Commit 9bca3f8f authored by Joel's avatar Joel

feat: code support output var list

parent 0d2366b4
......@@ -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<Props> = ({
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)
}
......
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
......
......@@ -95,7 +95,7 @@ const VarReferencePicker: FC<Props> = ({
<Variable02 className='w-3.5 h-3.5' />
<div className='ml-0.5 text-xs font-medium'>{varName}</div>
</div>
<div className='ml-0.5 text-xs font-normal text-gray-500'>{getVarType()}</div>
<div className='ml-0.5 text-xs font-normal text-gray-500 capitalize'>{getVarType()}</div>
</>
)}
</div>
......
......@@ -30,7 +30,7 @@ const Item: FC<ItemProps> = ({
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<ObjectChildrenProps> = ({
<div className='absolute right-[248px] top-[-2px] bg-white rounded-lg border border-gray-200 shadow-lg space-y-1'>
<div className='flex items-center h-[22px] px-3 text-xs font-normal text-gray-700'><span className='text-gray-500'>{title}.</span>{currObjPath.join('.')}</div>
{
data.map((v, i) => (
data?.map((v, i) => (
<Item
key={i}
nodeId={nodeId}
......
......@@ -9,6 +9,7 @@ import {
} from '@/app/components/base/portal-to-follow-elem'
import { Check } from '@/app/components/base/icons/src/vender/line/general'
import { ChevronDown } from '@/app/components/base/icons/src/vender/line/arrows'
import { VarType } from '@/app/components/workflow/types'
type Props = {
className?: string
......@@ -17,7 +18,7 @@ type Props = {
onChange: (value: string) => void
}
const TYPES = ['string', 'number']
const TYPES = [VarType.string, VarType.number, VarType.arrayNumber, VarType.arrayString, VarType.object]
const VarReferencePicker: FC<Props> = ({
readonly,
className,
......
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<T> = {
inputs: T
setInputs: (newInputs: T) => void
......@@ -23,7 +25,7 @@ function useOutputVarList<T>({
draft[varKey] = {
...draft[varKey],
[`var-${Object.keys(draft[varKey]).length + 1}`]: {
type: OutputVarType.string,
type: VarType.string,
children: null,
},
}
......
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<string, {
type: OutputVarType
type: VarType
children: null // support nest in the future,
}>
......
......@@ -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 = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment