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

Function upsertTextItem

desktop/src/features/agents/ui/agentSessionTranscript.ts:336–388  ·  view source on GitHub ↗
(
  d: TranscriptDraft,
  id: string,
  type: "thought" | "lifecycle",
  title: string,
  text: string,
  timestamp: string,
  ctx: TranscriptItemContext,
  acpSource?: string,
)

Source from the content-addressed store, hash-verified

334}
335
336function upsertTextItem(
337 d: TranscriptDraft,
338 id: string,
339 type: "thought" | "lifecycle",
340 title: string,
341 text: string,
342 timestamp: string,
343 ctx: TranscriptItemContext,
344 acpSource?: string,
345) {
346 const existing = d.itemsById.get(id);
347 if (existing && existing.type === type) {
348 replaceItem(d, id, {
349 ...existing,
350 text:
351 type === "lifecycle"
352 ? joinLifecycleText(existing.text, text)
353 : existing.text + text,
354 channelId: ctx.channelId,
355 turnId: ctx.turnId ?? existing.turnId,
356 sessionId: ctx.sessionId ?? existing.sessionId,
357 acpSource: acpSource ?? existing.acpSource,
358 });
359 return;
360 }
361 sealOpenMessages(d);
362 if (type === "thought") {
363 pushItem(d, {
364 id,
365 type: "thought",
366 renderClass: "thought",
367 title,
368 text,
369 timestamp,
370 channelId: ctx.channelId,
371 turnId: ctx.turnId,
372 sessionId: ctx.sessionId,
373 acpSource,
374 });
375 return;
376 }
377
378 upsertLifecycleItem(
379 d,
380 id,
381 title.toLowerCase().includes("error") ? "error" : "status",
382 title,
383 text,
384 timestamp,
385 ctx,
386 acpSource,
387 );
388}
389
390function joinLifecycleText(existing: string, next: string) {
391 if (!existing) return next;

Callers 1

processTranscriptEventFunction · 0.85

Calls 6

replaceItemFunction · 0.85
joinLifecycleTextFunction · 0.85
sealOpenMessagesFunction · 0.85
pushItemFunction · 0.85
upsertLifecycleItemFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected