Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions codex-rs/tui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::app_event::ExitMode;
use crate::app_event::FeedbackCategory;
use crate::app_event::HistoryLookupResponse;
use crate::app_event::PermissionProfileSelection;
use crate::app_event::PluginLocation;
use crate::app_event::RateLimitRefreshOrigin;
use crate::app_event::RealtimeAudioDeviceKind;
#[cfg(target_os = "windows")]
Expand Down
35 changes: 28 additions & 7 deletions codex-rs/tui/src/app/background_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,22 +241,22 @@ impl App {
&mut self,
app_server: &AppServerSession,
cwd: PathBuf,
marketplace_path: AbsolutePathBuf,
location: PluginLocation,
plugin_name: String,
plugin_display_name: String,
) {
let request_handle = app_server.request_handle();
let app_event_tx = self.app_event_tx.clone();
tokio::spawn(async move {
let cwd_for_event = cwd.clone();
let marketplace_path_for_event = marketplace_path.clone();
let location_for_event = location.clone();
let plugin_name_for_event = plugin_name.clone();
let result = fetch_plugin_install(request_handle, marketplace_path, plugin_name)
let result = fetch_plugin_install(request_handle, location, plugin_name)
.await
.map_err(|err| format!("Failed to install plugin: {err}"));
app_event_tx.send(AppEvent::PluginInstallLoaded {
cwd: cwd_for_event,
marketplace_path: marketplace_path_for_event,
location: location_for_event,
plugin_name: plugin_name_for_event,
plugin_display_name,
result,
Expand Down Expand Up @@ -835,16 +835,17 @@ pub(super) async fn fetch_marketplace_upgrade(
}
pub(super) async fn fetch_plugin_install(
request_handle: AppServerRequestHandle,
marketplace_path: AbsolutePathBuf,
location: PluginLocation,
plugin_name: String,
) -> Result<PluginInstallResponse> {
let request_id = RequestId::String(format!("plugin-install-{}", Uuid::new_v4()));
let (marketplace_path, remote_marketplace_name) = location.into_request_params();
request_handle
.request_typed(ClientRequest::PluginInstall {
request_id,
params: PluginInstallParams {
marketplace_path: Some(marketplace_path),
remote_marketplace_name: None,
marketplace_path,
remote_marketplace_name,
plugin_name,
},
})
Expand Down Expand Up @@ -1062,6 +1063,26 @@ mod tests {
);
}

#[test]
fn plugin_location_request_params_select_exactly_one_location() {
let local_path = test_absolute_path("/marketplaces/local");

assert_eq!(
PluginLocation::Local {
marketplace_path: local_path.clone()
}
.into_request_params(),
(Some(local_path), None)
);
assert_eq!(
PluginLocation::Remote {
marketplace_name: "workspace-directory".to_string()
}
.into_request_params(),
(None, Some("workspace-directory".to_string()))
);
}

#[test]
fn mcp_inventory_maps_prefix_tool_names_by_server() {
let statuses = vec![
Expand Down
14 changes: 8 additions & 6 deletions codex-rs/tui/src/app/event_dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,14 +573,14 @@ impl App {
}
AppEvent::FetchPluginInstall {
cwd,
marketplace_path,
location,
plugin_name,
plugin_display_name,
} => {
self.fetch_plugin_install(
app_server,
cwd,
marketplace_path,
location,
plugin_name,
plugin_display_name,
);
Expand All @@ -601,7 +601,7 @@ impl App {
}
AppEvent::PluginInstallLoaded {
cwd,
marketplace_path,
location,
plugin_name,
plugin_display_name,
result,
Expand All @@ -612,7 +612,7 @@ impl App {
}
let should_refresh_plugin_detail = self.chat_widget.on_plugin_install_loaded(
cwd.clone(),
marketplace_path.clone(),
location.clone(),
plugin_name.clone(),
plugin_display_name,
result,
Expand All @@ -621,12 +621,14 @@ impl App {
{
self.fetch_plugins_list(app_server, cwd.clone());
if should_refresh_plugin_detail {
let (marketplace_path, remote_marketplace_name) =
location.into_request_params();
self.fetch_plugin_detail(
app_server,
cwd,
PluginReadParams {
marketplace_path: Some(marketplace_path),
remote_marketplace_name: None,
marketplace_path,
remote_marketplace_name,
plugin_name,
},
);
Expand Down
19 changes: 17 additions & 2 deletions codex-rs/tui/src/app_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ pub(crate) struct ConnectorsSnapshot {
pub(crate) connectors: Vec<AppInfo>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) enum PluginLocation {
Local { marketplace_path: AbsolutePathBuf },
Remote { marketplace_name: String },
}

impl PluginLocation {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe MarketplaceRef?

pub(crate) fn into_request_params(self) -> (Option<AbsolutePathBuf>, Option<String>) {
match self {
PluginLocation::Local { marketplace_path } => (Some(marketplace_path), None),
PluginLocation::Remote { marketplace_name } => (None, Some(marketplace_name)),
}
}
}

/// Distinguishes why a rate-limit refresh was requested so the completion
/// handler can route the result correctly.
///
Expand Down Expand Up @@ -493,15 +508,15 @@ pub(crate) enum AppEvent {
/// Install a specific plugin from a marketplace.
FetchPluginInstall {
cwd: PathBuf,
marketplace_path: AbsolutePathBuf,
location: PluginLocation,
plugin_name: String,
plugin_display_name: String,
},

/// Result of installing a plugin.
PluginInstallLoaded {
cwd: PathBuf,
marketplace_path: AbsolutePathBuf,
location: PluginLocation,
plugin_name: String,
plugin_display_name: String,
result: Result<PluginInstallResponse, String>,
Expand Down
Loading
Loading