Implements weeks 1-4 of the multi-provider architecture: Week 1 - Foundation: - Add domain models (AgentProvider, AgentRequest, AgentEvent, AgentResult) - Define CodeAgent port interface with Execute, Cancel, Capabilities - Create thread-safe provider registry with first-registered default Week 2 - Claude Code Adapter: - Extract kubectl exec logic into CodeAgent implementation - Parse stream-json output format (init, message, tool_use, result) - Support session continuation via --resume flag Week 3 - OpenCode Adapter: - HTTP/SSE client for opencode serve API - Session management (create, send message, abort) - Event streaming with documented buffer rationale Week 4 - Quality & Polish: - Fix race condition in OpenCode Cancel method - Add AgentRequest.Validate() with ErrPromptRequired, ErrInvalidTimeout - Document DefaultAvailabilityTimeout constants - Add HTTP error context for debugging Also includes: - Work queue system with PostgreSQL adapter - Credential store for infrastructure secrets - Project templates with Woodpecker CI integration - Comprehensive test coverage Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
54 lines
1.3 KiB
Markdown
54 lines
1.3 KiB
Markdown
# SSE Streaming
|
|
|
|
**Last Updated:** 2025-01
|
|
**Confidence:** High
|
|
|
|
## Summary
|
|
|
|
Server-Sent Events (SSE) stream command output in real-time. Clients connect to a stream URL and receive output as it's produced.
|
|
|
|
**Key Facts:**
|
|
- Endpoint: `GET /projects/{id}/events/{stream_id}`
|
|
- Content-Type: `text/event-stream`
|
|
- Events: `output` (stdout/stderr), `done` (completion)
|
|
- In-memory stream publisher for current implementation
|
|
- Stream URLs returned from command execution endpoints
|
|
|
|
**File Pointers:**
|
|
- Handler: `internal/handlers/projects.go` (events endpoint)
|
|
- Publisher: `internal/adapter/memory/stream.go`
|
|
- Port: `internal/port/stream.go`
|
|
|
|
## Client Usage
|
|
|
|
```bash
|
|
curl -N -H "X-API-Key: $KEY" \
|
|
"http://localhost:8080/projects/my-project/events/stream-123"
|
|
```
|
|
|
|
## Event Format
|
|
|
|
```
|
|
event: output
|
|
data: {"type": "stdout", "content": "Hello world\n"}
|
|
|
|
event: output
|
|
data: {"type": "stderr", "content": "Warning: ...\n"}
|
|
|
|
event: done
|
|
data: {"exit_code": 0, "duration_ms": 1234}
|
|
```
|
|
|
|
## Flow
|
|
|
|
1. Client calls `POST /projects/{id}/claude`
|
|
2. Response includes `stream_url`
|
|
3. Client connects to `stream_url` via SSE
|
|
4. Server streams output events as produced
|
|
5. `done` event signals completion
|
|
|
|
## Related Topics
|
|
|
|
- [Command Execution](./command-execution.md)
|
|
- [Project Service](../services/project-service.md)
|