Files
codex/codex-rs/tui/src/model_catalog.rs
T
Eric Traut d4dc882998 Discover TUI collaboration modes from the app server (#42401)
## What changed

- Fetch `collaborationMode/list` during TUI startup and reconnect, and use the
  returned catalog for visible collaboration-mode selection.
- Keep collaboration-mode discovery optional with a two-second timeout so an
  unavailable, invalid, or unsupported response does not block bootstrap.
- Preserve discovered modes when the model catalog refreshes, clear restored
  developer-instruction overrides when selecting a server mode, and retain a
  `/plan` draft when plan mode is unavailable.

## Testing

- Cover optional discovery failures and catalog refresh on reconnect.
- Cover server mode selection, model refreshes, restored settings, and
  unavailable plan mode.

GitOrigin-RevId: a6e35c14aab2e38526606164091ac64c500151bb
2026-09-03 00:45:48 +00:00

41 lines
1.1 KiB
Rust

//! TUI model and collaboration inventories; refreshing models preserves the server mode catalog.
use codex_protocol::config_types::CollaborationModeMask;
use codex_protocol::openai_models::ModelPreset;
use std::convert::Infallible;
pub(crate) const LUNA_RESERVE_MODEL: &str = "gpt-reserve";
pub(crate) const LUNA_MODEL: &str = "gpt-5.6-luna";
pub(crate) fn model_display_name(model: &str) -> &str {
if model.eq_ignore_ascii_case(LUNA_RESERVE_MODEL) {
"Luna Reserve"
} else {
model
}
}
#[derive(Debug, Clone)]
pub(crate) struct ModelCatalog {
pub(crate) models: Vec<ModelPreset>,
pub(crate) collaboration_modes: Vec<CollaborationModeMask>,
}
impl ModelCatalog {
pub(crate) fn new(models: Vec<ModelPreset>) -> Self {
Self {
models,
collaboration_modes: Vec::new(),
}
}
pub(crate) fn with_collaboration_modes(mut self, modes: Vec<CollaborationModeMask>) -> Self {
self.collaboration_modes = modes;
self
}
pub(crate) fn try_list_models(&self) -> Result<Vec<ModelPreset>, Infallible> {
Ok(self.models.clone())
}
}