@juspay/neurolink 9.87.2 → 9.87.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.
@@ -11,8 +11,9 @@
11
11
  */
12
12
  import { buildTranslationOptions } from "../../proxy/proxyTranslationEngine.js";
13
13
  import type { ModelRouter } from "../../proxy/modelRouter.js";
14
+ import { ProxyTracer } from "../../proxy/proxyTracer.js";
14
15
  import { isPermanentRefreshFailure } from "../../proxy/tokenRefresh.js";
15
- import type { AccountAllowlist, AccountCooldownPlan, AccountQuota, ParsedClaudeError, ProxyPassthroughAccount, RouteGroup, RuntimeAccountState, StreamTerminalOutcome } from "../../types/index.js";
16
+ import type { AccountAllowlist, AccountCooldownPlan, AccountQuota, AnthropicAttemptLogger, AnthropicAuthRetryResult, AnthropicLoopState, AnthropicSuccessResult, AnthropicUpstreamFetchResult, ClaudeFinalRequestLogger, ClaudeRequest, ParsedClaudeError, ProxyBodyCaptureLogger, ProxyPassthroughAccount, RouteGroup, RuntimeAccountState, ServerContext, StreamTerminalOutcome } from "../../types/index.js";
16
17
  /** Resolve the configured primary's stable key to its current index in the
17
18
  * request's enabledAccounts list. Returns 0 (insertion-order fallback) when
18
19
  * no key is configured or the key cannot be matched (account disabled/
@@ -24,6 +25,9 @@ declare function resolveHomeIndex(enabledAccounts: ProxyPassthroughAccount[]): n
24
25
  * account once its rate limit window expires. Called at the start of each
25
26
  * request. Home is resolved fresh per call via resolveHomeIndex. */
26
27
  declare function maybeResetPrimaryToHome(enabledAccounts: ProxyPassthroughAccount[]): void;
28
+ declare function claimTransientRateLimitRetry(accountKey: string, coolingUntil: number, now?: number): number | undefined;
29
+ declare function claimTransientCooldownAdmission(accountKey: string, coolingUntil: number, now?: number): number | undefined;
30
+ declare function waitForTransientAccountAvailability(orderedAccounts: ProxyPassthroughAccount[]): Promise<ProxyPassthroughAccount[]>;
27
31
  /** Convert an Anthropic unified-window reset (Unix epoch SECONDS, per the
28
32
  * `anthropic-ratelimit-unified-*-reset` headers) into epoch-ms. Tolerates a
29
33
  * value already expressed in ms (some intermediaries normalise it). Returns
@@ -77,11 +81,109 @@ declare function trackUpstreamReadableStream(source: ReadableStream<Uint8Array>)
77
81
  stream: ReadableStream<Uint8Array>;
78
82
  outcome: Promise<StreamTerminalOutcome>;
79
83
  };
84
+ declare function handleAnthropicStreamingSuccessResponse(args: {
85
+ ctx: ServerContext;
86
+ body: ClaudeRequest;
87
+ account: ProxyPassthroughAccount;
88
+ accountState: RuntimeAccountState;
89
+ response: Response;
90
+ responseHeaders: Record<string, string>;
91
+ tracer?: ProxyTracer;
92
+ requestStartTime: number;
93
+ fetchStartMs: number;
94
+ attemptNumber: number;
95
+ finalBodyStr: string;
96
+ upstreamSpan?: import("@opentelemetry/api").Span;
97
+ logProxyBody: ProxyBodyCaptureLogger;
98
+ logFinalRequest: (status: number, accountLabel: string, accountType: string, errorType?: string, errorMessage?: string, extra?: {
99
+ inputTokens?: number;
100
+ outputTokens?: number;
101
+ cacheCreationTokens?: number;
102
+ cacheReadTokens?: number;
103
+ }) => void;
104
+ }): Promise<AnthropicSuccessResult>;
80
105
  declare function getStreamFailureDetails(outcome: StreamTerminalOutcome): {
81
106
  status: number;
82
107
  errorType: string;
83
108
  message: string;
84
109
  } | undefined;
110
+ declare function handleAnthropicAuthRetry(args: {
111
+ ctx: ServerContext;
112
+ body: ClaudeRequest;
113
+ account: ProxyPassthroughAccount;
114
+ accountState: RuntimeAccountState;
115
+ headers: Record<string, string>;
116
+ buildUpstreamBody: (token: string) => {
117
+ bodyStr: string;
118
+ sessionId?: string;
119
+ };
120
+ enabledAccounts: ProxyPassthroughAccount[];
121
+ orderedAccounts: ProxyPassthroughAccount[];
122
+ response: Response;
123
+ tracer?: ProxyTracer;
124
+ requestStartTime: number;
125
+ fetchStartMs: number;
126
+ attemptNumber: number;
127
+ finalBodyStr: string;
128
+ upstreamSpan?: import("@opentelemetry/api").Span;
129
+ logAttempt: (status: number, errorType?: string, errorMessage?: string, extra?: {
130
+ inputTokens?: number;
131
+ outputTokens?: number;
132
+ cacheCreationTokens?: number;
133
+ cacheReadTokens?: number;
134
+ }) => void;
135
+ logProxyBody: ProxyBodyCaptureLogger;
136
+ logFinalRequest: (status: number, accountLabel: string, accountType: string, errorType?: string, errorMessage?: string, extra?: {
137
+ inputTokens?: number;
138
+ outputTokens?: number;
139
+ cacheCreationTokens?: number;
140
+ cacheReadTokens?: number;
141
+ }) => void;
142
+ lastError: unknown;
143
+ authFailureMessage: string | null;
144
+ sawRateLimit: boolean;
145
+ sawTransientFailure: boolean;
146
+ sawNetworkError: boolean;
147
+ }): Promise<AnthropicAuthRetryResult>;
148
+ declare function finalizeAnthropicTerminalFetchError(args: {
149
+ terminalError: NonNullable<AnthropicUpstreamFetchResult["terminalError"]>;
150
+ account: ProxyPassthroughAccount;
151
+ tracer?: ProxyTracer;
152
+ requestStartTime: number;
153
+ attemptNumber: number;
154
+ logProxyBody: ProxyBodyCaptureLogger;
155
+ logFinalRequest: ClaudeFinalRequestLogger;
156
+ }): Response | unknown;
157
+ /**
158
+ * Detect Anthropic's anti-abuse / request-construction 429.
159
+ *
160
+ * The subscription/OAuth path rejects requests it does not recognise as genuine
161
+ * Claude Code traffic with a 429 `rate_limit_error` whose message is literally
162
+ * "Error" and which carries NONE of the real rate-limit headers (no retry-after,
163
+ * no anthropic-ratelimit-*). This is NOT a capacity limit — retrying or rotating
164
+ * accounts cannot fix it and only burns quota, so the caller must fail fast and
165
+ * return a non-retryable request error instead of "all accounts rate-limited".
166
+ */
167
+ declare function isAntiAbuseConstruction429(headers: Record<string, string>, body: string): boolean;
168
+ declare function fetchAnthropicAccountResponse(args: {
169
+ url: string;
170
+ headers: Record<string, string>;
171
+ finalBodyStr: string;
172
+ account: ProxyPassthroughAccount;
173
+ accountState: RuntimeAccountState;
174
+ enabledAccounts: ProxyPassthroughAccount[];
175
+ orderedAccounts: ProxyPassthroughAccount[];
176
+ tracer?: ProxyTracer;
177
+ logAttempt: AnthropicAttemptLogger;
178
+ logProxyBody: ProxyBodyCaptureLogger;
179
+ fetchStartMs: number;
180
+ attemptNumber: number;
181
+ currentLastError: unknown;
182
+ currentSawRateLimit: boolean;
183
+ currentSawNetworkError: boolean;
184
+ upstreamSpan?: import("@opentelemetry/api").Span;
185
+ }): Promise<AnthropicUpstreamFetchResult>;
186
+ declare function shouldAttemptClaudeFallback(loopState: AnthropicLoopState): boolean;
85
187
  /**
86
188
  * Create Claude-compatible proxy routes.
87
189
  *
@@ -94,6 +196,7 @@ declare function getStreamFailureDetails(outcome: StreamTerminalOutcome): {
94
196
  */
