From f37936c84d3a85b6c0b6caab5791ebbb56d8bebc Mon Sep 17 00:00:00 2001 From: Lars Date: Thu, 26 Mar 2026 13:17:58 +0100 Subject: [PATCH] feat: show all stage outputs as collapsible JSON in expert mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backend: - Add ALL stage outputs to metadata (not just referenced ones) - Format JSON with indent for readability - Description: 'Zwischenergebnis aus Stage X' Frontend: - Stage raw values shown in collapsible
element - JSON formatted in
 tag with syntax highlighting
- 'JSON anzeigen ▼' summary for better UX

Fixes: Stage X - Rohdaten now shows intermediate results
---
 backend/routers/prompts.py      | 48 ++++++++++++++++++---------------
 frontend/src/pages/Analysis.jsx | 24 ++++++++++++++++-
 2 files changed, 49 insertions(+), 23 deletions(-)

diff --git a/backend/routers/prompts.py b/backend/routers/prompts.py
index 77cd2b7..65b3ae7 100644
--- a/backend/routers/prompts.py
+++ b/backend/routers/prompts.py
@@ -900,6 +900,20 @@ async def execute_unified_prompt(
                             'category': category
                         }
 
+                # Add all stage outputs (raw JSON) for expert mode - regardless of whether referenced
+                for stage_key, stage_value in stage_outputs.items():
+                    if stage_key not in metadata['placeholders']:
+                        stage_parts = stage_key.split('_')
+                        stage_num = stage_parts[1] if len(stage_parts) > 1 else '?'
+                        output_name = '_'.join(stage_parts[2:]) if len(stage_parts) > 2 else 'output'
+
+                        metadata['placeholders'][stage_key] = {
+                            'value': json.dumps(stage_value, ensure_ascii=False, indent=2) if isinstance(stage_value, dict) else str(stage_value),
+                            'description': f"Zwischenergebnis aus Stage {stage_num} ({output_name})",
+                            'is_stage_raw': True,
+                            'category': f"Stage {stage_num} - Rohdaten"
+                        }
+
                 # Collect all resolved placeholders from prompts (input placeholders)
                 for stage_debug in stages_debug:
                     for prompt_debug in stage_debug.get('prompts', []):
@@ -912,33 +926,23 @@ async def execute_unified_prompt(
 
                         for key in resolved_keys:
                             if key not in metadata['placeholders']:  # Avoid duplicates
-                                # Get value: first try stage outputs, then cleaned_values
-                                value = stage_outputs.get(key, cleaned_values.get(key, ''))
+                                # Get value from cleaned_values
+                                value = cleaned_values.get(key, '')
 
-                                # For stage output placeholders (raw JSON), add special description
-                                if key.startswith('stage_'):
-                                    stage_parts = key.split('_')
-                                    stage_num = stage_parts[1] if len(stage_parts) > 1 else '?'
-                                    desc = f"Rohdaten Stage {stage_num} (Basis-Analyse JSON)"
-                                    category = f"Stage {stage_num} - Rohdaten"
-                                    is_stage_raw = True
-                                else:
-                                    # Find description and category in catalog
-                                    desc = None
-                                    category = 'Sonstiges'
-                                    for cat_name, cat_items in catalog.items():
-                                        matching = [item for item in cat_items if item['key'] == key]
-                                        if matching:
-                                            desc = matching[0].get('description', '')
-                                            category = cat_name
-                                            break
-                                    desc = desc or ''
-                                    is_stage_raw = False
+                                # Find description and category in catalog
+                                desc = None
+                                category = 'Sonstiges'
+                                for cat_name, cat_items in catalog.items():
+                                    matching = [item for item in cat_items if item['key'] == key]
+                                    if matching:
+                                        desc = matching[0].get('description', '')
+                                        category = cat_name
+                                        break
+                                desc = desc or ''
 
                                 metadata['placeholders'][key] = {
                                     'value': value if isinstance(value, str) else json.dumps(value, ensure_ascii=False),
                                     'description': desc,
-                                    'is_stage_raw': is_stage_raw,  # Mark raw stage outputs for expert mode
                                     'category': category
                                 }
 
diff --git a/frontend/src/pages/Analysis.jsx b/frontend/src/pages/Analysis.jsx
index 61a232b..4cba2e8 100644
--- a/frontend/src/pages/Analysis.jsx
+++ b/frontend/src/pages/Analysis.jsx
@@ -224,7 +224,29 @@ function InsightCard({ ins, onDelete, defaultOpen=false, prompts=[] }) {
                               fontSize: isStageRaw ? 9 : 11,
                               color: isStageRaw ? 'var(--text3)' : 'var(--text1)'
                             }}>
-                              {data.value}
+                              {isStageRaw ? (
+                                
+ + JSON anzeigen ▼ + +
+                                    {data.value}
+                                  
+
+ ) : data.value}