From 35ac68f579c4c13f5201d8a3a016df9fcd7631e7 Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Mon, 30 Jun 2025 13:55:12 -0700 Subject: [PATCH] fix(func var resolution): variable ref codepath triggered - lint fixed --- apps/sim/app/api/function/execute/route.ts | 21 +++++++++++-------- .../handlers/function/function-handler.ts | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/apps/sim/app/api/function/execute/route.ts b/apps/sim/app/api/function/execute/route.ts index 485e7b07c..e7c649694 100644 --- a/apps/sim/app/api/function/execute/route.ts +++ b/apps/sim/app/api/function/execute/route.ts @@ -44,11 +44,9 @@ function resolveCodeVariables( // Resolve tags with syntax (including nested paths like ) const tagMatches = resolvedCode.match(/<([a-zA-Z_][a-zA-Z0-9_.]*[a-zA-Z0-9_])>/g) || [] - for (const match of tagMatches) { const tagName = match.slice(1, -1).trim() - // Handle nested paths like "getrecord.response.data" or "function1.response.result" // First try params, then blockData directly, then try with block name mapping let tagValue = getNestedValue(params, tagName) || getNestedValue(blockData, tagName) || '' @@ -76,15 +74,15 @@ function resolveCodeVariables( const remainingPath = pathParts.slice(1).join('.') const fullPath = `${blockId}.${remainingPath}` tagValue = getNestedValue(blockData, fullPath) || '' - } } - - // If the value is a stringified JSON, parse it back to object - if (typeof tagValue === 'string' && tagValue.length > 100 && - (tagValue.startsWith('{') || tagValue.startsWith('['))) { + if ( + typeof tagValue === 'string' && + tagValue.length > 100 && + (tagValue.startsWith('{') || tagValue.startsWith('[')) + ) { try { tagValue = JSON.parse(tagValue) } catch (e) { @@ -156,8 +154,13 @@ export async function POST(req: NextRequest) { logger.info(`[${requestId}] Original code:`, code.substring(0, 200)) logger.info(`[${requestId}] Execution params keys:`, Object.keys(executionParams)) - - const { resolvedCode, contextVariables } = resolveCodeVariables(code, executionParams, envVars, blockData, blockNameMapping) + const { resolvedCode, contextVariables } = resolveCodeVariables( + code, + executionParams, + envVars, + blockData, + blockNameMapping + ) logger.info(`[${requestId}] Resolved code:`, resolvedCode.substring(0, 200)) logger.info(`[${requestId}] Context variables keys:`, Object.keys(contextVariables)) diff --git a/apps/sim/executor/handlers/function/function-handler.ts b/apps/sim/executor/handlers/function/function-handler.ts index 3a56a1c12..8fcda9009 100644 --- a/apps/sim/executor/handlers/function/function-handler.ts +++ b/apps/sim/executor/handlers/function/function-handler.ts @@ -32,7 +32,7 @@ export class FunctionBlockHandler implements BlockHandler { blockData[blockId] = blockState.output // Try to find the block name from the workflow - const workflowBlock = context.workflow?.blocks?.find(b => b.id === blockId) + const workflowBlock = context.workflow?.blocks?.find((b) => b.id === blockId) if (workflowBlock?.metadata?.name) { blockNameMapping[workflowBlock.metadata.name] = blockId }