Skip to content

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 SptWebBridge class 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

TypeDescription
SptWebBridgeMain WASM-exposed bridge struct (JS class)
MemoryRecordA single memory with id, content, type, importance, timestamps
SearchResultA memory record with relevance score
ThinkResultQuery results with ranked matches and summary
StatsEngine statistics (count, types, avg importance)
SystemInfoDiagnostic info (engine version, storage type, search method)
BridgeErrorError type converted to JsValue for JS consumers

Released under the MIT License.