@juspay/neurolink 10.12.0 → 10.12.2

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.
@@ -110,6 +110,9 @@ function fetchAnthropicUpstream(url, init) {
110
110
  });
111
111
  }
112
112
  const accountRuntimeState = new Map();
113
+ /** Persisted quota is advisory after a restart. Older snapshots cannot reject
114
+ * an account or create a new cooldown because the provider may have reset it. */
115
+ const QUOTA_SNAPSHOT_FRESHNESS_MS = 15 * 60 * 1000;
113
116
  /** Shared across requests so a concurrent burst gets at most two retries for
114
117
  * the account/window, rather than every request starting its own retry chain. */
115
118
  const transientRateLimitRetryBudgets = new Map();
@@ -603,8 +606,9 @@ function reconcileCooldownFromQuota(state, quota, now) {
603
606
  * proxy restart: all accounts tie, selection falls back to token-store
604
607
  * enumeration order, and the first account served becomes self-reinforcing
605
608
  * (it alone has data) — starving the others regardless of their resets.
606
- * Never overwrites fresher in-memory quota; stale disk snapshots degrade
607
- * gracefully because past reset timestamps are ignored by resetEpochToMs.
609
+ * Never overwrites fresher in-memory quota. Persisted quota cannot create or
610
+ * clear a cooldown: only an existing cooldown or fresh upstream response
611
+ * headers can change admission state.
608
612
  */
609
613
  async function seedRuntimeQuotasFromDisk(accounts) {
610
614
  try {
@@ -625,15 +629,6 @@ async function seedRuntimeQuotasFromDisk(accounts) {
625
629
  state.coolingUntil = persistedCooldown.coolingUntil;
626
630
  state.coolingReason = persistedCooldown.reason;
627
631
  }
628
- if (state.quota) {
629
- const cooldownUpdate = reconcileCooldownFromQuota(state, state.quota, now);
630
- if (cooldownUpdate?.kind === "cooled") {
631
- await saveAccountCooldown(account.key, cooldownUpdate.coolingUntil, cooldownUpdate.coolingReason);
632
- }
633
- else if (cooldownUpdate?.kind === "cleared") {
634
- await clearAccountCooldown(account.key, cooldownUpdate.coolingUntil);
635
- }
636
- }
637
632
  }
638
633
  }
639
634
  catch {
@@ -802,47 +797,59 @@ function getSessionResetToleranceMs() {
802
797
  function accountSortMetrics(accountKey, now, sessionSoftLimit, sessionResetToleranceMs) {
803
798
  const st = accountRuntimeState.get(accountKey);
804
799
  const q = st?.quota;
800
+ const quotaLastUpdated = q && Number.isFinite(q.lastUpdated) ? q.lastUpdated : null;
801
+ const quotaAgeMs = quotaLastUpdated === null ? null : Math.max(0, now - quotaLastUpdated);
802
+ const quotaStale = quotaAgeMs !== null && quotaAgeMs > QUOTA_SNAPSHOT_FRESHNESS_MS;
803
+ const routingQuota = quotaStale ? undefined : q;
805
804
  const coolingActive = !!st?.coolingUntil && now < st.coolingUntil;
806
805
  // resetEpochToMs returns undefined for absent OR passed resets, so a
807
806
  // ticking window is exactly "reset !== undefined".
808
- const weeklyReset = resetEpochToMs(q?.weeklyResetAt, now);
809
- const sessionReset = resetEpochToMs(q?.sessionResetAt, now);
807
+ const weeklyReset = resetEpochToMs(routingQuota?.weeklyResetAt, now);
808
+ const sessionReset = resetEpochToMs(routingQuota?.sessionResetAt, now);
810
809
  const sessionTicking = sessionReset !== undefined;
811
810
  const weeklyTicking = weeklyReset !== undefined;
812
- const sessionUsed = q ? (sessionTicking ? (q.sessionUsed ?? 0) : 0) : null;
813
- const weeklyUsed = q ? (weeklyTicking ? (q.weeklyUsed ?? null) : 0) : null;
814
- const sessionStatus = q
811
+ const sessionUsed = routingQuota
815
812
  ? sessionTicking
816
- ? (q.sessionStatus ?? "unknown")
813
+ ? (routingQuota.sessionUsed ?? 0)
814
+ : 0
815
+ : null;
816
+ const weeklyUsed = routingQuota
817
+ ? weeklyTicking
818
+ ? (routingQuota.weeklyUsed ?? null)
819
+ : 0
820
+ : null;
821
+ const sessionStatus = routingQuota
822
+ ? sessionTicking
823
+ ? (routingQuota.sessionStatus ?? "unknown")
817
824
  : "allowed"
818
825
  : null;
819
- const weeklyStatus = q
826
+ const weeklyStatus = routingQuota
820
827
  ? weeklyTicking
821
- ? (q.weeklyStatus ?? "unknown")
828
+ ? (routingQuota.weeklyStatus ?? "unknown")
822
829
  : "allowed"
823
830
  : null;
824
- const overageEligible = isQuotaOverageAvailable(q);
831
+ const overageEligible = isQuotaOverageAvailable(routingQuota);
825
832
  const saturated = sessionStatus === "throttled" ||
826
833
  (sessionTicking && (sessionUsed ?? 0) >= sessionSoftLimit);
827
- const quotaLastUpdated = q && Number.isFinite(q.lastUpdated) ? q.lastUpdated : null;
828
834
  return {
829
835
  usable: !coolingActive &&
830
836
  weeklyStatus !== "rejected" &&
831
837
  (sessionStatus !== "rejected" || overageEligible) &&
832
- (q?.unifiedStatus?.trim().toLowerCase() !== "rejected" ||
838
+ (routingQuota?.unifiedStatus?.trim().toLowerCase() !== "rejected" ||
833
839
  overageEligible),
834
- saturated,
835
- hasQuota: !!q,
840
+ saturated: !quotaStale && saturated,
841
+ hasQuota: !!routingQuota,
842
+ quotaStale,
836
843
  quotaLastUpdated,
837
- quotaAgeMs: quotaLastUpdated === null ? null : Math.max(0, now - quotaLastUpdated),
844
+ quotaAgeMs,
838
845
  coolingActive,
839
846
  coolingReason: st?.coolingReason ?? null,
840
847
  coolingUntil: st?.coolingUntil ?? 0,
841
- unifiedStatus: q?.unifiedStatus ?? null,
842
- fallbackStatus: q?.fallbackStatus ?? null,
843
- upgradePaths: q?.upgradePaths ?? null,
848
+ unifiedStatus: routingQuota?.unifiedStatus ?? null,
849
+ fallbackStatus: routingQuota?.fallbackStatus ?? null,
850
+ upgradePaths: routingQuota?.upgradePaths ?? null,
844
851
  overageEligible,
845
- overageStatus: q?.overageStatus ?? null,
852
+ overageStatus: routingQuota?.overageStatus ?? null,
846
853
  sessionStatus,
847
854
  sessionUsed,
848
855
  sessionResetBucket: sessionTicking
@@ -960,6 +967,7 @@ function buildRoutingDecision(args) {
960
967
  usable: metrics.usable,
961
968
  saturated: metrics.saturated,
962
969
  quotaObserved: metrics.hasQuota,
970
+ quotaStale: metrics.quotaStale,
963
971
  quotaLastUpdated: metrics.quotaLastUpdated,
964
972
  quotaAgeMs: metrics.quotaAgeMs,
965
973
  coolingActive: metrics.coolingActive,
@@ -439,6 +439,7 @@ export type ProxyAccountRoutingCandidate = {
439
439
  usable: boolean;
440
440
  saturated: boolean;
441
441
  quotaObserved: boolean;
442
+ quotaStale: boolean;
442
443
  quotaLastUpdated: number | null;
443
444
  quotaAgeMs: number | null;
444
445
  coolingActive: boolean;
@@ -477,6 +478,7 @@ export type ProxyAccountSortMetrics = {
477
478
  usable: boolean;
478
479
  saturated: boolean;
479
480
  hasQuota: boolean;
481
+ quotaStale: boolean;
480
482
  quotaLastUpdated: number | null;
481
483
  quotaAgeMs: number | null;
482
484
  coolingActive: boolean;
@@ -941,6 +943,8 @@ export type AccountQuota = {
941
943
  upgradePaths?: string;
942
944
  /** "allowed" | "rejected" */
943
945
  overageStatus: string;
946
+ /** Whether Anthropic reports that paid overage is actively serving traffic. */
947
+ overageInUse?: boolean;
944
948
  /** Epoch ms when we last captured this data */
945
949
  lastUpdated: number;
946
950
  /** Dynamic per-plan limit buckets from the usage API `limits[]` array
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/neurolink",
3
- "version": "10.12.0",
3
+ "version": "10.12.2",
4
4
  "packageManager": "pnpm@10.15.1",
5
5
  "description": "TypeScript AI SDK with 24+ LLM providers behind one consistent API. MCP-native (connect any MCP server), voice TTS/STT/realtime, RAG, agents, memory, context compaction. OpenAI · Anthropic · Gemini · Bedrock · Azure · Ollama · DeepSeek · NVIDIA NIM and more.",
6
6
  "author": {