From 3c0fd213bf0b578d719033ba98c4c6299c6604fa Mon Sep 17 00:00:00 2001 From: twwu Date: Wed, 24 Dec 2025 12:13:32 +0800 Subject: [PATCH] refactor: update human input form handling to support async submission and improve placeholder resolution --- .../human-input-content/content-item.tsx | 103 +++++------------- .../human-input-content/human-input-form.tsx | 33 ++---- .../chat/answer/human-input-content/index.tsx | 36 +++--- .../chat/answer/human-input-content/type.ts | 34 ++++++ .../chat/answer/human-input-content/utils.ts | 2 +- .../base/chat/chat/answer/index.tsx | 31 +++++- web/app/components/base/chat/chat/index.tsx | 2 +- .../workflow/nodes/human-input/types.ts | 12 +- web/service/base.ts | 80 +++++++------- web/service/common.ts | 3 +- web/service/use-common.ts | 5 +- web/types/workflow.ts | 9 +- 12 files changed, 168 insertions(+), 182 deletions(-) create mode 100644 web/app/components/base/chat/chat/answer/human-input-content/type.ts diff --git a/web/app/components/base/chat/chat/answer/human-input-content/content-item.tsx b/web/app/components/base/chat/chat/answer/human-input-content/content-item.tsx index 35ada6d907..f7b541c10a 100644 --- a/web/app/components/base/chat/chat/answer/human-input-content/content-item.tsx +++ b/web/app/components/base/chat/chat/answer/human-input-content/content-item.tsx @@ -1,111 +1,60 @@ -import React from 'react' +import React, { useMemo } from 'react' import { Markdown } from '@/app/components/base/markdown' -import Select from '@/app/components/base/select' import Textarea from '@/app/components/base/textarea' -import Input from '@/app/components/base/input' -import FormInputBoolean from '@/app/components/workflow/nodes/_base/components/form-input-boolean' -import { FileUploaderInAttachmentWrapper } from '@/app/components/base/file-uploader' -import { getProcessedFiles } from '@/app/components/base/file-uploader/utils' -import { DEFAULT_VALUE_MAX_LEN } from '@/config' -import type { GeneratedFormInputItem } from '@/app/components/workflow/nodes/human-input/types' +import type { ContentItemProps } from './type' -type Props = { - content: string - formInputFields: GeneratedFormInputItem[] - inputs: Record - onInputChange: (name: string, value: any) => void -} - -const ContentItem = ({ content, formInputFields, inputs, onInputChange }: Props) => { +const ContentItem = ({ + content, + formInputFields, + inputs, + resolvedPlaceholderValues, + onInputChange, +}: ContentItemProps) => { const isInputField = (field: string) => { const outputVarRegex = /{{#\$output\.[^#]+#}}/ return outputVarRegex.test(field) } - const extractFieldName = (str: string) => { + const extractFieldName = (str: string): string => { const outputVarRegex = /{{#\$output\.([^#]+)#}}/ const match = str.match(outputVarRegex) return match ? match[1] : '' } + const fieldName = useMemo(() => { + return extractFieldName(content) + }, [content]) + + const formInputField = useMemo(() => { + return formInputFields.find(field => field.output_variable_name === fieldName) + }, [formInputFields, fieldName]) + + const placeholder = useMemo(() => { + return formInputField?.placeholder.type === 'variable' + ? resolvedPlaceholderValues?.[fieldName] + : formInputField?.placeholder.value + }, [formInputField, resolvedPlaceholderValues, fieldName]) + if (!isInputField(content)) { return ( ) } - const fieldName = extractFieldName(content) - const formInputField = formInputFields.find(field => field.output_variable_name === fieldName) - if (!formInputField) return null return (
- {formInputField.type === 'select' && ( - { onInputChange(fieldName, e.target.value) }} - maxLength={formInputField.max_length || DEFAULT_VALUE_MAX_LEN} - /> - )} {formInputField.type === 'paragraph' && (