Skip to content

Commit 0cdb5c9

Browse files
committed
fix(chat): keep the zone wait countdown running under a steered message
The clock read the last message, which is the steered one while it trails the running response, so the countdown froze. It now reads the live response.
1 parent 49b06c7 commit 0cdb5c9

3 files changed

Lines changed: 36 additions & 7 deletions

File tree

‎apps/sim/platform/lib/data/chat-model.test.ts‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
import { describe, expect, it } from 'vitest'
99
import type { ChatMessage } from '@/app/workspace/[workspaceId]/home/types'
10-
import { toPlatformTurns } from '@/platform/lib/data/chat-model'
10+
import { isRunningWait, toPlatformTurns } from '@/platform/lib/data/chat-model'
1111

1212
const options = {
1313
streaming: true,
@@ -53,3 +53,29 @@ describe('toPlatformTurns', () => {
5353
)
5454
})
5555
})
56+
57+
describe('isRunningWait', () => {
58+
const pausing: ChatMessage = {
59+
id: 'pausing',
60+
role: 'assistant',
61+
content: '',
62+
contentBlocks: [
63+
{ type: 'tool_call', toolCall: { id: 'wait-1', name: 'wait', status: 'executing' } },
64+
],
65+
}
66+
67+
it('keeps counting down while a steered message trails the running response', () => {
68+
const steered: ChatMessage = {
69+
id: 'steered',
70+
role: 'user',
71+
content: 'Also this',
72+
steering: { streamId: 'turn' },
73+
}
74+
expect(isRunningWait([pausing, steered])).toBe(true)
75+
})
76+
77+
it('stops at the next turn: a wait left in an earlier response is not running', () => {
78+
const next: ChatMessage = { id: 'next', role: 'user', content: 'Next' }
79+
expect(isRunningWait([pausing, next])).toBe(false)
80+
})
81+
})

‎apps/sim/platform/lib/data/chat-model.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,13 @@ function liveResponseIndex(messages: readonly ChatMessage[]): number {
526526
return -1
527527
}
528528

529+
/** Whether the running response is paused in a `wait`, which counts down. */
530+
export function isRunningWait(messages: readonly ChatMessage[]): boolean {
531+
return (messages[liveResponseIndex(messages)]?.contentBlocks ?? []).some(
532+
(block) => block.toolCall?.name === 'wait' && block.toolCall.status === 'executing'
533+
)
534+
}
535+
529536
/**
530537
* The hook's transcript as Platform turns. A pure read of `messages`, so a replay, a reconnect or a
531538
* reload lands on the same turns, and it keeps the legacy parsers as the only readers of the wire.

‎apps/sim/platform/lib/data/chat.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
import type { ChatRuntime, ToolDecision } from '@/platform/app/(shell)/_components/chat/model'
2828
import { platformUrl } from '@/platform/lib/data/base-path'
2929
import { draftToSend } from '@/platform/lib/data/chat-draft'
30-
import { toPlatformTurns } from '@/platform/lib/data/chat-model'
30+
import { isRunningWait, toPlatformTurns } from '@/platform/lib/data/chat-model'
3131
import { useAssistantReview } from '@/platform/lib/data/chat-review'
3232
import { useOrganization } from '@/platform/lib/data/organization'
3333
import { type SummaryRequest, useSendSummary } from '@/platform/lib/data/search-summary'
@@ -38,11 +38,7 @@ import { useToolPermissionStore } from '@/stores/tool-permission/store'
3838
/** A running `wait` counts down, and nothing else re-renders during the pause. */
3939
function useWaitClock(messages: readonly ChatMessage[], streaming: boolean): number {
4040
const [now, setNow] = useState(() => Date.now())
41-
const waiting =
42-
streaming &&
43-
(messages.at(-1)?.contentBlocks ?? []).some(
44-
(block) => block.toolCall?.name === 'wait' && block.toolCall.status === 'executing'
45-
)
41+
const waiting = streaming && isRunningWait(messages)
4642
useEffect(() => {
4743
if (!waiting) return
4844
const interval = setInterval(() => setNow(Date.now()), 1_000)

0 commit comments

Comments
 (0)