v0.8.15: custom providers and model parameters under Advanced options

The settings dialog could pick a preset, a model and a key and nothing else.
Two things were missing: a provider the presets do not know, and what the
model is asked to do while it answers. Both live under "Advanced options"
now, next to the entry they belong to.

Custom providers (engine)
- cst_models_user_set_provider() / cst_models_user_drop_provider() write the
  engine's own user layer, <config>/cst-agent/models.json:
  {"providers": {"myllm": {"api_base": ..., "key_env": ...,
                           "default_model": ..., "models": [...]}}}
  and reload the registry, so the provider is at once in the provider list,
  in the wire models[] and in the CLI's /provider -- the file a hand-written
  override would go into is the same one, so the GUI and an editor agree.
  The name is checked (1-31 of letters, digits, '.', '_', '-'), a preset's
  name overrides that preset (a self-hosted endpoint, a proxy), everything
  else in the file (model rules) is kept, and a file that is not a JSON
  object is never overwritten. Dropping only removes the user's own entry.
- AgentCore::providers() gained "custom" (source == "user"), and
  addProvider() / removeProvider() drive the two calls above.

Model parameters (engine + wire)
- cst_agent_config_t and cst_llm_request_t carry temperature, top_p and
  max_tokens. 0 means the field is not sent at all -- an absent field is the
  provider's own default, which "temperature": 0 is not (deterministic
  decoding is a real choice), so cst_llm_build_body() only adds what was set.
  tests/test_llm_body.c:test_gen_params pins both halves.
- settings.json keeps them per provider ("params": {...}) via
  cst_settings_remember_params(); cst_settings_remember() carries them along
  with the provider choice, and cst_agent_create() reads them, so a CLI or
  TUI run sends what the window was set to. An all-zero config (the CLI)
  leaves what the GUI saved alone.
- AgentCore::genParams() / setGenParams(), and useProvider() applies both the
  remembered parameters of the provider it lands on and a base URL that was
  edited in the dialog.

The dialog
- Rewritten around one scrolling body with a fixed footer: a long model list
  used to push the key field and the buttons out of the dialog. The model
  chips are filtered (a filter field appears past twelve) and capped at 40
  with "... +N more", which is what a router with hundreds of models needs.
- "Advanced options" folds out the provider entry (name, base URL, key
  variable, default model, models; Save provider / Remove from models.json)
  and the model parameters (temperature, top-p, max tokens; empty = not
  sent). The fields follow the picked provider and are what gets saved, so a
  hand-typed edit is never lost to a stale property.

Verified: --uitest 67/67 (15 new checks: parameters round-trip through the
engine, a provider added through the form and removed again, a bad name
refused, a preset not removable), --selftest, ctest cst-app-selftest, and
make check with the new body test.

Version 0.8.15.

mode = coding
This commit is contained in:
WHC
2026-10-11 13:26:02 +08:00
parent 3fd039cb51
commit 82dee65942
14 changed files with 1202 additions and 184 deletions
+28
View File
@@ -89,6 +89,13 @@ typedef struct {
cst_protocol_t protocol;
int max_steps; /* model calls per user turn */
size_t tool_out_cap; /* bytes of one tool output sent to the model */
/* What the model is asked to do (Chat Completions fields). 0 = the field
* is not sent at all and the provider's own default stands; that is what a
* config that was not told otherwise has, so a CLI run is unchanged.
* temperature and top_p are doubles, max_tokens the completion cap. */
double temperature;
double top_p;
int max_tokens;
int headless;
int confirm_shell; /* confirm run_shell */
int confirm_write; /* confirm file-changing tools */
@@ -271,6 +278,9 @@ typedef struct {
const char *cache_ttl; /* cache_control ttl (CST_CACHE_ANTHROPIC); NULL = 5m */
int images_off; /* the model does not take images: send a note instead */
size_t tool_out_cap; /* wire cap for role=tool content; 0 = default */
double temperature; /* 0 = not sent */
double top_p; /* 0 = not sent */
int max_tokens; /* 0 = not sent */
const char *session_path; /* where stored images live; NULL = none */
volatile int *cancel_flag; /* non-zero → abort (error "cancelled") */
volatile int *stop_flag; /* non-zero → stop reading, not an error */
@@ -422,6 +432,16 @@ int cst_creds_prompt_console(const char *provider, char *out, size_t out_sz);
* <config>/settings.json. */
#define CST_SETTINGS_MAX_MODELS 16
#define CST_SETTINGS_MAX_TRUSTED 32
#define CST_SETTINGS_MAX_PARAMS 16
/* Generation parameters remembered per provider ("params" in settings.json):
* what the user set for that provider's models. 0 = not set, the field is
* not sent. */
typedef struct {
char provider[32];
double temperature;
double top_p;
int max_tokens;
} cst_gen_params_t;
typedef struct {
char provider[32];
char effort[16];
@@ -436,10 +456,18 @@ typedef struct {
char provider[32];
char model[128];
} models[CST_SETTINGS_MAX_MODELS];
int nparams;
cst_gen_params_t params[CST_SETTINGS_MAX_PARAMS];
} cst_settings_t;
int cst_settings_load(cst_settings_t *s);
int cst_settings_save(const cst_settings_t *s);
const char *cst_settings_model(const cst_settings_t *s, const char *provider);
/* The remembered parameters of a provider, or NULL when it has none. */
const cst_gen_params_t *cst_settings_params(const cst_settings_t *s,
const char *provider);
/* Remember parameters for a provider; all-zero (or NULL) forgets them. */
int cst_settings_remember_params(const char *provider,
const cst_gen_params_t *p);
/* Record cfg's provider, model, effort and mode as the last used ones. */
int cst_settings_remember(const cst_agent_config_t *cfg);
/* Record an approval mode the user picked (CST_APPROVAL_*). */