@zhin.js/adapter-satori 1.1.27 → 1.1.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,151 @@
1
1
  # @zhin.js/adapter-satori
2
2
 
3
+ ## 1.1.29
4
+
5
+ ### Patch Changes
6
+
7
+ - d80964d: 修复 1.2 发版撞号:`@zhin.js/core` 与 `@zhin.js/agent` 按 minor 升到 1.2.0 时,npm 上早已有同号的旧架构版本(core 1.2.0–1.5.16、agent 1.2.0–1.2.1),`changeset publish` 只提示 already published 就跳过,导致 `zhin.js@1.1.26` 等已发布的包依赖了旧 core / agent,启动时缺少 `CHAT_ROLES`。
8
+
9
+ 本次把 core 发为 1.6.0、agent 发为 1.3.0(npm 上第一个空闲的 minor),并重新发布所有直接依赖它们的包,让依赖版本与 peer 范围指向新版本(`^1.6.0` / `^1.3.0`,不再落进旧架构版本)。
10
+
11
+ - Updated dependencies [7fb1ee7]
12
+ - Updated dependencies [d80964d]
13
+ - @zhin.js/host-http@1.2.1
14
+ - @zhin.js/core@1.6.0
15
+ - @zhin.js/adapter@1.1.33
16
+
17
+ ## 1.1.28
18
+
19
+ ### Patch Changes
20
+
21
+ - c606d51: 各适配器按平台能力上报入站发送者的 `sender.platform`(ADR 0056 §1),并在能力画像 `scene.platformStanding` 中声明:OneBot11、NapCat、Milky、ICQQ 群消息上报群主 / 管理员 / 成员;QQ 官方频道上报频道主 / 超级管理员与身份组;Discord 服务器频道上报所有者 / 管理员 / 成员、身份组与 snake*case 权限位;Telegram 群消息按 `getChatMember` 上报 creator / administrator / member / 已离开,以及管理员的 `can*\*` 权限;KOOK 服务器频道上报服务器主 / 管理员角色、角色列表与权限位;飞书、钉钉群消息上报群主 / 管理员 / 成员;Sandbox 把模拟角色作为平台身份上报,不再授予框架主人角色。Satori、Slack、OneBot12、企业微信、LINE 的事件不带可靠的成员身份,不上报。README 补充「成员身份」说明。
22
+
23
+ 机器人自身身份(`management.inspectSelfStanding` + 能力画像 `scene.selfStanding`,供 `bot:*` permit):ICQQ、OneBot11、NapCat、Milky 群(`get_group_member_info` self);QQ 官方群(`getBotState`)与频道(机器人频道成员身份组);Discord(`guild.members.me` 身份组与频道权限);Telegram(`getChatMember` bot);KOOK(`/v3/user/view` self 的服务器角色与权限位);飞书(`chat.get` 群主与 `bot_manager_id_list`)。钉钉没有对应接口,不声明。群管理类 Agent 工具补上 `bot:admin` / `bot:owner` / `bot-permission:*`,需要发言者是群管的平台操作改用 `platform:admin` 等。
24
+
25
+ - 57c6cdc: fix: 全仓审计修复
26
+
27
+ - kernel: 模板求值沙箱不再泄漏宿主对象——宿主函数的返回值与抛出的错误会重新包裹代理(`segments.map(x=>x).constructor.constructor(...)` 之前可拿到宿主 `Function`),并禁止通过代理写入/删除宿主属性。
28
+ - agent: exec 白名单正则按整体锚定(`git|npm` 不再匹配 `gitevil`);SSRF 主机名黑名单识别尾点形式(`localhost.`);Docker 沙箱 `always` 模式的 fail-closed 分支可被触达;声明缺失的 `chalk` 依赖。
29
+ - ai: 摘要按最新优先加载(超过 500 条时不再使用过期锚点);修复 `test` 脚本指向不存在的配置。
30
+ - cli: `ZHIN_LOG_LEVEL` 生效(修复运算符优先级);移除旧守护进程遗留的无引用进程辅助函数。
31
+ - logger: `formatCompact` 不再把 `config: 'yaml'`、`direction: 'in'` 这类非路径值改写成 `./yaml`。
32
+ - host-http: 未配置数据库时 `db:tables` 与有数据库时一致返回 `{ tables }`。
33
+ - a2a: 405 响应把 `Allow` 放进响应头。
34
+ - pagemanager: 内联进 `<script>` 的页面元数据转义 `<`。
35
+ - client: 事件历史请求失败时携带 HTTP 状态,token 失效可触发重新登录。
36
+ - scaffold-wizard / create-zhin-app: 修正适配器文档 URL 与模板里的 `@zhin.js/tool` 导入。
37
+ - adapter-wechat-mp: 签名比较改为常量时间。
38
+ - adapter-kook: 声明运行时依赖 `ws`。
39
+ - plugin-lottery: 遗漏值按最近一次出现计算;推送目标 schema 字段与实现一致(`endpointKey`)。
40
+ - plugin-code-runner: 语言校验改用自有属性判断。
41
+ - plugin-link-poster: 抓取前校验主机名白名单(修复 SSRF),超时覆盖响应体读取。
42
+ - 其余包:从 `files` 中移除不存在的目录。
43
+ - feature-kit / middleware: 修正 README 中层级错误的文档链接。
44
+
45
+ - e1fda87: fix: 按审计待审清单处理(安全、功能、清理)
46
+
47
+ **行为变更(升级前请阅读)**
48
+
49
+ - kernel / core / zhin.js:出站文本中的 `${…}` 不再用 `vm` 求值,只替换 `TemplateContext` 上能解析到值的属性路径(如 `${sender.name}`);表达式、函数调用、未知名字原样保留。整套 vm 沙箱(`evaluate` / `execute` / `compiler` / `getValueWithRuntime`)已移除。
50
+ - kernel / core / zhin.js:移除零引用的遗留导出——`Scheduler`、错误管理器与 `ZhinError` 子类、`compose`、`segment.from/toString`、AI 触发/准入函数、`@zhin.js/core/queue-im-field-contract`、`zhin.js/contexts`。
51
+ - agent:readonly 执行预设不再放行重定向、后台 `&`、进程替换、`find -delete/-exec`、`sed -i`、`sort -o`、`tee`、`xargs`、awk;curl/wget 校验每个 URL 与裸主机并识别更多上传参数;自定义 `execAllowlist` 中的只读命令带写入风险时改走审批。沙箱超时/取消会杀掉进程组或具名容器,默认镜像改为 `node:22-bookworm-slim` + `bash`。移除无生产调用的 `AuditLogger`、`AnomalyDetector`、旧 vision 回合等导出。
52
+ - ai:移除 `storage`、`FileStateCache`、`CostTracker`、`model-name-utils`、`./agent-step-checkpoint` 子路径、`ContextManager` 及旧压缩管线;延迟工具快照改为有界 LRU。
53
+ - cli:`zhin send` / `watch` / `schedule` 改为与运行中的 Host 通信(新增 `POST /message/send` 与 `/assistant/jobs` 写接口),`schedule` 不再支持离线改文件;移除 `zhin uninstall service`(用 `zhin service uninstall`)、`build --analyze`、`install -S`;`zhin stop` 杀不掉进程时保留 pid 文件并以非零退出;`runtime migrate` 新增 `verify`;未设置 `TZ` 时调度默认时区改为系统时区;不带 `ZHIN_SUPERVISOR_PID` 的进程被 init 接管后不再自行退出。
54
+ - schedule:后台 reconcile 出错不再产生未处理 rejection(新增 `onStoreError`);启动途中 `stop()` 不再遗留定时器。
55
+ - schema:元组校验与 `safeParse`、JSON Schema 一致(空数组不通过,缺省的可选元组为 `undefined`)。
56
+ - client / contract:删除无后端路由的 agent-stream API、未使用的 `definePage` 与旧 PageManager 类型;`@zhin.js/contract` 不再依赖 `@zhin.js/ai`;客户端收到 401 会清除已保存的凭据;安装/更新/卸载 RPC 默认超时 120 秒。
57
+ - a2a:流式响应中途出错写入 SSE error 并结束;未配置 token 的非生产环境只接受本机请求;任务存储有上限与过期;Mailbox 凭据回退与生产环境缺密钥检查修复。
58
+ - speech:`provider: openai` 不再套用 Ollama 的默认 host/model;识别语言改为可配置,不再写死 `zh`。
59
+ - adapter-lark:支持 `encryptKey` 加密事件解密。adapter-github:Device Flow 可取消、带超时并回复失败原因。adapter-wecom / dingtalk:请求加超时并校验 HTTP 状态。adapter-weixin-ilink:输入关闭期间暂停轮询。adapter-milky:SSE 支持 CRLF、缓冲上限与空闲重连。adapter-onebot-events:好友删除通知改为 `notice.friend.decrease`。
60
+ - plugin-group-suite:`teachAllowRegex` 默认关闭,正则安全检查更严格。plugin-qrcode:改为本地生成,回复 data URL 图片。plugin-rss / short-url / link-poster:拒绝解析到内网的地址;rss 修复条目每周重复推送;short-url 的 Console 创建改为真实调用 is.gd。plugin-lottery:按 `historyLimit` 同步。
61
+
62
+ **其余**
63
+
64
+ - host-http:插件市场详情加缓存与包名校验,SSE 回放容忍背压。host-http-contract:新增 `readTextBody()`,九个适配器改用它。
65
+ - pagemanager:页面外壳 importmap 升级到 React 19.2.8 / react-router 7.12.0。console-contract:`definePage` 接受 `description` / `group` / `parent` / `fullWidth`。
66
+ - command:进度提示本地化,匹配不再重复拷贝消息段。runtime:源码监听降级后退避重试原生监听。
67
+ - html-renderer:删除未接线的 `aiTextAsImage`。create-zhin-app / scaffold-wizard:移除不起作用的"全局安装 CLI"与运行时选择提示。
68
+ - 依赖声明清理、发布清单不再携带解析不到的 `src` 目录、移除未使用的 Skill 挂载、README 与示例配置按当前实现更正。
69
+
70
+ - 120e225: 聊天角色(ADR 0056,2026-11-12 修订):zhin 角色 owner / admin / trusted 分四级、只来自授予;发言者的平台身份与机器人自身的平台身份是独立维度,命令、Agent 工具 / 技能、中间件与按钮按三条维度共用一个评估器过滤。升级说明见 docs/migrations/chat-roles.md。
71
+
72
+ - zhin.js:实例首次启动把适配器 `master` / `trusted`、`endpoints[i].master|trusted` 与 `ai.trigger.masters|trusted` 迁入项目数据库 `chat_roles`(先记入 `.zhin/chat-roles-migration.json`,再从配置移除并记日志);之后配置再出现这些字段时启动报错并指向升级指南。平台身份不再映射为 zhin 角色:删除 `roles.mappings`(适配器块与 `endpoints[i].roles` 出现即启动报错)、`chat_role_mappings` 表与 Console `chat-roles.mappings` / `chat-roles.set-mappings`;`features.selfService.platformAdmins|roles|allowUsers` 删除;群内「功能」「角色」命令只认 zhin 角色,平台群主不再自动具备;聊天改配置、聊天重启、Agent 主人审批按 zhin `owner` 判断。
73
+ - @zhin.js/core(minor,破坏性):角色模型与解析移入 core(`ChatRoleService`、`createChatRoleSenderEnricher`),入站消息带 `sender.chatRole` 与归一的 `sender.platform`;删除 `SenderRole`、`senderRolesFromMessage`、`roleSatisfies` 等,`master` 改名 `owner`;删除映射规则 API(`createMappingChatRoleSource`、`DEFAULT_CHAT_ROLE_MAPPINGS` 等)与 `ChatRoleSource`;`createSenderEnricher` / `createConfigurationChatAuthorizer` 改为基于聊天角色。IM Runtime 为 PermissionHost 提供机器人自身身份(经 Adapter 索引缓存),机器人的角色变化事件使缓存失效;命令拒绝回复说明缺少的平台 / 机器人条件;`<Button permit>` 按点击者鉴权;场景治理工具工厂同时要求 `platform:*` 与 `bot:*`;`ai.trigger.masters|trusted` 删除。
74
+ - @zhin.js/permission(minor,破坏性):permit 语法 `owner` / `admin` / `trusted` / `role(...)`(zhin 角色)、`platform:owner|admin`、`platform-role:<id>`、`platform-permission:<name>`(发言者平台身份),新增 `bot:owner|admin`、`bot-role:<id>`、`bot-permission:<name>`(机器人自身平台身份,`PermissionSubject.bot`);`PermissionHost` 新增 `setBotStandingResolver`、`withBotStanding`、`firstDenied`,`checkAll` 可带 `source` 解析机器人身份;新增 `describeDeniedPermit`、`permitsNeedBotStanding`。删除 `role(master)`、`scene_admin`、`scene_owner`、`platform(adapter,perm)` 及 `registerPlatform`、`createSceneRolePlatformChecker`、`platformPermission`、`definePlatformPermission`,定义时报错并给出替代写法。
75
+ - @zhin.js/command(minor,破坏性):命令会话的发送者改为 `chatRole` / `platform`,不再从 metadata 读角色;`CONVERSATION_MANAGER_PERMIT` 改为 `admin`(平台群主不再自动满足);分发结果 `denied` 带 `denial`(第一条不满足的规则与原因);指令菜单只列出当前发送者在本会话可用的命令。
76
+ - @zhin.js/agent(minor,破坏性):危险工具、文件 / exec 策略、主人审批、Agent 回合主体只读 zhin 角色(`principal.roles` 只含展开的聊天角色,平台地位在 `principal.platform`);`SenderRole` → `PrincipalRole`,`SELF_CHANGE_MASTER_ROLE` → `SELF_CHANGE_OWNER_ROLE`;回合开始时读取机器人自身身份(`contextState.bot.platform`),按三条维度过滤 tool / skill / Agent 包后才披露,执行工具时再校验一次;群规「群主和管理员豁免」改为平台群主 / 管理员与 zhin `owner`。
77
+ - @zhin.js/feature-kit:`OperationSession.sender` 改为 `chatRole` / `platform`。
78
+ - @zhin.js/im-contract:新增 `PlatformStanding`、`SelfStandingRequest`、`standingFromMemberRole`。
79
+ - @zhin.js/adapter:入站 sender 可带 `platform`;账号管理命令需要聊天角色 `owner`;`EndpointManagement` 新增可选 `inspectSelfStanding`,能力画像新增 `scene.selfStanding`(声明即须实现),`AdapterIndex.selfStanding` / `invalidateSelfStanding` 按会话缓存机器人自身身份。
80
+ - @zhin.js/middleware:入站中间件可声明 `permit`,不满足时跳过该中间件(机器人身份只读缓存)。
81
+ - @zhin.js/tool:定义工具时拒绝已移除的 permit 写法。
82
+ - @zhin.js/ai:注释更新。
83
+ - @zhin.js/console-protocol:`chat-roles.list|grant|revoke`(`iam.manage`);`ConsoleChatRoleSource` 只有 `grant`。
84
+ - @zhin.js/runtime:Host 配置 Schema 删除 `features.selfService.platformAdmins|roles|allowUsers`。
85
+ - @zhin.js/testing:伪造消息与 `PluginTestKit` 用 `sender.chatRole` 声明测试身份。
86
+ - @zhin.js/scaffold-wizard:ICQQ 向导不再写 `master`,完成后提示在 Console 账号「角色」页签或聊天 `角色 授予` 设置 owner。
87
+ - 适配器:配置 Schema 删除 `master` / `trusted`(以及预览版的 `roles`);群管理类工具同时声明发言者条件与机器人条件(如 `platform:admin` + `bot:admin`、`bot-permission:manage_roles`),NapCat / OneBot11 工具不再使用已移除的 `platform(adapter,…)` 写法。
88
+ - 插件:内容审核以 `inbound.bypass`(permit 列表,默认 `owner` 或 `platform:admin`)取代 `masters` / `inbound.bypassMasters`;群管、音乐、日历、地震、B 站、轮盘赌的权限改用 zhin 角色,订阅类命令只认 zhin `admin` / `owner`。
89
+
90
+ - c2bbdcf: Console 访问控制(ADR 0049):用户、角色、会话、API 令牌与审计日志存入项目数据库,每个 Console RPC、`/api` 路由与 Host 鉴权的 WebSocket 都按 `@zhin.js/console-protocol` 的权限表放行,未登记的一律拒绝。
91
+
92
+ **破坏性变更**
93
+
94
+ - `http.tokens` 与演示模式(`scope: demo` / `user`)删除;配置里仍有 `http.tokens` 时 Host 拒绝启动。Host 配置 Schema 同步删除该字段。
95
+ - `http.token` 变为初始化令牌:只在创建第一个所有者之前有效,之后在所有接口上被拒绝。
96
+ - 未在 `CONSOLE_WS_PERMISSIONS` 登记、又使用 Host 鉴权的插件 WebSocket 不再接受 Console 账号;插件自己的 WebSocket 应改用 `ws(path, { auth: 'protocol' })` 并自行校验凭据(新增 `verifyProtocolAccessToken`、`isLoopbackAddress`)。
97
+ - OneBot 11 / 12、NapCat、Milky 的反向 WebSocket 改为只认适配器自己的 `access_token`;未配置 `access_token` 时只接受本机回环连接。
98
+ - `zhin doctor --live` 等改从 `ZHIN_CONSOLE_TOKEN` 读取 API 令牌(仍兼容 `ZHIN_HTTP_TOKEN`)。
99
+
100
+ **迁移步骤**(详见文档「升级到 Console 访问控制」)
101
+
102
+ 1. 升级后用 `http.token` 打开 Console 初始化向导创建第一个所有者,或运行 `zhin console init`(脚本:`zhin console init --yes --owner <名> --password-stdin`)。
103
+ 2. 删除配置里的 `http.tokens`,在 Console「访问控制」里为原来的令牌持有人创建用户并绑定角色(`viewer` / `operator` / `admin`);演示环境改用 `viewer` 账号。
104
+ 3. 自动化在 Console 签发 API 令牌,放进 `ZHIN_CONSOLE_TOKEN`。
105
+ 4. 从其他机器或容器连接的反向 WebSocket endpoint 补上 `access_token`。
106
+ 5. 忘记密码或所有者被锁时,停下 Host,用 `zhin console user passwd|enable|create` 离线恢复。
107
+
108
+ MCP / A2A 的 Bearer 访问同样接受用户 API 令牌(分别需要 `mcp.access`、`a2a.access`)。适配器与插件文档同步改为账号与角色的说法。
109
+
110
+ - 5cd9d3d: HTTP 路由契约改为 Web 标准 `Request` / `Response`(ADR 0054 §2,B1.0)
111
+
112
+ - host-http-contract:路由处理函数签名改为 `(request, context) => Response`,`context` 提供 `url`、`params`、`principal`、`remoteAddress`;新增 `readBodyBytes` / `readTextBody` / `readJsonBody`(带大小上限,超限先读完再报 413)、`jsonResponse` / `emptyResponse`、带背压的 `createResponseStream`(SSE、大文件下载)与 `WsConnection`。契约不再引用 `node:http` / `ws`。
113
+ - host-http:Node 服务器移到 `@zhin.js/host-http/node`(`createHttpHost`),负责 Node 请求与 `Request` / `Response` 的互转;认证结果经 `context.principal` 传给路由,删除旧的按请求取主体的辅助函数;未预期的异常只返回通用错误信息,细节写日志。
114
+ - runtime、mcp、a2a、gateway、zhin.js、calendar 插件与各适配器的 Webhook / 反向 WebSocket 路由迁移到新契约,行为不变。
115
+
116
+ - Updated dependencies [53932e5]
117
+ - Updated dependencies [57c6cdc]
118
+ - Updated dependencies [e1fda87]
119
+ - Updated dependencies [4e8ba38]
120
+ - Updated dependencies [a9c7a13]
121
+ - Updated dependencies [120e225]
122
+ - Updated dependencies [c2bbdcf]
123
+ - Updated dependencies [c2bbdcf]
124
+ - Updated dependencies [63595fc]
125
+ - Updated dependencies [fd055d2]
126
+ - Updated dependencies [4e8ba38]
127
+ - Updated dependencies [cc7a5f9]
128
+ - Updated dependencies [4e8ba38]
129
+ - Updated dependencies [f8bf684]
130
+ - Updated dependencies [e0bc008]
131
+ - Updated dependencies [5cd9d3d]
132
+ - Updated dependencies [5cd9d3d]
133
+ - Updated dependencies [c2bbdcf]
134
+ - Updated dependencies [f8bf684]
135
+ - Updated dependencies [663473b]
136
+ - Updated dependencies [c606d51]
137
+ - Updated dependencies [5cd9d3d]
138
+ - Updated dependencies [d655ef0]
139
+ - Updated dependencies [1e54b1e]
140
+ - @zhin.js/adapter@1.1.33
141
+ - @zhin.js/core@1.2.0
142
+ - @zhin.js/logger@1.1.3
143
+ - @zhin.js/host-http@1.2.0
144
+ - @zhin.js/feature-kit@1.1.16
145
+ - @zhin.js/console-contract@1.1.6
146
+ - @zhin.js/im-contract@1.1.14
147
+ - @zhin.js/page@1.1.18
148
+
3
149
  ## 1.1.27
