variable resolution to support arrays of config objects

- Added handling for arrays of config objects in the resolveVariables function.
- Implemented a recursive search for config values to process all matching parameters, improving flexibility in variable resolution.
This commit is contained in:
Henry 2025-10-21 13:52:30 +01:00
parent bff859520a
commit e496ea599e
1 changed files with 44 additions and 4 deletions

View File

@ -489,6 +489,14 @@ export const resolveVariables = async (
return
}
// Handle arrays of config objects
if (Array.isArray(configObj)) {
for (const item of configObj) {
await processConfigParams(item, configParamWithAcceptVariables)
}
return
}
for (const [key, value] of Object.entries(configObj)) {
// Only resolve variables for parameters that accept them
// Example: requestsGetHeaders is in configParamWithAcceptVariables, so resolve "Bearer {{ $vars.TOKEN }}"
@ -528,15 +536,47 @@ export const resolveVariables = async (
// STEP 5: Look for the config object (paramName + "Config")
// Example: Look for "agentSelectedToolConfig" in the inputs
const configParamName = paramWithLoadConfig + 'Config'
const configValue = findParamValue(paramsObj, configParamName)
// STEP 6: Process config object to resolve variables
// Find all config values (handle arrays)
const findAllConfigValues = (obj: any, paramName: string): any[] => {
const results: any[] = []
if (typeof obj !== 'object' || obj === null) {
return results
}
// Handle arrays (e.g., agentTools array)
if (Array.isArray(obj)) {
for (const item of obj) {
results.push(...findAllConfigValues(item, paramName))
}
return results
}
// Direct property match
if (Object.prototype.hasOwnProperty.call(obj, paramName)) {
results.push(obj[paramName])
}
// Recursively search nested objects
for (const value of Object.values(obj)) {
results.push(...findAllConfigValues(value, paramName))
}
return results
}
const configValues = findAllConfigValues(paramsObj, configParamName)
// STEP 6: Process all config objects to resolve variables
// Example: Resolve "Bearer {{ $vars.TOKEN }}" in requestsGetHeaders
if (configValue && configParamWithAcceptVariables.length > 0) {
if (configValues.length > 0 && configParamWithAcceptVariables.length > 0) {
for (const configValue of configValues) {
await processConfigParams(configValue, configParamWithAcceptVariables)
}
}
}
}
// Original logic for direct acceptVariable params (maintains backward compatibility)
// Example: Direct params like agentUserMessage with acceptVariable: true