@nemoir/compiler-wasm
v0.1.7
Published
Browser-callable compiler API as WebAssembly. Owns the worker-side bridge between the Monaco DSL editor and the NemoIR compiler stack.
Maintainers
Readme
@nemoir/compiler-wasm
Browser-callable NemoIR compiler as WebAssembly — the Worker-side bridge between the Monaco DSL editor and the NemoIR compiler stack.
What this package is
@nemoir/compiler-wasm wraps the NemoIR DSL and visual frontends, IR
validator, and backend code generators in a single WebAssembly module. It exposes six
typed entry points:
analyze(request)— parse, lower, and validate.nemosource; returns structured diagnostics and optionally the lowered IR.generate(request)— run the full compiler pipeline and invoke a selected backend to produce downloadable source artifacts (Python package, web app, visualizer HTML).metadata()— return compiler crate version, IR schema version, and the list of supported targets.analyzeVisual(request)— validate and lower a visual semantic document (JSON) directly into shared IR; visual diagnostics carryphase: "visual"and avisualLocationinstead of a source range.generateVisual(request)— run the visual pipeline and invoke a selected backend to produce a downloadable artifact.visualMetadata()— return the visual schema version and the capability catalogue used for tool-stage and policy validation.
All responses are plain JavaScript objects (no Map instances), so they are
safe for structuredClone, JSON.stringify, and postMessage.
Installation
npm install @nemoir/compiler-wasmBrowser usage
import init, { analyze, generate, metadata } from "@nemoir/compiler-wasm";
await init(); // fetches and instantiates the WebAssembly module
const result = analyze({
source: 'workflow Hello { stage @entry A { prompt:"hi" } }',
filename: "workflow.nemo",
includeIr: true,
});
console.log(result.ok); // true
console.log(result.diagnostics); // []
console.log(result.ir); // the validated WorkflowIr as a plain objectThe package uses wasm-pack --target web, so the .wasm asset is loaded
via fetch. For synchronous initialization (e.g. in a Worker with raw
bytes), use initSync:
import { initSync, analyze } from "@nemoir/compiler-wasm";
const wasmBytes = await fetch("/nemoir_wasm_bg.wasm").then(r => r.arrayBuffer());
initSync(wasmBytes);Targets
| Target | Output |
|--------|--------|
| none | Validated IR JSON (no artifact file) |
| visualizer | Standalone workflow visualization HTML |
| python | Installable Python package source tree |
| web | Vite/TypeScript browser-app source tree |
Visual frontend
The visual entry points accept a parsed JSON semantic document (schemaVersion,
workflow, states, controlEdges, dataEdges, policies) and lower it
into the same shared WorkflowIr as the DSL frontend:
import { analyzeVisual } from "@nemoir/compiler-wasm";
const result = analyzeVisual({
document: { schemaVersion: "0.1", workflow: { id: "Hello", inputs: [] }, /* ... */ },
filename: "workflow.visual.json",
includeIr: true,
});The document is a semantic document only: it carries no canvas layout and is
never serialized as .nemo source or interpreted as raw WorkflowIr. The full
visual document shape is documented in the companion TypeScript declaration
file (api.d.ts); the canonical public guide is the
visual frontend guide.
API types
All request and response types are documented in the companion TypeScript declaration file. The canonical compiler semantics live in the NemoIR compiler docs, including the browser compiler guide.
Local development
Build this package from the compiler checkout root (the directory containing
Cargo.toml):
rustup target add wasm32-unknown-unknown
wasm-pack build crates/nemoir-wasm --target web --release --scope nemoir
# The generated pkg/ directory is ready for local consumption.For integrated development with the browser editor app, point its
package.json at the generated pkg/ directory. In a NemoIR meta checkout,
this path is relative to web/nemoir-compiler/package.json:
"@nemoir/compiler-wasm": "file:../../compiler/crates/nemoir-wasm/pkg"See also web/nemoir-compiler/README.md for the full browser-application
build instructions.
License
MIT
