@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.
@@ -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: number;
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
- export interface AppendStreamOptions {
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?.(t("log.streamFrameFailed", { index: req.index, attempts: attempt + 1, reason }));
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?.(t("log.streamFrameRateLimited", { index: req.index, attempt: attempt + 1, delay, reason }));
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 { status?: number; message?: string };
213
- return e?.status === 429 || /429|50002/.test(String(e?.message ?? ""));
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
  }