|
| 1 | +const BASE = import.meta.env.VITE_API_BASE ?? "http://localhost:3333/api"; |
| 2 | + |
| 3 | +async function request<T>(path: string, opts: RequestInit = {}): Promise<T> { |
| 4 | + const res = await fetch(`${BASE}${path}`, { |
| 5 | + headers: { "Content-Type": "application/json" }, |
| 6 | + credentials: "include", |
| 7 | + ...opts, |
| 8 | + }); |
| 9 | + const data = await res.json().catch(() => ({})); |
| 10 | + if (!res.ok) throw new Error(data?.error || res.statusText); |
| 11 | + return data as T; |
| 12 | +} |
| 13 | + |
| 14 | +export const api = { |
| 15 | + listRepos: () => request<{ repos: string[] }>("/mcp/repos"), |
| 16 | + listBranches: (repo: string) => request<{ branches: string[] }>(`/mcp/repos/${encodeURIComponent(repo)}/branches`), |
| 17 | + createPipeline: (payload: any) => request("/mcp/pipeline", { method: "POST", body: JSON.stringify(payload) }), |
| 18 | + listAwsRoles: () => request<{ roles: string[] }>("/mcp/oidc/roles"), |
| 19 | + openPr: (payload: any) => request("/mcp/pull-request", { method: "POST", body: JSON.stringify(payload) }), |
| 20 | + getConnections: (repo: string) => request(`/mcp/config/connections?repo=${encodeURIComponent(repo)}`), |
| 21 | + getSecretPresence: (repo: string, env: string) => request(`/mcp/config/secrets?repo=${encodeURIComponent(repo)}&env=${env}`), |
| 22 | + setSecret: (body: any) => request("/mcp/config/secret", { method: "POST", body: JSON.stringify(body) }), |
| 23 | + runPreflight: (body: any) => request("/mcp/config/preflight", { method: "POST", body: JSON.stringify(body) }), |
| 24 | + startDeploy: (body: any) => request("/mcp/deploy/start", { method: "POST", body: JSON.stringify(body) }), |
| 25 | + streamJob(jobId: string, onEvent: (e: any) => void) { |
| 26 | + const es = new EventSource(`${BASE}/mcp/jobs/${jobId}/events`, { withCredentials: true }); |
| 27 | + es.onmessage = (evt) => onEvent(JSON.parse(evt.data)); |
| 28 | + es.onerror = () => es.close(); |
| 29 | + return () => es.close(); |
| 30 | + }, |
| 31 | +}; |
| 32 | + |
0 commit comments