The kairos-wasm crate compiles the Kairos engine to WebAssembly for browser and Node.js environments. It exports two classes: WasmEngine for raw simulation and WasmSession (behind a feature flag) for fly-by-wire evaluation.
# Default build (WasmEngine only)
wasm-pack build crates/kairos-wasm --target web
# With fly-by-wire feature (adds WasmSession)
wasm-pack build crates/kairos-wasm --target web --features fly-by-wire
wasm-pack build crates/kairos-wasm --target nodejs --features fly-by-wire
Output is an npm-publishable package in pkg/.
The WASM runtime operates in advisory mode :
Aspect WASM (advisory) Native (authoritative) Policy signature Skipped Verified License enforcement Skipped Enforced HITL override tokens Always rejected Cryptographically verified Domain/expiry checks Skipped Enforced
WASM bindings are suitable for dashboards, previews, and client-side simulations. Production enforcement must use a native licensed build.
The core simulation engine — no policy evaluation, no Substrate runtime. All methods use camelCase for JavaScript convention.
import { WasmEngine } from " kairos-wasm " ;
const engine = new WasmEngine (
{ columns: 25 , rows: 17 , lambda: 0.65 , gamma: 0.1 },
Method Returns Description setSeed(seed)voidSet RNG seed getSeed()numberGet current seed setLambda(v)voidSet λ \lambda λ parameter getLambda()numberGet λ \lambda λ parameter setGamma(v)voidSet γ \gamma γ parameter getGamma()numberGet γ \gamma γ parameter setGridSize(cols, rows)voidOverride grid dimensions setZeroSumEnabled(enabled)voidToggle zero-sum attractor capture getConfig()objectCurrent engine config
Method Returns Description getState()objectCurrent engine state (t, b, lastMove, marker) getWarningSignal()objectWarning signal (active, level, kind, metrics) setState(state)voidSet engine state setMarker(marker)voidSet marker position primaryAgentId()stringGet primary agent ID
Method Returns Description runTick()objectExecute single-agent tick runTickMulti(moves)objectExecute multi-agent tick decideNextMoveForAgent(id)MoveDirectionPolicy-decided move for one agent decideAllMoves()objectPolicy-decided moves for all agents
Method Returns Description getAgentStates()AgentState[]All agent states resetAgents(setups)voidReset agents from setup array updateAgentPolicy(id, lambda, gamma)voidUpdate per-agent policy overrides
Method Returns Description getSpecialNodes()SpecialNode[]All attractors and repulsors getSpecialNodesInRange(tMin, tMax, bMin, bMax)SpecialNode[]Nodes within bounding box setSpecialNodes(nodes)voidReplace all special nodes
Method Returns Description computeReachabilityField(horizon)voidCompute reachability DP getReachabilityTotal(t, b)numberReachability value at grid position getAllowedMoves(t, b)numberAllowed moves bitmask at position
Method Returns Description startRecording(scenarioId?)voidBegin trace recording stopRecording()object | nullEnd recording and return trace
Method Returns Description loadEventScript(events)voidLoad EDMS event script isEdmsActive()booleanCheck if EDMS is active
Method Returns Description getDestroyedBasins()object[]Destroyed basin records getCaptureEvents()object[]Zero-sum capture events
Requires the fly-by-wire feature. Combines the engine with Substrate policy evaluation in a stateful session.
import { WasmSession } from " kairos-wasm " ;
const session = new WasmSession (
{ columns: 25 , rows: 17 , lambda: 0.65 , gamma: 0.1 },
artifactJson , // Calibration artifact JSON string
policyJson , // Deployment policy JSON string
null // HMAC secret (Uint8Array or null)
Method Returns Description evaluate(request)objectEvaluate request without advancing time step(direction)objectAdvance primary actor by one tick stepActor(actorId, direction)objectAdvance specific actor by one tick stepMulti(moves)objectAdvance all actors with explicit moves decideAllMoves()objectPolicy-decided moves for all active actors
Method Returns Description getTelemetry()objectWarning signal for primary actor getTelemetryForActor(actorId)objectWarning signal for specific actor getTelemetryMap()objectWarning signals for all active actors
Method Returns Description previewProjection(actorId, horizon)objectProjection preview for actor previewProjectionForPrimary(horizon)objectProjection preview for primary actor previewTimelineEvents(horizon)object[]Upcoming EDMS timeline events
Method Returns Description registerActor(setup)voidRegister a new actor unregisterActor(actorId)voidRemove a non-primary actor
Method Returns Description loadScenario(scenario)voidLoad scenario into session engine loadEventScript(events)voidLoad EDMS event script currentTick()numberCurrent engine tick
import init, { WasmEngine } from " kairos-wasm " ;
const engine = new WasmEngine (
{ columns: 25 , rows: 17 , lambda: 0.65 , gamma: 0.1 },
for ( let i = 0 ; i < 200 ; i ++ ) {
const moves = engine . decideAllMoves ();
const result = engine . runTickMulti ( moves );
const state = engine . getState ();
console . log ( ` Position: t= ${ state . t } , b= ${ state . b } ` );
All complex data crosses the WASM boundary via serde-wasm-bindgen — JavaScript objects map directly to Rust structs without JSON serialization overhead. Rust panics are caught by console_error_panic_hook and surfaced as JavaScript errors.