This commit is contained in:
@@ -10,20 +10,14 @@ 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
|
||||
@@ -92,17 +86,7 @@ export const getNodesConnectedSourceOrTargetHandleIdsMap = (changes: ConnectedSo
|
||||
return nodesConnectedSourceOrTargetHandleIdsMap
|
||||
}
|
||||
|
||||
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) => {
|
||||
export const getValidTreeNodes = (nodes: Node[], edges: Edge[]) => {
|
||||
const startNode = nodes.find(node => node.data.type === BlockEnum.Start)
|
||||
|
||||
if (!startNode) {
|
||||
@@ -125,19 +109,6 @@ export const getValidTreeNodes = (nodes: Node[], edges: Edge[], isCollectVar?: b
|
||||
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)
|
||||
@@ -356,48 +327,3 @@ 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
|
||||
}
|
||||
|
Reference in New Issue
Block a user