( sessionId: string, )
| 306 | * @returns The session resource |
| 307 | */ |
| 308 | export async function fetchSession( |
| 309 | sessionId: string, |
| 310 | ): Promise<SessionResource> { |
| 311 | const { accessToken, orgUUID } = await prepareApiRequest() |
| 312 | |
| 313 | const url = buildNoumenaPlatformUrl(`/v1/sessions/${sessionId}`) |
| 314 | const headers = { |
| 315 | ...getOAuthHeaders(accessToken), |
| 316 | 'anthropic-beta': 'ccr-byoc-2025-07-29', |
| 317 | 'x-organization-uuid': orgUUID, |
| 318 | } |
| 319 | |
| 320 | const response = await axios.get<SessionResource>(url, { |
| 321 | headers, |
| 322 | timeout: 15000, |
| 323 | validateStatus: status => status < 500, |
| 324 | }) |
| 325 | |
| 326 | if (response.status !== 200) { |
| 327 | // Extract error message from response if available |
| 328 | const errorData = response.data as { error?: { message?: string } } |
| 329 | const apiMessage = errorData?.error?.message |
| 330 | |
| 331 | if (response.status === 404) { |
| 332 | throw new Error(`Session not found: ${sessionId}`) |
| 333 | } |
| 334 | |
| 335 | if (response.status === 401) { |
| 336 | throw new Error('Session expired. Please run /login to sign in again.') |
| 337 | } |
| 338 | |
| 339 | throw new Error( |
| 340 | apiMessage || |
| 341 | `Failed to fetch session: ${response.status} ${response.statusText}`, |
| 342 | ) |
| 343 | } |
| 344 | |
| 345 | return response.data |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | * Extracts the first branch name from a session's git repository outcomes |
no test coverage detected