Skip to content

Add Public API Route for Task Streaming #131

@ishaan1013

Description

@ishaan1013

Add Public API Route for Task Streaming

Overview

Create a public REST API endpoint that allows external systems to trigger Shadow tasks and receive streaming responses without requiring WebSocket connections.

Proposed Implementation

API Endpoint

  • POST /api/v1/tasks/stream - RESTful endpoint for task creation and streaming
  • Authentication via Bearer token (reuse existing apiKeyAuth middleware)
  • Request body: repository details, initial message, model selection
  • Response: Server-Sent Events (SSE) stream with task progress and AI responses

Streaming Architecture

  • Leverage existing StreamChunk types and emitStreamChunk infrastructure
  • Convert WebSocket events to SSE format for REST compatibility
  • Support same event types: content, tool-calls, tool-results, init-progress, etc.
  • Reuse StreamProcessor and ChunkHandlers for consistent streaming behavior

Integration Points

  • Extend current task creation flow (createTask + /initiate endpoints)
  • Reuse TaskInitializationEngine and ChatService components
  • Maintain same security model with API key validation
  • Support both local and remote execution modes

Response Format

  • SSE data format containing StreamChunk JSON payloads
  • Task metadata in initial response headers
  • Proper error handling and connection management
  • Graceful stream termination on completion/failure

Benefits

  • Enable headless integrations and CI/CD pipelines
  • Support external tools without WebSocket complexity
  • Maintain consistency with existing streaming infrastructure
  • Preserve security and execution isolation features

Implementation Considerations

  • Rate limiting for public API usage
  • Documentation and examples for integration
  • Error handling for malformed requests
  • Proper cleanup of resources on client disconnect

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions