feat(T07): KI-Copilot with OpenRouter chat, voice input, action system, chat history

This commit is contained in:
2026-07-17 02:28:41 +02:00
parent cb89e3ff1e
commit 5cc9f8e9a9
24 changed files with 2878 additions and 188 deletions
+22 -43
View File
@@ -1,52 +1,31 @@
# Current Status
## T06: Verkaufsmodul + Rechtsdokumente + DATEV-Export + Sales UI
## T07: KI-Copilot (Text + Sprache) + Systemsteuerung + Copilot UI
**Status:** COMPLETED
### Backend
- ✅ Sale model (app/models/sale.py) - UUID PK, vehicle_id FK, buyer_contact_id FK, seller_contact_id FK nullable, sale_price DECIMAL, sale_date, status enum, is_gwg BOOLEAN, contract_pdf_path
- ✅ DATEVExport model (app/models/datev_export.py) - UUID PK, start_date, end_date, file_path, total_amount, created_at
- ✅ Sale schemas (app/schemas/sale.py) - SaleCreate, SaleUpdate, SaleResponse, SaleListResponse, ContractResponse, UstIdVerifyResponse
- ✅ DATEV schemas (app/schemas/datev.py) - DATEVExportCreate, DATEVExportResponse, DATEVExportListResponse
- ✅ Sale service (app/services/sale_service.py) - create_sale, get_sale, list_sales, update_sale, cancel_sale, delete_sale, regenerate_contract_pdf, verify_ust_id
- ✅ DATEV service (app/services/datev_service.py) - create_export, list_exports, get_export_csv
- ✅ Contract PDF utils (app/utils/contract_pdf.py) - HTML template with WeasyPrint, GwG-Klausel, USt-IdNr. field, async via asyncio.to_thread
- ✅ DATEV CSV utils (app/utils/datev.py) - Buchungsstapel format: Datum, Konto, Gegenkonto, Betrag, Belegfeld, Buchungstext
- ✅ Sales router (app/routers/sales.py) - GET/POST/PUT/DELETE /sales, POST/GET /sales/:id/contract, POST /sales/:id/verify-ust-id
- ✅ DATEV router (app/routers/datev.py) - POST /datev/export, GET /datev/exports, GET /datev/exports/:id/download
- ✅ Config updated - BZST_API_ENABLED=False, WEASYPRINT_OUTPUT_DIR
- ✅ main.py updated - sales + datev routers registered
- ✅ requirements.txt - weasyprint>=62.0 added
- ✅ models/__init__.py - all models imported for Base.metadata registration
- ✅ Backend tests (tests/test_sales.py, tests/test_datev.py) - 34 tests, all passing
- [x] models/copilot.py — CopilotSession, CopilotChat models
- [x] schemas/copilot.py — ChatRequest, ChatResponse, ActionRequest, ActionResponse, ChatHistoryResponse, VoiceRequest, VoiceResponse
- [x] routers/copilot.py — POST /chat, POST /action, GET /history, POST /voice
- [x] services/copilot_service.py — chat, execute_action, get_history, get_sessions, transcribe_audio, voice_chat
- [x] utils/copilot_actions.py — 5 actions: search_vehicles, search_contacts, get_sale_overview, create_vehicle, create_contact
- [x] utils/copilot_prompt.py — System prompt with ERP context and action definitions
- [x] tests/test_copilot.py — 28 endpoint+unit tests
- [x] tests/test_copilot_coverage.py — 20 service-level coverage tests
- [x] main.py — copilot router registered
### Frontend
- ✅ Sales lib (lib/sales.ts) - listSales, getSale, createSale, updateSale, deleteSale, regenerateContract, verifyUstId
- ✅ DATEV lib (lib/datev.ts) - createDatevExport, listDatevExports, getDatevDownloadUrl
- ✅ SaleList component - Sales table with status + date range filters, pagination
- ✅ SaleForm component - Sale create form with vehicle select, buyer input, price, GwG toggle
- ✅ ContractPreview component - PDF embed preview, regenerate button, download link
- ✅ DatevExport component - Date range picker, export list table, CSV download
- ✅ Pages: verkauf/page.tsx, verkauf/[id]/page.tsx, verkauf/neu/page.tsx
- ✅ Frontend tests (tests/sales.test.tsx, tests/datev.test.tsx) - 16 tests, all passing
- [x] lib/copilot.ts — API client functions
- [x] app/[locale]/ki-copilot/page.tsx — Copilot page
- [x] components/copilot/ChatInterface.tsx — Main chat interface
- [x] components/copilot/MessageList.tsx — Message list
- [x] components/copilot/ChatInput.tsx — Text input
- [x] components/copilot/VoiceInput.tsx — Voice input (Web Speech API)
- [x] components/copilot/ActionPreview.tsx — Action preview before execution
- [x] components/copilot/ChatHistory.tsx — Chat history sidebar
- [x] tests/copilot.test.tsx — 24 frontend tests
### Acceptance Criteria Met
- ✅ GET /api/v1/sales → 200 + paginated list with filter (date range, status)
- ✅ GET /api/v1/sales/:id → 200 + sale detail with vehicle + contact nested
- ✅ POST /api/v1/sales mit valid data → 201 + sale object
- ✅ POST /api/v1/sales ohne vehicle_id → 422
- ✅ POST /api/v1/sales ohne buyer_contact_id → 422
- ✅ PUT /api/v1/sales/:id → 200 + updated sale
- ✅ DELETE /api/v1/sales/:id → 200 (sale cancelled, vehicle status back to available)
- ✅ POST /api/v1/sales/:id/contract → 200 + regenerated contract PDF path
- ✅ GET /api/v1/sales/:id/contract → 200 + PDF content (application/pdf)
- ✅ Sale mit is_gwg=true und sale_price <= 800 → GwG-Klausel in contract
- ✅ POST /api/v1/sales/:id/verify-ust-id → 200 + {verified: false, message: 'BZSt API not available'}
- ✅ POST /api/v1/datev/export mit date range → 201 + DATEVExport object
- ✅ POST /api/v1/datev/export mit invalid date range → 422
- ✅ GET /api/v1/datev/exports → 200 + list of exports
- ✅ GET /api/v1/datev/exports/:id/download → 200 + CSV content (text/csv)
- ✅ DATEV CSV enthält korrekte Felder: Datum, Konto, Gegenkonto, Betrag, Belegfeld, Buchungstext
- ✅ Sale creation → Vehicle status='sold'
- ✅ Sale deletion → Vehicle status='available' (in_stock)
### Test Results
- Backend: 48 passed, 90% coverage (exceeds 80% requirement)
- Frontend: 24 passed