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
+2 -31
View File
@@ -12,7 +12,7 @@ import {
replaceBase64ImagesWithFileReferences,
updateFlowState
} from '../utils'
import { get } from 'lodash'
import { processTemplateVariables } from '../../../src/utils'
class LLM_Agentflow implements INode {
label: string
@@ -529,36 +529,7 @@ class LLM_Agentflow implements INode {
}
// Process template variables in state
if (newState && Object.keys(newState).length > 0) {
for (const key in newState) {
const stateValue = newState[key].toString()
if (stateValue.includes('{{ output')) {
// Handle simple output replacement
if (stateValue === '{{ output }}') {
newState[key] = finalResponse
continue
}
// Handle JSON path expressions like {{ output.item1 }}
// eslint-disable-next-line
const match = stateValue.match(/{{[\s]*output\.([\w\.]+)[\s]*}}/)
if (match) {
try {
// Parse the response if it's JSON
const jsonResponse = typeof finalResponse === 'string' ? JSON.parse(finalResponse) : finalResponse
// Get the value using lodash get
const path = match[1]
const value = get(jsonResponse, path)
newState[key] = value ?? stateValue // Fall back to original if path not found
} catch (e) {
// If JSON parsing fails, keep original template
console.warn(`Failed to parse JSON or find path in output: ${e}`)
newState[key] = stateValue
}
}
}
}
}
newState = processTemplateVariables(newState, finalResponse)
// Replace the actual messages array with one that includes the file references for images instead of base64 data
const messagesWithFileReferences = replaceBase64ImagesWithFileReferences(