From ac0fb0d388eb82e3187d33e681be5f8084315f31 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Tue, 13 May 2025 10:54:35 +0530 Subject: [PATCH 001/182] instructions to clean reset --- docs/docs/troubleshooting.mdx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/docs/troubleshooting.mdx b/docs/docs/troubleshooting.mdx index 71eac9d9b..dcb619f76 100644 --- a/docs/docs/troubleshooting.mdx +++ b/docs/docs/troubleshooting.mdx @@ -162,6 +162,10 @@ Most Continue features will work normally, including autocomplete and chat. Howe For more details about this requirement, see the [LanceDB issue #2195](https://github.com/lancedb/lance/issues/2195). +### Resetting the entire plugin + +In cases when you like to clean reset the plugin, you would need to delete the `~/.continue` directory (or `%USERPROFILE%\.continue` on Windows). This will remove all your local settings, sessions, and other customizations. After this you may want to reinstall the plugin. + ## Still having trouble? You can also join our Discord community [here](https://discord.gg/vapESyrFmJ) for additional support and discussions. Alternatively, you can create a GitHub issue [here](https://github.com/continuedev/continue/issues/new?assignees=&labels=bug&projects=&template=bug-report-%F0%9F%90%9B.md&title=), providing details of your problem, and we'll be able to help you out more quickly. From d837f9215662b77ff45f0e2cab34a4c5cc89905a Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Tue, 13 May 2025 11:24:05 +0530 Subject: [PATCH 002/182] rename "apply" to "Apply Role" in sidebar --- docs/docs/customize/model-roles/apply.mdx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/docs/customize/model-roles/apply.mdx b/docs/docs/customize/model-roles/apply.mdx index 6cce4acbc..d1ee7609b 100644 --- a/docs/docs/customize/model-roles/apply.mdx +++ b/docs/docs/customize/model-roles/apply.mdx @@ -1,3 +1,10 @@ +--- +title: Apply Role +description: Apply model role +keywords: [apply, model, role] +sidebar_position: 4 +--- + When editing code, Chat and Edit model output often doesn't clearly align with existing code. A model with the `apply` role is used to generate a more precise diff to apply changes to a file. ## Recommended Apply models From 952d13b22acf9217be032f22f818bc1eedc95df1 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 13 May 2025 10:00:10 -0700 Subject: [PATCH 003/182] Update docs/docs/troubleshooting.mdx --- docs/docs/troubleshooting.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/troubleshooting.mdx b/docs/docs/troubleshooting.mdx index dcb619f76..b6df0dd22 100644 --- a/docs/docs/troubleshooting.mdx +++ b/docs/docs/troubleshooting.mdx @@ -162,7 +162,7 @@ Most Continue features will work normally, including autocomplete and chat. Howe For more details about this requirement, see the [LanceDB issue #2195](https://github.com/lancedb/lance/issues/2195). -### Resetting the entire plugin +### How do I reset the state of the extension? In cases when you like to clean reset the plugin, you would need to delete the `~/.continue` directory (or `%USERPROFILE%\.continue` on Windows). This will remove all your local settings, sessions, and other customizations. After this you may want to reinstall the plugin. From 7c4cd8313aa2f52a2b49445d6f1dc0e644046cbf Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 13 May 2025 10:02:09 -0700 Subject: [PATCH 004/182] Update docs/docs/troubleshooting.mdx --- docs/docs/troubleshooting.mdx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/docs/troubleshooting.mdx b/docs/docs/troubleshooting.mdx index b6df0dd22..f6836e78c 100644 --- a/docs/docs/troubleshooting.mdx +++ b/docs/docs/troubleshooting.mdx @@ -164,7 +164,9 @@ For more details about this requirement, see the [LanceDB issue #2195](https://g ### How do I reset the state of the extension? -In cases when you like to clean reset the plugin, you would need to delete the `~/.continue` directory (or `%USERPROFILE%\.continue` on Windows). This will remove all your local settings, sessions, and other customizations. After this you may want to reinstall the plugin. +Continue stores it's data in the `~/.continue` directory (%USERPROFILE%\.continue` on Windows). + +If you'd like to perform a clean reset of the extension, including removing all configuration files, indices, etc, you can remove this directory, uninstall, and then reinstall. ## Still having trouble? From 8d8cf3644e41d8b4d095cc4a4197112f65c0cbec Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 29 May 2025 13:48:47 -0700 Subject: [PATCH 005/182] fix apply cancellation and make slash commands cancelable --- core/commands/index.ts | 3 ++- core/commands/slash/commit.ts | 4 ++-- core/commands/slash/draftIssue.ts | 4 ++-- core/commands/slash/mcp.ts | 2 +- core/commands/slash/onboard.ts | 4 ++-- core/commands/slash/review.ts | 4 ++-- core/edit/lazy/applyCodeBlock.ts | 9 ++++++++- core/edit/lazy/replace.ts | 12 ++++++++---- core/edit/lazy/streamLazyApply.ts | 7 +++---- core/index.d.ts | 3 ++- core/llm/streamChat.ts | 1 + core/promptFiles/v1/slashCommandFromPromptFile.ts | 2 +- extensions/vscode/src/apply/ApplyManager.ts | 8 +++++++- 13 files changed, 41 insertions(+), 22 deletions(-) diff --git a/core/commands/index.ts b/core/commands/index.ts index 3037d7ef7..d87a3536f 100644 --- a/core/commands/index.ts +++ b/core/commands/index.ts @@ -25,6 +25,7 @@ export function slashFromCustomCommand( config, selectedCode, fetch, + abortController, }) { // Render prompt template let renderedPrompt: string; @@ -63,7 +64,7 @@ export function slashFromCustomCommand( for await (const chunk of llm.streamChat( messages, - new AbortController().signal, + abortController.signal, completionOptions, )) { yield renderChatMessage(chunk); diff --git a/core/commands/slash/commit.ts b/core/commands/slash/commit.ts index 8fc1ae27b..55499b583 100644 --- a/core/commands/slash/commit.ts +++ b/core/commands/slash/commit.ts @@ -4,7 +4,7 @@ import { renderChatMessage } from "../../util/messageContent.js"; const CommitMessageCommand: SlashCommand = { name: "commit", description: "Generate a commit message for current changes", - run: async function* ({ ide, llm, params }) { + run: async function* ({ ide, llm, params, abortController }) { const includeUnstaged = params?.includeUnstaged ?? false; const diff = await ide.getDiff(includeUnstaged); @@ -16,7 +16,7 @@ const CommitMessageCommand: SlashCommand = { const prompt = `${diff.join("\n")}\n\nGenerate a commit message for the above set of changes. First, give a single sentence, no more than 80 characters. Then, after 2 line breaks, give a list of no more than 5 short bullet points, each no more than 40 characters. Output nothing except for the commit message, and don't surround it in quotes.`; for await (const chunk of llm.streamChat( [{ role: "user", content: prompt }], - new AbortController().signal, + abortController.signal, )) { yield renderChatMessage(chunk); } diff --git a/core/commands/slash/draftIssue.ts b/core/commands/slash/draftIssue.ts index 637013476..fba5d4cd3 100644 --- a/core/commands/slash/draftIssue.ts +++ b/core/commands/slash/draftIssue.ts @@ -24,7 +24,7 @@ Body:\n\n`; const DraftIssueCommand: SlashCommand = { name: "issue", description: "Draft a GitHub issue", - run: async function* ({ input, llm, history, params }) { + run: async function* ({ input, llm, history, params, abortController }) { if (params?.repositoryUrl === undefined) { yield "This command requires a repository URL to be set in the config file."; return; @@ -46,7 +46,7 @@ const DraftIssueCommand: SlashCommand = { for await (const chunk of llm.streamChat( messages, - new AbortController().signal, + abortController.signal, )) { body += chunk.content; yield renderChatMessage(chunk); diff --git a/core/commands/slash/mcp.ts b/core/commands/slash/mcp.ts index 84df38989..89af5c5c2 100644 --- a/core/commands/slash/mcp.ts +++ b/core/commands/slash/mcp.ts @@ -60,7 +60,7 @@ export function constructMcpSlashCommand( for await (const chunk of context.llm.streamChat( messages, - new AbortController().signal, + context.abortController.signal, context.completionOptions, )) { yield renderChatMessage(chunk); diff --git a/core/commands/slash/onboard.ts b/core/commands/slash/onboard.ts index b53c8d3a9..545b75cc2 100644 --- a/core/commands/slash/onboard.ts +++ b/core/commands/slash/onboard.ts @@ -41,7 +41,7 @@ const MAX_EXPLORE_DEPTH = 2; const OnboardSlashCommand: SlashCommand = { name: "onboard", description: "Familiarize yourself with the codebase", - run: async function* ({ llm, ide }) { + run: async function* ({ llm, ide, abortController }) { const [workspaceDir] = await ide.getWorkspaceDirs(); const context = await gatherProjectContext(workspaceDir, ide); @@ -49,7 +49,7 @@ const OnboardSlashCommand: SlashCommand = { for await (const chunk of llm.streamChat( [{ role: "user", content: prompt }], - new AbortController().signal, + abortController.signal, )) { yield renderChatMessage(chunk); } diff --git a/core/commands/slash/review.ts b/core/commands/slash/review.ts index a3a2be6a7..6190f5499 100644 --- a/core/commands/slash/review.ts +++ b/core/commands/slash/review.ts @@ -38,14 +38,14 @@ function getLastUserHistory(history: ChatMessage[]): string { const ReviewMessageCommand: SlashCommand = { name: "review", description: "Review code and give feedback", - run: async function* ({ llm, history }) { + run: async function* ({ llm, history, abortController }) { const reviewText = getLastUserHistory(history).replace("\\review", ""); const content = `${prompt} \r\n ${reviewText}`; for await (const chunk of llm.streamChat( [{ role: "user", content: content }], - new AbortController().signal, + abortController.signal, )) { yield renderChatMessage(chunk); } diff --git a/core/edit/lazy/applyCodeBlock.ts b/core/edit/lazy/applyCodeBlock.ts index 8ca9a8154..b58b9d4ec 100644 --- a/core/edit/lazy/applyCodeBlock.ts +++ b/core/edit/lazy/applyCodeBlock.ts @@ -16,6 +16,7 @@ export async function applyCodeBlock( newLazyFile: string, filename: string, llm: ILLM, + abortController: AbortController, ): Promise<{ isInstantApply: boolean; diffLinesGenerator: AsyncGenerator; @@ -51,6 +52,12 @@ export async function applyCodeBlock( return { isInstantApply: false, - diffLinesGenerator: streamLazyApply(oldFile, filename, newLazyFile, llm), + diffLinesGenerator: streamLazyApply( + oldFile, + filename, + newLazyFile, + llm, + abortController, + ), }; } diff --git a/core/edit/lazy/replace.ts b/core/edit/lazy/replace.ts index 26e174c17..1a5ba704d 100644 --- a/core/edit/lazy/replace.ts +++ b/core/edit/lazy/replace.ts @@ -59,6 +59,7 @@ export async function* getReplacementWithLlm( linesBefore: string[], linesAfter: string[], llm: ILLM, + abortController: AbortController, ): AsyncGenerator { const userPrompt = dedent` ORIGINAL CODE: @@ -83,10 +84,13 @@ export async function* getReplacementWithLlm( \`\`\` `; - const completion = await llm.streamChat([ - { role: "user", content: userPrompt }, - { role: "assistant", content: assistantPrompt }, - ], new AbortController().signal); + const completion = await llm.streamChat( + [ + { role: "user", content: userPrompt }, + { role: "assistant", content: assistantPrompt }, + ], + abortController.signal, + ); let lines = streamLines(completion); lines = filterLeadingNewline(lines); diff --git a/core/edit/lazy/streamLazyApply.ts b/core/edit/lazy/streamLazyApply.ts index ce7af0ef7..f8ec0905c 100644 --- a/core/edit/lazy/streamLazyApply.ts +++ b/core/edit/lazy/streamLazyApply.ts @@ -16,6 +16,7 @@ export async function* streamLazyApply( filename: string, newCode: string, llm: ILLM, + abortController: AbortController, ): AsyncGenerator { const promptFactory = lazyApplyPromptForModel(llm.model, llm.providerName); if (!promptFactory) { @@ -23,10 +24,7 @@ export async function* streamLazyApply( } const promptMessages = promptFactory(oldCode, filename, newCode); - const lazyCompletion = llm.streamChat( - promptMessages, - new AbortController().signal, - ); + const lazyCompletion = llm.streamChat(promptMessages, abortController.signal); // Do find and replace over the lazy edit response async function* replacementFunction( @@ -39,6 +37,7 @@ export async function* streamLazyApply( linesBefore, linesAfter, llm, + abortController, )) { yield line; } diff --git a/core/index.d.ts b/core/index.d.ts index 794c03ce0..ffbd84d1b 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -836,6 +836,7 @@ export interface ContinueSDK { config: ContinueConfig; fetch: FetchFunction; completionOptions?: LLMFullCompletionOptions; + abortController: AbortController; } export interface SlashCommand { @@ -1141,7 +1142,7 @@ export interface StreamableHTTPOptions { requestOptions?: RequestOptions; } -export type TransportOptions = +export type TransportOptions = | StdioOptions | WebSocketOptions | SSEOptions diff --git a/core/llm/streamChat.ts b/core/llm/streamChat.ts index c899e437f..99e1dad94 100644 --- a/core/llm/streamChat.ts +++ b/core/llm/streamChat.ts @@ -84,6 +84,7 @@ export async function* llmStreamChat( config.requestOptions, ), completionOptions, + abortController, }); let next = await gen.next(); while (!next.done) { diff --git a/core/promptFiles/v1/slashCommandFromPromptFile.ts b/core/promptFiles/v1/slashCommandFromPromptFile.ts index 7f478e623..9b5cf0c34 100644 --- a/core/promptFiles/v1/slashCommandFromPromptFile.ts +++ b/core/promptFiles/v1/slashCommandFromPromptFile.ts @@ -98,7 +98,7 @@ export function slashCommandFromPromptFileV1( for await (const chunk of context.llm.streamChat( messages, - new AbortController().signal, + context.abortController.signal, context.completionOptions, )) { yield renderChatMessage(chunk); diff --git a/extensions/vscode/src/apply/ApplyManager.ts b/extensions/vscode/src/apply/ApplyManager.ts index df5791335..d16bc433c 100644 --- a/extensions/vscode/src/apply/ApplyManager.ts +++ b/extensions/vscode/src/apply/ApplyManager.ts @@ -3,6 +3,7 @@ import { applyCodeBlock } from "core/edit/lazy/applyCodeBlock"; import { getUriPathBasename } from "core/util/uri"; import * as vscode from "vscode"; +import { StreamAbortManager } from "core/util/abortManager"; import { VerticalDiffManager } from "../diff/vertical/manager"; import { VsCodeIde } from "../VsCodeIde"; import { VsCodeWebviewProtocol } from "../webviewProtocol"; @@ -116,11 +117,16 @@ export class ApplyManager { return; } + const fileUri = editor.document.uri.toString(); + const abortManager = StreamAbortManager.getInstance(); + const abortController = abortManager.get(fileUri); + const { isInstantApply, diffLinesGenerator } = await applyCodeBlock( editor.document.getText(), text, - getUriPathBasename(editor.document.uri.toString()), + getUriPathBasename(fileUri), llm, + abortController, ); if (isInstantApply) { From a1dc1f8aa249a1678d0f2b611a3f6f87ad2f695d Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 29 May 2025 16:04:35 -0700 Subject: [PATCH 006/182] change to reject diffs approach rather than cancel apply approach --- core/core.ts | 13 ++-- .../applyAbortManager.ts} | 12 ++-- core/edit/recursiveStream.ts | 1 + core/edit/streamDiffLines.ts | 7 +- core/index.d.ts | 2 +- core/llm/utils/extractPathsFromCodeBlocks.ts | 2 - .../continueintellijextension/types.kt | 2 +- extensions/vscode/package-lock.json | 6 +- extensions/vscode/src/apply/ApplyManager.ts | 4 +- extensions/vscode/src/commands.ts | 67 +++---------------- extensions/vscode/src/diff/processDiff.ts | 52 ++++++++++++++ .../vscode/src/diff/vertical/manager.ts | 10 ++- .../Lump/LumpToolbar/IsApplyingToolbar.tsx | 8 ++- gui/src/pages/gui/Chat.tsx | 2 +- .../thunks/streamResponseAfterToolCall.ts | 12 ++-- 15 files changed, 111 insertions(+), 89 deletions(-) rename core/{util/abortManager.ts => edit/applyAbortManager.ts} (70%) create mode 100644 extensions/vscode/src/diff/processDiff.ts diff --git a/core/core.ts b/core/core.ts index 6b5f9814e..bd4d8b48b 100644 --- a/core/core.ts +++ b/core/core.ts @@ -53,6 +53,7 @@ import { } from "./config/onboarding"; import { createNewWorkspaceBlockFile } from "./config/workspace/workspaceBlocks"; import { MCPManagerSingleton } from "./context/mcp/MCPManagerSingleton"; +import { ApplyAbortManager } from "./edit/applyAbortManager"; import { streamDiffLines } from "./edit/streamDiffLines"; import { shouldIgnore } from "./indexing/shouldIgnore"; import { walkDirCache } from "./indexing/walkDir"; @@ -61,7 +62,6 @@ import { LLMLogger } from "./llm/logger"; import { llmStreamChat } from "./llm/streamChat"; import type { FromCoreProtocol, ToCoreProtocol } from "./protocol"; import type { IMessenger, Message } from "./protocol/messenger"; -import { StreamAbortManager } from "./util/abortManager"; export class Core { configHandler: ConfigHandler; @@ -509,6 +509,11 @@ export class Core { throw new Error("No model selected"); } + const abortManager = ApplyAbortManager.getInstance(); + const abortController = abortManager.get( + data.fileUri ?? "current-file-stream", + ); // not super important since currently cancelling apply will cancel all streams it's one file at a time + return streamDiffLines({ highlighted: data.highlighted, prefix: data.prefix, @@ -522,13 +527,13 @@ export class Core { language: data.language, onlyOneInsertion: false, overridePrompt: undefined, - abortControllerId: data.fileUri ?? "current-file-stream", // not super important since currently cancelling apply will cancel all streams it's one file at a time + abortController, }); }); on("cancelApply", async (msg) => { - const abortManager = StreamAbortManager.getInstance(); - abortManager.clear(); + const abortManager = ApplyAbortManager.getInstance(); + abortManager.clear(); // for now abort all streams }); on("completeOnboarding", this.handleCompleteOnboarding.bind(this)); diff --git a/core/util/abortManager.ts b/core/edit/applyAbortManager.ts similarity index 70% rename from core/util/abortManager.ts rename to core/edit/applyAbortManager.ts index e7de53bca..e811b5d4b 100644 --- a/core/util/abortManager.ts +++ b/core/edit/applyAbortManager.ts @@ -1,16 +1,16 @@ -export class StreamAbortManager { - private static instance: StreamAbortManager; +export class ApplyAbortManager { + private static instance: ApplyAbortManager; private controllers: Map; private constructor() { this.controllers = new Map(); } - public static getInstance(): StreamAbortManager { - if (!StreamAbortManager.instance) { - StreamAbortManager.instance = new StreamAbortManager(); + public static getInstance(): ApplyAbortManager { + if (!ApplyAbortManager.instance) { + ApplyAbortManager.instance = new ApplyAbortManager(); } - return StreamAbortManager.instance; + return ApplyAbortManager.instance; } public get(id: string): AbortController { diff --git a/core/edit/recursiveStream.ts b/core/edit/recursiveStream.ts index 004563cdb..5a6d4b39b 100644 --- a/core/edit/recursiveStream.ts +++ b/core/edit/recursiveStream.ts @@ -68,6 +68,7 @@ export async function* recursiveStream( }); for await (const chunk of generator) { + console.log(chunk); yield chunk; const rendered = renderChatMessage(chunk); buffer += rendered; diff --git a/core/edit/streamDiffLines.ts b/core/edit/streamDiffLines.ts index 096b31d7d..f64448f36 100644 --- a/core/edit/streamDiffLines.ts +++ b/core/edit/streamDiffLines.ts @@ -20,7 +20,6 @@ import { streamDiff } from "../diff/streamDiff"; import { streamLines } from "../diff/util"; import { getSystemMessageWithRules } from "../llm/rules/getSystemMessageWithRules"; import { gptEditPrompt } from "../llm/templates/edit"; -import { StreamAbortManager } from "../util/abortManager"; import { findLast } from "../util/findLast"; import { Telemetry } from "../util/posthog"; import { recursiveStream } from "./recursiveStream"; @@ -64,7 +63,7 @@ export async function* streamDiffLines({ highlighted, suffix, llm, - abortControllerId, + abortController, input, language, onlyOneInsertion, @@ -75,15 +74,13 @@ export async function* streamDiffLines({ highlighted: string; suffix: string; llm: ILLM; - abortControllerId: string; + abortController: AbortController; input: string; language: string | undefined; onlyOneInsertion: boolean; overridePrompt: ChatMessage[] | undefined; rulesToInclude: RuleWithSource[] | undefined; }): AsyncGenerator { - const abortManager = StreamAbortManager.getInstance(); - const abortController = abortManager.get(abortControllerId); void Telemetry.capture( "inlineEdit", { diff --git a/core/index.d.ts b/core/index.d.ts index ffbd84d1b..bbd4e385c 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1263,7 +1263,7 @@ export interface HighlightedCodePayload { } export interface AcceptOrRejectDiffPayload { - filepath: string; + filepath?: string; streamId?: string; } diff --git a/core/llm/utils/extractPathsFromCodeBlocks.ts b/core/llm/utils/extractPathsFromCodeBlocks.ts index 00f723c7a..99f2764b2 100644 --- a/core/llm/utils/extractPathsFromCodeBlocks.ts +++ b/core/llm/utils/extractPathsFromCodeBlocks.ts @@ -2,8 +2,6 @@ * Extracts file paths from markdown code blocks */ export function extractPathsFromCodeBlocks(content: string): string[] { - console.log("CONTENT", content); - const paths: string[] = []; // Match code block opening patterns: diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/types.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/types.kt index 86862a096..56fe76777 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/types.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/types.kt @@ -249,7 +249,7 @@ data class StreamDiffLinesPayload( ) data class AcceptOrRejectDiffPayload( - val filepath: String, + val filepath: String? = null, val streamId: String? = null ) diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 5634027da..f2db4b382 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "1.1.39", + "version": "1.1.40", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "1.1.39", + "version": "1.1.40", "license": "Apache-2.0", "dependencies": { "@continuedev/config-types": "^1.0.14", @@ -110,7 +110,7 @@ "@continuedev/fetch": "^1.0.10", "@continuedev/llm-info": "^1.0.8", "@continuedev/openai-adapters": "^1.0.25", - "@modelcontextprotocol/sdk": "^1.5.0", + "@modelcontextprotocol/sdk": "^1.12.0", "@mozilla/readability": "^0.5.0", "@octokit/rest": "^20.1.1", "@typescript-eslint/eslint-plugin": "^7.8.0", diff --git a/extensions/vscode/src/apply/ApplyManager.ts b/extensions/vscode/src/apply/ApplyManager.ts index d16bc433c..fb446e174 100644 --- a/extensions/vscode/src/apply/ApplyManager.ts +++ b/extensions/vscode/src/apply/ApplyManager.ts @@ -3,7 +3,7 @@ import { applyCodeBlock } from "core/edit/lazy/applyCodeBlock"; import { getUriPathBasename } from "core/util/uri"; import * as vscode from "vscode"; -import { StreamAbortManager } from "core/util/abortManager"; +import { ApplyAbortManager } from "core/edit/applyAbortManager"; import { VerticalDiffManager } from "../diff/vertical/manager"; import { VsCodeIde } from "../VsCodeIde"; import { VsCodeWebviewProtocol } from "../webviewProtocol"; @@ -118,7 +118,7 @@ export class ApplyManager { } const fileUri = editor.document.uri.toString(); - const abortManager = StreamAbortManager.getInstance(); + const abortManager = ApplyAbortManager.getInstance(); const abortController = abortManager.get(fileUri); const { isInstantApply, diffLinesGenerator } = await applyCodeBlock( diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index 84885f757..88c25bc07 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -35,6 +35,7 @@ import { } from "./autocomplete/statusBar"; import { ContinueConsoleWebviewViewProvider } from "./ContinueConsoleWebviewViewProvider"; import { ContinueGUIWebviewViewProvider } from "./ContinueGUIWebviewViewProvider"; +import { processDiff } from "./diff/processDiff"; import { VerticalDiffManager } from "./diff/vertical/manager"; import EditDecorationManager from "./quickEdit/EditDecorationManager"; import { QuickEdit, QuickEditShowParams } from "./quickEdit/QuickEditQuickPick"; @@ -93,56 +94,6 @@ function hideGUI() { } } -async function processDiff( - action: "accept" | "reject", - sidebar: ContinueGUIWebviewViewProvider, - ide: VsCodeIde, - core: Core, - verticalDiffManager: VerticalDiffManager, - newFileUri?: string, - streamId?: string, - toolCallId?: string, -) { - captureCommandTelemetry(`${action}Diff`); - - const currentFile = await ide.getCurrentFile(); - - let newOrCurrentUri = newFileUri; - if (!newOrCurrentUri) { - newOrCurrentUri = currentFile?.path; - } - if (!newOrCurrentUri) { - console.warn( - `No file provided or current file open while attempting to resolve diff`, - ); - return; - } - - await ide.openFile(newOrCurrentUri); - - // Clear vertical diffs depending on action - verticalDiffManager.clearForfileUri(newOrCurrentUri, action === "accept"); - if (action === "reject") { - core.invoke("cancelApply", undefined); - } - - if (streamId) { - const fileContent = await ide.readFile(newOrCurrentUri); - - await sidebar.webviewProtocol.request("updateApplyState", { - fileContent, - filepath: newOrCurrentUri, - streamId, - status: "closed", - numDiffs: 0, - toolCallId, - }); - } - - // Save the file - await ide.saveFile(newOrCurrentUri); -} - function waitForSidebarReady( sidebar: ContinueGUIWebviewViewProvider, timeout: number, @@ -235,8 +186,9 @@ const getCommandsMap: ( } return { - "continue.acceptDiff": async (newFileUri?: string, streamId?: string) => - processDiff( + "continue.acceptDiff": async (newFileUri?: string, streamId?: string) => { + captureCommandTelemetry("acceptDiff"); + void processDiff( "accept", sidebar, ide, @@ -244,10 +196,12 @@ const getCommandsMap: ( verticalDiffManager, newFileUri, streamId, - ), + ); + }, - "continue.rejectDiff": async (newFileUri?: string, streamId?: string) => - processDiff( + "continue.rejectDiff": async (newFileUri?: string, streamId?: string) => { + captureCommandTelemetry("rejectDiff"); + void processDiff( "reject", sidebar, ide, @@ -255,7 +209,8 @@ const getCommandsMap: ( verticalDiffManager, newFileUri, streamId, - ), + ); + }, "continue.acceptVerticalDiffBlock": (fileUri?: string, index?: number) => { captureCommandTelemetry("acceptVerticalDiffBlock"); verticalDiffManager.acceptRejectVerticalDiffBlock(true, fileUri, index); diff --git a/extensions/vscode/src/diff/processDiff.ts b/extensions/vscode/src/diff/processDiff.ts new file mode 100644 index 000000000..b78ea966c --- /dev/null +++ b/extensions/vscode/src/diff/processDiff.ts @@ -0,0 +1,52 @@ +import { Core } from "core/core"; +import { ContinueGUIWebviewViewProvider } from "../ContinueGUIWebviewViewProvider"; +import { VsCodeIde } from "../VsCodeIde"; +import { VerticalDiffManager } from "./vertical/manager"; + +export async function processDiff( + action: "accept" | "reject", + sidebar: ContinueGUIWebviewViewProvider, + ide: VsCodeIde, + core: Core, + verticalDiffManager: VerticalDiffManager, + newFileUri?: string, + streamId?: string, + toolCallId?: string, +) { + let newOrCurrentUri = newFileUri; + if (!newOrCurrentUri) { + const currentFile = await ide.getCurrentFile(); + newOrCurrentUri = currentFile?.path; + } + if (!newOrCurrentUri) { + console.warn( + `No file provided or current file open while attempting to resolve diff`, + ); + return; + } + + await ide.openFile(newOrCurrentUri); + + // Clear vertical diffs depending on action + verticalDiffManager.clearForfileUri(newOrCurrentUri, action === "accept"); + if (action === "reject") { + // this is so that IDE reject diff command can also cancel apply + core.invoke("cancelApply", undefined); + } + + if (streamId) { + const fileContent = await ide.readFile(newOrCurrentUri); + + await sidebar.webviewProtocol.request("updateApplyState", { + fileContent, + filepath: newOrCurrentUri, + streamId, + status: "closed", + numDiffs: 0, + toolCallId, + }); + } + + // Save the file + await ide.saveFile(newOrCurrentUri); +} diff --git a/extensions/vscode/src/diff/vertical/manager.ts b/extensions/vscode/src/diff/vertical/manager.ts index 104db10c6..aca644c3a 100644 --- a/extensions/vscode/src/diff/vertical/manager.ts +++ b/extensions/vscode/src/diff/vertical/manager.ts @@ -10,6 +10,7 @@ import EditDecorationManager from "../../quickEdit/EditDecorationManager"; import { handleLLMError } from "../../util/errorHandling"; import { VsCodeWebviewProtocol } from "../../webviewProtocol"; +import { ApplyAbortManager } from "core/edit/applyAbortManager"; import { VerticalDiffHandler, VerticalDiffHandlerOptions } from "./handler"; export interface VerticalDiffCodeLens { @@ -437,6 +438,9 @@ export class VerticalDiffManager { this.editDecorationManager.clear(); + const abortManager = ApplyAbortManager.getInstance(); + const abortController = abortManager.get(fileUri); + try { const streamedLines: string[] = []; @@ -451,7 +455,7 @@ export class VerticalDiffManager { language: getMarkdownLanguageTagForFile(fileUri), onlyOneInsertion: !!onlyOneInsertion, overridePrompt, - abortControllerId: fileUri, + abortController, }); for await (const line of stream) { @@ -467,6 +471,10 @@ export class VerticalDiffManager { // enable a listener for user edits to file while diff is open this.enableDocumentChangeListener(); + if (abortController.signal.aborted) { + vscode.commands.executeCommand("continue.rejectDiff"); + } + return `${prefix}${streamedLines.join("\n")}${suffix}`; } catch (e) { this.disableDocumentChangeListener(); diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/IsApplyingToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/IsApplyingToolbar.tsx index 0faf43e0e..f4840088d 100644 --- a/gui/src/components/mainInput/Lump/LumpToolbar/IsApplyingToolbar.tsx +++ b/gui/src/components/mainInput/Lump/LumpToolbar/IsApplyingToolbar.tsx @@ -1,12 +1,14 @@ import { useContext } from "react"; import { IdeMessengerContext } from "../../../../context/IdeMessenger"; +import { useAppDispatch } from "../../../../redux/hooks"; +import { cancelStream } from "../../../../redux/thunks"; import { getAltKeyLabel, getMetaKeyLabel } from "../../../../util"; import { Container, StopButton } from "./components"; import { GeneratingIndicator } from "./GeneratingIndicator"; export const IsApplyingToolbar = () => { const ideMessenger = useContext(IdeMessengerContext); - + const dispatch = useAppDispatch(); const jetbrains = window.location.protocol === "jb-api:"; return ( @@ -18,7 +20,9 @@ export const IsApplyingToolbar = () => { // Note that this will NOT stop generation but once apply is cancelled will show the Generating/cancel option // Apply is prioritized because it can be more catastrophic // Intentional to be more WYSIWYG for now - ideMessenger.post("cancelApply", undefined); + // Keyboard shortcut is handled in chat + dispatch(cancelStream()); + ideMessenger.post("rejectDiff", {}); }} > {/* JetBrains overrides cmd+backspace, so we have to use another shortcut */} diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index c3e8ac512..30088ab53 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -139,7 +139,7 @@ export function Chat() { !e.shiftKey ) { dispatch(cancelStream()); - ideMessenger.post("cancelApply", undefined); // just always cancel, if not in applying won't matter + ideMessenger.post("rejectDiff", {}); // just always cancel, if not in applying won't matter } }; window.addEventListener("keydown", listener); diff --git a/gui/src/redux/thunks/streamResponseAfterToolCall.ts b/gui/src/redux/thunks/streamResponseAfterToolCall.ts index 990723f7a..21d151562 100644 --- a/gui/src/redux/thunks/streamResponseAfterToolCall.ts +++ b/gui/src/redux/thunks/streamResponseAfterToolCall.ts @@ -35,7 +35,7 @@ export const streamResponseAfterToolCall = createAsyncThunk< const toolCallState = findToolCall(state.session.history, toolCallId); if (!toolCallState) { - throw new Error("Tool call not found"); + return; // in cases where edit tool is cancelled mid apply, this will be triggered } const toolOutput = toolCallState.output ?? []; @@ -65,12 +65,14 @@ export const streamResponseAfterToolCall = createAsyncThunk< dispatch(setActive()); - const updatedHistory = getState().session.history; - const messageMode = getState().session.mode + const messageMode = getState().session.mode; + + const baseChatOrAgentSystemMessage = getBaseSystemMessage( + selectedChatModel, + messageMode, + ); - const baseChatOrAgentSystemMessage = getBaseSystemMessage(selectedChatModel, messageMode) - const messages = constructMessages( messageMode, [...updatedHistory], From 2d3bdbe256871c219f7abfa252141a002691cd3f Mon Sep 17 00:00:00 2001 From: chezsmithy Date: Wed, 4 Jun 2025 22:23:39 -0700 Subject: [PATCH 007/182] refactor: :recycle: Updates to code to remove negative cases first (linting) --- .../implementations/runTerminalCommand.ts | 90 +++++++++---------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/core/tools/implementations/runTerminalCommand.ts b/core/tools/implementations/runTerminalCommand.ts index 785f4ee30..4f0596535 100644 --- a/core/tools/implementations/runTerminalCommand.ts +++ b/core/tools/implementations/runTerminalCommand.ts @@ -130,26 +130,7 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { return; } - if (!waitForCompletion) { - // Already resolved, just update the UI with final output - if (extras.onPartialOutput) { - const status = - code === 0 || !code - ? "\nBackground command completed" - : `\nBackground command failed with exit code ${code}`; - extras.onPartialOutput({ - toolCallId, - contextItems: [ - { - name: "Terminal", - description: "Terminal command output", - content: terminalOutput, - status: status, - }, - ], - }); - } - } else { + if (waitForCompletion) { // Normal completion, resolve now if (code === 0) { const status = "Command completed"; @@ -172,6 +153,25 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { }, ]); } + } else { + // Already resolved, just update the UI with final output + if (extras.onPartialOutput) { + const status = + code === 0 || !code + ? "\nBackground command completed" + : `\nBackground command failed with exit code ${code}`; + extras.onPartialOutput({ + toolCallId, + contextItems: [ + { + name: "Terminal", + description: "Terminal command output", + content: terminalOutput, + status: status, + }, + ], + }); + } } }); @@ -197,7 +197,31 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { const workspaceDirs = await extras.ide.getWorkspaceDirs(); const cwd = fileURLToPath(workspaceDirs[0]); - if (!waitForCompletion) { + if (waitForCompletion) { + // Standard execution, waiting for completion + try { + const output = await asyncExec(args.command, { cwd }); + const status = "Command completed"; + return [ + { + name: "Terminal", + description: "Terminal command output", + content: output.stdout ?? "", + status: status, + }, + ]; + } catch (error: any) { + const status = `Command failed with: ${error.message || error.toString()}`; + return [ + { + name: "Terminal", + description: "Terminal command output", + content: error.stderr ?? error.toString(), + status: status, + }, + ]; + } + } else { // For non-streaming but also not waiting for completion, use spawn // but don't attach any listeners other than error try { @@ -246,30 +270,6 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { }, ]; } - } else { - // Standard execution, waiting for completion - try { - const output = await asyncExec(args.command, { cwd }); - const status = "Command completed"; - return [ - { - name: "Terminal", - description: "Terminal command output", - content: output.stdout ?? "", - status: status, - }, - ]; - } catch (error: any) { - const status = `Command failed with: ${error.message || error.toString()}`; - return [ - { - name: "Terminal", - description: "Terminal command output", - content: error.stderr ?? error.toString(), - status: status, - }, - ]; - } } } } From 0444e47e6d4f9d31578fad133d3c67e6b0f0704b Mon Sep 17 00:00:00 2001 From: "yong.zhang" Date: Thu, 5 Jun 2025 15:07:16 +0800 Subject: [PATCH 008/182] fix intellij extension create file failed --- .../editor/EditorUtils.kt | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/EditorUtils.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/EditorUtils.kt index 857c0104f..2995f91e5 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/EditorUtils.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/EditorUtils.kt @@ -2,6 +2,7 @@ package com.github.continuedev.continueintellijextension.editor import com.github.continuedev.continueintellijextension.utils.toUriOrNull import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.command.WriteCommandAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.SelectionModel @@ -14,6 +15,8 @@ import com.intellij.openapi.util.TextRange import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.ui.JBColor import com.intellij.openapi.editor.ScrollType +import com.intellij.openapi.vfs.LocalFileSystem +import java.io.File /** * Utility class for working with Editor instances. @@ -155,10 +158,23 @@ class EditorUtils(val editor: Editor) { */ fun getOrOpenEditor(project: Project, filepath: String?): EditorUtils? { if (!filepath.isNullOrEmpty()) { - val virtualFile = VirtualFileManager.getInstance().findFileByUrl(filepath) + var virtualFile = VirtualFileManager.getInstance().findFileByUrl(filepath) + if (virtualFile == null) { + // file not exists and create + val ioFile = File(filepath.replace("file:///", "")) + if (!ioFile.exists()) { + ioFile.parentFile?.mkdirs() + ioFile.createNewFile() + } + // IntelliJ refresh VirtualFile + virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ioFile) + } + if (virtualFile != null) { ApplicationManager.getApplication().invokeAndWait { - FileEditorManager.getInstance(project).openFile(virtualFile, true).first() + runWriteAction { + FileEditorManager.getInstance(project).openFile(virtualFile, true) + } } } } From e83290bd3a921929052b0c0c91751800e7e9fd2c Mon Sep 17 00:00:00 2001 From: chezsmithy Date: Thu, 5 Jun 2025 01:13:26 -0700 Subject: [PATCH 009/182] feat: :sparkles: Give the terminal color and ansi escape rendering --- .../implementations/runTerminalCommand.ts | 22 +- gui/package-lock.json | 16 +- gui/package.json | 2 + gui/src/components/ansiTerminal/Ansi.tsx | 279 ++++++++++++++++++ .../gui/ToolCallDiv/RunTerminalCommand.tsx | 64 ++-- 5 files changed, 358 insertions(+), 25 deletions(-) create mode 100644 gui/src/components/ansiTerminal/Ansi.tsx diff --git a/core/tools/implementations/runTerminalCommand.ts b/core/tools/implementations/runTerminalCommand.ts index 4f0596535..3d3ac85cb 100644 --- a/core/tools/implementations/runTerminalCommand.ts +++ b/core/tools/implementations/runTerminalCommand.ts @@ -10,6 +10,16 @@ import { const asyncExec = util.promisify(childProcess.exec); +// Add color-supporting environment variables +const getColorEnv = () => ({ + ...process.env, + FORCE_COLOR: "1", + COLORTERM: "truecolor", + TERM: "xterm-256color", + CLICOLOR: "1", + CLICOLOR_FORCE: "1", +}); + const ENABLED_FOR_REMOTES = [ "", "local", @@ -56,10 +66,11 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { } } - // Use spawn instead of exec to get streaming output + // Use spawn with color environment const childProc = childProcess.spawn(args.command, { cwd, shell: true, + env: getColorEnv(), // Add enhanced environment for colors }); childProc.stdout?.on("data", (data) => { @@ -200,7 +211,11 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { if (waitForCompletion) { // Standard execution, waiting for completion try { - const output = await asyncExec(args.command, { cwd }); + // Use color environment for exec as well + const output = await asyncExec(args.command, { + cwd, + env: getColorEnv(), + }); const status = "Command completed"; return [ { @@ -225,10 +240,11 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { // For non-streaming but also not waiting for completion, use spawn // but don't attach any listeners other than error try { - // Use spawn instead of exec but don't wait + // Use spawn with color environment const childProc = childProcess.spawn(args.command, { cwd, shell: true, + env: getColorEnv(), // Add color environment // Detach the process so it's not tied to the parent detached: true, // Redirect to /dev/null equivalent (works cross-platform) diff --git a/gui/package-lock.json b/gui/package-lock.json index 020586519..96d91cee6 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -25,10 +25,12 @@ "@tiptap/starter-kit": "^2.1.13", "@tiptap/suggestion": "^2.1.13", "@types/uuid": "^10.0.0", + "anser": "^2.3.2", "clsx": "^2.1.1", "core": "file:../core", "dompurify": "^3.0.6", "downshift": "^7.6.0", + "escape-carriage": "^1.3.1", "lodash": "^4.17.21", "lowlight": "^3.3.0", "minisearch": "^7.0.2", @@ -111,7 +113,7 @@ "@aws-sdk/credential-providers": "^3.778.0", "@continuedev/config-types": "^1.0.13", "@continuedev/config-yaml": "file:../packages/config-yaml", - "@continuedev/fetch": "^1.0.10", + "@continuedev/fetch": "^1.0.13", "@continuedev/llm-info": "^1.0.8", "@continuedev/openai-adapters": "^1.0.25", "@modelcontextprotocol/sdk": "^1.12.0", @@ -3727,6 +3729,12 @@ "url": "https://github.com/sponsors/epoberezkin" } }, + "node_modules/anser": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/anser/-/anser-2.3.2.tgz", + "integrity": "sha512-PMqBCBvrOVDRqLGooQb+z+t1Q0PiPyurUQeZRR5uHBOVZcW8B04KMmnT12USnhpNX2wCPagWzLVppQMUG3u0Dw==", + "license": "MIT" + }, "node_modules/ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", @@ -5190,6 +5198,12 @@ "node": ">=6" } }, + "node_modules/escape-carriage": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/escape-carriage/-/escape-carriage-1.3.1.tgz", + "integrity": "sha512-GwBr6yViW3ttx1kb7/Oh+gKQ1/TrhYwxKqVmg5gS+BK+Qe2KrOa/Vh7w3HPBvgGf0LfcDGoY9I6NHKoA5Hozhw==", + "license": "MIT" + }, "node_modules/escape-string-regexp": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", diff --git a/gui/package.json b/gui/package.json index de6da1959..1f137f19b 100644 --- a/gui/package.json +++ b/gui/package.json @@ -34,10 +34,12 @@ "@tiptap/starter-kit": "^2.1.13", "@tiptap/suggestion": "^2.1.13", "@types/uuid": "^10.0.0", + "anser": "^2.3.2", "clsx": "^2.1.1", "core": "file:../core", "dompurify": "^3.0.6", "downshift": "^7.6.0", + "escape-carriage": "^1.3.1", "lodash": "^4.17.21", "lowlight": "^3.3.0", "minisearch": "^7.0.2", diff --git a/gui/src/components/ansiTerminal/Ansi.tsx b/gui/src/components/ansiTerminal/Ansi.tsx new file mode 100644 index 000000000..35d4b0a43 --- /dev/null +++ b/gui/src/components/ansiTerminal/Ansi.tsx @@ -0,0 +1,279 @@ +import Anser, { AnserJsonEntry } from "anser"; +import { escapeCarriageReturn } from "escape-carriage"; +import * as React from "react"; +import styled from "styled-components"; +import { + defaultBorderRadius, + vscBackground, + vscEditorBackground, + vscForeground, +} from "../../components"; +import { getFontSize } from "../../util"; + +const AnsiSpan = styled.span<{ + bg?: string; + fg?: string; + decoration?: string; +}>` + ${({ bg }) => bg && `background-color: rgb(${bg});`} + ${({ fg }) => fg && `color: rgb(${fg});`} + ${({ decoration }) => { + switch (decoration) { + case "bold": + return "font-weight: bold;"; + case "dim": + return "opacity: 0.5;"; + case "italic": + return "font-style: italic;"; + case "hidden": + return "visibility: hidden;"; + case "strikethrough": + return "text-decoration: line-through;"; + case "underline": + return "text-decoration: underline;"; + case "blink": + return "text-decoration: blink;"; + default: + return ""; + } + }} +`; + +const AnsiLink = styled.a` + color: var(--vscode-textLink-foreground, #3794ff); + text-decoration: none; + &:hover { + text-decoration: underline; + } +`; + +// Using the same styled component structure as StyledMarkdown +const StyledAnsi = styled.div<{ + fontSize?: number; + whiteSpace: string; + bgColor: string; +}>` + pre { + white-space: ${(props) => props.whiteSpace}; + background-color: ${vscEditorBackground}; + border-radius: ${defaultBorderRadius}; + border: 1px solid + var(--vscode-editorWidget-border, rgba(127, 127, 127, 0.3)); + max-width: calc(100vw - 24px); + overflow-x: scroll; + overflow-y: hidden; + padding: 8px; + } + + code { + span.line:empty { + display: none; + } + word-wrap: break-word; + border-radius: ${defaultBorderRadius}; + background-color: ${vscEditorBackground}; + font-size: ${getFontSize() - 2}px; + font-family: var(--vscode-editor-font-family); + } + + code:not(pre > code) { + font-family: var(--vscode-editor-font-family); + color: var(--vscode-input-placeholderForeground); + } + + background-color: ${(props) => props.bgColor}; + font-family: + var(--vscode-font-family), + system-ui, + -apple-system, + BlinkMacSystemFont, + "Segoe UI", + Roboto, + Oxygen, + Ubuntu, + Cantarell, + "Open Sans", + "Helvetica Neue", + sans-serif; + font-size: ${(props) => props.fontSize || getFontSize()}px; + padding-left: 8px; + padding-right: 8px; + color: ${vscForeground}; + line-height: 1.5; + + > *:last-child { + margin-bottom: 0; + } +`; + +/** + * Converts ANSI strings into JSON output. + * @name ansiToJSON + * @function + * @param {String} input The input string. + * @param {boolean} use_classes If `true`, HTML classes will be appended + * to the HTML output. + * @return {Array} The parsed input. + */ +function ansiToJSON( + input: string, + use_classes: boolean = false, +): AnserJsonEntry[] { + input = escapeCarriageReturn(fixBackspace(input)); + return Anser.ansiToJson(input, { + json: true, + remove_empty: true, + use_classes, + }); +} + +/** + * Create a class string. + * @name createClass + * @function + * @param {AnserJsonEntry} bundle + * @return {String} class name(s) + */ +function createClass(bundle: AnserJsonEntry): string | null { + let classNames: string = ""; + + if (bundle.bg) { + classNames += `${bundle.bg}-bg `; + } + if (bundle.fg) { + classNames += `${bundle.fg}-fg `; + } + if (bundle.decoration) { + classNames += `ansi-${bundle.decoration} `; + } + + if (classNames === "") { + return null; + } + + classNames = classNames.substring(0, classNames.length - 1); + return classNames; +} + +/** + * Converts an Anser bundle into a React Node. + * @param linkify whether links should be converting into clickable anchor tags. + * @param useClasses should render the span with a class instead of style. + * @param bundle Anser output. + * @param key + */ + +function convertBundleIntoReact( + linkify: boolean, + useClasses: boolean, + bundle: AnserJsonEntry, + key: number, +): JSX.Element { + const className = useClasses ? createClass(bundle) : null; + // Convert bundle.decoration to string or undefined (not null) to match the prop type + const decorationProp = bundle.decoration + ? String(bundle.decoration) + : undefined; + + if (!linkify) { + return ( + + {bundle.content} + + ); + } + + const content: React.ReactNode[] = []; + const linkRegex = + /(\s|^)(https?:\/\/(?:www\.|(?!www))[^\s.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})/g; + + let index = 0; + let match: RegExpExecArray | null; + while ((match = linkRegex.exec(bundle.content)) !== null) { + const [, pre, url] = match; + + const startIndex = match.index + pre.length; + if (startIndex > index) { + content.push(bundle.content.substring(index, startIndex)); + } + + // Make sure the href we generate from the link is fully qualified. We assume http + // if it starts with a www because many sites don't support https + const href = url.startsWith("www.") ? `http://${url}` : url; + + content.push( + + {url} + , + ); + + index = linkRegex.lastIndex; + } + + if (index < bundle.content.length) { + content.push(bundle.content.substring(index)); + } + + return ( + + {content} + + ); +} + +declare interface Props { + children?: string; + linkify?: boolean; + className?: string; + useClasses?: boolean; +} + +export default function Ansi(props: Props): JSX.Element { + const { className, useClasses, children, linkify } = props; + + // Create the ANSI content + const ansiContent = ansiToJSON(children ?? "", useClasses ?? false).map( + (bundle, i) => + convertBundleIntoReact(linkify ?? false, useClasses ?? false, bundle, i), + ); + + return ( + +
+        {ansiContent}
+      
+
+ ); +} + +// This is copied from the Jupyter Classic source code +// notebook/static/base/js/utils.js to handle \b in a way +// that is **compatible with Jupyter classic**. One can +// argue that this behavior is questionable: +// https://stackoverflow.com/questions/55440152/multiple-b-doesnt-work-as-expected-in-jupyter# +function fixBackspace(txt: string) { + let tmp = txt; + do { + txt = tmp; + // Cancel out anything-but-newline followed by backspace + tmp = txt.replace(/[^\n]\x08/gm, ""); + } while (tmp.length < txt.length); + return txt; +} diff --git a/gui/src/pages/gui/ToolCallDiv/RunTerminalCommand.tsx b/gui/src/pages/gui/ToolCallDiv/RunTerminalCommand.tsx index c78ec3495..0b3bf1b9d 100644 --- a/gui/src/pages/gui/ToolCallDiv/RunTerminalCommand.tsx +++ b/gui/src/pages/gui/ToolCallDiv/RunTerminalCommand.tsx @@ -1,11 +1,10 @@ -import { AnyAction, ThunkDispatch } from "@reduxjs/toolkit"; import { ToolCallState } from "core"; -import { Fragment } from "react"; -import { useDispatch } from "react-redux"; import styled from "styled-components"; +import { vscForeground } from "../../../components"; +import Ansi from "../../../components/ansiTerminal/Ansi"; import StyledMarkdownPreview from "../../../components/StyledMarkdownPreview"; -import { moveTerminalProcessToBackground } from "../../../redux/thunks/moveTerminalProcessToBackground"; import { useAppDispatch } from "../../../redux/hooks"; +import { moveTerminalProcessToBackground } from "../../../redux/thunks/moveTerminalProcessToBackground"; interface RunTerminalCommandToolCallProps { command: string; @@ -15,13 +14,12 @@ interface RunTerminalCommandToolCallProps { const CommandStatus = styled.div` font-size: 12px; - color: #666; + color: var(--vscode-descriptionForeground, ${vscForeground}88); margin-top: 8px; - padding-left: 8px; - padding-right: 8px; - padding-bottom: 8px; display: flex; align-items: center; + padding-left: 8px; + padding-right: 8px; `; const StatusIcon = styled.span<{ @@ -33,21 +31,32 @@ const StatusIcon = styled.span<{ margin-right: 8px; background-color: ${(props) => props.status === "running" - ? "#4caf50" + ? "var(--vscode-testing-runAction, #4caf50)" : props.status === "completed" - ? "#4caf50" + ? "var(--vscode-testing-iconPassed, #4caf50)" : props.status === "background" - ? "#2196f3" - : "#f44336"}; + ? "var(--vscode-statusBarItem-prominentBackground, #2196f3)" + : "var(--vscode-testing-iconFailed, #f44336)"}; ${(props) => props.status === "running" ? "animation: pulse 1.5s infinite;" : ""} `; -// Removed unused styled components +// Waiting message styled for consistency +const WaitingMessage = styled.div` + padding: 8px; + padding-left: 16px; + padding-right: 16px; + margin-top: 8px; +`; + +// For consistency with the rest of the styled components +const AnsiWrapper = styled.div` + margin-top: 8px; +`; const BackgroundLink = styled.a` font-size: 12px; - color: #0077cc; + color: var(--vscode-textLink-foreground, #3794ff); margin-left: 12px; cursor: pointer; text-decoration: none; @@ -57,6 +66,11 @@ const BackgroundLink = styled.a` } `; +// Just spacing between terminal components and the next toolcall +const TerminalContainer = styled.div` + margin-bottom: 16px; +`; + export function RunTerminalCommand(props: RunTerminalCommandToolCallProps) { const dispatch = useAppDispatch(); @@ -82,16 +96,24 @@ export function RunTerminalCommand(props: RunTerminalCommandToolCallProps) { } return ( - + + {/* Command */} + {/* Terminal output with ANSI support */} + {isRunning && !hasOutput && ( + Waiting for output... + )} + {hasOutput && ( + + {terminalContent} + + )} + + {/* Status information */} {(statusMessage || isRunning) && ( @@ -112,6 +134,6 @@ export function RunTerminalCommand(props: RunTerminalCommandToolCallProps) { )} )} - + ); } From 5b1261f3d0650c8fd48f8e8d91dc224bf825e9ac Mon Sep 17 00:00:00 2001 From: Shankhadeep Dey Date: Tue, 3 Jun 2025 11:38:40 +0530 Subject: [PATCH 011/182] feaet: add support for vLLM response format in reranking logic and update documentation --- core/llm/index.ts | 21 ++++++++++++++++--- .../customize/model-providers/more/vllm.mdx | 4 ++-- packages/openai-adapters/src/apis/base.ts | 18 ++++++++++++++++ packages/openai-adapters/src/index.ts | 2 +- 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/core/llm/index.ts b/core/llm/index.ts index ca33b7437..2221f18a5 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -5,6 +5,7 @@ import { BaseLlmApi, ChatCompletionCreateParams, constructLlmApi, + VllmRerankResponse } from "@continuedev/openai-adapters"; import Handlebars from "handlebars"; @@ -1068,9 +1069,23 @@ export abstract class BaseLLM implements ILLM { documents: chunks.map((chunk) => chunk.content), }); - // Put them in the order they were given - const sortedResults = results.data.sort((a, b) => a.index - b.index); - return sortedResults.map((result) => result.relevance_score); + // Handle different response formats: OpenAI (data), vLLM (results) + let dataArray: Array<{ index: number; relevance_score: number }>; + + if (results.data && Array.isArray(results.data)) { + dataArray = results.data; + } else if ((results as VllmRerankResponse).results && Array.isArray((results as VllmRerankResponse).results)) { + dataArray = (results as VllmRerankResponse).results; + }else { + throw new Error( + `Unexpected rerank response format from ${this.providerName}. ` + + `Expected 'data' or 'results' array but got: ${JSON.stringify(results)}` + ); + } + + return dataArray + .sort((a, b) => a.index - b.index) + .map((result) => result.relevance_score); } throw new Error( diff --git a/docs/docs/customize/model-providers/more/vllm.mdx b/docs/docs/customize/model-providers/more/vllm.mdx index 9bae1880e..49d6c8212 100644 --- a/docs/docs/customize/model-providers/more/vllm.mdx +++ b/docs/docs/customize/model-providers/more/vllm.mdx @@ -1,5 +1,3 @@ -import TabItem from "@theme/TabItem"; -import Tabs from "@theme/Tabs"; # vLLM @@ -100,6 +98,8 @@ We recommend configuring **Nomic Embed Text** as your embeddings model. ## Reranking model +Continue automatically handles vLLM's response format (which uses `results` instead of `data`). + [Click here](../../model-roles/reranking.mdx) to see a list of reranking model providers. The continue implementation uses [OpenAI](../top-level/openai.mdx) under the hood. [View the source](https://github.com/continuedev/continue/blob/main/core/llm/llms/Vllm.ts) diff --git a/packages/openai-adapters/src/apis/base.ts b/packages/openai-adapters/src/apis/base.ts index 5079aedef..4ce8509a8 100644 --- a/packages/openai-adapters/src/apis/base.ts +++ b/packages/openai-adapters/src/apis/base.ts @@ -37,6 +37,24 @@ export interface CreateRerankResponse { }; } +// vLLM-specific rerank response format +export interface VllmRerankItem { + index: number; + document: { + text: string; + }; + relevance_score: number; +} + +export interface VllmRerankResponse { + id: string; + model: string; + usage: { + total_tokens: number; + }; + results: VllmRerankItem[]; +} + export interface BaseLlmApi { // Chat, no stream chatCompletionNonStream( diff --git a/packages/openai-adapters/src/index.ts b/packages/openai-adapters/src/index.ts index eea617cf7..6dbf8e385 100644 --- a/packages/openai-adapters/src/index.ts +++ b/packages/openai-adapters/src/index.ts @@ -121,5 +121,5 @@ export { } from "openai/resources/index"; // export -export type { BaseLlmApi } from "./apis/base.js"; +export type { BaseLlmApi, VllmRerankItem, VllmRerankResponse } from "./apis/base.js"; export type { LLMConfig } from "./types.js"; From 1d000bec682d1d723bf6748f34c3dd86b684d775 Mon Sep 17 00:00:00 2001 From: Shankhadeep Dey Date: Tue, 3 Jun 2025 11:55:08 +0530 Subject: [PATCH 012/182] fix: format code --- packages/openai-adapters/src/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/openai-adapters/src/index.ts b/packages/openai-adapters/src/index.ts index 6dbf8e385..8b47f3ea6 100644 --- a/packages/openai-adapters/src/index.ts +++ b/packages/openai-adapters/src/index.ts @@ -121,5 +121,9 @@ export { } from "openai/resources/index"; // export -export type { BaseLlmApi, VllmRerankItem, VllmRerankResponse } from "./apis/base.js"; +export type { + BaseLlmApi, + VllmRerankItem, + VllmRerankResponse, +} from "./apis/base.js"; export type { LLMConfig } from "./types.js"; From c8d9d959f10b34cb0af857cfa178c1f9df30f5cf Mon Sep 17 00:00:00 2001 From: Shankhadeep Dey Date: Thu, 5 Jun 2025 11:12:20 +0530 Subject: [PATCH 013/182] feat: move vLLM rerank response in the VLLM.ts and remove unused types --- core/llm/index.ts | 25 +++++--------- core/llm/llms/Vllm.ts | 42 ++++++++++++++++++++++- packages/openai-adapters/src/apis/base.ts | 36 ++++++------------- packages/openai-adapters/src/index.ts | 9 ++--- 4 files changed, 63 insertions(+), 49 deletions(-) diff --git a/core/llm/index.ts b/core/llm/index.ts index 2221f18a5..eb83f51e4 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -4,8 +4,7 @@ import { findLlmInfo } from "@continuedev/llm-info"; import { BaseLlmApi, ChatCompletionCreateParams, - constructLlmApi, - VllmRerankResponse + constructLlmApi } from "@continuedev/openai-adapters"; import Handlebars from "handlebars"; @@ -1069,23 +1068,17 @@ export abstract class BaseLLM implements ILLM { documents: chunks.map((chunk) => chunk.content), }); - // Handle different response formats: OpenAI (data), vLLM (results) - let dataArray: Array<{ index: number; relevance_score: number }>; - + // Standard OpenAI format if (results.data && Array.isArray(results.data)) { - dataArray = results.data; - } else if ((results as VllmRerankResponse).results && Array.isArray((results as VllmRerankResponse).results)) { - dataArray = (results as VllmRerankResponse).results; - }else { - throw new Error( - `Unexpected rerank response format from ${this.providerName}. ` + - `Expected 'data' or 'results' array but got: ${JSON.stringify(results)}` - ); + return results.data + .sort((a, b) => a.index - b.index) + .map((result) => result.relevance_score); } - return dataArray - .sort((a, b) => a.index - b.index) - .map((result) => result.relevance_score); + throw new Error( + `Unexpected rerank response format from ${this.providerName}. ` + + `Expected 'data' array but got: ${JSON.stringify(Object.keys(results))}` + ); } throw new Error( diff --git a/core/llm/llms/Vllm.ts b/core/llm/llms/Vllm.ts index 991b09c3e..0767777c5 100644 --- a/core/llm/llms/Vllm.ts +++ b/core/llm/llms/Vllm.ts @@ -1,7 +1,25 @@ -import { LLMOptions } from "../../index.js"; +import { Chunk, LLMOptions } from "../../index.js"; import OpenAI from "./OpenAI.js"; +// vLLM-specific rerank response types +interface VllmRerankItem { + index: number; + document: { + text: string; + }; + relevance_score: number; +} + +interface VllmRerankResponse { + id: string; + model: string; + usage: { + total_tokens: number; + }; + results: VllmRerankItem[]; +} + class Vllm extends OpenAI { static providerName = "vllm"; constructor(options: LLMOptions) { @@ -16,6 +34,28 @@ class Vllm extends OpenAI { return false; } + async rerank(query: string, chunks: Chunk[]): Promise { + if (this.useOpenAIAdapterFor.includes("rerank") && this.openaiAdapter) { + const results = await this.openaiAdapter.rerank({ + model: this.model, + query, + documents: chunks.map((chunk) => chunk.content), + }) as unknown as VllmRerankResponse; + + // vLLM uses 'results' array instead of 'data' + if (results.results && Array.isArray(results.results)) { + const sortedResults = results.results.sort((a, b) => a.index - b.index); + return sortedResults.map((result) => result.index); + } + + throw new Error( + `vLLM rerank response missing 'results' array. Got: ${JSON.stringify(Object.keys(results))}` + ); + } + + throw new Error("vLLM rerank requires OpenAI adapter"); + } + private _setupCompletionOptions() { this.fetch(this._getEndpoint("models"), { method: "GET", diff --git a/packages/openai-adapters/src/apis/base.ts b/packages/openai-adapters/src/apis/base.ts index 4ce8509a8..f0d3d55d2 100644 --- a/packages/openai-adapters/src/apis/base.ts +++ b/packages/openai-adapters/src/apis/base.ts @@ -1,14 +1,14 @@ import { - ChatCompletion, - ChatCompletionChunk, - ChatCompletionCreateParamsNonStreaming, - ChatCompletionCreateParamsStreaming, - Completion, - CompletionCreateParamsNonStreaming, - CompletionCreateParamsStreaming, - CreateEmbeddingResponse, - EmbeddingCreateParams, - Model, + ChatCompletion, + ChatCompletionChunk, + ChatCompletionCreateParamsNonStreaming, + ChatCompletionCreateParamsStreaming, + Completion, + CompletionCreateParamsNonStreaming, + CompletionCreateParamsStreaming, + CreateEmbeddingResponse, + EmbeddingCreateParams, + Model, } from "openai/resources/index"; export interface FimCreateParamsStreaming @@ -37,23 +37,7 @@ export interface CreateRerankResponse { }; } -// vLLM-specific rerank response format -export interface VllmRerankItem { - index: number; - document: { - text: string; - }; - relevance_score: number; -} -export interface VllmRerankResponse { - id: string; - model: string; - usage: { - total_tokens: number; - }; - results: VllmRerankItem[]; -} export interface BaseLlmApi { // Chat, no stream diff --git a/packages/openai-adapters/src/index.ts b/packages/openai-adapters/src/index.ts index 8b47f3ea6..4dc9219a6 100644 --- a/packages/openai-adapters/src/index.ts +++ b/packages/openai-adapters/src/index.ts @@ -117,13 +117,10 @@ export { type Completion, type CompletionCreateParams, type CompletionCreateParamsNonStreaming, - type CompletionCreateParamsStreaming, + type CompletionCreateParamsStreaming } from "openai/resources/index"; // export -export type { - BaseLlmApi, - VllmRerankItem, - VllmRerankResponse, -} from "./apis/base.js"; +export type { BaseLlmApi } from "./apis/base.js"; export type { LLMConfig } from "./types.js"; + From cbb5c21f591e078df186fd86865830cb8971be03 Mon Sep 17 00:00:00 2001 From: Shankhadeep Dey Date: Fri, 6 Jun 2025 21:23:40 +0530 Subject: [PATCH 014/182] fix: correct formatting --- core/llm/index.ts | 4 ++-- core/llm/llms/Vllm.ts | 6 +++--- packages/openai-adapters/src/apis/base.ts | 22 ++++++++++------------ packages/openai-adapters/src/index.ts | 3 +-- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/core/llm/index.ts b/core/llm/index.ts index eb83f51e4..6cadb6992 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -4,7 +4,7 @@ import { findLlmInfo } from "@continuedev/llm-info"; import { BaseLlmApi, ChatCompletionCreateParams, - constructLlmApi + constructLlmApi, } from "@continuedev/openai-adapters"; import Handlebars from "handlebars"; @@ -1077,7 +1077,7 @@ export abstract class BaseLLM implements ILLM { throw new Error( `Unexpected rerank response format from ${this.providerName}. ` + - `Expected 'data' array but got: ${JSON.stringify(Object.keys(results))}` + `Expected 'data' array but got: ${JSON.stringify(Object.keys(results))}`, ); } diff --git a/core/llm/llms/Vllm.ts b/core/llm/llms/Vllm.ts index 0767777c5..ac550f153 100644 --- a/core/llm/llms/Vllm.ts +++ b/core/llm/llms/Vllm.ts @@ -36,11 +36,11 @@ class Vllm extends OpenAI { async rerank(query: string, chunks: Chunk[]): Promise { if (this.useOpenAIAdapterFor.includes("rerank") && this.openaiAdapter) { - const results = await this.openaiAdapter.rerank({ + const results = (await this.openaiAdapter.rerank({ model: this.model, query, documents: chunks.map((chunk) => chunk.content), - }) as unknown as VllmRerankResponse; + })) as unknown as VllmRerankResponse; // vLLM uses 'results' array instead of 'data' if (results.results && Array.isArray(results.results)) { @@ -49,7 +49,7 @@ class Vllm extends OpenAI { } throw new Error( - `vLLM rerank response missing 'results' array. Got: ${JSON.stringify(Object.keys(results))}` + `vLLM rerank response missing 'results' array. Got: ${JSON.stringify(Object.keys(results))}`, ); } diff --git a/packages/openai-adapters/src/apis/base.ts b/packages/openai-adapters/src/apis/base.ts index f0d3d55d2..5079aedef 100644 --- a/packages/openai-adapters/src/apis/base.ts +++ b/packages/openai-adapters/src/apis/base.ts @@ -1,14 +1,14 @@ import { - ChatCompletion, - ChatCompletionChunk, - ChatCompletionCreateParamsNonStreaming, - ChatCompletionCreateParamsStreaming, - Completion, - CompletionCreateParamsNonStreaming, - CompletionCreateParamsStreaming, - CreateEmbeddingResponse, - EmbeddingCreateParams, - Model, + ChatCompletion, + ChatCompletionChunk, + ChatCompletionCreateParamsNonStreaming, + ChatCompletionCreateParamsStreaming, + Completion, + CompletionCreateParamsNonStreaming, + CompletionCreateParamsStreaming, + CreateEmbeddingResponse, + EmbeddingCreateParams, + Model, } from "openai/resources/index"; export interface FimCreateParamsStreaming @@ -37,8 +37,6 @@ export interface CreateRerankResponse { }; } - - export interface BaseLlmApi { // Chat, no stream chatCompletionNonStream( diff --git a/packages/openai-adapters/src/index.ts b/packages/openai-adapters/src/index.ts index 4dc9219a6..eea617cf7 100644 --- a/packages/openai-adapters/src/index.ts +++ b/packages/openai-adapters/src/index.ts @@ -117,10 +117,9 @@ export { type Completion, type CompletionCreateParams, type CompletionCreateParamsNonStreaming, - type CompletionCreateParamsStreaming + type CompletionCreateParamsStreaming, } from "openai/resources/index"; // export export type { BaseLlmApi } from "./apis/base.js"; export type { LLMConfig } from "./types.js"; - From 45e39ed50925d72ade246c55c69df59f5e96a0dc Mon Sep 17 00:00:00 2001 From: Lucas Shamanic Date: Sat, 7 Jun 2025 02:19:07 +0100 Subject: [PATCH 015/182] bump dependencies and update package versions in package-lock files --- binary/package-lock.json | 5 +++-- core/package-lock.json | 4 ++-- extensions/vscode/package-lock.json | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/binary/package-lock.json b/binary/package-lock.json index abb11ce8e..2d84672f0 100644 --- a/binary/package-lock.json +++ b/binary/package-lock.json @@ -52,7 +52,7 @@ "@aws-sdk/credential-providers": "^3.778.0", "@continuedev/config-types": "^1.0.13", "@continuedev/config-yaml": "file:../packages/config-yaml", - "@continuedev/fetch": "^1.0.10", + "@continuedev/fetch": "^1.0.13", "@continuedev/llm-info": "^1.0.8", "@continuedev/openai-adapters": "^1.0.25", "@modelcontextprotocol/sdk": "^1.12.0", @@ -144,7 +144,8 @@ "onnxruntime-common": "1.14.0", "onnxruntime-web": "1.14.0", "ts-jest": "^29.1.1", - "typescript": "^5.6.3" + "typescript": "^5.6.3", + "vitest": "^3.1.4" }, "engines": { "node": ">=20.19.0" diff --git a/core/package-lock.json b/core/package-lock.json index f6eabcae4..20b1d0870 100644 --- a/core/package-lock.json +++ b/core/package-lock.json @@ -113,10 +113,10 @@ "node": ">=20.19.0" } }, - "../../../../dallin/documents/code/continuedev/continue/packages/config-yaml": { + "../../../dallin/documents/code/continuedev/continue/packages/config-yaml": { "extraneous": true }, - "../../../../documents/code/continuedev/continue/packages/config-yaml": { + "../../../documents/code/continuedev/continue/packages/config-yaml": { "version": "1.0.78", "extraneous": true, "license": "Apache-2.0", diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 38efaa08a..349212a6a 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "1.1.44", + "version": "1.1.45", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "1.1.44", + "version": "1.1.45", "license": "Apache-2.0", "dependencies": { "@continuedev/config-types": "^1.0.14", From 77a723cdea62e281e28bb13e85b45f21f2d8585d Mon Sep 17 00:00:00 2001 From: Lucas Shamanic Date: Sat, 7 Jun 2025 04:00:30 +0100 Subject: [PATCH 016/182] Add force autocomplete command and update inline completion handling - Introduced a new command `continue.forceAutocomplete` to trigger autocompletion manually. - Updated `CompletionProvider` to accept a `force` parameter for inline completion. - Enhanced `ContinueCompletionProvider` to handle manual autocompletion triggers. --- core/autocomplete/CompletionProvider.ts | 9 +++++++-- extensions/vscode/package.json | 16 ++++++++++++++++ .../src/autocomplete/completionProvider.ts | 5 +++++ extensions/vscode/src/commands.ts | 5 +++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/core/autocomplete/CompletionProvider.ts b/core/autocomplete/CompletionProvider.ts index 8a579c231..749b44e25 100644 --- a/core/autocomplete/CompletionProvider.ts +++ b/core/autocomplete/CompletionProvider.ts @@ -127,6 +127,7 @@ export class CompletionProvider { public async provideInlineCompletionItems( input: AutocompleteInput, token: AbortSignal | undefined, + force?: boolean, ): Promise { try { // Create abort signal if not given @@ -146,8 +147,12 @@ export class CompletionProvider { const options = await this._getAutocompleteOptions(llm); // Debounce - if (await this.debouncer.delayAndShouldDebounce(options.debounceDelay)) { - return undefined; + if (!force) { + if ( + await this.debouncer.delayAndShouldDebounce(options.debounceDelay) + ) { + return undefined; + } } if (llm.promptTemplates?.autocomplete) { diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 54f93c509..8a265c903 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -225,6 +225,11 @@ "title": "Toggle Autocomplete Enabled", "group": "Continue" }, + { + "command": "continue.forceAutocomplete", + "title": "Continue: Force Autocomplete", + "category": "Continue" + }, { "command": "continue.selectFilesAsContext", "category": "Continue", @@ -411,6 +416,17 @@ "key": "ctrl+k ctrl+a", "when": "!terminalFocus" }, + { + "command": "continue.forceAutocomplete", + "key": "ctrl+alt+space", + "when": "editorTextFocus && !editorHasSelection && !editorReadOnly && !inSnippetMode" + }, + { + "command": "continue.forceAutocomplete", + "key": "cmd+alt+space", + "mac": "cmd+alt+space", + "when": "editorTextFocus && !editorHasSelection && !editorReadOnly && !inSnippetMode" + }, { "command": "continue.applyCodeFromChat", "mac": "alt+a", diff --git a/extensions/vscode/src/autocomplete/completionProvider.ts b/extensions/vscode/src/autocomplete/completionProvider.ts index c15897883..963dcedeb 100644 --- a/extensions/vscode/src/autocomplete/completionProvider.ts +++ b/extensions/vscode/src/autocomplete/completionProvider.ts @@ -189,6 +189,10 @@ export class ContinueCompletionProvider // Handle commit message input box let manuallyPassPrefix: string | undefined = undefined; + // handle manual autocompletion trigger + const wasManuallyTriggered = + context.triggerKind === vscode.InlineCompletionTriggerKind.Invoke; + const input: AutocompleteInput = { pos, manuallyPassFileContents, @@ -208,6 +212,7 @@ export class ContinueCompletionProvider await this.completionProvider.provideInlineCompletionItems( input, signal, + wasManuallyTriggered, ); if (!outcome || !outcome.completion) { diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index 3aadfadb9..351c3a33c 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -624,6 +624,11 @@ const getCommandsMap: ( } } }, + "continue.forceAutocomplete": () => { + captureCommandTelemetry("forceAutocomplete"); + vscode.commands.executeCommand("editor.action.inlineSuggest.trigger"); + }, + "continue.openTabAutocompleteConfigMenu": async () => { captureCommandTelemetry("openTabAutocompleteConfigMenu"); From cc507687eb36be5b7fd59eac433a9a908c1ee07e Mon Sep 17 00:00:00 2001 From: shamanic Date: Sat, 7 Jun 2025 04:17:02 +0100 Subject: [PATCH 017/182] fix(vscode): improve forceAutocomplete command reliability Modified the `forceAutocomplete` command to first hide any existing inline suggestion before triggering a new one. This ensures VS Code's suggestion cache is cleared, forcing it to call the provider for a fresh suggestion. --- extensions/vscode/src/commands.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index 351c3a33c..2162b1fca 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -624,9 +624,16 @@ const getCommandsMap: ( } } }, - "continue.forceAutocomplete": () => { + "continue.forceAutocomplete": async () => { captureCommandTelemetry("forceAutocomplete"); - vscode.commands.executeCommand("editor.action.inlineSuggest.trigger"); + + // 1. Explicitly hide any existing suggestion. This clears VS Code's cache for the current position. + await vscode.commands.executeCommand("editor.action.inlineSuggest.hide"); + + // 2. Now trigger a new one. VS Code has no cached suggestion, so it's forced to call our provider. + await vscode.commands.executeCommand( + "editor.action.inlineSuggest.trigger", + ); }, "continue.openTabAutocompleteConfigMenu": async () => { From dcffd3529ff8583c3ddb429928af82aeb25c8436 Mon Sep 17 00:00:00 2001 From: shamanic Date: Sat, 7 Jun 2025 05:03:12 +0100 Subject: [PATCH 018/182] test: add force autocomplete test case - Adds `forceCompletion` method to `AutocompleteActions` to trigger autocomplete via command. - Includes new test case to verify forced autocomplete functionality. - Attempted to test these tests to the best of my ability` --- .../vscode/e2e/actions/Autocomplete.actions.ts | 15 ++++++++++++++- extensions/vscode/e2e/tests/Autocomplete.test.ts | 5 +++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/extensions/vscode/e2e/actions/Autocomplete.actions.ts b/extensions/vscode/e2e/actions/Autocomplete.actions.ts index c35c47a29..9e91355fd 100644 --- a/extensions/vscode/e2e/actions/Autocomplete.actions.ts +++ b/extensions/vscode/e2e/actions/Autocomplete.actions.ts @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { TextEditor } from "vscode-extension-tester"; +import { TextEditor, VSBrowser, Workbench } from "vscode-extension-tester"; import { DEFAULT_TIMEOUT } from "../constants"; import { AutocompleteSelectors } from "../selectors/Autocomplete.selectors"; @@ -29,4 +29,17 @@ export class AutocompleteActions { ); expect(ghostText1).to.equal(messagePair1.llmResponse); } + + public static async forceCompletion(editor: TextEditor): Promise { + await editor.setText("def main():\n "); + await editor.moveCursor(2, 5); + + await new Workbench().executeCommand("Continue: Force Autocomplete"); + + const ghostText = await TestUtils.waitForSuccess(() => + AutocompleteSelectors.getGhostTextContent(VSBrowser.instance.driver) + ); + + return ghostText; + } } diff --git a/extensions/vscode/e2e/tests/Autocomplete.test.ts b/extensions/vscode/e2e/tests/Autocomplete.test.ts index 836c2c60e..7685d52ae 100644 --- a/extensions/vscode/e2e/tests/Autocomplete.test.ts +++ b/extensions/vscode/e2e/tests/Autocomplete.test.ts @@ -1,3 +1,4 @@ +import { expect } from "chai"; import { EditorView, TextEditor } from "vscode-extension-tester"; import { AutocompleteActions } from "../actions/Autocomplete.actions"; @@ -23,4 +24,8 @@ describe("Autocomplete", () => { it("Should display completions", async () => { await AutocompleteActions.testCompletions(editor); }).timeout(DEFAULT_TIMEOUT.XL); + it("Should force a completion using the command", async () => { + const ghostText = await AutocompleteActions.forceCompletion(editor); + expect(ghostText).to.not.be.empty; + }).timeout(DEFAULT_TIMEOUT.XL); }); From 4952c1696491dc6418790313393e8c3bf5705c7c Mon Sep 17 00:00:00 2001 From: shamanic Date: Sat, 7 Jun 2025 05:15:57 +0100 Subject: [PATCH 019/182] docs: add section on forcing autocomplete suggestions Includes details on triggering autocomplete suggestions immediately using the `cmd/ctrl + alt + space` keyboard shortcut. --- docs/docs/autocomplete/how-to-use-it.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/docs/autocomplete/how-to-use-it.md b/docs/docs/autocomplete/how-to-use-it.md index b9b3c19d2..93a1ce507 100644 --- a/docs/docs/autocomplete/how-to-use-it.md +++ b/docs/docs/autocomplete/how-to-use-it.md @@ -23,3 +23,7 @@ Reject a full suggestion with Esc ### Partially accepting a suggestion For more granular control, use cmd/ctrl + → to accept parts of the suggestion word-by-word. + +### Forcing a suggestion + +If you want to trigger a suggestion immediately without waiting, or if you've dismissed a suggestion and want a new one, you can force it by using the keyboard shortcut **cmd/ctrl + alt + space**. From 6d6f89fe55e7301d3c84473162d2e4da8bf0dc31 Mon Sep 17 00:00:00 2001 From: Jacob Date: Mon, 9 Jun 2025 11:04:23 +0800 Subject: [PATCH 020/182] fix: Fix the issue where the chunk index might be duplicated --- core/indexing/chunk/chunk.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/indexing/chunk/chunk.ts b/core/indexing/chunk/chunk.ts index d51f368a2..c918ddac8 100644 --- a/core/indexing/chunk/chunk.ts +++ b/core/indexing/chunk/chunk.ts @@ -62,12 +62,11 @@ export async function* chunkDocument({ resolve({ ...chunkWithoutId, digest, - index, + index: index++, filepath, }); }), ); - index++; } for await (const chunk of chunkPromises) { if (!chunk) { From 41bc0e922b333ee404ddb17e5bdcf7c83b7a6ca0 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 9 Jun 2025 10:10:05 -0700 Subject: [PATCH 021/182] feat: onboarding card upgrade tab --- core/control-plane/client.ts | 22 +++- core/core.ts | 6 ++ core/llm/streamChat.ts | 21 ++++ core/protocol/core.ts | 6 ++ core/protocol/ideWebview.ts | 2 +- core/protocol/passThrough.ts | 2 + core/protocol/webview.ts | 1 + extensions/vscode/src/webviewProtocol.ts | 2 +- gui/src/components/Layout.tsx | 32 ++++-- .../OnboardingCard/OnboardingCard.tsx | 29 ++++- .../components/OnboardingCardLanding.tsx | 2 +- .../components/OnboardingCardTabs.tsx | 102 +++++++++++++----- .../components/OnboardingModelsAddOnTab.tsx | 84 +++++++++++++++ .../components/OnboardingProvidersTab.tsx | 2 +- .../OnboardingCard/components/index.ts | 1 + .../dialogs/FreeTrialOverDialog.tsx | 25 ----- .../components/{gui => svg}/ContinueLogo.tsx | 0 gui/src/components/svg/ContinueSignet.tsx | 35 ++++++ gui/src/components/svg/OllamaLogo.tsx | 51 +++++++++ gui/src/pages/config/ScopeSelect.tsx | 2 +- gui/src/pages/gui/Chat.tsx | 2 - 21 files changed, 359 insertions(+), 70 deletions(-) create mode 100644 gui/src/components/OnboardingCard/components/OnboardingModelsAddOnTab.tsx delete mode 100644 gui/src/components/dialogs/FreeTrialOverDialog.tsx rename gui/src/components/{gui => svg}/ContinueLogo.tsx (100%) create mode 100644 gui/src/components/svg/ContinueSignet.tsx create mode 100644 gui/src/components/svg/OllamaLogo.tsx diff --git a/core/control-plane/client.ts b/core/control-plane/client.ts index 72523aa08..5a045f4b3 100644 --- a/core/control-plane/client.ts +++ b/core/control-plane/client.ts @@ -10,7 +10,7 @@ import { import fetch, { RequestInit, Response } from "node-fetch"; import { OrganizationDescription } from "../config/ProfileLifecycleManager.js"; -import { IdeSettings, ModelDescription } from "../index.js"; +import { IdeSettings, IdeType, ModelDescription } from "../index.js"; import { ControlPlaneSessionInfo, isOnPremSession } from "./AuthTypes.js"; import { getControlPlaneEnv } from "./env.js"; @@ -182,4 +182,24 @@ export class ControlPlaneClient { return null; } } + + public async getModelsAddOnUpgradeUrl( + ide: IdeType, + ): Promise<{ url: string } | null> { + if (!(await this.isSignedIn())) { + return null; + } + + try { + const resp = await this.request( + `ide/get-models-add-on-upgrade-url?ide=${encodeURIComponent(ide)}`, + { + method: "GET", + }, + ); + return (await resp.json()) as { url: string }; + } catch (e) { + return null; + } + } } diff --git a/core/core.ts b/core/core.ts index dfa91e1f7..dc03537a8 100644 --- a/core/core.ts +++ b/core/core.ts @@ -342,6 +342,12 @@ export class Core { return this.configHandler.controlPlaneClient.getFreeTrialStatus(); }); + on("controlPlane/getModelsAddOnUpgradeUrl", async (msg) => { + return this.configHandler.controlPlaneClient.getModelsAddOnUpgradeUrl( + msg.data.ide, + ); + }); + on("mcp/reloadServer", async (msg) => { await MCPManagerSingleton.getInstance().refreshConnection(msg.data.id); }); diff --git a/core/llm/streamChat.ts b/core/llm/streamChat.ts index c899e437f..e56e321a3 100644 --- a/core/llm/streamChat.ts +++ b/core/llm/streamChat.ts @@ -135,6 +135,8 @@ export async function* llmStreamChat( true, ); + void checkForFreeTrialExceeded(configHandler, messenger); + if (!next.done) { throw new Error("Will never happen"); } @@ -142,3 +144,22 @@ export async function* llmStreamChat( return next.value; } } + +async function checkForFreeTrialExceeded( + configHandler: ConfigHandler, + messenger: IMessenger, +) { + try { + const freeTrialStatus = + await configHandler.controlPlaneClient.getFreeTrialStatus(); + if ( + freeTrialStatus && + freeTrialStatus.chatCount && + freeTrialStatus.chatCount > freeTrialStatus.chatLimit + ) { + void messenger.request("freeTrialExceeded", undefined); + } + } catch (error) { + console.error("Error checking free trial status:", error); + } +} diff --git a/core/protocol/core.ts b/core/protocol/core.ts index 1358e0a3a..7251a8497 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -21,6 +21,7 @@ import { ExperimentalModelRoles, FileSymbolMap, IdeSettings, + IdeType, LLMFullCompletionOptions, ModelDescription, PromptLog, @@ -40,6 +41,7 @@ import { FreeTrialStatus } from "../control-plane/client"; export enum OnboardingModes { PROVIDERS = "Providers", LOCAL = "Local", + MODELS_ADD_ON = "Models Add-On", } export interface ListHistoryOptions { @@ -199,6 +201,10 @@ export type ToCoreFromIdeOrWebviewProtocol = { "clipboardCache/add": [{ content: string }, void]; "controlPlane/openUrl": [{ path: string; orgSlug?: string }, void]; "controlPlane/getFreeTrialStatus": [undefined, FreeTrialStatus | null]; + "controlPlane/getModelsAddOnUpgradeUrl": [ + { ide: IdeType }, + { url: string } | null, + ]; isItemTooBig: [{ item: ContextItemWithId }, boolean]; didChangeControlPlaneSessionInfo: [ { sessionInfo: ControlPlaneSessionInfo | undefined }, diff --git a/core/protocol/ideWebview.ts b/core/protocol/ideWebview.ts index 39ae205a5..074e3837f 100644 --- a/core/protocol/ideWebview.ts +++ b/core/protocol/ideWebview.ts @@ -76,7 +76,7 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & { setColors: [{ [key: string]: string }, void]; "jetbrains/editorInsetRefresh": [undefined, void]; "jetbrains/isOSREnabled": [boolean, void]; - addApiKey: [undefined, void]; + setupApiKey: [undefined, void]; setupLocalConfig: [undefined, void]; incrementFtc: [undefined, void]; openOnboardingCard: [undefined, void]; diff --git a/core/protocol/passThrough.ts b/core/protocol/passThrough.ts index d1e1a0e8f..622b4e6f5 100644 --- a/core/protocol/passThrough.ts +++ b/core/protocol/passThrough.ts @@ -61,6 +61,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] = "didChangeSelectedOrg", "tools/call", "controlPlane/openUrl", + "controlPlane/getModelsAddOnUpgradeUrl", "isItemTooBig", "process/markAsBackgrounded", "process/isBackgrounded", @@ -83,4 +84,5 @@ export const CORE_TO_WEBVIEW_PASS_THROUGH: (keyof ToWebviewFromCoreProtocol)[] = "sessionUpdate", "didCloseFiles", "toolCallPartialOutput", + "freeTrialExceeded", ]; diff --git a/core/protocol/webview.ts b/core/protocol/webview.ts index 5ba47e3d4..1a8d40313 100644 --- a/core/protocol/webview.ts +++ b/core/protocol/webview.ts @@ -43,4 +43,5 @@ export type ToWebviewFromIdeOrCoreProtocol = { "jetbrains/setColors": [Record, void]; sessionUpdate: [{ sessionInfo: ControlPlaneSessionInfo | undefined }, void]; toolCallPartialOutput: [{ toolCallId: string; contextItems: any[] }, void]; + freeTrialExceeded: [undefined, void]; }; diff --git a/extensions/vscode/src/webviewProtocol.ts b/extensions/vscode/src/webviewProtocol.ts index 5778371a3..013e10d03 100644 --- a/extensions/vscode/src/webviewProtocol.ts +++ b/extensions/vscode/src/webviewProtocol.ts @@ -129,7 +129,7 @@ export class VsCodeWebviewProtocol .showInformationMessage(message, "Add API Key", "Use Local Model") .then((selection) => { if (selection === "Add API Key") { - this.request("addApiKey", undefined); + this.request("setupApiKey", undefined); } else if (selection === "Use Local Model") { this.request("setupLocalConfig", undefined); } diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index 811297e81..a046d33ef 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -9,7 +9,7 @@ import { LocalStorageProvider } from "../context/LocalStorage"; import { useWebviewListener } from "../hooks/useWebviewListener"; import { useAppDispatch, useAppSelector } from "../redux/hooks"; import { setCodeToEdit } from "../redux/slices/editState"; -import { setShowDialog } from "../redux/slices/uiSlice"; +import { setDialogMessage, setShowDialog } from "../redux/slices/uiSlice"; import { enterEdit, exitEdit } from "../redux/thunks/edit"; import { saveCurrentSession } from "../redux/thunks/session"; import { fontSize, isMetaEquivalentKeyPressed } from "../util"; @@ -20,7 +20,11 @@ import TextDialog from "./dialogs"; import Footer from "./Footer"; import { LumpProvider } from "./mainInput/Lump/LumpContext"; import { useMainEditor } from "./mainInput/TipTapEditor"; -import { isNewUserOnboarding, useOnboardingCard } from "./OnboardingCard"; +import { + isNewUserOnboarding, + OnboardingCard, + useOnboardingCard, +} from "./OnboardingCard"; import OSRContextMenu from "./OSRContextMenu"; import PostHogPageView from "./PosthogPageView"; @@ -130,17 +134,33 @@ const Layout = () => { ); useWebviewListener( - "openOnboardingCard", + "setupLocalConfig", async () => { - onboardingCard.open(OnboardingModes.PROVIDERS); + onboardingCard.open(OnboardingModes.LOCAL); }, [], ); useWebviewListener( - "setupLocalConfig", + "freeTrialExceeded", async () => { - onboardingCard.open(OnboardingModes.LOCAL); + dispatch(setShowDialog(true)); + onboardingCard.setActiveTab(OnboardingModes.MODELS_ADD_ON); + dispatch( + setDialogMessage( +
+ +
, + ), + ); + }, + [], + ); + + useWebviewListener( + "setupApiKey", + async () => { + onboardingCard.open(OnboardingModes.PROVIDERS); }, [], ); diff --git a/gui/src/components/OnboardingCard/OnboardingCard.tsx b/gui/src/components/OnboardingCard/OnboardingCard.tsx index 1c0569c80..855b1f0e5 100644 --- a/gui/src/components/OnboardingCard/OnboardingCard.tsx +++ b/gui/src/components/OnboardingCard/OnboardingCard.tsx @@ -1,11 +1,13 @@ import { OnboardingModes } from "core/protocol/core"; import { useAppSelector } from "../../redux/hooks"; import { getLocalStorage, setLocalStorage } from "../../util/localStorage"; +import Alert from "../gui/Alert"; import { ReusableCard } from "../ReusableCard"; import { OnboardingCardLanding, OnboardingCardTabs, OnboardingLocalTab, + OnboardingModelsAddOnTab, OnboardingProvidersTab, } from "./components"; import { useOnboardingCard } from "./hooks"; @@ -17,9 +19,13 @@ export interface OnboardingCardState { interface OnboardingCardProps { isDialog?: boolean; + showFreeTrialExceededAlert?: boolean; } -export function OnboardingCard({ isDialog }: OnboardingCardProps) { +export function OnboardingCard({ + isDialog, + showFreeTrialExceededAlert, +}: OnboardingCardProps) { const { activeTab, close, setActiveTab } = useOnboardingCard(); const config = useAppSelector((store) => store.config.config); @@ -33,6 +39,8 @@ export function OnboardingCard({ isDialog }: OnboardingCardProps) { return ; case OnboardingModes.LOCAL: return ; + case OnboardingModes.MODELS_ADD_ON: + return ; default: return ; } @@ -45,7 +53,24 @@ export function OnboardingCard({ isDialog }: OnboardingCardProps) { onClose={close} testId="onboarding-card" > - + {showFreeTrialExceededAlert && ( +
+ +

+ Free trial completed +

+ + To keep using Continue, select an option below to setup your + models + +
+
+ )} + {renderTabContent()} ); diff --git a/gui/src/components/OnboardingCard/components/OnboardingCardLanding.tsx b/gui/src/components/OnboardingCard/components/OnboardingCardLanding.tsx index efef32934..3af954188 100644 --- a/gui/src/components/OnboardingCard/components/OnboardingCardLanding.tsx +++ b/gui/src/components/OnboardingCard/components/OnboardingCardLanding.tsx @@ -5,8 +5,8 @@ import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { selectCurrentOrg } from "../../../redux"; import { useAppSelector } from "../../../redux/hooks"; import { hasPassedFTL } from "../../../util/freeTrial"; -import ContinueLogo from "../../gui/ContinueLogo"; import { ToolTip } from "../../gui/Tooltip"; +import ContinueLogo from "../../svg/ContinueLogo"; import { useOnboardingCard } from "../hooks"; export function OnboardingCardLanding({ diff --git a/gui/src/components/OnboardingCard/components/OnboardingCardTabs.tsx b/gui/src/components/OnboardingCard/components/OnboardingCardTabs.tsx index 07de1e42e..5c3eb4829 100644 --- a/gui/src/components/OnboardingCard/components/OnboardingCardTabs.tsx +++ b/gui/src/components/OnboardingCard/components/OnboardingCardTabs.tsx @@ -1,26 +1,64 @@ import { KeyIcon } from "@heroicons/react/24/outline"; import { OnboardingModes } from "core/protocol/core"; +import ContinueSignet from "../../svg/ContinueSignet"; +import OllamaLogo from "../../svg/OllamaLogo"; interface OnboardingCardTabsProps { - /** The currently active tab */ activeTab: OnboardingModes; - /** Callback function called when a tab is clicked */ onTabClick: (tabName: OnboardingModes) => void; + showFreeTrialExceededAlert?: boolean; } -const getTabIcon = (tabTitle: OnboardingModes) => { +const renderTabButton = ( + tabTitle: OnboardingModes, + index: number, + activeTab: OnboardingModes, + onTabClick: (tabName: OnboardingModes) => void, +) => { + const baseButtonClass = `text-foreground -mb-px cursor-pointer rounded-t-sm border-none bg-transparent py-2 font-medium hover:brightness-125 focus:outline-none ${index === 0 ? "pl-1.5 pr-3" : "px-3"} ${activeTab === tabTitle ? "brightness-125" : "brightness-75"}`; + if (tabTitle === OnboardingModes.PROVIDERS) { - return ; - } - if (tabTitle === OnboardingModes.LOCAL) { return ( - Ollama + ); } + + if (tabTitle === OnboardingModes.LOCAL) { + return ( + + ); + } + + if (tabTitle === OnboardingModes.MODELS_ADD_ON) { + return ( + + ); + } + return null; }; @@ -30,28 +68,34 @@ const getTabIcon = (tabTitle: OnboardingModes) => { export function OnboardingCardTabs({ activeTab, onTabClick, + showFreeTrialExceededAlert, }: OnboardingCardTabsProps) { + /** + * When users initially install, we only render these tabs after they've + * declined the free trial, so we show the upgrade tab last since they've + * indicated they want don't want to use the Hub. + * + * If `showFreeTrialExceededAlert` is true, they've used the Hub, so show + * upgrade first. + */ + const tabs = showFreeTrialExceededAlert + ? [ + OnboardingModes.MODELS_ADD_ON, + OnboardingModes.PROVIDERS, + OnboardingModes.LOCAL, + ] + : [ + OnboardingModes.PROVIDERS, + OnboardingModes.LOCAL, + OnboardingModes.MODELS_ADD_ON, + ]; return (
- {Object.values(OnboardingModes).map((tabTitle) => { - const isActive = activeTab === tabTitle; - - return ( - - ); - })} + {tabs.map((tabTitle, index) => + renderTabButton(tabTitle, index, activeTab, onTabClick), + )}
@@ -61,7 +105,7 @@ export function OnboardingCardTabs({ value={activeTab} onChange={(e) => onTabClick(e.target.value as OnboardingModes)} > - {Object.values(OnboardingModes).map((tabTitle) => { + {tabs.map((tabTitle) => { return (