Add support for inference over jsonrpc

This commit is contained in:
Josiah Grace
2025-10-31 19:49:57 -07:00
parent 0f22067242
commit da432778b1
14 changed files with 1406 additions and 4 deletions

View File

@@ -6,6 +6,28 @@
Similar to [MCP](https://modelcontextprotocol.io/), `codex app-server` supports bidirectional communication, streaming JSONL over stdio. The protocol is JSON-RPC 2.0, though the `"jsonrpc":"2.0"` header is omitted.
### Delegating OpenAI Responses HTTP over JSONRPC (Experimental)
When the `responses_http_over_jsonrpc` feature is enabled in Codex (see `~/.codex/config.toml`), the appserver will delegate the actual HTTP `POST /v1/responses` to the JSONRPC client. This keeps all agent logic inside appserver, while allowing an integrating UI to control the network call (e.g., to supply credentials and enforce policy) and stream responses back.
- Server → Client request:
- Method: `responsesApi/call`
- Params: `{ conversationId, callId, url, headers: {k: v}, body: <json>, stream: true }`
- The client should perform the HTTP request and stream SSE events back via notifications (see below).
- After streaming completes, the client must send a JSONRPC response with `{ status, requestId?, error? }`.
- Client → Server notifications (during stream):
- Method: `responsesApi/event`
- Params: `{ callId, event }` where `event` is the raw JSON object emitted by the Responses API SSE stream (e.g. `{ "type": "response.output_item.done", ... }`).
- Feature flag (optin): in `~/.codex/config.toml` add
```toml
[features]
responses_http_over_jsonrpc = true
```
The JSON envelopes are mapped 1:1 onto Codexs internal streaming events, so downstream behavior (streaming assistant text, tool calls, final completion) matches the direct HTTP path.
## Message Schema
Currently, you can dump a TypeScript version of the schema using `codex generate-ts`. It is specific to the version of Codex you used to run `generate-ts`, so the two are guaranteed to be compatible.