diff --git a/web/app/components/workflow/nodes/_base/components/variable/output-var-list.tsx b/web/app/components/workflow/nodes/_base/components/variable/output-var-list.tsx index 09437be694..6dc3b4e42a 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/output-var-list.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/output-var-list.tsx @@ -2,9 +2,10 @@ import type { FC } from 'react' import React, { useCallback } from 'react' import produce from 'immer' -import type { OutputVar, OutputVarType } from '../../../code/types' +import type { OutputVar } from '../../../code/types' import RemoveButton from '../remove-button' import VarTypePicker from './var-type-picker' +import type { VarType } from '@/app/components/workflow/types' type Props = { readonly: boolean @@ -39,7 +40,7 @@ const OutputVarList: FC = ({ return (value: string) => { const key = list[index].variable const newOutputs = produce(outputs, (draft) => { - draft[key].type = value as OutputVarType + draft[key].type = value as VarType }) onChange(newOutputs) } diff --git a/web/app/components/workflow/nodes/_base/components/variable/utils.ts b/web/app/components/workflow/nodes/_base/components/variable/utils.ts index 24be9ec027..ec827ce62f 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/utils.ts +++ b/web/app/components/workflow/nodes/_base/components/variable/utils.ts @@ -1,3 +1,4 @@ +import type { CodeNodeType } from '../../../code/types' import { BlockEnum, InputVarType, VarType } from '@/app/components/workflow/types' import type { StartNodeType } from '@/app/components/workflow/nodes/start/types' import type { NodeOutPutVar } from '@/app/components/workflow/types' @@ -40,6 +41,19 @@ const formatItem = (item: any): NodeOutPutVar => { res.vars = KNOWLEDGE_RETRIEVAL_OUTPUT_STRUCT break } + + case BlockEnum.Code: { + const { + outputs, + } = data as CodeNodeType + res.vars = Object.keys(outputs).map((key) => { + return { + variable: key, + type: outputs[key].type, + } + }) + break + } } return res diff --git a/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx b/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx index ec7f8a3945..d0b3030f0e 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx @@ -95,7 +95,7 @@ const VarReferencePicker: FC = ({
{varName}
-
{getVarType()}
+
{getVarType()}
)} diff --git a/web/app/components/workflow/nodes/_base/components/variable/var-reference-popup.tsx b/web/app/components/workflow/nodes/_base/components/variable/var-reference-popup.tsx index d698822fbe..cb788e31c2 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/var-reference-popup.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/var-reference-popup.tsx @@ -30,7 +30,7 @@ const Item: FC = ({ itemData, onChange, }) => { - const isObj = itemData.type === VarType.object + const isObj = itemData.type === VarType.object && itemData.children && itemData.children.length > 0 const itemRef = useRef(null) const isItemHovering = useHover(itemRef) const handleChosen = (e: React.MouseEvent) => { @@ -78,7 +78,7 @@ const ObjectChildren: FC = ({
{title}.{currObjPath.join('.')}
{ - data.map((v, i) => ( + data?.map((v, i) => ( void } -const TYPES = ['string', 'number'] +const TYPES = [VarType.string, VarType.number, VarType.arrayNumber, VarType.arrayString, VarType.object] const VarReferencePicker: FC = ({ readonly, className, diff --git a/web/app/components/workflow/nodes/_base/hooks/use-output-var-list.ts b/web/app/components/workflow/nodes/_base/hooks/use-output-var-list.ts index b21b0b7b1f..29136fae39 100644 --- a/web/app/components/workflow/nodes/_base/hooks/use-output-var-list.ts +++ b/web/app/components/workflow/nodes/_base/hooks/use-output-var-list.ts @@ -1,6 +1,8 @@ import { useCallback } from 'react' import produce from 'immer' -import { type OutputVar, OutputVarType } from '../../code/types' +import { type OutputVar } from '../../code/types' +import { VarType } from '@/app/components/workflow/types' + type Params = { inputs: T setInputs: (newInputs: T) => void @@ -23,7 +25,7 @@ function useOutputVarList({ draft[varKey] = { ...draft[varKey], [`var-${Object.keys(draft[varKey]).length + 1}`]: { - type: OutputVarType.string, + type: VarType.string, children: null, }, } diff --git a/web/app/components/workflow/nodes/code/types.ts b/web/app/components/workflow/nodes/code/types.ts index f7953f61d5..9c055f3969 100644 --- a/web/app/components/workflow/nodes/code/types.ts +++ b/web/app/components/workflow/nodes/code/types.ts @@ -1,4 +1,4 @@ -import type { CommonNodeType, Variable } from '@/app/components/workflow/types' +import type { CommonNodeType, VarType, Variable } from '@/app/components/workflow/types' export enum CodeLanguage { python3 = 'python3', @@ -6,15 +6,8 @@ export enum CodeLanguage { json = 'json', } -export enum OutputVarType { - string = 'string', - number = 'number', - boolean = 'boolean', - object = 'object', -} - export type OutputVar = Record diff --git a/web/app/components/workflow/types.ts b/web/app/components/workflow/types.ts index 0ae12c48c8..634f023c2c 100644 --- a/web/app/components/workflow/types.ts +++ b/web/app/components/workflow/types.ts @@ -119,14 +119,14 @@ export type Memory = { } export enum VarType { - string = 'String', - number = 'Number', - boolean = 'Boolean', - object = 'Object', - array = 'Array', - arrayString = 'Array[string]', - arrayNumber = 'Array[number]', - arrayObject = 'Array[object]', + string = 'string', + number = 'number', + boolean = 'boolean', + object = 'object', + array = 'array', + arrayString = 'array[string]', + arrayNumber = 'array[number]', + arrayObject = 'array[object]', } export type Var = {