From e4f49c0351619a4dbf480d91163ef800ddf500e9 Mon Sep 17 00:00:00 2001 From: Lars Date: Fri, 20 Mar 2026 15:35:33 +0100 Subject: [PATCH] fix: enable AI analysis history and correct pipeline scope Fixes two critical bugs in AI analysis storage: 1. History now works - analyses are saved, not overwritten - Removed DELETE statements before INSERT in insights.py - All analyses are now preserved per scope - Displayed in descending order by creation date 2. Pipeline saves under correct scope 'pipeline' instead of 'gesamt' - Changed scope from 'gesamt' to 'pipeline' in pipeline endpoint - Pipeline results now appear under correct category in history 3. Fixed pipeline appearing twice in UI - Filter now excludes both 'pipeline_*' and 'pipeline' from individual list - Pipeline only appears in dedicated section at top Changes: - backend/routers/insights.py: Removed DELETE, changed scope to 'pipeline' - frontend/src/pages/Analysis.jsx: Fixed filter to exclude 'pipeline' Co-Authored-By: Claude Opus 4.6 --- backend/routers/insights.py | 10 ++++------ frontend/src/pages/Analysis.jsx | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/backend/routers/insights.py b/backend/routers/insights.py index b325bf0..f624f35 100644 --- a/backend/routers/insights.py +++ b/backend/routers/insights.py @@ -294,10 +294,9 @@ async def analyze_with_prompt(slug: str, x_profile_id: Optional[str]=Header(defa else: raise HTTPException(500, "Keine KI-API konfiguriert") - # Save insight + # Save insight (with history - no DELETE) with get_db() as conn: cur = get_cursor(conn) - cur.execute("DELETE FROM ai_insights WHERE profile_id=%s AND scope=%s", (pid, slug)) cur.execute("INSERT INTO ai_insights (id, profile_id, scope, content, created) VALUES (%s,%s,%s,%s,CURRENT_TIMESTAMP)", (str(uuid.uuid4()), pid, slug, content)) @@ -431,15 +430,14 @@ async def analyze_pipeline(x_profile_id: Optional[str]=Header(default=None), ses if goals_text: final_content += "\n\n" + goals_text - # Save as 'gesamt' scope + # Save as 'pipeline' scope (with history - no DELETE) with get_db() as conn: cur = get_cursor(conn) - cur.execute("DELETE FROM ai_insights WHERE profile_id=%s AND scope='gesamt'", (pid,)) - cur.execute("INSERT INTO ai_insights (id, profile_id, scope, content, created) VALUES (%s,%s,'gesamt',%s,CURRENT_TIMESTAMP)", + cur.execute("INSERT INTO ai_insights (id, profile_id, scope, content, created) VALUES (%s,%s,'pipeline',%s,CURRENT_TIMESTAMP)", (str(uuid.uuid4()), pid, final_content)) inc_ai_usage(pid) - return {"scope": "gesamt", "content": final_content, "stage1": stage1_results} + return {"scope": "pipeline", "content": final_content, "stage1": stage1_results} @router.get("/ai/usage") diff --git a/frontend/src/pages/Analysis.jsx b/frontend/src/pages/Analysis.jsx index 630bc1b..128b34f 100644 --- a/frontend/src/pages/Analysis.jsx +++ b/frontend/src/pages/Analysis.jsx @@ -177,7 +177,7 @@ export default function Analysis() { grouped[key].push(ins) }) - const activePrompts = prompts.filter(p=>p.active && !p.slug.startsWith('pipeline_')) + const activePrompts = prompts.filter(p=>p.active && !p.slug.startsWith('pipeline_') && p.slug !== 'pipeline') // Pipeline is available if the "pipeline" prompt is active const pipelinePrompt = prompts.find(p=>p.slug==='pipeline')