Expand description
REST resource gateway over the JSON-RPC method registry (#2983, #587,
Slice 1 bridge + Slice 2 session.* read routes).
Why: the vision spec (#587) wants tcode serve --http to expose a
conventional REST resource vocabulary (GET /projects, POST /sessions, …) alongside the existing JSON-RPC POST /rpc endpoint, but
every one of those resources is already backed by a registered JSON-RPC
method (session.create, task.run, …). Re-implementing the same
business logic a second time as bespoke axum handlers would fork the two
surfaces the moment either one changed — exactly the drift trusty-code’s
Router was built to prevent between the STDIO and HTTP JSON-RPC
transports (see crate::jsonrpc module docs). This module is
trusty-memory’s “Pattern C” (crates/trusty-memory/src/web/rpc.rs:
one shared dispatch seam, many transports) applied one layer further:
a REST route handler will call call instead of building its own
Request, so a REST resource and its JSON-RPC method twin always run
the exact same handler.
What: call synthesizes a JSON-RPC Request from a method +
params pair and drives it through Router::dispatch, unwrapping the
Response envelope back into a plain Result<Value, RpcError> — the
shape a REST handler wants (? onto an HTTP error), rather than the
always-200 envelope POST /rpc returns. rpc_error_to_status maps an
RpcError onto the real HTTP status a REST response should carry,
deliberately diverging from POST /rpc’s “always 200, error in the
envelope” convention — matching how GET /sessions/{id}/events
(crate::serve::http::session_events_sse) already returns a real 404
for session_not_found rather than a 200-wrapped error. [respond] is
the one place that glues those two together into the Result<Json<Value>, (StatusCode, Json<Response>)> shape every axum REST handler returns, so
a route handler is never more than “extract params, call respond”.
[throwaway_ctx] builds the per-request ConnectionContext every REST
handler needs to call call with — identical in spirit to
crate::serve::http::rpc_handler’s own throwaway context, since a REST
call is exactly as one-shot as a POST /rpc call.
Slice 1 wired no axum routes — only this bridge. Slice 2
(sessions) adds the first concrete resource group: GET /sessions,
GET /sessions/{id}, GET /sessions/{id}/transcript,
GET /sessions/{id}/readiness, GET /sessions/{id}/goals, each a thin
handler calling [respond] against its session.* JSON-RPC twin.
Slice 3 (sessions_write) adds the session.* WRITE routes:
POST /sessions, POST /sessions/{id}/messages,
POST /sessions/{id}/cancel, PUT /sessions/{id}/goal,
DELETE /sessions/{id}/goal. Slice 4 (tasks) adds
POST /tasks -> task.run. Slice 5 (fs) adds
GET /fs -> fs.list_dir. Slice 6 (agents) adds
GET /sessions/{id}/agents -> session.get_agents. Slice 7
(search_audit) adds GET /sessions/{id}/search-audit ->
session.get_search_audit (issue #3072). workstreams adds the full
workstream.* surface: POST /workstreams, GET /workstreams/{id},
GET /workstreams, POST /workstreams/{id}/close (issue #3295, epic
#3292) and POST /workstreams/{id}/activate,
POST /workstreams/{id}/deactivate (DOC-48 §5.2/§6, issue #3294) — see
its module docs for why the paths are unprefixed rather than DOC-48
§5.2’s literal /api/v1/workstreams. projects adds GET /projects
-> fs.list_projects (issue #3365 — the GUI’s workstream-first
project-picker modal’s roster data source). agent_catalog/
skill_catalog (issue #3449) add the Foundry GUI’s Agents/Skills
management tabs’ full surface — GET/POST /agents,
DELETE /agents/{name} and the skills twin — over
crate::agents::protocol/crate::skills::protocol; distinct from this
module’s own agents group (GET /sessions/{id}/agents, the
per-session LIVE roster, unrelated to the disk/embedded catalog these two
new groups manage). Every slice reuses [respond]/[throwaway_ctx]
rather than reimplementing the glue.
Test: tests::* — a success round-trip, an error round-trip, and one
assertion per rpc_error_to_status mapping. See sessions::tests for
the Slice 2 route-level coverage.
Modules§
- agent_
catalog GET/POST /agents,DELETE /agents/{name}REST routes over theagents.*JSON-RPC surface (issue #3449, Foundry GUI Agents tab).- agents
GET /sessions/{id}/agentsREST route over thesession.get_agentsJSON-RPC method (#2983 Slice 6).- fs
GET /fsREST route over thefs.list_dirJSON-RPC method (#2983 Slice 5).- projects
GET /projectsREST route over thefs.list_projectsJSON-RPC method (issue #3365).- search_
audit GET /sessions/{id}/search-auditREST route over thesession.get_search_auditJSON-RPC method (issue #3072).- sessions
GET /sessions*REST routes over thesession.*JSON-RPC methods (#2983 Slice 2 — read-only routes only, no writes).- sessions_
write POST/PUT/DELETE /sessions*REST routes over thesession.*JSON-RPC methods (#2983 Slice 3 — write routes).- skill_
catalog GET/POST /skills,DELETE /skills/{name}REST routes over theskills.*JSON-RPC surface (issue #3449, Foundry GUI Skills tab).- tasks
POST /tasksREST route over thetask.runJSON-RPC method (#2983 Slice 4).- workstreams
GET/POST /workstreams*REST routes over the fullworkstream.*JSON-RPC surface (issues #3294, #3295, epic #3292).
Functions§
- call
- Call a registered JSON-RPC method from a REST handler, in-process.
- rpc_
error_ to_ status - Map an
RpcErroronto the HTTP status a REST response should carry.