[t-012] Create chat.py models — ChatRequest + SSEEvent types #12

Open
opened 2026-07-05 08:31:00 +00:00 by david · 0 comments
Owner

Goal

Define the Strawberry GraphQL / Pydantic models for chat requests and SSE events.

References

Reference

  • DESIGN.md §4 BFF models (chat.py)
  • DESIGN.md §5 API Contract (chat stream request/response)
  • DOMAIN.md §5 SSE Streaming Events

Implementation Steps

Implementation Steps

1. Create src/models/chat.py

Create chat request and SSE event models:

# src/models/chat.py
from pydantic import BaseModel, Field
from typing import Optional

class Attachment(BaseModel):
    staging_path: str
    name: str

class ChatRequest(BaseModel):
    message: str
    model: Optional[str] = None
    attachments: list[Attachment] = []

# SSE event types for internal processing
from enum import Enum

class SSEEventType(Enum):
    COMPONENT = "component"
    CHUNK = "chunk"
    COMPONENT_PATCH = "component_patch"
    COMPONENT_COMPLETE = "component_complete"
    DONE = "done"
    ERROR = "error"

class SSEEvent(BaseModel):
    event_type: SSEEventType
    data: dict  # varies by event type

Verification Gate

Verification Gate

Run:

cd /home/david/Projects/keryx-bff && uv run python -c "
from src.models.chat import ChatRequest, Attachment, SSEEventType
req = ChatRequest(message='Hello', attachments=[Attachment(staging_path='/tmp/keryx/file.pdf', name='file.pdf')])
assert req.message == 'Hello'
assert len(req.attachments) == 1
assert SSEEventType.COMPONENT.value == 'component'
print('OK')"
# Expected output: OK

STOP Conditions

STOP Conditions

  • If the ChatRequest model cannot be instantiated with attachments, stop and fix.

Depends on: t-004

## Goal Define the Strawberry GraphQL / Pydantic models for chat requests and SSE events. ## References ## Reference - DESIGN.md §4 BFF models (chat.py) - DESIGN.md §5 API Contract (chat stream request/response) - DOMAIN.md §5 SSE Streaming Events ## Implementation Steps ## Implementation Steps ### 1. Create `src/models/chat.py` Create chat request and SSE event models: ```python # src/models/chat.py from pydantic import BaseModel, Field from typing import Optional class Attachment(BaseModel): staging_path: str name: str class ChatRequest(BaseModel): message: str model: Optional[str] = None attachments: list[Attachment] = [] # SSE event types for internal processing from enum import Enum class SSEEventType(Enum): COMPONENT = "component" CHUNK = "chunk" COMPONENT_PATCH = "component_patch" COMPONENT_COMPLETE = "component_complete" DONE = "done" ERROR = "error" class SSEEvent(BaseModel): event_type: SSEEventType data: dict # varies by event type ``` ## Verification Gate ## Verification Gate Run: ```bash cd /home/david/Projects/keryx-bff && uv run python -c " from src.models.chat import ChatRequest, Attachment, SSEEventType req = ChatRequest(message='Hello', attachments=[Attachment(staging_path='/tmp/keryx/file.pdf', name='file.pdf')]) assert req.message == 'Hello' assert len(req.attachments) == 1 assert SSEEventType.COMPONENT.value == 'component' print('OK')" # Expected output: OK ``` ## STOP Conditions ## STOP Conditions - If the ChatRequest model cannot be instantiated with attachments, stop and fix. Depends on: t-004
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: david/keryx-bff#12
No description provided.