MCPcopy Create free account
hub / github.com/block/buzz / upsertTool

Function upsertTool

desktop/src/features/agents/ui/agentSessionTranscript.ts:605–696  ·  view source on GitHub ↗
(
  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,
)

Source from the content-addressed store, hash-verified

603}
604
605function 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,

Callers 1

processTranscriptEventFunction · 0.85

Calls 10

findBuzzToolNameFunction · 0.90
isGenericToolTitleFunction · 0.90
classifyToolFunction · 0.90
mergeToolStatusFunction · 0.85
replaceItemFunction · 0.85
isTerminalToolStatusFunction · 0.85
sealOpenMessagesFunction · 0.85
pushItemFunction · 0.85
keysMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected