()
| 202 | * @returns Array of code sessions |
| 203 | */ |
| 204 | export async function fetchCodeSessionsFromSessionsAPI(): Promise< |
| 205 | CodeSession[] |
| 206 | > { |
| 207 | const { accessToken, orgUUID } = await prepareApiRequest() |
| 208 | |
| 209 | const url = `${getOauthConfig().BASE_API_URL}/v1/sessions` |
| 210 | |
| 211 | try { |
| 212 | const headers = { |
| 213 | ...getOAuthHeaders(accessToken), |
| 214 | 'anthropic-beta': 'ccr-byoc-2025-07-29', |
| 215 | 'x-organization-uuid': orgUUID, |
| 216 | } |
| 217 | |
| 218 | const response = await axiosGetWithRetry<ListSessionsResponse>(url, { |
| 219 | headers, |
| 220 | }) |
| 221 | |
| 222 | if (response.status !== 200) { |
| 223 | throw new Error(`Failed to fetch code sessions: ${response.statusText}`) |
| 224 | } |
| 225 | |
| 226 | // Transform SessionResource[] to CodeSession[] format |
| 227 | const sessions: CodeSession[] = response.data.data.map(session => { |
| 228 | // Extract repository info from git sources |
| 229 | const gitSource = session.session_context.sources.find( |
| 230 | (source): source is GitSource => source.type === 'git_repository', |
| 231 | ) |
| 232 | |
| 233 | let repo: CodeSession['repo'] = null |
| 234 | if (gitSource?.url) { |
| 235 | // Parse GitHub URL using the existing utility function |
| 236 | const repoPath = parseGitHubRepository(gitSource.url) |
| 237 | if (repoPath) { |
| 238 | const [owner, name] = repoPath.split('/') |
| 239 | if (owner && name) { |
| 240 | repo = { |
| 241 | name, |
| 242 | owner: { |
| 243 | login: owner, |
| 244 | }, |
| 245 | default_branch: gitSource.revision || undefined, |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | return { |
| 252 | id: session.id, |
| 253 | title: session.title || 'Untitled', |
| 254 | description: '', // SessionResource doesn't have description field |
| 255 | status: session.session_status as CodeSession['status'], // Map session_status to status |
| 256 | repo, |
| 257 | turns: [], // SessionResource doesn't have turns field |
| 258 | created_at: session.created_at, |
| 259 | updated_at: session.updated_at, |
| 260 | } |
| 261 | }) |
no test coverage detected