diff --git a/web/app/components/base/features/feature-panel/index.tsx b/web/app/components/base/features/feature-panel/index.tsx index e979391c9..72799ef2f 100644 --- a/web/app/components/base/features/feature-panel/index.tsx +++ b/web/app/components/base/features/feature-panel/index.tsx @@ -13,16 +13,19 @@ import TextToSpeech from './text-to-speech' import SpeechToText from './speech-to-text' import Citation from './citation' import Moderation from './moderation' +import type { InputVar } from '@/app/components/workflow/types' export type FeaturePanelProps = { onChange?: OnFeaturesChange openingStatementProps: OpeningStatementProps disabled?: boolean + workflowVariables: InputVar[] } const FeaturePanel = ({ onChange, openingStatementProps, disabled, + workflowVariables, }: FeaturePanelProps) => { const { t } = useTranslation() const features = useFeatures(s => s.features) @@ -60,6 +63,7 @@ const FeaturePanel = ({ {...openingStatementProps} onChange={onChange} readonly={disabled} + workflowVariables={workflowVariables} /> ) } diff --git a/web/app/components/base/features/feature-panel/opening-statement/index.tsx b/web/app/components/base/features/feature-panel/opening-statement/index.tsx index b039165c9..1f102700a 100644 --- a/web/app/components/base/features/feature-panel/opening-statement/index.tsx +++ b/web/app/components/base/features/feature-panel/opening-statement/index.tsx @@ -24,6 +24,7 @@ import ConfirmAddVar from '@/app/components/app/configuration/config-prompt/conf import { getNewVar } from '@/utils/var' import { varHighlightHTML } from '@/app/components/app/configuration/base/var-highlight' import type { PromptVariable } from '@/models/debug' +import type { InputVar } from '@/app/components/workflow/types' const MAX_QUESTION_NUM = 5 @@ -32,6 +33,7 @@ export type OpeningStatementProps = { readonly?: boolean promptVariables?: PromptVariable[] onAutoAddPromptVariable: (variable: PromptVariable[]) => void + workflowVariables?: InputVar[] } // regex to match the {{}} and replace it with a span @@ -42,6 +44,7 @@ const OpeningStatement: FC = ({ readonly, promptVariables = [], onAutoAddPromptVariable, + workflowVariables = [], }) => { const { t } = useTranslation() const featureStore = useFeaturesStore() @@ -96,14 +99,18 @@ const OpeningStatement: FC = ({ const handleConfirm = () => { const keys = getInputKeys(tempValue) const promptKeys = promptVariables.map(item => item.key) + const workflowVariableKeys = workflowVariables.map(item => item.variable) let notIncludeKeys: string[] = [] - if (promptKeys.length === 0) { + if (promptKeys.length === 0 && workflowVariables.length === 0) { if (keys.length > 0) notIncludeKeys = keys } else { - notIncludeKeys = keys.filter(key => !promptKeys.includes(key)) + if (workflowVariables.length > 0) + notIncludeKeys = keys.filter(key => !workflowVariableKeys.includes(key)) + + else notIncludeKeys = keys.filter(key => !promptKeys.includes(key)) } if (notIncludeKeys.length > 0) { diff --git a/web/app/components/workflow/features.tsx b/web/app/components/workflow/features.tsx index 60a47bf17..16b638108 100644 --- a/web/app/components/workflow/features.tsx +++ b/web/app/components/workflow/features.tsx @@ -4,16 +4,21 @@ import { } from 'react' import { useTranslation } from 'react-i18next' import { RiCloseLine } from '@remixicon/react' +import { useNodes } from 'reactflow' import { useStore } from './store' import { useIsChatMode, useNodesReadOnly, useNodesSyncDraft, } from './hooks' +import { type CommonNodeType, type InputVar, InputVarType, type Node } from './types' +import useConfig from './nodes/start/use-config' +import type { StartNodeType } from './nodes/start/types' import { FeaturesChoose, FeaturesPanel, } from '@/app/components/base/features' +import type { PromptVariable } from '@/models/debug' const Features = () => { const { t } = useTranslation() @@ -21,6 +26,24 @@ const Features = () => { const setShowFeaturesPanel = useStore(s => s.setShowFeaturesPanel) const { nodesReadOnly } = useNodesReadOnly() const { handleSyncWorkflowDraft } = useNodesSyncDraft() + const nodes = useNodes() + + const startNode = nodes.find(node => node.data.type === 'start') + const { id, data } = startNode as Node + const { handleAddVariable } = useConfig(id, data) + + const handleAddOpeningStatementVariable = (variables: PromptVariable[]) => { + const newVariable = variables[0] + const startNodeVariable: InputVar = { + variable: newVariable.key, + label: newVariable.name, + type: InputVarType.textInput, + max_length: newVariable.max_length, + required: newVariable.required || false, + options: [], + } + handleAddVariable(startNodeVariable) + } const handleFeaturesChange = useCallback(() => { handleSyncWorkflowDraft() @@ -55,8 +78,9 @@ const Features = () => { disabled={nodesReadOnly} onChange={handleFeaturesChange} openingStatementProps={{ - onAutoAddPromptVariable: () => {}, + onAutoAddPromptVariable: handleAddOpeningStatementVariable, }} + workflowVariables={data.variables} />