Spaces:
Paused
Paused
Download frontend/src/api/client.ts from 2Btainment/repospace: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/spaces/2Btainment/repospace/resolve/main/frontend/src/api/client.ts
- Command line
-
hf download hf://spaces/2Btainment/repospace/frontend/src/api/client.ts
-
curl -L -o client.ts https://huggingface.co/spaces/2Btainment/repospace/resolve/main/frontend/src/api/client.ts
1.49 kB
| import type { LogLine, Session } from "../types"; | |
| async function parseError(res: Response): Promise<string> { | |
| try { | |
| const j = await res.json(); | |
| if (typeof j.detail === "string") return j.detail; | |
| if (j.detail?.message) return j.detail.message; | |
| return JSON.stringify(j.detail || j); | |
| } catch { | |
| return res.statusText || `HTTP ${res.status}`; | |
| } | |
| } | |
| export async function createSession( | |
| repoUrl: string, | |
| githubToken?: string, | |
| ref?: string | |
| ): Promise<Session> { | |
| const res = await fetch("/api/sessions", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ | |
| repo_url: repoUrl, | |
| github_token: githubToken || undefined, | |
| ref: ref || undefined, | |
| }), | |
| }); | |
| if (!res.ok) throw new Error(await parseError(res)); | |
| return res.json(); | |
| } | |
| export async function getSession(id: string): Promise<Session> { | |
| const res = await fetch(`/api/sessions/${id}`); | |
| if (!res.ok) throw new Error(await parseError(res)); | |
| return res.json(); | |
| } | |
| export async function getLogs(id: string, after = 0): Promise<{ lines: LogLine[]; next_after: number }> { | |
| const res = await fetch(`/api/sessions/${id}/logs?after=${after}`); | |
| if (!res.ok) throw new Error(await parseError(res)); | |
| return res.json(); | |
| } | |
| export async function deleteSession(id: string): Promise<void> { | |
| const res = await fetch(`/api/sessions/${id}`, { method: "DELETE" }); | |
| if (!res.ok && res.status !== 404) throw new Error(await parseError(res)); | |
| } | |