@chen_hu_hu/pi-qq 1.6.0 → 1.6.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/CHANGELOG.md +36 -4
- package/README-zh.md +21 -44
- package/README.md +29 -52
- package/doc/archive/{delivery-v1.md → delivery.1.0.0.md} +1 -1
- package/doc/archive/{delivery-v2.md → delivery.1.2.0.md} +1 -1
- package/doc/archive/{delivery-v3.md → delivery.1.3.0.md} +1 -1
- package/doc/archive/{delivery-v4.md → delivery.1.4.0.md} +1 -1
- package/doc/archive/{delivery-v5.md → delivery.1.5.0.md} +2 -2
- package/doc/archive/{delivery-v6.md → delivery.1.6.0.md} +3 -3
- package/doc/archive/delivery.1.6.1.md +150 -0
- package/doc/archive/delivery.1.6.2.md +196 -0
- package/doc/todo.md +2 -2
- package/index.ts +30 -32
- package/package.json +1 -1
- package/src/attachments/attachment-download.ts +2 -1
- package/src/attachments/file-attachments.ts +4 -5
- package/src/infra/file-logger.ts +6 -6
- package/src/infra/i18n.ts +4 -198
- package/src/infra/log-message-keys.ts +66 -0
- package/src/infra/power-status.ts +1 -11
- package/src/infra/reply-type.ts +1 -1
- package/src/infra/settings.ts +0 -6
- package/src/qq/inbound-attachments.ts +2 -2
- package/src/qq/inbound-command.ts +8 -7
- package/src/qq/media-tool.ts +36 -60
- package/src/qq/qq-bot.ts +1 -1
- package/src/qq/qq-diagnostics.ts +1 -1
- package/src/qq/qq-message-handler.ts +7 -6
- package/src/qq/status-report.ts +1 -13
- package/src/quota/reply-quota.ts +2 -2
- package/src/relay/bubble-writer.ts +84 -38
- package/src/relay/reply-policy.ts +0 -13
- package/src/relay/run-stream-relay.ts +129 -203
- package/src/relay/run-timeline.ts +127 -0
- package/src/relay/stream-block-format.ts +1 -1
- package/src/relay/stream-session.ts +25 -8
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# pi-qq delivery 1.6.2
|
|
2
|
+
|
|
3
|
+
> **Delivery record.** 1.6.2 makes `/last` repush the current run snapshot, hardens stream recovery, removes `replyType: "last"`, and consolidates the code-review and repair notes. See [README](../../README.md) for current user-facing behavior.
|
|
4
|
+
> Version: 1.6.2
|
|
5
|
+
> Date: 2026-11-11
|
|
6
|
+
> Previous: [delivery.1.6.1.md](./delivery.1.6.1.md).
|
|
7
|
+
> Open work: [doc/todo.md](../todo.md).
|
|
8
|
+
|
|
9
|
+
## 1. Scope
|
|
10
|
+
|
|
11
|
+
Before 1.6.2, `/last` during a run only repushed `run.currentText`. If the run was still producing thinking or tools, the command silently did nothing. A separate long-run defect also stopped all relay output when QQ returned `40054005` (duplicate `msgseq`).
|
|
12
|
+
|
|
13
|
+
1.6.2 covers:
|
|
14
|
+
|
|
15
|
+
- `/last` snapshot repush for `replyType: "full"`;
|
|
16
|
+
- separation of run content state from stream delivery;
|
|
17
|
+
- removal of `replyType: "last"`;
|
|
18
|
+
- rate-limit retry correctness;
|
|
19
|
+
- fresh-stream recovery for duplicate `msgseq`;
|
|
20
|
+
- English-only log messages;
|
|
21
|
+
- dead-code and duplication cleanup from the full code review;
|
|
22
|
+
- direct tests for the new timeline and writer boundaries.
|
|
23
|
+
|
|
24
|
+
Out of scope:
|
|
25
|
+
|
|
26
|
+
- replaying the complete run history;
|
|
27
|
+
- changing model/agent behavior or tool set;
|
|
28
|
+
- adding tool partial-output forwarding;
|
|
29
|
+
- docs packaging changes and optional large refactors listed in section 8.
|
|
30
|
+
|
|
31
|
+
## 2. Observed failure
|
|
32
|
+
|
|
33
|
+
The 2026-11-11 log contained a 26-minute run that reached 221 stream bubbles. At 12:55:19 local time the next stream used a previously used `msg_seq`:
|
|
34
|
+
|
|
35
|
+
```text
|
|
36
|
+
40054005 消息被去重,请检查请求msgseq
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The same checkpoint `msgSeq` was retried twice, all retries were rejected, and `BubbleWriter` killed the stream. After that:
|
|
40
|
+
|
|
41
|
+
- 146 subsequent tool starts produced no relay output;
|
|
42
|
+
- `/last` at 13:01:44 and 13:04:21 logged `last repush ignored` with `textLength=0`;
|
|
43
|
+
- the first assistant text appeared at 13:09:56, after both `/last` calls;
|
|
44
|
+
- the final text used the normal plain-message fallback.
|
|
45
|
+
|
|
46
|
+
The `/last` calls did not fail because the text was too old; at that moment there was no `currentText` at all. The run state and the delivery writer were coupled, so `/last` could not use the thinking/tool state.
|
|
47
|
+
|
|
48
|
+
## 3. Final decisions
|
|
49
|
+
|
|
50
|
+
| # | Question | Decision |
|
|
51
|
+
| --- | ------------------------------------------------------ | -------------------------------------------------------------------------------------------------------- |
|
|
52
|
+
| D1 | What should `/last` push during a full-mode run? | The current thinking, the active/recent tools, and the current text, without waiting for assistant text. |
|
|
53
|
+
| D2 | How much history should `/last` replay? | A bounded state snapshot: current active tool plus the last three finished tools, capped at five. |
|
|
54
|
+
| D3 | Should run state depend on the writer? | No. `RunTimeline` owns content and tool lifecycle; `RunFeedback` decides delivery. |
|
|
55
|
+
| D4 | What should happen on `40054005`? | Open a new stream with a fresh `msgSeq`, replay the failed buffer, and keep the existing recovery cap. |
|
|
56
|
+
| D5 | Should `replyType: "last"` remain? | No. Keep only `full` and `simple`; old `"last"` values fall back to `full` with a validation warning. |
|
|
57
|
+
| D6 | Should log files follow `language`? | No. Log messages are written directly in English; `language` only affects UI notifications and replies. |
|
|
58
|
+
| D7 | Should `/last` fail silently when there is no content? | No. Reply with `commands.last.empty`. |
|
|
59
|
+
|
|
60
|
+
## 4. `/last` snapshot
|
|
61
|
+
|
|
62
|
+
`repushCurrent()` now builds a `RepushResult` instead of returning a bare boolean:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
type RepushResult =
|
|
66
|
+
| { ok: true; thinkingLength: number; toolCount: number; textLength: number }
|
|
67
|
+
| { ok: false; reason: "no-run" | "empty" };
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Full-mode snapshot order:
|
|
71
|
+
|
|
72
|
+
1. current thinking;
|
|
73
|
+
2. current active tool and recent finished tools in start order;
|
|
74
|
+
3. current assistant text.
|
|
75
|
+
|
|
76
|
+
`BubbleWriter.restartSnapshot()` accepts structured blocks and:
|
|
77
|
+
|
|
78
|
+
- closes an open code fence;
|
|
79
|
+
- rotates the old stream;
|
|
80
|
+
- updates the target `openid` / `msgId`;
|
|
81
|
+
- resets `streamDead`, pending resume, block and fence state;
|
|
82
|
+
- pushes thinking/tool/text blocks to the new stream.
|
|
83
|
+
|
|
84
|
+
`simple` mode uses a text-only snapshot. `last` mode no longer exists.
|
|
85
|
+
|
|
86
|
+
After a repush:
|
|
87
|
+
|
|
88
|
+
- `thinkingSentLen` / `resultSentLen` are not reset; they continue tracking processed content;
|
|
89
|
+
- deferred thinking/text are cleared because the snapshot already includes them;
|
|
90
|
+
- an active tool result and subsequent assistant deltas continue on the new stream.
|
|
91
|
+
|
|
92
|
+
## 5. Stream reliability
|
|
93
|
+
|
|
94
|
+
### 5.1 Rate-limit retries
|
|
95
|
+
|
|
96
|
+
`AppendStream.sendWithRetry()` now:
|
|
97
|
+
|
|
98
|
+
- advances `index` before a rate-limit retry, matching `qqbot-nodejs`'s `StreamSession`;
|
|
99
|
+
- recognizes `status`, `httpStatus`, `code`, `err_code`, `bizCode`, and message text for 429/50002.
|
|
100
|
+
|
|
101
|
+
### 5.2 Duplicate `msgseq`
|
|
102
|
+
|
|
103
|
+
`BubbleWriter.handleStreamError()` detects `40054005` / duplicate-`msgseq` messages. Instead of resuming the same checkpoint, it opens a fresh stream with:
|
|
104
|
+
|
|
105
|
+
- no old `msgSeq` (the new stream generates one);
|
|
106
|
+
- `index: 0`;
|
|
107
|
+
- the failed buffer preserved.
|
|
108
|
+
|
|
109
|
+
Other stream errors keep the existing resume semantics. The recovery-attempt cap still applies.
|
|
110
|
+
|
|
111
|
+
## 6. Implementation
|
|
112
|
+
|
|
113
|
+
| File | Change |
|
|
114
|
+
| ------------------------------------- | --------------------------------------------------------------------------------------------- |
|
|
115
|
+
| `src/relay/run-timeline.ts` (new) | `RunTimeline`, tool state, snapshot selection, diagnostics |
|
|
116
|
+
| `src/relay/run-stream-relay.ts` | Uses `RunTimeline`; `advanceTools()`; `RepushResult`; removes last-mode delivery and fallback |
|
|
117
|
+
| `src/relay/bubble-writer.ts` | `RepushBlock`, `restartSnapshot()`, fresh-stream recovery, options-based push API |
|
|
118
|
+
| `src/relay/stream-session.ts` | Rate-limit index advance, API status fields, optional fresh `msgSeq` resume |
|
|
119
|
+
| `src/relay/reply-policy.ts` | Removes `relayTextLive`, `deliverLastAtEnd`, and last policy |
|
|
120
|
+
| `src/infra/reply-type.ts` | Only `full` and `simple` |
|
|
121
|
+
| `src/qq/inbound-command.ts` | `/last` consumes `InboundPushResult`; empty snapshot notice |
|
|
122
|
+
| `src/qq/media-tool.ts` | Shared send/result helper; removes test-only `isActive` |
|
|
123
|
+
| `src/infra/file-logger.ts` | Writes direct English messages; `msgKey` lookup only |
|
|
124
|
+
| `src/infra/log-message-keys.ts` (new) | Stable English message-to-key map |
|
|
125
|
+
| `src/infra/i18n.ts` | UI strings only; log translations and localization removed |
|
|
126
|
+
|
|
127
|
+
## 7. Verification
|
|
128
|
+
|
|
129
|
+
Automated:
|
|
130
|
+
|
|
131
|
+
- **234 tests** across 22 files.
|
|
132
|
+
- `npm run lint`, `npm run typecheck`, `npm run format:check`, and `npm pack --dry-run` pass.
|
|
133
|
+
- New tests cover:
|
|
134
|
+
- thinking-only and tool-only `/last` snapshots;
|
|
135
|
+
- snapshot ordering and the tool window;
|
|
136
|
+
- writer-dead recovery;
|
|
137
|
+
- continuation of tool results after repush;
|
|
138
|
+
- `40054005` fresh-stream recovery;
|
|
139
|
+
- rate-limit index and `httpStatus` / `bizCode` detection;
|
|
140
|
+
- direct `restartSnapshot()` behavior.
|
|
141
|
+
|
|
142
|
+
Manual QQ smoke test (`pi-qq-2026-11-11.log`, local time 18:11–18:17):
|
|
143
|
+
|
|
144
|
+
- four runs covering `simple` and `full`;
|
|
145
|
+
- `/last` in full mode repushed 366 characters of current thinking and two tools with a new `msgId`;
|
|
146
|
+
- `/status` returned the expected full-mode report;
|
|
147
|
+
- `/stop` ended both active runs;
|
|
148
|
+
- no warnings, stream errors, `40054005`, or rate-limit events.
|
|
149
|
+
|
|
150
|
+
Not manually exercised:
|
|
151
|
+
|
|
152
|
+
- actual rate-limit retry;
|
|
153
|
+
- actual `40054005` recovery;
|
|
154
|
+
- `/last` with a dead writer;
|
|
155
|
+
- `/last` in `simple` mode.
|
|
156
|
+
|
|
157
|
+
These paths are covered by automated tests.
|
|
158
|
+
|
|
159
|
+
## 8. Code review consolidation
|
|
160
|
+
|
|
161
|
+
Fixed from the review:
|
|
162
|
+
|
|
163
|
+
- rate-limit retry index and API error fields;
|
|
164
|
+
- duplicate-`msgseq` recovery;
|
|
165
|
+
- unused relay/command surface and dead translations;
|
|
166
|
+
- duplicated media send/result construction and text-delta handling;
|
|
167
|
+
- command-layer dependency on the relay `RepushResult` type;
|
|
168
|
+
- unnecessary `index` option in attachment saves;
|
|
169
|
+
- empty attachment responses;
|
|
170
|
+
- English-only log messages.
|
|
171
|
+
|
|
172
|
+
Deferred intentionally:
|
|
173
|
+
|
|
174
|
+
- npm package docs policy (`doc/todo.md` and archive docs) is left to the release owner;
|
|
175
|
+
- splitting `index.ts`, `BubbleWriter`, or the large `run-stream-relay` test file further;
|
|
176
|
+
- a broader `ReplyType` policy refactor beyond the two remaining modes.
|
|
177
|
+
|
|
178
|
+
No dependency cycles were found.
|
|
179
|
+
|
|
180
|
+
## 9. Risks and limitations
|
|
181
|
+
|
|
182
|
+
| Risk | Impact | Handling |
|
|
183
|
+
| ------------------------------------------------------------ | -------------------------------------------------- | ----------------------------------------------------------- |
|
|
184
|
+
| Snapshot order differs from the original interleaving | Repush is a state snapshot, not a full transcript | Documented behavior |
|
|
185
|
+
| Tool window is bounded | Older tools are omitted | Active tool + last three finished tools |
|
|
186
|
+
| A duplicate-`msgseq` repush can create a new bubble | The old bubble remains | Only triggered by a stream failure; history is not replayed |
|
|
187
|
+
| `replyType: "last"` removal is breaking for configured users | Values fall back to full with a warning | Documented in the READMEs and changelog |
|
|
188
|
+
| Log language no longer follows `language` | Existing users may expect localized logs | Logs are stable English; UI remains localized |
|
|
189
|
+
| `doc/` contents are still in the current package manifest | Internal notes may ship until packaging is changed | Deferred to the release owner |
|
|
190
|
+
|
|
191
|
+
## 10. References
|
|
192
|
+
|
|
193
|
+
- User-facing behavior: [README.md](../../README.md), [README-zh.md](../../README-zh.md).
|
|
194
|
+
- Previous delivery: [delivery.1.6.1.md](./delivery.1.6.1.md).
|
|
195
|
+
- Manual test log: `/home/chen/project/mine/pi-qq-test/.pi/pi-qq/logs/pi-qq-2026-11-11.log`.
|
|
196
|
+
- This record replaces the temporary `doc/repair.md` and code-review working notes.
|
package/doc/todo.md
CHANGED
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
> 记录日期:2026-11-04
|
|
89
89
|
> 分析日期:2026-11-06
|
|
90
90
|
> 相关版本:pi-qq 1.4.0
|
|
91
|
-
> 详细调研:`doc/archive/delivery
|
|
91
|
+
> 详细调研:`doc/archive/delivery.1.4.0.md`
|
|
92
92
|
|
|
93
93
|
### 现象
|
|
94
94
|
|
|
@@ -206,7 +206,7 @@ QQ 侧的 `/last` 已可用于手动恢复:
|
|
|
206
206
|
- 本次日志未复现失败;不要据此实施错误分类、预算或自动重绑修复。
|
|
207
207
|
- 继续等待一次真正的多分钟单命令日志(最好 >5 分钟,并覆盖 >1 小时的 `msg_id` 生命周期);复现时按上面的“复现时仍需采集/分析”执行。
|
|
208
208
|
- 如果目标只是改善长工具期间的体感:优先实现长工具心跳和 `tool_execution_update` 转发,这不依赖失败复现。
|
|
209
|
-
- 如果后续日志确认 `msg_id` 过期/被动次数超限:再按 `doc/archive/delivery
|
|
209
|
+
- 如果后续日志确认 `msg_id` 过期/被动次数超限:再按 `doc/archive/delivery.1.4.0.md` 的“Long-running tools”建议实现错误分类和预算修复。
|
|
210
210
|
- 如果 `/stop` 的 `wait done` 缺失或 `waitedMs` 很大:实现非阻塞 `/stop`。
|
|
211
211
|
- `/last` 目前作为手动兜底可用,保持现状,不急于自动重绑。
|
|
212
212
|
- 修复后补测试,更新 `doc/todo.md` / `CHANGELOG.md`,再发布版本。
|
package/index.ts
CHANGED
|
@@ -40,27 +40,13 @@ let stateDetail: string | undefined;
|
|
|
40
40
|
let sessionCtx: ExtensionContext | undefined;
|
|
41
41
|
let mediaTool: MediaToolController | undefined;
|
|
42
42
|
let activeSettings: ResolvedSettings = getSettings({});
|
|
43
|
+
let lastConfigError: string | undefined;
|
|
43
44
|
const budget = new ReplyBudget();
|
|
44
45
|
const runFeedback = new RunFeedback({
|
|
45
46
|
bot: () => running?.bot,
|
|
46
47
|
budget,
|
|
47
|
-
getThinkingRelay: () => activeSettings.thinkingRelay,
|
|
48
48
|
getReplyType: () => activeSettings.replyType,
|
|
49
49
|
onWarn: (msg) => sessionCtx?.ui.notify(`pi-qq ${msg}`, "warning"),
|
|
50
|
-
onFallbackReply: (text) => {
|
|
51
|
-
const bot = running?.bot;
|
|
52
|
-
const bound = getLoginState()?.allowedOpenid;
|
|
53
|
-
if (!bot || !bound) {
|
|
54
|
-
log.warn("pi", "fallback reply skipped: no bot or bound user");
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
log.info("pi", "sending fallback reply", { textLength: text.length });
|
|
58
|
-
void sendReply(bot, markdownToPlain(text), {
|
|
59
|
-
budget,
|
|
60
|
-
boundOpenid: bound,
|
|
61
|
-
onWarn: (msg) => sessionCtx?.ui.notify(`pi-qq ${msg}`, "warning"),
|
|
62
|
-
});
|
|
63
|
-
},
|
|
64
50
|
});
|
|
65
51
|
|
|
66
52
|
const eventLoopDelay = monitorEventLoopDelay({ resolution: 100 });
|
|
@@ -114,6 +100,29 @@ function stopEventLoopMonitor(): void {
|
|
|
114
100
|
export default function (pi: ExtensionAPI) {
|
|
115
101
|
setLogGate(() => Boolean(getLoginState()) && runFeedback.isQQRunActive());
|
|
116
102
|
|
|
103
|
+
const notifyConfigError = (ctx: ExtensionContext, error: string | undefined, dedupe: boolean) => {
|
|
104
|
+
if (!error) {
|
|
105
|
+
lastConfigError = undefined;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (dedupe && error === lastConfigError) return;
|
|
109
|
+
lastConfigError = error;
|
|
110
|
+
ctx.ui.notify(`pi-qq ${error}`, "error");
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const applyConfig = (ctx?: ExtensionContext, options: { dedupeError?: boolean } = {}) => {
|
|
114
|
+
const { config, error } = readConfig();
|
|
115
|
+
activeSettings = getSettings(config);
|
|
116
|
+
configureI18n(activeSettings.language);
|
|
117
|
+
if (ctx) {
|
|
118
|
+
configureLogger(activeSettings.logLevel, join(ctx.cwd, ".pi", "pi-qq", "logs"));
|
|
119
|
+
notifyConfigError(ctx, error, options.dedupeError ?? false);
|
|
120
|
+
}
|
|
121
|
+
return { settings: activeSettings, error };
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
let pendingConfigError = applyConfig().error;
|
|
125
|
+
|
|
117
126
|
mediaTool = registerMediaTool(pi, {
|
|
118
127
|
getBot: () => running?.bot,
|
|
119
128
|
getLogin: () => getLoginState(),
|
|
@@ -121,23 +130,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
121
130
|
onWarn: (msg) => sessionCtx?.ui.notify(`pi-qq ${msg}`, "warning"),
|
|
122
131
|
});
|
|
123
132
|
|
|
124
|
-
activeSettings = getSettings(readConfig().config);
|
|
125
|
-
configureI18n(activeSettings.language);
|
|
126
|
-
|
|
127
133
|
const getAllowedOpenid = () => getLoginState()?.allowedOpenid;
|
|
128
134
|
const getDeliverAs = () => activeSettings.deliverAs;
|
|
129
|
-
const getReplyType = () => activeSettings.replyType;
|
|
130
135
|
|
|
131
136
|
const onWarn = (ctx: ExtensionContext) => (msg: string) => ctx.ui.notify(`pi-qq ${msg}`, "warning");
|
|
132
137
|
|
|
133
|
-
const applyConfig = (ctx: ExtensionContext) => {
|
|
134
|
-
const { config, error } = readConfig();
|
|
135
|
-
activeSettings = getSettings(config);
|
|
136
|
-
configureI18n(activeSettings.language);
|
|
137
|
-
if (error) ctx.ui.notify(`pi-qq ${error}`, "error");
|
|
138
|
-
return { settings: activeSettings, error };
|
|
139
|
-
};
|
|
140
|
-
|
|
141
138
|
const getStatusLines = (ctx: ExtensionContext | undefined = sessionCtx): string[] => {
|
|
142
139
|
const login = getLoginState();
|
|
143
140
|
const usage = ctx?.getContextUsage();
|
|
@@ -200,8 +197,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
200
197
|
ctx,
|
|
201
198
|
budget,
|
|
202
199
|
getAllowedOpenid,
|
|
200
|
+
reloadSettings: () => applyConfig(ctx, { dedupeError: true }),
|
|
203
201
|
getDeliverAs,
|
|
204
|
-
getReplyType,
|
|
205
202
|
getFileMaxSize: () => activeSettings.fileMaxSize,
|
|
206
203
|
getStatusLines,
|
|
207
204
|
getLastMessage: () => runFeedback.getLastMessage(),
|
|
@@ -223,8 +220,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
223
220
|
};
|
|
224
221
|
|
|
225
222
|
pi.on("session_start", async (_event, ctx) => {
|
|
226
|
-
const
|
|
227
|
-
|
|
223
|
+
const settings = activeSettings;
|
|
224
|
+
const configError = pendingConfigError;
|
|
225
|
+
pendingConfigError = undefined;
|
|
226
|
+
notifyConfigError(ctx, configError, false);
|
|
228
227
|
|
|
229
228
|
const login = getLoginState();
|
|
230
229
|
log.info("session", "started", {
|
|
@@ -234,7 +233,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
234
233
|
logLevel: settings.logLevel,
|
|
235
234
|
replyType: settings.replyType,
|
|
236
235
|
login: login ? { appId: login.credentials.appId, allowedOpenid: login.allowedOpenid } : null,
|
|
237
|
-
configError:
|
|
236
|
+
configError: configError ?? null,
|
|
238
237
|
});
|
|
239
238
|
if (login) {
|
|
240
239
|
await startWithCredentials(ctx, login.credentials, login.allowedOpenid);
|
|
@@ -422,7 +421,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
422
421
|
pi.registerCommand("qq-login", {
|
|
423
422
|
description: t("commands.descQqLogin"),
|
|
424
423
|
handler: async (_args, ctx) => {
|
|
425
|
-
applyConfig(ctx);
|
|
426
424
|
stopIfRunning();
|
|
427
425
|
setLoginState(undefined);
|
|
428
426
|
let result: QrLoginResult | undefined;
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@ export interface InboundAttachmentLike {
|
|
|
8
8
|
size?: number;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
interface DownloadOptions {
|
|
12
12
|
url: string;
|
|
13
13
|
maxSize: number;
|
|
14
14
|
timeoutMs: number;
|
|
@@ -19,6 +19,7 @@ export interface DownloadOptions {
|
|
|
19
19
|
async function readBodyLimited(response: Response, limit: number, kind: string): Promise<Buffer> {
|
|
20
20
|
if (!response.body) {
|
|
21
21
|
const body = Buffer.from(await response.arrayBuffer());
|
|
22
|
+
if (body.byteLength === 0) throw new Error(t("attachments.empty", { kind }));
|
|
22
23
|
if (body.byteLength > limit) {
|
|
23
24
|
throw new Error(
|
|
24
25
|
t("attachments.tooLarge", { kind, size: formatBytes(body.byteLength), limit: formatBytes(limit) }),
|
|
@@ -14,16 +14,15 @@ export interface SavedFile {
|
|
|
14
14
|
path: string;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
type UploadIndex = Record<string, string>;
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
interface SaveFilesOptions {
|
|
20
20
|
maxSize: number;
|
|
21
21
|
uploadDir: string;
|
|
22
|
-
index?: UploadIndex;
|
|
23
22
|
fetchImpl?: typeof fetch;
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
interface SaveFilesResult {
|
|
27
26
|
files: SavedFile[];
|
|
28
27
|
failures: AttachmentFailure[];
|
|
29
28
|
}
|
|
@@ -189,7 +188,7 @@ export async function saveInboundFiles(
|
|
|
189
188
|
const uploadDir = options.uploadDir;
|
|
190
189
|
const limit = Math.max(1, options.maxSize);
|
|
191
190
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
192
|
-
const index =
|
|
191
|
+
const index = await loadUploadIndex(uploadDir);
|
|
193
192
|
const files: SavedFile[] = [];
|
|
194
193
|
const failures: AttachmentFailure[] = [];
|
|
195
194
|
const seenPaths = new Set<string>();
|
package/src/infra/file-logger.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { appendFile, mkdir } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { logMessageKey } from "./log-message-keys";
|
|
4
4
|
|
|
5
5
|
export type LogLevel = "silent" | "error" | "warn" | "info" | "debug";
|
|
6
6
|
type LogFields = Record<string, unknown>;
|
|
@@ -93,13 +93,13 @@ function writeRecord(level: Exclude<LogLevel, "silent">, scope: string, message:
|
|
|
93
93
|
if (!isLevelEnabled(activeLevel, level)) return;
|
|
94
94
|
if (!isLogAllowed()) return;
|
|
95
95
|
|
|
96
|
-
const
|
|
96
|
+
const msgKey = logMessageKey(message);
|
|
97
97
|
const record: LogFields = {
|
|
98
98
|
time: new Date().toISOString(),
|
|
99
99
|
level,
|
|
100
100
|
scope,
|
|
101
|
-
...(
|
|
102
|
-
msg:
|
|
101
|
+
...(msgKey ? { msgKey } : {}),
|
|
102
|
+
msg: message,
|
|
103
103
|
};
|
|
104
104
|
const fields = normalizeData(data);
|
|
105
105
|
if (fields) {
|
|
@@ -122,8 +122,8 @@ function writeRecord(level: Exclude<LogLevel, "silent">, scope: string, message:
|
|
|
122
122
|
time: record.time,
|
|
123
123
|
level,
|
|
124
124
|
scope,
|
|
125
|
-
...(
|
|
126
|
-
msg:
|
|
125
|
+
...(msgKey ? { msgKey } : {}),
|
|
126
|
+
msg: message,
|
|
127
127
|
serializationError: stringifyError(err),
|
|
128
128
|
});
|
|
129
129
|
}
|