@adelie/amsp

中文文档
0.6.4发布于 2026/11/05Apache-2.0TypeScriptES Module零依赖近 30 天下载 2728

AMSP (Agent Message Stream Protocol): the wire types of an Adelie agent's API and a zero-dependency client for Node 24 and browsers.

原始使用文档
文档目录3 节
  1. The reader without the client
  2. Documentation
  3. Development

@adelie/amsp

The client of a Adelie agent's API, and the types of AMSP (Agent Message Stream Protocol), the event stream that API serves. No runtime dependencies; runs in Node 24 and in current browsers on fetch, ReadableStream, TextDecoder and AbortController.

A Project owner turns an agent's API on in the Adelie Web App (the agent's API tab) and mints a key there. A program then runs the agent, reads the run as it happens, and continues the conversation by its Session id:

import { AgentClient } from "@adelie/amsp";

const client = new AgentClient({
  baseUrl: "http://localhost:7364/api/amsp/v1",
  agent: "demo/coder", // <projectId>/<agentId>
  apiKey: process.env.PENGUIN_AGENT_KEY,
});

const run = client.run({ input: "Summarize README.md" });
for await (const event of run) {
  if (event.type === "text.delta") process.stdout.write(event.text);
}
const first = await run.result();

const second = await client.ask({
  sessionId: first.sessionId,
  input: "Now list its headings",
  onApproval: () => "allow", // without a callback, approval requests are denied
});
console.log(second.text, second.usage.total);
  • run() starts the run and returns it: iterate it once for the events, await session for the Session id, result() for the outcome, and call abort() to have the server abort it. ask() returns the result alone.
  • result() resolves for every run that reached run.done, whatever its status. A refusal before the stream rejects with AmspHttpError (status, code, message); a stream that ends or breaks before run.done rejects with AmspStreamError; aborting the signal rejects with its reason.
  • onApproval answers each approval.requested, and the client posts the answer; parseArguments reads a tool call's JSON arguments.
  • agent(), session(id), abort(id) and approve(id, toolCallId, decision) call the API's other routes; readSse is the SSE reader, for a program that reads a run's body itself.
  • Every AMSP event type is exported (AmspEvent, RunDone, ToolCallDone, …). Events of a type the client does not know are passed through.

The reader without the client

A program that sends the request itself — its own fetch, its own credentials or URL — reads the body with readSse and folds the events with RunCollector, which AgentClient uses for result():

import { readSse, RunCollector } from "@adelie/amsp";
import type { AmspEvent } from "@adelie/amsp";

const collector = new RunCollector();
for await (const data of readSse(response.body!)) {
  if (data === "[DONE]") break;
  collector.add(JSON.parse(data) as AmspEvent);
}
const result = collector.result(); // throws AmspStreamError when the stream ended before run.done

Documentation

  • Agent API: turning an agent's API on, keys, approval modes, routes, errors, the client in Node and browsers
  • AMSP: the protocol, event by event

Development

pnpm --filter @adelie/amsp build       # tsup → dist/ (exports point at dist)
pnpm --filter @adelie/amsp typecheck
pnpm --filter @adelie/amsp test

Part of Adelie · Apache-2.0

版本与发布记录

@adelie/amsp 共发布 18 个版本,首次发布于 2026/10/17;过去 12 个月发布了 18 个版本。

版本发布日期距今
0.6.4latest2026/11/052 天前
0.6.32026/11/043 天前
0.6.22026/11/025 天前
0.6.12026/11/016 天前
0.6.02026/10/308 天前
0.5.102026/10/309 天前

关于 @adelie/amsp 的常见问题

@adelie/amsp 是什么?

AMSP (Agent Message Stream Protocol): the wire types of an Adelie agent's API and a zero-dependency client for Node 24 and browsers.

如何安装 @adelie/amsp?

在项目目录运行 npm install @adelie/amsp,或使用 pnpm add / yarn add / bun add。

@adelie/amsp 支持 TypeScript 吗?

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

@adelie/amsp 支持 ESM 还是 CommonJS?

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

@adelie/amsp 需要什么版本的 Node.js?

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

@adelie/amsp 可以商用吗?

@adelie/amsp 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@adelie/amsp 的下载量有多少?

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

@adelie/amsp 还在维护吗?

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