@omnicross/core 0.1.3 → 0.1.5

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 (141) hide show
  1. package/LICENSE +21 -21
  2. package/NOTICE +57 -57
  3. package/README.md +15 -15
  4. package/dist/auth/GeminiCodeAssistProjectResolver.cjs +6 -5
  5. package/dist/auth/GeminiCodeAssistProjectResolver.js +6 -5
  6. package/dist/{chunk-2DCNB7DF.cjs → chunk-3Q6Z6JTO.cjs} +154 -26
  7. package/dist/chunk-3QFXFCHG.js +33 -0
  8. package/dist/chunk-3Z5BQZFM.cjs +52 -0
  9. package/dist/{chunk-4VAVYUZS.cjs → chunk-4XMYPW46.cjs} +9 -9
  10. package/dist/chunk-4YINUUKQ.cjs +33 -0
  11. package/dist/{chunk-S4WBV25P.js → chunk-6QZGDLL4.js} +106 -23
  12. package/dist/{chunk-C72S6TTV.cjs → chunk-7FEBOPJO.cjs} +5 -4
  13. package/dist/chunk-APYG5QD7.cjs +50 -0
  14. package/dist/{chunk-5HTVET6E.js → chunk-BODMAL6G.js} +143 -15
  15. package/dist/{chunk-CWM2ZDU5.js → chunk-BPKCU575.js} +3 -10
  16. package/dist/{chunk-2FMI2B6V.cjs → chunk-CGKLE6IW.cjs} +350 -461
  17. package/dist/{chunk-BO4RFWBR.js → chunk-D3TDKWRP.js} +84 -3
  18. package/dist/{chunk-RSJ3TWJQ.cjs → chunk-DDMRUL76.cjs} +5 -5
  19. package/dist/chunk-FCR77GYM.cjs +33 -0
  20. package/dist/{chunk-4DECIFU7.js → chunk-FH2P4OCD.js} +178 -289
  21. package/dist/{chunk-N5QFKSDO.js → chunk-HRRYG2AX.js} +2 -1
  22. package/dist/{chunk-KUU2RNG6.cjs → chunk-HYN75H6G.cjs} +3 -0
  23. package/dist/{chunk-Z7LUNECE.js → chunk-IB3FDI4O.js} +5 -4
  24. package/dist/chunk-IFXJ2BG7.js +109 -0
  25. package/dist/{chunk-JO5NLTLY.js → chunk-IK3KE3AU.js} +3 -0
  26. package/dist/{chunk-C7PSERMH.js → chunk-IWQAX3CS.js} +1 -1
  27. package/dist/{chunk-YGXJGRFI.cjs → chunk-JWVTXXPX.cjs} +106 -23
  28. package/dist/{chunk-7YN22L2H.cjs → chunk-K52THW2C.cjs} +5 -5
  29. package/dist/chunk-K5NM7VAH.js +33 -0
  30. package/dist/{chunk-Y6OM7EV7.cjs → chunk-KFI44N2R.cjs} +2 -1
  31. package/dist/{chunk-Z7Y2NPHY.js → chunk-MFZ5437A.js} +1 -1
  32. package/dist/chunk-OE6TDIWW.js +22 -0
  33. package/dist/{chunk-MQNDWYPN.js → chunk-OQWKZCXP.js} +13 -6
  34. package/dist/chunk-OZFM4X3S.js +18 -0
  35. package/dist/chunk-PG7PS2NN.cjs +170 -0
  36. package/dist/{chunk-3QOSDDNI.cjs → chunk-SNYBEXLB.cjs} +6 -13
  37. package/dist/chunk-SYQF7OIR.js +52 -0
  38. package/dist/{chunk-CZHZGRU7.js → chunk-UHGVBFU3.js} +2 -0
  39. package/dist/chunk-UIBD2YY5.cjs +22 -0
  40. package/dist/chunk-UNWKG6EI.cjs +109 -0
  41. package/dist/{chunk-SVXC36MU.cjs → chunk-VACWOIRE.cjs} +2 -0
  42. package/dist/chunk-WLYIIEAF.js +50 -0
  43. package/dist/chunk-XSVNC2UD.cjs +18 -0
  44. package/dist/{chunk-FFALUUZZ.cjs → chunk-ZCIQ3L3R.cjs} +18 -11
  45. package/dist/completion/CompletionService.cjs +26 -19
  46. package/dist/completion/CompletionService.js +25 -18
  47. package/dist/completion.cjs +28 -21
  48. package/dist/completion.js +27 -20
  49. package/dist/index.cjs +35 -25
  50. package/dist/index.d.cts +7 -3
  51. package/dist/index.d.ts +7 -3
  52. package/dist/index.js +44 -34
  53. package/dist/keyPolicy-Cp0FntZl.d.cts +90 -0
  54. package/dist/keyPolicy-Cp0FntZl.d.ts +90 -0
  55. package/dist/outbound-api/auditCapture.cjs +9 -0
  56. package/dist/outbound-api/auditCapture.d.cts +54 -0
  57. package/dist/outbound-api/auditCapture.d.ts +54 -0
  58. package/dist/outbound-api/auditCapture.js +9 -0
  59. package/dist/outbound-api/auditRedact.cjs +8 -0
  60. package/dist/outbound-api/auditRedact.d.cts +30 -0
  61. package/dist/outbound-api/auditRedact.d.ts +30 -0
  62. package/dist/outbound-api/auditRedact.js +8 -0
  63. package/dist/outbound-api/billingCapture.cjs +8 -0
  64. package/dist/outbound-api/billingCapture.d.cts +61 -0
  65. package/dist/outbound-api/billingCapture.d.ts +61 -0
  66. package/dist/outbound-api/billingCapture.js +8 -0
  67. package/dist/outbound-api/quotaWarn.cjs +12 -0
  68. package/dist/outbound-api/quotaWarn.d.cts +43 -0
  69. package/dist/outbound-api/quotaWarn.d.ts +43 -0
  70. package/dist/outbound-api/quotaWarn.js +12 -0
  71. package/dist/outbound-api/routeResolver.cjs +2 -2
  72. package/dist/outbound-api/routeResolver.d.cts +3 -2
  73. package/dist/outbound-api/routeResolver.d.ts +3 -2
  74. package/dist/outbound-api/routeResolver.js +1 -1
  75. package/dist/outbound-api/types.d.cts +2 -1
  76. package/dist/outbound-api/types.d.ts +2 -1
  77. package/dist/outbound-api.cjs +33 -23
  78. package/dist/outbound-api.d.cts +9 -140
  79. package/dist/outbound-api.d.ts +9 -140
  80. package/dist/outbound-api.js +32 -22
  81. package/dist/pipeline/AuthSource.d.cts +6 -0
  82. package/dist/pipeline/AuthSource.d.ts +6 -0
  83. package/dist/pipeline/SubscriptionAuthSource.cjs +2 -2
  84. package/dist/pipeline/SubscriptionAuthSource.js +1 -1
  85. package/dist/pipeline/SubscriptionAuthStrategy.d.cts +6 -0
  86. package/dist/pipeline/SubscriptionAuthStrategy.d.ts +6 -0
  87. package/dist/pipeline/auditUsageStash.cjs +10 -0
  88. package/dist/pipeline/auditUsageStash.d.cts +37 -0
  89. package/dist/pipeline/auditUsageStash.d.ts +37 -0
  90. package/dist/pipeline/auditUsageStash.js +10 -0
  91. package/dist/pipeline/executeProviderCall.cjs +2 -2
  92. package/dist/pipeline/executeProviderCall.js +1 -1
  93. package/dist/pipeline/upstreamFetch.cjs +15 -0
  94. package/dist/pipeline/upstreamFetch.d.cts +89 -0
  95. package/dist/pipeline/upstreamFetch.d.ts +89 -0
  96. package/dist/pipeline/upstreamFetch.js +15 -0
  97. package/dist/pipeline/upstreamTrace.cjs +14 -0
  98. package/dist/pipeline/upstreamTrace.d.cts +85 -0
  99. package/dist/pipeline/upstreamTrace.d.ts +85 -0
  100. package/dist/pipeline/upstreamTrace.js +14 -0
  101. package/dist/pipeline/webhookEmit.cjs +10 -0
  102. package/dist/pipeline/webhookEmit.d.cts +36 -0
  103. package/dist/pipeline/webhookEmit.d.ts +36 -0
  104. package/dist/pipeline/webhookEmit.js +10 -0
  105. package/dist/ports.d.cts +2 -1
  106. package/dist/ports.d.ts +2 -1
  107. package/dist/provider-proxy/ProviderProxy.cjs +26 -19
  108. package/dist/provider-proxy/ProviderProxy.js +25 -18
  109. package/dist/provider-proxy/ingress/providerProxyShared.cjs +28 -19
  110. package/dist/provider-proxy/ingress/providerProxyShared.d.cts +17 -1
  111. package/dist/provider-proxy/ingress/providerProxyShared.d.ts +17 -1
  112. package/dist/provider-proxy/ingress/providerProxyShared.js +27 -18
  113. package/dist/provider-proxy/types.d.cts +7 -0
  114. package/dist/provider-proxy/types.d.ts +7 -0
  115. package/dist/provider-proxy.cjs +26 -19
  116. package/dist/provider-proxy.js +25 -18
  117. package/dist/{routeResolver-B1NglTfe.d.ts → routeResolver-C4T7yClx.d.ts} +1 -1
  118. package/dist/{routeResolver-CbG5uBgm.d.cts → routeResolver-CB3tvJKy.d.cts} +1 -1
  119. package/dist/transformer/transformers/AnthropicTransformer.cjs +2 -2
  120. package/dist/transformer/transformers/AnthropicTransformer.js +1 -1
  121. package/dist/transformer/transformers/GeminiCodeAssistTransformer.cjs +3 -3
  122. package/dist/transformer/transformers/GeminiCodeAssistTransformer.js +2 -2
  123. package/dist/transformer/transformers/GeminiTransformer.cjs +3 -3
  124. package/dist/transformer/transformers/GeminiTransformer.js +2 -2
  125. package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +2 -2
  126. package/dist/transformer/transformers/OpenAIResponseTransformer.js +1 -1
  127. package/dist/transformer/transformers/OpenCodeGoTransformer.cjs +2 -2
  128. package/dist/transformer/transformers/OpenCodeGoTransformer.js +1 -1
  129. package/dist/transformer/transformers.cjs +8 -8
  130. package/dist/transformer/transformers.js +7 -7
  131. package/dist/transformer.cjs +8 -8
  132. package/dist/transformer.js +7 -7
  133. package/dist/{types-aBFFXoBz.d.cts → types-B8Arpxn0.d.cts} +14 -90
  134. package/dist/{types-6OUY_xfA.d.ts → types-lgPYQuZS.d.ts} +14 -90
  135. package/dist/usage/usage-recorder.cjs +3 -2
  136. package/dist/usage/usage-recorder.js +2 -1
  137. package/dist/usage.cjs +3 -2
  138. package/dist/usage.js +2 -1
  139. package/package.json +64 -64
  140. package/dist/chunk-S6JGLF3G.cjs +0 -89
  141. package/dist/{chunk-FTQ7IQUC.js → chunk-C6OV7GCC.js} +8 -8
@@ -6,16 +6,13 @@ var _chunkHQP3K7PUcjs = require('./chunk-HQP3K7PU.cjs');
6
6
  var _chunk46ZIFWYGcjs = require('./chunk-46ZIFWYG.cjs');
7
7
 
8
8
 
9
- var _chunk4VAVYUZScjs = require('./chunk-4VAVYUZS.cjs');
9
+ var _chunk4XMYPW46cjs = require('./chunk-4XMYPW46.cjs');
10
10
 
11
11
 
12
- var _chunk7YN22L2Hcjs = require('./chunk-7YN22L2H.cjs');
12
+ var _chunkK52THW2Ccjs = require('./chunk-K52THW2C.cjs');
13
13
 
14
14
 
15
- var _chunk2DCNB7DFcjs = require('./chunk-2DCNB7DF.cjs');
16
-
17
-
18
- var _chunk3QOSDDNIcjs = require('./chunk-3QOSDDNI.cjs');
15
+ var _chunk3Q6Z6JTOcjs = require('./chunk-3Q6Z6JTO.cjs');
19
16
 
20
17
 
21
18
  var _chunkGBHYAGX3cjs = require('./chunk-GBHYAGX3.cjs');
@@ -32,60 +29,65 @@ var _chunk6RPZADX3cjs = require('./chunk-6RPZADX3.cjs');
32
29
  var _chunkQWBWGODScjs = require('./chunk-QWBWGODS.cjs');
33
30
 
34
31
 
35
- var _chunkNYUNU75Acjs = require('./chunk-NYUNU75A.cjs');
32
+ var _chunkUIBD2YY5cjs = require('./chunk-UIBD2YY5.cjs');
36
33
 
37
34
 
35
+ var _chunkR3HK6R4Bcjs = require('./chunk-R3HK6R4B.cjs');
38
36
 
39
- var _chunkVQY5W4YWcjs = require('./chunk-VQY5W4YW.cjs');
40
37
 
38
+ var _chunkHYN75H6Gcjs = require('./chunk-HYN75H6G.cjs');
41
39
 
42
- var _chunkY6OM7EV7cjs = require('./chunk-Y6OM7EV7.cjs');
43
40
 
44
41
 
45
- var _chunkSVNDB62Dcjs = require('./chunk-SVNDB62D.cjs');
42
+ var _chunkQ27JY5RGcjs = require('./chunk-Q27JY5RG.cjs');
46
43
 
47
44
 
48
- var _chunkR3HK6R4Bcjs = require('./chunk-R3HK6R4B.cjs');
45
+ var _chunkQXD4MV2Xcjs = require('./chunk-QXD4MV2X.cjs');
49
46
 
50
47
 
48
+ var _chunkNYUNU75Acjs = require('./chunk-NYUNU75A.cjs');
51
49
 
52
- var _chunkAEOZIDEBcjs = require('./chunk-AEOZIDEB.cjs');
53
50
 
54
51
 
52
+ var _chunkVQY5W4YWcjs = require('./chunk-VQY5W4YW.cjs');
55
53
 
56
- var _chunkL74VDN4Acjs = require('./chunk-L74VDN4A.cjs');
57
54
 
55
+ var _chunkKFI44N2Rcjs = require('./chunk-KFI44N2R.cjs');
58
56
 
59
- var _chunkKUU2RNG6cjs = require('./chunk-KUU2RNG6.cjs');
60
57
 
58
+ var _chunkSVNDB62Dcjs = require('./chunk-SVNDB62D.cjs');
61
59
 
62
60
 
63
- var _chunkQ27JY5RGcjs = require('./chunk-Q27JY5RG.cjs');
61
+ var _chunkAPYG5QD7cjs = require('./chunk-APYG5QD7.cjs');
64
62
 
65
63
 
66
- var _chunkQXD4MV2Xcjs = require('./chunk-QXD4MV2X.cjs');
67
64
 
65
+ var _chunk4YINUUKQcjs = require('./chunk-4YINUUKQ.cjs');
68
66
 
69
67
 
70
68
 
71
- var _chunkA2YMUCBTcjs = require('./chunk-A2YMUCBT.cjs');
72
69
 
73
70
 
74
71
 
75
72
 
76
73
 
77
74
 
75
+ var _chunkVACWOIREcjs = require('./chunk-VACWOIRE.cjs');
78
76
 
79
77
 
80
78
 
81
- var _chunkSVXC36MUcjs = require('./chunk-SVXC36MU.cjs');
79
+
80
+ var _chunkA2YMUCBTcjs = require('./chunk-A2YMUCBT.cjs');
81
+
82
+
83
+ var _chunkUNWKG6EIcjs = require('./chunk-UNWKG6EI.cjs');
82
84
 
83
85
 
84
86
 
85
87
  var _chunkSUEGJ75Dcjs = require('./chunk-SUEGJ75D.cjs');
86
88
 
87
89
 
88
- var _chunkS6JGLF3Gcjs = require('./chunk-S6JGLF3G.cjs');
90
+ var _chunkPG7PS2NNcjs = require('./chunk-PG7PS2NN.cjs');
89
91
 
90
92
 
91
93
  var _chunkJMJBSACDcjs = require('./chunk-JMJBSACD.cjs');
@@ -515,17 +517,17 @@ function getSharedExecutor() {
515
517
  }
516
518
  var sharedResponses = null;
517
519
  function getResponsesEndpointTransformer() {
518
- if (!sharedResponses) sharedResponses = new (0, _chunk2DCNB7DFcjs.OpenAIResponseTransformer)();
520
+ if (!sharedResponses) sharedResponses = new (0, _chunk3Q6Z6JTOcjs.OpenAIResponseTransformer)();
519
521
  return sharedResponses;
520
522
  }
521
523
  var sharedAnthropic = null;
522
524
  function getAnthropicEndpointTransformer() {
523
- if (!sharedAnthropic) sharedAnthropic = new (0, _chunk4VAVYUZScjs.AnthropicTransformer)();
525
+ if (!sharedAnthropic) sharedAnthropic = new (0, _chunk4XMYPW46cjs.AnthropicTransformer)();
524
526
  return sharedAnthropic;
525
527
  }
526
528
  var sharedGemini = null;
527
529
  function getGeminiEndpointTransformer() {
528
- if (!sharedGemini) sharedGemini = new (0, _chunk7YN22L2Hcjs.GeminiTransformer)();
530
+ if (!sharedGemini) sharedGemini = new (0, _chunkK52THW2Ccjs.GeminiTransformer)();
529
531
  return sharedGemini;
530
532
  }
