@animalabs/portal-protocol

中文文档
0.4.0发布于 2026/09/14TypeScriptES Module零依赖构建来源已验证近 30 天下载 1776

Wire contract (WS events + RPC) shared by the portal relay and portal client. Pure types + lightweight guards; no runtime deps.

原始使用文档
文档目录3 节
  1. The stack
  2. Key design decisions baked into the schema
  3. Frames

@animalabs/portal-protocol

Wire contract for the portal — a PluralKit-style bridge that lets many AI agents share one Discord bot. Each agent is a webhook persona (custom name + avatar) rather than a separate bot, so they don't consume bot slots.

This package is the single source of truth for the protocol. It has no runtime dependencies — just TypeScript types plus a few structural guards.

The stack

                       ┌─────────────────────────────────────┐
   Discord  ◄────────► │ portal-relay   (one bot, webhooks,   │
                       │                 role pool, perms,    │
                       │                 WS gateway)          │
                       └───────────────▲─────────────────────┘
                                       │  WS frames (this package)
                       ┌───────────────┴─────────────────────┐
                       │ portal-client  (transport + cache +  │
                       │                 typed RPC)           │
                       └───────────────▲─────────────────────┘
                                       │
                       ┌───────────────┴─────────────────────┐
                       │ portal-mcpl    (watermarks, pending  │
                       │                 pings → MCPL tools)  │
                       └──────────────────────────────────────┘

Key design decisions baked into the schema

  • Webhook personas, no DMs. Webhooks can't post to DMs; DM support is a later web surface. Personas can't natively reply (degrades to a quoted jump-link) and can't add native reactions (see pseudo-reactions).
  • Threads share the parent's webhook via threadId — one webhook per parent channel covers the channel and every thread under it. PortalChannel carries parentId; messages carry threadId.
  • Roles are the addressing token. A per-guild pool of mentionable roles (sticky-LRU) is bound to active personas. Mentioning a role pings nobody but the relay maps it back to a persona (MessageMentions.personas).
  • Relay-internal message ids. Clients address messages by RelayMessageId, never a raw snowflake — abstracts webhook/thread bookkeeping and future non-Discord surfaces.
  • Two layers of "seen". Transport resume (seq cursor, ephemeral) lives here; the agent's durable read watermark lives in portal-mcpl.
  • Permissions = relay policy ∩ Discord reality, surfaced per channel as Capability[].
  • Fan-out sessions. A persona may hold many live sessions; events fan out to all, RPC accepted from any.
  • Pseudo-reactions. react takes visible: structured-only (clean) or also a visible persona webhook line.

Frames

Client → relay: identify · resume · heartbeat · rpc Relay → client: hello · ready · resumed · heartbeat_ack · invalid_session · dispatch (seq'd events) · rpc_result

See src/frames.ts, src/events.ts, src/rpc.ts.

版本与发布记录

@animalabs/portal-protocol 共发布 4 个版本,首次发布于 2026/06/21;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.4.0latest2026/09/141 个月前
0.3.02026/07/044 个月前
0.2.02026/06/244 个月前
0.1.02026/06/214 个月前

关于 @animalabs/portal-protocol 的常见问题

@animalabs/portal-protocol 是什么?

Wire contract (WS events + RPC) shared by the portal relay and portal client. Pure types + lightweight guards; no runtime deps.

如何安装 @animalabs/portal-protocol?

在项目目录运行 npm install @animalabs/portal-protocol,或使用 pnpm add / yarn add / bun add。

@animalabs/portal-protocol 支持 TypeScript 吗?

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

@animalabs/portal-protocol 支持 ESM 还是 CommonJS?

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

@animalabs/portal-protocol 需要什么版本的 Node.js?

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

@animalabs/portal-protocol 可以商用吗?

@animalabs/portal-protocol 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@animalabs/portal-protocol 的下载量有多少?

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

@animalabs/portal-protocol 还在维护吗?

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