2026-04-05 09:04:08 +02:00
|
|
|
|
import React, { useState, useEffect, useMemo } from 'react'
|
2026-04-05 12:07:11 +02:00
|
|
|
|
import { Brain, Trash2, ChevronDown, ChevronUp } from 'lucide-react'
|
|
|
|
|
|
import { Link } from 'react-router-dom'
|
2026-03-16 13:35:11 +01:00
|
|
|
|
import { api } from '../utils/api'
|
2026-04-11 12:04:35 +02:00
|
|
|
|
import { getWorkflowDisplayContent } from '../utils/workflowDisplay'
|
2026-04-11 12:19:06 +02:00
|
|
|
|
import {
|
|
|
|
|
|
ANALYSIS_CATEGORY_ORDER,
|
|
|
|
|
|
ANALYSIS_CATEGORY_LABELS,
|
|
|
|
|
|
} from '../config/analysisCategories'
|
2026-03-16 13:35:11 +01:00
|
|
|
|
import { useAuth } from '../context/AuthContext'
|
|
|
|
|
|
import Markdown from '../utils/Markdown'
|
2026-03-21 06:43:10 +01:00
|
|
|
|
import UsageBadge from '../components/UsageBadge'
|
2026-04-13 12:41:12 +02:00
|
|
|
|
import WorkflowDebugPanel from '../components/WorkflowDebugPanel'
|
2026-03-16 13:35:11 +01:00
|
|
|
|
import dayjs from 'dayjs'
|
|
|
|
|
|
import 'dayjs/locale/de'
|
|
|
|
|
|
dayjs.locale('de')
|
|
|
|
|
|
|
2026-03-26 07:50:13 +01:00
|
|
|
|
// Legacy fallback labels (display_name takes precedence)
|
2026-03-16 13:35:11 +01:00
|
|
|
|
const SLUG_LABELS = {
|
2026-03-26 07:50:13 +01:00
|
|
|
|
pipeline: '🔬 Mehrstufige Gesamtanalyse'
|
2026-03-16 13:35:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-05 09:04:08 +02:00
|
|
|
|
function sortAnalysisCategoryKeys(keys) {
|
|
|
|
|
|
return [...keys].sort((a, b) => {
|
|
|
|
|
|
const na = String(a).toLowerCase()
|
|
|
|
|
|
const nb = String(b).toLowerCase()
|
|
|
|
|
|
const ia = ANALYSIS_CATEGORY_ORDER.indexOf(na)
|
|
|
|
|
|
const ib = ANALYSIS_CATEGORY_ORDER.indexOf(nb)
|
|
|
|
|
|
if (ia === -1 && ib === -1) return String(a).localeCompare(String(b), 'de')
|
|
|
|
|
|
if (ia === -1) return 1
|
|
|
|
|
|
if (ib === -1) return -1
|
|
|
|
|
|
return ia - ib
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function analysisCategoryLabel(key) {
|
|
|
|
|
|
const k = String(key).toLowerCase()
|
|
|
|
|
|
return ANALYSIS_CATEGORY_LABELS[k] || String(key)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-11 11:42:54 +02:00
|
|
|
|
/** Analyse-Angebote: klassische Pipelines + graphbasierte KI-Workflows (`type === 'workflow'`) */
|
|
|
|
|
|
function isAnalysisOfferPrompt(p) {
|
|
|
|
|
|
return p.active && (p.type === 'pipeline' || p.type === 'workflow')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-05 09:04:08 +02:00
|
|
|
|
/** Pipeline-Prompts nach `category` gruppieren (Backend-Feld), innerhalb Gruppe nach sort_order */
|
|
|
|
|
|
function buildPipelineGroups(pipelinePrompts) {
|
|
|
|
|
|
const m = new Map()
|
|
|
|
|
|
for (const p of pipelinePrompts) {
|
|
|
|
|
|
const raw =
|
|
|
|
|
|
p.category != null && String(p.category).trim() !== ''
|
|
|
|
|
|
? String(p.category).trim()
|
|
|
|
|
|
: 'ganzheitlich'
|
|
|
|
|
|
if (!m.has(raw)) m.set(raw, [])
|
|
|
|
|
|
m.get(raw).push(p)
|
|
|
|
|
|
}
|
|
|
|
|
|
for (const arr of m.values()) {
|
|
|
|
|
|
arr.sort((a, b) => (Number(a.sort_order) || 0) - (Number(b.sort_order) || 0))
|
|
|
|
|
|
}
|
|
|
|
|
|
return sortAnalysisCategoryKeys([...m.keys()]).map(cat => ({
|
|
|
|
|
|
categoryKey: cat,
|
|
|
|
|
|
label: analysisCategoryLabel(cat),
|
|
|
|
|
|
prompts: m.get(cat),
|
|
|
|
|
|
}))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-25 06:44:22 +01:00
|
|
|
|
function InsightCard({ ins, onDelete, defaultOpen=false, prompts=[] }) {
|
2026-03-16 13:35:11 +01:00
|
|
|
|
const [open, setOpen] = useState(defaultOpen)
|
2026-03-26 12:37:52 +01:00
|
|
|
|
|
|
|
|
|
|
// Parse metadata early to determine showOnlyValues
|
|
|
|
|
|
const metadataRaw = ins.metadata ? (typeof ins.metadata === 'string' ? JSON.parse(ins.metadata) : ins.metadata) : null
|
|
|
|
|
|
const isBasePrompt = metadataRaw?.prompt_type === 'base'
|
|
|
|
|
|
const isJsonOutput = ins.content && (ins.content.trim().startsWith('{') || ins.content.trim().startsWith('['))
|
|
|
|
|
|
const placeholdersRaw = metadataRaw?.placeholders || {}
|
|
|
|
|
|
const showOnlyValues = isBasePrompt && isJsonOutput && Object.keys(placeholdersRaw).length > 0
|
|
|
|
|
|
|
|
|
|
|
|
const [showValues, setShowValues] = useState(showOnlyValues) // Auto-expand for base prompts with JSON
|
2026-03-26 12:44:28 +01:00
|
|
|
|
const [expertMode, setExpertMode] = useState(false) // Show empty/technical placeholders
|
2026-03-25 06:44:22 +01:00
|
|
|
|
|
|
|
|
|
|
// Find matching prompt to get display_name
|
|
|
|
|
|
const prompt = prompts.find(p => p.slug === ins.scope)
|
2026-04-11 12:19:06 +02:00
|
|
|
|
const displayName =
|
|
|
|
|
|
prompt?.display_name || prompt?.name || SLUG_LABELS[ins.scope] || ins.scope
|
2026-03-25 06:44:22 +01:00
|
|
|
|
|
2026-03-26 12:37:52 +01:00
|
|
|
|
// Use already-parsed metadata
|
|
|
|
|
|
const metadata = metadataRaw
|
2026-03-26 12:44:28 +01:00
|
|
|
|
const allPlaceholders = placeholdersRaw
|
|
|
|
|
|
|
feat: extract individual values from stage outputs (Issue #47)
FEATURE: Basis-Analysen Einzelwerte
Vorher: stage_1_body → {"bmi": 26.6, "weight": "85.2kg"} (1 Zeile)
Jetzt: bmi → 26.6 (eigene Zeile)
weight → 85.2kg (eigene Zeile)
BACKEND: JSON-Extraktion
- Stage outputs (JSON) → extract individual fields
- extracted_values dict sammelt alle Einzelwerte
- Deduplizierung: Gleiche Keys nur einmal
- Flags:
- is_extracted: true → Wert aus Stage-Output extrahiert
- is_stage_raw: true → Rohdaten (JSON) nur Experten-Modus
BEISPIEL Stage 1 Output:
{
"stage_1_body": {
"bmi": 26.6,
"weight": "85.2 kg",
"trend": "sinkend"
}
}
→ Metadata:
{
"bmi": {
value: "26.6",
description: "Aus Stage 1 (stage_1_body)",
is_extracted: true
},
"weight": {
value: "85.2 kg",
description: "Aus Stage 1 (stage_1_body)",
is_extracted: true
},
"stage_1_body": {
value: "{\"bmi\": 26.6, ...}",
description: "Rohdaten Stage 1 (Basis-Analyse JSON)",
is_stage_raw: true
}
}
FRONTEND: Smart Filtering
Normal-Modus:
- Zeigt: Einzelwerte (bmi, weight, trend)
- Versteckt: Rohdaten (stage_1_body JSON)
- Filter: is_stage_raw === false
Experten-Modus:
- Zeigt: Alles (Einzelwerte + Rohdaten)
- Rohdaten: Grauer Hintergrund + 🔬 Icon
VISUAL Indicators:
↳ bmi → Extrahierter Wert (grün)
weight → Normaler Platzhalter (accent)
🔬 stage_1_* → Rohdaten JSON (grau, klein, nur Experten)
ERGEBNIS:
┌──────────────────────────────────────────┐
│ 📊 Verwendete Werte (8) (+2 ausgeblendet)│
│ ┌────────────────────────────────────────┐│
│ │ weight_aktuell │ 85.2 kg │ Gewicht ││ ← Normal
│ │ ↳ bmi │ 26.6 │ Aus St..││ ← Extrahiert
│ │ ↳ trend │ sinkend │ Aus St..││ ← Extrahiert
│ └────────────────────────────────────────┘│
└──────────────────────────────────────────┘
Experten-Modus zusätzlich:
│ 🔬 stage_1_body │ {"bmi":...│ Rohdaten││ ← JSON
version: 9.9.0 (feature)
module: prompts 2.4.0, insights 1.7.0
2026-03-26 12:55:53 +01:00
|
|
|
|
// Filter placeholders: In normal mode, hide empty values and raw stage outputs
|
2026-03-26 12:44:28 +01:00
|
|
|
|
const placeholders = expertMode
|
|
|
|
|
|
? allPlaceholders
|
|
|
|
|
|
: Object.fromEntries(
|
|
|
|
|
|
Object.entries(allPlaceholders).filter(([key, data]) => {
|
feat: extract individual values from stage outputs (Issue #47)
FEATURE: Basis-Analysen Einzelwerte
Vorher: stage_1_body → {"bmi": 26.6, "weight": "85.2kg"} (1 Zeile)
Jetzt: bmi → 26.6 (eigene Zeile)
weight → 85.2kg (eigene Zeile)
BACKEND: JSON-Extraktion
- Stage outputs (JSON) → extract individual fields
- extracted_values dict sammelt alle Einzelwerte
- Deduplizierung: Gleiche Keys nur einmal
- Flags:
- is_extracted: true → Wert aus Stage-Output extrahiert
- is_stage_raw: true → Rohdaten (JSON) nur Experten-Modus
BEISPIEL Stage 1 Output:
{
"stage_1_body": {
"bmi": 26.6,
"weight": "85.2 kg",
"trend": "sinkend"
}
}
→ Metadata:
{
"bmi": {
value: "26.6",
description: "Aus Stage 1 (stage_1_body)",
is_extracted: true
},
"weight": {
value: "85.2 kg",
description: "Aus Stage 1 (stage_1_body)",
is_extracted: true
},
"stage_1_body": {
value: "{\"bmi\": 26.6, ...}",
description: "Rohdaten Stage 1 (Basis-Analyse JSON)",
is_stage_raw: true
}
}
FRONTEND: Smart Filtering
Normal-Modus:
- Zeigt: Einzelwerte (bmi, weight, trend)
- Versteckt: Rohdaten (stage_1_body JSON)
- Filter: is_stage_raw === false
Experten-Modus:
- Zeigt: Alles (Einzelwerte + Rohdaten)
- Rohdaten: Grauer Hintergrund + 🔬 Icon
VISUAL Indicators:
↳ bmi → Extrahierter Wert (grün)
weight → Normaler Platzhalter (accent)
🔬 stage_1_* → Rohdaten JSON (grau, klein, nur Experten)
ERGEBNIS:
┌──────────────────────────────────────────┐
│ 📊 Verwendete Werte (8) (+2 ausgeblendet)│
│ ┌────────────────────────────────────────┐│
│ │ weight_aktuell │ 85.2 kg │ Gewicht ││ ← Normal
│ │ ↳ bmi │ 26.6 │ Aus St..││ ← Extrahiert
│ │ ↳ trend │ sinkend │ Aus St..││ ← Extrahiert
│ └────────────────────────────────────────┘│
└──────────────────────────────────────────┘
Experten-Modus zusätzlich:
│ 🔬 stage_1_body │ {"bmi":...│ Rohdaten││ ← JSON
version: 9.9.0 (feature)
module: prompts 2.4.0, insights 1.7.0
2026-03-26 12:55:53 +01:00
|
|
|
|
// Hide raw stage outputs (JSON) in normal mode
|
|
|
|
|
|
if (data.is_stage_raw) return false
|
|
|
|
|
|
|
|
|
|
|
|
// Hide empty values
|
2026-03-26 12:44:28 +01:00
|
|
|
|
const val = data.value || ''
|
|
|
|
|
|
return val.trim() !== '' && val !== 'nicht verfügbar' && val !== '[Nicht verfügbar]'
|
|
|
|
|
|
})
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2026-03-26 11:52:26 +01:00
|
|
|
|
const placeholderCount = Object.keys(placeholders).length
|
2026-03-26 12:44:28 +01:00
|
|
|
|
const hiddenCount = Object.keys(allPlaceholders).length - placeholderCount
|
2026-03-26 11:52:26 +01:00
|
|
|
|
|
feat: category grouping in value table (Issue #47)
FEATURE: Gruppierung nach Kategorien
- Wertetabelle jetzt nach Modulen/Kategorien gruppiert
- Bessere Übersicht und Zuordnung der Werte
BACKEND: Category Metadata
- Für normale Platzhalter: Kategorie aus Catalog (Profil, Körper, Ernährung, etc.)
- Für extrahierte Werte: "Stage X - [Output Name]"
- Für Rohdaten: "Stage X - Rohdaten"
- Fallback: "Sonstiges"
FRONTEND: Grouped Display
- sortedCategories: Sortierung (Normal → Stage Outputs → Rohdaten)
- Section Headers: Grauer Hintergrund mit Kategorie-Name
- React.Fragment für Gruppierung
SORTIERUNG:
1. Normale Kategorien (Profil, Körper, Ernährung, Training, etc.)
2. Stage Outputs (Stage 1 - Body, Stage 1 - Nutrition, etc.)
3. Rohdaten (Stage 1 - Rohdaten, Stage 2 - Rohdaten)
4. Innerhalb: Alphabetisch
BEISPIEL:
┌────────────────────────────────────────────┐
│ PROFIL │
├────────────────────────────────────────────┤
│ name │ Lars │ Name des Nutzers │
│ age │ 55 │ Alter in Jahren │
├────────────────────────────────────────────┤
│ KÖRPER │
├────────────────────────────────────────────┤
│ weight_... │ 85.2 kg │ Aktuelles Gewicht │
│ bmi │ 26.6 │ Body Mass Index │
├────────────────────────────────────────────┤
│ ERNÄHRUNG │
├────────────────────────────────────────────┤
│ kcal_avg │ 1427... │ Durchschn. Kalorien│
│ protein... │ 106g... │ Durchschn. Protein │
├────────────────────────────────────────────┤
│ STAGE 1 - BODY │
├────────────────────────────────────────────┤
│ ↳ bmi │ 26.6 │ Aus Stage 1 (body) │
│ ↳ trend │ sinkend │ Aus Stage 1 (body) │
├────────────────────────────────────────────┤
│ STAGE 1 - NUTRITION │
├────────────────────────────────────────────┤
│ ↳ kcal_... │ 1427 │ Aus Stage 1 (nutr.)│
└────────────────────────────────────────────┘
Experten-Modus zusätzlich:
├────────────────────────────────────────────┤
│ STAGE 1 - ROHDATEN │
├────────────────────────────────────────────┤
│ 🔬 stage...│ {"bmi"..│ Rohdaten Stage 1 │
└────────────────────────────────────────────┘
version: 9.10.0 (feature)
module: prompts 2.5.0, insights 1.8.0
2026-03-26 12:59:52 +01:00
|
|
|
|
// Group placeholders by category
|
|
|
|
|
|
const groupedPlaceholders = Object.entries(placeholders).reduce((acc, [key, data]) => {
|
|
|
|
|
|
const category = data.category || 'Sonstiges'
|
|
|
|
|
|
if (!acc[category]) acc[category] = []
|
|
|
|
|
|
acc[category].push([key, data])
|
|
|
|
|
|
return acc
|
|
|
|
|
|
}, {})
|
|
|
|
|
|
|
|
|
|
|
|
// Sort categories: Regular categories first, then Stage outputs, then Rohdaten
|
|
|
|
|
|
const sortedCategories = Object.keys(groupedPlaceholders).sort((a, b) => {
|
|
|
|
|
|
const aIsStage = a.startsWith('Stage')
|
|
|
|
|
|
const bIsStage = b.startsWith('Stage')
|
|
|
|
|
|
const aIsRohdaten = a.includes('Rohdaten')
|
|
|
|
|
|
const bIsRohdaten = b.includes('Rohdaten')
|
|
|
|
|
|
|
|
|
|
|
|
// Rohdaten last
|
|
|
|
|
|
if (aIsRohdaten && !bIsRohdaten) return 1
|
|
|
|
|
|
if (!aIsRohdaten && bIsRohdaten) return -1
|
|
|
|
|
|
|
|
|
|
|
|
// Stage outputs after regular categories
|
|
|
|
|
|
if (!aIsStage && bIsStage) return -1
|
|
|
|
|
|
if (aIsStage && !bIsStage) return 1
|
|
|
|
|
|
|
|
|
|
|
|
// Otherwise alphabetical
|
|
|
|
|
|
return a.localeCompare(b)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-03-16 13:35:11 +01:00
|
|
|
|
return (
|
|
|
|
|
|
<div className="card section-gap" style={{borderLeft:`3px solid var(--accent)`}}>
|
|
|
|
|
|
<div style={{display:'flex',alignItems:'center',gap:8,marginBottom:open?12:0,cursor:'pointer'}}
|
|
|
|
|
|
onClick={()=>setOpen(o=>!o)}>
|
|
|
|
|
|
<div style={{flex:1}}>
|
|
|
|
|
|
<div style={{fontSize:13,fontWeight:600}}>
|
2026-03-25 06:44:22 +01:00
|
|
|
|
{displayName}
|
2026-03-16 13:35:11 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
<div style={{fontSize:11,color:'var(--text3)'}}>
|
|
|
|
|
|
{dayjs(ins.created).format('DD. MMMM YYYY, HH:mm')}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<button style={{background:'none',border:'none',cursor:'pointer',color:'var(--text3)',padding:4}}
|
|
|
|
|
|
onClick={e=>{e.stopPropagation();onDelete(ins.id)}}>
|
|
|
|
|
|
<Trash2 size={13}/>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
{open ? <ChevronUp size={16} color="var(--text3)"/> : <ChevronDown size={16} color="var(--text3)"/>}
|
|
|
|
|
|
</div>
|
2026-03-26 11:52:26 +01:00
|
|
|
|
{open && (
|
|
|
|
|
|
<>
|
2026-03-26 12:37:52 +01:00
|
|
|
|
{/* For base prompts with JSON: Only show value table */}
|
|
|
|
|
|
{showOnlyValues && (
|
|
|
|
|
|
<div style={{ padding: '12px 16px', background: 'var(--surface)', borderRadius: 8, marginBottom: 12 }}>
|
|
|
|
|
|
<div style={{ fontSize: 11, color: 'var(--text3)', marginBottom: 8 }}>
|
|
|
|
|
|
ℹ️ Basis-Prompt Rohdaten (JSON-Struktur für technische Nutzung)
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<details style={{ fontSize: 11, color: 'var(--text3)' }}>
|
|
|
|
|
|
<summary style={{ cursor: 'pointer' }}>Technische Daten anzeigen</summary>
|
|
|
|
|
|
<pre style={{
|
|
|
|
|
|
marginTop: 8,
|
|
|
|
|
|
padding: 8,
|
|
|
|
|
|
background: 'var(--bg)',
|
|
|
|
|
|
borderRadius: 4,
|
|
|
|
|
|
overflow: 'auto',
|
|
|
|
|
|
fontSize: 10,
|
|
|
|
|
|
fontFamily: 'monospace'
|
|
|
|
|
|
}}>
|
|
|
|
|
|
{ins.content}
|
|
|
|
|
|
</pre>
|
|
|
|
|
|
</details>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{/* For other prompts: Show full content */}
|
|
|
|
|
|
{!showOnlyValues && <Markdown text={ins.content}/>}
|
2026-03-26 11:52:26 +01:00
|
|
|
|
|
|
|
|
|
|
{/* Value Table */}
|
|
|
|
|
|
{placeholderCount > 0 && (
|
|
|
|
|
|
<div style={{ marginTop: 16, borderTop: '1px solid var(--border)', paddingTop: 12 }}>
|
2026-03-26 12:44:28 +01:00
|
|
|
|
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
|
|
|
|
|
|
<div
|
|
|
|
|
|
onClick={() => setShowValues(!showValues)}
|
|
|
|
|
|
style={{
|
|
|
|
|
|
cursor: 'pointer',
|
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
|
color: 'var(--text2)',
|
|
|
|
|
|
fontWeight: 600,
|
|
|
|
|
|
display: 'flex',
|
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
|
gap: 6
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{showValues ? <ChevronUp size={14} /> : <ChevronDown size={14} />}
|
|
|
|
|
|
📊 Verwendete Werte ({placeholderCount})
|
|
|
|
|
|
{hiddenCount > 0 && !expertMode && (
|
|
|
|
|
|
<span style={{ fontSize: 10, color: 'var(--text3)', fontWeight: 400 }}>
|
|
|
|
|
|
(+{hiddenCount} ausgeblendet)
|
|
|
|
|
|
</span>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{showValues && Object.keys(allPlaceholders).length > 0 && (
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
|
e.stopPropagation()
|
|
|
|
|
|
setExpertMode(!expertMode)
|
|
|
|
|
|
}}
|
|
|
|
|
|
className="btn"
|
|
|
|
|
|
style={{
|
|
|
|
|
|
fontSize: 10,
|
|
|
|
|
|
padding: '4px 8px',
|
|
|
|
|
|
background: expertMode ? 'var(--accent)' : 'var(--surface)',
|
|
|
|
|
|
color: expertMode ? 'white' : 'var(--text2)'
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
🔬 Experten-Modus
|
|
|
|
|
|
</button>
|
|
|
|
|
|
)}
|
2026-03-26 11:52:26 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{showValues && (
|
|
|
|
|
|
<div style={{ marginTop: 12, fontSize: 11 }}>
|
|
|
|
|
|
<table style={{ width: '100%', borderCollapse: 'collapse' }}>
|
|
|
|
|
|
<thead>
|
|
|
|
|
|
<tr style={{ borderBottom: '1px solid var(--border)', textAlign: 'left' }}>
|
|
|
|
|
|
<th style={{ padding: '6px 8px', color: 'var(--text3)', fontWeight: 600 }}>Platzhalter</th>
|
|
|
|
|
|
<th style={{ padding: '6px 8px', color: 'var(--text3)', fontWeight: 600 }}>Wert</th>
|
|
|
|
|
|
<th style={{ padding: '6px 8px', color: 'var(--text3)', fontWeight: 600 }}>Beschreibung</th>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
</thead>
|
|
|
|
|
|
<tbody>
|
feat: category grouping in value table (Issue #47)
FEATURE: Gruppierung nach Kategorien
- Wertetabelle jetzt nach Modulen/Kategorien gruppiert
- Bessere Übersicht und Zuordnung der Werte
BACKEND: Category Metadata
- Für normale Platzhalter: Kategorie aus Catalog (Profil, Körper, Ernährung, etc.)
- Für extrahierte Werte: "Stage X - [Output Name]"
- Für Rohdaten: "Stage X - Rohdaten"
- Fallback: "Sonstiges"
FRONTEND: Grouped Display
- sortedCategories: Sortierung (Normal → Stage Outputs → Rohdaten)
- Section Headers: Grauer Hintergrund mit Kategorie-Name
- React.Fragment für Gruppierung
SORTIERUNG:
1. Normale Kategorien (Profil, Körper, Ernährung, Training, etc.)
2. Stage Outputs (Stage 1 - Body, Stage 1 - Nutrition, etc.)
3. Rohdaten (Stage 1 - Rohdaten, Stage 2 - Rohdaten)
4. Innerhalb: Alphabetisch
BEISPIEL:
┌────────────────────────────────────────────┐
│ PROFIL │
├────────────────────────────────────────────┤
│ name │ Lars │ Name des Nutzers │
│ age │ 55 │ Alter in Jahren │
├────────────────────────────────────────────┤
│ KÖRPER │
├────────────────────────────────────────────┤
│ weight_... │ 85.2 kg │ Aktuelles Gewicht │
│ bmi │ 26.6 │ Body Mass Index │
├────────────────────────────────────────────┤
│ ERNÄHRUNG │
├────────────────────────────────────────────┤
│ kcal_avg │ 1427... │ Durchschn. Kalorien│
│ protein... │ 106g... │ Durchschn. Protein │
├────────────────────────────────────────────┤
│ STAGE 1 - BODY │
├────────────────────────────────────────────┤
│ ↳ bmi │ 26.6 │ Aus Stage 1 (body) │
│ ↳ trend │ sinkend │ Aus Stage 1 (body) │
├────────────────────────────────────────────┤
│ STAGE 1 - NUTRITION │
├────────────────────────────────────────────┤
│ ↳ kcal_... │ 1427 │ Aus Stage 1 (nutr.)│
└────────────────────────────────────────────┘
Experten-Modus zusätzlich:
├────────────────────────────────────────────┤
│ STAGE 1 - ROHDATEN │
├────────────────────────────────────────────┤
│ 🔬 stage...│ {"bmi"..│ Rohdaten Stage 1 │
└────────────────────────────────────────────┘
version: 9.10.0 (feature)
module: prompts 2.5.0, insights 1.8.0
2026-03-26 12:59:52 +01:00
|
|
|
|
{sortedCategories.map(category => (
|
|
|
|
|
|
<React.Fragment key={category}>
|
|
|
|
|
|
{/* Category Header */}
|
|
|
|
|
|
<tr style={{ background: 'var(--surface2)', borderTop: '2px solid var(--border)' }}>
|
|
|
|
|
|
<td colSpan="3" style={{
|
|
|
|
|
|
padding: '8px',
|
|
|
|
|
|
fontWeight: 600,
|
|
|
|
|
|
fontSize: 11,
|
|
|
|
|
|
color: 'var(--text2)',
|
|
|
|
|
|
letterSpacing: '0.5px'
|
|
|
|
|
|
}}>
|
|
|
|
|
|
{category}
|
|
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
{/* Category Values */}
|
|
|
|
|
|
{groupedPlaceholders[category].map(([key, data]) => {
|
feat: extract individual values from stage outputs (Issue #47)
FEATURE: Basis-Analysen Einzelwerte
Vorher: stage_1_body → {"bmi": 26.6, "weight": "85.2kg"} (1 Zeile)
Jetzt: bmi → 26.6 (eigene Zeile)
weight → 85.2kg (eigene Zeile)
BACKEND: JSON-Extraktion
- Stage outputs (JSON) → extract individual fields
- extracted_values dict sammelt alle Einzelwerte
- Deduplizierung: Gleiche Keys nur einmal
- Flags:
- is_extracted: true → Wert aus Stage-Output extrahiert
- is_stage_raw: true → Rohdaten (JSON) nur Experten-Modus
BEISPIEL Stage 1 Output:
{
"stage_1_body": {
"bmi": 26.6,
"weight": "85.2 kg",
"trend": "sinkend"
}
}
→ Metadata:
{
"bmi": {
value: "26.6",
description: "Aus Stage 1 (stage_1_body)",
is_extracted: true
},
"weight": {
value: "85.2 kg",
description: "Aus Stage 1 (stage_1_body)",
is_extracted: true
},
"stage_1_body": {
value: "{\"bmi\": 26.6, ...}",
description: "Rohdaten Stage 1 (Basis-Analyse JSON)",
is_stage_raw: true
}
}
FRONTEND: Smart Filtering
Normal-Modus:
- Zeigt: Einzelwerte (bmi, weight, trend)
- Versteckt: Rohdaten (stage_1_body JSON)
- Filter: is_stage_raw === false
Experten-Modus:
- Zeigt: Alles (Einzelwerte + Rohdaten)
- Rohdaten: Grauer Hintergrund + 🔬 Icon
VISUAL Indicators:
↳ bmi → Extrahierter Wert (grün)
weight → Normaler Platzhalter (accent)
🔬 stage_1_* → Rohdaten JSON (grau, klein, nur Experten)
ERGEBNIS:
┌──────────────────────────────────────────┐
│ 📊 Verwendete Werte (8) (+2 ausgeblendet)│
│ ┌────────────────────────────────────────┐│
│ │ weight_aktuell │ 85.2 kg │ Gewicht ││ ← Normal
│ │ ↳ bmi │ 26.6 │ Aus St..││ ← Extrahiert
│ │ ↳ trend │ sinkend │ Aus St..││ ← Extrahiert
│ └────────────────────────────────────────┘│
└──────────────────────────────────────────┘
Experten-Modus zusätzlich:
│ 🔬 stage_1_body │ {"bmi":...│ Rohdaten││ ← JSON
version: 9.9.0 (feature)
module: prompts 2.4.0, insights 1.7.0
2026-03-26 12:55:53 +01:00
|
|
|
|
const isExtracted = data.is_extracted
|
|
|
|
|
|
const isStageRaw = data.is_stage_raw
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<tr key={key} style={{
|
|
|
|
|
|
borderBottom: '1px solid var(--border)',
|
|
|
|
|
|
background: isStageRaw && expertMode ? 'var(--surface)' : 'transparent'
|
2026-03-26 12:37:52 +01:00
|
|
|
|
}}>
|
feat: extract individual values from stage outputs (Issue #47)
FEATURE: Basis-Analysen Einzelwerte
Vorher: stage_1_body → {"bmi": 26.6, "weight": "85.2kg"} (1 Zeile)
Jetzt: bmi → 26.6 (eigene Zeile)
weight → 85.2kg (eigene Zeile)
BACKEND: JSON-Extraktion
- Stage outputs (JSON) → extract individual fields
- extracted_values dict sammelt alle Einzelwerte
- Deduplizierung: Gleiche Keys nur einmal
- Flags:
- is_extracted: true → Wert aus Stage-Output extrahiert
- is_stage_raw: true → Rohdaten (JSON) nur Experten-Modus
BEISPIEL Stage 1 Output:
{
"stage_1_body": {
"bmi": 26.6,
"weight": "85.2 kg",
"trend": "sinkend"
}
}
→ Metadata:
{
"bmi": {
value: "26.6",
description: "Aus Stage 1 (stage_1_body)",
is_extracted: true
},
"weight": {
value: "85.2 kg",
description: "Aus Stage 1 (stage_1_body)",
is_extracted: true
},
"stage_1_body": {
value: "{\"bmi\": 26.6, ...}",
description: "Rohdaten Stage 1 (Basis-Analyse JSON)",
is_stage_raw: true
}
}
FRONTEND: Smart Filtering
Normal-Modus:
- Zeigt: Einzelwerte (bmi, weight, trend)
- Versteckt: Rohdaten (stage_1_body JSON)
- Filter: is_stage_raw === false
Experten-Modus:
- Zeigt: Alles (Einzelwerte + Rohdaten)
- Rohdaten: Grauer Hintergrund + 🔬 Icon
VISUAL Indicators:
↳ bmi → Extrahierter Wert (grün)
weight → Normaler Platzhalter (accent)
🔬 stage_1_* → Rohdaten JSON (grau, klein, nur Experten)
ERGEBNIS:
┌──────────────────────────────────────────┐
│ 📊 Verwendete Werte (8) (+2 ausgeblendet)│
│ ┌────────────────────────────────────────┐│
│ │ weight_aktuell │ 85.2 kg │ Gewicht ││ ← Normal
│ │ ↳ bmi │ 26.6 │ Aus St..││ ← Extrahiert
│ │ ↳ trend │ sinkend │ Aus St..││ ← Extrahiert
│ └────────────────────────────────────────┘│
└──────────────────────────────────────────┘
Experten-Modus zusätzlich:
│ 🔬 stage_1_body │ {"bmi":...│ Rohdaten││ ← JSON
version: 9.9.0 (feature)
module: prompts 2.4.0, insights 1.7.0
2026-03-26 12:55:53 +01:00
|
|
|
|
<td style={{
|
|
|
|
|
|
padding: '6px 8px',
|
|
|
|
|
|
fontFamily: 'monospace',
|
|
|
|
|
|
color: isStageRaw ? 'var(--text3)' : (isExtracted ? '#6B8E23' : 'var(--accent)'),
|
|
|
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
|
|
verticalAlign: 'top',
|
|
|
|
|
|
fontSize: isStageRaw ? 10 : 11
|
|
|
|
|
|
}}>
|
|
|
|
|
|
{isExtracted && '↳ '}
|
|
|
|
|
|
{isStageRaw && '🔬 '}
|
|
|
|
|
|
{key}
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td style={{
|
|
|
|
|
|
padding: '6px 8px',
|
|
|
|
|
|
fontFamily: 'monospace',
|
|
|
|
|
|
wordBreak: 'break-word',
|
|
|
|
|
|
maxWidth: '400px',
|
|
|
|
|
|
verticalAlign: 'top',
|
|
|
|
|
|
fontSize: isStageRaw ? 9 : 11,
|
|
|
|
|
|
color: isStageRaw ? 'var(--text3)' : 'var(--text1)'
|
|
|
|
|
|
}}>
|
2026-03-26 13:17:58 +01:00
|
|
|
|
{isStageRaw ? (
|
|
|
|
|
|
<details style={{ cursor: 'pointer' }}>
|
|
|
|
|
|
<summary style={{
|
|
|
|
|
|
fontWeight: 600,
|
|
|
|
|
|
color: 'var(--accent)',
|
|
|
|
|
|
fontSize: 10,
|
|
|
|
|
|
marginBottom: '4px'
|
|
|
|
|
|
}}>
|
|
|
|
|
|
JSON anzeigen ▼
|
|
|
|
|
|
</summary>
|
|
|
|
|
|
<pre style={{
|
|
|
|
|
|
background: 'var(--surface2)',
|
|
|
|
|
|
padding: '8px',
|
|
|
|
|
|
borderRadius: '4px',
|
|
|
|
|
|
fontSize: 9,
|
|
|
|
|
|
overflow: 'auto',
|
|
|
|
|
|
maxHeight: '300px',
|
|
|
|
|
|
margin: 0
|
|
|
|
|
|
}}>
|
|
|
|
|
|
{data.value}
|
|
|
|
|
|
</pre>
|
|
|
|
|
|
</details>
|
|
|
|
|
|
) : data.value}
|
feat: extract individual values from stage outputs (Issue #47)
FEATURE: Basis-Analysen Einzelwerte
Vorher: stage_1_body → {"bmi": 26.6, "weight": "85.2kg"} (1 Zeile)
Jetzt: bmi → 26.6 (eigene Zeile)
weight → 85.2kg (eigene Zeile)
BACKEND: JSON-Extraktion
- Stage outputs (JSON) → extract individual fields
- extracted_values dict sammelt alle Einzelwerte
- Deduplizierung: Gleiche Keys nur einmal
- Flags:
- is_extracted: true → Wert aus Stage-Output extrahiert
- is_stage_raw: true → Rohdaten (JSON) nur Experten-Modus
BEISPIEL Stage 1 Output:
{
"stage_1_body": {
"bmi": 26.6,
"weight": "85.2 kg",
"trend": "sinkend"
}
}
→ Metadata:
{
"bmi": {
value: "26.6",
description: "Aus Stage 1 (stage_1_body)",
is_extracted: true
},
"weight": {
value: "85.2 kg",
description: "Aus Stage 1 (stage_1_body)",
is_extracted: true
},
"stage_1_body": {
value: "{\"bmi\": 26.6, ...}",
description: "Rohdaten Stage 1 (Basis-Analyse JSON)",
is_stage_raw: true
}
}
FRONTEND: Smart Filtering
Normal-Modus:
- Zeigt: Einzelwerte (bmi, weight, trend)
- Versteckt: Rohdaten (stage_1_body JSON)
- Filter: is_stage_raw === false
Experten-Modus:
- Zeigt: Alles (Einzelwerte + Rohdaten)
- Rohdaten: Grauer Hintergrund + 🔬 Icon
VISUAL Indicators:
↳ bmi → Extrahierter Wert (grün)
weight → Normaler Platzhalter (accent)
🔬 stage_1_* → Rohdaten JSON (grau, klein, nur Experten)
ERGEBNIS:
┌──────────────────────────────────────────┐
│ 📊 Verwendete Werte (8) (+2 ausgeblendet)│
│ ┌────────────────────────────────────────┐│
│ │ weight_aktuell │ 85.2 kg │ Gewicht ││ ← Normal
│ │ ↳ bmi │ 26.6 │ Aus St..││ ← Extrahiert
│ │ ↳ trend │ sinkend │ Aus St..││ ← Extrahiert
│ └────────────────────────────────────────┘│
└──────────────────────────────────────────┘
Experten-Modus zusätzlich:
│ 🔬 stage_1_body │ {"bmi":...│ Rohdaten││ ← JSON
version: 9.9.0 (feature)
module: prompts 2.4.0, insights 1.7.0
2026-03-26 12:55:53 +01:00
|
|
|
|
</td>
|
|
|
|
|
|
<td style={{
|
|
|
|
|
|
padding: '6px 8px',
|
|
|
|
|
|
color: 'var(--text3)',
|
|
|
|
|
|
fontSize: 10,
|
|
|
|
|
|
verticalAlign: 'top',
|
|
|
|
|
|
fontStyle: isExtracted ? 'italic' : 'normal'
|
|
|
|
|
|
}}>
|
|
|
|
|
|
{data.description || '—'}
|
|
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
feat: category grouping in value table (Issue #47)
FEATURE: Gruppierung nach Kategorien
- Wertetabelle jetzt nach Modulen/Kategorien gruppiert
- Bessere Übersicht und Zuordnung der Werte
BACKEND: Category Metadata
- Für normale Platzhalter: Kategorie aus Catalog (Profil, Körper, Ernährung, etc.)
- Für extrahierte Werte: "Stage X - [Output Name]"
- Für Rohdaten: "Stage X - Rohdaten"
- Fallback: "Sonstiges"
FRONTEND: Grouped Display
- sortedCategories: Sortierung (Normal → Stage Outputs → Rohdaten)
- Section Headers: Grauer Hintergrund mit Kategorie-Name
- React.Fragment für Gruppierung
SORTIERUNG:
1. Normale Kategorien (Profil, Körper, Ernährung, Training, etc.)
2. Stage Outputs (Stage 1 - Body, Stage 1 - Nutrition, etc.)
3. Rohdaten (Stage 1 - Rohdaten, Stage 2 - Rohdaten)
4. Innerhalb: Alphabetisch
BEISPIEL:
┌────────────────────────────────────────────┐
│ PROFIL │
├────────────────────────────────────────────┤
│ name │ Lars │ Name des Nutzers │
│ age │ 55 │ Alter in Jahren │
├────────────────────────────────────────────┤
│ KÖRPER │
├────────────────────────────────────────────┤
│ weight_... │ 85.2 kg │ Aktuelles Gewicht │
│ bmi │ 26.6 │ Body Mass Index │
├────────────────────────────────────────────┤
│ ERNÄHRUNG │
├────────────────────────────────────────────┤
│ kcal_avg │ 1427... │ Durchschn. Kalorien│
│ protein... │ 106g... │ Durchschn. Protein │
├────────────────────────────────────────────┤
│ STAGE 1 - BODY │
├────────────────────────────────────────────┤
│ ↳ bmi │ 26.6 │ Aus Stage 1 (body) │
│ ↳ trend │ sinkend │ Aus Stage 1 (body) │
├────────────────────────────────────────────┤
│ STAGE 1 - NUTRITION │
├────────────────────────────────────────────┤
│ ↳ kcal_... │ 1427 │ Aus Stage 1 (nutr.)│
└────────────────────────────────────────────┘
Experten-Modus zusätzlich:
├────────────────────────────────────────────┤
│ STAGE 1 - ROHDATEN │
├────────────────────────────────────────────┤
│ 🔬 stage...│ {"bmi"..│ Rohdaten Stage 1 │
└────────────────────────────────────────────┘
version: 9.10.0 (feature)
module: prompts 2.5.0, insights 1.8.0
2026-03-26 12:59:52 +01:00
|
|
|
|
)
|
|
|
|
|
|
})}
|
|
|
|
|
|
</React.Fragment>
|
|
|
|
|
|
))}
|
2026-03-26 11:52:26 +01:00
|
|
|
|
</tbody>
|
|
|
|
|
|
</table>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
2026-03-16 13:35:11 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default function Analysis() {
|
2026-03-26 07:50:13 +01:00
|
|
|
|
const { canUseAI } = useAuth()
|
2026-03-16 13:35:11 +01:00
|
|
|
|
const [prompts, setPrompts] = useState([])
|
|
|
|
|
|
const [allInsights, setAllInsights] = useState([])
|
|
|
|
|
|
const [loading, setLoading] = useState(null)
|
|
|
|
|
|
const [error, setError] = useState(null)
|
|
|
|
|
|
const [tab, setTab] = useState('run')
|
2026-03-26 07:50:13 +01:00
|
|
|
|
const [newResult, setNewResult] = useState(null)
|
|
|
|
|
|
const [aiUsage, setAiUsage] = useState(null)
|
2026-04-05 10:06:29 +02:00
|
|
|
|
/** Kategorie-Schlüssel aus `buildPipelineGroups` (Navigation); Detail = alle Pipelines dieser Kategorie */
|
|
|
|
|
|
const [activeCategoryKey, setActiveCategoryKey] = useState(null)
|
2026-04-05 08:52:40 +02:00
|
|
|
|
const [historyScopePick, setHistoryScopePick] = useState(null)
|
2026-04-13 11:23:16 +02:00
|
|
|
|
// NEW: Progress tracking for SSE workflows
|
|
|
|
|
|
const [progress, setProgress] = useState(null) // { total_nodes, completed_nodes, current_node_label }
|
2026-03-16 13:35:11 +01:00
|
|
|
|
|
|
|
|
|
|
const loadAll = async () => {
|
|
|
|
|
|
const [p, i] = await Promise.all([
|
2026-03-16 16:52:36 +01:00
|
|
|
|
api.listPrompts(),
|
2026-03-16 13:35:11 +01:00
|
|
|
|
api.listInsights()
|
|
|
|
|
|
])
|
|
|
|
|
|
setPrompts(Array.isArray(p)?p:[])
|
|
|
|
|
|
setAllInsights(Array.isArray(i)?i:[])
|
|
|
|
|
|
}
|
2026-03-21 06:43:10 +01:00
|
|
|
|
|
|
|
|
|
|
useEffect(()=>{
|
|
|
|
|
|
loadAll()
|
|
|
|
|
|
// Load feature usage for badges
|
|
|
|
|
|
api.getFeatureUsage().then(features => {
|
|
|
|
|
|
const aiFeature = features.find(f => f.feature_id === 'ai_calls')
|
|
|
|
|
|
setAiUsage(aiFeature)
|
|
|
|
|
|
}).catch(err => console.error('Failed to load usage:', err))
|
|
|
|
|
|
},[])
|
2026-03-16 13:35:11 +01:00
|
|
|
|
|
2026-04-05 08:52:40 +02:00
|
|
|
|
useEffect(() => {
|
2026-04-11 11:42:54 +02:00
|
|
|
|
const list = prompts.filter(isAnalysisOfferPrompt)
|
2026-04-05 10:06:29 +02:00
|
|
|
|
setActiveCategoryKey(prev => {
|
2026-04-05 08:52:40 +02:00
|
|
|
|
if (!list.length) return null
|
2026-04-05 09:04:08 +02:00
|
|
|
|
const groups = buildPipelineGroups(list)
|
2026-04-05 10:06:29 +02:00
|
|
|
|
const keys = groups.map(g => g.categoryKey)
|
|
|
|
|
|
if (prev && keys.includes(prev)) return prev
|
|
|
|
|
|
return groups[0]?.categoryKey ?? null
|
2026-04-05 08:52:40 +02:00
|
|
|
|
})
|
|
|
|
|
|
}, [prompts])
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-04-05 10:06:29 +02:00
|
|
|
|
if (!newResult?.scope) return
|
2026-04-11 11:42:54 +02:00
|
|
|
|
const list = prompts.filter(isAnalysisOfferPrompt)
|
2026-04-05 10:06:29 +02:00
|
|
|
|
const groups = buildPipelineGroups(list)
|
|
|
|
|
|
const g = groups.find(gg => gg.prompts.some(p => p.slug === newResult.scope))
|
|
|
|
|
|
if (g) setActiveCategoryKey(g.categoryKey)
|
|
|
|
|
|
}, [newResult?.scope, prompts])
|
2026-04-05 08:52:40 +02:00
|
|
|
|
|
2026-03-16 13:35:11 +01:00
|
|
|
|
const runPrompt = async (slug) => {
|
2026-04-13 11:23:16 +02:00
|
|
|
|
setLoading(slug); setError(null); setNewResult(null); setProgress(null)
|
2026-03-16 13:35:11 +01:00
|
|
|
|
try {
|
2026-04-13 11:23:16 +02:00
|
|
|
|
// Use SSE-based executor for long-running workflows
|
2026-04-13 12:38:55 +02:00
|
|
|
|
const result = await api.executeUnifiedPromptStream(slug, null, null, true, true, (event) => {
|
2026-04-13 11:23:16 +02:00
|
|
|
|
// Progress callback: update UI in real-time
|
|
|
|
|
|
if (event.type === 'execution_started') {
|
|
|
|
|
|
setProgress({ total_nodes: 0, completed_nodes: 0, current_node_label: 'Starte...' })
|
|
|
|
|
|
} else if (event.type === 'node_complete') {
|
|
|
|
|
|
setProgress({
|
|
|
|
|
|
total_nodes: event.total_nodes || 0,
|
|
|
|
|
|
completed_nodes: event.completed_nodes || 0,
|
|
|
|
|
|
current_node_label: event.node_label || `Node ${event.node_id}`
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2026-03-26 09:38:58 +01:00
|
|
|
|
|
|
|
|
|
|
// Transform result to match old format for InsightCard
|
|
|
|
|
|
let content = ''
|
|
|
|
|
|
if (result.type === 'pipeline') {
|
|
|
|
|
|
// For pipeline, extract final output
|
|
|
|
|
|
const finalOutput = result.output || {}
|
|
|
|
|
|
if (typeof finalOutput === 'object' && Object.keys(finalOutput).length === 1) {
|
|
|
|
|
|
content = Object.values(finalOutput)[0]
|
|
|
|
|
|
} else {
|
|
|
|
|
|
content = JSON.stringify(finalOutput, null, 2)
|
|
|
|
|
|
}
|
2026-04-11 11:42:54 +02:00
|
|
|
|
} else if (result.type === 'workflow') {
|
2026-04-11 12:04:35 +02:00
|
|
|
|
content = getWorkflowDisplayContent(result.aggregated_result)
|
2026-03-26 09:38:58 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
// For base prompts, use output directly
|
|
|
|
|
|
content = typeof result.output === 'string' ? result.output : JSON.stringify(result.output, null, 2)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-26 12:29:05 +01:00
|
|
|
|
// Build metadata from debug info (same logic as backend)
|
|
|
|
|
|
let metadata = null
|
|
|
|
|
|
if (result.debug && result.debug.resolved_placeholders) {
|
|
|
|
|
|
const placeholders = {}
|
|
|
|
|
|
const resolved = result.debug.resolved_placeholders
|
|
|
|
|
|
|
2026-04-11 11:42:54 +02:00
|
|
|
|
// For pipeline, collect from all stages (Workflow: kein gleiches debug-Schema)
|
2026-03-26 12:29:05 +01:00
|
|
|
|
if (result.type === 'pipeline' && result.debug.stages) {
|
|
|
|
|
|
for (const stage of result.debug.stages) {
|
|
|
|
|
|
for (const promptDebug of (stage.prompts || [])) {
|
|
|
|
|
|
const stageResolved = promptDebug.resolved_placeholders || promptDebug.ref_debug?.resolved_placeholders || {}
|
|
|
|
|
|
for (const [key, value] of Object.entries(stageResolved)) {
|
|
|
|
|
|
if (!placeholders[key]) {
|
|
|
|
|
|
placeholders[key] = { value, description: '' }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// For base prompts
|
|
|
|
|
|
for (const [key, value] of Object.entries(resolved)) {
|
|
|
|
|
|
placeholders[key] = { value, description: '' }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Object.keys(placeholders).length > 0) {
|
|
|
|
|
|
metadata = { prompt_type: result.type, placeholders }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-13 12:41:12 +02:00
|
|
|
|
setNewResult({
|
|
|
|
|
|
scope: slug,
|
|
|
|
|
|
content,
|
|
|
|
|
|
metadata,
|
|
|
|
|
|
node_states: result.node_states, // For workflow debug panel
|
|
|
|
|
|
result_type: result.type,
|
|
|
|
|
|
aggregated_result: result.aggregated_result
|
|
|
|
|
|
})
|
2026-03-26 07:50:13 +01:00
|
|
|
|
await loadAll()
|
|
|
|
|
|
setTab('run')
|
2026-03-16 13:35:11 +01:00
|
|
|
|
} catch(e) {
|
|
|
|
|
|
setError('Fehler: ' + e.message)
|
2026-04-13 11:23:16 +02:00
|
|
|
|
} finally {
|
|
|
|
|
|
setLoading(null)
|
|
|
|
|
|
setProgress(null) // Clear progress
|
|
|
|
|
|
}
|
2026-03-16 13:35:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const deleteInsight = async (id) => {
|
|
|
|
|
|
if (!confirm('Analyse löschen?')) return
|
2026-03-26 11:40:19 +01:00
|
|
|
|
try {
|
|
|
|
|
|
await api.deleteInsight(id)
|
|
|
|
|
|
if (newResult?.id === id) setNewResult(null)
|
|
|
|
|
|
await loadAll()
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
setError('Löschen fehlgeschlagen: ' + e.message)
|
|
|
|
|
|
}
|
2026-03-16 13:35:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Group insights by scope for history view
|
|
|
|
|
|
const grouped = {}
|
|
|
|
|
|
allInsights.forEach(ins => {
|
|
|
|
|
|
const key = ins.scope || 'sonstige'
|
|
|
|
|
|
grouped[key] = grouped[key] || []
|
|
|
|
|
|
grouped[key].push(ins)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-04-11 11:42:54 +02:00
|
|
|
|
// Aktive Pipeline- + Workflow-Prompts (nach DB-Kategorie gruppiert)
|
2026-04-05 09:04:08 +02:00
|
|
|
|
const { pipelinePrompts, pipelineGroups } = useMemo(() => {
|
2026-04-11 11:42:54 +02:00
|
|
|
|
const list = prompts.filter(isAnalysisOfferPrompt)
|
2026-04-05 09:04:08 +02:00
|
|
|
|
return { pipelinePrompts: list, pipelineGroups: buildPipelineGroups(list) }
|
|
|
|
|
|
}, [prompts])
|
2026-03-19 07:47:59 +01:00
|
|
|
|
|
2026-04-05 08:52:40 +02:00
|
|
|
|
const historyScopeKeys = Object.keys(grouped).sort((a, b) => a.localeCompare(b))
|
|
|
|
|
|
const activeHistoryScope =
|
|
|
|
|
|
historyScopeKeys.length === 0
|
|
|
|
|
|
? null
|
|
|
|
|
|
: historyScopeKeys.includes(historyScopePick)
|
|
|
|
|
|
? historyScopePick
|
|
|
|
|
|
: historyScopeKeys[0]
|
|
|
|
|
|
|
2026-03-16 13:35:11 +01:00
|
|
|
|
return (
|
2026-04-05 08:52:40 +02:00
|
|
|
|
<div className="analysis-page">
|
|
|
|
|
|
<div className="analysis-page__header">
|
2026-04-05 12:07:11 +02:00
|
|
|
|
<div>
|
|
|
|
|
|
<h1 className="page-title" style={{ margin: 0 }}>KI-Analyse</h1>
|
|
|
|
|
|
<p style={{ fontSize: 12, color: 'var(--text3)', margin: '8px 0 0', lineHeight: 1.5, maxWidth: 520 }}>
|
|
|
|
|
|
Ziele und Fokusbereiche steuern den Kontext der Auswertungen –{' '}
|
|
|
|
|
|
<Link to="/goals" style={{ color: 'var(--accent)', fontWeight: 600 }}>unter „Ziele“ konfigurieren</Link>
|
|
|
|
|
|
{' '}(auch über die untere Navigation).
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
2026-03-26 16:50:22 +01:00
|
|
|
|
</div>
|
2026-03-16 13:35:11 +01:00
|
|
|
|
|
|
|
|
|
|
<div className="tabs">
|
2026-04-05 08:52:40 +02:00
|
|
|
|
<button type="button" className={'tab'+(tab==='run'?' active':'')} onClick={()=>setTab('run')}>Analysen starten</button>
|
|
|
|
|
|
<button type="button" className={'tab'+(tab==='history'?' active':'')} onClick={()=>setTab('history')}>
|
2026-03-16 13:35:11 +01:00
|
|
|
|
Verlauf
|
|
|
|
|
|
{allInsights.length>0 && <span style={{marginLeft:4,fontSize:10,background:'var(--accent)',
|
|
|
|
|
|
color:'white',padding:'1px 5px',borderRadius:8}}>{allInsights.length}</span>}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{error && (
|
|
|
|
|
|
<div style={{padding:'10px 14px',background:'#FCEBEB',borderRadius:8,fontSize:13,
|
|
|
|
|
|
color:'#D85A30',marginBottom:12,lineHeight:1.5}}>
|
|
|
|
|
|
{error.includes('nicht aktiviert') || error.includes('Limit')
|
|
|
|
|
|
? <>🔒 <strong>KI-Zugang eingeschränkt</strong><br/>
|
|
|
|
|
|
Dein Profil hat keinen Zugang zu KI-Analysen oder das Tageslimit wurde erreicht.
|
|
|
|
|
|
Bitte den Admin kontaktieren.</>
|
|
|
|
|
|
: error}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{/* ── Analysen starten ── */}
|
|
|
|
|
|
{tab==='run' && (
|
|
|
|
|
|
<div>
|
2026-04-05 11:39:15 +02:00
|
|
|
|
{/* Fallback: Ergebnis oben nur wenn keine Pipeline-Split-Ansicht (z. B. keine Prompts) */}
|
|
|
|
|
|
{newResult && !(canUseAI && pipelinePrompts.length > 0) && (
|
2026-03-16 13:35:11 +01:00
|
|
|
|
<div style={{marginBottom:16}}>
|
|
|
|
|
|
<div style={{fontSize:12,fontWeight:600,color:'var(--accent)',marginBottom:8}}>
|
|
|
|
|
|
✅ Neue Analyse erstellt:
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<InsightCard
|
|
|
|
|
|
ins={{...newResult, created: new Date().toISOString()}}
|
|
|
|
|
|
onDelete={deleteInsight}
|
|
|
|
|
|
defaultOpen={true}
|
2026-03-25 06:44:22 +01:00
|
|
|
|
prompts={prompts}
|
2026-03-16 13:35:11 +01:00
|
|
|
|
/>
|
2026-04-13 12:41:12 +02:00
|
|
|
|
{newResult.node_states && (
|
|
|
|
|
|
<WorkflowDebugPanel nodeStates={newResult.node_states} />
|
|
|
|
|
|
)}
|
2026-03-16 13:35:11 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{!canUseAI && (
|
|
|
|
|
|
<div style={{padding:'14px 16px',background:'#FCEBEB',borderRadius:10,
|
|
|
|
|
|
border:'1px solid #D85A3033',marginBottom:16}}>
|
|
|
|
|
|
<div style={{fontSize:14,fontWeight:600,color:'#D85A30',marginBottom:4}}>
|
|
|
|
|
|
🔒 KI-Analysen nicht freigeschaltet
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div style={{fontSize:13,color:'var(--text2)',lineHeight:1.5}}>
|
|
|
|
|
|
Dein Profil hat keinen Zugang zu KI-Analysen.
|
|
|
|
|
|
Bitte den Admin bitten, KI für dein Profil zu aktivieren
|
|
|
|
|
|
(Einstellungen → Admin → Profil bearbeiten).
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
2026-03-26 07:50:13 +01:00
|
|
|
|
{canUseAI && pipelinePrompts.length > 0 && (
|
2026-04-05 08:52:40 +02:00
|
|
|
|
<>
|
|
|
|
|
|
<p style={{fontSize:13,color:'var(--text2)',marginBottom:14,lineHeight:1.6}}>
|
2026-04-11 12:19:06 +02:00
|
|
|
|
Zuerst die <strong>Kategorie</strong> wählen (Chip-Leiste bzw. Seitenleiste). Alle{' '}
|
|
|
|
|
|
<strong>Pipeline- und Workflow-Auswertungen</strong> dieser Kategorie erscheinen im Detailbereich
|
|
|
|
|
|
(rechts auf Desktop, darunter auf Mobil). Bei Workflows legst du Kategorie, Titel und Kurztext in der{' '}
|
|
|
|
|
|
<strong>Start-Node</strong> des Workflow-Editors fest; bei Pipelines im Admin unter KI-Prompts.
|
2026-04-05 08:52:40 +02:00
|
|
|
|
</p>
|
|
|
|
|
|
<div className="analysis-split">
|
|
|
|
|
|
<div className="analysis-split__nav-wrap">
|
2026-04-05 10:06:29 +02:00
|
|
|
|
<nav className="analysis-split__nav" aria-label="KI-Analyse-Kategorien">
|
2026-04-05 09:04:08 +02:00
|
|
|
|
{pipelineGroups.map(({ categoryKey, label, prompts: inGroup }) => (
|
2026-04-05 10:06:29 +02:00
|
|
|
|
<button
|
|
|
|
|
|
key={categoryKey}
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
className={
|
|
|
|
|
|
'analysis-split__nav-item' +
|
|
|
|
|
|
(activeCategoryKey === categoryKey ? ' analysis-split__nav-item--active' : '')
|
|
|
|
|
|
}
|
|
|
|
|
|
onClick={() => setActiveCategoryKey(categoryKey)}
|
|
|
|
|
|
aria-current={activeCategoryKey === categoryKey ? 'page' : undefined}
|
|
|
|
|
|
>
|
|
|
|
|
|
{label}
|
|
|
|
|
|
<span className="analysis-split__nav-cat-count">({inGroup.length})</span>
|
|
|
|
|
|
</button>
|
2026-04-05 09:04:08 +02:00
|
|
|
|
))}
|
2026-04-05 08:52:40 +02:00
|
|
|
|
</nav>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="analysis-split__main">
|
2026-04-05 11:39:15 +02:00
|
|
|
|
{newResult && (
|
|
|
|
|
|
<div style={{ marginBottom: 20 }}>
|
|
|
|
|
|
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--accent)', marginBottom: 8 }}>
|
|
|
|
|
|
✅ Neue Analyse erstellt:
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<InsightCard
|
|
|
|
|
|
ins={{ ...newResult, created: new Date().toISOString() }}
|
|
|
|
|
|
onDelete={deleteInsight}
|
|
|
|
|
|
defaultOpen={true}
|
|
|
|
|
|
prompts={prompts}
|
|
|
|
|
|
/>
|
2026-04-13 12:41:12 +02:00
|
|
|
|
{newResult.node_states && (
|
|
|
|
|
|
<WorkflowDebugPanel nodeStates={newResult.node_states} />
|
|
|
|
|
|
)}
|
2026-04-05 11:39:15 +02:00
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2026-04-05 10:06:29 +02:00
|
|
|
|
{activeCategoryKey && (() => {
|
|
|
|
|
|
const group = pipelineGroups.find(g => g.categoryKey === activeCategoryKey)
|
|
|
|
|
|
if (!group?.prompts?.length) return null
|
2026-04-05 08:52:40 +02:00
|
|
|
|
return (
|
2026-04-05 10:06:29 +02:00
|
|
|
|
<>
|
|
|
|
|
|
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)', marginBottom: 12 }}>
|
|
|
|
|
|
{group.label} · {group.prompts.length} {group.prompts.length === 1 ? 'Analyse' : 'Analysen'}
|
2026-04-05 08:52:40 +02:00
|
|
|
|
</div>
|
2026-04-05 10:06:29 +02:00
|
|
|
|
{group.prompts.map(p => {
|
|
|
|
|
|
const existing = allInsights.find(i => i.scope === p.slug)
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div key={p.id} className="card" style={{marginBottom:16,borderColor:'var(--accent)',borderWidth:2}}>
|
|
|
|
|
|
<div style={{display:'flex',alignItems:'flex-start',gap:12,flexWrap:'wrap'}}>
|
|
|
|
|
|
<div style={{flex:1,minWidth:0}}>
|
|
|
|
|
|
<div className="badge-container-right" style={{fontWeight:700,fontSize:15,color:'var(--accent)'}}>
|
|
|
|
|
|
<span>{p.display_name || SLUG_LABELS[p.slug] || p.name}</span>
|
|
|
|
|
|
{aiUsage && <UsageBadge {...aiUsage} />}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{p.description && (
|
|
|
|
|
|
<div style={{fontSize:12,color:'var(--text2)',marginTop:3,lineHeight:1.5}}>
|
|
|
|
|
|
{p.description}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{existing && (
|
|
|
|
|
|
<div style={{fontSize:11,color:'var(--text3)',marginTop:3}}>
|
|
|
|
|
|
Letzte Analyse: {dayjs(existing.created).format('DD.MM.YYYY, HH:mm')}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div
|
|
|
|
|
|
title={aiUsage && !aiUsage.allowed ? `Limit erreicht (${aiUsage.used}/${aiUsage.limit}). Kontaktiere den Admin oder warte bis zum nächsten Reset.` : ''}
|
|
|
|
|
|
style={{display:'inline-block'}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
className="btn btn-primary"
|
|
|
|
|
|
style={{flexShrink:0,minWidth:100, cursor: (aiUsage && !aiUsage.allowed) ? 'not-allowed' : 'pointer'}}
|
|
|
|
|
|
onClick={() => runPrompt(p.slug)}
|
|
|
|
|
|
disabled={!!loading||!canUseAI||(aiUsage && !aiUsage.allowed)}
|
|
|
|
|
|
>
|
|
|
|
|
|
{loading===p.slug
|
2026-04-13 11:23:16 +02:00
|
|
|
|
? (progress
|
|
|
|
|
|
? <><div className="spinner" style={{width:13,height:13}}/> {progress.completed_nodes}/{progress.total_nodes} Nodes</>
|
|
|
|
|
|
: <><div className="spinner" style={{width:13,height:13}}/> Läuft…</>)
|
2026-04-05 10:06:29 +02:00
|
|
|
|
: (aiUsage && !aiUsage.allowed) ? '🔒 Limit'
|
|
|
|
|
|
: <><Brain size={13}/> Starten</>}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{existing && newResult?.id !== existing.id && (
|
|
|
|
|
|
<div style={{marginTop:8,borderTop:'1px solid var(--border)',paddingTop:8}}>
|
|
|
|
|
|
<InsightCard ins={existing} onDelete={deleteInsight} defaultOpen={false} prompts={prompts}/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
})}
|
|
|
|
|
|
</>
|
2026-04-05 08:52:40 +02:00
|
|
|
|
)
|
|
|
|
|
|
})()}
|
2026-03-16 13:35:11 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-04-05 08:52:40 +02:00
|
|
|
|
</>
|
|
|
|
|
|
)}
|
2026-03-26 07:50:13 +01:00
|
|
|
|
|
|
|
|
|
|
{canUseAI && pipelinePrompts.length === 0 && (
|
|
|
|
|
|
<div className="empty-state">
|
2026-04-11 12:19:06 +02:00
|
|
|
|
<p>Keine aktiven Pipeline- oder Workflow-Auswertungen verfügbar.</p>
|
2026-03-26 07:50:13 +01:00
|
|
|
|
<p style={{fontSize:12,color:'var(--text3)',marginTop:8}}>
|
2026-04-11 12:19:06 +02:00
|
|
|
|
Pipelines und Workflows werden im Admin unter KI-Prompts bzw. Workflow-Editor angelegt.
|
2026-03-26 07:50:13 +01:00
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
ROLLBACK: complete removal of broken feature enforcement system
Reverts all feature enforcement changes (commits 3745ebd, cbad50a, cd4d912, 8415509)
to restore original working functionality.
Issues caused by feature enforcement implementation:
- Export buttons disappeared and never reappeared
- KI analysis counter not incrementing
- New analyses not saving
- Pipeline appearing twice
- Many core features broken
Restored files to working state before enforcement implementation (commit 0210844):
- Backend: auth.py, insights.py, exportdata.py, importdata.py, nutrition.py, activity.py
- Frontend: Analysis.jsx, SettingsPage.jsx, api.js
- Removed: FeatureGate.jsx, useFeatureAccess.js
The original simple AI limit system (ai_enabled, ai_limit_day) is now active again.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-20 15:19:56 +01:00
|
|
|
|
)}
|
2026-03-16 13:35:11 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{/* ── Verlauf gruppiert ── */}
|
|
|
|
|
|
{tab==='history' && (
|
|
|
|
|
|
<div>
|
2026-04-05 08:52:40 +02:00
|
|
|
|
{allInsights.length===0 ? (
|
|
|
|
|
|
<div className="empty-state"><h3>Noch keine Analysen</h3></div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<div className="analysis-split">
|
|
|
|
|
|
<div className="analysis-split__nav-wrap">
|
|
|
|
|
|
<nav className="analysis-split__nav" aria-label="Gespeicherte Analysen">
|
|
|
|
|
|
{historyScopeKeys.map(scope => (
|
|
|
|
|
|
<button
|
|
|
|
|
|
key={scope}
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
className={'analysis-split__nav-item' + (activeHistoryScope === scope ? ' analysis-split__nav-item--active' : '')}
|
|
|
|
|
|
onClick={() => setHistoryScopePick(scope)}
|
|
|
|
|
|
aria-current={activeHistoryScope === scope ? 'page' : undefined}
|
|
|
|
|
|
>
|
2026-04-11 12:19:06 +02:00
|
|
|
|
{(() => {
|
|
|
|
|
|
const pr = prompts.find((p) => p.slug === scope)
|
|
|
|
|
|
return pr?.display_name || pr?.name || SLUG_LABELS[scope] || scope
|
|
|
|
|
|
})()}
|
2026-04-05 08:52:40 +02:00
|
|
|
|
<span className="muted" style={{ fontSize: 12 }}> ({grouped[scope].length})</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</nav>
|
2026-03-16 13:35:11 +01:00
|
|
|
|
</div>
|
2026-04-05 08:52:40 +02:00
|
|
|
|
<div className="analysis-split__main">
|
|
|
|
|
|
{activeHistoryScope && grouped[activeHistoryScope]?.map(i => (
|
|
|
|
|
|
<InsightCard key={i.id} ins={i} onDelete={deleteInsight} prompts={prompts}/>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2026-03-16 13:35:11 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|