Skip to content

Commit b85c6b0

Browse files
committed
fix(chat): preserve request options when editing queued messages
1 parent b8b5d57 commit b85c6b0

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.mount-send.test.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,41 @@ describe('useChat remount send recovery', () => {
339339
vi.clearAllMocks()
340340
})
341341

342+
it.each([
343+
{ options: undefined, expectedSource: 'drive' },
344+
{ options: { assistantSearch: { source: 'slack' } }, expectedSource: 'slack' },
345+
])(
346+
'preserves queued assistant mode when edited with $options',
347+
async ({ options, expectedSource }) => {
348+
useMothershipQueueStore.setState({
349+
queues: {
350+
'chat-a': [
351+
{
352+
id: 'queued-question',
353+
content: 'Find the policy',
354+
requestMode: 'assistant',
355+
assistantSearch: { source: 'drive' },
356+
},
357+
],
358+
},
359+
editing: { 'chat-a': 'queued-question' },
360+
})
361+
const { getResult } = renderUseChatInChat('chat-a')
362+
363+
await act(async () => {
364+
await getResult().sendMessage('Find the updated policy', undefined, undefined, options)
365+
})
366+
await waitFor(() => state.postBodies.length === 1)
367+
368+
expect(state.postBodies[0]).toMatchObject({
369+
message: 'Find the updated policy',
370+
mode: 'assistant',
371+
assistantSearch: { source: expectedSource },
372+
})
373+
expect(useMothershipQueueStore.getState().editing['chat-a']).toBeUndefined()
374+
}
375+
)
376+
342377
it('keeps a cross-route handoff recoverable across a StrictMode double-mount', async () => {
343378
MothershipHandoffStorage.store({ message: 'investigate this failed run' }, 'ws-1')
344379

apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4396,14 +4396,14 @@ export function useChat(
43964396
// Edit-in-place: replace at the original index. If the slot was already
43974397
// dispatched mid-edit (UI-guard race), fall through to a tail-append.
43984398
if (editingId) {
4399-
const existing = queueStore.queues[activeChatKey] ?? []
4400-
if (existing.some((m) => m.id === editingId)) {
4399+
const existing = queueStore.queues[activeChatKey]?.find((m) => m.id === editingId)
4400+
if (existing) {
44014401
queueStore.replaceAt(activeChatKey, editingId, {
44024402
content: message,
44034403
fileAttachments,
44044404
contexts,
4405-
requestMode: options?.requestMode,
4406-
assistantSearch: options?.assistantSearch,
4405+
requestMode: options?.requestMode ?? existing.requestMode,
4406+
assistantSearch: options?.assistantSearch ?? existing.assistantSearch,
44074407
})
44084408
queueStore.setEditing(activeChatKey, null)
44094409
// Resume dispatch if it paused on this slot.

0 commit comments

Comments
 (0)