(data: SessionData, current: SessionData)
| 327 | } |
| 328 | |
| 329 | export function replayActiveText(data: SessionData, current: SessionData): StreamCommit[] { |
| 330 | return [...current.part.entries()].flatMap(([partID, kind]) => { |
| 331 | if (kind === "user" || current.end.has(partID) || data.ids.has(partID)) { |
| 332 | return [] |
| 333 | } |
| 334 | |
| 335 | const text = current.text.get(partID) ?? "" |
| 336 | const existing = data.text.get(partID) ?? "" |
| 337 | const sent = current.sent.get(partID) ?? 0 |
| 338 | const existingSent = data.sent.get(partID) ?? 0 |
| 339 | const visible = current.visible.get(partID) ?? "" |
| 340 | const existingVisible = data.visible.get(partID) ?? "" |
| 341 | if (!text.startsWith(existing) || existingSent > sent || !visible.startsWith(existingVisible)) { |
| 342 | return [] |
| 343 | } |
| 344 | |
| 345 | data.part.set(partID, kind) |
| 346 | data.text.set(partID, text) |
| 347 | data.sent.set(partID, sent) |
| 348 | data.visible.set(partID, visible) |
| 349 | const messageID = current.msg.get(partID) |
| 350 | if (messageID) { |
| 351 | data.msg.set(partID, messageID) |
| 352 | const role = current.role.get(messageID) |
| 353 | if (role) { |
| 354 | data.role.set(messageID, role) |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | const chunk = visible.slice(existingVisible.length) |
| 359 | if (!chunk) { |
| 360 | return [] |
| 361 | } |
| 362 | |
| 363 | return [ |
| 364 | { |
| 365 | kind, |
| 366 | text: chunk, |
| 367 | phase: "progress", |
| 368 | source: kind, |
| 369 | ...(messageID ? { messageID } : {}), |
| 370 | partID, |
| 371 | }, |
| 372 | ] satisfies StreamCommit[] |
| 373 | }) |
| 374 | } |
no test coverage detected