The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(sdk): export route-decoupled McpTab + ToolsetConfigPanel for plugins (#86896)
Teknium3671529e9d15
diff --git a/apps/desktop/src/app/settings/toolset-config-panel.tsx b/apps/desktop/src/app/settings/toolset-config-panel.tsxindex 40571042eb1..1cee5ec8431 100644--- a/apps/desktop/src/app/settings/toolset-config-panel.tsx+++ b/apps/desktop/src/app/settings/toolset-config-panel.tsx@@ -50,6 +50,23 @@ interface ToolsetConfigPanelProps {* backend's _MODEL_CATALOG_TOOLSETS map). */const MODEL_CATALOG_TOOLSETS = new Set(['image_gen', 'video_gen'])+/**+ * `useNavigate` throws when there is no react-router context. Inside Settings+ * (the panel's original home) there always is one, so behavior is unchanged;+ * embedded in a plugin dialog OUTSIDE the router there is none, and this+ * degrades to `null` instead of crashing the whole panel. Router presence is+ * stable for a mounted instance's lifetime, so the try/catch never changes the+ * hook count between renders (rules-of-hooks safe).+ */+function useOptionalNavigate(): null | ReturnType<typeof useNavigate> {+ try {+ // eslint-disable-next-line react-hooks/rules-of-hooks -- stable per instance: router presence never changes for a mounted component's lifetime+ return useNavigate()+ } catch {+ return null+ }+}+function providerConfigured(provider: ToolProvider, envState: Record<string, boolean>): boolean {if (provider.env_vars.length === 0) {return true@@ -91,7 +108,7 @@ interface EnvVarFieldProps {function EnvVarField({ envVar, isSet, onSaved, onCleared, profile }: EnvVarFieldProps) {const { t } = useI18n()const copy = t.settings.toolsets- const navigate = useNavigate()+ const navigate = useOptionalNavigate()const [editing, setEditing] = useState(false)const [value, setValue] = useState('')const [revealed, setRevealed] = useState<string | null>(null)@@ -99,7 +116,9 @@ function EnvVarField({ envVar, isSet, onSaved, onCleared, profile }: EnvVarField// Internal route change to Settings → API Keys (tools sub-view) with the// deep-link param keys-settings consumes to scroll + flash this key's card.- const openInKeys = () => navigate(`${SETTINGS_ROUTE}?tab=keys&key=${encodeURIComponent(envVar.key)}`)+ // No-op when there is no router (embedded outside Settings, e.g. a plugin+ // dialog): the "Manage keys" affordance simply doesn't navigate there.+ const openInKeys = () => navigate?.(`${SETTINGS_ROUTE}?tab=keys&key=${encodeURIComponent(envVar.key)}`)async function handleSave() {if (!value) {diff --git a/apps/desktop/src/app/settings/use-deep-link-highlight.ts b/apps/desktop/src/app/settings/use-deep-link-highlight.tsindex 215202ff8ea..27809b2ac27 100644--- a/apps/desktop/src/app/settings/use-deep-link-highlight.ts+++ b/apps/desktop/src/app/settings/use-deep-link-highlight.ts@@ -9,6 +9,21 @@ interface DeepLinkHighlightOptions {block?: ScrollLogicalPosition}+// react-router's useSearchParams throws with no router context. Inside Settings+// (every original caller) there always is one, so behavior is unchanged; when a+// consumer is embedded OUTSIDE the router (e.g. McpTab in a plugin dialog) there+// is none, and this degrades to an inert [empty params, no-op setter] instead of+// crashing. Router presence is stable for a mounted instance's lifetime, so the+// try/catch never changes the hook count between renders (rules-of-hooks safe).+function useOptionalSearchParams(): ReturnType<typeof useSearchParams> {+ try {+ // eslint-disable-next-line react-hooks/rules-of-hooks -- stable per instance: router presence never changes for a mounted component's lifetime+ return useSearchParams()+ } catch {+ return [new URLSearchParams(), () => undefined]+ }+}+// Deep-link from the command palette (?<param>=<id>): once the target row is// renderable, scroll it into view and flash it, then drop the param so it// doesn't re-fire. Returns the pending target (null once consumed) so callers@@ -20,7 +35,7 @@ export function useDeepLinkHighlight({onResolve,block = 'center'}: DeepLinkHighlightOptions): null | string {- const [searchParams, setSearchParams] = useSearchParams()+ const [searchParams, setSearchParams] = useOptionalSearchParams()const target = searchParams.get(param)useEffect(() => {diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.tsindex a2e81f64858..499b0463247 100644--- a/apps/desktop/src/sdk/index.ts+++ b/apps/desktop/src/sdk/index.ts@@ -23,7 +23,7 @@ import { atom, type ReadableAtom } from 'nanostores'import { openSession, type OpenSessionIntent } from '@/app/open-session'import { $narrowViewport } from '@/components/pane-shell/tree/store'import { onGatewayEvent } from '@/contrib/events'-import { getLogs, getStatus } from '@/hermes'+import { getLogs, getStatus, type HermesGateway } from '@/hermes'import { $gateway, ensureGatewayForAgent, openGatewayForAgent, openGatewayForProfile } from '@/store/gateway'import { notify, notifyError } from '@/store/notifications'import { $activeGatewayProfile, ensureGatewayProfile, newSessionInProfile, setShowAllProfiles } from '@/store/profile'@@ -212,7 +212,14 @@ export const host = {}return gateway.request<T>(method, params)- }+ },++ /** The LIVE gateway instance for the active profile (null before the first+ * socket opens). Most plugins want `host.request`; this exists for SDK+ * components that take a `HermesGateway` prop directly (e.g. `McpTab`),+ * which need the instance, not just a JSON-RPC door. Re-read per use — the+ * active instance changes on a profile swap. */+ getGateway: (): HermesGateway | null => $gateway.get()}// -- react bridge -------------------------------------------------------------@@ -226,6 +233,11 @@ export { COMPOSER_AREAS, type ComposerAttachmentProvider, type ComposerMiddlewarexport { PALETTE_AREA, type PaletteContribution } from '@/app/command-palette/contrib'export { type RouteContribution, ROUTES_AREA, SIDEBAR_NAV_AREA, type SidebarNavContribution } from '@/app/routes'+/** THE full per-toolset config panel core Settings renders — provider picker,+ * env vars / API keys, model catalog picker, and post-setup runners. Route-+ * decoupled (the "manage keys" deep link is a no-op outside the router); pass+ * `toolset`, optional `onConfiguredChange`, and an optional `profile`. */+export { ToolsetConfigPanel } from '@/app/settings/toolset-config-panel'/** THE model catalog menu — the same searchable, provider-grouped, family-* collapsing picker the chat composer uses, including the per-row* thinking/effort/fast submenu. Drive it with a `ModelMenuController`: the@@ -241,6 +253,11 @@ export {export type { StatusbarItem } from '@/app/shell/statusbar-controls'export type { TitlebarTool } from '@/app/shell/titlebar-controls'+/** THE full MCP tab core Settings renders — per-server enable + OAuth sign-in+ * + API-key setup + live probes, not a checkbox list. Route-decoupled so it+ * renders anywhere (a plugin dialog); pass a live `gateway` (see+ * `host.getGateway()`) and an optional `profile` to scope it to one bot. */+export { McpTab } from '@/app/skills/mcp-tab'/** Pane placement roles. `'floating'` is the one NON-tiling value: the pane is* excluded from the layout tree and rendered as a fixed, draggable card above* it — it takes no width from any zone, has no tab, and can't be docked.@@ -319,6 +336,9 @@ export type {* id with your plugin slug (`kanban:board-switcher`). */export { Contribute, type ContributeProps } from '@/contrib/react/contribute'export type { Contribution } from '@/contrib/types'+/** The live gateway instance type — for typing the `gateway` prop `McpTab`+ * takes; obtain the instance from `host.getGateway()`. */+export type { HermesGateway } from '@/hermes'/** Grab-to-pan for overflow containers (boards, timelines, wide tables) —* the shared scrub primitive; don't hand-roll drag-to-scroll. */export { type GrabScroll, useGrabScroll } from '@/hooks/use-grab-scroll'