-
Notifications
You must be signed in to change notification settings - Fork 10.8k
[plugins] Support plugin installation elicitation. #14896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cf11996
update
mzeng-openai fb88b51
update
mzeng-openai 1b7d84e
Merge branch 'main' of github.com:openai/codex into dev/mzeng/plugin_…
mzeng-openai 27217b4
update
mzeng-openai c634ffe
update
mzeng-openai b05298f
update
mzeng-openai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,24 +42,14 @@ use crate::mcp_connection_manager::McpConnectionManager; | |
| use crate::mcp_connection_manager::codex_apps_tools_cache_key; | ||
| use crate::plugins::AppConnectorId; | ||
| use crate::plugins::PluginsManager; | ||
| use crate::plugins::list_tool_suggest_discoverable_plugins; | ||
| use crate::token_data::TokenData; | ||
| use crate::tools::discoverable::DiscoverablePluginInfo; | ||
| use crate::tools::discoverable::DiscoverableTool; | ||
|
|
||
| pub use codex_connectors::CONNECTORS_CACHE_TTL; | ||
| const CONNECTORS_READY_TIMEOUT_ON_EMPTY_TOOLS: Duration = Duration::from_secs(30); | ||
| const DIRECTORY_CONNECTORS_TIMEOUT: Duration = Duration::from_secs(60); | ||
| const TOOL_SUGGEST_DISCOVERABLE_CONNECTOR_IDS: &[&str] = &[ | ||
| "connector_2128aebfecb84f64a069897515042a44", | ||
| "connector_68df038e0ba48191908c8434991bbac2", | ||
| "asdk_app_69a1d78e929881919bba0dbda1f6436d", | ||
| "connector_4964e3b22e3e427e9b4ae1acf2c1fa34", | ||
| "connector_9d7cfa34e6654a5f98d3387af34b2e1c", | ||
| "connector_6f1ec045b8fa4ced8738e32c7f74514b", | ||
| "connector_947e0d954944416db111db556030eea6", | ||
| "connector_5f3c8c41a1e54ad7a76272c89e2554fa", | ||
| "connector_686fad9b54914a35b75be6d06a0f6f31", | ||
| "connector_76869538009648d5b282a4bb21c3d157", | ||
| "connector_37316be7febe4224b3d31465bae4dbd7", | ||
| ]; | ||
|
|
||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub(crate) struct AppToolPolicy { | ||
|
|
@@ -116,13 +106,24 @@ pub(crate) async fn list_tool_suggest_discoverable_tools_with_auth( | |
| config: &Config, | ||
| auth: Option<&CodexAuth>, | ||
| accessible_connectors: &[AppInfo], | ||
| ) -> anyhow::Result<Vec<AppInfo>> { | ||
| ) -> anyhow::Result<Vec<DiscoverableTool>> { | ||
| let directory_connectors = | ||
| list_directory_connectors_for_tool_suggest_with_auth(config, auth).await?; | ||
| Ok(filter_tool_suggest_discoverable_tools( | ||
| let connector_ids = tool_suggest_connector_ids(config); | ||
| let discoverable_connectors = filter_tool_suggest_discoverable_connectors( | ||
| directory_connectors, | ||
| accessible_connectors, | ||
| )) | ||
| &connector_ids, | ||
| ) | ||
| .into_iter() | ||
| .map(DiscoverableTool::from); | ||
| let discoverable_plugins = list_tool_suggest_discoverable_plugins(config)? | ||
| .into_iter() | ||
| .map(DiscoverablePluginInfo::from) | ||
| .map(DiscoverableTool::from); | ||
| Ok(discoverable_connectors | ||
| .chain(discoverable_plugins) | ||
| .collect()) | ||
| } | ||
|
|
||
| pub async fn list_cached_accessible_connectors_from_mcp_tools( | ||
|
|
@@ -350,24 +351,21 @@ fn write_cached_accessible_connectors( | |
| }); | ||
| } | ||
|
|
||
| fn filter_tool_suggest_discoverable_tools( | ||
| fn filter_tool_suggest_discoverable_connectors( | ||
| directory_connectors: Vec<AppInfo>, | ||
| accessible_connectors: &[AppInfo], | ||
| discoverable_connector_ids: &HashSet<String>, | ||
| ) -> Vec<AppInfo> { | ||
| let accessible_connector_ids: HashSet<&str> = accessible_connectors | ||
| .iter() | ||
| .filter(|connector| connector.is_accessible && connector.is_enabled) | ||
| .filter(|connector| connector.is_accessible) | ||
| .map(|connector| connector.id.as_str()) | ||
| .collect(); | ||
| let allowed_connector_ids: HashSet<&str> = TOOL_SUGGEST_DISCOVERABLE_CONNECTOR_IDS | ||
| .iter() | ||
| .copied() | ||
| .collect(); | ||
|
|
||
| let mut connectors = filter_disallowed_connectors(directory_connectors) | ||
| .into_iter() | ||
| .filter(|connector| !accessible_connector_ids.contains(connector.id.as_str())) | ||
| .filter(|connector| allowed_connector_ids.contains(connector.id.as_str())) | ||
| .filter(|connector| discoverable_connector_ids.contains(connector.id.as_str())) | ||
| .collect::<Vec<_>>(); | ||
| connectors.sort_by(|left, right| { | ||
| left.name | ||
|
|
@@ -377,6 +375,16 @@ fn filter_tool_suggest_discoverable_tools( | |
| connectors | ||
| } | ||
|
|
||
| fn tool_suggest_connector_ids(config: &Config) -> HashSet<String> { | ||
| PluginsManager::new(config.codex_home.clone()) | ||
| .plugins_for_config(config) | ||
|
Comment on lines
+378
to
+380
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. confirming-- we only want to suggest connectors that are associated with plugins? if they have no plugins installed, this would be empty, right? |
||
| .capability_summaries() | ||
| .iter() | ||
| .flat_map(|plugin| plugin.app_connector_ids.iter()) | ||
| .map(|connector_id| connector_id.0.clone()) | ||
| .collect() | ||
| } | ||
|
|
||
| async fn list_directory_connectors_for_tool_suggest_with_auth( | ||
| config: &Config, | ||
| auth: Option<&CodexAuth>, | ||
|
|
@@ -675,6 +683,7 @@ pub(crate) fn codex_app_tool_is_enabled( | |
| const DISALLOWED_CONNECTOR_IDS: &[&str] = &[ | ||
| "asdk_app_6938a94a61d881918ef32cb999ff937c", | ||
| "connector_2b0a9009c9c64bf9933a3dae3f2b1254", | ||
| "connector_3f8d1a79f27c4c7ba1a897ab13bf37dc", | ||
| "connector_68de829bf7648191acd70a907364c67c", | ||
| "connector_68e004f14af881919eb50893d3d9f523", | ||
| "connector_69272cb413a081919685ec3c88d1744e", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| use anyhow::Context; | ||
| use tracing::warn; | ||
|
|
||
| use super::OPENAI_CURATED_MARKETPLACE_NAME; | ||
| use super::PluginCapabilitySummary; | ||
| use super::PluginReadRequest; | ||
| use super::PluginsManager; | ||
| use crate::config::Config; | ||
| use crate::features::Feature; | ||
|
|
||
| const TOOL_SUGGEST_DISCOVERABLE_PLUGIN_ALLOWLIST: &[&str] = &[ | ||
| "github@openai-curated", | ||
| "notion@openai-curated", | ||
| "slack@openai-curated", | ||
| "gmail@openai-curated", | ||
| "google-calendar@openai-curated", | ||
| "google-docs@openai-curated", | ||
| "google-drive@openai-curated", | ||
| "google-sheets@openai-curated", | ||
| "google-slides@openai-curated", | ||
| ]; | ||
|
|
||
| pub(crate) fn list_tool_suggest_discoverable_plugins( | ||
| config: &Config, | ||
| ) -> anyhow::Result<Vec<PluginCapabilitySummary>> { | ||
| if !config.features.enabled(Feature::Plugins) { | ||
| return Ok(Vec::new()); | ||
| } | ||
|
|
||
| let plugins_manager = PluginsManager::new(config.codex_home.clone()); | ||
| let marketplaces = plugins_manager | ||
| .list_marketplaces_for_config(config, &[]) | ||
| .context("failed to list plugin marketplaces for tool suggestions")?; | ||
| let Some(curated_marketplace) = marketplaces | ||
| .into_iter() | ||
| .find(|marketplace| marketplace.name == OPENAI_CURATED_MARKETPLACE_NAME) | ||
| else { | ||
| return Ok(Vec::new()); | ||
| }; | ||
|
|
||
| let mut discoverable_plugins = Vec::<PluginCapabilitySummary>::new(); | ||
| for plugin in curated_marketplace.plugins { | ||
| if plugin.installed | ||
| || !TOOL_SUGGEST_DISCOVERABLE_PLUGIN_ALLOWLIST.contains(&plugin.id.as_str()) | ||
| { | ||
| continue; | ||
| } | ||
| let plugin_id = plugin.id.clone(); | ||
| let plugin_name = plugin.name.clone(); | ||
|
|
||
| match plugins_manager.read_plugin_for_config( | ||
| config, | ||
| &PluginReadRequest { | ||
| plugin_name, | ||
| marketplace_path: curated_marketplace.path.clone(), | ||
| }, | ||
| ) { | ||
| Ok(plugin) => discoverable_plugins.push(plugin.plugin.into()), | ||
| Err(err) => warn!("failed to load curated plugin suggestion {plugin_id}: {err:#}"), | ||
| } | ||
| } | ||
| discoverable_plugins.sort_by(|left, right| { | ||
| left.display_name | ||
| .cmp(&right.display_name) | ||
| .then_with(|| left.config_name.cmp(&right.config_name)) | ||
| }); | ||
| Ok(discoverable_plugins) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| #[path = "discoverable_tests.rs"] | ||
| mod tests; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.