feat: Improve file display, timezone handling, and LOT management

Changes:
- Fix datetime serialization with UTC 'Z' suffix for correct timezone display
- Add PDF upload support with extension fallback for MIME detection
- Fix LOT add/remove by creating new list for SQLAlchemy JSON change detection
- Add file message components (FileMessage, ImageLightbox, UploadPreview)
- Add multi-file upload support with progress tracking
- Link uploaded files to chat messages via message_id
- Include file attachments in AI report generation
- Update specs for file-storage, realtime-messaging, and ai-report-generation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
egg
2025-12-08 12:39:15 +08:00
parent 599802b818
commit 44822a561a
36 changed files with 2252 additions and 156 deletions

View File

@@ -50,7 +50,7 @@ The system SHALL maintain a permanent `users` table to store user display names
### Requirement: Report Data Collection
The system SHALL collect all relevant room data for AI processing, including messages, members, files, and room metadata.
The system SHALL collect all relevant room data for AI processing, including messages, members, files with their conversation context, and room metadata.
#### Scenario: Collect complete room data for report generation
@@ -62,9 +62,29 @@ The system SHALL collect all relevant room data for AI processing, including mes
- Room metadata (title, incident_type, severity, status, location, description, timestamps)
- All 50 messages sorted by created_at ascending
- All 5 members with their roles (owner, editor, viewer)
- All 3 files with metadata (filename, type, uploader, upload time)
- All 3 files with metadata (filename, type, uploader, upload time) AND their associated message context
- **AND** messages SHALL include sender display name (not just user_id)
- **AND** file references in messages SHALL be annotated as "[附件: filename.ext]"
- **AND** file references in messages SHALL be annotated with surrounding context
#### Scenario: Include file context in report data
- **GIVEN** a file "defect_photo.jpg" was uploaded with the message "發現產品表面瑕疵"
- **AND** the previous message was "Line 3 溫度異常升高中"
- **AND** the next message was "已通知維修人員處理"
- **WHEN** report data is collected
- **THEN** the file entry SHALL include:
```json
{
"file_id": "...",
"filename": "defect_photo.jpg",
"uploader_display_name": "陳工程師",
"uploaded_at": "2025-12-08T14:30:00+08:00",
"caption": "發現產品表面瑕疵",
"context_before": "Line 3 溫度異常升高中",
"context_after": "已通知維修人員處理"
}
```
- **AND** the AI prompt SHALL format files as:
`[附件: defect_photo.jpg] - 上傳者: 陳工程師 (14:30), 說明: "發現產品表面瑕疵" (前文: "Line 3 溫度異常升高中")`
#### Scenario: Handle room with no messages
@@ -82,8 +102,6 @@ The system SHALL collect all relevant room data for AI processing, including mes
- **AND** summarize older messages by day (e.g., "2025-12-01: 45 則訊息討論設備檢修")
- **AND** the total formatted content SHALL stay within token limits
---
### Requirement: DIFY AI Integration
The system SHALL integrate with DIFY Chat API to generate structured report content from collected room data.
@@ -126,7 +144,7 @@ The system SHALL integrate with DIFY Chat API to generate structured report cont
### Requirement: Document Assembly
The system SHALL assemble professional .docx documents from AI-generated content with embedded images from MinIO.
The system SHALL assemble professional .docx documents from AI-generated content with embedded images from MinIO and file context from conversations.
#### Scenario: Generate complete report document
@@ -142,8 +160,9 @@ The system SHALL assemble professional .docx documents from AI-generated content
- Section 4: 處理過程 (from AI resolution_process.content)
- Section 5: 目前狀態 (from AI current_status)
- Section 6: 最終處置結果 (from AI final_resolution, if has_resolution=true)
- Section 7: 附件 (embedded images + file list)
- Section 7: 附件 (embedded images with captions + file list with context)
- **AND** images SHALL be embedded at appropriate size (max width 15cm)
- **AND** each image SHALL include its caption from the upload message
- **AND** document SHALL use professional formatting (標楷體 or similar)
#### Scenario: Handle missing images during assembly
@@ -163,8 +182,6 @@ The system SHALL assemble professional .docx documents from AI-generated content
- **THEN** the system SHALL create a complete document without the embedded images section
- **AND** the attachments section SHALL show "本事件無附件檔案" if no files exist
---
### Requirement: Report Generation API
The system SHALL provide REST API endpoints for triggering report generation and downloading generated reports.