gateway, sessions, reconnect: splinter serves other harnesses and keeps tabs

- --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.
This commit is contained in:
lotherk committed 2026-11-16 09:33:37 +00:00
1 parent a9f175c25b
commit 5143fcd054
32 files changed
+2642 -111

No files matched your search

+19
View File
@@ -160,9 +160,18 @@ struct sp_transport {
/* optional: provider/key identity for quota/usage tracking (plugins) */
const char *provider; /* e.g. "openai-compat", "ollama", "opencode" */
const char *key_id; /* stable key fingerprint/id, never the secret */
/*
* Optional: free the context a constructor allocated. A transport a
* caller builds per request (the OpenAI gateway) uses this; the agent's
* own transport lives as long as the agent. Zero for plugin transports,
* whose context belongs to the plugin.
*/
void (*free)(void *ctx);
};
void sp_reply_free(struct sp_reply *);
/* free a transport's context (if it owns one) and zero the struct */
void sp_transport_dispose(struct sp_transport *);
/* A deterministic in-process transport: replies are queued FIFO. */
struct sp_mock {
@@ -202,6 +211,16 @@ int sp_session_folder_history(const char *dir, const char *cwd,
int sp_session_load(const struct sp_session_info *, struct sp_conv *conv,
size_t *loaded, struct sp_buf *err);
/* one line of a session listing: id, mtime, bytes; newest first */
struct sp_session_brief {
char id[64];
long mtime;
size_t bytes;
};
/* up to max entries from dir; returns the count (0..max), or -1 */
int sp_session_list(const char *dir, struct sp_session_brief *v,
size_t max);
/* ----------------------------------------------------------------- agent */
struct sp_agent_config {