@zhin.js/adapter-icqq 1.1.17 → 1.1.19

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.
Files changed (59) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/README.md +55 -10
  3. package/adapters/icqq/index.js +3 -19
  4. package/adapters/icqq/index.ts +2 -25
  5. package/commands/icqq/endpoint/definition.js +3 -25
  6. package/commands/icqq/endpoint/definition.ts +3 -24
  7. package/commands/icqq/login/code/index.js +28 -0
  8. package/commands/icqq/login/code/index.ts +30 -0
  9. package/commands/icqq/login/confirm/index.js +20 -0
  10. package/commands/icqq/login/confirm/index.ts +21 -0
  11. package/commands/icqq/login/definition.js +65 -0
  12. package/commands/icqq/login/definition.ts +72 -0
  13. package/commands/icqq/login/qr/index.js +53 -0
  14. package/commands/icqq/login/qr/index.ts +55 -0
  15. package/commands/icqq/login/retry/index.js +21 -0
  16. package/commands/icqq/login/retry/index.ts +23 -0
  17. package/commands/icqq/login/status/index.js +31 -0
  18. package/commands/icqq/login/status/index.ts +34 -0
  19. package/lib/adapter.d.ts +13 -0
  20. package/lib/adapter.js +27 -0
  21. package/lib/client.d.ts +6 -9
  22. package/lib/client.js +1 -3
  23. package/lib/console-spec.d.ts +17 -0
  24. package/lib/console-spec.js +21 -0
  25. package/lib/console.d.ts +2 -0
  26. package/lib/console.js +13 -0
  27. package/lib/endpoint.d.ts +12 -15
  28. package/lib/endpoint.js +373 -164
  29. package/lib/group-moderation.d.ts +6 -3
  30. package/lib/group-moderation.js +9 -8
  31. package/lib/group-scene.d.ts +3 -3
  32. package/lib/group-scene.js +8 -7
  33. package/lib/icqq-login-assist.d.ts +3 -1
  34. package/lib/icqq-login-assist.js +3 -1
  35. package/lib/icqq-login-control.d.ts +24 -0
  36. package/lib/icqq-login-control.js +25 -0
  37. package/lib/index.d.ts +3 -2
  38. package/lib/index.js +2 -2
  39. package/lib/protocol.d.ts +13 -0
  40. package/lib/protocol.js +24 -9
  41. package/package.json +25 -17
  42. package/pages/index/index.js +15 -0
  43. package/pages/index/index.ts +16 -0
  44. package/plugin.js +3 -5
  45. package/schema.json +174 -0
  46. package/src/adapter.ts +29 -0
  47. package/src/client.ts +6 -11
  48. package/src/console-spec.ts +26 -0
  49. package/src/console.ts +17 -0
  50. package/src/endpoint.ts +381 -178
  51. package/src/group-moderation.ts +10 -10
  52. package/src/group-scene.ts +8 -8
  53. package/src/icqq-login-assist.ts +6 -2
  54. package/src/icqq-login-control.ts +42 -0
  55. package/src/index.ts +4 -1
  56. package/src/protocol.ts +35 -8
  57. package/lib/icqq-runtime-state.d.ts +0 -1
  58. package/lib/icqq-runtime-state.js +0 -6
  59. package/src/icqq-runtime-state.ts +0 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,88 @@
1
1
  # @zhin.js/adapter-icqq
2
2
 
