@ynhcj/xiaoyi-channel 0.0.94-next → 0.0.95-next
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/dist/src/provider.js +13 -14
- package/package.json +1 -1
package/dist/src/provider.js
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
import { createHash } from "crypto";
|
|
11
11
|
import { getCurrentSessionContext } from "./tools/session-manager.js";
|
|
12
12
|
import { selfEvolutionManager } from "./utils/self-evolution-manager.js";
|
|
13
|
-
import { logger } from "./utils/logger.js";
|
|
14
13
|
// ── Retry config ──────────────────────────────────────────────
|
|
15
14
|
const RETRY_DELAYS_MS = [10_000, 20_000, 40_000, 60_000, 60_000];
|
|
16
15
|
const MAX_RETRY_ATTEMPTS = 5;
|
|
@@ -127,7 +126,7 @@ function createRetryingStream(createStream, cronJob) {
|
|
|
127
126
|
if (!hasContent && !isContent) {
|
|
128
127
|
// ── Buffer phase (no content yet) ──
|
|
129
128
|
if (event.type === "done") {
|
|
130
|
-
|
|
129
|
+
console.log(`[xiaoyiprovider] stream completed (no content), usage: input=${event.message?.usage?.input} output=${event.message?.usage?.output}`);
|
|
131
130
|
for (const b of buffer)
|
|
132
131
|
yield b;
|
|
133
132
|
resultResolve(event.message);
|
|
@@ -142,7 +141,7 @@ function createRetryingStream(createStream, cronJob) {
|
|
|
142
141
|
else {
|
|
143
142
|
// ── Streaming phase ──
|
|
144
143
|
if (!hasContent) {
|
|
145
|
-
|
|
144
|
+
console.log("[xiaoyiprovider] first content event received, switching to streaming mode");
|
|
146
145
|
hasContent = true;
|
|
147
146
|
for (const b of buffer)
|
|
148
147
|
yield b;
|
|
@@ -151,13 +150,13 @@ function createRetryingStream(createStream, cronJob) {
|
|
|
151
150
|
// The SDK calls result() when it sees done/error — if we yield first, the generator
|
|
152
151
|
// suspends and can never reach resolve, causing a permanent deadlock.
|
|
153
152
|
if (event.type === "done") {
|
|
154
|
-
|
|
153
|
+
console.log(`[xiaoyiprovider] stream completed, usage: input=${event.message?.usage?.input} output=${event.message?.usage?.output}`);
|
|
155
154
|
resultResolve(event.message);
|
|
156
155
|
yield event;
|
|
157
156
|
return;
|
|
158
157
|
}
|
|
159
158
|
if (event.type === "error") {
|
|
160
|
-
|
|
159
|
+
console.log(`[xiaoyiprovider] stream error after content: ${event.error?.errorMessage}`);
|
|
161
160
|
errorResult = event.error;
|
|
162
161
|
break; // break inner loop, proceed to retry decision
|
|
163
162
|
}
|
|
@@ -168,15 +167,15 @@ function createRetryingStream(createStream, cronJob) {
|
|
|
168
167
|
if (errorResult?.stopReason === "error" && isRetryableProviderError(errorResult.errorMessage)) {
|
|
169
168
|
if (attempt < MAX_RETRY_ATTEMPTS - 1) {
|
|
170
169
|
const delayMs = getRetryDelayMs(attempt + 1, cronJob);
|
|
171
|
-
|
|
170
|
+
console.log(`[xiaoyiprovider] retryable error (attempt ${attempt + 1}/${MAX_RETRY_ATTEMPTS}): ` +
|
|
172
171
|
`${errorResult.errorMessage} — retrying in ${delayMs}ms`);
|
|
173
172
|
await sleep(delayMs);
|
|
174
173
|
continue; // discard buffer, retry with a new stream
|
|
175
174
|
}
|
|
176
|
-
|
|
175
|
+
console.log(`[xiaoyiprovider] all ${MAX_RETRY_ATTEMPTS} retries exhausted, surfacing last error`);
|
|
177
176
|
}
|
|
178
177
|
else if (errorResult) {
|
|
179
|
-
|
|
178
|
+
console.log(`[xiaoyiprovider] non-retryable error: ${errorResult.errorMessage}`);
|
|
180
179
|
}
|
|
181
180
|
// Non-retryable or retries exhausted — yield buffered events.
|
|
182
181
|
// Resolve before yielding the terminal event to avoid the same deadlock.
|
|
@@ -196,7 +195,7 @@ function createRetryingStream(createStream, cronJob) {
|
|
|
196
195
|
return;
|
|
197
196
|
}
|
|
198
197
|
// Safety: final fallback attempt
|
|
199
|
-
|
|
198
|
+
console.log("[xiaoyiprovider] entering final fallback attempt");
|
|
200
199
|
const lastStream = await createStream();
|
|
201
200
|
for await (const event of lastStream) {
|
|
202
201
|
if (event.type === "done") {
|
|
@@ -485,9 +484,9 @@ export const xiaoyiProvider = {
|
|
|
485
484
|
}
|
|
486
485
|
}
|
|
487
486
|
// 记录输入
|
|
488
|
-
|
|
487
|
+
console.log(`[xiaoyiprovider] input messages count: ${context.messages?.length ?? 0}`);
|
|
489
488
|
if (context.systemPrompt) {
|
|
490
|
-
|
|
489
|
+
console.log(`[xiaoyiprovider] system prompt length: ${context.systemPrompt.length}`);
|
|
491
490
|
}
|
|
492
491
|
// Reuse deviceType from extraParams instead of calling getCurrentSessionContext()
|
|
493
492
|
// again (which may be ambiguous in multi-session or async scenarios).
|
|
@@ -518,11 +517,11 @@ export const xiaoyiProvider = {
|
|
|
518
517
|
sp = sp.replace('## Runtime', combined + '\n\n## Runtime');
|
|
519
518
|
}
|
|
520
519
|
}
|
|
521
|
-
|
|
520
|
+
console.log(`[xiaoyiprovider] system prompt optimized: ${beforeLen} -> ${sp.length}`);
|
|
522
521
|
context.systemPrompt = sp;
|
|
523
522
|
}
|
|
524
523
|
const selfEvolutionEnabled = await selfEvolutionManager.isEnabled();
|
|
525
|
-
|
|
524
|
+
console.log(`[selfEvolution] selfEvolution flag: ${selfEvolutionEnabled}`);
|
|
526
525
|
context.systemPrompt = applySelfEvolutionPrompt(context.systemPrompt, selfEvolutionEnabled);
|
|
527
526
|
// Append device context to systemPrompt (using pre-captured deviceType from prepareExtraParams)
|
|
528
527
|
if (deviceType) {
|
|
@@ -550,7 +549,7 @@ export const xiaoyiProvider = {
|
|
|
550
549
|
// ── Retry-capable streaming ──────────────────────────────
|
|
551
550
|
const cronJob = isCronTriggered(context.messages);
|
|
552
551
|
if (cronJob)
|
|
553
|
-
|
|
552
|
+
console.log("[xiaoyiprovider] detected cron-triggered request, using extended retry delays");
|
|
554
553
|
const makeStream = () => underlying(model, context, {
|
|
555
554
|
...options,
|
|
556
555
|
headers: {
|