MCPcopy Create free account
hub / github.com/Noumena-Network/code / writeMessages

Function writeMessages

src/bridge/replBridge.ts:1711–1773  ·  view source on GitHub ↗
(messages)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 9

isEligibleBridgeMessageFunction · 0.85
extractTitleTextFunction · 0.85
onUserMessageFunction · 0.85
toSDKMessagesFunction · 0.85
writeBatchMethod · 0.80
logForDebuggingFunction · 0.50
hasMethod · 0.45
enqueueMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected