@juspay/neurolink 10.9.0 → 10.10.0

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 (34) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/browser/neurolink.min.js +379 -379
  3. package/dist/cli/commands/proxy.js +80 -20
  4. package/dist/lib/providers/anthropic/client.d.ts +22 -7
  5. package/dist/lib/providers/anthropic/client.js +83 -58
  6. package/dist/lib/providers/anthropic/rateLimitCapture.d.ts +82 -0
  7. package/dist/lib/providers/anthropic/rateLimitCapture.js +375 -0
  8. package/dist/lib/proxy/proxyLifecycle.d.ts +5 -0
  9. package/dist/lib/proxy/proxyLifecycle.js +61 -11
  10. package/dist/lib/proxy/quotaHeaders.d.ts +73 -0
  11. package/dist/lib/proxy/quotaHeaders.js +189 -0
  12. package/dist/lib/proxy/usageStats.d.ts +2 -0
  13. package/dist/lib/proxy/usageStats.js +4 -0
  14. package/dist/lib/server/routes/claudeProxyRoutes.js +132 -17
  15. package/dist/lib/types/analytics.d.ts +8 -0
  16. package/dist/lib/types/generate.d.ts +12 -0
  17. package/dist/lib/types/proxy.d.ts +50 -0
  18. package/dist/lib/types/subscription.d.ts +77 -0
  19. package/dist/providers/anthropic/client.d.ts +22 -7
  20. package/dist/providers/anthropic/client.js +83 -58
  21. package/dist/providers/anthropic/rateLimitCapture.d.ts +82 -0
  22. package/dist/providers/anthropic/rateLimitCapture.js +374 -0
  23. package/dist/proxy/proxyLifecycle.d.ts +5 -0
  24. package/dist/proxy/proxyLifecycle.js +61 -11
  25. package/dist/proxy/quotaHeaders.d.ts +73 -0
  26. package/dist/proxy/quotaHeaders.js +188 -0
  27. package/dist/proxy/usageStats.d.ts +2 -0
  28. package/dist/proxy/usageStats.js +4 -0
  29. package/dist/server/routes/claudeProxyRoutes.js +132 -17
  30. package/dist/types/analytics.d.ts +8 -0
  31. package/dist/types/generate.d.ts +12 -0
  32. package/dist/types/proxy.d.ts +50 -0
  33. package/dist/types/subscription.d.ts +77 -0
  34. package/package.json +3 -1
@@ -87,6 +87,83 @@ export type AnthropicRateLimitInfo = {
87
87
  * Retry-After header value in seconds (present on 429 responses)
88
88
  */
89
89
  retryAfter?: number;
90
+ /**
91
+ * Subscription (OAuth) window utilization, 0.0-1.0 of capacity USED, from
92
+ * `anthropic-ratelimit-unified-5h-utilization`.
93
+ *
94
+ * Anthropic publishes utilization for subscription windows, never an
95
+ * absolute remaining count — there is no message or token figure to report.
96
+ * `sessionLeftPct` below is the derived "how much is left".
97
+ */
98
+ sessionUtilization?: number;
99
+ /** "allowed" | "throttled" | "rejected" for the 5h window. */
100
+ sessionStatus?: string;
101
+ /** Unix epoch seconds at which the 5h window resets. */
102
+ sessionResetAt?: number;
103
+ /** Whole-percent capacity remaining in the 5h window (100 - utilization). */
104
+ sessionLeftPct?: number;
105
+ /** 7d window utilization, 0.0-1.0 of capacity USED. */
106
+ weeklyUtilization?: number;
107
+ weeklyStatus?: string;
108
+ weeklyResetAt?: number;
109
+ weeklyLeftPct?: number;
110
+ /** Authoritative top-level unified status; can be "rejected" even while both
111
+ * sub-windows still report "allowed". */
112
+ unifiedStatus?: string;
113
+ /** Whether overage is permitted once a window is exhausted. */
114
+ overageStatus?: string;
115
+ };
116
+ /**
117
+ * Per-request limit snapshot as observed by the Anthropic provider.
118
+ *
119
+ * Assembled from response headers on every request — whether the provider is
120
+ * talking directly to Anthropic (both auth methods) or through the NeuroLink
121
+ * Claude proxy. The `account`/`pool`/`servedBy` fields are populated only by
122
+ * the proxy, which is the only party that knows them.
123
+ */
124
+ export type ClaudeLimitSnapshot = {
125
+ /** Rate-limit figures parsed from `anthropic-ratelimit-*` headers. */
126
+ rateLimit: AnthropicRateLimitInfo;
127
+ /**
128
+ * Provenance of the quota numbers. "snapshot" means the proxy reported a
129
+ * previously captured reading rather than one from this response; "none"
130
+ * means no Anthropic account served the request (e.g. a fallback provider).
131
+ * Absent when talking directly to Anthropic, where any figures are live.
132
+ */
133
+ quotaSource?: "live" | "snapshot" | "none";
134
+ /** Proxy account label that served the request. */
135
+ account?: string;
136
+ /** "oauth" | "api_key" | "passthrough". */
137
+ accountType?: string;
138
+ /** Upstream that produced the response — "anthropic" or a fallback provider. */
139
+ servedBy?: string;
140
+ /** Epoch ms until which the serving account is cooling. */
141
+ accountCoolingUntil?: number;
142
+ accountCoolingReason?: string;
143
+ /** Proxy account-pool headroom at response time. */
144
+ pool?: {
145
+ available?: number;
146
+ cooling?: number;
147
+ bestSessionLeftPct?: number;
148
+ };
149
+ /** Anthropic request id, for correlating with provider-side logs. */
150
+ requestId?: string;
151
+ /** HTTP status of the response the snapshot came from. */
152
+ status?: number;
153
+ /** Epoch ms when this snapshot was captured. */
154
+ capturedAt: number;
155
+ };
156
+ /**
157
+ * Per-request capture slot the Anthropic fetch wrapper writes into.
158
+ *
159
+ * Held in AsyncLocalStorage for the duration of a generate/stream call, so
160
+ * concurrent calls on one provider instance cannot see each other's limits.
161
+ * `headers` keeps the raw response header bag so the AI-SDK model adapter can
162
+ * report real response headers.
163
+ */
164
+ export type ClaudeLimitCaptureSlot = {
165
+ snapshot?: ClaudeLimitSnapshot;
166
+ headers?: Record<string, string>;
90
167
  };
91
168
  /**
92
169
  * Response metadata including rate limit information
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/neurolink",
3
- "version": "10.9.0",
3
+ "version": "10.10.0",
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": {
@@ -222,6 +222,8 @@
222
222
  "test:agent-plumbing": "npx tsx test/continuous-test-suite-agent-plumbing.ts",
223
223
  "test:tool-execution-recorder": "npx tsx test/continuous-test-suite-tool-execution-recorder.ts",
224
224
  "test:proxy-terminal-errors": "npx tsx test/continuous-test-suite-proxy-terminal-errors.ts",
225
+ "test:proxy-limit-headers": "npx tsx test/continuous-test-suite-proxy-limit-headers.ts",
226
+ "test:anthropic-limit-capture": "npx tsx test/continuous-test-suite-anthropic-limit-capture.ts",
225
227
  "test:audio": "npx tsx test/continuous-test-suite-audio.ts",
226
228
  "test:office": "npx tsx test/continuous-test-suite-office.ts",
227
229
  "test:tts:unit": "npx tsx test/continuous-test-suite-tts-unit.ts",