Files
lotherk 74df75d438 no approval gate: splinter runs what the operator's registry offers
Konrad, 24.11.: "v1 geht durch ohne irgendwas. ich will auch keine approvals
generell. ich will nur das der user mit ask nach sachen gefragt werden kann."

Removed the whole approval apparatus, not just the prompt:

- agent.c: the decision point (sp_host_gate/approve callbacks), the
  pause/resume path (has_pending, pending_from, sp_agent_resume), ack_approval,
  ask_operator and the ack stdin thread are gone. A tool runs; its exit status
  is the observation. sp_tool_policy (allow/deny per profile) stays - that is
  the operator's own configuration, not a question to the operator.
- engine.c: SP_EV_APPROVAL, sp_engine_approve, the approve_pending condition
  variable and the `approval`/`approve` protocol commands are gone.
- openai_server.c: the v1 endpoint runs gw_* tools without a gate; the
  autonomous flag is no longer part of sp_gateway_opts.
- a2aserver.c: INPUT_REQUIRED and the resume-by-taskId path are gone; CancelTask
  stays. An A2A caller has no operator sitting in front of a prompt.
- mcpserver.c: --autonomous no longer gates mutating tools; the flag and the
  config key are accepted for compatibility and documented as changing
  nothing.
- telegram.c: tg_approve and the approval callback are gone; ask is the only
  dialog, and /cancel inside it still ends the turn.
- front ends: protocol.c, curses.c, ui_local.c, ui_remote.c, client.c lose the
  approval event and the waiting flag.
- ack.c stays: it is a plugin API (plugins/kids asks its parent through it),
  not splinter's own gate. --ack is documented as such.

Tests: test_pause.c guarded the pause and now guards the opposite (a mutate and
a destructive tool run, nothing is asked). test_a2a_input.sh, test_protocol.sh,
test_ui.sh, test_agents_ui.sh, test_gateway.sh, test_gateway_openai.sh,
test_agent.c and test_mcpsession.sh were rewritten the same way;
splinter_approve must now be absent from the MCP tool list. Every rewritten
test was run red against the old behaviour where that was possible.

make check: all tests passed (428 s)
make check-asan: all 47 test binaries clean
make check-tsan: all 47 test binaries free of data races
2026-11-24 11:46:10 +00:00

125 lines
5.4 KiB
Markdown

# 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.
```sh
# 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:
1. splinter asks its provider with the caller's conversation, the caller's
tools **and** its own tools renamed `gw_*`.
2. If the model calls `gw_*`, splinter runs it here (read tools always;
mutating and destructive ones as the registry offers them), appends the
observation and asks the provider again. The caller never sees these calls.
3. If the model calls a caller tool, splinter returns a normal
`chat.completion` with `tool_calls` and `finish_reason: "tool_calls"`. The
harness runs them, sends the results as `tool` messages in the next request,
and the gateway continues.
4. If a reply mixes both, the local calls run here and the caller's calls are
returned in the same `tool_calls` answer. Since the caller cannot answer a
`gw_` call, the local observations travel in the message `content` (under
"local gateway tools ran on the splinter host:"); the caller sends them back
with the assistant message as usual, and the model sees both sides.
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.
## Request shaping
The caller's `temperature`, `top_p` and `max_tokens` (or
`max_completion_tokens`) are forwarded to the provider; absent values stay the
provider's default. The response echoes the request's `model` name, and every
message, including the mixed-reply case, stays within the OpenAI chat shape.
Bodies may arrive with `Content-Length` or `Transfer-Encoding: chunked`; only
one request per connection is read, then the connection closes.
## Streaming
With `"stream": true` the gateway uses the provider's streaming transport and
forwards each text delta as a `chat.completion.chunk` event while it arrives -
the caller sees the answer grow instead of waiting for the last token. The
caller's tool calls are sent as one `tool_calls` delta at the end of the step,
because a name is only complete when the provider has finished it; local
`gw_*` calls stay invisible. `"stream_options":{"include_usage":true}` adds a
final usage chunk before `[DONE]`, with the token counts summed over every
upstream round of the request.
If the provider fails after the stream has started, the stream carries an
`{"error":...}` object and `[DONE]`; a request that was invalid before the
first byte is still an ordinary HTTP 400. The gateway ignores SIGPIPE, so a
caller that closes its stream early cannot kill the server.
## Examples
A local tool, executed by splinter, from the caller's point of view an ordinary
completion:
```sh
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:
```json
{"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 needs
`Authorization: Bearer <token>`.
- the endpoint has no approval step: whatever `gw_*` tool the registry offers
is callable (`gw_write`, `gw_run`, ...). `--autonomous` is accepted and
changes nothing. Who may reach the endpoint is decided by the token and by
what the operator registers, not by a question the gateway could not put to
anyone.
- 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. That makes a silent client everyone's problem: an
unanswered read ends after 60 seconds
(`SPLINTER_GATEWAY_READ_TIMEOUT`), and the next connection is then served.
## 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 skills tools. Plugins loaded with `--plugin` add
theirs. The caller's tools are passed through to the provider untouched, except
for the `gw_` reservation.