Skip to content

Commit 0363f8a

Browse files
fix(external-triggers): not passing payload through + incorrect server-side resolver logic (#1801)
* fix integration triggers * ignore text readonly subblocks * fix * fix to ignore readOnly vals * fix var references * simplify * cleanup code
1 parent d1fcade commit 0363f8a

File tree

4 files changed

+59
-64
lines changed

4 files changed

+59
-64
lines changed

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

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ export function buildResolutionFromBlock(block: SerializedBlock): ExecutorStartR
7676
return null
7777
}
7878

79-
const path = classifyStartBlockType(type)
79+
const category = block.metadata?.category
80+
const triggerModeEnabled = block.config?.params?.triggerMode === true
81+
82+
const path = classifyStartBlockType(type, {
83+
category,
84+
triggerModeEnabled,
85+
})
8086
if (!path) {
8187
return null
8288
}
@@ -342,11 +348,11 @@ function buildManualTriggerOutput(
342348
finalInput: unknown,
343349
workflowInput: unknown
344350
): NormalizedBlockOutput {
345-
const finalObject = isPlainObject(finalInput) ? finalInput : undefined
351+
const finalObject = isPlainObject(finalInput)
352+
? (finalInput as Record<string, unknown>)
353+
: undefined
346354

347-
const output: NormalizedBlockOutput = finalObject
348-
? { ...(finalObject as Record<string, unknown>) }
349-
: { input: finalInput }
355+
const output: NormalizedBlockOutput = finalObject ? { ...finalObject } : { input: finalInput }
350356

351357
if (!Object.hasOwn(output, 'input')) {
352358
output.input = getRawInputCandidate(workflowInput)
@@ -355,6 +361,24 @@ function buildManualTriggerOutput(
355361
return mergeFilesIntoOutput(output, workflowInput)
356362
}
357363

364+
function buildIntegrationTriggerOutput(
365+
finalInput: unknown,
366+
workflowInput: unknown
367+
): NormalizedBlockOutput {
368+
const base: NormalizedBlockOutput = isPlainObject(workflowInput)
369+
? ({ ...(workflowInput as Record<string, unknown>) } as NormalizedBlockOutput)
370+
: {}
371+
372+
if (isPlainObject(finalInput)) {
373+
Object.assign(base, finalInput as Record<string, unknown>)
374+
base.input = { ...(finalInput as Record<string, unknown>) }
375+
} else {
376+
base.input = finalInput
377+
}
378+
379+
return mergeFilesIntoOutput(base, workflowInput)
380+
}
381+
358382
function extractSubBlocks(block: SerializedBlock): Record<string, unknown> | undefined {
359383
const metadata = block.metadata
360384
if (!metadata || typeof metadata !== 'object') {
@@ -398,6 +422,9 @@ export function buildStartBlockOutput(options: StartBlockOutputOptions): Normali
398422
case StartBlockPath.SPLIT_MANUAL:
399423
return buildManualTriggerOutput(finalInput, workflowInput)
400424

425+
case StartBlockPath.EXTERNAL_TRIGGER:
426+
return buildIntegrationTriggerOutput(finalInput, workflowInput)
427+
401428
case StartBlockPath.LEGACY_STARTER:
402429
return buildLegacyStarterOutput(
403430
finalInput,

apps/sim/executor/variables/resolver.ts

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,6 @@ import { WorkflowResolver } from './resolvers/workflow'
1212

1313
const logger = createLogger('VariableResolver')
1414

15-
const INVALID_REFERENCE_CHARS = /[+*/=<>!]/
16-
17-
function isLikelyReferenceSegment(segment: string): boolean {
18-
if (!segment.startsWith(REFERENCE.START) || !segment.endsWith(REFERENCE.END)) {
19-
return false
20-
}
21-
22-
const inner = segment.slice(1, -1)
23-
24-
// Starts with space - not a reference
25-
if (inner.startsWith(' ')) {
26-
return false
27-
}
28-
29-
// Contains only comparison operators or has operators with spaces
30-
if (inner.match(/^\s*[<>=!]+\s*$/) || inner.match(/\s[<>=!]+\s/)) {
31-
return false
32-
}
33-
34-
// Starts with comparison operator followed by space
35-
if (inner.match(/^[<>=!]+\s/)) {
36-
return false
37-
}
38-
39-
// For dotted references (like <block.field>)
40-
if (inner.includes('.')) {
41-
const dotIndex = inner.indexOf('.')
42-
const beforeDot = inner.substring(0, dotIndex)
43-
const afterDot = inner.substring(dotIndex + 1)
44-
45-
// No spaces after dot
46-
if (afterDot.includes(' ')) {
47-
return false
48-
}
49-
50-
// No invalid chars in either part
51-
if (INVALID_REFERENCE_CHARS.test(beforeDot) || INVALID_REFERENCE_CHARS.test(afterDot)) {
52-
return false
53-
}
54-
} else if (INVALID_REFERENCE_CHARS.test(inner) || inner.match(/^\d/) || inner.match(/\s\d/)) {
55-
// No invalid chars, doesn't start with digit, no space before digit
56-
return false
57-
}
58-
59-
return true
60-
}
61-
6215
export class VariableResolver {
6316
private resolvers: Resolver[]
6417
private blockResolver: BlockResolver
@@ -197,10 +150,6 @@ export class VariableResolver {
197150
result = result.replace(referenceRegex, (match) => {
198151
if (replacementError) return match
199152

200-
if (!isLikelyReferenceSegment(match)) {
201-
return match
202-
}
203-
204153
try {
205154
const resolved = this.resolveReference(match, resolutionContext)
206155
if (resolved === undefined) {
@@ -260,10 +209,6 @@ export class VariableResolver {
260209
result = result.replace(referenceRegex, (match) => {
261210
if (replacementError) return match
262211

263-
if (!isLikelyReferenceSegment(match)) {
264-
return match
265-
}
266-
267212
try {
268213
const resolved = this.resolveReference(match, resolutionContext)
269214
if (resolved === undefined) {

apps/sim/executor/variables/resolvers/block.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ export class BlockResolver implements Resolver {
4646

4747
const blockId = this.findBlockIdByName(blockName)
4848
if (!blockId) {
49-
logger.error('Block not found by name', { blockName, reference })
50-
throw new Error(`Block "${blockName}" not found`)
49+
logger.debug('Block not found by name, skipping resolution', { blockName, reference })
50+
return undefined
5151
}
5252

5353
const output = this.getBlockOutput(blockId, context)

apps/sim/lib/workflows/triggers.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export enum StartBlockPath {
2323
SPLIT_API = 'legacy_api_trigger',
2424
SPLIT_CHAT = 'legacy_chat_trigger',
2525
SPLIT_MANUAL = 'legacy_manual_trigger',
26+
EXTERNAL_TRIGGER = 'external_trigger',
2627
}
2728

2829
type StartExecutionKind = 'chat' | 'manual' | 'api'
@@ -60,13 +61,26 @@ const START_CONFLICT_TYPES: TriggerType[] = [
6061

6162
type BlockWithType = { type: string; subBlocks?: Record<string, unknown> | undefined }
6263

64+
type BlockWithMetadata = BlockWithType & {
65+
category?: string
66+
triggers?: { enabled?: boolean }
67+
}
68+
6369
export interface StartBlockCandidate<T extends BlockWithType> {
6470
blockId: string
6571
block: T
6672
path: StartBlockPath
6773
}
6874

69-
export function classifyStartBlockType(type: string): StartBlockPath | null {
75+
type ClassifyStartOptions = {
76+
category?: string
77+
triggerModeEnabled?: boolean
78+
}
79+
80+
export function classifyStartBlockType(
81+
type: string,
82+
opts?: ClassifyStartOptions
83+
): StartBlockPath | null {
7084
switch (type) {
7185
case TRIGGER_TYPES.START:
7286
return StartBlockPath.UNIFIED
@@ -80,13 +94,22 @@ export function classifyStartBlockType(type: string): StartBlockPath | null {
8094
return StartBlockPath.SPLIT_CHAT
8195
case TRIGGER_TYPES.MANUAL:
8296
return StartBlockPath.SPLIT_MANUAL
97+
case TRIGGER_TYPES.WEBHOOK:
98+
case TRIGGER_TYPES.SCHEDULE:
99+
return StartBlockPath.EXTERNAL_TRIGGER
83100
default:
101+
if (opts?.category === 'triggers' || opts?.triggerModeEnabled) {
102+
return StartBlockPath.EXTERNAL_TRIGGER
103+
}
84104
return null
85105
}
86106
}
87107

88108
export function classifyStartBlock<T extends BlockWithType>(block: T): StartBlockPath | null {
89-
return classifyStartBlockType(block.type)
109+
const blockWithMetadata = block as BlockWithMetadata
110+
const category = blockWithMetadata.category
111+
const triggerModeEnabled = Boolean(blockWithMetadata.triggers?.enabled)
112+
return classifyStartBlockType(block.type, { category, triggerModeEnabled })
90113
}
91114

92115
export function isLegacyStartPath(path: StartBlockPath): boolean {

0 commit comments

Comments
 (0)