3
+ ## 1.1.19
4
+
5
+ ### Patch Changes
6
+
7
+ - 2c3610a: Move account lifecycle ownership into the generic Adapter base and let native Endpoints retain their SDK Client inheritance. Infer platform-specific operation Sessions from a single adapter registry while preserving command parameter, option, configuration and factory inference.
8
+
9
+ Bind message replies, management ports, login challenges and Agent cancellation to the captured account incarnation. Persist runtime account intent with encrypted, revision-checked Host storage; keep account management independent of Root process restarts. Require explicit operator confirmation before importing existing accounts, and give replacement accounts a new identity without inheriting previous Sessions.
10
+
11
+ Expose account save, start, stop, update and replacement through the existing adapter Console, with exact account ownership, truthful pending/unknown outcomes and no startup configuration or environment-file rewrites.
12
+
13
+ Complete the target migration across every adapter, the public authoring API, generators, examples and Console. This intentionally removes the old create factory, inheritable Endpoint/ClientEndpoint classes, Client descriptors and file-rewrite account management; plugin authors must use createAdapter, native Client inheritance and the single AdapterRegistry. Satori and OneBot12 require explicit platform/userId selection, and WeCom requires a separate agentId.
14
+
15
+ Verify opaque credential changes before the same configuration snapshot is committed. Drain admitted native callbacks across close/rollback, cancel target work on stop, and keep raw transport parsing, platform ACK timing and SDK native methods under their existing owners. Account metadata conceals credentials carried in URLs.
16
+
17
+ - a9f4e48: PATCH COMPATIBILITY CUTOVER: this batch intentionally changes plugin APIs. The maintainer explicitly chose patch releases with declared version boundaries. Upgrade the complete tested dependency set; patch numbering does not promise compatibility with the removed interfaces.
18
+
19
+ The first planned floors are zhin.js 1.1.19, Core 1.1.54, Adapter 1.1.26, FeatureKit 1.1.10, Plugin Runtime 1.1.18, Runtime/Isolate 1.1.16 and Agent 1.1.45. Keep old-interface plugins with the earlier locked stack until they are migrated. Adapter's independent Feature API changes from 1.0.0 to 2.0.0; official consumers declare ^2.0.0. Existing Feature API admission rejects explicitly incompatible ranges; omitted API metadata keeps its existing behavior and does not certify compatibility. Runtime engine and patch-only release gates remain unchanged.
20
+
21
+ Use the native-Client Adapter target contract, canonical FeatureKit AdapterRegistry augmentation and named Endpoint control/management requests. Route message controls from canonical message/conversation refs; retain exact source authority and propagate caller/account/explicit-Root-stop cancellation. Replace removed Agent activity feedback exports with source-bound feedback. HMR pause/resume belongs to concrete plugin instances; plugins choose accepted-work policy without changing Controller commit/rollback authority. Cooperative worker/process control cancellation does not kill an isolate or reopen retired business admission.
22
+
23
+ Provide authenticated historical-data preview, exact selected binding, transactional application, authoritative inspection and explicit resumption, including active games. Preserve before-images and journals; never replay an unconfirmed effect, infer an account from an alias, or reuse historical permission grants. Owner V2 approvals remain inactive legacy data, while new writes use V3. Rollback requires matching software, lockfile and verified data; installing old code alone cannot read a new V3 approval file. Conflicting after-images are never overwritten.
24
+
25
+ See docs/plans/adapter-operation-version-boundaries.md and the Chinese/English upgrade guide for the complete version inventory, custom-plugin changes, acceptance and recovery sequence. These code and metadata changes do not authorize merging, publication, deployment, login, production migration or removal of installed workspace patches.
26
+
27
+ - Updated dependencies [2c3610a]
28
+ - Updated dependencies [a9f4e48]
29
+ - Updated dependencies [f8505b0]
30
+ - @zhin.js/adapter@1.1.26
31
+ - @zhin.js/feature-kit@1.1.10
32
+ - @zhin.js/core@1.1.54
33
+ - @zhin.js/client@1.1.22
34
+ - @zhin.js/page@1.1.11
35
+ - @zhin.js/agent-feature@1.1.11
36
+ - @zhin.js/skill@1.1.11
37
+ - @zhin.js/tool@1.1.13
38
+ - @zhin.js/permission@1.1.10
39
+
40
+ ## 1.1.18
41
+
42
+ ### Patch Changes
43
+
44
+ - 6345a38: feat(adapters): add per-adapter Console pages
45
+
46
+ Every platform adapter now ships a `pages/index` Console page backed by a shared
47
+ `createAdapterConsolePage` component and `createAdapterConsoleRpc` server helper:
48
+
49
+ - See running endpoints, test connectivity, and manage
50
+ `plugins.<adapter>.endpoints` (add/remove writes `.env` references) from the
51
+ Console instead of chat commands.
52
+ - Surface LoginAssist pending tasks (QR / slider / SMS / device) so ICQQ login no
53
+ longer requires the terminal.
54
+ - QQ moves its QR binding flow (`qq endpoint add`) into Console actions with
55
+ public/private selection.
56
+ - Pages are permission-gated by `<adapter>:read`; writes need `<adapter>:write`.
57
+
58
+ - ff3efe7: feat(adapters): notify masters when ICQQ or QQ goes offline and support ICQQ re-login
59
+
60
+ - Add an explicit `notify` target to ICQQ and QQ endpoint config: when the
61
+ transport goes offline or login fails, send a short notice through another
62
+ adapter instance's Endpoint via `OutboundHost`.
63
+ - ICQQ automatically retries login after `system.offline.kickoff` when
64
+ `autoReconnect` is enabled, and exposes pending QR/slider/device challenges.
65
+ - Add `icqq login status|qr|confirm|code|retry` recovery commands. They can be
66
+ invoked from the QQ conversation that received the notice; `qr` returns the
67
+ login QR code as an image when the notifying platform supports it.
68
+ - `notify.id` also counts as the master identity for the related endpoint
69
+ management commands, so recovery can happen from the notified conversation.
70
+ - Document the new config and commands in the ICQQ/QQ READMEs and generated
71
+ configuration reference.
72
+
73
+ - c58c589: Group deferred tools by their canonical plugin or MCP server instead of installation paths. Omit already represented delivered text and ledger facts only from the current model projection, preserving full history and restoring facts when their covering reply leaves the active context. Allow tools to declare a synchronous, read-only availability predicate before turn disclosure, with execution-time checks remaining authoritative.
74
+
75
+ Preserve every confirmed platform message identity across Agent replies and ICQQ split sends. Give each bubble its own stable single-message alias while retaining the reply's ordered association; preserve confirmed prefixes on partial delivery without retrying or inventing unknown message IDs.
76
+
77
+ - Updated dependencies [6345a38]
78
+ - Updated dependencies [ff3efe7]
79
+ - Updated dependencies [c58c589]
80
+ - @zhin.js/adapter@1.1.25
81
+ - @zhin.js/client@1.1.21
82
+ - @zhin.js/core@1.1.53
83
+ - @zhin.js/im-contract@1.1.9
84
+ - @zhin.js/tool@1.1.12
85
+
3
86
  ## 1.1.17
4
87
 
5
88
  ### Patch Changes
