From c7fa7009b179bec98b5d5cb09f54fdd6360be039 Mon Sep 17 00:00:00 2001 From: twwu Date: Tue, 6 Jan 2026 18:13:42 +0800 Subject: [PATCH] refactor: update form submission parameter from formID to formToken across chat components --- .../base/chat/chat-with-history/chat-wrapper.tsx | 6 +++--- .../human-input-content/human-input-form.tsx | 8 ++++---- .../chat/chat/answer/human-input-content/type.ts | 4 ++-- .../chat/answer/human-input-filled-form-list.tsx | 2 +- .../chat/chat/answer/human-input-form-list.tsx | 2 +- .../components/base/chat/chat/answer/index.tsx | 2 +- web/app/components/base/chat/chat/index.tsx | 2 +- .../base/chat/embedded-chatbot/chat-wrapper.tsx | 6 +++--- .../panel/debug-and-preview/chat-wrapper.tsx | 4 ++-- .../workflow/panel/debug-and-preview/hooks.ts | 4 ++-- .../panel/human-input-filled-form-list.tsx | 16 +--------------- .../workflow/panel/human-input-form-list.tsx | 2 +- .../workflow/panel/workflow-preview.tsx | 4 ++-- web/types/workflow.ts | 3 ++- 14 files changed, 26 insertions(+), 39 deletions(-) diff --git a/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx b/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx index cb2e4a8ba6..2222d7adf0 100644 --- a/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx +++ b/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx @@ -163,11 +163,11 @@ const ChatWrapper = () => { return chatList.filter(item => !item.isOpeningStatement) }, [chatList, currentConversationId]) - const handleSubmitHumanInputForm = useCallback(async (formID: string, formData: any) => { + const handleSubmitHumanInputForm = useCallback(async (formToken: string, formData: any) => { if (isInstalledApp) - await submitHumanInputFormService(formID, formData) + await submitHumanInputFormService(formToken, formData) else - await submitHumanInputForm(formID, formData) + await submitHumanInputForm(formToken, formData) }, [isInstalledApp]) const [collapsed, setCollapsed] = useState(!!currentConversationId) diff --git a/web/app/components/base/chat/chat/answer/human-input-content/human-input-form.tsx b/web/app/components/base/chat/chat/answer/human-input-content/human-input-form.tsx index 95595c5b6d..429143d38f 100644 --- a/web/app/components/base/chat/chat/answer/human-input-content/human-input-form.tsx +++ b/web/app/components/base/chat/chat/answer/human-input-content/human-input-form.tsx @@ -10,7 +10,7 @@ const HumanInputForm = ({ formData, onSubmit, }: HumanInputFormProps) => { - const formID = formData.form_id + const formToken = formData.form_token const defaultInputs = initializeInputs(formData.inputs) const contentList = splitByOutputVar(formData.form_content) const [inputs, setInputs] = useState(defaultInputs) @@ -23,9 +23,9 @@ const HumanInputForm = ({ })) }, []) - const submit = async (formID: string, actionID: string, inputs: Record) => { + const submit = async (formToken: string, actionID: string, inputs: Record) => { setIsSubmitting(true) - await onSubmit?.(formID, { inputs, action: actionID }) + await onSubmit?.(formToken, { inputs, action: actionID }) setIsSubmitting(false) } @@ -47,7 +47,7 @@ const HumanInputForm = ({ key={action.id} disabled={isSubmitting} variant={getButtonStyle(action.button_style) as any} - onClick={() => submit(formID, action.id, inputs)} + onClick={() => submit(formToken, action.id, inputs)} > {action.title} diff --git a/web/app/components/base/chat/chat/answer/human-input-content/type.ts b/web/app/components/base/chat/chat/answer/human-input-content/type.ts index 41f0a31341..a37b699e28 100644 --- a/web/app/components/base/chat/chat/answer/human-input-content/type.ts +++ b/web/app/components/base/chat/chat/answer/human-input-content/type.ts @@ -13,7 +13,7 @@ export type UnsubmittedHumanInputContentProps = { showDebugModeTip?: boolean showTimeout?: boolean expirationTime?: number - onSubmit?: (formID: string, data: any) => Promise + onSubmit?: (formToken: string, data: any) => Promise } export type SubmittedHumanInputContentProps = { @@ -22,7 +22,7 @@ export type SubmittedHumanInputContentProps = { export type HumanInputFormProps = { formData: HumanInputFormData - onSubmit?: (formID: string, data: any) => Promise + onSubmit?: (formToken: string, data: any) => Promise } export type ContentItemProps = { 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 51d7c36913..4dd82b13a7 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 @@ -15,7 +15,7 @@ const HumanInputFilledFormList = ({ humanInputFilledFormDataList.map(formData => ( Promise + onHumanInputFormSubmit?: (formToken: string, formData: any) => Promise getHumanInputNodeData?: (nodeID: string) => any } diff --git a/web/app/components/base/chat/chat/answer/index.tsx b/web/app/components/base/chat/chat/answer/index.tsx index e9a24d10a5..53589cfecf 100644 --- a/web/app/components/base/chat/chat/answer/index.tsx +++ b/web/app/components/base/chat/chat/answer/index.tsx @@ -40,7 +40,7 @@ type AnswerProps = { noChatInput?: boolean switchSibling?: (siblingMessageId: string) => void hideAvatar?: boolean - onHumanInputFormSubmit?: (formID: string, formData: any) => Promise + onHumanInputFormSubmit?: (formToken: string, formData: any) => Promise } const Answer: FC = ({ item, diff --git a/web/app/components/base/chat/chat/index.tsx b/web/app/components/base/chat/chat/index.tsx index bc926ce244..6656b70a1b 100644 --- a/web/app/components/base/chat/chat/index.tsx +++ b/web/app/components/base/chat/chat/index.tsx @@ -73,7 +73,7 @@ export type ChatProps = { inputDisabled?: boolean sidebarCollapseState?: boolean hideAvatar?: boolean - onHumanInputFormSubmit?: (formID: string, formData: any) => Promise + onHumanInputFormSubmit?: (formToken: string, formData: any) => Promise getHumanInputNodeData?: (nodeID: string) => any } diff --git a/web/app/components/base/chat/embedded-chatbot/chat-wrapper.tsx b/web/app/components/base/chat/embedded-chatbot/chat-wrapper.tsx index 62c960410f..cfad5e71ae 100644 --- a/web/app/components/base/chat/embedded-chatbot/chat-wrapper.tsx +++ b/web/app/components/base/chat/embedded-chatbot/chat-wrapper.tsx @@ -176,11 +176,11 @@ const ChatWrapper = () => { } }, [inputsForms.length, isMobile, currentConversationId, collapsed, allInputsHidden]) - const handleSubmitHumanInputForm = useCallback(async (formID: string, formData: any) => { + const handleSubmitHumanInputForm = useCallback(async (formToken: string, formData: any) => { if (isInstalledApp) - await submitHumanInputFormService(formID, formData) + await submitHumanInputFormService(formToken, formData) else - await submitHumanInputForm(formID, formData) + await submitHumanInputForm(formToken, formData) }, [isInstalledApp]) const welcome = useMemo(() => { diff --git a/web/app/components/workflow/panel/debug-and-preview/chat-wrapper.tsx b/web/app/components/workflow/panel/debug-and-preview/chat-wrapper.tsx index b821d65f78..da45f9c43c 100644 --- a/web/app/components/workflow/panel/debug-and-preview/chat-wrapper.tsx +++ b/web/app/components/workflow/panel/debug-and-preview/chat-wrapper.tsx @@ -123,9 +123,9 @@ const ChatWrapper = ( doSend(editedQuestion ? editedQuestion.message : question.content, editedQuestion ? editedQuestion.files : question.message_files, true, isValidGeneratedAnswer(parentAnswer) ? parentAnswer : null) }, [chatList, doSend]) - const doHumanInputFormSubmit = useCallback(async (formID: string, formData: any) => { + const doHumanInputFormSubmit = useCallback(async (formToken: string, formData: any) => { // Handle human input form submission - await handleSubmitHumanInputForm(formID, formData) + await handleSubmitHumanInputForm(formToken, formData) }, [handleSubmitHumanInputForm]) const inputDisabled = useMemo(() => { 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 9bb8b1aad4..b03f17cd67 100644 --- a/web/app/components/workflow/panel/debug-and-preview/hooks.ts +++ b/web/app/components/workflow/panel/debug-and-preview/hooks.ts @@ -583,8 +583,8 @@ export const useChat = ( ) }, [threadMessages, chatTree.length, updateCurrentQAOnTree, handleResponding, formSettings?.inputsForm, handleRun, notify, t, workflowStore, fetchInspectVars, invalidAllLastRun, config?.suggested_questions_after_answer?.enabled]) - const handleSubmitHumanInputForm = async (formID: string, formData: any) => { - await submitHumanInputForm(formID, formData) + const handleSubmitHumanInputForm = async (formToken: string, formData: any) => { + await submitHumanInputForm(formToken, formData) } const getHumanInputNodeData = (nodeID: string) => { 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 94ce49b962..7f39e939fe 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 @@ -1,9 +1,6 @@ import type { HumanInputFilledFormData } from '@/types/workflow' -import { useCallback } from 'react' -import { useStoreApi } from 'reactflow' import ContentWrapper from '@/app/components/base/chat/chat/answer/human-input-content/content-wrapper' import { SubmittedHumanInputContent } from '@/app/components/base/chat/chat/answer/human-input-content/submitted' -import { CUSTOM_NODE } from '@/app/components/workflow/constants' type HumanInputFilledFormListProps = { humanInputFilledFormDataList: HumanInputFilledFormData[] @@ -12,24 +9,13 @@ type HumanInputFilledFormListProps = { const HumanInputFilledFormList = ({ humanInputFilledFormDataList, }: HumanInputFilledFormListProps) => { - const store = useStoreApi() - - const getHumanInputNodeTitle = useCallback((nodeID: string) => { - const { - getNodes, - } = store.getState() - const nodes = getNodes().filter(node => node.type === CUSTOM_NODE) - const node = nodes.find(n => n.id === nodeID) - return node?.data.title - }, [store]) - return (
{ humanInputFilledFormDataList.map(formData => ( Promise + onHumanInputFormSubmit?: (formToken: string, formData: any) => Promise } const HumanInputFormList = ({ diff --git a/web/app/components/workflow/panel/workflow-preview.tsx b/web/app/components/workflow/panel/workflow-preview.tsx index d01cfdf3e2..239fba57a6 100644 --- a/web/app/components/workflow/panel/workflow-preview.tsx +++ b/web/app/components/workflow/panel/workflow-preview.tsx @@ -99,8 +99,8 @@ const WorkflowPreview = () => { } }, [resize, stopResizing]) - const handleSubmitHumanInputForm = useCallback(async (formID: string, formData: any) => { - await submitHumanInputForm(formID, formData) + const handleSubmitHumanInputForm = useCallback(async (formToken: string, formData: any) => { + await submitHumanInputForm(formToken, formData) }, []) return ( diff --git a/web/types/workflow.ts b/web/types/workflow.ts index e4e0d0fc6c..0f68f84e24 100644 --- a/web/types/workflow.ts +++ b/web/types/workflow.ts @@ -320,7 +320,7 @@ export type HumanInputFormData = { form_content: string inputs: FormInputItem[] actions: UserAction[] - web_app_form_token: string // For WebApp + form_token: string resolved_placeholder_values: Record // For human input placeholder when its type is variable } @@ -333,6 +333,7 @@ export type HumanInputRequiredResponse = { export type HumanInputFilledFormData = { node_id: string + node_title: string rendered_content: string action_id: string action_text: string