From 7ba07bc42838265b843fc9763699f0f6be25ea40 Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Sun, 25 Jan 2026 22:56:13 -0800 Subject: [PATCH] fix output condition logic --- apps/sim/blocks/blocks/gmail.ts | 12 +++++++++ apps/sim/executor/utils/block-data.ts | 13 +++++++++- .../sim/lib/workflows/blocks/block-outputs.ts | 25 +++++++++++-------- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/apps/sim/blocks/blocks/gmail.ts b/apps/sim/blocks/blocks/gmail.ts index e389d3b3d..223b69ec7 100644 --- a/apps/sim/blocks/blocks/gmail.ts +++ b/apps/sim/blocks/blocks/gmail.ts @@ -581,6 +581,18 @@ export const GmailV2Block: BlockConfig = { results: { type: 'json', description: 'Search/read summary results' }, attachments: { type: 'json', description: 'Downloaded attachments (if enabled)' }, + // Draft-specific outputs + draftId: { + type: 'string', + description: 'Draft ID', + condition: { field: 'operation', value: 'draft_gmail' }, + }, + messageId: { + type: 'string', + description: 'Gmail message ID for the draft', + condition: { field: 'operation', value: 'draft_gmail' }, + }, + // Trigger outputs (unchanged) email_id: { type: 'string', description: 'Gmail message ID' }, thread_id: { type: 'string', description: 'Gmail thread ID' }, diff --git a/apps/sim/executor/utils/block-data.ts b/apps/sim/executor/utils/block-data.ts index 6363bd5b0..0c7ec4bd1 100644 --- a/apps/sim/executor/utils/block-data.ts +++ b/apps/sim/executor/utils/block-data.ts @@ -15,14 +15,25 @@ export function getBlockSchema( block: SerializedBlock, toolConfig?: ToolConfig ): OutputSchema | undefined { - if (block.outputs && Object.keys(block.outputs).length > 0) { + const isTrigger = + block.metadata?.category === 'triggers' || + (block.config?.params as Record | undefined)?.triggerMode === true + + // Triggers use saved outputs (defines the trigger payload schema) + if (isTrigger && block.outputs && Object.keys(block.outputs).length > 0) { return block.outputs as OutputSchema } + // When a tool is selected, tool outputs are the source of truth if (toolConfig?.outputs && Object.keys(toolConfig.outputs).length > 0) { return toolConfig.outputs as OutputSchema } + // Fallback to saved outputs for blocks without tools + if (block.outputs && Object.keys(block.outputs).length > 0) { + return block.outputs as OutputSchema + } + return undefined } diff --git a/apps/sim/lib/workflows/blocks/block-outputs.ts b/apps/sim/lib/workflows/blocks/block-outputs.ts index 12972141a..0fecd31ed 100644 --- a/apps/sim/lib/workflows/blocks/block-outputs.ts +++ b/apps/sim/lib/workflows/blocks/block-outputs.ts @@ -618,13 +618,6 @@ export function getToolOutputs( } } -/** - * Generates output paths for a tool-based block. - * - * @param blockConfig - The block configuration containing tools config - * @param subBlocks - SubBlock values for tool selection and condition evaluation - * @returns Array of output paths for the tool, or empty array on error - */ export function getToolOutputPaths( blockConfig: BlockConfig, subBlocks?: Record @@ -634,12 +627,22 @@ export function getToolOutputPaths( if (!outputs || Object.keys(outputs).length === 0) return [] if (subBlocks && blockConfig.outputs) { - const filteredBlockOutputs = filterOutputsByCondition(blockConfig.outputs, subBlocks) - const allowedKeys = new Set(Object.keys(filteredBlockOutputs)) - const filteredOutputs: Record = {} + for (const [key, value] of Object.entries(outputs)) { - if (allowedKeys.has(key)) { + const blockOutput = blockConfig.outputs[key] + + if (!blockOutput || typeof blockOutput !== 'object') { + filteredOutputs[key] = value + continue + } + + const condition = (blockOutput as any).condition as OutputCondition | undefined + if (condition) { + if (evaluateOutputCondition(condition, subBlocks)) { + filteredOutputs[key] = value + } + } else { filteredOutputs[key] = value } }