95
197
  export declare function createClaudeProxyRoutes(modelRouter?: ModelRouter, basePath?: string, accountStrategy?: "round-robin" | "fill-first", passthroughMode?: boolean, primaryAccountKey?: string, accountAllowlist?: AccountAllowlist): RouteGroup;
96
198
  export declare function getTransientSameAccountRetryDelayMs(retryNumber: number): number;
199
+ declare function describeTransportError(error: unknown): string;
97
200
  /**
98
201
  * Parse a Claude error payload when available.
99
202
  */
@@ -132,5 +235,19 @@ export declare const __testHooks: {
132
235
  getPrimaryAccountIndex: () => number;
133
236
  setAccountRuntimeState: (key: string, state: Partial<RuntimeAccountState>) => void;
134
237
  resetAllRuntimeState: () => void;
238
+ polyfillOAuthBody: (bodyStr: string, isClaudeClientRequest: boolean) => {
239
+ bodyStr: string;
240
+ sessionId?: string;
241
+ };
242
+ isAntiAbuseConstruction429: typeof isAntiAbuseConstruction429;
243
+ fetchAnthropicAccountResponse: typeof fetchAnthropicAccountResponse;
244
+ finalizeAnthropicTerminalFetchError: typeof finalizeAnthropicTerminalFetchError;
245
+ handleAnthropicAuthRetry: typeof handleAnthropicAuthRetry;
246
+ handleAnthropicStreamingSuccessResponse: typeof handleAnthropicStreamingSuccessResponse;
247
+ claimTransientRateLimitRetry: typeof claimTransientRateLimitRetry;
248
+ claimTransientCooldownAdmission: typeof claimTransientCooldownAdmission;
249
+ waitForTransientAccountAvailability: typeof waitForTransientAccountAvailability;
250
+ describeTransportError: typeof describeTransportError;
251
+ shouldAttemptClaudeFallback: typeof shouldAttemptClaudeFallback;
135
252
  };
136
253
  export {};