From fb7a145c1caedeedac00673103e2f035618c8338 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 24 Apr 2025 16:07:57 -0700 Subject: [PATCH 1/3] notch tooltips --- extensions/vscode/package-lock.json | 4 +- .../Lump/BlockSettingsTopToolbar.tsx | 136 +++++++++++------- .../mainInput/Lump/sections/MCPSection.tsx | 5 - .../mainInput/Lump/sections/RulesSection.tsx | 4 + .../Lump/sections/SelectedSection.tsx | 4 +- .../sections/{ => errors}/ErrorSection.tsx | 2 +- .../sections/errors/ErrorsSectionTooltip.tsx | 14 ++ .../Lump/sections/mcp/MCPSection.tsx | 5 + .../Lump/sections/mcp/MCPTooltip.tsx | 18 +++ .../ToolPoliciesSectionTooltip.tsx | 16 +++ gui/src/redux/selectors/selectActiveTools.ts | 22 +++ gui/src/redux/slices/sessionSlice.ts | 4 - gui/src/redux/slices/uiSlice.ts | 13 +- gui/src/redux/thunks/streamNormalInput.ts | 31 ++-- 14 files changed, 193 insertions(+), 85 deletions(-) delete mode 100644 gui/src/components/mainInput/Lump/sections/MCPSection.tsx rename gui/src/components/mainInput/Lump/sections/{ => errors}/ErrorSection.tsx (95%) create mode 100644 gui/src/components/mainInput/Lump/sections/errors/ErrorsSectionTooltip.tsx create mode 100644 gui/src/components/mainInput/Lump/sections/mcp/MCPSection.tsx create mode 100644 gui/src/components/mainInput/Lump/sections/mcp/MCPTooltip.tsx create mode 100644 gui/src/components/mainInput/Lump/sections/tool-policies/ToolPoliciesSectionTooltip.tsx create mode 100644 gui/src/redux/selectors/selectActiveTools.ts diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 7cf0b9dd7..805cd2d4a 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "1.1.24", + "version": "1.1.25", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "1.1.24", + "version": "1.1.25", "license": "Apache-2.0", "dependencies": { "@continuedev/fetch": "^1.0.3", diff --git a/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx b/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx index 2ec82b660..00d00a8c7 100644 --- a/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx +++ b/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx @@ -9,15 +9,21 @@ import { Squares2X2Icon, WrenchScrewdriverIcon, } from "@heroicons/react/24/outline"; +import { ReactNode } from "react"; import { vscBadgeForeground } from "../.."; import { useAppSelector } from "../../../redux/hooks"; import { fontSize } from "../../../util"; +import { ToolTip } from "../../gui/Tooltip"; import AssistantSelect from "../../modelSelection/platform/AssistantSelect"; import HoverItem from "../InputToolbar/HoverItem"; import { useLump } from "./LumpContext"; +import { ErrorsSectionTooltip } from "./sections/errors/ErrorsSectionTooltip"; +import { McpSectionTooltip } from "./sections/mcp/MCPTooltip"; +import { ToolsSectionTooltip } from "./sections/tool-policies/ToolPoliciesSectionTooltip"; interface BlockSettingsToolbarIcon { - tooltip: string; + title: string; + tooltip: ReactNode; icon: React.ComponentType; itemCount?: number; onClick: () => void; @@ -27,18 +33,39 @@ interface BlockSettingsToolbarIcon { interface Section { id: string; - tooltip: string; + title: string; + tooltip: ReactNode; icon: React.ComponentType; } const sections: Section[] = [ - { id: "models", tooltip: "Models", icon: CubeIcon }, - { id: "rules", tooltip: "Rules", icon: PencilIcon }, - { id: "docs", tooltip: "Docs", icon: BookOpenIcon }, - { id: "prompts", tooltip: "Prompts", icon: ChatBubbleLeftIcon }, - { id: "tools", tooltip: "Tools", icon: WrenchScrewdriverIcon }, - { id: "mcp", tooltip: "MCP", icon: Squares2X2Icon }, - { id: "error", tooltip: "Errors", icon: ExclamationTriangleIcon }, + { id: "models", title: "Models", tooltip: "Models", icon: CubeIcon }, + { id: "rules", title: "Rules", tooltip: "Rules", icon: PencilIcon }, + { id: "docs", title: "Docs", tooltip: "Docs", icon: BookOpenIcon }, + { + id: "prompts", + title: "Prompts", + tooltip: "Prompts", + icon: ChatBubbleLeftIcon, + }, + { + id: "tools", + title: "Tools", + tooltip: , + icon: WrenchScrewdriverIcon, + }, + { + id: "mcp", + title: "MCP", + tooltip: , + icon: Squares2X2Icon, + }, + { + id: "error", + title: "Errors", + tooltip: , + icon: ExclamationTriangleIcon, + }, ]; function BlockSettingsToolbarIcon( @@ -46,53 +73,60 @@ function BlockSettingsToolbarIcon( ) { const isErrorSection = props.sectionId === "error"; + const id = `block-settings-toolbar-icon-${props.sectionId}`; return ( - -
{ - if (e.key === "Enter" || e.key === " ") { - e.preventDefault(); - props.onClick(); - } - }} - className={`${ - props.isSelected - ? isErrorSection - ? "bg-red-600" - : "bg-badge" - : undefined - } relative flex select-none items-center rounded-full px-1 transition-all duration-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/50 ${props.className || ""}`} + <> + -
-
+ + + {props.tooltip} + + ); } @@ -129,6 +163,7 @@ export function BlockSettingsTopToolbar() { tooltip={ isToolbarExpanded ? "Collapse sections" : "Expand sections" } + title="" isSelected={false} onClick={handleEllipsisClick} /> @@ -142,6 +177,7 @@ export function BlockSettingsTopToolbar() { sectionId={section.id} icon={section.icon} tooltip={section.tooltip} + title={section.title} isSelected={selectedSection === section.id} onClick={() => setSelectedSection( diff --git a/gui/src/components/mainInput/Lump/sections/MCPSection.tsx b/gui/src/components/mainInput/Lump/sections/MCPSection.tsx deleted file mode 100644 index b365dca34..000000000 --- a/gui/src/components/mainInput/Lump/sections/MCPSection.tsx +++ /dev/null @@ -1,5 +0,0 @@ -import MCPServersPreview from "../../../../pages/config/MCPServersPreview"; - -export function MCPSection() { - return ; -} diff --git a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx index 0fae7611e..d6129eef8 100644 --- a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx @@ -209,3 +209,7 @@ export function RulesSection() { ); } + +export function RulesSectionToolTip() { + return "rules"; +} diff --git a/gui/src/components/mainInput/Lump/sections/SelectedSection.tsx b/gui/src/components/mainInput/Lump/sections/SelectedSection.tsx index 85f72078f..f7fca7a35 100644 --- a/gui/src/components/mainInput/Lump/sections/SelectedSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/SelectedSection.tsx @@ -1,8 +1,8 @@ import { useLump } from "../LumpContext"; import { ContextSection } from "./ContextSection"; import DocsSection from "./docs/DocsSection"; -import { ErrorSection } from "./ErrorSection"; -import { MCPSection } from "./MCPSection"; +import { ErrorSection } from "./errors/ErrorSection"; +import { MCPSection } from "./mcp/MCPSection"; import { ModelsSection } from "./ModelsSection"; import { PromptsSection } from "./PromptsSection"; import { RulesSection } from "./RulesSection"; diff --git a/gui/src/components/mainInput/Lump/sections/ErrorSection.tsx b/gui/src/components/mainInput/Lump/sections/errors/ErrorSection.tsx similarity index 95% rename from gui/src/components/mainInput/Lump/sections/ErrorSection.tsx rename to gui/src/components/mainInput/Lump/sections/errors/ErrorSection.tsx index d4d01141c..dbd72de65 100644 --- a/gui/src/components/mainInput/Lump/sections/ErrorSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/errors/ErrorSection.tsx @@ -2,7 +2,7 @@ import { ExclamationCircleIcon, ExclamationTriangleIcon, } from "@heroicons/react/24/outline"; -import { useAppSelector } from "../../../../redux/hooks"; +import { useAppSelector } from "../../../../../redux/hooks"; export function ErrorSection() { const configError = useAppSelector((state) => state.config.configError); diff --git a/gui/src/components/mainInput/Lump/sections/errors/ErrorsSectionTooltip.tsx b/gui/src/components/mainInput/Lump/sections/errors/ErrorsSectionTooltip.tsx new file mode 100644 index 000000000..fd2199ede --- /dev/null +++ b/gui/src/components/mainInput/Lump/sections/errors/ErrorsSectionTooltip.tsx @@ -0,0 +1,14 @@ +import { useAppSelector } from "../../../../../redux/hooks"; + +export const ErrorsSectionTooltip = () => { + const configError = useAppSelector((store) => store.config.configError); + + const numErrors = configError?.length ?? 0; + const plural = numErrors > 1 ? "s" : ""; + + return ( +
+ {`${numErrors} Config Error${plural}`} +
+ ); +}; diff --git a/gui/src/components/mainInput/Lump/sections/mcp/MCPSection.tsx b/gui/src/components/mainInput/Lump/sections/mcp/MCPSection.tsx new file mode 100644 index 000000000..9c2f888eb --- /dev/null +++ b/gui/src/components/mainInput/Lump/sections/mcp/MCPSection.tsx @@ -0,0 +1,5 @@ +import MCPServersPreview from "../../../../../pages/config/MCPServersPreview"; + +export function MCPSection() { + return ; +} diff --git a/gui/src/components/mainInput/Lump/sections/mcp/MCPTooltip.tsx b/gui/src/components/mainInput/Lump/sections/mcp/MCPTooltip.tsx new file mode 100644 index 000000000..b06528fdb --- /dev/null +++ b/gui/src/components/mainInput/Lump/sections/mcp/MCPTooltip.tsx @@ -0,0 +1,18 @@ +import { useAppSelector } from "../../../../../redux/hooks"; + +export const McpSectionTooltip = () => { + const mcpServers = useAppSelector( + (store) => store.config.config.mcpServerStatuses, + ); + + const numServers = mcpServers.length; + const numActiveServers = mcpServers.filter( + (server) => server.status === "connected", + ).length; + + return ( +
+ {`MCP Servers (${numActiveServers}/${numServers} active)`} +
+ ); +}; diff --git a/gui/src/components/mainInput/Lump/sections/tool-policies/ToolPoliciesSectionTooltip.tsx b/gui/src/components/mainInput/Lump/sections/tool-policies/ToolPoliciesSectionTooltip.tsx new file mode 100644 index 000000000..7e3334b1a --- /dev/null +++ b/gui/src/components/mainInput/Lump/sections/tool-policies/ToolPoliciesSectionTooltip.tsx @@ -0,0 +1,16 @@ +import { useAppSelector } from "../../../../../redux/hooks"; +import { selectActiveTools } from "../../../../../redux/selectors/selectActiveTools"; + +export const ToolsSectionTooltip = () => { + const tools = useAppSelector((store) => store.config.config.tools); + const activeTools = useAppSelector(selectActiveTools); + + const numTools = tools.length; + const numActiveTools = activeTools.length; + + return ( +
+ {`Tools (${numActiveTools}/${numTools} active)`} +
+ ); +}; diff --git a/gui/src/redux/selectors/selectActiveTools.ts b/gui/src/redux/selectors/selectActiveTools.ts new file mode 100644 index 000000000..bae3426e0 --- /dev/null +++ b/gui/src/redux/selectors/selectActiveTools.ts @@ -0,0 +1,22 @@ +import { createSelector } from "@reduxjs/toolkit"; +import { Tool } from "core"; +import { RootState } from "../store"; + +export const selectActiveTools = createSelector( + [ + (store: RootState) => store.session.mode, + (store: RootState) => store.config.config.tools, + (store: RootState) => store.ui.toolSettings, + (store: RootState) => store.ui.toolGroupSettings, + ], + (mode, tools, policies, groupPolicies): Tool[] => { + if (mode !== "agent") { + return []; + } + return tools.filter( + (tool) => + policies[tool.function.name] !== "disabled" && + groupPolicies[tool.group] !== "exclude", + ); + }, +); diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 002b809db..6adbabcf7 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -768,9 +768,6 @@ export const sessionSlice = createSlice({ selectHasCodeToEdit: (state) => { return state.codeToEdit.length > 0; }, - selectUseTools: (state) => { - return state.mode === "agent"; - }, }, extraReducers: (builder) => { addPassthroughCases(builder, [streamResponseThunk]); @@ -852,7 +849,6 @@ export const { selectCurrentMode, selectIsSingleRangeEditOrInsertion, selectHasCodeToEdit, - selectUseTools, } = sessionSlice.selectors; export default sessionSlice.reducer; diff --git a/gui/src/redux/slices/uiSlice.ts b/gui/src/redux/slices/uiSlice.ts index 7cc964cd6..2fb5f4759 100644 --- a/gui/src/redux/slices/uiSlice.ts +++ b/gui/src/redux/slices/uiSlice.ts @@ -7,12 +7,15 @@ import { } from "../../components/OnboardingCard"; import { getLocalStorage, LocalStorageKey } from "../../util/localStorage"; -type ToolSetting = +export type ToolPolicy = | "allowedWithPermission" | "allowedWithoutPermission" | "disabled"; -type ToolGroupSetting = "include" | "exclude"; +export type ToolGroupPolicy = "include" | "exclude"; + +export type ToolPolicies = { [toolName: string]: ToolPolicy }; +export type ToolGroupPolicies = { [toolGroupName: string]: ToolGroupPolicy }; type UIState = { showDialog: boolean; @@ -22,12 +25,12 @@ type UIState = { isExploreDialogOpen: boolean; hasDismissedExploreDialog: boolean; shouldAddFileForEditing: boolean; - toolSettings: { [toolName: string]: ToolSetting }; - toolGroupSettings: { [toolGroupName: string]: ToolGroupSetting }; + toolSettings: ToolPolicies; + toolGroupSettings: ToolGroupPolicies; ttsActive: boolean; }; -export const DEFAULT_TOOL_SETTING: ToolSetting = "allowedWithPermission"; +export const DEFAULT_TOOL_SETTING: ToolPolicy = "allowedWithPermission"; export const uiSlice = createSlice({ name: "ui", diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts index 819ec79ee..43e431271 100644 --- a/gui/src/redux/thunks/streamNormalInput.ts +++ b/gui/src/redux/thunks/streamNormalInput.ts @@ -1,13 +1,13 @@ import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit"; -import { ChatMessage } from "core"; +import { ChatMessage, LLMFullCompletionOptions } from "core"; import { modelSupportsTools } from "core/llm/autodetect"; import { ToCoreProtocol } from "core/protocol"; +import { selectActiveTools } from "../selectors/selectActiveTools"; import { selectCurrentToolCall } from "../selectors/selectCurrentToolCall"; import { selectSelectedChatModel } from "../slices/configSlice"; import { abortStream, addPromptCompletionPair, - selectUseTools, setToolGenerated, streamUpdate, } from "../slices/sessionSlice"; @@ -31,27 +31,24 @@ export const streamNormalInput = createAsyncThunk< const state = getState(); const selectedChatModel = selectSelectedChatModel(state); - const toolSettings = state.ui.toolSettings; - const toolGroupSettings = state.ui.toolGroupSettings; const streamAborter = state.session.streamAborter; - const useTools = selectUseTools(state); if (!selectedChatModel) { throw new Error("Default model not defined"); } - const includeTools = useTools && modelSupportsTools(selectedChatModel); + + let completionOptions: LLMFullCompletionOptions = {}; + const activeTools = selectActiveTools(state); + const toolsSupported = modelSupportsTools(selectedChatModel); + if (toolsSupported && activeTools.length > 0) { + completionOptions = { + tools: activeTools, + }; + } // Send request const gen = extra.ideMessenger.llmStreamChat( { - completionOptions: includeTools - ? { - tools: state.config.config.tools.filter( - (tool) => - toolSettings[tool.function.name] !== "disabled" && - toolGroupSettings[tool.group] !== "exclude", - ), - } - : {}, + completionOptions, title: selectedChatModel.title, messages, legacySlashCommandData, @@ -105,7 +102,9 @@ export const streamNormalInput = createAsyncThunk< } // If it's a tool call that is automatically accepted, we should call it - const toolCallState = selectCurrentToolCall(getState()); + const newState = getState(); + const toolSettings = newState.ui.toolSettings; + const toolCallState = selectCurrentToolCall(newState); if (toolCallState) { dispatch( setToolGenerated({ From 8f2337c08d27133ed67ade17b54fa679ac5afaaf Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 24 Apr 2025 16:07:57 -0700 Subject: [PATCH 2/3] notch tooltips Co-authored-by: uinstinct <61635505+uinstinct@users.noreply.github.com> --- extensions/vscode/package-lock.json | 4 +- .../Lump/BlockSettingsTopToolbar.tsx | 136 +++++++++++------- .../mainInput/Lump/sections/MCPSection.tsx | 5 - .../mainInput/Lump/sections/RulesSection.tsx | 4 + .../Lump/sections/SelectedSection.tsx | 4 +- .../sections/{ => errors}/ErrorSection.tsx | 2 +- .../sections/errors/ErrorsSectionTooltip.tsx | 14 ++ .../Lump/sections/mcp/MCPSection.tsx | 5 + .../Lump/sections/mcp/MCPTooltip.tsx | 18 +++ .../ToolPoliciesSectionTooltip.tsx | 16 +++ gui/src/redux/selectors/selectActiveTools.ts | 22 +++ gui/src/redux/slices/sessionSlice.ts | 4 - gui/src/redux/slices/uiSlice.ts | 13 +- gui/src/redux/thunks/streamNormalInput.ts | 31 ++-- 14 files changed, 193 insertions(+), 85 deletions(-) delete mode 100644 gui/src/components/mainInput/Lump/sections/MCPSection.tsx rename gui/src/components/mainInput/Lump/sections/{ => errors}/ErrorSection.tsx (95%) create mode 100644 gui/src/components/mainInput/Lump/sections/errors/ErrorsSectionTooltip.tsx create mode 100644 gui/src/components/mainInput/Lump/sections/mcp/MCPSection.tsx create mode 100644 gui/src/components/mainInput/Lump/sections/mcp/MCPTooltip.tsx create mode 100644 gui/src/components/mainInput/Lump/sections/tool-policies/ToolPoliciesSectionTooltip.tsx create mode 100644 gui/src/redux/selectors/selectActiveTools.ts diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 7cf0b9dd7..805cd2d4a 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "1.1.24", + "version": "1.1.25", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "1.1.24", + "version": "1.1.25", "license": "Apache-2.0", "dependencies": { "@continuedev/fetch": "^1.0.3", diff --git a/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx b/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx index 2ec82b660..00d00a8c7 100644 --- a/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx +++ b/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx @@ -9,15 +9,21 @@ import { Squares2X2Icon, WrenchScrewdriverIcon, } from "@heroicons/react/24/outline"; +import { ReactNode } from "react"; import { vscBadgeForeground } from "../.."; import { useAppSelector } from "../../../redux/hooks"; import { fontSize } from "../../../util"; +import { ToolTip } from "../../gui/Tooltip"; import AssistantSelect from "../../modelSelection/platform/AssistantSelect"; import HoverItem from "../InputToolbar/HoverItem"; import { useLump } from "./LumpContext"; +import { ErrorsSectionTooltip } from "./sections/errors/ErrorsSectionTooltip"; +import { McpSectionTooltip } from "./sections/mcp/MCPTooltip"; +import { ToolsSectionTooltip } from "./sections/tool-policies/ToolPoliciesSectionTooltip"; interface BlockSettingsToolbarIcon { - tooltip: string; + title: string; + tooltip: ReactNode; icon: React.ComponentType; itemCount?: number; onClick: () => void; @@ -27,18 +33,39 @@ interface BlockSettingsToolbarIcon { interface Section { id: string; - tooltip: string; + title: string; + tooltip: ReactNode; icon: React.ComponentType; } const sections: Section[] = [ - { id: "models", tooltip: "Models", icon: CubeIcon }, - { id: "rules", tooltip: "Rules", icon: PencilIcon }, - { id: "docs", tooltip: "Docs", icon: BookOpenIcon }, - { id: "prompts", tooltip: "Prompts", icon: ChatBubbleLeftIcon }, - { id: "tools", tooltip: "Tools", icon: WrenchScrewdriverIcon }, - { id: "mcp", tooltip: "MCP", icon: Squares2X2Icon }, - { id: "error", tooltip: "Errors", icon: ExclamationTriangleIcon }, + { id: "models", title: "Models", tooltip: "Models", icon: CubeIcon }, + { id: "rules", title: "Rules", tooltip: "Rules", icon: PencilIcon }, + { id: "docs", title: "Docs", tooltip: "Docs", icon: BookOpenIcon }, + { + id: "prompts", + title: "Prompts", + tooltip: "Prompts", + icon: ChatBubbleLeftIcon, + }, + { + id: "tools", + title: "Tools", + tooltip: , + icon: WrenchScrewdriverIcon, + }, + { + id: "mcp", + title: "MCP", + tooltip: , + icon: Squares2X2Icon, + }, + { + id: "error", + title: "Errors", + tooltip: , + icon: ExclamationTriangleIcon, + }, ]; function BlockSettingsToolbarIcon( @@ -46,53 +73,60 @@ function BlockSettingsToolbarIcon( ) { const isErrorSection = props.sectionId === "error"; + const id = `block-settings-toolbar-icon-${props.sectionId}`; return ( - -
{ - if (e.key === "Enter" || e.key === " ") { - e.preventDefault(); - props.onClick(); - } - }} - className={`${ - props.isSelected - ? isErrorSection - ? "bg-red-600" - : "bg-badge" - : undefined - } relative flex select-none items-center rounded-full px-1 transition-all duration-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/50 ${props.className || ""}`} + <> + -
-
+ + + {props.tooltip} + + ); } @@ -129,6 +163,7 @@ export function BlockSettingsTopToolbar() { tooltip={ isToolbarExpanded ? "Collapse sections" : "Expand sections" } + title="" isSelected={false} onClick={handleEllipsisClick} /> @@ -142,6 +177,7 @@ export function BlockSettingsTopToolbar() { sectionId={section.id} icon={section.icon} tooltip={section.tooltip} + title={section.title} isSelected={selectedSection === section.id} onClick={() => setSelectedSection( diff --git a/gui/src/components/mainInput/Lump/sections/MCPSection.tsx b/gui/src/components/mainInput/Lump/sections/MCPSection.tsx deleted file mode 100644 index b365dca34..000000000 --- a/gui/src/components/mainInput/Lump/sections/MCPSection.tsx +++ /dev/null @@ -1,5 +0,0 @@ -import MCPServersPreview from "../../../../pages/config/MCPServersPreview"; - -export function MCPSection() { - return ; -} diff --git a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx index 0fae7611e..d6129eef8 100644 --- a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx @@ -209,3 +209,7 @@ export function RulesSection() { ); } + +export function RulesSectionToolTip() { + return "rules"; +} diff --git a/gui/src/components/mainInput/Lump/sections/SelectedSection.tsx b/gui/src/components/mainInput/Lump/sections/SelectedSection.tsx index 85f72078f..f7fca7a35 100644 --- a/gui/src/components/mainInput/Lump/sections/SelectedSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/SelectedSection.tsx @@ -1,8 +1,8 @@ import { useLump } from "../LumpContext"; import { ContextSection } from "./ContextSection"; import DocsSection from "./docs/DocsSection"; -import { ErrorSection } from "./ErrorSection"; -import { MCPSection } from "./MCPSection"; +import { ErrorSection } from "./errors/ErrorSection"; +import { MCPSection } from "./mcp/MCPSection"; import { ModelsSection } from "./ModelsSection"; import { PromptsSection } from "./PromptsSection"; import { RulesSection } from "./RulesSection"; diff --git a/gui/src/components/mainInput/Lump/sections/ErrorSection.tsx b/gui/src/components/mainInput/Lump/sections/errors/ErrorSection.tsx similarity index 95% rename from gui/src/components/mainInput/Lump/sections/ErrorSection.tsx rename to gui/src/components/mainInput/Lump/sections/errors/ErrorSection.tsx index d4d01141c..dbd72de65 100644 --- a/gui/src/components/mainInput/Lump/sections/ErrorSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/errors/ErrorSection.tsx @@ -2,7 +2,7 @@ import { ExclamationCircleIcon, ExclamationTriangleIcon, } from "@heroicons/react/24/outline"; -import { useAppSelector } from "../../../../redux/hooks"; +import { useAppSelector } from "../../../../../redux/hooks"; export function ErrorSection() { const configError = useAppSelector((state) => state.config.configError); diff --git a/gui/src/components/mainInput/Lump/sections/errors/ErrorsSectionTooltip.tsx b/gui/src/components/mainInput/Lump/sections/errors/ErrorsSectionTooltip.tsx new file mode 100644 index 000000000..fd2199ede --- /dev/null +++ b/gui/src/components/mainInput/Lump/sections/errors/ErrorsSectionTooltip.tsx @@ -0,0 +1,14 @@ +import { useAppSelector } from "../../../../../redux/hooks"; + +export const ErrorsSectionTooltip = () => { + const configError = useAppSelector((store) => store.config.configError); + + const numErrors = configError?.length ?? 0; + const plural = numErrors > 1 ? "s" : ""; + + return ( +
+ {`${numErrors} Config Error${plural}`} +
+ ); +}; diff --git a/gui/src/components/mainInput/Lump/sections/mcp/MCPSection.tsx b/gui/src/components/mainInput/Lump/sections/mcp/MCPSection.tsx new file mode 100644 index 000000000..9c2f888eb --- /dev/null +++ b/gui/src/components/mainInput/Lump/sections/mcp/MCPSection.tsx @@ -0,0 +1,5 @@ +import MCPServersPreview from "../../../../../pages/config/MCPServersPreview"; + +export function MCPSection() { + return ; +} diff --git a/gui/src/components/mainInput/Lump/sections/mcp/MCPTooltip.tsx b/gui/src/components/mainInput/Lump/sections/mcp/MCPTooltip.tsx new file mode 100644 index 000000000..b06528fdb --- /dev/null +++ b/gui/src/components/mainInput/Lump/sections/mcp/MCPTooltip.tsx @@ -0,0 +1,18 @@ +import { useAppSelector } from "../../../../../redux/hooks"; + +export const McpSectionTooltip = () => { + const mcpServers = useAppSelector( + (store) => store.config.config.mcpServerStatuses, + ); + + const numServers = mcpServers.length; + const numActiveServers = mcpServers.filter( + (server) => server.status === "connected", + ).length; + + return ( +
+ {`MCP Servers (${numActiveServers}/${numServers} active)`} +
+ ); +}; diff --git a/gui/src/components/mainInput/Lump/sections/tool-policies/ToolPoliciesSectionTooltip.tsx b/gui/src/components/mainInput/Lump/sections/tool-policies/ToolPoliciesSectionTooltip.tsx new file mode 100644 index 000000000..7e3334b1a --- /dev/null +++ b/gui/src/components/mainInput/Lump/sections/tool-policies/ToolPoliciesSectionTooltip.tsx @@ -0,0 +1,16 @@ +import { useAppSelector } from "../../../../../redux/hooks"; +import { selectActiveTools } from "../../../../../redux/selectors/selectActiveTools"; + +export const ToolsSectionTooltip = () => { + const tools = useAppSelector((store) => store.config.config.tools); + const activeTools = useAppSelector(selectActiveTools); + + const numTools = tools.length; + const numActiveTools = activeTools.length; + + return ( +
+ {`Tools (${numActiveTools}/${numTools} active)`} +
+ ); +}; diff --git a/gui/src/redux/selectors/selectActiveTools.ts b/gui/src/redux/selectors/selectActiveTools.ts new file mode 100644 index 000000000..bae3426e0 --- /dev/null +++ b/gui/src/redux/selectors/selectActiveTools.ts @@ -0,0 +1,22 @@ +import { createSelector } from "@reduxjs/toolkit"; +import { Tool } from "core"; +import { RootState } from "../store"; + +export const selectActiveTools = createSelector( + [ + (store: RootState) => store.session.mode, + (store: RootState) => store.config.config.tools, + (store: RootState) => store.ui.toolSettings, + (store: RootState) => store.ui.toolGroupSettings, + ], + (mode, tools, policies, groupPolicies): Tool[] => { + if (mode !== "agent") { + return []; + } + return tools.filter( + (tool) => + policies[tool.function.name] !== "disabled" && + groupPolicies[tool.group] !== "exclude", + ); + }, +); diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 002b809db..6adbabcf7 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -768,9 +768,6 @@ export const sessionSlice = createSlice({ selectHasCodeToEdit: (state) => { return state.codeToEdit.length > 0; }, - selectUseTools: (state) => { - return state.mode === "agent"; - }, }, extraReducers: (builder) => { addPassthroughCases(builder, [streamResponseThunk]); @@ -852,7 +849,6 @@ export const { selectCurrentMode, selectIsSingleRangeEditOrInsertion, selectHasCodeToEdit, - selectUseTools, } = sessionSlice.selectors; export default sessionSlice.reducer; diff --git a/gui/src/redux/slices/uiSlice.ts b/gui/src/redux/slices/uiSlice.ts index 7cc964cd6..2fb5f4759 100644 --- a/gui/src/redux/slices/uiSlice.ts +++ b/gui/src/redux/slices/uiSlice.ts @@ -7,12 +7,15 @@ import { } from "../../components/OnboardingCard"; import { getLocalStorage, LocalStorageKey } from "../../util/localStorage"; -type ToolSetting = +export type ToolPolicy = | "allowedWithPermission" | "allowedWithoutPermission" | "disabled"; -type ToolGroupSetting = "include" | "exclude"; +export type ToolGroupPolicy = "include" | "exclude"; + +export type ToolPolicies = { [toolName: string]: ToolPolicy }; +export type ToolGroupPolicies = { [toolGroupName: string]: ToolGroupPolicy }; type UIState = { showDialog: boolean; @@ -22,12 +25,12 @@ type UIState = { isExploreDialogOpen: boolean; hasDismissedExploreDialog: boolean; shouldAddFileForEditing: boolean; - toolSettings: { [toolName: string]: ToolSetting }; - toolGroupSettings: { [toolGroupName: string]: ToolGroupSetting }; + toolSettings: ToolPolicies; + toolGroupSettings: ToolGroupPolicies; ttsActive: boolean; }; -export const DEFAULT_TOOL_SETTING: ToolSetting = "allowedWithPermission"; +export const DEFAULT_TOOL_SETTING: ToolPolicy = "allowedWithPermission"; export const uiSlice = createSlice({ name: "ui", diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts index 819ec79ee..43e431271 100644 --- a/gui/src/redux/thunks/streamNormalInput.ts +++ b/gui/src/redux/thunks/streamNormalInput.ts @@ -1,13 +1,13 @@ import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit"; -import { ChatMessage } from "core"; +import { ChatMessage, LLMFullCompletionOptions } from "core"; import { modelSupportsTools } from "core/llm/autodetect"; import { ToCoreProtocol } from "core/protocol"; +import { selectActiveTools } from "../selectors/selectActiveTools"; import { selectCurrentToolCall } from "../selectors/selectCurrentToolCall"; import { selectSelectedChatModel } from "../slices/configSlice"; import { abortStream, addPromptCompletionPair, - selectUseTools, setToolGenerated, streamUpdate, } from "../slices/sessionSlice"; @@ -31,27 +31,24 @@ export const streamNormalInput = createAsyncThunk< const state = getState(); const selectedChatModel = selectSelectedChatModel(state); - const toolSettings = state.ui.toolSettings; - const toolGroupSettings = state.ui.toolGroupSettings; const streamAborter = state.session.streamAborter; - const useTools = selectUseTools(state); if (!selectedChatModel) { throw new Error("Default model not defined"); } - const includeTools = useTools && modelSupportsTools(selectedChatModel); + + let completionOptions: LLMFullCompletionOptions = {}; + const activeTools = selectActiveTools(state); + const toolsSupported = modelSupportsTools(selectedChatModel); + if (toolsSupported && activeTools.length > 0) { + completionOptions = { + tools: activeTools, + }; + } // Send request const gen = extra.ideMessenger.llmStreamChat( { - completionOptions: includeTools - ? { - tools: state.config.config.tools.filter( - (tool) => - toolSettings[tool.function.name] !== "disabled" && - toolGroupSettings[tool.group] !== "exclude", - ), - } - : {}, + completionOptions, title: selectedChatModel.title, messages, legacySlashCommandData, @@ -105,7 +102,9 @@ export const streamNormalInput = createAsyncThunk< } // If it's a tool call that is automatically accepted, we should call it - const toolCallState = selectCurrentToolCall(getState()); + const newState = getState(); + const toolSettings = newState.ui.toolSettings; + const toolCallState = selectCurrentToolCall(newState); if (toolCallState) { dispatch( setToolGenerated({ From effcaeaefeef2633bebef8dce101cf5ee6bac836 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 24 Apr 2025 16:21:44 -0700 Subject: [PATCH 3/3] rearrange/cleanup --- .../mainInput/Lump/sections/RulesSection.tsx | 4 - .../Lump/sections/SelectedSection.tsx | 2 +- .../Lump/sections/mcp/MCPSection.tsx | 190 +++++++++++++++++- gui/src/pages/config/MCPServersPreview.tsx | 189 ----------------- 4 files changed, 188 insertions(+), 197 deletions(-) delete mode 100644 gui/src/pages/config/MCPServersPreview.tsx diff --git a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx index d6129eef8..0fae7611e 100644 --- a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx @@ -209,7 +209,3 @@ export function RulesSection() { ); } - -export function RulesSectionToolTip() { - return "rules"; -} diff --git a/gui/src/components/mainInput/Lump/sections/SelectedSection.tsx b/gui/src/components/mainInput/Lump/sections/SelectedSection.tsx index f7fca7a35..ad07a86d6 100644 --- a/gui/src/components/mainInput/Lump/sections/SelectedSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/SelectedSection.tsx @@ -2,7 +2,7 @@ import { useLump } from "../LumpContext"; import { ContextSection } from "./ContextSection"; import DocsSection from "./docs/DocsSection"; import { ErrorSection } from "./errors/ErrorSection"; -import { MCPSection } from "./mcp/MCPSection"; +import MCPSection from "./mcp/MCPSection"; import { ModelsSection } from "./ModelsSection"; import { PromptsSection } from "./PromptsSection"; import { RulesSection } from "./RulesSection"; diff --git a/gui/src/components/mainInput/Lump/sections/mcp/MCPSection.tsx b/gui/src/components/mainInput/Lump/sections/mcp/MCPSection.tsx index 9c2f888eb..07ec23c56 100644 --- a/gui/src/components/mainInput/Lump/sections/mcp/MCPSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/mcp/MCPSection.tsx @@ -1,5 +1,189 @@ -import MCPServersPreview from "../../../../../pages/config/MCPServersPreview"; +import { ConfigYaml, parseConfigYaml } from "@continuedev/config-yaml"; +import { + ArrowPathIcon, + CircleStackIcon, + CommandLineIcon, + InformationCircleIcon, + WrenchScrewdriverIcon, +} from "@heroicons/react/24/outline"; +import { MCPServerStatus } from "core"; +import { useContext, useMemo } from "react"; +import { useAuth } from "../../../../../context/Auth"; +import { IdeMessengerContext } from "../../../../../context/IdeMessenger"; +import { useAppDispatch, useAppSelector } from "../../../../../redux/hooks"; +import { updateConfig } from "../../../../../redux/slices/configSlice"; +import { fontSize } from "../../../../../util"; +import { ToolTip } from "../../../../gui/Tooltip"; +import EditBlockButton from "../../EditBlockButton"; +import { ExploreBlocksButton } from "../ExploreBlocksButton"; -export function MCPSection() { - return ; +interface MCPServerStatusProps { + server: MCPServerStatus; + serverFromYaml?: NonNullable[number]; } +function MCPServerPreview({ server, serverFromYaml }: MCPServerStatusProps) { + const ideMessenger = useContext(IdeMessengerContext); + const config = useAppSelector((store) => store.config.config); + const dispatch = useAppDispatch(); + const toolsTooltipId = `${server.id}-tools`; + const promptsTooltipId = `${server.id}-prompts`; + const resourcesTooltipId = `${server.id}-resources`; + const errorsTooltipId = `${server.id}-errors`; + + async function onRefresh() { + // optimistic config update + dispatch( + updateConfig({ + ...config, + mcpServerStatuses: config.mcpServerStatuses.map((s) => + s.id === server.id + ? { + ...s, + status: "connecting", + } + : s, + ), + }), + ); + ideMessenger.post("mcp/reloadServer", { + id: server.id, + }); + } + + return ( +
+
+ {/* Name and Status */} + {server.name} + + {/* Error indicator if any */} + {server.errors.length ? ( + <> + + + {server.errors.map((error, idx) => ( + {error} + ))} + + + ) : null} + + {/* Tools, Prompts, Resources with counts */} +
+
+ + {server.tools.length} + + {server.tools.map((tool, idx) => ( + {tool.name} + ))} + {server.tools.length === 0 && ( + No tools + )} + +
+
+ + {server.prompts.length} + + {server.prompts.map((prompt, idx) => ( + {prompt.name} + ))} + {server.prompts.length === 0 && ( + No prompts + )} + +
+
+ + {server.resources.length} + + {server.resources.map((resource, idx) => ( + {resource.name} + ))} + {server.resources.length === 0 && ( + No resources + )} + +
+
+
+ + {/* Refresh button */} +
+ +
+ +
+ +
+
+
+ ); +} + +function MCPSection() { + const servers = useAppSelector( + (store) => store.config.config.mcpServerStatuses, + ); + const { selectedProfile } = useAuth(); + + const mergedBlocks = useMemo(() => { + const parsed = selectedProfile?.rawYaml + ? parseConfigYaml(selectedProfile?.rawYaml ?? "") + : undefined; + return (servers ?? []).map((doc, index) => ({ + block: doc, + blockFromYaml: parsed?.mcpServers?.[index], + })); + }, [servers, selectedProfile]); + + return ( +
+
+ {mergedBlocks.map(({ block, blockFromYaml }, idx) => ( + + ))} +
+ +
+ ); +} + +export default MCPSection; diff --git a/gui/src/pages/config/MCPServersPreview.tsx b/gui/src/pages/config/MCPServersPreview.tsx deleted file mode 100644 index f1ca7b5af..000000000 --- a/gui/src/pages/config/MCPServersPreview.tsx +++ /dev/null @@ -1,189 +0,0 @@ -import { ConfigYaml, parseConfigYaml } from "@continuedev/config-yaml"; -import { - ArrowPathIcon, - CircleStackIcon, - CommandLineIcon, - InformationCircleIcon, - WrenchScrewdriverIcon, -} from "@heroicons/react/24/outline"; -import { MCPServerStatus } from "core"; -import { useContext, useMemo } from "react"; -import { ToolTip } from "../../components/gui/Tooltip"; -import EditBlockButton from "../../components/mainInput/Lump/EditBlockButton"; -import { ExploreBlocksButton } from "../../components/mainInput/Lump/sections/ExploreBlocksButton"; -import { useAuth } from "../../context/Auth"; -import { IdeMessengerContext } from "../../context/IdeMessenger"; -import { useAppDispatch, useAppSelector } from "../../redux/hooks"; -import { updateConfig } from "../../redux/slices/configSlice"; -import { fontSize } from "../../util"; - -interface MCPServerStatusProps { - server: MCPServerStatus; - serverFromYaml?: NonNullable[number]; -} -function MCPServerPreview({ server, serverFromYaml }: MCPServerStatusProps) { - const ideMessenger = useContext(IdeMessengerContext); - const config = useAppSelector((store) => store.config.config); - const dispatch = useAppDispatch(); - const toolsTooltipId = `${server.id}-tools`; - const promptsTooltipId = `${server.id}-prompts`; - const resourcesTooltipId = `${server.id}-resources`; - const errorsTooltipId = `${server.id}-errors`; - - async function onRefresh() { - // optimistic config update - dispatch( - updateConfig({ - ...config, - mcpServerStatuses: config.mcpServerStatuses.map((s) => - s.id === server.id - ? { - ...s, - status: "connecting", - } - : s, - ), - }), - ); - ideMessenger.post("mcp/reloadServer", { - id: server.id, - }); - } - - return ( -
-
- {/* Name and Status */} - {server.name} - - {/* Error indicator if any */} - {server.errors.length ? ( - <> - - - {server.errors.map((error, idx) => ( - {error} - ))} - - - ) : null} - - {/* Tools, Prompts, Resources with counts */} -
-
- - {server.tools.length} - - {server.tools.map((tool, idx) => ( - {tool.name} - ))} - {server.tools.length === 0 && ( - No tools - )} - -
-
- - {server.prompts.length} - - {server.prompts.map((prompt, idx) => ( - {prompt.name} - ))} - {server.prompts.length === 0 && ( - No prompts - )} - -
-
- - {server.resources.length} - - {server.resources.map((resource, idx) => ( - {resource.name} - ))} - {server.resources.length === 0 && ( - No resources - )} - -
-
-
- - {/* Refresh button */} -
- -
- -
- -
-
-
- ); -} - -function MCPServersPreview() { - const servers = useAppSelector( - (store) => store.config.config.mcpServerStatuses, - ); - const { selectedProfile } = useAuth(); - - const mergedBlocks = useMemo(() => { - const parsed = selectedProfile?.rawYaml - ? parseConfigYaml(selectedProfile?.rawYaml ?? "") - : undefined; - return (servers ?? []).map((doc, index) => ({ - block: doc, - blockFromYaml: parsed?.mcpServers?.[index], - })); - }, [servers, selectedProfile]); - - return ( -
-
- {mergedBlocks.map(({ block, blockFromYaml }, idx) => ( - - ))} -
- -
- ); -} - -export default MCPServersPreview;