Skip to content

feat: add REST API with OpenAPI 3.1 spec#249

Open
pkonowrocki wants to merge 6 commits intosipeed:mainfrom
pkonowrocki:feature/rest-api
Open

feat: add REST API with OpenAPI 3.1 spec#249
pkonowrocki wants to merge 6 commits intosipeed:mainfrom
pkonowrocki:feature/rest-api

Conversation

@pkonowrocki
Copy link

Summary

  • Add REST API endpoints: /api/chat (POST), /api/sessions (GET), /api/health (GET), /api/openapi.yaml (GET)
  • Bearer token authentication via Authorization header with configurable API key
  • OpenAPI 3.1 specification embedded and served at /api/openapi.yaml
  • Add APIConfig struct, GetSessionManager() accessor, and ListSessions() method

Test plan

  • Auth middleware tests (valid/invalid/missing token, public paths, open mode)
  • Health endpoint returns status and version
  • Spec endpoint returns valid YAML with correct content-type
  • Chat endpoint validates required message field
  • Chat endpoint rejects non-POST methods
  • Chat endpoint rejects invalid JSON
  • Manual: curl -H "Authorization: Bearer <key>" -d '{"message":"hi"}' localhost:18790/api/chat

pkonowrocki and others added 6 commits February 15, 2026 16:46
…story

Addresses two bugs causing invalid message ordering:

1. Atomic message saving: moves all session saves to after successful LLM
   completion, preventing orphaned user messages when LLM calls fail.

2. Comprehensive history sanitization: replaces partial tool-message stripping
   with sanitizeHistory() that handles leading non-user messages, consecutive
   user messages, orphaned tool results, and trailing incomplete tool-call
   sequences.

3. Smart truncation: TruncateHistory now scans forward to find the nearest
   user message boundary, preventing summarization from creating invalid
   mid-sequence starting points.
Adds opt-in distributed tracing via OTLP/gRPC exporter:

- New pkg/tracing package with Init/Shutdown lifecycle
- TracingConfig in config.go (enabled + endpoint fields)
- Spans for agent.processMessage, agent.llm.call, agent.tool.execute,
  and provider.chat with relevant attributes
- Jaeger all-in-one service in docker-compose.yml (tracing profile)
- Tracing initialization in both agentCmd and gatewayCmd
Merges upstream changes (LINE/OneBot channels, GitHub Copilot provider,
device monitoring, DuckDuckGo search, I2C/SPI tools, embedded workspace)
while preserving our additions (tracing, atomic saves, sanitizeHistory,
key rotation, smart truncation).

Conflict resolutions:
- config.go: keep both Tracing and Devices configs, merge ProviderConfig
  fields (APIKeys + ConnectMode)
- http_provider.go: keep our retry/backoff logic over upstream's simpler
  error path
- manager_test.go: keep both test sets (truncation + filename sanitization)
- go.mod/go.sum: merge both dependency sets
historyOffset was computed from len(history) before sanitization,
but BuildMessages runs sanitizeHistory which can remove messages.
This caused a slice bounds out of range panic when the sanitized
history was shorter than the original.

Fix: compute offset from actual messages slice length instead.
Add webhook/REST API with bearer token auth, chat endpoint, session
listing, health check, and embedded OpenAPI spec serving. Includes
auth middleware, request validation, and comprehensive tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Leeaandrob
Copy link
Collaborator

@Zepan This PR adds a REST API with OpenAPI 3.1 spec (+1542/-114). While a REST API could be valuable for programmatic access, it's not currently on the roadmap board.

Consideration: This adds an HTTP server to a project designed for <10MB RAM on $10 hardware. The memory and attack surface implications should be evaluated carefully. Also, MCP support (#290, priority: high) may provide a more standard integration protocol for the same use cases.

Recommendation: Defer. Not on the roadmap, and MCP (#282) may be a better fit for the extensibility story. Worth revisiting after MCP lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants