Skip to content

Commit a6561f3

Browse files
committed
address bugbot comment
1 parent 05451f2 commit a6561f3

4 files changed

Lines changed: 38 additions & 28 deletions

File tree

apps/sim/executor/constants.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,26 @@ export function isTriggerBlockType(blockType: string | undefined): boolean {
275275
return blockType !== undefined && (TRIGGER_BLOCK_TYPES as readonly string[]).includes(blockType)
276276
}
277277

278+
/**
279+
* Determines if a block behaves as a trigger based on its metadata and config.
280+
* This is used for execution flow decisions where trigger-like behavior matters.
281+
*
282+
* A block is considered trigger-like if:
283+
* - Its category is 'triggers'
284+
* - It has triggerMode enabled
285+
* - It's a starter block (legacy entry point)
286+
*/
287+
export function isTriggerBehavior(block: {
288+
metadata?: { category?: string; id?: string }
289+
config?: { params?: { triggerMode?: boolean } }
290+
}): boolean {
291+
return (
292+
block.metadata?.category === 'triggers' ||
293+
block.config?.params?.triggerMode === true ||
294+
block.metadata?.id === BlockType.STARTER
295+
)
296+
}
297+
278298
export function isMetadataOnlyBlockType(blockType: string | undefined): boolean {
279299
return (
280300
blockType !== undefined && (METADATA_ONLY_BLOCK_TYPES as readonly string[]).includes(blockType)

apps/sim/executor/execution/block-executor.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
DEFAULTS,
1212
EDGE,
1313
isSentinelBlockType,
14+
isTriggerBehavior,
1415
} from '@/executor/constants'
1516
import type { DAGNode } from '@/executor/dag/builder'
1617
import { ChildWorkflowError } from '@/executor/errors/child-workflow-error'
@@ -346,12 +347,7 @@ export class BlockExecutor {
346347
return filtered
347348
}
348349

349-
const isTrigger =
350-
block.metadata?.category === 'triggers' ||
351-
block.config?.params?.triggerMode === true ||
352-
block.metadata?.id === BlockType.STARTER
353-
354-
if (isTrigger) {
350+
if (isTriggerBehavior(block)) {
355351
const filtered: NormalizedBlockOutput = {}
356352
const internalKeys = ['webhook', 'workflowId']
357353
for (const [key, value] of Object.entries(output)) {

apps/sim/executor/handlers/trigger/trigger-handler.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
import { createLogger } from '@sim/logger'
2-
import { BlockType } from '@/executor/constants'
2+
import { BlockType, isTriggerBehavior } from '@/executor/constants'
33
import type { BlockHandler, ExecutionContext } from '@/executor/types'
44
import type { SerializedBlock } from '@/serializer/types'
55

66
const logger = createLogger('TriggerBlockHandler')
77

88
export class TriggerBlockHandler implements BlockHandler {
99
canHandle(block: SerializedBlock): boolean {
10-
if (block.metadata?.id === BlockType.STARTER) {
11-
return true
12-
}
13-
14-
const isTriggerCategory = block.metadata?.category === 'triggers'
15-
16-
const hasTriggerMode = block.config?.params?.triggerMode === true
17-
18-
return isTriggerCategory || hasTriggerMode
10+
return isTriggerBehavior(block)
1911
}
2012

2113
async execute(

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { normalizeInputFormatValue } from '@/lib/workflows/input-format'
2-
import { normalizeName } from '@/executor/constants'
2+
import { isTriggerBehavior, normalizeName } from '@/executor/constants'
33
import type { ExecutionContext } from '@/executor/types'
44
import type { OutputSchema } from '@/executor/utils/block-reference'
55
import type { SerializedBlock } from '@/serializer/types'
@@ -13,18 +13,20 @@ export interface BlockDataCollection {
1313
}
1414

1515
/**
16-
* Triggers where inputFormat fields should be merged into outputs schema.
16+
* Block types where inputFormat fields should be merged into outputs schema.
1717
* These are blocks where users define custom fields via inputFormat that become
18-
* valid output paths (e.g., <start.myField>, <webhook1.customField>).
18+
* valid output paths (e.g., <start.myField>, <webhook1.customField>, <hitl1.resumeField>).
19+
*
20+
* Note: This includes non-trigger blocks like 'starter' and 'human_in_the_loop' which
21+
* have category 'blocks' but still need their inputFormat exposed as outputs.
1922
*/
20-
const TRIGGERS_WITH_INPUT_FORMAT_OUTPUTS = [
23+
const BLOCKS_WITH_INPUT_FORMAT_OUTPUTS = [
2124
'start_trigger',
2225
'starter',
2326
'api_trigger',
2427
'input_trigger',
2528
'generic_webhook',
2629
'human_in_the_loop',
27-
'approval',
2830
] as const
2931

3032
function getInputFormatFields(block: SerializedBlock): OutputSchema {
@@ -48,17 +50,15 @@ export function getBlockSchema(
4850
block: SerializedBlock,
4951
toolConfig?: ToolConfig
5052
): OutputSchema | undefined {
51-
const isTrigger =
52-
block.metadata?.category === 'triggers' ||
53-
(block.config?.params as Record<string, unknown> | undefined)?.triggerMode === true
54-
5553
const blockType = block.metadata?.id
5654

55+
// For blocks that expose inputFormat as outputs, always merge them
56+
// This includes both triggers (start_trigger, generic_webhook) and
57+
// non-triggers (starter, human_in_the_loop) that have inputFormat
5758
if (
58-
isTrigger &&
5959
blockType &&
60-
TRIGGERS_WITH_INPUT_FORMAT_OUTPUTS.includes(
61-
blockType as (typeof TRIGGERS_WITH_INPUT_FORMAT_OUTPUTS)[number]
60+
BLOCKS_WITH_INPUT_FORMAT_OUTPUTS.includes(
61+
blockType as (typeof BLOCKS_WITH_INPUT_FORMAT_OUTPUTS)[number]
6262
)
6363
) {
6464
const baseOutputs = (block.outputs as OutputSchema) || {}
@@ -69,6 +69,8 @@ export function getBlockSchema(
6969
}
7070
}
7171

72+
const isTrigger = isTriggerBehavior(block)
73+
7274
if (isTrigger && block.outputs && Object.keys(block.outputs).length > 0) {
7375
return block.outputs as OutputSchema
7476
}

0 commit comments

Comments
 (0)