@ai-matrx/applets

中文文档
0.19.15发布于 2026/10/30MITTypeScriptESM + CJS近 30 天下载 4.8万

AI Matrx Applets: the contract types and AppletHost doorway, an in-memory host for tests and development, the React frame hooks Applet code imports (useRows, useJob, useValue, useAction, Pages, Applet, Kind), and mountApplet, which compiles a stored multi

原始使用文档

@ai-matrx/applets

Applets are custom interfaces an agent builds on a person's own data and the platform's features. This package is the doorway between an Applet and whatever hosts it.

EntryWhat it is
@ai-matrx/appletsThe contract types and the AppletHost interface. No React.
@ai-matrx/applets/hostcreateMemoryHost(spec) — an in-memory host for tests and development.
@ai-matrx/applets/reactWhat Applet code imports: useRows, useJob, useConversation, WritingBox, useValue, useAction, Pages, …
@ai-matrx/applets/platformcreatePlatformHost(opts) — the real host over the live platform; every client injected.
@ai-matrx/applets/framemountApplet(record, host, scope) — compile a stored Applet and render it.
import { createMemoryHost } from "@ai-matrx/applets/host";
import { mountApplet } from "@ai-matrx/applets/frame";

const host = createMemoryHost({ record, tables: { posts: { columns, rows } } });
const mounted = mountApplet(record, host, { entries: [], shadowDangerousGlobals: true });
if (mounted.ok) root.render(<mounted.Component />);

Inside an Applet:

import { useRows, useJob, JobOutput, Pages } from "@ai-matrx/applets/react";

export default function Posts() {
  const { rows, update, error } = useRows("posts");          // optimistic, versioned writes
  const draft = useJob("draft");                              // a declared job, by alias
  return (
    <>
      <button onClick={() => draft.run({ topic: "launch" })}>Draft</button>
      <JobOutput job={draft} label="Drafting" />               {/* the run streams here */}
      <ul>{rows.map((r) => <li key={r._id}>{String(r.title)}</li>)}</ul>
    </>
  );
}

A job's run always renders through <JobOutput job={…} /> — never job.text in a paragraph, never a "busy" label while it works, never <Kind> on job.result at the end. The host renders the run through its one live-run pipeline (streamed text, partial kinds, tool steps, loading and errors, the final kind) via renderRun. Where there is no room to stream inline, use <JobOutput job={…} mode="window" /> (each run opens once in the host's floating run window) or call job.open() from a button. Hosts supply renderRun / openRun to mountApplet / AppletFrame.

A heading around a run never claims success before the run has one. A title like "Content ready for publication" above <JobOutput> shows only when job.status === "done"; while it works or after it fails (job.status === "error"), say what is happening or nothing. job.error.message is always a plain sentence for the visitor (forVisitor); the server's own words go to the host's error inspector, never to the page.

A box a person writes in is <WritingBox value={text} onValueChange={setText} /> — never Textarea. It renders the host's writing box (renderWritingBox), which carries the platform's microphone (dictation) and read-aloud; <ConversationComposer> writes through it too.

A conversation is useConversation(alias) — a multi-turn chat with one declared job. The first send(text, variables?) starts it, every later send continues the same conversation, stop() stops the turn in flight. Render it with <ConversationOutput conversation={…} />: each answer streams through the host's same live-run pipeline, never hand-rendered.

const chat = useConversation("assistant");
<ConversationOutput conversation={chat} label="Answering" />
<button onClick={() => chat.send(draftText)}>Send</button>

Hooks never throw: each answers a status and an error carrying the system's own sentence. On useRows / useRow, error means the data could not be read; a save the store refused is writeError (its sentence) — show it beside the control that saved, never in place of the list. React and React DOM are peer dependencies. The contract this implements is common-docs/projects/applets/CONTRACTS.md (v2).

版本与发布记录

@ai-matrx/applets 共发布 129 个版本,首次发布于 2026/10/07;过去 12 个月发布了 129 个版本。

版本发布日期距今
0.19.15latest2026/10/306 天前
0.19.142026/10/288 天前
0.19.132026/10/2413 天前
0.19.122026/10/2313 天前
0.19.112026/10/2314 天前
0.19.102026/10/2314 天前

关于 @ai-matrx/applets 的常见问题

@ai-matrx/applets 是什么?

AI Matrx Applets: the contract types and AppletHost doorway, an in-memory host for tests and development, the React frame hooks Applet code imports (useRows, useJob, useValue, useAction, Pages, Applet, Kind), and mountApplet, which compiles a stored multi

如何安装 @ai-matrx/applets?

在项目目录运行 npm install @ai-matrx/applets,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18.0.0)、react-dom(>=18.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@ai-matrx/applets 支持 TypeScript 吗?

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

@ai-matrx/applets 支持 ESM 还是 CommonJS?

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

@ai-matrx/applets 需要什么版本的 Node.js?

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

@ai-matrx/applets 可以商用吗?

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

@ai-matrx/applets 的下载量有多少?

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

@ai-matrx/applets 还在维护吗?

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