mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-04 17:30:41 +08:00
chore: fix ts an give an exlicter name
This commit is contained in:
parent
8cd8da99d6
commit
bec7812e69
@ -2,7 +2,7 @@ import { useWorkflowStore } from '../store'
|
|||||||
const useCurrentVars = () => {
|
const useCurrentVars = () => {
|
||||||
const workflowStore = useWorkflowStore()
|
const workflowStore = useWorkflowStore()
|
||||||
const {
|
const {
|
||||||
nodes: currentNodes,
|
nodesWithInspectVars: currentNodes,
|
||||||
getInspectVar: getCurrentVar,
|
getInspectVar: getCurrentVar,
|
||||||
setInspectVar: setCurrentVar,
|
setInspectVar: setCurrentVar,
|
||||||
clearInspectVars: clearCurrentVars,
|
clearInspectVars: clearCurrentVars,
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
import type { StateCreator } from 'zustand'
|
import type { StateCreator } from 'zustand'
|
||||||
import produce from 'immer'
|
import produce from 'immer'
|
||||||
import type { NodeWithVar, VarInInspect } from '@/types/workflow'
|
import type { NodeWithVar, VarInInspect } from '@/types/workflow'
|
||||||
import type { ValueSelector } from '../../types'
|
import type { ValueSelector } from '../../../types'
|
||||||
|
|
||||||
type InspectVarsState = {
|
type InspectVarsState = {
|
||||||
currentFocusNodeId: string | null
|
currentFocusNodeId: string | null
|
||||||
nodes: NodeWithVar[] // the nodes have data
|
nodesWithInspectVars: NodeWithVar[] // the nodes have data
|
||||||
conversationVars: VarInInspect[]
|
conversationVars: VarInInspect[]
|
||||||
}
|
}
|
||||||
|
|
||||||
type InspectVarsActions = {
|
type InspectVarsActions = {
|
||||||
|
setCurrentFocusNodeId: (nodeId: string | null) => void
|
||||||
getAllInspectVars: () => NodeWithVar[]
|
getAllInspectVars: () => NodeWithVar[]
|
||||||
clearInspectVars: () => void
|
clearInspectVars: () => void
|
||||||
setNodeInspectVars: (nodeId: string, payload: NodeWithVar) => void
|
setNodeInspectVars: (nodeId: string, payload: NodeWithVar) => void
|
||||||
@ -20,24 +21,29 @@ type InspectVarsActions = {
|
|||||||
getInspectVar: (nodeId: string, selector: ValueSelector) => any
|
getInspectVar: (nodeId: string, selector: ValueSelector) => any
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CurrentVarsSliceShape = InspectVarsState & InspectVarsActions
|
export type InspectVarsSliceShape = InspectVarsState & InspectVarsActions
|
||||||
|
|
||||||
export const createInspectVarsSlice: StateCreator<CurrentVarsSliceShape> = (set, get) => {
|
export const createInspectVarsSlice: StateCreator<InspectVarsSliceShape> = (set, get) => {
|
||||||
return ({
|
return ({
|
||||||
currentFocusNodeId: null,
|
currentFocusNodeId: null,
|
||||||
nodes: [],
|
nodesWithInspectVars: [],
|
||||||
conversationVars: [],
|
conversationVars: [],
|
||||||
|
setCurrentFocusNodeId: (nodeId) => {
|
||||||
|
set(() => ({
|
||||||
|
currentFocusNodeId: nodeId,
|
||||||
|
}))
|
||||||
|
},
|
||||||
getAllInspectVars: () => {
|
getAllInspectVars: () => {
|
||||||
return get().nodes
|
return get().nodesWithInspectVars
|
||||||
},
|
},
|
||||||
clearInspectVars: () => {
|
clearInspectVars: () => {
|
||||||
set(() => ({
|
set(() => ({
|
||||||
nodes: [],
|
nodesWithInspectVars: [],
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
setNodeInspectVars: (nodeId, payload) => {
|
setNodeInspectVars: (nodeId, payload) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
const prevNodes = state.nodes
|
const prevNodes = state.nodesWithInspectVars
|
||||||
const nodes = produce(prevNodes, (draft) => {
|
const nodes = produce(prevNodes, (draft) => {
|
||||||
const index = prevNodes.findIndex(node => node.nodeId === nodeId)
|
const index = prevNodes.findIndex(node => node.nodeId === nodeId)
|
||||||
if (index === -1)
|
if (index === -1)
|
||||||
@ -47,27 +53,27 @@ export const createInspectVarsSlice: StateCreator<CurrentVarsSliceShape> = (set,
|
|||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
nodes,
|
nodesWithInspectVars: nodes,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
clearNodeInspectVars: (nodeId) => {
|
clearNodeInspectVars: (nodeId) => {
|
||||||
set(produce((state: CurrentVarsSliceShape) => {
|
set(produce((state: InspectVarsSliceShape) => {
|
||||||
const nodes = state.nodes.filter(node => node.nodeId !== nodeId)
|
const nodes = state.nodesWithInspectVars.filter(node => node.nodeId !== nodeId)
|
||||||
state.nodes = nodes
|
state.nodesWithInspectVars = nodes
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
getNodeInspectVars: (nodeId) => {
|
getNodeInspectVars: (nodeId) => {
|
||||||
const nodes = get().nodes
|
const nodes = get().nodesWithInspectVars
|
||||||
return nodes.find(node => node.nodeId === nodeId)
|
return nodes.find(node => node.nodeId === nodeId)
|
||||||
},
|
},
|
||||||
hasNodeInspectVars: (nodeId) => {
|
hasNodeInspectVars: (nodeId) => {
|
||||||
return !!get().getNodeInspectVars(nodeId)
|
return !!get().getNodeInspectVars(nodeId)
|
||||||
},
|
},
|
||||||
setInspectVar: (nodeId, selector, value) => {
|
setInspectVar: (nodeId, selector, value) => {
|
||||||
set(produce((state: CurrentVarsSliceShape) => {
|
set(produce((state: InspectVarsSliceShape) => {
|
||||||
const nodes = state.nodes.map((node) => {
|
const nodes = state.nodesWithInspectVars.map((node) => {
|
||||||
if (node.nodeId === nodeId) {
|
if (node.nodeId === nodeId) {
|
||||||
return produce(node, (draft) => {
|
return produce(node, (draft) => {
|
||||||
const needChangeVarIndex = draft.vars.findIndex((varItem) => {
|
const needChangeVarIndex = draft.vars.findIndex((varItem) => {
|
||||||
@ -79,7 +85,7 @@ export const createInspectVarsSlice: StateCreator<CurrentVarsSliceShape> = (set,
|
|||||||
}
|
}
|
||||||
return node
|
return node
|
||||||
})
|
})
|
||||||
state.nodes = nodes
|
state.nodesWithInspectVars = nodes
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
getInspectVar(nodeId, key) {
|
getInspectVar(nodeId, key) {
|
@ -28,10 +28,10 @@ import type { WorkflowDraftSliceShape } from './workflow-draft-slice'
|
|||||||
import { createWorkflowDraftSlice } from './workflow-draft-slice'
|
import { createWorkflowDraftSlice } from './workflow-draft-slice'
|
||||||
import type { WorkflowSliceShape } from './workflow-slice'
|
import type { WorkflowSliceShape } from './workflow-slice'
|
||||||
import { createWorkflowSlice } from './workflow-slice'
|
import { createWorkflowSlice } from './workflow-slice'
|
||||||
import type { LastRunSliceShape } from './last-run-slice'
|
import type { LastRunSliceShape } from './debug/last-run-slice'
|
||||||
import { createLastRunSlice } from './last-run-slice'
|
import { createLastRunSlice } from './debug/last-run-slice'
|
||||||
import type { CurrentVarsSliceShape } from './var-inspect-slice'
|
import type { InspectVarsSliceShape } from './debug/inspect-vars-slice'
|
||||||
import { createInspectVarsSlice } from './var-inspect-slice'
|
import { createInspectVarsSlice } from './debug/inspect-vars-slice'
|
||||||
|
|
||||||
import { WorkflowContext } from '@/app/components/workflow/context'
|
import { WorkflowContext } from '@/app/components/workflow/context'
|
||||||
import type { LayoutSliceShape } from './layout-slice'
|
import type { LayoutSliceShape } from './layout-slice'
|
||||||
@ -51,7 +51,7 @@ export type Shape =
|
|||||||
WorkflowDraftSliceShape &
|
WorkflowDraftSliceShape &
|
||||||
WorkflowSliceShape &
|
WorkflowSliceShape &
|
||||||
LastRunSliceShape &
|
LastRunSliceShape &
|
||||||
CurrentVarsSliceShape &
|
InspectVarsSliceShape &
|
||||||
LayoutSliceShape &
|
LayoutSliceShape &
|
||||||
WorkflowAppSliceShape
|
WorkflowAppSliceShape
|
||||||
|
|
||||||
|
@ -379,11 +379,11 @@ export enum VarInInspectType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type VarInInspect = {
|
export type VarInInspect = {
|
||||||
id: string
|
id?: string // value parse from output not has id
|
||||||
type: VarInInspectType
|
type: VarInInspectType
|
||||||
name: string
|
name: string
|
||||||
description: string
|
description: string
|
||||||
selector: ValueSelector
|
selector: ValueSelector // can get node id from selector[0]
|
||||||
value_type: VarType
|
value_type: VarType
|
||||||
value: any
|
value: any
|
||||||
edited: boolean
|
edited: boolean
|
||||||
|
Loading…
x
Reference in New Issue
Block a user