dsh-coding-subscription-oauth 0.5.2 → 0.5.3

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-coding-subscription-oauth",
3
3
  "description": "DeepSeek Harness coding-subscription OAuth: SuperGrok/Grok Build, ChatGPT Plus Codex, Kimi Code, Claude Code. Fixes AUTH API key is invalid, INVALID_REPLAY_STATE, grok-4.6 xhigh, Kimi Bearer vs x-api-key.",
4
- "version": "0.5.2",
4
+ "version": "0.5.3",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "registry": "https://registry.npmjs.org/"
package/src/adapter.ts CHANGED
@@ -58,12 +58,17 @@ const MIN_OAUTH_VALIDITY_MS = 60_000;
58
58
  * set: retrying a billing-limit 403 cannot succeed and only delays the real
59
59
  * message. Genuine credential death is converted to MISSING_CREDENTIAL (not
60
60
  * retryable) by the resolver below, so it cannot loop either.
61
+ *
62
+ * Five stacked exponential delays (5s → 10s → 20s → 40s → 80s, ~155s total)
63
+ * pair with the xAI capacity remap in {@link AliasLlmAdapter}: "at capacity"
64
+ * finish errors become RATE_LIMIT so they enter this policy instead of failing
65
+ * as PI_AI_ERROR.
61
66
  */
62
67
  const CODING_OAUTH_RETRY_POLICY = {
63
68
  mode: "normal" as const,
64
- maxRetries: 2,
69
+ maxRetries: 5,
65
70
  retryableCodes: ["EMPTY_RESPONSE", "RATE_LIMIT", "SERVER", "TIMEOUT", "TRANSPORT", "AUTH"],
66
- backoff: { initialDelayMs: 500, maxDelayMs: 10_000, jitterRatio: 0.1 },
71
+ backoff: { initialDelayMs: 5_000, maxDelayMs: 80_000, jitterRatio: 0.1 },
67
72
  };
68
73
 
69
74
  function profile(
@@ -12,6 +12,7 @@ import type {
12
12
  StreamChunk,
13
13
  } from "@deepseek-ai/dsh-llm";
14
14
  import { LlmAdapter, LlmError } from "@deepseek-ai/dsh-llm";
15
+ import { remapXaiCapacityFailure } from "./grok-errors.ts";
15
16
  import { remapAuthFailureIfContextOverflow } from "./kimi-errors.ts";
16
17
 
17
18
  export interface AliasLlmRoutePolicy {
@@ -121,7 +122,7 @@ export class AliasLlmAdapter extends LlmAdapter {
121
122
  ...raw,
122
123
  reason: {
123
124
  ...raw.reason,
124
- failure: remapAuthFailureIfContextOverflow(raw.reason.failure),
125
+ failure: remapXaiCapacityFailure(remapAuthFailureIfContextOverflow(raw.reason.failure)),
125
126
  },
126
127
  }
127
128
  : raw;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * xAI / Grok Build error remapping.
3
+ * @module dsh-coding-subscription-oauth/grok-errors
4
+ */
5
+
6
+ /**
7
+ * xAI returns capacity / overload messages that pi-ai classifies as
8
+ * `PI_AI_ERROR` (or occasionally mislabels as AUTH) because the payload has
9
+ * `error.code: null` and no HTTP 429 / rate-limit wording. Without a remap the
10
+ * harness retry policy never runs.
11
+ */
12
+ const XAI_CAPACITY = /\b(?:at\s+capacity|high\s+demand|priority\s+processing|overloaded)\b/i;
13
+
14
+ export function isXaiCapacityError(detail: string): boolean {
15
+ return XAI_CAPACITY.test(detail);
16
+ }
17
+
18
+ export function remapXaiCapacityFailure(failure: { message: string; code: string }): {
19
+ message: string;
20
+ code: string;
21
+ } {
22
+ if (!isXaiCapacityError(failure.message)) return failure;
23
+ return { ...failure, code: "RATE_LIMIT" };
24
+ }