MCPcopy Create free account
hub / github.com/Noumena-Network/code / fetchCodeSessionsFromSessionsAPI

Function fetchCodeSessionsFromSessionsAPI

src/utils/teleport/api.ts:232–288  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

230 * @returns Array of code sessions
231 */
232export async function fetchCodeSessionsFromSessionsAPI(): Promise<
233 CodeSession[]
234> {
235 const { accessToken, orgUUID } = await prepareApiRequest()
236
237 const url = buildNoumenaPlatformUrl('/v1/sessions')
238
239 try {
240 const headers = {
241 ...getOAuthHeaders(accessToken),
242 'anthropic-beta': 'ccr-byoc-2025-07-29',
243 'x-organization-uuid': orgUUID,
244 }
245
246 const response = await axiosGetWithRetry<ListSessionsResponse>(url, {
247 headers,
248 })
249
250 if (response.status !== 200) {
251 throw new Error(`Failed to fetch code sessions: ${response.statusText}`)
252 }
253
254 // Transform SessionResource[] to CodeSession[] format
255 const sessions: CodeSession[] = response.data.data.map(session => {
256 const gitSource = getGitSourceFromSessionContext(session.session_context)
257 const repoRef = getSessionRepoRef(session.session_context)
258
259 let repo: CodeSession['repo'] = null
260 if (repoRef) {
261 repo = {
262 name: repoRef.name,
263 owner: {
264 login: repoRef.owner,
265 },
266 default_branch: gitSource?.revision || undefined,
267 }
268 }
269
270 return {
271 id: session.id,
272 title: session.title || 'Untitled',
273 description: '', // SessionResource doesn't have description field
274 status: session.session_status as CodeSession['status'], // Map session_status to status
275 repo,
276 turns: [], // SessionResource doesn't have turns field
277 created_at: session.created_at,
278 updated_at: session.updated_at,
279 }
280 })
281
282 return sessions
283 } catch (error) {
284 const err = toError(error)
285 logError(err)
286 throw error
287 }
288}
289

Callers 2

ResumeTaskFunction · 0.85
api.e2e.test.tsFile · 0.85

Calls 7

prepareApiRequestFunction · 0.85
buildNoumenaPlatformUrlFunction · 0.85
getOAuthHeadersFunction · 0.85
getSessionRepoRefFunction · 0.85
toErrorFunction · 0.50
logErrorFunction · 0.50

Tested by

no test coverage detected