(block: BlockState)
| 430 | * params exactly the way execution (serializeBlock) does. |
| 431 | */ |
| 432 | export function extractBlockParams(block: BlockState): Record<string, any> { |
| 433 | if (block.type === 'loop' || block.type === 'parallel') { |
| 434 | return {} |
| 435 | } |
| 436 | |
| 437 | const blockConfig = getBlock(block.type) |
| 438 | if (!blockConfig) { |
| 439 | throw new Error(`Invalid block type: ${block.type}`) |
| 440 | } |
| 441 | |
| 442 | const params: Record<string, any> = {} |
| 443 | const legacyAdvancedMode = block.advancedMode ?? false |
| 444 | const canonicalModeOverrides = block.data?.canonicalModes |
| 445 | const isStarterBlock = block.type === 'starter' |
| 446 | const isAgentBlock = block.type === 'agent' |
| 447 | const isTriggerContext = block.triggerMode ?? false |
| 448 | const isTriggerCategory = blockConfig.category === 'triggers' |
| 449 | const canonicalIndex = buildCanonicalIndex(blockConfig.subBlocks) |
| 450 | const allValues = buildSubBlockValues(block.subBlocks) |
| 451 | |
| 452 | Object.entries(block.subBlocks).forEach(([id, subBlock]) => { |
| 453 | const matchingConfigs = blockConfig.subBlocks.filter((config) => config.id === id) |
| 454 | |
| 455 | const hasStarterInputFormatValues = |
| 456 | isStarterBlock && |
| 457 | id === 'inputFormat' && |
| 458 | Array.isArray(subBlock.value) && |
| 459 | subBlock.value.length > 0 |
| 460 | |
| 461 | const isLegacyAgentField = |
| 462 | isAgentBlock && ['systemPrompt', 'userPrompt', 'memories'].includes(id) |
| 463 | |
| 464 | const shouldInclude = |
| 465 | matchingConfigs.length === 0 || |
| 466 | matchingConfigs.some((config) => |
| 467 | shouldSerializeSubBlock( |
| 468 | config, |
| 469 | allValues, |
| 470 | legacyAdvancedMode, |
| 471 | isTriggerContext, |
| 472 | isTriggerCategory, |
| 473 | canonicalIndex, |
| 474 | canonicalModeOverrides |
| 475 | ) |
| 476 | ) |
| 477 | |
| 478 | if ( |
| 479 | (matchingConfigs.length > 0 && shouldInclude) || |
| 480 | hasStarterInputFormatValues || |
| 481 | isLegacyAgentField |
| 482 | ) { |
| 483 | params[id] = subBlock.value |
| 484 | } |
| 485 | }) |
| 486 | |
| 487 | blockConfig.subBlocks.forEach((subBlockConfig) => { |
| 488 | const id = subBlockConfig.id |
| 489 | if ( |
no test coverage detected