Expand description
16F: per-agent dispatch surface — /xagent/{name}/api/v1/...
Closes the THQ dispatch gap: torpi’s proxy forwards
/thq/api/agents/{id}/... to {endpoint}/api/v1/... with the CALLER’s
Bearer injected, so until now THQ-dispatched sessions ran under the
CALLER’s identity (the owner), not the agent’s. This module exposes the
same handler surface under a per-agent path prefix and re-keys every
request to the agent-user the THQ entry represents.
Mechanism (impersonation by Bearer swap — zero handler duplication):
{name}resolves through the boot-time dispatch table (ServerState.thq_dispatch, populated by 16E discovery) to the agent-user’s stable key (= its Kanidmsub, per the 16E pin).- The OUTER caller is gate-checked: human admin only
(
crate::auth::check_dispatch_admin). Agents can never dispatch agents; open mode follows the same open posture ascheck_auth. - The agent’s service token (captured from its per-user
.envat boot) is exchanged for a short-livedrole=agentaccess token (RFC 8693, expiry-buffered cache). Open mode passes through unauthenticated, matchingcheck_auth’s open posture. - The inner request is rebuilt with
Authorization: Bearer <agent>and the caller’s cookie STRIPPED, then the STANDARD handler runs:check_authauthenticates the AGENT, Cedar applies the per-action agent matrix (working set minus DeleteSession),user_keyresolves to the agent’s sub, and session bucket / per-user home / MCP loader all resolve to the agent’s own namespace — her own fame, never the caller’s tools.
THQ-side wiring: set each agent-user’s [thq].advertise_url to
https://<host>:<port>/xagent/<agent_name> — torpi appends
/api/v1/... to the advertised origin, landing here.
Functions§
- router
- The
/xagent/{agent}/api/v1route tree — merged into the main router. - x_
create_ session - x_
destroy_ session - x_
get_ live_ session - x_
get_ session_ detail - x_
get_ session_ history - x_
health - THQ polls
{advertise_url}/api/v1/healthfor liveness — resolve the agent (unknown → 404 → THQ marks it offline) then answer with the shared health. - x_
list_ live_ sessions - x_
list_ models - x_
list_ sessions - x_
post_ cancel_ session - x_
post_ command_ session - x_
post_ handoff_ session - x_
resume_ session - x_
ws_ session_ handler