Files
remote-mcp-manager/apps/web/src/api/client.ts
T
dasemuandClaude Sonnet 5.5 9a85c3bca0 feat: show the installed commit and how many newer commits the remote has
The Manager card now shows the commit SHA the image was built from (GIT_SHA build arg, passed
by the panel's self-update and documented for compose) and counts the commits SELF_UPDATE_REF
has beyond it, with their subjects and a "Check for updates" button. The check is a cached,
background, history-only git fetch so GET /api/system never waits on it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-19 09:14:35 +02:00

90 lines
3.7 KiB
TypeScript

export interface Installation {
id: string;
slug: string;
name: string;
repoUrl: string;
gitRef: string | null;
status: "draft" | "cloning" | "building" | "built" | "starting" | "running" | "stopped" | "error";
statusDetail: string | null;
imageTag: string | null;
containerName: string;
internalPort: number;
httpPath: string;
portEnvVar: string;
hostEnvVar: string;
env: Record<string, string>;
bearerToken: string | null;
publicUrl: string;
createdAt: string;
updatedAt: string;
}
export interface RemoteStatus {
checkedAt: string;
remoteSha: string | null;
behind: number | null;
commits: { sha: string; subject: string }[];
error: string | null;
}
export interface SystemInfo {
version: string;
sha: string | null;
remote: RemoteStatus | null;
uptimeSec: number;
canSelfUpdate: boolean;
unavailableReason: string | null;
ref: string;
phase: "idle" | "cloning" | "building" | "handing-over";
error: string | null;
log: string;
lastUpdate: { finishedAt: string; ok: boolean; log: string } | null;
}
async function request<T>(path: string, init?: RequestInit): Promise<T> {
const res = await fetch(path, {
...init,
credentials: "include",
headers: { "Content-Type": "application/json", ...(init?.headers ?? {}) },
});
if (!res.ok) {
const body = await res.json().catch(() => ({ error: res.statusText }));
throw new Error(body.error ?? `request failed with ${res.status}`);
}
if (res.status === 204) return undefined as T;
return res.json();
}
export const api = {
session: () => request<{ authenticated: boolean }>("/api/auth/session"),
login: (password: string) => request<{ ok: true }>("/api/auth/login", { method: "POST", body: JSON.stringify({ password }) }),
logout: () => request<{ ok: true }>("/api/auth/logout", { method: "POST" }),
listInstallations: () => request<Installation[]>("/api/installations"),
getInstallation: (id: string) => request<Installation>(`/api/installations/${id}`),
createInstallation: (input: { name: string; repoUrl: string; gitRef?: string }) =>
request<{ installation: Installation; detectedEnvKeys: string[] }>("/api/installations", {
method: "POST",
body: JSON.stringify(input),
}),
configureInstallation: (
id: string,
patch: { env?: Record<string, string>; portEnvVar?: string; hostEnvVar?: string; httpPath?: string },
) => request<Installation>(`/api/installations/${id}/config`, { method: "PATCH", body: JSON.stringify(patch) }),
build: (id: string) => request<Installation>(`/api/installations/${id}/build`, { method: "POST" }),
deploy: (id: string) => request<Installation>(`/api/installations/${id}/deploy`, { method: "POST" }),
redeploy: (id: string, rebuild: boolean) =>
request<Installation>(`/api/installations/${id}/redeploy`, { method: "POST", body: JSON.stringify({ rebuild }) }),
start: (id: string) => request<Installation>(`/api/installations/${id}/start`, { method: "POST" }),
stop: (id: string) => request<Installation>(`/api/installations/${id}/stop`, { method: "POST" }),
restart: (id: string) => request<Installation>(`/api/installations/${id}/restart`, { method: "POST" }),
regenerateToken: (id: string) =>
request<{ bearerToken: string }>(`/api/installations/${id}/regenerate-token`, { method: "POST" }),
remove: (id: string) => request<void>(`/api/installations/${id}`, { method: "DELETE" }),
logs: (id: string) => request<{ log: string }>(`/api/installations/${id}/logs`),
systemInfo: () => request<SystemInfo>("/api/system"),
checkManager: () => request<SystemInfo>("/api/system/check", { method: "POST" }),
updateManager: () => request<{ ok: true }>("/api/system/update", { method: "POST" }),
};