Skip to content

Commit ae33508

Browse files
committed
fix(copilot): canonical modes should be constructed
1 parent ac91d78 commit ae33508

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

apps/sim/lib/copilot/tools/server/workflow/edit-workflow.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import { extractAndPersistCustomTools } from '@/lib/workflows/persistence/custom
1111
import { loadWorkflowFromNormalizedTables } from '@/lib/workflows/persistence/utils'
1212
import { isValidKey } from '@/lib/workflows/sanitization/key-validation'
1313
import { validateWorkflowState } from '@/lib/workflows/sanitization/validation'
14+
import { buildCanonicalIndex, isCanonicalPair } from '@/lib/workflows/subblocks/visibility'
1415
import { TriggerUtils } from '@/lib/workflows/triggers/triggers'
1516
import { getAllBlocks, getBlock } from '@/blocks/registry'
16-
import type { SubBlockConfig } from '@/blocks/types'
17+
import type { BlockConfig, SubBlockConfig } from '@/blocks/types'
1718
import { EDGE, normalizeName, RESERVED_BLOCK_NAMES } from '@/executor/constants'
1819
import { getUserPermissionConfig } from '@/executor/utils/permission-check'
1920
import { generateLoopBlocks, generateParallelBlocks } from '@/stores/workflows/workflow/utils'
@@ -667,11 +668,56 @@ function createBlockFromParams(
667668
}
668669
}
669670
})
671+
672+
if (validatedInputs) {
673+
updateCanonicalModesForInputs(blockState, Object.keys(validatedInputs), blockConfig)
674+
}
670675
}
671676

672677
return blockState
673678
}
674679

680+
function updateCanonicalModesForInputs(
681+
block: { data?: { canonicalModes?: Record<string, 'basic' | 'advanced'> } },
682+
inputKeys: string[],
683+
blockConfig: BlockConfig
684+
): void {
685+
if (!blockConfig.subBlocks?.length) return
686+
687+
const canonicalIndex = buildCanonicalIndex(blockConfig.subBlocks)
688+
const canonicalModeUpdates: Record<string, 'basic' | 'advanced'> = {}
689+
690+
for (const inputKey of inputKeys) {
691+
const canonicalId = canonicalIndex.canonicalIdBySubBlockId[inputKey]
692+
if (!canonicalId) continue
693+
694+
const group = canonicalIndex.groupsById[canonicalId]
695+
if (!group || !isCanonicalPair(group)) continue
696+
697+
const subBlockConfig = blockConfig.subBlocks.find((sb) => sb.id === inputKey)
698+
if (
699+
!subBlockConfig?.mode ||
700+
subBlockConfig.mode === 'both' ||
701+
subBlockConfig.mode === 'trigger'
702+
)
703+
continue
704+
705+
const inputMode: 'basic' | 'advanced' =
706+
subBlockConfig.mode === 'advanced' ? 'advanced' : 'basic'
707+
const existingMode = canonicalModeUpdates[canonicalId]
708+
709+
if (!existingMode || inputMode === 'advanced') {
710+
canonicalModeUpdates[canonicalId] = inputMode
711+
}
712+
}
713+
714+
if (Object.keys(canonicalModeUpdates).length > 0) {
715+
if (!block.data) block.data = {}
716+
if (!block.data.canonicalModes) block.data.canonicalModes = {}
717+
Object.assign(block.data.canonicalModes, canonicalModeUpdates)
718+
}
719+
}
720+
675721
/**
676722
* Normalize tools array by adding back fields that were sanitized for training
677723
*/
@@ -1654,6 +1700,15 @@ function applyOperationsToWorkflowState(
16541700
block.data.collection = params.inputs.collection
16551701
}
16561702
}
1703+
1704+
const editBlockConfig = getBlock(block.type)
1705+
if (editBlockConfig) {
1706+
updateCanonicalModesForInputs(
1707+
block,
1708+
Object.keys(validationResult.validInputs),
1709+
editBlockConfig
1710+
)
1711+
}
16571712
}
16581713

16591714
// Update basic properties

bun.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)