Fix/variable resolution to support arrays of config objects (#5348)

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 Heng 2025-10-21 15:07:33 +01:00 committed by GitHub
parent bff859520a
commit f3f2eabb89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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,12 +536,44 @@ 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) {
await processConfigParams(configValue, configParamWithAcceptVariables)
if (configValues.length > 0 && configParamWithAcceptVariables.length > 0) {
for (const configValue of configValues) {
await processConfigParams(configValue, configParamWithAcceptVariables)
}
}
}
}