| Crates.io | orbis-plugin-api |
| lib.rs | orbis-plugin-api |
| version | 1.0.0 |
| created_at | 2025-12-23 05:01:15.917067+00 |
| updated_at | 2025-12-23 05:01:15.917067+00 |
| description | Public API for developing Orbis plugins |
| homepage | |
| repository | https://github.com/cyberpath-HQ/orbis |
| max_upload_size | |
| id | 2000749 |
| size | 130,443 |
Public API for developing Orbis WASM plugins. This crate contains all the types, host functions, and utilities needed to create secure, stateful plugins for the Orbis application platform.
serde, serde_json, semver, and thiserrorAdd this to your Cargo.toml:
[dependencies]
orbis-plugin-api = "0.1"
[package]
name = "my-plugin"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[dependencies]
orbis-plugin-api = { path = "path/to/orbis-plugin-api" }
serde = { version = "1.0", features = ["derive"], default-features = false }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
[profile.release]
opt-level = "z"
lto = true
strip = true
#![no_std]
extern crate alloc;
use alloc::{format, string::String, vec::Vec};
use orbis_plugin_api::{LogLevel, PluginContext};
use serde::{Deserialize, Serialize};
// Import host functions
unsafe extern "C" {
fn log(level: i32, ptr: *const u8, len: i32);
fn state_get(key_ptr: *const u8, key_len: i32) -> *const u8;
fn state_set(key_ptr: *const u8, key_len: i32, value_ptr: *const u8, value_len: i32) -> i32;
}
// Memory management (required)
#[unsafe(no_mangle)]
pub extern "C" fn allocate(size: i32) -> *mut u8 {
let mut buf = Vec::with_capacity(size as usize);
let ptr = buf.as_mut_ptr();
core::mem::forget(buf);
ptr
}
#[unsafe(no_mangle)]
pub extern "C" fn deallocate(ptr: *mut u8, size: i32) {
unsafe { let _ = Vec::from_raw_parts(ptr, 0, size as usize); }
}
// Lifecycle hooks
#[unsafe(no_mangle)]
pub extern "C" fn init() -> i32 {
// Initialize plugin
1 // Success
}
// Handler function
#[unsafe(no_mangle)]
pub extern "C" fn my_handler(context_ptr: i32, context_len: i32) -> i32 {
// Process request and return response pointer
0
}
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
cargo build --target wasm32-unknown-unknown --release
state_get(key_ptr, key_len) -> ptrGet a value from plugin state. Returns NULL if key not found, otherwise returns pointer to length-prefixed JSON data.
state_set(key_ptr, key_len, value_ptr, value_len) -> i32Set a value in plugin state. Returns 1 on success, 0 on failure.
state_remove(key_ptr, key_len) -> i32Remove a value from plugin state. Returns 1 on success, 0 on failure.
log(level, ptr, len)Log a message at the specified level:
0 = ERROR1 = WARN2 = INFO3 = DEBUG4 = TRACESee examples/basic-plugin.rs for complete working examples.
use orbis_plugin_api::{PluginManifest, PluginPermission, PageDefinition};
let manifest = PluginManifest {
name: "my-plugin".to_string(),
version: "0.1.0".to_string(),
description: "My awesome plugin".to_string(),
permissions: vec![PluginPermission::DatabaseRead],
pages: vec![
PageDefinition {
route: "/dashboard".to_string(),
title: "Dashboard".to_string(),
// ... more configuration
}
],
// ... more fields
};
// Validate the manifest
manifest.validate()?;
use orbis_plugin_api::{PageDefinition, ComponentSchema, StateFieldDefinition, StateFieldType};
use std::collections::HashMap;
let page = PageDefinition {
route: "/users".to_string(),
title: "User Management".to_string(),
state: {
let mut state = HashMap::new();
state.insert("users".to_string(), StateFieldDefinition {
field_type: StateFieldType::Array,
default: Some(serde_json::json!([])),
nullable: false,
description: Some("List of users".to_string()),
});
state
},
sections: vec![
ComponentSchema::new("Container")
.with_id("main")
.with_child(
ComponentSchema::new("Table")
.with_prop("dataSource", serde_json::json!("state:users"))
)
],
// ... more configuration
};
PluginContext: Context passed to handler functionsPluginManifest: Main manifest structure describing the pluginPageDefinition: UI page definition with routes, state, and componentsComponentSchema: Individual UI component schemaAction: Actions that can be triggered by UI eventsLogLevel: Enum for logging levelsPlugins can request various permissions:
DatabaseRead / DatabaseWriteFileRead / FileWriteNetworkSystemShell (dangerous - requires explicit user approval)EnvironmentPages can define typed state fields:
StringNumberBooleanObjectArrayAll validation methods return orbis_plugin_api::Result<T>:
use orbis_plugin_api::{Result, Error};
fn validate_my_manifest(manifest: &PluginManifest) -> Result<()> {
manifest.validate()?;
// Additional validation
Ok(())
}