@omnicross/core 0.4.4 → 0.4.6

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 (109) hide show
  1. package/dist/{CompletionService-BniP7j88.d.cts → CompletionService-BJu4AWVc.d.cts} +1 -1
  2. package/dist/{CompletionService-BqrKPwfA.d.ts → CompletionService-C4W2gBi_.d.ts} +1 -1
  3. package/dist/{ProviderProxy-Ckr6oTrE.d.ts → ProviderProxy-DxsNi3cO.d.ts} +1 -1
  4. package/dist/{ProviderProxy-Bz_nkOwq.d.cts → ProviderProxy-OuQPYW2I.d.cts} +1 -1
  5. package/dist/auth/GeminiCodeAssistProjectResolver.cjs +4 -4
  6. package/dist/auth/GeminiCodeAssistProjectResolver.js +3 -3
  7. package/dist/{chunk-NKVZ6Z3Y.cjs → chunk-4HMAS74X.cjs} +8 -3
  8. package/dist/{chunk-MPFOC7AT.js → chunk-5XG6FR5F.js} +2 -2
  9. package/dist/{chunk-VFFCV4J6.cjs → chunk-CXRJMNJJ.cjs} +12 -6
  10. package/dist/{chunk-E5RCCGE7.cjs → chunk-DF5JXK36.cjs} +2 -2
  11. package/dist/{chunk-NCZDUBC2.js → chunk-DRUT7H5H.js} +1 -1
  12. package/dist/{chunk-RX3BCX53.cjs → chunk-DV7656NN.cjs} +1208 -527
  13. package/dist/{chunk-CGEZQC2G.cjs → chunk-F3TT5XPV.cjs} +2 -2
  14. package/dist/{chunk-EE7VP4O3.js → chunk-HQ7C3VB6.js} +1 -1
  15. package/dist/{chunk-ZJJBITUN.js → chunk-IAWLTZUP.js} +2 -2
  16. package/dist/{chunk-57Y2EA2G.cjs → chunk-JGRNVH7C.cjs} +1 -1
  17. package/dist/{chunk-NTF7TLT7.js → chunk-LBIXTHP7.js} +11 -5
  18. package/dist/{chunk-GWC7HCZI.cjs → chunk-LWBXQXZ3.cjs} +1 -1
  19. package/dist/{chunk-7PIUVCKK.js → chunk-MZCJL3QU.js} +1 -1
  20. package/dist/{chunk-K6J2RIEX.js → chunk-NDJSLJIA.js} +1 -1
  21. package/dist/{chunk-UOOLU64V.cjs → chunk-QLVRJ5FS.cjs} +4 -4
  22. package/dist/{chunk-F6P4DIBL.js → chunk-TLYFFUW4.js} +1 -1
  23. package/dist/{chunk-YV4JSBPA.js → chunk-TU4BB776.js} +789 -108
  24. package/dist/{chunk-GL6XM527.js → chunk-TX7ZM4OI.js} +8 -3
  25. package/dist/{chunk-ZMERU7D3.js → chunk-VXHN5IDL.js} +1 -1
  26. package/dist/{chunk-NDIBVTBZ.cjs → chunk-XYFCNDJK.cjs} +2 -2
  27. package/dist/{chunk-X6GHTNDL.cjs → chunk-ZG57GAVU.cjs} +7 -7
  28. package/dist/{chunk-QWNUOR7F.cjs → chunk-ZTN2PVKO.cjs} +1 -1
  29. package/dist/completion/CompletionService.cjs +12 -12
  30. package/dist/completion/CompletionService.d.cts +2 -2
  31. package/dist/completion/CompletionService.d.ts +2 -2
  32. package/dist/completion/CompletionService.js +11 -11
  33. package/dist/completion.cjs +12 -12
  34. package/dist/completion.d.cts +2 -2
  35. package/dist/completion.d.ts +2 -2
  36. package/dist/completion.js +11 -11
  37. package/dist/image-generation.d.cts +4 -4
  38. package/dist/image-generation.d.ts +4 -4
  39. package/dist/index.cjs +14 -12
  40. package/dist/index.d.cts +7 -7
  41. package/dist/index.d.ts +7 -7
  42. package/dist/index.js +13 -11
  43. package/dist/openai-operation.d.cts +1 -1
  44. package/dist/openai-operation.d.ts +1 -1
  45. package/dist/outbound-api/routeResolver.cjs +2 -2
  46. package/dist/outbound-api/routeResolver.d.cts +5 -5
  47. package/dist/outbound-api/routeResolver.d.ts +5 -5
  48. package/dist/outbound-api/routeResolver.js +1 -1
  49. package/dist/outbound-api/subscriptionRegistryPort.d.cts +9 -1
  50. package/dist/outbound-api/subscriptionRegistryPort.d.ts +9 -1
  51. package/dist/outbound-api/types.d.cts +5 -5
  52. package/dist/outbound-api/types.d.ts +5 -5
  53. package/dist/outbound-api.cjs +14 -12
  54. package/dist/outbound-api.d.cts +49 -8
  55. package/dist/outbound-api.d.ts +49 -8
  56. package/dist/outbound-api.js +13 -11
  57. package/dist/pipeline/AccountAllowanceScheduling.d.cts +4 -4
  58. package/dist/pipeline/AccountAllowanceScheduling.d.ts +4 -4
  59. package/dist/pipeline/AccountRouteActivity.cjs +2 -2
  60. package/dist/pipeline/AccountRouteActivity.d.cts +33 -8
  61. package/dist/pipeline/AccountRouteActivity.d.ts +33 -8
  62. package/dist/pipeline/AccountRouteActivity.js +1 -1
  63. package/dist/pipeline/SubscriptionAuthSource.d.cts +11 -0
  64. package/dist/pipeline/SubscriptionAuthSource.d.ts +11 -0
  65. package/dist/pipeline/upstreamFetch.cjs +3 -3
  66. package/dist/pipeline/upstreamFetch.d.cts +15 -1
  67. package/dist/pipeline/upstreamFetch.d.ts +15 -1
  68. package/dist/pipeline/upstreamFetch.js +2 -2
  69. package/dist/ports.d.cts +4 -4
  70. package/dist/ports.d.ts +4 -4
  71. package/dist/provider-proxy/ProviderProxy.cjs +12 -12
  72. package/dist/provider-proxy/ProviderProxy.d.cts +2 -2
  73. package/dist/provider-proxy/ProviderProxy.d.ts +2 -2
  74. package/dist/provider-proxy/ProviderProxy.js +11 -11
  75. package/dist/provider-proxy/identity/codexCliHeaders.d.cts +6 -4
  76. package/dist/provider-proxy/identity/codexCliHeaders.d.ts +6 -4
  77. package/dist/provider-proxy/identity/openCodeGoHeaders.cjs +2 -2
  78. package/dist/provider-proxy/identity/openCodeGoHeaders.js +1 -1
  79. package/dist/provider-proxy/ingress/providerProxyShared.cjs +20 -12
  80. package/dist/provider-proxy/ingress/providerProxyShared.d.cts +54 -2
  81. package/dist/provider-proxy/ingress/providerProxyShared.d.ts +54 -2
  82. package/dist/provider-proxy/ingress/providerProxyShared.js +19 -11
  83. package/dist/provider-proxy/types.d.cts +1 -1
  84. package/dist/provider-proxy/types.d.ts +1 -1
  85. package/dist/provider-proxy.cjs +12 -12
  86. package/dist/provider-proxy.d.cts +6 -6
  87. package/dist/provider-proxy.d.ts +6 -6
  88. package/dist/provider-proxy.js +11 -11
  89. package/dist/{routeResolver-C2z0pp-q.d.cts → routeResolver-BQYMEXer.d.cts} +2 -2
  90. package/dist/{routeResolver-BLTleO4H.d.ts → routeResolver-DTfyzaFb.d.ts} +2 -2
  91. package/dist/transformer/transformers/AntigravityTransformer.cjs +6 -6
  92. package/dist/transformer/transformers/AntigravityTransformer.js +5 -5
  93. package/dist/transformer/transformers/OpenAITransformer.cjs +2 -2
  94. package/dist/transformer/transformers/OpenAITransformer.js +1 -1
  95. package/dist/transformer/transformers/antigravityFailover.cjs +7 -7
  96. package/dist/transformer/transformers/antigravityFailover.js +6 -6
  97. package/dist/transformer/transformers/antigravityIdentity.cjs +4 -4
  98. package/dist/transformer/transformers/antigravityIdentity.js +3 -3
  99. package/dist/transformer/transformers.cjs +9 -9
  100. package/dist/transformer/transformers.js +8 -8
  101. package/dist/transformer.cjs +9 -9
  102. package/dist/transformer.js +8 -8
  103. package/dist/{types-C6m-Db26.d.cts → types-BpSkj2JA.d.cts} +66 -5
  104. package/dist/{types-BVwJQ9ZS.d.cts → types-BsZ1s_a_.d.cts} +1 -1
  105. package/dist/{types-By9Tg6-I.d.ts → types-Di8VH1c9.d.ts} +12 -0
  106. package/dist/{types-BSIJdsyl.d.cts → types-Dpr5IAaP.d.cts} +12 -0
  107. package/dist/{types-Da735j2d.d.ts → types-EReErShW.d.ts} +66 -5
  108. package/dist/{types-VAHRysdP.d.ts → types-USaixzVP.d.ts} +1 -1
  109. package/package.json +2 -2
@@ -11,7 +11,7 @@ var _chunkVGBJPHHDcjs = require('./chunk-VGBJPHHD.cjs');
11
11
 
12
12
 
13
13
 
14
- var _chunkCGEZQC2Gcjs = require('./chunk-CGEZQC2G.cjs');
14
+ var _chunkF3TT5XPVcjs = require('./chunk-F3TT5XPV.cjs');
15
15
 
16
16
 
17
17
  var _chunkBTSADEX4cjs = require('./chunk-BTSADEX4.cjs');
@@ -53,7 +53,7 @@ var _chunkRPII3E6Zcjs = require('./chunk-RPII3E6Z.cjs');
53
53
  var _chunk6RPZADX3cjs = require('./chunk-6RPZADX3.cjs');
54
54
 
55
55
 
56
- var _chunkGWC7HCZIcjs = require('./chunk-GWC7HCZI.cjs');
56
+ var _chunkLWBXQXZ3cjs = require('./chunk-LWBXQXZ3.cjs');
57
57
 
58
58
 
59
59
 
@@ -118,7 +118,7 @@ var _chunk4YINUUKQcjs = require('./chunk-4YINUUKQ.cjs');
118
118
 
119
119
 
120
120
 
121
- var _chunk57Y2EA2Gcjs = require('./chunk-57Y2EA2G.cjs');
121
+ var _chunkJGRNVH7Ccjs = require('./chunk-JGRNVH7C.cjs');
122
122
 
123
123
 
124
124
  var _chunkQBZJ7P2Tcjs = require('./chunk-QBZJ7P2T.cjs');
@@ -147,19 +147,20 @@ var _chunkA2YMUCBTcjs = require('./chunk-A2YMUCBT.cjs');
147
147
  var _chunkGDIXXKF2cjs = require('./chunk-GDIXXKF2.cjs');
148
148
 
149
149
 
150
- var _chunkNDIBVTBZcjs = require('./chunk-NDIBVTBZ.cjs');
150
+ var _chunkXYFCNDJKcjs = require('./chunk-XYFCNDJK.cjs');
151
+
151
152
 
152
153
 
153
154
  var _chunkIUL4VWNUcjs = require('./chunk-IUL4VWNU.cjs');
154
155
 
155
156
 
156
- var _chunkVFFCV4J6cjs = require('./chunk-VFFCV4J6.cjs');
157
+ var _chunkCXRJMNJJcjs = require('./chunk-CXRJMNJJ.cjs');
157
158
 
158
159
 
159
160
  var _chunkVYOBVPNBcjs = require('./chunk-VYOBVPNB.cjs');
160
161
 
161
162
 
162
- var _chunkNKVZ6Z3Ycjs = require('./chunk-NKVZ6Z3Y.cjs');
163
+ var _chunk4HMAS74Xcjs = require('./chunk-4HMAS74X.cjs');
163
164
 
164
165
 
165
166
 
@@ -896,6 +897,124 @@ async function aggregateAnthropicSseToJsonBody(response, rewriteModel, signal) {
896
897
  if (rewriteModel) message["model"] = rewriteModel;
897
898
  return JSON.stringify(message);
898
899
  }
900
+ async function aggregateResponsesSseToJsonBody(response, rewriteModel, signal) {
901
+ const text = await readResponseTextWithSignal(response, signal);
902
+ let terminal = null;
903
+ for (const raw of text.split("\n")) {
904
+ const line = raw.trim();
905
+ if (!line.startsWith("data:")) continue;
906
+ const payload = line.slice(5).trim();
907
+ if (!payload || payload === "[DONE]") continue;
908
+ try {
909
+ const ev = JSON.parse(payload);
910
+ if (ev["type"] === "response.completed" || ev["type"] === "response.failed" || ev["type"] === "response.incomplete") {
911
+ const resp = ev["response"];
912
+ if (resp && typeof resp === "object") terminal = resp;
913
+ }
914
+ } catch (e11) {
915
+ }
916
+ }
917
+ if (!terminal) return null;
918
+ if (rewriteModel && typeof terminal["model"] === "string") terminal["model"] = rewriteModel;
919
+ return JSON.stringify(terminal);
920
+ }
921
+ async function aggregateOpenAIChatChunksToJsonBody(response, rewriteModel, signal) {
922
+ const text = await readResponseTextWithSignal(response, signal);
923
+ let id;
924
+ let created;
925
+ let model;
926
+ let content = "";
927
+ let reasoning = "";
928
+ let finishReason = null;
929
+ let usage;
930
+ const toolCalls = /* @__PURE__ */ new Map();
931
+ let sawChoice = false;
932
+ for (const raw of text.split("\n")) {
933
+ const line = raw.trim();
934
+ if (!line.startsWith("data:")) continue;
935
+ const payload = line.slice(5).trim();
936
+ if (!payload || payload === "[DONE]") continue;
937
+ let ev;
938
+ try {
939
+ ev = JSON.parse(payload);
940
+ } catch (e12) {
941
+ continue;
942
+ }
943
+ if (typeof ev["id"] === "string" && id === void 0) id = ev["id"];
944
+ if (typeof ev["created"] === "number" && created === void 0) created = ev["created"];
945
+ if (typeof ev["model"] === "string" && model === void 0) model = ev["model"];
946
+ if (ev["usage"] && typeof ev["usage"] === "object") {
947
+ usage = ev["usage"];
948
+ }
949
+ const choices = ev["choices"];
950
+ if (!Array.isArray(choices) || choices.length === 0) continue;
951
+ const choice = choices[0];
952
+ if (!choice || typeof choice !== "object") continue;
953
+ sawChoice = true;
954
+ if (typeof choice["finish_reason"] === "string") finishReason = choice["finish_reason"];
955
+ const delta = choice["delta"];
956
+ if (!delta || typeof delta !== "object") continue;
957
+ const d = delta;
958
+ if (typeof d["content"] === "string") content += d["content"];
959
+ if (typeof d["reasoning_content"] === "string") reasoning += d["reasoning_content"];
960
+ const thinking = d["thinking"];
961
+ if (thinking && typeof thinking === "object") {
962
+ const tc = thinking["content"];
963
+ if (typeof tc === "string") reasoning += tc;
964
+ } else if (typeof thinking === "string") {
965
+ reasoning += thinking;
966
+ }
967
+ const tcs = d["tool_calls"];
968
+ if (Array.isArray(tcs)) {
969
+ for (const tcRaw of tcs) {
970
+ if (!tcRaw || typeof tcRaw !== "object") continue;
971
+ const tc = tcRaw;
972
+ const idx = typeof tc["index"] === "number" ? tc["index"] : 0;
973
+ const fn = _nullishCoalesce(tc["function"], () => ( {}));
974
+ const slot = _nullishCoalesce(toolCalls.get(idx), () => ( { id: "", name: "", arguments: "" }));
975
+ if (typeof tc["id"] === "string" && tc["id"]) slot.id = tc["id"];
976
+ if (typeof fn["name"] === "string" && fn["name"]) slot.name = fn["name"];
977
+ if (typeof fn["arguments"] === "string") slot.arguments += fn["arguments"];
978
+ toolCalls.set(idx, slot);
979
+ }
980
+ }
981
+ }
982
+ if (!sawChoice && !usage) return null;
983
+ const message = { role: "assistant", content };
984
+ if (reasoning) message["reasoning_content"] = reasoning;
985
+ if (toolCalls.size > 0) {
986
+ message["tool_calls"] = [...toolCalls.entries()].sort((a, b) => a[0] - b[0]).map(([index, tc]) => ({
987
+ index,
988
+ id: tc.id,
989
+ type: "function",
990
+ function: { name: tc.name, arguments: tc.arguments || "{}" }
991
+ }));
992
+ }
993
+ const completion = {
994
+ id: _nullishCoalesce(id, () => ( "chatcmpl-aggregated")),
995
+ object: "chat.completion",
996
+ created: _nullishCoalesce(created, () => ( Math.floor(Date.now() / 1e3))),
997
+ model: _nullishCoalesce(_nullishCoalesce(rewriteModel, () => ( model)), () => ( "")),
998
+ choices: [{ index: 0, message, finish_reason: _nullishCoalesce(finishReason, () => ( "stop")) }]
999
+ };
1000
+ if (usage) completion["usage"] = usage;
1001
+ return JSON.stringify(completion);
1002
+ }
1003
+ async function sniffIsSseResponse(response) {
1004
+ const contentType = _nullishCoalesce(response.headers.get("Content-Type"), () => ( ""));
1005
+ if (contentType.includes("text/event-stream")) return true;
1006
+ if (!response.body) return false;
1007
+ const peek = response.clone();
1008
+ try {
1009
+ const reader = peek.body.getReader();
1010
+ const { value } = await reader.read();
1011
+ reader.releaseLock();
1012
+ const head = value ? new TextDecoder().decode(value).trimStart() : "";
1013
+ return head.startsWith("event:") || head.startsWith("data:");
1014
+ } catch (e13) {
1015
+ return false;
1016
+ }
1017
+ }
899
1018
  function writeError(res, status, message) {
900
1019
  if (isAnthropicProtocolResponse(res)) {
901
1020
  writeAnthropicError(res, status, message);
@@ -953,6 +1072,21 @@ async function resolvePoolBoundKey(deps, providerId, provider, sessionId, prefer
953
1072
  }
954
1073
  return resolveApiKey(_chunkA2YMUCBTcjs.resolveProviderEndpoint.call(void 0, provider).apiKey);
955
1074
  }
1075
+ function buildByoRouteActivityMeta(deps, providerId, sessionId) {
1076
+ return {
1077
+ providerId,
1078
+ resolveKeyId: () => {
1079
+ if (!sessionId) return void 0;
1080
+ const pool = deps.apiKeyPool;
1081
+ if (!pool || typeof pool.getKeyIdForSession !== "function") return void 0;
1082
+ try {
1083
+ return _nullishCoalesce(pool.getKeyIdForSession(providerId, sessionId), () => ( void 0));
1084
+ } catch (e14) {
1085
+ return void 0;
1086
+ }
1087
+ }
1088
+ };
1089
+ }
956
1090
 
957
1091
  // src/provider-proxy/providerProxyRouteMap.ts
958
1092
  var _crypto = require('crypto');
@@ -996,7 +1130,7 @@ var ProviderProxyRouteMap = (_class = class {
996
1130
  if (!entry) return void 0;
997
1131
  try {
998
1132
  _optionalChain([entry, 'access', _43 => _43.onActivity, 'optionalCall', _44 => _44(Date.now())]);
999
- } catch (e11) {
1133
+ } catch (e15) {
1000
1134
  }
1001
1135
  this.armIdleTimer(token, entry);
1002
1136
  return entry.context;
@@ -1056,7 +1190,7 @@ var ProviderProxyRouteMap = (_class = class {
1056
1190
  this.clearIdleTimer(entry);
1057
1191
  try {
1058
1192
  _optionalChain([entry, 'access', _48 => _48.onEvicted, 'optionalCall', _49 => _49(reason)]);
1059
- } catch (e12) {
1193
+ } catch (e16) {
1060
1194
  }
1061
1195
  }
1062
1196
  }, _class);
@@ -1525,13 +1659,13 @@ function recordAnthropicNonStreamUsage(recorder, bodyText, attribution) {
1525
1659
  parsed.usage,
1526
1660
  attribution
1527
1661
  );
1528
- } catch (e13) {
1662
+ } catch (e17) {
1529
1663
  }
1530
1664
  }
1531
1665
  function recordAnthropicStreamUsage(recorder, rawUsage, attribution) {
1532
1666
  try {
1533
1667
  emitAnthropicUsageRecord(recorder, rawUsage, attribution);
1534
- } catch (e14) {
1668
+ } catch (e18) {
1535
1669
  }
1536
1670
  }
1537
1671
 
@@ -1595,7 +1729,7 @@ async function buildSubscriptionIterationPlan(profile, route, deps, resolvedMode
1595
1729
  });
1596
1730
  const bearer = (_nullishCoalesce(_nullishCoalesce(headers.Authorization, () => ( headers.authorization)), () => ( ""))).replace(/^Bearer\s+/i, "").trim();
1597
1731
  if (bearer) {
1598
- transformerProvider.geminiProject = await _chunkNDIBVTBZcjs.getAntigravityProjectResolver.call(void 0, ).resolveProject(bearer);
1732
+ transformerProvider.geminiProject = await _chunkXYFCNDJKcjs.getAntigravityProjectResolver.call(void 0, ).resolveProject(bearer);
1599
1733
  }
1600
1734
  }
1601
1735
  return {
@@ -1666,6 +1800,31 @@ function collectText(value) {
1666
1800
  function proxyProviderId(plan) {
1667
1801
  return plan.isSubscription ? plan.transformerProvider.name : "byo";
1668
1802
  }
1803
+ function buildAnthropicRouteActivity(plan, proxyAccountId, model, onRecorded) {
1804
+ if (!plan.isSubscription) {
1805
+ const routeSessionId = plan.byoSessionId || void 0;
1806
+ return {
1807
+ providerId: _nullishCoalesce(_optionalChain([plan, 'access', _107 => _107.byoActivity, 'optionalAccess', _108 => _108.providerId]), () => ( plan.transformerProvider.name)),
1808
+ credentialKind: "provider-key",
1809
+ keyId: _optionalChain([plan, 'access', _109 => _109.byoActivity, 'optionalAccess', _110 => _110.resolveKeyId, 'call', _111 => _111()]),
1810
+ endpoint: "messages",
1811
+ sessionKey: routeSessionId,
1812
+ sessionSource: routeSessionId ? "route-session-id" : "none",
1813
+ model,
1814
+ onRecorded
1815
+ };
1816
+ }
1817
+ return {
1818
+ providerId: proxyProviderId(plan),
1819
+ credentialKind: "subscription-account",
1820
+ accountId: proxyAccountId,
1821
+ endpoint: "messages",
1822
+ sessionKey: plan.sessionKey,
1823
+ sessionSource: plan.sessionKey ? "content-fingerprint" : "none",
1824
+ model,
1825
+ onRecorded
1826
+ };
1827
+ }
1669
1828
  async function runPipeline(anthropicBody, plan, reportSelection, signal, callerOpenCodeSession) {
1670
1829
  const executor = getSharedExecutor();
1671
1830
  const endpointTransformer = getAnthropicEndpointTransformer();
@@ -1682,12 +1841,12 @@ async function runPipeline(anthropicBody, plan, reportSelection, signal, callerO
1682
1841
  boundAccountFallbackPolicy: plan.boundAccountFallbackPolicy,
1683
1842
  reportSelection: (accountId, isActive) => {
1684
1843
  proxyAccountId = accountId;
1685
- _optionalChain([reportSelection, 'optionalCall', _107 => _107(accountId, isActive)]);
1844
+ _optionalChain([reportSelection, 'optionalCall', _112 => _112(accountId, isActive)]);
1686
1845
  }
1687
1846
  });
1688
1847
  if (plan.transformerProvider.name === "antigravity") {
1689
1848
  const bearer = (_nullishCoalesce(_nullishCoalesce(authHeaders.Authorization, () => ( authHeaders.authorization)), () => ( ""))).replace(/^Bearer\s+/i, "").trim();
1690
- if (bearer) transformerProvider.geminiProject = await _chunkNDIBVTBZcjs.getAntigravityProjectResolver.call(void 0, ).resolveProject(bearer);
1849
+ if (bearer) transformerProvider.geminiProject = await _chunkXYFCNDJKcjs.getAntigravityProjectResolver.call(void 0, ).resolveProject(bearer);
1691
1850
  }
1692
1851
  let rawStatus = null;
1693
1852
  let activityRecordId;
@@ -1709,21 +1868,20 @@ async function runPipeline(anthropicBody, plan, reportSelection, signal, callerO
1709
1868
  },
1710
1869
  fetchFn: (url, headers, body) => {
1711
1870
  console.info(`[ProviderProxy:anthropic] -> ${url} model=${resolvedModel} stream=${isStream}`);
1712
- return _chunkVFFCV4J6cjs.fetchUpstream.call(void 0,
1871
+ return _chunkCXRJMNJJcjs.fetchUpstream.call(void 0,
1713
1872
  url,
1714
1873
  { method: "POST", headers, body: JSON.stringify(body), signal },
1715
1874
  {
1716
1875
  providerId: proxyProviderId(plan),
1717
1876
  accountId: proxyAccountId,
1718
- routeActivity: plan.isSubscription ? {
1719
- endpoint: "messages",
1720
- sessionKey: plan.sessionKey,
1721
- sessionSource: plan.sessionKey ? "content-fingerprint" : "none",
1722
- model: resolvedModel,
1723
- onRecorded: (record5) => {
1877
+ routeActivity: buildAnthropicRouteActivity(
1878
+ plan,
1879
+ proxyAccountId,
1880
+ resolvedModel,
1881
+ (record5) => {
1724
1882
  activityRecordId = record5.id;
1725
1883
  }
1726
- } : void 0
1884
+ )
1727
1885
  }
1728
1886
  ).then((r) => {
1729
1887
  rawStatus = r.status;
@@ -1749,7 +1907,7 @@ async function runSubscriptionSameFormatFetch(rawBody, plan, reportSelection, op
1749
1907
  reportSelection: (accountId, isActive, remapped) => {
1750
1908
  proxyAccountId = accountId;
1751
1909
  remappedModel = remapped;
1752
- _optionalChain([reportSelection, 'optionalCall', _108 => _108(accountId, isActive, remapped)]);
1910
+ _optionalChain([reportSelection, 'optionalCall', _113 => _113(accountId, isActive, remapped)]);
1753
1911
  }
1754
1912
  });
1755
1913
  const isClaudeSubscription = plan.isSubscription && plan.transformerProvider.name === "claude";
@@ -1780,21 +1938,20 @@ async function runSubscriptionSameFormatFetch(rawBody, plan, reportSelection, op
1780
1938
  `[ProviderProxy:anthropic] (subscription same-format) -> ${_nullishCoalesce(urlOverride, () => ( plan.upstreamUrl))} model=${outboundModel} stream=${plan.isStream}`
1781
1939
  );
1782
1940
  let activityRecordId;
1783
- const response = await _chunkVFFCV4J6cjs.fetchUpstream.call(void 0,
1941
+ const response = await _chunkCXRJMNJJcjs.fetchUpstream.call(void 0,
1784
1942
  _nullishCoalesce(urlOverride, () => ( plan.upstreamUrl)),
1785
1943
  { method: "POST", headers, body: outboundBody, signal: options.signal },
1786
1944
  {
1787
1945
  providerId: proxyProviderId(plan),
1788
1946
  accountId: proxyAccountId,
1789
- routeActivity: plan.isSubscription ? {
1790
- endpoint: "messages",
1791
- sessionKey: plan.sessionKey,
1792
- sessionSource: plan.sessionKey ? "content-fingerprint" : "none",
1793
- model: outboundModel,
1794
- onRecorded: (record5) => {
1947
+ routeActivity: buildAnthropicRouteActivity(
1948
+ plan,
1949
+ proxyAccountId,
1950
+ outboundModel,
1951
+ (record5) => {
1795
1952
  activityRecordId = record5.id;
1796
1953
  }
1797
- } : void 0
1954
+ )
1798
1955
  }
1799
1956
  );
1800
1957
  return {
@@ -1814,7 +1971,7 @@ function rewriteBodyModel(rawBody, model) {
1814
1971
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return rawBody;
1815
1972
  parsed.model = model;
1816
1973
  return JSON.stringify(parsed);
1817
- } catch (e15) {
1974
+ } catch (e19) {
1818
1975
  return rawBody;
1819
1976
  }
1820
1977
  }
@@ -1833,7 +1990,7 @@ async function runSubscriptionAttemptWith401Retry(anthropicBody, relayBody, plan
1833
1990
  const first = await runOnce();
1834
1991
  let result = first;
1835
1992
  if (first.rawStatus === 401) {
1836
- const refreshed = await _optionalChain([plan, 'access', _109 => _109.auth, 'access', _110 => _110.onUnauthorized, 'optionalCall', _111 => _111(plan.sessionKey)]);
1993
+ const refreshed = await _optionalChain([plan, 'access', _114 => _114.auth, 'access', _115 => _115.onUnauthorized, 'optionalCall', _116 => _116(plan.sessionKey)]);
1837
1994
  if (refreshed) {
1838
1995
  console.info("[ProviderProxy:anthropic] 401 \u2192 token refreshed; retrying once");
1839
1996
  await cancelDiscardedResponse(first.response);
@@ -1849,7 +2006,7 @@ async function readBoundedBody(response, max = 2048) {
1849
2006
  try {
1850
2007
  const text = await response.clone().text();
1851
2008
  return text.slice(0, max);
1852
- } catch (e16) {
2009
+ } catch (e20) {
1853
2010
  return void 0;
1854
2011
  }
1855
2012
  }
@@ -1865,8 +2022,8 @@ async function markSubscriptionHealth(plan, selectedAccountId, result) {
1865
2022
  if (errorBody) {
1866
2023
  try {
1867
2024
  const parsed = JSON.parse(errorBody);
1868
- if (typeof _optionalChain([parsed, 'access', _112 => _112.error, 'optionalAccess', _113 => _113.type]) === "string") upstreamErrorType = parsed.error.type;
1869
- } catch (e17) {
2025
+ if (typeof _optionalChain([parsed, 'access', _117 => _117.error, 'optionalAccess', _118 => _118.type]) === "string") upstreamErrorType = parsed.error.type;
2026
+ } catch (e21) {
1870
2027
  }
1871
2028
  }
1872
2029
  }
@@ -1889,7 +2046,7 @@ function breakerOutcome(rawStatus) {
1889
2046
  function recordBreakerOutcome(profile, modelId, rawStatus) {
1890
2047
  const outcome = breakerOutcome(rawStatus);
1891
2048
  if (outcome === "neutral") return;
1892
- _optionalChain([profile, 'optionalAccess', _114 => _114.recordModelOutcome, 'optionalCall', _115 => _115(modelId, outcome === "success")]);
2049
+ _optionalChain([profile, 'optionalAccess', _119 => _119.recordModelOutcome, 'optionalCall', _120 => _120(modelId, outcome === "success")]);
1893
2050
  }
1894
2051
  async function runSubscriptionAttemptOutcome(anthropicBody, relayBody, plan, options = {}) {
1895
2052
  try {
@@ -1908,20 +2065,20 @@ function settleOutcome(outcome) {
1908
2065
  async function runPipelineWithSubscriptionRetry(anthropicBody, rawBody, initialPlan, route, deps, options = {}, prepareTranslateBody) {
1909
2066
  const profile = route.subscriptionProfile;
1910
2067
  const scenario = initialPlan.scenario;
1911
- const clientGone = () => _optionalChain([options, 'access', _116 => _116.signal, 'optionalAccess', _117 => _117.aborted]) === true;
2068
+ const clientGone = () => _optionalChain([options, 'access', _121 => _121.signal, 'optionalAccess', _122 => _122.aborted]) === true;
1912
2069
  const prepareTranslateAttempt = async (body) => {
1913
2070
  if (!prepareTranslateBody) return body;
1914
2071
  const clone = JSON.parse(JSON.stringify(body));
1915
2072
  await prepareTranslateBody(clone);
1916
2073
  return clone;
1917
2074
  };
1918
- if (!_optionalChain([profile, 'optionalAccess', _118 => _118.nextFallback]) || scenario === void 0) {
2075
+ if (!_optionalChain([profile, 'optionalAccess', _123 => _123.nextFallback]) || scenario === void 0) {
1919
2076
  const loneBody = initialPlan.sameFormat ? anthropicBody : await prepareTranslateAttempt(anthropicBody);
1920
2077
  let loneOutcome = await runSubscriptionAttemptOutcome(loneBody, rawBody, initialPlan, options);
1921
2078
  if (!clientGone()) recordBreakerOutcome(profile, initialPlan.resolvedModel, outcomeStatus(loneOutcome));
1922
2079
  if (initialPlan.transformerProvider.name === "antigravity" && !clientGone() && outcomeStatus(loneOutcome) !== null && !is2xxStatus(outcomeStatus(loneOutcome))) {
1923
2080
  const bodyText = loneOutcome.kind === "result" ? await readBoundedBody(loneOutcome.result.response) : void 0;
1924
- const failoverUrl = _chunkCGEZQC2Gcjs.maybeAntigravityFailoverUrl.call(void 0,
2081
+ const failoverUrl = _chunkF3TT5XPVcjs.maybeAntigravityFailoverUrl.call(void 0,
1925
2082
  initialPlan.upstreamUrl,
1926
2083
  outcomeStatus(loneOutcome),
1927
2084
  bodyText
@@ -2011,7 +2168,7 @@ function withUpstreamUrl(plan, url) {
2011
2168
  const original = new URL(resolved);
2012
2169
  const target = new URL(url);
2013
2170
  return `${target.origin}${original.pathname}${original.search}`;
2014
- } catch (e18) {
2171
+ } catch (e22) {
2015
2172
  return url;
2016
2173
  }
2017
2174
  }
@@ -2031,7 +2188,7 @@ var MAX_CMAP_ENTRIES = 65536;
2031
2188
  function extractPdfText(base64, budgetMs = DEFAULT_PDF_TEXT_BUDGET_MS) {
2032
2189
  try {
2033
2190
  return extract(Buffer.from(base64, "base64"), budgetMs);
2034
- } catch (e19) {
2191
+ } catch (e23) {
2035
2192
  return { reason: "no-text-layer" };
2036
2193
  }
2037
2194
  }
@@ -2307,8 +2464,8 @@ async function prepareAnthropicTranslateBody(body, pdfBudgetMs) {
2307
2464
  }
2308
2465
  async function prepareDocumentBlock(block, pdfBudgetMs) {
2309
2466
  const source = block["source"];
2310
- const mediaType = _optionalChain([source, 'optionalAccess', _119 => _119["media_type"]]);
2311
- const data = _optionalChain([source, 'optionalAccess', _120 => _120["data"]]);
2467
+ const mediaType = _optionalChain([source, 'optionalAccess', _124 => _124["media_type"]]);
2468
+ const data = _optionalChain([source, 'optionalAccess', _125 => _125["data"]]);
2312
2469
  if (!source || source["type"] !== "base64" || mediaType !== "application/pdf" || typeof data !== "string") {
2313
2470
  throw new DocumentNotSupportedError(
2314
2471
  "no-text-layer",
@@ -2355,10 +2512,10 @@ function emitResponsesUsageRecord(recorder, rawUsage, attribution) {
2355
2512
  providerId: attribution.providerId,
2356
2513
  model: attribution.model,
2357
2514
  apiKeyId: attribution.apiKeyId,
2358
- runId: _nullishCoalesce(_optionalChain([attribution, 'access', _121 => _121.routeLease, 'optionalAccess', _122 => _122.runId]), () => ( null)),
2359
- routeLeaseId: _nullishCoalesce(_optionalChain([attribution, 'access', _123 => _123.routeLease, 'optionalAccess', _124 => _124.leaseId]), () => ( null)),
2360
- routeLeaseConsumer: _nullishCoalesce(_optionalChain([attribution, 'access', _125 => _125.routeLease, 'optionalAccess', _126 => _126.consumer]), () => ( null)),
2361
- routeLeaseStageId: _nullishCoalesce(_optionalChain([attribution, 'access', _127 => _127.routeLease, 'optionalAccess', _128 => _128.stageId]), () => ( null)),
2515
+ runId: _nullishCoalesce(_optionalChain([attribution, 'access', _126 => _126.routeLease, 'optionalAccess', _127 => _127.runId]), () => ( null)),
2516
+ routeLeaseId: _nullishCoalesce(_optionalChain([attribution, 'access', _128 => _128.routeLease, 'optionalAccess', _129 => _129.leaseId]), () => ( null)),
2517
+ routeLeaseConsumer: _nullishCoalesce(_optionalChain([attribution, 'access', _130 => _130.routeLease, 'optionalAccess', _131 => _131.consumer]), () => ( null)),
2518
+ routeLeaseStageId: _nullishCoalesce(_optionalChain([attribution, 'access', _132 => _132.routeLease, 'optionalAccess', _133 => _133.stageId]), () => ( null)),
2362
2519
  cacheKeySource: attribution.cacheKeySource,
2363
2520
  cacheKeyInjected: attribution.cacheKeyInjected,
2364
2521
  auditResponse: attribution.auditResponse,
@@ -2375,13 +2532,13 @@ function recordResponsesNonStreamUsage(recorder, bodyText, attribution) {
2375
2532
  parsed.usage,
2376
2533
  attribution
2377
2534
  );
2378
- } catch (e20) {
2535
+ } catch (e24) {
2379
2536
  }
2380
2537
  }
2381
2538
  function recordResponsesStreamUsage(recorder, rawUsage, attribution) {
2382
2539
  try {
2383
2540
  emitResponsesUsageRecord(recorder, rawUsage, attribution);
2384
- } catch (e21) {
2541
+ } catch (e25) {
2385
2542
  }
2386
2543
  }
2387
2544
 
@@ -2407,21 +2564,21 @@ function parseCodexUsageLimitErrorPayload(bodyText) {
2407
2564
  if (!raw.startsWith("{")) return null;
2408
2565
  try {
2409
2566
  const parsed = JSON.parse(raw);
2410
- const error = _optionalChain([parsed, 'optionalAccess', _129 => _129.error]);
2411
- const code = _optionalChain([error, 'optionalAccess', _130 => _130.code]);
2567
+ const error = _optionalChain([parsed, 'optionalAccess', _134 => _134.error]);
2568
+ const code = _optionalChain([error, 'optionalAccess', _135 => _135.code]);
2412
2569
  if (typeof code !== "string" || !CODEX_USAGE_LIMIT_ERROR_CODES.has(code)) return null;
2413
- const resetsAt = _optionalChain([error, 'optionalAccess', _131 => _131.resets_at]);
2570
+ const resetsAt = _optionalChain([error, 'optionalAccess', _136 => _136.resets_at]);
2414
2571
  let resetsAtMs;
2415
2572
  if (typeof resetsAt === "number" && Number.isFinite(resetsAt) && resetsAt > 0) {
2416
2573
  resetsAtMs = resetsAt > 1e11 ? resetsAt : resetsAt * 1e3;
2417
2574
  }
2418
- const planType = _optionalChain([error, 'optionalAccess', _132 => _132.plan_type]);
2575
+ const planType = _optionalChain([error, 'optionalAccess', _137 => _137.plan_type]);
2419
2576
  return {
2420
2577
  code,
2421
2578
  ...resetsAtMs !== void 0 ? { resetsAtMs } : {},
2422
2579
  ...typeof planType === "string" && planType ? { planType } : {}
2423
2580
  };
2424
- } catch (e22) {
2581
+ } catch (e26) {
2425
2582
  return null;
2426
2583
  }
2427
2584
  }
@@ -2431,11 +2588,11 @@ function deadlineFromAllowanceSnapshot(accountId, now) {
2431
2588
  const candidates = snapshot.windows.filter(
2432
2589
  (w) => typeof w.usedPercent === "number" && w.usedPercent >= QUOTA_EXHAUSTED_PERCENT && typeof w.resetsAt === "string"
2433
2590
  ).map((w) => ({ ms: Date.parse(w.resetsAt), usedPercent: w.usedPercent })).filter((x) => Number.isFinite(x.ms) && x.ms > now).sort((a, b) => b.usedPercent - a.usedPercent);
2434
- return _optionalChain([candidates, 'access', _133 => _133[0], 'optionalAccess', _134 => _134.ms]);
2591
+ return _optionalChain([candidates, 'access', _138 => _138[0], 'optionalAccess', _139 => _139.ms]);
2435
2592
  }
2436
2593
  function resolveCodexQuotaDeadline(accountId, bodyText, now = Date.now()) {
2437
2594
  const structured = parseCodexUsageLimitErrorPayload(bodyText);
2438
- const structuredDeadline = _optionalChain([structured, 'optionalAccess', _135 => _135.resetsAtMs]) !== void 0 && structured.resetsAtMs > now ? structured.resetsAtMs : void 0;
2595
+ const structuredDeadline = _optionalChain([structured, 'optionalAccess', _140 => _140.resetsAtMs]) !== void 0 && structured.resetsAtMs > now ? structured.resetsAtMs : void 0;
2439
2596
  const parsed = parseTryAgainDeadline(bodyText);
2440
2597
  const parsedDeadline = parsed !== void 0 && parsed > now ? parsed : void 0;
2441
2598
  return _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(deadlineFromAllowanceSnapshot(accountId, now), () => ( structuredDeadline)), () => ( parsedDeadline)), () => ( now + DEFAULT_QUOTA_COOLDOWN_MS));
@@ -2487,7 +2644,7 @@ function normalizeHostedImageState(value) {
2487
2644
  hasImageContext: value.hasImageContext,
2488
2645
  pendingReceipts: Object.freeze(pendingReceipts)
2489
2646
  });
2490
- } catch (e23) {
2647
+ } catch (e27) {
2491
2648
  throw new TypeError(INVALID_HOSTED_IMAGE_METADATA);
2492
2649
  }
2493
2650
  }
@@ -2531,7 +2688,7 @@ var ResponsesAffinityStore = (_class6 = class {
2531
2688
  const entry = this.entries.get(responseId);
2532
2689
  const now = this.now();
2533
2690
  if (!entry || entry.expiresAt <= now || entry.providerId !== scope.providerId || entry.clientScope !== scope.clientScope || entry.sessionKey !== scope.sessionKey) {
2534
- if (_optionalChain([entry, 'optionalAccess', _136 => _136.expiresAt]) !== void 0 && entry.expiresAt <= now) {
2691
+ if (_optionalChain([entry, 'optionalAccess', _141 => _141.expiresAt]) !== void 0 && entry.expiresAt <= now) {
2535
2692
  this.entries.delete(responseId);
2536
2693
  }
2537
2694
  throw previousResponseNotFound();
@@ -2566,7 +2723,7 @@ function classifyResponsesProfile(declaration) {
2566
2723
  if (declaration.authMode === "byo") {
2567
2724
  return declaration.providerApiFormat === "openai-response" ? "native" : "reduced";
2568
2725
  }
2569
- if (declaration.subscriptionProviderId === "codex" && _optionalChain([declaration, 'access', _137 => _137.subscriptionTransformerNames, 'optionalAccess', _138 => _138.includes, 'call', _139 => _139("openai-response")]) && isResponsesCreateUrl(declaration.upstreamUrl)) {
2726
+ if (declaration.subscriptionProviderId === "codex" && _optionalChain([declaration, 'access', _142 => _142.subscriptionTransformerNames, 'optionalAccess', _143 => _143.includes, 'call', _144 => _144("openai-response")]) && isResponsesCreateUrl(declaration.upstreamUrl)) {
2570
2727
  return "native";
2571
2728
  }
2572
2729
  return "reduced";
@@ -2586,7 +2743,7 @@ function isResponsesCreateUrl(value) {
2586
2743
  if (!value) return false;
2587
2744
  try {
2588
2745
  return new URL(value).pathname.replace(/\/+$/, "").endsWith("/responses");
2589
- } catch (e24) {
2746
+ } catch (e28) {
2590
2747
  return false;
2591
2748
  }
2592
2749
  }
@@ -2756,7 +2913,7 @@ function deriveResponsesCompactUrl(createUrl) {
2756
2913
  let url;
2757
2914
  try {
2758
2915
  url = new URL(createUrl);
2759
- } catch (e25) {
2916
+ } catch (e29) {
2760
2917
  throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({
2761
2918
  status: 502,
2762
2919
  code: "invalid_upstream_url",
@@ -2798,7 +2955,7 @@ async function resolveResponsesRouteProfile(route, deps, resolvedModel) {
2798
2955
  if (!subscriptionProfile) {
2799
2956
  throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({ status: 502, code: "provider_configuration_error", message: "Subscription route is missing its profile" });
2800
2957
  }
2801
- const upstreamUrl = _optionalChain([subscriptionProfile, 'access', _140 => _140.resolveUpstreamUrl, 'optionalCall', _141 => _141(resolvedModel)]);
2958
+ const upstreamUrl = _optionalChain([subscriptionProfile, 'access', _145 => _145.resolveUpstreamUrl, 'optionalCall', _146 => _146(resolvedModel)]);
2802
2959
  if (!upstreamUrl) {
2803
2960
  throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({ status: 502, code: "provider_configuration_error", message: "Subscription profile is missing its Responses URL" });
2804
2961
  }
@@ -2818,7 +2975,7 @@ async function resolveResponsesRouteProfile(route, deps, resolvedModel) {
2818
2975
  }
2819
2976
  async function buildResponsesCallPlan(route, deps, resolved, resolvedModel, isStream, sessionKey, sessionSource, requestHeaders, affinity) {
2820
2977
  if (route.authMode === "byo") {
2821
- return buildByoPlan(route, deps, resolved, resolvedModel, isStream, affinity);
2978
+ return buildByoPlan(route, deps, resolved, resolvedModel, isStream, sessionKey, sessionSource, affinity);
2822
2979
  }
2823
2980
  return buildSubscriptionPlan2(
2824
2981
  route,
@@ -2832,10 +2989,10 @@ async function buildResponsesCallPlan(route, deps, resolved, resolvedModel, isSt
2832
2989
  affinity
2833
2990
  );
2834
2991
  }
2835
- async function buildByoPlan(route, deps, resolved, resolvedModel, isStream, affinity) {
2992
+ async function buildByoPlan(route, deps, resolved, resolvedModel, isStream, sessionKey, sessionSource, affinity) {
2836
2993
  const providerId = route.providerId;
2837
2994
  const provider = resolved.provider;
2838
- const affinityKeyId = _optionalChain([affinity, 'optionalAccess', _142 => _142.credential, 'access', _143 => _143.kind]) === "byo-key" ? affinity.credential.id : void 0;
2995
+ const affinityKeyId = _optionalChain([affinity, 'optionalAccess', _147 => _147.credential, 'access', _148 => _148.kind]) === "byo-key" ? affinity.credential.id : void 0;
2839
2996
  const preferredKeyId = _nullishCoalesce(affinityKeyId, () => ( route.preferredKeyId));
2840
2997
  const apiKey = await resolvePoolBoundKey(
2841
2998
  deps,
@@ -2849,7 +3006,7 @@ async function buildByoPlan(route, deps, resolved, resolvedModel, isStream, affi
2849
3006
  if (affinity) throw previousResponseNotFound();
2850
3007
  throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({ status: 502, code: "provider_configuration_error", message: "Provider credential is unavailable" });
2851
3008
  }
2852
- const selectedKeyId = _nullishCoalesce(preferredKeyId, () => ( (route.sessionId && typeof _optionalChain([deps, 'access', _144 => _144.apiKeyPool, 'optionalAccess', _145 => _145.getKeyIdForSession]) === "function" ? _nullishCoalesce(deps.apiKeyPool.getKeyIdForSession(providerId, route.sessionId), () => ( void 0)) : void 0)));
3009
+ const selectedKeyId = _nullishCoalesce(preferredKeyId, () => ( (route.sessionId && typeof _optionalChain([deps, 'access', _149 => _149.apiKeyPool, 'optionalAccess', _150 => _150.getKeyIdForSession]) === "function" ? _nullishCoalesce(deps.apiKeyPool.getKeyIdForSession(providerId, route.sessionId), () => ( void 0)) : void 0)));
2853
3010
  const credential = selectedKeyId ? { kind: "byo-key", id: selectedKeyId } : { kind: "provider-key", id: providerId };
2854
3011
  const auth = affinityKeyId ? new (0, _chunkTX4UCSOPcjs.LlmConfigProviderAuth)({ provider, apiKey, apiKeyPool: null, providerId, sessionId: route.sessionId }) : _nullishCoalesce(route.auth, () => ( new (0, _chunkTX4UCSOPcjs.LlmConfigProviderAuth)({
2855
3012
  provider,
@@ -2881,15 +3038,19 @@ async function buildByoPlan(route, deps, resolved, resolvedModel, isStream, affi
2881
3038
  statefulContinuation: !!affinity,
2882
3039
  credential,
2883
3040
  resolveCredential: () => {
2884
- const keyId = route.sessionId && typeof _optionalChain([deps, 'access', _146 => _146.apiKeyPool, 'optionalAccess', _147 => _147.getKeyIdForSession]) === "function" ? deps.apiKeyPool.getKeyIdForSession(providerId, route.sessionId) : null;
3041
+ const keyId = route.sessionId && typeof _optionalChain([deps, 'access', _151 => _151.apiKeyPool, 'optionalAccess', _152 => _152.getKeyIdForSession]) === "function" ? deps.apiKeyPool.getKeyIdForSession(providerId, route.sessionId) : null;
2885
3042
  return keyId ? { kind: "byo-key", id: keyId } : credential;
2886
- }
3043
+ },
3044
+ byoActivity: buildByoRouteActivityMeta(deps, providerId, route.sessionId),
3045
+ byoSessionId: _nullishCoalesce(route.sessionId, () => ( null)),
3046
+ sessionKey,
3047
+ sessionSource
2887
3048
  };
2888
3049
  }
2889
3050
  async function buildSubscriptionPlan2(route, deps, resolved, resolvedModel, isStream, sessionKey, sessionSource, requestHeaders, affinity) {
2890
3051
  const profile = route.subscriptionProfile;
2891
3052
  const upstreamUrl = resolved.upstreamUrl;
2892
- const affinityAccountId = _optionalChain([affinity, 'optionalAccess', _148 => _148.credential, 'access', _149 => _149.kind]) === "subscription-account" ? affinity.credential.id : void 0;
3053
+ const affinityAccountId = _optionalChain([affinity, 'optionalAccess', _153 => _153.credential, 'access', _154 => _154.kind]) === "subscription-account" ? affinity.credential.id : void 0;
2893
3054
  const auth = _nullishCoalesce(route.auth, () => ( new (0, _chunkRXMF7GNFcjs.SubscriptionAuthSource)(profile)));
2894
3055
  const chain = resolved.profile === "native" ? { providerTransformers: [], modelTransformers: [] } : _chunkNYUNU75Acjs.resolveSubscriptionChain.call(void 0,
2895
3056
  profile,
@@ -2942,7 +3103,7 @@ async function buildSubscriptionPlan2(route, deps, resolved, resolvedModel, isSt
2942
3103
  callerClientHeaders: profile.authStrategy.providerId === "codex" ? _chunkSQU2FGXIcjs.extractCodexClientHeaders.call(void 0, requestHeaders) : void 0,
2943
3104
  // opencodego-egress-identity: the caller's own session id, forwarded
2944
3105
  // verbatim to opencode.ai (the codex callerClientHeaders precedent).
2945
- callerOpenCodeSession: profile.authStrategy.providerId === "opencodego" ? _chunkGWC7HCZIcjs.extractOpenCodeSessionHeader.call(void 0, requestHeaders) : void 0,
3106
+ callerOpenCodeSession: profile.authStrategy.providerId === "opencodego" ? _chunkLWBXQXZ3cjs.extractOpenCodeSessionHeader.call(void 0, requestHeaders) : void 0,
2946
3107
  statefulContinuation: !!affinity,
2947
3108
  credential: affinityAccountId ? { kind: "subscription-account", id: affinityAccountId } : { kind: "subscription-account", id: "pending-selection" }
2948
3109
  };
@@ -2952,14 +3113,15 @@ async function resolveGeminiProject(profile, hints) {
2952
3113
  await profile.authStrategy.applyHeaders(headers, hints);
2953
3114
  const accessToken = (_nullishCoalesce(_nullishCoalesce(headers.Authorization, () => ( headers.authorization)), () => ( ""))).replace(/^Bearer\s+/i, "").trim();
2954
3115
  if (!accessToken) return void 0;
2955
- return _optionalChain([_chunkR3HK6R4Bcjs.getGeminiCodeAssistResolver.call(void 0, ), 'optionalAccess', _150 => _150.resolveProject, 'call', _151 => _151(accessToken)]);
3116
+ return _optionalChain([_chunkR3HK6R4Bcjs.getGeminiCodeAssistResolver.call(void 0, ), 'optionalAccess', _155 => _155.resolveProject, 'call', _156 => _156(accessToken)]);
2956
3117
  }
3118
+ var resolveGeminiProjectForChatBridge = resolveGeminiProject;
2957
3119
  async function resolveAntigravityProjectThreaded(profile, hints) {
2958
3120
  const headers = {};
2959
3121
  await profile.authStrategy.applyHeaders(headers, hints);
2960
3122
  const accessToken = (_nullishCoalesce(_nullishCoalesce(headers.Authorization, () => ( headers.authorization)), () => ( ""))).replace(/^Bearer\s+/i, "").trim();
2961
3123
  if (!accessToken) return void 0;
2962
- return _chunkNDIBVTBZcjs.getAntigravityProjectResolver.call(void 0, ).resolveProject(accessToken);
3124
+ return _chunkXYFCNDJKcjs.getAntigravityProjectResolver.call(void 0, ).resolveProject(accessToken);
2963
3125
  }
2964
3126
  async function executeResponsesUpstream(body, plan, operation, signal) {
2965
3127
  const run = () => plan.profile === "native" ? runNative(body, plan, operation, signal) : runReduced(body, plan, signal);
@@ -2967,16 +3129,16 @@ async function executeResponsesUpstream(body, plan, operation, signal) {
2967
3129
  throwIfResponsesAborted(signal);
2968
3130
  if (!plan.statefulContinuation) {
2969
3131
  if (plan.proxyProviderId === "byo") {
2970
- const outcome = await _optionalChain([plan, 'access', _152 => _152.auth, 'access', _153 => _153.onResult, 'optionalCall', _154 => _154(result.rawStatus)]);
2971
- if (_optionalChain([outcome, 'optionalAccess', _155 => _155.rebound])) {
2972
- await _optionalChain([result, 'access', _156 => _156.response, 'access', _157 => _157.body, 'optionalAccess', _158 => _158.cancel, 'call', _159 => _159(), 'access', _160 => _160.catch, 'call', _161 => _161(() => void 0)]);
3132
+ const outcome = await _optionalChain([plan, 'access', _157 => _157.auth, 'access', _158 => _158.onResult, 'optionalCall', _159 => _159(result.rawStatus)]);
3133
+ if (_optionalChain([outcome, 'optionalAccess', _160 => _160.rebound])) {
3134
+ await _optionalChain([result, 'access', _161 => _161.response, 'access', _162 => _162.body, 'optionalAccess', _163 => _163.cancel, 'call', _164 => _164(), 'access', _165 => _165.catch, 'call', _166 => _166(() => void 0)]);
2973
3135
  throwIfResponsesAborted(signal);
2974
3136
  result = await run();
2975
3137
  }
2976
3138
  } else if (result.rawStatus === 401) {
2977
- const refreshed = await _optionalChain([plan, 'access', _162 => _162.auth, 'access', _163 => _163.onUnauthorized, 'optionalCall', _164 => _164(plan.sessionKey)]);
3139
+ const refreshed = await _optionalChain([plan, 'access', _167 => _167.auth, 'access', _168 => _168.onUnauthorized, 'optionalCall', _169 => _169(plan.sessionKey)]);
2978
3140
  if (refreshed) {
2979
- await _optionalChain([result, 'access', _165 => _165.response, 'access', _166 => _166.body, 'optionalAccess', _167 => _167.cancel, 'call', _168 => _168(), 'access', _169 => _169.catch, 'call', _170 => _170(() => void 0)]);
3141
+ await _optionalChain([result, 'access', _170 => _170.response, 'access', _171 => _171.body, 'optionalAccess', _172 => _172.cancel, 'call', _173 => _173(), 'access', _174 => _174.catch, 'call', _175 => _175(() => void 0)]);
2980
3142
  throwIfResponsesAborted(signal);
2981
3143
  result = await run();
2982
3144
  }
@@ -2985,6 +3147,32 @@ async function executeResponsesUpstream(body, plan, operation, signal) {
2985
3147
  }
2986
3148
  return result;
2987
3149
  }
3150
+ function buildResponsesRouteActivity(plan, accountId, actualModel, onRecorded) {
3151
+ if (plan.proxyProviderId === "byo") {
3152
+ const contentKey = _optionalChain([plan, 'access', _176 => _176.sessionKey, 'optionalAccess', _177 => _177.trim, 'call', _178 => _178()]) || void 0;
3153
+ const routeSessionId = plan.byoSessionId || void 0;
3154
+ return {
3155
+ providerId: _nullishCoalesce(_optionalChain([plan, 'access', _179 => _179.byoActivity, 'optionalAccess', _180 => _180.providerId]), () => ( plan.providerIdentity)),
3156
+ credentialKind: "provider-key",
3157
+ keyId: _optionalChain([plan, 'access', _181 => _181.byoActivity, 'optionalAccess', _182 => _182.resolveKeyId, 'call', _183 => _183()]),
3158
+ endpoint: "responses",
3159
+ sessionKey: _nullishCoalesce(contentKey, () => ( routeSessionId)),
3160
+ sessionSource: contentKey ? _nullishCoalesce(plan.sessionSource, () => ( "none")) : routeSessionId ? "route-session-id" : "none",
3161
+ model: actualModel,
3162
+ onRecorded
3163
+ };
3164
+ }
3165
+ return {
3166
+ providerId: plan.proxyProviderId,
3167
+ credentialKind: "subscription-account",
3168
+ accountId,
3169
+ endpoint: "responses",
3170
+ sessionKey: plan.sessionKey,
3171
+ sessionSource: _nullishCoalesce(plan.sessionSource, () => ( "none")),
3172
+ model: actualModel,
3173
+ onRecorded
3174
+ };
3175
+ }
2988
3176
  async function applyPlanAuth(body, plan) {
2989
3177
  let accountId;
2990
3178
  let actualModel = plan.resolvedModel;
@@ -3004,12 +3192,16 @@ async function applyPlanAuth(body, plan) {
3004
3192
  });
3005
3193
  body.model = actualModel;
3006
3194
  plan.transformerProvider.models = [actualModel];
3195
+ if (plan.proxyProviderId === "codex") {
3196
+ body.store = false;
3197
+ if (!plan.isStream) body.stream = true;
3198
+ }
3007
3199
  return { headers, accountId, actualModel };
3008
3200
  }
3009
3201
  function decorateCodexHeaders(headers, plan) {
3010
3202
  if (plan.proxyProviderId !== "codex") return;
3011
3203
  _chunkUKQHBK4Qcjs.fillMissingHeaders.call(void 0, headers, _nullishCoalesce(plan.callerClientHeaders, () => ( {})));
3012
- _chunkUKQHBK4Qcjs.fillMissingHeaders.call(void 0, headers, { accept: _chunkSQU2FGXIcjs.codexAcceptHeader.call(void 0, plan.isStream) });
3204
+ _chunkUKQHBK4Qcjs.fillMissingHeaders.call(void 0, headers, { accept: _chunkSQU2FGXIcjs.codexAcceptHeader.call(void 0, true) });
3013
3205
  _chunkSQU2FGXIcjs.fillMissingCodexCliIdentity.call(void 0, headers);
3014
3206
  }
3015
3207
  async function runNative(body, plan, operation, signal) {
@@ -3019,21 +3211,15 @@ async function runNative(body, plan, operation, signal) {
3019
3211
  decorateCodexHeaders(headers, plan);
3020
3212
  const url = operation === "compact" ? deriveResponsesCompactUrl(plan.upstreamUrl) : plan.upstreamUrl;
3021
3213
  let activityRecordId;
3022
- const response = await _chunkVFFCV4J6cjs.fetchUpstream.call(void 0,
3214
+ const response = await _chunkCXRJMNJJcjs.fetchUpstream.call(void 0,
3023
3215
  url,
3024
3216
  { method: "POST", headers, body: JSON.stringify(body), signal },
3025
3217
  {
3026
3218
  providerId: plan.proxyProviderId,
3027
3219
  accountId,
3028
- routeActivity: plan.proxyProviderId === "byo" ? void 0 : {
3029
- endpoint: "responses",
3030
- sessionKey: plan.sessionKey,
3031
- sessionSource: _nullishCoalesce(plan.sessionSource, () => ( "none")),
3032
- model: actualModel,
3033
- onRecorded: (record5) => {
3034
- activityRecordId = record5.id;
3035
- }
3036
- }
3220
+ routeActivity: buildResponsesRouteActivity(plan, accountId, actualModel, (record5) => {
3221
+ activityRecordId = record5.id;
3222
+ })
3037
3223
  }
3038
3224
  );
3039
3225
  return {
@@ -3042,7 +3228,7 @@ async function runNative(body, plan, operation, signal) {
3042
3228
  accountId,
3043
3229
  actualModel,
3044
3230
  activityRecordId,
3045
- credential: accountId ? { kind: "subscription-account", id: accountId } : _nullishCoalesce(_optionalChain([plan, 'access', _171 => _171.resolveCredential, 'optionalCall', _172 => _172()]), () => ( plan.credential))
3231
+ credential: accountId ? { kind: "subscription-account", id: accountId } : _nullishCoalesce(_optionalChain([plan, 'access', _184 => _184.resolveCredential, 'optionalCall', _185 => _185()]), () => ( plan.credential))
3046
3232
  };
3047
3233
  }
3048
3234
  async function runReduced(body, plan, signal) {
@@ -3050,7 +3236,7 @@ async function runReduced(body, plan, signal) {
3050
3236
  const { headers: authHeaders, accountId, actualModel } = await applyPlanAuth(body, plan);
3051
3237
  if (plan.proxyProviderId === "antigravity") {
3052
3238
  const bearer = (_nullishCoalesce(_nullishCoalesce(authHeaders.Authorization, () => ( authHeaders.authorization)), () => ( ""))).replace(/^Bearer\s+/i, "").trim();
3053
- if (bearer) plan.transformerProvider.geminiProject = await _chunkNDIBVTBZcjs.getAntigravityProjectResolver.call(void 0, ).resolveProject(bearer);
3239
+ if (bearer) plan.transformerProvider.geminiProject = await _chunkXYFCNDJKcjs.getAntigravityProjectResolver.call(void 0, ).resolveProject(bearer);
3054
3240
  }
3055
3241
  let rawStatus = null;
3056
3242
  let activityRecordId;
@@ -3072,24 +3258,18 @@ async function runReduced(body, plan, signal) {
3072
3258
  return headers;
3073
3259
  },
3074
3260
  fetchFn: async (url, headers, requestBody) => {
3075
- const send = (target) => _chunkVFFCV4J6cjs.fetchUpstream.call(void 0,
3261
+ const send = (target) => _chunkCXRJMNJJcjs.fetchUpstream.call(void 0,
3076
3262
  target,
3077
3263
  { method: "POST", headers, body: JSON.stringify(requestBody), signal },
3078
3264
  {
3079
3265
  providerId: plan.proxyProviderId,
3080
3266
  accountId,
3081
- routeActivity: plan.proxyProviderId === "byo" ? void 0 : {
3082
- endpoint: "responses",
3083
- sessionKey: plan.sessionKey,
3084
- sessionSource: _nullishCoalesce(plan.sessionSource, () => ( "none")),
3085
- model: actualModel,
3086
- onRecorded: (record5) => {
3087
- activityRecordId = record5.id;
3088
- }
3089
- }
3267
+ routeActivity: buildResponsesRouteActivity(plan, accountId, actualModel, (record5) => {
3268
+ activityRecordId = record5.id;
3269
+ })
3090
3270
  }
3091
3271
  );
3092
- const upstream = plan.proxyProviderId === "antigravity" ? await _chunkCGEZQC2Gcjs.fetchWithAntigravityFailover.call(void 0, url, send, signal) : await send(url);
3272
+ const upstream = plan.proxyProviderId === "antigravity" ? await _chunkF3TT5XPVcjs.fetchWithAntigravityFailover.call(void 0, url, send, signal) : await send(url);
3093
3273
  rawStatus = upstream.status;
3094
3274
  return upstream;
3095
3275
  },
@@ -3102,7 +3282,7 @@ async function runReduced(body, plan, signal) {
3102
3282
  accountId,
3103
3283
  actualModel,
3104
3284
  activityRecordId,
3105
- credential: accountId ? { kind: "subscription-account", id: accountId } : _nullishCoalesce(_optionalChain([plan, 'access', _173 => _173.resolveCredential, 'optionalCall', _174 => _174()]), () => ( plan.credential))
3285
+ credential: accountId ? { kind: "subscription-account", id: accountId } : _nullishCoalesce(_optionalChain([plan, 'access', _186 => _186.resolveCredential, 'optionalCall', _187 => _187()]), () => ( plan.credential))
3106
3286
  };
3107
3287
  }
3108
3288
  var MAX_QUOTA_RETRIES = 3;
@@ -3125,7 +3305,7 @@ function record(value) {
3125
3305
  return !!value && typeof value === "object" && !Array.isArray(value);
3126
3306
  }
3127
3307
  function hasResponsesHostedImageWork(body, previousState) {
3128
- if (_optionalChain([previousState, 'optionalAccess', _175 => _175.hasImageContext]) || _optionalChain([previousState, 'optionalAccess', _176 => _176.pendingReceipts, 'access', _177 => _177.length])) return true;
3308
+ if (_optionalChain([previousState, 'optionalAccess', _188 => _188.hasImageContext]) || _optionalChain([previousState, 'optionalAccess', _189 => _189.pendingReceipts, 'access', _190 => _190.length])) return true;
3129
3309
  if (Array.isArray(body.tools) && body.tools.some((tool) => record(tool) && tool.type === "image_generation")) {
3130
3310
  return true;
3131
3311
  }
@@ -3309,7 +3489,7 @@ function createNonCollidingSelectorName(tools, createName) {
3309
3489
  let candidate;
3310
3490
  try {
3311
3491
  candidate = createName();
3312
- } catch (e26) {
3492
+ } catch (e30) {
3313
3493
  throw new (0, _chunkINY54AYXcjs.ImageGenerationError)("image_generation_failed");
3314
3494
  }
3315
3495
  if (typeof candidate === "string" && SELECTOR_NAME_PATTERN.test(candidate) && !declaredNames.has(candidate)) {
@@ -3328,7 +3508,7 @@ function parseSelectorPrompt(value) {
3328
3508
  let parsed;
3329
3509
  try {
3330
3510
  parsed = JSON.parse(value);
3331
- } catch (e27) {
3511
+ } catch (e31) {
3332
3512
  protocolFailure();
3333
3513
  }
3334
3514
  if (!isRecord4(parsed) || Object.keys(parsed).some((key) => key !== "prompt") || typeof parsed.prompt !== "string" || !parsed.prompt.trim() || parsed.prompt.length > 32e3) {
@@ -3545,7 +3725,7 @@ function parseSelectorArguments(value) {
3545
3725
  let parsed;
3546
3726
  try {
3547
3727
  parsed = JSON.parse(value);
3548
- } catch (e28) {
3728
+ } catch (e32) {
3549
3729
  return void 0;
3550
3730
  }
3551
3731
  if (!isRecord5(parsed) || typeof parsed.query !== "string") return void 0;
@@ -3673,7 +3853,7 @@ var NativeResponsesSearchLease = class {
3673
3853
  let parsed;
3674
3854
  try {
3675
3855
  parsed = JSON.parse(text);
3676
- } catch (e29) {
3856
+ } catch (e33) {
3677
3857
  return responseWithBody(input.response, text, false);
3678
3858
  }
3679
3859
  if (!isRecord6(parsed)) return responseWithBody(input.response, text, false);
@@ -3774,18 +3954,18 @@ function responsesSearchDisabledError() {
3774
3954
  var SERVER_OVERLOADED_CODES = /* @__PURE__ */ new Set(["server_is_overloaded", "slow_down"]);
3775
3955
  function isCodexServerOverloadEvent(event) {
3776
3956
  const error = codexResponseFailedError(event);
3777
- const code = _optionalChain([error, 'optionalAccess', _178 => _178["code"]]);
3957
+ const code = _optionalChain([error, 'optionalAccess', _191 => _191["code"]]);
3778
3958
  return typeof code === "string" && SERVER_OVERLOADED_CODES.has(code);
3779
3959
  }
3780
3960
  function codexResponseFailedError(event) {
3781
3961
  if (event["type"] !== "response.failed") return void 0;
3782
- const error = _optionalChain([event, 'access', _179 => _179["response"], 'optionalAccess', _180 => _180["error"]]);
3962
+ const error = _optionalChain([event, 'access', _192 => _192["response"], 'optionalAccess', _193 => _193["error"]]);
3783
3963
  return error && typeof error === "object" ? error : void 0;
3784
3964
  }
3785
3965
  var USAGE_LIMIT_CODES = /* @__PURE__ */ new Set(["usage_limit_reached", "usage_not_included"]);
3786
3966
  function isCodexUsageLimitEvent(event) {
3787
3967
  const error = codexResponseFailedError(event);
3788
- const code = _optionalChain([error, 'optionalAccess', _181 => _181["code"]]);
3968
+ const code = _optionalChain([error, 'optionalAccess', _194 => _194["code"]]);
3789
3969
  return typeof code === "string" && USAGE_LIMIT_CODES.has(code);
3790
3970
  }
3791
3971
  function codexUsageLimitEventBody(event) {
@@ -3819,7 +3999,7 @@ async function handleOpenAIResponsesRequest(res, rawBody, route, deps, requestHe
3819
3999
  let parsedBody;
3820
4000
  try {
3821
4001
  parsedBody = JSON.parse(rawBody);
3822
- } catch (e30) {
4002
+ } catch (e34) {
3823
4003
  writeError(res, 400, "Invalid JSON in request body");
3824
4004
  return;
3825
4005
  }
@@ -3832,7 +4012,7 @@ async function handleOpenAIResponsesRequest(res, rawBody, route, deps, requestHe
3832
4012
  return;
3833
4013
  }
3834
4014
  const responsesBody = parsedBody;
3835
- _optionalChain([onStreamModeResolved, 'optionalCall', _182 => _182(responsesBody.stream === true)]);
4015
+ _optionalChain([onStreamModeResolved, 'optionalCall', _195 => _195(responsesBody.stream === true)]);
3836
4016
  try {
3837
4017
  await handleResponsesOperation(
3838
4018
  res,
@@ -3912,7 +4092,7 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
3912
4092
  throw error;
3913
4093
  }
3914
4094
  const cacheKeyAttribution = operation === "create" ? ensureCodexPromptCacheKey(responsesBody, plan.proxyProviderId, derivedSession) : { cacheKeySource: "none", cacheKeyInjected: false };
3915
- const previousHostedImageState = _optionalChain([affinity, 'optionalAccess', _183 => _183.hostedImage]);
4095
+ const previousHostedImageState = _optionalChain([affinity, 'optionalAccess', _196 => _196.hostedImage]);
3916
4096
  const hasHostedImageWork = operation === "create" && hasResponsesHostedImageWork(
3917
4097
  responsesBody,
3918
4098
  previousHostedImageState
@@ -3942,7 +4122,7 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
3942
4122
  message: "Hosted image generation requires an authenticated outbound key"
3943
4123
  });
3944
4124
  }
3945
- const searchMode = operation === "create" ? _nullishCoalesce(_optionalChain([deps, 'access', _184 => _184.searchFrontendModes, 'optionalAccess', _185 => _185.responses]), () => ( _chunkE4QHVXV5cjs.DEFAULT_SEARCH_FRONTEND_MODES.responses)) : "native";
4125
+ const searchMode = operation === "create" ? _nullishCoalesce(_optionalChain([deps, 'access', _197 => _197.searchFrontendModes, 'optionalAccess', _198 => _198.responses]), () => ( _chunkE4QHVXV5cjs.DEFAULT_SEARCH_FRONTEND_MODES.responses)) : "native";
3946
4126
  const wantsHostedSearch = operation === "create" && hasResponsesHostedSearchWork(responsesBody);
3947
4127
  if (wantsHostedSearch && searchMode === "off") {
3948
4128
  throw responsesSearchDisabledError();
@@ -3997,16 +4177,16 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
3997
4177
  let providerResponse;
3998
4178
  try {
3999
4179
  if (hostedImageRequest) {
4000
- _optionalChain([route, 'access', _186 => _186.suppressAuditBodies, 'optionalCall', _187 => _187()]);
4180
+ _optionalChain([route, 'access', _199 => _199.suppressAuditBodies, 'optionalCall', _200 => _200()]);
4001
4181
  }
4002
4182
  providerResponse = await executeResponsesUpstream(
4003
- _nullishCoalesce(_nullishCoalesce(_optionalChain([searchRequest, 'optionalAccess', _188 => _188.upstreamBody]), () => ( _optionalChain([hostedImageRequest, 'optionalAccess', _189 => _189.upstreamBody]))), () => ( responsesBody)),
4183
+ _nullishCoalesce(_nullishCoalesce(_optionalChain([searchRequest, 'optionalAccess', _201 => _201.upstreamBody]), () => ( _optionalChain([hostedImageRequest, 'optionalAccess', _202 => _202.upstreamBody]))), () => ( responsesBody)),
4004
4184
  plan,
4005
4185
  operation,
4006
4186
  signal
4007
4187
  );
4008
4188
  } catch (error) {
4009
- await _optionalChain([hostedImageRequest, 'optionalAccess', _190 => _190.dispose, 'call', _191 => _191()]);
4189
+ await _optionalChain([hostedImageRequest, 'optionalAccess', _203 => _203.dispose, 'call', _204 => _204()]);
4010
4190
  if (affinity && _chunk25GXJCEZcjs.isBoundAccountSelectionError.call(void 0, error)) {
4011
4191
  throw previousResponseNotFound();
4012
4192
  }
@@ -4027,7 +4207,7 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
4027
4207
  extractUsage(event) {
4028
4208
  if (event.type !== "response.completed") return null;
4029
4209
  const response = event.response;
4030
- return _optionalChain([response, 'optionalAccess', _192 => _192.usage]);
4210
+ return _optionalChain([response, 'optionalAccess', _205 => _205.usage]);
4031
4211
  },
4032
4212
  onUsage(rawUsage) {
4033
4213
  recordResponsesStreamUsage(usageRecorder, rawUsage, usageAttribution);
@@ -4070,11 +4250,35 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
4070
4250
  })
4071
4251
  };
4072
4252
  }
4253
+ if (!isStream) {
4254
+ if (await sniffIsSseResponse(providerResponse.response)) {
4255
+ const collapsed = await aggregateResponsesSseToJsonBody(
4256
+ providerResponse.response,
4257
+ route.requestedModel,
4258
+ signal
4259
+ );
4260
+ if (collapsed !== null) {
4261
+ providerResponse = {
4262
+ ...providerResponse,
4263
+ response: new Response(collapsed, {
4264
+ status: providerResponse.response.status,
4265
+ headers: { "Content-Type": "application/json" }
4266
+ })
4267
+ };
4268
+ } else {
4269
+ throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({
4270
+ status: 502,
4271
+ code: "upstream_stream_collapse_failed",
4272
+ message: "upstream streamed no terminal response event"
4273
+ });
4274
+ }
4275
+ }
4276
+ }
4073
4277
  let overloadRecorded = false;
4074
4278
  let usageLimitRecorded = false;
4075
4279
  const observeSse = (event) => {
4076
4280
  if (event.type === "response.completed") {
4077
- recordAffinity(_optionalChain([event, 'access', _193 => _193.response, 'optionalAccess', _194 => _194.id]));
4281
+ recordAffinity(_optionalChain([event, 'access', _206 => _206.response, 'optionalAccess', _207 => _207.id]));
4078
4282
  }
4079
4283
  if (!usageLimitRecorded && isCodexUsageLimitEvent(event)) {
4080
4284
  usageLimitRecorded = true;
@@ -4089,7 +4293,7 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
4089
4293
  if (overloadRecorded || !isCodexServerOverloadEvent(event)) return;
4090
4294
  overloadRecorded = true;
4091
4295
  if (providerResponse.activityRecordId) {
4092
- _chunkNKVZ6Z3Ycjs.getSharedAccountRouteActivity.call(void 0, ).amend(providerResponse.activityRecordId, { streamError: "server_overloaded" });
4296
+ _chunk4HMAS74Xcjs.getSharedAccountRouteActivity.call(void 0, ).amend(providerResponse.activityRecordId, { streamError: "server_overloaded" });
4093
4297
  }
4094
4298
  if (providerResponse.accountId) {
4095
4299
  _chunkOTZC4TNHcjs.getSharedOverloadCounter.call(void 0, ).recordOverload({
@@ -4111,14 +4315,14 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
4111
4315
  signal
4112
4316
  );
4113
4317
  } finally {
4114
- await _optionalChain([hostedImageRequest, 'optionalAccess', _195 => _195.dispose, 'call', _196 => _196()]);
4318
+ await _optionalChain([hostedImageRequest, 'optionalAccess', _208 => _208.dispose, 'call', _209 => _209()]);
4115
4319
  }
4116
4320
  if (!bodyText) return;
4117
4321
  if (usageRecorder) recordResponsesNonStreamUsage(usageRecorder, bodyText, usageAttribution);
4118
4322
  try {
4119
4323
  const body = JSON.parse(bodyText);
4120
4324
  if (body.status !== "failed" && body.status !== "incomplete") recordAffinity(body.id);
4121
- } catch (e31) {
4325
+ } catch (e35) {
4122
4326
  }
4123
4327
  }
4124
4328
 
@@ -4127,7 +4331,7 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
4127
4331
  let anthropicBody;
4128
4332
  try {
4129
4333
  anthropicBody = JSON.parse(rawBody);
4130
- } catch (e32) {
4334
+ } catch (e36) {
4131
4335
  writeError(res, 400, "Invalid JSON in request body");
4132
4336
  return;
4133
4337
  }
@@ -4165,7 +4369,7 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
4165
4369
  extractUsage(event) {
4166
4370
  if (event["type"] === "message_start") {
4167
4371
  const msg = event["message"];
4168
- const u = _optionalChain([msg, 'optionalAccess', _197 => _197["usage"]]);
4372
+ const u = _optionalChain([msg, 'optionalAccess', _210 => _210["usage"]]);
4169
4373
  if (u) anthropicInputUsage = u;
4170
4374
  return null;
4171
4375
  }
@@ -4188,7 +4392,7 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
4188
4392
  if (!usageLimitRecorded) {
4189
4393
  let limitHit = isCodexUsageLimitEvent(event);
4190
4394
  if (!limitHit && event["type"] === "error") {
4191
- const message = _optionalChain([event, 'access', _198 => _198["error"], 'optionalAccess', _199 => _199["message"]]);
4395
+ const message = _optionalChain([event, 'access', _211 => _211["error"], 'optionalAccess', _212 => _212["message"]]);
4192
4396
  limitHit = typeof message === "string" && (message.includes("usage_limit_reached") || message.includes("usage_not_included"));
4193
4397
  }
4194
4398
  if (limitHit) {
@@ -4205,13 +4409,13 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
4205
4409
  if (overloadRecorded) return;
4206
4410
  let hit = isCodexServerOverloadEvent(event);
4207
4411
  if (!hit && event["type"] === "error") {
4208
- const message = _optionalChain([event, 'access', _200 => _200["error"], 'optionalAccess', _201 => _201["message"]]);
4412
+ const message = _optionalChain([event, 'access', _213 => _213["error"], 'optionalAccess', _214 => _214["message"]]);
4209
4413
  hit = typeof message === "string" && (message.includes("server_is_overloaded") || message.includes("slow_down"));
4210
4414
  }
4211
4415
  if (!hit) return;
4212
4416
  overloadRecorded = true;
4213
4417
  if (overloadActivityId) {
4214
- _chunkNKVZ6Z3Ycjs.getSharedAccountRouteActivity.call(void 0, ).amend(overloadActivityId, {
4418
+ _chunk4HMAS74Xcjs.getSharedAccountRouteActivity.call(void 0, ).amend(overloadActivityId, {
4215
4419
  streamError: "server_overloaded"
4216
4420
  });
4217
4421
  }
@@ -4226,7 +4430,7 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
4226
4430
  let inbandOverloadRecorded = false;
4227
4431
  const inbandOverloadObserver = plan.isSubscription && plan.sameFormat && overloadAccountId ? (event) => {
4228
4432
  if (inbandOverloadRecorded || event["type"] !== "error") return;
4229
- const errorType = _optionalChain([event, 'access', _202 => _202["error"], 'optionalAccess', _203 => _203["type"]]);
4433
+ const errorType = _optionalChain([event, 'access', _215 => _215["error"], 'optionalAccess', _216 => _216["type"]]);
4230
4434
  if (errorType !== "overloaded_error") return;
4231
4435
  inbandOverloadRecorded = true;
4232
4436
  _chunk7LRTPNFLcjs.getSharedAccountHealth.call(void 0, ).recordUpstreamOutcome(
@@ -4263,7 +4467,7 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
4263
4467
  recordAnthropicNonStreamUsage(deps.usageRecorder, bodyText, usageAttribution);
4264
4468
  }
4265
4469
  } catch (err) {
4266
- if (_optionalChain([options, 'access', _204 => _204.signal, 'optionalAccess', _205 => _205.aborted])) return;
4470
+ if (_optionalChain([options, 'access', _217 => _217.signal, 'optionalAccess', _218 => _218.aborted])) return;
4267
4471
  if (err instanceof DocumentNotSupportedError || err instanceof UnsupportedContentBlockError) {
4268
4472
  writeError(res, 400, `${err.message} [code: ${err.code}]`);
4269
4473
  return;
@@ -4329,7 +4533,9 @@ async function buildByoPlan2(res, route, deps, resolvedModel, isStream) {
4329
4533
  isSubscription: false,
4330
4534
  provider,
4331
4535
  apiKey,
4332
- extendedContextEnabled: _nullishCoalesce(_optionalChain([route, 'access', _206 => _206.anthropicSdkHints, 'optionalAccess', _207 => _207.extendedContext, 'optionalAccess', _208 => _208.enabled]), () => ( false))
4536
+ extendedContextEnabled: _nullishCoalesce(_optionalChain([route, 'access', _219 => _219.anthropicSdkHints, 'optionalAccess', _220 => _220.extendedContext, 'optionalAccess', _221 => _221.enabled]), () => ( false)),
4537
+ byoActivity: buildByoRouteActivityMeta(deps, providerId, route.sessionId),
4538
+ byoSessionId: _nullishCoalesce(route.sessionId, () => ( null))
4333
4539
  };
4334
4540
  }
4335
4541
  async function runSameFormatFetch(bodyToSend, plan, options, keyOverride, urlOverride) {
@@ -4339,7 +4545,7 @@ async function runSameFormatFetch(bodyToSend, plan, options, keyOverride, urlOve
4339
4545
  }
4340
4546
  const effectiveKey = _nullishCoalesce(_nullishCoalesce(keyOverride, () => ( apiKey)), () => ( ""));
4341
4547
  const headers = _chunkTX4UCSOPcjs.getProviderHeaders.call(void 0, provider, effectiveKey);
4342
- const callerBeta = _optionalChain([options, 'access', _209 => _209.callerAnthropicBeta, 'optionalAccess', _210 => _210.trim, 'call', _211 => _211()]);
4548
+ const callerBeta = _optionalChain([options, 'access', _222 => _222.callerAnthropicBeta, 'optionalAccess', _223 => _223.trim, 'call', _224 => _224()]);
4343
4549
  if (callerBeta) {
4344
4550
  const existing = _nullishCoalesce(headers["anthropic-beta"], () => ( headers["Anthropic-Beta"]));
4345
4551
  const parts = new Set(
@@ -4351,23 +4557,41 @@ async function runSameFormatFetch(bodyToSend, plan, options, keyOverride, urlOve
4351
4557
  }
4352
4558
  }
4353
4559
  _chunkGBHYAGX3cjs.injectExtendedContextBeta.call(void 0, headers, resolvedModel, _nullishCoalesce(extendedContextEnabled, () => ( false)));
4354
- const callerVersion = _optionalChain([options, 'access', _212 => _212.callerAnthropicVersion, 'optionalAccess', _213 => _213.trim, 'call', _214 => _214()]);
4560
+ const callerVersion = _optionalChain([options, 'access', _225 => _225.callerAnthropicVersion, 'optionalAccess', _226 => _226.trim, 'call', _227 => _227()]);
4355
4561
  headers["anthropic-version"] = callerVersion || DEFAULT_ANTHROPIC_VERSION;
4356
4562
  const url = _nullishCoalesce(urlOverride, () => ( _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: resolvedModel, stream: isStream })));
4357
4563
  console.info(`[ProviderProxy:anthropic] (same-format) -> ${url} model=${resolvedModel} stream=${isStream}`);
4358
- const response = await _chunkVFFCV4J6cjs.fetchUpstream.call(void 0,
4564
+ let activityRecordId;
4565
+ const response = await _chunkCXRJMNJJcjs.fetchUpstream.call(void 0,
4359
4566
  url,
4360
4567
  { method: "POST", headers, body: bodyToSend, signal: options.signal },
4361
- { providerId: "byo" }
4568
+ {
4569
+ providerId: "byo",
4570
+ routeActivity: {
4571
+ providerId: _nullishCoalesce(_optionalChain([plan, 'access', _228 => _228.byoActivity, 'optionalAccess', _229 => _229.providerId]), () => ( provider.name)),
4572
+ credentialKind: "provider-key",
4573
+ // LIVE resolution: a pool rebind retry re-invokes this fetch, and the
4574
+ // binding has already rotated, so the retried attempt attributes the
4575
+ // NEW key. `keyOverride` is a key STRING (never recorded).
4576
+ keyId: _optionalChain([plan, 'access', _230 => _230.byoActivity, 'optionalAccess', _231 => _231.resolveKeyId, 'call', _232 => _232()]),
4577
+ endpoint: "messages",
4578
+ sessionKey: plan.byoSessionId || void 0,
4579
+ sessionSource: plan.byoSessionId ? "route-session-id" : "none",
4580
+ model: resolvedModel,
4581
+ onRecorded: (record5) => {
4582
+ activityRecordId = record5.id;
4583
+ }
4584
+ }
4585
+ }
4362
4586
  );
4363
- return { response, rawStatus: response.status };
4587
+ return { response, rawStatus: response.status, activityRecordId };
4364
4588
  }
4365
4589
  function resolveSameFormatBody(anthropicBody, rawBody, plan) {
4366
4590
  let originalModel;
4367
4591
  try {
4368
4592
  const m = JSON.parse(rawBody).model;
4369
4593
  originalModel = typeof m === "string" ? m : void 0;
4370
- } catch (e33) {
4594
+ } catch (e37) {
4371
4595
  originalModel = void 0;
4372
4596
  }
4373
4597
  return plan.resolvedModel !== originalModel ? JSON.stringify(anthropicBody) : rawBody;
@@ -4376,8 +4600,8 @@ async function runPipelineWithPoolReporting(anthropicBody, rawBody, plan, option
4376
4600
  const sameFormatBody = plan.sameFormat ? resolveSameFormatBody(anthropicBody, rawBody, plan) : rawBody;
4377
4601
  const runOnce = (keyOverride) => plan.sameFormat ? runSameFormatFetch(sameFormatBody, plan, options, keyOverride) : runPipeline(anthropicBody, plan, void 0, options.signal);
4378
4602
  const first = await runOnce();
4379
- const outcome = await _optionalChain([plan, 'access', _215 => _215.auth, 'access', _216 => _216.onResult, 'optionalCall', _217 => _217(first.rawStatus)]);
4380
- if (_optionalChain([outcome, 'optionalAccess', _218 => _218.rebound])) {
4603
+ const outcome = await _optionalChain([plan, 'access', _233 => _233.auth, 'access', _234 => _234.onResult, 'optionalCall', _235 => _235(first.rawStatus)]);
4604
+ if (_optionalChain([outcome, 'optionalAccess', _236 => _236.rebound])) {
4381
4605
  console.info(
4382
4606
  "[ProviderProxy:anthropic] pool re-bound key after status",
4383
4607
  first.rawStatus,
@@ -4463,7 +4687,7 @@ function countTools(tools, budget) {
4463
4687
  let serialized;
4464
4688
  try {
4465
4689
  serialized = _nullishCoalesce(JSON.stringify(tool), () => ( ""));
4466
- } catch (e34) {
4690
+ } catch (e38) {
4467
4691
  serialized = "";
4468
4692
  }
4469
4693
  if (!budget.addChars(serialized.length)) return;
@@ -4508,7 +4732,7 @@ async function handleAnthropicCountTokens(res, rawBody, route, deps, options = {
4508
4732
  let body;
4509
4733
  try {
4510
4734
  body = JSON.parse(rawBody);
4511
- } catch (e35) {
4735
+ } catch (e39) {
4512
4736
  writeError(res, 400, "Invalid JSON in request body");
4513
4737
  return;
4514
4738
  }
@@ -4540,7 +4764,7 @@ async function handleAnthropicCountTokens(res, rawBody, route, deps, options = {
4540
4764
  const providerResponse = plan.isSubscription ? await runSubscriptionCountTokensFetch(bodyToSend, plan, options, countTokensUrl) : await runByoCountTokensFetch(bodyToSend, plan, options, countTokensUrl);
4541
4765
  await relayResponse(res, providerResponse.response, false, void 0, void 0, void 0, options.signal);
4542
4766
  } catch (err) {
4543
- if (_optionalChain([options, 'access', _219 => _219.signal, 'optionalAccess', _220 => _220.aborted])) return;
4767
+ if (_optionalChain([options, 'access', _237 => _237.signal, 'optionalAccess', _238 => _238.aborted])) return;
4544
4768
  if (_chunk25GXJCEZcjs.isBoundAccountSelectionError.call(void 0, err)) {
4545
4769
  writeBoundAccountError(res, err);
4546
4770
  return;
@@ -4562,8 +4786,8 @@ function writeCountTokensEstimate(res, body, budgetMs) {
4562
4786
  async function runByoCountTokensFetch(bodyToSend, plan, options, url) {
4563
4787
  const runOnce = (keyOverride) => runSameFormatFetch(bodyToSend, plan, options, keyOverride, url);
4564
4788
  const first = await runOnce();
4565
- const outcome = await _optionalChain([plan, 'access', _221 => _221.auth, 'access', _222 => _222.onResult, 'optionalCall', _223 => _223(first.rawStatus)]);
4566
- if (_optionalChain([outcome, 'optionalAccess', _224 => _224.rebound])) {
4789
+ const outcome = await _optionalChain([plan, 'access', _239 => _239.auth, 'access', _240 => _240.onResult, 'optionalCall', _241 => _241(first.rawStatus)]);
4790
+ if (_optionalChain([outcome, 'optionalAccess', _242 => _242.rebound])) {
4567
4791
  await cancelDiscardedResponse(first.response);
4568
4792
  console.info(
4569
4793
  "[ProviderProxy:anthropic] pool re-bound key after status",
@@ -4581,7 +4805,7 @@ async function runSubscriptionCountTokensFetch(bodyToSend, plan, options, url) {
4581
4805
  // src/provider-proxy/ingress/anthropicPathMatch.ts
4582
4806
  function classifyAnthropicMessagesPath(url) {
4583
4807
  if (!url) return null;
4584
- const path = _nullishCoalesce(_optionalChain([url, 'access', _225 => _225.split, 'call', _226 => _226("?"), 'access', _227 => _227[0], 'optionalAccess', _228 => _228.replace, 'call', _229 => _229(/\/+$/, "")]), () => ( ""));
4808
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _243 => _243.split, 'call', _244 => _244("?"), 'access', _245 => _245[0], 'optionalAccess', _246 => _246.replace, 'call', _247 => _247(/\/+$/, "")]), () => ( ""));
4585
4809
  if (path.endsWith("/v1/messages/count_tokens")) return "count_tokens";
4586
4810
  if (path.endsWith("/v1/messages")) return "messages";
4587
4811
  if (/\/v1\/messages\/.+/.test(path)) return "unsupported-subpath";
@@ -4609,7 +4833,7 @@ async function handleAnthropicMessagesRequest(req, res, route, deps) {
4609
4833
  const callerAnthropicVersion = Array.isArray(callerVersionRaw) ? callerVersionRaw.join(",") : callerVersionRaw;
4610
4834
  const callerIdentity = _chunk6RPZADX3cjs.captureCallerIdentity.call(void 0, _chunkRPII3E6Zcjs.getSharedIdentityStore.call(void 0, ), request.headers);
4611
4835
  const callerClientHeaders = extractClaudeClientHeaders(request.headers);
4612
- const callerOpenCodeSession = _chunkGWC7HCZIcjs.extractOpenCodeSessionHeader.call(void 0, request.headers);
4836
+ const callerOpenCodeSession = _chunkLWBXQXZ3cjs.extractOpenCodeSessionHeader.call(void 0, request.headers);
4613
4837
  await handleAnthropicCountTokens(res, rawBody, route, deps, {
4614
4838
  callerAnthropicBeta,
4615
4839
  callerAnthropicVersion,
@@ -4625,14 +4849,14 @@ async function handleAnthropicMessagesRequest(req, res, route, deps) {
4625
4849
  }
4626
4850
  return;
4627
4851
  }
4628
- const searchMode = _nullishCoalesce(_optionalChain([deps, 'access', _230 => _230.searchFrontendModes, 'optionalAccess', _231 => _231.anthropic]), () => ( _chunkE4QHVXV5cjs.DEFAULT_SEARCH_FRONTEND_MODES.anthropic));
4629
- const routeSuppliedSearchBackend = _nullishCoalesce(_optionalChain([route, 'access', _232 => _232.anthropicSdkHints, 'optionalAccess', _233 => _233.webSearchService]), () => ( null));
4852
+ const searchMode = _nullishCoalesce(_optionalChain([deps, 'access', _248 => _248.searchFrontendModes, 'optionalAccess', _249 => _249.anthropic]), () => ( _chunkE4QHVXV5cjs.DEFAULT_SEARCH_FRONTEND_MODES.anthropic));
4853
+ const routeSuppliedSearchBackend = _nullishCoalesce(_optionalChain([route, 'access', _250 => _250.anthropicSdkHints, 'optionalAccess', _251 => _251.webSearchService]), () => ( null));
4630
4854
  if (searchMode !== "native" && !routeSuppliedSearchBackend) {
4631
4855
  const preReadBody = await readBody(req);
4632
4856
  let parsedForSearch;
4633
4857
  try {
4634
4858
  parsedForSearch = preReadBody ? JSON.parse(preReadBody) : {};
4635
- } catch (e36) {
4859
+ } catch (e40) {
4636
4860
  parsedForSearch = void 0;
4637
4861
  }
4638
4862
  const handled = await handleAnthropicManagedSearch(res, parsedForSearch, {
@@ -4654,7 +4878,7 @@ async function handleAnthropicMessagesRequest(req, res, route, deps) {
4654
4878
  const callerAnthropicVersion = Array.isArray(callerVersionRaw) ? callerVersionRaw.join(",") : callerVersionRaw;
4655
4879
  const callerIdentity = _chunk6RPZADX3cjs.captureCallerIdentity.call(void 0, _chunkRPII3E6Zcjs.getSharedIdentityStore.call(void 0, ), request.headers);
4656
4880
  const callerClientHeaders = extractClaudeClientHeaders(request.headers);
4657
- const callerOpenCodeSession = _chunkGWC7HCZIcjs.extractOpenCodeSessionHeader.call(void 0, request.headers);
4881
+ const callerOpenCodeSession = _chunkLWBXQXZ3cjs.extractOpenCodeSessionHeader.call(void 0, request.headers);
4658
4882
  await handleAnthropicMessagesByo(res, rawBody, route, deps, {
4659
4883
  callerAnthropicBeta,
4660
4884
  callerAnthropicVersion,
@@ -4759,10 +4983,10 @@ function emitGeminiUsageRecord(recorder, rawUsageMetadata, attribution) {
4759
4983
  providerId: attribution.providerId,
4760
4984
  model: attribution.model,
4761
4985
  apiKeyId: attribution.apiKeyId,
4762
- runId: _nullishCoalesce(_optionalChain([attribution, 'access', _234 => _234.routeLease, 'optionalAccess', _235 => _235.runId]), () => ( null)),
4763
- routeLeaseId: _nullishCoalesce(_optionalChain([attribution, 'access', _236 => _236.routeLease, 'optionalAccess', _237 => _237.leaseId]), () => ( null)),
4764
- routeLeaseConsumer: _nullishCoalesce(_optionalChain([attribution, 'access', _238 => _238.routeLease, 'optionalAccess', _239 => _239.consumer]), () => ( null)),
4765
- routeLeaseStageId: _nullishCoalesce(_optionalChain([attribution, 'access', _240 => _240.routeLease, 'optionalAccess', _241 => _241.stageId]), () => ( null)),
4986
+ runId: _nullishCoalesce(_optionalChain([attribution, 'access', _252 => _252.routeLease, 'optionalAccess', _253 => _253.runId]), () => ( null)),
4987
+ routeLeaseId: _nullishCoalesce(_optionalChain([attribution, 'access', _254 => _254.routeLease, 'optionalAccess', _255 => _255.leaseId]), () => ( null)),
4988
+ routeLeaseConsumer: _nullishCoalesce(_optionalChain([attribution, 'access', _256 => _256.routeLease, 'optionalAccess', _257 => _257.consumer]), () => ( null)),
4989
+ routeLeaseStageId: _nullishCoalesce(_optionalChain([attribution, 'access', _258 => _258.routeLease, 'optionalAccess', _259 => _259.stageId]), () => ( null)),
4766
4990
  auditResponse: attribution.auditResponse,
4767
4991
  engineOrigin: "codex-ingress",
4768
4992
  usage: tapped,
@@ -4777,13 +5001,13 @@ function recordGeminiNonStreamUsage(recorder, bodyText, attribution) {
4777
5001
  parsed.usageMetadata,
4778
5002
  attribution
4779
5003
  );
4780
- } catch (e37) {
5004
+ } catch (e41) {
4781
5005
  }
4782
5006
  }
4783
5007
  function recordGeminiStreamUsage(recorder, rawUsageMetadata, attribution) {
4784
5008
  try {
4785
5009
  emitGeminiUsageRecord(recorder, rawUsageMetadata, attribution);
4786
- } catch (e38) {
5010
+ } catch (e42) {
4787
5011
  }
4788
5012
  }
4789
5013
 
@@ -4792,14 +5016,14 @@ var GENERATE_CONTENT_ACTION = ":generateContent";
4792
5016
  var STREAM_GENERATE_CONTENT_ACTION = ":streamGenerateContent";
4793
5017
  function isGeminiGenerateContentRequest(method, url) {
4794
5018
  if (method !== "POST" || !url) return false;
4795
- const path = _nullishCoalesce(_optionalChain([url, 'access', _242 => _242.split, 'call', _243 => _243("?"), 'access', _244 => _244[0], 'optionalAccess', _245 => _245.replace, 'call', _246 => _246(/\/+$/, "")]), () => ( ""));
5019
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _260 => _260.split, 'call', _261 => _261("?"), 'access', _262 => _262[0], 'optionalAccess', _263 => _263.replace, 'call', _264 => _264(/\/+$/, "")]), () => ( ""));
4796
5020
  const lastSegment = _nullishCoalesce(path.split("/").pop(), () => ( ""));
4797
5021
  return lastSegment.includes(STREAM_GENERATE_CONTENT_ACTION) || lastSegment.includes(GENERATE_CONTENT_ACTION);
4798
5022
  }
4799
5023
  function isGeminiStreamRequest(url) {
4800
5024
  if (!url) return false;
4801
5025
  const [path, query = ""] = url.split("?");
4802
- const lastSegment = _nullishCoalesce((_nullishCoalesce(_optionalChain([path, 'optionalAccess', _247 => _247.replace, 'call', _248 => _248(/\/+$/, "")]), () => ( ""))).split("/").pop(), () => ( ""));
5026
+ const lastSegment = _nullishCoalesce((_nullishCoalesce(_optionalChain([path, 'optionalAccess', _265 => _265.replace, 'call', _266 => _266(/\/+$/, "")]), () => ( ""))).split("/").pop(), () => ( ""));
4803
5027
  if (lastSegment.includes(STREAM_GENERATE_CONTENT_ACTION)) return true;
4804
5028
  return /(^|&)alt=sse(&|$)/.test(query);
4805
5029
  }
@@ -4807,7 +5031,7 @@ async function handleGeminiGenerateContentRequest(res, rawBody, url, route, deps
4807
5031
  let geminiBody;
4808
5032
  try {
4809
5033
  geminiBody = JSON.parse(rawBody);
4810
- } catch (e39) {
5034
+ } catch (e43) {
4811
5035
  writeError(res, 400, "Invalid JSON in request body");
4812
5036
  return;
4813
5037
  }
@@ -4903,7 +5127,9 @@ async function buildByoPlan3(res, route, deps, resolvedModel, isStream) {
4903
5127
  resolvedModel,
4904
5128
  isStream,
4905
5129
  resolveUrl: (config) => config.url instanceof URL ? config.url.toString() : byoUrl,
4906
- upstreamUrl: byoUrl
5130
+ upstreamUrl: byoUrl,
5131
+ byoActivity: buildByoRouteActivityMeta(deps, providerId, route.sessionId),
5132
+ byoSessionId: _nullishCoalesce(route.sessionId, () => ( null))
4907
5133
  };
4908
5134
  }
4909
5135
  async function runPipeline2(geminiBody, plan) {
@@ -4931,10 +5157,21 @@ async function runPipeline2(geminiBody, plan) {
4931
5157
  },
4932
5158
  fetchFn: (url, headers, body) => {
4933
5159
  console.log(`[ProviderProxy:gemini] -> ${url} model=${resolvedModel} stream=${isStream}`);
4934
- return _chunkVFFCV4J6cjs.fetchUpstream.call(void 0,
5160
+ return _chunkCXRJMNJJcjs.fetchUpstream.call(void 0,
4935
5161
  url,
4936
5162
  { method: "POST", headers, body: JSON.stringify(body) },
4937
- { providerId: "byo" }
5163
+ {
5164
+ providerId: "byo",
5165
+ routeActivity: {
5166
+ providerId: _nullishCoalesce(_optionalChain([plan, 'access', _267 => _267.byoActivity, 'optionalAccess', _268 => _268.providerId]), () => ( transformerProvider.name)),
5167
+ credentialKind: "provider-key",
5168
+ keyId: _optionalChain([plan, 'access', _269 => _269.byoActivity, 'optionalAccess', _270 => _270.resolveKeyId, 'call', _271 => _271()]),
5169
+ endpoint: "generateContent",
5170
+ sessionKey: plan.byoSessionId || void 0,
5171
+ sessionSource: plan.byoSessionId ? "route-session-id" : "none",
5172
+ model: resolvedModel
5173
+ }
5174
+ }
4938
5175
  ).then((r) => {
4939
5176
  rawStatus = r.status;
4940
5177
  return r;
@@ -4946,8 +5183,8 @@ async function runPipeline2(geminiBody, plan) {
4946
5183
  }
4947
5184
  async function runPipelineWithPoolReporting2(geminiBody, plan) {
4948
5185
  const first = await runPipeline2(geminiBody, plan);
4949
- const outcome = await _optionalChain([plan, 'access', _249 => _249.auth, 'access', _250 => _250.onResult, 'optionalCall', _251 => _251(first.rawStatus)]);
4950
- if (_optionalChain([outcome, 'optionalAccess', _252 => _252.rebound])) {
5186
+ const outcome = await _optionalChain([plan, 'access', _272 => _272.auth, 'access', _273 => _273.onResult, 'optionalCall', _274 => _274(first.rawStatus)]);
5187
+ if (_optionalChain([outcome, 'optionalAccess', _275 => _275.rebound])) {
4951
5188
  console.log(
4952
5189
  "[ProviderProxy:gemini] pool re-bound key after status",
4953
5190
  first.rawStatus,
@@ -4986,10 +5223,10 @@ function emitChatCompletionsUsageRecord(recorder, rawUsage, attribution) {
4986
5223
  providerId: attribution.providerId,
4987
5224
  model: attribution.model,
4988
5225
  apiKeyId: attribution.apiKeyId,
4989
- runId: _nullishCoalesce(_optionalChain([attribution, 'access', _253 => _253.routeLease, 'optionalAccess', _254 => _254.runId]), () => ( null)),
4990
- routeLeaseId: _nullishCoalesce(_optionalChain([attribution, 'access', _255 => _255.routeLease, 'optionalAccess', _256 => _256.leaseId]), () => ( null)),
4991
- routeLeaseConsumer: _nullishCoalesce(_optionalChain([attribution, 'access', _257 => _257.routeLease, 'optionalAccess', _258 => _258.consumer]), () => ( null)),
4992
- routeLeaseStageId: _nullishCoalesce(_optionalChain([attribution, 'access', _259 => _259.routeLease, 'optionalAccess', _260 => _260.stageId]), () => ( null)),
5226
+ runId: _nullishCoalesce(_optionalChain([attribution, 'access', _276 => _276.routeLease, 'optionalAccess', _277 => _277.runId]), () => ( null)),
5227
+ routeLeaseId: _nullishCoalesce(_optionalChain([attribution, 'access', _278 => _278.routeLease, 'optionalAccess', _279 => _279.leaseId]), () => ( null)),
5228
+ routeLeaseConsumer: _nullishCoalesce(_optionalChain([attribution, 'access', _280 => _280.routeLease, 'optionalAccess', _281 => _281.consumer]), () => ( null)),
5229
+ routeLeaseStageId: _nullishCoalesce(_optionalChain([attribution, 'access', _282 => _282.routeLease, 'optionalAccess', _283 => _283.stageId]), () => ( null)),
4993
5230
  auditResponse: attribution.auditResponse,
4994
5231
  engineOrigin: "codex-ingress",
4995
5232
  usage: tapped,
@@ -5004,24 +5241,33 @@ function recordChatCompletionsNonStreamUsage(recorder, bodyText, attribution) {
5004
5241
  parsed.usage,
5005
5242
  attribution
5006
5243
  );
5007
- } catch (e40) {
5244
+ } catch (e44) {
5008
5245
  }
5009
5246
  }
5010
5247
  function recordChatCompletionsStreamUsage(recorder, rawUsage, attribution) {
5011
5248
  try {
5012
5249
  emitChatCompletionsUsageRecord(recorder, rawUsage, attribution);
5013
- } catch (e41) {
5250
+ } catch (e45) {
5014
5251
  }
5015
5252
  }
5016
5253
 
5017
5254
  // src/provider-proxy/ingress/openaiChatIngress.ts
5018
- var CHAT_BRIDGE_SUBSCRIPTION_PROVIDERS = /* @__PURE__ */ new Set(["claude"]);
5255
+ var CHAT_BRIDGE_SUBSCRIPTION_PROVIDERS = /* @__PURE__ */ new Set([
5256
+ "claude",
5257
+ "kimi",
5258
+ "grok",
5259
+ "opencodego",
5260
+ "codex",
5261
+ "gemini",
5262
+ "copilot",
5263
+ "antigravity"
5264
+ ]);
5019
5265
  var IDENTITY_ENDPOINT_TRANSFORMER = { name: "identity-openai-chat" };
5020
5266
  async function handleOpenAIChatRequest(res, rawBody, route, deps) {
5021
5267
  let chatBody;
5022
5268
  try {
5023
5269
  chatBody = JSON.parse(rawBody);
5024
- } catch (e42) {
5270
+ } catch (e46) {
5025
5271
  writeError(res, 400, "Invalid JSON in request body");
5026
5272
  return;
5027
5273
  }
@@ -5029,9 +5275,26 @@ async function handleOpenAIChatRequest(res, rawBody, route, deps) {
5029
5275
  const resolvedModel = route.model;
5030
5276
  chatBody.model = resolvedModel;
5031
5277
  try {
5032
- const plan = route.authMode === "subscription" ? await buildSubscriptionPlan3(res, route, deps, resolvedModel, isStream) : await buildByoPlan4(res, route, deps, resolvedModel, isStream);
5278
+ const plan = route.authMode === "subscription" ? await buildSubscriptionPlan3(res, route, deps, chatBody, resolvedModel, isStream) : await buildByoPlan4(res, route, deps, resolvedModel, isStream);
5033
5279
  if (!plan) return;
5034
- const providerResponse = plan.isSubscription ? await runPipelineWithSubscriptionRetry2(chatBody, plan) : await runPipelineWithPoolReporting3(chatBody, plan);
5280
+ let providerResponse = plan.isSubscription ? await runPipelineWithSubscriptionRetry2(chatBody, plan) : await runPipelineWithPoolReporting3(chatBody, plan);
5281
+ if (!isStream) {
5282
+ if (await sniffIsSseResponse(providerResponse.response)) {
5283
+ const collapsed = await aggregateOpenAIChatChunksToJsonBody(providerResponse.response);
5284
+ if (collapsed !== null) {
5285
+ providerResponse = {
5286
+ response: new Response(collapsed, {
5287
+ status: providerResponse.response.status,
5288
+ headers: { "Content-Type": "application/json" }
5289
+ }),
5290
+ rawStatus: providerResponse.rawStatus
5291
+ };
5292
+ } else {
5293
+ writeError(res, 502, "upstream streamed no completable chat chunks");
5294
+ return;
5295
+ }
5296
+ }
5297
+ }
5035
5298
  const usageAttribution = {
5036
5299
  sessionId: route.sessionId,
5037
5300
  providerId: _nullishCoalesce(route.providerId, () => ( "openai")),
@@ -5118,10 +5381,12 @@ async function buildByoPlan4(res, route, deps, resolvedModel, isStream) {
5118
5381
  resolveUrl: (config) => config.url instanceof URL ? config.url.toString() : byoUrl,
5119
5382
  upstreamUrl: byoUrl,
5120
5383
  proxyProviderId: "byo",
5121
- isSubscription: false
5384
+ isSubscription: false,
5385
+ byoActivity: buildByoRouteActivityMeta(deps, providerId, route.sessionId),
5386
+ routeSessionId: _nullishCoalesce(route.sessionId, () => ( null))
5122
5387
  };
5123
5388
  }
5124
- async function buildSubscriptionPlan3(res, route, deps, resolvedModel, isStream) {
5389
+ async function buildSubscriptionPlan3(res, route, deps, chatBody, resolvedModel, isStream) {
5125
5390
  const profile = route.subscriptionProfile;
5126
5391
  if (!profile) {
5127
5392
  writeError(res, 502, "Subscription mode requires a subscription profile");
@@ -5132,27 +5397,56 @@ async function buildSubscriptionPlan3(res, route, deps, resolvedModel, isStream)
5132
5397
  writeError(
5133
5398
  res,
5134
5399
  501,
5135
- `the OpenAI-chat\u2192subscription bridge currently supports claude only; subscription provider '${providerId}' is not implemented on this endpoint yet (use the /v1/responses endpoint, a Claude subscription, or a BYO provider)`
5400
+ `the OpenAI-chat\u2192subscription bridge does not implement subscription provider '${providerId}' on this endpoint yet (use the /v1/responses endpoint, a Claude/Kimi/Grok/OpenCodeGo subscription, or a BYO provider)`
5136
5401
  );
5137
5402
  return null;
5138
5403
  }
5139
- const upstreamUrl = _optionalChain([profile, 'access', _261 => _261.resolveUpstreamUrl, 'optionalCall', _262 => _262(resolvedModel)]);
5404
+ let mappedModel = resolvedModel;
5405
+ if (profile.modelMapper) {
5406
+ const summary = buildSubscriptionRequestSummary(chatBody);
5407
+ const mapped = profile.modelMapper(resolvedModel, summary, route.subscriptionConfig);
5408
+ mappedModel = mapped.resolvedModel;
5409
+ }
5410
+ const upstreamUrl = _optionalChain([profile, 'access', _284 => _284.resolveUpstreamUrl, 'optionalCall', _285 => _285(mappedModel, route.subscriptionConfig)]);
5140
5411
  if (!upstreamUrl) {
5141
5412
  writeError(res, 502, "Subscription profile is missing resolveUpstreamUrl");
5142
5413
  return null;
5143
5414
  }
5144
5415
  const auth = _nullishCoalesce(route.auth, () => ( new (0, _chunkRXMF7GNFcjs.SubscriptionAuthSource)(profile)));
5416
+ const chatChainNames = _nullishCoalesce(_optionalChain([profile, 'access', _286 => _286.chatBridgeTransformerNames, 'optionalCall', _287 => _287(mappedModel, route.subscriptionConfig)]), () => ( _optionalChain([profile, 'access', _288 => _288.resolveProviderTransformerNames, 'optionalCall', _289 => _289(mappedModel, route.subscriptionConfig)])));
5145
5417
  const chain = _chunkNYUNU75Acjs.resolveSubscriptionChain.call(void 0,
5146
5418
  profile,
5147
5419
  deps.llmConfig.getTransformerService(),
5148
- IDENTITY_ENDPOINT_TRANSFORMER
5420
+ IDENTITY_ENDPOINT_TRANSFORMER,
5421
+ chatChainNames
5149
5422
  );
5150
5423
  const transformerProvider = {
5151
5424
  name: providerId,
5152
5425
  baseUrl: upstreamUrl,
5153
5426
  apiKey: "",
5154
- models: [resolvedModel]
5427
+ models: [mappedModel]
5155
5428
  };
5429
+ const sessionKey = _chunkJ3QQ6JS5cjs.deriveSubscriptionSessionKey.call(void 0, chatBody);
5430
+ if (providerId === "gemini") {
5431
+ transformerProvider.geminiProject = await resolveGeminiProjectForChatBridge(profile, {
5432
+ sessionKey,
5433
+ preferredAccountId: route.preferredAccountId,
5434
+ preferredAccountGroup: route.preferredAccountGroup,
5435
+ boundAccountFallbackPolicy: route.boundAccountFallbackPolicy
5436
+ });
5437
+ } else if (providerId === "antigravity") {
5438
+ transformerProvider.geminiProject = await resolveAntigravityProjectThreaded(profile, {
5439
+ resolvedModel: mappedModel,
5440
+ reportSelection: () => {
5441
+ },
5442
+ sessionKey,
5443
+ preferredAccountId: route.preferredAccountId,
5444
+ preferredAccountGroup: route.preferredAccountGroup,
5445
+ boundAccountFallbackPolicy: route.boundAccountFallbackPolicy
5446
+ });
5447
+ }
5448
+ chatBody.model = mappedModel;
5449
+ const resolveUrl = providerId === "antigravity" ? (config) => config.url instanceof URL ? config.url.toString() : typeof config.url === "string" ? config.url : upstreamUrl : () => upstreamUrl;
5156
5450
  return {
5157
5451
  auth,
5158
5452
  preferredAccountId: route.preferredAccountId,
@@ -5160,12 +5454,14 @@ async function buildSubscriptionPlan3(res, route, deps, resolvedModel, isStream)
5160
5454
  boundAccountFallbackPolicy: route.boundAccountFallbackPolicy,
5161
5455
  chain,
5162
5456
  transformerProvider,
5163
- resolvedModel,
5457
+ resolvedModel: mappedModel,
5164
5458
  isStream,
5165
- resolveUrl: (config) => config.url instanceof URL ? config.url.toString() : typeof config.url === "string" ? config.url : upstreamUrl,
5459
+ resolveUrl,
5166
5460
  upstreamUrl,
5167
5461
  proxyProviderId: providerId,
5168
- isSubscription: true
5462
+ isSubscription: true,
5463
+ contentSessionKey: sessionKey,
5464
+ routeSessionId: _nullishCoalesce(route.sessionId, () => ( null))
5169
5465
  };
5170
5466
  }
5171
5467
  async function runPipeline3(chatBody, plan) {
@@ -5176,6 +5472,7 @@ async function runPipeline3(chatBody, plan) {
5176
5472
  await auth.applyHeaders(authHeaders, {
5177
5473
  upstreamUrl,
5178
5474
  model: resolvedModel,
5475
+ sessionKey: plan.contentSessionKey,
5179
5476
  preferredAccountId: plan.preferredAccountId,
5180
5477
  preferredAccountGroup: plan.preferredAccountGroup,
5181
5478
  boundAccountFallbackPolicy: plan.boundAccountFallbackPolicy,
@@ -5197,14 +5494,36 @@ async function runPipeline3(chatBody, plan) {
5197
5494
  if (value !== void 0 && !(key in headers)) headers[key] = value;
5198
5495
  }
5199
5496
  }
5497
+ if (plan.proxyProviderId === "codex") _chunkSQU2FGXIcjs.fillMissingCodexCliIdentity.call(void 0, headers);
5200
5498
  return headers;
5201
5499
  },
5202
5500
  fetchFn: (url, headers, body) => {
5203
5501
  console.log(`[ProviderProxy:chat] -> ${url} model=${resolvedModel} stream=${isStream}`);
5204
- return _chunkVFFCV4J6cjs.fetchUpstream.call(void 0,
5502
+ const sessionKey = plan.routeSessionId || void 0;
5503
+ return _chunkCXRJMNJJcjs.fetchUpstream.call(void 0,
5205
5504
  url,
5206
5505
  { method: "POST", headers, body: JSON.stringify(body) },
5207
- { providerId: plan.proxyProviderId, accountId: proxyAccountId }
5506
+ {
5507
+ providerId: plan.proxyProviderId,
5508
+ accountId: proxyAccountId,
5509
+ routeActivity: plan.isSubscription ? {
5510
+ providerId: plan.proxyProviderId,
5511
+ credentialKind: "subscription-account",
5512
+ accountId: proxyAccountId,
5513
+ endpoint: "chat",
5514
+ sessionKey,
5515
+ sessionSource: sessionKey ? "route-session-id" : "none",
5516
+ model: resolvedModel
5517
+ } : {
5518
+ providerId: _nullishCoalesce(_optionalChain([plan, 'access', _290 => _290.byoActivity, 'optionalAccess', _291 => _291.providerId]), () => ( transformerProvider.name)),
5519
+ credentialKind: "provider-key",
5520
+ keyId: _optionalChain([plan, 'access', _292 => _292.byoActivity, 'optionalAccess', _293 => _293.resolveKeyId, 'call', _294 => _294()]),
5521
+ endpoint: "chat",
5522
+ sessionKey,
5523
+ sessionSource: sessionKey ? "route-session-id" : "none",
5524
+ model: resolvedModel
5525
+ }
5526
+ }
5208
5527
  ).then((r) => {
5209
5528
  rawStatus = r.status;
5210
5529
  return r;
@@ -5216,8 +5535,8 @@ async function runPipeline3(chatBody, plan) {
5216
5535
  }
5217
5536
  async function runPipelineWithPoolReporting3(chatBody, plan) {
5218
5537
  const first = await runPipeline3(chatBody, plan);
5219
- const outcome = await _optionalChain([plan, 'access', _263 => _263.auth, 'access', _264 => _264.onResult, 'optionalCall', _265 => _265(first.rawStatus)]);
5220
- if (_optionalChain([outcome, 'optionalAccess', _266 => _266.rebound])) {
5538
+ const outcome = await _optionalChain([plan, 'access', _295 => _295.auth, 'access', _296 => _296.onResult, 'optionalCall', _297 => _297(first.rawStatus)]);
5539
+ if (_optionalChain([outcome, 'optionalAccess', _298 => _298.rebound])) {
5221
5540
  console.log(
5222
5541
  "[ProviderProxy:chat] pool re-bound key after status",
5223
5542
  first.rawStatus,
@@ -5230,7 +5549,7 @@ async function runPipelineWithPoolReporting3(chatBody, plan) {
5230
5549
  async function runPipelineWithSubscriptionRetry2(chatBody, plan) {
5231
5550
  const first = await runPipeline3(chatBody, plan);
5232
5551
  if (first.rawStatus !== 401) return first;
5233
- const refreshed = await _optionalChain([plan, 'access', _267 => _267.auth, 'access', _268 => _268.onUnauthorized, 'optionalCall', _269 => _269()]);
5552
+ const refreshed = await _optionalChain([plan, 'access', _299 => _299.auth, 'access', _300 => _300.onUnauthorized, 'optionalCall', _301 => _301()]);
5234
5553
  if (!refreshed) {
5235
5554
  console.warn("[ProviderProxy:chat] 401 not recoverable (onUnauthorized returned false)");
5236
5555
  return first;
@@ -5252,7 +5571,7 @@ function resolveRouteToken(req) {
5252
5571
  if (fromAuth) return fromAuth;
5253
5572
  const googKey = req.headers["x-goog-api-key"];
5254
5573
  const value = Array.isArray(googKey) ? googKey[0] : googKey;
5255
- return _optionalChain([value, 'optionalAccess', _270 => _270.trim, 'call', _271 => _271()]) || void 0;
5574
+ return _optionalChain([value, 'optionalAccess', _302 => _302.trim, 'call', _303 => _303()]) || void 0;
5256
5575
  }
5257
5576
  async function routeRequest(req, res, routes, deps) {
5258
5577
  if (classifyAnthropicMessagesPath(req.url) !== null) {
@@ -5267,7 +5586,7 @@ async function routeRequest(req, res, routes, deps) {
5267
5586
  const method = req.method;
5268
5587
  const url = req.url;
5269
5588
  const openAIOperation = _chunkG4CZIUIBcjs.classifyOpenAIOperation.call(void 0, method, url);
5270
- if (_optionalChain([openAIOperation, 'optionalAccess', _272 => _272.owner]) === "extension") {
5589
+ if (_optionalChain([openAIOperation, 'optionalAccess', _304 => _304.owner]) === "extension") {
5271
5590
  const registry = deps.openAIOperationRegistry;
5272
5591
  if (!registry) {
5273
5592
  _chunkG4CZIUIBcjs.writeOpenAIOperationError.call(void 0, res, _chunkG4CZIUIBcjs.unsupportedOpenAIOperation.call(void 0, openAIOperation));
@@ -5289,7 +5608,7 @@ async function routeRequest(req, res, routes, deps) {
5289
5608
  await handleAnthropicMessagesRequest(req, res, route, deps);
5290
5609
  return;
5291
5610
  }
5292
- if (_optionalChain([openAIOperation, 'optionalAccess', _273 => _273.id]) === "responses.create") {
5611
+ if (_optionalChain([openAIOperation, 'optionalAccess', _305 => _305.id]) === "responses.create") {
5293
5612
  const abortScope = createResponsesAbortScope({ request: req, response: res });
5294
5613
  try {
5295
5614
  const rawBody = await readBody(req, abortScope.signal);
@@ -5320,7 +5639,7 @@ async function routeRequest(req, res, routes, deps) {
5320
5639
  }
5321
5640
  return;
5322
5641
  }
5323
- if (_optionalChain([openAIOperation, 'optionalAccess', _274 => _274.id]) === "chat.completions.create") {
5642
+ if (_optionalChain([openAIOperation, 'optionalAccess', _306 => _306.id]) === "chat.completions.create") {
5324
5643
  const rawBody = await readBody(req);
5325
5644
  await handleOpenAIChatRequest(res, rawBody, route, deps);
5326
5645
  return;
@@ -5391,7 +5710,7 @@ var ProviderProxy = (_class8 = class {
5391
5710
  for (const cleanup of [...this.beforeStop]) {
5392
5711
  try {
5393
5712
  await cleanup();
5394
- } catch (e43) {
5713
+ } catch (e47) {
5395
5714
  }
5396
5715
  }
5397
5716
  this.routes.clear();
@@ -5677,7 +5996,7 @@ var SYSTEM_ROUTE_LEASE_CLOCK = {
5677
5996
  now: () => Date.now(),
5678
5997
  setTimeout(callback, delayMs) {
5679
5998
  const timer = setTimeout(callback, delayMs);
5680
- _optionalChain([timer, 'access', _275 => _275.unref, 'optionalCall', _276 => _276()]);
5999
+ _optionalChain([timer, 'access', _307 => _307.unref, 'optionalCall', _308 => _308()]);
5681
6000
  return timer;
5682
6001
  },
5683
6002
  clearTimeout(handle) {
@@ -5771,12 +6090,12 @@ var RouteLeaseManager = (_class10 = class {
5771
6090
  this.assertOpen();
5772
6091
  const route = {
5773
6092
  ...resolved,
5774
- sessionId: _nullishCoalesce(_optionalChain([request, 'access', _277 => _277.execution, 'optionalAccess', _278 => _278.sessionIdHash]), () => ( null)),
6093
+ sessionId: _nullishCoalesce(_optionalChain([request, 'access', _309 => _309.execution, 'optionalAccess', _310 => _310.sessionIdHash]), () => ( null)),
5775
6094
  routeLease: {
5776
6095
  leaseId,
5777
6096
  consumer: request.consumer,
5778
- ..._optionalChain([request, 'access', _279 => _279.execution, 'optionalAccess', _280 => _280.runId]) ? { runId: request.execution.runId } : {},
5779
- ..._optionalChain([request, 'access', _281 => _281.execution, 'optionalAccess', _282 => _282.stageId]) ? { stageId: request.execution.stageId } : {}
6097
+ ..._optionalChain([request, 'access', _311 => _311.execution, 'optionalAccess', _312 => _312.runId]) ? { runId: request.execution.runId } : {},
6098
+ ..._optionalChain([request, 'access', _313 => _313.execution, 'optionalAccess', _314 => _314.stageId]) ? { stageId: request.execution.stageId } : {}
5780
6099
  }
5781
6100
  };
5782
6101
  const now = this.clock.now();
@@ -5831,7 +6150,7 @@ var RouteLeaseManager = (_class10 = class {
5831
6150
  this.active.set(leaseId, activeLease);
5832
6151
  this.idempotency.set(scope, { leaseId, payloadHash: input.payloadHash });
5833
6152
  published = true;
5834
- _optionalChain([this, 'access', _283 => _283.afterPublish, 'optionalCall', _284 => _284()]);
6153
+ _optionalChain([this, 'access', _315 => _315.afterPublish, 'optionalCall', _316 => _316()]);
5835
6154
  if (this.closed) {
5836
6155
  this.finalize(activeLease, "released");
5837
6156
  throw new RouteLeaseError("daemon_not_ready", "route lease manager is shutting down");
@@ -5868,7 +6187,7 @@ var RouteLeaseManager = (_class10 = class {
5868
6187
  if (!lease) {
5869
6188
  this.pruneTombstones();
5870
6189
  const known = this.tombstones.get(leaseId);
5871
- if (_optionalChain([known, 'optionalAccess', _285 => _285.metadata, 'access', _286 => _286.status]) === "expired") {
6190
+ if (_optionalChain([known, 'optionalAccess', _317 => _317.metadata, 'access', _318 => _318.status]) === "expired") {
5872
6191
  throw new RouteLeaseError("lease_expired", "route lease has expired");
5873
6192
  }
5874
6193
  throw new RouteLeaseError("lease_not_found", "route lease was not found");
@@ -5905,7 +6224,7 @@ var RouteLeaseManager = (_class10 = class {
5905
6224
  try {
5906
6225
  this.finalize(lease, "released");
5907
6226
  } catch (error) {
5908
- _optionalChain([this, 'access', _287 => _287.logger, 'optionalAccess', _288 => _288.warn, 'call', _289 => _289("route lease cleanup failed during shutdown", { leaseId: lease.leaseId, error: safeErrorName(error) })]);
6227
+ _optionalChain([this, 'access', _319 => _319.logger, 'optionalAccess', _320 => _320.warn, 'call', _321 => _321("route lease cleanup failed during shutdown", { leaseId: lease.leaseId, error: safeErrorName(error) })]);
5909
6228
  }
5910
6229
  }
5911
6230
  }
@@ -5951,7 +6270,7 @@ var RouteLeaseManager = (_class10 = class {
5951
6270
  try {
5952
6271
  this.routePort.removeRoute(routeToken);
5953
6272
  } catch (error) {
5954
- _optionalChain([this, 'access', _290 => _290.logger, 'optionalAccess', _291 => _291.warn, 'call', _292 => _292("route lease route cleanup failed", { leaseId, error: safeErrorName(error) })]);
6273
+ _optionalChain([this, 'access', _322 => _322.logger, 'optionalAccess', _323 => _323.warn, 'call', _324 => _324("route lease route cleanup failed", { leaseId, error: safeErrorName(error) })]);
5955
6274
  }
5956
6275
  }
5957
6276
  pruneTombstones() {
@@ -5976,33 +6295,38 @@ function nonBlank(value) {
5976
6295
  return typeof value === "string" && value.trim() !== "";
5977
6296
  }
5978
6297
  function gatewayBindingAllowsKey(binding, apiKeyId) {
5979
- const scope = _nullishCoalesce(binding.keyScope, () => ( (_optionalChain([binding, 'access', _293 => _293.apiKeyIds, 'optionalAccess', _294 => _294.length]) ? "selected" : "all")));
5980
- return scope === "all" || Boolean(_optionalChain([binding, 'access', _295 => _295.apiKeyIds, 'optionalAccess', _296 => _296.includes, 'call', _297 => _297(apiKeyId)]));
6298
+ const scope = _nullishCoalesce(binding.keyScope, () => ( (_optionalChain([binding, 'access', _325 => _325.apiKeyIds, 'optionalAccess', _326 => _326.length]) ? "selected" : "all")));
6299
+ return scope === "all" || Boolean(_optionalChain([binding, 'access', _327 => _327.apiKeyIds, 'optionalAccess', _328 => _328.includes, 'call', _329 => _329(apiKeyId)]));
5981
6300
  }
5982
6301
  function wildcardMatches(pattern, value) {
5983
6302
  const escaped = pattern.split("*").map((part) => part.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&")).join(".*");
5984
6303
  return new RegExp(`^${escaped}$`, "iu").test(value);
5985
6304
  }
5986
- function resolveGatewayModelMapping(mappings, requestedModel) {
6305
+ function resolveGatewayModelMappingRow(mappings, requestedModel) {
5987
6306
  if (!nonBlank(requestedModel)) return void 0;
5988
6307
  const wanted = requestedModel.trim();
5989
6308
  const exact = (_nullishCoalesce(mappings, () => ( []))).find(
5990
6309
  (mapping) => nonBlank(mapping.source) && !mapping.source.includes("*") && mapping.source.trim().toLocaleLowerCase() === wanted.toLocaleLowerCase()
5991
6310
  );
5992
- if (exact && nonBlank(exact.target)) return exact.target.trim();
6311
+ if (exact && nonBlank(exact.target)) {
6312
+ return { target: exact.target.trim(), effort: exact.effort };
6313
+ }
5993
6314
  const wildcard = (_nullishCoalesce(mappings, () => ( []))).find(
5994
6315
  (mapping) => nonBlank(mapping.source) && mapping.source.includes("*") && wildcardMatches(mapping.source.trim(), wanted)
5995
6316
  );
5996
- return wildcard && nonBlank(wildcard.target) ? wildcard.target.trim() : void 0;
6317
+ return wildcard && nonBlank(wildcard.target) ? { target: wildcard.target.trim(), effort: wildcard.effort } : void 0;
6318
+ }
6319
+ function resolveGatewayModelMapping(mappings, requestedModel) {
6320
+ return _optionalChain([resolveGatewayModelMappingRow, 'call', _330 => _330(mappings, requestedModel), 'optionalAccess', _331 => _331.target]);
5997
6321
  }
5998
6322
  function routeCanServe(binding, requestedModel, role) {
5999
6323
  if (binding.modelMode === "passthrough") return nonBlank(requestedModel);
6000
- if (_optionalChain([binding, 'access', _298 => _298.modelMappings, 'optionalAccess', _299 => _299.length])) {
6324
+ if (_optionalChain([binding, 'access', _332 => _332.modelMappings, 'optionalAccess', _333 => _333.length])) {
6001
6325
  return nonBlank(resolveGatewayModelMapping(binding.modelMappings, requestedModel));
6002
6326
  }
6003
- if (_chunk57Y2EA2Gcjs.isKindMappedEndpoint.call(void 0, binding.endpoint)) {
6327
+ if (_chunkJGRNVH7Ccjs.isKindMappedEndpoint.call(void 0, binding.endpoint)) {
6004
6328
  const map = _nullishCoalesce(binding.modelMap, () => ( {}));
6005
- const kind = _chunk57Y2EA2Gcjs.detectModelKind.call(void 0, binding.endpoint, requestedModel);
6329
+ const kind = _chunkJGRNVH7Ccjs.detectModelKind.call(void 0, binding.endpoint, requestedModel);
6006
6330
  if (kind && nonBlank(map[kind])) return true;
6007
6331
  if (binding.endpoint === "messages") {
6008
6332
  return MESSAGE_FALLBACK_KINDS.some((candidate) => nonBlank(map[candidate]));
@@ -6010,12 +6334,12 @@ function routeCanServe(binding, requestedModel, role) {
6010
6334
  return nonBlank(map.codex);
6011
6335
  }
6012
6336
  if (binding.endpoint === "chat" && binding.dispatchMode === "prefix") {
6013
- return _chunk57Y2EA2Gcjs.resolvePrefixTarget.call(void 0, binding.prefixTargets, requestedModel) !== null;
6337
+ return _chunkJGRNVH7Ccjs.resolvePrefixTarget.call(void 0, binding.prefixTargets, requestedModel) !== null;
6014
6338
  }
6015
6339
  if (binding.endpoint === "chat") {
6016
6340
  if (!requestedModel) return false;
6017
6341
  const wanted = requestedModel.trim().toLowerCase();
6018
- return (_nullishCoalesce(binding.models, () => ( []))).some((ref) => _optionalChain([modelIdOf, 'call', _300 => _300(ref), 'optionalAccess', _301 => _301.toLowerCase, 'call', _302 => _302()]) === wanted);
6342
+ return (_nullishCoalesce(binding.models, () => ( []))).some((ref) => _optionalChain([modelIdOf, 'call', _334 => _334(ref), 'optionalAccess', _335 => _335.toLowerCase, 'call', _336 => _336()]) === wanted);
6019
6343
  }
6020
6344
  return role === "background" ? nonBlank(binding.backgroundModel) : nonBlank(binding.defaultModel);
6021
6345
  }
@@ -6048,9 +6372,9 @@ function targetPrefixRefs(target, refs) {
6048
6372
  function applySingleModel(config, binding, targetModel) {
6049
6373
  const ref = targetRef(binding.target, targetModel);
6050
6374
  if (!ref) return;
6051
- if (_chunk57Y2EA2Gcjs.isKindMappedEndpoint.call(void 0, binding.endpoint)) {
6375
+ if (_chunkJGRNVH7Ccjs.isKindMappedEndpoint.call(void 0, binding.endpoint)) {
6052
6376
  config.modelMap = Object.fromEntries(
6053
- _chunk57Y2EA2Gcjs.modelKindsForEndpoint.call(void 0, binding.endpoint).map((kind) => [kind, ref])
6377
+ _chunkJGRNVH7Ccjs.modelKindsForEndpoint.call(void 0, binding.endpoint).map((kind) => [kind, ref])
6054
6378
  );
6055
6379
  } else if (binding.endpoint === "chat") {
6056
6380
  config.models = [ref];
@@ -6066,11 +6390,13 @@ function gatewayBindingToEndpointConfig(binding, requestedModel) {
6066
6390
  endpoint: binding.endpoint,
6067
6391
  useSubscription: target.kind !== "provider"
6068
6392
  };
6069
- const usesGenericModelHandling = binding.modelMode === "passthrough" || Boolean(_optionalChain([binding, 'access', _303 => _303.modelMappings, 'optionalAccess', _304 => _304.length]));
6070
- const dynamicModel = binding.modelMode === "passthrough" ? requestedModel : resolveGatewayModelMapping(binding.modelMappings, requestedModel);
6393
+ const usesGenericModelHandling = binding.modelMode === "passthrough" || Boolean(_optionalChain([binding, 'access', _337 => _337.modelMappings, 'optionalAccess', _338 => _338.length]));
6394
+ const winningMapping = binding.modelMode === "passthrough" ? void 0 : resolveGatewayModelMappingRow(binding.modelMappings, requestedModel);
6395
+ const dynamicModel = binding.modelMode === "passthrough" ? requestedModel : _optionalChain([winningMapping, 'optionalAccess', _339 => _339.target]);
6071
6396
  if (usesGenericModelHandling) {
6072
6397
  if (nonBlank(dynamicModel)) applySingleModel(config, binding, dynamicModel);
6073
- } else if (_chunk57Y2EA2Gcjs.isKindMappedEndpoint.call(void 0, binding.endpoint)) {
6398
+ if (_optionalChain([winningMapping, 'optionalAccess', _340 => _340.effort])) config.reasoningEffort = winningMapping.effort;
6399
+ } else if (_chunkJGRNVH7Ccjs.isKindMappedEndpoint.call(void 0, binding.endpoint)) {
6074
6400
  config.modelMap = Object.fromEntries(
6075
6401
  Object.entries(_nullishCoalesce(binding.modelMap, () => ( {}))).map(([kind, ref]) => [kind, targetRef(target, ref)])
6076
6402
  );
@@ -6101,7 +6427,7 @@ function candidateGatewayBindings(bindings, apiKeyId, endpoint) {
6101
6427
  const candidates = (_nullishCoalesce(bindings, () => ( []))).filter(
6102
6428
  (binding) => binding.enabled && binding.endpoint === endpoint && gatewayBindingAllowsKey(binding, apiKeyId)
6103
6429
  );
6104
- const scopeOf = (binding) => _nullishCoalesce(binding.keyScope, () => ( (_optionalChain([binding, 'access', _305 => _305.apiKeyIds, 'optionalAccess', _306 => _306.length]) ? "selected" : "all")));
6430
+ const scopeOf = (binding) => _nullishCoalesce(binding.keyScope, () => ( (_optionalChain([binding, 'access', _341 => _341.apiKeyIds, 'optionalAccess', _342 => _342.length]) ? "selected" : "all")));
6105
6431
  const scoped = candidates.filter((binding) => scopeOf(binding) === "selected");
6106
6432
  const pool = scoped.length > 0 ? scoped : candidates.filter((binding) => scopeOf(binding) === "all");
6107
6433
  return pool.sort(
@@ -6155,7 +6481,7 @@ function syntheticBinding(request) {
6155
6481
  };
6156
6482
  }
6157
6483
  function transformerRegistered(llmConfig, name) {
6158
- return Boolean(_optionalChain([llmConfig, 'access', _307 => _307.getTransformerService, 'call', _308 => _308(), 'optionalAccess', _309 => _309.getTransformer, 'call', _310 => _310(name)]));
6484
+ return Boolean(_optionalChain([llmConfig, 'access', _343 => _343.getTransformerService, 'call', _344 => _344(), 'optionalAccess', _345 => _345.getTransformer, 'call', _346 => _346(name)]));
6159
6485
  }
6160
6486
  var RouteLeaseTargetResolver = class {
6161
6487
  constructor(llmConfig, options = {}) {
@@ -6169,12 +6495,12 @@ var RouteLeaseTargetResolver = class {
6169
6495
  await this.preflightTarget(request);
6170
6496
  const binding = syntheticBinding(request);
6171
6497
  const config = gatewayBindingToEndpointConfig(binding, request.model);
6172
- const result = await _chunk57Y2EA2Gcjs.resolveRoute.call(void 0, {
6498
+ const result = await _chunkJGRNVH7Ccjs.resolveRoute.call(void 0, {
6173
6499
  config,
6174
6500
  ingressFormat: runtime.ingressFormat,
6175
6501
  llmConfig: this.llmConfig,
6176
6502
  requestedModel: request.model,
6177
- sessionId: _nullishCoalesce(_optionalChain([request, 'access', _311 => _311.execution, 'optionalAccess', _312 => _312.sessionIdHash]), () => ( null))
6503
+ sessionId: _nullishCoalesce(_optionalChain([request, 'access', _347 => _347.execution, 'optionalAccess', _348 => _348.sessionIdHash]), () => ( null))
6178
6504
  });
6179
6505
  if (!result.ok) {
6180
6506
  throw new RouteLeaseError(
@@ -6197,7 +6523,7 @@ var RouteLeaseTargetResolver = class {
6197
6523
  throw new RouteLeaseError("model_not_configured", "model is not configured for the provider");
6198
6524
  }
6199
6525
  if (target.keyId) {
6200
- const availability = await _optionalChain([this, 'access', _313 => _313.options, 'access', _314 => _314.providerKeys, 'optionalAccess', _315 => _315.getKeyAvailability, 'optionalCall', _316 => _316(
6526
+ const availability = await _optionalChain([this, 'access', _349 => _349.options, 'access', _350 => _350.providerKeys, 'optionalAccess', _351 => _351.getKeyAvailability, 'optionalCall', _352 => _352(
6201
6527
  target.providerId,
6202
6528
  target.keyId
6203
6529
  )]);
@@ -6210,9 +6536,9 @@ var RouteLeaseTargetResolver = class {
6210
6536
  }
6211
6537
  } else {
6212
6538
  const directKey = resolveEnvKey(provider.api_key);
6213
- const poolAvailability = await _optionalChain([this, 'access', _317 => _317.options, 'access', _318 => _318.providerKeys, 'optionalAccess', _319 => _319.getPoolAvailability, 'optionalCall', _320 => _320(target.providerId)]);
6539
+ const poolAvailability = await _optionalChain([this, 'access', _353 => _353.options, 'access', _354 => _354.providerKeys, 'optionalAccess', _355 => _355.getPoolAvailability, 'optionalCall', _356 => _356(target.providerId)]);
6214
6540
  const poolReady = poolAvailability ? poolAvailability.outcome === "usable" : this.options.providerKeys ? await this.options.providerKeys.hasUsableKeys(target.providerId) : false;
6215
- if (!directKey && _optionalChain([poolAvailability, 'optionalAccess', _321 => _321.outcome]) === "exhausted") {
6541
+ if (!directKey && _optionalChain([poolAvailability, 'optionalAccess', _357 => _357.outcome]) === "exhausted") {
6216
6542
  throw new RouteLeaseError("upstream_exhausted", "provider key pool is temporarily exhausted", {
6217
6543
  retryAfterSeconds: poolAvailability.retryAfterSeconds
6218
6544
  });
@@ -6236,14 +6562,14 @@ var RouteLeaseTargetResolver = class {
6236
6562
  }
6237
6563
  async preflightSubscription(target, model) {
6238
6564
  const registry = _chunkQBZJ7P2Tcjs.getSubscriptionRegistryForOutbound.call(void 0, );
6239
- const profile = _nullishCoalesce(_optionalChain([registry, 'optionalAccess', _322 => _322.getProfile, 'call', _323 => _323(target.providerId)]), () => ( null));
6565
+ const profile = _nullishCoalesce(_optionalChain([registry, 'optionalAccess', _358 => _358.getProfile, 'call', _359 => _359(target.providerId)]), () => ( null));
6240
6566
  if (!profile) throw new RouteLeaseError("upstream_not_found", "subscription provider was not found");
6241
- await _optionalChain([this, 'access', _324 => _324.options, 'access', _325 => _325.subscriptions, 'optionalAccess', _326 => _326.assertAvailable, 'call', _327 => _327(target, model)]);
6242
- const names = _nullishCoalesce(_nullishCoalesce(_optionalChain([profile, 'access', _328 => _328.resolveProviderTransformerNames, 'optionalCall', _329 => _329(model)]), () => ( profile.providerTransformerNames)), () => ( []));
6567
+ await _optionalChain([this, 'access', _360 => _360.options, 'access', _361 => _361.subscriptions, 'optionalAccess', _362 => _362.assertAvailable, 'call', _363 => _363(target, model)]);
6568
+ const names = _nullishCoalesce(_nullishCoalesce(_optionalChain([profile, 'access', _364 => _364.resolveProviderTransformerNames, 'optionalCall', _365 => _365(model)]), () => ( profile.providerTransformerNames)), () => ( []));
6243
6569
  if (names.some((name) => !transformerRegistered(this.llmConfig, name))) {
6244
6570
  throw new RouteLeaseError("format_unsupported", "a required transformer is unavailable");
6245
6571
  }
6246
- if (_optionalChain([profile, 'access', _330 => _330.modelTransformerNames, 'optionalAccess', _331 => _331.some, 'call', _332 => _332((name) => !transformerRegistered(this.llmConfig, name))])) {
6572
+ if (_optionalChain([profile, 'access', _366 => _366.modelTransformerNames, 'optionalAccess', _367 => _367.some, 'call', _368 => _368((name) => !transformerRegistered(this.llmConfig, name))])) {
6247
6573
  throw new RouteLeaseError("format_unsupported", "a required model transformer is unavailable");
6248
6574
  }
6249
6575
  }
@@ -6265,7 +6591,7 @@ function createResponsesCompactHandler(options = {}) {
6265
6591
  const parsed = JSON.parse(rawBody);
6266
6592
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error();
6267
6593
  body = parsed;
6268
- } catch (e44) {
6594
+ } catch (e48) {
6269
6595
  throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({
6270
6596
  status: 400,
6271
6597
  code: "invalid_request_body",
@@ -6356,7 +6682,7 @@ var BoundedSseFrameDecoder = class {
6356
6682
  let decoded;
6357
6683
  try {
6358
6684
  decoded = this.#decoder.decode(chunk, { stream: true });
6359
- } catch (e45) {
6685
+ } catch (e49) {
6360
6686
  protocolFailure2();
6361
6687
  }
6362
6688
  return this.#append(decoded, false);
@@ -6365,7 +6691,7 @@ var BoundedSseFrameDecoder = class {
6365
6691
  let tail;
6366
6692
  try {
6367
6693
  tail = this.#decoder.decode();
6368
- } catch (e46) {
6694
+ } catch (e50) {
6369
6695
  protocolFailure2();
6370
6696
  }
6371
6697
  const frames = this.#append(tail, true);
@@ -6495,7 +6821,7 @@ var HostedImageSsePipeline = class {
6495
6821
  if (this.#cancelPromise) return this.#cancelPromise;
6496
6822
  this.#cancelled = true;
6497
6823
  this.#cancelPromise = Promise.allSettled([
6498
- _nullishCoalesce(_optionalChain([this, 'access', _333 => _333.#reader, 'optionalAccess', _334 => _334.cancel, 'call', _335 => _335(reason)]), () => ( Promise.resolve())),
6824
+ _nullishCoalesce(_optionalChain([this, 'access', _369 => _369.#reader, 'optionalAccess', _370 => _370.cancel, 'call', _371 => _371(reason)]), () => ( Promise.resolve())),
6499
6825
  this.#closeActiveImageIterator(),
6500
6826
  this.#options.onCancel()
6501
6827
  ]).then(() => void 0);
@@ -6509,7 +6835,7 @@ var HostedImageSsePipeline = class {
6509
6835
  let parsed;
6510
6836
  try {
6511
6837
  parsed = JSON.parse(frame2.data);
6512
- } catch (e47) {
6838
+ } catch (e51) {
6513
6839
  protocolFailure2();
6514
6840
  }
6515
6841
  if (!isRecord8(parsed) || typeof parsed.type !== "string" || parsed.type.length > 256) {
@@ -6866,7 +7192,7 @@ data: ${JSON.stringify(event)}
6866
7192
  #closeActiveImageIterator() {
6867
7193
  if (this.#activeImageIteratorClose) return this.#activeImageIteratorClose;
6868
7194
  const iterator = this.#activeImageIterator;
6869
- if (!_optionalChain([iterator, 'optionalAccess', _336 => _336.return])) return Promise.resolve();
7195
+ if (!_optionalChain([iterator, 'optionalAccess', _372 => _372.return])) return Promise.resolve();
6870
7196
  this.#activeImageIteratorClose = Promise.resolve(iterator.return()).then(
6871
7197
  () => void 0,
6872
7198
  () => void 0
@@ -6903,7 +7229,7 @@ function createNativeResponsesHostedImageSseResponse(options) {
6903
7229
  },
6904
7230
  async cancel(reason) {
6905
7231
  await pipeline.cancel(reason);
6906
- await _optionalChain([iterator, 'access', _337 => _337.return, 'optionalCall', _338 => _338()]);
7232
+ await _optionalChain([iterator, 'access', _373 => _373.return, 'optionalCall', _374 => _374()]);
6907
7233
  }
6908
7234
  });
6909
7235
  return transformedResponse(options.upstream, body);
@@ -6975,7 +7301,7 @@ function parseJsonObject(bytes) {
6975
7301
  let text;
6976
7302
  try {
6977
7303
  text = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
6978
- } catch (e48) {
7304
+ } catch (e52) {
6979
7305
  protocolFailure3();
6980
7306
  }
6981
7307
  try {
@@ -7148,7 +7474,7 @@ var NativeResponsesHostedImageRequestLease = class {
7148
7474
  #wrapSse(input) {
7149
7475
  const status = _nullishCoalesce(input.rawStatus, () => ( input.response.status));
7150
7476
  if (status < 200 || status >= 300) return input.response;
7151
- const hasInheritedContext = _optionalChain([this, 'access', _339 => _339.#input, 'access', _340 => _340.previousHostedImageState, 'optionalAccess', _341 => _341.hasImageContext]) === true;
7477
+ const hasInheritedContext = _optionalChain([this, 'access', _375 => _375.#input, 'access', _376 => _376.previousHostedImageState, 'optionalAccess', _377 => _377.hasImageContext]) === true;
7152
7478
  return createNativeResponsesHostedImageSseResponse({
7153
7479
  upstream: input.response,
7154
7480
  signal: this.#input.signal,
@@ -7174,7 +7500,7 @@ var NativeResponsesHostedImageRequestLease = class {
7174
7500
  signal: this.#input.signal,
7175
7501
  ...this.#input.authorizedPreviousResponseId ? {
7176
7502
  authorizedPreviousResponseId: this.#input.authorizedPreviousResponseId,
7177
- authorizedPreviousResponseKnownEmpty: _optionalChain([this, 'access', _342 => _342.#input, 'access', _343 => _343.previousHostedImageState, 'optionalAccess', _344 => _344.hasImageContext]) !== true
7503
+ authorizedPreviousResponseKnownEmpty: _optionalChain([this, 'access', _378 => _378.#input, 'access', _379 => _379.previousHostedImageState, 'optionalAccess', _380 => _380.hasImageContext]) !== true
7178
7504
  } : {},
7179
7505
  mainProviderId: this.#input.mainProviderId,
7180
7506
  ...input.selectedMainAccountId ? { selectedMainAccountId: input.selectedMainAccountId } : {}
@@ -7209,7 +7535,7 @@ var NativeResponsesHostedImageRequestLease = class {
7209
7535
  if (!UPSTREAM_CALL_ID_PATTERN4.test(selected.upstreamCallId)) protocolFailure3();
7210
7536
  }
7211
7537
  this.#runtime.validateSelection(this.#admission, parsedSelection.selection);
7212
- const hasInheritedContext = _optionalChain([this, 'access', _345 => _345.#input, 'access', _346 => _346.previousHostedImageState, 'optionalAccess', _347 => _347.hasImageContext]) === true;
7538
+ const hasInheritedContext = _optionalChain([this, 'access', _381 => _381.#input, 'access', _382 => _382.previousHostedImageState, 'optionalAccess', _383 => _383.hasImageContext]) === true;
7213
7539
  const requiresScope = parsedSelection.imageCalls.length > 0 || hasInheritedContext || this.#admission.explicitCallIds.length > 0;
7214
7540
  const publicOutput = [...upstreamBody.output];
7215
7541
  const pendingReceipts = [];
@@ -7226,7 +7552,7 @@ var NativeResponsesHostedImageRequestLease = class {
7226
7552
  signal: this.#input.signal,
7227
7553
  ...this.#input.authorizedPreviousResponseId ? {
7228
7554
  authorizedPreviousResponseId: this.#input.authorizedPreviousResponseId,
7229
- authorizedPreviousResponseKnownEmpty: _optionalChain([this, 'access', _348 => _348.#input, 'access', _349 => _349.previousHostedImageState, 'optionalAccess', _350 => _350.hasImageContext]) !== true
7555
+ authorizedPreviousResponseKnownEmpty: _optionalChain([this, 'access', _384 => _384.#input, 'access', _385 => _385.previousHostedImageState, 'optionalAccess', _386 => _386.hasImageContext]) !== true
7230
7556
  } : {},
7231
7557
  mainProviderId: this.#input.mainProviderId,
7232
7558
  ...input.selectedMainAccountId ? { selectedMainAccountId: input.selectedMainAccountId } : {}
@@ -7272,7 +7598,7 @@ function createNativeResponsesHostedImageIngress(runtimeFactory, options = {}) {
7272
7598
  const createRequestId = _nullishCoalesce(options.createRequestId, () => ( (() => `hosted-image-${_crypto.randomUUID.call(void 0, )}`)));
7273
7599
  return Object.freeze({
7274
7600
  prepare: async (input) => {
7275
- if (input.operation !== "create" || input.profile !== "native" || !hasImageOwnedResponsesInput(input.body) && !_optionalChain([input, 'access', _351 => _351.previousHostedImageState, 'optionalAccess', _352 => _352.hasImageContext]) && !_optionalChain([input, 'access', _353 => _353.previousHostedImageState, 'optionalAccess', _354 => _354.pendingReceipts, 'access', _355 => _355.length])) {
7601
+ if (input.operation !== "create" || input.profile !== "native" || !hasImageOwnedResponsesInput(input.body) && !_optionalChain([input, 'access', _387 => _387.previousHostedImageState, 'optionalAccess', _388 => _388.hasImageContext]) && !_optionalChain([input, 'access', _389 => _389.previousHostedImageState, 'optionalAccess', _390 => _390.pendingReceipts, 'access', _391 => _391.length])) {
7276
7602
  return null;
7277
7603
  }
7278
7604
  if (!input.hostedImageGenerationAllowed) {
@@ -7305,7 +7631,7 @@ function createNativeResponsesHostedImageIngress(runtimeFactory, options = {}) {
7305
7631
  const selection = prepareNativeResponsesImageSelection({
7306
7632
  body: input.body,
7307
7633
  admission,
7308
- pendingReceipts: _optionalChain([input, 'access', _356 => _356.previousHostedImageState, 'optionalAccess', _357 => _357.pendingReceipts]),
7634
+ pendingReceipts: _optionalChain([input, 'access', _392 => _392.previousHostedImageState, 'optionalAccess', _393 => _393.pendingReceipts]),
7309
7635
  ...options.createSelectorName ? { createSelectorName: options.createSelectorName } : {}
7310
7636
  });
7311
7637
  return new NativeResponsesHostedImageRequestLease({
@@ -7964,9 +8290,9 @@ function stringList(value, cap) {
7964
8290
  }
7965
8291
  function tavilyConfig(value) {
7966
8292
  const raw = record4(value);
7967
- const apiKey = configString(_optionalChain([raw, 'optionalAccess', _358 => _358["apiKey"]]));
8293
+ const apiKey = configString(_optionalChain([raw, 'optionalAccess', _394 => _394["apiKey"]]));
7968
8294
  if (!apiKey) return void 0;
7969
- const apiHost = configString(_optionalChain([raw, 'optionalAccess', _359 => _359["apiHost"]]));
8295
+ const apiHost = configString(_optionalChain([raw, 'optionalAccess', _395 => _395["apiHost"]]));
7970
8296
  return { apiKey, ...apiHost ? { apiHost } : {} };
7971
8297
  }
7972
8298
  function jinaConfig(value) {
@@ -7978,10 +8304,10 @@ function jinaConfig(value) {
7978
8304
  }
7979
8305
  function searxngConfig(value) {
7980
8306
  const raw = record4(value);
7981
- const apiHost = configString(_optionalChain([raw, 'optionalAccess', _360 => _360["apiHost"]]));
8307
+ const apiHost = configString(_optionalChain([raw, 'optionalAccess', _396 => _396["apiHost"]]));
7982
8308
  if (!apiHost) return void 0;
7983
- const basicAuthUsername = configString(_optionalChain([raw, 'optionalAccess', _361 => _361["basicAuthUsername"]]));
7984
- const basicAuthPassword = configString(_optionalChain([raw, 'optionalAccess', _362 => _362["basicAuthPassword"]]));
8309
+ const basicAuthUsername = configString(_optionalChain([raw, 'optionalAccess', _397 => _397["basicAuthUsername"]]));
8310
+ const basicAuthPassword = configString(_optionalChain([raw, 'optionalAccess', _398 => _398["basicAuthPassword"]]));
7985
8311
  return {
7986
8312
  apiHost,
7987
8313
  ...basicAuthUsername ? { basicAuthUsername } : {},
@@ -7990,9 +8316,9 @@ function searxngConfig(value) {
7990
8316
  }
7991
8317
  function zhipuConfig(value) {
7992
8318
  const raw = record4(value);
7993
- const apiKey = configString(_optionalChain([raw, 'optionalAccess', _363 => _363["apiKey"]]));
8319
+ const apiKey = configString(_optionalChain([raw, 'optionalAccess', _399 => _399["apiKey"]]));
7994
8320
  if (!apiKey) return void 0;
7995
- const apiHost = configString(_optionalChain([raw, 'optionalAccess', _364 => _364["apiHost"]]));
8321
+ const apiHost = configString(_optionalChain([raw, 'optionalAccess', _400 => _400["apiHost"]]));
7996
8322
  return { apiKey, ...apiHost ? { apiHost } : {} };
7997
8323
  }
7998
8324
  function normalizeSearchApiProviderConfigs(value) {
@@ -8144,11 +8470,11 @@ var DEFAULT_ACCOUNT_HEALTH = {
8144
8470
  overloadCooldownMs: 10 * 6e4
8145
8471
  };
8146
8472
  function normalizeAccountHealth(raw) {
8147
- const ah = _optionalChain([raw, 'optionalAccess', _365 => _365.accountHealth]);
8473
+ const ah = _optionalChain([raw, 'optionalAccess', _401 => _401.accountHealth]);
8148
8474
  return {
8149
- overloadCooldownEnabled: _optionalChain([ah, 'optionalAccess', _366 => _366.overloadCooldownEnabled]) !== false,
8475
+ overloadCooldownEnabled: _optionalChain([ah, 'optionalAccess', _402 => _402.overloadCooldownEnabled]) !== false,
8150
8476
  overloadCooldownMs: clampNumber(
8151
- _optionalChain([ah, 'optionalAccess', _367 => _367.overloadCooldownMs]),
8477
+ _optionalChain([ah, 'optionalAccess', _403 => _403.overloadCooldownMs]),
8152
8478
  6e4,
8153
8479
  36e5,
8154
8480
  DEFAULT_ACCOUNT_HEALTH.overloadCooldownMs
@@ -8170,25 +8496,25 @@ var DEFAULT_ALLOWANCE_SCHEDULING = {
8170
8496
  priorityPenalty: 100
8171
8497
  };
8172
8498
  function normalizeAllowanceScheduling(raw) {
8173
- const value = _optionalChain([raw, 'optionalAccess', _368 => _368.allowanceScheduling]);
8499
+ const value = _optionalChain([raw, 'optionalAccess', _404 => _404.allowanceScheduling]);
8174
8500
  const demoteAtPercent = clampNumber(
8175
- _optionalChain([value, 'optionalAccess', _369 => _369.demoteAtPercent]),
8501
+ _optionalChain([value, 'optionalAccess', _405 => _405.demoteAtPercent]),
8176
8502
  0,
8177
8503
  100,
8178
8504
  DEFAULT_ALLOWANCE_SCHEDULING.demoteAtPercent
8179
8505
  );
8180
8506
  const requestedPause = clampNumber(
8181
- _optionalChain([value, 'optionalAccess', _370 => _370.pauseAtPercent]),
8507
+ _optionalChain([value, 'optionalAccess', _406 => _406.pauseAtPercent]),
8182
8508
  0,
8183
8509
  100,
8184
8510
  DEFAULT_ALLOWANCE_SCHEDULING.pauseAtPercent
8185
8511
  );
8186
8512
  return {
8187
- enabled: _optionalChain([value, 'optionalAccess', _371 => _371.enabled]) === true,
8513
+ enabled: _optionalChain([value, 'optionalAccess', _407 => _407.enabled]) === true,
8188
8514
  demoteAtPercent,
8189
8515
  pauseAtPercent: Math.max(demoteAtPercent, requestedPause),
8190
8516
  priorityPenalty: Math.trunc(clampNumber(
8191
- _optionalChain([value, 'optionalAccess', _372 => _372.priorityPenalty]),
8517
+ _optionalChain([value, 'optionalAccess', _408 => _408.priorityPenalty]),
8192
8518
  1,
8193
8519
  1e3,
8194
8520
  DEFAULT_ALLOWANCE_SCHEDULING.priorityPenalty
@@ -8196,29 +8522,29 @@ function normalizeAllowanceScheduling(raw) {
8196
8522
  };
8197
8523
  }
8198
8524
  function normalizeAccountProbe(raw) {
8199
- const ap = _optionalChain([raw, 'optionalAccess', _373 => _373.accountProbe]);
8525
+ const ap = _optionalChain([raw, 'optionalAccess', _409 => _409.accountProbe]);
8200
8526
  return {
8201
- enabled: _optionalChain([ap, 'optionalAccess', _374 => _374.enabled]) === true,
8202
- intervalMs: clampNumber(_optionalChain([ap, 'optionalAccess', _375 => _375.intervalMs]), 6e4, 864e5, DEFAULT_ACCOUNT_PROBE.intervalMs),
8203
- onlyMultiAccount: _optionalChain([ap, 'optionalAccess', _376 => _376.onlyMultiAccount]) !== false,
8204
- timeoutMs: clampNumber(_optionalChain([ap, 'optionalAccess', _377 => _377.timeoutMs]), 1e3, 6e4, DEFAULT_ACCOUNT_PROBE.timeoutMs),
8527
+ enabled: _optionalChain([ap, 'optionalAccess', _410 => _410.enabled]) === true,
8528
+ intervalMs: clampNumber(_optionalChain([ap, 'optionalAccess', _411 => _411.intervalMs]), 6e4, 864e5, DEFAULT_ACCOUNT_PROBE.intervalMs),
8529
+ onlyMultiAccount: _optionalChain([ap, 'optionalAccess', _412 => _412.onlyMultiAccount]) !== false,
8530
+ timeoutMs: clampNumber(_optionalChain([ap, 'optionalAccess', _413 => _413.timeoutMs]), 1e3, 6e4, DEFAULT_ACCOUNT_PROBE.timeoutMs),
8205
8531
  historySize: Math.trunc(
8206
- clampNumber(_optionalChain([ap, 'optionalAccess', _378 => _378.historySize]), 1, 200, DEFAULT_ACCOUNT_PROBE.historySize)
8532
+ clampNumber(_optionalChain([ap, 'optionalAccess', _414 => _414.historySize]), 1, 200, DEFAULT_ACCOUNT_PROBE.historySize)
8207
8533
  ),
8208
- staggerMs: clampNumber(_optionalChain([ap, 'optionalAccess', _379 => _379.staggerMs]), 0, 6e4, DEFAULT_ACCOUNT_PROBE.staggerMs)
8534
+ staggerMs: clampNumber(_optionalChain([ap, 'optionalAccess', _415 => _415.staggerMs]), 0, 6e4, DEFAULT_ACCOUNT_PROBE.staggerMs)
8209
8535
  };
8210
8536
  }
8211
8537
  function normalizeAudit(raw) {
8212
- const a = _optionalChain([raw, 'optionalAccess', _380 => _380.audit]);
8538
+ const a = _optionalChain([raw, 'optionalAccess', _416 => _416.audit]);
8213
8539
  return {
8214
- enabled: _optionalChain([a, 'optionalAccess', _381 => _381.enabled]) === true,
8215
- captureBodies: _optionalChain([a, 'optionalAccess', _382 => _382.captureBodies]) === true,
8216
- maxBodyBytes: normalizeMaxBodyBytes(_optionalChain([a, 'optionalAccess', _383 => _383.maxBodyBytes])),
8540
+ enabled: _optionalChain([a, 'optionalAccess', _417 => _417.enabled]) === true,
8541
+ captureBodies: _optionalChain([a, 'optionalAccess', _418 => _418.captureBodies]) === true,
8542
+ maxBodyBytes: normalizeMaxBodyBytes(_optionalChain([a, 'optionalAccess', _419 => _419.maxBodyBytes])),
8217
8543
  retentionDays: Math.trunc(
8218
- clampNumber(_optionalChain([a, 'optionalAccess', _384 => _384.retentionDays]), 1, 365, _audittypes.DEFAULT_AUDIT_CONFIG.retentionDays)
8544
+ clampNumber(_optionalChain([a, 'optionalAccess', _420 => _420.retentionDays]), 1, 365, _audittypes.DEFAULT_AUDIT_CONFIG.retentionDays)
8219
8545
  ),
8220
- compactStreamingBodies: _optionalChain([a, 'optionalAccess', _385 => _385.compactStreamingBodies]) === true,
8221
- trustForwardedFor: _optionalChain([a, 'optionalAccess', _386 => _386.trustForwardedFor]) === true
8546
+ compactStreamingBodies: _optionalChain([a, 'optionalAccess', _421 => _421.compactStreamingBodies]) === true,
8547
+ trustForwardedFor: _optionalChain([a, 'optionalAccess', _422 => _422.trustForwardedFor]) === true
8222
8548
  };
8223
8549
  }
8224
8550
  function normalizeMaxBodyBytes(value) {
@@ -8229,26 +8555,26 @@ function normalizeMaxBodyBytes(value) {
8229
8555
  return Math.trunc(Math.min(1048576, value));
8230
8556
  }
8231
8557
  function normalizeBilling(raw) {
8232
- const b = _optionalChain([raw, 'optionalAccess', _387 => _387.billing]);
8558
+ const b = _optionalChain([raw, 'optionalAccess', _423 => _423.billing]);
8233
8559
  const config = {
8234
- enabled: _optionalChain([b, 'optionalAccess', _388 => _388.enabled]) === true,
8560
+ enabled: _optionalChain([b, 'optionalAccess', _424 => _424.enabled]) === true,
8235
8561
  maxRetryAgeMs: Math.trunc(
8236
- clampNumber(_optionalChain([b, 'optionalAccess', _389 => _389.maxRetryAgeMs]), 6e4, 2592e6, _billingtypes.DEFAULT_BILLING_CONFIG.maxRetryAgeMs)
8562
+ clampNumber(_optionalChain([b, 'optionalAccess', _425 => _425.maxRetryAgeMs]), 6e4, 2592e6, _billingtypes.DEFAULT_BILLING_CONFIG.maxRetryAgeMs)
8237
8563
  )
8238
8564
  };
8239
- if (typeof _optionalChain([b, 'optionalAccess', _390 => _390.endpoint]) === "string" && b.endpoint.trim()) config.endpoint = b.endpoint.trim();
8240
- if (typeof _optionalChain([b, 'optionalAccess', _391 => _391.secret]) === "string" && b.secret.length > 0) config.secret = b.secret;
8565
+ if (typeof _optionalChain([b, 'optionalAccess', _426 => _426.endpoint]) === "string" && b.endpoint.trim()) config.endpoint = b.endpoint.trim();
8566
+ if (typeof _optionalChain([b, 'optionalAccess', _427 => _427.secret]) === "string" && b.secret.length > 0) config.secret = b.secret;
8241
8567
  return config;
8242
8568
  }
8243
8569
  var DEFAULT_FINGERPRINT = { enabled: false };
8244
8570
  function normalizeFingerprint(raw) {
8245
- const f = _optionalChain([raw, 'optionalAccess', _392 => _392.fingerprint]);
8246
- const out = { enabled: _optionalChain([f, 'optionalAccess', _393 => _393.enabled]) === true };
8247
- if (typeof _optionalChain([f, 'optionalAccess', _394 => _394.ua]) === "string" && f.ua.trim().length > 0) out.ua = f.ua.trim();
8571
+ const f = _optionalChain([raw, 'optionalAccess', _428 => _428.fingerprint]);
8572
+ const out = { enabled: _optionalChain([f, 'optionalAccess', _429 => _429.enabled]) === true };
8573
+ if (typeof _optionalChain([f, 'optionalAccess', _430 => _430.ua]) === "string" && f.ua.trim().length > 0) out.ua = f.ua.trim();
8248
8574
  return out;
8249
8575
  }
8250
8576
  function normalizeVoucher(raw) {
8251
- return { enabled: _optionalChain([raw, 'optionalAccess', _395 => _395.voucher, 'optionalAccess', _396 => _396.enabled]) === true };
8577
+ return { enabled: _optionalChain([raw, 'optionalAccess', _431 => _431.voucher, 'optionalAccess', _432 => _432.enabled]) === true };
8252
8578
  }
8253
8579
  var DEFAULT_ANTHROPIC_SEGMENT = {
8254
8580
  countTokens: { mode: "auto", estimateBudgetMs: 2e3 },
@@ -8261,34 +8587,34 @@ var DEFAULT_ANTHROPIC_SEGMENT = {
8261
8587
  var COUNT_TOKENS_MODES = ["auto", "passthrough", "estimate", "reject"];
8262
8588
  var MODELS_SHAPES = ["auto", "anthropic", "openai"];
8263
8589
  function normalizeAnthropicSegment(raw) {
8264
- const a = _optionalChain([raw, 'optionalAccess', _397 => _397.anthropic]);
8590
+ const a = _optionalChain([raw, 'optionalAccess', _433 => _433.anthropic]);
8265
8591
  return {
8266
8592
  countTokens: {
8267
- mode: COUNT_TOKENS_MODES.includes(String(_optionalChain([a, 'optionalAccess', _398 => _398.countTokens, 'optionalAccess', _399 => _399.mode]))) ? _optionalChain([a, 'optionalAccess', _400 => _400.countTokens, 'optionalAccess', _401 => _401.mode]) : DEFAULT_ANTHROPIC_SEGMENT.countTokens.mode,
8593
+ mode: COUNT_TOKENS_MODES.includes(String(_optionalChain([a, 'optionalAccess', _434 => _434.countTokens, 'optionalAccess', _435 => _435.mode]))) ? _optionalChain([a, 'optionalAccess', _436 => _436.countTokens, 'optionalAccess', _437 => _437.mode]) : DEFAULT_ANTHROPIC_SEGMENT.countTokens.mode,
8268
8594
  estimateBudgetMs: clampNumber(
8269
- _optionalChain([a, 'optionalAccess', _402 => _402.countTokens, 'optionalAccess', _403 => _403.estimateBudgetMs]),
8595
+ _optionalChain([a, 'optionalAccess', _438 => _438.countTokens, 'optionalAccess', _439 => _439.estimateBudgetMs]),
8270
8596
  100,
8271
8597
  6e4,
8272
8598
  DEFAULT_ANTHROPIC_SEGMENT.countTokens.estimateBudgetMs
8273
8599
  )
8274
8600
  },
8275
- modelsShape: MODELS_SHAPES.includes(String(_optionalChain([a, 'optionalAccess', _404 => _404.modelsShape]))) ? _optionalChain([a, 'optionalAccess', _405 => _405.modelsShape]) : DEFAULT_ANTHROPIC_SEGMENT.modelsShape,
8601
+ modelsShape: MODELS_SHAPES.includes(String(_optionalChain([a, 'optionalAccess', _440 => _440.modelsShape]))) ? _optionalChain([a, 'optionalAccess', _441 => _441.modelsShape]) : DEFAULT_ANTHROPIC_SEGMENT.modelsShape,
8276
8602
  heartbeatIntervalMs: clampNumber(
8277
- _optionalChain([a, 'optionalAccess', _406 => _406.heartbeatIntervalMs]),
8603
+ _optionalChain([a, 'optionalAccess', _442 => _442.heartbeatIntervalMs]),
8278
8604
  0,
8279
8605
  6e5,
8280
8606
  DEFAULT_ANTHROPIC_SEGMENT.heartbeatIntervalMs
8281
8607
  ),
8282
8608
  pdfTextExtraction: {
8283
8609
  budgetMs: clampNumber(
8284
- _optionalChain([a, 'optionalAccess', _407 => _407.pdfTextExtraction, 'optionalAccess', _408 => _408.budgetMs]),
8610
+ _optionalChain([a, 'optionalAccess', _443 => _443.pdfTextExtraction, 'optionalAccess', _444 => _444.budgetMs]),
8285
8611
  100,
8286
8612
  6e4,
8287
8613
  DEFAULT_ANTHROPIC_SEGMENT.pdfTextExtraction.budgetMs
8288
8614
  )
8289
8615
  },
8290
- proxyOauthUsage: _optionalChain([a, 'optionalAccess', _409 => _409.proxyOauthUsage]) === true,
8291
- apiHello: _optionalChain([a, 'optionalAccess', _410 => _410.apiHello]) !== false
8616
+ proxyOauthUsage: _optionalChain([a, 'optionalAccess', _445 => _445.proxyOauthUsage]) === true,
8617
+ apiHello: _optionalChain([a, 'optionalAccess', _446 => _446.apiHello]) !== false
8292
8618
  };
8293
8619
  }
8294
8620
  var PROXY_TYPES = ["http", "https", "socks5"];
@@ -8373,14 +8699,14 @@ function clampNumber(value, min, max, fallback) {
8373
8699
  return Math.min(max, Math.max(min, n));
8374
8700
  }
8375
8701
  function normalizeQueueSegments(raw) {
8376
- const umq = _optionalChain([raw, 'optionalAccess', _411 => _411.userMessageQueue]);
8377
- const cq = _optionalChain([raw, 'optionalAccess', _412 => _412.concurrencyQueue]);
8702
+ const umq = _optionalChain([raw, 'optionalAccess', _447 => _447.userMessageQueue]);
8703
+ const cq = _optionalChain([raw, 'optionalAccess', _448 => _448.concurrencyQueue]);
8378
8704
  return {
8379
8705
  userMessageQueue: {
8380
- enabled: _optionalChain([umq, 'optionalAccess', _413 => _413.enabled]) === true,
8381
- delayMs: clampNumber(_optionalChain([umq, 'optionalAccess', _414 => _414.delayMs]), 0, 1e4, DEFAULT_USER_MESSAGE_QUEUE.delayMs),
8706
+ enabled: _optionalChain([umq, 'optionalAccess', _449 => _449.enabled]) === true,
8707
+ delayMs: clampNumber(_optionalChain([umq, 'optionalAccess', _450 => _450.delayMs]), 0, 1e4, DEFAULT_USER_MESSAGE_QUEUE.delayMs),
8382
8708
  waitTimeoutMs: clampNumber(
8383
- _optionalChain([umq, 'optionalAccess', _415 => _415.waitTimeoutMs]),
8709
+ _optionalChain([umq, 'optionalAccess', _451 => _451.waitTimeoutMs]),
8384
8710
  1e3,
8385
8711
  3e5,
8386
8712
  DEFAULT_USER_MESSAGE_QUEUE.waitTimeoutMs
@@ -8388,14 +8714,14 @@ function normalizeQueueSegments(raw) {
8388
8714
  },
8389
8715
  concurrencyQueue: {
8390
8716
  maxQueueSizeFactor: clampNumber(
8391
- _optionalChain([cq, 'optionalAccess', _416 => _416.maxQueueSizeFactor]),
8717
+ _optionalChain([cq, 'optionalAccess', _452 => _452.maxQueueSizeFactor]),
8392
8718
  1,
8393
8719
  10,
8394
8720
  DEFAULT_CONCURRENCY_QUEUE.maxQueueSizeFactor
8395
8721
  ),
8396
- minQueueSize: clampNumber(_optionalChain([cq, 'optionalAccess', _417 => _417.minQueueSize]), 1, 100, DEFAULT_CONCURRENCY_QUEUE.minQueueSize),
8722
+ minQueueSize: clampNumber(_optionalChain([cq, 'optionalAccess', _453 => _453.minQueueSize]), 1, 100, DEFAULT_CONCURRENCY_QUEUE.minQueueSize),
8397
8723
  waitTimeoutMs: clampNumber(
8398
- _optionalChain([cq, 'optionalAccess', _418 => _418.waitTimeoutMs]),
8724
+ _optionalChain([cq, 'optionalAccess', _454 => _454.waitTimeoutMs]),
8399
8725
  1e3,
8400
8726
  3e5,
8401
8727
  DEFAULT_CONCURRENCY_QUEUE.waitTimeoutMs
@@ -8406,11 +8732,11 @@ function normalizeQueueSegments(raw) {
8406
8732
  var ALL_ENDPOINTS = ["chat", "responses", "messages", "gemini"];
8407
8733
  function blankModelMap(endpoint) {
8408
8734
  const modelMap = {};
8409
- for (const kind of _chunk57Y2EA2Gcjs.modelKindsForEndpoint.call(void 0, endpoint)) modelMap[kind] = "";
8735
+ for (const kind of _chunkJGRNVH7Ccjs.modelKindsForEndpoint.call(void 0, endpoint)) modelMap[kind] = "";
8410
8736
  return modelMap;
8411
8737
  }
8412
8738
  function defaultEndpointConfig(endpoint) {
8413
- if (_chunk57Y2EA2Gcjs.isKindMappedEndpoint.call(void 0, endpoint)) {
8739
+ if (_chunkJGRNVH7Ccjs.isKindMappedEndpoint.call(void 0, endpoint)) {
8414
8740
  return { endpoint, modelMap: blankModelMap(endpoint), useSubscription: false };
8415
8741
  }
8416
8742
  if (endpoint === "chat") {
@@ -8440,10 +8766,10 @@ function normalizeEndpointConfig(e) {
8440
8766
  const boundAccountFallbackPolicy = boundAccountId ? e.boundAccountFallbackPolicy === "pool" ? "pool" : "strict" : void 0;
8441
8767
  const boundKeyId = typeof e.boundKeyId === "string" && e.boundKeyId.trim() !== "" ? e.boundKeyId : void 0;
8442
8768
  let config;
8443
- if (_chunk57Y2EA2Gcjs.isKindMappedEndpoint.call(void 0, endpoint)) {
8769
+ if (_chunkJGRNVH7Ccjs.isKindMappedEndpoint.call(void 0, endpoint)) {
8444
8770
  const rawMap = e.modelMap && typeof e.modelMap === "object" ? e.modelMap : {};
8445
8771
  const modelMap = {};
8446
- for (const kind of _chunk57Y2EA2Gcjs.modelKindsForEndpoint.call(void 0, endpoint)) {
8772
+ for (const kind of _chunkJGRNVH7Ccjs.modelKindsForEndpoint.call(void 0, endpoint)) {
8447
8773
  const v = rawMap[kind];
8448
8774
  modelMap[kind] = typeof v === "string" ? v : "";
8449
8775
  }
@@ -8494,6 +8820,7 @@ function normalizeBindingTarget(raw) {
8494
8820
  }
8495
8821
  return null;
8496
8822
  }
8823
+ var MAPPING_EFFORT_MAX_LENGTH = 32;
8497
8824
  function normalizeGatewayModelMappings(raw) {
8498
8825
  if (!Array.isArray(raw)) return [];
8499
8826
  const mappings = [];
@@ -8503,12 +8830,14 @@ function normalizeGatewayModelMappings(raw) {
8503
8830
  const source = typeof value.source === "string" ? value.source.trim() : "";
8504
8831
  const target = typeof value.target === "string" ? value.target.trim() : "";
8505
8832
  if (!source || !target) continue;
8506
- mappings.push({ source, target });
8833
+ const rawEffort = typeof value.effort === "string" ? value.effort.trim() : "";
8834
+ const effort = rawEffort && rawEffort.length <= MAPPING_EFFORT_MAX_LENGTH ? rawEffort : void 0;
8835
+ mappings.push(effort ? { source, target, effort } : { source, target });
8507
8836
  }
8508
8837
  return mappings;
8509
8838
  }
8510
8839
  function hasConfiguredLegacyModels(config) {
8511
- return Object.values(_nullishCoalesce(config.modelMap, () => ( {}))).some((value) => typeof value === "string" && value.trim()) || Boolean(_optionalChain([config, 'access', _419 => _419.models, 'optionalAccess', _420 => _420.some, 'call', _421 => _421((value) => typeof value === "string" && value.trim())])) || Boolean(_optionalChain([config, 'access', _422 => _422.defaultModel, 'optionalAccess', _423 => _423.trim, 'call', _424 => _424()])) || Boolean(_optionalChain([config, 'access', _425 => _425.backgroundModel, 'optionalAccess', _426 => _426.trim, 'call', _427 => _427()])) || Boolean(Object.values(_nullishCoalesce(config.prefixTargets, () => ( {}))).some((value) => _optionalChain([value, 'optionalAccess', _428 => _428.trim, 'call', _429 => _429()])));
8840
+ return Object.values(_nullishCoalesce(config.modelMap, () => ( {}))).some((value) => typeof value === "string" && value.trim()) || Boolean(_optionalChain([config, 'access', _455 => _455.models, 'optionalAccess', _456 => _456.some, 'call', _457 => _457((value) => typeof value === "string" && value.trim())])) || Boolean(_optionalChain([config, 'access', _458 => _458.defaultModel, 'optionalAccess', _459 => _459.trim, 'call', _460 => _460()])) || Boolean(_optionalChain([config, 'access', _461 => _461.backgroundModel, 'optionalAccess', _462 => _462.trim, 'call', _463 => _463()])) || Boolean(Object.values(_nullishCoalesce(config.prefixTargets, () => ( {}))).some((value) => _optionalChain([value, 'optionalAccess', _464 => _464.trim, 'call', _465 => _465()])));
8512
8841
  }
8513
8842
  function splitModelRef(ref) {
8514
8843
  if (typeof ref !== "string") return null;
@@ -8576,7 +8905,7 @@ function legacyEndpointToBindings(config) {
8576
8905
  if (!parsed) continue;
8577
8906
  const route = routeFor(parsed.providerId);
8578
8907
  route[field] = ref;
8579
- if (_optionalChain([config, 'access', _430 => _430.backgroundModelIds, 'optionalAccess', _431 => _431.length])) {
8908
+ if (_optionalChain([config, 'access', _466 => _466.backgroundModelIds, 'optionalAccess', _467 => _467.length])) {
8580
8909
  route.backgroundModelIds = [...config.backgroundModelIds];
8581
8910
  }
8582
8911
  }
@@ -8759,10 +9088,10 @@ function asObject(value) {
8759
9088
  return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
8760
9089
  }
8761
9090
  function anthropicSessionId(body) {
8762
- const userId = _optionalChain([asObject, 'call', _432 => _432(body["metadata"]), 'optionalAccess', _433 => _433["user_id"]]);
9091
+ const userId = _optionalChain([asObject, 'call', _468 => _468(body["metadata"]), 'optionalAccess', _469 => _469["user_id"]]);
8763
9092
  if (typeof userId !== "string" || !userId) return void 0;
8764
9093
  const matched = ANTHROPIC_SESSION_RE.exec(userId);
8765
- return _optionalChain([matched, 'optionalAccess', _434 => _434[1]]);
9094
+ return _optionalChain([matched, 'optionalAccess', _470 => _470[1]]);
8766
9095
  }
8767
9096
  function anthropicContentFingerprint(body) {
8768
9097
  const messages = body["messages"];
@@ -8795,6 +9124,61 @@ function deriveAuditSessionKey(body, headers = {}, options = {}) {
8795
9124
  return gateway.key;
8796
9125
  }
8797
9126
 
9127
+ // src/outbound-api/mappingEffortInjection.ts
9128
+ function isPlainObject(value) {
9129
+ return !!value && typeof value === "object" && !Array.isArray(value);
9130
+ }
9131
+ function hasOpenAiWireReasoningIntent(body) {
9132
+ return _chunkIUL4VWNUcjs.extractReasoningIntent.call(void 0, {
9133
+ model: typeof body["model"] === "string" ? body["model"] : "",
9134
+ reasoning: isPlainObject(body["reasoning"]) ? body["reasoning"] : void 0,
9135
+ reasoning_effort: body["reasoning_effort"]
9136
+ }) !== void 0;
9137
+ }
9138
+ function injectMappingEffortDefault(endpoint, effort, body) {
9139
+ if (!effort) return false;
9140
+ switch (endpoint) {
9141
+ case "chat":
9142
+ if (hasOpenAiWireReasoningIntent(body)) {
9143
+ return false;
9144
+ }
9145
+ body["reasoning_effort"] = effort;
9146
+ return true;
9147
+ case "responses": {
9148
+ if (hasOpenAiWireReasoningIntent(body)) {
9149
+ return false;
9150
+ }
9151
+ const reasoning = body["reasoning"];
9152
+ body["reasoning"] = {
9153
+ ...isPlainObject(reasoning) ? reasoning : {},
9154
+ effort
9155
+ };
9156
+ return true;
9157
+ }
9158
+ case "messages": {
9159
+ if (body["thinking"] !== void 0) return false;
9160
+ if (effort === "none") return false;
9161
+ body["thinking"] = { type: "adaptive" };
9162
+ const outputConfig = body["output_config"];
9163
+ body["output_config"] = {
9164
+ ...isPlainObject(outputConfig) ? outputConfig : {},
9165
+ effort
9166
+ };
9167
+ return true;
9168
+ }
9169
+ case "gemini": {
9170
+ const generationConfig = body["generationConfig"];
9171
+ const config = isPlainObject(generationConfig) ? generationConfig : {};
9172
+ if (config["thinkingConfig"] !== void 0) return false;
9173
+ body["generationConfig"] = {
9174
+ ...config,
9175
+ thinkingConfig: { thinkingLevel: effort }
9176
+ };
9177
+ return true;
9178
+ }
9179
+ }
9180
+ }
9181
+
8798
9182
  // src/outbound-api/outboundApiKeyAuth.ts
8799
9183
 
8800
9184
 
@@ -8940,7 +9324,7 @@ function effectiveOutboundPermissions(value) {
8940
9324
  if (value === void 0) return LEGACY_OUTBOUND_PERMISSIONS;
8941
9325
  try {
8942
9326
  return validateOutboundPermissions(value);
8943
- } catch (e49) {
9327
+ } catch (e53) {
8944
9328
  return [];
8945
9329
  }
8946
9330
  }
@@ -8981,8 +9365,23 @@ function toVerifiedKey(row) {
8981
9365
  if (rateLimit) key.rateLimit = rateLimit;
8982
9366
  const modelRestriction = extractModelRestriction(row);
8983
9367
  if (modelRestriction) key.modelRestriction = modelRestriction;
9368
+ const directTarget = extractBoundUpstream(row);
9369
+ if (directTarget) key.boundUpstream = directTarget;
8984
9370
  return key;
8985
9371
  }
9372
+ function extractBoundUpstream(row) {
9373
+ if (row.boundUpstream && typeof row.boundUpstream === "object") {
9374
+ const target = row.boundUpstream;
9375
+ if (target.kind === "provider" && typeof target.providerId === "string" && target.providerId || target.kind === "account-pool" && typeof target.providerId === "string" && target.providerId || target.kind === "account" && target.providerId && target.accountId || target.kind === "account-group" && target.providerId && target.group) {
9376
+ return target;
9377
+ }
9378
+ return void 0;
9379
+ }
9380
+ if (typeof row.boundUpstreamProviderId === "string" && row.boundUpstreamProviderId) {
9381
+ return { kind: "provider", providerId: row.boundUpstreamProviderId };
9382
+ }
9383
+ return void 0;
9384
+ }
8986
9385
  async function verifyKey(db, presentedKey, now = Date.now()) {
8987
9386
  if (!presentedKey) return { status: "invalid" };
8988
9387
  const trimmed = presentedKey.trim();
@@ -9191,8 +9590,8 @@ var OutboundRateLimiter = (_class16 = class {
9191
9590
  * recorded (no bucket growth).
9192
9591
  */
9193
9592
  check(apiKeyId, now = Date.now(), override) {
9194
- const maxRequests = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _435 => _435.maxRequests]), () => ( this.maxRequests));
9195
- const windowMs = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _436 => _436.windowMs]), () => ( this.windowMs));
9593
+ const maxRequests = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _471 => _471.maxRequests]), () => ( this.maxRequests));
9594
+ const windowMs = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _472 => _472.windowMs]), () => ( this.windowMs));
9196
9595
  if (maxRequests === 0) return { allowed: true, retryAfterSeconds: 0 };
9197
9596
  const cutoff = now - windowMs;
9198
9597
  const timestamps = (_nullishCoalesce(this.hits.get(apiKeyId), () => ( []))).filter((ts) => ts > cutoff);
@@ -9378,10 +9777,10 @@ async function handleCodexSearchRequest(req, res, deps) {
9378
9777
  let parseFailed = false;
9379
9778
  try {
9380
9779
  parsed = raw ? JSON.parse(raw) : {};
9381
- } catch (e50) {
9780
+ } catch (e54) {
9382
9781
  parseFailed = true;
9383
9782
  }
9384
- _optionalChain([deps, 'access', _437 => _437.onRequestBody, 'optionalCall', _438 => _438(raw, isRecord10(parsed) ? parsed : {})]);
9783
+ _optionalChain([deps, 'access', _473 => _473.onRequestBody, 'optionalCall', _474 => _474(raw, isRecord10(parsed) ? parsed : {})]);
9385
9784
  if (parseFailed) {
9386
9785
  throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({
9387
9786
  status: 400,
@@ -9426,7 +9825,7 @@ function isUserMessageAnthropic(body) {
9426
9825
  if (typeof content === "string") return true;
9427
9826
  if (Array.isArray(content)) {
9428
9827
  const hasToolResult = content.some(
9429
- (block) => _optionalChain([asObject2, 'call', _439 => _439(block), 'optionalAccess', _440 => _440["type"]]) === "tool_result"
9828
+ (block) => _optionalChain([asObject2, 'call', _475 => _475(block), 'optionalAccess', _476 => _476["type"]]) === "tool_result"
9430
9829
  );
9431
9830
  return !hasToolResult;
9432
9831
  }
@@ -9455,7 +9854,7 @@ function isUserMessageGemini(body) {
9455
9854
  if (!lastContent || lastContent["role"] !== "user") return false;
9456
9855
  const parts = asArray(lastContent["parts"]);
9457
9856
  const hasFunctionResponse = parts.some(
9458
- (part) => _optionalChain([asObject2, 'call', _441 => _441(part), 'optionalAccess', _442 => _442["functionResponse"]]) !== void 0
9857
+ (part) => _optionalChain([asObject2, 'call', _477 => _477(part), 'optionalAccess', _478 => _478["functionResponse"]]) !== void 0
9459
9858
  );
9460
9859
  return !hasFunctionResponse;
9461
9860
  }
@@ -9629,14 +10028,14 @@ function newVoucherId() {
9629
10028
  }
9630
10029
  function computeVoucherGrant(voucher, currentKey, now) {
9631
10030
  if (voucher.type === "credit") {
9632
- const current = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _443 => _443.totalCostLimitUsd]), () => ( 0));
10031
+ const current = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _479 => _479.totalCostLimitUsd]), () => ( 0));
9633
10032
  let granted2 = current + (_nullishCoalesce(voucher.creditUsd, () => ( 0)));
9634
10033
  if (voucher.maxTotalCostLimitUsd != null) {
9635
10034
  granted2 = Math.min(granted2, voucher.maxTotalCostLimitUsd);
9636
10035
  }
9637
10036
  return { totalCostLimitUsd: granted2 };
9638
10037
  }
9639
- const currentExpiry = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _444 => _444.expiresAt]), () => ( now));
10038
+ const currentExpiry = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _480 => _480.expiresAt]), () => ( now));
9640
10039
  let granted = currentExpiry + (_nullishCoalesce(voucher.renewalDays, () => ( 0))) * DAY_MS2;
9641
10040
  if (voucher.maxExpiryDays != null) {
9642
10041
  granted = Math.min(granted, now + voucher.maxExpiryDays * DAY_MS2);
@@ -9667,7 +10066,7 @@ function toVoucherInfo(v) {
9667
10066
  // src/outbound-api/voucherRedeem.ts
9668
10067
  function isRedeemRequest(method, url) {
9669
10068
  if (method !== "POST" || !url) return false;
9670
- const path = _nullishCoalesce(_optionalChain([url, 'access', _445 => _445.split, 'call', _446 => _446("?"), 'access', _447 => _447[0], 'optionalAccess', _448 => _448.replace, 'call', _449 => _449(/\/+$/, "")]), () => ( ""));
10069
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _481 => _481.split, 'call', _482 => _482("?"), 'access', _483 => _483[0], 'optionalAccess', _484 => _484.replace, 'call', _485 => _485(/\/+$/, "")]), () => ( ""));
9671
10070
  return path.endsWith("/redeem");
9672
10071
  }
9673
10072
  function writeErr(res, status, message, headers = {}) {
@@ -9697,8 +10096,8 @@ function grantToResult(type, granted) {
9697
10096
  function currentResult(type, keyRow) {
9698
10097
  const result = { type };
9699
10098
  if (type === "credit") {
9700
- if (_optionalChain([keyRow, 'optionalAccess', _450 => _450.totalCostLimitUsd]) != null) result.totalCostLimitUsd = keyRow.totalCostLimitUsd;
9701
- } else if (_optionalChain([keyRow, 'optionalAccess', _451 => _451.expiresAt]) != null) {
10099
+ if (_optionalChain([keyRow, 'optionalAccess', _486 => _486.totalCostLimitUsd]) != null) result.totalCostLimitUsd = keyRow.totalCostLimitUsd;
10100
+ } else if (_optionalChain([keyRow, 'optionalAccess', _487 => _487.expiresAt]) != null) {
9702
10101
  result.expiresAt = keyRow.expiresAt;
9703
10102
  }
9704
10103
  return result;
@@ -9736,7 +10135,7 @@ async function handleVoucherRedeem(req, res, deps, voucherEnabled, redeemLimiter
9736
10135
  let code;
9737
10136
  try {
9738
10137
  code = raw ? JSON.parse(raw)["code"] : void 0;
9739
- } catch (e51) {
10138
+ } catch (e55) {
9740
10139
  writeErr(res, 400, "Invalid JSON in request body");
9741
10140
  return;
9742
10141
  }
@@ -9785,7 +10184,7 @@ async function handleVoucherRedeem(req, res, deps, voucherEnabled, redeemLimiter
9785
10184
  const won = await voucherDb.voucherRedeemCas(voucher.id, verifiedKeyId, absolute, now);
9786
10185
  if (!won) {
9787
10186
  const after = await voucherDb.voucherGetByHash(codeHash);
9788
- if (_optionalChain([after, 'optionalAccess', _452 => _452.status]) === "redeemed" && after.redeemedByKeyId === verifiedKeyId) {
10187
+ if (_optionalChain([after, 'optionalAccess', _488 => _488.status]) === "redeemed" && after.redeemedByKeyId === verifiedKeyId) {
9789
10188
  return after.grantApplied === true ? { ok: true, result: currentResult(after.type, await deps.db.outboundApiKeysGetByHash(keyHash)) } : await applyFirstPass(after, recordedAbsolute(after));
9790
10189
  }
9791
10190
  return { ok: false, status: 409, message: "Code was already redeemed" };
@@ -9860,10 +10259,10 @@ function extractPresentedKey(req) {
9860
10259
  }
9861
10260
  const xApiKey = req.headers["x-api-key"];
9862
10261
  const xApi = Array.isArray(xApiKey) ? xApiKey[0] : xApiKey;
9863
- if (_optionalChain([xApi, 'optionalAccess', _453 => _453.trim, 'call', _454 => _454()])) return xApi.trim();
10262
+ if (_optionalChain([xApi, 'optionalAccess', _489 => _489.trim, 'call', _490 => _490()])) return xApi.trim();
9864
10263
  const goog = req.headers["x-goog-api-key"];
9865
10264
  const g = Array.isArray(goog) ? goog[0] : goog;
9866
- return _optionalChain([g, 'optionalAccess', _455 => _455.trim, 'call', _456 => _456()]) || void 0;
10265
+ return _optionalChain([g, 'optionalAccess', _491 => _491.trim, 'call', _492 => _492()]) || void 0;
9867
10266
  }
9868
10267
  function isLoopbackPeer(address) {
9869
10268
  if (!address) return false;
@@ -9873,10 +10272,10 @@ function isLoopbackPeer(address) {
9873
10272
  function selectEndpoint(method, url) {
9874
10273
  if (method !== "POST" || !url) return null;
9875
10274
  const openAIOperation = _chunkG4CZIUIBcjs.classifyOpenAIOperation.call(void 0, method, url);
9876
- if (_optionalChain([openAIOperation, 'optionalAccess', _457 => _457.policyFamily]) === "chat" || _optionalChain([openAIOperation, 'optionalAccess', _458 => _458.policyFamily]) === "responses") {
10275
+ if (_optionalChain([openAIOperation, 'optionalAccess', _493 => _493.policyFamily]) === "chat" || _optionalChain([openAIOperation, 'optionalAccess', _494 => _494.policyFamily]) === "responses") {
9877
10276
  return openAIOperation.policyFamily;
9878
10277
  }
9879
- const path = _nullishCoalesce(_optionalChain([url, 'access', _459 => _459.split, 'call', _460 => _460("?"), 'access', _461 => _461[0], 'optionalAccess', _462 => _462.replace, 'call', _463 => _463(/\/+$/, "")]), () => ( ""));
10278
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _495 => _495.split, 'call', _496 => _496("?"), 'access', _497 => _497[0], 'optionalAccess', _498 => _498.replace, 'call', _499 => _499(/\/+$/, "")]), () => ( ""));
9880
10279
  const classified = classifyAnthropicMessagesPath(url);
9881
10280
  if (classified === "messages" || classified === "count_tokens") return "messages";
9882
10281
  const lastSeg = _nullishCoalesce(path.split("/").pop(), () => ( ""));
@@ -9893,32 +10292,126 @@ function extractGeminiModelFromUrl(url) {
9893
10292
  }
9894
10293
  function isModelsListRequest(url) {
9895
10294
  if (!url) return false;
9896
- const path = _nullishCoalesce(_optionalChain([url, 'access', _464 => _464.split, 'call', _465 => _465("?"), 'access', _466 => _466[0], 'optionalAccess', _467 => _467.replace, 'call', _468 => _468(/\/+$/, "")]), () => ( ""));
10295
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _500 => _500.split, 'call', _501 => _501("?"), 'access', _502 => _502[0], 'optionalAccess', _503 => _503.replace, 'call', _504 => _504(/\/+$/, "")]), () => ( ""));
9897
10296
  return path.endsWith("/models");
9898
10297
  }
9899
10298
  function isAnthropicOauthUsagePath(url) {
9900
10299
  if (!url) return false;
9901
- const path = _nullishCoalesce(_optionalChain([url, 'access', _469 => _469.split, 'call', _470 => _470("?"), 'access', _471 => _471[0], 'optionalAccess', _472 => _472.replace, 'call', _473 => _473(/\/+$/, "")]), () => ( ""));
10300
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _505 => _505.split, 'call', _506 => _506("?"), 'access', _507 => _507[0], 'optionalAccess', _508 => _508.replace, 'call', _509 => _509(/\/+$/, "")]), () => ( ""));
9902
10301
  return path === "/api/oauth/usage";
9903
10302
  }
9904
10303
  function resolveModelsShape(modelsShape, allowedEndpoints) {
9905
10304
  if (modelsShape === "anthropic") return "anthropic";
9906
10305
  if (modelsShape === "openai") return "openai";
9907
- if (_optionalChain([allowedEndpoints, 'optionalAccess', _474 => _474.includes, 'call', _475 => _475("images")])) return "openai";
10306
+ if (_optionalChain([allowedEndpoints, 'optionalAccess', _510 => _510.includes, 'call', _511 => _511("images")])) return "openai";
9908
10307
  if (!allowedEndpoints || allowedEndpoints.length === 0) return "anthropic";
9909
10308
  return allowedEndpoints.includes("messages") ? "anthropic" : "openai";
9910
10309
  }
10310
+ var UPSTREAM_MODELS_TTL_MS = 6e4;
10311
+ var UPSTREAM_MODELS_NEGATIVE_TTL_MS = 5e3;
10312
+ var UPSTREAM_MODELS_TIMEOUT_MS = 1e4;
10313
+ var upstreamModelsCache = /* @__PURE__ */ new Map();
10314
+ var upstreamModelsInFlight = /* @__PURE__ */ new Map();
10315
+ function resolveProviderKeyLiteral(apiKey) {
10316
+ if (!apiKey) return "";
10317
+ if (apiKey.startsWith("$")) return process.env[apiKey.slice(1)] || "";
10318
+ return apiKey;
10319
+ }
10320
+ function buildProviderModelsUrl(baseUrl, format) {
10321
+ const base = baseUrl.trim().replace(/\/+$/, "");
10322
+ if (!base) return null;
10323
+ if (format === "google") {
10324
+ return /\/models$/.test(base) ? base : `${base}/models`;
10325
+ }
10326
+ if (format === "anthropic") {
10327
+ if (base.endsWith("/messages")) return `${base.slice(0, -"/messages".length)}/models`;
10328
+ if (/\/v\d+$/.test(base)) return `${base}/models`;
10329
+ return `${base}/v1/models`;
10330
+ }
10331
+ const completionSuffix = format === "openai-response" ? "/responses" : "/chat/completions";
10332
+ const root = base.endsWith(completionSuffix) ? base.slice(0, -completionSuffix.length) : base;
10333
+ if (root !== base || /\/v\d+$/.test(base)) return `${root}/models`;
10334
+ return `${base}/v1/models`;
10335
+ }
10336
+ async function fetchUpstreamModelsUncached(provider) {
10337
+ const format = _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider);
10338
+ const url = buildProviderModelsUrl(_nullishCoalesce(provider.api_base_url, () => ( "")), format);
10339
+ if (!url) return [];
10340
+ const headers = _chunkTX4UCSOPcjs.getProviderHeaders.call(void 0, provider, resolveProviderKeyLiteral(provider.api_key));
10341
+ delete headers["Content-Type"];
10342
+ headers["Accept"] = "application/json";
10343
+ const response = await _chunkCXRJMNJJcjs.fetchUpstream.call(void 0,
10344
+ url,
10345
+ { method: "GET", headers, signal: AbortSignal.timeout(UPSTREAM_MODELS_TIMEOUT_MS) },
10346
+ { providerId: "byo" }
10347
+ );
10348
+ if (!response.ok) return [];
10349
+ const body = await response.json();
10350
+ const fromData = Array.isArray(_optionalChain([body, 'optionalAccess', _512 => _512.data])) ? body.data.map((entry) => typeof _optionalChain([entry, 'optionalAccess', _513 => _513.id]) === "string" ? entry.id.trim() : "").filter((id) => id !== "") : [];
10351
+ if (fromData.length > 0) return fromData;
10352
+ return Array.isArray(_optionalChain([body, 'optionalAccess', _514 => _514.models])) ? body.models.map(
10353
+ (entry) => typeof _optionalChain([entry, 'optionalAccess', _515 => _515.name]) === "string" ? entry.name.replace(/^models\//, "").trim() : ""
10354
+ ).filter((id) => id !== "") : [];
10355
+ }
10356
+ async function discoverUpstreamModels(provider) {
10357
+ const cached = upstreamModelsCache.get(provider.id);
10358
+ if (cached) {
10359
+ const ttl = cached.ok ? UPSTREAM_MODELS_TTL_MS : UPSTREAM_MODELS_NEGATIVE_TTL_MS;
10360
+ if (Date.now() - cached.at < ttl) return cached.ids;
10361
+ upstreamModelsCache.delete(provider.id);
10362
+ }
10363
+ const existing = upstreamModelsInFlight.get(provider.id);
10364
+ if (existing) return existing;
10365
+ const pending = (async () => {
10366
+ let ids = [];
10367
+ try {
10368
+ ids = await fetchUpstreamModelsUncached(provider);
10369
+ } catch (e56) {
10370
+ ids = [];
10371
+ }
10372
+ upstreamModelsCache.set(provider.id, { at: Date.now(), ids, ok: ids.length > 0 });
10373
+ return ids;
10374
+ })();
10375
+ upstreamModelsInFlight.set(provider.id, pending);
10376
+ try {
10377
+ return await pending;
10378
+ } finally {
10379
+ upstreamModelsInFlight.delete(provider.id);
10380
+ }
10381
+ }
10382
+ async function passthroughProviderModelIds(llmConfig, providerId) {
10383
+ const provider = await llmConfig.getProvider(providerId);
10384
+ if (!provider) return [];
10385
+ const configured = _nullishCoalesce(provider.models, () => ( []));
10386
+ return configured.length > 0 ? configured : await discoverUpstreamModels(provider);
10387
+ }
9911
10388
  var ANTHROPIC_MODELS_CREATED_AT = (/* @__PURE__ */ new Date()).toISOString();
10389
+ function hasWildcardMapping(binding) {
10390
+ return (_nullishCoalesce(binding.modelMappings, () => ( []))).some(
10391
+ (mapping) => mapping.source.includes("*") && mapping.target.trim() !== ""
10392
+ );
10393
+ }
10394
+ async function pushTargetCatalog(llmConfig, target, push) {
10395
+ if (target.kind === "provider") {
10396
+ for (const id of await passthroughProviderModelIds(llmConfig, target.providerId)) {
10397
+ push(id);
10398
+ }
10399
+ } else if (Object.prototype.hasOwnProperty.call(_subscriptionmodelcatalog.SUBSCRIPTION_MODEL_CATALOG, target.providerId)) {
10400
+ for (const id of _subscriptionmodelcatalog.SUBSCRIPTION_MODEL_CATALOG[target.providerId]) {
10401
+ push(id);
10402
+ }
10403
+ }
10404
+ }
10405
+ var MODEL_LIST_ENDPOINTS = ["chat", "responses", "messages", "gemini"];
9912
10406
  function parseModelsLimit(url) {
9913
- const query = _optionalChain([url, 'optionalAccess', _476 => _476.split, 'call', _477 => _477("?"), 'access', _478 => _478[1]]);
10407
+ const query = _optionalChain([url, 'optionalAccess', _516 => _516.split, 'call', _517 => _517("?"), 'access', _518 => _518[1]]);
9914
10408
  if (!query) return void 0;
9915
10409
  const raw = new URLSearchParams(query).get("limit");
9916
10410
  if (raw === null) return void 0;
9917
10411
  const n = Number.parseInt(raw, 10);
9918
10412
  return Number.isFinite(n) && n > 0 ? n : void 0;
9919
10413
  }
9920
- async function writeModelsListAnthropic(res, llmConfig, config, apiKeyId, allowedEndpoints, limit) {
9921
- void allowedEndpoints;
10414
+ async function writeModelsListAnthropic(res, llmConfig, config, apiKeyId, allowedEndpoints, limit, directTarget) {
9922
10415
  const entries2 = [];
9923
10416
  const seen = /* @__PURE__ */ new Set();
9924
10417
  const push = (id, displayName) => {
@@ -9929,32 +10422,40 @@ async function writeModelsListAnthropic(res, llmConfig, config, apiKeyId, allowe
9929
10422
  );
9930
10423
  };
9931
10424
  const viaLabel = (name, ref) => {
9932
- const modelId = ref ? _optionalChain([_chunk57Y2EA2Gcjs.parseModelRef.call(void 0, ref), 'optionalAccess', _479 => _479.modelId]) : void 0;
10425
+ const modelId = ref ? _optionalChain([_chunkJGRNVH7Ccjs.parseModelRef.call(void 0, ref), 'optionalAccess', _519 => _519.modelId]) : void 0;
9933
10426
  return modelId ? `${name} (via ${modelId})` : void 0;
9934
10427
  };
9935
- for (const binding of candidateGatewayBindings(config.bindings, apiKeyId, "messages")) {
9936
- if (binding.modelMode === "passthrough") {
9937
- if (binding.target.kind === "provider") {
9938
- const provider = await llmConfig.getProvider(binding.target.providerId);
9939
- for (const id of _nullishCoalesce(_optionalChain([provider, 'optionalAccess', _480 => _480.models]), () => ( []))) push(id);
9940
- } else if (Object.prototype.hasOwnProperty.call(_subscriptionmodelcatalog.SUBSCRIPTION_MODEL_CATALOG, binding.target.providerId)) {
9941
- for (const id of _subscriptionmodelcatalog.SUBSCRIPTION_MODEL_CATALOG[binding.target.providerId]) {
9942
- push(id);
10428
+ for (const endpoint of MODEL_LIST_ENDPOINTS) {
10429
+ if (allowedEndpoints && !allowedEndpoints.includes(endpoint)) continue;
10430
+ for (const binding of candidateGatewayBindings(config.bindings, apiKeyId, endpoint)) {
10431
+ if (binding.modelMode === "passthrough") {
10432
+ await pushTargetCatalog(llmConfig, binding.target, push);
10433
+ continue;
10434
+ }
10435
+ if (_optionalChain([binding, 'access', _520 => _520.modelMappings, 'optionalAccess', _521 => _521.length])) {
10436
+ for (const mapping of binding.modelMappings) {
10437
+ const source = mapping.source.trim();
10438
+ if (source === "" || source.includes("*")) continue;
10439
+ push(source, viaLabel(source, mapping.target));
9943
10440
  }
10441
+ if (hasWildcardMapping(binding)) {
10442
+ await pushTargetCatalog(llmConfig, binding.target, push);
10443
+ for (const mapping of _nullishCoalesce(binding.modelMappings, () => ( []))) {
10444
+ if (!mapping.source.includes("*") || mapping.target.trim() === "") continue;
10445
+ push(_nullishCoalesce(_optionalChain([_chunkJGRNVH7Ccjs.parseModelRef.call(void 0, mapping.target), 'optionalAccess', _522 => _522.modelId]), () => ( mapping.target.trim())));
10446
+ }
10447
+ }
10448
+ continue;
9944
10449
  }
9945
- continue;
9946
- }
9947
- if (_optionalChain([binding, 'access', _481 => _481.modelMappings, 'optionalAccess', _482 => _482.length])) {
9948
- for (const mapping of binding.modelMappings) {
9949
- const source = mapping.source.trim();
9950
- if (source === "" || source.includes("*")) continue;
9951
- push(source, viaLabel(source, mapping.target));
10450
+ for (const [kind, ref] of Object.entries(_nullishCoalesce(binding.modelMap, () => ( {})))) {
10451
+ if (typeof ref !== "string" || ref.trim() === "") continue;
10452
+ push(kind, viaLabel(kind, ref));
9952
10453
  }
9953
- continue;
9954
10454
  }
9955
- for (const [kind, ref] of Object.entries(_nullishCoalesce(binding.modelMap, () => ( {})))) {
9956
- if (typeof ref !== "string" || ref.trim() === "") continue;
9957
- push(kind, viaLabel(kind, ref));
10455
+ }
10456
+ if (_optionalChain([directTarget, 'optionalAccess', _523 => _523.kind]) === "provider") {
10457
+ for (const id of await passthroughProviderModelIds(llmConfig, directTarget.providerId)) {
10458
+ push(id);
9958
10459
  }
9959
10460
  }
9960
10461
  const limited = limit !== void 0 ? entries2.slice(0, limit) : entries2;
@@ -9962,9 +10463,9 @@ async function writeModelsListAnthropic(res, llmConfig, config, apiKeyId, allowe
9962
10463
  res.end(
9963
10464
  JSON.stringify({
9964
10465
  data: limited,
9965
- first_id: _nullishCoalesce(_optionalChain([limited, 'access', _483 => _483[0], 'optionalAccess', _484 => _484.id]), () => ( null)),
10466
+ first_id: _nullishCoalesce(_optionalChain([limited, 'access', _524 => _524[0], 'optionalAccess', _525 => _525.id]), () => ( null)),
9966
10467
  has_more: limited.length < entries2.length,
9967
- last_id: _nullishCoalesce(_optionalChain([limited, 'access', _485 => _485[limited.length - 1], 'optionalAccess', _486 => _486.id]), () => ( null))
10468
+ last_id: _nullishCoalesce(_optionalChain([limited, 'access', _526 => _526[limited.length - 1], 'optionalAccess', _527 => _527.id]), () => ( null))
9968
10469
  })
9969
10470
  );
9970
10471
  }
@@ -9986,8 +10487,8 @@ function handleOauthUsageProxy(res, config, apiKeyId) {
9986
10487
  const snapshot = _nullishCoalesce(_nullishCoalesce((preferredAccountId !== void 0 ? snapshots.find((s) => s.accountId === preferredAccountId) : void 0), () => ( snapshots.find((s) => s.windows.some((w) => w.state === "fresh")))), () => ( snapshots[0]));
9987
10488
  const body = {};
9988
10489
  for (const [wireKey, windowId] of OAUTH_USAGE_WINDOW_IDS) {
9989
- const window = _optionalChain([snapshot, 'optionalAccess', _487 => _487.windows, 'access', _488 => _488.find, 'call', _489 => _489((w) => w.id === windowId)]);
9990
- const usable = _optionalChain([window, 'optionalAccess', _490 => _490.state]) === "fresh";
10490
+ const window = _optionalChain([snapshot, 'optionalAccess', _528 => _528.windows, 'access', _529 => _529.find, 'call', _530 => _530((w) => w.id === windowId)]);
10491
+ const usable = _optionalChain([window, 'optionalAccess', _531 => _531.state]) === "fresh";
9991
10492
  body[wireKey] = {
9992
10493
  utilization: usable ? _nullishCoalesce(window.usedPercent, () => ( null)) : null,
9993
10494
  resets_at: usable ? _nullishCoalesce(window.resetsAt, () => ( null)) : null
@@ -9996,29 +10497,172 @@ function handleOauthUsageProxy(res, config, apiKeyId) {
9996
10497
  res.writeHead(200, { "Content-Type": "application/json" });
9997
10498
  res.end(JSON.stringify(body));
9998
10499
  }
9999
- async function writeModelsList(res, llmConfig, config, apiKeyId, allowedEndpoints, imageModels = []) {
10500
+ function directUpstreamRoot(baseUrl, format) {
10501
+ const base = baseUrl.trim().replace(/\/+$/, "");
10502
+ if (!base) return null;
10503
+ if (format === "google") return base.replace(/\/models$/, "");
10504
+ if (format === "anthropic") return base.replace(/\/messages$/, "");
10505
+ if (format === "openai-response") return base.replace(/\/responses$/, "");
10506
+ return base.replace(/\/chat\/completions$/, "");
10507
+ }
10508
+ function directUpstreamUrl(provider, requestUrl) {
10509
+ const root = directUpstreamRoot(
10510
+ _nullishCoalesce(provider.api_base_url, () => ( "")),
10511
+ _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider)
10512
+ );
10513
+ if (!root) return null;
10514
+ const raw = _nullishCoalesce(requestUrl, () => ( "/"));
10515
+ const queryIndex = raw.indexOf("?");
10516
+ const path = (queryIndex >= 0 ? raw.slice(0, queryIndex) : raw) || "/";
10517
+ const query = queryIndex >= 0 ? raw.slice(queryIndex) : "";
10518
+ const versionSegment = _optionalChain([/\/v\d+[a-z]*$/, 'access', _532 => _532.exec, 'call', _533 => _533(root), 'optionalAccess', _534 => _534[0]]);
10519
+ let tail = path;
10520
+ if (versionSegment) {
10521
+ if (path === versionSegment) tail = "";
10522
+ else if (path.startsWith(`${versionSegment}/`)) tail = path.slice(versionSegment.length);
10523
+ }
10524
+ return `${root}${tail}${query}`;
10525
+ }
10526
+ function directUpstreamBinding(target, apiKeyId, priority = 1e3) {
10527
+ return {
10528
+ id: `direct:${apiKeyId}`,
10529
+ name: "direct upstream",
10530
+ enabled: true,
10531
+ keyScope: "selected",
10532
+ apiKeyIds: [apiKeyId],
10533
+ endpoint: "messages",
10534
+ target,
10535
+ priority,
10536
+ fallback: "fail",
10537
+ modelMode: "passthrough"
10538
+ };
10539
+ }
10540
+ async function relayDirectUpstream(req, res, deps, verified, config, concurrencyGate, audit, preReadBody) {
10541
+ const direct = verified.boundUpstream;
10542
+ const providerId = _optionalChain([direct, 'optionalAccess', _535 => _535.kind]) === "provider" ? direct.providerId : "";
10543
+ const provider = await deps.llmConfig.getProvider(providerId);
10544
+ if (!provider) {
10545
+ writeJsonError(
10546
+ res,
10547
+ 503,
10548
+ `direct upstream provider '${providerId}' is not configured for this key`
10549
+ );
10550
+ return;
10551
+ }
10552
+ const url = directUpstreamUrl(provider, req.url);
10553
+ if (!url) {
10554
+ writeJsonError(res, 503, `direct upstream provider '${providerId}' has no base URL`);
10555
+ return;
10556
+ }
10557
+ const concurrencyLimit = verified.maxConcurrency;
10558
+ let releaseConcurrency = null;
10559
+ if (typeof concurrencyLimit === "number" && concurrencyLimit > 0) {
10560
+ const cq = _nullishCoalesce(config.concurrencyQueue, () => ( DEFAULT_CONCURRENCY_QUEUE));
10561
+ const acquisition = concurrencyGate.acquire(verified.id, concurrencyLimit, {
10562
+ maxQueueSizeFactor: cq.maxQueueSizeFactor,
10563
+ minQueueSize: cq.minQueueSize,
10564
+ waitTimeoutMs: cq.waitTimeoutMs
10565
+ });
10566
+ const cancelOnClose = () => acquisition.cancel();
10567
+ res.once("close", cancelOnClose);
10568
+ let slot;
10569
+ try {
10570
+ slot = await acquisition.granted;
10571
+ } catch (err) {
10572
+ res.removeListener("close", cancelOnClose);
10573
+ if (isConcurrencyRejection(err)) {
10574
+ writeJsonError(res, 429, "Concurrency limit exceeded", { "Retry-After": "5" });
10575
+ return;
10576
+ }
10577
+ throw err;
10578
+ }
10579
+ res.removeListener("close", cancelOnClose);
10580
+ const release2 = () => slot.release();
10581
+ releaseConcurrency = release2;
10582
+ res.once("close", release2);
10583
+ }
10584
+ try {
10585
+ const rawBody = preReadBody !== void 0 ? preReadBody : await readBody3(req);
10586
+ if (audit) {
10587
+ audit.setRequestBody(rawBody);
10588
+ try {
10589
+ audit.sessionKey = deriveAuditSessionKey(
10590
+ rawBody ? JSON.parse(rawBody) : {},
10591
+ req.headers,
10592
+ { fallbackKey: verified.id, endpoint: "direct" }
10593
+ );
10594
+ } catch (e57) {
10595
+ }
10596
+ }
10597
+ const headers = _chunkTX4UCSOPcjs.getProviderHeaders.call(void 0, provider, resolveProviderKeyLiteral(provider.api_key));
10598
+ delete headers["Content-Type"];
10599
+ const clientContentType = req.headers["content-type"];
10600
+ if (typeof clientContentType === "string" && clientContentType) {
10601
+ headers["Content-Type"] = clientContentType;
10602
+ }
10603
+ const clientAccept = req.headers["accept"];
10604
+ if (typeof clientAccept === "string" && clientAccept) headers["Accept"] = clientAccept;
10605
+ const hasRequestBody = req.method !== "GET" && req.method !== "HEAD";
10606
+ const upstream = await _chunkCXRJMNJJcjs.fetchUpstream.call(void 0,
10607
+ url,
10608
+ {
10609
+ method: _nullishCoalesce(req.method, () => ( "GET")),
10610
+ headers,
10611
+ ...hasRequestBody ? { body: rawBody } : {},
10612
+ // Client hang-up aborts the upstream call (no egress after cancel).
10613
+ signal: requestLifecycleSignal(req, res)
10614
+ },
10615
+ { providerId: "byo" }
10616
+ );
10617
+ if (audit) audit.provider = provider.id;
10618
+ const responseHeaders = {};
10619
+ const contentType = upstream.headers.get("content-type");
10620
+ if (contentType) responseHeaders["Content-Type"] = contentType;
10621
+ res.writeHead(upstream.status, responseHeaders);
10622
+ if (!upstream.body) {
10623
+ res.end();
10624
+ return;
10625
+ }
10626
+ const bodyStream = _stream.Readable.fromWeb(
10627
+ upstream.body
10628
+ );
10629
+ bodyStream.on("error", () => {
10630
+ res.destroy();
10631
+ });
10632
+ bodyStream.pipe(res);
10633
+ await new Promise((resolve) => {
10634
+ res.once("close", resolve);
10635
+ });
10636
+ } catch (err) {
10637
+ const message = _chunkSVNDB62Dcjs.serializeError.call(void 0, err);
10638
+ if (deps.logger) deps.logger.error("[OutboundApi] direct relay error:", message);
10639
+ else console.error("[OutboundApi] direct relay error:", message);
10640
+ _chunkUIBD2YY5cjs.emitWebhookEvent.call(void 0, { kind: "server.error", at: Date.now(), message });
10641
+ if (audit) audit.error = message;
10642
+ if (!res.headersSent) writeJsonError(res, 502, message);
10643
+ else res.destroy();
10644
+ }
10645
+ }
10646
+ async function writeModelsList(res, llmConfig, config, apiKeyId, allowedEndpoints, imageModels = [], directTarget) {
10000
10647
  const modelIds = [];
10001
- for (const endpoint of ["chat", "responses", "messages", "gemini"]) {
10648
+ for (const endpoint of MODEL_LIST_ENDPOINTS) {
10002
10649
  if (allowedEndpoints && !allowedEndpoints.includes(endpoint)) continue;
10003
10650
  for (const binding of candidateGatewayBindings(config.bindings, apiKeyId, endpoint)) {
10004
10651
  if (binding.modelMode === "passthrough") {
10005
- if (binding.target.kind === "provider") {
10006
- const provider = await llmConfig.getProvider(binding.target.providerId);
10007
- modelIds.push(..._nullishCoalesce(_optionalChain([provider, 'optionalAccess', _491 => _491.models]), () => ( [])));
10008
- } else if (Object.prototype.hasOwnProperty.call(
10009
- _subscriptionmodelcatalog.SUBSCRIPTION_MODEL_CATALOG,
10010
- binding.target.providerId
10011
- )) {
10012
- modelIds.push(
10013
- ..._subscriptionmodelcatalog.SUBSCRIPTION_MODEL_CATALOG[binding.target.providerId]
10014
- );
10015
- }
10652
+ await pushTargetCatalog(llmConfig, binding.target, (id) => modelIds.push(id));
10016
10653
  continue;
10017
10654
  }
10018
- if (_optionalChain([binding, 'access', _492 => _492.modelMappings, 'optionalAccess', _493 => _493.length])) {
10655
+ if (_optionalChain([binding, 'access', _536 => _536.modelMappings, 'optionalAccess', _537 => _537.length])) {
10019
10656
  modelIds.push(
10020
10657
  ...binding.modelMappings.map((mapping) => mapping.source.trim()).filter((source) => source !== "" && !source.includes("*"))
10021
10658
  );
10659
+ if (hasWildcardMapping(binding)) {
10660
+ await pushTargetCatalog(llmConfig, binding.target, (id) => modelIds.push(id));
10661
+ for (const mapping of _nullishCoalesce(binding.modelMappings, () => ( []))) {
10662
+ if (!mapping.source.includes("*") || mapping.target.trim() === "") continue;
10663
+ modelIds.push(_nullishCoalesce(_optionalChain([_chunkJGRNVH7Ccjs.parseModelRef.call(void 0, mapping.target), 'optionalAccess', _538 => _538.modelId]), () => ( mapping.target.trim())));
10664
+ }
10665
+ }
10022
10666
  continue;
10023
10667
  }
10024
10668
  const endpointConfig = gatewayBindingToEndpointConfig(binding);
@@ -10031,10 +10675,13 @@ async function writeModelsList(res, llmConfig, config, apiKeyId, allowedEndpoint
10031
10675
  if (endpointConfig.backgroundModel) refs.push(endpointConfig.backgroundModel);
10032
10676
  }
10033
10677
  modelIds.push(
10034
- ...refs.map((ref) => _optionalChain([_chunk57Y2EA2Gcjs.parseModelRef.call(void 0, ref), 'optionalAccess', _494 => _494.modelId])).filter((modelId) => modelId !== void 0)
10678
+ ...refs.map((ref) => _optionalChain([_chunkJGRNVH7Ccjs.parseModelRef.call(void 0, ref), 'optionalAccess', _539 => _539.modelId])).filter((modelId) => modelId !== void 0)
10035
10679
  );
10036
10680
  }
10037
10681
  }
10682
+ if (_optionalChain([directTarget, 'optionalAccess', _540 => _540.kind]) === "provider") {
10683
+ modelIds.push(...await passthroughProviderModelIds(llmConfig, directTarget.providerId));
10684
+ }
10038
10685
  modelIds.push(...imageModels);
10039
10686
  const seen = /* @__PURE__ */ new Set();
10040
10687
  const data = modelIds.filter((modelId) => {
@@ -10078,9 +10725,9 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10078
10725
  const anthropicPathClass = classifyAnthropicMessagesPath(req.url);
10079
10726
  const isCountTokens = anthropicPathClass === "count_tokens";
10080
10727
  const classifiedOperation = _chunkG4CZIUIBcjs.classifyOpenAIOperation.call(void 0, req.method, req.url);
10081
- const imageOperation = _optionalChain([classifiedOperation, 'optionalAccess', _495 => _495.policyFamily]) === "images" ? classifiedOperation : null;
10728
+ const imageOperation = _optionalChain([classifiedOperation, 'optionalAccess', _541 => _541.policyFamily]) === "images" ? classifiedOperation : null;
10082
10729
  if (anthropicPathClass !== null) markAnthropicProtocolResponse(res);
10083
- const proxyOauthUsageEnabled = _optionalChain([config, 'access', _496 => _496.anthropic, 'optionalAccess', _497 => _497.proxyOauthUsage]) === true;
10730
+ const proxyOauthUsageEnabled = _optionalChain([config, 'access', _542 => _542.anthropic, 'optionalAccess', _543 => _543.proxyOauthUsage]) === true;
10084
10731
  const isOauthUsagePath = proxyOauthUsageEnabled && isAnthropicOauthUsagePath(req.url);
10085
10732
  if (isOauthUsagePath) markAnthropicProtocolResponse(res);
10086
10733
  const audit = _chunkFX325I5Qcjs.beginAuditCapture.call(void 0, req, res, now, {
@@ -10100,7 +10747,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10100
10747
  const verified = verification.key;
10101
10748
  if (audit) audit.keyId = verified.id;
10102
10749
  if (billing) billing.keyId = verified.id;
10103
- if (verified.loopbackOnly && !isLoopbackPeer(_optionalChain([req, 'access', _498 => _498.socket, 'optionalAccess', _499 => _499.remoteAddress]))) {
10750
+ if (verified.loopbackOnly && !isLoopbackPeer(_optionalChain([req, 'access', _544 => _544.socket, 'optionalAccess', _545 => _545.remoteAddress]))) {
10104
10751
  writeJsonError(res, 403, "This integration key is restricted to loopback clients");
10105
10752
  return;
10106
10753
  }
@@ -10113,7 +10760,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10113
10760
  req,
10114
10761
  res,
10115
10762
  deps,
10116
- _optionalChain([config, 'access', _500 => _500.voucher, 'optionalAccess', _501 => _501.enabled]) === true,
10763
+ _optionalChain([config, 'access', _546 => _546.voucher, 'optionalAccess', _547 => _547.enabled]) === true,
10117
10764
  _nullishCoalesce(redeemLimiter, () => ( getFallbackRedeemLimiter())),
10118
10765
  verified.id,
10119
10766
  _nullishCoalesce(presented, () => ( "")),
@@ -10129,6 +10776,16 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10129
10776
  });
10130
10777
  return;
10131
10778
  }
10779
+ const directProvider = _optionalChain([verified, 'access', _548 => _548.boundUpstream, 'optionalAccess', _549 => _549.kind]) === "provider" ? verified.boundUpstream : null;
10780
+ if (verified.boundUpstream && !directProvider) {
10781
+ config = {
10782
+ ...config,
10783
+ bindings: [
10784
+ ..._nullishCoalesce(config.bindings, () => ( [])),
10785
+ directUpstreamBinding(verified.boundUpstream, verified.id, 1e3)
10786
+ ]
10787
+ };
10788
+ }
10132
10789
  if (isOauthUsagePath) {
10133
10790
  if (req.method !== "GET") {
10134
10791
  writeJsonError(res, 404, `Unsupported: ${req.method} ${req.url}`);
@@ -10162,7 +10819,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10162
10819
  }
10163
10820
  if (isCodexSearchRequest(req.method, req.url)) {
10164
10821
  await handleCodexSearchRequest(req, res, {
10165
- mode: _nullishCoalesce(_optionalChain([config, 'access', _502 => _502.search, 'optionalAccess', _503 => _503.modes, 'access', _504 => _504.codex]), () => ( _chunkE4QHVXV5cjs.DEFAULT_SEARCH_FRONTEND_MODES.codex)),
10822
+ mode: _nullishCoalesce(_optionalChain([config, 'access', _550 => _550.search, 'optionalAccess', _551 => _551.modes, 'access', _552 => _552.codex]), () => ( _chunkE4QHVXV5cjs.DEFAULT_SEARCH_FRONTEND_MODES.codex)),
10166
10823
  runtime: _nullishCoalesce(deps.searchRuntime, () => ( null)),
10167
10824
  // This handler EXECUTES rather than relays, and `handleOutboundRequest`
10168
10825
  // has no signal of its own to hand down, so it builds one. Without it a
@@ -10185,21 +10842,22 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10185
10842
  writeJsonError(res, 403, "API key is not allowed to access this endpoint");
10186
10843
  return;
10187
10844
  }
10188
- if (resolveModelsShape(_optionalChain([config, 'access', _505 => _505.anthropic, 'optionalAccess', _506 => _506.modelsShape]), verified.allowedEndpoints) === "anthropic") {
10845
+ if (resolveModelsShape(_optionalChain([config, 'access', _553 => _553.anthropic, 'optionalAccess', _554 => _554.modelsShape]), verified.allowedEndpoints) === "anthropic") {
10189
10846
  await writeModelsListAnthropic(
10190
10847
  res,
10191
10848
  deps.llmConfig,
10192
10849
  config,
10193
10850
  verified.id,
10194
10851
  verified.allowedEndpoints,
10195
- parseModelsLimit(req.url)
10852
+ parseModelsLimit(req.url),
10853
+ verified.boundUpstream
10196
10854
  );
10197
10855
  } else {
10198
10856
  let imageModels = [];
10199
10857
  if (verified.allowedEndpoints.includes("images") && deps.imageModelCatalog) {
10200
10858
  try {
10201
10859
  imageModels = await deps.imageModelCatalog.listAvailableModels(verified.id);
10202
- } catch (e52) {
10860
+ } catch (e58) {
10203
10861
  }
10204
10862
  }
10205
10863
  await writeModelsList(
@@ -10208,21 +10866,26 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10208
10866
  config,
10209
10867
  verified.id,
10210
10868
  verified.allowedEndpoints,
10211
- imageModels
10869
+ imageModels,
10870
+ verified.boundUpstream
10212
10871
  );
10213
10872
  }
10214
10873
  return;
10215
10874
  }
10216
10875
  const endpoint = selectEndpoint(req.method, req.url);
10217
10876
  if (!endpoint) {
10877
+ if (directProvider) {
10878
+ await relayDirectUpstream(req, res, deps, verified, config, concurrencyGate, audit);
10879
+ return;
10880
+ }
10218
10881
  writeJsonError(res, 404, `Unsupported: ${req.method} ${req.url}`);
10219
10882
  return;
10220
10883
  }
10221
- if (verified.allowedEndpoints && !verified.allowedEndpoints.includes(endpoint)) {
10884
+ if (verified.allowedEndpoints && !verified.boundUpstream && !verified.allowedEndpoints.includes(endpoint)) {
10222
10885
  writeJsonError(res, 403, "API key is not allowed to access this endpoint");
10223
10886
  return;
10224
10887
  }
10225
- if (candidateGatewayBindings(config.bindings, verified.id, endpoint).length === 0) {
10888
+ if (candidateGatewayBindings(config.bindings, verified.id, endpoint).length === 0 && !directProvider) {
10226
10889
  writeJsonError(res, 503, `endpoint '${endpoint}' has no downstream route for this key`);
10227
10890
  return;
10228
10891
  }
@@ -10282,12 +10945,12 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10282
10945
  res.once("close", release2);
10283
10946
  }
10284
10947
  try {
10285
- const ingressFormat = _chunk57Y2EA2Gcjs.endpointToIngressFormat.call(void 0, endpoint);
10948
+ const ingressFormat = _chunkJGRNVH7Ccjs.endpointToIngressFormat.call(void 0, endpoint);
10286
10949
  const rawBody = await readBody3(req);
10287
10950
  let parsedBody = {};
10288
10951
  try {
10289
10952
  parsedBody = rawBody ? JSON.parse(rawBody) : {};
10290
- } catch (e53) {
10953
+ } catch (e59) {
10291
10954
  writeJsonError(res, 400, "Invalid JSON in request body");
10292
10955
  return;
10293
10956
  }
@@ -10302,8 +10965,8 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10302
10965
  const urlModel = extractGeminiModelFromUrl(req.url);
10303
10966
  if (urlModel) parsedBody["model"] = urlModel;
10304
10967
  }
10305
- const requestedModel = _chunk57Y2EA2Gcjs.extractRequestedModel.call(void 0, ingressFormat, parsedBody);
10306
- const role = _chunk57Y2EA2Gcjs.isKindMappedEndpoint.call(void 0, endpoint) || endpoint === "chat" ? void 0 : _chunk57Y2EA2Gcjs.detectRequestRole.call(void 0, ingressFormat, parsedBody, {
10968
+ const requestedModel = _chunkJGRNVH7Ccjs.extractRequestedModel.call(void 0, ingressFormat, parsedBody);
10969
+ const role = _chunkJGRNVH7Ccjs.isKindMappedEndpoint.call(void 0, endpoint) || endpoint === "chat" ? void 0 : _chunkJGRNVH7Ccjs.detectRequestRole.call(void 0, ingressFormat, parsedBody, {
10307
10970
  // Role detection precedes the route pick (the pick consumes the
10308
10971
  // role), so the hint is the union across the candidate routes.
10309
10972
  backgroundModelIds: candidateBackgroundModelIds(config.bindings, verified.id, endpoint)
@@ -10316,26 +10979,35 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10316
10979
  role
10317
10980
  });
10318
10981
  if (bindingResolution.source === "none") {
10982
+ if (directProvider) {
10983
+ await relayDirectUpstream(req, res, deps, verified, config, concurrencyGate, audit, rawBody);
10984
+ return;
10985
+ }
10319
10986
  writeJsonError(res, 503, `endpoint '${endpoint}' has no downstream route for this key`);
10320
10987
  return;
10321
10988
  }
10322
10989
  const effectiveEndpointConfig = bindingResolution.config;
10323
10990
  const bindingAffinitySuffix = `:${bindingResolution.binding.id}`;
10324
10991
  const sessionId = deps.proxyDeps.apiKeyPool ? `outbound:${verified.id}${bindingAffinitySuffix}` : null;
10992
+ let replayBody = rawBody;
10993
+ if (!isCountTokens && effectiveEndpointConfig.reasoningEffort && injectMappingEffortDefault(endpoint, effectiveEndpointConfig.reasoningEffort, parsedBody)) {
10994
+ replayBody = JSON.stringify(parsedBody);
10995
+ }
10325
10996
  const hostedImageGenerationAllowed = verified.allowedEndpoints.includes("images");
10326
- const resolved = _chunk57Y2EA2Gcjs.isKindMappedEndpoint.call(void 0, endpoint) || endpoint === "chat" ? await _chunk57Y2EA2Gcjs.resolveRoute.call(void 0, {
10997
+ const listResolvedModel = endpoint === "chat" && bindingResolution.binding.modelMode === "mapped" ? _nullishCoalesce(_optionalChain([resolveGatewayModelMappingRow, 'call', _555 => _555(bindingResolution.binding.modelMappings, requestedModel), 'optionalAccess', _556 => _556.target]), () => ( requestedModel)) : requestedModel;
10998
+ const resolved = _chunkJGRNVH7Ccjs.isKindMappedEndpoint.call(void 0, endpoint) || endpoint === "chat" ? await _chunkJGRNVH7Ccjs.resolveRoute.call(void 0, {
10327
10999
  config: effectiveEndpointConfig,
10328
11000
  ingressFormat,
10329
11001
  llmConfig: deps.llmConfig,
10330
11002
  sessionId,
10331
- // Capture the ORIGINAL requested id BEFORE any downstream swap; for
10332
- // kind-mapped endpoints it selects the kind AND is stamped onto
10333
- // `route.requestedModel`; for chat it is matched against the list.
10334
- requestedModel,
11003
+ // The id the route resolves against: the client's ORIGINAL id for
11004
+ // kind-mapped endpoints (it selects the kind AND is stamped onto
11005
+ // `route.requestedModel`), the mapping-resolved target for chat.
11006
+ requestedModel: listResolvedModel,
10335
11007
  // Attribution: stamp the verified named-key id onto the route.
10336
11008
  apiKeyId: verified.id,
10337
11009
  hostedImageGenerationAllowed
10338
- }) : await _chunk57Y2EA2Gcjs.resolveRoute.call(void 0, {
11010
+ }) : await _chunkJGRNVH7Ccjs.resolveRoute.call(void 0, {
10339
11011
  config: effectiveEndpointConfig,
10340
11012
  role,
10341
11013
  ingressFormat,
@@ -10346,6 +11018,10 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10346
11018
  hostedImageGenerationAllowed
10347
11019
  });
10348
11020
  if (!resolved.ok) {
11021
+ if (directProvider) {
11022
+ await relayDirectUpstream(req, res, deps, verified, config, concurrencyGate, audit, rawBody);
11023
+ return;
11024
+ }
10349
11025
  writeJsonError(res, resolved.error.status, resolved.error.message);
10350
11026
  return;
10351
11027
  }
@@ -10367,7 +11043,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10367
11043
  }
10368
11044
  let releaseSerial = null;
10369
11045
  const providerKey = resolved.route.providerId;
10370
- if (_optionalChain([config, 'access', _507 => _507.userMessageQueue, 'optionalAccess', _508 => _508.enabled]) && providerKey && !isCountTokens && isUserMessageRequest(endpoint, parsedBody)) {
11046
+ if (_optionalChain([config, 'access', _557 => _557.userMessageQueue, 'optionalAccess', _558 => _558.enabled]) && providerKey && !isCountTokens && isUserMessageRequest(endpoint, parsedBody)) {
10371
11047
  const umq = config.userMessageQueue;
10372
11048
  try {
10373
11049
  const serialSlot = await serialQueue.acquire(providerKey, {
@@ -10397,17 +11073,17 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10397
11073
  const token = routeMap.addRoute(
10398
11074
  isCountTokens ? {
10399
11075
  ...requestRoute,
10400
- anthropicCountTokensMode: _optionalChain([config, 'access', _509 => _509.anthropic, 'optionalAccess', _510 => _510.countTokens, 'optionalAccess', _511 => _511.mode]),
10401
- anthropicCountTokensEstimateBudgetMs: _optionalChain([config, 'access', _512 => _512.anthropic, 'optionalAccess', _513 => _513.countTokens, 'optionalAccess', _514 => _514.estimateBudgetMs]),
10402
- anthropicPdfTextExtractionBudgetMs: _optionalChain([config, 'access', _515 => _515.anthropic, 'optionalAccess', _516 => _516.pdfTextExtraction, 'optionalAccess', _517 => _517.budgetMs])
11076
+ anthropicCountTokensMode: _optionalChain([config, 'access', _559 => _559.anthropic, 'optionalAccess', _560 => _560.countTokens, 'optionalAccess', _561 => _561.mode]),
11077
+ anthropicCountTokensEstimateBudgetMs: _optionalChain([config, 'access', _562 => _562.anthropic, 'optionalAccess', _563 => _563.countTokens, 'optionalAccess', _564 => _564.estimateBudgetMs]),
11078
+ anthropicPdfTextExtractionBudgetMs: _optionalChain([config, 'access', _565 => _565.anthropic, 'optionalAccess', _566 => _566.pdfTextExtraction, 'optionalAccess', _567 => _567.budgetMs])
10403
11079
  } : anthropicPathClass !== null ? {
10404
11080
  ...requestRoute,
10405
- anthropicPdfTextExtractionBudgetMs: _optionalChain([config, 'access', _518 => _518.anthropic, 'optionalAccess', _519 => _519.pdfTextExtraction, 'optionalAccess', _520 => _520.budgetMs])
11081
+ anthropicPdfTextExtractionBudgetMs: _optionalChain([config, 'access', _568 => _568.anthropic, 'optionalAccess', _569 => _569.pdfTextExtraction, 'optionalAccess', _570 => _570.budgetMs])
10406
11082
  } : requestRoute
10407
11083
  );
10408
11084
  try {
10409
11085
  shimAuthHeader(req, token);
10410
- const replay = makeReplayRequest(req, rawBody);
11086
+ const replay = makeReplayRequest(req, replayBody);
10411
11087
  await routeRequest(replay, res, routeMap, deps.proxyDeps);
10412
11088
  } catch (err) {
10413
11089
  if (_chunk25GXJCEZcjs.isBoundAccountSelectionError.call(void 0, err)) {
@@ -10586,7 +11262,7 @@ var OutboundApiServer = (_class19 = class {
10586
11262
  this.server = listener.server;
10587
11263
  this.boundAddr = bindAddr;
10588
11264
  this.boundPort = actualPort;
10589
- if (actualPort !== port) _optionalChain([this, 'access', _521 => _521.onPortChange, 'optionalCall', _522 => _522(actualPort)]);
11265
+ if (actualPort !== port) _optionalChain([this, 'access', _571 => _571.onPortChange, 'optionalCall', _572 => _572(actualPort)]);
10590
11266
  this.logInfo(`[OutboundApiServer] Listening on ${bindAddr}:${actualPort}`);
10591
11267
  return actualPort;
10592
11268
  }
@@ -10629,8 +11305,8 @@ var OutboundApiServer = (_class19 = class {
10629
11305
  this.anthropicConfig = input.anthropic;
10630
11306
  this.searchConfig = input.search;
10631
11307
  this.imagesEnabled = input.imagesEnabled === true;
10632
- this.apiHelloEnabled = _optionalChain([input, 'access', _523 => _523.anthropic, 'optionalAccess', _524 => _524.apiHello]) !== false;
10633
- _chunkVGBJPHHDcjs.setAnthropicPingHeartbeatMs.call(void 0, _optionalChain([input, 'access', _525 => _525.anthropic, 'optionalAccess', _526 => _526.heartbeatIntervalMs]));
11308
+ this.apiHelloEnabled = _optionalChain([input, 'access', _573 => _573.anthropic, 'optionalAccess', _574 => _574.apiHello]) !== false;
11309
+ _chunkVGBJPHHDcjs.setAnthropicPingHeartbeatMs.call(void 0, _optionalChain([input, 'access', _575 => _575.anthropic, 'optionalAccess', _576 => _576.heartbeatIntervalMs]));
10634
11310
  }
10635
11311
  captureRuntimeSnapshot() {
10636
11312
  return {
@@ -10656,8 +11332,8 @@ var OutboundApiServer = (_class19 = class {
10656
11332
  this.anthropicConfig = snapshot.anthropic;
10657
11333
  this.searchConfig = snapshot.search;
10658
11334
  this.imagesEnabled = snapshot.imagesEnabled;
10659
- this.apiHelloEnabled = _optionalChain([snapshot, 'access', _527 => _527.anthropic, 'optionalAccess', _528 => _528.apiHello]) !== false;
10660
- _chunkVGBJPHHDcjs.setAnthropicPingHeartbeatMs.call(void 0, _optionalChain([snapshot, 'access', _529 => _529.anthropic, 'optionalAccess', _530 => _530.heartbeatIntervalMs]));
11335
+ this.apiHelloEnabled = _optionalChain([snapshot, 'access', _577 => _577.anthropic, 'optionalAccess', _578 => _578.apiHello]) !== false;
11336
+ _chunkVGBJPHHDcjs.setAnthropicPingHeartbeatMs.call(void 0, _optionalChain([snapshot, 'access', _579 => _579.anthropic, 'optionalAccess', _580 => _580.heartbeatIntervalMs]));
10661
11337
  }
10662
11338
  async restoreRuntimeSnapshot(snapshot) {
10663
11339
  const current = this.server;
@@ -10691,22 +11367,22 @@ var OutboundApiServer = (_class19 = class {
10691
11367
  server.close(() => {
10692
11368
  try {
10693
11369
  this.logInfo("[OutboundApiServer] Stopped");
10694
- } catch (e54) {
11370
+ } catch (e60) {
10695
11371
  }
10696
11372
  });
10697
- } catch (e55) {
11373
+ } catch (e61) {
10698
11374
  }
10699
11375
  }
10700
11376
  announcePublishedListener(bindAddr, requestedPort, actualPort) {
10701
11377
  if (actualPort !== requestedPort) {
10702
11378
  try {
10703
- _optionalChain([this, 'access', _531 => _531.onPortChange, 'optionalCall', _532 => _532(actualPort)]);
10704
- } catch (e56) {
11379
+ _optionalChain([this, 'access', _581 => _581.onPortChange, 'optionalCall', _582 => _582(actualPort)]);
11380
+ } catch (e62) {
10705
11381
  }
10706
11382
  }
10707
11383
  try {
10708
11384
  this.logInfo(`[OutboundApiServer] Listening on ${bindAddr}:${actualPort}`);
10709
- } catch (e57) {
11385
+ } catch (e63) {
10710
11386
  }
10711
11387
  }
10712
11388
  /** Per-request handler. Auth is enforced on EVERY request (incl. loopback). */
@@ -10753,7 +11429,7 @@ var OutboundApiServer = (_class19 = class {
10753
11429
  tryServeApiHello(req, res) {
10754
11430
  if (!this.apiHelloEnabled) return false;
10755
11431
  if (req.method !== "HEAD") return false;
10756
- const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access', _533 => _533.split, 'call', _534 => _534("?"), 'access', _535 => _535[0], 'optionalAccess', _536 => _536.replace, 'call', _537 => _537(/\/+$/, "")]) || "/";
11432
+ const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access', _583 => _583.split, 'call', _584 => _584("?"), 'access', _585 => _585[0], 'optionalAccess', _586 => _586.replace, 'call', _587 => _587(/\/+$/, "")]) || "/";
10757
11433
  if (path !== "/api/hello") return false;
10758
11434
  res.writeHead(200);
10759
11435
  res.end();
@@ -10767,7 +11443,7 @@ var OutboundApiServer = (_class19 = class {
10767
11443
  const provider = this.deps.healthReportProvider;
10768
11444
  if (!provider) return false;
10769
11445
  if (req.method !== "GET" && req.method !== "HEAD") return false;
10770
- const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access', _538 => _538.split, 'call', _539 => _539("?"), 'access', _540 => _540[0], 'optionalAccess', _541 => _541.replace, 'call', _542 => _542(/\/+$/, "")]) || "/";
11446
+ const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access', _588 => _588.split, 'call', _589 => _589("?"), 'access', _590 => _590[0], 'optionalAccess', _591 => _591.replace, 'call', _592 => _592(/\/+$/, "")]) || "/";
10771
11447
  if (path !== "/health" && path !== "/healthz") return false;
10772
11448
  const report = provider();
10773
11449
  res.writeHead(_healthloggingtypes.healthHttpStatus.call(void 0, report.status), { "Content-Type": "application/json" });
@@ -10992,7 +11668,7 @@ function resolveCompletionReasoningPlan(provider, options, target, requestMaxTok
10992
11668
  }
10993
11669
  function resolveOpenAIEffort(provider, options, target) {
10994
11670
  const plan = resolveCompletionReasoningPlan(provider, options, target);
10995
- return _optionalChain([plan, 'optionalAccess', _543 => _543.kind]) === "level" && plan.enabled ? plan.effort : void 0;
11671
+ return _optionalChain([plan, 'optionalAccess', _593 => _593.kind]) === "level" && plan.enabled ? plan.effort : void 0;
10996
11672
  }
10997
11673
  function buildAnthropicReasoningWire(provider, options) {
10998
11674
  const configuredMaxTokens = _nullishCoalesce(options.maxTokens, () => ( LEGACY_ANTHROPIC_MAX_TOKENS));
@@ -11003,7 +11679,7 @@ function buildAnthropicReasoningWire(provider, options) {
11003
11679
  "anthropic",
11004
11680
  legacyBound
11005
11681
  );
11006
- if (_optionalChain([plan, 'optionalAccess', _544 => _544.kind]) === "level" && plan.enabled) {
11682
+ if (_optionalChain([plan, 'optionalAccess', _594 => _594.kind]) === "level" && plan.enabled) {
11007
11683
  return {
11008
11684
  effectiveMaxTokens: configuredMaxTokens,
11009
11685
  thinking: { type: "adaptive" },
@@ -11011,7 +11687,7 @@ function buildAnthropicReasoningWire(provider, options) {
11011
11687
  legacyBudgetEnabled: false
11012
11688
  };
11013
11689
  }
11014
- if (_optionalChain([plan, 'optionalAccess', _545 => _545.kind]) === "budget" && plan.enabled) {
11690
+ if (_optionalChain([plan, 'optionalAccess', _595 => _595.kind]) === "budget" && plan.enabled) {
11015
11691
  return {
11016
11692
  effectiveMaxTokens: legacyBound,
11017
11693
  thinking: { type: "enabled", budget_tokens: plan.budgetTokens },
@@ -11025,13 +11701,13 @@ function buildAnthropicReasoningWire(provider, options) {
11025
11701
  }
11026
11702
  function buildGeminiThinkingConfig(provider, options) {
11027
11703
  const plan = resolveCompletionReasoningPlan(provider, options, "gemini");
11028
- if (_optionalChain([plan, 'optionalAccess', _546 => _546.kind]) === "level") {
11704
+ if (_optionalChain([plan, 'optionalAccess', _596 => _596.kind]) === "level") {
11029
11705
  return {
11030
11706
  includeThoughts: plan.enabled,
11031
11707
  thinkingLevel: plan.effort
11032
11708
  };
11033
11709
  }
11034
- if (_optionalChain([plan, 'optionalAccess', _547 => _547.kind]) === "budget") {
11710
+ if (_optionalChain([plan, 'optionalAccess', _597 => _597.kind]) === "budget") {
11035
11711
  return {
11036
11712
  includeThoughts: plan.enabled,
11037
11713
  thinkingBudget: plan.budgetTokens
@@ -11127,7 +11803,7 @@ async function callAnthropicCompletion(provider, apiKey, options, logger) {
11127
11803
  message: {
11128
11804
  id: `assistant-${Date.now()}`,
11129
11805
  role: "assistant",
11130
- content: _optionalChain([choice2, 'access', _548 => _548.message, 'optionalAccess', _549 => _549.content]) || "",
11806
+ content: _optionalChain([choice2, 'access', _598 => _598.message, 'optionalAccess', _599 => _599.content]) || "",
11131
11807
  timestamp: Date.now()
11132
11808
  },
11133
11809
  usage: openaiResponse2.usage ? {
@@ -11244,7 +11920,7 @@ async function callGeminiCompletion(provider, apiKey, options, logger) {
11244
11920
  const candidate = candidates[0];
11245
11921
  const content = candidate.content;
11246
11922
  let textContent = "";
11247
- if (_optionalChain([content, 'optionalAccess', _550 => _550.parts])) {
11923
+ if (_optionalChain([content, 'optionalAccess', _600 => _600.parts])) {
11248
11924
  for (const part of content.parts) {
11249
11925
  if (part.text) {
11250
11926
  textContent += part.text;
@@ -11372,7 +12048,7 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
11372
12048
  });
11373
12049
  if (!response.ok) {
11374
12050
  const errorText = await response.text();
11375
- _optionalChain([callbacks, 'access', _551 => _551.onError, 'optionalCall', _552 => _552(`API error (${response.status}): ${errorText}`)]);
12051
+ _optionalChain([callbacks, 'access', _601 => _601.onError, 'optionalCall', _602 => _602(`API error (${response.status}): ${errorText}`)]);
11376
12052
  return;
11377
12053
  }
11378
12054
  const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "openai", {
@@ -11382,7 +12058,7 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
11382
12058
  onVideo: callbacks.onVideo,
11383
12059
  onError: callbacks.onError
11384
12060
  });
11385
- _optionalChain([callbacks, 'access', _553 => _553.onDone, 'optionalCall', _554 => _554(
12061
+ _optionalChain([callbacks, 'access', _603 => _603.onDone, 'optionalCall', _604 => _604(
11386
12062
  {
11387
12063
  id: messageId,
11388
12064
  role: "assistant",
@@ -11457,7 +12133,7 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
11457
12133
  logger.info("Streaming Anthropic completion request", {
11458
12134
  url: apiUrl,
11459
12135
  model: anthropicRequest.model,
11460
- messagesCount: _optionalChain([anthropicRequest, 'access', _555 => _555.messages, 'optionalAccess', _556 => _556.length]),
12136
+ messagesCount: _optionalChain([anthropicRequest, 'access', _605 => _605.messages, 'optionalAccess', _606 => _606.length]),
11461
12137
  max_tokens: anthropicRequest.max_tokens,
11462
12138
  temperature: anthropicRequest.temperature,
11463
12139
  stream: anthropicRequest.stream,
@@ -11474,7 +12150,7 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
11474
12150
  if (!response.ok) {
11475
12151
  const errorText = await response.text();
11476
12152
  logger.error("Anthropic API error", void 0, { status: response.status, errorText });
11477
- _optionalChain([callbacks, 'access', _557 => _557.onError, 'optionalCall', _558 => _558(`API error (${response.status}): ${errorText}`)]);
12153
+ _optionalChain([callbacks, 'access', _607 => _607.onError, 'optionalCall', _608 => _608(`API error (${response.status}): ${errorText}`)]);
11478
12154
  return;
11479
12155
  }
11480
12156
  const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "anthropic", {
@@ -11485,10 +12161,10 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
11485
12161
  });
11486
12162
  logger.info("Anthropic stream complete", {
11487
12163
  contentLength: result.content.length,
11488
- reasoningLength: _optionalChain([result, 'access', _559 => _559.reasoning, 'optionalAccess', _560 => _560.length]) || 0,
12164
+ reasoningLength: _optionalChain([result, 'access', _609 => _609.reasoning, 'optionalAccess', _610 => _610.length]) || 0,
11489
12165
  blocksCount: result.blocks.length
11490
12166
  });
11491
- _optionalChain([callbacks, 'access', _561 => _561.onDone, 'optionalCall', _562 => _562(
12167
+ _optionalChain([callbacks, 'access', _611 => _611.onDone, 'optionalCall', _612 => _612(
11492
12168
  {
11493
12169
  id: messageId,
11494
12170
  role: "assistant",
@@ -11546,7 +12222,7 @@ async function streamGeminiCompletion(provider, apiKey, options, messageId, call
11546
12222
  if (!response.ok) {
11547
12223
  const errorText = await response.text();
11548
12224
  logger.error("Gemini API error", void 0, { status: response.status, errorText });
11549
- _optionalChain([callbacks, 'access', _563 => _563.onError, 'optionalCall', _564 => _564(`API error (${response.status}): ${errorText}`)]);
12225
+ _optionalChain([callbacks, 'access', _613 => _613.onError, 'optionalCall', _614 => _614(`API error (${response.status}): ${errorText}`)]);
11550
12226
  return;
11551
12227
  }
11552
12228
  const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "gemini", {
@@ -11555,7 +12231,7 @@ async function streamGeminiCompletion(provider, apiKey, options, messageId, call
11555
12231
  onError: callbacks.onError
11556
12232
  });
11557
12233
  logger.info("Gemini stream complete", { contentLength: result.content.length });
11558
- _optionalChain([callbacks, 'access', _565 => _565.onDone, 'optionalCall', _566 => _566(
12234
+ _optionalChain([callbacks, 'access', _615 => _615.onDone, 'optionalCall', _616 => _616(
11559
12235
  {
11560
12236
  id: messageId,
11561
12237
  role: "assistant",
@@ -11605,7 +12281,7 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
11605
12281
  });
11606
12282
  if (!response.ok) {
11607
12283
  const errorText = await response.text();
11608
- _optionalChain([callbacks, 'access', _567 => _567.onError, 'optionalCall', _568 => _568(`API error (${response.status}): ${errorText}`)]);
12284
+ _optionalChain([callbacks, 'access', _617 => _617.onError, 'optionalCall', _618 => _618(`API error (${response.status}): ${errorText}`)]);
11609
12285
  return;
11610
12286
  }
11611
12287
  const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "openai-response", {
@@ -11614,7 +12290,7 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
11614
12290
  onError: callbacks.onError
11615
12291
  });
11616
12292
  logger.info("OpenAI Response API stream complete", { contentLength: result.content.length });
11617
- _optionalChain([callbacks, 'access', _569 => _569.onDone, 'optionalCall', _570 => _570(
12293
+ _optionalChain([callbacks, 'access', _619 => _619.onDone, 'optionalCall', _620 => _620(
11618
12294
  {
11619
12295
  id: messageId,
11620
12296
  role: "assistant",
@@ -11642,7 +12318,7 @@ async function resolveEffectiveMaxTokens(llmConfig, _getProvider, logger, _provi
11642
12318
  }
11643
12319
  try {
11644
12320
  const globalParams = await llmConfig.getGlobalModelParameters();
11645
- if (_optionalChain([globalParams, 'optionalAccess', _571 => _571.maxTokens, 'optionalAccess', _572 => _572.enabled]) && globalParams.maxTokens.value > 0) {
12321
+ if (_optionalChain([globalParams, 'optionalAccess', _621 => _621.maxTokens, 'optionalAccess', _622 => _622.enabled]) && globalParams.maxTokens.value > 0) {
11646
12322
  logger.debug("Using global maxTokens", { maxTokens: globalParams.maxTokens.value });
11647
12323
  return globalParams.maxTokens.value;
11648
12324
  }
@@ -11670,7 +12346,7 @@ async function resolveThinkingBudget(getProvider, logger, providerId, modelId, m
11670
12346
  }
11671
12347
  const thinkingBudget = _thinkingconfig.calculateThinkingBudget.call(void 0, modelId, thinkLevel, maxTokens);
11672
12348
  const provider = await getProvider(providerId);
11673
- const providerName = _optionalChain([provider, 'optionalAccess', _573 => _573.name, 'optionalAccess', _574 => _574.toLowerCase, 'call', _575 => _575()]) || "";
12349
+ const providerName = _optionalChain([provider, 'optionalAccess', _623 => _623.name, 'optionalAccess', _624 => _624.toLowerCase, 'call', _625 => _625()]) || "";
11674
12350
  const apiFormat = provider ? _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider) : "openai";
11675
12351
  if (apiFormat === "anthropic" || providerName === "anthropic" || providerName.includes("claude")) {
11676
12352
  const thinkingConfig = _thinkingconfig.buildAnthropicThinking.call(void 0, modelId, thinkLevel, maxTokens);
@@ -11707,7 +12383,7 @@ function logToolFormat(tools, logger) {
11707
12383
  tools: openaiTools.map((t) => t.function.name),
11708
12384
  firstTool: {
11709
12385
  name: firstTool.function.name,
11710
- description: _optionalChain([firstTool, 'access', _576 => _576.function, 'access', _577 => _577.description, 'optionalAccess', _578 => _578.slice, 'call', _579 => _579(0, 100)]),
12386
+ description: _optionalChain([firstTool, 'access', _626 => _626.function, 'access', _627 => _627.description, 'optionalAccess', _628 => _628.slice, 'call', _629 => _629(0, 100)]),
11711
12387
  parameters: firstTool.function.parameters
11712
12388
  }
11713
12389
  });
@@ -11718,7 +12394,7 @@ function logToolFormat(tools, logger) {
11718
12394
  tools: anthropicTools.map((t) => t.name),
11719
12395
  firstTool: {
11720
12396
  name: firstTool.name,
11721
- description: _optionalChain([firstTool, 'access', _580 => _580.description, 'optionalAccess', _581 => _581.slice, 'call', _582 => _582(0, 100)]),
12397
+ description: _optionalChain([firstTool, 'access', _630 => _630.description, 'optionalAccess', _631 => _631.slice, 'call', _632 => _632(0, 100)]),
11722
12398
  input_schema: firstTool.input_schema
11723
12399
  }
11724
12400
  });
@@ -11729,9 +12405,9 @@ function logToolFormat(tools, logger) {
11729
12405
  count: allDeclarations.length,
11730
12406
  tools: allDeclarations.map((t) => t.name),
11731
12407
  firstTool: {
11732
- name: _optionalChain([allDeclarations, 'access', _583 => _583[0], 'optionalAccess', _584 => _584.name]),
11733
- description: _optionalChain([allDeclarations, 'access', _585 => _585[0], 'optionalAccess', _586 => _586.description, 'optionalAccess', _587 => _587.slice, 'call', _588 => _588(0, 100)]),
11734
- parameters: _optionalChain([allDeclarations, 'access', _589 => _589[0], 'optionalAccess', _590 => _590.parameters])
12408
+ name: _optionalChain([allDeclarations, 'access', _633 => _633[0], 'optionalAccess', _634 => _634.name]),
12409
+ description: _optionalChain([allDeclarations, 'access', _635 => _635[0], 'optionalAccess', _636 => _636.description, 'optionalAccess', _637 => _637.slice, 'call', _638 => _638(0, 100)]),
12410
+ parameters: _optionalChain([allDeclarations, 'access', _639 => _639[0], 'optionalAccess', _640 => _640.parameters])
11735
12411
  }
11736
12412
  });
11737
12413
  }
@@ -11794,7 +12470,7 @@ function buildToolRequest(apiFormat, conversationMessages, actualModel, options,
11794
12470
  function extractDeltaContent(rawJson, apiFormat) {
11795
12471
  const json = rawJson;
11796
12472
  if (apiFormat === "google") {
11797
- const parts = _optionalChain([json, 'access', _591 => _591.candidates, 'optionalAccess', _592 => _592[0], 'optionalAccess', _593 => _593.content, 'optionalAccess', _594 => _594.parts]) || [];
12473
+ const parts = _optionalChain([json, 'access', _641 => _641.candidates, 'optionalAccess', _642 => _642[0], 'optionalAccess', _643 => _643.content, 'optionalAccess', _644 => _644.parts]) || [];
11798
12474
  let text = "";
11799
12475
  for (const part of parts) {
11800
12476
  if (part.thought === true) continue;
@@ -11802,15 +12478,15 @@ function extractDeltaContent(rawJson, apiFormat) {
11802
12478
  }
11803
12479
  return text;
11804
12480
  } else if (apiFormat === "anthropic") {
11805
- return _optionalChain([json, 'access', _595 => _595.delta, 'optionalAccess', _596 => _596.text]) || "";
12481
+ return _optionalChain([json, 'access', _645 => _645.delta, 'optionalAccess', _646 => _646.text]) || "";
11806
12482
  } else {
11807
- return _optionalChain([json, 'access', _597 => _597.choices, 'optionalAccess', _598 => _598[0], 'optionalAccess', _599 => _599.delta, 'optionalAccess', _600 => _600.content]) || "";
12483
+ return _optionalChain([json, 'access', _647 => _647.choices, 'optionalAccess', _648 => _648[0], 'optionalAccess', _649 => _649.delta, 'optionalAccess', _650 => _650.content]) || "";
11808
12484
  }
11809
12485
  }
11810
12486
  function extractDeltaReasoning(rawJson, apiFormat) {
11811
12487
  const json = rawJson;
11812
12488
  if (apiFormat === "google") {
11813
- const parts = _optionalChain([json, 'access', _601 => _601.candidates, 'optionalAccess', _602 => _602[0], 'optionalAccess', _603 => _603.content, 'optionalAccess', _604 => _604.parts]) || [];
12489
+ const parts = _optionalChain([json, 'access', _651 => _651.candidates, 'optionalAccess', _652 => _652[0], 'optionalAccess', _653 => _653.content, 'optionalAccess', _654 => _654.parts]) || [];
11814
12490
  let reasoning = "";
11815
12491
  for (const part of parts) {
11816
12492
  if (part.thought === true && part.text) reasoning += part.text;
@@ -11819,14 +12495,14 @@ function extractDeltaReasoning(rawJson, apiFormat) {
11819
12495
  } else if (apiFormat === "anthropic") {
11820
12496
  return "";
11821
12497
  } else {
11822
- const delta = _optionalChain([json, 'access', _605 => _605.choices, 'optionalAccess', _606 => _606[0], 'optionalAccess', _607 => _607.delta]);
11823
- return (_optionalChain([delta, 'optionalAccess', _608 => _608.thinking, 'optionalAccess', _609 => _609.content]) || "") + (_optionalChain([delta, 'optionalAccess', _610 => _610.reasoning_content]) || "");
12498
+ const delta = _optionalChain([json, 'access', _655 => _655.choices, 'optionalAccess', _656 => _656[0], 'optionalAccess', _657 => _657.delta]);
12499
+ return (_optionalChain([delta, 'optionalAccess', _658 => _658.thinking, 'optionalAccess', _659 => _659.content]) || "") + (_optionalChain([delta, 'optionalAccess', _660 => _660.reasoning_content]) || "");
11824
12500
  }
11825
12501
  }
11826
12502
  function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pendingOpenAIToolCalls) {
11827
12503
  const json = rawJson;
11828
12504
  if (apiFormat === "google") {
11829
- const parts = _optionalChain([json, 'access', _611 => _611.candidates, 'optionalAccess', _612 => _612[0], 'optionalAccess', _613 => _613.content, 'optionalAccess', _614 => _614.parts]) || [];
12505
+ const parts = _optionalChain([json, 'access', _661 => _661.candidates, 'optionalAccess', _662 => _662[0], 'optionalAccess', _663 => _663.content, 'optionalAccess', _664 => _664.parts]) || [];
11830
12506
  for (const part of parts) {
11831
12507
  if (part.functionCall) {
11832
12508
  logger.info("Function call detected", { functionCall: part.functionCall });
@@ -11836,13 +12512,13 @@ function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pend
11836
12512
  args: part.functionCall.args || {}
11837
12513
  };
11838
12514
  toolCalls.push(toolCall);
11839
- _optionalChain([callbacks, 'access', _615 => _615.onToolCall, 'optionalCall', _616 => _616(toolCall)]);
12515
+ _optionalChain([callbacks, 'access', _665 => _665.onToolCall, 'optionalCall', _666 => _666(toolCall)]);
11840
12516
  logger.info("Tool called", { toolName: toolCall.name });
11841
12517
  }
11842
12518
  }
11843
12519
  } else if (apiFormat !== "anthropic") {
11844
- const delta = _optionalChain([json, 'access', _617 => _617.choices, 'optionalAccess', _618 => _618[0], 'optionalAccess', _619 => _619.delta]);
11845
- if (_optionalChain([delta, 'optionalAccess', _620 => _620.tool_calls]) && pendingOpenAIToolCalls) {
12520
+ const delta = _optionalChain([json, 'access', _667 => _667.choices, 'optionalAccess', _668 => _668[0], 'optionalAccess', _669 => _669.delta]);
12521
+ if (_optionalChain([delta, 'optionalAccess', _670 => _670.tool_calls]) && pendingOpenAIToolCalls) {
11846
12522
  for (const tc of delta.tool_calls) {
11847
12523
  const index = _nullishCoalesce(tc.index, () => ( 0));
11848
12524
  let pending = pendingOpenAIToolCalls.get(index);
@@ -11851,8 +12527,8 @@ function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pend
11851
12527
  pendingOpenAIToolCalls.set(index, pending);
11852
12528
  }
11853
12529
  if (tc.id) pending.id = tc.id;
11854
- if (_optionalChain([tc, 'access', _621 => _621.function, 'optionalAccess', _622 => _622.name])) pending.name += tc.function.name;
11855
- if (_optionalChain([tc, 'access', _623 => _623.function, 'optionalAccess', _624 => _624.arguments])) pending.arguments += tc.function.arguments;
12530
+ if (_optionalChain([tc, 'access', _671 => _671.function, 'optionalAccess', _672 => _672.name])) pending.name += tc.function.name;
12531
+ if (_optionalChain([tc, 'access', _673 => _673.function, 'optionalAccess', _674 => _674.arguments])) pending.arguments += tc.function.arguments;
11856
12532
  }
11857
12533
  }
11858
12534
  }
@@ -11867,7 +12543,7 @@ function finalizeOpenAIToolCalls(pendingOpenAIToolCalls, toolCalls, callbacks, l
11867
12543
  args: JSON.parse(pending.arguments || "{}")
11868
12544
  };
11869
12545
  toolCalls.push(toolCall);
11870
- _optionalChain([callbacks, 'access', _625 => _625.onToolCall, 'optionalCall', _626 => _626(toolCall)]);
12546
+ _optionalChain([callbacks, 'access', _675 => _675.onToolCall, 'optionalCall', _676 => _676(toolCall)]);
11871
12547
  logger.info("Tool called (OpenAI)", { toolName: toolCall.name, args: toolCall.args });
11872
12548
  } catch (e) {
11873
12549
  logger.error("Failed to parse OpenAI tool call arguments", e instanceof Error ? e : void 0, {
@@ -11881,38 +12557,38 @@ function finalizeOpenAIToolCalls(pendingOpenAIToolCalls, toolCalls, callbacks, l
11881
12557
  function parseStreamChunk(rawJson, apiFormat, callbacks, logger) {
11882
12558
  const json = rawJson;
11883
12559
  if (apiFormat === "google") {
11884
- const candidate = _optionalChain([json, 'access', _627 => _627.candidates, 'optionalAccess', _628 => _628[0]]);
12560
+ const candidate = _optionalChain([json, 'access', _677 => _677.candidates, 'optionalAccess', _678 => _678[0]]);
11885
12561
  if (!candidate) {
11886
12562
  logger.warn("No candidate found in Gemini response");
11887
12563
  return;
11888
12564
  }
11889
- const parts = _optionalChain([candidate, 'access', _629 => _629.content, 'optionalAccess', _630 => _630.parts]) || [];
12565
+ const parts = _optionalChain([candidate, 'access', _679 => _679.content, 'optionalAccess', _680 => _680.parts]) || [];
11890
12566
  for (const part of parts) {
11891
12567
  if (part.thought === true && part.text) {
11892
- _optionalChain([callbacks, 'access', _631 => _631.onReasoning, 'optionalCall', _632 => _632(part.text)]);
12568
+ _optionalChain([callbacks, 'access', _681 => _681.onReasoning, 'optionalCall', _682 => _682(part.text)]);
11893
12569
  continue;
11894
12570
  } else if (part.thoughtSignature && !part.thought) {
11895
12571
  logger.debug("Gemini returned thoughtSignature without thought content");
11896
12572
  }
11897
12573
  if (part.text) {
11898
- _optionalChain([callbacks, 'access', _633 => _633.onDelta, 'optionalCall', _634 => _634(part.text)]);
12574
+ _optionalChain([callbacks, 'access', _683 => _683.onDelta, 'optionalCall', _684 => _684(part.text)]);
11899
12575
  }
11900
12576
  }
11901
12577
  } else if (apiFormat === "anthropic") {
11902
12578
  const delta = json.delta;
11903
- if (_optionalChain([delta, 'optionalAccess', _635 => _635.text])) {
11904
- _optionalChain([callbacks, 'access', _636 => _636.onDelta, 'optionalCall', _637 => _637(delta.text)]);
12579
+ if (_optionalChain([delta, 'optionalAccess', _685 => _685.text])) {
12580
+ _optionalChain([callbacks, 'access', _686 => _686.onDelta, 'optionalCall', _687 => _687(delta.text)]);
11905
12581
  }
11906
12582
  } else {
11907
- const delta = _optionalChain([json, 'access', _638 => _638.choices, 'optionalAccess', _639 => _639[0], 'optionalAccess', _640 => _640.delta]);
11908
- if (_optionalChain([delta, 'optionalAccess', _641 => _641.content])) {
11909
- _optionalChain([callbacks, 'access', _642 => _642.onDelta, 'optionalCall', _643 => _643(delta.content)]);
12583
+ const delta = _optionalChain([json, 'access', _688 => _688.choices, 'optionalAccess', _689 => _689[0], 'optionalAccess', _690 => _690.delta]);
12584
+ if (_optionalChain([delta, 'optionalAccess', _691 => _691.content])) {
12585
+ _optionalChain([callbacks, 'access', _692 => _692.onDelta, 'optionalCall', _693 => _693(delta.content)]);
11910
12586
  }
11911
- if (_optionalChain([delta, 'optionalAccess', _644 => _644.thinking, 'optionalAccess', _645 => _645.content])) {
11912
- _optionalChain([callbacks, 'access', _646 => _646.onReasoning, 'optionalCall', _647 => _647(delta.thinking.content)]);
12587
+ if (_optionalChain([delta, 'optionalAccess', _694 => _694.thinking, 'optionalAccess', _695 => _695.content])) {
12588
+ _optionalChain([callbacks, 'access', _696 => _696.onReasoning, 'optionalCall', _697 => _697(delta.thinking.content)]);
11913
12589
  }
11914
- if (_optionalChain([delta, 'optionalAccess', _648 => _648.reasoning_content])) {
11915
- _optionalChain([callbacks, 'access', _649 => _649.onReasoning, 'optionalCall', _650 => _650(delta.reasoning_content)]);
12590
+ if (_optionalChain([delta, 'optionalAccess', _698 => _698.reasoning_content])) {
12591
+ _optionalChain([callbacks, 'access', _699 => _699.onReasoning, 'optionalCall', _700 => _700(delta.reasoning_content)]);
11916
12592
  }
11917
12593
  }
11918
12594
  }
@@ -11925,7 +12601,7 @@ function buildIterationBlocks(iteration, content, reasoning, blocks, callbacks)
11925
12601
  content: reasoning
11926
12602
  };
11927
12603
  blocks.push(thinkingBlock);
11928
- _optionalChain([callbacks, 'access', _651 => _651.onBlock, 'optionalCall', _652 => _652(thinkingBlock)]);
12604
+ _optionalChain([callbacks, 'access', _701 => _701.onBlock, 'optionalCall', _702 => _702(thinkingBlock)]);
11929
12605
  }
11930
12606
  if (content && content.trim()) {
11931
12607
  const textBlock = {
@@ -11934,7 +12610,7 @@ function buildIterationBlocks(iteration, content, reasoning, blocks, callbacks)
11934
12610
  content
11935
12611
  };
11936
12612
  blocks.push(textBlock);
11937
- _optionalChain([callbacks, 'access', _653 => _653.onBlock, 'optionalCall', _654 => _654(textBlock)]);
12613
+ _optionalChain([callbacks, 'access', _703 => _703.onBlock, 'optionalCall', _704 => _704(textBlock)]);
11938
12614
  }
11939
12615
  }
11940
12616
  async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbacks, logger, builtinExecutor) {
@@ -11949,7 +12625,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
11949
12625
  status: "running"
11950
12626
  };
11951
12627
  blocks.push(toolUseBlock);
11952
- _optionalChain([callbacks, 'access', _655 => _655.onBlock, 'optionalCall', _656 => _656(toolUseBlock)]);
12628
+ _optionalChain([callbacks, 'access', _705 => _705.onBlock, 'optionalCall', _706 => _706(toolUseBlock)]);
11953
12629
  try {
11954
12630
  logger.info("Executing tool", { toolName: toolCall.name });
11955
12631
  const mcpTool = mcpTools.find((t) => t.id === toolCall.name);
@@ -11972,8 +12648,8 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
11972
12648
  result = { isError: true, content: [{ type: "text", text: "MCP service not available" }] };
11973
12649
  }
11974
12650
  logger.info("Tool result received", { result });
11975
- _optionalChain([callbacks, 'access', _657 => _657.onToolResult, 'optionalCall', _658 => _658(toolCall.id, result)]);
11976
- const resultText = _optionalChain([result, 'access', _659 => _659.content, 'optionalAccess', _660 => _660[0], 'optionalAccess', _661 => _661.text]) || JSON.stringify(result);
12651
+ _optionalChain([callbacks, 'access', _707 => _707.onToolResult, 'optionalCall', _708 => _708(toolCall.id, result)]);
12652
+ const resultText = _optionalChain([result, 'access', _709 => _709.content, 'optionalAccess', _710 => _710[0], 'optionalAccess', _711 => _711.text]) || JSON.stringify(result);
11977
12653
  const toolResultBlock = {
11978
12654
  id: `${toolCall.id}_result`,
11979
12655
  type: "tool_result",
@@ -11983,11 +12659,11 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
11983
12659
  isError: result.isError
11984
12660
  };
11985
12661
  blocks.push(toolResultBlock);
11986
- _optionalChain([callbacks, 'access', _662 => _662.onBlock, 'optionalCall', _663 => _663(toolResultBlock)]);
12662
+ _optionalChain([callbacks, 'access', _712 => _712.onBlock, 'optionalCall', _713 => _713(toolResultBlock)]);
11987
12663
  const toolUseBlockRef = blocks.find((b) => b.id === `${toolCall.id}_use`);
11988
12664
  if (toolUseBlockRef && toolUseBlockRef.type === "tool_use") {
11989
12665
  toolUseBlockRef.status = result.isError ? "error" : "completed";
11990
- _optionalChain([callbacks, 'access', _664 => _664.onBlock, 'optionalCall', _665 => _665({ ...toolUseBlockRef })]);
12666
+ _optionalChain([callbacks, 'access', _714 => _714.onBlock, 'optionalCall', _715 => _715({ ...toolUseBlockRef })]);
11991
12667
  }
11992
12668
  toolResults.push({ toolCall, result });
11993
12669
  } catch (error) {
@@ -11997,7 +12673,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
11997
12673
  isError: true,
11998
12674
  content: [{ type: "text", text: `Error: ${errorMessage}` }]
11999
12675
  };
12000
- _optionalChain([callbacks, 'access', _666 => _666.onToolResult, 'optionalCall', _667 => _667(toolCall.id, errorResult)]);
12676
+ _optionalChain([callbacks, 'access', _716 => _716.onToolResult, 'optionalCall', _717 => _717(toolCall.id, errorResult)]);
12001
12677
  const errorToolResultBlock = {
12002
12678
  id: `${toolCall.id}_result`,
12003
12679
  type: "tool_result",
@@ -12007,11 +12683,11 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
12007
12683
  isError: true
12008
12684
  };
12009
12685
  blocks.push(errorToolResultBlock);
12010
- _optionalChain([callbacks, 'access', _668 => _668.onBlock, 'optionalCall', _669 => _669(errorToolResultBlock)]);
12686
+ _optionalChain([callbacks, 'access', _718 => _718.onBlock, 'optionalCall', _719 => _719(errorToolResultBlock)]);
12011
12687
  const errorToolUseBlockRef = blocks.find((b) => b.id === `${toolCall.id}_use`);
12012
12688
  if (errorToolUseBlockRef && errorToolUseBlockRef.type === "tool_use") {
12013
12689
  errorToolUseBlockRef.status = "error";
12014
- _optionalChain([callbacks, 'access', _670 => _670.onBlock, 'optionalCall', _671 => _671({ ...errorToolUseBlockRef })]);
12690
+ _optionalChain([callbacks, 'access', _720 => _720.onBlock, 'optionalCall', _721 => _721({ ...errorToolUseBlockRef })]);
12015
12691
  }
12016
12692
  toolResults.push({ toolCall, result: errorResult });
12017
12693
  }
@@ -12021,7 +12697,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
12021
12697
  function mapToolArguments(args, mcpTool, logger) {
12022
12698
  const mappedArgs = { ...args };
12023
12699
  const toolSchema = mcpTool.inputSchema;
12024
- if (_optionalChain([toolSchema, 'optionalAccess', _672 => _672.properties])) {
12700
+ if (_optionalChain([toolSchema, 'optionalAccess', _722 => _722.properties])) {
12025
12701
  const expectedParams = Object.keys(toolSchema.properties);
12026
12702
  const paramMappings = {
12027
12703
  "search_query": ["query", "q", "searchQuery", "search"],
@@ -12055,25 +12731,25 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
12055
12731
  options.providerId,
12056
12732
  options.model
12057
12733
  );
12058
- const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _673 => _673.actualProviderId]) || options.providerId;
12059
- const actualModel = _optionalChain([routedInfo, 'optionalAccess', _674 => _674.actualModelId]) || options.model;
12734
+ const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _723 => _723.actualProviderId]) || options.providerId;
12735
+ const actualModel = _optionalChain([routedInfo, 'optionalAccess', _724 => _724.actualModelId]) || options.model;
12060
12736
  const provider = await getProvider(actualProviderId);
12061
12737
  if (!provider) {
12062
- _optionalChain([callbacks, 'access', _675 => _675.onError, 'optionalCall', _676 => _676(`Provider not found: ${actualProviderId}`)]);
12738
+ _optionalChain([callbacks, 'access', _725 => _725.onError, 'optionalCall', _726 => _726(`Provider not found: ${actualProviderId}`)]);
12063
12739
  return;
12064
12740
  }
12065
12741
  if (!provider.enabled) {
12066
- _optionalChain([callbacks, 'access', _677 => _677.onError, 'optionalCall', _678 => _678(`Provider is disabled: ${provider.name}`)]);
12742
+ _optionalChain([callbacks, 'access', _727 => _727.onError, 'optionalCall', _728 => _728(`Provider is disabled: ${provider.name}`)]);
12067
12743
  return;
12068
12744
  }
12069
12745
  const { apiKey: effectiveKey } = _chunkA2YMUCBTcjs.resolveProviderEndpoint.call(void 0, provider);
12070
12746
  const apiKey = resolveApiKey2(effectiveKey);
12071
12747
  if (!apiKey) {
12072
- _optionalChain([callbacks, 'access', _679 => _679.onError, 'optionalCall', _680 => _680("API key not configured")]);
12748
+ _optionalChain([callbacks, 'access', _729 => _729.onError, 'optionalCall', _730 => _730("API key not configured")]);
12073
12749
  return;
12074
12750
  }
12075
12751
  const messageId = `msg_${Date.now()}_${Math.random().toString(36).slice(2)}`;
12076
- _optionalChain([callbacks, 'access', _681 => _681.onStart, 'optionalCall', _682 => _682(messageId)]);
12752
+ _optionalChain([callbacks, 'access', _731 => _731.onStart, 'optionalCall', _732 => _732(messageId)]);
12077
12753
  const globalParams = await llmConfig.getGlobalModelParameters();
12078
12754
  const MAX_ITERATIONS = _nullishCoalesce(globalParams.toolMaxTurns, () => ( 100));
12079
12755
  let iteration = 0;
@@ -12120,12 +12796,12 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
12120
12796
  });
12121
12797
  if (!response.ok) {
12122
12798
  const errorText = await response.text();
12123
- _optionalChain([callbacks, 'access', _683 => _683.onError, 'optionalCall', _684 => _684(`API error (${response.status}): ${errorText}`)]);
12799
+ _optionalChain([callbacks, 'access', _733 => _733.onError, 'optionalCall', _734 => _734(`API error (${response.status}): ${errorText}`)]);
12124
12800
  return;
12125
12801
  }
12126
- const reader = _optionalChain([response, 'access', _685 => _685.body, 'optionalAccess', _686 => _686.getReader, 'call', _687 => _687()]);
12802
+ const reader = _optionalChain([response, 'access', _735 => _735.body, 'optionalAccess', _736 => _736.getReader, 'call', _737 => _737()]);
12127
12803
  if (!reader) {
12128
- _optionalChain([callbacks, 'access', _688 => _688.onError, 'optionalCall', _689 => _689("No response body")]);
12804
+ _optionalChain([callbacks, 'access', _738 => _738.onError, 'optionalCall', _739 => _739("No response body")]);
12129
12805
  return;
12130
12806
  }
12131
12807
  const decoder = new TextDecoder();
@@ -12158,7 +12834,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
12158
12834
  logger.debug("Parsed JSON", { json });
12159
12835
  if (json.error) {
12160
12836
  logger.error("API Error", void 0, { error: json.error });
12161
- _optionalChain([callbacks, 'access', _690 => _690.onError, 'optionalCall', _691 => _691(`API Error: ${json.error.message || JSON.stringify(json.error)}`)]);
12837
+ _optionalChain([callbacks, 'access', _740 => _740.onError, 'optionalCall', _741 => _741(`API Error: ${json.error.message || JSON.stringify(json.error)}`)]);
12162
12838
  return;
12163
12839
  }
12164
12840
  parseStreamChunk(json, apiFormat, callbacks, logger);
@@ -12191,7 +12867,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
12191
12867
  toolCallsLength: toolCalls.length,
12192
12868
  executableToolCallsLength: executableToolCalls.length,
12193
12869
  hasMcpTools: !!options.mcpTools,
12194
- mcpToolsLength: _optionalChain([options, 'access', _692 => _692.mcpTools, 'optionalAccess', _693 => _693.length]),
12870
+ mcpToolsLength: _optionalChain([options, 'access', _742 => _742.mcpTools, 'optionalAccess', _743 => _743.length]),
12195
12871
  hasMcpService: !!mcpService
12196
12872
  });
12197
12873
  if (executableToolCalls.length > 0 && options.mcpTools && (mcpService || builtinExecutor)) {
@@ -12212,7 +12888,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
12212
12888
  builtinExecutor
12213
12889
  );
12214
12890
  const toolResultsText = toolResults.map(({ toolCall, result }) => {
12215
- const resultText = typeof result === "string" ? result : _optionalChain([result, 'access', _694 => _694.content, 'optionalAccess', _695 => _695[0], 'optionalAccess', _696 => _696.text]) || JSON.stringify(result);
12891
+ const resultText = typeof result === "string" ? result : _optionalChain([result, 'access', _744 => _744.content, 'optionalAccess', _745 => _745[0], 'optionalAccess', _746 => _746.text]) || JSON.stringify(result);
12216
12892
  return `Tool ${toolCall.name} result:
12217
12893
  ${resultText}`;
12218
12894
  }).join("\n\n");
@@ -12230,12 +12906,12 @@ ${resultText}`;
12230
12906
  }
12231
12907
  } catch (streamError) {
12232
12908
  logger.error("Stream processing error", streamError instanceof Error ? streamError : void 0);
12233
- _optionalChain([callbacks, 'access', _697 => _697.onError, 'optionalCall', _698 => _698(`Stream error: ${streamError instanceof Error ? streamError.message : "Unknown error"}`)]);
12909
+ _optionalChain([callbacks, 'access', _747 => _747.onError, 'optionalCall', _748 => _748(`Stream error: ${streamError instanceof Error ? streamError.message : "Unknown error"}`)]);
12234
12910
  return;
12235
12911
  }
12236
12912
  }
12237
12913
  logger.info("Sending final callback", { blocksCount: blocks.length });
12238
- _optionalChain([callbacks, 'access', _699 => _699.onDone, 'optionalCall', _700 => _700({
12914
+ _optionalChain([callbacks, 'access', _749 => _749.onDone, 'optionalCall', _750 => _750({
12239
12915
  id: messageId,
12240
12916
  role: "assistant",
12241
12917
  content: finalContent,
@@ -12246,7 +12922,7 @@ ${resultText}`;
12246
12922
  } catch (error) {
12247
12923
  logger.error("Error in streamWithTools", error instanceof Error ? error : void 0);
12248
12924
  const message = error instanceof Error ? error.message : "Unknown error";
12249
- _optionalChain([callbacks, 'access', _701 => _701.onError, 'optionalCall', _702 => _702(message)]);
12925
+ _optionalChain([callbacks, 'access', _751 => _751.onError, 'optionalCall', _752 => _752(message)]);
12250
12926
  }
12251
12927
  }
12252
12928
 
@@ -12297,8 +12973,8 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
12297
12973
  options.providerId,
12298
12974
  options.model
12299
12975
  );
12300
- const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _703 => _703.actualProviderId]) || options.providerId;
12301
- const actualModel = _optionalChain([routedInfo, 'optionalAccess', _704 => _704.actualModelId]) || options.model;
12976
+ const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _753 => _753.actualProviderId]) || options.providerId;
12977
+ const actualModel = _optionalChain([routedInfo, 'optionalAccess', _754 => _754.actualModelId]) || options.model;
12302
12978
  const provider = await getProvider(actualProviderId);
12303
12979
  if (!provider) {
12304
12980
  return { success: false, error: `Provider not found: ${actualProviderId}` };
@@ -12375,18 +13051,18 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
12375
13051
  { endpointTransformer: void 0 }
12376
13052
  );
12377
13053
  const data = await transformedResponse2.json();
12378
- const choice = _optionalChain([data, 'access', _705 => _705.choices, 'optionalAccess', _706 => _706[0]]);
13054
+ const choice = _optionalChain([data, 'access', _755 => _755.choices, 'optionalAccess', _756 => _756[0]]);
12379
13055
  if (!choice) {
12380
13056
  return { success: false, error: "No choices in response" };
12381
13057
  }
12382
- const rawToolCalls = _optionalChain([choice, 'access', _707 => _707.message, 'optionalAccess', _708 => _708.tool_calls]);
12383
- const toolCalls = _optionalChain([rawToolCalls, 'optionalAccess', _709 => _709.map, 'call', _710 => _710((tc) => ({
13058
+ const rawToolCalls = _optionalChain([choice, 'access', _757 => _757.message, 'optionalAccess', _758 => _758.tool_calls]);
13059
+ const toolCalls = _optionalChain([rawToolCalls, 'optionalAccess', _759 => _759.map, 'call', _760 => _760((tc) => ({
12384
13060
  id: tc.id,
12385
13061
  name: tc.function.name,
12386
13062
  args: typeof tc.function.arguments === "string" ? JSON.parse(tc.function.arguments) : tc.function.arguments
12387
13063
  }))]);
12388
13064
  const tapped = readUsageFromOpenAIResponse(data.usage);
12389
- if (_optionalChain([recording, 'optionalAccess', _711 => _711.recorder]) && tapped) {
13065
+ if (_optionalChain([recording, 'optionalAccess', _761 => _761.recorder]) && tapped) {
12390
13066
  recording.recorder.record({
12391
13067
  messageId: _nullishCoalesce(options.messageId, () => ( null)),
12392
13068
  parentMessageId: _nullishCoalesce(options.parentMessageId, () => ( null)),
@@ -12404,9 +13080,9 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
12404
13080
  message: {
12405
13081
  id: `msg_${Date.now()}`,
12406
13082
  role: "assistant",
12407
- content: _optionalChain([choice, 'access', _712 => _712.message, 'optionalAccess', _713 => _713.content]) || "",
13083
+ content: _optionalChain([choice, 'access', _762 => _762.message, 'optionalAccess', _763 => _763.content]) || "",
12408
13084
  timestamp: Date.now(),
12409
- thinking: data.reasoning_content || _optionalChain([choice, 'access', _714 => _714.message, 'optionalAccess', _715 => _715.thinking, 'optionalAccess', _716 => _716.content]) ? { content: data.reasoning_content || _optionalChain([choice, 'access', _717 => _717.message, 'optionalAccess', _718 => _718.thinking, 'optionalAccess', _719 => _719.content]) || "", signature: _optionalChain([choice, 'access', _720 => _720.message, 'optionalAccess', _721 => _721.thinking, 'optionalAccess', _722 => _722.signature]) } : void 0,
13085
+ thinking: data.reasoning_content || _optionalChain([choice, 'access', _764 => _764.message, 'optionalAccess', _765 => _765.thinking, 'optionalAccess', _766 => _766.content]) ? { content: data.reasoning_content || _optionalChain([choice, 'access', _767 => _767.message, 'optionalAccess', _768 => _768.thinking, 'optionalAccess', _769 => _769.content]) || "", signature: _optionalChain([choice, 'access', _770 => _770.message, 'optionalAccess', _771 => _771.thinking, 'optionalAccess', _772 => _772.signature]) } : void 0,
12410
13086
  toolCalls
12411
13087
  },
12412
13088
  usage: data.usage ? {
@@ -12427,21 +13103,21 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
12427
13103
  options.providerId,
12428
13104
  options.model
12429
13105
  );
12430
- const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _723 => _723.actualProviderId]) || options.providerId;
12431
- const actualModel = _optionalChain([routedInfo, 'optionalAccess', _724 => _724.actualModelId]) || options.model;
13106
+ const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _773 => _773.actualProviderId]) || options.providerId;
13107
+ const actualModel = _optionalChain([routedInfo, 'optionalAccess', _774 => _774.actualModelId]) || options.model;
12432
13108
  const provider = await getProvider(actualProviderId);
12433
13109
  if (!provider) {
12434
- _optionalChain([callbacks, 'access', _725 => _725.onError, 'optionalCall', _726 => _726(`Provider not found: ${actualProviderId}`)]);
13110
+ _optionalChain([callbacks, 'access', _775 => _775.onError, 'optionalCall', _776 => _776(`Provider not found: ${actualProviderId}`)]);
12435
13111
  return;
12436
13112
  }
12437
13113
  if (!provider.enabled) {
12438
- _optionalChain([callbacks, 'access', _727 => _727.onError, 'optionalCall', _728 => _728(`Provider is disabled: ${provider.name}`)]);
13114
+ _optionalChain([callbacks, 'access', _777 => _777.onError, 'optionalCall', _778 => _778(`Provider is disabled: ${provider.name}`)]);
12439
13115
  return;
12440
13116
  }
12441
13117
  const { apiKey: effectiveKey } = _chunkA2YMUCBTcjs.resolveProviderEndpoint.call(void 0, provider);
12442
13118
  const apiKey = resolveApiKey2(effectiveKey);
12443
13119
  if (!apiKey) {
12444
- _optionalChain([callbacks, 'access', _729 => _729.onError, 'optionalCall', _730 => _730("API key not configured")]);
13120
+ _optionalChain([callbacks, 'access', _779 => _779.onError, 'optionalCall', _780 => _780("API key not configured")]);
12445
13121
  return;
12446
13122
  }
12447
13123
  const { chain, hasTransformers } = await resolveChainWithMain(
@@ -12453,7 +13129,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
12453
13129
  return completeStreamFallback(options, callbacks);
12454
13130
  }
12455
13131
  const messageId = `msg_${Date.now()}`;
12456
- _optionalChain([callbacks, 'access', _731 => _731.onStart, 'optionalCall', _732 => _732(messageId)]);
13132
+ _optionalChain([callbacks, 'access', _781 => _781.onStart, 'optionalCall', _782 => _782(messageId)]);
12457
13133
  const unifiedRequest = buildUnifiedCompletionRequest(actualModel, options, true);
12458
13134
  const transformerProvider = {
12459
13135
  name: provider.name,
@@ -12493,7 +13169,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
12493
13169
  });
12494
13170
  if (!response.ok) {
12495
13171
  const errorText = await response.text();
12496
- _optionalChain([callbacks, 'access', _733 => _733.onError, 'optionalCall', _734 => _734(`API error (${response.status}): ${errorText}`)]);
13172
+ _optionalChain([callbacks, 'access', _783 => _783.onError, 'optionalCall', _784 => _784(`API error (${response.status}): ${errorText}`)]);
12497
13173
  return;
12498
13174
  }
12499
13175
  const transformedResponse2 = await executor.executeResponseChain(
@@ -12503,9 +13179,9 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
12503
13179
  chain,
12504
13180
  { endpointTransformer: void 0 }
12505
13181
  );
12506
- const reader = _optionalChain([transformedResponse2, 'access', _735 => _735.body, 'optionalAccess', _736 => _736.getReader, 'call', _737 => _737()]);
13182
+ const reader = _optionalChain([transformedResponse2, 'access', _785 => _785.body, 'optionalAccess', _786 => _786.getReader, 'call', _787 => _787()]);
12507
13183
  if (!reader) {
12508
- _optionalChain([callbacks, 'access', _738 => _738.onError, 'optionalCall', _739 => _739("No response body")]);
13184
+ _optionalChain([callbacks, 'access', _788 => _788.onError, 'optionalCall', _789 => _789("No response body")]);
12509
13185
  return;
12510
13186
  }
12511
13187
  const decoder = new TextDecoder();
@@ -12523,22 +13199,22 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
12523
13199
  if (data === "[DONE]") continue;
12524
13200
  try {
12525
13201
  const json = JSON.parse(data);
12526
- const delta = _optionalChain([json, 'access', _740 => _740.choices, 'optionalAccess', _741 => _741[0], 'optionalAccess', _742 => _742.delta]);
12527
- if (_optionalChain([delta, 'optionalAccess', _743 => _743.content])) {
13202
+ const delta = _optionalChain([json, 'access', _790 => _790.choices, 'optionalAccess', _791 => _791[0], 'optionalAccess', _792 => _792.delta]);
13203
+ if (_optionalChain([delta, 'optionalAccess', _793 => _793.content])) {
12528
13204
  content += delta.content;
12529
- _optionalChain([callbacks, 'access', _744 => _744.onDelta, 'optionalCall', _745 => _745(delta.content)]);
13205
+ _optionalChain([callbacks, 'access', _794 => _794.onDelta, 'optionalCall', _795 => _795(delta.content)]);
12530
13206
  }
12531
- if (_optionalChain([delta, 'optionalAccess', _746 => _746.thinking, 'optionalAccess', _747 => _747.content])) {
13207
+ if (_optionalChain([delta, 'optionalAccess', _796 => _796.thinking, 'optionalAccess', _797 => _797.content])) {
12532
13208
  reasoning += delta.thinking.content;
12533
- _optionalChain([callbacks, 'access', _748 => _748.onReasoning, 'optionalCall', _749 => _749(delta.thinking.content)]);
13209
+ _optionalChain([callbacks, 'access', _798 => _798.onReasoning, 'optionalCall', _799 => _799(delta.thinking.content)]);
12534
13210
  }
12535
- if (_optionalChain([delta, 'optionalAccess', _750 => _750.reasoning_content])) {
13211
+ if (_optionalChain([delta, 'optionalAccess', _800 => _800.reasoning_content])) {
12536
13212
  reasoning += delta.reasoning_content;
12537
- _optionalChain([callbacks, 'access', _751 => _751.onReasoning, 'optionalCall', _752 => _752(delta.reasoning_content)]);
13213
+ _optionalChain([callbacks, 'access', _801 => _801.onReasoning, 'optionalCall', _802 => _802(delta.reasoning_content)]);
12538
13214
  }
12539
13215
  if (json.usage) {
12540
13216
  const tapped = readUsageFromOpenAIResponse(json.usage);
12541
- if (_optionalChain([recording, 'optionalAccess', _753 => _753.recorder]) && tapped) {
13217
+ if (_optionalChain([recording, 'optionalAccess', _803 => _803.recorder]) && tapped) {
12542
13218
  recording.recorder.record({
12543
13219
  messageId: _nullishCoalesce(options.messageId, () => ( null)),
12544
13220
  parentMessageId: _nullishCoalesce(options.parentMessageId, () => ( null)),
@@ -12551,7 +13227,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
12551
13227
  rawUsage: json.usage
12552
13228
  });
12553
13229
  }
12554
- _optionalChain([callbacks, 'access', _754 => _754.onDone, 'optionalCall', _755 => _755(
13230
+ _optionalChain([callbacks, 'access', _804 => _804.onDone, 'optionalCall', _805 => _805(
12555
13231
  {
12556
13232
  id: messageId,
12557
13233
  role: "assistant",
@@ -12572,7 +13248,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
12572
13248
  }
12573
13249
  }
12574
13250
  }
12575
- _optionalChain([callbacks, 'access', _756 => _756.onDone, 'optionalCall', _757 => _757({
13251
+ _optionalChain([callbacks, 'access', _806 => _806.onDone, 'optionalCall', _807 => _807({
12576
13252
  id: messageId,
12577
13253
  role: "assistant",
12578
13254
  content,
@@ -12584,7 +13260,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
12584
13260
  }
12585
13261
  } catch (error) {
12586
13262
  const message = error instanceof Error ? error.message : "Unknown error";
12587
- _optionalChain([callbacks, 'access', _758 => _758.onError, 'optionalCall', _759 => _759(message)]);
13263
+ _optionalChain([callbacks, 'access', _808 => _808.onError, 'optionalCall', _809 => _809(message)]);
12588
13264
  }
12589
13265
  }
12590
13266
 
@@ -12651,8 +13327,8 @@ var CompletionService = (_class21 = class {
12651
13327
  options.providerId,
12652
13328
  options.model
12653
13329
  );
12654
- const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _760 => _760.actualProviderId]) || options.providerId;
12655
- const actualModel = _optionalChain([routedInfo, 'optionalAccess', _761 => _761.actualModelId]) || options.model;
13330
+ const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _810 => _810.actualProviderId]) || options.providerId;
13331
+ const actualModel = _optionalChain([routedInfo, 'optionalAccess', _811 => _811.actualModelId]) || options.model;
12656
13332
  const provider = await this.getProvider(actualProviderId);
12657
13333
  if (!provider) {
12658
13334
  return { success: false, error: `Provider not found: ${actualProviderId}` };
@@ -12685,7 +13361,7 @@ var CompletionService = (_class21 = class {
12685
13361
  this.apiKeyPool.reportSuccess(options.sessionId);
12686
13362
  }
12687
13363
  if (result.success && result.usage && options.sessionId) {
12688
- _optionalChain([this, 'access', _762 => _762.usageEventSink, 'optionalAccess', _763 => _763.emit, 'call', _764 => _764({
13364
+ _optionalChain([this, 'access', _812 => _812.usageEventSink, 'optionalAccess', _813 => _813.emit, 'call', _814 => _814({
12689
13365
  sessionId: options.sessionId,
12690
13366
  modelId: actualModel,
12691
13367
  usage: result.usage,
@@ -12714,8 +13390,8 @@ var CompletionService = (_class21 = class {
12714
13390
  options.model
12715
13391
  );
12716
13392
  this.logger.debug("Resolved routed model", { routedInfo });
12717
- const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _765 => _765.actualProviderId]) || options.providerId;
12718
- const actualModel = _optionalChain([routedInfo, 'optionalAccess', _766 => _766.actualModelId]) || options.model;
13393
+ const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _815 => _815.actualProviderId]) || options.providerId;
13394
+ const actualModel = _optionalChain([routedInfo, 'optionalAccess', _816 => _816.actualModelId]) || options.model;
12719
13395
  this.logger.debug("Resolved provider and model", { actualProviderId, actualModel });
12720
13396
  const provider = await this.getProvider(actualProviderId);
12721
13397
  this.logger.debug("Retrieved provider", provider ? {
@@ -12727,22 +13403,22 @@ var CompletionService = (_class21 = class {
12727
13403
  enabled: provider.enabled
12728
13404
  } : { error: "Provider not found" });
12729
13405
  if (!provider) {
12730
- _optionalChain([callbacks, 'access', _767 => _767.onError, 'optionalCall', _768 => _768(`Provider not found: ${actualProviderId}`)]);
13406
+ _optionalChain([callbacks, 'access', _817 => _817.onError, 'optionalCall', _818 => _818(`Provider not found: ${actualProviderId}`)]);
12731
13407
  return;
12732
13408
  }
12733
13409
  if (!provider.enabled) {
12734
- _optionalChain([callbacks, 'access', _769 => _769.onError, 'optionalCall', _770 => _770(`Provider is disabled: ${provider.name}`)]);
13410
+ _optionalChain([callbacks, 'access', _819 => _819.onError, 'optionalCall', _820 => _820(`Provider is disabled: ${provider.name}`)]);
12735
13411
  return;
12736
13412
  }
12737
13413
  const apiKey = await this.resolveApiKeyForRequest(provider, actualProviderId, options.sessionId);
12738
13414
  if (!apiKey) {
12739
- _optionalChain([callbacks, 'access', _771 => _771.onError, 'optionalCall', _772 => _772("API key not configured")]);
13415
+ _optionalChain([callbacks, 'access', _821 => _821.onError, 'optionalCall', _822 => _822("API key not configured")]);
12740
13416
  return;
12741
13417
  }
12742
13418
  const apiFormat = _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider);
12743
13419
  this.logger.info("Using API format for stream", { apiFormat });
12744
13420
  const messageId = `msg_${Date.now()}`;
12745
- _optionalChain([callbacks, 'access', _773 => _773.onStart, 'optionalCall', _774 => _774(messageId)]);
13421
+ _optionalChain([callbacks, 'access', _823 => _823.onStart, 'optionalCall', _824 => _824(messageId)]);
12746
13422
  const resolvedOptions = { ...options, model: actualModel };
12747
13423
  if (options.sessionId) {
12748
13424
  const sid = options.sessionId;
@@ -12751,14 +13427,14 @@ var CompletionService = (_class21 = class {
12751
13427
  ...callbacks,
12752
13428
  onDone: (message, usage, metrics) => {
12753
13429
  if (usage) {
12754
- _optionalChain([this, 'access', _775 => _775.usageEventSink, 'optionalAccess', _776 => _776.emit, 'call', _777 => _777({
13430
+ _optionalChain([this, 'access', _825 => _825.usageEventSink, 'optionalAccess', _826 => _826.emit, 'call', _827 => _827({
12755
13431
  sessionId: sid,
12756
13432
  modelId: actualModel,
12757
13433
  usage,
12758
13434
  engineOrigin: "completion"
12759
13435
  })]);
12760
13436
  }
12761
- _optionalChain([userOnDone, 'optionalCall', _778 => _778(message, usage, metrics)]);
13437
+ _optionalChain([userOnDone, 'optionalCall', _828 => _828(message, usage, metrics)]);
12762
13438
  }
12763
13439
  };
12764
13440
  }
@@ -12774,11 +13450,11 @@ var CompletionService = (_class21 = class {
12774
13450
  retryState.error = { status, message: error };
12775
13451
  return;
12776
13452
  }
12777
- _optionalChain([callbacks, 'access', _779 => _779.onError, 'optionalCall', _780 => _780(error)]);
13453
+ _optionalChain([callbacks, 'access', _829 => _829.onError, 'optionalCall', _830 => _830(error)]);
12778
13454
  },
12779
13455
  onDone: (message, usage, metrics) => {
12780
13456
  this.apiKeyPool.reportSuccess(options.sessionId);
12781
- _optionalChain([callbacks, 'access', _781 => _781.onDone, 'optionalCall', _782 => _782(message, usage, metrics)]);
13457
+ _optionalChain([callbacks, 'access', _831 => _831.onDone, 'optionalCall', _832 => _832(message, usage, metrics)]);
12782
13458
  }
12783
13459
  };
12784
13460
  await this.callStreamHandler(apiFormat, provider, apiKey, resolvedOptions, messageId, interceptCallbacks);
@@ -12799,7 +13475,7 @@ var CompletionService = (_class21 = class {
12799
13475
  // don't fire onStart again
12800
13476
  });
12801
13477
  } else {
12802
- _optionalChain([callbacks, 'access', _783 => _783.onError, 'optionalCall', _784 => _784(retryState.error.message)]);
13478
+ _optionalChain([callbacks, 'access', _833 => _833.onError, 'optionalCall', _834 => _834(retryState.error.message)]);
12803
13479
  }
12804
13480
  }
12805
13481
  } else {
@@ -12812,7 +13488,7 @@ var CompletionService = (_class21 = class {
12812
13488
  } catch (error) {
12813
13489
  const message = error instanceof Error ? error.message : "Unknown error";
12814
13490
  this.logger.error("Stream completion error", error instanceof Error ? error : void 0, { message });
12815
- _optionalChain([callbacks, 'access', _785 => _785.onError, 'optionalCall', _786 => _786(message)]);
13491
+ _optionalChain([callbacks, 'access', _835 => _835.onError, 'optionalCall', _836 => _836(message)]);
12816
13492
  }
12817
13493
  }
12818
13494
  /**
@@ -12852,7 +13528,7 @@ var CompletionService = (_class21 = class {
12852
13528
  return {
12853
13529
  success: true,
12854
13530
  message: "Connection successful",
12855
- response: _optionalChain([result, 'access', _787 => _787.message, 'optionalAccess', _788 => _788.content]) || "",
13531
+ response: _optionalChain([result, 'access', _837 => _837.message, 'optionalAccess', _838 => _838.content]) || "",
12856
13532
  model: modelId,
12857
13533
  durationMs
12858
13534
  };
@@ -12917,7 +13593,7 @@ ${description}`;
12917
13593
  * 3. Legacy single key from provider config
12918
13594
  */
12919
13595
  async resolveApiKeyForRequest(provider, providerId, sessionId) {
12920
- if (_optionalChain([provider, 'access', _789 => _789.codingPlan, 'optionalAccess', _790 => _790.enabled]) && provider.codingPlan.apiKey) {
13596
+ if (_optionalChain([provider, 'access', _839 => _839.codingPlan, 'optionalAccess', _840 => _840.enabled]) && provider.codingPlan.apiKey) {
12921
13597
  return this.resolveApiKey(provider.codingPlan.apiKey);
12922
13598
  }
12923
13599
  if (this.apiKeyPool) {
@@ -13227,4 +13903,9 @@ ${description}`;
13227
13903
 
13228
13904
 
13229
13905
 
13230
- 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.getSharedExecutor = getSharedExecutor; exports.getResponsesEndpointTransformer = getResponsesEndpointTransformer; exports.getAnthropicEndpointTransformer = getAnthropicEndpointTransformer; exports.getGeminiEndpointTransformer = getGeminiEndpointTransformer; exports.readBody = readBody; exports.cancelDiscardedResponse = cancelDiscardedResponse; exports.projectUpstreamResponseHeaders = projectUpstreamResponseHeaders; exports.relayResponse = relayResponse; exports.aggregateAnthropicSseToJsonBody = aggregateAnthropicSseToJsonBody; exports.writeError = writeError; exports.writeBoundAccountError = writeBoundAccountError; exports.resolvePoolBoundKey = resolvePoolBoundKey; exports.DEFAULT_ROUTE_IDLE_MS = DEFAULT_ROUTE_IDLE_MS; exports.ProviderProxyRouteMap = ProviderProxyRouteMap; exports.previousResponseNotFound = previousResponseNotFound; exports.ResponsesAffinityStore = ResponsesAffinityStore; exports.getResponsesAffinityStore = getResponsesAffinityStore; exports.classifyResponsesProfile = classifyResponsesProfile; exports.extractRouteToken = extractRouteToken; exports.isLoopbackAddress = isLoopbackAddress; exports.ProviderProxy = ProviderProxy; exports.ROUTE_LEASE_REQUEST_SCHEMA = ROUTE_LEASE_REQUEST_SCHEMA; exports.ROUTE_LEASE_RESULT_SCHEMA = ROUTE_LEASE_RESULT_SCHEMA; exports.ROUTE_LEASE_CAPABILITIES_SCHEMA = ROUTE_LEASE_CAPABILITIES_SCHEMA; exports.ROUTE_LEASE_API_VERSION = ROUTE_LEASE_API_VERSION; exports.ROUTE_LEASE_DEFAULT_TTL_SECONDS = ROUTE_LEASE_DEFAULT_TTL_SECONDS; exports.ROUTE_LEASE_MAX_TTL_SECONDS = ROUTE_LEASE_MAX_TTL_SECONDS; exports.ROUTE_LEASE_MAX_IDEMPOTENCY_BYTES = ROUTE_LEASE_MAX_IDEMPOTENCY_BYTES; exports.ROUTE_LEASE_MAX_CONSUMER_BYTES = ROUTE_LEASE_MAX_CONSUMER_BYTES; exports.ROUTE_LEASE_MAX_EXECUTION_ID_BYTES = ROUTE_LEASE_MAX_EXECUTION_ID_BYTES; exports.ROUTE_LEASE_MAX_SESSION_ID_BYTES = ROUTE_LEASE_MAX_SESSION_ID_BYTES; exports.ROUTE_LEASE_MAX_MODEL_BYTES = ROUTE_LEASE_MAX_MODEL_BYTES; exports.ROUTE_LEASE_SESSION_HASH_DOMAIN = ROUTE_LEASE_SESSION_HASH_DOMAIN; exports.ROUTE_LEASE_CODEX_TOKEN_ENV = ROUTE_LEASE_CODEX_TOKEN_ENV; exports.ROUTE_LEASE_RUNTIMES = ROUTE_LEASE_RUNTIMES; exports.ROUTE_LEASE_CAPABILITIES = ROUTE_LEASE_CAPABILITIES; exports.ROUTE_LEASE_RUNTIME_TABLE = ROUTE_LEASE_RUNTIME_TABLE; exports.RouteLeaseError = RouteLeaseError; exports.normalizeRouteLeaseIdempotencyKey = normalizeRouteLeaseIdempotencyKey; exports.normalizeRouteLeaseTtl = normalizeRouteLeaseTtl; exports.hashRouteLeaseSessionId = hashRouteLeaseSessionId; exports.canonicalizeRouteLeasePayload = canonicalizeRouteLeasePayload; exports.hashRouteLeasePayload = hashRouteLeasePayload; exports.parseRouteLeaseCreate = parseRouteLeaseCreate; exports.routeLeaseRuntime = routeLeaseRuntime; exports.SYSTEM_ROUTE_LEASE_CLOCK = SYSTEM_ROUTE_LEASE_CLOCK; exports.RouteLeaseManager = RouteLeaseManager; exports.gatewayBindingToEndpointConfig = gatewayBindingToEndpointConfig; exports.candidateGatewayBindings = candidateGatewayBindings; exports.candidateBackgroundModelIds = candidateBackgroundModelIds; exports.resolveGatewayBinding = resolveGatewayBinding; exports.RouteLeaseTargetResolver = RouteLeaseTargetResolver; exports.createResponsesCompactHandler = createResponsesCompactHandler; exports.registerResponsesCompactOperation = registerResponsesCompactOperation; exports.createNativeResponsesHostedImageIngress = createNativeResponsesHostedImageIngress; exports.getProviderProxy = getProviderProxy; exports.__resetProviderProxyForTests = __resetProviderProxyForTests; exports.KeyedMutex = KeyedMutex; exports.IMAGE_SERVER_HARD_CEILINGS = IMAGE_SERVER_HARD_CEILINGS; exports.DEFAULT_IMAGES_SERVER_CONFIG = DEFAULT_IMAGES_SERVER_CONFIG; exports.normalizeImagesServerConfig = normalizeImagesServerConfig; exports.validateImagesServerConfig = validateImagesServerConfig; exports.DEFAULT_SEARCH_SERVER_CONFIG = DEFAULT_SEARCH_SERVER_CONFIG; exports.normalizeSearchApiProviderConfigs = normalizeSearchApiProviderConfigs; exports.normalizeSearchServerConfig = normalizeSearchServerConfig; exports.validateSearchServerConfig = validateSearchServerConfig; 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.DEFAULT_ALLOWANCE_SCHEDULING = DEFAULT_ALLOWANCE_SCHEDULING; exports.normalizeAllowanceScheduling = normalizeAllowanceScheduling; 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.legacyEndpointsToBindings = legacyEndpointsToBindings; exports.normalizeGatewayBindings = normalizeGatewayBindings; 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.createIntegrationKey = createIntegrationKey; exports.LEGACY_OUTBOUND_PERMISSIONS = LEGACY_OUTBOUND_PERMISSIONS; exports.validateOutboundPermissions = validateOutboundPermissions; exports.effectiveOutboundPermissions = effectiveOutboundPermissions; 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.codexSearchRoutePath = codexSearchRoutePath; exports.isCodexSearchRequest = isCodexSearchRequest; exports.handleCodexSearchRequest = handleCodexSearchRequest; 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.OutboundApiServer = OutboundApiServer; exports.formatUrls = formatUrls; exports.startOfLocalDay = startOfLocalDay; exports.startOfLocalWeek = startOfLocalWeek; exports.KeySpendTracker = KeySpendTracker; exports.getOutboundApiServer = getOutboundApiServer; exports.__resetOutboundApiServerForTests = __resetOutboundApiServerForTests;
13906
+
13907
+
13908
+
13909
+
13910
+
13911
+ 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.getSharedExecutor = getSharedExecutor; exports.getResponsesEndpointTransformer = getResponsesEndpointTransformer; exports.getAnthropicEndpointTransformer = getAnthropicEndpointTransformer; exports.getGeminiEndpointTransformer = getGeminiEndpointTransformer; exports.readBody = readBody; exports.cancelDiscardedResponse = cancelDiscardedResponse; exports.projectUpstreamResponseHeaders = projectUpstreamResponseHeaders; exports.relayResponse = relayResponse; exports.aggregateAnthropicSseToJsonBody = aggregateAnthropicSseToJsonBody; exports.aggregateResponsesSseToJsonBody = aggregateResponsesSseToJsonBody; exports.aggregateOpenAIChatChunksToJsonBody = aggregateOpenAIChatChunksToJsonBody; exports.sniffIsSseResponse = sniffIsSseResponse; exports.writeError = writeError; exports.writeBoundAccountError = writeBoundAccountError; exports.resolvePoolBoundKey = resolvePoolBoundKey; exports.buildByoRouteActivityMeta = buildByoRouteActivityMeta; exports.DEFAULT_ROUTE_IDLE_MS = DEFAULT_ROUTE_IDLE_MS; exports.ProviderProxyRouteMap = ProviderProxyRouteMap; exports.previousResponseNotFound = previousResponseNotFound; exports.ResponsesAffinityStore = ResponsesAffinityStore; exports.getResponsesAffinityStore = getResponsesAffinityStore; exports.classifyResponsesProfile = classifyResponsesProfile; exports.extractRouteToken = extractRouteToken; exports.isLoopbackAddress = isLoopbackAddress; exports.ProviderProxy = ProviderProxy; exports.ROUTE_LEASE_REQUEST_SCHEMA = ROUTE_LEASE_REQUEST_SCHEMA; exports.ROUTE_LEASE_RESULT_SCHEMA = ROUTE_LEASE_RESULT_SCHEMA; exports.ROUTE_LEASE_CAPABILITIES_SCHEMA = ROUTE_LEASE_CAPABILITIES_SCHEMA; exports.ROUTE_LEASE_API_VERSION = ROUTE_LEASE_API_VERSION; exports.ROUTE_LEASE_DEFAULT_TTL_SECONDS = ROUTE_LEASE_DEFAULT_TTL_SECONDS; exports.ROUTE_LEASE_MAX_TTL_SECONDS = ROUTE_LEASE_MAX_TTL_SECONDS; exports.ROUTE_LEASE_MAX_IDEMPOTENCY_BYTES = ROUTE_LEASE_MAX_IDEMPOTENCY_BYTES; exports.ROUTE_LEASE_MAX_CONSUMER_BYTES = ROUTE_LEASE_MAX_CONSUMER_BYTES; exports.ROUTE_LEASE_MAX_EXECUTION_ID_BYTES = ROUTE_LEASE_MAX_EXECUTION_ID_BYTES; exports.ROUTE_LEASE_MAX_SESSION_ID_BYTES = ROUTE_LEASE_MAX_SESSION_ID_BYTES; exports.ROUTE_LEASE_MAX_MODEL_BYTES = ROUTE_LEASE_MAX_MODEL_BYTES; exports.ROUTE_LEASE_SESSION_HASH_DOMAIN = ROUTE_LEASE_SESSION_HASH_DOMAIN; exports.ROUTE_LEASE_CODEX_TOKEN_ENV = ROUTE_LEASE_CODEX_TOKEN_ENV; exports.ROUTE_LEASE_RUNTIMES = ROUTE_LEASE_RUNTIMES; exports.ROUTE_LEASE_CAPABILITIES = ROUTE_LEASE_CAPABILITIES; exports.ROUTE_LEASE_RUNTIME_TABLE = ROUTE_LEASE_RUNTIME_TABLE; exports.RouteLeaseError = RouteLeaseError; exports.normalizeRouteLeaseIdempotencyKey = normalizeRouteLeaseIdempotencyKey; exports.normalizeRouteLeaseTtl = normalizeRouteLeaseTtl; exports.hashRouteLeaseSessionId = hashRouteLeaseSessionId; exports.canonicalizeRouteLeasePayload = canonicalizeRouteLeasePayload; exports.hashRouteLeasePayload = hashRouteLeasePayload; exports.parseRouteLeaseCreate = parseRouteLeaseCreate; exports.routeLeaseRuntime = routeLeaseRuntime; exports.SYSTEM_ROUTE_LEASE_CLOCK = SYSTEM_ROUTE_LEASE_CLOCK; exports.RouteLeaseManager = RouteLeaseManager; exports.gatewayBindingToEndpointConfig = gatewayBindingToEndpointConfig; exports.candidateGatewayBindings = candidateGatewayBindings; exports.candidateBackgroundModelIds = candidateBackgroundModelIds; exports.resolveGatewayBinding = resolveGatewayBinding; exports.RouteLeaseTargetResolver = RouteLeaseTargetResolver; exports.createResponsesCompactHandler = createResponsesCompactHandler; exports.registerResponsesCompactOperation = registerResponsesCompactOperation; exports.createNativeResponsesHostedImageIngress = createNativeResponsesHostedImageIngress; exports.getProviderProxy = getProviderProxy; exports.__resetProviderProxyForTests = __resetProviderProxyForTests; exports.KeyedMutex = KeyedMutex; exports.IMAGE_SERVER_HARD_CEILINGS = IMAGE_SERVER_HARD_CEILINGS; exports.DEFAULT_IMAGES_SERVER_CONFIG = DEFAULT_IMAGES_SERVER_CONFIG; exports.normalizeImagesServerConfig = normalizeImagesServerConfig; exports.validateImagesServerConfig = validateImagesServerConfig; exports.DEFAULT_SEARCH_SERVER_CONFIG = DEFAULT_SEARCH_SERVER_CONFIG; exports.normalizeSearchApiProviderConfigs = normalizeSearchApiProviderConfigs; exports.normalizeSearchServerConfig = normalizeSearchServerConfig; exports.validateSearchServerConfig = validateSearchServerConfig; 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.DEFAULT_ALLOWANCE_SCHEDULING = DEFAULT_ALLOWANCE_SCHEDULING; exports.normalizeAllowanceScheduling = normalizeAllowanceScheduling; 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.legacyEndpointsToBindings = legacyEndpointsToBindings; exports.normalizeGatewayBindings = normalizeGatewayBindings; exports.defaultServerConfig = defaultServerConfig; exports.normalizeServerConfig = normalizeServerConfig; exports.loadServerConfig = loadServerConfig; exports.saveServerConfig = saveServerConfig; exports.mergeServerConfig = mergeServerConfig; exports.injectMappingEffortDefault = injectMappingEffortDefault; exports.computeKeyExpiry = computeKeyExpiry; exports.checkKeyQuota = checkKeyQuota; exports.randomBase62 = randomBase62; exports.hashKey = hashKey; exports.createNamedKey = createNamedKey; exports.createIntegrationKey = createIntegrationKey; exports.LEGACY_OUTBOUND_PERMISSIONS = LEGACY_OUTBOUND_PERMISSIONS; exports.validateOutboundPermissions = validateOutboundPermissions; exports.effectiveOutboundPermissions = effectiveOutboundPermissions; 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.codexSearchRoutePath = codexSearchRoutePath; exports.isCodexSearchRequest = isCodexSearchRequest; exports.handleCodexSearchRequest = handleCodexSearchRequest; 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.OutboundApiServer = OutboundApiServer; exports.formatUrls = formatUrls; exports.startOfLocalDay = startOfLocalDay; exports.startOfLocalWeek = startOfLocalWeek; exports.KeySpendTracker = KeySpendTracker; exports.getOutboundApiServer = getOutboundApiServer; exports.__resetOutboundApiServerForTests = __resetOutboundApiServerForTests;