Skip to content

Commit

Permalink
refactor and compatibilize with agent flow
Browse files Browse the repository at this point in the history
  • Loading branch information
raffareis committed Aug 26, 2024
1 parent bbf8cee commit d3662bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
5 changes: 2 additions & 3 deletions packages/server/src/utils/buildChatflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
nodeToExecute.data = replaceInputsWithConfig(nodeToExecute.data, incomingInput.overrideConfig)
}

const options: ICommonObject = {
const flowData: ICommonObject = {
chatflowid,
chatId,
sessionId,
Expand All @@ -342,8 +342,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
reactFlowNodes,
incomingInput.question,
chatHistory,
incomingInput.overrideConfig,
options
flowData
)
nodeToExecuteData = reactFlowNodeData

Expand Down
23 changes: 9 additions & 14 deletions packages/server/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ export const buildFlow = async ({
const initializedNodes: Set<string> = new Set()
const reversedGraph = constructGraphs(reactFlowNodes, reactFlowEdges, { isReversed: true }).graph

const options: ICommonObject = {
const flowData: ICommonObject = {
chatflowid,
chatId,
sessionId,
Expand Down Expand Up @@ -517,8 +517,7 @@ export const buildFlow = async ({
flowNodes,
question,
chatHistory,
overrideConfig,
options
flowData
)

if (isUpsert && stopNodeId && nodeId === stopNodeId) {
Expand Down Expand Up @@ -769,8 +768,7 @@ export const getVariableValue = async (
question: string,
chatHistory: IMessage[],
isAcceptVariable = false,
overrideConfig?: ICommonObject,
options?: ICommonObject
flowData?: ICommonObject
) => {
const isObject = typeof paramValue === 'object'
let returnVal = (isObject ? JSON.stringify(paramValue) : paramValue) ?? ''
Expand Down Expand Up @@ -807,16 +805,16 @@ 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
returnVal = returnVal.split(`{{${variableFullPath}}}`).join(variableValue)
}
}

if (variableFullPath.startsWith('$flow.') && options) {
const variableValue = get(options, variableFullPath.replace('$flow.', ''))
if (variableFullPath.startsWith('$flow.') && flowData) {
const variableValue = get(flowData, variableFullPath.replace('$flow.', ''))
if (variableValue) {
variableDict[`{{${variableFullPath}}}`] = variableValue
returnVal = returnVal.split(`{{${variableFullPath}}}`).join(variableValue)
Expand Down Expand Up @@ -915,8 +913,7 @@ export const resolveVariables = async (
reactFlowNodes: IReactFlowNode[],
question: string,
chatHistory: IMessage[],
overrideConfig?: ICommonObject,
options?: ICommonObject
flowData?: ICommonObject
): Promise<INodeData> => {
let flowNodeData = cloneDeep(reactFlowNodeData)
const types = 'inputs'
Expand All @@ -934,8 +931,7 @@ export const resolveVariables = async (
question,
chatHistory,
undefined,
overrideConfig,
options
flowData
)
resolvedInstances.push(resolvedInstance)
}
Expand All @@ -949,8 +945,7 @@ export const resolveVariables = async (
question,
chatHistory,
isAcceptVariable,
overrideConfig,
options
flowData
)
paramsObj[key] = resolvedInstance
}
Expand Down

0 comments on commit d3662bc

Please sign in to comment.