From 3896f8cad71c336f4b35203e725bade149a4fb17 Mon Sep 17 00:00:00 2001 From: Ender Date: Sat, 25 Oct 2025 21:18:22 +0200 Subject: [PATCH] feat: add real-time content streaming with live preview - Added streaming UI components with live content preview and token counter - Implemented new generateContentStream service for SSE-based content generation - Created comprehensive STREAMING_UI_GUIDE.md documentation with implementation details - Added streaming toggle checkbox with default enabled state - Enhanced StepGenerate component with progress bar and animated streaming display - Added error handling and graceful fallback for streaming failures --- apps/admin/STREAMING_UI_GUIDE.md | 212 ++++++++++++ .../src/components/steps/StepGenerate.tsx | 139 ++++++-- apps/admin/src/services/aiStream.ts | 169 ++++++++++ apps/api/STREAMING_GUIDE.md | 301 ++++++++++++++++++ apps/api/src/routes/ai.routes.ts | 29 +- .../src/services/ai/contentGeneratorStream.ts | 177 ++++++++++ 6 files changed, 1001 insertions(+), 26 deletions(-) create mode 100644 apps/admin/STREAMING_UI_GUIDE.md create mode 100644 apps/admin/src/services/aiStream.ts create mode 100644 apps/api/STREAMING_GUIDE.md create mode 100644 apps/api/src/services/ai/contentGeneratorStream.ts diff --git a/apps/admin/STREAMING_UI_GUIDE.md b/apps/admin/STREAMING_UI_GUIDE.md new file mode 100644 index 0000000..52af69a --- /dev/null +++ b/apps/admin/STREAMING_UI_GUIDE.md @@ -0,0 +1,212 @@ +# Streaming UI Implementation Guide + +## What You'll See + +### ✨ Real-Time Streaming Experience + +When you click "Generate Draft" with streaming enabled, you'll see: + +1. **Instant Feedback** (< 1 second) + - Button changes to "Streaming... (X tokens)" + - Linear progress bar appears + - "Live Generation" section opens automatically + +2. **Content Appears Word-by-Word** + - HTML content streams in real-time + - Formatted with headings, paragraphs, lists + - Pulsing blue border indicates active streaming + - Token counter updates live + +3. **Completion** + - Content moves to "Generated Draft" section + - Image placeholders detected + - Ready for next step + +## UI Features + +### **Streaming Toggle** ⚡ +``` +☑ Stream content in real-time ⚡ + See content being generated live (much faster feedback) +``` +- **Checked (default)**: Uses streaming API +- **Unchecked**: Uses original non-streaming API + +### **Live Generation Section** +- **Border**: Pulsing blue animation +- **Auto-scroll**: Follows new content +- **Max height**: 500px with scroll +- **Status**: "⚡ Content is being generated in real-time..." + +### **Progress Indicator** +- **Linear progress bar**: Animated while streaming +- **Token counter**: "Streaming content in real-time... 234 tokens generated" +- **Button text**: "Streaming... (234 tokens)" + +### **Error Handling** +- Errors shown in red alert +- Streaming stops gracefully +- Partial content preserved + +## Visual Flow + +``` +┌─────────────────────────────────────┐ +│ Generate Draft Button │ +│ [Streaming... (234 tokens)] │ +└─────────────────────────────────────┘ + ↓ +┌─────────────────────────────────────┐ +│ ▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░ │ ← Progress bar +│ Streaming... 234 tokens generated │ +└─────────────────────────────────────┘ + ↓ +┌─────────────────────────────────────┐ +│ ▼ Live Generation │ +│ ┌───────────────────────────────┐ │ +│ │

Introduction

│ │ ← Pulsing blue border +│ │

TypeScript is a...

│ │ +│ │

It provides...

│ │ +│ │

Key Features

│ │ +│ │