| 580 | // buffered text parts that were waiting on role confirmation. User-role |
| 581 | // parts are silently dropped. |
| 582 | function replay(data: SessionData, commits: SessionCommit[], messageID: string, role: MessageRole, thinking: boolean) { |
| 583 | for (const [partID, msg] of data.msg.entries()) { |
| 584 | if (msg !== messageID || data.ids.has(partID)) { |
| 585 | continue |
| 586 | } |
| 587 | |
| 588 | if (role === "user" && !data.includeUserText) { |
| 589 | data.ids.add(partID) |
| 590 | drop(data, partID) |
| 591 | continue |
| 592 | } |
| 593 | |
| 594 | const kind = data.part.get(partID) |
| 595 | if (!kind) { |
| 596 | continue |
| 597 | } |
| 598 | |
| 599 | if (role === "user" && kind === "assistant") { |
| 600 | data.part.set(partID, "user") |
| 601 | } |
| 602 | |
| 603 | if (kind === "reasoning" && !thinking) { |
| 604 | if (data.end.has(partID)) { |
| 605 | data.ids.add(partID) |
| 606 | } |
| 607 | drop(data, partID) |
| 608 | continue |
| 609 | } |
| 610 | |
| 611 | flushPart(data, commits, partID) |
| 612 | |
| 613 | if (!data.end.has(partID)) { |
| 614 | continue |
| 615 | } |
| 616 | |
| 617 | data.ids.add(partID) |
| 618 | drop(data, partID) |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | function toolCommit( |
| 623 | part: ToolPart, |