Create SSE endpoint for project events #34

Closed
opened 2025-12-29 23:48:24 +00:00 by cardosofelipe · 0 comments

Description

Implement Server-Sent Events (SSE) endpoint for real-time project updates.

Requirements

Endpoint

GET /api/v1/projects/{project_id}/events/stream

Implementation

@router.get("/projects/{project_id}/events/stream")
async def stream_events(
    project_id: UUID,
    current_user: User = Depends(get_current_user),
    event_bus: EventBus = Depends(get_event_bus)
):
    # Authorization check
    # Subscribe to project channel
    # Yield SSE formatted events
    # Keepalive every 30s

SSE Format

event: agent.status_changed
data: {"id": "...", "type": "agent.status_changed", ...}

: keepalive

event: issue.created
data: {...}

Features

  • Automatic reconnection support (Last-Event-ID)
  • Keepalive every 30 seconds
  • Connection cleanup on disconnect
  • Rate limiting

Tests

  • Event streaming
  • Keepalive mechanism
  • Authorization
  • Reconnection

Acceptance Criteria

  • SSE endpoint implemented
  • Events stream correctly
  • Keepalive working
  • Authorization enforced
  • Last-Event-ID support
  • Integration tests

Dependencies

  • Depends on: #33 (EventBus)

Assignable To

backend-engineer agent

## Description Implement Server-Sent Events (SSE) endpoint for real-time project updates. ## Requirements ### Endpoint ``` GET /api/v1/projects/{project_id}/events/stream ``` ### Implementation ```python @router.get("/projects/{project_id}/events/stream") async def stream_events( project_id: UUID, current_user: User = Depends(get_current_user), event_bus: EventBus = Depends(get_event_bus) ): # Authorization check # Subscribe to project channel # Yield SSE formatted events # Keepalive every 30s ``` ### SSE Format ``` event: agent.status_changed data: {"id": "...", "type": "agent.status_changed", ...} : keepalive event: issue.created data: {...} ``` ### Features - Automatic reconnection support (Last-Event-ID) - Keepalive every 30 seconds - Connection cleanup on disconnect - Rate limiting ### Tests - Event streaming - Keepalive mechanism - Authorization - Reconnection ## Acceptance Criteria - [ ] SSE endpoint implemented - [ ] Events stream correctly - [ ] Keepalive working - [ ] Authorization enforced - [ ] Last-Event-ID support - [ ] Integration tests ## Dependencies - Depends on: #33 (EventBus) ## Assignable To backend-engineer agent
cardosofelipe added the backendphase-1 labels 2025-12-29 23:50:16 +00:00
Sign in to join this conversation.