From e430bee5ea8e0b6e49fb7086088117bff41d3da1 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Tue, 4 Feb 2025 18:14:00 -0800 Subject: [PATCH] Add the ability to resolve envvar values and connection tags inside of tools sub-block --- executor/index.ts | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/executor/index.ts b/executor/index.ts index bf521b848..d2e70ae3e 100644 --- a/executor/index.ts +++ b/executor/index.ts @@ -237,13 +237,39 @@ export class Executor { const toolConfig = getTool(toolId) if (!toolConfig) return null - // Return the tool configuration with parameters + // Resolve environment variables in tool parameters + const resolvedParams = Object.entries(tool.params || {}).reduce((acc, [key, value]) => { + if (typeof value === 'string') { + // Handle environment variables with {{}} syntax + const envMatches = value.match(/\{\{([^}]+)\}\}/g) + if (envMatches) { + let resolvedValue = value + for (const match of envMatches) { + const envKey = match.slice(2, -2) // remove {{ and }} + const envValue = context.environmentVariables?.[envKey] + + if (envValue === undefined) { + throw new Error(`Environment variable "${envKey}" was not found.`) + } + + resolvedValue = resolvedValue.replace(match, envValue) + } + acc[key] = resolvedValue + } else { + acc[key] = value + } + } else { + acc[key] = value + } + return acc + }, {} as Record) + + // Return the tool configuration with resolved parameters return { id: toolConfig.id, name: toolConfig.name, description: toolConfig.description, - // Store the actual parameters from the tool input - params: tool.params || {}, + params: resolvedParams, parameters: { type: 'object', properties: Object.entries(toolConfig.params).reduce((acc, [key, config]) => ({ @@ -251,7 +277,7 @@ export class Executor { [key]: { type: config.type === 'json' ? 'object' : config.type, description: config.description || '', - ...(key in (tool.params || {}) && { default: tool.params[key] }) + ...(key in resolvedParams && { default: resolvedParams[key] }) } }), {}), required: Object.entries(toolConfig.params)