* Helper function to check if a subblock should be serialized.
( subBlockConfig: SubBlockConfig, values: Record<string, unknown>, displayAdvancedOptions: boolean, isTriggerContext: boolean, isTriggerCategory: boolean, canonicalIndex: ReturnType<typeof buildCanonicalIndex>, canonicalModeOverrides?: CanonicalModeOverrides )
| 42 | * Helper function to check if a subblock should be serialized. |
| 43 | */ |
| 44 | function shouldSerializeSubBlock( |
| 45 | subBlockConfig: SubBlockConfig, |
| 46 | values: Record<string, unknown>, |
| 47 | displayAdvancedOptions: boolean, |
| 48 | isTriggerContext: boolean, |
| 49 | isTriggerCategory: boolean, |
| 50 | canonicalIndex: ReturnType<typeof buildCanonicalIndex>, |
| 51 | canonicalModeOverrides?: CanonicalModeOverrides |
| 52 | ): boolean { |
| 53 | if (!isSubBlockFeatureEnabled(subBlockConfig)) return false |
| 54 | if (isSubBlockHidden(subBlockConfig)) return false |
| 55 | |
| 56 | if (subBlockConfig.mode === 'trigger') { |
| 57 | if (!isTriggerContext && !isTriggerCategory) return false |
| 58 | } else if (isTriggerContext && !isTriggerCategory) { |
| 59 | return false |
| 60 | } |
| 61 | |
| 62 | const isCanonicalMember = Boolean(canonicalIndex.canonicalIdBySubBlockId[subBlockConfig.id]) |
| 63 | if (isCanonicalMember) { |
| 64 | const canonicalId = canonicalIndex.canonicalIdBySubBlockId[subBlockConfig.id] |
| 65 | const group = canonicalId ? canonicalIndex.groupsById[canonicalId] : undefined |
| 66 | if (group && isCanonicalPair(group)) { |
| 67 | const mode = |
| 68 | canonicalModeOverrides?.[group.canonicalId] != null || !displayAdvancedOptions |
| 69 | ? resolveCanonicalMode(group, values, canonicalModeOverrides) |
| 70 | : 'advanced' |
| 71 | const matchesMode = |
| 72 | mode === 'advanced' |
| 73 | ? group.advancedIds.includes(subBlockConfig.id) |
| 74 | : group.basicId === subBlockConfig.id |
| 75 | return matchesMode && evaluateSubBlockCondition(subBlockConfig.condition, values) |
| 76 | } |
| 77 | return evaluateSubBlockCondition(subBlockConfig.condition, values) |
| 78 | } |
| 79 | |
| 80 | if (subBlockConfig.mode === 'advanced' && !displayAdvancedOptions) { |
| 81 | return isNonEmptyValue(values[subBlockConfig.id]) |
| 82 | } |
| 83 | if (subBlockConfig.mode === 'basic' && displayAdvancedOptions) { |
| 84 | return false |
| 85 | } |
| 86 | |
| 87 | return evaluateSubBlockCondition(subBlockConfig.condition, values) |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Helper function to migrate agent block params from old format to messages array |
no test coverage detected