From 8347a714d283721175a937990d791a004e85b4b6 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 8 Mar 2026 01:07:43 +0300 Subject: [PATCH] pinakes-plugin-api: extend manifest with dependencies; basic WASM exchange buffer Signed-off-by: NotAShelf Change-Id: I60c0607fe27092a43826ac956e20a9a16a6a6964 --- crates/pinakes-plugin-api/src/manifest.rs | 72 ++++++++++++++++++++++- crates/pinakes-plugin-api/src/wasm.rs | 3 + 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/crates/pinakes-plugin-api/src/manifest.rs b/crates/pinakes-plugin-api/src/manifest.rs index 0b6d9f4..a334fba 100644 --- a/crates/pinakes-plugin-api/src/manifest.rs +++ b/crates/pinakes-plugin-api/src/manifest.rs @@ -24,6 +24,10 @@ pub struct PluginManifest { pub config: HashMap, } +const fn default_priority() -> u16 { + 500 +} + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PluginInfo { pub name: String, @@ -34,6 +38,11 @@ pub struct PluginInfo { pub homepage: Option, pub license: Option, + /// 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` pub kind: Vec, @@ -62,6 +71,9 @@ pub struct ManifestCapabilities { #[serde(default)] pub network: bool, + #[serde(default)] + pub allowed_domains: Option>, + #[serde(default)] pub environment: Option>, @@ -175,6 +187,12 @@ impl PluginManifest { )); } + if self.plugin.priority > 999 { + return Err(ManifestError::ValidationError( + "priority must be 0-999".to_string(), + )); + } + Ok(()) } @@ -200,7 +218,7 @@ impl PluginManifest { }, network: NetworkCapability { enabled: self.capabilities.network, - allowed_domains: None, + allowed_domains: self.capabilities.allowed_domains.clone(), }, environment: EnvironmentCapability { enabled: self.capabilities.environment.is_some(), @@ -277,6 +295,58 @@ version = "1.0.0" api_version = "1.0" 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] wasm = "plugin.wasm" "#; diff --git a/crates/pinakes-plugin-api/src/wasm.rs b/crates/pinakes-plugin-api/src/wasm.rs index 7df1018..166785f 100644 --- a/crates/pinakes-plugin-api/src/wasm.rs +++ b/crates/pinakes-plugin-api/src/wasm.rs @@ -72,6 +72,9 @@ pub mod host_functions { /// Emit an 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