@@ -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,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
0 commit comments