npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

koishi-plugin-agent-nexus

v0.4.2

Published

Nexus Gateway agent delegation for ChatLuna

Readme

koishi-plugin-agent-nexus

AgentNexus 是 Nexus Gateway 的 Koishi / ChatLuna 配套插件。Gateway 统一接入 ACP 与 A2A Agent;本插件自动发现这些 Agent,并为每个可用 Agent 注册统一的 nexus_task 任务工具和独立的 nexus_<agent> 兼容工具。

功能边界

插件负责:

  • 连接一个 Nexus Gateway,定时读取 /v1/agents。
  • 注册 ChatLuna 风格的 nexus_task(run/status/list/agents/message/publish/stop),并按 Agent 保留 nexus_<agent> 工具。
  • 创建、续接、查询、取消和显式释放 Gateway Session。
  • 默认把用户任务原样交给目标 Agent,并等待 Agent 返回结果。
  • 用户当前消息中的图片、文件、音频和视频会在工具真正执行时读取并上传到 Gateway,再按 ACP/A2A 协议传递给目标 Agent;不会把整段 ChatLuna 历史上下文作为调用前提。
  • 会话上下文不是调用前提;显式使用后台模式时,如有 ChatLuna 会话上下文则在完成后唤醒原会话, 没有上下文时可通过返回的任务 ID 查询。
  • 转存 Gateway 返回的二进制产物为 ChatLuna 临时文件。
  • 用精确 request ID 回复授权或输入请求,避免把过期确认提交给后一个请求。
  • 优先通过 SSE 跟踪后台任务;Gateway 重启导致内存 Session 丢失时,任务会立即收敛为失败。
  • 只接受与当前 Gateway Run 匹配的协议完成证明;缺少证明、仍有待确认请求、或没有最终文本/产物的 completed 会转为失败,不会主动向 ChatLuna 谎报任务成功。
  • 为单个 Agent 提供改名、停用、工作区、描述和技能标签覆盖。

插件不再负责:

  • 直接连接 A2A Agent Card。
  • 兼容 ACP Bridge 或选择 Gateway 后端。
  • 管理多个 Gateway。
  • 内置、安装或维护 Gateway 服务。
  • SSH、远程终端、文件管理、Agent 安装和 Skills 同步。

这些能力属于独立的 Nexus Gateway 或宿主机运维层。

安装

要求 Node.js 20、Nexus Gateway 0.3.0 或更高版本(已针对 0.4.0 验证),并已安装 ChatLuna 与 koishi-plugin-chatluna-storage-service。

npm install koishi-plugin-agent-nexus

然后在 Koishi 插件设置中配置:

| 配置项 | 默认值 | 说明 | | --- | --- | --- | | gatewayUrl | http://127.0.0.1:8787 | Nexus Gateway 的数据面地址 | | gatewayKey | 空 | Gateway“API 密钥”页面生成的 API Key | | commandAuthority | 4 | Console 写操作所需权限等级 | | maxResponseBytes | 33554432 | 单个 HTTP 响应或 SSE 事件帧读取上限;不是整条长期事件流的累计上限 | | inputAttachments.localRoots | [] | 允许读取本地附件的专用目录;相对路径基于 Koishi 工作目录,目录必须已存在 | | inputAttachments.privateOrigins | [] | 允许访问内网附件服务的准确 HTTP(S) origin,例如 http://127.0.0.1:3000 |

gatewayKey 是数据面 API Key,不是 Gateway 控制台登录密码。

新版 Gateway 兼容性

本插件使用数据面 Session API,不读取管理员运行列表,所以不依赖旧版列表中的 task 字段,也不需要管理员 Cookie。通用 stdio Agent 与其他 ACP Agent 一样自动发现;命令、参数、环境变量和权限策略仍在 Gateway 配置。

新版 Gateway 默认按 Key 限制 Session、同时运行任务、SSE 和上传字节数。出现 429 时应检查该 Key 当前资源占用或调整 Gateway 的 quotas。创建任务、发送消息、授权和上传都可能产生外部效果,插件不会因为限流或断线自动重复提交这些写操作。

收到 SSE reset 时,插件重新读取固定的 Session 快照并更新游标,避免输出重复;这只能恢复当前状态,不能找回 Gateway 已淘汰的中间事件。Key 被停用、删除或收缩权限后,401/403 会停止对应任务的监控并显示鉴权失败;这不代表远端执行已取消。Session 已不存在时,404 会结束本地监控。

历史与产物受 Gateway 的保留期和磁盘预算约束。需要长期保存的文件应及时转存到 ChatLuna 存储;历史清理不等于聊天附件的长期备份。Gateway 控制台跨 Key 的取消/重试等管理接口不向插件开放,插件继续使用原 API Key 的归属和 Agent scope。

图片与文件闭环

