From 6fea18b4d0ff34ce6ebad43ae0436419cb6881e2 Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 1 Apr 2024 17:40:17 +0800 Subject: [PATCH] feat: insert var key ui --- .../components/before-run-form/form-item.tsx | 33 +++++++++++++++++-- .../workflow/nodes/llm/use-config.ts | 8 +++-- web/app/components/workflow/types.ts | 12 +++++-- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/web/app/components/workflow/nodes/_base/components/before-run-form/form-item.tsx b/web/app/components/workflow/nodes/_base/components/before-run-form/form-item.tsx index 5d6cb392ab..4edbd7c391 100644 --- a/web/app/components/workflow/nodes/_base/components/before-run-form/form-item.tsx +++ b/web/app/components/workflow/nodes/_base/components/before-run-form/form-item.tsx @@ -3,7 +3,7 @@ import type { FC } from 'react' import React, { useCallback } from 'react' import produce from 'immer' import type { InputVar } from '../../../../types' -import { InputVarType } from '../../../../types' +import { BlockEnum, InputVarType } from '../../../../types' import CodeEditor from '../editor/code-editor' import { CodeLanguage } from '../../../code/types' import Select from '@/app/components/base/select' @@ -11,6 +11,9 @@ import TextGenerationImageUploader from '@/app/components/base/image-uploader/te import { Resolution } from '@/types/app' import { Trash03 } from '@/app/components/base/icons/src/vender/line/general' import { useFeatures } from '@/app/components/base/features/hooks' +import { VarBlockIcon } from '@/app/components/workflow/block-icon' +import { Line3 } from '@/app/components/base/icons/src/public/common' +import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' type Props = { payload: InputVar @@ -44,9 +47,35 @@ const FormItem: FC = ({ onChange(newValues) } }, [value, onChange]) + const nodeKey = (() => { + if (typeof payload.label === 'object') { + const { nodeType, nodeName, variable } = payload.label + return ( +
+
+
+ +
+
+ {nodeName} +
+ +
+ +
+ +
+ {variable} +
+
+
+ ) + } + return '' + })() return (
- {type !== InputVarType.contexts &&
{payload.label}
} + {type !== InputVarType.contexts &&
{typeof payload.label === 'object' ? nodeKey : payload.label}
}
{ type === InputVarType.textInput && ( diff --git a/web/app/components/workflow/nodes/llm/use-config.ts b/web/app/components/workflow/nodes/llm/use-config.ts index 2661c88508..928fe3efe5 100644 --- a/web/app/components/workflow/nodes/llm/use-config.ts +++ b/web/app/components/workflow/nodes/llm/use-config.ts @@ -282,11 +282,13 @@ const useConfig = (id: string, payload: LLMNodeType) => { const variables = uniqBy(valueSelectors, item => item.join('.')).map((item) => { const varInfo = getNodeInfoById(availableNodes, item[0])?.data - const variable = [...item] - variable[0] = varInfo?.title || availableNodes[0]?.data.title // default start node title return { - label: `${variable[0]}/${variable[variable.length - 1]}`, + label: { + nodeType: varInfo?.type, + nodeName: varInfo?.title || availableNodes[0]?.data.title, // default start node title + variable: item[item.length - 1], + }, variable: `#${item.join('.')}#`, value_selector: item, } diff --git a/web/app/components/workflow/types.ts b/web/app/components/workflow/types.ts index 75d405ff12..ff1e02be00 100644 --- a/web/app/components/workflow/types.ts +++ b/web/app/components/workflow/types.ts @@ -63,7 +63,11 @@ export type ValueSelector = string[] // [nodeId, key | obj key path] export type Variable = { variable: string - label?: string + label?: string | { + nodeType: BlockEnum + nodeName: string + variable: string + } value_selector: ValueSelector variable_type?: VarKindType value?: string @@ -90,7 +94,11 @@ export enum InputVarType { export type InputVar = { type: InputVarType - label: string + label: string | { + nodeType: BlockEnum + nodeName: string + variable: string + } variable: string max_length?: number default?: string