@chen_hu_hu/pi-qq 1.1.0 → 1.2.0
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.md +34 -30
- package/doc/features-v1.md +50 -50
- package/doc/features-v2.md +131 -19
- package/doc/plan-v1.md +19 -19
- package/doc/plan-v2.md +99 -13
- package/index.ts +13 -8
- package/package.json +1 -1
- package/src/bot.ts +5 -3
- package/src/files.ts +162 -39
- package/src/inbound.ts +46 -9
package/README.md
CHANGED
|
@@ -29,13 +29,17 @@ Send a QQ private message to the bot to start a task.
|
|
|
29
29
|
- **Text**: normal chat message.
|
|
30
30
|
- **Voice**: QQ built-in ASR text is sent to pi directly; the audio is not downloaded or saved. If ASR returns no text, the bot asks you to resend or type it.
|
|
31
31
|
- **Images**: sent to pi as vision input.
|
|
32
|
-
- **Files**: saved under the current workspace at `.pi/pi-qq
|
|
32
|
+
- **Files**: saved under the current workspace at `.pi/pi-qq/<sessionId>/uploads/`. A file-only message does not start pi; send the instruction in the next text or voice message, and the saved path(s), size, and original filename are added to that prompt.
|
|
33
|
+
|
|
34
|
+
When you upload multiple files before giving an instruction, they are combined into the next prompt. `/new` clears files waiting for an instruction.
|
|
35
|
+
|
|
36
|
+
Uploads are scoped to the current pi session. If you upload the same filename with identical content, pi reuses the existing file; the same filename with different content is saved as `name-1.ext`; different filenames with identical content are kept as separate files.
|
|
33
37
|
|
|
34
38
|
Example file prompt seen by pi:
|
|
35
39
|
|
|
36
40
|
```text
|
|
37
41
|
User sent the following file via QQ (saved locally; use read/bash or other tools to access it):
|
|
38
|
-
- /home/chen/project/myproj/.pi/pi-qq/
|
|
42
|
+
- /home/chen/project/myproj/.pi/pi-qq/<sessionId>/uploads/report.pdf (1.4MB, original name: report.pdf)
|
|
39
43
|
|
|
40
44
|
User message:
|
|
41
45
|
Summarize this file.
|
|
@@ -55,25 +59,25 @@ Voice messages use QQ's built-in ASR (`asr_refer_text`). The transcript is sent
|
|
|
55
59
|
|
|
56
60
|
Run these in the pi terminal:
|
|
57
61
|
|
|
58
|
-
| Command
|
|
59
|
-
|
|
|
60
|
-
| `/qq-login`
|
|
61
|
-
| `/qq-status`
|
|
62
|
-
| `/qq-logout`
|
|
63
|
-
| `/qq-test-budget`
|
|
64
|
-
| `/qq-test-md [text]` | Send a Markdown test message
|
|
65
|
-
| `/qq-test-stream`
|
|
66
|
-
| `/qq-new`
|
|
62
|
+
| Command | Description |
|
|
63
|
+
| -------------------- | ------------------------------------------------------- |
|
|
64
|
+
| `/qq-login` | Log in with a QR code and bind the scanning QQ user |
|
|
65
|
+
| `/qq-status` | Show login, connection, model, context, and bound user |
|
|
66
|
+
| `/qq-logout` | Log out and clear in-memory credentials |
|
|
67
|
+
| `/qq-test-budget` | Show passive-reply budget and stream-bubble diagnostics |
|
|
68
|
+
| `/qq-test-md [text]` | Send a Markdown test message |
|
|
69
|
+
| `/qq-test-stream` | Run a streamed timeline diagnostic |
|
|
70
|
+
| `/qq-new` | Reset the current session (used by QQ `/new`) |
|
|
67
71
|
|
|
68
72
|
QQ-side commands:
|
|
69
73
|
|
|
70
|
-
| Command
|
|
71
|
-
|
|
|
72
|
-
| `/new`
|
|
73
|
-
| `/stop`
|
|
74
|
-
| `/compact` | Compact the current context
|
|
75
|
-
| `/status`
|
|
76
|
-
| `/help`
|
|
74
|
+
| Command | Description |
|
|
75
|
+
| ---------- | ------------------------------- |
|
|
76
|
+
| `/new` | Start a new pi session |
|
|
77
|
+
| `/stop` | Abort the current run |
|
|
78
|
+
| `/compact` | Compact the current context |
|
|
79
|
+
| `/status` | Show session and context status |
|
|
80
|
+
| `/help` | Show command help |
|
|
77
81
|
|
|
78
82
|
## Settings
|
|
79
83
|
|
|
@@ -87,18 +91,18 @@ Create `~/.pi/agent/pi-qq.json` to override defaults. This file contains setting
|
|
|
87
91
|
}
|
|
88
92
|
```
|
|
89
93
|
|
|
90
|
-
| Key
|
|
91
|
-
|
|
|
92
|
-
| `streamAssistant`
|
|
93
|
-
| `markdownSupport`
|
|
94
|
-
| `deliverAs`
|
|
95
|
-
| `imageMaxSize`
|
|
96
|
-
| `fileMaxSize`
|
|
97
|
-
| `heartbeatMinutes`
|
|
98
|
-
| `heartbeatMaxMessages` | `3`
|
|
99
|
-
| `streamRelay`
|
|
100
|
-
| `streamFlushMs`
|
|
101
|
-
| `logLevel`
|
|
94
|
+
| Key | Default | Description |
|
|
95
|
+
| ---------------------- | ---------- | ------------------------------------------------------------ |
|
|
96
|
+
| `streamAssistant` | `true` | Stream assistant replies |
|
|
97
|
+
| `markdownSupport` | `false` | Bot has QQ Markdown permission; pass Markdown through |
|
|
98
|
+
| `deliverAs` | `"steer"` | Queue new messages while busy: `steer` or `followUp` |
|
|
99
|
+
| `imageMaxSize` | `10485760` | QQ image download limit in bytes (10MB) |
|
|
100
|
+
| `fileMaxSize` | `52428800` | QQ file download limit in bytes (50MB) |
|
|
101
|
+
| `heartbeatMinutes` | `10` | Long-task heartbeat interval; `0` disables |
|
|
102
|
+
| `heartbeatMaxMessages` | `3` | Per-run message heartbeat limit |
|
|
103
|
+
| `streamRelay` | `true` | Use append-mode stream bubbles |
|
|
104
|
+
| `streamFlushMs` | `10000` | Stream summary frame interval in ms (minimum 300) |
|
|
105
|
+
| `logLevel` | `"silent"` | Log threshold: `silent`, `error`, `warn`, `info`, or `debug` |
|
|
102
106
|
|
|
103
107
|
When enabled, logs are written to `<cwd>/.pi/pi-qq/logs/pi-qq-YYYY-MM-DD.log`. `PI_QQ_LOG_DIR` overrides the directory. `info` records metadata only; `debug` records full events, attachments, prompts, and tool payloads. Legacy `debug: true` maps to `logLevel: "debug"`.
|
|
104
108
|
|
package/doc/features-v1.md
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
技术栈:
|
|
7
7
|
|
|
8
|
-
| 依赖
|
|
9
|
-
|
|
|
10
|
-
| `@tencent-connect/qqbot-nodejs`
|
|
11
|
-
| `@tencent-connect/qqbot-connector`
|
|
12
|
-
| `@earendil-works/pi-coding-agent`(ExtensionAPI) | pi 扩展宿主:事件订阅、命令注册、消息注入、上下文用量
|
|
8
|
+
| 依赖 | 用途 |
|
|
9
|
+
| ------------------------------------------------- | --------------------------------------------------------------------------- |
|
|
10
|
+
| `@tencent-connect/qqbot-nodejs` | QQ 开放平台协议层:WebSocket Gateway、C2C 消息收发、媒体上传、流式消息 |
|
|
11
|
+
| `@tencent-connect/qqbot-connector` | 扫码登录:展示二维码,扫码后换取 `appId / appSecret / userOpenid`(仅内存) |
|
|
12
|
+
| `@earendil-works/pi-coding-agent`(ExtensionAPI) | pi 扩展宿主:事件订阅、命令注册、消息注入、上下文用量 |
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
|
@@ -166,13 +166,13 @@ pi-qq 扩展 ── pi.sendUserMessage(text+images) ─┴─ pi 事件:
|
|
|
166
166
|
|
|
167
167
|
QQ 开放平台的发送限制直接决定回传策略,必须统一管理:
|
|
168
168
|
|
|
169
|
-
| 限制
|
|
170
|
-
|
|
|
171
|
-
| 被动回复额度 | 每条入站消息 5 分钟内有效,约 4 条/小时
|
|
172
|
-
| 主动消息
|
|
173
|
-
| 流式消息
|
|
174
|
-
| 文本长度
|
|
175
|
-
| markdown
|
|
169
|
+
| 限制 | 数值 | 应对 |
|
|
170
|
+
| ------------ | ------------------------------------------ | ----------------------------------------------------------------------------------- |
|
|
171
|
+
| 被动回复额度 | 每条入站消息 5 分钟内有效,约 4 条/小时 | 扩展内维护回复预算(复用 SDK `ReplyLimiter` 思路);assistant 时间线按文本/活动分泡 |
|
|
172
|
+
| 主动消息 | 无 `msgId` 发送受平台额度限制 | 被动额度耗尽时才降级为主动发送,且给出明确提示 |
|
|
173
|
+
| 流式消息 | 仅 C2C;节流 ≥300ms;基于 5 分钟内 `msgId` | 流式仅用于 assistant 文本;无关联 `msgId` 时自动降级 `sendText` |
|
|
174
|
+
| 文本长度 | 单条 ~5000 字符 | SDK 分块;超出部分按序发送 |
|
|
175
|
+
| markdown | 默认无权限(`markdownSupport: false`) | Markdown → 纯文本降级渲染 |
|
|
176
176
|
|
|
177
177
|
**合并规则**(默认):assistant 文本消息与活动时间线严格分泡(每条文本消息 1 条纯文本气泡,工具间隔另起活动气泡);不再发送用量摘要,上下文占比通过 `/status` 查询。气泡数随回合内文本消息数增长,需关注 `msgId` 的被动额度;若平台拒绝(帧失败),自动降级消息路径。工具调用过程本身不逐条回传。
|
|
178
178
|
|
|
@@ -180,31 +180,31 @@ QQ 开放平台的发送限制直接决定回传策略,必须统一管理:
|
|
|
180
180
|
|
|
181
181
|
`~/.pi/agent/pi-qq.json`(只保存设置;不含凭据、不写入登录信息):
|
|
182
182
|
|
|
183
|
-
| 字段
|
|
184
|
-
|
|
|
185
|
-
| `streamAssistant`
|
|
186
|
-
| `markdownSupport`
|
|
187
|
-
| `deliverAs`
|
|
188
|
-
| `imageMaxSize`
|
|
189
|
-
| `fileMaxSize`
|
|
190
|
-
| `heartbeatMinutes`
|
|
191
|
-
| `heartbeatMaxMessages` | `3`
|
|
192
|
-
| `streamRelay`
|
|
193
|
-
| `streamFlushMs`
|
|
194
|
-
| `debug`
|
|
183
|
+
| 字段 | 默认 | 说明 |
|
|
184
|
+
| ---------------------- | ------------------- | ------------------------------------------------------------------------------------ |
|
|
185
|
+
| `streamAssistant` | `true` | assistant 流式回传开关 |
|
|
186
|
+
| `markdownSupport` | `false` | 机器人是否有 markdown 权限;`true` 时回传透传 Markdown |
|
|
187
|
+
| `deliverAs` | `"steer"` | 忙碌时新消息的处理方式 |
|
|
188
|
+
| `imageMaxSize` | `10MB` | QQ 图片下载上限 |
|
|
189
|
+
| `fileMaxSize` | `50MB` | QQ 文件下载上限 |
|
|
190
|
+
| `heartbeatMinutes` | `10`(0 关闭) | F7 节流心跳间隔 |
|
|
191
|
+
| `heartbeatMaxMessages` | `3` | F7 每 run 消息心跳上限(流式心跳不受限) |
|
|
192
|
+
| `streamRelay` | `true` | F7 流式载体开关(append 追加 + 节流合帧 + 限流退避,实测可用;失败自动降级消息路径) |
|
|
193
|
+
| `streamFlushMs` | `10000`(最小 300) | F7 流式汇总帧间隔(毫秒,默认每 10s 汇总工具调用) |
|
|
194
|
+
| `debug` | `false` | 诊断模式:SDK 日志转终端 + 流式重试/超时日志 + 行组/文本帧时间戳 |
|
|
195
195
|
|
|
196
196
|
## 5. 命令总表
|
|
197
197
|
|
|
198
|
-
| 位置
|
|
199
|
-
|
|
|
200
|
-
| pi 侧 | `/qq-login`
|
|
201
|
-
| pi 侧 | `/qq-status`
|
|
202
|
-
| pi 侧 | `/qq-test-budget`
|
|
203
|
-
| pi 侧 | `/qq-logout`
|
|
204
|
-
| pi 侧 | `/qq-new`
|
|
205
|
-
| pi 侧 | `/qq-test-md [text]`
|
|
206
|
-
| pi 侧 | `/qq-test-stream`
|
|
207
|
-
| QQ 侧 | `/new` `/stop` `/compact` `/status` `/help` | 会话控制(见 F2)
|
|
198
|
+
| 位置 | 命令 | 行为 |
|
|
199
|
+
| ----- | ------------------------------------------- | ---------------------------------------------------- |
|
|
200
|
+
| pi 侧 | `/qq-login` | 扫码登录并绑定(QR only) |
|
|
201
|
+
| pi 侧 | `/qq-status` | 登录态、连接状态、绑定用户 |
|
|
202
|
+
| pi 侧 | `/qq-test-budget` | 诊断:被动额度、流式气泡数、最近 msgId 新鲜度 |
|
|
203
|
+
| pi 侧 | `/qq-logout` | 清除内存凭据并断开 |
|
|
204
|
+
| pi 侧 | `/qq-new` | 重置当前会话(QQ `/new` 调用) |
|
|
205
|
+
| pi 侧 | `/qq-test-md [text]` | 诊断:发送 Markdown 消息,验证 C2C markdown 渲染能力 |
|
|
206
|
+
| pi 侧 | `/qq-test-stream` | 诊断:开流→三帧→complete,验证流式帧是否渲染 |
|
|
207
|
+
| QQ 侧 | `/new` `/stop` `/compact` `/status` `/help` | 会话控制(见 F2) |
|
|
208
208
|
|
|
209
209
|
## 6. 可靠性与安全
|
|
210
210
|
|
|
@@ -216,24 +216,24 @@ QQ 开放平台的发送限制直接决定回传策略,必须统一管理:
|
|
|
216
216
|
|
|
217
217
|
## 7. 决策记录
|
|
218
218
|
|
|
219
|
-
| #
|
|
220
|
-
| --- |
|
|
221
|
-
| 1
|
|
222
|
-
| 2
|
|
223
|
-
| 3
|
|
224
|
-
| 4
|
|
225
|
-
| 5
|
|
226
|
-
| 6
|
|
227
|
-
| 7
|
|
228
|
-
| 8
|
|
229
|
-
| 9
|
|
219
|
+
| # | 问题 | 决策 |
|
|
220
|
+
| --- | ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
221
|
+
| 1 | TUI 二维码渲染 | 登录协议用 connector;展示用 `qrcode-terminal`(零依赖)在 `ctx.ui` 弹窗画码 |
|
|
222
|
+
| 2 | thinking 内容 | 不回传具体内容(始终剔除,无配置开关);F7 时间线中仅以 `[💭] Thinking...` 标记体现 |
|
|
223
|
+
| 3 | tool 消息 | **完全不回传**;只回传 assistant 消息,上下文占比通过 `/status` 查询 |
|
|
224
|
+
| 4 | 图片方向 | F3 为 QQ → pi(用户发图给 pi);pi 不向 QQ 发图片(LLM 仅输出纯文本) |
|
|
225
|
+
| 5 | 成本/用量摘要 | 已移除每轮用量摘要;不展示 token、缓存命中率、成本 |
|
|
226
|
+
| 6 | 回复格式 | 回复通常为 Markdown 格式的总结/提问文本(不在回复中写代码);默认轻量转纯文本,有 markdown 权限可透传 |
|
|
227
|
+
| 7 | 登录方式 | 仅 `/qq-login` 扫码;凭据只存进程内存、不落盘;pi 进程退出后必须重新扫码 |
|
|
228
|
+
| 8 | 长任务反馈 | typing 保鲜 + 每 10s 汇总工具调用 + 节流心跳(默认 10 分钟/条,流式载体优先,每 run ≤3 条消息心跳保险丝)+ 机会性流式(平台拒绝即降级);不发送开始确认 |
|
|
229
|
+
| 9 | 流式可用性(实测三轮) | ① C2C markdown(msg_type=2,`sendMarkdown`)渲染正常;② SDK 内置流式 `input_mode="replace"` 被平台拒绝("已经提交的消息内容不可修改"),首帧可渲染、后续帧报错;③ 自实现 `AppendStream`(input_mode="append",增量追加 + DONE)实测通过;补齐节流合帧(500ms)与限流退避重试后**默认开启**,失败自动降级消息路径 |
|
|
230
230
|
|
|
231
231
|
## 8. 里程碑
|
|
232
232
|
|
|
233
|
-
| 阶段 | 内容
|
|
234
|
-
|
|
|
235
|
-
| M1
|
|
236
|
-
| M2
|
|
237
|
-
| M4
|
|
233
|
+
| 阶段 | 内容 | 验收 |
|
|
234
|
+
| ---- | -------------------------------------------- | -------------------------------------------- |
|
|
235
|
+
| M1 | F1 扫码登录 + 内存凭据 + 连接启动 | 扫码后 `/qq-status` 在线;重启 pi 需重新扫码 |
|
|
236
|
+
| M2 | F2 单人聊天 + F4 assistant 回传(先非流式) | QQ 发消息得到 pi 回复 |
|
|
237
|
+
| M4 | F3 QQ 图片/文件消息 + markdownSupport + 打磨 | 图片可进入 pi 会话;文件保存并关联到提示词 |
|
|
238
238
|
|
|
239
239
|
> 原 M3 用量摘要已取消(2026-10-29)。
|
package/doc/features-v2.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# pi-qq — features-v2.md
|
|
2
2
|
|
|
3
|
-
> V2 增量:F8 语音自动转写、F9
|
|
3
|
+
> V2 增量:F8 语音自动转写、F9 轻量日志基础设施、F10 文件消息等待指令、F11 文件存储与去重。
|
|
4
4
|
> 基线见 [features-v1.md](./features-v1.md);本文只描述新增/变更内容。
|
|
5
5
|
|
|
6
6
|
## 1. 背景与结论
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
|
|
20
20
|
### 行为
|
|
21
21
|
|
|
22
|
-
| 情况
|
|
23
|
-
|
|
|
24
|
-
| 有 ASR 文本 | `markQQTrigger()` → `pi.sendUserMessage(text, { deliverAs })`
|
|
25
|
-
| ASR 为空
|
|
26
|
-
| 语音消息
|
|
22
|
+
| 情况 | 处理 |
|
|
23
|
+
| ----------- | ------------------------------------------------------------------------------------- |
|
|
24
|
+
| 有 ASR 文本 | `markQQTrigger()` → `pi.sendUserMessage(text, { deliverAs })` |
|
|
25
|
+
| ASR 为空 | 回复 `Could not transcribe this voice message; please resend or type it.`,不触发 run |
|
|
26
|
+
| 语音消息 | 不下载 `url` / `voice_wav_url`,不保存文件,不走图片/文件分支 |
|
|
27
27
|
|
|
28
28
|
- 语音和文字是两条独立消息,不做同条组合。
|
|
29
29
|
- 转写文本不参与 QQ 命令解析,作为普通用户消息交给 pi。
|
|
@@ -64,13 +64,13 @@
|
|
|
64
64
|
}
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
-
| 级别
|
|
68
|
-
|
|
|
69
|
-
| `silent` | 不写日志(默认)
|
|
70
|
-
| `error`
|
|
71
|
-
| `warn`
|
|
72
|
-
| `info`
|
|
73
|
-
| `debug`
|
|
67
|
+
| 级别 | 输出 |
|
|
68
|
+
| -------- | ---------------------------------------------------- |
|
|
69
|
+
| `silent` | 不写日志(默认) |
|
|
70
|
+
| `error` | error |
|
|
71
|
+
| `warn` | warn + error |
|
|
72
|
+
| `info` | info + warn + error |
|
|
73
|
+
| `debug` | 全部,含 raw 事件、附件、prompt、工具参数/结果、正文 |
|
|
74
74
|
|
|
75
75
|
- 配置键使用 `logLevel`,不使用 `log_level`。
|
|
76
76
|
- 移除 `debug` 配置;旧 `debug: true` 迁移为 `logLevel: "debug"`,其他情况默认 `silent`。
|
|
@@ -84,14 +84,126 @@
|
|
|
84
84
|
- 旧 `debug` 配置可迁移。
|
|
85
85
|
- 日志路径、日期滚动、写入失败降级正常。
|
|
86
86
|
|
|
87
|
-
## 4.
|
|
87
|
+
## 4. F10 文件消息等待指令
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
| --- | --- |
|
|
91
|
-
| `logLevel` | 新增;默认 `silent` |
|
|
92
|
-
| `debug` | 移除;仅保留迁移读取 |
|
|
89
|
+
### 目标
|
|
93
90
|
|
|
94
|
-
|
|
91
|
+
QQ 不能同时发送文字和文件。非图片文件上传后先保存,等待用户下一条文字或语音指令,避免立即触发 pi。
|
|
92
|
+
|
|
93
|
+
### 行为
|
|
94
|
+
|
|
95
|
+
| 情况 | 处理 |
|
|
96
|
+
| ------------ | ------------------------------------------------------------------------------------------------------------- |
|
|
97
|
+
| 只发文件 | 保存到 F11 定义的 session uploads 目录;加入 pending 队列;不回复;不调用 `sendUserMessage` / `markQQTrigger` |
|
|
98
|
+
| 连续上传文件 | 追加到同一 pending 队列;不回复 |
|
|
99
|
+
| 下一条文字 | 合并 pending 文件与当前文件,`formatFilePrompt(files, text)` 后 `sendUserMessage`;清空 pending;触发 run |
|
|
100
|
+
| 下一条语音 | 用 ASR 文本作为指令,合并 pending 文件;清空 pending |
|
|
101
|
+
| `/new` | 清空 pending |
|
|
102
|
+
| 其他 QQ 命令 | 不消费 pending,命令行为不变 |
|
|
103
|
+
| 图片 | 保持 v1 行为;图片可以随文字发送,不进入 pending |
|
|
104
|
+
|
|
105
|
+
- 部分文件保存失败:只把成功文件加入 pending,并回复失败清单。
|
|
106
|
+
- 文件消息不回复确认,不触发 agent run。
|
|
107
|
+
- pending 状态只保存在当前会话内存;pi 重启后丢失,已落盘文件仍保留。
|
|
108
|
+
- pending 文件按保存顺序合并;消费后清空,不重复注入。
|
|
109
|
+
|
|
110
|
+
### 代码边界
|
|
111
|
+
|
|
112
|
+
- `src/inbound.ts`:维护 pending 队列;文件消息先入队,下一条文字/语音指令出队并合并。
|
|
113
|
+
- `/new` 命令清空 pending。
|
|
114
|
+
- 图片路径不变。
|
|
115
|
+
|
|
116
|
+
### 验收
|
|
117
|
+
|
|
118
|
+
- 只发文件:文件已保存,不回复,`sendUserMessage` / `markQQTrigger` 均未调用。
|
|
119
|
+
- 文件后发文字:只触发一次 run,提示词包含文件路径和文字指令。
|
|
120
|
+
- 连续两个文件后发文字:两个文件路径都在提示词中。
|
|
121
|
+
- 文件后发语音:ASR 文本与文件一起注入。
|
|
122
|
+
- `/new`:pending 被清空。
|
|
123
|
+
- 文件保存失败:不进入 pending,仍回复失败信息。
|
|
124
|
+
- 图片、普通文字、既有文件+文字行为不变。
|
|
125
|
+
|
|
126
|
+
## 5. F11 文件存储与去重
|
|
127
|
+
|
|
128
|
+
### 路径
|
|
129
|
+
|
|
130
|
+
- 非图片文件保存到:
|
|
131
|
+
```text
|
|
132
|
+
<cwd>/.pi/pi-qq/<sessionId>/uploads/
|
|
133
|
+
```
|
|
134
|
+
- `sessionId` 来自 `ctx.sessionManager.getSessionId()`。
|
|
135
|
+
- 不再使用日期目录或 `msgId` 子目录。
|
|
136
|
+
- 文件名使用清理后的 basename;同名文件通过后缀区分。
|
|
137
|
+
|
|
138
|
+
### 索引
|
|
139
|
+
|
|
140
|
+
索引文件:
|
|
141
|
+
|
|
142
|
+
```text
|
|
143
|
+
<cwd>/.pi/pi-qq/<sessionId>/uploads/.index.json
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
格式只记录文件名和内容摘要,不记录完整路径:
|
|
147
|
+
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"a.txt": "<sha256>",
|
|
151
|
+
"a-1.txt": "<sha256>"
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### 保存规则
|
|
156
|
+
|
|
157
|
+
| 情况 | 处理 |
|
|
158
|
+
| -------------------- | ------------------------------------------------------------ |
|
|
159
|
+
| 文件名不重复 | 保存文件;计算 SHA-256;写入索引;引用文件 |
|
|
160
|
+
| 文件名重复,内容不同 | 保存为下一个可用文件名(如 `a-1.txt`);写入索引;引用新文件 |
|
|
161
|
+
| 文件名重复,内容相同 | 不保存新文件;复用已有文件路径 |
|
|
162
|
+
|
|
163
|
+
- 只有文件名重复时才比较内容摘要;文件名不重复时即使内容已存在于其他文件名下,也按规则保存新文件。
|
|
164
|
+
- 文件名重复且内容不同时,从 `name-1.ext` 开始寻找可用文件名;如果该后缀文件已存在且内容相同,复用该后缀文件。
|
|
165
|
+
- 文件名重复且内容相同,复用已有同名文件,不生成副本。
|
|
166
|
+
- 图片、语音不进入该文件索引。
|
|
167
|
+
|
|
168
|
+
### 索引维护
|
|
169
|
+
|
|
170
|
+
- QQ 登录 / 会话启动时加载索引:
|
|
171
|
+
- 对每个 `fileName` 检查 `uploads/fileName` 是否存在。
|
|
172
|
+
- 文件不存在则删除对应索引项。
|
|
173
|
+
- 只做存在性检查,不读取文件内容,不重新计算 hash。
|
|
174
|
+
- 索引有变化才原子写回。
|
|
175
|
+
- 保存或复用文件前再次检查目标文件是否存在;不存在则删除索引项并按新文件处理。
|
|
176
|
+
- 索引缺失或损坏时从空索引开始;遇到同名文件时再计算已有文件 hash 并补写索引。
|
|
177
|
+
- 文件保存与索引更新按用户消息串行执行;当前消息处理完成前不处理下一条,避免并发覆盖索引。
|
|
178
|
+
- 索引写入失败只记 warn,不影响文件保存和消息处理。
|
|
179
|
+
- 不新增配置参数。
|
|
180
|
+
|
|
181
|
+
### 与 pending 的关系
|
|
182
|
+
|
|
183
|
+
- 同名同内容重复上传:只返回一个 `SavedFile`,pending 不重复加入。
|
|
184
|
+
- 不同文件名但内容相同:按规则保存两份,pending 保留两个路径。
|
|
185
|
+
|
|
186
|
+
### 验收
|
|
187
|
+
|
|
188
|
+
- 文件保存到 `.pi/pi-qq/<sessionId>/uploads/`,不再出现日期 / `msgId` 目录。
|
|
189
|
+
- 索引文件只包含文件名到 SHA-256 的映射。
|
|
190
|
+
- 文件名不重复:保存并引用。
|
|
191
|
+
- 同名不同内容:保存为 `name-1.ext` 并引用新文件。
|
|
192
|
+
- 同名同内容:不新增文件,复用已有路径。
|
|
193
|
+
- 登录 / 会话启动:删除指向不存在文件的索引项,且不重新计算所有文件 hash。
|
|
194
|
+
- 索引缺失或损坏:同名文件仍能通过现有文件 hash 正确判断。
|
|
195
|
+
- 索引写入失败不影响文件保存和消息处理。
|
|
196
|
+
|
|
197
|
+
## 6. 配置变更
|
|
198
|
+
|
|
199
|
+
| 配置 | 变更 |
|
|
200
|
+
| ---------- | -------------------- |
|
|
201
|
+
| `logLevel` | 新增;默认 `silent` |
|
|
202
|
+
| `debug` | 移除;仅保留迁移读取 |
|
|
203
|
+
|
|
204
|
+
## 7. 限制
|
|
95
205
|
|
|
96
206
|
- `asr_refer_text` 可能为空或识别不准确;V2 只提示用户重发或改用文字,不做回退。
|
|
97
207
|
- `debug` 日志可能包含消息正文和 URL token,仅在排查时本地开启。
|
|
208
|
+
- 文件 pending 不跨 pi 重启;未消费的文件仍保留在 `.pi/pi-qq/<sessionId>/uploads/` 下。
|
|
209
|
+
- 索引信任写入时的 hash;如果用户手动修改同名文件内容,登录时的存在性检查不会发现。
|
package/doc/plan-v1.md
CHANGED
|
@@ -12,11 +12,11 @@ npm init -y
|
|
|
12
12
|
npm i @tencent-connect/qqbot-nodejs @tencent-connect/qqbot-connector qrcode-terminal
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
| 包
|
|
16
|
-
|
|
|
17
|
-
| `@tencent-connect/qqbot-nodejs`
|
|
18
|
-
| `@tencent-connect/qqbot-connector` | ^1.2.0
|
|
19
|
-
| `qrcode-terminal`
|
|
15
|
+
| 包 | 版本锚点 | 用途 |
|
|
16
|
+
| ---------------------------------- | -------- | ------------------------------------------------------------------ |
|
|
17
|
+
| `@tencent-connect/qqbot-nodejs` | ^1.0.5 | QQ 协议层(本地另有源码 `/home/chen/project/qqbot-nodejs` 可查阅) |
|
|
18
|
+
| `@tencent-connect/qqbot-connector` | ^1.2.0 | 扫码登录(唯一登录方式) |
|
|
19
|
+
| `qrcode-terminal` | ^0.12 | 二维码 ASCII 渲染(零依赖) |
|
|
20
20
|
|
|
21
21
|
开发加载方式:`pi --extension /home/chen/project/pi-qq`(jiti 直接跑 TS,无需构建)。
|
|
22
22
|
|
|
@@ -45,13 +45,13 @@ pi-qq/
|
|
|
45
45
|
|
|
46
46
|
## 2. pi 事件与 SDK 接线总表
|
|
47
47
|
|
|
48
|
-
| 方向
|
|
49
|
-
|
|
|
50
|
-
| QQ → pi | `bot.on("message")`(kind=c2c)
|
|
51
|
-
| pi → QQ | `message_update`(assistant)
|
|
52
|
-
| pi → QQ | `message_end`(assistant)
|
|
53
|
-
| 状态
|
|
54
|
-
| 收尾
|
|
48
|
+
| 方向 | 信号 | 处理 |
|
|
49
|
+
| ------- | ------------------------------------ | --------------------------------------------------------------------------------------------------- |
|
|
50
|
+
| QQ → pi | `bot.on("message")`(kind=c2c) | 白名单 → QQ 命令(`/new` `/stop` `/compact` `/status` `/help`)→ 文本+图片 → `pi.sendUserMessage()` |
|
|
51
|
+
| pi → QQ | `message_update`(assistant) | 流式:`openStream().update(转换后全文)`,节流 ≥300ms |
|
|
52
|
+
| pi → QQ | `message_end`(assistant) | `stream.complete()`;无流上下文时 `sendText`;`stopReason==="error"` 回错误摘要 |
|
|
53
|
+
| 状态 | `session_start` / `session_shutdown` | 有内存登录态则启动 bot / 幂等停止 |
|
|
54
|
+
| 收尾 | `agent_end` | 封口最后一个流式气泡(DONE);不再发送用量摘要 |
|
|
55
55
|
|
|
56
56
|
## 3. 里程碑
|
|
57
57
|
|
|
@@ -111,13 +111,13 @@ pi-qq/
|
|
|
111
111
|
|
|
112
112
|
## 5. 风险与预案
|
|
113
113
|
|
|
114
|
-
| 风险
|
|
115
|
-
|
|
|
116
|
-
| 流式消息对非 C2C/过期 `msgId` 抛错
|
|
117
|
-
| 被动额度耗尽(长 run 多回复)
|
|
118
|
-
| markdown 转换漏判
|
|
119
|
-
| connector 混淆代码异常 / 扫码接口变更 | 无法登录
|
|
120
|
-
| pi 事件在非 TUI 模式无 UI
|
|
114
|
+
| 风险 | 影响 | 预案 |
|
|
115
|
+
| ------------------------------------- | ------------- | ------------------------------------------------------- |
|
|
116
|
+
| 流式消息对非 C2C/过期 `msgId` 抛错 | 流式路径崩溃 | `openStream` 前置校验,失败即降级 `sendText`(M4 已含) |
|
|
117
|
+
| 被动额度耗尽(长 run 多回复) | 消息发不出去 | reply-budget 统一发牌,超限降级主动+提示;摘要固定合并 |
|
|
118
|
+
| markdown 转换漏判 | QQ 端残留记号 | 转换函数单测覆盖常见结构;允许透传开关兜底 |
|
|
119
|
+
| connector 混淆代码异常 / 扫码接口变更 | 无法登录 | 重试扫码;升级 connector;保留日志排查 |
|
|
120
|
+
| pi 事件在非 TUI 模式无 UI | 扩展报错 | 所有 `ctx.ui` 调用前判 `ctx.hasUI`/`ctx.mode` |
|
|
121
121
|
|
|
122
122
|
## 6. Todo-List(随进度勾选)
|
|
123
123
|
|
package/doc/plan-v2.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# pi-qq — plan-v2.md
|
|
2
2
|
|
|
3
3
|
> 执行计划。功能范围见 [features-v2.md](./features-v2.md);本文只回答:改哪些文件、按什么顺序做、每步怎么验收。
|
|
4
|
-
> V2 范围:F8 语音自动转写、F9
|
|
4
|
+
> V2 范围:F8 语音自动转写、F9 轻量日志基础设施、F10 文件消息等待指令、F11 文件存储与去重。不引入新依赖。
|
|
5
5
|
|
|
6
6
|
## 0. 前置与范围
|
|
7
7
|
|
|
@@ -19,7 +19,8 @@ pi-qq/
|
|
|
19
19
|
│ ├── logger.ts # 新增:级别过滤、JSONL、按天单文件、SDK logger 适配
|
|
20
20
|
│ ├── voice.ts # 新增:语音附件判断、ASR 文本提取
|
|
21
21
|
│ ├── config.ts # 修改:logLevel、旧 debug 迁移
|
|
22
|
-
│ ├── inbound.ts # 修改:语音分支 + 日志分级
|
|
22
|
+
│ ├── inbound.ts # 修改:语音分支 + 日志分级 + pending + session uploads
|
|
23
|
+
│ ├── files.ts # 修改:session uploads、SHA-256 去重、索引维护
|
|
23
24
|
│ ├── bot.ts # 修改:接入 logger,移除 debug 选项
|
|
24
25
|
│ ├── index.ts # 修改:配置 logger,移除 getDebug,日志分级
|
|
25
26
|
│ ├── outbound.ts # 修改:发送日志分级
|
|
@@ -29,6 +30,7 @@ pi-qq/
|
|
|
29
30
|
│ ├── voice.test.ts # 新增
|
|
30
31
|
│ ├── config.test.ts # 新增或扩展现有设置测试
|
|
31
32
|
│ ├── inbound.test.ts # 修改
|
|
33
|
+
│ ├── bot.test.ts # 新增:message handler 串行回归
|
|
32
34
|
│ └── run-feedback.test.ts # 修改
|
|
33
35
|
├── README.md # 修改:logLevel、日志路径、语音说明
|
|
34
36
|
└── doc/features-v2.md # 已存在,按实现结果校正
|
|
@@ -148,7 +150,53 @@ pi-qq/
|
|
|
148
150
|
- 语音消息不会出现在 `saveInboundFiles()` 的附件参数中。
|
|
149
151
|
- 空 ASR 不会启动 agent。
|
|
150
152
|
|
|
151
|
-
### M5b-3 —
|
|
153
|
+
### M5b-3 — F10 文件消息等待指令
|
|
154
|
+
|
|
155
|
+
**改动**
|
|
156
|
+
|
|
157
|
+
1. `src/inbound.ts` 增加 pending 文件队列,仅处理非图片文件:
|
|
158
|
+
- 文件消息保存后入队,不回复,不调用 `sendUserMessage` / `markQQTrigger`。
|
|
159
|
+
- 下一条文字或语音 ASR 文本出队,合并后走现有 `formatFilePrompt()`。
|
|
160
|
+
- 消费后清空;`/new` 清空;其他命令不消费。
|
|
161
|
+
- 部分失败只入队成功文件;图片、普通文字、文件+文字行为不变。
|
|
162
|
+
2. 更新 `test/inbound.test.ts`:
|
|
163
|
+
- 文件-only:保存、不回复、不发送 user message、不触发 run。
|
|
164
|
+
- 文件后文字:一次 run,提示词包含路径和文字。
|
|
165
|
+
- 连续文件:多个路径合并。
|
|
166
|
+
- 文件后语音:ASR 文本参与合并。
|
|
167
|
+
- `/new` 清空 pending。
|
|
168
|
+
|
|
169
|
+
**验证**
|
|
170
|
+
|
|
171
|
+
- `npm test -- test/inbound.test.ts` 通过。
|
|
172
|
+
- 文件-only 不启动 agent;下一条指令只启动一次。
|
|
173
|
+
- 图片行为与 v1 一致。
|
|
174
|
+
|
|
175
|
+
### M5b-4 — F11 文件存储与去重
|
|
176
|
+
|
|
177
|
+
**改动**
|
|
178
|
+
|
|
179
|
+
1. `src/inbound.ts`:文件保存路径改为 `<cwd>/.pi/pi-qq/<sessionId>/uploads/`,sessionId 来自 `ctx.sessionManager.getSessionId()`。
|
|
180
|
+
2. `src/files.ts`:
|
|
181
|
+
- 增加 `.index.json` 读写:`{ "<fileName>": "<sha256>" }`。
|
|
182
|
+
- 文件名不重复:保存、计算 SHA-256、写索引、引用。
|
|
183
|
+
- 同名不同内容:保存为下一个可用后缀名,写索引、引用新文件。
|
|
184
|
+
- 同名同内容:不保存,复用已有路径。
|
|
185
|
+
- 登录/会话启动:只检查索引中的文件是否存在,删除失效项;不重算所有 hash。
|
|
186
|
+
- 保存/复用前再次检查目标文件存在性;索引缺失或损坏时按需计算已有文件 hash。
|
|
187
|
+
- `bot.ts` 的 message handler 必须 await `onMessage`,让 SDK concurrencyGuard 持有锁到文件保存完成。
|
|
188
|
+
3. 更新 `test/files.test.ts` / `test/inbound.test.ts`:
|
|
189
|
+
- 路径、索引格式、三类保存规则。
|
|
190
|
+
- 删除文件后的索引清理与惰性回退。
|
|
191
|
+
- pending 同名同内容不重复入队;不同文件名同内容保留两份。
|
|
192
|
+
|
|
193
|
+
**验证**
|
|
194
|
+
|
|
195
|
+
- `npm test -- test/files.test.ts test/inbound.test.ts` 通过。
|
|
196
|
+
- 登录/会话启动只做存在性检查,不读取文件内容。
|
|
197
|
+
- 同名同内容不新增文件;同名不同内容生成后缀文件。
|
|
198
|
+
|
|
199
|
+
### M5b-5 — 文档与清理
|
|
152
200
|
|
|
153
201
|
**改动**
|
|
154
202
|
|
|
@@ -170,7 +218,7 @@ pi-qq/
|
|
|
170
218
|
|
|
171
219
|
### 准备
|
|
172
220
|
|
|
173
|
-
- [x] 阅读 `doc/features-v2.md`,确认范围仅为 F8/F9
|
|
221
|
+
- [x] 阅读 `doc/features-v2.md`,确认范围仅为 F8/F9/F10/F11
|
|
174
222
|
- [x] 运行基线 `npm test`、`npm run typecheck`
|
|
175
223
|
- [x] 确认不新增 npm 依赖
|
|
176
224
|
|
|
@@ -199,10 +247,34 @@ pi-qq/
|
|
|
199
247
|
- [x] `test/inbound.test.ts`:有 ASR / 空 ASR / 不保存文件
|
|
200
248
|
- [x] 确认文字、图片、文件用例不回归
|
|
201
249
|
|
|
250
|
+
### F10 — 文件等待指令
|
|
251
|
+
|
|
252
|
+
- [x] `src/inbound.ts`:pending 文件队列
|
|
253
|
+
- [x] 文件-only:保存后不回复,不启动 run
|
|
254
|
+
- [x] 下一条文字/语音:合并 pending 文件后注入
|
|
255
|
+
- [x] `/new` 清空 pending
|
|
256
|
+
- [x] `test/inbound.test.ts`:pending 队列相关用例
|
|
257
|
+
- [x] 图片、文字、文件+文字行为不回归
|
|
258
|
+
- [x] QQ 实机文件等待指令验收
|
|
259
|
+
|
|
260
|
+
### F11 — 文件存储与去重
|
|
261
|
+
|
|
262
|
+
- [x] `inbound.ts`:session uploads 路径
|
|
263
|
+
- [x] `files.ts`:`.index.json` 读写
|
|
264
|
+
- [x] 文件名不重复:保存并索引
|
|
265
|
+
- [x] 同名不同内容:生成后缀文件
|
|
266
|
+
- [x] 同名同内容:复用已有文件
|
|
267
|
+
- [x] 登录/会话启动:清理不存在文件的索引项
|
|
268
|
+
- [x] 惰性检查:复用前确认文件仍存在
|
|
269
|
+
- [x] `test/files.test.ts` / `test/inbound.test.ts`:去重与索引用例
|
|
270
|
+
- [x] `bot.ts`:await message handler,确保文件保存串行
|
|
271
|
+
- [x] `test/bot.test.ts`:handler await 回归
|
|
272
|
+
- [x] QQ 实机文件去重验收(并发文件上传重测)
|
|
273
|
+
|
|
202
274
|
### 文档与收尾
|
|
203
275
|
|
|
204
|
-
- [x] `README.md`:`logLevel
|
|
205
|
-
- [x] `doc/features-v2.md
|
|
276
|
+
- [x] `README.md`:`logLevel`、日志路径、语音说明、文件等待指令、文件去重
|
|
277
|
+
- [x] `doc/features-v2.md`:F8/F9/F10/F11 与实现保持一致
|
|
206
278
|
- [x] 清理临时调试说明
|
|
207
279
|
- [x] `npm test`
|
|
208
280
|
- [x] `npm run typecheck`
|
|
@@ -228,18 +300,32 @@ pi-qq/
|
|
|
228
300
|
6. `logLevel: "debug"`:日志文件包含 `asr_refer_text` 和完整附件;`info` 不含正文。
|
|
229
301
|
7. 旧配置 `debug: true` 仍能开启 debug 日志。
|
|
230
302
|
8. 文字、图片、文件消息行为与 v1 一致。
|
|
303
|
+
9. 只发文件:不回复,不启动 run。
|
|
304
|
+
10. 文件后发文字/语音:只启动一次 run,提示词包含文件路径和指令。
|
|
305
|
+
11. 连续上传多个文件:下一条指令合并全部文件。
|
|
306
|
+
12. `/new` 后 pending 清空。
|
|
307
|
+
13. 文件保存到 `.pi/pi-qq/<sessionId>/uploads/`。
|
|
308
|
+
14. 文件名不重复:保存并引用。
|
|
309
|
+
15. 同名不同内容:生成 `name-1.ext` 并引用。
|
|
310
|
+
16. 同名同内容:不新增文件,复用已有路径。
|
|
311
|
+
17. 删除文件后登录/会话启动清理索引,且不重算所有 hash。
|
|
231
312
|
|
|
232
313
|
## 5. 风险与预案
|
|
233
314
|
|
|
234
|
-
| 风险
|
|
235
|
-
|
|
|
236
|
-
| ASR 为空或识别不准
|
|
237
|
-
| 平台只返回 `voice` 的假定失效
|
|
238
|
-
| 日志目录不可写
|
|
239
|
-
| 默认 `silent` 导致排查时无日志 | 诊断困难
|
|
240
|
-
| 移除 debug 时间戳影响现有诊断
|
|
315
|
+
| 风险 | 影响 | 预案 |
|
|
316
|
+
| ------------------------------ | --------------- | -------------------------------------------------- |
|
|
317
|
+
| ASR 为空或识别不准 | 语音无法转写 | 回复提示重发或打字;V2 不做语音回退 |
|
|
318
|
+
| 平台只返回 `voice` 的假定失效 | 语音分支不触发 | 以实测字段为准;若变化再扩展识别条件 |
|
|
319
|
+
| 日志目录不可写 | 无日志 | 捕获写入异常,消息处理继续 |
|
|
320
|
+
| 默认 `silent` 导致排查时无日志 | 诊断困难 | README 明确开启 `logLevel: "info"` / `"debug"` |
|
|
321
|
+
| 移除 debug 时间戳影响现有诊断 | QQ 气泡少时间戳 | 已确认日志级别不影响聊天展示;需要时后续加独立开关 |
|
|
241
322
|
|
|
242
323
|
## 6. 执行记录
|
|
243
324
|
|
|
244
325
|
- 2026-10-30:M5a / M5b 代码与单测完成;`npm test` 97 项通过,`npm run typecheck`、`npm run format:check` 通过。
|
|
245
326
|
- 2026-10-30:QQ 实机语音验收通过。两条语音均直接使用 `asr_refer_text` 进入 pi;未保存 `.amr`,未调用本地转写工具;`logLevel: "debug"` 日志包含 ASR 元数据与全文。
|
|
327
|
+
- 2026-10-30:F10 文件等待指令实现完成;`npm test` 101 项通过,`typecheck`、`format:check` 通过。
|
|
328
|
+
- 2026-10-30:QQ 实机文件等待指令验收通过。文件-only 无回复、无 run;后续文字指令正确合并 1 个和 2 个 pending 文件并读取。
|
|
329
|
+
- 2026-10-30:F11 文件存储与去重实现完成;`npm test` 109 项通过,`typecheck`、`format:check` 通过。
|
|
330
|
+
- 2026-10-30:实机测试发现两条文件消息并发时索引互相覆盖(`c.txt` 文件存在但索引缺失)。根因是 `bot.ts` 的 message handler 未 await `onMessage`,导致 `concurrencyGuard` 提前释放锁。已修复并新增 `test/bot.test.ts`。
|
|
331
|
+
- 2026-10-30:F11 实机重测通过。`c.txt` / `b.txt` 快速连续上传后索引同时保留两项;`a.txt` / `d.txt` 不同文件名同内容按规则保留两份;索引共 4 项。
|
package/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { AppendStream } from "./src/append-stream";
|
|
|
11
11
|
import { formatTokenCount } from "./src/format";
|
|
12
12
|
import { formatBudgetStatus } from "./src/budget-status";
|
|
13
13
|
import { configureLogger, log, previewForLog } from "./src/logger";
|
|
14
|
+
import { pruneUploadIndex, sessionUploadDir } from "./src/files";
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* pi-qq extension entry.
|
|
@@ -90,9 +91,14 @@ export default function (pi: ExtensionAPI) {
|
|
|
90
91
|
|
|
91
92
|
// —— Login and connection ——
|
|
92
93
|
|
|
93
|
-
const startWithCredentials = (ctx: ExtensionContext, creds: Credentials, allowedOpenid: string) => {
|
|
94
|
+
const startWithCredentials = async (ctx: ExtensionContext, creds: Credentials, allowedOpenid: string) => {
|
|
94
95
|
const settings = getSettings(readConfig().config);
|
|
95
96
|
configureLogger(settings.logLevel, join(ctx.cwd, ".pi", "pi-qq", "logs"));
|
|
97
|
+
running?.stop();
|
|
98
|
+
stateDetail = undefined;
|
|
99
|
+
sessionCtx = ctx;
|
|
100
|
+
const uploadDir = sessionUploadDir(ctx.cwd, ctx.sessionManager.getSessionId());
|
|
101
|
+
const uploadIndex = await pruneUploadIndex(uploadDir);
|
|
96
102
|
log.info("session", "starting bot", {
|
|
97
103
|
appId: creds.appId,
|
|
98
104
|
allowedOpenid,
|
|
@@ -100,10 +106,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
100
106
|
model: ctx.model?.name ?? null,
|
|
101
107
|
markdownSupport: settings.markdownSupport,
|
|
102
108
|
logLevel: settings.logLevel,
|
|
109
|
+
uploadDir,
|
|
110
|
+
indexedFiles: Object.keys(uploadIndex).length,
|
|
103
111
|
});
|
|
104
|
-
running?.stop();
|
|
105
|
-
stateDetail = undefined;
|
|
106
|
-
sessionCtx = ctx;
|
|
107
112
|
running = startBot({
|
|
108
113
|
credentials: creds,
|
|
109
114
|
allowedOpenid,
|
|
@@ -143,7 +148,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
143
148
|
|
|
144
149
|
// —— Lifecycle ——
|
|
145
150
|
|
|
146
|
-
pi.on("session_start", (_event, ctx) => {
|
|
151
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
147
152
|
const { config, error } = readConfig();
|
|
148
153
|
const settings = getSettings(config);
|
|
149
154
|
configureLogger(settings.logLevel, join(ctx.cwd, ".pi", "pi-qq", "logs"));
|
|
@@ -159,7 +164,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
159
164
|
configError: error ?? null,
|
|
160
165
|
});
|
|
161
166
|
if (login) {
|
|
162
|
-
startWithCredentials(ctx, login.credentials, login.allowedOpenid);
|
|
167
|
+
await startWithCredentials(ctx, login.credentials, login.allowedOpenid);
|
|
163
168
|
} else if (ctx.hasUI) {
|
|
164
169
|
ctx.ui.notify("pi-qq: run /qq-login to scan a QR code.", "warning");
|
|
165
170
|
}
|
|
@@ -297,7 +302,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
297
302
|
|
|
298
303
|
const credentials: Credentials = { appId: result.appId, appSecret: result.appSecret };
|
|
299
304
|
setLoginState({ credentials, allowedOpenid: result.userOpenid });
|
|
300
|
-
startWithCredentials(ctx, credentials, result.userOpenid);
|
|
305
|
+
await startWithCredentials(ctx, credentials, result.userOpenid);
|
|
301
306
|
},
|
|
302
307
|
});
|
|
303
308
|
|
|
@@ -320,7 +325,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
320
325
|
handler: async (_args, ctx) => {
|
|
321
326
|
stopIfRunning();
|
|
322
327
|
setLoginState(undefined);
|
|
323
|
-
ctx.ui.notify("pi-qq logged out.
|
|
328
|
+
ctx.ui.notify("pi-qq logged out.", "info");
|
|
324
329
|
},
|
|
325
330
|
});
|
|
326
331
|
|
package/package.json
CHANGED
package/src/bot.ts
CHANGED
|
@@ -83,7 +83,7 @@ export function startBot(opts: StartBotOptions): RunningBot {
|
|
|
83
83
|
log.error("bot", "error event", { err });
|
|
84
84
|
opts.onRecoverableError?.(err);
|
|
85
85
|
});
|
|
86
|
-
bot.on("message", (_ctx, msg) => {
|
|
86
|
+
bot.on("message", async (_ctx, msg) => {
|
|
87
87
|
log.debug("bot", "inbound message", {
|
|
88
88
|
kind: msg.kind,
|
|
89
89
|
rawEventType: msg.rawEventType,
|
|
@@ -102,9 +102,11 @@ export function startBot(opts: StartBotOptions): RunningBot {
|
|
|
102
102
|
msgElements: msg.msgElements,
|
|
103
103
|
raw: msg.raw,
|
|
104
104
|
});
|
|
105
|
-
|
|
105
|
+
try {
|
|
106
|
+
await opts.onMessage?.(bot, msg);
|
|
107
|
+
} catch (err) {
|
|
106
108
|
log.error("bot", "message handler rejected", { err });
|
|
107
|
-
}
|
|
109
|
+
}
|
|
108
110
|
});
|
|
109
111
|
|
|
110
112
|
let stopped = false;
|
package/src/files.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
/** Save QQ non-image attachments in the workspace
|
|
2
|
-
import {
|
|
1
|
+
/** Save QQ non-image attachments in the workspace, with session-scoped deduplication. */
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { mkdir, readFile, rename, stat, writeFile } from "node:fs/promises";
|
|
3
4
|
import { basename, extname, join } from "node:path";
|
|
4
5
|
import { downloadLimited, type InboundAttachmentLike } from "./download";
|
|
5
6
|
import { formatBytes } from "./format";
|
|
7
|
+
import { log } from "./logger";
|
|
6
8
|
|
|
7
9
|
const DOWNLOAD_TIMEOUT_MS = 60_000;
|
|
8
|
-
const
|
|
10
|
+
const UPLOAD_INDEX_FILENAME = ".index.json";
|
|
9
11
|
|
|
10
12
|
export interface SavedFile {
|
|
11
13
|
path: string;
|
|
@@ -18,13 +20,15 @@ export interface FileFailure {
|
|
|
18
20
|
reason: string;
|
|
19
21
|
}
|
|
20
22
|
|
|
23
|
+
/** fileName -> SHA-256. Paths are derived from uploadDir. */
|
|
24
|
+
export type UploadIndex = Record<string, string>;
|
|
25
|
+
|
|
21
26
|
export interface SaveFilesOptions {
|
|
22
27
|
maxSize: number;
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
now?: Date;
|
|
28
|
+
/** `<cwd>/.pi/pi-qq/<sessionId>/uploads`. */
|
|
29
|
+
uploadDir: string;
|
|
30
|
+
/** Test/caller override; loaded from uploadDir when omitted. Mutated in place. */
|
|
31
|
+
index?: UploadIndex;
|
|
28
32
|
fetchImpl?: typeof fetch;
|
|
29
33
|
}
|
|
30
34
|
|
|
@@ -33,18 +37,18 @@ export interface SaveFilesResult {
|
|
|
33
37
|
failures: FileFailure[];
|
|
34
38
|
}
|
|
35
39
|
|
|
36
|
-
function
|
|
37
|
-
|
|
40
|
+
function safePathSegment(key: string): string {
|
|
41
|
+
const cleaned = key.replace(/[^A-Za-z0-9._-]/g, "_").replace(/^[._]+|[._]+$/g, "");
|
|
42
|
+
return cleaned.slice(0, 64) || "session";
|
|
38
43
|
}
|
|
39
44
|
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
/** Session-scoped upload directory; no date or msgId subdirectories. */
|
|
46
|
+
export function sessionUploadDir(cwd: string, sessionId: string): string {
|
|
47
|
+
return join(cwd, ".pi", "pi-qq", safePathSegment(sessionId), "uploads");
|
|
42
48
|
}
|
|
43
49
|
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
const stem = filename.slice(0, filename.length - ext.length);
|
|
47
|
-
return `${stem}-${suffix}${ext}`;
|
|
50
|
+
export function uploadIndexPath(uploadDir: string): string {
|
|
51
|
+
return join(uploadDir, UPLOAD_INDEX_FILENAME);
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
/** Keep only a safe basename (no paths/control/Windows-invalid chars); truncate long stems. */
|
|
@@ -62,22 +66,134 @@ export function sanitizeFilename(filename: string | undefined, fallback: string)
|
|
|
62
66
|
return `${stem.slice(0, maxStemLength)}${ext}`;
|
|
63
67
|
}
|
|
64
68
|
|
|
65
|
-
function
|
|
66
|
-
const
|
|
67
|
-
|
|
69
|
+
function withSuffix(filename: string, suffix: number): string {
|
|
70
|
+
const ext = extname(filename);
|
|
71
|
+
const stem = filename.slice(0, filename.length - ext.length);
|
|
72
|
+
return `${stem}-${suffix}${ext}`;
|
|
68
73
|
}
|
|
69
74
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
function isSafeIndexKey(filename: string): boolean {
|
|
76
|
+
return (
|
|
77
|
+
filename.length > 0 &&
|
|
78
|
+
filename !== "." &&
|
|
79
|
+
filename !== ".." &&
|
|
80
|
+
filename !== UPLOAD_INDEX_FILENAME &&
|
|
81
|
+
basename(filename) === filename
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function sha256Hex(body: Buffer): string {
|
|
86
|
+
return createHash("sha256").update(body).digest("hex");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function isFile(path: string): Promise<boolean> {
|
|
90
|
+
try {
|
|
91
|
+
return (await stat(path)).isFile();
|
|
92
|
+
} catch {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export async function loadUploadIndex(uploadDir: string): Promise<UploadIndex> {
|
|
98
|
+
try {
|
|
99
|
+
const parsed = JSON.parse(await readFile(uploadIndexPath(uploadDir), "utf8")) as unknown;
|
|
100
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
|
|
101
|
+
const index: UploadIndex = {};
|
|
102
|
+
for (const [filename, hash] of Object.entries(parsed as Record<string, unknown>)) {
|
|
103
|
+
if (isSafeIndexKey(filename) && typeof hash === "string") index[filename] = hash;
|
|
79
104
|
}
|
|
105
|
+
return index;
|
|
106
|
+
} catch {
|
|
107
|
+
return {};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function persistUploadIndex(uploadDir: string, index: UploadIndex): Promise<void> {
|
|
112
|
+
const path = uploadIndexPath(uploadDir);
|
|
113
|
+
const tmp = `${path}.${process.pid}.tmp`;
|
|
114
|
+
try {
|
|
115
|
+
await mkdir(uploadDir, { recursive: true });
|
|
116
|
+
await writeFile(tmp, `${JSON.stringify(index, null, 2)}\n`, "utf8");
|
|
117
|
+
await rename(tmp, path);
|
|
118
|
+
} catch (err) {
|
|
119
|
+
log.warn("files", "failed to write upload index", { path, err });
|
|
80
120
|
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Load the index and drop entries whose files no longer exist. No content hashing. */
|
|
124
|
+
export async function pruneUploadIndex(uploadDir: string): Promise<UploadIndex> {
|
|
125
|
+
const index = await loadUploadIndex(uploadDir);
|
|
126
|
+
let changed = false;
|
|
127
|
+
for (const filename of Object.keys(index)) {
|
|
128
|
+
if (!(await isFile(join(uploadDir, filename)))) {
|
|
129
|
+
delete index[filename];
|
|
130
|
+
changed = true;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (changed) await persistUploadIndex(uploadDir, index);
|
|
134
|
+
return index;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function hashExistingFile(path: string): Promise<string> {
|
|
138
|
+
return sha256Hex(await readFile(path));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async function saveOrReuse(
|
|
142
|
+
uploadDir: string,
|
|
143
|
+
filename: string,
|
|
144
|
+
body: Buffer,
|
|
145
|
+
index: UploadIndex,
|
|
146
|
+
): Promise<{ file: SavedFile; changed: boolean }> {
|
|
147
|
+
const hash = sha256Hex(body);
|
|
148
|
+
const target = join(uploadDir, filename);
|
|
149
|
+
let changed = false;
|
|
150
|
+
|
|
151
|
+
if (!(await isFile(target))) {
|
|
152
|
+
// A stale index entry must not make a missing file look reusable.
|
|
153
|
+
if (index[filename]) {
|
|
154
|
+
delete index[filename];
|
|
155
|
+
changed = true;
|
|
156
|
+
}
|
|
157
|
+
await writeFile(target, body, { flag: "wx" });
|
|
158
|
+
index[filename] = hash;
|
|
159
|
+
return { file: { path: target, originalName: filename, size: body.byteLength }, changed: true };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
let existingHash = index[filename];
|
|
163
|
+
if (!existingHash) {
|
|
164
|
+
existingHash = await hashExistingFile(target);
|
|
165
|
+
index[filename] = existingHash;
|
|
166
|
+
changed = true;
|
|
167
|
+
}
|
|
168
|
+
if (existingHash === hash) {
|
|
169
|
+
return { file: { path: target, originalName: filename, size: body.byteLength }, changed };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
for (let suffix = 1; suffix < 100; suffix++) {
|
|
173
|
+
const candidate = withSuffix(filename, suffix);
|
|
174
|
+
const candidatePath = join(uploadDir, candidate);
|
|
175
|
+
if (await isFile(candidatePath)) {
|
|
176
|
+
let candidateHash = index[candidate];
|
|
177
|
+
if (!candidateHash) {
|
|
178
|
+
candidateHash = await hashExistingFile(candidatePath);
|
|
179
|
+
index[candidate] = candidateHash;
|
|
180
|
+
changed = true;
|
|
181
|
+
}
|
|
182
|
+
if (candidateHash === hash) {
|
|
183
|
+
return { file: { path: candidatePath, originalName: candidate, size: body.byteLength }, changed };
|
|
184
|
+
}
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (index[candidate]) {
|
|
189
|
+
delete index[candidate];
|
|
190
|
+
changed = true;
|
|
191
|
+
}
|
|
192
|
+
await writeFile(candidatePath, body, { flag: "wx" });
|
|
193
|
+
index[candidate] = hash;
|
|
194
|
+
return { file: { path: candidatePath, originalName: candidate, size: body.byteLength }, changed: true };
|
|
195
|
+
}
|
|
196
|
+
|
|
81
197
|
throw new Error("Could not allocate a unique filename");
|
|
82
198
|
}
|
|
83
199
|
|
|
@@ -86,20 +202,25 @@ export async function saveInboundFiles(
|
|
|
86
202
|
attachments: readonly InboundAttachmentLike[],
|
|
87
203
|
options: SaveFilesOptions,
|
|
88
204
|
): Promise<SaveFilesResult> {
|
|
89
|
-
const
|
|
90
|
-
const baseDir = options.baseDir ?? DEFAULT_BASE_DIR;
|
|
91
|
-
const dir = options.dirKey
|
|
92
|
-
? join(baseDir, dateStamp(now), safeDirKey(options.dirKey))
|
|
93
|
-
: join(baseDir, dateStamp(now));
|
|
205
|
+
const uploadDir = options.uploadDir;
|
|
94
206
|
const limit = Math.max(1, options.maxSize);
|
|
95
207
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
96
|
-
|
|
208
|
+
const index = options.index ?? (await loadUploadIndex(uploadDir));
|
|
97
209
|
const files: SavedFile[] = [];
|
|
98
210
|
const failures: FileFailure[] = [];
|
|
99
|
-
|
|
211
|
+
const seenPaths = new Set<string>();
|
|
212
|
+
let indexChanged = false;
|
|
213
|
+
|
|
214
|
+
if (attachments.length > 0) await mkdir(uploadDir, { recursive: true });
|
|
215
|
+
|
|
216
|
+
const addFile = (file: SavedFile) => {
|
|
217
|
+
if (seenPaths.has(file.path)) return;
|
|
218
|
+
seenPaths.add(file.path);
|
|
219
|
+
files.push(file);
|
|
220
|
+
};
|
|
100
221
|
|
|
101
|
-
for (const [
|
|
102
|
-
const fallback = `file-${
|
|
222
|
+
for (const [position, attachment] of attachments.entries()) {
|
|
223
|
+
const fallback = `file-${position + 1}`;
|
|
103
224
|
const filename = sanitizeFilename(attachment.filename, fallback);
|
|
104
225
|
if (typeof attachment.size === "number" && attachment.size > limit) {
|
|
105
226
|
failures.push({ filename, reason: `file too large (${formatBytes(attachment.size)} > ${formatBytes(limit)})` });
|
|
@@ -114,13 +235,15 @@ export async function saveInboundFiles(
|
|
|
114
235
|
kind: "file",
|
|
115
236
|
fetchImpl,
|
|
116
237
|
});
|
|
117
|
-
const
|
|
118
|
-
|
|
238
|
+
const result = await saveOrReuse(uploadDir, filename, body, index);
|
|
239
|
+
indexChanged ||= result.changed;
|
|
240
|
+
addFile(result.file);
|
|
119
241
|
} catch (err) {
|
|
120
242
|
failures.push({ filename, reason: err instanceof Error ? err.message : "Download failed" });
|
|
121
243
|
}
|
|
122
244
|
}
|
|
123
245
|
|
|
246
|
+
if (indexChanged) await persistUploadIndex(uploadDir, index);
|
|
124
247
|
return { files, failures };
|
|
125
248
|
}
|
|
126
249
|
|
package/src/inbound.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { join } from "node:path";
|
|
3
2
|
import type { QQBot, QQBotInboundMessage } from "@tencent-connect/qqbot-nodejs";
|
|
4
3
|
import { sendReply, type ReplyChannel } from "./outbound";
|
|
5
4
|
import type { ReplyBudget } from "./reply-budget";
|
|
@@ -10,7 +9,7 @@ import {
|
|
|
10
9
|
resolveInboundImages,
|
|
11
10
|
type ImageContentLike,
|
|
12
11
|
} from "./images";
|
|
13
|
-
import { formatFilePrompt, saveInboundFiles, type SavedFile } from "./files";
|
|
12
|
+
import { formatFilePrompt, saveInboundFiles, sessionUploadDir, type SavedFile } from "./files";
|
|
14
13
|
import { log } from "./logger";
|
|
15
14
|
import { isVoiceAttachment, resolveVoiceTranscript } from "./voice";
|
|
16
15
|
|
|
@@ -40,6 +39,14 @@ export interface InboundDeps {
|
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
export function createInboundHandler(deps: InboundDeps) {
|
|
42
|
+
// F10: files uploaded without text wait for the next text/voice instruction.
|
|
43
|
+
let pendingFiles: SavedFile[] = [];
|
|
44
|
+
const takePendingFiles = (): SavedFile[] => {
|
|
45
|
+
const files = pendingFiles;
|
|
46
|
+
pendingFiles = [];
|
|
47
|
+
return files;
|
|
48
|
+
};
|
|
49
|
+
|
|
43
50
|
return async (bot: QQBot, msg: QQBotInboundMessage): Promise<void> => {
|
|
44
51
|
log.debug("inbound", "message received", {
|
|
45
52
|
kind: msg.kind,
|
|
@@ -89,7 +96,12 @@ export function createInboundHandler(deps: InboundDeps) {
|
|
|
89
96
|
|
|
90
97
|
const text = (msg.content ?? "").trim();
|
|
91
98
|
if (text.startsWith("/")) {
|
|
92
|
-
|
|
99
|
+
const command = text.split(/\s+/)[0];
|
|
100
|
+
log.info("inbound", "QQ command", { command });
|
|
101
|
+
if (command === "/new" && deps.ctx.isIdle() && pendingFiles.length > 0) {
|
|
102
|
+
log.info("inbound", "cleared pending files for /new", { count: pendingFiles.length });
|
|
103
|
+
pendingFiles = [];
|
|
104
|
+
}
|
|
93
105
|
await handleCommand(text, reply, deps);
|
|
94
106
|
return;
|
|
95
107
|
}
|
|
@@ -116,9 +128,15 @@ export function createInboundHandler(deps: InboundDeps) {
|
|
|
116
128
|
return;
|
|
117
129
|
}
|
|
118
130
|
log.debug("inbound", "voice transcript", { messageId: msg.messageId, transcript });
|
|
131
|
+
const pending = takePendingFiles();
|
|
132
|
+
const promptText = formatFilePrompt(pending, transcript);
|
|
119
133
|
deps.markQQTrigger(msg.senderId, msg.messageId);
|
|
120
|
-
deps.pi.sendUserMessage(
|
|
121
|
-
log.info("inbound", "voice sent to pi", {
|
|
134
|
+
deps.pi.sendUserMessage(promptText, { deliverAs: deps.getDeliverAs() });
|
|
135
|
+
log.info("inbound", "voice sent to pi", {
|
|
136
|
+
messageId: msg.messageId,
|
|
137
|
+
asrLength: transcript.length,
|
|
138
|
+
pendingFiles: pending.length,
|
|
139
|
+
});
|
|
122
140
|
return;
|
|
123
141
|
}
|
|
124
142
|
|
|
@@ -145,10 +163,15 @@ export function createInboundHandler(deps: InboundDeps) {
|
|
|
145
163
|
|
|
146
164
|
let files: SavedFile[] = [];
|
|
147
165
|
if (fileAttachments.length > 0) {
|
|
166
|
+
const uploadDir = sessionUploadDir(deps.ctx.cwd, deps.ctx.sessionManager.getSessionId());
|
|
167
|
+
log.debug("inbound", "saving files", {
|
|
168
|
+
messageId: msg.messageId,
|
|
169
|
+
count: fileAttachments.length,
|
|
170
|
+
uploadDir,
|
|
171
|
+
});
|
|
148
172
|
const result = await saveFiles(fileAttachments, {
|
|
149
173
|
maxSize: deps.getFileMaxSize(),
|
|
150
|
-
|
|
151
|
-
dirKey: msg.messageId,
|
|
174
|
+
uploadDir,
|
|
152
175
|
});
|
|
153
176
|
files = result.files;
|
|
154
177
|
failures.push(...result.failures);
|
|
@@ -170,15 +193,29 @@ export function createInboundHandler(deps: InboundDeps) {
|
|
|
170
193
|
return;
|
|
171
194
|
}
|
|
172
195
|
|
|
196
|
+
// F10: a file-only message waits for the next text/voice instruction.
|
|
197
|
+
if (!text && images.length === 0 && files.length > 0) {
|
|
198
|
+
pendingFiles.push(...files);
|
|
199
|
+
log.info("inbound", "files pending for instruction", {
|
|
200
|
+
messageId: msg.messageId,
|
|
201
|
+
count: files.length,
|
|
202
|
+
pendingCount: pendingFiles.length,
|
|
203
|
+
});
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
173
207
|
// F7: mark a QQ-triggered run; do not send a start confirmation.
|
|
174
208
|
deps.markQQTrigger(msg.senderId, msg.messageId);
|
|
175
|
-
const
|
|
209
|
+
const pending = text ? takePendingFiles() : [];
|
|
210
|
+
const promptFiles = [...pending, ...files];
|
|
211
|
+
const promptText = formatFilePrompt(promptFiles, text);
|
|
176
212
|
deps.pi.sendUserMessage(buildImageMessageContent(promptText, images), { deliverAs: deps.getDeliverAs() });
|
|
177
213
|
log.info("inbound", "sent to pi", {
|
|
178
214
|
messageId: msg.messageId,
|
|
179
215
|
textLength: text.length,
|
|
180
216
|
images: images.length,
|
|
181
|
-
files:
|
|
217
|
+
files: promptFiles.length,
|
|
218
|
+
pendingFiles: pending.length,
|
|
182
219
|
deliverAs: deps.getDeliverAs(),
|
|
183
220
|
});
|
|
184
221
|
};
|