mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-05 20:56:10 +08:00
feat: output to vars
This commit is contained in:
parent
bec7812e69
commit
b0cc339c06
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
56
web/app/components/workflow/utils/debug.ts
Normal file
56
web/app/components/workflow/utils/debug.ts
Normal 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
|
||||
}
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user