feat(confidence-engine): use server investigation persistence
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
async function request(path, options) {
|
||||
const response = await fetch(path, options);
|
||||
const body = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
throw new Error(body.error || "Investigation persistence request failed");
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
export async function saveInvestigation(snapshot, id) {
|
||||
const body = await request("/api/investigations", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ id, snapshot }),
|
||||
});
|
||||
return body.snapshot ?? null;
|
||||
}
|
||||
|
||||
export async function loadInvestigation(id) {
|
||||
const url = `/api/investigations/${encodeURIComponent(id)}`;
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
if (response.status === 404) return null;
|
||||
const body = await response.json().catch(() => ({}));
|
||||
throw new Error(body.error || "Investigation persistence request failed");
|
||||
}
|
||||
const body = await response.json();
|
||||
return body.snapshot ?? null;
|
||||
}
|
||||
|
||||
export async function listInvestigations() {
|
||||
const body = await request("/api/investigations");
|
||||
return body.investigations ?? [];
|
||||
}
|
||||
|
||||
export async function restartInvestigation(id) {
|
||||
const body = await request(`/api/investigations/${encodeURIComponent(id)}/restart`, {
|
||||
method: "POST",
|
||||
});
|
||||
return body.snapshot ?? null;
|
||||
}
|
||||
Reference in New Issue
Block a user