mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 12:44:18 +08:00
27c41f7416
* feat(proxy): add GET /v1/models endpoint for Codex CLI reachability check Codex CLI probes GET /v1/models at startup. Without this endpoint the proxy returns 404, causing Codex to fail before any request reaches the upstream LLM. Return an OpenAI-compatible model list derived from the cc-switch–managed model catalog file. Fixes #3812 * fix(proxy): return Codex catalog schema from /v1/models Codex deserializes the response as a catalog with a top-level `models` field, not the OpenAI `{"object":"list","data":[...]}` envelope. Return the catalog file content directly so the format matches what Codex expects. Co-authored-by: Codex review bot * fix(proxy): guard /v1/models against serving stale catalog Only return the model catalog when config.toml still references it via `model_catalog_json`. After switching to a provider without a custom catalog, the old file lingers on disk — serving it unconditionally would advertise the previous provider's models to Codex. Co-authored-by: Codex review bot * fix(proxy): match relative model_catalog_json in stale-guard cc-switch writes `model_catalog_json = "cc-switch-model-catalog.json"` (relative) via set_codex_model_catalog_json_field. Match on the filename constant rather than the absolute path so the guard works with both relative and absolute paths. Co-authored-by: Codex review bot * fix(proxy): parse model_catalog_json field instead of substring match Replace raw config_text.contains() with proper TOML field parsing so commented-out lines and stray mentions of the filename in other fields don't defeat the stale guard. Also switch from contains() to exact filename match (Path::new(val).file_name() == Some(...)) to stay consistent with resolve_cc_switch_catalog_path in codex_config.rs. Add log::debug! when the guard blocks serving so the operator can distinguish "no models configured" from "guard blocked stale catalog". * refactor(proxy): reuse resolve_cc_switch_catalog_path in handle_models Replace the inline config.toml parsing and filename match in handle_models with the existing resolve_cc_switch_catalog_path helper (now pub(crate)). This removes the duplicated stale-guard logic, keeps a single source of truth for catalog-path ownership, and makes the handler honor absolute model_catalog_json paths the same way Codex live-setting import does. --------- Co-authored-by: Jason <farion1231@gmail.com>