@@ -402,8 +402,7 @@ export class Serializer {
402402
403403 // Second pass: filter by mode and conditions
404404 Object . entries ( block . subBlocks ) . forEach ( ( [ id , subBlock ] ) => {
405- // Find the corresponding subblock config to check its mode and condition
406- const subBlockConfig = blockConfig . subBlocks . find ( ( config ) => config . id === id )
405+ const matchingConfigs = blockConfig . subBlocks . filter ( ( config ) => config . id === id )
407406
408407 // Include field if it matches current mode OR if it's the starter inputFormat with values
409408 const hasStarterInputFormatValues =
@@ -417,13 +416,17 @@ export class Serializer {
417416 const isLegacyAgentField =
418417 isAgentBlock && [ 'systemPrompt' , 'userPrompt' , 'memories' ] . includes ( id )
419418
420- // Check if field's condition is met (conditionally-hidden fields should be excluded)
421- const conditionMet = subBlockConfig
422- ? evaluateCondition ( subBlockConfig . condition , allValues )
423- : true
419+ const anyConditionMet =
420+ matchingConfigs . length === 0
421+ ? true
422+ : matchingConfigs . some (
423+ ( config ) =>
424+ shouldIncludeField ( config , isAdvancedMode ) &&
425+ evaluateCondition ( config . condition , allValues )
426+ )
424427
425428 if (
426- ( subBlockConfig && shouldIncludeField ( subBlockConfig , isAdvancedMode ) && conditionMet ) ||
429+ ( matchingConfigs . length > 0 && anyConditionMet ) ||
427430 hasStarterInputFormatValues ||
428431 isLegacyAgentField
429432 ) {
@@ -540,26 +543,26 @@ export class Serializer {
540543 // Iterate through the tool's parameters, not the block's subBlocks
541544 Object . entries ( currentTool . params || { } ) . forEach ( ( [ paramId , paramConfig ] ) => {
542545 if ( paramConfig . required && paramConfig . visibility === 'user-only' ) {
543- const subBlockConfig = blockConfig . subBlocks ?. find ( ( sb : any ) => sb . id === paramId )
546+ const matchingConfigs = blockConfig . subBlocks ?. filter ( ( sb : any ) => sb . id === paramId ) || [ ]
544547
545548 let shouldValidateParam = true
546549
547- if ( subBlockConfig ) {
550+ if ( matchingConfigs . length > 0 ) {
548551 const isAdvancedMode = block . advancedMode ?? false
549- const includedByMode = shouldIncludeField ( subBlockConfig , isAdvancedMode )
550552
551- // Check visibility condition
552- const includedByCondition = evaluateCondition ( subBlockConfig . condition , params )
553+ shouldValidateParam = matchingConfigs . some ( ( subBlockConfig : any ) => {
554+ const includedByMode = shouldIncludeField ( subBlockConfig , isAdvancedMode )
553555
554- // Check if field is required based on its required condition (if it's a condition object)
555- const isRequired = ( ( ) => {
556- if ( ! subBlockConfig . required ) return false
557- if ( typeof subBlockConfig . required === 'boolean' ) return subBlockConfig . required
558- // If required is a condition object, evaluate it
559- return evaluateCondition ( subBlockConfig . required , params )
560- } ) ( )
556+ const includedByCondition = evaluateCondition ( subBlockConfig . condition , params )
561557
562- shouldValidateParam = includedByMode && includedByCondition && isRequired
558+ const isRequired = ( ( ) => {
559+ if ( ! subBlockConfig . required ) return false
560+ if ( typeof subBlockConfig . required === 'boolean' ) return subBlockConfig . required
561+ return evaluateCondition ( subBlockConfig . required , params )
562+ } ) ( )
563+
564+ return includedByMode && includedByCondition && isRequired
565+ } )
563566 }
564567
565568 if ( ! shouldValidateParam ) {
@@ -568,7 +571,12 @@ export class Serializer {
568571
569572 const fieldValue = params [ paramId ]
570573 if ( fieldValue === undefined || fieldValue === null || fieldValue === '' ) {
571- const displayName = subBlockConfig ?. title || paramId
574+ const activeConfig = matchingConfigs . find (
575+ ( config : any ) =>
576+ shouldIncludeField ( config , block . advancedMode ?? false ) &&
577+ evaluateCondition ( config . condition , params )
578+ )
579+ const displayName = activeConfig ?. title || paramId
572580 missingFields . push ( displayName )
573581 }
574582 }
@@ -596,8 +604,6 @@ export class Serializer {
596604 const accessibleIds = new Set < string > ( ancestorIds )
597605 accessibleIds . add ( blockId )
598606
599- // Only add starter block if it's actually upstream (already in ancestorIds)
600- // Don't add it just because it exists on the canvas
601607 if ( starterBlock && ancestorIds . includes ( starterBlock . id ) ) {
602608 accessibleIds . add ( starterBlock . id )
603609 }
0 commit comments