From 1d738f3fa69329f1474c55ef8047c183c6dfb7b3 Mon Sep 17 00:00:00 2001 From: Joel Date: Wed, 9 Jul 2025 16:48:17 +0800 Subject: [PATCH] feat: chat support bool --- .../chat/chat-with-history/chat-wrapper.tsx | 5 ++-- .../base/chat/chat-with-history/hooks.tsx | 2 +- .../chat-with-history/inputs-form/content.tsx | 23 ++++++++++++++----- .../chat/embedded-chatbot/chat-wrapper.tsx | 2 +- .../base/chat/embedded-chatbot/hooks.tsx | 2 +- .../embedded-chatbot/inputs-form/content.tsx | 11 +++++++++ web/utils/model-config.ts | 2 +- 7 files changed, 35 insertions(+), 12 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 cbe4826c14..2cdd10147e 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 @@ -23,6 +23,7 @@ import SuggestedQuestions from '@/app/components/base/chat/chat/answer/suggested import { Markdown } from '@/app/components/base/markdown' import cn from '@/utils/classnames' import type { FileEntity } from '../../file-uploader/types' +import { formatBooleanInputs } from '@/utils/model-config' const ChatWrapper = () => { const { @@ -87,7 +88,7 @@ const ChatWrapper = () => { let hasEmptyInput = '' let fileIsUploading = false - const requiredVars = inputsForms.filter(({ required }) => required) + const requiredVars = inputsForms.filter(({ required, type }) => required && type !== InputVarType.boolean) if (requiredVars.length) { requiredVars.forEach(({ variable, label, type }) => { if (hasEmptyInput) @@ -130,7 +131,7 @@ const ChatWrapper = () => { const data: any = { query: message, files, - inputs: currentConversationId ? currentConversationInputs : newConversationInputs, + inputs: formatBooleanInputs(inputsForms, currentConversationId ? currentConversationInputs : newConversationInputs), conversation_id: currentConversationId, parent_message_id: (isRegenerate ? parentAnswer?.id : getLastAnswer(chatList)?.id) || null, } 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 32f74e6457..6161ffbee7 100644 --- a/web/app/components/base/chat/chat-with-history/hooks.tsx +++ b/web/app/components/base/chat/chat-with-history/hooks.tsx @@ -331,7 +331,7 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => { let hasEmptyInput = '' let fileIsUploading = false - const requiredVars = inputsForms.filter(({ required }) => required) + const requiredVars = inputsForms.filter(({ required, type }) => required && type !== InputVarType.boolean) if (requiredVars.length) { requiredVars.forEach(({ variable, label, type }) => { if (hasEmptyInput) diff --git a/web/app/components/base/chat/chat-with-history/inputs-form/content.tsx b/web/app/components/base/chat/chat-with-history/inputs-form/content.tsx index 73a1f07b69..4ba49548d4 100644 --- a/web/app/components/base/chat/chat-with-history/inputs-form/content.tsx +++ b/web/app/components/base/chat/chat-with-history/inputs-form/content.tsx @@ -6,6 +6,7 @@ import Textarea from '@/app/components/base/textarea' import { PortalSelect } from '@/app/components/base/select' import { FileUploaderInAttachmentWrapper } from '@/app/components/base/file-uploader' import { InputVarType } from '@/app/components/workflow/types' +import BoolInput from '@/app/components/workflow/nodes/_base/components/before-run-form/bool-input' type Props = { showTip?: boolean @@ -42,12 +43,14 @@ const InputsFormContent = ({ showTip }: Props) => {
{visibleInputsForms.map(form => (
-
-
{form.label}
- {!form.required && ( -
{t('appDebug.variableTable.optional')}
- )} -
+ {form.type !== InputVarType.boolean && ( +
+
{form.label}
+ {!form.required && ( +
{t('appDebug.variableTable.optional')}
+ )} +
+ )} {form.type === InputVarType.textInput && ( { placeholder={form.label} /> )} + {form.type === InputVarType.boolean && ( + handleFormChange(form.variable, value)} + /> + )} {form.type === InputVarType.select && ( { let hasEmptyInput = '' let fileIsUploading = false - const requiredVars = inputsForms.filter(({ required }) => required) + const requiredVars = inputsForms.filter(({ required, type }) => required && type !== InputVarType.boolean) if (requiredVars.length) { requiredVars.forEach(({ variable, label, type }) => { if (hasEmptyInput) diff --git a/web/app/components/base/chat/embedded-chatbot/hooks.tsx b/web/app/components/base/chat/embedded-chatbot/hooks.tsx index 7dd665efdc..a097823c0f 100644 --- a/web/app/components/base/chat/embedded-chatbot/hooks.tsx +++ b/web/app/components/base/chat/embedded-chatbot/hooks.tsx @@ -312,7 +312,7 @@ export const useEmbeddedChatbot = () => { let hasEmptyInput = '' let fileIsUploading = false - const requiredVars = inputsForms.filter(({ required }) => required) + const requiredVars = inputsForms.filter(({ required, type }) => required && type !== InputVarType.boolean) if (requiredVars.length) { requiredVars.forEach(({ variable, label, type }) => { if (hasEmptyInput) diff --git a/web/app/components/base/chat/embedded-chatbot/inputs-form/content.tsx b/web/app/components/base/chat/embedded-chatbot/inputs-form/content.tsx index c5f39718f1..631f144720 100644 --- a/web/app/components/base/chat/embedded-chatbot/inputs-form/content.tsx +++ b/web/app/components/base/chat/embedded-chatbot/inputs-form/content.tsx @@ -6,6 +6,7 @@ import Textarea from '@/app/components/base/textarea' import { PortalSelect } from '@/app/components/base/select' import { FileUploaderInAttachmentWrapper } from '@/app/components/base/file-uploader' import { InputVarType } from '@/app/components/workflow/types' +import BoolInput from '@/app/components/workflow/nodes/_base/components/before-run-form/bool-input' type Props = { showTip?: boolean @@ -42,12 +43,14 @@ const InputsFormContent = ({ showTip }: Props) => {
{visibleInputsForms.map(form => (
+ {form.type !== InputVarType.boolean && (
{form.label}
{!form.required && (
{t('appDebug.variableTable.optional')}
)}
+ )} {form.type === InputVarType.textInput && ( { placeholder={form.label} /> )} + {form.type === InputVarType.boolean && ( + handleFormChange(form.variable, value)} + /> + )} {form.type === InputVarType.select && ( ) => { +export const formatBooleanInputs = (useInputs?: PromptVariable[] | null, inputs?: Record | null) => { if(!useInputs) return inputs const res = { ...(inputs || {}) }