package/README.md CHANGED
@@ -5,7 +5,7 @@ ICQQ Plugin Runtime 适配器 — 进程内直接使用 [@icqqjs/icqq](https://g
5
5
  ## 功能特性
6
6
 
7
7
  - 群聊 / 私聊 / 群临时会话 / QQ 频道消息
8
- - 入站:ICQQ Client 原始事件经 `Endpoint.emit(...)` 唯一入口上送;文本与图片 / 语音 / 视频 / 文件统一归一为 canonical `Segment` + `MediaRef`
8
+ - 入站:ICQQ Client 原始事件经 `endpoint[endpointSpec].events` 唯一入口上送;文本与图片 / 语音 / 视频 / 文件统一归一为 canonical `Segment` + `MediaRef`
9
9
  - 出站:canonical Segment 直接投影为 ICQQ 原生 `Sendable`,再由 `sendGroupMsg` / `sendPrivateMsg` / …发送
10
10
  - 群聊 reaction:`control.addReaction` / `removeReaction`(协议 ACK 失败不阻塞后续发送)
11
11
  - Agent 工具:按职责拆分在 `agents/icqq/skills/icqq-*/tools/`,只在对应 Skill 激活后披露
@@ -97,9 +97,9 @@ export default defineHandler({
97
97
  })
98
98
  ```
99
99
 
100
- `client` 就是当前账号的真实 ICQQ SDK 实例,不是 Endpoint facade。未知扩展事件可显式使用
100
+ 原生 Handler 参数中的 `client` 就是当前账号的真实 ICQQ SDK 实例,`event` 保留同一原生事件对象、原型和方法。消息操作的 `session.endpoint`、`session.event` 与 `session.adapter` 分别提供同一个实际 Endpoint、原始消息事件和所属 Adapter。未知扩展事件可显式使用
101
101
  `event: '*'`;此时 Client 类型保持完整,事件 payload 为 `unknown`。普通消息回复仍应走
102
- `Message.$reply`;群管理、请求审批与 ICQQ 专属查询可直接调用当前事件的 `client`。
102
+ `Message.$reply`;群管理、请求审批与 ICQQ 专属查询可直接调用当前 Session 的 Endpoint。
103
103
 
104
104
  Command context 的 `$client` 是按需读取的 getter:
105
105
 
@@ -140,16 +140,16 @@ export default defineAgentTool({
140
140
 
141
141
  `adapter` 缺失时 `$client` 静态类型为 `unknown`;声明后若实际 operation 不属于 ICQQ,
142
142
  运行时会在执行前拒绝。Client 只能在当前 operation 内使用。task、schedule 或 Host 等脱离
143
- IM turn 的场景,才使用 `icqqClient.get(context, endpointId)` 显式选择账号。
143
+ IM turn 的场景,应通过 Host 提供的显式账号作用域操作,不能缓存旧 Client 或从另一个可写目录选择账号。
144
144
 
145
145
  ## 架构
146
146
 
147
147
  - `plugin.ts` + `adapters/icqq/index.ts`:Plugin Runtime 入口与 `defineAdapter` 声明
148
- - `src/endpoint.ts`:组合 ICQQ `Client`,只协调账号 transport、Zhin lifecycle 与各能力端口
148
+ - `src/endpoint.ts`:继承真实 ICQQ `Client`,只协调账号 transport、Zhin lifecycle 与各能力端口
149
149
  - `src/content-resolver.ts`:保存已观察消息,并按深度和条数限制递归展开合并转发
150
150
  - `src/icqq-inbound.ts`:把 ICQQ 原生消息归一为 Zhin 入站消息
151
151
  - `src/protocol.ts`:配置解析、会话映射与出站目标转换
152
- - `src/client.ts`:向插件作者暴露 ICQQ `Client` / `EventMap` 类型注册
152
+ - `src/client.ts`:从原生 SDK 推导事件类型,并将实际 `IcqqAdapter` 注册到唯一 `AdapterRegistry`
153
153
  - Agent 工具:`agents/icqq/skills/icqq-*/tools/<name>/index.ts`;权限说明见 `PERMITS.md`
154
154
 
155
155
  阅读适配器实现时从 `endpoint.ts` 看能力装配,再进入对应能力文件。包外代码只从
@@ -163,7 +163,7 @@ IM turn 的场景,才使用 `icqqClient.get(context, endpointId)` 显式选择
163
163
  - ICQQ 的语音、视频、文件是独立消息元素;它们与其他段混发时适配器会明确拒绝,避免协议栈静默丢段。
164
164
  - 入站语音 / 视频在 Endpoint 持有原生 Client 时解析可下载 URL;解析失败则保留真实平台引用,不伪造或丢弃媒体。
165
165
  - **Console 社交/群管 RPC 已接线**:endpoint 把好友/群/群成员列表、请求审批和群管操作归一化为冻结的 `EndpointManagement`。Host 只消费该语义端口。
166
- - 好友/入群请求与通知:经 the unified `Endpoint.emit(...)` ingress 分发到 `handlers`(`notice.receive` / `request.receive`);审批走 `Request.$approve` / `EndpointManagement.approveRequest`。Console `request.list` 优先读 `management.listRequests()`(`getSystemMsg`),不再写入 `unified_inbox_request/notice`。
166
+ - 好友/入群请求与通知:经 the unified `endpoint[endpointSpec].events` ingress 分发到 `handlers`(`notice.receive` / `request.receive`);审批走 `Request.$approve` / `EndpointManagement.approveRequest`。Console `request.list` 优先读 `management.listRequests()`(`getSystemMsg`),不再写入 `unified_inbox_request/notice`。
167
167
  - `system.*`(登录扫码等)分发到 `system.receive`。
168
168
  - **登录辅助**:`system.login.qrcode|slider|device|auth` 经 `loginAssistToken`(`LoginAssist`)挂起待办;刷新后可用 Console `login.list` / `login.submit` 或终端 stdin 继续(对齐 icqq 官方 stdin 流程)。`system.online` / `login.error` 会清理该 endpoint 待办。
169
169
 
@@ -173,6 +173,51 @@ ICQQ Agent 可按需加载 `icqq-conversation` 查询当前群/频道和 Bot
173
173
 
174
174
  `icqq-group-admin` 新增撤回他人消息与退群:前者保留群管发起权限、实时平台角色检查,无需逐次审批;退群仅主人可发起、每次审批,Bot 为群主时拒绝执行。引用/转发走统一发送链路,不支持跨会话转发。当前 guild-channel 接入仅提供身份查询,不能使用这些群/私聊操作。详见 [权限与能力说明](./PERMITS.md)。
175
175
 
176
+ ## Console 页面
177
+
178
+ 启动后打开 Console 的「ICQQ」页(地址 `/icqq`),可以:
179
+
180
+ - 查看运行中的连接、点「测试连接」做连通性诊断;
181
+ - 在账号库保存、修改、启动、停止、替换或删除该 Adapter 的账号;新增仅保存,不创建 SDK Client,需手动启动;
182
+ - 处理登录待办(扫码 / 滑块 / 设备确认等,来自 LoginAssist);
183
+
184
+ ICQQ 首次登录的二维码、滑块、设备确认会出现在「登录待办」里,不需要再回到终端确认。
185
+
186
+ 读取需要 `icqq:read`,写操作需要 `icqq:write`;管理员 full token 不受限。页面里的「添加 endpoint」等价于原来的 `icqq endpoint add`。
187
+
188
+ 首次修改启动配置里的既有账号前,管理员必须核对清单并确认一次迁移。原 canonical 身份与历史保留,完整账号配置加密进入 Host 数据库;此后账号管理只写数据库,不修改启动文件或 `.env`,不重启进程。没有持久化账号端口的环境可使用静态配置连接,动态写操作明确不可用。
189
+
190
+ 启停意图在进程重启后恢复。停止或删除会取消并关闭目标账号的在途操作,其他账号继续运行;删除保留历史。已启动账号的连接配置更新先关闭旧 incarnation,再仅重连该账号;平台身份变化按替换处理,分配新内部身份、保留旧历史,新账号不继承旧 Session、个人设置或启动意图。提交结果未知时先刷新核实,不自动重复 CAS 或平台操作。
191
+
192
+ ## 掉线通知与重新登录
193
+
194
+ 配置 `notify` 后,ICQQ 被踢下线、登录失败或启动失败时,会通过另一个适配器实例给 master 发通知。例如用 QQ 官方机器人实例通知:
195
+
196
+ ```yaml
197
+ qq:
198
+ # ... 已配置好的 QQ 官方机器人
199
+ icqq:
200
+ master: 123456
201
+ autoReconnect: true # 默认 true:被踢下线后自动重新登录
202
+ notify:
203
+ adapter: qq
204
+ endpoint: bot-1
205
+ kind: private
206
+ id: "${QQ_MASTER_OPENID}" # master 在 QQ 官方机器人里的 openid
207
+ ```
208
+
209
+ `autoReconnect: true` 时,被踢下线会自动重试登录;二维码/滑块/设备确认就绪后,通知会提示下一步。收到通知后可以直接在 QQ 里完成:
210
+
211
+ | 命令 | 作用 |
212
+ |------|------|
213
+ | `icqq login qr` | 把 ICQQ 登录二维码发到当前会话(QQ 支持图片时) |
214
+ | `icqq login confirm` | 扫码后确认继续登录 |
215
+ | `icqq login code <内容>` | 提交滑块 ticket、短信验证码或设备确认内容 |
216
+ | `icqq login status` | 查看在线状态与登录待办 |
217
+ | `icqq login retry` | 强制重新触发登录 |
218
+
219
+ 命令只接受 master(顶层或 `endpoints[i].master`)或 `notify.id` 对应账号;两者都没配置时请用 Console 的 ICQQ 页面。没有配置 `notify` 时,掉线只写日志并在 Console 显示登录待办。
220
+
176
221
  ## 故障排查
177
222
 
178
223
  | 现象 | 排查 |
@@ -190,14 +235,14 @@ MIT
190
235
 
191
236
  发送成功回执只接受平台真实消息 ID。网络超时、断线、缺少消息 ID 的响应会报告 `deliveryUnknown`,框架不会自动重发;手动重发可能重复发送。
192
237
 
193
- ICQQ 原生分享和文件 API 可能已经成功,但只返回空值或文件 ID;这类结果不能当作可引用、可撤回的消息 ID。群聊和私聊的分享卡片发出后,适配器会读一次会话记录,找到机器人自己刚发出的卡片消息,用它的真实消息 ID 作为回执(记录有延迟时半秒后再读一次)。找不到时(以及临时会话、频道和文件)仍报告投递结果未知,不编造 ID。平台操作仍只执行一次。文件撤回应使用平台专用文件 API。
238
+ ICQQ 原生分享和文件 API 可能已经成功,但只返回空值或文件 ID;这类结果不能当作可引用、可撤回的消息 ID。适配器不会根据时间和卡片类型从历史猜测本次分享的 ID;同一时刻的其他卡片也可能匹配。没有直接消息 ID 的部分保留为未知,平台操作仍只执行一次。文件撤回应使用平台专用文件 API。
194
239
 
195
240
  ### 独立元素按顺序拆分发送
196
241
 
197
242
  ICQQ 要求分享、文件、语音、视频、JSON 卡片和合并转发单独成条。一条消息里同时有文字和这些元素时(例如 Agent 回复“找到了:”加一张音乐分享卡片),适配器按原顺序拆成多条依次发送,引用只附在第一条普通消息上。
198
243
 
199
- - 回执的消息 ID 取第一条拿到 ID 的部分;所有部分都没有 ID(如单独一张分享)时,仍报告投递结果未知。
200
- - 第一条就失败时原样报告失败;后面的部分失败时报告 `partial_delivery`(结果未知),因为前面的部分已经送达,重发会重复。
244
+ - 回执按发送顺序保留每部分的真实 ID 和原始段位置;没有 ID 的卡片或文件保留未知槽位,不把完整回复正文复制给每个 ID。所有部分都没有 ID(如单独一张分享)时,仍报告投递结果未知。
245
+ - 第一条就失败时原样报告失败;后面的部分失败时报告 `partial_delivery`(结果未知),保留已完成部分的回执。前面的调用可能已被平台接收,重发可能重复。
201
246
 
202
247
  ## 语言
203
248
 
@@ -1,13 +1,10 @@
1
1
  // Generated by build-plugin-runtime-entries.mjs. Do not edit.
2
- import { projectLocaleToken } from 'zhin.js/i18n';
2
+ import { IcqqAdapter } from "../../lib/adapter.js";
3
3
  /**
4
4
  * Convention entry: discover `adapters/icqq/index.ts` → defineAdapter.
5
5
  */
6
6
  import { defineAdapter } from 'zhin.js/adapter';
7
- import { loginAssistToken } from '@zhin.js/core/runtime';
8
- import { IcqqEndpoint } from "../../lib/endpoint.js";
9
- import { icqqRuntimeStateToken } from "../../lib/icqq-runtime-state.js";
10
- import { resolveIcqqConfig, } from "../../lib/protocol.js";
7
+ import {} from "../../lib/protocol.js";
11
8
  export { IcqqEndpoint } from "../../lib/endpoint.js";
12
9
  export default defineAdapter({
13
10
  capabilities: ['inbound', 'outbound'],
@@ -37,18 +34,5 @@ export default defineAdapter({
37
34
  },
38
35
  },
39
36
  },
40
- create(context) {
41
- const config = resolveIcqqConfig(context.config);
42
- // 注册到插件运行时状态(icqq endpoint list 的"运行中"数据源)
43
- context.use(icqqRuntimeStateToken).endpoints.set(config.id, {
44
- id: config.id,
45
- mode: 'direct',
46
- });
47
- return new IcqqEndpoint({
48
- id: context.id,
49
- loginAssist: context.use(loginAssistToken),
50
- locale: context.use(projectLocaleToken),
51
- config,
52
- });
53
- },
37
+ createAdapter: context => new IcqqAdapter(context),
54
38
  });
@@ -1,25 +1,15 @@
1
- import { projectLocaleToken } from 'zhin.js/i18n';
1
+ import { IcqqAdapter } from '../../src/adapter.js';
2
2
  /**
3
3
  * Convention entry: discover `adapters/icqq/index.ts` → defineAdapter.
4
4
  */
5
5
  import { defineAdapter } from 'zhin.js/adapter';
6
- import { loginAssistToken } from '@zhin.js/core/runtime';
7
- import { IcqqEndpoint } from '../../src/endpoint.js';
8
- import { icqqRuntimeStateToken } from '../../src/icqq-runtime-state.js';
9
6
  import {
10
- resolveIcqqConfig,
11
7
  type IcqqEndpointConfig,
12
8
  } from '../../src/protocol.js';
13
9
 
14
10
  export { IcqqEndpoint } from '../../src/endpoint.js';
15
11
  export type { IcqqEndpointOptions } from '../../src/endpoint.js';
16
12
 
17
- declare module '@zhin.js/core' {
18
- interface AdapterEndpoints {
19
- icqq: import('../../src/endpoint.js').IcqqEndpoint;
20
- }
21
- }
22
-
23
13
  export default defineAdapter<IcqqEndpointConfig>({
24
14
  capabilities: ['inbound', 'outbound'],
25
15
  operations: ['recall', 'reaction'],
@@ -48,18 +38,5 @@ export default defineAdapter<IcqqEndpointConfig>({
48
38
  },
49
39
  },
50
40
  },
51
- create(context) {
52
- const config = resolveIcqqConfig(context.config);
53
- // 注册到插件运行时状态(icqq endpoint list 的"运行中"数据源)
54
- context.use(icqqRuntimeStateToken).endpoints.set(config.id, {
55
- id: config.id,
56
- mode: 'direct',
57
- });
58
- return new IcqqEndpoint({
59
- id: context.id,
60
- loginAssist: context.use(loginAssistToken),
61
- locale: context.use(projectLocaleToken),
62
- config,
63
- });
64
- },
41
+ createAdapter: context => new IcqqAdapter(context),
65
42
  });
@@ -1,33 +1,11 @@
1
1
  // Generated by build-plugin-runtime-entries.mjs. Do not edit.
2
2
  import { messages as t } from "../../../lib/i18n.js";
3
- import { createEndpointCommands, endpointConfigurationStoreToken } from 'zhin.js/adapter';
3
+ import { createEndpointCommands } from 'zhin.js/adapter';
4
4
  import { defineCommand } from 'zhin.js/command';
5
- import { icqqRuntimeStateToken } from "../../../lib/icqq-runtime-state.js";
6
5
  export const icqqEndpointCommands = createEndpointCommands({
7
6
  adapterKey: 'icqq',
8
7
  adapterDisplayName: 'ICQQ',
9
- running: (use) => use(icqqRuntimeStateToken).endpoints.values(),
10
8
  describeEntry: (_entry, locale) => t(locale, 'direct'),
11
- addDescription: '登记 ICQQ endpoint(重启 zhin 生效)',
12
- addDescriptionI18n: { en: 'Register an ICQQ endpoint; restart zhin to apply' },
13
- bindFlow: async ({ id, use, locale, formatCommand }) => {
14
- if (!id) {
15
- const command = formatCommand?.('icqq endpoint add');
16
- return command ? t(locale, 'addUsage', { command }) : t(locale, 'uinRequired');
17
- }
18
- if (!/^\d+$/.test(id)) {
19
- return t(locale, 'uinInvalid');
20
- }
21
- try {
22
- const { filePath } = await use(endpointConfigurationStoreToken).add({
23
- adapterKey: 'icqq',
24
- entry: { id },
25
- environment: {},
26
- });
27
- return t(locale, 'endpointAdded', { id, file: filePath });
28
- }
29
- catch (error) {
30
- return t(locale, 'endpointAddFailed', { error: error instanceof Error ? error.message : String(error) });
31
- }
32
- },
9
+ addDescription: '保存 ICQQ 账号;保存后需手动启动',
10
+ addDescriptionI18n: { en: 'Save an ICQQ account; start it explicitly after saving' },
33
11
  }, defineCommand);
@@ -1,32 +1,11 @@
1
1
  import { messages as t } from '../../../src/i18n.js';
2
- import { createEndpointCommands, endpointConfigurationStoreToken } from 'zhin.js/adapter';
2
+ import { createEndpointCommands } from 'zhin.js/adapter';
3
3
  import { defineCommand } from 'zhin.js/command';
4
- import { icqqRuntimeStateToken } from '../../../src/icqq-runtime-state.js';
5
4
 
6
5
  export const icqqEndpointCommands = createEndpointCommands({
7
6
  adapterKey: 'icqq',
8
7
  adapterDisplayName: 'ICQQ',
9
- running: (use) => use(icqqRuntimeStateToken).endpoints.values(),
10
8
  describeEntry: (_entry, locale) => t(locale, 'direct'),
11
- addDescription: '登记 ICQQ endpoint(重启 zhin 生效)',
12
- addDescriptionI18n: { en: 'Register an ICQQ endpoint; restart zhin to apply' },
13
- bindFlow: async ({ id, use, locale, formatCommand }) => {
14
- if (!id) {
15
- const command = formatCommand?.('icqq endpoint add');
16
- return command ? t(locale, 'addUsage', { command }) : t(locale, 'uinRequired');
17
- }
18
- if (!/^\d+$/.test(id)) {
19
- return t(locale, 'uinInvalid');
20
- }
21
- try {
22
- const { filePath } = await use(endpointConfigurationStoreToken).add({
23
- adapterKey: 'icqq',
24
- entry: { id },
25
- environment: {},
26
- });
27
- return t(locale, 'endpointAdded', { id, file: filePath });
28
- } catch (error) {
29
- return t(locale, 'endpointAddFailed', { error: error instanceof Error ? error.message : String(error) });
30
- }
31
- },
9
+ addDescription: '保存 ICQQ 账号;保存后需手动启动',
10
+ addDescriptionI18n: { en: 'Save an ICQQ account; start it explicitly after saving' },
32
11
  }, defineCommand);
@@ -0,0 +1,28 @@
1
+ // Generated by build-plugin-runtime-entries.mjs. Do not edit.
2
+ import { defineCommand } from 'zhin.js/command';
3
+ import { icqqLoginControls, icqqLoginForbidden, isIcqqLoginOperator, pendingTaskLabel, pickIcqqLoginControl, } from '../definition.js';
4
+ export default defineCommand({
5
+ description: '提交 ICQQ 滑块/短信/设备验证内容',
6
+ descriptionI18n: { en: 'Submit an ICQQ slider, SMS or device verification value' },
7
+ async execute({ args, config, input, project, owner }) {
8
+ if (!isIcqqLoginOperator(config, input))
9
+ return icqqLoginForbidden();
10
+ const controls = icqqLoginControls({ project, owner });
11
+ // One endpoint: the whole argument is the code. Multiple: first arg selects the UIN.
12
+ const requested = controls.size > 1 ? args[0] : undefined;
13
+ const value = (controls.size > 1 ? args.slice(1) : args).join(' ').trim();
14
+ const picked = pickIcqqLoginControl(controls, requested);
15
+ if (!picked.control)
16
+ return picked.text ?? 'ICQQ 适配器还没有启动';
17
+ if (!value) {
18
+ return '请把验证内容放在命令后面,例如 `icqq login code 123456` 或 `icqq login code <ticket>`。';
19
+ }
20
+ const task = picked.control.pending()
21
+ .find((item) => item.type === 'slider' || item.type === 'device' || item.type === 'sms' || item.type === 'other');
22
+ if (!task)
23
+ return '当前没有滑块/短信/设备验证待办;发送 `icqq login qr` 查看二维码。';
24
+ if (!picked.control.submit(task.id, value))
25
+ return '登录待办已失效,请重新触发 `icqq login qr`。';
26
+ return `已提交 ICQQ ${task.endpointKey} 的${pendingTaskLabel(task.type)}内容,正在验证。`;
27
+ },
28
+ });
@@ -0,0 +1,30 @@
1
+ import { defineCommand } from 'zhin.js/command';
2
+ import {
3
+ icqqLoginControls,
4
+ icqqLoginForbidden,
5
+ isIcqqLoginOperator,
6
+ pendingTaskLabel,
7
+ pickIcqqLoginControl,
8
+ } from '../definition.js';
9
+
10
+ export default defineCommand({
11
+ description: '提交 ICQQ 滑块/短信/设备验证内容',
12
+ descriptionI18n: { en: 'Submit an ICQQ slider, SMS or device verification value' },
13
+ async execute({ args, config, input, project, owner }) {
14
+ if (!isIcqqLoginOperator(config, input)) return icqqLoginForbidden();
15
+ const controls = icqqLoginControls({ project, owner });
16
+ // One endpoint: the whole argument is the code. Multiple: first arg selects the UIN.
17
+ const requested = controls.size > 1 ? args[0] : undefined;
18
+ const value = (controls.size > 1 ? args.slice(1) : args).join(' ').trim();
19
+ const picked = pickIcqqLoginControl(controls, requested);
20
+ if (!picked.control) return picked.text ?? 'ICQQ 适配器还没有启动';
21
+ if (!value) {
22
+ return '请把验证内容放在命令后面,例如 `icqq login code 123456` 或 `icqq login code <ticket>`。';
23
+ }
24
+ const task = picked.control.pending()
25
+ .find((item) => item.type === 'slider' || item.type === 'device' || item.type === 'sms' || item.type === 'other');
26
+ if (!task) return '当前没有滑块/短信/设备验证待办;发送 `icqq login qr` 查看二维码。';
27
+ if (!picked.control.submit(task.id, value)) return '登录待办已失效,请重新触发 `icqq login qr`。';
28
+ return `已提交 ICQQ ${task.endpointKey} 的${pendingTaskLabel(task.type)}内容,正在验证。`;
29
+ },
30
+ });
@@ -0,0 +1,20 @@
1
+ // Generated by build-plugin-runtime-entries.mjs. Do not edit.
2
+ import { defineCommand } from 'zhin.js/command';
3
+ import { icqqLoginControls, icqqLoginForbidden, isIcqqLoginOperator, pickIcqqLoginControl, } from '../definition.js';
4
+ export default defineCommand({
5
+ description: '确认已完成 ICQQ 扫码登录',
6
+ descriptionI18n: { en: 'Confirm the ICQQ QR login was scanned' },
7
+ async execute({ args, config, input, project, owner }) {
8
+ if (!isIcqqLoginOperator(config, input))
9
+ return icqqLoginForbidden();
10
+ const picked = pickIcqqLoginControl(icqqLoginControls({ project, owner }), args[0]);
11
+ if (!picked.control)
12
+ return picked.text ?? 'ICQQ 适配器还没有启动';
13
+ const task = picked.control.pending().find((item) => item.type === 'qrcode' || item.type === 'auth');
14
+ if (!task)
15
+ return '当前没有等待确认的扫码登录;发送 `icqq login qr` 获取二维码。';
16
+ if (!picked.control.submit(task.id, 'ok'))
17
+ return '登录待办已失效,请重新发送 `icqq login qr`。';
18
+ return `已提交 ICQQ ${task.endpointKey} 的扫码确认,正在登录。`;
19
+ },
20
+ });
@@ -0,0 +1,21 @@
1
+ import { defineCommand } from 'zhin.js/command';
2
+ import {
3
+ icqqLoginControls,
4
+ icqqLoginForbidden,
5
+ isIcqqLoginOperator,
6
+ pickIcqqLoginControl,
7
+ } from '../definition.js';
8
+
9
+ export default defineCommand({
10
+ description: '确认已完成 ICQQ 扫码登录',
11
+ descriptionI18n: { en: 'Confirm the ICQQ QR login was scanned' },
12
+ async execute({ args, config, input, project, owner }) {
13
+ if (!isIcqqLoginOperator(config, input)) return icqqLoginForbidden();
14
+ const picked = pickIcqqLoginControl(icqqLoginControls({ project, owner }), args[0]);
15
+ if (!picked.control) return picked.text ?? 'ICQQ 适配器还没有启动';
16
+ const task = picked.control.pending().find((item) => item.type === 'qrcode' || item.type === 'auth');
17
+ if (!task) return '当前没有等待确认的扫码登录;发送 `icqq login qr` 获取二维码。';
18
+ if (!picked.control.submit(task.id, 'ok')) return '登录待办已失效,请重新发送 `icqq login qr`。';
19
+ return `已提交 ICQQ ${task.endpointKey} 的扫码确认,正在登录。`;
20
+ },
21
+ });
@@ -0,0 +1,65 @@
1
+ // Generated by build-plugin-runtime-entries.mjs. Do not edit.
2
+ /**
3
+ * `icqq login` recovery commands.
4
+ *
5
+ * They are registered by the ICQQ plugin but can be invoked from any connected
6
+ * adapter (typically the QQ instance that delivered the outage notice), so the
7
+ * master can fetch the QR image and confirm/send verification codes without the
8
+ * Console or terminal.
9
+ */
10
+ import { icqqLoginControls } from "../../../lib/icqq-login-control.js";
11
+ export { icqqLoginControls };
12
+ /** Master = framework master(s), or the configured outage-notify conversation id(s). */
13
+ export function isIcqqLoginOperator(config, input) {
14
+ const cfg = (config ?? {});
15
+ const masters = new Set();
16
+ const collect = (value) => {
17
+ if (value === undefined || value === null)
18
+ return;
19
+ const text = String(value).trim();
20
+ if (text)
21
+ masters.add(text);
22
+ };
23
+ collect(cfg.master);
24
+ collect(cfg.notify?.id);
25
+ if (Array.isArray(cfg.endpoints)) {
26
+ for (const endpoint of cfg.endpoints) {
27
+ collect(endpoint.master);
28
+ collect(endpoint.notify?.id);
29
+ }
30
+ }
31
+ // Login control is account-sensitive: without an explicit master/notify target,
32
+ // refuse chat recovery and leave it to the authenticated Console page.
33
+ if (masters.size === 0)
34
+ return false;
35
+ const senderRaw = input?.sender;
36
+ const senderId = (typeof senderRaw === 'object' && senderRaw?.id) ? String(senderRaw.id).trim() : '';
37
+ return senderId !== '' && masters.has(senderId);
38
+ }
39
+ export function pickIcqqLoginControl(controls, requested) {
40
+ const wanted = requested?.trim();
41
+ if (wanted) {
42
+ const control = controls.get(wanted);
43
+ return control ? { control } : { text: `找不到 ICQQ endpoint「${wanted}」` };
44
+ }
45
+ if (controls.size === 0)
46
+ return { text: 'ICQQ 适配器还没有启动' };
47
+ if (controls.size === 1) {
48
+ const control = [...controls.values()][0];
49
+ return control ? { control } : { text: 'ICQQ 适配器还没有启动' };
50
+ }
51
+ return { text: `有多个 ICQQ endpoint,请指定 QQ 号:${[...controls.keys()].join('、')}` };
52
+ }
53
+ export function icqqLoginForbidden() {
54
+ return '仅 master 或 notify 目标账号可以操作 ICQQ 登录';
55
+ }
56
+ export function pendingTaskLabel(type) {
57
+ switch (type) {
58
+ case 'qrcode': return '二维码';
59
+ case 'slider': return '滑块验证';
60
+ case 'device': return '设备确认';
61
+ case 'sms': return '短信验证';
62
+ case 'auth': return '登录确认';
63
+ default: return '登录验证';
64
+ }
65
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * `icqq login` recovery commands.
3
+ *
4
+ * They are registered by the ICQQ plugin but can be invoked from any connected
5
+ * adapter (typically the QQ instance that delivered the outage notice), so the
6
+ * master can fetch the QR image and confirm/send verification codes without the
7
+ * Console or terminal.
8
+ */
9
+ import { icqqLoginControls, type IcqqLoginControl } from '../../../src/icqq-login-control.js';
10
+
11
+ export { icqqLoginControls };
12
+
13
+ /** Master = framework master(s), or the configured outage-notify conversation id(s). */
14
+ export function isIcqqLoginOperator(config: unknown, input: unknown): boolean {
15
+ const cfg = (config ?? {}) as {
16
+ master?: unknown;
17
+ notify?: { id?: unknown };
18
+ endpoints?: readonly { master?: unknown; notify?: { id?: unknown } }[];
19
+ };
20
+ const masters = new Set<string>();
21
+ const collect = (value: unknown) => {
22
+ if (value === undefined || value === null) return;
23
+ const text = String(value).trim();
24
+ if (text) masters.add(text);
25
+ };
26
+ collect(cfg.master);
27
+ collect(cfg.notify?.id);
28
+ if (Array.isArray(cfg.endpoints)) {
29
+ for (const endpoint of cfg.endpoints) {
30
+ collect(endpoint.master);
31
+ collect(endpoint.notify?.id);
32
+ }
33
+ }
34
+ // Login control is account-sensitive: without an explicit master/notify target,
35
+ // refuse chat recovery and leave it to the authenticated Console page.
36
+ if (masters.size === 0) return false;
37
+ const senderRaw = (input as { sender?: { id?: unknown } } | null | undefined)?.sender;
38
+ const senderId = (typeof senderRaw === 'object' && senderRaw?.id) ? String(senderRaw.id).trim() : '';
39
+ return senderId !== '' && masters.has(senderId);
40
+ }
41
+
42
+ export function pickIcqqLoginControl(
43
+ controls: ReadonlyMap<string, IcqqLoginControl>,
44
+ requested?: string,
45
+ ): { control?: IcqqLoginControl; text?: string } {
46
+ const wanted = requested?.trim();
47
+ if (wanted) {
48
+ const control = controls.get(wanted);
49
+ return control ? { control } : { text: `找不到 ICQQ endpoint「${wanted}」` };
50
+ }
51
+ if (controls.size === 0) return { text: 'ICQQ 适配器还没有启动' };
52
+ if (controls.size === 1) {
53
+ const control = [...controls.values()][0];
54
+ return control ? { control } : { text: 'ICQQ 适配器还没有启动' };
55
+ }
56
+ return { text: `有多个 ICQQ endpoint,请指定 QQ 号:${[...controls.keys()].join('、')}` };
57
+ }
58
+
59
+ export function icqqLoginForbidden(): string {
60
+ return '仅 master 或 notify 目标账号可以操作 ICQQ 登录';
61
+ }
62
+
63
+ export function pendingTaskLabel(type: string): string {
64
+ switch (type) {
65
+ case 'qrcode': return '二维码';
66
+ case 'slider': return '滑块验证';
67
+ case 'device': return '设备确认';
68
+ case 'sms': return '短信验证';
69
+ case 'auth': return '登录确认';
70
+ default: return '登录验证';
71
+ }
72
+ }