feat(api-server): add session management API for frontend clients - #8556
Closed
Codename-11 wants to merge 2 commits into
Closed
feat(api-server): add session management API for frontend clients#8556Codename-11 wants to merge 2 commits into
Codename-11 wants to merge 2 commits into
Conversation
Adds 20 REST endpoints to the API server that enable web/mobile
frontends to manage sessions, chat with streaming, browse skills,
read/write memory, and configure models — all through the gateway's
existing auth and message handling pipeline.
Session CRUD:
- GET /api/sessions — list (paginated)
- POST /api/sessions — create
- GET /api/sessions/search?q=... — full-text search
- GET /api/sessions/{id} — get single
- GET /api/sessions/{id}/messages — message history
- PATCH /api/sessions/{id} — update title/prompt
- DELETE /api/sessions/{id} — delete
- POST /api/sessions/{id}/fork — deep clone
Session Chat:
- POST /api/sessions/{id}/chat — sync agent turn
- POST /api/sessions/{id}/chat/stream — SSE streaming turn
with structured lifecycle events (session.created, run.started,
message.started, assistant.delta, tool.started, tool.completed,
assistant.completed, run.completed, done) and periodic keepalive
heartbeats to prevent client/proxy timeouts during long LLM calls
Memory (CRUD):
- GET /api/memory — read entries
- POST /api/memory — add entry
- PATCH /api/memory — replace entry
- DELETE /api/memory — delete entry
Skills (read-only):
- GET /api/skills — list all
- GET /api/skills/categories — list categories
- GET /api/skills/{name} — view skill detail
Config:
- GET /api/config — current settings
- PATCH /api/config — update model/provider
- GET /api/available-models — curated model list
Also adds:
- Capability probe fast-path for /v1/chat/completions (max_tokens=1
or model='test' returns instant minimal response for frontend
endpoint detection)
- SSE keepalive on chat/stream matching the existing pattern on
/v1/chat/completions
- Proper shutdown cleanup (SessionDB.close, memory store clear)
- 91 new tests covering all endpoints, auth, error handling, SSE
streaming lifecycle, and capability probe
Codename-11
force-pushed
the
feat/session-api
branch
from
April 12, 2026 19:44
4468bf4 to
7e6a4f5
Compare
Codename-11
marked this pull request as ready for review
April 12, 2026 19:48
Upstream refactor removed skills_categories from tools/skills_tool.py. Remove the import, the _handle_skill_categories handler, and the /api/skills/categories route registration to restore gateway startup. The app uses /api/skills?category= for filtering; the standalone categories endpoint was not called by any current client.
1 task
|
Hey. Thanks for your changes. I am waiting for this feature |
Contributor
Author
|
Superseded by #29302. This original branch had the right product intent — API Server clients need a real session/control surface, not only OpenAI-compatible chat — but it grew into a broad/stale patch covering sessions, memory, skills, config, and other admin surfaces, and it now conflicts with current I rebuilt the useful session-control portion from current upstream/main in #29302 as a smaller, reviewable PR:
Closing this one to avoid splitting review across two competing API-server branches. |
Contributor
Author
|
Closing as superseded by #29302. |
This was referenced May 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds 20 REST endpoints to the API server that give web and mobile frontends a complete session management API — CRUD, streaming chat with structured lifecycle events, memory, skills, and config — all flowing through the gateway's existing auth pipeline.
Motivation: The current API server exposes OpenAI-compatible endpoints (
/v1/chat/completions,/v1/responses) which are stateless. Every frontend (web UIs, mobile apps, desktop clients) that wants persistent sessions, tool visibility, and session history has to reinvent session management client-side. This PR provides a server-side session API that multiple frontends can share.Supersedes #6334 (which added read-only endpoints only — no chat capability).
Endpoints Added (20)
Session CRUD (8)
/api/sessions/api/sessions/api/sessions/search?q=.../api/sessions/{id}/api/sessions/{id}/messages/api/sessions/{id}/api/sessions/{id}/api/sessions/{id}/forkSession Chat (2) — the key addition
/api/sessions/{id}/chat/api/sessions/{id}/chat/streamThe streaming endpoint emits rich lifecycle events:
Includes periodic SSE keepalive comments (every 30s) matching the existing pattern on
/v1/chat/completions— prevents client/proxy timeouts during agent init and long LLM calls with extended thinking.Memory CRUD (4)
/api/memory/api/memory/api/memory/api/memorySkills (3, read-only)
/api/skills/api/skills/categories/api/skills/{name}Config (3)
/api/config/api/config/api/available-modelsOther
/v1/chat/completions:max_tokens=1ormodel='test'returns an instant minimal response so frontends can detect endpoint availability without spinning up an agent.Architecture
All endpoints use the existing
_check_auth()gate. Session state delegates to the existingSessionDB(SQLite + FTS5). Chat endpoints instantiate the sameAIAgentused by/v1/chat/completions, with the addition of session-aware conversation history loading and persistence.No parallel agent lifecycle, no gateway runner bypass — chat flows through the same agent instantiation path.
Type of Change
Tests
91 new tests in
tests/gateway/test_session_api.py:python -m pytest tests/gateway/test_session_api.py -q # 91 passed in ~5sChecklist
gateway/platforms/api_server.py)