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

Function writeMessages

src/bridge/remoteBridgeCore.ts:753–798  ·  view source on GitHub ↗
(messages)

Source from the content-addressed store, hash-verified

751 environmentId: '',
752 sessionIngressUrl: credentials.api_base_url,
753 writeMessages(messages) {
754 const filtered = messages.filter(
755 m =>
756 isEligibleBridgeMessage(m) &&
757 !initialMessageUUIDs.has(m.uuid) &&
758 !recentPostedUUIDs.has(m.uuid),
759 )
760 if (filtered.length === 0) return
761
762 // Fire onUserMessage for title derivation. Scan before the flushGate
763 // check — prompts are title-worthy even if they queue. Keeps calling
764 // on every title-worthy message until the callback returns true; the
765 // caller owns the policy (derive at 1st and 3rd, skip if explicit).
766 if (!userMessageCallbackDone) {
767 for (const m of filtered) {
768 const text = extractTitleText(m)
769 if (text !== undefined && onUserMessage?.(text, sessionId)) {
770 userMessageCallbackDone = true
771 break
772 }
773 }
774 }
775
776 if (flushGate.enqueue(...filtered)) {
777 logForDebugging(
778 `[remote-bridge] Queued ${filtered.length} message(s) during flush`,
779 )
780 return
781 }
782
783 for (const msg of filtered) recentPostedUUIDs.add(msg.uuid)
784 const events = toSDKMessages(filtered).map(m => ({
785 ...m,
786 session_id: sessionId,
787 }))
788 // v2 does not derive worker_status from events server-side (unlike v1
789 // session-ingress session_status_updater.go). Push it from here so the
790 // CCR web session list shows Running instead of stuck on Idle. A user
791 // message in the batch marks turn start. CCRClient.reportState dedupes
792 // consecutive same-state pushes.
793 if (filtered.some(m => m.type === 'user')) {
794 transport.reportState('running')
795 }
796 logForDebugging(`[remote-bridge] Sending ${filtered.length} message(s)`)
797 void transport.writeBatch(events)
798 },
799 writeSdkMessages(messages: SDKMessage[]) {
800 const filtered = messages.filter(
801 m => !m.uuid || !recentPostedUUIDs.has(m.uuid),

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected