# @ai-matrx/code-runtime 中文文档

规范地址：https://npmcn.com/package/%40ai-matrx/code-runtime/

版本：0\.4\.100
npm 元数据更新时间：2026-10-28T12:55:57.623Z
中文译文更新时间：2026-11-05T18:52:44.848Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40ai-matrx/code-runtime
原文对照：https://npmcn.com/package/%40ai-matrx/code-runtime/?lang=original
项目主页：https://github.com/AI-Matrix-Engine/aidream/tree/main/apps/shared/code-runtime#readme
源码仓库：https://github.com/AI-Matrix-Engine/aidream

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：1.6 MB，47 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=20
- 运行依赖：6 个
- peer 依赖：react \>=18\.0\.0，react-dom \>=18\.0\.0
- 首次发布：2026-10-06T16:25:20.924Z
- 最新版本发布：2026-10-28T12:55:57.278Z
- 近 30 天下载量：54347（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：106（近 12 个月 106 个）

## 中文简介

AI Matrx in-frame 代码运行时间: 将存储的多文件 TSX( applets, kind 组件, 工具并放出渲染器, 代码块) 编译到一个有文件记录的导入范围, 并指定任何未解决事项的站点, 一个源口列表, 和一个编译

## 安装

```sh
npm install @ai-matrx/code-runtime
```

也可以使用：`pnpm add @ai-matrx/code-runtime`、`yarn add @ai-matrx/code-runtime`、`bun add @ai-matrx/code-runtime`

## README

# @ai- matrx/ 代码运行时间

将存储的 TSX —— 一个或多个文件—— 汇编到反应组件中, 对照一个文件导入 (a) 范围,如果范围无法提供,则有明显的、据报的备用设施.

```ts
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);
```

-   **范围**数字 : `listScopeEntries()` 是整个注册。 软件包拥有的条目在任何地方都可行 (Next.js, Vite) (英语). 主机拥有的(Markdown、kin-kit、复制按钮、Applet部件、重型) 图书馆)提供一次: `provideScopeModules({ "@/components/MarkdownStream": () => mod })`。 。 。 . Async 条目( 重写) 需要 `await prepareScope(spec)` 或者说 `compileAsync`备案图书馆 a 机体进口总是进入其范围;等待 `prepareSource(code)` 编号 : `prepareGraph(graph)` (或民意调查) `pendingEntriesFor(code)`在同步编译之前,它被装入.
-   **沙盒分割**: 父运行 `@ai-matrx/code-runtime/transform` (单位:千美元)`transformFiles`和 张贴 JSON 图; 帧运行 `@ai-matrx/code-runtime/execute` (单位:千美元)`executeGraph`没有巴贝尔.
-   **门**数字 : `@ai-matrx/code-runtime/gate` 是纯的(服务器,写路径)。 将船只列为 `@ai-matrx/code-runtime/gate-lists.json`。 。 。 .
-   **类型**: 注射 `kindComponentCompiler()` 输入 `@ai-matrx/content-ir/react`是因为 `createDbKindComponentCache({ compile })`。 。 。 .

不是安全边界:危险-全球的阴影只是赤裸的识别器。 隔离是 沙盒的框架.

## 常见问题

### @ai-matrx/code-runtime 是什么？

AI Matrx in-frame 代码运行时间: 将存储的多文件 TSX\( applets, kind 组件, 工具并放出渲染器, 代码块\) 编译到一个有文件记录的导入范围, 并指定任何未解决事项的站点, 一个源口列表, 和一个编译

### 如何安装 @ai-matrx/code-runtime？

在项目目录运行 npm install @ai-matrx/code-runtime，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：react（\>=18\.0\.0）、react-dom（\>=18\.0\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @ai-matrx/code-runtime 支持 TypeScript 吗？

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

### @ai-matrx/code-runtime 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @ai-matrx/code-runtime 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=20。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @ai-matrx/code-runtime 可以商用吗？

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

### @ai-matrx/code-runtime 的下载量有多少？

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

### @ai-matrx/code-runtime 还在维护吗？

最新版本 0\.4\.100 发布于 2026/10/28（8 天前）；至今共发布 106 个版本，其中过去 12 个月发布了 106 个；首次发布于 2026/10/07。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

