diff --git a/executor/utils.ts b/executor/utils.ts index c799c5885b..a528e276fb 100644 --- a/executor/utils.ts +++ b/executor/utils.ts @@ -1,16 +1,3 @@ -function stringifyValue(value: any): string { - if (typeof value === 'string') { - return `"${value.replace(/"/g, '\\"').replace(/\n/g, '\\n')}"` - } else if (value === null) { - return 'null' - } else if (typeof value === 'undefined') { - return 'undefined' - } else if (typeof value === 'object') { - return JSON.stringify(value) - } - return String(value) -} - export function resolveEnvVariables(value: any, environmentVariables: Record): any { if (typeof value === 'string') { const envMatches = value.match(/\{\{([^}]+)\}\}/g) @@ -46,36 +33,29 @@ export function resolveBlockReferences( ): string { const blockMatches = value.match(/<([^>]+)>/g) let resolvedValue = value - if (blockMatches) { for (const match of blockMatches) { - // e.g. "" const path = match.slice(1, -1) const [blockRef, ...pathParts] = path.split('.') let sourceBlock = blockById.get(blockRef) - if (!sourceBlock) { const normalized = blockRef.toLowerCase().replace(/\s+/g, '') sourceBlock = blockByName.get(normalized) } - if (!sourceBlock) { throw new Error(`Block reference "${blockRef}" was not found.`) } - if (sourceBlock.enabled === false) { throw new Error( `Block "${sourceBlock.metadata?.title}" is disabled, and block "${currentBlockTitle}" depends on it.` ) } - const sourceState = contextBlockStates.get(sourceBlock.id) if (!sourceState) { throw new Error( `No state found for block "${sourceBlock.metadata?.title}" (ID: ${sourceBlock.id}).` ) } - // Drill into the property path. let replacementValue: any = sourceState for (const part of pathParts) { @@ -84,29 +64,13 @@ export function resolveBlockReferences( } replacementValue = replacementValue[part] } - if (replacementValue !== undefined) { - // For condition blocks, we need to properly stringify the value - const isConditionBlock = - value.includes('!==') || - value.includes('===') || - value.includes('>=') || - value.includes('<=') || - value.includes('>') || - value.includes('<') || - value.includes('&&') || - value.includes('||') - - if (isConditionBlock) { - resolvedValue = resolvedValue.replace(match, stringifyValue(replacementValue)) - } else { - resolvedValue = resolvedValue.replace( - match, - typeof replacementValue === 'object' - ? JSON.stringify(replacementValue) - : String(replacementValue) - ) - } + resolvedValue = resolvedValue.replace( + match, + typeof replacementValue === 'object' + ? JSON.stringify(replacementValue) + : String(replacementValue) + ) } else { throw new Error( `No value found at path "${path}" in block "${sourceBlock.metadata?.title}".` @@ -114,6 +78,5 @@ export function resolveBlockReferences( } } } - return resolvedValue }