@chen_hu_hu/pi-qq 1.3.6 → 1.4.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 +13 -1
- package/README-zh.md +1 -1
- package/README.md +1 -1
- package/doc/archive/README.md +14 -0
- package/doc/archive/delivery-v4-zh.md +327 -0
- package/doc/archive/delivery-v4.md +327 -0
- package/doc/todo.md +107 -2
- package/index.ts +64 -0
- package/package.json +1 -1
- package/src/qq/inbound-command.ts +7 -0
- package/src/qq/qq-diagnostics.ts +2 -2
- package/src/qq/reply-sender.ts +5 -0
- package/src/relay/bubble-writer.ts +110 -21
- package/src/relay/run-stream-relay.ts +166 -12
- package/src/relay/stream-block-format.ts +139 -22
- package/src/relay/stream-session.ts +27 -4
- package/doc/bugfix-v4.md +0 -698
- package/doc/enhance-status.md +0 -427
- package/doc/send-skill.md +0 -257
- package/doc/tool-return.md +0 -378
|
@@ -18,12 +18,21 @@ export interface AppendStreamCheckpoint {
|
|
|
18
18
|
buffer?: string;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
export interface AppendStreamFrameInfo {
|
|
22
|
+
index: number;
|
|
23
|
+
state: "generating" | "done";
|
|
24
|
+
msgSeq: number | null;
|
|
25
|
+
streamMsgId?: string;
|
|
26
|
+
bufferLength: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
21
29
|
export interface AppendStreamOptions {
|
|
22
30
|
throttleMs?: number;
|
|
23
31
|
retryBaseMs?: number;
|
|
24
32
|
resume?: AppendStreamCheckpoint;
|
|
25
33
|
onError?: (err: Error) => void;
|
|
26
34
|
onDebug?: (message: string) => void;
|
|
35
|
+
onFrameError?: (err: unknown, info: AppendStreamFrameInfo) => void;
|
|
27
36
|
}
|
|
28
37
|
|
|
29
38
|
export class AppendStream {
|
|
@@ -131,7 +140,9 @@ export class AppendStream {
|
|
|
131
140
|
if (this.flushing) return;
|
|
132
141
|
const content = state === "done" ? "" : this.buffer;
|
|
133
142
|
if (!content && state === "generating") return;
|
|
134
|
-
this.opts.onDebug?.(
|
|
143
|
+
this.opts.onDebug?.(
|
|
144
|
+
`flush: start state=${state}, content=${content.length}, index=${this.index}, msgSeq=${this.msgSeq ?? "none"}, streamMsgId=${this.streamMsgId ?? "none"}`,
|
|
145
|
+
);
|
|
135
146
|
this.flushing = true;
|
|
136
147
|
let failed = false;
|
|
137
148
|
try {
|
|
@@ -148,11 +159,13 @@ export class AppendStream {
|
|
|
148
159
|
index,
|
|
149
160
|
...(this.streamMsgId ? { stream_msg_id: this.streamMsgId } : {}),
|
|
150
161
|
} as unknown as StreamMessageRequest;
|
|
151
|
-
const resp = await this.sendWithRetry(req);
|
|
162
|
+
const resp = await this.sendWithRetry(req, state);
|
|
152
163
|
if (resp?.id && !this.streamMsgId) this.streamMsgId = resp.id;
|
|
153
164
|
if (state === "generating") this.buffer = this.buffer.slice(content.length);
|
|
154
165
|
this.lastFlushAt = Date.now();
|
|
155
|
-
this.opts.onDebug?.(
|
|
166
|
+
this.opts.onDebug?.(
|
|
167
|
+
`flush: done state=${state}, remaining=${this.buffer.length}, streamMsgId=${this.streamMsgId ?? "none"}`,
|
|
168
|
+
);
|
|
156
169
|
} catch (err) {
|
|
157
170
|
failed = true;
|
|
158
171
|
throw err;
|
|
@@ -167,7 +180,10 @@ export class AppendStream {
|
|
|
167
180
|
}
|
|
168
181
|
}
|
|
169
182
|
|
|
170
|
-
private async sendWithRetry(
|
|
183
|
+
private async sendWithRetry(
|
|
184
|
+
req: StreamMessageRequest,
|
|
185
|
+
state: "generating" | "done",
|
|
186
|
+
): Promise<MessageResponse | undefined> {
|
|
171
187
|
const base = this.opts.retryBaseMs ?? RATE_LIMIT_BASE_MS;
|
|
172
188
|
for (let attempt = 0; ; attempt++) {
|
|
173
189
|
try {
|
|
@@ -175,6 +191,13 @@ export class AppendStream {
|
|
|
175
191
|
} catch (err) {
|
|
176
192
|
const reason = err instanceof Error ? err.message : String(err);
|
|
177
193
|
if (attempt >= MAX_RETRIES || !this.isRateLimitError(err)) {
|
|
194
|
+
this.opts.onFrameError?.(err, {
|
|
195
|
+
index: req.index,
|
|
196
|
+
state,
|
|
197
|
+
msgSeq: this.msgSeq,
|
|
198
|
+
...(this.streamMsgId ? { streamMsgId: this.streamMsgId } : {}),
|
|
199
|
+
bufferLength: this.buffer.length,
|
|
200
|
+
});
|
|
178
201
|
this.opts.onDebug?.(t("log.streamFrameFailed", { index: req.index, attempts: attempt + 1, reason }));
|
|
179
202
|
throw err;
|
|
180
203
|
}
|