@ai-matrx/content-ir

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

The AI Matrx Content IR package: the pure parser, normalized envelope, session, schema conversion and validation kernel, plus the React render layer (kind routing, component resolver, directives, kind kit) as separate sections.

原始使用文档
文档目录4 节
  1. Entry points
  2. Reading an envelope: kindState , never kind alone
  3. /source streaming mode: what "settled" promises
  4. Release gate

@ai-matrx/content-ir

The framework-independent Content IR kernel used by AI Matrx applications. It parses streamed or complete structured content into canonical envelopes, manages incremental parse sessions, converts kind schemas, and performs structural validation.

pnpm add @ai-matrx/content-ir

Entry points

The root export is the full surface and always will be. Since 0.10.0 each internal area is also addressable on its own — prefer these, so a consumer that only reads wire contracts never pulls the parser (or ajv) into its graph.

ImportWhat it holds
@ai-matrx/content-ireverything below
@ai-matrx/content-ir/coreIR types + tree, JSON tokenizer, kind parser, snapshots, normalize, fingerprint, discriminator, envelope read/value/cache, region, schema structure
@ai-matrx/content-ir/sessionParseSession and the one-writer-per-identity registry
@ai-matrx/content-ir/registrykind registry types, storage transform, the dual gate, createKindValidator over a host SchemaSourcePort
@ai-matrx/content-ir/convertkind ⇄ JSON Schema, the OpenAI structured-output converter
@ai-matrx/content-ir/wirepartial-kind events, runtime wrapper readers, emit payload
@ai-matrx/content-ir/directivesKind Directives: slug grammar, the ONE decoder
@ai-matrx/content-ir/sourceoffset-preserving source tokenizer, splice save + anchor-mapping change set, the single-dollar math rule
import { createKindStreamParser, envelopeFromCompleteValue } from "@ai-matrx/content-ir/core";
import { validateStructuralLeg } from "@ai-matrx/content-ir/registry";
import {
  readPartialKindEvent,
  makePartialKindStalenessGate,
  rehydrateNodeOutcome,
  rehydrateRunResult,
  withRootKind,
} from "@ai-matrx/content-ir/wire";

Reading an envelope: kindState, never kind alone

root.kind is preserved when a payload fails its schema — a broken flashcard_set stays a flashcard_set so you can say what broke. root.status reports only that parsing finished. The validity signal is root.kindState:

  • "resolved" — the only state a typed consumer may act on.
  • "unverified" — the kind has no registered schema, so nothing was ever checked; it still routes to its component.
  • "raw" / "pending_*" / "speculative" — do not consume as typed data.

The package has no browser, React runtime, application store, database client, routing, or renderer dependency. ajv is its only runtime dependency. Host-specific registry fetching, component compilation, rendering, and error capture remain adapters around this kernel.

/source streaming mode: what "settled" promises

tokenizeSource(text) reads stored text; tokenizeSource(prefix, { streaming: true }) reads a message still arriving. In streaming mode anything the next bytes could still change is held back as plain prose (an open last line, an unclosed code span, a $$ that can still pair, a footnote whose continuation is undecided, lines a box-drawing tree still forming below may claim as its root label, a paragraph cut short by a block that may still dissolve, …), so an island reported complete is the island the finished text has — with ONE documented exception:

  • A late orphan reasoning closer. Models do emit closer-only reasoning (the <thinking> opener lost upstream). When a </thinking> / </think> / </reasoning> arrives with no opener, the one-shot reading folds everything before it into a thinking region — retroactively. No streaming reader can know that in advance short of holding ALL prose provisional until the stream ends, which costs more than it saves (chair ruling, 2026-09-26; common-docs projects/rich-content-unification/REGISTER.md, RC-B3 rulings).

Consumer contract: when a stream completes, re-read the finished text in one-shot mode (tokenizeSource(text), no streaming) and show THAT — the final screen always equals the one-shot result, which is also what a reload shows. Stored text never goes through streaming mode, so none of this can change a stored byte. (matrx-frontend's chat renderer does the same for its own live accumulator: components/mardown-display/chat-markdown/settle-stream-blocks.ts.)

Release gate

pnpm --filter @ai-matrx/content-ir typecheck
pnpm --filter @ai-matrx/content-ir test
pnpm --filter @ai-matrx/content-ir check:package

The gate runs the parser's shared fixtures and parity vectors, validates the packed declarations and exports, installs the tarball in an empty project, and imports the public API.

版本与发布记录

@ai-matrx/content-ir 共发布 132 个版本,首次发布于 2026/08/23;过去 12 个月发布了 132 个版本。

版本发布日期距今
0.24.50latest2026/10/306 天前
0.24.492026/10/288 天前
0.24.482026/10/279 天前
0.24.472026/10/2610 天前
0.24.462026/10/2511 天前
0.24.452026/10/2511 天前

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

@ai-matrx/content-ir 是什么?

The AI Matrx Content IR package: the pure parser, normalized envelope, session, schema conversion and validation kernel, plus the React render layer (kind routing, component resolver, directives, kind kit) as separate sections.

如何安装 @ai-matrx/content-ir?

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

@ai-matrx/content-ir 支持 TypeScript 吗?

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

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

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

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

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

@ai-matrx/content-ir 可以商用吗?

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

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

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

@ai-matrx/content-ir 还在维护吗?

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