This commit is contained in:
Team3
2026-06-06 16:07:04 +02:00
parent 18bb18bf4a
commit 4aa3130807
19 changed files with 861 additions and 206 deletions

View File

@@ -10,14 +10,16 @@ from agents import provider_available
from config import PROJECTS_DIR, PROVIDERS
from database import (
create_guide, delete_guide, get_guide, list_guides,
create_topic, list_topics as db_list_topics, delete_topic,
list_progress, set_progress, delete_progress,
)
from generator import (
generate_guide, cancel_guide, chat_with_guide,
generate_bausteine, bausteine_status, active_bausteine, reset_bausteine,
generate_bausteine, cancel_bausteine, bausteine_status, active_bausteine, reset_bausteine,
)
from models import (
GuideCreateRequest, GuideResponse,
TopicCreateRequest,
BausteineCreateRequest, BausteineStatusResponse,
GuideChatRequest, GuideChatResponse,
ProgressUpdate, ProgressResponse, ProjectResponse, ProviderInfo,
@@ -33,12 +35,26 @@ async def get_providers():
@router.get("/topics")
async def list_topics():
async def get_topics():
db_topics = await db_list_topics()
guides = await list_guides()
topics = {g["topic"] for g in guides}
topics.update(bausteine_topics())
topics.update(job["topic"] for job in active_bausteine())
return sorted(topics)
derived = {g["topic"] for g in guides}
derived.update(bausteine_topics())
derived.update(job["topic"] for job in active_bausteine())
# DB ist führend (Reihenfolge: neueste zuerst); Abgeleitetes ohne DB-Eintrag hinten anhängen
return db_topics + sorted(derived - set(db_topics))
@router.post("/topics")
async def add_topic(req: TopicCreateRequest):
await create_topic(req.name.strip())
return {"ok": True}
@router.delete("/topics")
async def remove_topic(topic: str):
await delete_topic(topic)
return {"ok": True}
def _safe_project_name(name: str) -> str:
@@ -81,10 +97,18 @@ async def create_bausteine(req: BausteineCreateRequest):
topic = req.topic.strip()
if bausteine_status(topic)["generating"]:
return {"ok": True, "status": "already_generating"}
await create_topic(topic)
asyncio.create_task(generate_bausteine(topic, req.instructions.strip(), req.provider))
return {"ok": True}
@router.post("/bausteine/cancel")
async def cancel_bausteine_route(topic: str):
if not cancel_bausteine(topic):
raise HTTPException(404, "Keine laufende Generierung")
return {"ok": True}
@router.delete("/bausteine")
async def remove_bausteine(topic: str):
reset_bausteine(topic)
@@ -95,8 +119,9 @@ async def remove_bausteine(topic: str):
@router.post("/guides", response_model=GuideResponse)
async def create(req: GuideCreateRequest):
if not bausteine_path(req.topic.strip()).exists():
if req.format != "OnePager" and not bausteine_path(req.topic.strip()).exists():
raise HTTPException(400, "Erst Bausteine erstellen")
await create_topic(req.topic.strip())
now = datetime.now(timezone.utc).isoformat()
guide = {
"id": str(uuid.uuid4()),