TUI Plugin Sharing 1 - add remote plugin identity (#26701)

This commit is contained in:
canvrno-oai authored and GitHub committed 2026-06-09 16:34:38 -07:00
1 parent 51b3cd51f6
commit fb8f1ea0d5
7 files changed
+573 -74

No files matched your search

+146 -59
View File
@@ -5,6 +5,7 @@ use std::time::Instant;
use super::ChatWidget;
use crate::app_event::AppEvent;
use crate::app_event::PluginLocation;
use crate::bottom_pane::ColumnWidthMode;
use crate::bottom_pane::SelectionAction;
use crate::bottom_pane::SelectionItem;
@@ -25,17 +26,18 @@ use crate::tui::FrameRequester;
use codex_app_server_protocol::MarketplaceAddResponse;
use codex_app_server_protocol::MarketplaceRemoveResponse;
use codex_app_server_protocol::MarketplaceUpgradeResponse;
use codex_app_server_protocol::PluginAvailability;
use codex_app_server_protocol::PluginDetail;
use codex_app_server_protocol::PluginInstallPolicy;
use codex_app_server_protocol::PluginInstallResponse;
use codex_app_server_protocol::PluginListResponse;
use codex_app_server_protocol::PluginMarketplaceEntry;
use codex_app_server_protocol::PluginReadResponse;
use codex_app_server_protocol::PluginSource;
use codex_app_server_protocol::PluginSummary;
use codex_app_server_protocol::PluginUninstallResponse;
use codex_core_plugins::OPENAI_CURATED_MARKETPLACE_NAME;
use codex_features::Feature;
use codex_utils_absolute_path::AbsolutePathBuf;
use crossterm::event::KeyCode;
use crossterm::event::KeyEvent;
use crossterm::event::KeyEventKind;
@@ -453,7 +455,7 @@ impl ChatWidget {
pub(crate) fn on_plugin_install_loaded(
&mut self,
cwd: PathBuf,
_marketplace_path: AbsolutePathBuf,
_location: PluginLocation,
_plugin_name: String,
plugin_display_name: String,
result: Result<PluginInstallResponse, String>,
@@ -1625,19 +1627,22 @@ impl ChatWidget {
) -> SelectionViewParams {
let marketplace_label = plugin.marketplace_name.clone();
let display_name = plugin_display_name(&plugin.summary);
let detail_status_label = if plugin.summary.installed {
if plugin.summary.enabled {
"Installed"
let detail_status_label =
if plugin.summary.availability == PluginAvailability::DisabledByAdmin {
"Disabled by admin"
} else if plugin.summary.installed {
if plugin.summary.enabled {
"Installed"
} else {
"Disabled"
}
} else {
"Disabled"
}
} else {
match plugin.summary.install_policy {
PluginInstallPolicy::NotAvailable => "Not installable",
PluginInstallPolicy::Available => "Can be installed",
PluginInstallPolicy::InstalledByDefault => "Available by default",
}
};
match plugin.summary.install_policy {
PluginInstallPolicy::NotAvailable => "Not installable",
PluginInstallPolicy::Available => "Can be installed",
PluginInstallPolicy::InstalledByDefault => "Available by default",
}
};
let mut header = ColumnRenderable::new();
header.push(Line::from("Plugins".bold()));
header.push(Line::from(
@@ -1676,23 +1681,40 @@ impl ChatWidget {
}];
if plugin.summary.installed {
let uninstall_cwd = self.config.cwd.to_path_buf();
let plugin_id = plugin.summary.id.clone();
let plugin_display_name = display_name;
if let Some(plugin_id) = plugin_uninstall_id(&plugin.summary) {
let uninstall_cwd = self.config.cwd.to_path_buf();
let plugin_display_name = display_name;
items.push(SelectionItem {
name: "Uninstall plugin".to_string(),
description: Some("Remove this plugin now.".to_string()),
selected_description: Some("Remove this plugin now.".to_string()),
actions: vec![Box::new(move |tx| {
tx.send(AppEvent::OpenPluginUninstallLoading {
plugin_display_name: plugin_display_name.clone(),
});
tx.send(AppEvent::FetchPluginUninstall {
cwd: uninstall_cwd.clone(),
plugin_id: plugin_id.clone(),
plugin_display_name: plugin_display_name.clone(),
});
})],
..Default::default()
});
} else {
items.push(SelectionItem {
name: "Uninstall plugin".to_string(),
description: Some(
"This remote plugin did not provide an uninstall identity.".to_string(),
),
is_disabled: true,
..Default::default()
});
}
} else if plugin.summary.availability == PluginAvailability::DisabledByAdmin {
items.push(SelectionItem {
name: "Uninstall plugin".to_string(),
description: Some("Remove this plugin now.".to_string()),
selected_description: Some("Remove this plugin now.".to_string()),
actions: vec![Box::new(move |tx| {
tx.send(AppEvent::OpenPluginUninstallLoading {
plugin_display_name: plugin_display_name.clone(),
});
tx.send(AppEvent::FetchPluginUninstall {
cwd: uninstall_cwd.clone(),
plugin_id: plugin_id.clone(),
plugin_display_name: plugin_display_name.clone(),
});
})],
name: "Install plugin".to_string(),
description: Some("This plugin is disabled by your workspace admin.".to_string()),
is_disabled: true,
..Default::default()
});
} else if plugin.summary.install_policy == PluginInstallPolicy::NotAvailable {
@@ -1704,9 +1726,9 @@ impl ChatWidget {
is_disabled: true,
..Default::default()
});
} else if let Some(marketplace_path) = plugin.marketplace_path.clone() {
} else if let Some(location) = plugin_detail_location(plugin) {
let install_cwd = self.config.cwd.to_path_buf();
let plugin_name = plugin.summary.name.clone();
let plugin_name = plugin_request_name(&plugin.summary);
let plugin_display_name = display_name;
items.push(SelectionItem {
name: "Install plugin".to_string(),
@@ -1718,7 +1740,7 @@ impl ChatWidget {
});
tx.send(AppEvent::FetchPluginInstall {
cwd: install_cwd.clone(),
marketplace_path: marketplace_path.clone(),
location: location.clone(),
plugin_name: plugin_name.clone(),
plugin_display_name: plugin_display_name.clone(),
});
@@ -1728,7 +1750,7 @@ impl ChatWidget {
} else {
items.push(SelectionItem {
name: "Install plugin".to_string(),
description: Some("Installing remote plugins is not supported yet.".to_string()),
description: Some("This plugin did not provide an install location.".to_string()),
is_disabled: true,
..Default::default()
});
@@ -1792,9 +1814,12 @@ impl ChatWidget {
} else {
plugin_brief_description_without_marketplace(plugin, status_label_width)
};
let can_view_details = marketplace.path.is_some();
let plugin_detail_request = plugin_detail_request_for_entry(marketplace, plugin);
let can_view_details = plugin_detail_request.is_some();
let disabled_by_admin = plugin.availability == PluginAvailability::DisabledByAdmin;
let can_toggle_plugin = plugin.installed && !disabled_by_admin;
let selected_status_label = format!("{status_label:<status_label_width$}");
let selected_description = if plugin.installed {
let selected_description = if can_toggle_plugin {
let toggle_action = if plugin.enabled { "disable" } else { "enable" };
if can_view_details {
format!(
@@ -1803,6 +1828,12 @@ impl ChatWidget {
} else {
format!("{selected_status_label} Space to {toggle_action}.")
}
} else if plugin.installed && can_view_details {
format!("{selected_status_label} Press Enter to view plugin details.")
} else if plugin.installed {
format!("{selected_status_label} Plugin details are unavailable.")
} else if disabled_by_admin && can_view_details {
format!("{selected_status_label} Press Enter to view plugin details.")
} else if can_view_details {
format!("{selected_status_label} Press Enter to install or view plugin details.")
} else {
@@ -1814,11 +1845,9 @@ impl ChatWidget {
);
let cwd = self.config.cwd.to_path_buf();
let plugin_display_name = display_name.clone();
let marketplace_path = marketplace.path.clone();
let plugin_name = plugin.name.clone();
let toggle_cwd = cwd.clone();
let toggle_plugin_id = plugin.id.clone();
let toggle = plugin.installed.then(|| SelectionToggle {
let toggle = can_toggle_plugin.then(|| SelectionToggle {
is_on: plugin.enabled,
action: Box::new(move |enabled, tx| {
tx.send(AppEvent::SetPluginEnabled {
@@ -1828,31 +1857,33 @@ impl ChatWidget {
});
}),
});
let actions: Vec<SelectionAction> = if let Some(marketplace_path) = marketplace_path {
vec![Box::new(move |tx| {
tx.send(AppEvent::OpenPluginDetailLoading {
plugin_display_name: plugin_display_name.clone(),
});
tx.send(AppEvent::FetchPluginDetail {
cwd: cwd.clone(),
params: codex_app_server_protocol::PluginReadParams {
marketplace_path: Some(marketplace_path.clone()),
remote_marketplace_name: None,
plugin_name: plugin_name.clone(),
},
});
})]
} else {
Vec::new()
};
let actions: Vec<SelectionAction> =
if let Some((location, plugin_name)) = plugin_detail_request {
vec![Box::new(move |tx| {
tx.send(AppEvent::OpenPluginDetailLoading {
plugin_display_name: plugin_display_name.clone(),
});
let (marketplace_path, remote_marketplace_name) =
location.clone().into_request_params();
tx.send(AppEvent::FetchPluginDetail {
cwd: cwd.clone(),
params: codex_app_server_protocol::PluginReadParams {
marketplace_path,
remote_marketplace_name,
plugin_name: plugin_name.clone(),
},
});
})]
} else {
Vec::new()
};
let is_disabled = !can_view_details && !plugin.installed;
let disabled_reason =
is_disabled.then(|| "remote plugin details are not available yet".to_string());
let disabled_reason = is_disabled.then(|| "plugin details are unavailable".to_string());
items.push(SelectionItem {
name: display_name,
toggle,
toggle_placeholder: (!plugin.installed).then_some("[-] "),
toggle_placeholder: (!can_toggle_plugin).then_some("[-] "),
description: Some(description),
selected_description: Some(selected_description),
search_value: Some(search_value),
@@ -2082,6 +2113,9 @@ fn plugin_brief_description_without_marketplace(
}
fn plugin_status_label(plugin: &PluginSummary) -> &'static str {
if plugin.availability == PluginAvailability::DisabledByAdmin {
return "Disabled by admin";
}
if plugin.installed {
if plugin.enabled {
"Installed"
@@ -2097,6 +2131,59 @@ fn plugin_status_label(plugin: &PluginSummary) -> &'static str {
}
}
fn plugin_location_for_marketplace(
marketplace: &PluginMarketplaceEntry,
plugin: &PluginSummary,
) -> Option<PluginLocation> {
if let Some(marketplace_path) = marketplace.path.clone() {
return Some(PluginLocation::Local { marketplace_path });
}
plugin_remote_identity(plugin).map(|_| PluginLocation::Remote {
marketplace_name: marketplace.name.clone(),
})
}
fn plugin_detail_location(plugin: &PluginDetail) -> Option<PluginLocation> {
if let Some(marketplace_path) = plugin.marketplace_path.clone() {
return Some(PluginLocation::Local { marketplace_path });
}
plugin_remote_identity(&plugin.summary).map(|_| PluginLocation::Remote {
marketplace_name: plugin.marketplace_name.clone(),
})
}
fn plugin_detail_request_for_entry(
marketplace: &PluginMarketplaceEntry,
plugin: &PluginSummary,
) -> Option<(PluginLocation, String)> {
plugin_location_for_marketplace(marketplace, plugin)
.map(|location| (location, plugin_request_name(plugin)))
}
fn plugin_request_name(plugin: &PluginSummary) -> String {
if matches!(&plugin.source, PluginSource::Remote)
&& let Some(remote_plugin_id) = plugin_remote_identity(plugin)
{
return remote_plugin_id;
}
plugin.name.clone()
}
fn plugin_remote_identity(plugin: &PluginSummary) -> Option<String> {
plugin
.share_context
.as_ref()
.map(|context| context.remote_plugin_id.clone())
.or_else(|| plugin.remote_plugin_id.clone())
}
fn plugin_uninstall_id(plugin: &PluginSummary) -> Option<String> {
if matches!(&plugin.source, PluginSource::Remote) {
return plugin_remote_identity(plugin);
}
Some(plugin.id.clone())
}
fn plugin_description(plugin: &PluginSummary) -> Option<String> {
plugin
.interface