mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Refresh the TUI model picker from the app server (#41467)
## Why The model picker can open from a cached startup catalog that no longer reflects the models available to the current account. ## What changed - Fetch the current model list asynchronously whenever the picker opens, while showing cached choices immediately. - Refresh an open model picker in place, preserving its highlighted model, dismissal behavior, and reasoning submenu. - Apply accepted catalog updates to model-dependent UI, service-tier controls, and new-thread defaults. Ignore stale, failed, empty, unchanged, or account-invalidated responses. ## Testing - Added coverage for catalog refreshes, stale and unusable responses, popup state preservation, empty choices, service tiers, and new-thread defaults. GitOrigin-RevId: 45abe1d309ff7f90701fffe29c6544ca4157f836
This commit is contained in:
1 parent
0b45b171ca
commit
5fc7840cf6
16 files changed
+609
-18
No files matched your search
@@ -0,0 +1,50 @@
|
||||
//! Fetch picker models without blocking the event loop and keep new-thread defaults in sync.
|
||||
|
||||
use super::AppServerSession;
|
||||
use super::model_preset_from_api_model;
|
||||
use crate::app_event::AppEvent;
|
||||
use crate::app_event_sender::AppEventSender;
|
||||
use codex_app_server_protocol::ClientRequest;
|
||||
use codex_app_server_protocol::ModelListParams;
|
||||
use codex_app_server_protocol::ModelListResponse;
|
||||
use codex_app_server_protocol::RequestId;
|
||||
use codex_protocol::openai_models::ModelPreset;
|
||||
use uuid::Uuid;
|
||||
|
||||
impl AppServerSession {
|
||||
pub(crate) fn set_available_models(&mut self, models: Vec<ModelPreset>) {
|
||||
if let Some(default) = models
|
||||
.iter()
|
||||
.find(|model| model.is_default)
|
||||
.or(models.first())
|
||||
{
|
||||
self.default_model = Some(default.model.clone());
|
||||
}
|
||||
self.available_models = models;
|
||||
}
|
||||
|
||||
pub(crate) fn fetch_models(&self, request_id: Uuid, app_event_tx: AppEventSender) {
|
||||
let request_handle = self.request_handle();
|
||||
tokio::spawn(async move {
|
||||
let result = request_handle
|
||||
.request_typed::<ModelListResponse>(ClientRequest::ModelList {
|
||||
request_id: RequestId::String(format!("model-list-{request_id}")),
|
||||
params: ModelListParams {
|
||||
cursor: None,
|
||||
limit: None,
|
||||
include_hidden: Some(true),
|
||||
},
|
||||
})
|
||||
.await
|
||||
.map(|response| {
|
||||
response
|
||||
.data
|
||||
.into_iter()
|
||||
.map(model_preset_from_api_model)
|
||||
.collect()
|
||||
})
|
||||
.map_err(|err| err.to_string());
|
||||
app_event_tx.send(AppEvent::ModelsLoaded { request_id, result });
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user