531
533
  function readBody(req) {
@@ -649,6 +651,95 @@ async function relayResponse(res, providerResponse, isStream, rewriteModel) {
649
651
  res.end(clientText);
650
652
  return bodyText;
651
653
  }
654
+ async function aggregateAnthropicSseToJsonBody(response, rewriteModel) {
655
+ const text = await response.text();
656
+ const message = {
657
+ type: "message",
658
+ role: "assistant",
659
+ content: [],
660
+ stop_reason: null,
661
+ stop_sequence: null,
662
+ usage: {}
663
+ };
664
+ const blocks = /* @__PURE__ */ new Map();
665
+ for (const raw of text.split("\n")) {
666
+ const line = raw.trim();
667
+ if (!line.startsWith("data:")) continue;
668
+ const payload = line.slice(5).trim();
669
+ if (!payload || payload === "[DONE]") continue;
670
+ let ev;
671
+ try {
672
+ ev = JSON.parse(payload);
673
+ } catch (e7) {
674
+ continue;
675
+ }
676
+ switch (ev["type"]) {
677
+ case "message_start": {
678
+ const m = _nullishCoalesce(ev["message"], () => ( {}));
679
+ if (typeof m["id"] === "string") message["id"] = m["id"];
680
+ if (typeof m["model"] === "string") message["model"] = m["model"];
681
+ if (m["usage"]) message["usage"] = { ...m["usage"] };
682
+ break;
683
+ }
684
+ case "content_block_start": {
685
+ const idx = Number(ev["index"]);
686
+ const cb = _nullishCoalesce(ev["content_block"], () => ( {}));
687
+ blocks.set(idx, {
688
+ type: typeof cb["type"] === "string" ? cb["type"] : "text",
689
+ text: typeof cb["text"] === "string" ? cb["text"] : "",
690
+ id: typeof cb["id"] === "string" ? cb["id"] : void 0,
691
+ name: typeof cb["name"] === "string" ? cb["name"] : void 0,
692
+ inputJson: ""
693
+ });
694
+ break;
695
+ }
696
+ case "content_block_delta": {
697
+ const b = blocks.get(Number(ev["index"]));
698
+ if (!b) break;
699
+ const d = _nullishCoalesce(ev["delta"], () => ( {}));
700
+ if (d["type"] === "text_delta" && typeof d["text"] === "string") b.text += d["text"];
701
+ else if (d["type"] === "input_json_delta" && typeof d["partial_json"] === "string")
702
+ b.inputJson += d["partial_json"];
703
+ else if (d["type"] === "thinking_delta" && typeof d["thinking"] === "string")
704
+ b.text += d["thinking"];
705
+ else if (d["type"] === "signature_delta" && typeof d["signature"] === "string")
706
+ b.signature = (b.signature || "") + d["signature"];
707
+ break;
708
+ }
709
+ case "message_delta": {
710
+ const d = _nullishCoalesce(ev["delta"], () => ( {}));
711
+ if (d["stop_reason"] !== void 0) message["stop_reason"] = d["stop_reason"];
712
+ if (d["stop_sequence"] !== void 0) message["stop_sequence"] = d["stop_sequence"];
713
+ if (ev["usage"])
714
+ message["usage"] = { ...message["usage"], ...ev["usage"] };
715
+ break;
716
+ }
717
+ default:
718
+ break;
719
+ }
720
+ }
721
+ message["content"] = [...blocks.keys()].sort((a, b) => a - b).map((idx) => {
722
+ const blk = blocks.get(idx);
723
+ if (!blk) return void 0;
724
+ if (blk.type === "tool_use") {
725
+ let input = {};
726
+ try {
727
+ input = blk.inputJson ? JSON.parse(blk.inputJson) : {};
728
+ } catch (e8) {
729
+ input = {};
730
+ }
731
+ return { type: "tool_use", id: _nullishCoalesce(blk.id, () => ( "")), name: _nullishCoalesce(blk.name, () => ( "")), input };
732
+ }
733
+ if (blk.type === "thinking") {
734
+ const out = { type: "thinking", thinking: blk.text };
735
+ if (blk.signature) out.signature = blk.signature;
736
+ return out;
737
+ }
738
+ return { type: blk.type || "text", text: blk.text };
739
+ }).filter((b) => b !== void 0);
740
+ if (rewriteModel) message["model"] = rewriteModel;
741
+ return JSON.stringify(message);
742
+ }
652
743
  function writeError(res, status, message) {
653
744
  if (res.headersSent) return;
654
745
  res.writeHead(status, { "Content-Type": "application/json" });
@@ -695,7 +786,7 @@ async function buildSubscriptionPlan(res, route, deps, anthropicBody, routeModel
695
786
  function buildSubscriptionIterationPlan(profile, route, deps, resolvedModel, isStream, scenario, sessionKey) {
696
787
  const upstreamUrl = _optionalChain([profile, 'access', _8 => _8.resolveUpstreamUrl, 'optionalCall', _9 => _9(resolvedModel, route.subscriptionConfig)]);
697
788
  if (!upstreamUrl) return null;
698
- const auth = _nullishCoalesce(route.auth, () => ( new (0, _chunkY6OM7EV7cjs.SubscriptionAuthSource)(profile)));
789
+ const auth = _nullishCoalesce(route.auth, () => ( new (0, _chunkKFI44N2Rcjs.SubscriptionAuthSource)(profile)));
699
790
  const sameFormat = profile.mode === "pass-through" || upstreamUrl.endsWith("/v1/messages");
700
791
  const overrideNames = _optionalChain([profile, 'access', _10 => _10.resolveProviderTransformerNames, 'optionalCall', _11 => _11(
701
792
  resolvedModel,
@@ -715,6 +806,7 @@ function buildSubscriptionIterationPlan(profile, route, deps, resolvedModel, isS
715
806
  };
716
807
  return {
717
808
  auth,
809
+ preferredAccountId: route.preferredAccountId,
718
810
  chain,
719
811
  transformerProvider,
720
812
  resolvedModel,
@@ -788,13 +880,14 @@ async function runPipeline(anthropicBody, plan, reportSelection) {
788
880
  upstreamUrl,
789
881
  model: resolvedModel,
790
882
  sessionKey: plan.sessionKey,
883
+ preferredAccountId: plan.preferredAccountId,
791
884
  reportSelection: (accountId, isActive) => {
792
885
  proxyAccountId = accountId;
793
886
  _optionalChain([reportSelection, 'optionalCall', _12 => _12(accountId, isActive)]);
794
887
  }
795
888
  });
796
889
  let rawStatus = null;
797
- const { response } = await _chunkKUU2RNG6cjs.executeProviderCall.call(void 0, {
890
+ const { response } = await _chunkHYN75H6Gcjs.executeProviderCall.call(void 0, {
798
891
  executor,
799
892
  request: anthropicBody,
800
893
  provider: transformerProvider,
@@ -812,7 +905,7 @@ async function runPipeline(anthropicBody, plan, reportSelection) {
812
905
  },
813
906
  fetchFn: (url, headers, body) => {
814
907
  console.info(`[ProviderProxy:anthropic] -> ${url} model=${resolvedModel} stream=${isStream}`);
815
- return _chunkS6JGLF3Gcjs.fetchUpstream.call(void 0,
908
+ return _chunkPG7PS2NNcjs.fetchUpstream.call(void 0,
816
909
  url,
817
910
  { method: "POST", headers, body: JSON.stringify(body) },
818
911
  { providerId: proxyProviderId(plan), accountId: proxyAccountId }
@@ -833,6 +926,7 @@ async function runSubscriptionSameFormatFetch(rawBody, plan, reportSelection, op
833
926
  upstreamUrl: plan.upstreamUrl,
834
927
  model: plan.resolvedModel,
835
928
  sessionKey: plan.sessionKey,
929
+ preferredAccountId: plan.preferredAccountId,
836
930
  reportSelection: (accountId, isActive, remapped) => {
837
931
  proxyAccountId = accountId;
838
932
  remappedModel = remapped;
@@ -854,7 +948,7 @@ async function runSubscriptionSameFormatFetch(rawBody, plan, reportSelection, op
854
948
  console.info(
855
949
  `[ProviderProxy:anthropic] (subscription same-format) -> ${plan.upstreamUrl} model=${outboundModel} stream=${plan.isStream}`
856
950
  );
857
- const response = await _chunkS6JGLF3Gcjs.fetchUpstream.call(void 0,
951
+ const response = await _chunkPG7PS2NNcjs.fetchUpstream.call(void 0,
858
952
  plan.upstreamUrl,
859
953
  { method: "POST", headers, body: outboundBody },
860
954
  { providerId: proxyProviderId(plan), accountId: proxyAccountId }
@@ -870,7 +964,7 @@ function rewriteBodyModel(rawBody, model) {
870
964
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return rawBody;
871
965
  parsed.model = model;
872
966
  return JSON.stringify(parsed);
873
- } catch (e7) {
967
+ } catch (e9) {
874
968
  return rawBody;
875
969
  }
876
970
  }
@@ -898,7 +992,7 @@ async function readBoundedBody(response, max = 2048) {
898
992
  try {
899
993
  const text = await response.clone().text();
900
994
  return text.slice(0, max);
901
- } catch (e8) {
995
+ } catch (e10) {
902
996
  return void 0;
903
997
  }
904
998
  }
@@ -1009,7 +1103,7 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
1009
1103
  let anthropicBody;
1010
1104
  try {
1011
1105
  anthropicBody = JSON.parse(rawBody);
1012
- } catch (e9) {
1106
+ } catch (e11) {
1013
1107
  writeError(res, 400, "Invalid JSON in request body");
1014
1108
  return;
1015
1109
  }
@@ -1021,7 +1115,21 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
1021
1115
  if (!plan) return;
1022
1116
  anthropicBody.model = plan.resolvedModel;
1023
1117
  const providerResponse = route.authMode === "subscription" ? await runPipelineWithSubscriptionRetry(anthropicBody, rawBody, plan, route, deps, options) : await runPipelineWithPoolReporting(anthropicBody, rawBody, plan, options);
1024
- const bodyText = await relayResponse(res, providerResponse.response, isStream, route.requestedModel);
1118
+ const upstreamResponse = providerResponse.response;
1119
+ const upstreamSse = (_nullishCoalesce(upstreamResponse.headers.get("content-type"), () => ( ""))).includes(
1120
+ "text/event-stream"
1121
+ );
1122
+ let bodyText;
1123
+ if (!isStream && upstreamSse) {
1124
+ bodyText = await aggregateAnthropicSseToJsonBody(upstreamResponse, route.requestedModel);
1125
+ res.writeHead(
1126
+ upstreamResponse.status && upstreamResponse.status >= 100 ? upstreamResponse.status : 200,
1127
+ { "Content-Type": "application/json" }
1128
+ );
1129
+ res.end(bodyText);
1130
+ } else {
1131
+ bodyText = await relayResponse(res, upstreamResponse, isStream, route.requestedModel);
1132
+ }
1025
1133
  if (bodyText && deps.usageRecorder) {
1026
1134
  recordAnthropicNonStreamUsage(deps.usageRecorder, bodyText, {
1027
1135
  sessionId: route.sessionId,
@@ -1106,7 +1214,7 @@ async function runSameFormatFetch(bodyToSend, plan, options, keyOverride) {
1106
1214
  _chunkGBHYAGX3cjs.injectExtendedContextBeta.call(void 0, headers, resolvedModel, _nullishCoalesce(extendedContextEnabled, () => ( false)));
1107
1215
  const url = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: resolvedModel, stream: isStream });
1108
1216
  console.info(`[ProviderProxy:anthropic] (same-format) -> ${url} model=${resolvedModel} stream=${isStream}`);
1109
- const response = await _chunkS6JGLF3Gcjs.fetchUpstream.call(void 0,
1217
+ const response = await _chunkPG7PS2NNcjs.fetchUpstream.call(void 0,
1110
1218
  url,
1111
1219
  { method: "POST", headers, body: bodyToSend },
1112
1220
  { providerId: "byo" }
@@ -1118,7 +1226,7 @@ function resolveSameFormatBody(anthropicBody, rawBody, plan) {
1118
1226
  try {
1119
1227
  const m = JSON.parse(rawBody).model;
1120
1228
  originalModel = typeof m === "string" ? m : void 0;
1121
- } catch (e10) {
1229
+ } catch (e12) {
1122
1230
  originalModel = void 0;
1123
1231
  }
1124
1232
  return plan.resolvedModel !== originalModel ? JSON.stringify(anthropicBody) : rawBody;
@@ -1218,7 +1326,7 @@ function recordGeminiNonStreamUsage(recorder, bodyText, attribution) {
1218
1326
  usage: tapped,
1219
1327
  rawUsage: parsed.usageMetadata
1220
1328
  });
1221
- } catch (e11) {
1329
+ } catch (e13) {
1222
1330
  }
1223
1331
  }
1224
1332
 
@@ -1242,7 +1350,7 @@ async function handleGeminiGenerateContentRequest(res, rawBody, url, route, deps
1242
1350
  let geminiBody;
1243
1351
  try {
1244
1352
  geminiBody = JSON.parse(rawBody);
1245
- } catch (e12) {
1353
+ } catch (e14) {
1246
1354
  writeError(res, 400, "Invalid JSON in request body");
1247
1355
  return;
1248
1356
  }
@@ -1323,7 +1431,7 @@ async function runPipeline2(geminiBody, plan) {
1323
1431
  const authHeaders = {};
1324
1432
  await auth.applyHeaders(authHeaders, { upstreamUrl, model: resolvedModel });
1325
1433
  let rawStatus = null;
1326
- const { response } = await _chunkKUU2RNG6cjs.executeProviderCall.call(void 0, {
1434
+ const { response } = await _chunkHYN75H6Gcjs.executeProviderCall.call(void 0, {
1327
1435
  executor,
1328
1436
  request: geminiBody,
1329
1437
  provider: transformerProvider,
@@ -1341,7 +1449,7 @@ async function runPipeline2(geminiBody, plan) {
1341
1449
  },
1342
1450
  fetchFn: (url, headers, body) => {
1343
1451
  console.log(`[ProviderProxy:gemini] -> ${url} model=${resolvedModel} stream=${isStream}`);
1344
- return _chunkS6JGLF3Gcjs.fetchUpstream.call(void 0,
1452
+ return _chunkPG7PS2NNcjs.fetchUpstream.call(void 0,
1345
1453
  url,
1346
1454
  { method: "POST", headers, body: JSON.stringify(body) },
1347
1455
  { providerId: "byo" }
@@ -1403,7 +1511,7 @@ function recordChatCompletionsNonStreamUsage(recorder, bodyText, attribution) {
1403
1511
  usage: tapped,
1404
1512
  rawUsage: parsed.usage
1405
1513
  });
1406
- } catch (e13) {
1514
+ } catch (e15) {
1407
1515
  }
1408
1516
  }
1409
1517
 
@@ -1419,7 +1527,7 @@ async function handleOpenAIChatRequest(res, rawBody, route, deps) {
1419
1527
  let chatBody;
1420
1528
  try {
1421
1529
  chatBody = JSON.parse(rawBody);
1422
- } catch (e14) {
1530
+ } catch (e16) {
1423
1531
  writeError(res, 400, "Invalid JSON in request body");
1424
1532
  return;
1425
1533
  }
@@ -1510,7 +1618,7 @@ async function buildSubscriptionPlan2(res, route, deps, resolvedModel, isStream)
1510
1618
  writeError(res, 502, "Subscription profile is missing resolveUpstreamUrl");
1511
1619
  return null;
1512
1620
  }
1513
- const auth = _nullishCoalesce(route.auth, () => ( new (0, _chunkY6OM7EV7cjs.SubscriptionAuthSource)(profile)));
1621
+ const auth = _nullishCoalesce(route.auth, () => ( new (0, _chunkKFI44N2Rcjs.SubscriptionAuthSource)(profile)));
1514
1622
  const chain = _chunkNYUNU75Acjs.resolveSubscriptionChain.call(void 0,
1515
1623
  profile,
1516
1624
  deps.llmConfig.getTransformerService(),
@@ -1547,7 +1655,7 @@ async function runPipeline3(chatBody, plan) {
1547
1655
  }
1548
1656
  });
1549
1657
  let rawStatus = null;
1550
- const { response } = await _chunkKUU2RNG6cjs.executeProviderCall.call(void 0, {
1658
+ const { response } = await _chunkHYN75H6Gcjs.executeProviderCall.call(void 0, {
1551
1659
  executor,
1552
1660
  request: chatBody,
1553
1661
  provider: transformerProvider,
@@ -1564,7 +1672,7 @@ async function runPipeline3(chatBody, plan) {
1564
1672
  },
1565
1673
  fetchFn: (url, headers, body) => {
1566
1674
  console.log(`[ProviderProxy:chat] -> ${url} model=${resolvedModel} stream=${isStream}`);
1567
- return _chunkS6JGLF3Gcjs.fetchUpstream.call(void 0,
1675
+ return _chunkPG7PS2NNcjs.fetchUpstream.call(void 0,
1568
1676
  url,
1569
1677
  { method: "POST", headers, body: JSON.stringify(body) },
1570
1678
  { providerId: plan.proxyProviderId, accountId: proxyAccountId }
@@ -1637,7 +1745,7 @@ function recordResponsesNonStreamUsage(recorder, bodyText, attribution) {
1637
1745
  usage: tapped,
1638
1746
  rawUsage: parsed.usage
1639
1747
  });
1640
- } catch (e15) {
1748
+ } catch (e17) {
1641
1749
  }
1642
1750
  }
1643
1751
 
@@ -1651,7 +1759,7 @@ async function handleOpenAIResponsesRequest(res, rawBody, route, deps) {
1651
1759
  let responsesBody;
1652
1760
  try {
1653
1761
  responsesBody = JSON.parse(rawBody);
1654
- } catch (e16) {
1762
+ } catch (e18) {
1655
1763
  writeError(res, 400, "Invalid JSON in request body");
1656
1764
  return;
1657
1765
  }
@@ -1732,7 +1840,7 @@ async function buildSubscriptionPlan3(res, route, deps, resolvedModel, isStream)
1732
1840
  writeError(res, 502, "Subscription profile is missing resolveUpstreamUrl");
1733
1841
  return null;
1734
1842
  }
1735
- const auth = _nullishCoalesce(route.auth, () => ( new (0, _chunkY6OM7EV7cjs.SubscriptionAuthSource)(profile)));
1843
+ const auth = _nullishCoalesce(route.auth, () => ( new (0, _chunkKFI44N2Rcjs.SubscriptionAuthSource)(profile)));
1736
1844
  const chain = _chunkNYUNU75Acjs.resolveSubscriptionChain.call(void 0,
1737
1845
  profile,
1738
1846
  deps.llmConfig.getTransformerService(),
@@ -1754,6 +1862,7 @@ async function buildSubscriptionPlan3(res, route, deps, resolvedModel, isStream)
1754
1862
  }
1755
1863
  return {
1756
1864
  auth,
1865
+ preferredAccountId: route.preferredAccountId,
1757
1866
  chain,
1758
1867
  transformerProvider,
1759
1868
  resolvedModel,
@@ -1785,12 +1894,13 @@ async function runPipeline4(responsesBody, plan) {
1785
1894
  await auth.applyHeaders(authHeaders, {
1786
1895
  upstreamUrl,
1787
1896
  model: resolvedModel,
1897
+ preferredAccountId: plan.preferredAccountId,
1788
1898
  reportSelection: (accountId) => {
1789
1899
  proxyAccountId = accountId;
1790
1900
  }
1791
1901
  });
1792
1902
  let rawStatus = null;
1793
- const { response } = await _chunkKUU2RNG6cjs.executeProviderCall.call(void 0, {
1903
+ const { response } = await _chunkHYN75H6Gcjs.executeProviderCall.call(void 0, {
1794
1904
  executor,
1795
1905
  request: responsesBody,
1796
1906
  provider: transformerProvider,
@@ -1808,7 +1918,7 @@ async function runPipeline4(responsesBody, plan) {
1808
1918
  },
1809
1919
  fetchFn: (url, headers, body) => {
1810
1920
  console.log(`[ProviderProxy:responses] -> ${url} model=${resolvedModel} stream=${isStream}`);
1811
- return _chunkS6JGLF3Gcjs.fetchUpstream.call(void 0,
1921
+ return _chunkPG7PS2NNcjs.fetchUpstream.call(void 0,
1812
1922
  url,
1813
1923
  { method: "POST", headers, body: JSON.stringify(body) },
1814
1924
  { providerId: plan.proxyProviderId, accountId: proxyAccountId }
@@ -2044,17 +2154,6 @@ var KeyedMutex = (_class3 = class {constructor() { _class3.prototype.__init4.cal
2044
2154
  // src/outbound-api/outboundApiRouter.ts
2045
2155
  var _stream = require('stream');
2046
2156
 
2047
- // src/pipeline/webhookEmit.ts
2048
- var sink = null;
2049
- function emitWebhookEvent(event) {
2050
- const active = sink;
2051
- if (!active) return;
2052
- try {
2053
- active(event);
2054
- } catch (e17) {
2055
- }
2056
- }
2057
-
2058
2157
  // src/outbound-api/apiServerConfig.ts
2059
2158
  var _audittypes = require('@omnicross/contracts/audit-types');
2060
2159
  var _billingtypes = require('@omnicross/contracts/billing-types');
@@ -2261,11 +2360,11 @@ function normalizeQueueSegments(raw) {
2261
2360
  var ALL_ENDPOINTS = ["chat", "responses", "messages", "gemini"];
2262
2361
  function blankModelMap(endpoint) {
2263
2362
  const modelMap = {};
2264
- for (const kind of _chunkSVXC36MUcjs.modelKindsForEndpoint.call(void 0, endpoint)) modelMap[kind] = "";
2363
+ for (const kind of _chunkVACWOIREcjs.modelKindsForEndpoint.call(void 0, endpoint)) modelMap[kind] = "";
2265
2364
  return modelMap;
2266
2365
  }
2267
2366
  function defaultEndpointConfig(endpoint) {
2268
- if (_chunkSVXC36MUcjs.isKindMappedEndpoint.call(void 0, endpoint)) {
2367
+ if (_chunkVACWOIREcjs.isKindMappedEndpoint.call(void 0, endpoint)) {
2269
2368
  return { endpoint, modelMap: blankModelMap(endpoint), useSubscription: false };
2270
2369
  }
2271
2370
  if (endpoint === "chat") {
@@ -2291,34 +2390,38 @@ function normalizePrefixTargets(raw) {
2291
2390
  function normalizeEndpointConfig(e) {
2292
2391
  const endpoint = e.endpoint;
2293
2392
  const useSubscription = e.useSubscription === true;
2294
- if (_chunkSVXC36MUcjs.isKindMappedEndpoint.call(void 0, endpoint)) {
2393
+ const boundAccountId = typeof e.boundAccountId === "string" && e.boundAccountId.trim() !== "" ? e.boundAccountId : void 0;
2394
+ const boundKeyId = typeof e.boundKeyId === "string" && e.boundKeyId.trim() !== "" ? e.boundKeyId : void 0;
2395
+ let config;
2396
+ if (_chunkVACWOIREcjs.isKindMappedEndpoint.call(void 0, endpoint)) {
2295
2397
  const rawMap = e.modelMap && typeof e.modelMap === "object" ? e.modelMap : {};
2296
2398
  const modelMap = {};
2297
- for (const kind of _chunkSVXC36MUcjs.modelKindsForEndpoint.call(void 0, endpoint)) {
2399
+ for (const kind of _chunkVACWOIREcjs.modelKindsForEndpoint.call(void 0, endpoint)) {
2298
2400
  const v = rawMap[kind];
2299
2401
  modelMap[kind] = typeof v === "string" ? v : "";
2300
2402
  }
2301
- return { endpoint, modelMap, useSubscription };
2302
- }
2303
- if (endpoint === "chat") {
2403
+ config = { endpoint, modelMap, useSubscription };
2404
+ } else if (endpoint === "chat") {
2304
2405
  const models = Array.isArray(e.models) ? e.models.filter((m) => typeof m === "string" && m.trim() !== "") : [];
2305
- const config2 = { endpoint, models, useSubscription };
2406
+ config = { endpoint, models, useSubscription };
2306
2407
  if (e.dispatchMode === "prefix") {
2307
- config2.dispatchMode = "prefix";
2408
+ config.dispatchMode = "prefix";
2308
2409
  const targets = normalizePrefixTargets(e.prefixTargets);
2309
- if (targets) config2.prefixTargets = targets;
2410
+ if (targets) config.prefixTargets = targets;
2411
+ }
2412
+ } else {
2413
+ config = {
2414
+ endpoint,
2415
+ defaultModel: typeof e.defaultModel === "string" ? e.defaultModel : "",
2416
+ backgroundModel: typeof e.backgroundModel === "string" ? e.backgroundModel : "",
2417
+ useSubscription
2418
+ };
2419
+ if (Array.isArray(e.backgroundModelIds)) {
2420
+ config.backgroundModelIds = e.backgroundModelIds;
2310
2421
  }
2311
- return config2;
2312
- }
2313
- const config = {
2314
- endpoint,
2315
- defaultModel: typeof e.defaultModel === "string" ? e.defaultModel : "",
2316
- backgroundModel: typeof e.backgroundModel === "string" ? e.backgroundModel : "",
2317
- useSubscription
2318
- };
2319
- if (Array.isArray(e.backgroundModelIds)) {
2320
- config.backgroundModelIds = e.backgroundModelIds;
2321
2422
  }
2423
+ if (boundAccountId) config.boundAccountId = boundAccountId;
2424
+ if (boundKeyId) config.boundKeyId = boundKeyId;
2322
2425
  return config;
2323
2426
  }
2324
2427
  function defaultServerConfig() {
@@ -2406,204 +2509,6 @@ function mergeServerConfig(current, patch) {
2406
2509
  });
2407
2510
  }
2408
2511
 
2409
- // src/outbound-api/auditCapture.ts
2410
-
2411
-
2412
- // src/outbound-api/auditRedact.ts
2413
- var AUDIT_REDACTED = "***REDACTED***";
2414
- var RULES = [
2415
- // `sk-…` family (Anthropic sk-ant-, omnicross sk-omnicross-, OpenAI sk-proj-/sk-).
2416
- { re: /\bsk-[A-Za-z0-9_-]{6,}/g, replace: AUDIT_REDACTED },
2417
- // Google API keys.
2418
- { re: /\bAIza[A-Za-z0-9_-]{10,}/g, replace: AUDIT_REDACTED },
2419
- // `Bearer <token>` (auth headers echoed into a body / SSE error).
2420
- { re: /\bBearer\s+[A-Za-z0-9._~+/=-]{6,}/gi, replace: `Bearer ${AUDIT_REDACTED}` },
2421
- // Inline `x-api-key` / `api-key` / `authorization` label followed by a value.
2422
- {
2423
- re: /\b(x-api-key|api[_-]?key|authorization)(["']?\s*[:=]\s*["']?)[A-Za-z0-9._~+/=-]{6,}/gi,
2424
- replace: `$1$2${AUDIT_REDACTED}`
2425
- },
2426
- // `x-goog-api-key` header echoed inline.
2427
- {
2428
- re: /\b(x-goog-api-key)(["']?\s*[:=]\s*["']?)[A-Za-z0-9._~+/=-]{6,}/gi,
2429
- replace: `$1$2${AUDIT_REDACTED}`
2430
- }
2431
- ];
2432
- function redactAuditText(text) {
2433
- if (typeof text !== "string" || text.length === 0) return _nullishCoalesce(text, () => ( ""));
2434
- let out = text;
2435
- for (const { re, replace } of RULES) {
2436
- out = out.replace(re, replace);
2437
- }
2438
- return out;
2439
- }
2440
-
2441
- // src/outbound-api/auditCapture.ts
2442
- function isStreamingContentType(res) {
2443
- const ct = res.getHeader("content-type");
2444
- const value = Array.isArray(ct) ? ct.join(";") : String(_nullishCoalesce(ct, () => ( "")));
2445
- return value.toLowerCase().includes("text/event-stream");
2446
- }
2447
- function resolveClientIp(req, trustForwardedFor) {
2448
- if (trustForwardedFor) {
2449
- const xff = req.headers["x-forwarded-for"];
2450
- const raw = Array.isArray(xff) ? xff[0] : xff;
2451
- if (typeof raw === "string" && raw.trim()) {
2452
- const first = _optionalChain([raw, 'access', _105 => _105.split, 'call', _106 => _106(","), 'access', _107 => _107[0], 'optionalAccess', _108 => _108.trim, 'call', _109 => _109()]);
2453
- if (first) return first;
2454
- }
2455
- }
2456
- return _nullishCoalesce(_optionalChain([req, 'access', _110 => _110.socket, 'optionalAccess', _111 => _111.remoteAddress]), () => ( void 0));
2457
- }
2458
- function truncateToBytes(text, maxBytes) {
2459
- const buf = Buffer.from(text, "utf8");
2460
- if (buf.length <= maxBytes) return text;
2461
- return buf.subarray(0, maxBytes).toString("utf8");
2462
- }
2463
- function beginAuditCapture(req, res, now) {
2464
- const config = _chunkAEOZIDEBcjs.getAuditCaptureConfig.call(void 0, );
2465
- if (!config) return null;
2466
- let rawRequestBody;
2467
- const responseChunks = [];
2468
- let responseBytes = 0;
2469
- let streamDetected = false;
2470
- let finished = false;
2471
- const ctx = {
2472
- setRequestBody(raw) {
2473
- if (config.captureBodies) rawRequestBody = raw;
2474
- }
2475
- };
2476
- if (config.captureBodies) {
2477
- installResponseCapture(res, config.maxBodyBytes, {
2478
- push(chunk) {
2479
- responseBytes += chunk.length;
2480
- responseChunks.push(chunk);
2481
- },
2482
- get bytes() {
2483
- return responseBytes;
2484
- },
2485
- markStream() {
2486
- streamDetected = true;
2487
- },
2488
- get isStream() {
2489
- return streamDetected;
2490
- }
2491
- });
2492
- }
2493
- const finalize = () => {
2494
- if (finished) return;
2495
- finished = true;
2496
- try {
2497
- const record = {
2498
- id: _crypto.randomUUID.call(void 0, ),
2499
- ts: now,
2500
- method: _nullishCoalesce(req.method, () => ( "")),
2501
- path: _nullishCoalesce((_nullishCoalesce(req.url, () => ( ""))).split("?")[0], () => ( "")),
2502
- status: res.statusCode,
2503
- latencyMs: Math.max(0, Date.now() - now)
2504
- };
2505
- if (ctx.keyId != null) record.keyId = ctx.keyId;
2506
- const ip = resolveClientIp(req, config.trustForwardedFor);
2507
- if (ip) record.ip = ip;
2508
- const ua = req.headers["user-agent"];
2509
- if (typeof ua === "string" && ua) record.ua = ua;
2510
- if (ctx.model) record.model = ctx.model;
2511
- if (ctx.provider) record.provider = ctx.provider;
2512
- const usage = _chunk3QOSDDNIcjs.readAuditUsage.call(void 0, res);
2513
- if (usage) {
2514
- if (typeof usage.inputTokens === "number") record.inputTokens = usage.inputTokens;
2515
- if (typeof usage.outputTokens === "number") record.outputTokens = usage.outputTokens;
2516
- if (typeof usage.costUsd === "number") record.costUsd = usage.costUsd;
2517
- if (!record.model && usage.model) record.model = usage.model;
2518
- if (!record.provider && usage.provider) record.provider = usage.provider;
2519
- }
2520
- if (ctx.error) record.error = redactAuditText(ctx.error);
2521
- if (config.captureBodies) {
2522
- if (rawRequestBody != null && rawRequestBody.length > 0) {
2523
- record.requestBody = redactAuditText(truncateToBytes(rawRequestBody, config.maxBodyBytes));
2524
- }
2525
- if (!streamDetected && responseChunks.length > 0) {
2526
- const body = Buffer.concat(responseChunks).toString("utf8");
2527
- record.responseBody = redactAuditText(body);
2528
- }
2529
- }
2530
- _chunkAEOZIDEBcjs.recordAudit.call(void 0, record);
2531
- } catch (e18) {
2532
- }
2533
- };
2534
- res.once("close", finalize);
2535
- return ctx;
2536
- }
2537
- function installResponseCapture(res, maxBodyBytes, sink2) {
2538
- let contentTypeChecked = false;
2539
- const capture = (chunk) => {
2540
- if (sink2.isStream) return;
2541
- if (!contentTypeChecked) {
2542
- contentTypeChecked = true;
2543
- if (isStreamingContentType(res)) {
2544
- sink2.markStream();
2545
- return;
2546
- }
2547
- }
2548
- if (sink2.bytes >= maxBodyBytes) return;
2549
- let buf = null;
2550
- if (Buffer.isBuffer(chunk)) buf = chunk;
2551
- else if (typeof chunk === "string") buf = Buffer.from(chunk, "utf8");
2552
- if (!buf || buf.length === 0) return;
2553
- const remaining = maxBodyBytes - sink2.bytes;
2554
- sink2.push(buf.length > remaining ? buf.subarray(0, remaining) : buf);
2555
- };
2556
- const originalWrite = res.write.bind(res);
2557
- const originalEnd = res.end.bind(res);
2558
- res.write = ((chunk, ...args) => {
2559
- if (chunk != null) capture(chunk);
2560
- return originalWrite(chunk, ...args);
2561
- });
2562
- res.end = ((chunk, ...args) => {
2563
- if (chunk != null && typeof chunk !== "function") capture(chunk);
2564
- return originalEnd(chunk, ...args);
2565
- });
2566
- }
2567
-
2568
- // src/outbound-api/billingCapture.ts
2569
-
2570
- var defaultDefer = (fn) => {
2571
- setTimeout(fn, 0);
2572
- };
2573
- function beginBillingCapture(_req, res, now, defer = defaultDefer) {
2574
- if (!_chunkL74VDN4Acjs.getBillingCaptureConfig.call(void 0, )) return null;
2575
- const ctx = {};
2576
- let finished = false;
2577
- const finalize = () => {
2578
- if (finished) return;
2579
- finished = true;
2580
- const status = res.statusCode;
2581
- defer(() => {
2582
- try {
2583
- const usage = _chunk3QOSDDNIcjs.readAuditUsage.call(void 0, res);
2584
- if (!usage) return;
2585
- const event = {
2586
- id: _crypto.randomUUID.call(void 0, ),
2587
- ts: now,
2588
- model: _nullishCoalesce(_nullishCoalesce(ctx.model, () => ( usage.model)), () => ( "")),
2589
- authMode: _nullishCoalesce(ctx.authMode, () => ( "byo")),
2590
- inputTokens: _nullishCoalesce(usage.inputTokens, () => ( 0)),
2591
- outputTokens: _nullishCoalesce(usage.outputTokens, () => ( 0)),
2592
- costUsd: _nullishCoalesce(usage.costUsd, () => ( 0)),
2593
- status
2594
- };
2595
- if (ctx.keyId != null) event.keyId = ctx.keyId;
2596
- const provider = _nullishCoalesce(ctx.provider, () => ( usage.provider));
2597
- if (provider) event.provider = provider;
2598
- _chunkL74VDN4Acjs.publishBillingEvent.call(void 0, event);
2599
- } catch (e19) {
2600
- }
2601
- });
2602
- };
2603
- res.once("close", finalize);
2604
- return ctx;
2605
- }
2606
-
2607
2512
  // src/outbound-api/outboundApiKeyAuth.ts
2608
2513
 
2609
2514
 
@@ -2752,30 +2657,6 @@ async function verifyPresentedKey(db, presentedKey) {
2752
2657
  return result.status === "ok" ? result.key : null;
2753
2658
  }
2754
2659
 
2755
- // src/outbound-api/quotaWarn.ts
2756
- var WEBHOOK_QUOTA_WARN_RATIO = 0.8;
2757
- function computeQuotaWarnings(limits, spend, ratio = WEBHOOK_QUOTA_WARN_RATIO) {
2758
- const out = [];
2759
- const consider = (scope, limit, spent, windowStart) => {
2760
- if (limit == null || limit <= 0) return;
2761
- if (spent >= limit) return;
2762
- if (spent >= ratio * limit) out.push({ scope, limitUsd: limit, spentUsd: spent, windowStart });
2763
- };
2764
- consider("daily", limits.dailyUsd, spend.dailyUsd, spend.dailyWindowStart);
2765
- consider("weekly", limits.weeklyUsd, spend.weeklyUsd, spend.weeklyWindowStart);
2766
- consider("total", limits.totalUsd, spend.totalUsd, 0);
2767
- return out;
2768
- }
2769
- var WARN_GUARD_MAX = 1e4;
2770
- var warned = /* @__PURE__ */ new Set();
2771
- function markQuotaWarnedOnce(keyId, scope, windowStart) {
2772
- const key = `${keyId}\0${scope}\0${windowStart}`;
2773
- if (warned.has(key)) return false;
2774
- if (warned.size >= WARN_GUARD_MAX) warned.clear();
2775
- warned.add(key);
2776
- return true;
2777
- }
2778
-
2779
2660
  // src/outbound-api/outboundConcurrencyGate.ts
2780
2661
  var ConcurrencyQueueFullError = (_class4 = class extends Error {
2781
2662
  constructor(apiKeyId, maxQueueSize) {
@@ -2962,8 +2843,8 @@ var OutboundRateLimiter = (_class8 = class {
2962
2843
  * recorded (no bucket growth).
2963
2844
  */
2964
2845
  check(apiKeyId, now = Date.now(), override) {
2965
- const maxRequests = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _112 => _112.maxRequests]), () => ( this.maxRequests));
2966
- const windowMs = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _113 => _113.windowMs]), () => ( this.windowMs));
2846
+ const maxRequests = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _105 => _105.maxRequests]), () => ( this.maxRequests));
2847
+ const windowMs = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _106 => _106.windowMs]), () => ( this.windowMs));
2967
2848
  if (maxRequests === 0) return { allowed: true, retryAfterSeconds: 0 };
2968
2849
  const cutoff = now - windowMs;
2969
2850
  const timestamps = (_nullishCoalesce(this.hits.get(apiKeyId), () => ( []))).filter((ts) => ts > cutoff);
@@ -3008,7 +2889,7 @@ function isUserMessageAnthropic(body) {
3008
2889
  if (typeof content === "string") return true;
3009
2890
  if (Array.isArray(content)) {
3010
2891
  const hasToolResult = content.some(
3011
- (block) => _optionalChain([asObject, 'call', _114 => _114(block), 'optionalAccess', _115 => _115["type"]]) === "tool_result"
2892
+ (block) => _optionalChain([asObject, 'call', _107 => _107(block), 'optionalAccess', _108 => _108["type"]]) === "tool_result"
3012
2893
  );
3013
2894
  return !hasToolResult;
3014
2895
  }
@@ -3037,7 +2918,7 @@ function isUserMessageGemini(body) {
3037
2918
  if (!lastContent || lastContent["role"] !== "user") return false;
3038
2919
  const parts = asArray(lastContent["parts"]);
3039
2920
  const hasFunctionResponse = parts.some(
3040
- (part) => _optionalChain([asObject, 'call', _116 => _116(part), 'optionalAccess', _117 => _117["functionResponse"]]) !== void 0
2921
+ (part) => _optionalChain([asObject, 'call', _109 => _109(part), 'optionalAccess', _110 => _110["functionResponse"]]) !== void 0
3041
2922
  );
3042
2923
  return !hasFunctionResponse;
3043
2924
  }
@@ -3211,14 +3092,14 @@ function newVoucherId() {
3211
3092
  }
3212
3093
  function computeVoucherGrant(voucher, currentKey, now) {
3213
3094
  if (voucher.type === "credit") {
3214
- const current = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _118 => _118.totalCostLimitUsd]), () => ( 0));
3095
+ const current = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _111 => _111.totalCostLimitUsd]), () => ( 0));
3215
3096
  let granted2 = current + (_nullishCoalesce(voucher.creditUsd, () => ( 0)));
3216
3097
  if (voucher.maxTotalCostLimitUsd != null) {
3217
3098
  granted2 = Math.min(granted2, voucher.maxTotalCostLimitUsd);
3218
3099
  }
3219
3100
  return { totalCostLimitUsd: granted2 };
3220
3101
  }
3221
- const currentExpiry = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _119 => _119.expiresAt]), () => ( now));
3102
+ const currentExpiry = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _112 => _112.expiresAt]), () => ( now));
3222
3103
  let granted = currentExpiry + (_nullishCoalesce(voucher.renewalDays, () => ( 0))) * DAY_MS2;
3223
3104
  if (voucher.maxExpiryDays != null) {
3224
3105
  granted = Math.min(granted, now + voucher.maxExpiryDays * DAY_MS2);
@@ -3249,7 +3130,7 @@ function toVoucherInfo(v) {
3249
3130
  // src/outbound-api/voucherRedeem.ts
3250
3131
  function isRedeemRequest(method, url) {
3251
3132
  if (method !== "POST" || !url) return false;
3252
- const path = _nullishCoalesce(_optionalChain([url, 'access', _120 => _120.split, 'call', _121 => _121("?"), 'access', _122 => _122[0], 'optionalAccess', _123 => _123.replace, 'call', _124 => _124(/\/+$/, "")]), () => ( ""));
3133
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _113 => _113.split, 'call', _114 => _114("?"), 'access', _115 => _115[0], 'optionalAccess', _116 => _116.replace, 'call', _117 => _117(/\/+$/, "")]), () => ( ""));
3253
3134
  return path.endsWith("/redeem");
3254
3135
  }
3255
3136
  function writeErr(res, status, message, headers = {}) {
@@ -3279,8 +3160,8 @@ function grantToResult(type, granted) {
3279
3160
  function currentResult(type, keyRow) {
3280
3161
  const result = { type };
3281
3162
  if (type === "credit") {
3282
- if (_optionalChain([keyRow, 'optionalAccess', _125 => _125.totalCostLimitUsd]) != null) result.totalCostLimitUsd = keyRow.totalCostLimitUsd;
3283
- } else if (_optionalChain([keyRow, 'optionalAccess', _126 => _126.expiresAt]) != null) {
3163
+ if (_optionalChain([keyRow, 'optionalAccess', _118 => _118.totalCostLimitUsd]) != null) result.totalCostLimitUsd = keyRow.totalCostLimitUsd;
3164
+ } else if (_optionalChain([keyRow, 'optionalAccess', _119 => _119.expiresAt]) != null) {
3284
3165
  result.expiresAt = keyRow.expiresAt;
3285
3166
  }
3286
3167
  return result;
@@ -3318,7 +3199,7 @@ async function handleVoucherRedeem(req, res, deps, voucherEnabled, redeemLimiter
3318
3199
  let code;
3319
3200
  try {
3320
3201
  code = raw ? JSON.parse(raw)["code"] : void 0;
3321
- } catch (e20) {
3202
+ } catch (e19) {
3322
3203
  writeErr(res, 400, "Invalid JSON in request body");
3323
3204
  return;
3324
3205
  }
@@ -3367,7 +3248,7 @@ async function handleVoucherRedeem(req, res, deps, voucherEnabled, redeemLimiter
3367
3248
  const won = await voucherDb.voucherRedeemCas(voucher.id, verifiedKeyId, absolute, now);
3368
3249
  if (!won) {
3369
3250
  const after = await voucherDb.voucherGetByHash(codeHash);
3370
- if (_optionalChain([after, 'optionalAccess', _127 => _127.status]) === "redeemed" && after.redeemedByKeyId === verifiedKeyId) {
3251
+ if (_optionalChain([after, 'optionalAccess', _120 => _120.status]) === "redeemed" && after.redeemedByKeyId === verifiedKeyId) {
3371
3252
  return after.grantApplied === true ? { ok: true, result: currentResult(after.type, await deps.db.outboundApiKeysGetByHash(keyHash)) } : await applyFirstPass(after, recordedAbsolute(after));
3372
3253
  }
3373
3254
  return { ok: false, status: 409, message: "Code was already redeemed" };
@@ -3428,14 +3309,14 @@ function extractPresentedKey(req) {
3428
3309
  }
3429
3310
  const xApiKey = req.headers["x-api-key"];
3430
3311
  const xApi = Array.isArray(xApiKey) ? xApiKey[0] : xApiKey;
3431
- if (_optionalChain([xApi, 'optionalAccess', _128 => _128.trim, 'call', _129 => _129()])) return xApi.trim();
3312
+ if (_optionalChain([xApi, 'optionalAccess', _121 => _121.trim, 'call', _122 => _122()])) return xApi.trim();
3432
3313
  const goog = req.headers["x-goog-api-key"];
3433
3314
  const g = Array.isArray(goog) ? goog[0] : goog;
3434
- return _optionalChain([g, 'optionalAccess', _130 => _130.trim, 'call', _131 => _131()]) || void 0;
3315
+ return _optionalChain([g, 'optionalAccess', _123 => _123.trim, 'call', _124 => _124()]) || void 0;
3435
3316
  }
3436
3317
  function selectEndpoint(method, url) {
3437
3318
  if (method !== "POST" || !url) return null;
3438
- const path = _nullishCoalesce(_optionalChain([url, 'access', _132 => _132.split, 'call', _133 => _133("?"), 'access', _134 => _134[0], 'optionalAccess', _135 => _135.replace, 'call', _136 => _136(/\/+$/, "")]), () => ( ""));
3319
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _125 => _125.split, 'call', _126 => _126("?"), 'access', _127 => _127[0], 'optionalAccess', _128 => _128.replace, 'call', _129 => _129(/\/+$/, "")]), () => ( ""));
3439
3320
  if (path.endsWith("/chat/completions")) return "chat";
3440
3321
  if (path.endsWith("/responses")) return "responses";
3441
3322
  if (path.includes("/v1/messages")) return "messages";
@@ -3453,12 +3334,12 @@ function extractGeminiModelFromUrl(url) {
3453
3334
  }
3454
3335
  function isModelsListRequest(url) {
3455
3336
  if (!url) return false;
3456
- const path = _nullishCoalesce(_optionalChain([url, 'access', _137 => _137.split, 'call', _138 => _138("?"), 'access', _139 => _139[0], 'optionalAccess', _140 => _140.replace, 'call', _141 => _141(/\/+$/, "")]), () => ( ""));
3337
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _130 => _130.split, 'call', _131 => _131("?"), 'access', _132 => _132[0], 'optionalAccess', _133 => _133.replace, 'call', _134 => _134(/\/+$/, "")]), () => ( ""));
3457
3338
  return path.endsWith("/models");
3458
3339
  }
3459
3340
  function writeChatModelsList(res, config) {
3460
3341
  const chat = config.endpoints.find((e) => e.endpoint === "chat");
3461
- const data = (_nullishCoalesce(_optionalChain([chat, 'optionalAccess', _142 => _142.models]), () => ( []))).map((ref) => _chunkSVXC36MUcjs.parseModelRef.call(void 0, ref)).filter((p) => p !== null).map((p) => ({ id: p.modelId, object: "model", owned_by: "omnicross" }));
3342
+ const data = (_nullishCoalesce(_optionalChain([chat, 'optionalAccess', _135 => _135.models]), () => ( []))).map((ref) => _chunkVACWOIREcjs.parseModelRef.call(void 0, ref)).filter((p) => p !== null).map((p) => ({ id: p.modelId, object: "model", owned_by: "omnicross" }));
3462
3343
  res.writeHead(200, { "Content-Type": "application/json" });
3463
3344
  res.end(JSON.stringify({ object: "list", data }));
3464
3345
  }
@@ -3477,8 +3358,8 @@ function shimAuthHeader(req, routeToken) {
3477
3358
  }
3478
3359
  async function handleOutboundRequest(req, res, deps, config, rateLimiter, serialQueue, concurrencyGate, redeemLimiter, redeemMutex) {
3479
3360
  const now = Date.now();
3480
- const audit = beginAuditCapture(req, res, now);
3481
- const billing = beginBillingCapture(req, res, now);
3361
+ const audit = _chunkUNWKG6EIcjs.beginAuditCapture.call(void 0, req, res, now);
3362
+ const billing = _chunkAPYG5QD7cjs.beginBillingCapture.call(void 0, req, res, now);
3482
3363
  const presented = extractPresentedKey(req);
3483
3364
  const verification = await verifyKey(deps.db, presented, now);
3484
3365
  if (verification.status !== "ok") {
@@ -3497,7 +3378,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
3497
3378
  req,
3498
3379
  res,
3499
3380
  deps,
3500
- _optionalChain([config, 'access', _143 => _143.voucher, 'optionalAccess', _144 => _144.enabled]) === true,
3381
+ _optionalChain([config, 'access', _136 => _136.voucher, 'optionalAccess', _137 => _137.enabled]) === true,
3501
3382
  _nullishCoalesce(redeemLimiter, () => ( getFallbackRedeemLimiter())),
3502
3383
  verified.id,
3503
3384
  _nullishCoalesce(presented, () => ( "")),
@@ -3531,7 +3412,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
3531
3412
  const spend = await deps.keySpendTracker.getSpend(verified.id, now);
3532
3413
  const quota = checkKeyQuota(verified.costLimits, spend);
3533
3414
  if (!quota.allowed) {
3534
- emitWebhookEvent({
3415
+ _chunkUIBD2YY5cjs.emitWebhookEvent.call(void 0, {
3535
3416
  kind: "key.quotaExceeded",
3536
3417
  at: now,
3537
3418
  keyId: verified.id,
@@ -3542,9 +3423,9 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
3542
3423
  writeCostLimitError(res, quota.scope, quota.limitUsd, quota.spentUsd);
3543
3424
  return;
3544
3425
  }
3545
- for (const warn of computeQuotaWarnings(verified.costLimits, spend)) {
3546
- if (markQuotaWarnedOnce(verified.id, warn.scope, warn.windowStart)) {
3547
- emitWebhookEvent({
3426
+ for (const warn of _chunk4YINUUKQcjs.computeQuotaWarnings.call(void 0, verified.costLimits, spend)) {
3427
+ if (_chunk4YINUUKQcjs.markQuotaWarnedOnce.call(void 0, verified.id, warn.scope, warn.windowStart)) {
3428
+ _chunkUIBD2YY5cjs.emitWebhookEvent.call(void 0, {
3548
3429
  kind: "key.quotaWarning",
3549
3430
  at: now,
3550
3431
  keyId: verified.id,
@@ -3583,12 +3464,12 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
3583
3464
  res.once("close", release2);
3584
3465
  }
3585
3466
  try {
3586
- const ingressFormat = _chunkSVXC36MUcjs.endpointToIngressFormat.call(void 0, endpoint);
3467
+ const ingressFormat = _chunkVACWOIREcjs.endpointToIngressFormat.call(void 0, endpoint);
3587
3468
  const rawBody = await readBody3(req);
3588
3469
  let parsedBody = {};
3589
3470
  try {
3590
3471
  parsedBody = rawBody ? JSON.parse(rawBody) : {};
3591
- } catch (e21) {
3472
+ } catch (e20) {
3592
3473
  writeJsonError(res, 400, "Invalid JSON in request body");
3593
3474
  return;
3594
3475
  }
@@ -3598,7 +3479,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
3598
3479
  if (urlModel) parsedBody["model"] = urlModel;
3599
3480
  }
3600
3481
  const sessionId = deps.proxyDeps.apiKeyPool ? `outbound:${verified.id}` : null;
3601
- const resolved = _chunkSVXC36MUcjs.isKindMappedEndpoint.call(void 0, endpoint) || endpoint === "chat" ? await _chunkSVXC36MUcjs.resolveRoute.call(void 0, {
3482
+ const resolved = _chunkVACWOIREcjs.isKindMappedEndpoint.call(void 0, endpoint) || endpoint === "chat" ? await _chunkVACWOIREcjs.resolveRoute.call(void 0, {
3602
3483
  config: endpointConfig,
3603
3484
  ingressFormat,
3604
3485
  llmConfig: deps.llmConfig,
@@ -3606,12 +3487,12 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
3606
3487
  // Capture the ORIGINAL requested id BEFORE any downstream swap; for
3607
3488
  // kind-mapped endpoints it selects the kind AND is stamped onto
3608
3489
  // `route.requestedModel`; for chat it is matched against the list.
3609
- requestedModel: _chunkSVXC36MUcjs.extractRequestedModel.call(void 0, ingressFormat, parsedBody),
3490
+ requestedModel: _chunkVACWOIREcjs.extractRequestedModel.call(void 0, ingressFormat, parsedBody),
3610
3491
  // Attribution: stamp the verified named-key id onto the route.
3611
3492
  apiKeyId: verified.id
3612
- }) : await _chunkSVXC36MUcjs.resolveRoute.call(void 0, {
3493
+ }) : await _chunkVACWOIREcjs.resolveRoute.call(void 0, {
3613
3494
  config: endpointConfig,
3614
- role: _chunkSVXC36MUcjs.detectRequestRole.call(void 0, ingressFormat, parsedBody, {
3495
+ role: _chunkVACWOIREcjs.detectRequestRole.call(void 0, ingressFormat, parsedBody, {
3615
3496
  backgroundModelIds: endpointConfig.backgroundModelIds
3616
3497
  }),
3617
3498
  ingressFormat,
@@ -3642,7 +3523,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
3642
3523
  }
3643
3524
  let releaseSerial = null;
3644
3525
  const providerKey = resolved.route.providerId;
3645
- if (_optionalChain([config, 'access', _145 => _145.userMessageQueue, 'optionalAccess', _146 => _146.enabled]) && providerKey && isUserMessageRequest(endpoint, parsedBody)) {
3526
+ if (_optionalChain([config, 'access', _138 => _138.userMessageQueue, 'optionalAccess', _139 => _139.enabled]) && providerKey && isUserMessageRequest(endpoint, parsedBody)) {
3646
3527
  const umq = config.userMessageQueue;
3647
3528
  try {
3648
3529
  const serialSlot = await serialQueue.acquire(providerKey, {
@@ -3677,7 +3558,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
3677
3558
  const message = _chunkSVNDB62Dcjs.serializeError.call(void 0, err);
3678
3559
  if (deps.logger) deps.logger.error("[OutboundApi] dispatch error:", message);
3679
3560
  else console.error("[OutboundApi] dispatch error:", message);
3680
- emitWebhookEvent({ kind: "server.error", at: Date.now(), message });
3561
+ _chunkUIBD2YY5cjs.emitWebhookEvent.call(void 0, { kind: "server.error", at: Date.now(), message });
3681
3562
  if (audit) audit.error = message;
3682
3563
  writeJsonError(res, 502, message);
3683
3564
  } finally {
@@ -3759,7 +3640,7 @@ var OutboundApiServer = (_class11 = class {
3759
3640
  await this.stop();
3760
3641
  return;
3761
3642
  }
3762
- const missing = _chunkSVXC36MUcjs.validateServerModelConfig.call(void 0, {
3643
+ const missing = _chunkVACWOIREcjs.validateServerModelConfig.call(void 0, {
3763
3644
  enabled: true,
3764
3645
  networkBinding: input.networkBinding,
3765
3646
  endpoints: input.endpoints,
@@ -3783,7 +3664,7 @@ var OutboundApiServer = (_class11 = class {
3783
3664
  const actualPort = await this.listen(bindAddr, port);
3784
3665
  this.boundAddr = bindAddr;
3785
3666
  this.boundPort = actualPort;
3786
- if (actualPort !== port) _optionalChain([this, 'access', _147 => _147.onPortChange, 'optionalCall', _148 => _148(actualPort)]);
3667
+ if (actualPort !== port) _optionalChain([this, 'access', _140 => _140.onPortChange, 'optionalCall', _141 => _141(actualPort)]);
3787
3668
  this.logInfo(`[OutboundApiServer] Listening on ${bindAddr}:${actualPort}`);
3788
3669
  return actualPort;
3789
3670
  }
@@ -3817,6 +3698,7 @@ var OutboundApiServer = (_class11 = class {
3817
3698
  }
3818
3699
  /** Per-request handler. Auth is enforced on EVERY request (incl. loopback). */
3819
3700
  onRequest(req, res) {
3701
+ if (req.url) req.url = normalizeDoubledEndpointPath(req.url);
3820
3702
  if (this.deps.healthReportProvider && this.tryServeHealth(req, res)) return;
3821
3703
  handleOutboundRequest(
3822
3704
  req,
@@ -3850,7 +3732,7 @@ var OutboundApiServer = (_class11 = class {
3850
3732
  const provider = this.deps.healthReportProvider;
3851
3733
  if (!provider) return false;
3852
3734
  if (req.method !== "GET" && req.method !== "HEAD") return false;
3853
- const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access', _149 => _149.split, 'call', _150 => _150("?"), 'access', _151 => _151[0], 'optionalAccess', _152 => _152.replace, 'call', _153 => _153(/\/+$/, "")]) || "/";
3735
+ const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access', _142 => _142.split, 'call', _143 => _143("?"), 'access', _144 => _144[0], 'optionalAccess', _145 => _145.replace, 'call', _146 => _146(/\/+$/, "")]) || "/";
3854
3736
  if (path !== "/health" && path !== "/healthz") return false;
3855
3737
  const report = provider();
3856
3738
  res.writeHead(_healthloggingtypes.healthHttpStatus.call(void 0, report.status), { "Content-Type": "application/json" });
@@ -3939,6 +3821,16 @@ function firstLanIPv4() {
3939
3821
  }
3940
3822
  return null;
3941
3823
  }
3824
+ function normalizeDoubledEndpointPath(url) {
3825
+ const queryIdx = url.indexOf("?");
3826
+ const path = queryIdx === -1 ? url : url.slice(0, queryIdx);
3827
+ const query = queryIdx === -1 ? "" : url.slice(queryIdx);
3828
+ const collapsed = path.replace(
3829
+ /^(.*?)(\/v1\/(?:messages|responses|chat\/completions))\2$/,
3830
+ "$1$2"
3831
+ );
3832
+ return collapsed + query;
3833
+ }
3942
3834
 
3943
3835
  // src/outbound-api/keySpendTracker.ts
3944
3836
  function startOfLocalDay(ts) {
@@ -4125,7 +4017,7 @@ async function callAnthropicCompletion(provider, apiKey, options, logger) {
4125
4017
  message: {
4126
4018
  id: `assistant-${Date.now()}`,
4127
4019
  role: "assistant",
4128
- content: _optionalChain([choice2, 'access', _154 => _154.message, 'optionalAccess', _155 => _155.content]) || "",
4020
+ content: _optionalChain([choice2, 'access', _147 => _147.message, 'optionalAccess', _148 => _148.content]) || "",
4129
4021
  timestamp: Date.now()
4130
4022
  },
4131
4023
  usage: openaiResponse2.usage ? {
@@ -4230,7 +4122,7 @@ async function callGeminiCompletion(provider, apiKey, options, logger) {
4230
4122
  const candidate = candidates[0];
4231
4123
  const content = candidate.content;
4232
4124
  let textContent = "";
4233
- if (_optionalChain([content, 'optionalAccess', _156 => _156.parts])) {
4125
+ if (_optionalChain([content, 'optionalAccess', _149 => _149.parts])) {
4234
4126
  for (const part of content.parts) {
4235
4127
  if (part.text) {
4236
4128
  textContent += part.text;
@@ -4363,7 +4255,7 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
4363
4255
  });
4364
4256
  if (!response.ok) {
4365
4257
  const errorText = await response.text();
4366
- _optionalChain([callbacks, 'access', _157 => _157.onError, 'optionalCall', _158 => _158(`API error (${response.status}): ${errorText}`)]);
4258
+ _optionalChain([callbacks, 'access', _150 => _150.onError, 'optionalCall', _151 => _151(`API error (${response.status}): ${errorText}`)]);
4367
4259
  return;
4368
4260
  }
4369
4261
  const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "openai", {
@@ -4373,7 +4265,7 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
4373
4265
  onVideo: callbacks.onVideo,
4374
4266
  onError: callbacks.onError
4375
4267
  });
4376
- _optionalChain([callbacks, 'access', _159 => _159.onDone, 'optionalCall', _160 => _160(
4268
+ _optionalChain([callbacks, 'access', _152 => _152.onDone, 'optionalCall', _153 => _153(
4377
4269
  {
4378
4270
  id: messageId,
4379
4271
  role: "assistant",
@@ -4445,7 +4337,7 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
4445
4337
  logger.info("Streaming Anthropic completion request", {
4446
4338
  url: apiUrl,
4447
4339
  model: anthropicRequest.model,
4448
- messagesCount: _optionalChain([anthropicRequest, 'access', _161 => _161.messages, 'optionalAccess', _162 => _162.length]),
4340
+ messagesCount: _optionalChain([anthropicRequest, 'access', _154 => _154.messages, 'optionalAccess', _155 => _155.length]),
4449
4341
  max_tokens: anthropicRequest.max_tokens,
4450
4342
  temperature: anthropicRequest.temperature,
4451
4343
  stream: anthropicRequest.stream,
@@ -4462,7 +4354,7 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
4462
4354
  if (!response.ok) {
4463
4355
  const errorText = await response.text();
4464
4356
  logger.error("Anthropic API error", void 0, { status: response.status, errorText });
4465
- _optionalChain([callbacks, 'access', _163 => _163.onError, 'optionalCall', _164 => _164(`API error (${response.status}): ${errorText}`)]);
4357
+ _optionalChain([callbacks, 'access', _156 => _156.onError, 'optionalCall', _157 => _157(`API error (${response.status}): ${errorText}`)]);
4466
4358
  return;
4467
4359
  }
4468
4360
  const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "anthropic", {
@@ -4473,10 +4365,10 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
4473
4365
  });
4474
4366
  logger.info("Anthropic stream complete", {
4475
4367
  contentLength: result.content.length,
4476
- reasoningLength: _optionalChain([result, 'access', _165 => _165.reasoning, 'optionalAccess', _166 => _166.length]) || 0,
4368
+ reasoningLength: _optionalChain([result, 'access', _158 => _158.reasoning, 'optionalAccess', _159 => _159.length]) || 0,
4477
4369
  blocksCount: result.blocks.length
4478
4370
  });
4479
- _optionalChain([callbacks, 'access', _167 => _167.onDone, 'optionalCall', _168 => _168(
4371
+ _optionalChain([callbacks, 'access', _160 => _160.onDone, 'optionalCall', _161 => _161(
4480
4372
  {
4481
4373
  id: messageId,
4482
4374
  role: "assistant",
@@ -4532,7 +4424,7 @@ async function streamGeminiCompletion(provider, apiKey, options, messageId, call
4532
4424
  if (!response.ok) {
4533
4425
  const errorText = await response.text();
4534
4426
  logger.error("Gemini API error", void 0, { status: response.status, errorText });
4535
- _optionalChain([callbacks, 'access', _169 => _169.onError, 'optionalCall', _170 => _170(`API error (${response.status}): ${errorText}`)]);
4427
+ _optionalChain([callbacks, 'access', _162 => _162.onError, 'optionalCall', _163 => _163(`API error (${response.status}): ${errorText}`)]);
4536
4428
  return;
4537
4429
  }
4538
4430
  const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "gemini", {
@@ -4541,7 +4433,7 @@ async function streamGeminiCompletion(provider, apiKey, options, messageId, call
4541
4433
  onError: callbacks.onError
4542
4434
  });
4543
4435
  logger.info("Gemini stream complete", { contentLength: result.content.length });
4544
- _optionalChain([callbacks, 'access', _171 => _171.onDone, 'optionalCall', _172 => _172(
4436
+ _optionalChain([callbacks, 'access', _164 => _164.onDone, 'optionalCall', _165 => _165(
4545
4437
  {
4546
4438
  id: messageId,
4547
4439
  role: "assistant",
@@ -4593,7 +4485,7 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
4593
4485
  });
4594
4486
  if (!response.ok) {
4595
4487
  const errorText = await response.text();
4596
- _optionalChain([callbacks, 'access', _173 => _173.onError, 'optionalCall', _174 => _174(`API error (${response.status}): ${errorText}`)]);
4488
+ _optionalChain([callbacks, 'access', _166 => _166.onError, 'optionalCall', _167 => _167(`API error (${response.status}): ${errorText}`)]);
4597
4489
  return;
4598
4490
  }
4599
4491
  const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "openai-response", {
@@ -4602,7 +4494,7 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
4602
4494
  onError: callbacks.onError
4603
4495
  });
4604
4496
  logger.info("OpenAI Response API stream complete", { contentLength: result.content.length });
4605
- _optionalChain([callbacks, 'access', _175 => _175.onDone, 'optionalCall', _176 => _176(
4497
+ _optionalChain([callbacks, 'access', _168 => _168.onDone, 'optionalCall', _169 => _169(
4606
4498
  {
4607
4499
  id: messageId,
4608
4500
  role: "assistant",
@@ -4630,7 +4522,7 @@ async function resolveEffectiveMaxTokens(llmConfig, getProvider, logger, provide
4630
4522
  }
4631
4523
  try {
4632
4524
  const globalParams = await llmConfig.getGlobalModelParameters();
4633
- if (_optionalChain([globalParams, 'optionalAccess', _177 => _177.maxTokens, 'optionalAccess', _178 => _178.enabled]) && globalParams.maxTokens.value > 0) {
4525
+ if (_optionalChain([globalParams, 'optionalAccess', _170 => _170.maxTokens, 'optionalAccess', _171 => _171.enabled]) && globalParams.maxTokens.value > 0) {
4634
4526
  logger.debug("Using global maxTokens", { maxTokens: globalParams.maxTokens.value });
4635
4527
  return globalParams.maxTokens.value;
4636
4528
  }
@@ -4640,8 +4532,8 @@ async function resolveEffectiveMaxTokens(llmConfig, getProvider, logger, provide
4640
4532
  const MAX_TOKENS_CAP = 131072;
4641
4533
  const provider = await getProvider(providerId);
4642
4534
  if (provider) {
4643
- const modelConfig = _optionalChain([provider, 'access', _179 => _179.modelConfigs, 'optionalAccess', _180 => _180.find, 'call', _181 => _181((m) => m.id === modelId)]);
4644
- if (_optionalChain([modelConfig, 'optionalAccess', _182 => _182.maxTokens]) && modelConfig.maxTokens > 0) {
4535
+ const modelConfig = _optionalChain([provider, 'access', _172 => _172.modelConfigs, 'optionalAccess', _173 => _173.find, 'call', _174 => _174((m) => m.id === modelId)]);
4536
+ if (_optionalChain([modelConfig, 'optionalAccess', _175 => _175.maxTokens]) && modelConfig.maxTokens > 0) {
4645
4537
  const cappedMaxTokens = Math.min(modelConfig.maxTokens, MAX_TOKENS_CAP);
4646
4538
  logger.debug("Using model config maxTokens", {
4647
4539
  maxTokens: modelConfig.maxTokens,
@@ -4651,8 +4543,8 @@ async function resolveEffectiveMaxTokens(llmConfig, getProvider, logger, provide
4651
4543
  }
4652
4544
  if (provider.modelGroups) {
4653
4545
  for (const group of provider.modelGroups) {
4654
- const model = _optionalChain([group, 'access', _183 => _183.models, 'optionalAccess', _184 => _184.find, 'call', _185 => _185((m) => m.id === modelId)]);
4655
- if (_optionalChain([model, 'optionalAccess', _186 => _186.maxTokens]) && model.maxTokens > 0) {
4546
+ const model = _optionalChain([group, 'access', _176 => _176.models, 'optionalAccess', _177 => _177.find, 'call', _178 => _178((m) => m.id === modelId)]);
4547
+ if (_optionalChain([model, 'optionalAccess', _179 => _179.maxTokens]) && model.maxTokens > 0) {
4656
4548
  const cappedMaxTokens = Math.min(model.maxTokens, MAX_TOKENS_CAP);
4657
4549
  logger.debug("Using modelGroup model maxTokens", {
4658
4550
  maxTokens: model.maxTokens,
@@ -4697,7 +4589,7 @@ async function resolveThinkingBudget(getProvider, logger, providerId, modelId, m
4697
4589
  }
4698
4590
  const thinkingBudget = _thinkingconfig.calculateThinkingBudget.call(void 0, modelId, thinkLevel, maxTokens);
4699
4591
  const provider = await getProvider(providerId);
4700
- const providerName = _optionalChain([provider, 'optionalAccess', _187 => _187.name, 'optionalAccess', _188 => _188.toLowerCase, 'call', _189 => _189()]) || "";
4592
+ const providerName = _optionalChain([provider, 'optionalAccess', _180 => _180.name, 'optionalAccess', _181 => _181.toLowerCase, 'call', _182 => _182()]) || "";
4701
4593
  const apiFormat = provider ? _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider) : "openai";
4702
4594
  if (apiFormat === "anthropic" || providerName === "anthropic" || providerName.includes("claude")) {
4703
4595
  const thinkingConfig = _thinkingconfig.buildAnthropicThinking.call(void 0, modelId, thinkLevel, maxTokens);
@@ -4734,7 +4626,7 @@ function logToolFormat(tools, logger) {
4734
4626
  tools: openaiTools.map((t) => t.function.name),
4735
4627
  firstTool: {
4736
4628
  name: firstTool.function.name,
4737
- description: _optionalChain([firstTool, 'access', _190 => _190.function, 'access', _191 => _191.description, 'optionalAccess', _192 => _192.slice, 'call', _193 => _193(0, 100)]),
4629
+ description: _optionalChain([firstTool, 'access', _183 => _183.function, 'access', _184 => _184.description, 'optionalAccess', _185 => _185.slice, 'call', _186 => _186(0, 100)]),
4738
4630
  parameters: firstTool.function.parameters
4739
4631
  }
4740
4632
  });
@@ -4745,7 +4637,7 @@ function logToolFormat(tools, logger) {
4745
4637
  tools: anthropicTools.map((t) => t.name),
4746
4638
  firstTool: {
4747
4639
  name: firstTool.name,
4748
- description: _optionalChain([firstTool, 'access', _194 => _194.description, 'optionalAccess', _195 => _195.slice, 'call', _196 => _196(0, 100)]),
4640
+ description: _optionalChain([firstTool, 'access', _187 => _187.description, 'optionalAccess', _188 => _188.slice, 'call', _189 => _189(0, 100)]),
4749
4641
  input_schema: firstTool.input_schema
4750
4642
  }
4751
4643
  });
@@ -4756,9 +4648,9 @@ function logToolFormat(tools, logger) {
4756
4648
  count: allDeclarations.length,
4757
4649
  tools: allDeclarations.map((t) => t.name),
4758
4650
  firstTool: {
4759
- name: _optionalChain([allDeclarations, 'access', _197 => _197[0], 'optionalAccess', _198 => _198.name]),
4760
- description: _optionalChain([allDeclarations, 'access', _199 => _199[0], 'optionalAccess', _200 => _200.description, 'optionalAccess', _201 => _201.slice, 'call', _202 => _202(0, 100)]),
4761
- parameters: _optionalChain([allDeclarations, 'access', _203 => _203[0], 'optionalAccess', _204 => _204.parameters])
4651
+ name: _optionalChain([allDeclarations, 'access', _190 => _190[0], 'optionalAccess', _191 => _191.name]),
4652
+ description: _optionalChain([allDeclarations, 'access', _192 => _192[0], 'optionalAccess', _193 => _193.description, 'optionalAccess', _194 => _194.slice, 'call', _195 => _195(0, 100)]),
4653
+ parameters: _optionalChain([allDeclarations, 'access', _196 => _196[0], 'optionalAccess', _197 => _197.parameters])
4762
4654
  }
4763
4655
  });
4764
4656
  }
@@ -4817,7 +4709,7 @@ function buildToolRequest(apiFormat, conversationMessages, actualModel, options,
4817
4709
  function extractDeltaContent(rawJson, apiFormat) {
4818
4710
  const json = rawJson;
4819
4711
  if (apiFormat === "google") {
4820
- const parts = _optionalChain([json, 'access', _205 => _205.candidates, 'optionalAccess', _206 => _206[0], 'optionalAccess', _207 => _207.content, 'optionalAccess', _208 => _208.parts]) || [];
4712
+ const parts = _optionalChain([json, 'access', _198 => _198.candidates, 'optionalAccess', _199 => _199[0], 'optionalAccess', _200 => _200.content, 'optionalAccess', _201 => _201.parts]) || [];
4821
4713
  let text = "";
4822
4714
  for (const part of parts) {
4823
4715
  if (part.thought === true) continue;
@@ -4825,15 +4717,15 @@ function extractDeltaContent(rawJson, apiFormat) {
4825
4717
  }
4826
4718
  return text;
4827
4719
  } else if (apiFormat === "anthropic") {
4828
- return _optionalChain([json, 'access', _209 => _209.delta, 'optionalAccess', _210 => _210.text]) || "";
4720
+ return _optionalChain([json, 'access', _202 => _202.delta, 'optionalAccess', _203 => _203.text]) || "";
4829
4721
  } else {
4830
- return _optionalChain([json, 'access', _211 => _211.choices, 'optionalAccess', _212 => _212[0], 'optionalAccess', _213 => _213.delta, 'optionalAccess', _214 => _214.content]) || "";
4722
+ return _optionalChain([json, 'access', _204 => _204.choices, 'optionalAccess', _205 => _205[0], 'optionalAccess', _206 => _206.delta, 'optionalAccess', _207 => _207.content]) || "";
4831
4723
  }
4832
4724
  }
4833
4725
  function extractDeltaReasoning(rawJson, apiFormat) {
4834
4726
  const json = rawJson;
4835
4727
  if (apiFormat === "google") {
4836
- const parts = _optionalChain([json, 'access', _215 => _215.candidates, 'optionalAccess', _216 => _216[0], 'optionalAccess', _217 => _217.content, 'optionalAccess', _218 => _218.parts]) || [];
4728
+ const parts = _optionalChain([json, 'access', _208 => _208.candidates, 'optionalAccess', _209 => _209[0], 'optionalAccess', _210 => _210.content, 'optionalAccess', _211 => _211.parts]) || [];
4837
4729
  let reasoning = "";
4838
4730
  for (const part of parts) {
4839
4731
  if (part.thought === true && part.text) reasoning += part.text;
@@ -4842,14 +4734,14 @@ function extractDeltaReasoning(rawJson, apiFormat) {
4842
4734
  } else if (apiFormat === "anthropic") {
4843
4735
  return "";
4844
4736
  } else {
4845
- const delta = _optionalChain([json, 'access', _219 => _219.choices, 'optionalAccess', _220 => _220[0], 'optionalAccess', _221 => _221.delta]);
4846
- return (_optionalChain([delta, 'optionalAccess', _222 => _222.thinking, 'optionalAccess', _223 => _223.content]) || "") + (_optionalChain([delta, 'optionalAccess', _224 => _224.reasoning_content]) || "");
4737
+ const delta = _optionalChain([json, 'access', _212 => _212.choices, 'optionalAccess', _213 => _213[0], 'optionalAccess', _214 => _214.delta]);
4738
+ return (_optionalChain([delta, 'optionalAccess', _215 => _215.thinking, 'optionalAccess', _216 => _216.content]) || "") + (_optionalChain([delta, 'optionalAccess', _217 => _217.reasoning_content]) || "");
4847
4739
  }
4848
4740
  }
4849
4741
  function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pendingOpenAIToolCalls) {
4850
4742
  const json = rawJson;
4851
4743
  if (apiFormat === "google") {
4852
- const parts = _optionalChain([json, 'access', _225 => _225.candidates, 'optionalAccess', _226 => _226[0], 'optionalAccess', _227 => _227.content, 'optionalAccess', _228 => _228.parts]) || [];
4744
+ const parts = _optionalChain([json, 'access', _218 => _218.candidates, 'optionalAccess', _219 => _219[0], 'optionalAccess', _220 => _220.content, 'optionalAccess', _221 => _221.parts]) || [];
4853
4745
  for (const part of parts) {
4854
4746
  if (part.functionCall) {
4855
4747
  logger.info("Function call detected", { functionCall: part.functionCall });
@@ -4859,13 +4751,13 @@ function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pend
4859
4751
  args: part.functionCall.args || {}
4860
4752
  };
4861
4753
  toolCalls.push(toolCall);
4862
- _optionalChain([callbacks, 'access', _229 => _229.onToolCall, 'optionalCall', _230 => _230(toolCall)]);
4754
+ _optionalChain([callbacks, 'access', _222 => _222.onToolCall, 'optionalCall', _223 => _223(toolCall)]);
4863
4755
  logger.info("Tool called", { toolName: toolCall.name });
4864
4756
  }
4865
4757
  }
4866
4758
  } else if (apiFormat !== "anthropic") {
4867
- const delta = _optionalChain([json, 'access', _231 => _231.choices, 'optionalAccess', _232 => _232[0], 'optionalAccess', _233 => _233.delta]);
4868
- if (_optionalChain([delta, 'optionalAccess', _234 => _234.tool_calls]) && pendingOpenAIToolCalls) {
4759
+ const delta = _optionalChain([json, 'access', _224 => _224.choices, 'optionalAccess', _225 => _225[0], 'optionalAccess', _226 => _226.delta]);
4760
+ if (_optionalChain([delta, 'optionalAccess', _227 => _227.tool_calls]) && pendingOpenAIToolCalls) {
4869
4761
  for (const tc of delta.tool_calls) {
4870
4762
  const index = _nullishCoalesce(tc.index, () => ( 0));
4871
4763
  let pending = pendingOpenAIToolCalls.get(index);
@@ -4874,8 +4766,8 @@ function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pend
4874
4766
  pendingOpenAIToolCalls.set(index, pending);
4875
4767
  }
4876
4768
  if (tc.id) pending.id = tc.id;
4877
- if (_optionalChain([tc, 'access', _235 => _235.function, 'optionalAccess', _236 => _236.name])) pending.name += tc.function.name;
4878
- if (_optionalChain([tc, 'access', _237 => _237.function, 'optionalAccess', _238 => _238.arguments])) pending.arguments += tc.function.arguments;
4769
+ if (_optionalChain([tc, 'access', _228 => _228.function, 'optionalAccess', _229 => _229.name])) pending.name += tc.function.name;
4770
+ if (_optionalChain([tc, 'access', _230 => _230.function, 'optionalAccess', _231 => _231.arguments])) pending.arguments += tc.function.arguments;
4879
4771
  }
4880
4772
  }
4881
4773
  }
@@ -4890,7 +4782,7 @@ function finalizeOpenAIToolCalls(pendingOpenAIToolCalls, toolCalls, callbacks, l
4890
4782
  args: JSON.parse(pending.arguments || "{}")
4891
4783
  };
4892
4784
  toolCalls.push(toolCall);
4893
- _optionalChain([callbacks, 'access', _239 => _239.onToolCall, 'optionalCall', _240 => _240(toolCall)]);
4785
+ _optionalChain([callbacks, 'access', _232 => _232.onToolCall, 'optionalCall', _233 => _233(toolCall)]);
4894
4786
  logger.info("Tool called (OpenAI)", { toolName: toolCall.name, args: toolCall.args });
4895
4787
  } catch (e) {
4896
4788
  logger.error("Failed to parse OpenAI tool call arguments", e instanceof Error ? e : void 0, {
@@ -4904,38 +4796,38 @@ function finalizeOpenAIToolCalls(pendingOpenAIToolCalls, toolCalls, callbacks, l
4904
4796
  function parseStreamChunk(rawJson, apiFormat, callbacks, logger) {
4905
4797
  const json = rawJson;
4906
4798
  if (apiFormat === "google") {
4907
- const candidate = _optionalChain([json, 'access', _241 => _241.candidates, 'optionalAccess', _242 => _242[0]]);
4799
+ const candidate = _optionalChain([json, 'access', _234 => _234.candidates, 'optionalAccess', _235 => _235[0]]);
4908
4800
  if (!candidate) {
4909
4801
  logger.warn("No candidate found in Gemini response");
4910
4802
  return;
4911
4803
  }
4912
- const parts = _optionalChain([candidate, 'access', _243 => _243.content, 'optionalAccess', _244 => _244.parts]) || [];
4804
+ const parts = _optionalChain([candidate, 'access', _236 => _236.content, 'optionalAccess', _237 => _237.parts]) || [];
4913
4805
  for (const part of parts) {
4914
4806
  if (part.thought === true && part.text) {
4915
- _optionalChain([callbacks, 'access', _245 => _245.onReasoning, 'optionalCall', _246 => _246(part.text)]);
4807
+ _optionalChain([callbacks, 'access', _238 => _238.onReasoning, 'optionalCall', _239 => _239(part.text)]);
4916
4808
  continue;
4917
4809
  } else if (part.thoughtSignature && !part.thought) {
4918
4810
  logger.debug("Gemini returned thoughtSignature without thought content");
4919
4811
  }
4920
4812
  if (part.text) {
4921
- _optionalChain([callbacks, 'access', _247 => _247.onDelta, 'optionalCall', _248 => _248(part.text)]);
4813
+ _optionalChain([callbacks, 'access', _240 => _240.onDelta, 'optionalCall', _241 => _241(part.text)]);
4922
4814
  }
4923
4815
  }
4924
4816
  } else if (apiFormat === "anthropic") {
4925
4817
  const delta = json.delta;
4926
- if (_optionalChain([delta, 'optionalAccess', _249 => _249.text])) {
4927
- _optionalChain([callbacks, 'access', _250 => _250.onDelta, 'optionalCall', _251 => _251(delta.text)]);
4818
+ if (_optionalChain([delta, 'optionalAccess', _242 => _242.text])) {
4819
+ _optionalChain([callbacks, 'access', _243 => _243.onDelta, 'optionalCall', _244 => _244(delta.text)]);
4928
4820
  }
4929
4821
  } else {
4930
- const delta = _optionalChain([json, 'access', _252 => _252.choices, 'optionalAccess', _253 => _253[0], 'optionalAccess', _254 => _254.delta]);
4931
- if (_optionalChain([delta, 'optionalAccess', _255 => _255.content])) {
4932
- _optionalChain([callbacks, 'access', _256 => _256.onDelta, 'optionalCall', _257 => _257(delta.content)]);
4822
+ const delta = _optionalChain([json, 'access', _245 => _245.choices, 'optionalAccess', _246 => _246[0], 'optionalAccess', _247 => _247.delta]);
4823
+ if (_optionalChain([delta, 'optionalAccess', _248 => _248.content])) {
4824
+ _optionalChain([callbacks, 'access', _249 => _249.onDelta, 'optionalCall', _250 => _250(delta.content)]);
4933
4825
  }
4934
- if (_optionalChain([delta, 'optionalAccess', _258 => _258.thinking, 'optionalAccess', _259 => _259.content])) {
4935
- _optionalChain([callbacks, 'access', _260 => _260.onReasoning, 'optionalCall', _261 => _261(delta.thinking.content)]);
4826
+ if (_optionalChain([delta, 'optionalAccess', _251 => _251.thinking, 'optionalAccess', _252 => _252.content])) {
4827
+ _optionalChain([callbacks, 'access', _253 => _253.onReasoning, 'optionalCall', _254 => _254(delta.thinking.content)]);
4936
4828
  }
4937
- if (_optionalChain([delta, 'optionalAccess', _262 => _262.reasoning_content])) {
4938
- _optionalChain([callbacks, 'access', _263 => _263.onReasoning, 'optionalCall', _264 => _264(delta.reasoning_content)]);
4829
+ if (_optionalChain([delta, 'optionalAccess', _255 => _255.reasoning_content])) {
4830
+ _optionalChain([callbacks, 'access', _256 => _256.onReasoning, 'optionalCall', _257 => _257(delta.reasoning_content)]);
4939
4831
  }
4940
4832
  }
4941
4833
  }
@@ -4948,7 +4840,7 @@ function buildIterationBlocks(iteration, content, reasoning, blocks, callbacks)
4948
4840
  content: reasoning
4949
4841
  };
4950
4842
  blocks.push(thinkingBlock);
4951
- _optionalChain([callbacks, 'access', _265 => _265.onBlock, 'optionalCall', _266 => _266(thinkingBlock)]);
4843
+ _optionalChain([callbacks, 'access', _258 => _258.onBlock, 'optionalCall', _259 => _259(thinkingBlock)]);
4952
4844
  }
4953
4845
  if (content && content.trim()) {
4954
4846
  const textBlock = {
@@ -4957,7 +4849,7 @@ function buildIterationBlocks(iteration, content, reasoning, blocks, callbacks)
4957
4849
  content
4958
4850
  };
4959
4851
  blocks.push(textBlock);
4960
- _optionalChain([callbacks, 'access', _267 => _267.onBlock, 'optionalCall', _268 => _268(textBlock)]);
4852
+ _optionalChain([callbacks, 'access', _260 => _260.onBlock, 'optionalCall', _261 => _261(textBlock)]);
4961
4853
  }
4962
4854
  }
4963
4855
  async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbacks, logger, builtinExecutor) {
@@ -4972,7 +4864,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
4972
4864
  status: "running"
4973
4865
  };
4974
4866
  blocks.push(toolUseBlock);
4975
- _optionalChain([callbacks, 'access', _269 => _269.onBlock, 'optionalCall', _270 => _270(toolUseBlock)]);
4867
+ _optionalChain([callbacks, 'access', _262 => _262.onBlock, 'optionalCall', _263 => _263(toolUseBlock)]);
4976
4868
  try {
4977
4869
  logger.info("Executing tool", { toolName: toolCall.name });
4978
4870
  const mcpTool = mcpTools.find((t) => t.id === toolCall.name);
@@ -4995,8 +4887,8 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
4995
4887
  result = { isError: true, content: [{ type: "text", text: "MCP service not available" }] };
4996
4888
  }
4997
4889
  logger.info("Tool result received", { result });
4998
- _optionalChain([callbacks, 'access', _271 => _271.onToolResult, 'optionalCall', _272 => _272(toolCall.id, result)]);
4999
- const resultText = _optionalChain([result, 'access', _273 => _273.content, 'optionalAccess', _274 => _274[0], 'optionalAccess', _275 => _275.text]) || JSON.stringify(result);
4890
+ _optionalChain([callbacks, 'access', _264 => _264.onToolResult, 'optionalCall', _265 => _265(toolCall.id, result)]);
4891
+ const resultText = _optionalChain([result, 'access', _266 => _266.content, 'optionalAccess', _267 => _267[0], 'optionalAccess', _268 => _268.text]) || JSON.stringify(result);
5000
4892
  const toolResultBlock = {
5001
4893
  id: `${toolCall.id}_result`,
5002
4894
  type: "tool_result",
@@ -5006,11 +4898,11 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
5006
4898
  isError: result.isError
5007
4899
  };
5008
4900
  blocks.push(toolResultBlock);
5009
- _optionalChain([callbacks, 'access', _276 => _276.onBlock, 'optionalCall', _277 => _277(toolResultBlock)]);
4901
+ _optionalChain([callbacks, 'access', _269 => _269.onBlock, 'optionalCall', _270 => _270(toolResultBlock)]);
5010
4902
  const toolUseBlockRef = blocks.find((b) => b.id === `${toolCall.id}_use`);
5011
4903
  if (toolUseBlockRef && toolUseBlockRef.type === "tool_use") {
5012
4904
  toolUseBlockRef.status = result.isError ? "error" : "completed";
5013
- _optionalChain([callbacks, 'access', _278 => _278.onBlock, 'optionalCall', _279 => _279({ ...toolUseBlockRef })]);
4905
+ _optionalChain([callbacks, 'access', _271 => _271.onBlock, 'optionalCall', _272 => _272({ ...toolUseBlockRef })]);
5014
4906
  }
5015
4907
  toolResults.push({ toolCall, result });
5016
4908
  } catch (error) {
@@ -5020,7 +4912,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
5020
4912
  isError: true,
5021
4913
  content: [{ type: "text", text: `Error: ${errorMessage}` }]
5022
4914
  };
5023
- _optionalChain([callbacks, 'access', _280 => _280.onToolResult, 'optionalCall', _281 => _281(toolCall.id, errorResult)]);
4915
+ _optionalChain([callbacks, 'access', _273 => _273.onToolResult, 'optionalCall', _274 => _274(toolCall.id, errorResult)]);
5024
4916
  const errorToolResultBlock = {
5025
4917
  id: `${toolCall.id}_result`,
5026
4918
  type: "tool_result",
@@ -5030,11 +4922,11 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
5030
4922
  isError: true
5031
4923
  };
5032
4924
  blocks.push(errorToolResultBlock);
5033
- _optionalChain([callbacks, 'access', _282 => _282.onBlock, 'optionalCall', _283 => _283(errorToolResultBlock)]);
4925
+ _optionalChain([callbacks, 'access', _275 => _275.onBlock, 'optionalCall', _276 => _276(errorToolResultBlock)]);
5034
4926
  const errorToolUseBlockRef = blocks.find((b) => b.id === `${toolCall.id}_use`);
5035
4927
  if (errorToolUseBlockRef && errorToolUseBlockRef.type === "tool_use") {
5036
4928
  errorToolUseBlockRef.status = "error";
5037
- _optionalChain([callbacks, 'access', _284 => _284.onBlock, 'optionalCall', _285 => _285({ ...errorToolUseBlockRef })]);
4929
+ _optionalChain([callbacks, 'access', _277 => _277.onBlock, 'optionalCall', _278 => _278({ ...errorToolUseBlockRef })]);
5038
4930
  }
5039
4931
  toolResults.push({ toolCall, result: errorResult });
5040
4932
  }
@@ -5044,7 +4936,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
5044
4936
  function mapToolArguments(args, mcpTool, logger) {
5045
4937
  const mappedArgs = { ...args };
5046
4938
  const toolSchema = mcpTool.inputSchema;
5047
- if (_optionalChain([toolSchema, 'optionalAccess', _286 => _286.properties])) {
4939
+ if (_optionalChain([toolSchema, 'optionalAccess', _279 => _279.properties])) {
5048
4940
  const expectedParams = Object.keys(toolSchema.properties);
5049
4941
  const paramMappings = {
5050
4942
  "search_query": ["query", "q", "searchQuery", "search"],
@@ -5078,25 +4970,25 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
5078
4970
  options.providerId,
5079
4971
  options.model
5080
4972
  );
5081
- const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _287 => _287.actualProviderId]) || options.providerId;
5082
- const actualModel = _optionalChain([routedInfo, 'optionalAccess', _288 => _288.actualModelId]) || options.model;
4973
+ const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _280 => _280.actualProviderId]) || options.providerId;
4974
+ const actualModel = _optionalChain([routedInfo, 'optionalAccess', _281 => _281.actualModelId]) || options.model;
5083
4975
  const provider = await getProvider(actualProviderId);
5084
4976
  if (!provider) {
5085
- _optionalChain([callbacks, 'access', _289 => _289.onError, 'optionalCall', _290 => _290(`Provider not found: ${actualProviderId}`)]);
4977
+ _optionalChain([callbacks, 'access', _282 => _282.onError, 'optionalCall', _283 => _283(`Provider not found: ${actualProviderId}`)]);
5086
4978
  return;
5087
4979
  }
5088
4980
  if (!provider.enabled) {
5089
- _optionalChain([callbacks, 'access', _291 => _291.onError, 'optionalCall', _292 => _292(`Provider is disabled: ${provider.name}`)]);
4981
+ _optionalChain([callbacks, 'access', _284 => _284.onError, 'optionalCall', _285 => _285(`Provider is disabled: ${provider.name}`)]);
5090
4982
  return;
5091
4983
  }
5092
4984
  const { apiKey: effectiveKey } = _chunkA2YMUCBTcjs.resolveProviderEndpoint.call(void 0, provider);
5093
4985
  const apiKey = resolveApiKey2(effectiveKey);
5094
4986
  if (!apiKey) {
5095
- _optionalChain([callbacks, 'access', _293 => _293.onError, 'optionalCall', _294 => _294("API key not configured")]);
4987
+ _optionalChain([callbacks, 'access', _286 => _286.onError, 'optionalCall', _287 => _287("API key not configured")]);
5096
4988
  return;
5097
4989
  }
5098
4990
  const messageId = `msg_${Date.now()}_${Math.random().toString(36).slice(2)}`;
5099
- _optionalChain([callbacks, 'access', _295 => _295.onStart, 'optionalCall', _296 => _296(messageId)]);
4991
+ _optionalChain([callbacks, 'access', _288 => _288.onStart, 'optionalCall', _289 => _289(messageId)]);
5100
4992
  const globalParams = await llmConfig.getGlobalModelParameters();
5101
4993
  const MAX_ITERATIONS = _nullishCoalesce(globalParams.toolMaxTurns, () => ( 100));
5102
4994
  let iteration = 0;
@@ -5143,12 +5035,12 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
5143
5035
  });
5144
5036
  if (!response.ok) {
5145
5037
  const errorText = await response.text();
5146
- _optionalChain([callbacks, 'access', _297 => _297.onError, 'optionalCall', _298 => _298(`API error (${response.status}): ${errorText}`)]);
5038
+ _optionalChain([callbacks, 'access', _290 => _290.onError, 'optionalCall', _291 => _291(`API error (${response.status}): ${errorText}`)]);
5147
5039
  return;
5148
5040
  }
5149
- const reader = _optionalChain([response, 'access', _299 => _299.body, 'optionalAccess', _300 => _300.getReader, 'call', _301 => _301()]);
5041
+ const reader = _optionalChain([response, 'access', _292 => _292.body, 'optionalAccess', _293 => _293.getReader, 'call', _294 => _294()]);
5150
5042
  if (!reader) {
5151
- _optionalChain([callbacks, 'access', _302 => _302.onError, 'optionalCall', _303 => _303("No response body")]);
5043
+ _optionalChain([callbacks, 'access', _295 => _295.onError, 'optionalCall', _296 => _296("No response body")]);
5152
5044
  return;
5153
5045
  }
5154
5046
  const decoder = new TextDecoder();
@@ -5181,7 +5073,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
5181
5073
  logger.debug("Parsed JSON", { json });
5182
5074
  if (json.error) {
5183
5075
  logger.error("API Error", void 0, { error: json.error });
5184
- _optionalChain([callbacks, 'access', _304 => _304.onError, 'optionalCall', _305 => _305(`API Error: ${json.error.message || JSON.stringify(json.error)}`)]);
5076
+ _optionalChain([callbacks, 'access', _297 => _297.onError, 'optionalCall', _298 => _298(`API Error: ${json.error.message || JSON.stringify(json.error)}`)]);
5185
5077
  return;
5186
5078
  }
5187
5079
  parseStreamChunk(json, apiFormat, callbacks, logger);
@@ -5214,7 +5106,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
5214
5106
  toolCallsLength: toolCalls.length,
5215
5107
  executableToolCallsLength: executableToolCalls.length,
5216
5108
  hasMcpTools: !!options.mcpTools,
5217
- mcpToolsLength: _optionalChain([options, 'access', _306 => _306.mcpTools, 'optionalAccess', _307 => _307.length]),
5109
+ mcpToolsLength: _optionalChain([options, 'access', _299 => _299.mcpTools, 'optionalAccess', _300 => _300.length]),
5218
5110
  hasMcpService: !!mcpService
5219
5111
  });
5220
5112
  if (executableToolCalls.length > 0 && options.mcpTools && (mcpService || builtinExecutor)) {
@@ -5235,7 +5127,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
5235
5127
  builtinExecutor
5236
5128
  );
5237
5129
  const toolResultsText = toolResults.map(({ toolCall, result }) => {
5238
- const resultText = typeof result === "string" ? result : _optionalChain([result, 'access', _308 => _308.content, 'optionalAccess', _309 => _309[0], 'optionalAccess', _310 => _310.text]) || JSON.stringify(result);
5130
+ const resultText = typeof result === "string" ? result : _optionalChain([result, 'access', _301 => _301.content, 'optionalAccess', _302 => _302[0], 'optionalAccess', _303 => _303.text]) || JSON.stringify(result);
5239
5131
  return `Tool ${toolCall.name} result:
5240
5132
  ${resultText}`;
5241
5133
  }).join("\n\n");
@@ -5253,12 +5145,12 @@ ${resultText}`;
5253
5145
  }
5254
5146
  } catch (streamError) {
5255
5147
  logger.error("Stream processing error", streamError instanceof Error ? streamError : void 0);
5256
- _optionalChain([callbacks, 'access', _311 => _311.onError, 'optionalCall', _312 => _312(`Stream error: ${streamError instanceof Error ? streamError.message : "Unknown error"}`)]);
5148
+ _optionalChain([callbacks, 'access', _304 => _304.onError, 'optionalCall', _305 => _305(`Stream error: ${streamError instanceof Error ? streamError.message : "Unknown error"}`)]);
5257
5149
  return;
5258
5150
  }
5259
5151
  }
5260
5152
  logger.info("Sending final callback", { blocksCount: blocks.length });
5261
- _optionalChain([callbacks, 'access', _313 => _313.onDone, 'optionalCall', _314 => _314({
5153
+ _optionalChain([callbacks, 'access', _306 => _306.onDone, 'optionalCall', _307 => _307({
5262
5154
  id: messageId,
5263
5155
  role: "assistant",
5264
5156
  content: finalContent,
@@ -5269,7 +5161,7 @@ ${resultText}`;
5269
5161
  } catch (error) {
5270
5162
  logger.error("Error in streamWithTools", error instanceof Error ? error : void 0);
5271
5163
  const message = error instanceof Error ? error.message : "Unknown error";
5272
- _optionalChain([callbacks, 'access', _315 => _315.onError, 'optionalCall', _316 => _316(message)]);
5164
+ _optionalChain([callbacks, 'access', _308 => _308.onError, 'optionalCall', _309 => _309(message)]);
5273
5165
  }
5274
5166
  }
5275
5167
 
@@ -5308,8 +5200,8 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
5308
5200
  options.providerId,
5309
5201
  options.model
5310
5202
  );
5311
- const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _317 => _317.actualProviderId]) || options.providerId;
5312
- const actualModel = _optionalChain([routedInfo, 'optionalAccess', _318 => _318.actualModelId]) || options.model;
5203
+ const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _310 => _310.actualProviderId]) || options.providerId;
5204
+ const actualModel = _optionalChain([routedInfo, 'optionalAccess', _311 => _311.actualModelId]) || options.model;
5313
5205
  const provider = await getProvider(actualProviderId);
5314
5206
  if (!provider) {
5315
5207
  return { success: false, error: `Provider not found: ${actualProviderId}` };
@@ -5347,7 +5239,7 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
5347
5239
  models: provider.models || []
5348
5240
  };
5349
5241
  const executor = getSharedExecutor2();
5350
- const { response } = await _chunkKUU2RNG6cjs.executeProviderCall.call(void 0, {
5242
+ const { response } = await _chunkHYN75H6Gcjs.executeProviderCall.call(void 0, {
5351
5243
  executor,
5352
5244
  request: unifiedRequest,
5353
5245
  provider: transformerProvider,
@@ -5390,18 +5282,18 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
5390
5282
  { endpointTransformer: void 0 }
5391
5283
  );
5392
5284
  const data = await transformedResponse.json();
5393
- const choice = _optionalChain([data, 'access', _319 => _319.choices, 'optionalAccess', _320 => _320[0]]);
5285
+ const choice = _optionalChain([data, 'access', _312 => _312.choices, 'optionalAccess', _313 => _313[0]]);
5394
5286
  if (!choice) {
5395
5287
  return { success: false, error: "No choices in response" };
5396
5288
  }
5397
- const rawToolCalls = _optionalChain([choice, 'access', _321 => _321.message, 'optionalAccess', _322 => _322.tool_calls]);
5398
- const toolCalls = _optionalChain([rawToolCalls, 'optionalAccess', _323 => _323.map, 'call', _324 => _324((tc) => ({
5289
+ const rawToolCalls = _optionalChain([choice, 'access', _314 => _314.message, 'optionalAccess', _315 => _315.tool_calls]);
5290
+ const toolCalls = _optionalChain([rawToolCalls, 'optionalAccess', _316 => _316.map, 'call', _317 => _317((tc) => ({
5399
5291
  id: tc.id,
5400
5292
  name: tc.function.name,
5401
5293
  args: typeof tc.function.arguments === "string" ? JSON.parse(tc.function.arguments) : tc.function.arguments
5402
5294
  }))]);
5403
5295
  const tapped = readUsageFromOpenAIResponse(data.usage);
5404
- if (_optionalChain([recording, 'optionalAccess', _325 => _325.recorder]) && tapped) {
5296
+ if (_optionalChain([recording, 'optionalAccess', _318 => _318.recorder]) && tapped) {
5405
5297
  recording.recorder.record({
5406
5298
  messageId: _nullishCoalesce(options.messageId, () => ( null)),
5407
5299
  parentMessageId: _nullishCoalesce(options.parentMessageId, () => ( null)),
@@ -5419,9 +5311,9 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
5419
5311
  message: {
5420
5312
  id: `msg_${Date.now()}`,
5421
5313
  role: "assistant",
5422
- content: _optionalChain([choice, 'access', _326 => _326.message, 'optionalAccess', _327 => _327.content]) || "",
5314
+ content: _optionalChain([choice, 'access', _319 => _319.message, 'optionalAccess', _320 => _320.content]) || "",
5423
5315
  timestamp: Date.now(),
5424
- thinking: data.reasoning_content || _optionalChain([choice, 'access', _328 => _328.message, 'optionalAccess', _329 => _329.thinking, 'optionalAccess', _330 => _330.content]) ? { content: data.reasoning_content || _optionalChain([choice, 'access', _331 => _331.message, 'optionalAccess', _332 => _332.thinking, 'optionalAccess', _333 => _333.content]) || "", signature: _optionalChain([choice, 'access', _334 => _334.message, 'optionalAccess', _335 => _335.thinking, 'optionalAccess', _336 => _336.signature]) } : void 0,
5316
+ thinking: data.reasoning_content || _optionalChain([choice, 'access', _321 => _321.message, 'optionalAccess', _322 => _322.thinking, 'optionalAccess', _323 => _323.content]) ? { content: data.reasoning_content || _optionalChain([choice, 'access', _324 => _324.message, 'optionalAccess', _325 => _325.thinking, 'optionalAccess', _326 => _326.content]) || "", signature: _optionalChain([choice, 'access', _327 => _327.message, 'optionalAccess', _328 => _328.thinking, 'optionalAccess', _329 => _329.signature]) } : void 0,
5425
5317
  toolCalls
5426
5318
  },
5427
5319
  usage: data.usage ? {
@@ -5442,21 +5334,21 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
5442
5334
  options.providerId,
5443
5335
  options.model
5444
5336
  );
5445
- const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _337 => _337.actualProviderId]) || options.providerId;
5446
- const actualModel = _optionalChain([routedInfo, 'optionalAccess', _338 => _338.actualModelId]) || options.model;
5337
+ const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _330 => _330.actualProviderId]) || options.providerId;
5338
+ const actualModel = _optionalChain([routedInfo, 'optionalAccess', _331 => _331.actualModelId]) || options.model;
5447
5339
  const provider = await getProvider(actualProviderId);
5448
5340
  if (!provider) {
5449
- _optionalChain([callbacks, 'access', _339 => _339.onError, 'optionalCall', _340 => _340(`Provider not found: ${actualProviderId}`)]);
5341
+ _optionalChain([callbacks, 'access', _332 => _332.onError, 'optionalCall', _333 => _333(`Provider not found: ${actualProviderId}`)]);
5450
5342
  return;
5451
5343
  }
5452
5344
  if (!provider.enabled) {
5453
- _optionalChain([callbacks, 'access', _341 => _341.onError, 'optionalCall', _342 => _342(`Provider is disabled: ${provider.name}`)]);
5345
+ _optionalChain([callbacks, 'access', _334 => _334.onError, 'optionalCall', _335 => _335(`Provider is disabled: ${provider.name}`)]);
5454
5346
  return;
5455
5347
  }
5456
5348
  const { apiKey: effectiveKey } = _chunkA2YMUCBTcjs.resolveProviderEndpoint.call(void 0, provider);
5457
5349
  const apiKey = resolveApiKey2(effectiveKey);
5458
5350
  if (!apiKey) {
5459
- _optionalChain([callbacks, 'access', _343 => _343.onError, 'optionalCall', _344 => _344("API key not configured")]);
5351
+ _optionalChain([callbacks, 'access', _336 => _336.onError, 'optionalCall', _337 => _337("API key not configured")]);
5460
5352
  return;
5461
5353
  }
5462
5354
  const { chain, hasTransformers } = await resolveChainWithMain(
@@ -5468,7 +5360,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
5468
5360
  return completeStreamFallback(options, callbacks);
5469
5361
  }
5470
5362
  const messageId = `msg_${Date.now()}`;
5471
- _optionalChain([callbacks, 'access', _345 => _345.onStart, 'optionalCall', _346 => _346(messageId)]);
5363
+ _optionalChain([callbacks, 'access', _338 => _338.onStart, 'optionalCall', _339 => _339(messageId)]);
5472
5364
  const unifiedRequest = {
5473
5365
  model: actualModel,
5474
5366
  messages: options.messages.map((m) => ({
@@ -5486,7 +5378,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
5486
5378
  models: provider.models || []
5487
5379
  };
5488
5380
  const executor = getSharedExecutor2();
5489
- const { response } = await _chunkKUU2RNG6cjs.executeProviderCall.call(void 0, {
5381
+ const { response } = await _chunkHYN75H6Gcjs.executeProviderCall.call(void 0, {
5490
5382
  executor,
5491
5383
  request: unifiedRequest,
5492
5384
  provider: transformerProvider,
@@ -5516,7 +5408,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
5516
5408
  });
5517
5409
  if (!response.ok) {
5518
5410
  const errorText = await response.text();
5519
- _optionalChain([callbacks, 'access', _347 => _347.onError, 'optionalCall', _348 => _348(`API error (${response.status}): ${errorText}`)]);
5411
+ _optionalChain([callbacks, 'access', _340 => _340.onError, 'optionalCall', _341 => _341(`API error (${response.status}): ${errorText}`)]);
5520
5412
  return;
5521
5413
  }
5522
5414
  const transformedResponse = await executor.executeResponseChain(
@@ -5526,9 +5418,9 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
5526
5418
  chain,
5527
5419
  { endpointTransformer: void 0 }
5528
5420
  );
5529
- const reader = _optionalChain([transformedResponse, 'access', _349 => _349.body, 'optionalAccess', _350 => _350.getReader, 'call', _351 => _351()]);
5421
+ const reader = _optionalChain([transformedResponse, 'access', _342 => _342.body, 'optionalAccess', _343 => _343.getReader, 'call', _344 => _344()]);
5530
5422
  if (!reader) {
5531
- _optionalChain([callbacks, 'access', _352 => _352.onError, 'optionalCall', _353 => _353("No response body")]);
5423
+ _optionalChain([callbacks, 'access', _345 => _345.onError, 'optionalCall', _346 => _346("No response body")]);
5532
5424
  return;
5533
5425
  }
5534
5426
  const decoder = new TextDecoder();
@@ -5546,22 +5438,22 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
5546
5438
  if (data === "[DONE]") continue;
5547
5439
  try {
5548
5440
  const json = JSON.parse(data);
5549
- const delta = _optionalChain([json, 'access', _354 => _354.choices, 'optionalAccess', _355 => _355[0], 'optionalAccess', _356 => _356.delta]);
5550
- if (_optionalChain([delta, 'optionalAccess', _357 => _357.content])) {
5441
+ const delta = _optionalChain([json, 'access', _347 => _347.choices, 'optionalAccess', _348 => _348[0], 'optionalAccess', _349 => _349.delta]);
5442
+ if (_optionalChain([delta, 'optionalAccess', _350 => _350.content])) {
5551
5443
  content += delta.content;
5552
- _optionalChain([callbacks, 'access', _358 => _358.onDelta, 'optionalCall', _359 => _359(delta.content)]);
5444
+ _optionalChain([callbacks, 'access', _351 => _351.onDelta, 'optionalCall', _352 => _352(delta.content)]);
5553
5445
  }
5554
- if (_optionalChain([delta, 'optionalAccess', _360 => _360.thinking, 'optionalAccess', _361 => _361.content])) {
5446
+ if (_optionalChain([delta, 'optionalAccess', _353 => _353.thinking, 'optionalAccess', _354 => _354.content])) {
5555
5447
  reasoning += delta.thinking.content;
5556
- _optionalChain([callbacks, 'access', _362 => _362.onReasoning, 'optionalCall', _363 => _363(delta.thinking.content)]);
5448
+ _optionalChain([callbacks, 'access', _355 => _355.onReasoning, 'optionalCall', _356 => _356(delta.thinking.content)]);
5557
5449
  }
5558
- if (_optionalChain([delta, 'optionalAccess', _364 => _364.reasoning_content])) {
5450
+ if (_optionalChain([delta, 'optionalAccess', _357 => _357.reasoning_content])) {
5559
5451
  reasoning += delta.reasoning_content;
5560
- _optionalChain([callbacks, 'access', _365 => _365.onReasoning, 'optionalCall', _366 => _366(delta.reasoning_content)]);
5452
+ _optionalChain([callbacks, 'access', _358 => _358.onReasoning, 'optionalCall', _359 => _359(delta.reasoning_content)]);
5561
5453
  }
5562
5454
  if (json.usage) {
5563
5455
  const tapped = readUsageFromOpenAIResponse(json.usage);
5564
- if (_optionalChain([recording, 'optionalAccess', _367 => _367.recorder]) && tapped) {
5456
+ if (_optionalChain([recording, 'optionalAccess', _360 => _360.recorder]) && tapped) {
5565
5457
  recording.recorder.record({
5566
5458
  messageId: _nullishCoalesce(options.messageId, () => ( null)),
5567
5459
  parentMessageId: _nullishCoalesce(options.parentMessageId, () => ( null)),
@@ -5574,7 +5466,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
5574
5466
  rawUsage: json.usage
5575
5467
  });
5576
5468
  }
5577
- _optionalChain([callbacks, 'access', _368 => _368.onDone, 'optionalCall', _369 => _369(
5469
+ _optionalChain([callbacks, 'access', _361 => _361.onDone, 'optionalCall', _362 => _362(
5578
5470
  {
5579
5471
  id: messageId,
5580
5472
  role: "assistant",
@@ -5595,7 +5487,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
5595
5487
  }
5596
5488
  }
5597
5489
  }
5598
- _optionalChain([callbacks, 'access', _370 => _370.onDone, 'optionalCall', _371 => _371({
5490
+ _optionalChain([callbacks, 'access', _363 => _363.onDone, 'optionalCall', _364 => _364({
5599
5491
  id: messageId,
5600
5492
  role: "assistant",
5601
5493
  content,
@@ -5607,7 +5499,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
5607
5499
  }
5608
5500
  } catch (error) {
5609
5501
  const message = error instanceof Error ? error.message : "Unknown error";
5610
- _optionalChain([callbacks, 'access', _372 => _372.onError, 'optionalCall', _373 => _373(message)]);
5502
+ _optionalChain([callbacks, 'access', _365 => _365.onError, 'optionalCall', _366 => _366(message)]);
5611
5503
  }
5612
5504
  }
5613
5505
 
@@ -5646,8 +5538,8 @@ var CompletionService = (_class13 = class {
5646
5538
  * emission is unconditional in production. Optional — when unset (unit-test
5647
5539
  * constructors), the emit calls no-op, identical to `usageRecorder`.
5648
5540
  */
5649
- setUsageEventSink(sink2) {
5650
- this.usageEventSink = sink2;
5541
+ setUsageEventSink(sink) {
5542
+ this.usageEventSink = sink;
5651
5543
  }
5652
5544
  /**
5653
5545
  * Set the vision-fallback provider used by `applyVisionFallback` to describe
@@ -5674,8 +5566,8 @@ var CompletionService = (_class13 = class {
5674
5566
  options.providerId,
5675
5567
  options.model
5676
5568
  );
5677
- const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _374 => _374.actualProviderId]) || options.providerId;
5678
- const actualModel = _optionalChain([routedInfo, 'optionalAccess', _375 => _375.actualModelId]) || options.model;
5569
+ const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _367 => _367.actualProviderId]) || options.providerId;
5570
+ const actualModel = _optionalChain([routedInfo, 'optionalAccess', _368 => _368.actualModelId]) || options.model;
5679
5571
  const provider = await this.getProvider(actualProviderId);
5680
5572
  if (!provider) {
5681
5573
  return { success: false, error: `Provider not found: ${actualProviderId}` };
@@ -5708,7 +5600,7 @@ var CompletionService = (_class13 = class {
5708
5600
  this.apiKeyPool.reportSuccess(options.sessionId);
5709
5601
  }
5710
5602
  if (result.success && result.usage && options.sessionId) {
5711
- _optionalChain([this, 'access', _376 => _376.usageEventSink, 'optionalAccess', _377 => _377.emit, 'call', _378 => _378({
5603
+ _optionalChain([this, 'access', _369 => _369.usageEventSink, 'optionalAccess', _370 => _370.emit, 'call', _371 => _371({
5712
5604
  sessionId: options.sessionId,
5713
5605
  modelId: actualModel,
5714
5606
  usage: result.usage,
@@ -5737,8 +5629,8 @@ var CompletionService = (_class13 = class {
5737
5629
  options.model
5738
5630
  );
5739
5631
  this.logger.debug("Resolved routed model", { routedInfo });
5740
- const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _379 => _379.actualProviderId]) || options.providerId;
5741
- const actualModel = _optionalChain([routedInfo, 'optionalAccess', _380 => _380.actualModelId]) || options.model;
5632
+ const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _372 => _372.actualProviderId]) || options.providerId;
5633
+ const actualModel = _optionalChain([routedInfo, 'optionalAccess', _373 => _373.actualModelId]) || options.model;
5742
5634
  this.logger.debug("Resolved provider and model", { actualProviderId, actualModel });
5743
5635
  const provider = await this.getProvider(actualProviderId);
5744
5636
  this.logger.debug("Retrieved provider", provider ? {
@@ -5750,22 +5642,22 @@ var CompletionService = (_class13 = class {
5750
5642
  enabled: provider.enabled
5751
5643
  } : { error: "Provider not found" });
5752
5644
  if (!provider) {
5753
- _optionalChain([callbacks, 'access', _381 => _381.onError, 'optionalCall', _382 => _382(`Provider not found: ${actualProviderId}`)]);
5645
+ _optionalChain([callbacks, 'access', _374 => _374.onError, 'optionalCall', _375 => _375(`Provider not found: ${actualProviderId}`)]);
5754
5646
  return;
5755
5647
  }
5756
5648
  if (!provider.enabled) {
5757
- _optionalChain([callbacks, 'access', _383 => _383.onError, 'optionalCall', _384 => _384(`Provider is disabled: ${provider.name}`)]);
5649
+ _optionalChain([callbacks, 'access', _376 => _376.onError, 'optionalCall', _377 => _377(`Provider is disabled: ${provider.name}`)]);
5758
5650
  return;
5759
5651
  }
5760
5652
  const apiKey = await this.resolveApiKeyForRequest(provider, actualProviderId, options.sessionId);
5761
5653
  if (!apiKey) {
5762
- _optionalChain([callbacks, 'access', _385 => _385.onError, 'optionalCall', _386 => _386("API key not configured")]);
5654
+ _optionalChain([callbacks, 'access', _378 => _378.onError, 'optionalCall', _379 => _379("API key not configured")]);
5763
5655
  return;
5764
5656
  }
5765
5657
  const apiFormat = _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider);
5766
5658
  this.logger.info("Using API format for stream", { apiFormat });
5767
5659
  const messageId = `msg_${Date.now()}`;
5768
- _optionalChain([callbacks, 'access', _387 => _387.onStart, 'optionalCall', _388 => _388(messageId)]);
5660
+ _optionalChain([callbacks, 'access', _380 => _380.onStart, 'optionalCall', _381 => _381(messageId)]);
5769
5661
  const resolvedOptions = { ...options, model: actualModel };
5770
5662
  if (options.sessionId) {
5771
5663
  const sid = options.sessionId;
@@ -5774,14 +5666,14 @@ var CompletionService = (_class13 = class {
5774
5666
  ...callbacks,
5775
5667
  onDone: (message, usage, metrics) => {
5776
5668
  if (usage) {
5777
- _optionalChain([this, 'access', _389 => _389.usageEventSink, 'optionalAccess', _390 => _390.emit, 'call', _391 => _391({
5669
+ _optionalChain([this, 'access', _382 => _382.usageEventSink, 'optionalAccess', _383 => _383.emit, 'call', _384 => _384({
5778
5670
  sessionId: sid,
5779
5671
  modelId: actualModel,
5780
5672
  usage,
5781
5673
  engineOrigin: "completion"
5782
5674
  })]);
5783
5675
  }
5784
- _optionalChain([userOnDone, 'optionalCall', _392 => _392(message, usage, metrics)]);
5676
+ _optionalChain([userOnDone, 'optionalCall', _385 => _385(message, usage, metrics)]);
5785
5677
  }
5786
5678
  };
5787
5679
  }
@@ -5797,11 +5689,11 @@ var CompletionService = (_class13 = class {
5797
5689
  retryState.error = { status, message: error };
5798
5690
  return;
5799
5691
  }
5800
- _optionalChain([callbacks, 'access', _393 => _393.onError, 'optionalCall', _394 => _394(error)]);
5692
+ _optionalChain([callbacks, 'access', _386 => _386.onError, 'optionalCall', _387 => _387(error)]);
5801
5693
  },
5802
5694
  onDone: (message, usage, metrics) => {
5803
5695
  this.apiKeyPool.reportSuccess(options.sessionId);
5804
- _optionalChain([callbacks, 'access', _395 => _395.onDone, 'optionalCall', _396 => _396(message, usage, metrics)]);
5696
+ _optionalChain([callbacks, 'access', _388 => _388.onDone, 'optionalCall', _389 => _389(message, usage, metrics)]);
5805
5697
  }
5806
5698
  };
5807
5699
  await this.callStreamHandler(apiFormat, provider, apiKey, resolvedOptions, messageId, interceptCallbacks);
@@ -5822,7 +5714,7 @@ var CompletionService = (_class13 = class {
5822
5714
  // don't fire onStart again
5823
5715
  });
5824
5716
  } else {
5825
- _optionalChain([callbacks, 'access', _397 => _397.onError, 'optionalCall', _398 => _398(retryState.error.message)]);
5717
+ _optionalChain([callbacks, 'access', _390 => _390.onError, 'optionalCall', _391 => _391(retryState.error.message)]);
5826
5718
  }
5827
5719
  }
5828
5720
  } else {
@@ -5835,7 +5727,7 @@ var CompletionService = (_class13 = class {
5835
5727
  } catch (error) {
5836
5728
  const message = error instanceof Error ? error.message : "Unknown error";
5837
5729
  this.logger.error("Stream completion error", error instanceof Error ? error : void 0, { message });
5838
- _optionalChain([callbacks, 'access', _399 => _399.onError, 'optionalCall', _400 => _400(message)]);
5730
+ _optionalChain([callbacks, 'access', _392 => _392.onError, 'optionalCall', _393 => _393(message)]);
5839
5731
  }
5840
5732
  }
5841
5733
  /**
@@ -5875,7 +5767,7 @@ var CompletionService = (_class13 = class {
5875
5767
  return {
5876
5768
  success: true,
5877
5769
  message: "Connection successful",
5878
- response: _optionalChain([result, 'access', _401 => _401.message, 'optionalAccess', _402 => _402.content]) || "",
5770
+ response: _optionalChain([result, 'access', _394 => _394.message, 'optionalAccess', _395 => _395.content]) || "",
5879
5771
  model: modelId,
5880
5772
  durationMs
5881
5773
  };
@@ -5940,7 +5832,7 @@ ${description}`;
5940
5832
  * 3. Legacy single key from provider config
5941
5833
  */
5942
5834
  async resolveApiKeyForRequest(provider, providerId, sessionId) {
5943
- if (_optionalChain([provider, 'access', _403 => _403.codingPlan, 'optionalAccess', _404 => _404.enabled]) && provider.codingPlan.apiKey) {
5835
+ if (_optionalChain([provider, 'access', _396 => _396.codingPlan, 'optionalAccess', _397 => _397.enabled]) && provider.codingPlan.apiKey) {
5944
5836
  return this.resolveApiKey(provider.codingPlan.apiKey);
5945
5837
  }
5946
5838
  if (this.apiKeyPool) {
@@ -6190,7 +6082,4 @@ ${description}`;
6190
6082
 
6191
6083
 
6192
6084
 
6193
-
6194
-
6195
-
6196
- exports.CompletionService = CompletionService; exports.register = register; exports.emit = emit; exports.attach = attach; exports.release = release; exports.convertMessageToOpenAI = convertMessageToOpenAI; exports.convertMessageToAnthropic = convertMessageToAnthropic; exports.convertMessageToGemini = convertMessageToGemini; exports.getOpenRouterProviderConfig = getOpenRouterProviderConfig; exports.addOpenRouterProviderToRequest = addOpenRouterProviderToRequest; exports.DEFAULT_ROUTE_IDLE_MS = DEFAULT_ROUTE_IDLE_MS; exports.ProviderProxyRouteMap = ProviderProxyRouteMap; exports.getSharedExecutor = getSharedExecutor; exports.getResponsesEndpointTransformer = getResponsesEndpointTransformer; exports.getAnthropicEndpointTransformer = getAnthropicEndpointTransformer; exports.getGeminiEndpointTransformer = getGeminiEndpointTransformer; exports.readBody = readBody; exports.relayResponse = relayResponse; exports.writeError = writeError; exports.resolvePoolBoundKey = resolvePoolBoundKey; exports.extractRouteToken = extractRouteToken; exports.isLoopbackAddress = isLoopbackAddress; exports.ProviderProxy = ProviderProxy; exports.getProviderProxy = getProviderProxy; exports.__resetProviderProxyForTests = __resetProviderProxyForTests; exports.KeyedMutex = KeyedMutex; exports.OUTBOUND_API_SERVER_CONFIG_KEY = OUTBOUND_API_SERVER_CONFIG_KEY; exports.DEFAULT_USER_MESSAGE_QUEUE = DEFAULT_USER_MESSAGE_QUEUE; exports.DEFAULT_CONCURRENCY_QUEUE = DEFAULT_CONCURRENCY_QUEUE; exports.DEFAULT_ACCOUNT_PROBE = DEFAULT_ACCOUNT_PROBE; exports.normalizeAccountProbe = normalizeAccountProbe; exports.normalizeAudit = normalizeAudit; exports.normalizeBilling = normalizeBilling; exports.DEFAULT_FINGERPRINT = DEFAULT_FINGERPRINT; exports.normalizeFingerprint = normalizeFingerprint; exports.normalizeVoucher = normalizeVoucher; exports.normalizeProxyConfig = normalizeProxyConfig; exports.normalizeProxySegment = normalizeProxySegment; exports.normalizeWebhookDestination = normalizeWebhookDestination; exports.normalizeWebhookSegment = normalizeWebhookSegment; exports.normalizeQueueSegments = normalizeQueueSegments; exports.normalizePrefixTargets = normalizePrefixTargets; exports.defaultServerConfig = defaultServerConfig; exports.normalizeServerConfig = normalizeServerConfig; exports.loadServerConfig = loadServerConfig; exports.saveServerConfig = saveServerConfig; exports.mergeServerConfig = mergeServerConfig; exports.AUDIT_REDACTED = AUDIT_REDACTED; exports.redactAuditText = redactAuditText; exports.beginAuditCapture = beginAuditCapture; exports.beginBillingCapture = beginBillingCapture; exports.computeKeyExpiry = computeKeyExpiry; exports.checkKeyQuota = checkKeyQuota; exports.randomBase62 = randomBase62; exports.hashKey = hashKey; exports.createNamedKey = createNamedKey; exports.verifyKey = verifyKey; exports.verifyPresentedKey = verifyPresentedKey; exports.ConcurrencyQueueFullError = ConcurrencyQueueFullError; exports.ConcurrencyWaitTimeoutError = ConcurrencyWaitTimeoutError; exports.ConcurrencyWaitCancelledError = ConcurrencyWaitCancelledError; exports.isConcurrencyRejection = isConcurrencyRejection; exports.OutboundConcurrencyGate = OutboundConcurrencyGate; exports.OutboundRateLimiter = OutboundRateLimiter; exports.isUserMessageRequest = isUserMessageRequest; exports.SerialQueueTimeoutError = SerialQueueTimeoutError; exports.isSerialQueueTimeout = isSerialQueueTimeout; exports.UserMessageSerialQueue = UserMessageSerialQueue; exports.generateVoucherCode = generateVoucherCode; exports.hashVoucherCode = hashVoucherCode; exports.voucherCodePrefix = voucherCodePrefix; exports.newVoucherId = newVoucherId; exports.computeVoucherGrant = computeVoucherGrant; exports.toVoucherInfo = toVoucherInfo; exports.isRedeemRequest = isRedeemRequest; exports.handleVoucherRedeem = handleVoucherRedeem; exports.DEFAULT_OUTBOUND_PORT = DEFAULT_OUTBOUND_PORT; exports.OutboundApiConfigError = OutboundApiConfigError; exports.OutboundApiServer = OutboundApiServer; exports.formatUrls = formatUrls; exports.startOfLocalDay = startOfLocalDay; exports.startOfLocalWeek = startOfLocalWeek; exports.KeySpendTracker = KeySpendTracker; exports.getOutboundApiServer = getOutboundApiServer; exports.__resetOutboundApiServerForTests = __resetOutboundApiServerForTests;
6085
+ exports.CompletionService = CompletionService; exports.register = register; exports.emit = emit; exports.attach = attach; exports.release = release; exports.convertMessageToOpenAI = convertMessageToOpenAI; exports.convertMessageToAnthropic = convertMessageToAnthropic; exports.convertMessageToGemini = convertMessageToGemini; exports.getOpenRouterProviderConfig = getOpenRouterProviderConfig; exports.addOpenRouterProviderToRequest = addOpenRouterProviderToRequest; exports.DEFAULT_ROUTE_IDLE_MS = DEFAULT_ROUTE_IDLE_MS; exports.ProviderProxyRouteMap = ProviderProxyRouteMap; exports.getSharedExecutor = getSharedExecutor; exports.getResponsesEndpointTransformer = getResponsesEndpointTransformer; exports.getAnthropicEndpointTransformer = getAnthropicEndpointTransformer; exports.getGeminiEndpointTransformer = getGeminiEndpointTransformer; exports.readBody = readBody; exports.relayResponse = relayResponse; exports.aggregateAnthropicSseToJsonBody = aggregateAnthropicSseToJsonBody; exports.writeError = writeError; exports.resolvePoolBoundKey = resolvePoolBoundKey; exports.extractRouteToken = extractRouteToken; exports.isLoopbackAddress = isLoopbackAddress; exports.ProviderProxy = ProviderProxy; exports.getProviderProxy = getProviderProxy; exports.__resetProviderProxyForTests = __resetProviderProxyForTests; exports.KeyedMutex = KeyedMutex; exports.OUTBOUND_API_SERVER_CONFIG_KEY = OUTBOUND_API_SERVER_CONFIG_KEY; exports.DEFAULT_USER_MESSAGE_QUEUE = DEFAULT_USER_MESSAGE_QUEUE; exports.DEFAULT_CONCURRENCY_QUEUE = DEFAULT_CONCURRENCY_QUEUE; exports.DEFAULT_ACCOUNT_PROBE = DEFAULT_ACCOUNT_PROBE; exports.normalizeAccountProbe = normalizeAccountProbe; exports.normalizeAudit = normalizeAudit; exports.normalizeBilling = normalizeBilling; exports.DEFAULT_FINGERPRINT = DEFAULT_FINGERPRINT; exports.normalizeFingerprint = normalizeFingerprint; exports.normalizeVoucher = normalizeVoucher; exports.normalizeProxyConfig = normalizeProxyConfig; exports.normalizeProxySegment = normalizeProxySegment; exports.normalizeWebhookDestination = normalizeWebhookDestination; exports.normalizeWebhookSegment = normalizeWebhookSegment; exports.normalizeQueueSegments = normalizeQueueSegments; exports.normalizePrefixTargets = normalizePrefixTargets; exports.defaultServerConfig = defaultServerConfig; exports.normalizeServerConfig = normalizeServerConfig; exports.loadServerConfig = loadServerConfig; exports.saveServerConfig = saveServerConfig; exports.mergeServerConfig = mergeServerConfig; exports.computeKeyExpiry = computeKeyExpiry; exports.checkKeyQuota = checkKeyQuota; exports.randomBase62 = randomBase62; exports.hashKey = hashKey; exports.createNamedKey = createNamedKey; exports.verifyKey = verifyKey; exports.verifyPresentedKey = verifyPresentedKey; exports.ConcurrencyQueueFullError = ConcurrencyQueueFullError; exports.ConcurrencyWaitTimeoutError = ConcurrencyWaitTimeoutError; exports.ConcurrencyWaitCancelledError = ConcurrencyWaitCancelledError; exports.isConcurrencyRejection = isConcurrencyRejection; exports.OutboundConcurrencyGate = OutboundConcurrencyGate; exports.OutboundRateLimiter = OutboundRateLimiter; exports.isUserMessageRequest = isUserMessageRequest; exports.SerialQueueTimeoutError = SerialQueueTimeoutError; exports.isSerialQueueTimeout = isSerialQueueTimeout; exports.UserMessageSerialQueue = UserMessageSerialQueue; exports.generateVoucherCode = generateVoucherCode; exports.hashVoucherCode = hashVoucherCode; exports.voucherCodePrefix = voucherCodePrefix; exports.newVoucherId = newVoucherId; exports.computeVoucherGrant = computeVoucherGrant; exports.toVoucherInfo = toVoucherInfo; exports.isRedeemRequest = isRedeemRequest; exports.handleVoucherRedeem = handleVoucherRedeem; exports.DEFAULT_OUTBOUND_PORT = DEFAULT_OUTBOUND_PORT; exports.OutboundApiConfigError = OutboundApiConfigError; exports.OutboundApiServer = OutboundApiServer; exports.formatUrls = formatUrls; exports.startOfLocalDay = startOfLocalDay; exports.startOfLocalWeek = startOfLocalWeek; exports.KeySpendTracker = KeySpendTracker; exports.getOutboundApiServer = getOutboundApiServer; exports.__resetOutboundApiServerForTests = __resetOutboundApiServerForTests;