@@ -11,9 +11,10 @@ import { extractAndPersistCustomTools } from '@/lib/workflows/persistence/custom
1111import { loadWorkflowFromNormalizedTables } from '@/lib/workflows/persistence/utils'
1212import { isValidKey } from '@/lib/workflows/sanitization/key-validation'
1313import { validateWorkflowState } from '@/lib/workflows/sanitization/validation'
14+ import { buildCanonicalIndex , isCanonicalPair } from '@/lib/workflows/subblocks/visibility'
1415import { TriggerUtils } from '@/lib/workflows/triggers/triggers'
1516import { getAllBlocks , getBlock } from '@/blocks/registry'
16- import type { SubBlockConfig } from '@/blocks/types'
17+ import type { BlockConfig , SubBlockConfig } from '@/blocks/types'
1718import { EDGE , normalizeName , RESERVED_BLOCK_NAMES } from '@/executor/constants'
1819import { getUserPermissionConfig } from '@/executor/utils/permission-check'
1920import { generateLoopBlocks , generateParallelBlocks } from '@/stores/workflows/workflow/utils'
@@ -667,11 +668,47 @@ 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 isAdvanced = group . advancedIds . includes ( inputKey )
698+ const existingMode = canonicalModeUpdates [ canonicalId ]
699+
700+ if ( ! existingMode || isAdvanced ) {
701+ canonicalModeUpdates [ canonicalId ] = isAdvanced ? 'advanced' : 'basic'
702+ }
703+ }
704+
705+ if ( Object . keys ( canonicalModeUpdates ) . length > 0 ) {
706+ if ( ! block . data ) block . data = { }
707+ if ( ! block . data . canonicalModes ) block . data . canonicalModes = { }
708+ Object . assign ( block . data . canonicalModes , canonicalModeUpdates )
709+ }
710+ }
711+
675712/**
676713 * Normalize tools array by adding back fields that were sanitized for training
677714 */
@@ -1654,6 +1691,15 @@ function applyOperationsToWorkflowState(
16541691 block . data . collection = params . inputs . collection
16551692 }
16561693 }
1694+
1695+ const editBlockConfig = getBlock ( block . type )
1696+ if ( editBlockConfig ) {
1697+ updateCanonicalModesForInputs (
1698+ block ,
1699+ Object . keys ( validationResult . validInputs ) ,
1700+ editBlockConfig
1701+ )
1702+ }
16571703 }
16581704
16591705 // Update basic properties
@@ -2256,6 +2302,15 @@ function applyOperationsToWorkflowState(
22562302 existingBlock . subBlocks [ key ] . value = sanitizedValue
22572303 }
22582304 } )
2305+
2306+ const existingBlockConfig = getBlock ( existingBlock . type )
2307+ if ( existingBlockConfig ) {
2308+ updateCanonicalModesForInputs (
2309+ existingBlock ,
2310+ Object . keys ( validationResult . validInputs ) ,
2311+ existingBlockConfig
2312+ )
2313+ }
22592314 }
22602315 } else {
22612316 // Special container types (loop, parallel) are not in the block registry but are valid
0 commit comments