@absolutejs/a2a

中文文档
0.3.6发布于 2026/07/27MITTypeScriptES Module近 30 天下载 1832

Production A2A Protocol 1.0 client and server with streaming, durable tasks, push configuration, and Agency enforcement.

原始使用文档

@absolutejs/a2a

An A2A Protocol 1.0 JSON-RPC client and server for AbsoluteJS. It implements Agent Card discovery, messages, streaming, task subscriptions, filtered and paginated task listing, push notification configuration, authenticated extended cards, explicit version and extension negotiation, and AbsoluteJS Agency enforcement.

Agency is a required host peer (>=0.7.1 <0.8.0), not a bundled dependency. The host therefore owns one action ledger and one contract version across A2A and every other agent transport. This package tests against exactly 0.7.1; support for a new Agency minor requires an explicit compatibility release.

Protocol reference: https://a2a-protocol.org/latest/specification/

The protocol version is intentionally pinned. A2A 1.0 changed its JSON-RPC method names and Agent Card shape from 0.3; this package does not silently downgrade and lose security or behavior.

Discovery and RPC clients require HTTPS outside localhost, reject credentials in URLs and redirects, enforce timeouts and response-size limits, and validate response media types. Servers authenticate before parsing bodies, cap request sizes, bind every task and push configuration to the authenticated caller, and refuse to advertise optional capabilities that are not configured.

import { createA2aHandler, createPostgresA2aTaskStore } from "@absolutejs/a2a";

const a2a = createA2aHandler({
  path: "/a2a",
  agentCard: {
    name: "Support Agent",
    description: "Resolves customer support cases.",
    version: "1.0.0",
    supportedInterfaces: [
      {
        protocolBinding: "JSONRPC",
        protocolVersion: "1.0",
        url: "https://example.com/a2a",
      },
    ],
    capabilities: {},
    defaultInputModes: ["text/plain"],
    defaultOutputModes: ["text/plain"],
    skills: [],
  },
  authorize: verifyA2aBearer,
  taskStore: createPostgresA2aTaskStore({ client }),
  agency: { agency },
  sendMessage: async ({ message }) => ({
    task: await startSupportTask(message),
  }),
});

The same handler supports the A2A 1.0 optional methods when their advertised capabilities are configured:

import { createMemoryA2aPushNotificationConfigStore } from "@absolutejs/a2a";

const a2a = createA2aHandler({
  // ...the required configuration above
  pushNotifications: {
    store: createMemoryA2aPushNotificationConfigStore(),
  },
  extendedAgentCard: authenticatedCard,
  sendStreamingMessage: async function* (request, context) {
    yield* runAgentStream(request, context);
  },
  subscribeToTask: async function* (task, context) {
    yield* subscribeToAgentTask(task, context);
  },
});

For production push configuration storage, implement A2aPushNotificationConfigStore with the same authorization-key isolation as the included memory store. Webhook delivery should independently resolve DNS, block private and link-local destinations, avoid redirects, authenticate each request, and retry idempotently.

When policy requires approval, the server returns an A2A extension error with the Agency actionId. After approval, resend the same request with that ID at metadata[ABSOLUTE_AGENCY_EXTENSION].actionId; Agency re-evaluates policy, issues a single-use lease, and records the execution receipt.

Task ownership is always keyed by the authorization result. A caller cannot probe, list, cancel, or overwrite another caller's task, and PostgreSQL updates protect terminal task states atomically.

Hosts that operate multi-agent fleets can attach trusted labels in the authorization result and use the separate operator view. Labels are never read from A2A request data. Operator results omit task artifacts and history unless explicitly requested, so a status console does not accidentally retrieve task payloads.

const taskStore = createPostgresA2aTaskStore({ client });

const authorized = {
  actor,
  authorizationKey,
  caller,
  ok: true as const,
  taskLabels: { clientId: actor.agentId, tenantId: tenant.id },
};

const posture = await taskStore.listForOperator({
  labels: { tenantId: tenant.id },
  pageSize: 25,
});

版本与发布记录

@absolutejs/a2a 共发布 13 个版本,首次发布于 2026/07/16;过去 12 个月发布了 13 个版本。

版本发布日期距今
0.3.6latest2026/07/273 个月前
0.3.52026/07/253 个月前
0.3.42026/07/243 个月前
0.3.32026/07/243 个月前
0.3.22026/07/233 个月前
0.3.12026/07/233 个月前

关于 @absolutejs/a2a 的常见问题

@absolutejs/a2a 是什么?

Production A2A Protocol 1.0 client and server with streaming, durable tasks, push configuration, and Agency enforcement.

如何安装 @absolutejs/a2a?

在项目目录运行 npm install @absolutejs/a2a,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@absolutejs/agency(>=0.7.3 <0.8.0)、drizzle-orm(>=1.0.0-rc.4 <2)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@absolutejs/a2a 支持 TypeScript 吗?

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

@absolutejs/a2a 支持 ESM 还是 CommonJS?

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

@absolutejs/a2a 可以商用吗?

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

@absolutejs/a2a 的下载量有多少?

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

@absolutejs/a2a 还在维护吗?

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