Skip to content

The agent that grows with you

fix(desktop): a setup look typed in the composer applies like a clicked one

alt-glitch68d0ff456f3e
diff --git a/apps/desktop/src/components/assistant-ui/clarify/setup-pending.tsx b/apps/desktop/src/components/assistant-ui/clarify/setup-pending.tsx
index 7d519e940b3..bb2f30a7cc4 100644
--- a/apps/desktop/src/components/assistant-ui/clarify/setup-pending.tsx
+++ b/apps/desktop/src/components/assistant-ui/clarify/setup-pending.tsx
@@ -147,6 +147,15 @@ export function SetupChoosePending({
[kind, mode, question.multiSelect, requestId, rowLabels, setMode]
)
+ // Composer text that names a row picks it through this card, so the typed pick applies its look too.
+ const liveRequestId = request?.requestId
+
+ useEffect(() => {
+ if (liveRequestId) {
+ stageSetupChoose(liveRequestId, { preview: stage })
+ }
+ }, [liveRequestId, stage])
+
const toggle = useCallback(
(_question: ClarifyQuestion, choice: string) => {
const row = rows?.[question.choices?.indexOf(choice) ?? -1]
diff --git a/apps/desktop/src/store/clarify.test.ts b/apps/desktop/src/store/clarify.test.ts
index 9dccd7dfd0b..70e4a55dca8 100644
--- a/apps/desktop/src/store/clarify.test.ts
+++ b/apps/desktop/src/store/clarify.test.ts
@@ -3,13 +3,17 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import {
$clarifyRequest,
$clarifyRequests,
+ $setupChooseStages,
+ answerSetupCard,
type ClarifyRequest,
clearClarifyRequest,
hasClarifyRequest,
normalizeChoices,
normalizeQuestions,
setClarifyRequest,
- skipClarifyRequest
+ setupChooseStage,
+ skipClarifyRequest,
+ stageSetupChoose
} from './clarify'
import { $gateway } from './gateway'
import { rememberServerRequest, resetServerRequestsForTests } from './server-requests'
@@ -129,6 +133,56 @@ describe('skipClarifyRequest', () => {
})
})
+describe('answerSetupCard', () => {
+ const ACCENTS = { '#0000ff': 'Blue', '#ff0000': 'Red' }
+ let look: string
+
+ // The card's pick: snapshot the look once, then apply the row (as setup-pending's `stage` does).
+ function mountAccentCard(requestId: string) {
+ stageSetupChoose(requestId, {
+ labels: ACCENTS,
+ preview: id => {
+ const before = look
+ stageSetupChoose(requestId, {
+ picked: [id],
+ revert: setupChooseStage(requestId).revert ?? (() => (look = before))
+ })
+ look = id
+ }
+ })
+ }
+
+ beforeEach(() => {
+ look = 'original'
+ $clarifyRequests.set({})
+ $setupChooseStages.set({})
+ resetServerRequestsForTests()
+ })
+
+ afterEach(() => {
+ $clarifyRequests.set({})
+ $setupChooseStages.set({})
+ })
+
+ it('applies a typed row over the row previewed on the card, and keeps it after the card clears', () => {
+ const respond = vi.fn()
+
+ rememberServerRequest({ fail: vi.fn(), id: 'req-a', method: 'setup_choose', params: {}, respond })
+ setClarifyRequest({
+ ...clarify('session-a', 'req-a'),
+ setup: { kind: 'accent', multiSelect: false, options: null, preselected: [] }
+ })
+ mountAccentCard('req-a')
+ setupChooseStage('req-a').preview?.('#ff0000')
+
+ expect(answerSetupCard('session-a', 'blue')).toBe(true)
+
+ expect(respond).toHaveBeenCalledWith({ label: 'Blue', picked: '#0000ff' })
+ expect(hasClarifyRequest('session-a')).toBe(false)
+ expect(look).toBe('#0000ff')
+ })
+})
+
describe('normalizeChoices', () => {
it('returns empty array for null/undefined', () => {
expect(normalizeChoices(null)).toEqual([])
diff --git a/apps/desktop/src/store/clarify.ts b/apps/desktop/src/store/clarify.ts
index 893d2ca6bf9..fc6e9e7a84b 100644
--- a/apps/desktop/src/store/clarify.ts
+++ b/apps/desktop/src/store/clarify.ts
@@ -251,10 +251,12 @@ interface SetupChooseStage {
*/
labels: Record<string, string>
picked: string[]
+ /** The card's own pick of a row: it applies the row's look the same way a click does. */
+ preview: ((id: string) => void) | null
revert: (() => void) | null
}
-export const EMPTY_SETUP_STAGE: SetupChooseStage = { draft: '', labels: {}, picked: [], revert: null }
+export const EMPTY_SETUP_STAGE: SetupChooseStage = { draft: '', labels: {}, picked: [], preview: null, revert: null }
/**
* A card's answer: the picked ids, and the names the user saw for them when any id is a row. The backend
@@ -421,8 +423,14 @@ function answerSetupChoose(request: ClarifyRequest, setup: SetupChooseSpec, text
return false
}
- // Keep the look of a row already previewed on the card; any other preview reverts with the request.
- if (setup.multiSelect || stage.picked.includes(id)) {
+ // A typed row is picked as if clicked, so its look stays once the request clears.
+ const staged = setup.multiSelect || stage.picked.includes(id)
+
+ if (!staged) {
+ stage.preview?.(id)
+ }
+
+ if (staged || stage.preview) {
commitSetupChoose(request.requestId)
}