Changesets · Branches · Tags · Compare
| Changeset | bf136946f6caaf7c7b7f0b04a1acf68b700dfb9c2b5af701fa930f875f243184 |
|---|---|
| Author | Nate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-09-11 15:11 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-09-11 15:11 -07:00 |
| Parents | 562def2ea40d, 97a51e0ee813 |
6 files changed
modified extensions/cli/package-lock.json +0 −0
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
modified extensions/cli/package.json +1 −0
| @@ -118,6 +118,7 @@ | ||
| 118 | 118 | "open": "^10.1.0", |
| 119 | 119 | "posthog-node": "^5.6.0", |
| 120 | 120 | "prettier": "^3.6.2", |
| 121 | + "prettier-plugin-tailwindcss": "^0.6.14", | |
| 121 | 122 | "react": "^19.1.0", |
| 122 | 123 | "readline-sync": "^1.4.10", |
| 123 | 124 | "semantic-release": "^24.2.7", |
modified extensions/cli/src/__mocks__/config.ts +1 −2
| @@ -13,5 +13,4 @@ | ||
| 13 | 13 | ) => [any, any] |
| 14 | 14 | >(); |
| 15 | 15 | export const getModel = vi.fn<(config: any, modelName: string) => any>(); |
| 16 | -export const createLlmApi = | |
| 17 | - vi.fn<(modelConfig: any, authConfig: any, orgScopeId?: string) => any>(); | |
| 16 | +export const createLlmApi = vi.fn<(model: any, authConfig: any) => any>(); |
modified extensions/cli/src/config.ts +34 −22
| @@ -19,25 +19,14 @@ | ||
| 19 | 19 | import { env } from "./env.js"; |
| 20 | 20 | import { MCPService } from "./services/MCPService.js"; |
| 21 | 21 | |
| 22 | -export function getLlmApi( | |
| 23 | - assistant: AssistantUnrolled, | |
| 24 | - authConfig: AuthConfig, | |
| 25 | -): [BaseLlmApi, ModelConfig] { | |
| 26 | - if (!assistant.models || assistant.models.length === 0) { | |
| 27 | - throw new Error("No models found in the configured assistant"); | |
| 28 | - } | |
| 29 | - | |
| 30 | - const model = assistant.models?.find( | |
| 31 | - (model) => | |
| 32 | - model?.roles?.includes("chat") || (model && model.roles === undefined), | |
| 33 | - ); | |
| 34 | - | |
| 35 | - if (!model) { | |
| 36 | - throw new Error( | |
| 37 | - "No models with the chat role found in the configured assistant", | |
| 38 | - ); | |
| 39 | - } | |
| 40 | - | |
| 22 | +/** | |
| 23 | + * Creates an LLM API instance from a ModelConfig and auth configuration | |
| 24 | + * Handles special logic for continue-proxy provider and constructs the API | |
| 25 | + */ | |
| 26 | +export function createLlmApi( | |
| 27 | + model: ModelConfig, | |
| 28 | + authConfig: AuthConfig | null, | |
| 29 | +): BaseLlmApi | null { | |
| 41 | 30 | const accessToken = getAccessToken(authConfig); |
| 42 | 31 | const organizationId = getOrganizationId(authConfig); |
| 43 | 32 | |
| @@ -50,9 +39,10 @@ | ||
| 50 | 39 | apiKey: accessToken ?? undefined, |
| 51 | 40 | env: { |
| 52 | 41 | apiKeyLocation: (model as any).apiKeyLocation, |
| 53 | - // envSecretLocations: model.env, | |
| 54 | 42 | orgScopeId: organizationId, |
| 55 | - proxyUrl: undefined, // TODO | |
| 43 | + proxyUrl: | |
| 44 | + (model as { onPremProxyUrl: string | undefined }) | |
| 45 | + .onPremProxyUrl ?? undefined, | |
| 56 | 46 | }, |
| 57 | 47 | } |
| 58 | 48 | : { |
| @@ -63,7 +53,29 @@ | ||
| 63 | 53 | env: model.env, |
| 64 | 54 | }; |
| 65 | 55 | |
| 66 | - const llmApi = constructLlmApi(config); | |
| 56 | + return constructLlmApi(config) ?? null; | |
| 57 | +} | |
| 58 | + | |
| 59 | +export function getLlmApi( | |
| 60 | + assistant: AssistantUnrolled, | |
| 61 | + authConfig: AuthConfig, | |
| 62 | +): [BaseLlmApi, ModelConfig] { | |
| 63 | + if (!assistant.models || assistant.models.length === 0) { | |
| 64 | + throw new Error("No models found in the configured assistant"); | |
| 65 | + } | |
| 66 | + | |
| 67 | + const model = assistant.models?.find( | |
| 68 | + (model) => | |
| 69 | + model?.roles?.includes("chat") || (model && model.roles === undefined), | |
| 70 | + ); | |
| 71 | + | |
| 72 | + if (!model) { | |
| 73 | + throw new Error( | |
| 74 | + "No models with the chat role found in the configured assistant", | |
| 75 | + ); | |
| 76 | + } | |
| 77 | + | |
| 78 | + const llmApi = createLlmApi(model, authConfig); | |
| 67 | 79 | |
| 68 | 80 | if (!llmApi) { |
| 69 | 81 | throw new Error( |
modified extensions/cli/src/services/ModelService.test.ts +10 −30
| @@ -1,9 +1,7 @@ | ||
| 1 | 1 | import { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml"; |
| 2 | -import * as openaiAdapters from "@continuedev/openai-adapters"; | |
| 3 | 2 | import { describe, expect, beforeEach, vi, test } from "vitest"; |
| 4 | 3 | |
| 5 | 4 | // Mock dependencies before imports |
| 6 | -vi.mock("@continuedev/openai-adapters"); | |
| 7 | 5 | vi.mock("../config.js"); |
| 8 | 6 | vi.mock("../auth/workos.js"); |
| 9 | 7 | |
| @@ -81,9 +79,7 @@ | ||
| 81 | 79 | |
| 82 | 80 | test("should initialize with persisted model if valid", async () => { |
| 83 | 81 | vi.mocked(workos.getModelName).mockReturnValue("Claude 3"); |
| 84 | - vi.mocked(openaiAdapters.constructLlmApi).mockReturnValue( | |
| 85 | - mockLlmApi as any, | |
| 86 | - ); | |
| 82 | + vi.mocked(config.createLlmApi).mockReturnValue(mockLlmApi as any); | |
| 87 | 83 | |
| 88 | 84 | const state = await service.initialize(mockAssistant, mockAuthConfig); |
| 89 | 85 | |
| @@ -152,9 +148,7 @@ | ||
| 152 | 148 | await service.initialize(mockAssistant, mockAuthConfig); |
| 153 | 149 | |
| 154 | 150 | const newLlmApi = { complete: vi.fn(), stream: vi.fn() }; |
| 155 | - vi.mocked(openaiAdapters.constructLlmApi).mockReturnValue( | |
| 156 | - newLlmApi as any, | |
| 157 | - ); | |
| 151 | + vi.mocked(config.createLlmApi).mockReturnValue(newLlmApi as any); | |
| 158 | 152 | |
| 159 | 153 | const state = await service.switchModel(1); |
| 160 | 154 | |
| @@ -204,24 +198,14 @@ | ||
| 204 | 198 | ]); |
| 205 | 199 | await service.initialize(mockAssistant, mockAuthConfig); |
| 206 | 200 | |
| 207 | - vi.mocked(workos.getAccessToken).mockReturnValue("proxy-token"); | |
| 208 | - vi.mocked(workos.getOrganizationId).mockReturnValue("org-123"); | |
| 209 | - vi.mocked(openaiAdapters.constructLlmApi).mockReturnValue( | |
| 210 | - mockLlmApi as any, | |
| 211 | - ); | |
| 201 | + vi.mocked(config.createLlmApi).mockReturnValue(mockLlmApi as any); | |
| 212 | 202 | |
| 213 | 203 | await service.switchModel(0); |
| 214 | 204 | |
| 215 | - expect(vi.mocked(openaiAdapters.constructLlmApi)).toHaveBeenCalledWith({ | |
| 216 | - provider: "continue-proxy", | |
| 217 | - apiBase: "https://proxy.continue.dev", | |
| 218 | - apiKey: "proxy-token", | |
| 219 | - env: { | |
| 220 | - apiKeyLocation: "env.PROXY_KEY", | |
| 221 | - orgScopeId: "org-123", | |
| 222 | - proxyUrl: undefined, | |
| 223 | - }, | |
| 224 | - }); | |
| 205 | + expect(vi.mocked(config.createLlmApi)).toHaveBeenCalledWith( | |
| 206 | + proxyModel, | |
| 207 | + mockAuthConfig, | |
| 208 | + ); | |
| 225 | 209 | }); |
| 226 | 210 | }); |
| 227 | 211 | |
| @@ -292,9 +276,7 @@ | ||
| 292 | 276 | |
| 293 | 277 | expect(service.getCurrentModelIndex()).toBe(0); |
| 294 | 278 | |
| 295 | - vi.mocked(openaiAdapters.constructLlmApi).mockReturnValue( | |
| 296 | - mockLlmApi as any, | |
| 297 | - ); | |
| 279 | + vi.mocked(config.createLlmApi).mockReturnValue(mockLlmApi as any); | |
| 298 | 280 | await service.switchModel(1); |
| 299 | 281 | expect(service.getCurrentModelIndex()).toBe(1); |
| 300 | 282 | }); |
| @@ -392,9 +374,7 @@ | ||
| 392 | 374 | service.on("stateChanged", listener); |
| 393 | 375 | |
| 394 | 376 | const newLlmApi = { complete: vi.fn(), stream: vi.fn() }; |
| 395 | - vi.mocked(openaiAdapters.constructLlmApi).mockReturnValue( | |
| 396 | - newLlmApi as any, | |
| 397 | - ); | |
| 377 | + vi.mocked(config.createLlmApi).mockReturnValue(newLlmApi as any); | |
| 398 | 378 | await service.switchModel(1); |
| 399 | 379 | |
| 400 | 380 | expect(listener).toHaveBeenCalledWith( |
| @@ -419,7 +399,7 @@ | ||
| 419 | 399 | const errorListener = vi.fn(); |
| 420 | 400 | service.on("error", errorListener); |
| 421 | 401 | |
| 422 | - vi.mocked(openaiAdapters.constructLlmApi).mockReturnValue(null as any); | |
| 402 | + vi.mocked(config.createLlmApi).mockReturnValue(null as any); | |
| 423 | 403 | |
| 424 | 404 | await expect(service.switchModel(1)).rejects.toThrow( |
| 425 | 405 | "Failed to initialize LLM", |
modified extensions/cli/src/services/ModelService.ts +5 −59
| @@ -1,13 +1,7 @@ | ||
| 1 | 1 | import { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml"; |
| 2 | -import { constructLlmApi, LLMConfig } from "@continuedev/openai-adapters"; | |
| 3 | - | |
| 4 | -import { | |
| 5 | - AuthConfig, | |
| 6 | - getAccessToken, | |
| 7 | - getModelName, | |
| 8 | - getOrganizationId, | |
| 9 | -} from "../auth/workos.js"; | |
| 10 | -import { getLlmApi } from "../config.js"; | |
| 2 | + | |
| 3 | +import { AuthConfig, getModelName } from "../auth/workos.js"; | |
| 4 | +import { createLlmApi, getLlmApi } from "../config.js"; | |
| 11 | 5 | import { logger } from "../util/logger.js"; |
| 12 | 6 | |
| 13 | 7 | import { BaseService, ServiceWithDependencies } from "./BaseService.js"; |
| @@ -89,31 +83,7 @@ | ||
| 89 | 83 | name: (selectedModel as any).name || "unnamed", |
| 90 | 84 | }); |
| 91 | 85 | |
| 92 | - const accessToken = getAccessToken(authConfig); | |
| 93 | - const organizationId = getOrganizationId(authConfig); | |
| 94 | - | |
| 95 | - const config: LLMConfig = | |
| 96 | - selectedModel.provider === "continue-proxy" | |
| 97 | - ? { | |
| 98 | - provider: selectedModel.provider, | |
| 99 | - requestOptions: selectedModel.requestOptions, | |
| 100 | - apiBase: selectedModel.apiBase, | |
| 101 | - apiKey: accessToken ?? undefined, | |
| 102 | - env: { | |
| 103 | - apiKeyLocation: (selectedModel as any).apiKeyLocation, | |
| 104 | - orgScopeId: organizationId, | |
| 105 | - proxyUrl: (selectedModel as any).onPremProxyUrl ?? undefined, | |
| 106 | - }, | |
| 107 | - } | |
| 108 | - : { | |
| 109 | - provider: selectedModel.provider as any, | |
| 110 | - apiKey: selectedModel.apiKey, | |
| 111 | - apiBase: selectedModel.apiBase, | |
| 112 | - requestOptions: selectedModel.requestOptions, | |
| 113 | - env: selectedModel.env, | |
| 114 | - }; | |
| 115 | - | |
| 116 | - const llmApi = constructLlmApi(config); | |
| 86 | + const llmApi = createLlmApi(selectedModel, authConfig); | |
| 117 | 87 | |
| 118 | 88 | if (!llmApi) { |
| 119 | 89 | throw new Error("Failed to initialize LLM with persisted model"); |
| @@ -288,31 +258,7 @@ | ||
| 288 | 258 | }); |
| 289 | 259 | |
| 290 | 260 | try { |
| 291 | - const accessToken = getAccessToken(authConfig); | |
| 292 | - const organizationId = getOrganizationId(authConfig); | |
| 293 | - | |
| 294 | - const config: LLMConfig = | |
| 295 | - selectedModel.provider === "continue-proxy" | |
| 296 | - ? { | |
| 297 | - provider: selectedModel.provider, | |
| 298 | - requestOptions: selectedModel.requestOptions, | |
| 299 | - apiBase: selectedModel.apiBase, | |
| 300 | - apiKey: accessToken ?? undefined, | |
| 301 | - env: { | |
| 302 | - apiKeyLocation: (selectedModel as any).apiKeyLocation, | |
| 303 | - orgScopeId: organizationId, | |
| 304 | - proxyUrl: (selectedModel as any).onPremProxyUrl ?? undefined, | |
| 305 | - }, | |
| 306 | - } | |
| 307 | - : { | |
| 308 | - provider: selectedModel.provider as any, | |
| 309 | - apiKey: selectedModel.apiKey, | |
| 310 | - apiBase: selectedModel.apiBase, | |
| 311 | - requestOptions: selectedModel.requestOptions, | |
| 312 | - env: selectedModel.env, | |
| 313 | - }; | |
| 314 | - | |
| 315 | - const llmApi = constructLlmApi(config); | |
| 261 | + const llmApi = createLlmApi(selectedModel, authConfig); | |
| 316 | 262 | |
| 317 | 263 | if (!llmApi) { |
| 318 | 264 | throw new Error("Failed to initialize LLM with selected model"); |