Skip to content

Commit e0d4d25

Browse files
committed
fix(editing): resolve a canonical param name on the block's active surface
On a trigger-mode block, a name shared by action and trigger fields (siteId) was written to the dormant action member.
1 parent 15bc7dc commit e0d4d25

4 files changed

Lines changed: 57 additions & 17 deletions

File tree

‎apps/sim/lib/workflows/editing/builders.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ export function createBlockFromParams(
157157
enforceToolBindingContract = false
158158
): any {
159159
const blockConfig = getBlock(params.type)
160+
const triggerMode = params.triggerMode || false
161+
const isTriggerCapable = blockConfig ? hasTriggerCapability(blockConfig) : false
162+
const effectiveTriggerMode = Boolean(triggerMode && isTriggerCapable)
160163

161164
// Validate inputs against block configuration
162165
let validatedInputs: Record<string, any> | undefined
@@ -166,19 +169,15 @@ export function createBlockFromParams(
166169
params.inputs,
167170
blockId,
168171
{},
169-
enforceToolBindingContract
172+
enforceToolBindingContract,
173+
effectiveTriggerMode
170174
)
171175
validatedInputs = result.validInputs
172176
if (errorsCollector && result.errors.length > 0) {
173177
errorsCollector.push(...result.errors)
174178
}
175179
}
176180

177-
// Determine outputs based on trigger mode
178-
const triggerMode = params.triggerMode || false
179-
const isTriggerCapable = blockConfig ? hasTriggerCapability(blockConfig) : false
180-
const effectiveTriggerMode = Boolean(triggerMode && isTriggerCapable)
181-
182181
const blockState: any = {
183182
id: blockId,
184183
type: params.type,

‎apps/sim/lib/workflows/editing/operations.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ function mergeNestedNodesForParent(
340340
childBlock.inputs,
341341
existingId,
342342
buildSubBlockValues(existingBlock.subBlocks),
343-
ctx.enforceToolBindingContract
343+
ctx.enforceToolBindingContract,
344+
existingBlock.triggerMode === true
344345
)
345346
validationErrors.push(...childValidation.errors)
346347

@@ -599,7 +600,8 @@ export function handleEditOperation(op: EditWorkflowOperation, ctx: OperationCon
599600
params.inputs,
600601
block_id,
601602
buildSubBlockValues(block.subBlocks),
602-
ctx.enforceToolBindingContract
603+
ctx.enforceToolBindingContract,
604+
typeof params.triggerMode === 'boolean' ? params.triggerMode : block.triggerMode === true
603605
)
604606
validationErrors.push(...validationResult.errors)
605607

@@ -1070,7 +1072,8 @@ export function handleInsertIntoSubflowOperation(
10701072
params.inputs,
10711073
block_id,
10721074
buildSubBlockValues(existingBlock.subBlocks ?? {}),
1073-
ctx.enforceToolBindingContract
1075+
ctx.enforceToolBindingContract,
1076+
existingBlock.triggerMode === true
10741077
)
10751078
validationErrors.push(...validationResult.errors)
10761079

‎apps/sim/lib/workflows/editing/validation.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ const canonicalCredBlockConfig = {
120120
],
121121
}
122122

123+
// Mirrors webflow: the action pair and the trigger field share the canonical param siteId.
124+
const dualSurfaceBlockConfig = {
125+
type: 'dualsurface',
126+
name: 'DualSurface',
127+
outputs: {},
128+
subBlocks: [
129+
{ id: 'siteSelector', type: 'project-selector', canonicalParamId: 'siteId', mode: 'basic' },
130+
{ id: 'manualSiteId', type: 'short-input', canonicalParamId: 'siteId', mode: 'advanced' },
131+
{ id: 'triggerSiteId', type: 'short-input', canonicalParamId: 'siteId', mode: 'trigger' },
132+
],
133+
}
134+
123135
// Mirrors video_generator_v3: routes provider -> tool; only video_falai has hosting.
124136
const videoBlockConfig = {
125137
type: 'video_generator_v3',
@@ -244,6 +256,7 @@ const blockConfigsByType: Record<string, unknown> = {
244256
huggingface: huggingfaceBlockConfig,
245257
knowledge: knowledgeBlockConfig,
246258
canonicalcred: canonicalCredBlockConfig,
259+
dualsurface: dualSurfaceBlockConfig,
247260
video_generator_v3: videoBlockConfig,
248261
custom_key_block: customKeyBlockConfig,
249262
image_generator_v2: imageBlockConfig,
@@ -407,6 +420,22 @@ describe('validateInputsForBlock', () => {
407420
])
408421
})
409422

