feat: output to vars

This commit is contained in:
Joel 2025-04-24 14:24:15 +08:00
parent bec7812e69
commit b0cc339c06
4 changed files with 74 additions and 13 deletions

View File

@ -33,6 +33,7 @@ import { ssePost } from '@/service/base'
import { noop } from 'lodash-es'
import { getInputVars as doGetInputVars } from '@/app/components/base/prompt-editor/constants'
import type { NodeRunResult, NodeTracing } from '@/types/workflow'
import { getNodeWithVar } from '../../../utils/debug'
const { checkValid: checkLLMValid } = LLMDefault
const { checkValid: checkKnowledgeRetrievalValid } = KnowledgeRetrievalDefault
const { checkValid: checkIfElseValid } = IfElseDefault
@ -156,15 +157,21 @@ const useOneStepRun = <T>({
const workflowStore = useWorkflowStore()
const {
setLastRunNodeInfo,
setNodeInspectVars: setCurrentNodeVars,
setNodeInspectVars,
setShowSingleRunPanel,
} = workflowStore.getState()
const [runResult, doSetRunResult] = useState<NodeRunResult | null>(null)
const nodeData = data
const setRunResult = useCallback((data: NodeRunResult | null) => {
doSetRunResult(data)
setLastRunNodeInfo(id, data as any)
setCurrentNodeVars(id, data as any)
}, [id, setLastRunNodeInfo, setCurrentNodeVars])
setLastRunNodeInfo(id, data!)
setNodeInspectVars(id, getNodeWithVar({
nodeId: id,
nodeType: nodeData.type,
title: nodeData.title,
values: data?.outputs || {},
}))
}, [nodeData, id, setLastRunNodeInfo, setNodeInspectVars])
const { handleNodeDataUpdate }: { handleNodeDataUpdate: (data: any) => void } = useNodeDataUpdate()
const [canShowSingleRun, setCanShowSingleRun] = useState(false)

View File

@ -1,18 +1,16 @@
import type { NodeTracing } from '@/types/workflow'
import produce from 'immer'
import type { StateCreator } from 'zustand'
type NodeInfo = NodeTracing
import type { NodeRunResult } from '@/types/workflow'
type LastRunState = {
nodes: NodeInfo[]
nodes: NodeRunResult[]
}
type LastRunActions = {
setLastRunInfos: (vars: NodeInfo[]) => void
getLastRunInfos: () => NodeInfo[]
setLastRunNodeInfo: (nodeId: string, payload: NodeInfo) => void
getLastRunNodeInfo: (nodeId: string) => NodeInfo | undefined
setLastRunInfos: (vars: NodeRunResult[]) => void
getLastRunInfos: () => NodeRunResult[]
setLastRunNodeInfo: (nodeId: string, payload: NodeRunResult) => void
getLastRunNodeInfo: (nodeId: string) => NodeRunResult | undefined
getLastRunVar: (nodeId: string, key: string) => any
}

View File

@ -0,0 +1,56 @@
import type { NodeWithVar, VarInInspect } from '@/types/workflow'
import { VarInInspectType } from '@/types/workflow'
import type { BlockEnum } from '../types'
import { VarType } from '../types'
type OutputToVarInInspectParams = {
nodeId: string
name: string
value: any
}
export const outputToVarInInspect = ({
nodeId,
name,
value,
}: OutputToVarInInspectParams): VarInInspect => {
return {
id: `${Date.now()}`, // TODO: wait for api
type: VarInInspectType.node,
name,
description: '',
selector: [nodeId, name],
value_type: VarType.string, // TODO: wait for api or get from node
value,
edited: false,
}
}
type NodeWithVarParams = {
nodeId: string
nodeType: BlockEnum
title: string
values: Record<string, any>
}
export const getNodeWithVar = ({
nodeId,
nodeType,
title,
values,
}: NodeWithVarParams): NodeWithVar => {
const res: NodeWithVar = {
nodeId,
nodeType,
title,
vars: [],
}
res.vars = Object.entries(values).map(([key, value]) => {
return outputToVarInInspect({
nodeId,
name: key,
value,
})
})
return res
}

View File

@ -379,7 +379,7 @@ export enum VarInInspectType {
}
export type VarInInspect = {
id?: string // value parse from output not has id
id: string
type: VarInInspectType
name: string
description: string