Skip to content

Commit 7ba07bc

Browse files
committed
fix output condition logic
1 parent 0c69f8b commit 7ba07bc

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

apps/sim/blocks/blocks/gmail.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,18 @@ export const GmailV2Block: BlockConfig<GmailToolResponse> = {
581581
results: { type: 'json', description: 'Search/read summary results' },
582582
attachments: { type: 'json', description: 'Downloaded attachments (if enabled)' },
583583

584+
// Draft-specific outputs
585+
draftId: {
586+
type: 'string',
587+
description: 'Draft ID',
588+
condition: { field: 'operation', value: 'draft_gmail' },
589+
},
590+
messageId: {
591+
type: 'string',
592+
description: 'Gmail message ID for the draft',
593+
condition: { field: 'operation', value: 'draft_gmail' },
594+
},
595+
584596
// Trigger outputs (unchanged)
585597
email_id: { type: 'string', description: 'Gmail message ID' },
586598
thread_id: { type: 'string', description: 'Gmail thread ID' },

apps/sim/executor/utils/block-data.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,25 @@ export function getBlockSchema(
1515
block: SerializedBlock,
1616
toolConfig?: ToolConfig
1717
): OutputSchema | undefined {
18-
if (block.outputs && Object.keys(block.outputs).length > 0) {
18+
const isTrigger =
19+
block.metadata?.category === 'triggers' ||
20+
(block.config?.params as Record<string, unknown> | undefined)?.triggerMode === true
21+
22+
// Triggers use saved outputs (defines the trigger payload schema)
23+
if (isTrigger && block.outputs && Object.keys(block.outputs).length > 0) {
1924
return block.outputs as OutputSchema
2025
}
2126

27+
// When a tool is selected, tool outputs are the source of truth
2228
if (toolConfig?.outputs && Object.keys(toolConfig.outputs).length > 0) {
2329
return toolConfig.outputs as OutputSchema
2430
}
2531

32+
// Fallback to saved outputs for blocks without tools
33+
if (block.outputs && Object.keys(block.outputs).length > 0) {
34+
return block.outputs as OutputSchema
35+
}
36+
2637
return undefined
2738
}
2839

apps/sim/lib/workflows/blocks/block-outputs.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -618,13 +618,6 @@ export function getToolOutputs(
618618
}
619619
}
620620

621-
/**
622-
* Generates output paths for a tool-based block.
623-
*
624-
* @param blockConfig - The block configuration containing tools config
625-
* @param subBlocks - SubBlock values for tool selection and condition evaluation
626-
* @returns Array of output paths for the tool, or empty array on error
627-
*/
628621
export function getToolOutputPaths(
629622
blockConfig: BlockConfig,
630623
subBlocks?: Record<string, SubBlockWithValue>
@@ -634,12 +627,22 @@ export function getToolOutputPaths(
634627
if (!outputs || Object.keys(outputs).length === 0) return []
635628

636629
if (subBlocks && blockConfig.outputs) {
637-
const filteredBlockOutputs = filterOutputsByCondition(blockConfig.outputs, subBlocks)
638-
const allowedKeys = new Set(Object.keys(filteredBlockOutputs))
639-
640630
const filteredOutputs: Record<string, any> = {}
631+
641632
for (const [key, value] of Object.entries(outputs)) {
642-
if (allowedKeys.has(key)) {
633+
const blockOutput = blockConfig.outputs[key]
634+
635+
if (!blockOutput || typeof blockOutput !== 'object') {
636+
filteredOutputs[key] = value
637+
continue
638+
}
639+
640+
const condition = (blockOutput as any).condition as OutputCondition | undefined
641+
if (condition) {
642+
if (evaluateOutputCondition(condition, subBlocks)) {
643+
filteredOutputs[key] = value
644+
}
645+
} else {
643646
filteredOutputs[key] = value
644647
}
645648
}

0 commit comments

Comments
 (0)