@arnilo/liveframe

中文文档
0.2.3发布于 2026/11/04MITTypeScriptES Module构建来源已验证近 30 天下载 2621

Runtime-composable UI: primitives, design-system recipes and TSX widgets that change an app's UI without a deployment.

原始使用文档
文档目录8 节
  1. Install
  2. Quickstart
  3. What is in the package
  4. Use it with a coding agent
  5. Guides
  6. Status
  7. Development
  8. License

Liveframe

CI

Runtime-composable UI for apps: people and AI agents install TSX widgets at runtime and the app's UI changes, with no deployment.

An app ships a small set of trusted primitive components and a design system. Widgets are ordinary TSX written against those primitives. Widget code runs on the app's backend; the browser only draws a validated tree with the app's own components, so the UI looks native and no widget code runs in the page.

Four rules, none of them optional:

  1. Widget code never runs in the browser. Only the app's compiled primitives run there.
  2. The UI tree is data, and it is validated before the renderer reads it.
  3. Widget code never sets colours or raw CSS. Look comes from the design system; layout comes from token-constrained style props.
  4. A widget never holds authority. Data is resolved and actions are run by the app, as the viewer.

Specification · How a surface is built · Security model · Compatibility · Changelog

Install

bun add @arnilo/liveframe

Each peer is optional and only the subpaths that need it use it:

PeerRangeNeeded by
react, react-dom^19.0.0/react, /preview/react, /conformance/react
playwright^1.49.0liveframe preview capture, the MCP server's capture_preview
@modelcontextprotocol/server^2.0.0liveframe mcp

The backend subpaths (/store/fs, /preview/worker, the in-process package loader and the CLI) need Bun ≥ 1.4.2. The host-API-free subpaths need ES2022 plus only the globals listed below. The browser subpaths (/css, /react, /preview/react, /conformance/react) need any ESM bundler. The package ships compiled ES2022 JavaScript with .d.ts declarations and the published JSON Schemas; spec §13 has the runtime matrix and package contents.

Host-API-free subpathNon-ECMAScript globals
.none
sdknone
cssnone
authoringTextEncoder, TextDecoder, URL, console
runner-kitnone
preview/captureTextEncoder, TextDecoder, URL
conformanceTextDecoder, console
packTextDecoder, console
storeconsole
previewsetTimeout, clearTimeout, TextDecoder, console

Paths are relative to @arnilo/liveframe; . is the root export. The sdk row includes /sdk/gen and both JSX runtimes; /runner-kit.bundle.js and /validator.bundle.js also need no non-ECMAScript globals. Entries include bundled dependencies: Acorn guards its unused console warning, and the packer's source-map codec optionally uses TextDecoder with a pure JavaScript fallback. Preview timers bound module loading; capture needs the Encoding and URL APIs. Authoring reaches capture. Source, compiled output and browser bundles are checked against this table in CI.

Quickstart

A catalog, its React implementations and a validator are all a surface needs. compileValidator takes the validated catalog, capabilities and manifest for one widget; createRenderer returns the <Surface> that draws a tree it has validated.

import { type Catalog, compileValidator, defineComponent, obj, str, type UiTree } from "@arnilo/liveframe";
import { createRenderer, implement } from "@arnilo/liveframe/react";

const text = defineComponent({
  kind: "text",
  description: "One line of text.",
  props: obj({ value: str({ maxLength: 200 }) }),
  children: "none",
  variants: ["default"],
  defaultVariant: "default",
  slots: ["root"],
  events: {},
  styleProps: [],
  a11y: { role: "paragraph" },
});

const catalog = {
  format: "liveframe-catalog/1",
  catalogId: "acme.ui@1",
  description: "The app's primitives.",
  vocabulary: {
    colourRoles: ["text.primary", "surface.base", "accent.primary"],
    surfaceRoles: ["surface.base"],
    fillableRoles: ["accent.primary"],
    typographyRoles: ["body"],
    space: ["space.1"],
    radius: ["radius.control"],
    size: ["size.glyph"],
    breakpoints: ["bp.sm"],
    tones: { default: "text.primary" },
    surfaceTypography: "body",
  },
  definitions: [text],
} as const satisfies Catalog;

const capabilities = { format: "liveframe-capabilities/1", sources: {}, actions: {} };
const manifest = {
  format: "liveframe-manifest/1",
  id: "hello",
  version: "1.0.0",
  catalogId: catalog.catalogId,
  params: obj({}),
  state: obj({}),
  context: obj({}),
  initialState: {},
  sources: {},
  actions: [],
};

const Text = implement(text, ({ props, slot, style }) => (
  <p className={slot("root")} style={style}>
    {props.value}
  </p>
));
const { Surface } = createRenderer({ catalog, implementations: [Text] });
const validator = compileValidator({ catalog, capabilities, manifest });
const identity = { id: "acme", version: "1.0.0" };

/** Draw a validated tree that the app's backend rendered. */
export function Hello({
  tree,
  onIntent,
}: {
  tree: unknown;
  onIntent: (intent: { type: "setState" | "action" }) => void;
}) {
  return (
    <Surface
      tree={tree}
      validator={validator}
      theme={identity}
      designSystem={identity}
      onIntent={onIntent}
      fallback={null}
    />
  );
}

export const tree: UiTree = {
  format: "liveframe/1",
  catalogId: catalog.catalogId,
  surfaceId: "hello",
  revision: 1,
  root: { id: "root", kind: "text", props: { value: "Hello from Liveframe" } },
};

