( sessionId: string, )
| 287 | * @returns The session resource |
| 288 | */ |
| 289 | export async function fetchSession( |
| 290 | sessionId: string, |
| 291 | ): Promise<SessionResource> { |
| 292 | const { accessToken, orgUUID } = await prepareApiRequest() |
| 293 | |
| 294 | const url = `${getOauthConfig().BASE_API_URL}/v1/sessions/${sessionId}` |
| 295 | const headers = { |
| 296 | ...getOAuthHeaders(accessToken), |
| 297 | 'anthropic-beta': 'ccr-byoc-2025-07-29', |
| 298 | 'x-organization-uuid': orgUUID, |
| 299 | } |
| 300 | |
| 301 | const response = await axios.get<SessionResource>(url, { |
| 302 | headers, |
| 303 | timeout: 15000, |
| 304 | validateStatus: status => status < 500, |
| 305 | }) |
| 306 | |
| 307 | if (response.status !== 200) { |
| 308 | // Extract error message from response if available |
| 309 | const errorData = response.data as { error?: { message?: string } } |
| 310 | const apiMessage = errorData?.error?.message |
| 311 | |
| 312 | if (response.status === 404) { |
| 313 | throw new Error(`Session not found: ${sessionId}`) |
| 314 | } |
| 315 | |
| 316 | if (response.status === 401) { |
| 317 | throw new Error('Session expired. Please run /login to sign in again.') |
| 318 | } |
| 319 | |
| 320 | throw new Error( |
| 321 | apiMessage || |
| 322 | `Failed to fetch session: ${response.status} ${response.statusText}`, |
| 323 | ) |
| 324 | } |
| 325 | |
| 326 | return response.data |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * Extracts the first branch name from a session's git repository outcomes |
no test coverage detected