Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(workflow): track human input forms by execution identity (#42819)

-LAN-75989efed3cc
diff --git a/web/app/components/app/text-generate/item/__tests__/workflow-body.spec.tsx b/web/app/components/app/text-generate/item/__tests__/workflow-body.spec.tsx
index ef6d7ff0afb..746c5112ff1 100644
--- a/web/app/components/app/text-generate/item/__tests__/workflow-body.spec.tsx
+++ b/web/app/components/app/text-generate/item/__tests__/workflow-body.spec.tsx
@@ -55,6 +55,7 @@ describe('WorkflowBody', () => {
humanInputFormDataList: [createHumanInputFormFixture()],
humanInputFilledFormDataList: [
{
+ form_id: 'filled-form-1',
node_id: 'filled-1',
node_title: 'Human Input',
rendered_content: '',
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 c296613b9d5..d1140bed51c 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
@@ -19,6 +19,7 @@ import {
updateFeedback,
} from '@/service/share'
import { createChatConfigFixture as createChatConfig } from '@/test/fixtures/chat'
+import { createHumanInputFormFixture } from '@/test/fixtures/workflow-process'
import { CONVERSATION_ID_INFO, TAB_CONVERSATION_ID_INFO } from '../../constants'
import { useChatWithHistory } from '../hooks'
@@ -1086,7 +1087,7 @@ describe('useChatWithHistory', () => {
{
type: 'human_input',
submitted: false,
- form_definition: { fields: [] },
+ form_definition: createHumanInputFormFixture(),
workflow_run_id: 'wf-run-1',
},
],
@@ -1107,6 +1108,134 @@ describe('useChatWithHistory', () => {
expect(answerNode?.workflow_run_id).toBe('wf-run-1')
})
+ it('preserves distinct legacy submissions without form definitions', async () => {
+ // Arrange
+ const listData = createConversationData({
+ data: [createConversationItem({ id: 'conversation-1' })],
+ })
+ const chatListData = {
+ data: [
+ {
+ id: 'msg-normal',
+ query: 'Normal query',
+ answer: 'Answer',
+ message_files: [],
+ feedback: null,
+ retriever_resources: [],
+ agent_thoughts: null,
+ parent_message_id: null,
+ inputs: {},
+ status: 'normal',
+ extra_contents: [
+ {
+ type: 'human_input',
+ submitted: true,
+ form_submission_data: {
+ node_id: 'human-input',
+ node_title: 'Approval',
+ rendered_content: 'First approval',
+ action_id: 'approve',
+ action_text: 'Approve',
+ },
+ },
+ {
+ type: 'human_input',
+ submitted: true,
+ form_submission_data: {
+ node_id: 'human-input',
+ node_title: 'Approval',
+ rendered_content: 'Second approval',
+ action_id: 'approve',
+ action_text: 'Approve',
+ },
+ },
+ ],
+ },
+ ],
+ }
+ mockFetchConversations.mockResolvedValue(listData)
+ mockFetchChatList.mockResolvedValue(chatListData)
+
+ const { result } = await renderWithClient(() => useChatWithHistory())
+
+ await waitFor(() => {
+ expect(result.current.appPrevChatTree.length).toBeGreaterThan(0)
+ })
+
+ const answerNode = result.current.appPrevChatTree[0]?.children?.[0]
+ const forms = answerNode!.humanInputFilledFormDataList!
+ expect(forms.map((form) => form.rendered_content)).toEqual([
+ 'First approval',
+ 'Second approval',
+ ])
+ expect(forms[0]!.form_id).not.toBe(forms[1]!.form_id)
+ })
+
+ it('restores distinct same-Tool forms without removing the unsubmitted sibling', async () => {
+ mockFetchConversations.mockResolvedValue(
+ createConversationData({ data: [createConversationItem({ id: 'conversation-1' })] }),
+ )
+ const first = {
+ form_id: 'first',
+ node_id: 'tool',
+ node_title: 'Tool',
+ form_content: 'First approval',
+ inputs: [],
+ actions: [],
+ form_token: 'first-token',
+ display_in_ui: true,
+ resolved_default_values: {},
+ expiration_time: 100,
+ }
+ const second = {
+ ...first,
+ form_id: 'second',
+ form_content: 'Second approval',
+ form_token: 'second-token',
+ }
+ const filled = {
+ node_id: 'tool',
+ node_title: 'Tool',
+ rendered_content: 'Approved',
+ action_id: 'approve',
+ action_text: 'Approve',
+ }
+ mockFetchChatList.mockResolvedValue({
+ data: [
+ {
+ id: 'message',
+ query: 'Approve both requests',
+ answer: '',
+ message_files: [],
+ status: 'paused',
+ extra_contents: [
+ {
+ type: 'human_input',
+ submitted: false,
+ workflow_run_id: 'run',
+ form_definition: first,
+ },
+ {
+ type: 'human_input',
+ submitted: true,
+ workflow_run_id: 'run',
+ form_definition: second,
+ form_submission_data: filled,
+ },
+ ],
+ },
+ ],
+ })
+ const { result } = await renderWithClient(() => useChatWithHistory())
+ await waitFor(() => {
+ const answer = result.current.appPrevChatTree[0]?.children?.[0]
+ expect(answer?.humanInputFormDataList).toEqual([first])
+ expect(answer?.humanInputFilledFormDataList).toEqual([
+ { ...filled, form_id: 'second', form_content: 'Second approval', inputs: [] },
+ ])
+ })
+ })
+
it('should parse human input payloads regardless of message status', async () => {
const listData = createConversationData({
data: [createConversationItem({ id: 'conversation-1' })],
@@ -1566,7 +1695,17 @@ describe('useChatWithHistory', () => {
status: 'normal',
extra_contents: [
{ type: 'human_input', submitted: false },
- { type: 'human_input', submitted: true, form_submission_data: { submitted: true } },
+ {
+ type: 'human_input',
+ submitted: true,
+ form_submission_data: {
+ node_id: 'human-input-1',
+ node_title: 'Human Input',
+ rendered_content: 'Approved',
+ action_id: 'approve',
+ action_text: 'Approve',
+ },
+ },
],
},
{
@@ -1584,7 +1723,7 @@ describe('useChatWithHistory', () => {
{
type: 'human_input',
submitted: false,
- form_definition: { fields: [] },
+ form_definition: createHumanInputFormFixture(),
workflow_run_id: 'wf-run-branch',
},
{ type: 'human_input', submitted: true },
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 bd6d0b3dc97..74c1da66e2b 100644
--- a/web/app/components/base/chat/chat-with-history/hooks.tsx
+++ b/web/app/components/base/chat/chat-with-history/hooks.tsx
@@ -78,7 +78,7 @@ function getFormattedChatList(messages: any[]) {
const humanInputFormDataList: HumanInputFormData[] = []
const humanInputFilledFormDataList: HumanInputFilledFormData[] = []
let workflowRunId = ''
- item.extra_contents?.forEach((content: ExtraContent) => {
+ item.extra_contents?.forEach((content: ExtraContent, contentIndex: number) => {
if (content.type !== 'human_input') return
const formDefinition = 'form_definition' in content ? content.form_definition : undefined
@@ -90,16 +90,17 @@ function getFormattedChatList(messages: any[]) {
}
if (!('form_submission_data' in content) || !content.form_submission_data) return
- const currentFormIndex = humanInputFormDataList.findIndex(
- (item) => item.node_id === content.form_submission_data.node_id,
- )
- const requiredFormData =
- formDefinition ||
- (currentFormIndex > -1 ? humanInputFormDataList[currentFormIndex] : undefined)
- if (currentFormIndex > -1) humanInputFormDataList.splice(currentFormIndex, 1)
+ // Legacy submissions without a definition expose no form ID, so give their
+ // cards a history-only identity.
+ const formId =
+ formDefinition?.form_id ??
+ `${content.workflow_run_id ?? item.id}:${content.form_submission_data.node_id}:${contentIndex}`
workflowRunId = content.workflow_run_id || workflowRunId
humanInputFilledFormDataList.push(
- enrichSubmittedHumanInputFormData(content.form_submission_data, requiredFormData),
+ enrichSubmittedHumanInputFormData(
+ { ...content.form_submission_data, form_id: formId },
+ formDefinition,
+ ),
)
})
newChatList.push({
diff --git a/web/app/components/base/chat/chat/__tests__/hooks.spec.tsx b/web/app/components/base/chat/chat/__tests__/hooks.spec.tsx
index 3be396ca243..6e2cbc95a62 100644
--- a/web/app/components/base/chat/chat/__tests__/hooks.spec.tsx
+++ b/web/app/components/base/chat/chat/__tests__/hooks.spec.tsx
@@ -638,9 +638,10 @@ describe('useChat', () => {
callbacks.onWorkflowStarted({ workflow_run_id: 'wr-1', task_id: 't-1', message_id: 'm-3' })
// Human input required
- callbacks.onHumanInputRequired({ data: { node_id: 'n-human' } })
+ callbacks.onHumanInputRequired({ data: { form_id: 'form-n-human', node_id: 'n-human' } })
callbacks.onHumanInputRequired({
data: {
+ form_id: 'form-n-human',
node_id: 'n-human',
updated: true,
form_content: '{{#$output.answer#}}',
@@ -649,11 +650,15 @@ describe('useChat', () => {
}) // update existing
// setTimeout for timeout form
- callbacks.onHumanInputFormTimeout({ data: { node_id: 'n-human', expiration_time: 123456 } })
+ callbacks.onHumanInputFormTimeout({
+ data: { form_id: 'form-n-human', node_id: 'n-human', expiration_time: 123456 },
+ })
// Form filled
- callbacks.onHumanInputFormFilled({ data: { node_id: 'n-human' } })
- callbacks.onHumanInputFormFilled({ data: { node_id: 'n-human2' } }) // new one
+ callbacks.onHumanInputFormFilled({ data: { form_id: 'form-n-human', node_id: 'n-human' } })
+ callbacks.onHumanInputFormFilled({
+ data: { form_id: 'form-n-human2', node_id: 'n-human2' },
+ }) // new one
// onWorkflowPaused
callbacks.onWorkflowPaused({ data: { workflow_run_id: 'wr-1' } }) // should call sseGet
@@ -738,7 +743,7 @@ describe('useChat', () => {
postCallbacks.onWorkflowStarted({ workflow_run_id: 'wr-1', task_id: 't-1' })
postCallbacks.onHumanInputRequired({
workflow_run_id: 'wr-1',
- data: { node_id: 'human-1' },
+ data: { form_id: 'form-human-1', node_id: 'human-1' },
})
})
expect(sseGet).not.toHaveBeenCalled()
@@ -812,7 +817,7 @@ describe('useChat', () => {
})
postCallbacks.onHumanInputRequired({
workflow_run_id: 'wr-1',
- data: { node_id: 'human-1' },
+ data: { form_id: 'form-human-1', node_id: 'human-1' },
})
postCallbacks.onWorkflowPaused({ data: { workflow_run_id: 'wr-1' } })
})
@@ -850,7 +855,7 @@ describe('useChat', () => {
postCallbacks.onNodeStarted({ data: { node_id: 'human-1', id: 'human-1' } })
postCallbacks.onHumanInputRequired({
workflow_run_id: 'wr-1',
- data: { node_id: 'human-1' },
+ data: { form_id: 'form-human-1', node_id: 'human-1' },
})
})
@@ -1723,10 +1728,14 @@ describe('useChat', () => {
callbacks.onNodeFinished({ data: { node_id: 'n-1', id: 'n-1', status: 'succeeded' } })
// human input
- callbacks.onHumanInputRequired({ data: { node_id: 'h-1' } })
- callbacks.onHumanInputRequired({ data: { node_id: 'h-1', updated: true } })
- callbacks.onHumanInputFormTimeout({ data: { node_id: 'h-1', expiration_time: 123 } })
- callbacks.onHumanInputFormFilled({ data: { node_id: 'h-1' } })
+ callbacks.onHumanInputRequired({ data: { form_id: 'form-h-1', node_id: 'h-1' } })
+ callbacks.onHumanInputRequired({
+ data: { form_id: 'form-h-1', node_id: 'h-1', updated: true },
+ })
+ callbacks.onHumanInputFormTimeout({
+ data: { form_id: 'form-h-1', node_id: 'h-1', expiration_time: 123 },
+ })
+ callbacks.onHumanInputFormFilled({ data: { form_id: 'form-h-1', node_id: 'h-1' } })
callbacks.onTTSChunk('m-1', 'audio1')
callbacks.onTTSEnd('m-1', 'audio1')
@@ -2121,10 +2130,10 @@ describe('useChat', () => {
act(() => {
callbacks.onWorkflowStarted({ workflow_run_id: 'wr-1', task_id: 't-1' })
callbacks.onNodeStarted({ data: { node_id: 'node-1', id: 'node-1' } })
- callbacks.onHumanInputRequired({ data: { node_id: 'node-1' } })
- callbacks.onHumanInputRequired({ data: { node_id: 'node-2' } })
- callbacks.onHumanInputFormFilled({ data: { node_id: 'node-1' } })
- callbacks.onHumanInputFormFilled({ data: { node_id: 'node-3' } })
+ callbacks.onHumanInputRequired({ data: { form_id: 'form-node-1', node_id: 'node-1' } })
+ callbacks.onHumanInputRequired({ data: { form_id: 'form-node-2', node_id: 'node-2' } })
+ callbacks.onHumanInputFormFilled({ data: { form_id: 'form-node-1', node_id: 'node-1' } })
+ callbacks.onHumanInputFormFilled({ data: { form_id: 'form-node-3', node_id: 'node-3' } })
})
const lastResponse = result.current.chatList[1]
@@ -2532,7 +2541,7 @@ describe('useChat', () => {
content: 'answer 1',
isAnswer: true,
workflow_run_id: 'wr-1',
- humanInputFormDataList: [{ node_id: 'n-1' }],
+ humanInputFormDataList: [{ form_id: 'form-n-1', node_id: 'n-1' }],
siblingIndex: 0,
annotation: { id: 'anno-old', authorName: 'user' },
},
diff --git a/web/app/components/base/chat/chat/answer/__tests__/human-input-filled-form-list.spec.tsx b/web/app/components/base/chat/chat/answer/__tests__/human-input-filled-form-list.spec.tsx
new file mode 100644
index 00000000000..46e8a6a227f
--- /dev/null
+++ b/web/app/components/base/chat/chat/answer/__tests__/human-input-filled-form-list.spec.tsx
@@ -0,0 +1,38 @@
+import type { HumanInputFilledFormData } from '@/types/workflow'
+import { render, screen } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
+import HumanInputFilledFormList from '../human-input-filled-form-list'
+
+it('keeps expansion with the same form when same-Tool submissions are reordered', async () => {
+ const user = userEvent.setup()
+ const first = {
+ form_id: 'first',
+ node_id: 'tool',
+ node_title: 'First approval',
+ rendered_content: 'First submitted content',
+ action_id: 'approve',
+ action_text: 'Approve',
+ } satisfies HumanInputFilledFormData
+ const second = {
+ ...first,
+ form_id: 'second',
+ node_title: 'Second approval',
+ rendered_content: 'Second submitted content',
+ }
+ const { rerender } = render(
+ <HumanInputFilledFormList humanInputFilledFormDataList={[first, second]} />,
+ )
+
+ await user.click(screen.getByRole('button', { name: /First approval/ }))
+ expect(await screen.findByText('First submitted content')).toBeInTheDocument()
+ expect(screen.queryByText('Second submitted content')).not.toBeInTheDocument()
+
+ rerender(<HumanInputFilledFormList humanInputFilledFormDataList={[second, first]} />)
+
+ expect(screen.getByRole('button', { name: /First approval/ })).toHaveAttribute(
+ 'aria-expanded',
+ 'true',
+ )
+ expect(screen.getByText('First submitted content')).toBeInTheDocument()
+ expect(screen.queryByText('Second submitted content')).not.toBeInTheDocument()
+})
diff --git a/web/app/components/base/chat/chat/answer/__tests__/index.spec.tsx b/web/app/components/base/chat/chat/answer/__tests__/index.spec.tsx
index fdd251bad96..d543f3924ae 100644
--- a/web/app/components/base/chat/chat/answer/__tests__/index.spec.tsx
+++ b/web/app/components/base/chat/chat/answer/__tests__/index.spec.tsx
@@ -22,6 +22,7 @@ const pendingForm: HumanInputFormData = {
expiration_time: null,
}
const filledForm: HumanInputFilledFormData = {
+ form_id: 'form-1',
node_id: 'review',
node_title: 'Completed review',
rendered_content: 'Approved response',
diff --git a/web/app/components/base/chat/chat/answer/human-input-content/__tests__/form-state.spec.ts b/web/app/components/base/chat/chat/answer/human-input-content/__tests__/form-state.spec.ts
new file mode 100644
index 00000000000..53fa2c4a877
--- /dev/null
+++ b/web/app/components/base/chat/chat/answer/human-input-content/__tests__/form-state.spec.ts
@@ -0,0 +1,71 @@
+import type { HumanInputFilledFormData, HumanInputFormData } from '@/types/workflow'
+import {
+ updateFilledHumanInputForm,
+ updateHumanInputFormTimeout,
+ updatePendingHumanInputForm,
+} from '../form-state'
+
+const createPendingForm = (form_id: string): HumanInputFormData => ({
+ form_id,
+ node_id: 'tool',
+ node_title: 'Workflow Tool',
+ form_content: `Approval ${form_id}`,
+ inputs: [],
+ actions: [],
+ form_token: `token-${form_id}`,
+ display_in_ui: true,
+ expiration_time: 100,
+ resolved_default_values: {},
+})
+const filledForm: HumanInputFilledFormData = {
+ form_id: 'second',
+ node_id: 'tool',
+ node_title: 'Workflow Tool',
+ rendered_content: 'Approved',
+ action_id: 'approve',
+ action_text: 'Approve',
+}
+
+it('updates only the addressed form when several forms share a Tool node', () => {
+ const state: Parameters<typeof updatePendingHumanInputForm>[0] = {}
+ const first = createPendingForm('first')
+ const second = createPendingForm('second')
+ updatePendingHumanInputForm(state, first)
+ updatePendingHumanInputForm(state, second)
+ updatePendingHumanInputForm(state, { ...second, form_token: 'refreshed' })
+ updateHumanInputFormTimeout(state, { ...second, expiration_time: 200 })
+ updateHumanInputFormTimeout(state, { ...createPendingForm('missing'), expiration_time: 300 })
+
+ expect(state.humanInputFormDataList).toEqual([
+ first,
+ { ...second, form_token: 'refreshed', expiration_time: 200 },
+ ])
+
+ updateFilledHumanInputForm(state, filledForm)
+ updateFilledHumanInputForm(state, { ...filledForm, rendered_content: 'Replayed approval' })
+ updateHumanInputFormTimeout(state, { ...second, expiration_time: 300 })
+
+ expect(state.humanInputFormDataList).toEqual([first])
+ expect(state.humanInputFilledFormDataList).toEqual([
+ {
+ ...filledForm,
+ rendered_content: 'Replayed approval',
+ form_content: second.form_content,
+ inputs: [],
+ },
+ ])
+ updateFilledHumanInputForm(state, { ...filledForm, form_id: 'first' })
+ expect(state.humanInputFormDataList).toEqual([])
+ expect(state.humanInputFilledFormDataList?.map((form) => form.form_id)).toEqual([
+ 'second',
+ 'first',
+ ])
+})
+
+it('accepts submitted replay without a pending form and ignores its later timeout', () => {
+ const state: Parameters<typeof updateFilledHumanInputForm>[0] = {}
+ updateFilledHumanInputForm(state, filledForm)
+ updateFilledHumanInputForm(state, filledForm)
+ updateHumanInputFormTimeout(state, { ...filledForm, expiration_time: 200 })
+ expect(state).toEqual({ humanInputFilledFormDataList: [filledForm] })
+})
diff --git a/web/app/components/base/chat/chat/answer/human-input-content/__tests__/submitted.spec.tsx b/web/app/components/base/chat/chat/answer/human-input-content/__tests__/submitted.spec.tsx
index 1938441cf20..b468998bfe0 100644
--- a/web/app/components/base/chat/chat/answer/human-input-content/__tests__/submitted.spec.tsx
+++ b/web/app/components/base/chat/chat/answer/human-input-content/__tests__/submitted.spec.tsx
@@ -11,6 +11,7 @@ vi.mock('@/app/components/base/markdown', () => ({
describe('SubmittedHumanInputContent Integration', () => {
const mockFormData: HumanInputFilledFormData = {
+ form_id: 'form-1',
rendered_content: 'Rendered **Markdown** content',
action_id: 'btn_1',
action_text: 'Submit Action',
diff --git a/web/app/components/base/chat/chat/answer/human-input-content/form-state.ts b/web/app/components/base/chat/chat/answer/human-input-content/form-state.ts
new file mode 100644
index 00000000000..0573a7b7e4e
--- /dev/null
+++ b/web/app/components/base/chat/chat/answer/human-input-content/form-state.ts
@@ -0,0 +1,43 @@
+import type {
+ HumanInputFilledFormData,
+ HumanInputFormData,
+ HumanInputFormTimeoutData,
+} from '@/types/workflow'
+import { enrichSubmittedHumanInputFormData } from './submitted-utils'
+
+type HumanInputFormState = {
+ humanInputFormDataList?: HumanInputFormData[]
+ humanInputFilledFormDataList?: HumanInputFilledFormData[]
+}
+
+export const updatePendingHumanInputForm = (
+ state: HumanInputFormState,
+ data: HumanInputFormData,
+) => {
+ const forms = (state.humanInputFormDataList ??= [])
+ const index = forms.findIndex((form) => form.form_id === data.form_id)
+ if (index === -1) forms.push(data)
+ else forms[index] = data
+}
+
+export const updateFilledHumanInputForm = (
+ state: HumanInputFormState,
+ data: HumanInputFilledFormData,
+) => {
+ const pendingForms = state.humanInputFormDataList
+ const index = pendingForms?.findIndex((form) => form.form_id === data.form_id) ?? -1
+ const pendingForm = index === -1 ? undefined : pendingForms?.splice(index, 1)[0]
+ const filledForm = enrichSubmittedHumanInputFormData(data, pendingForm)
+ const filledForms = (state.humanInputFilledFormDataList ??= [])
+ const existingForm = filledForms.find((form) => form.form_id === data.form_id)
+ if (existingForm) Object.assign(existingForm, filledForm)
+ else filledForms.push(filledForm)
+}
+
+export const updateHumanInputFormTimeout = (
+ state: HumanInputFormState,
+ data: HumanInputFormTimeoutData,
+) => {
+ const form = state.humanInputFormDataList?.find((form) => form.form_id === data.form_id)
+ if (form) form.expiration_time = data.expiration_time
+}
diff --git a/web/app/components/base/chat/chat/answer/human-input-filled-form-list.tsx b/web/app/components/base/chat/chat/answer/human-input-filled-form-list.tsx
index 51c50adc20b..ba7d10f2c50 100644
--- a/web/app/components/base/chat/chat/answer/human-input-filled-form-list.tsx
+++ b/web/app/components/base/chat/chat/answer/human-input-filled-form-list.tsx
@@ -12,8 +12,8 @@ const HumanInputFilledFormList = ({
return (
<div className="mt-2 flex flex-col gap-y-2">
{humanInputFilledFormDataList.map((formData) => (
- <ContentWrapper key={formData.node_id} nodeTitle={formData.node_title} showExpandIcon>
- <SubmittedHumanInputContent key={formData.node_id} formData={formData} />
+ <ContentWrapper key={formData.form_id} nodeTitle={formData.node_title} showExpandIcon>
+ <SubmittedHumanInputContent formData={formData} />
</ContentWrapper>
))}
</div>
diff --git a/web/app/components/base/chat/chat/hooks.ts b/web/app/components/base/chat/chat/hooks.ts
index 850970aed16..8bee70634d5 100644
--- a/web/app/components/base/chat/chat/hooks.ts
+++ b/web/app/components/base/chat/chat/hooks.ts
@@ -13,7 +13,11 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { v4 as uuidV4 } from 'uuid'
import { AudioPlayerManager } from '@/app/components/base/audio-btn/audio.player.manager'
-import { enrichSubmittedHumanInputFormData } from '@/app/components/base/chat/chat/answer/human-input-content/submitted-utils'
+import {
+ updateFilledHumanInputForm,
+ updateHumanInputFormTimeout,
+ updatePendingHumanInputForm,
+} from '@/app/components/base/chat/chat/answer/human-input-content/form-state'
import {
getProcessedFiles,
getProcessedFilesFromResponse,
@@ -968,18 +972,7 @@ export const useChat = (
options: otherOptions,
}
updateChatTreeNode(messageId, (responseItem) => {
- if (!responseItem.humanInputFormDataList) {
- responseItem.humanInputFormDataList = [humanInputRequiredData]
- } else {
- const currentFormIndex = responseItem.humanInputFormDataList.findIndex(
- (item) => item.node_id === humanInputRequiredData.node_id,
- )
- if (currentFormIndex > -1) {
- responseItem.humanInputFormDataList[currentFormIndex] = humanInputRequiredData
- } else {
- responseItem.humanInputFormDataList.push(humanInputRequiredData)
- }
- }
+ updatePendingHumanInputForm(responseItem, humanInputRequiredData)
if (responseItem.workflowProcess?.tracing) {
const currentTracingIndex = responseItem.workflowProcess.tracing.findIndex(
(item) => item.node_id === humanInputRequiredData.node_id,
@@ -994,38 +987,12 @@ export const useChat = (
workflowPauseConfirmedRef.current = false
handleResponding(true)
updateChatTreeNode(messageId, (responseItem) => {
- let requiredFormData:
- | NonNullable<ChatItem['humanInputFormDataList']>[number]
- | undefined
- if (responseItem.humanInputFormDataList?.length) {
- const currentFormIndex = responseItem.humanInputFormDataList.findIndex(
- (item) => item.node_id === humanInputFilledFormData.node_id,
- )
- if (currentFormIndex > -1) {
- requiredFormData = responseItem.humanInputFormDataList[currentFormIndex]
- responseItem.humanInputFormDataList.splice(currentFormIndex, 1)
- }
- }
- const enrichedHumanInputFilledFormData = enrichSubmittedHumanInputFormData(
- humanInputFilledFormData,
- requiredFormData,
- )
- if (!responseItem.humanInputFilledFormDataList) {
- responseItem.humanInputFilledFormDataList = [enrichedHumanInputFilledFormData]
- } else {
- responseItem.humanInputFilledFormDataList.push(enrichedHumanInputFilledFormData)
- }
+ updateFilledHumanInputForm(responseItem, humanInputFilledFormData)
})
},
onHumanInputFormTimeout: ({ data: humanInputFormTimeoutData }) => {
updateChatTreeNode(messageId, (responseItem) => {
- if (responseItem.humanInputFormDataList?.length) {
- const currentFormIndex = responseItem.humanInputFormDataList.findIndex(
- (item) => item.node_id === humanInputFormTimeoutData.node_id,
- )
- responseItem.humanInputFormDataList[currentFormIndex]!.expiration_time =
- humanInputFormTimeoutData.expiration_time
- }
+ updateHumanInputFormTimeout(responseItem, humanInputFormTimeoutData)
})
},
onWorkflowPaused: ({ data: workflowPausedData }) => {
@@ -1717,18 +1684,7 @@ export const useChat = (
workflowRunId: pausedWorkflowRunId || currentWorkflowRunId,
options: otherOptions,
}
- if (!responseItem.humanInputFormDataList) {
- responseItem.humanInputFormDataList = [humanInputRequiredData]
- } else {
- const currentFormIndex = responseItem.humanInputFormDataList!.findIndex(
- (item) => item.node_id === humanInputRequiredData.node_id,
- )
- if (currentFormIndex > -1) {
- responseItem.humanInputFormDataList[currentFormIndex] = humanInputRequiredData
- } else {
- responseItem.humanInputFormDataList.push(humanInputRequiredData)
- }
- }
+ updatePendingHumanInputForm(responseItem, humanInputRequiredData)
const currentTracingIndex = responseItem.workflowProcess!.tracing!.findIndex(
(item) => item.node_id === humanInputRequiredData.node_id,
)
@@ -1746,25 +1702,7 @@ export const useChat = (
onHumanInputFormFilled: ({ data: humanInputFilledFormData }) => {
workflowPauseConfirmedRef.current = false
handleResponding(true)
- let requiredFormData: NonNullable<ChatItem['humanInputFormDataList']>[number] | undefined
- if (responseItem.humanInputFormDataList?.length) {
- const currentFormIndex = responseItem.humanInputFormDataList!.findIndex(
- (item) => item.node_id === humanInputFilledFormData.node_id,
- )
- if (currentFormIndex > -1) {
- requiredFormData = responseItem.humanInputFormDataList[currentFormIndex]
- responseItem.humanInputFormDataList.splice(currentFormIndex, 1)
- }
- }
- const enrichedHumanInputFilledFormData = enrichSubmittedHumanInputFormData(
- humanInputFilledFormData,
- requiredFormData,
- )
- if (!responseItem.humanInputFilledFormDataList) {
- responseItem.humanInputFilledFormDataList = [enrichedHumanInputFilledFormData]
- } else {
- responseItem.humanInputFilledFormDataList.push(enrichedHumanInputFilledFormData)
- }
+ updateFilledHumanInputForm(responseItem, humanInputFilledFormData)
updateCurrentQAOnTree({
placeholderQuestionId,
questionItem,
@@ -1773,13 +1711,7 @@ export const useChat = (
})
},
onHumanInputFormTimeout: ({ data: humanInputFormTimeoutData }) => {
- if (responseItem.humanInputFormDataList?.length) {
- const currentFormIndex = responseItem.humanInputFormDataList!.findIndex(
- (item) => item.node_id === humanInputFormTimeoutData.node_id,
- )
- responseItem.humanInputFormDataList[currentFormIndex]!.expiration_time =
- humanInputFormTimeoutData.expiration_time
- }
+ updateHumanInputFormTimeout(responseItem, humanInputFormTimeoutData)
updateCurrentQAOnTree({
placeholderQuestionId,
questionItem,
diff --git a/web/app/components/base/chat/chat/type.ts b/web/app/components/base/chat/chat/type.ts
index a9c7b2be0fe..862b1432e0f 100644
--- a/web/app/components/base/chat/chat/type.ts
+++ b/web/app/components/base/chat/chat/type.ts
@@ -77,7 +77,7 @@ type SubmittedHumanInputExtraContent = {
type: 'human_input'
submitted: true
form_definition?: HumanInputFormData
- form_submission_data: HumanInputFilledFormData
+ form_submission_data: Omit<HumanInputFilledFormData, 'form_id'>
workflow_run_id?: string
}
diff --git a/web/app/components/share/text-generation/result/__tests__/workflow-stream-handlers.spec.ts b/web/app/components/share/text-generation/result/__tests__/workflow-stream-handlers.spec.ts
index f8921476e0d..034dff8b474 100644
--- a/web/app/components/share/text-generation/result/__tests__/workflow-stream-handlers.spec.ts
+++ b/web/app/components/share/text-generation/result/__tests__/workflow-stream-handlers.spec.ts
@@ -181,11 +181,14 @@ describe('workflow state transformations', () => {
expect(second.resultText).toBe('Hello world')
})
- it('updates pending forms by node and retains submitted form metadata separately', () => {
+ it('updates pending forms by identity and retains submitted form metadata separately', () => {
let process = upsertWorkflowNode(undefined, createTrace())!
process = updateHumanInputRequired(process, createHumanInput())
process = updateHumanInputRequired(process, createHumanInput({ expiration_time: 300 }))
- process = updateHumanInputRequired(process, createHumanInput({ node_id: 'node-2' }))
+ process = updateHumanInputRequired(
+ process,
+ createHumanInput({ node_id: 'node-2', form_id: 'form-2' }),
+ )
expect(process.tracing[0]?.status).toBe(NodeRunningStatus.Paused)
expect(process.humanInputFormDataList?.map((form) => form.node_id)).toEqual([
'node-1',
@@ -193,12 +196,14 @@ describe('workflow state transformations', () => {
])
expect(process.humanInputFormDataList?.[0]?.expiration_time).toBe(300)
process = updateHumanInputTimeout(process, {
+ form_id: 'form-2',
node_id: 'node-2',
node_title: 'Node',
expiration_time: 400,
})
expect(process.humanInputFormDataList?.[1]?.expiration_time).toBe(400)
process = updateHumanInputFilled(process, {
+ form_id: 'form-1',
action_id: 'submit',
action_text: 'Submit',
node_id: 'node-1',
@@ -409,6 +414,7 @@ describe('createWorkflowStreamHandlers', () => {
workflow_run_id: 'run-1',
event: 'human_input_form_filled',
data: {
+ form_id: 'form-1',
node_id: 'node-1',
node_title: 'Node',
rendered_content: 'Done',
@@ -421,6 +427,7 @@ describe('createWorkflowStreamHandlers', () => {
workflow_run_id: 'run-1',
event: 'human_input_form_timeout',
data: {
+ form_id: 'form-1',
node_id: 'node-1',
node_title: 'Node',
expiration_time: 200,
@@ -472,6 +479,14 @@ describe('createWorkflowStreamHandlers', () => {
})
})
+ expect(setup.workflowProcessData()?.humanInputFormDataList).toEqual([])
+ expect(setup.workflowProcessData()?.humanInputFilledFormDataList).toEqual([
+ expect.objectContaining({
+ form_id: 'form-1',
+ rendered_content: 'Done',
+ form_content: 'content',
+ }),
+ ])
expect(setup.currentTaskId()).toBe('task-1')
expect(setup.isStopping()).toBe(false)
expect(setup.workflowProcessData()).toEqual(
diff --git a/web/app/components/share/text-generation/result/workflow-stream-handlers.ts b/web/app/components/share/text-generation/result/workflow-stream-handlers.ts
index 4f27bd3c92e..cc2398849a0 100644
--- a/web/app/components/share/text-generation/result/workflow-stream-handlers.ts
+++ b/web/app/components/share/text-generation/result/workflow-stream-handlers.ts
@@ -8,7 +8,11 @@ import type {
WorkflowFinishedResponse,
} from '@/types/workflow'
import { produce } from 'immer'
-import { enrichSubmittedHumanInputFormData } from '@/app/components/base/chat/chat/answer/human-input-content/submitted-utils'
+import {
+ updateFilledHumanInputForm,
+ updateHumanInputFormTimeout,
+ updatePendingHumanInputForm,
+} from '@/app/components/base/chat/chat/answer/human-input-content/form-state'
import { getFilesInLogs } from '@/app/components/base/file-uploader/utils'
import { NodeRunningStatus, WorkflowRunningStatus } from '@/app/components/workflow/types'
import { sseGet } from '@/service/base'
@@ -195,15 +199,7 @@ const updateHumanInputRequired = (
data: NonNullable<WorkflowProcess['humanInputFormDataList']>[number],
) => {
return updateWorkflowProcess(current, (draft) => {
- if (!draft.humanInputFormDataList) {
- draft.humanInputFormDataList = [data]
- } else {
- const currentFormIndex = draft.humanInputFormDataList.findIndex(
- (item) => item.node_id === data.node_id,
- )
- if (currentFormIndex > -1) draft.humanInputFormDataList[currentFormIndex] = data
- else draft.humanInputFormDataList.push(data)
- }
+ updatePendingHumanInputForm(draft, data)
const currentIndex = draft.tracing.findIndex((item) => item.node_id === data.node_id)
if (currentIndex > -1) draft.tracing[currentIndex]!.status = NodeRunningStatus.Paused
@@ -215,20 +211,7 @@ const updateHumanInputFilled = (
data: NonNullable<WorkflowProcess['humanInputFilledFormDataList']>[number],
) => {
return updateWorkflowProcess(current, (draft) => {
- let requiredFormData: NonNullable<WorkflowProcess['humanInputFormDataList']>[number] | undefined
- if (draft.humanInputFormDataList?.length) {
- const currentFormIndex = draft.humanInputFormDataList.findIndex(
- (item) => item.node_id === data.node_id,
- )
- if (currentFormIndex > -1) {
- requiredFormData = draft.humanInputFormDataList[currentFormIndex]
- draft.humanInputFormDataList.splice(currentFormIndex, 1)
- }
- }
-
- const enrichedData = enrichSubmittedHumanInputFormData(data, requiredFormData)
- if (!draft.humanInputFilledFormDataList) draft.humanInputFilledFormDataList = [enrichedData]
- else draft.humanInputFilledFormDataList.push(enrichedData)
+ updateFilledHumanInputForm(draft, data)
})
}
@@ -237,13 +220,7 @@ const updateHumanInputTimeout = (
data: HumanInputFormTimeoutData,
) => {
return updateWorkflowProcess(current, (draft) => {
- if (!draft.humanInputFormDataList?.length) return
-
- const currentFormIndex = draft.humanInputFormDataList.findIndex(
- (item) => item.node_id === data.node_id,
- )
- if (currentFormIndex > -1)
- draft.humanInputFormDataList[currentFormIndex]!.expiration_time = data.expiration_time
+ updateHumanInputFormTimeout(draft, data)
})
}
diff --git a/web/app/components/workflow/header/__tests__/running-title.spec.tsx b/web/app/components/workflow/header/__tests__/running-title.spec.tsx
index 43bcfe69af3..801984ed184 100644
--- a/web/app/components/workflow/header/__tests__/running-title.spec.tsx
+++ b/web/app/components/workflow/header/__tests__/running-title.spec.tsx
@@ -24,4 +24,18 @@ describe('RunningTitle', () => {
expect(screen.getByText('Test Chat (Running)')).toBeInTheDocument()
})
+
+ it.each(['workflow', 'advanced-chat'] as const)(
+ 'shows paused history in %s mode without a completion time',
+ (mode) => {
+ renderWorkflowComponent(<RunningTitle />, {
+ resource: { kind: 'app', appId: 'app-1', mode },
+ initialStoreState: { historyWorkflowData: { id: 'history-paused', status: 'paused' } },
+ })
+
+ expect(
+ screen.getByText(`Test ${mode === 'advanced-chat' ? 'Chat' : 'Run'} (Paused)`),
+ ).toBeInTheDocument()
+ },
+ )
})
diff --git a/web/app/components/workflow/header/running-title.tsx b/web/app/components/workflow/header/running-title.tsx
index d05ac1f5afa..420176c64e4 100644
--- a/web/app/components/workflow/header/running-title.tsx
+++ b/web/app/components/workflow/header/running-title.tsx
@@ -18,8 +18,8 @@ const RunningTitle = () => {
/>
<span>
{isChatflow
- ? `Test Chat${formatWorkflowRunIdentifier(historyWorkflowData?.finished_at)}`
- : `Test Run${formatWorkflowRunIdentifier(historyWorkflowData?.finished_at)}`}
+ ? `Test Chat${formatWorkflowRunIdentifier(historyWorkflowData?.finished_at, historyWorkflowData?.status)}`
+ : `Test Run${formatWorkflowRunIdentifier(historyWorkflowData?.finished_at, historyWorkflowData?.status)}`}
</span>
<span className="mx-1">·</span>
<span className="ml-1 flex h-4.5 items-center rounded-[5px] border border-indigo-300 bg-white/48 px-1 text-2xs font-semibold text-indigo-600 uppercase">
diff --git a/web/app/components/workflow/hooks/use-workflow-run-event/__tests__/use-workflow-node-human-input-form-filled.spec.ts b/web/app/components/workflow/hooks/use-workflow-run-event/__tests__/use-workflow-node-human-input-form-filled.spec.ts
deleted file mode 100644
index 37ace6ae4cb..00000000000
--- a/web/app/components/workflow/hooks/use-workflow-run-event/__tests__/use-workflow-node-human-input-form-filled.spec.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { baseRunningData, renderWorkflowHook } from '../../../__tests__/workflow-test-env'
-import { useWorkflowNodeHumanInputFormFilled } from '../use-workflow-node-human-input-form-filled'
-
-describe('useWorkflowNodeHumanInputFormFilled', () => {
- it('removes the form from pending and adds it to filled', () => {
- const { result, store } = renderWorkflowHook(() => useWorkflowNodeHumanInputFormFilled(), {
- initialStoreState: {
- workflowRunningData: baseRunningData({
- humanInputFormDataList: [
- { node_id: 'n1', form_id: 'f1', node_title: 'Node 1', form_content: '' },
- ],
- }),
- },
- })
-
- const data = {
- node_id: 'n1',
- node_title: 'Node 1',
- rendered_content: 'done',
- action_id: 'approve',
- action_text: 'Approve',
- }
- result.current.handleWorkflowNodeHumanInputFormFilled({
- task_id: 'task-1',
- workflow_run_id: 'run-1',
- event: 'human_input_form_filled',
- data,
- })
-
- const state = store.getState().workflowRunningData!
- expect(state.humanInputFormDataList).toHaveLength(0)
- expect(state.humanInputFilledFormDataList).toEqual([data])
- })
-})
diff --git a/web/app/components/workflow/hooks/use-workflow-run-event/__tests__/use-workflow-node-human-input-form-timeout.spec.ts b/web/app/components/workflow/hooks/use-workflow-run-event/__tests__/use-workflow-node-human-input-form-timeout.spec.ts
deleted file mode 100644
index e7ba9de17fb..00000000000
--- a/web/app/components/workflow/hooks/use-workflow-run-event/__tests__/use-workflow-node-human-input-form-timeout.spec.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-import { baseRunningData, renderWorkflowHook } from '../../../__tests__/workflow-test-env'
-import { useWorkflowNodeHumanInputFormTimeout } from '../use-workflow-node-human-input-form-timeout'
-
-describe('useWorkflowNodeHumanInputFormTimeout', () => {
- it('sets expiration_time on the matching form', () => {
- const { result, store } = renderWorkflowHook(() => useWorkflowNodeHumanInputFormTimeout(), {
- initialStoreState: {
- workflowRunningData: baseRunningData({
- humanInputFormDataList: [
- {
- node_id: 'n1',
- form_id: 'f1',
- node_title: 'Node 1',
- form_content: '',
- expiration_time: 0,
- },
- ],
- }),
- },
- })
-
- result.current.handleWorkflowNodeHumanInputFormTimeout({
- task_id: 'task',
- workflow_run_id: 'run',
- event: 'human_input_form_timeout',
- data: { node_id: 'n1', node_title: 'Node 1', expiration_time: 1000 },
- })
-
- expect(store.getState().workflowRunningData!.humanInputFormDataList![0]!.expiration_time).toBe(
- 1000,
- )
- })
-})
diff --git a/web/app/components/workflow/hooks/use-workflow-run-event/__tests__/use-workflow-node-human-input-required.spec.ts b/web/app/components/workflow/hooks/use-workflow-run-event/__tests__/use-workflow-node-human-input-required.spec.ts
index eee670efdc7..7cfbda46b6a 100644
--- a/web/app/components/workflow/hooks/use-workflow-run-event/__tests__/use-workflow-node-human-input-required.spec.ts
+++ b/web/app/components/workflow/hooks/use-workflow-run-event/__tests__/use-workflow-node-human-input-required.spec.ts
@@ -2,7 +2,7 @@ import type { HumanInputFormData, HumanInputRequiredResponse } from '@/types/wor
import { act, waitFor } from '@testing-library/react'
import { createNode } from '../../../__tests__/fixtures'
import { baseRunningData } from '../../../__tests__/workflow-test-env'
-import { NodeRunningStatus } from '../../../types'
+import { BlockEnum, NodeRunningStatus } from '../../../types'
import { useWorkflowNodeHumanInputRequired } from '../use-workflow-node-human-input-required'
import { getNodeRuntimeState, renderViewportHook } from './test-helpers'
@@ -20,50 +20,56 @@ const form = (nodeId: string, overrides: Partial<HumanInputFormData> = {}): Huma
...overrides,
})
-it('pauses only the waiting node and replaces its form without losing other pending forms', async () => {
- const { result, store } = renderViewportHook(() => useWorkflowNodeHumanInputRequired(), {
- nodes: ['n1', 'n2'].map((id, index) =>
- createNode({
- id,
- position: { x: index * 300, y: 0 },
- data: { _runningStatus: NodeRunningStatus.Running },
- }),
- ),
- edges: [],
- initialStoreState: {
- workflowRunningData: baseRunningData({
- tracing: ['n1', 'n2'].map((node_id) => ({ node_id, status: NodeRunningStatus.Running })),
- }),
- },
- })
- const send = (data: HumanInputFormData) => {
- const event: HumanInputRequiredResponse = {
- task_id: 'task',
- workflow_run_id: 'run',
- event: 'human_input_required',
- data,
+it.each([BlockEnum.HumanInput, BlockEnum.Tool])(
+ 'pauses only the waiting %s node and updates its form without losing other pending forms',
+ async (nodeType) => {
+ const { result, store } = renderViewportHook(() => useWorkflowNodeHumanInputRequired(), {
+ nodes: ['n1', 'n2'].map((id, index) =>
+ createNode({
+ id,
+ position: { x: index * 300, y: 0 },
+ data: {
+ type: id === 'n1' ? nodeType : BlockEnum.HumanInput,
+ _runningStatus: NodeRunningStatus.Running,
+ },
+ }),
+ ),
+ edges: [],
+ initialStoreState: {
+ workflowRunningData: baseRunningData({
+ tracing: ['n1', 'n2'].map((node_id) => ({ node_id, status: NodeRunningStatus.Running })),
+ }),
+ },
+ })
+ const send = (data: HumanInputFormData) => {
+ const event: HumanInputRequiredResponse = {
+ task_id: 'task',
+ workflow_run_id: 'run',
+ event: 'human_input_required',
+ data,
+ }
+ act(() => result.current.handleWorkflowNodeHumanInputRequired(event))
}
- act(() => result.current.handleWorkflowNodeHumanInputRequired(event))
- }
- const first = form('n1')
- send(first)
- expect(store.getState().workflowRunningData!.humanInputFormDataList).toEqual([first])
- expect(store.getState().workflowRunningData!.tracing).toMatchObject([
- { node_id: 'n1', status: NodeRunningStatus.Paused },
- { node_id: 'n2', status: NodeRunningStatus.Running },
- ])
- await waitFor(() => {
+ const first = form('n1')
+ send(first)
+ expect(store.getState().workflowRunningData!.humanInputFormDataList).toEqual([first])
+ expect(store.getState().workflowRunningData!.tracing).toMatchObject([
+ { node_id: 'n1', status: NodeRunningStatus.Paused },
+ { node_id: 'n2', status: NodeRunningStatus.Running },
+ ])
+ await waitFor(() => {
+ expect(
+ getNodeRuntimeState(result.current.nodes.find((node) => node.id === 'n1'))._runningStatus,
+ ).toBe(NodeRunningStatus.Paused)
+ })
expect(
- getNodeRuntimeState(result.current.nodes.find((node) => node.id === 'n1'))._runningStatus,
- ).toBe(NodeRunningStatus.Paused)
- })
- expect(
- getNodeRuntimeState(result.current.nodes.find((node) => node.id === 'n2'))._runningStatus,
- ).toBe(NodeRunningStatus.Running)
- const second = form('n2')
- send(second)
- expect(store.getState().workflowRunningData!.humanInputFormDataList).toEqual([first, second])
- const updated = form('n1', { form_id: 'replacement', form_content: 'Updated instructions' })
- send(updated)
- expect(store.getState().workflowRunningData!.humanInputFormDataList).toEqual([updated, second])
-})
+ getNodeRuntimeState(result.current.nodes.find((node) => node.id === 'n2'))._runningStatus,
+ ).toBe(NodeRunningStatus.Running)
+ const second = form('n2')
+ send(second)
+ expect(store.getState().workflowRunningData!.humanInputFormDataList).toEqual([first, second])
+ const updated = form('n1', { form_content: 'Updated instructions' })
+ send(updated)
+ expect(store.getState().workflowRunningData!.humanInputFormDataList).toEqual([updated, second])
+ },
+)
diff --git a/web/app/components/workflow/hooks/use-workflow-run-event/use-workflow-node-human-input-form-filled.ts b/web/app/components/workflow/hooks/use-workflow-run-event/use-workflow-node-human-input-form-filled.ts
index 312fc3464f7..45d7748c3b2 100644
--- a/web/app/components/workflow/hooks/use-workflow-run-event/use-workflow-node-human-input-form-filled.ts
+++ b/web/app/components/workflow/hooks/use-workflow-run-event/use-workflow-node-human-input-form-filled.ts
@@ -1,6 +1,7 @@
import type { HumanInputFormFilledResponse } from '@/types/workflow'
import { produce } from 'immer'
import { useCallback } from 'react'
+import { updateFilledHumanInputForm } from '@/app/components/base/chat/chat/answer/human-input-content/form-state'
import { useWorkflowStore } from '@/app/components/workflow/store'
export const useWorkflowNodeHumanInputFormFilled = () => {
@@ -12,17 +13,7 @@ export const useWorkflowNodeHumanInputFormFilled = () => {
const { workflowRunningData, setWorkflowRunningData } = workflowStore.getState()
const newWorkflowRunningData = produce(workflowRunningData!, (draft) => {
- if (draft.humanInputFormDataList?.length) {
- const currentFormIndex = draft.humanInputFormDataList.findIndex(
- (item) => item.node_id === data.node_id,
- )
- draft.humanInputFormDataList.splice(currentFormIndex, 1)
- }
- if (!draft.humanInputFilledFormDataList) {
- draft.humanInputFilledFormDataList = [data]
- } else {
- draft.humanInputFilledFormDataList.push(data)
- }
+ updateFilledHumanInputForm(draft, data)
})
setWorkflowRunningData(newWorkflowRunningData)
},
diff --git a/web/app/components/workflow/hooks/use-workflow-run-event/use-workflow-node-human-input-form-timeout.ts b/web/app/components/workflow/hooks/use-workflow-run-event/use-workflow-node-human-input-form-timeout.ts
index dc054f5d0f2..d490cd3d27a 100644
--- a/web/app/components/workflow/hooks/use-workflow-run-event/use-workflow-node-human-input-form-timeout.ts
+++ b/web/app/components/workflow/hooks/use-workflow-run-event/use-workflow-node-human-input-form-timeout.ts
@@ -1,6 +1,7 @@
import type { HumanInputFormTimeoutResponse } from '@/types/workflow'
import { produce } from 'immer'
import { useCallback } from 'react'
+import { updateHumanInputFormTimeout } from '@/app/components/base/chat/chat/answer/human-input-content/form-state'
import { useWorkflowStore } from '@/app/components/workflow/store'
export const useWorkflowNodeHumanInputFormTimeout = () => {
@@ -12,12 +13,7 @@ export const useWorkflowNodeHumanInputFormTimeout = () => {
const { workflowRunningData, setWorkflowRunningData } = workflowStore.getState()
const newWorkflowRunningData = produce(workflowRunningData!, (draft) => {
- if (draft.humanInputFormDataList?.length) {
- const currentFormIndex = draft.humanInputFormDataList.findIndex(
- (item) => item.node_id === data.node_id,
- )
- draft.humanInputFormDataList[currentFormIndex]!.expiration_time = data.expiration_time
- }
+ updateHumanInputFormTimeout(draft, data)
})
setWorkflowRunningData(newWorkflowRunningData)
},
diff --git a/web/app/components/workflow/hooks/use-workflow-run-event/use-workflow-node-human-input-required.ts b/web/app/components/workflow/hooks/use-workflow-run-event/use-workflow-node-human-input-required.ts
index caf36889242..1a1177d0c57 100644
--- a/web/app/components/workflow/hooks/use-workflow-run-event/use-workflow-node-human-input-required.ts
+++ b/web/app/components/workflow/hooks/use-workflow-run-event/use-workflow-node-human-input-required.ts
@@ -2,6 +2,7 @@ import type { HumanInputRequiredResponse } from '@/types/workflow'
import { produce } from 'immer'
import { useCallback } from 'react'
import { useStoreApi } from 'reactflow'
+import { updatePendingHumanInputForm } from '@/app/components/base/chat/chat/answer/human-input-content/form-state'
import { useWorkflowStore } from '@/app/components/workflow/store'
import { NodeRunningStatus } from '@/app/components/workflow/types'
@@ -16,18 +17,7 @@ export const useWorkflowNodeHumanInputRequired = () => {
const { workflowRunningData, setWorkflowRunningData } = workflowStore.getState()
const newWorkflowRunningData = produce(workflowRunningData!, (draft) => {
- if (!draft.humanInputFormDataList) {
- draft.humanInputFormDataList = [data]
- } else {
- const currentFormIndex = draft.humanInputFormDataList.findIndex(
- (item) => item.node_id === data.node_id,
- )
- if (currentFormIndex > -1) {
- draft.humanInputFormDataList[currentFormIndex] = data
- } else {
- draft.humanInputFormDataList.push(data)
- }
- }
+ updatePendingHumanInputForm(draft, data)
const currentIndex = draft.tracing!.findIndex((item) => item.node_id === data.node_id)
if (currentIndex > -1) {
draft.tracing![currentIndex] = {
diff --git a/web/app/components/workflow/panel/__tests__/human-input-filled-form-list.spec.tsx b/web/app/components/workflow/panel/__tests__/human-input-filled-form-list.spec.tsx
index c694ac09361..97d2ec4e980 100644
--- a/web/app/components/workflow/panel/__tests__/human-input-filled-form-list.spec.tsx
+++ b/web/app/components/workflow/panel/__tests__/human-input-filled-form-list.spec.tsx
@@ -6,6 +6,7 @@ import HumanInputFilledFormList from '../human-input-filled-form-list'
const createFilledForm = (
overrides: Partial<HumanInputFilledFormData> = {},
): HumanInputFilledFormData => ({
+ form_id: 'form-1',
node_id: 'node-1',
node_title: 'Approval',
rendered_content: 'Approved by Alice',
@@ -18,23 +19,20 @@ const createFilledForm = (
})
describe('HumanInputFilledFormList', () => {
- it('renders submitted form content and toggles expansion', async () => {
+ it('keeps each submitted form expanded or collapsed when same-node forms reorder', async () => {
const user = userEvent.setup()
- render(
- <HumanInputFilledFormList
- humanInputFilledFormDataList={[
- createFilledForm(),
- createFilledForm({
- node_id: 'node-2',
- node_title: 'Review',
- rendered_content: 'Reviewed by Bob',
- submitted_data: { summary: 'Reviewed by Bob' },
- action_id: 'review',
- action_text: 'Review',
- }),
- ]}
- />,
+ const first = createFilledForm()
+ const second = createFilledForm({
+ form_id: 'form-2',
+ node_title: 'Review',
+ rendered_content: 'Reviewed by Bob',
+ action_id: 'review',
+ action_text: 'Review',
+ submitted_data: { summary: 'Reviewed by Bob' },
+ })
+ const { rerender } = render(
+ <HumanInputFilledFormList humanInputFilledFormDataList={[first, second]} />,
)
expect(screen.getByText('Approved by Alice')).toBeInTheDocument()
@@ -48,5 +46,12 @@ describe('HumanInputFilledFormList', () => {
expect(collapseApproval).toHaveAttribute('aria-expanded', 'false')
expect(screen.queryByText('Approved by Alice')).not.toBeInTheDocument()
expect(screen.getByText('Reviewed by Bob')).toBeInTheDocument()
+
+ rerender(<HumanInputFilledFormList humanInputFilledFormDataList={[second, first]} />)
+ expect(screen.getByRole('button', { name: /Approval/ })).toHaveAttribute(
+ 'aria-expanded',
+ 'false',
+ )
+ expect(screen.getByRole('button', { name: /Review/ })).toHaveAttribute('aria-expanded', 'true')
})
})
diff --git a/web/app/components/workflow/panel/__tests__/human-input-form-list.spec.tsx b/web/app/components/workflow/panel/__tests__/human-input-form-list.spec.tsx
index ec38e11b6f1..92e6b11cafe 100644
--- a/web/app/components/workflow/panel/__tests__/human-input-form-list.spec.tsx
+++ b/web/app/components/workflow/panel/__tests__/human-input-form-list.spec.tsx
@@ -142,6 +142,44 @@ describe('HumanInputFormList', () => {
})
})
+ it('submits same-Tool forms with separate tokens and preserves the remaining draft', async () => {
+ const user = userEvent.setup()
+ const onSubmit = vi.fn().mockResolvedValue(undefined)
+ const first = createFormData({ node_id: 'tool', node_title: 'First approval' })
+ const second = createFormData({
+ node_id: 'tool',
+ form_id: 'form-2',
+ form_token: 'token-2',
+ node_title: 'Second approval',
+ })
+ const { rerender } = render(
+ <HumanInputFormList
+ humanInputFormDataList={[first, second]}
+ onHumanInputFormSubmit={onSubmit}
+ />,
+ )
+ const inputs = screen.getAllByRole('textbox')
+ await user.clear(inputs[0]!)
+ await user.type(inputs[0]!, 'first decision')
+ await user.clear(inputs[1]!)
+ await user.type(inputs[1]!, 'second decision')
+ await user.click(screen.getAllByRole('button', { name: 'Approve' })[0]!)
+ expect(onSubmit).toHaveBeenCalledWith('token-1', {
+ inputs: { reason: 'first decision' },
+ action: 'approve',
+ })
+
+ rerender(
+ <HumanInputFormList humanInputFormDataList={[second]} onHumanInputFormSubmit={onSubmit} />,
+ )
+ expect(screen.getByRole('textbox')).toHaveValue('second decision')
+ await user.click(screen.getByRole('button', { name: 'Approve' }))
+ expect(onSubmit).toHaveBeenLastCalledWith('token-2', {
+ inputs: { reason: 'second decision' },
+ action: 'approve',
+ })
+ })
+
it('should omit delivery tips when the node has no enabled delivery methods', () => {
mockNodes.push({
id: 'human-node-1',
diff --git a/web/app/components/workflow/panel/__tests__/record.spec.tsx b/web/app/components/workflow/panel/__tests__/record.spec.tsx
index 73b2b8109dc..1afc0e64dff 100644
--- a/web/app/components/workflow/panel/__tests__/record.spec.tsx
+++ b/web/app/components/workflow/panel/__tests__/record.spec.tsx
@@ -77,7 +77,7 @@ describe('Record', () => {
historyWorkflowData: {
id: 'run-1',
status: 'succeeded',
- finished_at: 1700000000000,
+ finished_at: 1_700_000_000,
},
},
hooksStoreProps: {
@@ -90,6 +90,19 @@ describe('Record', () => {
expect(screen.getByTestId('run')).toHaveAttribute('data-tracing-list-url', '/traces/run-1')
})
+ it('renders paused history without a finished timestamp', () => {
+ renderWorkflowComponent(<Record />, {
+ initialStoreState: {
+ historyWorkflowData: {
+ id: 'run-1',
+ status: 'paused',
+ },
+ },
+ })
+
+ expect(screen.getByText('Test Run (Paused)')).toBeInTheDocument()
+ })
+
it('updates the workflow canvas with a fallback viewport when the response omits one', () => {
const nodes = [createNode({ id: 'node-1' })]
const edges = [createEdge({ id: 'edge-1' })]
diff --git a/web/app/components/workflow/panel/__tests__/workflow-preview.spec.tsx b/web/app/components/workflow/panel/__tests__/workflow-preview.spec.tsx
index 35752c00852..7170594b38e 100644
--- a/web/app/components/workflow/panel/__tests__/workflow-preview.spec.tsx
+++ b/web/app/components/workflow/panel/__tests__/workflow-preview.spec.tsx
@@ -84,6 +84,7 @@ const createHumanInputFormData = (
const createHumanInputFilledFormData = (
overrides: Partial<HumanInputFilledFormData> = {},
): HumanInputFilledFormData => ({
+ form_id: 'form-1',
node_id: 'node-1',
node_title: 'Previous approval',
rendered_content: 'Already approved',
diff --git a/web/app/components/workflow/panel/chat-record/__tests__/index.spec.tsx b/web/app/components/workflow/panel/chat-record/__tests__/index.spec.tsx
index c8238ea2dea..1f8a967a6d6 100644
--- a/web/app/components/workflow/panel/chat-record/__tests__/index.spec.tsx
+++ b/web/app/components/workflow/panel/chat-record/__tests__/index.spec.tsx
@@ -23,6 +23,22 @@ describe('ChatRecord', () => {
mockRequest.mockReset()
})
+ it('renders paused history without a finished timestamp', async () => {
+ mockRequest.mockResolvedValue({ data: [] })
+
+ renderWorkflowComponent(<ChatRecord />, {
+ initialStoreState: {
+ historyWorkflowData: {
+ ...historyWorkflowData,
+ status: 'paused',
+ finished_at: undefined,
+ },
+ },
+ })
+
+ expect(await screen.findByText('TEST CHAT (Paused)')).toBeInTheDocument()
+ })
+
it('renders chat history and keeps sibling selection within its conversation', async () => {
const user = userEvent.setup()
diff --git a/web/app/components/workflow/panel/chat-record/index.tsx b/web/app/components/workflow/panel/chat-record/index.tsx
index 3d3158ede71..b78d197c50d 100644
--- a/web/app/components/workflow/panel/chat-record/index.tsx
+++ b/web/app/components/workflow/panel/chat-record/index.tsx
@@ -94,7 +94,7 @@ const ChatRecord = () => {
{!isPending && (
<>
<div className="flex shrink-0 items-center justify-between p-4 pb-1 text-base font-semibold text-text-primary">
- {`TEST CHAT${formatWorkflowRunIdentifier(historyWorkflowData?.finished_at)}`}
+ {`TEST CHAT${formatWorkflowRunIdentifier(historyWorkflowData?.finished_at, historyWorkflowData?.status)}`}
<div
className="flex size-6 cursor-pointer items-center justify-center"
onClick={() => {
diff --git a/web/app/components/workflow/panel/debug-and-preview/__tests__/hooks/handle-resume.spec.ts b/web/app/components/workflow/panel/debug-and-preview/__tests__/hooks/handle-resume.spec.ts
index 06f91252631..4060703fa0b 100644
--- a/web/app/components/workflow/panel/debug-and-preview/__tests__/hooks/handle-resume.spec.ts
+++ b/web/app/components/workflow/panel/debug-and-preview/__tests__/hooks/handle-resume.spec.ts
@@ -720,13 +720,13 @@ describe('useChat – handleResume', () => {
act(() => {
capturedResumeOptions.onHumanInputRequired({
- data: { node_id: 'rn-human', form_token: 'rt-1' },
+ data: { form_id: 'form-rn-human', node_id: 'rn-human', form_token: 'rt-1' },
})
})
act(() => {
capturedResumeOptions.onHumanInputRequired({
- data: { node_id: 'rn-human', form_token: 'rt-2' },
+ data: { form_id: 'form-rn-human', node_id: 'rn-human', form_token: 'rt-2' },
})
})
@@ -735,14 +735,14 @@ describe('useChat – handleResume', () => {
act(() => {
capturedResumeOptions.onHumanInputRequired({
- data: { node_id: 'rn-human-2', form_token: 'rt-3' },
+ data: { form_id: 'form-rn-human-2', node_id: 'rn-human-2', form_token: 'rt-3' },
})
})
answer = result.current.chatList.find((item) => item.id === 'msg-resume')
expect(answer!.humanInputFormDataList).toEqual([
- { node_id: 'rn-human', form_token: 'rt-2' },
- { node_id: 'rn-human-2', form_token: 'rt-3' },
+ { form_id: 'form-rn-human', node_id: 'rn-human', form_token: 'rt-2' },
+ { form_id: 'form-rn-human-2', node_id: 'rn-human-2', form_token: 'rt-3' },
])
})
@@ -764,7 +764,7 @@ describe('useChat – handleResume', () => {
act(() => {
capturedResumeOptions.onHumanInputRequired({
- data: { node_id: 'rn-human', form_token: 'rt-1' },
+ data: { form_id: 'form-rn-human', node_id: 'rn-human', form_token: 'rt-1' },
})
})
@@ -780,13 +780,13 @@ describe('useChat – handleResume', () => {
act(() => {
capturedResumeOptions.onHumanInputRequired({
- data: { node_id: 'rn-human', form_token: 'rt-1' },
+ data: { form_id: 'form-rn-human', node_id: 'rn-human', form_token: 'rt-1' },
})
})
act(() => {
capturedResumeOptions.onHumanInputFormFilled({
- data: { node_id: 'rn-human', submitted_data: { a: 'one' } },
+ data: { form_id: 'form-rn-human', node_id: 'rn-human', submitted_data: { a: 'one' } },
})
})
@@ -803,20 +803,26 @@ describe('useChat – handleResume', () => {
const { result } = await setupResumeWithTree()
act(() => {
capturedResumeOptions.onHumanInputRequired({
- data: { node_id: 'submitted', form_token: 'one' },
+ data: { form_id: 'form-submitted', node_id: 'submitted', form_token: 'one' },
})
capturedResumeOptions.onHumanInputRequired({
- data: { node_id: 'pending', form_token: 'two' },
+ data: { form_id: 'form-pending', node_id: 'pending', form_token: 'two' },
})
capturedResumeOptions.onHumanInputFormFilled({
- data: { node_id: 'submitted', submitted_data: { answer: 'yes' } },
+ data: {
+ form_id: 'form-submitted',
+ node_id: 'submitted',
+ submitted_data: { answer: 'yes' },
+ },
})
capturedResumeOptions.onHumanInputFormTimeout({
- data: { node_id: 'submitted', expiration_time: 1748736000 },
+ data: { form_id: 'form-submitted', node_id: 'submitted', expiration_time: 1748736000 },
})
})
const answer = result.current.chatList.find((item) => item.id === 'msg-resume')
- expect(answer!.humanInputFormDataList).toEqual([{ node_id: 'pending', form_token: 'two' }])
+ expect(answer!.humanInputFormDataList).toEqual([
+ { form_id: 'form-pending', node_id: 'pending', form_token: 'two' },
+ ])
expect(answer!.humanInputFilledFormDataList).toEqual([
expect.objectContaining({ node_id: 'submitted', submitted_data: { answer: 'yes' } }),
])
@@ -827,13 +833,13 @@ describe('useChat – handleResume', () => {
act(() => {
capturedResumeOptions.onHumanInputRequired({
- data: { node_id: 'rn-human', form_token: 'rt-1' },
+ data: { form_id: 'form-rn-human', node_id: 'rn-human', form_token: 'rt-1' },
})
})
act(() => {
capturedResumeOptions.onHumanInputFormTimeout({
- data: { node_id: 'rn-human', expiration_time: 1748736000 },
+ data: { form_id: 'form-rn-human', node_id: 'rn-human', expiration_time: 1748736000 },
})
})
diff --git a/web/app/components/workflow/panel/debug-and-preview/__tests__/hooks/misc.spec.ts b/web/app/components/workflow/panel/debug-and-preview/__tests__/hooks/misc.spec.ts
index e0b73cc96c2..a8b3d8a50bd 100644
--- a/web/app/components/workflow/panel/debug-and-preview/__tests__/hooks/misc.spec.ts
+++ b/web/app/components/workflow/panel/debug-and-preview/__tests__/hooks/misc.spec.ts
@@ -85,7 +85,7 @@ describe('useChat – handleSwitchSibling', () => {
act(() => {
sendCallbacks.onHumanInputRequired({
- data: { node_id: 'human-n', form_token: 'ft-1' },
+ data: { form_id: 'form-human-n', node_id: 'human-n', form_token: 'ft-1' },
})
})
@@ -187,7 +187,7 @@ describe('useChat – handleSwitchSibling', () => {
act(() => {
sendCallbacks.onHumanInputRequired({
- data: { node_id: 'h-child', form_token: 'ft-c' },
+ data: { form_id: 'form-h-child', node_id: 'h-child', form_token: 'ft-c' },
})
})
diff --git a/web/app/components/workflow/panel/debug-and-preview/__tests__/hooks/sse-callbacks.spec.ts b/web/app/components/workflow/panel/debug-and-preview/__tests__/hooks/sse-callbacks.spec.ts
index aa14e14056e..7f8b2393a3b 100644
--- a/web/app/components/workflow/panel/debug-and-preview/__tests__/hooks/sse-callbacks.spec.ts
+++ b/web/app/components/workflow/panel/debug-and-preview/__tests__/hooks/sse-callbacks.spec.ts
@@ -650,6 +650,7 @@ describe('useChat – handleSend SSE callbacks', () => {
act(() => {
capturedCallbacks.onHumanInputRequired({
data: {
+ form_id: 'form-human-node',
node_id: 'human-node',
form_token: 'token-1',
form_content: '{{#$output.answer#}}',
@@ -678,6 +679,7 @@ describe('useChat – handleSend SSE callbacks', () => {
act(() => {
capturedCallbacks.onHumanInputRequired({
data: {
+ form_id: 'form-human-node',
node_id: 'human-node',
form_token: 'token-1',
form_content: '{{#$output.answer#}}',
@@ -688,7 +690,7 @@ describe('useChat – handleSend SSE callbacks', () => {
act(() => {
capturedCallbacks.onHumanInputRequired({
- data: { node_id: 'human-node', form_token: 'token-2' },
+ data: { form_id: 'form-human-node', node_id: 'human-node', form_token: 'token-2' },
})
})
@@ -705,13 +707,13 @@ describe('useChat – handleSend SSE callbacks', () => {
act(() => {
capturedCallbacks.onHumanInputRequired({
- data: { node_id: 'human-node-1', form_token: 'token-1' },
+ data: { form_id: 'form-human-node-1', node_id: 'human-node-1', form_token: 'token-1' },
})
})
act(() => {
capturedCallbacks.onHumanInputRequired({
- data: { node_id: 'human-node-2', form_token: 'token-2' },
+ data: { form_id: 'form-human-node-2', node_id: 'human-node-2', form_token: 'token-2' },
})
})
@@ -732,6 +734,7 @@ describe('useChat – handleSend SSE callbacks', () => {
act(() => {
capturedCallbacks.onHumanInputRequired({
data: {
+ form_id: 'form-human-node',
node_id: 'human-node',
form_token: 'token-1',
form_content: '{{#$output.answer#}}',
@@ -742,7 +745,11 @@ describe('useChat – handleSend SSE callbacks', () => {
act(() => {
capturedCallbacks.onHumanInputFormFilled({
- data: { node_id: 'human-node', submitted_data: { answer: 'yes' } },
+ data: {
+ form_id: 'form-human-node',
+ node_id: 'human-node',
+ submitted_data: { answer: 'yes' },
+ },
})
})
@@ -769,13 +776,13 @@ describe('useChat – handleSend SSE callbacks', () => {
act(() => {
capturedCallbacks.onHumanInputRequired({
- data: { node_id: 'human-node', form_token: 'token-1' },
+ data: { form_id: 'form-human-node', node_id: 'human-node', form_token: 'token-1' },
})
})
act(() => {
capturedCallbacks.onHumanInputFormTimeout({
- data: { node_id: 'human-node', expiration_time: 1735689600 },
+ data: { form_id: 'form-human-node', node_id: 'human-node', expiration_time: 1735689600 },
})
})
diff --git a/web/app/components/workflow/panel/debug-and-preview/hooks.ts b/web/app/components/workflow/panel/debug-and-preview/hooks.ts
index 6e3d2e78ea1..f070fc10b2c 100644
--- a/web/app/components/workflow/panel/debug-and-preview/hooks.ts
+++ b/web/app/components/workflow/panel/debug-and-preview/hooks.ts
@@ -11,7 +11,11 @@ import { useAtomValue } from 'jotai'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useStoreApi } from 'reactflow'
-import { enrichSubmittedHumanInputFormData } from '@/app/components/base/chat/chat/answer/human-input-content/submitted-utils'
+import {
+ updateFilledHumanInputForm,
+ updateHumanInputFormTimeout,
+ updatePendingHumanInputForm,
+} from '@/app/components/base/chat/chat/answer/human-input-content/form-state'
import { getProcessedInputs, processOpeningStatement } from '@/app/components/base/chat/chat/utils'
import { getThreadMessages } from '@/app/components/base/chat/utils'
import {
@@ -629,18 +633,7 @@ export const useChat = (
}
},
onHumanInputRequired: ({ data }) => {
- if (!responseItem.humanInputFormDataList) {
- responseItem.humanInputFormDataList = [data]
- } else {
- const currentFormIndex = responseItem.humanInputFormDataList.findIndex(
- (item) => item.node_id === data.node_id,
- )
- if (currentFormIndex > -1) {
- responseItem.humanInputFormDataList[currentFormIndex] = data
- } else {
- responseItem.humanInputFormDataList.push(data)
- }
- }
+ updatePendingHumanInputForm(responseItem, data)
const currentTracingIndex = responseItem.workflowProcess!.tracing!.findIndex(
(item) => item.node_id === data.node_id,
)
@@ -656,22 +649,7 @@ export const useChat = (
}
},
onHumanInputFormFilled: ({ data }) => {
- let requiredFormData: NonNullable<ChatItem['humanInputFormDataList']>[number] | undefined
- if (responseItem.humanInputFormDataList?.length) {
- const currentFormIndex = responseItem.humanInputFormDataList.findIndex(
- (item) => item.node_id === data.node_id,
- )
- if (currentFormIndex > -1) {
- requiredFormData = responseItem.humanInputFormDataList[currentFormIndex]
- responseItem.humanInputFormDataList.splice(currentFormIndex, 1)
- }
- }
- const enrichedData = enrichSubmittedHumanInputFormData(data, requiredFormData)
- if (!responseItem.humanInputFilledFormDataList) {
- responseItem.humanInputFilledFormDataList = [enrichedData]
- } else {
- responseItem.humanInputFilledFormDataList.push(enrichedData)
- }
+ updateFilledHumanInputForm(responseItem, data)
updateCurrentQAOnTree({
placeholderQuestionId,
questionItem,
@@ -680,14 +658,7 @@ export const useChat = (
})
},
onHumanInputFormTimeout: ({ data }) => {
- if (responseItem.humanInputFormDataList?.length) {
- const currentFormIndex = responseItem.humanInputFormDataList.findIndex(
- (item) => item.node_id === data.node_id,
- )
- if (currentFormIndex > -1)
- responseItem.humanInputFormDataList[currentFormIndex]!.expiration_time =
- data.expiration_time
- }
+ updateHumanInputFormTimeout(responseItem, data)
updateCurrentQAOnTree({
placeholderQuestionId,
questionItem,
@@ -950,18 +921,7 @@ export const useChat = (
},
onHumanInputRequired: ({ data: humanInputRequiredData }) => {
updateChatTreeNode(messageId, (responseItem) => {
- if (!responseItem.humanInputFormDataList) {
- responseItem.humanInputFormDataList = [humanInputRequiredData]
- } else {
- const currentFormIndex = responseItem.humanInputFormDataList.findIndex(
- (item) => item.node_id === humanInputRequiredData.node_id,
- )
- if (currentFormIndex > -1) {
- responseItem.humanInputFormDataList[currentFormIndex] = humanInputRequiredData
- } else {
- responseItem.humanInputFormDataList.push(humanInputRequiredData)
- }
- }
+ updatePendingHumanInputForm(responseItem, humanInputRequiredData)
if (responseItem.workflowProcess?.tracing) {
const currentTracingIndex = responseItem.workflowProcess.tracing.findIndex(
(item) => item.node_id === humanInputRequiredData.node_id,
@@ -974,39 +934,12 @@ export const useChat = (
},
onHumanInputFormFilled: ({ data: humanInputFilledFormData }) => {
updateChatTreeNode(messageId, (responseItem) => {
- let requiredFormData:
- | NonNullable<ChatItem['humanInputFormDataList']>[number]
- | undefined
- if (responseItem.humanInputFormDataList?.length) {
- const currentFormIndex = responseItem.humanInputFormDataList.findIndex(
- (item) => item.node_id === humanInputFilledFormData.node_id,
- )
- if (currentFormIndex > -1) {
- requiredFormData = responseItem.humanInputFormDataList[currentFormIndex]
- responseItem.humanInputFormDataList.splice(currentFormIndex, 1)
- }
- }
- const enrichedHumanInputFilledFormData = enrichSubmittedHumanInputFormData(
- humanInputFilledFormData,
- requiredFormData,
- )
- if (!responseItem.humanInputFilledFormDataList) {
- responseItem.humanInputFilledFormDataList = [enrichedHumanInputFilledFormData]
- } else {
- responseItem.humanInputFilledFormDataList.push(enrichedHumanInputFilledFormData)
- }
+ updateFilledHumanInputForm(responseItem, humanInputFilledFormData)
})
},
onHumanInputFormTimeout: ({ data: humanInputFormTimeoutData }) => {
updateChatTreeNode(messageId, (responseItem) => {
- if (responseItem.humanInputFormDataList?.length) {
- const currentFormIndex = responseItem.humanInputFormDataList.findIndex(
- (item) => item.node_id === humanInputFormTimeoutData.node_id,
- )
- if (currentFormIndex > -1)
- responseItem.humanInputFormDataList[currentFormIndex]!.expiration_time =
- humanInputFormTimeoutData.expiration_time
- }
+ updateHumanInputFormTimeout(responseItem, humanInputFormTimeoutData)
})
},
onWorkflowPaused: () => {
diff --git a/web/app/components/workflow/panel/human-input-filled-form-list.tsx b/web/app/components/workflow/panel/human-input-filled-form-list.tsx
index 03855baf518..d4e1d742235 100644
--- a/web/app/components/workflow/panel/human-input-filled-form-list.tsx
+++ b/web/app/components/workflow/panel/human-input-filled-form-list.tsx
@@ -13,13 +13,13 @@ const HumanInputFilledFormList = ({
<div className="mt-3 flex flex-col gap-y-3 first:mt-0">
{humanInputFilledFormDataList.map((formData) => (
<ContentWrapper
- key={formData.node_id}
+ key={formData.form_id}
nodeTitle={formData.node_title}
showExpandIcon
className="bg-components-panel-bg"
expanded
>
- <SubmittedHumanInputContent key={formData.node_id} formData={formData} />
+ <SubmittedHumanInputContent formData={formData} />
</ContentWrapper>
))}
</div>
diff --git a/web/app/components/workflow/panel/record.tsx b/web/app/components/workflow/panel/record.tsx
index 6ff1c83eb9b..57b9895cea2 100644
--- a/web/app/components/workflow/panel/record.tsx
+++ b/web/app/components/workflow/panel/record.tsx
@@ -26,7 +26,7 @@ const Record = () => {
return (
<div className="flex h-full w-100 flex-col rounded-l-2xl border-[0.5px] border-components-panel-border bg-components-panel-bg shadow-xl">
<div className="flex items-center justify-between p-4 pb-0 system-xl-semibold text-text-primary">
- {`Test Run${formatWorkflowRunIdentifier(historyWorkflowData?.finished_at)}`}
+ {`Test Run${formatWorkflowRunIdentifier(historyWorkflowData?.finished_at, historyWorkflowData?.status)}`}
</div>
<Run
runDetailUrl={getWorkflowRunAndTraceUrl(historyWorkflowData?.id).runUrl}
diff --git a/web/types/workflow.ts b/web/types/workflow.ts
index a3493041074..4dcf760b812 100644
--- a/web/types/workflow.ts
+++ b/web/types/workflow.ts
@@ -368,6 +368,7 @@ export type HumanInputFormValue = string | FileResponse | FileResponse[]
export type HumanInputResolvedValue = string | FileResponse | FileResponse[]
export type HumanInputFilledFormData = {
+ form_id: string
node_id: string
node_title: string
rendered_content: string
@@ -386,6 +387,7 @@ export type HumanInputFormFilledResponse = {
}
export type HumanInputFormTimeoutData = {
+ form_id: string
node_id: string
node_title: string
expiration_time: number