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

Function initBridgeCore

src/bridge/replBridge.ts:268–1856  ·  view source on GitHub ↗
(
  params: BridgeCoreParams,
)

Source from the content-addressed store, hash-verified

266 * Returns null on registration or session-creation failure.
267 */
268export async function initBridgeCore(
269 params: BridgeCoreParams,
270): Promise<BridgeCoreHandle | null> {
271 const {
272 dir,
273 machineName,
274 branch,
275 gitRepoUrl,
276 title,
277 baseUrl,
278 sessionIngressUrl,
279 workerType,
280 runtimeAuth,
281 getAccessToken,
282 createSession,
283 archiveSession,
284 getCurrentTitle = () => title,
285 toSDKMessages = () => {
286 throw new Error(
287 'BridgeCoreParams.toSDKMessages not provided. Pass it if you use writeMessages() or initialMessages — daemon callers that only use writeSdkMessages() never hit this path.',
288 )
289 },
290 onAuth401,
291 getPollIntervalConfig = () => DEFAULT_POLL_CONFIG,
292 initialHistoryCap = 200,
293 initialMessages,
294 previouslyFlushedUUIDs,
295 onInboundMessage,
296 onPermissionResponse,
297 onInterrupt,
298 onSetModel,
299 onSetMaxThinkingTokens,
300 onSetPermissionMode,
301 onStateChange,
302 onUserMessage,
303 perpetual,
304 initialSSESequenceNum = 0,
305 } = params
306
307 const seq = ++initSequence
308
309 // bridgePointer import hoisted: perpetual mode reads it before register;
310 // non-perpetual writes it after session create; both use clear at teardown.
311 const { writeBridgePointer, clearBridgePointer, readBridgePointer } =
312 await import('./bridgePointer.js')
313
314 // Perpetual mode: read the crash-recovery pointer and treat it as prior
315 // state. The pointer is written unconditionally after session create
316 // (crash-recovery for all sessions); perpetual mode just skips the
317 // teardown clear so it survives clean exits too. Only reuse 'repl'
318 // pointers — a crashed standalone bridge (`ncode remote-control`)
319 // writes source:'standalone' with a different workerType.
320 const rawPrior = perpetual ? await readBridgePointer(dir) : null
321 const prior = rawPrior?.source === 'repl' ? rawPrior : null
322
323 logForDebugging(
324 `[bridge:repl] initBridgeCore #${seq} starting (initialMessages=${initialMessages?.length ?? 0}${prior ? ` perpetual prior=env:${prior.environmentId}` : ''})`,
325 )

Callers 1

initReplBridgeFunction · 0.85

Calls 15

addMethod · 0.95
dropMethod · 0.95
deactivateMethod · 0.95
randomUUIDFunction · 0.90
isEnvTruthyFunction · 0.90
readBridgePointerFunction · 0.85
createBridgeApiClientFunction · 0.85
isInternalBuildFunction · 0.85
wrapApiForFaultInjectionFunction · 0.85
logBridgeSkipFunction · 0.85
clearBridgePointerFunction · 0.85
onStateChangeFunction · 0.85

Tested by

no test coverage detected