Add $flow to Variable Resolution in Flow Building Process (#3075)
* Add $flow to Variable Resolution in Flow Building Process * add overrideConfig values to $flow.... * fix for replacement of $flow values inside text. * refactor and compatibilize with agent flow
This commit is contained in:
parent
58d995a4f3
commit
455fb144a3
|
|
@ -337,13 +337,21 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
|
||||||
nodeToExecute.data = replaceInputsWithConfig(nodeToExecute.data, incomingInput.overrideConfig)
|
nodeToExecute.data = replaceInputsWithConfig(nodeToExecute.data, incomingInput.overrideConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const flowData: ICommonObject = {
|
||||||
|
chatflowid,
|
||||||
|
chatId,
|
||||||
|
sessionId,
|
||||||
|
chatHistory,
|
||||||
|
...incomingInput.overrideConfig
|
||||||
|
}
|
||||||
|
|
||||||
const reactFlowNodeData: INodeData = await resolveVariables(
|
const reactFlowNodeData: INodeData = await resolveVariables(
|
||||||
appServer.AppDataSource,
|
appServer.AppDataSource,
|
||||||
nodeToExecute.data,
|
nodeToExecute.data,
|
||||||
reactFlowNodes,
|
reactFlowNodes,
|
||||||
incomingInput.question,
|
incomingInput.question,
|
||||||
chatHistory,
|
chatHistory,
|
||||||
incomingInput.overrideConfig
|
flowData
|
||||||
)
|
)
|
||||||
nodeToExecuteData = reactFlowNodeData
|
nodeToExecuteData = reactFlowNodeData
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -486,6 +486,14 @@ export const buildFlow = async ({
|
||||||
|
|
||||||
const initializedNodes: Set<string> = new Set()
|
const initializedNodes: Set<string> = new Set()
|
||||||
const reversedGraph = constructGraphs(reactFlowNodes, reactFlowEdges, { isReversed: true }).graph
|
const reversedGraph = constructGraphs(reactFlowNodes, reactFlowEdges, { isReversed: true }).graph
|
||||||
|
|
||||||
|
const flowData: ICommonObject = {
|
||||||
|
chatflowid,
|
||||||
|
chatId,
|
||||||
|
sessionId,
|
||||||
|
chatHistory,
|
||||||
|
...overrideConfig
|
||||||
|
}
|
||||||
while (nodeQueue.length) {
|
while (nodeQueue.length) {
|
||||||
const { nodeId, depth } = nodeQueue.shift() as INodeQueue
|
const { nodeId, depth } = nodeQueue.shift() as INodeQueue
|
||||||
|
|
||||||
|
|
@ -509,7 +517,7 @@ export const buildFlow = async ({
|
||||||
flowNodes,
|
flowNodes,
|
||||||
question,
|
question,
|
||||||
chatHistory,
|
chatHistory,
|
||||||
overrideConfig
|
flowData
|
||||||
)
|
)
|
||||||
|
|
||||||
if (isUpsert && stopNodeId && nodeId === stopNodeId) {
|
if (isUpsert && stopNodeId && nodeId === stopNodeId) {
|
||||||
|
|
@ -760,7 +768,7 @@ export const getVariableValue = async (
|
||||||
question: string,
|
question: string,
|
||||||
chatHistory: IMessage[],
|
chatHistory: IMessage[],
|
||||||
isAcceptVariable = false,
|
isAcceptVariable = false,
|
||||||
overrideConfig?: ICommonObject
|
flowData?: ICommonObject
|
||||||
) => {
|
) => {
|
||||||
const isObject = typeof paramValue === 'object'
|
const isObject = typeof paramValue === 'object'
|
||||||
let returnVal = (isObject ? JSON.stringify(paramValue) : paramValue) ?? ''
|
let returnVal = (isObject ? JSON.stringify(paramValue) : paramValue) ?? ''
|
||||||
|
|
@ -797,7 +805,7 @@ export const getVariableValue = async (
|
||||||
}
|
}
|
||||||
|
|
||||||
if (variableFullPath.startsWith('$vars.')) {
|
if (variableFullPath.startsWith('$vars.')) {
|
||||||
const vars = await getGlobalVariable(appDataSource, overrideConfig)
|
const vars = await getGlobalVariable(appDataSource, flowData)
|
||||||
const variableValue = get(vars, variableFullPath.replace('$vars.', ''))
|
const variableValue = get(vars, variableFullPath.replace('$vars.', ''))
|
||||||
if (variableValue) {
|
if (variableValue) {
|
||||||
variableDict[`{{${variableFullPath}}}`] = variableValue
|
variableDict[`{{${variableFullPath}}}`] = variableValue
|
||||||
|
|
@ -805,6 +813,14 @@ export const getVariableValue = async (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (variableFullPath.startsWith('$flow.') && flowData) {
|
||||||
|
const variableValue = get(flowData, variableFullPath.replace('$flow.', ''))
|
||||||
|
if (variableValue) {
|
||||||
|
variableDict[`{{${variableFullPath}}}`] = variableValue
|
||||||
|
returnVal = returnVal.split(`{{${variableFullPath}}}`).join(variableValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Resolve values with following case.
|
// Resolve values with following case.
|
||||||
// 1: <variableNodeId>.data.instance
|
// 1: <variableNodeId>.data.instance
|
||||||
// 2: <variableNodeId>.data.instance.pathtokey
|
// 2: <variableNodeId>.data.instance.pathtokey
|
||||||
|
|
@ -897,7 +913,7 @@ export const resolveVariables = async (
|
||||||
reactFlowNodes: IReactFlowNode[],
|
reactFlowNodes: IReactFlowNode[],
|
||||||
question: string,
|
question: string,
|
||||||
chatHistory: IMessage[],
|
chatHistory: IMessage[],
|
||||||
overrideConfig?: ICommonObject
|
flowData?: ICommonObject
|
||||||
): Promise<INodeData> => {
|
): Promise<INodeData> => {
|
||||||
let flowNodeData = cloneDeep(reactFlowNodeData)
|
let flowNodeData = cloneDeep(reactFlowNodeData)
|
||||||
const types = 'inputs'
|
const types = 'inputs'
|
||||||
|
|
@ -915,7 +931,7 @@ export const resolveVariables = async (
|
||||||
question,
|
question,
|
||||||
chatHistory,
|
chatHistory,
|
||||||
undefined,
|
undefined,
|
||||||
overrideConfig
|
flowData
|
||||||
)
|
)
|
||||||
resolvedInstances.push(resolvedInstance)
|
resolvedInstances.push(resolvedInstance)
|
||||||
}
|
}
|
||||||
|
|
@ -929,7 +945,7 @@ export const resolveVariables = async (
|
||||||
question,
|
question,
|
||||||
chatHistory,
|
chatHistory,
|
||||||
isAcceptVariable,
|
isAcceptVariable,
|
||||||
overrideConfig
|
flowData
|
||||||
)
|
)
|
||||||
paramsObj[key] = resolvedInstance
|
paramsObj[key] = resolvedInstance
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue