Commit 9bca3f8f authored by Joel's avatar Joel

feat: code support output var list

parent 0d2366b4
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
import type { FC } from 'react' import type { FC } from 'react'
import React, { useCallback } from 'react' import React, { useCallback } from 'react'
import produce from 'immer' import produce from 'immer'
import type { OutputVar, OutputVarType } from '../../../code/types' import type { OutputVar } from '../../../code/types'
import RemoveButton from '../remove-button' import RemoveButton from '../remove-button'
import VarTypePicker from './var-type-picker' import VarTypePicker from './var-type-picker'
import type { VarType } from '@/app/components/workflow/types'
type Props = { type Props = {
readonly: boolean readonly: boolean
...@@ -39,7 +40,7 @@ const OutputVarList: FC<Props> = ({ ...@@ -39,7 +40,7 @@ const OutputVarList: FC<Props> = ({
return (value: string) => { return (value: string) => {
const key = list[index].variable const key = list[index].variable
const newOutputs = produce(outputs, (draft) => { const newOutputs = produce(outputs, (draft) => {
draft[key].type = value as OutputVarType draft[key].type = value as VarType
}) })
onChange(newOutputs) onChange(newOutputs)
} }
......
import type { CodeNodeType } from '../../../code/types'
import { BlockEnum, InputVarType, VarType } from '@/app/components/workflow/types' import { BlockEnum, InputVarType, VarType } from '@/app/components/workflow/types'
import type { StartNodeType } from '@/app/components/workflow/nodes/start/types' import type { StartNodeType } from '@/app/components/workflow/nodes/start/types'
import type { NodeOutPutVar } from '@/app/components/workflow/types' import type { NodeOutPutVar } from '@/app/components/workflow/types'
...@@ -40,6 +41,19 @@ const formatItem = (item: any): NodeOutPutVar => { ...@@ -40,6 +41,19 @@ const formatItem = (item: any): NodeOutPutVar => {
res.vars = KNOWLEDGE_RETRIEVAL_OUTPUT_STRUCT res.vars = KNOWLEDGE_RETRIEVAL_OUTPUT_STRUCT
break 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 return res
......
...@@ -95,7 +95,7 @@ const VarReferencePicker: FC<Props> = ({ ...@@ -95,7 +95,7 @@ const VarReferencePicker: FC<Props> = ({
<Variable02 className='w-3.5 h-3.5' /> <Variable02 className='w-3.5 h-3.5' />
<div className='ml-0.5 text-xs font-medium'>{varName}</div> <div className='ml-0.5 text-xs font-medium'>{varName}</div>
</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> </div>
......
...@@ -30,7 +30,7 @@ const Item: FC<ItemProps> = ({ ...@@ -30,7 +30,7 @@ const Item: FC<ItemProps> = ({
itemData, itemData,
onChange, onChange,
}) => { }) => {
const isObj = itemData.type === VarType.object const isObj = itemData.type === VarType.object && itemData.children && itemData.children.length > 0
const itemRef = useRef(null) const itemRef = useRef(null)
const isItemHovering = useHover(itemRef) const isItemHovering = useHover(itemRef)
const handleChosen = (e: React.MouseEvent) => { const handleChosen = (e: React.MouseEvent) => {
...@@ -78,7 +78,7 @@ const ObjectChildren: FC<ObjectChildrenProps> = ({ ...@@ -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='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> <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 <Item
key={i} key={i}
nodeId={nodeId} nodeId={nodeId}
......
...@@ -9,6 +9,7 @@ import { ...@@ -9,6 +9,7 @@ import {
} from '@/app/components/base/portal-to-follow-elem' } from '@/app/components/base/portal-to-follow-elem'
import { Check } from '@/app/components/base/icons/src/vender/line/general' import { Check } from '@/app/components/base/icons/src/vender/line/general'
import { ChevronDown } from '@/app/components/base/icons/src/vender/line/arrows' import { ChevronDown } from '@/app/components/base/icons/src/vender/line/arrows'
import { VarType } from '@/app/components/workflow/types'
type Props = { type Props = {
className?: string className?: string
...@@ -17,7 +18,7 @@ type Props = { ...@@ -17,7 +18,7 @@ type Props = {
onChange: (value: string) => void onChange: (value: string) => void
} }
const TYPES = ['string', 'number'] const TYPES = [VarType.string, VarType.number, VarType.arrayNumber, VarType.arrayString, VarType.object]
const VarReferencePicker: FC<Props> = ({ const VarReferencePicker: FC<Props> = ({
readonly, readonly,
className, className,
......
import { useCallback } from 'react' import { useCallback } from 'react'
import produce from 'immer' 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> = { type Params<T> = {
inputs: T inputs: T
setInputs: (newInputs: T) => void setInputs: (newInputs: T) => void
...@@ -23,7 +25,7 @@ function useOutputVarList<T>({ ...@@ -23,7 +25,7 @@ function useOutputVarList<T>({
draft[varKey] = { draft[varKey] = {
...draft[varKey], ...draft[varKey],
[`var-${Object.keys(draft[varKey]).length + 1}`]: { [`var-${Object.keys(draft[varKey]).length + 1}`]: {
type: OutputVarType.string, type: VarType.string,
children: null, children: null,
}, },
} }
......
import type { CommonNodeType, Variable } from '@/app/components/workflow/types' import type { CommonNodeType, VarType, Variable } from '@/app/components/workflow/types'
export enum CodeLanguage { export enum CodeLanguage {
python3 = 'python3', python3 = 'python3',
...@@ -6,15 +6,8 @@ export enum CodeLanguage { ...@@ -6,15 +6,8 @@ export enum CodeLanguage {
json = 'json', json = 'json',
} }
export enum OutputVarType {
string = 'string',
number = 'number',
boolean = 'boolean',
object = 'object',
}
export type OutputVar = Record<string, { export type OutputVar = Record<string, {
type: OutputVarType type: VarType
children: null // support nest in the future, children: null // support nest in the future,
}> }>
......
...@@ -119,14 +119,14 @@ export type Memory = { ...@@ -119,14 +119,14 @@ export type Memory = {
} }
export enum VarType { export enum VarType {
string = 'String', string = 'string',
number = 'Number', number = 'number',
boolean = 'Boolean', boolean = 'boolean',
object = 'Object', object = 'object',
array = 'Array', array = 'array',
arrayString = 'Array[string]', arrayString = 'array[string]',
arrayNumber = 'Array[number]', arrayNumber = 'array[number]',
arrayObject = 'Array[object]', arrayObject = 'array[object]',
} }
export type Var = { 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