@juspay/neurolink 11.1.1 → 11.2.1

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 (74) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/auth/codexOAuth.d.ts +67 -0
  3. package/dist/auth/codexOAuth.js +202 -0
  4. package/dist/auth/index.d.ts +1 -0
  5. package/dist/auth/index.js +4 -0
  6. package/dist/browser/neurolink.min.js +401 -401
  7. package/dist/cli/commands/auth.d.ts +27 -8
  8. package/dist/cli/commands/auth.js +425 -6
  9. package/dist/cli/commands/proxy.js +230 -5
  10. package/dist/cli/factories/authCommandFactory.d.ts +8 -0
  11. package/dist/cli/factories/authCommandFactory.js +74 -1
  12. package/dist/lib/auth/codexOAuth.d.ts +67 -0
  13. package/dist/lib/auth/codexOAuth.js +203 -0
  14. package/dist/lib/auth/index.d.ts +1 -0
  15. package/dist/lib/auth/index.js +4 -0
  16. package/dist/lib/providers/configuredOpenAICompat.d.ts +24 -0
  17. package/dist/lib/providers/configuredOpenAICompat.js +60 -0
  18. package/dist/lib/providers/openaiCompatCatalog.d.ts +24 -0
  19. package/dist/lib/providers/openaiCompatCatalog.js +272 -0
  20. package/dist/lib/proxy/accountCooldown.js +35 -2
  21. package/dist/lib/proxy/accountQuota.d.ts +29 -3
  22. package/dist/lib/proxy/accountQuota.js +203 -12
  23. package/dist/lib/proxy/accountUsage.js +15 -2
  24. package/dist/lib/proxy/codexAccountUsage.d.ts +26 -0
  25. package/dist/lib/proxy/codexAccountUsage.js +174 -0
  26. package/dist/lib/proxy/proxyAnalysis.js +12 -1
  27. package/dist/lib/proxy/proxyConfig.js +24 -0
  28. package/dist/lib/proxy/routingEvidence.d.ts +12 -1
  29. package/dist/lib/proxy/routingEvidence.js +23 -0
  30. package/dist/lib/proxy/runtimeConfig.js +3 -0
  31. package/dist/lib/server/routes/claudeProxyRoutes.d.ts +79 -5
  32. package/dist/lib/server/routes/claudeProxyRoutes.js +653 -72
  33. package/dist/lib/server/routes/codexProxyRoutes.d.ts +64 -0
  34. package/dist/lib/server/routes/codexProxyRoutes.js +454 -0
  35. package/dist/lib/types/cli.d.ts +7 -1
  36. package/dist/lib/types/codex.d.ts +95 -0
  37. package/dist/lib/types/codex.js +15 -0
  38. package/dist/lib/types/index.d.ts +1 -0
  39. package/dist/lib/types/index.js +1 -0
  40. package/dist/lib/types/providers.d.ts +99 -0
  41. package/dist/lib/types/proxy.d.ts +83 -0
  42. package/dist/lib/types/subscription.d.ts +13 -0
  43. package/dist/lib/utils/providerConfig.d.ts +23 -1
  44. package/dist/lib/utils/providerConfig.js +60 -0
  45. package/dist/providers/configuredOpenAICompat.d.ts +24 -0
  46. package/dist/providers/configuredOpenAICompat.js +59 -0
  47. package/dist/providers/openaiCompatCatalog.d.ts +24 -0
  48. package/dist/providers/openaiCompatCatalog.js +271 -0
  49. package/dist/proxy/accountCooldown.js +35 -2
  50. package/dist/proxy/accountQuota.d.ts +29 -3
  51. package/dist/proxy/accountQuota.js +203 -12
  52. package/dist/proxy/accountUsage.js +15 -2
  53. package/dist/proxy/codexAccountUsage.d.ts +26 -0
  54. package/dist/proxy/codexAccountUsage.js +173 -0
  55. package/dist/proxy/proxyAnalysis.js +12 -1
  56. package/dist/proxy/proxyConfig.js +24 -0
  57. package/dist/proxy/routingEvidence.d.ts +12 -1
  58. package/dist/proxy/routingEvidence.js +23 -0
  59. package/dist/proxy/runtimeConfig.js +3 -0
  60. package/dist/server/routes/claudeProxyRoutes.d.ts +79 -5
  61. package/dist/server/routes/claudeProxyRoutes.js +653 -72
  62. package/dist/server/routes/codexProxyRoutes.d.ts +64 -0
  63. package/dist/server/routes/codexProxyRoutes.js +453 -0
  64. package/dist/types/cli.d.ts +7 -1
  65. package/dist/types/codex.d.ts +95 -0
  66. package/dist/types/codex.js +14 -0
  67. package/dist/types/index.d.ts +1 -0
  68. package/dist/types/index.js +1 -0
  69. package/dist/types/providers.d.ts +99 -0
  70. package/dist/types/proxy.d.ts +83 -0
  71. package/dist/types/subscription.d.ts +13 -0
  72. package/dist/utils/providerConfig.d.ts +23 -1
  73. package/dist/utils/providerConfig.js +60 -0
  74. package/package.json +3 -1
