MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / archiveBridgeSession

Function archiveBridgeSession

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

Source from the content-addressed store, hash-verified

269 * cleanup; call sites wrap with .catch().
270 */
271export async function archiveBridgeSession(
272 sessionId: string,
273 opts?: {
274 baseUrl?: string
275 getAccessToken?: () => string | undefined
276 timeoutMs?: number
277 },
278): Promise<void> {
279 const { getClaudeAIOAuthTokens } = await import('../utils/auth.js')
280 const { getOrganizationUUID } = await import('../services/oauth/client.js')
281 const { getOauthConfig } = await import('../constants/oauth.js')
282 const { getOAuthHeaders } = await import('../utils/teleport/api.js')
283 const { default: axios } = await import('axios')
284 const { isSelfHostedBridge } = await import('./bridgeConfig.js')
285
286 const accessToken =
287 opts?.getAccessToken?.() ?? getClaudeAIOAuthTokens()?.accessToken
288 if (!accessToken) {
289 logForDebugging('[bridge] No access token for session archive')
290 return
291 }
292
293 const orgUUID = isSelfHostedBridge()
294 ? 'self-hosted'
295 : await getOrganizationUUID()
296 if (!orgUUID) {
297 logForDebugging('[bridge] No org UUID for session archive')
298 return
299 }
300
301 const headers = {
302 ...getOAuthHeaders(accessToken),
303 'anthropic-beta': 'ccr-byoc-2025-07-29',
304 'x-organization-uuid': orgUUID,
305 }
306
307 const url = `${opts?.baseUrl ?? getOauthConfig().BASE_API_URL}/v1/sessions/${sessionId}/archive`
308 logForDebugging(`[bridge] Archiving session ${sessionId}`)
309
310 const response = await axios.post(
311 url,
312 {},
313 {
314 headers,
315 timeout: opts?.timeoutMs ?? 10_000,
316 validateStatus: s => s < 500,
317 },
318 )
319
320 if (response.status === 200) {
321 logForDebugging(`[bridge] Session ${sessionId} archived successfully`)
322 } else {
323 const detail = extractErrorDetail(response.data)
324 logForDebugging(
325 `[bridge] Session archive failed with status ${response.status}${detail ? `: ${detail}` : ''}`,
326 )
327 }
328}

Callers 1

initReplBridgeFunction · 0.85

Calls 6

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

Tested by

no test coverage detected