const BASE = '/api' export async function fetchGuides() { const res = await fetch(`${BASE}/guides`) return res.json() } export async function createGuide(topic, format, instructions = '', provider = 'claude') { const res = await fetch(`${BASE}/guides`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ topic, format, instructions, provider }), }) return res.json() } export async function fetchActiveBausteine() { const res = await fetch(`${BASE}/bausteine/active`) return res.json() } export async function fetchBausteineStatus(topic) { const res = await fetch(`${BASE}/bausteine/status?topic=${encodeURIComponent(topic)}`) return res.json() } export async function createBausteine(topic, instructions = '', provider = 'claude') { const res = await fetch(`${BASE}/bausteine`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ topic, instructions, provider }), }) return res.json() } export async function cancelBausteine(topic) { await fetch(`${BASE}/bausteine/cancel?topic=${encodeURIComponent(topic)}`, { method: 'POST' }) } export async function deleteBausteine(topic) { await fetch(`${BASE}/bausteine?topic=${encodeURIComponent(topic)}`, { method: 'DELETE' }) } export async function fetchStats() { const res = await fetch(`${BASE}/stats`) return res.json() } export async function fetchProviders() { const res = await fetch(`${BASE}/providers`) return res.json() } export async function fetchProjects() { const res = await fetch(`${BASE}/projects`) return res.json() } export async function deleteProject(name) { await fetch(`${BASE}/projects/${encodeURIComponent(name)}`, { method: 'DELETE' }) } export async function cancelGuide(id) { await fetch(`${BASE}/guides/${id}/cancel`, { method: 'POST' }) } export async function deleteGuide(id) { await fetch(`${BASE}/guides/${id}`, { method: 'DELETE' }) } export async function fetchGuideContent(id) { const res = await fetch(`${BASE}/guides/${id}/content`) if (!res.ok) throw new Error(`Inhalt nicht verfügbar (${res.status})`) return res.json() } export async function fetchTopics() { const res = await fetch(`${BASE}/topics`) return res.json() } export async function createTopic(name) { await fetch(`${BASE}/topics`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name }), }) } export async function deleteTopic(name) { await fetch(`${BASE}/topics?topic=${encodeURIComponent(name)}`, { method: 'DELETE' }) } export async function fetchProgress(id) { const res = await fetch(`${BASE}/guides/${id}/progress`) return res.json() } export async function setProgress(id, chapter, done) { const res = await fetch(`${BASE}/guides/${id}/progress`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ chapter, done }), }) return res.json() } export async function chatGuide(id, { section, outline, messages, provider = 'claude' }) { const res = await fetch(`${BASE}/guides/${id}/chat`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ section, outline, messages, provider }), }) return res.json() }