(messages)
| 1692 | }, |
| 1693 | sessionIngressUrl, |
| 1694 | writeMessages(messages) { |
| 1695 | // Filter to user/assistant messages that haven't already been sent. |
| 1696 | // Two layers of dedup: |
| 1697 | // - initialMessageUUIDs: messages sent as session creation events |
| 1698 | // - recentPostedUUIDs: messages recently sent via POST |
| 1699 | const filtered = messages.filter( |
| 1700 | m => |
| 1701 | isEligibleBridgeMessage(m) && |
| 1702 | !initialMessageUUIDs.has(m.uuid) && |
| 1703 | !recentPostedUUIDs.has(m.uuid), |
| 1704 | ) |
| 1705 | if (filtered.length === 0) return |
| 1706 | |
| 1707 | // Fire onUserMessage for title derivation. Scan before the flushGate |
| 1708 | // check — prompts are title-worthy even if they queue behind the |
| 1709 | // initial history flush. Keeps calling on every title-worthy message |
| 1710 | // until the callback returns true; the caller owns the policy. |
| 1711 | if (!userMessageCallbackDone) { |
| 1712 | for (const m of filtered) { |
| 1713 | const text = extractTitleText(m) |
| 1714 | if (text !== undefined && onUserMessage?.(text, currentSessionId)) { |
| 1715 | userMessageCallbackDone = true |
| 1716 | break |
| 1717 | } |
| 1718 | } |
| 1719 | } |
| 1720 | |
| 1721 | // Queue messages while the initial flush is in progress to prevent |
| 1722 | // them from arriving at the server interleaved with history. |
| 1723 | if (flushGate.enqueue(...filtered)) { |
| 1724 | logForDebugging( |
| 1725 | `[bridge:repl] Queued ${filtered.length} message(s) during initial flush`, |
| 1726 | ) |
| 1727 | return |
| 1728 | } |
| 1729 | |
| 1730 | if (!transport) { |
| 1731 | const types = filtered.map(m => m.type).join(',') |
| 1732 | logForDebugging( |
| 1733 | `[bridge:repl] Transport not configured, dropping ${filtered.length} message(s) [${types}] for session=${currentSessionId}`, |
| 1734 | { level: 'warn' }, |
| 1735 | ) |
| 1736 | return |
| 1737 | } |
| 1738 | |
| 1739 | // Track in the bounded ring buffer for echo filtering and dedup. |
| 1740 | for (const msg of filtered) { |
| 1741 | recentPostedUUIDs.add(msg.uuid) |
| 1742 | } |
| 1743 | |
| 1744 | logForDebugging( |
| 1745 | `[bridge:repl] Sending ${filtered.length} message(s) via transport`, |
| 1746 | ) |
| 1747 | |
| 1748 | // Convert to SDK format and send via HTTP POST (HybridTransport). |
| 1749 | // The web UI receives them via the subscribe WebSocket. |
| 1750 | const sdkMessages = toSDKMessages(filtered) |
| 1751 | const events = sdkMessages.map(sdkMsg => ({ |
nothing calls this directly
no test coverage detected