Spaces:
Paused
Paused
File size: 5,111 Bytes
f6a5256 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | /** API client for the Studio 2.0 control plane (/api/studio2). */
async function handle<T>(res: Response): Promise<T> {
if (!res.ok) {
const body = await res.text().catch(() => '');
throw new Error(`API ${res.status}: ${body || res.statusText}`);
}
return res.json() as Promise<T>;
}
const get = <T,>(url: string) => fetch(url).then((r) => handle<T>(r));
const post = <T,>(url: string, body?: unknown) =>
fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body ?? {}),
}).then((r) => handle<T>(r));
// ------------------------------------------------------------------ types
export interface Studio2Status {
registry_counts: Record<string, number>;
dependencies: Record<string, string>;
soft_dependencies: string[];
}
export interface RegistryEntity {
entity_id: string;
kind: string;
name?: string;
created_at?: string;
provenance?: Record<string, unknown>;
[key: string]: unknown;
}
export interface DatasetEntity extends RegistryEntity {
role: string;
protected_evaluation: boolean;
governance_overrides: { actor: string; reason: string; timestamp: string }[];
role_history: { from: string | null; to: string; actor: string }[];
lineage: { parents: string[] };
}
export interface RunEntity extends RegistryEntity {
engine: string;
reproducibility: 'REPRODUCIBLE' | 'NON_REPRODUCIBLE';
missing_components: string[];
reproducibility_tuple: Record<string, unknown>;
results?: Record<string, unknown>;
}
export interface ReleaseDecision {
entity_id: string;
status: 'GO' | 'REVIEW' | 'NO_GO';
confidence: number;
evidence_completeness: number;
blocking_conditions: string[];
unresolved_questions: string[];
degraded_inputs: string[];
human_approval_required: boolean;
deployment_authorized: boolean;
approval: { approver: string; rationale: string; approved_at: string } | null;
policy_version: string;
evidence_tuple: Record<string, unknown>;
evaluated_at: string;
}
export interface HardwareRow {
combination: Record<string, string>;
combination_label: string;
metrics: Record<string, number> | null;
n: number;
status: 'PASS' | 'FAIL' | 'INSUFFICIENT';
critical: boolean;
failed_checks?: string[];
reason?: string;
derivation?: Record<string, string>;
}
export interface HardwareMatrix {
matrix_id: string;
status: string;
global_pass: boolean | null;
global_metrics: Record<string, number> | null;
global_vs_matrix_note: string | null;
n_combinations: number;
n_pass: number;
n_fail: number;
n_insufficient: number;
min_support: { n: number; method: string };
rows: HardwareRow[];
insufficient: { combination_label: string; reason: string; critical: boolean }[];
source_run_id?: string | null;
}
export interface FunnelStage {
stage: string;
label: string;
available: boolean;
source: string;
data?: Record<string, unknown>;
status?: string;
reason?: string;
}
export interface FunnelPanel {
available: boolean;
source: string;
data?: Record<string, unknown>;
status?: string;
reason?: string;
}
export interface Funnel {
generated_at: string;
stages: FunnelStage[];
safety: FunnelPanel;
model_comparison: FunnelPanel;
drift: FunnelPanel;
compute: FunnelPanel;
availability: Record<string, boolean>;
}
export interface DemoStep {
step: string;
available: boolean;
[key: string]: unknown;
}
export interface DemoResult {
demo_id: string;
seed: number;
steps: DemoStep[];
decision: ReleaseDecision;
regression_dataset: DatasetEntity | null;
generated_at: string;
}
// ------------------------------------------------------------------ calls
export const getStatus = () => get<Studio2Status>('/api/studio2/status');
export const listEntities = (kind: string) =>
get<{ kind: string; entities: RegistryEntity[] }>(`/api/studio2/registry/${kind}`);
export const runIngest = () =>
post<{ registered: Record<string, number>; totals: Record<string, number> }>(
'/api/studio2/registry/ingest'
);
export const listDecisions = () =>
get<{ decisions: ReleaseDecision[] }>('/api/studio2/release/decisions');
export const evaluateRelease = () =>
post<ReleaseDecision>('/api/studio2/release/evaluate', { use_live_sources: true });
export const approveDecision = (decisionId: string, approver: string, rationale: string) =>
post<ReleaseDecision>(`/api/studio2/release/decisions/${decisionId}/approve`, {
approver,
rationale,
});
export const getHardwareMatrix = (refresh = false) =>
get<HardwareMatrix>(`/api/studio2/hardware/matrix${refresh ? '?refresh=true' : ''}`);
export const getFunnel = () => get<Funnel>('/api/studio2/funnel');
export const runDemo = (seed?: number) =>
post<DemoResult>('/api/studio2/demo/run', seed !== undefined ? { seed } : {});
export const getLatestDemo = () => get<DemoResult>('/api/studio2/demo/latest');
export const listDocs = () => get<{ docs: string[] }>('/api/studio2/docs');
export const getDoc = (name: string) =>
get<{ name: string; content: string }>(`/api/studio2/docs/${name}`);
|