@@ -12,7 +12,7 @@
12
12
  import { buildTranslationOptions } from "../../proxy/proxyTranslationEngine.js";
13
13
  import { ProxyTracer } from "../../proxy/proxyTracer.js";
14
14
  import { isPermanentRefreshFailure } from "../../proxy/tokenRefresh.js";
15
- import type { AccountAllowlist, AccountAdmissionLease, AccountCooldownPlan, AccountQuota, AccountUsageFetchResult, AnthropicAttemptLogger, AnthropicAuthRetryResult, AnthropicLoopState, AnthropicNonOkResult, AnthropicSuccessResult, AnthropicUpstreamFetchResult, ClaudeFinalRequestLogger, ClaudeLoggedErrorBuilder, ClaudeRequest, ClaudeProxyRouteRuntimeOptions, ModelRouterInterface, ParsedClaudeError, ProxyAccountRoutingDecision, ProxyAccountSortMetrics, ProxyBodyCaptureLogger, ProxyLimitsRefreshResponse, ProxyQuotaCooldownUpdate, ProxyPassthroughAccount, QueuedAccountAdmission, RouteGroup, RuntimeAccountState, ServerContext, StreamTerminalOutcome } from "../../types/index.js";
15
+ import type { AccountAllowlist, AccountAdmissionLease, AccountCooldownPlan, AccountQuota, AccountQuotaWindow, AccountUsageFetchResult, AnthropicAttemptLogger, AnthropicAuthRetryResult, AnthropicEntitlementFailure, AnthropicLoopState, AnthropicScopedExhaustion, AnthropicNonOkResult, AnthropicSuccessResult, AnthropicUpstreamFetchResult, ClaudeFinalRequestLogger, ClaudeLoggedErrorBuilder, ClaudeRequest, ClaudeProxyRouteRuntimeOptions, ModelRouterInterface, ParsedClaudeError, ProxyAccountRoutingDecision, ProxyAccountSortMetrics, ProxyBodyCaptureLogger, ProxyLimitsRefreshResponse, ProxyQuotaCooldownUpdate, ProxyOveragePolicy, ProxyPassthroughAccount, QueuedAccountAdmission, RouteGroup, RuntimeAccountState, ServerContext, StreamTerminalOutcome } from "../../types/index.js";
16
16
  declare function tryAcquireAccountAdmission(accountKey: string, capacity: number | undefined): AccountAdmissionLease | undefined;
17
17
  declare function enqueueAccountAdmission(accountKey: string, capacity: number): QueuedAccountAdmission;
18
18
  declare function acquireAccountAdmission(accountKey: string, capacity: number, abortSignal?: AbortSignal, timeoutMs?: number): Promise<AccountAdmissionLease | undefined>;
@@ -54,7 +54,7 @@ declare function resetEpochToMs(resetEpoch: number | undefined, now: number): nu
54
54
  * burst / acceleration limit) is transient: honor retry-after as a floor,
55
55
  * allow a couple of jittered same-account retries, then a short cooldown.
56
56
  */
57
- declare function planCooldownFor429(quota: AccountQuota | null, retryAfterMs: number, now: number, unifiedStatus?: string | undefined): AccountCooldownPlan;
57
+ declare function planCooldownFor429(quota: AccountQuota | null, retryAfterMs: number, now: number, unifiedStatus?: string | undefined, policy?: ProxyOveragePolicy): AccountCooldownPlan;
58
58
  /**
59
59
  * Proactively cool an account when a SUCCESS response reveals a window has just
60
60
  * flipped to "rejected" (the boundary request that spends the last of the quota
@@ -62,7 +62,7 @@ declare function planCooldownFor429(quota: AccountQuota | null, retryAfterMs: nu
62
62
  * its reset so the next request skips it instead of discovering the limit via a
63
63
  * 429, except when the provider explicitly enables paid overage.
64
64
  */
