feat(login): custom provider logins fetch and select models

After the base URL, name, and key steps, the login now opens a model
selection screen instead of blindly saving. The listing fetch runs
concurrently with a manual-id input — a WAF challenge page or a 404 no
longer passes validation silently: a base without a /vN tail is probed
once as {base}/v1 and the working base is adopted, an anthropic-wire
listing that 401s on x-api-key retries once with Bearer (relays gate
GET /models on Bearer while /messages takes the key header), and a
failed fetch shows its reason while manual add stays usable. The chosen
ids persist as [platforms.<name>] models = [...]; catalog assembly
synthesizes selected ids the listing never served (before [model.*]
overrides so they compose) and filters unselected provider entries
(after overrides, authoritative in the provider namespace). Provider-
owned entries keep their declared wire against donor backend
inheritance, and listing errors quote line/column only — a reflected
body could carry the key.
This commit is contained in:
雷电芽衣 committed 2026-09-29 22:00:20 -04:00
1 parent 1d631a07fa
commit 9a2a9eac99
20 files changed
+1655 -68

No files matched your search

+21 -2
View File
@@ -485,8 +485,27 @@ client-side, no backend surface.
instead of `x-api-key` (this also repaired `anthropic` and `minimax`).
Login: picker rows `custom-openai` / `custom-anthropic` are not loginable
(`AuthMethodKind::Unknown`); the TUI asks base URL, name (default from the
host), key, then `save_custom_provider` writes config.toml (through
`config_write_dest`) and auth.json, and `authenticate("custom:<name>")`
host), key, then opens a MODEL-SELECTION screen (`custom_entry.rs`
`CustomSelectState`, welcome `AuthMode::CustomProviderSelect`): the listing
fetch (`fetch_listing_for_login`) runs concurrently with the manual-id input
— both visible at once, failure shows its reason — space toggles fetched
rows, enter adds a typed id or finishes (a finish pressed mid-fetch waits for
it: `finish_requested`), and the chosen ids persist as `[platforms.<name>]
models = [...]` via `save_custom_provider`. The listing fetch probes
`{base}/v1` once when `{base}/models` 404s or answers unparsable (a WAF
challenge is HTTP 200 HTML) and the base has no `/vN` tail, adopting the
probed base for the saved definition; anthropic-wire listings that 401 on
`x-api-key` retry once with `Bearer` (relays gate `GET /models` on Bearer
while `/messages` takes `x-api-key`); listing errors never quote response
content (line/column only — a reflected body could carry the key). Catalog
assembly honors the allowlist in `selection.rs`: `synthesize_selected` (BEFORE
`[model.*]` overrides, so an override composes with a synthesized entry)
builds wire-default entries for selected ids the listing never served, and
`filter_unselected` (AFTER overrides) is authoritative in the provider's
namespace — even a `[model."name/x"]` entry for an unselected id is dropped.
Provider-owned entries never take donor `api_backend` inheritance in
`resolve_model_list` (the declared wire wins); no `models` key = the whole
listing (the declarative path). `authenticate("custom:<name>")` then
validates `GET {base}/models` (401/403 = rejected key, other non-2xx and network
errors surface). Limits: context window 256K unless the listing serves
`context_length` (Anthropic: `max_input_tokens`); no models.dev enrichment; a