KI-Konzil/frontend/app/utils/api-client.ts
Claude 001649a364
Implement Phase 4: tools, God Mode, and missing features
Backend:
- Add Tavily web search tool wrapper (tools/web_search.py)
- Add PDF reader + ChromaDB vector store tool (tools/pdf_reader.py)
- Bind tools to LLM calls via .bind_tools() in dynamic_graph_builder
- Implement God Mode using LangGraph interrupt_before + MemorySaver
- Add approve/reject/modify API endpoints for God Mode
- Add PDF upload endpoint with ingestion pipeline
- Add persistent run history (CouncilRun model + run_service + API)
- Add Alembic migration for council_runs table
- Enhance WebSocket to emit run_paused and run_resumed events
- Add tests for tools, God Mode, and run history

Frontend:
- Add God Mode approval UI (GodModePanel component)
- Add Auto-Pilot / God Mode toggle in Konferenzzimmer
- Add functional PDF upload handler
- Add Conditional Edge editor (EdgeSettingsPanel component)
- Add edge click selection in ArchitectCanvas
- Update Zustand store with edge selection and update actions
- Update types for God Mode, execution modes, and WS events
- Update API client with God Mode, PDF upload, and blueprint run endpoints
- Update WebSocket hook for paused/resumed events
- Add Vitest config and frontend tests (store, parser, types, API)

https://claude.ai/code/session_017U6idFgaqnYTXzPxA7mxMv
2026-02-21 10:53:12 +00:00

90 lines
2.8 KiB
TypeScript

// API client for the FastAPI backend
import { CouncilBlueprint, CouncilRun, GodModeAction, GodModeState } from "@/app/types/council";
const BASE_URL = process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8000";
async function request<T>(path: string, options?: RequestInit): Promise<T> {
const res = await fetch(`${BASE_URL}${path}`, {
headers: { "Content-Type": "application/json" },
...options,
});
if (!res.ok) {
const text = await res.text();
throw new Error(`API error ${res.status}: ${text}`);
}
return res.json() as Promise<T>;
}
// Council blueprint CRUD
export const councilApi = {
list: () => request<CouncilBlueprint[]>("/api/councils/"),
get: (id: string) => request<CouncilBlueprint>(`/api/councils/${id}`),
create: (blueprint: CouncilBlueprint) =>
request<CouncilBlueprint>("/api/councils/", {
method: "POST",
body: JSON.stringify(blueprint),
}),
update: (id: string, blueprint: CouncilBlueprint) =>
request<CouncilBlueprint>(`/api/councils/${id}`, {
method: "PUT",
body: JSON.stringify(blueprint),
}),
delete: (id: string) =>
request<void>(`/api/councils/${id}`, { method: "DELETE" }),
};
// Council run (execution)
export const runApi = {
start: (input_topic: string, god_mode: boolean = false) =>
request<CouncilRun>("/api/councils/run", {
method: "POST",
body: JSON.stringify({ input_topic, god_mode }),
}),
startFromBlueprint: (blueprintId: string, input_topic: string, god_mode: boolean = false) =>
request<CouncilRun>(`/api/councils/${blueprintId}/run`, {
method: "POST",
body: JSON.stringify({ input_topic, god_mode }),
}),
status: (run_id: string) =>
request<CouncilRun>(`/api/councils/run/${run_id}`),
// God Mode: approve/reject/modify a paused run
approve: (run_id: string, action: GodModeAction, modified_state?: Record<string, unknown>) =>
request<CouncilRun>(`/api/councils/run/${run_id}/approve`, {
method: "POST",
body: JSON.stringify({ action, modified_state }),
}),
// God Mode: get the paused state
getState: (run_id: string) =>
request<GodModeState>(`/api/councils/run/${run_id}/state`),
};
// PDF upload
export const pdfApi = {
upload: async (file: File) => {
const formData = new FormData();
formData.append("file", file);
const res = await fetch(`${BASE_URL}/api/councils/upload-pdf`, {
method: "POST",
body: formData,
});
if (!res.ok) {
const text = await res.text();
throw new Error(`Upload error ${res.status}: ${text}`);
}
return res.json() as Promise<{ filename: string; chunks_ingested: number; message: string }>;
},
};
// WebSocket URL helper
export function wsUrl(run_id: string): string {
const wsBase = BASE_URL.replace(/^http/, "ws");
return `${wsBase}/ws/council/${run_id}`;
}