sessions switch locally, gateway keeps caller settings and mixed calls
- sp_engine_switch(): close the old engine and open the chosen session from the same options; if the new one fails, reopen the session the engine was on. The protocol's open and the in-process /open both use it. The curses screen clears the pane and replays the new history, so /open no longer says it needs --attach. - gateway: temperature, top_p and max_tokens (max_completion_tokens) are forwarded to the provider instead of dropped; request bodies may be Transfer-Encoding: chunked; a mixed reply runs the gw_ calls, returns the caller's calls in tool_calls and puts the local observations in content (also in the SSE delta), so the caller can echo them back. - reconnect: when the remembered session is gone, the screen says which one and stays on the session the server has instead of silently swapping the transcript. - ring: the exits' transports are disposed on plugin shutdown. - /status goes through the catalogues like the rest of the UI (the English labels and their alignment are unchanged, so existing parsers still work). - the man page passes mandoc -Tlint and covers the gateway and /open. Tests: test_ui.sh covers local /sessions and /open (new, back, history), test_protocol.sh the shared switch, test_reconnect.sh a vanished session, test_gateway_openai.sh forwarded parameters, a chunked body and the mixed reply in JSON and SSE. make check green.
This commit is contained in:
1 parent
5143fcd054
commit
a01bfe9df1
28 files changed
+931
-244
No files matched your search
@@ -150,6 +150,20 @@ enum {
|
||||
|
||||
typedef void (*sp_stream_cb)(void *ctx, int kind, const char *text);
|
||||
|
||||
/*
|
||||
* Request shaping a front end may pass through to a provider. The gateway
|
||||
* forwards what the calling harness asked for instead of dropping it; zero
|
||||
* flags mean "not given" and leave the provider default.
|
||||
*/
|
||||
struct sp_gen_opts {
|
||||
int have_temperature;
|
||||
double temperature;
|
||||
int have_top_p;
|
||||
double top_p;
|
||||
int have_max_tokens;
|
||||
long max_tokens;
|
||||
};
|
||||
|
||||
struct sp_transport {
|
||||
int (*send)(void *ctx, const struct sp_conv *, struct sp_reply *out,
|
||||
struct sp_buf *err);
|
||||
@@ -421,10 +435,17 @@ char *sp_endpoint_url(const char *endpoint, const char *route, char *out,
|
||||
|
||||
struct sp_transport sp_openai_transport(const char *url, const char *model,
|
||||
const char *api_key, const struct sp_registry *, long timeout_s);
|
||||
/* the same, with request shaping the caller wants forwarded */
|
||||
struct sp_transport sp_openai_transport_gen(const char *url, const char *model,
|
||||
const char *api_key, const struct sp_registry *, long timeout_s,
|
||||
const struct sp_gen_opts *);
|
||||
|
||||
/* openai.c -- pure JSON shaping, testable without a network */
|
||||
int sp_openai_request(const struct sp_conv *, const char *model,
|
||||
const struct sp_registry *, int streaming, struct sp_buf *out);
|
||||
int sp_openai_request_opts(const struct sp_conv *, const char *model,
|
||||
const struct sp_registry *, int streaming,
|
||||
const struct sp_gen_opts *, struct sp_buf *out);
|
||||
int sp_openai_reply(const char *json, struct sp_reply *out,
|
||||
struct sp_buf *err);
|
||||
|
||||
@@ -458,11 +479,17 @@ int sp_sse_kind(const struct sp_sse *);
|
||||
*/
|
||||
struct sp_transport sp_anthropic_transport(const char *url, const char *model,
|
||||
const char *api_key, const struct sp_registry *, long timeout_s);
|
||||
struct sp_transport sp_anthropic_transport_gen(const char *url,
|
||||
const char *model, const char *api_key, const struct sp_registry *,
|
||||
long timeout_s, const struct sp_gen_opts *);
|
||||
|
||||
/* anthropic.c -- pure JSON shaping, testable without a network */
|
||||
int sp_anthropic_request(const struct sp_conv *, const char *model,
|
||||
const struct sp_registry *, int streaming, int oauth,
|
||||
struct sp_buf *out);
|
||||
int sp_anthropic_request_opts(const struct sp_conv *, const char *model,
|
||||
const struct sp_registry *, int streaming, int oauth,
|
||||
const struct sp_gen_opts *, struct sp_buf *out);
|
||||
int sp_anthropic_reply(const char *json, struct sp_reply *out,
|
||||
struct sp_buf *err);
|
||||
|
||||
|
||||
@@ -127,6 +127,16 @@ int sp_engine_state(struct sp_engine *, struct sp_engine_state *);
|
||||
int sp_engine_open(struct sp_engine **, const struct sp_engine_opts *,
|
||||
struct sp_buf *err);
|
||||
void sp_engine_close(struct sp_engine *);
|
||||
/*
|
||||
* Move an engine to another session: close the old engine, open the new one
|
||||
* from the same options, replace *ep. `id` is a session id, "new" for a fresh
|
||||
* one, or NULL/"last" for the newest. The old engine is closed first because
|
||||
* plugins keep process globals; a failed open reopens the session the engine
|
||||
* was on, so the pointer is only NULL when even that fails. Returns 0 or -1
|
||||
* with `err` set.
|
||||
*/
|
||||
int sp_engine_switch(struct sp_engine **ep, const struct sp_engine_opts *,
|
||||
const char *id, struct sp_buf *err);
|
||||
|
||||
/* The pieces a front end may look at. The pointers stay valid until close. */
|
||||
struct sp_agent *sp_engine_agent(struct sp_engine *);
|
||||
|
||||
Reference in new issue
Block a user