(toolIndex: number, id?: string, name?: string)
| 533 | } |
| 534 | |
| 535 | const getToolBlock = (toolIndex: number, id?: string, name?: string) => { |
| 536 | const existing = openBlocks.find( |
| 537 | block => block.kind === 'tool_use' && block.sourceIndex === toolIndex, |
| 538 | ) |
| 539 | if (existing && existing.kind === 'tool_use') { |
| 540 | if (name) existing.name = name |
| 541 | if (id) existing.id = id |
| 542 | return existing |
| 543 | } |
| 544 | const created: OpenBlock = { |
| 545 | kind: 'tool_use', |
| 546 | index: nextIndex++, |
| 547 | sourceIndex: toolIndex, |
| 548 | id: id ?? `toolu_${Math.random().toString(36).slice(2, 10)}`, |
| 549 | name: name ?? '', |
| 550 | closed: false, |
| 551 | } |
| 552 | openBlocks.push(created) |
| 553 | return created |
| 554 | } |
| 555 | |
| 556 | const closeOpenBlocks = function* () { |
| 557 | for (const block of [...openBlocks].sort((a, b) => a.index - b.index)) { |
no test coverage detected