Skip to content

The agent that grows with you

fix(desktop): onboarding cards clear only once answered, and close when their call finishes

alt-glitch7d1548b91686
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts
index 203f34903cb..145ee907149 100644
--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts
+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts
@@ -17,7 +17,7 @@ import { resetBrowseState } from '@/store/composer-input-history'
import { enqueueQueuedPrompt, type QueuedPromptEntry } from '@/store/composer-queue'
import { hasConnectionRequest, skipConnectionRequest } from '@/store/connection-request'
import { notify } from '@/store/notifications'
-import { answerParkedCard } from '@/store/parked-card-answers'
+import { answerParkedCard, skipParkedCards } from '@/store/parked-card-answers'
import { hasBlockingPromptRequest } from '@/store/prompts'
import { cloneAttachments, type QueueEditState } from '../composer-utils'
@@ -324,6 +324,11 @@ export function useComposerSubmit({
if (routable && hasConnectionRequest(sessionId)) {
void skipConnectionRequest(sessionId)
}
+
+ // And for the onboarding chat's setup and theme cards.
+ if (routable) {
+ skipParkedCards(sessionId ?? '')
+ }
}
const submitDraft = () => {
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/server-requests.ts b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/server-requests.ts
index 6deb9713849..87ccb4290b0 100644
--- a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/server-requests.ts
+++ b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/server-requests.ts
@@ -751,7 +751,8 @@ const setupBeat: Handler = ctx => {
card: (request.params.card ?? {}) as SetupBeatCard,
question,
requestId: request.id,
- sessionId
+ sessionId,
+ toolCallId: str(request.params.tool_call_id) || null
})
markNeedsInput(ctx)
notifyInput(ctx, question)
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/tools.ts b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/tools.ts
index 2d7f1dbd9ac..03fbbf8e181 100644
--- a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/tools.ts
+++ b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/tools.ts
@@ -10,10 +10,11 @@ import { noteSetupBeatResult } from '@/store/onboarding-run'
import { flashPetActivity, setPetActivity } from '@/store/pet'
import { recordPreviewArtifact, reofferPreviewArtifact } from '@/store/preview-status'
import { $sessionStates, storedSessionIdForRuntimeId } from '@/store/session-states'
-import { setupBeatResult } from '@/store/setup-beat'
+import { dropSetupBeatForCall, setupBeatResult } from '@/store/setup-beat'
import { isTerminalSubagentCompletion, pruneDelegateFallbackSubagents, upsertSubagent } from '@/store/subagents'
import { reportMcpToolResult } from '@/store/suggestion-providers/repair'
import { invalidateSkillSuggestionIndex } from '@/store/suggestion-providers/skill'
+import { dropThemePick } from '@/store/theme-pick'
import { restoreSessionTodosFromSnapshot } from '@/store/todos'
import { setSessionDraftingTool } from '@/store/tool-drafting'
import { notifyWorkspaceChanged, toolChangedPath, toolMayMutateFiles } from '@/store/workspace-events'
@@ -44,12 +45,21 @@ function recordToolPreview(ctx: GatewayEventContext, sessionId: string, cwd: str
}
}
+// A card's tool finished, so the card is done in this window too: answered in another window, or its
+// cancel was lost. Without this it would keep taking typed text.
+const SETTLED_CARDS = new Map([
+ ['set_theme', dropThemePick],
+ ['setup_beat', dropSetupBeatForCall]
+])
+
/** What a completed tool leaves behind outside its row: a preview target, or the end of an onboarding run. */
function noteToolOutcome(ctx: GatewayEventContext, sessionId: string, cwd: string, pendingProduction: boolean): void {
if (!ctx.deps.sessionInterrupted(sessionId)) {
recordToolPreview(ctx, sessionId, cwd, pendingProduction)
}
+ SETTLED_CARDS.get(ctx.payload?.name ?? '')?.(sessionId, ctx.payload?.tool_id)
+
if (ctx.payload?.name === 'setup_beat' && !ctx.event.replayed) {
noteSetupBeatResult([sessionId, storedSessionIdForRuntimeId(sessionId)], setupBeatResult(ctx.payload.result))
}
diff --git a/apps/desktop/src/store/connection-request.ts b/apps/desktop/src/store/connection-request.ts
index 11345d1ec71..526db180bbe 100644
--- a/apps/desktop/src/store/connection-request.ts
+++ b/apps/desktop/src/store/connection-request.ts
@@ -514,26 +514,38 @@ export const skipConnectionTarget = (request: ConnectionRequest, name: string):
export const continueConnectionRequest = (request: ConnectionRequest): Promise<boolean> =>
respondToConnectionRequest(request, { settled_by: 'continue' })
+// Directory cards that took composer words and have not reported settled yet: until the backend's
+// update arrives, a second quick message must not be taken as the answer too.
+const answeredInWords = new Set<string>()
+
+function directoryWaiting(sessionId: string): ConnectionRequest | null {
+ const request = $connectionRequests.get()[keyFor(sessionId)]
+
+ return request?.display && !request.settled && !answeredInWords.has(request.opId) ? request : null
+}
+
/** The composer's words answer an open connector directory card; the tool returns them as `said`. */
export function answerConnectorDirectory(sessionId: string, text: string): null | Promise<boolean> {
- const request = $connectionRequests.get()[keyFor(sessionId)]
+ const request = directoryWaiting(sessionId)
- if (!request?.display || request.settled || !text.trim()) {
+ if (!request || !text.trim()) {
return null
}
- return respondToConnectionRequest(request, { said: text.trim(), settled_by: 'continue' })
+ answeredInWords.add(request.opId)
+ const sent = respondToConnectionRequest(request, { said: text.trim(), settled_by: 'continue' })
+ const reopen = () => answeredInWords.delete(request.opId)
+
+ void sent.then(delivered => delivered || reopen(), reopen)
+
+ return sent
}
registerParkedCardAnswer('connector-directory', {
onboardingOnly: true,
$requests: $connectionRequests,
answer: answerConnectorDirectory,
- waiting: sessionId => {
- const request = $connectionRequests.get()[keyFor(sessionId)]
-
- return Boolean(request?.display && !request.settled)
- }
+ waiting: sessionId => Boolean(directoryWaiting(sessionId))
})
// Typing a message while the card is open ends the operation, otherwise the typed message waits behind
diff --git a/apps/desktop/src/store/parked-card-answers.ts b/apps/desktop/src/store/parked-card-answers.ts
index 7e41bab9d49..29b3428cc8c 100644
--- a/apps/desktop/src/store/parked-card-answers.ts
+++ b/apps/desktop/src/store/parked-card-answers.ts
@@ -13,6 +13,8 @@ export interface ParkedCardKind {
answer: ParkedCardAnswer
/** Takes typed text only in the onboarding chat; elsewhere the text is sent as a normal message. */
onboardingOnly?: boolean
+ /** Closes the card unanswered, so a message that cannot answer it (attachments, a slash command) runs. */
+ skip?: (sessionId: string) => boolean
waiting: (sessionId: string) => boolean
}
@@ -69,6 +71,15 @@ export function answerParkedCard(sessionId: string, text: string, onFailed: () =
return false
}
+/** Close every card waiting on `sessionId` that a message cannot answer (attachments, a slash command). */
+export function skipParkedCards(sessionId: string): void {
+ for (const kind of kindsFor(sessionId)) {
+ if (kind.waiting(sessionId)) {
+ kind.skip?.(sessionId)
+ }
+ }
+}
+
/** Whether any card waits on `sessionId`, so typed text would answer it. */
export function parkedCardWaiting(sessionId: string): boolean {
return kindsFor(sessionId).some(kind => kind.waiting(sessionId))
diff --git a/apps/desktop/src/store/setup-beat.ts b/apps/desktop/src/store/setup-beat.ts
index 38e84270b0e..612e0a7d6cf 100644
--- a/apps/desktop/src/store/setup-beat.ts
+++ b/apps/desktop/src/store/setup-beat.ts
@@ -4,7 +4,8 @@
* The setup_beat tool row reads this to draw the beat's card. A pick answers the request with
* `{answer}`; composer text answers it with `{said}` (the backend treats words on the name card as
* the name). The backend's `request.cancel` (timeout, Stop, Skip setup) clears the entry by request
- * id, so a late cancel never erases a newer card the same session raised.
+ * id, so a late cancel never erases a newer card the same session raised; the setup_beat call's
+ * completion clears it by tool call id, which covers a card answered in another window.
*/
import type { ToolCallMessagePart } from '@assistant-ui/react'
@@ -65,6 +66,8 @@ export interface SetupBeatRequest {
question: string
requestId: string
sessionId: string
+ /** The setup_beat call the card belongs to; only that transcript row draws it. */
+ toolCallId: null | string
}
export const $setupBeatRequests = atom<Record<string, SetupBeatRequest>>({})
@@ -86,16 +89,29 @@ export function clearSetupBeat(requestId: string, sessionId: string): boolean {
return true
}
-function respond(sessionId: string, result: { answer: SetupBeatAnswer } | { said: string }): boolean {
+/** The setup_beat call `toolCallId` finished: its card is done here too, wherever it was answered. */
+export function dropSetupBeatForCall(sessionId: string, toolCallId: string | undefined): void {
const request = $setupBeatRequests.get()[sessionId]
- if (!request) {
+ if (request && toolCallId && request.toolCallId === toolCallId) {
+ clearSetupBeat(request.requestId, sessionId)
+ }
+}
+
+// The card clears only once the answer is sent, so a failed send leaves it on screen to answer again.
+function respond(
+ sessionId: string,
+ result: { answer: SetupBeatAnswer } | Record<string, never> | { said: string }
+): boolean {
+ const request = $setupBeatRequests.get()[sessionId]
+
+ if (!request || !respondToServerRequest(request.requestId, { ...result })) {
return false
}
clearSetupBeat(request.requestId, sessionId)
- return respondToServerRequest(request.requestId, { ...result })
+ return true
}
/** Answer the session's card with the beat's picks. False when no card waits. */
@@ -114,5 +130,7 @@ registerParkedCardAnswer('setup_beat', {
onboardingOnly: true,
$requests: $setupBeatRequests,
answer: sayToSetupBeat,
+ // An empty answer closes the card unanswered, so an attachment or a slash command can run.
+ skip: sessionId => respond(sessionId, {}),
waiting: sessionId => Boolean($setupBeatRequests.get()[sessionId])
})
diff --git a/apps/desktop/src/store/theme-pick.ts b/apps/desktop/src/store/theme-pick.ts
index bbebad57aa4..33774ae08cc 100644
--- a/apps/desktop/src/store/theme-pick.ts
+++ b/apps/desktop/src/store/theme-pick.ts
@@ -39,16 +39,26 @@ export function clearThemePick(requestId: string, sessionId: string): boolean {
return true
}
+// The card clears only once the answer is sent, so a failed send leaves it on screen to answer again.
function answer(sessionId: string, result: ThemePickResult): boolean {
const request = $themePicks.get()[sessionId]
- if (!request) {
+ if (!request || !respondToServerRequest(request.requestId, { ...result })) {
return false
}
clearThemePick(request.requestId, sessionId)
- return respondToServerRequest(request.requestId, { ...result })
+ return true
+}
+
+/** The set_theme call finished: its picker is done here too, wherever it was answered. */
+export function dropThemePick(sessionId: string): void {
+ const request = $themePicks.get()[sessionId]
+
+ if (request) {
+ clearThemePick(request.requestId, sessionId)
+ }
}
/** Apply the user's pick and answer the session's card with it. False when no card waits or the value is unknown. */
@@ -71,5 +81,6 @@ registerParkedCardAnswer('theme-pick', {
onboardingOnly: true,
$requests: $themePicks,
answer: sayToThemePick,
+ skip: cancelThemePick,
waiting: sessionId => Boolean($themePicks.get()[sessionId])
})