spt-web-bridge
WASM bridge exposing the SmartBrain cognitive engine to JavaScript
Overview
spt-web-bridge is the WebAssembly bridge layer between the Rust cognitive engine and web applications running in the browser. Since spt-core depends on platform-specific storage (redb, mmap), this crate implements a simplified in-memory engine with the same API surface, using substring matching rather than HNSW indexing. It compiles as a cdylib for wasm-pack and exposes operations via wasm-bindgen.
Key Features
- WASM-bindgen FFI -- exposes
SptWebBridgeclass to JavaScript with constructor, init, and cognitive ops - In-memory engine -- lightweight memory store with substring-based relevance scoring
- Think operation -- search memories by query with ranked results and summary
- Memory CRUD -- add, retrieve, list, and search memory records from JS
- Statistics and diagnostics -- engine stats and system info exposed to the web app
Dependencies
No internal SPT crate dependencies. Uses wasm-bindgen for JS interop, serde/serde-wasm-bindgen for serialization, uuid for record IDs, chrono for timestamps.
Usage
javascript
// JavaScript usage after wasm-pack build
import { SptWebBridge } from 'spt-web-bridge';
const bridge = new SptWebBridge();
bridge.initialize();
bridge.add_memory("My first memory", "knowledge", 0.8);
const results = bridge.think("first");API Reference
Core Types
| Type | Description |
|---|---|
SptWebBridge | Main WASM-exposed bridge struct (JS class) |
MemoryRecord | A single memory with id, content, type, importance, timestamps |
SearchResult | A memory record with relevance score |
ThinkResult | Query results with ranked matches and summary |
Stats | Engine statistics (count, types, avg importance) |
SystemInfo | Diagnostic info (engine version, storage type, search method) |
BridgeError | Error type converted to JsValue for JS consumers |