Skip to main content

qualia_core_db/extensions/
extension_manifest.rs

1use serde::{Deserialize, Serialize};
2
3/// The transport mechanism used to communicate with the extension daemon.
4#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
5#[serde(rename_all = "snake_case")]
6pub enum TransportProtocol {
7    /// Localhost HTTP/REST or WebSocket over a specific port
8    LocalHttp { port: u16 },
9    /// Local named pipe (Windows) or Unix domain socket (macOS/Linux)
10    NamedPipe { pipe_name: String },
11    /// Standard Input / Standard Output (for simple one-shot binaries)
12    Stdio,
13}
14
15/// The sandbox level required by the extension.
16#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
17#[serde(rename_all = "snake_case")]
18pub enum SandboxLevel {
19    /// Strict sandbox: no network, no filesystem (except via provided zero-copy buffers)
20    Strict,
21    /// Partial sandbox: allowed specific network domains or directories
22    Partial {
23        allowed_domains: Vec<String>,
24        allowed_dirs: Vec<String>,
25    },
26    /// Trusted: full host access (requires explicit user Guardian approval to install)
27    Trusted,
28}
29
30/// Declares an individual capability exposed by the extension.
31#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
32pub struct ExtensionCapability {
33    /// The semantic interface this capability fulfills (e.g., "q42:VideoTranscode", "q42:ObjectDetection")
34    pub interface: String,
35    /// MIME types this capability can accept as input
36    pub supported_mimetypes: Vec<String>,
37    /// Expected output semantic types or MIME types
38    pub outputs: Vec<String>,
39    /// Description of what the capability does
40    pub description: String,
41}
42
43/// Defines the security profile and resource requirements for the extension.
44#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
45pub struct ExtensionSecurity {
46    pub sandbox_level: SandboxLevel,
47    /// Whether the extension requires GPU access (e.g., for OpenCV, ONNX, CUDA)
48    pub requires_gpu: bool,
49    /// Whether the extension needs to bind to local ports
50    pub requires_network_bind: bool,
51}
52
53/// The Capability Manifest schema for a Qualia-DB Extension.
54/// This defines an isolated process (like FFmpeg, OpenCV) that plugs into the local engine.
55#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
56pub struct ExtensionManifest {
57    pub extension_id: String,
58    pub version: String,
59    pub display_name: String,
60    pub description: String,
61
62    pub transport: TransportProtocol,
63    pub capabilities: Vec<ExtensionCapability>,
64    pub security: ExtensionSecurity,
65}
66
67impl ExtensionManifest {
68    /// Parses an ExtensionManifest from a JSON file.
69    pub fn from_json(json_bytes: &[u8]) -> Result<Self, serde_json::Error> {
70        serde_json::from_slice(json_bytes)
71    }
72}