MCPcopy Index your code
hub / github.com/simstudioai/sim / namespaceSubBlockId

Function namespaceSubBlockId

apps/sim/triggers/index.ts:39–63  ·  view source on GitHub ↗

* Namespaces a subBlock ID with the trigger ID to avoid conflicts when * multiple triggers are merged into a single block. * * Only namespaces display-only subBlocks (readOnly or text type) that have * a condition on selectedTriggerId. User-input fields are NOT namespaced * so their values pers

(subBlock: SubBlockConfig, triggerId: string)

Source from the content-addressed store, hash-verified

37 * so their values persist when switching between triggers.
38 */
39function namespaceSubBlockId(subBlock: SubBlockConfig, triggerId: string): SubBlockConfig {
40 // Don't namespace shared IDs
41 if (SHARED_SUBBLOCK_IDS.has(subBlock.id)) {
42 return subBlock
43 }
44
45 // Only namespace display-only subBlocks to avoid content conflicts
46 // User-input fields should remain shared so values persist across trigger switches
47 if (!isDisplayOnlySubBlock(subBlock)) {
48 return subBlock
49 }
50
51 // Only namespace if the subBlock has a condition on selectedTriggerId
52 // These are the ones that are trigger-specific and will conflict when merged
53 const condition =
54 typeof subBlock.condition === 'function' ? subBlock.condition() : subBlock.condition
55 if (condition?.field === 'selectedTriggerId') {
56 return {
57 ...subBlock,
58 id: `${subBlock.id}_${triggerId}`,
59 }
60 }
61
62 return subBlock
63}
64
65/**
66 * Gets a trigger config and injects samplePayload subblock with condition.

Callers 1

getTriggerFunction · 0.85

Calls 1

isDisplayOnlySubBlockFunction · 0.85

Tested by

no test coverage detected