@juspay/neurolink 12.40.3 → 12.41.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 (36) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/dist/browser/neurolink.min.js +447 -443
  3. package/dist/cli/commands/proxy.js +5 -1
  4. package/dist/proxy/accountLedger.js +3 -0
  5. package/dist/proxy/codexOutboundCache.d.ts +52 -0
  6. package/dist/proxy/codexOutboundCache.js +147 -0
  7. package/dist/proxy/codexOutboundFallback.d.ts +27 -2
  8. package/dist/proxy/codexOutboundFallback.js +147 -11
  9. package/dist/proxy/codexResponsesFormat.js +7 -1
  10. package/dist/proxy/codexToAnthropicFallback.js +6 -0
  11. package/dist/proxy/proxyAnalysis.js +4 -0
  12. package/dist/proxy/proxyConfig.js +120 -0
  13. package/dist/proxy/proxyTokenUsage.d.ts +15 -0
  14. package/dist/proxy/proxyTokenUsage.js +33 -0
  15. package/dist/proxy/proxyTracer.d.ts +16 -1
  16. package/dist/proxy/proxyTracer.js +26 -5
  17. package/dist/proxy/requestLogger.js +9 -0
  18. package/dist/proxy/runtimeConfig.js +20 -0
  19. package/dist/proxy/sseInterceptor.js +9 -0
  20. package/dist/proxy/vertexAnthropicFallback.js +9 -0
  21. package/dist/server/routes/claudeProxyRoutes.js +65 -1
  22. package/dist/server/routes/codexProxyRoutes.d.ts +39 -3
  23. package/dist/server/routes/codexProxyRoutes.js +792 -8
  24. package/dist/server/routes/index.d.ts +8 -0
  25. package/dist/server/routes/index.js +9 -1
  26. package/dist/types/analytics.d.ts +25 -0
  27. package/dist/types/codex.d.ts +45 -1
  28. package/dist/types/proxy.d.ts +40 -2
  29. package/dist/types/proxyClient.d.ts +2 -0
  30. package/dist/types/server.d.ts +15 -0
  31. package/dist/types/subscription.d.ts +22 -0
  32. package/dist/utils/anthropicCacheBreakpoints.d.ts +2 -2
  33. package/dist/utils/anthropicCacheBreakpoints.js +14 -3
  34. package/dist/utils/pricing.js +101 -24
  35. package/docs-site/static/search-index.json +17 -6
  36. package/package.json +1 -1
@@ -17,7 +17,7 @@
17
17
  * never collides with anthropic entries) and does pre-commit rotation only, not
18
18
  * the full transient-budget / admission machinery.
19
19
  */
20
- import type { AccountQuota, CodexRefreshTokenStore, CodexRuntimeAccount, CodexTokenRefresher, RateLimitCoolingReason, RouteGroup, ServerContext } from "../../types/index.js";
20
+ import type { AccountQuota, CodexRefreshTokenStore, CodexResponseEnvelope, CodexResponseStream, CodexRuntimeAccount, CodexTokenRefresher, RateLimitCoolingReason, RouteGroup, ServerContext, ProxyRuntimeConfigProvider } from "../../types/index.js";
21
21
  declare function refreshCodexTokenOnceWithDependencies(key: string, refreshToken: string, store: CodexRefreshTokenStore, refresh: CodexTokenRefresher): Promise<{
22
22
  accessToken: string;
23
23
  refreshToken: string;
@@ -47,15 +47,49 @@ declare function planCodexCooldown(quota: AccountQuota | null, retryAfterMs: num
47
47
  coolingUntil: number;
48
48
  reason: RateLimitCoolingReason;
49
49
  };
50
+ /**
51
+ * Drive a `CodexResponseStream`'s `frames` generator into a `Response` body,
52
+ * calling `onSettled` exactly once with the outcome: the terminal envelope on
53
+ * a normal finish, the thrown error on the (never expected, still handled)
54
+ * post-commit failure, or `cancelled` when the consumer cancels the
55
+ * `ReadableStream` first (client disconnect, or an upstream timeout/abort).
56
+ *
57
+ * `createAnthropicFallbackStream`'s generator never throws once past its own
58
+ * internal preflight (codexToAnthropicFallback.ts:220-517) — every
59
+ * post-commit failure is instead serialized as a `response.failed` frame and
60
+ * the generator completes normally — so the `catch` branch here is a
61
+ * defensive backstop, not the documented failure path.
62
+ */
63
+ declare function wrapCodexOutboundResponseStream(codecStream: CodexResponseStream, headers: Record<string, string>, onSettled: (result: {
64
+ kind: "completed";
65
+ envelope: CodexResponseEnvelope;
66
+ } | {
67
+ kind: "error";
68
+ error: unknown;
69
+ } | {
70
+ kind: "cancelled";
71
+ }) => void): Response;
50
72
  /** Core pooled handler for POST /backend-api/codex/responses. */
51
- export declare function handleCodexResponsesRequest(ctx: ServerContext): Promise<Response>;
73
+ export declare function handleCodexResponsesRequest(ctx: ServerContext, runtimeConfigProvider?: ProxyRuntimeConfigProvider, loopbackPort?: number, internalDispatch?: (request: Request) => Response | Promise<Response>): Promise<Response>;
52
74
  /**
53
75
  * Create Codex proxy routes.
54
76
  *
55
77
  * @param basePath - Base path prefix (default "").
78
+ * @param runtimeConfigProvider - Optional runtime config snapshot reader.
79
+ * Gates the Codex-outbound fallback dispatcher at all four insertion
80
+ * points in `dispatch()`: omitting it (or a snapshot with the feature
81
+ * disabled / no targets configured) reproduces today's behavior exactly.
82
+ * @param loopbackPort - The in-process HTTP port the outbound-fallback leg's
83
+ * Anthropic-pool loopback request targets (mirrors `createOpenAIProxyRoutes`'s
84
+ * bridge). Required only for an `anthropic` target; the `vertex` target
85
+ * dispatches via `executeVertexAnthropicFallback` and never reads it.
86
+ * @param internalDispatch - Optional in-process fetch (`(request) =>
87
+ * app.fetch(request)`), so the outbound-fallback loopback never re-enters
88
+ * the public listener. Falls back to a real `fetch` against
89
+ * `loopbackPort` when omitted.
56
90
  * @returns RouteGroup with the Codex backend Responses endpoint.
57
91
  */
58
- export declare function createCodexProxyRoutes(basePath?: string): RouteGroup;
92
+ export declare function createCodexProxyRoutes(basePath?: string, runtimeConfigProvider?: ProxyRuntimeConfigProvider, loopbackPort?: number, internalDispatch?: (request: Request) => Response | Promise<Response>): RouteGroup;
59
93
  export declare const __testHooks: {
60
94
  loadCodexProxyAccounts: typeof loadCodexProxyAccounts;
61
95
  orderCodexAccounts: typeof orderCodexAccounts;
@@ -64,5 +98,7 @@ export declare const __testHooks: {
64
98
  refreshCodexTokenOnce: typeof refreshCodexTokenOnce;
65
99
  refreshCodexTokenOnceWithDependencies: typeof refreshCodexTokenOnceWithDependencies;
66
100
  codexRefreshInFlightSize: () => number;
101
+ setOutboundFallbackTimeoutMsForTests: (ms: number | null) => void;
102
+ wrapCodexOutboundResponseStream: typeof wrapCodexOutboundResponseStream;
67
103
  };
68
104
  export {};