Elffuss BraidHub

kikocis/continue public

main · 1.8 KiBRawPermalink
1import { EnhancedStore } from "@reduxjs/toolkit";
2import { BrowserSerializedContinueConfig, ModelDescription } from "core";
3import { SerializedOrgWithProfiles } from "core/config/ProfileLifecycleManager";
4import { copyOf } from "core/util";
5import { MockIdeMessenger } from "../../context/MockIdeMessenger";
6
7interface TestConfigUpdateParams {
8 store: EnhancedStore;
9 ideMessenger: MockIdeMessenger;
10 newProfileId?: string;
11 newOrgId?: string;
12 newOrgs?: SerializedOrgWithProfiles[];
13 editConfig?: (
14 current: BrowserSerializedContinueConfig,
15 ) => BrowserSerializedContinueConfig;
16}
17
18export function triggerConfigUpdate({
19 store,
20 ideMessenger,
21 editConfig,
22 newOrgs,
23 newOrgId,
24 newProfileId,
25}: TestConfigUpdateParams) {
26 const state = store.getState();
27 ideMessenger.mockMessageToWebview("configUpdate", {
28 organizations: newOrgs ?? state.profiles.organizations,
29 selectedOrgId: newOrgId ?? state.profiles.selectedOrganizationId,
30 profileId: newProfileId ?? state.profiles.selectedProfileId,
31 result: {
32 config: editConfig
33 ? editConfig(copyOf(state.config.config))
34 : state.config.config,
35 configLoadInterrupted: false,
36 errors: [],
37 },
38 });
39}
40
41export function addAndSelectChatModel(
42 store: EnhancedStore,
43 ideMessenger: MockIdeMessenger,
44 llmDesc: ModelDescription,
45) {
46 triggerConfigUpdate({
47 store,
48 ideMessenger,
49 editConfig(current) {
50 current.modelsByRole.chat.push(llmDesc);
51 current.selectedModelByRole.chat = llmDesc;
52 return current;
53 },
54 });
55}
56
57export function addAndSelectMockLlm(
58 store: EnhancedStore,
59 ideMessenger: MockIdeMessenger,
60) {
61 addAndSelectChatModel(store, ideMessenger, {
62 model: "mock",
63 provider: "mock",
64 title: "Mock LLM",
65 underlyingProviderName: "mock",
66 });
67}