@ai-matrx/alchemy

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

Matrx Alchemy: the complete Matrx copy, prepare-for-AI, and export experience, with framework-neutral core, React menu, glyph and styles; Declare (what a screen holds: types, registry, validation, JSON schema) and the one surface sync; Actions (the one ac

原始使用文档
文档目录6 节
  1. One menu, ready to use
  2. Portal and Tap Target
  3. Extend the shared menu
  4. Table exports and live references
  5. Integrate Matrx services once
  6. Framework-neutral use

@ai-matrx/alchemy

Alchemy is Matrx’s content-to-AI toolkit. Alchemy Menu is its small, reusable copy, preparation and export control. This distribution ships the shared core, React controls, CSS and SVG; it contains no parallel implementation. It sits below @ai-matrx/agents and never depends on it.

One menu, ready to use

import { AlchemyMenu } from "@ai-matrx/alchemy/react";
import "@ai-matrx/alchemy/styles.css";

export function TaskActions({ task }: { task: { id: string; title: string; description: string } }) {
  return <AlchemyMenu
    sourceId={`task:${task.id}`}
    label={task.title}
    human={() => task.description}
    json={() => task}
    agent={() => ({
      kind: "task",
      location: "Task detail",
      description: "Current task, including unsaved changes",
      data: task,
    })}
  />;
}

The transparent icon opens ordinary copy, Markdown, formatted HTML with plain-text fallback, JSON, direct AI context, preparation, and downloads. No chevron, icon library or Tailwind build is required. Semantic HSL tokens inherit the host’s Matrx theme; neutral defaults work without one. Set sourceId from the record identity when a mounted control can switch records. Lazy getters run when content is captured.

Preparation supports editable drafts, detail presets, structural reductions, omissions and undo. Supplying table rows adds relevant spreadsheet formats; registered exporters and page actions retain the same captured-source boundary. An absent AI provider leaves manual preparation available without showing dead AI controls.

Portal and Tap Target

Portal is the default mark in every Matrx host. Default glass/transparent controls use the actual Tap Target primitive with sidebar-parity 18px artwork, 1.75 stroke and shell icon colors in a 32px desktop target; coarse pointers retain 44px. Use triggerVariant="glass" in headers and triggerVariant="transparent" for content actions. triggerVariant="outline" uses the canonical outlined Button for dense toolbars (28px target and 16px artwork, matching the Data toolbar). AlchemyMenu sizes xs and toolbar select compact 28px targets with 14px artwork for glass/transparent controls. icon="copy-transform" is an optional package variant; both marks ship as SVG assets. Future host marks extend this typed icon set rather than replacing the trigger or adding page CSS.

import { ContentTransferMenu } from "@ai-matrx/alchemy/react";

<ContentTransferMenu source={{ kind: "markdown", text: content }} />
<ContentTransferMenu source={{ kind: "text", text: title }} triggerVariant="glass" />
// Inside a mounted ContentTransferSurfaceProvider, no source prop is needed:
<ContentTransferMenu />

Even a plain source has format copy/download, a source-labelled AI context envelope, manual editing, detail/character limits, and undo. The authenticated host adds six AI preparation recipes and the available Matrx destinations. Table sources add selection, filtering, sorting, column choice, row limits, CSV/TSV and Excel. A manually edited draft is the content sent to destinations; actions incompatible with its new shape disappear.

Extend the shared menu

The Copy/Download selector uses one format palette. Additional formats use the same tiles; quick copy, preparation, alternate context, and page operations use shared groups. Supply capabilities and descriptors rather than rendering another menu.

  • Use human, json, and agent getters for different representations of the same content.
  • Use export.sheetRows and export.sheetColumns for a table; spreadsheet formats become available automatically.
  • Use export.items[].build for a custom file's bytes, MIME type, extension, and optional filename. It appears in Download. An onSelect callback takes precedence over build and remains a page action.
  • Use aiVariants for alternate sources, aiCustom for source settings, and groomer for per-section detail. They enter the same preparation workspace.
  • Use the lower-level ContentTransferMenu and its capability provider for format adapters and projected page actions. sourceFormats={false} suppresses source formats in a file/action-only control; an action's placement: "download" places a genuine download in the palette.

Labels and hints wrap within the shared geometry. Preserve stable IDs, eligibility checks, capture boundaries, and honest outcomes. Do not add per-page Copy/Download lists, bypass the shared transport, or restyle the menu for a particular integration.

Table exports and live references

Register tableDataFormat for flat JSON keyed by display labels and tableSchemaFormat for source identity, projected schema and rows. Ordinary JSON retains machine keys; duplicate display labels are disambiguated without dropping values. Both adapters read the current projected draft, including filtering, sorting and visible columns. The readable format also opts Email JSON into that representation.

Supply table.availableScopes, table.initialScope and optional table.scopeLabels with loaders that honestly capture each scope. The preparation workspace retains drafts per scope. Provide references with explicit registered entity identities and a provider reference port that validates and builds the canonical envelope. These are live saved references, independent of content filters and draft edits. referenceActions can open the existing advanced picker. Never infer an entity from a title.

A provider email port enables CSV, JSON and Markdown email actions. The package shows the exact sealed file and adjustments before explicit Send; the host delivers the same filename, MIME and bytes to the authenticated account. Share/access controls stay separate. Standard table copy configuration also accepts references, rowReferences and triggerVariant.

Integrate Matrx services once

The Matrx service adapter lives in @ai-matrx/agents, which sits above Alchemy. Import MatrxContentTransferProvider from @ai-matrx/agents/content-transfer/react, and createMatrxTransferPorts(bindings) / createMatrxTransferActions(ports) from @ai-matrx/agents/content-transfer. The provider accepts the canonical transport, authenticated database read port, current organization getter and source application, and supplies the declared durable AI preparation job to descendant Alchemy menus. Mount it at an identity boundary so changing user or organization cannot reuse another identity’s prepared run. Bind existing Notes, Documents, Workbooks, task, attachment, Code and chat openers once and register the returned actions through the provider's capabilities.actions; menus inherit Save to Matrx and Continue with AI groups.

Openers report that an editor was opened, not that the item was saved. Save-and-attach preserves the created note if the destination picker fails. New-chat/window handoffs attach captured content as a text resource, leave the human composer empty and never auto-run. Connected tools are selected through the existing assistant Chat Options picker; this is not an automatic MCP invocation.

For an exact mounted declared surface, use createSurfaceTransferHandle from /core and ContentTransferSurfaceProvider from /react. Bind its scope getter and mounted predicate to that instance. Never look up a same-named surface globally. Standard Matrx tables include shared row and toolbar controls by default; copy={false} opts out. Custom tables can use the lower-level ContentTransferMenu source/table contract.

Framework-neutral use

import { capture, createDraft, serialize } from "@ai-matrx/alchemy/core";

const { snapshot } = await capture(
  { kind: "text", text: "Hello" },
  new AbortController().signal,
);
const artifact = serialize(createDraft(snapshot), "plain");
EntryExports
/core (also package root)Capture, projection, preparation, serializers, artifacts and transport.
/reactAlchemyMenu, lower-level ContentTransferMenu, surface/provider bindings and React glyph.
/operate write doorcreateWriteDoor({ ports, declarations }): every write to a declared target (person, menu, destination, agent, applet, automation) returns a Receipt — applied (maybe with a warning), queued or refused with a sentence and a remedy. Bind it as the door host port and register a headless handler per destination.
/portsHost port types only (AlchemyHostPorts, KindValidatorPort, DiagnosticsPort, IdentityPort, PersistencePort). A host binds them once at its boundary; an unbound optional port means that capability is absent, never stubbed.
/actionsThe one action registry (menu Actions run through runAction; programmatic ones by id through invokeAction + invocableAction), plus surface Actions: ActionDeclaration/ActionInfo, projections from write targets, client tools and ui.ui_surface_action rows, resolveActionChain (child wins by name) and the one runner runSurfaceAction (server, mandate, navigate, page).
/surfaceThe one SurfacePort runtime: readSurfaceChain(client, surfaceName, { maxDepth?, organizationIds? }) reads a surface's Actions from ui.ui_surface* through the viewer's client (organization extensions apply only to their members), and createSurfacePort(opts) mounts it, holds its values and runs its Actions (page Actions travel on the "actions" stream and are answered with completeAction).
/checksThe one surface sync. It writes only declared_by: "code" rows and never reports a database-declared row as stale or orphaned.
/styles.cssSelf-contained menu and workspace styling.
/alchemy.svg, /portal.svg, /copy-transform.svgPackaged icon assets; Portal is default.

The registry installation canary requires the sibling kit and design-system releases first, and fails if installing Alchemy pulls in @ai-matrx/agents. Stylesheets import the canonical design-system styling; SVG assets are copied from their one source at build time.

版本与发布记录

@ai-matrx/alchemy 共发布 238 个版本,首次发布于 2026/09/13;过去 12 个月发布了 238 个版本。

版本发布日期距今
0.23.96latest2026/10/306 天前
0.23.952026/10/297 天前
0.23.942026/10/298 天前
0.23.932026/10/289 天前
0.23.922026/10/2610 天前
0.23.912026/10/2512 天前

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

@ai-matrx/alchemy 是什么?

Matrx Alchemy: the complete Matrx copy, prepare-for-AI, and export experience, with framework-neutral core, React menu, glyph and styles; Declare (what a screen holds: types, registry, validation, JSON schema) and the one surface sync; Actions (the one ac

如何安装 @ai-matrx/alchemy?

在项目目录运行 npm install @ai-matrx/alchemy,或使用 pnpm add / yarn add / bun add。

@ai-matrx/alchemy 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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

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

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