From b879748ba0892334845952090931fe92bfd787f8 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Wed, 22 Apr 2026 08:26:47 +0800 Subject: [PATCH] Parse human input extra contents by payload --- .../__tests__/hooks.spec.tsx | 16 ++++++++++ .../base/chat/chat-with-history/hooks.tsx | 31 ++++++++++--------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/web/app/components/base/chat/chat-with-history/__tests__/hooks.spec.tsx b/web/app/components/base/chat/chat-with-history/__tests__/hooks.spec.tsx index e2dee20cad..041870b9f1 100644 --- a/web/app/components/base/chat/chat-with-history/__tests__/hooks.spec.tsx +++ b/web/app/components/base/chat/chat-with-history/__tests__/hooks.spec.tsx @@ -1076,6 +1076,10 @@ describe('useChatWithHistory', () => { await waitFor(() => { expect(result!.current.appPrevChatTree.length).toBeGreaterThan(0) }) + + const answerNode = result!.current.appPrevChatTree[0]?.children?.[0] + expect(answerNode?.humanInputFormDataList).toHaveLength(1) + expect(answerNode?.workflow_run_id).toBe('wf-run-1') }) it('should set workflow_run_id for normal messages with submitted human_input', async () => { @@ -1114,6 +1118,9 @@ describe('useChatWithHistory', () => { await waitFor(() => { expect(result!.current.appPrevChatTree.length).toBeGreaterThan(0) }) + + const answerNode = result!.current.appPrevChatTree[0]?.children?.[0] + expect(answerNode?.humanInputFilledFormDataList).toHaveLength(1) }) it('should return empty appPrevChatTree when there is no currentConversationId', async () => { @@ -1835,6 +1842,15 @@ describe('useChatWithHistory', () => { expect(messageWithFiles?.message_files).toHaveLength(1) expect(messageWithFiles?.children?.[0]?.message_files).toHaveLength(1) expect(messageWithFiles?.children?.[0]?.agent_thoughts?.[0]?.message_files).toHaveLength(1) + + const normalAnswerNode = messageWithFiles?.children?.[0] + const pausedAnswerNode = result!.current.appPrevChatTree.find(item => item.id === 'question-msg-paused-branch')?.children?.[0] + + expect(normalAnswerNode?.humanInputFilledFormDataList).toHaveLength(1) + expect(normalAnswerNode?.humanInputFormDataList).toHaveLength(0) + expect(pausedAnswerNode?.humanInputFormDataList).toHaveLength(1) + expect(pausedAnswerNode?.humanInputFilledFormDataList).toHaveLength(0) + expect(pausedAnswerNode?.workflow_run_id).toBe('wf-run-branch') }) }) diff --git a/web/app/components/base/chat/chat-with-history/hooks.tsx b/web/app/components/base/chat/chat-with-history/hooks.tsx index 223c35f6dd..41cd8a0ede 100644 --- a/web/app/components/base/chat/chat-with-history/hooks.tsx +++ b/web/app/components/base/chat/chat-with-history/hooks.tsx @@ -36,21 +36,22 @@ function getFormattedChatList(messages: any[]) { const humanInputFormDataList: HumanInputFormData[] = [] const humanInputFilledFormDataList: HumanInputFilledFormData[] = [] let workflowRunId = '' - if (item.status === 'paused') { - item.extra_contents?.forEach((content: ExtraContent) => { - if (content.type === 'human_input' && !content.submitted) { - humanInputFormDataList.push(content.form_definition) - workflowRunId = content.workflow_run_id - } - }) - } - else if (item.status === 'normal') { - item.extra_contents?.forEach((content: ExtraContent) => { - if (content.type === 'human_input' && content.submitted) { - humanInputFilledFormDataList.push(content.form_submission_data) - } - }) - } + item.extra_contents?.forEach((content: ExtraContent) => { + if (content.type !== 'human_input') + return + + if (!content.submitted) { + if (!('form_definition' in content) || !content.form_definition) + return + humanInputFormDataList.push(content.form_definition) + workflowRunId = content.workflow_run_id || workflowRunId + return + } + + if (!('form_submission_data' in content) || !content.form_submission_data) + return + humanInputFilledFormDataList.push(content.form_submission_data) + }) newChatList.push({ id: item.id, content: item.answer,