423+
it("writes a canonical name on a trigger-mode block into the trigger's member, not a dormant action one", () => {
424+
const trigger = validateInputsForBlock(
425+
'dualsurface',
426+
{ siteId: 'site_1' },
427+
'b',
428+
{},
429+
false,
430+
true
431+
)
432+
const action = validateInputsForBlock('dualsurface', { siteId: 'site_1' }, 'b')
433+
434+
expect(trigger.errors).toEqual([])
435+
expect(trigger.validInputs).toEqual({ triggerSiteId: 'site_1' })
436+
expect(action.validInputs).toEqual({ manualSiteId: 'site_1' })
437+
})
438+
410439
it('still names a key that is neither a field nor a canonical param as unknown', () => {
411440
const result = validateInputsForBlock('canonicalcred', { credKey: 'cred_1' }, 'cred-1')
412441

‎apps/sim/lib/workflows/editing/validation.ts‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
import { containsReference } from '@/lib/workflows/sanitization/references'
3434
import { getSkillById } from '@/lib/workflows/skills/operations'
3535
import {
36+
buildCanonicalIndexForSurface,
3637
buildSubBlockValues,
3738
getCanonicalSubBlocksForSurface,
3839
} from '@/lib/workflows/subblocks/visibility'
@@ -111,17 +112,19 @@ function isContainerBlockType(blockType: string): blockType is 'loop' | 'paralle
111112
* member. For a basic/advanced pair, a string (an id, a `<block.output>` reference) goes to the
112113
* advanced member, the free-text field that takes either, and anything else to the basic one, as
113114
* source compiles a literal; the caller then records the mode the written member implies. A
114-
* canonical name written beside one of its own members is refused: the two would compete.
115+
* canonical name written beside one of its own members is refused: the two would compete. Names
116+
* resolve on the block's active surface (`triggerSurface`), so a trigger-mode block's name never
117+
* lands on a dormant action member that shares it.
115118
*/
116119
function withCanonicalNamesResolved(
117-
subBlocks: readonly SubBlockConfig[],
120+
subBlocks: SubBlockConfig[],
118121
subBlockMap: ReadonlyMap<string, SubBlockConfig[]>,
119122
inputs: Record<string, unknown>,
123+
triggerSurface: boolean,
120124
refuse: (key: string, error: string) => void
121125
): Record<string, unknown> {
122126
if (Object.keys(inputs).every((key) => subBlockMap.has(key))) return inputs
123-
// canonical-index-unscoped: maps written names to member ids and reads no values.
124-
const { groupsById } = buildCanonicalIndex(subBlocks)
127+
const { groupsById } = buildCanonicalIndexForSurface(subBlocks, triggerSurface)
125128
const resolved: Record<string, unknown> = {}
126129
for (const [key, value] of Object.entries(inputs)) {
127130
const group = subBlockMap.has(key) ? undefined : groupsById[key]
@@ -156,14 +159,16 @@ function withCanonicalNamesResolved(
156159

157160
/**
158161
* Validates and filters inputs against a block's subBlock configuration
159-
* Returns valid inputs and any validation errors encountered
162+
* Returns valid inputs and any validation errors encountered. `triggerSurface` is whether the
163+
* block runs in trigger mode, the surface a canonical param name resolves on.
160164
*/
161165
export function validateInputsForBlock(
162166
blockType: string,
163167
inputs: Record<string, any>,
164168
blockId: string,
165169
existingValues: Record<string, unknown> = {},
166-
enforceToolBindingContract = false
170+
enforceToolBindingContract = false,
171+
triggerSurface = false
167172
): ValidationResult {
168173
const errors: ValidationError[] = []
169174

@@ -228,8 +233,12 @@ export function validateInputsForBlock(
228233
subBlockMap.set(subBlock.id, variants)
229234
}
230235

231-
inputs = withCanonicalNamesResolved(blockConfig.subBlocks, subBlockMap, inputs, (key, error) =>
232-
errors.push({ blockId, blockType, field: key, value: inputs[key], error })
236+
inputs = withCanonicalNamesResolved(
237+
blockConfig.subBlocks,
238+
subBlockMap,
239+
inputs,
240+
triggerSurface,
241+
(key, error) => errors.push({ blockId, blockType, field: key, value: inputs[key], error })
233242
)
234243
const conditionValues = { ...existingValues, ...inputs }
235244

0 commit comments

Comments
 (0)