Skip to content

The agent that grows with you

feat(desktop): directory card for manage_connections display

alt-glitchc07be22d0c9d
diff --git a/apps/desktop/src/app/capabilities/connectors/connectors-directory.tsx b/apps/desktop/src/app/capabilities/connectors/connectors-directory.tsx
index d0480ce83ea..093869e73a8 100644
--- a/apps/desktop/src/app/capabilities/connectors/connectors-directory.tsx
+++ b/apps/desktop/src/app/capabilities/connectors/connectors-directory.tsx
@@ -6,6 +6,8 @@ import { ErrorBanner } from '@/components/ui/error-state'
import { SearchField } from '@/components/ui/search-field'
import { SegmentedControl } from '@/components/ui/segmented-control'
import { useI18n } from '@/i18n'
+import type { Translations } from '@/i18n/types'
+import { cn } from '@/lib/utils'
import { ConnectorRowCard } from './connector-row-card'
import { cardKey, EMPTY_CONNECTORS_FILTER } from './derive'
@@ -185,40 +187,94 @@ function Group({
const { t } = useI18n()
const copy = t.connectorsPage.group
+ return (
+ <ConnectorSection count={group.cards.length} note={groupNote(group, copy)} title={group.id === 'local' ? where : copy[group.id]}>
+ <ConnectorGrid
+ busyKey={busyKey}
+ cards={group.cards}
+ onOpen={onOpen}
+ onPrefetch={onPrefetch}
+ onServerToggle={onServerToggle}
+ onVerb={onVerb}
+ selectedKey={selectedKey}
+ />
+ </ConnectorSection>
+ )
+}
+
+function groupNote(group: ConnectorGroupModel, copy: Translations['connectorsPage']['group']): ReactNode {
+ if (group.id === 'connected' && showsAttentionFirst(group)) {
+ return <Note>{copy.connectedNote}</Note>
+ }
+
+ return group.id === 'off' ? <Note>{copy.offNote}</Note> : null
+}
+
+export interface ConnectorSectionProps {
+ children: ReactNode
+ count: number
+ note?: ReactNode
+ title: string
+}
+
+/** One titled group of connector rows, as the Connectors page draws it. */
+export function ConnectorSection({ children, count, note, title }: ConnectorSectionProps) {
return (
<section className="grid gap-2">
<header className="flex items-center gap-2">
- <h3 className="text-xs font-semibold text-(--ui-text-primary)">
- {group.id === 'local' ? where : copy[group.id]}
- </h3>
- <span className="tabular-nums text-xs text-(--ui-text-tertiary)">{group.cards.length}</span>
-
- {group.id === 'connected' && showsAttentionFirst(group) ? <Note>{copy.connectedNote}</Note> : null}
- {group.id === 'off' ? <Note>{copy.offNote}</Note> : null}
+ <h3 className="text-xs font-semibold text-(--ui-text-primary)">{title}</h3>
+ <span className="tabular-nums text-xs text-(--ui-text-tertiary)">{count}</span>
+ {note}
</header>
-
- <div className="grid gap-3 sm:grid-cols-2">
- {group.cards.map(card => {
- const key = cardKey(card)
-
- return (
- <ConnectorRowCard
- busy={busyKey === key}
- card={card}
- key={key}
- onOpen={() => onOpen(card)}
- onPrefetch={onPrefetch ? () => onPrefetch(card) : undefined}
- onServerToggle={onServerToggle ? next => onServerToggle(card, next) : undefined}
- onVerb={onVerb ? () => onVerb(card) : undefined}
- selected={selectedKey === key}
- />
- )
- })}
- </div>
+ {children}
</section>
)
}
+export interface ConnectorGridProps {
+ busyKey: null | string
+ cards: readonly ConnectorCardModel[]
+ /** Two columns from the `sm` breakpoint on the page; one in a narrow chat card. */
+ columns?: 1 | 2
+ onOpen: (card: ConnectorCardModel) => void
+ onPrefetch?: (card: ConnectorCardModel) => void
+ onServerToggle?: (card: ConnectorCardModel, next: boolean) => void
+ onVerb?: (card: ConnectorCardModel) => void
+ selectedKey?: null | string
+}
+
+export function ConnectorGrid({
+ busyKey,
+ cards,
+ columns = 2,
+ onOpen,
+ onPrefetch,
+ onServerToggle,
+ onVerb,
+ selectedKey = null
+}: ConnectorGridProps) {
+ return (
+ <div className={cn('grid gap-3', columns === 2 && 'sm:grid-cols-2')}>
+ {cards.map(card => {
+ const key = cardKey(card)
+
+ return (
+ <ConnectorRowCard
+ busy={busyKey === key}
+ card={card}
+ key={key}
+ onOpen={() => onOpen(card)}
+ onPrefetch={onPrefetch ? () => onPrefetch(card) : undefined}
+ onServerToggle={onServerToggle ? next => onServerToggle(card, next) : undefined}
+ onVerb={onVerb ? () => onVerb(card) : undefined}
+ selected={selectedKey === key}
+ />
+ )
+ })}
+ </div>
+ )
+}
+
function Note({ children }: { children: ReactNode }) {
return <span className="truncate text-[0.65rem] text-(--ui-text-tertiary)">{children}</span>
}
diff --git a/apps/desktop/src/app/capabilities/connectors/connectors-tab.tsx b/apps/desktop/src/app/capabilities/connectors/connectors-tab.tsx
index 96907a4a177..40fbc9adef7 100644
--- a/apps/desktop/src/app/capabilities/connectors/connectors-tab.tsx
+++ b/apps/desktop/src/app/capabilities/connectors/connectors-tab.tsx
@@ -6,7 +6,6 @@ import { Button } from '@/components/ui/button'
import type { HermesGateway, ProfileScope } from '@/hermes'
import { useI18n } from '@/i18n'
import { $freeTierStatus } from '@/store/free-tier'
-import { openFreeTierSignIn } from '@/store/free-tier-sign-in'
import { notifyError } from '@/store/notifications'
import { installBundledEntry } from '../mcp/install-catalog-entry'
@@ -14,15 +13,15 @@ import { useMcpServers } from '../mcp/use-mcp-servers'
import { AddServerDialog } from './add-dialog'
import { ConnectorsDirectory } from './connectors-directory'
-import { $abandonedConnects, $accountOperations, abandonConnect, accountOperationFor } from './data/account-operations'
+import { $abandonedConnects } from './data/account-operations'
import { claimRouteLink } from './data/deep-link'
-import { accountAddress, joinBundledEntries, joinLocalServers, pickAccount } from './data/join'
+import { useHostedActions } from './data/hosted-actions'
+import { joinBundledEntries, joinLocalServers } from './data/join'
import { invalidateConnectors } from './data/keys'
-import { useConnectConnector, useConnectorSwitch, useDisconnectAccount, useRenameAccount } from './data/mutations'
+import { useRenameAccount } from './data/mutations'
import { seedLocalServers, startConnectorPersistence, storeLocalServers } from './data/persist'
import { prefetchConnectorTools, usePrefetchConnectedTools } from './data/prefetch'
import { useHostedConnectors, usePluginServers } from './data/queries'
-import type { ConnectAddress } from './data/rpc'
import {
cardKey,
deriveCards,
@@ -33,10 +32,11 @@ import {
} from './derive'
import { DisconnectConfirm, type Disconnecting } from './disconnect-confirm'
import { HostedConnectorDialog, type PendingRename } from './hosted-dialog'
+import { HostedNotice } from './hosted-notice'
import { LocalConnectorDialog } from './local-dialog'
import { RemoveServerConfirm } from './local-slots'
import { openToolsList, resetOpenedTools } from './tools-summary'
-import type { AccountRow, ConnectorCardModel, ConnectorsFilter, HostedPhase } from './types'
+import type { AccountRow, ConnectorCardModel, ConnectorsFilter } from './types'
const toolsListKey = (card: ConnectorCardModel) => (card.residency === 'local' ? localServerName(card) : card.slug)
@@ -51,17 +51,15 @@ export function ConnectorsTab({ gateway, profile }: ConnectorsTabProps) {
const hosted = useHostedConnectors(profile)
const mcp = useMcpServers({ gateway, profile })
- const operations = useStore($accountOperations)
const abandoned = useStore($abandonedConnects)
const freeTier = useStore($freeTierStatus)
- const connector = useConnectConnector(profile)
- const switcher = useConnectorSwitch(profile)
- const remover = useDisconnectAccount(profile)
- const renamer = useRenameAccount(profile)
-
const [filter, setFilter] = useState<ConnectorsFilter>(EMPTY_CONNECTORS_FILTER)
const [openKey, setOpenKey] = useState<null | string>(null)
+ const hostedActions = useHostedActions(profile, hosted.accounts, card => setOpenKey(cardKey(card)))
+ const { connectAccount, connector, remover, startConnect, switcher, write } = hostedActions
+ const renamer = useRenameAccount(profile)
+
const [addOpen, setAddOpen] = useState(false)
const [removeServer, setRemoveServer] = useState<null | ConnectorCardModel>(null)
const [disconnecting, setDisconnecting] = useState<Disconnecting | null>(null)
@@ -121,44 +119,6 @@ export function ConnectorsTab({ gateway, profile }: ConnectorsTabProps) {
useOpenFromRoute(cards, profile, setOpenKey, setPendingRename)
- const write = async (pending: Promise<{ error?: unknown; ok: boolean }>) => {
- const outcome = await pending
-
- if (!outcome.ok) {
- notifyError(outcome.error, copy.page.writeFailed)
- }
- }
-
- const connectAccount = async (card: ConnectorCardModel, reconnect: boolean, address: ConnectAddress = {}) => {
- const outcome = await connector.connect(card.slug, { ...address, reconnect })
-
- if (outcome.ok) {
- const url = outcome.operation.targets.find(target => target.connectUrl)?.connectUrl
-
- if (url) {
- void window.hermesDesktop?.openExternal?.(url)
- }
- }
-
- return outcome
- }
-
- // A row passes its own account. An app-level reconnect or Try again (no account) names the account the
- // summary speaks for, or nothing; either goes by id, so it still matches the sign-in that is already open.
- const startConnect = async (card: ConnectorCardModel, reconnect: boolean, account?: AccountRow) => {
- const target = account ?? (reconnect ? pickAccount(hosted.accounts, card.slug) : undefined)
- const address = target ? accountAddress(target) : {}
- const outcome = await connectAccount(card, reconnect, address)
-
- if (!outcome.ok) {
- notifyError(outcome.error, t.connectors.connectErrorFor(card.name))
-
- return
- }
-
- setOpenKey(cardKey(card))
- }
-
const bundledEntry = (card: ConnectorCardModel) =>
mcp.availableCatalog.find(candidate => candidate.name === card.ways.local?.entryName) ?? null
@@ -183,7 +143,9 @@ export function ConnectorsTab({ gateway, profile }: ConnectorsTabProps) {
}
const runVerb = (card: ConnectorCardModel) => {
- const open = accountOperationFor(operations, card.slug, profile)
+ if (hostedActions.runHostedVerb(card)) {
+ return
+ }
switch (card.verb) {
case 'authenticate':
@@ -191,11 +153,6 @@ export function ConnectorsTab({ gateway, profile }: ConnectorsTabProps) {
return
- case 'connect':
- void startConnect(card, false)
-
- return
-
case 'install':
if (card.ways.local?.entryName && card.ways.local.needsEnv !== true) {
void startInstall(card, {})
@@ -205,35 +162,6 @@ export function ConnectorsTab({ gateway, profile }: ConnectorsTabProps) {
break
- case 'reconnect':
-
- case 'tryAgain':
- void startConnect(card, true)
-
- return
- case 'stopWaiting': {
- if (open) {
- void write(connector.giveUp(open.opId))
-
- return
- }
-
- abandonConnect([card.slug])
-
- const pending = pickAccount(hosted.accounts, card.slug)
-
- if (pending) {
- void write(remover.disconnect(pending.connection_id))
- }
-
- return
- }
-
- case 'turnBackOn':
- void write(switcher.setEnabled(card.slug, true))
-
- return
-
default:
break
}
@@ -241,7 +169,7 @@ export function ConnectorsTab({ gateway, profile }: ConnectorsTabProps) {
setOpenKey(cardKey(card))
}
- const busySlug = switcher.pending ?? connector.pending
+ const busySlug = hostedActions.busySlug
const busyKey = installing ?? (busySlug === null ? null : hostedCardKey(busySlug))
return (
@@ -352,28 +280,6 @@ export function ConnectorsTab({ gateway, profile }: ConnectorsTabProps) {
)
}
-function HostedNotice({ hasGuest, phase }: { hasGuest: boolean; phase: HostedPhase }) {
- const { t } = useI18n()
- const copy = t.connectorsPage.page
-
- if (phase === 'signedOut') {
- return (
- <p className="flex shrink-0 items-center gap-1 text-[0.7rem] text-(--ui-text-tertiary)">
- {copy.signInLine}
- <Button onClick={() => openFreeTierSignIn()} size="xs" variant="text">
- {copy.signIn}
- </Button>
- </p>
- )
- }
-
- if (phase === 'unavailable') {
- return <p className="shrink-0 text-[0.7rem] text-(--ui-text-tertiary)">{copy.managedUnavailable}</p>
- }
-
- return hasGuest ? <p className="shrink-0 text-[0.7rem] text-(--ui-text-tertiary)">{copy.freeTierNote}</p> : null
-}
-
function useOpenFromRoute(
cards: readonly ConnectorCardModel[],
scope: ProfileScope,
diff --git a/apps/desktop/src/app/capabilities/connectors/data/hosted-actions.ts b/apps/desktop/src/app/capabilities/connectors/data/hosted-actions.ts
new file mode 100644
index 00000000000..c29990104e8
--- /dev/null
+++ b/apps/desktop/src/app/capabilities/connectors/data/hosted-actions.ts
@@ -0,0 +1,143 @@
+import { useStore } from '@nanostores/react'
+
+import type { ProfileScope } from '@/hermes'
+import { useI18n } from '@/i18n'
+import { notifyError } from '@/store/notifications'
+
+import type { AccountRow, ConnectorCardModel } from '../types'
+
+import { $accountOperations, abandonConnect, accountOperationFor } from './account-operations'
+import { accountAddress, pickAccount } from './join'
+import {
+ type AccountDisconnect,
+ type ConnectorConnect,
+ type ConnectorSwitch,
+ type ConnectOutcome,
+ useConnectConnector,
+ useConnectorSwitch,
+ useDisconnectAccount,
+ type WriteOutcome
+} from './mutations'
+import type { ConnectAddress } from './rpc'
+
+export interface HostedActions {
+ busySlug: null | string
+ connectAccount: (card: ConnectorCardModel, reconnect: boolean, address?: ConnectAddress) => Promise<ConnectOutcome>
+ connector: ConnectorConnect
+ remover: AccountDisconnect
+ /** Runs a hosted card's verb; false when the verb is not a hosted one (a local server's). */
+ runHostedVerb: (card: ConnectorCardModel) => boolean
+ startConnect: (card: ConnectorCardModel, reconnect: boolean, account?: AccountRow) => Promise<void>
+ switcher: ConnectorSwitch
+ write: (pending: Promise<WriteOutcome>) => Promise<void>
+}
+
+/** The hosted connect, reconnect, give-up and turn-back-on paths, shared by the Connectors page and the chat's
+ * directory card. `onStarted` runs after a sign-in starts. */
+export function useHostedActions(
+ scope: ProfileScope,
+ accounts: readonly AccountRow[],
+ onStarted?: (card: ConnectorCardModel) => void
+): HostedActions {
+ const { t } = useI18n()
+ const operations = useStore($accountOperations)
+ const connector = useConnectConnector(scope)
+ const switcher = useConnectorSwitch(scope)
+ const remover = useDisconnectAccount(scope)
+
+ const write = async (pending: Promise<WriteOutcome>) => {
+ const outcome = await pending
+
+ if (!outcome.ok) {
+ notifyError(outcome.error, t.connectorsPage.page.writeFailed)
+ }
+ }
+
+ const connectAccount = async (card: ConnectorCardModel, reconnect: boolean, address: ConnectAddress = {}) => {
+ const outcome = await connector.connect(card.slug, { ...address, reconnect })
+
+ if (outcome.ok) {
+ const url = outcome.operation.targets.find(target => target.connectUrl)?.connectUrl
+
+ if (url) {
+ void window.hermesDesktop?.openExternal?.(url)
+ }
+ }
+
+ return outcome
+ }
+
+ // A row passes its own account. An app-level reconnect or Try again (no account) names the account the
+ // summary speaks for, or nothing; either goes by id, so it still matches the sign-in that is already open.
+ const startConnect = async (card: ConnectorCardModel, reconnect: boolean, account?: AccountRow) => {
+ const target = account ?? (reconnect ? pickAccount(accounts, card.slug) : undefined)
+ const address = target ? accountAddress(target) : {}
+ const outcome = await connectAccount(card, reconnect, address)
+
+ if (!outcome.ok) {
+ notifyError(outcome.error, t.connectors.connectErrorFor(card.name))
+
+ return
+ }
+
+ onStarted?.(card)
+ }
+
+ const stopWaiting = (card: ConnectorCardModel) => {
+ const open = accountOperationFor(operations, card.slug, scope)
+
+ if (open) {
+ void write(connector.giveUp(open.opId))
+
+ return
+ }
+
+ abandonConnect([card.slug])
+
+ const pending = pickAccount(accounts, card.slug)
+
+ if (pending) {
+ void write(remover.disconnect(pending.connection_id))
+ }
+ }
+
+ const runHostedVerb = (card: ConnectorCardModel): boolean => {
+ switch (card.verb) {
+ case 'connect':
+ void startConnect(card, false)
+
+ return true
+
+ case 'reconnect':
+
+ case 'tryAgain':
+ void startConnect(card, true)
+
+ return true
+
+ case 'stopWaiting':
+ stopWaiting(card)
+
+ return true
+
+ case 'turnBackOn':
+ void write(switcher.setEnabled(card.slug, true))
+
+ return true
+
+ default:
+ return false
+ }
+ }
+
+ return {
+ busySlug: switcher.pending ?? connector.pending,
+ connectAccount,
+ connector,
+ remover,
+ runHostedVerb,
+ startConnect,
+ switcher,
+ write
+ }
+}
diff --git a/apps/desktop/src/app/capabilities/connectors/hosted-notice.tsx b/apps/desktop/src/app/capabilities/connectors/hosted-notice.tsx
new file mode 100644
index 00000000000..b86406283cc
--- /dev/null
+++ b/apps/desktop/src/app/capabilities/connectors/hosted-notice.tsx
@@ -0,0 +1,27 @@
+import { Button } from '@/components/ui/button'
+import { useI18n } from '@/i18n'
+import { openFreeTierSignIn } from '@/store/free-tier-sign-in'
+
+import type { HostedPhase } from './types'
+
+export function HostedNotice({ hasGuest, phase }: { hasGuest: boolean; phase: HostedPhase }) {
+ const { t } = useI18n()
+ const copy = t.connectorsPage.page
+
+ if (phase === 'signedOut') {
+ return (
+ <p className="flex shrink-0 items-center gap-1 text-[0.7rem] text-(--ui-text-tertiary)">
+ {copy.signInLine}
+ <Button onClick={() => openFreeTierSignIn()} size="xs" variant="text">
+ {copy.signIn}
+ </Button>
+ </p>
+ )
+ }
+
+ if (phase === 'unavailable') {
+ return <p className="shrink-0 text-[0.7rem] text-(--ui-text-tertiary)">{copy.managedUnavailable}</p>
+ }
+
+ return hasGuest ? <p className="shrink-0 text-[0.7rem] text-(--ui-text-tertiary)">{copy.freeTierNote}</p> : null
+}
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/input-requests.ts b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/input-requests.ts
index 8cf53335235..1f4f6de11e8 100644
--- a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/input-requests.ts
+++ b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/input-requests.ts
@@ -70,7 +70,7 @@ export function handleInputRequestEvent(ctx: GatewayEventContext): boolean {
}
dispatchNativeNotification({
- body: request.targets.map(target => target.name).join(', '),
+ body: request.targets.map(target => target.name).join(', ') || translateNow('connectors.title'),
kind: 'input',
sessionId,
title: translateNow('notifications.native.inputTitle')
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/restore-pending-connection.ts b/apps/desktop/src/app/session/hooks/use-session-actions/restore-pending-connection.ts
index 231558c5d68..cb34c7eae93 100644
--- a/apps/desktop/src/app/session/hooks/use-session-actions/restore-pending-connection.ts
+++ b/apps/desktop/src/app/session/hooks/use-session-actions/restore-pending-connection.ts
@@ -72,6 +72,14 @@ export function connectionRequestToolPayload(request: ConnectionRequest): Gatewa
}
}
+ if (request.display) {
+ return {
+ args: { action: 'display', connectors: request.display.suggested, [CONNECTION_OP_ARG]: request.opId },
+ name: 'manage_connections',
+ tool_id: request.toolCallId
+ }
+ }
+
return {
args: {
action: request.targets[0]?.action ?? (request.targets[0]?.kind === 'connector' ? 'connect' : 'install'),
diff --git a/apps/desktop/src/components/assistant-ui/connector-directory-card.test.tsx b/apps/desktop/src/components/assistant-ui/connector-directory-card.test.tsx
new file mode 100644
index 00000000000..e9c7da37146
--- /dev/null
+++ b/apps/desktop/src/components/assistant-ui/connector-directory-card.test.tsx
@@ -0,0 +1,127 @@
+import type { ToolCallMessagePartProps } from '@assistant-ui/react'
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
+import { atom } from 'nanostores'
+import type { ReactNode } from 'react'
+import { afterEach, describe, expect, it, vi } from 'vitest'
+
+import { type SessionView, SessionViewProvider } from '@/app/chat/session-view'
+import { ConnectorDirectoryCard } from '@/components/assistant-ui/connector-directory-card'
+import { ConnectorTool } from '@/components/assistant-ui/connector-tool'
+import { I18nProvider } from '@/i18n'
+import { $connectionRequests } from '@/store/connection-request'
+import { setPrimaryGateway, setPrimaryGatewayConnectionId } from '@/store/gateway'
+import { _resetSessionOwnerHintsForTests, setSessionOwnerHint } from '@/store/session'
+
+const SESSION_ID = 'session-1'
+
+const row = (connector: string, connected: boolean) => ({
+ connected,
+ connection_status: connected ? 'active' : null,
+ connector,
+ enabled: true,
+ gateway_disabled_tools: [],
+ status_reason: null
+})
+
+const REPLIES = new Map<string, object>([
+ ['connectors.accounts', { accounts: [] }],
+ ['connectors.catalog', { connectors: [] }],
+ [
+ 'connectors.list',
+ { available: true, connectors: [row('gmail', true), row('linear', false), row('notion', false), row('slack', false)] }
+ ],
+ ['connectors.policy.get', { layers: [] }]
+])
+
+function gateway() {
+ const request = vi.fn(async (method: string) => REPLIES.get(method) ?? {})
+ setSessionOwnerHint(SESSION_ID, { connectionId: 'connection-1', profile: 'default' })
+ // SAFETY: the card and its queries call only `request` on the primary socket.
+ setPrimaryGateway({ request } as never)
+ setPrimaryGatewayConnectionId('connection-1')
+
+ return request
+}
+
+function view(): SessionView {
+ return {
+ $awaitingResponse: atom(false),
+ $busy: atom(false),
+ $cwd: atom(''),
+ $fast: atom(false),
+ $lastVisibleIsUser: atom(false),
+ $messages: atom([]),
+ $messagesEmpty: atom(false),
+ $model: atom(''),
+ $provider: atom(''),
+ $reasoningEffort: atom(''),
+ $reasoningEffortPending: atom(false),
+ $reasoningEffortWire: atom(''),
+ $runtimeId: atom(SESSION_ID),
+ $storedId: atom(SESSION_ID),
+ $turnStartedAt: atom(null),
+ kind: 'primary'
+ }
+}
+
+function inChat(children: ReactNode) {
+ return render(
+ <QueryClientProvider client={new QueryClient({ defaultOptions: { queries: { retry: false } } })}>
+ <I18nProvider configClient={null} initialLocale="en">
+ <SessionViewProvider value={view()}>{children}</SessionViewProvider>
+ </I18nProvider>
+ </QueryClientProvider>
+ )
+}
+
+// Each app is a toggle tile; its first line is the app name.
+const tileOrder = (container: HTMLElement) =>
+ [...container.querySelectorAll('button[aria-pressed]')].map(tile => tile.querySelector('.block')?.textContent)
+
+afterEach(() => {
+ cleanup()
+ $connectionRequests.set({})
+ setPrimaryGateway(null)
+ _resetSessionOwnerHintsForTests({ storage: true })
+ vi.clearAllMocks()
+})
+
+describe('ConnectorDirectoryCard', () => {
+ it('pins Suggested rows first in the given order, then the most used apps, and Continue reports the result', async () => {
+ gateway()
+ const onContinue = vi.fn()
+
+ const { container } = inChat(<ConnectorDirectoryCard onContinue={onContinue} suggested={['slack', 'linear']} />)
+
+ await waitFor(() => expect(tileOrder(container)).toEqual(['Slack', 'Linear', 'Gmail', 'Notion']))
+ expect(screen.getByText('Suggested')).toBeTruthy()
+
+ fireEvent.click(screen.getByRole('button', { name: 'Continue' }))
+
+ expect(onContinue).toHaveBeenCalledWith({ connected: ['gmail'], newly_connected: [], suggested: ['slack', 'linear'] })
+ })
+
+ it('collapses to one receipt line naming what the user connected once the call returns', () => {
+ const args = { action: 'display', connectors: ['slack'] }
+
+ const props: ToolCallMessagePartProps = {
+ addResult: vi.fn(),
+ args,
+ argsText: JSON.stringify(args),
+ isError: false,
+ respondToApproval: vi.fn(),
+ result: JSON.stringify({ connected: ['gmail', 'slack'], newly_connected: ['slack'], suggested: ['slack'] }),
+ resume: vi.fn(),
+ status: { type: 'complete' },
+ toolCallId: 'display-call-1',
+ toolName: 'manage_connections',
+ type: 'tool-call'
+ }
+
+ const { container } = inChat(<ConnectorTool {...props} />)
+
+ expect(screen.getByText('Connected: Slack')).toBeTruthy()
+ expect(tileOrder(container)).toEqual([])
+ })
+})
diff --git a/apps/desktop/src/components/assistant-ui/connector-directory-card.tsx b/apps/desktop/src/components/assistant-ui/connector-directory-card.tsx
new file mode 100644
index 00000000000..d620ea29514
--- /dev/null
+++ b/apps/desktop/src/components/assistant-ui/connector-directory-card.tsx
@@ -0,0 +1,226 @@
+import { useStore } from '@nanostores/react'
+import { useMemo, useState } from 'react'
+
+import { $abandonedConnects } from '@/app/capabilities/connectors/data/account-operations'
+import { useHostedActions } from '@/app/capabilities/connectors/data/hosted-actions'
+import { useHostedConnectors } from '@/app/capabilities/connectors/data/queries'
+import { deriveCards, forgetAbandoned } from '@/app/capabilities/connectors/derive'
+import { HostedNotice } from '@/app/capabilities/connectors/hosted-notice'
+import type { ConnectorCardModel } from '@/app/capabilities/connectors/types'
+import { useSessionView } from '@/app/chat/session-view'
+import { useConnectionOwner } from '@/components/assistant-ui/use-connection-owner'
+import { WIDGET_SHELL_CLASS } from '@/components/chat/widget-shell'
+import { Chip } from '@/components/onboarding-chat/chip'
+import { orderConnectorPicks } from '@/components/onboarding-chat/options'
+import { Button } from '@/components/ui/button'
+import { ConnectorLogo } from '@/components/ui/connector-logo'
+import { FadeScroll } from '@/components/ui/fade-scroll'
+import { SearchField } from '@/components/ui/search-field'
+import { useI18n } from '@/i18n'
+import { connectorIconUrl } from '@/lib/connector-tools'
+import { Plug } from '@/lib/icons'
+import { cn } from '@/lib/utils'
+import type { ConnectionOwner } from '@/store/connection-request'
+import { $freeTierStatus } from '@/store/free-tier'
+
+/** Same shape as the `manage_connections` display result. */
+export interface ConnectorDirectoryResult {
+ connected: string[]
+ newly_connected: string[]
+ suggested: string[]
+}
+
+export interface ConnectorDirectoryCardProps {
+ /** Slugs pinned at the top, in this order; unknown slugs are left out. */
+ suggested?: readonly string[]
+ onContinue: (result: ConnectorDirectoryResult) => void
+}
+
+export interface DirectorySections {
+ rest: ConnectorCardModel[]
+ suggested: ConnectorCardModel[]
+}
+
+// The onboarding apps step showed search from this many apps on.
+const SEARCH_THRESHOLD = 12
+
+const LABEL_CLASS = 'text-[0.6875rem] leading-4 text-(--ui-text-tertiary)'
+
+const matches = (card: ConnectorCardModel, needle: string): boolean =>
+ !needle || card.name.toLowerCase().includes(needle) || card.slug.includes(needle)
+
+/** Suggested apps first in the caller's order, then every other app in the onboarding picker's order (the most
+ * used apps lead; apps turned off and the picker's hidden few are left out). */
+export function directorySections(
+ cards: readonly ConnectorCardModel[],
+ suggested: readonly string[],
+ query: string
+): DirectorySections {
+ const needle = query.trim().toLowerCase()
+ const bySlug = new Map(cards.map(card => [card.slug, card]))
+ const pinned = new Set(suggested)
+
+ const ordered = orderConnectorPicks(
+ cards.map(card => ({ card, connector: card.slug, enabled: card.state !== 'off' }))
+ ).map(row => row.card)
+
+ return {
+ rest: ordered.filter(card => !pinned.has(card.slug) && matches(card, needle)),
+ suggested: suggested.flatMap(slug => {
+ const card = bySlug.get(slug)
+
+ return card && matches(card, needle) ? [card] : []
+ })
+ }
+}
+
+const NO_SUGGESTIONS: readonly string[] = []
+
+const connectedSlugs = (cards: readonly ConnectorCardModel[]): string[] =>
+ cards.filter(card => card.state === 'connected').map(card => card.slug)
+
+/** Every hosted connector in one chat card, laid out like the onboarding apps step; a tile runs the Connectors
+ * page's connect flow. It resolves the chat's own profile and connection, so it must render inside a session view. */
+export function ConnectorDirectoryCard(props: ConnectorDirectoryCardProps) {
+ const storedId = useStore(useSessionView().$storedId)
+ const owner = useConnectionOwner(storedId, true)
+
+ return owner ? <DirectoryBody {...props} owner={owner} /> : null
+}
+
+function DirectoryBody({
+ onContinue,
+ owner,
+ suggested = NO_SUGGESTIONS
+}: ConnectorDirectoryCardProps & { owner: ConnectionOwner }) {
+ const { t } = useI18n()
+ const copy = t.connectors
+ const hosted = useHostedConnectors(owner)
+ const abandoned = useStore($abandonedConnects)
+ const freeTier = useStore($freeTierStatus)
+ const actions = useHostedActions(owner, hosted.accounts)
+ const [query, setQuery] = useState('')
+
+ const cards = useMemo(
+ () => deriveCards({ hosted: forgetAbandoned(hosted.rows, new Set(abandoned)), local: [], titles: hosted.titles }),
+ [abandoned, hosted.rows, hosted.titles]
+ )
+
+ const sections = useMemo(() => directorySections(cards, suggested, query), [cards, query, suggested])
+
+ // What was connected when the list first answered; `newly_connected` is measured against it.
+ const [baseline, setBaseline] = useState<null | ReadonlySet<string>>(null)
+
+ if (baseline === null && hosted.phase === 'ready') {
+ setBaseline(new Set(connectedSlugs(cards)))
+ }
+
+ const finish = () => {
+ const connected = connectedSlugs(cards)
+
+ onContinue({
+ connected,
+ newly_connected: connected.filter(slug => !baseline?.has(slug)),
+ suggested: [...suggested]
+ })
+ }
+
+ const tileSub = (card: ConnectorCardModel, busy: boolean): string | undefined => {
+ if (busy) {
+ return copy.opening
+ }
+
+ return card.state === 'available' ? undefined : t.connectorsPage.card.state[card.stateWord]
+ }
+
+ const tile = (card: ConnectorCardModel) => {
+ const busy = actions.busySlug === card.slug
+
+ return (
+ <Chip
+ className="w-full"
+ icon={
+ <ConnectorLogo
+ className="size-7 rounded-full text-sm"
+ connector={{ iconUrl: connectorIconUrl(card.slug), name: card.slug, title: card.name }}
+ />
+ }
+ key={card.slug}
+ label={card.name}
+ on={card.state === 'connected'}
+ onToggle={() => {
+ if (!busy) {
+ actions.runHostedVerb(card)
+ }
+ }}
+ sub={tileSub(card, busy)}
+ />
+ )
+ }
+
+ const pinned = sections.suggested.length > 0
+ const nothingMatches = cards.length > 0 && !pinned && sections.rest.length === 0
+
+ return (
+ <div className="my-1.5 grid min-w-0 gap-2" data-connector-directory>
+ <div
+ className={cn(
+ WIDGET_SHELL_CLASS,
+ 'grid gap-3 text-[length:var(--conversation-text-font-size)] text-(--ui-text-primary)'
+ )}
+ >
+ <div className="flex items-start gap-2">
+ <span className={cn('flex-1', LABEL_CLASS)}>{copy.title}</span>
+ <Plug aria-hidden className="mt-px size-4 shrink-0 text-(--ui-text-tertiary)" />
+ </div>
+
+ <HostedNotice hasGuest={freeTier?.has_guest === true} phase={hosted.phase} />
+
+ {hosted.phase === 'failed' ? (
+ <p className="flex items-center gap-1.5 text-xs text-(--ui-text-tertiary)">
+ {t.connectorsPage.page.hostedFailedTitle}
+ <Button onClick={hosted.refetch} size="xs" variant="text">
+ {t.connectorsPage.page.retry}
+ </Button>
+ </p>
+ ) : null}
+
+ {cards.length > SEARCH_THRESHOLD ? (
+ <SearchField onChange={setQuery} placeholder={copy.search} value={query} />
+ ) : null}
+
+ {hosted.phase === 'loading' && cards.length === 0 ? (
+ <div className="grid grid-cols-3 gap-2" role="status">
+ <span className="sr-only">{t.connectorsPage.page.loading}</span>
+ {Array.from({ length: 6 }, (_, index) => (
+ <div className="h-10 animate-pulse rounded-lg bg-muted/40" key={index} />
+ ))}
+ </div>
+ ) : (
+ <>
+ {pinned ? (
+ <section className="grid gap-1.5">
+ <span className={LABEL_CLASS}>{copy.directory.suggested}</span>
+ <div className="grid grid-cols-3 gap-2 p-1">{sections.suggested.map(tile)}</div>
+ </section>
+ ) : null}
+ {sections.rest.length > 0 ? (
+ <section className="grid gap-1.5">
+ {pinned ? <span className={LABEL_CLASS}>{copy.directory.allApps}</span> : null}
+ <FadeScroll className="grid grid-cols-3 gap-2 p-1" fade="1.5rem" maxHeight="18rem" pad="1.5rem">
+ {sections.rest.map(tile)}
+ </FadeScroll>
+ </section>
+ ) : null}
+ {nothingMatches ? <p className="text-xs text-(--ui-text-tertiary)">{copy.empty}</p> : null}
+ </>
+ )}
+ </div>
+ <div className="px-3.5">
+ <Button onClick={finish} size="xs" variant="textStrong">
+ {t.common.continue}
+ </Button>
+ </div>
+ </div>
+ )
+}
diff --git a/apps/desktop/src/components/assistant-ui/connector-tool.tsx b/apps/desktop/src/components/assistant-ui/connector-tool.tsx
index 758a3c65fc3..03a0f71f412 100644
--- a/apps/desktop/src/components/assistant-ui/connector-tool.tsx
+++ b/apps/desktop/src/components/assistant-ui/connector-tool.tsx
@@ -7,9 +7,13 @@ import { useInRouterContext, useNavigate } from 'react-router'
import { accountRenameRoute } from '@/app/capabilities/connectors/data/deep-link'
import { useSessionView } from '@/app/chat/session-view'
import { sessionRoute } from '@/app/routes'
+import { ConnectorDirectoryCard } from '@/components/assistant-ui/connector-directory-card'
import { ToolFallback } from '@/components/assistant-ui/tool/fallback'
+import { useConnectionOwner } from '@/components/assistant-ui/use-connection-owner'
+import { SCAFFOLD_LABEL_CLASS, ScaffoldRow } from '@/components/chat/scaffold-row'
import { Button } from '@/components/ui/button'
import { ConnectorCard, ConnectorRow, type ConnectorRowMark, ConnectorSummary } from '@/components/ui/connector-card'
+import { ConnectorLogo } from '@/components/ui/connector-logo'
import { useI18n } from '@/i18n'
import {
connectorAuthorizationUrl,
@@ -34,34 +38,6 @@ import {
import { requestGatewayForAgent } from '@/store/gateway'
import { notifyError } from '@/store/notifications'
-/** Resolve that owner. Null until it resolves and null when it cannot: a card RPC must reach the
- * gateway that holds the operation, never whichever one the window happens to have in front. */
-export function useConnectionOwner(sessionId: null | string, active: boolean): ConnectionOwner | null {
- const [owner, setOwner] = useState<ConnectionOwner | null>(null)
-
- useEffect(() => {
- if (!sessionId || !active) {
- setOwner(null)
-
- return
- }
-
- let cancelled = false
-
- void connectionOwnerFor(sessionId, 'connectors.connect').then(resolved => {
- if (!cancelled) {
- setOwner(resolved)
- }
- })
-
- return () => {
- cancelled = true
- }
- }, [active, sessionId])
-
- return owner
-}
-
/** The browser leg of a connection came back through `hermes://connections/done`. Show the session
* that opened the operation and tell its backend to read the account now instead of at its next
* tick. Nothing in the link is trusted to move a row: the op id only names which card to show, and
@@ -171,6 +147,10 @@ export function ConnectorTool(props: ToolCallMessagePartProps) {
// Owner routes and hints are keyed by the stored id, not the runtime id the events carry.
const owner = useConnectionOwner(storedId, live)
+ if (recordOf(props.args).action === 'display') {
+ return <ConnectorDirectoryTool live={live} request={request} result={props.result} />
+ }
+
if (!live || !request) {
return <ToolFallback {...props} />
}
@@ -178,6 +158,65 @@ export function ConnectorTool(props: ToolCallMessagePartProps) {
return owner ? <ConnectorOffer owner={owner} request={request} /> : null
}
+interface ConnectorDirectoryToolProps {
+ live: boolean
+ request: ConnectionRequest | null
+ result: unknown
+}
+
+/** The display card while its operation is open; afterwards the one line the result says. */
+function ConnectorDirectoryTool({ live, request, result }: ConnectorDirectoryToolProps) {
+ if (live && request && !request.settled) {
+ return (
+ <ConnectorDirectoryCard
+ onContinue={() => void continueConnectionRequest(request)}
+ suggested={request.display?.suggested}
+ />
+ )
+ }
+
+ return result === undefined ? null : <ConnectorDirectoryReceipt result={result} />
+}
+
+function receiptText(copy: ConnectorCopy['directory'], outcome: ReturnType<typeof recordOf>, added: string[]): string {
+ if (outcome.timed_out === true) {
+ return copy.receiptTimedOut
+ }
+
+ if (connectorText(outcome.said) !== undefined) {
+ return copy.receiptSaid
+ }
+
+ return added.length > 0 ? copy.receiptConnected(added.map(connectorTitle).join(', ')) : copy.receiptNone
+}
+
+export function ConnectorDirectoryReceipt({ result }: { result: unknown }) {
+ const { t } = useI18n()
+ const copy = t.connectors.directory
+ const outcome = recordOf(result)
+
+ const added = Array.isArray(outcome.newly_connected)
+ ? outcome.newly_connected.flatMap(name => connectorText(name) ?? [])
+ : []
+
+ const text = receiptText(copy, outcome, added)
+
+ return (
+ <div data-conversation-scaffold="" data-slot="connector-directory-receipt">
+ <ScaffoldRow>
+ {added.map(name => (
+ <ConnectorLogo
+ className="size-4 rounded-[0.25rem]"
+ connector={{ iconUrl: connectorIconUrl(name), name, title: connectorTitle(name) }}
+ key={name}
+ />
+ ))}
+ <span className={SCAFFOLD_LABEL_CLASS}>{text}</span>
+ </ScaffoldRow>
+ </div>
+ )
+}
+
type ConnectorCopy = ReturnType<typeof useI18n>['t']['connectors']
type ConnectorVerb = 'none' | 'open' | 'reissue'
diff --git a/apps/desktop/src/components/assistant-ui/mcp-setup-tool.tsx b/apps/desktop/src/components/assistant-ui/mcp-setup-tool.tsx
index 10beb6ae512..c2ef598bf96 100644
--- a/apps/desktop/src/components/assistant-ui/mcp-setup-tool.tsx
+++ b/apps/desktop/src/components/assistant-ui/mcp-setup-tool.tsx
@@ -10,10 +10,10 @@ import {
CONNECTOR_CARD_PHASES,
MARK_LABEL,
reissueConnectionTarget,
- useConnectionOwner,
useConnectorFocusHandoff
} from '@/components/assistant-ui/connector-tool'
import { ToolFallback } from '@/components/assistant-ui/tool/fallback'
+import { useConnectionOwner } from '@/components/assistant-ui/use-connection-owner'
import { WIDGET_SHELL_CLASS } from '@/components/chat/widget-shell'
import { Button } from '@/components/ui/button'
import { ConnectorCard, ConnectorRow, type ConnectorRowAction, ConnectorSummary } from '@/components/ui/connector-card'
diff --git a/apps/desktop/src/components/assistant-ui/use-connection-owner.ts b/apps/desktop/src/components/assistant-ui/use-connection-owner.ts
new file mode 100644
index 00000000000..f44d07471f9
--- /dev/null
+++ b/apps/desktop/src/components/assistant-ui/use-connection-owner.ts
@@ -0,0 +1,31 @@
+import { useEffect, useState } from 'react'
+
+import { type ConnectionOwner, connectionOwnerFor } from '@/store/connection-request'
+
+/** The gateway route that owns a session's connection operation. Null until it resolves and null when it cannot: a card RPC must reach the
+ * gateway that holds the operation, never whichever one the window happens to have in front. */
+export function useConnectionOwner(sessionId: null | string, active: boolean): ConnectionOwner | null {
+ const [owner, setOwner] = useState<ConnectionOwner | null>(null)
+
+ useEffect(() => {
+ if (!sessionId || !active) {
+ setOwner(null)
+
+ return
+ }
+
+ let cancelled = false
+
+ void connectionOwnerFor(sessionId, 'connectors.connect').then(resolved => {
+ if (!cancelled) {
+ setOwner(resolved)
+ }
+ })
+
+ return () => {
+ cancelled = true
+ }
+ }, [active, sessionId])
+
+ return owner
+}
diff --git a/apps/desktop/src/i18n/de_connector_card.ts b/apps/desktop/src/i18n/de_connector_card.ts
index 7e4e8830080..09299682a17 100644
--- a/apps/desktop/src/i18n/de_connector_card.ts
+++ b/apps/desktop/src/i18n/de_connector_card.ts
@@ -32,5 +32,13 @@ export const deConnectorCard: TranslationOverrides['connectors'] = {
authorizedToolsUnavailable: 'Autorisiert. Tools nicht verfügbar.',
required: 'Erforderlich',
namedAccount: (app: string, alias: string) => `Hermes hat dieses ${app}-Konto ${alias} genannt.`,
- renameAccount: 'Umbenennen'
+ renameAccount: 'Umbenennen',
+ directory: {
+ suggested: 'Vorgeschlagen',
+ allApps: 'Alle Apps',
+ receiptConnected: apps => `Verbunden: ${apps}`,
+ receiptNone: 'Keine Apps verbunden',
+ receiptSaid: 'Im Chat beantwortet',
+ receiptTimedOut: 'Nach 5 Minuten geschlossen'
+ }
}
diff --git a/apps/desktop/src/i18n/en_connector_card.ts b/apps/desktop/src/i18n/en_connector_card.ts
index 450d900ce86..c07e3c96796 100644
--- a/apps/desktop/src/i18n/en_connector_card.ts
+++ b/apps/desktop/src/i18n/en_connector_card.ts
@@ -32,5 +32,13 @@ export const enConnectorCard: Translations['connectors'] = {
authorizedToolsUnavailable: 'Authorized. Tools unavailable.',
required: 'Required',
namedAccount: (app: string, alias: string) => `Hermes named this ${app} account ${alias}.`,
- renameAccount: 'Rename'
+ renameAccount: 'Rename',
+ directory: {
+ suggested: 'Suggested',
+ allApps: 'All apps',
+ receiptConnected: apps => `Connected: ${apps}`,
+ receiptNone: 'No apps connected',
+ receiptSaid: 'Answered in chat',
+ receiptTimedOut: 'Closed after 5 minutes'
+ }
}
diff --git a/apps/desktop/src/i18n/es_connector_card.ts b/apps/desktop/src/i18n/es_connector_card.ts
index 0d73ca679eb..b3d2b60a964 100644
--- a/apps/desktop/src/i18n/es_connector_card.ts
+++ b/apps/desktop/src/i18n/es_connector_card.ts
@@ -32,5 +32,13 @@ export const esConnectorCard: TranslationOverrides['connectors'] = {
authorizedToolsUnavailable: 'Autorizado. Herramientas no disponibles.',
required: 'Obligatorio',
namedAccount: (app: string, alias: string) => `Hermes llamó ${alias} a esta cuenta de ${app}.`,
- renameAccount: 'Cambiar nombre'
+ renameAccount: 'Cambiar nombre',
+ directory: {
+ suggested: 'Sugeridas',
+ allApps: 'Todas las apps',
+ receiptConnected: apps => `Conectadas: ${apps}`,
+ receiptNone: 'Ninguna app conectada',
+ receiptSaid: 'Respondido en el chat',
+ receiptTimedOut: 'Cerrado tras 5 minutos'
+ }
}
diff --git a/apps/desktop/src/i18n/fr_connector_card.ts b/apps/desktop/src/i18n/fr_connector_card.ts
index 9d2d31f173c..dcb2c59b7c8 100644
--- a/apps/desktop/src/i18n/fr_connector_card.ts
+++ b/apps/desktop/src/i18n/fr_connector_card.ts
@@ -32,5 +32,13 @@ export const frConnectorCard: TranslationOverrides['connectors'] = {
authorizedToolsUnavailable: 'Autorisé. Outils indisponibles.',
required: 'Obligatoire',
namedAccount: (app: string, alias: string) => `Hermes a nommé ce compte ${app} ${alias}.`,
- renameAccount: 'Renommer'
+ renameAccount: 'Renommer',
+ directory: {
+ suggested: 'Suggérées',
+ allApps: 'Toutes les apps',
+ receiptConnected: apps => `Connectées : ${apps}`,
+ receiptNone: 'Aucune app connectée',
+ receiptSaid: 'Répondu dans le chat',
+ receiptTimedOut: 'Fermé après 5 minutes'
+ }
}
diff --git a/apps/desktop/src/i18n/types_connectors.ts b/apps/desktop/src/i18n/types_connectors.ts
index 6cb5886bf2c..2d53968ba4c 100644
--- a/apps/desktop/src/i18n/types_connectors.ts
+++ b/apps/desktop/src/i18n/types_connectors.ts
@@ -31,6 +31,17 @@ export interface ConnectorCardTranslations {
required: string
namedAccount: (app: string, alias: string) => string
renameAccount: string
+ directory: ConnectorDirectoryTranslations
+}
+
+/** The chat's directory card (`manage_connections` display) and the line it collapses to. */
+export interface ConnectorDirectoryTranslations {
+ suggested: string
+ allApps: string
+ receiptConnected: (apps: string) => string
+ receiptNone: string
+ receiptSaid: string
+ receiptTimedOut: string
}
export interface ConnectorAccountsTranslations {
diff --git a/apps/desktop/src/i18n/zh_connector_card.ts b/apps/desktop/src/i18n/zh_connector_card.ts
index 98ab1a38a96..ce9d8db432f 100644
--- a/apps/desktop/src/i18n/zh_connector_card.ts
+++ b/apps/desktop/src/i18n/zh_connector_card.ts
@@ -31,5 +31,13 @@ export const zhConnectorCard: TranslationOverrides['connectors'] = {
authorizedToolsUnavailable: '已授权。工具不可用。',
required: '必填',
namedAccount: (app, alias) => `Hermes 已将这个 ${app} 账户命名为 ${alias}。`,
- renameAccount: '重命名'
+ renameAccount: '重命名',
+ directory: {
+ suggested: '推荐',
+ allApps: '全部应用',
+ receiptConnected: apps => `已连接:${apps}`,
+ receiptNone: '未连接任何应用',
+ receiptSaid: '已在聊天中回复',
+ receiptTimedOut: '5 分钟后已关闭'
+ }
}
diff --git a/apps/desktop/src/store/connection-request.ts b/apps/desktop/src/store/connection-request.ts
index e397cb0af90..098f2e2d2cd 100644
--- a/apps/desktop/src/store/connection-request.ts
+++ b/apps/desktop/src/store/connection-request.ts
@@ -124,6 +124,12 @@ export interface ConnectionRequest {
/** Local receipt time (Unix seconds), used to reject stale resume cleanup. */
receivedAt?: number
sessionId: string | null
+ /** A `manage_connections` display card: no targets, the directory with these slugs pinned. */
+ display?: ConnectorDisplay | null
+}
+
+export interface ConnectorDisplay {
+ suggested: string[]
}
const keyFor = (sessionId: string | null | undefined): string => sessionId ?? ''
@@ -278,12 +284,15 @@ export function normalizeConnectionRequest(
.map(parseConnectionTarget)
.filter((target): target is ConnectionTarget => target !== null)
- if (!payload.op_id || !payload.tool_call_id || !(payload.deadline_at > 0) || targets.length === 0) {
+ const display = payload.display ? { suggested: payload.display.suggested } : null
+
+ if (!payload.op_id || !payload.tool_call_id || !(payload.deadline_at > 0) || (targets.length === 0 && !display)) {
return null
}
return {
deadlineAt: payload.deadline_at,
+ display,
opId: payload.op_id,
receivedAt: Date.now() / 1000,
seq: payload.seq,
@@ -504,6 +513,19 @@ export const skipConnectionTarget = (request: ConnectionRequest, name: string):
export const continueConnectionRequest = (request: ConnectionRequest): Promise<boolean> =>
respondToConnectionRequest(request, { settled_by: 'continue' })
+/** The composer's words answer an open display card: the tool returns them as `said`. True when a card took them. */
+export function answerConnectorDirectory(sessionId: string, text: string): boolean {
+ const request = $connectionRequests.get()[keyFor(sessionId)]
+
+ if (!request?.display || request.settled || !text.trim()) {
+ return false
+ }
+
+ void respondToConnectionRequest(request, { said: text.trim(), settled_by: 'continue' }).catch(() => undefined)
+
+ return true
+}
+
// Typing a message while the card is open ends the operation, otherwise the typed message waits behind
// the blocked tool until the deadline.
export async function skipConnectionRequest(sessionId: string | null | undefined): Promise<boolean> {