( ctx: ExecutionContext, currentNodeId?: string )
| 58 | } |
| 59 | |
| 60 | export function collectBlockData( |
| 61 | ctx: ExecutionContext, |
| 62 | currentNodeId?: string |
| 63 | ): BlockDataCollection { |
| 64 | const blockData: Record<string, unknown> = {} |
| 65 | const blockNameMapping: Record<string, string> = {} |
| 66 | const blockOutputSchemas: Record<string, OutputSchema> = {} |
| 67 | |
| 68 | const branchIndex = |
| 69 | currentNodeId && isBranchNodeId(currentNodeId) ? extractBranchIndex(currentNodeId) : null |
| 70 | |
| 71 | for (const [id, state] of ctx.blockStates.entries()) { |
| 72 | if (state.output !== undefined) { |
| 73 | blockData[id] = state.output |
| 74 | |
| 75 | if (branchIndex !== null && isBranchNodeId(id)) { |
| 76 | const stateBranchIndex = extractBranchIndex(id) |
| 77 | if (stateBranchIndex === branchIndex) { |
| 78 | const baseId = extractBaseBlockId(id) |
| 79 | if (blockData[baseId] === undefined) { |
| 80 | blockData[baseId] = state.output |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | const workflowBlocks = ctx.workflow?.blocks ?? [] |
| 88 | for (const block of workflowBlocks) { |
| 89 | const id = block.id |
| 90 | |
| 91 | if (block.metadata?.name) { |
| 92 | blockNameMapping[normalizeName(block.metadata.name)] = id |
| 93 | } |
| 94 | |
| 95 | const schema = getBlockSchema(block) |
| 96 | if (schema && Object.keys(schema).length > 0) { |
| 97 | blockOutputSchemas[id] = schema |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return { blockData, blockNameMapping, blockOutputSchemas } |
| 102 | } |
no test coverage detected