Widgets are authored separately with the SDK, which exports render() and the JSX runtime and emits the tree Hello receives. The preview guide shows the backend runners that execute widget code, and the package guide shows how a rendered widget becomes an immutable package a host stores and places.

For streaming updates, diffTrees(prev, next) emits an optional liveframe/tree-patch/1 patch on the backend, and the browser host applies it with applyPatch(base, patch) and passes the patched tree to <Surface> (which validates the whole tree on arrival):

import { applyPatch, diffTrees } from "@arnilo/liveframe";

const next = {
  ...tree,
  revision: 2,
  root: { id: "root", kind: "text", props: { value: "Hello again" } },
};
const patch = diffTrees(tree, next);
if (patch.ok) {
  const updated = applyPatch(tree, patch.value);
  if (updated.ok) Hello({ tree: updated.value, onIntent: () => {} });
}

What is in the package

ImportHolds
@arnilo/liveframeDefinition, catalog, theme, design-system, UI-tree and tree-patch formats; validateTreePatch, diffTrees and applyPatch; the validator; the recipe resolver; LiveframeFailure and LiveframeError
@arnilo/liveframe/sdkThe JSX runtime (/sdk/jsx-runtime, /sdk/jsx-dev-runtime), intent helpers and render()
@arnilo/liveframe/sdk/genThe host-side emitters behind liveframe gen: generate(), generateDefinitions() and generateElementsSchema()
@arnilo/liveframe/reactThe renderer: createRenderer(), <Surface> and implement()
@arnilo/liveframe/cssThe scoped CSS projection and the class, style, scope and variable helpers; the host inserts sheets
@arnilo/liveframe/packPackage and scenario formats, structural validators, pack(), verifyPackage(), canonicalJson() and packageHash()
@arnilo/liveframe/storeRecord formats, the Store interface, memoryStore() and loadPlacement()
@arnilo/liveframe/store/fsfileStore(dir), which reads and writes the file system
@arnilo/liveframe/previewThe Runner interface, inProcessRunner() and createPreview()
@arnilo/liveframe/authoringEight typed authoring operations without MCP; the host supplies its runner
@arnilo/liveframe/runner-kitrenderModule() and linkPackage(), the in-sandbox half of a runner
@arnilo/liveframe/runner-kit.bundle.jsThe kit, SDK and validator as one import-free ES module for isolates
@arnilo/liveframe/validator.bundle.jsThe root exports as one import-free ES module for hosts that validate without rendering
@arnilo/liveframe/preview/captureCapture as bytes with a pluggable backend
@arnilo/liveframe/preview/workerworkerRunner(), which needs the Worker global
@arnilo/liveframe/preview/react<Preview>
@arnilo/liveframe/conformanceHost-API-free catalog, design-system and store suites
@arnilo/liveframe/conformance/reactThe renderer suites and conformancePage()
@arnilo/liveframe/schemas/<format>.jsonThe JSON Schema for every format

The spec defines each subpath's contract.

Use it with a coding agent

liveframe mcp is an MCP server over stdio that lets a coding agent read your catalog, write a draft widget and look at its renders. It is authoring only: no tool installs, places or approves a widget, or runs an action.

  1. Install the optional peers: bun add -d @modelcontextprotocol/server, and bunx playwright install chromium if the agent should capture screenshots.
  2. Write a config module that default-exports an AuthoringConfig (your catalog, capabilities, runner and, for captures, a preview(binding) that starts your <Preview> page). examples/demo-host/mcp.config.ts is a working one.
  3. Register it with the agent. For Claude Code, put this in .mcp.json in your app; Claude Desktop and other clients use the same mcpServers shape in their own config file:
{ "mcpServers": { "liveframe": { "command": "bunx", "args": ["liveframe", "mcp", "./mcp.config.ts"] } } }

The client starts the server itself. The MCP guide covers the eight tools, captures and errors.

Guides

Status

Pre-1.0 (0.2.2 is the current release). The public API, the formats and the on-disk fileStore layout are described by the compatibility policy; the release notes list the known limitations of this release.

Development

bun install
bun run check   # build, generated output, typecheck, lint, format, tests

Repository layout, roadmap and plans: roadmap.md, plans/. Contributing with agents: AGENTS.md. Security reports: SECURITY.md.

License

MIT — see LICENSE.

版本与发布记录

@arnilo/liveframe 共发布 16 个版本,首次发布于 2026/10/27;过去 12 个月发布了 16 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.3latest2026/11/043 天前
0.2.3-rc.1next2026/11/043 天前
0.2.22026/11/034 天前
0.2.2-rc.22026/11/034 天前
0.2.2-rc.12026/11/035 天前
0.2.12026/11/017 天前

关于 @arnilo/liveframe 的常见问题

@arnilo/liveframe 是什么?

Runtime-composable UI: primitives, design-system recipes and TSX widgets that change an app's UI without a deployment.

如何安装 @arnilo/liveframe?

在项目目录运行 npm install @arnilo/liveframe,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 liveframe,可以用 npx liveframe 直接运行。

@arnilo/liveframe 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@arnilo/liveframe 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@arnilo/liveframe 可以商用吗?

@arnilo/liveframe 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@arnilo/liveframe 的下载量有多少?

根据 npm 官方下载统计,@arnilo/liveframe 在 2026/10/07 – 2026/11/05 这 30 天内被下载 2,621 次,日均约 87 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@arnilo/liveframe 还在维护吗?

最新版本 0.2.3 发布于 2026/11/04(3 天前);至今共发布 16 个版本,其中过去 12 个月发布了 16 个;首次发布于 2026/10/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。