const BASE = import.meta.env.VITE_API_BASE_URL ?? '/api' export interface DeploymentStatus { mode: 'PUBLIC' | 'PRIVATE' tenantRegisterEnabled: boolean services: Record } export async function getDeploymentStatus(): Promise { const res = await fetch(`${BASE}/private/deployment/status`) const json = await res.json() return json.data as DeploymentStatus } async function streamOperation( path: string, onLine: (line: string) => void, signal?: AbortSignal, ): Promise { const token = localStorage.getItem('token') ?? '' const res = await fetch(`${BASE}${path}`, { method: 'POST', headers: { Authorization: `Bearer ${token}` }, signal, }) if (!res.ok) { const text = await res.text() throw new Error(text || `HTTP ${res.status}`) } const reader = res.body!.getReader() const decoder = new TextDecoder() let buf = '' while (true) { const { done, value } = await reader.read() if (done) break buf += decoder.decode(value, { stream: true }) const lines = buf.split('\n') buf = lines.pop() ?? '' for (const line of lines) { onLine(line) } } if (buf) onLine(buf) } export function streamSystemUpdate(onLine: (line: string) => void, signal?: AbortSignal) { return streamOperation('/system/update', onLine, signal) } export function streamSystemReset(onLine: (line: string) => void, signal?: AbortSignal) { return streamOperation('/system/reset', onLine, signal) }