pi-provider-qoder-cn 0.2.20 → 0.2.21

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.
Files changed (2) hide show
  1. package/dist/index.js +23 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2390,7 +2390,7 @@ function formatQoderStreamError(statusCode, rawBody, now = Date.now(), mode = "c
2390
2390
  }
2391
2391
  if (code === "103" || /duplicate request/i.test(message)) {
2392
2392
  return isCn ? [
2393
- `[Qoder \u91CD\u590D\u8BF7\u6C42] \u7F51\u5173\u628A\u8FD9\u6B21\u8BF7\u6C42\u5224\u5B9A\u4E3A\u91CD\u653E\u5E76\u62D2\u7EDD (\u9519\u8BEF\u7801 103 Duplicate request)`,
2393
+ `[Qoder CN \u91CD\u590D\u8BF7\u6C42] \u7F51\u5173\u628A\u8FD9\u6B21\u8BF7\u6C42\u5224\u5B9A\u4E3A\u91CD\u653E\u5E76\u62D2\u7EDD (\u9519\u8BEF\u7801 103 Duplicate request)`,
2394
2394
  `- \u539F\u56E0\uFF1A\u540C\u4E00\u4E2A\u5DF2\u7B7E\u540D\u7684\u8BF7\u6C42\u88AB\u518D\u6B21\u63D0\u4EA4\uFF08COSY Authorization/\u65F6\u95F4\u6233/\u7B7E\u540D \u672A\u5237\u65B0\uFF09\uFF0C\u5E76\u975E\u989D\u5EA6\u6216\u51ED\u8BC1\u95EE\u9898\u3002`,
2395
2395
  `- \u89E3\u51B3\u5EFA\u8BAE\uFF1A\u5BA2\u6237\u7AEF\u5E94\u4E3A\u6BCF\u6B21\u91CD\u8BD5\u91CD\u65B0\u7B7E\u540D\uFF1B\u82E5\u4ECD\u590D\u73B0\uFF0C\u8BF7\u7528 /model \u5207\u6362 Provider \u7A0D\u540E\u91CD\u8BD5\u3002`
2396
2396
  ].join("\n") : [
@@ -2830,9 +2830,22 @@ function parseQueueNotice(envelope) {
2830
2830
  return {
2831
2831
  retryAfterMs: Math.min(retryMs, MAX_WAIT_MS),
2832
2832
  waitTimeSeconds: positiveNumber(payload.waitTime, 0),
2833
- queueCount: positiveNumber(payload.queueCount, 0)
2833
+ queueCount: positiveNumber(payload.queueCount, 0),
2834
+ // Only a real boolean is surfaced; a missing field must not be read as
2835
+ // "unavailable" (that would collapse the normal queue into a hard stop).
2836
+ serviceAvailable: typeof payload.serviceAvailable === "boolean" ? payload.serviceAvailable : void 0
2834
2837
  };
2835
2838
  }
2839
+ function formatQueueFigure(n) {
2840
+ if (!Number.isFinite(n) || n <= 0) return "0";
2841
+ if (n < 100) return String(Math.round(n));
2842
+ if (n >= 1e6) return `${(n / 1e6).toFixed(1)}M`;
2843
+ return `${(n / 1e3).toFixed(1)}k`;
2844
+ }
2845
+ function formatWaitMinutes(seconds) {
2846
+ if (!Number.isFinite(seconds) || seconds <= 0) return "<1";
2847
+ return String(Math.min(99, Math.max(1, Math.round(seconds / 60))));
2848
+ }
2836
2849
  function sleep(ms, signal) {
2837
2850
  return new Promise((resolve, reject) => {
2838
2851
  if (signal?.aborted) {
@@ -3522,9 +3535,15 @@ function streamQoder(model, context, options) {
3522
3535
  if (queue) {
3523
3536
  await reader.cancel().catch(() => {
3524
3537
  });
3525
- if (queuedAttempt >= MAX_QUEUE_RETRIES) {
3538
+ const stopEarly = queue.serviceAvailable === false;
3539
+ if (queuedAttempt >= (stopEarly ? 1 : MAX_QUEUE_RETRIES)) {
3540
+ if (stopEarly) {
3541
+ throw new Error(
3542
+ `Qoder \u4E0A\u6E38\u6682\u4E0D\u53EF\u670D\u52A1\uFF08\u7F51\u5173\u62A5 serviceAvailable:false\uFF1B\u961F\u5217\u4F4D\u7F6E ${formatQueueFigure(queue.queueCount)}\uFF0C\u9884\u8BA1 ${formatWaitMinutes(queue.waitTimeSeconds)} \u5206\u949F\u5185\u653E\u884C\uFF09\u3002\u5DF2\u6309 Retry-After \u7B49\u5F85\u5E76\u91CD\u8BD5 1 \u6B21\uFF0C\u4ECD\u672A\u653E\u884C\u3002\u8FD9\u4E0D\u662F\u51ED\u8BC1\u6216\u989D\u5EA6\u95EE\u9898\uFF0C\u8BF7\u7528 /model \u5207\u6362\u5176\u4ED6 Provider\uFF0C\u6216\u7A0D\u540E\u91CD\u8BD5\u3002`
3543
+ );
3544
+ }
3526
3545
  throw new Error(
3527
- `Qoder is at capacity: the request stayed queued after ${queuedAttempt + 1} attempts (~${queue.waitTimeSeconds}s wait reported). Try again shortly.`
3546
+ `Qoder is at capacity: the request stayed queued after ${queuedAttempt + 1} attempts (~${formatWaitMinutes(queue.waitTimeSeconds)} min wait reported). Try again shortly.`
3528
3547
  );
3529
3548
  }
3530
3549
  queuedAttempt++;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-provider-qoder-cn",
3
- "version": "0.2.20",
3
+ "version": "0.2.21",
4
4
  "description": "Pi extension for Qoder CN — PAT/OAuth auth, /qoder-cn.usage quota command, and enterprise VPC endpoint support",
5
5
  "type": "module",
6
6
  "license": "MIT",