@ag-ui/a2ui-middleware

中文文档
0.0.14发布于 2026/10/31MITTypeScriptESM + CJS构建来源已验证近 30 天下载 172.3万

Middleware for streaming A2UI surfaces and generation recovery activities.

原始使用文档
文档目录3 节
  1. Optional sibling-call disambiguation
  2. Ancestry limitations
  3. Automatic tool completion

@ag-ui/a2ui-middleware

Middleware for streaming A2UI surfaces and generation recovery activities.

Optional sibling-call disambiguation

Existing consumers need no configuration changes. By default, the middleware preserves nested render ownership for all generation-wrapper names, including custom names: retries and final success or failure replace one wrapper activity.

Some adapters give sibling tool calls distinct parentMessageId values. Message IDs identify assistant messages, not parent tool calls, so these calls cannot be distinguished reliably from nested renders. If your adapter does this, you can opt into stricter association by listing your generation wrappers:

import { A2UIMiddleware } from "@ag-ui/a2ui-middleware";

const middleware = new A2UIMiddleware({
  a2uiGenerationToolNames: ["generate_a2ui", "create_dashboard"],
});

Include every outer generation wrapper used by your agent, including custom adapter toolName values. These are not the inner render tools listed in a2uiToolNames. With an explicit list, calls with distinct, nonempty message IDs remain independent unless the preceding tool is a listed wrapper. This lets a sibling dashboard render and a flight tool's result retain separate activities. Use a2uiGenerationToolNames: [] if your agent has no generation wrappers.

Omitting the option retains the legacy heuristic; an empty list opts into stricter association with no known wrappers. When opting in, an omitted wrapper name can cause its retries to get separate activities, leaving a failed attempt alongside a successful render. There is no built-in wrapper list in this opt-in mode.

Ancestry limitations

  • Calls sharing a nonempty parent message ID remain siblings in either mode.
  • Without the option, distinct-ID siblings can still be mistaken for nested calls and suppress valid output. This is the existing default behavior.
  • Even with the option, distinct-ID siblings involving a listed wrapper such as generate_a2ui and a direct render_a2ui can still be combined incorrectly.
  • Missing or empty message IDs retain heuristic nesting in either mode. Concurrent generation wrappers can also be associated with the most recent candidate rather than the actual parent.

Unambiguous automatic association requires adapters to provide parent-tool-call ancestry or consistent sibling message identities. Neither tool arguments nor TOOL_CALL_END (which ends argument streaming) reliably proves nesting.

Automatic tool completion

When this middleware supplies a result for a render call made in the current run, it continues the downstream agent with that result and the original call ID. UI activity and results stay inside one public run. Other unresolved frontend calls, interruptions, cancellation, and errors stop continuation. New render chains are limited to ten rounds; exceeding that limit fails the stream. Historical calls are not executed again.

Failed middleware results carry metadata["ag-ui:tool-result"].error. The string marker (including an empty string) preserves error status through client history without changing the result payload. Claude SDK recovery reads this marker when no explicit tool-message error is present.

版本与发布记录

@ag-ui/a2ui-middleware 共发布 16 个版本,首次发布于 2026/01/29;过去 12 个月发布了 16 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.0.14latest2026/10/317 天前
0.0.132026/10/1919 天前
0.0.122026/10/061 个月前
0.0.112026/09/301 个月前
0.0.102026/06/194 个月前
0.0.10-alpha.1alpha2026/06/184 个月前

关于 @ag-ui/a2ui-middleware 的常见问题

@ag-ui/a2ui-middleware 是什么?

Middleware for streaming A2UI surfaces and generation recovery activities.

如何安装 @ag-ui/a2ui-middleware?

在项目目录运行 npm install @ag-ui/a2ui-middleware,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:rxjs(7.8.1)、@ag-ui/client(>=1.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@ag-ui/a2ui-middleware 支持 TypeScript 吗?

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

@ag-ui/a2ui-middleware 支持 ESM 还是 CommonJS?

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

@ag-ui/a2ui-middleware 可以商用吗?

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

@ag-ui/a2ui-middleware 的下载量有多少?

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

@ag-ui/a2ui-middleware 还在维护吗?

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