Bugfix/Array Input Variables (#5196)

- Replace manual template variable processing in multiple components with a new utility function `processTemplateVariables`.
This commit is contained in:
Henry Heng
2025-09-12 14:42:34 +01:00
committed by GitHub
parent 736c2b11a1
commit 4987a2880d
9 changed files with 199 additions and 81 deletions
@@ -8,7 +8,7 @@ import {
INodeParams,
IServerSideEventStreamer
} from '../../../src/Interface'
import { getVars, executeJavaScriptCode, createCodeExecutionSandbox } from '../../../src/utils'
import { getVars, executeJavaScriptCode, createCodeExecutionSandbox, processTemplateVariables } from '../../../src/utils'
import { updateFlowState } from '../utils'
interface ICustomFunctionInputVariables {
@@ -145,19 +145,13 @@ class CustomFunction_Agentflow implements INode {
const appDataSource = options.appDataSource as DataSource
const databaseEntities = options.databaseEntities as IDatabaseEntity
// Update flow state if needed
let newState = { ...state }
if (_customFunctionUpdateState && Array.isArray(_customFunctionUpdateState) && _customFunctionUpdateState.length > 0) {
newState = updateFlowState(state, _customFunctionUpdateState)
}
const variables = await getVars(appDataSource, databaseEntities, nodeData, options)
const flow = {
chatflowId: options.chatflowid,
sessionId: options.sessionId,
chatId: options.chatId,
input,
state: newState
state
}
// Create additional sandbox variables for custom function inputs
@@ -190,15 +184,14 @@ class CustomFunction_Agentflow implements INode {
finalOutput = JSON.stringify(response, null, 2)
}
// Process template variables in state
if (newState && Object.keys(newState).length > 0) {
for (const key in newState) {
if (newState[key].toString().includes('{{ output }}')) {
newState[key] = newState[key].replaceAll('{{ output }}', finalOutput)
}
}
// Update flow state if needed
let newState = { ...state }
if (_customFunctionUpdateState && Array.isArray(_customFunctionUpdateState) && _customFunctionUpdateState.length > 0) {
newState = updateFlowState(state, _customFunctionUpdateState)
}
newState = processTemplateVariables(newState, finalOutput)
const returnOutput = {
id: nodeData.id,
name: this.name,