diff --git a/backend/main.py b/backend/main.py index 76339a0..730665f 100644 --- a/backend/main.py +++ b/backend/main.py @@ -40,11 +40,34 @@ app.add_middleware( AVATAR_COLORS = ['#1D9E75','#378ADD','#D85A30','#EF9F27','#7F77DD','#D4537E','#639922','#888780'] +@app.on_event("startup") +async def startup_event(): + """Run migrations and initialization on startup.""" + init_db() + def init_db(): """Initialize database - Schema is loaded by startup.sh""" # Schema loading and migration handled by startup.sh # This function kept for backwards compatibility - pass + + # Ensure "pipeline" master prompt exists + with get_db() as conn: + cur = get_cursor(conn) + cur.execute("SELECT COUNT(*) as count FROM ai_prompts WHERE slug='pipeline'") + if cur.fetchone()['count'] == 0: + cur.execute(""" + INSERT INTO ai_prompts (slug, name, description, template, active, sort_order) + VALUES ( + 'pipeline', + 'Mehrstufige Gesamtanalyse', + 'Master-Schalter für die gesamte Pipeline. Deaktiviere diese Analyse, um die Pipeline komplett zu verstecken.', + 'PIPELINE_MASTER', + true, + -10 + ) + """) + conn.commit() + print("✓ Pipeline master prompt created") # ── Helper: get profile_id from header ─────────────────────────────────────── def get_pid(x_profile_id: Optional[str] = Header(default=None)) -> str: diff --git a/frontend/src/pages/Analysis.jsx b/frontend/src/pages/Analysis.jsx index 4c55d33..630bc1b 100644 --- a/frontend/src/pages/Analysis.jsx +++ b/frontend/src/pages/Analysis.jsx @@ -179,9 +179,9 @@ export default function Analysis() { const activePrompts = prompts.filter(p=>p.active && !p.slug.startsWith('pipeline_')) - // Pipeline is available only if ALL pipeline sub-prompts are active - const pipelineSlugs = ['pipeline_body','pipeline_nutrition','pipeline_activity','pipeline_synthesis','pipeline_goals'] - const pipelineAvailable = pipelineSlugs.every(slug => prompts.find(p=>p.slug===slug)?.active) + // Pipeline is available if the "pipeline" prompt is active + const pipelinePrompt = prompts.find(p=>p.slug==='pipeline') + const pipelineAvailable = pipelinePrompt?.active ?? true // Default to true if not found (backwards compatibility) return (
@@ -386,15 +386,47 @@ export default function Analysis() { ))} {/* Pipeline prompts */} -
- Mehrstufige Pipeline -
-
- ⚠️ Hinweis: Pipeline-Stage-1-Prompts müssen valides JSON zurückgeben. - Halte das JSON-Format im Prompt erhalten. Stage 2 + 3 können frei angepasst werden. +
+
+ Mehrstufige Pipeline +
+ {(() => { + const pipelinePrompt = prompts.find(p=>p.slug==='pipeline') + return pipelinePrompt && ( + + ) + })()}
+ {(() => { + const pipelinePrompt = prompts.find(p=>p.slug==='pipeline') + const isPipelineActive = pipelinePrompt?.active ?? true + return ( +
+ {isPipelineActive ? ( + <>⚠️ Hinweis: Pipeline-Stage-1-Prompts müssen valides JSON zurückgeben. + Halte das JSON-Format im Prompt erhalten. Stage 2 + 3 können frei angepasst werden. + ) : ( + <>⏸ Pipeline deaktiviert: Die mehrstufige Gesamtanalyse ist aktuell nicht verfügbar. + Aktiviere sie mit dem Schalter oben, um sie auf der Analyse-Seite zu nutzen. + )} +
+ ) + })()} {pipelinePrompts.map(p=>{ const isJson = jsonSlugs.includes(p.slug) return (