mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
## 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
75 lines
2.8 KiB
Rust
75 lines
2.8 KiB
Rust
//! Accept current account-scoped model replies and refresh present pickers without reopening them.
|
|
|
|
use super::model_popups::ALL_MODELS_SELECTION_VIEW_ID;
|
|
use super::model_popups::MODEL_SELECTION_VIEW_ID;
|
|
use super::*;
|
|
|
|
impl ChatWidget {
|
|
fn model_popup_view_id(&self) -> Option<&'static str> {
|
|
[MODEL_SELECTION_VIEW_ID, ALL_MODELS_SELECTION_VIEW_ID]
|
|
.into_iter()
|
|
.find(|view_id| {
|
|
self.bottom_pane
|
|
.selected_index_for_present_view(view_id)
|
|
.is_some()
|
|
})
|
|
}
|
|
|
|
pub(crate) fn model_popup_request_is_current(&self, request_id: uuid::Uuid) -> bool {
|
|
self.model_popup_request_id == Some(request_id)
|
|
}
|
|
|
|
pub(crate) fn on_models_loaded(
|
|
&mut self,
|
|
request_id: uuid::Uuid,
|
|
result: Result<Vec<ModelPreset>, String>,
|
|
) -> bool {
|
|
if !self.model_popup_request_is_current(request_id) {
|
|
return false;
|
|
}
|
|
self.model_popup_request_id = None;
|
|
let Ok(presets) = result else {
|
|
return false;
|
|
};
|
|
if presets.is_empty()
|
|
|| self.model_catalog.try_list_models().ok().as_ref() == Some(&presets)
|
|
{
|
|
return false;
|
|
}
|
|
Arc::make_mut(&mut self.model_catalog).models = presets;
|
|
self.refresh_effective_service_tier();
|
|
self.refresh_model_dependent_surfaces();
|
|
true
|
|
}
|
|
|
|
/// Keep a present model picker aligned with the active task, including Reserve entry/exit.
|
|
pub(super) fn refresh_open_model_picker(&mut self) {
|
|
// Refresh an existing parent without reopening it or interrupting its reasoning child.
|
|
match self.model_popup_view_id() {
|
|
Some(MODEL_SELECTION_VIEW_ID) => self.open_model_popup_with_presets(
|
|
self.model_catalog.try_list_models().unwrap_or_default(),
|
|
),
|
|
Some(ALL_MODELS_SELECTION_VIEW_ID) => self.open_all_models_popup(),
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
pub(super) fn show_model_selection_view(&mut self, mut params: SelectionViewParams) {
|
|
let selected_index = params
|
|
.view_id
|
|
.and_then(|view_id| self.bottom_pane.selected_index_for_present_view(view_id));
|
|
let selected_model = selected_index.and_then(|index| self.model_popup_model_ids.get(index));
|
|
params.initial_selected_idx = params
|
|
.items
|
|
.iter()
|
|
.position(|item| Some(&item.name) == selected_model);
|
|
self.model_popup_model_ids = params.items.iter().map(|item| item.name.clone()).collect();
|
|
if let Some(view_id) = params.view_id.filter(|_| selected_index.is_some()) {
|
|
self.bottom_pane
|
|
.replace_selection_view_if_present(view_id, params);
|
|
} else {
|
|
self.bottom_pane.show_selection_view(params);
|
|
}
|
|
}
|
|
}
|