mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
## Why Connector declarations currently enter Codex through broad plugin capability summaries, then MCP setup, turn tooling, and `app/list` each reconstruct the same information. That makes executor-selected connectors difficult to add without coupling connector behavior to the host plugin loader. This PR introduces a small connector-owned value that later stack layers can populate before thread startup. ## What changed - Move the pure app-declaration parser into `codex-connectors`, preserving declaration order and category cleanup while leaving host-side validation and deduplication unchanged. - Add an immutable `ConnectorSnapshot` with ordered connector IDs and plugin display-name provenance. - Adapt the existing local-plugin capability summaries into that snapshot at current consumer boundaries. - Use the snapshot for MCP tool provenance, turn connector inventory, and `app/list`. - Keep the crate API narrow: no test-only snapshot accessors are exposed. The externally visible behavior is unchanged. Connector tools still come from the orchestrator-owned `/ps/mcp` server, and local plugin enablement remains owned by the existing plugin loader. ## Stack scope This is the foundation only. It does not read selected executor packages or change thread startup. #29852 adds the executor-backed declaration reader, and #29856 composes selected declarations into a thread snapshot.
51 lines
1.4 KiB
Rust
51 lines
1.4 KiB
Rust
use codex_plugin::AppConnectorId;
|
|
use codex_plugin::AppDeclaration;
|
|
use indexmap::IndexMap;
|
|
use serde::Deserialize;
|
|
use serde_json::Value;
|
|
|
|
#[derive(Debug, Default, Deserialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
struct PluginAppFile {
|
|
#[serde(default)]
|
|
apps: IndexMap<String, PluginAppConfig>,
|
|
}
|
|
|
|
#[derive(Debug, Default, Deserialize)]
|
|
struct PluginAppConfig {
|
|
id: String,
|
|
category: Option<String>,
|
|
}
|
|
|
|
/// Parses connector declarations from a plugin app configuration file.
|
|
pub fn parse_plugin_app_config(contents: &str) -> serde_json::Result<Vec<AppDeclaration>> {
|
|
serde_json::from_str(contents).map(app_declarations_from_file)
|
|
}
|
|
|
|
/// Parses connector declarations from an already-decoded plugin app configuration.
|
|
pub fn parse_plugin_app_config_value(value: Value) -> serde_json::Result<Vec<AppDeclaration>> {
|
|
serde_json::from_value(value).map(app_declarations_from_file)
|
|
}
|
|
|
|
fn app_declarations_from_file(parsed: PluginAppFile) -> Vec<AppDeclaration> {
|
|
parsed
|
|
.apps
|
|
.into_iter()
|
|
.map(|(name, app)| AppDeclaration {
|
|
name,
|
|
connector_id: AppConnectorId(app.id),
|
|
category: cleaned_category(app.category),
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
fn cleaned_category(category: Option<String>) -> Option<String> {
|
|
category
|
|
.map(|category| category.trim().to_string())
|
|
.filter(|category| !category.is_empty())
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "plugin_config_tests.rs"]
|
|
mod tests;
|