4
150
 
5
151
  ### Patch Changes
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 凉菜
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -100,10 +100,6 @@ SDK 会向 `path` 发送 POST,请求头 `Satori-Opcode: 0` 表示事件;每
100
100
  - 消息 id 格式为 `channelId:messageId`,便于发消息 / 撤回时解析。
101
101
  - 撤回时需 `channel_id` + `message_id`,适配器已按上述格式解析。
102
102
 
103
- ## AI 工具
104
-
105
- 技能说明见 `skills/satori/SKILL.md`。
106
-
107
103
  ## 协议文档
108
104
 
109
105
  - [介绍](https://satori.chat/zh-CN/introduction.html)
@@ -118,7 +114,7 @@ SDK 会向 `path` 发送 POST,请求头 `Satori-Opcode: 0` 表示事件;每
118
114
  - 经所属 Adapter 增删持久化账号、启停单个 Endpoint;凭据由 Host 加密仓储保存,不改启动 YAML 或 `.env`,不重启进程;
119
115
  - 如果适配器要求登录,页面会显示 LoginAssist 的扫码 / 滑块 / 设备确认待办;
120
116
 
121
- 读取需要 `satori:read`,写操作需要 `satori:write`;管理员 full token 不受限。页面里的「添加 endpoint」等价于原来的 `satori endpoint add`。
117
+ 读取需要 `satori:read`(`read` 级别,内置角色 `viewer` 及以上都有);增删改账号等写操作需要 `satori:write`(`operate` 级别,`operator` 及以上都有,绑定到本适配器的角色也算),首次迁移还需管理员身份;全局所有者不受限,见[插件权限的级别](https://zhin.js.org/console/#插件权限的级别)。页面里的「添加 endpoint」等价于原来的 `satori endpoint add`。
122
118
 
123
119
  ## 故障排查
124
120
 
@@ -128,3 +124,7 @@ SDK 会向 `path` 发送 POST,请求头 `Satori-Opcode: 0` 表示事件;每
128
124
  | Webhook 无事件 | 确认路径、`Satori-Opcode: 0` 与 HTTP Host |
129
125
  | 401 | 检查 API、WS IDENTIFY 与 Webhook 使用的 token 是否一致 |
130
126
  | 发送目标错误 | 核对 `channel_id` 与 Conversation kind;DIRECT 才映射为 private |
127
+
128
+ ## 成员身份
129
+
130
+ Satori 事件不带可靠的群主 / 管理员信息,不上报 `sender.platform`,能力画像也不声明 `scene.platformStanding`。详见 [ADR 0056 §1](https://github.com/zhinjs/zhin/blob/main/docs/adr/0056-chat-roles.md)。
package/lib/endpoint.js CHANGED
@@ -346,11 +346,12 @@ export class SatoriWebhookEndpoint extends SatoriClient {
346
346
  this.#routeReleases.push(...registerSatoriWebhookRoutes(this.#options.http, {
347
347
  config: this.#options.config,
348
348
  get isOpen() { return isOpen(); },
349
- acceptHttp: async (request, response) => {
350
- await acceptHttpIngress(request, response, body => {
349
+ acceptHttp: async (request) => {
350
+ const result = await acceptHttpIngress(request, undefined, body => {
351
351
  void this[endpointSpec].events.run(() => this.#receive(body))
352
352
  .catch(error => this.#warnPlatformEvent('event', error));
353
353
  });
354
+ return new Response(JSON.stringify(result.body), { status: result.status, headers: result.headers });
354
355
  },
355
356
  }));
356
357
  this.#logger.info(formatCompact({
package/lib/webhook.d.ts CHANGED
@@ -1,12 +1,15 @@
1
- import type { IncomingMessage, ServerResponse } from 'node:http';
2
1
  import type { HttpHost, HttpRouteRegistration } from '@zhin.js/host-http';
3
2
  import { type ResolvedSatoriWebhookConfig } from './protocol.js';
4
3
  export interface SatoriWebhookHandler {
5
4
  readonly config: ResolvedSatoriWebhookConfig;
6
5
  readonly isOpen: boolean;
7
- acceptHttp(request: IncomingMessage, response: ServerResponse): Promise<void>;
6
+ acceptHttp(request: Request): Promise<Response>;
8
7
  }
9
8
  export declare function registerSatoriWebhookRoutes(http: HttpHost, handler: SatoriWebhookHandler): HttpRouteRegistration[];
10
- export declare function handleSatoriWebhookRequest(request: IncomingMessage, response: ServerResponse, handler: SatoriWebhookHandler): Promise<void>;
11
- export declare function resolveSatoriOpcode(request: IncomingMessage): number | undefined;
12
- export declare function verifySatoriToken(token: string | undefined, request: IncomingMessage): boolean;
9
+ export declare function handleSatoriWebhookRequest(request: Request, handler: SatoriWebhookHandler): Promise<Response>;
10
+ export declare function resolveSatoriOpcode(request: {
11
+ readonly headers: Headers;
12
+ }): number | undefined;
13
+ export declare function verifySatoriToken(token: string | undefined, request: {
14
+ readonly headers: Headers;
15
+ }): boolean;
package/lib/webhook.js CHANGED
@@ -8,43 +8,29 @@ const logger = getLogger('satori');
8
8
  export function registerSatoriWebhookRoutes(http, handler) {
9
9
  const path = handler.config.path;
10
10
  return [
11
- http.route('POST', path, async (request, response) => {
12
- await handleSatoriWebhookRequest(request, response, handler);
13
- }, { summary: 'Satori webhook callback', tags: ['satori'] }),
11
+ http.route('POST', path, (request) => handleSatoriWebhookRequest(request, handler), { summary: 'Satori webhook callback', tags: ['satori'] }),
14
12
  ];
15
13
  }
16
- export async function handleSatoriWebhookRequest(request, response, handler) {
14
+ export async function handleSatoriWebhookRequest(request, handler) {
17
15
  try {
18
16
  if (!verifySatoriToken(handler.config.token, request)) {
19
- response.writeHead(403, { 'Content-Type': 'application/json' });
20
- response.end(JSON.stringify({ message: 'Unauthorized' }));
21
- return;
17
+ return new Response(JSON.stringify({ message: 'Unauthorized' }), { status: 403, headers: { 'Content-Type': 'application/json' } });
22
18
  }
23
19
  const opcode = resolveSatoriOpcode(request);
24
20
  if (opcode !== SatoriOpcode.EVENT && opcode !== SatoriOpcode.META) {
25
- response.writeHead(200, { 'Content-Type': 'application/json' });
26
- response.end(JSON.stringify({ message: 'OK' }));
27
- return;
28
- }
29
- if (handler.isOpen) {
30
- await handler.acceptHttp(request, response);
31
- }
32
- else {
33
- response.writeHead(200, { 'Content-Type': 'application/json' });
34
- response.end(JSON.stringify({ status: 'ok' }));
21
+ return new Response(JSON.stringify({ message: 'OK' }), { status: 200, headers: { 'Content-Type': 'application/json' } });
35
22
  }
23
+ if (handler.isOpen)
24
+ return await handler.acceptHttp(request);
25
+ return new Response(JSON.stringify({ status: 'ok' }), { status: 200, headers: { 'Content-Type': 'application/json' } });
36
26
  }
37
27
  catch (error) {
38
28
  logger.error('Satori webhook error:', error);
39
- if (!response.headersSent) {
40
- response.writeHead(500, { 'Content-Type': 'application/json' });
41
- response.end(JSON.stringify({ message: 'Internal Server Error' }));
42
- }
29
+ return new Response(JSON.stringify({ message: 'Internal Server Error' }), { status: 500, headers: { 'Content-Type': 'application/json' } });
43
30
  }
44
31
  }
45
32
  export function resolveSatoriOpcode(request) {
46
- const raw = request.headers['satori-opcode'] ?? request.headers['Satori-Opcode'];
47
- const value = Array.isArray(raw) ? raw[0] : raw;
33
+ const value = request.headers.get('satori-opcode');
48
34
  if (value == null || value === '')
49
35
  return undefined;
50
36
  const parsed = Number.parseInt(String(value), 10);
@@ -53,7 +39,7 @@ export function resolveSatoriOpcode(request) {
53
39
  export function verifySatoriToken(token, request) {
54
40
  if (!token)
55
41
  return true;
56
- const auth = request.headers.authorization ?? '';
42
+ const auth = request.headers.get('authorization') ?? '';
57
43
  const expected = Buffer.from(`Bearer ${token}`, 'utf8');
58
44
  const actual = Buffer.from(auth, 'utf8');
59
45
  return actual.length === expected.length && timingSafeEqual(actual, expected);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/adapter-satori",
3
- "version": "1.1.27",
3
+ "version": "1.1.29",
4
4
  "description": "Zhin.js Satori adapter for Plugin Runtime (WebSocket client)",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -19,7 +19,6 @@
19
19
  "schema.json",
20
20
  "src",
21
21
  "lib",
22
- "skills",
23
22
  "README.md",
24
23
  "CHANGELOG.md"
25
24
  ],
@@ -34,36 +33,35 @@
34
33
  "license": "MIT",
35
34
  "repository": {
36
35
  "type": "git",
37
- "url": "https://github.com/zhinjs/zhin.git",
36
+ "url": "git+https://github.com/zhinjs/zhin.git",
38
37
  "directory": "plugins/adapters/satori"
39
38
  },
40
39
  "dependencies": {
41
40
  "@imhelper/satori-v1": "1.0.7",
42
41
  "imhelper": "1.0.7",
43
42
  "ws": "^8.21.1",
44
- "@zhin.js/adapter": "1.1.32",
45
- "@zhin.js/console-contract": "1.1.5",
46
- "@zhin.js/core": "1.1.60",
47
- "@zhin.js/host-http": "1.1.17",
48
- "@zhin.js/feature-kit": "1.1.15",
49
- "@zhin.js/im-contract": "1.1.13",
50
- "@zhin.js/logger": "1.1.2",
51
- "@zhin.js/page": "1.1.17",
52
- "@zhin.js/skill": "1.1.16"
43
+ "@zhin.js/adapter": "1.1.33",
44
+ "@zhin.js/console-contract": "1.1.6",
45
+ "@zhin.js/core": "1.6.0",
46
+ "@zhin.js/feature-kit": "1.1.16",
47
+ "@zhin.js/host-http": "1.2.1",
48
+ "@zhin.js/im-contract": "1.1.14",
49
+ "@zhin.js/logger": "1.1.3",
50
+ "@zhin.js/page": "1.1.18"
53
51
  },
54
52
  "devDependencies": {
55
53
  "@types/node": "^26.1.2",
56
54
  "@types/ws": "^8.18.1",
57
55
  "typescript": "^6.0.3",
58
56
  "vitest": "^4.1.10",
59
- "@zhin.js/host-http": "1.1.17",
60
- "zhin.js": "1.1.25"
57
+ "@zhin.js/host-http": "1.2.1",
58
+ "zhin.js": "1.1.27"
61
59
  },
62
60
  "peerDependencies": {
63
- "@zhin.js/adapter": "^1.1.32",
64
- "@zhin.js/command": "^1.1.17",
65
- "@zhin.js/core": "^1.1.60",
66
- "zhin.js": "^1.1.25"
61
+ "@zhin.js/adapter": "^1.1.33",
62
+ "@zhin.js/command": "^1.2.1",
63
+ "@zhin.js/core": "^1.6.0",
64
+ "zhin.js": "^1.1.27"
67
65
  },
68
66
  "peerDependenciesMeta": {
69
67
  "@zhin.js/command": {
@@ -100,10 +98,6 @@
100
98
  "package": "@zhin.js/command",
101
99
  "api": "^1.0.0"
102
100
  },
103
- {
104
- "package": "@zhin.js/skill",
105
- "api": "^1.0.0"
106
- },
107
101
  {
108
102
  "package": "@zhin.js/page",
109
103
  "api": "^1.0.0"
@@ -114,6 +108,6 @@
114
108
  "scripts": {
115
109
  "build": "tsc",
116
110
  "clean": "rimraf lib",
117
- "test": "NODE_OPTIONS=--experimental-strip-types vitest run --root ../../.. plugins/adapters/satori/tests"
111
+ "test": "vitest run --root ../../.. plugins/adapters/satori/tests"
118
112
  }
119
113
  }
package/schema.json CHANGED
@@ -17,34 +17,6 @@
17
17
  "default": 10000,
18
18
  "description": "WS PING interval in milliseconds"
19
19
  },
20
- "master": {
21
- "type": [
22
- "string",
23
- "number"
24
- ],
25
- "description": "框架 master(platform user id;AI/工具权限、endpoint 管理)。endpoints[i].master 可逐项覆盖",
26
- "x-i18n": {
27
- "en": {
28
- "description": "Framework masters (platform user id; AI/tool permissions and endpoint management). endpoints[i].master can override this value."
29
- }
30
- }
31
- },
32
- "trusted": {
33
- "type": "array",
34
- "items": {
35
- "type": [
36
- "string",
37
- "number"
38
- ],
39
- "description": "Trusted platform user id"
40
- },
41
- "description": "框架 trusted 用户列表(弱于 master)。endpoints[i].trusted 可逐项追加",
42
- "x-i18n": {
43
- "en": {
44
- "description": "Framework trusted users, below master authority. endpoints[i].trusted can add users."
45
- }
46
- }
47
- },
48
20
  "endpoints": {
49
21
  "type": "array",
50
22
  "minItems": 1,
@@ -53,34 +25,6 @@
53
25
  "type": "object",
54
26
  "additionalProperties": false,
55
27
  "properties": {
56
- "master": {
57
- "type": [
58
- "string",
59
- "number"
60
- ],
61
- "description": "本 endpoint 的框架 master(platform user id);覆盖顶层 master",
62
- "x-i18n": {
63
- "en": {
64
- "description": "Framework masters for this endpoint (platform user id), overriding the top-level master list."
65
- }
66
- }
67
- },
68
- "trusted": {
69
- "type": "array",
70
- "items": {
71
- "type": [
72
- "string",
73
- "number"
74
- ],
75
- "description": "Trusted platform user id"
76
- },
77
- "description": "本 endpoint 的 trusted 列表",
78
- "x-i18n": {
79
- "en": {
80
- "description": "Trusted users for this endpoint."
81
- }
82
- }
83
- },
84
28
  "baseUrl": {
85
29
  "type": "string",
86
30
  "description": "Satori SDK HTTP/WS base URL (e.g. http://127.0.0.1:5140)"
package/src/endpoint.ts CHANGED
@@ -427,11 +427,12 @@ export class SatoriWebhookEndpoint extends SatoriClient implements Endpoint {
427
427
  this.#routeReleases.push(...registerSatoriWebhookRoutes(this.#options.http, {
428
428
  config: this.#options.config,
429
429
  get isOpen() { return isOpen(); },
430
- acceptHttp: async (request, response) => {
431
- await acceptHttpIngress<SatoriEventBody>(request, response, body => {
430
+ acceptHttp: async (request) => {
431
+ const result = await acceptHttpIngress<SatoriEventBody>(request, undefined, body => {
432
432
  void this[endpointSpec].events.run(() => this.#receive(body))
433
433
  .catch(error => this.#warnPlatformEvent('event', error));
434
434
  });
435
+ return new Response(JSON.stringify(result.body), { status: result.status, headers: result.headers });
435
436
  },
436
437
  }));
437
438
  this.#logger.info(formatCompact({
package/src/webhook.ts CHANGED
@@ -2,7 +2,6 @@
2
2
  * Satori webhook HTTP: token → opcode → parse → admit.
3
3
  */
4
4
  import { timingSafeEqual } from 'node:crypto';
5
- import type { IncomingMessage, ServerResponse } from 'node:http';
6
5
  import type { HttpHost, HttpRouteRegistration } from '@zhin.js/host-http';
7
6
  import { getLogger } from '@zhin.js/logger';
8
7
  import {
@@ -15,7 +14,7 @@ const logger = getLogger('satori');
15
14
  export interface SatoriWebhookHandler {
16
15
  readonly config: ResolvedSatoriWebhookConfig;
17
16
  readonly isOpen: boolean;
18
- acceptHttp(request: IncomingMessage, response: ServerResponse): Promise<void>;
17
+ acceptHttp(request: Request): Promise<Response>;
19
18
  }
20
19
 
21
20
  export function registerSatoriWebhookRoutes(
@@ -24,55 +23,40 @@ export function registerSatoriWebhookRoutes(
24
23
  ): HttpRouteRegistration[] {
25
24
  const path = handler.config.path;
26
25
  return [
27
- http.route('POST', path, async (request, response) => {
28
- await handleSatoriWebhookRequest(request, response, handler);
29
- }, { summary: 'Satori webhook callback', tags: ['satori'] }),
26
+ http.route('POST', path, (request) => handleSatoriWebhookRequest(request, handler), { summary: 'Satori webhook callback', tags: ['satori'] }),
30
27
  ];
31
28
  }
32
29
 
33
30
  export async function handleSatoriWebhookRequest(
34
- request: IncomingMessage,
35
- response: ServerResponse,
31
+ request: Request,
36
32
  handler: SatoriWebhookHandler,
37
- ): Promise<void> {
33
+ ): Promise<Response> {
38
34
  try {
39
35
  if (!verifySatoriToken(handler.config.token, request)) {
40
- response.writeHead(403, { 'Content-Type': 'application/json' });
41
- response.end(JSON.stringify({ message: 'Unauthorized' }));
42
- return;
36
+ return new Response(JSON.stringify({ message: 'Unauthorized' }), { status: 403, headers: { 'Content-Type': 'application/json' } });
43
37
  }
44
38
  const opcode = resolveSatoriOpcode(request);
45
39
  if (opcode !== SatoriOpcode.EVENT && opcode !== SatoriOpcode.META) {
46
- response.writeHead(200, { 'Content-Type': 'application/json' });
47
- response.end(JSON.stringify({ message: 'OK' }));
48
- return;
49
- }
50
- if (handler.isOpen) {
51
- await handler.acceptHttp(request, response);
52
- } else {
53
- response.writeHead(200, { 'Content-Type': 'application/json' });
54
- response.end(JSON.stringify({ status: 'ok' }));
40
+ return new Response(JSON.stringify({ message: 'OK' }), { status: 200, headers: { 'Content-Type': 'application/json' } });
55
41
  }
42
+ if (handler.isOpen) return await handler.acceptHttp(request);
43
+ return new Response(JSON.stringify({ status: 'ok' }), { status: 200, headers: { 'Content-Type': 'application/json' } });
56
44
  } catch (error) {
57
45
  logger.error('Satori webhook error:', error);
58
- if (!response.headersSent) {
59
- response.writeHead(500, { 'Content-Type': 'application/json' });
60
- response.end(JSON.stringify({ message: 'Internal Server Error' }));
61
- }
46
+ return new Response(JSON.stringify({ message: 'Internal Server Error' }), { status: 500, headers: { 'Content-Type': 'application/json' } });
62
47
  }
63
48
  }
64
49
 
65
- export function resolveSatoriOpcode(request: IncomingMessage): number | undefined {
66
- const raw = request.headers['satori-opcode'] ?? request.headers['Satori-Opcode'];
67
- const value = Array.isArray(raw) ? raw[0] : raw;
50
+ export function resolveSatoriOpcode(request: { readonly headers: Headers }): number | undefined {
51
+ const value = request.headers.get('satori-opcode');
68
52
  if (value == null || value === '') return undefined;
69
53
  const parsed = Number.parseInt(String(value), 10);
70
54
  return Number.isNaN(parsed) ? undefined : parsed;
71
55
  }
72
56
 
73
- export function verifySatoriToken(token: string | undefined, request: IncomingMessage): boolean {
57
+ export function verifySatoriToken(token: string | undefined, request: { readonly headers: Headers }): boolean {
74
58
  if (!token) return true;
75
- const auth = request.headers.authorization ?? '';
59
+ const auth = request.headers.get('authorization') ?? '';
76
60
  const expected = Buffer.from(`Bearer ${token}`, 'utf8');
77
61
  const actual = Buffer.from(auth, 'utf8');
78
62
  return actual.length === expected.length && timingSafeEqual(actual, expected);