Spaces:
Sleeping
Sleeping
| export type RepoState = 'CONNECTED' | 'DISCONNECTED' | 'ERROR'; | |
| export interface RepoStatus { | |
| state: RepoState; | |
| stage: string; | |
| last_updated: string | null; | |
| } | |
| export interface MetricSeries { | |
| avg: number[]; | |
| max: number[]; | |
| min: number[]; | |
| } | |
| export interface AggregatedMetrics { | |
| timestamps: string[]; | |
| cpu: MetricSeries; | |
| memory: MetricSeries; | |
| } | |
| export interface Repository { | |
| id: string; | |
| namespace: string; | |
| repo: string; | |
| } | |
| const API_BASE = '/api'; | |
| export const fetchRepositories = async (): Promise<Repository[]> => { | |
| const res = await fetch(`${API_BASE}/repos`); | |
| if (!res.ok) throw new Error('Failed to fetch repositories'); | |
| return res.json(); | |
| }; | |
| export const addRepository = async (namespace: string, repo: string): Promise<Repository> => { | |
| const res = await fetch(`${API_BASE}/repos`, { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify({ namespace, repo }), | |
| }); | |
| if (!res.ok) throw new Error('Failed to add repository'); | |
| return res.json(); | |
| }; | |
| export const removeRepository = async (id: string): Promise<void> => { | |
| const res = await fetch(`${API_BASE}/repos${id}`, { | |
| method: 'DELETE', | |
| }); | |
| if (!res.ok) throw new Error('Failed to remove repository'); | |
| }; | |
| export const fetchRepoStatus = async (repoId: string): Promise<RepoStatus> => { | |
| const res = await fetch(`${API_BASE}/status?repoId=${repoId}`); | |
| if (!res.ok) throw new Error('Failed to fetch status'); | |
| return res.json(); | |
| }; | |
| export const fetchRepoMetrics = async (repoId: string, range: string = 'hour'): Promise<AggregatedMetrics> => { | |
| const res = await fetch(`${API_BASE}/metrics?repoId=${repoId}&range=${range}`); | |
| if (!res.ok) throw new Error('Failed to fetch metrics'); | |
| return res.json(); | |
| }; | |