diff --git a/src/backend/confblock.c b/src/backend/confblock.c index a2dbda7..c80890e 100644 --- a/src/backend/confblock.c +++ b/src/backend/confblock.c @@ -386,6 +386,12 @@ do_provider(struct cb *c, const char *name, unsigned line, struct ent *e, goto done; if (list[0] != '\0') sp_buf_printf(&l, " | tags=%s", list); + } else if (!strcmp(k, "models")) { + joined(&e[i].v, list, sizeof(list)); + if (!clean(c, &e[i], list)) + goto done; + if (list[0] != '\0') + sp_buf_printf(&l, " | models=%s", list); } else if (!strcmp(k, "key")) { /* the key itself, in the (0600) file: kept in a private * variable that key_env then names */ diff --git a/src/backend/config.c b/src/backend/config.c index 1989730..a03fe9e 100644 --- a/src/backend/config.c +++ b/src/backend/config.c @@ -289,6 +289,8 @@ parse_delegate(struct sp_delegate *d, const char *val, struct sp_buf *err, snprintf(d->endpoint, sizeof(d->endpoint), "%s", s + 9); else if (!strncmp(s, "model=", 6)) snprintf(d->model, sizeof(d->model), "%s", s + 6); + else if (!strncmp(s, "models=", 7)) + snprintf(d->models, sizeof(d->models), "%s", s + 7); else if (!strncmp(s, "key_env=", 8)) snprintf(d->key_env, sizeof(d->key_env), "%s", s + 8); else if (!strncmp(s, "ctx=", 4)) { diff --git a/src/backend/config.h b/src/backend/config.h index 7eb2d79..fc3c913 100644 --- a/src/backend/config.h +++ b/src/backend/config.h @@ -77,6 +77,7 @@ struct sp_delegate { char tags[128]; /* comma separated, matched against the task */ char endpoint[512]; char model[256]; + char models[512]; /* optional comma list: the only models this provider offers */ char key_env[64]; unsigned long ctx; /* context window in tokens, 0 = unknown */ char env[SP_CONFIG_MAX_ENV][SP_CONFIG_ENV_LEN]; /* NAME=VALUE */ diff --git a/src/backend/delegate.c b/src/backend/delegate.c index 00f7d54..a6e651c 100644 --- a/src/backend/delegate.c +++ b/src/backend/delegate.c @@ -159,6 +159,7 @@ tool_delegate_list(const char *args, struct sp_buf *out, void *ctx) snprintf(pv.endpoint, sizeof(pv.endpoint), "%s", d->endpoint); snprintf(pv.model, sizeof(pv.model), "%s", d->model); + snprintf(pv.models, sizeof(pv.models), "%s", d->models); snprintf(pv.key_env, sizeof(pv.key_env), "%s", d->key_env); /* a literal key lives in 'key' until the child starts */ diff --git a/src/backend/providers.c b/src/backend/providers.c index cf351ad..04ab489 100644 --- a/src/backend/providers.c +++ b/src/backend/providers.c @@ -96,6 +96,7 @@ delegates: snprintf(out->kind, sizeof(out->kind), "%s", d->kind); snprintf(out->endpoint, sizeof(out->endpoint), "%s", d->endpoint); snprintf(out->model, sizeof(out->model), "%s", d->model); + snprintf(out->models, sizeof(out->models), "%s", d->models); snprintf(out->key_env, sizeof(out->key_env), "%s", d->key_env); snprintf(out->key, sizeof(out->key), "%s", d->key); snprintf(out->about, sizeof(out->about), "%s", d->about); @@ -447,6 +448,30 @@ provider_headers(const struct sp_provider *p, char *hdr, size_t cap, return n; } +/* 1 when the provider's optional models= list is empty or names this id */ +static int +provider_lists(const struct sp_provider *p, const char *id) +{ + char list[512], *tok, *save = NULL; + + if (p->models[0] == '\0') + return 1; + snprintf(list, sizeof(list), "%s", p->models); + for (tok = strtok_r(list, ",", &save); tok != NULL; + tok = strtok_r(NULL, ",", &save)) { + char *end; + + while (*tok == ' ' || *tok == '\t') + tok++; + end = tok + strlen(tok); + while (end > tok && (end[-1] == ' ' || end[-1] == '\t')) + *--end = '\0'; + if (*tok != '\0' && strcmp(tok, id) == 0) + return 1; + } + return 0; +} + int sp_provider_served(const struct sp_provider *p, struct sp_buf *ids, struct sp_buf *err) @@ -483,6 +508,8 @@ sp_provider_served(const struct sp_provider *p, struct sp_buf *ids, if (id == NULL) continue; + if (!provider_lists(p, id)) + continue; if (ids->len > 0 && sp_buf_puts(ids, "\n") != 0) goto oom; if (sp_buf_puts(ids, id) != 0) diff --git a/src/backend/providers.h b/src/backend/providers.h index f47945e..3062f59 100644 --- a/src/backend/providers.h +++ b/src/backend/providers.h @@ -22,6 +22,7 @@ struct sp_provider { char kind[16]; /* "openai" (default), "anthropic" or "cli" */ char endpoint[512]; char model[256]; + char models[512]; /* optional comma list, filters what the endpoint serves */ char key_env[64]; char key[256]; /* a literal key (d->key), wins over key_env */ char about[128]; diff --git a/src/main.c b/src/main.c index 32ca19c..7445d50 100644 --- a/src/main.c +++ b/src/main.c @@ -783,6 +783,7 @@ run_doctor(const struct sp_config *conf, const struct opts *o) snprintf(pv.kind, sizeof(pv.kind), "%s", d->kind); snprintf(pv.endpoint, sizeof(pv.endpoint), "%s", d->endpoint); snprintf(pv.model, sizeof(pv.model), "%s", d->model); + snprintf(pv.models, sizeof(pv.models), "%s", d->models); snprintf(pv.key_env, sizeof(pv.key_env), "%s", d->key_env); /* the model list only: never a completion, never a token spent */ if (sp_buf_init(&ids) == 0 && sp_buf_init(&perr) == 0) { @@ -988,6 +989,7 @@ run_model_list(const struct sp_config *conf, const struct opts *o) snprintf(pv.kind, sizeof(pv.kind), "%s", d->kind); snprintf(pv.endpoint, sizeof(pv.endpoint), "%s", d->endpoint); snprintf(pv.model, sizeof(pv.model), "%s", d->model); + snprintf(pv.models, sizeof(pv.models), "%s", d->models); snprintf(pv.key_env, sizeof(pv.key_env), "%s", d->key_env); served = sp_provider_served(&pv, &ids, &perr) == 0; }