import { ApiError, apiErrorMessage, apiFetch } from "./client"; export type PiReasoning = "low" | "medium" | "high"; export interface PiInstallationConfig { provider: string; model: string; reasoning: PiReasoning; } export interface PiManagementStatus { hostPlatform?: "linux" | "macos" | "windows"; version?: string; ready: boolean; credentials: "present" | "missing"; config: Partial; checkedAt: string; message?: string; } export interface PiManagementTestResult { ready: boolean; checkedAt: string; message?: string; } export interface PiManagementLogs { lines: string[]; checkedAt: string; } export type PiManagementApiErrorCode = | "pi_management_forbidden" | "pi_management_unavailable"; export interface PiManagementApiError { status: number; code: PiManagementApiErrorCode; message: string; } const errorCodes = new Set([ "pi_management_forbidden", "pi_management_unavailable", ]); /** Narrows the sanctioned error code and derives its message locally. */ export function asPiManagementApiError(error: unknown): PiManagementApiError | undefined { if (!(error instanceof ApiError)) return undefined; const code = error.code; if (typeof code !== "string" || !errorCodes.has(code as PiManagementApiErrorCode)) { return undefined; } return { status: error.status, code: code as PiManagementApiErrorCode, message: apiErrorMessage(error) }; } export const getPiManagementStatus = () => apiFetch("/pi-management/status"); export const runPiManagementTest = () => apiFetch("/pi-management/test", { method: "POST" }); export const getPiManagementLogs = () => apiFetch("/pi-management/logs");