feat(data): add read-only artifact health monitor
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
export interface ArtifactScope {
|
||||
scope_id: string;
|
||||
file_count: number;
|
||||
logical_bytes: number;
|
||||
modified_at_utc: string | null;
|
||||
}
|
||||
|
||||
export interface ArtifactHealth {
|
||||
schema_version: "missioncore.artifact-health/v1";
|
||||
generated_at_utc: string;
|
||||
overall_state: "live" | "attention" | "unavailable";
|
||||
inventory: {
|
||||
state: "live" | "degraded" | "unavailable";
|
||||
scanned_at_utc: string;
|
||||
scan_duration_ms: number;
|
||||
file_count: number;
|
||||
logical_bytes: number;
|
||||
unreadable_entries: number;
|
||||
files_delta_since_previous: number | null;
|
||||
bytes_delta_since_previous: number | null;
|
||||
scopes: ArtifactScope[];
|
||||
};
|
||||
exact_audit: {
|
||||
state: "exact-current" | "exact-stale" | "unavailable";
|
||||
result_id: string | null;
|
||||
audited_at_utc: string | null;
|
||||
root_count: number;
|
||||
file_count: number;
|
||||
logical_bytes: number;
|
||||
unique_content_bytes: number;
|
||||
duplicate_bytes: number;
|
||||
duplicate_fraction: number;
|
||||
amplification_ratio: number;
|
||||
duplicate_content_groups: number;
|
||||
changed_roots: string[];
|
||||
limitations: string[];
|
||||
};
|
||||
content_references: {
|
||||
state: "not-indexed";
|
||||
storage_model: "materialized-copies";
|
||||
storage_migration_authorized: false;
|
||||
next_gate: string;
|
||||
};
|
||||
}
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
||||
}
|
||||
|
||||
export async function fetchArtifactHealth(
|
||||
signal?: AbortSignal,
|
||||
): Promise<ArtifactHealth> {
|
||||
const response = await fetch("/api/v1/data/artifact-health", {
|
||||
method: "GET",
|
||||
headers: { Accept: "application/json" },
|
||||
signal,
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`API здоровья данных вернул HTTP ${response.status}.`);
|
||||
}
|
||||
const document: unknown = await response.json();
|
||||
if (
|
||||
!isRecord(document)
|
||||
|| document.schema_version !== "missioncore.artifact-health/v1"
|
||||
|| !isRecord(document.inventory)
|
||||
|| !Array.isArray(document.inventory.scopes)
|
||||
|| !isRecord(document.exact_audit)
|
||||
|| !isRecord(document.content_references)
|
||||
) {
|
||||
throw new Error("Ответ здоровья данных не соответствует контракту.");
|
||||
}
|
||||
return document as unknown as ArtifactHealth;
|
||||
}
|
||||
Reference in New Issue
Block a user