@ai-matrx/code-runtime
v0.4.88
Published
The AI Matrx in-frame code runtime: compiles stored multi-file TSX (Applets, kind components, tool and emit renderers, code blocks) against one documented import scope, with named stand-ins for anything unresolved, the one source-gate list, and a compile
Maintainers
Readme
@ai-matrx/code-runtime
Compile stored TSX — one file or many — into a React component, against one documented import scope, with a visible, reported stand-in for anything the scope cannot supply.
import { compile, gate } from "@ai-matrx/code-runtime";
const files = {
"App.tsx": `import { Form } from "./Form"; export default () => <Form />;`,
"Form.tsx": `import { Button } from "@ai-matrx/design-system/controls";
export const Form = () => <Button>Save</Button>;`,
};
if (gate(files).some((f) => f.severity === "refuse")) throw new Error("refused");
const r = compile(files, "App.tsx", { entries: ["react", "@ai-matrx/design-system/controls"], shadowDangerousGlobals: true });
if (r.ok) render(<r.Component />); else show(r.error.message);- Scope:
listScopeEntries()is the whole registry. Package-owned entries work anywhere (Next.js, Vite). Host-owned ones (Markdown, kind-kit, copy buttons, Applet parts, heavy libraries) are supplied once:provideScopeModules({ "@/components/MarkdownStream": () => mod }). Async entries (recharts) needawait prepareScope(spec)orcompileAsync. A documented library a body imports always enters its scope; awaitprepareSource(code)/prepareGraph(graph)(or pollpendingEntriesFor(code)) before a synchronous compile so it is loaded. - Sandbox split: the parent runs
@ai-matrx/code-runtime/transform(transformFiles) and posts the JSON graph; the frame runs@ai-matrx/code-runtime/execute(executeGraph), no Babel. - Gate:
@ai-matrx/code-runtime/gateis pure (servers, write paths). The lists ship as@ai-matrx/code-runtime/gate-lists.json. - Kinds: inject
kindComponentCompiler()into@ai-matrx/content-ir/react'screateDbKindComponentCache({ compile }).
Not a security boundary: the dangerous-global stubs shadow bare identifiers only. Isolation is the sandbox frame.
