()
| 280 | * @returns Array of code sessions |
| 281 | */ |
| 282 | export async function fetchCodeSessionsFromSessionsAPI(): Promise< |
| 283 | CodeSession[] |
| 284 | > { |
| 285 | const { accessToken, orgUUID } = await prepareApiRequest() |
| 286 | |
| 287 | const url = `${getOauthConfig().BASE_API_URL}/v1/sessions` |
| 288 | |
| 289 | try { |
| 290 | const headers = { |
| 291 | ...getOAuthHeaders(accessToken), |
| 292 | 'anthropic-beta': 'ccr-byoc-2025-07-29', |
| 293 | 'x-organization-uuid': orgUUID, |
| 294 | } |
| 295 | |
| 296 | const response = await axiosGetWithRetry<ListSessionsResponse>(url, { |
| 297 | headers, |
| 298 | }) |
| 299 | |
| 300 | if (response.status !== 200) { |
| 301 | throw new Error(`Failed to fetch code sessions: ${response.statusText}`) |
| 302 | } |
| 303 | |
| 304 | // Transform SessionResource[] to CodeSession[] format |
| 305 | const sessions: CodeSession[] = response.data.data.map(session => { |
| 306 | // Extract repository info from git sources |
| 307 | const gitSource = session.session_context.sources.find( |
| 308 | (source): source is GitSource => source.type === 'git_repository', |
| 309 | ) |
| 310 | |
| 311 | let repo: CodeSession['repo'] = null |
| 312 | if (gitSource?.url) { |
| 313 | // Parse GitHub URL using the existing utility function |
| 314 | const repoPath = parseGitHubRepository(gitSource.url) |
| 315 | if (repoPath) { |
| 316 | const [owner, name] = repoPath.split('/') |
| 317 | if (owner && name) { |
| 318 | repo = { |
| 319 | name, |
| 320 | owner: { |
| 321 | login: owner, |
| 322 | }, |
| 323 | default_branch: gitSource.revision || undefined, |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | return { |
| 330 | id: session.id, |
| 331 | title: session.title || 'Untitled', |
| 332 | description: '', // SessionResource doesn't have description field |
| 333 | status: session.session_status as CodeSession['status'], // Map session_status to status |
| 334 | repo, |
| 335 | turns: [], // SessionResource doesn't have turns field |
| 336 | created_at: session.created_at, |
| 337 | updated_at: session.updated_at, |
| 338 | } |
| 339 | }) |
no test coverage detected