@aparte/plugin-artifacts

中文文档
0.32.1发布于 2026/11/02MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 5115

Artifacts for aparté — a create_artifact tool the model calls, a rich Code/Preview card that renders its result, and the tag grammar for a model that writes one in its prose.

原始使用文档
文档目录3 节
  1. Options
  2. What the card does
  3. Two ways in, one card

@aparte/plugin-artifacts

Artifacts for aparté: a document the model produces — a page, a component, a script, an SVG, a Markdown note, a spreadsheet — shown as a Code/Preview card in the transcript. An artifact is a convention an app teaches its model, not something a model does by nature, so the whole convention lives here: the create_artifact tool the model calls, the card that renders its result, and the <artifact> tag grammar for a model that writes one in its prose.

npm install @aparte/plugin-artifacts @aparte/core
import { setupArtifacts } from '@aparte/plugin-artifacts';

setupArtifacts(); // registers the tool, its renderer, the grammar and the segment renderer

@aparte/core is the only peer dependency.

Options

setupArtifacts({
  name: 'create_artifact',        // the tool's name as the model sees it
  systemPrompt: false,            // your own string, or false to send none
  tag: 'artifact',                // the tag recognised in the prose; false for none
  preview: true,                  // false: no Preview tab; a function: your own srcdoc builder
  onBinary: async (artifact) => { // pdf / xlsx / docx: produce the file from the model's source
    const { buffer, filename } = await runInYourSandbox(artifact.content);
    return { buffer, filename, mime: artifact.mimeType };
  },
});

A second argument scopes everything to one AparteConfig instead of the global one. The call returns a function that unregisters all four.

What the card does

  • Opens on Code, highlighted through whatever highlighter core was given.
  • Preview — for html, react, svg, js and css — is mounted only when the reader presses the tab: a previewable artifact is model-authored code, and mounting it unasked executes it. The frame is sandbox="allow-scripts" with a CSP that lets nothing out.
  • Copy and Download on every text artifact; a binary one (pdf, xlsx, docx) downloads only once your onBinary produced it — without one there is no button, because the library holds no bytes.
  • Only a call that ran shows the card. One waiting for a person's approval says so; one that was refused, stopped or failed shows its title and "Not created", with nothing to copy or download.

Two ways in, one card

A model with tools calls create_artifact with { mimeType, title, content }; the handler returns the document as the tool's structured result and the card is drawn from it. A model without tools writes <artifact type="text/html" title="…">…</artifact> in its reply; core's parser — taught the grammar by this plugin through registerStreamBlock — streams it into an artifact segment the same card renders.

MIME types follow the standard, plus Anthropic's application/vnd.ant.* namespace for framework kinds (application/vnd.ant.react). deriveArtifactKind(mimeType) gives the short kind the card switches on.

版本与发布记录

@aparte/plugin-artifacts 共发布 46 个版本,首次发布于 2026/08/30;过去 12 个月发布了 46 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.32.1latest2026/11/024 天前
0.32.02026/11/024 天前
0.31.02026/11/024 天前
0.30.12026/11/014 天前
0.30.02026/11/014 天前
0.29.42026/11/015 天前

其他发布通道:alpha → 0.17.0。

关于 @aparte/plugin-artifacts 的常见问题

@aparte/plugin-artifacts 是什么?

Artifacts for aparté — a create_artifact tool the model calls, a rich Code/Preview card that renders its result, and the tag grammar for a model that writes one in its prose.

如何安装 @aparte/plugin-artifacts?

在项目目录运行 npm install @aparte/plugin-artifacts,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@aparte/core(>=0.32.1 <1.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aparte/plugin-artifacts 支持 TypeScript 吗?

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

@aparte/plugin-artifacts 支持 ESM 还是 CommonJS?

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

@aparte/plugin-artifacts 需要什么版本的 Node.js?

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

@aparte/plugin-artifacts 可以商用吗?

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

@aparte/plugin-artifacts 的下载量有多少?

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

@aparte/plugin-artifacts 还在维护吗?

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