MCPcopy
hub / github.com/claude-code-best/claude-code / initEnvLessBridgeCore

Function initEnvLessBridgeCore

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

Source from the content-addressed store, hash-verified

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

Callers 1

initReplBridgeFunction · 0.85

Calls 15

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

Tested by

no test coverage detected