MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / getBridgeSession

Function getBridgeSession

src/bridge/createSession.ts:195–252  ·  view source on GitHub ↗
(
  sessionId: string,
  opts?: { baseUrl?: string; getAccessToken?: () => string | undefined },
)

Source from the content-addressed store, hash-verified

193 * makes the Sessions API return 404.
194 */
195export async function getBridgeSession(
196 sessionId: string,
197 opts?: { baseUrl?: string; getAccessToken?: () => string | undefined },
198): Promise<{ environment_id?: string; title?: string } | null> {
199 const { getClaudeAIOAuthTokens } = await import('../utils/auth.js')
200 const { getOrganizationUUID } = await import('../services/oauth/client.js')
201 const { getOauthConfig } = await import('../constants/oauth.js')
202 const { getOAuthHeaders } = await import('../utils/teleport/api.js')
203 const { default: axios } = await import('axios')
204 const { isSelfHostedBridge } = await import('./bridgeConfig.js')
205
206 const accessToken =
207 opts?.getAccessToken?.() ?? getClaudeAIOAuthTokens()?.accessToken
208 if (!accessToken) {
209 logForDebugging('[bridge] No access token for session fetch')
210 return null
211 }
212
213 const orgUUID = isSelfHostedBridge()
214 ? 'self-hosted'
215 : await getOrganizationUUID()
216 if (!orgUUID) {
217 logForDebugging('[bridge] No org UUID for session fetch')
218 return null
219 }
220
221 const headers = {
222 ...getOAuthHeaders(accessToken),
223 'anthropic-beta': 'ccr-byoc-2025-07-29',
224 'x-organization-uuid': orgUUID,
225 }
226
227 const url = `${opts?.baseUrl ?? getOauthConfig().BASE_API_URL}/v1/sessions/${sessionId}`
228 logForDebugging(`[bridge] Fetching session ${sessionId}`)
229
230 let response
231 try {
232 response = await axios.get<{ environment_id?: string; title?: string }>(
233 url,
234 { headers, timeout: 10_000, validateStatus: s => s < 500 },
235 )
236 } catch (err: unknown) {
237 logForDebugging(
238 `[bridge] Session fetch request failed: ${errorMessage(err)}`,
239 )
240 return null
241 }
242
243 if (response.status !== 200) {
244 const detail = extractErrorDetail(response.data)
245 logForDebugging(
246 `[bridge] Session fetch failed with status ${response.status}${detail ? `: ${detail}` : ''}`,
247 )
248 return null
249 }
250
251 return response.data
252}

Callers 2

fetchSessionTitleFunction · 0.85
bridgeMainFunction · 0.85

Calls 7

isSelfHostedBridgeFunction · 0.85
getOrganizationUUIDFunction · 0.85
getOAuthHeadersFunction · 0.85
getOauthConfigFunction · 0.85
extractErrorDetailFunction · 0.85
logForDebuggingFunction · 0.50
errorMessageFunction · 0.50

Tested by

no test coverage detected