orbis-plugin-api
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.
Features
- WASM Runtime Interface: Complete host function bindings for plugin development
- Stateful by Default: Built-in state management with JSON serialization
- Plugin Manifest: Define plugin metadata, dependencies, permissions, and routes
- UI Schema: Declarative JSON-based UI definition system for creating plugin pages
- Type Safety: Strongly-typed Rust definitions that serialize to JSON
- Comprehensive Logging: Multiple log levels (ERROR, WARN, INFO, DEBUG, TRACE)
- Memory Management: Automatic allocation/deallocation patterns
- Minimal Dependencies: Only requires
serde,serde_json,semver, andthiserror
Usage
Add this to your Cargo.toml:
[]
= "0.1"
Quick Start: WASM Plugin
1. Project Setup
[]
= "my-plugin"
= "0.1.0"
= "2021"
[]
= ["cdylib"]
[]
= { = "path/to/orbis-plugin-api" }
= { = "1.0", = ["derive"], = false }
= { = "1.0", = false, = ["alloc"] }
[]
= "z"
= true
= true
2. Plugin Implementation
extern crate alloc;
use ;
use ;
use ;
// Import host functions
unsafe extern "C"
// Memory management (required)
pub extern "C"
pub extern "C"
// Lifecycle hooks
pub extern "C"
// Handler function
pub extern "C"
!
3. Build
Host Functions Reference
State Management
state_get(key_ptr, key_len) -> ptr
Get 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) -> i32
Set a value in plugin state. Returns 1 on success, 0 on failure.
state_remove(key_ptr, key_len) -> i32
Remove a value from plugin state. Returns 1 on success, 0 on failure.
Logging
log(level, ptr, len)
Log a message at the specified level:
0= ERROR1= WARN2= INFO3= DEBUG4= TRACE
See examples/basic-plugin.rs for complete working examples.
Creating UI Manifests
Creating a Plugin Manifest
use ;
let manifest = PluginManifest ;
// Validate the manifest
manifest.validate?;
Defining UI Pages
use ;
use HashMap;
let page = PageDefinition ;
Type Reference
Core Types
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 levels
Permissions
Plugins can request various permissions:
DatabaseRead/DatabaseWriteFileRead/FileWriteNetworkSystemShell(dangerous - requires explicit user approval)Environment
State Management
Pages can define typed state fields:
StringNumberBooleanObjectArray
Error Handling
All validation methods return orbis_plugin_api::Result<T>:
use ;