( d: TranscriptDraft, id: string, role: "assistant" | "user", title: string, text: string, timestamp: string, ctx: TranscriptItemContext, authorPubkey: string | null = null, acpSource?: string, messageId: string | null = null, )
| 282 | }; |
| 283 | |
| 284 | function upsertMessage( |
| 285 | d: TranscriptDraft, |
| 286 | id: string, |
| 287 | role: "assistant" | "user", |
| 288 | title: string, |
| 289 | text: string, |
| 290 | timestamp: string, |
| 291 | ctx: TranscriptItemContext, |
| 292 | authorPubkey: string | null = null, |
| 293 | acpSource?: string, |
| 294 | messageId: string | null = null, |
| 295 | ) { |
| 296 | const currentKey = d.activeMessageKey.get(id); |
| 297 | |
| 298 | if (currentKey && !d.sealedKeys.has(currentKey)) { |
| 299 | const existing = d.itemsById.get(currentKey); |
| 300 | if (existing?.type === "message") { |
| 301 | replaceItem(d, currentKey, { |
| 302 | ...existing, |
| 303 | text: existing.text + text, |
| 304 | channelId: ctx.channelId, |
| 305 | turnId: ctx.turnId ?? existing.turnId, |
| 306 | sessionId: ctx.sessionId ?? existing.sessionId, |
| 307 | authorPubkey: authorPubkey ?? existing.authorPubkey, |
| 308 | acpSource: acpSource ?? existing.acpSource, |
| 309 | messageId: messageId ?? existing.messageId, |
| 310 | }); |
| 311 | return; |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | d.continuationSeq += 1; |
| 316 | const newKey = currentKey ? `${id}:c${d.continuationSeq}` : id; |
| 317 | pushItem(d, { |
| 318 | id: newKey, |
| 319 | type: "message", |
| 320 | renderClass: "message", |
| 321 | role, |
| 322 | title, |
| 323 | text, |
| 324 | timestamp, |
| 325 | messageId, |
| 326 | channelId: ctx.channelId, |
| 327 | turnId: ctx.turnId, |
| 328 | sessionId: ctx.sessionId, |
| 329 | authorPubkey, |
| 330 | acpSource, |
| 331 | }); |
| 332 | d.activeMessageKey = new Map(d.activeMessageKey); |
| 333 | d.activeMessageKey.set(id, newKey); |
| 334 | } |
| 335 | |
| 336 | function upsertTextItem( |
| 337 | d: TranscriptDraft, |
no test coverage detected