pinakes-plugin-api: extend manifest with dependencies; basic WASM exchange buffer
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I60c0607fe27092a43826ac956e20a9a16a6a6964
This commit is contained in:
parent
cb10c84809
commit
8347a714d2
2 changed files with 74 additions and 1 deletions
|
|
@ -24,6 +24,10 @@ pub struct PluginManifest {
|
||||||
pub config: HashMap<String, toml::Value>,
|
pub config: HashMap<String, toml::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fn default_priority() -> u16 {
|
||||||
|
500
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct PluginInfo {
|
pub struct PluginInfo {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
|
@ -34,6 +38,11 @@ pub struct PluginInfo {
|
||||||
pub homepage: Option<String>,
|
pub homepage: Option<String>,
|
||||||
pub license: Option<String>,
|
pub license: Option<String>,
|
||||||
|
|
||||||
|
/// Pipeline priority (0-999). Lower values run first. Built-in handlers run
|
||||||
|
/// at 100. Default: 500.
|
||||||
|
#[serde(default = "default_priority")]
|
||||||
|
pub priority: u16,
|
||||||
|
|
||||||
/// Plugin kind(s) - e.g., `media_type`, `metadata_extractor`
|
/// Plugin kind(s) - e.g., `media_type`, `metadata_extractor`
|
||||||
pub kind: Vec<String>,
|
pub kind: Vec<String>,
|
||||||
|
|
||||||
|
|
@ -62,6 +71,9 @@ pub struct ManifestCapabilities {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub network: bool,
|
pub network: bool,
|
||||||
|
|
||||||
|
#[serde(default)]
|
||||||
|
pub allowed_domains: Option<Vec<String>>,
|
||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub environment: Option<Vec<String>>,
|
pub environment: Option<Vec<String>>,
|
||||||
|
|
||||||
|
|
@ -175,6 +187,12 @@ impl PluginManifest {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.plugin.priority > 999 {
|
||||||
|
return Err(ManifestError::ValidationError(
|
||||||
|
"priority must be 0-999".to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -200,7 +218,7 @@ impl PluginManifest {
|
||||||
},
|
},
|
||||||
network: NetworkCapability {
|
network: NetworkCapability {
|
||||||
enabled: self.capabilities.network,
|
enabled: self.capabilities.network,
|
||||||
allowed_domains: None,
|
allowed_domains: self.capabilities.allowed_domains.clone(),
|
||||||
},
|
},
|
||||||
environment: EnvironmentCapability {
|
environment: EnvironmentCapability {
|
||||||
enabled: self.capabilities.environment.is_some(),
|
enabled: self.capabilities.environment.is_some(),
|
||||||
|
|
@ -277,6 +295,58 @@ version = "1.0.0"
|
||||||
api_version = "1.0"
|
api_version = "1.0"
|
||||||
kind = ["invalid_kind"]
|
kind = ["invalid_kind"]
|
||||||
|
|
||||||
|
[plugin.binary]
|
||||||
|
wasm = "plugin.wasm"
|
||||||
|
"#;
|
||||||
|
|
||||||
|
assert!(PluginManifest::parse_str(toml).is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_priority_default() {
|
||||||
|
let toml = r#"
|
||||||
|
[plugin]
|
||||||
|
name = "test"
|
||||||
|
version = "1.0.0"
|
||||||
|
api_version = "1.0"
|
||||||
|
kind = ["media_type"]
|
||||||
|
|
||||||
|
[plugin.binary]
|
||||||
|
wasm = "plugin.wasm"
|
||||||
|
"#;
|
||||||
|
|
||||||
|
let manifest = PluginManifest::parse_str(toml).unwrap();
|
||||||
|
assert_eq!(manifest.plugin.priority, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_priority_custom() {
|
||||||
|
let toml = r#"
|
||||||
|
[plugin]
|
||||||
|
name = "test"
|
||||||
|
version = "1.0.0"
|
||||||
|
api_version = "1.0"
|
||||||
|
priority = 50
|
||||||
|
kind = ["media_type"]
|
||||||
|
|
||||||
|
[plugin.binary]
|
||||||
|
wasm = "plugin.wasm"
|
||||||
|
"#;
|
||||||
|
|
||||||
|
let manifest = PluginManifest::parse_str(toml).unwrap();
|
||||||
|
assert_eq!(manifest.plugin.priority, 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_priority_out_of_range() {
|
||||||
|
let toml = r#"
|
||||||
|
[plugin]
|
||||||
|
name = "test"
|
||||||
|
version = "1.0.0"
|
||||||
|
api_version = "1.0"
|
||||||
|
priority = 1000
|
||||||
|
kind = ["media_type"]
|
||||||
|
|
||||||
[plugin.binary]
|
[plugin.binary]
|
||||||
wasm = "plugin.wasm"
|
wasm = "plugin.wasm"
|
||||||
"#;
|
"#;
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,9 @@ pub mod host_functions {
|
||||||
|
|
||||||
/// Emit an event
|
/// Emit an event
|
||||||
pub const EMIT_EVENT: &str = "host_emit_event";
|
pub const EMIT_EVENT: &str = "host_emit_event";
|
||||||
|
|
||||||
|
/// Set result data from plugin
|
||||||
|
pub const SET_RESULT: &str = "host_set_result";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Log level for plugin logging
|
/// Log level for plugin logging
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue