Config: { } blocks (core, telegram, provider, pool, exit) translated to the flat
reader with source line numbers; flat form still loads; delegate/plugin limits
raised. Pools: failover/balance, used by delegation (tag-safe), by -m and for
the conversation when its provider hits a limit. -m SEL picks a pool, provider,
provider/model or model name; --model-list lists them with served models.
Usage limits: the agent finds the reset and waits (UI: Ctrl-C stops, /resume
goes on; on_limit=fail turns it off).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
127 lines
4.9 KiB
C
127 lines
4.9 KiB
C
/* splinter -- the models this installation can talk to, and how to add one. */
|
|
#ifndef SPLINTER_PROVIDERS_H
|
|
#define SPLINTER_PROVIDERS_H
|
|
|
|
#include <stddef.h>
|
|
|
|
struct sp_config;
|
|
struct sp_delegate;
|
|
struct sp_pool;
|
|
struct sp_agent;
|
|
struct sp_transport;
|
|
struct sp_buf;
|
|
|
|
/*
|
|
* One reachable model: the endpoint, the model name and the variable the key
|
|
* lives in. The list is what the run was configured with -- main endpoint,
|
|
* delegates that name a model, exits -- so nothing here talks to the network.
|
|
*/
|
|
struct sp_provider {
|
|
char id[64];
|
|
char endpoint[512];
|
|
char model[256];
|
|
char key_env[64];
|
|
char about[128];
|
|
int main; /* the endpoint/model the run started with */
|
|
};
|
|
|
|
/* main first, then delegates with an endpoint and a model, then exits */
|
|
size_t sp_provider_count(const struct sp_config *);
|
|
int sp_provider_at(const struct sp_config *, size_t, struct sp_provider *);
|
|
int sp_provider_find(const struct sp_config *, const char *id, size_t *idx);
|
|
|
|
/*
|
|
* Provider identity for the per-key quota/usage plugins: "ollama",
|
|
* "opencode" or "openai-compat", plus the key fingerprint the bench and the
|
|
* usage state are filed under.
|
|
*/
|
|
void sp_provider_identify(struct sp_transport *, const char *endpoint,
|
|
const char *secret);
|
|
|
|
/* Point the agent at provider 'i' for the rest of this run. 0 or -1. */
|
|
int sp_provider_use(struct sp_agent *, const struct sp_config *, size_t,
|
|
struct sp_buf *err);
|
|
|
|
/* The same for an endpoint/model the config may not name (one model of a
|
|
* provider: /model <name>). */
|
|
int sp_provider_apply(struct sp_agent *, const char *endpoint,
|
|
const char *model, const char *key_env, struct sp_buf *err);
|
|
|
|
/* The drop-in directory next to the config file (…/splinter.conf.d). */
|
|
int sp_provider_dir(char *, size_t);
|
|
|
|
/*
|
|
* Add a provider (or replace one with the same id) in 'cfg' and in
|
|
* <dir>/20-connect.conf, so the next start has it too. The fields are
|
|
* validated here: a line that cannot be read back is worse than a refusal.
|
|
*/
|
|
int sp_provider_add(struct sp_config *, const char *dir, const char *id,
|
|
const char *endpoint, const char *model, const char *key_env,
|
|
struct sp_buf *err);
|
|
|
|
/* One answer of /connect, checked before it becomes a line: a name must fit
|
|
* the id field, an endpoint must be http(s), a model must be a name and the key
|
|
* variable an environment name. 1 when it does. */
|
|
int sp_provider_id_ok(const char *id);
|
|
int sp_provider_endpoint_ok(const char *endpoint);
|
|
int sp_provider_model_ok(const char *model);
|
|
int sp_provider_key_ok(const char *key_env);
|
|
|
|
/*
|
|
* Ask the endpoint which models it really serves (/v1/models). 'ids' gets one
|
|
* model name per line. A provider that does not answer that route is not
|
|
* broken -- many do not -- so the caller decides what a failure means.
|
|
*/
|
|
int sp_provider_served(const struct sp_provider *, struct sp_buf *ids,
|
|
struct sp_buf *err);
|
|
|
|
/* One tiny turn against the provider: does the endpoint, the model and the key
|
|
* work? 'answer' gets the first bytes of what came back. */
|
|
int sp_provider_test(const struct sp_provider *, struct sp_buf *answer,
|
|
struct sp_buf *err);
|
|
|
|
/*
|
|
* Remember the choice for the next start: <config>.d/90-model.conf. Picking
|
|
* "main" removes the file instead, so the config speaks again. Returns 1 when
|
|
* nothing was written because a plugin transport decides the model anyway.
|
|
*/
|
|
int sp_provider_save_choice(const struct sp_config *,
|
|
const struct sp_provider *, struct sp_buf *err);
|
|
|
|
/* The config line for one provider, also handy for showing it. */
|
|
int sp_provider_line(char *buf, size_t len, const char *id,
|
|
const char *endpoint, const char *model, const char *key_env);
|
|
|
|
/*
|
|
* Pools. A pool is a name for providers that stand in for each other.
|
|
* sp_pool_pick gives the member to use now -- first with room (failover) or
|
|
* the one with the most left (balance) -- never 'skip' (the one that just
|
|
* failed) and only one that has every tag of 'need_tags' (comma list, NULL:
|
|
* any), and NULL when every member is benched or used up; *soonest then
|
|
* holds the epoch the first of them is back (0: unknown).
|
|
*/
|
|
const struct sp_pool *sp_pool_find(const struct sp_config *, const char *id);
|
|
const struct sp_pool *sp_pool_of(const struct sp_config *, const char *member);
|
|
const struct sp_delegate *sp_pool_pick(const struct sp_config *,
|
|
const struct sp_pool *, const char *skip, const char *need_tags,
|
|
long *soonest);
|
|
|
|
/*
|
|
* What the user means by "-m SEL": a pool, a provider, "provider/model", or a
|
|
* model name one of the providers has. 0, or -1 when nothing matches.
|
|
*/
|
|
struct sp_choice {
|
|
const struct sp_delegate *d;
|
|
char model[256]; /* the model to ask for, the provider's own by default */
|
|
};
|
|
int sp_provider_choose(const struct sp_config *, const char *sel,
|
|
struct sp_choice *out);
|
|
|
|
/*
|
|
* The provider the conversation is on is at its limit: move to another member
|
|
* of its pool that has room. 1 when the agent now talks to another provider.
|
|
*/
|
|
int sp_provider_failover(struct sp_agent *, const struct sp_config *);
|
|
|
|
#endif /* SPLINTER_PROVIDERS_H */
|