(
sessionId: string,
title: string,
opts?: { baseUrl?: string; getAccessToken?: () => string | undefined },
)
| 325 | * Errors are swallowed — title sync is best-effort. |
| 326 | */ |
| 327 | export async function updateBridgeSessionTitle( |
| 328 | sessionId: string, |
| 329 | title: string, |
| 330 | opts?: { baseUrl?: string; getAccessToken?: () => string | undefined }, |
| 331 | ): Promise<void> { |
| 332 | const { getClaudeAIOAuthTokens } = await import('../utils/auth.js') |
| 333 | const { getOrganizationUUID } = await import('../services/oauth/client.js') |
| 334 | const { getOauthConfig } = await import('../constants/oauth.js') |
| 335 | const { getOAuthHeaders } = await import('../utils/teleport/api.js') |
| 336 | const { default: axios } = await import('axios') |
| 337 | |
| 338 | const accessToken = |
| 339 | opts?.getAccessToken?.() ?? getClaudeAIOAuthTokens()?.accessToken |
| 340 | if (!accessToken) { |
| 341 | logForDebugging('[bridge] No access token for session title update') |
| 342 | return |
| 343 | } |
| 344 | |
| 345 | const orgUUID = await getOrganizationUUID() |
| 346 | if (!orgUUID) { |
| 347 | logForDebugging('[bridge] No org UUID for session title update') |
| 348 | return |
| 349 | } |
| 350 | |
| 351 | const headers = { |
| 352 | ...getOAuthHeaders(accessToken), |
| 353 | 'anthropic-beta': 'ccr-byoc-2025-07-29', |
| 354 | 'x-organization-uuid': orgUUID, |
| 355 | } |
| 356 | |
| 357 | // Compat gateway only accepts session_* (compat/convert.go:27). v2 callers |
| 358 | // pass raw cse_*; retag here so all callers can pass whatever they hold. |
| 359 | // Idempotent for v1's session_* and bridgeMain's pre-converted compatSessionId. |
| 360 | const compatId = toCompatSessionId(sessionId) |
| 361 | const url = `${opts?.baseUrl ?? getOauthConfig().BASE_API_URL}/v1/sessions/${compatId}` |
| 362 | logForDebugging(`[bridge] Updating session title: ${compatId} → ${title}`) |
| 363 | |
| 364 | try { |
| 365 | const response = await axios.patch( |
| 366 | url, |
| 367 | { title }, |
| 368 | { headers, timeout: 10_000, validateStatus: s => s < 500 }, |
| 369 | ) |
| 370 | |
| 371 | if (response.status === 200) { |
| 372 | logForDebugging(`[bridge] Session title updated successfully`) |
| 373 | } else { |
| 374 | const detail = extractErrorDetail(response.data) |
| 375 | logForDebugging( |
| 376 | `[bridge] Session title update failed with status ${response.status}${detail ? `: ${detail}` : ''}`, |
| 377 | ) |
| 378 | } |
| 379 | } catch (err: unknown) { |
| 380 | logForDebugging( |
| 381 | `[bridge] Session title update request failed: ${errorMessage(err)}`, |
| 382 | ) |
| 383 | } |
| 384 | } |
no test coverage detected