mirror of
https://github.com/leonvanzyl/autocoder.git
synced 2026-03-26 07:13:09 +00:00
feat: add document file upload support for spec creation and project expansion
Add support for uploading Markdown, Text, Word (.docx), CSV, Excel (.xlsx), PDF, and PowerPoint (.pptx) files in addition to existing JPEG/PNG image uploads in the spec creation and project expansion chat interfaces. Backend changes: - New server/utils/document_extraction.py: in-memory text extraction for all document formats using python-docx, openpyxl, PyPDF2, python-pptx (no disk persistence) - Rename ImageAttachment to FileAttachment across schemas, routers, and chat session services - Add build_attachment_content_blocks() helper in chat_constants.py to route images as image content blocks and documents as extracted text blocks - Separate size limits: 5MB for images, 20MB for documents - Handle extraction errors (corrupt files, encrypted PDFs) gracefully Frontend changes: - Widen accepted MIME types and file extensions in both chat components - Add resolveMimeType() fallback for browsers that don't set MIME on .md files - Document attachments display with FileText icon instead of image thumbnail - ChatMessage renders documents as compact pills with filename and size - Update help text from "attach images" to "attach files" Dependencies added: python-docx, openpyxl, PyPDF2, python-pptx Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -18,9 +18,11 @@ from typing import Any, AsyncGenerator, Optional
|
||||
from claude_agent_sdk import ClaudeAgentOptions, ClaudeSDKClient
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from ..schemas import ImageAttachment
|
||||
from ..schemas import FileAttachment
|
||||
from ..utils.document_extraction import DocumentExtractionError
|
||||
from .chat_constants import (
|
||||
ROOT_DIR,
|
||||
build_attachment_content_blocks,
|
||||
check_rate_limit_error,
|
||||
make_multimodal_message,
|
||||
safe_receive_response,
|
||||
@@ -201,7 +203,7 @@ class SpecChatSession:
|
||||
async def send_message(
|
||||
self,
|
||||
user_message: str,
|
||||
attachments: list[ImageAttachment] | None = None
|
||||
attachments: list[FileAttachment] | None = None
|
||||
) -> AsyncGenerator[dict, None]:
|
||||
"""
|
||||
Send user message and stream Claude's response.
|
||||
@@ -247,7 +249,7 @@ class SpecChatSession:
|
||||
async def _query_claude(
|
||||
self,
|
||||
message: str,
|
||||
attachments: list[ImageAttachment] | None = None
|
||||
attachments: list[FileAttachment] | None = None
|
||||
) -> AsyncGenerator[dict, None]:
|
||||
"""
|
||||
Internal method to query Claude and stream responses.
|
||||
@@ -273,21 +275,17 @@ class SpecChatSession:
|
||||
if message:
|
||||
content_blocks.append({"type": "text", "text": message})
|
||||
|
||||
# Add image blocks
|
||||
for att in attachments:
|
||||
content_blocks.append({
|
||||
"type": "image",
|
||||
"source": {
|
||||
"type": "base64",
|
||||
"media_type": att.mimeType,
|
||||
"data": att.base64Data,
|
||||
}
|
||||
})
|
||||
# Add attachment blocks (images as image blocks, documents as extracted text)
|
||||
try:
|
||||
content_blocks.extend(build_attachment_content_blocks(attachments))
|
||||
except DocumentExtractionError as e:
|
||||
yield {"type": "error", "content": str(e)}
|
||||
return
|
||||
|
||||
# Send multimodal content to Claude using async generator format
|
||||
# The SDK's query() accepts AsyncIterable[dict] for custom message formats
|
||||
await self.client.query(make_multimodal_message(content_blocks))
|
||||
logger.info(f"Sent multimodal message with {len(attachments)} image(s)")
|
||||
logger.info(f"Sent multimodal message with {len(attachments)} attachment(s)")
|
||||
else:
|
||||
# Text-only message: use string format
|
||||
await self.client.query(message)
|
||||
|
||||
Reference in New Issue
Block a user