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

Function initEnvLessBridgeCore

src/bridge/remoteBridgeCore.ts:139–873  ·  view source on GitHub ↗
(
  params: EnvLessBridgeParams,
)

Source from the content-addressed store, hash-verified

137 * as a generic "initialization failed" state.
138 */
139export async function initEnvLessBridgeCore(
140 params: EnvLessBridgeParams,
141): Promise<ReplBridgeHandle | null> {
142 const {
143 baseUrl,
144 runtimeAuth,
145 title,
146 toSDKMessages,
147 initialHistoryCap,
148 initialMessages,
149 onInboundMessage,
150 onUserMessage,
151 onPermissionResponse,
152 onInterrupt,
153 onSetModel,
154 onSetMaxThinkingTokens,
155 onSetPermissionMode,
156 onStateChange,
157 outboundOnly,
158 tags,
159 } = params
160
161 const cfg = await getEnvLessBridgeConfig()
162
163 // ── 1. Create session (POST /v1/code/sessions, no env_id) ───────────────
164 const accessToken = runtimeAuth.getAccessToken()
165 if (!accessToken) {
166 logForDebugging('[remote-bridge] No OAuth token')
167 return null
168 }
169
170 const createdSessionId = await withRetry(
171 () =>
172 createCodeSession(baseUrl, accessToken, title, cfg.http_timeout_ms, tags),
173 'createCodeSession',
174 cfg,
175 )
176 if (!createdSessionId) {
177 onStateChange?.('failed', 'Session creation failed — see debug log')
178 logBridgeSkip('v2_session_create_failed', undefined, true)
179 return null
180 }
181 const sessionId: string = createdSessionId
182 logForDebugging(`[remote-bridge] Created session ${sessionId}`)
183 logForDiagnosticsNoPII('info', 'bridge_repl_v2_session_created')
184
185 // ── 2. Fetch bridge credentials (POST /bridge → worker_jwt, expires_in, api_base_url) ──
186 const credentials = await withRetry(
187 () =>
188 fetchRemoteCredentials(
189 sessionId,
190 baseUrl,
191 accessToken,
192 cfg.http_timeout_ms,
193 ),
194 'fetchRemoteCredentials',
195 cfg,
196 )

Callers 1

initReplBridgeFunction · 0.85

Calls 15

addMethod · 0.95
startMethod · 0.95
getEnvLessBridgeConfigFunction · 0.85
createCodeSessionFunction · 0.85
onStateChangeFunction · 0.85
logBridgeSkipFunction · 0.85
logForDiagnosticsNoPIIFunction · 0.85
buildCCRv2SdkUrlFunction · 0.85
createV2ReplTransportFunction · 0.85
rebuildTransportFunction · 0.85
wireTransportCallbacksFunction · 0.85

Tested by

no test coverage detected