mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-06 05:38:54 +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 { noop } from 'lodash-es'
|
||||||
import { getInputVars as doGetInputVars } from '@/app/components/base/prompt-editor/constants'
|
import { getInputVars as doGetInputVars } from '@/app/components/base/prompt-editor/constants'
|
||||||
import type { NodeRunResult, NodeTracing } from '@/types/workflow'
|
import type { NodeRunResult, NodeTracing } from '@/types/workflow'
|
||||||
|
import { getNodeWithVar } from '../../../utils/debug'
|
||||||
const { checkValid: checkLLMValid } = LLMDefault
|
const { checkValid: checkLLMValid } = LLMDefault
|
||||||
const { checkValid: checkKnowledgeRetrievalValid } = KnowledgeRetrievalDefault
|
const { checkValid: checkKnowledgeRetrievalValid } = KnowledgeRetrievalDefault
|
||||||
const { checkValid: checkIfElseValid } = IfElseDefault
|
const { checkValid: checkIfElseValid } = IfElseDefault
|
||||||
@ -156,15 +157,21 @@ const useOneStepRun = <T>({
|
|||||||
const workflowStore = useWorkflowStore()
|
const workflowStore = useWorkflowStore()
|
||||||
const {
|
const {
|
||||||
setLastRunNodeInfo,
|
setLastRunNodeInfo,
|
||||||
setNodeInspectVars: setCurrentNodeVars,
|
setNodeInspectVars,
|
||||||
setShowSingleRunPanel,
|
setShowSingleRunPanel,
|
||||||
} = workflowStore.getState()
|
} = workflowStore.getState()
|
||||||
const [runResult, doSetRunResult] = useState<NodeRunResult | null>(null)
|
const [runResult, doSetRunResult] = useState<NodeRunResult | null>(null)
|
||||||
|
const nodeData = data
|
||||||
const setRunResult = useCallback((data: NodeRunResult | null) => {
|
const setRunResult = useCallback((data: NodeRunResult | null) => {
|
||||||
doSetRunResult(data)
|
doSetRunResult(data)
|
||||||
setLastRunNodeInfo(id, data as any)
|
setLastRunNodeInfo(id, data!)
|
||||||
setCurrentNodeVars(id, data as any)
|
setNodeInspectVars(id, getNodeWithVar({
|
||||||
}, [id, setLastRunNodeInfo, setCurrentNodeVars])
|
nodeId: id,
|
||||||
|
nodeType: nodeData.type,
|
||||||
|
title: nodeData.title,
|
||||||
|
values: data?.outputs || {},
|
||||||
|
}))
|
||||||
|
}, [nodeData, id, setLastRunNodeInfo, setNodeInspectVars])
|
||||||
|
|
||||||
const { handleNodeDataUpdate }: { handleNodeDataUpdate: (data: any) => void } = useNodeDataUpdate()
|
const { handleNodeDataUpdate }: { handleNodeDataUpdate: (data: any) => void } = useNodeDataUpdate()
|
||||||
const [canShowSingleRun, setCanShowSingleRun] = useState(false)
|
const [canShowSingleRun, setCanShowSingleRun] = useState(false)
|
||||||
|
@ -1,18 +1,16 @@
|
|||||||
import type { NodeTracing } from '@/types/workflow'
|
|
||||||
import produce from 'immer'
|
import produce from 'immer'
|
||||||
import type { StateCreator } from 'zustand'
|
import type { StateCreator } from 'zustand'
|
||||||
|
import type { NodeRunResult } from '@/types/workflow'
|
||||||
type NodeInfo = NodeTracing
|
|
||||||
|
|
||||||
type LastRunState = {
|
type LastRunState = {
|
||||||
nodes: NodeInfo[]
|
nodes: NodeRunResult[]
|
||||||
}
|
}
|
||||||
|
|
||||||
type LastRunActions = {
|
type LastRunActions = {
|
||||||
setLastRunInfos: (vars: NodeInfo[]) => void
|
setLastRunInfos: (vars: NodeRunResult[]) => void
|
||||||
getLastRunInfos: () => NodeInfo[]
|
getLastRunInfos: () => NodeRunResult[]
|
||||||
setLastRunNodeInfo: (nodeId: string, payload: NodeInfo) => void
|
setLastRunNodeInfo: (nodeId: string, payload: NodeRunResult) => void
|
||||||
getLastRunNodeInfo: (nodeId: string) => NodeInfo | undefined
|
getLastRunNodeInfo: (nodeId: string) => NodeRunResult | undefined
|
||||||
getLastRunVar: (nodeId: string, key: string) => any
|
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 = {
|
export type VarInInspect = {
|
||||||
id?: string // value parse from output not has id
|
id: string
|
||||||
type: VarInInspectType
|
type: VarInInspectType
|
||||||
name: string
|
name: string
|
||||||
description: string
|
description: string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user