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:
parent
bff859520a
commit
f3f2eabb89
|
|
@ -489,6 +489,14 @@ export const resolveVariables = async (
|
||||||
return
|
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)) {
|
for (const [key, value] of Object.entries(configObj)) {
|
||||||
// Only resolve variables for parameters that accept them
|
// Only resolve variables for parameters that accept them
|
||||||
// Example: requestsGetHeaders is in configParamWithAcceptVariables, so resolve "Bearer {{ $vars.TOKEN }}"
|
// 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")
|
// STEP 5: Look for the config object (paramName + "Config")
|
||||||
// Example: Look for "agentSelectedToolConfig" in the inputs
|
// Example: Look for "agentSelectedToolConfig" in the inputs
|
||||||
const configParamName = paramWithLoadConfig + 'Config'
|
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
|
// Example: Resolve "Bearer {{ $vars.TOKEN }}" in requestsGetHeaders
|
||||||
if (configValue && configParamWithAcceptVariables.length > 0) {
|
if (configValues.length > 0 && configParamWithAcceptVariables.length > 0) {
|
||||||
await processConfigParams(configValue, configParamWithAcceptVariables)
|
for (const configValue of configValues) {
|
||||||
|
await processConfigParams(configValue, configParamWithAcceptVariables)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue