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

Function getBridgeSession

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

Source from the content-addressed store, hash-verified

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

Callers 2

fetchSessionTitleFunction · 0.85
bridgeMainFunction · 0.85

Calls 6

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

Tested by

no test coverage detected