65
- declare function reconcileCooldownFromQuota(state: RuntimeAccountState, quota: AccountQuota, now: number): ProxyQuotaCooldownUpdate;
65
+ declare function reconcileCooldownFromQuota(state: RuntimeAccountState, quota: AccountQuota, now: number, policy?: ProxyOveragePolicy): ProxyQuotaCooldownUpdate;
66
66
  /**
67
67
  * Seed each account's runtime quota from the persisted snapshots in
68
68
  * ~/.neurolink/account-quotas.json (keyed by label). Runtime state is
@@ -88,6 +88,47 @@ declare function refreshAccountLimits(options?: {
88
88
  accountFilter?: string;
89
89
  snapshotOnly?: boolean;
90
90
  }): Promise<ProxyLimitsRefreshResponse>;
91
+ /**
92
+ * Publish the operator's extra-usage policy for paths that cannot receive it
93
+ * explicitly. Callers that make a routing or cooldown decision take it as a
94
+ * parameter instead — see {@link isOverageUsable} — so a concurrent request or
95
+ * a hot config reload cannot change the answer mid-flight.
96
+ *
97
+ * `undefined` means "no runtime config on this path", which is not a request to
98
+ * clear an operator's setting, so the current value is kept.
99
+ */
100
+ declare function setOveragePolicy(policy: ProxyOveragePolicy | undefined): void;
101
+ /**
102
+ * Find the model-scoped quota window that applies to the requested model.
103
+ *
104
+ * Two sources describe the same cap differently: response headers carry the wire
105
+ * id of the model just served, while the usage API reports a DISPLAY name
106
+ * ("Fable", "Claude Opus 4.6"). So an exact wire-id match is tried first and
107
+ * display-name containment over alphanumeric-normalized forms is the fallback.
108
+ * Among equally specific matches the freshest observation wins, which favours
109
+ * the continuously-updated header window over a manually-refreshed one.
110
+ *
111
+ * Returns null whenever the account reports no applicable, still-fresh scoped
112
+ * cap — the common case.
113
+ */
114
+ declare function matchScopedQuotaWindow(quota: AccountQuota | undefined, requestedModel: string | undefined, now?: number): AccountQuotaWindow | null;
115
+ /**
116
+ * Split a candidate set by whether each account can still serve the requested
117
+ * model under its model-scoped cap.
118
+ *
119
+ * An account is scoped out only on evidence strong enough to act on: a fresh
120
+ * window, a reset that is actually ticking, a rejected/spent reading, and no
121
+ * paid extra usage to absorb the overflow. Anything weaker leaves the account
122
+ * eligible — a stale or mis-parsed window must never be able to empty the pool.
123
+ *
124
+ * `exhaustion` is populated only when every candidate is scoped out AND the
125
+ * evidence is trustworthy, which is what lets the caller report "switch model"
126
+ * instead of a generic rate limit.
127
+ */
128
+ declare function evaluateScopedExhaustion(accounts: ProxyPassthroughAccount[], requestedModel: string | undefined, now?: number, policy?: ProxyOveragePolicy): {
129
+ eligible: ProxyPassthroughAccount[];
130
+ exhaustion: AnthropicScopedExhaustion | null;
131
+ };
91
132
  /**
92
133
  * Order accounts to MAXIMIZE quota utilization (fill-first, smart order):
93
134
  * spend the overall weekly allowance that expires SOONEST first, so quota
@@ -112,7 +153,7 @@ declare function refreshAccountLimits(options?: {
112
153
  * Cooling/rejected accounts sort last, soonest-back-to-service first, as
113
154
  * last resort.
114
155
  */
115
- declare function orderAccountsByQuota(accounts: ProxyPassthroughAccount[], now: number, primaryKey: string | undefined, sessionSoftLimit?: number, sessionResetToleranceMs?: number): ProxyPassthroughAccount[];
156
+ declare function orderAccountsByQuota(accounts: ProxyPassthroughAccount[], now: number, primaryKey: string | undefined, sessionSoftLimit?: number, sessionResetToleranceMs?: number, requestedModel?: string): ProxyPassthroughAccount[];
116
157
  declare function scheduleAdaptiveQuotaRefreshes(accounts: ProxyPassthroughAccount[], orderedAccounts: ProxyPassthroughAccount[], sessionSoftLimit: number, routingMetrics?: ReadonlyMap<string, ProxyAccountSortMetrics>): void;
117
158
  declare function scheduleHandoffQuotaRefresh(current: ProxyPassthroughAccount, candidate: ProxyPassthroughAccount | undefined, handoffEpoch: number, sessionSoftLimit: number): void;
