fix: restore responding state after HITL resume (#38992)

This commit is contained in:
Wu Tianwei 2026-07-15 14:59:25 +08:00 committed by GitHub
parent ab3e4daa95
commit 10da5e8f9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 0 deletions

View File

@ -590,6 +590,39 @@ describe('useChat', () => {
expect(result.current.isResponding).toBe(false) // from onError
})
it('should restore responding state when a paused human input workflow resumes', async () => {
let initialCallbacks: HookCallbacks
let resumedCallbacks: HookCallbacks
vi.mocked(ssePost).mockImplementation(async (_url, _params, options) => {
initialCallbacks = options as HookCallbacks
})
vi.mocked(sseGet).mockImplementation(async (_url, _params, options) => {
resumedCallbacks = options as HookCallbacks
})
const { result } = renderHook(() => useChat())
act(() => {
result.current.handleSend('test-url', { query: 'human input test' }, {})
})
act(() => {
initialCallbacks.onWorkflowStarted({ workflow_run_id: 'wr-1', task_id: 't-1' })
initialCallbacks.onWorkflowPaused({ data: { workflow_run_id: 'wr-1' } })
})
await act(async () => {
await initialCallbacks.onCompleted()
})
expect(result.current.isResponding).toBe(false)
act(() => {
resumedCallbacks.onWorkflowStarted({ workflow_run_id: 'wr-1', task_id: 't-1' })
})
expect(result.current.isResponding).toBe(true)
})
it('should handle file uploads in onFile', () => {
let callbacks: HookCallbacks

View File

@ -1242,6 +1242,7 @@ export const useChat = (
})
},
onWorkflowStarted: ({ workflow_run_id, task_id, conversation_id, message_id }) => {
handleResponding(true)
// If there are no streaming messages, we still need to set the conversation_id to avoid create a new conversation when regeneration in chat-flow.
if (conversation_id) {
conversationIdRef.current = conversation_id