Base: codex-main originale (prima del fork aKode)
This commit is contained in:
6
codex-rs/ext/connectors/BUILD.bazel
Normal file
6
codex-rs/ext/connectors/BUILD.bazel
Normal file
@@ -0,0 +1,6 @@
|
||||
load("//:defs.bzl", "codex_rust_crate")
|
||||
|
||||
codex_rust_crate(
|
||||
name = "connectors",
|
||||
crate_name = "codex_connectors_extension",
|
||||
)
|
||||
24
codex-rs/ext/connectors/Cargo.toml
Normal file
24
codex-rs/ext/connectors/Cargo.toml
Normal file
@@ -0,0 +1,24 @@
|
||||
[package]
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
name = "codex-connectors-extension"
|
||||
version.workspace = true
|
||||
|
||||
[lib]
|
||||
name = "codex_connectors_extension"
|
||||
path = "src/lib.rs"
|
||||
doctest = false
|
||||
test = false
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
codex-connectors = { workspace = true }
|
||||
codex-core-plugins = { workspace = true }
|
||||
codex-file-system = { workspace = true }
|
||||
codex-plugin = { workspace = true }
|
||||
codex-utils-path-uri = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
6
codex-rs/ext/connectors/src/lib.rs
Normal file
6
codex-rs/ext/connectors/src/lib.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
//! Plugin app declaration loading.
|
||||
|
||||
mod plugin_app;
|
||||
|
||||
pub use plugin_app::PluginAppProvider;
|
||||
pub use plugin_app::PluginAppProviderError;
|
||||
68
codex-rs/ext/connectors/src/plugin_app.rs
Normal file
68
codex-rs/ext/connectors/src/plugin_app.rs
Normal file
@@ -0,0 +1,68 @@
|
||||
use codex_connectors::parse_plugin_app_config;
|
||||
use codex_core_plugins::ResolvedExecutorPlugin;
|
||||
use codex_file_system::ReadFileOptions;
|
||||
use codex_plugin::AppDeclaration;
|
||||
use codex_plugin::PluginResourceLocator;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use std::io;
|
||||
use thiserror::Error;
|
||||
|
||||
/// Loads app declarations from a resolved plugin.
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct PluginAppProvider;
|
||||
|
||||
/// Failure to load app declarations from a plugin.
|
||||
#[derive(Debug, Error)]
|
||||
pub enum PluginAppProviderError {
|
||||
#[error("failed to read app config for selected plugin `{plugin_id}` at `{path}`: {source}")]
|
||||
ReadConfig {
|
||||
plugin_id: String,
|
||||
path: PathUri,
|
||||
#[source]
|
||||
source: io::Error,
|
||||
},
|
||||
#[error("failed to parse app config for selected plugin `{plugin_id}` at `{path}`: {source}")]
|
||||
ParseConfig {
|
||||
plugin_id: String,
|
||||
path: PathUri,
|
||||
#[source]
|
||||
source: serde_json::Error,
|
||||
},
|
||||
}
|
||||
|
||||
impl PluginAppProvider {
|
||||
/// Returns the app declarations contributed by `plugin`.
|
||||
#[tracing::instrument(name = "connectors.plugin.declarations.load", skip_all)]
|
||||
pub async fn load(
|
||||
&self,
|
||||
plugin: &ResolvedExecutorPlugin,
|
||||
) -> Result<Vec<AppDeclaration>, PluginAppProviderError> {
|
||||
let resolved_plugin = plugin.plugin();
|
||||
let plugin_id = resolved_plugin.selected_root_id();
|
||||
let Some(PluginResourceLocator::Environment {
|
||||
path: config_path, ..
|
||||
}) = resolved_plugin.manifest().paths.apps.as_ref()
|
||||
else {
|
||||
return Ok(Vec::new());
|
||||
};
|
||||
let contents = plugin
|
||||
.file_system()
|
||||
.read_file_text(
|
||||
config_path,
|
||||
ReadFileOptions::default(),
|
||||
/*sandbox*/ None,
|
||||
)
|
||||
.await
|
||||
.map_err(|source| PluginAppProviderError::ReadConfig {
|
||||
plugin_id: plugin_id.to_string(),
|
||||
path: config_path.clone(),
|
||||
source,
|
||||
})?;
|
||||
|
||||
parse_plugin_app_config(&contents).map_err(|source| PluginAppProviderError::ParseConfig {
|
||||
plugin_id: plugin_id.to_string(),
|
||||
path: config_path.clone(),
|
||||
source,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user