@chen_hu_hu/pi-qq 1.6.1 → 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 +20 -1
- package/README-zh.md +6 -7
- package/README.md +19 -20
- package/doc/archive/delivery.1.6.2.md +196 -0
- package/index.ts +0 -16
- 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 -196
- 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/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 +5 -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 -202
- 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
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { getNextMsgSeq, StreamContentType, StreamInputState } from "@tencent-connect/qqbot-nodejs/protocol";
|
|
2
|
-
import { t } from "../infra/i18n";
|
|
3
2
|
import type {
|
|
4
3
|
Credentials,
|
|
5
4
|
MessageApi,
|
|
@@ -12,7 +11,7 @@ const RATE_LIMIT_BASE_MS = 1000;
|
|
|
12
11
|
const MAX_RETRIES = 3;
|
|
13
12
|
|
|
14
13
|
export interface AppendStreamCheckpoint {
|
|
15
|
-
msgSeq
|
|
14
|
+
msgSeq?: number;
|
|
16
15
|
index: number;
|
|
17
16
|
streamMsgId?: string;
|
|
18
17
|
buffer?: string;
|
|
@@ -26,7 +25,7 @@ export interface AppendStreamFrameInfo {
|
|
|
26
25
|
bufferLength: number;
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
interface AppendStreamOptions {
|
|
30
29
|
throttleMs?: number;
|
|
31
30
|
retryBaseMs?: number;
|
|
32
31
|
resume?: AppendStreamCheckpoint;
|
|
@@ -54,7 +53,7 @@ export class AppendStream {
|
|
|
54
53
|
) {
|
|
55
54
|
const resume = this.opts.resume;
|
|
56
55
|
if (resume) {
|
|
57
|
-
this.msgSeq = resume.msgSeq;
|
|
56
|
+
if (resume.msgSeq !== undefined) this.msgSeq = resume.msgSeq;
|
|
58
57
|
this.index = resume.index;
|
|
59
58
|
this.streamMsgId = resume.streamMsgId;
|
|
60
59
|
this.buffer = resume.buffer ?? "";
|
|
@@ -198,18 +197,36 @@ export class AppendStream {
|
|
|
198
197
|
...(this.streamMsgId ? { streamMsgId: this.streamMsgId } : {}),
|
|
199
198
|
bufferLength: this.buffer.length,
|
|
200
199
|
});
|
|
201
|
-
this.opts.onDebug?.(
|
|
200
|
+
this.opts.onDebug?.(`frame index=${req.index} failed after ${attempt + 1} attempt(s): ${reason}`);
|
|
202
201
|
throw err;
|
|
203
202
|
}
|
|
204
203
|
const delay = base * 2 ** attempt;
|
|
205
|
-
this.opts.onDebug?.(
|
|
204
|
+
this.opts.onDebug?.(
|
|
205
|
+
`frame index=${req.index} rate limited (attempt ${attempt + 1}), retry in ${delay}ms: ${reason}`,
|
|
206
|
+
);
|
|
206
207
|
await new Promise((r) => setTimeout(r, delay));
|
|
208
|
+
req.index = this.index++;
|
|
207
209
|
}
|
|
208
210
|
}
|
|
209
211
|
}
|
|
210
212
|
|
|
211
213
|
private isRateLimitError(err: unknown): boolean {
|
|
212
|
-
const e = err as {
|
|
213
|
-
|
|
214
|
+
const e = err as {
|
|
215
|
+
status?: number;
|
|
216
|
+
httpStatus?: number;
|
|
217
|
+
code?: number;
|
|
218
|
+
err_code?: number;
|
|
219
|
+
bizCode?: number;
|
|
220
|
+
message?: string;
|
|
221
|
+
};
|
|
222
|
+
return (
|
|
223
|
+
e?.status === 429 ||
|
|
224
|
+
e?.httpStatus === 429 ||
|
|
225
|
+
e?.code === 429 ||
|
|
226
|
+
e?.code === 50002 ||
|
|
227
|
+
e?.err_code === 50002 ||
|
|
228
|
+
e?.bizCode === 50002 ||
|
|
229
|
+
/429|50002/.test(String(e?.message ?? ""))
|
|
230
|
+
);
|
|
214
231
|
}
|
|
215
232
|
}
|