- --openai-listen: an OpenAI-compatible /v1/chat/completions and /v1/models. The model gets splinter's local tools as gw_* (executed here) and the caller's tools under their own names (returned as tool_calls to run there). Local calls loop inside one request; a mixed reply runs the local calls and asks again. --autonomous gates mutation; beyond loopback a bearer token is required; stream:true answers with SSE. - --serve keeps several sessions: sessions/open over the protocol and /sessions, /open in the attach screen. The server owns the engines, closes the old one before opening the next (plugins keep globals) and sends state/history after every switch. Session ids are unique per process, so two engines in the same second no longer share a file. - --attach reconnects: when the server goes away the screen keeps running, retries every second, asks for its session by id and restores the transcript; a missing session falls back to the server's current one. - transports own their context now: provider switches and close dispose it (a switch used to leak one per change). The idle screen repaints entries it drains, so a reconnect note is not invisible. - docs/GATEWAY.md; PROTOCOL, FRONTENDS, README and the manual page describe the three; tests cover the gateway tools, sessions/open and a server restart under --attach.
3.6 KiB
The OpenAI gateway
splinter --openai-listen IP [--openai-listen-port N] is a small
OpenAI-compatible endpoint. Another harness points its OpenAI client at it and
gets an answer from splinter's configured provider, with tools on both
sides: splinter executes its own tools where splinter runs, the caller
executes its tools where the caller runs.
# the side with the files and the shell
splinter -m myprovider --openai-listen 127.0.0.1 --openai-listen-port 8097
# the other harness
export OPENAI_BASE_URL=http://127.0.0.1:8097/v1
export OPENAI_API_KEY=unused # unless SPLINTER_GATEWAY_TOKEN is set
GET /v1/models answers with the run's model, so a client that probes first is
happy. POST /v1/chat/completions accepts the usual messages, tools and
stream fields.
Two tool namespaces
The model sees two kinds of tools in one request:
| name | who runs it | where |
|---|---|---|
gw_read, gw_write, gw_edit, gw_run, … |
splinter | on the host where splinter runs |
everything in the caller's tools array |
the calling harness | where the harness runs |
gw_ is reserved: a caller tool with that prefix is refused with HTTP 400,
because that is how a local read and a caller's read stay apart.
The loop, inside one HTTP request:
- splinter asks its provider with the caller's conversation, the caller's
tools and its own tools renamed
gw_*. - If the model calls
gw_*, splinter runs it here (read tools always; mutating and destructive ones only with--autonomous), appends the observation and asks the provider again. The caller never sees these calls. - If the model calls a caller tool, splinter returns a normal
chat.completionwithtool_callsandfinish_reason: "tool_calls". The harness runs them, sends the results astoolmessages in the next request, and the gateway continues. - If a reply mixes both, the local calls run first and the model is asked again; the caller's calls come on a later step.
Every request is stateless, as the OpenAI protocol says: the conversation travels with it. The loop is capped at 16 local tool rounds and each observation at 32 KiB.
Examples
A local tool, executed by splinter, from the caller's point of view an ordinary completion:
curl -s http://127.0.0.1:8097/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"x","messages":[{"role":"user","content":"read Cargo.toml"}]}'
A caller tool comes back instead:
{"choices":[{"index":0,"message":{"role":"assistant","content":"",
"tool_calls":[{"id":"c1","type":"function",
"function":{"name":"browser_open","arguments":"{\"url\":\"...\"}"}}]},
"finish_reason":"tool_calls"}]}
Security
- Beyond loopback the server refuses to start without
SPLINTER_GATEWAY_TOKEN; with a token set, every request needsAuthorization: Bearer <token>. --autonomousis the switch that lets the model usegw_write,gw_editandgw_run. Without it those calls are denied with an observation the model reads, so it can still answer.- There is no TLS. Expose it through ssh, WireGuard or a TLS proxy when the network is not yours.
- One request is served at a time; the endpoint is a gateway, not a load balanced service.
Where the tools come from
gw_* is the engine's registry: the builtins (read, write, edit,
search, list, run, websearch, webfetch), folder_history,
delegate, and the memory/skills tools. Plugins loaded with --plugin add
theirs. The caller's tools are passed through to the provider untouched, except
for the gw_ reservation.