( d: TranscriptDraft, id: string, title: string, toolName: string, buzzToolName: string | null, status: ToolStatus, args: Record<string, unknown>, result: string, isError: boolean, timestamp: string, ctx: TranscriptItemContext, acpSource?: string, )
| 603 | } |
| 604 | |
| 605 | function upsertTool( |
| 606 | d: TranscriptDraft, |
| 607 | id: string, |
| 608 | title: string, |
| 609 | toolName: string, |
| 610 | buzzToolName: string | null, |
| 611 | status: ToolStatus, |
| 612 | args: Record<string, unknown>, |
| 613 | result: string, |
| 614 | isError: boolean, |
| 615 | timestamp: string, |
| 616 | ctx: TranscriptItemContext, |
| 617 | acpSource?: string, |
| 618 | ) { |
| 619 | const existing = d.itemsById.get(id); |
| 620 | const canonicalBuzzToolName = |
| 621 | buzzToolName ?? findBuzzToolName(toolName, true); |
| 622 | if (existing?.type === "tool") { |
| 623 | const updatedTitle = !isGenericToolTitle(title) ? title : existing.title; |
| 624 | let updatedToolName = existing.toolName; |
| 625 | let updatedBuzzToolName = existing.buzzToolName; |
| 626 | if (canonicalBuzzToolName) { |
| 627 | updatedBuzzToolName = canonicalBuzzToolName; |
| 628 | updatedToolName = canonicalBuzzToolName; |
| 629 | } else if (!existing.buzzToolName && !isGenericToolTitle(toolName)) { |
| 630 | updatedToolName = toolName; |
| 631 | } |
| 632 | const mergedStatus = mergeToolStatus(existing.status, status); |
| 633 | const updatedArgs = Object.keys(args).length > 0 ? args : existing.args; |
| 634 | const updatedResult = result || existing.result; |
| 635 | const updatedIsError = isError || existing.isError; |
| 636 | const descriptor = classifyTool({ |
| 637 | title: updatedTitle, |
| 638 | toolName: updatedToolName, |
| 639 | buzzToolName: updatedBuzzToolName, |
| 640 | args: updatedArgs, |
| 641 | result: updatedResult, |
| 642 | isError: updatedIsError || mergedStatus === "failed", |
| 643 | }); |
| 644 | replaceItem(d, id, { |
| 645 | ...existing, |
| 646 | renderClass: descriptor.renderClass, |
| 647 | descriptor, |
| 648 | title: updatedTitle, |
| 649 | toolName: updatedToolName, |
| 650 | buzzToolName: updatedBuzzToolName, |
| 651 | status: mergedStatus, |
| 652 | args: updatedArgs, |
| 653 | result: updatedResult, |
| 654 | isError: updatedIsError, |
| 655 | completedAt: |
| 656 | isTerminalToolStatus(mergedStatus) && existing.completedAt == null |
| 657 | ? timestamp |
| 658 | : existing.completedAt, |
| 659 | channelId: ctx.channelId, |
| 660 | turnId: ctx.turnId ?? existing.turnId, |
| 661 | sessionId: ctx.sessionId ?? existing.sessionId, |
| 662 | acpSource: acpSource ?? existing.acpSource, |
no test coverage detected