( d: TranscriptDraft, id: string, type: "thought" | "lifecycle", title: string, text: string, timestamp: string, ctx: TranscriptItemContext, acpSource?: string, )
| 334 | } |
| 335 | |
| 336 | function 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 | |
| 390 | function joinLifecycleText(existing: string, next: string) { |
| 391 | if (!existing) return next; |
no test coverage detected