ChatLuna 需要把任务交给 nexus_<agent> 工具时,插件会从当前 Koishi 消息元素收集附件,并先调用 Gateway 的 Session 附件接口。Gateway 会在对应 Session 中临时保存附件:单个文件最多 16 MiB、单次 任务最多 32 MiB、最多 16 个文件。之后:

  1. ACP Agent 优先收到其声明支持的图片/音频能力;不支持时由 Gateway 生成受限的临时资源链接。
  2. A2A Agent 收到带文件名和媒体类型的二进制 Part。
  3. Agent 返回的图片、音频、视频和文件由插件转成 ChatLuna 可发送的临时文件元素。
  4. Agent 只返回工作区路径时,可调用 action=publish;Gateway 会校验 realpath 边界并读取普通文件, 单个发布文件最多 12 MiB,再由插件转成 ChatLuna 临时文件。

附件只跟随当前任务发送,不会拼接成历史对话;ChatLuna 清空或删除会话时,插件会关闭关联的 Gateway Session 并清理临时附件。停止生成时会取消关联的活动任务。

默认只读取 data: 附件及公开 HTTP/HTTPS 地址。HTTP 地址不得包含用户名、密码或 fragment;域名的 全部解析结果和每次重定向目标都必须是公开地址,连接使用已校验的 DNS 结果。最多跟随 5 次重定向, 整个网络读取限时 30 秒;压缩响应也受解压后大小限制。

本地适配器返回 file:// 附件时,需要在 inputAttachments.localRoots 添加其专用附件缓存目录。 目录必须由管理员控制,不能允许不可信本地用户修改,也不要添加 Koishi 工作目录、配置目录或整个磁盘。 允许目录内的所有文件都可能作为聊天附件读取,因此该目录不能保存不应向聊天用户开放的文件。 允许目录在插件启动时固定为 realpath;目录外文件、UNC 地址、目录与符号链接逃逸会被拒绝,普通文件 在读取前和读取中均检查大小。升级后应按实际适配器设置这些允许目录。

内网附件 HTTP 服务需要在 inputAttachments.privateOrigins 添加准确的协议、主机和端口,不含路径或 尾斜杠。例如本机适配器文件服务可添加 http://127.0.0.1:3000。只添加专用且可信的附件服务;该项 允许其访问内网 IP,但不会信任它重定向到的其他 origin。插件不会自动把 Gateway 地址加入允许列表。

局域网配置

如果 Gateway 在 10.1.2.40,Koishi 插件中应填写:

gatewayUrl = http://10.1.2.40:8787
gatewayKey = <Gateway 中生成的 API Key>

0.0.0.0 只用于 Gateway 服务端监听所有网卡,不能作为客户端访问地址。局域网中的 Koishi 应使用 Gateway 机器的真实 IP 或域名。还要确认 Gateway 监听 0.0.0.0,并在防火墙中只放行 可信局域网来源。

A2A Agent

A2A Agent Card 在 Nexus Gateway 的 Agent 管理页配置。配置并健康检查成功后,Gateway 会在 /v1/agents 中返回该 Agent,插件会像处理 ACP Agent 一样自动创建 ChatLuna 工具。Koishi 插件中不需要再次填写 Agent Card URL、Bearer Token 或传输协议。

Agent 覆盖项

Console 的“Agent 中枢”页面默认展示 Gateway 返回的全部 Agent。无需手工创建路由;只有以下 情况才需要保存覆盖项:

  • 修改 ChatLuna 工具显示名称。
  • 暂停发布某个 Agent。
  • 为调用覆盖默认工作区。
  • 补充工具描述或技能标签。

删除覆盖项后会立即恢复 Gateway 自动配置。

ChatLuna 调用方式

推荐使用统一的 nexus_task。每个 Agent 仍会得到独立兼容工具,例如 nexus_hermes、 nexus_claude、nexus_dsh 或 nexus_opencode。action=run 默认以前台方式运行:插件原样传递用户 prompt,Gateway 会另外附加协议级完成约束,并持续等待 Agent 完成、失败、请求输入或请求授权。只有明确设置 background=true 时才立即返回任务 ID。后台任务完成或等待确认时会主动唤醒原 ChatLuna 会话,不需要轮询。后台任务仍在执行时, action=message 会把文字 guidance 持久化排队,并在当前远端 turn 完成后继续同一个 Gateway Session; 排队期间不接受附件。

授权/输入响应使用 action=message id=<任务ID> requestId=<请求ID>,并传 optionId、decision 或 prompt。发布远端工作区文件使用 action=publish id=<任务ID> path="dist/report.pdf"。 status、message、publish 和 stop 都可凭任务 ID 工作,即使当前工具调用没有 ChatLuna 会话上下文。

开发与验证

npm install
npm run typecheck
npm run build
npm pack --dry-run --json

License

MIT