Changesets · Branches · Tags · Compare
| Changeset | 8ec1a9e770aef609c83c9faa2bdf6d98d21027c4575afce69e43d80b5aeea042 |
|---|---|
| Author | uinstinct <61635505+uinstinct@users.noreply.github.com> · 2025-09-18 11:43 +05:30 |
| Committer | uinstinct <61635505+uinstinct@users.noreply.github.com> · 2025-09-18 11:43 +05:30 |
| Parents | 9334ee37bf04, d4eec0630c2e |
125 files changed
| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | timeout-minutes: 10 |
| 19 | 19 | steps: |
| 20 | 20 | - name: Run Detailed PR Review |
| 21 | - uses: continuedev/continue/actions/detailed-review@8373ac24010df1110cd00512f925b63813362da1 | |
| 21 | + uses: continuedev/continue/actions/detailed-review@3ebd8232440080aa8891909753f69d75a87b2c86 | |
| 22 | 22 | with: |
| 23 | 23 | continue-api-key: ${{ secrets.CONTINUE_API_KEY }} |
| 24 | 24 | continue-org: continuedev |
| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | timeout-minutes: 10 |
| 19 | 19 | steps: |
| 20 | 20 | - name: Run Continue PR Review Action |
| 21 | - uses: continuedev/continue/actions/general-review@8373ac24010df1110cd00512f925b63813362da1 | |
| 21 | + uses: continuedev/continue/actions/general-review@3ebd8232440080aa8891909753f69d75a87b2c86 | |
| 22 | 22 | with: |
| 23 | 23 | continue-api-key: ${{ secrets.CONTINUE_API_KEY }} |
| 24 | 24 | continue-org: "continuedev" |
| @@ -84,6 +84,9 @@ | ||
| 84 | 84 | AZURE_FOUNDRY_CODESTRAL_API_KEY: ${{ secrets.AZURE_FOUNDRY_CODESTRAL_API_KEY }} |
| 85 | 85 | AZURE_FOUNDRY_MISTRAL_SMALL_API_KEY: ${{ secrets.AZURE_FOUNDRY_MISTRAL_SMALL_API_KEY }} |
| 86 | 86 | AZURE_OPENAI_GPT41_API_KEY: ${{ secrets.AZURE_OPENAI_GPT41_API_KEY }} |
| 87 | + VOYAGE_API_KEY: ${{ secrets.VOYAGE_API_KEY }} | |
| 88 | + RELACE_API_KEY: ${{ secrets.RELACE_API_KEY }} | |
| 89 | + INCEPTION_API_KEY: ${{ secrets.INCEPTION_API_KEY }} | |
| 87 | 90 | |
| 88 | 91 | gui-checks: |
| 89 | 92 | runs-on: ubuntu-latest |
| @@ -217,6 +220,8 @@ | ||
| 217 | 220 | AZURE_FOUNDRY_MISTRAL_SMALL_API_KEY: ${{ secrets.AZURE_FOUNDRY_MISTRAL_SMALL_API_KEY }} |
| 218 | 221 | AZURE_OPENAI_GPT41_API_KEY: ${{ secrets.AZURE_OPENAI_GPT41_API_KEY }} |
| 219 | 222 | VOYAGE_API_KEY: ${{ secrets.VOYAGE_API_KEY }} |
| 223 | + RELACE_API_KEY: ${{ secrets.RELACE_API_KEY }} | |
| 224 | + INCEPTION_API_KEY: ${{ secrets.INCEPTION_API_KEY }} | |
| 220 | 225 | |
| 221 | 226 | vscode-get-test-file-matrix: |
| 222 | 227 | runs-on: ubuntu-latest |
| @@ -32,3 +32,5 @@ | ||
| 32 | 32 | AZURE_FOUNDRY_MISTRAL_SMALL_API_KEY: ${{ secrets.AZURE_FOUNDRY_MISTRAL_SMALL_API_KEY }} |
| 33 | 33 | AZURE_OPENAI_GPT41_API_KEY: ${{ secrets.AZURE_OPENAI_GPT41_API_KEY }} |
| 34 | 34 | VOYAGE_API_KEY: ${{ secrets.VOYAGE_API_KEY }} |
| 35 | + RELACE_API_KEY: ${{ secrets.RELACE_API_KEY }} | |
| 36 | + INCEPTION_API_KEY: ${{ secrets.INCEPTION_API_KEY }} |
| @@ -32,3 +32,5 @@ | ||
| 32 | 32 | AZURE_FOUNDRY_MISTRAL_SMALL_API_KEY: ${{ secrets.AZURE_FOUNDRY_MISTRAL_SMALL_API_KEY }} |
| 33 | 33 | AZURE_OPENAI_GPT41_API_KEY: ${{ secrets.AZURE_OPENAI_GPT41_API_KEY }} |
| 34 | 34 | VOYAGE_API_KEY: ${{ secrets.VOYAGE_API_KEY }} |
| 35 | + RELACE_API_KEY: ${{ secrets.RELACE_API_KEY }} | |
| 36 | + INCEPTION_API_KEY: ${{ secrets.INCEPTION_API_KEY }} |
| @@ -23,4 +23,7 @@ | ||
| 23 | 23 | AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }} |
| 24 | 24 | AZURE_FOUNDRY_CODESTRAL_API_KEY: ${{ secrets.AZURE_FOUNDRY_CODESTRAL_API_KEY }} |
| 25 | 25 | AZURE_FOUNDRY_MISTRAL_SMALL_API_KEY: ${{ secrets.AZURE_FOUNDRY_MISTRAL_SMALL_API_KEY }} |
| 26 | - AZURE_OPENAI_GPT41_API_KEY: ${{ secrets.AZURE_OPENAI_GPT41_API_KEY }} | |
| No newline at the end of the file | ||
| 26 | + AZURE_OPENAI_GPT41_API_KEY: ${{ secrets.AZURE_OPENAI_GPT41_API_KEY }} | |
| 27 | + VOYAGE_API_KEY: ${{ secrets.VOYAGE_API_KEY }} | |
| 28 | + RELACE_API_KEY: ${{ secrets.RELACE_API_KEY }} | |
| 29 | + INCEPTION_API_KEY: ${{ secrets.INCEPTION_API_KEY }} |
| @@ -32,3 +32,5 @@ | ||
| 32 | 32 | AZURE_FOUNDRY_MISTRAL_SMALL_API_KEY: ${{ secrets.AZURE_FOUNDRY_MISTRAL_SMALL_API_KEY }} |
| 33 | 33 | AZURE_OPENAI_GPT41_API_KEY: ${{ secrets.AZURE_OPENAI_GPT41_API_KEY }} |
| 34 | 34 | VOYAGE_API_KEY: ${{ secrets.VOYAGE_API_KEY }} |
| 35 | + RELACE_API_KEY: ${{ secrets.RELACE_API_KEY }} | |
| 36 | + INCEPTION_API_KEY: ${{ secrets.INCEPTION_API_KEY }} |
| @@ -32,6 +32,10 @@ | ||
| 32 | 32 | required: false |
| 33 | 33 | VOYAGE_API_KEY: |
| 34 | 34 | required: false |
| 35 | + RELACE_API_KEY: | |
| 36 | + required: false | |
| 37 | + INCEPTION_API_KEY: | |
| 38 | + required: false | |
| 35 | 39 | |
| 36 | 40 | permissions: |
| 37 | 41 | contents: write |
| @@ -77,6 +81,8 @@ | ||
| 77 | 81 | AZURE_FOUNDRY_MISTRAL_SMALL_API_KEY: ${{ secrets.AZURE_FOUNDRY_MISTRAL_SMALL_API_KEY }} |
| 78 | 82 | AZURE_OPENAI_GPT41_API_KEY: ${{ secrets.AZURE_OPENAI_GPT41_API_KEY }} |
| 79 | 83 | VOYAGE_API_KEY: ${{ secrets.VOYAGE_API_KEY }} |
| 84 | + RELACE_API_KEY: ${{ secrets.RELACE_API_KEY }} | |
| 85 | + INCEPTION_API_KEY: ${{ secrets.INCEPTION_API_KEY }} | |
| 80 | 86 | |
| 81 | 87 | - name: Release |
| 82 | 88 | env: |
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
| @@ -215,8 +215,8 @@ | ||
| 215 | 215 | // Prepare models |
| 216 | 216 | for (const model of models) { |
| 217 | 217 | model.requestOptions = { |
| 218 | - ...model.requestOptions, | |
| 219 | 218 | ...config.requestOptions, |
| 219 | + ...model.requestOptions, | |
| 220 | 220 | }; |
| 221 | 221 | if (roles !== undefined) { |
| 222 | 222 | model.roles = model.roles ?? roles; |
| @@ -545,6 +545,7 @@ | ||
| 545 | 545 | |
| 546 | 546 | // Trigger MCP server refreshes (Config is reloaded again once connected!) |
| 547 | 547 | const mcpManager = MCPManagerSingleton.getInstance(); |
| 548 | + | |
| 548 | 549 | const orgPolicy = PolicySingleton.getInstance().policy; |
| 549 | 550 | if (orgPolicy?.policy?.allowMcpServers === false) { |
| 550 | 551 | await mcpManager.shutdown(); |
| @@ -555,6 +556,7 @@ | ||
| 555 | 556 | id: `continue-mcp-server-${index + 1}`, |
| 556 | 557 | name: `MCP Server`, |
| 557 | 558 | ...server, |
| 559 | + requestOptions: config.requestOptions, | |
| 558 | 560 | }), |
| 559 | 561 | ), |
| 560 | 562 | false, |
| @@ -187,7 +187,6 @@ | ||
| 187 | 187 | const mcpManager = MCPManagerSingleton.getInstance(); |
| 188 | 188 | const mcpServerStatuses = mcpManager.getStatuses(); |
| 189 | 189 | |
| 190 | - // Slightly hacky just need connection's client to make slash command for now | |
| 191 | 190 | const serializableStatuses = mcpServerStatuses.map((server) => { |
| 192 | 191 | const { client, ...rest } = server; |
| 193 | 192 | return rest; |
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | ConfigResult, |
| 5 | 5 | ConfigValidationError, |
| 6 | 6 | isAssistantUnrolledNonNullable, |
| 7 | + mergeConfigYamlRequestOptions, | |
| 7 | 8 | mergeUnrolledAssistants, |
| 8 | 9 | ModelRole, |
| 9 | 10 | PackageIdentifier, |
| @@ -34,10 +35,7 @@ | ||
| 34 | 35 | import { unrollLocalYamlBlocks } from "./loadLocalYamlBlocks"; |
| 35 | 36 | import { LocalPlatformClient } from "./LocalPlatformClient"; |
| 36 | 37 | import { llmsFromModelConfig } from "./models"; |
| 37 | -import { | |
| 38 | - convertYamlMcpToContinueMcp, | |
| 39 | - convertYamlRuleToContinueRule, | |
| 40 | -} from "./yamlToContinueConfig"; | |
| 38 | +import { convertYamlRuleToContinueRule } from "./yamlToContinueConfig"; | |
| 41 | 39 | |
| 42 | 40 | async function loadConfigYaml(options: { |
| 43 | 41 | overrideConfigYaml: AssistantUnrolled | undefined; |
| @@ -155,16 +153,15 @@ | ||
| 155 | 153 | }; |
| 156 | 154 | } |
| 157 | 155 | |
| 158 | -async function configYamlToContinueConfig(options: { | |
| 156 | +export async function configYamlToContinueConfig(options: { | |
| 159 | 157 | config: AssistantUnrolled; |
| 160 | 158 | ide: IDE; |
| 161 | - ideSettings: IdeSettings; | |
| 162 | 159 | ideInfo: IdeInfo; |
| 163 | 160 | uniqueId: string; |
| 164 | 161 | llmLogger: ILLMLogger; |
| 165 | 162 | workOsAccessToken: string | undefined; |
| 166 | 163 | }): Promise<{ config: ContinueConfig; errors: ConfigValidationError[] }> { |
| 167 | - let { config, ide, ideSettings, ideInfo, uniqueId, llmLogger } = options; | |
| 164 | + let { config, ide, ideInfo, uniqueId, llmLogger } = options; | |
| 168 | 165 | |
| 169 | 166 | const localErrors: ConfigValidationError[] = []; |
| 170 | 167 | |
| @@ -192,6 +189,7 @@ | ||
| 192 | 189 | summarize: null, |
| 193 | 190 | }, |
| 194 | 191 | rules: [], |
| 192 | + requestOptions: { ...config.requestOptions }, | |
| 195 | 193 | }; |
| 196 | 194 | |
| 197 | 195 | // Right now, if there are any missing packages in the config, then we will just throw an error |
| @@ -226,7 +224,13 @@ | ||
| 226 | 224 | } |
| 227 | 225 | } |
| 228 | 226 | |
| 229 | - continueConfig.data = config.data; | |
| 227 | + continueConfig.data = config.data?.map((d) => ({ | |
| 228 | + ...d, | |
| 229 | + requestOptions: mergeConfigYamlRequestOptions( | |
| 230 | + d.requestOptions, | |
| 231 | + continueConfig.requestOptions, | |
| 232 | + ), | |
| 233 | + })); | |
| 230 | 234 | continueConfig.docs = config.docs?.map((doc) => ({ |
| 231 | 235 | title: doc.name, |
| 232 | 236 | startUrl: doc.startUrl, |
| @@ -250,12 +254,6 @@ | ||
| 250 | 254 | }); |
| 251 | 255 | }); |
| 252 | 256 | |
| 253 | - continueConfig.experimental = { | |
| 254 | - modelContextProtocolServers: config.mcpServers?.map( | |
| 255 | - convertYamlMcpToContinueMcp, | |
| 256 | - ), | |
| 257 | - }; | |
| 258 | - | |
| 259 | 257 | // Prompt files - |
| 260 | 258 | try { |
| 261 | 259 | const promptFiles = await getAllPromptFiles(ide, undefined, true); |
| @@ -307,9 +305,7 @@ | ||
| 307 | 305 | try { |
| 308 | 306 | const llms = await llmsFromModelConfig({ |
| 309 | 307 | model, |
| 310 | - ide, | |
| 311 | 308 | uniqueId, |
| 312 | - ideSettings, | |
| 313 | 309 | llmLogger, |
| 314 | 310 | config: continueConfig, |
| 315 | 311 | }); |
| @@ -394,6 +390,7 @@ | ||
| 394 | 390 | |
| 395 | 391 | // Trigger MCP server refreshes (Config is reloaded again once connected!) |
| 396 | 392 | const mcpManager = MCPManagerSingleton.getInstance(); |
| 393 | + | |
| 397 | 394 | const orgPolicy = PolicySingleton.getInstance().policy; |
| 398 | 395 | if (orgPolicy?.policy?.allowMcpServers === false) { |
| 399 | 396 | await mcpManager.shutdown(); |
| @@ -406,6 +403,10 @@ | ||
| 406 | 403 | transport: { |
| 407 | 404 | type: "stdio", |
| 408 | 405 | args: [], |
| 406 | + requestOptions: mergeConfigYamlRequestOptions( | |
| 407 | + server.requestOptions, | |
| 408 | + config.requestOptions, | |
| 409 | + ), | |
| 409 | 410 | ...(server as any), // TODO: fix the types on mcpServers in config-yaml |
| 410 | 411 | }, |
| 411 | 412 | timeout: server.connectionTimeout, |
| @@ -464,7 +465,6 @@ | ||
| 464 | 465 | await configYamlToContinueConfig({ |
| 465 | 466 | config: configYamlResult.config, |
| 466 | 467 | ide, |
| 467 | - ideSettings, | |
| 468 | 468 | ideInfo, |
| 469 | 469 | uniqueId, |
| 470 | 470 | llmLogger, |
| @@ -1,12 +1,9 @@ | ||
| 1 | -import { ModelConfig } from "@continuedev/config-yaml"; | |
| 2 | - | |
| 3 | 1 | import { |
| 4 | - ContinueConfig, | |
| 5 | - IDE, | |
| 6 | - IdeSettings, | |
| 7 | - ILLMLogger, | |
| 8 | - LLMOptions, | |
| 9 | -} from "../.."; | |
| 2 | + mergeConfigYamlRequestOptions, | |
| 3 | + ModelConfig, | |
| 4 | +} from "@continuedev/config-yaml"; | |
| 5 | + | |
| 6 | +import { ContinueConfig, ILLMLogger, LLMOptions } from "../.."; | |
| 10 | 7 | import { BaseLLM } from "../../llm"; |
| 11 | 8 | import { LLMClasses } from "../../llm/llms"; |
| 12 | 9 | |
| @@ -29,14 +26,12 @@ | ||
| 29 | 26 | async function modelConfigToBaseLLM({ |
| 30 | 27 | model, |
| 31 | 28 | uniqueId, |
| 32 | - ideSettings, | |
| 33 | 29 | llmLogger, |
| 34 | 30 | config, |
| 35 | 31 | isFromAutoDetect, |
| 36 | 32 | }: { |
| 37 | 33 | model: ModelConfig; |
| 38 | 34 | uniqueId: string; |
| 39 | - ideSettings: IdeSettings; | |
| 40 | 35 | llmLogger: ILLMLogger; |
| 41 | 36 | config: ContinueConfig; |
| 42 | 37 | isFromAutoDetect?: boolean; |
| @@ -49,6 +44,11 @@ | ||
| 49 | 44 | |
| 50 | 45 | const { capabilities, ...rest } = model; |
| 51 | 46 | |
| 47 | + const mergedRequestOptions = mergeConfigYamlRequestOptions( | |
| 48 | + rest.requestOptions, | |
| 49 | + config.requestOptions, | |
| 50 | + ); | |
| 51 | + | |
| 52 | 52 | let options: LLMOptions = { |
| 53 | 53 | ...rest, |
| 54 | 54 | contextLength: model.defaultCompletionOptions?.contextLength, |
| @@ -74,6 +74,7 @@ | ||
| 74 | 74 | }, |
| 75 | 75 | autocompleteOptions: model.autocompleteOptions, |
| 76 | 76 | isFromAutoDetect, |
| 77 | + requestOptions: mergedRequestOptions, | |
| 77 | 78 | }; |
| 78 | 79 | |
| 79 | 80 | // Model capabilities - need to be undefined if not found |
| @@ -154,17 +155,13 @@ | ||
| 154 | 155 | async function autodetectModels({ |
| 155 | 156 | llm, |
| 156 | 157 | model, |
| 157 | - ide, | |
| 158 | 158 | uniqueId, |
| 159 | - ideSettings, | |
| 160 | 159 | llmLogger, |
| 161 | 160 | config, |
| 162 | 161 | }: { |
| 163 | 162 | llm: BaseLLM; |
| 164 | 163 | model: ModelConfig; |
| 165 | - ide: IDE; | |
| 166 | 164 | uniqueId: string; |
| 167 | - ideSettings: IdeSettings; | |
| 168 | 165 | llmLogger: ILLMLogger; |
| 169 | 166 | config: ContinueConfig; |
| 170 | 167 | }): Promise<BaseLLM[]> { |
| @@ -183,7 +180,6 @@ | ||
| 183 | 180 | name: modelName, |
| 184 | 181 | }, |
| 185 | 182 | uniqueId, |
| 186 | - ideSettings, | |
| 187 | 183 | llmLogger, |
| 188 | 184 | config, |
| 189 | 185 | isFromAutoDetect: true, |
| @@ -199,23 +195,18 @@ | ||
| 199 | 195 | |
| 200 | 196 | export async function llmsFromModelConfig({ |
| 201 | 197 | model, |
| 202 | - ide, | |
| 203 | 198 | uniqueId, |
| 204 | - ideSettings, | |
| 205 | 199 | llmLogger, |
| 206 | 200 | config, |
| 207 | 201 | }: { |
| 208 | 202 | model: ModelConfig; |
| 209 | - ide: IDE; | |
| 210 | 203 | uniqueId: string; |
| 211 | - ideSettings: IdeSettings; | |
| 212 | 204 | llmLogger: ILLMLogger; |
| 213 | 205 | config: ContinueConfig; |
| 214 | 206 | }): Promise<BaseLLM[]> { |
| 215 | 207 | const baseLlm = await modelConfigToBaseLLM({ |
| 216 | 208 | model, |
| 217 | 209 | uniqueId, |
| 218 | - ideSettings, | |
| 219 | 210 | llmLogger, |
| 220 | 211 | config, |
| 221 | 212 | }); |
| @@ -227,9 +218,7 @@ | ||
| 227 | 218 | const models = await autodetectModels({ |
| 228 | 219 | llm: baseLlm, |
| 229 | 220 | model, |
| 230 | - ide, | |
| 231 | 221 | uniqueId, |
| 232 | - ideSettings, | |
| 233 | 222 | llmLogger, |
| 234 | 223 | config, |
| 235 | 224 | }); |
| @@ -0,0 +1,355 @@ | ||
| 1 | +import { ModelConfig } from "@continuedev/config-yaml"; | |
| 2 | +import { beforeEach, describe, expect, it, vi } from "vitest"; | |
| 3 | + | |
| 4 | +import { ContinueConfig, ILLMLogger } from "../.."; | |
| 5 | +import { llmsFromModelConfig } from "./models"; | |
| 6 | + | |
| 7 | +// Mock the LLM classes | |
| 8 | +vi.mock("../../llm/llms", () => ({ | |
| 9 | + LLMClasses: [ | |
| 10 | + class MockOpenAI { | |
| 11 | + static providerName = "openai"; | |
| 12 | + static defaultOptions = { | |
| 13 | + completionOptions: { | |
| 14 | + maxTokens: 2048, | |
| 15 | + }, | |
| 16 | + }; | |
| 17 | + | |
| 18 | + constructor(options: any) { | |
| 19 | + Object.assign(this, options); | |
| 20 | + } | |
| 21 | + | |
| 22 | + async listModels() { | |
| 23 | + return ["gpt-4", "gpt-3.5-turbo"]; | |
| 24 | + } | |
| 25 | + }, | |
| 26 | + class MockAnthropic { | |
| 27 | + static providerName = "anthropic"; | |
| 28 | + static defaultOptions = { | |
| 29 | + completionOptions: { | |
| 30 | + maxTokens: 4096, | |
| 31 | + }, | |
| 32 | + }; | |
| 33 | + | |
| 34 | + constructor(options: any) { | |
| 35 | + Object.assign(this, options); | |
| 36 | + } | |
| 37 | + | |
| 38 | + async listModels() { | |
| 39 | + return ["claude-3-5-sonnet-20241022", "claude-3-haiku-20240307"]; | |
| 40 | + } | |
| 41 | + }, | |
| 42 | + ], | |
| 43 | +})); | |
| 44 | + | |
| 45 | +describe("llmsFromModelConfig requestOptions merging", () => { | |
| 46 | + let mockLLMLogger: ILLMLogger; | |
| 47 | + let mockConfig: ContinueConfig; | |
| 48 | + | |
| 49 | + beforeEach(() => { | |
| 50 | + mockLLMLogger = { log: vi.fn() } as any; | |
| 51 | + mockConfig = { | |
| 52 | + requestOptions: { | |
| 53 | + timeout: 30000, | |
| 54 | + headers: { | |
| 55 | + "User-Agent": "Continue/1.0.0", | |
| 56 | + }, | |
| 57 | + proxy: "global-proxy", | |
| 58 | + }, | |
| 59 | + contextProviders: [], | |
| 60 | + mcpServerStatuses: [], | |
| 61 | + rules: [], | |
| 62 | + selectedModelByRole: { | |
| 63 | + apply: null, | |
| 64 | + autocomplete: null, | |
| 65 | + chat: null, | |
| 66 | + edit: null, | |
| 67 | + embed: null, | |
| 68 | + rerank: null, | |
| 69 | + summarize: null, | |
| 70 | + }, | |
| 71 | + modelsByRole: { | |
| 72 | + apply: [], | |
| 73 | + autocomplete: [], | |
| 74 | + chat: [], | |
| 75 | + edit: [], | |
| 76 | + embed: [], | |
| 77 | + rerank: [], | |
| 78 | + summarize: [], | |
| 79 | + }, | |
| 80 | + slashCommands: [], | |
| 81 | + tools: [], | |
| 82 | + allowAnonymousTelemetry: false, | |
| 83 | + } as ContinueConfig; | |
| 84 | + vi.clearAllMocks(); | |
| 85 | + }); | |
| 86 | + | |
| 87 | + it("should merge model requestOptions with config requestOptions", async () => { | |
| 88 | + const model: ModelConfig = { | |
| 89 | + name: "test-openai", | |
| 90 | + provider: "openai", | |
| 91 | + model: "gpt-4", | |
| 92 | + requestOptions: { | |
| 93 | + timeout: 60000, | |
| 94 | + headers: { | |
| 95 | + Authorization: "Bearer token123", | |
| 96 | + }, | |
| 97 | + proxy: "model-proxy", | |
| 98 | + }, | |
| 99 | + }; | |
| 100 | + | |
| 101 | + const result = await llmsFromModelConfig({ | |
| 102 | + model, | |
| 103 | + uniqueId: "test-id", | |
| 104 | + llmLogger: mockLLMLogger, | |
| 105 | + config: mockConfig, | |
| 106 | + }); | |
| 107 | + | |
| 108 | + expect(result).toHaveLength(1); | |
| 109 | + const llm = result[0]; | |
| 110 | + | |
| 111 | + // The LLM should have merged requestOptions | |
| 112 | + expect(llm.requestOptions).toEqual({ | |
| 113 | + timeout: 60000, // model-specific takes precedence | |
| 114 | + headers: { | |
| 115 | + "User-Agent": "Continue/1.0.0", // from global request options | |
| 116 | + Authorization: "Bearer token123", // from model | |
| 117 | + }, | |
| 118 | + proxy: "model-proxy", // model-specific takes precedence | |
| 119 | + }); | |
| 120 | + }); | |
| 121 | + | |
| 122 | + it("should use config requestOptions when model has no requestOptions", async () => { | |
| 123 | + const model: ModelConfig = { | |
| 124 | + name: "test-openai", | |
| 125 | + provider: "openai", | |
| 126 | + model: "gpt-4", | |
| 127 | + // no requestOptions | |
| 128 | + }; | |
| 129 | + | |
| 130 | + const result = await llmsFromModelConfig({ | |
| 131 | + model, | |
| 132 | + uniqueId: "test-id", | |
| 133 | + llmLogger: mockLLMLogger, | |
| 134 | + config: mockConfig, | |
| 135 | + }); | |
| 136 | + | |
| 137 | + expect(result).toHaveLength(1); | |
| 138 | + const llm = result[0]; | |
| 139 | + | |
| 140 | + // The LLM should have config requestOptions | |
| 141 | + expect(llm.requestOptions).toEqual(mockConfig.requestOptions); | |
| 142 | + }); | |
| 143 | + | |
| 144 | + it("should use model requestOptions when config has no requestOptions", async () => { | |
| 145 | + const model: ModelConfig = { | |
| 146 | + name: "test-openai", | |
| 147 | + provider: "openai", | |
| 148 | + model: "gpt-4", | |
| 149 | + requestOptions: { | |
| 150 | + timeout: 45000, | |
| 151 | + headers: { | |
| 152 | + "API-Key": "secret", | |
| 153 | + }, | |
| 154 | + }, | |
| 155 | + }; | |
| 156 | + | |
| 157 | + const configWithoutOptions = { ...mockConfig }; | |
| 158 | + delete configWithoutOptions.requestOptions; | |
| 159 | + | |
| 160 | + const result = await llmsFromModelConfig({ | |
| 161 | + model, | |
| 162 | + uniqueId: "test-id", | |
| 163 | + llmLogger: mockLLMLogger, | |
| 164 | + config: configWithoutOptions, | |
| 165 | + }); | |
| 166 | + | |
| 167 | + expect(result).toHaveLength(1); | |
| 168 | + const llm = result[0]; | |
| 169 | + | |
| 170 | + // The LLM should have model requestOptions | |
| 171 | + expect(llm.requestOptions).toEqual(model.requestOptions); | |
| 172 | + }); | |
| 173 | + | |
| 174 | + it("should handle empty headers correctly in merge", async () => { | |
| 175 | + const model: ModelConfig = { | |
| 176 | + name: "test-openai", | |
| 177 | + provider: "openai", | |
| 178 | + model: "gpt-4", | |
| 179 | + requestOptions: { | |
| 180 | + timeout: 60000, | |
| 181 | + headers: {}, | |
| 182 | + }, | |
| 183 | + }; | |
| 184 | + | |
| 185 | + const configWithEmptyHeaders = { | |
| 186 | + ...mockConfig, | |
| 187 | + requestOptions: { | |
| 188 | + ...mockConfig.requestOptions!, | |
| 189 | + headers: {}, | |
| 190 | + }, | |
| 191 | + }; | |
| 192 | + | |
| 193 | + const result = await llmsFromModelConfig({ | |
| 194 | + model, | |
| 195 | + uniqueId: "test-id", | |
| 196 | + llmLogger: mockLLMLogger, | |
| 197 | + config: configWithEmptyHeaders, | |
| 198 | + }); | |
| 199 | + | |
| 200 | + expect(result).toHaveLength(1); | |
| 201 | + const llm = result[0]; | |
| 202 | + | |
| 203 | + // When headers merge to empty object, they should be undefined | |
| 204 | + expect(llm.requestOptions).toEqual({ | |
| 205 | + timeout: 60000, | |
| 206 | + proxy: "global-proxy", | |
| 207 | + headers: undefined, | |
| 208 | + }); | |
| 209 | + }); | |
| 210 | + | |
| 211 | + it("should handle autodetect models with merged requestOptions", async () => { | |
| 212 | + const model: ModelConfig = { | |
| 213 | + name: "autodetect-openai", | |
| 214 | + provider: "openai", | |
| 215 | + model: "AUTODETECT", | |
| 216 | + requestOptions: { | |
| 217 | + timeout: 120000, | |
| 218 | + headers: { | |
| 219 | + "X-Custom": "autodetect", | |
| 220 | + }, | |
| 221 | + }, | |
| 222 | + }; | |
| 223 | + | |
| 224 | + const result = await llmsFromModelConfig({ | |
| 225 | + model, | |
| 226 | + uniqueId: "test-id", | |
| 227 | + llmLogger: mockLLMLogger, | |
| 228 | + config: mockConfig, | |
| 229 | + }); | |
| 230 | + | |
| 231 | + // Should return multiple models from listModels() | |
| 232 | + expect(result.length).toBeGreaterThan(0); | |
| 233 | + | |
| 234 | + // Each detected model should have the merged requestOptions | |
| 235 | + result.forEach((llm) => { | |
| 236 | + expect(llm.requestOptions).toEqual({ | |
| 237 | + timeout: 120000, // model-specific takes precedence | |
| 238 | + headers: { | |
| 239 | + "User-Agent": "Continue/1.0.0", // from global request options | |
| 240 | + "X-Custom": "autodetect", // from model | |
| 241 | + }, | |
| 242 | + proxy: "global-proxy", // from global request options | |
| 243 | + }); | |
| 244 | + }); | |
| 245 | + }); | |
| 246 | + | |
| 247 | + it("should handle unknown provider gracefully", async () => { | |
| 248 | + const model: ModelConfig = { | |
| 249 | + name: "unknown-provider", | |
| 250 | + provider: "unknown", | |
| 251 | + model: "unknown-model", | |
| 252 | + requestOptions: { | |
| 253 | + timeout: 60000, | |
| 254 | + }, | |
| 255 | + }; | |
| 256 | + | |
| 257 | + const result = await llmsFromModelConfig({ | |
| 258 | + model, | |
| 259 | + uniqueId: "test-id", | |
| 260 | + llmLogger: mockLLMLogger, | |
| 261 | + config: mockConfig, | |
| 262 | + }); | |
| 263 | + | |
| 264 | + // Should return empty array for unknown provider | |
| 265 | + expect(result).toHaveLength(0); | |
| 266 | + }); | |
| 267 | + | |
| 268 | + it("should preserve other model properties while merging requestOptions", async () => { | |
| 269 | + const model: ModelConfig = { | |
| 270 | + name: "test-anthropic", | |
| 271 | + provider: "anthropic", | |
| 272 | + model: "claude-3-5-sonnet-20241022", | |
| 273 | + roles: ["chat", "summarize"], | |
| 274 | + capabilities: ["tool_use", "image_input"], | |
| 275 | + defaultCompletionOptions: { | |
| 276 | + temperature: 0.7, | |
| 277 | + maxTokens: 1000, | |
| 278 | + }, | |
| 279 | + requestOptions: { | |
| 280 | + timeout: 90000, | |
| 281 | + }, | |
| 282 | + }; | |
| 283 | + | |
| 284 | + const result = await llmsFromModelConfig({ | |
| 285 | + model, | |
| 286 | + uniqueId: "test-id", | |
| 287 | + llmLogger: mockLLMLogger, | |
| 288 | + config: mockConfig, | |
| 289 | + }); | |
| 290 | + | |
| 291 | + expect(result).toHaveLength(1); | |
| 292 | + const llm = result[0]; | |
| 293 | + | |
| 294 | + // Should preserve model properties | |
| 295 | + expect(llm.title).toBe("test-anthropic"); | |
| 296 | + expect(llm.completionOptions?.temperature).toBe(0.7); | |
| 297 | + expect(llm.completionOptions?.maxTokens).toBe(1000); | |
| 298 | + expect(llm.capabilities?.tools).toBe(true); | |
| 299 | + expect(llm.capabilities?.uploadImage).toBe(true); | |
| 300 | + | |
| 301 | + // Should have merged requestOptions | |
| 302 | + expect(llm.requestOptions).toEqual({ | |
| 303 | + timeout: 90000, | |
| 304 | + headers: { | |
| 305 | + "User-Agent": "Continue/1.0.0", | |
| 306 | + }, | |
| 307 | + proxy: "global-proxy", | |
| 308 | + }); | |
| 309 | + }); | |
| 310 | + | |
| 311 | + it("should handle complex header merging scenarios", async () => { | |
| 312 | + const model: ModelConfig = { | |
| 313 | + name: "complex-headers", | |
| 314 | + provider: "openai", | |
| 315 | + model: "gpt-4", | |
| 316 | + requestOptions: { | |
| 317 | + headers: { | |
| 318 | + Authorization: "Bearer model-token", | |
| 319 | + Accept: "application/json", // Should override config Accept | |
| 320 | + "X-Model-Specific": "true", | |
| 321 | + }, | |
| 322 | + }, | |
| 323 | + }; | |
| 324 | + | |
| 325 | + const configWithMoreHeaders = { | |
| 326 | + ...mockConfig, | |
| 327 | + requestOptions: { | |
| 328 | + ...mockConfig.requestOptions!, | |
| 329 | + headers: { | |
| 330 | + ...mockConfig.requestOptions!.headers, | |
| 331 | + Accept: "text/plain", // Should be overridden by model | |
| 332 | + "Cache-Control": "no-cache", | |
| 333 | + }, | |
| 334 | + }, | |
| 335 | + }; | |
| 336 | + | |
| 337 | + const result = await llmsFromModelConfig({ | |
| 338 | + model, | |
| 339 | + uniqueId: "test-id", | |
| 340 | + llmLogger: mockLLMLogger, | |
| 341 | + config: configWithMoreHeaders, | |
| 342 | + }); | |
| 343 | + | |
| 344 | + expect(result).toHaveLength(1); | |
| 345 | + const llm = result[0]; | |
| 346 | + | |
| 347 | + expect(llm.requestOptions?.headers).toEqual({ | |
| 348 | + "User-Agent": "Continue/1.0.0", // from global request options | |
| 349 | + "Cache-Control": "no-cache", // from global request options | |
| 350 | + Authorization: "Bearer model-token", // from model | |
| 351 | + Accept: "application/json", // from model (overrides config) | |
| 352 | + "X-Model-Specific": "true", // from model | |
| 353 | + }); | |
| 354 | + }); | |
| 355 | +}); |
| @@ -18,6 +18,7 @@ | ||
| 18 | 18 | import DocsService from "./indexing/docs/DocsService"; |
| 19 | 19 | import { countTokens } from "./llm/countTokens"; |
| 20 | 20 | import Ollama from "./llm/llms/Ollama"; |
| 21 | +import Lemonade from "./llm/llms/Lemonade"; | |
| 21 | 22 | import { EditAggregator } from "./nextEdit/context/aggregateEdits"; |
| 22 | 23 | import { createNewPromptFileV2 } from "./promptFiles/createNewPromptFile"; |
| 23 | 24 | import { callTool } from "./tools/callTool"; |
| @@ -1263,6 +1264,9 @@ | ||
| 1263 | 1264 | if (msg.data.title === "Ollama") { |
| 1264 | 1265 | const models = await new Ollama({ model: "" }).listModels(); |
| 1265 | 1266 | return models; |
| 1267 | + } else if (msg.data.title === "Lemonade") { | |
| 1268 | + const models = await new Lemonade({ model: "" }).listModels(); | |
| 1269 | + return models; | |
| 1266 | 1270 | } else { |
| 1267 | 1271 | return undefined; |
| 1268 | 1272 | } |
| @@ -1348,6 +1352,8 @@ | ||
| 1348 | 1352 | selectedCode, |
| 1349 | 1353 | reranker: config.selectedModelByRole.rerank, |
| 1350 | 1354 | fetch: (url, init) => |
| 1355 | + // Important note: context providers fetch uses global request options not LLM request options | |
| 1356 | + // Because LLM calls are handled separately | |
| 1351 | 1357 | fetchwithRequestOptions(url, init, config.requestOptions), |
| 1352 | 1358 | isInAgentMode: msg.data.isInAgentMode, |
| 1353 | 1359 | }); |
| @@ -1099,6 +1099,7 @@ | ||
| 1099 | 1099 | exampleArgs?: Array<[string, string | number]>; |
| 1100 | 1100 | }; |
| 1101 | 1101 | defaultToolPolicy?: ToolPolicy; |
| 1102 | + toolCallIcon?: string; | |
| 1102 | 1103 | evaluateToolCallPolicy?: ( |
| 1103 | 1104 | basePolicy: ToolPolicy, |
| 1104 | 1105 | parsedArgs: Record<string, unknown>, |
| @@ -1281,6 +1282,7 @@ | ||
| 1281 | 1282 | transport: TransportOptions; |
| 1282 | 1283 | faviconUrl?: string; |
| 1283 | 1284 | timeout?: number; |
| 1285 | + requestOptions?: RequestOptions; | |
| 1284 | 1286 | } |
| 1285 | 1287 | |
| 1286 | 1288 | export type MCPConnectionStatus = |
| @@ -203,6 +203,13 @@ | ||
| 203 | 203 | ...ADDITIONAL_INDEXING_IGNORE_DIRS, |
| 204 | 204 | ]; |
| 205 | 205 | |
| 206 | +export const DEFAULT_IGNORES = [ | |
| 207 | + ...DEFAULT_IGNORE_FILETYPES, | |
| 208 | + ...DEFAULT_IGNORE_DIRS, | |
| 209 | +]; | |
| 210 | + | |
| 211 | +export const defaultIgnoresGlob = `!{${DEFAULT_IGNORES.join(",")}}`; | |
| 212 | + | |
| 206 | 213 | // Create ignore instances |
| 207 | 214 | export const defaultSecurityIgnoreFile = ignore().add( |
| 208 | 215 | DEFAULT_SECURITY_IGNORE_FILETYPES, |
| @@ -45,6 +45,7 @@ | ||
| 45 | 45 | |
| 46 | 46 | const PROVIDER_HANDLES_TEMPLATING: string[] = [ |
| 47 | 47 | "lmstudio", |
| 48 | + "lemonade", | |
| 48 | 49 | "openai", |
| 49 | 50 | "nvidia", |
| 50 | 51 | "ollama", |
| @@ -67,6 +68,7 @@ | ||
| 67 | 68 | const PROVIDER_SUPPORTS_IMAGES: string[] = [ |
| 68 | 69 | "openai", |
| 69 | 70 | "ollama", |
| 71 | + "lemonade", | |
| 70 | 72 | "cohere", |
| 71 | 73 | "gemini", |
| 72 | 74 | "msty", |
| @@ -85,7 +85,7 @@ | ||
| 85 | 85 | |
| 86 | 86 | function countImageTokens(content: MessagePart): number { |
| 87 | 87 | if (content.type === "imageUrl") { |
| 88 | - return 85; | |
| 88 | + return 1024; | |
| 89 | 89 | } |
| 90 | 90 | throw new Error("Non-image content type"); |
| 91 | 91 | } |
| @@ -30,6 +30,7 @@ | ||
| 30 | 30 | TemplateType, |
| 31 | 31 | Usage, |
| 32 | 32 | } from "../index.js"; |
| 33 | +import { isLemonadeInstalled } from "../util/lemonadeHelper.js"; | |
| 33 | 34 | import { Logger } from "../util/Logger.js"; |
| 34 | 35 | import mergeJson from "../util/merge.js"; |
| 35 | 36 | import { renderChatMessage } from "../util/messageContent.js"; |
| @@ -503,6 +504,24 @@ | ||
| 503 | 504 | : "Unable to connect to local Ollama instance. Ollama may not be installed or may not running."; |
| 504 | 505 | throw new Error(message); |
| 505 | 506 | } |
| 507 | + if ( | |
| 508 | + e.code === "ECONNREFUSED" && | |
| 509 | + e.message.includes("http://localhost:8000") | |
| 510 | + ) { | |
| 511 | + const isInstalled = await isLemonadeInstalled(); | |
| 512 | + let message: string; | |
| 513 | + if (process.platform === "linux") { | |
| 514 | + // On Linux, isLemonadeInstalled checks if it's running (via health endpoint) | |
| 515 | + message = | |
| 516 | + "Unable to connect to local Lemonade instance. Please ensure Lemonade is running. Visit http://lemonade-server.ai for setup instructions."; | |
| 517 | + } else { | |
| 518 | + // On Windows, we can check if it's installed | |
| 519 | + message = isInstalled | |
| 520 | + ? "Unable to connect to local Lemonade instance. Lemonade server may not be running." | |
| 521 | + : "Unable to connect to local Lemonade instance. Lemonade may not be installed or may not be running."; | |
| 522 | + } | |
| 523 | + throw new Error(message); | |
| 524 | + } | |
| 506 | 525 | } |
| 507 | 526 | throw e; |
| 508 | 527 | } |
| @@ -537,18 +556,14 @@ | ||
| 537 | 556 | } |
| 538 | 557 | |
| 539 | 558 | private _formatChatMessage(msg: ChatMessage): string { |
| 540 | - let contentToShow = ""; | |
| 541 | - if (msg.role === "tool") { | |
| 542 | - contentToShow = msg.content; | |
| 543 | - } else if (msg.role === "assistant" && msg.toolCalls?.length) { | |
| 544 | - contentToShow = msg.toolCalls | |
| 559 | + let contentToShow = renderChatMessage(msg); | |
| 560 | + if (msg.role === "assistant" && msg.toolCalls?.length) { | |
| 561 | + contentToShow += msg.toolCalls | |
| 545 | 562 | ?.map( |
| 546 | 563 | (toolCall) => |
| 547 | 564 | `${toolCall.function?.name}(${toolCall.function?.arguments})`, |
| 548 | 565 | ) |
| 549 | 566 | .join("\n"); |
| 550 | - } else if ("content" in msg) { | |
| 551 | - contentToShow = renderChatMessage(msg); | |
| 552 | 567 | } |
| 553 | 568 | |
| 554 | 569 | return `<${msg.role}>\n${contentToShow}\n\n`; |
| @@ -68,6 +68,17 @@ | ||
| 68 | 68 | return finalOptions; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | + private buildTextPart(text: string, addCaching: boolean) { | |
| 72 | + const part: any = { | |
| 73 | + type: "text", | |
| 74 | + text, | |
| 75 | + }; | |
| 76 | + if (addCaching) { | |
| 77 | + part.cache_control = { type: "ephemeral" }; | |
| 78 | + } | |
| 79 | + return part; | |
| 80 | + } | |
| 81 | + | |
| 71 | 82 | private convertMessage(message: ChatMessage, addCaching: boolean): any { |
| 72 | 83 | if (message.role === "tool") { |
| 73 | 84 | return { |
| @@ -81,14 +92,30 @@ | ||
| 81 | 92 | ], |
| 82 | 93 | }; |
| 83 | 94 | } else if (message.role === "assistant" && message.toolCalls) { |
| 84 | - return { | |
| 85 | - role: "assistant", | |
| 86 | - content: message.toolCalls.map((toolCall) => ({ | |
| 95 | + const parts: any[] = []; | |
| 96 | + if (message.content) { | |
| 97 | + if (typeof message.content === "string") { | |
| 98 | + parts.push(this.buildTextPart(message.content, addCaching)); | |
| 99 | + } else if (message.content.length > 0) { | |
| 100 | + const textContent = message.content.filter((p) => p.type === "text"); | |
| 101 | + const textParts = textContent.map((part, idx) => { | |
| 102 | + const cache = idx === textContent.length - 1 && addCaching; | |
| 103 | + return this.buildTextPart(part.text, cache); | |
| 104 | + }); | |
| 105 | + parts.push(...textParts); | |
| 106 | + } | |
| 107 | + } | |
| 108 | + parts.push( | |
| 109 | + ...message.toolCalls.map((toolCall) => ({ | |
| 87 | 110 | type: "tool_use", |
| 88 | 111 | id: toolCall.id, |
| 89 | 112 | name: toolCall.function?.name, |
| 90 | 113 | input: safeParseToolCallArgs(toolCall), |
| 91 | 114 | })), |
| 115 | + ); | |
| 116 | + return { | |
| 117 | + role: "assistant", | |
| 118 | + content: parts, | |
| 92 | 119 | }; |
| 93 | 120 | } else if (message.role === "thinking" && !message.redactedThinking) { |
| 94 | 121 | return { |
| @@ -154,9 +181,7 @@ | ||
| 154 | 181 | |
| 155 | 182 | public convertMessages(msgs: ChatMessage[]): any[] { |
| 156 | 183 | // should be public for use within VertexAI |
| 157 | - const filteredmessages = msgs.filter( | |
| 158 | - (m) => m.role !== "system" && !!m.content, | |
| 159 | - ); | |
| 184 | + const filteredmessages = msgs.filter((m) => m.role !== "system"); | |
| 160 | 185 | const lastTwoUserMsgIndices = filteredmessages |
| 161 | 186 | .map((msg, index) => (msg.role === "user" ? index : -1)) |
| 162 | 187 | .filter((index) => index !== -1) |
| @@ -0,0 +1,12 @@ | ||
| 1 | +import { LLMOptions } from "../../index.js"; | |
| 2 | + | |
| 3 | +import OpenAI from "./OpenAI.js"; | |
| 4 | + | |
| 5 | +class Lemonade extends OpenAI { | |
| 6 | + static providerName = "lemonade"; | |
| 7 | + static defaultOptions: Partial<LLMOptions> = { | |
| 8 | + apiBase: "http://localhost:8000/api/v1/", | |
| 9 | + }; | |
| 10 | +} | |
| 11 | + | |
| 12 | +export default Lemonade; |
| @@ -269,6 +269,11 @@ | ||
| 269 | 269 | return this.modelMap[this.model] ?? this.model; |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | + get contextLength() { | |
| 273 | + const DEFAULT_OLLAMA_CONTEXT_LENGTH = 8192; // twice of https://github.com/ollama/ollama/blob/29ddfc2cab7f5a83a96c3133094f67b22e4f27d1/envconfig/config.go#L185 | |
| 274 | + return this._contextLength ?? DEFAULT_OLLAMA_CONTEXT_LENGTH; | |
| 275 | + } | |
| 276 | + | |
| 272 | 277 | private _getModelFileParams( |
| 273 | 278 | options: CompletionOptions, |
| 274 | 279 | ): OllamaModelFileParams { |
| @@ -174,7 +174,7 @@ | ||
| 174 | 174 | protected _getHeaders() { |
| 175 | 175 | return { |
| 176 | 176 | "Content-Type": "application/json", |
| 177 | - Authorization: `Bearer ${this.apiKey}`, | |
| 177 | + ...(this.apiKey && { Authorization: `Bearer ${this.apiKey}` }), | |
| 178 | 178 | "api-key": this.apiKey ?? "", // For Azure |
| 179 | 179 | }; |
| 180 | 180 | } |
| @@ -33,6 +33,7 @@ | ||
| 33 | 33 | import LlamaCpp from "./LlamaCpp"; |
| 34 | 34 | import Llamafile from "./Llamafile"; |
| 35 | 35 | import LlamaStack from "./LlamaStack"; |
| 36 | +import Lemonade from "./Lemonade"; | |
| 36 | 37 | import LMStudio from "./LMStudio"; |
| 37 | 38 | import Mistral from "./Mistral"; |
| 38 | 39 | import MockLLM from "./Mock"; |
| @@ -82,6 +83,7 @@ | ||
| 82 | 83 | LlamaCpp, |
| 83 | 84 | OpenAI, |
| 84 | 85 | OVHcloud, |
| 86 | + Lemonade, | |
| 85 | 87 | LMStudio, |
| 86 | 88 | Mistral, |
| 87 | 89 | Bedrock, |
| @@ -95,7 +95,7 @@ | ||
| 95 | 95 | ...init, |
| 96 | 96 | signal: abortController.signal, |
| 97 | 97 | }, |
| 98 | - config.requestOptions, | |
| 98 | + model.requestOptions, | |
| 99 | 99 | ), |
| 100 | 100 | completionOptions, |
| 101 | 101 | abortController, |
| @@ -374,9 +374,8 @@ | ||
| 374 | 374 | [/o[134]/], |
| 375 | 375 | [/deepseek/, /r1|reasoner/], |
| 376 | 376 | [/gemini/, /2\.5/, /pro/], |
| 377 | - [/gpt/, /4/], | |
| 378 | 377 | [/gpt-5/], |
| 379 | - [/claude/, /sonnet/, /3\.5|3\.7|3-5|3-7|-4/], | |
| 378 | + [/claude/, /sonnet/, /3\.7|3-7|-4/], | |
| 380 | 379 | [/claude/, /opus/, /-4/], |
| 381 | 380 | ]; |
| 382 | 381 | for (const combo of recs) { |
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
| @@ -84,4 +84,5 @@ | ||
| 84 | 84 | ["alwaysApply", "false"], |
| 85 | 85 | ], |
| 86 | 86 | }, |
| 87 | + toolCallIcon: "PencilIcon", | |
| 87 | 88 | }; |
| @@ -30,4 +30,5 @@ | ||
| 30 | 30 | prefix: `To fetch the content of a URL, use the ${BuiltInToolNames.FetchUrlContent} tool. For example, to read the contents of a webpage, you might respond with:`, |
| 31 | 31 | exampleArgs: [["url", "https://example.com"]], |
| 32 | 32 | }, |
| 33 | + toolCallIcon: "GlobeAltIcon", | |
| 33 | 34 | }; |
| @@ -13,7 +13,7 @@ | ||
| 13 | 13 | function: { |
| 14 | 14 | name: BuiltInToolNames.FileGlobSearch, |
| 15 | 15 | description: |
| 16 | - "Search for files recursively in the project using glob patterns. Supports ** for recursive directory search. Output may be truncated; use targeted patterns", | |
| 16 | + "Search for files recursively in the project using glob patterns. Supports ** for recursive directory search. Will not show many build, cache, secrets dirs/files (can use ls tool instead). Output may be truncated; use targeted patterns", | |
| 17 | 17 | parameters: { |
| 18 | 18 | type: "object", |
| 19 | 19 | required: ["pattern"], |
| @@ -30,4 +30,5 @@ | ||
| 30 | 30 | prefix: `To return a list of files based on a glob search pattern, use the ${BuiltInToolNames.FileGlobSearch} tool`, |
| 31 | 31 | exampleArgs: [["pattern", "*.py"]], |
| 32 | 32 | }, |
| 33 | + toolCallIcon: "MagnifyingGlassIcon", | |
| 33 | 34 | }; |
| @@ -13,7 +13,7 @@ | ||
| 13 | 13 | function: { |
| 14 | 14 | name: BuiltInToolNames.GrepSearch, |
| 15 | 15 | description: |
| 16 | - "Perform a search over the repository using ripgrep. Output may be truncated, so use targeted queries", | |
| 16 | + "Perform a search over the repository using ripgrep. Will not include results for many build, cache, secrets dirs/files. Output may be truncated, so use targeted queries", | |
| 17 | 17 | parameters: { |
| 18 | 18 | type: "object", |
| 19 | 19 | required: ["query"], |
| @@ -31,4 +31,5 @@ | ||
| 31 | 31 | prefix: `To perform a grep search within the project, call the ${BuiltInToolNames.GrepSearch} tool with the query pattern to match. For example:`, |
| 32 | 32 | exampleArgs: [["query", ".*main_services.*"]], |
| 33 | 33 | }, |
| 34 | + toolCallIcon: "MagnifyingGlassIcon", | |
| 34 | 35 | }; |
| @@ -38,4 +38,5 @@ | ||
| 38 | 38 | ["recursive", "false"], |
| 39 | 39 | ], |
| 40 | 40 | }, |
| 41 | + toolCallIcon: "FolderIcon", | |
| 41 | 42 | }; |
| @@ -24,4 +24,5 @@ | ||
| 24 | 24 | prefix: `To view the user's currently open file, use the ${BuiltInToolNames.ReadCurrentlyOpenFile} tool. |
| 25 | 25 | If the user is asking about a file and you don't see any code, use this to check the current file`, |
| 26 | 26 | }, |
| 27 | + toolCallIcon: "DocumentTextIcon", | |
| 27 | 28 | }; |
| @@ -31,4 +31,5 @@ | ||
| 31 | 31 | exampleArgs: [["filepath", "path/to/the_file.txt"]], |
| 32 | 32 | }, |
| 33 | 33 | defaultToolPolicy: "allowedWithoutPermission", |
| 34 | + toolCallIcon: "DocumentIcon", | |
| 34 | 35 | }; |
| @@ -48,4 +48,5 @@ | ||
| 48 | 48 | ], |
| 49 | 49 | }, |
| 50 | 50 | defaultToolPolicy: "allowedWithoutPermission", |
| 51 | + toolCallIcon: "DocumentIcon", | |
| 51 | 52 | }; |
| @@ -30,4 +30,5 @@ | ||
| 30 | 30 | prefix: `To search the web, use the ${BuiltInToolNames.SearchWeb} tool with a natural language query. For example, to search for the current weather, you would respond with:`, |
| 31 | 31 | exampleArgs: [["query", "What is the current weather in San Francisco?"]], |
| 32 | 32 | }, |
| 33 | + toolCallIcon: "GlobeAltIcon", | |
| 33 | 34 | }; |
| @@ -23,4 +23,5 @@ | ||
| 23 | 23 | prefix: `To view the current git diff, use the ${BuiltInToolNames.ViewDiff} tool. This will show you the changes made in the working directory compared to the last commit.`, |
| 24 | 24 | }, |
| 25 | 25 | defaultToolPolicy: "allowedWithoutPermission", |
| 26 | + toolCallIcon: "CodeBracketIcon", | |
| 26 | 27 | }; |
| @@ -23,4 +23,5 @@ | ||
| 23 | 23 | prefix: `To view the repository map, use the ${BuiltInToolNames.ViewRepoMap} tool. This will provide a visual representation of the project's structure and organization.`, |
| 24 | 24 | }, |
| 25 | 25 | defaultToolPolicy: "allowedWithPermission", |
| 26 | + toolCallIcon: "MapIcon", | |
| 26 | 27 | }; |
| @@ -30,4 +30,5 @@ | ||
| 30 | 30 | exampleArgs: [["directory_path", "path/to/subdirectory"]], |
| 31 | 31 | }, |
| 32 | 32 | defaultToolPolicy: "allowedWithPermission", |
| 33 | + toolCallIcon: "FolderOpenIcon", | |
| 33 | 34 | }; |
| @@ -1,10 +1,10 @@ | ||
| 1 | 1 | import { ConfigDependentToolParams, Tool } from ".."; |
| 2 | +import { isRecommendedAgentModel } from "../llm/toolSupport"; | |
| 2 | 3 | import * as toolDefinitions from "./definitions"; |
| 3 | 4 | |
| 4 | 5 | // I'm writing these as functions because we've messed up 3 TIMES by pushing to const, causing duplicate tool definitions on subsequent config loads. |
| 5 | 6 | export const getBaseToolDefinitions = () => [ |
| 6 | 7 | toolDefinitions.readFileTool, |
| 7 | - | |
| 8 | 8 | toolDefinitions.createNewFileTool, |
| 9 | 9 | toolDefinitions.runTerminalCommandTool, |
| 10 | 10 | toolDefinitions.globSearchTool, |
| @@ -13,7 +13,6 @@ | ||
| 13 | 13 | toolDefinitions.lsTool, |
| 14 | 14 | toolDefinitions.createRuleBlock, |
| 15 | 15 | toolDefinitions.fetchUrlContentTool, |
| 16 | - toolDefinitions.singleFindAndReplaceTool, | |
| 17 | 16 | ]; |
| 18 | 17 | |
| 19 | 18 | export const getConfigDependentToolDefinitions = ( |
| @@ -38,10 +37,11 @@ | ||
| 38 | 37 | ); |
| 39 | 38 | } |
| 40 | 39 | |
| 41 | - if (modelName?.includes("claude") || modelName?.includes("gpt-5")) { | |
| 40 | + if (modelName && isRecommendedAgentModel(modelName)) { | |
| 42 | 41 | tools.push(toolDefinitions.multiEditTool); |
| 43 | 42 | } else { |
| 44 | 43 | tools.push(toolDefinitions.editFileTool); |
| 44 | + tools.push(toolDefinitions.singleFindAndReplaceTool); | |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | // missing support for remote os calls: https://github.com/microsoft/vscode/issues/252269 |
| @@ -44,9 +44,8 @@ | ||
| 44 | 44 | isSupportedLanceDbCpuTargetForLinux: boolean; |
| 45 | 45 | sharedConfig: SharedConfigSchema; |
| 46 | 46 | failedDocs: SiteIndexingConfig[]; |
| 47 | - shownDeprecatedProviderWarnings: { | |
| 48 | - [providerTitle: string]: boolean; | |
| 49 | - }; | |
| 47 | + shownDeprecatedProviderWarnings: { [providerTitle: string]: boolean }; | |
| 48 | + autoUpdateCli: boolean; | |
| 50 | 49 | mcpOauthStorage: { |
| 51 | 50 | [serverUrl: string]: { |
| 52 | 51 | clientInformation?: OAuthClientInformationFull; |
| @@ -66,16 +65,7 @@ | ||
| 66 | 65 | ) { |
| 67 | 66 | const filepath = getGlobalContextFilePath(); |
| 68 | 67 | if (!fs.existsSync(filepath)) { |
| 69 | - fs.writeFileSync( | |
| 70 | - filepath, | |
| 71 | - JSON.stringify( | |
| 72 | - { | |
| 73 | - [key]: value, | |
| 74 | - }, | |
| 75 | - null, | |
| 76 | - 2, | |
| 77 | - ), | |
| 78 | - ); | |
| 68 | + fs.writeFileSync(filepath, JSON.stringify({ [key]: value }, null, 2)); | |
| 79 | 69 | } else { |
| 80 | 70 | const data = fs.readFileSync(filepath, "utf-8"); |
| 81 | 71 | |
| @@ -113,10 +103,7 @@ | ||
| 113 | 103 | } |
| 114 | 104 | |
| 115 | 105 | // Recreate the file with salvaged values plus the new value |
| 116 | - const newData = { | |
| 117 | - ...salvaged, | |
| 118 | - [key]: value, | |
| 119 | - }; | |
| 106 | + const newData = { ...salvaged, [key]: value }; | |
| 120 | 107 | |
| 121 | 108 | fs.writeFileSync(filepath, JSON.stringify(newData, null, 2)); |
| 122 | 109 | return; |
| @@ -174,10 +161,7 @@ | ||
| 174 | 161 | newValues: Partial<SharedConfigSchema>, |
| 175 | 162 | ): SharedConfigSchema { |
| 176 | 163 | const currentSharedConfig = this.getSharedConfig(); |
| 177 | - const updatedSharedConfig = { | |
| 178 | - ...currentSharedConfig, | |
| 179 | - ...newValues, | |
| 180 | - }; | |
| 164 | + const updatedSharedConfig = { ...currentSharedConfig, ...newValues }; | |
| 181 | 165 | this.update("sharedConfig", updatedSharedConfig); |
| 182 | 166 | return updatedSharedConfig; |
| 183 | 167 | } |
| @@ -189,10 +173,7 @@ | ||
| 189 | 173 | ): GlobalContextModelSelections { |
| 190 | 174 | const currentSelections = this.get("selectedModelsByProfileId") ?? {}; |
| 191 | 175 | const forProfile = currentSelections[profileId] ?? {}; |
| 192 | - const newSelections = { | |
| 193 | - ...forProfile, | |
| 194 | - [role]: title, | |
| 195 | - }; | |
| 176 | + const newSelections = { ...forProfile, [role]: title }; | |
| 196 | 177 | |
| 197 | 178 | this.update("selectedModelsByProfileId", { |
| 198 | 179 | ...currentSelections, |
| @@ -0,0 +1,59 @@ | ||
| 1 | +import { exec } from "node:child_process"; | |
| 2 | +import { IDE } from ".."; | |
| 3 | + | |
| 4 | +export async function isLemonadeInstalled(): Promise<boolean> { | |
| 5 | + // On Windows, check if lemonade-server command exists | |
| 6 | + if (process.platform === "win32") { | |
| 7 | + return new Promise((resolve, _reject) => { | |
| 8 | + exec("where.exe lemonade-server", (error, _stdout, _stderr) => { | |
| 9 | + resolve(!error); | |
| 10 | + }); | |
| 11 | + }); | |
| 12 | + } | |
| 13 | + | |
| 14 | + // On Linux, check if the health endpoint is accessible | |
| 15 | + try { | |
| 16 | + const response = await fetch("http://localhost:8000/api/v1/health", { | |
| 17 | + method: "GET", | |
| 18 | + signal: AbortSignal.timeout(3000), // 3 second timeout | |
| 19 | + }); | |
| 20 | + | |
| 21 | + if (response.ok) { | |
| 22 | + const data = await response.json(); | |
| 23 | + return data.status === "ok"; | |
| 24 | + } | |
| 25 | + return false; | |
| 26 | + } catch { | |
| 27 | + return false; | |
| 28 | + } | |
| 29 | +} | |
| 30 | + | |
| 31 | +export async function startLocalLemonade(ide: IDE): Promise<any> { | |
| 32 | + let startCommand: string | undefined; | |
| 33 | + | |
| 34 | + switch (process.platform) { | |
| 35 | + case "linux": // Linux | |
| 36 | + // On Linux, direct users to start Lemonade manually | |
| 37 | + return ide.showToast( | |
| 38 | + "info", | |
| 39 | + "Please start Lemonade manually. Visit https://lemonade-server.ai for instructions.", | |
| 40 | + ); | |
| 41 | + | |
| 42 | + case "win32": // Windows | |
| 43 | + startCommand = "lemonade-server serve\n"; | |
| 44 | + break; | |
| 45 | + | |
| 46 | + default: | |
| 47 | + return ide.showToast( | |
| 48 | + "error", | |
| 49 | + "Cannot start Lemonade: platform not supported!", | |
| 50 | + ); | |
| 51 | + } | |
| 52 | + | |
| 53 | + if (startCommand) { | |
| 54 | + return ide.runCommand(startCommand, { | |
| 55 | + reuseTerminal: true, | |
| 56 | + terminalName: "Start Lemonade", | |
| 57 | + }); | |
| 58 | + } | |
| 59 | +} |
Binary content is not shown. View the file.
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
Binary content is not shown. View the file.
| @@ -0,0 +1,81 @@ | ||
| 1 | +--- | |
| 2 | +title: "Lemonade Server" | |
| 3 | +description: "Configure Lemonade Server with Continue for refreshingly fast local LLM inference on GPUs and NPUs" | |
| 4 | +--- | |
| 5 | + | |
| 6 | +<Info> | |
| 7 | + Get started with [Lemonade Server](https://lemonade-server.ai/) - Refreshingly fast LLMs on GPUs and NPUs with seamless Continue integration | |
| 8 | +</Info> | |
| 9 | + | |
| 10 | +## Overview | |
| 11 | + | |
| 12 | +Lemonade Server provides optimized local LLM inference with support for GPU and NPU hardware acceleration. It offers an OpenAI-compatible API that seamlessly integrates with Continue and other open-source platforms. | |
| 13 | + | |
| 14 | +## Installation | |
| 15 | + | |
| 16 | +Download and install Lemonade Server from [lemonade-server.ai](https://lemonade-server.ai/). | |
| 17 | + | |
| 18 | +## Configuration | |
| 19 | + | |
| 20 | +Lemonade Server is available directly in the Continue UI as a provider. You can select it from the model provider dropdown without manual configuration. | |
| 21 | + | |
| 22 | +### Option 1: Using the Continue UI (Recommended) | |
| 23 | + | |
| 24 | +1. Click on the model selector dropdown in Continue | |
| 25 | +2. Select "Add Model" | |
| 26 | +3. Choose "Lemonade Server" from the provider list | |
| 27 | +4. Continue will automatically configure the connection | |
| 28 | + | |
| 29 | +### Option 2: Manual Configuration | |
| 30 | + | |
| 31 | +If you need custom settings, you can manually configure Lemonade: | |
| 32 | + | |
| 33 | +<Tabs> | |
| 34 | + <Tab title="YAML"> | |
| 35 | + ```yaml title="config.yaml" | |
| 36 | + models: | |
| 37 | + - name: Lemonade | |
| 38 | + provider: lemonade | |
| 39 | + model: <MODEL_NAME> | |
| 40 | + apiBase: http://localhost:8000/api/v1/ | |
| 41 | + ``` | |
| 42 | + </Tab> | |
| 43 | + <Tab title="JSON (Deprecated)"> | |
| 44 | + ```json title="config.json" | |
| 45 | + { | |
| 46 | + "models": [ | |
| 47 | + { | |
| 48 | + "title": "Lemonade", | |
| 49 | + "provider": "lemonade", | |
| 50 | + "model": "<MODEL_NAME>", | |
| 51 | + "apiBase": "http://localhost:8000/api/v1/" | |
| 52 | + } | |
| 53 | + ] | |
| 54 | + } | |
| 55 | + ``` | |
| 56 | + </Tab> | |
| 57 | +</Tabs> | |
| 58 | + | |
| 59 | +## Getting Started | |
| 60 | + | |
| 61 | +1. **Install Lemonade Server**: Download from [lemonade-server.ai](https://lemonade-server.ai/) | |
| 62 | +2. **Start the server**: Launch Lemonade Server (runs on `http://localhost:8000/api/v1/` by default) | |
| 63 | +3. **Add to Continue**: Select Lemonade Server from the model provider dropdown in Continue | |
| 64 | +4. **Load a model**: Choose your preferred model through the interface | |
| 65 | + | |
| 66 | +## Hardware Support | |
| 67 | + | |
| 68 | +Lemonade Server automatically detects and optimizes for available hardware: | |
| 69 | +- **NPU**: Neural Processing Unit acceleration for efficient inference | |
| 70 | +- **GPU**: Full GPU acceleration support | |
| 71 | +- **CPU**: Optimized CPU fallback when accelerators are unavailable | |
| 72 | + | |
| 73 | +## Key Features | |
| 74 | + | |
| 75 | +- OpenAI-compatible API for seamless integration | |
| 76 | +- Support for popular model formats | |
| 77 | +- Automatic hardware detection and optimization | |
| 78 | +- Integration with Continue, Open WebUI, Gaia, and AnythingLLM | |
| 79 | +- Active open-source community | |
| 80 | + | |
| 81 | +[View the source](https://github.com/continuedev/continue/blob/main/core/llm/llms/Lemonade.ts) | |
| No newline at the end of the file |
| @@ -3,81 +3,250 @@ | ||
| 3 | 3 | sidebarTitle: "Tetrate Agent Router Service" |
| 4 | 4 | slug: ../tetrate-agent-router-service |
| 5 | 5 | --- |
| 6 | - | |
| 7 | -The **Tetrate Agent Router Service** provides a unified Gateway for accessing various AI models with fast inference capabilities as well as embedding services. | |
| 6 | +The **Tetrate Agent Router Service** provides a unified Gateway for accessing various AI models with fast inference capabilities. | |
| 8 | 7 | |
| 9 | 8 | This gateway acts as an intelligent router that can distribute requests across multiple model providers, offering enterprise-grade reliability and performance optimization. |
| 10 | 9 | |
| 11 | -## Getting Started | |
| 10 | +<Tip> | |
| 11 | +Want to get started quickly? Sign up for the [Tetrate Agent Router Service](https://router.tetrate.ai/) to get an API key, then use [Tetrate on Continue Hub](https://hub.continue.dev/tetrate) to get started fast. | |
| 12 | +</Tip> | |
| 12 | 13 | |
| 13 | -1. Obtain an API key from the [Agent Router Service portal](https://api.router.tetrate.ai/) | |
| 14 | -2. Configure Continue to use Agent Router Service as your model provider | |
| 14 | +## Setup | |
| 15 | 15 | |
| 16 | -## Configuring Models | |
| 16 | +<Steps> | |
| 17 | +<Step title="Sign in or sign up"> | |
| 18 | +Visit the [Agent Router Service portal](https://router.tetrate.ai/) and create an account to get your API key | |
| 19 | +<img src="../assets/tetrate-sign-in.png" alt="Tetrate sign in page" style={{width: '250px', maxWidth: '100%'}} /> | |
| 20 | +</Step> | |
| 17 | 21 | |
| 18 | -You can also quickly use models from Tetrate on the Cotninue Hub by visiting Tetrate on the Continue Hub [here](https://hub.continue.dev/tetrate). The easiest way if you don't see the model you want to use is to remix one of the models on the Tetrate page and change the model to the one you want to use. | |
| 22 | +<Step title="Get your API key"> | |
| 23 | +Go to the [API keys page](https://router.tetrate.ai/api-keys) to get your key | |
| 24 | +<img src="../assets/tetrate-get-api-key.png" alt="Tetrate get API key" style={{width: '250px', maxWidth: '100%'}} /> | |
| 25 | +</Step> | |
| 19 | 26 | |
| 20 | - | |
| 27 | +<Step title="Configure Continue"> | |
| 28 | +- Choose a configuration method below. | |
| 29 | +- If you use the Continue VS Code extension, install version `>=1.2.3`. | |
| 30 | +</Step> | |
| 31 | + | |
| 32 | +</Steps> | |
| 21 | 33 | |
| 22 | -### Available Models | |
| 23 | 34 | |
| 24 | -Agent Router Service supports routing to various models. | |
| 25 | -Go to the [Agent Router Service model catalog](https://router.tetrate.ai/models) for a full list of supported models. | |
| 35 | +### Quickstart with Continue Hub | |
| 26 | 36 | |
| 27 | -## Configuration Options | |
| 37 | +Fastest way: use preconfigured models from Tetrate on Continue Hub | |
| 28 | 38 | |
| 29 | -As Agent Router Service is an OpenAI API compatible provider, you can configure it like any other OpenAI API compatible provider. Therefore you will be setting `provider: openai` and `apiBase: https://api.router.tetrate.ai/v1`. | |
| 39 | +<Steps> | |
| 40 | +<Step title="Browse models"> | |
| 41 | +Open [Tetrate on Continue Hub](https://hub.continue.dev/tetrate) and pick a model (e.g., [Claude Sonnet 4](https://hub.continue.dev/tetrate/claude-sonnet-4)) | |
| 42 | +</Step> | |
| 30 | 43 | |
| 31 | -Update your Continue configuration file (`~/.continue/config.yaml`) with your Agent Router Service API key: | |
| 44 | +<Step title="Use or remix"> | |
| 45 | +Click "Use Model", or "Remix" to change the model ID if needed | |
| 46 | +</Step> | |
| 32 | 47 | |
| 33 | -### On your local machine | |
| 48 | +<Step title="Add your API key"> | |
| 49 | +Add your API key to Continue. See [adding secrets in Continue Hub](/hub/secrets/secret-types) and [managing local secrets in the FAQ](/faqs#managing-local-secrets-and-environment-variables) | |
| 50 | +<Tip> | |
| 51 | +Add it as a Continue Hub secret named `TETRATE_API_KEY` to reuse across projects. | |
| 52 | +</Tip> | |
| 53 | +</Step> | |
| 54 | +</Steps> | |
| 34 | 55 | |
| 35 | -#### In your config.yaml | |
| 56 | + | |
| 36 | 57 | |
| 37 | -```yaml title="config.yaml" | |
| 58 | +<Info> | |
| 59 | +If a model is missing, remix a similar one and set the `model` field to the target ID. | |
| 60 | +</Info> | |
| 61 | + | |
| 62 | +### Configuration Methods | |
| 63 | + | |
| 64 | +<CardGroup cols={1}> | |
| 65 | + <Card title="In Local Agent Configuration" icon="folder" vertical> | |
| 66 | + Use a Tetrate model block from the Hub or define it directly in your local agent configuration. | |
| 67 | + </Card> | |
| 68 | + <Card title="Continue Hub" icon="cloud" vertical> | |
| 69 | + Use a Tetrate model block from the Hub or define your own on the Hub. | |
| 70 | + </Card> | |
| 71 | + <Card title="Using Local Model Blocks" icon="file-lines" vertical> | |
| 72 | + Create a local model block for reuse across agents without publishing it to the Hub. | |
| 73 | + </Card> | |
| 74 | +</CardGroup> | |
| 75 | + | |
| 76 | + | |
| 77 | +### Configuration Examples | |
| 78 | +<Info> | |
| 79 | +**Click a tab** to see an example. | |
| 80 | +</Info> | |
| 81 | +<Tabs> | |
| 82 | +<Tab title="In Local Agent Configuration"> | |
| 83 | + | |
| 84 | +**When to use**: Simple local setups (like using the VS Code extension) when you don't need shared or published blocks. | |
| 85 | + | |
| 86 | +Use a Tetrate model block from the Hub in your local agent configuration: | |
| 87 | + | |
| 88 | +```yaml title="~/.continue/config.yaml" | |
| 89 | +name: Local Agent | |
| 90 | +version: 1.0.0 | |
| 91 | +schema: v1 | |
| 38 | 92 | models: |
| 39 | - - name: <MODEL_NAME> | |
| 40 | - provider: openai | |
| 41 | - model: <MODEL_ID> | |
| 42 | - apiKey: <TETRATE_API_KEY> | |
| 43 | - apiBase: https://api.router.tetrate.ai/v1 | |
| 93 | + - uses: tetrate/claude-sonnet-4 | |
| 94 | + with: | |
| 95 | + TETRATE_API_KEY: ${{ secrets.TETRATE_API_KEY }} | |
| 96 | +context: | |
| 97 | + - provider: code | |
| 98 | + - provider: docs | |
| 99 | + - provider: diff | |
| 100 | + - provider: terminal | |
| 101 | + - provider: problems | |
| 102 | + - provider: folder | |
| 103 | + - provider: codebase | |
| 44 | 104 | ``` |
| 45 | 105 | |
| 46 | -#### As a local model block | |
| 47 | - | |
| 48 | -Review the configuration reference for [model blocks](/reference#models) and using [local blocks](/reference#local-blocks). Ensure you look at the roles and capabilities section and review the [model capabilities guide](/customize/deep-dives/model-capabilities). | |
| 49 | - | |
| 50 | -```yaml title="model_name.yaml" | |
| 51 | - name: <MODEL_NAME> | |
| 52 | - models: | |
| 53 | - - name: <MODEL_NAME> | |
| 54 | - provider: openai | |
| 55 | - model: <MODEL_ID> | |
| 56 | - apiKey: ${{ inputs.TETRATE_API_KEY }} | |
| 57 | - apiBase: https://api.router.tetrate.ai/v1 | |
| 58 | - roles: | |
| 59 | - - chat | |
| 60 | - - edit | |
| 61 | - - apply | |
| 62 | - capabilities: | |
| 63 | - - tool_use | |
| 106 | +Or define the model directly: | |
| 107 | + | |
| 108 | +```yaml title="~/.continue/config.yaml" | |
| 109 | +name: Local Agent | |
| 110 | +version: 1.0.0 | |
| 111 | +schema: v1 | |
| 112 | +models: | |
| 113 | + - name: Claude Sonnet 4 | |
| 114 | + provider: tars | |
| 115 | + model: claude-4-sonnet-20250514 | |
| 116 | + apiKey: ${{ secrets.TETRATE_API_KEY }} | |
| 117 | + roles: | |
| 118 | + - chat | |
| 119 | + - edit | |
| 120 | + - apply | |
| 121 | + capabilities: | |
| 122 | + - tool_use | |
| 123 | +context: | |
| 124 | + - provider: code | |
| 125 | + - provider: docs | |
| 126 | + - provider: diff | |
| 127 | + - provider: terminal | |
| 128 | + - provider: problems | |
| 129 | + - provider: folder | |
| 130 | + - provider: codebase | |
| 131 | +``` | |
| 132 | +</Tab> | |
| 133 | +<Tab title="Continue Hub"> | |
| 134 | +**When to use**: Share configurations across teams or contribute to the community. | |
| 135 | + | |
| 136 | +**The Model Block:** | |
| 137 | + | |
| 138 | +```yaml title="tetrate/claude-sonnet-4" | |
| 139 | +name: Claude Sonnet 4 | |
| 140 | +version: 1.0.14 | |
| 141 | +schema: v1 | |
| 142 | +models: | |
| 143 | + - name: Claude Sonnet 4 - Tetrate | |
| 144 | + provider: tars | |
| 145 | + model: claude-4-sonnet-20250514 | |
| 146 | + apiKey: ${{ inputs.TETRATE_API_KEY }} | |
| 147 | + roles: | |
| 148 | + - chat | |
| 149 | + - edit | |
| 150 | + - apply | |
| 151 | + capabilities: | |
| 152 | + - tool_use | |
| 64 | 153 | ``` |
| 154 | +View the model block `tetrate/claude-sonnet-4` on the [Continue Hub](https://hub.continue.dev/tetrate/claude-sonnet-4). | |
| 65 | 155 | |
| 66 | -### On Model Block on Continue Hub | |
| 67 | -Learn how to use model blocks on Continue Hub [here](/hub/blocks/create-a-block). | |
| 68 | - | |
| 69 | -```yaml title="model_name.yaml" | |
| 70 | - name: <MODEL_NAME> | |
| 71 | - models: | |
| 72 | - - name: <MODEL_NAME> | |
| 73 | - provider: openai | |
| 74 | - model: <MODEL_ID> | |
| 75 | - apiKey: ${{ inputs.TETRATE_API_KEY }} | |
| 76 | - apiBase: https://api.router.tetrate.ai/v1 | |
| 77 | - roles: | |
| 78 | - - chat | |
| 79 | - - edit | |
| 80 | - - apply | |
| 81 | - capabilities: | |
| 82 | - - tool_use | |
| 156 | +**Reference it in your Agent configuration:** | |
| 157 | + | |
| 158 | +```yaml title="my-agent" | |
| 159 | +name: My Agent | |
| 160 | +version: 1.0.0 | |
| 161 | +schema: v1 | |
| 162 | +models: | |
| 163 | + - uses: tetrate/claude-sonnet-4 | |
| 164 | + with: | |
| 165 | + TETRATE_API_KEY: ${{ secrets.TETRATE_API_KEY }} | |
| 166 | +context: | |
| 167 | + - uses: continuedev/diff-context | |
| 168 | + - uses: continuedev/terminal-context | |
| 169 | + - uses: continuedev/file-context | |
| 170 | +``` | |
| 171 | +<Tip> | |
| 172 | +To customize, see the [model block creation guide](/hub/blocks/create-a-block). | |
| 173 | +</Tip> | |
| 174 | + | |
| 175 | +</Tab> | |
| 176 | + | |
| 177 | +<Tab title="Using Local Model Blocks"> | |
| 178 | +**When to use**: Reuse configurations across agents and keep them local or in GitHub (not on Continue Hub). | |
| 179 | + | |
| 180 | +**The Local Model Block:** | |
| 181 | +<Info> | |
| 182 | +Name the file `my-claude-4-model.yaml` so you can reference it in the Agent. | |
| 183 | +</Info> | |
| 184 | + | |
| 185 | +```yaml title="~/.continue/models/my-claude-4-model.yaml" | |
| 186 | +name: Claude Sonnet 4 | |
| 187 | +version: 1.0.1 | |
| 188 | +schema: v1 | |
| 189 | +models: | |
| 190 | + - name: Claude Sonnet 4 | |
| 191 | + provider: tars | |
| 192 | + model: claude-4-sonnet-20250514 | |
| 193 | + apiKey: ${{ inputs.TETRATE_API_KEY }} | |
| 194 | + roles: | |
| 195 | + - chat | |
| 196 | + - edit | |
| 197 | + - apply | |
| 198 | + capabilities: | |
| 199 | + - tool_use | |
| 200 | +``` | |
| 201 | +Reference it as `my-claude-4-model` in your Agent configuration: | |
| 202 | + | |
| 203 | +```yaml title="~/.continue/agents/simple-agent.yaml" | |
| 204 | +name: Simple Agent | |
| 205 | +version: 1.0.0 | |
| 206 | +schema: v1 | |
| 207 | +models: | |
| 208 | + - uses: my-claude-4-model | |
| 209 | + with: | |
| 210 | + TETRATE_API_KEY: ${{ secrets.TETRATE_API_KEY }} | |
| 211 | +context: | |
| 212 | + - uses: continuedev/diff-context | |
| 213 | + - uses: continuedev/terminal-context | |
| 214 | + - uses: continuedev/file-context | |
| 83 | 215 | ``` |
| 216 | + | |
| 217 | +<Tip> | |
| 218 | +Learn more about [model blocks](/reference#models) and [local blocks](/reference#local-blocks). | |
| 219 | +</Tip> | |
| 220 | + | |
| 221 | +</Tab> | |
| 222 | +</Tabs> | |
| 223 | + | |
| 224 | +--- | |
| 225 | + | |
| 226 | +## Troubleshooting Common Issues | |
| 227 | + | |
| 228 | +<CardGroup cols={2}> | |
| 229 | + <Card title="Invalid API key" icon="key" vertical> | |
| 230 | + Verify your API key is active and has no extra spaces. | |
| 231 | + </Card> | |
| 232 | + <Card title="Model not found" icon="ban" href="https://router.tetrate.ai/models" vertical> | |
| 233 | + Confirm the model ID matches the Tetrate catalog. | |
| 234 | + </Card> | |
| 235 | + <Card title="Slow responses" icon="code" vertical> | |
| 236 | + Check your network or try a less-loaded model. Contact Tetrate support if issues persist. | |
| 237 | + </Card> | |
| 238 | + <Card title="Configuration not loading" icon="file-lines" vertical> | |
| 239 | + Validate YAML syntax and review error messages in Continue. If using Hub, ensure the block is published. | |
| 240 | + </Card> | |
| 241 | +</CardGroup> | |
| 242 | + | |
| 243 | +--- | |
| 244 | + | |
| 245 | +## Join the Community | |
| 246 | +Connect with Tetrate and other builders for help and discussion. | |
| 247 | + | |
| 248 | +<CardGroup cols={1}> | |
| 249 | + <Card title="Join the Tetrate Community" icon="slack" href="https://join.slack.com/t/tetrate-agent-router/shared_invite/zt-399tv7hjm-6YMXztGywTOQrMIolvEBNg"> | |
| 250 | +Get answers, insights, and best practices for secure, scalable infrastructure | |
| 251 | + </Card> | |
| 252 | +</CardGroup> |
| @@ -233,6 +233,7 @@ | ||
| 233 | 233 | "guides/codebase-documentation-awareness", |
| 234 | 234 | "guides/cli", |
| 235 | 235 | "guides/continuous-ai", |
| 236 | + "guides/posthog-github-continuous-ai", | |
| 236 | 237 | "guides/continuous-ai-readiness-assessment", |
| 237 | 238 | "guides/plan-mode-guide", |
| 238 | 239 | "guides/ollama-guide", |
| @@ -354,10 +355,6 @@ | ||
| 354 | 355 | "source": "/hub/blocks", |
| 355 | 356 | "destination": "/hub/blocks/intro" |
| 356 | 357 | }, |
| 357 | - { | |
| 358 | - "source": "/hub/agents/intro", | |
| 359 | - "destination": "/hub/agents/intro" | |
| 360 | - }, | |
| 361 | 358 | { |
| 362 | 359 | "source": "/customize", |
| 363 | 360 | "destination": "/customization/overview" |
| @@ -14,6 +14,7 @@ | ||
| 14 | 14 | - [Continuous AI: A Developer's Guide](/guides/continuous-ai) - Integrating AI into development workflows |
| 15 | 15 | - [How to Use Continue CLI (cn)](/guides/cli) - Command-line interface for Continue |
| 16 | 16 | - [Continuous AI Readiness Assessment](/guides/continuous-ai-readiness-assessment) - Evaluate team readiness for Continuous AI adoption |
| 17 | +- [PostHog Session Analysis with Continue CLI](/guides/posthog-github-continuous-ai) - Analyze user behavior data to optimize your codebase with automatic issue creation | |
| 17 | 18 | |
| 18 | 19 | ## What Advanced Tutorials Are Available |
| 19 | 20 |
| @@ -0,0 +1,496 @@ | ||
| 1 | +--- | |
| 2 | +title: "Building a Continuous AI Workflow with PostHog and GitHub" | |
| 3 | +description: "Build an automated system that continuously monitors PostHog session recordings, analyzes UX issues using Continue CLI, and creates GitHub issues automatically." | |
| 4 | +sidebarTitle: "PostHog Session Analysis with Continue CLI" | |
| 5 | +--- | |
| 6 | + | |
| 7 | +<Card title="What You'll Build" icon="robot"> | |
| 8 | + A fully automated workflow that uses Continue CLI to fetch PostHog session | |
| 9 | + data, analyze user experience issues with AI, and automatically create GitHub | |
| 10 | + issues with specific technical recommendations | |
| 11 | +</Card> | |
| 12 | + | |
| 13 | +## Prerequisites | |
| 14 | + | |
| 15 | +Before starting, ensure you have: | |
| 16 | + | |
| 17 | +- GitHub repository where you want to create issues | |
| 18 | +- PostHog account with **[session recordings enabled and collecting data](https://posthog.com/docs/session-replay/installation)** | |
| 19 | +- Node.js 18+ installed locally | |
| 20 | +- Continue CLI account with **active credits** (required for API usage) | |
| 21 | + | |
| 22 | +<Steps> | |
| 23 | + <Step title="Install Continue CLI"> | |
| 24 | + ```bash | |
| 25 | + npm i -g @continuedev/cli | |
| 26 | + ``` | |
| 27 | + </Step> | |
| 28 | + | |
| 29 | + <Step title="Set up Continue CLI Account & API Key"> | |
| 30 | + 1. Visit [Continue Organizations](https://hub.continue.dev/settings/organizations) | |
| 31 | + 2. Sign up or log in to your Continue account | |
| 32 | + 3. Navigate to your organization settings | |
| 33 | + 4. Click **"API Keys"** and then **"+ New API Key"** | |
| 34 | + 5. Copy the API key immediately (you won't see it again!) | |
| 35 | + 6. Login to the CLI: `cn login` | |
| 36 | + </Step> | |
| 37 | + | |
| 38 | + <Step title="Add Required Secrets to Continue CLI"> | |
| 39 | + Continue CLI will securely store your API keys as secrets that can be referenced in prompts. | |
| 40 | + </Step> | |
| 41 | +</Steps> | |
| 42 | + | |
| 43 | +<Tip> | |
| 44 | + Continue CLI handles all the complex API interactions - you just need to | |
| 45 | + provide the right prompts! | |
| 46 | +</Tip> | |
| 47 | + | |
| 48 | +## Step 1: Set Up Your Credentials | |
| 49 | + | |
| 50 | +First, you'll need to gather your API credentials and add them as secrets in Continue CLI. | |
| 51 | + | |
| 52 | +### Get Your PostHog API Credentials | |
| 53 | + | |
| 54 | +You need a **Personal API Key** (not a Project API key) to access session recordings: | |
| 55 | + | |
| 56 | +1. Go to [Personal API Keys](https://app.posthog.com/settings/user-api-keys) in PostHog | |
| 57 | +2. Click **+ Create a personal API Key** | |
| 58 | +3. Name it "Continue CLI Session Analysis" | |
| 59 | +4. Select these scopes: | |
| 60 | + - `session_recording:read` - **Required** for accessing session data | |
| 61 | + - `insight:read` - Optional, for additional analytics | |
| 62 | +5. Copy the key immediately (you won't see it again!) | |
| 63 | + | |
| 64 | +<Tip> | |
| 65 | + **Find Your Project Details**: Your Project ID is in your PostHog URL: | |
| 66 | + `https://app.posthog.com/project/YOUR_PROJECT_ID` | |
| 67 | +</Tip> | |
| 68 | + | |
| 69 | +### Get Your GitHub Personal Access Token | |
| 70 | + | |
| 71 | +1. Go to [GitHub Personal Access Tokens](https://github.com/settings/personal-access-tokens/new) | |
| 72 | +2. Click **"Generate new token (classic)"** | |
| 73 | +3. Name it "Continue CLI PostHog Analysis" | |
| 74 | +4. Select these scopes: | |
| 75 | + - `repo` (or just `public_repo` if your repository is public) | |
| 76 | + - `issues:write` - **Required** for creating issues | |
| 77 | +5. Copy the token immediately | |
| 78 | + | |
| 79 | +### Add Secrets to Continue CLI | |
| 80 | + | |
| 81 | +Use Continue CLI's built-in environment setup helper: | |
| 82 | + | |
| 83 | +```bash | |
| 84 | +cn -p "Help me set up my environment for PostHog session analysis. Please: | |
| 85 | +1. Check if I have the required secrets configured in Continue CLI: | |
| 86 | + - POSTHOG_API_KEY | |
| 87 | + - POSTHOG_PROJECT_ID | |
| 88 | + - POSTHOG_HOST | |
| 89 | + - GITHUB_PAT | |
| 90 | +2. If any are missing, guide me through: | |
| 91 | + - How to get PostHog Personal API Key from PostHog settings | |
| 92 | + - How to find my PostHog Project ID from the URL | |
| 93 | + - How to create a GitHub Personal Access Token with issues:write permission | |
| 94 | + - How to add these as secrets in Continue CLI | |
| 95 | +3. Help me identify my GitHub repository owner and name by: | |
| 96 | + - Checking git remote origin URL | |
| 97 | + - Or asking me to provide them | |
| 98 | +4. Test the API connections by making a simple API call to both PostHog and GitHub to verify the credentials work. | |
| 99 | +Please walk me through this setup process step by step." | |
| 100 | +``` | |
| 101 | + | |
| 102 | +<Info> | |
| 103 | + Continue CLI will guide you through adding secrets and testing your API | |
| 104 | + connections. Follow the prompts to add: - `POSTHOG_API_KEY`: Your PostHog | |
| 105 | + Personal API Key - `POSTHOG_PROJECT_ID`: Your PostHog Project ID - | |
| 106 | + `POSTHOG_HOST`: `https://us.posthog.com` (or your custom PostHog host) - | |
| 107 | + `GITHUB_PAT`: Your GitHub Personal Access Token | |
| 108 | +</Info> | |
| 109 | + | |
| 110 | +## Step 2: Analyze PostHog Sessions with Continue CLI | |
| 111 | + | |
| 112 | +Now you'll use Continue CLI to fetch PostHog session data and analyze it for UX issues. Continue CLI handles all the API calls and analysis automatically. | |
| 113 | + | |
| 114 | +### Run the Analysis | |
| 115 | + | |
| 116 | +Use this prompt with Continue CLI to fetch and analyze your PostHog sessions: | |
| 117 | + | |
| 118 | +```bash | |
| 119 | +cn -p "I need you to help me analyze PostHog session recordings to identify UX issues. Please: | |
| 120 | + | |
| 121 | +1. First, fetch session recordings from PostHog using these details: | |
| 122 | + - Use the POSTHOG_API_KEY, POSTHOG_PROJECT_ID, and POSTHOG_HOST from my secrets | |
| 123 | + - API endpoint: {POSTHOG_HOST}/api/projects/{POSTHOG_PROJECT_ID}/session_recordings/?limit=20 | |
| 124 | + - Include Authorization header: 'Bearer {POSTHOG_API_KEY}' | |
| 125 | + | |
| 126 | +2. Filter the sessions to find problematic ones with either: | |
| 127 | + - console_error_count > 0 (JavaScript errors) | |
| 128 | + - recording_duration > 300 (sessions longer than 5 minutes) | |
| 129 | + | |
| 130 | +3. Analyze the filtered sessions and create exactly 3 GitHub issues for the most critical UX problems. | |
| 131 | + | |
| 132 | +4. Format each issue like this: | |
| 133 | +### 1. **Issue Title Here** | |
| 134 | +**Problem**: One sentence describing the user problem | |
| 135 | +**Technical Causes**: Brief technical explanation | |
| 136 | +**Affected Pages**: List the URLs | |
| 137 | +**Recommended Fix**: | |
| 138 | +- Specific action item 1 | |
| 139 | +- Specific action item 2 | |
| 140 | +**Priority**: **HIGH** or **MEDIUM** or **LOW** | |
| 141 | +**Impact**: Quantify the impact (e.g., 'Affects 80% of sessions') | |
| 142 | + | |
| 143 | +Please make the API call, analyze the data, and provide the 3 formatted issues. Base all recommendations on actual patterns in the session data." | |
| 144 | +``` | |
| 145 | + | |
| 146 | +<Info> | |
| 147 | + **What Continue CLI Does:** - Makes authenticated API calls to PostHog using | |
| 148 | + your stored secrets - Fetches and filters session recordings automatically - | |
| 149 | + Analyzes patterns in the data using AI - Generates structured issue | |
| 150 | + descriptions ready for GitHub | |
| 151 | +</Info> | |
| 152 | + | |
| 153 | +<Tip> | |
| 154 | + Save the analysis output to a file by adding `> analysis-results.txt` to the | |
| 155 | + command if you want to review it later. | |
| 156 | +</Tip> | |
| 157 | + | |
| 158 | +## Step 3: Create GitHub Issues Automatically | |
| 159 | + | |
| 160 | +Now use Continue CLI to create GitHub issues from your analysis results: | |
| 161 | + | |
| 162 | +```bash | |
| 163 | +cn -p "I have analyzed PostHog session data and identified UX issues. Now I need you to create GitHub issues using the GitHub API. | |
| 164 | + | |
| 165 | +Use these details from my secrets: | |
| 166 | +- GITHUB_PAT: My GitHub Personal Access Token | |
| 167 | +- Repository: Extract from git remote or ask me to specify | |
| 168 | + | |
| 169 | +For each issue in my analysis: | |
| 170 | +1. Parse the issue title, body content, and priority level | |
| 171 | +2. Create a GitHub issue via API POST to: https://api.github.com/repos/{owner}/{repo}/issues | |
| 172 | +3. Use these headers: | |
| 173 | + - Authorization: token {GITHUB_PAT} | |
| 174 | + - Accept: application/vnd.github.v3+json | |
| 175 | + - Content-Type: application/json | |
| 176 | +4. Set labels based on priority: | |
| 177 | + - HIGH: [\"bug\", \"high-priority\", \"user-experience\", \"automated\"] | |
| 178 | + - MEDIUM: [\"enhancement\", \"medium-priority\", \"user-experience\", \"automated\"] | |
| 179 | + - LOW: [\"low-priority\", \"user-experience\", \"automated\"] | |
| 180 | +5. Format the issue title as: \"🔍 UX Issue: {original title}\" | |
| 181 | + | |
| 182 | +Please create the GitHub issues and confirm they were successfully created with issue numbers and URLs. | |
| 183 | +" | |
| 184 | +``` | |
| 185 | + | |
| 186 | +<Warning> | |
| 187 | +**Repository Labels Required**: Make sure your GitHub repository has these labels: | |
| 188 | +- `bug`, `enhancement` | |
| 189 | +- `high-priority`, `medium-priority`, `low-priority` | |
| 190 | +- `user-experience`, `automated` | |
| 191 | + | |
| 192 | +Create missing labels in your repo at: **Settings → Labels → New label** | |
| 193 | + | |
| 194 | +</Warning> | |
| 195 | + | |
| 196 | +<Info> | |
| 197 | + **What Continue CLI Does:** - Parses your analysis results automatically - | |
| 198 | + Makes authenticated GitHub API calls using your stored token - Creates | |
| 199 | + properly formatted issues with appropriate labels - Checks for duplicate | |
| 200 | + issues to avoid spam - Provides confirmation with issue URLs | |
| 201 | +</Info> | |
| 202 | + | |
| 203 | +## Step 4: Set Up Automated GitHub Actions Workflow | |
| 204 | + | |
| 205 | +Create a GitHub Actions workflow that runs your Continue CLI analysis automatically on a schedule. | |
| 206 | + | |
| 207 | +### Add GitHub Secrets | |
| 208 | + | |
| 209 | +First, add these secrets to your GitHub repository: | |
| 210 | + | |
| 211 | +1. Go to **Repository Settings → Secrets and variables → Actions** | |
| 212 | +2. Click **"New repository secret"** and add: | |
| 213 | + - `CONTINUE_API_KEY`: Your Continue API key from hub.continue.dev | |
| 214 | + - `POSTHOG_API_KEY`: Your PostHog Personal API Key | |
| 215 | + - `POSTHOG_PROJECT_ID`: Your PostHog Project ID | |
| 216 | + - `POSTHOG_HOST`: `https://us.posthog.com` (or your custom PostHog host) | |
| 217 | + - `GITHUB_PAT`: Your GitHub Personal Access Token | |
| 218 | + | |
| 219 | +### Create GitHub Actions Workflow | |
| 220 | + | |
| 221 | +Create `.github/workflows/posthog-analysis.yml` in your repository: | |
| 222 | + | |
| 223 | +```yaml | |
| 224 | +name: PostHog Session Analysis with Continue CLI | |
| 225 | + | |
| 226 | +on: | |
| 227 | + schedule: | |
| 228 | + - cron: "0 6 * * *" # Run at 6 AM UTC daily | |
| 229 | + workflow_dispatch: # Allow manual triggering | |
| 230 | + | |
| 231 | +jobs: | |
| 232 | + analyze: | |
| 233 | + runs-on: ubuntu-latest | |
| 234 | + | |
| 235 | + permissions: | |
| 236 | + contents: read | |
| 237 | + issues: write | |
| 238 | + | |
| 239 | + steps: | |
| 240 | + - uses: actions/checkout@v4 | |
| 241 | + | |
| 242 | + - name: Set up Node.js | |
| 243 | + uses: actions/setup-node@v4 | |
| 244 | + with: | |
| 245 | + node-version: "18" | |
| 246 | + | |
| 247 | + - name: Install Continue CLI | |
| 248 | + run: | | |
| 249 | + npm install -g @continuedev/cli | |
| 250 | + echo "✅ Continue CLI installed" | |
| 251 | + cn --version | |
| 252 | + | |
| 253 | + - name: Set up environment variables | |
| 254 | + run: | | |
| 255 | + echo "POSTHOG_API_KEY=${{ secrets.POSTHOG_API_KEY }}" >> $GITHUB_ENV | |
| 256 | + echo "POSTHOG_PROJECT_ID=${{ secrets.POSTHOG_PROJECT_ID }}" >> $GITHUB_ENV | |
| 257 | + echo "POSTHOG_HOST=${{ secrets.POSTHOG_HOST || 'https://us.posthog.com' }}" >> $GITHUB_ENV | |
| 258 | + echo "GITHUB_PAT=${{ secrets.GITHUB_PAT }}" >> $GITHUB_ENV | |
| 259 | + echo "GITHUB_OWNER=${{ github.repository_owner }}" >> $GITHUB_ENV | |
| 260 | + echo "GITHUB_REPO=$(echo ${{ github.repository }} | cut -d'/' -f2)" >> $GITHUB_ENV | |
| 261 | + | |
| 262 | + - name: Authenticate with Continue CLI | |
| 263 | + run: | | |
| 264 | + # Set Continue API key | |
| 265 | + export CONTINUE_API_KEY="${{ secrets.CONTINUE_API_KEY }}" | |
| 266 | + # Login to Continue CLI | |
| 267 | + if ! cn auth login --api-key "$CONTINUE_API_KEY"; then | |
| 268 | + echo "❌ Failed to authenticate with Continue CLI" | |
| 269 | + exit 1 | |
| 270 | + fi | |
| 271 | + echo "✅ Continue CLI authenticated" | |
| 272 | + | |
| 273 | + - name: Run PostHog Session Analysis | |
| 274 | + run: | | |
| 275 | + echo "🎬 Starting PostHog session analysis..." | |
| 276 | + # Create the analysis prompt | |
| 277 | + cat > analysis_prompt.txt << 'EOF' | |
| 278 | + I need you to help me analyze PostHog session recordings to identify UX issues. Please: | |
| 279 | + | |
| 280 | + 1. First, fetch session recordings from PostHog using these details: | |
| 281 | + - Use the POSTHOG_API_KEY, POSTHOG_PROJECT_ID, and POSTHOG_HOST from environment variables | |
| 282 | + - API endpoint: $POSTHOG_HOST/api/projects/$POSTHOG_PROJECT_ID/session_recordings/?limit=20 | |
| 283 | + - Include Authorization header: "Bearer $POSTHOG_API_KEY" | |
| 284 | + | |
| 285 | + 2. Filter the sessions to find problematic ones with either: | |
| 286 | + - console_error_count > 0 (JavaScript errors) | |
| 287 | + - recording_duration > 300 (sessions longer than 5 minutes) | |
| 288 | + | |
| 289 | + 3. Analyze the filtered sessions and create exactly 3 GitHub issues for the most critical UX problems. | |
| 290 | + | |
| 291 | + 4. Format each issue like this: | |
| 292 | + ### 1. **Issue Title Here** | |
| 293 | + **Problem**: One sentence describing the user problem | |
| 294 | + **Technical Causes**: Brief technical explanation | |
| 295 | + **Affected Pages**: List the URLs | |
| 296 | + **Recommended Fix**: | |
| 297 | + - Specific action item 1 | |
| 298 | + - Specific action item 2 | |
| 299 | + **Priority**: **HIGH** or **MEDIUM** or **LOW** | |
| 300 | + **Impact**: Quantify the impact (e.g., 'Affects 80% of sessions') | |
| 301 | + | |
| 302 | + Please make the API call, analyze the data, and provide the 3 formatted issues. Base all recommendations on actual patterns in the session data. | |
| 303 | + | |
| 304 | + Environment context: | |
| 305 | + - POSTHOG_API_KEY: $POSTHOG_API_KEY | |
| 306 | + - POSTHOG_PROJECT_ID: $POSTHOG_PROJECT_ID | |
| 307 | + - POSTHOG_HOST: $POSTHOG_HOST | |
| 308 | + - GitHub Repo: $GITHUB_OWNER/$GITHUB_REPO | |
| 309 | + EOF | |
| 310 | + | |
| 311 | + # Run the analysis | |
| 312 | + cn < analysis_prompt.txt > analysis-results.txt 2>&1 | |
| 313 | + | |
| 314 | + # Check if analysis completed | |
| 315 | + if [ ! -s analysis-results.txt ]; then | |
| 316 | + echo "❌ Analysis failed or produced no output" | |
| 317 | + exit 1 | |
| 318 | + fi | |
| 319 | + | |
| 320 | + echo "✅ Analysis completed" | |
| 321 | + echo "📄 Analysis results preview:" | |
| 322 | + head -20 analysis-results.txt | |
| 323 | + | |
| 324 | + - name: Create GitHub Issues from Analysis | |
| 325 | + run: | | |
| 326 | + echo "📝 Creating GitHub issues from analysis..." | |
| 327 | + # Create the issue creation prompt | |
| 328 | + cat > issue_prompt.txt << 'EOF' | |
| 329 | + I have analyzed PostHog session data and identified UX issues. Now I need you to create GitHub issues using the GitHub API. | |
| 330 | + | |
| 331 | + Use these details from environment variables: | |
| 332 | + - GITHUB_PAT: My GitHub Personal Access Token | |
| 333 | + - Repository: $GITHUB_OWNER/$GITHUB_REPO | |
| 334 | + | |
| 335 | + For each issue in my analysis: | |
| 336 | + 1. Parse the issue title, body content, and priority level | |
| 337 | + 2. Create a GitHub issue via API POST to: https://api.github.com/repos/$GITHUB_OWNER/$GITHUB_REPO/issues | |
| 338 | + 3. Use these headers: | |
| 339 | + - Authorization: token $GITHUB_PAT | |
| 340 | + - Accept: application/vnd.github.v3+json | |
| 341 | + - Content-Type: application/json | |
| 342 | + 4. Set labels based on priority: | |
| 343 | + - HIGH: ["bug", "high-priority", "user-experience", "automated"] | |
| 344 | + - MEDIUM: ["enhancement", "medium-priority", "user-experience", "automated"] | |
| 345 | + - LOW: ["low-priority", "user-experience", "automated"] | |
| 346 | + 5. Format the issue title as: "🔍 UX Issue: {original title}" | |
| 347 | + | |
| 348 | + Please create the GitHub issues and confirm they were successfully created with issue numbers and URLs. | |
| 349 | + | |
| 350 | + Here's my analysis to process: | |
| 351 | + EOF | |
| 352 | + | |
| 353 | + # Append the analysis results to the prompt | |
| 354 | + cat analysis-results.txt >> issue_prompt.txt | |
| 355 | + | |
| 356 | + # Run the issue creation | |
| 357 | + cn < issue_prompt.txt > issue-creation-results.txt 2>&1 | |
| 358 | + | |
| 359 | + echo "✅ Issue creation completed" | |
| 360 | + echo "📄 Issue creation results:" | |
| 361 | + cat issue-creation-results.txt | |
| 362 | + | |
| 363 | + - name: Upload Analysis Artifacts | |
| 364 | + uses: actions/upload-artifact@v4 | |
| 365 | + if: always() | |
| 366 | + with: | |
| 367 | + name: analysis-results-${{ github.run_number }} | |
| 368 | + path: | | |
| 369 | + analysis-results.txt | |
| 370 | + issue-creation-results.txt | |
| 371 | + retention-days: 30 | |
| 372 | + | |
| 373 | + - name: Summary | |
| 374 | + run: | | |
| 375 | + echo "✅ PostHog analysis workflow completed!" | |
| 376 | + echo "📊 Check the artifacts for detailed analysis results" | |
| 377 | + echo "🐛 Check your repository issues for newly created UX issues" | |
| 378 | +``` | |
| 379 | + | |
| 380 | +## Step 5: Testing Your Workflow | |
| 381 | + | |
| 382 | +### Test Locally First | |
| 383 | + | |
| 384 | +Before setting up automation, test the workflow locally: | |
| 385 | + | |
| 386 | +**Test 1: Session Analysis** | |
| 387 | + | |
| 388 | +```bash | |
| 389 | +cn -p "[Paste the PostHog analysis prompt from Step 2]" | |
| 390 | +``` | |
| 391 | + | |
| 392 | +Expected: Analysis output with 3 formatted GitHub issues | |
| 393 | + | |
| 394 | +**Test 2: Issue Creation** | |
| 395 | + | |
| 396 | +```bash | |
| 397 | +cn -p "[Paste the GitHub issue creation prompt from Step 3 with your analysis results]" | |
| 398 | +``` | |
| 399 | + | |
| 400 | +Expected: Confirmation of GitHub issues created with URLs | |
| 401 | + | |
| 402 | +### Test the GitHub Actions Workflow | |
| 403 | + | |
| 404 | +1. **Manual Trigger**: Go to **Actions** tab in your repository and manually trigger the workflow | |
| 405 | +2. **Check Artifacts**: Download the analysis results from the workflow run | |
| 406 | +3. **Verify Issues**: Check that GitHub issues were created in your repository | |
| 407 | + | |
| 408 | +<Check> | |
| 409 | + **Success Indicators:** - PostHog API returns session data (not empty) - | |
| 410 | + Continue CLI generates analysis with identified issues - GitHub issues are | |
| 411 | + created with proper labels and formatting - Workflow completes without errors | |
| 412 | +</Check> | |
| 413 | + | |
| 414 | +## Troubleshooting | |
| 415 | + | |
| 416 | +If you encounter issues, use this helpful prompt to diagnose problems: | |
| 417 | + | |
| 418 | +```bash | |
| 419 | +cn -p "Help me set up my environment for PostHog session analysis. Please: | |
| 420 | + | |
| 421 | +1. Check if I have the required secrets configured in Continue CLI: | |
| 422 | + - POSTHOG_API_KEY | |
| 423 | + - POSTHOG_PROJECT_ID | |
| 424 | + - POSTHOG_HOST | |
| 425 | + - GITHUB_PAT | |
| 426 | + | |
| 427 | +2. If any are missing, guide me through: | |
| 428 | + - How to get PostHog Personal API Key from PostHog settings | |
| 429 | + - How to find my PostHog Project ID from the URL | |
| 430 | + - How to create a GitHub Personal Access Token with issues:write permission | |
| 431 | + - How to add these as secrets in Continue CLI | |
| 432 | + | |
| 433 | +3. Help me identify my GitHub repository owner and name by: | |
| 434 | + - Checking git remote origin URL | |
| 435 | + - Or asking me to provide them | |
| 436 | + | |
| 437 | +4. Test the API connections by making a simple API call to both PostHog and GitHub to verify the credentials work. | |
| 438 | + | |
| 439 | +Please walk me through this setup process step by step." | |
| 440 | +``` | |
| 441 | + | |
| 442 | +## What You've Built | |
| 443 | + | |
| 444 | +After completing this guide, you have a complete **Continuous AI system** that: | |
| 445 | + | |
| 446 | +✅ **Monitors user experience** - Automatically fetches and analyzes PostHog session data | |
| 447 | +✅ **Identifies problems intelligently** - Uses AI to spot patterns and technical issues | |
| 448 | +✅ **Creates actionable tasks** - Generates GitHub issues with specific recommendations | |
| 449 | +✅ **Runs autonomously** - Operates daily without manual intervention using GitHub Actions | |
| 450 | +✅ **Scales with your team** - Handles growing amounts of session data automatically | |
| 451 | + | |
| 452 | +<Card title="Continuous AI" icon="rocket"> | |
| 453 | + Your system now operates at **[Level 2 Continuous | |
| 454 | + AI](https://blog.continue.dev/what-is-continuous-ai-a-developers-guide/)** - | |
| 455 | + AI handles routine analysis tasks with human oversight through GitHub issue | |
| 456 | + review and prioritization. | |
| 457 | +</Card> | |
| 458 | + | |
| 459 | +## Security Best Practices | |
| 460 | + | |
| 461 | +<Warning> | |
| 462 | + **Protect Your API Keys:** - Store all credentials as GitHub Secrets, never in | |
| 463 | + code - Use Continue CLI's secure secret storage - Limit token scopes to | |
| 464 | + minimum required permissions - Rotate API keys regularly (every 90 days | |
| 465 | + recommended) - Monitor token usage for unusual activity | |
| 466 | +</Warning> | |
| 467 | + | |
| 468 | +## Advanced Prompts | |
| 469 | + | |
| 470 | +Consider enhancing your workflow with these advanced Continue CLI prompts: | |
| 471 | + | |
| 472 | +<CardGroup cols={2}> | |
| 473 | + <Card title="Performance Analysis" icon="chart-line"> | |
| 474 | + "Analyze PostHog performance metrics alongside session recordings to | |
| 475 | + identify slow page loads affecting user experience" | |
| 476 | + </Card> | |
| 477 | + <Card title="Error Correlation" icon="bug"> | |
| 478 | + "Cross-reference JavaScript console errors with user actions to identify the | |
| 479 | + root cause of UX issues" | |
| 480 | + </Card> | |
| 481 | + <Card title="Feature Flag Analysis" icon="flag"> | |
| 482 | + "Analyze how PostHog feature flags impact user behavior in session | |
| 483 | + recordings" | |
| 484 | + </Card> | |
| 485 | + <Card title="Custom Slack Alerts" icon="slack"> | |
| 486 | + "Create Slack alerts when critical UX issues are detected in PostHog | |
| 487 | + sessions" | |
| 488 | + </Card> | |
| 489 | +</CardGroup> | |
| 490 | + | |
| 491 | +## Next Steps | |
| 492 | + | |
| 493 | +1. **Monitor your first issues** - Review the GitHub issues created and implement fixes | |
| 494 | +2. **Measure impact** - Track how resolved issues improve PostHog metrics | |
| 495 | +3. **Refine prompts** - Adjust the Continue CLI prompts based on issue quality | |
| 496 | +4. **Scale the system** - Add more data sources or create specialized analysis workflows |
| @@ -403,6 +403,7 @@ | ||
| 403 | 403 | - `env`: An optional map of environment variables for the server process. |
| 404 | 404 | - `cwd`: An optional working directory to run the command in. Can be absolute or relative path. |
| 405 | 405 | - `connectionTimeout`: An optional connection timeout number to the server in milliseconds. |
| 406 | +- `requestOptions`: Optional request options for `sse` and `streamable-http` servers. Same format as [model requestOptions](#models). | |
| 406 | 407 | |
| 407 | 408 | **Example:** |
| 408 | 409 |
| @@ -37,7 +37,7 @@ | ||
| 37 | 37 | "license": "Apache-2.0", |
| 38 | 38 | "repository": { |
| 39 | 39 | "type": "git", |
| 40 | - "url": "https://github.com/continuedev/cli.git" | |
| 40 | + "url": "https://github.com/continuedev/continue.git" | |
| 41 | 41 | }, |
| 42 | 42 | "bugs": { |
| 43 | 43 | "url": "https://github.com/continuedev/continue/issues" |
| @@ -40,6 +40,11 @@ | ||
| 40 | 40 | description: "Sign out of your current session", |
| 41 | 41 | category: "system", |
| 42 | 42 | }, |
| 43 | + { | |
| 44 | + name: "update", | |
| 45 | + description: "Update the Continue CLI", | |
| 46 | + category: "system", | |
| 47 | + }, | |
| 43 | 48 | { |
| 44 | 49 | name: "whoami", |
| 45 | 50 | description: "Check who you're currently logged in as", |
| @@ -9,13 +9,10 @@ | ||
| 9 | 9 | } from "./auth/workos.js"; |
| 10 | 10 | import { services } from "./services/index.js"; |
| 11 | 11 | import { getCurrentSession, getSessionFilePath } from "./session.js"; |
| 12 | -import { posthogService } from "./telemetry/posthogService.js"; | |
| 13 | 12 | import { logger } from "./util/logger.js"; |
| 14 | 13 | import { getVersion } from "./version.js"; |
| 15 | 14 | |
| 16 | 15 | export async function handleInfoSlashCommand() { |
| 17 | - posthogService.capture("useSlashCommand", { name: "info" }); | |
| 18 | - | |
| 19 | 16 | const infoLines = []; |
| 20 | 17 | |
| 21 | 18 | // Version and working directory info |
| @@ -0,0 +1,241 @@ | ||
| 1 | +import { exec, spawn } from "child_process"; | |
| 2 | +import { promisify } from "util"; | |
| 3 | + | |
| 4 | +import { GlobalContext } from "core/util/GlobalContext.js"; | |
| 5 | + | |
| 6 | +import { logger } from "src/util/logger.js"; | |
| 7 | + | |
| 8 | +import { compareVersions, getLatestVersion, getVersion } from "../version.js"; | |
| 9 | + | |
| 10 | +import { BaseService } from "./BaseService.js"; | |
| 11 | +import { serviceContainer } from "./ServiceContainer.js"; | |
| 12 | +import { UpdateServiceState, UpdateStatus } from "./types.js"; | |
| 13 | +const execAsync = promisify(exec); | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * Service for checking and performing CLI updates | |
| 17 | + */ | |
| 18 | +export class UpdateService extends BaseService<UpdateServiceState> { | |
| 19 | + constructor() { | |
| 20 | + super("update", { | |
| 21 | + autoUpdate: true, | |
| 22 | + isAutoUpdate: true, | |
| 23 | + status: UpdateStatus.IDLE, | |
| 24 | + message: "", | |
| 25 | + error: null, | |
| 26 | + isUpdateAvailable: false, | |
| 27 | + latestVersion: null, | |
| 28 | + currentVersion: getVersion(), | |
| 29 | + }); | |
| 30 | + } | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * Initialize the update service | |
| 34 | + */ | |
| 35 | + async doInitialize(headless?: boolean) { | |
| 36 | + // Don't automatically check in tests/headless | |
| 37 | + if (!headless && process.env.NODE_ENV !== "test") { | |
| 38 | + void this.checkAndAutoUpdate(); | |
| 39 | + } | |
| 40 | + | |
| 41 | + return this.currentState; | |
| 42 | + } | |
| 43 | + | |
| 44 | + private async checkAndAutoUpdate() { | |
| 45 | + // First get auto update setting from global context | |
| 46 | + const globalContext = new GlobalContext(); | |
| 47 | + const autoUpdate = globalContext.get("autoUpdateCli") ?? true; | |
| 48 | + this.setState({ | |
| 49 | + autoUpdate, | |
| 50 | + }); | |
| 51 | + | |
| 52 | + try { | |
| 53 | + // Check for updates | |
| 54 | + this.setState({ | |
| 55 | + status: UpdateStatus.CHECKING, | |
| 56 | + message: "Checking for updates", | |
| 57 | + }); | |
| 58 | + | |
| 59 | + const latestVersion = await getLatestVersion(); | |
| 60 | + this.setState({ | |
| 61 | + latestVersion, | |
| 62 | + }); | |
| 63 | + | |
| 64 | + if (!latestVersion) { | |
| 65 | + this.setState({ | |
| 66 | + status: UpdateStatus.IDLE, | |
| 67 | + message: "Continue CLI", | |
| 68 | + isUpdateAvailable: false, | |
| 69 | + }); | |
| 70 | + return; | |
| 71 | + } | |
| 72 | + | |
| 73 | + const comparison = compareVersions( | |
| 74 | + this.currentState.currentVersion, | |
| 75 | + latestVersion, | |
| 76 | + ); | |
| 77 | + const isUpdateAvailable = comparison === "older"; | |
| 78 | + this.setState({ | |
| 79 | + isUpdateAvailable, | |
| 80 | + }); | |
| 81 | + | |
| 82 | + if (this.currentState.currentVersion === "0.0.0-dev") { | |
| 83 | + this.setState({ | |
| 84 | + status: UpdateStatus.IDLE, | |
| 85 | + message: `Continue CLI`, | |
| 86 | + isUpdateAvailable, | |
| 87 | + latestVersion, | |
| 88 | + }); | |
| 89 | + return; // Uncomment to test auto-update behavior in dev | |
| 90 | + } | |
| 91 | + | |
| 92 | + // If update is available, automatically update | |
| 93 | + if ( | |
| 94 | + autoUpdate && | |
| 95 | + isUpdateAvailable && | |
| 96 | + this.currentState.status !== "updating" && | |
| 97 | + !process.env.CONTINUE_CLI_AUTO_UPDATED //Already auto updated, preventing sequential auto-update | |
| 98 | + ) { | |
| 99 | + await this.performUpdate(true); | |
| 100 | + } else { | |
| 101 | + this.setState({ | |
| 102 | + status: UpdateStatus.IDLE, | |
| 103 | + message: isUpdateAvailable | |
| 104 | + ? `Update available: v${latestVersion}` | |
| 105 | + : `Continue CLI v${this.currentState.currentVersion}`, | |
| 106 | + isUpdateAvailable, | |
| 107 | + latestVersion, | |
| 108 | + }); | |
| 109 | + } | |
| 110 | + } catch (error: any) { | |
| 111 | + logger.error("Error checking for updates:", error); | |
| 112 | + this.setState({ | |
| 113 | + status: UpdateStatus.ERROR, | |
| 114 | + message: `Continue CLI v${this.currentState.currentVersion}`, | |
| 115 | + error, | |
| 116 | + }); | |
| 117 | + } | |
| 118 | + } | |
| 119 | + | |
| 120 | + public async setAutoUpdate(value: boolean) { | |
| 121 | + const globalContext = new GlobalContext(); | |
| 122 | + globalContext.update("autoUpdateCli", value); | |
| 123 | + this.setState({ | |
| 124 | + autoUpdate: value, | |
| 125 | + }); | |
| 126 | + } | |
| 127 | + | |
| 128 | + // TODO this is a hack because our service state update code is broken | |
| 129 | + // Currently all things that need update use serviceContainer.set manually | |
| 130 | + // Rather than actually using the stateChanged event | |
| 131 | + setState(newState: Partial<UpdateServiceState>): void { | |
| 132 | + super.setState(newState); | |
| 133 | + serviceContainer.set("update", this.currentState); | |
| 134 | + } | |
| 135 | + | |
| 136 | + async performUpdate(isAutoUpdate?: boolean) { | |
| 137 | + if (this.currentState.status === "updating") { | |
| 138 | + return; | |
| 139 | + } | |
| 140 | + | |
| 141 | + try { | |
| 142 | + this.setState({ | |
| 143 | + isAutoUpdate, | |
| 144 | + status: UpdateStatus.UPDATING, | |
| 145 | + message: `${isAutoUpdate ? "Auto-updating" : "Updating"} to v${this.currentState.latestVersion}`, | |
| 146 | + }); | |
| 147 | + | |
| 148 | + // Install the update | |
| 149 | + const { stdout, stderr } = await execAsync("npm i -g @continuedev/cli"); | |
| 150 | + logger.debug("Update output:", { stdout, stderr }); | |
| 151 | + | |
| 152 | + if (stderr) { | |
| 153 | + const errLines = stderr.split("\n"); | |
| 154 | + for (const line of errLines) { | |
| 155 | + const lower = line.toLowerCase().trim(); | |
| 156 | + if ( | |
| 157 | + !line || | |
| 158 | + lower.includes("debugger") || | |
| 159 | + lower.includes("npm warn") | |
| 160 | + ) { | |
| 161 | + continue; | |
| 162 | + } | |
| 163 | + this.setState({ | |
| 164 | + status: UpdateStatus.ERROR, | |
| 165 | + message: `Error updating to v${this.currentState.latestVersion}`, | |
| 166 | + error: new Error(stderr), | |
| 167 | + }); | |
| 168 | + return; | |
| 169 | + } | |
| 170 | + } | |
| 171 | + | |
| 172 | + this.setState({ | |
| 173 | + status: UpdateStatus.UPDATED, | |
| 174 | + message: `${isAutoUpdate ? "Auto-updated to" : "Restart for"} v${this.currentState.latestVersion}`, | |
| 175 | + isUpdateAvailable: false, | |
| 176 | + }); | |
| 177 | + if (isAutoUpdate) { | |
| 178 | + this.restartCLI(); | |
| 179 | + } | |
| 180 | + } catch (error: any) { | |
| 181 | + logger.error("Error updating CLI:", error); | |
| 182 | + this.setState({ | |
| 183 | + status: UpdateStatus.ERROR, | |
| 184 | + message: isAutoUpdate ? "Auto-update failed" : "Update failed", | |
| 185 | + error, | |
| 186 | + }); | |
| 187 | + setTimeout(() => { | |
| 188 | + this.setState({ | |
| 189 | + status: UpdateStatus.IDLE, | |
| 190 | + message: `/update to v${this.currentState.latestVersion}`, | |
| 191 | + }); | |
| 192 | + }, 4000); | |
| 193 | + } | |
| 194 | + } | |
| 195 | + | |
| 196 | + private restartCLI(): void { | |
| 197 | + try { | |
| 198 | + const entryPoint = process.argv[1]; | |
| 199 | + const cliArgs = process.argv.slice(2); | |
| 200 | + const nodeExecutable = process.execPath; | |
| 201 | + | |
| 202 | + logger.debug( | |
| 203 | + `Preparing for CLI restart with: ${nodeExecutable} ${entryPoint} ${cliArgs.join( | |
| 204 | + " ", | |
| 205 | + )}`, | |
| 206 | + ); | |
| 207 | + | |
| 208 | + // Halt/clean up parent cn process | |
| 209 | + try { | |
| 210 | + // Remove all input listeners | |
| 211 | + global.clearTimeout = () => {}; | |
| 212 | + global.clearInterval = () => {}; | |
| 213 | + process.stdin.removeAllListeners(); | |
| 214 | + process.stdin.pause(); | |
| 215 | + // console.clear(); // Don't want to clear things that were in console before cn started | |
| 216 | + } catch (e) { | |
| 217 | + logger.debug("Error cleaning up terminal:", e); | |
| 218 | + } | |
| 219 | + | |
| 220 | + // Spawn a new detached cn process | |
| 221 | + const child = spawn(nodeExecutable, [entryPoint, ...cliArgs], { | |
| 222 | + detached: true, | |
| 223 | + stdio: "inherit", | |
| 224 | + env: { | |
| 225 | + ...process.env, | |
| 226 | + CONTINUE_CLI_AUTO_UPDATED: "true", | |
| 227 | + }, | |
| 228 | + }); | |
| 229 | + | |
| 230 | + // I did not find a way on existing to avoid a bug where next process has input glitches without leaving parent in place | |
| 231 | + // So instead of existing, parent will exit when child exits | |
| 232 | + // process.exit(0); | |
| 233 | + child.on("exit", (code) => { | |
| 234 | + process.exit(code); | |
| 235 | + }); | |
| 236 | + child.unref(); | |
| 237 | + } catch (error) { | |
| 238 | + logger.error("Failed to restart CLI:", error); | |
| 239 | + } | |
| 240 | + } | |
| 241 | +} |
| @@ -21,6 +21,7 @@ | ||
| 21 | 21 | ServiceInitOptions, |
| 22 | 22 | ServiceInitResult, |
| 23 | 23 | } from "./types.js"; |
| 24 | +import { UpdateService } from "./UpdateService.js"; | |
| 24 | 25 | |
| 25 | 26 | // Service instances |
| 26 | 27 | const authService = new AuthService(); |
| @@ -31,6 +32,7 @@ | ||
| 31 | 32 | const fileIndexService = new FileIndexService(); |
| 32 | 33 | const resourceMonitoringService = new ResourceMonitoringService(); |
| 33 | 34 | const chatHistoryService = new ChatHistoryService(); |
| 35 | +const updateService = new UpdateService(); | |
| 34 | 36 | |
| 35 | 37 | /** |
| 36 | 38 | * Initialize all services and register them with the service container |
| @@ -132,6 +134,12 @@ | ||
| 132 | 134 | [], // No dependencies |
| 133 | 135 | ); |
| 134 | 136 | |
| 137 | + serviceContainer.register( | |
| 138 | + SERVICE_NAMES.UPDATE, | |
| 139 | + () => updateService.initialize(), | |
| 140 | + [], // No dependencies | |
| 141 | + ); | |
| 142 | + | |
| 135 | 143 | serviceContainer.register( |
| 136 | 144 | SERVICE_NAMES.API_CLIENT, |
| 137 | 145 | async () => { |
| @@ -283,17 +291,9 @@ | ||
| 283 | 291 | * Check if all core services are ready |
| 284 | 292 | */ |
| 285 | 293 | export function areServicesReady(): boolean { |
| 286 | - return [ | |
| 287 | - SERVICE_NAMES.TOOL_PERMISSIONS, | |
| 288 | - SERVICE_NAMES.AUTH, | |
| 289 | - SERVICE_NAMES.API_CLIENT, | |
| 290 | - SERVICE_NAMES.CONFIG, | |
| 291 | - SERVICE_NAMES.MODEL, | |
| 292 | - SERVICE_NAMES.MCP, | |
| 293 | - SERVICE_NAMES.FILE_INDEX, | |
| 294 | - SERVICE_NAMES.RESOURCE_MONITORING, | |
| 295 | - SERVICE_NAMES.CHAT_HISTORY, | |
| 296 | - ].every((name) => serviceContainer.isReady(name)); | |
| 294 | + return Object.values(SERVICE_NAMES).every((name) => | |
| 295 | + serviceContainer.isReady(name), | |
| 296 | + ); | |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | /** |
| @@ -317,6 +317,7 @@ | ||
| 317 | 317 | resourceMonitoring: resourceMonitoringService, |
| 318 | 318 | systemMessage: systemMessageService, |
| 319 | 319 | chatHistory: chatHistoryService, |
| 320 | + updateService: updateService, | |
| 320 | 321 | } as const; |
| 321 | 322 | |
| 322 | 323 | // Export the service container for advanced usage |
| @@ -81,6 +81,25 @@ | ||
| 81 | 81 | prompts: MCPPrompt[]; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | +export enum UpdateStatus { | |
| 85 | + IDLE = "idle", | |
| 86 | + CHECKING = "checking", | |
| 87 | + UPDATING = "updating", | |
| 88 | + UPDATED = "updated", | |
| 89 | + ERROR = "error", | |
| 90 | +} | |
| 91 | + | |
| 92 | +export interface UpdateServiceState { | |
| 93 | + autoUpdate: boolean; | |
| 94 | + isAutoUpdate: boolean; | |
| 95 | + status: UpdateStatus; | |
| 96 | + message: string; | |
| 97 | + error?: Error | null; | |
| 98 | + isUpdateAvailable: boolean; | |
| 99 | + latestVersion: string | null; | |
| 100 | + currentVersion: string; | |
| 101 | +} | |
| 102 | + | |
| 84 | 103 | export interface ApiClientServiceState { |
| 85 | 104 | apiClient: DefaultApiInterface | null; |
| 86 | 105 | } |
| @@ -92,8 +111,8 @@ | ||
| 92 | 111 | originalPolicies?: ToolPermissions; |
| 93 | 112 | } |
| 94 | 113 | |
| 95 | -export type { FileIndexServiceState } from "./FileIndexService.js"; | |
| 96 | 114 | export type { ChatHistoryState } from "./ChatHistoryService.js"; |
| 115 | +export type { FileIndexServiceState } from "./FileIndexService.js"; | |
| 97 | 116 | |
| 98 | 117 | /** |
| 99 | 118 | * Service names as constants to prevent typos |
| @@ -109,6 +128,7 @@ | ||
| 109 | 128 | RESOURCE_MONITORING: "resourceMonitoring", |
| 110 | 129 | SYSTEM_MESSAGE: "systemMessage", |
| 111 | 130 | CHAT_HISTORY: "chatHistory", |
| 131 | + UPDATE: "update", | |
| 112 | 132 | } as const; |
| 113 | 133 | |
| 114 | 134 | /** |
| @@ -48,12 +48,10 @@ | ||
| 48 | 48 | ` Type ${chalk.cyan("/")} to see available slash commands`, |
| 49 | 49 | ` Type ${chalk.cyan("!")} followed by a command to execute bash directly`, |
| 50 | 50 | ].join("\n"); |
| 51 | - posthogService.capture("useSlashCommand", { name: "help" }); | |
| 52 | 51 | return { output: helpMessage }; |
| 53 | 52 | } |
| 54 | 53 | |
| 55 | 54 | async function handleLogin() { |
| 56 | - posthogService.capture("useSlashCommand", { name: "login" }); | |
| 57 | 55 | try { |
| 58 | 56 | const newAuthState = await services.auth.login(); |
| 59 | 57 | await reloadService(SERVICE_NAMES.AUTH); |
| @@ -79,7 +77,6 @@ | ||
| 79 | 77 | } |
| 80 | 78 | |
| 81 | 79 | async function handleLogout() { |
| 82 | - posthogService.capture("useSlashCommand", { name: "logout" }); | |
| 83 | 80 | try { |
| 84 | 81 | await services.auth.logout(); |
| 85 | 82 | return { |
| @@ -95,7 +92,6 @@ | ||
| 95 | 92 | } |
| 96 | 93 | |
| 97 | 94 | function handleWhoami() { |
| 98 | - posthogService.capture("useSlashCommand", { name: "whoami" }); | |
| 99 | 95 | if (isAuthenticated()) { |
| 100 | 96 | const config = loadAuthConfig(); |
| 101 | 97 | if (config && isAuthenticatedConfig(config)) { |
| @@ -118,8 +114,6 @@ | ||
| 118 | 114 | } |
| 119 | 115 | |
| 120 | 116 | async function handleFork() { |
| 121 | - posthogService.capture("useSlashCommand", { name: "fork" }); | |
| 122 | - | |
| 123 | 117 | try { |
| 124 | 118 | const currentSession = getCurrentSession(); |
| 125 | 119 | const forkCommand = `cn --fork ${currentSession.sessionId}`; |
| @@ -148,15 +142,12 @@ | ||
| 148 | 142 | const commandHandlers: Record<string, CommandHandler> = { |
| 149 | 143 | help: handleHelp, |
| 150 | 144 | clear: () => { |
| 151 | - posthogService.capture("useSlashCommand", { name: "clear" }); | |
| 152 | 145 | return { clear: true, output: "Chat history cleared" }; |
| 153 | 146 | }, |
| 154 | 147 | exit: () => { |
| 155 | - posthogService.capture("useSlashCommand", { name: "exit" }); | |
| 156 | 148 | return { exit: true, output: "Goodbye!" }; |
| 157 | 149 | }, |
| 158 | 150 | config: () => { |
| 159 | - posthogService.capture("useSlashCommand", { name: "config" }); | |
| 160 | 151 | return { openConfigSelector: true }; |
| 161 | 152 | }, |
| 162 | 153 | login: handleLogin, |
| @@ -165,38 +156,25 @@ | ||
| 165 | 156 | info: handleInfoSlashCommand, |
| 166 | 157 | model: () => ({ openModelSelector: true }), |
| 167 | 158 | compact: () => { |
| 168 | - posthogService.capture("useSlashCommand", { name: "compact" }); | |
| 169 | 159 | return { compact: true }; |
| 170 | 160 | }, |
| 171 | 161 | mcp: () => { |
| 172 | - posthogService.capture("useSlashCommand", { name: "mcp" }); | |
| 173 | 162 | return { openMcpSelector: true }; |
| 174 | 163 | }, |
| 175 | 164 | resume: () => { |
| 176 | - posthogService.capture("useSlashCommand", { name: "resume" }); | |
| 177 | 165 | return { openSessionSelector: true }; |
| 178 | 166 | }, |
| 179 | 167 | fork: handleFork, |
| 180 | - init: (args, assistant) => { | |
| 181 | - posthogService.capture("useSlashCommand", { name: "init" }); | |
| 182 | - return handleInit(args, assistant); | |
| 168 | + init: handleInit, | |
| 169 | + update: () => { | |
| 170 | + return { openUpdateSelector: true }; | |
| 183 | 171 | }, |
| 184 | 172 | }; |
| 185 | 173 | |
| 186 | 174 | export async function handleSlashCommands( |
| 187 | 175 | input: string, |
| 188 | 176 | assistant: AssistantConfig, |
| 189 | -): Promise<{ | |
| 190 | - output?: string; | |
| 191 | - exit?: boolean; | |
| 192 | - newInput?: string; | |
| 193 | - clear?: boolean; | |
| 194 | - openConfigSelector?: boolean; | |
| 195 | - openModelSelector?: boolean; | |
| 196 | - openMCPSelector?: boolean; | |
| 197 | - openSessionSelector?: boolean; | |
| 198 | - compact?: boolean; | |
| 199 | -} | null> { | |
| 177 | +): Promise<SlashCommandResult | null> { | |
| 200 | 178 | // Only trigger slash commands if slash is the very first character |
| 201 | 179 | if (!input.startsWith("/") || !input.trim().startsWith("/")) { |
| 202 | 180 | return null; |
| @@ -16,9 +16,11 @@ | ||
| 16 | 16 | import { ToolCall } from "../tools/index.js"; |
| 17 | 17 | import { |
| 18 | 18 | chatCompletionStreamWithBackoff, |
| 19 | + isContextLengthError, | |
| 19 | 20 | withExponentialBackoff, |
| 20 | 21 | } from "../util/exponentialBackoff.js"; |
| 21 | 22 | import { logger } from "../util/logger.js"; |
| 23 | +import { validateContextLength } from "../util/tokenizer.js"; | |
| 22 | 24 | |
| 23 | 25 | import { getAllTools, handleToolCalls } from "./handleToolCalls.js"; |
| 24 | 26 | import { handleAutoCompaction } from "./streamChatResponse.autoCompaction.js"; |
| @@ -148,6 +150,12 @@ | ||
| 148 | 150 | tools, |
| 149 | 151 | } = options; |
| 150 | 152 | |
| 153 | + // Validate context length before making the request | |
| 154 | + const validation = validateContextLength(chatHistory, model); | |
| 155 | + if (!validation.isValid) { | |
| 156 | + throw new Error(`Context length validation failed: ${validation.error}`); | |
| 157 | + } | |
| 158 | + | |
| 151 | 159 | // Get fresh system message and inject it |
| 152 | 160 | const systemMessage = await systemMessageService.getSystemMessage(); |
| 153 | 161 | const openaiChatHistory = convertFromUnifiedHistoryWithSystemMessage( |
| @@ -277,6 +285,13 @@ | ||
| 277 | 285 | shouldContinue: false, |
| 278 | 286 | }; |
| 279 | 287 | } |
| 288 | + | |
| 289 | + // Handle context length errors with helpful message | |
| 290 | + if (isContextLengthError(error)) { | |
| 291 | + logger.debug(`Context length exceeded: ${error}`); | |
| 292 | + throw new Error(`Context length exceeded: ${error}`); | |
| 293 | + } | |
| 294 | + | |
| 280 | 295 | throw error; |
| 281 | 296 | } |
| 282 | 297 |
| @@ -6,8 +6,10 @@ | ||
| 6 | 6 | serviceContainer, |
| 7 | 7 | } from "../services/index.js"; |
| 8 | 8 | import type { ToolPermissionServiceState } from "../services/ToolPermissionService.js"; |
| 9 | +import type { ModelServiceState } from "../services/types.js"; | |
| 9 | 10 | import { telemetryService } from "../telemetry/telemetryService.js"; |
| 10 | 11 | import { logger } from "../util/logger.js"; |
| 12 | +import { isModelCapable } from "../utils/index.js"; | |
| 11 | 13 | |
| 12 | 14 | import { editTool } from "./edit.js"; |
| 13 | 15 | import { exitTool } from "./exit.js"; |
| @@ -66,9 +68,53 @@ | ||
| 66 | 68 | return dynamicTools; |
| 67 | 69 | } |
| 68 | 70 | |
| 69 | -// Get all builtin tools including dynamic ones | |
| 71 | +// Check if the current model is capable and should exclude Edit tool | |
| 72 | +function shouldExcludeEditTool(): boolean { | |
| 73 | + try { | |
| 74 | + const modelServiceResult = getServiceSync<ModelServiceState>( | |
| 75 | + SERVICE_NAMES.MODEL, | |
| 76 | + ); | |
| 77 | + | |
| 78 | + if ( | |
| 79 | + modelServiceResult.state === "ready" && | |
| 80 | + modelServiceResult.value?.model | |
| 81 | + ) { | |
| 82 | + const { name, provider, model } = modelServiceResult.value.model; | |
| 83 | + | |
| 84 | + // Check if model is capable | |
| 85 | + const isCapable = isModelCapable(provider, name, model); | |
| 86 | + | |
| 87 | + logger.debug("Capability-based tool filtering", { | |
| 88 | + provider, | |
| 89 | + name, | |
| 90 | + isCapable, | |
| 91 | + willExcludeEdit: isCapable, | |
| 92 | + }); | |
| 93 | + | |
| 94 | + return isCapable; | |
| 95 | + } | |
| 96 | + } catch (error) { | |
| 97 | + logger.debug("Error checking model capability for tool filtering", { | |
| 98 | + error, | |
| 99 | + }); | |
| 100 | + } | |
| 101 | + return false; | |
| 102 | +} | |
| 103 | + | |
| 104 | +// Get all builtin tools including dynamic ones, with capability-based filtering | |
| 70 | 105 | export function getAllBuiltinTools(): Tool[] { |
| 71 | - return [...BUILTIN_TOOLS, ...getDynamicTools()]; | |
| 106 | + let builtinTools = [...BUILTIN_TOOLS]; | |
| 107 | + | |
| 108 | + // Apply capability-based filtering for edit tools | |
| 109 | + // If model is capable, exclude editTool in favor of multiEditTool | |
| 110 | + if (shouldExcludeEditTool()) { | |
| 111 | + builtinTools = builtinTools.filter((tool) => tool.name !== editTool.name); | |
| 112 | + logger.debug( | |
| 113 | + "Excluded Edit tool for capable model - MultiEdit will be used instead", | |
| 114 | + ); | |
| 115 | + } | |
| 116 | + | |
| 117 | + return [...builtinTools, ...getDynamicTools()]; | |
| 72 | 118 | } |
| 73 | 119 | |
| 74 | 120 | export function getToolDisplayName(toolName: string): string { |
| @@ -9,7 +9,6 @@ | ||
| 9 | 9 | getLanguageFromFilePath, |
| 10 | 10 | } from "../telemetry/utils.js"; |
| 11 | 11 | |
| 12 | -import { editTool } from "./edit.js"; | |
| 13 | 12 | import { readFilesSet, readFileTool } from "./readFile.js"; |
| 14 | 13 | import { Tool } from "./types.js"; |
| 15 | 14 | import { generateDiff } from "./writeFile.js"; |
| @@ -133,8 +132,8 @@ | ||
| 133 | 132 | displayName: "MultiEdit", |
| 134 | 133 | readonly: false, |
| 135 | 134 | isBuiltIn: true, |
| 136 | - description: `This is a tool for making multiple edits to a single file in one operation. It is built on top of the ${editTool.name} tool and allows you to perform multiple find-and-replace operations efficiently. | |
| 137 | -Prefer this tool over the ${editTool.name} tool when you need to make multiple edits to the same file. | |
| 135 | + description: `This is a tool for making multiple edits to a single file in one operation. It allows you to perform multiple find-and-replace operations efficiently. | |
| 136 | +This tool is ideal when you need to make multiple edits to the same file. | |
| 138 | 137 | |
| 139 | 138 | To make multiple edits to a file, provide the following: |
| 140 | 139 | 1. file_path: The absolute path to the file to modify (must be absolute, not relative) |
| @@ -0,0 +1,33 @@ | ||
| 1 | +import { Text } from "ink"; | |
| 2 | +import React, { useEffect, useState } from "react"; | |
| 3 | + | |
| 4 | +interface LoadingTextProps { | |
| 5 | + text: string; | |
| 6 | + color?: string; | |
| 7 | + interval?: number; | |
| 8 | +} | |
| 9 | + | |
| 10 | +export const LoadingText: React.FC<LoadingTextProps> = ({ | |
| 11 | + text, | |
| 12 | + color = "gray", | |
| 13 | + interval = 300, | |
| 14 | +}) => { | |
| 15 | + const [dotsCount, setDotsCount] = useState(1); | |
| 16 | + | |
| 17 | + useEffect(() => { | |
| 18 | + const timer = setInterval(() => { | |
| 19 | + setDotsCount((current) => (current % 3) + 1); | |
| 20 | + }, interval); | |
| 21 | + | |
| 22 | + return () => clearInterval(timer); | |
| 23 | + }, [interval]); | |
| 24 | + | |
| 25 | + const dots = ".".repeat(dotsCount); | |
| 26 | + | |
| 27 | + return ( | |
| 28 | + <Text color={color}> | |
| 29 | + {text} | |
| 30 | + {dots} | |
| 31 | + </Text> | |
| 32 | + ); | |
| 33 | +}; |
| @@ -14,6 +14,7 @@ | ||
| 14 | 14 | ConfigServiceState, |
| 15 | 15 | MCPServiceState, |
| 16 | 16 | ModelServiceState, |
| 17 | + UpdateServiceState, | |
| 17 | 18 | } from "../services/types.js"; |
| 18 | 19 | import { logger } from "../util/logger.js"; |
| 19 | 20 | |
| @@ -93,7 +94,8 @@ | ||
| 93 | 94 | model: ModelServiceState; |
| 94 | 95 | mcp: MCPServiceState; |
| 95 | 96 | apiClient: ApiClientServiceState; |
| 96 | - }>(["auth", "config", "model", "mcp", "apiClient"]); | |
| 97 | + update: UpdateServiceState; | |
| 98 | + }>(["auth", "config", "model", "mcp", "apiClient", "update"]); | |
| 97 | 99 | |
| 98 | 100 | return { services, allServicesReady, isRemoteMode }; |
| 99 | 101 | } |
| @@ -207,6 +209,7 @@ | ||
| 207 | 209 | onShowConfigSelector: () => navigateTo("config"), |
| 208 | 210 | onShowModelSelector: () => navigateTo("model"), |
| 209 | 211 | onShowMCPSelector: () => navigateTo("mcp"), |
| 212 | + onShowUpdateSelector: () => navigateTo("update"), | |
| 210 | 213 | onShowSessionSelector: () => navigateTo("session"), |
| 211 | 214 | onLoginPrompt: handleLoginPrompt, |
| 212 | 215 | onReload: handleReload, |
| @@ -1,10 +1,3 @@ | ||
| 1 | -// Mock the version module before any other imports | |
| 2 | -vi.mock("../version.js", () => ({ | |
| 3 | - getVersion: vi.fn(), | |
| 4 | - getLatestVersion: vi.fn(), | |
| 5 | - compareVersions: vi.fn(), | |
| 6 | -})); | |
| 7 | - | |
| 8 | 1 | // Mock useTerminalSize hook |
| 9 | 2 | vi.mock("./hooks/useTerminalSize.js", () => ({ |
| 10 | 3 | useTerminalSize: () => ({ columns: 80, rows: 24 }), |
| @@ -30,93 +23,202 @@ | ||
| 30 | 23 | import React from "react"; |
| 31 | 24 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
| 32 | 25 | |
| 33 | -import * as versionModule from "../version.js"; | |
| 26 | +import { UpdateStatus } from "../services/types.js"; | |
| 34 | 27 | |
| 35 | 28 | import { UpdateNotification } from "./UpdateNotification.js"; |
| 36 | 29 | |
| 37 | -const mockVersionModule = vi.mocked(versionModule); | |
| 30 | +// Mock useServices hook | |
| 31 | +const mockUseServices = vi.fn(); | |
| 32 | +vi.mock("../hooks/useService.js", () => ({ | |
| 33 | + useServices: () => mockUseServices(), | |
| 34 | +})); | |
| 38 | 35 | |
| 39 | 36 | describe("UpdateNotification", () => { |
| 40 | - let originalNodeEnv: string | undefined; | |
| 41 | - | |
| 42 | 37 | beforeEach(() => { |
| 43 | 38 | vi.clearAllMocks(); |
| 44 | - originalNodeEnv = process.env.NODE_ENV; | |
| 45 | - // Default mock implementations | |
| 46 | - mockVersionModule.getLatestVersion.mockResolvedValue("1.0.1"); | |
| 47 | - mockVersionModule.compareVersions.mockReturnValue("older"); | |
| 39 | + // Default mock implementation - no update available | |
| 40 | + mockUseServices.mockReturnValue({ | |
| 41 | + services: { | |
| 42 | + update: { | |
| 43 | + autoUpdate: true, | |
| 44 | + status: UpdateStatus.IDLE, | |
| 45 | + message: "Continue CLI v1.0.0", | |
| 46 | + error: null, | |
| 47 | + isUpdateAvailable: false, | |
| 48 | + latestVersion: null, | |
| 49 | + currentVersion: "1.0.0", | |
| 50 | + }, | |
| 51 | + }, | |
| 52 | + }); | |
| 48 | 53 | }); |
| 49 | 54 | |
| 50 | 55 | afterEach(() => { |
| 51 | - // Restore original NODE_ENV | |
| 52 | - if (originalNodeEnv === undefined) { | |
| 53 | - delete process.env.NODE_ENV; | |
| 54 | - } else { | |
| 55 | - process.env.NODE_ENV = originalNodeEnv; | |
| 56 | - } | |
| 56 | + vi.clearAllMocks(); | |
| 57 | 57 | }); |
| 58 | 58 | |
| 59 | - it("should not check for updates when version ends with -dev", async () => { | |
| 60 | - // Set NODE_ENV to non-test value to enable update checks | |
| 61 | - process.env.NODE_ENV = "development"; | |
| 62 | - mockVersionModule.getVersion.mockReturnValue("1.0.0-dev"); | |
| 63 | - | |
| 64 | - render(<UpdateNotification />); | |
| 59 | + it("should show default message when no update is available", () => { | |
| 60 | + const { lastFrame } = render(<UpdateNotification />); | |
| 65 | 61 | |
| 66 | - // Wait a bit to ensure useEffect has run | |
| 67 | - await new Promise((resolve) => setTimeout(resolve, 50)); | |
| 68 | - | |
| 69 | - // getLatestVersion should not have been called for dev versions | |
| 70 | - expect(mockVersionModule.getLatestVersion).not.toHaveBeenCalled(); | |
| 62 | + expect(lastFrame()).toContain("◉ Continue CLI v1.0.0"); | |
| 71 | 63 | }); |
| 72 | 64 | |
| 73 | - it("should check for updates when version does not end with -dev", async () => { | |
| 74 | - // Set NODE_ENV to non-test value to enable update checks | |
| 75 | - process.env.NODE_ENV = "development"; | |
| 76 | - mockVersionModule.getVersion.mockReturnValue("1.0.0"); | |
| 77 | - | |
| 78 | - render(<UpdateNotification />); | |
| 79 | - | |
| 80 | - // Wait a bit to ensure useEffect has run | |
| 81 | - await new Promise((resolve) => setTimeout(resolve, 50)); | |
| 82 | - | |
| 83 | - // getLatestVersion should have been called for non-dev versions | |
| 84 | - expect(mockVersionModule.getLatestVersion).toHaveBeenCalled(); | |
| 65 | + it("should show update available message when update is available", () => { | |
| 66 | + mockUseServices.mockReturnValue({ | |
| 67 | + services: { | |
| 68 | + update: { | |
| 69 | + autoUpdate: true, | |
| 70 | + status: UpdateStatus.IDLE, | |
| 71 | + message: "Update available: v1.0.1", | |
| 72 | + error: null, | |
| 73 | + isUpdateAvailable: true, | |
| 74 | + latestVersion: "1.0.1", | |
| 75 | + currentVersion: "1.0.0", | |
| 76 | + }, | |
| 77 | + }, | |
| 78 | + }); | |
| 79 | + | |
| 80 | + const { lastFrame } = render(<UpdateNotification />); | |
| 81 | + | |
| 82 | + expect(lastFrame()).toContain("◉ Update available: v1.0.1"); | |
| 85 | 83 | }); |
| 86 | 84 | |
| 87 | - it("should handle various dev version formats", async () => { | |
| 88 | - // Set NODE_ENV to non-test value to enable update checks | |
| 89 | - process.env.NODE_ENV = "development"; | |
| 90 | - const devVersions = ["1.0.0-dev", "2.1.3-dev", "0.5.0-dev"]; | |
| 91 | - | |
| 92 | - for (const version of devVersions) { | |
| 93 | - vi.clearAllMocks(); | |
| 94 | - mockVersionModule.getVersion.mockReturnValue(version); | |
| 95 | - | |
| 96 | - render(<UpdateNotification />); | |
| 97 | - | |
| 98 | - // Wait a bit to ensure useEffect has run | |
| 99 | - await new Promise((resolve) => setTimeout(resolve, 50)); | |
| 85 | + it("should show checking message when checking for updates", () => { | |
| 86 | + mockUseServices.mockReturnValue({ | |
| 87 | + services: { | |
| 88 | + update: { | |
| 89 | + autoUpdate: true, | |
| 90 | + status: UpdateStatus.CHECKING, | |
| 91 | + message: "Checking for updates", | |
| 92 | + error: null, | |
| 93 | + isUpdateAvailable: false, | |
| 94 | + latestVersion: null, | |
| 95 | + currentVersion: "1.0.0", | |
| 96 | + }, | |
| 97 | + }, | |
| 98 | + }); | |
| 99 | + | |
| 100 | + const { lastFrame } = render(<UpdateNotification />); | |
| 101 | + | |
| 102 | + expect(lastFrame()).toContain("◉ Checking for updates"); | |
| 103 | + }); | |
| 100 | 104 | |
| 101 | - expect(mockVersionModule.getLatestVersion).not.toHaveBeenCalled(); | |
| 102 | - } | |
| 105 | + it("should show updating message when updating", () => { | |
| 106 | + mockUseServices.mockReturnValue({ | |
| 107 | + services: { | |
| 108 | + update: { | |
| 109 | + autoUpdate: true, | |
| 110 | + status: UpdateStatus.UPDATING, | |
| 111 | + message: "Updating to v1.0.1", | |
| 112 | + error: null, | |
| 113 | + isUpdateAvailable: false, | |
| 114 | + latestVersion: "1.0.1", | |
| 115 | + currentVersion: "1.0.0", | |
| 116 | + }, | |
| 117 | + }, | |
| 118 | + }); | |
| 119 | + | |
| 120 | + const { lastFrame } = render(<UpdateNotification />); | |
| 121 | + | |
| 122 | + expect(lastFrame()).toContain("◉ Updating to v1.0.1"); | |
| 103 | 123 | }); |
| 104 | 124 | |
| 105 | - it("should still check for updates with other version suffixes", async () => { | |
| 106 | - // Set NODE_ENV to non-test value to enable update checks | |
| 107 | - process.env.NODE_ENV = "development"; | |
| 108 | - const nonDevVersions = ["1.0.0-beta", "1.0.0-alpha", "1.0.0-rc1"]; | |
| 125 | + it("should show updated message when update completes", () => { | |
| 126 | + mockUseServices.mockReturnValue({ | |
| 127 | + services: { | |
| 128 | + update: { | |
| 129 | + autoUpdate: true, | |
| 130 | + status: UpdateStatus.UPDATED, | |
| 131 | + message: "Auto-updated to v1.0.1", | |
| 132 | + error: null, | |
| 133 | + isUpdateAvailable: false, | |
| 134 | + latestVersion: "1.0.1", | |
| 135 | + currentVersion: "1.0.0", | |
| 136 | + }, | |
| 137 | + }, | |
| 138 | + }); | |
| 139 | + | |
| 140 | + const { lastFrame } = render(<UpdateNotification />); | |
| 141 | + | |
| 142 | + expect(lastFrame()).toContain("◉ Auto-updated to v1.0.1"); | |
| 143 | + }); | |
| 109 | 144 | |
| 110 | - for (const version of nonDevVersions) { | |
| 111 | - vi.clearAllMocks(); | |
| 112 | - mockVersionModule.getVersion.mockReturnValue(version); | |
| 145 | + it("should show error message when update fails", () => { | |
| 146 | + mockUseServices.mockReturnValue({ | |
| 147 | + services: { | |
| 148 | + update: { | |
| 149 | + autoUpdate: true, | |
| 150 | + status: UpdateStatus.ERROR, | |
| 151 | + message: "Update failed", | |
| 152 | + error: new Error("Update error"), | |
| 153 | + isUpdateAvailable: true, | |
| 154 | + latestVersion: "1.0.1", | |
| 155 | + currentVersion: "1.0.0", | |
| 156 | + }, | |
| 157 | + }, | |
| 158 | + }); | |
| 159 | + | |
| 160 | + const { lastFrame } = render(<UpdateNotification />); | |
| 161 | + | |
| 162 | + expect(lastFrame()).toContain("◉ Update failed"); | |
| 163 | + }); | |
| 113 | 164 | |
| 114 | - render(<UpdateNotification />); | |
| 165 | + it("should show remote mode when in remote mode and no update available", () => { | |
| 166 | + mockUseServices.mockReturnValue({ | |
| 167 | + services: { | |
| 168 | + update: { | |
| 169 | + autoUpdate: true, | |
| 170 | + status: UpdateStatus.IDLE, | |
| 171 | + message: "Continue CLI v1.0.0", | |
| 172 | + error: null, | |
| 173 | + isUpdateAvailable: false, | |
| 174 | + latestVersion: null, | |
| 175 | + currentVersion: "1.0.0", | |
| 176 | + }, | |
| 177 | + }, | |
| 178 | + }); | |
| 179 | + | |
| 180 | + const { lastFrame } = render(<UpdateNotification isRemoteMode={true} />); | |
| 181 | + | |
| 182 | + expect(lastFrame()).toContain("◉ Remote Mode"); | |
| 183 | + }); | |
| 115 | 184 | |
| 116 | - // Wait a bit to ensure useEffect has run | |
| 117 | - await new Promise((resolve) => setTimeout(resolve, 50)); | |
| 185 | + it("should show update message even in remote mode when update is available", () => { | |
| 186 | + mockUseServices.mockReturnValue({ | |
| 187 | + services: { | |
| 188 | + update: { | |
| 189 | + autoUpdate: true, | |
| 190 | + status: UpdateStatus.IDLE, | |
| 191 | + message: "Update available: v1.0.1", | |
| 192 | + error: null, | |
| 193 | + isUpdateAvailable: true, | |
| 194 | + latestVersion: "1.0.1", | |
| 195 | + currentVersion: "1.0.0", | |
| 196 | + }, | |
| 197 | + }, | |
| 198 | + }); | |
| 199 | + | |
| 200 | + const { lastFrame } = render(<UpdateNotification isRemoteMode={true} />); | |
| 201 | + | |
| 202 | + expect(lastFrame()).toContain("◉ Update available: v1.0.1"); | |
| 203 | + }); | |
| 118 | 204 | |
| 119 | - expect(mockVersionModule.getLatestVersion).toHaveBeenCalled(); | |
| 120 | - } | |
| 205 | + it("should show default message when update service has no message", () => { | |
| 206 | + mockUseServices.mockReturnValue({ | |
| 207 | + services: { | |
| 208 | + update: { | |
| 209 | + autoUpdate: true, | |
| 210 | + status: UpdateStatus.IDLE, | |
| 211 | + message: "", | |
| 212 | + error: null, | |
| 213 | + isUpdateAvailable: false, | |
| 214 | + latestVersion: null, | |
| 215 | + currentVersion: "1.0.0", | |
| 216 | + }, | |
| 217 | + }, | |
| 218 | + }); | |
| 219 | + | |
| 220 | + const { lastFrame } = render(<UpdateNotification />); | |
| 221 | + | |
| 222 | + expect(lastFrame()).toContain("◉ Continue CLI"); | |
| 121 | 223 | }); |
| 122 | 224 | }); |
| @@ -1,79 +1,54 @@ | ||
| 1 | 1 | import { Text } from "ink"; |
| 2 | -import React, { useEffect, useMemo, useState } from "react"; | |
| 3 | - | |
| 4 | -import { compareVersions, getLatestVersion, getVersion } from "../version.js"; | |
| 2 | +import React, { useMemo } from "react"; | |
| 3 | + | |
| 4 | +import { useServices } from "../hooks/useService.js"; | |
| 5 | +import { | |
| 6 | + SERVICE_NAMES, | |
| 7 | + UpdateServiceState, | |
| 8 | + UpdateStatus, | |
| 9 | +} from "../services/types.js"; | |
| 5 | 10 | |
| 6 | 11 | import { useTerminalSize } from "./hooks/useTerminalSize.js"; |
| 7 | 12 | |
| 8 | 13 | interface UpdateNotificationProps { |
| 9 | 14 | isRemoteMode?: boolean; |
| 10 | 15 | } |
| 11 | - | |
| 12 | 16 | const UpdateNotification: React.FC<UpdateNotificationProps> = ({ |
| 13 | 17 | isRemoteMode = false, |
| 14 | 18 | }) => { |
| 15 | - const [updateAvailable, setUpdateAvailable] = useState(false); | |
| 16 | - const [latestVersion, setLatestVersion] = useState<string>(""); | |
| 17 | - const [currentVersion] = useState(getVersion()); | |
| 18 | 19 | const { columns } = useTerminalSize(); |
| 19 | 20 | |
| 20 | - useEffect(() => { | |
| 21 | - // Skip update check in test environment | |
| 22 | - if (process.env.NODE_ENV === "test") { | |
| 23 | - return; | |
| 21 | + const { services } = useServices<{ | |
| 22 | + update: UpdateServiceState; | |
| 23 | + }>([SERVICE_NAMES.UPDATE]); | |
| 24 | + | |
| 25 | + const color = useMemo(() => { | |
| 26 | + switch (services.update?.status) { | |
| 27 | + case UpdateStatus.UPDATING: | |
| 28 | + case UpdateStatus.CHECKING: | |
| 29 | + return "yellow"; | |
| 30 | + case UpdateStatus.UPDATED: | |
| 31 | + return "green"; | |
| 32 | + case UpdateStatus.ERROR: | |
| 33 | + return "red"; | |
| 34 | + default: | |
| 35 | + return "dim"; | |
| 24 | 36 | } |
| 37 | + }, [services.update?.status]); | |
| 25 | 38 | |
| 26 | - // Skip update check for development versions | |
| 27 | - if (currentVersion.endsWith("-dev")) { | |
| 28 | - return; | |
| 39 | + const text = useMemo(() => { | |
| 40 | + if (!services.update?.message) { | |
| 41 | + return "Continue CLI"; | |
| 29 | 42 | } |
| 30 | 43 | |
| 31 | - const abortController = new AbortController(); | |
| 32 | - | |
| 33 | - const checkForUpdate = async () => { | |
| 34 | - try { | |
| 35 | - const latest = await getLatestVersion(abortController.signal); | |
| 36 | - if (latest) { | |
| 37 | - setLatestVersion(latest); | |
| 38 | - const comparison = compareVersions(currentVersion, latest); | |
| 39 | - setUpdateAvailable(comparison === "older"); | |
| 40 | - } | |
| 41 | - } catch (error) { | |
| 42 | - // Silently fail - we don't want to interrupt the user experience | |
| 43 | - if (error instanceof Error && error.name !== "AbortError") { | |
| 44 | - console.debug("Failed to check for updates:", error); | |
| 45 | - } | |
| 46 | - } | |
| 47 | - }; | |
| 48 | - | |
| 49 | - // Check for updates but don't block | |
| 50 | - checkForUpdate(); | |
| 51 | - | |
| 52 | - // Cleanup function to abort the request when component unmounts | |
| 53 | - return () => { | |
| 54 | - abortController.abort(); | |
| 55 | - }; | |
| 56 | - }, [currentVersion]); | |
| 44 | + return services.update.message; | |
| 45 | + }, [columns, services.update?.message]); | |
| 57 | 46 | |
| 58 | - const text = useMemo(() => { | |
| 59 | - if (columns < 75) { | |
| 60 | - return `v${latestVersion} available`; | |
| 61 | - } | |
| 62 | - return `Update available: v${latestVersion} (npm i -g @continuedev/cli)`; | |
| 63 | - }, [columns, latestVersion]); | |
| 64 | - | |
| 65 | - if (!updateAvailable) { | |
| 66 | - if (isRemoteMode) { | |
| 67 | - return <Text color="cyan">◉ Remote Mode</Text>; | |
| 68 | - } | |
| 69 | - return ( | |
| 70 | - <Text wrap="truncate-end" color="gray"> | |
| 71 | - ● Continue CLI | |
| 72 | - </Text> | |
| 73 | - ); | |
| 47 | + if (!services.update?.isUpdateAvailable && isRemoteMode) { | |
| 48 | + return <Text color="cyan">◉ Remote Mode</Text>; | |
| 74 | 49 | } |
| 75 | 50 | |
| 76 | - return <Text color="dim">{text}</Text>; | |
| 51 | + return <Text color={color}>{`◉ ${text}`}</Text>; | |
| 77 | 52 | }; |
| 78 | 53 | |
| 79 | 54 | export { UpdateNotification }; |
| @@ -0,0 +1,93 @@ | ||
| 1 | +import React, { useMemo, useState } from "react"; | |
| 2 | + | |
| 3 | +import { useService } from "../hooks/useService.js"; | |
| 4 | +import { services } from "../services/index.js"; | |
| 5 | +import type { UpdateServiceState } from "../services/types.js"; | |
| 6 | +import { SERVICE_NAMES } from "../services/types.js"; | |
| 7 | + | |
| 8 | +import { Selector, SelectorOption } from "./Selector.js"; | |
| 9 | + | |
| 10 | +interface UpdateSelectorProps { | |
| 11 | + onCancel: () => void; | |
| 12 | +} | |
| 13 | + | |
| 14 | +interface UpdateOption extends SelectorOption { | |
| 15 | + action: "run" | "toggle-auto" | "back"; | |
| 16 | +} | |
| 17 | + | |
| 18 | +export const UpdateSelector: React.FC<UpdateSelectorProps> = ({ onCancel }) => { | |
| 19 | + const [selectedIndex, setSelectedIndex] = useState(0); | |
| 20 | + const updateServiceState = useService<UpdateServiceState>( | |
| 21 | + SERVICE_NAMES.UPDATE, | |
| 22 | + ); | |
| 23 | + | |
| 24 | + const updateState = updateServiceState.value; | |
| 25 | + | |
| 26 | + const isWorking = | |
| 27 | + updateServiceState.state === "loading" || | |
| 28 | + updateState?.status === "checking" || | |
| 29 | + updateState?.status === "updating"; | |
| 30 | + | |
| 31 | + const error: string | null = useMemo(() => { | |
| 32 | + if (updateServiceState.state === "error") { | |
| 33 | + return updateServiceState.error?.message || "Update service error"; | |
| 34 | + } | |
| 35 | + if (updateState?.status === "error") { | |
| 36 | + return updateState.message || "Update failed"; | |
| 37 | + } | |
| 38 | + return null; | |
| 39 | + }, [updateServiceState.state, updateServiceState.error, updateState]); | |
| 40 | + | |
| 41 | + const loadingMessage = useMemo(() => { | |
| 42 | + if (!updateState) return "Preparing update..."; | |
| 43 | + return updateState.message || "Working..."; | |
| 44 | + }, [updateState]); | |
| 45 | + | |
| 46 | + const options: UpdateOption[] = useMemo(() => { | |
| 47 | + const runLabel = updateState?.latestVersion | |
| 48 | + ? `Run update to v${updateState.latestVersion}` | |
| 49 | + : "Run update"; | |
| 50 | + | |
| 51 | + const autoUpdateLabel = updateState?.autoUpdate | |
| 52 | + ? "Turn off auto-updates" | |
| 53 | + : "Turn on auto-updates"; | |
| 54 | + | |
| 55 | + return [ | |
| 56 | + { id: "run-update", name: runLabel, action: "run" }, | |
| 57 | + { id: "toggle-auto", name: autoUpdateLabel, action: "toggle-auto" }, | |
| 58 | + { id: "back", name: "Back", action: "back" }, | |
| 59 | + ]; | |
| 60 | + }, [updateState?.latestVersion, updateState?.autoUpdate]); | |
| 61 | + | |
| 62 | + const handleSelect = async (option: UpdateOption) => { | |
| 63 | + switch (option.action) { | |
| 64 | + case "run": | |
| 65 | + // Perform a manual update (not auto-update) | |
| 66 | + await services.updateService.performUpdate(false); | |
| 67 | + return; // Keep selector open to show status changes | |
| 68 | + case "toggle-auto": | |
| 69 | + // Toggle auto-update setting | |
| 70 | + const newValue = !updateState?.autoUpdate; | |
| 71 | + await services.updateService.setAutoUpdate(newValue); | |
| 72 | + return; // Keep selector open to show updated label | |
| 73 | + case "back": | |
| 74 | + onCancel(); | |
| 75 | + return; | |
| 76 | + } | |
| 77 | + }; | |
| 78 | + | |
| 79 | + return ( | |
| 80 | + <Selector | |
| 81 | + title="Update Continue CLI" | |
| 82 | + options={options} | |
| 83 | + selectedIndex={selectedIndex} | |
| 84 | + loading={!!isWorking} | |
| 85 | + error={error} | |
| 86 | + loadingMessage={loadingMessage} | |
| 87 | + currentId={null} | |
| 88 | + onSelect={handleSelect} | |
| 89 | + onCancel={onCancel} | |
| 90 | + onNavigate={setSelectedIndex} | |
| 91 | + /> | |
| 92 | + ); | |
| 93 | +}; |
| @@ -1,6 +1,8 @@ | ||
| 1 | 1 | import { Box, Text } from "ink"; |
| 2 | 2 | import React from "react"; |
| 3 | 3 | |
| 4 | +import { UpdateServiceState } from "src/services/types.js"; | |
| 5 | + | |
| 4 | 6 | import { listSessions } from "../../session.js"; |
| 5 | 7 | import { ConfigSelector } from "../ConfigSelector.js"; |
| 6 | 8 | import type { NavigationScreen } from "../context/NavigationContext.js"; |
| @@ -9,6 +11,7 @@ | ||
| 9 | 11 | import { ModelSelector } from "../ModelSelector.js"; |
| 10 | 12 | import { SessionSelector } from "../SessionSelector.js"; |
| 11 | 13 | import type { ConfigOption, ModelOption } from "../types/selectorTypes.js"; |
| 14 | +import { UpdateSelector } from "../UpdateSelector.js"; | |
| 12 | 15 | import { UserInput } from "../UserInput.js"; |
| 13 | 16 | |
| 14 | 17 | import { ToolPermissionSelector } from "./ToolPermissionSelector.js"; |
| @@ -42,6 +45,14 @@ | ||
| 42 | 45 | onImageInClipboardChange?: (hasImage: boolean) => void; |
| 43 | 46 | } |
| 44 | 47 | |
| 48 | +function hideScreenContent(state?: UpdateServiceState) { | |
| 49 | + return ( | |
| 50 | + (state?.status === "checking" && state?.autoUpdate) || | |
| 51 | + (state?.isAutoUpdate && | |
| 52 | + (state?.status === "updating" || state?.status === "updated")) | |
| 53 | + ); | |
| 54 | +} | |
| 55 | + | |
| 45 | 56 | export const ScreenContent: React.FC<ScreenContentProps> = ({ |
| 46 | 57 | isScreenActive, |
| 47 | 58 | navState, |
| @@ -65,6 +76,10 @@ | ||
| 65 | 76 | isRemoteMode, |
| 66 | 77 | onImageInClipboardChange, |
| 67 | 78 | }) => { |
| 79 | + if (hideScreenContent(services.update)) { | |
| 80 | + return null; | |
| 81 | + } | |
| 82 | + | |
| 68 | 83 | // Login prompt |
| 69 | 84 | if (isScreenActive("login") && navState.screenData) { |
| 70 | 85 | return ( |
| @@ -106,6 +121,10 @@ | ||
| 106 | 121 | return <MCPSelector onCancel={closeCurrentScreen} />; |
| 107 | 122 | } |
| 108 | 123 | |
| 124 | + if (isScreenActive("update")) { | |
| 125 | + return <UpdateSelector onCancel={closeCurrentScreen} />; | |
| 126 | + } | |
| 127 | + | |
| 109 | 128 | // Model selector |
| 110 | 129 | if (isScreenActive("model")) { |
| 111 | 130 | return ( |
| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | import React, { |
| 2 | 2 | createContext, |
| 3 | + ReactNode, | |
| 4 | + useCallback, | |
| 3 | 5 | useContext, |
| 4 | 6 | useReducer, |
| 5 | - useCallback, | |
| 6 | - ReactNode, | |
| 7 | 7 | } from "react"; |
| 8 | 8 | |
| 9 | 9 | /** |
| @@ -17,6 +17,7 @@ | ||
| 17 | 17 | | "free-trial" // Free trial transition UI |
| 18 | 18 | | "login" // Login prompt |
| 19 | 19 | | "mcp" // MCP selector |
| 20 | + | "update" // Update selector | |
| 20 | 21 | | "session"; // Session selector |
| 21 | 22 | |
| 22 | 23 | interface NavigationState { |
| @@ -48,6 +48,7 @@ | ||
| 48 | 48 | setChatHistory: React.Dispatch<React.SetStateAction<ChatHistoryItem[]>>; |
| 49 | 49 | onShowConfigSelector: () => void; |
| 50 | 50 | onShowModelSelector?: () => void; |
| 51 | + onShowUpdateSelector?: () => void; | |
| 51 | 52 | onShowMCPSelector?: () => void; |
| 52 | 53 | onShowSessionSelector?: () => void; |
| 53 | 54 | onClear?: () => void; |
| @@ -61,6 +62,7 @@ | ||
| 61 | 62 | chatHistory, |
| 62 | 63 | setChatHistory, |
| 63 | 64 | onShowConfigSelector, |
| 65 | + onShowUpdateSelector, | |
| 64 | 66 | onShowModelSelector, |
| 65 | 67 | onShowMCPSelector, |
| 66 | 68 | onShowSessionSelector, |
| @@ -75,6 +77,11 @@ | ||
| 75 | 77 | return null; |
| 76 | 78 | } |
| 77 | 79 | |
| 80 | + if (result.openUpdateSelector) { | |
| 81 | + onShowUpdateSelector?.(); | |
| 82 | + return null; | |
| 83 | + } | |
| 84 | + | |
| 78 | 85 | if (result.openConfigSelector) { |
| 79 | 86 | onShowConfigSelector(); |
| 80 | 87 | return null; |
| @@ -55,6 +55,7 @@ | ||
| 55 | 55 | additionalPrompts, |
| 56 | 56 | onShowConfigSelector, |
| 57 | 57 | onShowModelSelector, |
| 58 | + onShowUpdateSelector, | |
| 58 | 59 | onShowMCPSelector, |
| 59 | 60 | onShowSessionSelector, |
| 60 | 61 | onLoginPrompt: _onLoginPrompt, |
| @@ -419,6 +420,7 @@ | ||
| 419 | 420 | onShowModelSelector, |
| 420 | 421 | onShowMCPSelector, |
| 421 | 422 | onShowSessionSelector, |
| 423 | + onShowUpdateSelector, | |
| 422 | 424 | onClear, |
| 423 | 425 | }); |
| 424 | 426 |
| @@ -15,6 +15,7 @@ | ||
| 15 | 15 | additionalPrompts?: string[]; |
| 16 | 16 | onShowConfigSelector: () => void; |
| 17 | 17 | onShowMCPSelector: () => void; |
| 18 | + onShowUpdateSelector: () => void; | |
| 18 | 19 | onShowModelSelector?: () => void; |
| 19 | 20 | onShowSessionSelector?: () => void; |
| 20 | 21 | onLoginPrompt?: (promptText: string) => Promise<string>; |
| @@ -57,6 +58,7 @@ | ||
| 57 | 58 | openConfigSelector?: boolean; |
| 58 | 59 | openModelSelector?: boolean; |
| 59 | 60 | openMcpSelector?: boolean; |
| 61 | + openUpdateSelector?: boolean; | |
| 60 | 62 | openSessionSelector?: boolean; |
| 61 | 63 | compact?: boolean; |
| 62 | 64 | } |
| @@ -77,10 +77,40 @@ | ||
| 77 | 77 | ); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | +/** | |
| 81 | + * Checks if the error indicates a context length issue (non-retryable) | |
| 82 | + */ | |
| 83 | +export function isContextLengthError(error: any): boolean { | |
| 84 | + const errorMessage = error.message?.toLowerCase() || ""; | |
| 85 | + const contextLengthPatterns = [ | |
| 86 | + // Anthropic Claude | |
| 87 | + "input length and max_tokens exceed context limit", | |
| 88 | + "decrease input length or max_tokens", | |
| 89 | + // OpenAI | |
| 90 | + "maximum context length", | |
| 91 | + "reduce the length of the messages", | |
| 92 | + // Mistral | |
| 93 | + "tokens in the prompt exceeds", | |
| 94 | + "use a shorter prompt", | |
| 95 | + // Generic patterns | |
| 96 | + "context_length_exceeded", | |
| 97 | + "invalid_request_error", | |
| 98 | + ]; | |
| 99 | + | |
| 100 | + return contextLengthPatterns.some((pattern) => | |
| 101 | + errorMessage.includes(pattern), | |
| 102 | + ); | |
| 103 | +} | |
| 104 | + | |
| 80 | 105 | /** |
| 81 | 106 | * Determines if an error is retryable based on the error type and status code |
| 82 | 107 | */ |
| 83 | 108 | function isRetryableError(error: any): boolean { |
| 109 | + // Context length errors are never retryable - they need user intervention | |
| 110 | + if (isContextLengthError(error)) { | |
| 111 | + return false; | |
| 112 | + } | |
| 113 | + | |
| 84 | 114 | // Network errors are retryable |
| 85 | 115 | if (isNetworkError(error)) { |
| 86 | 116 | return true; |
| @@ -0,0 +1,62 @@ | ||
| 1 | +import { ModelConfig } from "@continuedev/config-yaml"; | |
| 2 | +import { describe, expect, it } from "vitest"; | |
| 3 | + | |
| 4 | +import { validateContextLength } from "./tokenizer.js"; | |
| 5 | + | |
| 6 | +describe("validateContextLength", () => { | |
| 7 | + const createMockModel = ( | |
| 8 | + contextLength: number, | |
| 9 | + maxTokens?: number, | |
| 10 | + ): ModelConfig => ({ | |
| 11 | + name: "test-model", | |
| 12 | + model: "test", | |
| 13 | + provider: "openai", | |
| 14 | + defaultCompletionOptions: { | |
| 15 | + contextLength, | |
| 16 | + maxTokens, | |
| 17 | + }, | |
| 18 | + }); | |
| 19 | + | |
| 20 | + const createMockHistory = (messageCount: number, contentLength = 100) => { | |
| 21 | + return Array.from({ length: messageCount }, (_, i) => ({ | |
| 22 | + message: { | |
| 23 | + role: "user" as const, | |
| 24 | + content: "x".repeat(contentLength), // Roughly contentLength/4 tokens | |
| 25 | + }, | |
| 26 | + contextItems: [], | |
| 27 | + })); | |
| 28 | + }; | |
| 29 | + | |
| 30 | + it("should pass validation when within context limits", () => { | |
| 31 | + const model = createMockModel(1000, 200); | |
| 32 | + const chatHistory = createMockHistory(5, 40); // ~50 tokens total | |
| 33 | + | |
| 34 | + const result = validateContextLength(chatHistory, model); | |
| 35 | + | |
| 36 | + expect(result.isValid).toBe(true); | |
| 37 | + expect(result.error).toBeUndefined(); | |
| 38 | + }); | |
| 39 | + | |
| 40 | + it("should fail validation when input + maxTokens exceeds context limit", () => { | |
| 41 | + const model = createMockModel(1000, 800); | |
| 42 | + const chatHistory = createMockHistory(20, 100); // ~500+ tokens | |
| 43 | + | |
| 44 | + const result = validateContextLength(chatHistory, model); | |
| 45 | + | |
| 46 | + expect(result.isValid).toBe(false); | |
| 47 | + expect(result.error).toContain("Context length exceeded"); | |
| 48 | + expect(result.error).toContain("input"); | |
| 49 | + expect(result.error).toContain("max_tokens"); | |
| 50 | + expect(result.error).toContain("context_limit"); | |
| 51 | + }); | |
| 52 | + | |
| 53 | + it("should handle large models with appropriate scaling", () => { | |
| 54 | + const model = createMockModel(200_000, 64_000); // Claude-like model | |
| 55 | + const chatHistory = createMockHistory(100, 1000); // Large conversation | |
| 56 | + | |
| 57 | + const result = validateContextLength(chatHistory, model); | |
| 58 | + | |
| 59 | + expect(result.contextLimit).toBe(200_000); | |
| 60 | + expect(result.maxTokens).toBe(64_000); | |
| 61 | + }); | |
| 62 | +}); |
| @@ -78,14 +78,14 @@ | ||
| 78 | 78 | role: "user", |
| 79 | 79 | content: [ |
| 80 | 80 | { type: "text", text: "Hello" }, // 5 chars -> ~2 tokens |
| 81 | - { type: "imageUrl", imageUrl: { url: "test.jpg" } }, // +85 tokens | |
| 81 | + { type: "imageUrl", imageUrl: { url: "test.jpg" } }, // +1024 tokens | |
| 82 | 82 | ], |
| 83 | 83 | }, |
| 84 | 84 | contextItems: [], |
| 85 | 85 | }; |
| 86 | 86 | |
| 87 | 87 | const tokenCount = countChatHistoryItemTokens(historyItem); |
| 88 | - expect(tokenCount).toBe(89); // 2 + 85 + 2 role tokens | |
| 88 | + expect(tokenCount).toBe(1028); // 2 + 1024 + 2 role tokens | |
| 89 | 89 | }); |
| 90 | 90 | |
| 91 | 91 | it("should count tokens for tool calls", () => { |
| @@ -47,7 +47,7 @@ | ||
| 47 | 47 | // Images and other content types have their own token costs |
| 48 | 48 | // but we'll use a rough estimate for now |
| 49 | 49 | if (part.type === "imageUrl") { |
| 50 | - tokenCount += 85; // Rough estimate for image tokens | |
| 50 | + tokenCount += 1024; // Rough estimate for image tokens | |
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | } |
| @@ -192,3 +192,46 @@ | ||
| 192 | 192 | const limit = getModelContextLimit(model); |
| 193 | 193 | return `Approaching context limit (${(limit / 1000).toFixed(0)}K tokens). Auto-compacting chat history...`; |
| 194 | 194 | } |
| 195 | + | |
| 196 | +/** | |
| 197 | + * Validates that the input tokens + max_tokens don't exceed context limit | |
| 198 | + * @param chatHistory The chat history to validate | |
| 199 | + * @param model The model configuration | |
| 200 | + * @returns Validation result with error details if invalid | |
| 201 | + */ | |
| 202 | +export function validateContextLength( | |
| 203 | + chatHistory: ChatHistoryItem[], | |
| 204 | + model: ModelConfig, | |
| 205 | +): { | |
| 206 | + isValid: boolean; | |
| 207 | + error?: string; | |
| 208 | + inputTokens?: number; | |
| 209 | + contextLimit?: number; | |
| 210 | + maxTokens?: number; | |
| 211 | +} { | |
| 212 | + const inputTokens = countChatHistoryTokens(chatHistory); | |
| 213 | + const contextLimit = getModelContextLimit(model); | |
| 214 | + const maxTokens = model.defaultCompletionOptions?.maxTokens || 0; | |
| 215 | + | |
| 216 | + // If maxTokens is not set, use 35% default reservation for output | |
| 217 | + const reservedForOutput = | |
| 218 | + maxTokens > 0 ? maxTokens : Math.ceil(contextLimit * 0.35); | |
| 219 | + const totalRequired = inputTokens + reservedForOutput; | |
| 220 | + | |
| 221 | + if (totalRequired > contextLimit) { | |
| 222 | + return { | |
| 223 | + isValid: false, | |
| 224 | + error: `Context length exceeded: input (${inputTokens.toLocaleString()}) + max_tokens (${reservedForOutput.toLocaleString()}) = ${totalRequired.toLocaleString()} > context_limit (${contextLimit.toLocaleString()})`, | |
| 225 | + inputTokens, | |
| 226 | + contextLimit, | |
| 227 | + maxTokens: reservedForOutput, | |
| 228 | + }; | |
| 229 | + } | |
| 230 | + | |
| 231 | + return { | |
| 232 | + isValid: true, | |
| 233 | + inputTokens, | |
| 234 | + contextLimit, | |
| 235 | + maxTokens: reservedForOutput, | |
| 236 | + }; | |
| 237 | +} |
| @@ -45,6 +45,76 @@ | ||
| 45 | 45 | private val continuePluginService: ContinuePluginService, |
| 46 | 46 | |
| 47 | 47 | ) : IDE { |
| 48 | + | |
| 49 | + // Security-focused ignore patterns - should always be excluded for security reasons | |
| 50 | + private val DEFAULT_SECURITY_IGNORE_FILETYPES = listOf( | |
| 51 | + // Environment and configuration files with secrets | |
| 52 | + "*.env", "*.env.*", ".env*", "config.json", "config.yaml", "config.yml", | |
| 53 | + "settings.json", "appsettings.json", "appsettings.*.json", | |
| 54 | + | |
| 55 | + // Certificate and key files | |
| 56 | + "*.key", "*.pem", "*.p12", "*.pfx", "*.crt", "*.cer", "*.jks", | |
| 57 | + "*.keystore", "*.truststore", | |
| 58 | + | |
| 59 | + // Database files that may contain sensitive data | |
| 60 | + "*.db", "*.sqlite", "*.sqlite3", "*.mdb", "*.accdb", | |
| 61 | + | |
| 62 | + // Credential and secret files | |
| 63 | + "*.secret", "*.secrets", "credentials", "credentials.*", "auth.json", | |
| 64 | + "token", "token.*", "*.token", | |
| 65 | + | |
| 66 | + // Backup files that might contain sensitive data | |
| 67 | + "*.bak", "*.backup", "*.old", "*.orig", | |
| 68 | + | |
| 69 | + // Docker secrets | |
| 70 | + "docker-compose.override.yml", "docker-compose.override.yaml", | |
| 71 | + | |
| 72 | + // SSH and GPG | |
| 73 | + "id_rsa", "id_dsa", "id_ecdsa", "id_ed25519", "*.ppk", "*.gpg" | |
| 74 | + ) | |
| 75 | + | |
| 76 | + private val DEFAULT_SECURITY_IGNORE_DIRS = listOf( | |
| 77 | + // Environment and configuration directories | |
| 78 | + ".env/", "env/", | |
| 79 | + | |
| 80 | + // Cloud provider credential directories | |
| 81 | + ".aws/", ".gcp/", ".azure/", ".kube/", ".docker/", | |
| 82 | + | |
| 83 | + // Secret directories | |
| 84 | + "secrets/", ".secrets/", "private/", ".private/", "certs/", | |
| 85 | + "certificates/", "keys/", ".ssh/", ".gnupg/", ".gpg/", | |
| 86 | + | |
| 87 | + // Temporary directories that might contain sensitive data | |
| 88 | + "tmp/secrets/", "temp/secrets/", ".tmp/" | |
| 89 | + ) | |
| 90 | + | |
| 91 | + // Additional non-security patterns for general indexing exclusion | |
| 92 | + private val ADDITIONAL_SEARCH_IGNORE_FILETYPES = listOf( | |
| 93 | + "*.DS_Store", "*-lock.json", "*.lock", "*.log", "*.ttf", "*.png", | |
| 94 | + "*.jpg", "*.jpeg", "*.gif", "*.mp4", "*.svg", "*.ico", "*.pdf", | |
| 95 | + "*.zip", "*.gz", "*.tar", "*.dmg", "*.tgz", "*.rar", "*.7z", | |
| 96 | + "*.exe", "*.dll", "*.obj", "*.o", "*.o.d", "*.a", "*.lib", | |
| 97 | + "*.so", "*.dylib", "*.ncb", "*.sdf", "*.woff", "*.woff2", | |
| 98 | + "*.eot", "*.cur", "*.avi", "*.mpg", "*.mpeg", "*.mov", "*.mp3", | |
| 99 | + "*.mkv", "*.webm", "*.jar", "*.onnx", "*.parquet", "*.pqt", | |
| 100 | + "*.wav", "*.webp", "*.wasm", "*.plist", "*.profraw", "*.gcda", | |
| 101 | + "*.gcno", "go.sum", "*.gitignore", "*.gitkeep", "*.continueignore", | |
| 102 | + "*.csv", "*.uasset", "*.pdb", "*.bin", "*.pag", "*.swp", "*.jsonl" | |
| 103 | + ) | |
| 104 | + | |
| 105 | + private val ADDITIONAL_SEARCH_IGNORE_DIRS = listOf( | |
| 106 | + ".git/", ".svn/", "node_modules/", "dist/", "build/", "Build/", | |
| 107 | + "target/", "out/", "bin/", ".pytest_cache/", ".vscode-test/", | |
| 108 | + "__pycache__/", "site-packages/", ".gradle/", ".mvn/", ".cache/", | |
| 109 | + "gems/", "vendor/", ".venv/", "venv/", ".vscode/", ".idea/", ".vs/", | |
| 110 | + ".continue/" | |
| 111 | + ) | |
| 112 | + | |
| 113 | + // Combined patterns for use in ripgrep | |
| 114 | + private val DEFAULT_IGNORES = DEFAULT_SECURITY_IGNORE_FILETYPES + | |
| 115 | + DEFAULT_SECURITY_IGNORE_DIRS + | |
| 116 | + ADDITIONAL_SEARCH_IGNORE_FILETYPES + | |
| 117 | + ADDITIONAL_SEARCH_IGNORE_DIRS | |
| 48 | 118 | |
| 49 | 119 | private val gitService = GitService(project, continuePluginService) |
| 50 | 120 | private val fileUtils = FileUtils(project) |
| @@ -335,6 +405,9 @@ | ||
| 335 | 405 | val ideInfo = this.getIdeInfo() |
| 336 | 406 | if (ideInfo.remoteName == "local") { |
| 337 | 407 | try { |
| 408 | + // Create a single combined ignore pattern using glob brace expansion | |
| 409 | + val defaultIgnorePattern = DEFAULT_IGNORES.joinToString(",") { it } | |
| 410 | + | |
| 338 | 411 | var commandArgs = mutableListOf<String>( |
| 339 | 412 | ripgrep, |
| 340 | 413 | "--files", |
| @@ -343,7 +416,9 @@ | ||
| 343 | 416 | "--ignore-file", |
| 344 | 417 | ".continueignore", |
| 345 | 418 | "--ignore-file", |
| 346 | - ".gitignore" | |
| 419 | + ".gitignore", | |
| 420 | + "--glob", | |
| 421 | + "!{${defaultIgnorePattern}}" | |
| 347 | 422 | ) |
| 348 | 423 | if (maxResults != null) { |
| 349 | 424 | commandArgs.add("--max-count") |
| @@ -370,6 +445,9 @@ | ||
| 370 | 445 | val ideInfo = this.getIdeInfo() |
| 371 | 446 | if (ideInfo.remoteName == "local") { |
| 372 | 447 | try { |
| 448 | + // Create a single combined ignore pattern for ripgrep | |
| 449 | + val defaultIgnorePattern = DEFAULT_IGNORES.joinToString(",") { it } | |
| 450 | + | |
| 373 | 451 | val commandArgs = mutableListOf( |
| 374 | 452 | ripgrep, |
| 375 | 453 | "-i", |
| @@ -379,7 +457,9 @@ | ||
| 379 | 457 | ".gitignore", |
| 380 | 458 | "-C", |
| 381 | 459 | "2", |
| 382 | - "--heading" | |
| 460 | + "--heading", | |
| 461 | + "--glob", | |
| 462 | + "!{${defaultIgnorePattern}}" // Exclude all default ignores using brace expansion | |
| 383 | 463 | ) |
| 384 | 464 | |
| 385 | 465 | // Conditionally add maxResults flag |
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | "name": "continue", |
| 3 | 3 | "icon": "media/icon.png", |
| 4 | 4 | "author": "Continue Dev, Inc", |
| 5 | - "version": "1.3.9", | |
| 5 | + "version": "1.3.10", | |
| 6 | 6 | "repository": { |
| 7 | 7 | "type": "git", |
| 8 | 8 | "url": "https://github.com/continuedev/continue" |
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | |
| 4 | 4 | import { Range } from "core"; |
| 5 | 5 | import { EXTENSION_NAME } from "core/control-plane/env"; |
| 6 | +import { DEFAULT_IGNORES, defaultIgnoresGlob } from "core/indexing/ignore"; | |
| 6 | 7 | import * as URI from "uri-js"; |
| 7 | 8 | import * as vscode from "vscode"; |
| 8 | 9 | |
| @@ -452,7 +453,9 @@ | ||
| 452 | 453 | resolve(output); |
| 453 | 454 | } else if (code === 1) { |
| 454 | 455 | // No matches |
| 455 | - resolve("No matches found"); | |
| 456 | + resolve( | |
| 457 | + "No matches found. Build, secrets, etc. dirs and files are not included.", | |
| 458 | + ); | |
| 456 | 459 | } else { |
| 457 | 460 | reject(new Error(`Process exited with code ${code}`)); |
| 458 | 461 | } |
| @@ -464,6 +467,8 @@ | ||
| 464 | 467 | pattern: string, |
| 465 | 468 | maxResults?: number, |
| 466 | 469 | ): Promise<string[]> { |
| 470 | + // Create a single combined ignore pattern for ripgrep (calculated once) | |
| 471 | + | |
| 467 | 472 | if (vscode.env.remoteName) { |
| 468 | 473 | // TODO better tests for this remote search implementation |
| 469 | 474 | // throw new Error("Ripgrep not supported, this workspace is remote"); |
| @@ -475,6 +480,11 @@ | ||
| 475 | 480 | ); |
| 476 | 481 | |
| 477 | 482 | const ignoreGlobs: Set<string> = new Set(); |
| 483 | + // Add default ignores from core | |
| 484 | + for (const pattern of DEFAULT_IGNORES) { | |
| 485 | + ignoreGlobs.add(pattern); | |
| 486 | + } | |
| 487 | + | |
| 478 | 488 | for (const file of ignoreFiles) { |
| 479 | 489 | const content = await this.ideUtils.readFile(file); |
| 480 | 490 | if (content === null) { |
| @@ -535,6 +545,7 @@ | ||
| 535 | 545 | return results.map((result) => vscode.workspace.asRelativePath(result)); |
| 536 | 546 | } else { |
| 537 | 547 | const results: string[] = []; |
| 548 | + // Create a single combined ignore pattern using glob brace expansion | |
| 538 | 549 | for (const dir of await this.getWorkspaceDirs()) { |
| 539 | 550 | const dirResults = await this.runRipgrepQuery(dir, [ |
| 540 | 551 | "--files", |
| @@ -544,6 +555,8 @@ | ||
| 544 | 555 | ".continueignore", |
| 545 | 556 | "--ignore-file", |
| 546 | 557 | ".gitignore", |
| 558 | + "--glob", | |
| 559 | + defaultIgnoresGlob, | |
| 547 | 560 | ...(maxResults ? ["--max-count", String(maxResults)] : []), |
| 548 | 561 | ]); |
| 549 | 562 | |
| @@ -566,6 +579,7 @@ | ||
| 566 | 579 | throw new Error("Ripgrep not supported, this workspace is remote"); |
| 567 | 580 | } |
| 568 | 581 | const results: string[] = []; |
| 582 | + | |
| 569 | 583 | for (const dir of await this.getWorkspaceDirs()) { |
| 570 | 584 | const dirResults = await this.runRipgrepQuery(dir, [ |
| 571 | 585 | "-i", // Case-insensitive search |
| @@ -576,6 +590,9 @@ | ||
| 576 | 590 | "-C", |
| 577 | 591 | "2", // Show 2 lines of context |
| 578 | 592 | "--heading", // Only show filepath once per result |
| 593 | + // Use a single glob with all default ignores | |
| 594 | + "--glob", | |
| 595 | + defaultIgnoresGlob, | |
| 579 | 596 | ...(maxResults ? ["-m", maxResults.toString()] : []), |
| 580 | 597 | "-e", |
| 581 | 598 | query, // Pattern to search for |
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | import { walkDirAsync } from "core/indexing/walkDir"; |
| 10 | 10 | import { isModelInstaller } from "core/llm"; |
| 11 | 11 | import { startLocalOllama } from "core/util/ollamaHelper"; |
| 12 | +import { startLocalLemonade } from "core/util/lemonadeHelper"; | |
| 12 | 13 | import { getConfigJsonPath, getConfigYamlPath } from "core/util/paths"; |
| 13 | 14 | import { Telemetry } from "core/util/posthog"; |
| 14 | 15 | import * as vscode from "vscode"; |
| @@ -620,6 +621,9 @@ | ||
| 620 | 621 | "continue.startLocalOllama": () => { |
| 621 | 622 | startLocalOllama(ide); |
| 622 | 623 | }, |
| 624 | + "continue.startLocalLemonade": () => { | |
| 625 | + startLocalLemonade(ide); | |
| 626 | + }, | |
| 623 | 627 | "continue.installModel": async ( |
| 624 | 628 | modelName: string, |
| 625 | 629 | llmProvider: ILLM | undefined, |
| @@ -76,6 +76,39 @@ | ||
| 76 | 76 | this.disposables.push(disposable); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | + /** ensures the current target file is open and focused before performing edits*/ | |
| 80 | + private async ensureCurrentFileIsFocused() { | |
| 81 | + const targetUri = this.editor.document.uri; | |
| 82 | + const active = vscode.window.activeTextEditor; | |
| 83 | + if ( | |
| 84 | + active && | |
| 85 | + URI.equal(active.document.uri.toString(), targetUri.toString()) | |
| 86 | + ) { | |
| 87 | + this.editor = active; | |
| 88 | + return; | |
| 89 | + } | |
| 90 | + | |
| 91 | + const visible = vscode.window.visibleTextEditors.find((foundEditor) => | |
| 92 | + URI.equal(foundEditor.document.uri.toString(), targetUri.toString()), | |
| 93 | + ); | |
| 94 | + if (visible) { | |
| 95 | + await vscode.window.showTextDocument(visible.document, { | |
| 96 | + preview: false, | |
| 97 | + preserveFocus: false, | |
| 98 | + viewColumn: visible.viewColumn, | |
| 99 | + }); | |
| 100 | + this.editor = vscode.window.activeTextEditor ?? visible; | |
| 101 | + return; | |
| 102 | + } | |
| 103 | + | |
| 104 | + const doc = await vscode.workspace.openTextDocument(targetUri); | |
| 105 | + const editor = await vscode.window.showTextDocument(doc, { | |
| 106 | + preview: false, | |
| 107 | + preserveFocus: false, | |
| 108 | + }); | |
| 109 | + this.editor = editor; | |
| 110 | + } | |
| 111 | + | |
| 79 | 112 | public get range(): vscode.Range { |
| 80 | 113 | const startLine = Math.min(this.startLine, this.endLine); |
| 81 | 114 | const endLine = Math.max(this.startLine, this.endLine); |
| @@ -296,6 +329,8 @@ | ||
| 296 | 329 | // Diff is messed up without this delay. |
| 297 | 330 | await new Promise((resolve) => setTimeout(resolve, 100)); |
| 298 | 331 | |
| 332 | + await this.ensureCurrentFileIsFocused(); | |
| 333 | + | |
| 299 | 334 | // First, we reset the original diff by rejecting all pending diff blocks |
| 300 | 335 | const blocks = this.editorToVerticalDiffCodeLens.get(this.fileUri) ?? []; |
| 301 | 336 | for (const block of blocks.reverse()) { |
| @@ -443,6 +478,7 @@ | ||
| 443 | 478 | } |
| 444 | 479 | |
| 445 | 480 | private async insertTextAboveLine(index: number, text: string) { |
| 481 | + await this.ensureCurrentFileIsFocused(); | |
| 446 | 482 | await this.editor.edit( |
| 447 | 483 | (editBuilder) => { |
| 448 | 484 | const lineCount = this.editor.document.lineCount; |
| @@ -471,6 +507,7 @@ | ||
| 471 | 507 | |
| 472 | 508 | private async deleteLinesAt(index: number, numLines = 1) { |
| 473 | 509 | const startLine = new vscode.Position(index, 0); |
| 510 | + await this.ensureCurrentFileIsFocused(); | |
| 474 | 511 | await this.editor.edit( |
| 475 | 512 | (editBuilder) => { |
| 476 | 513 | editBuilder.delete( |
| @@ -482,6 +519,7 @@ | ||
| 482 | 519 | } |
| 483 | 520 | |
| 484 | 521 | private async deleteRangeLines(ranges: vscode.Range[]) { |
| 522 | + await this.ensureCurrentFileIsFocused(); | |
| 485 | 523 | await this.editor.edit( |
| 486 | 524 | (editBuilder) => { |
| 487 | 525 | for (const range of ranges) { |
| @@ -51,7 +51,7 @@ | ||
| 51 | 51 | this.fileUriToHandler.get(fileUri)?.clear(false); |
| 52 | 52 | this.fileUriToHandler.delete(fileUri); |
| 53 | 53 | } |
| 54 | - const editor = vscode.window.activeTextEditor; // TODO might cause issues if user switches files | |
| 54 | + const editor = vscode.window.activeTextEditor; | |
| 55 | 55 | if (editor && URI.equal(editor.document.uri.toString(), fileUri)) { |
| 56 | 56 | const handler = new VerticalDiffHandler( |
| 57 | 57 | startLine, |
| @@ -3,13 +3,41 @@ | ||
| 3 | 3 | import * as vscode from "vscode"; |
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | - * @param error Handles common LLM errors. Currently only handles Ollama-related errors. | |
| 6 | + * @param error Handles common LLM errors. Currently handles Ollama and Lemonade-related errors. | |
| 7 | 7 | * @returns true if error is handled, false otherwise |
| 8 | 8 | */ |
| 9 | 9 | export async function handleLLMError(error: unknown): Promise<boolean> { |
| 10 | 10 | if (!error || !(error instanceof Error) || !error.message) { |
| 11 | 11 | return false; |
| 12 | 12 | } |
| 13 | + | |
| 14 | + // Handle Lemonade errors | |
| 15 | + if (error.message.toLowerCase().includes("lemonade")) { | |
| 16 | + let message: string = error.message; | |
| 17 | + let options: string[] | undefined; | |
| 18 | + | |
| 19 | + // For Windows, offer to start Lemonade if it's installed but not running | |
| 20 | + if ( | |
| 21 | + process.platform === "win32" && | |
| 22 | + message.includes("Lemonade server may not be running") | |
| 23 | + ) { | |
| 24 | + options = ["Start Lemonade", "Setup Instructions"]; | |
| 25 | + } else { | |
| 26 | + // For all other cases (Linux, not installed, etc.), direct to setup instructions | |
| 27 | + options = ["Setup Instructions"]; | |
| 28 | + } | |
| 29 | + | |
| 30 | + vscode.window.showErrorMessage(message, ...options).then((val) => { | |
| 31 | + if (val === "Setup Instructions") { | |
| 32 | + vscode.env.openExternal(vscode.Uri.parse("https://lemonade-server.ai")); | |
| 33 | + } else if (val === "Start Lemonade") { | |
| 34 | + vscode.commands.executeCommand("continue.startLocalLemonade"); | |
| 35 | + } | |
| 36 | + }); | |
| 37 | + return true; | |
| 38 | + } | |
| 39 | + | |
| 40 | + // Handle Ollama errors | |
| 13 | 41 | if (!error.message.toLowerCase().includes("ollama")) { |
| 14 | 42 | return false; |
| 15 | 43 | } |
| @@ -107,7 +107,7 @@ | ||
| 107 | 107 | |
| 108 | 108 | if (e.cause) { |
| 109 | 109 | if (e.cause.name === "ConnectTimeoutError") { |
| 110 | - message = `Connection timed out. If you expect it to take a long time to connect, you can increase the timeout in config.json by setting "requestOptions": { "timeout": 10000 }. You can find the full config reference here: https://docs.continue.dev/reference/config`; | |
| 110 | + message = `Connection timed out. If you expect it to take a long time to connect, you can increase the timeout in your config by setting "requestOptions": { "timeout": 10000 }. You can find the full config reference here: https://docs.continue.dev/reference/config`; | |
| 111 | 111 | } else if (e.cause.code === "ECONNREFUSED") { |
| 112 | 112 | message = `Connection was refused. This likely means that there is no server running at the specified URL. If you are running your own server you may need to set the "apiBase" parameter in config.json. For example, you can set up an OpenAI-compatible server like here: https://docs.continue.dev/reference/Model%20Providers/openai#openai-compatible-servers--apis`; |
| 113 | 113 | } else { |
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
Binary content is not shown. View the file.
| @@ -1,4 +1,7 @@ | ||
| 1 | -import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; | |
| 1 | +import { | |
| 2 | + Cog6ToothIcon, | |
| 3 | + ExclamationTriangleIcon, | |
| 4 | +} from "@heroicons/react/24/outline"; | |
| 2 | 5 | import { ProfileDescription } from "core/config/ProfileLifecycleManager"; |
| 3 | 6 | import { useContext, useMemo } from "react"; |
| 4 | 7 | import { useNavigate } from "react-router-dom"; |
| @@ -48,7 +51,7 @@ | ||
| 48 | 51 | disabled={hasFatalErrors} |
| 49 | 52 | onClick={!hasFatalErrors ? handleOptionClick : undefined} |
| 50 | 53 | fontSizeModifier={-2} |
| 51 | - className={selected ? "bg-list-active text-list-active-foreground" : ""} | |
| 54 | + className={`group ${selected ? "bg-list-active text-list-active-foreground" : ""}`} | |
| 52 | 55 | > |
| 53 | 56 | <div className="flex w-full items-center justify-between gap-10 py-0.5"> |
| 54 | 57 | <div className="flex w-full items-center gap-3"> |
| @@ -62,6 +65,20 @@ | ||
| 62 | 65 | </span> |
| 63 | 66 | </div> |
| 64 | 67 | <div className="flex flex-row items-center gap-1.5"> |
| 68 | + <Button | |
| 69 | + variant="ghost" | |
| 70 | + size="sm" | |
| 71 | + className="text-description-muted hover:enabled:text-foreground my-0 h-4 w-4 p-0 opacity-0 transition-opacity group-hover:opacity-100" | |
| 72 | + onClick={(e) => { | |
| 73 | + e.stopPropagation(); | |
| 74 | + ideMessenger.post("config/openProfile", { | |
| 75 | + profileId: profile.id, | |
| 76 | + }); | |
| 77 | + onClick(); // Close the listbox | |
| 78 | + }} | |
| 79 | + > | |
| 80 | + <Cog6ToothIcon className="h-3.5 w-3.5" /> | |
| 81 | + </Button> | |
| 65 | 82 | {profile.errors && profile.errors?.length > 0 && ( |
| 66 | 83 | <ToolTip content="View errors"> |
| 67 | 84 | <Button |
| @@ -1,14 +1,16 @@ | ||
| 1 | -import { CheckIcon } from "@heroicons/react/24/outline"; | |
| 1 | +import { Cog6ToothIcon } from "@heroicons/react/24/outline"; | |
| 2 | 2 | import { |
| 3 | 3 | BuildingOfficeIcon, |
| 4 | 4 | UserCircleIcon, |
| 5 | 5 | UserIcon, |
| 6 | 6 | } from "@heroicons/react/24/solid"; |
| 7 | 7 | import { useContext } from "react"; |
| 8 | +import { useNavigate } from "react-router-dom"; | |
| 8 | 9 | import { IdeMessengerContext } from "../../context/IdeMessenger"; |
| 9 | 10 | import { useAppDispatch, useAppSelector } from "../../redux/hooks"; |
| 10 | 11 | import { setSelectedOrgId } from "../../redux/slices/profilesSlice"; |
| 11 | -import { ListboxOption } from "../ui"; | |
| 12 | +import { CONFIG_ROUTES } from "../../util/navigation"; | |
| 13 | +import { Button, ListboxOption } from "../ui"; | |
| 12 | 14 | |
| 13 | 15 | interface OrganizationOptionProps { |
| 14 | 16 | organization: { id: string; name: string; iconUrl?: string | null }; |
| @@ -45,6 +47,7 @@ | ||
| 45 | 47 | onClose, |
| 46 | 48 | }: OrganizationOptionProps) { |
| 47 | 49 | const dispatch = useAppDispatch(); |
| 50 | + const navigate = useNavigate(); | |
| 48 | 51 | const ideMessenger = useContext(IdeMessengerContext); |
| 49 | 52 | const selectedOrgId = useAppSelector( |
| 50 | 53 | (state) => state.profiles.selectedOrganizationId, |
| @@ -64,7 +67,7 @@ | ||
| 64 | 67 | value={organization.id} |
| 65 | 68 | onClick={handleOptionClick} |
| 66 | 69 | fontSizeModifier={-2} |
| 67 | - className={isSelected ? "bg-list-active text-list-active-foreground" : ""} | |
| 70 | + className={`group ${isSelected ? "bg-list-active text-list-active-foreground" : ""}`} | |
| 68 | 71 | > |
| 69 | 72 | <div className="flex w-full items-center justify-between gap-10 py-0.5"> |
| 70 | 73 | <div className="flex w-full items-center gap-3"> |
| @@ -78,7 +81,18 @@ | ||
| 78 | 81 | </span> |
| 79 | 82 | </div> |
| 80 | 83 | <div className="flex flex-row items-center gap-1.5"> |
| 81 | - {isSelected && <CheckIcon className="h-3.5 w-3.5 flex-shrink-0" />} | |
| 84 | + <Button | |
| 85 | + variant="ghost" | |
| 86 | + size="sm" | |
| 87 | + className="text-description-muted hover:enabled:text-foreground my-0 h-4 w-4 p-0 opacity-0 transition-opacity group-hover:opacity-100" | |
| 88 | + onClick={(e) => { | |
| 89 | + e.stopPropagation(); | |
| 90 | + navigate(CONFIG_ROUTES.ORGANIZATIONS); | |
| 91 | + onClose(); // Close the listbox | |
| 92 | + }} | |
| 93 | + > | |
| 94 | + <Cog6ToothIcon className="h-3.5 w-3.5" /> | |
| 95 | + </Button> | |
| 82 | 96 | </div> |
| 83 | 97 | </div> |
| 84 | 98 | </ListboxOption> |
| @@ -2,9 +2,7 @@ | ||
| 2 | 2 | ArrowPathIcon, |
| 3 | 3 | ArrowRightStartOnRectangleIcon, |
| 4 | 4 | Cog6ToothIcon, |
| 5 | - PencilIcon, | |
| 6 | 5 | PlusIcon, |
| 7 | - WrenchScrewdriverIcon, | |
| 8 | 6 | } from "@heroicons/react/24/outline"; |
| 9 | 7 | import { isOnPremSession } from "core/control-plane/AuthTypes"; |
| 10 | 8 | import { useContext, useEffect, useRef } from "react"; |
| @@ -155,7 +153,7 @@ | ||
| 155 | 153 | className="max-h-32 -translate-x-1.5 overflow-y-auto pb-0" |
| 156 | 154 | style={{ zIndex: 200 }} |
| 157 | 155 | > |
| 158 | - <div className="flex items-center justify-between p-2"> | |
| 156 | + <div className="flex items-center justify-between px-1.5 py-1"> | |
| 159 | 157 | <span className="text-description text-xs font-medium"> |
| 160 | 158 | Agents |
| 161 | 159 | </span> |
| @@ -193,7 +191,7 @@ | ||
| 193 | 191 | {shouldRenderOrgInfo && ( |
| 194 | 192 | <> |
| 195 | 193 | <Divider className="!mb-0.5 !mt-0" /> |
| 196 | - <div className="flex items-center justify-between p-2"> | |
| 194 | + <div className="flex items-center justify-between px-1.5 py-1"> | |
| 197 | 195 | <span className="text-description text-xs font-medium"> |
| 198 | 196 | Organizations |
| 199 | 197 | </span> |
| @@ -232,34 +230,6 @@ | ||
| 232 | 230 | {/* Settings Section */} |
| 233 | 231 | {variant !== "sidebar" && ( |
| 234 | 232 | <div> |
| 235 | - <Button | |
| 236 | - onClick={(e) => { | |
| 237 | - e.stopPropagation(); | |
| 238 | - onRulesConfig(); | |
| 239 | - }} | |
| 240 | - variant="ghost" | |
| 241 | - size="sm" | |
| 242 | - className="text-description hover:bg-input my-0 w-full justify-start py-1.5 pl-1 text-left" | |
| 243 | - > | |
| 244 | - <div className="flex w-full items-center"> | |
| 245 | - <PencilIcon className="ml-1.5 mr-2 h-3.5 w-3.5 flex-shrink-0" /> | |
| 246 | - <span className="text-2xs">Rules</span> | |
| 247 | - </div> | |
| 248 | - </Button> | |
| 249 | - <Button | |
| 250 | - onClick={(e) => { | |
| 251 | - e.stopPropagation(); | |
| 252 | - onToolsConfig(); | |
| 253 | - }} | |
| 254 | - variant="ghost" | |
| 255 | - size="sm" | |
| 256 | - className="text-description hover:bg-input my-0 w-full justify-start py-1.5 pl-1 text-left" | |
| 257 | - > | |
| 258 | - <div className="flex w-full items-center"> | |
| 259 | - <WrenchScrewdriverIcon className="ml-1.5 mr-2 h-3.5 w-3.5 flex-shrink-0" /> | |
| 260 | - <span className="text-2xs">Tools</span> | |
| 261 | - </div> | |
| 262 | - </Button> | |
| 263 | 233 | <Button |
| 264 | 234 | onClick={(e) => { |
| 265 | 235 | e.stopPropagation(); |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | import { Editor, JSONContent } from "@tiptap/react"; |
| 2 | 2 | import { ContextItemWithId, InputModifiers, RuleWithSource } from "core"; |
| 3 | -import { useMemo } from "react"; | |
| 3 | +import { memo, useMemo } from "react"; | |
| 4 | 4 | import { defaultBorderRadius, vscBackground } from ".."; |
| 5 | 5 | import { useAppSelector } from "../../redux/hooks"; |
| 6 | 6 | import { selectSlashCommandComboBoxInputs } from "../../redux/selectors"; |
| @@ -69,16 +69,20 @@ | ||
| 69 | 69 | const historyKey = isInEdit ? "edit" : "chat"; |
| 70 | 70 | const placeholder = isInEdit ? "Edit selected code" : undefined; |
| 71 | 71 | |
| 72 | - const toolbarOptions: ToolbarOptions = isInEdit | |
| 73 | - ? { | |
| 72 | + const toolbarOptions: ToolbarOptions = useMemo(() => { | |
| 73 | + if (isInEdit) { | |
| 74 | + return { | |
| 74 | 75 | hideAddContext: false, |
| 75 | 76 | hideImageUpload: false, |
| 76 | 77 | hideUseCodebase: true, |
| 77 | 78 | hideSelectModel: false, |
| 78 | 79 | enterText: |
| 79 | 80 | editModeState.applyState.status === "done" ? "Retry" : "Edit", |
| 80 | - } | |
| 81 | - : {}; | |
| 81 | + } as ToolbarOptions; | |
| 82 | + } | |
| 83 | + // Stable empty object to avoid re-renders from identity changes | |
| 84 | + return {} as ToolbarOptions; | |
| 85 | + }, [isInEdit, editModeState.applyState.status]); | |
| 82 | 86 | |
| 83 | 87 | const { appliedRules = [], contextItems = [] } = props; |
| 84 | 88 | |
| @@ -123,4 +127,4 @@ | ||
| 123 | 127 | ); |
| 124 | 128 | } |
| 125 | 129 | |
| 126 | -export default ContinueInputBox; | |
| 130 | +export default memo(ContinueInputBox); |
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | modelSupportsImages, |
| 10 | 10 | modelSupportsReasoning, |
| 11 | 11 | } from "core/llm/autodetect"; |
| 12 | -import { useContext, useRef } from "react"; | |
| 12 | +import { memo, useContext, useRef } from "react"; | |
| 13 | 13 | import { IdeMessengerContext } from "../../context/IdeMessenger"; |
| 14 | 14 | import { useAppDispatch, useAppSelector } from "../../redux/hooks"; |
| 15 | 15 | import { selectUseActiveFile } from "../../redux/selectors"; |
| @@ -242,4 +242,24 @@ | ||
| 242 | 242 | ); |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | -export default InputToolbar; | |
| 245 | +function shallowToolbarOptionsEqual(a?: ToolbarOptions, b?: ToolbarOptions) { | |
| 246 | + if (a === b) return true; | |
| 247 | + if (!a || !b) return false; | |
| 248 | + return ( | |
| 249 | + a.hideAddContext === b.hideAddContext && | |
| 250 | + a.hideImageUpload === b.hideImageUpload && | |
| 251 | + a.hideUseCodebase === b.hideUseCodebase && | |
| 252 | + a.hideSelectModel === b.hideSelectModel && | |
| 253 | + a.enterText === b.enterText | |
| 254 | + ); | |
| 255 | +} | |
| 256 | + | |
| 257 | +export default memo( | |
| 258 | + InputToolbar, | |
| 259 | + (prev, next) => | |
| 260 | + prev.hidden === next.hidden && | |
| 261 | + prev.disabled === next.disabled && | |
| 262 | + prev.isMainInput === next.isMainInput && | |
| 263 | + prev.activeKey === next.activeKey && | |
| 264 | + shallowToolbarOptionsEqual(prev.toolbarOptions, next.toolbarOptions), | |
| 265 | +); |
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | |
| 7 | 7 | type SectionKey = Exclude< |
| 8 | 8 | keyof ConfigYaml, |
| 9 | - "name" | "version" | "schema" | "metadata" | "env" | |
| 9 | + "name" | "version" | "schema" | "metadata" | "env" | "requestOptions" | |
| 10 | 10 | >; |
| 11 | 11 | |
| 12 | 12 | interface EditBlockButtonProps<T extends SectionKey> { |
| @@ -1,24 +1,45 @@ | ||
| 1 | -import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; | |
| 1 | +import { | |
| 2 | + CubeIcon, | |
| 3 | + ExclamationTriangleIcon, | |
| 4 | + PencilIcon, | |
| 5 | + WrenchScrewdriverIcon, | |
| 6 | +} from "@heroicons/react/24/outline"; | |
| 2 | 7 | import { useContext, useEffect, useState } from "react"; |
| 3 | 8 | import { useNavigate } from "react-router-dom"; |
| 4 | 9 | import { IdeMessengerContext } from "../../../../context/IdeMessenger"; |
| 5 | -import { useAppSelector } from "../../../../redux/hooks"; | |
| 10 | +import { useAppDispatch, useAppSelector } from "../../../../redux/hooks"; | |
| 11 | +import { | |
| 12 | + selectPendingToolCalls, | |
| 13 | + selectToolCallsByStatus, | |
| 14 | +} from "../../../../redux/selectors/selectToolCalls"; | |
| 15 | +import { setSelectedProfile } from "../../../../redux/slices/profilesSlice"; | |
| 6 | 16 | import FreeTrialButton from "../../../FreeTrialButton"; |
| 7 | 17 | import { ToolTip } from "../../../gui/Tooltip"; |
| 18 | +import HoverItem from "../../InputToolbar/HoverItem"; | |
| 8 | 19 | |
| 9 | 20 | import { usesFreeTrialApiKey } from "core/config/usesFreeTrialApiKey"; |
| 10 | 21 | import type { FreeTrialStatus } from "core/control-plane/client"; |
| 22 | +import { useAuth } from "../../../../context/Auth"; | |
| 11 | 23 | import { getLocalStorage } from "../../../../util/localStorage"; |
| 12 | 24 | import { CONFIG_ROUTES } from "../../../../util/navigation"; |
| 13 | 25 | import { AssistantAndOrgListbox } from "../../../AssistantAndOrgListbox"; |
| 14 | 26 | |
| 15 | 27 | export function BlockSettingsTopToolbar() { |
| 16 | 28 | const navigate = useNavigate(); |
| 29 | + const dispatch = useAppDispatch(); | |
| 30 | + const { selectedProfile } = useAuth(); | |
| 17 | 31 | |
| 18 | 32 | const configError = useAppSelector((store) => store.config.configError); |
| 19 | 33 | const config = useAppSelector((state) => state.config.config); |
| 20 | 34 | const ideMessenger = useContext(IdeMessengerContext); |
| 21 | 35 | |
| 36 | + const pendingToolCalls = useAppSelector(selectPendingToolCalls); | |
| 37 | + const callingToolCalls = useAppSelector((state) => | |
| 38 | + selectToolCallsByStatus(state, "calling"), | |
| 39 | + ); | |
| 40 | + const hasActiveContent = | |
| 41 | + pendingToolCalls.length > 0 || callingToolCalls.length > 0; | |
| 42 | + | |
| 22 | 43 | const [freeTrialStatus, setFreeTrialStatus] = |
| 23 | 44 | useState<FreeTrialStatus | null>(null); |
| 24 | 45 | const hasExitedFreeTrial = getLocalStorage("hasExitedFreeTrial"); |
| @@ -53,9 +74,39 @@ | ||
| 53 | 74 | |
| 54 | 75 | const shouldShowError = configError && configError?.length > 0; |
| 55 | 76 | |
| 77 | + const handleRulesClick = () => { | |
| 78 | + if (selectedProfile) { | |
| 79 | + dispatch(setSelectedProfile(selectedProfile.id)); | |
| 80 | + ideMessenger.post("didChangeSelectedProfile", { | |
| 81 | + id: selectedProfile.id, | |
| 82 | + }); | |
| 83 | + } | |
| 84 | + navigate(CONFIG_ROUTES.RULES); | |
| 85 | + }; | |
| 86 | + | |
| 87 | + const handleToolsClick = () => { | |
| 88 | + if (selectedProfile) { | |
| 89 | + dispatch(setSelectedProfile(selectedProfile.id)); | |
| 90 | + ideMessenger.post("didChangeSelectedProfile", { | |
| 91 | + id: selectedProfile.id, | |
| 92 | + }); | |
| 93 | + } | |
| 94 | + navigate(CONFIG_ROUTES.TOOLS); | |
| 95 | + }; | |
| 96 | + | |
| 97 | + const handleModelsClick = () => { | |
| 98 | + if (selectedProfile) { | |
| 99 | + dispatch(setSelectedProfile(selectedProfile.id)); | |
| 100 | + ideMessenger.post("didChangeSelectedProfile", { | |
| 101 | + id: selectedProfile.id, | |
| 102 | + }); | |
| 103 | + } | |
| 104 | + navigate(CONFIG_ROUTES.MODELS); | |
| 105 | + }; | |
| 106 | + | |
| 56 | 107 | return ( |
| 57 | 108 | <div className="flex flex-1 items-center justify-between gap-1.5"> |
| 58 | - <div> | |
| 109 | + <div className="flex items-center gap-1"> | |
| 59 | 110 | {shouldShowError && ( |
| 60 | 111 | <ToolTip delayShow={700} content="View configuration errors"> |
| 61 | 112 | <div |
| @@ -78,7 +129,30 @@ | ||
| 78 | 129 | </div> |
| 79 | 130 | </ToolTip> |
| 80 | 131 | )} |
| 132 | + | |
| 133 | + {!hasActiveContent && ( | |
| 134 | + <div className="flex items-center gap-1.5"> | |
| 135 | + <ToolTip content="Configure rules"> | |
| 136 | + <HoverItem onClick={handleRulesClick} px={2}> | |
| 137 | + <PencilIcon className="text-description-muted h-3 w-3 hover:brightness-125" /> | |
| 138 | + </HoverItem> | |
| 139 | + </ToolTip> | |
| 140 | + | |
| 141 | + <ToolTip content="Configure tools"> | |
| 142 | + <HoverItem onClick={handleToolsClick} px={2}> | |
| 143 | + <WrenchScrewdriverIcon className="text-description-muted h-3 w-3 hover:brightness-125" /> | |
| 144 | + </HoverItem> | |
| 145 | + </ToolTip> | |
| 146 | + | |
| 147 | + <ToolTip content="Configure models"> | |
| 148 | + <HoverItem onClick={handleModelsClick} px={2}> | |
| 149 | + <CubeIcon className="text-description-muted h-3 w-3 hover:brightness-125" /> | |
| 150 | + </HoverItem> | |
| 151 | + </ToolTip> | |
| 152 | + </div> | |
| 153 | + )} | |
| 81 | 154 | </div> |
| 155 | + | |
| 82 | 156 | <ToolTip |
| 83 | 157 | place="top" |
| 84 | 158 | content={isUsingFreeTrial ? "View free trial usage" : "Select Agent"} |
| @@ -1,7 +1,14 @@ | ||
| 1 | 1 | import { Editor, EditorContent, JSONContent } from "@tiptap/react"; |
| 2 | 2 | import { ContextProviderDescription, InputModifiers } from "core"; |
| 3 | 3 | import { modelSupportsImages } from "core/llm/autodetect"; |
| 4 | -import { useCallback, useContext, useEffect, useRef, useState } from "react"; | |
| 4 | +import { | |
| 5 | + memo, | |
| 6 | + useCallback, | |
| 7 | + useContext, | |
| 8 | + useEffect, | |
| 9 | + useRef, | |
| 10 | + useState, | |
| 11 | +} from "react"; | |
| 5 | 12 | import { IdeMessengerContext } from "../../../context/IdeMessenger"; |
| 6 | 13 | import useIsOSREnabled from "../../../hooks/useIsOSREnabled"; |
| 7 | 14 | import useUpdatingRef from "../../../hooks/useUpdatingRef"; |
| @@ -38,7 +45,7 @@ | ||
| 38 | 45 | |
| 39 | 46 | export const TIPPY_DIV_ID = "tippy-js-div"; |
| 40 | 47 | |
| 41 | -export function TipTapEditor(props: TipTapEditorProps) { | |
| 48 | +function TipTapEditorInner(props: TipTapEditorProps) { | |
| 42 | 49 | const dispatch = useAppDispatch(); |
| 43 | 50 | const mainEditorContext = useMainEditor(); |
| 44 | 51 | |
| @@ -72,12 +79,13 @@ | ||
| 72 | 79 | return; |
| 73 | 80 | } |
| 74 | 81 | const placeholder = getPlaceholderText(props.placeholder, historyLength); |
| 75 | - | |
| 76 | - editor.extensionManager.extensions.filter( | |
| 77 | - (extension) => extension.name === "placeholder", | |
| 78 | - )[0].options["placeholder"] = placeholder; | |
| 79 | - | |
| 80 | - editor.view.dispatch(editor.state.tr); | |
| 82 | + const placeholderExt = editor.extensionManager.extensions.find( | |
| 83 | + (e) => e.name === "placeholder", | |
| 84 | + ) as any; | |
| 85 | + if (placeholderExt) { | |
| 86 | + placeholderExt.options["placeholder"] = placeholder; | |
| 87 | + editor.view.dispatch(editor.state.tr); | |
| 88 | + } | |
| 81 | 89 | }, [editor, props.placeholder, historyLength]); |
| 82 | 90 | |
| 83 | 91 | useEffect(() => { |
| @@ -112,6 +120,23 @@ | ||
| 112 | 120 | } |
| 113 | 121 | }, [props.isMainInput, isStreaming, editor]); |
| 114 | 122 | |
| 123 | + // Recovery mechanism: ensure historical inputs regain editability when streaming ends | |
| 124 | + useEffect(() => { | |
| 125 | + if (!isStreaming && !props.isMainInput && editor) { | |
| 126 | + // Small delay to ensure editor state has settled after streaming transition | |
| 127 | + const timeoutId = setTimeout(() => { | |
| 128 | + if (editor && !editor.isDestroyed) { | |
| 129 | + // Force re-enable the editor | |
| 130 | + editor.setOptions({ editable: true }); | |
| 131 | + // Trigger view update to refresh editor state | |
| 132 | + editor.view.dispatch(editor.state.tr); | |
| 133 | + } | |
| 134 | + }, 100); | |
| 135 | + | |
| 136 | + return () => clearTimeout(timeoutId); | |
| 137 | + } | |
| 138 | + }, [isStreaming, props.isMainInput]); | |
| 139 | + | |
| 115 | 140 | const [showDragOverMsg, setShowDragOverMsg] = useState(false); |
| 116 | 141 | |
| 117 | 142 | const [activeKey, setActiveKey] = useState<string | null>(null); |
| @@ -281,3 +306,37 @@ | ||
| 281 | 306 | </InputBoxDiv> |
| 282 | 307 | ); |
| 283 | 308 | } |
| 309 | + | |
| 310 | +function toolbarOptionsEqual(a?: ToolbarOptions, b?: ToolbarOptions) { | |
| 311 | + if (a === b) return true; | |
| 312 | + if (!a || !b) return false; | |
| 313 | + return ( | |
| 314 | + a.hideAddContext === b.hideAddContext && | |
| 315 | + a.hideImageUpload === b.hideImageUpload && | |
| 316 | + a.hideUseCodebase === b.hideUseCodebase && | |
| 317 | + a.hideSelectModel === b.hideSelectModel && | |
| 318 | + a.enterText === b.enterText | |
| 319 | + ); | |
| 320 | +} | |
| 321 | + | |
| 322 | +const MemoInner = memo( | |
| 323 | + TipTapEditorInner, | |
| 324 | + (prev, next) => | |
| 325 | + prev.isMainInput === next.isMainInput && | |
| 326 | + prev.placeholder === next.placeholder && | |
| 327 | + prev.historyKey === next.historyKey && | |
| 328 | + prev.inputId === next.inputId && | |
| 329 | + toolbarOptionsEqual(prev.toolbarOptions, next.toolbarOptions) && | |
| 330 | + (prev.availableContextProviders?.length || 0) === | |
| 331 | + (next.availableContextProviders?.length || 0) && | |
| 332 | + (prev.availableSlashCommands?.length || 0) === | |
| 333 | + (next.availableSlashCommands?.length || 0), | |
| 334 | +); | |
| 335 | + | |
| 336 | +export function TipTapEditor(props: TipTapEditorProps) { | |
| 337 | + return ( | |
| 338 | + <div className="relative w-full"> | |
| 339 | + <MemoInner {...props} /> | |
| 340 | + </div> | |
| 341 | + ); | |
| 342 | +} |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | import { Editor } from "@tiptap/react"; |
| 2 | -import { KeyboardEvent } from "react"; | |
| 2 | +import { KeyboardEvent, useRef } from "react"; | |
| 3 | 3 | import { isJetBrains, isMetaEquivalentKeyPressed } from "../../../../util"; |
| 4 | 4 | import { |
| 5 | 5 | handleJetBrainsOSRMetaKeyIssues, |
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | setActiveKey: (key: string | null) => void; |
| 14 | 14 | }) { |
| 15 | 15 | const { editor, isOSREnabled, editorFocusedRef, setActiveKey } = options; |
| 16 | + const metaActiveRef = useRef(false); | |
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * This handles various issues with meta key actions |
| @@ -31,10 +32,14 @@ | ||
| 31 | 32 | return; |
| 32 | 33 | } |
| 33 | 34 | |
| 34 | - setActiveKey(e.key); | |
| 35 | - | |
| 36 | 35 | if (!editorFocusedRef?.current || !isMetaEquivalentKeyPressed(e)) return; |
| 37 | 36 | |
| 37 | + // Only set activeKey for Meta/Control/Alt to drive toolbar highlighting | |
| 38 | + if (e.key === "Meta" || e.key === "Control" || e.key === "Alt") { | |
| 39 | + setActiveKey(e.key); | |
| 40 | + metaActiveRef.current = true; | |
| 41 | + } | |
| 42 | + | |
| 38 | 43 | if (isOSREnabled) { |
| 39 | 44 | handleJetBrainsOSRMetaKeyIssues(e, editor); |
| 40 | 45 | } else if (!isJetBrains()) { |
| @@ -42,7 +47,12 @@ | ||
| 42 | 47 | } |
| 43 | 48 | }; |
| 44 | 49 | |
| 45 | - const handleKeyUp = () => setActiveKey(null); | |
| 50 | + const handleKeyUp = () => { | |
| 51 | + if (metaActiveRef.current) { | |
| 52 | + setActiveKey(null); | |
| 53 | + metaActiveRef.current = false; | |
| 54 | + } | |
| 55 | + }; | |
| 46 | 56 | |
| 47 | 57 | return { handleKeyDown, handleKeyUp }; |
| 48 | 58 | } |
| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | import { |
| 2 | 2 | ArrowPathIcon, |
| 3 | - CheckIcon, | |
| 4 | 3 | ChevronDownIcon, |
| 5 | 4 | Cog6ToothIcon, |
| 6 | 5 | CubeIcon, |
| @@ -16,7 +15,9 @@ | ||
| 16 | 15 | import { updateSelectedModelByRole } from "../../redux/thunks/updateSelectedModelByRole"; |
| 17 | 16 | import { getMetaKeyLabel, isMetaEquivalentKeyPressed } from "../../util"; |
| 18 | 17 | import { CONFIG_ROUTES } from "../../util/navigation"; |
| 18 | +import { ToolTip } from "../gui/Tooltip"; | |
| 19 | 19 | import { |
| 20 | + Button, | |
| 20 | 21 | Listbox, |
| 21 | 22 | ListboxButton, |
| 22 | 23 | ListboxOption, |
| @@ -57,6 +58,8 @@ | ||
| 57 | 58 | showMissingApiKeyMsg, |
| 58 | 59 | isSelected, |
| 59 | 60 | }: ModelOptionProps) { |
| 61 | + const navigate = useNavigate(); | |
| 62 | + | |
| 60 | 63 | function handleOptionClick(e: any) { |
| 61 | 64 | if (showMissingApiKeyMsg) { |
| 62 | 65 | e.preventDefault(); |
| @@ -64,12 +67,18 @@ | ||
| 64 | 67 | } |
| 65 | 68 | } |
| 66 | 69 | |
| 70 | + function handleConfigureClick(e: React.MouseEvent) { | |
| 71 | + e.stopPropagation(); | |
| 72 | + navigate(CONFIG_ROUTES.MODELS); | |
| 73 | + } | |
| 74 | + | |
| 67 | 75 | return ( |
| 68 | 76 | <ListboxOption |
| 69 | 77 | key={idx} |
| 70 | 78 | disabled={showMissingApiKeyMsg} |
| 71 | 79 | value={option.value} |
| 72 | 80 | onClick={handleOptionClick} |
| 81 | + className={`group ${isSelected ? "bg-list-active text-list-active-foreground" : ""}`} | |
| 73 | 82 | > |
| 74 | 83 | <div className="flex w-full items-center justify-between gap-5"> |
| 75 | 84 | <div className="flex items-center gap-2 py-0.5"> |
| @@ -88,9 +97,14 @@ | ||
| 88 | 97 | )} |
| 89 | 98 | </span> |
| 90 | 99 | </div> |
| 91 | - <CheckIcon | |
| 92 | - className={`h-3 w-3 flex-shrink-0 ${isSelected ? "" : "invisible"}`} | |
| 93 | - /> | |
| 100 | + <Button | |
| 101 | + variant="ghost" | |
| 102 | + size="sm" | |
| 103 | + className="text-description-muted hover:enabled:text-foreground my-0 h-4 w-4 p-0 opacity-0 transition-opacity group-hover:opacity-100" | |
| 104 | + onClick={handleConfigureClick} | |
| 105 | + > | |
| 106 | + <Cog6ToothIcon className="h-3.5 w-3.5" /> | |
| 107 | + </Button> | |
| 94 | 108 | </div> |
| 95 | 109 | </ListboxOption> |
| 96 | 110 | ); |
| @@ -245,8 +259,21 @@ | ||
| 245 | 259 | /> |
| 246 | 260 | </ListboxButton> |
| 247 | 261 | <ListboxOptions className="min-w-[160px]"> |
| 248 | - <div className="flex items-center justify-between gap-1 px-2 py-1"> | |
| 249 | - <span className="text-description font-semibold">Models</span> | |
| 262 | + <div className="flex items-center justify-between px-1.5 py-1"> | |
| 263 | + <span className="text-description text-xs font-medium">Models</span> | |
| 264 | + <div className="flex items-center gap-0.5"> | |
| 265 | + <Button | |
| 266 | + onClick={(e) => { | |
| 267 | + e.stopPropagation(); | |
| 268 | + onClickConfigureModels(e); | |
| 269 | + }} | |
| 270 | + variant="ghost" | |
| 271 | + size="sm" | |
| 272 | + className="my-0 h-5 w-5 p-0" | |
| 273 | + > | |
| 274 | + <Cog6ToothIcon className="text-description h-3.5 w-3.5" /> | |
| 275 | + </Button> | |
| 276 | + </div> | |
| 250 | 277 | </div> |
| 251 | 278 | |
| 252 | 279 | <div className="no-scrollbar max-h-[300px] overflow-y-auto"> |
| @@ -274,36 +301,26 @@ | ||
| 274 | 301 | |
| 275 | 302 | {!isConfigLoading && ( |
| 276 | 303 | <> |
| 277 | - <Divider className="!mb-0" /> | |
| 278 | - | |
| 279 | 304 | {selectedProfile?.profileType === "local" && ( |
| 280 | - <ListboxOption | |
| 281 | - key={options.length} | |
| 282 | - onClick={onClickAddModel} | |
| 283 | - value={"addModel" as any} | |
| 284 | - fontSizeModifier={-2} | |
| 285 | - className="px-2 py-2" | |
| 286 | - > | |
| 287 | - <span className="text-description text-2xs flex flex-row items-center"> | |
| 288 | - <PlusIcon className="mr-1.5 h-3.5 w-3.5" /> | |
| 289 | - Add Chat model | |
| 290 | - </span> | |
| 291 | - </ListboxOption> | |
| 305 | + <> | |
| 306 | + <Divider className="!mb-0" /> | |
| 307 | + <ListboxOption | |
| 308 | + key={options.length} | |
| 309 | + onClick={onClickAddModel} | |
| 310 | + value={"addModel" as any} | |
| 311 | + fontSizeModifier={-2} | |
| 312 | + className="px-2 py-2" | |
| 313 | + > | |
| 314 | + <span className="text-description text-2xs flex flex-row items-center"> | |
| 315 | + <PlusIcon className="mr-1.5 h-3.5 w-3.5" /> | |
| 316 | + Add Chat model | |
| 317 | + </span> | |
| 318 | + </ListboxOption> | |
| 319 | + </> | |
| 292 | 320 | )} |
| 293 | 321 | |
| 294 | - <ListboxOption | |
| 295 | - value="configure-models" | |
| 296 | - fontSizeModifier={-2} | |
| 297 | - className="px-2 py-2" | |
| 298 | - onClick={onClickConfigureModels} | |
| 299 | - > | |
| 300 | - <span className="text-description text-2xs flex flex-row items-center"> | |
| 301 | - <Cog6ToothIcon className="mr-1.5 h-3.5 w-3.5" /> | |
| 302 | - Configure models | |
| 303 | - </span> | |
| 304 | - </ListboxOption> | |
| 305 | 322 | <Divider className="!my-0" /> |
| 306 | - <div className="text-description flex items-center justify-between gap-1.5 px-2 py-2"> | |
| 323 | + <div className="text-description flex items-center justify-start p-2"> | |
| 307 | 324 | <span className="block" style={{ fontSize: tinyFont }}> |
| 308 | 325 | <code>{getMetaKeyLabel()}'</code> to toggle model |
| 309 | 326 | </span> |
| @@ -1,57 +0,0 @@ | ||
| 1 | -import styled from "styled-components"; | |
| 2 | -import { | |
| 3 | - defaultBorderRadius, | |
| 4 | - lightGray, | |
| 5 | - vscInputBackground, | |
| 6 | - vscListActiveBackground, | |
| 7 | - vscListActiveForeground, | |
| 8 | -} from ".."; | |
| 9 | - | |
| 10 | -const TopDiv = styled.div` | |
| 11 | - display: flex; | |
| 12 | - align-items: center; | |
| 13 | - text-align: center; | |
| 14 | - margin: auto; | |
| 15 | - width: fit-content; | |
| 16 | - cursor: pointer; | |
| 17 | - | |
| 18 | - border: 1px solid ${lightGray}; | |
| 19 | - | |
| 20 | - background-color: ${vscInputBackground}; | |
| 21 | - border-radius: ${defaultBorderRadius}; | |
| 22 | - | |
| 23 | - &:hover { | |
| 24 | - background-color: ${lightGray}55; | |
| 25 | - } | |
| 26 | -`; | |
| 27 | - | |
| 28 | -const SubDiv = styled.div<{ selected: boolean }>` | |
| 29 | - text-align: center; | |
| 30 | - padding: 8px 12px; | |
| 31 | - border-radius: ${defaultBorderRadius}; | |
| 32 | - | |
| 33 | - transition: all 0.2s ease-in-out; | |
| 34 | - | |
| 35 | - ${(props) => | |
| 36 | - props.selected && | |
| 37 | - ` | |
| 38 | - background-color: ${vscListActiveBackground}; | |
| 39 | - color: ${vscListActiveForeground}; | |
| 40 | - `} | |
| 41 | -`; | |
| 42 | - | |
| 43 | -function Toggle(props: { | |
| 44 | - optionOne: string; | |
| 45 | - optionTwo: string; | |
| 46 | - selected: boolean; | |
| 47 | - onClick: () => void; | |
| 48 | -}) { | |
| 49 | - return ( | |
| 50 | - <TopDiv onClick={props.onClick}> | |
| 51 | - <SubDiv selected={props.selected}>{props.optionOne}</SubDiv> | |
| 52 | - <SubDiv selected={!props.selected}>{props.optionTwo}</SubDiv> | |
| 53 | - </TopDiv> | |
| 54 | - ); | |
| 55 | -} | |
| 56 | - | |
| 57 | -export default Toggle; |
| @@ -0,0 +1,70 @@ | ||
| 1 | +import { CSSProperties, useEffect, useRef } from "react"; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * useRenderDebug | |
| 5 | + * | |
| 6 | + * Developer utility to visualize component re-renders. | |
| 7 | + * | |
| 8 | + * - Returns a `ref` to attach to a container element and a `count` that | |
| 9 | + * increments on every render of the component using this hook. | |
| 10 | + * - On each render, it briefly adds a CSS class (default: `rerender-flash`) | |
| 11 | + * to the element for a quick visual flash. | |
| 12 | + * - Use together with <RenderCountBadge /> to show the render count inline. | |
| 13 | + * | |
| 14 | + * Options: | |
| 15 | + * - enabled: boolean to toggle the effect (default true) | |
| 16 | + * - flashClassName: class added on each render (default `rerender-flash`) | |
| 17 | + * - flashDurationMs: duration of the flash animation in ms (default 180) | |
| 18 | + */ | |
| 19 | + | |
| 20 | +export function useRenderDebug(options?: { | |
| 21 | + enabled?: boolean; | |
| 22 | + flashClassName?: string; | |
| 23 | + flashDurationMs?: number; | |
| 24 | +}) { | |
| 25 | + const { | |
| 26 | + enabled = true, | |
| 27 | + flashClassName = "rerender-flash", | |
| 28 | + flashDurationMs = 180, | |
| 29 | + } = options || {}; | |
| 30 | + | |
| 31 | + const ref = useRef<HTMLElement | null>(null); | |
| 32 | + const countRef = useRef(0); | |
| 33 | + countRef.current += 1; | |
| 34 | + | |
| 35 | + useEffect(() => { | |
| 36 | + if (!enabled || !ref.current) return; | |
| 37 | + const el = ref.current; | |
| 38 | + el.classList.add(flashClassName); | |
| 39 | + const t = setTimeout( | |
| 40 | + () => el.classList.remove(flashClassName), | |
| 41 | + flashDurationMs, | |
| 42 | + ); | |
| 43 | + return () => { | |
| 44 | + clearTimeout(t); | |
| 45 | + // Ensure we don't leave the flash class applied on cleanup | |
| 46 | + el.classList.remove(flashClassName); | |
| 47 | + }; | |
| 48 | + }); | |
| 49 | + | |
| 50 | + return { ref, count: countRef.current, countRef } as const; | |
| 51 | +} | |
| 52 | + | |
| 53 | +export function RenderCountBadge(props: { | |
| 54 | + count: number; | |
| 55 | + title?: string; | |
| 56 | + style?: CSSProperties; | |
| 57 | + className?: string; | |
| 58 | +}) { | |
| 59 | + // Simple badge for use with useRenderDebug; keep lightweight. | |
| 60 | + const { count, title = `Renders: ${count}`, style, className } = props; | |
| 61 | + return ( | |
| 62 | + <span | |
| 63 | + className={`render-count ${className || ""}`} | |
| 64 | + title={title} | |
| 65 | + style={style} | |
| 66 | + > | |
| 67 | + R{count} | |
| 68 | + </span> | |
| 69 | + ); | |
| 70 | +} |
| @@ -119,3 +119,28 @@ | ||
| 119 | 119 | .scroll-container:is(:hover, :focus)::-webkit-scrollbar { |
| 120 | 120 | display: block; /* Show scrollbar only on hover or focus */ |
| 121 | 121 | } |
| 122 | + | |
| 123 | +/* Debug: visible flash when component re-renders */ | |
| 124 | +@keyframes rerenderFlash { | |
| 125 | + 0% { | |
| 126 | + box-shadow: 0 0 0 2px rgba(255, 0, 0, 0.9) inset; | |
| 127 | + } | |
| 128 | + 100% { | |
| 129 | + box-shadow: 0 0 0 0 rgba(255, 0, 0, 0) inset; | |
| 130 | + } | |
| 131 | +} | |
| 132 | + | |
| 133 | +.rerender-flash { | |
| 134 | + animation: rerenderFlash 180ms ease-out; | |
| 135 | +} | |
| 136 | + | |
| 137 | +.render-count { | |
| 138 | + display: inline-block; | |
| 139 | + margin-right: 6px; | |
| 140 | + padding: 0 4px; | |
| 141 | + border-radius: 3px; | |
| 142 | + background: rgba(255, 0, 0, 0.15); | |
| 143 | + color: rgba(255, 0, 0, 0.9); | |
| 144 | + font-weight: 600; | |
| 145 | + letter-spacing: 0.02em; | |
| 146 | +} |
| @@ -566,6 +566,38 @@ | ||
| 566 | 566 | packages: [models.grokBeta], |
| 567 | 567 | apiKeyUrl: "https://console.x.ai/", |
| 568 | 568 | }, |
| 569 | + lemonade: { | |
| 570 | + title: "Lemonade", | |
| 571 | + provider: "lemonade", | |
| 572 | + description: | |
| 573 | + "High-performance local LLM inference with AMD hardware optimization", | |
| 574 | + longDescription: | |
| 575 | + "Lemonade provides optimized local LLM inference with support for AMD NPU, GPU, and CPU acceleration. Visit [lemonade-server.ai](https://lemonade-server.ai/) for installation and setup instructions. Once the Lemonade server is running, you can begin using Continue with your local models.", | |
| 576 | + icon: "lemonade.png", | |
| 577 | + tags: [ModelProviderTags.Local, ModelProviderTags.OpenSource], | |
| 578 | + params: { | |
| 579 | + apiBase: "http://localhost:8000/api/v1/", | |
| 580 | + }, | |
| 581 | + packages: [ | |
| 582 | + { | |
| 583 | + ...models.AUTODETECT, | |
| 584 | + params: { | |
| 585 | + ...models.AUTODETECT.params, | |
| 586 | + title: "Lemonade", | |
| 587 | + }, | |
| 588 | + }, | |
| 589 | + ...openSourceModels, | |
| 590 | + ], | |
| 591 | + collectInputFor: [ | |
| 592 | + ...completionParamsInputsConfigs, | |
| 593 | + { | |
| 594 | + ...apiBaseInput, | |
| 595 | + defaultValue: "http://localhost:8000/api/v1/", | |
| 596 | + required: true, | |
| 597 | + }, | |
| 598 | + ], | |
| 599 | + downloadUrl: "http://lemonade-server.ai", | |
| 600 | + }, | |
| 569 | 601 | lmstudio: { |
| 570 | 602 | title: "LM Studio", |
| 571 | 603 | provider: "lmstudio", |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | import { isOnPremSession } from "core/control-plane/AuthTypes"; |
| 2 | -import React, { useEffect, useState } from "react"; | |
| 2 | +import React, { useState } from "react"; | |
| 3 | 3 | import { useNavigate, useSearchParams } from "react-router-dom"; |
| 4 | 4 | import { AssistantAndOrgListbox } from "../../components/AssistantAndOrgListbox"; |
| 5 | 5 | import Alert from "../../components/gui/Alert"; |
| @@ -14,17 +14,11 @@ | ||
| 14 | 14 | useNavigationListener(); |
| 15 | 15 | const navigate = useNavigate(); |
| 16 | 16 | const [searchParams] = useSearchParams(); |
| 17 | - const [activeTab, setActiveTab] = useState("settings"); | |
| 17 | + const [activeTab, setActiveTab] = useState(() => { | |
| 18 | + return searchParams.get("tab") || "settings"; | |
| 19 | + }); | |
| 18 | 20 | const { session, organizations } = useAuth(); |
| 19 | 21 | |
| 20 | - // Set initial tab from URL parameter | |
| 21 | - useEffect(() => { | |
| 22 | - const tab = searchParams.get("tab"); | |
| 23 | - if (tab) { | |
| 24 | - setActiveTab(tab); | |
| 25 | - } | |
| 26 | - }, [searchParams]); | |
| 27 | - | |
| 28 | 22 | const allTabs = getAllTabs(); |
| 29 | 23 | const shouldRenderOrgInfo = |
| 30 | 24 | session && organizations.length > 1 && !isOnPremSession(session); |
| @@ -49,6 +49,8 @@ | ||
| 49 | 49 | import { EmptyChatBody } from "./EmptyChatBody"; |
| 50 | 50 | import { ExploreDialogWatcher } from "./ExploreDialogWatcher"; |
| 51 | 51 | import { useAutoScroll } from "./useAutoScroll"; |
| 52 | +import { useStore } from "react-redux"; | |
| 53 | +import { RootState } from "../../redux/store"; | |
| 52 | 54 | |
| 53 | 55 | // Helper function to find the index of the latest conversation summary |
| 54 | 56 | function findLatestSummaryIndex(history: ChatHistoryItem[]): number { |
| @@ -98,13 +100,11 @@ | ||
| 98 | 100 | export function Chat() { |
| 99 | 101 | const dispatch = useAppDispatch(); |
| 100 | 102 | const ideMessenger = useContext(IdeMessengerContext); |
| 103 | + const reduxStore = useStore<RootState>(); | |
| 101 | 104 | const onboardingCard = useOnboardingCard(); |
| 102 | 105 | const showSessionTabs = useAppSelector( |
| 103 | 106 | (store) => store.config.config.ui?.showSessionTabs, |
| 104 | 107 | ); |
| 105 | - const selectedModels = useAppSelector( | |
| 106 | - (store) => store.config?.config.selectedModelByRole, | |
| 107 | - ); | |
| 108 | 108 | const isStreaming = useAppSelector((state) => state.session.isStreaming); |
| 109 | 109 | const [stepsOpen] = useState<(boolean | undefined)[]>([]); |
| 110 | 110 | const mainTextInputRef = useRef<HTMLInputElement>(null); |
| @@ -115,7 +115,6 @@ | ||
| 115 | 115 | (state) => state.config.config.ui?.showChatScrollbar, |
| 116 | 116 | ); |
| 117 | 117 | const codeToEdit = useAppSelector((state) => state.editModeState.codeToEdit); |
| 118 | - const mode = useAppSelector((store) => store.session.mode); | |
| 119 | 118 | const isInEdit = useAppSelector((store) => store.session.isInEdit); |
| 120 | 119 | |
| 121 | 120 | const lastSessionId = useAppSelector((state) => state.session.lastSessionId); |
| @@ -152,9 +151,6 @@ | ||
| 152 | 151 | isStreaming, |
| 153 | 152 | ); |
| 154 | 153 | |
| 155 | - const pendingToolCalls = useAppSelector(selectPendingToolCalls); | |
| 156 | - const pendingApplyStates = useAppSelector(selectDoneApplyStates); | |
| 157 | - | |
| 158 | 154 | const sendInput = useCallback( |
| 159 | 155 | ( |
| 160 | 156 | editorState: JSONContent, |
| @@ -162,8 +158,16 @@ | ||
| 162 | 158 | index?: number, |
| 163 | 159 | editorToClearOnSend?: Editor, |
| 164 | 160 | ) => { |
| 161 | + const stateSnapshot = reduxStore.getState(); | |
| 162 | + const latestPendingToolCalls = selectPendingToolCalls(stateSnapshot); | |
| 163 | + const latestPendingApplyStates = selectDoneApplyStates(stateSnapshot); | |
| 164 | + const isCurrentlyInEdit = stateSnapshot.session.isInEdit; | |
| 165 | + const codeToEditSnapshot = stateSnapshot.editModeState.codeToEdit; | |
| 166 | + const selectedModelByRole = | |
| 167 | + stateSnapshot.config.config.selectedModelByRole; | |
| 168 | + | |
| 165 | 169 | // Cancel all pending tool calls |
| 166 | - pendingToolCalls.forEach((toolCallState) => { | |
| 170 | + latestPendingToolCalls.forEach((toolCallState) => { | |
| 167 | 171 | dispatch( |
| 168 | 172 | cancelToolCall({ |
| 169 | 173 | toolCallId: toolCallState.toolCallId, |
| @@ -172,19 +176,20 @@ | ||
| 172 | 176 | }); |
| 173 | 177 | |
| 174 | 178 | // Reject all pending apply states |
| 175 | - pendingApplyStates.forEach((applyState) => { | |
| 179 | + latestPendingApplyStates.forEach((applyState) => { | |
| 176 | 180 | if (applyState.status !== "closed") { |
| 177 | 181 | ideMessenger.post("rejectDiff", applyState); |
| 178 | 182 | } |
| 179 | 183 | }); |
| 180 | - const model = isInEdit | |
| 181 | - ? (selectedModels?.edit ?? selectedModels?.chat) | |
| 182 | - : selectedModels?.chat; | |
| 184 | + const model = isCurrentlyInEdit | |
| 185 | + ? (selectedModelByRole.edit ?? selectedModelByRole.chat) | |
| 186 | + : selectedModelByRole.chat; | |
| 187 | + | |
| 183 | 188 | if (!model) { |
| 184 | 189 | return; |
| 185 | 190 | } |
| 186 | 191 | |
| 187 | - if (isInEdit && codeToEdit.length === 0) { | |
| 192 | + if (isCurrentlyInEdit && codeToEditSnapshot.length === 0) { | |
| 188 | 193 | return; |
| 189 | 194 | } |
| 190 | 195 | |
| @@ -212,11 +217,11 @@ | ||
| 212 | 217 | // } |
| 213 | 218 | // } |
| 214 | 219 | |
| 215 | - if (isInEdit) { | |
| 220 | + if (isCurrentlyInEdit) { | |
| 216 | 221 | void dispatch( |
| 217 | 222 | streamEditThunk({ |
| 218 | 223 | editorState, |
| 219 | - codeToEdit, | |
| 224 | + codeToEdit: codeToEditSnapshot, | |
| 220 | 225 | }), |
| 221 | 226 | ); |
| 222 | 227 | } else { |
| @@ -227,15 +232,7 @@ | ||
| 227 | 232 | } |
| 228 | 233 | } |
| 229 | 234 | }, |
| 230 | - [ | |
| 231 | - history, | |
| 232 | - selectedModels, | |
| 233 | - mode, | |
| 234 | - isInEdit, | |
| 235 | - codeToEdit, | |
| 236 | - pendingToolCalls, | |
| 237 | - pendingApplyStates, | |
| 238 | - ], | |
| 235 | + [dispatch, ideMessenger, reduxStore], | |
| 239 | 236 | ); |
| 240 | 237 | |
| 241 | 238 | useWebviewListener( |
| @@ -19,9 +19,16 @@ | ||
| 19 | 19 | useFontSize: () => 14, |
| 20 | 20 | })); |
| 21 | 21 | |
| 22 | -vi.mock("../../../util/clientTools/findAndReplaceUtils", () => ({ | |
| 23 | - performFindAndReplace: vi.fn(), | |
| 24 | -})); | |
| 22 | +vi.mock("../../../util/clientTools/findAndReplaceUtils", async () => { | |
| 23 | + const actual = await vi.importActual( | |
| 24 | + "../../../util/clientTools/findAndReplaceUtils", | |
| 25 | + ); | |
| 26 | + | |
| 27 | + return { | |
| 28 | + performFindAndReplace: vi.fn(), | |
| 29 | + trimEmptyLines: actual.trimEmptyLines, | |
| 30 | + }; | |
| 31 | +}); | |
| 25 | 32 | |
| 26 | 33 | vi.mock("./utils", () => ({ |
| 27 | 34 | getStatusIcon: vi.fn(() => <div data-testid="status-icon">✓</div>), |
| @@ -13,7 +13,10 @@ | ||
| 13 | 13 | selectApplyStateByToolCallId, |
| 14 | 14 | selectToolCallById, |
| 15 | 15 | } from "../../../redux/selectors/selectToolCalls"; |
| 16 | -import { performFindAndReplace } from "../../../util/clientTools/findAndReplaceUtils"; | |
| 16 | +import { | |
| 17 | + performFindAndReplace, | |
| 18 | + trimEmptyLines, | |
| 19 | +} from "../../../util/clientTools/findAndReplaceUtils"; | |
| 17 | 20 | import { cn } from "../../../util/cn"; |
| 18 | 21 | import { getStatusIcon } from "./utils"; |
| 19 | 22 | |
| @@ -313,14 +316,16 @@ | ||
| 313 | 316 | const showMiddleEllipses = |
| 314 | 317 | !isFirst && !isLast && lines.length > MAX_SAME_LINES * 2 + 1; |
| 315 | 318 | |
| 316 | - const startLines = showStartEllipsis | |
| 319 | + let startLines = showStartEllipsis | |
| 317 | 320 | ? lines.slice(-MAX_SAME_LINES) |
| 318 | 321 | : showMiddleEllipses || showEndEllipsis |
| 319 | 322 | ? lines.slice(0, MAX_SAME_LINES) |
| 320 | 323 | : lines; |
| 321 | - const endLines = showMiddleEllipses | |
| 324 | + startLines = trimEmptyLines({ lines: startLines, fromEnd: false }); | |
| 325 | + let endLines = showMiddleEllipses | |
| 322 | 326 | ? lines.slice(-MAX_SAME_LINES) |
| 323 | 327 | : []; |
| 328 | + endLines = trimEmptyLines({ lines: endLines, fromEnd: true }); | |
| 324 | 329 | |
| 325 | 330 | return ( |
| 326 | 331 | <div key={index}> |
| @@ -43,18 +43,6 @@ | ||
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - function handleToggleClick() { | |
| 47 | - if (isToggleable) { | |
| 48 | - setOpen((prev) => !prev); | |
| 49 | - } | |
| 50 | - } | |
| 51 | - | |
| 52 | - function handleIconClick() { | |
| 53 | - if (isSingleItem) { | |
| 54 | - openContextItem(shownContextItems[0], ideMessenger); | |
| 55 | - } | |
| 56 | - } | |
| 57 | - | |
| 58 | 46 | return ( |
| 59 | 47 | <div className="mt-1 flex flex-col px-4"> |
| 60 | 48 | <div className="flex min-w-0 flex-row items-center justify-between gap-2"> |
| @@ -69,7 +57,6 @@ | ||
| 69 | 57 | icon={Icon} |
| 70 | 58 | isToggleable={isToggleable} |
| 71 | 59 | open={shouldShowContent} |
| 72 | - onClick={isToggleable ? handleToggleClick : handleIconClick} | |
| 73 | 60 | isClickable={isSingleItem} |
| 74 | 61 | /> |
| 75 | 62 | <ToolCallStatusMessage tool={tool} toolCallState={toolCallState} /> |
| @@ -1,4 +1,7 @@ | ||
| 1 | -import { ArrowRightIcon } from "@heroicons/react/24/outline"; | |
| 1 | +import { | |
| 2 | + ArrowRightIcon, | |
| 3 | + MagnifyingGlassIcon, | |
| 4 | +} from "@heroicons/react/24/outline"; | |
| 2 | 5 | import { ToolCallState } from "core"; |
| 3 | 6 | import { BuiltInToolNames } from "core/tools/builtIn"; |
| 4 | 7 | import { useState } from "react"; |
| @@ -7,7 +10,7 @@ | ||
| 7 | 10 | import { GroupedToolCallHeader } from "./GroupedToolCallHeader"; |
| 8 | 11 | import { SimpleToolCallUI } from "./SimpleToolCallUI"; |
| 9 | 12 | import { ToolCallDisplay } from "./ToolCallDisplay"; |
| 10 | -import { getStatusIcon, toolCallIcons } from "./utils"; | |
| 13 | +import { getIconByName, getStatusIcon } from "./utils"; | |
| 11 | 14 | |
| 12 | 15 | interface ToolCallDivProps { |
| 13 | 16 | toolCallStates: ToolCallState[]; |
| @@ -37,7 +40,10 @@ | ||
| 37 | 40 | (tool) => toolCallState.toolCall.function?.name === tool.function.name, |
| 38 | 41 | ); |
| 39 | 42 | const functionName = toolCallState.toolCall.function?.name; |
| 40 | - const icon = functionName && toolCallIcons[functionName]; | |
| 43 | + const icon = | |
| 44 | + functionName && tool?.toolCallIcon | |
| 45 | + ? getIconByName(tool.toolCallIcon) | |
| 46 | + : undefined; | |
| 41 | 47 | |
| 42 | 48 | if (icon) { |
| 43 | 49 | return ( |
| @@ -1,25 +1,11 @@ | ||
| 1 | -import { | |
| 2 | - ArrowRightIcon, | |
| 3 | - CheckIcon, | |
| 4 | - CodeBracketIcon, | |
| 5 | - DocumentIcon, | |
| 6 | - DocumentTextIcon, | |
| 7 | - FolderIcon, | |
| 8 | - FolderOpenIcon, | |
| 9 | - GlobeAltIcon, | |
| 10 | - MagnifyingGlassIcon, | |
| 11 | - MapIcon, | |
| 12 | - PencilIcon, | |
| 13 | - XMarkIcon, | |
| 14 | -} from "@heroicons/react/24/outline"; | |
| 1 | +import * as Icons from "@heroicons/react/24/outline"; | |
| 15 | 2 | import { |
| 16 | 3 | ContextItem, |
| 17 | 4 | ContextItemWithId, |
| 18 | 5 | ToolCallState, |
| 19 | 6 | ToolStatus, |
| 20 | 7 | } from "core"; |
| 21 | -import { BuiltInToolNames } from "core/tools/builtIn"; | |
| 22 | -import { ComponentType } from "react"; | |
| 8 | +import { ComponentType, SVGProps } from "react"; | |
| 23 | 9 | import { vscButtonBackground } from "../../../components"; |
| 24 | 10 | import Spinner from "../../../components/gui/Spinner"; |
| 25 | 11 | |
| @@ -70,19 +56,16 @@ | ||
| 70 | 56 | return "Performing"; |
| 71 | 57 | } |
| 72 | 58 | |
| 73 | -export const toolCallIcons: Record<string, ComponentType> = { | |
| 74 | - [BuiltInToolNames.FileGlobSearch]: MagnifyingGlassIcon, | |
| 75 | - [BuiltInToolNames.GrepSearch]: MagnifyingGlassIcon, | |
| 76 | - [BuiltInToolNames.LSTool]: FolderIcon, | |
| 77 | - [BuiltInToolNames.ReadCurrentlyOpenFile]: DocumentTextIcon, | |
| 78 | - [BuiltInToolNames.ReadFile]: DocumentIcon, | |
| 79 | - [BuiltInToolNames.FetchUrlContent]: GlobeAltIcon, | |
| 80 | - [BuiltInToolNames.SearchWeb]: GlobeAltIcon, | |
| 81 | - [BuiltInToolNames.ViewDiff]: CodeBracketIcon, | |
| 82 | - [BuiltInToolNames.ViewRepoMap]: MapIcon, | |
| 83 | - [BuiltInToolNames.ViewSubdirectory]: FolderOpenIcon, | |
| 84 | - [BuiltInToolNames.CreateRuleBlock]: PencilIcon, | |
| 85 | -}; | |
| 59 | +type IconName = keyof typeof Icons; | |
| 60 | + | |
| 61 | +type Icon = ComponentType<SVGProps<SVGSVGElement>> | undefined; | |
| 62 | + | |
| 63 | +export function getIconByName(name: string): Icon | null { | |
| 64 | + if (name in Icons) { | |
| 65 | + return Icons[name as IconName] as Icon; | |
| 66 | + } | |
| 67 | + return null; | |
| 68 | +} | |
| 86 | 69 | |
| 87 | 70 | export function getStatusIcon(state: ToolStatus) { |
| 88 | 71 | switch (state) { |
| @@ -90,12 +73,12 @@ | ||
| 90 | 73 | case "calling": |
| 91 | 74 | return <Spinner />; |
| 92 | 75 | case "generated": |
| 93 | - return <ArrowRightIcon color={vscButtonBackground} />; | |
| 76 | + return <Icons.ArrowRightIcon color={vscButtonBackground} />; | |
| 94 | 77 | case "done": |
| 95 | - return <CheckIcon className="text-success" />; | |
| 78 | + return <Icons.CheckIcon className="text-success" />; | |
| 96 | 79 | case "canceled": |
| 97 | 80 | case "errored": |
| 98 | - return <XMarkIcon className="text-error" />; | |
| 81 | + return <Icons.XMarkIcon className="text-error" />; | |
| 99 | 82 | } |
| 100 | 83 | } |
| 101 | 84 |
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | EMPTY_NON_FIRST_EDIT_MESSAGE, |
| 5 | 5 | FOUND_MULTIPLE_FIND_STRINGS_ERROR, |
| 6 | 6 | performFindAndReplace, |
| 7 | + trimEmptyLines, | |
| 7 | 8 | validateCreatingForMultiEdit, |
| 8 | 9 | validateSingleEdit, |
| 9 | 10 | } from "./findAndReplaceUtils"; |
| @@ -454,3 +455,23 @@ | ||
| 454 | 455 | }); |
| 455 | 456 | }); |
| 456 | 457 | }); |
| 458 | + | |
| 459 | +describe("trimEmptyLines", () => { | |
| 460 | + it("trims leading empty lines from start", () => { | |
| 461 | + const input = ["", "", "a", "", "b"]; | |
| 462 | + const result = trimEmptyLines({ lines: input, fromEnd: false }); | |
| 463 | + expect(result).toEqual(["a", "", "b"]); | |
| 464 | + }); | |
| 465 | + | |
| 466 | + it("trims trailing empty lines from end", () => { | |
| 467 | + const input = ["a", "", "b", "", ""]; | |
| 468 | + const result = trimEmptyLines({ lines: input, fromEnd: true }); | |
| 469 | + expect(result).toEqual(["a", "", "b"]); | |
| 470 | + }); | |
| 471 | + | |
| 472 | + it("returns empty array when all lines are empty", () => { | |
| 473 | + const input = ["", "", ""]; | |
| 474 | + const result = trimEmptyLines({ lines: input, fromEnd: false }); | |
| 475 | + expect(result).toEqual([]); | |
| 476 | + }); | |
| 477 | +}); |
| @@ -95,3 +95,22 @@ | ||
| 95 | 95 | |
| 96 | 96 | return isCreating; |
| 97 | 97 | } |
| 98 | + | |
| 99 | +export function trimEmptyLines({ | |
| 100 | + lines, | |
| 101 | + fromEnd, | |
| 102 | +}: { | |
| 103 | + lines: string[]; | |
| 104 | + fromEnd: boolean; | |
| 105 | +}): string[] { | |
| 106 | + lines = fromEnd ? lines.toReversed() : lines.slice(); | |
| 107 | + const newLines: string[] = []; | |
| 108 | + let shouldContinueRemoving = true; | |
| 109 | + for (let index = 0; index < lines.length; index++) { | |
| 110 | + const line = lines[index]; | |
| 111 | + if (shouldContinueRemoving && line.trim() === "") continue; | |
| 112 | + shouldContinueRemoving = false; | |
| 113 | + newLines.push(line); | |
| 114 | + } | |
| 115 | + return fromEnd ? newLines.reverse() : newLines; | |
| 116 | +} |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | { |
| 2 | 2 | "name": "@continuedev/config-yaml", |
| 3 | - "version": "1.14.0", | |
| 3 | + "version": "1.17.0", | |
| 4 | 4 | "description": "", |
| 5 | 5 | "main": "dist/index.js", |
| 6 | 6 | "types": "dist/index.d.ts", |
| @@ -193,6 +193,7 @@ | ||
| 193 | 193 | prompts, |
| 194 | 194 | mcpServers, |
| 195 | 195 | docs, |
| 196 | + requestOptions: configJson.requestOptions, | |
| 196 | 197 | }; |
| 197 | 198 | |
| 198 | 199 | return configYaml; |
| @@ -1,3 +1,5 @@ | ||
| 1 | +import os from "node:os"; | |
| 2 | + | |
| 1 | 3 | export interface PackageSlug { |
| 2 | 4 | ownerSlug: string; |
| 3 | 5 | packageSlug: string; |
| @@ -61,13 +63,18 @@ | ||
| 61 | 63 | fileUri: identifier.substring(7), |
| 62 | 64 | }; |
| 63 | 65 | } |
| 64 | - // Otherwise, it's a slug | |
| 65 | - else { | |
| 66 | + // support ~ by replacing with home directory | |
| 67 | + else if (identifier.startsWith("~")) { | |
| 66 | 68 | return { |
| 67 | - uriType: "slug", | |
| 68 | - fullSlug: decodeFullSlug(identifier), | |
| 69 | + uriType: "file", | |
| 70 | + fileUri: identifier.replace("~", os.homedir()), | |
| 69 | 71 | }; |
| 70 | 72 | } |
| 73 | + // Otherwise, it's a slug | |
| 74 | + return { | |
| 75 | + uriType: "slug", | |
| 76 | + fullSlug: decodeFullSlug(identifier), | |
| 77 | + }; | |
| 71 | 78 | } |
| 72 | 79 | |
| 73 | 80 | export enum VirtualTags { |
| @@ -0,0 +1,235 @@ | ||
| 1 | +import { describe, expect, it } from "@jest/globals"; | |
| 2 | +import type { RequestOptions } from "../schemas/models.js"; | |
| 3 | +import { mergeConfigYamlRequestOptions } from "./merge.js"; | |
| 4 | + | |
| 5 | +describe("mergeConfigYamlRequestOptions", () => { | |
| 6 | + it("should return undefined when both base and global are undefined", () => { | |
| 7 | + const result = mergeConfigYamlRequestOptions(undefined, undefined); | |
| 8 | + expect(result).toBeUndefined(); | |
| 9 | + }); | |
| 10 | + | |
| 11 | + it("should return global when base is undefined", () => { | |
| 12 | + const global: RequestOptions = { | |
| 13 | + timeout: 5000, | |
| 14 | + verifySsl: true, | |
| 15 | + headers: { Authorization: "Bearer token" }, | |
| 16 | + }; | |
| 17 | + const result = mergeConfigYamlRequestOptions(undefined, global); | |
| 18 | + expect(result).toEqual(global); | |
| 19 | + }); | |
| 20 | + | |
| 21 | + it("should return base when global is undefined", () => { | |
| 22 | + const base: RequestOptions = { | |
| 23 | + timeout: 3000, | |
| 24 | + verifySsl: false, | |
| 25 | + headers: { "X-Custom": "value" }, | |
| 26 | + }; | |
| 27 | + const result = mergeConfigYamlRequestOptions(base, undefined); | |
| 28 | + expect(result).toEqual(base); | |
| 29 | + }); | |
| 30 | + | |
| 31 | + it("should merge headers from both objects", () => { | |
| 32 | + const base: RequestOptions = { | |
| 33 | + headers: { "X-Base": "base-value", "X-Common": "base-common" }, | |
| 34 | + }; | |
| 35 | + const global: RequestOptions = { | |
| 36 | + headers: { "X-Global": "global-value", "X-Common": "global-common" }, | |
| 37 | + }; | |
| 38 | + const result = mergeConfigYamlRequestOptions(base, global); | |
| 39 | + expect(result?.headers).toEqual({ | |
| 40 | + "X-Global": "global-value", | |
| 41 | + "X-Common": "base-common", // base overrides global | |
| 42 | + "X-Base": "base-value", | |
| 43 | + }); | |
| 44 | + }); | |
| 45 | + | |
| 46 | + it("should override simple values with base values", () => { | |
| 47 | + const base: RequestOptions = { | |
| 48 | + timeout: 3000, | |
| 49 | + verifySsl: false, | |
| 50 | + proxy: "http://base-proxy.com", | |
| 51 | + }; | |
| 52 | + const global: RequestOptions = { | |
| 53 | + timeout: 5000, | |
| 54 | + verifySsl: true, | |
| 55 | + proxy: "http://global-proxy.com", | |
| 56 | + caBundlePath: "/path/to/ca", | |
| 57 | + }; | |
| 58 | + const result = mergeConfigYamlRequestOptions(base, global); | |
| 59 | + expect(result).toEqual({ | |
| 60 | + timeout: 3000, // base overrides | |
| 61 | + verifySsl: false, // base overrides | |
| 62 | + proxy: "http://base-proxy.com", // base overrides | |
| 63 | + caBundlePath: "/path/to/ca", // only in global | |
| 64 | + headers: undefined, | |
| 65 | + }); | |
| 66 | + }); | |
| 67 | + | |
| 68 | + it("should handle noProxy array properly (base overrides)", () => { | |
| 69 | + const base: RequestOptions = { | |
| 70 | + noProxy: ["localhost", "127.0.0.1"], | |
| 71 | + }; | |
| 72 | + const global: RequestOptions = { | |
| 73 | + noProxy: ["192.168.1.1", "example.com"], | |
| 74 | + }; | |
| 75 | + const result = mergeConfigYamlRequestOptions(base, global); | |
| 76 | + expect(result?.noProxy).toEqual(["localhost", "127.0.0.1"]); // base overrides completely | |
| 77 | + }); | |
| 78 | + | |
| 79 | + it("should handle extraBodyProperties (base overrides)", () => { | |
| 80 | + const base: RequestOptions = { | |
| 81 | + extraBodyProperties: { baseProp: "baseValue", common: "base" }, | |
| 82 | + }; | |
| 83 | + const global: RequestOptions = { | |
| 84 | + extraBodyProperties: { globalProp: "globalValue", common: "global" }, | |
| 85 | + }; | |
| 86 | + const result = mergeConfigYamlRequestOptions(base, global); | |
| 87 | + expect(result?.extraBodyProperties).toEqual({ | |
| 88 | + baseProp: "baseValue", | |
| 89 | + common: "base", | |
| 90 | + }); // base overrides completely | |
| 91 | + }); | |
| 92 | + | |
| 93 | + it("should handle clientCertificate (base overrides)", () => { | |
| 94 | + const base: RequestOptions = { | |
| 95 | + clientCertificate: { | |
| 96 | + cert: "base-cert", | |
| 97 | + key: "base-key", | |
| 98 | + passphrase: "base-pass", | |
| 99 | + }, | |
| 100 | + }; | |
| 101 | + const global: RequestOptions = { | |
| 102 | + clientCertificate: { | |
| 103 | + cert: "global-cert", | |
| 104 | + key: "global-key", | |
| 105 | + }, | |
| 106 | + }; | |
| 107 | + const result = mergeConfigYamlRequestOptions(base, global); | |
| 108 | + expect(result?.clientCertificate).toEqual({ | |
| 109 | + cert: "base-cert", | |
| 110 | + key: "base-key", | |
| 111 | + passphrase: "base-pass", | |
| 112 | + }); // base overrides completely | |
| 113 | + }); | |
| 114 | + | |
| 115 | + it("should return undefined headers when both have empty headers", () => { | |
| 116 | + const base: RequestOptions = { | |
| 117 | + headers: {}, | |
| 118 | + timeout: 1000, | |
| 119 | + }; | |
| 120 | + const global: RequestOptions = { | |
| 121 | + headers: {}, | |
| 122 | + verifySsl: true, | |
| 123 | + }; | |
| 124 | + const result = mergeConfigYamlRequestOptions(base, global); | |
| 125 | + expect(result?.headers).toBeUndefined(); | |
| 126 | + expect(result?.timeout).toBe(1000); | |
| 127 | + expect(result?.verifySsl).toBe(true); | |
| 128 | + }); | |
| 129 | + | |
| 130 | + it("should handle caBundlePath as string", () => { | |
| 131 | + const base: RequestOptions = { | |
| 132 | + caBundlePath: "/base/ca.pem", | |
| 133 | + }; | |
| 134 | + const global: RequestOptions = { | |
| 135 | + caBundlePath: "/global/ca.pem", | |
| 136 | + }; | |
| 137 | + const result = mergeConfigYamlRequestOptions(base, global); | |
| 138 | + expect(result?.caBundlePath).toBe("/base/ca.pem"); // base overrides | |
| 139 | + }); | |
| 140 | + | |
| 141 | + it("should handle caBundlePath as array", () => { | |
| 142 | + const base: RequestOptions = { | |
| 143 | + caBundlePath: ["/base/ca1.pem", "/base/ca2.pem"], | |
| 144 | + }; | |
| 145 | + const global: RequestOptions = { | |
| 146 | + caBundlePath: ["/global/ca.pem"], | |
| 147 | + }; | |
| 148 | + const result = mergeConfigYamlRequestOptions(base, global); | |
| 149 | + expect(result?.caBundlePath).toEqual(["/base/ca1.pem", "/base/ca2.pem"]); // base overrides | |
| 150 | + }); | |
| 151 | + | |
| 152 | + it("should preserve all fields from base when global has different fields", () => { | |
| 153 | + const base: RequestOptions = { | |
| 154 | + timeout: 3000, | |
| 155 | + headers: { "X-Base": "value" }, | |
| 156 | + noProxy: ["localhost"], | |
| 157 | + }; | |
| 158 | + const global: RequestOptions = { | |
| 159 | + verifySsl: true, | |
| 160 | + proxy: "http://proxy.com", | |
| 161 | + caBundlePath: "/ca.pem", | |
| 162 | + }; | |
| 163 | + const result = mergeConfigYamlRequestOptions(base, global); | |
| 164 | + expect(result).toEqual({ | |
| 165 | + timeout: 3000, | |
| 166 | + verifySsl: true, | |
| 167 | + proxy: "http://proxy.com", | |
| 168 | + caBundlePath: "/ca.pem", | |
| 169 | + headers: { "X-Base": "value" }, | |
| 170 | + noProxy: ["localhost"], | |
| 171 | + }); | |
| 172 | + }); | |
| 173 | + | |
| 174 | + it("should handle complex header merging scenario", () => { | |
| 175 | + const base: RequestOptions = { | |
| 176 | + headers: { | |
| 177 | + Authorization: "Bearer base-token", | |
| 178 | + "X-Custom-Header": "base-custom", | |
| 179 | + "Content-Type": "application/json", | |
| 180 | + }, | |
| 181 | + }; | |
| 182 | + const global: RequestOptions = { | |
| 183 | + headers: { | |
| 184 | + Authorization: "Bearer global-token", | |
| 185 | + "X-Global-Header": "global-value", | |
| 186 | + "Accept-Language": "en-US", | |
| 187 | + }, | |
| 188 | + }; | |
| 189 | + const result = mergeConfigYamlRequestOptions(base, global); | |
| 190 | + expect(result?.headers).toEqual({ | |
| 191 | + Authorization: "Bearer base-token", // base overrides | |
| 192 | + "X-Global-Header": "global-value", // from global | |
| 193 | + "Accept-Language": "en-US", // from global | |
| 194 | + "X-Custom-Header": "base-custom", // from base | |
| 195 | + "Content-Type": "application/json", // from base | |
| 196 | + }); | |
| 197 | + }); | |
| 198 | + | |
| 199 | + it("should handle all possible fields", () => { | |
| 200 | + const base: RequestOptions = { | |
| 201 | + timeout: 1000, | |
| 202 | + verifySsl: false, | |
| 203 | + caBundlePath: ["/base/ca.pem"], | |
| 204 | + proxy: "http://base-proxy.com", | |
| 205 | + headers: { "X-Base": "base" }, | |
| 206 | + extraBodyProperties: { baseProp: true }, | |
| 207 | + noProxy: ["base.local"], | |
| 208 | + clientCertificate: { cert: "base-cert", key: "base-key" }, | |
| 209 | + }; | |
| 210 | + const global: RequestOptions = { | |
| 211 | + timeout: 2000, | |
| 212 | + verifySsl: true, | |
| 213 | + caBundlePath: ["/global/ca.pem"], | |
| 214 | + proxy: "http://global-proxy.com", | |
| 215 | + headers: { "X-Global": "global" }, | |
| 216 | + extraBodyProperties: { globalProp: false }, | |
| 217 | + noProxy: ["global.local"], | |
| 218 | + clientCertificate: { cert: "global-cert", key: "global-key" }, | |
| 219 | + }; | |
| 220 | + const result = mergeConfigYamlRequestOptions(base, global); | |
| 221 | + expect(result).toEqual({ | |
| 222 | + timeout: 1000, // base overrides | |
| 223 | + verifySsl: false, // base overrides | |
| 224 | + caBundlePath: ["/base/ca.pem"], // base overrides | |
| 225 | + proxy: "http://base-proxy.com", // base overrides | |
| 226 | + headers: { | |
| 227 | + "X-Global": "global", | |
| 228 | + "X-Base": "base", | |
| 229 | + }, // merged | |
| 230 | + extraBodyProperties: { baseProp: true }, // base overrides | |
| 231 | + noProxy: ["base.local"], // base overrides | |
| 232 | + clientCertificate: { cert: "base-cert", key: "base-key" }, // base overrides | |
| 233 | + }); | |
| 234 | + }); | |
| 235 | +}); |
| @@ -1,3 +1,4 @@ | ||
| 1 | +import { RequestOptions } from "../browser.js"; | |
| 1 | 2 | import { AssistantUnrolled, ConfigYaml } from "../schemas/index.js"; |
| 2 | 3 | |
| 3 | 4 | export function mergePackages( |
| @@ -14,6 +15,10 @@ | ||
| 14 | 15 | prompts: [...(current.prompts ?? []), ...(incoming.prompts ?? [])], |
| 15 | 16 | docs: [...(current.docs ?? []), ...(incoming.docs ?? [])], |
| 16 | 17 | env: { ...current.env, ...incoming.env }, |
| 18 | + requestOptions: mergeConfigYamlRequestOptions( | |
| 19 | + current.requestOptions, | |
| 20 | + incoming.requestOptions, | |
| 21 | + ), | |
| 17 | 22 | }; |
| 18 | 23 | } |
| 19 | 24 | |
| @@ -31,5 +36,35 @@ | ||
| 31 | 36 | mcpServers: [...(current.mcpServers ?? []), ...(incoming.mcpServers ?? [])], |
| 32 | 37 | prompts: [...(current.prompts ?? []), ...(incoming.prompts ?? [])], |
| 33 | 38 | env: { ...current.env, ...incoming.env }, |
| 39 | + requestOptions: mergeConfigYamlRequestOptions( | |
| 40 | + current.requestOptions, | |
| 41 | + incoming.requestOptions, | |
| 42 | + ), | |
| 43 | + }; | |
| 44 | +} | |
| 45 | + | |
| 46 | +export function mergeConfigYamlRequestOptions( | |
| 47 | + base: RequestOptions | undefined, | |
| 48 | + global: RequestOptions | undefined, | |
| 49 | +): RequestOptions | undefined { | |
| 50 | + if (!base && !global) { | |
| 51 | + return undefined; | |
| 52 | + } | |
| 53 | + if (!base) { | |
| 54 | + return global; | |
| 55 | + } | |
| 56 | + if (!global) { | |
| 57 | + return base; | |
| 58 | + } | |
| 59 | + | |
| 60 | + const headers = { | |
| 61 | + ...global.headers, | |
| 62 | + ...base.headers, | |
| 63 | + }; | |
| 64 | + | |
| 65 | + return { | |
| 66 | + ...global, | |
| 67 | + ...base, // base overrides for simple values as well as noProxy and extraBodyProperties | |
| 68 | + headers: Object.keys(headers).length === 0 ? undefined : headers, // headers are the only thing that really merge | |
| 34 | 69 | }; |
| 35 | 70 | } |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import * as YAML from "yaml"; |
| 2 | 2 | import { ZodError } from "zod"; |
| 3 | +import { mergeConfigYamlRequestOptions, RequestOptions } from "../browser.js"; | |
| 3 | 4 | import { PlatformClient, Registry } from "../interfaces/index.js"; |
| 4 | 5 | import { encodeSecretLocation } from "../interfaces/SecretResult.js"; |
| 5 | 6 | import { |
| @@ -203,6 +204,7 @@ | ||
| 203 | 204 | injectBlocks?: PackageIdentifier[]; |
| 204 | 205 | allowlistedBlocks?: PackageSlug[]; |
| 205 | 206 | blocklistedBlocks?: PackageSlug[]; |
| 207 | + injectRequestOptions?: RequestOptions; | |
| 206 | 208 | } |
| 207 | 209 | |
| 208 | 210 | export interface DoNotRenderSecretsUnrollAssistantOptions |
| @@ -274,6 +276,7 @@ | ||
| 274 | 276 | options.injectBlocks, |
| 275 | 277 | options.allowlistedBlocks, |
| 276 | 278 | options.blocklistedBlocks, |
| 279 | + options.injectRequestOptions, | |
| 277 | 280 | ); |
| 278 | 281 | |
| 279 | 282 | // Back to a string so we can fill in template variables |
| @@ -302,14 +305,14 @@ | ||
| 302 | 305 | const renderedYaml = renderTemplateData(templatedYaml, { secrets }); |
| 303 | 306 | |
| 304 | 307 | // Parse again and replace models with proxy versions where secrets weren't rendered |
| 305 | - const finalConfig = useProxyForUnrenderedSecrets( | |
| 308 | + const renderedConfig = useProxyForUnrenderedSecrets( | |
| 306 | 309 | parseAssistantUnrolled(renderedYaml), |
| 307 | 310 | id, |
| 308 | 311 | options.orgScopeId, |
| 309 | 312 | options.onPremProxyUrl, |
| 310 | 313 | ); |
| 311 | 314 | |
| 312 | - return { config: finalConfig, errors, configLoadInterrupted }; | |
| 315 | + return { config: renderedConfig, errors, configLoadInterrupted }; | |
| 313 | 316 | } |
| 314 | 317 | |
| 315 | 318 | function isPackageAllowed( |
| @@ -350,6 +353,7 @@ | ||
| 350 | 353 | injectBlocks: PackageIdentifier[] | undefined, |
| 351 | 354 | allowlistedBlocks?: PackageSlug[], |
| 352 | 355 | blocklistedBlocks?: PackageSlug[], |
| 356 | + injectRequestOptions?: RequestOptions, | |
| 353 | 357 | ): Promise<ConfigResult<AssistantUnrolled>> { |
| 354 | 358 | const errors: ConfigValidationError[] = []; |
| 355 | 359 | |
| @@ -363,11 +367,27 @@ | ||
| 363 | 367 | const unrolledAssistant: AssistantUnrolled = { |
| 364 | 368 | name: assistant.name, |
| 365 | 369 | version: assistant.version, |
| 370 | + requestOptions: assistant.requestOptions, | |
| 366 | 371 | }; |
| 367 | 372 | |
| 373 | + if (injectRequestOptions) { | |
| 374 | + unrolledAssistant.requestOptions = mergeConfigYamlRequestOptions( | |
| 375 | + assistant.requestOptions, | |
| 376 | + injectRequestOptions, | |
| 377 | + ); | |
| 378 | + } else { | |
| 379 | + unrolledAssistant.requestOptions = assistant.requestOptions; | |
| 380 | + } | |
| 381 | + | |
| 368 | 382 | const sections: (keyof Omit< |
| 369 | 383 | ConfigYaml, |
| 370 | - "name" | "version" | "rules" | "schema" | "metadata" | "env" | |
| 384 | + | "name" | |
| 385 | + | "version" | |
| 386 | + | "rules" | |
| 387 | + | "schema" | |
| 388 | + | "metadata" | |
| 389 | + | "env" | |
| 390 | + | "requestOptions" | |
| 371 | 391 | >)[] = ["models", "context", "data", "mcpServers", "prompts", "docs"]; |
| 372 | 392 | |
| 373 | 393 | // Process all sections in parallel |
| @@ -36,6 +36,7 @@ | ||
| 36 | 36 | globs?: string | string[]; |
| 37 | 37 | regex?: string | string[]; |
| 38 | 38 | alwaysApply?: boolean; |
| 39 | + invokable?: boolean; | |
| 39 | 40 | } = {}, |
| 40 | 41 | ): string { |
| 41 | 42 | const frontmatter: RuleFrontmatter = {}; |
| @@ -54,6 +55,10 @@ | ||
| 54 | 55 | frontmatter.description = options.description.trim(); |
| 55 | 56 | } |
| 56 | 57 | |
| 58 | + if (options.invokable !== undefined) { | |
| 59 | + frontmatter.invokable = options.invokable; | |
| 60 | + } | |
| 61 | + | |
| 57 | 62 | if (options.alwaysApply !== undefined) { |
| 58 | 63 | frontmatter.alwaysApply = options.alwaysApply; |
| 59 | 64 | } |
| @@ -117,6 +117,7 @@ | ||
| 117 | 117 | schema: z.string().optional(), |
| 118 | 118 | metadata: z.record(z.string()).and(commonMetadataSchema.partial()).optional(), |
| 119 | 119 | env: envRecord.optional(), |
| 120 | + requestOptions: requestOptionsSchema.optional(), | |
| 120 | 121 | }); |
| 121 | 122 | |
| 122 | 123 | const modelsUsesSchema = z |
| @@ -262,6 +263,7 @@ | ||
| 262 | 263 | api_base: z.string().optional(), |
| 263 | 264 | api_key: z.string().optional(), |
| 264 | 265 | env: envRecord.optional(), |
| 266 | + requestOptions: requestOptionsSchema.optional(), | |
| 265 | 267 | }); |
| 266 | 268 | |
| 267 | 269 | export type Config = z.infer<typeof configSchema>; |
| @@ -20,10 +20,10 @@ | ||
| 20 | 20 | }, |
| 21 | 21 | "../config-yaml": { |
| 22 | 22 | "name": "@continuedev/config-yaml", |
| 23 | - "version": "1.0.96", | |
| 23 | + "version": "1.14.0", | |
| 24 | 24 | "license": "Apache-2.0", |
| 25 | 25 | "dependencies": { |
| 26 | - "@continuedev/config-types": "file:../config-types", | |
| 26 | + "@continuedev/config-types": "^1.0.14", | |
| 27 | 27 | "yaml": "^2.6.1", |
| 28 | 28 | "zod": "^3.24.2" |
| 29 | 29 | }, |
| @@ -4,5 +4,6 @@ | ||
| 4 | 4 | { |
| 5 | 5 | model: "starcoder2:3b", |
| 6 | 6 | displayName: "StarCoder 2 3B", |
| 7 | + contextLength: 8192, | |
| 7 | 8 | }, |
| 8 | 9 | ]; |
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | { |
| 2 | 2 | "name": "@continuedev/openai-adapters", |
| 3 | - "version": "1.14.0", | |
| 3 | + "version": "1.15.0", | |
| 4 | 4 | "description": "", |
| 5 | 5 | "main": "dist/index.js", |
| 6 | 6 | "types": "dist/index.d.ts", |
| @@ -140,9 +140,25 @@ | ||
| 140 | 140 | ], |
| 141 | 141 | }; |
| 142 | 142 | } else if (message.role === "assistant" && message.tool_calls) { |
| 143 | - return { | |
| 144 | - role: "assistant", | |
| 145 | - content: message.tool_calls.map((toolCall) => { | |
| 143 | + const parts: any[] = []; | |
| 144 | + if (message.content) { | |
| 145 | + if (typeof message.content === "string") { | |
| 146 | + parts.push({ | |
| 147 | + type: "text", | |
| 148 | + text: message.content, | |
| 149 | + }); | |
| 150 | + } else if (message.content.length > 0) { | |
| 151 | + parts.push( | |
| 152 | + message.content.map((c) => ({ | |
| 153 | + type: "text", | |
| 154 | + text: c.type === "text" ? c.text : c.refusal, | |
| 155 | + })), | |
| 156 | + ); | |
| 157 | + } | |
| 158 | + } | |
| 159 | + | |
| 160 | + parts.push( | |
| 161 | + ...message.tool_calls.map((toolCall) => { | |
| 146 | 162 | // Type guard for function tool calls |
| 147 | 163 | if (toolCall.type === "function" && "function" in toolCall) { |
| 148 | 164 | return { |
| @@ -158,6 +174,10 @@ | ||
| 158 | 174 | throw new Error(`Unsupported tool call type: ${toolCall.type}`); |
| 159 | 175 | } |
| 160 | 176 | }), |
| 177 | + ); | |
| 178 | + return { | |
| 179 | + role: "assistant", | |
| 180 | + content: parts, | |
| 161 | 181 | }; |
| 162 | 182 | } |
| 163 | 183 |
| @@ -12,6 +12,7 @@ | ||
| 12 | 12 | export interface TestConfigOptions { |
| 13 | 13 | skipTools: boolean; |
| 14 | 14 | expectUsage?: boolean; |
| 15 | + skipSystemMessage?: boolean; | |
| 15 | 16 | } |
| 16 | 17 | |
| 17 | 18 | function testConfig(_config: ModelConfig & { options?: TestConfigOptions }) { |
| @@ -98,9 +99,9 @@ | ||
| 98 | 99 | }, |
| 99 | 100 | { |
| 100 | 101 | provider: "mistral", |
| 101 | - model: "codestral", | |
| 102 | + model: "codestral-latest", | |
| 102 | 103 | apiKey: process.env.MISTRAL_API_KEY!, |
| 103 | - roles: ["chat"], | |
| 104 | + roles: ["chat", "autocomplete"], | |
| 104 | 105 | options: { |
| 105 | 106 | skipTools: false, |
| 106 | 107 | expectUsage: true, |
| @@ -150,6 +151,7 @@ | ||
| 150 | 151 | options: { |
| 151 | 152 | skipTools: true, |
| 152 | 153 | expectUsage: true, |
| 154 | + skipSystemMessage: true, | |
| 153 | 155 | }, |
| 154 | 156 | }, |
| 155 | 157 | { |
| @@ -210,26 +210,28 @@ | ||
| 210 | 210 | }); |
| 211 | 211 | |
| 212 | 212 | test("should acknowledge system message in chat", async () => { |
| 213 | - const response = await api.chatCompletionNonStream( | |
| 214 | - { | |
| 215 | - model, | |
| 216 | - messages: [ | |
| 217 | - { | |
| 218 | - role: "system", | |
| 219 | - content: | |
| 220 | - "Regardless of what is asked of you, your answer should start with 'RESPONSE: '.", | |
| 221 | - }, | |
| 222 | - { role: "user", content: "Who are you?" }, | |
| 223 | - ], | |
| 224 | - stream: false, | |
| 225 | - }, | |
| 226 | - new AbortController().signal, | |
| 227 | - ); | |
| 228 | - expect(response.choices.length).toBeGreaterThan(0); | |
| 229 | - const completion = response.choices[0].message.content; | |
| 230 | - expect(typeof completion).toBe("string"); | |
| 231 | - expect(completion?.length).toBeGreaterThan(0); | |
| 232 | - expect(completion?.startsWith("RESPONSE: ")).toBe(true); | |
| 213 | + if (options?.skipSystemMessage !== true) { | |
| 214 | + const response = await api.chatCompletionNonStream( | |
| 215 | + { | |
| 216 | + model, | |
| 217 | + messages: [ | |
| 218 | + { | |
| 219 | + role: "system", | |
| 220 | + content: | |
| 221 | + "Regardless of what is asked of you, your answer should start with 'RESPONSE: '.", | |
| 222 | + }, | |
| 223 | + { role: "user", content: "Who are you?" }, | |
| 224 | + ], | |
| 225 | + stream: false, | |
| 226 | + }, | |
| 227 | + new AbortController().signal, | |
| 228 | + ); | |
| 229 | + expect(response.choices.length).toBeGreaterThan(0); | |
| 230 | + const completion = response.choices[0].message.content; | |
| 231 | + expect(typeof completion).toBe("string"); | |
| 232 | + expect(completion?.length).toBeGreaterThan(0); | |
| 233 | + expect(completion?.startsWith("RESPONSE: ")).toBe(true); | |
| 234 | + } | |
| 233 | 235 | }); |
| 234 | 236 | |
| 235 | 237 | if (options?.skipTools === false) { |
| @@ -315,14 +317,14 @@ | ||
| 315 | 317 | arguments: '{"name":"Nate"}', |
| 316 | 318 | name: "say_hello", |
| 317 | 319 | }, |
| 318 | - id: "tool_call_1", | |
| 320 | + id: "toolcall1", // mistral requires alphanumeric length of 9 | |
| 319 | 321 | type: "function", |
| 320 | 322 | }, |
| 321 | 323 | ], |
| 322 | 324 | }, |
| 323 | 325 | { |
| 324 | 326 | role: "tool", |
| 325 | - tool_call_id: "tool_call_1", | |
| 327 | + tool_call_id: "toolcall1", | |
| 326 | 328 | content: "Nate was greeted", |
| 327 | 329 | }, |
| 328 | 330 | ], |