(paramsObj: ICommonObject)
| 455 | } |
| 456 | |
| 457 | const getParamValues = async (paramsObj: ICommonObject) => { |
| 458 | /* |
| 459 | * EXAMPLE SCENARIO: |
| 460 | * |
| 461 | * 1. Agent node has inputParam: { name: "agentTools", type: "array", array: [{ name: "agentSelectedTool", loadConfig: true }] } |
| 462 | * 2. Inputs contain: { agentTools: [{ agentSelectedTool: "requestsGet", agentSelectedToolConfig: { requestsGetHeaders: "Bearer {{ $vars.TOKEN }}" } }] } |
| 463 | * 3. We need to resolve the variable in requestsGetHeaders because RequestsGet node defines requestsGetHeaders with acceptVariable: true |
| 464 | * |
| 465 | * STEP 1: Find all parameters with loadConfig=true (e.g., "agentSelectedTool") |
| 466 | * STEP 2: Find their values in inputs (e.g., "requestsGet") |
| 467 | * STEP 3: Look up component node definition for "requestsGet" |
| 468 | * STEP 4: Find which of its parameters have acceptVariable=true (e.g., "requestsGetHeaders") |
| 469 | * STEP 5: Find the config object (e.g., "agentSelectedToolConfig") |
| 470 | * STEP 6: Resolve variables in config parameters that accept variables |
| 471 | */ |
| 472 | |
| 473 | // Helper function to find params with loadConfig recursively |
| 474 | // Example: Finds ["agentModel", "agentSelectedTool"] from the inputParams structure |
| 475 | const findParamsWithLoadConfig = (inputParams: any[]): string[] => { |
| 476 | const paramsWithLoadConfig: string[] = [] |
| 477 | |
| 478 | for (const param of inputParams) { |
| 479 | // Direct loadConfig param (e.g., agentModel with loadConfig: true) |
| 480 | if (param.loadConfig === true) { |
| 481 | paramsWithLoadConfig.push(param.name) |
| 482 | } |
| 483 | |
| 484 | // Check nested array parameters (e.g., agentTools.array contains agentSelectedTool with loadConfig: true) |
| 485 | if (param.type === 'array' && param.array && Array.isArray(param.array)) { |
| 486 | const nestedParams = findParamsWithLoadConfig(param.array) |
| 487 | paramsWithLoadConfig.push(...nestedParams) |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | return paramsWithLoadConfig |
| 492 | } |
| 493 | |
| 494 | // Helper function to find value of a parameter recursively in nested objects/arrays |
| 495 | // Example: Searches for "agentSelectedTool" value in complex nested inputs structure |
| 496 | // Returns "requestsGet" when found in agentTools[0].agentSelectedTool |
| 497 | const findParamValue = (obj: any, paramName: string): any => { |
| 498 | if (typeof obj !== 'object' || obj === null) { |
| 499 | return undefined |
| 500 | } |
| 501 | |
| 502 | // Handle arrays (e.g., agentTools array) |
| 503 | if (Array.isArray(obj)) { |
| 504 | for (const item of obj) { |
| 505 | const result = findParamValue(item, paramName) |
| 506 | if (result !== undefined) { |
| 507 | return result |
| 508 | } |
| 509 | } |
| 510 | return undefined |
| 511 | } |
| 512 | |
| 513 | // Direct property match |
| 514 | if (Object.prototype.hasOwnProperty.call(obj, paramName)) { |
no test coverage detected