File tree Expand file tree Collapse file tree 4 files changed +26
-21
lines changed
copilot/tools/server/workflow/edit-workflow Expand file tree Collapse file tree 4 files changed +26
-21
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,11 @@ import crypto from 'crypto'
22import { createLogger } from '@sim/logger'
33import type { PermissionGroupConfig } from '@/lib/permission-groups/types'
44import { getEffectiveBlockOutputs } from '@/lib/workflows/blocks/block-outputs'
5- import { buildCanonicalIndex , isCanonicalPair } from '@/lib/workflows/subblocks/visibility'
5+ import {
6+ buildCanonicalIndex ,
7+ buildDefaultCanonicalModes ,
8+ isCanonicalPair ,
9+ } from '@/lib/workflows/subblocks/visibility'
610import { hasTriggerCapability } from '@/lib/workflows/triggers/trigger-utils'
711import { getAllBlocks } from '@/blocks/registry'
812import type { BlockConfig } from '@/blocks/types'
@@ -130,13 +134,7 @@ export function createBlockFromParams(
130134 }
131135 } )
132136
133- const canonicalIndex = buildCanonicalIndex ( blockConfig . subBlocks )
134- const defaultModes : Record < string , 'basic' | 'advanced' > = { }
135- for ( const group of Object . values ( canonicalIndex . groupsById ) ) {
136- if ( isCanonicalPair ( group ) ) {
137- defaultModes [ group . canonicalId ] = 'basic'
138- }
139- }
137+ const defaultModes = buildDefaultCanonicalModes ( blockConfig . subBlocks )
140138 if ( Object . keys ( defaultModes ) . length > 0 ) {
141139 if ( ! blockState . data ) blockState . data = { }
142140 blockState . data . canonicalModes = defaultModes
Original file line number Diff line number Diff line change @@ -75,6 +75,23 @@ export function isCanonicalPair(group?: CanonicalGroup): boolean {
7575 return Boolean ( group ?. basicId && group ?. advancedIds ?. length )
7676}
7777
78+ /**
79+ * Builds default canonical mode overrides for a block's subblocks.
80+ * All canonical pairs default to `'basic'`.
81+ */
82+ export function buildDefaultCanonicalModes (
83+ subBlocks : SubBlockConfig [ ]
84+ ) : Record < string , 'basic' | 'advanced' > {
85+ const index = buildCanonicalIndex ( subBlocks )
86+ const modes : Record < string , 'basic' | 'advanced' > = { }
87+ for ( const group of Object . values ( index . groupsById ) ) {
88+ if ( isCanonicalPair ( group ) ) {
89+ modes [ group . canonicalId ] = 'basic'
90+ }
91+ }
92+ return modes
93+ }
94+
7895/**
7996 * Determine the active mode for a canonical group.
8097 */
Original file line number Diff line number Diff line change @@ -378,11 +378,7 @@ export class Serializer {
378378 const hasExplicitOverride = canonicalModeOverrides ?. [ group . canonicalId ] != null
379379 const pairMode =
380380 hasExplicitOverride || ! legacyAdvancedMode
381- ? resolveCanonicalMode (
382- group ,
383- buildSubBlockValues ( block . subBlocks ) ,
384- canonicalModeOverrides
385- )
381+ ? resolveCanonicalMode ( group , allValues , canonicalModeOverrides )
386382 : 'advanced'
387383 const chosen = pairMode === 'advanced' ? advancedValue : basicValue
388384
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { v4 as uuidv4 } from 'uuid'
33import { DEFAULT_DUPLICATE_OFFSET } from '@/lib/workflows/autolayout/constants'
44import { getEffectiveBlockOutputs } from '@/lib/workflows/blocks/block-outputs'
55import { mergeSubblockStateWithValues } from '@/lib/workflows/subblocks'
6- import { buildCanonicalIndex , isCanonicalPair } from '@/lib/workflows/subblocks/visibility'
6+ import { buildDefaultCanonicalModes } from '@/lib/workflows/subblocks/visibility'
77import { hasTriggerCapability } from '@/lib/workflows/triggers/trigger-utils'
88import { TriggerUtils } from '@/lib/workflows/triggers/triggers'
99import { getBlock } from '@/blocks'
@@ -198,13 +198,7 @@ export function prepareBlockState(options: PrepareBlockStateOptions): BlockState
198198 } )
199199
200200 if ( blockConfig . subBlocks ) {
201- const canonicalIndex = buildCanonicalIndex ( blockConfig . subBlocks )
202- const canonicalModes : Record < string , 'basic' | 'advanced' > = { }
203- for ( const group of Object . values ( canonicalIndex . groupsById ) ) {
204- if ( isCanonicalPair ( group ) ) {
205- canonicalModes [ group . canonicalId ] = 'basic'
206- }
207- }
201+ const canonicalModes = buildDefaultCanonicalModes ( blockConfig . subBlocks )
208202 if ( Object . keys ( canonicalModes ) . length > 0 ) {
209203 blockData . canonicalModes = canonicalModes
210204 }
You can’t perform that action at this time.
0 commit comments