Expand description
NeoMind Extension SDK
A unified SDK for developing NeoMind extensions that can be compiled for both Native and WASM targets.
§Features
- Unified trait system for Native and WASM
- Automatic FFI export generation
- Helper macros for common patterns
- Type-safe metric and command definitions
- Single-source IPC boundary types
§Architecture (V2 - Process Isolation)
All extensions run in isolated processes by default:
┌─────────────────────────────────────────────────────────────┐
│ NeoMind Main Process │
│ - UnifiedExtensionService manages all extensions │
│ - IPC communication via stdin/stdout │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Extension Runner Process │
│ - Your extension runs here in isolation │
│ - Native: loaded via FFI │
│ - WASM: executed via wasmtime │
│ - Crashes don't affect main process │
└─────────────────────────────────────────────────────────────┘§ABI Stability
The IPC boundary types in ipc_types are the stable protocol between
extensions and the main process. Extensions compiled against older SDK
versions will continue to work because:
- Types are serialized as JSON over IPC
- Only the JSON format matters, not the implementation
- New fields use
#[serde(default)]for forward compatibility
§Quick Start
ⓘ
use neomind_extension_sdk::prelude::*;
// Define your extension struct
pub struct MyExtension {
counter: std::sync::atomic::AtomicI64,
}
impl MyExtension {
pub fn new() -> Self {
Self {
counter: std::sync::atomic::AtomicI64::new(0),
}
}
}
// Implement the Extension trait
#[async_trait]
impl Extension for MyExtension {
fn metadata(&self) -> &ExtensionMetadata {
static META: ExtensionMetadata = ExtensionMetadata::new(
"my-extension",
"My Extension",
"1.0.0",
);
&META
}
fn metrics(&self) -> Vec<MetricDescriptor> {
vec![
MetricDescriptor::new("counter", "Counter", MetricDataType::Integer)
.with_unit("count")
]
}
fn commands(&self) -> Vec<ExtensionCommand> {
vec![
CommandBuilder::new("increment")
.display_name("Increment")
.param(
ParamBuilder::new("amount", MetricDataType::Integer)
.display_name("Amount")
.default(MetricValue::Integer(1))
.build()
)
.build()
]
}
async fn execute_command(&self, command: &str, args: &serde_json::Value) -> Result<serde_json::Value> {
match command {
"increment" => {
let amount = args.get("amount").and_then(|v| v.as_i64()).unwrap_or(1);
let new_value = self.counter.fetch_add(amount, std::sync::atomic::Ordering::SeqCst) + amount;
Ok(serde_json::json!({ "counter": new_value }))
}
_ => Err(ExtensionError::CommandNotFound(command.to_string())),
}
}
fn produce_metrics(&self) -> Result<Vec<ExtensionMetricValue>> {
Ok(vec![
ExtensionMetricValue::new(
"counter",
MetricValue::Integer(self.counter.load(std::sync::atomic::Ordering::SeqCst))
)
])
}
}
// Export FFI functions
neomind_export!(MyExtension);Modules§
- capabilities
- Unified Capabilities Module (Native + WASM support)
- capability_
constants - Capability name constants - re-exported from host module
- ipc
- Stable IPC boundary types for extension communication.
- native
- Native-specific extension utilities
- prelude
- NeoMind Extension SDK Prelude
- utils
- Utility functions for extension development
Macros§
- create_
c_ metadata - Create a C-compatible metadata structure
- define_
commands - Define commands for an extension (helper macro)
- define_
metrics - Define metrics for an extension (helper macro)
- define_
params - Define parameters for a command (helper macro)
- ext_
debug - Extension debug log
- ext_
error - Extension error log
- ext_
info - Extension info log
- ext_log
- Helper macro to log a message
- ext_
warn - Extension warning log
- json
- Construct a
serde_json::Valuefrom a JSON literal. - metric_
bool - Helper macro to create a boolean metric value
- metric_
float - Helper macro to create a float metric value
- metric_
int - Helper macro to create an integer metric value
- metric_
string - Helper macro to create a string metric value
- metric_
value - Helper macro to create a metric value
- neomind_
export - Export FFI functions for an extension type
- neomind_
export_ with_ constructor - Export FFI functions with a custom constructor
- neomind_
extension - Define an extension with configuration-style syntax
- neomind_
extension_ metric_ type - Helper macro to convert type name to MetricDataType
- neomind_
extension_ param_ type - Helper macro to convert type name to MetricDataType for parameters
- neomind_
simple_ extension - Simplified extension definition with minimal boilerplate
- static_
commands - Create a static slice of commands
- static_
metadata - Create a static ExtensionMetadata
- static_
metrics - Create a static slice of metrics
Structs§
- ArgParser
- Helper for parsing command arguments
- Available
Capabilities - Available capabilities registry.
- Batch
Command - Single command in a batch
- Batch
Result - Result of a single command execution
- Batch
Results Vec - Container for batch execution results
- CExtension
Metadata - C-compatible extension metadata for FFI.
- Capability
Context - Capability context for invoking capabilities from extensions. Only available on native targets (requires tokio runtime).
- Capability
Manifest - Capability manifest for extension capabilities.
- Client
Info - Client information.
- Command
Builder - Helper type for building command definitions
- Command
Descriptor - Command definition/descriptor.
- Component
Size - Component size definition
- Data
Chunk - Data chunk for streaming.
- Event
Filter - Event filter for subscriptions.
- Event
Subscription - Event subscription configuration.
- Extension
Context - Extension context for capability invocation.
- Extension
Context Config - Extension context configuration.
- Extension
Descriptor - Complete extension descriptor.
- Extension
Metadata - Extension metadata.
- Extension
Metric Value - Extension metric value with timestamp.
- Extension
Runtime State - Dynamic runtime state for a loaded extension.
- Extension
Stats - Extension runtime statistics.
- Flow
Control - Flow control configuration.
- Frontend
Component - Frontend component definition
- Frontend
Manifest - Frontend component manifest for extensions
- Frontend
Manifest Builder - Builder for creating frontend manifests
- I18n
Config - i18n configuration
- IpcFrame
- Frame format for IPC communication
- Metric
Builder - Helper type for building metric descriptors
- Metric
Descriptor - Metric definition/descriptor.
- Param
Builder - Helper type for building parameter definitions
- Parameter
Definition - Parameter definition for commands.
- Parameter
Group - Parameter group for organizing command parameters.
- Push
Output Data - Push output data (extracted from PushOutput response) Used for forwarding push data to WebSocket clients
- Push
Output Message - Message sent from extension to host for Push mode streaming.
- SdkCommand
Definition - Command definition (SDK-specific)
- SdkExtension
Metadata - Extension metadata for SDK (SDK-specific fields)
- SdkExtension
Metric Value - Extension metric value with name, value and timestamp (SDK-specific)
- SdkMetric
Definition - Metric definition (SDK-specific)
- SdkParameter
Definition - Parameter definition for commands (SDK-specific)
- SdkParameter
Group - Parameter group for organizing command parameters
- Session
Stats - Session statistics.
- Stream
Capability - Stream capability descriptor.
- Stream
Client Info - Stream client info (for IPC transfer)
- Stream
Data Chunk - Stream data chunk (for IPC transfer)
- Stream
Error - Stream error.
- Stream
Result - Stream result.
- Stream
Session - Stream session.
- Validation
Rule - Validation rule for parameters.
Enums§
- Capability
Error - Error type for capability operations.
- Error
Kind - Error kind classification for IPC
- Extension
Capability - Extension capabilities for accessing NeoMind platform features.
- Extension
Error - Extension error types.
- Frontend
Component Type - Component type enumeration
- IpcMessage
- IPC message sent from host to extension process
- IpcResponse
- IPC response sent from extension process to host
- Metric
Data Type - Metric data type enumeration.
- Metric
Value - Metric value for parameters and measurements.
- SdkExtension
Error - Extension error type (SDK-specific)
- SdkMetric
Data Type - Metric data types (SDK-specific)
- SdkMetric
Value - Metric value (SDK-specific)
- Stream
Data Type - Stream data type.
- Stream
Direction - Stream direction.
- Stream
Mode - Stream mode.
- Value
- Represents any valid JSON value.
Constants§
- ABI_
VERSION - ABI version for dynamic loading. This must be incremented when breaking changes are made to IPC types.
- MAX_
IPC_ FRAME_ SIZE - Maximum IPC frame payload size (16 MB) This prevents malicious extensions from sending extremely large messages that could exhaust main process memory.
- MIN_
NEOMIND_ VERSION - Minimum NeoMind core version required
- SDK_
ABI_ VERSION - ABI version for the unified SDK
- SDK_
VERSION - SDK version
Traits§
- Extension
- Core extension trait that all NeoMind extensions must implement.
- Extension
Capability Provider - Trait for capability providers.
Functions§
- current_
timestamp_ ms - Get current timestamp in milliseconds.
- current_
timestamp_ secs - Get current timestamp in seconds.
- send_
push_ output - Send a push-output message from the extension to the host.
- set_
native_ capability_ bridge - Set the native capability bridge for FFI.
- set_
push_ output_ writer - Called by the generated FFI registration function to install the push-output writer callback. Returns 0 on success.
Type Aliases§
- Command
Definition - Alias for backward compatibility.
- Extension
Command - Alias for backward compatibility.
- Metric
Definition - Native
Capability Free Fn - Native
Capability Invoke Fn - Native capability function types.
- Param
Metric Value - Alias for backward compatibility with existing code.
- Push
Output Writer Fn - Function pointer type for writing push output from extension → runner. The runner registers this callback so the extension can push data without going through the JSON FFI round-trip.
- Result
- Result type for extension operations.
- SdkResult
- Result type for SDK extension operations