()
| 605 | |
| 606 | // ── 8. History flush + drain helpers ──────────────────────────────────── |
| 607 | function drainFlushGate(): void { |
| 608 | const msgs = flushGate.end() |
| 609 | if (msgs.length === 0) return |
| 610 | for (const msg of msgs) recentPostedUUIDs.add(msg.uuid) |
| 611 | const events = toSDKMessages(msgs).map(m => ({ |
| 612 | ...m, |
| 613 | session_id: sessionId, |
| 614 | })) |
| 615 | if (msgs.some(m => m.type === 'user')) { |
| 616 | transport.reportState('running') |
| 617 | } |
| 618 | logForDebugging( |
| 619 | `[remote-bridge] Drained ${msgs.length} queued message(s) after flush`, |
| 620 | ) |
| 621 | void transport.writeBatch(events) |
| 622 | } |
| 623 | |
| 624 | async function flushHistory(msgs: Message[]): Promise<void> { |
| 625 | // v2 always creates a fresh server session (unconditional createCodeSession |
no test coverage detected