diff --git a/web/app/(commonLayout)/workflow/nodes/page.tsx b/web/app/(commonLayout)/workflow/nodes/page.tsx index 117e9b4cf7..ea6542d771 100644 --- a/web/app/(commonLayout)/workflow/nodes/page.tsx +++ b/web/app/(commonLayout)/workflow/nodes/page.tsx @@ -5,9 +5,9 @@ import { memo } from 'react' import Workflow from '@/app/components/workflow' import { BlockEnum } from '@/app/components/workflow/types' const nodes = [ - BlockEnum.Start/* 1 */, BlockEnum.DirectAnswer/* 2 */, BlockEnum.LLM/* 3 */, BlockEnum.KnowledgeRetrieval/* 4 */, BlockEnum.QuestionClassifier/* 5 */, + BlockEnum.End/* 12 */, BlockEnum.Start/* 1 */, BlockEnum.DirectAnswer/* 2 */, BlockEnum.LLM/* 3 */, BlockEnum.KnowledgeRetrieval/* 4 */, BlockEnum.QuestionClassifier/* 5 */, BlockEnum.IfElse/* 6 */, BlockEnum.Code/* 7 */, BlockEnum.TemplateTransform/* 8 */, BlockEnum.HttpRequest/* 9 */, BlockEnum.Tool/* 10 */, - BlockEnum.VariableAssigner/* 11 */, BlockEnum.End/* 12 */, + BlockEnum.VariableAssigner/* 11 */, ].map((item, i) => ({ id: `${i + 1}`, type: 'custom', diff --git a/web/app/components/workflow/nodes/_base/components/field.tsx b/web/app/components/workflow/nodes/_base/components/field.tsx index 24c7187d2e..82c05c390c 100644 --- a/web/app/components/workflow/nodes/_base/components/field.tsx +++ b/web/app/components/workflow/nodes/_base/components/field.tsx @@ -23,7 +23,7 @@ const Filed: FC = ({
-
{title}
+
{title}
{tooltip && ( diff --git a/web/app/components/workflow/nodes/end/mock.ts b/web/app/components/workflow/nodes/end/mock.ts index b12d98cba9..d1885c6117 100644 --- a/web/app/components/workflow/nodes/end/mock.ts +++ b/web/app/components/workflow/nodes/end/mock.ts @@ -1,13 +1,14 @@ +import { BlockEnum } from '../../types' import { EndVarType } from './types' import type { EndNodeType } from './types' export const mockData: EndNodeType = { title: 'Test', desc: 'Test', - type: 'Test', + type: BlockEnum.End, outputs: { - type: EndVarType.plainText, - plain_text_selector: ['test'], + type: EndVarType.structured, + plain_text_selector: ['aaa', 'name'], structured_variables: [ { variable: 'test', diff --git a/web/app/components/workflow/nodes/end/panel.tsx b/web/app/components/workflow/nodes/end/panel.tsx index 6e401a9a4e..2cfdd65540 100644 --- a/web/app/components/workflow/nodes/end/panel.tsx +++ b/web/app/components/workflow/nodes/end/panel.tsx @@ -1,8 +1,97 @@ -import type { FC } from 'react' +import { type FC, useCallback } from 'react' +import { useTranslation } from 'react-i18next' +import cn from 'classnames' +import VarReferencePicker from '../_base/components/variable/var-reference-picker' +import useConfig from './use-config' +import { mockData } from './mock' +import { EndVarType } from './types' +import VarList from '@/app/components/workflow/nodes/_base/components/variable/var-list' +import Field from '@/app/components/workflow/nodes/_base/components/field' +import AddButton from '@/app/components/base/button/add-button' +const i18nPrefix = 'workflow.nodes.end' + +const TypeItem = ({ type, current, onClick }: { type: EndVarType; current: EndVarType; onClick: (type: EndVarType) => void }) => { + const { t } = useTranslation() + + const handleOnClick = useCallback(() => { + if (type === current) + return + onClick(type) + }, [type, current, onClick]) + return ( +
+ {t(`${i18nPrefix}.type.${type}`)} +
+ ) +} + +const allTypes = [EndVarType.plainText, EndVarType.structured, EndVarType.none] const Panel: FC = () => { + const { t } = useTranslation() + const readOnly = false + + const { + inputs, + handleOutputTypeChange, + handleVarListChange, + handelPlainTextSelectorChange, + handleAddVariable, + } = useConfig(mockData) + + const outputs = inputs.outputs return ( -
start panel inputs
+
+
+ +
+ {allTypes.map(type => ( + + ))} +
+
+ {outputs.type !== EndVarType.none && ( + : undefined + } + > + {outputs.type + === EndVarType.structured + ? ( + + ) + : ( + + )} + + + )} +
+
) } diff --git a/web/app/components/workflow/nodes/end/types.ts b/web/app/components/workflow/nodes/end/types.ts index 3386ed9ec6..eb038f4f24 100644 --- a/web/app/components/workflow/nodes/end/types.ts +++ b/web/app/components/workflow/nodes/end/types.ts @@ -5,11 +5,11 @@ export enum EndVarType { plainText = 'plain-text', structured = 'structured', } - -export type EndNodeType = CommonNodeType & { - outputs: { - type: EndVarType - plain_text_selector?: string[] - structured_variables?: Variable[] - } +export type OutPuts = { + type: EndVarType + plain_text_selector?: string[] + structured_variables?: Variable[] +} +export type EndNodeType = CommonNodeType & { + outputs: OutPuts } diff --git a/web/app/components/workflow/nodes/end/use-config.ts b/web/app/components/workflow/nodes/end/use-config.ts new file mode 100644 index 0000000000..0ce1e908e4 --- /dev/null +++ b/web/app/components/workflow/nodes/end/use-config.ts @@ -0,0 +1,43 @@ +import produce from 'immer' +import { useCallback, useState } from 'react' +import useVarList from '../_base/hooks/use-var-list' +import type { EndNodeType, EndVarType, OutPuts } from './types' + +const useConfig = (initInputs: EndNodeType) => { + const [inputs, setInputs] = useState(initInputs) + const handleOutputTypeChange = useCallback((type: EndVarType) => { + const newInputs = produce(inputs, (draft: any) => { + draft.outputs.type = type + }) + setInputs(newInputs) + }, [inputs, setInputs]) + + const handelPlainTextSelectorChange = useCallback((newList: string[]) => { + const newInputs = produce(inputs, (draft: any) => { + draft.outputs.plain_text_selector = newList + }) + setInputs(newInputs) + } + , [inputs, setInputs]) + + const { handleVarListChange, handleAddVariable } = useVarList({ + inputs: inputs.outputs, + setInputs: (newOutputs) => { + const newInputs = produce(inputs, (draft: any) => { + draft.outputs = newOutputs + }) + setInputs(newInputs) + }, + varKey: 'structured_variables', + }) + + return { + inputs, + handleOutputTypeChange, + handelPlainTextSelectorChange, + handleVarListChange, + handleAddVariable, + } +} + +export default useConfig diff --git a/web/i18n/en-US/workflow.ts b/web/i18n/en-US/workflow.ts index bfb678238c..915838ac39 100644 --- a/web/i18n/en-US/workflow.ts +++ b/web/i18n/en-US/workflow.ts @@ -21,6 +21,10 @@ const translation = { }, end: { outputs: 'Outputs', + output: { + type: 'output type', + variable: 'output variable', + }, type: { 'none': 'None', 'plain-text': 'Plain Text', diff --git a/web/i18n/zh-Hans/workflow.ts b/web/i18n/zh-Hans/workflow.ts index abc3afa7d3..5cf60f3330 100644 --- a/web/i18n/zh-Hans/workflow.ts +++ b/web/i18n/zh-Hans/workflow.ts @@ -20,6 +20,10 @@ const translation = { }, end: { outputs: '输出', + output: { + type: '输出类型', + variable: '输出变量', + }, type: { 'none': '无', 'plain-text': '纯文本',