dsh-qqchat 0.2.0 → 0.2.2
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/README.en.md +25 -15
- package/README.md +22 -11
- package/client-src/settings.cts +32 -2
- package/docs/ARCHITECTURE.en.md +5 -2
- package/docs/ARCHITECTURE.md +3 -8
- package/docs/MEDIA_AND_QUOTES.md +11 -12
- package/docs/SECURITY.md +1 -1
- package/docs/STREAMING.md +22 -19
- package/docs/assets//346/211/253/347/240/201/351/223/276/346/216/245.jpg +0 -0
- package/docs/assets//350/256/276/347/275/256/347/225/214/351/235/242.jpg +0 -0
- package/lib/client.js +26 -3
- package/lib/gateway/api.d.ts +1 -1
- package/lib/gateway/api.js +5 -1
- package/lib/gateway/gateway.js +5 -1
- package/lib/session/agent-bridge.d.ts +4 -2
- package/lib/session/agent-bridge.js +74 -22
- package/lib/session/runtime.d.ts +1 -0
- package/lib/session/runtime.js +26 -0
- package/lib/shared/augmentations.d.ts +0 -4
- package/lib/transport/rpc.js +5 -0
- package/package.json +3 -1
- package/src/gateway/api.ts +5 -1
- package/src/gateway/gateway.ts +5 -1
- package/src/session/agent-bridge.ts +73 -23
- package/src/session/runtime.ts +24 -0
- package/src/shared/augmentations.ts +0 -4
- package/src/transport/rpc.ts +9 -0
package/README.en.md
CHANGED
|
@@ -31,16 +31,18 @@
|
|
|
31
31
|
| --- | --- | --- |
|
|
32
32
|
| QQ group and direct chat | Receives group and C2C messages | One isolated DSH Session per group or direct peer |
|
|
33
33
|
| QR connection | Binds an official QQ Bot from **Settings -> QQ Chat** | Cancel the binding and scan again when needed |
|
|
34
|
+
| Manual connection | Connects with AppID and AppSecret from the settings page | Useful for headless servers or QR failures; the secret is sent only to the Host |
|
|
34
35
|
| Group receive modes | Auto reply, Mention only or Silent record | Silent record stores messages without waking the Agent |
|
|
35
36
|
| Message formats | Smart, Markdown or Plain compatibility | Group and direct-chat formats are configured separately; groups default to Plain compatibility |
|
|
36
37
|
| Direct-chat streaming | Optionally uses QQ's official streaming message API for private chats | Private chats only; Plain compatibility disables it automatically; some clients may not display streaming |
|
|
37
38
|
| Quotes and mentions | Preserves quoted messages and resolves QQ mentions to display names | Stable IDs remain in metadata |
|
|
38
|
-
| Memory system | Stores group, member and direct-user memory
|
|
39
|
+
| Memory system | Stores group, member and direct-user memory; user memory can be reused across groups under the same Bot | Group relationships and group events stay scoped; can be disabled |
|
|
39
40
|
| Memory reflection | Converts recent daily notes into long-term memory | Runs asynchronously after idle or batch thresholds |
|
|
40
41
|
| Media and file permissions | Separately controls receiving media, reading attachments, and regular tools | Owner and direct chats are unrestricted by default |
|
|
41
|
-
|
|
|
42
|
+
| Permission management | Separately controls group-member tools, media reading and file receiving | Owner is matched by stable user ID |
|
|
42
43
|
| Native DSH commands | Runs `/compact`, `/goal`, `/plan`, `/qqmodel`, `/qqstatus` and more directly from QQ | Commands do not go through the model; `/qqhelp` lists the full set |
|
|
43
44
|
| Native DSH UI | Uses the normal Session list, Conversation surface and composer styling | QQ Sessions remain ungrouped in DSH |
|
|
45
|
+
| Session presets | Each QQ Session can use DSH's native Agent Preset mechanism | The plugin default applies only to new Sessions; a Session's own selection is persisted |
|
|
44
46
|
| Diagnostics | Shows plugin logs in Settings | Useful for connection and delivery troubleshooting |
|
|
45
47
|
|
|
46
48
|
## How to use
|
|
@@ -67,7 +69,7 @@
|
|
|
67
69
|
<td width="50%" valign="top">
|
|
68
70
|
<img src="./docs/assets/记忆系统.jpg" width="100%" alt="QQ Chat memory system">
|
|
69
71
|
<h3>Memory system</h3>
|
|
70
|
-
<p>The plugin maintains separate memory for groups, members and direct users. Member memory supports profiles, group nicknames, historical nicknames, behavior patterns and long-term notes; recent messages are organized asynchronously. Memory is refreshed as Session context when needed, and can be disabled without deleting stored data.</p>
|
|
72
|
+
<p>The plugin maintains separate memory for groups, members and direct users. Under the same Bot, user memory is reusable across groups by stable user ID; group relationships and group events remain scoped to their original group. Member memory supports profiles, group nicknames, historical nicknames, behavior patterns and long-term notes; recent messages are organized asynchronously. Memory is refreshed as Session context when needed, and can be disabled without deleting stored data.</p>
|
|
71
73
|
</td>
|
|
72
74
|
</tr>
|
|
73
75
|
</table>
|
|
@@ -80,6 +82,8 @@
|
|
|
80
82
|
4. Authorize the desired official Bot.
|
|
81
83
|
5. The Gateway starts automatically. Use **Cancel connection** before scanning again if you need to bind another Bot.
|
|
82
84
|
|
|
85
|
+
If QR authorization is inconvenient, choose **Manual configuration** and enter the AppID and AppSecret from the QQ Open Platform. Select the sandbox environment when needed. The plugin validates the credentials before saving them and starting the Gateway.
|
|
86
|
+
|
|
83
87
|
The Host decrypts and stores the AppSecret in the local plugin database. The temporary QR AES key never travels through the browser Client RPC.
|
|
84
88
|
|
|
85
89
|
### Chat in QQ
|
|
@@ -115,7 +119,7 @@ npx @deepseek-ai/dsh --profile web
|
|
|
115
119
|
Before npm publication, install the branch directly from GitHub:
|
|
116
120
|
|
|
117
121
|
```bash
|
|
118
|
-
npx @deepseek-ai/dsh plugin --profile qqchat add @deepseek-ai/dsh-web-app
|
|
122
|
+
npx @deepseek-ai/dsh plugin --profile qqchat add @deepseek-ai/dsh-web-app dsh-qqchat
|
|
119
123
|
npx @deepseek-ai/dsh --profile qqchat
|
|
120
124
|
```
|
|
121
125
|
|
|
@@ -142,7 +146,7 @@ Groups default to Plain compatibility format. Group and direct-chat formats can
|
|
|
142
146
|
|
|
143
147
|
## Commands
|
|
144
148
|
|
|
145
|
-
Messages beginning with `/` are handled directly by the command system and are not sent to the model. Native DSH commands keep their original names; QQChat commands use the `qq` prefix. In a group, write `@Bot /
|
|
149
|
+
Messages beginning with `/` are handled directly by the command system and are not sent to the model. Native DSH commands keep their original names; QQChat commands use the `qq` prefix. In a group, write `@Bot /qqhelp`.
|
|
146
150
|
|
|
147
151
|
| Command | Purpose |
|
|
148
152
|
| --- | --- |
|
|
@@ -150,6 +154,7 @@ Messages beginning with `/` are handled directly by the command system and are n
|
|
|
150
154
|
| `/qqnew`, `/qqreset`, `/qqclear` | Keep the old Session and start a new one on the next message |
|
|
151
155
|
| `/compact` | Compact older conversation history |
|
|
152
156
|
| `/qqmodel [provider/]model` | Show or switch the current Session model |
|
|
157
|
+
| `/qqpreset [preset]` | List or switch the Agent Preset for the current blank Session; start a new Session after conversation begins |
|
|
153
158
|
| `/qqstop` | Stop the current generation |
|
|
154
159
|
| `/qqstatus` | Show Session, model and generation status |
|
|
155
160
|
| `/qqping` | Check QQChat connectivity |
|
|
@@ -185,11 +190,15 @@ QQ Chat stores:
|
|
|
185
190
|
|
|
186
191
|
Reflection runs asynchronously after the chat is idle or enough messages have accumulated. The **QQ Memory** action at the top of a QQ Session shows group and member memory. Memory snapshots refresh when a Session starts, the memory context expires, or the Session is compacted; continuous conversation does not repeatedly write the full memory. Enabled memory may reduce context-cache hit rate or increase input tokens, and can be disabled under **Settings -> QQ Chat -> Memory system** without deleting stored data.
|
|
187
192
|
|
|
188
|
-
##
|
|
193
|
+
## Permission management
|
|
189
194
|
|
|
190
|
-
|
|
195
|
+
The settings page keeps media/file permissions separate from regular Agent-tool permissions:
|
|
191
196
|
|
|
192
|
-
|
|
197
|
+
- **Receive group-member media/files** controls whether images, files, audio and video are downloaded, stored and shown in the Session.
|
|
198
|
+
- **Allow group members to read media/files** controls whether a group member's Agent turn may call QQChat media tools for the current attachment.
|
|
199
|
+
- **Group members can use tools** controls whether group members may use regular Agent tools exposed by the current preset.
|
|
200
|
+
|
|
201
|
+
When regular tools or media reading are disabled, group members can still send normal text and receive replies. Owner matching uses a stable QQ user ID, not a nickname.
|
|
193
202
|
|
|
194
203
|
## Message display
|
|
195
204
|
|
|
@@ -201,10 +210,14 @@ QQ conversations use DSH's default Conversation UI:
|
|
|
201
210
|
- QQ `@` mentions are converted to usernames when available.
|
|
202
211
|
- The DSH Session composer can proactively send messages to QQ.
|
|
203
212
|
|
|
213
|
+
## Session presets
|
|
214
|
+
|
|
215
|
+
QQ Sessions use DSH's native Agent Preset mechanism. The preset configured for the plugin is only the default for new QQ Sessions. When a preset is selected for a blank Session in DSH Web, the selection is persisted with that Session and takes priority when the Session is resumed after a restart. You can also send `/qqpreset <preset>` as the first QQ message for that Session. Once a conversation has started, DSH locks the preset; use `/qqnew` to start another Session. The plugin does not copy DSH presets, tools or the AgentLoop.
|
|
216
|
+
|
|
204
217
|
## Notes
|
|
205
218
|
|
|
206
219
|
- An official QQ Bot is required; personal QQ account login is not supported.
|
|
207
|
-
- `0.2.
|
|
220
|
+
- `0.2.1` is still being refined; test with a dedicated Bot and group first.
|
|
208
221
|
- Rich media, full QQ emoji handling and some complex message formats may require compatibility mode.
|
|
209
222
|
- Uninstalling the plugin does not automatically delete saved chat or memory data.
|
|
210
223
|
|
|
@@ -217,15 +230,12 @@ QR authorization and connection
|
|
|
217
230
|
Group receive mode
|
|
218
231
|
Group and direct-chat reply formats
|
|
219
232
|
Memory system [on/off]
|
|
220
|
-
Media and file permissions and regular tool permissions are independent settings:
|
|
221
|
-
|
|
222
|
-
- **Receive group-member media/files** controls whether images, files, audio, and video are downloaded, stored, and shown in the session.
|
|
223
|
-
- **Allow group members to read media/files** controls whether their Agent turns may call QQChat media tools for the current attachment.
|
|
224
|
-
- **Group members can use tools** controls access to regular Agent tools.
|
|
225
233
|
Owner stable ID
|
|
226
234
|
Diagnostics and logs
|
|
227
235
|
```
|
|
228
236
|
|
|
237
|
+
Media/file permissions and regular tool permissions are independent settings. See [Permission management](#permission-management) for their behavior.
|
|
238
|
+
|
|
229
239
|
The Settings page does not contain chat lists, transcripts or memory browsing. Those remain in the normal DSH Session and Conversation surfaces.
|
|
230
240
|
|
|
231
241
|
## Persistence and memory scopes
|
|
@@ -244,7 +254,7 @@ Memory scopes are isolated as follows:
|
|
|
244
254
|
- **Member:** typed profile, pattern, summary, daily and long-term memory for one stable sender.
|
|
245
255
|
- **Direct chat:** uses the member scope for that QQ user.
|
|
246
256
|
|
|
247
|
-
The same stable sender may retain
|
|
257
|
+
The same stable sender may retain user memory across groups under the same Bot. Group relationships and group-specific facts never cross group scopes, and different Bots keep separate user-memory scopes. Reflection runs after roughly 120 seconds of inactivity or 20 unreflected messages, and can also compress older daily records after the configured thresholds.
|
|
248
258
|
|
|
249
259
|
## Development
|
|
250
260
|
|
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
<a href="./docs/ARCHITECTURE.md">架构说明</a>
|
|
17
17
|
</p>
|
|
18
18
|
|
|
19
|
-
<p><em>dsh-qqchat 是 DeepSeek Harness(DSH)的 QQ
|
|
19
|
+
<p><em>dsh-qqchat 是 DeepSeek Harness(DSH)的 QQ Bot 插件,支持 QQ 群聊、私聊、会话隔离、记忆系统和 DSH 原生命令。</em></p>
|
|
20
20
|
|
|
21
21
|
> 本项目是一个 Vibe Coding 项目,代码质量和工程完整性可能需要改进。如果你发现问题或有更好的实现建议,欢迎提交 [Issue](https://github.com/Coffeiz/dsh-qqchat/issues) 或 [Pull Request](https://github.com/Coffeiz/dsh-qqchat/pulls)。
|
|
22
22
|
|
|
@@ -26,20 +26,22 @@
|
|
|
26
26
|
|
|
27
27
|
| 功能 | 说明 | 备注 |
|
|
28
28
|
| --- | --- | --- |
|
|
29
|
-
| QQ 群聊与私聊 | 接收 QQ
|
|
29
|
+
| QQ 群聊与私聊 | 接收 QQ Bot 的群聊和私聊消息 | 每个群、每个私聊对象对应独立 DSH 会话 |
|
|
30
30
|
| 扫码连接 | 在 **设置 → QQ Chat** 中扫码绑定 QQ Bot | 支持取消连接后重新绑定 |
|
|
31
|
+
| 手动连接 | 在设置页填写 AppID 和 AppSecret 连接 QQ Bot | 适合无手机、服务器或扫码失败场景;密钥只提交到 Host |
|
|
31
32
|
| 断线重连 | QQ Gateway 断线后自动恢复连接 | 无需重复扫码 |
|
|
32
33
|
| 群聊回复模式 | 自动回应、@回复、静默记录 | 可在设置页随时切换 |
|
|
33
|
-
| 消息格式兼容 | 智能兼容、Markdown、纯文本兼容 |
|
|
34
|
+
| 消息格式兼容 | 智能兼容、Markdown、纯文本兼容 | 可兼容旧版本QQ的群友们! |
|
|
34
35
|
| 私聊流式回复 | 私聊可选用 QQ 官方流式消息接口逐步更新回复 | 仅适用于私聊;纯文本兼容模式自动关闭;部分客户端可能不可见 |
|
|
35
36
|
| 消息引用与 @ | 支持引用消息和 QQ @消息 | @用户优先显示用户名 |
|
|
36
37
|
| 会话隔离 | QQ 群聊和私聊分别使用独立会话 | 不同群、不同用户的上下文互相隔离 |
|
|
37
|
-
| 记忆系统 |
|
|
38
|
+
| 记忆系统 | 保存群聊、群成员和私聊用户的独立记忆;同一 Bot 下的用户记忆支持跨群复用 | 群关系和群级事件不会跨群共享;设置中可关闭 |
|
|
38
39
|
| 记忆整理 | 自动将近期记录整理为长期记忆 | 后台执行,不阻塞正常回复 |
|
|
39
40
|
| 媒体与文件权限 | 分别控制群成员媒体接收、媒体读取和普通工具使用 | Owner 与私聊默认不受限制 |
|
|
40
|
-
|
|
|
41
|
+
| 权限管理 | 单独控制群成员是否可以使用普通 Agent 工具、读取媒体和接收文件 | 可指定 Owner,按稳定用户 ID 判断 |
|
|
41
42
|
| DSH / QQChat 命令 | QQ 中直接执行 `/compact`、`/goal`、`/plan`、`/qqmodel`、`/qqstatus` 等命令 | 命令不经过模型;发送 `/qqhelp` 查看完整列表 |
|
|
42
43
|
| DSH 原生界面 | 使用 DSH 默认会话、聊天区和输入框 | 支持从 DSH 主动向 QQ 发送消息 |
|
|
44
|
+
| Session Preset | 每个 QQ Session 可使用 DSH 原生 preset | 新 Session 使用插件默认 preset;Session 自己选择后独立保存 |
|
|
43
45
|
| 日志查看 | 在设置页查看 QQ Chat 运行日志 | 方便排查连接和消息问题 |
|
|
44
46
|
|
|
45
47
|
## 如何使用
|
|
@@ -66,7 +68,7 @@
|
|
|
66
68
|
<td width="50%" valign="top">
|
|
67
69
|
<img src="./docs/assets/记忆系统.jpg" width="100%" alt="QQ Chat 群聊记忆系统">
|
|
68
70
|
<h3>记忆系统</h3>
|
|
69
|
-
<p
|
|
71
|
+
<p>插件会分别维护群聊、群成员和私聊用户的记忆。同一 Bot 下,基于稳定用户 ID 的用户记忆可以跨群复用;群内关系和群级事件只保留在对应群。成员记忆支持资料、群内称呼、历史昵称、行为模式和长期信息;近期消息会在空闲或达到阈值后自动整理。记忆会作为 Session 上下文按需刷新,设置中可以关闭,关闭后不会删除已有数据。</p>
|
|
70
72
|
</td>
|
|
71
73
|
</tr>
|
|
72
74
|
</table>
|
|
@@ -90,7 +92,7 @@ npx @deepseek-ai/dsh --profile web
|
|
|
90
92
|
当前开发分支也可以直接从 GitHub 安装:
|
|
91
93
|
|
|
92
94
|
```bash
|
|
93
|
-
npx @deepseek-ai/dsh plugin --profile qqchat add @deepseek-ai/dsh-web-app
|
|
95
|
+
npx @deepseek-ai/dsh plugin --profile qqchat add @deepseek-ai/dsh-web-app dsh-qqchat
|
|
94
96
|
npx @deepseek-ai/dsh --profile qqchat
|
|
95
97
|
```
|
|
96
98
|
|
|
@@ -99,9 +101,11 @@ npx @deepseek-ai/dsh --profile qqchat
|
|
|
99
101
|
1. 启动 DSH Web。
|
|
100
102
|
2. 打开 **设置 → QQ Chat**。
|
|
101
103
|
3. 点击 **扫码连接**。
|
|
102
|
-
4. 使用手机 QQ 扫描二维码,并选择要授权的官方 Bot
|
|
104
|
+
4. 使用手机 QQ 扫描二维码,并选择要授权的官方 Bot或手动填写 AppID 和 AppSecret 接入。
|
|
103
105
|
5. 授权完成后,QQ Gateway 会自动连接。
|
|
104
106
|
|
|
107
|
+
如果无法扫码,也可以选择 **手动配置**,填写 QQ 开放平台的 AppID 和 AppSecret,并按需选择沙箱环境。插件会先验证凭据,验证成功后再保存并启动 Gateway。
|
|
108
|
+
|
|
105
109
|
连接成功后,QQ Chat 的设置和对话会出现在 DSH 中。
|
|
106
110
|
|
|
107
111
|
## 群聊接收方式
|
|
@@ -118,7 +122,7 @@ npx @deepseek-ai/dsh --profile qqchat
|
|
|
118
122
|
|
|
119
123
|
## 命令
|
|
120
124
|
|
|
121
|
-
QQ 中以 `/` 开头的消息会交给命令系统处理,不会作为普通消息发送给模型。DSH 原生命令保持原名;QQChat 自有命令使用 `qq` 前缀。群聊中可以发送 `@Bot /
|
|
125
|
+
QQ 中以 `/` 开头的消息会交给命令系统处理,不会作为普通消息发送给模型。DSH 原生命令保持原名;QQChat 自有命令使用 `qq` 前缀。群聊中可以发送 `@Bot /qqhelp`。
|
|
122
126
|
|
|
123
127
|
| 命令 | 用途 |
|
|
124
128
|
| --- | --- |
|
|
@@ -126,6 +130,7 @@ QQ 中以 `/` 开头的消息会交给命令系统处理,不会作为普通消
|
|
|
126
130
|
| `/qqnew`、`/qqreset`、`/qqclear` | 保留旧 Session,下一条消息开始新的 QQ Session |
|
|
127
131
|
| `/compact` | 手动压缩较早的会话历史 |
|
|
128
132
|
| `/qqmodel [provider/]model` | 查看或切换当前群聊/私聊的模型 |
|
|
133
|
+
| `/qqpreset [preset]` | 查看或切换当前空白 Session 的 Agent Preset;对话开始后需新建 Session |
|
|
129
134
|
| `/qqstop` | 中止当前生成 |
|
|
130
135
|
| `/qqstatus` | 查看当前 Session、模型和生成状态 |
|
|
131
136
|
| `/qqping` | 测试 QQChat 连通性 |
|
|
@@ -159,11 +164,13 @@ QQ Chat 会分别保存:
|
|
|
159
164
|
- 群成员记忆:成员的资料、群内称呼、历史昵称、行为特点和长期信息
|
|
160
165
|
- 私聊记忆:与某个 QQ 用户的长期对话信息
|
|
161
166
|
|
|
167
|
+
同一 Bot 下,用户记忆按照稳定用户 ID 跨群连续;群内关系、群级事件和群聊记录不会跨群混入。不同 Bot 的用户记忆相互隔离。
|
|
168
|
+
|
|
162
169
|
记忆会在聊天空闲或积累到一定数量后异步整理,不会阻塞正常回复。可以从 QQ Session 顶部的 **QQ 记忆** 入口查看群和成员记忆。记忆内容会按需进入 Agent 上下文,启用后可能降低上下文缓存命中率并增加输入 token;可在 **设置 → QQ Chat → 记忆系统** 中关闭。
|
|
163
170
|
|
|
164
171
|
记忆快照会在新 Session、记忆上下文过期或 Session 压缩后刷新,连续对话不会重复写入完整记忆。群级记忆和当前群员记忆分别管理,群持续活跃不会替潜水成员刷新成员记忆。
|
|
165
172
|
|
|
166
|
-
##
|
|
173
|
+
## 权限管理
|
|
167
174
|
|
|
168
175
|
在设置中,媒体与文件权限和普通工具权限分别控制:
|
|
169
176
|
|
|
@@ -185,10 +192,14 @@ QQ 对话会使用 DSH 的默认聊天界面显示:
|
|
|
185
192
|
- 支持 QQ @消息转换为用户名
|
|
186
193
|
- 支持从 DSH 会话输入框主动发送 QQ 消息
|
|
187
194
|
|
|
195
|
+
## Session Preset
|
|
196
|
+
|
|
197
|
+
QQ Session 使用 DSH 原生的 Agent Preset 机制。插件配置中的 preset 只作为新建 QQ Session 的默认值;在 DSH Web 中为某个空白 Session 选择 preset 后,选择结果会随该 Session 保存,重启或恢复后仍优先使用该 Session 最近一次选择。也可以在该 Session 的第一条 QQ 消息中发送 `/qqpreset <preset>` 完成选择。对话开始后 DSH 不允许更换 preset,此时请先使用 `/qqnew`。插件不复制 DSH 的 preset、工具或 AgentLoop。
|
|
198
|
+
|
|
188
199
|
## 注意事项
|
|
189
200
|
|
|
190
201
|
- 需要 QQ 官方 Bot,不支持个人 QQ 账号登录。
|
|
191
|
-
- `0.2.
|
|
202
|
+
- `0.2.1` 仍在持续完善,建议先在测试 Bot 和测试群中使用。
|
|
192
203
|
- 富媒体、完整 QQ 表情和部分复杂消息格式可能需要使用兼容模式。
|
|
193
204
|
- 卸载插件不会自动删除已经保存的聊天和记忆数据。
|
|
194
205
|
|
package/client-src/settings.cts
CHANGED
|
@@ -15,6 +15,10 @@ export function QQSettings({ rpc }: { rpc: Rpc }) {
|
|
|
15
15
|
const [members, setMembers] = useState<KnownMember[]>(() => qqSettingsCache?.members || [])
|
|
16
16
|
const [loading, setLoading] = useState(() => qqSettingsCache === undefined)
|
|
17
17
|
const [auth, setAuth] = useState<{ taskId: string; qrDataUrl: string } | null>(null)
|
|
18
|
+
const [connectionMode, setConnectionMode] = useState<'qr' | 'manual'>('qr')
|
|
19
|
+
const [manualAppId, setManualAppId] = useState('')
|
|
20
|
+
const [manualAppSecret, setManualAppSecret] = useState('')
|
|
21
|
+
const [manualSandbox, setManualSandbox] = useState(false)
|
|
18
22
|
const [logs, setLogs] = useState<PluginLog[] | null>(null)
|
|
19
23
|
const [busy, setBusy] = useState(false)
|
|
20
24
|
const [error, setError] = useState('')
|
|
@@ -78,6 +82,15 @@ export function QQSettings({ rpc }: { rpc: Rpc }) {
|
|
|
78
82
|
setBusy(true)
|
|
79
83
|
try { setAuth(await call<{ taskId: string; qrDataUrl: string }>(rpc, 'auth/start')); setError('') } catch (err) { setError(err instanceof Error ? err.message : String(err)) } finally { setBusy(false) }
|
|
80
84
|
}
|
|
85
|
+
const connectManual = async () => {
|
|
86
|
+
setBusy(true)
|
|
87
|
+
try {
|
|
88
|
+
await call(rpc, 'account/manual-connect', { appId: manualAppId, appSecret: manualAppSecret, sandbox: manualSandbox })
|
|
89
|
+
setManualAppSecret('')
|
|
90
|
+
await refresh()
|
|
91
|
+
setError('')
|
|
92
|
+
} catch (err) { setError(err instanceof Error ? err.message : String(err)) } finally { setBusy(false) }
|
|
93
|
+
}
|
|
81
94
|
const disconnect = async () => {
|
|
82
95
|
if (!account) return
|
|
83
96
|
setBusy(true)
|
|
@@ -128,7 +141,24 @@ export function QQSettings({ rpc }: { rpc: Rpc }) {
|
|
|
128
141
|
h('div', { className: 'qqStatus' }, loading ? '加载中…' : account ? (account.gatewayStatus === 'online' ? '已连接' : '已授权') : '未连接', account && h(Button, { size: 'sm', variant: 'outline', disabled: busy, onClick: () => void disconnect() }, '取消连接')))
|
|
129
142
|
|
|
130
143
|
if (loading) return h('div', { className: 'qqs' }, head, h('div', { className: 'qqMuted' }, '正在读取 QQ Chat 设置…'))
|
|
131
|
-
if (!account)
|
|
144
|
+
if (!account) {
|
|
145
|
+
const modeButtons = h('div', { className: 'qqChoiceButtons' },
|
|
146
|
+
h(Button, { size: 'sm', variant: connectionMode === 'qr' ? 'primary' : 'outline', onClick: () => { setConnectionMode('qr'); setError('') } }, '扫码连接'),
|
|
147
|
+
h(Button, { size: 'sm', variant: connectionMode === 'manual' ? 'primary' : 'outline', onClick: () => { setConnectionMode('manual'); setAuth(null); setError('') } }, '手动配置'))
|
|
148
|
+
const qrBody = h('div', { className: 'qqConnect' },
|
|
149
|
+
h('div', { className: 'qqsTitle' }, auth ? '使用 QQ 扫码授权' : '连接 QQ Bot'),
|
|
150
|
+
h('div', { className: 'qqMuted' }, '使用手机 QQ 扫描官方 Bot 授权二维码。扫码和凭据解密都在 DSH Host 侧完成。'),
|
|
151
|
+
auth && h('div', { className: 'qqQr' }, h('img', { src: auth.qrDataUrl, alt: 'QQ 授权二维码' })),
|
|
152
|
+
h(Button, { variant: 'primary', disabled: busy, onClick: () => void startAuth() }, auth ? '重新生成二维码' : '生成二维码'))
|
|
153
|
+
const manualBody = h('div', { className: 'qqConnect qqManualConnect' },
|
|
154
|
+
h('div', { className: 'qqsTitle' }, '手动配置 QQ Bot'),
|
|
155
|
+
h('div', { className: 'qqMuted' }, '填写 QQ 开放平台创建的 AppID 和 AppSecret。密钥只提交到 DSH Host,不会显示在会话或日志中。'),
|
|
156
|
+
h(Input, { value: manualAppId, placeholder: 'AppID', onChange: (event: import('react').ChangeEvent<HTMLInputElement>) => setManualAppId(event.target.value) }),
|
|
157
|
+
h(Input, { type: 'password', value: manualAppSecret, placeholder: 'AppSecret', onChange: (event: import('react').ChangeEvent<HTMLInputElement>) => setManualAppSecret(event.target.value) }),
|
|
158
|
+
h('label', { className: 'qqCheckRow' }, h('input', { type: 'checkbox', checked: manualSandbox, onChange: (event: import('react').ChangeEvent<HTMLInputElement>) => setManualSandbox(event.target.checked) }), h('span', null, '使用沙箱环境')),
|
|
159
|
+
h(Button, { variant: 'primary', disabled: busy || !manualAppId.trim() || !manualAppSecret.trim(), onClick: () => void connectManual() }, busy ? '验证并连接中…' : '验证并连接'))
|
|
160
|
+
return h('div', { className: 'qqs' }, head, error && h('div', { className: 'qqError' }, error), modeButtons, connectionMode === 'qr' ? qrBody : manualBody)
|
|
161
|
+
}
|
|
132
162
|
if (!settings) return h('div', { className: 'qqs' }, head, h('div', { className: 'qqMuted' }, '正在读取设置…'))
|
|
133
163
|
|
|
134
164
|
const receiveButtons = h('div', { className: 'qqChoiceButtons' },
|
|
@@ -171,7 +201,7 @@ export function QQSettings({ rpc }: { rpc: Rpc }) {
|
|
|
171
201
|
h('div', { className: 'qqSetting' },
|
|
172
202
|
h('div', null,
|
|
173
203
|
h('div', { className: 'qqSettingTitle' }, '启用记忆系统'),
|
|
174
|
-
h('div', { className: 'qqSettingHelp' }, '
|
|
204
|
+
h('div', { className: 'qqSettingHelp' }, '记忆会在新 Session、上下文 TTL 过期、记忆变化或 Session 压缩后刷新,不会每轮重复注入完整上下文;后台会在空闲时整理近期消息。启用记忆可能降低上下文缓存命中率并增加输入 token。关闭后停止记忆注入和后台整理,但不会删除已有记忆。')),
|
|
175
205
|
h('div', { className: 'qqControl' }, h(Button, { size: 'sm', variant: settings.memoryEnabled ? 'primary' : 'outline', onClick: () => void patch({ memoryEnabled: !settings.memoryEnabled }) }, settings.memoryEnabled ? '已启用' : '已关闭'))))
|
|
176
206
|
const ownerSetting = !settings.groupMembersCanUseTools
|
|
177
207
|
? h('div', { className: 'qqSetting' },
|
package/docs/ARCHITECTURE.en.md
CHANGED
|
@@ -47,7 +47,9 @@ QQ Direct · <nickname>
|
|
|
47
47
|
|
|
48
48
|
The Client no longer registers a `sidebar.footer.action` chat picker. QQ Sessions are listed and opened by DSH's normal Session/Workspace Browser.
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
QQChat no longer submits an internal bootstrap wake. A newly created silent Session remains blank according to DSH's own semantics, so the native DSH Agent Preset selector can be used before the first Agent turn. The first QQ message that actually wakes the Agent creates the normal turn boundary.
|
|
51
|
+
|
|
52
|
+
The plugin's `agentPreset` setting applies only to new Sessions. When a preset is selected in DSH Web, DSH records an `agent-preset/selected` event. QQChat reads that event when resuming the Session and restores the Session's most recent preset selection.
|
|
51
53
|
|
|
52
54
|
## Settings boundary
|
|
53
55
|
|
|
@@ -56,8 +58,9 @@ A new silent-only peer would otherwise remain blank because DSH uses `turn/start
|
|
|
56
58
|
```text
|
|
57
59
|
QR authorization / connection
|
|
58
60
|
Auto reply / Mention only / Silent record
|
|
59
|
-
reply
|
|
61
|
+
group and direct-chat reply formats
|
|
60
62
|
memory system [on/off]
|
|
63
|
+
group-member media receive/read permissions
|
|
61
64
|
group-member tool permission
|
|
62
65
|
Owner stable ID
|
|
63
66
|
plugin logs
|
package/docs/ARCHITECTURE.md
CHANGED
|
@@ -47,14 +47,9 @@ QQ私聊 · <昵称>
|
|
|
47
47
|
|
|
48
48
|
Client 不再注册 `sidebar.footer.action` 会话选择器。QQ Session 直接由 DSH 自己的 Session/Workspace Browser 展示和打开。
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
-
|
|
53
|
-
- Session 能进入 DSH 正常列表;
|
|
54
|
-
- 没有 model step;
|
|
55
|
-
- 不调用 LLM;
|
|
56
|
-
- 不发送 QQ 消息;
|
|
57
|
-
- bootstrap 不进入模型 history。
|
|
50
|
+
QQChat 不再提交内部 bootstrap wake。新建的静默 Session 保持 DSH 原生 blank 状态,因此可以直接使用 DSH 的 Agent Preset 选择器;第一条真正触发 Agent 的 QQ 消息才会创建正常 turn boundary。
|
|
51
|
+
|
|
52
|
+
插件配置中的 `agentPreset` 只用于新 Session。Session 被 DSH Web 选择过 preset 后,DSH 会写入 `agent-preset/selected` 事件;QQChat 恢复 Session 时读取该事件,优先恢复 Session 最近一次选择的 preset。
|
|
58
53
|
|
|
59
54
|
## Settings 边界
|
|
60
55
|
|
package/docs/MEDIA_AND_QUOTES.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
本文是设计与审查文档,不代表所有功能已经实现。
|
|
16
16
|
|
|
17
|
-
当前实现进度:Phase 0–2
|
|
17
|
+
当前实现进度:Phase 0–2 已完成,Phase 3–4 的 Host 侧基础能力已完成,包括媒体接收、元数据工具、引用关系、引用索引和附件复用。已包含标准化媒体/引用类型、QQ 附件解析、SQLite 附件关系、安全下载、媒体清理、图片附件接入、`qqchat_describe_image`、`qqchat_read_file`、`qqchat_media_info` 和 JSON 可序列化的 Web transcript 摘要。Agent 触发消息已经使用 DSH 原生图片块;静默 transcript 的图片目前通过受保护的 RPC data URL 做最小适配。DSH Web 自定义 transcript 的完整原生媒体 renderer、文件/音频/视频播放器、短 TTL 媒体 URL 和真实环境验收仍未完成,因此不能视为完整的 Web 侧 Phase 3–4 交付。
|
|
18
18
|
|
|
19
19
|
Web 渲染后续采用“DSH 原生优先”的方案:触发 Agent 的消息使用 DSH 原生消息内容和 `ImageBlock`;静默记录或未触发 Agent 的 QQ transcript 只增加最小的附件适配,不另建一套气泡、图片预览、文件卡片或媒体主题。这样不会为了显示媒体而改变群聊接收模式或额外唤醒 Agent。
|
|
20
20
|
|
|
@@ -467,9 +467,9 @@ createUserMessage({
|
|
|
467
467
|
网页显示必须复用 DSH 原生消息和附件样式:
|
|
468
468
|
|
|
469
469
|
- 图片显示缩略图和可选的打开动作;
|
|
470
|
-
-
|
|
471
|
-
-
|
|
472
|
-
-
|
|
470
|
+
- 语音、视频和文件目前保存并展示受限的元数据摘要;
|
|
471
|
+
- Agent 侧可通过媒体工具读取允许范围内的文件或媒体;
|
|
472
|
+
- Web 侧完整播放器、下载/保存动作仍等待 DSH 公开 renderer 接口;
|
|
473
473
|
- 引用消息显示独立的引用块,正文和引用附件分开;
|
|
474
474
|
- 不在插件里重新实现 DSH 的气泡、输入框、Modal、图片预览、文件卡片或附件基础样式;
|
|
475
475
|
- 插件 Client 只负责把 QQ 消息、引用和附件转换成 DSH renderer 能消费的结构。
|
|
@@ -479,9 +479,9 @@ createUserMessage({
|
|
|
479
479
|
### A. DSH 原生能力确认
|
|
480
480
|
|
|
481
481
|
- [x] 确认当前 DSH 核心对 `ImageBlock`、`ImageAttachmentRef` 和附件引用的输入边界;
|
|
482
|
-
- [
|
|
483
|
-
- [
|
|
484
|
-
- [
|
|
482
|
+
- [x] 确认 DSH 当前对图片块和附件引用的输入边界;
|
|
483
|
+
- [x] 确认 DSH 尚未向插件公开可直接复用的自定义 transcript 图片、文件、音频、视频 renderer 接口;
|
|
484
|
+
- [x] 确认自定义 `qqchat/message` event 不能直接承载 DSH 原生附件块;
|
|
485
485
|
- [x] 自定义 event 不能直接变成原生 `ImageBlock` 时,记录并采用最小适配边界,不复制 DSH 基础组件。
|
|
486
486
|
|
|
487
487
|
### B. Host 附件读取和权限
|
|
@@ -491,7 +491,7 @@ createUserMessage({
|
|
|
491
491
|
- [x] 校验附件是否已经关联到当前消息、引用消息和会话范围;
|
|
492
492
|
- [x] 校验附件状态、过期时间和图片读取大小;媒体类型由入站媒体归一化和 DSH 图片附件服务共同校验;
|
|
493
493
|
- [x] 图片响应优先带回 DSH 原生 `ImageAttachmentRef`;仅为当前自定义 transcript 的图片预览提供受限 data URL;
|
|
494
|
-
- [
|
|
494
|
+
- [x] 当前实现使用受大小限制的 RPC 响应 data URL;接入 DSH renderer 后应替换为短 TTL 的受保护引用;
|
|
495
495
|
- [x] 不把 QQ 原始签名 URL、AppSecret、Token 或本地文件路径返回给 Client;
|
|
496
496
|
- [x] 无权限、过期、删除和超限附件会被拒绝;损坏文件由 RPC 失败处理,不泄露存储路径。
|
|
497
497
|
|
|
@@ -509,11 +509,10 @@ createUserMessage({
|
|
|
509
509
|
|
|
510
510
|
- [x] 静默消息继续使用 `qqchat/message`,不为了显示媒体改成 `user/message`;
|
|
511
511
|
- [x] event 只携带 JSON 可序列化的附件摘要:ID、类型、文件名、大小、引用标记;
|
|
512
|
-
- [
|
|
513
|
-
- [
|
|
514
|
-
- [ ] 薄适配层只负责附件引用转换和加载状态,不复制气泡、Modal、按钮或预览组件;
|
|
512
|
+
- [x] 已确认当前没有自定义 event 的原生附件入口;
|
|
513
|
+
- [x] 薄适配层只负责附件摘要、受保护读取和加载状态,不复制气泡、Modal、按钮或预览组件;
|
|
515
514
|
- [x] 图片加载通过受保护的附件读取 RPC,保持与 DSH 原生附件引用相同的权限边界;
|
|
516
|
-
- [
|
|
515
|
+
- [x] 文件、语音、视频在当前 transcript 中只保留统一 JSON 元数据摘要;原生播放器待 DSH 暴露公开入口后接入;
|
|
517
516
|
- [x] 加载失败、过期和无权限状态不显示原始 URL 或路径。
|
|
518
517
|
|
|
519
518
|
### E. 引用消息显示
|
package/docs/SECURITY.md
CHANGED
|
@@ -6,7 +6,7 @@ QQChat 同时接触 QQ 凭据、用户身份、群消息和 DSH Session。安全
|
|
|
6
6
|
|
|
7
7
|
## 凭据边界
|
|
8
8
|
|
|
9
|
-
- AppSecret、QQ Token、扫码 AES 临时 key 只存在 Host
|
|
9
|
+
- AppSecret、QQ Token、扫码 AES 临时 key 只存在 Host;手动连接表单只通过 loopback RPC 提交 AppSecret,验证失败时不保存新凭据。
|
|
10
10
|
- 浏览器只通过受限 RPC 获取状态和已经脱敏的展示数据。
|
|
11
11
|
- 凭据不写入 URL、日志、前端状态、测试 fixture 或 Git。
|
|
12
12
|
- SQLite 数据目录默认位于 `$DSH_HOME/plugins/dsh-qqchat/`,应由本地用户权限保护。
|
package/docs/STREAMING.md
CHANGED
|
@@ -296,25 +296,28 @@ if (writer.sentFrameCount === 0) {
|
|
|
296
296
|
}
|
|
297
297
|
```
|
|
298
298
|
|
|
299
|
-
##
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
- [
|
|
304
|
-
- [
|
|
305
|
-
- [
|
|
306
|
-
- [
|
|
307
|
-
- [
|
|
308
|
-
- [
|
|
309
|
-
- [
|
|
310
|
-
- [
|
|
311
|
-
- [
|
|
312
|
-
- [
|
|
313
|
-
- [
|
|
314
|
-
- [
|
|
315
|
-
- [ ]
|
|
316
|
-
- [
|
|
317
|
-
|
|
299
|
+
## 当前实现核对清单
|
|
300
|
+
|
|
301
|
+
以下是当前 `dsh-qqchat` 对官方方案的落地情况:
|
|
302
|
+
|
|
303
|
+
- [x] 使用 QQ 官方 `stream_messages` 请求和响应字段;
|
|
304
|
+
- [x] 仅为 C2C 私聊创建流式 Writer;
|
|
305
|
+
- [x] 从 DSH assistant text-delta 累计全文;
|
|
306
|
+
- [x] 使用 `replace`,不把 delta 当作独立消息;
|
|
307
|
+
- [x] 为每个流生成新的 `msg_seq`;
|
|
308
|
+
- [x] `index` 从 0 开始严格递增;
|
|
309
|
+
- [x] 首帧响应后再读取和保存 `stream_msg_id`;
|
|
310
|
+
- [x] 所有请求通过串行队列;
|
|
311
|
+
- [x] 使用节流减少更新频率;
|
|
312
|
+
- [x] 对发送失败区分“尚未发送”和“已经发送部分”;
|
|
313
|
+
- [x] 提供流式开关和普通发送回退;
|
|
314
|
+
- [x] 使用模拟 HTTP 测试覆盖首帧、后续帧、结束帧和队列竞态;
|
|
315
|
+
- [ ] 真实 QQ 手机端和桌面端分别验证所有客户端的可见性;
|
|
316
|
+
- [x] 日志只记录 `msg_seq`、`index`、是否有 `stream_msg_id` 等定位信息,不记录完整敏感正文。
|
|
317
|
+
|
|
318
|
+
### 已知故障:QQ `40054005` 去重
|
|
319
|
+
|
|
320
|
+
QQ 会在 `msg_seq` 重复或流式上下文不完整时返回 `40054005`。当前实现为每个流生成新的序列号,并在首帧成功后把返回的 `stream_msg_id` 传给后续帧;如果流式首帧尚未成功,运行时会回退到普通发送,避免用户收不到回复。如果已经成功显示过部分流式内容,插件不会再发送一条完整重复消息,而是记录失败并结束本轮。
|
|
318
321
|
|
|
319
322
|
## 测试矩阵
|
|
320
323
|
|
|
Binary file
|
|
Binary file
|
package/lib/client.js
CHANGED
|
@@ -29,6 +29,10 @@ function QQSettings({ rpc }) {
|
|
|
29
29
|
const [members, setMembers] = (0, shared_cjs_1.useState)(() => qqSettingsCache?.members || []);
|
|
30
30
|
const [loading, setLoading] = (0, shared_cjs_1.useState)(() => qqSettingsCache === undefined);
|
|
31
31
|
const [auth, setAuth] = (0, shared_cjs_1.useState)(null);
|
|
32
|
+
const [connectionMode, setConnectionMode] = (0, shared_cjs_1.useState)('qr');
|
|
33
|
+
const [manualAppId, setManualAppId] = (0, shared_cjs_1.useState)('');
|
|
34
|
+
const [manualAppSecret, setManualAppSecret] = (0, shared_cjs_1.useState)('');
|
|
35
|
+
const [manualSandbox, setManualSandbox] = (0, shared_cjs_1.useState)(false);
|
|
32
36
|
const [logs, setLogs] = (0, shared_cjs_1.useState)(null);
|
|
33
37
|
const [busy, setBusy] = (0, shared_cjs_1.useState)(false);
|
|
34
38
|
const [error, setError] = (0, shared_cjs_1.useState)('');
|
|
@@ -125,6 +129,21 @@ function QQSettings({ rpc }) {
|
|
|
125
129
|
setBusy(false);
|
|
126
130
|
}
|
|
127
131
|
};
|
|
132
|
+
const connectManual = async () => {
|
|
133
|
+
setBusy(true);
|
|
134
|
+
try {
|
|
135
|
+
await (0, shared_cjs_1.call)(rpc, 'account/manual-connect', { appId: manualAppId, appSecret: manualAppSecret, sandbox: manualSandbox });
|
|
136
|
+
setManualAppSecret('');
|
|
137
|
+
await refresh();
|
|
138
|
+
setError('');
|
|
139
|
+
}
|
|
140
|
+
catch (err) {
|
|
141
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
setBusy(false);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
128
147
|
const disconnect = async () => {
|
|
129
148
|
if (!account)
|
|
130
149
|
return;
|
|
@@ -184,8 +203,12 @@ function QQSettings({ rpc }) {
|
|
|
184
203
|
const head = (0, shared_cjs_1.h)('div', { className: 'qqsHead' }, (0, shared_cjs_1.h)('div', null, (0, shared_cjs_1.h)('div', { className: 'qqsTitle' }, 'QQ Chat'), (0, shared_cjs_1.h)('div', { className: 'qqMuted' }, 'QQ Bot 接收、兼容与权限设置')), (0, shared_cjs_1.h)('div', { className: 'qqStatus' }, loading ? '加载中…' : account ? (account.gatewayStatus === 'online' ? '已连接' : '已授权') : '未连接', account && (0, shared_cjs_1.h)(shared_cjs_1.Button, { size: 'sm', variant: 'outline', disabled: busy, onClick: () => void disconnect() }, '取消连接')));
|
|
185
204
|
if (loading)
|
|
186
205
|
return (0, shared_cjs_1.h)('div', { className: 'qqs' }, head, (0, shared_cjs_1.h)('div', { className: 'qqMuted' }, '正在读取 QQ Chat 设置…'));
|
|
187
|
-
if (!account)
|
|
188
|
-
|
|
206
|
+
if (!account) {
|
|
207
|
+
const modeButtons = (0, shared_cjs_1.h)('div', { className: 'qqChoiceButtons' }, (0, shared_cjs_1.h)(shared_cjs_1.Button, { size: 'sm', variant: connectionMode === 'qr' ? 'primary' : 'outline', onClick: () => { setConnectionMode('qr'); setError(''); } }, '扫码连接'), (0, shared_cjs_1.h)(shared_cjs_1.Button, { size: 'sm', variant: connectionMode === 'manual' ? 'primary' : 'outline', onClick: () => { setConnectionMode('manual'); setAuth(null); setError(''); } }, '手动配置'));
|
|
208
|
+
const qrBody = (0, shared_cjs_1.h)('div', { className: 'qqConnect' }, (0, shared_cjs_1.h)('div', { className: 'qqsTitle' }, auth ? '使用 QQ 扫码授权' : '连接 QQ Bot'), (0, shared_cjs_1.h)('div', { className: 'qqMuted' }, '使用手机 QQ 扫描官方 Bot 授权二维码。扫码和凭据解密都在 DSH Host 侧完成。'), auth && (0, shared_cjs_1.h)('div', { className: 'qqQr' }, (0, shared_cjs_1.h)('img', { src: auth.qrDataUrl, alt: 'QQ 授权二维码' })), (0, shared_cjs_1.h)(shared_cjs_1.Button, { variant: 'primary', disabled: busy, onClick: () => void startAuth() }, auth ? '重新生成二维码' : '生成二维码'));
|
|
209
|
+
const manualBody = (0, shared_cjs_1.h)('div', { className: 'qqConnect qqManualConnect' }, (0, shared_cjs_1.h)('div', { className: 'qqsTitle' }, '手动配置 QQ Bot'), (0, shared_cjs_1.h)('div', { className: 'qqMuted' }, '填写 QQ 开放平台创建的 AppID 和 AppSecret。密钥只提交到 DSH Host,不会显示在会话或日志中。'), (0, shared_cjs_1.h)(shared_cjs_1.Input, { value: manualAppId, placeholder: 'AppID', onChange: (event) => setManualAppId(event.target.value) }), (0, shared_cjs_1.h)(shared_cjs_1.Input, { type: 'password', value: manualAppSecret, placeholder: 'AppSecret', onChange: (event) => setManualAppSecret(event.target.value) }), (0, shared_cjs_1.h)('label', { className: 'qqCheckRow' }, (0, shared_cjs_1.h)('input', { type: 'checkbox', checked: manualSandbox, onChange: (event) => setManualSandbox(event.target.checked) }), (0, shared_cjs_1.h)('span', null, '使用沙箱环境')), (0, shared_cjs_1.h)(shared_cjs_1.Button, { variant: 'primary', disabled: busy || !manualAppId.trim() || !manualAppSecret.trim(), onClick: () => void connectManual() }, busy ? '验证并连接中…' : '验证并连接'));
|
|
210
|
+
return (0, shared_cjs_1.h)('div', { className: 'qqs' }, head, error && (0, shared_cjs_1.h)('div', { className: 'qqError' }, error), modeButtons, connectionMode === 'qr' ? qrBody : manualBody);
|
|
211
|
+
}
|
|
189
212
|
if (!settings)
|
|
190
213
|
return (0, shared_cjs_1.h)('div', { className: 'qqs' }, head, (0, shared_cjs_1.h)('div', { className: 'qqMuted' }, '正在读取设置…'));
|
|
191
214
|
const receiveButtons = (0, shared_cjs_1.h)('div', { className: 'qqChoiceButtons' }, ...['auto', 'mention', 'silent'].map(mode => (0, shared_cjs_1.h)(shared_cjs_1.Button, {
|
|
@@ -204,7 +227,7 @@ function QQSettings({ rpc }) {
|
|
|
204
227
|
: settings.directStreamingEnabled
|
|
205
228
|
? '使用 QQ 官方流式接口逐步更新私聊回复;部分 QQ 客户端可能看不到流式效果。'
|
|
206
229
|
: '使用普通一次性消息发送,兼容性更好。')))));
|
|
207
|
-
const memoryGroup = (0, shared_cjs_1.h)('div', { className: 'qqSettingsGroup' }, (0, shared_cjs_1.h)('h3', null, '记忆系统'), (0, shared_cjs_1.h)('div', { className: 'qqSetting' }, (0, shared_cjs_1.h)('div', null, (0, shared_cjs_1.h)('div', { className: 'qqSettingTitle' }, '启用记忆系统'), (0, shared_cjs_1.h)('div', { className: 'qqSettingHelp' }, '
|
|
230
|
+
const memoryGroup = (0, shared_cjs_1.h)('div', { className: 'qqSettingsGroup' }, (0, shared_cjs_1.h)('h3', null, '记忆系统'), (0, shared_cjs_1.h)('div', { className: 'qqSetting' }, (0, shared_cjs_1.h)('div', null, (0, shared_cjs_1.h)('div', { className: 'qqSettingTitle' }, '启用记忆系统'), (0, shared_cjs_1.h)('div', { className: 'qqSettingHelp' }, '记忆会在新 Session、上下文 TTL 过期、记忆变化或 Session 压缩后刷新,不会每轮重复注入完整上下文;后台会在空闲时整理近期消息。启用记忆可能降低上下文缓存命中率并增加输入 token。关闭后停止记忆注入和后台整理,但不会删除已有记忆。')), (0, shared_cjs_1.h)('div', { className: 'qqControl' }, (0, shared_cjs_1.h)(shared_cjs_1.Button, { size: 'sm', variant: settings.memoryEnabled ? 'primary' : 'outline', onClick: () => void patch({ memoryEnabled: !settings.memoryEnabled }) }, settings.memoryEnabled ? '已启用' : '已关闭'))));
|
|
208
231
|
const ownerSetting = !settings.groupMembersCanUseTools
|
|
209
232
|
? (0, shared_cjs_1.h)('div', { className: 'qqSetting' }, (0, shared_cjs_1.h)('div', null, (0, shared_cjs_1.h)('div', { className: 'qqSettingTitle' }, 'Owner stable ID'), (0, shared_cjs_1.h)('div', { className: 'qqSettingHelp' }, '使用 stable sender ID,不根据昵称判断。')), (0, shared_cjs_1.h)('div', { className: 'qqControl' }, (0, shared_cjs_1.h)(shared_cjs_1.Input, {
|
|
210
233
|
value: settings.ownerUserId,
|
package/lib/gateway/api.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare class QQApiClient {
|
|
|
14
14
|
constructor(db: QQChatDatabase, config: QQChatConfig);
|
|
15
15
|
clearToken(accountId: number): void;
|
|
16
16
|
token(account: AccountRow): Promise<string>;
|
|
17
|
-
gatewayUrl(account: AccountRow): Promise<string>;
|
|
17
|
+
gatewayUrl(account: AccountRow, retry?: boolean): Promise<string>;
|
|
18
18
|
private nextSeq;
|
|
19
19
|
/**
|
|
20
20
|
* QQ stream_messages requires a fresh msg_seq for each stream session.
|
package/lib/gateway/api.js
CHANGED
|
@@ -32,12 +32,16 @@ export class QQApiClient {
|
|
|
32
32
|
this.tokens.set(id, { token: data.access_token, expiresAt: Date.now() + Math.max(60, ttl) * 1000 });
|
|
33
33
|
return data.access_token;
|
|
34
34
|
}
|
|
35
|
-
async gatewayUrl(account) {
|
|
35
|
+
async gatewayUrl(account, retry = true) {
|
|
36
36
|
const token = await this.token(account);
|
|
37
37
|
const base = account.sandbox ? SANDBOX_API_BASE : API_BASE;
|
|
38
38
|
const response = await fetch(`${base}/gateway`, {
|
|
39
39
|
headers: { Authorization: `QQBot ${token}` }, signal: AbortSignal.timeout(15_000),
|
|
40
40
|
});
|
|
41
|
+
if (response.status === 401 && retry) {
|
|
42
|
+
this.clearToken(account.id);
|
|
43
|
+
return this.gatewayUrl(account, false);
|
|
44
|
+
}
|
|
41
45
|
const data = await safeJson(response);
|
|
42
46
|
if (!response.ok || !data?.url)
|
|
43
47
|
throw new Error(`QQ gateway 获取失败: HTTP ${response.status}`);
|
package/lib/gateway/gateway.js
CHANGED
|
@@ -72,7 +72,11 @@ export class QQGateway {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
async connectOnce() {
|
|
75
|
-
|
|
75
|
+
// Resolve the URL first. gatewayUrl may invalidate and refresh a stale
|
|
76
|
+
// cached token after a 401; fetching the identify token in parallel could
|
|
77
|
+
// otherwise retain the pre-refresh token for the WebSocket handshake.
|
|
78
|
+
const url = await this.api.gatewayUrl(this.account);
|
|
79
|
+
const token = await this.api.token(this.account);
|
|
76
80
|
await new Promise((resolve, reject) => {
|
|
77
81
|
const ws = new WebSocket(url);
|
|
78
82
|
this.ws = ws;
|