Changesets · Branches · Tags · Compare
| Changeset | dc97a0f5f35c7e9d15a2da58800d8bb9c9447662e5eb0a3399b081fbb500745c |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-09-10 18:41 -07:00 |
| Committer | Dallin Romney <dallinromney@gmail.com> · 2025-09-10 18:41 -07:00 |
| Parents | 08395f969ed7, 8e0cf6e8890e |
204 files changed
deleted .claude/lint-check.sh +0 −20
| @@ -1,20 +0,0 @@ | ||
| 1 | -#!/bin/bash | |
| 2 | - | |
| 3 | -# Get file path from hook input | |
| 4 | -FILE_PATH=$(cat | jq -r '.tool_input.file_path // .tool_input.edits[].file_path // empty' | head -n1) | |
| 5 | - | |
| 6 | -# Function to run lint and typecheck | |
| 7 | -run_checks() { | |
| 8 | - local dir=$1 | |
| 9 | - cd "$dir" | |
| 10 | - npm run lint >&2 && npm run tsc:check >&2 | |
| 11 | -} | |
| 12 | - | |
| 13 | -# Run checks based on file location | |
| 14 | -if [[ "$FILE_PATH" == *"/core/"* ]]; then | |
| 15 | - run_checks core | |
| 16 | -elif [[ "$FILE_PATH" == *"/gui/"* ]]; then | |
| 17 | - run_checks gui | |
| 18 | -elif [[ "$FILE_PATH" == *"/extensions/vscode/"* ]]; then | |
| 19 | - run_checks extensions/vscode | |
| 20 | -fi | |
| No newline at the end of the file |
deleted .claude/settings.json +0 −15
| @@ -1,15 +0,0 @@ | ||
| 1 | -{ | |
| 2 | - "hooks": { | |
| 3 | - "PostToolUse": [ | |
| 4 | - { | |
| 5 | - "matcher": "Write|Edit|MultiEdit", | |
| 6 | - "hooks": [ | |
| 7 | - { | |
| 8 | - "type": "command", | |
| 9 | - "command": "$CLAUDE_PROJECT_DIR/.claude/lint-check.sh" | |
| 10 | - } | |
| 11 | - ] | |
| 12 | - } | |
| 13 | - ] | |
| 14 | - } | |
| 15 | -} |
modified .github/workflows/respond-to-cubic.yaml +2 −2
| @@ -91,7 +91,7 @@ | ||
| 91 | 91 | Please analyze the current PR, understand the request, implement the necessary changes, and commit them to this branch." |
| 92 | 92 | |
| 93 | 93 | # Start remote session and capture JSON output |
| 94 | - SESSION_OUTPUT=$(echo "$PROMPT" | cn remote -s --branch ${{ steps.pr-info.outputs.head_ref }}) | |
| 94 | + SESSION_OUTPUT=$(echo "$PROMPT" | cn remote -s --config continuedev/address-code-review --branch ${{ steps.pr-info.outputs.head_ref }}) | |
| 95 | 95 | echo "Raw session output: $SESSION_OUTPUT" |
| 96 | 96 | |
| 97 | 97 | # Extract URL from JSON output |
| @@ -233,7 +233,7 @@ | ||
| 233 | 233 | |
| 234 | 234 | # Start remote session and capture JSON output |
| 235 | 235 | echo "Starting cn with prompt..." |
| 236 | - SESSION_OUTPUT=$(cat /tmp/prompt.txt | cn remote -s --branch ${{ github.event.pull_request.head.ref }}) | |
| 236 | + SESSION_OUTPUT=$(cat /tmp/prompt.txt | cn remote -s --config continuedev/address-code-review --branch ${{ github.event.pull_request.head.ref }}) | |
| 237 | 237 | echo "Raw session output: $SESSION_OUTPUT" |
| 238 | 238 | |
| 239 | 239 | # Extract URL from JSON output |
modified .vscode/settings.json +2 −1
| @@ -43,7 +43,8 @@ | ||
| 43 | 43 | "extensions/vscode/e2e/storage": true, |
| 44 | 44 | "extensions/vscode/e2e/vsix": true, |
| 45 | 45 | "extensions/.continue-debug": true, |
| 46 | - "extensions/cli/dist/**": true | |
| 46 | + "extensions/cli/dist/**": true, | |
| 47 | + "packages/config-yaml/dist/**": true | |
| 47 | 48 | // "sync/**": true |
| 48 | 49 | }, |
| 49 | 50 | "editor.formatOnSave": true, |
modified core/autocomplete/filtering/streamTransforms/lineStream.ts +7 −2
| @@ -166,8 +166,13 @@ | ||
| 166 | 166 | export const CODE_STOP_BLOCK = "[/CODE]"; |
| 167 | 167 | export const BRACKET_ENDING_CHARS = [")", "]", "}", ";"]; |
| 168 | 168 | export const PREFIXES_TO_SKIP = ["<COMPLETION>"]; |
| 169 | -export const LINES_TO_STOP_AT = ["# End of file.", "<STOP EDITING HERE"]; | |
| 170 | -export const LINES_TO_SKIP = ["</START EDITING HERE>"]; | |
| 169 | +export const LINES_TO_STOP_AT = [ | |
| 170 | + "# End of file.", | |
| 171 | + "<STOP EDITING HERE", | |
| 172 | + "<|/updated_code|>", | |
| 173 | + "```", | |
| 174 | +]; | |
| 175 | +export const LINES_TO_SKIP = ["</START EDITING HERE>", "<|updated_code|>"]; | |
| 171 | 176 | export const LINES_TO_REMOVE_BEFORE_START = [ |
| 172 | 177 | "<COMPLETION>", |
| 173 | 178 | "[CODE]", |
modified core/config/createNewAssistantFile.ts +18 −21
| @@ -1,32 +1,32 @@ | ||
| 1 | 1 | import { IDE } from ".."; |
| 2 | 2 | import { joinPathsToUri } from "../util/uri"; |
| 3 | 3 | |
| 4 | -const DEFAULT_ASSISTANT_FILE = `# This is an example assistant configuration file | |
| 5 | -# It is used to define custom AI assistants within Continue | |
| 6 | -# Each assistant file can be accessed by selecting it from the assistant dropdown | |
| 4 | +const DEFAULT_ASSISTANT_FILE = `# This is an example agent configuration file | |
| 5 | +# It is used to define custom AI agents within Continue | |
| 6 | +# Each agent file can be accessed by selecting it from the agent dropdown | |
| 7 | 7 | |
| 8 | -# To learn more, see the full assistant reference: https://docs.continue.dev/reference | |
| 8 | +# To learn more, see the full config.yaml reference: https://docs.continue.dev/reference | |
| 9 | 9 | |
| 10 | -name: Example Assistant | |
| 10 | +name: Example Agent | |
| 11 | 11 | version: 1.0.0 |
| 12 | 12 | schema: v1 |
| 13 | 13 | |
| 14 | -# Models define which AI models this assistant can use | |
| 14 | +# Models define which AI models this agent can use | |
| 15 | +# https://docs.continue.dev/customization/models | |
| 15 | 16 | models: |
| 16 | 17 | - name: my gpt-5 |
| 17 | 18 | provider: openai |
| 18 | 19 | model: gpt-5 |
| 19 | - apiKey: YOUR_API_KEY_HERE | |
| 20 | + apiKey: YOUR_OPENAI_API_KEY_HERE | |
| 21 | + - uses: ollama/qwen2.5-coder-7b | |
| 22 | + - uses: anthropic/claude-4-sonnet | |
| 23 | + with: | |
| 24 | + ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }} | |
| 20 | 25 | |
| 21 | -# Context providers define what information the assistant can access | |
| 22 | -context: | |
| 23 | - - provider: code | |
| 24 | - - provider: docs | |
| 25 | - - provider: diff | |
| 26 | - - provider: terminal | |
| 27 | - - provider: problems | |
| 28 | - - provider: folder | |
| 29 | - - provider: codebase | |
| 26 | +# MCP Servers the agent can use | |
| 27 | +# https://docs.continue.dev/customization/mcp-tools | |
| 28 | +mcpServers: | |
| 29 | + - uses: anthropic/memory-mcp | |
| 30 | 30 | `; |
| 31 | 31 | |
| 32 | 32 | export async function createNewAssistantFile( |
| @@ -42,7 +42,7 @@ | ||
| 42 | 42 | |
| 43 | 43 | const baseDirUri = joinPathsToUri( |
| 44 | 44 | workspaceDirs[0], |
| 45 | - assistantPath ?? ".continue/assistants", | |
| 45 | + assistantPath ?? ".continue/agents", | |
| 46 | 46 | ); |
| 47 | 47 | |
| 48 | 48 | // Find the first available filename |
| @@ -50,10 +50,7 @@ | ||
| 50 | 50 | let assistantFileUri: string; |
| 51 | 51 | do { |
| 52 | 52 | const suffix = counter === 0 ? "" : `-${counter}`; |
| 53 | - assistantFileUri = joinPathsToUri( | |
| 54 | - baseDirUri, | |
| 55 | - `new-assistant${suffix}.yaml`, | |
| 56 | - ); | |
| 53 | + assistantFileUri = joinPathsToUri(baseDirUri, `new-agent${suffix}.yaml`); | |
| 57 | 54 | counter++; |
| 58 | 55 | } while (await ide.fileExists(assistantFileUri)); |
| 59 | 56 |
modified core/core.ts +6 −1
| @@ -29,8 +29,9 @@ | ||
| 29 | 29 | import { Telemetry } from "./util/posthog"; |
| 30 | 30 | import { |
| 31 | 31 | isProcessBackgrounded, |
| 32 | + killTerminalProcess, | |
| 32 | 33 | markProcessAsBackgrounded, |
| 33 | -} from "./util/processTerminalBackgroundStates"; | |
| 34 | +} from "./util/processTerminalStates"; | |
| 34 | 35 | import { getSymbolsForManyFiles } from "./util/treeSitter"; |
| 35 | 36 | import { TTS } from "./util/tts"; |
| 36 | 37 | |
| @@ -1062,6 +1063,10 @@ | ||
| 1062 | 1063 | }, |
| 1063 | 1064 | ); |
| 1064 | 1065 | |
| 1066 | + on("process/killTerminalProcess", async ({ data: { toolCallId } }) => { | |
| 1067 | + await killTerminalProcess(toolCallId); | |
| 1068 | + }); | |
| 1069 | + | |
| 1065 | 1070 | on("mdm/setLicenseKey", ({ data: { licenseKey } }) => { |
| 1066 | 1071 | const isValid = setMdmLicenseKey(licenseKey); |
| 1067 | 1072 | return isValid; |
modified core/edit/streamDiffLines.ts +18 −17
| @@ -108,23 +108,24 @@ | ||
| 108 | 108 | |
| 109 | 109 | // Rules can be included with edit prompt |
| 110 | 110 | // If any rules are present this will result in using chat instead of legacy completion |
| 111 | - const systemMessage = rulesToInclude | |
| 112 | - ? getSystemMessageWithRules({ | |
| 113 | - availableRules: rulesToInclude, | |
| 114 | - userMessage: | |
| 115 | - typeof prompt === "string" | |
| 116 | - ? ({ | |
| 117 | - role: "user", | |
| 118 | - content: prompt, | |
| 119 | - } as UserChatMessage) | |
| 120 | - : (findLast( | |
| 121 | - prompt, | |
| 122 | - (msg) => msg.role === "user" || msg.role === "tool", | |
| 123 | - ) as UserChatMessage | ToolResultChatMessage | undefined), | |
| 124 | - baseSystemMessage: undefined, | |
| 125 | - contextItems: [], | |
| 126 | - }).systemMessage | |
| 127 | - : undefined; | |
| 111 | + const systemMessage = | |
| 112 | + rulesToInclude || llm.baseChatSystemMessage | |
| 113 | + ? getSystemMessageWithRules({ | |
| 114 | + availableRules: rulesToInclude ?? [], | |
| 115 | + userMessage: | |
| 116 | + typeof prompt === "string" | |
| 117 | + ? ({ | |
| 118 | + role: "user", | |
| 119 | + content: prompt, | |
| 120 | + } as UserChatMessage) | |
| 121 | + : (findLast( | |
| 122 | + prompt, | |
| 123 | + (msg) => msg.role === "user" || msg.role === "tool", | |
| 124 | + ) as UserChatMessage | ToolResultChatMessage | undefined), | |
| 125 | + baseSystemMessage: llm.baseChatSystemMessage, | |
| 126 | + contextItems: [], | |
| 127 | + }).systemMessage | |
| 128 | + : undefined; | |
| 128 | 129 | |
| 129 | 130 | if (systemMessage) { |
| 130 | 131 | if (typeof prompt === "string") { |
modified core/llm/llms/Bedrock.test.ts +91 −1
| @@ -532,7 +532,7 @@ | ||
| 532 | 532 | ); |
| 533 | 533 | }); |
| 534 | 534 | |
| 535 | - it("should add cache points for prompt caching when needed", () => { | |
| 535 | + it("should add cache points when cacheBehavior.cacheConversation is enabled", () => { | |
| 536 | 536 | // Create a test instance with caching behavior enabled |
| 537 | 537 | const bedrockWithCaching = new TestBedrock({ |
| 538 | 538 | apiKey: "test-key", |
| @@ -576,5 +576,95 @@ | ||
| 576 | 576 | const userMessageText = converted[0].content?.[0].text; |
| 577 | 577 | expect(userMessageText).toMatch(/First message.+/); |
| 578 | 578 | }); |
| 579 | + | |
| 580 | + it("should add cache points when completionOptions.promptCaching is enabled", () => { | |
| 581 | + // Create a test instance with prompt caching enabled via completionOptions | |
| 582 | + const bedrockWithPromptCaching = new TestBedrock({ | |
| 583 | + apiKey: "test-key", | |
| 584 | + model: "anthropic.claude-3-sonnet-20240229-v1:0", | |
| 585 | + region: "us-east-1", | |
| 586 | + }); | |
| 587 | + | |
| 588 | + // Set completionOptions.promptCaching (without cacheBehavior) | |
| 589 | + bedrockWithPromptCaching.completionOptions = { | |
| 590 | + ...bedrockWithPromptCaching.completionOptions, | |
| 591 | + promptCaching: true, | |
| 592 | + }; | |
| 593 | + | |
| 594 | + const messages: ChatMessage[] = [ | |
| 595 | + { role: "user", content: "First message" } as UserChatMessage, | |
| 596 | + { role: "assistant", content: "First response" }, | |
| 597 | + { role: "user", content: "Second message" } as UserChatMessage, | |
| 598 | + ]; | |
| 599 | + | |
| 600 | + const availableTools = new Set<string>(); | |
| 601 | + const converted = bedrockWithPromptCaching["_convertMessages"]( | |
| 602 | + messages, | |
| 603 | + availableTools, | |
| 604 | + ); | |
| 605 | + | |
| 606 | + // The last two user messages should have cache points | |
| 607 | + expect(converted.length).toBe(3); | |
| 608 | + expect(converted[0].role).toBe("user"); | |
| 609 | + expect(converted[0].content?.some((block) => block.cachePoint)).toBe( | |
| 610 | + true, | |
| 611 | + ); | |
| 612 | + expect(converted[1].role).toBe("assistant"); | |
| 613 | + expect(converted[2].role).toBe("user"); | |
| 614 | + expect(converted[2].content?.some((block) => block.cachePoint)).toBe( | |
| 615 | + true, | |
| 616 | + ); | |
| 617 | + | |
| 618 | + // Verify that text content includes a cache ID suffix | |
| 619 | + const userMessageText = converted[0].content?.[0].text; | |
| 620 | + expect(userMessageText).toMatch(/First message.+/); | |
| 621 | + }); | |
| 622 | + | |
| 623 | + it("should not add cache points when both caching options are disabled", () => { | |
| 624 | + // Create a test instance with no caching enabled | |
| 625 | + const bedrockNoCaching = new TestBedrock({ | |
| 626 | + apiKey: "test-key", | |
| 627 | + model: "anthropic.claude-3-sonnet-20240229-v1:0", | |
| 628 | + region: "us-east-1", | |
| 629 | + }); | |
| 630 | + | |
| 631 | + // Explicitly set no caching | |
| 632 | + bedrockNoCaching.cacheBehavior = { | |
| 633 | + cacheConversation: false, | |
| 634 | + cacheSystemMessage: false, | |
| 635 | + }; | |
| 636 | + bedrockNoCaching.completionOptions = { | |
| 637 | + ...bedrockNoCaching.completionOptions, | |
| 638 | + promptCaching: false, | |
| 639 | + }; | |
| 640 | + | |
| 641 | + const messages: ChatMessage[] = [ | |
| 642 | + { role: "user", content: "First message" } as UserChatMessage, | |
| 643 | + { role: "assistant", content: "First response" }, | |
| 644 | + { role: "user", content: "Second message" } as UserChatMessage, | |
| 645 | + ]; | |
| 646 | + | |
| 647 | + const availableTools = new Set<string>(); | |
| 648 | + const converted = bedrockNoCaching["_convertMessages"]( | |
| 649 | + messages, | |
| 650 | + availableTools, | |
| 651 | + ); | |
| 652 | + | |
| 653 | + // No cache points should be added | |
| 654 | + expect(converted.length).toBe(3); | |
| 655 | + expect(converted[0].role).toBe("user"); | |
| 656 | + expect(converted[0].content?.some((block) => block.cachePoint)).toBe( | |
| 657 | + false, | |
| 658 | + ); | |
| 659 | + expect(converted[1].role).toBe("assistant"); | |
| 660 | + expect(converted[2].role).toBe("user"); | |
| 661 | + expect(converted[2].content?.some((block) => block.cachePoint)).toBe( | |
| 662 | + false, | |
| 663 | + ); | |
| 664 | + | |
| 665 | + // Verify that text content doesn't include a cache ID suffix | |
| 666 | + const userMessageText = converted[0].content?.[0].text; | |
| 667 | + expect(userMessageText).toBe("First message"); | |
| 668 | + }); | |
| 579 | 669 | }); |
| 580 | 670 | }); |
modified core/llm/llms/Bedrock.ts +4 −1
| @@ -513,7 +513,10 @@ | ||
| 513 | 513 | // The second-to-last because it retrieves potentially already cached contents, |
| 514 | 514 | // The last one because we want it cached for later retrieval. |
| 515 | 515 | // See: https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html |
| 516 | - if (this.cacheBehavior?.cacheConversation) { | |
| 516 | + if ( | |
| 517 | + this.cacheBehavior?.cacheConversation || | |
| 518 | + this.completionOptions.promptCaching | |
| 519 | + ) { | |
| 517 | 520 | this._addCachingToLastTwoUserMessages(converted); |
| 518 | 521 | } |
| 519 | 522 |
modified core/package-lock.json +0 −0
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
modified core/protocol/core.ts +1 −0
| @@ -313,5 +313,6 @@ | ||
| 313 | 313 | ]; |
| 314 | 314 | "process/markAsBackgrounded": [{ toolCallId: string }, void]; |
| 315 | 315 | "process/isBackgrounded": [{ toolCallId: string }, boolean]; |
| 316 | + "process/killTerminalProcess": [{ toolCallId: string }, void]; | |
| 316 | 317 | "mdm/setLicenseKey": [{ licenseKey: string }, boolean]; |
| 317 | 318 | }; |
modified core/protocol/passThrough.ts +1 −0
| @@ -86,6 +86,7 @@ | ||
| 86 | 86 | "isItemTooBig", |
| 87 | 87 | "process/markAsBackgrounded", |
| 88 | 88 | "process/isBackgrounded", |
| 89 | + "process/killTerminalProcess", | |
| 89 | 90 | ]; |
| 90 | 91 | |
| 91 | 92 | // Message types to pass through from core to webview |
modified core/tools/definitions/editFile.ts +2 −2
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | changes: string; |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | -export const NO_PARALLEL_TOOL_CALLING_INTSRUCTION = | |
| 10 | +export const NO_PARALLEL_TOOL_CALLING_INSTRUCTION = | |
| 11 | 11 | "This tool CANNOT be called in parallel with other tools."; |
| 12 | 12 | |
| 13 | 13 | const CHANGES_DESCRIPTION = |
| @@ -24,7 +24,7 @@ | ||
| 24 | 24 | isInstant: false, |
| 25 | 25 | function: { |
| 26 | 26 | name: BuiltInToolNames.EditExistingFile, |
| 27 | - description: `Use this tool to edit an existing file. If you don't know the contents of the file, read it first.\n${EDIT_CODE_INSTRUCTIONS}\n${NO_PARALLEL_TOOL_CALLING_INTSRUCTION}`, | |
| 27 | + description: `Use this tool to edit an existing file. If you don't know the contents of the file, read it first.\n${EDIT_CODE_INSTRUCTIONS}\n${NO_PARALLEL_TOOL_CALLING_INSTRUCTION}`, | |
| 28 | 28 | parameters: { |
| 29 | 29 | type: "object", |
| 30 | 30 | required: ["filepath", "changes"], |
modified core/tools/definitions/multiEdit.ts +2 −2
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | import { Tool } from "../.."; |
| 2 | 2 | import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn"; |
| 3 | -import { NO_PARALLEL_TOOL_CALLING_INTSRUCTION } from "./editFile"; | |
| 3 | +import { NO_PARALLEL_TOOL_CALLING_INSTRUCTION } from "./editFile"; | |
| 4 | 4 | import { singleFindAndReplaceTool } from "./singleFindAndReplace"; |
| 5 | 5 | |
| 6 | 6 | export interface EditOperation { |
| @@ -43,7 +43,7 @@ | ||
| 43 | 43 | |
| 44 | 44 | CRITICAL REQUIREMENTS: |
| 45 | 45 | 1. ALWAYS use the ${BuiltInToolNames.ReadFile} tool just before making edits, to understand the file's up-to-date contents and context. The user can also edit the file while you are working with it. |
| 46 | -2. ${NO_PARALLEL_TOOL_CALLING_INTSRUCTION} | |
| 46 | +2. ${NO_PARALLEL_TOOL_CALLING_INSTRUCTION} | |
| 47 | 47 | 3. When making edits: |
| 48 | 48 | - Ensure all edits result in idiomatic, correct code |
| 49 | 49 | - Do not leave the code in a broken state |
modified core/tools/definitions/singleFindAndReplace.ts +2 −2
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | import { Tool } from "../.."; |
| 2 | 2 | import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn"; |
| 3 | -import { NO_PARALLEL_TOOL_CALLING_INTSRUCTION } from "./editFile"; | |
| 3 | +import { NO_PARALLEL_TOOL_CALLING_INSTRUCTION } from "./editFile"; | |
| 4 | 4 | |
| 5 | 5 | export interface SingleFindAndReplaceArgs { |
| 6 | 6 | filepath: string; |
| @@ -24,7 +24,7 @@ | ||
| 24 | 24 | |
| 25 | 25 | IMPORTANT: |
| 26 | 26 | - ALWAYS use the \`${BuiltInToolNames.ReadFile}\` tool just before making edits, to understand the file's up-to-date contents and context. The user can also edit the file while you are working with it. |
| 27 | -- ${NO_PARALLEL_TOOL_CALLING_INTSRUCTION} | |
| 27 | +- ${NO_PARALLEL_TOOL_CALLING_INSTRUCTION} | |
| 28 | 28 | - When editing text from \`${BuiltInToolNames.ReadFile}\` tool output, ensure you preserve exact whitespace/indentation. |
| 29 | 29 | - Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked. |
| 30 | 30 | - Use \`replace_all\` for replacing and renaming strings across the file. This parameter is useful if you want to rename a variable, for instance. |
modified core/tools/implementations/runTerminalCommand.ts +55 −10
| @@ -36,8 +36,11 @@ | ||
| 36 | 36 | import { ToolImpl } from "."; |
| 37 | 37 | import { |
| 38 | 38 | isProcessBackgrounded, |
| 39 | + markProcessAsRunning, | |
| 39 | 40 | removeBackgroundedProcess, |
| 40 | -} from "../../util/processTerminalBackgroundStates"; | |
| 41 | + removeRunningProcess, | |
| 42 | + updateProcessOutput, | |
| 43 | +} from "../../util/processTerminalStates"; | |
| 41 | 44 | import { getBooleanArg, getStringArg } from "../parseArgs"; |
| 42 | 45 | |
| 43 | 46 | const asyncExec = util.promisify(childProcess.exec); |
| @@ -120,6 +123,16 @@ | ||
| 120 | 123 | env: getColorEnv(), // Add enhanced environment for colors |
| 121 | 124 | }); |
| 122 | 125 | |
| 126 | + // Track this process for foreground cancellation | |
| 127 | + if (toolCallId && waitForCompletion) { | |
| 128 | + markProcessAsRunning( | |
| 129 | + toolCallId, | |
| 130 | + childProc, | |
| 131 | + extras.onPartialOutput, | |
| 132 | + terminalOutput, | |
| 133 | + ); | |
| 134 | + } | |
| 135 | + | |
| 123 | 136 | childProc.stdout?.on("data", (data) => { |
| 124 | 137 | // Skip if this process has been backgrounded |
| 125 | 138 | if (isProcessBackgrounded(toolCallId)) return; |
| @@ -127,6 +140,11 @@ | ||
| 127 | 140 | const newOutput = getDecodedOutput(data); |
| 128 | 141 | terminalOutput += newOutput; |
| 129 | 142 | |
| 143 | + // Update the tracked output for potential cancellation notifications | |
| 144 | + if (toolCallId && waitForCompletion) { | |
| 145 | + updateProcessOutput(toolCallId, terminalOutput); | |
| 146 | + } | |
| 147 | + | |
| 130 | 148 | // Send partial output to UI |
| 131 | 149 | if (extras.onPartialOutput) { |
| 132 | 150 | const status = waitForCompletion |
| @@ -153,6 +171,11 @@ | ||
| 153 | 171 | const newOutput = getDecodedOutput(data); |
| 154 | 172 | terminalOutput += newOutput; |
| 155 | 173 | |
| 174 | + // Update the tracked output for potential cancellation notifications | |
| 175 | + if (toolCallId && waitForCompletion) { | |
| 176 | + updateProcessOutput(toolCallId, terminalOutput); | |
| 177 | + } | |
| 178 | + | |
| 156 | 179 | // Send partial output to UI, status is not required |
| 157 | 180 | if (extras.onPartialOutput) { |
| 158 | 181 | extras.onPartialOutput({ |
| @@ -182,15 +205,19 @@ | ||
| 182 | 205 | } |
| 183 | 206 | |
| 184 | 207 | childProc.on("close", (code) => { |
| 185 | - // If this process has been backgrounded, clean it up from the map and return | |
| 186 | - if (isProcessBackgrounded(toolCallId)) { | |
| 187 | - removeBackgroundedProcess(toolCallId); | |
| 188 | - return; | |
| 208 | + // Clean up process tracking | |
| 209 | + if (toolCallId) { | |
| 210 | + if (isProcessBackgrounded(toolCallId)) { | |
| 211 | + removeBackgroundedProcess(toolCallId); | |
| 212 | + return; | |
| 213 | + } | |
| 214 | + // Remove from foreground tracking if it was tracked | |
| 215 | + removeRunningProcess(toolCallId); | |
| 189 | 216 | } |
| 190 | 217 | |
| 191 | 218 | if (waitForCompletion) { |
| 192 | 219 | // Normal completion, resolve now |
| 193 | - if (code === 0) { | |
| 220 | + if (!code || code === 0) { | |
| 194 | 221 | const status = "Command completed"; |
| 195 | 222 | resolve([ |
| 196 | 223 | { |
| @@ -234,10 +261,14 @@ | ||
| 234 | 261 | }); |
| 235 | 262 | |
| 236 | 263 | childProc.on("error", (error) => { |
| 237 | - // If this process has been backgrounded, clean it up from the map and return | |
| 238 | - if (isProcessBackgrounded(toolCallId)) { | |
| 239 | - removeBackgroundedProcess(toolCallId); | |
| 240 | - return; | |
| 264 | + // Clean up process tracking | |
| 265 | + if (toolCallId) { | |
| 266 | + if (isProcessBackgrounded(toolCallId)) { | |
| 267 | + removeBackgroundedProcess(toolCallId); | |
| 268 | + return; | |
| 269 | + } | |
| 270 | + // Remove from foreground tracking if it was tracked | |
| 271 | + removeRunningProcess(toolCallId); | |
| 241 | 272 | } |
| 242 | 273 | |
| 243 | 274 | reject(error); |
| @@ -281,6 +312,11 @@ | ||
| 281 | 312 | }, |
| 282 | 313 | ); |
| 283 | 314 | |
| 315 | + // Track this process for foreground cancellation | |
| 316 | + if (toolCallId) { | |
| 317 | + markProcessAsRunning(toolCallId, childProc, undefined, ""); | |
| 318 | + } | |
| 319 | + | |
| 284 | 320 | let stdout = ""; |
| 285 | 321 | let stderr = ""; |
| 286 | 322 | |
| @@ -293,6 +329,11 @@ | ||
| 293 | 329 | }); |
| 294 | 330 | |
| 295 | 331 | childProc.on("close", (code) => { |
| 332 | + // Clean up process tracking | |
| 333 | + if (toolCallId) { | |
| 334 | + removeRunningProcess(toolCallId); | |
| 335 | + } | |
| 336 | + | |
| 296 | 337 | if (code === 0) { |
| 297 | 338 | resolve({ stdout, stderr }); |
| 298 | 339 | } else { |
| @@ -305,6 +346,10 @@ | ||
| 305 | 346 | }); |
| 306 | 347 | |
| 307 | 348 | childProc.on("error", (error) => { |
| 349 | + // Clean up process tracking | |
| 350 | + if (toolCallId) { | |
| 351 | + removeRunningProcess(toolCallId); | |
| 352 | + } | |
| 308 | 353 | reject(error); |
| 309 | 354 | }); |
| 310 | 355 | }, |
modified core/tools/implementations/runTerminalCommand.vitest.ts +3 −7
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | import * as os from "node:os"; |
| 13 | 13 | import * as path from "node:path"; |
| 14 | 14 | import { IDE, ToolExtras } from "../.."; |
| 15 | -import * as processBackgroundStates from "../../util/processTerminalBackgroundStates"; | |
| 15 | +import * as processTerminalStates from "../../util/processTerminalStates"; | |
| 16 | 16 | import { runTerminalCommandImpl } from "./runTerminalCommand"; |
| 17 | 17 | import { runTerminalCommandTool } from "../definitions/runTerminalCommand"; |
| 18 | 18 | |
| @@ -39,12 +39,8 @@ | ||
| 39 | 39 | vi.resetAllMocks(); |
| 40 | 40 | |
| 41 | 41 | // Setup backgrounded processes handling - don't mock, just make sure it's empty |
| 42 | - // Get any processes that might be already tracked and clear them | |
| 43 | - const processMap = (processBackgroundStates as any) | |
| 44 | - .processTerminalBackgroundStates; | |
| 45 | - if (processMap && typeof processMap.clear === "function") { | |
| 46 | - processMap.clear(); | |
| 47 | - } | |
| 42 | + // Clear any processes that might be already tracked | |
| 43 | + processTerminalStates.clearAllBackgroundProcesses(); | |
| 48 | 44 | |
| 49 | 45 | // Setup IDE mocks |
| 50 | 46 | mockGetIdeInfo.mockReturnValue(Promise.resolve({ remoteName: "local" })); |
modified core/util/messageContent.ts +15 −0
| @@ -35,6 +35,21 @@ | ||
| 35 | 35 | return contextItems.map((item) => item.content).join("\n\n"); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | +export function renderContextItemsWithStatus(contextItems: any[]): string { | |
| 39 | + return contextItems | |
| 40 | + .map((item) => { | |
| 41 | + let result = item.content; | |
| 42 | + | |
| 43 | + // If this item has a status, append it directly after the content | |
| 44 | + if (item.status) { | |
| 45 | + result += `\n[Status: ${item.status}]`; | |
| 46 | + } | |
| 47 | + | |
| 48 | + return result; | |
| 49 | + }) | |
| 50 | + .join("\n\n"); | |
| 51 | +} | |
| 52 | + | |
| 38 | 53 | export function normalizeToMessageParts(message: ChatMessage): MessagePart[] { |
| 39 | 54 | switch (message.role) { |
| 40 | 55 | case "user": |
deleted core/util/processTerminalBackgroundStates.test.ts +0 −73
| @@ -1,73 +0,0 @@ | ||
| 1 | -import { | |
| 2 | - markProcessAsBackgrounded, | |
| 3 | - isProcessBackgrounded, | |
| 4 | - removeBackgroundedProcess, | |
| 5 | -} from "./processTerminalBackgroundStates"; | |
| 6 | - | |
| 7 | -describe("processTerminalBackgroundStates", () => { | |
| 8 | - beforeEach(() => { | |
| 9 | - // Clear any backgrounded processes before each test | |
| 10 | - const backgroundedProcesses = Array.from( | |
| 11 | - Object.getOwnPropertySymbols(global), | |
| 12 | - ).find( | |
| 13 | - (symbol) => String(symbol) === "Symbol(processTerminalBackgroundStates)", | |
| 14 | - ); | |
| 15 | - | |
| 16 | - if (backgroundedProcesses) { | |
| 17 | - // Reset the map by reimporting the module | |
| 18 | - jest.resetModules(); | |
| 19 | - } | |
| 20 | - }); | |
| 21 | - | |
| 22 | - test("should mark a process as backgrounded", () => { | |
| 23 | - const toolCallId = "test-123"; | |
| 24 | - markProcessAsBackgrounded(toolCallId); | |
| 25 | - expect(isProcessBackgrounded(toolCallId)).toBe(true); | |
| 26 | - }); | |
| 27 | - | |
| 28 | - test("should correctly identify non-backgrounded processes", () => { | |
| 29 | - const toolCallId = "test-123"; | |
| 30 | - const anotherToolCallId = "test-456"; | |
| 31 | - | |
| 32 | - markProcessAsBackgrounded(toolCallId); | |
| 33 | - | |
| 34 | - expect(isProcessBackgrounded(toolCallId)).toBe(true); | |
| 35 | - expect(isProcessBackgrounded(anotherToolCallId)).toBe(false); | |
| 36 | - }); | |
| 37 | - | |
| 38 | - test("should remove a process from backgrounded state", () => { | |
| 39 | - const toolCallId = "test-123"; | |
| 40 | - | |
| 41 | - markProcessAsBackgrounded(toolCallId); | |
| 42 | - expect(isProcessBackgrounded(toolCallId)).toBe(true); | |
| 43 | - | |
| 44 | - removeBackgroundedProcess(toolCallId); | |
| 45 | - expect(isProcessBackgrounded(toolCallId)).toBe(false); | |
| 46 | - }); | |
| 47 | - | |
| 48 | - test("should handle removing non-existent processes", () => { | |
| 49 | - const toolCallId = "test-123"; | |
| 50 | - | |
| 51 | - // Should not throw an error | |
| 52 | - removeBackgroundedProcess(toolCallId); | |
| 53 | - expect(isProcessBackgrounded(toolCallId)).toBe(false); | |
| 54 | - }); | |
| 55 | - | |
| 56 | - test("should handle multiple processes", () => { | |
| 57 | - const toolCallId1 = "test-123"; | |
| 58 | - const toolCallId2 = "test-456"; | |
| 59 | - const toolCallId3 = "test-789"; | |
| 60 | - | |
| 61 | - markProcessAsBackgrounded(toolCallId1); | |
| 62 | - markProcessAsBackgrounded(toolCallId2); | |
| 63 | - | |
| 64 | - expect(isProcessBackgrounded(toolCallId1)).toBe(true); | |
| 65 | - expect(isProcessBackgrounded(toolCallId2)).toBe(true); | |
| 66 | - expect(isProcessBackgrounded(toolCallId3)).toBe(false); | |
| 67 | - | |
| 68 | - removeBackgroundedProcess(toolCallId1); | |
| 69 | - | |
| 70 | - expect(isProcessBackgrounded(toolCallId1)).toBe(false); | |
| 71 | - expect(isProcessBackgrounded(toolCallId2)).toBe(true); | |
| 72 | - }); | |
| 73 | -}); |
deleted core/util/processTerminalBackgroundStates.ts +0 −17
| @@ -1,17 +0,0 @@ | ||
| 1 | -// Track which processes have been backgrounded | |
| 2 | -const processTerminalBackgroundStates = new Map<string, boolean>(); | |
| 3 | - | |
| 4 | -// Function to mark a process as backgrounded | |
| 5 | -export function markProcessAsBackgrounded(toolCallId: string): void { | |
| 6 | - processTerminalBackgroundStates.set(toolCallId, true); | |
| 7 | -} | |
| 8 | - | |
| 9 | -// Function to check if a process is backgrounded | |
| 10 | -export function isProcessBackgrounded(toolCallId: string): boolean { | |
| 11 | - return processTerminalBackgroundStates.has(toolCallId); | |
| 12 | -} | |
| 13 | - | |
| 14 | -// Function to remove a process from the backgrounded processes map | |
| 15 | -export function removeBackgroundedProcess(toolCallId: string): void { | |
| 16 | - processTerminalBackgroundStates.delete(toolCallId); | |
| 17 | -} |
added core/util/processTerminalStates.test.ts +367 −0
| @@ -0,0 +1,367 @@ | ||
| 1 | +import { ChildProcess } from "child_process"; | |
| 2 | +import { | |
| 3 | + clearAllBackgroundProcesses, | |
| 4 | + getAllBackgroundedProcessIds, | |
| 5 | + getAllRunningProcessIds, | |
| 6 | + getRunningProcess, | |
| 7 | + isProcessBackgrounded, | |
| 8 | + isProcessRunning, | |
| 9 | + killAllRunningTerminalProcesses, | |
| 10 | + killMultipleTerminalProcesses, | |
| 11 | + killTerminalProcess, | |
| 12 | + markProcessAsBackgrounded, | |
| 13 | + markProcessAsRunning, | |
| 14 | + removeBackgroundedProcess, | |
| 15 | + removeRunningProcess, | |
| 16 | + updateProcessOutput, | |
| 17 | +} from "./processTerminalStates"; | |
| 18 | + | |
| 19 | +// Mock ChildProcess | |
| 20 | +const createMockProcess = ( | |
| 21 | + pid: number = 123, | |
| 22 | + killed: boolean = false, | |
| 23 | +): jest.Mocked<ChildProcess> => { | |
| 24 | + const mockProcess = { | |
| 25 | + pid, | |
| 26 | + killed, | |
| 27 | + kill: jest.fn(), | |
| 28 | + } as unknown as jest.Mocked<ChildProcess>; | |
| 29 | + | |
| 30 | + // Make kill() update the killed property | |
| 31 | + mockProcess.kill.mockImplementation(() => { | |
| 32 | + (mockProcess as any).killed = true; | |
| 33 | + return true; | |
| 34 | + }); | |
| 35 | + | |
| 36 | + return mockProcess; | |
| 37 | +}; | |
| 38 | + | |
| 39 | +describe("processTerminalStates", () => { | |
| 40 | + beforeEach(() => { | |
| 41 | + // Clear all running processes | |
| 42 | + const runningIds = getAllRunningProcessIds(); | |
| 43 | + runningIds.forEach((id) => removeRunningProcess(id)); | |
| 44 | + | |
| 45 | + // Clear all backgrounded processes | |
| 46 | + const backgroundedIds = getAllBackgroundedProcessIds(); | |
| 47 | + backgroundedIds.forEach((id) => removeBackgroundedProcess(id)); | |
| 48 | + | |
| 49 | + // Clear all timers | |
| 50 | + jest.clearAllTimers(); | |
| 51 | + }); | |
| 52 | + | |
| 53 | + test("should mark a process as backgrounded", () => { | |
| 54 | + const toolCallId = "test-123"; | |
| 55 | + markProcessAsBackgrounded(toolCallId); | |
| 56 | + expect(isProcessBackgrounded(toolCallId)).toBe(true); | |
| 57 | + }); | |
| 58 | + | |
| 59 | + test("should correctly identify non-backgrounded processes", () => { | |
| 60 | + const toolCallId = "test-123"; | |
| 61 | + const anotherToolCallId = "test-456"; | |
| 62 | + | |
| 63 | + markProcessAsBackgrounded(toolCallId); | |
| 64 | + | |
| 65 | + expect(isProcessBackgrounded(toolCallId)).toBe(true); | |
| 66 | + expect(isProcessBackgrounded(anotherToolCallId)).toBe(false); | |
| 67 | + }); | |
| 68 | + | |
| 69 | + test("should remove a process from backgrounded state", () => { | |
| 70 | + const toolCallId = "test-123"; | |
| 71 | + | |
| 72 | + markProcessAsBackgrounded(toolCallId); | |
| 73 | + expect(isProcessBackgrounded(toolCallId)).toBe(true); | |
| 74 | + | |
| 75 | + removeBackgroundedProcess(toolCallId); | |
| 76 | + expect(isProcessBackgrounded(toolCallId)).toBe(false); | |
| 77 | + }); | |
| 78 | + | |
| 79 | + test("should handle removing non-existent processes", () => { | |
| 80 | + const toolCallId = "test-123"; | |
| 81 | + | |
| 82 | + // Should not throw an error | |
| 83 | + removeBackgroundedProcess(toolCallId); | |
| 84 | + expect(isProcessBackgrounded(toolCallId)).toBe(false); | |
| 85 | + }); | |
| 86 | + | |
| 87 | + test("should handle multiple processes", () => { | |
| 88 | + const toolCallId1 = "test-123"; | |
| 89 | + const toolCallId2 = "test-456"; | |
| 90 | + const toolCallId3 = "test-789"; | |
| 91 | + | |
| 92 | + markProcessAsBackgrounded(toolCallId1); | |
| 93 | + markProcessAsBackgrounded(toolCallId2); | |
| 94 | + | |
| 95 | + expect(isProcessBackgrounded(toolCallId1)).toBe(true); | |
| 96 | + expect(isProcessBackgrounded(toolCallId2)).toBe(true); | |
| 97 | + expect(isProcessBackgrounded(toolCallId3)).toBe(false); | |
| 98 | + | |
| 99 | + removeBackgroundedProcess(toolCallId1); | |
| 100 | + | |
| 101 | + expect(isProcessBackgrounded(toolCallId1)).toBe(false); | |
| 102 | + expect(isProcessBackgrounded(toolCallId2)).toBe(true); | |
| 103 | + }); | |
| 104 | + | |
| 105 | + describe("foreground process functions", () => { | |
| 106 | + test("should mark a process as running", () => { | |
| 107 | + const toolCallId = "test-123"; | |
| 108 | + const mockProcess = createMockProcess(); | |
| 109 | + const mockCallback = jest.fn(); | |
| 110 | + const initialOutput = "initial output"; | |
| 111 | + | |
| 112 | + markProcessAsRunning( | |
| 113 | + toolCallId, | |
| 114 | + mockProcess, | |
| 115 | + mockCallback, | |
| 116 | + initialOutput, | |
| 117 | + ); | |
| 118 | + | |
| 119 | + expect(isProcessRunning(toolCallId)).toBe(true); | |
| 120 | + expect(getRunningProcess(toolCallId)).toBe(mockProcess); | |
| 121 | + }); | |
| 122 | + | |
| 123 | + test("should handle process without callback or initial output", () => { | |
| 124 | + const toolCallId = "test-123"; | |
| 125 | + const mockProcess = createMockProcess(); | |
| 126 | + | |
| 127 | + markProcessAsRunning(toolCallId, mockProcess); | |
| 128 | + | |
| 129 | + expect(isProcessRunning(toolCallId)).toBe(true); | |
| 130 | + expect(getRunningProcess(toolCallId)).toBe(mockProcess); | |
| 131 | + }); | |
| 132 | + | |
| 133 | + test("should correctly identify non-running processes", () => { | |
| 134 | + const toolCallId = "test-123"; | |
| 135 | + const anotherToolCallId = "test-456"; | |
| 136 | + const mockProcess = createMockProcess(); | |
| 137 | + | |
| 138 | + markProcessAsRunning(toolCallId, mockProcess); | |
| 139 | + | |
| 140 | + expect(isProcessRunning(toolCallId)).toBe(true); | |
| 141 | + expect(isProcessRunning(anotherToolCallId)).toBe(false); | |
| 142 | + }); | |
| 143 | + | |
| 144 | + test("should update process output", () => { | |
| 145 | + const toolCallId = "test-123"; | |
| 146 | + const mockProcess = createMockProcess(); | |
| 147 | + const initialOutput = "initial"; | |
| 148 | + const updatedOutput = "updated output"; | |
| 149 | + | |
| 150 | + markProcessAsRunning(toolCallId, mockProcess, undefined, initialOutput); | |
| 151 | + updateProcessOutput(toolCallId, updatedOutput); | |
| 152 | + | |
| 153 | + // We can't directly test the output value, but we can ensure the function doesn't throw | |
| 154 | + expect(() => | |
| 155 | + updateProcessOutput(toolCallId, updatedOutput), | |
| 156 | + ).not.toThrow(); | |
| 157 | + }); | |
| 158 | + | |
| 159 | + test("should handle updating output for non-existent process", () => { | |
| 160 | + const toolCallId = "non-existent"; | |
| 161 | + | |
| 162 | + expect(() => | |
| 163 | + updateProcessOutput(toolCallId, "some output"), | |
| 164 | + ).not.toThrow(); | |
| 165 | + }); | |
| 166 | + | |
| 167 | + test("should remove a process from running state", () => { | |
| 168 | + const toolCallId = "test-123"; | |
| 169 | + const mockProcess = createMockProcess(); | |
| 170 | + | |
| 171 | + markProcessAsRunning(toolCallId, mockProcess); | |
| 172 | + expect(isProcessRunning(toolCallId)).toBe(true); | |
| 173 | + | |
| 174 | + removeRunningProcess(toolCallId); | |
| 175 | + expect(isProcessRunning(toolCallId)).toBe(false); | |
| 176 | + expect(getRunningProcess(toolCallId)).toBeUndefined(); | |
| 177 | + }); | |
| 178 | + | |
| 179 | + test("should handle removing non-existent running processes", () => { | |
| 180 | + const toolCallId = "test-123"; | |
| 181 | + | |
| 182 | + expect(() => removeRunningProcess(toolCallId)).not.toThrow(); | |
| 183 | + expect(isProcessRunning(toolCallId)).toBe(false); | |
| 184 | + }); | |
| 185 | + | |
| 186 | + test("should return undefined for non-existent running process", () => { | |
| 187 | + const toolCallId = "non-existent"; | |
| 188 | + | |
| 189 | + expect(getRunningProcess(toolCallId)).toBeUndefined(); | |
| 190 | + }); | |
| 191 | + }); | |
| 192 | + | |
| 193 | + describe("terminal command cancellation", () => { | |
| 194 | + beforeEach(() => { | |
| 195 | + jest.useFakeTimers(); | |
| 196 | + }); | |
| 197 | + | |
| 198 | + afterEach(() => { | |
| 199 | + jest.useRealTimers(); | |
| 200 | + }); | |
| 201 | + | |
| 202 | + test("should cancel a running terminal command", async () => { | |
| 203 | + const toolCallId = "test-123"; | |
| 204 | + const mockProcess = createMockProcess(); | |
| 205 | + | |
| 206 | + markProcessAsRunning(toolCallId, mockProcess); | |
| 207 | + expect(isProcessRunning(toolCallId)).toBe(true); | |
| 208 | + | |
| 209 | + await killTerminalProcess(toolCallId); | |
| 210 | + | |
| 211 | + expect(mockProcess.kill).toHaveBeenCalledWith("SIGTERM"); | |
| 212 | + expect(isProcessRunning(toolCallId)).toBe(false); | |
| 213 | + }); | |
| 214 | + | |
| 215 | + test("should handle cancelling non-existent process", async () => { | |
| 216 | + const toolCallId = "non-existent"; | |
| 217 | + | |
| 218 | + await expect(killTerminalProcess(toolCallId)).resolves.not.toThrow(); | |
| 219 | + }); | |
| 220 | + | |
| 221 | + test("should handle cancelling already killed process", async () => { | |
| 222 | + const toolCallId = "test-123"; | |
| 223 | + const mockProcess = createMockProcess(123, true); // Already killed | |
| 224 | + | |
| 225 | + markProcessAsRunning(toolCallId, mockProcess); | |
| 226 | + | |
| 227 | + await killTerminalProcess(toolCallId); | |
| 228 | + | |
| 229 | + expect(mockProcess.kill).not.toHaveBeenCalled(); | |
| 230 | + }); | |
| 231 | + | |
| 232 | + test("should send SIGKILL after timeout if process not killed", async () => { | |
| 233 | + const toolCallId = "test-123"; | |
| 234 | + const mockProcess = createMockProcess(); | |
| 235 | + | |
| 236 | + // Mock kill to not actually set killed=true for SIGTERM | |
| 237 | + mockProcess.kill.mockImplementation((signal) => { | |
| 238 | + if (signal === "SIGKILL") { | |
| 239 | + (mockProcess as any).killed = true; | |
| 240 | + } | |
| 241 | + return true; | |
| 242 | + }); | |
| 243 | + | |
| 244 | + markProcessAsRunning(toolCallId, mockProcess); | |
| 245 | + | |
| 246 | + const cancelPromise = killTerminalProcess(toolCallId); | |
| 247 | + | |
| 248 | + // Fast-forward time to trigger the timeout | |
| 249 | + jest.advanceTimersByTime(5000); | |
| 250 | + | |
| 251 | + await cancelPromise; | |
| 252 | + | |
| 253 | + expect(mockProcess.kill).toHaveBeenCalledWith("SIGTERM"); | |
| 254 | + expect(mockProcess.kill).toHaveBeenCalledWith("SIGKILL"); | |
| 255 | + }); | |
| 256 | + | |
| 257 | + test("should not send SIGKILL if process was already killed", async () => { | |
| 258 | + const toolCallId = "test-123"; | |
| 259 | + const mockProcess = createMockProcess(); | |
| 260 | + | |
| 261 | + markProcessAsRunning(toolCallId, mockProcess); | |
| 262 | + | |
| 263 | + const cancelPromise = killTerminalProcess(toolCallId); | |
| 264 | + | |
| 265 | + // Fast-forward time to trigger the timeout | |
| 266 | + jest.advanceTimersByTime(5000); | |
| 267 | + | |
| 268 | + await cancelPromise; | |
| 269 | + | |
| 270 | + expect(mockProcess.kill).toHaveBeenCalledWith("SIGTERM"); | |
| 271 | + expect(mockProcess.kill).toHaveBeenCalledTimes(1); // Only SIGTERM, no SIGKILL | |
| 272 | + }); | |
| 273 | + }); | |
| 274 | + | |
| 275 | + describe("utility functions", () => { | |
| 276 | + test("should get all running process IDs", () => { | |
| 277 | + const toolCallId1 = "test-123"; | |
| 278 | + const toolCallId2 = "test-456"; | |
| 279 | + const mockProcess1 = createMockProcess(123); | |
| 280 | + const mockProcess2 = createMockProcess(456); | |
| 281 | + | |
| 282 | + markProcessAsRunning(toolCallId1, mockProcess1); | |
| 283 | + markProcessAsRunning(toolCallId2, mockProcess2); | |
| 284 | + | |
| 285 | + const runningIds = getAllRunningProcessIds(); | |
| 286 | + expect(runningIds).toContain(toolCallId1); | |
| 287 | + expect(runningIds).toContain(toolCallId2); | |
| 288 | + expect(runningIds).toHaveLength(2); | |
| 289 | + }); | |
| 290 | + | |
| 291 | + test("should get all backgrounded process IDs", () => { | |
| 292 | + const toolCallId1 = "test-123"; | |
| 293 | + const toolCallId2 = "test-456"; | |
| 294 | + | |
| 295 | + markProcessAsBackgrounded(toolCallId1); | |
| 296 | + markProcessAsBackgrounded(toolCallId2); | |
| 297 | + | |
| 298 | + const backgroundedIds = getAllBackgroundedProcessIds(); | |
| 299 | + expect(backgroundedIds).toContain(toolCallId1); | |
| 300 | + expect(backgroundedIds).toContain(toolCallId2); | |
| 301 | + expect(backgroundedIds).toHaveLength(2); | |
| 302 | + }); | |
| 303 | + | |
| 304 | + test("should return empty arrays when no processes", () => { | |
| 305 | + expect(getAllRunningProcessIds()).toEqual([]); | |
| 306 | + expect(getAllBackgroundedProcessIds()).toEqual([]); | |
| 307 | + }); | |
| 308 | + | |
| 309 | + test("should cancel multiple terminal commands", async () => { | |
| 310 | + const toolCallId1 = "test-123"; | |
| 311 | + const toolCallId2 = "test-456"; | |
| 312 | + const mockProcess1 = createMockProcess(123); | |
| 313 | + const mockProcess2 = createMockProcess(456); | |
| 314 | + | |
| 315 | + markProcessAsRunning(toolCallId1, mockProcess1); | |
| 316 | + markProcessAsRunning(toolCallId2, mockProcess2); | |
| 317 | + | |
| 318 | + await killMultipleTerminalProcesses([toolCallId1, toolCallId2]); | |
| 319 | + | |
| 320 | + expect(mockProcess1.kill).toHaveBeenCalledWith("SIGTERM"); | |
| 321 | + expect(mockProcess2.kill).toHaveBeenCalledWith("SIGTERM"); | |
| 322 | + expect(isProcessRunning(toolCallId1)).toBe(false); | |
| 323 | + expect(isProcessRunning(toolCallId2)).toBe(false); | |
| 324 | + }); | |
| 325 | + | |
| 326 | + test("should cancel all running terminal commands", async () => { | |
| 327 | + const toolCallId1 = "test-123"; | |
| 328 | + const toolCallId2 = "test-456"; | |
| 329 | + const mockProcess1 = createMockProcess(123); | |
| 330 | + const mockProcess2 = createMockProcess(456); | |
| 331 | + | |
| 332 | + markProcessAsRunning(toolCallId1, mockProcess1); | |
| 333 | + markProcessAsRunning(toolCallId2, mockProcess2); | |
| 334 | + | |
| 335 | + const cancelledIds = await killAllRunningTerminalProcesses(); | |
| 336 | + | |
| 337 | + expect(cancelledIds).toContain(toolCallId1); | |
| 338 | + expect(cancelledIds).toContain(toolCallId2); | |
| 339 | + expect(cancelledIds).toHaveLength(2); | |
| 340 | + expect(mockProcess1.kill).toHaveBeenCalledWith("SIGTERM"); | |
| 341 | + expect(mockProcess2.kill).toHaveBeenCalledWith("SIGTERM"); | |
| 342 | + expect(isProcessRunning(toolCallId1)).toBe(false); | |
| 343 | + expect(isProcessRunning(toolCallId2)).toBe(false); | |
| 344 | + }); | |
| 345 | + | |
| 346 | + test("should return empty array when no running commands to cancel", async () => { | |
| 347 | + const cancelledIds = await killAllRunningTerminalProcesses(); | |
| 348 | + expect(cancelledIds).toEqual([]); | |
| 349 | + }); | |
| 350 | + | |
| 351 | + test("should clear all background processes", () => { | |
| 352 | + const toolCallId1 = "test-123"; | |
| 353 | + const toolCallId2 = "test-456"; | |
| 354 | + | |
| 355 | + markProcessAsBackgrounded(toolCallId1); | |
| 356 | + markProcessAsBackgrounded(toolCallId2); | |
| 357 | + | |
| 358 | + expect(getAllBackgroundedProcessIds()).toHaveLength(2); | |
| 359 | + | |
| 360 | + clearAllBackgroundProcesses(); | |
| 361 | + | |
| 362 | + expect(getAllBackgroundedProcessIds()).toEqual([]); | |
| 363 | + expect(isProcessBackgrounded(toolCallId1)).toBe(false); | |
| 364 | + expect(isProcessBackgrounded(toolCallId2)).toBe(false); | |
| 365 | + }); | |
| 366 | + }); | |
| 367 | +}); |
added core/util/processTerminalStates.ts +119 −0
| @@ -0,0 +1,119 @@ | ||
| 1 | +import { ChildProcess } from "child_process"; | |
| 2 | + | |
| 3 | +// Track which processes have been backgrounded | |
| 4 | +const processTerminalBackgroundStates = new Map<string, boolean>(); | |
| 5 | + | |
| 6 | +// Track which foreground processes are currently running | |
| 7 | +interface RunningProcessInfo { | |
| 8 | + process: ChildProcess; | |
| 9 | + onPartialOutput?: (params: { | |
| 10 | + toolCallId: string; | |
| 11 | + contextItems: any[]; | |
| 12 | + }) => void; | |
| 13 | + currentOutput: string; | |
| 14 | +} | |
| 15 | + | |
| 16 | +const processTerminalForegroundStates = new Map<string, RunningProcessInfo>(); | |
| 17 | + | |
| 18 | +// Background process functions (existing) | |
| 19 | +export function markProcessAsBackgrounded(toolCallId: string): void { | |
| 20 | + processTerminalBackgroundStates.set(toolCallId, true); | |
| 21 | +} | |
| 22 | + | |
| 23 | +export function isProcessBackgrounded(toolCallId: string): boolean { | |
| 24 | + return processTerminalBackgroundStates.has(toolCallId); | |
| 25 | +} | |
| 26 | + | |
| 27 | +export function removeBackgroundedProcess(toolCallId: string): void { | |
| 28 | + processTerminalBackgroundStates.delete(toolCallId); | |
| 29 | +} | |
| 30 | + | |
| 31 | +// Foreground process functions (new) | |
| 32 | +export function markProcessAsRunning( | |
| 33 | + toolCallId: string, | |
| 34 | + process: ChildProcess, | |
| 35 | + onPartialOutput?: (params: { | |
| 36 | + toolCallId: string; | |
| 37 | + contextItems: any[]; | |
| 38 | + }) => void, | |
| 39 | + currentOutput: string = "", | |
| 40 | +): void { | |
| 41 | + processTerminalForegroundStates.set(toolCallId, { | |
| 42 | + process, | |
| 43 | + onPartialOutput, | |
| 44 | + currentOutput, | |
| 45 | + }); | |
| 46 | +} | |
| 47 | + | |
| 48 | +export function isProcessRunning(toolCallId: string): boolean { | |
| 49 | + return processTerminalForegroundStates.has(toolCallId); | |
| 50 | +} | |
| 51 | + | |
| 52 | +export function getRunningProcess( | |
| 53 | + toolCallId: string, | |
| 54 | +): ChildProcess | undefined { | |
| 55 | + const info = processTerminalForegroundStates.get(toolCallId); | |
| 56 | + return info?.process; | |
| 57 | +} | |
| 58 | + | |
| 59 | +export function updateProcessOutput(toolCallId: string, output: string): void { | |
| 60 | + const info = processTerminalForegroundStates.get(toolCallId); | |
| 61 | + if (info) { | |
| 62 | + info.currentOutput = output; | |
| 63 | + } | |
| 64 | +} | |
| 65 | + | |
| 66 | +export function removeRunningProcess(toolCallId: string): void { | |
| 67 | + processTerminalForegroundStates.delete(toolCallId); | |
| 68 | +} | |
| 69 | + | |
| 70 | +export async function killTerminalProcess(toolCallId: string): Promise<void> { | |
| 71 | + const processInfo = processTerminalForegroundStates.get(toolCallId); | |
| 72 | + if (processInfo && !processInfo.process.killed) { | |
| 73 | + const { process } = processInfo; | |
| 74 | + | |
| 75 | + process.kill("SIGTERM"); | |
| 76 | + | |
| 77 | + // Force kill after 5 seconds if still running | |
| 78 | + setTimeout(() => { | |
| 79 | + if (!process.killed) { | |
| 80 | + process.kill("SIGKILL"); | |
| 81 | + } | |
| 82 | + }, 5000); | |
| 83 | + | |
| 84 | + processTerminalForegroundStates.delete(toolCallId); | |
| 85 | + } | |
| 86 | +} | |
| 87 | + | |
| 88 | +// Function to cancel multiple terminal commands at once | |
| 89 | +export async function killMultipleTerminalProcesses( | |
| 90 | + toolCallIds: string[], | |
| 91 | +): Promise<void> { | |
| 92 | + const cancelPromises = toolCallIds.map((toolCallId) => | |
| 93 | + killTerminalProcess(toolCallId), | |
| 94 | + ); | |
| 95 | + await Promise.all(cancelPromises); | |
| 96 | +} | |
| 97 | + | |
| 98 | +// Function to cancel ALL currently running terminal commands | |
| 99 | +export async function killAllRunningTerminalProcesses(): Promise<string[]> { | |
| 100 | + const runningIds = getAllRunningProcessIds(); | |
| 101 | + if (runningIds.length > 0) { | |
| 102 | + await killMultipleTerminalProcesses(runningIds); | |
| 103 | + } | |
| 104 | + return runningIds; // Return the IDs that were cancelled | |
| 105 | +} | |
| 106 | + | |
| 107 | +// Utility functions | |
| 108 | +export function getAllRunningProcessIds(): string[] { | |
| 109 | + return Array.from(processTerminalForegroundStates.keys()); | |
| 110 | +} | |
| 111 | + | |
| 112 | +export function getAllBackgroundedProcessIds(): string[] { | |
| 113 | + return Array.from(processTerminalBackgroundStates.keys()); | |
| 114 | +} | |
| 115 | + | |
| 116 | +// Utility function for testing - clears all background process states | |
| 117 | +export function clearAllBackgroundProcesses(): void { | |
| 118 | + processTerminalBackgroundStates.clear(); | |
| 119 | +} |
modified extensions/cli/build.mjs +12 −1
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | #!/usr/bin/env node |
| 2 | 2 | |
| 3 | 3 | import * as esbuild from "esbuild"; |
| 4 | -import { chmodSync, writeFileSync } from "fs"; | |
| 4 | +import { chmodSync, writeFileSync, copyFileSync } from "fs"; | |
| 5 | 5 | import { dirname, resolve } from "path"; |
| 6 | 6 | import { fileURLToPath } from "url"; |
| 7 | 7 | |
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | const external = [ |
| 14 | 14 | "@sentry/profiling-node", // Contains native profiler bindings (optional) |
| 15 | 15 | "fsevents", // macOS native file watcher (optional dependency) |
| 16 | + "./xhr-sync-worker.js", // JSDOM worker file that needs to be copied separately | |
| 16 | 17 | ]; |
| 17 | 18 | |
| 18 | 19 | console.log("Building CLI with esbuild..."); |
| @@ -84,6 +85,16 @@ | ||
| 84 | 85 | // Write metafile for analysis |
| 85 | 86 | writeFileSync("dist/meta.json", JSON.stringify(result.metafile, null, 2)); |
| 86 | 87 | |
| 88 | + // Copy worker files needed by JSDOM | |
| 89 | + const workerSource = resolve(__dirname, "node_modules/jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js"); | |
| 90 | + const workerDest = resolve(__dirname, "dist/xhr-sync-worker.js"); | |
| 91 | + try { | |
| 92 | + copyFileSync(workerSource, workerDest); | |
| 93 | + console.log("✓ Copied xhr-sync-worker.js"); | |
| 94 | + } catch (error) { | |
| 95 | + console.warn("Warning: Could not copy xhr-sync-worker.js:", error.message); | |
| 96 | + } | |
| 97 | + | |
| 87 | 98 | // Create wrapper script with shebang |
| 88 | 99 | writeFileSync("dist/cn.js", "#!/usr/bin/env node\nimport('./index.js');"); |
| 89 | 100 |
modified extensions/cli/src/commands/commands.ts +5 −1
| @@ -65,7 +65,11 @@ | ||
| 65 | 65 | description: "Manage MCP server connections", |
| 66 | 66 | category: "system", |
| 67 | 67 | }, |
| 68 | - | |
| 68 | + { | |
| 69 | + name: "init", | |
| 70 | + description: "Create an AGENTS.md file", | |
| 71 | + category: "system", | |
| 72 | + }, | |
| 69 | 73 | { |
| 70 | 74 | name: "compact", |
| 71 | 75 | description: "Summarize chat history into a compact form", |
added extensions/cli/src/commands/init.ts +45 −0
| @@ -0,0 +1,45 @@ | ||
| 1 | +import { type AssistantConfig } from "@continuedev/sdk"; | |
| 2 | + | |
| 3 | +import { SlashCommandResult } from "../ui/hooks/useChat.types.js"; | |
| 4 | + | |
| 5 | +function createInitPrompt(): string { | |
| 6 | + return `Please analyze this repository and create a comprehensive AGENTS.md file. Use your available tools to understand the project structure, read important files like README.md, package.json, requirements.txt, and other configuration files to understand the technology stack and setup. | |
| 7 | + | |
| 8 | +Create an AGENTS.md file with the following structure: | |
| 9 | + | |
| 10 | +# Repository Overview | |
| 11 | + | |
| 12 | +## Project Description | |
| 13 | +- What this project does | |
| 14 | +- Main purpose and goals | |
| 15 | +- Key technologies used | |
| 16 | + | |
| 17 | +## Architecture Overview | |
| 18 | +- High-level architecture | |
| 19 | +- Main components and their relationships | |
| 20 | +- Data flow and system interactions | |
| 21 | + | |
| 22 | +## Directory Structure | |
| 23 | +- Important directories and their purposes | |
| 24 | +- Key files and configuration | |
| 25 | +- Entry points and main modules | |
| 26 | + | |
| 27 | +## Development Workflow | |
| 28 | +- How to build/run the project | |
| 29 | +- Testing approach | |
| 30 | +- Development environment setup | |
| 31 | +- Lint and format commands | |
| 32 | + | |
| 33 | +Please create the AGENTS.md file using the Write tool after analyzing the repository. Focus on providing actionable information that would help both AI agents and human developers understand and work effectively with this codebase. Keep the file concise but informational.`; | |
| 34 | +} | |
| 35 | + | |
| 36 | +export async function handleInit( | |
| 37 | + _args: string[], | |
| 38 | + _assistant: AssistantConfig, | |
| 39 | +): Promise<SlashCommandResult> { | |
| 40 | + const prompt = createInitPrompt(); | |
| 41 | + | |
| 42 | + return { | |
| 43 | + newInput: prompt, | |
| 44 | + }; | |
| 45 | +} |
modified extensions/cli/src/commands/remote.test.ts +65 −0
| @@ -236,6 +236,71 @@ | ||
| 236 | 236 | prompt: "test prompt", |
| 237 | 237 | idempotencyKey: testIdempotencyKey, |
| 238 | 238 | branchName: testBranch, |
| 239 | + agent: undefined, | |
| 240 | + config: undefined, | |
| 241 | + }); | |
| 242 | + }); | |
| 243 | + | |
| 244 | + it("should include config in request body when config option is provided", async () => { | |
| 245 | + const testConfig = "test-config-path"; | |
| 246 | + | |
| 247 | + await remote("test prompt", { config: testConfig }); | |
| 248 | + | |
| 249 | + expect(mockFetch).toHaveBeenCalledWith( | |
| 250 | + new URL("agents/devboxes", mockEnv.env.apiBase), | |
| 251 | + expect.objectContaining({ | |
| 252 | + method: "POST", | |
| 253 | + headers: { | |
| 254 | + "Content-Type": "application/json", | |
| 255 | + Authorization: "Bearer test-token", | |
| 256 | + }, | |
| 257 | + body: expect.stringContaining(`"config":"${testConfig}"`), | |
| 258 | + }), | |
| 259 | + ); | |
| 260 | + | |
| 261 | + expect(mockFetch).toHaveBeenCalledWith( | |
| 262 | + new URL("agents/devboxes", mockEnv.env.apiBase), | |
| 263 | + expect.objectContaining({ | |
| 264 | + body: expect.stringContaining(`"agent":"${testConfig}"`), | |
| 265 | + }), | |
| 266 | + ); | |
| 267 | + }); | |
| 268 | + | |
| 269 | + it("should handle proper request body structure with config field", async () => { | |
| 270 | + const testConfig = "my-agent-config"; | |
| 271 | + const testIdempotencyKey = "test-with-config"; | |
| 272 | + | |
| 273 | + await remote("test prompt", { | |
| 274 | + config: testConfig, | |
| 275 | + idempotencyKey: testIdempotencyKey, | |
| 276 | + }); | |
| 277 | + | |
| 278 | + const fetchCall = mockFetch.mock.calls[0]; | |
| 279 | + const requestBody = JSON.parse(fetchCall[1].body); | |
| 280 | + | |
| 281 | + expect(requestBody).toEqual({ | |
| 282 | + repoUrl: "https://github.com/user/test-repo.git", | |
| 283 | + name: expect.stringMatching(/^devbox-\d+$/), | |
| 284 | + prompt: "test prompt", | |
| 285 | + idempotencyKey: testIdempotencyKey, | |
| 286 | + agent: testConfig, | |
| 287 | + config: testConfig, | |
| 288 | + }); | |
| 289 | + }); | |
| 290 | + | |
| 291 | + it("should not include config in request body when config option is not provided", async () => { | |
| 292 | + await remote("test prompt", {}); | |
| 293 | + | |
| 294 | + const fetchCall = mockFetch.mock.calls[0]; | |
| 295 | + const requestBody = JSON.parse(fetchCall[1].body); | |
| 296 | + | |
| 297 | + expect(requestBody).toEqual({ | |
| 298 | + repoUrl: "https://github.com/user/test-repo.git", | |
| 299 | + name: expect.stringMatching(/^devbox-\d+$/), | |
| 300 | + prompt: "test prompt", | |
| 301 | + idempotencyKey: undefined, | |
| 302 | + agent: undefined, | |
| 303 | + config: undefined, | |
| 239 | 304 | }); |
| 240 | 305 | }); |
| 241 | 306 |
modified extensions/cli/src/commands/remote.ts +3 −0
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | start?: boolean; |
| 17 | 17 | branch?: string; |
| 18 | 18 | repo?: string; |
| 19 | + config?: string; | |
| 19 | 20 | } = {}, |
| 20 | 21 | ) { |
| 21 | 22 | // Check if prompt should come from stdin instead of parameter |
| @@ -84,6 +85,8 @@ | ||
| 84 | 85 | name: `devbox-${Date.now()}`, |
| 85 | 86 | prompt: actualPrompt, |
| 86 | 87 | idempotencyKey: options.idempotencyKey, |
| 88 | + agent: options.config, | |
| 89 | + config: options.config, | |
| 87 | 90 | }; |
| 88 | 91 | |
| 89 | 92 | // Add branchName to request body if branch option is provided |
modified extensions/cli/src/index.ts +6 −4
| @@ -113,7 +113,7 @@ | ||
| 113 | 113 | .description( |
| 114 | 114 | "Continue CLI - AI-powered development assistant. Starts an interactive session by default, use -p/--print for non-interactive output.", |
| 115 | 115 | ) |
| 116 | - .version(getVersion()); | |
| 116 | + .version(getVersion(), "-v, --version", "Display version number"); | |
| 117 | 117 | |
| 118 | 118 | // Root command - chat functionality (default) |
| 119 | 119 | // Add common options to the root command |
| @@ -254,9 +254,11 @@ | ||
| 254 | 254 | }); |
| 255 | 255 | |
| 256 | 256 | // Remote subcommand |
| 257 | -program | |
| 258 | - .command("remote [prompt]", { hidden: true }) | |
| 259 | - .description("Launch a remote instance of the cn agent") | |
| 257 | +addCommonOptions( | |
| 258 | + program | |
| 259 | + .command("remote [prompt]", { hidden: true }) | |
| 260 | + .description("Launch a remote instance of the cn agent"), | |
| 261 | +) | |
| 260 | 262 | .option( |
| 261 | 263 | "--url <url>", |
| 262 | 264 | "Connect directly to the specified URL instead of creating a new remote environment", |
modified extensions/cli/src/init.ts +3 −2
| @@ -3,10 +3,11 @@ | ||
| 3 | 3 | * This file intercepts console and stdout/stderr to prevent dependency logging |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | +import { isHeadlessMode as checkIsHeadlessMode } from "./util/cli.js"; | |
| 7 | + | |
| 6 | 8 | // Check if we're in headless mode by looking at process arguments |
| 7 | 9 | // We need to do this before any imports to catch early logging |
| 8 | -const args = process.argv.slice(2); | |
| 9 | -const isHeadlessMode = args.includes("-p") || args.includes("--print"); | |
| 10 | +const isHeadlessMode = checkIsHeadlessMode(); | |
| 10 | 11 | |
| 11 | 12 | // Store original methods before ANY dependencies can use them |
| 12 | 13 | const originalStdoutWrite = process.stdout.write.bind(process.stdout); |
modified extensions/cli/src/services/FileIndexService.ts +10 −0
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | import { FILE_IGNORE_PATTERNS, FILE_PATTERNS } from "../util/filePatterns.js"; |
| 4 | 4 | import { getFileWatcher } from "../util/fileWatcher.js"; |
| 5 | 5 | import { isGitRepo } from "../util/git.js"; |
| 6 | +import { isInHomeDirectory } from "../util/isInHomeDirectory.js"; | |
| 6 | 7 | import { logger } from "../util/logger.js"; |
| 7 | 8 | |
| 8 | 9 | import { BaseService } from "./BaseService.js"; |
| @@ -69,6 +70,15 @@ | ||
| 69 | 70 | |
| 70 | 71 | try { |
| 71 | 72 | const inGitRepo = isGitRepo(); |
| 73 | + | |
| 74 | + if (isInHomeDirectory()) { | |
| 75 | + this.setState({ | |
| 76 | + isIndexing: false, | |
| 77 | + error: "Skipping full index as in home directory", | |
| 78 | + }); | |
| 79 | + return; | |
| 80 | + } | |
| 81 | + | |
| 72 | 82 | const allMatches = await this.throttledGlob(FILE_PATTERNS, { |
| 73 | 83 | maxDepth: inGitRepo ? 15 : 3, |
| 74 | 84 | ignore: FILE_IGNORE_PATTERNS, |
modified extensions/cli/src/shared-options.ts +1 −1
| @@ -13,7 +13,7 @@ | ||
| 13 | 13 | ) |
| 14 | 14 | .option("--readonly", "Start in plan mode (read-only tools)") |
| 15 | 15 | .option("--auto", "Start in auto mode (all tools allowed)") |
| 16 | - .option("-v, --verbose", "Enable verbose logging") | |
| 16 | + .option("--verbose", "Enable verbose logging") | |
| 17 | 17 | .option( |
| 18 | 18 | "--rule <rule>", |
| 19 | 19 | "Add a rule (can be a file path, hub slug, or string content). Can be specified multiple times.", |
modified extensions/cli/src/slashCommands.ts +5 −0
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | loadAuthConfig, |
| 8 | 8 | } from "./auth/workos.js"; |
| 9 | 9 | import { getAllSlashCommands } from "./commands/commands.js"; |
| 10 | +import { handleInit } from "./commands/init.js"; | |
| 10 | 11 | import { handleInfoSlashCommand } from "./infoScreen.js"; |
| 11 | 12 | import { reloadService, SERVICE_NAMES, services } from "./services/index.js"; |
| 12 | 13 | import { getCurrentSession } from "./session.js"; |
| @@ -176,6 +177,10 @@ | ||
| 176 | 177 | return { openSessionSelector: true }; |
| 177 | 178 | }, |
| 178 | 179 | fork: handleFork, |
| 180 | + init: (args, assistant) => { | |
| 181 | + posthogService.capture("useSlashCommand", { name: "init" }); | |
| 182 | + return handleInit(args, assistant); | |
| 183 | + }, | |
| 179 | 184 | }; |
| 180 | 185 | |
| 181 | 186 | export async function handleSlashCommands( |
modified extensions/cli/src/telemetry/posthogService.ts +2 −9
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | import type { PostHog as PostHogType } from "posthog-node"; |
| 6 | 6 | |
| 7 | 7 | import { isAuthenticatedConfig, loadAuthConfig } from "../auth/workos.js"; |
| 8 | +import { isHeadlessMode } from "../util/cli.js"; | |
| 8 | 9 | import { isGitHubActions } from "../util/git.js"; |
| 9 | 10 | import { logger } from "../util/logger.js"; |
| 10 | 11 | import { getVersion } from "../version.js"; |
| @@ -38,14 +39,6 @@ | ||
| 38 | 39 | return this._hasInternetConnection; |
| 39 | 40 | } |
| 40 | 41 | |
| 41 | - /** | |
| 42 | - * Check if running in headless mode (-p/--print flags) | |
| 43 | - */ | |
| 44 | - private isHeadlessMode(): boolean { | |
| 45 | - const args = process.argv.slice(2); | |
| 46 | - return args.includes("-p") || args.includes("--print"); | |
| 47 | - } | |
| 48 | - | |
| 49 | 42 | get isEnabled() { |
| 50 | 43 | return process.env.CONTINUE_CLI_ENABLE_TELEMETRY !== "0"; |
| 51 | 44 | } |
| @@ -100,7 +93,7 @@ | ||
| 100 | 93 | extensionVersion: getVersion(), |
| 101 | 94 | ideName: "cn", |
| 102 | 95 | ideType: "cli", |
| 103 | - isHeadless: this.isHeadlessMode(), | |
| 96 | + isHeadless: isHeadlessMode(), | |
| 104 | 97 | isGitHubCI: isGitHubActions(), |
| 105 | 98 | }; |
| 106 | 99 | const payload = { |
added extensions/cli/src/telemetry/telemetryService.sessionMetadata.test.ts +238 −0
| @@ -0,0 +1,238 @@ | ||
| 1 | +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | |
| 2 | + | |
| 3 | +import { telemetryService } from "./telemetryService.js"; | |
| 4 | + | |
| 5 | +describe("TelemetryService - Session Metadata", () => { | |
| 6 | + let originalEnv: NodeJS.ProcessEnv; | |
| 7 | + let originalArgv: string[]; | |
| 8 | + | |
| 9 | + beforeEach(() => { | |
| 10 | + // Save original environment and argv | |
| 11 | + originalEnv = { ...process.env }; | |
| 12 | + originalArgv = [...process.argv]; | |
| 13 | + | |
| 14 | + // Mock logger to prevent console output during tests | |
| 15 | + vi.mock("../util/logger.js", () => ({ | |
| 16 | + logger: { | |
| 17 | + debug: vi.fn(), | |
| 18 | + info: vi.fn(), | |
| 19 | + warn: vi.fn(), | |
| 20 | + error: vi.fn(), | |
| 21 | + }, | |
| 22 | + })); | |
| 23 | + | |
| 24 | + // Enable telemetry for tests | |
| 25 | + process.env.CONTINUE_CLI_ENABLE_TELEMETRY = "1"; | |
| 26 | + process.env.OTEL_METRICS_EXPORTER = "console"; | |
| 27 | + }); | |
| 28 | + | |
| 29 | + afterEach(() => { | |
| 30 | + // Restore original environment and argv | |
| 31 | + process.env = originalEnv; | |
| 32 | + process.argv = originalArgv; | |
| 33 | + vi.clearAllMocks(); | |
| 34 | + }); | |
| 35 | + | |
| 36 | + describe("recordSessionStart", () => { | |
| 37 | + it("should include is_headless=false when not in headless mode", () => { | |
| 38 | + // Set up non-headless mode (no -p or --print flags) | |
| 39 | + process.argv = ["node", "cli.js", "chat"]; | |
| 40 | + | |
| 41 | + const mockAdd = vi.fn(); | |
| 42 | + const mockRecord = vi.fn(); | |
| 43 | + const service = telemetryService as any; | |
| 44 | + | |
| 45 | + // Mock the session counter and startup time histogram | |
| 46 | + service.sessionCounter = { add: mockAdd }; | |
| 47 | + service.startupTimeHistogram = { record: mockRecord }; | |
| 48 | + service.config = { enabled: true }; | |
| 49 | + service.meter = {}; | |
| 50 | + | |
| 51 | + service.recordSessionStart(); | |
| 52 | + | |
| 53 | + expect(mockAdd).toHaveBeenCalledWith( | |
| 54 | + 1, | |
| 55 | + expect.objectContaining({ | |
| 56 | + is_headless: "false", | |
| 57 | + }), | |
| 58 | + ); | |
| 59 | + }); | |
| 60 | + | |
| 61 | + it("should include is_headless=true when -p flag is present", () => { | |
| 62 | + // Set up headless mode with -p flag | |
| 63 | + process.argv = ["node", "cli.js", "-p", "What is the weather?"]; | |
| 64 | + | |
| 65 | + const mockAdd = vi.fn(); | |
| 66 | + const mockRecord = vi.fn(); | |
| 67 | + const service = telemetryService as any; | |
| 68 | + | |
| 69 | + // Mock the session counter and startup time histogram | |
| 70 | + service.sessionCounter = { add: mockAdd }; | |
| 71 | + service.startupTimeHistogram = { record: mockRecord }; | |
| 72 | + service.config = { enabled: true }; | |
| 73 | + service.meter = {}; | |
| 74 | + | |
| 75 | + service.recordSessionStart(); | |
| 76 | + | |
| 77 | + expect(mockAdd).toHaveBeenCalledWith( | |
| 78 | + 1, | |
| 79 | + expect.objectContaining({ | |
| 80 | + is_headless: "true", | |
| 81 | + }), | |
| 82 | + ); | |
| 83 | + }); | |
| 84 | + | |
| 85 | + it("should include is_headless=true when --print flag is present", () => { | |
| 86 | + // Set up headless mode with --print flag | |
| 87 | + process.argv = ["node", "cli.js", "--print", "What is the weather?"]; | |
| 88 | + | |
| 89 | + const mockAdd = vi.fn(); | |
| 90 | + const mockRecord = vi.fn(); | |
| 91 | + const service = telemetryService as any; | |
| 92 | + | |
| 93 | + // Mock the session counter and startup time histogram | |
| 94 | + service.sessionCounter = { add: mockAdd }; | |
| 95 | + service.startupTimeHistogram = { record: mockRecord }; | |
| 96 | + service.config = { enabled: true }; | |
| 97 | + service.meter = {}; | |
| 98 | + | |
| 99 | + service.recordSessionStart(); | |
| 100 | + | |
| 101 | + expect(mockAdd).toHaveBeenCalledWith( | |
| 102 | + 1, | |
| 103 | + expect.objectContaining({ | |
| 104 | + is_headless: "true", | |
| 105 | + }), | |
| 106 | + ); | |
| 107 | + }); | |
| 108 | + | |
| 109 | + it("should include is_github_actions=false when not in GitHub Actions", () => { | |
| 110 | + // Ensure GITHUB_ACTIONS is not set | |
| 111 | + delete process.env.GITHUB_ACTIONS; | |
| 112 | + | |
| 113 | + const mockAdd = vi.fn(); | |
| 114 | + const mockRecord = vi.fn(); | |
| 115 | + const service = telemetryService as any; | |
| 116 | + | |
| 117 | + // Mock the session counter and startup time histogram | |
| 118 | + service.sessionCounter = { add: mockAdd }; | |
| 119 | + service.startupTimeHistogram = { record: mockRecord }; | |
| 120 | + service.config = { enabled: true }; | |
| 121 | + service.meter = {}; | |
| 122 | + | |
| 123 | + service.recordSessionStart(); | |
| 124 | + | |
| 125 | + expect(mockAdd).toHaveBeenCalledWith( | |
| 126 | + 1, | |
| 127 | + expect.objectContaining({ | |
| 128 | + is_github_actions: "false", | |
| 129 | + is_continue_remote_agent: "false", | |
| 130 | + }), | |
| 131 | + ); | |
| 132 | + }); | |
| 133 | + | |
| 134 | + it("should include is_github_actions=true when in GitHub Actions", () => { | |
| 135 | + // Set GitHub Actions environment | |
| 136 | + process.env.GITHUB_ACTIONS = "true"; | |
| 137 | + | |
| 138 | + const mockAdd = vi.fn(); | |
| 139 | + const mockRecord = vi.fn(); | |
| 140 | + const service = telemetryService as any; | |
| 141 | + | |
| 142 | + // Mock the session counter and startup time histogram | |
| 143 | + service.sessionCounter = { add: mockAdd }; | |
| 144 | + service.startupTimeHistogram = { record: mockRecord }; | |
| 145 | + service.config = { enabled: true }; | |
| 146 | + service.meter = {}; | |
| 147 | + | |
| 148 | + service.recordSessionStart(); | |
| 149 | + | |
| 150 | + expect(mockAdd).toHaveBeenCalledWith( | |
| 151 | + 1, | |
| 152 | + expect.objectContaining({ | |
| 153 | + is_github_actions: "true", | |
| 154 | + is_continue_remote_agent: "false", | |
| 155 | + }), | |
| 156 | + ); | |
| 157 | + }); | |
| 158 | + | |
| 159 | + it("should include both headless and GitHub Actions metadata when both are true", () => { | |
| 160 | + // Set both headless mode and GitHub Actions | |
| 161 | + process.argv = ["node", "cli.js", "-p", "What is the weather?"]; | |
| 162 | + process.env.GITHUB_ACTIONS = "true"; | |
| 163 | + | |
| 164 | + const mockAdd = vi.fn(); | |
| 165 | + const mockRecord = vi.fn(); | |
| 166 | + const service = telemetryService as any; | |
| 167 | + | |
| 168 | + // Mock the session counter and startup time histogram | |
| 169 | + service.sessionCounter = { add: mockAdd }; | |
| 170 | + service.startupTimeHistogram = { record: mockRecord }; | |
| 171 | + service.config = { enabled: true }; | |
| 172 | + service.meter = {}; | |
| 173 | + | |
| 174 | + service.recordSessionStart(); | |
| 175 | + | |
| 176 | + expect(mockAdd).toHaveBeenCalledWith( | |
| 177 | + 1, | |
| 178 | + expect.objectContaining({ | |
| 179 | + is_headless: "true", | |
| 180 | + is_github_actions: "true", | |
| 181 | + is_continue_remote_agent: "false", | |
| 182 | + }), | |
| 183 | + ); | |
| 184 | + }); | |
| 185 | + | |
| 186 | + it("should include is_continue_remote_agent=true when in remote agent mode", () => { | |
| 187 | + // Set Continue remote agent environment | |
| 188 | + process.env.CONTINUE_REMOTE = "true"; | |
| 189 | + | |
| 190 | + const mockAdd = vi.fn(); | |
| 191 | + const mockRecord = vi.fn(); | |
| 192 | + const service = telemetryService as any; | |
| 193 | + | |
| 194 | + // Mock the session counter and startup time histogram | |
| 195 | + service.sessionCounter = { add: mockAdd }; | |
| 196 | + service.startupTimeHistogram = { record: mockRecord }; | |
| 197 | + service.config = { enabled: true }; | |
| 198 | + service.meter = {}; | |
| 199 | + | |
| 200 | + service.recordSessionStart(); | |
| 201 | + | |
| 202 | + expect(mockAdd).toHaveBeenCalledWith( | |
| 203 | + 1, | |
| 204 | + expect.objectContaining({ | |
| 205 | + is_continue_remote_agent: "true", | |
| 206 | + }), | |
| 207 | + ); | |
| 208 | + }); | |
| 209 | + | |
| 210 | + it("should include all environment flags when all are true", () => { | |
| 211 | + // Set all environments | |
| 212 | + process.argv = ["node", "cli.js", "-p", "What is the weather?"]; | |
| 213 | + process.env.GITHUB_ACTIONS = "true"; | |
| 214 | + process.env.CONTINUE_REMOTE = "true"; | |
| 215 | + | |
| 216 | + const mockAdd = vi.fn(); | |
| 217 | + const mockRecord = vi.fn(); | |
| 218 | + const service = telemetryService as any; | |
| 219 | + | |
| 220 | + // Mock the session counter and startup time histogram | |
| 221 | + service.sessionCounter = { add: mockAdd }; | |
| 222 | + service.startupTimeHistogram = { record: mockRecord }; | |
| 223 | + service.config = { enabled: true }; | |
| 224 | + service.meter = {}; | |
| 225 | + | |
| 226 | + service.recordSessionStart(); | |
| 227 | + | |
| 228 | + expect(mockAdd).toHaveBeenCalledWith( | |
| 229 | + 1, | |
| 230 | + expect.objectContaining({ | |
| 231 | + is_headless: "true", | |
| 232 | + is_github_actions: "true", | |
| 233 | + is_continue_remote_agent: "true", | |
| 234 | + }), | |
| 235 | + ); | |
| 236 | + }); | |
| 237 | + }); | |
| 238 | +}); |
modified extensions/cli/src/telemetry/telemetryService.ts +12 −1
| @@ -19,6 +19,8 @@ | ||
| 19 | 19 | } from "@opentelemetry/semantic-conventions"; |
| 20 | 20 | import { v4 as uuidv4 } from "uuid"; |
| 21 | 21 | |
| 22 | +import { isHeadlessMode } from "../util/cli.js"; | |
| 23 | +import { isContinueRemoteAgent, isGitHubActions } from "../util/git.js"; | |
| 22 | 24 | import { logger } from "../util/logger.js"; |
| 23 | 25 | import { getVersion } from "../version.js"; |
| 24 | 26 | |
| @@ -350,7 +352,16 @@ | ||
| 350 | 352 | if (!this.isEnabled()) return; |
| 351 | 353 | |
| 352 | 354 | logger.debug("Recording session start with telemetry"); |
| 353 | - this.sessionCounter.add(1, this.getStandardAttributes()); | |
| 355 | + | |
| 356 | + // Add extra metadata for session breakdown | |
| 357 | + const isGitHubActionsEnv = isGitHubActions(); | |
| 358 | + const sessionAttributes = this.getStandardAttributes({ | |
| 359 | + is_headless: isHeadlessMode().toString(), | |
| 360 | + is_github_actions: isGitHubActionsEnv.toString(), | |
| 361 | + is_continue_remote_agent: isContinueRemoteAgent().toString(), | |
| 362 | + }); | |
| 363 | + | |
| 364 | + this.sessionCounter.add(1, sessionAttributes); | |
| 354 | 365 | this.recordStartupTime(Date.now() - this.startTime); |
| 355 | 366 | } |
| 356 | 367 |
added extensions/cli/src/tools/fetch.test.ts +169 −0
| @@ -0,0 +1,169 @@ | ||
| 1 | +import type { ContextItem } from "core/index.js"; | |
| 2 | +import { fetchUrlContentImpl } from "core/tools/implementations/fetchUrlContent.js"; | |
| 3 | +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | |
| 4 | + | |
| 5 | +import { fetchTool } from "./fetch.js"; | |
| 6 | + | |
| 7 | +// Mock the core fetchUrlContent implementation | |
| 8 | +vi.mock("core/tools/implementations/fetchUrlContent.js", () => ({ | |
| 9 | + fetchUrlContentImpl: vi.fn(), | |
| 10 | +})); | |
| 11 | + | |
| 12 | +const mockFetchUrlContentImpl = vi.mocked(fetchUrlContentImpl); | |
| 13 | + | |
| 14 | +describe("fetchTool", () => { | |
| 15 | + let originalConsoleError: typeof console.error; | |
| 16 | + | |
| 17 | + beforeEach(() => { | |
| 18 | + originalConsoleError = console.error; | |
| 19 | + console.error = vi.fn(); | |
| 20 | + mockFetchUrlContentImpl.mockReset(); | |
| 21 | + }); | |
| 22 | + | |
| 23 | + afterEach(() => { | |
| 24 | + console.error = originalConsoleError; | |
| 25 | + }); | |
| 26 | + | |
| 27 | + it("should return clean content from successful fetch", async () => { | |
| 28 | + const mockContextItems: ContextItem[] = [ | |
| 29 | + { | |
| 30 | + name: "Example Page", | |
| 31 | + description: "https://example.com", | |
| 32 | + content: | |
| 33 | + "# Example Page\n\nThis is some example content from a webpage.", | |
| 34 | + uri: { type: "url", value: "https://example.com" }, | |
| 35 | + }, | |
| 36 | + ]; | |
| 37 | + | |
| 38 | + mockFetchUrlContentImpl.mockResolvedValue(mockContextItems); | |
| 39 | + | |
| 40 | + const result = await fetchTool.run({ url: "https://example.com" }); | |
| 41 | + | |
| 42 | + expect(result).toBe( | |
| 43 | + "# Example Page\n\nThis is some example content from a webpage.", | |
| 44 | + ); | |
| 45 | + expect(mockFetchUrlContentImpl).toHaveBeenCalledWith( | |
| 46 | + { url: "https://example.com" }, | |
| 47 | + { fetch }, | |
| 48 | + ); | |
| 49 | + }); | |
| 50 | + | |
| 51 | + it("should handle truncation warnings from core implementation", async () => { | |
| 52 | + const mockContextItems: ContextItem[] = [ | |
| 53 | + { | |
| 54 | + name: "Long Page", | |
| 55 | + description: "https://example.com", | |
| 56 | + content: "This is the main content that was truncated.", | |
| 57 | + uri: { type: "url", value: "https://example.com" }, | |
| 58 | + }, | |
| 59 | + { | |
| 60 | + name: "Truncation warning", | |
| 61 | + description: "", | |
| 62 | + content: | |
| 63 | + "The content from https://example.com was truncated because it exceeded the 20000 character limit.", | |
| 64 | + }, | |
| 65 | + ]; | |
| 66 | + | |
| 67 | + mockFetchUrlContentImpl.mockResolvedValue(mockContextItems); | |
| 68 | + | |
| 69 | + const result = await fetchTool.run({ url: "https://example.com" }); | |
| 70 | + | |
| 71 | + expect(result).toBe( | |
| 72 | + "This is the main content that was truncated.\n\nThe content from https://example.com was truncated because it exceeded the 20000 character limit.", | |
| 73 | + ); | |
| 74 | + }); | |
| 75 | + | |
| 76 | + it("should handle multiple content items", async () => { | |
| 77 | + const mockContextItems: ContextItem[] = [ | |
| 78 | + { | |
| 79 | + name: "Page 1", | |
| 80 | + description: "https://example.com", | |
| 81 | + content: "Content from page 1", | |
| 82 | + uri: { type: "url", value: "https://example.com" }, | |
| 83 | + }, | |
| 84 | + { | |
| 85 | + name: "Page 2", | |
| 86 | + description: "https://example.com", | |
| 87 | + content: "Content from page 2", | |
| 88 | + uri: { type: "url", value: "https://example.com" }, | |
| 89 | + }, | |
| 90 | + ]; | |
| 91 | + | |
| 92 | + mockFetchUrlContentImpl.mockResolvedValue(mockContextItems); | |
| 93 | + | |
| 94 | + const result = await fetchTool.run({ url: "https://example.com" }); | |
| 95 | + | |
| 96 | + expect(result).toBe("Content from page 1\n\nContent from page 2"); | |
| 97 | + }); | |
| 98 | + | |
| 99 | + it("should return error message when no content items returned", async () => { | |
| 100 | + mockFetchUrlContentImpl.mockResolvedValue([]); | |
| 101 | + | |
| 102 | + const result = await fetchTool.run({ url: "https://example.com" }); | |
| 103 | + | |
| 104 | + expect(result).toBe( | |
| 105 | + "Error: Could not fetch content from https://example.com", | |
| 106 | + ); | |
| 107 | + }); | |
| 108 | + | |
| 109 | + it("should handle errors from core implementation", async () => { | |
| 110 | + const error = new Error("Network error"); | |
| 111 | + mockFetchUrlContentImpl.mockRejectedValue(error); | |
| 112 | + | |
| 113 | + const result = await fetchTool.run({ url: "https://example.com" }); | |
| 114 | + | |
| 115 | + expect(result).toBe("Error: Network error"); | |
| 116 | + }); | |
| 117 | + | |
| 118 | + it("should call fetchUrlContentImpl with correct arguments", async () => { | |
| 119 | + const mockContextItems: ContextItem[] = [ | |
| 120 | + { | |
| 121 | + name: "Test Page", | |
| 122 | + description: "https://example.com", | |
| 123 | + content: "Test content", | |
| 124 | + uri: { type: "url", value: "https://example.com" }, | |
| 125 | + }, | |
| 126 | + ]; | |
| 127 | + | |
| 128 | + mockFetchUrlContentImpl.mockResolvedValue(mockContextItems); | |
| 129 | + | |
| 130 | + await fetchTool.run({ url: "https://example.com" }); | |
| 131 | + | |
| 132 | + expect(mockFetchUrlContentImpl).toHaveBeenCalledWith( | |
| 133 | + { url: "https://example.com" }, | |
| 134 | + { fetch }, | |
| 135 | + ); | |
| 136 | + }); | |
| 137 | + | |
| 138 | + it("should have correct tool metadata", () => { | |
| 139 | + expect(fetchTool.name).toBe("Fetch"); | |
| 140 | + expect(fetchTool.displayName).toBe("Fetch"); | |
| 141 | + expect(fetchTool.description).toBe( | |
| 142 | + "Fetches content from a URL, converts to markdown, and handles long content with truncation", | |
| 143 | + ); | |
| 144 | + expect(fetchTool.readonly).toBe(true); | |
| 145 | + expect(fetchTool.isBuiltIn).toBe(true); | |
| 146 | + expect(fetchTool.parameters).toEqual({ | |
| 147 | + url: { | |
| 148 | + type: "string", | |
| 149 | + description: "The URL to fetch content from", | |
| 150 | + required: true, | |
| 151 | + }, | |
| 152 | + }); | |
| 153 | + }); | |
| 154 | + | |
| 155 | + it("should provide correct preview in preprocess", async () => { | |
| 156 | + const args = { url: "https://example.com" }; | |
| 157 | + const result = await fetchTool.preprocess?.(args); | |
| 158 | + | |
| 159 | + expect(result).toEqual({ | |
| 160 | + preview: [ | |
| 161 | + { | |
| 162 | + type: "text", | |
| 163 | + content: "Will fetch: https://example.com", | |
| 164 | + }, | |
| 165 | + ], | |
| 166 | + args, | |
| 167 | + }); | |
| 168 | + }); | |
| 169 | +}); |
modified extensions/cli/src/tools/fetch.ts +24 −97
| @@ -1,50 +1,19 @@ | ||
| 1 | -import TurndownService from "turndown"; | |
| 1 | +import type { ContextItem } from "core/index.js"; | |
| 2 | +import { fetchUrlContentImpl } from "core/tools/implementations/fetchUrlContent.js"; | |
| 2 | 3 | |
| 3 | 4 | import { Tool } from "./types.js"; |
| 4 | 5 | |
| 5 | -const turndownService = new TurndownService({ | |
| 6 | - headingStyle: "atx", | |
| 7 | - codeBlockStyle: "fenced", | |
| 8 | - fence: "```", | |
| 9 | - emDelimiter: "*", | |
| 10 | - strongDelimiter: "**", | |
| 11 | - linkStyle: "inlined", | |
| 12 | - linkReferenceStyle: "full", | |
| 13 | -}); | |
| 14 | - | |
| 15 | -// Configure turndown for better markdown output | |
| 16 | -turndownService.addRule("strikethrough", { | |
| 17 | - filter: ["del", "s"], | |
| 18 | - replacement: function (content) { | |
| 19 | - return "~~" + content + "~~"; | |
| 20 | - }, | |
| 21 | -}); | |
| 22 | - | |
| 23 | -// Handle code blocks better | |
| 24 | -turndownService.addRule("pre", { | |
| 25 | - filter: "pre", | |
| 26 | - replacement: function (content, node) { | |
| 27 | - const codeEl = node.querySelector("code"); | |
| 28 | - const language = codeEl?.className.match(/language-(\w+)/)?.[1] || ""; | |
| 29 | - return "\n\n```" + language + "\n" + content + "\n```\n\n"; | |
| 30 | - }, | |
| 31 | -}); | |
| 32 | - | |
| 33 | 6 | export const fetchTool: Tool = { |
| 34 | 7 | name: "Fetch", |
| 35 | 8 | displayName: "Fetch", |
| 36 | - description: "Fetches content from a URL and converts it to markdown format", | |
| 9 | + description: | |
| 10 | + "Fetches content from a URL, converts to markdown, and handles long content with truncation", | |
| 37 | 11 | parameters: { |
| 38 | 12 | url: { |
| 39 | 13 | type: "string", |
| 40 | 14 | description: "The URL to fetch content from", |
| 41 | 15 | required: true, |
| 42 | 16 | }, |
| 43 | - timeout: { | |
| 44 | - type: "number", | |
| 45 | - description: "Request timeout in milliseconds (default: 10000)", | |
| 46 | - required: false, | |
| 47 | - }, | |
| 48 | 17 | }, |
| 49 | 18 | readonly: true, |
| 50 | 19 | isBuiltIn: true, |
| @@ -59,76 +28,34 @@ | ||
| 59 | 28 | args, |
| 60 | 29 | }; |
| 61 | 30 | }, |
| 62 | - run: async (args: { url: string; timeout?: number }): Promise<string> => { | |
| 63 | - const { url, timeout = 10000 } = args; | |
| 31 | + run: async (args: { url: string }): Promise<string> => { | |
| 32 | + const { url } = args; | |
| 64 | 33 | |
| 65 | 34 | try { |
| 66 | - // Validate URL | |
| 67 | - const urlObj = new URL(url); | |
| 68 | - if (!["http:", "https:"].includes(urlObj.protocol)) { | |
| 69 | - return "Error: Only HTTP and HTTPS URLs are supported"; | |
| 70 | - } | |
| 71 | - | |
| 72 | - // Fetch the content | |
| 73 | - const controller = new AbortController(); | |
| 74 | - const timeoutId = setTimeout(() => controller.abort(), timeout); | |
| 75 | - | |
| 76 | - const response = await fetch(url, { | |
| 77 | - signal: controller.signal, | |
| 78 | - headers: { | |
| 79 | - "User-Agent": "Continue-CLI/1.0 (https://continue.dev)", | |
| 80 | - Accept: | |
| 81 | - "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", | |
| 82 | - "Accept-Language": "en-US,en;q=0.5", | |
| 83 | - "Accept-Encoding": "gzip, deflate", | |
| 84 | - "Cache-Control": "no-cache", | |
| 85 | - }, | |
| 86 | - }); | |
| 35 | + // Suppress console errors from JSDOM CSS parsing | |
| 36 | + const originalConsoleError = console.error; | |
| 37 | + console.error = () => {}; | |
| 87 | 38 | |
| 88 | - clearTimeout(timeoutId); | |
| 39 | + // Use the core fetchUrlContent implementation | |
| 40 | + const contextItems = await fetchUrlContentImpl({ url }, { fetch }); | |
| 89 | 41 | |
| 90 | - if (!response.ok) { | |
| 91 | - return `Error: HTTP ${response.status} - ${response.statusText}`; | |
| 92 | - } | |
| 93 | - | |
| 94 | - const contentType = response.headers.get("content-type") || ""; | |
| 95 | - | |
| 96 | - // Handle different content types | |
| 97 | - if (contentType.includes("application/json")) { | |
| 98 | - const json = await response.json(); | |
| 99 | - return "```json\n" + JSON.stringify(json, null, 2) + "\n```"; | |
| 100 | - } | |
| 101 | - | |
| 102 | - if (contentType.includes("text/plain")) { | |
| 103 | - const text = await response.text(); | |
| 104 | - return text; | |
| 105 | - } | |
| 42 | + // Restore console.error | |
| 43 | + console.error = originalConsoleError; | |
| 106 | 44 | |
| 107 | - if (!contentType.includes("text/html")) { | |
| 108 | - return `Error: Unsupported content type: ${contentType}`; | |
| 45 | + if (contextItems.length === 0) { | |
| 46 | + return `Error: Could not fetch content from ${url}`; | |
| 109 | 47 | } |
| 110 | 48 | |
| 111 | - // Process HTML content | |
| 112 | - const html = await response.text(); | |
| 113 | - | |
| 114 | - // Convert HTML to markdown | |
| 115 | - const markdown = turndownService.turndown(html); | |
| 116 | - | |
| 117 | - // Clean up the markdown | |
| 118 | - const cleanedMarkdown = markdown | |
| 119 | - .replace(/\n\s*\n\s*\n/g, "\n\n") // Remove excessive newlines | |
| 120 | - .replace(/^\s+|\s+$/g, "") // Trim whitespace | |
| 121 | - .replace(/\\\[/g, "[") // Unescape brackets | |
| 122 | - .replace(/\\\]/g, "]"); | |
| 123 | - | |
| 124 | - return `# Content from ${url}\n\n${cleanedMarkdown}`; | |
| 49 | + // Format the results for CLI display | |
| 50 | + return contextItems | |
| 51 | + .map((item: ContextItem) => { | |
| 52 | + if (item.name === "Truncation warning") { | |
| 53 | + return item.content; | |
| 54 | + } | |
| 55 | + return item.content; | |
| 56 | + }) | |
| 57 | + .join("\n\n"); | |
| 125 | 58 | } catch (error) { |
| 126 | - if (error instanceof TypeError && error.message.includes("fetch")) { | |
| 127 | - return `Error: Failed to fetch URL "${url}". Please check the URL and try again.`; | |
| 128 | - } | |
| 129 | - if (error instanceof Error && error.name === "AbortError") { | |
| 130 | - return `Error: Request timed out after ${timeout}ms`; | |
| 131 | - } | |
| 132 | 59 | return `Error: ${error instanceof Error ? error.message : String(error)}`; |
| 133 | 60 | } |
| 134 | 61 | }, |
modified extensions/cli/src/ui/IntroMessage.tsx +4 −16
| @@ -1,12 +1,10 @@ | ||
| 1 | -import * as os from "node:os"; | |
| 2 | -import * as path from "node:path"; | |
| 3 | - | |
| 4 | 1 | import { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml"; |
| 5 | 2 | import { Box, Text } from "ink"; |
| 6 | 3 | import React, { useMemo } from "react"; |
| 7 | 4 | |
| 8 | 5 | import { getDisplayableAsciiArt } from "../asciiArt.js"; |
| 9 | 6 | import { MCPService } from "../services/MCPService.js"; |
| 7 | +import { isInHomeDirectory } from "../util/isInHomeDirectory.js"; | |
| 10 | 8 | import { isModelCapable } from "../utils/modelCapability.js"; |
| 11 | 9 | |
| 12 | 10 | import { ModelCapabilityWarning } from "./ModelCapabilityWarning.js"; |
| @@ -29,6 +27,8 @@ | ||
| 29 | 27 | ); |
| 30 | 28 | }; |
| 31 | 29 | |
| 30 | +const userInHomeDirectory = isInHomeDirectory(); | |
| 31 | + | |
| 32 | 32 | const IntroMessage: React.FC<IntroMessageProps> = ({ |
| 33 | 33 | config, |
| 34 | 34 | model, |
| @@ -40,18 +40,6 @@ | ||
| 40 | 40 | // Determine if we should show a tip (1 in 5 chance) - computed once on mount |
| 41 | 41 | const showTip = useMemo(() => shouldShowTip(), []); |
| 42 | 42 | |
| 43 | - // Check if current working directory is the home directory | |
| 44 | - const isInHomeDirectory = useMemo(() => { | |
| 45 | - const cwd = process.cwd(); | |
| 46 | - const homedir = os.homedir(); | |
| 47 | - const resolvedCwd = path.resolve(cwd); | |
| 48 | - const resolvedHome = path.resolve(homedir); | |
| 49 | - if (process.platform === "win32") { | |
| 50 | - return resolvedCwd.toLowerCase() === resolvedHome.toLowerCase(); | |
| 51 | - } | |
| 52 | - return resolvedCwd === resolvedHome; | |
| 53 | - }, []); | |
| 54 | - | |
| 55 | 43 | // Memoize expensive operations to avoid running on every resize |
| 56 | 44 | const { allRules, modelCapable } = useMemo(() => { |
| 57 | 45 | const allRules = extractRuleNames(config?.rules); |
| @@ -153,7 +141,7 @@ | ||
| 153 | 141 | {renderMcpServers()} |
| 154 | 142 | |
| 155 | 143 | {/* Home directory warning */} |
| 156 | - {isInHomeDirectory && ( | |
| 144 | + {userInHomeDirectory && ( | |
| 157 | 145 | <> |
| 158 | 146 | <Text color="yellow">{HOME_DIRECTORY_WARNING}</Text> |
| 159 | 147 | <Text> </Text> |
added extensions/cli/src/ui/MarkdownRenderer.thinking.test.tsx +36 −0
| @@ -0,0 +1,36 @@ | ||
| 1 | +import { render } from "ink-testing-library"; | |
| 2 | +import React from "react"; | |
| 3 | + | |
| 4 | +import { MarkdownRenderer } from "./MarkdownRenderer.js"; | |
| 5 | + | |
| 6 | +describe("MarkdownRenderer - thinking tags", () => { | |
| 7 | + it("handles multiple thinking tags", () => { | |
| 8 | + const content = | |
| 9 | + "Text <think>First thought</think> middle <think>Second thought</think> end"; | |
| 10 | + const { lastFrame } = render(<MarkdownRenderer content={content} />); | |
| 11 | + | |
| 12 | + expect(lastFrame()).toContain("First thought"); | |
| 13 | + expect(lastFrame()).toContain("Second thought"); | |
| 14 | + }); | |
| 15 | + | |
| 16 | + it("handles thinking tags with multiline content", () => { | |
| 17 | + const content = `<think> | |
| 18 | + This is a multiline | |
| 19 | + thinking block | |
| 20 | + </think>`; | |
| 21 | + const { lastFrame } = render(<MarkdownRenderer content={content} />); | |
| 22 | + | |
| 23 | + expect(lastFrame()).toContain("This is a multiline"); | |
| 24 | + expect(lastFrame()).toContain("thinking block"); | |
| 25 | + }); | |
| 26 | + | |
| 27 | + it("ignores thinking tags inside code blocks", () => { | |
| 28 | + const content = "```\n<think>This should not be processed</think>\n```"; | |
| 29 | + const { lastFrame } = render(<MarkdownRenderer content={content} />); | |
| 30 | + | |
| 31 | + // The thinking tag should appear as literal text within the code block | |
| 32 | + expect(lastFrame()).toContain( | |
| 33 | + "<think>This should not be processed</think>", | |
| 34 | + ); | |
| 35 | + }); | |
| 36 | +}); |
modified extensions/cli/src/ui/MarkdownRenderer.tsx +11 −4
| @@ -2,10 +2,10 @@ | ||
| 2 | 2 | import React from "react"; |
| 3 | 3 | |
| 4 | 4 | import { |
| 5 | - highlightCode, | |
| 5 | + defaultTheme, | |
| 6 | 6 | detectLanguage, |
| 7 | + highlightCode, | |
| 7 | 8 | SyntaxHighlighterTheme, |
| 8 | - defaultTheme, | |
| 9 | 9 | } from "./SyntaxHighlighter.js"; |
| 10 | 10 | |
| 11 | 11 | interface MarkdownRendererProps { |
| @@ -28,6 +28,14 @@ | ||
| 28 | 28 | return null; // This will be handled separately |
| 29 | 29 | }, |
| 30 | 30 | }, |
| 31 | + { | |
| 32 | + regex: /<think>([\s\S]*?)<\/think>/g, | |
| 33 | + render: (content, key) => ( | |
| 34 | + <Text key={key} color="gray"> | |
| 35 | + {content.trim()} | |
| 36 | + </Text> | |
| 37 | + ), | |
| 38 | + }, | |
| 31 | 39 | { |
| 32 | 40 | regex: /^(#{1,6})\s+(.+)$/gm, |
| 33 | 41 | render: (content, key) => ( |
| @@ -225,6 +233,5 @@ | ||
| 225 | 233 | |
| 226 | 234 | MarkdownRenderer.displayName = "MarkdownRenderer"; |
| 227 | 235 | |
| 228 | -export { MarkdownRenderer }; | |
| 236 | +export { defaultTheme, MarkdownRenderer }; | |
| 229 | 237 | export type { SyntaxHighlighterTheme }; |
| 230 | -export { defaultTheme }; |
modified extensions/cli/src/ui/TipsDisplay.tsx +1 −0
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | 'Multi-line input is supported by typing "\\" and pressing enter', |
| 10 | 10 | "Use `cn ls` or `/resume` to resume a previous conversation", |
| 11 | 11 | 'Run `cn` with the `-p` flag for headless mode. For example: `cn -p "Generate a commit message for the current changes. Output _only_ the commit message and nothing else."`', |
| 12 | + "Use the /init slash command to generate an AGENTS.md file. This will help `cn` understand your codebase and generate better responses.", | |
| 12 | 13 | ]; |
| 13 | 14 | |
| 14 | 15 | interface TipsDisplayProps { |
modified extensions/cli/src/ui/__tests__/BottomStatusBarCtrlC.test.tsx +7 −0
| @@ -13,6 +13,13 @@ | ||
| 13 | 13 | setExitMessageCallback: vi.fn(), |
| 14 | 14 | })); |
| 15 | 15 | |
| 16 | +// Mock git utility functions | |
| 17 | +vi.mock("../../util/git.js", () => ({ | |
| 18 | + isGitRepo: vi.fn(() => false), | |
| 19 | + getGitRemoteUrl: vi.fn(() => null), | |
| 20 | + getGitBranch: vi.fn(() => null), | |
| 21 | +})); | |
| 22 | + | |
| 16 | 23 | describe("BottomStatusBar Ctrl+C message", () => { |
| 17 | 24 | const defaultProps: BottomStatusBarProps = { |
| 18 | 25 | currentMode: "normal" as const, |
added extensions/cli/src/util/cli.ts +11 −0
| @@ -0,0 +1,11 @@ | ||
| 1 | +/** | |
| 2 | + * Utility functions for CLI operations | |
| 3 | + */ | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * Check if running in headless mode (-p/--print flags) | |
| 7 | + */ | |
| 8 | +export function isHeadlessMode(): boolean { | |
| 9 | + const args = process.argv.slice(2); | |
| 10 | + return args.includes("-p") || args.includes("--print"); | |
| 11 | +} |
modified extensions/cli/src/util/git.ts +7 −0
| @@ -57,6 +57,13 @@ | ||
| 57 | 57 | return process.env.GITHUB_ACTIONS === "true"; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | +/** | |
| 61 | + * Check if running in Continue remote agents | |
| 62 | + */ | |
| 63 | +export function isContinueRemoteAgent(): boolean { | |
| 64 | + return process.env.CONTINUE_REMOTE === "true"; | |
| 65 | +} | |
| 66 | + | |
| 60 | 67 | /** |
| 61 | 68 | * Get repository URL from GitHub Actions environment variables |
| 62 | 69 | * @returns GitHub repository URL or null if not available |
added extensions/cli/src/util/isInHomeDirectory.test.ts +85 −0
| @@ -0,0 +1,85 @@ | ||
| 1 | +// eslint-disable-next-line import/order | |
| 2 | +import { vi } from "vitest"; | |
| 3 | + | |
| 4 | +vi.mock("node:os", () => ({ | |
| 5 | + default: { | |
| 6 | + homedir: vi.fn(), | |
| 7 | + }, | |
| 8 | +})); | |
| 9 | + | |
| 10 | +vi.mock("node:path", () => ({ | |
| 11 | + default: { | |
| 12 | + resolve: vi.fn(), | |
| 13 | + }, | |
| 14 | +})); | |
| 15 | + | |
| 16 | +import os from "node:os"; | |
| 17 | +import path from "node:path"; | |
| 18 | + | |
| 19 | +import { isInHomeDirectory } from "./isInHomeDirectory.js"; | |
| 20 | + | |
| 21 | +describe("isInHomeDirectory", () => { | |
| 22 | + const originalCwd = process.cwd; | |
| 23 | + const originalPlatform = process.platform; | |
| 24 | + | |
| 25 | + beforeEach(() => { | |
| 26 | + vi.clearAllMocks(); | |
| 27 | + process.cwd = vi.fn(); | |
| 28 | + }); | |
| 29 | + | |
| 30 | + afterEach(() => { | |
| 31 | + process.cwd = originalCwd; | |
| 32 | + Object.defineProperty(process, "platform", { | |
| 33 | + value: originalPlatform, | |
| 34 | + writable: true, | |
| 35 | + }); | |
| 36 | + }); | |
| 37 | + | |
| 38 | + it("should return true when current directory is home directory on Unix", () => { | |
| 39 | + Object.defineProperty(process, "platform", { | |
| 40 | + value: "linux", | |
| 41 | + writable: true, | |
| 42 | + }); | |
| 43 | + | |
| 44 | + const mockCwd = "/home/user"; | |
| 45 | + const mockHome = "/home/user"; | |
| 46 | + | |
| 47 | + vi.mocked(process.cwd).mockReturnValue(mockCwd); | |
| 48 | + vi.mocked(os.homedir).mockReturnValue(mockHome); | |
| 49 | + vi.mocked(path.resolve).mockImplementation((p: string) => p); | |
| 50 | + | |
| 51 | + expect(isInHomeDirectory()).toBe(true); | |
| 52 | + }); | |
| 53 | + | |
| 54 | + it("should return false when current directory is not home directory on Unix", () => { | |
| 55 | + Object.defineProperty(process, "platform", { | |
| 56 | + value: "linux", | |
| 57 | + writable: true, | |
| 58 | + }); | |
| 59 | + | |
| 60 | + const mockCwd = "/home/user/projects"; | |
| 61 | + const mockHome = "/home/user"; | |
| 62 | + | |
| 63 | + vi.mocked(process.cwd).mockReturnValue(mockCwd); | |
| 64 | + vi.mocked(os.homedir).mockReturnValue(mockHome); | |
| 65 | + vi.mocked(path.resolve).mockImplementation((p: string) => p); | |
| 66 | + | |
| 67 | + expect(isInHomeDirectory()).toBe(false); | |
| 68 | + }); | |
| 69 | + | |
| 70 | + it("should return true when current directory is home directory on Windows (case insensitive)", () => { | |
| 71 | + Object.defineProperty(process, "platform", { | |
| 72 | + value: "win32", | |
| 73 | + writable: true, | |
| 74 | + }); | |
| 75 | + | |
| 76 | + const mockCwd = "C:\\Users\\User"; | |
| 77 | + const mockHome = "c:\\users\\user"; | |
| 78 | + | |
| 79 | + vi.mocked(process.cwd).mockReturnValue(mockCwd); | |
| 80 | + vi.mocked(os.homedir).mockReturnValue(mockHome); | |
| 81 | + vi.mocked(path.resolve).mockImplementation((p: string) => p); | |
| 82 | + | |
| 83 | + expect(isInHomeDirectory()).toBe(true); | |
| 84 | + }); | |
| 85 | +}); |
added extensions/cli/src/util/isInHomeDirectory.ts +13 −0
| @@ -0,0 +1,13 @@ | ||
| 1 | +import os from "node:os"; | |
| 2 | +import path from "node:path"; | |
| 3 | + | |
| 4 | +export function isInHomeDirectory(): boolean { | |
| 5 | + const cwd = process.cwd(); | |
| 6 | + const homedir = os.homedir(); | |
| 7 | + const resolvedCwd = path.resolve(cwd); | |
| 8 | + const resolvedHome = path.resolve(homedir); | |
| 9 | + if (process.platform === "win32") { | |
| 10 | + return resolvedCwd.toLowerCase() === resolvedHome.toLowerCase(); | |
| 11 | + } | |
| 12 | + return resolvedCwd === resolvedHome; | |
| 13 | +} |
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt +1 −0
| @@ -146,6 +146,7 @@ | ||
| 146 | 146 | "isItemTooBig", |
| 147 | 147 | "process/markAsBackgrounded", |
| 148 | 148 | "process/isBackgrounded", |
| 149 | + "process/killTerminalProcess" | |
| 149 | 150 | ) |
| 150 | 151 | } |
| 151 | 152 | } |
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/ApplyToFileHandler.kt +1 −1
| @@ -46,7 +46,7 @@ | ||
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | // Handle search/replace mode |
| 49 | - if (params.isSearchReplace == true) { | |
| 49 | + if (params.isSearchAndReplace == true) { | |
| 50 | 50 | handleSearchReplace(editorUtils) |
| 51 | 51 | return |
| 52 | 52 | } |
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/protocol/ideWebview.kt +1 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | val streamId: String, |
| 10 | 10 | val filepath: String?, |
| 11 | 11 | val toolCallId: String?, |
| 12 | - val isSearchReplace: Boolean? = null | |
| 12 | + val isSearchAndReplace: Boolean? = null | |
| 13 | 13 | ) |
| 14 | 14 | |
| 15 | 15 | data class InsertAtCursorParams( |
modified extensions/intellij/src/main/resources/META-INF/plugin.xml +3 −3
| @@ -151,9 +151,9 @@ | ||
| 151 | 151 | <action id="continue.openConfigPage" |
| 152 | 152 | class="com.github.continuedev.continueintellijextension.actions.OpenConfigAction" |
| 153 | 153 | icon="AllIcons.General.GearPlain" |
| 154 | - text="Continue Config" | |
| 155 | - description="Continue Config"> | |
| 156 | - <override-text place="GoToAction" text="Continue Config"/> | |
| 154 | + text="Settings" | |
| 155 | + description="Settings"> | |
| 156 | + <override-text place="GoToAction" text="Settings"/> | |
| 157 | 157 | </action> |
| 158 | 158 | |
| 159 | 159 | <action id="continue.openLogs" |
modified extensions/vscode/e2e/actions/GUI.actions.ts +22 −3
| @@ -136,10 +136,22 @@ | ||
| 136 | 136 | toolName: string, |
| 137 | 137 | desiredState: number | string, |
| 138 | 138 | ) { |
| 139 | - const toolButton = await TestUtils.waitForSuccess(() => | |
| 140 | - GUISelectors.getToolButton(view), | |
| 139 | + // Navigate to config page | |
| 140 | + | |
| 141 | + const settingsButton = await TestUtils.waitForSuccess(() => | |
| 142 | + GUISelectors.getSettingsNavButton(view), | |
| 143 | + ); | |
| 144 | + await settingsButton.click(); | |
| 145 | + await TestUtils.waitForTimeout(500); | |
| 146 | + | |
| 147 | + // Click on tools tab | |
| 148 | + const toolsTab = await TestUtils.waitForSuccess(() => | |
| 149 | + GUISelectors.getToolsTab(view), | |
| 141 | 150 | ); |
| 142 | - await toolButton.click(); | |
| 151 | + await toolsTab.click(); | |
| 152 | + await TestUtils.waitForTimeout(500); | |
| 153 | + | |
| 154 | + // Find and click the tool policy button | |
| 143 | 155 | const toolPolicyButton = await TestUtils.waitForSuccess(() => |
| 144 | 156 | GUISelectors.getToolPolicyButton(view, toolName), |
| 145 | 157 | ); |
| @@ -181,5 +193,12 @@ | ||
| 181 | 193 | `Failed to set tool policy to ${targetStates.join(" or ")} after 5 attempts`, |
| 182 | 194 | ); |
| 183 | 195 | } |
| 196 | + | |
| 197 | + // Navigate back to chat | |
| 198 | + const backButton = await TestUtils.waitForSuccess(() => | |
| 199 | + GUISelectors.getBackButton(view), | |
| 200 | + ); | |
| 201 | + await backButton.click(); | |
| 202 | + await TestUtils.waitForTimeout(500); | |
| 184 | 203 | } |
| 185 | 204 | } |
modified extensions/vscode/e2e/selectors/GUI.selectors.ts +10 −5
| @@ -47,11 +47,12 @@ | ||
| 47 | 47 | return SelectorUtils.getElementByDataTestId(view, "tool-call-title"); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - public static getToolButton(view: WebView) { | |
| 51 | - return SelectorUtils.getElementByDataTestId( | |
| 52 | - view, | |
| 53 | - `block-settings-toolbar-icon-tools`, | |
| 54 | - ); | |
| 50 | + public static getToolsTab(view: WebView) { | |
| 51 | + return SelectorUtils.getElementByDataTestId(view, "tab-tools"); | |
| 52 | + } | |
| 53 | + | |
| 54 | + public static getBackButton(view: WebView) { | |
| 55 | + return SelectorUtils.getElementByDataTestId(view, "tab-back"); | |
| 55 | 56 | } |
| 56 | 57 | |
| 57 | 58 | public static getToolPolicyButton(view: WebView, toolName: string) { |
| @@ -150,6 +151,10 @@ | ||
| 150 | 151 | return SelectorUtils.getElementByAriaLabel(view, "View History"); |
| 151 | 152 | } |
| 152 | 153 | |
| 154 | + public static getSettingsNavButton(view: WebView) { | |
| 155 | + return SelectorUtils.getElementByAriaLabel(view, "Open Settings"); | |
| 156 | + } | |
| 157 | + | |
| 153 | 158 | public static getNewSessionNavButton(view: WebView) { |
| 154 | 159 | return SelectorUtils.getElementByAriaLabel(view, "New Session"); |
| 155 | 160 | } |
modified extensions/vscode/e2e/tests/GUI.test.ts +1 −1
| @@ -16,7 +16,7 @@ | ||
| 16 | 16 | import { GUISelectors } from "../selectors/GUI.selectors"; |
| 17 | 17 | import { TestUtils } from "../TestUtils"; |
| 18 | 18 | |
| 19 | -describe("GUI Test", () => { | |
| 19 | +describe.skip("GUI Test", () => { | |
| 20 | 20 | let view: WebView; |
| 21 | 21 | let driver: WebDriver; |
| 22 | 22 |
modified extensions/vscode/package.json +1 −22
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | "name": "continue", |
| 3 | 3 | "icon": "media/icon.png", |
| 4 | 4 | "author": "Continue Dev, Inc", |
| 5 | - "version": "1.3.6", | |
| 5 | + "version": "1.3.7", | |
| 6 | 6 | "repository": { |
| 7 | 7 | "type": "git", |
| 8 | 8 | "url": "https://github.com/continuedev/continue" |
| @@ -210,13 +210,6 @@ | ||
| 210 | 210 | "title": "Exit Edit Mode", |
| 211 | 211 | "group": "Continue" |
| 212 | 212 | }, |
| 213 | - { | |
| 214 | - "command": "continue.toggleFullScreen", | |
| 215 | - "category": "Continue", | |
| 216 | - "title": "Open in new window", | |
| 217 | - "icon": "$(link-external)", | |
| 218 | - "group": "Continue" | |
| 219 | - }, | |
| 220 | 213 | { |
| 221 | 214 | "command": "continue.openConfigPage", |
| 222 | 215 | "category": "Continue", |
| @@ -444,12 +437,6 @@ | ||
| 444 | 437 | "mac": "cmd+shift+r", |
| 445 | 438 | "key": "ctrl+shift+r" |
| 446 | 439 | }, |
| 447 | - { | |
| 448 | - "command": "continue.toggleFullScreen", | |
| 449 | - "mac": "cmd+k cmd+m", | |
| 450 | - "key": "ctrl+k ctrl+m", | |
| 451 | - "when": "!terminalFocus" | |
| 452 | - }, | |
| 453 | 440 | { |
| 454 | 441 | "command": "continue.toggleTabAutocompleteEnabled", |
| 455 | 442 | "mac": "cmd+k cmd+a", |
| @@ -511,9 +498,6 @@ | ||
| 511 | 498 | { |
| 512 | 499 | "command": "continue.debugTerminal" |
| 513 | 500 | }, |
| 514 | - { | |
| 515 | - "command": "continue.toggleFullScreen" | |
| 516 | - }, | |
| 517 | 501 | { |
| 518 | 502 | "command": "continue.newSession" |
| 519 | 503 | }, |
| @@ -566,11 +550,6 @@ | ||
| 566 | 550 | "group": "navigation@2", |
| 567 | 551 | "when": "view == continue.continueGUIView" |
| 568 | 552 | }, |
| 569 | - { | |
| 570 | - "command": "continue.toggleFullScreen", | |
| 571 | - "group": "navigation@3", | |
| 572 | - "when": "view == continue.continueGUIView" | |
| 573 | - }, | |
| 574 | 553 | { |
| 575 | 554 | "command": "continue.openConfigPage", |
| 576 | 555 | "group": "navigation@4", |
modified extensions/vscode/src/apply/ApplyManager.ts +127 −8
| @@ -7,6 +7,9 @@ | ||
| 7 | 7 | import { myersDiff } from "core/diff/myers"; |
| 8 | 8 | import { generateLines } from "core/diff/util"; |
| 9 | 9 | import { ApplyAbortManager } from "core/edit/applyAbortManager"; |
| 10 | +import { streamDiffLines } from "core/edit/streamDiffLines"; | |
| 11 | +import { pruneLinesFromBottom, pruneLinesFromTop } from "core/llm/countTokens"; | |
| 12 | +import { getMarkdownLanguageTagForFile } from "core/util"; | |
| 10 | 13 | import { VerticalDiffManager } from "../diff/vertical/manager"; |
| 11 | 14 | import { VsCodeIde } from "../VsCodeIde"; |
| 12 | 15 | import { VsCodeWebviewProtocol } from "../webviewProtocol"; |
| @@ -92,6 +95,10 @@ | ||
| 92 | 95 | await this.ide.openFile(filepath); |
| 93 | 96 | } |
| 94 | 97 | |
| 98 | + private modelIsTooFastForStreaming(model: string): boolean { | |
| 99 | + return [/mercury/].some((r) => r.test(model)); | |
| 100 | + } | |
| 101 | + | |
| 95 | 102 | private async handleEmptyDocument( |
| 96 | 103 | editor: vscode.TextEditor, |
| 97 | 104 | text: string, |
| @@ -159,6 +166,7 @@ | ||
| 159 | 166 | streamId, |
| 160 | 167 | this.verticalDiffManager, |
| 161 | 168 | toolCallId, |
| 169 | + !this.modelIsTooFastForStreaming(llm.model), | |
| 162 | 170 | ); |
| 163 | 171 | } |
| 164 | 172 | } |
| @@ -170,6 +178,37 @@ | ||
| 170 | 178 | return `The following code was suggested as an edit:\n\`\`\`\n${text}\n\`\`\`\nPlease apply it to the previous code.`; |
| 171 | 179 | } |
| 172 | 180 | |
| 181 | + /** | |
| 182 | + * Calculates prefix and suffix for a given range, shared between streaming and non-streaming modes | |
| 183 | + */ | |
| 184 | + private calculatePrefixSuffix( | |
| 185 | + editor: vscode.TextEditor, | |
| 186 | + range: vscode.Range, | |
| 187 | + llm: any, | |
| 188 | + ): { prefix: string; suffix: string; rangeContent: string } { | |
| 189 | + const rangeContent = editor.document.getText(range); | |
| 190 | + | |
| 191 | + const prefix = pruneLinesFromTop( | |
| 192 | + editor.document.getText( | |
| 193 | + new vscode.Range(new vscode.Position(0, 0), range.start), | |
| 194 | + ), | |
| 195 | + llm.contextLength / 4, | |
| 196 | + llm.model, | |
| 197 | + ); | |
| 198 | + const suffix = pruneLinesFromBottom( | |
| 199 | + editor.document.getText( | |
| 200 | + new vscode.Range( | |
| 201 | + range.end, | |
| 202 | + new vscode.Position(editor.document.lineCount, 0), | |
| 203 | + ), | |
| 204 | + ), | |
| 205 | + llm.contextLength / 4, | |
| 206 | + llm.model, | |
| 207 | + ); | |
| 208 | + | |
| 209 | + return { prefix, suffix, rangeContent }; | |
| 210 | + } | |
| 211 | + | |
| 173 | 212 | private async handleNonInstantDiff( |
| 174 | 213 | editor: vscode.TextEditor, |
| 175 | 214 | text: string, |
| @@ -177,6 +216,7 @@ | ||
| 177 | 216 | streamId: string, |
| 178 | 217 | verticalDiffManager: VerticalDiffManager, |
| 179 | 218 | toolCallId?: string, |
| 219 | + streaming: boolean = true, | |
| 180 | 220 | ) { |
| 181 | 221 | const { config } = await this.configHandler.loadConfig(); |
| 182 | 222 | if (!config) { |
| @@ -195,14 +235,93 @@ | ||
| 195 | 235 | ? fullEditorRange |
| 196 | 236 | : editor.selection; |
| 197 | 237 | |
| 198 | - await verticalDiffManager.streamEdit({ | |
| 199 | - input: prompt, | |
| 238 | + if (streaming) { | |
| 239 | + await verticalDiffManager.streamEdit({ | |
| 240 | + input: prompt, | |
| 241 | + llm, | |
| 242 | + streamId, | |
| 243 | + range: rangeToApplyTo, | |
| 244 | + newCode: text, | |
| 245 | + toolCallId, | |
| 246 | + rulesToInclude: undefined, // No rules for apply | |
| 247 | + }); | |
| 248 | + } else { | |
| 249 | + // Non-streaming: accumulate LLM output, then apply via Myers diff | |
| 250 | + const finalContent = await this.generateAppliedContent( | |
| 251 | + editor, | |
| 252 | + prompt, | |
| 253 | + llm, | |
| 254 | + rangeToApplyTo, | |
| 255 | + text, | |
| 256 | + ); | |
| 257 | + | |
| 258 | + if (finalContent) { | |
| 259 | + const diffLinesGenerator = generateLines( | |
| 260 | + myersDiff(editor.document.getText(), finalContent), | |
| 261 | + ); | |
| 262 | + | |
| 263 | + await verticalDiffManager.streamDiffLines( | |
| 264 | + diffLinesGenerator, | |
| 265 | + true, // Apply instantly since we accumulated all content | |
| 266 | + streamId, | |
| 267 | + toolCallId, | |
| 268 | + ); | |
| 269 | + } | |
| 270 | + } | |
| 271 | + } | |
| 272 | + | |
| 273 | + /** | |
| 274 | + * Generates the final applied content by accumulating all LLM output | |
| 275 | + * Similar to streamEdit but collects all output before applying | |
| 276 | + */ | |
| 277 | + private async generateAppliedContent( | |
| 278 | + editor: vscode.TextEditor, | |
| 279 | + prompt: string, | |
| 280 | + llm: any, | |
| 281 | + range: vscode.Range, | |
| 282 | + newCode: string, | |
| 283 | + ): Promise<string | undefined> { | |
| 284 | + const fileUri = editor.document.uri.toString(); | |
| 285 | + const { prefix, suffix, rangeContent } = this.calculatePrefixSuffix( | |
| 286 | + editor, | |
| 287 | + range, | |
| 200 | 288 | llm, |
| 201 | - streamId, | |
| 202 | - range: rangeToApplyTo, | |
| 203 | - newCode: text, | |
| 204 | - toolCallId, | |
| 205 | - rulesToInclude: undefined, // No rules for apply | |
| 206 | - }); | |
| 289 | + ); | |
| 290 | + | |
| 291 | + const abortManager = ApplyAbortManager.getInstance(); | |
| 292 | + const abortController = abortManager.get(fileUri); | |
| 293 | + | |
| 294 | + try { | |
| 295 | + const streamedLines: string[] = []; | |
| 296 | + | |
| 297 | + // Use streamDiffLines to get the LLM output | |
| 298 | + const stream = streamDiffLines({ | |
| 299 | + highlighted: rangeContent, | |
| 300 | + prefix, | |
| 301 | + suffix, | |
| 302 | + llm, | |
| 303 | + rulesToInclude: undefined, // No rules for apply | |
| 304 | + input: prompt, | |
| 305 | + language: getMarkdownLanguageTagForFile(fileUri), | |
| 306 | + overridePrompt: undefined, | |
| 307 | + abortController, | |
| 308 | + }); | |
| 309 | + | |
| 310 | + // Accumulate all the streamed content | |
| 311 | + for await (const line of stream) { | |
| 312 | + if (abortController.signal.aborted) { | |
| 313 | + return undefined; | |
| 314 | + } | |
| 315 | + if (line.type === "new" || line.type === "same") { | |
| 316 | + streamedLines.push(line.line); | |
| 317 | + } | |
| 318 | + } | |
| 319 | + | |
| 320 | + // Return the complete file content | |
| 321 | + return `${prefix}${streamedLines.join("\n")}${suffix}`; | |
| 322 | + } catch (error) { | |
| 323 | + console.error("Error generating applied content:", error); | |
| 324 | + return undefined; | |
| 325 | + } | |
| 207 | 326 | } |
| 208 | 327 | } |
modified extensions/vscode/src/commands.ts +6 −102
| @@ -45,15 +45,6 @@ | ||
| 45 | 45 | import { openEditorAndRevealRange } from "./util/vscode"; |
| 46 | 46 | import { VsCodeIde } from "./VsCodeIde"; |
| 47 | 47 | |
| 48 | -let fullScreenPanel: vscode.WebviewPanel | undefined; | |
| 49 | - | |
| 50 | -function getFullScreenTab() { | |
| 51 | - const tabs = vscode.window.tabGroups.all.flatMap((tabGroup) => tabGroup.tabs); | |
| 52 | - return tabs.find((tab) => | |
| 53 | - (tab.input as any)?.viewType?.endsWith("continue.continueGUIView"), | |
| 54 | - ); | |
| 55 | -} | |
| 56 | - | |
| 57 | 48 | type TelemetryCaptureParams = Parameters<typeof Telemetry.capture>; |
| 58 | 49 | |
| 59 | 50 | /** |
| @@ -67,27 +58,15 @@ | ||
| 67 | 58 | } |
| 68 | 59 | |
| 69 | 60 | function focusGUI() { |
| 70 | - const fullScreenTab = getFullScreenTab(); | |
| 71 | - if (fullScreenTab) { | |
| 72 | - // focus fullscreen | |
| 73 | - fullScreenPanel?.reveal(); | |
| 74 | - } else { | |
| 75 | - // focus sidebar | |
| 76 | - vscode.commands.executeCommand("continue.continueGUIView.focus"); | |
| 77 | - // vscode.commands.executeCommand("workbench.action.focusAuxiliaryBar"); | |
| 78 | - } | |
| 61 | + // focus sidebar | |
| 62 | + vscode.commands.executeCommand("continue.continueGUIView.focus"); | |
| 63 | + // vscode.commands.executeCommand("workbench.action.focusAuxiliaryBar"); | |
| 79 | 64 | } |
| 80 | 65 | |
| 81 | 66 | function hideGUI() { |
| 82 | - const fullScreenTab = getFullScreenTab(); | |
| 83 | - if (fullScreenTab) { | |
| 84 | - // focus fullscreen | |
| 85 | - fullScreenPanel?.dispose(); | |
| 86 | - } else { | |
| 87 | - // focus sidebar | |
| 88 | - vscode.commands.executeCommand("workbench.action.closeAuxiliaryBar"); | |
| 89 | - // vscode.commands.executeCommand("workbench.action.toggleAuxiliaryBar"); | |
| 90 | - } | |
| 67 | + // focus sidebar | |
| 68 | + vscode.commands.executeCommand("workbench.action.closeAuxiliaryBar"); | |
| 69 | + // vscode.commands.executeCommand("workbench.action.toggleAuxiliaryBar"); | |
| 91 | 70 | } |
| 92 | 71 | |
| 93 | 72 | function waitForSidebarReady( |
| @@ -436,74 +415,6 @@ | ||
| 436 | 415 | "continue.applyCodeFromChat": () => { |
| 437 | 416 | void sidebar.webviewProtocol.request("applyCodeFromChat", undefined); |
| 438 | 417 | }, |
| 439 | - "continue.toggleFullScreen": async () => { | |
| 440 | - focusGUI(); | |
| 441 | - | |
| 442 | - const sessionId = await sidebar.webviewProtocol.request( | |
| 443 | - "getCurrentSessionId", | |
| 444 | - undefined, | |
| 445 | - ); | |
| 446 | - // Check if full screen is already open by checking open tabs | |
| 447 | - const fullScreenTab = getFullScreenTab(); | |
| 448 | - | |
| 449 | - if (fullScreenTab && fullScreenPanel) { | |
| 450 | - // Full screen open, but not focused - focus it | |
| 451 | - fullScreenPanel.reveal(); | |
| 452 | - return; | |
| 453 | - } | |
| 454 | - | |
| 455 | - // Clear the sidebar to prevent overwriting changes made in fullscreen | |
| 456 | - vscode.commands.executeCommand("continue.newSession"); | |
| 457 | - | |
| 458 | - // Full screen not open - open it | |
| 459 | - captureCommandTelemetry("openFullScreen"); | |
| 460 | - | |
| 461 | - // Create the full screen panel | |
| 462 | - let panel = vscode.window.createWebviewPanel( | |
| 463 | - "continue.continueGUIView", | |
| 464 | - "Continue", | |
| 465 | - vscode.ViewColumn.One, | |
| 466 | - { | |
| 467 | - retainContextWhenHidden: true, | |
| 468 | - enableScripts: true, | |
| 469 | - }, | |
| 470 | - ); | |
| 471 | - fullScreenPanel = panel; | |
| 472 | - | |
| 473 | - // Add content to the panel | |
| 474 | - panel.webview.html = sidebar.getSidebarContent( | |
| 475 | - extensionContext, | |
| 476 | - panel, | |
| 477 | - undefined, | |
| 478 | - undefined, | |
| 479 | - true, | |
| 480 | - ); | |
| 481 | - | |
| 482 | - const sessionLoader = panel.onDidChangeViewState(() => { | |
| 483 | - vscode.commands.executeCommand("continue.newSession"); | |
| 484 | - if (sessionId) { | |
| 485 | - vscode.commands.executeCommand( | |
| 486 | - "continue.focusContinueSessionId", | |
| 487 | - sessionId, | |
| 488 | - ); | |
| 489 | - } | |
| 490 | - panel.reveal(); | |
| 491 | - sessionLoader.dispose(); | |
| 492 | - }); | |
| 493 | - | |
| 494 | - // When panel closes, reset the webview and focus | |
| 495 | - panel.onDidDispose( | |
| 496 | - () => { | |
| 497 | - sidebar.resetWebviewProtocolWebview(); | |
| 498 | - vscode.commands.executeCommand("continue.focusContinueInput"); | |
| 499 | - }, | |
| 500 | - null, | |
| 501 | - extensionContext.subscriptions, | |
| 502 | - ); | |
| 503 | - | |
| 504 | - vscode.commands.executeCommand("workbench.action.copyEditorToNewWindow"); | |
| 505 | - vscode.commands.executeCommand("workbench.action.closeAuxiliaryBar"); | |
| 506 | - }, | |
| 507 | 418 | "continue.openConfigPage": () => { |
| 508 | 419 | vscode.commands.executeCommand("continue.navigateTo", "/config", false); |
| 509 | 420 | }, |
| @@ -652,11 +563,6 @@ | ||
| 652 | 563 | label: "$(comment) Open chat", |
| 653 | 564 | description: getMetaKeyLabel() + " + L", |
| 654 | 565 | }, |
| 655 | - { | |
| 656 | - label: "$(screen-full) Open full screen chat", | |
| 657 | - description: | |
| 658 | - getMetaKeyLabel() + " + K, " + getMetaKeyLabel() + " + M", | |
| 659 | - }, | |
| 660 | 566 | { |
| 661 | 567 | label: quickPickStatusText(targetStatus), |
| 662 | 568 | description: |
| @@ -699,8 +605,6 @@ | ||
| 699 | 605 | } |
| 700 | 606 | } else if (selectedOption === "$(comment) Open chat") { |
| 701 | 607 | vscode.commands.executeCommand("continue.focusContinueInput"); |
| 702 | - } else if (selectedOption === "$(screen-full) Open full screen chat") { | |
| 703 | - vscode.commands.executeCommand("continue.toggleFullScreen"); | |
| 704 | 608 | } else if (selectedOption === "$(gear) Open settings") { |
| 705 | 609 | vscode.commands.executeCommand("continue.navigateTo", "/config"); |
| 706 | 610 | } |
modified extensions/vscode/src/diff/vertical/manager.ts +3 −0
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | import { ApplyAbortManager } from "core/edit/applyAbortManager"; |
| 14 | 14 | import { EDIT_MODE_STREAM_ID } from "core/edit/constants"; |
| 15 | 15 | import { stripImages } from "core/util/messageContent"; |
| 16 | +import { getLastNPathParts } from "core/util/uri"; | |
| 16 | 17 | import { editOutcomeTracker } from "../../extension/EditOutcomeTracker"; |
| 17 | 18 | import { VerticalDiffHandler, VerticalDiffHandlerOptions } from "./handler"; |
| 18 | 19 | |
| @@ -432,9 +433,11 @@ | ||
| 432 | 433 | |
| 433 | 434 | let overridePrompt: ChatMessage[] | undefined; |
| 434 | 435 | if (llm.promptTemplates?.apply) { |
| 436 | + const filepath = getLastNPathParts(fileUri, 1); | |
| 435 | 437 | const rendered = llm.renderPromptTemplate(llm.promptTemplates.apply, [], { |
| 436 | 438 | original_code: rangeContent, |
| 437 | 439 | new_code: newCode ?? "", |
| 440 | + filepath, | |
| 438 | 441 | }); |
| 439 | 442 | overridePrompt = |
| 440 | 443 | typeof rendered === "string" |
modified extensions/vscode/src/extension/VsCodeMessenger.ts +0 −3
| @@ -112,9 +112,6 @@ | ||
| 112 | 112 | this.onWebview("focusEditor", (msg) => { |
| 113 | 113 | vscode.commands.executeCommand("workbench.action.focusActiveEditorGroup"); |
| 114 | 114 | }); |
| 115 | - this.onWebview("toggleFullScreen", (msg) => { | |
| 116 | - vscode.commands.executeCommand("continue.toggleFullScreen"); | |
| 117 | - }); | |
| 118 | 115 | |
| 119 | 116 | this.onWebview("acceptDiff", async ({ data: { filepath, streamId } }) => { |
| 120 | 117 | await vscode.commands.executeCommand( |
modified gui/package-lock.json +0 −0
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
modified gui/src/App.tsx +1 −1
| @@ -31,7 +31,7 @@ | ||
| 31 | 31 | element: <History />, |
| 32 | 32 | }, |
| 33 | 33 | { |
| 34 | - path: "/stats", | |
| 34 | + path: ROUTES.STATS, | |
| 35 | 35 | element: <Stats />, |
| 36 | 36 | }, |
| 37 | 37 | { |
modified gui/src/components/AssistantAndOrgListbox/AssistantIcon.tsx +10 −15
| @@ -1,33 +1,28 @@ | ||
| 1 | -import { ComputerDesktopIcon, SparklesIcon } from "@heroicons/react/24/outline"; | |
| 1 | +import { SparklesIcon } from "@heroicons/react/24/outline"; | |
| 2 | 2 | import { ProfileDescription } from "core/config/ProfileLifecycleManager"; |
| 3 | 3 | import { isLocalProfile } from "../../util"; |
| 4 | +import { BotIcon } from "../svg/BotIcon"; | |
| 4 | 5 | |
| 5 | 6 | export interface AssistantIconProps { |
| 6 | 7 | assistant: ProfileDescription; |
| 7 | - size?: number; | |
| 8 | + size?: string; | |
| 8 | 9 | } |
| 9 | 10 | |
| 10 | -export function AssistantIcon({ assistant, size }: AssistantIconProps) { | |
| 11 | - const sizeTw = size ?? 4; | |
| 11 | +export function AssistantIcon({ | |
| 12 | + assistant, | |
| 13 | + size = "h-4 w-4", | |
| 14 | +}: AssistantIconProps) { | |
| 12 | 15 | if (isLocalProfile(assistant)) { |
| 13 | - return ( | |
| 14 | - <div | |
| 15 | - className={`h-${sizeTw} w-${sizeTw} bg-lightgray flex items-center justify-center rounded-full`} | |
| 16 | - > | |
| 17 | - <ComputerDesktopIcon | |
| 18 | - className={`h-${sizeTw - 1} w-${sizeTw - 1} font-bold text-black`} | |
| 19 | - /> | |
| 20 | - </div> | |
| 21 | - ); | |
| 16 | + return <BotIcon className={`text-foreground ${size} flex-shrink-0`} />; | |
| 22 | 17 | } else if (assistant.iconUrl) { |
| 23 | 18 | return ( |
| 24 | 19 | <img |
| 25 | 20 | src={assistant.iconUrl} |
| 26 | - className={`h-${sizeTw} w-${sizeTw} rounded-full`} | |
| 21 | + className={`${size} flex-shrink-0 rounded-full`} | |
| 27 | 22 | alt="" |
| 28 | 23 | /> |
| 29 | 24 | ); |
| 30 | 25 | } else { |
| 31 | - return <SparklesIcon />; | |
| 26 | + return <SparklesIcon className={`${size} flex-shrink-0`} />; | |
| 32 | 27 | } |
| 33 | 28 | } |
modified gui/src/components/AssistantAndOrgListbox/AssistantOption.tsx +24 −58
| @@ -1,18 +1,13 @@ | ||
| 1 | -import { | |
| 2 | - ArrowTopRightOnSquareIcon, | |
| 3 | - Cog6ToothIcon, | |
| 4 | - ExclamationTriangleIcon, | |
| 5 | -} from "@heroicons/react/24/outline"; | |
| 1 | +import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; | |
| 6 | 2 | import { ProfileDescription } from "core/config/ProfileLifecycleManager"; |
| 7 | 3 | import { useContext, useMemo } from "react"; |
| 8 | 4 | import { useNavigate } from "react-router-dom"; |
| 9 | 5 | import { IdeMessengerContext } from "../../context/IdeMessenger"; |
| 10 | 6 | import { useAppDispatch } from "../../redux/hooks"; |
| 11 | 7 | import { setSelectedProfile } from "../../redux/slices/profilesSlice"; |
| 12 | -import { isLocalProfile } from "../../util"; | |
| 13 | -import { ROUTES } from "../../util/navigation"; | |
| 14 | -import { useLump } from "../mainInput/Lump/LumpContext"; | |
| 15 | -import { ListboxOption, useFontSize } from "../ui"; | |
| 8 | +import { CONFIG_ROUTES } from "../../util/navigation"; | |
| 9 | +import { ToolTip } from "../gui/Tooltip"; | |
| 10 | +import { Button, ListboxOption, useFontSize } from "../ui"; | |
| 16 | 11 | import { AssistantIcon } from "./AssistantIcon"; |
| 17 | 12 | |
| 18 | 13 | interface AssistantOptionProps { |
| @@ -28,7 +23,6 @@ | ||
| 28 | 23 | }: AssistantOptionProps) { |
| 29 | 24 | const tinyFont = useFontSize(-4); |
| 30 | 25 | const navigate = useNavigate(); |
| 31 | - const { setSelectedSection } = useLump(); | |
| 32 | 26 | const dispatch = useAppDispatch(); |
| 33 | 27 | const ideMessenger = useContext(IdeMessengerContext); |
| 34 | 28 | |
| @@ -37,27 +31,14 @@ | ||
| 37 | 31 | }, [profile.errors]); |
| 38 | 32 | |
| 39 | 33 | function handleOptionClick() { |
| 34 | + // Always select the agent first (even if it has errors) | |
| 40 | 35 | // optimistic update |
| 41 | 36 | dispatch(setSelectedProfile(profile.id)); |
| 42 | 37 | // notify core which will handle actual update |
| 43 | 38 | ideMessenger.post("didChangeSelectedProfile", { |
| 44 | 39 | id: profile.id, |
| 45 | 40 | }); |
| 46 | - onClick(); | |
| 47 | - } | |
| 48 | - | |
| 49 | - function handleConfigure() { | |
| 50 | - ideMessenger.post("config/openProfile", { profileId: profile.id }); | |
| 51 | - onClick(); | |
| 52 | - } | |
| 53 | 41 | |
| 54 | - function handleClickError() { | |
| 55 | - if (profile.id === "local") { | |
| 56 | - navigate(ROUTES.HOME); | |
| 57 | - setSelectedSection("error"); | |
| 58 | - } else { | |
| 59 | - ideMessenger.post("config/openProfile", { profileId: profile.id }); | |
| 60 | - } | |
| 61 | 42 | onClick(); |
| 62 | 43 | } |
| 63 | 44 | |
| @@ -69,47 +50,32 @@ | ||
| 69 | 50 | fontSizeModifier={-2} |
| 70 | 51 | className={selected ? "bg-list-active text-list-active-foreground" : ""} |
| 71 | 52 | > |
| 72 | - <div className="flex w-full items-center justify-between gap-2"> | |
| 73 | - <div className="flex w-full items-center gap-2"> | |
| 74 | - <div className="flex h-4 w-4 flex-shrink-0"> | |
| 75 | - <AssistantIcon size={3.5} assistant={profile} /> | |
| 53 | + <div className="flex w-full items-center justify-between gap-10 py-0.5"> | |
| 54 | + <div className="flex w-full items-center gap-3"> | |
| 55 | + <div className="flex h-4 w-4 flex-shrink-0 items-center justify-center"> | |
| 56 | + <AssistantIcon assistant={profile} /> | |
| 76 | 57 | </div> |
| 77 | 58 | <span |
| 78 | - className={`line-clamp-1 flex-1 ${selected ? "font-semibold" : ""}`} | |
| 59 | + className={`line-clamp-1 flex-1 ${selected ? "font-semibold" : ""} ${profile.errors && profile.errors.length > 0 ? "text-error" : ""}`} | |
| 79 | 60 | > |
| 80 | 61 | {profile.title} |
| 81 | 62 | </span> |
| 82 | 63 | </div> |
| 83 | - <div className="flex flex-row items-center gap-1"> | |
| 64 | + <div className="flex flex-row items-center gap-1.5"> | |
| 84 | 65 | {profile.errors && profile.errors?.length > 0 && ( |
| 85 | - <ExclamationTriangleIcon | |
| 86 | - data-tooltip-id={`${profile.id}-errors-tooltip`} | |
| 87 | - className="text-error h-3 w-3 flex-shrink-0 cursor-pointer" | |
| 88 | - onClick={(e) => { | |
| 89 | - e.preventDefault(); | |
| 90 | - e.stopPropagation(); | |
| 91 | - handleClickError(); | |
| 92 | - }} | |
| 93 | - /> | |
| 94 | - )} | |
| 95 | - {isLocalProfile(profile) ? ( | |
| 96 | - <Cog6ToothIcon | |
| 97 | - className="text-description h-3 w-3 flex-shrink-0 cursor-pointer" | |
| 98 | - onClick={(e) => { | |
| 99 | - e.stopPropagation(); | |
| 100 | - e.preventDefault(); | |
| 101 | - handleConfigure(); | |
| 102 | - }} | |
| 103 | - /> | |
| 104 | - ) : ( | |
| 105 | - <ArrowTopRightOnSquareIcon | |
| 106 | - className="text-description h-3 w-3 flex-shrink-0 cursor-pointer" | |
| 107 | - onClick={(e) => { | |
| 108 | - e.stopPropagation(); | |
| 109 | - e.preventDefault(); | |
| 110 | - handleConfigure(); | |
| 111 | - }} | |
| 112 | - /> | |
| 66 | + <ToolTip content="View errors"> | |
| 67 | + <Button | |
| 68 | + variant="ghost" | |
| 69 | + size="sm" | |
| 70 | + className="text-error hover:enabled:text-error my-0 h-4 w-4 p-0" | |
| 71 | + onClick={(e) => { | |
| 72 | + e.stopPropagation(); | |
| 73 | + navigate(CONFIG_ROUTES.AGENTS); | |
| 74 | + }} | |
| 75 | + > | |
| 76 | + <ExclamationTriangleIcon className="h-3.5 w-3.5" /> | |
| 77 | + </Button> | |
| 78 | + </ToolTip> | |
| 113 | 79 | )} |
| 114 | 80 | </div> |
| 115 | 81 | </div> |
modified gui/src/components/AssistantAndOrgListbox/AssistantOptions.tsx +16 −23
| @@ -13,28 +13,21 @@ | ||
| 13 | 13 | const { profiles } = useAuth(); |
| 14 | 14 | |
| 15 | 15 | return ( |
| 16 | - <> | |
| 17 | - <div className="flex gap-1.5 px-3 pb-1 pt-2"> | |
| 18 | - <label className="text-vsc-foreground font-semibold">Agents</label> | |
| 19 | - <div className="flex cursor-pointer flex-row items-center gap-1 hover:brightness-125"></div> | |
| 20 | - </div> | |
| 21 | - | |
| 22 | - <div className="thin-scrollbar flex max-h-[300px] flex-col overflow-y-auto"> | |
| 23 | - {profiles?.length === 0 ? ( | |
| 24 | - <div className="text-vsc-foreground px-3 py-2 opacity-70"> | |
| 25 | - No agents found | |
| 26 | - </div> | |
| 27 | - ) : ( | |
| 28 | - profiles?.map((profile, idx) => ( | |
| 29 | - <AssistantOption | |
| 30 | - key={idx} | |
| 31 | - profile={profile} | |
| 32 | - onClick={onClose} | |
| 33 | - selected={profile.id === selectedProfileId} | |
| 34 | - /> | |
| 35 | - )) | |
| 36 | - )} | |
| 37 | - </div> | |
| 38 | - </> | |
| 16 | + <div className="thin-scrollbar flex max-h-32 flex-col overflow-y-auto"> | |
| 17 | + {profiles?.length === 0 ? ( | |
| 18 | + <div className="text-vsc-foreground px-3 py-2 opacity-70"> | |
| 19 | + No agents found | |
| 20 | + </div> | |
| 21 | + ) : ( | |
| 22 | + profiles?.map((profile, idx) => ( | |
| 23 | + <AssistantOption | |
| 24 | + key={idx} | |
| 25 | + profile={profile} | |
| 26 | + onClick={onClose} | |
| 27 | + selected={profile.id === selectedProfileId} | |
| 28 | + /> | |
| 29 | + )) | |
| 30 | + )} | |
| 31 | + </div> | |
| 39 | 32 | ); |
| 40 | 33 | } |
added gui/src/components/AssistantAndOrgListbox/OrganizationOption.tsx +86 −0
| @@ -0,0 +1,86 @@ | ||
| 1 | +import { CheckIcon } from "@heroicons/react/24/outline"; | |
| 2 | +import { | |
| 3 | + BuildingOfficeIcon, | |
| 4 | + UserCircleIcon, | |
| 5 | + UserIcon, | |
| 6 | +} from "@heroicons/react/24/solid"; | |
| 7 | +import { useContext } from "react"; | |
| 8 | +import { IdeMessengerContext } from "../../context/IdeMessenger"; | |
| 9 | +import { useAppDispatch, useAppSelector } from "../../redux/hooks"; | |
| 10 | +import { setSelectedOrgId } from "../../redux/slices/profilesSlice"; | |
| 11 | +import { ListboxOption } from "../ui"; | |
| 12 | + | |
| 13 | +interface OrganizationOptionProps { | |
| 14 | + organization: { id: string; name: string; iconUrl?: string | null }; | |
| 15 | + onClose: () => void; | |
| 16 | +} | |
| 17 | + | |
| 18 | +function getOrgIcon( | |
| 19 | + org: { name: string; iconUrl?: string | null }, | |
| 20 | + size: "sm" | "md" = "sm", | |
| 21 | +) { | |
| 22 | + const sizeClasses = size === "sm" ? "h-3.5 w-3.5" : "xs:h-4 xs:w-4 h-3 w-3"; | |
| 23 | + | |
| 24 | + if (org.iconUrl) { | |
| 25 | + return ( | |
| 26 | + <img | |
| 27 | + src={org.iconUrl} | |
| 28 | + alt="" | |
| 29 | + className={`${sizeClasses} flex-shrink-0 rounded-full`} | |
| 30 | + /> | |
| 31 | + ); | |
| 32 | + } | |
| 33 | + | |
| 34 | + const IconComponent = | |
| 35 | + org.name === "Personal" | |
| 36 | + ? size === "md" | |
| 37 | + ? UserIcon | |
| 38 | + : UserCircleIcon | |
| 39 | + : BuildingOfficeIcon; | |
| 40 | + return <IconComponent className={`${sizeClasses} flex-shrink-0`} />; | |
| 41 | +} | |
| 42 | + | |
| 43 | +export function OrganizationOption({ | |
| 44 | + organization, | |
| 45 | + onClose, | |
| 46 | +}: OrganizationOptionProps) { | |
| 47 | + const dispatch = useAppDispatch(); | |
| 48 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 49 | + const selectedOrgId = useAppSelector( | |
| 50 | + (state) => state.profiles.selectedOrganizationId, | |
| 51 | + ); | |
| 52 | + const isSelected = selectedOrgId === organization.id; | |
| 53 | + | |
| 54 | + function handleOptionClick() { | |
| 55 | + dispatch(setSelectedOrgId(organization.id)); | |
| 56 | + ideMessenger.post("didChangeSelectedOrg", { | |
| 57 | + id: organization.id, | |
| 58 | + }); | |
| 59 | + onClose(); | |
| 60 | + } | |
| 61 | + | |
| 62 | + return ( | |
| 63 | + <ListboxOption | |
| 64 | + value={organization.id} | |
| 65 | + onClick={handleOptionClick} | |
| 66 | + fontSizeModifier={-2} | |
| 67 | + className={isSelected ? "bg-list-active text-list-active-foreground" : ""} | |
| 68 | + > | |
| 69 | + <div className="flex w-full items-center justify-between gap-10 py-0.5"> | |
| 70 | + <div className="flex w-full items-center gap-3"> | |
| 71 | + <div className="flex h-4 w-4 flex-shrink-0 items-center justify-center"> | |
| 72 | + {getOrgIcon(organization, "sm")} | |
| 73 | + </div> | |
| 74 | + <span | |
| 75 | + className={`line-clamp-1 flex-1 ${isSelected ? "font-semibold" : ""}`} | |
| 76 | + > | |
| 77 | + {organization.name} | |
| 78 | + </span> | |
| 79 | + </div> | |
| 80 | + <div className="flex flex-row items-center gap-1.5"> | |
| 81 | + {isSelected && <CheckIcon className="h-3.5 w-3.5 flex-shrink-0" />} | |
| 82 | + </div> | |
| 83 | + </div> | |
| 84 | + </ListboxOption> | |
| 85 | + ); | |
| 86 | +} |
added gui/src/components/AssistantAndOrgListbox/OrganizationOptions.tsx +18 −0
| @@ -0,0 +1,18 @@ | ||
| 1 | +import { useAuth } from "../../context/Auth"; | |
| 2 | +import { OrganizationOption } from "./OrganizationOption"; | |
| 3 | + | |
| 4 | +interface OrganizationOptionsProps { | |
| 5 | + onClose: () => void; | |
| 6 | +} | |
| 7 | + | |
| 8 | +export function OrganizationOptions({ onClose }: OrganizationOptionsProps) { | |
| 9 | + const { organizations } = useAuth(); | |
| 10 | + | |
| 11 | + return ( | |
| 12 | + <div className="thin-scrollbar flex max-h-24 flex-col overflow-y-auto"> | |
| 13 | + {organizations.map((org) => ( | |
| 14 | + <OrganizationOption key={org.id} organization={org} onClose={onClose} /> | |
| 15 | + ))} | |
| 16 | + </div> | |
| 17 | + ); | |
| 18 | +} |
deleted gui/src/components/AssistantAndOrgListbox/ScopeSelect.tsx +0 −86
| @@ -1,86 +0,0 @@ | ||
| 1 | -import { | |
| 2 | - BuildingOfficeIcon, | |
| 3 | - ChevronUpDownIcon, | |
| 4 | -} from "@heroicons/react/24/outline"; | |
| 5 | -import { UserCircleIcon } from "@heroicons/react/24/solid"; | |
| 6 | -import { useContext } from "react"; | |
| 7 | -import { useAuth } from "../../context/Auth"; | |
| 8 | -import { IdeMessengerContext } from "../../context/IdeMessenger"; | |
| 9 | -import { useAppDispatch, useAppSelector } from "../../redux/hooks"; | |
| 10 | -import { | |
| 11 | - selectCurrentOrg, | |
| 12 | - setSelectedOrgId, | |
| 13 | -} from "../../redux/slices/profilesSlice"; | |
| 14 | -import { | |
| 15 | - Listbox, | |
| 16 | - ListboxButton, | |
| 17 | - ListboxOption, | |
| 18 | - ListboxOptions, | |
| 19 | -} from "../ui/Listbox"; | |
| 20 | - | |
| 21 | -interface ScopeSelectProps { | |
| 22 | - onSelect?: () => void; | |
| 23 | -} | |
| 24 | - | |
| 25 | -function getOrgIcon(org: { name: string; iconUrl?: string | null }) { | |
| 26 | - if (org.iconUrl) { | |
| 27 | - return ( | |
| 28 | - <img src={org.iconUrl} alt="" className="h-3.5 w-3.5 rounded-full" /> | |
| 29 | - ); | |
| 30 | - } | |
| 31 | - | |
| 32 | - const IconComponent = | |
| 33 | - org.name === "Personal" ? UserCircleIcon : BuildingOfficeIcon; | |
| 34 | - return <IconComponent className="h-3.5 w-3.5" />; | |
| 35 | -} | |
| 36 | - | |
| 37 | -export function ScopeSelect({ onSelect }: ScopeSelectProps) { | |
| 38 | - const { organizations } = useAuth(); | |
| 39 | - const ideMessenger = useContext(IdeMessengerContext); | |
| 40 | - const selectedOrgId = useAppSelector( | |
| 41 | - (state) => state.profiles.selectedOrganizationId, | |
| 42 | - ); | |
| 43 | - const currentOrg = useAppSelector(selectCurrentOrg); | |
| 44 | - const dispatch = useAppDispatch(); | |
| 45 | - | |
| 46 | - const handleChange = (newValue: string) => { | |
| 47 | - // optimisitic update | |
| 48 | - dispatch(setSelectedOrgId(newValue)); | |
| 49 | - ideMessenger.post("didChangeSelectedOrg", { | |
| 50 | - id: newValue, | |
| 51 | - }); | |
| 52 | - onSelect?.(); | |
| 53 | - }; | |
| 54 | - | |
| 55 | - const selectedDisplay = currentOrg ?? { | |
| 56 | - name: "Personal", | |
| 57 | - iconUrl: null, | |
| 58 | - }; | |
| 59 | - | |
| 60 | - return ( | |
| 61 | - <Listbox value={selectedOrgId} onChange={handleChange}> | |
| 62 | - <div className="relative"> | |
| 63 | - <ListboxButton className="hover:bg-list-active hover:text-list-active-foreground w-full min-w-[140px] justify-between px-4 py-2 sm:min-w-[200px]"> | |
| 64 | - <div className="flex items-center gap-2"> | |
| 65 | - {getOrgIcon(selectedDisplay)} | |
| 66 | - <span className="truncate"> | |
| 67 | - {selectedDisplay?.name || "Select Organization"} | |
| 68 | - </span> | |
| 69 | - </div> | |
| 70 | - <ChevronUpDownIcon className="h-3.5 w-3.5" aria-hidden="true" /> | |
| 71 | - </ListboxButton> | |
| 72 | - | |
| 73 | - <ListboxOptions className="z-[1000] min-w-[140px] pt-0.5 sm:min-w-[200px]"> | |
| 74 | - {organizations.map((org) => ( | |
| 75 | - <ListboxOption key={org.id} value={org.id} className="py-2"> | |
| 76 | - <div className="flex items-center gap-2"> | |
| 77 | - {getOrgIcon(org)} | |
| 78 | - <span>{org.name}</span> | |
| 79 | - </div> | |
| 80 | - </ListboxOption> | |
| 81 | - ))} | |
| 82 | - </ListboxOptions> | |
| 83 | - </div> | |
| 84 | - </Listbox> | |
| 85 | - ); | |
| 86 | -} |
modified gui/src/components/AssistantAndOrgListbox/SelectedAssistantButton.tsx +39 −32
| @@ -4,56 +4,63 @@ | ||
| 4 | 4 | import { useAppSelector } from "../../redux/hooks"; |
| 5 | 5 | import { fontSize } from "../../util"; |
| 6 | 6 | import { cn } from "../../util/cn"; |
| 7 | -import { useLump } from "../mainInput/Lump/LumpContext"; | |
| 8 | 7 | import { ListboxButton } from "../ui"; |
| 9 | 8 | import { AssistantIcon } from "./AssistantIcon"; |
| 10 | 9 | |
| 11 | 10 | interface SelectedAssistantButtonProps { |
| 12 | 11 | selectedProfile: ProfileDescription | null; |
| 12 | + variant?: "lump" | "sidebar"; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | export function SelectedAssistantButton({ |
| 16 | 16 | selectedProfile, |
| 17 | + variant, | |
| 17 | 18 | }: SelectedAssistantButtonProps) { |
| 18 | - const { isToolbarExpanded } = useLump(); | |
| 19 | 19 | const configLoading = useAppSelector((store) => store.config.loading); |
| 20 | 20 | |
| 21 | + const isSidebar = variant === "sidebar"; | |
| 22 | + const iconSize = isSidebar ? "h-4 w-4" : "h-3 w-3"; | |
| 23 | + const buttonPadding = isSidebar ? "px-2 py-1.5" : "px-0 py-0.5"; | |
| 24 | + const buttonStyle = isSidebar ? {} : { fontSize: fontSize(-3) }; | |
| 25 | + | |
| 21 | 26 | return ( |
| 22 | 27 | <ListboxButton |
| 23 | 28 | data-testid="assistant-select-button" |
| 24 | - className="text-description border-none bg-transparent hover:brightness-125" | |
| 25 | - style={{ fontSize: fontSize(-3) }} | |
| 29 | + className={`text-description overflow-hidden border-none bg-transparent hover:brightness-110 ${isSidebar ? "w-full justify-start" : "gap-1.5"} ${buttonPadding}`} | |
| 30 | + style={buttonStyle} | |
| 26 | 31 | > |
| 27 | - <div className="flex flex-row items-center gap-1.5"> | |
| 28 | - {selectedProfile === null ? ( | |
| 29 | - "Create your first agent" | |
| 30 | - ) : configLoading ? ( | |
| 31 | - <span className="text-description flex flex-row items-center"> | |
| 32 | - <ArrowPathIcon | |
| 33 | - className={cn( | |
| 34 | - "text-description mr-1.5 h-3 w-3", | |
| 35 | - configLoading && "animate-spin-slow", | |
| 36 | - )} | |
| 37 | - /> | |
| 38 | - Loading | |
| 39 | - </span> | |
| 40 | - ) : ( | |
| 41 | - <> | |
| 42 | - <div className="h-3 w-3 flex-shrink-0 select-none"> | |
| 43 | - <AssistantIcon size={3} assistant={selectedProfile} /> | |
| 44 | - </div> | |
| 45 | - <span | |
| 46 | - className={`line-clamp-1 select-none break-all ${isToolbarExpanded ? "xs:hidden sm:line-clamp-1" : ""}`} | |
| 47 | - > | |
| 48 | - {selectedProfile.title} | |
| 32 | + <div | |
| 33 | + className={`flex flex-row items-center ${isSidebar ? "w-full justify-between" : "gap-1.5"}`} | |
| 34 | + > | |
| 35 | + <div className="flex min-w-0 flex-1 flex-row items-center gap-2"> | |
| 36 | + {selectedProfile === null ? ( | |
| 37 | + "Create your first agent" | |
| 38 | + ) : configLoading ? ( | |
| 39 | + <span className="text-description flex flex-row items-center"> | |
| 40 | + <ArrowPathIcon | |
| 41 | + className={cn( | |
| 42 | + `text-description mr-1.5 ${iconSize}`, | |
| 43 | + configLoading && "animate-spin-slow", | |
| 44 | + )} | |
| 45 | + /> | |
| 46 | + Loading | |
| 49 | 47 | </span> |
| 50 | - </> | |
| 51 | - )} | |
| 48 | + ) : ( | |
| 49 | + <> | |
| 50 | + <AssistantIcon assistant={selectedProfile} size={iconSize} /> | |
| 51 | + <span | |
| 52 | + className={`select-none truncate text-xs ${isSidebar && "hidden md:block"}`} | |
| 53 | + > | |
| 54 | + {selectedProfile.title} | |
| 55 | + </span> | |
| 56 | + </> | |
| 57 | + )} | |
| 58 | + </div> | |
| 59 | + <ChevronDownIcon | |
| 60 | + className={`text-description ml-0.5 h-3 w-3 flex-shrink-0 select-none ${isSidebar && "hidden md:block"}`} | |
| 61 | + aria-hidden="true" | |
| 62 | + /> | |
| 52 | 63 | </div> |
| 53 | - <ChevronDownIcon | |
| 54 | - className="h-2 w-2 flex-shrink-0 select-none" | |
| 55 | - aria-hidden="true" | |
| 56 | - /> | |
| 57 | 64 | </ListboxButton> |
| 58 | 65 | ); |
| 59 | 66 | } |
modified gui/src/components/AssistantAndOrgListbox/index.tsx +203 −82
| @@ -1,11 +1,14 @@ | ||
| 1 | 1 | import { |
| 2 | 2 | ArrowPathIcon, |
| 3 | - ArrowRightEndOnRectangleIcon, | |
| 4 | 3 | ArrowRightStartOnRectangleIcon, |
| 4 | + Cog6ToothIcon, | |
| 5 | + PencilIcon, | |
| 5 | 6 | PlusIcon, |
| 7 | + WrenchScrewdriverIcon, | |
| 6 | 8 | } from "@heroicons/react/24/outline"; |
| 7 | -import { AuthType, isOnPremSession } from "core/control-plane/AuthTypes"; | |
| 9 | +import { isOnPremSession } from "core/control-plane/AuthTypes"; | |
| 8 | 10 | import { useContext, useEffect, useRef } from "react"; |
| 11 | +import { useNavigate } from "react-router-dom"; | |
| 9 | 12 | import { useAuth } from "../../context/Auth"; |
| 10 | 13 | import { IdeMessengerContext } from "../../context/IdeMessenger"; |
| 11 | 14 | import { useAppDispatch, useAppSelector } from "../../redux/hooks"; |
| @@ -15,20 +18,28 @@ | ||
| 15 | 18 | } from "../../redux/slices/profilesSlice"; |
| 16 | 19 | import { getMetaKeyLabel, isMetaEquivalentKeyPressed } from "../../util"; |
| 17 | 20 | import { cn } from "../../util/cn"; |
| 18 | -import { ToolTip } from "../gui/Tooltip"; | |
| 21 | +import { CONFIG_ROUTES } from "../../util/navigation"; | |
| 19 | 22 | import { |
| 23 | + Button, | |
| 20 | 24 | Listbox, |
| 21 | - ListboxOption, | |
| 22 | 25 | ListboxOptions, |
| 23 | 26 | Transition, |
| 24 | 27 | useFontSize, |
| 25 | 28 | } from "../ui"; |
| 29 | +import { Divider } from "../ui/Divider"; | |
| 26 | 30 | import { AssistantOptions } from "./AssistantOptions"; |
| 27 | -import { ScopeSelect } from "./ScopeSelect"; | |
| 31 | +import { OrganizationOptions } from "./OrganizationOptions"; | |
| 28 | 32 | import { SelectedAssistantButton } from "./SelectedAssistantButton"; |
| 29 | 33 | |
| 30 | -export function AssistantAndOrgListbox() { | |
| 34 | +export interface AssistantAndOrgListboxProps { | |
| 35 | + variant: "lump" | "sidebar"; | |
| 36 | +} | |
| 37 | + | |
| 38 | +export function AssistantAndOrgListbox({ | |
| 39 | + variant = "sidebar", | |
| 40 | +}: AssistantAndOrgListboxProps) { | |
| 31 | 41 | const dispatch = useAppDispatch(); |
| 42 | + const navigate = useNavigate(); | |
| 32 | 43 | const listboxRef = useRef<HTMLDivElement>(null); |
| 33 | 44 | const currentOrg = useAppSelector(selectCurrentOrg); |
| 34 | 45 | const ideMessenger = useContext(IdeMessengerContext); |
| @@ -36,8 +47,8 @@ | ||
| 36 | 47 | profiles, |
| 37 | 48 | selectedProfile, |
| 38 | 49 | session, |
| 39 | - login, | |
| 40 | 50 | logout, |
| 51 | + login, | |
| 41 | 52 | organizations, |
| 42 | 53 | refreshProfiles, |
| 43 | 54 | } = useAuth(); |
| @@ -64,8 +75,30 @@ | ||
| 64 | 75 | close(); |
| 65 | 76 | } |
| 66 | 77 | |
| 67 | - function onLogout() { | |
| 68 | - logout(); | |
| 78 | + function onNewOrganization() { | |
| 79 | + void ideMessenger.request("controlPlane/openUrl", { | |
| 80 | + path: "/organizations/new", | |
| 81 | + }); | |
| 82 | + close(); | |
| 83 | + } | |
| 84 | + | |
| 85 | + function onAgentsConfig() { | |
| 86 | + navigate(CONFIG_ROUTES.AGENTS); | |
| 87 | + close(); | |
| 88 | + } | |
| 89 | + | |
| 90 | + function onOrganizationsConfig() { | |
| 91 | + navigate(CONFIG_ROUTES.ORGANIZATIONS); | |
| 92 | + close(); | |
| 93 | + } | |
| 94 | + | |
| 95 | + function onRulesConfig() { | |
| 96 | + navigate(CONFIG_ROUTES.RULES); | |
| 97 | + close(); | |
| 98 | + } | |
| 99 | + | |
| 100 | + function onToolsConfig() { | |
| 101 | + navigate(CONFIG_ROUTES.TOOLS); | |
| 69 | 102 | close(); |
| 70 | 103 | } |
| 71 | 104 | |
| @@ -113,41 +146,42 @@ | ||
| 113 | 146 | return ( |
| 114 | 147 | <Listbox> |
| 115 | 148 | <div className="relative" ref={listboxRef}> |
| 116 | - <SelectedAssistantButton selectedProfile={selectedProfile} /> | |
| 149 | + <SelectedAssistantButton | |
| 150 | + selectedProfile={selectedProfile} | |
| 151 | + variant={variant} | |
| 152 | + /> | |
| 117 | 153 | <Transition> |
| 118 | 154 | <ListboxOptions |
| 119 | - className="-translate-x-1.5 pb-0" | |
| 155 | + className="max-h-32 -translate-x-1.5 overflow-y-auto pb-0" | |
| 120 | 156 | style={{ zIndex: 200 }} |
| 121 | 157 | > |
| 122 | - <div className="border-border border-x-0 border-t-0 border-solid px-2 py-2"> | |
| 123 | - <div className="flex flex-col gap-2 pl-1"> | |
| 124 | - {session ? ( | |
| 125 | - <span className="text-description-muted flex items-center justify-between gap-x-1"> | |
| 126 | - {session?.AUTH_TYPE !== AuthType.OnPrem && | |
| 127 | - session?.account.id} | |
| 128 | - <ToolTip content="Logout"> | |
| 129 | - <ArrowRightStartOnRectangleIcon | |
| 130 | - className="h-3 w-3 cursor-pointer hover:brightness-125" | |
| 131 | - onClick={onLogout} | |
| 132 | - /> | |
| 133 | - </ToolTip> | |
| 134 | - </span> | |
| 135 | - ) : ( | |
| 136 | - <span | |
| 137 | - className="text-description-muted flex cursor-pointer items-center justify-end gap-x-1 hover:brightness-125" | |
| 138 | - onClick={() => login(false)} | |
| 139 | - > | |
| 140 | - Log In <ArrowRightEndOnRectangleIcon className="h-3 w-3" /> | |
| 141 | - </span> | |
| 142 | - )} | |
| 143 | - {shouldRenderOrgInfo && ( | |
| 144 | - <> | |
| 145 | - <label className="text-vsc-foreground font-semibold"> | |
| 146 | - Organization | |
| 147 | - </label> | |
| 148 | - <ScopeSelect /> | |
| 149 | - </> | |
| 150 | - )} | |
| 158 | + <div className="flex items-center justify-between p-2"> | |
| 159 | + <span className="text-description text-xs font-medium"> | |
| 160 | + Agents | |
| 161 | + </span> | |
| 162 | + <div className="flex items-center gap-0.5"> | |
| 163 | + <Button | |
| 164 | + onClick={(e) => { | |
| 165 | + e.stopPropagation(); | |
| 166 | + onNewAssistant(); | |
| 167 | + }} | |
| 168 | + variant="ghost" | |
| 169 | + size="sm" | |
| 170 | + className="my-0 h-5 w-5 p-0" | |
| 171 | + > | |
| 172 | + <PlusIcon className="text-description h-3.5 w-3.5" /> | |
| 173 | + </Button> | |
| 174 | + <Button | |
| 175 | + onClick={(e) => { | |
| 176 | + e.stopPropagation(); | |
| 177 | + onAgentsConfig(); | |
| 178 | + }} | |
| 179 | + variant="ghost" | |
| 180 | + size="sm" | |
| 181 | + className="my-0 h-5 w-5 p-0" | |
| 182 | + > | |
| 183 | + <Cog6ToothIcon className="text-description h-3.5 w-3.5" /> | |
| 184 | + </Button> | |
| 151 | 185 | </div> |
| 152 | 186 | </div> |
| 153 | 187 | |
| @@ -156,50 +190,137 @@ | ||
| 156 | 190 | onClose={close} |
| 157 | 191 | /> |
| 158 | 192 | |
| 159 | - {/* Bottom Actions */} | |
| 160 | - <div className="border-border border-x-0 border-b-0 border-t border-solid"> | |
| 161 | - <ListboxOption | |
| 162 | - value="new-assistant" | |
| 163 | - fontSizeModifier={-2} | |
| 164 | - className="border-border border-b px-2 py-1.5" | |
| 165 | - onClick={onNewAssistant} | |
| 166 | - > | |
| 167 | - <span | |
| 168 | - className="text-description flex flex-row items-center" | |
| 169 | - style={{ fontSize: tinyFont }} | |
| 193 | + {shouldRenderOrgInfo && ( | |
| 194 | + <> | |
| 195 | + <Divider className="!mb-0.5 !mt-0" /> | |
| 196 | + <div className="flex items-center justify-between p-2"> | |
| 197 | + <span className="text-description text-xs font-medium"> | |
| 198 | + Organizations | |
| 199 | + </span> | |
| 200 | + <div className="flex items-center gap-0.5"> | |
| 201 | + <Button | |
| 202 | + onClick={(e) => { | |
| 203 | + e.stopPropagation(); | |
| 204 | + onNewOrganization(); | |
| 205 | + }} | |
| 206 | + variant="ghost" | |
| 207 | + size="sm" | |
| 208 | + className="my-0 h-5 w-5 p-0" | |
| 209 | + > | |
| 210 | + <PlusIcon className="text-description h-3.5 w-3.5" /> | |
| 211 | + </Button> | |
| 212 | + <Button | |
| 213 | + onClick={(e) => { | |
| 214 | + e.stopPropagation(); | |
| 215 | + onOrganizationsConfig(); | |
| 216 | + }} | |
| 217 | + variant="ghost" | |
| 218 | + size="sm" | |
| 219 | + className="my-0 h-5 w-5 p-0" | |
| 220 | + > | |
| 221 | + <Cog6ToothIcon className="text-description h-3.5 w-3.5" /> | |
| 222 | + </Button> | |
| 223 | + </div> | |
| 224 | + </div> | |
| 225 | + | |
| 226 | + <OrganizationOptions onClose={close} /> | |
| 227 | + | |
| 228 | + <Divider className="!mb-0 mt-0.5" /> | |
| 229 | + </> | |
| 230 | + )} | |
| 231 | + | |
| 232 | + {/* Settings Section */} | |
| 233 | + {variant !== "sidebar" && ( | |
| 234 | + <div> | |
| 235 | + <Button | |
| 236 | + onClick={(e) => { | |
| 237 | + e.stopPropagation(); | |
| 238 | + onRulesConfig(); | |
| 239 | + }} | |
| 240 | + variant="ghost" | |
| 241 | + size="sm" | |
| 242 | + className="text-description hover:bg-input my-0 w-full justify-start py-1.5 pl-1 text-left" | |
| 170 | 243 | > |
| 171 | - <PlusIcon className="mr-1 h-3 w-3" /> New Agent | |
| 172 | - </span> | |
| 173 | - </ListboxOption> | |
| 174 | - | |
| 175 | - <ListboxOption | |
| 176 | - value="reload-assistant" | |
| 177 | - fontSizeModifier={-2} | |
| 178 | - className="border-border border-b px-2 py-1.5" | |
| 179 | - onClick={(e: React.MouseEvent) => { | |
| 180 | - e.stopPropagation(); | |
| 181 | - refreshProfiles("Manual refresh from assistant list"); | |
| 182 | - }} | |
| 183 | - > | |
| 184 | - <span | |
| 185 | - className="text-description flex flex-row items-center" | |
| 186 | - style={{ fontSize: tinyFont }} | |
| 244 | + <div className="flex w-full items-center"> | |
| 245 | + <PencilIcon className="ml-1.5 mr-2 h-3.5 w-3.5 flex-shrink-0" /> | |
| 246 | + <span className="text-2xs">Rules</span> | |
| 247 | + </div> | |
| 248 | + </Button> | |
| 249 | + <Button | |
| 250 | + onClick={(e) => { | |
| 251 | + e.stopPropagation(); | |
| 252 | + onToolsConfig(); | |
| 253 | + }} | |
| 254 | + variant="ghost" | |
| 255 | + size="sm" | |
| 256 | + className="text-description hover:bg-input my-0 w-full justify-start py-1.5 pl-1 text-left" | |
| 187 | 257 | > |
| 188 | - <ArrowPathIcon | |
| 189 | - className={cn( | |
| 190 | - "mr-1 h-3 w-3", | |
| 191 | - configLoading && "animate-spin-slow", | |
| 192 | - )} | |
| 193 | - /> | |
| 194 | - Reload agents | |
| 195 | - </span> | |
| 196 | - </ListboxOption> | |
| 197 | - | |
| 198 | - <div | |
| 199 | - className="text-description border-border flex items-center justify-between gap-1.5 border-x-0 border-b-0 border-t border-solid px-2 py-2" | |
| 200 | - style={{ fontSize: tinyFont }} | |
| 201 | - > | |
| 202 | - <span className="block" style={{ fontSize: tinyFont - 1 }}> | |
| 258 | + <div className="flex w-full items-center"> | |
| 259 | + <WrenchScrewdriverIcon className="ml-1.5 mr-2 h-3.5 w-3.5 flex-shrink-0" /> | |
| 260 | + <span className="text-2xs">Tools</span> | |
| 261 | + </div> | |
| 262 | + </Button> | |
| 263 | + <Button | |
| 264 | + onClick={(e) => { | |
| 265 | + e.stopPropagation(); | |
| 266 | + void refreshProfiles("Manual refresh from assistant list"); | |
| 267 | + }} | |
| 268 | + variant="ghost" | |
| 269 | + size="sm" | |
| 270 | + className="text-description hover:bg-input my-0 w-full justify-start py-1.5 pl-1 text-left" | |
| 271 | + > | |
| 272 | + <div className="flex w-full items-center"> | |
| 273 | + <ArrowPathIcon | |
| 274 | + className={cn( | |
| 275 | + "ml-1.5 mr-2 h-3.5 w-3.5 flex-shrink-0", | |
| 276 | + configLoading && "animate-spin-slow", | |
| 277 | + )} | |
| 278 | + /> | |
| 279 | + <span className="text-2xs">Reload</span> | |
| 280 | + </div> | |
| 281 | + </Button> | |
| 282 | + {session ? ( | |
| 283 | + <Button | |
| 284 | + onClick={(e) => { | |
| 285 | + e.stopPropagation(); | |
| 286 | + logout(); | |
| 287 | + close(); | |
| 288 | + }} | |
| 289 | + variant="ghost" | |
| 290 | + size="sm" | |
| 291 | + className="text-description hover:bg-input my-0 w-full justify-start py-1.5 pl-1 text-left" | |
| 292 | + > | |
| 293 | + <div className="flex w-full items-center"> | |
| 294 | + <ArrowRightStartOnRectangleIcon className="ml-1.5 mr-2 h-3.5 w-3.5 flex-shrink-0" /> | |
| 295 | + <span className="text-2xs">Log out</span> | |
| 296 | + </div> | |
| 297 | + </Button> | |
| 298 | + ) : ( | |
| 299 | + <Button | |
| 300 | + onClick={(e) => { | |
| 301 | + e.stopPropagation(); | |
| 302 | + login(false); | |
| 303 | + close(); | |
| 304 | + }} | |
| 305 | + variant="ghost" | |
| 306 | + size="sm" | |
| 307 | + className="text-description hover:bg-input my-0 w-full justify-start py-1.5 pl-1 text-left" | |
| 308 | + > | |
| 309 | + <div className="flex w-full items-center"> | |
| 310 | + <ArrowRightStartOnRectangleIcon className="ml-1.5 mr-2 h-3.5 w-3.5 flex-shrink-0 rotate-180" /> | |
| 311 | + <span className="text-2xs">Log in</span> | |
| 312 | + </div> | |
| 313 | + </Button> | |
| 314 | + )} | |
| 315 | + | |
| 316 | + <Divider className="!mt-0" /> | |
| 317 | + </div> | |
| 318 | + )} | |
| 319 | + | |
| 320 | + {/* Bottom Actions */} | |
| 321 | + <div> | |
| 322 | + <div className="text-description flex items-center justify-start px-2 py-1"> | |
| 323 | + <span className="block" style={{ fontSize: tinyFont }}> | |
| 203 | 324 | <code>{getMetaKeyLabel()} ⇧ '</code> to toggle agent |
| 204 | 325 | </span> |
| 205 | 326 | </div> |
modified gui/src/components/History/HistoryTableRow.tsx +2 −2
| @@ -65,7 +65,7 @@ | ||
| 65 | 65 | onMouseEnter={() => setHovered(true)} |
| 66 | 66 | onMouseLeave={() => setHovered(false)} |
| 67 | 67 | data-testid={`history-row-${index}`} |
| 68 | - className="border-border relative mb-2 box-border flex w-full cursor-pointer overflow-hidden rounded-lg border border-solid p-3" | |
| 68 | + className="hover:bg-input relative mb-2 box-border flex w-full cursor-pointer overflow-hidden rounded-lg p-3" | |
| 69 | 69 | onClick={async () => { |
| 70 | 70 | await dispatch(exitEdit({})); |
| 71 | 71 | if (sessionMetadata.sessionId !== currentSessionId) { |
| @@ -117,7 +117,7 @@ | ||
| 117 | 117 | </td> |
| 118 | 118 | |
| 119 | 119 | {hovered && !editing && ( |
| 120 | - <td className="bg-badge absolute right-2 top-1/2 ml-auto flex -translate-y-1/2 transform items-center gap-x-1 rounded-full px-2 py-1 shadow-md"> | |
| 120 | + <td className="bg-input absolute right-2 top-1/2 ml-auto flex -translate-y-1/2 transform items-center gap-x-1 rounded-full px-2 py-1 shadow-md"> | |
| 121 | 121 | <HeaderButtonWithToolTip |
| 122 | 122 | text="Edit" |
| 123 | 123 | onClick={async (e) => { |
modified gui/src/components/History/index.tsx +3 −3
| @@ -146,7 +146,7 @@ | ||
| 146 | 146 | return ( |
| 147 | 147 | <div |
| 148 | 148 | style={{ fontSize: getFontSize() }} |
| 149 | - className="flex flex-1 flex-col overflow-auto px-1" | |
| 149 | + className="flex flex-1 flex-col overflow-auto overflow-x-hidden px-1" | |
| 150 | 150 | > |
| 151 | 151 | <div className="relative my-2 mt-4 flex justify-center space-x-2"> |
| 152 | 152 | <input |
| @@ -170,7 +170,7 @@ | ||
| 170 | 170 | )} |
| 171 | 171 | </div> |
| 172 | 172 | |
| 173 | - <div className="thin-scrollbar flex flex-1 flex-col overflow-y-auto"> | |
| 173 | + <div className="thin-scrollbar flex w-full flex-1 flex-col overflow-y-auto"> | |
| 174 | 174 | {filteredAndSortedSessions.length === 0 && ( |
| 175 | 175 | <div className="m-3 text-center"> |
| 176 | 176 | {isSessionMetadataLoading ? ( |
| @@ -185,7 +185,7 @@ | ||
| 185 | 185 | </div> |
| 186 | 186 | )} |
| 187 | 187 | |
| 188 | - <table className="flex flex-1 flex-col"> | |
| 188 | + <table className="flex w-full flex-1 flex-col"> | |
| 189 | 189 | <tbody className=""> |
| 190 | 190 | {sessionGroups.map((group, groupIndex) => ( |
| 191 | 191 | <Fragment key={group.label}> |
modified gui/src/components/InfoHover.tsx +15 −4
| @@ -1,22 +1,33 @@ | ||
| 1 | 1 | import { InformationCircleIcon } from "@heroicons/react/24/outline"; |
| 2 | +import { ReactNode } from "react"; | |
| 2 | 3 | import { ToolTip } from "./gui/Tooltip"; |
| 3 | 4 | |
| 4 | 5 | const DEFAULT_SIZE = "5"; |
| 5 | 6 | |
| 7 | +const sizeMap = { | |
| 8 | + "3": "h-3 w-3", | |
| 9 | + "4": "h-4 w-4", | |
| 10 | + "5": "h-5 w-5", | |
| 11 | + "6": "h-6 w-6", | |
| 12 | + "8": "h-8 w-8", | |
| 13 | +} as const; | |
| 14 | + | |
| 6 | 15 | const InfoHover = ({ |
| 7 | 16 | msg, |
| 8 | 17 | size, |
| 9 | 18 | id, |
| 10 | 19 | }: { |
| 11 | 20 | id: string; |
| 12 | - msg: string; | |
| 21 | + msg: ReactNode; | |
| 13 | 22 | size?: string; |
| 14 | 23 | }) => { |
| 24 | + const sizeClasses = | |
| 25 | + sizeMap[size as keyof typeof sizeMap] || | |
| 26 | + sizeMap[DEFAULT_SIZE as keyof typeof sizeMap]; | |
| 27 | + | |
| 15 | 28 | return ( |
| 16 | 29 | <ToolTip content={msg} place="bottom"> |
| 17 | - <InformationCircleIcon | |
| 18 | - className={`h-${size ?? DEFAULT_SIZE} w-${size ?? DEFAULT_SIZE} cursor-help text-gray-500`} | |
| 19 | - /> | |
| 30 | + <InformationCircleIcon className={`${sizeClasses} text-gray-500`} /> | |
| 20 | 31 | </ToolTip> |
| 21 | 32 | ); |
| 22 | 33 | }; |
modified gui/src/components/Layout.tsx +26 −29
| @@ -18,7 +18,6 @@ | ||
| 18 | 18 | import { ROUTES } from "../util/navigation"; |
| 19 | 19 | import TextDialog from "./dialogs"; |
| 20 | 20 | import { GenerateRuleDialog } from "./GenerateRuleDialog"; |
| 21 | -import { LumpProvider } from "./mainInput/Lump/LumpContext"; | |
| 22 | 21 | import { useMainEditor } from "./mainInput/TipTapEditor"; |
| 23 | 22 | import { |
| 24 | 23 | isNewUserOnboarding, |
| @@ -258,35 +257,33 @@ | ||
| 258 | 257 | }} |
| 259 | 258 | /> |
| 260 | 259 | )} |
| 261 | - <LumpProvider> | |
| 262 | - <OSRContextMenu /> | |
| 263 | - <div | |
| 264 | - style={{ | |
| 265 | - scrollbarGutter: "stable both-edges", | |
| 266 | - minHeight: "100%", | |
| 267 | - display: "grid", | |
| 268 | - gridTemplateRows: "1fr auto", | |
| 260 | + <OSRContextMenu /> | |
| 261 | + <div | |
| 262 | + style={{ | |
| 263 | + scrollbarGutter: "stable both-edges", | |
| 264 | + minHeight: "100%", | |
| 265 | + display: "grid", | |
| 266 | + gridTemplateRows: "1fr auto", | |
| 267 | + }} | |
| 268 | + > | |
| 269 | + <TextDialog | |
| 270 | + showDialog={showDialog} | |
| 271 | + onEnter={() => { | |
| 272 | + dispatch(setShowDialog(false)); | |
| 273 | + }} | |
| 274 | + onClose={() => { | |
| 275 | + dispatch(setShowDialog(false)); | |
| 269 | 276 | }} |
| 270 | - > | |
| 271 | - <TextDialog | |
| 272 | - showDialog={showDialog} | |
| 273 | - onEnter={() => { | |
| 274 | - dispatch(setShowDialog(false)); | |
| 275 | - }} | |
| 276 | - onClose={() => { | |
| 277 | - dispatch(setShowDialog(false)); | |
| 278 | - }} | |
| 279 | - message={dialogMessage} | |
| 280 | - /> | |
| 281 | - | |
| 282 | - <GridDiv> | |
| 283 | - <PostHogPageView /> | |
| 284 | - <Outlet /> | |
| 285 | - <FatalErrorIndicator /> | |
| 286 | - </GridDiv> | |
| 287 | - </div> | |
| 288 | - <div style={{ fontSize: fontSize(-4) }} id="tooltip-portal-div" /> | |
| 289 | - </LumpProvider> | |
| 277 | + message={dialogMessage} | |
| 278 | + /> | |
| 279 | + | |
| 280 | + <GridDiv> | |
| 281 | + <PostHogPageView /> | |
| 282 | + <Outlet /> | |
| 283 | + <FatalErrorIndicator /> | |
| 284 | + </GridDiv> | |
| 285 | + </div> | |
| 286 | + <div style={{ fontSize: fontSize(-4) }} id="tooltip-portal-div" /> | |
| 290 | 287 | </LayoutTopDiv> |
| 291 | 288 | </TelemetryProviders> |
| 292 | 289 | </AuthProvider> |
modified gui/src/components/OnboardingCard/hooks/useSubmitOnboarding.ts +0 −3
| @@ -3,14 +3,12 @@ | ||
| 3 | 3 | import { useContext } from "react"; |
| 4 | 4 | import { IdeMessengerContext } from "../../../context/IdeMessenger"; |
| 5 | 5 | import { getLocalStorage, setLocalStorage } from "../../../util/localStorage"; |
| 6 | -import { useLump } from "../../mainInput/Lump/LumpContext"; | |
| 7 | 6 | import { useOnboardingCard } from "./useOnboardingCard"; |
| 8 | 7 | |
| 9 | 8 | export function useSubmitOnboarding(mode: OnboardingModes, isDialog = false) { |
| 10 | 9 | const posthog = usePostHog(); |
| 11 | 10 | const ideMessenger = useContext(IdeMessengerContext); |
| 12 | 11 | const { close: closeOnboardingCard } = useOnboardingCard(); |
| 13 | - const { setSelectedSection } = useLump(); | |
| 14 | 12 | |
| 15 | 13 | function submitOnboarding(provider?: string, apiKey?: string) { |
| 16 | 14 | const onboardingStatus = getLocalStorage("onboardingStatus"); |
| @@ -39,7 +37,6 @@ | ||
| 39 | 37 | } |
| 40 | 38 | |
| 41 | 39 | ideMessenger.post("config/openProfile", { profileId: undefined }); |
| 42 | - setSelectedSection("models"); | |
| 43 | 40 | } |
| 44 | 41 | |
| 45 | 42 | return { |
modified gui/src/components/PageHeader.tsx +9 −31
| @@ -1,49 +1,27 @@ | ||
| 1 | 1 | import { ArrowLeftIcon } from "@heroicons/react/24/outline"; |
| 2 | -import { useFontSize } from "./ui/font"; | |
| 3 | 2 | |
| 4 | 3 | export interface PageHeaderProps { |
| 5 | 4 | onTitleClick?: () => void; |
| 6 | 5 | title?: string; |
| 7 | - rightContent?: React.ReactNode; | |
| 8 | 6 | showBorder?: boolean; |
| 9 | 7 | } |
| 10 | 8 | |
| 11 | 9 | export function PageHeader({ |
| 12 | 10 | onTitleClick, |
| 13 | 11 | title, |
| 14 | - rightContent, | |
| 15 | - showBorder, | |
| 12 | + showBorder = true, | |
| 16 | 13 | }: PageHeaderProps) { |
| 17 | - const fontSize = useFontSize(-1); | |
| 18 | - | |
| 19 | 14 | return ( |
| 20 | 15 | <div |
| 21 | - className={`sticky top-0 z-20 m-0 flex items-center justify-between bg-inherit py-1 ${ | |
| 22 | - showBorder | |
| 23 | - ? "border-0 border-b-[1px] border-solid border-b-zinc-700" | |
| 24 | - : "" | |
| 25 | - }`} | |
| 16 | + className={`border-command-border sticky top-0 z-20 m-0 flex items-center justify-between border border-x-0 ${showBorder ? "border-b" : "border-b-0"} border-t-0 border-solid bg-inherit py-3.5`} | |
| 26 | 17 | > |
| 27 | - {title ? ( | |
| 28 | - <div | |
| 29 | - className="flex cursor-pointer items-center transition-colors duration-200 hover:brightness-125" | |
| 30 | - onClick={onTitleClick} | |
| 31 | - > | |
| 32 | - <ArrowLeftIcon className="ml-3 inline-block h-3 w-3" /> | |
| 33 | - <span | |
| 34 | - className="mx-2 inline-block text-lg font-bold" | |
| 35 | - style={{ | |
| 36 | - fontSize, | |
| 37 | - }} | |
| 38 | - > | |
| 39 | - {title} | |
| 40 | - </span> | |
| 41 | - </div> | |
| 42 | - ) : ( | |
| 43 | - <div /> | |
| 44 | - )} | |
| 45 | - | |
| 46 | - {rightContent && <div className="pr-2">{rightContent}</div>} | |
| 18 | + <div | |
| 19 | + className="flex cursor-pointer items-center transition-colors duration-200 hover:brightness-125" | |
| 20 | + onClick={onTitleClick} | |
| 21 | + > | |
| 22 | + <ArrowLeftIcon className="ml-3 inline-block h-3 w-3" /> | |
| 23 | + {title && <span className="mx-2 inline-block font-bold">{title}</span>} | |
| 24 | + </div> | |
| 47 | 25 | </div> |
| 48 | 26 | ); |
| 49 | 27 | } |
modified gui/src/components/StepContainer/StepContainer.tsx +8 −21
| @@ -22,9 +22,6 @@ | ||
| 22 | 22 | const dispatch = useDispatch(); |
| 23 | 23 | const [isTruncated, setIsTruncated] = useState(false); |
| 24 | 24 | const isStreaming = useAppSelector((state) => state.session.isStreaming); |
| 25 | - const historyItemAfterThis = useAppSelector( | |
| 26 | - (state) => state.session.history[props.index + 1], | |
| 27 | - ); | |
| 28 | 25 | const uiConfig = useAppSelector(selectUIConfig); |
| 29 | 26 | |
| 30 | 27 | // Calculate dimming and indicator state based on latest summary index |
| @@ -34,22 +31,12 @@ | ||
| 34 | 31 | const isLatestSummary = |
| 35 | 32 | latestSummaryIndex !== -1 && props.index === latestSummaryIndex; |
| 36 | 33 | |
| 37 | - const isNextMsgAssistantOrThinking = | |
| 38 | - historyItemAfterThis?.message.role === "assistant" || | |
| 39 | - historyItemAfterThis?.message.role === "thinking" || | |
| 40 | - historyItemAfterThis?.message.role === "tool"; | |
| 41 | - | |
| 42 | - const shouldRenderResponseAction = () => { | |
| 43 | - if (isNextMsgAssistantOrThinking) { | |
| 44 | - return false; | |
| 45 | - } | |
| 46 | - | |
| 47 | - if (!historyItemAfterThis) { | |
| 48 | - return !props.item.toolCallStates; | |
| 49 | - } | |
| 50 | - | |
| 51 | - return true; | |
| 52 | - }; | |
| 34 | + const historyItemAfterThis = useAppSelector( | |
| 35 | + (state) => state.session.history[props.index + 1], | |
| 36 | + ); | |
| 37 | + const showResponseActions = | |
| 38 | + (props.isLast || historyItemAfterThis?.message.role === "user") && | |
| 39 | + !(props.isLast && (isStreaming || props.item.toolCallStates)); | |
| 53 | 40 | |
| 54 | 41 | useEffect(() => { |
| 55 | 42 | if (!isStreaming) { |
| @@ -110,9 +97,9 @@ | ||
| 110 | 97 | {props.isLast && <ThinkingIndicator historyItem={props.item} />} |
| 111 | 98 | </div> |
| 112 | 99 | |
| 113 | - {shouldRenderResponseAction() && !isStreaming && ( | |
| 100 | + {showResponseActions && ( | |
| 114 | 101 | <div |
| 115 | - className={`mt-2 h-7 transition-opacity duration-300 ease-in-out ${isBeforeLatestSummary ? "opacity-35" : ""}`} | |
| 102 | + className={`mt-2 h-7 transition-opacity duration-300 ease-in-out ${isBeforeLatestSummary || isStreaming ? "opacity-35" : ""} ${isStreaming && "pointer-events-none cursor-not-allowed"}`} | |
| 116 | 103 | > |
| 117 | 104 | <ResponseActions |
| 118 | 105 | isTruncated={isTruncated} |
modified gui/src/components/config/FatalErrorNotice.tsx +4 −10
| @@ -3,9 +3,8 @@ | ||
| 3 | 3 | import { useAuth } from "../../context/Auth"; |
| 4 | 4 | import { IdeMessengerContext } from "../../context/IdeMessenger"; |
| 5 | 5 | import { useAppSelector } from "../../redux/hooks"; |
| 6 | -import { ROUTES } from "../../util/navigation"; | |
| 6 | +import { CONFIG_ROUTES } from "../../util/navigation"; | |
| 7 | 7 | import Alert from "../gui/Alert"; |
| 8 | -import { useLump } from "../mainInput/Lump/LumpContext"; | |
| 9 | 8 | |
| 10 | 9 | export const FatalErrorIndicator = () => { |
| 11 | 10 | const { refreshProfiles } = useAuth(); |
| @@ -18,12 +17,10 @@ | ||
| 18 | 17 | return configError?.some((error) => error.fatal); |
| 19 | 18 | }, [configError]); |
| 20 | 19 | |
| 21 | - const { setSelectedSection, selectedSection } = useLump(); | |
| 22 | 20 | const configLoading = useAppSelector((state) => state.config.loading); |
| 23 | 21 | |
| 24 | - const showLumpErrorSection = () => { | |
| 25 | - navigate(ROUTES.HOME); | |
| 26 | - setSelectedSection("error"); | |
| 22 | + const showConfigPage = () => { | |
| 23 | + navigate(CONFIG_ROUTES.AGENTS); | |
| 27 | 24 | }; |
| 28 | 25 | |
| 29 | 26 | const { selectedProfile } = useAuth(); |
| @@ -67,10 +64,7 @@ | ||
| 67 | 64 | Reload |
| 68 | 65 | </div> |
| 69 | 66 | )} |
| 70 | - <div | |
| 71 | - onClick={showLumpErrorSection} | |
| 72 | - className={`cursor-pointer underline transition-all ${selectedSection === "error" ? "opacity-0" : ""}`} | |
| 73 | - > | |
| 67 | + <div onClick={showConfigPage} className="cursor-pointer underline"> | |
| 74 | 68 | View |
| 75 | 69 | </div> |
| 76 | 70 | </div> |
modified gui/src/components/dialogs/AddDocsDialog.tsx +1 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | import { updateIndexingStatus } from "../../redux/slices/indexingSlice"; |
| 10 | 10 | import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; |
| 11 | 11 | import { ToolTip } from "../gui/Tooltip"; |
| 12 | -import DocsIndexingPeeks from "../mainInput/Lump/sections/docs/DocsIndexingPeeks"; | |
| 12 | +import DocsIndexingPeeks from "../../pages/config/sections/docs/DocsIndexingPeeks"; | |
| 13 | 13 | |
| 14 | 14 | function AddDocsDialog() { |
| 15 | 15 | const posthog = usePostHog(); |
modified gui/src/components/gui/Alert.tsx +30 −17
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | ExclamationTriangleIcon, |
| 5 | 5 | InformationCircleIcon, |
| 6 | 6 | } from "@heroicons/react/16/solid"; |
| 7 | +import { varWithFallback } from "../../styles/theme"; | |
| 7 | 8 | import { cn } from "../../util/cn"; |
| 8 | 9 | |
| 9 | 10 | type AlertTypes = "info" | "success" | "warning" | "error"; |
| @@ -18,7 +19,6 @@ | ||
| 18 | 19 | [key in AlertTypes]: { |
| 19 | 20 | Icon: any; |
| 20 | 21 | iconColor: string; |
| 21 | - background: string; | |
| 22 | 22 | border: string; |
| 23 | 23 | text: string; |
| 24 | 24 | }; |
| @@ -27,28 +27,24 @@ | ||
| 27 | 27 | const ALERT_CONFIGS: AlertConfig = { |
| 28 | 28 | info: { |
| 29 | 29 | Icon: InformationCircleIcon, |
| 30 | - background: "bg-background", | |
| 31 | - border: "border-foreground", | |
| 32 | - iconColor: "text-foreground", | |
| 30 | + border: "border-info", | |
| 31 | + iconColor: "text-info", | |
| 33 | 32 | text: "text-foreground", |
| 34 | 33 | }, |
| 35 | 34 | success: { |
| 36 | 35 | Icon: CheckCircleIcon, |
| 37 | - background: "bg-green-600/20", | |
| 38 | 36 | border: "border-success", |
| 39 | 37 | iconColor: "text-success", |
| 40 | 38 | text: "text-foreground", |
| 41 | 39 | }, |
| 42 | 40 | warning: { |
| 43 | 41 | Icon: ExclamationTriangleIcon, |
| 44 | - background: "bg-yellow-600/20", | |
| 45 | 42 | border: "border-warning", |
| 46 | 43 | iconColor: "text-warning", |
| 47 | 44 | text: "text-foreground", |
| 48 | 45 | }, |
| 49 | 46 | error: { |
| 50 | 47 | Icon: ExclamationCircleIcon, |
| 51 | - background: "bg-red-600/20", | |
| 52 | 48 | border: "border-error", |
| 53 | 49 | iconColor: "text-error", |
| 54 | 50 | text: "text-foreground", |
| @@ -56,33 +52,50 @@ | ||
| 56 | 52 | }; |
| 57 | 53 | |
| 58 | 54 | const alertSizes = { |
| 59 | - sm: "px-3 py-1.5 rounded-md border", | |
| 60 | - lg: "px-4 py-3 rounded-md border", | |
| 55 | + sm: "px-3 py-2 rounded-md", | |
| 56 | + lg: "px-3 py-2.5 rounded-md", | |
| 61 | 57 | }; |
| 62 | 58 | |
| 63 | 59 | const iconSizes = { |
| 64 | - sm: "h-4 w-4 mt-1", | |
| 65 | - lg: "h-5 w-5 mt-0.5", | |
| 60 | + sm: "h-4 w-4", | |
| 61 | + lg: "h-4 w-4", | |
| 66 | 62 | }; |
| 67 | 63 | |
| 68 | 64 | const spacingSizes = { |
| 69 | 65 | sm: "ml-2", |
| 70 | - lg: "ml-3", | |
| 66 | + lg: "ml-2", | |
| 71 | 67 | }; |
| 72 | 68 | |
| 73 | -function Alert({ type = "info", size = "lg", ...props }: AlertProps) { | |
| 74 | - const { Icon, background, border, text, iconColor } = ALERT_CONFIGS[type]; | |
| 69 | +function Alert({ | |
| 70 | + type = "info", | |
| 71 | + size = "lg", | |
| 72 | + className, | |
| 73 | + children, | |
| 74 | + ...props | |
| 75 | +}: AlertProps) { | |
| 76 | + const { Icon, border, text, iconColor } = ALERT_CONFIGS[type]; | |
| 77 | + | |
| 78 | + const colorMap = { | |
| 79 | + info: varWithFallback("info"), | |
| 80 | + success: varWithFallback("success"), | |
| 81 | + warning: varWithFallback("warning"), | |
| 82 | + error: varWithFallback("error"), | |
| 83 | + }; | |
| 75 | 84 | |
| 76 | 85 | return ( |
| 77 | 86 | <div |
| 78 | 87 | className={cn( |
| 79 | - `flex flex-row items-start ${background} border-[0.5px] border-solid ${border} shadow-sm ${alertSizes[size]}`, | |
| 80 | - props.className, | |
| 88 | + `flex flex-row items-start border-[0.5px] ${border} border-solid shadow-sm ${alertSizes[size]}`, | |
| 89 | + className, | |
| 81 | 90 | )} |
| 91 | + style={{ | |
| 92 | + backgroundColor: `color-mix(in srgb, ${colorMap[type]} 20%, transparent)`, | |
| 93 | + }} | |
| 94 | + {...props} | |
| 82 | 95 | > |
| 83 | 96 | <Icon className={`flex-shrink-0 ${iconColor} ${iconSizes[size]}`} /> |
| 84 | 97 | <div className="flex flex-1 flex-col"> |
| 85 | - <div className={`${spacingSizes[size]} ${text}`}>{props.children}</div> | |
| 98 | + <div className={`${spacingSizes[size]} ${text}`}>{children}</div> | |
| 86 | 99 | </div> |
| 87 | 100 | </div> |
| 88 | 101 | ); |
deleted gui/src/components/gui/NumberInput.tsx +0 −91
| @@ -1,91 +0,0 @@ | ||
| 1 | -import React, { useState } from "react"; | |
| 2 | - | |
| 3 | -interface NumberInputProps { | |
| 4 | - value: number; | |
| 5 | - onChange: (value: number) => void; | |
| 6 | - max: number; | |
| 7 | - min: number; | |
| 8 | -} | |
| 9 | - | |
| 10 | -const NumberInput: React.FC<NumberInputProps> = ({ | |
| 11 | - value, | |
| 12 | - onChange, | |
| 13 | - max, | |
| 14 | - min, | |
| 15 | -}) => { | |
| 16 | - const [inputValue, setInputValue] = useState(value.toString()); | |
| 17 | - | |
| 18 | - const handleIncrement = () => { | |
| 19 | - if (value < max) { | |
| 20 | - const newValue = value + 1; | |
| 21 | - onChange(newValue); | |
| 22 | - setInputValue(newValue.toString()); | |
| 23 | - } | |
| 24 | - }; | |
| 25 | - | |
| 26 | - const handleDecrement = () => { | |
| 27 | - if (value > min) { | |
| 28 | - const newValue = value - 1; | |
| 29 | - onChange(newValue); | |
| 30 | - setInputValue(newValue.toString()); | |
| 31 | - } | |
| 32 | - }; | |
| 33 | - | |
| 34 | - const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => { | |
| 35 | - const newInputValue = e.target.value; | |
| 36 | - setInputValue(newInputValue); | |
| 37 | - | |
| 38 | - // Only update the actual value if it's a valid number | |
| 39 | - const numValue = parseInt(newInputValue, 10); | |
| 40 | - if (!isNaN(numValue)) { | |
| 41 | - // Apply min/max constraints | |
| 42 | - const constrainedValue = Math.min(Math.max(numValue, min), max); | |
| 43 | - onChange(constrainedValue); | |
| 44 | - } | |
| 45 | - }; | |
| 46 | - | |
| 47 | - const handleBlur = () => { | |
| 48 | - // When input loses focus, ensure the displayed value matches the actual value | |
| 49 | - // This handles cases where the user entered an invalid value | |
| 50 | - setInputValue(value.toString()); | |
| 51 | - }; | |
| 52 | - | |
| 53 | - return ( | |
| 54 | - <div className="border-vsc-input-border bg-vsc-input-background flex flex-row overflow-hidden rounded-md border border-solid"> | |
| 55 | - <input | |
| 56 | - type="text" | |
| 57 | - value={inputValue} | |
| 58 | - onChange={handleInputChange} | |
| 59 | - onBlur={handleBlur} | |
| 60 | - className="text-vsc-foreground max-w-9 border-none bg-inherit pr-1.5 text-right outline-none ring-0 focus:border-none focus:outline-none focus:ring-0" | |
| 61 | - style={{ | |
| 62 | - appearance: "none", | |
| 63 | - WebkitAppearance: "none", | |
| 64 | - MozAppearance: "none", | |
| 65 | - }} | |
| 66 | - min={min} | |
| 67 | - max={max} | |
| 68 | - /> | |
| 69 | - <div className="flex flex-col"> | |
| 70 | - <button | |
| 71 | - style={{ fontSize: "9px" }} | |
| 72 | - onClick={handleIncrement} | |
| 73 | - disabled={value >= max} | |
| 74 | - className="text-vsc-foreground m-0 mb-0.5 cursor-pointer border-none bg-inherit px-1.5 py-0 hover:opacity-80" | |
| 75 | - > | |
| 76 | - ▲ | |
| 77 | - </button> | |
| 78 | - <button | |
| 79 | - style={{ fontSize: "9px" }} | |
| 80 | - className="text-vsc-foreground m-0 mb-0.5 cursor-pointer border-none bg-inherit px-1.5 py-0 hover:opacity-80" | |
| 81 | - onClick={handleDecrement} | |
| 82 | - disabled={value <= min} | |
| 83 | - > | |
| 84 | - ▼ | |
| 85 | - </button> | |
| 86 | - </div> | |
| 87 | - </div> | |
| 88 | - ); | |
| 89 | -}; | |
| 90 | - | |
| 91 | -export default NumberInput; |
modified gui/src/components/gui/Select.tsx +12 −7
| @@ -5,7 +5,12 @@ | ||
| 5 | 5 | // background-color: ${vscBackground}; |
| 6 | 6 | // color: ${vscForeground}; |
| 7 | 7 | |
| 8 | -import { vscBackground, vscForeground, vscInputBorder } from ".."; | |
| 8 | +import { | |
| 9 | + vscCommandCenterInactiveBorder, | |
| 10 | + vscForeground, | |
| 11 | + vscInputBackground, | |
| 12 | +} from ".."; | |
| 13 | +import { cn } from "../../util/cn"; | |
| 9 | 14 | |
| 10 | 15 | // appearance: none; |
| 11 | 16 | // -webkit-appearance: none; |
| @@ -19,9 +24,9 @@ | ||
| 19 | 24 | // // gui/src/components/gui/Select.tsx |
| 20 | 25 | // import React from 'react'; |
| 21 | 26 | |
| 22 | -export const Select: React.FC<React.SelectHTMLAttributes<HTMLSelectElement>> = ( | |
| 23 | - props, | |
| 24 | -) => ( | |
| 27 | +export const Select: React.FC< | |
| 28 | + React.SelectHTMLAttributes<HTMLSelectElement> | |
| 29 | +> = ({ className, ...props }) => ( | |
| 25 | 30 | <div |
| 26 | 31 | style={{ |
| 27 | 32 | color: vscForeground, |
| @@ -29,10 +34,10 @@ | ||
| 29 | 34 | > |
| 30 | 35 | <select |
| 31 | 36 | {...props} |
| 32 | - className="rounded border px-3 py-2" | |
| 37 | + className={cn("rounded-default border px-3 py-1.5", className)} | |
| 33 | 38 | style={{ |
| 34 | - borderColor: vscInputBorder, | |
| 35 | - backgroundColor: vscBackground, | |
| 39 | + borderColor: vscCommandCenterInactiveBorder, | |
| 40 | + backgroundColor: vscInputBackground, | |
| 36 | 41 | color: vscForeground, |
| 37 | 42 | appearance: "none", |
| 38 | 43 | WebkitAppearance: "none", |
modified gui/src/components/gui/Switch.tsx +1 −1
| @@ -37,7 +37,7 @@ | ||
| 37 | 37 | <div className="flex flex-row items-center gap-1"> |
| 38 | 38 | {isToggled && !!showIfToggled && showIfToggled} |
| 39 | 39 | <div |
| 40 | - className={`border-vsc-input-border bg-vsc-input-background relative flex items-center rounded-full border border-solid`} | |
| 40 | + className={`border-command-border bg-vsc-input-background relative flex items-center rounded-full border border-solid`} | |
| 41 | 41 | onClick={disabled ? undefined : onToggle} |
| 42 | 42 | style={{ |
| 43 | 43 | height: size, |
modified gui/src/components/gui/Tooltip.tsx +1 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | const TooltipStyles: CSSProperties = { |
| 10 | 10 | fontSize: fontSize(-4), |
| 11 | 11 | backgroundColor: vscBackground, |
| 12 | - outline: `0.5px solid ${varWithFallback("badge-background")}`, | |
| 12 | + outline: `0.5px solid ${varWithFallback("description")}`, | |
| 13 | 13 | color: vscForeground, |
| 14 | 14 | padding: "4px 8px", |
| 15 | 15 | zIndex: 1000, |
modified gui/src/components/mainInput/ContextStatus.tsx +1 −1
| @@ -68,7 +68,7 @@ | ||
| 68 | 68 | </div> |
| 69 | 69 | } |
| 70 | 70 | > |
| 71 | - <div className="border-description-muted relative h-[14px] w-[7px] rounded-[1px] border-[0.5px] border-solid md:h-[10px] md:w-[5px]"> | |
| 71 | + <div className="border-command-border relative h-[14px] w-[7px] rounded-[1px] border-[0.5px] border-solid md:h-[10px] md:w-[5px]"> | |
| 72 | 72 | <div |
| 73 | 73 | className={`transition-height absolute bottom-0 left-0 w-full duration-300 ease-in-out ${barColorClass}`} |
| 74 | 74 | style={{ height: `${percent}%` }} |
modified gui/src/components/mainInput/InputToolbar.tsx +18 −11
| @@ -13,7 +13,7 @@ | ||
| 13 | 13 | import { selectSelectedChatModel } from "../../redux/slices/configSlice"; |
| 14 | 14 | import { setHasReasoningEnabled } from "../../redux/slices/sessionSlice"; |
| 15 | 15 | import { exitEdit } from "../../redux/thunks/edit"; |
| 16 | -import { getAltKeyLabel, isMetaEquivalentKeyPressed } from "../../util"; | |
| 16 | +import { getMetaKeyLabel, isMetaEquivalentKeyPressed } from "../../util"; | |
| 17 | 17 | import { ToolTip } from "../gui/Tooltip"; |
| 18 | 18 | import ModelSelect from "../modelSelection/ModelSelect"; |
| 19 | 19 | import { ModeSelect } from "../ModeSelect"; |
| @@ -165,7 +165,13 @@ | ||
| 165 | 165 | {!props.toolbarOptions?.hideUseCodebase && !isInEdit && ( |
| 166 | 166 | <div className="hidden transition-colors duration-200 hover:underline md:flex"> |
| 167 | 167 | <HoverItem |
| 168 | - className={props.activeKey === "Alt" ? "underline" : ""} | |
| 168 | + className={ | |
| 169 | + props.activeKey === "Meta" || | |
| 170 | + props.activeKey === "Control" || | |
| 171 | + props.activeKey === "Alt" | |
| 172 | + ? "underline" | |
| 173 | + : "" | |
| 174 | + } | |
| 169 | 175 | onClick={(e) => |
| 170 | 176 | props.onEnter?.({ |
| 171 | 177 | useCodebase: false, |
| @@ -175,15 +181,14 @@ | ||
| 175 | 181 | > |
| 176 | 182 | <ToolTip |
| 177 | 183 | place="top-end" |
| 178 | - content={` | |
| 179 | - ${ | |
| 180 | - useActiveFile | |
| 181 | - ? "Send Without Active File" | |
| 182 | - : "Send With Active File" | |
| 183 | - } (${getAltKeyLabel()}⏎)`} | |
| 184 | + content={`${ | |
| 185 | + useActiveFile | |
| 186 | + ? "Send Without Active File" | |
| 187 | + : "Send With Active File" | |
| 188 | + } (${getMetaKeyLabel()}⏎)`} | |
| 184 | 189 | > |
| 185 | 190 | <span> |
| 186 | - {getAltKeyLabel()}⏎{" "} | |
| 191 | + {getMetaKeyLabel()}⏎{" "} | |
| 187 | 192 | {useActiveFile ? "No active file" : "Active file"} |
| 188 | 193 | </span> |
| 189 | 194 | </ToolTip> |
| @@ -211,8 +216,10 @@ | ||
| 211 | 216 | onClick={async (e) => { |
| 212 | 217 | if (props.onEnter) { |
| 213 | 218 | props.onEnter({ |
| 214 | - useCodebase: isMetaEquivalentKeyPressed(e as any), | |
| 215 | - noContext: useActiveFile ? e.altKey : !e.altKey, | |
| 219 | + useCodebase: false, | |
| 220 | + noContext: useActiveFile | |
| 221 | + ? !(isMetaEquivalentKeyPressed(e as any) || e.altKey) | |
| 222 | + : isMetaEquivalentKeyPressed(e as any) || e.altKey, | |
| 216 | 223 | }); |
| 217 | 224 | } |
| 218 | 225 | }} |
deleted gui/src/components/mainInput/Lump/LumpContext.tsx +0 −124
| @@ -1,124 +0,0 @@ | ||
| 1 | -/** | |
| 2 | - * Provides context for controlling the Lump component's visibility state | |
| 3 | - */ | |
| 4 | -import { | |
| 5 | - createContext, | |
| 6 | - ReactNode, | |
| 7 | - useCallback, | |
| 8 | - useContext, | |
| 9 | - useEffect, | |
| 10 | - useState, | |
| 11 | -} from "react"; | |
| 12 | -import { useAppSelector } from "../../../redux/hooks"; | |
| 13 | - | |
| 14 | -interface LumpContextType { | |
| 15 | - isLumpVisible: boolean; | |
| 16 | - selectedSection: string | null; | |
| 17 | - displayedSection: string | null; | |
| 18 | - isToolbarExpanded: boolean; | |
| 19 | - hideLump: () => void; | |
| 20 | - setSelectedSection: (section: string | null) => void; | |
| 21 | - toggleToolbar: () => void; | |
| 22 | -} | |
| 23 | - | |
| 24 | -const LumpContext = createContext<LumpContextType | undefined>(undefined); | |
| 25 | - | |
| 26 | -interface LumpProviderProps { | |
| 27 | - children: ReactNode; | |
| 28 | -} | |
| 29 | - | |
| 30 | -/** | |
| 31 | - * Provider component that makes Lump state available to any child component | |
| 32 | - */ | |
| 33 | -export function LumpProvider({ children }: LumpProviderProps) { | |
| 34 | - const [selectedSection, setSelectedSection] = useState<string | null>(null); | |
| 35 | - const [displayedSection, setDisplayedSection] = useState<string | null>(null); | |
| 36 | - const [isVisible, setIsVisible] = useState(false); | |
| 37 | - const [isToolbarExpanded, setIsToolbarExpanded] = useState(true); | |
| 38 | - const isStreaming = useAppSelector((state) => state.session.isStreaming); | |
| 39 | - | |
| 40 | - const configError = useAppSelector((store) => store.config.configError); | |
| 41 | - | |
| 42 | - // Handle keyboard escape | |
| 43 | - const handleKeyDown = useCallback( | |
| 44 | - (event: KeyboardEvent) => { | |
| 45 | - if (event.key === "Escape" && selectedSection) { | |
| 46 | - setSelectedSection(null); | |
| 47 | - } | |
| 48 | - }, | |
| 49 | - [selectedSection], | |
| 50 | - ); | |
| 51 | - | |
| 52 | - // Function to hide the lump | |
| 53 | - const hideLump = useCallback(() => { | |
| 54 | - setSelectedSection(null); | |
| 55 | - }, []); | |
| 56 | - | |
| 57 | - // Function to toggle toolbar expanded state | |
| 58 | - const toggleToolbar = useCallback(() => { | |
| 59 | - setIsToolbarExpanded((prev) => !prev); | |
| 60 | - }, []); | |
| 61 | - | |
| 62 | - // Update displayedSection and visibility when selectedSection changes | |
| 63 | - useEffect(() => { | |
| 64 | - if (selectedSection) { | |
| 65 | - setDisplayedSection(selectedSection); | |
| 66 | - setIsVisible(true); | |
| 67 | - } else { | |
| 68 | - setIsVisible(false); | |
| 69 | - const timeout = setTimeout(() => { | |
| 70 | - setDisplayedSection(null); | |
| 71 | - }, 300); | |
| 72 | - return () => clearTimeout(timeout); | |
| 73 | - } | |
| 74 | - }, [selectedSection]); | |
| 75 | - | |
| 76 | - // Don't allow selection error section if there are no errors | |
| 77 | - useEffect(() => { | |
| 78 | - if (selectedSection === "error" && !configError) { | |
| 79 | - setSelectedSection(null); | |
| 80 | - } | |
| 81 | - }, [selectedSection, configError]); | |
| 82 | - | |
| 83 | - // Reset when streaming starts | |
| 84 | - useEffect(() => { | |
| 85 | - if (isStreaming && selectedSection) { | |
| 86 | - setSelectedSection(null); | |
| 87 | - } | |
| 88 | - }, [isStreaming, selectedSection]); | |
| 89 | - | |
| 90 | - // Set up keyboard listener | |
| 91 | - useEffect(() => { | |
| 92 | - if (selectedSection) { | |
| 93 | - document.addEventListener("keydown", handleKeyDown); | |
| 94 | - return () => document.removeEventListener("keydown", handleKeyDown); | |
| 95 | - } | |
| 96 | - }, [selectedSection, handleKeyDown]); | |
| 97 | - | |
| 98 | - return ( | |
| 99 | - <LumpContext.Provider | |
| 100 | - value={{ | |
| 101 | - isLumpVisible: isVisible, | |
| 102 | - selectedSection, | |
| 103 | - displayedSection, | |
| 104 | - isToolbarExpanded, | |
| 105 | - hideLump, | |
| 106 | - setSelectedSection, | |
| 107 | - toggleToolbar, | |
| 108 | - }} | |
| 109 | - > | |
| 110 | - {children} | |
| 111 | - </LumpContext.Provider> | |
| 112 | - ); | |
| 113 | -} | |
| 114 | - | |
| 115 | -/** | |
| 116 | - * Hook that lets any component access the Lump context | |
| 117 | - */ | |
| 118 | -export function useLump() { | |
| 119 | - const context = useContext(LumpContext); | |
| 120 | - if (context === undefined) { | |
| 121 | - throw new Error("useLump must be used within a LumpProvider"); | |
| 122 | - } | |
| 123 | - return context; | |
| 124 | -} |
modified gui/src/components/mainInput/Lump/LumpToolbar/BlockSettingsTopToolbar.tsx +41 −187
| @@ -1,140 +1,19 @@ | ||
| 1 | -import { | |
| 2 | - ChatBubbleLeftIcon, | |
| 3 | - ChevronLeftIcon, | |
| 4 | - CubeIcon, | |
| 5 | - EllipsisHorizontalIcon, | |
| 6 | - ExclamationTriangleIcon, | |
| 7 | - PencilIcon, | |
| 8 | - Squares2X2Icon, | |
| 9 | - WrenchScrewdriverIcon, | |
| 10 | -} from "@heroicons/react/24/outline"; | |
| 11 | -import { ReactNode, useContext, useEffect, useState } from "react"; | |
| 12 | -import { vscBadgeForeground } from "../../.."; | |
| 1 | +import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; | |
| 2 | +import { useContext, useEffect, useState } from "react"; | |
| 3 | +import { useNavigate } from "react-router-dom"; | |
| 13 | 4 | import { IdeMessengerContext } from "../../../../context/IdeMessenger"; |
| 14 | 5 | import { useAppSelector } from "../../../../redux/hooks"; |
| 15 | 6 | import FreeTrialButton from "../../../FreeTrialButton"; |
| 16 | 7 | import { ToolTip } from "../../../gui/Tooltip"; |
| 17 | -import { useFontSize } from "../../../ui/font"; | |
| 18 | -import HoverItem from "../../InputToolbar/HoverItem"; | |
| 19 | -import { useLump } from "../LumpContext"; | |
| 20 | -import { ErrorsSectionTooltip } from "../sections/errors/ErrorsSectionTooltip"; | |
| 21 | -import { McpSectionTooltip } from "../sections/mcp/MCPTooltip"; | |
| 22 | -import { ToolsSectionTooltip } from "../sections/tool-policies/ToolPoliciesSectionTooltip"; | |
| 23 | 8 | |
| 24 | 9 | import { usesFreeTrialApiKey } from "core/config/usesFreeTrialApiKey"; |
| 25 | 10 | import type { FreeTrialStatus } from "core/control-plane/client"; |
| 26 | 11 | import { getLocalStorage } from "../../../../util/localStorage"; |
| 12 | +import { CONFIG_ROUTES } from "../../../../util/navigation"; | |
| 27 | 13 | import { AssistantAndOrgListbox } from "../../../AssistantAndOrgListbox"; |
| 28 | 14 | |
| 29 | -interface BlockSettingsToolbarIcon { | |
| 30 | - title: string; | |
| 31 | - tooltip: ReactNode; | |
| 32 | - icon: React.ComponentType<any>; | |
| 33 | - itemCount?: number; | |
| 34 | - onClick: () => void; | |
| 35 | - isSelected?: boolean; | |
| 36 | - className?: string; | |
| 37 | -} | |
| 38 | - | |
| 39 | -interface Section { | |
| 40 | - id: string; | |
| 41 | - title: string; | |
| 42 | - tooltip: ReactNode; | |
| 43 | - icon: React.ComponentType<any>; | |
| 44 | -} | |
| 45 | - | |
| 46 | -const sections: Section[] = [ | |
| 47 | - { id: "models", title: "Models", tooltip: "Models", icon: CubeIcon }, | |
| 48 | - { id: "rules", title: "Rules", tooltip: "Rules", icon: PencilIcon }, | |
| 49 | - { | |
| 50 | - id: "prompts", | |
| 51 | - title: "Prompts", | |
| 52 | - tooltip: "Prompts", | |
| 53 | - icon: ChatBubbleLeftIcon, | |
| 54 | - }, | |
| 55 | - { | |
| 56 | - id: "tools", | |
| 57 | - title: "Tools", | |
| 58 | - tooltip: <ToolsSectionTooltip />, | |
| 59 | - icon: WrenchScrewdriverIcon, | |
| 60 | - }, | |
| 61 | - { | |
| 62 | - id: "mcp", | |
| 63 | - title: "MCP", | |
| 64 | - tooltip: <McpSectionTooltip />, | |
| 65 | - icon: Squares2X2Icon, | |
| 66 | - }, | |
| 67 | - { | |
| 68 | - id: "error", | |
| 69 | - title: "Errors", | |
| 70 | - tooltip: <ErrorsSectionTooltip />, | |
| 71 | - icon: ExclamationTriangleIcon, | |
| 72 | - }, | |
| 73 | -]; | |
| 74 | - | |
| 75 | -function BlockSettingsToolbarIcon( | |
| 76 | - props: BlockSettingsToolbarIcon & { sectionId?: string }, | |
| 77 | -) { | |
| 78 | - const isErrorSection = props.sectionId === "error"; | |
| 79 | - | |
| 80 | - const id = `block-settings-toolbar-icon-${props.sectionId}`; | |
| 81 | - | |
| 82 | - const fontSize = useFontSize(-3); | |
| 83 | - return ( | |
| 84 | - <ToolTip delayShow={700} content={props.tooltip}> | |
| 85 | - <HoverItem px={0} onClick={props.onClick} data-testid={id}> | |
| 86 | - <div | |
| 87 | - role="button" | |
| 88 | - tabIndex={0} | |
| 89 | - onKeyDown={(e) => { | |
| 90 | - if (e.key === "Enter" || e.key === " ") { | |
| 91 | - e.preventDefault(); | |
| 92 | - props.onClick(); | |
| 93 | - } | |
| 94 | - }} | |
| 95 | - className={`${ | |
| 96 | - props.isSelected | |
| 97 | - ? isErrorSection | |
| 98 | - ? "bg-error" | |
| 99 | - : "bg-badge" | |
| 100 | - : undefined | |
| 101 | - } relative flex select-none items-center rounded-full px-[3px] py-0.5 transition-all duration-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/50 sm:px-1 ${props.className || ""}`} | |
| 102 | - > | |
| 103 | - <props.icon | |
| 104 | - className={`h-[13px] w-[13px] flex-shrink-0 hover:brightness-125 ${ | |
| 105 | - isErrorSection ? "text-error" : "" | |
| 106 | - }`} | |
| 107 | - style={{ | |
| 108 | - color: props.isSelected ? vscBadgeForeground : undefined, | |
| 109 | - }} | |
| 110 | - aria-hidden="true" | |
| 111 | - /> | |
| 112 | - <div | |
| 113 | - style={{ fontSize }} | |
| 114 | - className={`overflow-hidden transition-all duration-200 ${ | |
| 115 | - props.isSelected ? "ml-1 w-auto opacity-100" : "w-0 opacity-0" | |
| 116 | - }`} | |
| 117 | - > | |
| 118 | - <span | |
| 119 | - className="whitespace-nowrap" | |
| 120 | - style={{ color: vscBadgeForeground }} | |
| 121 | - > | |
| 122 | - {props.title} | |
| 123 | - </span> | |
| 124 | - </div> | |
| 125 | - </div> | |
| 126 | - </HoverItem> | |
| 127 | - </ToolTip> | |
| 128 | - ); | |
| 129 | -} | |
| 130 | - | |
| 131 | 15 | export function BlockSettingsTopToolbar() { |
| 132 | - const { | |
| 133 | - isToolbarExpanded, | |
| 134 | - toggleToolbar, | |
| 135 | - selectedSection, | |
| 136 | - setSelectedSection, | |
| 137 | - } = useLump(); | |
| 16 | + const navigate = useNavigate(); | |
| 138 | 17 | |
| 139 | 18 | const configError = useAppSelector((store) => store.config.configError); |
| 140 | 19 | const config = useAppSelector((state) => state.config.config); |
| @@ -172,71 +51,46 @@ | ||
| 172 | 51 | }; |
| 173 | 52 | }, [ideMessenger, isUsingFreeTrial]); |
| 174 | 53 | |
| 175 | - const handleEllipsisClick = () => { | |
| 176 | - if (isToolbarExpanded) { | |
| 177 | - setSelectedSection(null); | |
| 178 | - } | |
| 179 | - toggleToolbar(); | |
| 180 | - }; | |
| 181 | - | |
| 182 | - const visibleSections = sections.filter( | |
| 183 | - (section) => | |
| 184 | - section.id !== "error" || | |
| 185 | - (section.id === "error" && configError && configError?.length > 0), | |
| 186 | - ); | |
| 54 | + const shouldShowError = configError && configError?.length > 0; | |
| 187 | 55 | |
| 188 | 56 | return ( |
| 189 | - <div className="flex flex-1 items-center justify-between gap-2"> | |
| 190 | - <div className="flex flex-row"> | |
| 191 | - <div className="xs:flex text-description hidden items-center justify-center gap-0.5"> | |
| 192 | - <BlockSettingsToolbarIcon | |
| 193 | - className="-ml-1.5" | |
| 194 | - icon={isToolbarExpanded ? ChevronLeftIcon : EllipsisHorizontalIcon} | |
| 195 | - tooltip={isToolbarExpanded ? "Collapse Toolbar" : "Expand Toolbar"} | |
| 196 | - title="" | |
| 197 | - isSelected={false} | |
| 198 | - onClick={handleEllipsisClick} | |
| 199 | - /> | |
| 200 | - <div | |
| 201 | - className={`${isToolbarExpanded ? "w-min" : "w-0"} flex overflow-hidden transition-all duration-200`} | |
| 202 | - > | |
| 203 | - <div className="flex"> | |
| 204 | - {visibleSections.map((section) => ( | |
| 205 | - <BlockSettingsToolbarIcon | |
| 206 | - key={section.id} | |
| 207 | - sectionId={section.id} | |
| 208 | - icon={section.icon} | |
| 209 | - tooltip={section.tooltip} | |
| 210 | - title={section.title} | |
| 211 | - isSelected={selectedSection === section.id} | |
| 212 | - onClick={() => | |
| 213 | - setSelectedSection( | |
| 214 | - selectedSection === section.id ? null : section.id, | |
| 215 | - ) | |
| 216 | - } | |
| 217 | - /> | |
| 218 | - ))} | |
| 57 | + <div className="flex flex-1 items-center justify-between gap-1.5"> | |
| 58 | + <div> | |
| 59 | + {shouldShowError && ( | |
| 60 | + <ToolTip delayShow={700} content="View configuration errors"> | |
| 61 | + <div | |
| 62 | + role="button" | |
| 63 | + tabIndex={0} | |
| 64 | + onClick={() => navigate(CONFIG_ROUTES.AGENTS)} | |
| 65 | + onKeyDown={(e) => { | |
| 66 | + if (e.key === "Enter" || e.key === " ") { | |
| 67 | + e.preventDefault(); | |
| 68 | + navigate(CONFIG_ROUTES.AGENTS); | |
| 69 | + } | |
| 70 | + }} | |
| 71 | + data-testid="block-settings-toolbar-icon-error" | |
| 72 | + className="relative flex cursor-pointer select-none items-center rounded-full px-1.5 py-1 sm:px-1.5" | |
| 73 | + > | |
| 74 | + <ExclamationTriangleIcon | |
| 75 | + className="text-warning h-[13px] w-[13px] flex-shrink-0" | |
| 76 | + aria-hidden="true" | |
| 77 | + /> | |
| 219 | 78 | </div> |
| 220 | - </div> | |
| 221 | - </div> | |
| 222 | - </div> | |
| 223 | - <div className="flex gap-0.5"> | |
| 224 | - <ToolTip | |
| 225 | - place="top" | |
| 226 | - content={isUsingFreeTrial ? "View free trial usage" : "Select Agent"} | |
| 227 | - > | |
| 228 | - <HoverItem | |
| 229 | - data-tooltip-id="assistant-select-tooltip" | |
| 230 | - className="!m-0 !p-0" | |
| 231 | - > | |
| 232 | - {isUsingFreeTrial ? ( | |
| 233 | - <FreeTrialButton freeTrialStatus={freeTrialStatus} /> | |
| 234 | - ) : ( | |
| 235 | - <AssistantAndOrgListbox /> | |
| 236 | - )} | |
| 237 | - </HoverItem> | |
| 238 | - </ToolTip> | |
| 79 | + </ToolTip> | |
| 80 | + )} | |
| 239 | 81 | </div> |
| 82 | + <ToolTip | |
| 83 | + place="top" | |
| 84 | + content={isUsingFreeTrial ? "View free trial usage" : "Select Agent"} | |
| 85 | + > | |
| 86 | + <div> | |
| 87 | + {isUsingFreeTrial ? ( | |
| 88 | + <FreeTrialButton freeTrialStatus={freeTrialStatus} /> | |
| 89 | + ) : ( | |
| 90 | + <AssistantAndOrgListbox variant="lump" /> | |
| 91 | + )} | |
| 92 | + </div> | |
| 93 | + </ToolTip> | |
| 240 | 94 | </div> |
| 241 | 95 | ); |
| 242 | 96 | } |
modified gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx +91 −11
| @@ -1,13 +1,15 @@ | ||
| 1 | +import { BuiltInToolNames } from "core/tools/builtIn"; | |
| 1 | 2 | import { useContext, useEffect } from "react"; |
| 2 | -import { useSelector } from "react-redux"; | |
| 3 | 3 | import { IdeMessengerContext } from "../../../../context/IdeMessenger"; |
| 4 | 4 | import { useAppDispatch, useAppSelector } from "../../../../redux/hooks"; |
| 5 | 5 | import { |
| 6 | 6 | selectFirstPendingToolCall, |
| 7 | 7 | selectPendingToolCalls, |
| 8 | + selectToolCallsByStatus, | |
| 8 | 9 | } from "../../../../redux/selectors/selectToolCalls"; |
| 9 | 10 | import { cancelToolCall } from "../../../../redux/slices/sessionSlice"; |
| 10 | 11 | import { callToolById } from "../../../../redux/thunks/callToolById"; |
| 12 | +import { cancelStream } from "../../../../redux/thunks/cancelStream"; | |
| 11 | 13 | import { logToolUsage } from "../../../../redux/util"; |
| 12 | 14 | import { isJetBrains } from "../../../../util"; |
| 13 | 15 | import { BlockSettingsTopToolbar } from "./BlockSettingsTopToolbar"; |
| @@ -35,6 +37,14 @@ | ||
| 35 | 37 | return modifierKey && event.key === "Backspace"; |
| 36 | 38 | }; |
| 37 | 39 | |
| 40 | +// Check if a tool call is a terminal command | |
| 41 | +const isTerminalCommand = (toolCallState: any) => { | |
| 42 | + return ( | |
| 43 | + toolCallState?.toolCall?.function?.name === | |
| 44 | + BuiltInToolNames.RunTerminalCommand | |
| 45 | + ); | |
| 46 | +}; | |
| 47 | + | |
| 38 | 48 | export function LumpToolbar() { |
| 39 | 49 | const dispatch = useAppDispatch(); |
| 40 | 50 | const ideMessenger = useContext(IdeMessengerContext); |
| @@ -55,13 +65,67 @@ | ||
| 55 | 65 | ); |
| 56 | 66 | const isApplying = applyStates.some((state) => state.status === "streaming"); |
| 57 | 67 | |
| 68 | + // Get ALL running terminal commands | |
| 69 | + const runningToolCalls = useAppSelector((state) => | |
| 70 | + selectToolCallsByStatus(state, "calling"), | |
| 71 | + ); | |
| 72 | + const runningTerminalCalls = runningToolCalls.filter(isTerminalCommand); | |
| 73 | + const hasRunningTerminalCommand = runningTerminalCalls.length > 0; | |
| 74 | + | |
| 75 | + // Simple handler: stop ALL running terminal commands | |
| 76 | + const handleStopAllTerminalCommands = async () => { | |
| 77 | + if (runningTerminalCalls.length === 0) { | |
| 78 | + return; | |
| 79 | + } | |
| 80 | + | |
| 81 | + // Stop all terminal commands concurrently | |
| 82 | + const stopPromises = runningTerminalCalls.map(async (terminalCall) => { | |
| 83 | + try { | |
| 84 | + // Cancel the process on the backend | |
| 85 | + await ideMessenger.request("process/killTerminalProcess", { | |
| 86 | + toolCallId: terminalCall.toolCallId, | |
| 87 | + }); | |
| 88 | + | |
| 89 | + // Cancel the tool call in the UI | |
| 90 | + dispatch( | |
| 91 | + cancelToolCall({ | |
| 92 | + toolCallId: terminalCall.toolCallId, | |
| 93 | + }), | |
| 94 | + ); | |
| 95 | + | |
| 96 | + logToolUsage(terminalCall, false, true, ideMessenger); | |
| 97 | + } catch (error) { | |
| 98 | + console.error( | |
| 99 | + `Failed to cancel terminal command ${terminalCall.toolCallId}:`, | |
| 100 | + error, | |
| 101 | + ); | |
| 102 | + } | |
| 103 | + }); | |
| 104 | + | |
| 105 | + // Wait for all cancellations to complete | |
| 106 | + await Promise.all(stopPromises); | |
| 107 | + }; | |
| 108 | + | |
| 109 | + // Combined stop handler | |
| 110 | + const handleStopAction = async () => { | |
| 111 | + // Stop all terminal commands if any are running | |
| 112 | + if (hasRunningTerminalCommand) { | |
| 113 | + await handleStopAllTerminalCommands(); | |
| 114 | + } | |
| 115 | + | |
| 116 | + // Also stop regular streaming if it's happening | |
| 117 | + if (isStreaming) { | |
| 118 | + dispatch(cancelStream()); | |
| 119 | + } | |
| 120 | + }; | |
| 121 | + | |
| 58 | 122 | useEffect(() => { |
| 59 | - if (!firstPendingToolCall) { | |
| 123 | + if (!firstPendingToolCall && !hasRunningTerminalCommand) { | |
| 60 | 124 | return; |
| 61 | 125 | } |
| 62 | 126 | |
| 63 | 127 | const handleToolCallKeyboardShortcuts = (event: KeyboardEvent) => { |
| 64 | - if (isExecuteToolCallShortcut(event)) { | |
| 128 | + if (isExecuteToolCallShortcut(event) && firstPendingToolCall) { | |
| 65 | 129 | event.preventDefault(); |
| 66 | 130 | event.stopPropagation(); |
| 67 | 131 | |
| @@ -71,13 +135,19 @@ | ||
| 71 | 135 | } else if (isCancelToolCallShortcut(event, jetbrains)) { |
| 72 | 136 | event.preventDefault(); |
| 73 | 137 | event.stopPropagation(); |
| 74 | - void dispatch( | |
| 75 | - cancelToolCall({ | |
| 76 | - toolCallId: firstPendingToolCall.toolCallId, | |
| 77 | - }), | |
| 78 | - ); | |
| 79 | 138 | |
| 80 | - logToolUsage(firstPendingToolCall, false, true, ideMessenger); | |
| 139 | + if (hasRunningTerminalCommand) { | |
| 140 | + // Stop running terminal commands | |
| 141 | + void handleStopAction(); | |
| 142 | + } else if (firstPendingToolCall) { | |
| 143 | + // Cancel pending tool call | |
| 144 | + void dispatch( | |
| 145 | + cancelToolCall({ | |
| 146 | + toolCallId: firstPendingToolCall.toolCallId, | |
| 147 | + }), | |
| 148 | + ); | |
| 149 | + logToolUsage(firstPendingToolCall, false, true, ideMessenger); | |
| 150 | + } | |
| 81 | 151 | } |
| 82 | 152 | }; |
| 83 | 153 | |
| @@ -85,7 +155,7 @@ | ||
| 85 | 155 | return () => { |
| 86 | 156 | document.removeEventListener("keydown", handleToolCallKeyboardShortcuts); |
| 87 | 157 | }; |
| 88 | - }, [firstPendingToolCall]); | |
| 158 | + }, [firstPendingToolCall, hasRunningTerminalCommand, runningTerminalCalls]); | |
| 89 | 159 | |
| 90 | 160 | if (isApplying) { |
| 91 | 161 | return <IsApplyingToolbar />; |
| @@ -103,8 +173,18 @@ | ||
| 103 | 173 | return <TtsActiveToolbar />; |
| 104 | 174 | } |
| 105 | 175 | |
| 176 | + // Only show terminal streaming for actual terminal commands | |
| 177 | + if (hasRunningTerminalCommand) { | |
| 178 | + const count = runningTerminalCalls.length; | |
| 179 | + const stopText = `Stop Terminal${count > 1 ? ` (${count})` : ""}`; | |
| 180 | + return ( | |
| 181 | + <StreamingToolbar onStop={handleStopAction} displayText={stopText} /> | |
| 182 | + ); | |
| 183 | + } | |
| 184 | + | |
| 185 | + // Regular streaming (non-terminal) | |
| 106 | 186 | if (isStreaming) { |
| 107 | - return <StreamingToolbar />; | |
| 187 | + return <StreamingToolbar onStop={() => dispatch(cancelStream())} />; | |
| 108 | 188 | } |
| 109 | 189 | |
| 110 | 190 | if (pendingToolCalls.length > 0) { |
modified gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx +11 −6
| @@ -1,20 +1,25 @@ | ||
| 1 | -import { useAppDispatch } from "../../../../redux/hooks"; | |
| 2 | -import { cancelStream } from "../../../../redux/thunks/cancelStream"; | |
| 3 | 1 | import { getAltKeyLabel, getMetaKeyLabel, isJetBrains } from "../../../../util"; |
| 4 | 2 | import { GeneratingIndicator } from "./GeneratingIndicator"; |
| 5 | 3 | |
| 6 | -export function StreamingToolbar() { | |
| 4 | +interface StreamingToolbarProps { | |
| 5 | + onStop: () => void; | |
| 6 | + displayText?: string; | |
| 7 | +} | |
| 8 | + | |
| 9 | +export function StreamingToolbar({ | |
| 10 | + onStop, | |
| 11 | + displayText = "Stop", | |
| 12 | +}: StreamingToolbarProps) { | |
| 7 | 13 | const jetbrains = isJetBrains(); |
| 8 | - const dispatch = useAppDispatch(); | |
| 9 | 14 | |
| 10 | 15 | return ( |
| 11 | 16 | <div className="flex w-full items-center justify-between"> |
| 12 | 17 | <GeneratingIndicator /> |
| 13 | 18 | <div |
| 14 | - onClick={() => void dispatch(cancelStream())} | |
| 19 | + onClick={onStop} | |
| 15 | 20 | className="text-2xs cursor-pointer px-1.5 py-0.5 hover:brightness-125" |
| 16 | 21 | > |
| 17 | - <span className="text-description">Stop</span> | |
| 22 | + <span className="text-description">{displayText}</span> | |
| 18 | 23 | {/* JetBrains overrides cmd+backspace, so we have to use another shortcut */} |
| 19 | 24 | <span className="text-description-muted ml-1 opacity-75"> |
| 20 | 25 | {jetbrains ? getAltKeyLabel() : getMetaKeyLabel()}⌫ |
modified gui/src/components/mainInput/Lump/index.tsx +1 −15
| @@ -1,27 +1,13 @@ | ||
| 1 | -import { useLump } from "./LumpContext"; | |
| 2 | 1 | import { LumpToolbar } from "./LumpToolbar/LumpToolbar"; |
| 3 | -import { SelectedSection } from "./sections/SelectedSection"; | |
| 4 | 2 | |
| 5 | 3 | /** |
| 6 | - * Internal component that consumes the LumpContext | |
| 4 | + * Simplified toolbar component that only shows the toolbar without expansion | |
| 7 | 5 | */ |
| 8 | 6 | export function Lump() { |
| 9 | - const { isLumpVisible, selectedSection } = useLump(); | |
| 10 | - | |
| 11 | 7 | return ( |
| 12 | 8 | <div className="bg-input rounded-t-default border-command-border mx-1.5 border-l border-r border-t"> |
| 13 | 9 | <div className="xs:px-2 px-1 py-0.5"> |
| 14 | 10 | <LumpToolbar /> |
| 15 | - | |
| 16 | - <div | |
| 17 | - className={`no-scrollbar overflow-y-auto pr-0.5 transition-all duration-300 ease-in-out ${ | |
| 18 | - selectedSection | |
| 19 | - ? "my-1 max-h-[200px] opacity-100" | |
| 20 | - : "my-0 max-h-0 opacity-0" | |
| 21 | - } ${isLumpVisible ? "opacity-100" : "opacity-0"}`} | |
| 22 | - > | |
| 23 | - <SelectedSection /> | |
| 24 | - </div> | |
| 25 | 11 | </div> |
| 26 | 12 | </div> |
| 27 | 13 | ); |
deleted gui/src/components/mainInput/Lump/sections/ContextSection.tsx +0 −3
| @@ -1,3 +0,0 @@ | ||
| 1 | -export function ContextSection() { | |
| 2 | - return <div>Context content</div>; | |
| 3 | -} |
deleted gui/src/components/mainInput/Lump/sections/ExploreBlocksButton.tsx +0 −55
| @@ -1,55 +0,0 @@ | ||
| 1 | -import { BlockType } from "@continuedev/config-yaml"; | |
| 2 | -import { | |
| 3 | - ArrowTopRightOnSquareIcon, | |
| 4 | - PlusIcon, | |
| 5 | -} from "@heroicons/react/24/outline"; | |
| 6 | -import { useContext } from "react"; | |
| 7 | -import { GhostButton } from "../../.."; | |
| 8 | -import { useAuth } from "../../../../context/Auth"; | |
| 9 | -import { IdeMessengerContext } from "../../../../context/IdeMessenger"; | |
| 10 | -import { fontSize } from "../../../../util"; | |
| 11 | - | |
| 12 | -export function ExploreBlocksButton(props: { blockType: string }) { | |
| 13 | - const { selectedProfile } = useAuth(); | |
| 14 | - const ideMessenger = useContext(IdeMessengerContext); | |
| 15 | - | |
| 16 | - const isLocal = selectedProfile?.profileType === "local"; | |
| 17 | - | |
| 18 | - const Icon = isLocal ? PlusIcon : ArrowTopRightOnSquareIcon; | |
| 19 | - const text = `${isLocal ? "Add" : "Explore"} ${ | |
| 20 | - props.blockType === "mcpServers" | |
| 21 | - ? "MCP Servers" | |
| 22 | - : props.blockType.charAt(0).toUpperCase() + props.blockType.slice(1) | |
| 23 | - }`; | |
| 24 | - | |
| 25 | - const handleClick = () => { | |
| 26 | - if (isLocal) { | |
| 27 | - void ideMessenger.request("config/addLocalWorkspaceBlock", { | |
| 28 | - blockType: props.blockType as BlockType, | |
| 29 | - }); | |
| 30 | - } else { | |
| 31 | - void ideMessenger.request("controlPlane/openUrl", { | |
| 32 | - path: `new?type=block&blockType=${props.blockType}`, | |
| 33 | - orgSlug: undefined, | |
| 34 | - }); | |
| 35 | - } | |
| 36 | - }; | |
| 37 | - | |
| 38 | - return ( | |
| 39 | - <GhostButton | |
| 40 | - className="w-full cursor-pointer rounded px-2 py-0.5 text-center" | |
| 41 | - style={{ | |
| 42 | - fontSize: fontSize(-3), | |
| 43 | - }} | |
| 44 | - onClick={(e) => { | |
| 45 | - e.preventDefault(); | |
| 46 | - handleClick(); | |
| 47 | - }} | |
| 48 | - > | |
| 49 | - <div className="flex items-center justify-center gap-1"> | |
| 50 | - <Icon className="h-3 w-3 pr-1" /> | |
| 51 | - <span className="text-[11px]">{text}</span> | |
| 52 | - </div> | |
| 53 | - </GhostButton> | |
| 54 | - ); | |
| 55 | -} |
deleted gui/src/components/mainInput/Lump/sections/ModelsSection.tsx +0 −87
| @@ -1,87 +0,0 @@ | ||
| 1 | -import { ModelRole } from "@continuedev/config-yaml"; | |
| 2 | -import { ModelDescription } from "core"; | |
| 3 | -import { useAuth } from "../../../../context/Auth"; | |
| 4 | -import ModelRoleSelector from "../../../../pages/config/ModelRoleSelector"; | |
| 5 | -import { useAppDispatch, useAppSelector } from "../../../../redux/hooks"; | |
| 6 | -import { updateSelectedModelByRole } from "../../../../redux/thunks/updateSelectedModelByRole"; | |
| 7 | -import { isJetBrains } from "../../../../util"; | |
| 8 | - | |
| 9 | -export function ModelsSection() { | |
| 10 | - const { selectedProfile } = useAuth(); | |
| 11 | - const dispatch = useAppDispatch(); | |
| 12 | - | |
| 13 | - const config = useAppSelector((state) => state.config.config); | |
| 14 | - const jetbrains = isJetBrains(); | |
| 15 | - | |
| 16 | - function handleRoleUpdate(role: ModelRole, model: ModelDescription | null) { | |
| 17 | - if (!model) { | |
| 18 | - return; | |
| 19 | - } | |
| 20 | - | |
| 21 | - void dispatch( | |
| 22 | - updateSelectedModelByRole({ | |
| 23 | - role, | |
| 24 | - selectedProfile, | |
| 25 | - modelTitle: model.title, | |
| 26 | - }), | |
| 27 | - ); | |
| 28 | - } | |
| 29 | - | |
| 30 | - return ( | |
| 31 | - <div> | |
| 32 | - <div className="text-[${getFontSize() - 1}px] grid grid-cols-1 gap-x-2 gap-y-1 sm:grid-cols-[auto_1fr]"> | |
| 33 | - <ModelRoleSelector | |
| 34 | - displayName="Chat" | |
| 35 | - description="Used in the chat interface" | |
| 36 | - models={config.modelsByRole.chat} | |
| 37 | - selectedModel={config.selectedModelByRole.chat} | |
| 38 | - onSelect={(model) => handleRoleUpdate("chat", model)} | |
| 39 | - setupURL="https://docs.continue.dev/chat/model-setup" | |
| 40 | - /> | |
| 41 | - <ModelRoleSelector | |
| 42 | - displayName="Autocomplete" | |
| 43 | - description="Used to generate code completion suggestions" | |
| 44 | - models={config.modelsByRole.autocomplete} | |
| 45 | - selectedModel={config.selectedModelByRole.autocomplete} | |
| 46 | - onSelect={(model) => handleRoleUpdate("autocomplete", model)} | |
| 47 | - setupURL="https://docs.continue.dev/autocomplete/model-setup" | |
| 48 | - /> | |
| 49 | - {/* Jetbrains has a model selector inline */} | |
| 50 | - {!jetbrains && ( | |
| 51 | - <ModelRoleSelector | |
| 52 | - displayName="Edit" | |
| 53 | - description="Used for inline edits" | |
| 54 | - models={config.modelsByRole.edit} | |
| 55 | - selectedModel={config.selectedModelByRole.edit} | |
| 56 | - onSelect={(model) => handleRoleUpdate("edit", model)} | |
| 57 | - setupURL="https://docs.continue.dev/edit/model-setup" | |
| 58 | - /> | |
| 59 | - )} | |
| 60 | - <ModelRoleSelector | |
| 61 | - displayName="Apply" | |
| 62 | - description="Used to apply generated codeblocks to files" | |
| 63 | - models={config.modelsByRole.apply} | |
| 64 | - selectedModel={config.selectedModelByRole.apply} | |
| 65 | - onSelect={(model) => handleRoleUpdate("apply", model)} | |
| 66 | - setupURL="https://docs.continue.dev/customize/model-roles/apply" | |
| 67 | - /> | |
| 68 | - <ModelRoleSelector | |
| 69 | - displayName="Embed" | |
| 70 | - description="Used to generate and query embeddings for the @codebase and @docs context providers" | |
| 71 | - models={config.modelsByRole.embed} | |
| 72 | - selectedModel={config.selectedModelByRole.embed} | |
| 73 | - onSelect={(model) => handleRoleUpdate("embed", model)} | |
| 74 | - setupURL="https://docs.continue.dev/customize/model-roles/embeddings" | |
| 75 | - /> | |
| 76 | - <ModelRoleSelector | |
| 77 | - displayName="Rerank" | |
| 78 | - description="Used for reranking results from the @codebase and @docs context providers" | |
| 79 | - models={config.modelsByRole.rerank} | |
| 80 | - selectedModel={config.selectedModelByRole.rerank} | |
| 81 | - onSelect={(model) => handleRoleUpdate("rerank", model)} | |
| 82 | - setupURL="https://docs.continue.dev/customize/model-roles/reranking" | |
| 83 | - /> | |
| 84 | - </div> | |
| 85 | - </div> | |
| 86 | - ); | |
| 87 | -} |
deleted gui/src/components/mainInput/Lump/sections/PromptsSection.tsx +0 −180
| @@ -1,180 +0,0 @@ | ||
| 1 | -import { parseConfigYaml } from "@continuedev/config-yaml"; | |
| 2 | -import { | |
| 3 | - BookmarkIcon as BookmarkOutline, | |
| 4 | - PencilIcon, | |
| 5 | -} from "@heroicons/react/24/outline"; | |
| 6 | -import { BookmarkIcon as BookmarkSolid } from "@heroicons/react/24/solid"; | |
| 7 | -import { SlashCommandDescWithSource } from "core"; | |
| 8 | -import { useContext, useMemo } from "react"; | |
| 9 | -import { useAuth } from "../../../../context/Auth"; | |
| 10 | -import { IdeMessengerContext } from "../../../../context/IdeMessenger"; | |
| 11 | -import { useBookmarkedSlashCommands } from "../../../../hooks/useBookmarkedSlashCommands"; | |
| 12 | -import { useAppSelector } from "../../../../redux/hooks"; | |
| 13 | -import { fontSize } from "../../../../util"; | |
| 14 | -import { useMainEditor } from "../../TipTapEditor"; | |
| 15 | -import { useLump } from "../LumpContext"; | |
| 16 | -import { ExploreBlocksButton } from "./ExploreBlocksButton"; | |
| 17 | - | |
| 18 | -interface PromptCommandWithSlug extends SlashCommandDescWithSource { | |
| 19 | - slug?: string; | |
| 20 | -} | |
| 21 | - | |
| 22 | -interface PromptRowProps { | |
| 23 | - prompt: PromptCommandWithSlug; | |
| 24 | - isBookmarked: boolean; | |
| 25 | - setIsBookmarked: (isBookmarked: boolean) => void; | |
| 26 | - onEdit?: () => void; | |
| 27 | -} | |
| 28 | - | |
| 29 | -/** | |
| 30 | - * Displays a single prompt row with bookmark and edit controls | |
| 31 | - */ | |
| 32 | -function PromptRow({ | |
| 33 | - prompt, | |
| 34 | - isBookmarked, | |
| 35 | - setIsBookmarked, | |
| 36 | - onEdit, | |
| 37 | -}: PromptRowProps) { | |
| 38 | - const { mainEditor } = useMainEditor(); | |
| 39 | - const { hideLump } = useLump(); | |
| 40 | - | |
| 41 | - const handlePromptClick = (e: React.MouseEvent) => { | |
| 42 | - e.stopPropagation(); | |
| 43 | - mainEditor?.commands.insertPrompt({ | |
| 44 | - title: prompt.name, | |
| 45 | - description: prompt.description, | |
| 46 | - content: prompt.prompt, | |
| 47 | - }); | |
| 48 | - hideLump(); | |
| 49 | - }; | |
| 50 | - | |
| 51 | - const handleBookmarkClick = (e: React.MouseEvent) => { | |
| 52 | - e.stopPropagation(); | |
| 53 | - setIsBookmarked(!isBookmarked); | |
| 54 | - }; | |
| 55 | - | |
| 56 | - const handleEditClick = (e: React.MouseEvent) => { | |
| 57 | - e.stopPropagation(); | |
| 58 | - if (onEdit) { | |
| 59 | - onEdit(); | |
| 60 | - } | |
| 61 | - }; | |
| 62 | - | |
| 63 | - const canEdit = | |
| 64 | - prompt.promptFile && !prompt.promptFile.startsWith("builtin:"); | |
| 65 | - | |
| 66 | - return ( | |
| 67 | - <div | |
| 68 | - className="hover:bg-list-active hover:text-list-active-foreground flex items-center justify-between gap-3 rounded-md px-2 py-1 hover:cursor-pointer" | |
| 69 | - onClick={handlePromptClick} | |
| 70 | - style={{ | |
| 71 | - fontSize: fontSize(-3), | |
| 72 | - }} | |
| 73 | - > | |
| 74 | - <div className="flex min-w-0 flex-col"> | |
| 75 | - <span className="text-vscForeground shrink-0 font-medium"> | |
| 76 | - {prompt.name} | |
| 77 | - </span> | |
| 78 | - <span className="line-clamp-2 text-[11px] text-gray-400"> | |
| 79 | - {prompt.description} | |
| 80 | - </span> | |
| 81 | - </div> | |
| 82 | - <div className="flex items-center gap-2"> | |
| 83 | - <PencilIcon | |
| 84 | - className={`h-3 w-3 cursor-pointer text-gray-400 hover:brightness-125 ${!canEdit ? "pointer-events-none cursor-not-allowed opacity-50" : ""}`} | |
| 85 | - onClick={canEdit ? handleEditClick : undefined} | |
| 86 | - aria-disabled={!canEdit} | |
| 87 | - /> | |
| 88 | - <div | |
| 89 | - onClick={handleBookmarkClick} | |
| 90 | - className="cursor-pointer pt-0.5 text-gray-400 hover:brightness-125" | |
| 91 | - > | |
| 92 | - {isBookmarked ? ( | |
| 93 | - <BookmarkSolid className="h-3 w-3" /> | |
| 94 | - ) : ( | |
| 95 | - <BookmarkOutline className="h-3 w-3" /> | |
| 96 | - )} | |
| 97 | - </div> | |
| 98 | - </div> | |
| 99 | - </div> | |
| 100 | - ); | |
| 101 | -} | |
| 102 | - | |
| 103 | -/** | |
| 104 | - * Section that displays all available prompts with bookmarking functionality | |
| 105 | - */ | |
| 106 | -export function PromptsSection() { | |
| 107 | - const { selectedProfile } = useAuth(); | |
| 108 | - const { isCommandBookmarked, toggleBookmark } = useBookmarkedSlashCommands(); | |
| 109 | - const ideMessenger = useContext(IdeMessengerContext); | |
| 110 | - | |
| 111 | - const slashCommands = useAppSelector( | |
| 112 | - (state) => state.config.config.slashCommands ?? [], | |
| 113 | - ); | |
| 114 | - | |
| 115 | - const handleEdit = (prompt: PromptCommandWithSlug) => { | |
| 116 | - if (prompt.promptFile) { | |
| 117 | - ideMessenger.post("openFile", { | |
| 118 | - path: prompt.promptFile, | |
| 119 | - }); | |
| 120 | - } else if (prompt.slug) { | |
| 121 | - void ideMessenger.request("controlPlane/openUrl", { | |
| 122 | - path: `${prompt.slug}/new-version`, | |
| 123 | - orgSlug: undefined, | |
| 124 | - }); | |
| 125 | - } else { | |
| 126 | - ideMessenger.post("config/openProfile", { | |
| 127 | - profileId: undefined, | |
| 128 | - element: { sourceFile: (prompt as any).sourceFile }, | |
| 129 | - }); | |
| 130 | - } | |
| 131 | - }; | |
| 132 | - | |
| 133 | - const sortedCommands = useMemo(() => { | |
| 134 | - const promptsWithSlug: PromptCommandWithSlug[] = | |
| 135 | - structuredClone(slashCommands); | |
| 136 | - // get the slugs from rawYaml | |
| 137 | - if (selectedProfile?.rawYaml) { | |
| 138 | - const parsed = parseConfigYaml(selectedProfile.rawYaml); | |
| 139 | - const parsedPrompts = parsed.prompts ?? []; | |
| 140 | - | |
| 141 | - let index = 0; | |
| 142 | - for (const commandWithSlug of promptsWithSlug) { | |
| 143 | - // skip for local prompt files | |
| 144 | - if (commandWithSlug.promptFile) continue; | |
| 145 | - | |
| 146 | - const yamlPrompt = parsedPrompts[index]; | |
| 147 | - if (yamlPrompt) { | |
| 148 | - if ("uses" in yamlPrompt) { | |
| 149 | - commandWithSlug.slug = yamlPrompt.uses; | |
| 150 | - } else { | |
| 151 | - commandWithSlug.slug = `${selectedProfile?.fullSlug.ownerSlug}/${selectedProfile?.fullSlug.packageSlug}`; | |
| 152 | - } | |
| 153 | - } | |
| 154 | - index = index + 1; | |
| 155 | - } | |
| 156 | - } | |
| 157 | - return promptsWithSlug.sort((a, b) => { | |
| 158 | - const aBookmarked = isCommandBookmarked(a.name); | |
| 159 | - const bBookmarked = isCommandBookmarked(b.name); | |
| 160 | - if (aBookmarked && !bBookmarked) return -1; | |
| 161 | - if (!aBookmarked && bBookmarked) return 1; | |
| 162 | - return 0; | |
| 163 | - }); | |
| 164 | - }, [slashCommands, isCommandBookmarked, selectedProfile]); | |
| 165 | - | |
| 166 | - return ( | |
| 167 | - <div className="flex flex-col"> | |
| 168 | - {sortedCommands.map((prompt) => ( | |
| 169 | - <PromptRow | |
| 170 | - key={prompt.name} | |
| 171 | - prompt={prompt} | |
| 172 | - isBookmarked={isCommandBookmarked(prompt.name)} | |
| 173 | - setIsBookmarked={() => toggleBookmark(prompt)} | |
| 174 | - onEdit={() => handleEdit(prompt)} | |
| 175 | - /> | |
| 176 | - ))} | |
| 177 | - <ExploreBlocksButton blockType="prompts" /> | |
| 178 | - </div> | |
| 179 | - ); | |
| 180 | -} |
deleted gui/src/components/mainInput/Lump/sections/RulesSection.tsx +0 −273
| @@ -1,273 +0,0 @@ | ||
| 1 | -import { parseConfigYaml } from "@continuedev/config-yaml"; | |
| 2 | -import { | |
| 3 | - ArrowsPointingOutIcon, | |
| 4 | - EyeIcon, | |
| 5 | - PencilIcon, | |
| 6 | -} from "@heroicons/react/24/outline"; | |
| 7 | -import { RuleWithSource } from "core"; | |
| 8 | -import { | |
| 9 | - DEFAULT_AGENT_SYSTEM_MESSAGE, | |
| 10 | - DEFAULT_CHAT_SYSTEM_MESSAGE, | |
| 11 | - DEFAULT_SYSTEM_MESSAGES_URL, | |
| 12 | -} from "core/llm/defaultSystemMessages"; | |
| 13 | -import { useContext, useMemo } from "react"; | |
| 14 | -import { useAuth } from "../../../../context/Auth"; | |
| 15 | -import { IdeMessengerContext } from "../../../../context/IdeMessenger"; | |
| 16 | -import { useAppDispatch, useAppSelector } from "../../../../redux/hooks"; | |
| 17 | -import { | |
| 18 | - DEFAULT_RULE_SETTING, | |
| 19 | - setDialogMessage, | |
| 20 | - setShowDialog, | |
| 21 | - toggleRuleSetting, | |
| 22 | -} from "../../../../redux/slices/uiSlice"; | |
| 23 | -import HeaderButtonWithToolTip from "../../../gui/HeaderButtonWithToolTip"; | |
| 24 | -import Switch from "../../../gui/Switch"; | |
| 25 | -import { useFontSize } from "../../../ui/font"; | |
| 26 | -import { ExploreBlocksButton } from "./ExploreBlocksButton"; | |
| 27 | - | |
| 28 | -interface RuleCardProps { | |
| 29 | - rule: RuleWithSource; | |
| 30 | -} | |
| 31 | - | |
| 32 | -const RuleCard: React.FC<RuleCardProps> = ({ rule }) => { | |
| 33 | - const dispatch = useAppDispatch(); | |
| 34 | - const ideMessenger = useContext(IdeMessengerContext); | |
| 35 | - const mode = useAppSelector((store) => store.session.mode); | |
| 36 | - const policy = useAppSelector((state) => | |
| 37 | - rule.name | |
| 38 | - ? state.ui.ruleSettings[rule.name] || DEFAULT_RULE_SETTING | |
| 39 | - : undefined, | |
| 40 | - ); | |
| 41 | - | |
| 42 | - const isDisabled = policy === "off"; | |
| 43 | - | |
| 44 | - const handleOpen = async () => { | |
| 45 | - if (rule.slug) { | |
| 46 | - void ideMessenger.request("controlPlane/openUrl", { | |
| 47 | - path: `${rule.slug}/new-version`, | |
| 48 | - orgSlug: undefined, | |
| 49 | - }); | |
| 50 | - } else if (rule.ruleFile) { | |
| 51 | - ideMessenger.post("openFile", { | |
| 52 | - path: rule.ruleFile, | |
| 53 | - }); | |
| 54 | - } else if ( | |
| 55 | - rule.source === "default-chat" || | |
| 56 | - rule.source === "default-plan" || | |
| 57 | - rule.source === "default-agent" | |
| 58 | - ) { | |
| 59 | - ideMessenger.post("openUrl", DEFAULT_SYSTEM_MESSAGES_URL); | |
| 60 | - } else { | |
| 61 | - ideMessenger.post("config/openProfile", { | |
| 62 | - profileId: undefined, | |
| 63 | - element: { sourceFile: (rule as any).sourceFile }, | |
| 64 | - }); | |
| 65 | - } | |
| 66 | - }; | |
| 67 | - | |
| 68 | - const handleTogglePolicy = () => { | |
| 69 | - if (rule.name) { | |
| 70 | - dispatch(toggleRuleSetting(rule.name)); | |
| 71 | - } | |
| 72 | - }; | |
| 73 | - | |
| 74 | - const title = useMemo(() => { | |
| 75 | - if (rule.name) { | |
| 76 | - return rule.name; | |
| 77 | - } else { | |
| 78 | - if (rule.source === ".continuerules") { | |
| 79 | - return "Project rules"; | |
| 80 | - } else if (rule.source === "default-chat") { | |
| 81 | - return "Default chat system message"; | |
| 82 | - } else if (rule.source === "default-agent") { | |
| 83 | - return "Default agent system message"; | |
| 84 | - } else if (rule.source === "json-systemMessage") { | |
| 85 | - return "JSON systemMessage)"; | |
| 86 | - } else if (rule.source === "model-options-agent") { | |
| 87 | - return "Base System Agent Message"; | |
| 88 | - } else if (rule.source === "model-options-plan") { | |
| 89 | - return "Base System Plan Message"; | |
| 90 | - } else if (rule.source === "model-options-chat") { | |
| 91 | - return "Base System Chat Message"; | |
| 92 | - } else { | |
| 93 | - return "Agent rule"; | |
| 94 | - } | |
| 95 | - } | |
| 96 | - }, [rule]); | |
| 97 | - | |
| 98 | - function onClickExpand() { | |
| 99 | - dispatch(setShowDialog(true)); | |
| 100 | - dispatch( | |
| 101 | - setDialogMessage( | |
| 102 | - <div className="max-h-4/5 p-4"> | |
| 103 | - <h3>{title}</h3> | |
| 104 | - <pre className="max-w-full overflow-scroll">{rule.rule}</pre> | |
| 105 | - </div>, | |
| 106 | - ), | |
| 107 | - ); | |
| 108 | - } | |
| 109 | - | |
| 110 | - const smallFont = useFontSize(-2); | |
| 111 | - const tinyFont = useFontSize(-3); | |
| 112 | - return ( | |
| 113 | - <div | |
| 114 | - className={`border-border flex flex-col rounded-sm px-2 py-1.5 transition-colors ${isDisabled ? "opacity-50" : ""}`} | |
| 115 | - > | |
| 116 | - <div className="flex flex-col"> | |
| 117 | - <div className="flex flex-row justify-between gap-1"> | |
| 118 | - <span | |
| 119 | - className={`line-clamp-2 ${isDisabled ? "text-gray-400" : "text-vsc-foreground"}`} | |
| 120 | - style={{ | |
| 121 | - fontSize: smallFont, | |
| 122 | - }} | |
| 123 | - > | |
| 124 | - {title} | |
| 125 | - </span> | |
| 126 | - <div className="flex flex-row items-center gap-2"> | |
| 127 | - {rule.name && policy && ( | |
| 128 | - <div className="flex cursor-pointer flex-row items-center justify-end gap-1 px-2 py-0.5"> | |
| 129 | - <Switch | |
| 130 | - isToggled={policy === "on"} | |
| 131 | - onToggle={() => handleTogglePolicy()} | |
| 132 | - size={10} | |
| 133 | - text="" | |
| 134 | - /> | |
| 135 | - </div> | |
| 136 | - )} | |
| 137 | - <div className="flex flex-row items-start gap-1"> | |
| 138 | - <HeaderButtonWithToolTip onClick={onClickExpand} text="Expand"> | |
| 139 | - <ArrowsPointingOutIcon className="h-3 w-3 text-gray-400" /> | |
| 140 | - </HeaderButtonWithToolTip>{" "} | |
| 141 | - {rule.source === "default-chat" || | |
| 142 | - rule.source === "default-agent" ? ( | |
| 143 | - <HeaderButtonWithToolTip onClick={handleOpen} text="View"> | |
| 144 | - <EyeIcon className="h-3 w-3 text-gray-400" /> | |
| 145 | - </HeaderButtonWithToolTip> | |
| 146 | - ) : ( | |
| 147 | - <HeaderButtonWithToolTip onClick={handleOpen} text="Edit"> | |
| 148 | - <PencilIcon className="h-3 w-3 text-gray-400" /> | |
| 149 | - </HeaderButtonWithToolTip> | |
| 150 | - )} | |
| 151 | - </div> | |
| 152 | - </div> | |
| 153 | - </div> | |
| 154 | - | |
| 155 | - <span | |
| 156 | - style={{ | |
| 157 | - fontSize: tinyFont, | |
| 158 | - }} | |
| 159 | - className={`mt-1 line-clamp-3 ${isDisabled ? "text-gray-500" : "text-gray-400"}`} | |
| 160 | - > | |
| 161 | - {rule.rule} | |
| 162 | - </span> | |
| 163 | - {rule.globs ? ( | |
| 164 | - <div | |
| 165 | - style={{ | |
| 166 | - fontSize: tinyFont, | |
| 167 | - }} | |
| 168 | - className="mt-1.5 flex flex-col gap-1" | |
| 169 | - > | |
| 170 | - <span className="italic">Applies to files</span> | |
| 171 | - <code | |
| 172 | - className={`line-clamp-1 px-1 py-0.5 ${isDisabled ? "text-gray-500" : "text-gray-400"}`} | |
| 173 | - > | |
| 174 | - {rule.globs} | |
| 175 | - </code> | |
| 176 | - </div> | |
| 177 | - ) : null} | |
| 178 | - </div> | |
| 179 | - </div> | |
| 180 | - ); | |
| 181 | -}; | |
| 182 | - | |
| 183 | -export function RulesSection() { | |
| 184 | - const { selectedProfile } = useAuth(); | |
| 185 | - const config = useAppSelector((store) => store.config.config); | |
| 186 | - const mode = useAppSelector((store) => store.session.mode); | |
| 187 | - const sortedRules: RuleWithSource[] = useMemo(() => { | |
| 188 | - const rules = [...config.rules.map((rule) => ({ ...rule }))]; | |
| 189 | - | |
| 190 | - // Use profile rawYaml to infer slugs | |
| 191 | - if (selectedProfile?.rawYaml) { | |
| 192 | - try { | |
| 193 | - const parsed = parseConfigYaml(selectedProfile.rawYaml); | |
| 194 | - const parsedRules = parsed?.rules ?? []; | |
| 195 | - let index = 0; | |
| 196 | - for (const rule of rules) { | |
| 197 | - if (rule.source === "rules-block") { | |
| 198 | - let slug: string | undefined = undefined; | |
| 199 | - const yamlRule = parsedRules[index]; | |
| 200 | - if (yamlRule) { | |
| 201 | - if (typeof yamlRule !== "string" && "uses" in yamlRule) { | |
| 202 | - slug = yamlRule.uses; | |
| 203 | - } else { | |
| 204 | - slug = `${selectedProfile?.fullSlug.ownerSlug}/${selectedProfile?.fullSlug.packageSlug}`; | |
| 205 | - } | |
| 206 | - } | |
| 207 | - if (slug) { | |
| 208 | - rule.slug = slug; | |
| 209 | - } | |
| 210 | - | |
| 211 | - index++; | |
| 212 | - } | |
| 213 | - } | |
| 214 | - } catch (e) { | |
| 215 | - console.error( | |
| 216 | - "Rules notch section: failed to parse selected profile", | |
| 217 | - e, | |
| 218 | - ); | |
| 219 | - } | |
| 220 | - } | |
| 221 | - | |
| 222 | - if (mode === "chat") { | |
| 223 | - if (config.selectedModelByRole.chat?.baseChatSystemMessage) { | |
| 224 | - rules.unshift({ | |
| 225 | - rule: config.selectedModelByRole.chat?.baseChatSystemMessage, | |
| 226 | - source: "model-options-chat", | |
| 227 | - }); | |
| 228 | - } else { | |
| 229 | - rules.unshift({ | |
| 230 | - rule: DEFAULT_CHAT_SYSTEM_MESSAGE, | |
| 231 | - source: "default-chat", | |
| 232 | - }); | |
| 233 | - } | |
| 234 | - } else if (mode === "agent") { | |
| 235 | - // agent | |
| 236 | - if (config.selectedModelByRole.chat?.baseAgentSystemMessage) { | |
| 237 | - rules.unshift({ | |
| 238 | - rule: config.selectedModelByRole.chat?.baseAgentSystemMessage, | |
| 239 | - source: "model-options-agent", | |
| 240 | - }); | |
| 241 | - } else { | |
| 242 | - rules.unshift({ | |
| 243 | - rule: DEFAULT_AGENT_SYSTEM_MESSAGE, | |
| 244 | - source: "default-agent", | |
| 245 | - }); | |
| 246 | - } | |
| 247 | - } else { | |
| 248 | - // plan | |
| 249 | - if (config.selectedModelByRole.chat?.basePlanSystemMessage) { | |
| 250 | - rules.unshift({ | |
| 251 | - rule: config.selectedModelByRole.chat?.basePlanSystemMessage, | |
| 252 | - source: "model-options-plan", | |
| 253 | - }); | |
| 254 | - } else { | |
| 255 | - rules.unshift({ | |
| 256 | - rule: DEFAULT_AGENT_SYSTEM_MESSAGE, | |
| 257 | - source: "default-agent", | |
| 258 | - }); | |
| 259 | - } | |
| 260 | - } | |
| 261 | - | |
| 262 | - return rules; | |
| 263 | - }, [config, selectedProfile, mode]); | |
| 264 | - | |
| 265 | - return ( | |
| 266 | - <div className="flex flex-col gap-3"> | |
| 267 | - {sortedRules.map((rule, index) => ( | |
| 268 | - <RuleCard key={index} rule={rule} /> | |
| 269 | - ))} | |
| 270 | - <ExploreBlocksButton blockType="rules" /> | |
| 271 | - </div> | |
| 272 | - ); | |
| 273 | -} |
deleted gui/src/components/mainInput/Lump/sections/SelectedSection.tsx +0 −34
| @@ -1,34 +0,0 @@ | ||
| 1 | -import { useLump } from "../LumpContext"; | |
| 2 | -import { ContextSection } from "./ContextSection"; | |
| 3 | -import { ErrorSection } from "./errors/ErrorSection"; | |
| 4 | -import MCPSection from "./mcp/MCPSection"; | |
| 5 | -import { ModelsSection } from "./ModelsSection"; | |
| 6 | -import { PromptsSection } from "./PromptsSection"; | |
| 7 | -import { RulesSection } from "./RulesSection"; | |
| 8 | -import { ToolPoliciesSection } from "./tool-policies/ToolPoliciesSection"; | |
| 9 | - | |
| 10 | -/** | |
| 11 | - * Renders the appropriate section based on the selected section in the Lump context | |
| 12 | - */ | |
| 13 | -export function SelectedSection() { | |
| 14 | - const { displayedSection } = useLump(); | |
| 15 | - | |
| 16 | - switch (displayedSection) { | |
| 17 | - case "models": | |
| 18 | - return <ModelsSection />; | |
| 19 | - case "rules": | |
| 20 | - return <RulesSection />; | |
| 21 | - case "prompts": | |
| 22 | - return <PromptsSection />; | |
| 23 | - case "context": | |
| 24 | - return <ContextSection />; | |
| 25 | - case "tools": | |
| 26 | - return <ToolPoliciesSection />; | |
| 27 | - case "mcp": | |
| 28 | - return <MCPSection />; | |
| 29 | - case "error": | |
| 30 | - return <ErrorSection />; | |
| 31 | - default: | |
| 32 | - return null; | |
| 33 | - } | |
| 34 | -} |
deleted gui/src/components/mainInput/Lump/sections/docs/DocsDetailsDialog.tsx +0 −161
| @@ -1,161 +0,0 @@ | ||
| 1 | -import { DocsIndexingDetails } from "core"; | |
| 2 | -import { useCallback, useContext, useEffect, useState } from "react"; | |
| 3 | -import { useDispatch } from "react-redux"; | |
| 4 | -import { Tooltip } from "react-tooltip"; | |
| 5 | -import { SecondaryButton } from "../../../.."; | |
| 6 | -import { IdeMessengerContext } from "../../../../../context/IdeMessenger"; | |
| 7 | -import { | |
| 8 | - setDialogMessage, | |
| 9 | - setShowDialog, | |
| 10 | -} from "../../../../../redux/slices/uiSlice"; | |
| 11 | - | |
| 12 | -interface DocsDetailsDialogProps { | |
| 13 | - startUrl: string; | |
| 14 | -} | |
| 15 | - | |
| 16 | -function DocsDetailsDialog({ startUrl }: DocsDetailsDialogProps) { | |
| 17 | - const dispatch = useDispatch(); | |
| 18 | - | |
| 19 | - const ideMessenger = useContext(IdeMessengerContext); | |
| 20 | - | |
| 21 | - const closeDialog = () => { | |
| 22 | - dispatch(setShowDialog(false)); | |
| 23 | - dispatch(setDialogMessage(undefined)); | |
| 24 | - }; | |
| 25 | - | |
| 26 | - const [isLoading, setIsLoading] = useState(false); | |
| 27 | - const [isError, setIsError] = useState(false); | |
| 28 | - const [data, setData] = useState<DocsIndexingDetails | undefined>(undefined); | |
| 29 | - | |
| 30 | - const fetchData = useCallback(async () => { | |
| 31 | - setIsLoading(true); | |
| 32 | - setIsError(false); | |
| 33 | - | |
| 34 | - try { | |
| 35 | - const response = await ideMessenger.request("docs/getDetails", { | |
| 36 | - startUrl, | |
| 37 | - }); | |
| 38 | - if (response.status === "error") { | |
| 39 | - throw new Error(response.error); | |
| 40 | - } | |
| 41 | - setData(response.content); | |
| 42 | - } catch (error) { | |
| 43 | - setIsError(true); | |
| 44 | - } finally { | |
| 45 | - setIsLoading(false); | |
| 46 | - } | |
| 47 | - }, []); | |
| 48 | - | |
| 49 | - useEffect(() => { | |
| 50 | - void fetchData(); | |
| 51 | - }, []); | |
| 52 | - | |
| 53 | - let comp = <div>Loading...</div>; | |
| 54 | - if (!isLoading) { | |
| 55 | - if (isError) { | |
| 56 | - comp = ( | |
| 57 | - <div> | |
| 58 | - <div>Error fetching docs details</div> | |
| 59 | - <SecondaryButton onClick={fetchData}>Try again</SecondaryButton> | |
| 60 | - </div> | |
| 61 | - ); | |
| 62 | - } | |
| 63 | - if (data) { | |
| 64 | - comp = ( | |
| 65 | - <div className="flex flex-col gap-0.5"> | |
| 66 | - <p className="m-0 mt-2 p-0 text-stone-500">{`Title: ${data.config.title}`}</p> | |
| 67 | - {!data.chunks?.length ? ( | |
| 68 | - <div>No article chunks</div> | |
| 69 | - ) : ( | |
| 70 | - <div className="relative mt-2 h-[300px] overflow-auto"> | |
| 71 | - <table className="w-full border-collapse"> | |
| 72 | - <thead className="bg-vsc-background sticky top-0 text-left"> | |
| 73 | - <tr> | |
| 74 | - <th className="py-1">Filepath</th> | |
| 75 | - <th>Content</th> | |
| 76 | - </tr> | |
| 77 | - </thead> | |
| 78 | - <tbody className="h-20 overflow-y-scroll"> | |
| 79 | - {data.chunks.map((chunk, i) => { | |
| 80 | - const contentToolTipId = `docs-content-peek-${i}`; | |
| 81 | - const urlToolTipId = `docs-url-peek-${i}`; | |
| 82 | - return ( | |
| 83 | - <> | |
| 84 | - <tr key={i} className=""> | |
| 85 | - <td | |
| 86 | - className="cursor-pointer px-1" | |
| 87 | - data-tooltip-id={urlToolTipId} | |
| 88 | - data-tooltip-delay-show={500} | |
| 89 | - > | |
| 90 | - <span className="truncate-start max-w-[200px]"> | |
| 91 | - {chunk.filepath} | |
| 92 | - </span> | |
| 93 | - </td> | |
| 94 | - <td | |
| 95 | - className="cursor-pointer px-1" | |
| 96 | - data-tooltip-id={contentToolTipId} | |
| 97 | - data-tooltip-delay-show={500} | |
| 98 | - > | |
| 99 | - <span className="line-clamp-1"> | |
| 100 | - {chunk.content} | |
| 101 | - </span> | |
| 102 | - </td> | |
| 103 | - </tr> | |
| 104 | - </> | |
| 105 | - ); | |
| 106 | - })} | |
| 107 | - </tbody> | |
| 108 | - </table> | |
| 109 | - {/* Rending tooltips here because div can't be child of tbody apparently */} | |
| 110 | - {data.chunks.map((chunk, i) => { | |
| 111 | - const contentToolTipId = `docs-content-peek-${i}`; | |
| 112 | - const urlToolTipId = `docs-url-peek-${i}`; | |
| 113 | - return ( | |
| 114 | - <> | |
| 115 | - <Tooltip | |
| 116 | - key={urlToolTipId} | |
| 117 | - id={urlToolTipId} | |
| 118 | - place="top" | |
| 119 | - className="max-w-full" | |
| 120 | - > | |
| 121 | - {chunk.filepath} | |
| 122 | - </Tooltip> | |
| 123 | - <Tooltip | |
| 124 | - key={contentToolTipId} | |
| 125 | - id={contentToolTipId} | |
| 126 | - place="top" | |
| 127 | - className="max-h-[300px] max-w-[170px] overflow-y-auto" | |
| 128 | - > | |
| 129 | - {chunk.content} | |
| 130 | - </Tooltip> | |
| 131 | - </> | |
| 132 | - ); | |
| 133 | - })} | |
| 134 | - </div> | |
| 135 | - )} | |
| 136 | - </div> | |
| 137 | - ); | |
| 138 | - } | |
| 139 | - } | |
| 140 | - | |
| 141 | - return ( | |
| 142 | - <div className="px-2 py-4 sm:px-4"> | |
| 143 | - <h3>Docs index</h3> | |
| 144 | - <p | |
| 145 | - className="text-lightgray m-0 mt-1 cursor-pointer p-0 hover:underline" | |
| 146 | - onClick={(e) => { | |
| 147 | - e.stopPropagation(); | |
| 148 | - ideMessenger.post("openUrl", startUrl); | |
| 149 | - }} | |
| 150 | - > | |
| 151 | - {startUrl} | |
| 152 | - </p> | |
| 153 | - {comp} | |
| 154 | - <div className="flex flex-row justify-end"> | |
| 155 | - <SecondaryButton onClick={closeDialog}>Close</SecondaryButton> | |
| 156 | - </div> | |
| 157 | - </div> | |
| 158 | - ); | |
| 159 | -} | |
| 160 | - | |
| 161 | -export default DocsDetailsDialog; |
deleted gui/src/components/mainInput/Lump/sections/docs/DocsIndexingPeeks.tsx +0 −70
| @@ -1,70 +0,0 @@ | ||
| 1 | -import { IndexingStatus } from "core"; | |
| 2 | -import { useMemo } from "react"; | |
| 3 | -import { useDispatch } from "react-redux"; | |
| 4 | -import { useNavigate } from "react-router-dom"; | |
| 5 | -import { | |
| 6 | - setDialogMessage, | |
| 7 | - setShowDialog, | |
| 8 | -} from "../../../../../redux/slices/uiSlice"; | |
| 9 | - | |
| 10 | -export interface DocsIndexingPeekProps { | |
| 11 | - status: IndexingStatus; | |
| 12 | -} | |
| 13 | - | |
| 14 | -function DocsIndexingPeek({ status }: DocsIndexingPeekProps) { | |
| 15 | - const navigate = useNavigate(); | |
| 16 | - const dispatch = useDispatch(); | |
| 17 | - | |
| 18 | - const progressPercentage = useMemo(() => { | |
| 19 | - return Math.min(100, Math.max(0, status.progress * 100)); | |
| 20 | - }, [status.progress]); | |
| 21 | - | |
| 22 | - return ( | |
| 23 | - <div | |
| 24 | - className="text-lightgray flex cursor-pointer flex-row items-center gap-2 rounded-md px-1 hover:bg-gray-700/10" | |
| 25 | - onClick={() => { | |
| 26 | - // navigate("/more"); TODO | |
| 27 | - dispatch(setShowDialog(false)); | |
| 28 | - dispatch(setDialogMessage(undefined)); | |
| 29 | - }} | |
| 30 | - > | |
| 31 | - <p className="text-lightgray m-0 p-0 group-hover:underline"> | |
| 32 | - {status.title} | |
| 33 | - </p> | |
| 34 | - <div className="my-2 h-1.5 flex-1 rounded-md border border-solid border-gray-400"> | |
| 35 | - <div | |
| 36 | - className={`h-full rounded-lg bg-stone-500 transition-all duration-200 ease-in-out`} | |
| 37 | - style={{ | |
| 38 | - width: `${progressPercentage}%`, | |
| 39 | - }} | |
| 40 | - /> | |
| 41 | - </div> | |
| 42 | - <div className="xs:flex text-lightgray hidden flex-row items-center gap-1"> | |
| 43 | - <span className="text-xs no-underline"> | |
| 44 | - {progressPercentage.toFixed(0)}% | |
| 45 | - </span> | |
| 46 | - {/* <ArrowPathIcon | |
| 47 | - className={`animate-spin-slow inline-block h-4 w-4 text-lightgray`} | |
| 48 | - ></ArrowPathIcon> */} | |
| 49 | - </div> | |
| 50 | - </div> | |
| 51 | - ); | |
| 52 | -} | |
| 53 | - | |
| 54 | -interface DocsIndexingPeeksProps { | |
| 55 | - statuses: IndexingStatus[]; | |
| 56 | -} | |
| 57 | - | |
| 58 | -function DocsIndexingPeekList({ statuses }: DocsIndexingPeeksProps) { | |
| 59 | - return ( | |
| 60 | - <div className="border-vsc-input-border mt-2 flex flex-col border-0 border-t border-solid pt-2"> | |
| 61 | - <div className="max-h-[100px] overflow-y-auto pr-2"> | |
| 62 | - {statuses.map((status) => { | |
| 63 | - return <DocsIndexingPeek key={status.id} status={status} />; | |
| 64 | - })} | |
| 65 | - </div> | |
| 66 | - </div> | |
| 67 | - ); | |
| 68 | -} | |
| 69 | - | |
| 70 | -export default DocsIndexingPeekList; |
deleted gui/src/components/mainInput/Lump/sections/docs/DocsIndexingStatus.test.tsx +0 −377
| @@ -1,377 +0,0 @@ | ||
| 1 | -import { | |
| 2 | - act, | |
| 3 | - fireEvent, | |
| 4 | - render, | |
| 5 | - screen, | |
| 6 | - waitFor, | |
| 7 | -} from "@testing-library/react"; | |
| 8 | -import { SiteIndexingConfig } from "core"; | |
| 9 | -import { Provider } from "react-redux"; | |
| 10 | -import { beforeEach, describe, expect, it, vi } from "vitest"; | |
| 11 | -import { AuthProvider } from "../../../../../context/Auth"; | |
| 12 | -import { IdeMessengerContext } from "../../../../../context/IdeMessenger"; | |
| 13 | -import { createMockStore } from "../../../../../util/test/mockStore"; | |
| 14 | -import DocsIndexingStatus from "./DocsIndexingStatus"; | |
| 15 | - | |
| 16 | -const mockLumpContext = { | |
| 17 | - hideLump: vi.fn(), | |
| 18 | - showLump: vi.fn(), | |
| 19 | -}; | |
| 20 | - | |
| 21 | -vi.mock("../../LumpContext", () => ({ | |
| 22 | - useLump: () => mockLumpContext, | |
| 23 | -})); | |
| 24 | - | |
| 25 | -describe("DocsIndexingStatus", () => { | |
| 26 | - const mockDocConfig: SiteIndexingConfig = { | |
| 27 | - startUrl: "https://example.com", | |
| 28 | - title: "Example Docs", | |
| 29 | - }; | |
| 30 | - | |
| 31 | - const mockDocFromYaml = { | |
| 32 | - startUrl: "https://example.com", | |
| 33 | - title: "Example Docs", | |
| 34 | - }; | |
| 35 | - | |
| 36 | - const renderComponent = async ( | |
| 37 | - props: any = {}, | |
| 38 | - storeState = {}, | |
| 39 | - mockIdeMessengerSetup?: (mock: any) => void, | |
| 40 | - ) => { | |
| 41 | - const { mockIdeMessenger, ...store } = createMockStore(storeState); | |
| 42 | - | |
| 43 | - // Configure the mockIdeMessenger for this test | |
| 44 | - if (mockIdeMessengerSetup) { | |
| 45 | - mockIdeMessengerSetup(mockIdeMessenger); | |
| 46 | - } else { | |
| 47 | - mockIdeMessenger.request.mockResolvedValue({ | |
| 48 | - status: "success", | |
| 49 | - content: ["page1.html", "page2.html"], | |
| 50 | - }); | |
| 51 | - } | |
| 52 | - | |
| 53 | - const result = await act(async () => | |
| 54 | - render( | |
| 55 | - <Provider store={store}> | |
| 56 | - <IdeMessengerContext.Provider value={mockIdeMessenger}> | |
| 57 | - <AuthProvider> | |
| 58 | - <DocsIndexingStatus | |
| 59 | - docConfig={mockDocConfig} | |
| 60 | - docFromYaml={mockDocFromYaml} | |
| 61 | - {...props} | |
| 62 | - /> | |
| 63 | - </AuthProvider> | |
| 64 | - </IdeMessengerContext.Provider> | |
| 65 | - </Provider>, | |
| 66 | - ), | |
| 67 | - ); | |
| 68 | - | |
| 69 | - return { ...result, mockIdeMessenger }; | |
| 70 | - }; | |
| 71 | - | |
| 72 | - beforeEach(() => { | |
| 73 | - vi.clearAllMocks(); | |
| 74 | - }); | |
| 75 | - | |
| 76 | - it("renders doc title and basic structure", async () => { | |
| 77 | - await renderComponent(); | |
| 78 | - expect(screen.getByText("Example Docs")).toBeInTheDocument(); | |
| 79 | - }); | |
| 80 | - | |
| 81 | - it("renders startUrl when title is not provided", async () => { | |
| 82 | - const configWithoutTitle = { ...mockDocConfig, title: undefined }; | |
| 83 | - await renderComponent({ docConfig: configWithoutTitle }); | |
| 84 | - expect(screen.getByText("https://example.com")).toBeInTheDocument(); | |
| 85 | - }); | |
| 86 | - | |
| 87 | - it("shows progress percentage when indexing", async () => { | |
| 88 | - const storeState = { | |
| 89 | - indexing: { | |
| 90 | - indexing: { | |
| 91 | - statuses: { | |
| 92 | - "https://example.com": { | |
| 93 | - status: "indexing", | |
| 94 | - progress: 0.45, | |
| 95 | - description: "Indexing pages...", | |
| 96 | - }, | |
| 97 | - }, | |
| 98 | - }, | |
| 99 | - }, | |
| 100 | - }; | |
| 101 | - | |
| 102 | - await renderComponent({}, storeState); | |
| 103 | - expect(screen.getByText("45%")).toBeInTheDocument(); | |
| 104 | - }); | |
| 105 | - | |
| 106 | - it("shows stop icon when indexing", async () => { | |
| 107 | - const storeState = { | |
| 108 | - indexing: { | |
| 109 | - indexing: { | |
| 110 | - statuses: { | |
| 111 | - "https://example.com": { | |
| 112 | - status: "indexing", | |
| 113 | - progress: 0.25, | |
| 114 | - }, | |
| 115 | - }, | |
| 116 | - }, | |
| 117 | - }, | |
| 118 | - }; | |
| 119 | - | |
| 120 | - await renderComponent({}, storeState); | |
| 121 | - const stopIcon = screen.getByTestId("stop-indexing"); | |
| 122 | - expect(stopIcon).toBeInTheDocument(); | |
| 123 | - }); | |
| 124 | - | |
| 125 | - it("calls abort when stop icon is clicked", async () => { | |
| 126 | - const storeState = { | |
| 127 | - indexing: { | |
| 128 | - indexing: { | |
| 129 | - statuses: { | |
| 130 | - "https://example.com": { | |
| 131 | - status: "indexing", | |
| 132 | - progress: 0.25, | |
| 133 | - }, | |
| 134 | - }, | |
| 135 | - }, | |
| 136 | - }, | |
| 137 | - }; | |
| 138 | - | |
| 139 | - const { mockIdeMessenger } = await renderComponent({}, storeState); | |
| 140 | - const stopButton = screen.getByTestId("stop-indexing"); | |
| 141 | - fireEvent.click(stopButton); | |
| 142 | - | |
| 143 | - expect(mockIdeMessenger.post).toHaveBeenCalledWith("indexing/abort", { | |
| 144 | - type: "docs", | |
| 145 | - id: "https://example.com", | |
| 146 | - }); | |
| 147 | - }); | |
| 148 | - | |
| 149 | - it("shows reindex icon when status is complete", async () => { | |
| 150 | - const storeState = { | |
| 151 | - indexing: { | |
| 152 | - indexing: { | |
| 153 | - statuses: { | |
| 154 | - "https://example.com": { | |
| 155 | - status: "complete", | |
| 156 | - progress: 1, | |
| 157 | - }, | |
| 158 | - }, | |
| 159 | - }, | |
| 160 | - }, | |
| 161 | - }; | |
| 162 | - | |
| 163 | - await renderComponent({}, storeState); | |
| 164 | - const reindexButton = screen.getByTestId("reindex-docs"); | |
| 165 | - expect(reindexButton).toBeInTheDocument(); | |
| 166 | - }); | |
| 167 | - | |
| 168 | - it("calls reindex when reindex icon is clicked", async () => { | |
| 169 | - const storeState = { | |
| 170 | - indexing: { | |
| 171 | - indexing: { | |
| 172 | - statuses: { | |
| 173 | - "https://example.com": { | |
| 174 | - status: "complete", | |
| 175 | - progress: 1, | |
| 176 | - }, | |
| 177 | - }, | |
| 178 | - }, | |
| 179 | - }, | |
| 180 | - }; | |
| 181 | - | |
| 182 | - const { mockIdeMessenger } = await renderComponent({}, storeState); | |
| 183 | - const reindexButton = screen.getByTestId("reindex-docs"); | |
| 184 | - fireEvent.click(reindexButton); | |
| 185 | - | |
| 186 | - expect(mockIdeMessenger.post).toHaveBeenCalledWith("indexing/reindex", { | |
| 187 | - type: "docs", | |
| 188 | - id: "https://example.com", | |
| 189 | - }); | |
| 190 | - }); | |
| 191 | - | |
| 192 | - it("opens URL when title is clicked and status has URL", async () => { | |
| 193 | - const storeState = { | |
| 194 | - indexing: { | |
| 195 | - indexing: { | |
| 196 | - statuses: { | |
| 197 | - "https://example.com": { | |
| 198 | - status: "complete", | |
| 199 | - url: "https://example.com/docs", | |
| 200 | - }, | |
| 201 | - }, | |
| 202 | - }, | |
| 203 | - }, | |
| 204 | - }; | |
| 205 | - | |
| 206 | - const { mockIdeMessenger } = await renderComponent({}, storeState); | |
| 207 | - const titleElement = screen.getByText("Example Docs"); | |
| 208 | - fireEvent.click(titleElement); | |
| 209 | - | |
| 210 | - expect(mockIdeMessenger.post).toHaveBeenCalledWith( | |
| 211 | - "openUrl", | |
| 212 | - "https://example.com/docs", | |
| 213 | - ); | |
| 214 | - expect(mockLumpContext.hideLump).toHaveBeenCalled(); | |
| 215 | - }); | |
| 216 | - | |
| 217 | - it("fetches indexed pages when status becomes complete", async () => { | |
| 218 | - const storeState = { | |
| 219 | - indexing: { | |
| 220 | - indexing: { | |
| 221 | - statuses: { | |
| 222 | - "https://example.com": { | |
| 223 | - status: "complete", | |
| 224 | - progress: 1, | |
| 225 | - }, | |
| 226 | - }, | |
| 227 | - }, | |
| 228 | - }, | |
| 229 | - }; | |
| 230 | - | |
| 231 | - const { mockIdeMessenger } = await renderComponent({}, storeState); | |
| 232 | - | |
| 233 | - await waitFor(() => { | |
| 234 | - expect(mockIdeMessenger.request).toHaveBeenCalledWith( | |
| 235 | - "docs/getIndexedPages", | |
| 236 | - { | |
| 237 | - startUrl: "https://example.com", | |
| 238 | - }, | |
| 239 | - ); | |
| 240 | - }); | |
| 241 | - }); | |
| 242 | - | |
| 243 | - it("displays indexed pages count when available", async () => { | |
| 244 | - const storeState = { | |
| 245 | - indexing: { | |
| 246 | - indexing: { | |
| 247 | - statuses: { | |
| 248 | - "https://example.com": { | |
| 249 | - status: "complete", | |
| 250 | - progress: 1, | |
| 251 | - }, | |
| 252 | - }, | |
| 253 | - }, | |
| 254 | - }, | |
| 255 | - }; | |
| 256 | - | |
| 257 | - await renderComponent({}, storeState, (mockIdeMessenger) => { | |
| 258 | - mockIdeMessenger.request.mockResolvedValue({ | |
| 259 | - status: "success", | |
| 260 | - content: ["page1.html", "page2.html", "page3.html"], | |
| 261 | - }); | |
| 262 | - }); | |
| 263 | - | |
| 264 | - await waitFor(() => { | |
| 265 | - expect(screen.getByText("3 pages indexed")).toBeInTheDocument(); | |
| 266 | - }); | |
| 267 | - }); | |
| 268 | - | |
| 269 | - it("shows singular page text for one page", async () => { | |
| 270 | - const storeState = { | |
| 271 | - indexing: { | |
| 272 | - indexing: { | |
| 273 | - statuses: { | |
| 274 | - "https://example.com": { | |
| 275 | - status: "complete", | |
| 276 | - progress: 1, | |
| 277 | - }, | |
| 278 | - }, | |
| 279 | - }, | |
| 280 | - }, | |
| 281 | - }; | |
| 282 | - | |
| 283 | - await renderComponent({}, storeState, (mockIdeMessenger) => { | |
| 284 | - mockIdeMessenger.request.mockResolvedValue({ | |
| 285 | - status: "success", | |
| 286 | - content: ["page1.html"], | |
| 287 | - }); | |
| 288 | - }); | |
| 289 | - | |
| 290 | - await waitFor(() => { | |
| 291 | - expect(screen.getByText("1 page indexed")).toBeInTheDocument(); | |
| 292 | - }); | |
| 293 | - }); | |
| 294 | - | |
| 295 | - it("shows status description when not complete", async () => { | |
| 296 | - const storeState = { | |
| 297 | - indexing: { | |
| 298 | - indexing: { | |
| 299 | - statuses: { | |
| 300 | - "https://example.com": { | |
| 301 | - status: "indexing", | |
| 302 | - progress: 0.5, | |
| 303 | - description: "Processing documentation...", | |
| 304 | - }, | |
| 305 | - }, | |
| 306 | - }, | |
| 307 | - }, | |
| 308 | - }; | |
| 309 | - | |
| 310 | - await renderComponent({}, storeState); | |
| 311 | - expect(screen.getByText("Processing documentation...")).toBeInTheDocument(); | |
| 312 | - }); | |
| 313 | - | |
| 314 | - it("handles error when fetching indexed pages", async () => { | |
| 315 | - const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {}); | |
| 316 | - | |
| 317 | - const storeState = { | |
| 318 | - indexing: { | |
| 319 | - indexing: { | |
| 320 | - statuses: { | |
| 321 | - "https://example.com": { | |
| 322 | - status: "complete", | |
| 323 | - progress: 1, | |
| 324 | - }, | |
| 325 | - }, | |
| 326 | - }, | |
| 327 | - }, | |
| 328 | - }; | |
| 329 | - | |
| 330 | - await renderComponent({}, storeState, (mockIdeMessenger) => { | |
| 331 | - mockIdeMessenger.request.mockResolvedValue({ | |
| 332 | - status: "error", | |
| 333 | - error: "Failed to fetch pages", | |
| 334 | - }); | |
| 335 | - }); | |
| 336 | - | |
| 337 | - await waitFor(() => { | |
| 338 | - expect(consoleSpy).toHaveBeenCalledWith( | |
| 339 | - expect.stringContaining( | |
| 340 | - "Unable to fetch pages list for https://example.com", | |
| 341 | - ), | |
| 342 | - ); | |
| 343 | - }); | |
| 344 | - | |
| 345 | - consoleSpy.mockRestore(); | |
| 346 | - }); | |
| 347 | - | |
| 348 | - it("returns null when hasDeleted is true", async () => { | |
| 349 | - const { container } = await renderComponent(); | |
| 350 | - | |
| 351 | - // Simulate deletion state by accessing the component's internal state | |
| 352 | - // In a real scenario, this would be tested through user interaction | |
| 353 | - expect(container.firstChild).not.toBeNull(); | |
| 354 | - }); | |
| 355 | - | |
| 356 | - it("shows loading text when pages are being fetched", async () => { | |
| 357 | - const storeState = { | |
| 358 | - indexing: { | |
| 359 | - indexing: { | |
| 360 | - statuses: { | |
| 361 | - "https://example.com": { | |
| 362 | - status: "complete", | |
| 363 | - progress: 1, | |
| 364 | - }, | |
| 365 | - }, | |
| 366 | - }, | |
| 367 | - }, | |
| 368 | - }; | |
| 369 | - | |
| 370 | - await renderComponent({}, storeState, (mockIdeMessenger) => { | |
| 371 | - // Mock a delayed response to keep in loading state | |
| 372 | - mockIdeMessenger.request.mockImplementation(() => new Promise(() => {})); | |
| 373 | - }); | |
| 374 | - | |
| 375 | - expect(screen.getByText("Loading site info...")).toBeInTheDocument(); | |
| 376 | - }); | |
| 377 | -}); |
deleted gui/src/components/mainInput/Lump/sections/docs/DocsIndexingStatus.tsx +0 −246
| @@ -1,246 +0,0 @@ | ||
| 1 | -import { ConfigYaml } from "@continuedev/config-yaml"; | |
| 2 | -import { ArrowPathIcon, StopIcon } from "@heroicons/react/24/outline"; | |
| 3 | -import { SiteIndexingConfig } from "core"; | |
| 4 | -import { useContext, useEffect, useMemo, useState } from "react"; | |
| 5 | -import { IdeMessengerContext } from "../../../../../context/IdeMessenger"; | |
| 6 | -import { useAppDispatch, useAppSelector } from "../../../../../redux/hooks"; | |
| 7 | -import { updateIndexingStatus } from "../../../../../redux/slices/indexingSlice"; | |
| 8 | -import { | |
| 9 | - setDialogMessage, | |
| 10 | - setShowDialog, | |
| 11 | -} from "../../../../../redux/slices/uiSlice"; | |
| 12 | -import { fontSize } from "../../../../../util"; | |
| 13 | -import ConfirmationDialog from "../../../../dialogs/ConfirmationDialog"; | |
| 14 | -import { ToolTip } from "../../../../gui/Tooltip"; | |
| 15 | -import EditBlockButton from "../../EditBlockButton"; | |
| 16 | -import { useLump } from "../../LumpContext"; | |
| 17 | -import { IndexedPagesTooltip } from "./IndexedPagesTooltip"; | |
| 18 | -import { StatusIndicator } from "./StatusIndicator"; | |
| 19 | - | |
| 20 | -interface IndexingStatusViewerProps { | |
| 21 | - docConfig: SiteIndexingConfig; | |
| 22 | - docFromYaml?: NonNullable<ConfigYaml["docs"]>[number]; | |
| 23 | -} | |
| 24 | - | |
| 25 | -function DocsIndexingStatus({ | |
| 26 | - docConfig, | |
| 27 | - docFromYaml, | |
| 28 | -}: IndexingStatusViewerProps) { | |
| 29 | - const ideMessenger = useContext(IdeMessengerContext); | |
| 30 | - const dispatch = useAppDispatch(); | |
| 31 | - const { hideLump } = useLump(); | |
| 32 | - const [indexedPages, setIndexedPages] = useState<null | string[]>(null); | |
| 33 | - const [showTooltip, setShowTooltip] = useState(false); | |
| 34 | - | |
| 35 | - const status = useAppSelector( | |
| 36 | - (store) => store.indexing.indexing.statuses[docConfig.startUrl], | |
| 37 | - ); | |
| 38 | - | |
| 39 | - const isComplete = status?.status === "complete"; | |
| 40 | - | |
| 41 | - const reIndex = () => | |
| 42 | - ideMessenger.post("indexing/reindex", { | |
| 43 | - type: "docs", | |
| 44 | - id: docConfig.startUrl, | |
| 45 | - }); | |
| 46 | - | |
| 47 | - const abort = () => { | |
| 48 | - ideMessenger.post("indexing/abort", { | |
| 49 | - type: "docs", | |
| 50 | - id: docConfig.startUrl, | |
| 51 | - }); | |
| 52 | - // Optimistic abort status | |
| 53 | - if (status) { | |
| 54 | - dispatch( | |
| 55 | - updateIndexingStatus({ ...status, status: "aborted", progress: 0 }), | |
| 56 | - ); | |
| 57 | - } | |
| 58 | - }; | |
| 59 | - | |
| 60 | - const [hasDeleted, setHasDeleted] = useState(false); // simple alternative to optimistic redux update | |
| 61 | - const onDelete = () => { | |
| 62 | - // optimistic update | |
| 63 | - dispatch( | |
| 64 | - setDialogMessage( | |
| 65 | - <ConfirmationDialog | |
| 66 | - title={`Delete ${docConfig.title}`} | |
| 67 | - text={`Are you sure you want to remove ${docConfig.title} from your configuration?`} | |
| 68 | - onConfirm={() => { | |
| 69 | - ideMessenger.post("context/removeDocs", { | |
| 70 | - startUrl: docConfig.startUrl, | |
| 71 | - }); | |
| 72 | - setHasDeleted(true); | |
| 73 | - }} | |
| 74 | - />, | |
| 75 | - ), | |
| 76 | - ); | |
| 77 | - dispatch(setShowDialog(true)); | |
| 78 | - }; | |
| 79 | - | |
| 80 | - const progressPercentage = useMemo(() => { | |
| 81 | - if (!status) { | |
| 82 | - return 0; | |
| 83 | - } | |
| 84 | - return Math.min(100, Math.max(0, status.progress * 100)).toFixed(0); | |
| 85 | - }, [status?.progress]); | |
| 86 | - | |
| 87 | - // Fetch pages list when the status changes to complete | |
| 88 | - useEffect(() => { | |
| 89 | - async function getPagesList() { | |
| 90 | - try { | |
| 91 | - const response = await ideMessenger.request("docs/getIndexedPages", { | |
| 92 | - startUrl: docConfig.startUrl, | |
| 93 | - }); | |
| 94 | - if (response.status === "error") { | |
| 95 | - throw new Error(response.error); | |
| 96 | - } | |
| 97 | - setIndexedPages(response.content.sort()); | |
| 98 | - } catch (ex) { | |
| 99 | - console.error( | |
| 100 | - `Unable to fetch pages list for ${docConfig.startUrl}: ${ex}`, | |
| 101 | - ); | |
| 102 | - } | |
| 103 | - } | |
| 104 | - | |
| 105 | - if (isComplete) { | |
| 106 | - void getPagesList(); | |
| 107 | - } | |
| 108 | - }, [isComplete, ideMessenger, docConfig.startUrl]); | |
| 109 | - | |
| 110 | - const showPagesList = () => { | |
| 111 | - if (indexedPages) { | |
| 112 | - setShowTooltip(true); | |
| 113 | - } | |
| 114 | - }; | |
| 115 | - | |
| 116 | - if (hasDeleted) return null; | |
| 117 | - | |
| 118 | - const startUrlSlug = docConfig.startUrl.replace(/[^a-zA-Z0-9_-]/g, "_"); | |
| 119 | - | |
| 120 | - return ( | |
| 121 | - <div className="mt-1 flex w-full flex-col"> | |
| 122 | - <div | |
| 123 | - className={`flex flex-row items-center justify-between gap-2 text-sm`} | |
| 124 | - > | |
| 125 | - <div | |
| 126 | - className={`flex flex-row items-center gap-1`} | |
| 127 | - onClick={() => { | |
| 128 | - if (status?.url) { | |
| 129 | - ideMessenger.post("openUrl", status.url); | |
| 130 | - hideLump(); | |
| 131 | - } | |
| 132 | - }} | |
| 133 | - > | |
| 134 | - <p | |
| 135 | - style={{ | |
| 136 | - fontSize: fontSize(-3), | |
| 137 | - }} | |
| 138 | - className={`m-0 line-clamp-1 p-0 text-left ${status?.url ? "cursor-pointer hover:underline" : ""}`} | |
| 139 | - > | |
| 140 | - {docConfig.title ?? docConfig.startUrl} | |
| 141 | - </p> | |
| 142 | - </div> | |
| 143 | - | |
| 144 | - <div className="flex flex-row items-center gap-2"> | |
| 145 | - <div className="flex flex-row items-center gap-2 text-gray-400"> | |
| 146 | - {status?.status === "indexing" && ( | |
| 147 | - <span | |
| 148 | - className="text-xs" | |
| 149 | - style={{ | |
| 150 | - fontSize: fontSize(-3), | |
| 151 | - }} | |
| 152 | - > | |
| 153 | - {progressPercentage}% | |
| 154 | - </span> | |
| 155 | - )} | |
| 156 | - | |
| 157 | - {status?.status === "indexing" && ( | |
| 158 | - <StopIcon | |
| 159 | - className="h-3 w-3 cursor-pointer text-gray-400 hover:brightness-125" | |
| 160 | - onClick={abort} | |
| 161 | - data-testid="stop-indexing" | |
| 162 | - /> | |
| 163 | - )} | |
| 164 | - | |
| 165 | - <EditBlockButton | |
| 166 | - blockType="docs" | |
| 167 | - block={docFromYaml} | |
| 168 | - sourceFile={docConfig.sourceFile} | |
| 169 | - /> | |
| 170 | - | |
| 171 | - {["aborted", "complete", "failed"].includes( | |
| 172 | - status?.status ?? "", | |
| 173 | - ) && ( | |
| 174 | - <ArrowPathIcon | |
| 175 | - className="h-3 w-3 cursor-pointer text-gray-400 hover:brightness-125" | |
| 176 | - onClick={reIndex} | |
| 177 | - data-testid="reindex-docs" | |
| 178 | - /> | |
| 179 | - )} | |
| 180 | - | |
| 181 | - <StatusIndicator | |
| 182 | - status={status?.status} | |
| 183 | - hoverMessage={ | |
| 184 | - status?.status === "failed" ? status?.debugInfo : undefined | |
| 185 | - } | |
| 186 | - /> | |
| 187 | - </div> | |
| 188 | - </div> | |
| 189 | - </div> | |
| 190 | - | |
| 191 | - {status && ( | |
| 192 | - <div | |
| 193 | - className={`flex flex-row items-center justify-between gap-2 text-sm`} | |
| 194 | - > | |
| 195 | - <p | |
| 196 | - style={{ | |
| 197 | - fontSize: fontSize(-4), | |
| 198 | - }} | |
| 199 | - className={`m-0 line-clamp-1 p-0 text-left text-gray-400 ${isComplete ? "cursor-pointer hover:underline" : ""}`} | |
| 200 | - onClick={() => { | |
| 201 | - if (isComplete) { | |
| 202 | - showPagesList(); | |
| 203 | - } | |
| 204 | - }} | |
| 205 | - data-tooltip-id={`docs-tooltip-${startUrlSlug}`} | |
| 206 | - > | |
| 207 | - {isComplete | |
| 208 | - ? indexedPages | |
| 209 | - ? `${indexedPages.length} page${indexedPages.length === 1 ? "" : "s"} indexed` | |
| 210 | - : "Loading site info..." | |
| 211 | - : status.description} | |
| 212 | - </p> | |
| 213 | - </div> | |
| 214 | - )} | |
| 215 | - | |
| 216 | - {indexedPages && ( | |
| 217 | - <ToolTip | |
| 218 | - isOpen={showTooltip} | |
| 219 | - setIsOpen={setShowTooltip} | |
| 220 | - clickable | |
| 221 | - delayShow={0} | |
| 222 | - openEvents={{ | |
| 223 | - mouseenter: false, | |
| 224 | - click: true, | |
| 225 | - }} | |
| 226 | - closeEvents={{ | |
| 227 | - blur: true, | |
| 228 | - mouseleave: false, | |
| 229 | - click: true, | |
| 230 | - }} | |
| 231 | - content={ | |
| 232 | - <IndexedPagesTooltip | |
| 233 | - pages={indexedPages} | |
| 234 | - siteTitle={docConfig.title ?? docConfig.startUrl} | |
| 235 | - baseUrl={docConfig.startUrl} | |
| 236 | - /> | |
| 237 | - } | |
| 238 | - > | |
| 239 | - <div data-tooltip-id={`docs-tooltip-${startUrlSlug}`} /> | |
| 240 | - </ToolTip> | |
| 241 | - )} | |
| 242 | - </div> | |
| 243 | - ); | |
| 244 | -} | |
| 245 | - | |
| 246 | -export default DocsIndexingStatus; |
deleted gui/src/components/mainInput/Lump/sections/docs/DocsSection.tsx +0 −75
| @@ -1,75 +0,0 @@ | ||
| 1 | -import { parseConfigYaml } from "@continuedev/config-yaml"; | |
| 2 | -import { IndexingStatus } from "core"; | |
| 3 | -import { useMemo } from "react"; | |
| 4 | -import { useAuth } from "../../../../../context/Auth"; | |
| 5 | -import { useAppSelector } from "../../../../../redux/hooks"; | |
| 6 | -import { ExploreBlocksButton } from "../ExploreBlocksButton"; | |
| 7 | -import DocsIndexingStatus from "./DocsIndexingStatus"; | |
| 8 | - | |
| 9 | -function DocsIndexingStatuses() { | |
| 10 | - const config = useAppSelector((store) => store.config.config); | |
| 11 | - const indexingStatuses = useAppSelector( | |
| 12 | - (store) => store.indexing.indexing.statuses, | |
| 13 | - ); | |
| 14 | - const { selectedProfile } = useAuth(); | |
| 15 | - const mergedDocs = useMemo(() => { | |
| 16 | - const parsed = selectedProfile?.rawYaml | |
| 17 | - ? parseConfigYaml(selectedProfile?.rawYaml ?? "") | |
| 18 | - : undefined; | |
| 19 | - return (config.docs ?? []).map((doc, index) => ({ | |
| 20 | - doc, | |
| 21 | - docFromYaml: parsed?.docs?.[index], | |
| 22 | - })); | |
| 23 | - }, [config.docs, selectedProfile?.rawYaml]); | |
| 24 | - | |
| 25 | - const sortedConfigDocs = useMemo(() => { | |
| 26 | - const sorter = (status: IndexingStatus["status"]) => { | |
| 27 | - if (status === "complete") return 0; | |
| 28 | - if (status === "indexing" || status === "paused") return 1; | |
| 29 | - if (status === "failed") return 2; | |
| 30 | - if (status === "aborted" || status === "pending") return 3; | |
| 31 | - return 4; | |
| 32 | - }; | |
| 33 | - | |
| 34 | - const docs = [...mergedDocs]; | |
| 35 | - docs.sort((a, b) => { | |
| 36 | - const statusA = indexingStatuses[a.doc.startUrl]?.status ?? "pending"; | |
| 37 | - const statusB = indexingStatuses[b.doc.startUrl]?.status ?? "pending"; | |
| 38 | - | |
| 39 | - // First, compare by status | |
| 40 | - const statusCompare = sorter(statusA) - sorter(statusB); | |
| 41 | - if (statusCompare !== 0) return statusCompare; | |
| 42 | - | |
| 43 | - // If status is the same, sort by presence of icon | |
| 44 | - const hasIconA = !!a.doc.faviconUrl; | |
| 45 | - const hasIconB = !!b.doc.faviconUrl; | |
| 46 | - return hasIconB === hasIconA ? 0 : hasIconB ? 1 : -1; | |
| 47 | - }); | |
| 48 | - return docs; | |
| 49 | - }, [mergedDocs, indexingStatuses]); | |
| 50 | - | |
| 51 | - return ( | |
| 52 | - <div className="flex flex-col gap-1"> | |
| 53 | - <div className="flex flex-col overflow-y-auto overflow-x-hidden pr-2"> | |
| 54 | - {sortedConfigDocs.map((docConfig) => { | |
| 55 | - return ( | |
| 56 | - <div | |
| 57 | - key={docConfig.doc.startUrl} | |
| 58 | - className="flex items-center gap-2" | |
| 59 | - > | |
| 60 | - <div className="flex-grow"> | |
| 61 | - <DocsIndexingStatus | |
| 62 | - docFromYaml={docConfig.docFromYaml} | |
| 63 | - docConfig={docConfig.doc} | |
| 64 | - /> | |
| 65 | - </div> | |
| 66 | - </div> | |
| 67 | - ); | |
| 68 | - })} | |
| 69 | - </div> | |
| 70 | - <ExploreBlocksButton blockType="docs" /> | |
| 71 | - </div> | |
| 72 | - ); | |
| 73 | -} | |
| 74 | - | |
| 75 | -export default DocsIndexingStatuses; |
deleted gui/src/components/mainInput/Lump/sections/docs/IndexedPagesTooltip.test.tsx +0 −213
| @@ -1,213 +0,0 @@ | ||
| 1 | -import { fireEvent, render, screen } from "@testing-library/react"; | |
| 2 | -import { Provider } from "react-redux"; | |
| 3 | -import { beforeEach, describe, expect, it, vi } from "vitest"; | |
| 4 | -import { IdeMessengerContext } from "../../../../../context/IdeMessenger"; | |
| 5 | -import { createMockStore } from "../../../../../util/test/mockStore"; | |
| 6 | -import { IndexedPagesTooltip } from "./IndexedPagesTooltip"; | |
| 7 | - | |
| 8 | -describe("IndexedPagesTooltip", () => { | |
| 9 | - const defaultProps = { | |
| 10 | - pages: [ | |
| 11 | - "https://example.com/page1", | |
| 12 | - "https://example.com/page2", | |
| 13 | - "https://example.com/sub/page3", | |
| 14 | - ], | |
| 15 | - siteTitle: "Example Documentation", | |
| 16 | - baseUrl: "https://example.com", | |
| 17 | - }; | |
| 18 | - | |
| 19 | - const renderComponent = (props = {}, storeState = {}) => { | |
| 20 | - const { mockIdeMessenger, ...store } = createMockStore(storeState); | |
| 21 | - | |
| 22 | - return { | |
| 23 | - ...render( | |
| 24 | - <Provider store={store}> | |
| 25 | - <IdeMessengerContext.Provider value={mockIdeMessenger}> | |
| 26 | - <IndexedPagesTooltip {...defaultProps} {...props} /> | |
| 27 | - </IdeMessengerContext.Provider> | |
| 28 | - </Provider>, | |
| 29 | - ), | |
| 30 | - mockIdeMessenger, | |
| 31 | - store, | |
| 32 | - }; | |
| 33 | - }; | |
| 34 | - | |
| 35 | - beforeEach(() => { | |
| 36 | - vi.clearAllMocks(); | |
| 37 | - }); | |
| 38 | - | |
| 39 | - it("renders site title and page count", () => { | |
| 40 | - renderComponent(); | |
| 41 | - expect( | |
| 42 | - screen.getByText("Example Documentation - 3 Pages Indexed"), | |
| 43 | - ).toBeInTheDocument(); | |
| 44 | - }); | |
| 45 | - | |
| 46 | - it("renders all pages in the list", () => { | |
| 47 | - renderComponent(); | |
| 48 | - | |
| 49 | - // Check that all pages are rendered (with baseUrl prefix removed) | |
| 50 | - expect(screen.getByText("/page1")).toBeInTheDocument(); | |
| 51 | - expect(screen.getByText("/page2")).toBeInTheDocument(); | |
| 52 | - expect(screen.getByText("/sub/page3")).toBeInTheDocument(); | |
| 53 | - }); | |
| 54 | - | |
| 55 | - it("removes baseUrl prefix from page URLs", () => { | |
| 56 | - const pages = [ | |
| 57 | - "https://example.com/docs/getting-started", | |
| 58 | - "https://example.com/docs/api-reference", | |
| 59 | - "https://other-domain.com/page", // This should not have prefix removed | |
| 60 | - ]; | |
| 61 | - | |
| 62 | - renderComponent({ pages, baseUrl: "https://example.com" }); | |
| 63 | - | |
| 64 | - expect(screen.getByText("/docs/getting-started")).toBeInTheDocument(); | |
| 65 | - expect(screen.getByText("/docs/api-reference")).toBeInTheDocument(); | |
| 66 | - expect( | |
| 67 | - screen.getByText("https://other-domain.com/page"), | |
| 68 | - ).toBeInTheDocument(); | |
| 69 | - }); | |
| 70 | - | |
| 71 | - it("handles pages that don't start with baseUrl", () => { | |
| 72 | - const pages = [ | |
| 73 | - "https://different-domain.com/page1", | |
| 74 | - "mailto:contact@example.com", | |
| 75 | - ]; | |
| 76 | - | |
| 77 | - renderComponent({ pages }); | |
| 78 | - | |
| 79 | - expect( | |
| 80 | - screen.getByText("https://different-domain.com/page1"), | |
| 81 | - ).toBeInTheDocument(); | |
| 82 | - expect(screen.getByText("mailto:contact@example.com")).toBeInTheDocument(); | |
| 83 | - }); | |
| 84 | - | |
| 85 | - it("opens URL when page is clicked", () => { | |
| 86 | - const { mockIdeMessenger } = renderComponent(); | |
| 87 | - | |
| 88 | - const pageLink = screen.getByText("/page1"); | |
| 89 | - fireEvent.click(pageLink); | |
| 90 | - | |
| 91 | - expect(mockIdeMessenger.post).toHaveBeenCalledWith( | |
| 92 | - "openUrl", | |
| 93 | - "https://example.com/page1", | |
| 94 | - ); | |
| 95 | - }); | |
| 96 | - | |
| 97 | - it("opens each page URL correctly when clicked", () => { | |
| 98 | - const { mockIdeMessenger } = renderComponent(); | |
| 99 | - | |
| 100 | - // Click on different pages | |
| 101 | - fireEvent.click(screen.getByText("/page2")); | |
| 102 | - expect(mockIdeMessenger.post).toHaveBeenCalledWith( | |
| 103 | - "openUrl", | |
| 104 | - "https://example.com/page2", | |
| 105 | - ); | |
| 106 | - | |
| 107 | - fireEvent.click(screen.getByText("/sub/page3")); | |
| 108 | - expect(mockIdeMessenger.post).toHaveBeenCalledWith( | |
| 109 | - "openUrl", | |
| 110 | - "https://example.com/sub/page3", | |
| 111 | - ); | |
| 112 | - }); | |
| 113 | - | |
| 114 | - it("renders empty list when no pages provided", () => { | |
| 115 | - renderComponent({ pages: [] }); | |
| 116 | - | |
| 117 | - expect( | |
| 118 | - screen.getByText("Example Documentation - 0 Pages Indexed"), | |
| 119 | - ).toBeInTheDocument(); | |
| 120 | - expect(screen.queryByRole("listitem")).not.toBeInTheDocument(); | |
| 121 | - }); | |
| 122 | - | |
| 123 | - it("handles single page correctly", () => { | |
| 124 | - const pages = ["https://example.com/single-page"]; | |
| 125 | - | |
| 126 | - renderComponent({ pages }); | |
| 127 | - | |
| 128 | - expect( | |
| 129 | - screen.getByText("Example Documentation - 1 Pages Indexed"), | |
| 130 | - ).toBeInTheDocument(); | |
| 131 | - expect(screen.getByText("/single-page")).toBeInTheDocument(); | |
| 132 | - }); | |
| 133 | - | |
| 134 | - it("preserves page order", () => { | |
| 135 | - const pages = [ | |
| 136 | - "https://example.com/z-last", | |
| 137 | - "https://example.com/a-first", | |
| 138 | - "https://example.com/m-middle", | |
| 139 | - ]; | |
| 140 | - | |
| 141 | - renderComponent({ pages }); | |
| 142 | - | |
| 143 | - const listItems = screen.getAllByRole("listitem"); | |
| 144 | - expect(listItems).toHaveLength(3); | |
| 145 | - | |
| 146 | - // Check that the order is preserved as provided, not alphabetically sorted | |
| 147 | - expect(listItems[0]).toHaveTextContent("/z-last"); | |
| 148 | - expect(listItems[1]).toHaveTextContent("/a-first"); | |
| 149 | - expect(listItems[2]).toHaveTextContent("/m-middle"); | |
| 150 | - }); | |
| 151 | - | |
| 152 | - it("applies correct CSS classes for styling", () => { | |
| 153 | - renderComponent(); | |
| 154 | - | |
| 155 | - const pageItems = screen.getAllByRole("listitem"); | |
| 156 | - pageItems.forEach((item) => { | |
| 157 | - expect(item).toHaveClass( | |
| 158 | - "my-1", | |
| 159 | - "cursor-pointer", | |
| 160 | - "truncate", | |
| 161 | - "text-left", | |
| 162 | - "text-gray-400", | |
| 163 | - "hover:underline", | |
| 164 | - ); | |
| 165 | - }); | |
| 166 | - }); | |
| 167 | - | |
| 168 | - it("shows scrollable container for long lists", () => { | |
| 169 | - // Create a long list of pages | |
| 170 | - const longPageList = Array.from( | |
| 171 | - { length: 20 }, | |
| 172 | - (_, i) => `https://example.com/page-${i + 1}`, | |
| 173 | - ); | |
| 174 | - | |
| 175 | - const { container } = renderComponent({ pages: longPageList }); | |
| 176 | - | |
| 177 | - // Check that the scrollable container exists | |
| 178 | - const scrollContainer = container.querySelector( | |
| 179 | - ".max-h-48.overflow-y-auto", | |
| 180 | - ); | |
| 181 | - expect(scrollContainer).toBeInTheDocument(); | |
| 182 | - | |
| 183 | - // Check that all pages are rendered | |
| 184 | - expect( | |
| 185 | - screen.getByText("Example Documentation - 20 Pages Indexed"), | |
| 186 | - ).toBeInTheDocument(); | |
| 187 | - longPageList.forEach((_, index) => { | |
| 188 | - expect(screen.getByText(`/page-${index + 1}`)).toBeInTheDocument(); | |
| 189 | - }); | |
| 190 | - }); | |
| 191 | - | |
| 192 | - describe("removePrefix utility", () => { | |
| 193 | - it("removes prefix when string starts with it", () => { | |
| 194 | - const pages = ["https://example.com/docs/guide"]; | |
| 195 | - renderComponent({ pages, baseUrl: "https://example.com" }); | |
| 196 | - expect(screen.getByText("/docs/guide")).toBeInTheDocument(); | |
| 197 | - }); | |
| 198 | - | |
| 199 | - it("returns original string when it doesn't start with prefix", () => { | |
| 200 | - const pages = ["https://other-site.com/page"]; | |
| 201 | - renderComponent({ pages, baseUrl: "https://example.com" }); | |
| 202 | - expect( | |
| 203 | - screen.getByText("https://other-site.com/page"), | |
| 204 | - ).toBeInTheDocument(); | |
| 205 | - }); | |
| 206 | - | |
| 207 | - it("handles empty prefix", () => { | |
| 208 | - const pages = ["https://example.com/page"]; | |
| 209 | - renderComponent({ pages, baseUrl: "" }); | |
| 210 | - expect(screen.getByText("https://example.com/page")).toBeInTheDocument(); | |
| 211 | - }); | |
| 212 | - }); | |
| 213 | -}); |
deleted gui/src/components/mainInput/Lump/sections/docs/IndexedPagesTooltip.tsx +0 −71
| @@ -1,71 +0,0 @@ | ||
| 1 | -import { EyeIcon } from "@heroicons/react/24/outline"; | |
| 2 | -import { useContext } from "react"; | |
| 3 | -import { useDispatch } from "react-redux"; | |
| 4 | -import { IdeMessengerContext } from "../../../../../context/IdeMessenger"; | |
| 5 | -import { | |
| 6 | - setDialogMessage, | |
| 7 | - setShowDialog, | |
| 8 | -} from "../../../../../redux/slices/uiSlice"; | |
| 9 | -import { fontSize } from "../../../../../util"; | |
| 10 | -import DocsDetailsDialog from "./DocsDetailsDialog"; | |
| 11 | - | |
| 12 | -interface IndexedPagesTooltipProps { | |
| 13 | - pages: string[]; | |
| 14 | - siteTitle: string; | |
| 15 | - baseUrl: string; | |
| 16 | -} | |
| 17 | - | |
| 18 | -function removePrefix(str: string, prefix: string): string { | |
| 19 | - return str.startsWith(prefix) ? str.slice(prefix.length) : str; | |
| 20 | -} | |
| 21 | - | |
| 22 | -export const IndexedPagesTooltip = ({ | |
| 23 | - pages, | |
| 24 | - siteTitle, | |
| 25 | - baseUrl, | |
| 26 | -}: IndexedPagesTooltipProps) => { | |
| 27 | - const ideMessenger = useContext(IdeMessengerContext); | |
| 28 | - const dispatch = useDispatch(); | |
| 29 | - | |
| 30 | - const handleEyeIconClick = (e: React.MouseEvent) => { | |
| 31 | - e.stopPropagation(); | |
| 32 | - | |
| 33 | - // Open the DocsDetailsDialog component as a modal | |
| 34 | - dispatch(setShowDialog(true)); | |
| 35 | - dispatch(setDialogMessage(<DocsDetailsDialog startUrl={baseUrl} />)); | |
| 36 | - }; | |
| 37 | - | |
| 38 | - return ( | |
| 39 | - <div> | |
| 40 | - <div | |
| 41 | - className="mx-1 my-2 flex items-center justify-between font-semibold" | |
| 42 | - style={{ fontSize: fontSize(-3) }} | |
| 43 | - > | |
| 44 | - <span> | |
| 45 | - {siteTitle} - {pages.length} Pages Indexed | |
| 46 | - </span> | |
| 47 | - <EyeIcon | |
| 48 | - className="ml-2 h-4 w-4 cursor-pointer text-red-500 transition-colors hover:text-red-400" | |
| 49 | - onClick={handleEyeIconClick} | |
| 50 | - title="View detailed docs information" | |
| 51 | - /> | |
| 52 | - </div> | |
| 53 | - <div className="max-h-48 overflow-y-auto px-1"> | |
| 54 | - <ul className="list-none pl-0"> | |
| 55 | - {pages.map((page, index) => ( | |
| 56 | - <li | |
| 57 | - key={index} | |
| 58 | - className="my-1 cursor-pointer truncate text-left text-gray-400 hover:underline" | |
| 59 | - style={{ fontSize: fontSize(-4) }} | |
| 60 | - onClick={() => { | |
| 61 | - ideMessenger.post("openUrl", page); | |
| 62 | - }} | |
| 63 | - > | |
| 64 | - {removePrefix(page, baseUrl)} | |
| 65 | - </li> | |
| 66 | - ))} | |
| 67 | - </ul> | |
| 68 | - </div> | |
| 69 | - </div> | |
| 70 | - ); | |
| 71 | -}; |
deleted gui/src/components/mainInput/Lump/sections/docs/StatusIndicator.tsx +0 −37
| @@ -1,37 +0,0 @@ | ||
| 1 | -import { IndexingStatus } from "core"; | |
| 2 | -import { ToolTip } from "../../../../gui/Tooltip"; | |
| 3 | - | |
| 4 | -interface StatusIndicatorProps { | |
| 5 | - status?: IndexingStatus["status"]; | |
| 6 | - className?: string; | |
| 7 | - size?: number; | |
| 8 | - hoverMessage?: string; | |
| 9 | -} | |
| 10 | - | |
| 11 | -const STATUS_TO_COLOR: Record<IndexingStatus["status"], string> = { | |
| 12 | - indexing: "bg-yellow-500", | |
| 13 | - paused: "bg-blue-500", | |
| 14 | - complete: "bg-green-500", | |
| 15 | - aborted: "bg-gray-500", | |
| 16 | - pending: "bg-gray-300", | |
| 17 | - failed: "bg-red-500", | |
| 18 | -}; | |
| 19 | - | |
| 20 | -export function StatusIndicator({ | |
| 21 | - status, | |
| 22 | - className = "", | |
| 23 | - size = 2, | |
| 24 | - hoverMessage, | |
| 25 | -}: StatusIndicatorProps) { | |
| 26 | - if (!status) return null; | |
| 27 | - | |
| 28 | - return ( | |
| 29 | - <ToolTip hidden={!hoverMessage} content={hoverMessage}> | |
| 30 | - <div | |
| 31 | - className={`h-${size} w-${size} rounded-full ${STATUS_TO_COLOR[status]} ${ | |
| 32 | - status === "indexing" ? "animate-pulse" : "" | |
| 33 | - } ${className}`} | |
| 34 | - /> | |
| 35 | - </ToolTip> | |
| 36 | - ); | |
| 37 | -} |
deleted gui/src/components/mainInput/Lump/sections/errors/ErrorSection.tsx +0 −70
| @@ -1,70 +0,0 @@ | ||
| 1 | -import { | |
| 2 | - ExclamationCircleIcon, | |
| 3 | - ExclamationTriangleIcon, | |
| 4 | -} from "@heroicons/react/24/outline"; | |
| 5 | -import { useContext } from "react"; | |
| 6 | -import { useAuth } from "../../../../../context/Auth"; | |
| 7 | -import { IdeMessengerContext } from "../../../../../context/IdeMessenger"; | |
| 8 | -import { useAppSelector } from "../../../../../redux/hooks"; | |
| 9 | - | |
| 10 | -export function ErrorSection() { | |
| 11 | - const configError = useAppSelector((state) => state.config.configError); | |
| 12 | - const configLoading = useAppSelector((state) => state.config.loading); | |
| 13 | - const ideMessenger = useContext(IdeMessengerContext); | |
| 14 | - | |
| 15 | - const { refreshProfiles } = useAuth(); | |
| 16 | - | |
| 17 | - const sortedErrors = configError | |
| 18 | - ? [...configError].sort((a, b) => (b.fatal ? 1 : 0) - (a.fatal ? 1 : 0)) | |
| 19 | - : []; | |
| 20 | - | |
| 21 | - return ( | |
| 22 | - <div className="flex flex-col gap-2 p-2"> | |
| 23 | - <div className="flex flex-row items-center justify-end gap-1.5"> | |
| 24 | - <div | |
| 25 | - className={`text-description cursor-pointer text-xs underline transition-all ${configLoading ? "opacity-0" : ""}`} | |
| 26 | - onClick={() => { | |
| 27 | - refreshProfiles("Clicked reload in Error section"); | |
| 28 | - }} | |
| 29 | - > | |
| 30 | - Reload | |
| 31 | - </div> | |
| 32 | - <div | |
| 33 | - onClick={() => { | |
| 34 | - ideMessenger.post( | |
| 35 | - "openUrl", | |
| 36 | - "https://docs.continue.dev/troubleshooting", | |
| 37 | - ); | |
| 38 | - }} | |
| 39 | - className="text-description cursor-pointer text-xs underline" | |
| 40 | - > | |
| 41 | - Help | |
| 42 | - </div> | |
| 43 | - </div> | |
| 44 | - <ul className="m-0 list-none space-y-4 p-0"> | |
| 45 | - {sortedErrors.map((error, index) => ( | |
| 46 | - <li | |
| 47 | - key={index} | |
| 48 | - className={`flex items-start rounded-md p-2 text-sm shadow-md ${ | |
| 49 | - error.fatal | |
| 50 | - ? "bg-red-100 text-red-800" | |
| 51 | - : "bg-yellow-100 text-yellow-800" | |
| 52 | - }`} | |
| 53 | - > | |
| 54 | - {error.fatal ? ( | |
| 55 | - <ExclamationCircleIcon className="mr-2 mt-1 h-3.5 w-3.5 shrink-0" /> | |
| 56 | - ) : ( | |
| 57 | - <ExclamationTriangleIcon className="mr-2 mt-1 h-3.5 w-3.5 shrink-0" /> | |
| 58 | - )} | |
| 59 | - <p | |
| 60 | - className="m-0 whitespace-pre-wrap text-wrap" | |
| 61 | - style={{ wordBreak: "break-word" }} | |
| 62 | - > | |
| 63 | - {error.message} | |
| 64 | - </p> | |
| 65 | - </li> | |
| 66 | - ))} | |
| 67 | - </ul> | |
| 68 | - </div> | |
| 69 | - ); | |
| 70 | -} |
deleted gui/src/components/mainInput/Lump/sections/errors/ErrorsSectionTooltip.tsx +0 −14
| @@ -1,14 +0,0 @@ | ||
| 1 | -import { useAppSelector } from "../../../../../redux/hooks"; | |
| 2 | - | |
| 3 | -export const ErrorsSectionTooltip = () => { | |
| 4 | - const configError = useAppSelector((store) => store.config.configError); | |
| 5 | - | |
| 6 | - const numErrors = configError?.length ?? 0; | |
| 7 | - const plural = numErrors === 1 ? "" : "s"; | |
| 8 | - | |
| 9 | - return ( | |
| 10 | - <div> | |
| 11 | - <span>{`${numErrors} Config Error${plural}`}</span> | |
| 12 | - </div> | |
| 13 | - ); | |
| 14 | -}; |
deleted gui/src/components/mainInput/Lump/sections/mcp/MCPSection.tsx +0 −273
| @@ -1,273 +0,0 @@ | ||
| 1 | -import { ConfigYaml, parseConfigYaml } from "@continuedev/config-yaml"; | |
| 2 | -import { | |
| 3 | - ArrowPathIcon, | |
| 4 | - CircleStackIcon, | |
| 5 | - CommandLineIcon, | |
| 6 | - GlobeAltIcon, | |
| 7 | - InformationCircleIcon, | |
| 8 | - ShieldCheckIcon, | |
| 9 | - ShieldExclamationIcon, | |
| 10 | - WrenchScrewdriverIcon, | |
| 11 | -} from "@heroicons/react/24/outline"; | |
| 12 | -import { MCPServerStatus } from "core"; | |
| 13 | -import { Fragment, useContext, useMemo } from "react"; | |
| 14 | -import { useAuth } from "../../../../../context/Auth"; | |
| 15 | -import { IdeMessengerContext } from "../../../../../context/IdeMessenger"; | |
| 16 | -import { useAppDispatch, useAppSelector } from "../../../../../redux/hooks"; | |
| 17 | -import { updateConfig } from "../../../../../redux/slices/configSlice"; | |
| 18 | -import { selectCurrentOrg } from "../../../../../redux/slices/profilesSlice"; | |
| 19 | -import { fontSize } from "../../../../../util"; | |
| 20 | -import { ToolTip } from "../../../../gui/Tooltip"; | |
| 21 | -import { Button } from "../../../../ui"; | |
| 22 | -import EditBlockButton from "../../EditBlockButton"; | |
| 23 | -import { ExploreBlocksButton } from "../ExploreBlocksButton"; | |
| 24 | - | |
| 25 | -interface MCPServerStatusProps { | |
| 26 | - server: MCPServerStatus; | |
| 27 | - serverFromYaml?: NonNullable<ConfigYaml["mcpServers"]>[number]; | |
| 28 | -} | |
| 29 | -function MCPServerPreview({ server, serverFromYaml }: MCPServerStatusProps) { | |
| 30 | - const ideMessenger = useContext(IdeMessengerContext); | |
| 31 | - const config = useAppSelector((store) => store.config.config); | |
| 32 | - const dispatch = useAppDispatch(); | |
| 33 | - | |
| 34 | - const updateMCPServerStatus = (status: MCPServerStatus["status"]) => { | |
| 35 | - // optimistic config update | |
| 36 | - dispatch( | |
| 37 | - updateConfig({ | |
| 38 | - ...config, | |
| 39 | - mcpServerStatuses: config.mcpServerStatuses.map((s) => | |
| 40 | - s.id === server.id | |
| 41 | - ? { | |
| 42 | - ...s, | |
| 43 | - status, | |
| 44 | - } | |
| 45 | - : s, | |
| 46 | - ), | |
| 47 | - }), | |
| 48 | - ); | |
| 49 | - }; | |
| 50 | - | |
| 51 | - const onAuthenticate = async () => { | |
| 52 | - updateMCPServerStatus("authenticating"); | |
| 53 | - await ideMessenger.request("mcp/startAuthentication", server); | |
| 54 | - }; | |
| 55 | - | |
| 56 | - const onRemoveAuth = async () => { | |
| 57 | - updateMCPServerStatus("authenticating"); | |
| 58 | - await ideMessenger.request("mcp/removeAuthentication", server); | |
| 59 | - }; | |
| 60 | - | |
| 61 | - const onRefresh = async () => { | |
| 62 | - updateMCPServerStatus("connecting"); | |
| 63 | - ideMessenger.post("mcp/reloadServer", { | |
| 64 | - id: server.id, | |
| 65 | - }); | |
| 66 | - }; | |
| 67 | - | |
| 68 | - return ( | |
| 69 | - <div | |
| 70 | - style={{ | |
| 71 | - fontSize: fontSize(-2), | |
| 72 | - }} | |
| 73 | - className={`flex flex-row items-center justify-between gap-3 ${server.status === "authenticating" ? "my-0.5" : ""}`} | |
| 74 | - > | |
| 75 | - <div className="flex flex-row items-center gap-3"> | |
| 76 | - {/* Name and Status */} | |
| 77 | - <span className="m-0 font-semibold">{server.name}</span> | |
| 78 | - | |
| 79 | - {/* Error indicator if any */} | |
| 80 | - {server.errors.length ? ( | |
| 81 | - <ToolTip | |
| 82 | - clickable | |
| 83 | - delayHide={ | |
| 84 | - server.errors.some((error) => error.length > 150) ? 1500 : 0 | |
| 85 | - } | |
| 86 | - className="flex flex-col gap-0.5" | |
| 87 | - content={server.errors.map((error, idx) => ( | |
| 88 | - <Fragment key={idx}> | |
| 89 | - <div> | |
| 90 | - {error.length > 150 ? error.substring(0, 150) + "..." : error} | |
| 91 | - </div> | |
| 92 | - {error.length > 150 && ( | |
| 93 | - <Button | |
| 94 | - className="my-0" | |
| 95 | - size="sm" | |
| 96 | - variant="ghost" | |
| 97 | - onClick={() => | |
| 98 | - void ideMessenger.ide.showVirtualFile(server.name, error) | |
| 99 | - } | |
| 100 | - > | |
| 101 | - View full error | |
| 102 | - </Button> | |
| 103 | - )} | |
| 104 | - </Fragment> | |
| 105 | - ))} | |
| 106 | - > | |
| 107 | - <InformationCircleIcon | |
| 108 | - className={`h-3 w-3 ${server.status === "error" ? "text-red-500" : "text-yellow-500"}`} | |
| 109 | - /> | |
| 110 | - </ToolTip> | |
| 111 | - ) : null} | |
| 112 | - | |
| 113 | - {/* Tools, Prompts, Resources with counts */} | |
| 114 | - <div className="flex flex-row items-center gap-3"> | |
| 115 | - <ToolTip | |
| 116 | - className="flex flex-col gap-0.5" | |
| 117 | - content={ | |
| 118 | - <> | |
| 119 | - {server.tools.map((tool, idx) => ( | |
| 120 | - <code key={idx}>{tool.name}</code> | |
| 121 | - ))} | |
| 122 | - {server.tools.length === 0 && ( | |
| 123 | - <span className="text-lightgray">No tools</span> | |
| 124 | - )} | |
| 125 | - </> | |
| 126 | - } | |
| 127 | - > | |
| 128 | - <div className="flex cursor-zoom-in items-center gap-1 hover:opacity-80"> | |
| 129 | - <WrenchScrewdriverIcon className="h-3 w-3" /> | |
| 130 | - <span className="text-xs">{server.tools.length}</span> | |
| 131 | - </div> | |
| 132 | - </ToolTip> | |
| 133 | - | |
| 134 | - <ToolTip | |
| 135 | - className="flex flex-col gap-0.5" | |
| 136 | - content={ | |
| 137 | - <> | |
| 138 | - {server.prompts.map((prompt, idx) => ( | |
| 139 | - <code key={idx}>{prompt.name}</code> | |
| 140 | - ))} | |
| 141 | - {server.prompts.length === 0 && ( | |
| 142 | - <span className="text-lightgray">No prompts</span> | |
| 143 | - )} | |
| 144 | - </> | |
| 145 | - } | |
| 146 | - > | |
| 147 | - <div className="flex cursor-zoom-in items-center gap-1 hover:opacity-80"> | |
| 148 | - <CommandLineIcon className="h-3 w-3" /> | |
| 149 | - <span className="text-xs">{server.prompts.length}</span> | |
| 150 | - </div> | |
| 151 | - </ToolTip> | |
| 152 | - | |
| 153 | - <ToolTip | |
| 154 | - className="flex flex-col gap-0.5" | |
| 155 | - content={ | |
| 156 | - <> | |
| 157 | - {[...server.resources, ...server.resourceTemplates].map( | |
| 158 | - (resource, idx) => ( | |
| 159 | - <code key={idx}>{resource.name}</code> | |
| 160 | - ), | |
| 161 | - )} | |
| 162 | - {server.resources.length === 0 && ( | |
| 163 | - <span className="text-lightgray">No resources</span> | |
| 164 | - )} | |
| 165 | - </> | |
| 166 | - } | |
| 167 | - > | |
| 168 | - <div className="flex cursor-zoom-in items-center gap-1 hover:opacity-80"> | |
| 169 | - <CircleStackIcon className="h-3 w-3" /> | |
| 170 | - <span className="text-xs"> | |
| 171 | - {server.resources.length + server.resourceTemplates.length} | |
| 172 | - </span> | |
| 173 | - </div> | |
| 174 | - </ToolTip> | |
| 175 | - </div> | |
| 176 | - </div> | |
| 177 | - | |
| 178 | - <div className="flex items-center gap-2"> | |
| 179 | - {server.isProtectedResource && ( | |
| 180 | - <ToolTip | |
| 181 | - place="left" | |
| 182 | - hidden={server.status === "authenticating"} | |
| 183 | - content={server.status === "error" ? "Authenticate" : "Logout"} | |
| 184 | - > | |
| 185 | - <div className="text-lightgray flex cursor-pointer items-center hover:text-white hover:opacity-80"> | |
| 186 | - {server.status === "error" ? ( | |
| 187 | - <ShieldExclamationIcon | |
| 188 | - className="h-3 w-3" | |
| 189 | - onClick={onAuthenticate} | |
| 190 | - /> | |
| 191 | - ) : server.status === "authenticating" ? ( | |
| 192 | - <GlobeAltIcon className="animate-spin-slow h-3 w-3" /> | |
| 193 | - ) : ( | |
| 194 | - <ShieldCheckIcon className="h-3 w-3" onClick={onRemoveAuth} /> | |
| 195 | - )} | |
| 196 | - </div> | |
| 197 | - </ToolTip> | |
| 198 | - )} | |
| 199 | - <EditBlockButton | |
| 200 | - blockType={"mcpServers"} | |
| 201 | - block={serverFromYaml} | |
| 202 | - sourceFile={server.sourceFile} | |
| 203 | - /> | |
| 204 | - <div | |
| 205 | - className="text-lightgray flex cursor-pointer items-center hover:opacity-80" | |
| 206 | - onClick={onRefresh} | |
| 207 | - > | |
| 208 | - <ArrowPathIcon className="h-3 w-3" /> | |
| 209 | - </div> | |
| 210 | - | |
| 211 | - <div | |
| 212 | - className="hidden h-2 w-2 rounded-full sm:flex" | |
| 213 | - style={{ | |
| 214 | - backgroundColor: | |
| 215 | - server.status === "connected" | |
| 216 | - ? "#22c55e" // green-500 | |
| 217 | - : server.status === "connecting" | |
| 218 | - ? "#eab308" // yellow-500 | |
| 219 | - : server.status === "not-connected" | |
| 220 | - ? "#78716c" // stone-500 | |
| 221 | - : "#ef4444", // red-500 for error | |
| 222 | - }} | |
| 223 | - /> | |
| 224 | - </div> | |
| 225 | - </div> | |
| 226 | - ); | |
| 227 | -} | |
| 228 | - | |
| 229 | -function MCPSection() { | |
| 230 | - const currentOrg = useAppSelector(selectCurrentOrg); | |
| 231 | - const servers = useAppSelector( | |
| 232 | - (store) => store.config.config.mcpServerStatuses, | |
| 233 | - ); | |
| 234 | - const { selectedProfile } = useAuth(); | |
| 235 | - const disableMcp = currentOrg?.policy?.allowMcpServers === false; | |
| 236 | - | |
| 237 | - const mergedBlocks = useMemo(() => { | |
| 238 | - const parsed = selectedProfile?.rawYaml | |
| 239 | - ? parseConfigYaml(selectedProfile?.rawYaml ?? "") | |
| 240 | - : undefined; | |
| 241 | - return (servers ?? []).map((doc, index) => ({ | |
| 242 | - block: doc, | |
| 243 | - blockFromYaml: parsed?.mcpServers?.[index], | |
| 244 | - })); | |
| 245 | - }, [servers, selectedProfile]); | |
| 246 | - | |
| 247 | - if (disableMcp) { | |
| 248 | - return ( | |
| 249 | - <div className="flex flex-col items-center justify-center p-2"> | |
| 250 | - <span className="text-description"> | |
| 251 | - MCP servers are disabled in your organization | |
| 252 | - </span> | |
| 253 | - </div> | |
| 254 | - ); | |
| 255 | - } | |
| 256 | - | |
| 257 | - return ( | |
| 258 | - <div className="flex flex-col gap-1"> | |
| 259 | - <div className="flex max-h-[170px] flex-col gap-1 overflow-y-auto overflow-x-hidden pr-2"> | |
| 260 | - {mergedBlocks.map(({ block, blockFromYaml }, idx) => ( | |
| 261 | - <MCPServerPreview | |
| 262 | - key={idx} | |
| 263 | - server={block} | |
| 264 | - serverFromYaml={blockFromYaml} | |
| 265 | - /> | |
| 266 | - ))} | |
| 267 | - </div> | |
| 268 | - <ExploreBlocksButton blockType="mcpServers" /> | |
| 269 | - </div> | |
| 270 | - ); | |
| 271 | -} | |
| 272 | - | |
| 273 | -export default MCPSection; |
deleted gui/src/components/mainInput/Lump/sections/mcp/MCPTooltip.tsx +0 −18
| @@ -1,18 +0,0 @@ | ||
| 1 | -import { useAppSelector } from "../../../../../redux/hooks"; | |
| 2 | - | |
| 3 | -export const McpSectionTooltip = () => { | |
| 4 | - const mcpServers = useAppSelector( | |
| 5 | - (store) => store.config.config.mcpServerStatuses, | |
| 6 | - ); | |
| 7 | - | |
| 8 | - const numServers = mcpServers.length; | |
| 9 | - const numActiveServers = mcpServers.filter( | |
| 10 | - (server) => server.status === "connected", | |
| 11 | - ).length; | |
| 12 | - | |
| 13 | - return ( | |
| 14 | - <div> | |
| 15 | - <span>{`MCP Servers (${numActiveServers}/${numServers} active)`}</span> | |
| 16 | - </div> | |
| 17 | - ); | |
| 18 | -}; |
deleted gui/src/components/mainInput/Lump/sections/tool-policies/ToolPoliciesSection.tsx +0 −110
| @@ -1,110 +0,0 @@ | ||
| 1 | -import { MessageModes, Tool } from "core"; | |
| 2 | -import { useMemo } from "react"; | |
| 3 | -import { useAppDispatch, useAppSelector } from "../../../../../redux/hooks"; | |
| 4 | -import { toggleToolGroupSetting } from "../../../../../redux/slices/uiSlice"; | |
| 5 | -import { fontSize } from "../../../../../util"; | |
| 6 | -import Alert from "../../../../gui/Alert"; | |
| 7 | -import ToggleSwitch from "../../../../gui/Switch"; | |
| 8 | -import ToolPolicyItem from "./ToolPolicyItem"; | |
| 9 | - | |
| 10 | -export const ToolPoliciesSection = () => { | |
| 11 | - const mode = useAppSelector((state) => state.session.mode); | |
| 12 | - const availableTools = useAppSelector((state) => state.config.config.tools); | |
| 13 | - const toolGroupSettings = useAppSelector( | |
| 14 | - (store) => store.ui.toolGroupSettings, | |
| 15 | - ); | |
| 16 | - const dispatch = useAppDispatch(); | |
| 17 | - | |
| 18 | - const toolsByGroup = useMemo(() => { | |
| 19 | - const byGroup: Record<string, Tool[]> = {}; | |
| 20 | - for (const tool of availableTools) { | |
| 21 | - if (!byGroup[tool.group]) { | |
| 22 | - byGroup[tool.group] = []; | |
| 23 | - } | |
| 24 | - byGroup[tool.group].push(tool); | |
| 25 | - } | |
| 26 | - return Object.entries(byGroup); | |
| 27 | - }, [availableTools]); | |
| 28 | - | |
| 29 | - // Detect duplicate tool names | |
| 30 | - const duplicateDetection = useMemo(() => { | |
| 31 | - const counts: Record<string, number> = {}; | |
| 32 | - availableTools.forEach((tool) => { | |
| 33 | - if (counts[tool.function.name]) { | |
| 34 | - counts[tool.function.name] = counts[tool.function.name] + 1; | |
| 35 | - } else { | |
| 36 | - counts[tool.function.name] = 1; | |
| 37 | - } | |
| 38 | - }); | |
| 39 | - return Object.fromEntries( | |
| 40 | - Object.entries(counts).map(([k, v]) => [k, v > 1]), | |
| 41 | - ); | |
| 42 | - }, [availableTools]); | |
| 43 | - | |
| 44 | - const allToolsOff = mode === "chat"; | |
| 45 | - | |
| 46 | - const getMessage = (mode: MessageModes) => { | |
| 47 | - switch (mode) { | |
| 48 | - case "chat": | |
| 49 | - return "All tools disabled in Chat, switch to Plan or Agent mode to use tools"; | |
| 50 | - case "plan": | |
| 51 | - return "Read-only/MCP tools available in Plan mode"; | |
| 52 | - default: | |
| 53 | - return ""; | |
| 54 | - } | |
| 55 | - }; | |
| 56 | - | |
| 57 | - const message = getMessage(mode); | |
| 58 | - | |
| 59 | - return ( | |
| 60 | - <> | |
| 61 | - {(mode === "chat" || mode === "plan") && ( | |
| 62 | - <div className="bg-background sticky top-0 z-10 my-1 mb-3"> | |
| 63 | - <Alert type="info" size="sm"> | |
| 64 | - <span className="text-2xs italic">{message}</span> | |
| 65 | - </Alert> | |
| 66 | - </div> | |
| 67 | - )} | |
| 68 | - {toolsByGroup.length === 0 && ( | |
| 69 | - <span className="text-description text-sm italic"> | |
| 70 | - No tools available | |
| 71 | - </span> | |
| 72 | - )} | |
| 73 | - {toolsByGroup.map(([groupName, tools]) => { | |
| 74 | - const isGroupEnabled = | |
| 75 | - !allToolsOff && toolGroupSettings[groupName] !== "exclude"; | |
| 76 | - return ( | |
| 77 | - <div key={groupName} className="mt-2 flex flex-col pr-1"> | |
| 78 | - <div className="flex flex-row items-center justify-between px-1"> | |
| 79 | - <h3 | |
| 80 | - className="m-0 p-0 font-bold" | |
| 81 | - style={{ | |
| 82 | - fontSize: fontSize(-2), | |
| 83 | - }} | |
| 84 | - > | |
| 85 | - {groupName} | |
| 86 | - </h3> | |
| 87 | - <ToggleSwitch | |
| 88 | - isToggled={isGroupEnabled} | |
| 89 | - onToggle={() => dispatch(toggleToolGroupSetting(groupName))} | |
| 90 | - text="" | |
| 91 | - size={10} | |
| 92 | - disabled={allToolsOff} | |
| 93 | - /> | |
| 94 | - </div> | |
| 95 | - <div className={`relative flex flex-col p-1`}> | |
| 96 | - {tools.map((tool) => ( | |
| 97 | - <ToolPolicyItem | |
| 98 | - key={tool.uri + tool.function.name} | |
| 99 | - tool={tool} | |
| 100 | - duplicatesDetected={duplicateDetection[tool.function.name]} | |
| 101 | - isGroupEnabled={isGroupEnabled} | |
| 102 | - /> | |
| 103 | - ))} | |
| 104 | - </div> | |
| 105 | - </div> | |
| 106 | - ); | |
| 107 | - })} | |
| 108 | - </> | |
| 109 | - ); | |
| 110 | -}; |
deleted gui/src/components/mainInput/Lump/sections/tool-policies/ToolPoliciesSectionTooltip.tsx +0 −16
| @@ -1,16 +0,0 @@ | ||
| 1 | -import { useAppSelector } from "../../../../../redux/hooks"; | |
| 2 | -import { selectActiveTools } from "../../../../../redux/selectors/selectActiveTools"; | |
| 3 | - | |
| 4 | -export const ToolsSectionTooltip = () => { | |
| 5 | - const tools = useAppSelector((store) => store.config.config.tools); | |
| 6 | - const activeTools = useAppSelector(selectActiveTools); | |
| 7 | - | |
| 8 | - const numTools = tools.length; | |
| 9 | - const numActiveTools = activeTools.length; | |
| 10 | - | |
| 11 | - return ( | |
| 12 | - <div> | |
| 13 | - <span>{`Tools (${numActiveTools}/${numTools} active)`}</span> | |
| 14 | - </div> | |
| 15 | - ); | |
| 16 | -}; |
deleted gui/src/components/mainInput/Lump/sections/tool-policies/ToolPolicyItem.tsx +0 −183
| @@ -1,183 +0,0 @@ | ||
| 1 | -import { | |
| 2 | - ChevronRightIcon, | |
| 3 | - InformationCircleIcon, | |
| 4 | -} from "@heroicons/react/24/outline"; | |
| 5 | -import { Tool } from "core"; | |
| 6 | -import { BUILT_IN_GROUP_NAME } from "core/tools/builtIn"; | |
| 7 | -import { useEffect, useMemo, useState } from "react"; | |
| 8 | -import { useDispatch } from "react-redux"; | |
| 9 | -import { Tooltip } from "react-tooltip"; | |
| 10 | -import { useAppSelector } from "../../../../../redux/hooks"; | |
| 11 | -import { | |
| 12 | - addTool, | |
| 13 | - toggleToolSetting, | |
| 14 | -} from "../../../../../redux/slices/uiSlice"; | |
| 15 | -import { ToolTip } from "../../../../gui/Tooltip"; | |
| 16 | -import { useFontSize } from "../../../../ui/font"; | |
| 17 | - | |
| 18 | -interface ToolDropdownItemProps { | |
| 19 | - tool: Tool; | |
| 20 | - duplicatesDetected: boolean; | |
| 21 | - isGroupEnabled: boolean; | |
| 22 | -} | |
| 23 | - | |
| 24 | -function ToolPolicyItem(props: ToolDropdownItemProps) { | |
| 25 | - const dispatch = useDispatch(); | |
| 26 | - const policy = useAppSelector( | |
| 27 | - (state) => state.ui.toolSettings[props.tool.function.name], | |
| 28 | - ); | |
| 29 | - const [isExpanded, setIsExpanded] = useState(false); | |
| 30 | - const mode = useAppSelector((state) => state.session.mode); | |
| 31 | - | |
| 32 | - useEffect(() => { | |
| 33 | - if (!policy) { | |
| 34 | - dispatch(addTool(props.tool)); | |
| 35 | - } | |
| 36 | - }, [props.tool.function.name, policy]); | |
| 37 | - | |
| 38 | - const parameters = useMemo(() => { | |
| 39 | - if (props.tool.function.parameters?.properties) { | |
| 40 | - return Object.entries(props.tool.function.parameters.properties).map( | |
| 41 | - ([name, schema]) => | |
| 42 | - [name, schema] as [string, { description: string; type: string }], | |
| 43 | - ); | |
| 44 | - } | |
| 45 | - return undefined; | |
| 46 | - }, [props.tool.function.parameters]); | |
| 47 | - | |
| 48 | - const fontSize = useFontSize(-2); | |
| 49 | - | |
| 50 | - const disabled = | |
| 51 | - !props.isGroupEnabled || | |
| 52 | - (mode === "plan" && | |
| 53 | - props.tool.group === BUILT_IN_GROUP_NAME && | |
| 54 | - !props.tool.readonly); | |
| 55 | - | |
| 56 | - if (!policy) { | |
| 57 | - return null; | |
| 58 | - } | |
| 59 | - const disabledTooltipId = `disabled-note-${props.tool.function.name}`; | |
| 60 | - | |
| 61 | - return ( | |
| 62 | - <div | |
| 63 | - className="flex flex-col" | |
| 64 | - style={{ | |
| 65 | - fontSize, | |
| 66 | - }} | |
| 67 | - > | |
| 68 | - <div className="flex flex-row items-center"> | |
| 69 | - <div | |
| 70 | - className={`hover:bg-badge hover:text-list-active-foreground xs:gap-1.5 flex flex-1 cursor-pointer flex-row items-center gap-1 rounded py-0.5 pl-1 pr-2`} | |
| 71 | - onClick={() => setIsExpanded((val) => !val)} | |
| 72 | - > | |
| 73 | - <ChevronRightIcon | |
| 74 | - className={`xs:flex hidden h-3 w-3 flex-shrink-0 transition-all duration-200 ${isExpanded ? "rotate-90" : ""}`} | |
| 75 | - /> | |
| 76 | - | |
| 77 | - <div | |
| 78 | - className={`flex items-center gap-1 rounded-md`} | |
| 79 | - style={{ | |
| 80 | - fontSize, | |
| 81 | - }} | |
| 82 | - > | |
| 83 | - {props.duplicatesDetected ? ( | |
| 84 | - <ToolTip | |
| 85 | - place="bottom" | |
| 86 | - className="flex flex-wrap items-center" | |
| 87 | - content={ | |
| 88 | - <p className="m-0 p-0"> | |
| 89 | - <span>Duplicate tool name</span>{" "} | |
| 90 | - <code>{props.tool.function.name}</code>{" "} | |
| 91 | - <span> | |
| 92 | - detected. Permissions will conflict and usage may be | |
| 93 | - unpredictable | |
| 94 | - </span> | |
| 95 | - </p> | |
| 96 | - } | |
| 97 | - > | |
| 98 | - <InformationCircleIcon className="h-3 w-3 flex-shrink-0 cursor-help text-yellow-500" /> | |
| 99 | - </ToolTip> | |
| 100 | - ) : null} | |
| 101 | - {props.tool.faviconUrl && ( | |
| 102 | - <img | |
| 103 | - src={props.tool.faviconUrl} | |
| 104 | - alt={props.tool.displayTitle} | |
| 105 | - className="h-3 w-3 flex-shrink-0" | |
| 106 | - /> | |
| 107 | - )} | |
| 108 | - <span className="line-clamp-1 break-all"> | |
| 109 | - {props.tool.originalFunctionName ?? props.tool.function.name} | |
| 110 | - </span> | |
| 111 | - </div> | |
| 112 | - </div> | |
| 113 | - | |
| 114 | - <div | |
| 115 | - className={`flex w-8 select-none flex-row items-center justify-end gap-2 px-2 py-0.5 sm:w-16 ${disabled ? "cursor-not-allowed" : "hover:text-list-active-foreground cursor-pointer hover:brightness-125"}`} | |
| 116 | - data-testid={`tool-policy-item-${props.tool.function.name}`} | |
| 117 | - data-tooltip-id={disabled ? disabledTooltipId : undefined} | |
| 118 | - onClick={ | |
| 119 | - disabled | |
| 120 | - ? undefined | |
| 121 | - : (e) => { | |
| 122 | - dispatch(toggleToolSetting(props.tool.function.name)); | |
| 123 | - e.stopPropagation(); | |
| 124 | - e.preventDefault(); | |
| 125 | - } | |
| 126 | - } | |
| 127 | - > | |
| 128 | - {disabled || policy === "disabled" ? ( | |
| 129 | - <> | |
| 130 | - <span className="text-lightgray sm:hidden">Off</span> | |
| 131 | - <span className="text-lightgray hidden sm:inline-block"> | |
| 132 | - Excluded | |
| 133 | - </span> | |
| 134 | - </> | |
| 135 | - ) : policy === "allowedWithoutPermission" ? ( | |
| 136 | - <> | |
| 137 | - <span className="text-success sm:hidden">Auto</span> | |
| 138 | - <span className="text-success hidden sm:inline-block"> | |
| 139 | - Automatic | |
| 140 | - </span> | |
| 141 | - </> | |
| 142 | - ) : ( | |
| 143 | - // allowedWithPermission | |
| 144 | - <> | |
| 145 | - <span className="text-warning sm:hidden">Ask</span> | |
| 146 | - <span className="text-warning hidden sm:inline-block"> | |
| 147 | - Ask First | |
| 148 | - </span> | |
| 149 | - </> | |
| 150 | - )} | |
| 151 | - </div> | |
| 152 | - <Tooltip id={disabledTooltipId}> | |
| 153 | - {mode === "chat" | |
| 154 | - ? "Tool disabled in chat mode" | |
| 155 | - : !props.isGroupEnabled | |
| 156 | - ? "Group is turned off" | |
| 157 | - : "Tool disabled in plan mode"} | |
| 158 | - </Tooltip> | |
| 159 | - </div> | |
| 160 | - <div | |
| 161 | - className={`flex flex-col overflow-hidden ${isExpanded ? "h-min" : "h-0 opacity-0"} gap-x-1 gap-y-2 pl-2 transition-all`} | |
| 162 | - > | |
| 163 | - <span className="mt-1.5 text-xs font-bold">Description:</span> | |
| 164 | - <span className="italic">{props.tool.function.description}</span> | |
| 165 | - {parameters ? ( | |
| 166 | - <> | |
| 167 | - <span className="text-xs font-bold">Arguments:</span> | |
| 168 | - {parameters.map((param, idx) => ( | |
| 169 | - <div key={idx} className="block"> | |
| 170 | - <code className="">{param[0]}</code> | |
| 171 | - <span className="ml-1">{`(${param[1].type}):`}</span> | |
| 172 | - <span className="ml-1 italic">{param[1].description}</span> | |
| 173 | - </div> | |
| 174 | - ))} | |
| 175 | - </> | |
| 176 | - ) : null} | |
| 177 | - <div className="h-1"></div> | |
| 178 | - </div> | |
| 179 | - </div> | |
| 180 | - ); | |
| 181 | -} | |
| 182 | - | |
| 183 | -export default ToolPolicyItem; |
modified gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts +5 −2
| @@ -208,10 +208,13 @@ | ||
| 208 | 208 | }, |
| 209 | 209 | |
| 210 | 210 | "Mod-Enter": () => { |
| 211 | + posthog.capture("gui_use_active_file_enter"); | |
| 212 | + | |
| 211 | 213 | onEnterRef.current({ |
| 212 | - useCodebase: true, | |
| 213 | - noContext: !useActiveFile, | |
| 214 | + useCodebase: false, | |
| 215 | + noContext: !!useActiveFile, | |
| 214 | 216 | }); |
| 217 | + | |
| 215 | 218 | return true; |
| 216 | 219 | }, |
| 217 | 220 | "Alt-Enter": () => { |
modified gui/src/components/mainInput/TipTapEditor/utils/resolveEditorContent.ts +1 −1
| @@ -196,7 +196,7 @@ | ||
| 196 | 196 | ); |
| 197 | 197 | if (currentFileResponse.status === "success") { |
| 198 | 198 | const currentFile = currentFileResponse.content[0]; |
| 199 | - if (currentFile.uri?.value) { | |
| 199 | + if (currentFile?.uri?.value) { | |
| 200 | 200 | currentFile.id = { |
| 201 | 201 | providerTitle: "file", |
| 202 | 202 | itemId: currentFile.uri.value, |
modified gui/src/components/modelSelection/ModelSelect.tsx +58 −42
| @@ -7,23 +7,23 @@ | ||
| 7 | 7 | PlusIcon, |
| 8 | 8 | } from "@heroicons/react/24/outline"; |
| 9 | 9 | import { useContext, useEffect, useRef, useState } from "react"; |
| 10 | +import { useNavigate } from "react-router-dom"; | |
| 10 | 11 | import { useAuth } from "../../context/Auth"; |
| 11 | 12 | import { IdeMessengerContext } from "../../context/IdeMessenger"; |
| 12 | 13 | import { AddModelForm } from "../../forms/AddModelForm"; |
| 13 | 14 | import { useAppDispatch, useAppSelector } from "../../redux/hooks"; |
| 14 | 15 | import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; |
| 15 | 16 | import { updateSelectedModelByRole } from "../../redux/thunks/updateSelectedModelByRole"; |
| 16 | -import { | |
| 17 | - fontSize, | |
| 18 | - getMetaKeyLabel, | |
| 19 | - isMetaEquivalentKeyPressed, | |
| 20 | -} from "../../util"; | |
| 17 | +import { getMetaKeyLabel, isMetaEquivalentKeyPressed } from "../../util"; | |
| 18 | +import { CONFIG_ROUTES } from "../../util/navigation"; | |
| 21 | 19 | import { |
| 22 | 20 | Listbox, |
| 23 | 21 | ListboxButton, |
| 24 | 22 | ListboxOption, |
| 25 | 23 | ListboxOptions, |
| 26 | -} from "../ui/Listbox"; | |
| 24 | + useFontSize, | |
| 25 | +} from "../ui"; | |
| 26 | +import { Divider } from "../ui/Divider"; | |
| 27 | 27 | |
| 28 | 28 | interface ModelOptionProps { |
| 29 | 29 | option: Option; |
| @@ -71,8 +71,8 @@ | ||
| 71 | 71 | value={option.value} |
| 72 | 72 | onClick={handleOptionClick} |
| 73 | 73 | > |
| 74 | - <div className="flex w-full items-center justify-between"> | |
| 75 | - <div className="flex items-center gap-2"> | |
| 74 | + <div className="flex w-full items-center justify-between gap-5"> | |
| 75 | + <div className="flex items-center gap-2 py-0.5"> | |
| 76 | 76 | <CubeIcon className="h-3 w-3 flex-shrink-0" /> |
| 77 | 77 | <span className="line-clamp-1"> |
| 78 | 78 | {option.title} |
| @@ -98,6 +98,7 @@ | ||
| 98 | 98 | |
| 99 | 99 | function ModelSelect() { |
| 100 | 100 | const dispatch = useAppDispatch(); |
| 101 | + const navigate = useNavigate(); | |
| 101 | 102 | |
| 102 | 103 | const isInEdit = useAppSelector((store) => store.session.isInEdit); |
| 103 | 104 | const config = useAppSelector((state) => state.config.config); |
| @@ -107,6 +108,7 @@ | ||
| 107 | 108 | const [options, setOptions] = useState<Option[]>([]); |
| 108 | 109 | const [sortedOptions, setSortedOptions] = useState<Option[]>([]); |
| 109 | 110 | const { selectedProfile } = useAuth(); |
| 111 | + const tinyFont = useFontSize(-4); | |
| 110 | 112 | |
| 111 | 113 | let selectedModel = null; |
| 112 | 114 | let allModels = null; |
| @@ -201,6 +203,18 @@ | ||
| 201 | 203 | ); |
| 202 | 204 | } |
| 203 | 205 | |
| 206 | + function onClickConfigureModels(e: React.MouseEvent) { | |
| 207 | + e.stopPropagation(); | |
| 208 | + e.preventDefault(); | |
| 209 | + | |
| 210 | + // Close the dropdown | |
| 211 | + if (buttonRef.current) { | |
| 212 | + buttonRef.current.click(); | |
| 213 | + } | |
| 214 | + | |
| 215 | + navigate(CONFIG_ROUTES.MODELS); | |
| 216 | + } | |
| 217 | + | |
| 204 | 218 | const hasNoModels = allModels?.length === 0; |
| 205 | 219 | |
| 206 | 220 | return ( |
| @@ -232,16 +246,7 @@ | ||
| 232 | 246 | </ListboxButton> |
| 233 | 247 | <ListboxOptions className="min-w-[160px]"> |
| 234 | 248 | <div className="flex items-center justify-between gap-1 px-2 py-1"> |
| 235 | - <span className="font-semibold">Models</span> | |
| 236 | - <Cog6ToothIcon | |
| 237 | - className="text-description h-3 w-3 cursor-pointer hover:brightness-125" | |
| 238 | - onClick={() => | |
| 239 | - ideMessenger.post("config/openProfile", { | |
| 240 | - profileId: undefined, | |
| 241 | - element: { sourceFile: selectedModel?.sourceFile }, | |
| 242 | - }) | |
| 243 | - } | |
| 244 | - /> | |
| 249 | + <span className="text-description font-semibold">Models</span> | |
| 245 | 250 | </div> |
| 246 | 251 | |
| 247 | 252 | <div className="no-scrollbar max-h-[300px] overflow-y-auto"> |
| @@ -267,32 +272,43 @@ | ||
| 267 | 272 | )} |
| 268 | 273 | </div> |
| 269 | 274 | |
| 270 | - {!isConfigLoading && selectedProfile?.profileType === "local" && ( | |
| 271 | - <ListboxOption | |
| 272 | - key={options.length} | |
| 273 | - onClick={onClickAddModel} | |
| 274 | - value={"addModel" as any} | |
| 275 | - className="border-border border-x-0 border-y border-solid" | |
| 276 | - > | |
| 277 | - <div | |
| 278 | - className="text-description flex items-center py-0.5 hover:text-inherit" | |
| 279 | - style={{ | |
| 280 | - fontSize: fontSize(-3), | |
| 281 | - }} | |
| 275 | + {!isConfigLoading && ( | |
| 276 | + <> | |
| 277 | + <Divider className="!mb-0" /> | |
| 278 | + | |
| 279 | + {selectedProfile?.profileType === "local" && ( | |
| 280 | + <ListboxOption | |
| 281 | + key={options.length} | |
| 282 | + onClick={onClickAddModel} | |
| 283 | + value={"addModel" as any} | |
| 284 | + fontSizeModifier={-2} | |
| 285 | + className="px-2 py-2" | |
| 286 | + > | |
| 287 | + <span className="text-description text-2xs flex flex-row items-center"> | |
| 288 | + <PlusIcon className="mr-1.5 h-3.5 w-3.5" /> | |
| 289 | + Add Chat model | |
| 290 | + </span> | |
| 291 | + </ListboxOption> | |
| 292 | + )} | |
| 293 | + | |
| 294 | + <ListboxOption | |
| 295 | + value="configure-models" | |
| 296 | + fontSizeModifier={-2} | |
| 297 | + className="px-2 py-2" | |
| 298 | + onClick={onClickConfigureModels} | |
| 282 | 299 | > |
| 283 | - <PlusIcon className="mr-2 h-3 w-3" /> | |
| 284 | - Add Chat model | |
| 300 | + <span className="text-description text-2xs flex flex-row items-center"> | |
| 301 | + <Cog6ToothIcon className="mr-1.5 h-3.5 w-3.5" /> | |
| 302 | + Configure models | |
| 303 | + </span> | |
| 304 | + </ListboxOption> | |
| 305 | + <Divider className="!my-0" /> | |
| 306 | + <div className="text-description flex items-center justify-between gap-1.5 px-2 py-2"> | |
| 307 | + <span className="block" style={{ fontSize: tinyFont }}> | |
| 308 | + <code>{getMetaKeyLabel()}'</code> to toggle model | |
| 309 | + </span> | |
| 285 | 310 | </div> |
| 286 | - </ListboxOption> | |
| 287 | - )} | |
| 288 | - | |
| 289 | - {!isConfigLoading && ( | |
| 290 | - <div | |
| 291 | - className="text-description-muted px-2 py-1" | |
| 292 | - style={{ fontSize: fontSize(-3) }} | |
| 293 | - > | |
| 294 | - <code>{getMetaKeyLabel()}'</code> to toggle model | |
| 295 | - </div> | |
| 311 | + </> | |
| 296 | 312 | )} |
| 297 | 313 | </ListboxOptions> |
| 298 | 314 | </div> |
added gui/src/components/svg/BotIcon.tsx +24 −0
| @@ -0,0 +1,24 @@ | ||
| 1 | +interface BotIconProps extends React.SVGProps<SVGSVGElement> { | |
| 2 | + size?: number; | |
| 3 | +} | |
| 4 | + | |
| 5 | +export function BotIcon({ size = 24, className, ...props }: BotIconProps) { | |
| 6 | + return ( | |
| 7 | + <svg | |
| 8 | + width={size} | |
| 9 | + height={size} | |
| 10 | + viewBox="0 0 24 24" | |
| 11 | + fill="none" | |
| 12 | + stroke="currentColor" | |
| 13 | + strokeLinecap="round" | |
| 14 | + strokeLinejoin="round" | |
| 15 | + strokeWidth="2" | |
| 16 | + className={className} | |
| 17 | + {...props} | |
| 18 | + > | |
| 19 | + <path d="M12 8V4H8" /> | |
| 20 | + <rect width="16" height="12" x="4" y="8" rx="2" /> | |
| 21 | + <path d="M2 14h2m16 0h2m-7-1v2m-6-2v2" /> | |
| 22 | + </svg> | |
| 23 | + ); | |
| 24 | +} |
modified gui/src/components/ui/Button.tsx +13 −4
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | import * as React from "react"; |
| 2 | 2 | import { cn } from "../../util/cn"; |
| 3 | 3 | |
| 4 | -type ButtonVariant = "ghost" | "primary" | "secondary" | "outline"; | |
| 4 | +type ButtonVariant = "ghost" | "primary" | "secondary" | "outline" | "icon"; | |
| 5 | 5 | type ButtonSize = "sm" | "lg"; |
| 6 | 6 | |
| 7 | 7 | type ButtonProps = React.ComponentProps<"button"> & { |
| @@ -15,9 +15,10 @@ | ||
| 15 | 15 | secondary: |
| 16 | 16 | "border-none text-foreground bg-border hover:enabled:brightness-125", |
| 17 | 17 | outline: |
| 18 | - "border border-solid border-badge border-border text-foreground bg-transparent hover:enabled:bg-input", | |
| 18 | + "border border-solid border-description text-foreground bg-transparent hover:enabled:bg-input", | |
| 19 | 19 | ghost: |
| 20 | 20 | "border-none text-foreground bg-inherit hover:enabled:brightness-125 hover:enabled:bg-input", |
| 21 | + icon: "border border-solid border-description text-description bg-transparent hover:enabled:text-foreground hover:enabled:bg-input hover:enabled:border-description rounded-full p-0 flex items-center justify-center", | |
| 21 | 22 | }; |
| 22 | 23 | |
| 23 | 24 | const buttonSizes = { |
| @@ -25,17 +26,25 @@ | ||
| 25 | 26 | lg: "px-2 py-1 text-sm", |
| 26 | 27 | }; |
| 27 | 28 | |
| 29 | +const iconButtonSizes = { | |
| 30 | + sm: "h-4 w-4", | |
| 31 | + lg: "h-5 w-5", | |
| 32 | +}; | |
| 33 | + | |
| 28 | 34 | const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( |
| 29 | 35 | ({ variant = "primary", size = "lg", className, ...props }, ref) => { |
| 36 | + const isIcon = variant === "icon"; | |
| 30 | 37 | return ( |
| 31 | 38 | <button |
| 32 | 39 | ref={ref} |
| 33 | 40 | className={cn( |
| 34 | - "my-1.5 cursor-pointer rounded transition-all duration-200", | |
| 41 | + "cursor-pointer transition-all duration-200", | |
| 35 | 42 | "hover:enabled:cursor-pointer", |
| 36 | 43 | "disabled:text-description-muted disabled:pointer-events-none disabled:opacity-50", |
| 37 | 44 | buttonVariants[variant], |
| 38 | - buttonSizes[size], | |
| 45 | + isIcon | |
| 46 | + ? iconButtonSizes[size] | |
| 47 | + : `my-1.5 rounded ${buttonSizes[size]}`, | |
| 39 | 48 | className, |
| 40 | 49 | )} |
| 41 | 50 | style={{ |
added gui/src/components/ui/Card.tsx +14 −0
| @@ -0,0 +1,14 @@ | ||
| 1 | +interface CardProps extends React.ComponentProps<"div"> { | |
| 2 | + children: React.ReactNode; | |
| 3 | +} | |
| 4 | + | |
| 5 | +export function Card({ children, className = "", ...props }: CardProps) { | |
| 6 | + return ( | |
| 7 | + <div | |
| 8 | + className={`bg-editor rounded-default space-y-0 px-4 py-3 ${className}`} | |
| 9 | + {...props} | |
| 10 | + > | |
| 11 | + {children} | |
| 12 | + </div> | |
| 13 | + ); | |
| 14 | +} |
added gui/src/components/ui/Divider.tsx +11 −0
| @@ -0,0 +1,11 @@ | ||
| 1 | +interface DividerProps { | |
| 2 | + className?: string; | |
| 3 | +} | |
| 4 | + | |
| 5 | +export function Divider({ className }: DividerProps) { | |
| 6 | + return ( | |
| 7 | + <div | |
| 8 | + className={`border-command-border my-2 border-[0.5px] border-b border-solid opacity-20 ${className || ""}`} | |
| 9 | + /> | |
| 10 | + ); | |
| 11 | +} |
added gui/src/components/ui/EmptyState.tsx +11 −0
| @@ -0,0 +1,11 @@ | ||
| 1 | +interface EmptyStateProps { | |
| 2 | + message: string; | |
| 3 | +} | |
| 4 | + | |
| 5 | +export function EmptyState({ message }: EmptyStateProps) { | |
| 6 | + return ( | |
| 7 | + <div className="flex flex-col items-center justify-center p-1"> | |
| 8 | + <span className="text-description text-sm">{message}</span> | |
| 9 | + </div> | |
| 10 | + ); | |
| 11 | +} |
added gui/src/components/ui/TabButton.tsx +34 −0
| @@ -0,0 +1,34 @@ | ||
| 1 | +import { ToolTip } from "../gui/Tooltip"; | |
| 2 | + | |
| 3 | +interface TabButtonProps { | |
| 4 | + label: string; | |
| 5 | + icon: React.ReactNode; | |
| 6 | + isActive: boolean; | |
| 7 | + onClick: () => void; | |
| 8 | + tabId?: string; | |
| 9 | +} | |
| 10 | + | |
| 11 | +export function TabButton({ | |
| 12 | + label, | |
| 13 | + icon, | |
| 14 | + isActive, | |
| 15 | + onClick, | |
| 16 | + tabId, | |
| 17 | +}: TabButtonProps) { | |
| 18 | + return ( | |
| 19 | + <ToolTip content={label} place="right" className="text-xs md:!hidden"> | |
| 20 | + <div | |
| 21 | + className={`flex cursor-pointer items-center justify-center gap-1.5 rounded-md hover:brightness-125 md:justify-start ${ | |
| 22 | + isActive | |
| 23 | + ? "bg-vsc-input-background px-2 py-2" | |
| 24 | + : "text-description px-2 py-2" | |
| 25 | + }`} | |
| 26 | + onClick={onClick} | |
| 27 | + data-testid={tabId ? `tab-${tabId}` : undefined} | |
| 28 | + > | |
| 29 | + {icon} | |
| 30 | + <span className="text-description hidden md:inline">{label}</span> | |
| 31 | + </div> | |
| 32 | + </ToolTip> | |
| 33 | + ); | |
| 34 | +} |
added gui/src/components/ui/TabGroup.tsx +53 −0
| @@ -0,0 +1,53 @@ | ||
| 1 | +import { Divider } from "./Divider"; | |
| 2 | +import { TabButton } from "./TabButton"; | |
| 3 | + | |
| 4 | +interface TabOption { | |
| 5 | + id: string; | |
| 6 | + label: string; | |
| 7 | + component: React.ReactNode; | |
| 8 | + icon: React.ReactNode; | |
| 9 | +} | |
| 10 | + | |
| 11 | +interface TabGroupProps { | |
| 12 | + tabs: TabOption[]; | |
| 13 | + activeTab: string; | |
| 14 | + onTabClick: (tabId: string) => void; | |
| 15 | + label?: string; | |
| 16 | + showTopDivider?: boolean; | |
| 17 | + showBottomDivider?: boolean; | |
| 18 | + className?: string; | |
| 19 | +} | |
| 20 | + | |
| 21 | +export function TabGroup({ | |
| 22 | + tabs, | |
| 23 | + activeTab, | |
| 24 | + onTabClick, | |
| 25 | + label, | |
| 26 | + showTopDivider = false, | |
| 27 | + showBottomDivider = false, | |
| 28 | + className = "", | |
| 29 | +}: TabGroupProps) { | |
| 30 | + return ( | |
| 31 | + <div className={className}> | |
| 32 | + {showTopDivider && <Divider />} | |
| 33 | + | |
| 34 | + {label && ( | |
| 35 | + <div className="text-description-muted text-2xs mb-1 ml-1.5 hidden font-medium md:block md:pt-1"> | |
| 36 | + {label} | |
| 37 | + </div> | |
| 38 | + )} | |
| 39 | + | |
| 40 | + {tabs.map((tab) => ( | |
| 41 | + <TabButton | |
| 42 | + key={tab.id} | |
| 43 | + label={tab.label} | |
| 44 | + icon={tab.icon} | |
| 45 | + isActive={activeTab === tab.id} | |
| 46 | + onClick={() => onTabClick(tab.id)} | |
| 47 | + /> | |
| 48 | + ))} | |
| 49 | + | |
| 50 | + {showBottomDivider && <Divider />} | |
| 51 | + </div> | |
| 52 | + ); | |
| 53 | +} |
added gui/src/components/ui/Toggle.tsx +47 −0
| @@ -0,0 +1,47 @@ | ||
| 1 | +import { ChevronRightIcon } from "@heroicons/react/24/outline"; | |
| 2 | + | |
| 3 | +interface ToggleProps { | |
| 4 | + isOpen: boolean; | |
| 5 | + onToggle: () => void; | |
| 6 | + title: string; | |
| 7 | + subtitle?: string; | |
| 8 | + children: React.ReactNode; | |
| 9 | +} | |
| 10 | + | |
| 11 | +export function Toggle({ | |
| 12 | + isOpen, | |
| 13 | + onToggle, | |
| 14 | + title, | |
| 15 | + subtitle, | |
| 16 | + children, | |
| 17 | +}: ToggleProps) { | |
| 18 | + return ( | |
| 19 | + <div> | |
| 20 | + <div | |
| 21 | + className="flex cursor-pointer items-start gap-2 text-left text-sm font-semibold" | |
| 22 | + onClick={onToggle} | |
| 23 | + > | |
| 24 | + <ChevronRightIcon | |
| 25 | + className={`mt-0.5 h-4 w-4 transition-transform ${ | |
| 26 | + isOpen ? "rotate-90" : "" | |
| 27 | + }`} | |
| 28 | + /> | |
| 29 | + <div> | |
| 30 | + <span>{title}</span> | |
| 31 | + {subtitle && ( | |
| 32 | + <p className="text-description my-1 text-xs font-normal"> | |
| 33 | + {subtitle} | |
| 34 | + </p> | |
| 35 | + )} | |
| 36 | + </div> | |
| 37 | + </div> | |
| 38 | + <div | |
| 39 | + className={`duration-400 overflow-hidden transition-all ease-in-out ${ | |
| 40 | + isOpen ? "mt-4 max-h-screen" : "max-h-0" | |
| 41 | + }`} | |
| 42 | + > | |
| 43 | + <div className="pl-6">{children}</div> | |
| 44 | + </div> | |
| 45 | + </div> | |
| 46 | + ); | |
| 47 | +} |
modified gui/src/components/ui/index.ts +4 −0
| @@ -1,4 +1,7 @@ | ||
| 1 | 1 | export { Button } from "./Button"; |
| 2 | +export { Card } from "./Card"; | |
| 3 | +export { Divider } from "./Divider"; | |
| 4 | +export { EmptyState } from "./EmptyState"; | |
| 2 | 5 | export { useFontSize } from "./font"; |
| 3 | 6 | export { |
| 4 | 7 | Listbox, |
| @@ -7,4 +10,5 @@ | ||
| 7 | 10 | ListboxOptions, |
| 8 | 11 | } from "./Listbox"; |
| 9 | 12 | export { Popover, PopoverButton, PopoverPanel } from "./Popover"; |
| 13 | +export { Toggle } from "./Toggle"; | |
| 10 | 14 | export { Transition } from "./Transition"; |
modified gui/src/context/MockIdeMessenger.ts +15 −0
| @@ -89,6 +89,21 @@ | ||
| 89 | 89 | didPrune: false, |
| 90 | 90 | contextPercentage: 0.5, |
| 91 | 91 | }, |
| 92 | + "context/getContextItems": [ | |
| 93 | + { | |
| 94 | + id: { | |
| 95 | + providerTitle: "mock", | |
| 96 | + itemId: "mock", | |
| 97 | + }, | |
| 98 | + content: "Mock current file content", | |
| 99 | + name: "Mock File", | |
| 100 | + description: "Mock file for testing", | |
| 101 | + uri: { | |
| 102 | + type: "file", | |
| 103 | + value: "file:///Users/test/mock-file.ts", | |
| 104 | + }, | |
| 105 | + }, | |
| 106 | + ], | |
| 92 | 107 | }; |
| 93 | 108 | |
| 94 | 109 | const DEFAULT_CHAT_RESPONSE: ChatMessage[] = [ |
deleted gui/src/pages/config/AccountButton.tsx +0 −82
| @@ -1,82 +0,0 @@ | ||
| 1 | -import { UserCircleIcon } from "@heroicons/react/24/solid"; | |
| 2 | -import { isOnPremSession } from "core/control-plane/AuthTypes"; | |
| 3 | -import { ScopeSelect } from "../../components/AssistantAndOrgListbox/ScopeSelect"; | |
| 4 | -import { | |
| 5 | - Button, | |
| 6 | - Popover, | |
| 7 | - PopoverButton, | |
| 8 | - PopoverPanel, | |
| 9 | - Transition, | |
| 10 | -} from "../../components/ui"; | |
| 11 | -import { useAuth } from "../../context/Auth"; | |
| 12 | -import { useAppSelector } from "../../redux/hooks"; | |
| 13 | -import { selectCurrentOrg } from "../../redux/slices/profilesSlice"; | |
| 14 | - | |
| 15 | -export function AccountButton() { | |
| 16 | - const { session, logout, login, organizations } = useAuth(); | |
| 17 | - const selectedOrg = useAppSelector(selectCurrentOrg); | |
| 18 | - | |
| 19 | - if (!session) { | |
| 20 | - return ( | |
| 21 | - <Button | |
| 22 | - variant="outline" | |
| 23 | - className="mb-1 whitespace-nowrap py-1" | |
| 24 | - onClick={() => login(false)} | |
| 25 | - > | |
| 26 | - Sign in | |
| 27 | - </Button> | |
| 28 | - ); | |
| 29 | - } | |
| 30 | - | |
| 31 | - // No login button for on-prem deployments | |
| 32 | - if (isOnPremSession(session)) { | |
| 33 | - return null; | |
| 34 | - } | |
| 35 | - | |
| 36 | - return ( | |
| 37 | - <Popover className="relative"> | |
| 38 | - {({ close }) => ( | |
| 39 | - <> | |
| 40 | - <PopoverButton className="bg-vsc-background hover:bg-vsc-input-background text-vsc-foreground my-0.5 flex cursor-pointer rounded-md border-none px-2"> | |
| 41 | - <div className="flex items-center gap-1.5"> | |
| 42 | - <span className="font-medium"> | |
| 43 | - {selectedOrg === null ? "Personal" : selectedOrg.name} | |
| 44 | - </span> | |
| 45 | - <UserCircleIcon className="h-6 w-6" /> | |
| 46 | - </div> | |
| 47 | - </PopoverButton> | |
| 48 | - | |
| 49 | - <Transition> | |
| 50 | - <PopoverPanel className="bg-vsc-input-background xs:p-4 absolute right-0 mt-1 rounded-md border border-zinc-700 p-2 shadow-lg"> | |
| 51 | - <div className="flex flex-col gap-3"> | |
| 52 | - <div className="flex flex-col"> | |
| 53 | - <span className="font-medium">{session.account.label}</span> | |
| 54 | - <span className="text-lightgray text-sm"> | |
| 55 | - {session.account.id} | |
| 56 | - </span> | |
| 57 | - </div> | |
| 58 | - | |
| 59 | - {organizations.length > 0 && ( | |
| 60 | - <div className="flex flex-col gap-1"> | |
| 61 | - <label className="text-vsc-foreground text-xs"> | |
| 62 | - Organization | |
| 63 | - </label> | |
| 64 | - <ScopeSelect onSelect={close} /> | |
| 65 | - </div> | |
| 66 | - )} | |
| 67 | - | |
| 68 | - <Button | |
| 69 | - variant="ghost" | |
| 70 | - onClick={logout} | |
| 71 | - className="!mx-0 w-full" | |
| 72 | - > | |
| 73 | - Sign out | |
| 74 | - </Button> | |
| 75 | - </div> | |
| 76 | - </PopoverPanel> | |
| 77 | - </Transition> | |
| 78 | - </> | |
| 79 | - )} | |
| 80 | - </Popover> | |
| 81 | - ); | |
| 82 | -} |
deleted gui/src/pages/config/ConfigItemSelect.tsx +0 −91
| @@ -1,91 +0,0 @@ | ||
| 1 | -/** | |
| 2 | - * A component that displays config items either as tabs (on large screens) or a popover select (on small screens) | |
| 3 | - */ | |
| 4 | -interface ConfigItemSelectProps { | |
| 5 | - items: { | |
| 6 | - id: string; | |
| 7 | - label: string; | |
| 8 | - icon: React.ReactNode; | |
| 9 | - }[]; | |
| 10 | - activeId: string; | |
| 11 | - onSelect: (id: string) => void; | |
| 12 | -} | |
| 13 | - | |
| 14 | -import { ChevronDownIcon } from "@heroicons/react/24/outline"; | |
| 15 | -import { | |
| 16 | - Popover, | |
| 17 | - PopoverButton, | |
| 18 | - PopoverPanel, | |
| 19 | - Transition, | |
| 20 | -} from "../../components/ui"; | |
| 21 | -import { fontSize } from "../../util"; | |
| 22 | - | |
| 23 | -export function ConfigItemSelect({ | |
| 24 | - items, | |
| 25 | - activeId, | |
| 26 | - onSelect, | |
| 27 | -}: ConfigItemSelectProps) { | |
| 28 | - const activeItem = items.find((item) => item.id === activeId); | |
| 29 | - | |
| 30 | - const tabContent = ( | |
| 31 | - <div className="hidden border-0 border-b-[1px] border-solid border-b-zinc-700 p-0.5 sm:flex sm:justify-center md:grid md:grid-cols-2 md:gap-x-2"> | |
| 32 | - {items.map((item) => ( | |
| 33 | - <div | |
| 34 | - style={{ fontSize: fontSize(-2) }} | |
| 35 | - key={item.id} | |
| 36 | - className={`hover:bg-vsc-input-background flex cursor-pointer items-center justify-center gap-1.5 rounded-md px-2 py-2 ${ | |
| 37 | - activeId === item.id ? "" : "text-gray-400" | |
| 38 | - }`} | |
| 39 | - onClick={() => onSelect(item.id)} | |
| 40 | - > | |
| 41 | - {item.icon} | |
| 42 | - {item.label} | |
| 43 | - </div> | |
| 44 | - ))} | |
| 45 | - </div> | |
| 46 | - ); | |
| 47 | - | |
| 48 | - // Render popover on smaller screens | |
| 49 | - const popoverContent = ( | |
| 50 | - <div className="mt-2 px-1.5 sm:hidden"> | |
| 51 | - <Popover className="relative"> | |
| 52 | - <PopoverButton | |
| 53 | - className="flex w-full items-center justify-between gap-2 rounded-md border border-zinc-700 px-3 py-2" | |
| 54 | - style={{ fontSize: fontSize(-2) }} | |
| 55 | - > | |
| 56 | - <div className="flex items-center gap-2"> | |
| 57 | - {activeItem?.icon} | |
| 58 | - <span>{activeItem?.label}</span> | |
| 59 | - </div> | |
| 60 | - <ChevronDownIcon className="h-4 w-4" /> | |
| 61 | - </PopoverButton> | |
| 62 | - | |
| 63 | - <Transition> | |
| 64 | - <PopoverPanel className="bg-vsc-input-background absolute z-10 mt-1 w-full rounded-md border border-zinc-700 py-1"> | |
| 65 | - {items.map((item) => ( | |
| 66 | - <div | |
| 67 | - key={item.id} | |
| 68 | - className={`hover:bg-vsc-input-background flex cursor-pointer items-center gap-2 px-3 py-2 ${ | |
| 69 | - activeId === item.id ? "bg-vsc-input-background" : "" | |
| 70 | - }`} | |
| 71 | - onClick={() => { | |
| 72 | - onSelect(item.id); | |
| 73 | - }} | |
| 74 | - > | |
| 75 | - {item.icon} | |
| 76 | - <span>{item.label}</span> | |
| 77 | - </div> | |
| 78 | - ))} | |
| 79 | - </PopoverPanel> | |
| 80 | - </Transition> | |
| 81 | - </Popover> | |
| 82 | - </div> | |
| 83 | - ); | |
| 84 | - | |
| 85 | - return ( | |
| 86 | - <> | |
| 87 | - {tabContent} | |
| 88 | - {popoverContent} | |
| 89 | - </> | |
| 90 | - ); | |
| 91 | -} |
deleted gui/src/pages/config/ContinueFeaturesMenu.tsx +0 −29
| @@ -1,29 +0,0 @@ | ||
| 1 | -import ToggleSwitch from "../../components/gui/Switch"; | |
| 2 | -interface ContinueFeaturesMenuProps { | |
| 3 | - enableStaticContextualization: boolean; | |
| 4 | - handleEnableStaticContextualizationToggle: (value: boolean) => void; | |
| 5 | -} | |
| 6 | - | |
| 7 | -export function ContinueFeaturesMenu({ | |
| 8 | - enableStaticContextualization, | |
| 9 | - handleEnableStaticContextualizationToggle, | |
| 10 | -}: ContinueFeaturesMenuProps) { | |
| 11 | - return ( | |
| 12 | - <div className="flex w-full flex-col gap-y-4"> | |
| 13 | - <div className="my-2 text-center text-xs font-medium text-slate-400"> | |
| 14 | - 🚧 INTERNAL SETTINGS 🚧 | |
| 15 | - </div> | |
| 16 | - <div className="flex w-full flex-col gap-y-4"> | |
| 17 | - <ToggleSwitch | |
| 18 | - isToggled={enableStaticContextualization} | |
| 19 | - onToggle={() => | |
| 20 | - handleEnableStaticContextualizationToggle( | |
| 21 | - !enableStaticContextualization, | |
| 22 | - ) | |
| 23 | - } | |
| 24 | - text="Use Static Contextualization" | |
| 25 | - /> | |
| 26 | - </div> | |
| 27 | - </div> | |
| 28 | - ); | |
| 29 | -} |
deleted gui/src/pages/config/HelpCenterSection.tsx +0 −131
| @@ -1,131 +0,0 @@ | ||
| 1 | -import { | |
| 2 | - ArrowTopRightOnSquareIcon, | |
| 3 | - DocumentArrowUpIcon, | |
| 4 | - NumberedListIcon, | |
| 5 | - PaintBrushIcon, | |
| 6 | - TableCellsIcon, | |
| 7 | -} from "@heroicons/react/24/outline"; | |
| 8 | -import { useContext } from "react"; | |
| 9 | -import { useNavigate } from "react-router-dom"; | |
| 10 | -import { IdeMessengerContext } from "../../context/IdeMessenger"; | |
| 11 | -import { useAppDispatch, useAppSelector } from "../../redux/hooks"; | |
| 12 | -import { setOnboardingCard } from "../../redux/slices/uiSlice"; | |
| 13 | -import { saveCurrentSession } from "../../redux/thunks/session"; | |
| 14 | -import { ROUTES } from "../../util/navigation"; | |
| 15 | -import MoreHelpRow from "./MoreHelpRow"; | |
| 16 | - | |
| 17 | -export function HelpCenterSection() { | |
| 18 | - const ideMessenger = useContext(IdeMessengerContext); | |
| 19 | - const navigate = useNavigate(); | |
| 20 | - const dispatch = useAppDispatch(); | |
| 21 | - | |
| 22 | - const currentSession = useAppSelector((state) => state.session); | |
| 23 | - | |
| 24 | - const handleViewSessionData = async () => { | |
| 25 | - const sessionData = await ideMessenger.request("history/load", { | |
| 26 | - id: currentSession.id, | |
| 27 | - }); | |
| 28 | - | |
| 29 | - if (sessionData.status === "success") { | |
| 30 | - await ideMessenger.request("showVirtualFile", { | |
| 31 | - name: `${sessionData.content.title}.json`, | |
| 32 | - content: JSON.stringify(sessionData.content, null, 2), | |
| 33 | - }); | |
| 34 | - } | |
| 35 | - }; | |
| 36 | - | |
| 37 | - return ( | |
| 38 | - <div className="py-5"> | |
| 39 | - <h3 className="mb-4 mt-0 text-xl">Help center</h3> | |
| 40 | - <div className="-mx-4 flex flex-col"> | |
| 41 | - <MoreHelpRow | |
| 42 | - title="Continue Hub" | |
| 43 | - description="Visit hub.continue.dev to explore custom agents and blocks" | |
| 44 | - Icon={ArrowTopRightOnSquareIcon} | |
| 45 | - onClick={() => | |
| 46 | - ideMessenger.post("openUrl", "https://hub.continue.dev/") | |
| 47 | - } | |
| 48 | - /> | |
| 49 | - | |
| 50 | - <MoreHelpRow | |
| 51 | - title="Documentation" | |
| 52 | - description="Learn how to configure and use Continue" | |
| 53 | - Icon={ArrowTopRightOnSquareIcon} | |
| 54 | - onClick={() => | |
| 55 | - ideMessenger.post("openUrl", "https://docs.continue.dev/") | |
| 56 | - } | |
| 57 | - /> | |
| 58 | - | |
| 59 | - <MoreHelpRow | |
| 60 | - title="Have an issue?" | |
| 61 | - description="Let us know on GitHub and we'll do our best to resolve it" | |
| 62 | - Icon={ArrowTopRightOnSquareIcon} | |
| 63 | - onClick={() => | |
| 64 | - ideMessenger.post( | |
| 65 | - "openUrl", | |
| 66 | - "https://github.com/continuedev/continue/issues/new/choose", | |
| 67 | - ) | |
| 68 | - } | |
| 69 | - /> | |
| 70 | - | |
| 71 | - <MoreHelpRow | |
| 72 | - title="Join the community!" | |
| 73 | - description="Join us on Discord to stay up-to-date on the latest developments" | |
| 74 | - Icon={ArrowTopRightOnSquareIcon} | |
| 75 | - onClick={() => | |
| 76 | - ideMessenger.post("openUrl", "https://discord.gg/vapESyrFmJ") | |
| 77 | - } | |
| 78 | - /> | |
| 79 | - | |
| 80 | - <MoreHelpRow | |
| 81 | - title="Token usage" | |
| 82 | - description="Daily token usage across models" | |
| 83 | - Icon={TableCellsIcon} | |
| 84 | - onClick={() => navigate("/stats")} | |
| 85 | - /> | |
| 86 | - | |
| 87 | - {currentSession.history.length > 0 && !currentSession.isStreaming && ( | |
| 88 | - <MoreHelpRow | |
| 89 | - title="View current session history" | |
| 90 | - description="Open the current chat session file for troubleshooting" | |
| 91 | - Icon={NumberedListIcon} | |
| 92 | - onClick={handleViewSessionData} | |
| 93 | - /> | |
| 94 | - )} | |
| 95 | - | |
| 96 | - <MoreHelpRow | |
| 97 | - title="Quickstart" | |
| 98 | - description="Reopen the quickstart and tutorial file" | |
| 99 | - Icon={DocumentArrowUpIcon} | |
| 100 | - onClick={async () => { | |
| 101 | - navigate("/"); | |
| 102 | - // Used to clear the chat panel before showing onboarding card | |
| 103 | - await dispatch( | |
| 104 | - saveCurrentSession({ | |
| 105 | - openNewSession: true, | |
| 106 | - generateTitle: true, | |
| 107 | - }), | |
| 108 | - ); | |
| 109 | - dispatch( | |
| 110 | - setOnboardingCard({ | |
| 111 | - show: true, | |
| 112 | - activeTab: undefined, | |
| 113 | - }), | |
| 114 | - ); | |
| 115 | - ideMessenger.post("showTutorial", undefined); | |
| 116 | - }} | |
| 117 | - /> | |
| 118 | - {process.env.NODE_ENV === "development" && ( | |
| 119 | - <MoreHelpRow | |
| 120 | - title="Theme Test Page" | |
| 121 | - description="Development page for testing themes" | |
| 122 | - Icon={PaintBrushIcon} | |
| 123 | - onClick={async () => { | |
| 124 | - navigate(ROUTES.THEME); | |
| 125 | - }} | |
| 126 | - /> | |
| 127 | - )} | |
| 128 | - </div> | |
| 129 | - </div> | |
| 130 | - ); | |
| 131 | -} |
deleted gui/src/pages/config/IndexingProgress/IndexingProgress.tsx +0 −133
| @@ -1,133 +0,0 @@ | ||
| 1 | -import { IndexingProgressUpdate } from "core"; | |
| 2 | -import { usePostHog } from "posthog-js/react"; | |
| 3 | -import { useContext, useEffect, useState } from "react"; | |
| 4 | -import { useDispatch } from "react-redux"; | |
| 5 | - | |
| 6 | -import ConfirmationDialog from "../../../components/dialogs/ConfirmationDialog"; | |
| 7 | -import { IdeMessengerContext } from "../../../context/IdeMessenger"; | |
| 8 | -import { useWebviewListener } from "../../../hooks/useWebviewListener"; | |
| 9 | -import { setDialogMessage, setShowDialog } from "../../../redux/slices/uiSlice"; | |
| 10 | -import { isJetBrains } from "../../../util"; | |
| 11 | -import IndexingProgressBar from "./IndexingProgressBar"; | |
| 12 | -import IndexingProgressErrorText from "./IndexingProgressErrorText"; | |
| 13 | -import IndexingProgressIndicator from "./IndexingProgressIndicator"; | |
| 14 | -import IndexingProgressSubtext from "./IndexingProgressSubtext"; | |
| 15 | -import IndexingProgressTitleText from "./IndexingProgressTitleText"; | |
| 16 | - | |
| 17 | -export function getProgressPercentage( | |
| 18 | - progress: IndexingProgressUpdate["progress"], | |
| 19 | -) { | |
| 20 | - return Math.min(100, Math.max(0, progress * 100)); | |
| 21 | -} | |
| 22 | - | |
| 23 | -function IndexingProgress() { | |
| 24 | - const ideMessenger = useContext(IdeMessengerContext); | |
| 25 | - const posthog = usePostHog(); | |
| 26 | - const dispatch = useDispatch(); | |
| 27 | - const [paused, setPaused] = useState<boolean | undefined>(undefined); | |
| 28 | - const [update, setUpdate] = useState<IndexingProgressUpdate>({ | |
| 29 | - desc: "Loading indexing config", | |
| 30 | - progress: 0.0, | |
| 31 | - status: "loading", | |
| 32 | - }); | |
| 33 | - | |
| 34 | - // If sidebar is opened after extension initializes, retrieve saved states. | |
| 35 | - let initialized = false; | |
| 36 | - | |
| 37 | - useWebviewListener("indexProgress", async (data) => { | |
| 38 | - setUpdate(data); | |
| 39 | - }); | |
| 40 | - | |
| 41 | - useEffect(() => { | |
| 42 | - if (!initialized) { | |
| 43 | - // Triggers retrieval for possible non-default states set prior to IndexingProgressBar initialization | |
| 44 | - ideMessenger.post("index/indexingProgressBarInitialized", undefined); | |
| 45 | - initialized = true; | |
| 46 | - } | |
| 47 | - }, []); | |
| 48 | - | |
| 49 | - useEffect(() => { | |
| 50 | - if (paused === undefined) return; | |
| 51 | - ideMessenger.post("index/setPaused", paused); | |
| 52 | - }, [paused]); | |
| 53 | - | |
| 54 | - function onClickRetry() { | |
| 55 | - // For now, we don't show in JetBrains since the re-index command | |
| 56 | - // is not yet implemented | |
| 57 | - if (update.shouldClearIndexes && !isJetBrains()) { | |
| 58 | - dispatch(setShowDialog(true)); | |
| 59 | - dispatch( | |
| 60 | - setDialogMessage( | |
| 61 | - <ConfirmationDialog | |
| 62 | - title="Rebuild codebase index" | |
| 63 | - confirmText="Rebuild" | |
| 64 | - text={ | |
| 65 | - "Your index appears corrupted. We recommend clearing and rebuilding it, " + | |
| 66 | - "which may take time for large codebases.\n\n" + | |
| 67 | - "For a faster rebuild without clearing data, press 'Shift + Command + P' to open " + | |
| 68 | - "the Command Palette, and type out 'Continue: Force Codebase Re-Indexing'" | |
| 69 | - } | |
| 70 | - onConfirm={() => { | |
| 71 | - posthog.capture("rebuild_index_clicked"); | |
| 72 | - ideMessenger.post("index/forceReIndex", { | |
| 73 | - shouldClearIndexes: true, | |
| 74 | - }); | |
| 75 | - }} | |
| 76 | - />, | |
| 77 | - ), | |
| 78 | - ); | |
| 79 | - } else { | |
| 80 | - ideMessenger.post("index/forceReIndex", undefined); | |
| 81 | - } | |
| 82 | - } | |
| 83 | - | |
| 84 | - function onClick() { | |
| 85 | - switch (update.status) { | |
| 86 | - case "failed": | |
| 87 | - onClickRetry(); | |
| 88 | - break; | |
| 89 | - case "indexing": | |
| 90 | - case "loading": | |
| 91 | - case "paused": | |
| 92 | - if (update.progress < 1 && update.progress >= 0) { | |
| 93 | - setPaused((prev) => !prev); | |
| 94 | - } else { | |
| 95 | - ideMessenger.post("index/forceReIndex", undefined); | |
| 96 | - } | |
| 97 | - break; | |
| 98 | - case "disabled": | |
| 99 | - ideMessenger.post("config/openProfile", { | |
| 100 | - profileId: undefined, | |
| 101 | - }); | |
| 102 | - break; | |
| 103 | - case "done": | |
| 104 | - ideMessenger.post("index/forceReIndex", undefined); | |
| 105 | - default: | |
| 106 | - break; | |
| 107 | - } | |
| 108 | - } | |
| 109 | - | |
| 110 | - return ( | |
| 111 | - <div className="mt-4 flex flex-col"> | |
| 112 | - <div className="mb-0 flex justify-between text-sm"> | |
| 113 | - <IndexingProgressTitleText update={update} /> | |
| 114 | - {!["loading", "waiting"].includes(update.status) && ( | |
| 115 | - <IndexingProgressIndicator update={update} /> | |
| 116 | - )} | |
| 117 | - </div> | |
| 118 | - | |
| 119 | - <IndexingProgressBar update={update} /> | |
| 120 | - | |
| 121 | - <IndexingProgressSubtext update={update} onClick={onClick} /> | |
| 122 | - | |
| 123 | - {(update.status === "failed" || | |
| 124 | - (update.warnings && update.warnings.length > 0)) && ( | |
| 125 | - <div className="mt-4"> | |
| 126 | - <IndexingProgressErrorText update={update} /> | |
| 127 | - </div> | |
| 128 | - )} | |
| 129 | - </div> | |
| 130 | - ); | |
| 131 | -} | |
| 132 | - | |
| 133 | -export default IndexingProgress; |
deleted gui/src/pages/config/IndexingProgress/IndexingProgressBar.tsx +0 −27
| @@ -1,27 +0,0 @@ | ||
| 1 | -import { IndexingProgressUpdate } from "core"; | |
| 2 | -import { getProgressPercentage } from "./IndexingProgress"; | |
| 3 | - | |
| 4 | -export interface IndexingProgressBarProps { | |
| 5 | - update: IndexingProgressUpdate; | |
| 6 | -} | |
| 7 | - | |
| 8 | -function IndexingProgressBar({ update }: IndexingProgressBarProps) { | |
| 9 | - // Show 100% red progress bar if indexing failed | |
| 10 | - const progressPercentage = | |
| 11 | - update.status === "failed" ? 100 : getProgressPercentage(update.progress); | |
| 12 | - | |
| 13 | - return ( | |
| 14 | - <div className="my-2 h-1.5 w-full rounded-md border border-solid border-gray-400"> | |
| 15 | - <div | |
| 16 | - className={`h-full rounded-lg transition-all duration-200 ease-in-out ${ | |
| 17 | - update.status === "failed" ? "bg-red-600" : "bg-stone-500" | |
| 18 | - }`} | |
| 19 | - style={{ | |
| 20 | - width: `${progressPercentage}%`, | |
| 21 | - }} | |
| 22 | - /> | |
| 23 | - </div> | |
| 24 | - ); | |
| 25 | -} | |
| 26 | - | |
| 27 | -export default IndexingProgressBar; |
deleted gui/src/pages/config/IndexingProgress/IndexingProgressErrorText.tsx +0 −121
| @@ -1,121 +0,0 @@ | ||
| 1 | -import { | |
| 2 | - ArrowTopRightOnSquareIcon, | |
| 3 | - ChevronRightIcon, | |
| 4 | - ClipboardIcon, | |
| 5 | - XCircleIcon, | |
| 6 | -} from "@heroicons/react/24/outline"; | |
| 7 | -import { IndexingProgressUpdate } from "core"; | |
| 8 | -import { useContext, useState } from "react"; | |
| 9 | -import { GhostButton } from "../../../components"; | |
| 10 | -import { IdeMessengerContext } from "../../../context/IdeMessenger"; | |
| 11 | -import { useAppSelector } from "../../../redux/hooks"; | |
| 12 | - | |
| 13 | -export interface IndexingProgressErrorTextProps { | |
| 14 | - update: IndexingProgressUpdate; | |
| 15 | -} | |
| 16 | - | |
| 17 | -const copyWarningsToClipboard = (warnings: string[] = []) => { | |
| 18 | - const warningsText = warnings.join("\n"); | |
| 19 | - void navigator.clipboard.writeText(warningsText); | |
| 20 | -}; | |
| 21 | - | |
| 22 | -function IndexingProgressErrorText({ update }: IndexingProgressErrorTextProps) { | |
| 23 | - const ideMessenger = useContext(IdeMessengerContext); | |
| 24 | - const [showWarnings, setShowWarnings] = useState(false); | |
| 25 | - const embeddingsProvider = useAppSelector( | |
| 26 | - (state) => state.config.config.selectedModelByRole.embed, | |
| 27 | - ); | |
| 28 | - | |
| 29 | - if (!embeddingsProvider) { | |
| 30 | - return ( | |
| 31 | - <div className="flex items-center gap-2 italic"> | |
| 32 | - <XCircleIcon className="h-4 w-4 min-w-[10%]" /> | |
| 33 | - <span className="leading-relaxed"> | |
| 34 | - Add an Embeddings model to enable codebase indexing. See the docs for | |
| 35 | - examples: | |
| 36 | - <a | |
| 37 | - href="https://docs.continue.dev/walkthroughs/codebase-embeddings#embeddings-providers" | |
| 38 | - target="_blank" | |
| 39 | - className="cursor-pointer text-inherit underline hover:text-inherit" | |
| 40 | - > | |
| 41 | - https://docs.continue.dev/walkthroughs/codebase-embeddings#embeddings-providers | |
| 42 | - </a> | |
| 43 | - </span> | |
| 44 | - </div> | |
| 45 | - ); | |
| 46 | - } | |
| 47 | - | |
| 48 | - // Show warnings if they exist (for completed indexing with warnings) | |
| 49 | - if ( | |
| 50 | - update.warnings && | |
| 51 | - update.warnings.length > 0 && | |
| 52 | - update.status !== "failed" | |
| 53 | - ) { | |
| 54 | - return ( | |
| 55 | - <div> | |
| 56 | - <div | |
| 57 | - className="flex cursor-pointer items-center gap-2 italic text-yellow-600" | |
| 58 | - onClick={() => setShowWarnings(!showWarnings)} | |
| 59 | - > | |
| 60 | - <span className="leading-relaxed"> | |
| 61 | - {update.warnings.length} warning | |
| 62 | - {update.warnings.length > 1 ? "s" : ""} during indexing | |
| 63 | - </span> | |
| 64 | - <ChevronRightIcon | |
| 65 | - className={`h-3 w-3 transition-transform duration-300 ${ | |
| 66 | - showWarnings ? "rotate-90" : "" | |
| 67 | - }`} | |
| 68 | - /> | |
| 69 | - </div> | |
| 70 | - | |
| 71 | - <div | |
| 72 | - className={`ml-3 overflow-hidden transition-all duration-300 ease-in-out ${ | |
| 73 | - showWarnings ? "mt-2 max-h-96 opacity-100" : "max-h-0 opacity-0" | |
| 74 | - }`} | |
| 75 | - > | |
| 76 | - {/* Warning messages */} | |
| 77 | - <div className="space-y-1"> | |
| 78 | - {update.warnings.map((warning, index) => ( | |
| 79 | - <div key={index} className="text-xs"> | |
| 80 | - • {warning} | |
| 81 | - </div> | |
| 82 | - ))} | |
| 83 | - </div> | |
| 84 | - | |
| 85 | - {/* Action Buttons */} | |
| 86 | - <div className="flex flex-row items-center justify-end gap-2 pt-4"> | |
| 87 | - {/* Copy all warnings to clipboard */} | |
| 88 | - <GhostButton | |
| 89 | - onClick={() => copyWarningsToClipboard(update.warnings)} | |
| 90 | - className="flex items-center !px-1.5 !py-0.5 text-xs" | |
| 91 | - > | |
| 92 | - <ClipboardIcon className="mr-1 h-3 w-3" /> | |
| 93 | - <span>Copy output</span> | |
| 94 | - </GhostButton> | |
| 95 | - | |
| 96 | - {/* Open dev tools to view logs */} | |
| 97 | - <GhostButton | |
| 98 | - onClick={() => { | |
| 99 | - ideMessenger.post("toggleDevTools", undefined); | |
| 100 | - }} | |
| 101 | - className="flex items-center !px-1.5 !py-0.5 text-xs" | |
| 102 | - > | |
| 103 | - <ArrowTopRightOnSquareIcon className="mr-1 h-3 w-3" /> | |
| 104 | - <span>View Logs</span> | |
| 105 | - </GhostButton> | |
| 106 | - </div> | |
| 107 | - </div> | |
| 108 | - </div> | |
| 109 | - ); | |
| 110 | - } | |
| 111 | - | |
| 112 | - // Show error for failed status | |
| 113 | - return ( | |
| 114 | - <div className="flex items-center gap-2 italic text-red-600"> | |
| 115 | - <XCircleIcon className="h-4 w-4" /> | |
| 116 | - <span className="leading-relaxed">{update.desc}</span> | |
| 117 | - </div> | |
| 118 | - ); | |
| 119 | -} | |
| 120 | - | |
| 121 | -export default IndexingProgressErrorText; |
deleted gui/src/pages/config/IndexingProgress/IndexingProgressIndicator.tsx +0 −48
| @@ -1,48 +0,0 @@ | ||
| 1 | -import { | |
| 2 | - ArrowPathIcon, | |
| 3 | - CheckCircleIcon, | |
| 4 | - PauseCircleIcon, | |
| 5 | -} from "@heroicons/react/24/outline"; | |
| 6 | -import { IndexingProgressUpdate } from "core"; | |
| 7 | -import { getProgressPercentage } from "./IndexingProgress"; | |
| 8 | - | |
| 9 | -export interface IndexingProgressIndicatorProps { | |
| 10 | - update: IndexingProgressUpdate; | |
| 11 | -} | |
| 12 | - | |
| 13 | -const STATUS_TO_ICON: Record<IndexingProgressUpdate["status"], any> = { | |
| 14 | - disabled: null, | |
| 15 | - loading: null, | |
| 16 | - waiting: null, | |
| 17 | - indexing: ArrowPathIcon, | |
| 18 | - paused: PauseCircleIcon, | |
| 19 | - done: CheckCircleIcon, | |
| 20 | - failed: null, // Since we show an erorr message below | |
| 21 | - cancelled: null, | |
| 22 | -}; | |
| 23 | - | |
| 24 | -function IndexingProgressIndicator({ update }: IndexingProgressIndicatorProps) { | |
| 25 | - const progressPercentage = getProgressPercentage(update.progress).toFixed(0); | |
| 26 | - const Icon = STATUS_TO_ICON[update.status]; | |
| 27 | - const animateIcon = update.status === "indexing"; | |
| 28 | - const showProgress = | |
| 29 | - update.status !== "disabled" && progressPercentage !== "100"; | |
| 30 | - | |
| 31 | - return ( | |
| 32 | - <div className="text-lightgray flex items-center justify-between gap-1"> | |
| 33 | - {showProgress && <span className="text-xs">{progressPercentage}%</span>} | |
| 34 | - | |
| 35 | - {Icon && ( | |
| 36 | - <div className="flex items-center"> | |
| 37 | - <Icon | |
| 38 | - className={`text-lightgray inline-block h-4 w-4 align-top ${ | |
| 39 | - animateIcon ? "animate-spin-slow" : "" | |
| 40 | - }`} | |
| 41 | - ></Icon> | |
| 42 | - </div> | |
| 43 | - )} | |
| 44 | - </div> | |
| 45 | - ); | |
| 46 | -} | |
| 47 | - | |
| 48 | -export default IndexingProgressIndicator; |
deleted gui/src/pages/config/IndexingProgress/IndexingProgressSubtext.tsx +0 −48
| @@ -1,48 +0,0 @@ | ||
| 1 | -import { IndexingProgressUpdate } from "core"; | |
| 2 | - | |
| 3 | -export interface IndexingProgressSubtextProps { | |
| 4 | - update: IndexingProgressUpdate; | |
| 5 | - onClick: () => void; | |
| 6 | -} | |
| 7 | - | |
| 8 | -const STATUS_TO_SUBTITLE_TEXT: Record< | |
| 9 | - IndexingProgressUpdate["status"], | |
| 10 | - string | undefined | |
| 11 | -> = { | |
| 12 | - done: "Click to re-index", | |
| 13 | - loading: "", | |
| 14 | - waiting: "", | |
| 15 | - indexing: "Click to pause", | |
| 16 | - paused: "Click to resume", | |
| 17 | - failed: "Click to retry", | |
| 18 | - disabled: "Click to open agent configuration", | |
| 19 | - cancelled: "Click to restart", | |
| 20 | -}; | |
| 21 | - | |
| 22 | -function IndexingProgressSubtext({ | |
| 23 | - update, | |
| 24 | - onClick, | |
| 25 | -}: IndexingProgressSubtextProps) { | |
| 26 | - const showIndexingDesc = update.status === "indexing"; | |
| 27 | - | |
| 28 | - return ( | |
| 29 | - <div className="flex justify-between"> | |
| 30 | - <span | |
| 31 | - className={`text-lightgray inline-block cursor-pointer text-xs underline`} | |
| 32 | - onClick={onClick} | |
| 33 | - > | |
| 34 | - {STATUS_TO_SUBTITLE_TEXT[update.status]} | |
| 35 | - </span> | |
| 36 | - | |
| 37 | - <div className={`${showIndexingDesc ? "w-2/3" : "flex-1"}`}> | |
| 38 | - {showIndexingDesc && ( | |
| 39 | - <span className="text-lightgray block truncate text-right text-xs"> | |
| 40 | - {update.desc} | |
| 41 | - </span> | |
| 42 | - )} | |
| 43 | - </div> | |
| 44 | - </div> | |
| 45 | - ); | |
| 46 | -} | |
| 47 | - | |
| 48 | -export default IndexingProgressSubtext; |
deleted gui/src/pages/config/IndexingProgress/IndexingProgressTitleText.tsx +0 −30
| @@ -1,30 +0,0 @@ | ||
| 1 | -import { IndexingProgressUpdate } from "core"; | |
| 2 | -import { AnimatedEllipsis } from "../../../components/AnimatedEllipsis"; | |
| 3 | - | |
| 4 | -export interface IndexingProgressTitleTextProps { | |
| 5 | - update: IndexingProgressUpdate; | |
| 6 | -} | |
| 7 | - | |
| 8 | -const STATUS_TO_TEXT: Record<IndexingProgressUpdate["status"], string> = { | |
| 9 | - done: "Indexing complete", | |
| 10 | - loading: "Initializing", | |
| 11 | - waiting: "Indexing other workspace", | |
| 12 | - indexing: "Indexing in-progress", | |
| 13 | - paused: "Indexing paused", | |
| 14 | - failed: "Indexing failed", | |
| 15 | - disabled: "Indexing disabled", | |
| 16 | - cancelled: "Indexing cancelled", | |
| 17 | -}; | |
| 18 | - | |
| 19 | -function IndexingProgressTitleText({ update }: IndexingProgressTitleTextProps) { | |
| 20 | - const showEllipsis = update.status === "loading"; | |
| 21 | - | |
| 22 | - return ( | |
| 23 | - <span> | |
| 24 | - {STATUS_TO_TEXT[update.status]} | |
| 25 | - {showEllipsis && <AnimatedEllipsis />} | |
| 26 | - </span> | |
| 27 | - ); | |
| 28 | -} | |
| 29 | - | |
| 30 | -export default IndexingProgressTitleText; |
deleted gui/src/pages/config/IndexingProgress/index.ts +0 −1
| @@ -1,1 +0,0 @@ | ||
| 1 | -export { default } from "./IndexingProgress"; |
deleted gui/src/pages/config/IndexingSettingsSection.tsx +0 −37
| @@ -1,37 +0,0 @@ | ||
| 1 | -import DocsIndexingStatuses from "../../components/mainInput/Lump/sections/docs/DocsSection"; | |
| 2 | -import { useAppSelector } from "../../redux/hooks"; | |
| 3 | -import IndexingProgress from "./IndexingProgress"; | |
| 4 | - | |
| 5 | -export function IndexingSettingsSection() { | |
| 6 | - const config = useAppSelector((state) => state.config.config); | |
| 7 | - return ( | |
| 8 | - <div className="flex flex-col gap-3 py-5"> | |
| 9 | - <div> | |
| 10 | - <h3 className="mx-auto mb-1 mt-0 text-xl">@codebase index</h3> | |
| 11 | - <span className="text-lightgray w-3/4 text-xs"> | |
| 12 | - Local embeddings of your codebase | |
| 13 | - </span> | |
| 14 | - {config.disableIndexing ? ( | |
| 15 | - <div className="pb-2 pt-5"> | |
| 16 | - <p className="py-1 text-center font-semibold"> | |
| 17 | - Indexing is disabled | |
| 18 | - </p> | |
| 19 | - <p className="text-lightgray cursor-pointer text-center text-xs"> | |
| 20 | - Open settings and toggle <code>Enable Indexing</code> to re-enable | |
| 21 | - </p> | |
| 22 | - </div> | |
| 23 | - ) : ( | |
| 24 | - <IndexingProgress /> | |
| 25 | - )} | |
| 26 | - </div> | |
| 27 | - | |
| 28 | - <div className="mt-5"> | |
| 29 | - <h3 className="mx-auto mb-1 mt-0 text-xl">@docs index</h3> | |
| 30 | - <span className="text-lightgray w-3/4 text-xs"> | |
| 31 | - Local embeddings of your documentation sources | |
| 32 | - </span> | |
| 33 | - </div> | |
| 34 | - <DocsIndexingStatuses /> | |
| 35 | - </div> | |
| 36 | - ); | |
| 37 | -} |
deleted gui/src/pages/config/KeyboardShortcuts.tsx +0 −157
| @@ -1,157 +0,0 @@ | ||
| 1 | -import { useMemo } from "react"; | |
| 2 | -import Shortcut from "../../components/gui/Shortcut"; | |
| 3 | -import { isJetBrains } from "../../util"; | |
| 4 | - | |
| 5 | -interface KeyboardShortcutProps { | |
| 6 | - shortcut: string; | |
| 7 | - description: string; | |
| 8 | - isEven: boolean; | |
| 9 | -} | |
| 10 | - | |
| 11 | -function KeyboardShortcut(props: KeyboardShortcutProps) { | |
| 12 | - return ( | |
| 13 | - <div | |
| 14 | - className={`flex flex-col items-start p-2 sm:flex-row sm:items-center ${props.isEven ? "" : "bg-table-oddRow"}`} | |
| 15 | - > | |
| 16 | - <div className="w-full flex-grow pb-1 pr-4 sm:w-auto sm:pb-0"> | |
| 17 | - <span className="block break-words text-xs">{props.description}:</span> | |
| 18 | - </div> | |
| 19 | - <div className="flex-shrink-0 whitespace-nowrap"> | |
| 20 | - <Shortcut>{props.shortcut}</Shortcut> | |
| 21 | - </div> | |
| 22 | - </div> | |
| 23 | - ); | |
| 24 | -} | |
| 25 | - | |
| 26 | -// Shortcut strings will be rendered correctly based on the platform by the Shortcut component | |
| 27 | -const vscodeShortcuts: Omit<KeyboardShortcutProps, "isEven">[] = [ | |
| 28 | - { | |
| 29 | - shortcut: "cmd '", | |
| 30 | - description: "Toggle Selected Model", | |
| 31 | - }, | |
| 32 | - { | |
| 33 | - shortcut: "cmd I", | |
| 34 | - description: "Edit highlighted code", | |
| 35 | - }, | |
| 36 | - { | |
| 37 | - shortcut: "cmd L", | |
| 38 | - description: | |
| 39 | - "New Chat / New Chat With Selected Code / Close Continue Sidebar If Chat Already In Focus", | |
| 40 | - }, | |
| 41 | - { | |
| 42 | - shortcut: "cmd backspace", | |
| 43 | - description: "Cancel response", | |
| 44 | - }, | |
| 45 | - { | |
| 46 | - shortcut: "cmd shift I", | |
| 47 | - description: "Toggle inline edit focus", | |
| 48 | - }, | |
| 49 | - { | |
| 50 | - shortcut: "cmd shift L", | |
| 51 | - description: | |
| 52 | - "Focus Current Chat / Add Selected Code To Current Chat / Close Continue Sidebar If Chat Already In Focus", | |
| 53 | - }, | |
| 54 | - { | |
| 55 | - shortcut: "cmd shift R", | |
| 56 | - description: "Debug Terminal", | |
| 57 | - }, | |
| 58 | - { | |
| 59 | - shortcut: "cmd shift backspace", | |
| 60 | - description: "Reject Diff", | |
| 61 | - }, | |
| 62 | - { | |
| 63 | - shortcut: "cmd shift enter", | |
| 64 | - description: "Accept Diff", | |
| 65 | - }, | |
| 66 | - { | |
| 67 | - shortcut: "alt cmd N", | |
| 68 | - description: "Reject Top Change in Diff", | |
| 69 | - }, | |
| 70 | - { | |
| 71 | - shortcut: "alt cmd Y", | |
| 72 | - description: "Accept Top Change in Diff", | |
| 73 | - }, | |
| 74 | - { | |
| 75 | - shortcut: "cmd K cmd A", | |
| 76 | - description: "Toggle Autocomplete Enabled", | |
| 77 | - }, | |
| 78 | - { | |
| 79 | - shortcut: "cmd alt space", | |
| 80 | - description: "Force an Autocomplete Trigger", | |
| 81 | - }, | |
| 82 | - { | |
| 83 | - shortcut: "cmd K cmd M", | |
| 84 | - description: "Toggle Full Screen", | |
| 85 | - }, | |
| 86 | -]; | |
| 87 | - | |
| 88 | -const jetbrainsShortcuts: Omit<KeyboardShortcutProps, "isEven">[] = [ | |
| 89 | - { | |
| 90 | - shortcut: "cmd '", | |
| 91 | - description: "Toggle Selected Model", | |
| 92 | - }, | |
| 93 | - { | |
| 94 | - shortcut: "cmd I", | |
| 95 | - description: "Edit highlighted code", | |
| 96 | - }, | |
| 97 | - { | |
| 98 | - shortcut: "cmd J", | |
| 99 | - description: | |
| 100 | - "New Chat / New Chat With Selected Code / Close Continue Sidebar If Chat Already In Focus", | |
| 101 | - }, | |
| 102 | - { | |
| 103 | - shortcut: "cmd backspace", | |
| 104 | - description: "Cancel response", | |
| 105 | - }, | |
| 106 | - { | |
| 107 | - shortcut: "cmd shift I", | |
| 108 | - description: "Toggle inline edit focus", | |
| 109 | - }, | |
| 110 | - { | |
| 111 | - shortcut: "cmd shift J", | |
| 112 | - description: | |
| 113 | - "Focus Current Chat / Add Selected Code To Current Chat / Close Continue Sidebar If Chat Already In Focus", | |
| 114 | - }, | |
| 115 | - { | |
| 116 | - shortcut: "cmd shift backspace", | |
| 117 | - description: "Reject Diff", | |
| 118 | - }, | |
| 119 | - { | |
| 120 | - shortcut: "cmd shift enter", | |
| 121 | - description: "Accept Diff", | |
| 122 | - }, | |
| 123 | - { | |
| 124 | - shortcut: "alt shift J", | |
| 125 | - description: "Quick Input", | |
| 126 | - }, | |
| 127 | - { | |
| 128 | - shortcut: "alt cmd J", | |
| 129 | - description: "Toggle Sidebar", | |
| 130 | - }, | |
| 131 | -]; | |
| 132 | - | |
| 133 | -function KeyboardShortcuts() { | |
| 134 | - const shortcuts = useMemo(() => { | |
| 135 | - return isJetBrains() ? jetbrainsShortcuts : vscodeShortcuts; | |
| 136 | - }, []); | |
| 137 | - | |
| 138 | - return ( | |
| 139 | - <div className="h-full overflow-auto"> | |
| 140 | - <h3 className="mb-3 text-xl">Keyboard shortcuts</h3> | |
| 141 | - <div> | |
| 142 | - {shortcuts.map((shortcut, i) => { | |
| 143 | - return ( | |
| 144 | - <KeyboardShortcut | |
| 145 | - key={i} | |
| 146 | - shortcut={shortcut.shortcut} | |
| 147 | - description={shortcut.description} | |
| 148 | - isEven={i % 2 === 0} | |
| 149 | - /> | |
| 150 | - ); | |
| 151 | - })} | |
| 152 | - </div> | |
| 153 | - </div> | |
| 154 | - ); | |
| 155 | -} | |
| 156 | - | |
| 157 | -export default KeyboardShortcuts; |
deleted gui/src/pages/config/ModelRoleSelector.tsx +0 −195
| @@ -1,195 +0,0 @@ | ||
| 1 | -import { | |
| 2 | - CheckIcon, | |
| 3 | - ChevronUpDownIcon, | |
| 4 | - Cog6ToothIcon, | |
| 5 | - CubeIcon, | |
| 6 | -} from "@heroicons/react/24/outline"; | |
| 7 | -import { ModelDescription } from "core"; | |
| 8 | -import { LLMConfigurationStatuses } from "core/llm/constants"; | |
| 9 | -import { MouseEvent, useContext, useState } from "react"; | |
| 10 | -import { defaultBorderRadius } from "../../components"; | |
| 11 | -import InfoHover from "../../components/InfoHover"; | |
| 12 | -import { | |
| 13 | - Listbox, | |
| 14 | - ListboxButton, | |
| 15 | - ListboxOption, | |
| 16 | - ListboxOptions, | |
| 17 | - Transition, | |
| 18 | -} from "../../components/ui"; | |
| 19 | -import { IdeMessengerContext } from "../../context/IdeMessenger"; | |
| 20 | -import { fontSize } from "../../util"; | |
| 21 | - | |
| 22 | -interface ModelRoleSelectorProps { | |
| 23 | - models: ModelDescription[]; | |
| 24 | - selectedModel: ModelDescription | null; | |
| 25 | - onSelect: (model: ModelDescription | null) => void; | |
| 26 | - displayName: string; | |
| 27 | - description: string; | |
| 28 | - setupURL: string; | |
| 29 | -} | |
| 30 | - | |
| 31 | -const ModelRoleSelector = ({ | |
| 32 | - models, | |
| 33 | - selectedModel, | |
| 34 | - onSelect, | |
| 35 | - displayName, | |
| 36 | - description, | |
| 37 | - setupURL, | |
| 38 | -}: ModelRoleSelectorProps) => { | |
| 39 | - const ideMessenger = useContext(IdeMessengerContext); | |
| 40 | - const [hoveredIdx, setHoveredIdx] = useState<number | null>(null); | |
| 41 | - | |
| 42 | - const noConfiguredModels = models.every( | |
| 43 | - (model) => model.configurationStatus !== LLMConfigurationStatuses.VALID, | |
| 44 | - ); | |
| 45 | - | |
| 46 | - function handleSelect(title: string | null) { | |
| 47 | - onSelect(models.find((m) => m.title === title) ?? null); | |
| 48 | - } | |
| 49 | - | |
| 50 | - function onClickGear(e: MouseEvent<SVGSVGElement>, model: ModelDescription) { | |
| 51 | - e.stopPropagation(); | |
| 52 | - e.preventDefault(); | |
| 53 | - ideMessenger.post("config/openProfile", { | |
| 54 | - profileId: undefined, | |
| 55 | - element: model, | |
| 56 | - }); | |
| 57 | - } | |
| 58 | - | |
| 59 | - function handleOptionClick( | |
| 60 | - showMissingApiKeyMsg: boolean, | |
| 61 | - e: MouseEvent<HTMLLIElement>, | |
| 62 | - ) { | |
| 63 | - if (showMissingApiKeyMsg) { | |
| 64 | - e.preventDefault(); | |
| 65 | - e.stopPropagation(); | |
| 66 | - } | |
| 67 | - } | |
| 68 | - | |
| 69 | - return ( | |
| 70 | - <> | |
| 71 | - <div className="mt-2 flex flex-row items-center gap-1 sm:mt-0"> | |
| 72 | - <span style={{ fontSize: fontSize(-3) }}>{displayName}</span> | |
| 73 | - <InfoHover size="3" id={displayName} msg={description} /> | |
| 74 | - </div> | |
| 75 | - | |
| 76 | - <Listbox value={selectedModel?.title ?? null} onChange={handleSelect}> | |
| 77 | - <div className="relative"> | |
| 78 | - {models.length === 0 ? ( | |
| 79 | - <ListboxButton | |
| 80 | - onClick={() => ideMessenger.post("openUrl", setupURL)} | |
| 81 | - className="bg-vsc-editor-background hover:bg-list-active hover:text-list-active-foreground text-description w-full justify-between px-2 py-1 underline hover:underline" | |
| 82 | - > | |
| 83 | - <span className="line-clamp-1" style={{ fontSize: fontSize(-3) }}> | |
| 84 | - Setup {displayName} model | |
| 85 | - </span> | |
| 86 | - </ListboxButton> | |
| 87 | - ) : ( | |
| 88 | - <> | |
| 89 | - <ListboxButton | |
| 90 | - disabled={models.length === 0} | |
| 91 | - className="bg-vsc-editor-background hover:bg-list-active hover:text-list-active-foreground w-full justify-between px-2 py-1" | |
| 92 | - > | |
| 93 | - {models.length === 0 || noConfiguredModels ? ( | |
| 94 | - <span className="text-lightgray line-clamp-1 italic"> | |
| 95 | - {`No ${models.length === 0 ? "" : "valid "}${displayName} models${ | |
| 96 | - ["Chat", "Apply", "Edit"].includes(displayName) | |
| 97 | - ? ". Using Chat model" | |
| 98 | - : "" | |
| 99 | - }`} | |
| 100 | - </span> | |
| 101 | - ) : ( | |
| 102 | - <span className="line-clamp-1"> | |
| 103 | - {selectedModel?.title ?? `Select ${displayName} model`} | |
| 104 | - </span> | |
| 105 | - )} | |
| 106 | - | |
| 107 | - {models.length > 0 && ( | |
| 108 | - <div className="pointer-events-none flex items-center"> | |
| 109 | - <ChevronUpDownIcon className="h-3 w-3" aria-hidden="true" /> | |
| 110 | - </div> | |
| 111 | - )} | |
| 112 | - </ListboxButton> | |
| 113 | - <Transition> | |
| 114 | - <ListboxOptions | |
| 115 | - style={{ borderRadius: defaultBorderRadius }} | |
| 116 | - className="min-w-40" | |
| 117 | - > | |
| 118 | - {[...models] | |
| 119 | - .sort((a, b) => a.title.localeCompare(b.title)) | |
| 120 | - .map((option, idx) => { | |
| 121 | - const isConfigInvalid = | |
| 122 | - option.configurationStatus !== | |
| 123 | - LLMConfigurationStatuses.VALID; | |
| 124 | - let invalidMessage = "(Invalid config)"; | |
| 125 | - if ( | |
| 126 | - option.configurationStatus === | |
| 127 | - LLMConfigurationStatuses.MISSING_ENV_SECRET | |
| 128 | - ) { | |
| 129 | - invalidMessage = "(Missing env secret)"; | |
| 130 | - } | |
| 131 | - if ( | |
| 132 | - option.configurationStatus === | |
| 133 | - LLMConfigurationStatuses.MISSING_API_KEY | |
| 134 | - ) { | |
| 135 | - invalidMessage = "(Missing API Key)"; | |
| 136 | - } | |
| 137 | - | |
| 138 | - return ( | |
| 139 | - <ListboxOption | |
| 140 | - key={idx} | |
| 141 | - value={option.title} | |
| 142 | - disabled={isConfigInvalid} | |
| 143 | - onMouseEnter={() => setHoveredIdx(idx)} | |
| 144 | - onMouseLeave={() => setHoveredIdx(null)} | |
| 145 | - onClick={(e: any) => | |
| 146 | - handleOptionClick(isConfigInvalid, e) | |
| 147 | - } | |
| 148 | - className="" | |
| 149 | - > | |
| 150 | - <div className="flex flex-col gap-0.5"> | |
| 151 | - <div className="flex flex-1 flex-row items-center justify-between gap-2"> | |
| 152 | - <div className="flex flex-1 flex-row items-center gap-2"> | |
| 153 | - <CubeIcon className="h-3 w-3 flex-shrink-0" /> | |
| 154 | - <span | |
| 155 | - className="line-clamp-1 flex-1" | |
| 156 | - style={{ fontSize: fontSize(-3) }} | |
| 157 | - > | |
| 158 | - {option.title} | |
| 159 | - {isConfigInvalid && ( | |
| 160 | - <span className="ml-2 text-[10px] italic"> | |
| 161 | - {invalidMessage} | |
| 162 | - </span> | |
| 163 | - )} | |
| 164 | - </span> | |
| 165 | - </div> | |
| 166 | - | |
| 167 | - <div className="flex flex-shrink-0 flex-row items-center gap-1"> | |
| 168 | - {hoveredIdx === idx && ( | |
| 169 | - <Cog6ToothIcon | |
| 170 | - className="h-3 w-3 flex-shrink-0" | |
| 171 | - onClick={(e: MouseEvent<SVGSVGElement>) => | |
| 172 | - onClickGear(e, option) | |
| 173 | - } | |
| 174 | - /> | |
| 175 | - )} | |
| 176 | - {option.title === selectedModel?.title && ( | |
| 177 | - <CheckIcon className="h-3 w-3 flex-shrink-0" /> | |
| 178 | - )} | |
| 179 | - </div> | |
| 180 | - </div> | |
| 181 | - </div> | |
| 182 | - </ListboxOption> | |
| 183 | - ); | |
| 184 | - })} | |
| 185 | - </ListboxOptions> | |
| 186 | - </Transition> | |
| 187 | - </> | |
| 188 | - )} | |
| 189 | - </div> | |
| 190 | - </Listbox> | |
| 191 | - </> | |
| 192 | - ); | |
| 193 | -}; | |
| 194 | - | |
| 195 | -export default ModelRoleSelector; |
deleted gui/src/pages/config/MoreHelpRow.tsx +0 −27
| @@ -1,27 +0,0 @@ | ||
| 1 | -interface MoreHelpRowProps { | |
| 2 | - title: string; | |
| 3 | - description: string; | |
| 4 | - onClick?: () => void; | |
| 5 | - href?: string; | |
| 6 | - Icon: any; | |
| 7 | -} | |
| 8 | - | |
| 9 | -function MoreHelpRow({ title, description, onClick, Icon }: MoreHelpRowProps) { | |
| 10 | - return ( | |
| 11 | - <div | |
| 12 | - className="hover:bg-lightgray/30 flex cursor-pointer items-center justify-between gap-2 rounded px-4 py-2" | |
| 13 | - onClick={onClick} | |
| 14 | - > | |
| 15 | - <div className="flex w-4/5 flex-col justify-center"> | |
| 16 | - <h3 className="my-0 text-sm">{title}</h3> | |
| 17 | - <span className="text-lightgray py-1 text-xs">{description}</span> | |
| 18 | - </div> | |
| 19 | - | |
| 20 | - <div className="text-lightgray flex h-5 w-1/5 w-5 cursor-pointer justify-end"> | |
| 21 | - <Icon /> | |
| 22 | - </div> | |
| 23 | - </div> | |
| 24 | - ); | |
| 25 | -} | |
| 26 | - | |
| 27 | -export default MoreHelpRow; |
deleted gui/src/pages/config/UserSettingsForm.tsx +0 −518
| @@ -1,518 +0,0 @@ | ||
| 1 | -import { | |
| 2 | - CheckIcon, | |
| 3 | - ChevronRightIcon, | |
| 4 | - ExclamationTriangleIcon, | |
| 5 | - InformationCircleIcon, | |
| 6 | - XMarkIcon, | |
| 7 | -} from "@heroicons/react/24/outline"; | |
| 8 | -import { | |
| 9 | - SharedConfigSchema, | |
| 10 | - modifyAnyConfigWithSharedConfig, | |
| 11 | -} from "core/config/sharedConfig"; | |
| 12 | -import { HubSessionInfo } from "core/control-plane/AuthTypes"; | |
| 13 | -import { useContext, useEffect, useState } from "react"; | |
| 14 | -import { Input } from "../../components"; | |
| 15 | -import NumberInput from "../../components/gui/NumberInput"; | |
| 16 | -import { Select } from "../../components/gui/Select"; | |
| 17 | -import ToggleSwitch from "../../components/gui/Switch"; | |
| 18 | -import { ToolTip } from "../../components/gui/Tooltip"; | |
| 19 | -import { useFontSize } from "../../components/ui/font"; | |
| 20 | -import { useAuth } from "../../context/Auth"; | |
| 21 | -import { IdeMessengerContext } from "../../context/IdeMessenger"; | |
| 22 | -import { useAppDispatch, useAppSelector } from "../../redux/hooks"; | |
| 23 | -import { updateConfig } from "../../redux/slices/configSlice"; | |
| 24 | -import { selectCurrentOrg } from "../../redux/slices/profilesSlice"; | |
| 25 | -import { isContinueTeamMember } from "../../util/isContinueTeamMember"; | |
| 26 | -import { setLocalStorage } from "../../util/localStorage"; | |
| 27 | -import { ContinueFeaturesMenu } from "./ContinueFeaturesMenu"; | |
| 28 | - | |
| 29 | -export function UserSettingsForm() { | |
| 30 | - /////// User settings section ////// | |
| 31 | - const dispatch = useAppDispatch(); | |
| 32 | - const ideMessenger = useContext(IdeMessengerContext); | |
| 33 | - const config = useAppSelector((state) => state.config.config); | |
| 34 | - const currentOrg = useAppSelector(selectCurrentOrg); | |
| 35 | - | |
| 36 | - const [showExperimental, setShowExperimental] = useState(false); | |
| 37 | - const { session } = useAuth(); | |
| 38 | - | |
| 39 | - function handleUpdate(sharedConfig: SharedConfigSchema) { | |
| 40 | - // Optimistic update | |
| 41 | - const updatedConfig = modifyAnyConfigWithSharedConfig(config, sharedConfig); | |
| 42 | - dispatch(updateConfig(updatedConfig)); | |
| 43 | - // IMPORTANT no need for model role updates (separate logic for selected model roles) | |
| 44 | - // simply because this function won't be used to update model roles | |
| 45 | - | |
| 46 | - // Actual update to core which propagates back with config update event | |
| 47 | - ideMessenger.post("config/updateSharedConfig", sharedConfig); | |
| 48 | - } | |
| 49 | - | |
| 50 | - // Disable autocomplete | |
| 51 | - const disableAutocompleteInFiles = ( | |
| 52 | - config.tabAutocompleteOptions?.disableInFiles ?? [] | |
| 53 | - ).join(", "); | |
| 54 | - const [formDisableAutocomplete, setFormDisableAutocomplete] = useState( | |
| 55 | - disableAutocompleteInFiles, | |
| 56 | - ); | |
| 57 | - | |
| 58 | - useEffect(() => { | |
| 59 | - // Necessary so that reformatted/trimmed values don't cause dirty state | |
| 60 | - setFormDisableAutocomplete(disableAutocompleteInFiles); | |
| 61 | - }, [disableAutocompleteInFiles]); | |
| 62 | - | |
| 63 | - // Workspace prompts | |
| 64 | - const promptPath = config.experimental?.promptPath || ""; | |
| 65 | - const [formPromptPath, setFormPromptPath] = useState(promptPath); | |
| 66 | - const cancelChangePromptPath = () => { | |
| 67 | - setFormPromptPath(promptPath); | |
| 68 | - }; | |
| 69 | - const handleSubmitPromptPath = () => { | |
| 70 | - handleUpdate({ | |
| 71 | - promptPath: formPromptPath || "", | |
| 72 | - }); | |
| 73 | - }; | |
| 74 | - | |
| 75 | - const handleEnableStaticContextualizationToggle = (value: boolean) => { | |
| 76 | - handleUpdate({ enableStaticContextualization: value }); | |
| 77 | - }; | |
| 78 | - | |
| 79 | - useEffect(() => { | |
| 80 | - // Necessary so that reformatted/trimmed values don't cause dirty state | |
| 81 | - setFormPromptPath(promptPath); | |
| 82 | - }, [promptPath]); | |
| 83 | - | |
| 84 | - // TODO defaults are in multiple places, should be consolidated and probably not explicit here | |
| 85 | - const showSessionTabs = config.ui?.showSessionTabs ?? false; | |
| 86 | - const continueAfterToolRejection = | |
| 87 | - config.ui?.continueAfterToolRejection ?? false; | |
| 88 | - const codeWrap = config.ui?.codeWrap ?? false; | |
| 89 | - const showChatScrollbar = config.ui?.showChatScrollbar ?? false; | |
| 90 | - const readResponseTTS = config.experimental?.readResponseTTS ?? false; | |
| 91 | - const autoAcceptEditToolDiffs = config.ui?.autoAcceptEditToolDiffs ?? false; | |
| 92 | - const displayRawMarkdown = config.ui?.displayRawMarkdown ?? false; | |
| 93 | - const disableSessionTitles = config.disableSessionTitles ?? false; | |
| 94 | - const useCurrentFileAsContext = | |
| 95 | - config.experimental?.useCurrentFileAsContext ?? false; | |
| 96 | - const enableExperimentalTools = | |
| 97 | - config.experimental?.enableExperimentalTools ?? false; | |
| 98 | - const onlyUseSystemMessageTools = | |
| 99 | - config.experimental?.onlyUseSystemMessageTools ?? false; | |
| 100 | - const codebaseToolCallingOnly = | |
| 101 | - config.experimental?.codebaseToolCallingOnly ?? false; | |
| 102 | - const enableStaticContextualization = | |
| 103 | - config.experimental?.enableStaticContextualization ?? false; | |
| 104 | - | |
| 105 | - const allowAnonymousTelemetry = config.allowAnonymousTelemetry ?? true; | |
| 106 | - const disableIndexing = config.disableIndexing ?? false; | |
| 107 | - | |
| 108 | - // const useAutocompleteCache = config.tabAutocompleteOptions?.useCache ?? true; | |
| 109 | - // const useChromiumForDocsCrawling = | |
| 110 | - // config.experimental?.useChromiumForDocsCrawling ?? false; | |
| 111 | - // const codeBlockToolbarPosition = config.ui?.codeBlockToolbarPosition ?? "top"; | |
| 112 | - const useAutocompleteMultilineCompletions = | |
| 113 | - config.tabAutocompleteOptions?.multilineCompletions ?? "auto"; | |
| 114 | - const modelTimeout = config.tabAutocompleteOptions?.modelTimeout ?? 150; | |
| 115 | - const debounceDelay = config.tabAutocompleteOptions?.debounceDelay ?? 250; | |
| 116 | - const fontSize = useFontSize(); | |
| 117 | - | |
| 118 | - const cancelChangeDisableAutocomplete = () => { | |
| 119 | - setFormDisableAutocomplete(disableAutocompleteInFiles); | |
| 120 | - }; | |
| 121 | - const handleDisableAutocompleteSubmit = () => { | |
| 122 | - handleUpdate({ | |
| 123 | - disableAutocompleteInFiles: formDisableAutocomplete | |
| 124 | - .split(",") | |
| 125 | - .map((val) => val.trim()) | |
| 126 | - .filter((val) => !!val), | |
| 127 | - }); | |
| 128 | - }; | |
| 129 | - | |
| 130 | - const [hubEnabled, setHubEnabled] = useState(false); | |
| 131 | - useEffect(() => { | |
| 132 | - void ideMessenger.ide | |
| 133 | - .getIdeSettings() | |
| 134 | - .then(({ continueTestEnvironment }) => { | |
| 135 | - setHubEnabled(continueTestEnvironment === "production"); | |
| 136 | - }); | |
| 137 | - }, [ideMessenger]); | |
| 138 | - | |
| 139 | - const hasContinueEmail = isContinueTeamMember( | |
| 140 | - (session as HubSessionInfo)?.account?.id, | |
| 141 | - ); | |
| 142 | - | |
| 143 | - const disableTelemetryToggle = | |
| 144 | - currentOrg?.policy?.allowAnonymousTelemetry === false; | |
| 145 | - const disableIndexingToggle = | |
| 146 | - currentOrg?.policy?.allowCodebaseIndexing === false; | |
| 147 | - | |
| 148 | - return ( | |
| 149 | - <div className="flex flex-col"> | |
| 150 | - {/* {selectedProfile && isLocalProfile(selectedProfile) ? ( | |
| 151 | - <div className="flex items-center justify-center"> | |
| 152 | - <SecondaryButton | |
| 153 | - className="flex flex-row items-center gap-1" | |
| 154 | - onClick={() => { | |
| 155 | - ideMessenger.post("config/openProfile", { | |
| 156 | - profileId: selectedProfile.id, | |
| 157 | - }); | |
| 158 | - }} | |
| 159 | - > | |
| 160 | - <span>Open</span> | |
| 161 | - <span>Config</span> | |
| 162 | - <span className="xs:flex hidden">File</span> | |
| 163 | - </SecondaryButton> | |
| 164 | - </div> | |
| 165 | - ) : null} */} | |
| 166 | - {hubEnabled ? ( | |
| 167 | - <div className="flex flex-col gap-4 py-4"> | |
| 168 | - <div> | |
| 169 | - <h2 className="mb-2 mt-0 p-0">User settings</h2> | |
| 170 | - </div> | |
| 171 | - | |
| 172 | - <div className="flex flex-col gap-4"> | |
| 173 | - <ToggleSwitch | |
| 174 | - isToggled={showSessionTabs} | |
| 175 | - onToggle={() => | |
| 176 | - handleUpdate({ | |
| 177 | - showSessionTabs: !showSessionTabs, | |
| 178 | - }) | |
| 179 | - } | |
| 180 | - text="Show Session Tabs" | |
| 181 | - tooltip="If on, displays tabs above the chat as an alternative way to organize and access your sessions." | |
| 182 | - /> | |
| 183 | - <ToggleSwitch | |
| 184 | - isToggled={codeWrap} | |
| 185 | - onToggle={() => | |
| 186 | - handleUpdate({ | |
| 187 | - codeWrap: !codeWrap, | |
| 188 | - }) | |
| 189 | - } | |
| 190 | - text="Wrap Codeblocks" | |
| 191 | - tooltip="If on, displays tabs above the chat as an alternative way to organize and access your sessions." | |
| 192 | - /> | |
| 193 | - | |
| 194 | - <ToggleSwitch | |
| 195 | - isToggled={showChatScrollbar} | |
| 196 | - onToggle={() => | |
| 197 | - handleUpdate({ | |
| 198 | - showChatScrollbar: !showChatScrollbar, | |
| 199 | - }) | |
| 200 | - } | |
| 201 | - text="Show Chat Scrollbar" | |
| 202 | - tooltip="If on, enables a scrollbar in the chat window." | |
| 203 | - /> | |
| 204 | - <ToggleSwitch | |
| 205 | - isToggled={readResponseTTS} | |
| 206 | - onToggle={() => | |
| 207 | - handleUpdate({ | |
| 208 | - readResponseTTS: !readResponseTTS, | |
| 209 | - }) | |
| 210 | - } | |
| 211 | - text="Text-to-Speech Output" | |
| 212 | - tooltip="If on, reads LLM responses aloud with TTS." | |
| 213 | - /> | |
| 214 | - {/* <ToggleSwitch | |
| 215 | - isToggled={useChromiumForDocsCrawling} | |
| 216 | - onToggle={() => | |
| 217 | - handleUpdate({ | |
| 218 | - useChromiumForDocsCrawling: !useChromiumForDocsCrawling, | |
| 219 | - }) | |
| 220 | - } | |
| 221 | - text="Use Chromium for Docs Crawling" | |
| 222 | - /> */} | |
| 223 | - <ToggleSwitch | |
| 224 | - isToggled={!disableSessionTitles} | |
| 225 | - onToggle={() => | |
| 226 | - handleUpdate({ | |
| 227 | - disableSessionTitles: !disableSessionTitles, | |
| 228 | - }) | |
| 229 | - } | |
| 230 | - text="Enable Session Titles" | |
| 231 | - tooltip="If on, generates summary titles for each chat session after the first message, using the current Chat model." | |
| 232 | - /> | |
| 233 | - <ToggleSwitch | |
| 234 | - isToggled={!displayRawMarkdown} | |
| 235 | - onToggle={() => | |
| 236 | - handleUpdate({ | |
| 237 | - displayRawMarkdown: !displayRawMarkdown, | |
| 238 | - }) | |
| 239 | - } | |
| 240 | - text="Format Markdown" | |
| 241 | - tooltip="If off, shows responses as raw text." | |
| 242 | - /> | |
| 243 | - | |
| 244 | - <ToggleSwitch | |
| 245 | - isToggled={allowAnonymousTelemetry} | |
| 246 | - disabled={disableTelemetryToggle} | |
| 247 | - onToggle={() => | |
| 248 | - handleUpdate({ | |
| 249 | - allowAnonymousTelemetry: !allowAnonymousTelemetry, | |
| 250 | - }) | |
| 251 | - } | |
| 252 | - text="Allow Anonymous Telemetry" | |
| 253 | - tooltip="If on, allows Continue to send anonymous telemetry." | |
| 254 | - /> | |
| 255 | - | |
| 256 | - <ToggleSwitch | |
| 257 | - isToggled={!disableIndexing} | |
| 258 | - disabled={disableIndexingToggle} | |
| 259 | - onToggle={() => | |
| 260 | - handleUpdate({ | |
| 261 | - disableIndexing: !disableIndexing, | |
| 262 | - }) | |
| 263 | - } | |
| 264 | - text="Enable Indexing" | |
| 265 | - /> | |
| 266 | - | |
| 267 | - {/* <ToggleSwitch | |
| 268 | - isToggled={useAutocompleteCache} | |
| 269 | - onToggle={() => | |
| 270 | - handleUpdate({ | |
| 271 | - useAutocompleteCache: !useAutocompleteCache, | |
| 272 | - }) | |
| 273 | - } | |
| 274 | - text="Use Autocomplete Cache" | |
| 275 | - /> */} | |
| 276 | - | |
| 277 | - <label className="flex items-center justify-between gap-3"> | |
| 278 | - <span className="flex items-center gap-x-1 text-left"> | |
| 279 | - Font Size{" "} | |
| 280 | - <ToolTip content="Specifies base font size for UI elements"> | |
| 281 | - <InformationCircleIcon className="h-3 w-3" /> | |
| 282 | - </ToolTip> | |
| 283 | - </span> | |
| 284 | - <NumberInput | |
| 285 | - value={fontSize} | |
| 286 | - onChange={(val) => { | |
| 287 | - setLocalStorage("fontSize", val); | |
| 288 | - handleUpdate({ | |
| 289 | - fontSize: val, | |
| 290 | - }); | |
| 291 | - }} | |
| 292 | - min={7} | |
| 293 | - max={50} | |
| 294 | - /> | |
| 295 | - </label> | |
| 296 | - <label className="flex items-center justify-between gap-3"> | |
| 297 | - <span className="lines lines-1 flex items-center gap-x-1 text-left"> | |
| 298 | - Multiline Autocompletions | |
| 299 | - <ToolTip content="Controls multiline completions for autocomplete."> | |
| 300 | - <InformationCircleIcon className="h-3 w-3" /> | |
| 301 | - </ToolTip> | |
| 302 | - </span> | |
| 303 | - <Select | |
| 304 | - value={useAutocompleteMultilineCompletions} | |
| 305 | - onChange={(e) => | |
| 306 | - handleUpdate({ | |
| 307 | - useAutocompleteMultilineCompletions: e.target.value as | |
| 308 | - | "auto" | |
| 309 | - | "always" | |
| 310 | - | "never", | |
| 311 | - }) | |
| 312 | - } | |
| 313 | - > | |
| 314 | - <option value="auto">Auto</option> | |
| 315 | - <option value="always">Always</option> | |
| 316 | - <option value="never">Never</option> | |
| 317 | - </Select> | |
| 318 | - </label> | |
| 319 | - <label className="flex items-center justify-between gap-3"> | |
| 320 | - <span className="flex items-center gap-x-1 text-left"> | |
| 321 | - Autocomplete Timeout (ms) | |
| 322 | - <ToolTip content="Maximum time in milliseconds for autocomplete request/retrieval."> | |
| 323 | - <InformationCircleIcon className="h-3 w-3" /> | |
| 324 | - </ToolTip> | |
| 325 | - </span> | |
| 326 | - <NumberInput | |
| 327 | - value={modelTimeout} | |
| 328 | - onChange={(val) => | |
| 329 | - handleUpdate({ | |
| 330 | - modelTimeout: val, | |
| 331 | - }) | |
| 332 | - } | |
| 333 | - min={100} | |
| 334 | - max={5000} | |
| 335 | - /> | |
| 336 | - </label> | |
| 337 | - <label className="flex items-center justify-between gap-3"> | |
| 338 | - <span className="flex items-center gap-x-1 text-left"> | |
| 339 | - Autocomplete Debounce (ms) | |
| 340 | - <ToolTip content="Minimum time in milliseconds to trigger an autocomplete request after a change."> | |
| 341 | - <InformationCircleIcon className="h-3 w-3" /> | |
| 342 | - </ToolTip> | |
| 343 | - </span> | |
| 344 | - <NumberInput | |
| 345 | - value={debounceDelay} | |
| 346 | - onChange={(val) => | |
| 347 | - handleUpdate({ | |
| 348 | - debounceDelay: val, | |
| 349 | - }) | |
| 350 | - } | |
| 351 | - min={0} | |
| 352 | - max={2500} | |
| 353 | - /> | |
| 354 | - </label> | |
| 355 | - <form | |
| 356 | - className="flex flex-col gap-1" | |
| 357 | - onSubmit={(e) => { | |
| 358 | - e.preventDefault(); | |
| 359 | - handleDisableAutocompleteSubmit(); | |
| 360 | - }} | |
| 361 | - > | |
| 362 | - <div className="flex items-center justify-between"> | |
| 363 | - <span className="flex items-center gap-x-1"> | |
| 364 | - Disable autocomplete in files | |
| 365 | - <ToolTip content="List of comma-separated glob pattern to disable autocomplete in matching files. E.g., **/*.{txt,md}"> | |
| 366 | - <InformationCircleIcon className="h-3 w-3" /> | |
| 367 | - </ToolTip> | |
| 368 | - </span> | |
| 369 | - <div className="flex items-center gap-2"> | |
| 370 | - <Input | |
| 371 | - value={formDisableAutocomplete} | |
| 372 | - className="max-w-[100px]" | |
| 373 | - onChange={(e) => { | |
| 374 | - setFormDisableAutocomplete(e.target.value); | |
| 375 | - }} | |
| 376 | - /> | |
| 377 | - <div className="flex h-full flex-col"> | |
| 378 | - {formDisableAutocomplete !== disableAutocompleteInFiles ? ( | |
| 379 | - <> | |
| 380 | - <div | |
| 381 | - onClick={handleDisableAutocompleteSubmit} | |
| 382 | - className="cursor-pointer" | |
| 383 | - > | |
| 384 | - <CheckIcon className="h-4 w-4 text-green-500 hover:opacity-80" /> | |
| 385 | - </div> | |
| 386 | - <div | |
| 387 | - onClick={cancelChangeDisableAutocomplete} | |
| 388 | - className="cursor-pointer" | |
| 389 | - > | |
| 390 | - <XMarkIcon className="h-4 w-4 text-red-500 hover:opacity-80" /> | |
| 391 | - </div> | |
| 392 | - </> | |
| 393 | - ) : ( | |
| 394 | - <div> | |
| 395 | - <CheckIcon className="text-vsc-foreground-muted h-4 w-4" /> | |
| 396 | - </div> | |
| 397 | - )} | |
| 398 | - </div> | |
| 399 | - </div> | |
| 400 | - </div> | |
| 401 | - <span className="text-vsc-foreground-muted text-lightgray self-end text-xs"> | |
| 402 | - Comma-separated list of path matchers | |
| 403 | - </span> | |
| 404 | - </form> | |
| 405 | - </div> | |
| 406 | - | |
| 407 | - <div className="flex flex-col gap-x-2 gap-y-4"> | |
| 408 | - <div | |
| 409 | - className="flex cursor-pointer items-center gap-2 text-left text-sm font-semibold" | |
| 410 | - onClick={() => setShowExperimental(!showExperimental)} | |
| 411 | - > | |
| 412 | - <ChevronRightIcon | |
| 413 | - className={`h-4 w-4 transition-transform ${ | |
| 414 | - showExperimental ? "rotate-90" : "" | |
| 415 | - }`} | |
| 416 | - /> | |
| 417 | - <span>Experimental Settings</span> | |
| 418 | - </div> | |
| 419 | - <div | |
| 420 | - className={`duration-400 overflow-hidden transition-all ease-in-out ${ | |
| 421 | - showExperimental | |
| 422 | - ? "max-h-96" /* Increased from max-h-40 to max-h-96 to accommodate ContinueFeaturesMenu */ | |
| 423 | - : "max-h-0" | |
| 424 | - }`} | |
| 425 | - > | |
| 426 | - <div className="flex flex-col gap-x-1 gap-y-4 pl-6"> | |
| 427 | - <ToggleSwitch | |
| 428 | - isToggled={autoAcceptEditToolDiffs} | |
| 429 | - onToggle={() => | |
| 430 | - handleUpdate({ | |
| 431 | - autoAcceptEditToolDiffs: !autoAcceptEditToolDiffs, | |
| 432 | - }) | |
| 433 | - } | |
| 434 | - text="Auto-Accept Agent Edits" | |
| 435 | - tooltip="If on, diffs generated by the edit tool are | |
| 436 | - automatically accepted and Agent proceeds with the next conversational turn." | |
| 437 | - showIfToggled={ | |
| 438 | - <> | |
| 439 | - <ToolTip | |
| 440 | - content={`Be very careful with this setting. When turned on, Agent mode's edit tool can make changes to files with no manual review or guaranteed stopping point`} | |
| 441 | - > | |
| 442 | - <ExclamationTriangleIcon className="h-3 w-3 text-yellow-500" /> | |
| 443 | - </ToolTip> | |
| 444 | - </> | |
| 445 | - } | |
| 446 | - /> | |
| 447 | - | |
| 448 | - <ToggleSwitch | |
| 449 | - isToggled={useCurrentFileAsContext} | |
| 450 | - onToggle={() => | |
| 451 | - handleUpdate({ | |
| 452 | - useCurrentFileAsContext: !useCurrentFileAsContext, | |
| 453 | - }) | |
| 454 | - } | |
| 455 | - text="Add Current File by Default" | |
| 456 | - tooltip="If on, the currently open file is added as context in every new conversation." | |
| 457 | - /> | |
| 458 | - | |
| 459 | - <ToggleSwitch | |
| 460 | - isToggled={enableExperimentalTools} | |
| 461 | - onToggle={() => | |
| 462 | - handleUpdate({ | |
| 463 | - enableExperimentalTools: !enableExperimentalTools, | |
| 464 | - }) | |
| 465 | - } | |
| 466 | - text="Enable experimental tools" | |
| 467 | - /> | |
| 468 | - | |
| 469 | - <ToggleSwitch | |
| 470 | - isToggled={onlyUseSystemMessageTools} | |
| 471 | - onToggle={() => | |
| 472 | - handleUpdate({ | |
| 473 | - onlyUseSystemMessageTools: !onlyUseSystemMessageTools, | |
| 474 | - }) | |
| 475 | - } | |
| 476 | - tooltip="If on, Continue will not attempt to use native tool calling and will only use system message tools." | |
| 477 | - text="Only use system message tools" | |
| 478 | - /> | |
| 479 | - | |
| 480 | - <ToggleSwitch | |
| 481 | - isToggled={codebaseToolCallingOnly} | |
| 482 | - onToggle={() => | |
| 483 | - handleUpdate({ | |
| 484 | - codebaseToolCallingOnly: !codebaseToolCallingOnly, | |
| 485 | - }) | |
| 486 | - } | |
| 487 | - text="@Codebase: use tool calling only" | |
| 488 | - /> | |
| 489 | - | |
| 490 | - <ToggleSwitch | |
| 491 | - isToggled={continueAfterToolRejection} | |
| 492 | - onToggle={() => | |
| 493 | - handleUpdate({ | |
| 494 | - continueAfterToolRejection: !continueAfterToolRejection, | |
| 495 | - }) | |
| 496 | - } | |
| 497 | - text="Stream after tool rejection" | |
| 498 | - tooltip="If on, streaming will continue after the tool call is rejected." | |
| 499 | - /> | |
| 500 | - | |
| 501 | - {hasContinueEmail && ( | |
| 502 | - <ContinueFeaturesMenu | |
| 503 | - enableStaticContextualization={ | |
| 504 | - enableStaticContextualization | |
| 505 | - } | |
| 506 | - handleEnableStaticContextualizationToggle={ | |
| 507 | - handleEnableStaticContextualizationToggle | |
| 508 | - } | |
| 509 | - /> | |
| 510 | - )} | |
| 511 | - </div> | |
| 512 | - </div> | |
| 513 | - </div> | |
| 514 | - </div> | |
| 515 | - ) : null} | |
| 516 | - </div> | |
| 517 | - ); | |
| 518 | -} |
added gui/src/pages/config/components/ConfigHeader.tsx +48 −0
| @@ -0,0 +1,48 @@ | ||
| 1 | +import { PlusIcon } from "@heroicons/react/24/outline"; | |
| 2 | +import { ToolTip } from "../../../components/gui/Tooltip"; | |
| 3 | +import { Button } from "../../../components/ui"; | |
| 4 | + | |
| 5 | +interface ConfigHeaderProps { | |
| 6 | + title: string; | |
| 7 | + subtext?: string; | |
| 8 | + onAddClick?: () => void; | |
| 9 | + addButtonTooltip?: string; | |
| 10 | + className?: string; | |
| 11 | + variant?: "default" | "sm"; | |
| 12 | +} | |
| 13 | + | |
| 14 | +export function ConfigHeader({ | |
| 15 | + title, | |
| 16 | + subtext, | |
| 17 | + onAddClick, | |
| 18 | + addButtonTooltip = "Add item", | |
| 19 | + className = "", | |
| 20 | + variant = "default", | |
| 21 | +}: ConfigHeaderProps) { | |
| 22 | + const isSmall = variant === "sm"; | |
| 23 | + const marginBottom = isSmall ? "mb-4" : "mb-6"; | |
| 24 | + const titleSize = isSmall ? "text-sm font-semibold" : "text-xl font-semibold"; | |
| 25 | + const HeadingTag = isSmall ? "h3" : "h2"; | |
| 26 | + | |
| 27 | + return ( | |
| 28 | + <div | |
| 29 | + className={`${marginBottom} flex items-center justify-between ${className}`} | |
| 30 | + > | |
| 31 | + <div className="flex flex-col"> | |
| 32 | + <HeadingTag className={`my-0 ${titleSize}`}>{title}</HeadingTag> | |
| 33 | + {subtext && <p className="text-description mt-1 text-sm">{subtext}</p>} | |
| 34 | + </div> | |
| 35 | + {onAddClick && ( | |
| 36 | + <ToolTip content={addButtonTooltip}> | |
| 37 | + <Button | |
| 38 | + onClick={onAddClick} | |
| 39 | + variant="icon" | |
| 40 | + size={isSmall ? "sm" : "lg"} | |
| 41 | + > | |
| 42 | + <PlusIcon className={isSmall ? "h-2.5 w-2.5" : "h-3 w-3"} /> | |
| 43 | + </Button> | |
| 44 | + </ToolTip> | |
| 45 | + )} | |
| 46 | + </div> | |
| 47 | + ); | |
| 48 | +} |
added gui/src/pages/config/components/ConfigItemSelect.tsx +91 −0
| @@ -0,0 +1,91 @@ | ||
| 1 | +/** | |
| 2 | + * A component that displays config items either as tabs (on large screens) or a popover select (on small screens) | |
| 3 | + */ | |
| 4 | +interface ConfigItemSelectProps { | |
| 5 | + items: { | |
| 6 | + id: string; | |
| 7 | + label: string; | |
| 8 | + icon: React.ReactNode; | |
| 9 | + }[]; | |
| 10 | + activeId: string; | |
| 11 | + onSelect: (id: string) => void; | |
| 12 | +} | |
| 13 | + | |
| 14 | +import { ChevronDownIcon } from "@heroicons/react/24/outline"; | |
| 15 | +import { | |
| 16 | + Popover, | |
| 17 | + PopoverButton, | |
| 18 | + PopoverPanel, | |
| 19 | + Transition, | |
| 20 | +} from "../../../components/ui"; | |
| 21 | +import { fontSize } from "../../../util"; | |
| 22 | + | |
| 23 | +export function ConfigItemSelect({ | |
| 24 | + items, | |
| 25 | + activeId, | |
| 26 | + onSelect, | |
| 27 | +}: ConfigItemSelectProps) { | |
| 28 | + const activeItem = items.find((item) => item.id === activeId); | |
| 29 | + | |
| 30 | + const tabContent = ( | |
| 31 | + <div className="hidden border-0 border-b-[1px] border-solid border-b-zinc-700 p-0.5 sm:flex sm:justify-center md:grid md:grid-cols-2 md:gap-x-2"> | |
| 32 | + {items.map((item) => ( | |
| 33 | + <div | |
| 34 | + style={{ fontSize: fontSize(-2) }} | |
| 35 | + key={item.id} | |
| 36 | + className={`hover:bg-vsc-input-background flex cursor-pointer items-center justify-center gap-1.5 rounded-md px-2 py-2 ${ | |
| 37 | + activeId === item.id ? "" : "text-gray-400" | |
| 38 | + }`} | |
| 39 | + onClick={() => onSelect(item.id)} | |
| 40 | + > | |
| 41 | + {item.icon} | |
| 42 | + {item.label} | |
| 43 | + </div> | |
| 44 | + ))} | |
| 45 | + </div> | |
| 46 | + ); | |
| 47 | + | |
| 48 | + // Render popover on smaller screens | |
| 49 | + const popoverContent = ( | |
| 50 | + <div className="mt-2 px-1.5 sm:hidden"> | |
| 51 | + <Popover className="relative"> | |
| 52 | + <PopoverButton | |
| 53 | + className="flex w-full items-center justify-between gap-2 rounded-md border border-zinc-700 px-3 py-2" | |
| 54 | + style={{ fontSize: fontSize(-2) }} | |
| 55 | + > | |
| 56 | + <div className="flex items-center gap-2"> | |
| 57 | + {activeItem?.icon} | |
| 58 | + <span>{activeItem?.label}</span> | |
| 59 | + </div> | |
| 60 | + <ChevronDownIcon className="h-4 w-4" /> | |
| 61 | + </PopoverButton> | |
| 62 | + | |
| 63 | + <Transition> | |
| 64 | + <PopoverPanel className="bg-vsc-input-background absolute z-10 mt-1 w-full rounded-md border border-zinc-700 py-1"> | |
| 65 | + {items.map((item) => ( | |
| 66 | + <div | |
| 67 | + key={item.id} | |
| 68 | + className={`hover:bg-vsc-input-background flex cursor-pointer items-center gap-2 px-3 py-2 ${ | |
| 69 | + activeId === item.id ? "bg-vsc-input-background" : "" | |
| 70 | + }`} | |
| 71 | + onClick={() => { | |
| 72 | + onSelect(item.id); | |
| 73 | + }} | |
| 74 | + > | |
| 75 | + {item.icon} | |
| 76 | + <span>{item.label}</span> | |
| 77 | + </div> | |
| 78 | + ))} | |
| 79 | + </PopoverPanel> | |
| 80 | + </Transition> | |
| 81 | + </Popover> | |
| 82 | + </div> | |
| 83 | + ); | |
| 84 | + | |
| 85 | + return ( | |
| 86 | + <> | |
| 87 | + {tabContent} | |
| 88 | + {popoverContent} | |
| 89 | + </> | |
| 90 | + ); | |
| 91 | +} |
added gui/src/pages/config/components/ConfigRow.tsx +89 −0
| @@ -0,0 +1,89 @@ | ||
| 1 | +import React from "react"; | |
| 2 | +import { Button } from "../../../components/ui/Button"; | |
| 3 | +import { cn } from "../../../util/cn"; | |
| 4 | + | |
| 5 | +export interface ConfigRowProps { | |
| 6 | + title: string; | |
| 7 | + description: string; | |
| 8 | + icon?: React.ComponentType<React.SVGProps<SVGSVGElement>>; | |
| 9 | + onClick?: () => void; | |
| 10 | + disabled?: boolean; | |
| 11 | + children?: React.ReactNode; | |
| 12 | + className?: string; | |
| 13 | +} | |
| 14 | + | |
| 15 | +export function ConfigRow({ | |
| 16 | + title, | |
| 17 | + description, | |
| 18 | + icon: Icon, | |
| 19 | + onClick, | |
| 20 | + disabled = false, | |
| 21 | + children, | |
| 22 | + className = "", | |
| 23 | +}: ConfigRowProps) { | |
| 24 | + const baseClasses = | |
| 25 | + "flex items-start justify-between rounded-md transition-colors px-4 py-3"; | |
| 26 | + const interactiveClasses = onClick | |
| 27 | + ? "hover:bg-list-hover cursor-pointer" | |
| 28 | + : ""; | |
| 29 | + const disabledClasses = disabled ? "opacity-50 cursor-not-allowed" : ""; | |
| 30 | + | |
| 31 | + const handleClick = (event: React.MouseEvent) => { | |
| 32 | + if (!disabled && onClick) { | |
| 33 | + const target = event.target as HTMLElement; | |
| 34 | + const isInteractiveChild = target.closest( | |
| 35 | + 'button, input, textarea, select, [role="button"], [role="switch"]', | |
| 36 | + ); | |
| 37 | + | |
| 38 | + if ( | |
| 39 | + !isInteractiveChild || | |
| 40 | + target.closest("[data-config-row]") === event.currentTarget | |
| 41 | + ) { | |
| 42 | + onClick(); | |
| 43 | + } | |
| 44 | + } | |
| 45 | + }; | |
| 46 | + | |
| 47 | + if (onClick) { | |
| 48 | + return ( | |
| 49 | + <Button | |
| 50 | + variant="ghost" | |
| 51 | + className={cn( | |
| 52 | + baseClasses, | |
| 53 | + interactiveClasses, | |
| 54 | + disabledClasses, | |
| 55 | + "!my-0 text-left", | |
| 56 | + className, | |
| 57 | + )} | |
| 58 | + onClick={handleClick} | |
| 59 | + disabled={disabled} | |
| 60 | + data-config-row | |
| 61 | + > | |
| 62 | + <div className="flex flex-col"> | |
| 63 | + <span className="text-sm font-medium">{title}</span> | |
| 64 | + <p className="mt-0.5 text-xs text-gray-500">{description}</p> | |
| 65 | + </div> | |
| 66 | + <div className="flex items-center gap-4"> | |
| 67 | + {children} | |
| 68 | + {Icon && <Icon className="h-5 w-5 flex-shrink-0 text-gray-400" />} | |
| 69 | + </div> | |
| 70 | + </Button> | |
| 71 | + ); | |
| 72 | + } | |
| 73 | + | |
| 74 | + return ( | |
| 75 | + <div | |
| 76 | + className={cn(baseClasses, disabledClasses, className)} | |
| 77 | + data-config-row | |
| 78 | + > | |
| 79 | + <div className="flex flex-col"> | |
| 80 | + <span className="text-sm font-medium">{title}</span> | |
| 81 | + <p className="mt-0.5 text-xs text-gray-500">{description}</p> | |
| 82 | + </div> | |
| 83 | + <div className="flex items-center gap-4"> | |
| 84 | + {children} | |
| 85 | + {Icon && <Icon className="h-5 w-5 flex-shrink-0 text-gray-400" />} | |
| 86 | + </div> | |
| 87 | + </div> | |
| 88 | + ); | |
| 89 | +} |
added gui/src/pages/config/components/ConfigSection.tsx +22 −0
| @@ -0,0 +1,22 @@ | ||
| 1 | +import React from "react"; | |
| 2 | + | |
| 3 | +interface ConfigSectionProps { | |
| 4 | + title?: string; | |
| 5 | + children: React.ReactNode; | |
| 6 | + className?: string; | |
| 7 | +} | |
| 8 | + | |
| 9 | +// ConfigSection for internal section organization within pages | |
| 10 | +// Not used as page wrapper - that's handled by ConfigPageLayout | |
| 11 | +export function ConfigSection({ | |
| 12 | + title, | |
| 13 | + children, | |
| 14 | + className = "", | |
| 15 | +}: ConfigSectionProps) { | |
| 16 | + return ( | |
| 17 | + <div className={className}> | |
| 18 | + {title && <h3 className="mb-4 text-base font-semibold">{title}</h3>} | |
| 19 | + {children} | |
| 20 | + </div> | |
| 21 | + ); | |
| 22 | +} |
added gui/src/pages/config/components/ConfigSubsection.tsx +20 −0
| @@ -0,0 +1,20 @@ | ||
| 1 | +import React from "react"; | |
| 2 | + | |
| 3 | +interface ConfigSubsectionProps { | |
| 4 | + title?: string; | |
| 5 | + children: React.ReactNode; | |
| 6 | + className?: string; | |
| 7 | +} | |
| 8 | + | |
| 9 | +export function ConfigSubsection({ | |
| 10 | + title, | |
| 11 | + children, | |
| 12 | + className = "", | |
| 13 | +}: ConfigSubsectionProps) { | |
| 14 | + return ( | |
| 15 | + <div className={className}> | |
| 16 | + {title && <h3 className="mb-2 text-sm font-semibold">{title}</h3>} | |
| 17 | + {children} | |
| 18 | + </div> | |
| 19 | + ); | |
| 20 | +} |
added gui/src/pages/config/components/ContinueFeaturesMenu.tsx +29 −0
| @@ -0,0 +1,29 @@ | ||
| 1 | +import ToggleSwitch from "../../../components/gui/Switch"; | |
| 2 | +interface ContinueFeaturesMenuProps { | |
| 3 | + enableStaticContextualization: boolean; | |
| 4 | + handleEnableStaticContextualizationToggle: (value: boolean) => void; | |
| 5 | +} | |
| 6 | + | |
| 7 | +export function ContinueFeaturesMenu({ | |
| 8 | + enableStaticContextualization, | |
| 9 | + handleEnableStaticContextualizationToggle, | |
| 10 | +}: ContinueFeaturesMenuProps) { | |
| 11 | + return ( | |
| 12 | + <div className="flex w-full flex-col gap-y-4"> | |
| 13 | + <div className="my-2 text-center text-xs font-medium text-slate-400"> | |
| 14 | + 🚧 INTERNAL SETTINGS 🚧 | |
| 15 | + </div> | |
| 16 | + <div className="flex w-full flex-col gap-y-4"> | |
| 17 | + <ToggleSwitch | |
| 18 | + isToggled={enableStaticContextualization} | |
| 19 | + onToggle={() => | |
| 20 | + handleEnableStaticContextualizationToggle( | |
| 21 | + !enableStaticContextualization, | |
| 22 | + ) | |
| 23 | + } | |
| 24 | + text="Use Static Contextualization" | |
| 25 | + /> | |
| 26 | + </div> | |
| 27 | + </div> | |
| 28 | + ); | |
| 29 | +} |
added gui/src/pages/config/components/ModelRoleRow.tsx +68 −0
| @@ -0,0 +1,68 @@ | ||
| 1 | +import { ModelRole } from "@continuedev/config-yaml"; | |
| 2 | +import { Cog6ToothIcon } from "@heroicons/react/24/outline"; | |
| 3 | +import { ModelDescription } from "core"; | |
| 4 | +import { ReactNode } from "react"; | |
| 5 | +import { ToolTip } from "../../../components/gui/Tooltip"; | |
| 6 | +import { Button } from "../../../components/ui"; | |
| 7 | +import ModelRoleSelector from "./ModelRoleSelector"; | |
| 8 | + | |
| 9 | +interface ModelRoleRowProps { | |
| 10 | + role: ModelRole; | |
| 11 | + displayName: string; | |
| 12 | + description: string | ReactNode; | |
| 13 | + models: ModelDescription[]; | |
| 14 | + selectedModel: ModelDescription | undefined; | |
| 15 | + onSelect: (model: ModelDescription | null) => void; | |
| 16 | + onConfigure: (model: ModelDescription | null) => void; | |
| 17 | + setupURL: string; | |
| 18 | + shortcut?: ReactNode; | |
| 19 | +} | |
| 20 | + | |
| 21 | +export function ModelRoleRow({ | |
| 22 | + role, | |
| 23 | + displayName, | |
| 24 | + description, | |
| 25 | + models, | |
| 26 | + selectedModel, | |
| 27 | + onSelect, | |
| 28 | + onConfigure, | |
| 29 | + setupURL, | |
| 30 | + shortcut, | |
| 31 | +}: ModelRoleRowProps) { | |
| 32 | + return ( | |
| 33 | + <div className="py-6 first:pt-0 last:pb-0"> | |
| 34 | + <div className="mb-2"> | |
| 35 | + <div className="flex items-center gap-2"> | |
| 36 | + <span className="text-base font-medium">{displayName}</span> | |
| 37 | + {shortcut && shortcut} | |
| 38 | + </div> | |
| 39 | + <p className="text-description mt-1 text-xs">{description}</p> | |
| 40 | + </div> | |
| 41 | + <div className="flex items-center gap-2"> | |
| 42 | + <div className="flex-1"> | |
| 43 | + <ModelRoleSelector | |
| 44 | + displayName={displayName} | |
| 45 | + description={description} | |
| 46 | + models={models} | |
| 47 | + selectedModel={selectedModel ?? null} | |
| 48 | + onSelect={onSelect} | |
| 49 | + setupURL={setupURL} | |
| 50 | + hideTitle={true} | |
| 51 | + /> | |
| 52 | + </div> | |
| 53 | + {selectedModel && ( | |
| 54 | + <ToolTip content="Configure"> | |
| 55 | + <Button | |
| 56 | + variant="ghost" | |
| 57 | + size="sm" | |
| 58 | + onClick={() => onConfigure(selectedModel)} | |
| 59 | + className="text-description hover:enabled:text-foreground my-0 h-6 w-6 p-0" | |
| 60 | + > | |
| 61 | + <Cog6ToothIcon className="h-4 w-4 flex-shrink-0" /> | |
| 62 | + </Button> | |
| 63 | + </ToolTip> | |
| 64 | + )} | |
| 65 | + </div> | |
| 66 | + </div> | |
| 67 | + ); | |
| 68 | +} |
added gui/src/pages/config/components/ModelRoleSelector.tsx +179 −0
| @@ -0,0 +1,179 @@ | ||
| 1 | +import { | |
| 2 | + CheckIcon, | |
| 3 | + ChevronUpDownIcon, | |
| 4 | + CubeIcon, | |
| 5 | +} from "@heroicons/react/24/outline"; | |
| 6 | +import { ModelDescription } from "core"; | |
| 7 | +import { LLMConfigurationStatuses } from "core/llm/constants"; | |
| 8 | +import { MouseEvent, ReactNode, useContext } from "react"; | |
| 9 | +import { defaultBorderRadius } from "../../../components"; | |
| 10 | +import InfoHover from "../../../components/InfoHover"; | |
| 11 | +import { | |
| 12 | + Listbox, | |
| 13 | + ListboxButton, | |
| 14 | + ListboxOption, | |
| 15 | + ListboxOptions, | |
| 16 | + Transition, | |
| 17 | +} from "../../../components/ui"; | |
| 18 | +import { IdeMessengerContext } from "../../../context/IdeMessenger"; | |
| 19 | +import { fontSize } from "../../../util"; | |
| 20 | + | |
| 21 | +interface ModelRoleSelectorProps { | |
| 22 | + models: ModelDescription[]; | |
| 23 | + selectedModel: ModelDescription | null; | |
| 24 | + onSelect: (model: ModelDescription | null) => void; | |
| 25 | + displayName: string; | |
| 26 | + description: string | ReactNode; | |
| 27 | + setupURL: string; | |
| 28 | + hideTitle?: boolean; | |
| 29 | +} | |
| 30 | + | |
| 31 | +const ModelRoleSelector = ({ | |
| 32 | + models, | |
| 33 | + selectedModel, | |
| 34 | + onSelect, | |
| 35 | + displayName, | |
| 36 | + description, | |
| 37 | + setupURL, | |
| 38 | + hideTitle = false, | |
| 39 | +}: ModelRoleSelectorProps) => { | |
| 40 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 41 | + | |
| 42 | + const noConfiguredModels = models.every( | |
| 43 | + (model) => model.configurationStatus !== LLMConfigurationStatuses.VALID, | |
| 44 | + ); | |
| 45 | + | |
| 46 | + function handleSelect(title: string | null) { | |
| 47 | + onSelect(models.find((m) => m.title === title) ?? null); | |
| 48 | + } | |
| 49 | + | |
| 50 | + function handleOptionClick( | |
| 51 | + showMissingApiKeyMsg: boolean, | |
| 52 | + e: MouseEvent<HTMLLIElement>, | |
| 53 | + ) { | |
| 54 | + if (showMissingApiKeyMsg) { | |
| 55 | + e.preventDefault(); | |
| 56 | + e.stopPropagation(); | |
| 57 | + } | |
| 58 | + } | |
| 59 | + | |
| 60 | + return ( | |
| 61 | + <> | |
| 62 | + {!hideTitle && ( | |
| 63 | + <div className="mt-2 flex flex-row items-center gap-1 sm:mt-0"> | |
| 64 | + <span style={{ fontSize: fontSize(-1) }}>{displayName}</span> | |
| 65 | + <InfoHover size="3" id={displayName} msg={description} /> | |
| 66 | + </div> | |
| 67 | + )} | |
| 68 | + | |
| 69 | + <Listbox value={selectedModel?.title ?? null} onChange={handleSelect}> | |
| 70 | + <div className="relative"> | |
| 71 | + {models.length === 0 ? ( | |
| 72 | + <ListboxButton | |
| 73 | + onClick={() => ideMessenger.post("openUrl", setupURL)} | |
| 74 | + className="bg-input border-command-border hover:bg-list-active hover:text-list-active-foreground text-description w-full justify-between rounded border px-2 py-1.5 underline hover:underline" | |
| 75 | + > | |
| 76 | + <span className="line-clamp-1" style={{ fontSize: fontSize(-1) }}> | |
| 77 | + Setup {displayName} model | |
| 78 | + </span> | |
| 79 | + </ListboxButton> | |
| 80 | + ) : ( | |
| 81 | + <> | |
| 82 | + <ListboxButton | |
| 83 | + disabled={models.length === 0} | |
| 84 | + className="bg-input border-command-border hover:bg-list-active hover:text-list-active-foreground w-full justify-between rounded border px-2 py-1.5" | |
| 85 | + > | |
| 86 | + {models.length === 0 || noConfiguredModels ? ( | |
| 87 | + <span className="text-lightgray line-clamp-1 italic"> | |
| 88 | + {`No ${models.length === 0 ? "" : "valid "}${displayName} models${ | |
| 89 | + ["Chat", "Apply", "Edit"].includes(displayName) | |
| 90 | + ? ". Using Chat model" | |
| 91 | + : "" | |
| 92 | + }`} | |
| 93 | + </span> | |
| 94 | + ) : ( | |
| 95 | + <span | |
| 96 | + className="line-clamp-1" | |
| 97 | + style={{ fontSize: fontSize(-1) }} | |
| 98 | + > | |
| 99 | + {selectedModel?.title ?? `Select ${displayName} model`} | |
| 100 | + </span> | |
| 101 | + )} | |
| 102 | + | |
| 103 | + {models.length > 0 && ( | |
| 104 | + <div className="pointer-events-none flex items-center"> | |
| 105 | + <ChevronUpDownIcon className="h-3 w-3" aria-hidden="true" /> | |
| 106 | + </div> | |
| 107 | + )} | |
| 108 | + </ListboxButton> | |
| 109 | + <Transition> | |
| 110 | + <ListboxOptions | |
| 111 | + style={{ borderRadius: defaultBorderRadius }} | |
| 112 | + className="min-w-40" | |
| 113 | + > | |
| 114 | + {[...models] | |
| 115 | + .sort((a, b) => a.title.localeCompare(b.title)) | |
| 116 | + .map((option, idx) => { | |
| 117 | + const isConfigInvalid = | |
| 118 | + option.configurationStatus !== | |
| 119 | + LLMConfigurationStatuses.VALID; | |
| 120 | + let invalidMessage = "(Invalid config)"; | |
| 121 | + if ( | |
| 122 | + option.configurationStatus === | |
| 123 | + LLMConfigurationStatuses.MISSING_ENV_SECRET | |
| 124 | + ) { | |
| 125 | + invalidMessage = "(Missing env secret)"; | |
| 126 | + } | |
| 127 | + if ( | |
| 128 | + option.configurationStatus === | |
| 129 | + LLMConfigurationStatuses.MISSING_API_KEY | |
| 130 | + ) { | |
| 131 | + invalidMessage = "(Missing API Key)"; | |
| 132 | + } | |
| 133 | + | |
| 134 | + return ( | |
| 135 | + <ListboxOption | |
| 136 | + key={idx} | |
| 137 | + value={option.title} | |
| 138 | + disabled={isConfigInvalid} | |
| 139 | + onClick={(e: any) => | |
| 140 | + handleOptionClick(isConfigInvalid, e) | |
| 141 | + } | |
| 142 | + className="" | |
| 143 | + > | |
| 144 | + <div className="flex w-full items-center justify-between gap-2"> | |
| 145 | + <div className="flex min-w-0 flex-1 items-center gap-2"> | |
| 146 | + <CubeIcon className="h-3 w-3 flex-shrink-0" /> | |
| 147 | + <span | |
| 148 | + className="line-clamp-1 truncate" | |
| 149 | + style={{ fontSize: fontSize(-1) }} | |
| 150 | + > | |
| 151 | + {option.title} | |
| 152 | + {isConfigInvalid && ( | |
| 153 | + <span className="ml-2 text-[10px] italic"> | |
| 154 | + {invalidMessage} | |
| 155 | + </span> | |
| 156 | + )} | |
| 157 | + </span> | |
| 158 | + </div> | |
| 159 | + | |
| 160 | + <div className="flex-shrink-0"> | |
| 161 | + {option.title === selectedModel?.title && ( | |
| 162 | + <CheckIcon className="h-3 w-3" /> | |
| 163 | + )} | |
| 164 | + </div> | |
| 165 | + </div> | |
| 166 | + </ListboxOption> | |
| 167 | + ); | |
| 168 | + })} | |
| 169 | + </ListboxOptions> | |
| 170 | + </Transition> | |
| 171 | + </> | |
| 172 | + )} | |
| 173 | + </div> | |
| 174 | + </Listbox> | |
| 175 | + </> | |
| 176 | + ); | |
| 177 | +}; | |
| 178 | + | |
| 179 | +export default ModelRoleSelector; |
added gui/src/pages/config/components/ToolPolicies.tsx +60 −0
| @@ -0,0 +1,60 @@ | ||
| 1 | +import Alert from "../../../components/gui/Alert"; | |
| 2 | +import { Card } from "../../../components/ui"; | |
| 3 | +import { useToolPolicies } from "../hooks/useToolPolicies"; | |
| 4 | +import { ToolPoliciesGroup } from "./ToolPoliciesGroup"; | |
| 5 | + | |
| 6 | +export function ToolPolicies() { | |
| 7 | + const { | |
| 8 | + mode, | |
| 9 | + toolsByGroup, | |
| 10 | + duplicateDetection, | |
| 11 | + allToolsOff, | |
| 12 | + message, | |
| 13 | + expandedGroups, | |
| 14 | + toggleGroup, | |
| 15 | + toolGroupSettings, | |
| 16 | + } = useToolPolicies(); | |
| 17 | + | |
| 18 | + if (toolsByGroup.length === 0) { | |
| 19 | + return ( | |
| 20 | + <Card> | |
| 21 | + <span className="text-description text-sm italic"> | |
| 22 | + No tools available | |
| 23 | + </span> | |
| 24 | + </Card> | |
| 25 | + ); | |
| 26 | + } | |
| 27 | + | |
| 28 | + return ( | |
| 29 | + <div> | |
| 30 | + {(mode === "chat" || mode === "plan") && ( | |
| 31 | + <div className="mb-4"> | |
| 32 | + <Alert type="info" size="sm"> | |
| 33 | + <span className="text-2xs italic">{message}</span> | |
| 34 | + </Alert> | |
| 35 | + </div> | |
| 36 | + )} | |
| 37 | + | |
| 38 | + <div className="space-y-4"> | |
| 39 | + {toolsByGroup.map(([groupName, tools]) => { | |
| 40 | + const isGroupEnabled = | |
| 41 | + !allToolsOff && toolGroupSettings[groupName] !== "exclude"; | |
| 42 | + const isExpanded = expandedGroups[groupName]; | |
| 43 | + | |
| 44 | + return ( | |
| 45 | + <ToolPoliciesGroup | |
| 46 | + key={groupName} | |
| 47 | + groupName={groupName} | |
| 48 | + tools={tools} | |
| 49 | + isGroupEnabled={isGroupEnabled} | |
| 50 | + isExpanded={isExpanded} | |
| 51 | + allToolsOff={allToolsOff} | |
| 52 | + duplicateDetection={duplicateDetection} | |
| 53 | + onToggleGroup={toggleGroup} | |
| 54 | + /> | |
| 55 | + ); | |
| 56 | + })} | |
| 57 | + </div> | |
| 58 | + </div> | |
| 59 | + ); | |
| 60 | +} |
added gui/src/pages/config/components/ToolPoliciesGroup.tsx +92 −0
| @@ -0,0 +1,92 @@ | ||
| 1 | +import { ChevronDownIcon } from "@heroicons/react/24/outline"; | |
| 2 | +import { Tool } from "core"; | |
| 3 | +import ToggleSwitch from "../../../components/gui/Switch"; | |
| 4 | +import { ToolTip } from "../../../components/gui/Tooltip"; | |
| 5 | +import { Card } from "../../../components/ui"; | |
| 6 | +import { useAppDispatch } from "../../../redux/hooks"; | |
| 7 | +import { toggleToolGroupSetting } from "../../../redux/slices/uiSlice"; | |
| 8 | +import { ToolPolicyItem } from "./ToolPolicyItem"; | |
| 9 | + | |
| 10 | +interface ToolPoliciesGroupProps { | |
| 11 | + groupName: string; | |
| 12 | + tools: Tool[]; | |
| 13 | + isGroupEnabled: boolean; | |
| 14 | + isExpanded: boolean; | |
| 15 | + allToolsOff: boolean; | |
| 16 | + duplicateDetection: Record<string, boolean>; | |
| 17 | + onToggleGroup: (groupName: string) => void; | |
| 18 | +} | |
| 19 | + | |
| 20 | +export function ToolPoliciesGroup({ | |
| 21 | + groupName, | |
| 22 | + tools, | |
| 23 | + isGroupEnabled, | |
| 24 | + isExpanded, | |
| 25 | + allToolsOff, | |
| 26 | + duplicateDetection, | |
| 27 | + onToggleGroup, | |
| 28 | +}: ToolPoliciesGroupProps) { | |
| 29 | + const dispatch = useAppDispatch(); | |
| 30 | + | |
| 31 | + return ( | |
| 32 | + <Card> | |
| 33 | + <div className="flex flex-col"> | |
| 34 | + <div | |
| 35 | + className="-mx-2 flex cursor-pointer items-center justify-between gap-3 rounded px-2 py-2 hover:bg-gray-50 hover:bg-opacity-5" | |
| 36 | + onClick={() => onToggleGroup(groupName)} | |
| 37 | + > | |
| 38 | + <div className="flex items-center gap-3"> | |
| 39 | + <ChevronDownIcon | |
| 40 | + className={`text-description h-3 w-3 transition-transform ${ | |
| 41 | + isExpanded ? "rotate-180" : "" | |
| 42 | + }`} | |
| 43 | + /> | |
| 44 | + <div className="flex items-center gap-2"> | |
| 45 | + <span className="text-sm font-semibold">{groupName}</span> | |
| 46 | + <div className="flex h-5 w-5 items-center justify-center rounded-full bg-gray-600 text-xs font-medium text-white"> | |
| 47 | + {tools.length} | |
| 48 | + </div> | |
| 49 | + </div> | |
| 50 | + </div> | |
| 51 | + <ToolTip | |
| 52 | + content={ | |
| 53 | + allToolsOff | |
| 54 | + ? "Tools disabled in current mode" | |
| 55 | + : isGroupEnabled | |
| 56 | + ? `Disable all tools in ${groupName} group` | |
| 57 | + : `Enable all tools in ${groupName} group` | |
| 58 | + } | |
| 59 | + > | |
| 60 | + <div | |
| 61 | + onClick={(e) => { | |
| 62 | + e.stopPropagation(); | |
| 63 | + dispatch(toggleToolGroupSetting(groupName)); | |
| 64 | + }} | |
| 65 | + > | |
| 66 | + <ToggleSwitch | |
| 67 | + isToggled={isGroupEnabled} | |
| 68 | + onToggle={() => dispatch(toggleToolGroupSetting(groupName))} | |
| 69 | + text="" | |
| 70 | + size={10} | |
| 71 | + disabled={allToolsOff} | |
| 72 | + /> | |
| 73 | + </div> | |
| 74 | + </ToolTip> | |
| 75 | + </div> | |
| 76 | + | |
| 77 | + {isExpanded && ( | |
| 78 | + <div className="mt-3 space-y-1"> | |
| 79 | + {tools.map((tool) => ( | |
| 80 | + <ToolPolicyItem | |
| 81 | + key={tool.uri + tool.function.name} | |
| 82 | + tool={tool} | |
| 83 | + duplicatesDetected={duplicateDetection[tool.function.name]} | |
| 84 | + isGroupEnabled={isGroupEnabled} | |
| 85 | + /> | |
| 86 | + ))} | |
| 87 | + </div> | |
| 88 | + )} | |
| 89 | + </div> | |
| 90 | + </Card> | |
| 91 | + ); | |
| 92 | +} |
added gui/src/pages/config/components/ToolPolicyItem.tsx +198 −0
| @@ -0,0 +1,198 @@ | ||
| 1 | +import { ToolPolicy } from "@continuedev/terminal-security"; | |
| 2 | +import { | |
| 3 | + ChevronDownIcon, | |
| 4 | + ChevronRightIcon, | |
| 5 | + InformationCircleIcon, | |
| 6 | +} from "@heroicons/react/24/outline"; | |
| 7 | +import { Tool } from "core"; | |
| 8 | +import { BUILT_IN_GROUP_NAME } from "core/tools/builtIn"; | |
| 9 | +import { useEffect, useMemo, useState } from "react"; | |
| 10 | +import { useDispatch } from "react-redux"; | |
| 11 | +import { Tooltip } from "react-tooltip"; | |
| 12 | +import { ToolTip } from "../../../components/gui/Tooltip"; | |
| 13 | +import { | |
| 14 | + Listbox, | |
| 15 | + ListboxButton, | |
| 16 | + ListboxOption, | |
| 17 | + ListboxOptions, | |
| 18 | +} from "../../../components/ui"; | |
| 19 | +import { useFontSize } from "../../../components/ui/font"; | |
| 20 | +import { useAppSelector } from "../../../redux/hooks"; | |
| 21 | +import { addTool, setToolPolicy } from "../../../redux/slices/uiSlice"; | |
| 22 | + | |
| 23 | +interface ToolPolicyItemProps { | |
| 24 | + tool: Tool; | |
| 25 | + duplicatesDetected: boolean; | |
| 26 | + isGroupEnabled: boolean; | |
| 27 | +} | |
| 28 | + | |
| 29 | +export function ToolPolicyItem(props: ToolPolicyItemProps) { | |
| 30 | + const dispatch = useDispatch(); | |
| 31 | + const policy = useAppSelector( | |
| 32 | + (state) => state.ui.toolSettings[props.tool.function.name], | |
| 33 | + ); | |
| 34 | + const [isExpanded, setIsExpanded] = useState(false); | |
| 35 | + const mode = useAppSelector((state) => state.session.mode); | |
| 36 | + | |
| 37 | + useEffect(() => { | |
| 38 | + if (!policy) { | |
| 39 | + dispatch(addTool(props.tool)); | |
| 40 | + } | |
| 41 | + }, [props.tool.function.name, policy]); | |
| 42 | + | |
| 43 | + const parameters = useMemo(() => { | |
| 44 | + if (props.tool.function.parameters?.properties) { | |
| 45 | + return Object.entries(props.tool.function.parameters.properties).map( | |
| 46 | + ([name, schema]) => | |
| 47 | + [name, schema] as [string, { description: string; type: string }], | |
| 48 | + ); | |
| 49 | + } | |
| 50 | + return undefined; | |
| 51 | + }, [props.tool.function.parameters]); | |
| 52 | + | |
| 53 | + const fontSize = useFontSize(-2); | |
| 54 | + | |
| 55 | + const disabled = | |
| 56 | + !props.isGroupEnabled || | |
| 57 | + (mode === "plan" && | |
| 58 | + props.tool.group === BUILT_IN_GROUP_NAME && | |
| 59 | + !props.tool.readonly); | |
| 60 | + | |
| 61 | + if (!policy) { | |
| 62 | + return null; | |
| 63 | + } | |
| 64 | + const disabledTooltipId = `disabled-note-${props.tool.group}-${props.tool.displayTitle}-${props.tool.function.name}`; | |
| 65 | + | |
| 66 | + return ( | |
| 67 | + <div | |
| 68 | + className="flex flex-col" | |
| 69 | + style={{ | |
| 70 | + fontSize, | |
| 71 | + }} | |
| 72 | + > | |
| 73 | + <div className="-mx-2 flex flex-col rounded px-2 py-2 hover:bg-gray-50 hover:bg-opacity-5"> | |
| 74 | + <div className="flex flex-row items-start justify-between"> | |
| 75 | + <div | |
| 76 | + className="flex flex-1 cursor-pointer flex-row items-start gap-1" | |
| 77 | + onClick={() => setIsExpanded((val) => !val)} | |
| 78 | + > | |
| 79 | + <ChevronRightIcon | |
| 80 | + className={`xs:flex mt-0.5 hidden h-3 w-3 flex-shrink-0 transition-all duration-200 ${isExpanded ? "rotate-90" : ""}`} | |
| 81 | + /> | |
| 82 | + | |
| 83 | + <div className="flex flex-col gap-1"> | |
| 84 | + <div className="flex items-center gap-1"> | |
| 85 | + {props.duplicatesDetected ? ( | |
| 86 | + <ToolTip | |
| 87 | + place="bottom" | |
| 88 | + className="flex flex-wrap items-center" | |
| 89 | + content={ | |
| 90 | + <p className="m-0 p-0"> | |
| 91 | + <span>Duplicate tool name</span>{" "} | |
| 92 | + <code>{props.tool.function.name}</code>{" "} | |
| 93 | + <span> | |
| 94 | + detected. Permissions will conflict and usage may be | |
| 95 | + unpredictable | |
| 96 | + </span> | |
| 97 | + </p> | |
| 98 | + } | |
| 99 | + > | |
| 100 | + <InformationCircleIcon className="h-3 w-3 flex-shrink-0 cursor-help text-yellow-500" /> | |
| 101 | + </ToolTip> | |
| 102 | + ) : null} | |
| 103 | + {props.tool.faviconUrl && ( | |
| 104 | + <img | |
| 105 | + src={props.tool.faviconUrl} | |
| 106 | + alt={props.tool.displayTitle} | |
| 107 | + className="h-3 w-3 flex-shrink-0" | |
| 108 | + /> | |
| 109 | + )} | |
| 110 | + <span className="line-clamp-1 break-all text-sm"> | |
| 111 | + {props.tool.originalFunctionName ?? props.tool.function.name} | |
| 112 | + </span> | |
| 113 | + </div> | |
| 114 | + <div className="text-description line-clamp-3 text-sm"> | |
| 115 | + {props.tool.function.description} | |
| 116 | + </div> | |
| 117 | + </div> | |
| 118 | + </div> | |
| 119 | + | |
| 120 | + <div className="flex w-20 justify-end sm:w-24"> | |
| 121 | + <Listbox | |
| 122 | + value={disabled || policy === "disabled" ? "disabled" : policy} | |
| 123 | + onChange={(newPolicy) => { | |
| 124 | + if (!disabled && newPolicy !== policy) { | |
| 125 | + dispatch( | |
| 126 | + setToolPolicy({ | |
| 127 | + toolName: props.tool.function.name, | |
| 128 | + policy: newPolicy as ToolPolicy, | |
| 129 | + }), | |
| 130 | + ); | |
| 131 | + } | |
| 132 | + }} | |
| 133 | + disabled={disabled} | |
| 134 | + > | |
| 135 | + <div className="relative"> | |
| 136 | + <ListboxButton | |
| 137 | + className={`border-command-border h-7 w-full justify-between px-3 ${disabled ? "cursor-not-allowed opacity-50" : ""}`} | |
| 138 | + data-testid={`tool-policy-item-${props.tool.function.name}`} | |
| 139 | + data-tooltip-id={disabled ? disabledTooltipId : undefined} | |
| 140 | + > | |
| 141 | + <span className="text-xs"> | |
| 142 | + {disabled || policy === "disabled" | |
| 143 | + ? "Excluded" | |
| 144 | + : policy === "allowedWithoutPermission" | |
| 145 | + ? "Automatic" | |
| 146 | + : "Ask First"} | |
| 147 | + </span> | |
| 148 | + <ChevronDownIcon className="h-3 w-3" /> | |
| 149 | + </ListboxButton> | |
| 150 | + {!disabled && ( | |
| 151 | + <ListboxOptions className="min-w-0"> | |
| 152 | + <ListboxOption value="allowedWithoutPermission"> | |
| 153 | + Automatic | |
| 154 | + </ListboxOption> | |
| 155 | + <ListboxOption value="allowedWithPermission"> | |
| 156 | + Ask First | |
| 157 | + </ListboxOption> | |
| 158 | + <ListboxOption value="disabled">Excluded</ListboxOption> | |
| 159 | + </ListboxOptions> | |
| 160 | + )} | |
| 161 | + </div> | |
| 162 | + </Listbox> | |
| 163 | + </div> | |
| 164 | + </div> | |
| 165 | + <Tooltip id={disabledTooltipId}> | |
| 166 | + {mode === "chat" | |
| 167 | + ? "Tool disabled in chat mode" | |
| 168 | + : !props.isGroupEnabled | |
| 169 | + ? "Group is turned off" | |
| 170 | + : "Tool disabled in plan mode"} | |
| 171 | + </Tooltip> | |
| 172 | + </div> | |
| 173 | + <div | |
| 174 | + className={`flex flex-col overflow-hidden ${isExpanded ? "h-min" : "h-0 opacity-0"} gap-x-1 gap-y-2 pl-2 transition-all`} | |
| 175 | + > | |
| 176 | + <span className="text-2xs mt-1.5 font-bold">Description:</span> | |
| 177 | + <span className="text-2xs italic"> | |
| 178 | + {props.tool.function.description} | |
| 179 | + </span> | |
| 180 | + {parameters ? ( | |
| 181 | + <> | |
| 182 | + <span className="text-2xs font-bold">Arguments:</span> | |
| 183 | + {parameters.map((param, idx) => ( | |
| 184 | + <div key={idx} className="text-2xs block"> | |
| 185 | + <code className="">{param[0]}</code> | |
| 186 | + <span className="ml-1">{`(${param[1].type ?? "unknown"}):`}</span> | |
| 187 | + <span className="ml-1 italic"> | |
| 188 | + {param[1].description ?? "No description"} | |
| 189 | + </span> | |
| 190 | + </div> | |
| 191 | + ))} | |
| 192 | + </> | |
| 193 | + ) : null} | |
| 194 | + <div className="h-1"></div> | |
| 195 | + </div> | |
| 196 | + </div> | |
| 197 | + ); | |
| 198 | +} |
added gui/src/pages/config/components/UserSetting.tsx +202 −0
| @@ -0,0 +1,202 @@ | ||
| 1 | +import { | |
| 2 | + CheckIcon, | |
| 3 | + ChevronDownIcon, | |
| 4 | + XMarkIcon, | |
| 5 | +} from "@heroicons/react/24/outline"; | |
| 6 | +import React from "react"; | |
| 7 | +import ToggleSwitch from "../../../components/gui/Switch"; | |
| 8 | +import { ToolTip } from "../../../components/gui/Tooltip"; | |
| 9 | +import { | |
| 10 | + Listbox, | |
| 11 | + ListboxButton, | |
| 12 | + ListboxOption, | |
| 13 | + ListboxOptions, | |
| 14 | +} from "../../../components/ui"; | |
| 15 | + | |
| 16 | +interface BaseUserSettingProps { | |
| 17 | + title: string; | |
| 18 | + description: React.ReactNode; | |
| 19 | + disabled?: boolean; | |
| 20 | +} | |
| 21 | + | |
| 22 | +interface ToggleUserSettingProps extends BaseUserSettingProps { | |
| 23 | + type: "toggle"; | |
| 24 | + value: boolean; | |
| 25 | + onChange: (value: boolean) => void; | |
| 26 | +} | |
| 27 | + | |
| 28 | +interface NumberUserSettingProps extends BaseUserSettingProps { | |
| 29 | + type: "number"; | |
| 30 | + value: number; | |
| 31 | + onChange: (value: number) => void; | |
| 32 | + min?: number; | |
| 33 | + max?: number; | |
| 34 | +} | |
| 35 | + | |
| 36 | +interface SelectUserSettingProps extends BaseUserSettingProps { | |
| 37 | + type: "select"; | |
| 38 | + value: string; | |
| 39 | + onChange: (value: string) => void; | |
| 40 | + options: { label: string; value: string }[]; | |
| 41 | +} | |
| 42 | + | |
| 43 | +interface InputUserSettingProps extends BaseUserSettingProps { | |
| 44 | + type: "input"; | |
| 45 | + value: string; | |
| 46 | + onChange: (value: string) => void; | |
| 47 | + className?: string; | |
| 48 | + placeholder?: string; | |
| 49 | + onSubmit?: () => void; | |
| 50 | + onCancel?: () => void; | |
| 51 | + isDirty?: boolean; | |
| 52 | + isValid?: boolean; | |
| 53 | +} | |
| 54 | + | |
| 55 | +type UserSettingProps = | |
| 56 | + | ToggleUserSettingProps | |
| 57 | + | NumberUserSettingProps | |
| 58 | + | SelectUserSettingProps | |
| 59 | + | InputUserSettingProps; | |
| 60 | + | |
| 61 | +export function UserSetting(props: UserSettingProps) { | |
| 62 | + const { title, description, disabled = false } = props; | |
| 63 | + | |
| 64 | + const renderControl = () => { | |
| 65 | + switch (props.type) { | |
| 66 | + case "toggle": | |
| 67 | + return ( | |
| 68 | + <ToggleSwitch | |
| 69 | + isToggled={props.value} | |
| 70 | + disabled={disabled} | |
| 71 | + onToggle={() => props.onChange(!props.value)} | |
| 72 | + text="" | |
| 73 | + /> | |
| 74 | + ); | |
| 75 | + | |
| 76 | + case "number": | |
| 77 | + return ( | |
| 78 | + <div className="border-command-border bg-vsc-input-background focus-within:border-border-focus focus-within:ring-border-focus flex w-20 items-center rounded-md border border-solid focus-within:ring-1"> | |
| 79 | + <input | |
| 80 | + type="number" | |
| 81 | + value={props.value} | |
| 82 | + onChange={(e) => props.onChange(Number(e.target.value))} | |
| 83 | + min={props.min ?? 0} | |
| 84 | + max={props.max ?? 100} | |
| 85 | + disabled={disabled} | |
| 86 | + className="text-vsc-foreground flex-1 border-none bg-transparent px-2 py-1 text-right outline-none focus:outline-none focus:ring-0 [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none" | |
| 87 | + /> | |
| 88 | + </div> | |
| 89 | + ); | |
| 90 | + | |
| 91 | + case "select": | |
| 92 | + return ( | |
| 93 | + <Listbox | |
| 94 | + value={props.value} | |
| 95 | + onChange={props.onChange} | |
| 96 | + disabled={disabled} | |
| 97 | + > | |
| 98 | + <ListboxButton className="border-command-border !w-20 w-20 !flex-none justify-between !rounded-md px-2 py-1"> | |
| 99 | + {props.options.find((opt) => opt.value === props.value)?.label || | |
| 100 | + props.value} | |
| 101 | + <ChevronDownIcon className="h-3 w-3" /> | |
| 102 | + </ListboxButton> | |
| 103 | + <ListboxOptions className="!w-20 !min-w-0"> | |
| 104 | + {props.options.map((option) => ( | |
| 105 | + <ListboxOption key={option.value} value={option.value}> | |
| 106 | + {option.label} | |
| 107 | + </ListboxOption> | |
| 108 | + ))} | |
| 109 | + </ListboxOptions> | |
| 110 | + </Listbox> | |
| 111 | + ); | |
| 112 | + | |
| 113 | + case "input": | |
| 114 | + if (props.onSubmit) { | |
| 115 | + return ( | |
| 116 | + <form | |
| 117 | + onSubmit={(e) => { | |
| 118 | + e.preventDefault(); | |
| 119 | + props.onSubmit?.(); | |
| 120 | + }} | |
| 121 | + > | |
| 122 | + <div className="flex items-center gap-2"> | |
| 123 | + <div | |
| 124 | + className={`border-command-border bg-vsc-input-background focus-within:border-border-focus focus-within:ring-border-focus flex w-full flex-row overflow-hidden rounded-md border border-solid focus-within:ring-1 ${ | |
| 125 | + props.isDirty | |
| 126 | + ? !props.isValid | |
| 127 | + ? "outline outline-red-500" | |
| 128 | + : "outline outline-green-500" | |
| 129 | + : "" | |
| 130 | + } ${disabled ? "cursor-not-allowed opacity-50" : ""}`} | |
| 131 | + > | |
| 132 | + <input | |
| 133 | + type="text" | |
| 134 | + value={props.value} | |
| 135 | + onChange={(e) => props.onChange(e.target.value)} | |
| 136 | + placeholder={props.placeholder} | |
| 137 | + disabled={disabled} | |
| 138 | + className="text-vsc-foreground flex-1 border-none bg-inherit px-1.5 py-1 outline-none ring-0 focus:border-none focus:outline-none focus:ring-0 disabled:cursor-not-allowed" | |
| 139 | + /> | |
| 140 | + </div> | |
| 141 | + {props.isDirty && ( | |
| 142 | + <div className="flex flex-row items-center gap-1"> | |
| 143 | + <ToolTip content="Save"> | |
| 144 | + <div onClick={props.onSubmit} className="cursor-pointer"> | |
| 145 | + <CheckIcon className="h-4 w-4 text-green-500 hover:opacity-80" /> | |
| 146 | + </div> | |
| 147 | + </ToolTip> | |
| 148 | + <ToolTip content="Cancel"> | |
| 149 | + <div onClick={props.onCancel} className="cursor-pointer"> | |
| 150 | + <XMarkIcon className="h-4 w-4 text-red-500 hover:opacity-80" /> | |
| 151 | + </div> | |
| 152 | + </ToolTip> | |
| 153 | + </div> | |
| 154 | + )} | |
| 155 | + </div> | |
| 156 | + </form> | |
| 157 | + ); | |
| 158 | + } | |
| 159 | + return ( | |
| 160 | + <div | |
| 161 | + className={`border-command-border bg-vsc-input-background focus-within:border-border-focus focus-within:ring-border-focus flex w-full flex-row overflow-hidden rounded-md border border-solid focus-within:ring-1 ${disabled ? "cursor-not-allowed opacity-50" : ""}`} | |
| 162 | + > | |
| 163 | + <input | |
| 164 | + type="text" | |
| 165 | + value={props.value} | |
| 166 | + onChange={(e) => props.onChange(e.target.value)} | |
| 167 | + disabled={disabled} | |
| 168 | + className="text-vsc-foreground flex-1 border-none bg-inherit px-1.5 py-1 outline-none ring-0 focus:border-none focus:outline-none focus:ring-0 disabled:cursor-not-allowed" | |
| 169 | + /> | |
| 170 | + </div> | |
| 171 | + ); | |
| 172 | + | |
| 173 | + default: | |
| 174 | + return null; | |
| 175 | + } | |
| 176 | + }; | |
| 177 | + | |
| 178 | + // Use vertical layout for input types, horizontal for others | |
| 179 | + const isInputType = props.type === "input"; | |
| 180 | + | |
| 181 | + if (isInputType) { | |
| 182 | + return ( | |
| 183 | + <div className="flex flex-col gap-3"> | |
| 184 | + <div className="flex flex-col"> | |
| 185 | + <span className="text-sm font-medium">{title}</span> | |
| 186 | + <div className="mt-0.5 text-xs text-gray-500">{description}</div> | |
| 187 | + </div> | |
| 188 | + {renderControl()} | |
| 189 | + </div> | |
| 190 | + ); | |
| 191 | + } | |
| 192 | + | |
| 193 | + return ( | |
| 194 | + <div className="flex items-start justify-start gap-4"> | |
| 195 | + <div className="flex flex-1 flex-col"> | |
| 196 | + <span className="text-sm font-medium">{title}</span> | |
| 197 | + <div className="mt-0.5 text-xs text-gray-500">{description}</div> | |
| 198 | + </div> | |
| 199 | + {renderControl()} | |
| 200 | + </div> | |
| 201 | + ); | |
| 202 | +} |
added gui/src/pages/config/configTabs.tsx +171 −0
| @@ -0,0 +1,171 @@ | ||
| 1 | +import { | |
| 2 | + ArrowLeftIcon, | |
| 3 | + BuildingOfficeIcon, | |
| 4 | + CircleStackIcon, | |
| 5 | + Cog6ToothIcon, | |
| 6 | + CubeIcon, | |
| 7 | + PencilIcon, | |
| 8 | + QuestionMarkCircleIcon, | |
| 9 | + WrenchScrewdriverIcon, | |
| 10 | +} from "@heroicons/react/24/outline"; | |
| 11 | +import { BotIcon } from "../../components/svg/BotIcon"; | |
| 12 | +import { ConfigSection } from "./components/ConfigSection"; | |
| 13 | +import { AgentsSection } from "./sections/AgentsSection"; | |
| 14 | +import { HelpSection } from "./sections/HelpSection"; | |
| 15 | +import { IndexingSettingsSection } from "./sections/IndexingSettingsSection"; | |
| 16 | +import { ModelsSection } from "./sections/ModelsSection"; | |
| 17 | +import { OrganizationsSection } from "./sections/OrganizationsSection"; | |
| 18 | +import { RulesSection } from "./sections/RulesSection"; | |
| 19 | +import { ToolsSection } from "./sections/ToolsSection"; | |
| 20 | +import { UserSettingsSection } from "./sections/UserSettingsSection"; | |
| 21 | + | |
| 22 | +interface TabOption { | |
| 23 | + id: string; | |
| 24 | + label: string; | |
| 25 | + component: React.ReactNode; | |
| 26 | + icon: React.ReactNode; | |
| 27 | +} | |
| 28 | + | |
| 29 | +interface TabSection { | |
| 30 | + id: string; | |
| 31 | + tabs: TabOption[]; | |
| 32 | + showTopDivider?: boolean; | |
| 33 | + showBottomDivider?: boolean; | |
| 34 | + className?: string; | |
| 35 | +} | |
| 36 | + | |
| 37 | +export const topTabSections: TabSection[] = [ | |
| 38 | + { | |
| 39 | + id: "top", | |
| 40 | + tabs: [ | |
| 41 | + { | |
| 42 | + id: "back", | |
| 43 | + label: "Back", | |
| 44 | + component: <div />, | |
| 45 | + icon: <ArrowLeftIcon className="xs:h-4 xs:w-4 h-3 w-3 flex-shrink-0" />, | |
| 46 | + }, | |
| 47 | + ], | |
| 48 | + }, | |
| 49 | + { | |
| 50 | + id: "blocks", | |
| 51 | + showTopDivider: true, | |
| 52 | + tabs: [ | |
| 53 | + { | |
| 54 | + id: "models", | |
| 55 | + label: "Models", | |
| 56 | + component: ( | |
| 57 | + <ConfigSection> | |
| 58 | + <ModelsSection /> | |
| 59 | + </ConfigSection> | |
| 60 | + ), | |
| 61 | + icon: <CubeIcon className="xs:h-4 xs:w-4 h-3 w-3 flex-shrink-0" />, | |
| 62 | + }, | |
| 63 | + { | |
| 64 | + id: "rules", | |
| 65 | + label: "Rules", | |
| 66 | + component: ( | |
| 67 | + <ConfigSection> | |
| 68 | + <RulesSection /> | |
| 69 | + </ConfigSection> | |
| 70 | + ), | |
| 71 | + icon: <PencilIcon className="xs:h-4 xs:w-4 h-3 w-3 flex-shrink-0" />, | |
| 72 | + }, | |
| 73 | + { | |
| 74 | + id: "tools", | |
| 75 | + label: "Tools", | |
| 76 | + component: ( | |
| 77 | + <ConfigSection> | |
| 78 | + <ToolsSection /> | |
| 79 | + </ConfigSection> | |
| 80 | + ), | |
| 81 | + icon: ( | |
| 82 | + <WrenchScrewdriverIcon className="xs:h-4 xs:w-4 h-3 w-3 flex-shrink-0" /> | |
| 83 | + ), | |
| 84 | + }, | |
| 85 | + ], | |
| 86 | + }, | |
| 87 | + { | |
| 88 | + id: "agents-orgs", | |
| 89 | + showTopDivider: true, | |
| 90 | + tabs: [ | |
| 91 | + { | |
| 92 | + id: "agents", | |
| 93 | + label: "Agents", | |
| 94 | + component: ( | |
| 95 | + <ConfigSection> | |
| 96 | + <AgentsSection /> | |
| 97 | + </ConfigSection> | |
| 98 | + ), | |
| 99 | + icon: ( | |
| 100 | + <BotIcon className="xs:h-4 xs:w-4 h-3 w-3 flex-shrink-0" size={16} /> | |
| 101 | + ), | |
| 102 | + }, | |
| 103 | + { | |
| 104 | + id: "organizations", | |
| 105 | + label: "Organizations", | |
| 106 | + component: ( | |
| 107 | + <ConfigSection> | |
| 108 | + <OrganizationsSection /> | |
| 109 | + </ConfigSection> | |
| 110 | + ), | |
| 111 | + icon: ( | |
| 112 | + <BuildingOfficeIcon className="xs:h-4 xs:w-4 h-3 w-3 flex-shrink-0" /> | |
| 113 | + ), | |
| 114 | + }, | |
| 115 | + ], | |
| 116 | + }, | |
| 117 | + { | |
| 118 | + id: "indexing", | |
| 119 | + showTopDivider: true, | |
| 120 | + tabs: [ | |
| 121 | + { | |
| 122 | + id: "indexing", | |
| 123 | + label: "Indexing", | |
| 124 | + component: ( | |
| 125 | + <ConfigSection> | |
| 126 | + <IndexingSettingsSection /> | |
| 127 | + </ConfigSection> | |
| 128 | + ), | |
| 129 | + icon: ( | |
| 130 | + <CircleStackIcon className="xs:h-4 xs:w-4 h-3 w-3 flex-shrink-0" /> | |
| 131 | + ), | |
| 132 | + }, | |
| 133 | + ], | |
| 134 | + }, | |
| 135 | +]; | |
| 136 | + | |
| 137 | +export const bottomTabSections: TabSection[] = [ | |
| 138 | + { | |
| 139 | + id: "bottom", | |
| 140 | + tabs: [ | |
| 141 | + { | |
| 142 | + id: "settings", | |
| 143 | + label: "Settings", | |
| 144 | + component: ( | |
| 145 | + <ConfigSection> | |
| 146 | + <UserSettingsSection /> | |
| 147 | + </ConfigSection> | |
| 148 | + ), | |
| 149 | + icon: <Cog6ToothIcon className="xs:h-4 xs:w-4 h-3 w-3 flex-shrink-0" />, | |
| 150 | + }, | |
| 151 | + { | |
| 152 | + id: "help", | |
| 153 | + label: "Help", | |
| 154 | + component: ( | |
| 155 | + <ConfigSection> | |
| 156 | + <HelpSection /> | |
| 157 | + </ConfigSection> | |
| 158 | + ), | |
| 159 | + icon: ( | |
| 160 | + <QuestionMarkCircleIcon className="xs:h-4 xs:w-4 h-3 w-3 flex-shrink-0" /> | |
| 161 | + ), | |
| 162 | + }, | |
| 163 | + ], | |
| 164 | + }, | |
| 165 | +]; | |
| 166 | + | |
| 167 | +export const getAllTabs = (): TabOption[] => { | |
| 168 | + return [...topTabSections, ...bottomTabSections].flatMap( | |
| 169 | + (section) => section.tabs, | |
| 170 | + ); | |
| 171 | +}; |
added gui/src/pages/config/features/account/AccountDropdown.tsx +110 −0
| @@ -0,0 +1,110 @@ | ||
| 1 | +import { | |
| 2 | + ArrowRightStartOnRectangleIcon, | |
| 3 | + Cog6ToothIcon, | |
| 4 | + UserCircleIcon as UserCircleIconOutline, | |
| 5 | +} from "@heroicons/react/24/outline"; | |
| 6 | +import { UserCircleIcon as UserCircleIconSolid } from "@heroicons/react/24/solid"; | |
| 7 | +import { isOnPremSession } from "core/control-plane/AuthTypes"; | |
| 8 | +import { useContext } from "react"; | |
| 9 | +import { ToolTip } from "../../../../components/gui/Tooltip"; | |
| 10 | +import { | |
| 11 | + Button, | |
| 12 | + Listbox, | |
| 13 | + ListboxButton, | |
| 14 | + ListboxOption, | |
| 15 | + ListboxOptions, | |
| 16 | +} from "../../../../components/ui"; | |
| 17 | +import { Divider } from "../../../../components/ui/Divider"; | |
| 18 | +import { useAuth } from "../../../../context/Auth"; | |
| 19 | +import { IdeMessengerContext } from "../../../../context/IdeMessenger"; | |
| 20 | + | |
| 21 | +export function AccountDropdown() { | |
| 22 | + const { session, logout, login } = useAuth(); | |
| 23 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 24 | + | |
| 25 | + if (isOnPremSession(session)) { | |
| 26 | + return null; | |
| 27 | + } | |
| 28 | + | |
| 29 | + if (!session) { | |
| 30 | + return ( | |
| 31 | + <ToolTip content="Log in" className="text-xs md:!hidden"> | |
| 32 | + <Button | |
| 33 | + variant="ghost" | |
| 34 | + className="text-description flex w-full flex-row items-center gap-2 px-2 py-1.5" | |
| 35 | + onClick={() => login(false)} | |
| 36 | + > | |
| 37 | + <UserCircleIconOutline className="xs:h-4 xs:w-4 h-3 w-3 flex-shrink-0" /> | |
| 38 | + <span className="text-description hidden text-xs md:block"> | |
| 39 | + Log in | |
| 40 | + </span> | |
| 41 | + </Button> | |
| 42 | + </ToolTip> | |
| 43 | + ); | |
| 44 | + } | |
| 45 | + | |
| 46 | + return ( | |
| 47 | + <div> | |
| 48 | + <Listbox> | |
| 49 | + {({ open }) => ( | |
| 50 | + <> | |
| 51 | + <ListboxButton | |
| 52 | + className={`text-description w-full justify-start gap-1 border-none px-2 py-1.5 ${ | |
| 53 | + open ? "bg-input" : "hover:bg-input bg-inherit" | |
| 54 | + }`} | |
| 55 | + > | |
| 56 | + <UserCircleIconSolid className="xs:h-4 xs:w-4 h-3 w-3 flex-shrink-0" /> | |
| 57 | + <div className="ml-1 flex min-w-0 flex-1 flex-col items-start overflow-hidden"> | |
| 58 | + <span className="w-full truncate text-xs font-medium hover:brightness-110"> | |
| 59 | + {session.account.label} | |
| 60 | + </span> | |
| 61 | + <span className="text-description-muted w-full truncate text-xs"> | |
| 62 | + {session.account.id} | |
| 63 | + </span> | |
| 64 | + </div> | |
| 65 | + </ListboxButton> | |
| 66 | + <ListboxOptions anchor="right end"> | |
| 67 | + {/* Account info section for small screens */} | |
| 68 | + <div className="md:hidden"> | |
| 69 | + <div className="flex items-center gap-2 px-2 py-1"> | |
| 70 | + <UserCircleIconSolid className="h-5 w-5 flex-shrink-0" /> | |
| 71 | + <div className="flex min-w-0 flex-col"> | |
| 72 | + <span className="truncate text-xs font-medium"> | |
| 73 | + {session.account.label} | |
| 74 | + </span> | |
| 75 | + <span className="text-description-muted truncate text-xs"> | |
| 76 | + {session.account.id} | |
| 77 | + </span> | |
| 78 | + </div> | |
| 79 | + </div> | |
| 80 | + <Divider /> | |
| 81 | + </div> | |
| 82 | + | |
| 83 | + <ListboxOption | |
| 84 | + onClick={() => | |
| 85 | + ideMessenger.post( | |
| 86 | + "openUrl", | |
| 87 | + "https://hub.continue.dev/settings", | |
| 88 | + ) | |
| 89 | + } | |
| 90 | + value="manage-account" | |
| 91 | + > | |
| 92 | + <div className="flex items-center gap-2 py-0.5"> | |
| 93 | + <Cog6ToothIcon className="h-3.5 w-3.5" /> | |
| 94 | + <span>Manage Account</span> | |
| 95 | + </div> | |
| 96 | + </ListboxOption> | |
| 97 | + | |
| 98 | + <ListboxOption onClick={logout} value="logout"> | |
| 99 | + <div className="flex items-center gap-2 py-0.5"> | |
| 100 | + <ArrowRightStartOnRectangleIcon className="h-3.5 w-3.5" /> | |
| 101 | + <span>Log out</span> | |
| 102 | + </div> | |
| 103 | + </ListboxOption> | |
| 104 | + </ListboxOptions> | |
| 105 | + </> | |
| 106 | + )} | |
| 107 | + </Listbox> | |
| 108 | + </div> | |
| 109 | + ); | |
| 110 | +} |
added gui/src/pages/config/features/indexing/IndexingProgress.tsx +136 −0
| @@ -0,0 +1,136 @@ | ||
| 1 | +import { IndexingProgressUpdate } from "core"; | |
| 2 | +import { usePostHog } from "posthog-js/react"; | |
| 3 | +import { useContext, useEffect, useState } from "react"; | |
| 4 | +import { useDispatch } from "react-redux"; | |
| 5 | + | |
| 6 | +import ConfirmationDialog from "../../../../components/dialogs/ConfirmationDialog"; | |
| 7 | +import { IdeMessengerContext } from "../../../../context/IdeMessenger"; | |
| 8 | +import { useWebviewListener } from "../../../../hooks/useWebviewListener"; | |
| 9 | +import { | |
| 10 | + setDialogMessage, | |
| 11 | + setShowDialog, | |
| 12 | +} from "../../../../redux/slices/uiSlice"; | |
| 13 | +import { isJetBrains } from "../../../../util"; | |
| 14 | +import IndexingProgressBar from "./IndexingProgressBar"; | |
| 15 | +import IndexingProgressErrorText from "./IndexingProgressErrorText"; | |
| 16 | +import IndexingProgressIndicator from "./IndexingProgressIndicator"; | |
| 17 | +import IndexingProgressSubtext from "./IndexingProgressSubtext"; | |
| 18 | +import IndexingProgressTitleText from "./IndexingProgressTitleText"; | |
| 19 | + | |
| 20 | +export function getProgressPercentage( | |
| 21 | + progress: IndexingProgressUpdate["progress"], | |
| 22 | +) { | |
| 23 | + return Math.min(100, Math.max(0, progress * 100)); | |
| 24 | +} | |
| 25 | + | |
| 26 | +function IndexingProgress() { | |
| 27 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 28 | + const posthog = usePostHog(); | |
| 29 | + const dispatch = useDispatch(); | |
| 30 | + const [paused, setPaused] = useState<boolean | undefined>(undefined); | |
| 31 | + const [update, setUpdate] = useState<IndexingProgressUpdate>({ | |
| 32 | + desc: "Loading indexing config", | |
| 33 | + progress: 0.0, | |
| 34 | + status: "loading", | |
| 35 | + }); | |
| 36 | + | |
| 37 | + // If sidebar is opened after extension initializes, retrieve saved states. | |
| 38 | + let initialized = false; | |
| 39 | + | |
| 40 | + useWebviewListener("indexProgress", async (data) => { | |
| 41 | + setUpdate(data); | |
| 42 | + }); | |
| 43 | + | |
| 44 | + useEffect(() => { | |
| 45 | + if (!initialized) { | |
| 46 | + // Triggers retrieval for possible non-default states set prior to IndexingProgressBar initialization | |
| 47 | + ideMessenger.post("index/indexingProgressBarInitialized", undefined); | |
| 48 | + initialized = true; | |
| 49 | + } | |
| 50 | + }, []); | |
| 51 | + | |
| 52 | + useEffect(() => { | |
| 53 | + if (paused === undefined) return; | |
| 54 | + ideMessenger.post("index/setPaused", paused); | |
| 55 | + }, [paused]); | |
| 56 | + | |
| 57 | + function onClickRetry() { | |
| 58 | + // For now, we don't show in JetBrains since the re-index command | |
| 59 | + // is not yet implemented | |
| 60 | + if (update.shouldClearIndexes && !isJetBrains()) { | |
| 61 | + dispatch(setShowDialog(true)); | |
| 62 | + dispatch( | |
| 63 | + setDialogMessage( | |
| 64 | + <ConfirmationDialog | |
| 65 | + title="Rebuild codebase index" | |
| 66 | + confirmText="Rebuild" | |
| 67 | + text={ | |
| 68 | + "Your index appears corrupted. We recommend clearing and rebuilding it, " + | |
| 69 | + "which may take time for large codebases.\n\n" + | |
| 70 | + "For a faster rebuild without clearing data, press 'Shift + Command + P' to open " + | |
| 71 | + "the Command Palette, and type out 'Continue: Force Codebase Re-Indexing'" | |
| 72 | + } | |
| 73 | + onConfirm={() => { | |
| 74 | + posthog.capture("rebuild_index_clicked"); | |
| 75 | + ideMessenger.post("index/forceReIndex", { | |
| 76 | + shouldClearIndexes: true, | |
| 77 | + }); | |
| 78 | + }} | |
| 79 | + />, | |
| 80 | + ), | |
| 81 | + ); | |
| 82 | + } else { | |
| 83 | + ideMessenger.post("index/forceReIndex", undefined); | |
| 84 | + } | |
| 85 | + } | |
| 86 | + | |
| 87 | + function onClick() { | |
| 88 | + switch (update.status) { | |
| 89 | + case "failed": | |
| 90 | + onClickRetry(); | |
| 91 | + break; | |
| 92 | + case "indexing": | |
| 93 | + case "loading": | |
| 94 | + case "paused": | |
| 95 | + if (update.progress < 1 && update.progress >= 0) { | |
| 96 | + setPaused((prev) => !prev); | |
| 97 | + } else { | |
| 98 | + ideMessenger.post("index/forceReIndex", undefined); | |
| 99 | + } | |
| 100 | + break; | |
| 101 | + case "disabled": | |
| 102 | + ideMessenger.post("config/openProfile", { | |
| 103 | + profileId: undefined, | |
| 104 | + }); | |
| 105 | + break; | |
| 106 | + case "done": | |
| 107 | + ideMessenger.post("index/forceReIndex", undefined); | |
| 108 | + default: | |
| 109 | + break; | |
| 110 | + } | |
| 111 | + } | |
| 112 | + | |
| 113 | + return ( | |
| 114 | + <div className="flex flex-col"> | |
| 115 | + <div className="mb-0 flex justify-between text-sm"> | |
| 116 | + <IndexingProgressTitleText update={update} /> | |
| 117 | + {!["loading", "waiting"].includes(update.status) && ( | |
| 118 | + <IndexingProgressIndicator update={update} /> | |
| 119 | + )} | |
| 120 | + </div> | |
| 121 | + | |
| 122 | + <IndexingProgressBar update={update} /> | |
| 123 | + | |
| 124 | + <IndexingProgressSubtext update={update} onClick={onClick} /> | |
| 125 | + | |
| 126 | + {(update.status === "failed" || | |
| 127 | + (update.warnings && update.warnings.length > 0)) && ( | |
| 128 | + <div className="mt-4"> | |
| 129 | + <IndexingProgressErrorText update={update} /> | |
| 130 | + </div> | |
| 131 | + )} | |
| 132 | + </div> | |
| 133 | + ); | |
| 134 | +} | |
| 135 | + | |
| 136 | +export default IndexingProgress; |
added gui/src/pages/config/features/indexing/IndexingProgressBar.tsx +27 −0
| @@ -0,0 +1,27 @@ | ||
| 1 | +import { IndexingProgressUpdate } from "core"; | |
| 2 | +import { getProgressPercentage } from "./IndexingProgress"; | |
| 3 | + | |
| 4 | +export interface IndexingProgressBarProps { | |
| 5 | + update: IndexingProgressUpdate; | |
| 6 | +} | |
| 7 | + | |
| 8 | +function IndexingProgressBar({ update }: IndexingProgressBarProps) { | |
| 9 | + // Show 100% red progress bar if indexing failed | |
| 10 | + const progressPercentage = | |
| 11 | + update.status === "failed" ? 100 : getProgressPercentage(update.progress); | |
| 12 | + | |
| 13 | + return ( | |
| 14 | + <div className="my-2 h-1.5 w-full rounded-md border border-solid border-gray-400"> | |
| 15 | + <div | |
| 16 | + className={`h-full rounded-lg transition-all duration-200 ease-in-out ${ | |
| 17 | + update.status === "failed" ? "bg-red-600" : "bg-stone-500" | |
| 18 | + }`} | |
| 19 | + style={{ | |
| 20 | + width: `${progressPercentage}%`, | |
| 21 | + }} | |
| 22 | + /> | |
| 23 | + </div> | |
| 24 | + ); | |
| 25 | +} | |
| 26 | + | |
| 27 | +export default IndexingProgressBar; |
added gui/src/pages/config/features/indexing/IndexingProgressErrorText.tsx +121 −0
| @@ -0,0 +1,121 @@ | ||
| 1 | +import { | |
| 2 | + ArrowTopRightOnSquareIcon, | |
| 3 | + ChevronRightIcon, | |
| 4 | + ClipboardIcon, | |
| 5 | + XCircleIcon, | |
| 6 | +} from "@heroicons/react/24/outline"; | |
| 7 | +import { IndexingProgressUpdate } from "core"; | |
| 8 | +import { useContext, useState } from "react"; | |
| 9 | +import { GhostButton } from "../../../../components"; | |
| 10 | +import { IdeMessengerContext } from "../../../../context/IdeMessenger"; | |
| 11 | +import { useAppSelector } from "../../../../redux/hooks"; | |
| 12 | + | |
| 13 | +export interface IndexingProgressErrorTextProps { | |
| 14 | + update: IndexingProgressUpdate; | |
| 15 | +} | |
| 16 | + | |
| 17 | +const copyWarningsToClipboard = (warnings: string[] = []) => { | |
| 18 | + const warningsText = warnings.join("\n"); | |
| 19 | + void navigator.clipboard.writeText(warningsText); | |
| 20 | +}; | |
| 21 | + | |
| 22 | +function IndexingProgressErrorText({ update }: IndexingProgressErrorTextProps) { | |
| 23 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 24 | + const [showWarnings, setShowWarnings] = useState(false); | |
| 25 | + const embeddingsProvider = useAppSelector( | |
| 26 | + (state) => state.config.config.selectedModelByRole.embed, | |
| 27 | + ); | |
| 28 | + | |
| 29 | + if (!embeddingsProvider) { | |
| 30 | + return ( | |
| 31 | + <div className="flex items-center gap-2 italic"> | |
| 32 | + <XCircleIcon className="h-4 w-4 min-w-[10%]" /> | |
| 33 | + <span className="leading-relaxed"> | |
| 34 | + Add an Embeddings model to enable codebase indexing. See the docs for | |
| 35 | + examples: | |
| 36 | + <a | |
| 37 | + href="https://docs.continue.dev/walkthroughs/codebase-embeddings#embeddings-providers" | |
| 38 | + target="_blank" | |
| 39 | + className="cursor-pointer text-inherit underline hover:text-inherit" | |
| 40 | + > | |
| 41 | + https://docs.continue.dev/walkthroughs/codebase-embeddings#embeddings-providers | |
| 42 | + </a> | |
| 43 | + </span> | |
| 44 | + </div> | |
| 45 | + ); | |
| 46 | + } | |
| 47 | + | |
| 48 | + // Show warnings if they exist (for completed indexing with warnings) | |
| 49 | + if ( | |
| 50 | + update.warnings && | |
| 51 | + update.warnings.length > 0 && | |
| 52 | + update.status !== "failed" | |
| 53 | + ) { | |
| 54 | + return ( | |
| 55 | + <div> | |
| 56 | + <div | |
| 57 | + className="flex cursor-pointer items-center gap-2 italic text-yellow-600" | |
| 58 | + onClick={() => setShowWarnings(!showWarnings)} | |
| 59 | + > | |
| 60 | + <span className="leading-relaxed"> | |
| 61 | + {update.warnings.length} warning | |
| 62 | + {update.warnings.length > 1 ? "s" : ""} during indexing | |
| 63 | + </span> | |
| 64 | + <ChevronRightIcon | |
| 65 | + className={`h-3 w-3 transition-transform duration-300 ${ | |
| 66 | + showWarnings ? "rotate-90" : "" | |
| 67 | + }`} | |
| 68 | + /> | |
| 69 | + </div> | |
| 70 | + | |
| 71 | + <div | |
| 72 | + className={`ml-3 overflow-hidden transition-all duration-300 ease-in-out ${ | |
| 73 | + showWarnings ? "mt-2 max-h-96 opacity-100" : "max-h-0 opacity-0" | |
| 74 | + }`} | |
| 75 | + > | |
| 76 | + {/* Warning messages */} | |
| 77 | + <div className="space-y-1"> | |
| 78 | + {update.warnings.map((warning, index) => ( | |
| 79 | + <div key={index} className="text-xs"> | |
| 80 | + • {warning} | |
| 81 | + </div> | |
| 82 | + ))} | |
| 83 | + </div> | |
| 84 | + | |
| 85 | + {/* Action Buttons */} | |
| 86 | + <div className="flex flex-row items-center justify-end gap-2 pt-4"> | |
| 87 | + {/* Copy all warnings to clipboard */} | |
| 88 | + <GhostButton | |
| 89 | + onClick={() => copyWarningsToClipboard(update.warnings)} | |
| 90 | + className="flex items-center !px-1.5 !py-0.5 text-xs" | |
| 91 | + > | |
| 92 | + <ClipboardIcon className="mr-1 h-3 w-3" /> | |
| 93 | + <span>Copy output</span> | |
| 94 | + </GhostButton> | |
| 95 | + | |
| 96 | + {/* Open dev tools to view logs */} | |
| 97 | + <GhostButton | |
| 98 | + onClick={() => { | |
| 99 | + ideMessenger.post("toggleDevTools", undefined); | |
| 100 | + }} | |
| 101 | + className="flex items-center !px-1.5 !py-0.5 text-xs" | |
| 102 | + > | |
| 103 | + <ArrowTopRightOnSquareIcon className="mr-1 h-3 w-3" /> | |
| 104 | + <span>View Logs</span> | |
| 105 | + </GhostButton> | |
| 106 | + </div> | |
| 107 | + </div> | |
| 108 | + </div> | |
| 109 | + ); | |
| 110 | + } | |
| 111 | + | |
| 112 | + // Show error for failed status | |
| 113 | + return ( | |
| 114 | + <div className="flex items-center gap-2 italic text-red-600"> | |
| 115 | + <XCircleIcon className="h-4 w-4" /> | |
| 116 | + <span className="leading-relaxed">{update.desc}</span> | |
| 117 | + </div> | |
| 118 | + ); | |
| 119 | +} | |
| 120 | + | |
| 121 | +export default IndexingProgressErrorText; |
added gui/src/pages/config/features/indexing/IndexingProgressIndicator.tsx +48 −0
| @@ -0,0 +1,48 @@ | ||
| 1 | +import { | |
| 2 | + ArrowPathIcon, | |
| 3 | + CheckCircleIcon, | |
| 4 | + PauseCircleIcon, | |
| 5 | +} from "@heroicons/react/24/outline"; | |
| 6 | +import { IndexingProgressUpdate } from "core"; | |
| 7 | +import { getProgressPercentage } from "./IndexingProgress"; | |
| 8 | + | |
| 9 | +export interface IndexingProgressIndicatorProps { | |
| 10 | + update: IndexingProgressUpdate; | |
| 11 | +} | |
| 12 | + | |
| 13 | +const STATUS_TO_ICON: Record<IndexingProgressUpdate["status"], any> = { | |
| 14 | + disabled: null, | |
| 15 | + loading: null, | |
| 16 | + waiting: null, | |
| 17 | + indexing: ArrowPathIcon, | |
| 18 | + paused: PauseCircleIcon, | |
| 19 | + done: CheckCircleIcon, | |
| 20 | + failed: null, // Since we show an erorr message below | |
| 21 | + cancelled: null, | |
| 22 | +}; | |
| 23 | + | |
| 24 | +function IndexingProgressIndicator({ update }: IndexingProgressIndicatorProps) { | |
| 25 | + const progressPercentage = getProgressPercentage(update.progress).toFixed(0); | |
| 26 | + const Icon = STATUS_TO_ICON[update.status]; | |
| 27 | + const animateIcon = update.status === "indexing"; | |
| 28 | + const showProgress = | |
| 29 | + update.status !== "disabled" && progressPercentage !== "100"; | |
| 30 | + | |
| 31 | + return ( | |
| 32 | + <div className="text-lightgray flex items-center justify-between gap-1"> | |
| 33 | + {showProgress && <span className="text-xs">{progressPercentage}%</span>} | |
| 34 | + | |
| 35 | + {Icon && ( | |
| 36 | + <div className="flex items-center"> | |
| 37 | + <Icon | |
| 38 | + className={`text-lightgray inline-block h-4 w-4 align-top ${ | |
| 39 | + animateIcon ? "animate-spin-slow" : "" | |
| 40 | + }`} | |
| 41 | + ></Icon> | |
| 42 | + </div> | |
| 43 | + )} | |
| 44 | + </div> | |
| 45 | + ); | |
| 46 | +} | |
| 47 | + | |
| 48 | +export default IndexingProgressIndicator; |
added gui/src/pages/config/features/indexing/IndexingProgressSubtext.tsx +48 −0
| @@ -0,0 +1,48 @@ | ||
| 1 | +import { IndexingProgressUpdate } from "core"; | |
| 2 | + | |
| 3 | +export interface IndexingProgressSubtextProps { | |
| 4 | + update: IndexingProgressUpdate; | |
| 5 | + onClick: () => void; | |
| 6 | +} | |
| 7 | + | |
| 8 | +const STATUS_TO_SUBTITLE_TEXT: Record< | |
| 9 | + IndexingProgressUpdate["status"], | |
| 10 | + string | undefined | |
| 11 | +> = { | |
| 12 | + done: "Click to re-index", | |
| 13 | + loading: "", | |
| 14 | + waiting: "", | |
| 15 | + indexing: "Click to pause", | |
| 16 | + paused: "Click to resume", | |
| 17 | + failed: "Click to retry", | |
| 18 | + disabled: "Click to open agent configuration", | |
| 19 | + cancelled: "Click to restart", | |
| 20 | +}; | |
| 21 | + | |
| 22 | +function IndexingProgressSubtext({ | |
| 23 | + update, | |
| 24 | + onClick, | |
| 25 | +}: IndexingProgressSubtextProps) { | |
| 26 | + const showIndexingDesc = update.status === "indexing"; | |
| 27 | + | |
| 28 | + return ( | |
| 29 | + <div className="flex justify-between"> | |
| 30 | + <span | |
| 31 | + className={`text-lightgray inline-block cursor-pointer text-xs underline`} | |
| 32 | + onClick={onClick} | |
| 33 | + > | |
| 34 | + {STATUS_TO_SUBTITLE_TEXT[update.status]} | |
| 35 | + </span> | |
| 36 | + | |
| 37 | + <div className={`${showIndexingDesc ? "w-2/3" : "flex-1"}`}> | |
| 38 | + {showIndexingDesc && ( | |
| 39 | + <span className="text-lightgray block truncate text-right text-xs"> | |
| 40 | + {update.desc} | |
| 41 | + </span> | |
| 42 | + )} | |
| 43 | + </div> | |
| 44 | + </div> | |
| 45 | + ); | |
| 46 | +} | |
| 47 | + | |
| 48 | +export default IndexingProgressSubtext; |
added gui/src/pages/config/features/indexing/IndexingProgressTitleText.tsx +30 −0
| @@ -0,0 +1,30 @@ | ||
| 1 | +import { IndexingProgressUpdate } from "core"; | |
| 2 | +import { AnimatedEllipsis } from "../../../../components/AnimatedEllipsis"; | |
| 3 | + | |
| 4 | +export interface IndexingProgressTitleTextProps { | |
| 5 | + update: IndexingProgressUpdate; | |
| 6 | +} | |
| 7 | + | |
| 8 | +const STATUS_TO_TEXT: Record<IndexingProgressUpdate["status"], string> = { | |
| 9 | + done: "Indexing complete", | |
| 10 | + loading: "Initializing", | |
| 11 | + waiting: "Indexing other workspace", | |
| 12 | + indexing: "Indexing in-progress", | |
| 13 | + paused: "Indexing paused", | |
| 14 | + failed: "Indexing failed", | |
| 15 | + disabled: "Indexing disabled", | |
| 16 | + cancelled: "Indexing cancelled", | |
| 17 | +}; | |
| 18 | + | |
| 19 | +function IndexingProgressTitleText({ update }: IndexingProgressTitleTextProps) { | |
| 20 | + const showEllipsis = update.status === "loading"; | |
| 21 | + | |
| 22 | + return ( | |
| 23 | + <span> | |
| 24 | + {STATUS_TO_TEXT[update.status]} | |
| 25 | + {showEllipsis && <AnimatedEllipsis />} | |
| 26 | + </span> | |
| 27 | + ); | |
| 28 | +} | |
| 29 | + | |
| 30 | +export default IndexingProgressTitleText; |
added gui/src/pages/config/features/indexing/index.ts +1 −0
| @@ -0,0 +1,1 @@ | ||
| 1 | +export { default } from "./IndexingProgress"; |
added gui/src/pages/config/features/keyboard/KeyboardShortcuts.tsx +157 −0
| @@ -0,0 +1,157 @@ | ||
| 1 | +import { useMemo } from "react"; | |
| 2 | +import Shortcut from "../../../../components/gui/Shortcut"; | |
| 3 | +import { isJetBrains } from "../../../../util"; | |
| 4 | + | |
| 5 | +interface KeyboardShortcutProps { | |
| 6 | + shortcut: string; | |
| 7 | + description: string; | |
| 8 | + isEven: boolean; | |
| 9 | +} | |
| 10 | + | |
| 11 | +function KeyboardShortcut(props: KeyboardShortcutProps) { | |
| 12 | + return ( | |
| 13 | + <div | |
| 14 | + className={`flex flex-col items-start p-2 sm:flex-row sm:items-center ${props.isEven ? "" : "bg-table-oddRow"}`} | |
| 15 | + > | |
| 16 | + <div className="w-full flex-grow pb-1 pr-4 sm:w-auto sm:pb-0"> | |
| 17 | + <span className="block break-words text-xs">{props.description}:</span> | |
| 18 | + </div> | |
| 19 | + <div className="flex-shrink-0 whitespace-nowrap"> | |
| 20 | + <Shortcut>{props.shortcut}</Shortcut> | |
| 21 | + </div> | |
| 22 | + </div> | |
| 23 | + ); | |
| 24 | +} | |
| 25 | + | |
| 26 | +// Shortcut strings will be rendered correctly based on the platform by the Shortcut component | |
| 27 | +const vscodeShortcuts: Omit<KeyboardShortcutProps, "isEven">[] = [ | |
| 28 | + { | |
| 29 | + shortcut: "cmd '", | |
| 30 | + description: "Toggle Selected Model", | |
| 31 | + }, | |
| 32 | + { | |
| 33 | + shortcut: "cmd I", | |
| 34 | + description: "Edit highlighted code", | |
| 35 | + }, | |
| 36 | + { | |
| 37 | + shortcut: "cmd L", | |
| 38 | + description: | |
| 39 | + "New Chat / New Chat With Selected Code / Close Continue Sidebar If Chat Already In Focus", | |
| 40 | + }, | |
| 41 | + { | |
| 42 | + shortcut: "cmd backspace", | |
| 43 | + description: "Cancel response", | |
| 44 | + }, | |
| 45 | + { | |
| 46 | + shortcut: "cmd shift I", | |
| 47 | + description: "Toggle inline edit focus", | |
| 48 | + }, | |
| 49 | + { | |
| 50 | + shortcut: "cmd shift L", | |
| 51 | + description: | |
| 52 | + "Focus Current Chat / Add Selected Code To Current Chat / Close Continue Sidebar If Chat Already In Focus", | |
| 53 | + }, | |
| 54 | + { | |
| 55 | + shortcut: "cmd shift R", | |
| 56 | + description: "Debug Terminal", | |
| 57 | + }, | |
| 58 | + { | |
| 59 | + shortcut: "cmd shift backspace", | |
| 60 | + description: "Reject Diff", | |
| 61 | + }, | |
| 62 | + { | |
| 63 | + shortcut: "cmd shift enter", | |
| 64 | + description: "Accept Diff", | |
| 65 | + }, | |
| 66 | + { | |
| 67 | + shortcut: "alt cmd N", | |
| 68 | + description: "Reject Top Change in Diff", | |
| 69 | + }, | |
| 70 | + { | |
| 71 | + shortcut: "alt cmd Y", | |
| 72 | + description: "Accept Top Change in Diff", | |
| 73 | + }, | |
| 74 | + { | |
| 75 | + shortcut: "cmd K cmd A", | |
| 76 | + description: "Toggle Autocomplete Enabled", | |
| 77 | + }, | |
| 78 | + { | |
| 79 | + shortcut: "cmd alt space", | |
| 80 | + description: "Force an Autocomplete Trigger", | |
| 81 | + }, | |
| 82 | + { | |
| 83 | + shortcut: "cmd K cmd M", | |
| 84 | + description: "Toggle Full Screen", | |
| 85 | + }, | |
| 86 | +]; | |
| 87 | + | |
| 88 | +const jetbrainsShortcuts: Omit<KeyboardShortcutProps, "isEven">[] = [ | |
| 89 | + { | |
| 90 | + shortcut: "cmd '", | |
| 91 | + description: "Toggle Selected Model", | |
| 92 | + }, | |
| 93 | + { | |
| 94 | + shortcut: "cmd I", | |
| 95 | + description: "Edit highlighted code", | |
| 96 | + }, | |
| 97 | + { | |
| 98 | + shortcut: "cmd J", | |
| 99 | + description: | |
| 100 | + "New Chat / New Chat With Selected Code / Close Continue Sidebar If Chat Already In Focus", | |
| 101 | + }, | |
| 102 | + { | |
| 103 | + shortcut: "cmd backspace", | |
| 104 | + description: "Cancel response", | |
| 105 | + }, | |
| 106 | + { | |
| 107 | + shortcut: "cmd shift I", | |
| 108 | + description: "Toggle inline edit focus", | |
| 109 | + }, | |
| 110 | + { | |
| 111 | + shortcut: "cmd shift J", | |
| 112 | + description: | |
| 113 | + "Focus Current Chat / Add Selected Code To Current Chat / Close Continue Sidebar If Chat Already In Focus", | |
| 114 | + }, | |
| 115 | + { | |
| 116 | + shortcut: "cmd shift backspace", | |
| 117 | + description: "Reject Diff", | |
| 118 | + }, | |
| 119 | + { | |
| 120 | + shortcut: "cmd shift enter", | |
| 121 | + description: "Accept Diff", | |
| 122 | + }, | |
| 123 | + { | |
| 124 | + shortcut: "alt shift J", | |
| 125 | + description: "Quick Input", | |
| 126 | + }, | |
| 127 | + { | |
| 128 | + shortcut: "alt cmd J", | |
| 129 | + description: "Toggle Sidebar", | |
| 130 | + }, | |
| 131 | +]; | |
| 132 | + | |
| 133 | +function KeyboardShortcuts() { | |
| 134 | + const shortcuts = useMemo(() => { | |
| 135 | + return isJetBrains() ? jetbrainsShortcuts : vscodeShortcuts; | |
| 136 | + }, []); | |
| 137 | + | |
| 138 | + return ( | |
| 139 | + <div className="h-full overflow-auto"> | |
| 140 | + <h3 className="mb-3 text-xl">Keyboard shortcuts</h3> | |
| 141 | + <div> | |
| 142 | + {shortcuts.map((shortcut, i) => { | |
| 143 | + return ( | |
| 144 | + <KeyboardShortcut | |
| 145 | + key={i} | |
| 146 | + shortcut={shortcut.shortcut} | |
| 147 | + description={shortcut.description} | |
| 148 | + isEven={i % 2 === 0} | |
| 149 | + /> | |
| 150 | + ); | |
| 151 | + })} | |
| 152 | + </div> | |
| 153 | + </div> | |
| 154 | + ); | |
| 155 | +} | |
| 156 | + | |
| 157 | +export default KeyboardShortcuts; |
added gui/src/pages/config/hooks/useToolPolicies.ts +74 −0
| @@ -0,0 +1,74 @@ | ||
| 1 | +import { MessageModes, Tool } from "core"; | |
| 2 | +import { useMemo, useState } from "react"; | |
| 3 | +import { useAppSelector } from "../../../redux/hooks"; | |
| 4 | + | |
| 5 | +export function useToolPolicies() { | |
| 6 | + const mode = useAppSelector((state) => state.session.mode); | |
| 7 | + const availableTools = useAppSelector((state) => state.config.config.tools); | |
| 8 | + const toolGroupSettings = useAppSelector( | |
| 9 | + (store) => store.ui.toolGroupSettings, | |
| 10 | + ); | |
| 11 | + const [expandedGroups, setExpandedGroups] = useState<{ | |
| 12 | + [key: string]: boolean; | |
| 13 | + }>({}); | |
| 14 | + | |
| 15 | + const toolsByGroup = useMemo(() => { | |
| 16 | + const byGroup: Record<string, Tool[]> = {}; | |
| 17 | + for (const tool of availableTools) { | |
| 18 | + if (!byGroup[tool.group]) { | |
| 19 | + byGroup[tool.group] = []; | |
| 20 | + } | |
| 21 | + byGroup[tool.group].push(tool); | |
| 22 | + } | |
| 23 | + return Object.entries(byGroup); | |
| 24 | + }, [availableTools]); | |
| 25 | + | |
| 26 | + // Detect duplicate tool names | |
| 27 | + const duplicateDetection = useMemo(() => { | |
| 28 | + const counts: Record<string, number> = {}; | |
| 29 | + availableTools.forEach((tool) => { | |
| 30 | + if (counts[tool.function.name]) { | |
| 31 | + counts[tool.function.name] = counts[tool.function.name] + 1; | |
| 32 | + } else { | |
| 33 | + counts[tool.function.name] = 1; | |
| 34 | + } | |
| 35 | + }); | |
| 36 | + return Object.fromEntries( | |
| 37 | + Object.entries(counts).map(([k, v]) => [k, v > 1]), | |
| 38 | + ); | |
| 39 | + }, [availableTools]); | |
| 40 | + | |
| 41 | + const allToolsOff = mode === "chat"; | |
| 42 | + | |
| 43 | + const getMessage = (mode: MessageModes) => { | |
| 44 | + switch (mode) { | |
| 45 | + case "chat": | |
| 46 | + return "All tools disabled in Chat, switch to Plan or Agent mode to use tools"; | |
| 47 | + case "plan": | |
| 48 | + return "Read-only/MCP tools available in Plan mode"; | |
| 49 | + default: | |
| 50 | + return ""; | |
| 51 | + } | |
| 52 | + }; | |
| 53 | + | |
| 54 | + const message = getMessage(mode); | |
| 55 | + | |
| 56 | + const toggleGroup = (groupName: string) => { | |
| 57 | + setExpandedGroups((prev) => ({ | |
| 58 | + ...prev, | |
| 59 | + [groupName]: !prev[groupName], | |
| 60 | + })); | |
| 61 | + }; | |
| 62 | + | |
| 63 | + return { | |
| 64 | + mode, | |
| 65 | + availableTools, | |
| 66 | + toolGroupSettings, | |
| 67 | + toolsByGroup, | |
| 68 | + duplicateDetection, | |
| 69 | + allToolsOff, | |
| 70 | + message, | |
| 71 | + expandedGroups, | |
| 72 | + toggleGroup, | |
| 73 | + }; | |
| 74 | +} |
modified gui/src/pages/config/index.tsx +89 −78
| @@ -1,94 +1,105 @@ | ||
| 1 | -import { | |
| 2 | - BoltIcon, | |
| 3 | - CircleStackIcon, | |
| 4 | - Cog6ToothIcon, | |
| 5 | - QuestionMarkCircleIcon, | |
| 6 | -} from "@heroicons/react/24/outline"; | |
| 7 | -import { useState } from "react"; | |
| 8 | -import { useNavigate } from "react-router-dom"; | |
| 9 | -import { PageHeader } from "../../components/PageHeader"; | |
| 1 | +import { isOnPremSession } from "core/control-plane/AuthTypes"; | |
| 2 | +import React, { useEffect, useState } from "react"; | |
| 3 | +import { useNavigate, useSearchParams } from "react-router-dom"; | |
| 4 | +import { AssistantAndOrgListbox } from "../../components/AssistantAndOrgListbox"; | |
| 5 | +import Alert from "../../components/gui/Alert"; | |
| 6 | +import { Divider } from "../../components/ui/Divider"; | |
| 7 | +import { TabGroup } from "../../components/ui/TabGroup"; | |
| 8 | +import { useAuth } from "../../context/Auth"; | |
| 10 | 9 | import { useNavigationListener } from "../../hooks/useNavigationListener"; |
| 11 | -import { fontSize } from "../../util"; | |
| 12 | -import { AccountButton } from "./AccountButton"; | |
| 13 | -import { HelpCenterSection } from "./HelpCenterSection"; | |
| 14 | -import { IndexingSettingsSection } from "./IndexingSettingsSection"; | |
| 15 | -import KeyboardShortcuts from "./KeyboardShortcuts"; | |
| 16 | -import { UserSettingsForm } from "./UserSettingsForm"; | |
| 17 | - | |
| 18 | -type TabOption = { | |
| 19 | - id: string; | |
| 20 | - label: string; | |
| 21 | - component: React.ReactNode; | |
| 22 | - icon: React.ReactNode; | |
| 23 | -}; | |
| 10 | +import { bottomTabSections, getAllTabs, topTabSections } from "./configTabs"; | |
| 11 | +import { AccountDropdown } from "./features/account/AccountDropdown"; | |
| 24 | 12 | |
| 25 | 13 | function ConfigPage() { |
| 26 | 14 | useNavigationListener(); |
| 27 | 15 | const navigate = useNavigate(); |
| 16 | + const [searchParams] = useSearchParams(); | |
| 28 | 17 | const [activeTab, setActiveTab] = useState("settings"); |
| 18 | + const { session, organizations } = useAuth(); | |
| 29 | 19 | |
| 30 | - const tabs: TabOption[] = [ | |
| 31 | - { | |
| 32 | - id: "settings", | |
| 33 | - label: "Settings", | |
| 34 | - component: <UserSettingsForm />, | |
| 35 | - icon: <Cog6ToothIcon className="xs:h-4 xs:w-4 h-3 w-3 flex-shrink-0" />, | |
| 36 | - }, | |
| 37 | - { | |
| 38 | - id: "indexing", | |
| 39 | - label: "Indexing", | |
| 40 | - component: <IndexingSettingsSection />, | |
| 41 | - icon: <CircleStackIcon className="xs:h-4 xs:w-4 h-3 w-3 flex-shrink-0" />, | |
| 42 | - }, | |
| 43 | - { | |
| 44 | - id: "help", | |
| 45 | - label: "Help", | |
| 46 | - component: <HelpCenterSection />, | |
| 47 | - icon: ( | |
| 48 | - <QuestionMarkCircleIcon className="xs:h-4 xs:w-4 h-3 w-3 flex-shrink-0" /> | |
| 49 | - ), | |
| 50 | - }, | |
| 51 | - { | |
| 52 | - id: "shortcuts", | |
| 53 | - label: "Shortcuts", | |
| 54 | - component: <KeyboardShortcuts />, | |
| 55 | - icon: <BoltIcon className="xs:h-4 xs:w-4 h-3 w-3 flex-shrink-0" />, | |
| 56 | - }, | |
| 57 | - ]; | |
| 20 | + // Set initial tab from URL parameter | |
| 21 | + useEffect(() => { | |
| 22 | + const tab = searchParams.get("tab"); | |
| 23 | + if (tab) { | |
| 24 | + setActiveTab(tab); | |
| 25 | + } | |
| 26 | + }, [searchParams]); | |
| 27 | + | |
| 28 | + const allTabs = getAllTabs(); | |
| 29 | + const shouldRenderOrgInfo = | |
| 30 | + session && organizations.length > 1 && !isOnPremSession(session); | |
| 31 | + | |
| 32 | + const handleTabClick = (tabId: string) => { | |
| 33 | + if (tabId === "back") { | |
| 34 | + navigate("/"); | |
| 35 | + } else { | |
| 36 | + setActiveTab(tabId); | |
| 37 | + } | |
| 38 | + }; | |
| 58 | 39 | |
| 59 | 40 | return ( |
| 60 | - <div className="flex h-full flex-col overflow-y-auto"> | |
| 61 | - <div className="bg-vsc-background sticky top-0 z-10"> | |
| 62 | - <PageHeader | |
| 63 | - showBorder | |
| 64 | - onTitleClick={() => navigate("/")} | |
| 65 | - title="Chat" | |
| 66 | - rightContent={<AccountButton />} | |
| 67 | - /> | |
| 68 | - | |
| 69 | - {/* Tab Headers */} | |
| 70 | - <div className="bg-vsc-input-background grid cursor-pointer grid-cols-2 border-0 border-b-[1px] border-solid border-b-zinc-700 p-0.5 sm:flex sm:justify-center md:gap-x-2"> | |
| 71 | - {tabs.map((tab) => ( | |
| 72 | - <div | |
| 73 | - style={{ | |
| 74 | - fontSize: fontSize(-2), | |
| 75 | - }} | |
| 76 | - key={tab.id} | |
| 77 | - className={`flex cursor-pointer items-center justify-center gap-1.5 rounded-md px-2 py-2 hover:brightness-125 ${ | |
| 78 | - activeTab === tab.id ? "" : "text-gray-400" | |
| 79 | - }`} | |
| 80 | - onClick={() => setActiveTab(tab.id)} | |
| 81 | - > | |
| 82 | - {tab.icon} | |
| 83 | - {tab.label} | |
| 84 | - </div> | |
| 41 | + <div className="flex h-full flex-row overflow-hidden"> | |
| 42 | + {/* Vertical Sidebar - full height */} | |
| 43 | + <div className="bg-vsc-background flex w-12 flex-shrink-0 flex-col border-0 md:w-40"> | |
| 44 | + <div className="border-r-border flex flex-1 flex-col overflow-y-auto border-b-0 border-l-0 border-r-2 border-t-0 border-solid p-2 text-xs"> | |
| 45 | + {topTabSections.map((section, index) => ( | |
| 46 | + <React.Fragment key={section.id}> | |
| 47 | + <TabGroup | |
| 48 | + tabs={section.tabs} | |
| 49 | + activeTab={activeTab} | |
| 50 | + onTabClick={handleTabClick} | |
| 51 | + showTopDivider={section.showTopDivider} | |
| 52 | + showBottomDivider={section.showBottomDivider} | |
| 53 | + className={section.className} | |
| 54 | + /> | |
| 55 | + {index === 0 && shouldRenderOrgInfo && ( | |
| 56 | + <> | |
| 57 | + <Divider /> | |
| 58 | + <AssistantAndOrgListbox variant="sidebar" /> | |
| 59 | + </> | |
| 60 | + )} | |
| 61 | + </React.Fragment> | |
| 62 | + ))} | |
| 63 | + | |
| 64 | + <div className="flex-1" /> | |
| 65 | + | |
| 66 | + {bottomTabSections.map((section) => ( | |
| 67 | + <TabGroup | |
| 68 | + key={section.id} | |
| 69 | + tabs={section.tabs} | |
| 70 | + activeTab={activeTab} | |
| 71 | + onTabClick={handleTabClick} | |
| 72 | + showTopDivider={section.showTopDivider} | |
| 73 | + showBottomDivider={section.showBottomDivider} | |
| 74 | + className={section.className} | |
| 75 | + /> | |
| 85 | 76 | ))} |
| 77 | + | |
| 78 | + <Divider /> | |
| 79 | + | |
| 80 | + <AccountDropdown /> | |
| 86 | 81 | </div> |
| 87 | 82 | </div> |
| 88 | 83 | |
| 89 | - {/* Tab Content */} | |
| 90 | - <div className="flex-1 overflow-y-auto px-4"> | |
| 91 | - {tabs.find((tab) => tab.id === activeTab)?.component} | |
| 84 | + {/* Main content area */} | |
| 85 | + <div className="flex min-h-0 flex-1 flex-col overflow-hidden"> | |
| 86 | + {/* Alert for small screens (sm and below) */} | |
| 87 | + <div className="block px-4 py-4 sm:hidden"> | |
| 88 | + <Alert type="warning" className="max-w-md"> | |
| 89 | + <div className="flex flex-col"> | |
| 90 | + <div className="font-medium">Screen width too small</div> | |
| 91 | + <div className="text-description mt-1 text-sm"> | |
| 92 | + To view settings, please expand the sidebar by dragging the | |
| 93 | + left/right border | |
| 94 | + </div> | |
| 95 | + </div> | |
| 96 | + </Alert> | |
| 97 | + </div> | |
| 98 | + | |
| 99 | + {/* Tab Content for larger screens (md and above) */} | |
| 100 | + <div className="hidden flex-1 space-y-6 overflow-y-auto px-4 py-4 sm:block"> | |
| 101 | + {allTabs.find((tab) => tab.id === activeTab)?.component} | |
| 102 | + </div> | |
| 92 | 103 | </div> |
| 93 | 104 | </div> |
| 94 | 105 | ); |
added gui/src/pages/config/sections/AgentsSection.tsx +79 −0
| @@ -0,0 +1,79 @@ | ||
| 1 | +import { Cog6ToothIcon } from "@heroicons/react/24/outline"; | |
| 2 | +import { useContext } from "react"; | |
| 3 | +import { AssistantIcon } from "../../../components/AssistantAndOrgListbox/AssistantIcon"; | |
| 4 | +import { ToolTip } from "../../../components/gui/Tooltip"; | |
| 5 | +import { Button, Card, Divider, EmptyState } from "../../../components/ui"; | |
| 6 | +import { useAuth } from "../../../context/Auth"; | |
| 7 | +import { IdeMessengerContext } from "../../../context/IdeMessenger"; | |
| 8 | +import { ConfigHeader } from "../components/ConfigHeader"; | |
| 9 | + | |
| 10 | +export function AgentsSection() { | |
| 11 | + const { profiles } = useAuth(); | |
| 12 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 13 | + | |
| 14 | + function handleAddAgent() { | |
| 15 | + void ideMessenger.request("config/newAssistantFile", undefined); | |
| 16 | + } | |
| 17 | + | |
| 18 | + function handleConfigureAgent(profileId: string) { | |
| 19 | + ideMessenger.post("config/openProfile", { profileId }); | |
| 20 | + } | |
| 21 | + | |
| 22 | + return ( | |
| 23 | + <> | |
| 24 | + <ConfigHeader | |
| 25 | + title="Agents" | |
| 26 | + onAddClick={handleAddAgent} | |
| 27 | + addButtonTooltip="Add agent" | |
| 28 | + /> | |
| 29 | + | |
| 30 | + <Card> | |
| 31 | + {profiles && profiles.length > 0 ? ( | |
| 32 | + profiles.map((profile, index) => ( | |
| 33 | + <div key={profile.id}> | |
| 34 | + <div className="flex items-center justify-between"> | |
| 35 | + <div className="flex items-baseline gap-3"> | |
| 36 | + <div className="flex h-6 w-6 flex-shrink-0 items-center justify-center"> | |
| 37 | + <AssistantIcon assistant={profile} /> | |
| 38 | + </div> | |
| 39 | + <div className="flex-1"> | |
| 40 | + <h3 | |
| 41 | + className={`my-2 text-sm font-medium ${profile.errors && profile.errors.length > 0 ? "text-error" : ""}`} | |
| 42 | + > | |
| 43 | + {profile.title} | |
| 44 | + </h3> | |
| 45 | + {profile.errors && profile.errors.length > 0 && ( | |
| 46 | + <div className="mt-2 space-y-1"> | |
| 47 | + {profile.errors.map((error, errorIndex) => ( | |
| 48 | + <div | |
| 49 | + key={errorIndex} | |
| 50 | + className="text-error bg-error/10 rounded py-1 pr-2 text-xs" | |
| 51 | + > | |
| 52 | + {error.message} | |
| 53 | + </div> | |
| 54 | + ))} | |
| 55 | + </div> | |
| 56 | + )} | |
| 57 | + </div> | |
| 58 | + </div> | |
| 59 | + <ToolTip content="Configure agent"> | |
| 60 | + <Button | |
| 61 | + onClick={() => handleConfigureAgent(profile.id)} | |
| 62 | + variant="ghost" | |
| 63 | + size="sm" | |
| 64 | + className="text-description-muted hover:enabled:text-foreground my-0 h-6 w-6 p-0" | |
| 65 | + > | |
| 66 | + <Cog6ToothIcon className="h-4 w-4 flex-shrink-0" /> | |
| 67 | + </Button> | |
| 68 | + </ToolTip> | |
| 69 | + </div> | |
| 70 | + {index < profiles.length - 1 && <Divider />} | |
| 71 | + </div> | |
| 72 | + )) | |
| 73 | + ) : ( | |
| 74 | + <EmptyState message="No agents configured. Click the + button to add your first agent." /> | |
| 75 | + )} | |
| 76 | + </Card> | |
| 77 | + </> | |
| 78 | + ); | |
| 79 | +} |
added gui/src/pages/config/sections/DocsSection.tsx +32 −0
| @@ -0,0 +1,32 @@ | ||
| 1 | +import { useDispatch } from "react-redux"; | |
| 2 | +import AddDocsDialog from "../../../components/dialogs/AddDocsDialog"; | |
| 3 | +import { Card, Divider } from "../../../components/ui"; | |
| 4 | +import { setDialogMessage, setShowDialog } from "../../../redux/slices/uiSlice"; | |
| 5 | +import { ConfigHeader } from "../components/ConfigHeader"; | |
| 6 | +import DocsIndexingStatuses from "./docs/DocsSection"; | |
| 7 | + | |
| 8 | +export function DocsSection() { | |
| 9 | + const dispatch = useDispatch(); | |
| 10 | + | |
| 11 | + function handleAddDocs() { | |
| 12 | + dispatch(setShowDialog(true)); | |
| 13 | + dispatch(setDialogMessage(<AddDocsDialog />)); | |
| 14 | + } | |
| 15 | + | |
| 16 | + return ( | |
| 17 | + <div> | |
| 18 | + <ConfigHeader | |
| 19 | + title="Documentation" | |
| 20 | + onAddClick={handleAddDocs} | |
| 21 | + addButtonTooltip="Add documentation" | |
| 22 | + variant="sm" | |
| 23 | + /> | |
| 24 | + | |
| 25 | + <Card> | |
| 26 | + <div className="py-2"> | |
| 27 | + <DocsIndexingStatuses /> | |
| 28 | + </div> | |
| 29 | + </Card> | |
| 30 | + </div> | |
| 31 | + ); | |
| 32 | +} |
added gui/src/pages/config/sections/HelpSection.tsx +304 −0
| @@ -0,0 +1,304 @@ | ||
| 1 | +import { | |
| 2 | + DocumentArrowUpIcon, | |
| 3 | + LinkIcon, | |
| 4 | + NumberedListIcon, | |
| 5 | + PaintBrushIcon, | |
| 6 | + TableCellsIcon, | |
| 7 | +} from "@heroicons/react/24/outline"; | |
| 8 | +import { useContext, useMemo } from "react"; | |
| 9 | +import { useNavigate } from "react-router-dom"; | |
| 10 | +import Shortcut from "../../../components/gui/Shortcut"; | |
| 11 | +import { Card } from "../../../components/ui"; | |
| 12 | +import { IdeMessengerContext } from "../../../context/IdeMessenger"; | |
| 13 | +import { useAppDispatch, useAppSelector } from "../../../redux/hooks"; | |
| 14 | +import { setOnboardingCard } from "../../../redux/slices/uiSlice"; | |
| 15 | +import { saveCurrentSession } from "../../../redux/thunks/session"; | |
| 16 | +import { isJetBrains } from "../../../util"; | |
| 17 | +import { ROUTES } from "../../../util/navigation"; | |
| 18 | +import { ConfigHeader } from "../components/ConfigHeader"; | |
| 19 | +import { ConfigRow } from "../components/ConfigRow"; | |
| 20 | + | |
| 21 | +interface KeyboardShortcutProps { | |
| 22 | + shortcut: string; | |
| 23 | + description: string; | |
| 24 | + isEven: boolean; | |
| 25 | +} | |
| 26 | + | |
| 27 | +function KeyboardShortcut(props: KeyboardShortcutProps) { | |
| 28 | + return ( | |
| 29 | + <div | |
| 30 | + className={`flex flex-col items-start p-3 sm:flex-row sm:items-center ${props.isEven ? "" : "bg-vsc-editor-background/50"}`} | |
| 31 | + > | |
| 32 | + <div className="w-full flex-grow pb-2 pr-4 sm:w-auto sm:pb-0"> | |
| 33 | + <span className="block break-words text-sm">{props.description}:</span> | |
| 34 | + </div> | |
| 35 | + <div className="flex-shrink-0 whitespace-nowrap"> | |
| 36 | + <Shortcut>{props.shortcut}</Shortcut> | |
| 37 | + </div> | |
| 38 | + </div> | |
| 39 | + ); | |
| 40 | +} | |
| 41 | + | |
| 42 | +// Shortcut strings will be rendered correctly based on the platform by the Shortcut component | |
| 43 | +const vscodeShortcuts: Omit<KeyboardShortcutProps, "isEven">[] = [ | |
| 44 | + { | |
| 45 | + shortcut: "cmd '", | |
| 46 | + description: "Toggle Selected Model", | |
| 47 | + }, | |
| 48 | + { | |
| 49 | + shortcut: "cmd I", | |
| 50 | + description: "Edit highlighted code", | |
| 51 | + }, | |
| 52 | + { | |
| 53 | + shortcut: "cmd L", | |
| 54 | + description: | |
| 55 | + "New Chat / New Chat With Selected Code / Close Continue Sidebar If Chat Already In Focus", | |
| 56 | + }, | |
| 57 | + { | |
| 58 | + shortcut: "cmd backspace", | |
| 59 | + description: "Cancel response", | |
| 60 | + }, | |
| 61 | + { | |
| 62 | + shortcut: "cmd shift I", | |
| 63 | + description: "Toggle inline edit focus", | |
| 64 | + }, | |
| 65 | + { | |
| 66 | + shortcut: "cmd shift L", | |
| 67 | + description: | |
| 68 | + "Focus Current Chat / Add Selected Code To Current Chat / Close Continue Sidebar If Chat Already In Focus", | |
| 69 | + }, | |
| 70 | + { | |
| 71 | + shortcut: "cmd shift R", | |
| 72 | + description: "Debug Terminal", | |
| 73 | + }, | |
| 74 | + { | |
| 75 | + shortcut: "cmd shift backspace", | |
| 76 | + description: "Reject Diff", | |
| 77 | + }, | |
| 78 | + { | |
| 79 | + shortcut: "cmd shift enter", | |
| 80 | + description: "Accept Diff", | |
| 81 | + }, | |
| 82 | + { | |
| 83 | + shortcut: "alt cmd N", | |
| 84 | + description: "Reject Top Change in Diff", | |
| 85 | + }, | |
| 86 | + { | |
| 87 | + shortcut: "alt cmd Y", | |
| 88 | + description: "Accept Top Change in Diff", | |
| 89 | + }, | |
| 90 | + { | |
| 91 | + shortcut: "cmd K cmd A", | |
| 92 | + description: "Toggle Autocomplete Enabled", | |
| 93 | + }, | |
| 94 | + { | |
| 95 | + shortcut: "cmd alt space", | |
| 96 | + description: "Force an Autocomplete Trigger", | |
| 97 | + }, | |
| 98 | + { | |
| 99 | + shortcut: "cmd K cmd M", | |
| 100 | + description: "Toggle Full Screen", | |
| 101 | + }, | |
| 102 | +]; | |
| 103 | + | |
| 104 | +const jetbrainsShortcuts: Omit<KeyboardShortcutProps, "isEven">[] = [ | |
| 105 | + { | |
| 106 | + shortcut: "cmd '", | |
| 107 | + description: "Toggle Selected Model", | |
| 108 | + }, | |
| 109 | + { | |
| 110 | + shortcut: "cmd I", | |
| 111 | + description: "Edit highlighted code", | |
| 112 | + }, | |
| 113 | + { | |
| 114 | + shortcut: "cmd J", | |
| 115 | + description: | |
| 116 | + "New Chat / New Chat With Selected Code / Close Continue Sidebar If Chat Already In Focus", | |
| 117 | + }, | |
| 118 | + { | |
| 119 | + shortcut: "cmd backspace", | |
| 120 | + description: "Cancel response", | |
| 121 | + }, | |
| 122 | + { | |
| 123 | + shortcut: "cmd shift I", | |
| 124 | + description: "Toggle inline edit focus", | |
| 125 | + }, | |
| 126 | + { | |
| 127 | + shortcut: "cmd shift J", | |
| 128 | + description: | |
| 129 | + "Focus Current Chat / Add Selected Code To Current Chat / Close Continue Sidebar If Chat Already In Focus", | |
| 130 | + }, | |
| 131 | + { | |
| 132 | + shortcut: "cmd shift backspace", | |
| 133 | + description: "Reject Diff", | |
| 134 | + }, | |
| 135 | + { | |
| 136 | + shortcut: "cmd shift enter", | |
| 137 | + description: "Accept Diff", | |
| 138 | + }, | |
| 139 | + { | |
| 140 | + shortcut: "alt shift J", | |
| 141 | + description: "Quick Input", | |
| 142 | + }, | |
| 143 | + { | |
| 144 | + shortcut: "alt cmd J", | |
| 145 | + description: "Toggle Sidebar", | |
| 146 | + }, | |
| 147 | +]; | |
| 148 | + | |
| 149 | +export function HelpSection() { | |
| 150 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 151 | + const navigate = useNavigate(); | |
| 152 | + const dispatch = useAppDispatch(); | |
| 153 | + | |
| 154 | + const currentSession = useAppSelector((state) => state.session); | |
| 155 | + | |
| 156 | + const shortcuts = useMemo(() => { | |
| 157 | + return isJetBrains() ? jetbrainsShortcuts : vscodeShortcuts; | |
| 158 | + }, []); | |
| 159 | + | |
| 160 | + const handleViewSessionData = async () => { | |
| 161 | + const sessionData = await ideMessenger.request("history/load", { | |
| 162 | + id: currentSession.id, | |
| 163 | + }); | |
| 164 | + | |
| 165 | + if (sessionData.status === "success") { | |
| 166 | + await ideMessenger.request("showVirtualFile", { | |
| 167 | + name: `${sessionData.content.title}.json`, | |
| 168 | + content: JSON.stringify(sessionData.content, null, 2), | |
| 169 | + }); | |
| 170 | + } | |
| 171 | + }; | |
| 172 | + | |
| 173 | + return ( | |
| 174 | + <div className="flex flex-col"> | |
| 175 | + <ConfigHeader title="Help Center" /> | |
| 176 | + <div className="space-y-6"> | |
| 177 | + {/* Resources */} | |
| 178 | + <div> | |
| 179 | + <h3 className="mb-3 text-base font-medium">Resources</h3> | |
| 180 | + <Card className="!p-0"> | |
| 181 | + <div className="flex flex-col"> | |
| 182 | + <ConfigRow | |
| 183 | + title="Continue Hub" | |
| 184 | + description="Visit hub.continue.dev to explore custom agents and blocks" | |
| 185 | + icon={LinkIcon} | |
| 186 | + onClick={() => | |
| 187 | + ideMessenger.post("openUrl", "https://hub.continue.dev/") | |
| 188 | + } | |
| 189 | + /> | |
| 190 | + | |
| 191 | + <ConfigRow | |
| 192 | + title="Documentation" | |
| 193 | + description="Learn how to configure and use Continue" | |
| 194 | + icon={LinkIcon} | |
| 195 | + onClick={() => | |
| 196 | + ideMessenger.post("openUrl", "https://docs.continue.dev/") | |
| 197 | + } | |
| 198 | + /> | |
| 199 | + | |
| 200 | + <ConfigRow | |
| 201 | + title="Have an issue?" | |
| 202 | + description="Let us know on GitHub and we'll do our best to resolve it" | |
| 203 | + icon={LinkIcon} | |
| 204 | + onClick={() => | |
| 205 | + ideMessenger.post( | |
| 206 | + "openUrl", | |
| 207 | + "https://github.com/continuedev/continue/issues/new/choose", | |
| 208 | + ) | |
| 209 | + } | |
| 210 | + /> | |
| 211 | + | |
| 212 | + <ConfigRow | |
| 213 | + title="Join the community!" | |
| 214 | + description="Join us on Discord to stay up-to-date on the latest developments" | |
| 215 | + icon={LinkIcon} | |
| 216 | + onClick={() => | |
| 217 | + ideMessenger.post("openUrl", "https://discord.gg/vapESyrFmJ") | |
| 218 | + } | |
| 219 | + /> | |
| 220 | + </div> | |
| 221 | + </Card> | |
| 222 | + </div> | |
| 223 | + | |
| 224 | + {/* Tools */} | |
| 225 | + <div> | |
| 226 | + <h3 className="mb-3 text-base font-medium">Tools</h3> | |
| 227 | + <Card className="!p-0"> | |
| 228 | + <div className="flex flex-col"> | |
| 229 | + <ConfigRow | |
| 230 | + title="Token usage" | |
| 231 | + description="Daily token usage across models" | |
| 232 | + icon={TableCellsIcon} | |
| 233 | + onClick={() => navigate(ROUTES.STATS)} | |
| 234 | + /> | |
| 235 | + | |
| 236 | + {currentSession.history.length > 0 && | |
| 237 | + !currentSession.isStreaming && ( | |
| 238 | + <ConfigRow | |
| 239 | + title="View current session history" | |
| 240 | + description="Open the current chat session file for troubleshooting" | |
| 241 | + icon={NumberedListIcon} | |
| 242 | + onClick={handleViewSessionData} | |
| 243 | + /> | |
| 244 | + )} | |
| 245 | + | |
| 246 | + <ConfigRow | |
| 247 | + title="Quickstart" | |
| 248 | + description="Reopen the quickstart and tutorial file" | |
| 249 | + icon={DocumentArrowUpIcon} | |
| 250 | + onClick={async () => { | |
| 251 | + navigate("/"); | |
| 252 | + // Used to clear the chat panel before showing onboarding card | |
| 253 | + await dispatch( | |
| 254 | + saveCurrentSession({ | |
| 255 | + openNewSession: true, | |
| 256 | + generateTitle: true, | |
| 257 | + }), | |
| 258 | + ); | |
| 259 | + dispatch( | |
| 260 | + setOnboardingCard({ | |
| 261 | + show: true, | |
| 262 | + activeTab: undefined, | |
| 263 | + }), | |
| 264 | + ); | |
| 265 | + ideMessenger.post("showTutorial", undefined); | |
| 266 | + }} | |
| 267 | + /> | |
| 268 | + | |
| 269 | + {process.env.NODE_ENV === "development" && ( | |
| 270 | + <ConfigRow | |
| 271 | + title="Theme Test Page" | |
| 272 | + description="Development page for testing themes" | |
| 273 | + icon={PaintBrushIcon} | |
| 274 | + onClick={async () => { | |
| 275 | + navigate(ROUTES.THEME); | |
| 276 | + }} | |
| 277 | + /> | |
| 278 | + )} | |
| 279 | + </div> | |
| 280 | + </Card> | |
| 281 | + </div> | |
| 282 | + | |
| 283 | + {/* Keyboard Shortcuts */} | |
| 284 | + <div> | |
| 285 | + <h3 className="mb-3 text-base font-medium">Keyboard Shortcuts</h3> | |
| 286 | + <Card className="!p-0"> | |
| 287 | + <div className="overflow-hidden rounded-md border border-gray-600"> | |
| 288 | + {shortcuts.map((shortcut, i) => { | |
| 289 | + return ( | |
| 290 | + <KeyboardShortcut | |
| 291 | + key={i} | |
| 292 | + shortcut={shortcut.shortcut} | |
| 293 | + description={shortcut.description} | |
| 294 | + isEven={i % 2 === 0} | |
| 295 | + /> | |
| 296 | + ); | |
| 297 | + })} | |
| 298 | + </div> | |
| 299 | + </Card> | |
| 300 | + </div> | |
| 301 | + </div> | |
| 302 | + </div> | |
| 303 | + ); | |
| 304 | +} |
added gui/src/pages/config/sections/IndexingSettingsSection.tsx +119 −0
| @@ -0,0 +1,119 @@ | ||
| 1 | +import { | |
| 2 | + SharedConfigSchema, | |
| 3 | + modifyAnyConfigWithSharedConfig, | |
| 4 | +} from "core/config/sharedConfig"; | |
| 5 | +import { useContext } from "react"; | |
| 6 | +import Alert from "../../../components/gui/Alert"; | |
| 7 | +import { Card, Divider } from "../../../components/ui"; | |
| 8 | +import { IdeMessengerContext } from "../../../context/IdeMessenger"; | |
| 9 | +import { useAppDispatch, useAppSelector } from "../../../redux/hooks"; | |
| 10 | +import { updateConfig } from "../../../redux/slices/configSlice"; | |
| 11 | +import { selectCurrentOrg } from "../../../redux/slices/profilesSlice"; | |
| 12 | +import { ConfigHeader } from "../components/ConfigHeader"; | |
| 13 | +import { UserSetting } from "../components/UserSetting"; | |
| 14 | +import IndexingProgress from "../features/indexing"; | |
| 15 | +import { DocsSection } from "./DocsSection"; | |
| 16 | + | |
| 17 | +function CodebaseSubSection() { | |
| 18 | + const config = useAppSelector((state) => state.config.config); | |
| 19 | + | |
| 20 | + return ( | |
| 21 | + <div> | |
| 22 | + <div className="mb-4 flex items-center justify-between"> | |
| 23 | + <h3 className="mb-0 text-sm font-semibold">@codebase index</h3> | |
| 24 | + </div> | |
| 25 | + | |
| 26 | + <Card> | |
| 27 | + <div className="py-2"> | |
| 28 | + {config.disableIndexing ? ( | |
| 29 | + <div className="p-1"> | |
| 30 | + <p className="text-center font-semibold">Indexing is disabled</p> | |
| 31 | + </div> | |
| 32 | + ) : ( | |
| 33 | + <IndexingProgress /> | |
| 34 | + )} | |
| 35 | + </div> | |
| 36 | + </Card> | |
| 37 | + </div> | |
| 38 | + ); | |
| 39 | +} | |
| 40 | + | |
| 41 | +function EnableIndexingSetting() { | |
| 42 | + const dispatch = useAppDispatch(); | |
| 43 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 44 | + const config = useAppSelector((state) => state.config.config); | |
| 45 | + const currentOrg = useAppSelector(selectCurrentOrg); | |
| 46 | + | |
| 47 | + function handleUpdate(sharedConfig: SharedConfigSchema) { | |
| 48 | + const updatedConfig = modifyAnyConfigWithSharedConfig(config, sharedConfig); | |
| 49 | + dispatch(updateConfig(updatedConfig)); | |
| 50 | + ideMessenger.post("config/updateSharedConfig", sharedConfig); | |
| 51 | + } | |
| 52 | + | |
| 53 | + const disableIndexing = config.disableIndexing ?? false; | |
| 54 | + const disableIndexingToggle = | |
| 55 | + currentOrg?.policy?.allowCodebaseIndexing === false; | |
| 56 | + | |
| 57 | + return ( | |
| 58 | + <div className="flex flex-col gap-4"> | |
| 59 | + <UserSetting | |
| 60 | + title="Enable indexing" | |
| 61 | + type="toggle" | |
| 62 | + description={ | |
| 63 | + <div className="text-foreground"> | |
| 64 | + Allows indexing of your codebase for search and context | |
| 65 | + understanding. | |
| 66 | + <br /> | |
| 67 | + <br /> | |
| 68 | + Note that indexing can consume significant system resources, | |
| 69 | + especially on larger codebases. | |
| 70 | + </div> | |
| 71 | + } | |
| 72 | + value={!disableIndexing} | |
| 73 | + disabled={disableIndexingToggle} | |
| 74 | + onChange={(value) => handleUpdate({ disableIndexing: !value })} | |
| 75 | + /> | |
| 76 | + </div> | |
| 77 | + ); | |
| 78 | +} | |
| 79 | + | |
| 80 | +export function IndexingSettingsSection() { | |
| 81 | + const config = useAppSelector((state) => state.config.config); | |
| 82 | + const disableIndexing = config.disableIndexing ?? false; | |
| 83 | + | |
| 84 | + return ( | |
| 85 | + <> | |
| 86 | + <ConfigHeader title="Indexing" /> | |
| 87 | + | |
| 88 | + <Alert type="warning" className="mb-6"> | |
| 89 | + <div className="space-y-4"> | |
| 90 | + <div> | |
| 91 | + <div className="-mt-0.5 text-sm font-medium"> | |
| 92 | + Indexing has been deprecated | |
| 93 | + </div> | |
| 94 | + <div className="mt-1 text-xs"> | |
| 95 | + Learn how to{" "} | |
| 96 | + <a | |
| 97 | + href="https://docs.continue.dev/guides/codebase-documentation-awareness" | |
| 98 | + target="_blank" | |
| 99 | + rel="noopener noreferrer" | |
| 100 | + className="text-inherit underline hover:brightness-125" | |
| 101 | + > | |
| 102 | + make your agent aware of your codebase and documentation | |
| 103 | + </a> | |
| 104 | + </div> | |
| 105 | + </div> | |
| 106 | + <Divider className="border-inherit" /> | |
| 107 | + <EnableIndexingSetting /> | |
| 108 | + </div> | |
| 109 | + </Alert> | |
| 110 | + | |
| 111 | + {!disableIndexing && ( | |
| 112 | + <div className="space-y-8"> | |
| 113 | + <CodebaseSubSection /> | |
| 114 | + <DocsSection /> | |
| 115 | + </div> | |
| 116 | + )} | |
| 117 | + </> | |
| 118 | + ); | |
| 119 | +} |
added gui/src/pages/config/sections/McpSection.tsx +379 −0
| @@ -0,0 +1,379 @@ | ||
| 1 | +import { ConfigYaml, parseConfigYaml } from "@continuedev/config-yaml"; | |
| 2 | +import { | |
| 3 | + ArrowPathIcon, | |
| 4 | + ChevronDownIcon, | |
| 5 | + CircleStackIcon, | |
| 6 | + CommandLineIcon, | |
| 7 | + GlobeAltIcon, | |
| 8 | + UserCircleIcon, | |
| 9 | + WrenchScrewdriverIcon, | |
| 10 | +} from "@heroicons/react/24/outline"; | |
| 11 | +import { MCPServerStatus } from "core"; | |
| 12 | +import { useContext, useMemo, useState } from "react"; | |
| 13 | +import { ToolTip } from "../../../components/gui/Tooltip"; | |
| 14 | +import EditBlockButton from "../../../components/mainInput/Lump/EditBlockButton"; | |
| 15 | +import { Button, Card } from "../../../components/ui"; | |
| 16 | +import { useAuth } from "../../../context/Auth"; | |
| 17 | +import { IdeMessengerContext } from "../../../context/IdeMessenger"; | |
| 18 | +import { useAppDispatch, useAppSelector } from "../../../redux/hooks"; | |
| 19 | +import { updateConfig } from "../../../redux/slices/configSlice"; | |
| 20 | +import { selectCurrentOrg } from "../../../redux/slices/profilesSlice"; | |
| 21 | +import { ConfigHeader } from "../components/ConfigHeader"; | |
| 22 | + | |
| 23 | +interface MCPServerStatusProps { | |
| 24 | + server: MCPServerStatus; | |
| 25 | + serverFromYaml?: NonNullable<ConfigYaml["mcpServers"]>[number]; | |
| 26 | +} | |
| 27 | +function MCPServerCard({ server, serverFromYaml }: MCPServerStatusProps) { | |
| 28 | + const [isExpanded, setIsExpanded] = useState(false); | |
| 29 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 30 | + const config = useAppSelector((store) => store.config.config); | |
| 31 | + const dispatch = useAppDispatch(); | |
| 32 | + | |
| 33 | + const updateMCPServerStatus = (status: MCPServerStatus["status"]) => { | |
| 34 | + // optimistic config update | |
| 35 | + dispatch( | |
| 36 | + updateConfig({ | |
| 37 | + ...config, | |
| 38 | + mcpServerStatuses: config.mcpServerStatuses.map((s) => | |
| 39 | + s.id === server.id | |
| 40 | + ? { | |
| 41 | + ...s, | |
| 42 | + status, | |
| 43 | + } | |
| 44 | + : s, | |
| 45 | + ), | |
| 46 | + }), | |
| 47 | + ); | |
| 48 | + }; | |
| 49 | + | |
| 50 | + const onAuthenticate = async () => { | |
| 51 | + updateMCPServerStatus("authenticating"); | |
| 52 | + await ideMessenger.request("mcp/startAuthentication", server); | |
| 53 | + }; | |
| 54 | + | |
| 55 | + const onRemoveAuth = async () => { | |
| 56 | + updateMCPServerStatus("authenticating"); | |
| 57 | + await ideMessenger.request("mcp/removeAuthentication", server); | |
| 58 | + }; | |
| 59 | + | |
| 60 | + const onRefresh = async () => { | |
| 61 | + updateMCPServerStatus("connecting"); | |
| 62 | + ideMessenger.post("mcp/reloadServer", { | |
| 63 | + id: server.id, | |
| 64 | + }); | |
| 65 | + }; | |
| 66 | + | |
| 67 | + const handleToggleExpanded = (e: React.MouseEvent) => { | |
| 68 | + // Don't expand if clicking on buttons | |
| 69 | + if ((e.target as HTMLElement).closest("button")) { | |
| 70 | + return; | |
| 71 | + } | |
| 72 | + setIsExpanded(!isExpanded); | |
| 73 | + }; | |
| 74 | + | |
| 75 | + return ( | |
| 76 | + <div> | |
| 77 | + <div | |
| 78 | + className="hover:bg-input/50 -mx-2 flex cursor-pointer items-center justify-between rounded px-2 py-1" | |
| 79 | + onClick={handleToggleExpanded} | |
| 80 | + > | |
| 81 | + <div className="flex items-center gap-3"> | |
| 82 | + <ChevronDownIcon | |
| 83 | + className={`text-description h-4 w-4 transition-transform ${isExpanded ? "rotate-180" : ""}`} | |
| 84 | + /> | |
| 85 | + <div className="flex-1"> | |
| 86 | + <h3 | |
| 87 | + className={`text-sm font-medium ${server.errors && server.errors.length > 0 ? "text-error" : ""}`} | |
| 88 | + > | |
| 89 | + {server.name} | |
| 90 | + </h3> | |
| 91 | + </div> | |
| 92 | + </div> | |
| 93 | + | |
| 94 | + <div className="flex items-center gap-2"> | |
| 95 | + {server.isProtectedResource && ( | |
| 96 | + <ToolTip | |
| 97 | + content={ | |
| 98 | + server.status === "error" | |
| 99 | + ? "Authenticate" | |
| 100 | + : server.status === "authenticating" | |
| 101 | + ? "Authenticating..." | |
| 102 | + : "Remove authentication" | |
| 103 | + } | |
| 104 | + > | |
| 105 | + <Button | |
| 106 | + onClick={ | |
| 107 | + server.status === "error" | |
| 108 | + ? onAuthenticate | |
| 109 | + : server.status === "authenticating" | |
| 110 | + ? undefined | |
| 111 | + : onRemoveAuth | |
| 112 | + } | |
| 113 | + variant="ghost" | |
| 114 | + size="sm" | |
| 115 | + className="text-description-muted hover:enabled:text-foreground my-0 h-6 w-6 p-0" | |
| 116 | + disabled={server.status === "authenticating"} | |
| 117 | + > | |
| 118 | + {server.status === "authenticating" ? ( | |
| 119 | + <GlobeAltIcon className="animate-spin-slow h-4 w-4 flex-shrink-0" /> | |
| 120 | + ) : ( | |
| 121 | + <UserCircleIcon className="h-4 w-4 flex-shrink-0" /> | |
| 122 | + )} | |
| 123 | + </Button> | |
| 124 | + </ToolTip> | |
| 125 | + )} | |
| 126 | + | |
| 127 | + <EditBlockButton | |
| 128 | + blockType={"mcpServers"} | |
| 129 | + block={serverFromYaml} | |
| 130 | + sourceFile={server.sourceFile} | |
| 131 | + /> | |
| 132 | + | |
| 133 | + <ToolTip content="Refresh server"> | |
| 134 | + <Button | |
| 135 | + onClick={onRefresh} | |
| 136 | + variant="ghost" | |
| 137 | + size="sm" | |
| 138 | + className="text-description-muted hover:enabled:text-foreground my-0 h-6 w-6 p-0" | |
| 139 | + > | |
| 140 | + <ArrowPathIcon className="h-4 w-4 flex-shrink-0" /> | |
| 141 | + </Button> | |
| 142 | + </ToolTip> | |
| 143 | + | |
| 144 | + <div | |
| 145 | + className="h-2 w-2 flex-shrink-0 rounded-full" | |
| 146 | + style={{ | |
| 147 | + backgroundColor: | |
| 148 | + server.status === "connected" | |
| 149 | + ? "#22c55e" // green-500 | |
| 150 | + : server.status === "connecting" | |
| 151 | + ? "#eab308" // yellow-500 | |
| 152 | + : server.status === "not-connected" | |
| 153 | + ? "#78716c" // stone-500 | |
| 154 | + : "#ef4444", // red-500 for error | |
| 155 | + }} | |
| 156 | + /> | |
| 157 | + </div> | |
| 158 | + </div> | |
| 159 | + | |
| 160 | + {isExpanded && server.status === "connected" && ( | |
| 161 | + <div className="mt-3 pl-7"> | |
| 162 | + {/* Tools, Prompts, Resources with counts */} | |
| 163 | + <div className="mb-3 flex flex-row items-center gap-6"> | |
| 164 | + <ToolTip | |
| 165 | + className="flex flex-col gap-0.5" | |
| 166 | + content={ | |
| 167 | + <> | |
| 168 | + {server.tools.map((tool, idx) => ( | |
| 169 | + <div key={idx} className="flex flex-col gap-1"> | |
| 170 | + <div className="flex flex-col"> | |
| 171 | + <code className="font-semibold">{tool.name}</code> | |
| 172 | + {tool.description && ( | |
| 173 | + <span className="mt-0.5 text-xs text-gray-400"> | |
| 174 | + {tool.description} | |
| 175 | + </span> | |
| 176 | + )} | |
| 177 | + {tool.inputSchema?.properties && | |
| 178 | + Object.keys(tool.inputSchema.properties).length > | |
| 179 | + 0 && ( | |
| 180 | + <div className="mt-1"> | |
| 181 | + <span className="text-xs text-gray-500"> | |
| 182 | + Args: | |
| 183 | + </span> | |
| 184 | + <div className="ml-2"> | |
| 185 | + {Object.entries( | |
| 186 | + tool.inputSchema.properties, | |
| 187 | + ).map(([paramName, paramSchema], paramIdx) => ( | |
| 188 | + <div key={paramIdx} className="text-xs"> | |
| 189 | + <code className="text-blue-400"> | |
| 190 | + {paramName} | |
| 191 | + </code> | |
| 192 | + {paramSchema && | |
| 193 | + typeof paramSchema === "object" && | |
| 194 | + "type" in paramSchema && ( | |
| 195 | + <span className="ml-1 text-gray-500"> | |
| 196 | + ({paramSchema.type}) | |
| 197 | + </span> | |
| 198 | + )} | |
| 199 | + </div> | |
| 200 | + ))} | |
| 201 | + </div> | |
| 202 | + </div> | |
| 203 | + )} | |
| 204 | + </div> | |
| 205 | + {idx < server.tools.length - 1 && ( | |
| 206 | + <div className="my-1 border-b border-gray-600"></div> | |
| 207 | + )} | |
| 208 | + </div> | |
| 209 | + ))} | |
| 210 | + {server.tools.length === 0 && ( | |
| 211 | + <span className="text-lightgray">No tools</span> | |
| 212 | + )} | |
| 213 | + </> | |
| 214 | + } | |
| 215 | + > | |
| 216 | + <div className="flex cursor-zoom-in items-center gap-2 hover:opacity-80"> | |
| 217 | + <WrenchScrewdriverIcon className="h-4 w-4 flex-shrink-0" /> | |
| 218 | + <span className="text-sm">Tools: {server.tools.length}</span> | |
| 219 | + </div> | |
| 220 | + </ToolTip> | |
| 221 | + | |
| 222 | + <ToolTip | |
| 223 | + className="flex flex-col gap-0.5" | |
| 224 | + content={ | |
| 225 | + <> | |
| 226 | + {server.prompts.map((prompt, idx) => ( | |
| 227 | + <code key={idx}>{prompt.name}</code> | |
| 228 | + ))} | |
| 229 | + {server.prompts.length === 0 && ( | |
| 230 | + <span className="text-lightgray">No prompts</span> | |
| 231 | + )} | |
| 232 | + </> | |
| 233 | + } | |
| 234 | + > | |
| 235 | + <div className="flex cursor-zoom-in items-center gap-2 hover:opacity-80"> | |
| 236 | + <CommandLineIcon className="h-4 w-4 flex-shrink-0" /> | |
| 237 | + <span className="text-sm"> | |
| 238 | + Prompts: {server.prompts.length} | |
| 239 | + </span> | |
| 240 | + </div> | |
| 241 | + </ToolTip> | |
| 242 | + | |
| 243 | + <ToolTip | |
| 244 | + className="flex flex-col gap-0.5" | |
| 245 | + content={ | |
| 246 | + <> | |
| 247 | + {[...server.resources, ...server.resourceTemplates].map( | |
| 248 | + (resource, idx) => ( | |
| 249 | + <code key={idx}>{resource.name}</code> | |
| 250 | + ), | |
| 251 | + )} | |
| 252 | + {server.resources.length === 0 && ( | |
| 253 | + <span className="text-lightgray">No resources</span> | |
| 254 | + )} | |
| 255 | + </> | |
| 256 | + } | |
| 257 | + > | |
| 258 | + <div className="flex cursor-zoom-in items-center gap-2 hover:opacity-80"> | |
| 259 | + <CircleStackIcon className="h-4 w-4 flex-shrink-0" /> | |
| 260 | + <span className="text-sm"> | |
| 261 | + Resources:{" "} | |
| 262 | + {server.resources.length + server.resourceTemplates.length} | |
| 263 | + </span> | |
| 264 | + </div> | |
| 265 | + </ToolTip> | |
| 266 | + </div> | |
| 267 | + </div> | |
| 268 | + )} | |
| 269 | + | |
| 270 | + {/* Error display below expandable section */} | |
| 271 | + {server.errors && server.errors.length > 0 && ( | |
| 272 | + <div className="mt-2 space-y-1"> | |
| 273 | + {server.errors.map((error, errorIndex) => ( | |
| 274 | + <div | |
| 275 | + key={errorIndex} | |
| 276 | + className="text-error bg-error/10 rounded px-2 py-1 text-xs" | |
| 277 | + > | |
| 278 | + <div className="flex items-start justify-between gap-2"> | |
| 279 | + <span className="flex-1"> | |
| 280 | + {error.length > 150 ? error.substring(0, 150) + "..." : error} | |
| 281 | + </span> | |
| 282 | + {error.length > 150 && ( | |
| 283 | + <Button | |
| 284 | + className="my-0 flex-shrink-0" | |
| 285 | + size="sm" | |
| 286 | + variant="ghost" | |
| 287 | + onClick={() => | |
| 288 | + void ideMessenger.ide.showVirtualFile(server.name, error) | |
| 289 | + } | |
| 290 | + > | |
| 291 | + View full error | |
| 292 | + </Button> | |
| 293 | + )} | |
| 294 | + </div> | |
| 295 | + </div> | |
| 296 | + ))} | |
| 297 | + </div> | |
| 298 | + )} | |
| 299 | + </div> | |
| 300 | + ); | |
| 301 | +} | |
| 302 | + | |
| 303 | +function McpSection() { | |
| 304 | + const currentOrg = useAppSelector(selectCurrentOrg); | |
| 305 | + const servers = useAppSelector( | |
| 306 | + (store) => store.config.config.mcpServerStatuses, | |
| 307 | + ); | |
| 308 | + const { selectedProfile } = useAuth(); | |
| 309 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 310 | + const disableMcp = currentOrg?.policy?.allowMcpServers === false; | |
| 311 | + const isLocal = selectedProfile?.profileType === "local"; | |
| 312 | + | |
| 313 | + const mergedBlocks = useMemo(() => { | |
| 314 | + const parsed = selectedProfile?.rawYaml | |
| 315 | + ? parseConfigYaml(selectedProfile?.rawYaml ?? "") | |
| 316 | + : undefined; | |
| 317 | + return (servers ?? []).map((doc, index) => ({ | |
| 318 | + block: doc, | |
| 319 | + blockFromYaml: parsed?.mcpServers?.[index], | |
| 320 | + })); | |
| 321 | + }, [servers, selectedProfile]); | |
| 322 | + | |
| 323 | + const handleAddMcpServer = () => { | |
| 324 | + if (isLocal) { | |
| 325 | + void ideMessenger.request("config/addLocalWorkspaceBlock", { | |
| 326 | + blockType: "mcpServers", | |
| 327 | + }); | |
| 328 | + } else { | |
| 329 | + void ideMessenger.request("controlPlane/openUrl", { | |
| 330 | + path: "new?type=block&blockType=mcpServers", | |
| 331 | + orgSlug: undefined, | |
| 332 | + }); | |
| 333 | + } | |
| 334 | + }; | |
| 335 | + | |
| 336 | + if (disableMcp) { | |
| 337 | + return ( | |
| 338 | + <div className="flex flex-col items-center justify-center p-2"> | |
| 339 | + <span className="text-description"> | |
| 340 | + MCP servers are disabled in your organization | |
| 341 | + </span> | |
| 342 | + </div> | |
| 343 | + ); | |
| 344 | + } | |
| 345 | + | |
| 346 | + return ( | |
| 347 | + <div> | |
| 348 | + <ConfigHeader | |
| 349 | + title="MCP Servers" | |
| 350 | + onAddClick={handleAddMcpServer} | |
| 351 | + addButtonTooltip="Add MCP server" | |
| 352 | + /> | |
| 353 | + | |
| 354 | + <div className="mt-6"> | |
| 355 | + {mergedBlocks && mergedBlocks.length > 0 ? ( | |
| 356 | + mergedBlocks.map(({ block, blockFromYaml }, index) => ( | |
| 357 | + <div key={block.id}> | |
| 358 | + <Card> | |
| 359 | + <MCPServerCard server={block} serverFromYaml={blockFromYaml} /> | |
| 360 | + </Card> | |
| 361 | + {index < mergedBlocks.length - 1 && <div className="mb-4" />} | |
| 362 | + </div> | |
| 363 | + )) | |
| 364 | + ) : ( | |
| 365 | + <Card> | |
| 366 | + <div className="flex flex-col items-center justify-center p-8 text-center"> | |
| 367 | + <span className="text-description"> | |
| 368 | + No MCP servers configured. Click the + button to add your first | |
| 369 | + server. | |
| 370 | + </span> | |
| 371 | + </div> | |
| 372 | + </Card> | |
| 373 | + )} | |
| 374 | + </div> | |
| 375 | + </div> | |
| 376 | + ); | |
| 377 | +} | |
| 378 | + | |
| 379 | +export { McpSection }; |
added gui/src/pages/config/sections/ModelsSection.tsx +222 −0
| @@ -0,0 +1,222 @@ | ||
| 1 | +import { ModelRole } from "@continuedev/config-yaml"; | |
| 2 | +import { ModelDescription } from "core"; | |
| 3 | +import { useContext, useState } from "react"; | |
| 4 | +import Shortcut from "../../../components/gui/Shortcut"; | |
| 5 | +import { Card, Divider, Toggle } from "../../../components/ui"; | |
| 6 | +import { useAuth } from "../../../context/Auth"; | |
| 7 | +import { IdeMessengerContext } from "../../../context/IdeMessenger"; | |
| 8 | +import { AddModelForm } from "../../../forms/AddModelForm"; | |
| 9 | +import { useAppDispatch, useAppSelector } from "../../../redux/hooks"; | |
| 10 | +import { setDialogMessage, setShowDialog } from "../../../redux/slices/uiSlice"; | |
| 11 | +import { updateSelectedModelByRole } from "../../../redux/thunks/updateSelectedModelByRole"; | |
| 12 | +import { getMetaKeyLabel, isJetBrains } from "../../../util"; | |
| 13 | +import { ConfigHeader } from "../components/ConfigHeader"; | |
| 14 | +import { ModelRoleRow } from "../components/ModelRoleRow"; | |
| 15 | + | |
| 16 | +export function ModelsSection() { | |
| 17 | + const { selectedProfile } = useAuth(); | |
| 18 | + const dispatch = useAppDispatch(); | |
| 19 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 20 | + | |
| 21 | + const config = useAppSelector((state) => state.config.config); | |
| 22 | + const jetbrains = isJetBrains(); | |
| 23 | + const metaKey = getMetaKeyLabel(); | |
| 24 | + const [showAdditionalRoles, setShowAdditionalRoles] = useState(false); | |
| 25 | + | |
| 26 | + function handleRoleUpdate(role: ModelRole, model: ModelDescription | null) { | |
| 27 | + if (!model) { | |
| 28 | + return; | |
| 29 | + } | |
| 30 | + | |
| 31 | + void dispatch( | |
| 32 | + updateSelectedModelByRole({ | |
| 33 | + role, | |
| 34 | + selectedProfile, | |
| 35 | + modelTitle: model.title, | |
| 36 | + }), | |
| 37 | + ); | |
| 38 | + } | |
| 39 | + | |
| 40 | + function handleConfigureModel(model: ModelDescription | null) { | |
| 41 | + if (!model) { | |
| 42 | + return; | |
| 43 | + } | |
| 44 | + | |
| 45 | + ideMessenger.post("config/openProfile", { | |
| 46 | + profileId: undefined, | |
| 47 | + element: model, | |
| 48 | + }); | |
| 49 | + } | |
| 50 | + | |
| 51 | + function handleAddModel() { | |
| 52 | + const isLocal = selectedProfile?.profileType === "local"; | |
| 53 | + | |
| 54 | + if (isLocal) { | |
| 55 | + dispatch(setShowDialog(true)); | |
| 56 | + dispatch( | |
| 57 | + setDialogMessage( | |
| 58 | + <AddModelForm | |
| 59 | + onDone={() => { | |
| 60 | + dispatch(setShowDialog(false)); | |
| 61 | + }} | |
| 62 | + />, | |
| 63 | + ), | |
| 64 | + ); | |
| 65 | + } else { | |
| 66 | + void ideMessenger.request("controlPlane/openUrl", { | |
| 67 | + path: "?type=models", | |
| 68 | + orgSlug: undefined, | |
| 69 | + }); | |
| 70 | + } | |
| 71 | + } | |
| 72 | + | |
| 73 | + return ( | |
| 74 | + <div className="space-y-4"> | |
| 75 | + <ConfigHeader | |
| 76 | + title="Models" | |
| 77 | + onAddClick={handleAddModel} | |
| 78 | + addButtonTooltip="Add model" | |
| 79 | + /> | |
| 80 | + | |
| 81 | + <Card> | |
| 82 | + <ModelRoleRow | |
| 83 | + role="chat" | |
| 84 | + displayName="Chat" | |
| 85 | + shortcut={ | |
| 86 | + <span className="text-2xs text-description-muted"> | |
| 87 | + (<Shortcut>{`cmd ${jetbrains ? "J" : "L"}`}</Shortcut>) | |
| 88 | + </span> | |
| 89 | + } | |
| 90 | + description={ | |
| 91 | + <span> | |
| 92 | + Used in Chat, Plan, Agent mode ( | |
| 93 | + <a | |
| 94 | + href="https://docs.continue.dev/features/chat/quick-start hover:text-inherit" | |
| 95 | + target="_blank" | |
| 96 | + rel="noopener noreferrer" | |
| 97 | + className="text-inherit underline hover:brightness-125" | |
| 98 | + > | |
| 99 | + Learn more | |
| 100 | + </a> | |
| 101 | + ) | |
| 102 | + </span> | |
| 103 | + } | |
| 104 | + models={config.modelsByRole.chat} | |
| 105 | + selectedModel={config.selectedModelByRole.chat ?? undefined} | |
| 106 | + onSelect={(model) => handleRoleUpdate("chat", model)} | |
| 107 | + onConfigure={handleConfigureModel} | |
| 108 | + setupURL="https://docs.continue.dev/chat/model-setup" | |
| 109 | + /> | |
| 110 | + | |
| 111 | + <Divider /> | |
| 112 | + | |
| 113 | + <ModelRoleRow | |
| 114 | + role="autocomplete" | |
| 115 | + displayName="Autocomplete" | |
| 116 | + description={ | |
| 117 | + <span> | |
| 118 | + Used in inline code completions as you type ( | |
| 119 | + <a | |
| 120 | + href="https://docs.continue.dev/features/autocomplete/quick-start" | |
| 121 | + target="_blank" | |
| 122 | + rel="noopener noreferrer" | |
| 123 | + className="text-inherit underline hover:brightness-125" | |
| 124 | + > | |
| 125 | + Learn more | |
| 126 | + </a> | |
| 127 | + ) | |
| 128 | + </span> | |
| 129 | + } | |
| 130 | + models={config.modelsByRole.autocomplete} | |
| 131 | + selectedModel={config.selectedModelByRole.autocomplete ?? undefined} | |
| 132 | + onSelect={(model) => handleRoleUpdate("autocomplete", model)} | |
| 133 | + onConfigure={handleConfigureModel} | |
| 134 | + setupURL="https://docs.continue.dev/autocomplete/model-setup" | |
| 135 | + /> | |
| 136 | + | |
| 137 | + {/* Jetbrains has a model selector inline */} | |
| 138 | + {!jetbrains && ( | |
| 139 | + <> | |
| 140 | + <Divider /> | |
| 141 | + <ModelRoleRow | |
| 142 | + role="edit" | |
| 143 | + displayName="Edit" | |
| 144 | + shortcut={ | |
| 145 | + <span className="text-2xs text-description-muted"> | |
| 146 | + (<Shortcut>cmd I</Shortcut>) | |
| 147 | + </span> | |
| 148 | + } | |
| 149 | + description={ | |
| 150 | + <span> | |
| 151 | + Used to transform a selected section of code ( | |
| 152 | + <a | |
| 153 | + href="https://docs.continue.dev/features/edit/quick-start" | |
| 154 | + target="_blank" | |
| 155 | + rel="noopener noreferrer" | |
| 156 | + className="text-inherit underline hover:brightness-125" | |
| 157 | + > | |
| 158 | + Learn more | |
| 159 | + </a> | |
| 160 | + ) | |
| 161 | + </span> | |
| 162 | + } | |
| 163 | + models={config.modelsByRole.edit} | |
| 164 | + selectedModel={config.selectedModelByRole.edit ?? undefined} | |
| 165 | + onSelect={(model) => handleRoleUpdate("edit", model)} | |
| 166 | + onConfigure={handleConfigureModel} | |
| 167 | + setupURL="https://docs.continue.dev/edit/model-setup" | |
| 168 | + /> | |
| 169 | + </> | |
| 170 | + )} | |
| 171 | + </Card> | |
| 172 | + | |
| 173 | + <Card> | |
| 174 | + <Toggle | |
| 175 | + isOpen={showAdditionalRoles} | |
| 176 | + onToggle={() => setShowAdditionalRoles(!showAdditionalRoles)} | |
| 177 | + title="Additional model roles" | |
| 178 | + subtitle="Apply, Embed, Rerank" | |
| 179 | + > | |
| 180 | + <div className="flex flex-col"> | |
| 181 | + <ModelRoleRow | |
| 182 | + role="apply" | |
| 183 | + displayName="Apply" | |
| 184 | + description="Used to apply generated codeblocks to files" | |
| 185 | + models={config.modelsByRole.apply} | |
| 186 | + selectedModel={config.selectedModelByRole.apply ?? undefined} | |
| 187 | + onSelect={(model) => handleRoleUpdate("apply", model)} | |
| 188 | + onConfigure={handleConfigureModel} | |
| 189 | + setupURL="https://docs.continue.dev/customize/model-roles/apply" | |
| 190 | + /> | |
| 191 | + | |
| 192 | + <Divider /> | |
| 193 | + | |
| 194 | + <ModelRoleRow | |
| 195 | + role="embed" | |
| 196 | + displayName="Embed" | |
| 197 | + description="Used to generate and query embeddings for the @codebase and @docs context providers" | |
| 198 | + models={config.modelsByRole.embed} | |
| 199 | + selectedModel={config.selectedModelByRole.embed ?? undefined} | |
| 200 | + onSelect={(model) => handleRoleUpdate("embed", model)} | |
| 201 | + onConfigure={handleConfigureModel} | |
| 202 | + setupURL="https://docs.continue.dev/customize/model-roles/embeddings" | |
| 203 | + /> | |
| 204 | + | |
| 205 | + <Divider /> | |
| 206 | + | |
| 207 | + <ModelRoleRow | |
| 208 | + role="rerank" | |
| 209 | + displayName="Rerank" | |
| 210 | + description="Used for reranking results from the @codebase and @docs context providers" | |
| 211 | + models={config.modelsByRole.rerank} | |
| 212 | + selectedModel={config.selectedModelByRole.rerank ?? undefined} | |
| 213 | + onSelect={(model) => handleRoleUpdate("rerank", model)} | |
| 214 | + onConfigure={handleConfigureModel} | |
| 215 | + setupURL="https://docs.continue.dev/customize/model-roles/reranking" | |
| 216 | + /> | |
| 217 | + </div> | |
| 218 | + </Toggle> | |
| 219 | + </Card> | |
| 220 | + </div> | |
| 221 | + ); | |
| 222 | +} |
added gui/src/pages/config/sections/OrganizationsSection.tsx +99 −0
| @@ -0,0 +1,99 @@ | ||
| 1 | +import { Cog6ToothIcon } from "@heroicons/react/24/outline"; | |
| 2 | +import { BuildingOfficeIcon, UserIcon } from "@heroicons/react/24/solid"; | |
| 3 | +import { isOnPremSession } from "core/control-plane/AuthTypes"; | |
| 4 | +import { useContext } from "react"; | |
| 5 | +import { Button, Card, Divider } from "../../../components/ui"; | |
| 6 | +import { useAuth } from "../../../context/Auth"; | |
| 7 | +import { IdeMessengerContext } from "../../../context/IdeMessenger"; | |
| 8 | +import { ConfigHeader } from "../components/ConfigHeader"; | |
| 9 | + | |
| 10 | +function getOrgIcon(org: { name: string; iconUrl?: string | null }) { | |
| 11 | + if (org.iconUrl) { | |
| 12 | + return ( | |
| 13 | + <img | |
| 14 | + src={org.iconUrl} | |
| 15 | + alt="" | |
| 16 | + className="h-5 w-5 flex-shrink-0 rounded-full" | |
| 17 | + /> | |
| 18 | + ); | |
| 19 | + } | |
| 20 | + | |
| 21 | + const IconComponent = org.name === "Personal" ? UserIcon : BuildingOfficeIcon; | |
| 22 | + return <IconComponent className="h-5 w-5 flex-shrink-0" />; | |
| 23 | +} | |
| 24 | + | |
| 25 | +export function OrganizationsSection() { | |
| 26 | + const { organizations, session } = useAuth(); | |
| 27 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 28 | + | |
| 29 | + const shouldRenderOrgInfo = | |
| 30 | + session && organizations.length > 1 && !isOnPremSession(session); | |
| 31 | + | |
| 32 | + function handleAddOrganization() { | |
| 33 | + ideMessenger.request("controlPlane/openUrl", { | |
| 34 | + path: "/organizations/new", | |
| 35 | + }); | |
| 36 | + } | |
| 37 | + | |
| 38 | + function handleConfigureOrganization(orgId: string) { | |
| 39 | + ideMessenger.request("controlPlane/openUrl", { | |
| 40 | + path: `/organizations/${orgId}/settings`, | |
| 41 | + }); | |
| 42 | + } | |
| 43 | + | |
| 44 | + if (!shouldRenderOrgInfo) { | |
| 45 | + return ( | |
| 46 | + <> | |
| 47 | + <div className="mb-8 flex items-center justify-between"> | |
| 48 | + <div className="flex flex-col"> | |
| 49 | + <h2 className="mb-0 text-xl font-semibold">Organizations</h2> | |
| 50 | + </div> | |
| 51 | + </div> | |
| 52 | + <Card> | |
| 53 | + <div className="text-description py-8 text-center text-sm"> | |
| 54 | + Organizations are only available with cloud accounts. Sign in to | |
| 55 | + manage organizations. | |
| 56 | + </div> | |
| 57 | + </Card> | |
| 58 | + </> | |
| 59 | + ); | |
| 60 | + } | |
| 61 | + | |
| 62 | + return ( | |
| 63 | + <> | |
| 64 | + <ConfigHeader | |
| 65 | + title="Organizations" | |
| 66 | + onAddClick={handleAddOrganization} | |
| 67 | + addButtonTooltip="Add organization" | |
| 68 | + /> | |
| 69 | + | |
| 70 | + <Card> | |
| 71 | + {organizations.map((organization, index) => ( | |
| 72 | + <div key={organization.id}> | |
| 73 | + <div className="flex items-center justify-between"> | |
| 74 | + <div className="flex items-center gap-3"> | |
| 75 | + <div className="flex h-5 w-5 flex-shrink-0 items-center justify-center"> | |
| 76 | + {getOrgIcon(organization)} | |
| 77 | + </div> | |
| 78 | + <div className="flex-1"> | |
| 79 | + <h3 className="my-2 text-sm font-medium"> | |
| 80 | + {organization.name} | |
| 81 | + </h3> | |
| 82 | + </div> | |
| 83 | + </div> | |
| 84 | + <Button | |
| 85 | + onClick={() => handleConfigureOrganization(organization.id)} | |
| 86 | + variant="ghost" | |
| 87 | + size="sm" | |
| 88 | + className="text-description-muted hover:enabled:text-foreground my-0 h-6 w-6 p-0" | |
| 89 | + > | |
| 90 | + <Cog6ToothIcon className="h-4 w-4 flex-shrink-0" /> | |
| 91 | + </Button> | |
| 92 | + </div> | |
| 93 | + {index < organizations.length - 1 && <Divider />} | |
| 94 | + </div> | |
| 95 | + ))} | |
| 96 | + </Card> | |
| 97 | + </> | |
| 98 | + ); | |
| 99 | +} |
added gui/src/pages/config/sections/PromptsSection.tsx +207 −0
| @@ -0,0 +1,207 @@ | ||
| 1 | +import { parseConfigYaml } from "@continuedev/config-yaml"; | |
| 2 | +import { | |
| 3 | + BookmarkIcon as BookmarkOutline, | |
| 4 | + PencilIcon, | |
| 5 | + PlusIcon, | |
| 6 | +} from "@heroicons/react/24/outline"; | |
| 7 | +import { BookmarkIcon as BookmarkSolid } from "@heroicons/react/24/solid"; | |
| 8 | +import { SlashCommandDescWithSource } from "core"; | |
| 9 | +import { useContext, useMemo } from "react"; | |
| 10 | +import { useMainEditor } from "../../../components/mainInput/TipTapEditor"; | |
| 11 | +import { ToolTip } from "../../../components/gui/Tooltip"; | |
| 12 | +import { Button, Card, EmptyState } from "../../../components/ui"; | |
| 13 | +import { useAuth } from "../../../context/Auth"; | |
| 14 | +import { IdeMessengerContext } from "../../../context/IdeMessenger"; | |
| 15 | +import { useBookmarkedSlashCommands } from "../../../hooks/useBookmarkedSlashCommands"; | |
| 16 | +import { useAppSelector } from "../../../redux/hooks"; | |
| 17 | +import { fontSize } from "../../../util"; | |
| 18 | +import { ConfigHeader } from "../components/ConfigHeader"; | |
| 19 | + | |
| 20 | +interface PromptCommandWithSlug extends SlashCommandDescWithSource { | |
| 21 | + slug?: string; | |
| 22 | +} | |
| 23 | + | |
| 24 | +interface PromptRowProps { | |
| 25 | + prompt: PromptCommandWithSlug; | |
| 26 | + isBookmarked: boolean; | |
| 27 | + setIsBookmarked: (isBookmarked: boolean) => void; | |
| 28 | + onEdit?: () => void; | |
| 29 | +} | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * Displays a single prompt row with bookmark and edit controls | |
| 33 | + */ | |
| 34 | +function PromptRow({ | |
| 35 | + prompt, | |
| 36 | + isBookmarked, | |
| 37 | + setIsBookmarked, | |
| 38 | + onEdit, | |
| 39 | +}: PromptRowProps) { | |
| 40 | + const { mainEditor } = useMainEditor(); | |
| 41 | + | |
| 42 | + const handlePromptClick = (e: React.MouseEvent) => { | |
| 43 | + e.stopPropagation(); | |
| 44 | + mainEditor?.commands.insertPrompt({ | |
| 45 | + title: prompt.name, | |
| 46 | + description: prompt.description, | |
| 47 | + content: prompt.prompt, | |
| 48 | + }); | |
| 49 | + }; | |
| 50 | + | |
| 51 | + const handleBookmarkClick = (e: React.MouseEvent) => { | |
| 52 | + e.stopPropagation(); | |
| 53 | + setIsBookmarked(!isBookmarked); | |
| 54 | + }; | |
| 55 | + | |
| 56 | + const handleEditClick = (e: React.MouseEvent) => { | |
| 57 | + e.stopPropagation(); | |
| 58 | + if (onEdit) { | |
| 59 | + onEdit(); | |
| 60 | + } | |
| 61 | + }; | |
| 62 | + | |
| 63 | + const canEdit = | |
| 64 | + prompt.promptFile && !prompt.promptFile.startsWith("builtin:"); | |
| 65 | + | |
| 66 | + return ( | |
| 67 | + <div | |
| 68 | + className="hover:bg-list-active hover:text-list-active-foreground flex items-center justify-between gap-3 rounded-md px-2 py-1 hover:cursor-pointer" | |
| 69 | + onClick={handlePromptClick} | |
| 70 | + style={{ | |
| 71 | + fontSize: fontSize(-3), | |
| 72 | + }} | |
| 73 | + > | |
| 74 | + <div className="flex min-w-0 flex-col"> | |
| 75 | + <span className="text-vscForeground shrink-0 font-medium"> | |
| 76 | + {prompt.name} | |
| 77 | + </span> | |
| 78 | + <span className="line-clamp-2 text-[11px] text-gray-400"> | |
| 79 | + {prompt.description} | |
| 80 | + </span> | |
| 81 | + </div> | |
| 82 | + <div className="flex items-center gap-2"> | |
| 83 | + <PencilIcon | |
| 84 | + className={`h-3 w-3 cursor-pointer text-gray-400 hover:brightness-125 ${!canEdit ? "pointer-events-none cursor-not-allowed opacity-50" : ""}`} | |
| 85 | + onClick={canEdit ? handleEditClick : undefined} | |
| 86 | + aria-disabled={!canEdit} | |
| 87 | + /> | |
| 88 | + <div | |
| 89 | + onClick={handleBookmarkClick} | |
| 90 | + className="cursor-pointer pt-0.5 text-gray-400 hover:brightness-125" | |
| 91 | + > | |
| 92 | + {isBookmarked ? ( | |
| 93 | + <BookmarkSolid className="h-3 w-3" /> | |
| 94 | + ) : ( | |
| 95 | + <BookmarkOutline className="h-3 w-3" /> | |
| 96 | + )} | |
| 97 | + </div> | |
| 98 | + </div> | |
| 99 | + </div> | |
| 100 | + ); | |
| 101 | +} | |
| 102 | + | |
| 103 | +/** | |
| 104 | + * Section that displays all available prompts with bookmarking functionality | |
| 105 | + */ | |
| 106 | +export function PromptsSection() { | |
| 107 | + const { selectedProfile } = useAuth(); | |
| 108 | + const { isCommandBookmarked, toggleBookmark } = useBookmarkedSlashCommands(); | |
| 109 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 110 | + const isLocal = selectedProfile?.profileType === "local"; | |
| 111 | + | |
| 112 | + const slashCommands = useAppSelector( | |
| 113 | + (state) => state.config.config.slashCommands ?? [], | |
| 114 | + ); | |
| 115 | + | |
| 116 | + const handleEdit = (prompt: PromptCommandWithSlug) => { | |
| 117 | + if (prompt.promptFile) { | |
| 118 | + ideMessenger.post("openFile", { | |
| 119 | + path: prompt.promptFile, | |
| 120 | + }); | |
| 121 | + } else if (prompt.slug) { | |
| 122 | + void ideMessenger.request("controlPlane/openUrl", { | |
| 123 | + path: `${prompt.slug}/new-version`, | |
| 124 | + orgSlug: undefined, | |
| 125 | + }); | |
| 126 | + } else { | |
| 127 | + ideMessenger.post("config/openProfile", { | |
| 128 | + profileId: undefined, | |
| 129 | + element: { sourceFile: (prompt as any).sourceFile }, | |
| 130 | + }); | |
| 131 | + } | |
| 132 | + }; | |
| 133 | + | |
| 134 | + const handleAddPrompt = () => { | |
| 135 | + if (isLocal) { | |
| 136 | + void ideMessenger.request("config/addLocalWorkspaceBlock", { | |
| 137 | + blockType: "prompts", | |
| 138 | + }); | |
| 139 | + } else { | |
| 140 | + void ideMessenger.request("controlPlane/openUrl", { | |
| 141 | + path: "new?type=block&blockType=prompts", | |
| 142 | + orgSlug: undefined, | |
| 143 | + }); | |
| 144 | + } | |
| 145 | + }; | |
| 146 | + | |
| 147 | + const sortedCommands = useMemo(() => { | |
| 148 | + const promptsWithSlug: PromptCommandWithSlug[] = | |
| 149 | + structuredClone(slashCommands); | |
| 150 | + // get the slugs from rawYaml | |
| 151 | + if (selectedProfile?.rawYaml) { | |
| 152 | + const parsed = parseConfigYaml(selectedProfile.rawYaml); | |
| 153 | + const parsedPrompts = parsed.prompts ?? []; | |
| 154 | + | |
| 155 | + let index = 0; | |
| 156 | + for (const commandWithSlug of promptsWithSlug) { | |
| 157 | + // skip for local prompt files | |
| 158 | + if (commandWithSlug.promptFile) continue; | |
| 159 | + | |
| 160 | + const yamlPrompt = parsedPrompts[index]; | |
| 161 | + if (yamlPrompt) { | |
| 162 | + if ("uses" in yamlPrompt) { | |
| 163 | + commandWithSlug.slug = yamlPrompt.uses; | |
| 164 | + } else { | |
| 165 | + commandWithSlug.slug = `${selectedProfile?.fullSlug.ownerSlug}/${selectedProfile?.fullSlug.packageSlug}`; | |
| 166 | + } | |
| 167 | + } | |
| 168 | + index = index + 1; | |
| 169 | + } | |
| 170 | + } | |
| 171 | + return promptsWithSlug.sort((a, b) => { | |
| 172 | + const aBookmarked = isCommandBookmarked(a.name); | |
| 173 | + const bBookmarked = isCommandBookmarked(b.name); | |
| 174 | + if (aBookmarked && !bBookmarked) return -1; | |
| 175 | + if (!aBookmarked && bBookmarked) return 1; | |
| 176 | + return 0; | |
| 177 | + }); | |
| 178 | + }, [slashCommands, isCommandBookmarked, selectedProfile]); | |
| 179 | + | |
| 180 | + return ( | |
| 181 | + <div className="flex flex-col"> | |
| 182 | + <ConfigHeader | |
| 183 | + title="Prompts" | |
| 184 | + onAddClick={handleAddPrompt} | |
| 185 | + addButtonTooltip="Add prompt" | |
| 186 | + /> | |
| 187 | + | |
| 188 | + {sortedCommands.length > 0 ? ( | |
| 189 | + <div> | |
| 190 | + {sortedCommands.map((prompt) => ( | |
| 191 | + <PromptRow | |
| 192 | + key={prompt.name} | |
| 193 | + prompt={prompt} | |
| 194 | + isBookmarked={isCommandBookmarked(prompt.name)} | |
| 195 | + setIsBookmarked={() => toggleBookmark(prompt)} | |
| 196 | + onEdit={() => handleEdit(prompt)} | |
| 197 | + /> | |
| 198 | + ))} | |
| 199 | + </div> | |
| 200 | + ) : ( | |
| 201 | + <Card> | |
| 202 | + <EmptyState message="No prompts configured. Click the + button to add your first prompt." /> | |
| 203 | + </Card> | |
| 204 | + )} | |
| 205 | + </div> | |
| 206 | + ); | |
| 207 | +} |
added gui/src/pages/config/sections/RulesSection.tsx +525 −0
| @@ -0,0 +1,525 @@ | ||
| 1 | +import { parseConfigYaml } from "@continuedev/config-yaml"; | |
| 2 | +import { | |
| 3 | + ArrowsPointingOutIcon, | |
| 4 | + BookmarkIcon as BookmarkOutline, | |
| 5 | + EyeIcon, | |
| 6 | + PencilIcon, | |
| 7 | + PlusIcon, | |
| 8 | +} from "@heroicons/react/24/outline"; | |
| 9 | +import { BookmarkIcon as BookmarkSolid } from "@heroicons/react/24/solid"; | |
| 10 | +import { | |
| 11 | + BrowserSerializedContinueConfig, | |
| 12 | + RuleSource, | |
| 13 | + RuleWithSource, | |
| 14 | + SlashCommandDescWithSource, | |
| 15 | +} from "core"; | |
| 16 | +import { | |
| 17 | + DEFAULT_AGENT_SYSTEM_MESSAGE, | |
| 18 | + DEFAULT_CHAT_SYSTEM_MESSAGE, | |
| 19 | + DEFAULT_PLAN_SYSTEM_MESSAGE, | |
| 20 | + DEFAULT_SYSTEM_MESSAGES_URL, | |
| 21 | +} from "core/llm/defaultSystemMessages"; | |
| 22 | +import { useContext, useMemo } from "react"; | |
| 23 | +import HeaderButtonWithToolTip from "../../../components/gui/HeaderButtonWithToolTip"; | |
| 24 | +import Switch from "../../../components/gui/Switch"; | |
| 25 | +import { useMainEditor } from "../../../components/mainInput/TipTapEditor"; | |
| 26 | +import { Button, Card, EmptyState, useFontSize } from "../../../components/ui"; | |
| 27 | +import { useAuth } from "../../../context/Auth"; | |
| 28 | +import { IdeMessengerContext } from "../../../context/IdeMessenger"; | |
| 29 | +import { useBookmarkedSlashCommands } from "../../../hooks/useBookmarkedSlashCommands"; | |
| 30 | +import { useAppDispatch, useAppSelector } from "../../../redux/hooks"; | |
| 31 | +import { | |
| 32 | + DEFAULT_RULE_SETTING, | |
| 33 | + setDialogMessage, | |
| 34 | + setShowDialog, | |
| 35 | + toggleRuleSetting, | |
| 36 | +} from "../../../redux/slices/uiSlice"; | |
| 37 | +import { fontSize } from "../../../util"; | |
| 38 | +import { ConfigHeader } from "../components/ConfigHeader"; | |
| 39 | + | |
| 40 | +interface PromptCommandWithSlug extends SlashCommandDescWithSource { | |
| 41 | + slug?: string; | |
| 42 | +} | |
| 43 | + | |
| 44 | +interface PromptRowProps { | |
| 45 | + prompt: PromptCommandWithSlug; | |
| 46 | + isBookmarked: boolean; | |
| 47 | + setIsBookmarked: (isBookmarked: boolean) => void; | |
| 48 | + onEdit?: () => void; | |
| 49 | +} | |
| 50 | + | |
| 51 | +/** | |
| 52 | + * Displays a single prompt row with bookmark and edit controls | |
| 53 | + */ | |
| 54 | +function PromptRow({ | |
| 55 | + prompt, | |
| 56 | + isBookmarked, | |
| 57 | + setIsBookmarked, | |
| 58 | + onEdit, | |
| 59 | +}: PromptRowProps) { | |
| 60 | + const { mainEditor } = useMainEditor(); | |
| 61 | + | |
| 62 | + const handlePromptClick = (e: React.MouseEvent) => { | |
| 63 | + e.stopPropagation(); | |
| 64 | + mainEditor?.commands.insertPrompt({ | |
| 65 | + title: prompt.name, | |
| 66 | + description: prompt.description, | |
| 67 | + content: prompt.prompt, | |
| 68 | + }); | |
| 69 | + }; | |
| 70 | + | |
| 71 | + const handleBookmarkClick = (e: React.MouseEvent) => { | |
| 72 | + e.stopPropagation(); | |
| 73 | + setIsBookmarked(!isBookmarked); | |
| 74 | + }; | |
| 75 | + | |
| 76 | + const handleEditClick = (e: React.MouseEvent) => { | |
| 77 | + e.stopPropagation(); | |
| 78 | + if (onEdit) { | |
| 79 | + onEdit(); | |
| 80 | + } | |
| 81 | + }; | |
| 82 | + | |
| 83 | + const canEdit = | |
| 84 | + prompt.promptFile && !prompt.promptFile.startsWith("builtin:"); | |
| 85 | + | |
| 86 | + return ( | |
| 87 | + <div | |
| 88 | + className="hover:bg-list-active hover:text-list-active-foreground flex items-center justify-between gap-3 rounded-md px-2 py-1 hover:cursor-pointer" | |
| 89 | + onClick={handlePromptClick} | |
| 90 | + style={{ | |
| 91 | + fontSize: fontSize(-3), | |
| 92 | + }} | |
| 93 | + > | |
| 94 | + <div className="flex min-w-0 flex-col"> | |
| 95 | + <span className="text-vscForeground shrink-0 font-medium"> | |
| 96 | + {prompt.name} | |
| 97 | + </span> | |
| 98 | + <span className="line-clamp-2 text-[11px] text-gray-400"> | |
| 99 | + {prompt.description} | |
| 100 | + </span> | |
| 101 | + </div> | |
| 102 | + <div className="flex items-center gap-2"> | |
| 103 | + <PencilIcon | |
| 104 | + className={`h-3 w-3 cursor-pointer text-gray-400 hover:brightness-125 ${!canEdit ? "pointer-events-none cursor-not-allowed opacity-50" : ""}`} | |
| 105 | + onClick={canEdit ? handleEditClick : undefined} | |
| 106 | + aria-disabled={!canEdit} | |
| 107 | + /> | |
| 108 | + <div | |
| 109 | + onClick={handleBookmarkClick} | |
| 110 | + className="cursor-pointer pt-0.5 text-gray-400 hover:brightness-125" | |
| 111 | + > | |
| 112 | + {isBookmarked ? ( | |
| 113 | + <BookmarkSolid className="h-3 w-3" /> | |
| 114 | + ) : ( | |
| 115 | + <BookmarkOutline className="h-3 w-3" /> | |
| 116 | + )} | |
| 117 | + </div> | |
| 118 | + </div> | |
| 119 | + </div> | |
| 120 | + ); | |
| 121 | +} | |
| 122 | + | |
| 123 | +interface RuleCardProps { | |
| 124 | + rule: RuleWithSource; | |
| 125 | +} | |
| 126 | + | |
| 127 | +const RuleCard: React.FC<RuleCardProps> = ({ rule }) => { | |
| 128 | + const dispatch = useAppDispatch(); | |
| 129 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 130 | + const mode = useAppSelector((store) => store.session.mode); | |
| 131 | + const policy = useAppSelector((state) => | |
| 132 | + rule.name | |
| 133 | + ? state.ui.ruleSettings[rule.name] || DEFAULT_RULE_SETTING | |
| 134 | + : undefined, | |
| 135 | + ); | |
| 136 | + | |
| 137 | + const isDisabled = policy === "off"; | |
| 138 | + | |
| 139 | + const handleOpen = async () => { | |
| 140 | + if (rule.slug) { | |
| 141 | + void ideMessenger.request("controlPlane/openUrl", { | |
| 142 | + path: `${rule.slug}/new-version`, | |
| 143 | + orgSlug: undefined, | |
| 144 | + }); | |
| 145 | + } else if (rule.ruleFile) { | |
| 146 | + ideMessenger.post("openFile", { | |
| 147 | + path: rule.ruleFile, | |
| 148 | + }); | |
| 149 | + } else if ( | |
| 150 | + rule.source === "default-chat" || | |
| 151 | + rule.source === "default-plan" || | |
| 152 | + rule.source === "default-agent" | |
| 153 | + ) { | |
| 154 | + ideMessenger.post("openUrl", DEFAULT_SYSTEM_MESSAGES_URL); | |
| 155 | + } else { | |
| 156 | + ideMessenger.post("config/openProfile", { | |
| 157 | + profileId: undefined, | |
| 158 | + element: { sourceFile: (rule as any).sourceFile }, | |
| 159 | + }); | |
| 160 | + } | |
| 161 | + }; | |
| 162 | + | |
| 163 | + const handleTogglePolicy = () => { | |
| 164 | + if (rule.name) { | |
| 165 | + dispatch(toggleRuleSetting(rule.name)); | |
| 166 | + } | |
| 167 | + }; | |
| 168 | + | |
| 169 | + const title = useMemo(() => { | |
| 170 | + if (rule.name) { | |
| 171 | + return rule.name; | |
| 172 | + } else { | |
| 173 | + if (rule.source === ".continuerules") { | |
| 174 | + return "Project rules"; | |
| 175 | + } else if (rule.source === "default-chat") { | |
| 176 | + return "Default chat system message"; | |
| 177 | + } else if (rule.source === "default-agent") { | |
| 178 | + return "Default agent system message"; | |
| 179 | + } else if (rule.source === "json-systemMessage") { | |
| 180 | + return "JSON systemMessage)"; | |
| 181 | + } else if (rule.source === "model-options-agent") { | |
| 182 | + return "Base System Agent Message"; | |
| 183 | + } else if (rule.source === "model-options-plan") { | |
| 184 | + return "Base System Plan Message"; | |
| 185 | + } else if (rule.source === "model-options-chat") { | |
| 186 | + return "Base System Chat Message"; | |
| 187 | + } else { | |
| 188 | + return "Agent rule"; | |
| 189 | + } | |
| 190 | + } | |
| 191 | + }, [rule]); | |
| 192 | + | |
| 193 | + function onClickExpand() { | |
| 194 | + dispatch(setShowDialog(true)); | |
| 195 | + dispatch( | |
| 196 | + setDialogMessage( | |
| 197 | + <div className="max-h-4/5 p-4"> | |
| 198 | + <h3>{title}</h3> | |
| 199 | + <pre className="max-w-full overflow-scroll">{rule.rule}</pre> | |
| 200 | + </div>, | |
| 201 | + ), | |
| 202 | + ); | |
| 203 | + } | |
| 204 | + | |
| 205 | + const smallFont = useFontSize(-2); | |
| 206 | + const tinyFont = useFontSize(-3); | |
| 207 | + return ( | |
| 208 | + <div | |
| 209 | + className={`border-border flex flex-col rounded-sm px-2 py-1.5 transition-colors ${isDisabled ? "opacity-50" : ""}`} | |
| 210 | + > | |
| 211 | + <div className="flex flex-col"> | |
| 212 | + <div className="flex flex-row justify-between gap-1"> | |
| 213 | + <span | |
| 214 | + className={`line-clamp-2 ${isDisabled ? "text-gray-400" : "text-vsc-foreground"}`} | |
| 215 | + style={{ | |
| 216 | + fontSize: smallFont, | |
| 217 | + }} | |
| 218 | + > | |
| 219 | + {title} | |
| 220 | + </span> | |
| 221 | + <div className="flex flex-row items-center gap-2"> | |
| 222 | + {rule.name && policy && ( | |
| 223 | + <div className="flex cursor-pointer flex-row items-center justify-end gap-1 px-2 py-0.5"> | |
| 224 | + <Switch | |
| 225 | + isToggled={policy === "on"} | |
| 226 | + onToggle={() => handleTogglePolicy()} | |
| 227 | + size={10} | |
| 228 | + text="" | |
| 229 | + /> | |
| 230 | + </div> | |
| 231 | + )} | |
| 232 | + <div className="flex flex-row items-start gap-1"> | |
| 233 | + <HeaderButtonWithToolTip onClick={onClickExpand} text="Expand"> | |
| 234 | + <ArrowsPointingOutIcon className="h-3 w-3 text-gray-400" /> | |
| 235 | + </HeaderButtonWithToolTip>{" "} | |
| 236 | + {rule.source === "default-chat" || | |
| 237 | + rule.source === "default-agent" ? ( | |
| 238 | + <HeaderButtonWithToolTip onClick={handleOpen} text="View"> | |
| 239 | + <EyeIcon className="h-3 w-3 text-gray-400" /> | |
| 240 | + </HeaderButtonWithToolTip> | |
| 241 | + ) : ( | |
| 242 | + <HeaderButtonWithToolTip onClick={handleOpen} text="Edit"> | |
| 243 | + <PencilIcon className="h-3 w-3 text-gray-400" /> | |
| 244 | + </HeaderButtonWithToolTip> | |
| 245 | + )} | |
| 246 | + </div> | |
| 247 | + </div> | |
| 248 | + </div> | |
| 249 | + | |
| 250 | + <span | |
| 251 | + style={{ | |
| 252 | + fontSize: tinyFont, | |
| 253 | + }} | |
| 254 | + className={`mt-1 line-clamp-3 ${isDisabled ? "text-gray-500" : "text-gray-400"}`} | |
| 255 | + > | |
| 256 | + {rule.rule} | |
| 257 | + </span> | |
| 258 | + {rule.globs ? ( | |
| 259 | + <div | |
| 260 | + style={{ | |
| 261 | + fontSize: tinyFont, | |
| 262 | + }} | |
| 263 | + className="mt-1.5 flex flex-col gap-1" | |
| 264 | + > | |
| 265 | + <span className="italic">Applies to files</span> | |
| 266 | + <code | |
| 267 | + className={`line-clamp-1 px-1 py-0.5 ${isDisabled ? "text-gray-500" : "text-gray-400"}`} | |
| 268 | + > | |
| 269 | + {rule.globs} | |
| 270 | + </code> | |
| 271 | + </div> | |
| 272 | + ) : null} | |
| 273 | + </div> | |
| 274 | + </div> | |
| 275 | + ); | |
| 276 | +}; | |
| 277 | + | |
| 278 | +/** | |
| 279 | + * Section that displays all available prompts with bookmarking functionality | |
| 280 | + */ | |
| 281 | +function PromptsSubSection() { | |
| 282 | + const { selectedProfile } = useAuth(); | |
| 283 | + const { isCommandBookmarked, toggleBookmark } = useBookmarkedSlashCommands(); | |
| 284 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 285 | + const isLocal = selectedProfile?.profileType === "local"; | |
| 286 | + | |
| 287 | + const slashCommands = useAppSelector( | |
| 288 | + (state) => state.config.config.slashCommands ?? [], | |
| 289 | + ); | |
| 290 | + | |
| 291 | + const handleEdit = (prompt: PromptCommandWithSlug) => { | |
| 292 | + if (prompt.promptFile) { | |
| 293 | + ideMessenger.post("openFile", { | |
| 294 | + path: prompt.promptFile, | |
| 295 | + }); | |
| 296 | + } else if (prompt.slug) { | |
| 297 | + void ideMessenger.request("controlPlane/openUrl", { | |
| 298 | + path: `${prompt.slug}/new-version`, | |
| 299 | + orgSlug: undefined, | |
| 300 | + }); | |
| 301 | + } else { | |
| 302 | + ideMessenger.post("config/openProfile", { | |
| 303 | + profileId: undefined, | |
| 304 | + element: { sourceFile: (prompt as any).sourceFile }, | |
| 305 | + }); | |
| 306 | + } | |
| 307 | + }; | |
| 308 | + | |
| 309 | + const handleAddPrompt = () => { | |
| 310 | + if (isLocal) { | |
| 311 | + void ideMessenger.request("config/addLocalWorkspaceBlock", { | |
| 312 | + blockType: "prompts", | |
| 313 | + }); | |
| 314 | + } else { | |
| 315 | + void ideMessenger.request("controlPlane/openUrl", { | |
| 316 | + path: "?type=prompts", | |
| 317 | + orgSlug: undefined, | |
| 318 | + }); | |
| 319 | + } | |
| 320 | + }; | |
| 321 | + | |
| 322 | + const sortedCommands = useMemo(() => { | |
| 323 | + const promptsWithSlug: PromptCommandWithSlug[] = | |
| 324 | + structuredClone(slashCommands); | |
| 325 | + // get the slugs from rawYaml | |
| 326 | + if (selectedProfile?.rawYaml) { | |
| 327 | + const parsed = parseConfigYaml(selectedProfile.rawYaml); | |
| 328 | + const parsedPrompts = parsed.prompts ?? []; | |
| 329 | + | |
| 330 | + let index = 0; | |
| 331 | + for (const commandWithSlug of promptsWithSlug) { | |
| 332 | + // skip for local prompt files | |
| 333 | + if (commandWithSlug.promptFile) continue; | |
| 334 | + | |
| 335 | + const yamlPrompt = parsedPrompts[index]; | |
| 336 | + if (yamlPrompt) { | |
| 337 | + if ("uses" in yamlPrompt) { | |
| 338 | + commandWithSlug.slug = yamlPrompt.uses; | |
| 339 | + } else { | |
| 340 | + commandWithSlug.slug = `${selectedProfile?.fullSlug.ownerSlug}/${selectedProfile?.fullSlug.packageSlug}`; | |
| 341 | + } | |
| 342 | + } | |
| 343 | + index = index + 1; | |
| 344 | + } | |
| 345 | + } | |
| 346 | + return promptsWithSlug.sort((a, b) => { | |
| 347 | + const aBookmarked = isCommandBookmarked(a.name); | |
| 348 | + const bBookmarked = isCommandBookmarked(b.name); | |
| 349 | + if (aBookmarked && !bBookmarked) return -1; | |
| 350 | + if (!aBookmarked && bBookmarked) return 1; | |
| 351 | + return 0; | |
| 352 | + }); | |
| 353 | + }, [slashCommands, isCommandBookmarked, selectedProfile]); | |
| 354 | + | |
| 355 | + return ( | |
| 356 | + <div> | |
| 357 | + <ConfigHeader | |
| 358 | + title="Prompts" | |
| 359 | + variant="sm" | |
| 360 | + onAddClick={handleAddPrompt} | |
| 361 | + addButtonTooltip="Add prompt" | |
| 362 | + /> | |
| 363 | + | |
| 364 | + {sortedCommands.length > 0 ? ( | |
| 365 | + <Card> | |
| 366 | + <div> | |
| 367 | + {sortedCommands.map((prompt) => ( | |
| 368 | + <PromptRow | |
| 369 | + key={prompt.name} | |
| 370 | + prompt={prompt} | |
| 371 | + isBookmarked={isCommandBookmarked(prompt.name)} | |
| 372 | + setIsBookmarked={() => toggleBookmark(prompt)} | |
| 373 | + onEdit={() => handleEdit(prompt)} | |
| 374 | + /> | |
| 375 | + ))} | |
| 376 | + </div> | |
| 377 | + </Card> | |
| 378 | + ) : ( | |
| 379 | + <Card> | |
| 380 | + <EmptyState message="No prompts configured. Click the + button to add your first prompt." /> | |
| 381 | + </Card> | |
| 382 | + )} | |
| 383 | + </div> | |
| 384 | + ); | |
| 385 | +} | |
| 386 | + | |
| 387 | +/** | |
| 388 | + * Helper function to add the appropriate default system message based on mode | |
| 389 | + */ | |
| 390 | +function addDefaultSystemMessage( | |
| 391 | + rules: RuleWithSource[], | |
| 392 | + mode: string, | |
| 393 | + config: BrowserSerializedContinueConfig, | |
| 394 | +) { | |
| 395 | + const modeConfig = { | |
| 396 | + chat: { | |
| 397 | + customMessage: config.selectedModelByRole.chat?.baseChatSystemMessage, | |
| 398 | + defaultMessage: DEFAULT_CHAT_SYSTEM_MESSAGE, | |
| 399 | + customSource: "model-options-chat" as RuleSource, | |
| 400 | + defaultSource: "default-chat" as RuleSource, | |
| 401 | + }, | |
| 402 | + agent: { | |
| 403 | + customMessage: config.selectedModelByRole.chat?.baseAgentSystemMessage, | |
| 404 | + defaultMessage: DEFAULT_AGENT_SYSTEM_MESSAGE, | |
| 405 | + customSource: "model-options-agent" as RuleSource, | |
| 406 | + defaultSource: "default-agent" as RuleSource, | |
| 407 | + }, | |
| 408 | + plan: { | |
| 409 | + customMessage: config.selectedModelByRole.chat?.basePlanSystemMessage, | |
| 410 | + defaultMessage: DEFAULT_PLAN_SYSTEM_MESSAGE, | |
| 411 | + customSource: "model-options-plan" as RuleSource, | |
| 412 | + defaultSource: "default-plan" as RuleSource, | |
| 413 | + }, | |
| 414 | + }; | |
| 415 | + | |
| 416 | + const currentMode = modeConfig[mode as keyof typeof modeConfig]; | |
| 417 | + if (currentMode) { | |
| 418 | + const message = currentMode.customMessage || currentMode.defaultMessage; | |
| 419 | + const source = currentMode.customMessage | |
| 420 | + ? currentMode.customSource | |
| 421 | + : currentMode.defaultSource; | |
| 422 | + | |
| 423 | + rules.unshift({ | |
| 424 | + rule: message, | |
| 425 | + source, | |
| 426 | + }); | |
| 427 | + } | |
| 428 | +} | |
| 429 | + | |
| 430 | +function RulesSubSection() { | |
| 431 | + const { selectedProfile } = useAuth(); | |
| 432 | + const config = useAppSelector((store) => store.config.config); | |
| 433 | + const mode = useAppSelector((store) => store.session.mode); | |
| 434 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 435 | + const isLocal = selectedProfile?.profileType === "local"; | |
| 436 | + | |
| 437 | + const handleAddRule = () => { | |
| 438 | + if (isLocal) { | |
| 439 | + void ideMessenger.request("config/addLocalWorkspaceBlock", { | |
| 440 | + blockType: "rules", | |
| 441 | + }); | |
| 442 | + } else { | |
| 443 | + void ideMessenger.request("controlPlane/openUrl", { | |
| 444 | + path: "?type=rules", | |
| 445 | + orgSlug: undefined, | |
| 446 | + }); | |
| 447 | + } | |
| 448 | + }; | |
| 449 | + | |
| 450 | + const sortedRules: RuleWithSource[] = useMemo(() => { | |
| 451 | + const rules = [...config.rules.map((rule) => ({ ...rule }))]; | |
| 452 | + | |
| 453 | + // Use profile rawYaml to infer slugs | |
| 454 | + if (selectedProfile?.rawYaml) { | |
| 455 | + try { | |
| 456 | + const parsed = parseConfigYaml(selectedProfile.rawYaml); | |
| 457 | + const parsedRules = parsed?.rules ?? []; | |
| 458 | + let index = 0; | |
| 459 | + for (const rule of rules) { | |
| 460 | + if (rule.source === "rules-block") { | |
| 461 | + let slug: string | undefined = undefined; | |
| 462 | + const yamlRule = parsedRules[index]; | |
| 463 | + if (yamlRule) { | |
| 464 | + if (typeof yamlRule !== "string" && "uses" in yamlRule) { | |
| 465 | + slug = yamlRule.uses; | |
| 466 | + } else { | |
| 467 | + slug = `${selectedProfile?.fullSlug.ownerSlug}/${selectedProfile?.fullSlug.packageSlug}`; | |
| 468 | + } | |
| 469 | + } | |
| 470 | + if (slug) { | |
| 471 | + rule.slug = slug; | |
| 472 | + } | |
| 473 | + | |
| 474 | + index++; | |
| 475 | + } | |
| 476 | + } | |
| 477 | + } catch (e) { | |
| 478 | + console.error( | |
| 479 | + "Rules notch section: failed to parse selected profile", | |
| 480 | + e, | |
| 481 | + ); | |
| 482 | + } | |
| 483 | + } | |
| 484 | + | |
| 485 | + addDefaultSystemMessage(rules, mode, config); | |
| 486 | + | |
| 487 | + return rules; | |
| 488 | + }, [config, selectedProfile, mode]); | |
| 489 | + | |
| 490 | + return ( | |
| 491 | + <div> | |
| 492 | + <ConfigHeader | |
| 493 | + title="Rules" | |
| 494 | + variant="sm" | |
| 495 | + onAddClick={handleAddRule} | |
| 496 | + addButtonTooltip="Add rule" | |
| 497 | + /> | |
| 498 | + | |
| 499 | + <Card> | |
| 500 | + {sortedRules.length > 0 ? ( | |
| 501 | + <div className="flex flex-col gap-3"> | |
| 502 | + {sortedRules.map((rule, index) => ( | |
| 503 | + <RuleCard key={index} rule={rule} /> | |
| 504 | + ))} | |
| 505 | + </div> | |
| 506 | + ) : ( | |
| 507 | + <EmptyState message="No rules configured. Click the + button to add your first rule." /> | |
| 508 | + )} | |
| 509 | + </Card> | |
| 510 | + </div> | |
| 511 | + ); | |
| 512 | +} | |
| 513 | + | |
| 514 | +export function RulesSection() { | |
| 515 | + return ( | |
| 516 | + <> | |
| 517 | + <ConfigHeader title="Rules" /> | |
| 518 | + | |
| 519 | + <div className="space-y-6"> | |
| 520 | + <RulesSubSection /> | |
| 521 | + <PromptsSubSection /> | |
| 522 | + </div> | |
| 523 | + </> | |
| 524 | + ); | |
| 525 | +} |
added gui/src/pages/config/sections/ToolPoliciesSection.tsx +11 −0
| @@ -0,0 +1,11 @@ | ||
| 1 | +import { ConfigHeader } from "../components/ConfigHeader"; | |
| 2 | +import { ToolPolicies } from "../components/ToolPolicies"; | |
| 3 | + | |
| 4 | +export const ToolPoliciesSection = () => { | |
| 5 | + return ( | |
| 6 | + <div> | |
| 7 | + <ConfigHeader title="Tool Policies" /> | |
| 8 | + <ToolPolicies /> | |
| 9 | + </div> | |
| 10 | + ); | |
| 11 | +}; |
added gui/src/pages/config/sections/ToolsSection.tsx +372 −0
| @@ -0,0 +1,372 @@ | ||
| 1 | +import { ConfigYaml, parseConfigYaml } from "@continuedev/config-yaml"; | |
| 2 | +import { | |
| 3 | + ArrowPathIcon, | |
| 4 | + ChevronDownIcon, | |
| 5 | + CircleStackIcon, | |
| 6 | + CommandLineIcon, | |
| 7 | + GlobeAltIcon, | |
| 8 | + PlusIcon, | |
| 9 | + UserCircleIcon, | |
| 10 | + WrenchScrewdriverIcon, | |
| 11 | +} from "@heroicons/react/24/outline"; | |
| 12 | +import { MCPServerStatus } from "core"; | |
| 13 | +import { useContext, useMemo, useState } from "react"; | |
| 14 | +import Alert from "../../../components/gui/Alert"; | |
| 15 | +import { ToolTip } from "../../../components/gui/Tooltip"; | |
| 16 | +import EditBlockButton from "../../../components/mainInput/Lump/EditBlockButton"; | |
| 17 | +import { Button, Card, EmptyState } from "../../../components/ui"; | |
| 18 | +import { useAuth } from "../../../context/Auth"; | |
| 19 | +import { IdeMessengerContext } from "../../../context/IdeMessenger"; | |
| 20 | +import { useAppDispatch, useAppSelector } from "../../../redux/hooks"; | |
| 21 | +import { updateConfig } from "../../../redux/slices/configSlice"; | |
| 22 | +import { selectCurrentOrg } from "../../../redux/slices/profilesSlice"; | |
| 23 | +import { ConfigHeader } from "../components/ConfigHeader"; | |
| 24 | +import { ToolPolicies } from "../components/ToolPolicies"; | |
| 25 | + | |
| 26 | +interface MCPServerStatusProps { | |
| 27 | + server: MCPServerStatus; | |
| 28 | + serverFromYaml?: NonNullable<ConfigYaml["mcpServers"]>[number]; | |
| 29 | +} | |
| 30 | + | |
| 31 | +function MCPServerPreview({ server, serverFromYaml }: MCPServerStatusProps) { | |
| 32 | + const [expandedSections, setExpandedSections] = useState<{ | |
| 33 | + [key: string]: boolean; | |
| 34 | + }>({}); | |
| 35 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 36 | + const config = useAppSelector((store) => store.config.config); | |
| 37 | + const dispatch = useAppDispatch(); | |
| 38 | + | |
| 39 | + const updateMCPServerStatus = (status: MCPServerStatus["status"]) => { | |
| 40 | + // optimistic config update | |
| 41 | + dispatch( | |
| 42 | + updateConfig({ | |
| 43 | + ...config, | |
| 44 | + mcpServerStatuses: config.mcpServerStatuses.map((s) => | |
| 45 | + s.id === server.id | |
| 46 | + ? { | |
| 47 | + ...s, | |
| 48 | + status, | |
| 49 | + } | |
| 50 | + : s, | |
| 51 | + ), | |
| 52 | + }), | |
| 53 | + ); | |
| 54 | + }; | |
| 55 | + | |
| 56 | + const onAuthenticate = async () => { | |
| 57 | + updateMCPServerStatus("authenticating"); | |
| 58 | + await ideMessenger.request("mcp/startAuthentication", server); | |
| 59 | + }; | |
| 60 | + | |
| 61 | + const onRemoveAuth = async () => { | |
| 62 | + updateMCPServerStatus("authenticating"); | |
| 63 | + await ideMessenger.request("mcp/removeAuthentication", server); | |
| 64 | + }; | |
| 65 | + | |
| 66 | + const onRefresh = async () => { | |
| 67 | + updateMCPServerStatus("connecting"); | |
| 68 | + ideMessenger.post("mcp/reloadServer", { | |
| 69 | + id: server.id, | |
| 70 | + }); | |
| 71 | + }; | |
| 72 | + | |
| 73 | + const toggleSection = (section: string) => { | |
| 74 | + setExpandedSections((prev) => ({ | |
| 75 | + ...prev, | |
| 76 | + [section]: !prev[section], | |
| 77 | + })); | |
| 78 | + }; | |
| 79 | + | |
| 80 | + const ResourceRow = ({ | |
| 81 | + title, | |
| 82 | + items, | |
| 83 | + icon, | |
| 84 | + sectionKey, | |
| 85 | + }: { | |
| 86 | + title: string; | |
| 87 | + items: any[]; | |
| 88 | + icon: React.ReactNode; | |
| 89 | + sectionKey: string; | |
| 90 | + }) => { | |
| 91 | + const isExpanded = expandedSections[sectionKey]; | |
| 92 | + const hasItems = items.length > 0; | |
| 93 | + | |
| 94 | + return ( | |
| 95 | + <div> | |
| 96 | + <div | |
| 97 | + className="-mx-2 flex cursor-pointer items-center justify-between rounded px-2 py-2 hover:bg-gray-50 hover:bg-opacity-5" | |
| 98 | + onClick={() => toggleSection(sectionKey)} | |
| 99 | + > | |
| 100 | + <div className="flex items-center gap-3"> | |
| 101 | + <ChevronDownIcon | |
| 102 | + className={`text-description h-3 w-3 transition-transform ${isExpanded ? "rotate-180" : ""}`} | |
| 103 | + /> | |
| 104 | + <div className="flex items-center gap-2"> | |
| 105 | + {icon} | |
| 106 | + <span className="text-sm">{title}</span> | |
| 107 | + <div className="flex h-5 w-5 items-center justify-center rounded-full bg-gray-600 text-xs font-medium text-white"> | |
| 108 | + {items.length} | |
| 109 | + </div> | |
| 110 | + </div> | |
| 111 | + </div> | |
| 112 | + </div> | |
| 113 | + | |
| 114 | + {isExpanded && ( | |
| 115 | + <div className="mb-3 ml-6 mt-2"> | |
| 116 | + {hasItems ? ( | |
| 117 | + <div className="space-y-1"> | |
| 118 | + {items.map((item, idx) => ( | |
| 119 | + <div | |
| 120 | + key={idx} | |
| 121 | + className="text-description rounded bg-gray-50 bg-opacity-5 px-2 py-1 text-xs" | |
| 122 | + > | |
| 123 | + <code>{item.name}</code> | |
| 124 | + {item.description && ( | |
| 125 | + <div className="mt-1 text-xs text-gray-500"> | |
| 126 | + {item.description} | |
| 127 | + </div> | |
| 128 | + )} | |
| 129 | + </div> | |
| 130 | + ))} | |
| 131 | + </div> | |
| 132 | + ) : ( | |
| 133 | + <div className="text-xs italic text-gray-500"> | |
| 134 | + No {title.toLowerCase()} available | |
| 135 | + </div> | |
| 136 | + )} | |
| 137 | + </div> | |
| 138 | + )} | |
| 139 | + </div> | |
| 140 | + ); | |
| 141 | + }; | |
| 142 | + | |
| 143 | + return ( | |
| 144 | + <div> | |
| 145 | + <div className="flex items-center justify-between py-1"> | |
| 146 | + <div className="flex items-center gap-3"> | |
| 147 | + <div className="flex-1"> | |
| 148 | + <div className="flex items-center gap-3"> | |
| 149 | + <h3 className="my-0 text-sm font-medium">{server.name}</h3> | |
| 150 | + <div | |
| 151 | + className={`h-2 w-2 flex-shrink-0 rounded-full ${ | |
| 152 | + server.status === "connected" | |
| 153 | + ? "bg-success" | |
| 154 | + : server.status === "connecting" | |
| 155 | + ? "bg-warning" | |
| 156 | + : server.status === "not-connected" | |
| 157 | + ? "bg-description-muted" | |
| 158 | + : "bg-error" | |
| 159 | + }`} | |
| 160 | + /> | |
| 161 | + </div> | |
| 162 | + </div> | |
| 163 | + </div> | |
| 164 | + | |
| 165 | + <div className="-mr-2.5 flex items-center gap-1"> | |
| 166 | + {server.isProtectedResource && ( | |
| 167 | + <ToolTip | |
| 168 | + content={ | |
| 169 | + server.status === "error" | |
| 170 | + ? "Authenticate" | |
| 171 | + : server.status === "authenticating" | |
| 172 | + ? "Authenticating..." | |
| 173 | + : "Remove authentication" | |
| 174 | + } | |
| 175 | + > | |
| 176 | + <Button | |
| 177 | + onClick={ | |
| 178 | + server.status === "error" | |
| 179 | + ? onAuthenticate | |
| 180 | + : server.status === "authenticating" | |
| 181 | + ? undefined | |
| 182 | + : onRemoveAuth | |
| 183 | + } | |
| 184 | + variant="ghost" | |
| 185 | + size="sm" | |
| 186 | + className="text-description-muted hover:enabled:text-foreground my-0 h-6 w-6 p-0" | |
| 187 | + disabled={server.status === "authenticating"} | |
| 188 | + > | |
| 189 | + {server.status === "authenticating" ? ( | |
| 190 | + <GlobeAltIcon className="animate-spin-slow h-4 w-4 flex-shrink-0" /> | |
| 191 | + ) : ( | |
| 192 | + <UserCircleIcon className="h-4 w-4 flex-shrink-0" /> | |
| 193 | + )} | |
| 194 | + </Button> | |
| 195 | + </ToolTip> | |
| 196 | + )} | |
| 197 | + | |
| 198 | + <ToolTip content="Edit server configuration"> | |
| 199 | + <div> | |
| 200 | + <EditBlockButton | |
| 201 | + blockType={"mcpServers"} | |
| 202 | + block={serverFromYaml} | |
| 203 | + sourceFile={server.sourceFile} | |
| 204 | + /> | |
| 205 | + </div> | |
| 206 | + </ToolTip> | |
| 207 | + | |
| 208 | + <ToolTip content="Refresh server"> | |
| 209 | + <Button | |
| 210 | + onClick={onRefresh} | |
| 211 | + variant="ghost" | |
| 212 | + size="sm" | |
| 213 | + className="text-description-muted hover:enabled:text-foreground my-0 h-6 w-6 p-0" | |
| 214 | + > | |
| 215 | + <ArrowPathIcon className="h-4 w-4 flex-shrink-0" /> | |
| 216 | + </Button> | |
| 217 | + </ToolTip> | |
| 218 | + </div> | |
| 219 | + </div> | |
| 220 | + | |
| 221 | + {/* Individual resource rows */} | |
| 222 | + <div className="mt-1"> | |
| 223 | + <ResourceRow | |
| 224 | + title="Tools" | |
| 225 | + items={server.tools} | |
| 226 | + icon={ | |
| 227 | + <WrenchScrewdriverIcon className="text-description h-4 w-4 flex-shrink-0" /> | |
| 228 | + } | |
| 229 | + sectionKey={`${server.id}-tools`} | |
| 230 | + /> | |
| 231 | + | |
| 232 | + <ResourceRow | |
| 233 | + title="Prompts" | |
| 234 | + items={server.prompts} | |
| 235 | + icon={ | |
| 236 | + <CommandLineIcon className="text-description h-4 w-4 flex-shrink-0" /> | |
| 237 | + } | |
| 238 | + sectionKey={`${server.id}-prompts`} | |
| 239 | + /> | |
| 240 | + | |
| 241 | + <ResourceRow | |
| 242 | + title="Resources" | |
| 243 | + items={[...server.resources, ...server.resourceTemplates]} | |
| 244 | + icon={ | |
| 245 | + <CircleStackIcon className="text-description h-4 w-4 flex-shrink-0" /> | |
| 246 | + } | |
| 247 | + sectionKey={`${server.id}-resources`} | |
| 248 | + /> | |
| 249 | + </div> | |
| 250 | + | |
| 251 | + {/* Error display below expandable section */} | |
| 252 | + {server.errors && server.errors.length > 0 && ( | |
| 253 | + <div className="mt-3 space-y-2"> | |
| 254 | + {server.errors.map((error, errorIndex) => ( | |
| 255 | + <Alert | |
| 256 | + key={errorIndex} | |
| 257 | + type="error" | |
| 258 | + size="sm" | |
| 259 | + className="cursor-pointer transition-all hover:underline" | |
| 260 | + onClick={() => | |
| 261 | + void ideMessenger.ide.showVirtualFile(server.name, error) | |
| 262 | + } | |
| 263 | + > | |
| 264 | + <span className="text-xs"> | |
| 265 | + {error.length > 150 ? error.substring(0, 150) + "..." : error} | |
| 266 | + </span> | |
| 267 | + </Alert> | |
| 268 | + ))} | |
| 269 | + </div> | |
| 270 | + )} | |
| 271 | + </div> | |
| 272 | + ); | |
| 273 | +} | |
| 274 | + | |
| 275 | +function McpSubsection() { | |
| 276 | + const currentOrg = useAppSelector(selectCurrentOrg); | |
| 277 | + const servers = useAppSelector( | |
| 278 | + (store) => store.config.config.mcpServerStatuses, | |
| 279 | + ); | |
| 280 | + const { selectedProfile } = useAuth(); | |
| 281 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 282 | + const disableMcp = currentOrg?.policy?.allowMcpServers === false; | |
| 283 | + const isLocal = selectedProfile?.profileType === "local"; | |
| 284 | + | |
| 285 | + const mergedBlocks = useMemo(() => { | |
| 286 | + const parsed = selectedProfile?.rawYaml | |
| 287 | + ? parseConfigYaml(selectedProfile?.rawYaml ?? "") | |
| 288 | + : undefined; | |
| 289 | + | |
| 290 | + // Create a map of YAML servers keyed by name for stable matching | |
| 291 | + const yamlServersByName = new Map( | |
| 292 | + parsed?.mcpServers | |
| 293 | + ?.filter( | |
| 294 | + (server): server is NonNullable<typeof server> & { name: string } => | |
| 295 | + server != null && "name" in server, | |
| 296 | + ) | |
| 297 | + .map((server) => [server.name, server]) ?? [], | |
| 298 | + ); | |
| 299 | + | |
| 300 | + return (servers ?? []).map((doc) => ({ | |
| 301 | + block: doc, | |
| 302 | + blockFromYaml: yamlServersByName.get(doc.name), | |
| 303 | + })); | |
| 304 | + }, [servers, selectedProfile]); | |
| 305 | + | |
| 306 | + const handleAddMcpServer = () => { | |
| 307 | + if (isLocal) { | |
| 308 | + void ideMessenger.request("config/addLocalWorkspaceBlock", { | |
| 309 | + blockType: "mcpServers", | |
| 310 | + }); | |
| 311 | + } else { | |
| 312 | + void ideMessenger.request("controlPlane/openUrl", { | |
| 313 | + path: "?type=mcpServers", | |
| 314 | + orgSlug: undefined, | |
| 315 | + }); | |
| 316 | + } | |
| 317 | + }; | |
| 318 | + | |
| 319 | + return ( | |
| 320 | + <div> | |
| 321 | + <ConfigHeader | |
| 322 | + title="MCP Servers" | |
| 323 | + variant="sm" | |
| 324 | + onAddClick={!disableMcp ? handleAddMcpServer : undefined} | |
| 325 | + addButtonTooltip="Add MCP server" | |
| 326 | + /> | |
| 327 | + {disableMcp ? ( | |
| 328 | + <Card> | |
| 329 | + <EmptyState message="MCP servers are disabled in your organization" /> | |
| 330 | + </Card> | |
| 331 | + ) : mergedBlocks.length > 0 ? ( | |
| 332 | + mergedBlocks.map(({ block, blockFromYaml }, index) => ( | |
| 333 | + <div key={block.id}> | |
| 334 | + <Card> | |
| 335 | + <MCPServerPreview server={block} serverFromYaml={blockFromYaml} /> | |
| 336 | + </Card> | |
| 337 | + {index < mergedBlocks.length - 1 && <div className="mb-4" />} | |
| 338 | + </div> | |
| 339 | + )) | |
| 340 | + ) : ( | |
| 341 | + <Card> | |
| 342 | + <EmptyState message="No MCP servers configured. Click the + button to add your first server." /> | |
| 343 | + </Card> | |
| 344 | + )} | |
| 345 | + </div> | |
| 346 | + ); | |
| 347 | +} | |
| 348 | + | |
| 349 | +function ToolPoliciesSubsection() { | |
| 350 | + return ( | |
| 351 | + <div> | |
| 352 | + <ConfigHeader title="Tool Policies" variant="sm" /> | |
| 353 | + <ToolPolicies /> | |
| 354 | + </div> | |
| 355 | + ); | |
| 356 | +} | |
| 357 | + | |
| 358 | +export function ToolsSection() { | |
| 359 | + const availableTools = useAppSelector((state) => state.config.config.tools); | |
| 360 | + | |
| 361 | + const hasTools = availableTools && availableTools.length > 0; | |
| 362 | + | |
| 363 | + return ( | |
| 364 | + <> | |
| 365 | + <ConfigHeader title="Tools" /> | |
| 366 | + <div className="space-y-6"> | |
| 367 | + <McpSubsection /> | |
| 368 | + {hasTools && <ToolPoliciesSubsection />} | |
| 369 | + </div> | |
| 370 | + </> | |
| 371 | + ); | |
| 372 | +} |
added gui/src/pages/config/sections/UserSettingsSection.tsx +353 −0
| @@ -0,0 +1,353 @@ | ||
| 1 | +import { | |
| 2 | + SharedConfigSchema, | |
| 3 | + modifyAnyConfigWithSharedConfig, | |
| 4 | +} from "core/config/sharedConfig"; | |
| 5 | +import { HubSessionInfo } from "core/control-plane/AuthTypes"; | |
| 6 | +import { isContinueTeamMember } from "core/util/isContinueTeamMember"; | |
| 7 | +import { useContext, useEffect, useState } from "react"; | |
| 8 | +import { Card, Toggle, useFontSize } from "../../../components/ui"; | |
| 9 | +import { useAuth } from "../../../context/Auth"; | |
| 10 | +import { IdeMessengerContext } from "../../../context/IdeMessenger"; | |
| 11 | +import { useAppDispatch, useAppSelector } from "../../../redux/hooks"; | |
| 12 | +import { updateConfig } from "../../../redux/slices/configSlice"; | |
| 13 | +import { selectCurrentOrg } from "../../../redux/slices/profilesSlice"; | |
| 14 | +import { setLocalStorage } from "../../../util/localStorage"; | |
| 15 | +import { ConfigHeader } from "../components/ConfigHeader"; | |
| 16 | +import { ContinueFeaturesMenu } from "../components/ContinueFeaturesMenu"; | |
| 17 | +import { UserSetting } from "../components/UserSetting"; | |
| 18 | + | |
| 19 | +export function UserSettingsSection() { | |
| 20 | + /////// User settings section ////// | |
| 21 | + const dispatch = useAppDispatch(); | |
| 22 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 23 | + const config = useAppSelector((state) => state.config.config); | |
| 24 | + const currentOrg = useAppSelector(selectCurrentOrg); | |
| 25 | + | |
| 26 | + const [showExperimental, setShowExperimental] = useState(false); | |
| 27 | + const { session } = useAuth(); | |
| 28 | + | |
| 29 | + function handleUpdate(sharedConfig: SharedConfigSchema) { | |
| 30 | + // Optimistic update | |
| 31 | + const updatedConfig = modifyAnyConfigWithSharedConfig(config, sharedConfig); | |
| 32 | + dispatch(updateConfig(updatedConfig)); | |
| 33 | + // IMPORTANT no need for model role updates (separate logic for selected model roles) | |
| 34 | + // simply because this function won't be used to update model roles | |
| 35 | + | |
| 36 | + // Actual update to core which propagates back with config update event | |
| 37 | + ideMessenger.post("config/updateSharedConfig", sharedConfig); | |
| 38 | + } | |
| 39 | + | |
| 40 | + // Disable autocomplete | |
| 41 | + const disableAutocompleteInFiles = ( | |
| 42 | + config.tabAutocompleteOptions?.disableInFiles ?? [] | |
| 43 | + ).join(", "); | |
| 44 | + const [formDisableAutocomplete, setFormDisableAutocomplete] = useState( | |
| 45 | + disableAutocompleteInFiles, | |
| 46 | + ); | |
| 47 | + | |
| 48 | + useEffect(() => { | |
| 49 | + // Necessary so that reformatted/trimmed values don't cause dirty state | |
| 50 | + setFormDisableAutocomplete(disableAutocompleteInFiles); | |
| 51 | + }, [disableAutocompleteInFiles]); | |
| 52 | + | |
| 53 | + // Workspace prompts | |
| 54 | + const promptPath = config.experimental?.promptPath || ""; | |
| 55 | + | |
| 56 | + const handleEnableStaticContextualizationToggle = (value: boolean) => { | |
| 57 | + handleUpdate({ enableStaticContextualization: value }); | |
| 58 | + }; | |
| 59 | + | |
| 60 | + // TODO defaults are in multiple places, should be consolidated and probably not explicit here | |
| 61 | + const showSessionTabs = config.ui?.showSessionTabs ?? false; | |
| 62 | + const continueAfterToolRejection = | |
| 63 | + config.ui?.continueAfterToolRejection ?? false; | |
| 64 | + const codeWrap = config.ui?.codeWrap ?? false; | |
| 65 | + const showChatScrollbar = config.ui?.showChatScrollbar ?? false; | |
| 66 | + const readResponseTTS = config.experimental?.readResponseTTS ?? false; | |
| 67 | + const autoAcceptEditToolDiffs = config.ui?.autoAcceptEditToolDiffs ?? false; | |
| 68 | + const displayRawMarkdown = config.ui?.displayRawMarkdown ?? false; | |
| 69 | + const disableSessionTitles = config.disableSessionTitles ?? false; | |
| 70 | + const useCurrentFileAsContext = | |
| 71 | + config.experimental?.useCurrentFileAsContext ?? false; | |
| 72 | + const enableExperimentalTools = | |
| 73 | + config.experimental?.enableExperimentalTools ?? false; | |
| 74 | + const onlyUseSystemMessageTools = | |
| 75 | + config.experimental?.onlyUseSystemMessageTools ?? false; | |
| 76 | + const codebaseToolCallingOnly = | |
| 77 | + config.experimental?.codebaseToolCallingOnly ?? false; | |
| 78 | + const enableStaticContextualization = | |
| 79 | + config.experimental?.enableStaticContextualization ?? false; | |
| 80 | + | |
| 81 | + const allowAnonymousTelemetry = config.allowAnonymousTelemetry ?? true; | |
| 82 | + | |
| 83 | + const useAutocompleteMultilineCompletions = | |
| 84 | + config.tabAutocompleteOptions?.multilineCompletions ?? "auto"; | |
| 85 | + const modelTimeout = config.tabAutocompleteOptions?.modelTimeout ?? 150; | |
| 86 | + const debounceDelay = config.tabAutocompleteOptions?.debounceDelay ?? 250; | |
| 87 | + const fontSize = useFontSize(); | |
| 88 | + | |
| 89 | + const cancelChangeDisableAutocomplete = () => { | |
| 90 | + setFormDisableAutocomplete(disableAutocompleteInFiles); | |
| 91 | + }; | |
| 92 | + const handleDisableAutocompleteSubmit = () => { | |
| 93 | + handleUpdate({ | |
| 94 | + disableAutocompleteInFiles: formDisableAutocomplete | |
| 95 | + .split(",") | |
| 96 | + .map((val) => val.trim()) | |
| 97 | + .filter((val) => !!val), | |
| 98 | + }); | |
| 99 | + }; | |
| 100 | + | |
| 101 | + const hasContinueEmail = isContinueTeamMember( | |
| 102 | + (session as HubSessionInfo)?.account?.id, | |
| 103 | + ); | |
| 104 | + | |
| 105 | + const disableTelemetryToggle = | |
| 106 | + currentOrg?.policy?.allowAnonymousTelemetry === false; | |
| 107 | + | |
| 108 | + return ( | |
| 109 | + <div> | |
| 110 | + <div className="flex flex-col"> | |
| 111 | + <ConfigHeader title="User Settings" /> | |
| 112 | + <div className="space-y-6"> | |
| 113 | + {/* Chat Interface Settings */} | |
| 114 | + <div> | |
| 115 | + <ConfigHeader title="Chat" variant="sm" /> | |
| 116 | + <Card> | |
| 117 | + <div className="flex flex-col gap-4"> | |
| 118 | + <UserSetting | |
| 119 | + type="toggle" | |
| 120 | + title="Show Session Tabs" | |
| 121 | + description="Displays tabs above the chat as an alternative way to organize and access your sessions." | |
| 122 | + value={showSessionTabs} | |
| 123 | + onChange={(value) => handleUpdate({ showSessionTabs: value })} | |
| 124 | + /> | |
| 125 | + <UserSetting | |
| 126 | + type="toggle" | |
| 127 | + title="Wrap Codeblocks" | |
| 128 | + description="Wraps long lines in code blocks instead of showing horizontal scroll." | |
| 129 | + value={codeWrap} | |
| 130 | + onChange={(value) => handleUpdate({ codeWrap: value })} | |
| 131 | + /> | |
| 132 | + <UserSetting | |
| 133 | + type="toggle" | |
| 134 | + title="Show Chat Scrollbar" | |
| 135 | + description="Enables a scrollbar in the chat window." | |
| 136 | + value={showChatScrollbar} | |
| 137 | + onChange={(value) => | |
| 138 | + handleUpdate({ showChatScrollbar: value }) | |
| 139 | + } | |
| 140 | + /> | |
| 141 | + <UserSetting | |
| 142 | + type="toggle" | |
| 143 | + title="Text-to-Speech Output" | |
| 144 | + description="Reads LLM responses aloud with TTS." | |
| 145 | + value={readResponseTTS} | |
| 146 | + onChange={(value) => handleUpdate({ readResponseTTS: value })} | |
| 147 | + /> | |
| 148 | + <UserSetting | |
| 149 | + type="toggle" | |
| 150 | + title="Enable Session Titles" | |
| 151 | + description="Generates summary titles for each chat session after the first message, using the current Chat model." | |
| 152 | + value={!disableSessionTitles} | |
| 153 | + onChange={(value) => | |
| 154 | + handleUpdate({ disableSessionTitles: !value }) | |
| 155 | + } | |
| 156 | + /> | |
| 157 | + <UserSetting | |
| 158 | + type="toggle" | |
| 159 | + title="Format Markdown" | |
| 160 | + description="If off, shows responses as raw text." | |
| 161 | + value={!displayRawMarkdown} | |
| 162 | + onChange={(value) => | |
| 163 | + handleUpdate({ displayRawMarkdown: !value }) | |
| 164 | + } | |
| 165 | + /> | |
| 166 | + <UserSetting | |
| 167 | + type="toggle" | |
| 168 | + title="Auto-Accept Agent Edits" | |
| 169 | + description="Diffs generated by the edit tool are automatically accepted and Agent proceeds with the next conversational turn." | |
| 170 | + value={autoAcceptEditToolDiffs} | |
| 171 | + onChange={(value) => | |
| 172 | + handleUpdate({ autoAcceptEditToolDiffs: value }) | |
| 173 | + } | |
| 174 | + /> | |
| 175 | + </div> | |
| 176 | + </Card> | |
| 177 | + </div> | |
| 178 | + | |
| 179 | + {/* Telemetry Settings */} | |
| 180 | + <div> | |
| 181 | + <ConfigHeader title="Telemetry" variant="sm" /> | |
| 182 | + <Card> | |
| 183 | + <div className="flex flex-col gap-4"> | |
| 184 | + <UserSetting | |
| 185 | + type="toggle" | |
| 186 | + title="Allow Anonymous Telemetry" | |
| 187 | + description="Allows Continue to send anonymous telemetry." | |
| 188 | + value={allowAnonymousTelemetry} | |
| 189 | + disabled={disableTelemetryToggle} | |
| 190 | + onChange={(value) => | |
| 191 | + handleUpdate({ allowAnonymousTelemetry: value }) | |
| 192 | + } | |
| 193 | + /> | |
| 194 | + </div> | |
| 195 | + </Card> | |
| 196 | + </div> | |
| 197 | + | |
| 198 | + {/* Appearance Settings */} | |
| 199 | + <div> | |
| 200 | + <ConfigHeader title="Appearance" variant="sm" /> | |
| 201 | + <Card> | |
| 202 | + <div className="flex flex-col gap-4"> | |
| 203 | + <UserSetting | |
| 204 | + type="number" | |
| 205 | + title="Font Size" | |
| 206 | + description="Specifies base font size for UI elements." | |
| 207 | + value={fontSize} | |
| 208 | + onChange={(val) => { | |
| 209 | + setLocalStorage("fontSize", val); | |
| 210 | + handleUpdate({ fontSize: val }); | |
| 211 | + }} | |
| 212 | + min={7} | |
| 213 | + max={50} | |
| 214 | + /> | |
| 215 | + </div> | |
| 216 | + </Card> | |
| 217 | + </div> | |
| 218 | + | |
| 219 | + {/* Autocomplete Settings */} | |
| 220 | + <div> | |
| 221 | + <ConfigHeader title="Autocomplete" variant="sm" /> | |
| 222 | + <Card> | |
| 223 | + <div className="flex flex-col gap-4"> | |
| 224 | + <UserSetting | |
| 225 | + type="select" | |
| 226 | + title="Multiline Autocompletions" | |
| 227 | + description="Controls multiline completions for autocomplete." | |
| 228 | + value={useAutocompleteMultilineCompletions} | |
| 229 | + onChange={(value) => | |
| 230 | + handleUpdate({ | |
| 231 | + useAutocompleteMultilineCompletions: value as | |
| 232 | + | "auto" | |
| 233 | + | "always" | |
| 234 | + | "never", | |
| 235 | + }) | |
| 236 | + } | |
| 237 | + options={[ | |
| 238 | + { label: "Auto", value: "auto" }, | |
| 239 | + { label: "Always", value: "always" }, | |
| 240 | + { label: "Never", value: "never" }, | |
| 241 | + ]} | |
| 242 | + /> | |
| 243 | + <UserSetting | |
| 244 | + type="number" | |
| 245 | + title="Autocomplete Timeout (ms)" | |
| 246 | + description="Maximum time in milliseconds for autocomplete request/retrieval." | |
| 247 | + value={modelTimeout} | |
| 248 | + onChange={(val) => handleUpdate({ modelTimeout: val })} | |
| 249 | + min={100} | |
| 250 | + max={5000} | |
| 251 | + /> | |
| 252 | + <UserSetting | |
| 253 | + type="number" | |
| 254 | + title="Autocomplete Debounce (ms)" | |
| 255 | + description="Minimum time in milliseconds to trigger an autocomplete request after a change." | |
| 256 | + value={debounceDelay} | |
| 257 | + onChange={(val) => handleUpdate({ debounceDelay: val })} | |
| 258 | + min={0} | |
| 259 | + max={2500} | |
| 260 | + /> | |
| 261 | + <UserSetting | |
| 262 | + type="input" | |
| 263 | + title="Disable autocomplete in files" | |
| 264 | + description="List of comma-separated glob pattern to disable autocomplete in matching files." | |
| 265 | + placeholder="**/*.(txt,md)" | |
| 266 | + value={formDisableAutocomplete} | |
| 267 | + onChange={setFormDisableAutocomplete} | |
| 268 | + onSubmit={handleDisableAutocompleteSubmit} | |
| 269 | + onCancel={cancelChangeDisableAutocomplete} | |
| 270 | + isDirty={ | |
| 271 | + formDisableAutocomplete !== disableAutocompleteInFiles | |
| 272 | + } | |
| 273 | + isValid={formDisableAutocomplete.trim() !== ""} | |
| 274 | + /> | |
| 275 | + </div> | |
| 276 | + </Card> | |
| 277 | + </div> | |
| 278 | + | |
| 279 | + {/* Experimental Settings */} | |
| 280 | + <div> | |
| 281 | + <ConfigHeader title="Experimental" variant="sm" /> | |
| 282 | + <Card> | |
| 283 | + <Toggle | |
| 284 | + isOpen={showExperimental} | |
| 285 | + onToggle={() => setShowExperimental(!showExperimental)} | |
| 286 | + title="Show Experimental Settings" | |
| 287 | + > | |
| 288 | + <div className="flex flex-col gap-x-1 gap-y-4"> | |
| 289 | + <UserSetting | |
| 290 | + type="toggle" | |
| 291 | + title="Add Current File by Default" | |
| 292 | + description=" the currently open file is added as context in every new conversation." | |
| 293 | + value={useCurrentFileAsContext} | |
| 294 | + onChange={(value) => | |
| 295 | + handleUpdate({ useCurrentFileAsContext: value }) | |
| 296 | + } | |
| 297 | + /> | |
| 298 | + <UserSetting | |
| 299 | + type="toggle" | |
| 300 | + title="Enable experimental tools" | |
| 301 | + description=" enables access to experimental tools that are still in development." | |
| 302 | + value={enableExperimentalTools} | |
| 303 | + onChange={(value) => | |
| 304 | + handleUpdate({ enableExperimentalTools: value }) | |
| 305 | + } | |
| 306 | + /> | |
| 307 | + <UserSetting | |
| 308 | + type="toggle" | |
| 309 | + title="Only use system message tools" | |
| 310 | + description=" Continue will not attempt to use native tool calling and will only use system message tools." | |
| 311 | + value={onlyUseSystemMessageTools} | |
| 312 | + onChange={(value) => | |
| 313 | + handleUpdate({ onlyUseSystemMessageTools: value }) | |
| 314 | + } | |
| 315 | + /> | |
| 316 | + <UserSetting | |
| 317 | + type="toggle" | |
| 318 | + title="@Codebase: use tool calling only" | |
| 319 | + description=" @codebase context provider will only use tool calling for code retrieval." | |
| 320 | + value={codebaseToolCallingOnly} | |
| 321 | + onChange={(value) => | |
| 322 | + handleUpdate({ codebaseToolCallingOnly: value }) | |
| 323 | + } | |
| 324 | + /> | |
| 325 | + <UserSetting | |
| 326 | + type="toggle" | |
| 327 | + title="Stream after tool rejection" | |
| 328 | + description=" streaming will continue after the tool call is rejected." | |
| 329 | + value={continueAfterToolRejection} | |
| 330 | + onChange={(value) => | |
| 331 | + handleUpdate({ continueAfterToolRejection: value }) | |
| 332 | + } | |
| 333 | + /> | |
| 334 | + | |
| 335 | + {hasContinueEmail && ( | |
| 336 | + <ContinueFeaturesMenu | |
| 337 | + enableStaticContextualization={ | |
| 338 | + enableStaticContextualization | |
| 339 | + } | |
| 340 | + handleEnableStaticContextualizationToggle={ | |
| 341 | + handleEnableStaticContextualizationToggle | |
| 342 | + } | |
| 343 | + /> | |
| 344 | + )} | |
| 345 | + </div> | |
| 346 | + </Toggle> | |
| 347 | + </Card> | |
| 348 | + </div> | |
| 349 | + </div> | |
| 350 | + </div> | |
| 351 | + </div> | |
| 352 | + ); | |
| 353 | +} |
added gui/src/pages/config/sections/docs/DocsDetailsDialog.tsx +161 −0
| @@ -0,0 +1,161 @@ | ||
| 1 | +import { DocsIndexingDetails } from "core"; | |
| 2 | +import { useCallback, useContext, useEffect, useState } from "react"; | |
| 3 | +import { useDispatch } from "react-redux"; | |
| 4 | +import { Tooltip } from "react-tooltip"; | |
| 5 | +import { SecondaryButton } from "../../../../components"; | |
| 6 | +import { IdeMessengerContext } from "../../../../context/IdeMessenger"; | |
| 7 | +import { | |
| 8 | + setDialogMessage, | |
| 9 | + setShowDialog, | |
| 10 | +} from "../../../../redux/slices/uiSlice"; | |
| 11 | + | |
| 12 | +interface DocsDetailsDialogProps { | |
| 13 | + startUrl: string; | |
| 14 | +} | |
| 15 | + | |
| 16 | +function DocsDetailsDialog({ startUrl }: DocsDetailsDialogProps) { | |
| 17 | + const dispatch = useDispatch(); | |
| 18 | + | |
| 19 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 20 | + | |
| 21 | + const closeDialog = () => { | |
| 22 | + dispatch(setShowDialog(false)); | |
| 23 | + dispatch(setDialogMessage(undefined)); | |
| 24 | + }; | |
| 25 | + | |
| 26 | + const [isLoading, setIsLoading] = useState(false); | |
| 27 | + const [isError, setIsError] = useState(false); | |
| 28 | + const [data, setData] = useState<DocsIndexingDetails | undefined>(undefined); | |
| 29 | + | |
| 30 | + const fetchData = useCallback(async () => { | |
| 31 | + setIsLoading(true); | |
| 32 | + setIsError(false); | |
| 33 | + | |
| 34 | + try { | |
| 35 | + const response = await ideMessenger.request("docs/getDetails", { | |
| 36 | + startUrl, | |
| 37 | + }); | |
| 38 | + if (response.status === "error") { | |
| 39 | + throw new Error(response.error); | |
| 40 | + } | |
| 41 | + setData(response.content); | |
| 42 | + } catch (error) { | |
| 43 | + setIsError(true); | |
| 44 | + } finally { | |
| 45 | + setIsLoading(false); | |
| 46 | + } | |
| 47 | + }, []); | |
| 48 | + | |
| 49 | + useEffect(() => { | |
| 50 | + void fetchData(); | |
| 51 | + }, []); | |
| 52 | + | |
| 53 | + let comp = <div>Loading...</div>; | |
| 54 | + if (!isLoading) { | |
| 55 | + if (isError) { | |
| 56 | + comp = ( | |
| 57 | + <div> | |
| 58 | + <div>Error fetching docs details</div> | |
| 59 | + <SecondaryButton onClick={fetchData}>Try again</SecondaryButton> | |
| 60 | + </div> | |
| 61 | + ); | |
| 62 | + } | |
| 63 | + if (data) { | |
| 64 | + comp = ( | |
| 65 | + <div className="flex flex-col gap-0.5"> | |
| 66 | + <p className="m-0 mt-2 p-0 text-stone-500">{`Title: ${data.config.title}`}</p> | |
| 67 | + {!data.chunks?.length ? ( | |
| 68 | + <div>No article chunks</div> | |
| 69 | + ) : ( | |
| 70 | + <div className="relative mt-2 h-[300px] overflow-auto"> | |
| 71 | + <table className="w-full border-collapse"> | |
| 72 | + <thead className="bg-vsc-background sticky top-0 text-left"> | |
| 73 | + <tr> | |
| 74 | + <th className="py-1">Filepath</th> | |
| 75 | + <th>Content</th> | |
| 76 | + </tr> | |
| 77 | + </thead> | |
| 78 | + <tbody className="h-20 overflow-y-scroll"> | |
| 79 | + {data.chunks.map((chunk, i) => { | |
| 80 | + const contentToolTipId = `docs-content-peek-${i}`; | |
| 81 | + const urlToolTipId = `docs-url-peek-${i}`; | |
| 82 | + return ( | |
| 83 | + <> | |
| 84 | + <tr key={i} className=""> | |
| 85 | + <td | |
| 86 | + className="cursor-pointer px-1" | |
| 87 | + data-tooltip-id={urlToolTipId} | |
| 88 | + data-tooltip-delay-show={500} | |
| 89 | + > | |
| 90 | + <span className="truncate-start max-w-[200px]"> | |
| 91 | + {chunk.filepath} | |
| 92 | + </span> | |
| 93 | + </td> | |
| 94 | + <td | |
| 95 | + className="cursor-pointer px-1" | |
| 96 | + data-tooltip-id={contentToolTipId} | |
| 97 | + data-tooltip-delay-show={500} | |
| 98 | + > | |
| 99 | + <span className="line-clamp-1"> | |
| 100 | + {chunk.content} | |
| 101 | + </span> | |
| 102 | + </td> | |
| 103 | + </tr> | |
| 104 | + </> | |
| 105 | + ); | |
| 106 | + })} | |
| 107 | + </tbody> | |
| 108 | + </table> | |
| 109 | + {/* Rending tooltips here because div can't be child of tbody apparently */} | |
| 110 | + {data.chunks.map((chunk, i) => { | |
| 111 | + const contentToolTipId = `docs-content-peek-${i}`; | |
| 112 | + const urlToolTipId = `docs-url-peek-${i}`; | |
| 113 | + return ( | |
| 114 | + <> | |
| 115 | + <Tooltip | |
| 116 | + key={urlToolTipId} | |
| 117 | + id={urlToolTipId} | |
| 118 | + place="top" | |
| 119 | + className="max-w-full" | |
| 120 | + > | |
| 121 | + {chunk.filepath} | |
| 122 | + </Tooltip> | |
| 123 | + <Tooltip | |
| 124 | + key={contentToolTipId} | |
| 125 | + id={contentToolTipId} | |
| 126 | + place="top" | |
| 127 | + className="max-h-[300px] max-w-[170px] overflow-y-auto" | |
| 128 | + > | |
| 129 | + {chunk.content} | |
| 130 | + </Tooltip> | |
| 131 | + </> | |
| 132 | + ); | |
| 133 | + })} | |
| 134 | + </div> | |
| 135 | + )} | |
| 136 | + </div> | |
| 137 | + ); | |
| 138 | + } | |
| 139 | + } | |
| 140 | + | |
| 141 | + return ( | |
| 142 | + <div className="px-2 py-4 sm:px-4"> | |
| 143 | + <h3>Docs index</h3> | |
| 144 | + <p | |
| 145 | + className="text-lightgray m-0 mt-1 cursor-pointer p-0 hover:underline" | |
| 146 | + onClick={(e) => { | |
| 147 | + e.stopPropagation(); | |
| 148 | + ideMessenger.post("openUrl", startUrl); | |
| 149 | + }} | |
| 150 | + > | |
| 151 | + {startUrl} | |
| 152 | + </p> | |
| 153 | + {comp} | |
| 154 | + <div className="flex flex-row justify-end"> | |
| 155 | + <SecondaryButton onClick={closeDialog}>Close</SecondaryButton> | |
| 156 | + </div> | |
| 157 | + </div> | |
| 158 | + ); | |
| 159 | +} | |
| 160 | + | |
| 161 | +export default DocsDetailsDialog; |
added gui/src/pages/config/sections/docs/DocsIndexingPeeks.tsx +70 −0
| @@ -0,0 +1,70 @@ | ||
| 1 | +import { IndexingStatus } from "core"; | |
| 2 | +import { useMemo } from "react"; | |
| 3 | +import { useDispatch } from "react-redux"; | |
| 4 | +import { useNavigate } from "react-router-dom"; | |
| 5 | +import { | |
| 6 | + setDialogMessage, | |
| 7 | + setShowDialog, | |
| 8 | +} from "../../../../redux/slices/uiSlice"; | |
| 9 | + | |
| 10 | +export interface DocsIndexingPeekProps { | |
| 11 | + status: IndexingStatus; | |
| 12 | +} | |
| 13 | + | |
| 14 | +function DocsIndexingPeek({ status }: DocsIndexingPeekProps) { | |
| 15 | + const navigate = useNavigate(); | |
| 16 | + const dispatch = useDispatch(); | |
| 17 | + | |
| 18 | + const progressPercentage = useMemo(() => { | |
| 19 | + return Math.min(100, Math.max(0, status.progress * 100)); | |
| 20 | + }, [status.progress]); | |
| 21 | + | |
| 22 | + return ( | |
| 23 | + <div | |
| 24 | + className="text-lightgray flex cursor-pointer flex-row items-center gap-2 rounded-md px-1 hover:bg-gray-700/10" | |
| 25 | + onClick={() => { | |
| 26 | + // navigate("/more"); TODO | |
| 27 | + dispatch(setShowDialog(false)); | |
| 28 | + dispatch(setDialogMessage(undefined)); | |
| 29 | + }} | |
| 30 | + > | |
| 31 | + <p className="text-lightgray m-0 p-0 group-hover:underline"> | |
| 32 | + {status.title} | |
| 33 | + </p> | |
| 34 | + <div className="my-2 h-1.5 flex-1 rounded-md border border-solid border-gray-400"> | |
| 35 | + <div | |
| 36 | + className={`h-full rounded-lg bg-stone-500 transition-all duration-200 ease-in-out`} | |
| 37 | + style={{ | |
| 38 | + width: `${progressPercentage}%`, | |
| 39 | + }} | |
| 40 | + /> | |
| 41 | + </div> | |
| 42 | + <div className="xs:flex text-lightgray hidden flex-row items-center gap-1"> | |
| 43 | + <span className="text-xs no-underline"> | |
| 44 | + {progressPercentage.toFixed(0)}% | |
| 45 | + </span> | |
| 46 | + {/* <ArrowPathIcon | |
| 47 | + className={`animate-spin-slow inline-block h-4 w-4 text-lightgray`} | |
| 48 | + ></ArrowPathIcon> */} | |
| 49 | + </div> | |
| 50 | + </div> | |
| 51 | + ); | |
| 52 | +} | |
| 53 | + | |
| 54 | +interface DocsIndexingPeeksProps { | |
| 55 | + statuses: IndexingStatus[]; | |
| 56 | +} | |
| 57 | + | |
| 58 | +function DocsIndexingPeekList({ statuses }: DocsIndexingPeeksProps) { | |
| 59 | + return ( | |
| 60 | + <div className="border-vsc-input-border mt-2 flex flex-col border-0 border-t border-solid pt-2"> | |
| 61 | + <div className="max-h-[100px] overflow-y-auto pr-2"> | |
| 62 | + {statuses.map((status) => { | |
| 63 | + return <DocsIndexingPeek key={status.id} status={status} />; | |
| 64 | + })} | |
| 65 | + </div> | |
| 66 | + </div> | |
| 67 | + ); | |
| 68 | +} | |
| 69 | + | |
| 70 | +export default DocsIndexingPeekList; |
added gui/src/pages/config/sections/docs/DocsIndexingStatus.test.tsx +367 −0
| @@ -0,0 +1,367 @@ | ||
| 1 | +import { | |
| 2 | + act, | |
| 3 | + fireEvent, | |
| 4 | + render, | |
| 5 | + screen, | |
| 6 | + waitFor, | |
| 7 | +} from "@testing-library/react"; | |
| 8 | +import { SiteIndexingConfig } from "core"; | |
| 9 | +import { Provider } from "react-redux"; | |
| 10 | +import { beforeEach, describe, expect, it, vi } from "vitest"; | |
| 11 | +import { AuthProvider } from "../../../../context/Auth"; | |
| 12 | +import { IdeMessengerContext } from "../../../../context/IdeMessenger"; | |
| 13 | +import { createMockStore } from "../../../../util/test/mockStore"; | |
| 14 | +import DocsIndexingStatus from "./DocsIndexingStatus"; | |
| 15 | + | |
| 16 | +describe("DocsIndexingStatus", () => { | |
| 17 | + const mockDocConfig: SiteIndexingConfig = { | |
| 18 | + startUrl: "https://example.com", | |
| 19 | + title: "Example Docs", | |
| 20 | + }; | |
| 21 | + | |
| 22 | + const mockDocFromYaml = { | |
| 23 | + startUrl: "https://example.com", | |
| 24 | + title: "Example Docs", | |
| 25 | + }; | |
| 26 | + | |
| 27 | + const renderComponent = async ( | |
| 28 | + props: any = {}, | |
| 29 | + storeState = {}, | |
| 30 | + mockIdeMessengerSetup?: (mock: any) => void, | |
| 31 | + ) => { | |
| 32 | + const { mockIdeMessenger, ...store } = createMockStore(storeState); | |
| 33 | + | |
| 34 | + // Configure the mockIdeMessenger for this test | |
| 35 | + if (mockIdeMessengerSetup) { | |
| 36 | + mockIdeMessengerSetup(mockIdeMessenger); | |
| 37 | + } else { | |
| 38 | + mockIdeMessenger.request.mockResolvedValue({ | |
| 39 | + status: "success", | |
| 40 | + content: ["page1.html", "page2.html"], | |
| 41 | + }); | |
| 42 | + } | |
| 43 | + | |
| 44 | + const result = await act(async () => | |
| 45 | + render( | |
| 46 | + <Provider store={store}> | |
| 47 | + <IdeMessengerContext.Provider value={mockIdeMessenger}> | |
| 48 | + <AuthProvider> | |
| 49 | + <DocsIndexingStatus | |
| 50 | + docConfig={mockDocConfig} | |
| 51 | + docFromYaml={mockDocFromYaml} | |
| 52 | + {...props} | |
| 53 | + /> | |
| 54 | + </AuthProvider> | |
| 55 | + </IdeMessengerContext.Provider> | |
| 56 | + </Provider>, | |
| 57 | + ), | |
| 58 | + ); | |
| 59 | + | |
| 60 | + return { ...result, mockIdeMessenger }; | |
| 61 | + }; | |
| 62 | + | |
| 63 | + beforeEach(() => { | |
| 64 | + vi.clearAllMocks(); | |
| 65 | + }); | |
| 66 | + | |
| 67 | + it("renders doc title and basic structure", async () => { | |
| 68 | + await renderComponent(); | |
| 69 | + expect(screen.getByText("Example Docs")).toBeInTheDocument(); | |
| 70 | + }); | |
| 71 | + | |
| 72 | + it("renders startUrl when title is not provided", async () => { | |
| 73 | + const configWithoutTitle = { ...mockDocConfig, title: undefined }; | |
| 74 | + await renderComponent({ docConfig: configWithoutTitle }); | |
| 75 | + expect(screen.getByText("https://example.com")).toBeInTheDocument(); | |
| 76 | + }); | |
| 77 | + | |
| 78 | + it("shows progress percentage when indexing", async () => { | |
| 79 | + const storeState = { | |
| 80 | + indexing: { | |
| 81 | + indexing: { | |
| 82 | + statuses: { | |
| 83 | + "https://example.com": { | |
| 84 | + status: "indexing", | |
| 85 | + progress: 0.45, | |
| 86 | + description: "Indexing pages...", | |
| 87 | + }, | |
| 88 | + }, | |
| 89 | + }, | |
| 90 | + }, | |
| 91 | + }; | |
| 92 | + | |
| 93 | + await renderComponent({}, storeState); | |
| 94 | + expect(screen.getByText("45%")).toBeInTheDocument(); | |
| 95 | + }); | |
| 96 | + | |
| 97 | + it("shows stop icon when indexing", async () => { | |
| 98 | + const storeState = { | |
| 99 | + indexing: { | |
| 100 | + indexing: { | |
| 101 | + statuses: { | |
| 102 | + "https://example.com": { | |
| 103 | + status: "indexing", | |
| 104 | + progress: 0.25, | |
| 105 | + }, | |
| 106 | + }, | |
| 107 | + }, | |
| 108 | + }, | |
| 109 | + }; | |
| 110 | + | |
| 111 | + await renderComponent({}, storeState); | |
| 112 | + const stopIcon = screen.getByTestId("stop-indexing"); | |
| 113 | + expect(stopIcon).toBeInTheDocument(); | |
| 114 | + }); | |
| 115 | + | |
| 116 | + it("calls abort when stop icon is clicked", async () => { | |
| 117 | + const storeState = { | |
| 118 | + indexing: { | |
| 119 | + indexing: { | |
| 120 | + statuses: { | |
| 121 | + "https://example.com": { | |
| 122 | + status: "indexing", | |
| 123 | + progress: 0.25, | |
| 124 | + }, | |
| 125 | + }, | |
| 126 | + }, | |
| 127 | + }, | |
| 128 | + }; | |
| 129 | + | |
| 130 | + const { mockIdeMessenger } = await renderComponent({}, storeState); | |
| 131 | + const stopButton = screen.getByTestId("stop-indexing"); | |
| 132 | + fireEvent.click(stopButton); | |
| 133 | + | |
| 134 | + expect(mockIdeMessenger.post).toHaveBeenCalledWith("indexing/abort", { | |
| 135 | + type: "docs", | |
| 136 | + id: "https://example.com", | |
| 137 | + }); | |
| 138 | + }); | |
| 139 | + | |
| 140 | + it("shows reindex icon when status is complete", async () => { | |
| 141 | + const storeState = { | |
| 142 | + indexing: { | |
| 143 | + indexing: { | |
| 144 | + statuses: { | |
| 145 | + "https://example.com": { | |
| 146 | + status: "complete", | |
| 147 | + progress: 1, | |
| 148 | + }, | |
| 149 | + }, | |
| 150 | + }, | |
| 151 | + }, | |
| 152 | + }; | |
| 153 | + | |
| 154 | + await renderComponent({}, storeState); | |
| 155 | + const reindexButton = screen.getByTestId("reindex-docs"); | |
| 156 | + expect(reindexButton).toBeInTheDocument(); | |
| 157 | + }); | |
| 158 | + | |
| 159 | + it("calls reindex when reindex icon is clicked", async () => { | |
| 160 | + const storeState = { | |
| 161 | + indexing: { | |
| 162 | + indexing: { | |
| 163 | + statuses: { | |
| 164 | + "https://example.com": { | |
| 165 | + status: "complete", | |
| 166 | + progress: 1, | |
| 167 | + }, | |
| 168 | + }, | |
| 169 | + }, | |
| 170 | + }, | |
| 171 | + }; | |
| 172 | + | |
| 173 | + const { mockIdeMessenger } = await renderComponent({}, storeState); | |
| 174 | + const reindexButton = screen.getByTestId("reindex-docs"); | |
| 175 | + fireEvent.click(reindexButton); | |
| 176 | + | |
| 177 | + expect(mockIdeMessenger.post).toHaveBeenCalledWith("indexing/reindex", { | |
| 178 | + type: "docs", | |
| 179 | + id: "https://example.com", | |
| 180 | + }); | |
| 181 | + }); | |
| 182 | + | |
| 183 | + it("opens URL when title is clicked and status has URL", async () => { | |
| 184 | + const storeState = { | |
| 185 | + indexing: { | |
| 186 | + indexing: { | |
| 187 | + statuses: { | |
| 188 | + "https://example.com": { | |
| 189 | + status: "complete", | |
| 190 | + url: "https://example.com/docs", | |
| 191 | + }, | |
| 192 | + }, | |
| 193 | + }, | |
| 194 | + }, | |
| 195 | + }; | |
| 196 | + | |
| 197 | + const { mockIdeMessenger } = await renderComponent({}, storeState); | |
| 198 | + const titleElement = screen.getByText("Example Docs"); | |
| 199 | + fireEvent.click(titleElement); | |
| 200 | + | |
| 201 | + expect(mockIdeMessenger.post).toHaveBeenCalledWith( | |
| 202 | + "openUrl", | |
| 203 | + "https://example.com/docs", | |
| 204 | + ); | |
| 205 | + }); | |
| 206 | + | |
| 207 | + it("fetches indexed pages when status becomes complete", async () => { | |
| 208 | + const storeState = { | |
| 209 | + indexing: { | |
| 210 | + indexing: { | |
| 211 | + statuses: { | |
| 212 | + "https://example.com": { | |
| 213 | + status: "complete", | |
| 214 | + progress: 1, | |
| 215 | + }, | |
| 216 | + }, | |
| 217 | + }, | |
| 218 | + }, | |
| 219 | + }; | |
| 220 | + | |
| 221 | + const { mockIdeMessenger } = await renderComponent({}, storeState); | |
| 222 | + | |
| 223 | + await waitFor(() => { | |
| 224 | + expect(mockIdeMessenger.request).toHaveBeenCalledWith( | |
| 225 | + "docs/getIndexedPages", | |
| 226 | + { | |
| 227 | + startUrl: "https://example.com", | |
| 228 | + }, | |
| 229 | + ); | |
| 230 | + }); | |
| 231 | + }); | |
| 232 | + | |
| 233 | + it("displays indexed pages count when available", async () => { | |
| 234 | + const storeState = { | |
| 235 | + indexing: { | |
| 236 | + indexing: { | |
| 237 | + statuses: { | |
| 238 | + "https://example.com": { | |
| 239 | + status: "complete", | |
| 240 | + progress: 1, | |
| 241 | + }, | |
| 242 | + }, | |
| 243 | + }, | |
| 244 | + }, | |
| 245 | + }; | |
| 246 | + | |
| 247 | + await renderComponent({}, storeState, (mockIdeMessenger) => { | |
| 248 | + mockIdeMessenger.request.mockResolvedValue({ | |
| 249 | + status: "success", | |
| 250 | + content: ["page1.html", "page2.html", "page3.html"], | |
| 251 | + }); | |
| 252 | + }); | |
| 253 | + | |
| 254 | + await waitFor(() => { | |
| 255 | + expect(screen.getByText("3 pages indexed")).toBeInTheDocument(); | |
| 256 | + }); | |
| 257 | + }); | |
| 258 | + | |
| 259 | + it("shows singular page text for one page", async () => { | |
| 260 | + const storeState = { | |
| 261 | + indexing: { | |
| 262 | + indexing: { | |
| 263 | + statuses: { | |
| 264 | + "https://example.com": { | |
| 265 | + status: "complete", | |
| 266 | + progress: 1, | |
| 267 | + }, | |
| 268 | + }, | |
| 269 | + }, | |
| 270 | + }, | |
| 271 | + }; | |
| 272 | + | |
| 273 | + await renderComponent({}, storeState, (mockIdeMessenger) => { | |
| 274 | + mockIdeMessenger.request.mockResolvedValue({ | |
| 275 | + status: "success", | |
| 276 | + content: ["page1.html"], | |
| 277 | + }); | |
| 278 | + }); | |
| 279 | + | |
| 280 | + await waitFor(() => { | |
| 281 | + expect(screen.getByText("1 page indexed")).toBeInTheDocument(); | |
| 282 | + }); | |
| 283 | + }); | |
| 284 | + | |
| 285 | + it("shows status description when not complete", async () => { | |
| 286 | + const storeState = { | |
| 287 | + indexing: { | |
| 288 | + indexing: { | |
| 289 | + statuses: { | |
| 290 | + "https://example.com": { | |
| 291 | + status: "indexing", | |
| 292 | + progress: 0.5, | |
| 293 | + description: "Processing documentation...", | |
| 294 | + }, | |
| 295 | + }, | |
| 296 | + }, | |
| 297 | + }, | |
| 298 | + }; | |
| 299 | + | |
| 300 | + await renderComponent({}, storeState); | |
| 301 | + expect(screen.getByText("Processing documentation...")).toBeInTheDocument(); | |
| 302 | + }); | |
| 303 | + | |
| 304 | + it("handles error when fetching indexed pages", async () => { | |
| 305 | + const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {}); | |
| 306 | + | |
| 307 | + const storeState = { | |
| 308 | + indexing: { | |
| 309 | + indexing: { | |
| 310 | + statuses: { | |
| 311 | + "https://example.com": { | |
| 312 | + status: "complete", | |
| 313 | + progress: 1, | |
| 314 | + }, | |
| 315 | + }, | |
| 316 | + }, | |
| 317 | + }, | |
| 318 | + }; | |
| 319 | + | |
| 320 | + await renderComponent({}, storeState, (mockIdeMessenger) => { | |
| 321 | + mockIdeMessenger.request.mockResolvedValue({ | |
| 322 | + status: "error", | |
| 323 | + error: "Failed to fetch pages", | |
| 324 | + }); | |
| 325 | + }); | |
| 326 | + | |
| 327 | + await waitFor(() => { | |
| 328 | + expect(consoleSpy).toHaveBeenCalledWith( | |
| 329 | + expect.stringContaining( | |
| 330 | + "Unable to fetch pages list for https://example.com", | |
| 331 | + ), | |
| 332 | + ); | |
| 333 | + }); | |
| 334 | + | |
| 335 | + consoleSpy.mockRestore(); | |
| 336 | + }); | |
| 337 | + | |
| 338 | + it("returns null when hasDeleted is true", async () => { | |
| 339 | + const { container } = await renderComponent(); | |
| 340 | + | |
| 341 | + // Simulate deletion state by accessing the component's internal state | |
| 342 | + // In a real scenario, this would be tested through user interaction | |
| 343 | + expect(container.firstChild).not.toBeNull(); | |
| 344 | + }); | |
| 345 | + | |
| 346 | + it("shows loading text when pages are being fetched", async () => { | |
| 347 | + const storeState = { | |
| 348 | + indexing: { | |
| 349 | + indexing: { | |
| 350 | + statuses: { | |
| 351 | + "https://example.com": { | |
| 352 | + status: "complete", | |
| 353 | + progress: 1, | |
| 354 | + }, | |
| 355 | + }, | |
| 356 | + }, | |
| 357 | + }, | |
| 358 | + }; | |
| 359 | + | |
| 360 | + await renderComponent({}, storeState, (mockIdeMessenger) => { | |
| 361 | + // Mock a delayed response to keep in loading state | |
| 362 | + mockIdeMessenger.request.mockImplementation(() => new Promise(() => {})); | |
| 363 | + }); | |
| 364 | + | |
| 365 | + expect(screen.getByText("Loading site info...")).toBeInTheDocument(); | |
| 366 | + }); | |
| 367 | +}); |
added gui/src/pages/config/sections/docs/DocsIndexingStatus.tsx +243 −0
| @@ -0,0 +1,243 @@ | ||
| 1 | +import { ConfigYaml } from "@continuedev/config-yaml"; | |
| 2 | +import { ArrowPathIcon, StopIcon } from "@heroicons/react/24/outline"; | |
| 3 | +import { SiteIndexingConfig } from "core"; | |
| 4 | +import { useContext, useEffect, useMemo, useState } from "react"; | |
| 5 | +import { IdeMessengerContext } from "../../../../context/IdeMessenger"; | |
| 6 | +import { useAppDispatch, useAppSelector } from "../../../../redux/hooks"; | |
| 7 | +import { updateIndexingStatus } from "../../../../redux/slices/indexingSlice"; | |
| 8 | +import { | |
| 9 | + setDialogMessage, | |
| 10 | + setShowDialog, | |
| 11 | +} from "../../../../redux/slices/uiSlice"; | |
| 12 | +import { fontSize } from "../../../../util"; | |
| 13 | +import ConfirmationDialog from "../../../../components/dialogs/ConfirmationDialog"; | |
| 14 | +import { ToolTip } from "../../../../components/gui/Tooltip"; | |
| 15 | +import EditBlockButton from "../../../../components/mainInput/Lump/EditBlockButton"; | |
| 16 | +import { IndexedPagesTooltip } from "./IndexedPagesTooltip"; | |
| 17 | +import { StatusIndicator } from "./StatusIndicator"; | |
| 18 | + | |
| 19 | +interface IndexingStatusViewerProps { | |
| 20 | + docConfig: SiteIndexingConfig; | |
| 21 | + docFromYaml?: NonNullable<ConfigYaml["docs"]>[number]; | |
| 22 | +} | |
| 23 | + | |
| 24 | +function DocsIndexingStatus({ | |
| 25 | + docConfig, | |
| 26 | + docFromYaml, | |
| 27 | +}: IndexingStatusViewerProps) { | |
| 28 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 29 | + const dispatch = useAppDispatch(); | |
| 30 | + const [indexedPages, setIndexedPages] = useState<null | string[]>(null); | |
| 31 | + const [showTooltip, setShowTooltip] = useState(false); | |
| 32 | + | |
| 33 | + const status = useAppSelector( | |
| 34 | + (store) => store.indexing.indexing.statuses[docConfig.startUrl], | |
| 35 | + ); | |
| 36 | + | |
| 37 | + const isComplete = status?.status === "complete"; | |
| 38 | + | |
| 39 | + const reIndex = () => | |
| 40 | + ideMessenger.post("indexing/reindex", { | |
| 41 | + type: "docs", | |
| 42 | + id: docConfig.startUrl, | |
| 43 | + }); | |
| 44 | + | |
| 45 | + const abort = () => { | |
| 46 | + ideMessenger.post("indexing/abort", { | |
| 47 | + type: "docs", | |
| 48 | + id: docConfig.startUrl, | |
| 49 | + }); | |
| 50 | + // Optimistic abort status | |
| 51 | + if (status) { | |
| 52 | + dispatch( | |
| 53 | + updateIndexingStatus({ ...status, status: "aborted", progress: 0 }), | |
| 54 | + ); | |
| 55 | + } | |
| 56 | + }; | |
| 57 | + | |
| 58 | + const [hasDeleted, setHasDeleted] = useState(false); // simple alternative to optimistic redux update | |
| 59 | + const onDelete = () => { | |
| 60 | + // optimistic update | |
| 61 | + dispatch( | |
| 62 | + setDialogMessage( | |
| 63 | + <ConfirmationDialog | |
| 64 | + title={`Delete ${docConfig.title}`} | |
| 65 | + text={`Are you sure you want to remove ${docConfig.title} from your configuration?`} | |
| 66 | + onConfirm={() => { | |
| 67 | + ideMessenger.post("context/removeDocs", { | |
| 68 | + startUrl: docConfig.startUrl, | |
| 69 | + }); | |
| 70 | + setHasDeleted(true); | |
| 71 | + }} | |
| 72 | + />, | |
| 73 | + ), | |
| 74 | + ); | |
| 75 | + dispatch(setShowDialog(true)); | |
| 76 | + }; | |
| 77 | + | |
| 78 | + const progressPercentage = useMemo(() => { | |
| 79 | + if (!status) { | |
| 80 | + return 0; | |
| 81 | + } | |
| 82 | + return Math.min(100, Math.max(0, status.progress * 100)).toFixed(0); | |
| 83 | + }, [status?.progress]); | |
| 84 | + | |
| 85 | + // Fetch pages list when the status changes to complete | |
| 86 | + useEffect(() => { | |
| 87 | + async function getPagesList() { | |
| 88 | + try { | |
| 89 | + const response = await ideMessenger.request("docs/getIndexedPages", { | |
| 90 | + startUrl: docConfig.startUrl, | |
| 91 | + }); | |
| 92 | + if (response.status === "error") { | |
| 93 | + throw new Error(response.error); | |
| 94 | + } | |
| 95 | + setIndexedPages(response.content.sort()); | |
| 96 | + } catch (ex) { | |
| 97 | + console.error( | |
| 98 | + `Unable to fetch pages list for ${docConfig.startUrl}: ${ex}`, | |
| 99 | + ); | |
| 100 | + } | |
| 101 | + } | |
| 102 | + | |
| 103 | + if (isComplete) { | |
| 104 | + void getPagesList(); | |
| 105 | + } | |
| 106 | + }, [isComplete, ideMessenger, docConfig.startUrl]); | |
| 107 | + | |
| 108 | + const showPagesList = () => { | |
| 109 | + if (indexedPages) { | |
| 110 | + setShowTooltip(true); | |
| 111 | + } | |
| 112 | + }; | |
| 113 | + | |
| 114 | + if (hasDeleted) return null; | |
| 115 | + | |
| 116 | + const startUrlSlug = docConfig.startUrl.replace(/[^a-zA-Z0-9_-]/g, "_"); | |
| 117 | + | |
| 118 | + return ( | |
| 119 | + <div className="mt-1 flex w-full flex-col"> | |
| 120 | + <div | |
| 121 | + className={`flex flex-row items-center justify-between gap-2 text-sm`} | |
| 122 | + > | |
| 123 | + <div | |
| 124 | + className={`flex flex-row items-center gap-1`} | |
| 125 | + onClick={() => { | |
| 126 | + if (status?.url) { | |
| 127 | + ideMessenger.post("openUrl", status.url); | |
| 128 | + } | |
| 129 | + }} | |
| 130 | + > | |
| 131 | + <p | |
| 132 | + style={{ | |
| 133 | + fontSize: fontSize(-3), | |
| 134 | + }} | |
| 135 | + className={`m-0 line-clamp-1 p-0 text-left ${status?.url ? "cursor-pointer hover:underline" : ""}`} | |
| 136 | + > | |
| 137 | + {docConfig.title ?? docConfig.startUrl} | |
| 138 | + </p> | |
| 139 | + </div> | |
| 140 | + | |
| 141 | + <div className="flex flex-row items-center gap-2"> | |
| 142 | + <div className="flex flex-row items-center gap-2 text-gray-400"> | |
| 143 | + {status?.status === "indexing" && ( | |
| 144 | + <span | |
| 145 | + className="text-xs" | |
| 146 | + style={{ | |
| 147 | + fontSize: fontSize(-3), | |
| 148 | + }} | |
| 149 | + > | |
| 150 | + {progressPercentage}% | |
| 151 | + </span> | |
| 152 | + )} | |
| 153 | + | |
| 154 | + {status?.status === "indexing" && ( | |
| 155 | + <StopIcon | |
| 156 | + className="h-3 w-3 cursor-pointer text-gray-400 hover:brightness-125" | |
| 157 | + onClick={abort} | |
| 158 | + data-testid="stop-indexing" | |
| 159 | + /> | |
| 160 | + )} | |
| 161 | + | |
| 162 | + <EditBlockButton | |
| 163 | + blockType="docs" | |
| 164 | + block={docFromYaml} | |
| 165 | + sourceFile={docConfig.sourceFile} | |
| 166 | + /> | |
| 167 | + | |
| 168 | + {["aborted", "complete", "failed"].includes( | |
| 169 | + status?.status ?? "", | |
| 170 | + ) && ( | |
| 171 | + <ArrowPathIcon | |
| 172 | + className="h-3 w-3 cursor-pointer text-gray-400 hover:brightness-125" | |
| 173 | + onClick={reIndex} | |
| 174 | + data-testid="reindex-docs" | |
| 175 | + /> | |
| 176 | + )} | |
| 177 | + | |
| 178 | + <StatusIndicator | |
| 179 | + status={status?.status} | |
| 180 | + hoverMessage={ | |
| 181 | + status?.status === "failed" ? status?.debugInfo : undefined | |
| 182 | + } | |
| 183 | + /> | |
| 184 | + </div> | |
| 185 | + </div> | |
| 186 | + </div> | |
| 187 | + | |
| 188 | + {status && ( | |
| 189 | + <div | |
| 190 | + className={`flex flex-row items-center justify-between gap-2 text-sm`} | |
| 191 | + > | |
| 192 | + <p | |
| 193 | + style={{ | |
| 194 | + fontSize: fontSize(-4), | |
| 195 | + }} | |
| 196 | + className={`m-0 line-clamp-1 p-0 text-left text-gray-400 ${isComplete ? "cursor-pointer hover:underline" : ""}`} | |
| 197 | + onClick={() => { | |
| 198 | + if (isComplete) { | |
| 199 | + showPagesList(); | |
| 200 | + } | |
| 201 | + }} | |
| 202 | + data-tooltip-id={`docs-tooltip-${startUrlSlug}`} | |
| 203 | + > | |
| 204 | + {isComplete | |
| 205 | + ? indexedPages | |
| 206 | + ? `${indexedPages.length} page${indexedPages.length === 1 ? "" : "s"} indexed` | |
| 207 | + : "Loading site info..." | |
| 208 | + : status.description} | |
| 209 | + </p> | |
| 210 | + </div> | |
| 211 | + )} | |
| 212 | + | |
| 213 | + {indexedPages && ( | |
| 214 | + <ToolTip | |
| 215 | + isOpen={showTooltip} | |
| 216 | + setIsOpen={setShowTooltip} | |
| 217 | + clickable | |
| 218 | + delayShow={0} | |
| 219 | + openEvents={{ | |
| 220 | + mouseenter: false, | |
| 221 | + click: true, | |
| 222 | + }} | |
| 223 | + closeEvents={{ | |
| 224 | + blur: true, | |
| 225 | + mouseleave: false, | |
| 226 | + click: true, | |
| 227 | + }} | |
| 228 | + content={ | |
| 229 | + <IndexedPagesTooltip | |
| 230 | + pages={indexedPages} | |
| 231 | + siteTitle={docConfig.title ?? docConfig.startUrl} | |
| 232 | + baseUrl={docConfig.startUrl} | |
| 233 | + /> | |
| 234 | + } | |
| 235 | + > | |
| 236 | + <div data-tooltip-id={`docs-tooltip-${startUrlSlug}`} /> | |
| 237 | + </ToolTip> | |
| 238 | + )} | |
| 239 | + </div> | |
| 240 | + ); | |
| 241 | +} | |
| 242 | + | |
| 243 | +export default DocsIndexingStatus; |
added gui/src/pages/config/sections/docs/DocsSection.tsx +80 −0
| @@ -0,0 +1,80 @@ | ||
| 1 | +import { parseConfigYaml } from "@continuedev/config-yaml"; | |
| 2 | +import { IndexingStatus } from "core"; | |
| 3 | +import { useMemo } from "react"; | |
| 4 | +import { useAuth } from "../../../../context/Auth"; | |
| 5 | +import { useAppSelector } from "../../../../redux/hooks"; | |
| 6 | +import { EmptyState } from "../../../../components/ui"; | |
| 7 | +import DocsIndexingStatus from "./DocsIndexingStatus"; | |
| 8 | + | |
| 9 | +function DocsIndexingStatuses() { | |
| 10 | + const config = useAppSelector((store) => store.config.config); | |
| 11 | + const indexingStatuses = useAppSelector( | |
| 12 | + (store) => store.indexing.indexing.statuses, | |
| 13 | + ); | |
| 14 | + const { selectedProfile } = useAuth(); | |
| 15 | + const mergedDocs = useMemo(() => { | |
| 16 | + const parsed = selectedProfile?.rawYaml | |
| 17 | + ? parseConfigYaml(selectedProfile?.rawYaml ?? "") | |
| 18 | + : undefined; | |
| 19 | + return (config.docs ?? []).map((doc, index) => ({ | |
| 20 | + doc, | |
| 21 | + docFromYaml: parsed?.docs?.[index], | |
| 22 | + })); | |
| 23 | + }, [config.docs, selectedProfile?.rawYaml]); | |
| 24 | + | |
| 25 | + const sortedConfigDocs = useMemo(() => { | |
| 26 | + const sorter = (status: IndexingStatus["status"]) => { | |
| 27 | + if (status === "complete") return 0; | |
| 28 | + if (status === "indexing" || status === "paused") return 1; | |
| 29 | + if (status === "failed") return 2; | |
| 30 | + if (status === "aborted" || status === "pending") return 3; | |
| 31 | + return 4; | |
| 32 | + }; | |
| 33 | + | |
| 34 | + const docs = [...mergedDocs]; | |
| 35 | + docs.sort((a, b) => { | |
| 36 | + const statusA = indexingStatuses[a.doc.startUrl]?.status ?? "pending"; | |
| 37 | + const statusB = indexingStatuses[b.doc.startUrl]?.status ?? "pending"; | |
| 38 | + | |
| 39 | + // First, compare by status | |
| 40 | + const statusCompare = sorter(statusA) - sorter(statusB); | |
| 41 | + if (statusCompare !== 0) return statusCompare; | |
| 42 | + | |
| 43 | + // If status is the same, sort by presence of icon | |
| 44 | + const hasIconA = !!a.doc.faviconUrl; | |
| 45 | + const hasIconB = !!b.doc.faviconUrl; | |
| 46 | + return hasIconB === hasIconA ? 0 : hasIconB ? 1 : -1; | |
| 47 | + }); | |
| 48 | + return docs; | |
| 49 | + }, [mergedDocs, indexingStatuses]); | |
| 50 | + | |
| 51 | + if (sortedConfigDocs.length === 0) { | |
| 52 | + return ( | |
| 53 | + <EmptyState message="No documentation sources configured. Click the + button to add your first docs." /> | |
| 54 | + ); | |
| 55 | + } | |
| 56 | + | |
| 57 | + return ( | |
| 58 | + <div className="flex flex-col gap-1"> | |
| 59 | + <div className="flex flex-col overflow-y-auto overflow-x-hidden pr-2"> | |
| 60 | + {sortedConfigDocs.map((docConfig) => { | |
| 61 | + return ( | |
| 62 | + <div | |
| 63 | + key={docConfig.doc.startUrl} | |
| 64 | + className="flex items-center gap-2" | |
| 65 | + > | |
| 66 | + <div className="flex-grow"> | |
| 67 | + <DocsIndexingStatus | |
| 68 | + docFromYaml={docConfig.docFromYaml} | |
| 69 | + docConfig={docConfig.doc} | |
| 70 | + /> | |
| 71 | + </div> | |
| 72 | + </div> | |
| 73 | + ); | |
| 74 | + })} | |
| 75 | + </div> | |
| 76 | + </div> | |
| 77 | + ); | |
| 78 | +} | |
| 79 | + | |
| 80 | +export default DocsIndexingStatuses; |
added gui/src/pages/config/sections/docs/IndexedPagesTooltip.test.tsx +213 −0
| @@ -0,0 +1,213 @@ | ||
| 1 | +import { fireEvent, render, screen } from "@testing-library/react"; | |
| 2 | +import { Provider } from "react-redux"; | |
| 3 | +import { beforeEach, describe, expect, it, vi } from "vitest"; | |
| 4 | +import { IdeMessengerContext } from "../../../../context/IdeMessenger"; | |
| 5 | +import { createMockStore } from "../../../../util/test/mockStore"; | |
| 6 | +import { IndexedPagesTooltip } from "./IndexedPagesTooltip"; | |
| 7 | + | |
| 8 | +describe("IndexedPagesTooltip", () => { | |
| 9 | + const defaultProps = { | |
| 10 | + pages: [ | |
| 11 | + "https://example.com/page1", | |
| 12 | + "https://example.com/page2", | |
| 13 | + "https://example.com/sub/page3", | |
| 14 | + ], | |
| 15 | + siteTitle: "Example Documentation", | |
| 16 | + baseUrl: "https://example.com", | |
| 17 | + }; | |
| 18 | + | |
| 19 | + const renderComponent = (props = {}, storeState = {}) => { | |
| 20 | + const { mockIdeMessenger, ...store } = createMockStore(storeState); | |
| 21 | + | |
| 22 | + return { | |
| 23 | + ...render( | |
| 24 | + <Provider store={store}> | |
| 25 | + <IdeMessengerContext.Provider value={mockIdeMessenger}> | |
| 26 | + <IndexedPagesTooltip {...defaultProps} {...props} /> | |
| 27 | + </IdeMessengerContext.Provider> | |
| 28 | + </Provider>, | |
| 29 | + ), | |
| 30 | + mockIdeMessenger, | |
| 31 | + store, | |
| 32 | + }; | |
| 33 | + }; | |
| 34 | + | |
| 35 | + beforeEach(() => { | |
| 36 | + vi.clearAllMocks(); | |
| 37 | + }); | |
| 38 | + | |
| 39 | + it("renders site title and page count", () => { | |
| 40 | + renderComponent(); | |
| 41 | + expect( | |
| 42 | + screen.getByText("Example Documentation - 3 Pages Indexed"), | |
| 43 | + ).toBeInTheDocument(); | |
| 44 | + }); | |
| 45 | + | |
| 46 | + it("renders all pages in the list", () => { | |
| 47 | + renderComponent(); | |
| 48 | + | |
| 49 | + // Check that all pages are rendered (with baseUrl prefix removed) | |
| 50 | + expect(screen.getByText("/page1")).toBeInTheDocument(); | |
| 51 | + expect(screen.getByText("/page2")).toBeInTheDocument(); | |
| 52 | + expect(screen.getByText("/sub/page3")).toBeInTheDocument(); | |
| 53 | + }); | |
| 54 | + | |
| 55 | + it("removes baseUrl prefix from page URLs", () => { | |
| 56 | + const pages = [ | |
| 57 | + "https://example.com/docs/getting-started", | |
| 58 | + "https://example.com/docs/api-reference", | |
| 59 | + "https://other-domain.com/page", // This should not have prefix removed | |
| 60 | + ]; | |
| 61 | + | |
| 62 | + renderComponent({ pages, baseUrl: "https://example.com" }); | |
| 63 | + | |
| 64 | + expect(screen.getByText("/docs/getting-started")).toBeInTheDocument(); | |
| 65 | + expect(screen.getByText("/docs/api-reference")).toBeInTheDocument(); | |
| 66 | + expect( | |
| 67 | + screen.getByText("https://other-domain.com/page"), | |
| 68 | + ).toBeInTheDocument(); | |
| 69 | + }); | |
| 70 | + | |
| 71 | + it("handles pages that don't start with baseUrl", () => { | |
| 72 | + const pages = [ | |
| 73 | + "https://different-domain.com/page1", | |
| 74 | + "mailto:contact@example.com", | |
| 75 | + ]; | |
| 76 | + | |
| 77 | + renderComponent({ pages }); | |
| 78 | + | |
| 79 | + expect( | |
| 80 | + screen.getByText("https://different-domain.com/page1"), | |
| 81 | + ).toBeInTheDocument(); | |
| 82 | + expect(screen.getByText("mailto:contact@example.com")).toBeInTheDocument(); | |
| 83 | + }); | |
| 84 | + | |
| 85 | + it("opens URL when page is clicked", () => { | |
| 86 | + const { mockIdeMessenger } = renderComponent(); | |
| 87 | + | |
| 88 | + const pageLink = screen.getByText("/page1"); | |
| 89 | + fireEvent.click(pageLink); | |
| 90 | + | |
| 91 | + expect(mockIdeMessenger.post).toHaveBeenCalledWith( | |
| 92 | + "openUrl", | |
| 93 | + "https://example.com/page1", | |
| 94 | + ); | |
| 95 | + }); | |
| 96 | + | |
| 97 | + it("opens each page URL correctly when clicked", () => { | |
| 98 | + const { mockIdeMessenger } = renderComponent(); | |
| 99 | + | |
| 100 | + // Click on different pages | |
| 101 | + fireEvent.click(screen.getByText("/page2")); | |
| 102 | + expect(mockIdeMessenger.post).toHaveBeenCalledWith( | |
| 103 | + "openUrl", | |
| 104 | + "https://example.com/page2", | |
| 105 | + ); | |
| 106 | + | |
| 107 | + fireEvent.click(screen.getByText("/sub/page3")); | |
| 108 | + expect(mockIdeMessenger.post).toHaveBeenCalledWith( | |
| 109 | + "openUrl", | |
| 110 | + "https://example.com/sub/page3", | |
| 111 | + ); | |
| 112 | + }); | |
| 113 | + | |
| 114 | + it("renders empty list when no pages provided", () => { | |
| 115 | + renderComponent({ pages: [] }); | |
| 116 | + | |
| 117 | + expect( | |
| 118 | + screen.getByText("Example Documentation - 0 Pages Indexed"), | |
| 119 | + ).toBeInTheDocument(); | |
| 120 | + expect(screen.queryByRole("listitem")).not.toBeInTheDocument(); | |
| 121 | + }); | |
| 122 | + | |
| 123 | + it("handles single page correctly", () => { | |
| 124 | + const pages = ["https://example.com/single-page"]; | |
| 125 | + | |
| 126 | + renderComponent({ pages }); | |
| 127 | + | |
| 128 | + expect( | |
| 129 | + screen.getByText("Example Documentation - 1 Pages Indexed"), | |
| 130 | + ).toBeInTheDocument(); | |
| 131 | + expect(screen.getByText("/single-page")).toBeInTheDocument(); | |
| 132 | + }); | |
| 133 | + | |
| 134 | + it("preserves page order", () => { | |
| 135 | + const pages = [ | |
| 136 | + "https://example.com/z-last", | |
| 137 | + "https://example.com/a-first", | |
| 138 | + "https://example.com/m-middle", | |
| 139 | + ]; | |
| 140 | + | |
| 141 | + renderComponent({ pages }); | |
| 142 | + | |
| 143 | + const listItems = screen.getAllByRole("listitem"); | |
| 144 | + expect(listItems).toHaveLength(3); | |
| 145 | + | |
| 146 | + // Check that the order is preserved as provided, not alphabetically sorted | |
| 147 | + expect(listItems[0]).toHaveTextContent("/z-last"); | |
| 148 | + expect(listItems[1]).toHaveTextContent("/a-first"); | |
| 149 | + expect(listItems[2]).toHaveTextContent("/m-middle"); | |
| 150 | + }); | |
| 151 | + | |
| 152 | + it("applies correct CSS classes for styling", () => { | |
| 153 | + renderComponent(); | |
| 154 | + | |
| 155 | + const pageItems = screen.getAllByRole("listitem"); | |
| 156 | + pageItems.forEach((item) => { | |
| 157 | + expect(item).toHaveClass( | |
| 158 | + "my-1", | |
| 159 | + "cursor-pointer", | |
| 160 | + "truncate", | |
| 161 | + "text-left", | |
| 162 | + "text-gray-400", | |
| 163 | + "hover:underline", | |
| 164 | + ); | |
| 165 | + }); | |
| 166 | + }); | |
| 167 | + | |
| 168 | + it("shows scrollable container for long lists", () => { | |
| 169 | + // Create a long list of pages | |
| 170 | + const longPageList = Array.from( | |
| 171 | + { length: 20 }, | |
| 172 | + (_, i) => `https://example.com/page-${i + 1}`, | |
| 173 | + ); | |
| 174 | + | |
| 175 | + const { container } = renderComponent({ pages: longPageList }); | |
| 176 | + | |
| 177 | + // Check that the scrollable container exists | |
| 178 | + const scrollContainer = container.querySelector( | |
| 179 | + ".max-h-48.overflow-y-auto", | |
| 180 | + ); | |
| 181 | + expect(scrollContainer).toBeInTheDocument(); | |
| 182 | + | |
| 183 | + // Check that all pages are rendered | |
| 184 | + expect( | |
| 185 | + screen.getByText("Example Documentation - 20 Pages Indexed"), | |
| 186 | + ).toBeInTheDocument(); | |
| 187 | + longPageList.forEach((_, index) => { | |
| 188 | + expect(screen.getByText(`/page-${index + 1}`)).toBeInTheDocument(); | |
| 189 | + }); | |
| 190 | + }); | |
| 191 | + | |
| 192 | + describe("removePrefix utility", () => { | |
| 193 | + it("removes prefix when string starts with it", () => { | |
| 194 | + const pages = ["https://example.com/docs/guide"]; | |
| 195 | + renderComponent({ pages, baseUrl: "https://example.com" }); | |
| 196 | + expect(screen.getByText("/docs/guide")).toBeInTheDocument(); | |
| 197 | + }); | |
| 198 | + | |
| 199 | + it("returns original string when it doesn't start with prefix", () => { | |
| 200 | + const pages = ["https://other-site.com/page"]; | |
| 201 | + renderComponent({ pages, baseUrl: "https://example.com" }); | |
| 202 | + expect( | |
| 203 | + screen.getByText("https://other-site.com/page"), | |
| 204 | + ).toBeInTheDocument(); | |
| 205 | + }); | |
| 206 | + | |
| 207 | + it("handles empty prefix", () => { | |
| 208 | + const pages = ["https://example.com/page"]; | |
| 209 | + renderComponent({ pages, baseUrl: "" }); | |
| 210 | + expect(screen.getByText("https://example.com/page")).toBeInTheDocument(); | |
| 211 | + }); | |
| 212 | + }); | |
| 213 | +}); |
added gui/src/pages/config/sections/docs/IndexedPagesTooltip.tsx +71 −0
| @@ -0,0 +1,71 @@ | ||
| 1 | +import { EyeIcon } from "@heroicons/react/24/outline"; | |
| 2 | +import { useContext } from "react"; | |
| 3 | +import { useDispatch } from "react-redux"; | |
| 4 | +import { IdeMessengerContext } from "../../../../context/IdeMessenger"; | |
| 5 | +import { | |
| 6 | + setDialogMessage, | |
| 7 | + setShowDialog, | |
| 8 | +} from "../../../../redux/slices/uiSlice"; | |
| 9 | +import { fontSize } from "../../../../util"; | |
| 10 | +import DocsDetailsDialog from "./DocsDetailsDialog"; | |
| 11 | + | |
| 12 | +interface IndexedPagesTooltipProps { | |
| 13 | + pages: string[]; | |
| 14 | + siteTitle: string; | |
| 15 | + baseUrl: string; | |
| 16 | +} | |
| 17 | + | |
| 18 | +function removePrefix(str: string, prefix: string): string { | |
| 19 | + return str.startsWith(prefix) ? str.slice(prefix.length) : str; | |
| 20 | +} | |
| 21 | + | |
| 22 | +export const IndexedPagesTooltip = ({ | |
| 23 | + pages, | |
| 24 | + siteTitle, | |
| 25 | + baseUrl, | |
| 26 | +}: IndexedPagesTooltipProps) => { | |
| 27 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 28 | + const dispatch = useDispatch(); | |
| 29 | + | |
| 30 | + const handleEyeIconClick = (e: React.MouseEvent) => { | |
| 31 | + e.stopPropagation(); | |
| 32 | + | |
| 33 | + // Open the DocsDetailsDialog component as a modal | |
| 34 | + dispatch(setShowDialog(true)); | |
| 35 | + dispatch(setDialogMessage(<DocsDetailsDialog startUrl={baseUrl} />)); | |
| 36 | + }; | |
| 37 | + | |
| 38 | + return ( | |
| 39 | + <div> | |
| 40 | + <div | |
| 41 | + className="mx-1 my-2 flex items-center justify-between font-semibold" | |
| 42 | + style={{ fontSize: fontSize(-3) }} | |
| 43 | + > | |
| 44 | + <span> | |
| 45 | + {siteTitle} - {pages.length} Pages Indexed | |
| 46 | + </span> | |
| 47 | + <EyeIcon | |
| 48 | + className="ml-2 h-4 w-4 cursor-pointer text-red-500 transition-colors hover:text-red-400" | |
| 49 | + onClick={handleEyeIconClick} | |
| 50 | + title="View detailed docs information" | |
| 51 | + /> | |
| 52 | + </div> | |
| 53 | + <div className="max-h-48 overflow-y-auto px-1"> | |
| 54 | + <ul className="list-none pl-0"> | |
| 55 | + {pages.map((page, index) => ( | |
| 56 | + <li | |
| 57 | + key={index} | |
| 58 | + className="my-1 cursor-pointer truncate text-left text-gray-400 hover:underline" | |
| 59 | + style={{ fontSize: fontSize(-4) }} | |
| 60 | + onClick={() => { | |
| 61 | + ideMessenger.post("openUrl", page); | |
| 62 | + }} | |
| 63 | + > | |
| 64 | + {removePrefix(page, baseUrl)} | |
| 65 | + </li> | |
| 66 | + ))} | |
| 67 | + </ul> | |
| 68 | + </div> | |
| 69 | + </div> | |
| 70 | + ); | |
| 71 | +}; |
added gui/src/pages/config/sections/docs/StatusIndicator.tsx +37 −0
| @@ -0,0 +1,37 @@ | ||
| 1 | +import { IndexingStatus } from "core"; | |
| 2 | +import { ToolTip } from "../../../../components/gui/Tooltip"; | |
| 3 | + | |
| 4 | +interface StatusIndicatorProps { | |
| 5 | + status?: IndexingStatus["status"]; | |
| 6 | + className?: string; | |
| 7 | + size?: number; | |
| 8 | + hoverMessage?: string; | |
| 9 | +} | |
| 10 | + | |
| 11 | +const STATUS_TO_COLOR: Record<IndexingStatus["status"], string> = { | |
| 12 | + indexing: "bg-yellow-500", | |
| 13 | + paused: "bg-blue-500", | |
| 14 | + complete: "bg-green-500", | |
| 15 | + aborted: "bg-gray-500", | |
| 16 | + pending: "bg-gray-300", | |
| 17 | + failed: "bg-red-500", | |
| 18 | +}; | |
| 19 | + | |
| 20 | +export function StatusIndicator({ | |
| 21 | + status, | |
| 22 | + className = "", | |
| 23 | + size = 2, | |
| 24 | + hoverMessage, | |
| 25 | +}: StatusIndicatorProps) { | |
| 26 | + if (!status) return null; | |
| 27 | + | |
| 28 | + return ( | |
| 29 | + <ToolTip hidden={!hoverMessage} content={hoverMessage}> | |
| 30 | + <div | |
| 31 | + className={`h-${size} w-${size} rounded-full ${STATUS_TO_COLOR[status]} ${ | |
| 32 | + status === "indexing" ? "animate-pulse" : "" | |
| 33 | + } ${className}`} | |
| 34 | + /> | |
| 35 | + </ToolTip> | |
| 36 | + ); | |
| 37 | +} |
modified gui/src/pages/gui/ToolCallDiv/FindAndReplace.tsx +1 −1
| @@ -241,7 +241,7 @@ | ||
| 241 | 241 | className={`${config?.ui?.showChatScrollbar ? "thin-scrollbar" : "no-scrollbar"} max-h-72 overflow-auto`} |
| 242 | 242 | > |
| 243 | 243 | <pre |
| 244 | - className={`bg-editor m-0 w-full text-xs leading-tight ${config?.ui?.codeWrap ? "whitespace-pre-wrap" : "whitespace-pre"}`} | |
| 244 | + className={`bg-editor m-0 w-fit min-w-full text-xs leading-tight ${config?.ui?.codeWrap ? "whitespace-pre-wrap" : "whitespace-pre"}`} | |
| 245 | 245 | > |
| 246 | 246 | {diffResult.diff?.map((part, index) => { |
| 247 | 247 | if (part.removed) { |
modified gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx +48 −127
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | addAndSelectMockLlm, |
| 5 | 5 | triggerConfigUpdate, |
| 6 | 6 | } from "../../../util/test/config"; |
| 7 | +import { updateConfig } from "../../../redux/slices/configSlice"; | |
| 7 | 8 | import { renderWithProviders } from "../../../util/test/render"; |
| 8 | 9 | import { Chat } from "../Chat"; |
| 9 | 10 | |
| @@ -11,6 +12,7 @@ | ||
| 11 | 12 | import { act } from "@testing-library/react"; |
| 12 | 13 | import { ChatMessage } from "core"; |
| 13 | 14 | import { setToolPolicy } from "../../../redux/slices/uiSlice"; |
| 15 | +import { setInactive } from "../../../redux/slices/sessionSlice"; | |
| 14 | 16 | import { |
| 15 | 17 | getElementByTestId, |
| 16 | 18 | getElementByText, |
| @@ -47,8 +49,14 @@ | ||
| 47 | 49 | ]; |
| 48 | 50 | |
| 49 | 51 | const POST_EDIT_RESPONSE = "Edit applied successfully"; |
| 50 | -beforeEach(() => { | |
| 52 | +beforeEach(async () => { | |
| 51 | 53 | vi.clearAllMocks(); |
| 54 | + // Clear any persisted state to ensure test isolation | |
| 55 | + localStorage.clear(); | |
| 56 | + sessionStorage.clear(); | |
| 57 | + | |
| 58 | + // Add a small delay to ensure cleanup is complete | |
| 59 | + await new Promise((resolve) => setTimeout(resolve, 50)); | |
| 52 | 60 | }); |
| 53 | 61 | |
| 54 | 62 | test( |
| @@ -58,14 +66,52 @@ | ||
| 58 | 66 | // Setup |
| 59 | 67 | const { ideMessenger, store, user } = await renderWithProviders(<Chat />); |
| 60 | 68 | |
| 69 | + // Reset mocks to ensure clean state | |
| 70 | + ideMessenger.resetMocks(); | |
| 71 | + | |
| 72 | + // Reset streaming state to prevent test interference | |
| 73 | + store.dispatch(setInactive()); | |
| 74 | + | |
| 61 | 75 | ideMessenger.responses["getWorkspaceDirs"] = [EDIT_WORKSPACE_DIR]; |
| 62 | 76 | ideMessenger.responses["tools/evaluatePolicy"] = { |
| 63 | 77 | policy: "allowedWithPermission", |
| 64 | 78 | }; |
| 79 | + | |
| 80 | + // Mock context/getSymbolsForFiles to prevent errors during streaming | |
| 81 | + ideMessenger.responses["context/getSymbolsForFiles"] = {}; | |
| 82 | + | |
| 65 | 83 | const messengerPostSpy = vi.spyOn(ideMessenger, "post"); |
| 66 | 84 | const messengerRequestSpy = vi.spyOn(ideMessenger, "request"); |
| 67 | 85 | |
| 68 | - addAndSelectMockLlm(store, ideMessenger); | |
| 86 | + // Instead of using addAndSelectMockLlm (which relies on events that might be failing), | |
| 87 | + // directly dispatch the config update to set the selected model | |
| 88 | + const currentConfig = store.getState().config.config; | |
| 89 | + store.dispatch( | |
| 90 | + updateConfig({ | |
| 91 | + ...currentConfig, | |
| 92 | + selectedModelByRole: { | |
| 93 | + ...currentConfig.selectedModelByRole, | |
| 94 | + chat: { | |
| 95 | + model: "mock", | |
| 96 | + provider: "mock", | |
| 97 | + title: "Mock LLM", | |
| 98 | + underlyingProviderName: "mock", | |
| 99 | + }, | |
| 100 | + }, | |
| 101 | + modelsByRole: { | |
| 102 | + ...currentConfig.modelsByRole, | |
| 103 | + chat: [ | |
| 104 | + ...(currentConfig.modelsByRole.chat || []), | |
| 105 | + { | |
| 106 | + model: "mock", | |
| 107 | + provider: "mock", | |
| 108 | + title: "Mock LLM", | |
| 109 | + underlyingProviderName: "mock", | |
| 110 | + }, | |
| 111 | + ], | |
| 112 | + }, | |
| 113 | + }), | |
| 114 | + ); | |
| 69 | 115 | |
| 70 | 116 | // Send the input that will respond with an edit tool call |
| 71 | 117 | await sendInputWithMockedResponse( |
| @@ -166,128 +212,3 @@ | ||
| 166 | 212 | // }); |
| 167 | 213 | }, |
| 168 | 214 | ); |
| 169 | - | |
| 170 | -test("Edit run with no policy and yolo mode", { timeout: 15000 }, async () => { | |
| 171 | - // Setup | |
| 172 | - const { ideMessenger, store, user } = await renderWithProviders(<Chat />); | |
| 173 | - | |
| 174 | - ideMessenger.responses["getWorkspaceDirs"] = [EDIT_WORKSPACE_DIR]; | |
| 175 | - ideMessenger.responses["tools/evaluatePolicy"] = { | |
| 176 | - policy: "allowedWithoutPermission", | |
| 177 | - }; | |
| 178 | - const messengerPostSpy = vi.spyOn(ideMessenger, "post"); | |
| 179 | - const messengerRequestSpy = vi.spyOn(ideMessenger, "request"); | |
| 180 | - | |
| 181 | - addAndSelectMockLlm(store, ideMessenger); | |
| 182 | - | |
| 183 | - // Enable automatic edit and yolo mode | |
| 184 | - store.dispatch( | |
| 185 | - setToolPolicy({ | |
| 186 | - toolName: BuiltInToolNames.EditExistingFile, | |
| 187 | - policy: "allowedWithoutPermission", | |
| 188 | - }), | |
| 189 | - ); | |
| 190 | - triggerConfigUpdate({ | |
| 191 | - store, | |
| 192 | - ideMessenger, | |
| 193 | - editConfig: (current) => { | |
| 194 | - current.ui = { | |
| 195 | - ...current.ui, | |
| 196 | - autoAcceptEditToolDiffs: true, // Enable auto-accept for edit tool diffs | |
| 197 | - }; | |
| 198 | - return current; | |
| 199 | - }, | |
| 200 | - }); | |
| 201 | - expect(store.getState().config.config.ui?.autoAcceptEditToolDiffs).toBe(true); | |
| 202 | - | |
| 203 | - // Send the input that will respond with an edit tool call | |
| 204 | - await sendInputWithMockedResponse( | |
| 205 | - ideMessenger, | |
| 206 | - "Edit this file", | |
| 207 | - EDIT_MESSAGES, | |
| 208 | - ); | |
| 209 | - | |
| 210 | - // Wait for streaming to complete and tool calls to be processed | |
| 211 | - await act(async () => { | |
| 212 | - await new Promise((resolve) => setTimeout(resolve, 1000)); | |
| 213 | - }); | |
| 214 | - | |
| 215 | - // Toggle the codeblock and make sure the changes show | |
| 216 | - const toggleCodeblockChevron = await getElementByTestId("toggle-codeblock"); | |
| 217 | - | |
| 218 | - await user.click(toggleCodeblockChevron); | |
| 219 | - await getElementByText(EDIT_CHANGES); | |
| 220 | - | |
| 221 | - // Make sure there's no pending tool call | |
| 222 | - await verifyNotPresentByTestId( | |
| 223 | - generateToolCallButtonTestId("accept", EDIT_TOOL_CALL_ID), | |
| 224 | - ); | |
| 225 | - // Tool call, check that applyToFile was called for edit | |
| 226 | - await waitFor(() => { | |
| 227 | - expect(messengerRequestSpy).toHaveBeenCalledWith("applyToFile", { | |
| 228 | - streamId: expect.any(String), | |
| 229 | - filepath: EDIT_FILE_URI, | |
| 230 | - text: EDIT_CHANGES, | |
| 231 | - toolCallId: EDIT_TOOL_CALL_ID, | |
| 232 | - }); | |
| 233 | - }); | |
| 234 | - | |
| 235 | - // Extract stream ID and initiate mock streaming | |
| 236 | - const streamId = messengerRequestSpy.mock.calls.find( | |
| 237 | - (call) => call[0] === "applyToFile", | |
| 238 | - )?.[1]?.streamId; | |
| 239 | - expect(streamId).toBeDefined(); | |
| 240 | - | |
| 241 | - ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 242 | - status: "streaming", | |
| 243 | - streamId, | |
| 244 | - toolCallId: EDIT_TOOL_CALL_ID, | |
| 245 | - filepath: EDIT_FILE_URI, | |
| 246 | - }); | |
| 247 | - | |
| 248 | - // Mid stream, should show applying in notch | |
| 249 | - await getElementByTestId("notch-applying-text"); | |
| 250 | - await getElementByTestId("notch-applying-cancel-button"); | |
| 251 | - | |
| 252 | - // Close the stream | |
| 253 | - ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 254 | - status: "done", | |
| 255 | - streamId, | |
| 256 | - toolCallId: EDIT_TOOL_CALL_ID, | |
| 257 | - filepath: EDIT_FILE_URI, | |
| 258 | - }); | |
| 259 | - | |
| 260 | - // Set the chat response text before the auto-accept triggers | |
| 261 | - ideMessenger.setChatResponseText(POST_EDIT_RESPONSE); | |
| 262 | - | |
| 263 | - await waitFor(() => { | |
| 264 | - expect(messengerPostSpy).toHaveBeenCalledWith("acceptDiff", { | |
| 265 | - streamId, | |
| 266 | - filepath: EDIT_FILE_URI, | |
| 267 | - }); | |
| 268 | - }); | |
| 269 | - | |
| 270 | - // Close the stream, ensure response is shown and diff buttons are not present | |
| 271 | - ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 272 | - status: "closed", | |
| 273 | - streamId, | |
| 274 | - toolCallId: EDIT_TOOL_CALL_ID, | |
| 275 | - filepath: EDIT_FILE_URI, | |
| 276 | - }); | |
| 277 | - | |
| 278 | - // Allow time for the auto-streaming to complete | |
| 279 | - await new Promise((resolve) => setTimeout(resolve, 1000)); | |
| 280 | - | |
| 281 | - await verifyNotPresentByTestId("edit-accept-button"); | |
| 282 | - await verifyNotPresentByTestId("edit-reject-button"); | |
| 283 | - | |
| 284 | - // Try to manually trigger the streaming by checking if the response is set | |
| 285 | - await act(async () => { | |
| 286 | - await new Promise((resolve) => setTimeout(resolve, 500)); | |
| 287 | - }); | |
| 288 | - | |
| 289 | - // TODO: Fix this test - the POST_EDIT_RESPONSE is not being displayed | |
| 290 | - // await waitFor(() => getElementByText(POST_EDIT_RESPONSE), { | |
| 291 | - // timeout: 8000, | |
| 292 | - // }); | |
| 293 | -}); |
added gui/src/pages/gui/chat-tests/EditToolScenariosYolo.test.tsx +228 −0
| @@ -0,0 +1,228 @@ | ||
| 1 | +import { BuiltInToolNames } from "core/tools/builtIn"; | |
| 2 | +import { generateToolCallButtonTestId } from "../../../components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar"; | |
| 3 | +import { triggerConfigUpdate } from "../../../util/test/config"; | |
| 4 | +import { updateConfig } from "../../../redux/slices/configSlice"; | |
| 5 | +import { renderWithProviders } from "../../../util/test/render"; | |
| 6 | +import { Chat } from "../Chat"; | |
| 7 | + | |
| 8 | +import { waitFor } from "@testing-library/dom"; | |
| 9 | +import { act } from "@testing-library/react"; | |
| 10 | +import { ChatMessage } from "core"; | |
| 11 | +import { setToolPolicy } from "../../../redux/slices/uiSlice"; | |
| 12 | +import { setInactive } from "../../../redux/slices/sessionSlice"; | |
| 13 | +import { | |
| 14 | + getElementByTestId, | |
| 15 | + getElementByText, | |
| 16 | + sendInputWithMockedResponse, | |
| 17 | + verifyNotPresentByTestId, | |
| 18 | +} from "../../../util/test/utils"; | |
| 19 | + | |
| 20 | +const EDIT_WORKSPACE_DIR = "file:///workspace"; | |
| 21 | +const EDIT_FILEPATH = "test.txt"; | |
| 22 | +const EDIT_FILE_URI = `${EDIT_WORKSPACE_DIR}/${EDIT_FILEPATH}`; | |
| 23 | +const EDIT_CHANGES = "New content"; | |
| 24 | +const EDIT_TOOL_CALL_ID = "known-id"; | |
| 25 | +const EDIT_MESSAGES: ChatMessage[] = [ | |
| 26 | + { | |
| 27 | + role: "assistant", | |
| 28 | + content: "I'll edit the file for you.", | |
| 29 | + }, | |
| 30 | + { | |
| 31 | + role: "assistant", | |
| 32 | + content: "", | |
| 33 | + toolCalls: [ | |
| 34 | + { | |
| 35 | + id: EDIT_TOOL_CALL_ID, | |
| 36 | + function: { | |
| 37 | + name: BuiltInToolNames.EditExistingFile, | |
| 38 | + arguments: JSON.stringify({ | |
| 39 | + filepath: EDIT_FILEPATH, | |
| 40 | + changes: EDIT_CHANGES, | |
| 41 | + }), | |
| 42 | + }, | |
| 43 | + }, | |
| 44 | + ], | |
| 45 | + }, | |
| 46 | +]; | |
| 47 | + | |
| 48 | +const POST_EDIT_RESPONSE = "Edit applied successfully"; | |
| 49 | +beforeEach(async () => { | |
| 50 | + vi.clearAllMocks(); | |
| 51 | + // Clear any persisted state to ensure test isolation | |
| 52 | + localStorage.clear(); | |
| 53 | + sessionStorage.clear(); | |
| 54 | + | |
| 55 | + // Add a small delay to ensure cleanup is complete | |
| 56 | + await new Promise((resolve) => setTimeout(resolve, 50)); | |
| 57 | +}); | |
| 58 | + | |
| 59 | +test("Edit run with no policy and yolo mode", { timeout: 15000 }, async () => { | |
| 60 | + // Additional cleanup before test starts | |
| 61 | + localStorage.clear(); | |
| 62 | + sessionStorage.clear(); | |
| 63 | + await new Promise((resolve) => setTimeout(resolve, 100)); | |
| 64 | + | |
| 65 | + // Setup | |
| 66 | + const { ideMessenger, store, user } = await renderWithProviders(<Chat />); | |
| 67 | + | |
| 68 | + // Reset mocks to ensure clean state | |
| 69 | + ideMessenger.resetMocks(); | |
| 70 | + | |
| 71 | + // Reset streaming state to prevent test interference | |
| 72 | + store.dispatch(setInactive()); | |
| 73 | + | |
| 74 | + // Additional delay to ensure state is fully reset | |
| 75 | + await new Promise((resolve) => setTimeout(resolve, 100)); | |
| 76 | + | |
| 77 | + ideMessenger.responses["getWorkspaceDirs"] = [EDIT_WORKSPACE_DIR]; | |
| 78 | + ideMessenger.responses["tools/evaluatePolicy"] = { | |
| 79 | + policy: "allowedWithoutPermission", | |
| 80 | + }; | |
| 81 | + | |
| 82 | + // Mock context/getSymbolsForFiles to prevent errors during streaming | |
| 83 | + ideMessenger.responses["context/getSymbolsForFiles"] = {}; | |
| 84 | + | |
| 85 | + const messengerPostSpy = vi.spyOn(ideMessenger, "post"); | |
| 86 | + const messengerRequestSpy = vi.spyOn(ideMessenger, "request"); | |
| 87 | + | |
| 88 | + // Instead of using addAndSelectMockLlm (which relies on events that might be failing), | |
| 89 | + // directly dispatch the config update to set the selected model | |
| 90 | + const currentConfig = store.getState().config.config; | |
| 91 | + store.dispatch( | |
| 92 | + updateConfig({ | |
| 93 | + ...currentConfig, | |
| 94 | + selectedModelByRole: { | |
| 95 | + ...currentConfig.selectedModelByRole, | |
| 96 | + chat: { | |
| 97 | + model: "mock", | |
| 98 | + provider: "mock", | |
| 99 | + title: "Mock LLM", | |
| 100 | + underlyingProviderName: "mock", | |
| 101 | + }, | |
| 102 | + }, | |
| 103 | + modelsByRole: { | |
| 104 | + ...currentConfig.modelsByRole, | |
| 105 | + chat: [ | |
| 106 | + ...(currentConfig.modelsByRole.chat || []), | |
| 107 | + { | |
| 108 | + model: "mock", | |
| 109 | + provider: "mock", | |
| 110 | + title: "Mock LLM", | |
| 111 | + underlyingProviderName: "mock", | |
| 112 | + }, | |
| 113 | + ], | |
| 114 | + }, | |
| 115 | + }), | |
| 116 | + ); | |
| 117 | + | |
| 118 | + // Enable automatic edit and yolo mode | |
| 119 | + store.dispatch( | |
| 120 | + setToolPolicy({ | |
| 121 | + toolName: BuiltInToolNames.EditExistingFile, | |
| 122 | + policy: "allowedWithoutPermission", | |
| 123 | + }), | |
| 124 | + ); | |
| 125 | + triggerConfigUpdate({ | |
| 126 | + store, | |
| 127 | + ideMessenger, | |
| 128 | + editConfig: (current) => { | |
| 129 | + current.ui = { | |
| 130 | + ...current.ui, | |
| 131 | + autoAcceptEditToolDiffs: true, // Enable auto-accept for edit tool diffs | |
| 132 | + }; | |
| 133 | + return current; | |
| 134 | + }, | |
| 135 | + }); | |
| 136 | + expect(store.getState().config.config.ui?.autoAcceptEditToolDiffs).toBe(true); | |
| 137 | + | |
| 138 | + // Send the input that will respond with an edit tool call | |
| 139 | + await sendInputWithMockedResponse( | |
| 140 | + ideMessenger, | |
| 141 | + "Edit this file", | |
| 142 | + EDIT_MESSAGES, | |
| 143 | + ); | |
| 144 | + | |
| 145 | + // Wait for streaming to complete and tool calls to be processed | |
| 146 | + await act(async () => { | |
| 147 | + await new Promise((resolve) => setTimeout(resolve, 1000)); | |
| 148 | + }); | |
| 149 | + | |
| 150 | + // Toggle the codeblock and make sure the changes show | |
| 151 | + const toggleCodeblockChevron = await getElementByTestId("toggle-codeblock"); | |
| 152 | + | |
| 153 | + await user.click(toggleCodeblockChevron); | |
| 154 | + await getElementByText(EDIT_CHANGES); | |
| 155 | + | |
| 156 | + // Make sure there's no pending tool call | |
| 157 | + await verifyNotPresentByTestId( | |
| 158 | + generateToolCallButtonTestId("accept", EDIT_TOOL_CALL_ID), | |
| 159 | + ); | |
| 160 | + // Tool call, check that applyToFile was called for edit | |
| 161 | + await waitFor(() => { | |
| 162 | + expect(messengerRequestSpy).toHaveBeenCalledWith("applyToFile", { | |
| 163 | + streamId: expect.any(String), | |
| 164 | + filepath: EDIT_FILE_URI, | |
| 165 | + text: EDIT_CHANGES, | |
| 166 | + toolCallId: EDIT_TOOL_CALL_ID, | |
| 167 | + }); | |
| 168 | + }); | |
| 169 | + | |
| 170 | + // Extract stream ID and initiate mock streaming | |
| 171 | + const streamId = messengerRequestSpy.mock.calls.find( | |
| 172 | + (call) => call[0] === "applyToFile", | |
| 173 | + )?.[1]?.streamId; | |
| 174 | + expect(streamId).toBeDefined(); | |
| 175 | + | |
| 176 | + ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 177 | + status: "streaming", | |
| 178 | + streamId, | |
| 179 | + toolCallId: EDIT_TOOL_CALL_ID, | |
| 180 | + filepath: EDIT_FILE_URI, | |
| 181 | + }); | |
| 182 | + | |
| 183 | + // Mid stream, should show applying in notch | |
| 184 | + await getElementByTestId("notch-applying-text"); | |
| 185 | + await getElementByTestId("notch-applying-cancel-button"); | |
| 186 | + | |
| 187 | + // Close the stream | |
| 188 | + ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 189 | + status: "done", | |
| 190 | + streamId, | |
| 191 | + toolCallId: EDIT_TOOL_CALL_ID, | |
| 192 | + filepath: EDIT_FILE_URI, | |
| 193 | + }); | |
| 194 | + | |
| 195 | + // Set the chat response text before the auto-accept triggers | |
| 196 | + ideMessenger.setChatResponseText(POST_EDIT_RESPONSE); | |
| 197 | + | |
| 198 | + await waitFor(() => { | |
| 199 | + expect(messengerPostSpy).toHaveBeenCalledWith("acceptDiff", { | |
| 200 | + streamId, | |
| 201 | + filepath: EDIT_FILE_URI, | |
| 202 | + }); | |
| 203 | + }); | |
| 204 | + | |
| 205 | + // Close the stream, ensure response is shown and diff buttons are not present | |
| 206 | + ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 207 | + status: "closed", | |
| 208 | + streamId, | |
| 209 | + toolCallId: EDIT_TOOL_CALL_ID, | |
| 210 | + filepath: EDIT_FILE_URI, | |
| 211 | + }); | |
| 212 | + | |
| 213 | + // Allow time for the auto-streaming to complete | |
| 214 | + await new Promise((resolve) => setTimeout(resolve, 1000)); | |
| 215 | + | |
| 216 | + await verifyNotPresentByTestId("edit-accept-button"); | |
| 217 | + await verifyNotPresentByTestId("edit-reject-button"); | |
| 218 | + | |
| 219 | + // Try to manually trigger the streaming by checking if the response is set | |
| 220 | + await act(async () => { | |
| 221 | + await new Promise((resolve) => setTimeout(resolve, 500)); | |
| 222 | + }); | |
| 223 | + | |
| 224 | + // TODO: Fix this test - the POST_EDIT_RESPONSE is not being displayed | |
| 225 | + // await waitFor(() => getElementByText(POST_EDIT_RESPONSE), { | |
| 226 | + // timeout: 8000, | |
| 227 | + // }); | |
| 228 | +}); |
deleted gui/src/pages/gui/chat-tests/ParallelToolCalls.test.tsx +0 −242
| @@ -1,242 +0,0 @@ | ||
| 1 | -import { act } from "@testing-library/react"; | |
| 2 | -import { ChatMessage } from "core"; | |
| 3 | -import { addAndSelectMockLlm } from "../../../util/test/config"; | |
| 4 | -import { renderWithProviders } from "../../../util/test/render"; | |
| 5 | -import { sendInputWithMockedResponse } from "../../../util/test/utils"; | |
| 6 | -import { Chat } from "../Chat"; | |
| 7 | - | |
| 8 | -describe("Parallel Tool Calls", () => { | |
| 9 | - const PARALLEL_TOOL_CALL_RESPONSE: ChatMessage[] = [ | |
| 10 | - { | |
| 11 | - role: "assistant", | |
| 12 | - content: "I'll call both tools in parallel.", | |
| 13 | - }, | |
| 14 | - { | |
| 15 | - role: "assistant", | |
| 16 | - content: "", | |
| 17 | - toolCalls: [ | |
| 18 | - { | |
| 19 | - id: "tool-call-1", | |
| 20 | - type: "function", | |
| 21 | - function: { | |
| 22 | - name: "read_file", | |
| 23 | - arguments: JSON.stringify({ filepath: "test.js" }), | |
| 24 | - }, | |
| 25 | - }, | |
| 26 | - { | |
| 27 | - id: "tool-call-2", | |
| 28 | - type: "function", | |
| 29 | - function: { | |
| 30 | - name: "write_file", | |
| 31 | - arguments: JSON.stringify({ | |
| 32 | - filepath: "output.js", | |
| 33 | - content: "test", | |
| 34 | - }), | |
| 35 | - }, | |
| 36 | - }, | |
| 37 | - ], | |
| 38 | - }, | |
| 39 | - ]; | |
| 40 | - | |
| 41 | - test("should handle assistant message with multiple tool calls", async () => { | |
| 42 | - const { ideMessenger, store } = await renderWithProviders(<Chat />); | |
| 43 | - | |
| 44 | - // Mock the tools/evaluatePolicy response to allow tools without permission | |
| 45 | - ideMessenger.responses["tools/evaluatePolicy"] = { | |
| 46 | - policy: "allowedWithPermission", | |
| 47 | - }; | |
| 48 | - | |
| 49 | - await act(async () => { | |
| 50 | - addAndSelectMockLlm(store, ideMessenger); | |
| 51 | - }); | |
| 52 | - | |
| 53 | - await sendInputWithMockedResponse( | |
| 54 | - ideMessenger, | |
| 55 | - "Use both tools", | |
| 56 | - PARALLEL_TOOL_CALL_RESPONSE, | |
| 57 | - ); | |
| 58 | - | |
| 59 | - // Wait for streaming to complete and tool calls to be set to generated | |
| 60 | - await act(async () => { | |
| 61 | - await new Promise((resolve) => setTimeout(resolve, 500)); | |
| 62 | - }); | |
| 63 | - | |
| 64 | - const state = store.getState(); | |
| 65 | - const history = state.session.history; | |
| 66 | - | |
| 67 | - // Should have user message and assistant message | |
| 68 | - expect(history).toHaveLength(2); | |
| 69 | - | |
| 70 | - // Find assistant message with tool calls | |
| 71 | - const assistantMessage = history.find( | |
| 72 | - (item) => | |
| 73 | - item.message.role === "assistant" && item.toolCallStates?.length, | |
| 74 | - ); | |
| 75 | - | |
| 76 | - expect(assistantMessage).toBeDefined(); | |
| 77 | - expect(assistantMessage!.toolCallStates).toHaveLength(2); | |
| 78 | - expect(assistantMessage!.toolCallStates![0].toolCallId).toBe("tool-call-1"); | |
| 79 | - expect(assistantMessage!.toolCallStates![1].toolCallId).toBe("tool-call-2"); | |
| 80 | - }); | |
| 81 | - | |
| 82 | - test("should handle individual tool call actions without breaking other calls", async () => { | |
| 83 | - const { ideMessenger, store } = await renderWithProviders(<Chat />); | |
| 84 | - | |
| 85 | - // Mock the tools/evaluatePolicy response to allow tools without permission | |
| 86 | - ideMessenger.responses["tools/evaluatePolicy"] = { | |
| 87 | - policy: "allowedWithPermission", | |
| 88 | - }; | |
| 89 | - | |
| 90 | - await act(async () => { | |
| 91 | - addAndSelectMockLlm(store, ideMessenger); | |
| 92 | - }); | |
| 93 | - | |
| 94 | - await sendInputWithMockedResponse( | |
| 95 | - ideMessenger, | |
| 96 | - "Use multiple tools", | |
| 97 | - PARALLEL_TOOL_CALL_RESPONSE, | |
| 98 | - ); | |
| 99 | - | |
| 100 | - // Wait for streaming to complete and tool calls to be set to generated | |
| 101 | - await act(async () => { | |
| 102 | - await new Promise((resolve) => setTimeout(resolve, 500)); | |
| 103 | - }); | |
| 104 | - | |
| 105 | - const { findAllCurToolCallsByStatus } = await import("../../../redux/util"); | |
| 106 | - const { cancelToolCall } = await import( | |
| 107 | - "../../../redux/slices/sessionSlice" | |
| 108 | - ); | |
| 109 | - | |
| 110 | - // Verify we have multiple pending tool calls | |
| 111 | - let state = store.getState(); | |
| 112 | - let pendingToolCalls = findAllCurToolCallsByStatus( | |
| 113 | - state.session.history, | |
| 114 | - "generated", | |
| 115 | - ); | |
| 116 | - expect(pendingToolCalls).toHaveLength(2); | |
| 117 | - | |
| 118 | - // Cancel the first tool call | |
| 119 | - await act(async () => { | |
| 120 | - store.dispatch(cancelToolCall({ toolCallId: "tool-call-1" })); | |
| 121 | - }); | |
| 122 | - | |
| 123 | - // Check state after canceling first tool call | |
| 124 | - state = store.getState(); | |
| 125 | - pendingToolCalls = findAllCurToolCallsByStatus( | |
| 126 | - state.session.history, | |
| 127 | - "generated", | |
| 128 | - ); | |
| 129 | - | |
| 130 | - // The second tool call should still be pending | |
| 131 | - expect(pendingToolCalls).toHaveLength(1); | |
| 132 | - expect(pendingToolCalls[0].toolCallId).toBe("tool-call-2"); | |
| 133 | - | |
| 134 | - // The first tool call should now be canceled | |
| 135 | - const canceledToolCalls = findAllCurToolCallsByStatus( | |
| 136 | - state.session.history, | |
| 137 | - "canceled", | |
| 138 | - ); | |
| 139 | - expect(canceledToolCalls).toHaveLength(1); | |
| 140 | - expect(canceledToolCalls[0].toolCallId).toBe("tool-call-1"); | |
| 141 | - }); | |
| 142 | - | |
| 143 | - test("should handle streaming deltas for multiple tool calls", async () => { | |
| 144 | - const { ideMessenger, store } = await renderWithProviders(<Chat />); | |
| 145 | - | |
| 146 | - // Mock the tools/evaluatePolicy response to allow tools without permission | |
| 147 | - ideMessenger.responses["tools/evaluatePolicy"] = { | |
| 148 | - policy: "allowedWithPermission", | |
| 149 | - }; | |
| 150 | - | |
| 151 | - await act(async () => { | |
| 152 | - addAndSelectMockLlm(store, ideMessenger); | |
| 153 | - }); | |
| 154 | - | |
| 155 | - // Simulate streaming behavior with deltas | |
| 156 | - const STREAMING_RESPONSE: ChatMessage[] = [ | |
| 157 | - { | |
| 158 | - role: "assistant", | |
| 159 | - content: "I'll call both tools in parallel.", | |
| 160 | - }, | |
| 161 | - { | |
| 162 | - role: "assistant", | |
| 163 | - content: "", | |
| 164 | - toolCalls: [ | |
| 165 | - { | |
| 166 | - id: "tool-call-1", | |
| 167 | - type: "function", | |
| 168 | - function: { | |
| 169 | - name: "read_file", | |
| 170 | - arguments: "", | |
| 171 | - }, | |
| 172 | - }, | |
| 173 | - ], | |
| 174 | - }, | |
| 175 | - { | |
| 176 | - role: "assistant", | |
| 177 | - content: "", | |
| 178 | - toolCalls: [ | |
| 179 | - { | |
| 180 | - id: "tool-call-1", | |
| 181 | - type: "function", | |
| 182 | - function: { | |
| 183 | - name: "read_file", | |
| 184 | - arguments: '{"filepath": "test.js"}', | |
| 185 | - }, | |
| 186 | - }, | |
| 187 | - ], | |
| 188 | - }, | |
| 189 | - { | |
| 190 | - role: "assistant", | |
| 191 | - content: "", | |
| 192 | - toolCalls: [ | |
| 193 | - { | |
| 194 | - id: "tool-call-2", | |
| 195 | - type: "function", | |
| 196 | - function: { | |
| 197 | - name: "write_file", | |
| 198 | - arguments: '{"filepath": "output.js", "content": "test"}', | |
| 199 | - }, | |
| 200 | - }, | |
| 201 | - ], | |
| 202 | - }, | |
| 203 | - ]; | |
| 204 | - | |
| 205 | - await sendInputWithMockedResponse( | |
| 206 | - ideMessenger, | |
| 207 | - "Use both tools with streaming", | |
| 208 | - STREAMING_RESPONSE, | |
| 209 | - ); | |
| 210 | - | |
| 211 | - // Wait for streaming to complete and tool calls to be set to generated | |
| 212 | - await act(async () => { | |
| 213 | - await new Promise((resolve) => setTimeout(resolve, 500)); | |
| 214 | - }); | |
| 215 | - | |
| 216 | - const state = store.getState(); | |
| 217 | - const history = state.session.history; | |
| 218 | - | |
| 219 | - // Should have only one assistant message after streaming | |
| 220 | - const assistantMessages = history.filter( | |
| 221 | - (item) => item.message.role === "assistant", | |
| 222 | - ); | |
| 223 | - expect(assistantMessages).toHaveLength(1); | |
| 224 | - | |
| 225 | - const assistantMessage = assistantMessages[0]; | |
| 226 | - | |
| 227 | - // Should preserve original content | |
| 228 | - expect(assistantMessage.message.content).toContain( | |
| 229 | - "I'll call both tools in parallel", | |
| 230 | - ); | |
| 231 | - | |
| 232 | - // Should have both tool calls after streaming completes | |
| 233 | - expect(assistantMessage.toolCallStates).toHaveLength(2); | |
| 234 | - | |
| 235 | - // Verify tool calls are properly constructed | |
| 236 | - const toolCallIds = assistantMessage.toolCallStates!.map( | |
| 237 | - (tc) => tc.toolCallId, | |
| 238 | - ); | |
| 239 | - expect(toolCallIds).toContain("tool-call-1"); | |
| 240 | - expect(toolCallIds).toContain("tool-call-2"); | |
| 241 | - }); | |
| 242 | -}); |
added gui/src/pages/gui/chat-tests/ParallelToolCallsActions.test.tsx +125 −0
| @@ -0,0 +1,125 @@ | ||
| 1 | +import { act } from "@testing-library/react"; | |
| 2 | +import { ChatMessage } from "core"; | |
| 3 | +import { renderWithProviders } from "../../../util/test/render"; | |
| 4 | +import { sendInputWithMockedResponse } from "../../../util/test/utils"; | |
| 5 | +import { Chat } from "../Chat"; | |
| 6 | +import { findAllCurToolCallsByStatus } from "../../../redux/util"; | |
| 7 | +import { cancelToolCall } from "../../../redux/slices/sessionSlice"; | |
| 8 | +import { updateConfig } from "../../../redux/slices/configSlice"; | |
| 9 | + | |
| 10 | +describe("Parallel Tool Calls - Actions", () => { | |
| 11 | + const PARALLEL_TOOL_CALL_RESPONSE: ChatMessage[] = [ | |
| 12 | + { | |
| 13 | + role: "assistant", | |
| 14 | + content: "I'll call both tools in parallel.", | |
| 15 | + }, | |
| 16 | + { | |
| 17 | + role: "assistant", | |
| 18 | + content: "", | |
| 19 | + toolCalls: [ | |
| 20 | + { | |
| 21 | + id: "tool-call-1", | |
| 22 | + type: "function", | |
| 23 | + function: { | |
| 24 | + name: "read_file", | |
| 25 | + arguments: JSON.stringify({ filepath: "test.js" }), | |
| 26 | + }, | |
| 27 | + }, | |
| 28 | + { | |
| 29 | + id: "tool-call-2", | |
| 30 | + type: "function", | |
| 31 | + function: { | |
| 32 | + name: "write_file", | |
| 33 | + arguments: JSON.stringify({ | |
| 34 | + filepath: "output.js", | |
| 35 | + content: "test", | |
| 36 | + }), | |
| 37 | + }, | |
| 38 | + }, | |
| 39 | + ], | |
| 40 | + }, | |
| 41 | + ]; | |
| 42 | + | |
| 43 | + test("should handle individual tool call actions without breaking other calls", async () => { | |
| 44 | + const { ideMessenger, store } = await renderWithProviders(<Chat />); | |
| 45 | + | |
| 46 | + // Mock required responses | |
| 47 | + ideMessenger.responses["tools/evaluatePolicy"] = { | |
| 48 | + policy: "allowedWithPermission", | |
| 49 | + }; | |
| 50 | + ideMessenger.responses["context/getSymbolsForFiles"] = {}; | |
| 51 | + | |
| 52 | + // Setup mock model with direct Redux dispatch | |
| 53 | + const currentConfig = store.getState().config.config; | |
| 54 | + store.dispatch( | |
| 55 | + updateConfig({ | |
| 56 | + ...currentConfig, | |
| 57 | + selectedModelByRole: { | |
| 58 | + ...currentConfig.selectedModelByRole, | |
| 59 | + chat: { | |
| 60 | + model: "mock", | |
| 61 | + provider: "mock", | |
| 62 | + title: "Mock LLM", | |
| 63 | + underlyingProviderName: "mock", | |
| 64 | + }, | |
| 65 | + }, | |
| 66 | + modelsByRole: { | |
| 67 | + ...currentConfig.modelsByRole, | |
| 68 | + chat: [ | |
| 69 | + ...(currentConfig.modelsByRole.chat || []), | |
| 70 | + { | |
| 71 | + model: "mock", | |
| 72 | + provider: "mock", | |
| 73 | + title: "Mock LLM", | |
| 74 | + underlyingProviderName: "mock", | |
| 75 | + }, | |
| 76 | + ], | |
| 77 | + }, | |
| 78 | + }), | |
| 79 | + ); | |
| 80 | + | |
| 81 | + await sendInputWithMockedResponse( | |
| 82 | + ideMessenger, | |
| 83 | + "Use multiple tools", | |
| 84 | + PARALLEL_TOOL_CALL_RESPONSE, | |
| 85 | + ); | |
| 86 | + | |
| 87 | + // Wait for streaming to complete | |
| 88 | + await act(async () => { | |
| 89 | + await new Promise((resolve) => setTimeout(resolve, 500)); | |
| 90 | + }); | |
| 91 | + | |
| 92 | + // Verify we have multiple pending tool calls | |
| 93 | + let state = store.getState(); | |
| 94 | + let pendingToolCalls = findAllCurToolCallsByStatus( | |
| 95 | + state.session.history, | |
| 96 | + "generated", | |
| 97 | + ); | |
| 98 | + | |
| 99 | + expect(pendingToolCalls).toHaveLength(2); | |
| 100 | + | |
| 101 | + // Cancel the first tool call | |
| 102 | + await act(async () => { | |
| 103 | + store.dispatch(cancelToolCall({ toolCallId: "tool-call-1" })); | |
| 104 | + }); | |
| 105 | + | |
| 106 | + // Check state after canceling first tool call | |
| 107 | + state = store.getState(); | |
| 108 | + pendingToolCalls = findAllCurToolCallsByStatus( | |
| 109 | + state.session.history, | |
| 110 | + "generated", | |
| 111 | + ); | |
| 112 | + | |
| 113 | + // The second tool call should still be pending | |
| 114 | + expect(pendingToolCalls).toHaveLength(1); | |
| 115 | + expect(pendingToolCalls[0].toolCallId).toBe("tool-call-2"); | |
| 116 | + | |
| 117 | + // The first tool call should now be canceled | |
| 118 | + const canceledToolCalls = findAllCurToolCallsByStatus( | |
| 119 | + state.session.history, | |
| 120 | + "canceled", | |
| 121 | + ); | |
| 122 | + expect(canceledToolCalls).toHaveLength(1); | |
| 123 | + expect(canceledToolCalls[0].toolCallId).toBe("tool-call-1"); | |
| 124 | + }); | |
| 125 | +}); |
added gui/src/pages/gui/chat-tests/ParallelToolCallsBasic.test.tsx +107 −0
| @@ -0,0 +1,107 @@ | ||
| 1 | +import { act } from "@testing-library/react"; | |
| 2 | +import { ChatMessage } from "core"; | |
| 3 | +import { renderWithProviders } from "../../../util/test/render"; | |
| 4 | +import { sendInputWithMockedResponse } from "../../../util/test/utils"; | |
| 5 | +import { Chat } from "../Chat"; | |
| 6 | +import { updateConfig } from "../../../redux/slices/configSlice"; | |
| 7 | + | |
| 8 | +describe("Parallel Tool Calls - Basic", () => { | |
| 9 | + const PARALLEL_TOOL_CALL_RESPONSE: ChatMessage[] = [ | |
| 10 | + { | |
| 11 | + role: "assistant", | |
| 12 | + content: "I'll call both tools in parallel.", | |
| 13 | + }, | |
| 14 | + { | |
| 15 | + role: "assistant", | |
| 16 | + content: "", | |
| 17 | + toolCalls: [ | |
| 18 | + { | |
| 19 | + id: "tool-call-1", | |
| 20 | + type: "function", | |
| 21 | + function: { | |
| 22 | + name: "read_file", | |
| 23 | + arguments: JSON.stringify({ filepath: "test.js" }), | |
| 24 | + }, | |
| 25 | + }, | |
| 26 | + { | |
| 27 | + id: "tool-call-2", | |
| 28 | + type: "function", | |
| 29 | + function: { | |
| 30 | + name: "write_file", | |
| 31 | + arguments: JSON.stringify({ | |
| 32 | + filepath: "output.js", | |
| 33 | + content: "test", | |
| 34 | + }), | |
| 35 | + }, | |
| 36 | + }, | |
| 37 | + ], | |
| 38 | + }, | |
| 39 | + ]; | |
| 40 | + | |
| 41 | + test("should handle assistant message with multiple tool calls", async () => { | |
| 42 | + const { ideMessenger, store } = await renderWithProviders(<Chat />); | |
| 43 | + | |
| 44 | + // Mock required responses | |
| 45 | + ideMessenger.responses["tools/evaluatePolicy"] = { | |
| 46 | + policy: "allowedWithPermission", | |
| 47 | + }; | |
| 48 | + ideMessenger.responses["context/getSymbolsForFiles"] = {}; | |
| 49 | + | |
| 50 | + // Setup mock model with direct Redux dispatch | |
| 51 | + const currentConfig = store.getState().config.config; | |
| 52 | + store.dispatch( | |
| 53 | + updateConfig({ | |
| 54 | + ...currentConfig, | |
| 55 | + selectedModelByRole: { | |
| 56 | + ...currentConfig.selectedModelByRole, | |
| 57 | + chat: { | |
| 58 | + model: "mock", | |
| 59 | + provider: "mock", | |
| 60 | + title: "Mock LLM", | |
| 61 | + underlyingProviderName: "mock", | |
| 62 | + }, | |
| 63 | + }, | |
| 64 | + modelsByRole: { | |
| 65 | + ...currentConfig.modelsByRole, | |
| 66 | + chat: [ | |
| 67 | + ...(currentConfig.modelsByRole.chat || []), | |
| 68 | + { | |
| 69 | + model: "mock", | |
| 70 | + provider: "mock", | |
| 71 | + title: "Mock LLM", | |
| 72 | + underlyingProviderName: "mock", | |
| 73 | + }, | |
| 74 | + ], | |
| 75 | + }, | |
| 76 | + }), | |
| 77 | + ); | |
| 78 | + | |
| 79 | + await sendInputWithMockedResponse( | |
| 80 | + ideMessenger, | |
| 81 | + "Use both tools", | |
| 82 | + PARALLEL_TOOL_CALL_RESPONSE, | |
| 83 | + ); | |
| 84 | + | |
| 85 | + // Wait for streaming to complete | |
| 86 | + await act(async () => { | |
| 87 | + await new Promise((resolve) => setTimeout(resolve, 500)); | |
| 88 | + }); | |
| 89 | + | |
| 90 | + const state = store.getState(); | |
| 91 | + const history = state.session.history; | |
| 92 | + | |
| 93 | + // Should have user message and assistant message | |
| 94 | + expect(history).toHaveLength(2); | |
| 95 | + | |
| 96 | + // Find assistant message with tool calls | |
| 97 | + const assistantMessage = history.find( | |
| 98 | + (item) => | |
| 99 | + item.message.role === "assistant" && item.toolCallStates?.length, | |
| 100 | + ); | |
| 101 | + | |
| 102 | + expect(assistantMessage).toBeDefined(); | |
| 103 | + expect(assistantMessage!.toolCallStates).toHaveLength(2); | |
| 104 | + expect(assistantMessage!.toolCallStates![0].toolCallId).toBe("tool-call-1"); | |
| 105 | + expect(assistantMessage!.toolCallStates![1].toolCallId).toBe("tool-call-2"); | |
| 106 | + }); | |
| 107 | +}); |
added gui/src/pages/gui/chat-tests/ParallelToolCallsStreaming.test.tsx +134 −0
| @@ -0,0 +1,134 @@ | ||
| 1 | +import { act } from "@testing-library/react"; | |
| 2 | +import { ChatMessage } from "core"; | |
| 3 | +import { renderWithProviders } from "../../../util/test/render"; | |
| 4 | +import { sendInputWithMockedResponse } from "../../../util/test/utils"; | |
| 5 | +import { Chat } from "../Chat"; | |
| 6 | +import { updateConfig } from "../../../redux/slices/configSlice"; | |
| 7 | + | |
| 8 | +describe("Parallel Tool Calls - Streaming", () => { | |
| 9 | + test("should handle streaming deltas for multiple tool calls", async () => { | |
| 10 | + const { ideMessenger, store } = await renderWithProviders(<Chat />); | |
| 11 | + | |
| 12 | + // Mock required responses | |
| 13 | + ideMessenger.responses["tools/evaluatePolicy"] = { | |
| 14 | + policy: "allowedWithPermission", | |
| 15 | + }; | |
| 16 | + ideMessenger.responses["context/getSymbolsForFiles"] = {}; | |
| 17 | + | |
| 18 | + // Setup mock model with direct Redux dispatch | |
| 19 | + const currentConfig = store.getState().config.config; | |
| 20 | + store.dispatch( | |
| 21 | + updateConfig({ | |
| 22 | + ...currentConfig, | |
| 23 | + selectedModelByRole: { | |
| 24 | + ...currentConfig.selectedModelByRole, | |
| 25 | + chat: { | |
| 26 | + model: "mock", | |
| 27 | + provider: "mock", | |
| 28 | + title: "Mock LLM", | |
| 29 | + underlyingProviderName: "mock", | |
| 30 | + }, | |
| 31 | + }, | |
| 32 | + modelsByRole: { | |
| 33 | + ...currentConfig.modelsByRole, | |
| 34 | + chat: [ | |
| 35 | + ...(currentConfig.modelsByRole.chat || []), | |
| 36 | + { | |
| 37 | + model: "mock", | |
| 38 | + provider: "mock", | |
| 39 | + title: "Mock LLM", | |
| 40 | + underlyingProviderName: "mock", | |
| 41 | + }, | |
| 42 | + ], | |
| 43 | + }, | |
| 44 | + }), | |
| 45 | + ); | |
| 46 | + | |
| 47 | + // Simulate streaming behavior with deltas | |
| 48 | + const STREAMING_RESPONSE: ChatMessage[] = [ | |
| 49 | + { | |
| 50 | + role: "assistant", | |
| 51 | + content: "I'll call both tools in parallel.", | |
| 52 | + }, | |
| 53 | + { | |
| 54 | + role: "assistant", | |
| 55 | + content: "", | |
| 56 | + toolCalls: [ | |
| 57 | + { | |
| 58 | + id: "tool-call-1", | |
| 59 | + type: "function", | |
| 60 | + function: { | |
| 61 | + name: "read_file", | |
| 62 | + arguments: "", | |
| 63 | + }, | |
| 64 | + }, | |
| 65 | + ], | |
| 66 | + }, | |
| 67 | + { | |
| 68 | + role: "assistant", | |
| 69 | + content: "", | |
| 70 | + toolCalls: [ | |
| 71 | + { | |
| 72 | + id: "tool-call-1", | |
| 73 | + type: "function", | |
| 74 | + function: { | |
| 75 | + name: "read_file", | |
| 76 | + arguments: '{"filepath": "test.js"}', | |
| 77 | + }, | |
| 78 | + }, | |
| 79 | + ], | |
| 80 | + }, | |
| 81 | + { | |
| 82 | + role: "assistant", | |
| 83 | + content: "", | |
| 84 | + toolCalls: [ | |
| 85 | + { | |
| 86 | + id: "tool-call-2", | |
| 87 | + type: "function", | |
| 88 | + function: { | |
| 89 | + name: "write_file", | |
| 90 | + arguments: '{"filepath": "output.js", "content": "test"}', | |
| 91 | + }, | |
| 92 | + }, | |
| 93 | + ], | |
| 94 | + }, | |
| 95 | + ]; | |
| 96 | + | |
| 97 | + await sendInputWithMockedResponse( | |
| 98 | + ideMessenger, | |
| 99 | + "Use both tools with streaming", | |
| 100 | + STREAMING_RESPONSE, | |
| 101 | + ); | |
| 102 | + | |
| 103 | + // Wait for streaming to complete | |
| 104 | + await act(async () => { | |
| 105 | + await new Promise((resolve) => setTimeout(resolve, 500)); | |
| 106 | + }); | |
| 107 | + | |
| 108 | + const state = store.getState(); | |
| 109 | + const history = state.session.history; | |
| 110 | + | |
| 111 | + // Should have only one assistant message after streaming | |
| 112 | + const assistantMessages = history.filter( | |
| 113 | + (item) => item.message.role === "assistant", | |
| 114 | + ); | |
| 115 | + expect(assistantMessages).toHaveLength(1); | |
| 116 | + | |
| 117 | + const assistantMessage = assistantMessages[0]; | |
| 118 | + | |
| 119 | + // Should preserve original content | |
| 120 | + expect(assistantMessage.message.content).toContain( | |
| 121 | + "I'll call both tools in parallel", | |
| 122 | + ); | |
| 123 | + | |
| 124 | + // Should have both tool calls after streaming completes | |
| 125 | + expect(assistantMessage.toolCallStates).toHaveLength(2); | |
| 126 | + | |
| 127 | + // Verify tool calls are properly constructed | |
| 128 | + const toolCallIds = assistantMessage.toolCallStates!.map( | |
| 129 | + (tc) => tc.toolCallId, | |
| 130 | + ); | |
| 131 | + expect(toolCallIds).toContain("tool-call-1"); | |
| 132 | + expect(toolCallIds).toContain("tool-call-2"); | |
| 133 | + }); | |
| 134 | +}); |
modified gui/src/pages/history/index.tsx +1 −7
| @@ -2,7 +2,6 @@ | ||
| 2 | 2 | import { History } from "../../components/History"; |
| 3 | 3 | import { PageHeader } from "../../components/PageHeader"; |
| 4 | 4 | import { getFontSize } from "../../util"; |
| 5 | -import { AccountButton } from "../config/AccountButton"; | |
| 6 | 5 | |
| 7 | 6 | export default function HistoryPage() { |
| 8 | 7 | const navigate = useNavigate(); |
| @@ -12,12 +11,7 @@ | ||
| 12 | 11 | className="flex flex-1 flex-col overflow-auto" |
| 13 | 12 | style={{ fontSize: getFontSize() }} |
| 14 | 13 | > |
| 15 | - <PageHeader | |
| 16 | - showBorder | |
| 17 | - onTitleClick={() => navigate("/")} | |
| 18 | - title="Chat" | |
| 19 | - rightContent={<AccountButton />} | |
| 20 | - /> | |
| 14 | + <PageHeader showBorder onTitleClick={() => navigate("/")} title="Chat" /> | |
| 21 | 15 | <History /> |
| 22 | 16 | </div> |
| 23 | 17 | ); |
modified gui/src/pages/stats.tsx +2 −12
| @@ -1,10 +1,10 @@ | ||
| 1 | -import { ArrowLeftIcon } from "@heroicons/react/24/outline"; | |
| 2 | 1 | import { useContext, useEffect, useState } from "react"; |
| 3 | 2 | import { useNavigate } from "react-router-dom"; |
| 4 | 3 | import styled from "styled-components"; |
| 5 | 4 | import { table } from "table"; |
| 6 | 5 | import { lightGray, vscBackground, vscInputBackground } from "../components"; |
| 7 | 6 | import { CopyIconButton } from "../components/gui/CopyIconButton"; |
| 7 | +import { PageHeader } from "../components/PageHeader"; | |
| 8 | 8 | import { IdeMessengerContext } from "../context/IdeMessenger"; |
| 9 | 9 | import { useNavigationListener } from "../hooks/useNavigationListener"; |
| 10 | 10 | |
| @@ -65,17 +65,7 @@ | ||
| 65 | 65 | backgroundColor: vscBackground, |
| 66 | 66 | }} |
| 67 | 67 | > |
| 68 | - <div | |
| 69 | - onClick={() => navigate(-1)} | |
| 70 | - className="sticky top-0 m-0 flex cursor-pointer items-center p-0" | |
| 71 | - style={{ | |
| 72 | - borderBottom: `0.5px solid ${lightGray}`, | |
| 73 | - backgroundColor: vscBackground, | |
| 74 | - }} | |
| 75 | - > | |
| 76 | - <ArrowLeftIcon className="ml-4 inline-block h-3 w-3 cursor-pointer" /> | |
| 77 | - <span className="m-2 inline-block text-base font-bold">More</span> | |
| 78 | - </div> | |
| 68 | + <PageHeader title="More" onTitleClick={() => navigate(-1)} showBorder /> | |
| 79 | 69 | |
| 80 | 70 | <div className="p-2"> |
| 81 | 71 | <div className="flex items-center gap-2"> |
modified gui/src/redux/thunks/moveTerminalProcessToBackground.ts +1 −1
| @@ -46,7 +46,7 @@ | ||
| 46 | 46 | { |
| 47 | 47 | name: "Terminal", |
| 48 | 48 | description: "Terminal command output", |
| 49 | - content: existingContent + (existingContent ? "\n\n" : "") + status, | |
| 49 | + content: existingContent, | |
| 50 | 50 | status: status, |
| 51 | 51 | }, |
| 52 | 52 | ]; |
modified gui/src/redux/thunks/updateFileSymbols.ts +1 −1
| @@ -84,7 +84,7 @@ | ||
| 84 | 84 | |
| 85 | 85 | const uniqueUris = new Set( |
| 86 | 86 | contextItems |
| 87 | - .filter((item) => item.uri?.type === "file" && item?.uri?.value) | |
| 87 | + .filter((item) => item?.uri?.type === "file" && item?.uri?.value) | |
| 88 | 88 | .map((item) => item.uri!.value), |
| 89 | 89 | ); |
| 90 | 90 |
modified gui/src/redux/util/constructMessages.test.ts +343 −0
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | ToolResultChatMessage, |
| 9 | 9 | UserChatMessage, |
| 10 | 10 | } from "core"; |
| 11 | +import { BuiltInToolNames } from "core/tools/builtIn"; | |
| 11 | 12 | import { |
| 12 | 13 | CANCELLED_TOOL_CALL_MESSAGE, |
| 13 | 14 | NO_TOOL_CALL_OUTPUT_MESSAGE, |
| @@ -712,4 +713,346 @@ | ||
| 712 | 713 | expect(messages[0].content).toContain("Base System Message"); |
| 713 | 714 | expect(messages[0].content).not.toContain(LAST_MESSAGE_RULE.rule); |
| 714 | 715 | }); |
| 716 | + | |
| 717 | + // Tests for the specific block in lines 135-142 handling toolCallState.output | |
| 718 | + describe("toolCallState.output handling (lines 135-142)", () => { | |
| 719 | + test("should use CANCELLED_TOOL_CALL_MESSAGE for cancelled tool calls", () => { | |
| 720 | + const assistantWithToolCall: AssistantChatMessage = { | |
| 721 | + role: "assistant", | |
| 722 | + content: "I'll run a command", | |
| 723 | + toolCalls: [ | |
| 724 | + { | |
| 725 | + id: "tool-call-1", | |
| 726 | + type: "function", | |
| 727 | + function: { | |
| 728 | + name: "some_tool", | |
| 729 | + arguments: '{"command": "ls"}', | |
| 730 | + }, | |
| 731 | + }, | |
| 732 | + ], | |
| 733 | + }; | |
| 734 | + | |
| 735 | + mockHistory = [ | |
| 736 | + { | |
| 737 | + message: assistantWithToolCall, | |
| 738 | + contextItems: [], | |
| 739 | + toolCallStates: [ | |
| 740 | + { | |
| 741 | + toolCallId: "tool-call-1", | |
| 742 | + toolCall: { | |
| 743 | + id: "tool-call-1", | |
| 744 | + type: "function", | |
| 745 | + function: { | |
| 746 | + name: "some_tool", | |
| 747 | + arguments: '{"command": "ls"}', | |
| 748 | + }, | |
| 749 | + }, | |
| 750 | + status: "canceled", | |
| 751 | + parsedArgs: { command: "ls" }, | |
| 752 | + output: [ | |
| 753 | + createContextItem( | |
| 754 | + "result", | |
| 755 | + "This should be ignored due to cancelled status", | |
| 756 | + ), | |
| 757 | + ], | |
| 758 | + }, | |
| 759 | + ], | |
| 760 | + }, | |
| 761 | + ]; | |
| 762 | + | |
| 763 | + const { messages } = constructMessages( | |
| 764 | + mockHistory, | |
| 765 | + "Base System Message", | |
| 766 | + mockRules, | |
| 767 | + {}, | |
| 768 | + ); | |
| 769 | + | |
| 770 | + const toolMessage = messages[2] as ToolResultChatMessage; | |
| 771 | + expect(toolMessage.role).toBe("tool"); | |
| 772 | + expect(toolMessage.content).toBe(CANCELLED_TOOL_CALL_MESSAGE); | |
| 773 | + expect(toolMessage.content).not.toContain("This should be ignored"); | |
| 774 | + }); | |
| 775 | + | |
| 776 | + test("should use renderContextItemsWithStatus for RunTerminalCommand with output", () => { | |
| 777 | + const assistantWithTerminalCall: AssistantChatMessage = { | |
| 778 | + role: "assistant", | |
| 779 | + content: "I'll run a terminal command", | |
| 780 | + toolCalls: [ | |
| 781 | + { | |
| 782 | + id: "terminal-call-1", | |
| 783 | + type: "function", | |
| 784 | + function: { | |
| 785 | + name: BuiltInToolNames.RunTerminalCommand, | |
| 786 | + arguments: '{"command": "ls -la"}', | |
| 787 | + }, | |
| 788 | + }, | |
| 789 | + ], | |
| 790 | + }; | |
| 791 | + | |
| 792 | + const terminalOutputWithStatus = [ | |
| 793 | + { | |
| 794 | + ...createContextItem("terminal-output", "file1.txt\nfile2.txt"), | |
| 795 | + status: "completed", | |
| 796 | + }, | |
| 797 | + { | |
| 798 | + ...createContextItem("terminal-error", "Warning: deprecated flag"), | |
| 799 | + status: "warning", | |
| 800 | + }, | |
| 801 | + ]; | |
| 802 | + | |
| 803 | + mockHistory = [ | |
| 804 | + { | |
| 805 | + message: assistantWithTerminalCall, | |
| 806 | + contextItems: [], | |
| 807 | + toolCallStates: [ | |
| 808 | + { | |
| 809 | + toolCallId: "terminal-call-1", | |
| 810 | + toolCall: { | |
| 811 | + id: "terminal-call-1", | |
| 812 | + type: "function", | |
| 813 | + function: { | |
| 814 | + name: BuiltInToolNames.RunTerminalCommand, | |
| 815 | + arguments: '{"command": "ls -la"}', | |
| 816 | + }, | |
| 817 | + }, | |
| 818 | + status: "done", | |
| 819 | + parsedArgs: { command: "ls -la" }, | |
| 820 | + output: terminalOutputWithStatus, | |
| 821 | + }, | |
| 822 | + ], | |
| 823 | + }, | |
| 824 | + ]; | |
| 825 | + | |
| 826 | + const { messages } = constructMessages( | |
| 827 | + mockHistory, | |
| 828 | + "Base System Message", | |
| 829 | + mockRules, | |
| 830 | + {}, | |
| 831 | + ); | |
| 832 | + | |
| 833 | + const toolMessage = messages[2] as ToolResultChatMessage; | |
| 834 | + expect(toolMessage.role).toBe("tool"); | |
| 835 | + expect(toolMessage.toolCallId).toBe("terminal-call-1"); | |
| 836 | + // Should contain content with status appended | |
| 837 | + expect(toolMessage.content).toContain("file1.txt\nfile2.txt"); | |
| 838 | + expect(toolMessage.content).toContain("[Status: completed]"); | |
| 839 | + expect(toolMessage.content).toContain("Warning: deprecated flag"); | |
| 840 | + expect(toolMessage.content).toContain("[Status: warning]"); | |
| 841 | + // Should use renderContextItemsWithStatus format with double newlines between items | |
| 842 | + expect(toolMessage.content).toMatch( | |
| 843 | + /file1\.txt\nfile2\.txt\n\[Status: completed\]\n\nWarning: deprecated flag\n\[Status: warning\]/, | |
| 844 | + ); | |
| 845 | + }); | |
| 846 | + | |
| 847 | + test("should use renderContextItems for non-RunTerminalCommand tools with output", () => { | |
| 848 | + const assistantWithSearchCall: AssistantChatMessage = { | |
| 849 | + role: "assistant", | |
| 850 | + content: "I'll search for that", | |
| 851 | + toolCalls: [ | |
| 852 | + { | |
| 853 | + id: "search-call-1", | |
| 854 | + type: "function", | |
| 855 | + function: { | |
| 856 | + name: "search", // Not RunTerminalCommand | |
| 857 | + arguments: '{"query": "test"}', | |
| 858 | + }, | |
| 859 | + }, | |
| 860 | + ], | |
| 861 | + }; | |
| 862 | + | |
| 863 | + const searchOutput = [ | |
| 864 | + createContextItem("result1", "First search result"), | |
| 865 | + createContextItem("result2", "Second search result"), | |
| 866 | + ]; | |
| 867 | + | |
| 868 | + mockHistory = [ | |
| 869 | + { | |
| 870 | + message: assistantWithSearchCall, | |
| 871 | + contextItems: [], | |
| 872 | + toolCallStates: [ | |
| 873 | + { | |
| 874 | + toolCallId: "search-call-1", | |
| 875 | + toolCall: { | |
| 876 | + id: "search-call-1", | |
| 877 | + type: "function", | |
| 878 | + function: { | |
| 879 | + name: "search", | |
| 880 | + arguments: '{"query": "test"}', | |
| 881 | + }, | |
| 882 | + }, | |
| 883 | + status: "done", | |
| 884 | + parsedArgs: { query: "test" }, | |
| 885 | + output: searchOutput, | |
| 886 | + }, | |
| 887 | + ], | |
| 888 | + }, | |
| 889 | + ]; | |
| 890 | + | |
| 891 | + const { messages } = constructMessages( | |
| 892 | + mockHistory, | |
| 893 | + "Base System Message", | |
| 894 | + mockRules, | |
| 895 | + {}, | |
| 896 | + ); | |
| 897 | + | |
| 898 | + const toolMessage = messages[2] as ToolResultChatMessage; | |
| 899 | + expect(toolMessage.role).toBe("tool"); | |
| 900 | + expect(toolMessage.toolCallId).toBe("search-call-1"); | |
| 901 | + // Should use renderContextItems format (no status, double newlines between items) | |
| 902 | + expect(toolMessage.content).toBe( | |
| 903 | + "First search result\n\nSecond search result", | |
| 904 | + ); | |
| 905 | + expect(toolMessage.content).not.toContain("[Status:"); | |
| 906 | + }); | |
| 907 | + | |
| 908 | + test("should use NO_TOOL_CALL_OUTPUT_MESSAGE when no output exists", () => { | |
| 909 | + const assistantWithToolCall: AssistantChatMessage = { | |
| 910 | + role: "assistant", | |
| 911 | + content: "I'll search for that", | |
| 912 | + toolCalls: [ | |
| 913 | + { | |
| 914 | + id: "search-call-1", | |
| 915 | + type: "function", | |
| 916 | + function: { | |
| 917 | + name: "search", | |
| 918 | + arguments: '{"query": "test"}', | |
| 919 | + }, | |
| 920 | + }, | |
| 921 | + ], | |
| 922 | + }; | |
| 923 | + | |
| 924 | + mockHistory = [ | |
| 925 | + { | |
| 926 | + message: assistantWithToolCall, | |
| 927 | + contextItems: [], | |
| 928 | + toolCallStates: [ | |
| 929 | + { | |
| 930 | + toolCallId: "search-call-1", | |
| 931 | + toolCall: { | |
| 932 | + id: "search-call-1", | |
| 933 | + type: "function", | |
| 934 | + function: { | |
| 935 | + name: "search", | |
| 936 | + arguments: '{"query": "test"}', | |
| 937 | + }, | |
| 938 | + }, | |
| 939 | + status: "generating", | |
| 940 | + parsedArgs: { query: "test" }, | |
| 941 | + // No output field | |
| 942 | + }, | |
| 943 | + ], | |
| 944 | + }, | |
| 945 | + ]; | |
| 946 | + | |
| 947 | + const { messages } = constructMessages( | |
| 948 | + mockHistory, | |
| 949 | + "Base System Message", | |
| 950 | + mockRules, | |
| 951 | + {}, | |
| 952 | + ); | |
| 953 | + | |
| 954 | + const toolMessage = messages[2] as ToolResultChatMessage; | |
| 955 | + expect(toolMessage.role).toBe("tool"); | |
| 956 | + expect(toolMessage.toolCallId).toBe("search-call-1"); | |
| 957 | + expect(toolMessage.content).toBe(NO_TOOL_CALL_OUTPUT_MESSAGE); | |
| 958 | + }); | |
| 959 | + | |
| 960 | + test("should use NO_TOOL_CALL_OUTPUT_MESSAGE when toolCallState is undefined", () => { | |
| 961 | + const assistantWithToolCall: AssistantChatMessage = { | |
| 962 | + role: "assistant", | |
| 963 | + content: "I'll search for that", | |
| 964 | + toolCalls: [ | |
| 965 | + { | |
| 966 | + id: "search-call-1", | |
| 967 | + type: "function", | |
| 968 | + function: { | |
| 969 | + name: "search", | |
| 970 | + arguments: '{"query": "test"}', | |
| 971 | + }, | |
| 972 | + }, | |
| 973 | + ], | |
| 974 | + }; | |
| 975 | + | |
| 976 | + mockHistory = [ | |
| 977 | + { | |
| 978 | + message: assistantWithToolCall, | |
| 979 | + contextItems: [], | |
| 980 | + // No toolCallStates array | |
| 981 | + }, | |
| 982 | + ]; | |
| 983 | + | |
| 984 | + const { messages } = constructMessages( | |
| 985 | + mockHistory, | |
| 986 | + "Base System Message", | |
| 987 | + mockRules, | |
| 988 | + {}, | |
| 989 | + ); | |
| 990 | + | |
| 991 | + const toolMessage = messages[2] as ToolResultChatMessage; | |
| 992 | + expect(toolMessage.role).toBe("tool"); | |
| 993 | + expect(toolMessage.toolCallId).toBe("search-call-1"); | |
| 994 | + expect(toolMessage.content).toBe(NO_TOOL_CALL_OUTPUT_MESSAGE); | |
| 995 | + }); | |
| 996 | + | |
| 997 | + test("should prioritize cancelled status over output content", () => { | |
| 998 | + const assistantWithTerminalCall: AssistantChatMessage = { | |
| 999 | + role: "assistant", | |
| 1000 | + content: "I'll run a command", | |
| 1001 | + toolCalls: [ | |
| 1002 | + { | |
| 1003 | + id: "terminal-call-1", | |
| 1004 | + type: "function", | |
| 1005 | + function: { | |
| 1006 | + name: BuiltInToolNames.RunTerminalCommand, | |
| 1007 | + arguments: '{"command": "ls"}', | |
| 1008 | + }, | |
| 1009 | + }, | |
| 1010 | + ], | |
| 1011 | + }; | |
| 1012 | + | |
| 1013 | + mockHistory = [ | |
| 1014 | + { | |
| 1015 | + message: assistantWithTerminalCall, | |
| 1016 | + contextItems: [], | |
| 1017 | + toolCallStates: [ | |
| 1018 | + { | |
| 1019 | + toolCallId: "terminal-call-1", | |
| 1020 | + toolCall: { | |
| 1021 | + id: "terminal-call-1", | |
| 1022 | + type: "function", | |
| 1023 | + function: { | |
| 1024 | + name: BuiltInToolNames.RunTerminalCommand, | |
| 1025 | + arguments: '{"command": "ls"}', | |
| 1026 | + }, | |
| 1027 | + }, | |
| 1028 | + status: "canceled", // Cancelled status | |
| 1029 | + parsedArgs: { command: "ls" }, | |
| 1030 | + output: [ | |
| 1031 | + createContextItem( | |
| 1032 | + "terminal-output", | |
| 1033 | + "This output should be ignored", | |
| 1034 | + ), | |
| 1035 | + ], // Has output but is cancelled | |
| 1036 | + }, | |
| 1037 | + ], | |
| 1038 | + }, | |
| 1039 | + ]; | |
| 1040 | + | |
| 1041 | + const { messages } = constructMessages( | |
| 1042 | + mockHistory, | |
| 1043 | + "Base System Message", | |
| 1044 | + mockRules, | |
| 1045 | + {}, | |
| 1046 | + ); | |
| 1047 | + | |
| 1048 | + const toolMessage = messages[2] as ToolResultChatMessage; | |
| 1049 | + expect(toolMessage.role).toBe("tool"); | |
| 1050 | + expect(toolMessage.toolCallId).toBe("terminal-call-1"); | |
| 1051 | + // Should use cancelled message, not the output content | |
| 1052 | + expect(toolMessage.content).toBe(CANCELLED_TOOL_CALL_MESSAGE); | |
| 1053 | + expect(toolMessage.content).not.toContain( | |
| 1054 | + "This output should be ignored", | |
| 1055 | + ); | |
| 1056 | + }); | |
| 1057 | + }); | |
| 715 | 1058 | }); |
modified gui/src/redux/util/constructMessages.ts +13 −1
| @@ -10,6 +10,7 @@ | ||
| 10 | 10 | import { chatMessageIsEmpty } from "core/llm/messages"; |
| 11 | 11 | import { getSystemMessageWithRules } from "core/llm/rules/getSystemMessageWithRules"; |
| 12 | 12 | import { RulePolicies } from "core/llm/rules/types"; |
| 13 | +import { BuiltInToolNames } from "core/tools/builtIn"; | |
| 13 | 14 | import { |
| 14 | 15 | CANCELLED_TOOL_CALL_MESSAGE, |
| 15 | 16 | NO_TOOL_CALL_OUTPUT_MESSAGE, |
| @@ -20,8 +21,13 @@ | ||
| 20 | 21 | import { |
| 21 | 22 | normalizeToMessageParts, |
| 22 | 23 | renderContextItems, |
| 24 | + renderContextItemsWithStatus, | |
| 23 | 25 | } from "core/util/messageContent"; |
| 24 | 26 | import { toolCallStateToContextItems } from "../../pages/gui/ToolCallDiv/utils"; |
| 27 | + | |
| 28 | +// Helper function to render context items and append status information | |
| 29 | +// Helper function to render context items and append status information | |
| 30 | + | |
| 25 | 31 | interface MessageWithContextItems { |
| 26 | 32 | ctxItems: ContextItemWithId[]; |
| 27 | 33 | message: ChatMessage; |
| @@ -132,8 +138,14 @@ | ||
| 132 | 138 | |
| 133 | 139 | if (toolCallState?.status === "canceled") { |
| 134 | 140 | content = CANCELLED_TOOL_CALL_MESSAGE; |
| 141 | + } else if ( | |
| 142 | + toolCallState?.output && | |
| 143 | + toolCall.function?.name == BuiltInToolNames.RunTerminalCommand | |
| 144 | + ) { | |
| 145 | + // Add status for tools containing detailed status outcomes per context item | |
| 146 | + content = renderContextItemsWithStatus(toolCallState.output); | |
| 135 | 147 | } else if (toolCallState?.output) { |
| 136 | - content = renderContextItems(toolCallState.output); | |
| 148 | + content = renderContextItems(toolCallState?.output); | |
| 137 | 149 | } |
| 138 | 150 | |
| 139 | 151 | msgs.push({ |
modified gui/src/styles/theme.ts +7 −0
| @@ -116,6 +116,13 @@ | ||
| 116 | 116 | vars: ["--vscode-badge-foreground"], |
| 117 | 117 | default: "#ffffff", // white |
| 118 | 118 | }, |
| 119 | + info: { | |
| 120 | + vars: [ | |
| 121 | + "--vscode-charts-blue", | |
| 122 | + "--vscode-notebookStatusRunningIcon-foreground", | |
| 123 | + ], | |
| 124 | + default: "#2196f3", // blue | |
| 125 | + }, | |
| 119 | 126 | success: { |
| 120 | 127 | vars: [ |
| 121 | 128 | "--vscode-notebookStatusSuccessIcon-foreground", |
modified gui/src/util/clientTools/editImpl.ts +27 −5
| @@ -12,12 +12,28 @@ | ||
| 12 | 12 | "`filepath` and `changes` arguments are required to edit an existing file.", |
| 13 | 13 | ); |
| 14 | 14 | } |
| 15 | - const firstUriMatch = await resolveRelativePathInDir( | |
| 16 | - args.filepath, | |
| 15 | + let filepath = args.filepath; | |
| 16 | + if (filepath.startsWith("./")) { | |
| 17 | + filepath = filepath.slice(2); | |
| 18 | + } | |
| 19 | + | |
| 20 | + const openFiles = await extras.ideMessenger.ide.getOpenFiles(); | |
| 21 | + let firstUriMatch = await resolveRelativePathInDir( | |
| 22 | + filepath, | |
| 17 | 23 | extras.ideMessenger.ide, |
| 18 | 24 | ); |
| 25 | + | |
| 26 | + if (!firstUriMatch) { | |
| 27 | + for (const uri of openFiles) { | |
| 28 | + if (uri.endsWith(filepath)) { | |
| 29 | + firstUriMatch = uri; | |
| 30 | + break; | |
| 31 | + } | |
| 32 | + } | |
| 33 | + } | |
| 34 | + | |
| 19 | 35 | if (!firstUriMatch) { |
| 20 | - throw new Error(`${args.filepath} does not exist`); | |
| 36 | + throw new Error(`${filepath} does not exist`); | |
| 21 | 37 | } |
| 22 | 38 | const streamId = uuid(); |
| 23 | 39 | void extras.dispatch( |
| @@ -30,7 +46,13 @@ | ||
| 30 | 46 | ); |
| 31 | 47 | |
| 32 | 48 | return { |
| 33 | - respondImmediately: false, | |
| 34 | - output: undefined, // No immediate output. | |
| 49 | + respondImmediately: true, | |
| 50 | + output: [ | |
| 51 | + { | |
| 52 | + name: "File edited successfully", | |
| 53 | + content: `Successfully initiated edit for ${firstUriMatch}`, | |
| 54 | + description: "File edit operation started", | |
| 55 | + }, | |
| 56 | + ], | |
| 35 | 57 | }; |
| 36 | 58 | }; |
modified gui/src/util/navigation.ts +29 −0
| @@ -1,7 +1,36 @@ | ||
| 1 | +// Valid config tab names | |
| 2 | +export type ConfigTab = | |
| 3 | + | "models" | |
| 4 | + | "rules" | |
| 5 | + | "tools" | |
| 6 | + | "agents" | |
| 7 | + | "organizations" | |
| 8 | + | "indexing" | |
| 9 | + | "settings" | |
| 10 | + | "help"; | |
| 11 | + | |
| 1 | 12 | // TODO: Move all the routes here |
| 2 | 13 | export const ROUTES = { |
| 3 | 14 | HOME: "/", |
| 4 | 15 | CONFIG: "/config", |
| 5 | 16 | THEME: "/theme", |
| 17 | + STATS: "/stats", | |
| 6 | 18 | // EXAMPLE_ROUTE_WITH_PARAMS: (params: ParamsType) => `/route/${params}`, |
| 7 | 19 | }; |
| 20 | + | |
| 21 | +// Helper function to build config URLs with tabs | |
| 22 | +export const buildConfigRoute = (tab?: ConfigTab): string => { | |
| 23 | + return tab ? `${ROUTES.CONFIG}?tab=${tab}` : ROUTES.CONFIG; | |
| 24 | +}; | |
| 25 | + | |
| 26 | +// Typed config route builders for common tabs | |
| 27 | +export const CONFIG_ROUTES = { | |
| 28 | + MODELS: buildConfigRoute("models"), | |
| 29 | + RULES: buildConfigRoute("rules"), | |
| 30 | + TOOLS: buildConfigRoute("tools"), | |
| 31 | + AGENTS: buildConfigRoute("agents"), | |
| 32 | + ORGANIZATIONS: buildConfigRoute("organizations"), | |
| 33 | + INDEXING: buildConfigRoute("indexing"), | |
| 34 | + SETTINGS: buildConfigRoute("settings"), | |
| 35 | + HELP: buildConfigRoute("help"), | |
| 36 | +} as const; |
modified gui/src/util/test/render.tsx +2 −5
| @@ -4,7 +4,6 @@ | ||
| 4 | 4 | import { PropsWithChildren } from "react"; |
| 5 | 5 | import { Provider } from "react-redux"; |
| 6 | 6 | import { MemoryRouter, RouterProps } from "react-router-dom"; |
| 7 | -import { LumpProvider } from "../../components/mainInput/Lump/LumpContext"; | |
| 8 | 7 | import { MainEditorProvider } from "../../components/mainInput/TipTapEditor"; |
| 9 | 8 | import { AuthProvider } from "../../context/Auth"; |
| 10 | 9 | import { IdeMessengerProvider } from "../../context/IdeMessenger"; |
| @@ -52,10 +51,8 @@ | ||
| 52 | 51 | <Provider store={store}> |
| 53 | 52 | <AuthProvider> |
| 54 | 53 | <MainEditorProvider> |
| 55 | - <LumpProvider> | |
| 56 | - {children} | |
| 57 | - <ParallelListeners /> | |
| 58 | - </LumpProvider> | |
| 54 | + {children} | |
| 55 | + <ParallelListeners /> | |
| 59 | 56 | </MainEditorProvider> |
| 60 | 57 | </AuthProvider> |
| 61 | 58 | </Provider> |
modified gui/src/util/test/utils.ts +1 −1
| @@ -14,7 +14,7 @@ | ||
| 14 | 14 | "", |
| 15 | 15 | ); |
| 16 | 16 | cleaned = cleaned?.replace( |
| 17 | - "Alt⏎ Active file⏎ Enter⏎Log in to access a free trial of theModels Add-OnLog in to Continue HubOr, configure your own models", | |
| 17 | + /[⌘Ctrl]+⏎ (?:No )?[Aa]ctive file⏎ Enter⏎Log in to access a free trial of theModels Add-OnLog in to Continue HubOr, configure your own models/, | |
| 18 | 18 | "", |
| 19 | 19 | ); |
| 20 | 20 | cleaned = cleaned.replaceAll("Select model", ""); |
modified gui/tailwind.config.cjs +1 −0
| @@ -81,6 +81,7 @@ | ||
| 81 | 81 | DEFAULT: varWithFallback("badge-background"), |
| 82 | 82 | foreground: varWithFallback("badge-foreground"), |
| 83 | 83 | }, |
| 84 | + info: varWithFallback("info"), | |
| 84 | 85 | success: varWithFallback("success"), |
| 85 | 86 | warning: varWithFallback("warning"), |
| 86 | 87 | error: varWithFallback("error"), |
modified packages/config-yaml/src/schemas/models.ts +4 −1
| @@ -37,8 +37,11 @@ | ||
| 37 | 37 | z.literal("tool_use"), |
| 38 | 38 | z.literal("image_input"), |
| 39 | 39 | z.literal("next_edit"), |
| 40 | + z.string(), // Needed for forwards compatibility, see https://github.com/continuedev/continue/pull/7676 | |
| 40 | 41 | ]); |
| 41 | -export type ModelCapability = z.infer<typeof modelCapabilitySchema>; | |
| 42 | + | |
| 43 | +// not ideal but lose type suggestions if use z.infer because of the string fallback | |
| 44 | +export type ModelCapability = "tool_use" | "image_input" | "next_edit"; | |
| 42 | 45 | |
| 43 | 46 | export const completionOptionsSchema = z.object({ |
| 44 | 47 | contextLength: z.number().optional(), |