Browse documentation
Docs/API

Embed full Core in a browser

Full Core WASM runs Grid's canonical Rust LIR evaluator and resident model session. It retains the pure Tree, grammar, symbolic, algebra, graph, solver, exact-value and Workbook libraries.…

Embed full Core in a browser

Full Core WASM runs Grid's canonical Rust LIR evaluator and resident model session. It retains the pure Tree, grammar, symbolic, algebra, graph, solver, exact-value and Workbook libraries. Nano and Mini remain separate, restricted profiles. Native services and external execution need a host and are unavailable in this browser embedding.

Two independent private packages are available from the repository's local portable Build: @grid/core (core profile) and @grid/core-compiler (core-compiler profile). They are not published npm packages. A runtime that loads an existing LIR image does not download the compiler. Source compilation uses the canonical pure Core pipeline, with explicitly supplied imports and no implicit network resolver.

Compile and edit a model

Serve the generated packages over HTTPS or localhost, with JavaScript and application/wasm MIME types. Use Workers for interruptible work. This example assumes sibling runtime and compiler package directories:

import {createCoreWorkerClient} from './runtime/coreWorkerClient.mjs';

const compiler = createCoreWorkerClient(new URL('./compiler/coreCompilerWorker.mjs', import.meta.url));
const runtime = createCoreWorkerClient(new URL('./runtime/coreWorker.mjs', import.meta.url));
const compiled = await compiler.request({request: {source: `
input price = 12
input quantity = 3

total = price * quantity
`}});
if (!compiled.ok) throw new Error(JSON.stringify(compiled));

const loaded = await runtime.request({op: 'load', bytes: Uint8Array.from(compiled.lir), revision: 0});
if (!loaded.ok) throw new Error(JSON.stringify(loaded));
const changed = await runtime.request({op: 'command', request: {
  op: 'update', revision: loaded.revision, changes: [{symbol: 'price', value: 10}],
}});
if (!changed.ok) throw new Error(JSON.stringify(changed));
const result = await runtime.request({op: 'command', request: {
  op: 'resolve', revision: changed.revision, targets: ['total'], incremental: true,
}});
// result.values.total is 30. A null input value resets its override.
runtime.dispose();
compiler.dispose();

Each successful load or edit advances the revision. Stale commands refuse. A failed ordinary admission or input transaction preserves the previous model. Incremental reads use the existing native residency policy: eligible Workbook models retain dependency caches; domain-owned outputs use the general LIR reader. No alternate formula evaluator is introduced.

Ordinary results include convenient JSON values and the canonical typed response. Tree results use nativeResponse with canonical carrier bytes and media type; nativeValues contains bounded display projections. Display text is not a semantic value or replay authority. Retain the original LIR identity and native carrier when passing those values between embeddings.

Symbolic compilation may supply an explicit moduleAuthority, such as model:workspace/order. The compiler validates that authority and does not invent stable identities for anonymous symbolic declarations.

Limits and recovery

Compiler requests accept up to 8 MiB, including at most 256 supplied imports. Runtime images accept up to 64 MiB; commands accept up to 1 MiB and 4096 targets or changes. The Worker client defaults to 16 pending requests and a 30-second deadline; both are configurable when creating the client.

Pass an AbortSignal as the second request argument to cancel work. Cancellation, a deadline, or a fatal trap retires the whole Worker and rejects pending work. The next request starts a fresh Worker. Reload the model explicitly; the client never replays source or edits silently. dispose() permanently closes a client.

Browser stack limits differ. The measured WebKit Worker exhausts its stack at 128 nested parentheses; Chromium and Firefox accept that probe. All three recover with a fresh Worker and accept the 16-level nested-source control. These probes are not universal depth thresholds: expression shape also affects stack use. A trapped synchronous binding cannot be reused. Native filesystem, network and specialized service authority do not become available after a retry.