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