Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions apps/sim/executor/handlers/trigger/trigger-handler.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { createLogger } from '@/lib/logs/console/logger'
import { BlockType } from '@/executor/consts'
import type { BlockHandler, ExecutionContext } from '@/executor/types'
import type { SerializedBlock } from '@/serializer/types'

const logger = createLogger('TriggerBlockHandler')

/**
* Handler for trigger blocks (Gmail, Webhook, Schedule, etc.)
* These blocks don't execute tools - they provide input data to workflows
*/
export class TriggerBlockHandler implements BlockHandler {
canHandle(block: SerializedBlock): boolean {
// Handle blocks that are triggers - either by category or by having triggerMode enabled
if (block.metadata?.id === BlockType.STARTER) {
return true
}

const isTriggerCategory = block.metadata?.category === 'triggers'

// For blocks that can be both tools and triggers (like Gmail/Outlook), check if triggerMode is enabled
// This would come from the serialized block config/params
const hasTriggerMode = block.config?.params?.triggerMode === true

return isTriggerCategory || hasTriggerMode
Expand All @@ -27,6 +25,10 @@ export class TriggerBlockHandler implements BlockHandler {
): Promise<any> {
logger.info(`Executing trigger block: ${block.id} (Type: ${block.metadata?.id})`)

if (block.metadata?.id === BlockType.STARTER) {
return this.executeStarterBlock(ctx, block, inputs)
}

const existingState = ctx.blockStates.get(block.id)
if (existingState?.output && Object.keys(existingState.output).length > 0) {
const existingOutput = existingState.output as any
Expand Down Expand Up @@ -151,4 +153,31 @@ export class TriggerBlockHandler implements BlockHandler {
logger.debug(`No inputs provided for trigger block ${block.id}, returning empty object`)
return {}
}

private executeStarterBlock(
ctx: ExecutionContext,
block: SerializedBlock,
inputs: Record<string, any>
): any {
logger.info(`Executing starter block: ${block.id}`, {
blockName: block.metadata?.name,
})

const existingState = ctx.blockStates.get(block.id)
if (existingState?.output && Object.keys(existingState.output).length > 0) {
logger.debug('Returning pre-initialized starter block output', {
blockId: block.id,
outputKeys: Object.keys(existingState.output),
})
return existingState.output
}

logger.warn('Starter block output not found in context, returning empty output', {
blockId: block.id,
})

return {
input: inputs.input || '',
}
}
}