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)
|
||||
}
|
||||
|
||||
const flowData: ICommonObject = {
|
||||
chatflowid,
|
||||
chatId,
|
||||
sessionId,
|
||||
chatHistory,
|
||||
...incomingInput.overrideConfig
|
||||
}
|
||||
|
||||
const reactFlowNodeData: INodeData = await resolveVariables(
|
||||
appServer.AppDataSource,
|
||||
nodeToExecute.data,
|
||||
reactFlowNodes,
|
||||
incomingInput.question,
|
||||
chatHistory,
|
||||
incomingInput.overrideConfig
|
||||
flowData
|
||||
)
|
||||
nodeToExecuteData = reactFlowNodeData
|
||||
|
||||
|
|
|
|||
|
|
@ -486,6 +486,14 @@ export const buildFlow = async ({
|
|||
|
||||
const initializedNodes: Set<string> = new Set()
|
||||
const reversedGraph = constructGraphs(reactFlowNodes, reactFlowEdges, { isReversed: true }).graph
|
||||
|
||||
const flowData: ICommonObject = {
|
||||
chatflowid,
|
||||
chatId,
|
||||
sessionId,
|
||||
chatHistory,
|
||||
...overrideConfig
|
||||
}
|
||||
while (nodeQueue.length) {
|
||||
const { nodeId, depth } = nodeQueue.shift() as INodeQueue
|
||||
|
||||
|
|
@ -509,7 +517,7 @@ export const buildFlow = async ({
|
|||
flowNodes,
|
||||
question,
|
||||
chatHistory,
|
||||
overrideConfig
|
||||
flowData
|
||||
)
|
||||
|
||||
if (isUpsert && stopNodeId && nodeId === stopNodeId) {
|
||||
|
|
@ -760,7 +768,7 @@ export const getVariableValue = async (
|
|||
question: string,
|
||||
chatHistory: IMessage[],
|
||||
isAcceptVariable = false,
|
||||
overrideConfig?: ICommonObject
|
||||
flowData?: ICommonObject
|
||||
) => {
|
||||
const isObject = typeof paramValue === 'object'
|
||||
let returnVal = (isObject ? JSON.stringify(paramValue) : paramValue) ?? ''
|
||||
|
|
@ -797,7 +805,7 @@ export const getVariableValue = async (
|
|||
}
|
||||
|
||||
if (variableFullPath.startsWith('$vars.')) {
|
||||
const vars = await getGlobalVariable(appDataSource, overrideConfig)
|
||||
const vars = await getGlobalVariable(appDataSource, flowData)
|
||||
const variableValue = get(vars, variableFullPath.replace('$vars.', ''))
|
||||
if (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.
|
||||
// 1: <variableNodeId>.data.instance
|
||||
// 2: <variableNodeId>.data.instance.pathtokey
|
||||
|
|
@ -897,7 +913,7 @@ export const resolveVariables = async (
|
|||
reactFlowNodes: IReactFlowNode[],
|
||||
question: string,
|
||||
chatHistory: IMessage[],
|
||||
overrideConfig?: ICommonObject
|
||||
flowData?: ICommonObject
|
||||
): Promise<INodeData> => {
|
||||
let flowNodeData = cloneDeep(reactFlowNodeData)
|
||||
const types = 'inputs'
|
||||
|
|
@ -915,7 +931,7 @@ export const resolveVariables = async (
|
|||
question,
|
||||
chatHistory,
|
||||
undefined,
|
||||
overrideConfig
|
||||
flowData
|
||||
)
|
||||
resolvedInstances.push(resolvedInstance)
|
||||
}
|
||||
|
|
@ -929,7 +945,7 @@ export const resolveVariables = async (
|
|||
question,
|
||||
chatHistory,
|
||||
isAcceptVariable,
|
||||
overrideConfig
|
||||
flowData
|
||||
)
|
||||
paramsObj[key] = resolvedInstance
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue