@omnicross/core 0.1.6 → 0.1.7

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 (131) hide show
  1. package/dist/ApiConverter.cjs +2 -2
  2. package/dist/ApiConverter.js +1 -1
  3. package/dist/auth/GeminiCodeAssistProjectResolver.cjs +4 -3
  4. package/dist/auth/GeminiCodeAssistProjectResolver.js +3 -2
  5. package/dist/{chunk-3Z5BQZFM.cjs → chunk-235MXAGX.cjs} +3 -1
  6. package/dist/{chunk-DLXZEZWO.cjs → chunk-2E42SAW3.cjs} +42 -4
  7. package/dist/{chunk-7AK7B36B.cjs → chunk-2Z4XM3H5.cjs} +6 -6
  8. package/dist/{chunk-OEWZUX4G.js → chunk-32O35CIF.js} +9 -20
  9. package/dist/chunk-3SCOLIPT.cjs +63 -0
  10. package/dist/{chunk-SYQF7OIR.js → chunk-3WD4HTR2.js} +2 -0
  11. package/dist/{chunk-SQYVORNP.cjs → chunk-4BB343BI.cjs} +527 -267
  12. package/dist/{chunk-AT7B7SOZ.js → chunk-5NJLQ6T6.js} +21 -10
  13. package/dist/chunk-5RSZYQJH.cjs +62 -0
  14. package/dist/{chunk-IFXJ2BG7.js → chunk-7C7DET6S.js} +51 -6
  15. package/dist/{chunk-UDCC7EMR.js → chunk-E3COOKUP.js} +307 -47
  16. package/dist/chunk-FU7EAR73.js +62 -0
  17. package/dist/{chunk-UX7VWA46.js → chunk-FXR6N3SR.js} +39 -1
  18. package/dist/{chunk-WYTEQ4Q5.cjs → chunk-GDIXXKF2.cjs} +21 -10
  19. package/dist/{chunk-WB6PH56J.js → chunk-GFIZ6LQI.js} +12 -8
  20. package/dist/chunk-GL6XM527.js +61 -0
  21. package/dist/{chunk-EJLH6NFT.cjs → chunk-J3QQ6JS5.cjs} +12 -8
  22. package/dist/{chunk-VRFBB5DB.js → chunk-MYYR3HZL.js} +4 -4
  23. package/dist/{chunk-YJVHCHQX.js → chunk-N7OOJI5V.js} +46 -2
  24. package/dist/chunk-NKVZ6Z3Y.cjs +61 -0
  25. package/dist/{chunk-SNYBEXLB.cjs → chunk-OJGQKHN5.cjs} +3 -1
  26. package/dist/chunk-OTZC4TNH.cjs +79 -0
  27. package/dist/{chunk-6VUQPOV3.cjs → chunk-OVQBNVSV.cjs} +10 -21
  28. package/dist/{chunk-4VLRHHFE.cjs → chunk-OXHNSZ53.cjs} +9 -11
  29. package/dist/{chunk-6CL5HTPQ.js → chunk-PEGTIPB3.js} +8 -10
  30. package/dist/chunk-PO3XB56Z.js +79 -0
  31. package/dist/{chunk-SIZQQD6T.js → chunk-RJ5ZGNI3.js} +42 -5
  32. package/dist/{chunk-KCVJWJST.cjs → chunk-RJUONLUQ.cjs} +47 -10
  33. package/dist/{chunk-BPKCU575.js → chunk-SOO562NM.js} +3 -1
  34. package/dist/{chunk-UNWKG6EI.cjs → chunk-XPIOJQS2.cjs} +51 -6
  35. package/dist/chunk-XXFYLL7R.js +63 -0
  36. package/dist/{chunk-YK57NMIF.cjs → chunk-YWL7YZWS.cjs} +47 -3
  37. package/dist/completion/CompletionService.cjs +23 -19
  38. package/dist/completion/CompletionService.d.cts +1 -0
  39. package/dist/completion/CompletionService.d.ts +1 -0
  40. package/dist/completion/CompletionService.js +22 -18
  41. package/dist/completion.cjs +23 -19
  42. package/dist/completion.d.cts +1 -0
  43. package/dist/completion.d.ts +1 -0
  44. package/dist/completion.js +22 -18
  45. package/dist/index.cjs +26 -22
  46. package/dist/index.d.cts +2 -2
  47. package/dist/index.d.ts +2 -2
  48. package/dist/index.js +26 -22
  49. package/dist/outbound-api/auditCapture.cjs +2 -2
  50. package/dist/outbound-api/auditCapture.d.cts +3 -4
  51. package/dist/outbound-api/auditCapture.d.ts +3 -4
  52. package/dist/outbound-api/auditCapture.js +1 -1
  53. package/dist/outbound-api/routeResolver.d.cts +3 -2
  54. package/dist/outbound-api/routeResolver.d.ts +3 -2
  55. package/dist/outbound-api/subscriptionRegistryPort.d.cts +1 -0
  56. package/dist/outbound-api/subscriptionRegistryPort.d.ts +1 -0
  57. package/dist/outbound-api/types.d.cts +2 -1
  58. package/dist/outbound-api/types.d.ts +2 -1
  59. package/dist/outbound-api.cjs +23 -19
  60. package/dist/outbound-api.d.cts +7 -5
  61. package/dist/outbound-api.d.ts +7 -5
  62. package/dist/outbound-api.js +22 -18
  63. package/dist/pipeline/AccountAllowanceScheduling.d.cts +2 -1
  64. package/dist/pipeline/AccountAllowanceScheduling.d.ts +2 -1
  65. package/dist/pipeline/AccountRouteActivity.cjs +10 -0
  66. package/dist/pipeline/AccountRouteActivity.d.cts +61 -0
  67. package/dist/pipeline/AccountRouteActivity.d.ts +61 -0
  68. package/dist/pipeline/AccountRouteActivity.js +10 -0
  69. package/dist/pipeline/ServerOverloadCounter.cjs +16 -0
  70. package/dist/pipeline/ServerOverloadCounter.d.cts +77 -0
  71. package/dist/pipeline/ServerOverloadCounter.d.ts +77 -0
  72. package/dist/pipeline/ServerOverloadCounter.js +16 -0
  73. package/dist/pipeline/SubscriptionAccountHealth.cjs +4 -2
  74. package/dist/pipeline/SubscriptionAccountHealth.d.cts +32 -3
  75. package/dist/pipeline/SubscriptionAccountHealth.d.ts +32 -3
  76. package/dist/pipeline/SubscriptionAccountHealth.js +3 -1
  77. package/dist/pipeline/upstreamFetch.cjs +4 -3
  78. package/dist/pipeline/upstreamFetch.d.cts +35 -6
  79. package/dist/pipeline/upstreamFetch.d.ts +35 -6
  80. package/dist/pipeline/upstreamFetch.js +3 -2
  81. package/dist/pipeline/upstreamTrace.cjs +4 -2
  82. package/dist/pipeline/upstreamTrace.d.cts +22 -8
  83. package/dist/pipeline/upstreamTrace.d.ts +22 -8
  84. package/dist/pipeline/upstreamTrace.js +3 -1
  85. package/dist/ports.d.cts +1 -1
  86. package/dist/ports.d.ts +1 -1
  87. package/dist/provider-proxy/ProviderProxy.cjs +23 -19
  88. package/dist/provider-proxy/ProviderProxy.d.cts +1 -0
  89. package/dist/provider-proxy/ProviderProxy.d.ts +1 -0
  90. package/dist/provider-proxy/ProviderProxy.js +22 -18
  91. package/dist/provider-proxy/identity/codexCliHeaders.cjs +10 -0
  92. package/dist/provider-proxy/identity/codexCliHeaders.d.cts +45 -0
  93. package/dist/provider-proxy/identity/codexCliHeaders.d.ts +45 -0
  94. package/dist/provider-proxy/identity/codexCliHeaders.js +10 -0
  95. package/dist/provider-proxy/ingress/providerProxyShared.cjs +23 -19
  96. package/dist/provider-proxy/ingress/providerProxyShared.d.cts +11 -1
  97. package/dist/provider-proxy/ingress/providerProxyShared.d.ts +11 -1
  98. package/dist/provider-proxy/ingress/providerProxyShared.js +22 -18
  99. package/dist/provider-proxy/matchText.cjs +2 -2
  100. package/dist/provider-proxy/matchText.d.cts +1 -3
  101. package/dist/provider-proxy/matchText.d.ts +1 -3
  102. package/dist/provider-proxy/matchText.js +1 -1
  103. package/dist/provider-proxy/types.d.cts +5 -0
  104. package/dist/provider-proxy/types.d.ts +5 -0
  105. package/dist/provider-proxy.cjs +23 -19
  106. package/dist/provider-proxy.d.cts +1 -0
  107. package/dist/provider-proxy.d.ts +1 -0
  108. package/dist/provider-proxy.js +22 -18
  109. package/dist/{routeResolver-CHTv_Bs5.d.ts → routeResolver-BxOfunbm.d.ts} +1 -1
  110. package/dist/{routeResolver-kepxnfcC.d.cts → routeResolver-D5OzD0iM.d.cts} +1 -1
  111. package/dist/transformer/transformers/AnthropicTransformer.cjs +3 -2
  112. package/dist/transformer/transformers/AnthropicTransformer.js +2 -1
  113. package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +3 -2
  114. package/dist/transformer/transformers/OpenAIResponseTransformer.js +2 -1
  115. package/dist/transformer/transformers.cjs +7 -6
  116. package/dist/transformer/transformers.js +6 -5
  117. package/dist/transformer.cjs +9 -8
  118. package/dist/transformer.js +8 -7
  119. package/dist/{types-hsoKrVQS.d.ts → types-CqZD77rS.d.ts} +39 -0
  120. package/dist/{types-H3wGZSOo.d.cts → types-gjJ5lJ5n.d.cts} +39 -0
  121. package/dist/usage/pricing-engine.cjs +2 -2
  122. package/dist/usage/pricing-engine.d.cts +20 -0
  123. package/dist/usage/pricing-engine.d.ts +20 -0
  124. package/dist/usage/pricing-engine.js +1 -1
  125. package/dist/usage/usage-recorder.cjs +2 -2
  126. package/dist/usage/usage-recorder.d.cts +5 -1
  127. package/dist/usage/usage-recorder.d.ts +5 -1
  128. package/dist/usage/usage-recorder.js +1 -1
  129. package/dist/usage.cjs +3 -3
  130. package/dist/usage.js +2 -2
  131. package/package.json +1 -1
@@ -1,30 +1,30 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13;
2
2
 
3
+ var _chunkHQP3K7PUcjs = require('./chunk-HQP3K7PU.cjs');
3
4
 
4
5
 
5
- var _chunkEJLH6NFTcjs = require('./chunk-EJLH6NFT.cjs');
6
6
 
7
+ var _chunkOXHNSZ53cjs = require('./chunk-OXHNSZ53.cjs');
7
8
 
8
- var _chunkHQP3K7PUcjs = require('./chunk-HQP3K7PU.cjs');
9
+
10
+ var _chunkV4TXMEJScjs = require('./chunk-V4TXMEJS.cjs');
9
11
 
10
12
 
11
- var _chunkIIRPUVPHcjs = require('./chunk-IIRPUVPH.cjs');
13
+ var _chunkOVQBNVSVcjs = require('./chunk-OVQBNVSV.cjs');
12
14
 
13
15
 
14
- var _chunkGBHYAGX3cjs = require('./chunk-GBHYAGX3.cjs');
16
+ var _chunkIIRPUVPHcjs = require('./chunk-IIRPUVPH.cjs');
15
17
 
16
18
 
17
- var _chunkV4TXMEJScjs = require('./chunk-V4TXMEJS.cjs');
19
+ var _chunkGBHYAGX3cjs = require('./chunk-GBHYAGX3.cjs');
18
20
 
19
21
 
20
- var _chunk6VUQPOV3cjs = require('./chunk-6VUQPOV3.cjs');
21
22
 
22
23
 
23
24
 
24
- var _chunk4VLRHHFEcjs = require('./chunk-4VLRHHFE.cjs');
25
25
 
26
26
 
27
- var _chunkR3HK6R4Bcjs = require('./chunk-R3HK6R4B.cjs');
27
+ var _chunk3SCOLIPTcjs = require('./chunk-3SCOLIPT.cjs');
28
28
 
29
29
 
30
30
  var _chunkRPII3E6Zcjs = require('./chunk-RPII3E6Z.cjs');
@@ -34,20 +34,34 @@ var _chunkRPII3E6Zcjs = require('./chunk-RPII3E6Z.cjs');
34
34
  var _chunk6RPZADX3cjs = require('./chunk-6RPZADX3.cjs');
35
35
 
36
36
 
37
+
38
+
39
+ var _chunkJ3QQ6JS5cjs = require('./chunk-J3QQ6JS5.cjs');
40
+
41
+
42
+ var _chunkUIBD2YY5cjs = require('./chunk-UIBD2YY5.cjs');
43
+
44
+
45
+ var _chunkR3HK6R4Bcjs = require('./chunk-R3HK6R4B.cjs');
46
+
47
+
48
+ var _chunkQXD4MV2Xcjs = require('./chunk-QXD4MV2X.cjs');
49
+
50
+
37
51
  var _chunkNYUNU75Acjs = require('./chunk-NYUNU75A.cjs');
38
52
 
39
53
 
54
+ var _chunkOTZC4TNHcjs = require('./chunk-OTZC4TNH.cjs');
40
55
 
41
- var _chunkYK57NMIFcjs = require('./chunk-YK57NMIF.cjs');
42
56
 
43
57
 
44
- var _chunkYNJNTCSQcjs = require('./chunk-YNJNTCSQ.cjs');
58
+ var _chunkYWL7YZWScjs = require('./chunk-YWL7YZWS.cjs');
45
59
 
46
60
 
47
- var _chunkSVNDB62Dcjs = require('./chunk-SVNDB62D.cjs');
61
+ var _chunkYNJNTCSQcjs = require('./chunk-YNJNTCSQ.cjs');
48
62
 
49
63
 
50
- var _chunkUIBD2YY5cjs = require('./chunk-UIBD2YY5.cjs');
64
+ var _chunkSVNDB62Dcjs = require('./chunk-SVNDB62D.cjs');
51
65
 
52
66
 
53
67
  var _chunk6QQG7YG3cjs = require('./chunk-6QQG7YG3.cjs');
@@ -64,9 +78,6 @@ var _chunkMUHWHQVMcjs = require('./chunk-MUHWHQVM.cjs');
64
78
  var _chunkQ27JY5RGcjs = require('./chunk-Q27JY5RG.cjs');
65
79
 
66
80
 
67
- var _chunkQXD4MV2Xcjs = require('./chunk-QXD4MV2X.cjs');
68
-
69
-
70
81
  var _chunkAPYG5QD7cjs = require('./chunk-APYG5QD7.cjs');
71
82
 
72
83
 
@@ -90,14 +101,20 @@ var _chunk4VZX5F4Tcjs = require('./chunk-4VZX5F4T.cjs');
90
101
  var _chunkA2YMUCBTcjs = require('./chunk-A2YMUCBT.cjs');
91
102
 
92
103
 
93
- var _chunkUNWKG6EIcjs = require('./chunk-UNWKG6EI.cjs');
104
+ var _chunkXPIOJQS2cjs = require('./chunk-XPIOJQS2.cjs');
105
+
106
+
107
+
108
+ var _chunkGDIXXKF2cjs = require('./chunk-GDIXXKF2.cjs');
109
+
94
110
 
111
+ var _chunkRJUONLUQcjs = require('./chunk-RJUONLUQ.cjs');
95
112
 
96
113
 
97
- var _chunkWYTEQ4Q5cjs = require('./chunk-WYTEQ4Q5.cjs');
114
+ var _chunkHVBBDBS3cjs = require('./chunk-HVBBDBS3.cjs');
98
115
 
99
116
 
100
- var _chunkKCVJWJSTcjs = require('./chunk-KCVJWJST.cjs');
117
+ var _chunkNKVZ6Z3Ycjs = require('./chunk-NKVZ6Z3Y.cjs');
101
118
 
102
119
 
103
120
  var _chunkJMJBSACDcjs = require('./chunk-JMJBSACD.cjs');
@@ -479,6 +496,66 @@ var ProviderProxyRouteMap = (_class = class {
479
496
  }
480
497
  }, _class);
481
498
 
499
+ // src/provider-proxy/identity/claudeCodeHeaders.ts
500
+ var DEFAULT_ANTHROPIC_VERSION = "2023-06-01";
501
+ var OAUTH_BETA = "oauth-2025-04-20";
502
+ var CLAUDE_CODE_BETA = "claude-code-20250219";
503
+ var INTERLEAVED_THINKING_BETA = "interleaved-thinking-2025-05-14";
504
+ var TOOL_STREAMING_BETA = "fine-grained-tool-streaming-2025-05-14";
505
+ var DEFAULT_CLAUDE_CODE_HEADERS = Object.freeze({
506
+ "user-agent": "claude-cli/1.0.119 (external, cli)",
507
+ "x-app": "cli",
508
+ accept: "application/json",
509
+ "accept-language": "*",
510
+ "sec-fetch-mode": "cors",
511
+ "anthropic-dangerous-direct-browser-access": "true",
512
+ "x-stainless-lang": "js",
513
+ "x-stainless-package-version": "0.55.1",
514
+ "x-stainless-os": "Windows",
515
+ "x-stainless-arch": "x64",
516
+ "x-stainless-runtime": "node",
517
+ "x-stainless-runtime-version": "v20.19.2",
518
+ "x-stainless-retry-count": "0",
519
+ "x-stainless-timeout": "60"
520
+ });
521
+ var FORCED_ACCEPT_ENCODING = "identity";
522
+ var CLAUDE_FORWARD_ALLOWLIST = /* @__PURE__ */ new Set([
523
+ "accept",
524
+ "accept-language",
525
+ "sec-fetch-mode",
526
+ "user-agent",
527
+ "x-app",
528
+ "anthropic-dangerous-direct-browser-access",
529
+ "anthropic-version"
530
+ ]);
531
+ var STAINLESS_PREFIX = "x-stainless-";
532
+ function extractClaudeClientHeaders(reqHeaders) {
533
+ const out = {};
534
+ for (const [rawKey, rawVal] of Object.entries(reqHeaders)) {
535
+ const key = rawKey.toLowerCase();
536
+ if (_chunk3SCOLIPTcjs.NEVER_FORWARD_HEADERS.has(key)) continue;
537
+ if (!CLAUDE_FORWARD_ALLOWLIST.has(key) && !key.startsWith(STAINLESS_PREFIX)) continue;
538
+ const value = _chunk3SCOLIPTcjs.flattenHeaderValue.call(void 0, rawVal);
539
+ if (value !== void 0) out[key] = value;
540
+ }
541
+ return out;
542
+ }
543
+ function buildAnthropicBeta(model, callerBeta) {
544
+ const isHaiku = typeof model === "string" && model.toLowerCase().includes("haiku");
545
+ const baseline = isHaiku ? [OAUTH_BETA, INTERLEAVED_THINKING_BETA] : [CLAUDE_CODE_BETA, OAUTH_BETA, INTERLEAVED_THINKING_BETA, TOOL_STREAMING_BETA];
546
+ const seen = /* @__PURE__ */ new Set();
547
+ const out = [];
548
+ const add = (flag) => {
549
+ const trimmed = flag.trim();
550
+ if (!trimmed || seen.has(trimmed)) return;
551
+ seen.add(trimmed);
552
+ out.push(trimmed);
553
+ };
554
+ baseline.forEach(add);
555
+ if (callerBeta) callerBeta.split(",").forEach(add);
556
+ return out.join(",");
557
+ }
558
+
482
559
  // src/provider-proxy/usage/recordAnthropicUsage.ts
483
560
  function readAnthropicUsage(usage) {
484
561
  if (!usage) return null;
@@ -540,12 +617,12 @@ function getSharedExecutor() {
540
617
  }
541
618
  var sharedResponses = null;
542
619
  function getResponsesEndpointTransformer() {
543
- if (!sharedResponses) sharedResponses = new (0, _chunk6VUQPOV3cjs.OpenAIResponseTransformer)();
620
+ if (!sharedResponses) sharedResponses = new (0, _chunkOVQBNVSVcjs.OpenAIResponseTransformer)();
544
621
  return sharedResponses;
545
622
  }
546
623
  var sharedAnthropic = null;
547
624
  function getAnthropicEndpointTransformer() {
548
- if (!sharedAnthropic) sharedAnthropic = new (0, _chunk4VLRHHFEcjs.AnthropicTransformer)();
625
+ if (!sharedAnthropic) sharedAnthropic = new (0, _chunkOXHNSZ53cjs.AnthropicTransformer)();
549
626
  return sharedAnthropic;
550
627
  }
551
628
  var sharedGemini = null;
@@ -653,7 +730,7 @@ async function relaySseBody(res, body, options) {
653
730
  res.end();
654
731
  }
655
732
  }
656
- async function relayResponse(res, providerResponse, isStream, rewriteModel, usageTap) {
733
+ async function relayResponse(res, providerResponse, isStream, rewriteModel, usageTap, onSseEvent) {
657
734
  const contentType = _nullishCoalesce(providerResponse.headers.get("Content-Type"), () => ( ""));
658
735
  const status = providerResponse.status && providerResponse.status >= 100 ? providerResponse.status : 200;
659
736
  const upstreamIsSse = contentType.includes("text/event-stream");
@@ -667,13 +744,16 @@ async function relayResponse(res, providerResponse, isStream, rewriteModel, usag
667
744
  res.end();
668
745
  return null;
669
746
  }
670
- if (rewriteModel || usageTap) {
747
+ if (rewriteModel || usageTap || onSseEvent) {
671
748
  let capturedUsage = null;
672
749
  await relaySseBody(res, providerResponse.body, {
673
750
  rewriteModel,
674
- onSseEvent: usageTap ? (event) => {
675
- const raw = usageTap.extractUsage(event);
676
- if (raw) capturedUsage = raw;
751
+ onSseEvent: onSseEvent || usageTap ? (event) => {
752
+ _optionalChain([onSseEvent, 'optionalCall', _8 => _8(event)]);
753
+ if (usageTap) {
754
+ const raw = usageTap.extractUsage(event);
755
+ if (raw) capturedUsage = raw;
756
+ }
677
757
  } : void 0
678
758
  });
679
759
  if (capturedUsage) usageTap.onUsage(capturedUsage);
@@ -822,7 +902,7 @@ function resolveApiKey(apiKey) {
822
902
  }
823
903
  async function resolvePoolBoundKey(deps, providerId, provider, sessionId, preferredKeyId, boundKeyFallbackPolicy) {
824
904
  if (preferredKeyId) {
825
- const preferred = await _optionalChain([deps, 'access', _8 => _8.apiKeyPool, 'optionalAccess', _9 => _9.getKeyById, 'call', _10 => _10(providerId, preferredKeyId, sessionId)]);
905
+ const preferred = await _optionalChain([deps, 'access', _9 => _9.apiKeyPool, 'optionalAccess', _10 => _10.getKeyById, 'call', _11 => _11(providerId, preferredKeyId, sessionId)]);
826
906
  if (preferred) return preferred;
827
907
  if (boundKeyFallbackPolicy !== "pool") return "";
828
908
  }
@@ -848,7 +928,7 @@ async function buildSubscriptionPlan(res, route, deps, anthropicBody, routeModel
848
928
  resolvedModel = mapped.resolvedModel;
849
929
  scenario = mapped.scenario;
850
930
  }
851
- const sessionKey = _chunkEJLH6NFTcjs.deriveSubscriptionSessionKey.call(void 0, anthropicBody);
931
+ const sessionKey = _chunkJ3QQ6JS5cjs.deriveSubscriptionSessionKey.call(void 0, anthropicBody);
852
932
  const plan = buildSubscriptionIterationPlan(profile, route, deps, resolvedModel, isStream, scenario, sessionKey);
853
933
  if (!plan) {
854
934
  writeError(res, 502, "Subscription profile is missing resolveUpstreamUrl");
@@ -857,11 +937,11 @@ async function buildSubscriptionPlan(res, route, deps, anthropicBody, routeModel
857
937
  return plan;
858
938
  }
859
939
  function buildSubscriptionIterationPlan(profile, route, deps, resolvedModel, isStream, scenario, sessionKey) {
860
- const upstreamUrl = _optionalChain([profile, 'access', _11 => _11.resolveUpstreamUrl, 'optionalCall', _12 => _12(resolvedModel, route.subscriptionConfig)]);
940
+ const upstreamUrl = _optionalChain([profile, 'access', _12 => _12.resolveUpstreamUrl, 'optionalCall', _13 => _13(resolvedModel, route.subscriptionConfig)]);
861
941
  if (!upstreamUrl) return null;
862
942
  const auth = _nullishCoalesce(route.auth, () => ( new (0, _chunkYNJNTCSQcjs.SubscriptionAuthSource)(profile)));
863
943
  const sameFormat = profile.mode === "pass-through" || upstreamUrl.endsWith("/v1/messages");
864
- const overrideNames = _optionalChain([profile, 'access', _13 => _13.resolveProviderTransformerNames, 'optionalCall', _14 => _14(
944
+ const overrideNames = _optionalChain([profile, 'access', _14 => _14.resolveProviderTransformerNames, 'optionalCall', _15 => _15(
865
945
  resolvedModel,
866
946
  route.subscriptionConfig
867
947
  )]);
@@ -926,7 +1006,7 @@ function buildSubscriptionRequestSummary(anthropicBody) {
926
1006
  estimatedInputTokens: Math.ceil(totalChars / 4),
927
1007
  // Single source of truth (shared with the dispatcher builder) so both
928
1008
  // ingress paths yield identical `matchText` for the same body.
929
- matchText: _chunkEJLH6NFTcjs.collectMatchText.call(void 0, anthropicBody)
1009
+ matchText: _chunkJ3QQ6JS5cjs.collectMatchText.call(void 0, anthropicBody)
930
1010
  };
931
1011
  }
932
1012
  function collectText(value) {
@@ -960,7 +1040,7 @@ async function runPipeline(anthropicBody, plan, reportSelection) {
960
1040
  boundAccountFallbackPolicy: plan.boundAccountFallbackPolicy,
961
1041
  reportSelection: (accountId, isActive) => {
962
1042
  proxyAccountId = accountId;
963
- _optionalChain([reportSelection, 'optionalCall', _15 => _15(accountId, isActive)]);
1043
+ _optionalChain([reportSelection, 'optionalCall', _16 => _16(accountId, isActive)]);
964
1044
  }
965
1045
  });
966
1046
  let rawStatus = null;
@@ -982,10 +1062,19 @@ async function runPipeline(anthropicBody, plan, reportSelection) {
982
1062
  },
983
1063
  fetchFn: (url, headers, body) => {
984
1064
  console.info(`[ProviderProxy:anthropic] -> ${url} model=${resolvedModel} stream=${isStream}`);
985
- return _chunkKCVJWJSTcjs.fetchUpstream.call(void 0,
1065
+ return _chunkRJUONLUQcjs.fetchUpstream.call(void 0,
986
1066
  url,
987
1067
  { method: "POST", headers, body: JSON.stringify(body) },
988
- { providerId: proxyProviderId(plan), accountId: proxyAccountId }
1068
+ {
1069
+ providerId: proxyProviderId(plan),
1070
+ accountId: proxyAccountId,
1071
+ routeActivity: plan.isSubscription ? {
1072
+ endpoint: "messages",
1073
+ sessionKey: plan.sessionKey,
1074
+ sessionSource: plan.sessionKey ? "content-fingerprint" : "none",
1075
+ model: resolvedModel
1076
+ } : void 0
1077
+ }
989
1078
  ).then((r) => {
990
1079
  rawStatus = r.status;
991
1080
  return r;
@@ -1009,10 +1098,11 @@ async function runSubscriptionSameFormatFetch(rawBody, plan, reportSelection, op
1009
1098
  reportSelection: (accountId, isActive, remapped) => {
1010
1099
  proxyAccountId = accountId;
1011
1100
  remappedModel = remapped;
1012
- _optionalChain([reportSelection, 'optionalCall', _16 => _16(accountId, isActive, remapped)]);
1101
+ _optionalChain([reportSelection, 'optionalCall', _17 => _17(accountId, isActive, remapped)]);
1013
1102
  }
1014
1103
  });
1015
- if (plan.isSubscription && plan.transformerProvider.name === "claude") {
1104
+ const isClaudeSubscription = plan.isSubscription && plan.transformerProvider.name === "claude";
1105
+ if (isClaudeSubscription) {
1016
1106
  _chunk6RPZADX3cjs.applyFingerprint.call(void 0,
1017
1107
  _chunkRPII3E6Zcjs.getSharedIdentityStore.call(void 0, ),
1018
1108
  headers,
@@ -1021,16 +1111,36 @@ async function runSubscriptionSameFormatFetch(rawBody, plan, reportSelection, op
1021
1111
  options.callerIdentity
1022
1112
  );
1023
1113
  }
1114
+ if (isClaudeSubscription) {
1115
+ _chunk3SCOLIPTcjs.fillMissingHeaders.call(void 0, headers, _nullishCoalesce(options.callerClientHeaders, () => ( {})));
1116
+ _chunk3SCOLIPTcjs.fillMissingHeaders.call(void 0, headers, DEFAULT_CLAUDE_CODE_HEADERS);
1117
+ }
1118
+ _chunk3SCOLIPTcjs.fillMissingHeaders.call(void 0, headers, { "anthropic-version": DEFAULT_ANTHROPIC_VERSION });
1119
+ headers["accept-encoding"] = FORCED_ACCEPT_ENCODING;
1024
1120
  const applyRemap = remappedModel !== void 0 && outboundRemapApplies(plan);
1025
1121
  const outboundBody = applyRemap ? rewriteBodyModel(rawBody, remappedModel) : rawBody;
1026
1122
  const outboundModel = applyRemap ? remappedModel : plan.resolvedModel;
1123
+ if (isClaudeSubscription) {
1124
+ headers["anthropic-beta"] = buildAnthropicBeta(outboundModel, options.callerAnthropicBeta);
1125
+ } else if (options.callerAnthropicBeta) {
1126
+ _chunk3SCOLIPTcjs.fillMissingHeaders.call(void 0, headers, { "anthropic-beta": options.callerAnthropicBeta });
1127
+ }
1027
1128
  console.info(
1028
1129
  `[ProviderProxy:anthropic] (subscription same-format) -> ${plan.upstreamUrl} model=${outboundModel} stream=${plan.isStream}`
1029
1130
  );
1030
- const response = await _chunkKCVJWJSTcjs.fetchUpstream.call(void 0,
1131
+ const response = await _chunkRJUONLUQcjs.fetchUpstream.call(void 0,
1031
1132
  plan.upstreamUrl,
1032
1133
  { method: "POST", headers, body: outboundBody },
1033
- { providerId: proxyProviderId(plan), accountId: proxyAccountId }
1134
+ {
1135
+ providerId: proxyProviderId(plan),
1136
+ accountId: proxyAccountId,
1137
+ routeActivity: plan.isSubscription ? {
1138
+ endpoint: "messages",
1139
+ sessionKey: plan.sessionKey,
1140
+ sessionSource: plan.sessionKey ? "content-fingerprint" : "none",
1141
+ model: outboundModel
1142
+ } : void 0
1143
+ }
1034
1144
  );
1035
1145
  return { response, rawStatus: response.status };
1036
1146
  }
@@ -1056,7 +1166,7 @@ async function runSubscriptionAttemptWith401Retry(anthropicBody, relayBody, plan
1056
1166
  const first = await runOnce();
1057
1167
  let result = first;
1058
1168
  if (first.rawStatus === 401) {
1059
- const refreshed = await _optionalChain([plan, 'access', _17 => _17.auth, 'access', _18 => _18.onUnauthorized, 'optionalCall', _19 => _19(plan.sessionKey)]);
1169
+ const refreshed = await _optionalChain([plan, 'access', _18 => _18.auth, 'access', _19 => _19.onUnauthorized, 'optionalCall', _20 => _20(plan.sessionKey)]);
1060
1170
  if (refreshed) {
1061
1171
  console.info("[ProviderProxy:anthropic] 401 \u2192 token refreshed; retrying once");
1062
1172
  result = await runOnce();
@@ -1079,9 +1189,9 @@ async function markSubscriptionHealth(plan, selectedAccountId, result) {
1079
1189
  if (!plan.isSubscription || selectedAccountId === void 0) return;
1080
1190
  const providerId = plan.transformerProvider.name;
1081
1191
  const status = result.rawStatus;
1082
- const { resetHeaderSeconds, retryAfterSeconds } = _chunkYK57NMIFcjs.resolveResetSeconds.call(void 0, providerId, result.response.headers);
1192
+ const { resetHeaderSeconds, retryAfterSeconds } = _chunkYWL7YZWScjs.resolveResetSeconds.call(void 0, providerId, result.response.headers);
1083
1193
  const bodyText = status === 403 ? await readBoundedBody(result.response) : void 0;
1084
- _chunkYK57NMIFcjs.getSharedAccountHealth.call(void 0, ).recordUpstreamOutcome(providerId, selectedAccountId, {
1194
+ _chunkYWL7YZWScjs.getSharedAccountHealth.call(void 0, ).recordUpstreamOutcome(providerId, selectedAccountId, {
1085
1195
  status,
1086
1196
  resetHeaderSeconds,
1087
1197
  retryAfterSeconds,
@@ -1099,7 +1209,7 @@ function breakerOutcome(rawStatus) {
1099
1209
  function recordBreakerOutcome(profile, modelId, rawStatus) {
1100
1210
  const outcome = breakerOutcome(rawStatus);
1101
1211
  if (outcome === "neutral") return;
1102
- _optionalChain([profile, 'optionalAccess', _20 => _20.recordModelOutcome, 'optionalCall', _21 => _21(modelId, outcome === "success")]);
1212
+ _optionalChain([profile, 'optionalAccess', _21 => _21.recordModelOutcome, 'optionalCall', _22 => _22(modelId, outcome === "success")]);
1103
1213
  }
1104
1214
  async function runSubscriptionAttemptOutcome(anthropicBody, relayBody, plan, options = {}) {
1105
1215
  try {
@@ -1118,7 +1228,7 @@ function settleOutcome(outcome) {
1118
1228
  async function runPipelineWithSubscriptionRetry(anthropicBody, rawBody, initialPlan, route, deps, options = {}) {
1119
1229
  const profile = route.subscriptionProfile;
1120
1230
  const scenario = initialPlan.scenario;
1121
- if (!_optionalChain([profile, 'optionalAccess', _22 => _22.nextFallback]) || scenario === void 0) {
1231
+ if (!_optionalChain([profile, 'optionalAccess', _23 => _23.nextFallback]) || scenario === void 0) {
1122
1232
  const loneOutcome = await runSubscriptionAttemptOutcome(anthropicBody, rawBody, initialPlan, options);
1123
1233
  recordBreakerOutcome(profile, initialPlan.resolvedModel, outcomeStatus(loneOutcome));
1124
1234
  return settleOutcome(loneOutcome);
@@ -1212,7 +1322,7 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
1212
1322
  extractUsage(event) {
1213
1323
  if (event["type"] === "message_start") {
1214
1324
  const msg = event["message"];
1215
- const u = _optionalChain([msg, 'optionalAccess', _23 => _23["usage"]]);
1325
+ const u = _optionalChain([msg, 'optionalAccess', _24 => _24["usage"]]);
1216
1326
  if (u) anthropicInputUsage = u;
1217
1327
  return null;
1218
1328
  }
@@ -1302,7 +1412,7 @@ async function buildByoPlan(res, route, deps, resolvedModel, isStream) {
1302
1412
  isSubscription: false,
1303
1413
  provider,
1304
1414
  apiKey,
1305
- extendedContextEnabled: _nullishCoalesce(_optionalChain([route, 'access', _24 => _24.anthropicSdkHints, 'optionalAccess', _25 => _25.extendedContext, 'optionalAccess', _26 => _26.enabled]), () => ( false))
1415
+ extendedContextEnabled: _nullishCoalesce(_optionalChain([route, 'access', _25 => _25.anthropicSdkHints, 'optionalAccess', _26 => _26.extendedContext, 'optionalAccess', _27 => _27.enabled]), () => ( false))
1306
1416
  };
1307
1417
  }
1308
1418
  async function runSameFormatFetch(bodyToSend, plan, options, keyOverride) {
@@ -1312,7 +1422,7 @@ async function runSameFormatFetch(bodyToSend, plan, options, keyOverride) {
1312
1422
  }
1313
1423
  const effectiveKey = _nullishCoalesce(_nullishCoalesce(keyOverride, () => ( apiKey)), () => ( ""));
1314
1424
  const headers = _chunkQ27JY5RGcjs.getProviderHeaders.call(void 0, provider, effectiveKey);
1315
- const callerBeta = _optionalChain([options, 'access', _27 => _27.callerAnthropicBeta, 'optionalAccess', _28 => _28.trim, 'call', _29 => _29()]);
1425
+ const callerBeta = _optionalChain([options, 'access', _28 => _28.callerAnthropicBeta, 'optionalAccess', _29 => _29.trim, 'call', _30 => _30()]);
1316
1426
  if (callerBeta) {
1317
1427
  const existing = _nullishCoalesce(headers["anthropic-beta"], () => ( headers["Anthropic-Beta"]));
1318
1428
  const parts = new Set(
@@ -1326,7 +1436,7 @@ async function runSameFormatFetch(bodyToSend, plan, options, keyOverride) {
1326
1436
  _chunkGBHYAGX3cjs.injectExtendedContextBeta.call(void 0, headers, resolvedModel, _nullishCoalesce(extendedContextEnabled, () => ( false)));
1327
1437
  const url = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: resolvedModel, stream: isStream });
1328
1438
  console.info(`[ProviderProxy:anthropic] (same-format) -> ${url} model=${resolvedModel} stream=${isStream}`);
1329
- const response = await _chunkKCVJWJSTcjs.fetchUpstream.call(void 0,
1439
+ const response = await _chunkRJUONLUQcjs.fetchUpstream.call(void 0,
1330
1440
  url,
1331
1441
  { method: "POST", headers, body: bodyToSend },
1332
1442
  { providerId: "byo" }
@@ -1347,8 +1457,8 @@ async function runPipelineWithPoolReporting(anthropicBody, rawBody, plan, option
1347
1457
  const sameFormatBody = plan.sameFormat ? resolveSameFormatBody(anthropicBody, rawBody, plan) : rawBody;
1348
1458
  const runOnce = (keyOverride) => plan.sameFormat ? runSameFormatFetch(sameFormatBody, plan, options, keyOverride) : runPipeline(anthropicBody, plan);
1349
1459
  const first = await runOnce();
1350
- const outcome = await _optionalChain([plan, 'access', _30 => _30.auth, 'access', _31 => _31.onResult, 'optionalCall', _32 => _32(first.rawStatus)]);
1351
- if (_optionalChain([outcome, 'optionalAccess', _33 => _33.rebound])) {
1460
+ const outcome = await _optionalChain([plan, 'access', _31 => _31.auth, 'access', _32 => _32.onResult, 'optionalCall', _33 => _33(first.rawStatus)]);
1461
+ if (_optionalChain([outcome, 'optionalAccess', _34 => _34.rebound])) {
1352
1462
  console.info(
1353
1463
  "[ProviderProxy:anthropic] pool re-bound key after status",
1354
1464
  first.rawStatus,
@@ -1370,7 +1480,12 @@ async function handleAnthropicMessagesRequest(req, res, route, deps) {
1370
1480
  const callerBetaRaw = req.headers["anthropic-beta"];
1371
1481
  const callerAnthropicBeta = Array.isArray(callerBetaRaw) ? callerBetaRaw.join(",") : callerBetaRaw;
1372
1482
  const callerIdentity = _chunk6RPZADX3cjs.captureCallerIdentity.call(void 0, _chunkRPII3E6Zcjs.getSharedIdentityStore.call(void 0, ), req.headers);
1373
- await handleAnthropicMessagesByo(res, rawBody, route, deps, { callerAnthropicBeta, callerIdentity });
1483
+ const callerClientHeaders = extractClaudeClientHeaders(req.headers);
1484
+ await handleAnthropicMessagesByo(res, rawBody, route, deps, {
1485
+ callerAnthropicBeta,
1486
+ callerIdentity,
1487
+ callerClientHeaders
1488
+ });
1374
1489
  return;
1375
1490
  }
1376
1491
  const hints = route.anthropicSdkHints;
@@ -1485,14 +1600,14 @@ var GENERATE_CONTENT_ACTION = ":generateContent";
1485
1600
  var STREAM_GENERATE_CONTENT_ACTION = ":streamGenerateContent";
1486
1601
  function isGeminiGenerateContentRequest(method, url) {
1487
1602
  if (method !== "POST" || !url) return false;
1488
- const path = _nullishCoalesce(_optionalChain([url, 'access', _34 => _34.split, 'call', _35 => _35("?"), 'access', _36 => _36[0], 'optionalAccess', _37 => _37.replace, 'call', _38 => _38(/\/+$/, "")]), () => ( ""));
1603
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _35 => _35.split, 'call', _36 => _36("?"), 'access', _37 => _37[0], 'optionalAccess', _38 => _38.replace, 'call', _39 => _39(/\/+$/, "")]), () => ( ""));
1489
1604
  const lastSegment = _nullishCoalesce(path.split("/").pop(), () => ( ""));
1490
1605
  return lastSegment.includes(STREAM_GENERATE_CONTENT_ACTION) || lastSegment.includes(GENERATE_CONTENT_ACTION);
1491
1606
  }
1492
1607
  function isGeminiStreamRequest(url) {
1493
1608
  if (!url) return false;
1494
1609
  const [path, query = ""] = url.split("?");
1495
- const lastSegment = _nullishCoalesce((_nullishCoalesce(_optionalChain([path, 'optionalAccess', _39 => _39.replace, 'call', _40 => _40(/\/+$/, "")]), () => ( ""))).split("/").pop(), () => ( ""));
1610
+ const lastSegment = _nullishCoalesce((_nullishCoalesce(_optionalChain([path, 'optionalAccess', _40 => _40.replace, 'call', _41 => _41(/\/+$/, "")]), () => ( ""))).split("/").pop(), () => ( ""));
1496
1611
  if (lastSegment.includes(STREAM_GENERATE_CONTENT_ACTION)) return true;
1497
1612
  return /(^|&)alt=sse(&|$)/.test(query);
1498
1613
  }
@@ -1622,7 +1737,7 @@ async function runPipeline2(geminiBody, plan) {
1622
1737
  },
1623
1738
  fetchFn: (url, headers, body) => {
1624
1739
  console.log(`[ProviderProxy:gemini] -> ${url} model=${resolvedModel} stream=${isStream}`);
1625
- return _chunkKCVJWJSTcjs.fetchUpstream.call(void 0,
1740
+ return _chunkRJUONLUQcjs.fetchUpstream.call(void 0,
1626
1741
  url,
1627
1742
  { method: "POST", headers, body: JSON.stringify(body) },
1628
1743
  { providerId: "byo" }
@@ -1637,8 +1752,8 @@ async function runPipeline2(geminiBody, plan) {
1637
1752
  }
1638
1753
  async function runPipelineWithPoolReporting2(geminiBody, plan) {
1639
1754
  const first = await runPipeline2(geminiBody, plan);
1640
- const outcome = await _optionalChain([plan, 'access', _41 => _41.auth, 'access', _42 => _42.onResult, 'optionalCall', _43 => _43(first.rawStatus)]);
1641
- if (_optionalChain([outcome, 'optionalAccess', _44 => _44.rebound])) {
1755
+ const outcome = await _optionalChain([plan, 'access', _42 => _42.auth, 'access', _43 => _43.onResult, 'optionalCall', _44 => _44(first.rawStatus)]);
1756
+ if (_optionalChain([outcome, 'optionalAccess', _45 => _45.rebound])) {
1642
1757
  console.log(
1643
1758
  "[ProviderProxy:gemini] pool re-bound key after status",
1644
1759
  first.rawStatus,
@@ -1704,7 +1819,7 @@ function recordChatCompletionsStreamUsage(recorder, rawUsage, attribution) {
1704
1819
  // src/provider-proxy/ingress/openaiChatIngress.ts
1705
1820
  function isOpenAIChatRequest(method, url) {
1706
1821
  if (method !== "POST" || !url) return false;
1707
- const path = _nullishCoalesce(_optionalChain([url, 'access', _45 => _45.split, 'call', _46 => _46("?"), 'access', _47 => _47[0], 'optionalAccess', _48 => _48.replace, 'call', _49 => _49(/\/+$/, "")]), () => ( ""));
1822
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _46 => _46.split, 'call', _47 => _47("?"), 'access', _48 => _48[0], 'optionalAccess', _49 => _49.replace, 'call', _50 => _50(/\/+$/, "")]), () => ( ""));
1708
1823
  return path.endsWith("/chat/completions");
1709
1824
  }
1710
1825
  var CHAT_BRIDGE_SUBSCRIPTION_PROVIDERS = /* @__PURE__ */ new Set(["claude"]);
@@ -1826,7 +1941,7 @@ async function buildSubscriptionPlan2(res, route, deps, resolvedModel, isStream)
1826
1941
  );
1827
1942
  return null;
1828
1943
  }
1829
- const upstreamUrl = _optionalChain([profile, 'access', _50 => _50.resolveUpstreamUrl, 'optionalCall', _51 => _51(resolvedModel)]);
1944
+ const upstreamUrl = _optionalChain([profile, 'access', _51 => _51.resolveUpstreamUrl, 'optionalCall', _52 => _52(resolvedModel)]);
1830
1945
  if (!upstreamUrl) {
1831
1946
  writeError(res, 502, "Subscription profile is missing resolveUpstreamUrl");
1832
1947
  return null;
@@ -1891,7 +2006,7 @@ async function runPipeline3(chatBody, plan) {
1891
2006
  },
1892
2007
  fetchFn: (url, headers, body) => {
1893
2008
  console.log(`[ProviderProxy:chat] -> ${url} model=${resolvedModel} stream=${isStream}`);
1894
- return _chunkKCVJWJSTcjs.fetchUpstream.call(void 0,
2009
+ return _chunkRJUONLUQcjs.fetchUpstream.call(void 0,
1895
2010
  url,
1896
2011
  { method: "POST", headers, body: JSON.stringify(body) },
1897
2012
  { providerId: plan.proxyProviderId, accountId: proxyAccountId }
@@ -1906,8 +2021,8 @@ async function runPipeline3(chatBody, plan) {
1906
2021
  }
1907
2022
  async function runPipelineWithPoolReporting3(chatBody, plan) {
1908
2023
  const first = await runPipeline3(chatBody, plan);
1909
- const outcome = await _optionalChain([plan, 'access', _52 => _52.auth, 'access', _53 => _53.onResult, 'optionalCall', _54 => _54(first.rawStatus)]);
1910
- if (_optionalChain([outcome, 'optionalAccess', _55 => _55.rebound])) {
2024
+ const outcome = await _optionalChain([plan, 'access', _53 => _53.auth, 'access', _54 => _54.onResult, 'optionalCall', _55 => _55(first.rawStatus)]);
2025
+ if (_optionalChain([outcome, 'optionalAccess', _56 => _56.rebound])) {
1911
2026
  console.log(
1912
2027
  "[ProviderProxy:chat] pool re-bound key after status",
1913
2028
  first.rawStatus,
@@ -1920,7 +2035,7 @@ async function runPipelineWithPoolReporting3(chatBody, plan) {
1920
2035
  async function runPipelineWithSubscriptionRetry2(chatBody, plan) {
1921
2036
  const first = await runPipeline3(chatBody, plan);
1922
2037
  if (first.rawStatus !== 401) return first;
1923
- const refreshed = await _optionalChain([plan, 'access', _56 => _56.auth, 'access', _57 => _57.onUnauthorized, 'optionalCall', _58 => _58()]);
2038
+ const refreshed = await _optionalChain([plan, 'access', _57 => _57.auth, 'access', _58 => _58.onUnauthorized, 'optionalCall', _59 => _59()]);
1924
2039
  if (!refreshed) {
1925
2040
  console.warn("[ProviderProxy:chat] 401 not recoverable (onUnauthorized returned false)");
1926
2041
  return first;
@@ -1957,6 +2072,8 @@ function emitResponsesUsageRecord(recorder, rawUsage, attribution) {
1957
2072
  providerId: attribution.providerId,
1958
2073
  model: attribution.model,
1959
2074
  apiKeyId: attribution.apiKeyId,
2075
+ cacheKeySource: attribution.cacheKeySource,
2076
+ cacheKeyInjected: attribution.cacheKeyInjected,
1960
2077
  auditResponse: attribution.auditResponse,
1961
2078
  engineOrigin: "codex-ingress",
1962
2079
  usage: tapped,
@@ -1981,12 +2098,72 @@ function recordResponsesStreamUsage(recorder, rawUsage, attribution) {
1981
2098
  }
1982
2099
  }
1983
2100
 
2101
+ // src/provider-proxy/ingress/codexUsageLimitDetection.ts
2102
+ var PROVIDER_ID = "codex";
2103
+ var DEFAULT_QUOTA_COOLDOWN_MS = 5 * 6e4;
2104
+ var QUOTA_EXHAUSTED_PERCENT = 90;
2105
+ function parseTryAgainDeadline(bodyText) {
2106
+ const match = bodyText.match(/try again (?:at|on)\s+(.+?)(?:[.\n]|$)/i);
2107
+ if (!match) return void 0;
2108
+ const cleaned = match[1].replace(/(\d+)(st|nd|rd|th)/giu, "$1").trim();
2109
+ const ms = Date.parse(cleaned);
2110
+ return Number.isFinite(ms) ? ms : void 0;
2111
+ }
2112
+ function deadlineFromAllowanceSnapshot(accountId, now) {
2113
+ const snapshot = _chunkHVBBDBS3cjs.getSharedAccountAllowanceStore.call(void 0, ).get(PROVIDER_ID, accountId, now);
2114
+ if (!snapshot) return void 0;
2115
+ const candidates = snapshot.windows.filter(
2116
+ (w) => typeof w.usedPercent === "number" && w.usedPercent >= QUOTA_EXHAUSTED_PERCENT && typeof w.resetsAt === "string"
2117
+ ).map((w) => ({ ms: Date.parse(w.resetsAt), usedPercent: w.usedPercent })).filter((x) => Number.isFinite(x.ms) && x.ms > now).sort((a, b) => b.usedPercent - a.usedPercent);
2118
+ return _optionalChain([candidates, 'access', _60 => _60[0], 'optionalAccess', _61 => _61.ms]);
2119
+ }
2120
+ function resolveCodexQuotaDeadline(accountId, bodyText, now = Date.now()) {
2121
+ const parsed = parseTryAgainDeadline(bodyText);
2122
+ const parsedDeadline = parsed !== void 0 && parsed > now ? parsed : void 0;
2123
+ return _nullishCoalesce(_nullishCoalesce(deadlineFromAllowanceSnapshot(accountId, now), () => ( parsedDeadline)), () => ( now + DEFAULT_QUOTA_COOLDOWN_MS));
2124
+ }
2125
+ function markCodexUsageLimitExhaustion(accountId, bodyText, now = Date.now()) {
2126
+ if (!accountId) return;
2127
+ const deadline = resolveCodexQuotaDeadline(accountId, bodyText, now);
2128
+ _chunkYWL7YZWScjs.getSharedAccountHealth.call(void 0, ).markQuotaExhausted(PROVIDER_ID, accountId, deadline, now);
2129
+ }
2130
+
1984
2131
  // src/provider-proxy/ingress/openaiResponsesIngress.ts
2132
+ var SERVER_OVERLOADED_CODES = /* @__PURE__ */ new Set(["server_is_overloaded", "slow_down"]);
2133
+ function isCodexServerOverloadEvent(event) {
2134
+ if (event["type"] !== "response.failed") return false;
2135
+ const error = _optionalChain([event, 'access', _62 => _62["response"], 'optionalAccess', _63 => _63["error"]]);
2136
+ const code = _optionalChain([error, 'optionalAccess', _64 => _64["code"]]);
2137
+ return typeof code === "string" && SERVER_OVERLOADED_CODES.has(code);
2138
+ }
1985
2139
  function isOpenAIResponsesRequest(method, url) {
1986
2140
  if (method !== "POST" || !url) return false;
1987
- const path = _nullishCoalesce(_optionalChain([url, 'access', _59 => _59.split, 'call', _60 => _60("?"), 'access', _61 => _61[0], 'optionalAccess', _62 => _62.replace, 'call', _63 => _63(/\/+$/, "")]), () => ( ""));
2141
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _65 => _65.split, 'call', _66 => _66("?"), 'access', _67 => _67[0], 'optionalAccess', _68 => _68.replace, 'call', _69 => _69(/\/+$/, "")]), () => ( ""));
1988
2142
  return path.endsWith("/responses");
1989
2143
  }
2144
+ var SAFE_INJECTED_CACHE_KEY_SOURCES = /* @__PURE__ */ new Set([
2145
+ "session-header",
2146
+ "thread-header",
2147
+ "body-session-id",
2148
+ "body-thread-id",
2149
+ "content-fingerprint"
2150
+ ]);
2151
+ function isSafeInjectedCacheKeySource(source) {
2152
+ return SAFE_INJECTED_CACHE_KEY_SOURCES.has(source);
2153
+ }
2154
+ function ensureCodexPromptCacheKey(body, proxyProviderId2, derivedSession) {
2155
+ if (typeof body.prompt_cache_key === "string" && body.prompt_cache_key.trim()) {
2156
+ return { cacheKeySource: "client", cacheKeyInjected: false };
2157
+ }
2158
+ if (proxyProviderId2 !== "codex" || !isSafeInjectedCacheKeySource(derivedSession.source)) {
2159
+ return { cacheKeySource: "none", cacheKeyInjected: false };
2160
+ }
2161
+ body.prompt_cache_key = `omnicross:${derivedSession.source}:${derivedSession.key}`;
2162
+ return {
2163
+ cacheKeySource: derivedSession.source,
2164
+ cacheKeyInjected: true
2165
+ };
2166
+ }
1990
2167
  async function handleOpenAIResponsesRequest(res, rawBody, route, deps, requestHeaders = {}) {
1991
2168
  let responsesBody;
1992
2169
  try {
@@ -1996,7 +2173,7 @@ async function handleOpenAIResponsesRequest(res, rawBody, route, deps, requestHe
1996
2173
  return;
1997
2174
  }
1998
2175
  const isStream = responsesBody.stream === true;
1999
- const derivedSession = _chunkEJLH6NFTcjs.deriveGatewaySessionKey.call(void 0, responsesBody, requestHeaders, {
2176
+ const derivedSession = _chunkJ3QQ6JS5cjs.deriveGatewaySessionKey.call(void 0, responsesBody, requestHeaders, {
2000
2177
  endpoint: "responses",
2001
2178
  // A verified outbound key is the strongest route-local fallback. Resident
2002
2179
  // proxy callers without one still get a stable run/session bucket; the
@@ -2007,14 +2184,31 @@ async function handleOpenAIResponsesRequest(res, rawBody, route, deps, requestHe
2007
2184
  const resolvedModel = route.model;
2008
2185
  responsesBody.model = resolvedModel;
2009
2186
  try {
2010
- const plan = route.authMode === "subscription" ? await buildSubscriptionPlan3(res, route, deps, resolvedModel, isStream, sessionKey) : await buildByoPlan4(res, route, deps, resolvedModel, isStream);
2187
+ const plan = route.authMode === "subscription" ? await buildSubscriptionPlan3(
2188
+ res,
2189
+ route,
2190
+ deps,
2191
+ resolvedModel,
2192
+ isStream,
2193
+ sessionKey,
2194
+ derivedSession.source,
2195
+ requestHeaders
2196
+ ) : await buildByoPlan4(res, route, deps, resolvedModel, isStream);
2011
2197
  if (!plan) return;
2012
- const providerResponse = route.authMode === "subscription" ? await runPipelineWithSubscriptionRetry3(responsesBody, plan) : await runPipelineWithPoolReporting4(responsesBody, plan);
2198
+ const cacheKeyAttribution = ensureCodexPromptCacheKey(
2199
+ responsesBody,
2200
+ plan.proxyProviderId,
2201
+ derivedSession
2202
+ );
2203
+ let providerResponse = route.authMode === "subscription" ? await runPipelineWithSubscriptionRetry3(responsesBody, plan) : await runPipelineWithPoolReporting4(responsesBody, plan);
2204
+ providerResponse = await retryAroundCodexUsageLimit(responsesBody, plan, providerResponse);
2013
2205
  const usageAttribution = {
2014
2206
  sessionId: route.sessionId,
2015
2207
  providerId: _nullishCoalesce(route.providerId, () => ( "codex")),
2016
2208
  model: resolvedModel,
2017
2209
  apiKeyId: _nullishCoalesce(route.apiKeyId, () => ( null)),
2210
+ cacheKeySource: cacheKeyAttribution.cacheKeySource,
2211
+ cacheKeyInjected: cacheKeyAttribution.cacheKeyInjected,
2018
2212
  // request-audit-log: correlate this request's tokens/cost to its audit record.
2019
2213
  auditResponse: res
2020
2214
  };
@@ -2023,19 +2217,40 @@ async function handleOpenAIResponsesRequest(res, rawBody, route, deps, requestHe
2023
2217
  extractUsage(event) {
2024
2218
  if (event["type"] !== "response.completed") return null;
2025
2219
  const response = event["response"];
2026
- const usage = _optionalChain([response, 'optionalAccess', _64 => _64["usage"]]);
2220
+ const usage = _optionalChain([response, 'optionalAccess', _70 => _70["usage"]]);
2027
2221
  return _nullishCoalesce(usage, () => ( null));
2028
2222
  },
2029
2223
  onUsage(rawUsage) {
2030
2224
  recordResponsesStreamUsage(usageRecorder, rawUsage, usageAttribution);
2031
2225
  }
2032
2226
  } : void 0;
2227
+ const overloadActivityId = providerResponse.activityRecordId;
2228
+ const overloadAccountId = providerResponse.accountId;
2229
+ const overloadProviderId = plan.proxyProviderId;
2230
+ let overloadRecorded = false;
2231
+ const overloadDetector = (event) => {
2232
+ if (overloadRecorded || !isCodexServerOverloadEvent(event)) return;
2233
+ overloadRecorded = true;
2234
+ if (overloadActivityId) {
2235
+ _chunkNKVZ6Z3Ycjs.getSharedAccountRouteActivity.call(void 0, ).amend(overloadActivityId, {
2236
+ streamError: "server_overloaded"
2237
+ });
2238
+ }
2239
+ if (overloadAccountId) {
2240
+ _chunkOTZC4TNHcjs.getSharedOverloadCounter.call(void 0, ).recordOverload({
2241
+ providerId: overloadProviderId,
2242
+ accountId: overloadAccountId,
2243
+ endpoint: "responses"
2244
+ });
2245
+ }
2246
+ };
2033
2247
  const bodyText = await relayResponse(
2034
2248
  res,
2035
2249
  providerResponse.response,
2036
2250
  isStream,
2037
2251
  route.requestedModel,
2038
- usageTap
2252
+ usageTap,
2253
+ overloadDetector
2039
2254
  );
2040
2255
  if (bodyText && deps.usageRecorder) {
2041
2256
  recordResponsesNonStreamUsage(deps.usageRecorder, bodyText, usageAttribution);
@@ -2099,13 +2314,13 @@ async function buildByoPlan4(res, route, deps, resolvedModel, isStream) {
2099
2314
  proxyProviderId: "byo"
2100
2315
  };
2101
2316
  }
2102
- async function buildSubscriptionPlan3(res, route, deps, resolvedModel, isStream, sessionKey) {
2317
+ async function buildSubscriptionPlan3(res, route, deps, resolvedModel, isStream, sessionKey, sessionSource, requestHeaders) {
2103
2318
  const profile = route.subscriptionProfile;
2104
2319
  if (!profile) {
2105
2320
  writeError(res, 502, "Subscription mode requires a codex subscription profile");
2106
2321
  return null;
2107
2322
  }
2108
- const upstreamUrl = _optionalChain([profile, 'access', _65 => _65.resolveUpstreamUrl, 'optionalCall', _66 => _66(resolvedModel)]);
2323
+ const upstreamUrl = _optionalChain([profile, 'access', _71 => _71.resolveUpstreamUrl, 'optionalCall', _72 => _72(resolvedModel)]);
2109
2324
  if (!upstreamUrl) {
2110
2325
  writeError(res, 502, "Subscription profile is missing resolveUpstreamUrl");
2111
2326
  return null;
@@ -2142,6 +2357,7 @@ async function buildSubscriptionPlan3(res, route, deps, resolvedModel, isStream,
2142
2357
  return {
2143
2358
  auth,
2144
2359
  sessionKey,
2360
+ sessionSource,
2145
2361
  preferredAccountId: route.preferredAccountId,
2146
2362
  preferredAccountGroup: route.preferredAccountGroup,
2147
2363
  boundAccountFallbackPolicy: route.boundAccountFallbackPolicy,
@@ -2154,7 +2370,10 @@ async function buildSubscriptionPlan3(res, route, deps, resolvedModel, isStream,
2154
2370
  // profile's `resolveUpstreamUrl` for non-Code-Assist subscriptions.
2155
2371
  resolveUrl: (config) => config.url instanceof URL ? config.url.toString() : typeof config.url === "string" ? config.url : upstreamUrl,
2156
2372
  upstreamUrl,
2157
- proxyProviderId: profile.authStrategy.providerId
2373
+ proxyProviderId: profile.authStrategy.providerId,
2374
+ // Only the codex backend understands these; other subscription providers
2375
+ // (gemini Code Assist) share this relay and must not receive them.
2376
+ callerClientHeaders: profile.authStrategy.providerId === "codex" ? _chunk3SCOLIPTcjs.extractCodexClientHeaders.call(void 0, requestHeaders) : void 0
2158
2377
  };
2159
2378
  }
2160
2379
  async function resolveGeminiCodeAssistProject(profile, hints) {
@@ -2172,6 +2391,7 @@ async function runPipeline4(responsesBody, plan) {
2172
2391
  const endpointTransformer = getResponsesEndpointTransformer();
2173
2392
  const { auth, sessionKey, chain, transformerProvider, resolvedModel, isStream, resolveUrl, upstreamUrl } = plan;
2174
2393
  let proxyAccountId;
2394
+ let activityRecordId;
2175
2395
  const authHeaders = {};
2176
2396
  await auth.applyHeaders(authHeaders, {
2177
2397
  upstreamUrl,
@@ -2199,14 +2419,31 @@ async function runPipeline4(responsesBody, plan) {
2199
2419
  if (value !== void 0 && !(key in headers)) headers[key] = value;
2200
2420
  }
2201
2421
  }
2422
+ if (plan.proxyProviderId === "codex") {
2423
+ _chunk3SCOLIPTcjs.fillMissingHeaders.call(void 0, headers, _nullishCoalesce(plan.callerClientHeaders, () => ( {})));
2424
+ _chunk3SCOLIPTcjs.fillMissingHeaders.call(void 0, headers, _chunk3SCOLIPTcjs.DEFAULT_CODEX_CLI_HEADERS);
2425
+ _chunk3SCOLIPTcjs.fillMissingHeaders.call(void 0, headers, { accept: _chunk3SCOLIPTcjs.codexAcceptHeader.call(void 0, isStream) });
2426
+ }
2202
2427
  return headers;
2203
2428
  },
2204
2429
  fetchFn: (url, headers, body) => {
2205
2430
  console.log(`[ProviderProxy:responses] -> ${url} model=${resolvedModel} stream=${isStream}`);
2206
- return _chunkKCVJWJSTcjs.fetchUpstream.call(void 0,
2431
+ return _chunkRJUONLUQcjs.fetchUpstream.call(void 0,
2207
2432
  url,
2208
2433
  { method: "POST", headers, body: JSON.stringify(body) },
2209
- { providerId: plan.proxyProviderId, accountId: proxyAccountId }
2434
+ {
2435
+ providerId: plan.proxyProviderId,
2436
+ accountId: proxyAccountId,
2437
+ routeActivity: plan.proxyProviderId === "byo" ? void 0 : {
2438
+ endpoint: "responses",
2439
+ sessionKey,
2440
+ sessionSource: _nullishCoalesce(plan.sessionSource, () => ( "none")),
2441
+ model: resolvedModel,
2442
+ onRecorded: (record) => {
2443
+ activityRecordId = record.id;
2444
+ }
2445
+ }
2446
+ }
2210
2447
  ).then((r) => {
2211
2448
  rawStatus = r.status;
2212
2449
  return r;
@@ -2214,12 +2451,12 @@ async function runPipeline4(responsesBody, plan) {
2214
2451
  },
2215
2452
  runResponseChain: true
2216
2453
  });
2217
- return { response, rawStatus };
2454
+ return { response, rawStatus, accountId: proxyAccountId, activityRecordId };
2218
2455
  }
2219
2456
  async function runPipelineWithPoolReporting4(responsesBody, plan) {
2220
2457
  const first = await runPipeline4(responsesBody, plan);
2221
- const outcome = await _optionalChain([plan, 'access', _67 => _67.auth, 'access', _68 => _68.onResult, 'optionalCall', _69 => _69(first.rawStatus)]);
2222
- if (_optionalChain([outcome, 'optionalAccess', _70 => _70.rebound])) {
2458
+ const outcome = await _optionalChain([plan, 'access', _73 => _73.auth, 'access', _74 => _74.onResult, 'optionalCall', _75 => _75(first.rawStatus)]);
2459
+ if (_optionalChain([outcome, 'optionalAccess', _76 => _76.rebound])) {
2223
2460
  console.log(
2224
2461
  "[ProviderProxy:responses] pool re-bound key after status",
2225
2462
  first.rawStatus,
@@ -2232,7 +2469,7 @@ async function runPipelineWithPoolReporting4(responsesBody, plan) {
2232
2469
  async function runPipelineWithSubscriptionRetry3(responsesBody, plan) {
2233
2470
  const first = await runPipeline4(responsesBody, plan);
2234
2471
  if (first.rawStatus !== 401) return first;
2235
- const refreshed = await _optionalChain([plan, 'access', _71 => _71.auth, 'access', _72 => _72.onUnauthorized, 'optionalCall', _73 => _73(plan.sessionKey)]);
2472
+ const refreshed = await _optionalChain([plan, 'access', _77 => _77.auth, 'access', _78 => _78.onUnauthorized, 'optionalCall', _79 => _79(plan.sessionKey)]);
2236
2473
  if (!refreshed) {
2237
2474
  console.warn("[ProviderProxy:responses] 401 not recoverable (onUnauthorized returned false)");
2238
2475
  return first;
@@ -2240,6 +2477,22 @@ async function runPipelineWithSubscriptionRetry3(responsesBody, plan) {
2240
2477
  console.log("[ProviderProxy:responses] 401 \u2192 token refreshed; retrying once");
2241
2478
  return runPipeline4(responsesBody, plan);
2242
2479
  }
2480
+ var MAX_QUOTA_RETRIES = 3;
2481
+ function isCodexAccountQuota429(plan, result) {
2482
+ return plan.proxyProviderId === "codex" && !!result.accountId && result.rawStatus === 429;
2483
+ }
2484
+ async function retryAroundCodexUsageLimit(responsesBody, plan, first, runAttempt = runPipelineWithSubscriptionRetry3) {
2485
+ if (!isCodexAccountQuota429(plan, first)) return first;
2486
+ let current = first;
2487
+ for (let attempt = 0; attempt < MAX_QUOTA_RETRIES; attempt++) {
2488
+ const errorBody = await current.response.text().catch(() => "");
2489
+ markCodexUsageLimitExhaustion(current.accountId, errorBody);
2490
+ const next = await runAttempt(responsesBody, plan);
2491
+ if (!isCodexAccountQuota429(plan, next)) return next;
2492
+ current = next;
2493
+ }
2494
+ return current;
2495
+ }
2243
2496
 
2244
2497
  // src/provider-proxy/providerProxyRouter.ts
2245
2498
  function extractRouteToken(authHeader) {
@@ -2254,7 +2507,7 @@ function resolveRouteToken(req) {
2254
2507
  if (fromAuth) return fromAuth;
2255
2508
  const googKey = req.headers["x-goog-api-key"];
2256
2509
  const value = Array.isArray(googKey) ? googKey[0] : googKey;
2257
- return _optionalChain([value, 'optionalAccess', _74 => _74.trim, 'call', _75 => _75()]) || void 0;
2510
+ return _optionalChain([value, 'optionalAccess', _80 => _80.trim, 'call', _81 => _81()]) || void 0;
2258
2511
  }
2259
2512
  async function routeRequest(req, res, routes, deps) {
2260
2513
  const token = resolveRouteToken(req);
@@ -2462,11 +2715,11 @@ var DEFAULT_ACCOUNT_HEALTH = {
2462
2715
  overloadCooldownMs: 10 * 6e4
2463
2716
  };
2464
2717
  function normalizeAccountHealth(raw) {
2465
- const ah = _optionalChain([raw, 'optionalAccess', _76 => _76.accountHealth]);
2718
+ const ah = _optionalChain([raw, 'optionalAccess', _82 => _82.accountHealth]);
2466
2719
  return {
2467
- overloadCooldownEnabled: _optionalChain([ah, 'optionalAccess', _77 => _77.overloadCooldownEnabled]) !== false,
2720
+ overloadCooldownEnabled: _optionalChain([ah, 'optionalAccess', _83 => _83.overloadCooldownEnabled]) !== false,
2468
2721
  overloadCooldownMs: clampNumber(
2469
- _optionalChain([ah, 'optionalAccess', _78 => _78.overloadCooldownMs]),
2722
+ _optionalChain([ah, 'optionalAccess', _84 => _84.overloadCooldownMs]),
2470
2723
  6e4,
2471
2724
  36e5,
2472
2725
  DEFAULT_ACCOUNT_HEALTH.overloadCooldownMs
@@ -2488,25 +2741,25 @@ var DEFAULT_ALLOWANCE_SCHEDULING = {
2488
2741
  priorityPenalty: 100
2489
2742
  };
2490
2743
  function normalizeAllowanceScheduling(raw) {
2491
- const value = _optionalChain([raw, 'optionalAccess', _79 => _79.allowanceScheduling]);
2744
+ const value = _optionalChain([raw, 'optionalAccess', _85 => _85.allowanceScheduling]);
2492
2745
  const demoteAtPercent = clampNumber(
2493
- _optionalChain([value, 'optionalAccess', _80 => _80.demoteAtPercent]),
2746
+ _optionalChain([value, 'optionalAccess', _86 => _86.demoteAtPercent]),
2494
2747
  0,
2495
2748
  100,
2496
2749
  DEFAULT_ALLOWANCE_SCHEDULING.demoteAtPercent
2497
2750
  );
2498
2751
  const requestedPause = clampNumber(
2499
- _optionalChain([value, 'optionalAccess', _81 => _81.pauseAtPercent]),
2752
+ _optionalChain([value, 'optionalAccess', _87 => _87.pauseAtPercent]),
2500
2753
  0,
2501
2754
  100,
2502
2755
  DEFAULT_ALLOWANCE_SCHEDULING.pauseAtPercent
2503
2756
  );
2504
2757
  return {
2505
- enabled: _optionalChain([value, 'optionalAccess', _82 => _82.enabled]) === true,
2758
+ enabled: _optionalChain([value, 'optionalAccess', _88 => _88.enabled]) === true,
2506
2759
  demoteAtPercent,
2507
2760
  pauseAtPercent: Math.max(demoteAtPercent, requestedPause),
2508
2761
  priorityPenalty: Math.trunc(clampNumber(
2509
- _optionalChain([value, 'optionalAccess', _83 => _83.priorityPenalty]),
2762
+ _optionalChain([value, 'optionalAccess', _89 => _89.priorityPenalty]),
2510
2763
  1,
2511
2764
  1e3,
2512
2765
  DEFAULT_ALLOWANCE_SCHEDULING.priorityPenalty
@@ -2514,53 +2767,58 @@ function normalizeAllowanceScheduling(raw) {
2514
2767
  };
2515
2768
  }
2516
2769
  function normalizeAccountProbe(raw) {
2517
- const ap = _optionalChain([raw, 'optionalAccess', _84 => _84.accountProbe]);
2770
+ const ap = _optionalChain([raw, 'optionalAccess', _90 => _90.accountProbe]);
2518
2771
  return {
2519
- enabled: _optionalChain([ap, 'optionalAccess', _85 => _85.enabled]) === true,
2520
- intervalMs: clampNumber(_optionalChain([ap, 'optionalAccess', _86 => _86.intervalMs]), 6e4, 864e5, DEFAULT_ACCOUNT_PROBE.intervalMs),
2521
- onlyMultiAccount: _optionalChain([ap, 'optionalAccess', _87 => _87.onlyMultiAccount]) !== false,
2522
- timeoutMs: clampNumber(_optionalChain([ap, 'optionalAccess', _88 => _88.timeoutMs]), 1e3, 6e4, DEFAULT_ACCOUNT_PROBE.timeoutMs),
2772
+ enabled: _optionalChain([ap, 'optionalAccess', _91 => _91.enabled]) === true,
2773
+ intervalMs: clampNumber(_optionalChain([ap, 'optionalAccess', _92 => _92.intervalMs]), 6e4, 864e5, DEFAULT_ACCOUNT_PROBE.intervalMs),
2774
+ onlyMultiAccount: _optionalChain([ap, 'optionalAccess', _93 => _93.onlyMultiAccount]) !== false,
2775
+ timeoutMs: clampNumber(_optionalChain([ap, 'optionalAccess', _94 => _94.timeoutMs]), 1e3, 6e4, DEFAULT_ACCOUNT_PROBE.timeoutMs),
2523
2776
  historySize: Math.trunc(
2524
- clampNumber(_optionalChain([ap, 'optionalAccess', _89 => _89.historySize]), 1, 200, DEFAULT_ACCOUNT_PROBE.historySize)
2777
+ clampNumber(_optionalChain([ap, 'optionalAccess', _95 => _95.historySize]), 1, 200, DEFAULT_ACCOUNT_PROBE.historySize)
2525
2778
  ),
2526
- staggerMs: clampNumber(_optionalChain([ap, 'optionalAccess', _90 => _90.staggerMs]), 0, 6e4, DEFAULT_ACCOUNT_PROBE.staggerMs)
2779
+ staggerMs: clampNumber(_optionalChain([ap, 'optionalAccess', _96 => _96.staggerMs]), 0, 6e4, DEFAULT_ACCOUNT_PROBE.staggerMs)
2527
2780
  };
2528
2781
  }
2529
2782
  function normalizeAudit(raw) {
2530
- const a = _optionalChain([raw, 'optionalAccess', _91 => _91.audit]);
2783
+ const a = _optionalChain([raw, 'optionalAccess', _97 => _97.audit]);
2531
2784
  return {
2532
- enabled: _optionalChain([a, 'optionalAccess', _92 => _92.enabled]) === true,
2533
- captureBodies: _optionalChain([a, 'optionalAccess', _93 => _93.captureBodies]) === true,
2534
- maxBodyBytes: Math.trunc(
2535
- clampNumber(_optionalChain([a, 'optionalAccess', _94 => _94.maxBodyBytes]), 256, 1048576, _audittypes.DEFAULT_AUDIT_CONFIG.maxBodyBytes)
2536
- ),
2785
+ enabled: _optionalChain([a, 'optionalAccess', _98 => _98.enabled]) === true,
2786
+ captureBodies: _optionalChain([a, 'optionalAccess', _99 => _99.captureBodies]) === true,
2787
+ maxBodyBytes: normalizeMaxBodyBytes(_optionalChain([a, 'optionalAccess', _100 => _100.maxBodyBytes])),
2537
2788
  retentionDays: Math.trunc(
2538
- clampNumber(_optionalChain([a, 'optionalAccess', _95 => _95.retentionDays]), 1, 365, _audittypes.DEFAULT_AUDIT_CONFIG.retentionDays)
2789
+ clampNumber(_optionalChain([a, 'optionalAccess', _101 => _101.retentionDays]), 1, 365, _audittypes.DEFAULT_AUDIT_CONFIG.retentionDays)
2539
2790
  ),
2540
- trustForwardedFor: _optionalChain([a, 'optionalAccess', _96 => _96.trustForwardedFor]) === true
2791
+ trustForwardedFor: _optionalChain([a, 'optionalAccess', _102 => _102.trustForwardedFor]) === true
2541
2792
  };
2542
2793
  }
2794
+ function normalizeMaxBodyBytes(value) {
2795
+ if (value === -1) return -1;
2796
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
2797
+ return _audittypes.DEFAULT_AUDIT_CONFIG.maxBodyBytes;
2798
+ }
2799
+ return Math.trunc(Math.min(1048576, value));
2800
+ }
2543
2801
  function normalizeBilling(raw) {
2544
- const b = _optionalChain([raw, 'optionalAccess', _97 => _97.billing]);
2802
+ const b = _optionalChain([raw, 'optionalAccess', _103 => _103.billing]);
2545
2803
  const config = {
2546
- enabled: _optionalChain([b, 'optionalAccess', _98 => _98.enabled]) === true,
2804
+ enabled: _optionalChain([b, 'optionalAccess', _104 => _104.enabled]) === true,
2547
2805
  maxRetryAgeMs: Math.trunc(
2548
- clampNumber(_optionalChain([b, 'optionalAccess', _99 => _99.maxRetryAgeMs]), 6e4, 2592e6, _billingtypes.DEFAULT_BILLING_CONFIG.maxRetryAgeMs)
2806
+ clampNumber(_optionalChain([b, 'optionalAccess', _105 => _105.maxRetryAgeMs]), 6e4, 2592e6, _billingtypes.DEFAULT_BILLING_CONFIG.maxRetryAgeMs)
2549
2807
  )
2550
2808
  };
2551
- if (typeof _optionalChain([b, 'optionalAccess', _100 => _100.endpoint]) === "string" && b.endpoint.trim()) config.endpoint = b.endpoint.trim();
2552
- if (typeof _optionalChain([b, 'optionalAccess', _101 => _101.secret]) === "string" && b.secret.length > 0) config.secret = b.secret;
2809
+ if (typeof _optionalChain([b, 'optionalAccess', _106 => _106.endpoint]) === "string" && b.endpoint.trim()) config.endpoint = b.endpoint.trim();
2810
+ if (typeof _optionalChain([b, 'optionalAccess', _107 => _107.secret]) === "string" && b.secret.length > 0) config.secret = b.secret;
2553
2811
  return config;
2554
2812
  }
2555
2813
  var DEFAULT_FINGERPRINT = { enabled: false };
2556
2814
  function normalizeFingerprint(raw) {
2557
- const f = _optionalChain([raw, 'optionalAccess', _102 => _102.fingerprint]);
2558
- const out = { enabled: _optionalChain([f, 'optionalAccess', _103 => _103.enabled]) === true };
2559
- if (typeof _optionalChain([f, 'optionalAccess', _104 => _104.ua]) === "string" && f.ua.trim().length > 0) out.ua = f.ua.trim();
2815
+ const f = _optionalChain([raw, 'optionalAccess', _108 => _108.fingerprint]);
2816
+ const out = { enabled: _optionalChain([f, 'optionalAccess', _109 => _109.enabled]) === true };
2817
+ if (typeof _optionalChain([f, 'optionalAccess', _110 => _110.ua]) === "string" && f.ua.trim().length > 0) out.ua = f.ua.trim();
2560
2818
  return out;
2561
2819
  }
2562
2820
  function normalizeVoucher(raw) {
2563
- return { enabled: _optionalChain([raw, 'optionalAccess', _105 => _105.voucher, 'optionalAccess', _106 => _106.enabled]) === true };
2821
+ return { enabled: _optionalChain([raw, 'optionalAccess', _111 => _111.voucher, 'optionalAccess', _112 => _112.enabled]) === true };
2564
2822
  }
2565
2823
  var PROXY_TYPES = ["http", "https", "socks5"];
2566
2824
  function normalizeProxyConfig(raw) {
@@ -2644,14 +2902,14 @@ function clampNumber(value, min, max, fallback) {
2644
2902
  return Math.min(max, Math.max(min, n));
2645
2903
  }
2646
2904
  function normalizeQueueSegments(raw) {
2647
- const umq = _optionalChain([raw, 'optionalAccess', _107 => _107.userMessageQueue]);
2648
- const cq = _optionalChain([raw, 'optionalAccess', _108 => _108.concurrencyQueue]);
2905
+ const umq = _optionalChain([raw, 'optionalAccess', _113 => _113.userMessageQueue]);
2906
+ const cq = _optionalChain([raw, 'optionalAccess', _114 => _114.concurrencyQueue]);
2649
2907
  return {
2650
2908
  userMessageQueue: {
2651
- enabled: _optionalChain([umq, 'optionalAccess', _109 => _109.enabled]) === true,
2652
- delayMs: clampNumber(_optionalChain([umq, 'optionalAccess', _110 => _110.delayMs]), 0, 1e4, DEFAULT_USER_MESSAGE_QUEUE.delayMs),
2909
+ enabled: _optionalChain([umq, 'optionalAccess', _115 => _115.enabled]) === true,
2910
+ delayMs: clampNumber(_optionalChain([umq, 'optionalAccess', _116 => _116.delayMs]), 0, 1e4, DEFAULT_USER_MESSAGE_QUEUE.delayMs),
2653
2911
  waitTimeoutMs: clampNumber(
2654
- _optionalChain([umq, 'optionalAccess', _111 => _111.waitTimeoutMs]),
2912
+ _optionalChain([umq, 'optionalAccess', _117 => _117.waitTimeoutMs]),
2655
2913
  1e3,
2656
2914
  3e5,
2657
2915
  DEFAULT_USER_MESSAGE_QUEUE.waitTimeoutMs
@@ -2659,14 +2917,14 @@ function normalizeQueueSegments(raw) {
2659
2917
  },
2660
2918
  concurrencyQueue: {
2661
2919
  maxQueueSizeFactor: clampNumber(
2662
- _optionalChain([cq, 'optionalAccess', _112 => _112.maxQueueSizeFactor]),
2920
+ _optionalChain([cq, 'optionalAccess', _118 => _118.maxQueueSizeFactor]),
2663
2921
  1,
2664
2922
  10,
2665
2923
  DEFAULT_CONCURRENCY_QUEUE.maxQueueSizeFactor
2666
2924
  ),
2667
- minQueueSize: clampNumber(_optionalChain([cq, 'optionalAccess', _113 => _113.minQueueSize]), 1, 100, DEFAULT_CONCURRENCY_QUEUE.minQueueSize),
2925
+ minQueueSize: clampNumber(_optionalChain([cq, 'optionalAccess', _119 => _119.minQueueSize]), 1, 100, DEFAULT_CONCURRENCY_QUEUE.minQueueSize),
2668
2926
  waitTimeoutMs: clampNumber(
2669
- _optionalChain([cq, 'optionalAccess', _114 => _114.waitTimeoutMs]),
2927
+ _optionalChain([cq, 'optionalAccess', _120 => _120.waitTimeoutMs]),
2670
2928
  1e3,
2671
2929
  3e5,
2672
2930
  DEFAULT_CONCURRENCY_QUEUE.waitTimeoutMs
@@ -2779,7 +3037,7 @@ function normalizeGatewayModelMappings(raw) {
2779
3037
  return mappings;
2780
3038
  }
2781
3039
  function hasConfiguredLegacyModels(config) {
2782
- return Object.values(_nullishCoalesce(config.modelMap, () => ( {}))).some((value) => typeof value === "string" && value.trim()) || Boolean(_optionalChain([config, 'access', _115 => _115.models, 'optionalAccess', _116 => _116.some, 'call', _117 => _117((value) => typeof value === "string" && value.trim())])) || Boolean(_optionalChain([config, 'access', _118 => _118.defaultModel, 'optionalAccess', _119 => _119.trim, 'call', _120 => _120()])) || Boolean(_optionalChain([config, 'access', _121 => _121.backgroundModel, 'optionalAccess', _122 => _122.trim, 'call', _123 => _123()])) || Boolean(Object.values(_nullishCoalesce(config.prefixTargets, () => ( {}))).some((value) => _optionalChain([value, 'optionalAccess', _124 => _124.trim, 'call', _125 => _125()])));
3040
+ return Object.values(_nullishCoalesce(config.modelMap, () => ( {}))).some((value) => typeof value === "string" && value.trim()) || Boolean(_optionalChain([config, 'access', _121 => _121.models, 'optionalAccess', _122 => _122.some, 'call', _123 => _123((value) => typeof value === "string" && value.trim())])) || Boolean(_optionalChain([config, 'access', _124 => _124.defaultModel, 'optionalAccess', _125 => _125.trim, 'call', _126 => _126()])) || Boolean(_optionalChain([config, 'access', _127 => _127.backgroundModel, 'optionalAccess', _128 => _128.trim, 'call', _129 => _129()])) || Boolean(Object.values(_nullishCoalesce(config.prefixTargets, () => ( {}))).some((value) => _optionalChain([value, 'optionalAccess', _130 => _130.trim, 'call', _131 => _131()])));
2783
3041
  }
2784
3042
  function splitModelRef(ref) {
2785
3043
  if (typeof ref !== "string") return null;
@@ -2847,7 +3105,7 @@ function legacyEndpointToBindings(config) {
2847
3105
  if (!parsed) continue;
2848
3106
  const route = routeFor(parsed.providerId);
2849
3107
  route[field] = ref;
2850
- if (_optionalChain([config, 'access', _126 => _126.backgroundModelIds, 'optionalAccess', _127 => _127.length])) {
3108
+ if (_optionalChain([config, 'access', _132 => _132.backgroundModelIds, 'optionalAccess', _133 => _133.length])) {
2851
3109
  route.backgroundModelIds = [...config.backgroundModelIds];
2852
3110
  }
2853
3111
  }
@@ -3003,8 +3261,8 @@ function nonBlank(value) {
3003
3261
  return typeof value === "string" && value.trim() !== "";
3004
3262
  }
3005
3263
  function gatewayBindingAllowsKey(binding, apiKeyId) {
3006
- const scope = _nullishCoalesce(binding.keyScope, () => ( (_optionalChain([binding, 'access', _128 => _128.apiKeyIds, 'optionalAccess', _129 => _129.length]) ? "selected" : "all")));
3007
- return scope === "all" || Boolean(_optionalChain([binding, 'access', _130 => _130.apiKeyIds, 'optionalAccess', _131 => _131.includes, 'call', _132 => _132(apiKeyId)]));
3264
+ const scope = _nullishCoalesce(binding.keyScope, () => ( (_optionalChain([binding, 'access', _134 => _134.apiKeyIds, 'optionalAccess', _135 => _135.length]) ? "selected" : "all")));
3265
+ return scope === "all" || Boolean(_optionalChain([binding, 'access', _136 => _136.apiKeyIds, 'optionalAccess', _137 => _137.includes, 'call', _138 => _138(apiKeyId)]));
3008
3266
  }
3009
3267
  function wildcardMatches(pattern, value) {
3010
3268
  const escaped = pattern.split("*").map((part) => part.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&")).join(".*");
@@ -3024,7 +3282,7 @@ function resolveGatewayModelMapping(mappings, requestedModel) {
3024
3282
  }
3025
3283
  function routeCanServe(binding, requestedModel, role) {
3026
3284
  if (binding.modelMode === "passthrough") return nonBlank(requestedModel);
3027
- if (_optionalChain([binding, 'access', _133 => _133.modelMappings, 'optionalAccess', _134 => _134.length])) {
3285
+ if (_optionalChain([binding, 'access', _139 => _139.modelMappings, 'optionalAccess', _140 => _140.length])) {
3028
3286
  return nonBlank(resolveGatewayModelMapping(binding.modelMappings, requestedModel));
3029
3287
  }
3030
3288
  if (_chunk4VZX5F4Tcjs.isKindMappedEndpoint.call(void 0, binding.endpoint)) {
@@ -3042,7 +3300,7 @@ function routeCanServe(binding, requestedModel, role) {
3042
3300
  if (binding.endpoint === "chat") {
3043
3301
  if (!requestedModel) return false;
3044
3302
  const wanted = requestedModel.trim().toLowerCase();
3045
- return (_nullishCoalesce(binding.models, () => ( []))).some((ref) => _optionalChain([modelIdOf, 'call', _135 => _135(ref), 'optionalAccess', _136 => _136.toLowerCase, 'call', _137 => _137()]) === wanted);
3303
+ return (_nullishCoalesce(binding.models, () => ( []))).some((ref) => _optionalChain([modelIdOf, 'call', _141 => _141(ref), 'optionalAccess', _142 => _142.toLowerCase, 'call', _143 => _143()]) === wanted);
3046
3304
  }
3047
3305
  return role === "background" ? nonBlank(binding.backgroundModel) : nonBlank(binding.defaultModel);
3048
3306
  }
@@ -3093,7 +3351,7 @@ function gatewayBindingToEndpointConfig(binding, requestedModel) {
3093
3351
  endpoint: binding.endpoint,
3094
3352
  useSubscription: target.kind !== "provider"
3095
3353
  };
3096
- const usesGenericModelHandling = binding.modelMode === "passthrough" || Boolean(_optionalChain([binding, 'access', _138 => _138.modelMappings, 'optionalAccess', _139 => _139.length]));
3354
+ const usesGenericModelHandling = binding.modelMode === "passthrough" || Boolean(_optionalChain([binding, 'access', _144 => _144.modelMappings, 'optionalAccess', _145 => _145.length]));
3097
3355
  const dynamicModel = binding.modelMode === "passthrough" ? requestedModel : resolveGatewayModelMapping(binding.modelMappings, requestedModel);
3098
3356
  if (usesGenericModelHandling) {
3099
3357
  if (nonBlank(dynamicModel)) applySingleModel(config, binding, dynamicModel);
@@ -3128,7 +3386,7 @@ function candidateGatewayBindings(bindings, apiKeyId, endpoint) {
3128
3386
  const candidates = (_nullishCoalesce(bindings, () => ( []))).filter(
3129
3387
  (binding) => binding.enabled && binding.endpoint === endpoint && gatewayBindingAllowsKey(binding, apiKeyId)
3130
3388
  );
3131
- const scopeOf = (binding) => _nullishCoalesce(binding.keyScope, () => ( (_optionalChain([binding, 'access', _140 => _140.apiKeyIds, 'optionalAccess', _141 => _141.length]) ? "selected" : "all")));
3389
+ const scopeOf = (binding) => _nullishCoalesce(binding.keyScope, () => ( (_optionalChain([binding, 'access', _146 => _146.apiKeyIds, 'optionalAccess', _147 => _147.length]) ? "selected" : "all")));
3132
3390
  const scoped = candidates.filter((binding) => scopeOf(binding) === "selected");
3133
3391
  const pool = scoped.length > 0 ? scoped : candidates.filter((binding) => scopeOf(binding) === "all");
3134
3392
  return pool.sort(
@@ -3240,7 +3498,8 @@ async function createNamedKey(db, name) {
3240
3498
  id,
3241
3499
  name,
3242
3500
  keyHash: hashKey(secret),
3243
- keyPrefix: prefix
3501
+ keyPrefix: prefix,
3502
+ plaintext: secret
3244
3503
  });
3245
3504
  return {
3246
3505
  id: row.id,
@@ -3261,7 +3520,8 @@ async function createIntegrationKey(db, name, allowedEndpoints = ["responses", "
3261
3520
  keyPrefix: prefix,
3262
3521
  kind: "integration",
3263
3522
  allowedEndpoints: [...new Set(allowedEndpoints)],
3264
- loopbackOnly: true
3523
+ loopbackOnly: true,
3524
+ plaintext: secret
3265
3525
  });
3266
3526
  return {
3267
3527
  id: row.id,
@@ -3518,8 +3778,8 @@ var OutboundRateLimiter = (_class8 = class {
3518
3778
  * recorded (no bucket growth).
3519
3779
  */
3520
3780
  check(apiKeyId, now = Date.now(), override) {
3521
- const maxRequests = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _142 => _142.maxRequests]), () => ( this.maxRequests));
3522
- const windowMs = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _143 => _143.windowMs]), () => ( this.windowMs));
3781
+ const maxRequests = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _148 => _148.maxRequests]), () => ( this.maxRequests));
3782
+ const windowMs = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _149 => _149.windowMs]), () => ( this.windowMs));
3523
3783
  if (maxRequests === 0) return { allowed: true, retryAfterSeconds: 0 };
3524
3784
  const cutoff = now - windowMs;
3525
3785
  const timestamps = (_nullishCoalesce(this.hits.get(apiKeyId), () => ( []))).filter((ts) => ts > cutoff);
@@ -3564,7 +3824,7 @@ function isUserMessageAnthropic(body) {
3564
3824
  if (typeof content === "string") return true;
3565
3825
  if (Array.isArray(content)) {
3566
3826
  const hasToolResult = content.some(
3567
- (block) => _optionalChain([asObject, 'call', _144 => _144(block), 'optionalAccess', _145 => _145["type"]]) === "tool_result"
3827
+ (block) => _optionalChain([asObject, 'call', _150 => _150(block), 'optionalAccess', _151 => _151["type"]]) === "tool_result"
3568
3828
  );
3569
3829
  return !hasToolResult;
3570
3830
  }
@@ -3593,7 +3853,7 @@ function isUserMessageGemini(body) {
3593
3853
  if (!lastContent || lastContent["role"] !== "user") return false;
3594
3854
  const parts = asArray(lastContent["parts"]);
3595
3855
  const hasFunctionResponse = parts.some(
3596
- (part) => _optionalChain([asObject, 'call', _146 => _146(part), 'optionalAccess', _147 => _147["functionResponse"]]) !== void 0
3856
+ (part) => _optionalChain([asObject, 'call', _152 => _152(part), 'optionalAccess', _153 => _153["functionResponse"]]) !== void 0
3597
3857
  );
3598
3858
  return !hasFunctionResponse;
3599
3859
  }
@@ -3767,14 +4027,14 @@ function newVoucherId() {
3767
4027
  }
3768
4028
  function computeVoucherGrant(voucher, currentKey, now) {
3769
4029
  if (voucher.type === "credit") {
3770
- const current = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _148 => _148.totalCostLimitUsd]), () => ( 0));
4030
+ const current = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _154 => _154.totalCostLimitUsd]), () => ( 0));
3771
4031
  let granted2 = current + (_nullishCoalesce(voucher.creditUsd, () => ( 0)));
3772
4032
  if (voucher.maxTotalCostLimitUsd != null) {
3773
4033
  granted2 = Math.min(granted2, voucher.maxTotalCostLimitUsd);
3774
4034
  }
3775
4035
  return { totalCostLimitUsd: granted2 };
3776
4036
  }
3777
- const currentExpiry = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _149 => _149.expiresAt]), () => ( now));
4037
+ const currentExpiry = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _155 => _155.expiresAt]), () => ( now));
3778
4038
  let granted = currentExpiry + (_nullishCoalesce(voucher.renewalDays, () => ( 0))) * DAY_MS2;
3779
4039
  if (voucher.maxExpiryDays != null) {
3780
4040
  granted = Math.min(granted, now + voucher.maxExpiryDays * DAY_MS2);
@@ -3805,7 +4065,7 @@ function toVoucherInfo(v) {
3805
4065
  // src/outbound-api/voucherRedeem.ts
3806
4066
  function isRedeemRequest(method, url) {
3807
4067
  if (method !== "POST" || !url) return false;
3808
- const path = _nullishCoalesce(_optionalChain([url, 'access', _150 => _150.split, 'call', _151 => _151("?"), 'access', _152 => _152[0], 'optionalAccess', _153 => _153.replace, 'call', _154 => _154(/\/+$/, "")]), () => ( ""));
4068
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _156 => _156.split, 'call', _157 => _157("?"), 'access', _158 => _158[0], 'optionalAccess', _159 => _159.replace, 'call', _160 => _160(/\/+$/, "")]), () => ( ""));
3809
4069
  return path.endsWith("/redeem");
3810
4070
  }
3811
4071
  function writeErr(res, status, message, headers = {}) {
@@ -3835,8 +4095,8 @@ function grantToResult(type, granted) {
3835
4095
  function currentResult(type, keyRow) {
3836
4096
  const result = { type };
3837
4097
  if (type === "credit") {
3838
- if (_optionalChain([keyRow, 'optionalAccess', _155 => _155.totalCostLimitUsd]) != null) result.totalCostLimitUsd = keyRow.totalCostLimitUsd;
3839
- } else if (_optionalChain([keyRow, 'optionalAccess', _156 => _156.expiresAt]) != null) {
4098
+ if (_optionalChain([keyRow, 'optionalAccess', _161 => _161.totalCostLimitUsd]) != null) result.totalCostLimitUsd = keyRow.totalCostLimitUsd;
4099
+ } else if (_optionalChain([keyRow, 'optionalAccess', _162 => _162.expiresAt]) != null) {
3840
4100
  result.expiresAt = keyRow.expiresAt;
3841
4101
  }
3842
4102
  return result;
@@ -3923,7 +4183,7 @@ async function handleVoucherRedeem(req, res, deps, voucherEnabled, redeemLimiter
3923
4183
  const won = await voucherDb.voucherRedeemCas(voucher.id, verifiedKeyId, absolute, now);
3924
4184
  if (!won) {
3925
4185
  const after = await voucherDb.voucherGetByHash(codeHash);
3926
- if (_optionalChain([after, 'optionalAccess', _157 => _157.status]) === "redeemed" && after.redeemedByKeyId === verifiedKeyId) {
4186
+ if (_optionalChain([after, 'optionalAccess', _163 => _163.status]) === "redeemed" && after.redeemedByKeyId === verifiedKeyId) {
3927
4187
  return after.grantApplied === true ? { ok: true, result: currentResult(after.type, await deps.db.outboundApiKeysGetByHash(keyHash)) } : await applyFirstPass(after, recordedAbsolute(after));
3928
4188
  }
3929
4189
  return { ok: false, status: 409, message: "Code was already redeemed" };
@@ -3984,10 +4244,10 @@ function extractPresentedKey(req) {
3984
4244
  }
3985
4245
  const xApiKey = req.headers["x-api-key"];
3986
4246
  const xApi = Array.isArray(xApiKey) ? xApiKey[0] : xApiKey;
3987
- if (_optionalChain([xApi, 'optionalAccess', _158 => _158.trim, 'call', _159 => _159()])) return xApi.trim();
4247
+ if (_optionalChain([xApi, 'optionalAccess', _164 => _164.trim, 'call', _165 => _165()])) return xApi.trim();
3988
4248
  const goog = req.headers["x-goog-api-key"];
3989
4249
  const g = Array.isArray(goog) ? goog[0] : goog;
3990
- return _optionalChain([g, 'optionalAccess', _160 => _160.trim, 'call', _161 => _161()]) || void 0;
4250
+ return _optionalChain([g, 'optionalAccess', _166 => _166.trim, 'call', _167 => _167()]) || void 0;
3991
4251
  }
3992
4252
  function isLoopbackPeer(address) {
3993
4253
  if (!address) return false;
@@ -3996,7 +4256,7 @@ function isLoopbackPeer(address) {
3996
4256
  }
3997
4257
  function selectEndpoint(method, url) {
3998
4258
  if (method !== "POST" || !url) return null;
3999
- const path = _nullishCoalesce(_optionalChain([url, 'access', _162 => _162.split, 'call', _163 => _163("?"), 'access', _164 => _164[0], 'optionalAccess', _165 => _165.replace, 'call', _166 => _166(/\/+$/, "")]), () => ( ""));
4259
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _168 => _168.split, 'call', _169 => _169("?"), 'access', _170 => _170[0], 'optionalAccess', _171 => _171.replace, 'call', _172 => _172(/\/+$/, "")]), () => ( ""));
4000
4260
  if (path.endsWith("/chat/completions")) return "chat";
4001
4261
  if (path.endsWith("/responses")) return "responses";
4002
4262
  if (path.includes("/v1/messages")) return "messages";
@@ -4014,7 +4274,7 @@ function extractGeminiModelFromUrl(url) {
4014
4274
  }
4015
4275
  function isModelsListRequest(url) {
4016
4276
  if (!url) return false;
4017
- const path = _nullishCoalesce(_optionalChain([url, 'access', _167 => _167.split, 'call', _168 => _168("?"), 'access', _169 => _169[0], 'optionalAccess', _170 => _170.replace, 'call', _171 => _171(/\/+$/, "")]), () => ( ""));
4277
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _173 => _173.split, 'call', _174 => _174("?"), 'access', _175 => _175[0], 'optionalAccess', _176 => _176.replace, 'call', _177 => _177(/\/+$/, "")]), () => ( ""));
4018
4278
  return path.endsWith("/models");
4019
4279
  }
4020
4280
  function writeModelsList(res, config, apiKeyId, allowedEndpoints) {
@@ -4062,7 +4322,7 @@ function shimAuthHeader(req, routeToken) {
4062
4322
  }
4063
4323
  async function handleOutboundRequest(req, res, deps, config, rateLimiter, serialQueue, concurrencyGate, redeemLimiter, redeemMutex) {
4064
4324
  const now = Date.now();
4065
- const audit = _chunkUNWKG6EIcjs.beginAuditCapture.call(void 0, req, res, now);
4325
+ const audit = _chunkXPIOJQS2cjs.beginAuditCapture.call(void 0, req, res, now);
4066
4326
  const billing = _chunkAPYG5QD7cjs.beginBillingCapture.call(void 0, req, res, now);
4067
4327
  const presented = extractPresentedKey(req);
4068
4328
  const verification = await verifyKey(deps.db, presented, now);
@@ -4077,7 +4337,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
4077
4337
  const verified = verification.key;
4078
4338
  if (audit) audit.keyId = verified.id;
4079
4339
  if (billing) billing.keyId = verified.id;
4080
- if (verified.loopbackOnly && !isLoopbackPeer(_optionalChain([req, 'access', _172 => _172.socket, 'optionalAccess', _173 => _173.remoteAddress]))) {
4340
+ if (verified.loopbackOnly && !isLoopbackPeer(_optionalChain([req, 'access', _178 => _178.socket, 'optionalAccess', _179 => _179.remoteAddress]))) {
4081
4341
  writeJsonError(res, 403, "This integration key is restricted to loopback clients");
4082
4342
  return;
4083
4343
  }
@@ -4090,7 +4350,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
4090
4350
  req,
4091
4351
  res,
4092
4352
  deps,
4093
- _optionalChain([config, 'access', _174 => _174.voucher, 'optionalAccess', _175 => _175.enabled]) === true,
4353
+ _optionalChain([config, 'access', _180 => _180.voucher, 'optionalAccess', _181 => _181.enabled]) === true,
4094
4354
  _nullishCoalesce(redeemLimiter, () => ( getFallbackRedeemLimiter())),
4095
4355
  verified.id,
4096
4356
  _nullishCoalesce(presented, () => ( "")),
@@ -4259,7 +4519,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
4259
4519
  }
4260
4520
  let releaseSerial = null;
4261
4521
  const providerKey = resolved.route.providerId;
4262
- if (_optionalChain([config, 'access', _176 => _176.userMessageQueue, 'optionalAccess', _177 => _177.enabled]) && providerKey && isUserMessageRequest(endpoint, parsedBody)) {
4522
+ if (_optionalChain([config, 'access', _182 => _182.userMessageQueue, 'optionalAccess', _183 => _183.enabled]) && providerKey && isUserMessageRequest(endpoint, parsedBody)) {
4263
4523
  const umq = config.userMessageQueue;
4264
4524
  try {
4265
4525
  const serialSlot = await serialQueue.acquire(providerKey, {
@@ -4399,7 +4659,7 @@ var OutboundApiServer = (_class11 = class {
4399
4659
  const actualPort = await this.listen(bindAddr, port);
4400
4660
  this.boundAddr = bindAddr;
4401
4661
  this.boundPort = actualPort;
4402
- if (actualPort !== port) _optionalChain([this, 'access', _178 => _178.onPortChange, 'optionalCall', _179 => _179(actualPort)]);
4662
+ if (actualPort !== port) _optionalChain([this, 'access', _184 => _184.onPortChange, 'optionalCall', _185 => _185(actualPort)]);
4403
4663
  this.logInfo(`[OutboundApiServer] Listening on ${bindAddr}:${actualPort}`);
4404
4664
  return actualPort;
4405
4665
  }
@@ -4468,7 +4728,7 @@ var OutboundApiServer = (_class11 = class {
4468
4728
  const provider = this.deps.healthReportProvider;
4469
4729
  if (!provider) return false;
4470
4730
  if (req.method !== "GET" && req.method !== "HEAD") return false;
4471
- const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access', _180 => _180.split, 'call', _181 => _181("?"), 'access', _182 => _182[0], 'optionalAccess', _183 => _183.replace, 'call', _184 => _184(/\/+$/, "")]) || "/";
4731
+ const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access', _186 => _186.split, 'call', _187 => _187("?"), 'access', _188 => _188[0], 'optionalAccess', _189 => _189.replace, 'call', _190 => _190(/\/+$/, "")]) || "/";
4472
4732
  if (path !== "/health" && path !== "/healthz") return false;
4473
4733
  const report = provider();
4474
4734
  res.writeHead(_healthloggingtypes.healthHttpStatus.call(void 0, report.status), { "Content-Type": "application/json" });
@@ -4746,14 +5006,14 @@ async function callAnthropicCompletion(provider, apiKey, options, logger) {
4746
5006
  };
4747
5007
  }
4748
5008
  const anthropicResponse2 = await response2.json();
4749
- const openaiResponse2 = _chunkWYTEQ4Q5cjs.convertAnthropicToOpenAI.call(void 0, anthropicResponse2);
5009
+ const openaiResponse2 = _chunkGDIXXKF2cjs.convertAnthropicToOpenAI.call(void 0, anthropicResponse2);
4750
5010
  const choice2 = openaiResponse2.choices[0];
4751
5011
  return {
4752
5012
  success: true,
4753
5013
  message: {
4754
5014
  id: `assistant-${Date.now()}`,
4755
5015
  role: "assistant",
4756
- content: _optionalChain([choice2, 'access', _185 => _185.message, 'optionalAccess', _186 => _186.content]) || "",
5016
+ content: _optionalChain([choice2, 'access', _191 => _191.message, 'optionalAccess', _192 => _192.content]) || "",
4757
5017
  timestamp: Date.now()
4758
5018
  },
4759
5019
  usage: openaiResponse2.usage ? {
@@ -4777,7 +5037,7 @@ async function callAnthropicCompletion(provider, apiKey, options, logger) {
4777
5037
  const config = {
4778
5038
  defaultModel: options.model
4779
5039
  };
4780
- const anthropicRequest = _chunkWYTEQ4Q5cjs.convertOpenAIToAnthropic.call(void 0, openaiRequest, config);
5040
+ const anthropicRequest = _chunkGDIXXKF2cjs.convertOpenAIToAnthropic.call(void 0, openaiRequest, config);
4781
5041
  const apiUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: false });
4782
5042
  const headers = _chunkQ27JY5RGcjs.getProviderHeaders.call(void 0, provider, apiKey);
4783
5043
  logger.info("Calling Anthropic completion API", { url: apiUrl, model: options.model });
@@ -4794,7 +5054,7 @@ async function callAnthropicCompletion(provider, apiKey, options, logger) {
4794
5054
  };
4795
5055
  }
4796
5056
  const anthropicResponse = await response.json();
4797
- const openaiResponse = _chunkWYTEQ4Q5cjs.convertAnthropicToOpenAI.call(void 0, anthropicResponse);
5057
+ const openaiResponse = _chunkGDIXXKF2cjs.convertAnthropicToOpenAI.call(void 0, anthropicResponse);
4798
5058
  const choice = openaiResponse.choices[0];
4799
5059
  return {
4800
5060
  success: true,
@@ -4858,7 +5118,7 @@ async function callGeminiCompletion(provider, apiKey, options, logger) {
4858
5118
  const candidate = candidates[0];
4859
5119
  const content = candidate.content;
4860
5120
  let textContent = "";
4861
- if (_optionalChain([content, 'optionalAccess', _187 => _187.parts])) {
5121
+ if (_optionalChain([content, 'optionalAccess', _193 => _193.parts])) {
4862
5122
  for (const part of content.parts) {
4863
5123
  if (part.text) {
4864
5124
  textContent += part.text;
@@ -4991,7 +5251,7 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
4991
5251
  });
4992
5252
  if (!response.ok) {
4993
5253
  const errorText = await response.text();
4994
- _optionalChain([callbacks, 'access', _188 => _188.onError, 'optionalCall', _189 => _189(`API error (${response.status}): ${errorText}`)]);
5254
+ _optionalChain([callbacks, 'access', _194 => _194.onError, 'optionalCall', _195 => _195(`API error (${response.status}): ${errorText}`)]);
4995
5255
  return;
4996
5256
  }
4997
5257
  const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "openai", {
@@ -5001,7 +5261,7 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
5001
5261
  onVideo: callbacks.onVideo,
5002
5262
  onError: callbacks.onError
5003
5263
  });
5004
- _optionalChain([callbacks, 'access', _190 => _190.onDone, 'optionalCall', _191 => _191(
5264
+ _optionalChain([callbacks, 'access', _196 => _196.onDone, 'optionalCall', _197 => _197(
5005
5265
  {
5006
5266
  id: messageId,
5007
5267
  role: "assistant",
@@ -5059,7 +5319,7 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
5059
5319
  temperature: thinkingConfig ? void 0 : options.temperature,
5060
5320
  stream: true
5061
5321
  };
5062
- anthropicRequest = _chunkWYTEQ4Q5cjs.convertOpenAIToAnthropic.call(void 0, openaiRequest, config);
5322
+ anthropicRequest = _chunkGDIXXKF2cjs.convertOpenAIToAnthropic.call(void 0, openaiRequest, config);
5063
5323
  if (thinkingConfig) {
5064
5324
  anthropicRequest.thinking = thinkingConfig;
5065
5325
  delete anthropicRequest.temperature;
@@ -5073,7 +5333,7 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
5073
5333
  logger.info("Streaming Anthropic completion request", {
5074
5334
  url: apiUrl,
5075
5335
  model: anthropicRequest.model,
5076
- messagesCount: _optionalChain([anthropicRequest, 'access', _192 => _192.messages, 'optionalAccess', _193 => _193.length]),
5336
+ messagesCount: _optionalChain([anthropicRequest, 'access', _198 => _198.messages, 'optionalAccess', _199 => _199.length]),
5077
5337
  max_tokens: anthropicRequest.max_tokens,
5078
5338
  temperature: anthropicRequest.temperature,
5079
5339
  stream: anthropicRequest.stream,
@@ -5090,7 +5350,7 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
5090
5350
  if (!response.ok) {
5091
5351
  const errorText = await response.text();
5092
5352
  logger.error("Anthropic API error", void 0, { status: response.status, errorText });
5093
- _optionalChain([callbacks, 'access', _194 => _194.onError, 'optionalCall', _195 => _195(`API error (${response.status}): ${errorText}`)]);
5353
+ _optionalChain([callbacks, 'access', _200 => _200.onError, 'optionalCall', _201 => _201(`API error (${response.status}): ${errorText}`)]);
5094
5354
  return;
5095
5355
  }
5096
5356
  const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "anthropic", {
@@ -5101,10 +5361,10 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
5101
5361
  });
5102
5362
  logger.info("Anthropic stream complete", {
5103
5363
  contentLength: result.content.length,
5104
- reasoningLength: _optionalChain([result, 'access', _196 => _196.reasoning, 'optionalAccess', _197 => _197.length]) || 0,
5364
+ reasoningLength: _optionalChain([result, 'access', _202 => _202.reasoning, 'optionalAccess', _203 => _203.length]) || 0,
5105
5365
  blocksCount: result.blocks.length
5106
5366
  });
5107
- _optionalChain([callbacks, 'access', _198 => _198.onDone, 'optionalCall', _199 => _199(
5367
+ _optionalChain([callbacks, 'access', _204 => _204.onDone, 'optionalCall', _205 => _205(
5108
5368
  {
5109
5369
  id: messageId,
5110
5370
  role: "assistant",
@@ -5160,7 +5420,7 @@ async function streamGeminiCompletion(provider, apiKey, options, messageId, call
5160
5420
  if (!response.ok) {
5161
5421
  const errorText = await response.text();
5162
5422
  logger.error("Gemini API error", void 0, { status: response.status, errorText });
5163
- _optionalChain([callbacks, 'access', _200 => _200.onError, 'optionalCall', _201 => _201(`API error (${response.status}): ${errorText}`)]);
5423
+ _optionalChain([callbacks, 'access', _206 => _206.onError, 'optionalCall', _207 => _207(`API error (${response.status}): ${errorText}`)]);
5164
5424
  return;
5165
5425
  }
5166
5426
  const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "gemini", {
@@ -5169,7 +5429,7 @@ async function streamGeminiCompletion(provider, apiKey, options, messageId, call
5169
5429
  onError: callbacks.onError
5170
5430
  });
5171
5431
  logger.info("Gemini stream complete", { contentLength: result.content.length });
5172
- _optionalChain([callbacks, 'access', _202 => _202.onDone, 'optionalCall', _203 => _203(
5432
+ _optionalChain([callbacks, 'access', _208 => _208.onDone, 'optionalCall', _209 => _209(
5173
5433
  {
5174
5434
  id: messageId,
5175
5435
  role: "assistant",
@@ -5221,7 +5481,7 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
5221
5481
  });
5222
5482
  if (!response.ok) {
5223
5483
  const errorText = await response.text();
5224
- _optionalChain([callbacks, 'access', _204 => _204.onError, 'optionalCall', _205 => _205(`API error (${response.status}): ${errorText}`)]);
5484
+ _optionalChain([callbacks, 'access', _210 => _210.onError, 'optionalCall', _211 => _211(`API error (${response.status}): ${errorText}`)]);
5225
5485
  return;
5226
5486
  }
5227
5487
  const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "openai-response", {
@@ -5230,7 +5490,7 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
5230
5490
  onError: callbacks.onError
5231
5491
  });
5232
5492
  logger.info("OpenAI Response API stream complete", { contentLength: result.content.length });
5233
- _optionalChain([callbacks, 'access', _206 => _206.onDone, 'optionalCall', _207 => _207(
5493
+ _optionalChain([callbacks, 'access', _212 => _212.onDone, 'optionalCall', _213 => _213(
5234
5494
  {
5235
5495
  id: messageId,
5236
5496
  role: "assistant",
@@ -5258,7 +5518,7 @@ async function resolveEffectiveMaxTokens(llmConfig, _getProvider, logger, _provi
5258
5518
  }
5259
5519
  try {
5260
5520
  const globalParams = await llmConfig.getGlobalModelParameters();
5261
- if (_optionalChain([globalParams, 'optionalAccess', _208 => _208.maxTokens, 'optionalAccess', _209 => _209.enabled]) && globalParams.maxTokens.value > 0) {
5521
+ if (_optionalChain([globalParams, 'optionalAccess', _214 => _214.maxTokens, 'optionalAccess', _215 => _215.enabled]) && globalParams.maxTokens.value > 0) {
5262
5522
  logger.debug("Using global maxTokens", { maxTokens: globalParams.maxTokens.value });
5263
5523
  return globalParams.maxTokens.value;
5264
5524
  }
@@ -5286,7 +5546,7 @@ async function resolveThinkingBudget(getProvider, logger, providerId, modelId, m
5286
5546
  }
5287
5547
  const thinkingBudget = _thinkingconfig.calculateThinkingBudget.call(void 0, modelId, thinkLevel, maxTokens);
5288
5548
  const provider = await getProvider(providerId);
5289
- const providerName = _optionalChain([provider, 'optionalAccess', _210 => _210.name, 'optionalAccess', _211 => _211.toLowerCase, 'call', _212 => _212()]) || "";
5549
+ const providerName = _optionalChain([provider, 'optionalAccess', _216 => _216.name, 'optionalAccess', _217 => _217.toLowerCase, 'call', _218 => _218()]) || "";
5290
5550
  const apiFormat = provider ? _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider) : "openai";
5291
5551
  if (apiFormat === "anthropic" || providerName === "anthropic" || providerName.includes("claude")) {
5292
5552
  const thinkingConfig = _thinkingconfig.buildAnthropicThinking.call(void 0, modelId, thinkLevel, maxTokens);
@@ -5323,7 +5583,7 @@ function logToolFormat(tools, logger) {
5323
5583
  tools: openaiTools.map((t) => t.function.name),
5324
5584
  firstTool: {
5325
5585
  name: firstTool.function.name,
5326
- description: _optionalChain([firstTool, 'access', _213 => _213.function, 'access', _214 => _214.description, 'optionalAccess', _215 => _215.slice, 'call', _216 => _216(0, 100)]),
5586
+ description: _optionalChain([firstTool, 'access', _219 => _219.function, 'access', _220 => _220.description, 'optionalAccess', _221 => _221.slice, 'call', _222 => _222(0, 100)]),
5327
5587
  parameters: firstTool.function.parameters
5328
5588
  }
5329
5589
  });
@@ -5334,7 +5594,7 @@ function logToolFormat(tools, logger) {
5334
5594
  tools: anthropicTools.map((t) => t.name),
5335
5595
  firstTool: {
5336
5596
  name: firstTool.name,
5337
- description: _optionalChain([firstTool, 'access', _217 => _217.description, 'optionalAccess', _218 => _218.slice, 'call', _219 => _219(0, 100)]),
5597
+ description: _optionalChain([firstTool, 'access', _223 => _223.description, 'optionalAccess', _224 => _224.slice, 'call', _225 => _225(0, 100)]),
5338
5598
  input_schema: firstTool.input_schema
5339
5599
  }
5340
5600
  });
@@ -5345,9 +5605,9 @@ function logToolFormat(tools, logger) {
5345
5605
  count: allDeclarations.length,
5346
5606
  tools: allDeclarations.map((t) => t.name),
5347
5607
  firstTool: {
5348
- name: _optionalChain([allDeclarations, 'access', _220 => _220[0], 'optionalAccess', _221 => _221.name]),
5349
- description: _optionalChain([allDeclarations, 'access', _222 => _222[0], 'optionalAccess', _223 => _223.description, 'optionalAccess', _224 => _224.slice, 'call', _225 => _225(0, 100)]),
5350
- parameters: _optionalChain([allDeclarations, 'access', _226 => _226[0], 'optionalAccess', _227 => _227.parameters])
5608
+ name: _optionalChain([allDeclarations, 'access', _226 => _226[0], 'optionalAccess', _227 => _227.name]),
5609
+ description: _optionalChain([allDeclarations, 'access', _228 => _228[0], 'optionalAccess', _229 => _229.description, 'optionalAccess', _230 => _230.slice, 'call', _231 => _231(0, 100)]),
5610
+ parameters: _optionalChain([allDeclarations, 'access', _232 => _232[0], 'optionalAccess', _233 => _233.parameters])
5351
5611
  }
5352
5612
  });
5353
5613
  }
@@ -5381,7 +5641,7 @@ function buildToolRequest(apiFormat, conversationMessages, actualModel, options,
5381
5641
  // Native Anthropic Messages requires this field. Resolve an absent
5382
5642
  // caller cap to the model's real ceiling rather than a small constant —
5383
5643
  // see `resolveAnthropicMaxTokens`.
5384
- max_tokens: _chunk4VLRHHFEcjs.resolveAnthropicMaxTokens.call(void 0, actualModel, options.maxTokens),
5644
+ max_tokens: _chunkOXHNSZ53cjs.resolveAnthropicMaxTokens.call(void 0, actualModel, options.maxTokens),
5385
5645
  temperature: _nullishCoalesce(options.temperature, () => ( 0.7)),
5386
5646
  stream: true,
5387
5647
  tools: options.tools
@@ -5410,7 +5670,7 @@ function buildToolRequest(apiFormat, conversationMessages, actualModel, options,
5410
5670
  function extractDeltaContent(rawJson, apiFormat) {
5411
5671
  const json = rawJson;
5412
5672
  if (apiFormat === "google") {
5413
- const parts = _optionalChain([json, 'access', _228 => _228.candidates, 'optionalAccess', _229 => _229[0], 'optionalAccess', _230 => _230.content, 'optionalAccess', _231 => _231.parts]) || [];
5673
+ const parts = _optionalChain([json, 'access', _234 => _234.candidates, 'optionalAccess', _235 => _235[0], 'optionalAccess', _236 => _236.content, 'optionalAccess', _237 => _237.parts]) || [];
5414
5674
  let text = "";
5415
5675
  for (const part of parts) {
5416
5676
  if (part.thought === true) continue;
@@ -5418,15 +5678,15 @@ function extractDeltaContent(rawJson, apiFormat) {
5418
5678
  }
5419
5679
  return text;
5420
5680
  } else if (apiFormat === "anthropic") {
5421
- return _optionalChain([json, 'access', _232 => _232.delta, 'optionalAccess', _233 => _233.text]) || "";
5681
+ return _optionalChain([json, 'access', _238 => _238.delta, 'optionalAccess', _239 => _239.text]) || "";
5422
5682
  } else {
5423
- return _optionalChain([json, 'access', _234 => _234.choices, 'optionalAccess', _235 => _235[0], 'optionalAccess', _236 => _236.delta, 'optionalAccess', _237 => _237.content]) || "";
5683
+ return _optionalChain([json, 'access', _240 => _240.choices, 'optionalAccess', _241 => _241[0], 'optionalAccess', _242 => _242.delta, 'optionalAccess', _243 => _243.content]) || "";
5424
5684
  }
5425
5685
  }
5426
5686
  function extractDeltaReasoning(rawJson, apiFormat) {
5427
5687
  const json = rawJson;
5428
5688
  if (apiFormat === "google") {
5429
- const parts = _optionalChain([json, 'access', _238 => _238.candidates, 'optionalAccess', _239 => _239[0], 'optionalAccess', _240 => _240.content, 'optionalAccess', _241 => _241.parts]) || [];
5689
+ const parts = _optionalChain([json, 'access', _244 => _244.candidates, 'optionalAccess', _245 => _245[0], 'optionalAccess', _246 => _246.content, 'optionalAccess', _247 => _247.parts]) || [];
5430
5690
  let reasoning = "";
5431
5691
  for (const part of parts) {
5432
5692
  if (part.thought === true && part.text) reasoning += part.text;
@@ -5435,14 +5695,14 @@ function extractDeltaReasoning(rawJson, apiFormat) {
5435
5695
  } else if (apiFormat === "anthropic") {
5436
5696
  return "";
5437
5697
  } else {
5438
- const delta = _optionalChain([json, 'access', _242 => _242.choices, 'optionalAccess', _243 => _243[0], 'optionalAccess', _244 => _244.delta]);
5439
- return (_optionalChain([delta, 'optionalAccess', _245 => _245.thinking, 'optionalAccess', _246 => _246.content]) || "") + (_optionalChain([delta, 'optionalAccess', _247 => _247.reasoning_content]) || "");
5698
+ const delta = _optionalChain([json, 'access', _248 => _248.choices, 'optionalAccess', _249 => _249[0], 'optionalAccess', _250 => _250.delta]);
5699
+ return (_optionalChain([delta, 'optionalAccess', _251 => _251.thinking, 'optionalAccess', _252 => _252.content]) || "") + (_optionalChain([delta, 'optionalAccess', _253 => _253.reasoning_content]) || "");
5440
5700
  }
5441
5701
  }
5442
5702
  function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pendingOpenAIToolCalls) {
5443
5703
  const json = rawJson;
5444
5704
  if (apiFormat === "google") {
5445
- const parts = _optionalChain([json, 'access', _248 => _248.candidates, 'optionalAccess', _249 => _249[0], 'optionalAccess', _250 => _250.content, 'optionalAccess', _251 => _251.parts]) || [];
5705
+ const parts = _optionalChain([json, 'access', _254 => _254.candidates, 'optionalAccess', _255 => _255[0], 'optionalAccess', _256 => _256.content, 'optionalAccess', _257 => _257.parts]) || [];
5446
5706
  for (const part of parts) {
5447
5707
  if (part.functionCall) {
5448
5708
  logger.info("Function call detected", { functionCall: part.functionCall });
@@ -5452,13 +5712,13 @@ function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pend
5452
5712
  args: part.functionCall.args || {}
5453
5713
  };
5454
5714
  toolCalls.push(toolCall);
5455
- _optionalChain([callbacks, 'access', _252 => _252.onToolCall, 'optionalCall', _253 => _253(toolCall)]);
5715
+ _optionalChain([callbacks, 'access', _258 => _258.onToolCall, 'optionalCall', _259 => _259(toolCall)]);
5456
5716
  logger.info("Tool called", { toolName: toolCall.name });
5457
5717
  }
5458
5718
  }
5459
5719
  } else if (apiFormat !== "anthropic") {
5460
- const delta = _optionalChain([json, 'access', _254 => _254.choices, 'optionalAccess', _255 => _255[0], 'optionalAccess', _256 => _256.delta]);
5461
- if (_optionalChain([delta, 'optionalAccess', _257 => _257.tool_calls]) && pendingOpenAIToolCalls) {
5720
+ const delta = _optionalChain([json, 'access', _260 => _260.choices, 'optionalAccess', _261 => _261[0], 'optionalAccess', _262 => _262.delta]);
5721
+ if (_optionalChain([delta, 'optionalAccess', _263 => _263.tool_calls]) && pendingOpenAIToolCalls) {
5462
5722
  for (const tc of delta.tool_calls) {
5463
5723
  const index = _nullishCoalesce(tc.index, () => ( 0));
5464
5724
  let pending = pendingOpenAIToolCalls.get(index);
@@ -5467,8 +5727,8 @@ function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pend
5467
5727
  pendingOpenAIToolCalls.set(index, pending);
5468
5728
  }
5469
5729
  if (tc.id) pending.id = tc.id;
5470
- if (_optionalChain([tc, 'access', _258 => _258.function, 'optionalAccess', _259 => _259.name])) pending.name += tc.function.name;
5471
- if (_optionalChain([tc, 'access', _260 => _260.function, 'optionalAccess', _261 => _261.arguments])) pending.arguments += tc.function.arguments;
5730
+ if (_optionalChain([tc, 'access', _264 => _264.function, 'optionalAccess', _265 => _265.name])) pending.name += tc.function.name;
5731
+ if (_optionalChain([tc, 'access', _266 => _266.function, 'optionalAccess', _267 => _267.arguments])) pending.arguments += tc.function.arguments;
5472
5732
  }
5473
5733
  }
5474
5734
  }
@@ -5483,7 +5743,7 @@ function finalizeOpenAIToolCalls(pendingOpenAIToolCalls, toolCalls, callbacks, l
5483
5743
  args: JSON.parse(pending.arguments || "{}")
5484
5744
  };
5485
5745
  toolCalls.push(toolCall);
5486
- _optionalChain([callbacks, 'access', _262 => _262.onToolCall, 'optionalCall', _263 => _263(toolCall)]);
5746
+ _optionalChain([callbacks, 'access', _268 => _268.onToolCall, 'optionalCall', _269 => _269(toolCall)]);
5487
5747
  logger.info("Tool called (OpenAI)", { toolName: toolCall.name, args: toolCall.args });
5488
5748
  } catch (e) {
5489
5749
  logger.error("Failed to parse OpenAI tool call arguments", e instanceof Error ? e : void 0, {
@@ -5497,38 +5757,38 @@ function finalizeOpenAIToolCalls(pendingOpenAIToolCalls, toolCalls, callbacks, l
5497
5757
  function parseStreamChunk(rawJson, apiFormat, callbacks, logger) {
5498
5758
  const json = rawJson;
5499
5759
  if (apiFormat === "google") {
5500
- const candidate = _optionalChain([json, 'access', _264 => _264.candidates, 'optionalAccess', _265 => _265[0]]);
5760
+ const candidate = _optionalChain([json, 'access', _270 => _270.candidates, 'optionalAccess', _271 => _271[0]]);
5501
5761
  if (!candidate) {
5502
5762
  logger.warn("No candidate found in Gemini response");
5503
5763
  return;
5504
5764
  }
5505
- const parts = _optionalChain([candidate, 'access', _266 => _266.content, 'optionalAccess', _267 => _267.parts]) || [];
5765
+ const parts = _optionalChain([candidate, 'access', _272 => _272.content, 'optionalAccess', _273 => _273.parts]) || [];
5506
5766
  for (const part of parts) {
5507
5767
  if (part.thought === true && part.text) {
5508
- _optionalChain([callbacks, 'access', _268 => _268.onReasoning, 'optionalCall', _269 => _269(part.text)]);
5768
+ _optionalChain([callbacks, 'access', _274 => _274.onReasoning, 'optionalCall', _275 => _275(part.text)]);
5509
5769
  continue;
5510
5770
  } else if (part.thoughtSignature && !part.thought) {
5511
5771
  logger.debug("Gemini returned thoughtSignature without thought content");
5512
5772
  }
5513
5773
  if (part.text) {
5514
- _optionalChain([callbacks, 'access', _270 => _270.onDelta, 'optionalCall', _271 => _271(part.text)]);
5774
+ _optionalChain([callbacks, 'access', _276 => _276.onDelta, 'optionalCall', _277 => _277(part.text)]);
5515
5775
  }
5516
5776
  }
5517
5777
  } else if (apiFormat === "anthropic") {
5518
5778
  const delta = json.delta;
5519
- if (_optionalChain([delta, 'optionalAccess', _272 => _272.text])) {
5520
- _optionalChain([callbacks, 'access', _273 => _273.onDelta, 'optionalCall', _274 => _274(delta.text)]);
5779
+ if (_optionalChain([delta, 'optionalAccess', _278 => _278.text])) {
5780
+ _optionalChain([callbacks, 'access', _279 => _279.onDelta, 'optionalCall', _280 => _280(delta.text)]);
5521
5781
  }
5522
5782
  } else {
5523
- const delta = _optionalChain([json, 'access', _275 => _275.choices, 'optionalAccess', _276 => _276[0], 'optionalAccess', _277 => _277.delta]);
5524
- if (_optionalChain([delta, 'optionalAccess', _278 => _278.content])) {
5525
- _optionalChain([callbacks, 'access', _279 => _279.onDelta, 'optionalCall', _280 => _280(delta.content)]);
5783
+ const delta = _optionalChain([json, 'access', _281 => _281.choices, 'optionalAccess', _282 => _282[0], 'optionalAccess', _283 => _283.delta]);
5784
+ if (_optionalChain([delta, 'optionalAccess', _284 => _284.content])) {
5785
+ _optionalChain([callbacks, 'access', _285 => _285.onDelta, 'optionalCall', _286 => _286(delta.content)]);
5526
5786
  }
5527
- if (_optionalChain([delta, 'optionalAccess', _281 => _281.thinking, 'optionalAccess', _282 => _282.content])) {
5528
- _optionalChain([callbacks, 'access', _283 => _283.onReasoning, 'optionalCall', _284 => _284(delta.thinking.content)]);
5787
+ if (_optionalChain([delta, 'optionalAccess', _287 => _287.thinking, 'optionalAccess', _288 => _288.content])) {
5788
+ _optionalChain([callbacks, 'access', _289 => _289.onReasoning, 'optionalCall', _290 => _290(delta.thinking.content)]);
5529
5789
  }
5530
- if (_optionalChain([delta, 'optionalAccess', _285 => _285.reasoning_content])) {
5531
- _optionalChain([callbacks, 'access', _286 => _286.onReasoning, 'optionalCall', _287 => _287(delta.reasoning_content)]);
5790
+ if (_optionalChain([delta, 'optionalAccess', _291 => _291.reasoning_content])) {
5791
+ _optionalChain([callbacks, 'access', _292 => _292.onReasoning, 'optionalCall', _293 => _293(delta.reasoning_content)]);
5532
5792
  }
5533
5793
  }
5534
5794
  }
@@ -5541,7 +5801,7 @@ function buildIterationBlocks(iteration, content, reasoning, blocks, callbacks)
5541
5801
  content: reasoning
5542
5802
  };
5543
5803
  blocks.push(thinkingBlock);
5544
- _optionalChain([callbacks, 'access', _288 => _288.onBlock, 'optionalCall', _289 => _289(thinkingBlock)]);
5804
+ _optionalChain([callbacks, 'access', _294 => _294.onBlock, 'optionalCall', _295 => _295(thinkingBlock)]);
5545
5805
  }
5546
5806
  if (content && content.trim()) {
5547
5807
  const textBlock = {
@@ -5550,7 +5810,7 @@ function buildIterationBlocks(iteration, content, reasoning, blocks, callbacks)
5550
5810
  content
5551
5811
  };
5552
5812
  blocks.push(textBlock);
5553
- _optionalChain([callbacks, 'access', _290 => _290.onBlock, 'optionalCall', _291 => _291(textBlock)]);
5813
+ _optionalChain([callbacks, 'access', _296 => _296.onBlock, 'optionalCall', _297 => _297(textBlock)]);
5554
5814
  }
5555
5815
  }
5556
5816
  async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbacks, logger, builtinExecutor) {
@@ -5565,7 +5825,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
5565
5825
  status: "running"
5566
5826
  };
5567
5827
  blocks.push(toolUseBlock);
5568
- _optionalChain([callbacks, 'access', _292 => _292.onBlock, 'optionalCall', _293 => _293(toolUseBlock)]);
5828
+ _optionalChain([callbacks, 'access', _298 => _298.onBlock, 'optionalCall', _299 => _299(toolUseBlock)]);
5569
5829
  try {
5570
5830
  logger.info("Executing tool", { toolName: toolCall.name });
5571
5831
  const mcpTool = mcpTools.find((t) => t.id === toolCall.name);
@@ -5588,8 +5848,8 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
5588
5848
  result = { isError: true, content: [{ type: "text", text: "MCP service not available" }] };
5589
5849
  }
5590
5850
  logger.info("Tool result received", { result });
5591
- _optionalChain([callbacks, 'access', _294 => _294.onToolResult, 'optionalCall', _295 => _295(toolCall.id, result)]);
5592
- const resultText = _optionalChain([result, 'access', _296 => _296.content, 'optionalAccess', _297 => _297[0], 'optionalAccess', _298 => _298.text]) || JSON.stringify(result);
5851
+ _optionalChain([callbacks, 'access', _300 => _300.onToolResult, 'optionalCall', _301 => _301(toolCall.id, result)]);
5852
+ const resultText = _optionalChain([result, 'access', _302 => _302.content, 'optionalAccess', _303 => _303[0], 'optionalAccess', _304 => _304.text]) || JSON.stringify(result);
5593
5853
  const toolResultBlock = {
5594
5854
  id: `${toolCall.id}_result`,
5595
5855
  type: "tool_result",
@@ -5599,11 +5859,11 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
5599
5859
  isError: result.isError
5600
5860
  };
5601
5861
  blocks.push(toolResultBlock);
5602
- _optionalChain([callbacks, 'access', _299 => _299.onBlock, 'optionalCall', _300 => _300(toolResultBlock)]);
5862
+ _optionalChain([callbacks, 'access', _305 => _305.onBlock, 'optionalCall', _306 => _306(toolResultBlock)]);
5603
5863
  const toolUseBlockRef = blocks.find((b) => b.id === `${toolCall.id}_use`);
5604
5864
  if (toolUseBlockRef && toolUseBlockRef.type === "tool_use") {
5605
5865
  toolUseBlockRef.status = result.isError ? "error" : "completed";
5606
- _optionalChain([callbacks, 'access', _301 => _301.onBlock, 'optionalCall', _302 => _302({ ...toolUseBlockRef })]);
5866
+ _optionalChain([callbacks, 'access', _307 => _307.onBlock, 'optionalCall', _308 => _308({ ...toolUseBlockRef })]);
5607
5867
  }
5608
5868
  toolResults.push({ toolCall, result });
5609
5869
  } catch (error) {
@@ -5613,7 +5873,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
5613
5873
  isError: true,
5614
5874
  content: [{ type: "text", text: `Error: ${errorMessage}` }]
5615
5875
  };
5616
- _optionalChain([callbacks, 'access', _303 => _303.onToolResult, 'optionalCall', _304 => _304(toolCall.id, errorResult)]);
5876
+ _optionalChain([callbacks, 'access', _309 => _309.onToolResult, 'optionalCall', _310 => _310(toolCall.id, errorResult)]);
5617
5877
  const errorToolResultBlock = {
5618
5878
  id: `${toolCall.id}_result`,
5619
5879
  type: "tool_result",
@@ -5623,11 +5883,11 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
5623
5883
  isError: true
5624
5884
  };
5625
5885
  blocks.push(errorToolResultBlock);
5626
- _optionalChain([callbacks, 'access', _305 => _305.onBlock, 'optionalCall', _306 => _306(errorToolResultBlock)]);
5886
+ _optionalChain([callbacks, 'access', _311 => _311.onBlock, 'optionalCall', _312 => _312(errorToolResultBlock)]);
5627
5887
  const errorToolUseBlockRef = blocks.find((b) => b.id === `${toolCall.id}_use`);
5628
5888
  if (errorToolUseBlockRef && errorToolUseBlockRef.type === "tool_use") {
5629
5889
  errorToolUseBlockRef.status = "error";
5630
- _optionalChain([callbacks, 'access', _307 => _307.onBlock, 'optionalCall', _308 => _308({ ...errorToolUseBlockRef })]);
5890
+ _optionalChain([callbacks, 'access', _313 => _313.onBlock, 'optionalCall', _314 => _314({ ...errorToolUseBlockRef })]);
5631
5891
  }
5632
5892
  toolResults.push({ toolCall, result: errorResult });
5633
5893
  }
@@ -5637,7 +5897,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
5637
5897
  function mapToolArguments(args, mcpTool, logger) {
5638
5898
  const mappedArgs = { ...args };
5639
5899
  const toolSchema = mcpTool.inputSchema;
5640
- if (_optionalChain([toolSchema, 'optionalAccess', _309 => _309.properties])) {
5900
+ if (_optionalChain([toolSchema, 'optionalAccess', _315 => _315.properties])) {
5641
5901
  const expectedParams = Object.keys(toolSchema.properties);
5642
5902
  const paramMappings = {
5643
5903
  "search_query": ["query", "q", "searchQuery", "search"],
@@ -5671,25 +5931,25 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
5671
5931
  options.providerId,
5672
5932
  options.model
5673
5933
  );
5674
- const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _310 => _310.actualProviderId]) || options.providerId;
5675
- const actualModel = _optionalChain([routedInfo, 'optionalAccess', _311 => _311.actualModelId]) || options.model;
5934
+ const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _316 => _316.actualProviderId]) || options.providerId;
5935
+ const actualModel = _optionalChain([routedInfo, 'optionalAccess', _317 => _317.actualModelId]) || options.model;
5676
5936
  const provider = await getProvider(actualProviderId);
5677
5937
  if (!provider) {
5678
- _optionalChain([callbacks, 'access', _312 => _312.onError, 'optionalCall', _313 => _313(`Provider not found: ${actualProviderId}`)]);
5938
+ _optionalChain([callbacks, 'access', _318 => _318.onError, 'optionalCall', _319 => _319(`Provider not found: ${actualProviderId}`)]);
5679
5939
  return;
5680
5940
  }
5681
5941
  if (!provider.enabled) {
5682
- _optionalChain([callbacks, 'access', _314 => _314.onError, 'optionalCall', _315 => _315(`Provider is disabled: ${provider.name}`)]);
5942
+ _optionalChain([callbacks, 'access', _320 => _320.onError, 'optionalCall', _321 => _321(`Provider is disabled: ${provider.name}`)]);
5683
5943
  return;
5684
5944
  }
5685
5945
  const { apiKey: effectiveKey } = _chunkA2YMUCBTcjs.resolveProviderEndpoint.call(void 0, provider);
5686
5946
  const apiKey = resolveApiKey2(effectiveKey);
5687
5947
  if (!apiKey) {
5688
- _optionalChain([callbacks, 'access', _316 => _316.onError, 'optionalCall', _317 => _317("API key not configured")]);
5948
+ _optionalChain([callbacks, 'access', _322 => _322.onError, 'optionalCall', _323 => _323("API key not configured")]);
5689
5949
  return;
5690
5950
  }
5691
5951
  const messageId = `msg_${Date.now()}_${Math.random().toString(36).slice(2)}`;
5692
- _optionalChain([callbacks, 'access', _318 => _318.onStart, 'optionalCall', _319 => _319(messageId)]);
5952
+ _optionalChain([callbacks, 'access', _324 => _324.onStart, 'optionalCall', _325 => _325(messageId)]);
5693
5953
  const globalParams = await llmConfig.getGlobalModelParameters();
5694
5954
  const MAX_ITERATIONS = _nullishCoalesce(globalParams.toolMaxTurns, () => ( 100));
5695
5955
  let iteration = 0;
@@ -5736,12 +5996,12 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
5736
5996
  });
5737
5997
  if (!response.ok) {
5738
5998
  const errorText = await response.text();
5739
- _optionalChain([callbacks, 'access', _320 => _320.onError, 'optionalCall', _321 => _321(`API error (${response.status}): ${errorText}`)]);
5999
+ _optionalChain([callbacks, 'access', _326 => _326.onError, 'optionalCall', _327 => _327(`API error (${response.status}): ${errorText}`)]);
5740
6000
  return;
5741
6001
  }
5742
- const reader = _optionalChain([response, 'access', _322 => _322.body, 'optionalAccess', _323 => _323.getReader, 'call', _324 => _324()]);
6002
+ const reader = _optionalChain([response, 'access', _328 => _328.body, 'optionalAccess', _329 => _329.getReader, 'call', _330 => _330()]);
5743
6003
  if (!reader) {
5744
- _optionalChain([callbacks, 'access', _325 => _325.onError, 'optionalCall', _326 => _326("No response body")]);
6004
+ _optionalChain([callbacks, 'access', _331 => _331.onError, 'optionalCall', _332 => _332("No response body")]);
5745
6005
  return;
5746
6006
  }
5747
6007
  const decoder = new TextDecoder();
@@ -5774,7 +6034,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
5774
6034
  logger.debug("Parsed JSON", { json });
5775
6035
  if (json.error) {
5776
6036
  logger.error("API Error", void 0, { error: json.error });
5777
- _optionalChain([callbacks, 'access', _327 => _327.onError, 'optionalCall', _328 => _328(`API Error: ${json.error.message || JSON.stringify(json.error)}`)]);
6037
+ _optionalChain([callbacks, 'access', _333 => _333.onError, 'optionalCall', _334 => _334(`API Error: ${json.error.message || JSON.stringify(json.error)}`)]);
5778
6038
  return;
5779
6039
  }
5780
6040
  parseStreamChunk(json, apiFormat, callbacks, logger);
@@ -5807,7 +6067,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
5807
6067
  toolCallsLength: toolCalls.length,
5808
6068
  executableToolCallsLength: executableToolCalls.length,
5809
6069
  hasMcpTools: !!options.mcpTools,
5810
- mcpToolsLength: _optionalChain([options, 'access', _329 => _329.mcpTools, 'optionalAccess', _330 => _330.length]),
6070
+ mcpToolsLength: _optionalChain([options, 'access', _335 => _335.mcpTools, 'optionalAccess', _336 => _336.length]),
5811
6071
  hasMcpService: !!mcpService
5812
6072
  });
5813
6073
  if (executableToolCalls.length > 0 && options.mcpTools && (mcpService || builtinExecutor)) {
@@ -5828,7 +6088,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
5828
6088
  builtinExecutor
5829
6089
  );
5830
6090
  const toolResultsText = toolResults.map(({ toolCall, result }) => {
5831
- const resultText = typeof result === "string" ? result : _optionalChain([result, 'access', _331 => _331.content, 'optionalAccess', _332 => _332[0], 'optionalAccess', _333 => _333.text]) || JSON.stringify(result);
6091
+ const resultText = typeof result === "string" ? result : _optionalChain([result, 'access', _337 => _337.content, 'optionalAccess', _338 => _338[0], 'optionalAccess', _339 => _339.text]) || JSON.stringify(result);
5832
6092
  return `Tool ${toolCall.name} result:
5833
6093
  ${resultText}`;
5834
6094
  }).join("\n\n");
@@ -5846,12 +6106,12 @@ ${resultText}`;
5846
6106
  }
5847
6107
  } catch (streamError) {
5848
6108
  logger.error("Stream processing error", streamError instanceof Error ? streamError : void 0);
5849
- _optionalChain([callbacks, 'access', _334 => _334.onError, 'optionalCall', _335 => _335(`Stream error: ${streamError instanceof Error ? streamError.message : "Unknown error"}`)]);
6109
+ _optionalChain([callbacks, 'access', _340 => _340.onError, 'optionalCall', _341 => _341(`Stream error: ${streamError instanceof Error ? streamError.message : "Unknown error"}`)]);
5850
6110
  return;
5851
6111
  }
5852
6112
  }
5853
6113
  logger.info("Sending final callback", { blocksCount: blocks.length });
5854
- _optionalChain([callbacks, 'access', _336 => _336.onDone, 'optionalCall', _337 => _337({
6114
+ _optionalChain([callbacks, 'access', _342 => _342.onDone, 'optionalCall', _343 => _343({
5855
6115
  id: messageId,
5856
6116
  role: "assistant",
5857
6117
  content: finalContent,
@@ -5862,7 +6122,7 @@ ${resultText}`;
5862
6122
  } catch (error) {
5863
6123
  logger.error("Error in streamWithTools", error instanceof Error ? error : void 0);
5864
6124
  const message = error instanceof Error ? error.message : "Unknown error";
5865
- _optionalChain([callbacks, 'access', _338 => _338.onError, 'optionalCall', _339 => _339(message)]);
6125
+ _optionalChain([callbacks, 'access', _344 => _344.onError, 'optionalCall', _345 => _345(message)]);
5866
6126
  }
5867
6127
  }
5868
6128
 
@@ -5913,8 +6173,8 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
5913
6173
  options.providerId,
5914
6174
  options.model
5915
6175
  );
5916
- const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _340 => _340.actualProviderId]) || options.providerId;
5917
- const actualModel = _optionalChain([routedInfo, 'optionalAccess', _341 => _341.actualModelId]) || options.model;
6176
+ const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _346 => _346.actualProviderId]) || options.providerId;
6177
+ const actualModel = _optionalChain([routedInfo, 'optionalAccess', _347 => _347.actualModelId]) || options.model;
5918
6178
  const provider = await getProvider(actualProviderId);
5919
6179
  if (!provider) {
5920
6180
  return { success: false, error: `Provider not found: ${actualProviderId}` };
@@ -5990,18 +6250,18 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
5990
6250
  { endpointTransformer: void 0 }
5991
6251
  );
5992
6252
  const data = await transformedResponse.json();
5993
- const choice = _optionalChain([data, 'access', _342 => _342.choices, 'optionalAccess', _343 => _343[0]]);
6253
+ const choice = _optionalChain([data, 'access', _348 => _348.choices, 'optionalAccess', _349 => _349[0]]);
5994
6254
  if (!choice) {
5995
6255
  return { success: false, error: "No choices in response" };
5996
6256
  }
5997
- const rawToolCalls = _optionalChain([choice, 'access', _344 => _344.message, 'optionalAccess', _345 => _345.tool_calls]);
5998
- const toolCalls = _optionalChain([rawToolCalls, 'optionalAccess', _346 => _346.map, 'call', _347 => _347((tc) => ({
6257
+ const rawToolCalls = _optionalChain([choice, 'access', _350 => _350.message, 'optionalAccess', _351 => _351.tool_calls]);
6258
+ const toolCalls = _optionalChain([rawToolCalls, 'optionalAccess', _352 => _352.map, 'call', _353 => _353((tc) => ({
5999
6259
  id: tc.id,
6000
6260
  name: tc.function.name,
6001
6261
  args: typeof tc.function.arguments === "string" ? JSON.parse(tc.function.arguments) : tc.function.arguments
6002
6262
  }))]);
6003
6263
  const tapped = readUsageFromOpenAIResponse(data.usage);
6004
- if (_optionalChain([recording, 'optionalAccess', _348 => _348.recorder]) && tapped) {
6264
+ if (_optionalChain([recording, 'optionalAccess', _354 => _354.recorder]) && tapped) {
6005
6265
  recording.recorder.record({
6006
6266
  messageId: _nullishCoalesce(options.messageId, () => ( null)),
6007
6267
  parentMessageId: _nullishCoalesce(options.parentMessageId, () => ( null)),
@@ -6019,9 +6279,9 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
6019
6279
  message: {
6020
6280
  id: `msg_${Date.now()}`,
6021
6281
  role: "assistant",
6022
- content: _optionalChain([choice, 'access', _349 => _349.message, 'optionalAccess', _350 => _350.content]) || "",
6282
+ content: _optionalChain([choice, 'access', _355 => _355.message, 'optionalAccess', _356 => _356.content]) || "",
6023
6283
  timestamp: Date.now(),
6024
- thinking: data.reasoning_content || _optionalChain([choice, 'access', _351 => _351.message, 'optionalAccess', _352 => _352.thinking, 'optionalAccess', _353 => _353.content]) ? { content: data.reasoning_content || _optionalChain([choice, 'access', _354 => _354.message, 'optionalAccess', _355 => _355.thinking, 'optionalAccess', _356 => _356.content]) || "", signature: _optionalChain([choice, 'access', _357 => _357.message, 'optionalAccess', _358 => _358.thinking, 'optionalAccess', _359 => _359.signature]) } : void 0,
6284
+ thinking: data.reasoning_content || _optionalChain([choice, 'access', _357 => _357.message, 'optionalAccess', _358 => _358.thinking, 'optionalAccess', _359 => _359.content]) ? { content: data.reasoning_content || _optionalChain([choice, 'access', _360 => _360.message, 'optionalAccess', _361 => _361.thinking, 'optionalAccess', _362 => _362.content]) || "", signature: _optionalChain([choice, 'access', _363 => _363.message, 'optionalAccess', _364 => _364.thinking, 'optionalAccess', _365 => _365.signature]) } : void 0,
6025
6285
  toolCalls
6026
6286
  },
6027
6287
  usage: data.usage ? {
@@ -6042,21 +6302,21 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
6042
6302
  options.providerId,
6043
6303
  options.model
6044
6304
  );
6045
- const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _360 => _360.actualProviderId]) || options.providerId;
6046
- const actualModel = _optionalChain([routedInfo, 'optionalAccess', _361 => _361.actualModelId]) || options.model;
6305
+ const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _366 => _366.actualProviderId]) || options.providerId;
6306
+ const actualModel = _optionalChain([routedInfo, 'optionalAccess', _367 => _367.actualModelId]) || options.model;
6047
6307
  const provider = await getProvider(actualProviderId);
6048
6308
  if (!provider) {
6049
- _optionalChain([callbacks, 'access', _362 => _362.onError, 'optionalCall', _363 => _363(`Provider not found: ${actualProviderId}`)]);
6309
+ _optionalChain([callbacks, 'access', _368 => _368.onError, 'optionalCall', _369 => _369(`Provider not found: ${actualProviderId}`)]);
6050
6310
  return;
6051
6311
  }
6052
6312
  if (!provider.enabled) {
6053
- _optionalChain([callbacks, 'access', _364 => _364.onError, 'optionalCall', _365 => _365(`Provider is disabled: ${provider.name}`)]);
6313
+ _optionalChain([callbacks, 'access', _370 => _370.onError, 'optionalCall', _371 => _371(`Provider is disabled: ${provider.name}`)]);
6054
6314
  return;
6055
6315
  }
6056
6316
  const { apiKey: effectiveKey } = _chunkA2YMUCBTcjs.resolveProviderEndpoint.call(void 0, provider);
6057
6317
  const apiKey = resolveApiKey2(effectiveKey);
6058
6318
  if (!apiKey) {
6059
- _optionalChain([callbacks, 'access', _366 => _366.onError, 'optionalCall', _367 => _367("API key not configured")]);
6319
+ _optionalChain([callbacks, 'access', _372 => _372.onError, 'optionalCall', _373 => _373("API key not configured")]);
6060
6320
  return;
6061
6321
  }
6062
6322
  const { chain, hasTransformers } = await resolveChainWithMain(
@@ -6068,7 +6328,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
6068
6328
  return completeStreamFallback(options, callbacks);
6069
6329
  }
6070
6330
  const messageId = `msg_${Date.now()}`;
6071
- _optionalChain([callbacks, 'access', _368 => _368.onStart, 'optionalCall', _369 => _369(messageId)]);
6331
+ _optionalChain([callbacks, 'access', _374 => _374.onStart, 'optionalCall', _375 => _375(messageId)]);
6072
6332
  const unifiedRequest = buildUnifiedCompletionRequest(actualModel, options, true);
6073
6333
  const transformerProvider = {
6074
6334
  name: provider.name,
@@ -6107,7 +6367,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
6107
6367
  });
6108
6368
  if (!response.ok) {
6109
6369
  const errorText = await response.text();
6110
- _optionalChain([callbacks, 'access', _370 => _370.onError, 'optionalCall', _371 => _371(`API error (${response.status}): ${errorText}`)]);
6370
+ _optionalChain([callbacks, 'access', _376 => _376.onError, 'optionalCall', _377 => _377(`API error (${response.status}): ${errorText}`)]);
6111
6371
  return;
6112
6372
  }
6113
6373
  const transformedResponse = await executor.executeResponseChain(
@@ -6117,9 +6377,9 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
6117
6377
  chain,
6118
6378
  { endpointTransformer: void 0 }
6119
6379
  );
6120
- const reader = _optionalChain([transformedResponse, 'access', _372 => _372.body, 'optionalAccess', _373 => _373.getReader, 'call', _374 => _374()]);
6380
+ const reader = _optionalChain([transformedResponse, 'access', _378 => _378.body, 'optionalAccess', _379 => _379.getReader, 'call', _380 => _380()]);
6121
6381
  if (!reader) {
6122
- _optionalChain([callbacks, 'access', _375 => _375.onError, 'optionalCall', _376 => _376("No response body")]);
6382
+ _optionalChain([callbacks, 'access', _381 => _381.onError, 'optionalCall', _382 => _382("No response body")]);
6123
6383
  return;
6124
6384
  }
6125
6385
  const decoder = new TextDecoder();
@@ -6137,22 +6397,22 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
6137
6397
  if (data === "[DONE]") continue;
6138
6398
  try {
6139
6399
  const json = JSON.parse(data);
6140
- const delta = _optionalChain([json, 'access', _377 => _377.choices, 'optionalAccess', _378 => _378[0], 'optionalAccess', _379 => _379.delta]);
6141
- if (_optionalChain([delta, 'optionalAccess', _380 => _380.content])) {
6400
+ const delta = _optionalChain([json, 'access', _383 => _383.choices, 'optionalAccess', _384 => _384[0], 'optionalAccess', _385 => _385.delta]);
6401
+ if (_optionalChain([delta, 'optionalAccess', _386 => _386.content])) {
6142
6402
  content += delta.content;
6143
- _optionalChain([callbacks, 'access', _381 => _381.onDelta, 'optionalCall', _382 => _382(delta.content)]);
6403
+ _optionalChain([callbacks, 'access', _387 => _387.onDelta, 'optionalCall', _388 => _388(delta.content)]);
6144
6404
  }
6145
- if (_optionalChain([delta, 'optionalAccess', _383 => _383.thinking, 'optionalAccess', _384 => _384.content])) {
6405
+ if (_optionalChain([delta, 'optionalAccess', _389 => _389.thinking, 'optionalAccess', _390 => _390.content])) {
6146
6406
  reasoning += delta.thinking.content;
6147
- _optionalChain([callbacks, 'access', _385 => _385.onReasoning, 'optionalCall', _386 => _386(delta.thinking.content)]);
6407
+ _optionalChain([callbacks, 'access', _391 => _391.onReasoning, 'optionalCall', _392 => _392(delta.thinking.content)]);
6148
6408
  }
6149
- if (_optionalChain([delta, 'optionalAccess', _387 => _387.reasoning_content])) {
6409
+ if (_optionalChain([delta, 'optionalAccess', _393 => _393.reasoning_content])) {
6150
6410
  reasoning += delta.reasoning_content;
6151
- _optionalChain([callbacks, 'access', _388 => _388.onReasoning, 'optionalCall', _389 => _389(delta.reasoning_content)]);
6411
+ _optionalChain([callbacks, 'access', _394 => _394.onReasoning, 'optionalCall', _395 => _395(delta.reasoning_content)]);
6152
6412
  }
6153
6413
  if (json.usage) {
6154
6414
  const tapped = readUsageFromOpenAIResponse(json.usage);
6155
- if (_optionalChain([recording, 'optionalAccess', _390 => _390.recorder]) && tapped) {
6415
+ if (_optionalChain([recording, 'optionalAccess', _396 => _396.recorder]) && tapped) {
6156
6416
  recording.recorder.record({
6157
6417
  messageId: _nullishCoalesce(options.messageId, () => ( null)),
6158
6418
  parentMessageId: _nullishCoalesce(options.parentMessageId, () => ( null)),
@@ -6165,7 +6425,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
6165
6425
  rawUsage: json.usage
6166
6426
  });
6167
6427
  }
6168
- _optionalChain([callbacks, 'access', _391 => _391.onDone, 'optionalCall', _392 => _392(
6428
+ _optionalChain([callbacks, 'access', _397 => _397.onDone, 'optionalCall', _398 => _398(
6169
6429
  {
6170
6430
  id: messageId,
6171
6431
  role: "assistant",
@@ -6186,7 +6446,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
6186
6446
  }
6187
6447
  }
6188
6448
  }
6189
- _optionalChain([callbacks, 'access', _393 => _393.onDone, 'optionalCall', _394 => _394({
6449
+ _optionalChain([callbacks, 'access', _399 => _399.onDone, 'optionalCall', _400 => _400({
6190
6450
  id: messageId,
6191
6451
  role: "assistant",
6192
6452
  content,
@@ -6198,7 +6458,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
6198
6458
  }
6199
6459
  } catch (error) {
6200
6460
  const message = error instanceof Error ? error.message : "Unknown error";
6201
- _optionalChain([callbacks, 'access', _395 => _395.onError, 'optionalCall', _396 => _396(message)]);
6461
+ _optionalChain([callbacks, 'access', _401 => _401.onError, 'optionalCall', _402 => _402(message)]);
6202
6462
  }
6203
6463
  }
6204
6464
 
@@ -6265,8 +6525,8 @@ var CompletionService = (_class13 = class {
6265
6525
  options.providerId,
6266
6526
  options.model
6267
6527
  );
6268
- const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _397 => _397.actualProviderId]) || options.providerId;
6269
- const actualModel = _optionalChain([routedInfo, 'optionalAccess', _398 => _398.actualModelId]) || options.model;
6528
+ const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _403 => _403.actualProviderId]) || options.providerId;
6529
+ const actualModel = _optionalChain([routedInfo, 'optionalAccess', _404 => _404.actualModelId]) || options.model;
6270
6530
  const provider = await this.getProvider(actualProviderId);
6271
6531
  if (!provider) {
6272
6532
  return { success: false, error: `Provider not found: ${actualProviderId}` };
@@ -6299,7 +6559,7 @@ var CompletionService = (_class13 = class {
6299
6559
  this.apiKeyPool.reportSuccess(options.sessionId);
6300
6560
  }
6301
6561
  if (result.success && result.usage && options.sessionId) {
6302
- _optionalChain([this, 'access', _399 => _399.usageEventSink, 'optionalAccess', _400 => _400.emit, 'call', _401 => _401({
6562
+ _optionalChain([this, 'access', _405 => _405.usageEventSink, 'optionalAccess', _406 => _406.emit, 'call', _407 => _407({
6303
6563
  sessionId: options.sessionId,
6304
6564
  modelId: actualModel,
6305
6565
  usage: result.usage,
@@ -6328,8 +6588,8 @@ var CompletionService = (_class13 = class {
6328
6588
  options.model
6329
6589
  );
6330
6590
  this.logger.debug("Resolved routed model", { routedInfo });
6331
- const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _402 => _402.actualProviderId]) || options.providerId;
6332
- const actualModel = _optionalChain([routedInfo, 'optionalAccess', _403 => _403.actualModelId]) || options.model;
6591
+ const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _408 => _408.actualProviderId]) || options.providerId;
6592
+ const actualModel = _optionalChain([routedInfo, 'optionalAccess', _409 => _409.actualModelId]) || options.model;
6333
6593
  this.logger.debug("Resolved provider and model", { actualProviderId, actualModel });
6334
6594
  const provider = await this.getProvider(actualProviderId);
6335
6595
  this.logger.debug("Retrieved provider", provider ? {
@@ -6341,22 +6601,22 @@ var CompletionService = (_class13 = class {
6341
6601
  enabled: provider.enabled
6342
6602
  } : { error: "Provider not found" });
6343
6603
  if (!provider) {
6344
- _optionalChain([callbacks, 'access', _404 => _404.onError, 'optionalCall', _405 => _405(`Provider not found: ${actualProviderId}`)]);
6604
+ _optionalChain([callbacks, 'access', _410 => _410.onError, 'optionalCall', _411 => _411(`Provider not found: ${actualProviderId}`)]);
6345
6605
  return;
6346
6606
  }
6347
6607
  if (!provider.enabled) {
6348
- _optionalChain([callbacks, 'access', _406 => _406.onError, 'optionalCall', _407 => _407(`Provider is disabled: ${provider.name}`)]);
6608
+ _optionalChain([callbacks, 'access', _412 => _412.onError, 'optionalCall', _413 => _413(`Provider is disabled: ${provider.name}`)]);
6349
6609
  return;
6350
6610
  }
6351
6611
  const apiKey = await this.resolveApiKeyForRequest(provider, actualProviderId, options.sessionId);
6352
6612
  if (!apiKey) {
6353
- _optionalChain([callbacks, 'access', _408 => _408.onError, 'optionalCall', _409 => _409("API key not configured")]);
6613
+ _optionalChain([callbacks, 'access', _414 => _414.onError, 'optionalCall', _415 => _415("API key not configured")]);
6354
6614
  return;
6355
6615
  }
6356
6616
  const apiFormat = _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider);
6357
6617
  this.logger.info("Using API format for stream", { apiFormat });
6358
6618
  const messageId = `msg_${Date.now()}`;
6359
- _optionalChain([callbacks, 'access', _410 => _410.onStart, 'optionalCall', _411 => _411(messageId)]);
6619
+ _optionalChain([callbacks, 'access', _416 => _416.onStart, 'optionalCall', _417 => _417(messageId)]);
6360
6620
  const resolvedOptions = { ...options, model: actualModel };
6361
6621
  if (options.sessionId) {
6362
6622
  const sid = options.sessionId;
@@ -6365,14 +6625,14 @@ var CompletionService = (_class13 = class {
6365
6625
  ...callbacks,
6366
6626
  onDone: (message, usage, metrics) => {
6367
6627
  if (usage) {
6368
- _optionalChain([this, 'access', _412 => _412.usageEventSink, 'optionalAccess', _413 => _413.emit, 'call', _414 => _414({
6628
+ _optionalChain([this, 'access', _418 => _418.usageEventSink, 'optionalAccess', _419 => _419.emit, 'call', _420 => _420({
6369
6629
  sessionId: sid,
6370
6630
  modelId: actualModel,
6371
6631
  usage,
6372
6632
  engineOrigin: "completion"
6373
6633
  })]);
6374
6634
  }
6375
- _optionalChain([userOnDone, 'optionalCall', _415 => _415(message, usage, metrics)]);
6635
+ _optionalChain([userOnDone, 'optionalCall', _421 => _421(message, usage, metrics)]);
6376
6636
  }
6377
6637
  };
6378
6638
  }
@@ -6388,11 +6648,11 @@ var CompletionService = (_class13 = class {
6388
6648
  retryState.error = { status, message: error };
6389
6649
  return;
6390
6650
  }
6391
- _optionalChain([callbacks, 'access', _416 => _416.onError, 'optionalCall', _417 => _417(error)]);
6651
+ _optionalChain([callbacks, 'access', _422 => _422.onError, 'optionalCall', _423 => _423(error)]);
6392
6652
  },
6393
6653
  onDone: (message, usage, metrics) => {
6394
6654
  this.apiKeyPool.reportSuccess(options.sessionId);
6395
- _optionalChain([callbacks, 'access', _418 => _418.onDone, 'optionalCall', _419 => _419(message, usage, metrics)]);
6655
+ _optionalChain([callbacks, 'access', _424 => _424.onDone, 'optionalCall', _425 => _425(message, usage, metrics)]);
6396
6656
  }
6397
6657
  };
6398
6658
  await this.callStreamHandler(apiFormat, provider, apiKey, resolvedOptions, messageId, interceptCallbacks);
@@ -6413,7 +6673,7 @@ var CompletionService = (_class13 = class {
6413
6673
  // don't fire onStart again
6414
6674
  });
6415
6675
  } else {
6416
- _optionalChain([callbacks, 'access', _420 => _420.onError, 'optionalCall', _421 => _421(retryState.error.message)]);
6676
+ _optionalChain([callbacks, 'access', _426 => _426.onError, 'optionalCall', _427 => _427(retryState.error.message)]);
6417
6677
  }
6418
6678
  }
6419
6679
  } else {
@@ -6426,7 +6686,7 @@ var CompletionService = (_class13 = class {
6426
6686
  } catch (error) {
6427
6687
  const message = error instanceof Error ? error.message : "Unknown error";
6428
6688
  this.logger.error("Stream completion error", error instanceof Error ? error : void 0, { message });
6429
- _optionalChain([callbacks, 'access', _422 => _422.onError, 'optionalCall', _423 => _423(message)]);
6689
+ _optionalChain([callbacks, 'access', _428 => _428.onError, 'optionalCall', _429 => _429(message)]);
6430
6690
  }
6431
6691
  }
6432
6692
  /**
@@ -6466,7 +6726,7 @@ var CompletionService = (_class13 = class {
6466
6726
  return {
6467
6727
  success: true,
6468
6728
  message: "Connection successful",
6469
- response: _optionalChain([result, 'access', _424 => _424.message, 'optionalAccess', _425 => _425.content]) || "",
6729
+ response: _optionalChain([result, 'access', _430 => _430.message, 'optionalAccess', _431 => _431.content]) || "",
6470
6730
  model: modelId,
6471
6731
  durationMs
6472
6732
  };
@@ -6531,7 +6791,7 @@ ${description}`;
6531
6791
  * 3. Legacy single key from provider config
6532
6792
  */
6533
6793
  async resolveApiKeyForRequest(provider, providerId, sessionId) {
6534
- if (_optionalChain([provider, 'access', _426 => _426.codingPlan, 'optionalAccess', _427 => _427.enabled]) && provider.codingPlan.apiKey) {
6794
+ if (_optionalChain([provider, 'access', _432 => _432.codingPlan, 'optionalAccess', _433 => _433.enabled]) && provider.codingPlan.apiKey) {
6535
6795
  return this.resolveApiKey(provider.codingPlan.apiKey);
6536
6796
  }
6537
6797
  if (this.apiKeyPool) {