Spaces:
Sleeping
Sleeping
File size: 1,760 Bytes
d53c2af | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
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();
};
|