providers: add teamorouter; pick the first /models id when no default model
ci / linux (clang) (push) Successful in 4m2s
ci / linux (gcc) (push) Successful in 4m37s
ci / musl (push) Successful in 5m7s
ci / windows-cross (push) Successful in 9m55s

This commit is contained in:
WHC
2026-10-08 14:30:00 +08:00
parent 1772c26d43
commit 0226f417ff
6 changed files with 52 additions and 5 deletions
+21 -4
View File
@@ -3821,7 +3821,7 @@ static int secret_input_run(tui_t *t, const char *title, const char *hint,
* File-scope so a probe still running when the TUI exits writes nowhere
* stale. */
#define AM_MAX 64
#define AM_MAX 512 /* routers list hundreds; the picker filters as you type */
enum { AM_NONE = 0, AM_RUNNING, AM_OK, AM_FAILED, AM_AUTH };
static pthread_mutex_t g_am_mu = PTHREAD_MUTEX_INITIALIZER;
@@ -3920,15 +3920,23 @@ static int am_models(const char *provider, char out[][128], int max) {
return n;
}
/* After a probe: flag a model the API does not list. */
/* After a probe: flag a model the API does not list; with no model yet
* (router presets) take the first one listed. */
static void am_check_model(tui_t *t) {
const cst_agent_config_t *cfg = cst_agent_config(t->agent);
cst_agent_config_t *cfg = cst_agent_config_mut(t->agent);
char msg[400] = "";
int picked = 0;
pthread_mutex_lock(&g_am_mu);
if (cfg && strcmp(g_am.provider, cfg->provider) == 0) {
if (g_am.state == AM_AUTH) {
snprintf(msg, sizeof(msg), "the %s API key was rejected — /key to "
"replace it", cfg->provider);
} else if (g_am.state == AM_OK && g_am.n > 0 && !cfg->model[0]) {
snprintf(cfg->model, sizeof(cfg->model), "%s", g_am.ids[0]);
snprintf(msg, sizeof(msg), "model → %.127s (%d listed by %s) — /model "
"to change",
cfg->model, g_am.n, cfg->provider);
picked = 1;
} else if (g_am.state == AM_OK && g_am.n > 0) {
int found = 0;
for (int i = 0; i < g_am.n && !found; i++)
@@ -3939,6 +3947,8 @@ static void am_check_model(tui_t *t) {
}
}
pthread_mutex_unlock(&g_am_mu);
if (picked)
cst_settings_remember(cfg);
if (msg[0])
set_status(t, msg);
}
@@ -4314,7 +4324,8 @@ static void cmd_provider(tui_t *t, char *arg, int *quit) {
int cur_idx = 0;
for (int i = 0; i < n && i < 16; i++) {
const cst_provider_t *q = cst_provider_at(i);
snprintf(items[i], 128, "%-9s %s (%s)", q->name, q->api_base, q->model);
snprintf(items[i], 128, "%-11s %s (%s)", q->name, q->api_base,
q->model[0] ? q->model : "models from API");
if (strcmp(q->name, cfg->provider) == 0)
cur_idx = i;
}
@@ -5409,6 +5420,12 @@ static void request_cancel_ui(tui_t *t) {
static int begin_turn(tui_t *t, char *prompt) {
prompt_hist_push(t, prompt);
if (!cst_agent_config(t->agent)->model[0]) {
set_status(t, "no model selected yet — /model to pick one (↑ recalls "
"your message)");
free(prompt);
return -1;
}
block_t *ub = blocks_push(&t->hist);
if (ub) {
ub->kind = BLK_USER;