118
159
  declare function buildRoutingDecision(args: {
@@ -158,6 +199,8 @@ declare function buildClaudeAnthropicFailureResponse(args: {
158
199
  body: string;
159
200
  contentType?: string;
160
201
  } | null;
202
+ entitlementFailure: AnthropicEntitlementFailure | null;
203
+ scopedExhaustion: AnthropicScopedExhaustion | null;
161
204
  sawNetworkError: boolean;
162
205
  sawTransientFailure: boolean;
163
206
  sawRateLimit: boolean;
@@ -231,6 +274,7 @@ declare function handleAnthropicAuthRetry(args: {
231
274
  }) => void;
232
275
  lastError: unknown;
233
276
  authFailureMessage: string | null;
277
+ entitlementFailure: AnthropicEntitlementFailure | null;
234
278
  sawRateLimit: boolean;
235
279
  sawTransientFailure: boolean;
236
280
  sawNetworkError: boolean;
@@ -270,6 +314,7 @@ declare function handleAnthropicNonOkResponse(args: {
270
314
  body: string;
271
315
  contentType?: string;
272
316
  } | null;
317
+ entitlementFailure: AnthropicEntitlementFailure | null;
273
318
  }): Promise<AnthropicNonOkResult>;
274
319
  /**
275
320
  * Detect Anthropic's anti-abuse / request-construction 429.
@@ -286,6 +331,7 @@ declare function fetchAnthropicAccountResponse(args: {
286
331
  url: string;
287
332
  headers: Record<string, string>;
288
333
  finalBodyStr: string;
334
+ requestedModel?: string;
289
335
  account: ProxyPassthroughAccount;
290
336
  accountState: RuntimeAccountState;
291
337
  enabledAccounts: ProxyPassthroughAccount[];
@@ -341,6 +387,29 @@ export declare function isInvalidRequestError(status: number, errBody: string):
341
387
  * rather than a terminal client-facing 400.
342
388
  */
343
389
  export declare function isSubscriptionBetaRejection(status: number, errBody: string): boolean;
390
+ /**
391
+ * An entitlement rejection: Anthropic refuses THIS credential on organization
392
+ * or plan policy, e.g. `403 permission_error` /
393
+ * "OAuth authentication is currently not allowed for this organization."
394
+ *
395
+ * The taxonomy makes this safe to rotate on: `permission_error` is reserved for
396
+ * credential/organization permission, distinct from `invalid_request_error`
397
+ * (request shape) and `not_found_error`, both already terminal above. No
398
+ * `permission_error` is caused by the request body, so the identical request
399
+ * can succeed on a different account.
400
+ *
401
+ * Deliberately broad — rotation is cheap and reversible. Persisting the block
402
+ * is gated on the narrower {@link isDurableEntitlementBlock}.
403
+ */
404
+ export declare function isAccountEntitlementError(status: number, errBody: string): boolean;
405
+ /**
406
+ * Whether an entitlement rejection is specific enough to disable the account
407
+ * until someone re-enables it. Narrower than {@link isAccountEntitlementError}
408
+ * because disabling is sticky and user-visible: an unrecognised
409
+ * `permission_error` should rotate through the pool and surface a 403, never
410
+ * durably remove a credential on a guess.
411
+ */
412
+ export declare function isDurableEntitlementBlock(status: number, errBody: string): boolean;
344
413
  /**
345
414
  * Backward-compatible alias — delegates to the shared translation engine.
346
415
  */
@@ -374,7 +443,7 @@ export declare const __testHooks: {
374
443
  scheduleAdaptiveQuotaRefreshes: typeof scheduleAdaptiveQuotaRefreshes;
375
444
  scheduleHandoffQuotaRefresh: typeof scheduleHandoffQuotaRefresh;
376
445
  getQuotaRefreshState: (key: string) => import("../../types/proxy.js").ProxyQuotaRefreshRuntimeState;
377
- buildQuotaRoutingDecision: (accounts: ProxyPassthroughAccount[], now: number, primaryKey: string | undefined, sessionSoftLimit?: number, sessionResetToleranceMs?: number) => ProxyAccountRoutingDecision | undefined;
446
+ buildQuotaRoutingDecision: (accounts: ProxyPassthroughAccount[], now: number, primaryKey: string | undefined, sessionSoftLimit?: number, sessionResetToleranceMs?: number, requestedModel?: string) => ProxyAccountRoutingDecision | undefined;
378
447
  buildRoutingDecision: typeof buildRoutingDecision;
379
448
  resetEpochToMs: typeof resetEpochToMs;
380
449
  seedRuntimeQuotasFromDisk: typeof seedRuntimeQuotasFromDisk;
@@ -413,5 +482,10 @@ export declare const __testHooks: {
413
482
  shouldAttemptClaudeFallback: typeof shouldAttemptClaudeFallback;
414
483
  executeClaudeFallbackWithRetry: typeof executeClaudeFallbackWithRetry;
415
484
  buildClaudeAnthropicFailureResponse: typeof buildClaudeAnthropicFailureResponse;
485
+ isAccountEntitlementError: typeof isAccountEntitlementError;
486
+ isDurableEntitlementBlock: typeof isDurableEntitlementBlock;
487
+ evaluateScopedExhaustion: typeof evaluateScopedExhaustion;
488
+ matchScopedQuotaWindow: typeof matchScopedQuotaWindow;
489
+ setOveragePolicy: typeof setOveragePolicy;
416
490
  };
417
491
  export {};