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