diff --git a/apps/sim/lib/copilot/tools/server/workflow/edit-workflow.ts b/apps/sim/lib/copilot/tools/server/workflow/edit-workflow.ts index 34de7723f..1e112d3fc 100644 --- a/apps/sim/lib/copilot/tools/server/workflow/edit-workflow.ts +++ b/apps/sim/lib/copilot/tools/server/workflow/edit-workflow.ts @@ -11,9 +11,10 @@ import { extractAndPersistCustomTools } from '@/lib/workflows/persistence/custom import { loadWorkflowFromNormalizedTables } from '@/lib/workflows/persistence/utils' import { isValidKey } from '@/lib/workflows/sanitization/key-validation' import { validateWorkflowState } from '@/lib/workflows/sanitization/validation' +import { buildCanonicalIndex, isCanonicalPair } from '@/lib/workflows/subblocks/visibility' import { TriggerUtils } from '@/lib/workflows/triggers/triggers' import { getAllBlocks, getBlock } from '@/blocks/registry' -import type { SubBlockConfig } from '@/blocks/types' +import type { BlockConfig, SubBlockConfig } from '@/blocks/types' import { EDGE, normalizeName, RESERVED_BLOCK_NAMES } from '@/executor/constants' import { getUserPermissionConfig } from '@/executor/utils/permission-check' import { generateLoopBlocks, generateParallelBlocks } from '@/stores/workflows/workflow/utils' @@ -667,11 +668,47 @@ function createBlockFromParams( } } }) + + if (validatedInputs) { + updateCanonicalModesForInputs(blockState, Object.keys(validatedInputs), blockConfig) + } } return blockState } +function updateCanonicalModesForInputs( + block: { data?: { canonicalModes?: Record } }, + inputKeys: string[], + blockConfig: BlockConfig +): void { + if (!blockConfig.subBlocks?.length) return + + const canonicalIndex = buildCanonicalIndex(blockConfig.subBlocks) + const canonicalModeUpdates: Record = {} + + for (const inputKey of inputKeys) { + const canonicalId = canonicalIndex.canonicalIdBySubBlockId[inputKey] + if (!canonicalId) continue + + const group = canonicalIndex.groupsById[canonicalId] + if (!group || !isCanonicalPair(group)) continue + + const isAdvanced = group.advancedIds.includes(inputKey) + const existingMode = canonicalModeUpdates[canonicalId] + + if (!existingMode || isAdvanced) { + canonicalModeUpdates[canonicalId] = isAdvanced ? 'advanced' : 'basic' + } + } + + if (Object.keys(canonicalModeUpdates).length > 0) { + if (!block.data) block.data = {} + if (!block.data.canonicalModes) block.data.canonicalModes = {} + Object.assign(block.data.canonicalModes, canonicalModeUpdates) + } +} + /** * Normalize tools array by adding back fields that were sanitized for training */ @@ -1654,6 +1691,15 @@ function applyOperationsToWorkflowState( block.data.collection = params.inputs.collection } } + + const editBlockConfig = getBlock(block.type) + if (editBlockConfig) { + updateCanonicalModesForInputs( + block, + Object.keys(validationResult.validInputs), + editBlockConfig + ) + } } // Update basic properties @@ -2256,6 +2302,15 @@ function applyOperationsToWorkflowState( existingBlock.subBlocks[key].value = sanitizedValue } }) + + const existingBlockConfig = getBlock(existingBlock.type) + if (existingBlockConfig) { + updateCanonicalModesForInputs( + existingBlock, + Object.keys(validationResult.validInputs), + existingBlockConfig + ) + } } } else { // Special container types (loop, parallel) are not in the block registry but are valid diff --git a/bun.lock b/bun.lock index 4faa352e6..f1df7669e 100644 --- a/bun.lock +++ b/bun.lock @@ -1,6 +1,5 @@ { "lockfileVersion": 1, - "configVersion": 0, "workspaces": { "": { "name": "simstudio",