mirror of
https://github.com/leonvanzyl/autocoder.git
synced 2026-01-30 06:12:06 +00:00
feat: Add image upload support for Spec Creation chat
Add the ability to attach images (JPEG, PNG) in the Spec Creation chat interface for Claude to analyze during app specification creation. Frontend changes: - Add ImageAttachment interface to types.ts with id, filename, mimeType, base64Data, previewUrl, and size fields - Update ChatMessage interface with optional attachments field - Update useSpecChat hook to accept and send attachments via WebSocket - Add file input, drag-drop support, and preview thumbnails to SpecCreationChat component with validation (5 MB max, JPEG/PNG only) - Update ChatMessage component to render image attachments with click-to-enlarge functionality Backend changes: - Add ImageAttachment Pydantic schema with base64 validation - Update spec_creation.py WebSocket handler to parse and validate image attachments from client messages - Update spec_chat_session.py to format multimodal content blocks for Claude API using async generator pattern Features: - Drag-and-drop or click paperclip button to attach images - Preview thumbnails with remove button before sending - File type validation (image/jpeg, image/png) - File size validation (5 MB maximum) - Images display in chat history - Click images to view full size - Cross-platform compatible (Windows, macOS, Linux) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,9 +5,10 @@ Pydantic Schemas
|
||||
Request/Response models for the API endpoints.
|
||||
"""
|
||||
|
||||
import base64
|
||||
from datetime import datetime
|
||||
from typing import Literal
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
|
||||
|
||||
# ============================================================================
|
||||
@@ -163,6 +164,38 @@ class WSAgentStatusMessage(BaseModel):
|
||||
status: str
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Spec Chat Schemas
|
||||
# ============================================================================
|
||||
|
||||
# Maximum image file size: 5 MB
|
||||
MAX_IMAGE_SIZE = 5 * 1024 * 1024
|
||||
|
||||
|
||||
class ImageAttachment(BaseModel):
|
||||
"""Image attachment from client for spec creation chat."""
|
||||
filename: str = Field(..., min_length=1, max_length=255)
|
||||
mimeType: Literal['image/jpeg', 'image/png']
|
||||
base64Data: str
|
||||
|
||||
@field_validator('base64Data')
|
||||
@classmethod
|
||||
def validate_base64_and_size(cls, v: str) -> str:
|
||||
"""Validate that base64 data is valid and within size limit."""
|
||||
try:
|
||||
decoded = base64.b64decode(v)
|
||||
if len(decoded) > MAX_IMAGE_SIZE:
|
||||
raise ValueError(
|
||||
f'Image size ({len(decoded) / (1024 * 1024):.1f} MB) exceeds '
|
||||
f'maximum of {MAX_IMAGE_SIZE // (1024 * 1024)} MB'
|
||||
)
|
||||
return v
|
||||
except Exception as e:
|
||||
if 'Image size' in str(e):
|
||||
raise
|
||||
raise ValueError(f'Invalid base64 data: {e}')
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Filesystem Schemas
|
||||
# ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user