fix: wire image uploads into correct chat endpoint (unified_chat_service)

The frontend calls /ai-sessions/{id}/chat (unified_chat_service), not
/assistant/chats/{id}/messages (assistant_chat_service). The previous
commit wired images into the wrong backend. This fixes it:

- ai_session.py schema: add upload_ids to ChatMessageRequest
- ai_sessions.py endpoint: fetch images via _fetch_upload_images
- unified_chat_service: accept and forward images to _call_ai

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
chihlasm
2026-03-24 05:02:34 +00:00
parent 1c0f912cf6
commit 36ca830481
3 changed files with 14 additions and 0 deletions

View File

@@ -280,6 +280,12 @@ async def send_chat_message(
user_id = current_user.id
account_id = current_user.account_id
# Fetch attached images from S3 (if any)
images = None
if data.upload_ids:
from app.api.endpoints.assistant_chat import _fetch_upload_images
images = await _fetch_upload_images(data.upload_ids, account_id, db) or None
try:
ai_content, suggested_flows, session = await unified_chat_service.send_chat_message(
session_id=session_id,
@@ -287,6 +293,7 @@ async def send_chat_message(
account_id=account_id,
message=data.message,
db=db,
images=images,
)
except ValueError as e:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))

View File

@@ -245,6 +245,7 @@ class ChatSessionCreateResponse(BaseModel):
class ChatMessageRequest(BaseModel):
"""Send a message in a chat session."""
message: str = Field(..., min_length=1, max_length=8000)
upload_ids: list[UUID] = Field(default_factory=list, max_length=10)
class ChatMessageResponse(BaseModel):

View File

@@ -57,9 +57,14 @@ async def send_chat_message(
account_id: UUID,
message: str,
db: AsyncSession,
images: list[dict[str, Any]] | None = None,
) -> tuple[str, list[dict[str, Any]], AISession]:
"""Send a message in a chat session and get AI response.
Args:
images: Optional list of {"media_type": str, "data": str (base64)}
for vision content attached to this message.
Returns (ai_content, suggested_flows, session).
"""
result = await db.execute(
@@ -105,6 +110,7 @@ async def send_chat_message(
rag_context=rag_context,
history=ai_messages,
new_message=message,
images=images,
)
# Append messages to conversation_messages