fix:#18447:When variables in the workflow are deleted or modified, it is impossible to visually identify subsequent node errors (#18554)

Co-authored-by: crazywoola <427733928@qq.com>
This commit is contained in:
董富宝
2025-05-14 10:17:15 +08:00
committed by GitHub
parent 9e795374bc
commit 3c953cb0ef
26 changed files with 522 additions and 21 deletions

View File

@@ -10,14 +10,20 @@ import {
uniqBy,
} from 'lodash-es'
import type {
ConversationVariable,
Edge,
EnvironmentVariable,
Node,
Var,
} from '../types'
import {
BlockEnum,
} from '../types'
import type { IterationNodeType } from '../nodes/iteration/types'
import type { LoopNodeType } from '../nodes/loop/types'
import { VAR_REGEX_TEXT } from '@/config'
import { formatItem } from '../nodes/_base/components/variable/utils'
import type { StructuredOutput } from '../nodes/llm/types'
export const canRunBySingle = (nodeType: BlockEnum) => {
return nodeType === BlockEnum.LLM
@@ -86,7 +92,17 @@ export const getNodesConnectedSourceOrTargetHandleIdsMap = (changes: ConnectedSo
return nodesConnectedSourceOrTargetHandleIdsMap
}
export const getValidTreeNodes = (nodes: Node[], edges: Edge[]) => {
function getParentOutputVarMap(item: Var, path: string, varMap: Record<string, Var>) {
if (!item.children || (Array.isArray(item.children) && !item.children.length) || ((item.children as StructuredOutput).schema))
return
(item.children as Var[]).forEach((child) => {
const newPath = `${path}.${child.variable}`
varMap[newPath] = child
getParentOutputVarMap(child, newPath, varMap)
})
}
export const getValidTreeNodes = (nodes: Node[], edges: Edge[], isCollectVar?: boolean) => {
const startNode = nodes.find(node => node.data.type === BlockEnum.Start)
if (!startNode) {
@@ -109,6 +125,19 @@ export const getValidTreeNodes = (nodes: Node[], edges: Edge[]) => {
outgoers.forEach((outgoer) => {
list.push(outgoer)
if (isCollectVar) {
const nodeObj = formatItem(root, false, () => true)
const varMap = {} as Record<string, Var>
nodeObj.vars.forEach((item) => {
if (item.variable.startsWith('sys.'))
return
const newPath = `${nodeObj.nodeId}.${item.variable}`
varMap[newPath] = item
getParentOutputVarMap(item, newPath, varMap)
})
outgoer._parentOutputVarMap = { ...(root._parentOutputVarMap ?? {}), ...varMap }
}
if (outgoer.data.type === BlockEnum.Iteration)
list.push(...nodes.filter(node => node.parentId === outgoer.id))
if (outgoer.data.type === BlockEnum.Loop)
@@ -327,3 +356,48 @@ export const getParallelInfo = (nodes: Node[], edges: Edge[], parentNodeId?: str
export const hasErrorHandleNode = (nodeType?: BlockEnum) => {
return nodeType === BlockEnum.LLM || nodeType === BlockEnum.Tool || nodeType === BlockEnum.HttpRequest || nodeType === BlockEnum.Code
}
export const transformStartNodeVariables = (chatVarList: ConversationVariable[], environmentVariables: EnvironmentVariable[]) => {
const variablesMap: Record<string, ConversationVariable | EnvironmentVariable> = {}
chatVarList.forEach((variable) => {
variablesMap[`conversation.${variable.name}`] = variable
})
environmentVariables.forEach((variable) => {
variablesMap[`env.${variable.name}`] = variable
})
return variablesMap
}
export const getNotExistVariablesByText = (text: string, varMap: Record<string, Var>) => {
const var_warnings: string[] = []
text?.replace(VAR_REGEX_TEXT, (str, id_name) => {
if (id_name.startsWith('sys.'))
return str
if (varMap[id_name])
return str
const arr = id_name.split('.')
arr.shift()
var_warnings.push(arr.join('.'))
return str
})
return var_warnings
}
export const getNotExistVariablesByArray = (array: string[][], varMap: Record<string, Var>) => {
if (!array.length)
return []
const var_warnings: string[] = []
array.forEach((item) => {
if (!item.length)
return
if (['sys'].includes(item[0]))
return
const var_warning = varMap[item.join('.')]
if (var_warning)
return
const arr = [...item]
arr.shift()
var_warnings.push(arr.join('.'))
})
return var_warnings
}