MCPcopy
hub / github.com/continuedev/continue / doInitialize

Method doInitialize

extensions/cli/src/services/ModelService.ts:41–124  ·  view source on GitHub ↗

* Initialize the model service

(
    assistant: AssistantUnrolled,
    authConfig: AuthConfig,
    agentFileServiceState: AgentFileServiceState | undefined,
  )

Source from the content-addressed store, hash-verified

39 * Initialize the model service
40 */
41 async doInitialize(
42 assistant: AssistantUnrolled,
43 authConfig: AuthConfig,
44 agentFileServiceState: AgentFileServiceState | undefined,
45 ): Promise<ModelServiceState> {
46 logger.debug("ModelService.doInitialize called", {
47 hasAssistant: !!assistant,
48 hasAuthConfig: !!authConfig,
49 assistantModelsCount: assistant?.models?.length || 0,
50 });
51
52 this.assistant = assistant;
53 this.authConfig = authConfig;
54 this.availableModels = (assistant.models?.filter(
55 (model) =>
56 model && (model.roles?.includes("chat") || model.roles === undefined),
57 ) || []) as ModelConfig[];
58
59 let preferredModelName: string | null | undefined = null;
60 let modelSource = "default";
61
62 // Priority = agentFile -> last selected model
63 if (agentFileServiceState?.agentFileModel?.name) {
64 preferredModelName = agentFileServiceState.agentFileModel?.name;
65 modelSource = "agentFile";
66 } else {
67 const persistedName = getModelName(authConfig);
68 if (persistedName) {
69 preferredModelName = persistedName;
70 modelSource = "persisted";
71 }
72 }
73
74 // Try to use the preferred model (agent file or persisted)
75 if (preferredModelName) {
76 // During initialization, we need to check against availableModels directly
77 const modelIndex = this.availableModels.findIndex((model) => {
78 const name = (model as any).name || (model as any).model;
79 return name === preferredModelName;
80 });
81 if (modelIndex === -1) {
82 // Preferred model not found, use default model selection
83 const [llmApi, model] = getLlmApi(assistant, authConfig);
84 return {
85 llmApi,
86 model,
87 assistant,
88 authConfig,
89 };
90 } else {
91 // Use the preferred model - but we need to handle initialization specially
92 // During init, currentState isn't set yet, so switchModel would fail
93 // Instead, we'll manually switch here
94 const selectedModel = this.availableModels[modelIndex];
95 logger.debug(`Using ${modelSource} model during initialization`, {
96 modelIndex,
97 provider: selectedModel.provider,
98 name: (selectedModel as any).name || "unnamed",

Callers

nothing calls this directly

Calls 4

getModelNameFunction · 0.85
createLlmApiFunction · 0.85
getLlmApiFunction · 0.50
debugMethod · 0.45

Tested by

no test coverage detected