61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
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<PiInstallationConfig>;
|
|
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<PiManagementApiErrorCode>([
|
|
"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<PiManagementStatus>("/pi-management/status");
|
|
export const runPiManagementTest = () =>
|
|
apiFetch<PiManagementTestResult>("/pi-management/test", { method: "POST" });
|
|
export const getPiManagementLogs = () => apiFetch<PiManagementLogs>("/pi-management/logs");
|