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

Function wireTransportCallbacks

src/bridge/remoteBridgeCore.ts:373–459  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

371
372 // ── 6. Wire callbacks (extracted so transport-rebuild can re-wire) ──────
373 function wireTransportCallbacks(): void {
374 transport.setOnConnect(() => {
375 clearTimeout(connectDeadline)
376 logForDebugging('[remote-bridge] v2 transport connected')
377 logForDiagnosticsNoPII('info', 'bridge_repl_v2_transport_connected')
378 logEvent('ncode_bridge_repl_ws_connected', {
379 v2: true,
380 cause:
381 connectCause as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
382 })
383
384 if (!initialFlushDone && initialMessages && initialMessages.length > 0) {
385 initialFlushDone = true
386 // Capture current transport — if 401/teardown happens mid-flush,
387 // the stale .finally() must not drain the gate or signal connected.
388 // (Same guard pattern as replBridge.ts:1119.)
389 const flushTransport = transport
390 void flushHistory(initialMessages)
391 .catch(e =>
392 logForDebugging(`[remote-bridge] flushHistory failed: ${e}`),
393 )
394 .finally(() => {
395 // authRecoveryInFlight catches the v1-vs-v2 asymmetry: v1 nulls
396 // transport synchronously in setOnClose (replBridge.ts:1175), so
397 // transport !== flushTransport trips immediately. v2 doesn't null —
398 // transport reassigned only at rebuildTransport:346, 3 awaits deep.
399 // authRecoveryInFlight is set synchronously at rebuildTransport entry.
400 if (
401 transport !== flushTransport ||
402 tornDown ||
403 authRecoveryInFlight
404 ) {
405 return
406 }
407 drainFlushGate()
408 onStateChange?.('connected')
409 })
410 } else if (!flushGate.active) {
411 onStateChange?.('connected')
412 }
413 })
414
415 transport.setOnData((data: string) => {
416 handleIngressMessage(
417 data,
418 recentPostedUUIDs,
419 recentInboundUUIDs,
420 onInboundMessage,
421 // Remote client answered the permission prompt — the turn resumes.
422 // Without this the server stays on requires_action until the next
423 // user message or turn-end result.
424 onPermissionResponse
425 ? res => {
426 transport.reportState('running')
427 onPermissionResponse(res)
428 }
429 : undefined,
430 req =>

Callers 2

rebuildTransportFunction · 0.85
initEnvLessBridgeCoreFunction · 0.85

Calls 14

logForDiagnosticsNoPIIFunction · 0.85
flushHistoryFunction · 0.85
onStateChangeFunction · 0.85
handleIngressMessageFunction · 0.85
onPermissionResponseFunction · 0.85
recoverFromAuthFailureFunction · 0.85
setOnConnectMethod · 0.80
reportStateMethod · 0.80
logEventFunction · 0.70
drainFlushGateFunction · 0.70
logForDebuggingFunction · 0.50

Tested by

no test coverage detected