@omnicross/core 0.4.3 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/auth/GeminiCodeAssistProjectResolver.cjs +4 -4
  2. package/dist/auth/GeminiCodeAssistProjectResolver.js +3 -3
  3. package/dist/{chunk-MPFOC7AT.js → chunk-24W3DVGI.js} +1 -1
  4. package/dist/{chunk-WYECWQ3J.cjs → chunk-2DMOOZ4F.cjs} +1 -1
  5. package/dist/{chunk-NKVZ6Z3Y.cjs → chunk-4HMAS74X.cjs} +8 -3
  6. package/dist/{chunk-M6PKXP6T.js → chunk-4LSZ7NFM.js} +14 -2
  7. package/dist/{chunk-VFFCV4J6.cjs → chunk-CXRJMNJJ.cjs} +12 -6
  8. package/dist/{chunk-E5RCCGE7.cjs → chunk-DF5JXK36.cjs} +2 -2
  9. package/dist/{chunk-CGEZQC2G.cjs → chunk-F3TT5XPV.cjs} +2 -2
  10. package/dist/{chunk-EE7VP4O3.js → chunk-HQ7C3VB6.js} +1 -1
  11. package/dist/{chunk-ZJJBITUN.js → chunk-IAWLTZUP.js} +2 -2
  12. package/dist/{chunk-SWY2LTMR.js → chunk-L4L77G3X.js} +574 -100
  13. package/dist/{chunk-NTF7TLT7.js → chunk-LBIXTHP7.js} +11 -5
  14. package/dist/{chunk-UOOLU64V.cjs → chunk-LVQOCIES.cjs} +2 -2
  15. package/dist/{chunk-J5XMB5KY.cjs → chunk-NCCEWVWY.cjs} +978 -504
  16. package/dist/{chunk-K6J2RIEX.js → chunk-NDJSLJIA.js} +1 -1
  17. package/dist/{chunk-AFH5CEMF.cjs → chunk-SQU2FGXI.cjs} +15 -3
  18. package/dist/{chunk-F6P4DIBL.js → chunk-TLYFFUW4.js} +1 -1
  19. package/dist/{chunk-GL6XM527.js → chunk-TX7ZM4OI.js} +8 -3
  20. package/dist/{chunk-HRBXQ5AC.js → chunk-WYUXJKMK.js} +1 -1
  21. package/dist/{chunk-NDIBVTBZ.cjs → chunk-XYFCNDJK.cjs} +2 -2
  22. package/dist/{chunk-X6GHTNDL.cjs → chunk-ZG57GAVU.cjs} +7 -7
  23. package/dist/completion/CompletionService.cjs +11 -11
  24. package/dist/completion/CompletionService.js +10 -10
  25. package/dist/completion.cjs +11 -11
  26. package/dist/completion.js +10 -10
  27. package/dist/index.cjs +13 -11
  28. package/dist/index.d.cts +3 -3
  29. package/dist/index.d.ts +3 -3
  30. package/dist/index.js +12 -10
  31. package/dist/outbound-api/routeResolver.d.cts +2 -2
  32. package/dist/outbound-api/routeResolver.d.ts +2 -2
  33. package/dist/outbound-api/types.d.cts +2 -2
  34. package/dist/outbound-api/types.d.ts +2 -2
  35. package/dist/outbound-api.cjs +13 -11
  36. package/dist/outbound-api.d.cts +46 -5
  37. package/dist/outbound-api.d.ts +46 -5
  38. package/dist/outbound-api.js +12 -10
  39. package/dist/pipeline/AccountAllowanceScheduling.d.cts +1 -1
  40. package/dist/pipeline/AccountAllowanceScheduling.d.ts +1 -1
  41. package/dist/pipeline/AccountRouteActivity.cjs +2 -2
  42. package/dist/pipeline/AccountRouteActivity.d.cts +33 -8
  43. package/dist/pipeline/AccountRouteActivity.d.ts +33 -8
  44. package/dist/pipeline/AccountRouteActivity.js +1 -1
  45. package/dist/pipeline/upstreamFetch.cjs +3 -3
  46. package/dist/pipeline/upstreamFetch.d.cts +15 -1
  47. package/dist/pipeline/upstreamFetch.d.ts +15 -1
  48. package/dist/pipeline/upstreamFetch.js +2 -2
  49. package/dist/ports.d.cts +1 -1
  50. package/dist/ports.d.ts +1 -1
  51. package/dist/provider-proxy/ProviderProxy.cjs +11 -11
  52. package/dist/provider-proxy/ProviderProxy.js +10 -10
  53. package/dist/provider-proxy/identity/codexCliHeaders.cjs +6 -2
  54. package/dist/provider-proxy/identity/codexCliHeaders.d.cts +42 -11
  55. package/dist/provider-proxy/identity/codexCliHeaders.d.ts +42 -11
  56. package/dist/provider-proxy/identity/codexCliHeaders.js +6 -2
  57. package/dist/provider-proxy/identity/openCodeGoHeaders.cjs +2 -2
  58. package/dist/provider-proxy/identity/openCodeGoHeaders.js +1 -1
  59. package/dist/provider-proxy/ingress/providerProxyShared.cjs +13 -11
  60. package/dist/provider-proxy/ingress/providerProxyShared.d.cts +19 -1
  61. package/dist/provider-proxy/ingress/providerProxyShared.d.ts +19 -1
  62. package/dist/provider-proxy/ingress/providerProxyShared.js +12 -10
  63. package/dist/provider-proxy.cjs +11 -11
  64. package/dist/provider-proxy.d.cts +1 -1
  65. package/dist/provider-proxy.d.ts +1 -1
  66. package/dist/provider-proxy.js +10 -10
  67. package/dist/{routeResolver-C2z0pp-q.d.cts → routeResolver-BdNJvTZP.d.cts} +1 -1
  68. package/dist/{routeResolver-BLTleO4H.d.ts → routeResolver-zVoCx9r3.d.ts} +1 -1
  69. package/dist/transformer/transformers/AntigravityTransformer.cjs +6 -6
  70. package/dist/transformer/transformers/AntigravityTransformer.js +5 -5
  71. package/dist/transformer/transformers/antigravityFailover.cjs +7 -7
  72. package/dist/transformer/transformers/antigravityFailover.js +6 -6
  73. package/dist/transformer/transformers/antigravityIdentity.cjs +4 -4
  74. package/dist/transformer/transformers/antigravityIdentity.js +3 -3
  75. package/dist/transformer/transformers.cjs +8 -8
  76. package/dist/transformer/transformers.js +7 -7
  77. package/dist/transformer.cjs +8 -8
  78. package/dist/transformer.js +7 -7
  79. package/dist/{types-C6m-Db26.d.cts → types-Dt1bgHPg.d.cts} +63 -2
  80. package/dist/{types-Da735j2d.d.ts → types-IRPv4i1Y.d.ts} +63 -2
  81. 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');
@@ -43,7 +43,7 @@ var _chunkHQP3K7PUcjs = require('./chunk-HQP3K7PU.cjs');
43
43
 
44
44
 
45
45
 
46
- var _chunkAFH5CEMFcjs = require('./chunk-AFH5CEMF.cjs');
46
+ var _chunkSQU2FGXIcjs = require('./chunk-SQU2FGXI.cjs');
47
47
 
48
48
 
49
49
  var _chunkRPII3E6Zcjs = require('./chunk-RPII3E6Z.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 _chunkWYECWQ3Jcjs = require('./chunk-WYECWQ3J.cjs');
56
+ var _chunk2DMOOZ4Fcjs = require('./chunk-2DMOOZ4F.cjs');
57
57
 
58
58
 
59
59
 
@@ -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
 
@@ -953,6 +954,21 @@ async function resolvePoolBoundKey(deps, providerId, provider, sessionId, prefer
953
954
  }
954
955
  return resolveApiKey(_chunkA2YMUCBTcjs.resolveProviderEndpoint.call(void 0, provider).apiKey);
955
956
  }
957
+ function buildByoRouteActivityMeta(deps, providerId, sessionId) {
958
+ return {
959
+ providerId,
960
+ resolveKeyId: () => {
961
+ if (!sessionId) return void 0;
962
+ const pool = deps.apiKeyPool;
963
+ if (!pool || typeof pool.getKeyIdForSession !== "function") return void 0;
964
+ try {
965
+ return _nullishCoalesce(pool.getKeyIdForSession(providerId, sessionId), () => ( void 0));
966
+ } catch (e11) {
967
+ return void 0;
968
+ }
969
+ }
970
+ };
971
+ }
956
972
 
957
973
  // src/provider-proxy/providerProxyRouteMap.ts
958
974
  var _crypto = require('crypto');
@@ -996,7 +1012,7 @@ var ProviderProxyRouteMap = (_class = class {
996
1012
  if (!entry) return void 0;
997
1013
  try {
998
1014
  _optionalChain([entry, 'access', _43 => _43.onActivity, 'optionalCall', _44 => _44(Date.now())]);
999
- } catch (e11) {
1015
+ } catch (e12) {
1000
1016
  }
1001
1017
  this.armIdleTimer(token, entry);
1002
1018
  return entry.context;
@@ -1056,7 +1072,7 @@ var ProviderProxyRouteMap = (_class = class {
1056
1072
  this.clearIdleTimer(entry);
1057
1073
  try {
1058
1074
  _optionalChain([entry, 'access', _48 => _48.onEvicted, 'optionalCall', _49 => _49(reason)]);
1059
- } catch (e12) {
1075
+ } catch (e13) {
1060
1076
  }
1061
1077
  }
1062
1078
  }, _class);
@@ -1525,13 +1541,13 @@ function recordAnthropicNonStreamUsage(recorder, bodyText, attribution) {
1525
1541
  parsed.usage,
1526
1542
  attribution
1527
1543
  );
1528
- } catch (e13) {
1544
+ } catch (e14) {
1529
1545
  }
1530
1546
  }
1531
1547
  function recordAnthropicStreamUsage(recorder, rawUsage, attribution) {
1532
1548
  try {
1533
1549
  emitAnthropicUsageRecord(recorder, rawUsage, attribution);
1534
- } catch (e14) {
1550
+ } catch (e15) {
1535
1551
  }
1536
1552
  }
1537
1553
 
@@ -1595,7 +1611,7 @@ async function buildSubscriptionIterationPlan(profile, route, deps, resolvedMode
1595
1611
  });
1596
1612
  const bearer = (_nullishCoalesce(_nullishCoalesce(headers.Authorization, () => ( headers.authorization)), () => ( ""))).replace(/^Bearer\s+/i, "").trim();
1597
1613
  if (bearer) {
1598
- transformerProvider.geminiProject = await _chunkNDIBVTBZcjs.getAntigravityProjectResolver.call(void 0, ).resolveProject(bearer);
1614
+ transformerProvider.geminiProject = await _chunkXYFCNDJKcjs.getAntigravityProjectResolver.call(void 0, ).resolveProject(bearer);
1599
1615
  }
1600
1616
  }
1601
1617
  return {
@@ -1666,6 +1682,31 @@ function collectText(value) {
1666
1682
  function proxyProviderId(plan) {
1667
1683
  return plan.isSubscription ? plan.transformerProvider.name : "byo";
1668
1684
  }
1685
+ function buildAnthropicRouteActivity(plan, proxyAccountId, model, onRecorded) {
1686
+ if (!plan.isSubscription) {
1687
+ const routeSessionId = plan.byoSessionId || void 0;
1688
+ return {
1689
+ providerId: _nullishCoalesce(_optionalChain([plan, 'access', _107 => _107.byoActivity, 'optionalAccess', _108 => _108.providerId]), () => ( plan.transformerProvider.name)),
1690
+ credentialKind: "provider-key",
1691
+ keyId: _optionalChain([plan, 'access', _109 => _109.byoActivity, 'optionalAccess', _110 => _110.resolveKeyId, 'call', _111 => _111()]),
1692
+ endpoint: "messages",
1693
+ sessionKey: routeSessionId,
1694
+ sessionSource: routeSessionId ? "route-session-id" : "none",
1695
+ model,
1696
+ onRecorded
1697
+ };
1698
+ }
1699
+ return {
1700
+ providerId: proxyProviderId(plan),
1701
+ credentialKind: "subscription-account",
1702
+ accountId: proxyAccountId,
1703
+ endpoint: "messages",
1704
+ sessionKey: plan.sessionKey,
1705
+ sessionSource: plan.sessionKey ? "content-fingerprint" : "none",
1706
+ model,
1707
+ onRecorded
1708
+ };
1709
+ }
1669
1710
  async function runPipeline(anthropicBody, plan, reportSelection, signal, callerOpenCodeSession) {
1670
1711
  const executor = getSharedExecutor();
1671
1712
  const endpointTransformer = getAnthropicEndpointTransformer();
@@ -1682,12 +1723,12 @@ async function runPipeline(anthropicBody, plan, reportSelection, signal, callerO
1682
1723
  boundAccountFallbackPolicy: plan.boundAccountFallbackPolicy,
1683
1724
  reportSelection: (accountId, isActive) => {
1684
1725
  proxyAccountId = accountId;
1685
- _optionalChain([reportSelection, 'optionalCall', _107 => _107(accountId, isActive)]);
1726
+ _optionalChain([reportSelection, 'optionalCall', _112 => _112(accountId, isActive)]);
1686
1727
  }
1687
1728
  });
1688
1729
  if (plan.transformerProvider.name === "antigravity") {
1689
1730
  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);
1731
+ if (bearer) transformerProvider.geminiProject = await _chunkXYFCNDJKcjs.getAntigravityProjectResolver.call(void 0, ).resolveProject(bearer);
1691
1732
  }
1692
1733
  let rawStatus = null;
1693
1734
  let activityRecordId;
@@ -1709,21 +1750,20 @@ async function runPipeline(anthropicBody, plan, reportSelection, signal, callerO
1709
1750
  },
1710
1751
  fetchFn: (url, headers, body) => {
1711
1752
  console.info(`[ProviderProxy:anthropic] -> ${url} model=${resolvedModel} stream=${isStream}`);
1712
- return _chunkVFFCV4J6cjs.fetchUpstream.call(void 0,
1753
+ return _chunkCXRJMNJJcjs.fetchUpstream.call(void 0,
1713
1754
  url,
1714
1755
  { method: "POST", headers, body: JSON.stringify(body), signal },
1715
1756
  {
1716
1757
  providerId: proxyProviderId(plan),
1717
1758
  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) => {
1759
+ routeActivity: buildAnthropicRouteActivity(
1760
+ plan,
1761
+ proxyAccountId,
1762
+ resolvedModel,
1763
+ (record5) => {
1724
1764
  activityRecordId = record5.id;
1725
1765
  }
1726
- } : void 0
1766
+ )
1727
1767
  }
1728
1768
  ).then((r) => {
1729
1769
  rawStatus = r.status;
@@ -1749,7 +1789,7 @@ async function runSubscriptionSameFormatFetch(rawBody, plan, reportSelection, op
1749
1789
  reportSelection: (accountId, isActive, remapped) => {
1750
1790
  proxyAccountId = accountId;
1751
1791
  remappedModel = remapped;
1752
- _optionalChain([reportSelection, 'optionalCall', _108 => _108(accountId, isActive, remapped)]);
1792
+ _optionalChain([reportSelection, 'optionalCall', _113 => _113(accountId, isActive, remapped)]);
1753
1793
  }
1754
1794
  });
1755
1795
  const isClaudeSubscription = plan.isSubscription && plan.transformerProvider.name === "claude";
@@ -1780,21 +1820,20 @@ async function runSubscriptionSameFormatFetch(rawBody, plan, reportSelection, op
1780
1820
  `[ProviderProxy:anthropic] (subscription same-format) -> ${_nullishCoalesce(urlOverride, () => ( plan.upstreamUrl))} model=${outboundModel} stream=${plan.isStream}`
1781
1821
  );
1782
1822
  let activityRecordId;
1783
- const response = await _chunkVFFCV4J6cjs.fetchUpstream.call(void 0,
1823
+ const response = await _chunkCXRJMNJJcjs.fetchUpstream.call(void 0,
1784
1824
  _nullishCoalesce(urlOverride, () => ( plan.upstreamUrl)),
1785
1825
  { method: "POST", headers, body: outboundBody, signal: options.signal },
1786
1826
  {
1787
1827
  providerId: proxyProviderId(plan),
1788
1828
  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) => {
1829
+ routeActivity: buildAnthropicRouteActivity(
1830
+ plan,
1831
+ proxyAccountId,
1832
+ outboundModel,
1833
+ (record5) => {
1795
1834
  activityRecordId = record5.id;
1796
1835
  }
1797
- } : void 0
1836
+ )
1798
1837
  }
1799
1838
  );
1800
1839
  return {
@@ -1814,7 +1853,7 @@ function rewriteBodyModel(rawBody, model) {
1814
1853
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return rawBody;
1815
1854
  parsed.model = model;
1816
1855
  return JSON.stringify(parsed);
1817
- } catch (e15) {
1856
+ } catch (e16) {
1818
1857
  return rawBody;
1819
1858
  }
1820
1859
  }
@@ -1833,7 +1872,7 @@ async function runSubscriptionAttemptWith401Retry(anthropicBody, relayBody, plan
1833
1872
  const first = await runOnce();
1834
1873
  let result = first;
1835
1874
  if (first.rawStatus === 401) {
1836
- const refreshed = await _optionalChain([plan, 'access', _109 => _109.auth, 'access', _110 => _110.onUnauthorized, 'optionalCall', _111 => _111(plan.sessionKey)]);
1875
+ const refreshed = await _optionalChain([plan, 'access', _114 => _114.auth, 'access', _115 => _115.onUnauthorized, 'optionalCall', _116 => _116(plan.sessionKey)]);
1837
1876
  if (refreshed) {
1838
1877
  console.info("[ProviderProxy:anthropic] 401 \u2192 token refreshed; retrying once");
1839
1878
  await cancelDiscardedResponse(first.response);
@@ -1849,7 +1888,7 @@ async function readBoundedBody(response, max = 2048) {
1849
1888
  try {
1850
1889
  const text = await response.clone().text();
1851
1890
  return text.slice(0, max);
1852
- } catch (e16) {
1891
+ } catch (e17) {
1853
1892
  return void 0;
1854
1893
  }
1855
1894
  }
@@ -1865,8 +1904,8 @@ async function markSubscriptionHealth(plan, selectedAccountId, result) {
1865
1904
  if (errorBody) {
1866
1905
  try {
1867
1906
  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) {
1907
+ if (typeof _optionalChain([parsed, 'access', _117 => _117.error, 'optionalAccess', _118 => _118.type]) === "string") upstreamErrorType = parsed.error.type;
1908
+ } catch (e18) {
1870
1909
  }
1871
1910
  }
1872
1911
  }
@@ -1889,7 +1928,7 @@ function breakerOutcome(rawStatus) {
1889
1928
  function recordBreakerOutcome(profile, modelId, rawStatus) {
1890
1929
  const outcome = breakerOutcome(rawStatus);
1891
1930
  if (outcome === "neutral") return;
1892
- _optionalChain([profile, 'optionalAccess', _114 => _114.recordModelOutcome, 'optionalCall', _115 => _115(modelId, outcome === "success")]);
1931
+ _optionalChain([profile, 'optionalAccess', _119 => _119.recordModelOutcome, 'optionalCall', _120 => _120(modelId, outcome === "success")]);
1893
1932
  }
1894
1933
  async function runSubscriptionAttemptOutcome(anthropicBody, relayBody, plan, options = {}) {
1895
1934
  try {
@@ -1908,20 +1947,20 @@ function settleOutcome(outcome) {
1908
1947
  async function runPipelineWithSubscriptionRetry(anthropicBody, rawBody, initialPlan, route, deps, options = {}, prepareTranslateBody) {
1909
1948
  const profile = route.subscriptionProfile;
1910
1949
  const scenario = initialPlan.scenario;
1911
- const clientGone = () => _optionalChain([options, 'access', _116 => _116.signal, 'optionalAccess', _117 => _117.aborted]) === true;
1950
+ const clientGone = () => _optionalChain([options, 'access', _121 => _121.signal, 'optionalAccess', _122 => _122.aborted]) === true;
1912
1951
  const prepareTranslateAttempt = async (body) => {
1913
1952
  if (!prepareTranslateBody) return body;
1914
1953
  const clone = JSON.parse(JSON.stringify(body));
1915
1954
  await prepareTranslateBody(clone);
1916
1955
  return clone;
1917
1956
  };
1918
- if (!_optionalChain([profile, 'optionalAccess', _118 => _118.nextFallback]) || scenario === void 0) {
1957
+ if (!_optionalChain([profile, 'optionalAccess', _123 => _123.nextFallback]) || scenario === void 0) {
1919
1958
  const loneBody = initialPlan.sameFormat ? anthropicBody : await prepareTranslateAttempt(anthropicBody);
1920
1959
  let loneOutcome = await runSubscriptionAttemptOutcome(loneBody, rawBody, initialPlan, options);
1921
1960
  if (!clientGone()) recordBreakerOutcome(profile, initialPlan.resolvedModel, outcomeStatus(loneOutcome));
1922
1961
  if (initialPlan.transformerProvider.name === "antigravity" && !clientGone() && outcomeStatus(loneOutcome) !== null && !is2xxStatus(outcomeStatus(loneOutcome))) {
1923
1962
  const bodyText = loneOutcome.kind === "result" ? await readBoundedBody(loneOutcome.result.response) : void 0;
1924
- const failoverUrl = _chunkCGEZQC2Gcjs.maybeAntigravityFailoverUrl.call(void 0,
1963
+ const failoverUrl = _chunkF3TT5XPVcjs.maybeAntigravityFailoverUrl.call(void 0,
1925
1964
  initialPlan.upstreamUrl,
1926
1965
  outcomeStatus(loneOutcome),
1927
1966
  bodyText
@@ -2011,7 +2050,7 @@ function withUpstreamUrl(plan, url) {
2011
2050
  const original = new URL(resolved);
2012
2051
  const target = new URL(url);
2013
2052
  return `${target.origin}${original.pathname}${original.search}`;
2014
- } catch (e18) {
2053
+ } catch (e19) {
2015
2054
  return url;
2016
2055
  }
2017
2056
  }
@@ -2031,7 +2070,7 @@ var MAX_CMAP_ENTRIES = 65536;
2031
2070
  function extractPdfText(base64, budgetMs = DEFAULT_PDF_TEXT_BUDGET_MS) {
2032
2071
  try {
2033
2072
  return extract(Buffer.from(base64, "base64"), budgetMs);
2034
- } catch (e19) {
2073
+ } catch (e20) {
2035
2074
  return { reason: "no-text-layer" };
2036
2075
  }
2037
2076
  }
@@ -2307,8 +2346,8 @@ async function prepareAnthropicTranslateBody(body, pdfBudgetMs) {
2307
2346
  }
2308
2347
  async function prepareDocumentBlock(block, pdfBudgetMs) {
2309
2348
  const source = block["source"];
2310
- const mediaType = _optionalChain([source, 'optionalAccess', _119 => _119["media_type"]]);
2311
- const data = _optionalChain([source, 'optionalAccess', _120 => _120["data"]]);
2349
+ const mediaType = _optionalChain([source, 'optionalAccess', _124 => _124["media_type"]]);
2350
+ const data = _optionalChain([source, 'optionalAccess', _125 => _125["data"]]);
2312
2351
  if (!source || source["type"] !== "base64" || mediaType !== "application/pdf" || typeof data !== "string") {
2313
2352
  throw new DocumentNotSupportedError(
2314
2353
  "no-text-layer",
@@ -2355,10 +2394,10 @@ function emitResponsesUsageRecord(recorder, rawUsage, attribution) {
2355
2394
  providerId: attribution.providerId,
2356
2395
  model: attribution.model,
2357
2396
  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)),
2397
+ runId: _nullishCoalesce(_optionalChain([attribution, 'access', _126 => _126.routeLease, 'optionalAccess', _127 => _127.runId]), () => ( null)),
2398
+ routeLeaseId: _nullishCoalesce(_optionalChain([attribution, 'access', _128 => _128.routeLease, 'optionalAccess', _129 => _129.leaseId]), () => ( null)),
2399
+ routeLeaseConsumer: _nullishCoalesce(_optionalChain([attribution, 'access', _130 => _130.routeLease, 'optionalAccess', _131 => _131.consumer]), () => ( null)),
2400
+ routeLeaseStageId: _nullishCoalesce(_optionalChain([attribution, 'access', _132 => _132.routeLease, 'optionalAccess', _133 => _133.stageId]), () => ( null)),
2362
2401
  cacheKeySource: attribution.cacheKeySource,
2363
2402
  cacheKeyInjected: attribution.cacheKeyInjected,
2364
2403
  auditResponse: attribution.auditResponse,
@@ -2375,13 +2414,13 @@ function recordResponsesNonStreamUsage(recorder, bodyText, attribution) {
2375
2414
  parsed.usage,
2376
2415
  attribution
2377
2416
  );
2378
- } catch (e20) {
2417
+ } catch (e21) {
2379
2418
  }
2380
2419
  }
2381
2420
  function recordResponsesStreamUsage(recorder, rawUsage, attribution) {
2382
2421
  try {
2383
2422
  emitResponsesUsageRecord(recorder, rawUsage, attribution);
2384
- } catch (e21) {
2423
+ } catch (e22) {
2385
2424
  }
2386
2425
  }
2387
2426
 
@@ -2407,21 +2446,21 @@ function parseCodexUsageLimitErrorPayload(bodyText) {
2407
2446
  if (!raw.startsWith("{")) return null;
2408
2447
  try {
2409
2448
  const parsed = JSON.parse(raw);
2410
- const error = _optionalChain([parsed, 'optionalAccess', _129 => _129.error]);
2411
- const code = _optionalChain([error, 'optionalAccess', _130 => _130.code]);
2449
+ const error = _optionalChain([parsed, 'optionalAccess', _134 => _134.error]);
2450
+ const code = _optionalChain([error, 'optionalAccess', _135 => _135.code]);
2412
2451
  if (typeof code !== "string" || !CODEX_USAGE_LIMIT_ERROR_CODES.has(code)) return null;
2413
- const resetsAt = _optionalChain([error, 'optionalAccess', _131 => _131.resets_at]);
2452
+ const resetsAt = _optionalChain([error, 'optionalAccess', _136 => _136.resets_at]);
2414
2453
  let resetsAtMs;
2415
2454
  if (typeof resetsAt === "number" && Number.isFinite(resetsAt) && resetsAt > 0) {
2416
2455
  resetsAtMs = resetsAt > 1e11 ? resetsAt : resetsAt * 1e3;
2417
2456
  }
2418
- const planType = _optionalChain([error, 'optionalAccess', _132 => _132.plan_type]);
2457
+ const planType = _optionalChain([error, 'optionalAccess', _137 => _137.plan_type]);
2419
2458
  return {
2420
2459
  code,
2421
2460
  ...resetsAtMs !== void 0 ? { resetsAtMs } : {},
2422
2461
  ...typeof planType === "string" && planType ? { planType } : {}
2423
2462
  };
2424
- } catch (e22) {
2463
+ } catch (e23) {
2425
2464
  return null;
2426
2465
  }
2427
2466
  }
@@ -2431,11 +2470,11 @@ function deadlineFromAllowanceSnapshot(accountId, now) {
2431
2470
  const candidates = snapshot.windows.filter(
2432
2471
  (w) => typeof w.usedPercent === "number" && w.usedPercent >= QUOTA_EXHAUSTED_PERCENT && typeof w.resetsAt === "string"
2433
2472
  ).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]);
2473
+ return _optionalChain([candidates, 'access', _138 => _138[0], 'optionalAccess', _139 => _139.ms]);
2435
2474
  }
2436
2475
  function resolveCodexQuotaDeadline(accountId, bodyText, now = Date.now()) {
2437
2476
  const structured = parseCodexUsageLimitErrorPayload(bodyText);
2438
- const structuredDeadline = _optionalChain([structured, 'optionalAccess', _135 => _135.resetsAtMs]) !== void 0 && structured.resetsAtMs > now ? structured.resetsAtMs : void 0;
2477
+ const structuredDeadline = _optionalChain([structured, 'optionalAccess', _140 => _140.resetsAtMs]) !== void 0 && structured.resetsAtMs > now ? structured.resetsAtMs : void 0;
2439
2478
  const parsed = parseTryAgainDeadline(bodyText);
2440
2479
  const parsedDeadline = parsed !== void 0 && parsed > now ? parsed : void 0;
2441
2480
  return _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(deadlineFromAllowanceSnapshot(accountId, now), () => ( structuredDeadline)), () => ( parsedDeadline)), () => ( now + DEFAULT_QUOTA_COOLDOWN_MS));
@@ -2487,7 +2526,7 @@ function normalizeHostedImageState(value) {
2487
2526
  hasImageContext: value.hasImageContext,
2488
2527
  pendingReceipts: Object.freeze(pendingReceipts)
2489
2528
  });
2490
- } catch (e23) {
2529
+ } catch (e24) {
2491
2530
  throw new TypeError(INVALID_HOSTED_IMAGE_METADATA);
2492
2531
  }
2493
2532
  }
@@ -2531,7 +2570,7 @@ var ResponsesAffinityStore = (_class6 = class {
2531
2570
  const entry = this.entries.get(responseId);
2532
2571
  const now = this.now();
2533
2572
  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) {
2573
+ if (_optionalChain([entry, 'optionalAccess', _141 => _141.expiresAt]) !== void 0 && entry.expiresAt <= now) {
2535
2574
  this.entries.delete(responseId);
2536
2575
  }
2537
2576
  throw previousResponseNotFound();
@@ -2566,7 +2605,7 @@ function classifyResponsesProfile(declaration) {
2566
2605
  if (declaration.authMode === "byo") {
2567
2606
  return declaration.providerApiFormat === "openai-response" ? "native" : "reduced";
2568
2607
  }
2569
- if (declaration.subscriptionProviderId === "codex" && _optionalChain([declaration, 'access', _137 => _137.subscriptionTransformerNames, 'optionalAccess', _138 => _138.includes, 'call', _139 => _139("openai-response")]) && isResponsesCreateUrl(declaration.upstreamUrl)) {
2608
+ if (declaration.subscriptionProviderId === "codex" && _optionalChain([declaration, 'access', _142 => _142.subscriptionTransformerNames, 'optionalAccess', _143 => _143.includes, 'call', _144 => _144("openai-response")]) && isResponsesCreateUrl(declaration.upstreamUrl)) {
2570
2609
  return "native";
2571
2610
  }
2572
2611
  return "reduced";
@@ -2586,7 +2625,7 @@ function isResponsesCreateUrl(value) {
2586
2625
  if (!value) return false;
2587
2626
  try {
2588
2627
  return new URL(value).pathname.replace(/\/+$/, "").endsWith("/responses");
2589
- } catch (e24) {
2628
+ } catch (e25) {
2590
2629
  return false;
2591
2630
  }
2592
2631
  }
@@ -2756,7 +2795,7 @@ function deriveResponsesCompactUrl(createUrl) {
2756
2795
  let url;
2757
2796
  try {
2758
2797
  url = new URL(createUrl);
2759
- } catch (e25) {
2798
+ } catch (e26) {
2760
2799
  throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({
2761
2800
  status: 502,
2762
2801
  code: "invalid_upstream_url",
@@ -2798,7 +2837,7 @@ async function resolveResponsesRouteProfile(route, deps, resolvedModel) {
2798
2837
  if (!subscriptionProfile) {
2799
2838
  throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({ status: 502, code: "provider_configuration_error", message: "Subscription route is missing its profile" });
2800
2839
  }
2801
- const upstreamUrl = _optionalChain([subscriptionProfile, 'access', _140 => _140.resolveUpstreamUrl, 'optionalCall', _141 => _141(resolvedModel)]);
2840
+ const upstreamUrl = _optionalChain([subscriptionProfile, 'access', _145 => _145.resolveUpstreamUrl, 'optionalCall', _146 => _146(resolvedModel)]);
2802
2841
  if (!upstreamUrl) {
2803
2842
  throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({ status: 502, code: "provider_configuration_error", message: "Subscription profile is missing its Responses URL" });
2804
2843
  }
@@ -2818,7 +2857,7 @@ async function resolveResponsesRouteProfile(route, deps, resolvedModel) {
2818
2857
  }
2819
2858
  async function buildResponsesCallPlan(route, deps, resolved, resolvedModel, isStream, sessionKey, sessionSource, requestHeaders, affinity) {
2820
2859
  if (route.authMode === "byo") {
2821
- return buildByoPlan(route, deps, resolved, resolvedModel, isStream, affinity);
2860
+ return buildByoPlan(route, deps, resolved, resolvedModel, isStream, sessionKey, sessionSource, affinity);
2822
2861
  }
2823
2862
  return buildSubscriptionPlan2(
2824
2863
  route,
@@ -2832,10 +2871,10 @@ async function buildResponsesCallPlan(route, deps, resolved, resolvedModel, isSt
2832
2871
  affinity
2833
2872
  );
2834
2873
  }
2835
- async function buildByoPlan(route, deps, resolved, resolvedModel, isStream, affinity) {
2874
+ async function buildByoPlan(route, deps, resolved, resolvedModel, isStream, sessionKey, sessionSource, affinity) {
2836
2875
  const providerId = route.providerId;
2837
2876
  const provider = resolved.provider;
2838
- const affinityKeyId = _optionalChain([affinity, 'optionalAccess', _142 => _142.credential, 'access', _143 => _143.kind]) === "byo-key" ? affinity.credential.id : void 0;
2877
+ const affinityKeyId = _optionalChain([affinity, 'optionalAccess', _147 => _147.credential, 'access', _148 => _148.kind]) === "byo-key" ? affinity.credential.id : void 0;
2839
2878
  const preferredKeyId = _nullishCoalesce(affinityKeyId, () => ( route.preferredKeyId));
2840
2879
  const apiKey = await resolvePoolBoundKey(
2841
2880
  deps,
@@ -2849,7 +2888,7 @@ async function buildByoPlan(route, deps, resolved, resolvedModel, isStream, affi
2849
2888
  if (affinity) throw previousResponseNotFound();
2850
2889
  throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({ status: 502, code: "provider_configuration_error", message: "Provider credential is unavailable" });
2851
2890
  }
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)));
2891
+ 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
2892
  const credential = selectedKeyId ? { kind: "byo-key", id: selectedKeyId } : { kind: "provider-key", id: providerId };
2854
2893
  const auth = affinityKeyId ? new (0, _chunkTX4UCSOPcjs.LlmConfigProviderAuth)({ provider, apiKey, apiKeyPool: null, providerId, sessionId: route.sessionId }) : _nullishCoalesce(route.auth, () => ( new (0, _chunkTX4UCSOPcjs.LlmConfigProviderAuth)({
2855
2894
  provider,
@@ -2881,15 +2920,19 @@ async function buildByoPlan(route, deps, resolved, resolvedModel, isStream, affi
2881
2920
  statefulContinuation: !!affinity,
2882
2921
  credential,
2883
2922
  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;
2923
+ const keyId = route.sessionId && typeof _optionalChain([deps, 'access', _151 => _151.apiKeyPool, 'optionalAccess', _152 => _152.getKeyIdForSession]) === "function" ? deps.apiKeyPool.getKeyIdForSession(providerId, route.sessionId) : null;
2885
2924
  return keyId ? { kind: "byo-key", id: keyId } : credential;
2886
- }
2925
+ },
2926
+ byoActivity: buildByoRouteActivityMeta(deps, providerId, route.sessionId),
2927
+ byoSessionId: _nullishCoalesce(route.sessionId, () => ( null)),
2928
+ sessionKey,
2929
+ sessionSource
2887
2930
  };
2888
2931
  }
2889
2932
  async function buildSubscriptionPlan2(route, deps, resolved, resolvedModel, isStream, sessionKey, sessionSource, requestHeaders, affinity) {
2890
2933
  const profile = route.subscriptionProfile;
2891
2934
  const upstreamUrl = resolved.upstreamUrl;
2892
- const affinityAccountId = _optionalChain([affinity, 'optionalAccess', _148 => _148.credential, 'access', _149 => _149.kind]) === "subscription-account" ? affinity.credential.id : void 0;
2935
+ const affinityAccountId = _optionalChain([affinity, 'optionalAccess', _153 => _153.credential, 'access', _154 => _154.kind]) === "subscription-account" ? affinity.credential.id : void 0;
2893
2936
  const auth = _nullishCoalesce(route.auth, () => ( new (0, _chunkRXMF7GNFcjs.SubscriptionAuthSource)(profile)));
2894
2937
  const chain = resolved.profile === "native" ? { providerTransformers: [], modelTransformers: [] } : _chunkNYUNU75Acjs.resolveSubscriptionChain.call(void 0,
2895
2938
  profile,
@@ -2939,10 +2982,10 @@ async function buildSubscriptionPlan2(route, deps, resolved, resolvedModel, isSt
2939
2982
  upstreamUrl,
2940
2983
  proxyProviderId: profile.authStrategy.providerId,
2941
2984
  providerIdentity: resolved.providerIdentity,
2942
- callerClientHeaders: profile.authStrategy.providerId === "codex" ? _chunkAFH5CEMFcjs.extractCodexClientHeaders.call(void 0, requestHeaders) : void 0,
2985
+ callerClientHeaders: profile.authStrategy.providerId === "codex" ? _chunkSQU2FGXIcjs.extractCodexClientHeaders.call(void 0, requestHeaders) : void 0,
2943
2986
  // opencodego-egress-identity: the caller's own session id, forwarded
2944
2987
  // verbatim to opencode.ai (the codex callerClientHeaders precedent).
2945
- callerOpenCodeSession: profile.authStrategy.providerId === "opencodego" ? _chunkWYECWQ3Jcjs.extractOpenCodeSessionHeader.call(void 0, requestHeaders) : void 0,
2988
+ callerOpenCodeSession: profile.authStrategy.providerId === "opencodego" ? _chunk2DMOOZ4Fcjs.extractOpenCodeSessionHeader.call(void 0, requestHeaders) : void 0,
2946
2989
  statefulContinuation: !!affinity,
2947
2990
  credential: affinityAccountId ? { kind: "subscription-account", id: affinityAccountId } : { kind: "subscription-account", id: "pending-selection" }
2948
2991
  };
@@ -2952,14 +2995,14 @@ async function resolveGeminiProject(profile, hints) {
2952
2995
  await profile.authStrategy.applyHeaders(headers, hints);
2953
2996
  const accessToken = (_nullishCoalesce(_nullishCoalesce(headers.Authorization, () => ( headers.authorization)), () => ( ""))).replace(/^Bearer\s+/i, "").trim();
2954
2997
  if (!accessToken) return void 0;
2955
- return _optionalChain([_chunkR3HK6R4Bcjs.getGeminiCodeAssistResolver.call(void 0, ), 'optionalAccess', _150 => _150.resolveProject, 'call', _151 => _151(accessToken)]);
2998
+ return _optionalChain([_chunkR3HK6R4Bcjs.getGeminiCodeAssistResolver.call(void 0, ), 'optionalAccess', _155 => _155.resolveProject, 'call', _156 => _156(accessToken)]);
2956
2999
  }
2957
3000
  async function resolveAntigravityProjectThreaded(profile, hints) {
2958
3001
  const headers = {};
2959
3002
  await profile.authStrategy.applyHeaders(headers, hints);
2960
3003
  const accessToken = (_nullishCoalesce(_nullishCoalesce(headers.Authorization, () => ( headers.authorization)), () => ( ""))).replace(/^Bearer\s+/i, "").trim();
2961
3004
  if (!accessToken) return void 0;
2962
- return _chunkNDIBVTBZcjs.getAntigravityProjectResolver.call(void 0, ).resolveProject(accessToken);
3005
+ return _chunkXYFCNDJKcjs.getAntigravityProjectResolver.call(void 0, ).resolveProject(accessToken);
2963
3006
  }
2964
3007
  async function executeResponsesUpstream(body, plan, operation, signal) {
2965
3008
  const run = () => plan.profile === "native" ? runNative(body, plan, operation, signal) : runReduced(body, plan, signal);
@@ -2967,16 +3010,16 @@ async function executeResponsesUpstream(body, plan, operation, signal) {
2967
3010
  throwIfResponsesAborted(signal);
2968
3011
  if (!plan.statefulContinuation) {
2969
3012
  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)]);
3013
+ const outcome = await _optionalChain([plan, 'access', _157 => _157.auth, 'access', _158 => _158.onResult, 'optionalCall', _159 => _159(result.rawStatus)]);
3014
+ if (_optionalChain([outcome, 'optionalAccess', _160 => _160.rebound])) {
3015
+ 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
3016
  throwIfResponsesAborted(signal);
2974
3017
  result = await run();
2975
3018
  }
2976
3019
  } else if (result.rawStatus === 401) {
2977
- const refreshed = await _optionalChain([plan, 'access', _162 => _162.auth, 'access', _163 => _163.onUnauthorized, 'optionalCall', _164 => _164(plan.sessionKey)]);
3020
+ const refreshed = await _optionalChain([plan, 'access', _167 => _167.auth, 'access', _168 => _168.onUnauthorized, 'optionalCall', _169 => _169(plan.sessionKey)]);
2978
3021
  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)]);
3022
+ 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
3023
  throwIfResponsesAborted(signal);
2981
3024
  result = await run();
2982
3025
  }
@@ -2985,6 +3028,32 @@ async function executeResponsesUpstream(body, plan, operation, signal) {
2985
3028
  }
2986
3029
  return result;
2987
3030
  }
3031
+ function buildResponsesRouteActivity(plan, accountId, actualModel, onRecorded) {
3032
+ if (plan.proxyProviderId === "byo") {
3033
+ const contentKey = _optionalChain([plan, 'access', _176 => _176.sessionKey, 'optionalAccess', _177 => _177.trim, 'call', _178 => _178()]) || void 0;
3034
+ const routeSessionId = plan.byoSessionId || void 0;
3035
+ return {
3036
+ providerId: _nullishCoalesce(_optionalChain([plan, 'access', _179 => _179.byoActivity, 'optionalAccess', _180 => _180.providerId]), () => ( plan.providerIdentity)),
3037
+ credentialKind: "provider-key",
3038
+ keyId: _optionalChain([plan, 'access', _181 => _181.byoActivity, 'optionalAccess', _182 => _182.resolveKeyId, 'call', _183 => _183()]),
3039
+ endpoint: "responses",
3040
+ sessionKey: _nullishCoalesce(contentKey, () => ( routeSessionId)),
3041
+ sessionSource: contentKey ? _nullishCoalesce(plan.sessionSource, () => ( "none")) : routeSessionId ? "route-session-id" : "none",
3042
+ model: actualModel,
3043
+ onRecorded
3044
+ };
3045
+ }
3046
+ return {
3047
+ providerId: plan.proxyProviderId,
3048
+ credentialKind: "subscription-account",
3049
+ accountId,
3050
+ endpoint: "responses",
3051
+ sessionKey: plan.sessionKey,
3052
+ sessionSource: _nullishCoalesce(plan.sessionSource, () => ( "none")),
3053
+ model: actualModel,
3054
+ onRecorded
3055
+ };
3056
+ }
2988
3057
  async function applyPlanAuth(body, plan) {
2989
3058
  let accountId;
2990
3059
  let actualModel = plan.resolvedModel;
@@ -3004,13 +3073,14 @@ async function applyPlanAuth(body, plan) {
3004
3073
  });
3005
3074
  body.model = actualModel;
3006
3075
  plan.transformerProvider.models = [actualModel];
3076
+ if (plan.proxyProviderId === "codex") body.store = false;
3007
3077
  return { headers, accountId, actualModel };
3008
3078
  }
3009
3079
  function decorateCodexHeaders(headers, plan) {
3010
3080
  if (plan.proxyProviderId !== "codex") return;
3011
3081
  _chunkUKQHBK4Qcjs.fillMissingHeaders.call(void 0, headers, _nullishCoalesce(plan.callerClientHeaders, () => ( {})));
3012
- _chunkUKQHBK4Qcjs.fillMissingHeaders.call(void 0, headers, _chunkAFH5CEMFcjs.DEFAULT_CODEX_CLI_HEADERS);
3013
- _chunkUKQHBK4Qcjs.fillMissingHeaders.call(void 0, headers, { accept: _chunkAFH5CEMFcjs.codexAcceptHeader.call(void 0, plan.isStream) });
3082
+ _chunkUKQHBK4Qcjs.fillMissingHeaders.call(void 0, headers, { accept: _chunkSQU2FGXIcjs.codexAcceptHeader.call(void 0, plan.isStream) });
3083
+ _chunkSQU2FGXIcjs.fillMissingCodexCliIdentity.call(void 0, headers);
3014
3084
  }
3015
3085
  async function runNative(body, plan, operation, signal) {
3016
3086
  throwIfResponsesAborted(signal);
@@ -3019,21 +3089,15 @@ async function runNative(body, plan, operation, signal) {
3019
3089
  decorateCodexHeaders(headers, plan);
3020
3090
  const url = operation === "compact" ? deriveResponsesCompactUrl(plan.upstreamUrl) : plan.upstreamUrl;
3021
3091
  let activityRecordId;
3022
- const response = await _chunkVFFCV4J6cjs.fetchUpstream.call(void 0,
3092
+ const response = await _chunkCXRJMNJJcjs.fetchUpstream.call(void 0,
3023
3093
  url,
3024
3094
  { method: "POST", headers, body: JSON.stringify(body), signal },
3025
3095
  {
3026
3096
  providerId: plan.proxyProviderId,
3027
3097
  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
- }
3098
+ routeActivity: buildResponsesRouteActivity(plan, accountId, actualModel, (record5) => {
3099
+ activityRecordId = record5.id;
3100
+ })
3037
3101
  }
3038
3102
  );
3039
3103
  return {
@@ -3042,7 +3106,7 @@ async function runNative(body, plan, operation, signal) {
3042
3106
  accountId,
3043
3107
  actualModel,
3044
3108
  activityRecordId,
3045
- credential: accountId ? { kind: "subscription-account", id: accountId } : _nullishCoalesce(_optionalChain([plan, 'access', _171 => _171.resolveCredential, 'optionalCall', _172 => _172()]), () => ( plan.credential))
3109
+ credential: accountId ? { kind: "subscription-account", id: accountId } : _nullishCoalesce(_optionalChain([plan, 'access', _184 => _184.resolveCredential, 'optionalCall', _185 => _185()]), () => ( plan.credential))
3046
3110
  };
3047
3111
  }
3048
3112
  async function runReduced(body, plan, signal) {
@@ -3050,7 +3114,7 @@ async function runReduced(body, plan, signal) {
3050
3114
  const { headers: authHeaders, accountId, actualModel } = await applyPlanAuth(body, plan);
3051
3115
  if (plan.proxyProviderId === "antigravity") {
3052
3116
  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);
3117
+ if (bearer) plan.transformerProvider.geminiProject = await _chunkXYFCNDJKcjs.getAntigravityProjectResolver.call(void 0, ).resolveProject(bearer);
3054
3118
  }
3055
3119
  let rawStatus = null;
3056
3120
  let activityRecordId;
@@ -3072,24 +3136,18 @@ async function runReduced(body, plan, signal) {
3072
3136
  return headers;
3073
3137
  },
3074
3138
  fetchFn: async (url, headers, requestBody) => {
3075
- const send = (target) => _chunkVFFCV4J6cjs.fetchUpstream.call(void 0,
3139
+ const send = (target) => _chunkCXRJMNJJcjs.fetchUpstream.call(void 0,
3076
3140
  target,
3077
3141
  { method: "POST", headers, body: JSON.stringify(requestBody), signal },
3078
3142
  {
3079
3143
  providerId: plan.proxyProviderId,
3080
3144
  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
- }
3145
+ routeActivity: buildResponsesRouteActivity(plan, accountId, actualModel, (record5) => {
3146
+ activityRecordId = record5.id;
3147
+ })
3090
3148
  }
3091
3149
  );
3092
- const upstream = plan.proxyProviderId === "antigravity" ? await _chunkCGEZQC2Gcjs.fetchWithAntigravityFailover.call(void 0, url, send, signal) : await send(url);
3150
+ const upstream = plan.proxyProviderId === "antigravity" ? await _chunkF3TT5XPVcjs.fetchWithAntigravityFailover.call(void 0, url, send, signal) : await send(url);
3093
3151
  rawStatus = upstream.status;
3094
3152
  return upstream;
3095
3153
  },
@@ -3102,7 +3160,7 @@ async function runReduced(body, plan, signal) {
3102
3160
  accountId,
3103
3161
  actualModel,
3104
3162
  activityRecordId,
3105
- credential: accountId ? { kind: "subscription-account", id: accountId } : _nullishCoalesce(_optionalChain([plan, 'access', _173 => _173.resolveCredential, 'optionalCall', _174 => _174()]), () => ( plan.credential))
3163
+ credential: accountId ? { kind: "subscription-account", id: accountId } : _nullishCoalesce(_optionalChain([plan, 'access', _186 => _186.resolveCredential, 'optionalCall', _187 => _187()]), () => ( plan.credential))
3106
3164
  };
3107
3165
  }
3108
3166
  var MAX_QUOTA_RETRIES = 3;
@@ -3125,7 +3183,7 @@ function record(value) {
3125
3183
  return !!value && typeof value === "object" && !Array.isArray(value);
3126
3184
  }
3127
3185
  function hasResponsesHostedImageWork(body, previousState) {
3128
- if (_optionalChain([previousState, 'optionalAccess', _175 => _175.hasImageContext]) || _optionalChain([previousState, 'optionalAccess', _176 => _176.pendingReceipts, 'access', _177 => _177.length])) return true;
3186
+ if (_optionalChain([previousState, 'optionalAccess', _188 => _188.hasImageContext]) || _optionalChain([previousState, 'optionalAccess', _189 => _189.pendingReceipts, 'access', _190 => _190.length])) return true;
3129
3187
  if (Array.isArray(body.tools) && body.tools.some((tool) => record(tool) && tool.type === "image_generation")) {
3130
3188
  return true;
3131
3189
  }
@@ -3309,7 +3367,7 @@ function createNonCollidingSelectorName(tools, createName) {
3309
3367
  let candidate;
3310
3368
  try {
3311
3369
  candidate = createName();
3312
- } catch (e26) {
3370
+ } catch (e27) {
3313
3371
  throw new (0, _chunkINY54AYXcjs.ImageGenerationError)("image_generation_failed");
3314
3372
  }
3315
3373
  if (typeof candidate === "string" && SELECTOR_NAME_PATTERN.test(candidate) && !declaredNames.has(candidate)) {
@@ -3328,7 +3386,7 @@ function parseSelectorPrompt(value) {
3328
3386
  let parsed;
3329
3387
  try {
3330
3388
  parsed = JSON.parse(value);
3331
- } catch (e27) {
3389
+ } catch (e28) {
3332
3390
  protocolFailure();
3333
3391
  }
3334
3392
  if (!isRecord4(parsed) || Object.keys(parsed).some((key) => key !== "prompt") || typeof parsed.prompt !== "string" || !parsed.prompt.trim() || parsed.prompt.length > 32e3) {
@@ -3545,7 +3603,7 @@ function parseSelectorArguments(value) {
3545
3603
  let parsed;
3546
3604
  try {
3547
3605
  parsed = JSON.parse(value);
3548
- } catch (e28) {
3606
+ } catch (e29) {
3549
3607
  return void 0;
3550
3608
  }
3551
3609
  if (!isRecord5(parsed) || typeof parsed.query !== "string") return void 0;
@@ -3673,7 +3731,7 @@ var NativeResponsesSearchLease = class {
3673
3731
  let parsed;
3674
3732
  try {
3675
3733
  parsed = JSON.parse(text);
3676
- } catch (e29) {
3734
+ } catch (e30) {
3677
3735
  return responseWithBody(input.response, text, false);
3678
3736
  }
3679
3737
  if (!isRecord6(parsed)) return responseWithBody(input.response, text, false);
@@ -3774,18 +3832,18 @@ function responsesSearchDisabledError() {
3774
3832
  var SERVER_OVERLOADED_CODES = /* @__PURE__ */ new Set(["server_is_overloaded", "slow_down"]);
3775
3833
  function isCodexServerOverloadEvent(event) {
3776
3834
  const error = codexResponseFailedError(event);
3777
- const code = _optionalChain([error, 'optionalAccess', _178 => _178["code"]]);
3835
+ const code = _optionalChain([error, 'optionalAccess', _191 => _191["code"]]);
3778
3836
  return typeof code === "string" && SERVER_OVERLOADED_CODES.has(code);
3779
3837
  }
3780
3838
  function codexResponseFailedError(event) {
3781
3839
  if (event["type"] !== "response.failed") return void 0;
3782
- const error = _optionalChain([event, 'access', _179 => _179["response"], 'optionalAccess', _180 => _180["error"]]);
3840
+ const error = _optionalChain([event, 'access', _192 => _192["response"], 'optionalAccess', _193 => _193["error"]]);
3783
3841
  return error && typeof error === "object" ? error : void 0;
3784
3842
  }
3785
3843
  var USAGE_LIMIT_CODES = /* @__PURE__ */ new Set(["usage_limit_reached", "usage_not_included"]);
3786
3844
  function isCodexUsageLimitEvent(event) {
3787
3845
  const error = codexResponseFailedError(event);
3788
- const code = _optionalChain([error, 'optionalAccess', _181 => _181["code"]]);
3846
+ const code = _optionalChain([error, 'optionalAccess', _194 => _194["code"]]);
3789
3847
  return typeof code === "string" && USAGE_LIMIT_CODES.has(code);
3790
3848
  }
3791
3849
  function codexUsageLimitEventBody(event) {
@@ -3819,7 +3877,7 @@ async function handleOpenAIResponsesRequest(res, rawBody, route, deps, requestHe
3819
3877
  let parsedBody;
3820
3878
  try {
3821
3879
  parsedBody = JSON.parse(rawBody);
3822
- } catch (e30) {
3880
+ } catch (e31) {
3823
3881
  writeError(res, 400, "Invalid JSON in request body");
3824
3882
  return;
3825
3883
  }
@@ -3832,7 +3890,7 @@ async function handleOpenAIResponsesRequest(res, rawBody, route, deps, requestHe
3832
3890
  return;
3833
3891
  }
3834
3892
  const responsesBody = parsedBody;
3835
- _optionalChain([onStreamModeResolved, 'optionalCall', _182 => _182(responsesBody.stream === true)]);
3893
+ _optionalChain([onStreamModeResolved, 'optionalCall', _195 => _195(responsesBody.stream === true)]);
3836
3894
  try {
3837
3895
  await handleResponsesOperation(
3838
3896
  res,
@@ -3912,7 +3970,7 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
3912
3970
  throw error;
3913
3971
  }
3914
3972
  const cacheKeyAttribution = operation === "create" ? ensureCodexPromptCacheKey(responsesBody, plan.proxyProviderId, derivedSession) : { cacheKeySource: "none", cacheKeyInjected: false };
3915
- const previousHostedImageState = _optionalChain([affinity, 'optionalAccess', _183 => _183.hostedImage]);
3973
+ const previousHostedImageState = _optionalChain([affinity, 'optionalAccess', _196 => _196.hostedImage]);
3916
3974
  const hasHostedImageWork = operation === "create" && hasResponsesHostedImageWork(
3917
3975
  responsesBody,
3918
3976
  previousHostedImageState
@@ -3942,7 +4000,7 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
3942
4000
  message: "Hosted image generation requires an authenticated outbound key"
3943
4001
  });
3944
4002
  }
3945
- const searchMode = operation === "create" ? _nullishCoalesce(_optionalChain([deps, 'access', _184 => _184.searchFrontendModes, 'optionalAccess', _185 => _185.responses]), () => ( _chunkE4QHVXV5cjs.DEFAULT_SEARCH_FRONTEND_MODES.responses)) : "native";
4003
+ const searchMode = operation === "create" ? _nullishCoalesce(_optionalChain([deps, 'access', _197 => _197.searchFrontendModes, 'optionalAccess', _198 => _198.responses]), () => ( _chunkE4QHVXV5cjs.DEFAULT_SEARCH_FRONTEND_MODES.responses)) : "native";
3946
4004
  const wantsHostedSearch = operation === "create" && hasResponsesHostedSearchWork(responsesBody);
3947
4005
  if (wantsHostedSearch && searchMode === "off") {
3948
4006
  throw responsesSearchDisabledError();
@@ -3997,16 +4055,16 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
3997
4055
  let providerResponse;
3998
4056
  try {
3999
4057
  if (hostedImageRequest) {
4000
- _optionalChain([route, 'access', _186 => _186.suppressAuditBodies, 'optionalCall', _187 => _187()]);
4058
+ _optionalChain([route, 'access', _199 => _199.suppressAuditBodies, 'optionalCall', _200 => _200()]);
4001
4059
  }
4002
4060
  providerResponse = await executeResponsesUpstream(
4003
- _nullishCoalesce(_nullishCoalesce(_optionalChain([searchRequest, 'optionalAccess', _188 => _188.upstreamBody]), () => ( _optionalChain([hostedImageRequest, 'optionalAccess', _189 => _189.upstreamBody]))), () => ( responsesBody)),
4061
+ _nullishCoalesce(_nullishCoalesce(_optionalChain([searchRequest, 'optionalAccess', _201 => _201.upstreamBody]), () => ( _optionalChain([hostedImageRequest, 'optionalAccess', _202 => _202.upstreamBody]))), () => ( responsesBody)),
4004
4062
  plan,
4005
4063
  operation,
4006
4064
  signal
4007
4065
  );
4008
4066
  } catch (error) {
4009
- await _optionalChain([hostedImageRequest, 'optionalAccess', _190 => _190.dispose, 'call', _191 => _191()]);
4067
+ await _optionalChain([hostedImageRequest, 'optionalAccess', _203 => _203.dispose, 'call', _204 => _204()]);
4010
4068
  if (affinity && _chunk25GXJCEZcjs.isBoundAccountSelectionError.call(void 0, error)) {
4011
4069
  throw previousResponseNotFound();
4012
4070
  }
@@ -4027,7 +4085,7 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
4027
4085
  extractUsage(event) {
4028
4086
  if (event.type !== "response.completed") return null;
4029
4087
  const response = event.response;
4030
- return _optionalChain([response, 'optionalAccess', _192 => _192.usage]);
4088
+ return _optionalChain([response, 'optionalAccess', _205 => _205.usage]);
4031
4089
  },
4032
4090
  onUsage(rawUsage) {
4033
4091
  recordResponsesStreamUsage(usageRecorder, rawUsage, usageAttribution);
@@ -4074,7 +4132,7 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
4074
4132
  let usageLimitRecorded = false;
4075
4133
  const observeSse = (event) => {
4076
4134
  if (event.type === "response.completed") {
4077
- recordAffinity(_optionalChain([event, 'access', _193 => _193.response, 'optionalAccess', _194 => _194.id]));
4135
+ recordAffinity(_optionalChain([event, 'access', _206 => _206.response, 'optionalAccess', _207 => _207.id]));
4078
4136
  }
4079
4137
  if (!usageLimitRecorded && isCodexUsageLimitEvent(event)) {
4080
4138
  usageLimitRecorded = true;
@@ -4089,7 +4147,7 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
4089
4147
  if (overloadRecorded || !isCodexServerOverloadEvent(event)) return;
4090
4148
  overloadRecorded = true;
4091
4149
  if (providerResponse.activityRecordId) {
4092
- _chunkNKVZ6Z3Ycjs.getSharedAccountRouteActivity.call(void 0, ).amend(providerResponse.activityRecordId, { streamError: "server_overloaded" });
4150
+ _chunk4HMAS74Xcjs.getSharedAccountRouteActivity.call(void 0, ).amend(providerResponse.activityRecordId, { streamError: "server_overloaded" });
4093
4151
  }
4094
4152
  if (providerResponse.accountId) {
4095
4153
  _chunkOTZC4TNHcjs.getSharedOverloadCounter.call(void 0, ).recordOverload({
@@ -4111,14 +4169,14 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
4111
4169
  signal
4112
4170
  );
4113
4171
  } finally {
4114
- await _optionalChain([hostedImageRequest, 'optionalAccess', _195 => _195.dispose, 'call', _196 => _196()]);
4172
+ await _optionalChain([hostedImageRequest, 'optionalAccess', _208 => _208.dispose, 'call', _209 => _209()]);
4115
4173
  }
4116
4174
  if (!bodyText) return;
4117
4175
  if (usageRecorder) recordResponsesNonStreamUsage(usageRecorder, bodyText, usageAttribution);
4118
4176
  try {
4119
4177
  const body = JSON.parse(bodyText);
4120
4178
  if (body.status !== "failed" && body.status !== "incomplete") recordAffinity(body.id);
4121
- } catch (e31) {
4179
+ } catch (e32) {
4122
4180
  }
4123
4181
  }
4124
4182
 
@@ -4127,7 +4185,7 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
4127
4185
  let anthropicBody;
4128
4186
  try {
4129
4187
  anthropicBody = JSON.parse(rawBody);
4130
- } catch (e32) {
4188
+ } catch (e33) {
4131
4189
  writeError(res, 400, "Invalid JSON in request body");
4132
4190
  return;
4133
4191
  }
@@ -4165,7 +4223,7 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
4165
4223
  extractUsage(event) {
4166
4224
  if (event["type"] === "message_start") {
4167
4225
  const msg = event["message"];
4168
- const u = _optionalChain([msg, 'optionalAccess', _197 => _197["usage"]]);
4226
+ const u = _optionalChain([msg, 'optionalAccess', _210 => _210["usage"]]);
4169
4227
  if (u) anthropicInputUsage = u;
4170
4228
  return null;
4171
4229
  }
@@ -4188,7 +4246,7 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
4188
4246
  if (!usageLimitRecorded) {
4189
4247
  let limitHit = isCodexUsageLimitEvent(event);
4190
4248
  if (!limitHit && event["type"] === "error") {
4191
- const message = _optionalChain([event, 'access', _198 => _198["error"], 'optionalAccess', _199 => _199["message"]]);
4249
+ const message = _optionalChain([event, 'access', _211 => _211["error"], 'optionalAccess', _212 => _212["message"]]);
4192
4250
  limitHit = typeof message === "string" && (message.includes("usage_limit_reached") || message.includes("usage_not_included"));
4193
4251
  }
4194
4252
  if (limitHit) {
@@ -4205,13 +4263,13 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
4205
4263
  if (overloadRecorded) return;
4206
4264
  let hit = isCodexServerOverloadEvent(event);
4207
4265
  if (!hit && event["type"] === "error") {
4208
- const message = _optionalChain([event, 'access', _200 => _200["error"], 'optionalAccess', _201 => _201["message"]]);
4266
+ const message = _optionalChain([event, 'access', _213 => _213["error"], 'optionalAccess', _214 => _214["message"]]);
4209
4267
  hit = typeof message === "string" && (message.includes("server_is_overloaded") || message.includes("slow_down"));
4210
4268
  }
4211
4269
  if (!hit) return;
4212
4270
  overloadRecorded = true;
4213
4271
  if (overloadActivityId) {
4214
- _chunkNKVZ6Z3Ycjs.getSharedAccountRouteActivity.call(void 0, ).amend(overloadActivityId, {
4272
+ _chunk4HMAS74Xcjs.getSharedAccountRouteActivity.call(void 0, ).amend(overloadActivityId, {
4215
4273
  streamError: "server_overloaded"
4216
4274
  });
4217
4275
  }
@@ -4226,7 +4284,7 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
4226
4284
  let inbandOverloadRecorded = false;
4227
4285
  const inbandOverloadObserver = plan.isSubscription && plan.sameFormat && overloadAccountId ? (event) => {
4228
4286
  if (inbandOverloadRecorded || event["type"] !== "error") return;
4229
- const errorType = _optionalChain([event, 'access', _202 => _202["error"], 'optionalAccess', _203 => _203["type"]]);
4287
+ const errorType = _optionalChain([event, 'access', _215 => _215["error"], 'optionalAccess', _216 => _216["type"]]);
4230
4288
  if (errorType !== "overloaded_error") return;
4231
4289
  inbandOverloadRecorded = true;
4232
4290
  _chunk7LRTPNFLcjs.getSharedAccountHealth.call(void 0, ).recordUpstreamOutcome(
@@ -4263,7 +4321,7 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
4263
4321
  recordAnthropicNonStreamUsage(deps.usageRecorder, bodyText, usageAttribution);
4264
4322
  }
4265
4323
  } catch (err) {
4266
- if (_optionalChain([options, 'access', _204 => _204.signal, 'optionalAccess', _205 => _205.aborted])) return;
4324
+ if (_optionalChain([options, 'access', _217 => _217.signal, 'optionalAccess', _218 => _218.aborted])) return;
4267
4325
  if (err instanceof DocumentNotSupportedError || err instanceof UnsupportedContentBlockError) {
4268
4326
  writeError(res, 400, `${err.message} [code: ${err.code}]`);
4269
4327
  return;
@@ -4329,7 +4387,9 @@ async function buildByoPlan2(res, route, deps, resolvedModel, isStream) {
4329
4387
  isSubscription: false,
4330
4388
  provider,
4331
4389
  apiKey,
4332
- extendedContextEnabled: _nullishCoalesce(_optionalChain([route, 'access', _206 => _206.anthropicSdkHints, 'optionalAccess', _207 => _207.extendedContext, 'optionalAccess', _208 => _208.enabled]), () => ( false))
4390
+ extendedContextEnabled: _nullishCoalesce(_optionalChain([route, 'access', _219 => _219.anthropicSdkHints, 'optionalAccess', _220 => _220.extendedContext, 'optionalAccess', _221 => _221.enabled]), () => ( false)),
4391
+ byoActivity: buildByoRouteActivityMeta(deps, providerId, route.sessionId),
4392
+ byoSessionId: _nullishCoalesce(route.sessionId, () => ( null))
4333
4393
  };
4334
4394
  }
4335
4395
  async function runSameFormatFetch(bodyToSend, plan, options, keyOverride, urlOverride) {
@@ -4339,7 +4399,7 @@ async function runSameFormatFetch(bodyToSend, plan, options, keyOverride, urlOve
4339
4399
  }
4340
4400
  const effectiveKey = _nullishCoalesce(_nullishCoalesce(keyOverride, () => ( apiKey)), () => ( ""));
4341
4401
  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()]);
4402
+ const callerBeta = _optionalChain([options, 'access', _222 => _222.callerAnthropicBeta, 'optionalAccess', _223 => _223.trim, 'call', _224 => _224()]);
4343
4403
  if (callerBeta) {
4344
4404
  const existing = _nullishCoalesce(headers["anthropic-beta"], () => ( headers["Anthropic-Beta"]));
4345
4405
  const parts = new Set(
@@ -4351,23 +4411,41 @@ async function runSameFormatFetch(bodyToSend, plan, options, keyOverride, urlOve
4351
4411
  }
4352
4412
  }
4353
4413
  _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()]);
4414
+ const callerVersion = _optionalChain([options, 'access', _225 => _225.callerAnthropicVersion, 'optionalAccess', _226 => _226.trim, 'call', _227 => _227()]);
4355
4415
  headers["anthropic-version"] = callerVersion || DEFAULT_ANTHROPIC_VERSION;
4356
4416
  const url = _nullishCoalesce(urlOverride, () => ( _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: resolvedModel, stream: isStream })));
4357
4417
  console.info(`[ProviderProxy:anthropic] (same-format) -> ${url} model=${resolvedModel} stream=${isStream}`);
4358
- const response = await _chunkVFFCV4J6cjs.fetchUpstream.call(void 0,
4418
+ let activityRecordId;
4419
+ const response = await _chunkCXRJMNJJcjs.fetchUpstream.call(void 0,
4359
4420
  url,
4360
4421
  { method: "POST", headers, body: bodyToSend, signal: options.signal },
4361
- { providerId: "byo" }
4422
+ {
4423
+ providerId: "byo",
4424
+ routeActivity: {
4425
+ providerId: _nullishCoalesce(_optionalChain([plan, 'access', _228 => _228.byoActivity, 'optionalAccess', _229 => _229.providerId]), () => ( provider.name)),
4426
+ credentialKind: "provider-key",
4427
+ // LIVE resolution: a pool rebind retry re-invokes this fetch, and the
4428
+ // binding has already rotated, so the retried attempt attributes the
4429
+ // NEW key. `keyOverride` is a key STRING (never recorded).
4430
+ keyId: _optionalChain([plan, 'access', _230 => _230.byoActivity, 'optionalAccess', _231 => _231.resolveKeyId, 'call', _232 => _232()]),
4431
+ endpoint: "messages",
4432
+ sessionKey: plan.byoSessionId || void 0,
4433
+ sessionSource: plan.byoSessionId ? "route-session-id" : "none",
4434
+ model: resolvedModel,
4435
+ onRecorded: (record5) => {
4436
+ activityRecordId = record5.id;
4437
+ }
4438
+ }
4439
+ }
4362
4440
  );
4363
- return { response, rawStatus: response.status };
4441
+ return { response, rawStatus: response.status, activityRecordId };
4364
4442
  }
4365
4443
  function resolveSameFormatBody(anthropicBody, rawBody, plan) {
4366
4444
  let originalModel;
4367
4445
  try {
4368
4446
  const m = JSON.parse(rawBody).model;
4369
4447
  originalModel = typeof m === "string" ? m : void 0;
4370
- } catch (e33) {
4448
+ } catch (e34) {
4371
4449
  originalModel = void 0;
4372
4450
  }
4373
4451
  return plan.resolvedModel !== originalModel ? JSON.stringify(anthropicBody) : rawBody;
@@ -4376,8 +4454,8 @@ async function runPipelineWithPoolReporting(anthropicBody, rawBody, plan, option
4376
4454
  const sameFormatBody = plan.sameFormat ? resolveSameFormatBody(anthropicBody, rawBody, plan) : rawBody;
4377
4455
  const runOnce = (keyOverride) => plan.sameFormat ? runSameFormatFetch(sameFormatBody, plan, options, keyOverride) : runPipeline(anthropicBody, plan, void 0, options.signal);
4378
4456
  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])) {
4457
+ const outcome = await _optionalChain([plan, 'access', _233 => _233.auth, 'access', _234 => _234.onResult, 'optionalCall', _235 => _235(first.rawStatus)]);
4458
+ if (_optionalChain([outcome, 'optionalAccess', _236 => _236.rebound])) {
4381
4459
  console.info(
4382
4460
  "[ProviderProxy:anthropic] pool re-bound key after status",
4383
4461
  first.rawStatus,
@@ -4463,7 +4541,7 @@ function countTools(tools, budget) {
4463
4541
  let serialized;
4464
4542
  try {
4465
4543
  serialized = _nullishCoalesce(JSON.stringify(tool), () => ( ""));
4466
- } catch (e34) {
4544
+ } catch (e35) {
4467
4545
  serialized = "";
4468
4546
  }
4469
4547
  if (!budget.addChars(serialized.length)) return;
@@ -4508,7 +4586,7 @@ async function handleAnthropicCountTokens(res, rawBody, route, deps, options = {
4508
4586
  let body;
4509
4587
  try {
4510
4588
  body = JSON.parse(rawBody);
4511
- } catch (e35) {
4589
+ } catch (e36) {
4512
4590
  writeError(res, 400, "Invalid JSON in request body");
4513
4591
  return;
4514
4592
  }
@@ -4540,7 +4618,7 @@ async function handleAnthropicCountTokens(res, rawBody, route, deps, options = {
4540
4618
  const providerResponse = plan.isSubscription ? await runSubscriptionCountTokensFetch(bodyToSend, plan, options, countTokensUrl) : await runByoCountTokensFetch(bodyToSend, plan, options, countTokensUrl);
4541
4619
  await relayResponse(res, providerResponse.response, false, void 0, void 0, void 0, options.signal);
4542
4620
  } catch (err) {
4543
- if (_optionalChain([options, 'access', _219 => _219.signal, 'optionalAccess', _220 => _220.aborted])) return;
4621
+ if (_optionalChain([options, 'access', _237 => _237.signal, 'optionalAccess', _238 => _238.aborted])) return;
4544
4622
  if (_chunk25GXJCEZcjs.isBoundAccountSelectionError.call(void 0, err)) {
4545
4623
  writeBoundAccountError(res, err);
4546
4624
  return;
@@ -4562,8 +4640,8 @@ function writeCountTokensEstimate(res, body, budgetMs) {
4562
4640
  async function runByoCountTokensFetch(bodyToSend, plan, options, url) {
4563
4641
  const runOnce = (keyOverride) => runSameFormatFetch(bodyToSend, plan, options, keyOverride, url);
4564
4642
  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])) {
4643
+ const outcome = await _optionalChain([plan, 'access', _239 => _239.auth, 'access', _240 => _240.onResult, 'optionalCall', _241 => _241(first.rawStatus)]);
4644
+ if (_optionalChain([outcome, 'optionalAccess', _242 => _242.rebound])) {
4567
4645
  await cancelDiscardedResponse(first.response);
4568
4646
  console.info(
4569
4647
  "[ProviderProxy:anthropic] pool re-bound key after status",
@@ -4581,7 +4659,7 @@ async function runSubscriptionCountTokensFetch(bodyToSend, plan, options, url) {
4581
4659
  // src/provider-proxy/ingress/anthropicPathMatch.ts
4582
4660
  function classifyAnthropicMessagesPath(url) {
4583
4661
  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(/\/+$/, "")]), () => ( ""));
4662
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _243 => _243.split, 'call', _244 => _244("?"), 'access', _245 => _245[0], 'optionalAccess', _246 => _246.replace, 'call', _247 => _247(/\/+$/, "")]), () => ( ""));
4585
4663
  if (path.endsWith("/v1/messages/count_tokens")) return "count_tokens";
4586
4664
  if (path.endsWith("/v1/messages")) return "messages";
4587
4665
  if (/\/v1\/messages\/.+/.test(path)) return "unsupported-subpath";
@@ -4609,7 +4687,7 @@ async function handleAnthropicMessagesRequest(req, res, route, deps) {
4609
4687
  const callerAnthropicVersion = Array.isArray(callerVersionRaw) ? callerVersionRaw.join(",") : callerVersionRaw;
4610
4688
  const callerIdentity = _chunk6RPZADX3cjs.captureCallerIdentity.call(void 0, _chunkRPII3E6Zcjs.getSharedIdentityStore.call(void 0, ), request.headers);
4611
4689
  const callerClientHeaders = extractClaudeClientHeaders(request.headers);
4612
- const callerOpenCodeSession = _chunkWYECWQ3Jcjs.extractOpenCodeSessionHeader.call(void 0, request.headers);
4690
+ const callerOpenCodeSession = _chunk2DMOOZ4Fcjs.extractOpenCodeSessionHeader.call(void 0, request.headers);
4613
4691
  await handleAnthropicCountTokens(res, rawBody, route, deps, {
4614
4692
  callerAnthropicBeta,
4615
4693
  callerAnthropicVersion,
@@ -4625,14 +4703,14 @@ async function handleAnthropicMessagesRequest(req, res, route, deps) {
4625
4703
  }
4626
4704
  return;
4627
4705
  }
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));
4706
+ const searchMode = _nullishCoalesce(_optionalChain([deps, 'access', _248 => _248.searchFrontendModes, 'optionalAccess', _249 => _249.anthropic]), () => ( _chunkE4QHVXV5cjs.DEFAULT_SEARCH_FRONTEND_MODES.anthropic));
4707
+ const routeSuppliedSearchBackend = _nullishCoalesce(_optionalChain([route, 'access', _250 => _250.anthropicSdkHints, 'optionalAccess', _251 => _251.webSearchService]), () => ( null));
4630
4708
  if (searchMode !== "native" && !routeSuppliedSearchBackend) {
4631
4709
  const preReadBody = await readBody(req);
4632
4710
  let parsedForSearch;
4633
4711
  try {
4634
4712
  parsedForSearch = preReadBody ? JSON.parse(preReadBody) : {};
4635
- } catch (e36) {
4713
+ } catch (e37) {
4636
4714
  parsedForSearch = void 0;
4637
4715
  }
4638
4716
  const handled = await handleAnthropicManagedSearch(res, parsedForSearch, {
@@ -4654,7 +4732,7 @@ async function handleAnthropicMessagesRequest(req, res, route, deps) {
4654
4732
  const callerAnthropicVersion = Array.isArray(callerVersionRaw) ? callerVersionRaw.join(",") : callerVersionRaw;
4655
4733
  const callerIdentity = _chunk6RPZADX3cjs.captureCallerIdentity.call(void 0, _chunkRPII3E6Zcjs.getSharedIdentityStore.call(void 0, ), request.headers);
4656
4734
  const callerClientHeaders = extractClaudeClientHeaders(request.headers);
4657
- const callerOpenCodeSession = _chunkWYECWQ3Jcjs.extractOpenCodeSessionHeader.call(void 0, request.headers);
4735
+ const callerOpenCodeSession = _chunk2DMOOZ4Fcjs.extractOpenCodeSessionHeader.call(void 0, request.headers);
4658
4736
  await handleAnthropicMessagesByo(res, rawBody, route, deps, {
4659
4737
  callerAnthropicBeta,
4660
4738
  callerAnthropicVersion,
@@ -4759,10 +4837,10 @@ function emitGeminiUsageRecord(recorder, rawUsageMetadata, attribution) {
4759
4837
  providerId: attribution.providerId,
4760
4838
  model: attribution.model,
4761
4839
  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)),
4840
+ runId: _nullishCoalesce(_optionalChain([attribution, 'access', _252 => _252.routeLease, 'optionalAccess', _253 => _253.runId]), () => ( null)),
4841
+ routeLeaseId: _nullishCoalesce(_optionalChain([attribution, 'access', _254 => _254.routeLease, 'optionalAccess', _255 => _255.leaseId]), () => ( null)),
4842
+ routeLeaseConsumer: _nullishCoalesce(_optionalChain([attribution, 'access', _256 => _256.routeLease, 'optionalAccess', _257 => _257.consumer]), () => ( null)),
4843
+ routeLeaseStageId: _nullishCoalesce(_optionalChain([attribution, 'access', _258 => _258.routeLease, 'optionalAccess', _259 => _259.stageId]), () => ( null)),
4766
4844
  auditResponse: attribution.auditResponse,
4767
4845
  engineOrigin: "codex-ingress",
4768
4846
  usage: tapped,
@@ -4777,13 +4855,13 @@ function recordGeminiNonStreamUsage(recorder, bodyText, attribution) {
4777
4855
  parsed.usageMetadata,
4778
4856
  attribution
4779
4857
  );
4780
- } catch (e37) {
4858
+ } catch (e38) {
4781
4859
  }
4782
4860
  }
4783
4861
  function recordGeminiStreamUsage(recorder, rawUsageMetadata, attribution) {
4784
4862
  try {
4785
4863
  emitGeminiUsageRecord(recorder, rawUsageMetadata, attribution);
4786
- } catch (e38) {
4864
+ } catch (e39) {
4787
4865
  }
4788
4866
  }
4789
4867
 
@@ -4792,14 +4870,14 @@ var GENERATE_CONTENT_ACTION = ":generateContent";
4792
4870
  var STREAM_GENERATE_CONTENT_ACTION = ":streamGenerateContent";
4793
4871
  function isGeminiGenerateContentRequest(method, url) {
4794
4872
  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(/\/+$/, "")]), () => ( ""));
4873
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _260 => _260.split, 'call', _261 => _261("?"), 'access', _262 => _262[0], 'optionalAccess', _263 => _263.replace, 'call', _264 => _264(/\/+$/, "")]), () => ( ""));
4796
4874
  const lastSegment = _nullishCoalesce(path.split("/").pop(), () => ( ""));
4797
4875
  return lastSegment.includes(STREAM_GENERATE_CONTENT_ACTION) || lastSegment.includes(GENERATE_CONTENT_ACTION);
4798
4876
  }
4799
4877
  function isGeminiStreamRequest(url) {
4800
4878
  if (!url) return false;
4801
4879
  const [path, query = ""] = url.split("?");
4802
- const lastSegment = _nullishCoalesce((_nullishCoalesce(_optionalChain([path, 'optionalAccess', _247 => _247.replace, 'call', _248 => _248(/\/+$/, "")]), () => ( ""))).split("/").pop(), () => ( ""));
4880
+ const lastSegment = _nullishCoalesce((_nullishCoalesce(_optionalChain([path, 'optionalAccess', _265 => _265.replace, 'call', _266 => _266(/\/+$/, "")]), () => ( ""))).split("/").pop(), () => ( ""));
4803
4881
  if (lastSegment.includes(STREAM_GENERATE_CONTENT_ACTION)) return true;
4804
4882
  return /(^|&)alt=sse(&|$)/.test(query);
4805
4883
  }
@@ -4807,7 +4885,7 @@ async function handleGeminiGenerateContentRequest(res, rawBody, url, route, deps
4807
4885
  let geminiBody;
4808
4886
  try {
4809
4887
  geminiBody = JSON.parse(rawBody);
4810
- } catch (e39) {
4888
+ } catch (e40) {
4811
4889
  writeError(res, 400, "Invalid JSON in request body");
4812
4890
  return;
4813
4891
  }
@@ -4903,7 +4981,9 @@ async function buildByoPlan3(res, route, deps, resolvedModel, isStream) {
4903
4981
  resolvedModel,
4904
4982
  isStream,
4905
4983
  resolveUrl: (config) => config.url instanceof URL ? config.url.toString() : byoUrl,
4906
- upstreamUrl: byoUrl
4984
+ upstreamUrl: byoUrl,
4985
+ byoActivity: buildByoRouteActivityMeta(deps, providerId, route.sessionId),
4986
+ byoSessionId: _nullishCoalesce(route.sessionId, () => ( null))
4907
4987
  };
4908
4988
  }
4909
4989
  async function runPipeline2(geminiBody, plan) {
@@ -4931,10 +5011,21 @@ async function runPipeline2(geminiBody, plan) {
4931
5011
  },
4932
5012
  fetchFn: (url, headers, body) => {
4933
5013
  console.log(`[ProviderProxy:gemini] -> ${url} model=${resolvedModel} stream=${isStream}`);
4934
- return _chunkVFFCV4J6cjs.fetchUpstream.call(void 0,
5014
+ return _chunkCXRJMNJJcjs.fetchUpstream.call(void 0,
4935
5015
  url,
4936
5016
  { method: "POST", headers, body: JSON.stringify(body) },
4937
- { providerId: "byo" }
5017
+ {
5018
+ providerId: "byo",
5019
+ routeActivity: {
5020
+ providerId: _nullishCoalesce(_optionalChain([plan, 'access', _267 => _267.byoActivity, 'optionalAccess', _268 => _268.providerId]), () => ( transformerProvider.name)),
5021
+ credentialKind: "provider-key",
5022
+ keyId: _optionalChain([plan, 'access', _269 => _269.byoActivity, 'optionalAccess', _270 => _270.resolveKeyId, 'call', _271 => _271()]),
5023
+ endpoint: "generateContent",
5024
+ sessionKey: plan.byoSessionId || void 0,
5025
+ sessionSource: plan.byoSessionId ? "route-session-id" : "none",
5026
+ model: resolvedModel
5027
+ }
5028
+ }
4938
5029
  ).then((r) => {
4939
5030
  rawStatus = r.status;
4940
5031
  return r;
@@ -4946,8 +5037,8 @@ async function runPipeline2(geminiBody, plan) {
4946
5037
  }
4947
5038
  async function runPipelineWithPoolReporting2(geminiBody, plan) {
4948
5039
  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])) {
5040
+ const outcome = await _optionalChain([plan, 'access', _272 => _272.auth, 'access', _273 => _273.onResult, 'optionalCall', _274 => _274(first.rawStatus)]);
5041
+ if (_optionalChain([outcome, 'optionalAccess', _275 => _275.rebound])) {
4951
5042
  console.log(
4952
5043
  "[ProviderProxy:gemini] pool re-bound key after status",
4953
5044
  first.rawStatus,
@@ -4986,10 +5077,10 @@ function emitChatCompletionsUsageRecord(recorder, rawUsage, attribution) {
4986
5077
  providerId: attribution.providerId,
4987
5078
  model: attribution.model,
4988
5079
  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)),
5080
+ runId: _nullishCoalesce(_optionalChain([attribution, 'access', _276 => _276.routeLease, 'optionalAccess', _277 => _277.runId]), () => ( null)),
5081
+ routeLeaseId: _nullishCoalesce(_optionalChain([attribution, 'access', _278 => _278.routeLease, 'optionalAccess', _279 => _279.leaseId]), () => ( null)),
5082
+ routeLeaseConsumer: _nullishCoalesce(_optionalChain([attribution, 'access', _280 => _280.routeLease, 'optionalAccess', _281 => _281.consumer]), () => ( null)),
5083
+ routeLeaseStageId: _nullishCoalesce(_optionalChain([attribution, 'access', _282 => _282.routeLease, 'optionalAccess', _283 => _283.stageId]), () => ( null)),
4993
5084
  auditResponse: attribution.auditResponse,
4994
5085
  engineOrigin: "codex-ingress",
4995
5086
  usage: tapped,
@@ -5004,13 +5095,13 @@ function recordChatCompletionsNonStreamUsage(recorder, bodyText, attribution) {
5004
5095
  parsed.usage,
5005
5096
  attribution
5006
5097
  );
5007
- } catch (e40) {
5098
+ } catch (e41) {
5008
5099
  }
5009
5100
  }
5010
5101
  function recordChatCompletionsStreamUsage(recorder, rawUsage, attribution) {
5011
5102
  try {
5012
5103
  emitChatCompletionsUsageRecord(recorder, rawUsage, attribution);
5013
- } catch (e41) {
5104
+ } catch (e42) {
5014
5105
  }
5015
5106
  }
5016
5107
 
@@ -5021,7 +5112,7 @@ async function handleOpenAIChatRequest(res, rawBody, route, deps) {
5021
5112
  let chatBody;
5022
5113
  try {
5023
5114
  chatBody = JSON.parse(rawBody);
5024
- } catch (e42) {
5115
+ } catch (e43) {
5025
5116
  writeError(res, 400, "Invalid JSON in request body");
5026
5117
  return;
5027
5118
  }
@@ -5118,7 +5209,9 @@ async function buildByoPlan4(res, route, deps, resolvedModel, isStream) {
5118
5209
  resolveUrl: (config) => config.url instanceof URL ? config.url.toString() : byoUrl,
5119
5210
  upstreamUrl: byoUrl,
5120
5211
  proxyProviderId: "byo",
5121
- isSubscription: false
5212
+ isSubscription: false,
5213
+ byoActivity: buildByoRouteActivityMeta(deps, providerId, route.sessionId),
5214
+ routeSessionId: _nullishCoalesce(route.sessionId, () => ( null))
5122
5215
  };
5123
5216
  }
5124
5217
  async function buildSubscriptionPlan3(res, route, deps, resolvedModel, isStream) {
@@ -5136,7 +5229,7 @@ async function buildSubscriptionPlan3(res, route, deps, resolvedModel, isStream)
5136
5229
  );
5137
5230
  return null;
5138
5231
  }
5139
- const upstreamUrl = _optionalChain([profile, 'access', _261 => _261.resolveUpstreamUrl, 'optionalCall', _262 => _262(resolvedModel)]);
5232
+ const upstreamUrl = _optionalChain([profile, 'access', _284 => _284.resolveUpstreamUrl, 'optionalCall', _285 => _285(resolvedModel)]);
5140
5233
  if (!upstreamUrl) {
5141
5234
  writeError(res, 502, "Subscription profile is missing resolveUpstreamUrl");
5142
5235
  return null;
@@ -5165,7 +5258,8 @@ async function buildSubscriptionPlan3(res, route, deps, resolvedModel, isStream)
5165
5258
  resolveUrl: (config) => config.url instanceof URL ? config.url.toString() : typeof config.url === "string" ? config.url : upstreamUrl,
5166
5259
  upstreamUrl,
5167
5260
  proxyProviderId: providerId,
5168
- isSubscription: true
5261
+ isSubscription: true,
5262
+ routeSessionId: _nullishCoalesce(route.sessionId, () => ( null))
5169
5263
  };
5170
5264
  }
5171
5265
  async function runPipeline3(chatBody, plan) {
@@ -5201,10 +5295,31 @@ async function runPipeline3(chatBody, plan) {
5201
5295
  },
5202
5296
  fetchFn: (url, headers, body) => {
5203
5297
  console.log(`[ProviderProxy:chat] -> ${url} model=${resolvedModel} stream=${isStream}`);
5204
- return _chunkVFFCV4J6cjs.fetchUpstream.call(void 0,
5298
+ const sessionKey = plan.routeSessionId || void 0;
5299
+ return _chunkCXRJMNJJcjs.fetchUpstream.call(void 0,
5205
5300
  url,
5206
5301
  { method: "POST", headers, body: JSON.stringify(body) },
5207
- { providerId: plan.proxyProviderId, accountId: proxyAccountId }
5302
+ {
5303
+ providerId: plan.proxyProviderId,
5304
+ accountId: proxyAccountId,
5305
+ routeActivity: plan.isSubscription ? {
5306
+ providerId: plan.proxyProviderId,
5307
+ credentialKind: "subscription-account",
5308
+ accountId: proxyAccountId,
5309
+ endpoint: "chat",
5310
+ sessionKey,
5311
+ sessionSource: sessionKey ? "route-session-id" : "none",
5312
+ model: resolvedModel
5313
+ } : {
5314
+ providerId: _nullishCoalesce(_optionalChain([plan, 'access', _286 => _286.byoActivity, 'optionalAccess', _287 => _287.providerId]), () => ( transformerProvider.name)),
5315
+ credentialKind: "provider-key",
5316
+ keyId: _optionalChain([plan, 'access', _288 => _288.byoActivity, 'optionalAccess', _289 => _289.resolveKeyId, 'call', _290 => _290()]),
5317
+ endpoint: "chat",
5318
+ sessionKey,
5319
+ sessionSource: sessionKey ? "route-session-id" : "none",
5320
+ model: resolvedModel
5321
+ }
5322
+ }
5208
5323
  ).then((r) => {
5209
5324
  rawStatus = r.status;
5210
5325
  return r;
@@ -5216,8 +5331,8 @@ async function runPipeline3(chatBody, plan) {
5216
5331
  }
5217
5332
  async function runPipelineWithPoolReporting3(chatBody, plan) {
5218
5333
  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])) {
5334
+ const outcome = await _optionalChain([plan, 'access', _291 => _291.auth, 'access', _292 => _292.onResult, 'optionalCall', _293 => _293(first.rawStatus)]);
5335
+ if (_optionalChain([outcome, 'optionalAccess', _294 => _294.rebound])) {
5221
5336
  console.log(
5222
5337
  "[ProviderProxy:chat] pool re-bound key after status",
5223
5338
  first.rawStatus,
@@ -5230,7 +5345,7 @@ async function runPipelineWithPoolReporting3(chatBody, plan) {
5230
5345
  async function runPipelineWithSubscriptionRetry2(chatBody, plan) {
5231
5346
  const first = await runPipeline3(chatBody, plan);
5232
5347
  if (first.rawStatus !== 401) return first;
5233
- const refreshed = await _optionalChain([plan, 'access', _267 => _267.auth, 'access', _268 => _268.onUnauthorized, 'optionalCall', _269 => _269()]);
5348
+ const refreshed = await _optionalChain([plan, 'access', _295 => _295.auth, 'access', _296 => _296.onUnauthorized, 'optionalCall', _297 => _297()]);
5234
5349
  if (!refreshed) {
5235
5350
  console.warn("[ProviderProxy:chat] 401 not recoverable (onUnauthorized returned false)");
5236
5351
  return first;
@@ -5252,7 +5367,7 @@ function resolveRouteToken(req) {
5252
5367
  if (fromAuth) return fromAuth;
5253
5368
  const googKey = req.headers["x-goog-api-key"];
5254
5369
  const value = Array.isArray(googKey) ? googKey[0] : googKey;
5255
- return _optionalChain([value, 'optionalAccess', _270 => _270.trim, 'call', _271 => _271()]) || void 0;
5370
+ return _optionalChain([value, 'optionalAccess', _298 => _298.trim, 'call', _299 => _299()]) || void 0;
5256
5371
  }
5257
5372
  async function routeRequest(req, res, routes, deps) {
5258
5373
  if (classifyAnthropicMessagesPath(req.url) !== null) {
@@ -5267,7 +5382,7 @@ async function routeRequest(req, res, routes, deps) {
5267
5382
  const method = req.method;
5268
5383
  const url = req.url;
5269
5384
  const openAIOperation = _chunkG4CZIUIBcjs.classifyOpenAIOperation.call(void 0, method, url);
5270
- if (_optionalChain([openAIOperation, 'optionalAccess', _272 => _272.owner]) === "extension") {
5385
+ if (_optionalChain([openAIOperation, 'optionalAccess', _300 => _300.owner]) === "extension") {
5271
5386
  const registry = deps.openAIOperationRegistry;
5272
5387
  if (!registry) {
5273
5388
  _chunkG4CZIUIBcjs.writeOpenAIOperationError.call(void 0, res, _chunkG4CZIUIBcjs.unsupportedOpenAIOperation.call(void 0, openAIOperation));
@@ -5289,7 +5404,7 @@ async function routeRequest(req, res, routes, deps) {
5289
5404
  await handleAnthropicMessagesRequest(req, res, route, deps);
5290
5405
  return;
5291
5406
  }
5292
- if (_optionalChain([openAIOperation, 'optionalAccess', _273 => _273.id]) === "responses.create") {
5407
+ if (_optionalChain([openAIOperation, 'optionalAccess', _301 => _301.id]) === "responses.create") {
5293
5408
  const abortScope = createResponsesAbortScope({ request: req, response: res });
5294
5409
  try {
5295
5410
  const rawBody = await readBody(req, abortScope.signal);
@@ -5320,7 +5435,7 @@ async function routeRequest(req, res, routes, deps) {
5320
5435
  }
5321
5436
  return;
5322
5437
  }
5323
- if (_optionalChain([openAIOperation, 'optionalAccess', _274 => _274.id]) === "chat.completions.create") {
5438
+ if (_optionalChain([openAIOperation, 'optionalAccess', _302 => _302.id]) === "chat.completions.create") {
5324
5439
  const rawBody = await readBody(req);
5325
5440
  await handleOpenAIChatRequest(res, rawBody, route, deps);
5326
5441
  return;
@@ -5391,7 +5506,7 @@ var ProviderProxy = (_class8 = class {
5391
5506
  for (const cleanup of [...this.beforeStop]) {
5392
5507
  try {
5393
5508
  await cleanup();
5394
- } catch (e43) {
5509
+ } catch (e44) {
5395
5510
  }
5396
5511
  }
5397
5512
  this.routes.clear();
@@ -5677,7 +5792,7 @@ var SYSTEM_ROUTE_LEASE_CLOCK = {
5677
5792
  now: () => Date.now(),
5678
5793
  setTimeout(callback, delayMs) {
5679
5794
  const timer = setTimeout(callback, delayMs);
5680
- _optionalChain([timer, 'access', _275 => _275.unref, 'optionalCall', _276 => _276()]);
5795
+ _optionalChain([timer, 'access', _303 => _303.unref, 'optionalCall', _304 => _304()]);
5681
5796
  return timer;
5682
5797
  },
5683
5798
  clearTimeout(handle) {
@@ -5771,12 +5886,12 @@ var RouteLeaseManager = (_class10 = class {
5771
5886
  this.assertOpen();
5772
5887
  const route = {
5773
5888
  ...resolved,
5774
- sessionId: _nullishCoalesce(_optionalChain([request, 'access', _277 => _277.execution, 'optionalAccess', _278 => _278.sessionIdHash]), () => ( null)),
5889
+ sessionId: _nullishCoalesce(_optionalChain([request, 'access', _305 => _305.execution, 'optionalAccess', _306 => _306.sessionIdHash]), () => ( null)),
5775
5890
  routeLease: {
5776
5891
  leaseId,
5777
5892
  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 } : {}
5893
+ ..._optionalChain([request, 'access', _307 => _307.execution, 'optionalAccess', _308 => _308.runId]) ? { runId: request.execution.runId } : {},
5894
+ ..._optionalChain([request, 'access', _309 => _309.execution, 'optionalAccess', _310 => _310.stageId]) ? { stageId: request.execution.stageId } : {}
5780
5895
  }
5781
5896
  };
5782
5897
  const now = this.clock.now();
@@ -5831,7 +5946,7 @@ var RouteLeaseManager = (_class10 = class {
5831
5946
  this.active.set(leaseId, activeLease);
5832
5947
  this.idempotency.set(scope, { leaseId, payloadHash: input.payloadHash });
5833
5948
  published = true;
5834
- _optionalChain([this, 'access', _283 => _283.afterPublish, 'optionalCall', _284 => _284()]);
5949
+ _optionalChain([this, 'access', _311 => _311.afterPublish, 'optionalCall', _312 => _312()]);
5835
5950
  if (this.closed) {
5836
5951
  this.finalize(activeLease, "released");
5837
5952
  throw new RouteLeaseError("daemon_not_ready", "route lease manager is shutting down");
@@ -5868,7 +5983,7 @@ var RouteLeaseManager = (_class10 = class {
5868
5983
  if (!lease) {
5869
5984
  this.pruneTombstones();
5870
5985
  const known = this.tombstones.get(leaseId);
5871
- if (_optionalChain([known, 'optionalAccess', _285 => _285.metadata, 'access', _286 => _286.status]) === "expired") {
5986
+ if (_optionalChain([known, 'optionalAccess', _313 => _313.metadata, 'access', _314 => _314.status]) === "expired") {
5872
5987
  throw new RouteLeaseError("lease_expired", "route lease has expired");
5873
5988
  }
5874
5989
  throw new RouteLeaseError("lease_not_found", "route lease was not found");
@@ -5905,7 +6020,7 @@ var RouteLeaseManager = (_class10 = class {
5905
6020
  try {
5906
6021
  this.finalize(lease, "released");
5907
6022
  } 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) })]);
6023
+ _optionalChain([this, 'access', _315 => _315.logger, 'optionalAccess', _316 => _316.warn, 'call', _317 => _317("route lease cleanup failed during shutdown", { leaseId: lease.leaseId, error: safeErrorName(error) })]);
5909
6024
  }
5910
6025
  }
5911
6026
  }
@@ -5951,7 +6066,7 @@ var RouteLeaseManager = (_class10 = class {
5951
6066
  try {
5952
6067
  this.routePort.removeRoute(routeToken);
5953
6068
  } 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) })]);
6069
+ _optionalChain([this, 'access', _318 => _318.logger, 'optionalAccess', _319 => _319.warn, 'call', _320 => _320("route lease route cleanup failed", { leaseId, error: safeErrorName(error) })]);
5955
6070
  }
5956
6071
  }
5957
6072
  pruneTombstones() {
@@ -5976,28 +6091,33 @@ function nonBlank(value) {
5976
6091
  return typeof value === "string" && value.trim() !== "";
5977
6092
  }
5978
6093
  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)]));
6094
+ const scope = _nullishCoalesce(binding.keyScope, () => ( (_optionalChain([binding, 'access', _321 => _321.apiKeyIds, 'optionalAccess', _322 => _322.length]) ? "selected" : "all")));
6095
+ return scope === "all" || Boolean(_optionalChain([binding, 'access', _323 => _323.apiKeyIds, 'optionalAccess', _324 => _324.includes, 'call', _325 => _325(apiKeyId)]));
5981
6096
  }
5982
6097
  function wildcardMatches(pattern, value) {
5983
6098
  const escaped = pattern.split("*").map((part) => part.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&")).join(".*");
5984
6099
  return new RegExp(`^${escaped}$`, "iu").test(value);
5985
6100
  }
5986
- function resolveGatewayModelMapping(mappings, requestedModel) {
6101
+ function resolveGatewayModelMappingRow(mappings, requestedModel) {
5987
6102
  if (!nonBlank(requestedModel)) return void 0;
5988
6103
  const wanted = requestedModel.trim();
5989
6104
  const exact = (_nullishCoalesce(mappings, () => ( []))).find(
5990
6105
  (mapping) => nonBlank(mapping.source) && !mapping.source.includes("*") && mapping.source.trim().toLocaleLowerCase() === wanted.toLocaleLowerCase()
5991
6106
  );
5992
- if (exact && nonBlank(exact.target)) return exact.target.trim();
6107
+ if (exact && nonBlank(exact.target)) {
6108
+ return { target: exact.target.trim(), effort: exact.effort };
6109
+ }
5993
6110
  const wildcard = (_nullishCoalesce(mappings, () => ( []))).find(
5994
6111
  (mapping) => nonBlank(mapping.source) && mapping.source.includes("*") && wildcardMatches(mapping.source.trim(), wanted)
5995
6112
  );
5996
- return wildcard && nonBlank(wildcard.target) ? wildcard.target.trim() : void 0;
6113
+ return wildcard && nonBlank(wildcard.target) ? { target: wildcard.target.trim(), effort: wildcard.effort } : void 0;
6114
+ }
6115
+ function resolveGatewayModelMapping(mappings, requestedModel) {
6116
+ return _optionalChain([resolveGatewayModelMappingRow, 'call', _326 => _326(mappings, requestedModel), 'optionalAccess', _327 => _327.target]);
5997
6117
  }
5998
6118
  function routeCanServe(binding, requestedModel, role) {
5999
6119
  if (binding.modelMode === "passthrough") return nonBlank(requestedModel);
6000
- if (_optionalChain([binding, 'access', _298 => _298.modelMappings, 'optionalAccess', _299 => _299.length])) {
6120
+ if (_optionalChain([binding, 'access', _328 => _328.modelMappings, 'optionalAccess', _329 => _329.length])) {
6001
6121
  return nonBlank(resolveGatewayModelMapping(binding.modelMappings, requestedModel));
6002
6122
  }
6003
6123
  if (_chunk57Y2EA2Gcjs.isKindMappedEndpoint.call(void 0, binding.endpoint)) {
@@ -6015,7 +6135,7 @@ function routeCanServe(binding, requestedModel, role) {
6015
6135
  if (binding.endpoint === "chat") {
6016
6136
  if (!requestedModel) return false;
6017
6137
  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);
6138
+ return (_nullishCoalesce(binding.models, () => ( []))).some((ref) => _optionalChain([modelIdOf, 'call', _330 => _330(ref), 'optionalAccess', _331 => _331.toLowerCase, 'call', _332 => _332()]) === wanted);
6019
6139
  }
6020
6140
  return role === "background" ? nonBlank(binding.backgroundModel) : nonBlank(binding.defaultModel);
6021
6141
  }
@@ -6066,10 +6186,12 @@ function gatewayBindingToEndpointConfig(binding, requestedModel) {
6066
6186
  endpoint: binding.endpoint,
6067
6187
  useSubscription: target.kind !== "provider"
6068
6188
  };
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);
6189
+ const usesGenericModelHandling = binding.modelMode === "passthrough" || Boolean(_optionalChain([binding, 'access', _333 => _333.modelMappings, 'optionalAccess', _334 => _334.length]));
6190
+ const winningMapping = binding.modelMode === "passthrough" ? void 0 : resolveGatewayModelMappingRow(binding.modelMappings, requestedModel);
6191
+ const dynamicModel = binding.modelMode === "passthrough" ? requestedModel : _optionalChain([winningMapping, 'optionalAccess', _335 => _335.target]);
6071
6192
  if (usesGenericModelHandling) {
6072
6193
  if (nonBlank(dynamicModel)) applySingleModel(config, binding, dynamicModel);
6194
+ if (_optionalChain([winningMapping, 'optionalAccess', _336 => _336.effort])) config.reasoningEffort = winningMapping.effort;
6073
6195
  } else if (_chunk57Y2EA2Gcjs.isKindMappedEndpoint.call(void 0, binding.endpoint)) {
6074
6196
  config.modelMap = Object.fromEntries(
6075
6197
  Object.entries(_nullishCoalesce(binding.modelMap, () => ( {}))).map(([kind, ref]) => [kind, targetRef(target, ref)])
@@ -6101,7 +6223,7 @@ function candidateGatewayBindings(bindings, apiKeyId, endpoint) {
6101
6223
  const candidates = (_nullishCoalesce(bindings, () => ( []))).filter(
6102
6224
  (binding) => binding.enabled && binding.endpoint === endpoint && gatewayBindingAllowsKey(binding, apiKeyId)
6103
6225
  );
6104
- const scopeOf = (binding) => _nullishCoalesce(binding.keyScope, () => ( (_optionalChain([binding, 'access', _305 => _305.apiKeyIds, 'optionalAccess', _306 => _306.length]) ? "selected" : "all")));
6226
+ const scopeOf = (binding) => _nullishCoalesce(binding.keyScope, () => ( (_optionalChain([binding, 'access', _337 => _337.apiKeyIds, 'optionalAccess', _338 => _338.length]) ? "selected" : "all")));
6105
6227
  const scoped = candidates.filter((binding) => scopeOf(binding) === "selected");
6106
6228
  const pool = scoped.length > 0 ? scoped : candidates.filter((binding) => scopeOf(binding) === "all");
6107
6229
  return pool.sort(
@@ -6155,7 +6277,7 @@ function syntheticBinding(request) {
6155
6277
  };
6156
6278
  }
6157
6279
  function transformerRegistered(llmConfig, name) {
6158
- return Boolean(_optionalChain([llmConfig, 'access', _307 => _307.getTransformerService, 'call', _308 => _308(), 'optionalAccess', _309 => _309.getTransformer, 'call', _310 => _310(name)]));
6280
+ return Boolean(_optionalChain([llmConfig, 'access', _339 => _339.getTransformerService, 'call', _340 => _340(), 'optionalAccess', _341 => _341.getTransformer, 'call', _342 => _342(name)]));
6159
6281
  }
6160
6282
  var RouteLeaseTargetResolver = class {
6161
6283
  constructor(llmConfig, options = {}) {
@@ -6174,7 +6296,7 @@ var RouteLeaseTargetResolver = class {
6174
6296
  ingressFormat: runtime.ingressFormat,
6175
6297
  llmConfig: this.llmConfig,
6176
6298
  requestedModel: request.model,
6177
- sessionId: _nullishCoalesce(_optionalChain([request, 'access', _311 => _311.execution, 'optionalAccess', _312 => _312.sessionIdHash]), () => ( null))
6299
+ sessionId: _nullishCoalesce(_optionalChain([request, 'access', _343 => _343.execution, 'optionalAccess', _344 => _344.sessionIdHash]), () => ( null))
6178
6300
  });
6179
6301
  if (!result.ok) {
6180
6302
  throw new RouteLeaseError(
@@ -6197,7 +6319,7 @@ var RouteLeaseTargetResolver = class {
6197
6319
  throw new RouteLeaseError("model_not_configured", "model is not configured for the provider");
6198
6320
  }
6199
6321
  if (target.keyId) {
6200
- const availability = await _optionalChain([this, 'access', _313 => _313.options, 'access', _314 => _314.providerKeys, 'optionalAccess', _315 => _315.getKeyAvailability, 'optionalCall', _316 => _316(
6322
+ const availability = await _optionalChain([this, 'access', _345 => _345.options, 'access', _346 => _346.providerKeys, 'optionalAccess', _347 => _347.getKeyAvailability, 'optionalCall', _348 => _348(
6201
6323
  target.providerId,
6202
6324
  target.keyId
6203
6325
  )]);
@@ -6210,9 +6332,9 @@ var RouteLeaseTargetResolver = class {
6210
6332
  }
6211
6333
  } else {
6212
6334
  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)]);
6335
+ const poolAvailability = await _optionalChain([this, 'access', _349 => _349.options, 'access', _350 => _350.providerKeys, 'optionalAccess', _351 => _351.getPoolAvailability, 'optionalCall', _352 => _352(target.providerId)]);
6214
6336
  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") {
6337
+ if (!directKey && _optionalChain([poolAvailability, 'optionalAccess', _353 => _353.outcome]) === "exhausted") {
6216
6338
  throw new RouteLeaseError("upstream_exhausted", "provider key pool is temporarily exhausted", {
6217
6339
  retryAfterSeconds: poolAvailability.retryAfterSeconds
6218
6340
  });
@@ -6236,14 +6358,14 @@ var RouteLeaseTargetResolver = class {
6236
6358
  }
6237
6359
  async preflightSubscription(target, model) {
6238
6360
  const registry = _chunkQBZJ7P2Tcjs.getSubscriptionRegistryForOutbound.call(void 0, );
6239
- const profile = _nullishCoalesce(_optionalChain([registry, 'optionalAccess', _322 => _322.getProfile, 'call', _323 => _323(target.providerId)]), () => ( null));
6361
+ const profile = _nullishCoalesce(_optionalChain([registry, 'optionalAccess', _354 => _354.getProfile, 'call', _355 => _355(target.providerId)]), () => ( null));
6240
6362
  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)), () => ( []));
6363
+ await _optionalChain([this, 'access', _356 => _356.options, 'access', _357 => _357.subscriptions, 'optionalAccess', _358 => _358.assertAvailable, 'call', _359 => _359(target, model)]);
6364
+ const names = _nullishCoalesce(_nullishCoalesce(_optionalChain([profile, 'access', _360 => _360.resolveProviderTransformerNames, 'optionalCall', _361 => _361(model)]), () => ( profile.providerTransformerNames)), () => ( []));
6243
6365
  if (names.some((name) => !transformerRegistered(this.llmConfig, name))) {
6244
6366
  throw new RouteLeaseError("format_unsupported", "a required transformer is unavailable");
6245
6367
  }
6246
- if (_optionalChain([profile, 'access', _330 => _330.modelTransformerNames, 'optionalAccess', _331 => _331.some, 'call', _332 => _332((name) => !transformerRegistered(this.llmConfig, name))])) {
6368
+ if (_optionalChain([profile, 'access', _362 => _362.modelTransformerNames, 'optionalAccess', _363 => _363.some, 'call', _364 => _364((name) => !transformerRegistered(this.llmConfig, name))])) {
6247
6369
  throw new RouteLeaseError("format_unsupported", "a required model transformer is unavailable");
6248
6370
  }
6249
6371
  }
@@ -6265,7 +6387,7 @@ function createResponsesCompactHandler(options = {}) {
6265
6387
  const parsed = JSON.parse(rawBody);
6266
6388
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error();
6267
6389
  body = parsed;
6268
- } catch (e44) {
6390
+ } catch (e45) {
6269
6391
  throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({
6270
6392
  status: 400,
6271
6393
  code: "invalid_request_body",
@@ -6356,7 +6478,7 @@ var BoundedSseFrameDecoder = class {
6356
6478
  let decoded;
6357
6479
  try {
6358
6480
  decoded = this.#decoder.decode(chunk, { stream: true });
6359
- } catch (e45) {
6481
+ } catch (e46) {
6360
6482
  protocolFailure2();
6361
6483
  }
6362
6484
  return this.#append(decoded, false);
@@ -6365,7 +6487,7 @@ var BoundedSseFrameDecoder = class {
6365
6487
  let tail;
6366
6488
  try {
6367
6489
  tail = this.#decoder.decode();
6368
- } catch (e46) {
6490
+ } catch (e47) {
6369
6491
  protocolFailure2();
6370
6492
  }
6371
6493
  const frames = this.#append(tail, true);
@@ -6495,7 +6617,7 @@ var HostedImageSsePipeline = class {
6495
6617
  if (this.#cancelPromise) return this.#cancelPromise;
6496
6618
  this.#cancelled = true;
6497
6619
  this.#cancelPromise = Promise.allSettled([
6498
- _nullishCoalesce(_optionalChain([this, 'access', _333 => _333.#reader, 'optionalAccess', _334 => _334.cancel, 'call', _335 => _335(reason)]), () => ( Promise.resolve())),
6620
+ _nullishCoalesce(_optionalChain([this, 'access', _365 => _365.#reader, 'optionalAccess', _366 => _366.cancel, 'call', _367 => _367(reason)]), () => ( Promise.resolve())),
6499
6621
  this.#closeActiveImageIterator(),
6500
6622
  this.#options.onCancel()
6501
6623
  ]).then(() => void 0);
@@ -6509,7 +6631,7 @@ var HostedImageSsePipeline = class {
6509
6631
  let parsed;
6510
6632
  try {
6511
6633
  parsed = JSON.parse(frame2.data);
6512
- } catch (e47) {
6634
+ } catch (e48) {
6513
6635
  protocolFailure2();
6514
6636
  }
6515
6637
  if (!isRecord8(parsed) || typeof parsed.type !== "string" || parsed.type.length > 256) {
@@ -6866,7 +6988,7 @@ data: ${JSON.stringify(event)}
6866
6988
  #closeActiveImageIterator() {
6867
6989
  if (this.#activeImageIteratorClose) return this.#activeImageIteratorClose;
6868
6990
  const iterator = this.#activeImageIterator;
6869
- if (!_optionalChain([iterator, 'optionalAccess', _336 => _336.return])) return Promise.resolve();
6991
+ if (!_optionalChain([iterator, 'optionalAccess', _368 => _368.return])) return Promise.resolve();
6870
6992
  this.#activeImageIteratorClose = Promise.resolve(iterator.return()).then(
6871
6993
  () => void 0,
6872
6994
  () => void 0
@@ -6903,7 +7025,7 @@ function createNativeResponsesHostedImageSseResponse(options) {
6903
7025
  },
6904
7026
  async cancel(reason) {
6905
7027
  await pipeline.cancel(reason);
6906
- await _optionalChain([iterator, 'access', _337 => _337.return, 'optionalCall', _338 => _338()]);
7028
+ await _optionalChain([iterator, 'access', _369 => _369.return, 'optionalCall', _370 => _370()]);
6907
7029
  }
6908
7030
  });
6909
7031
  return transformedResponse(options.upstream, body);
@@ -6975,7 +7097,7 @@ function parseJsonObject(bytes) {
6975
7097
  let text;
6976
7098
  try {
6977
7099
  text = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
6978
- } catch (e48) {
7100
+ } catch (e49) {
6979
7101
  protocolFailure3();
6980
7102
  }
6981
7103
  try {
@@ -7148,7 +7270,7 @@ var NativeResponsesHostedImageRequestLease = class {
7148
7270
  #wrapSse(input) {
7149
7271
  const status = _nullishCoalesce(input.rawStatus, () => ( input.response.status));
7150
7272
  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;
7273
+ const hasInheritedContext = _optionalChain([this, 'access', _371 => _371.#input, 'access', _372 => _372.previousHostedImageState, 'optionalAccess', _373 => _373.hasImageContext]) === true;
7152
7274
  return createNativeResponsesHostedImageSseResponse({
7153
7275
  upstream: input.response,
7154
7276
  signal: this.#input.signal,
@@ -7174,7 +7296,7 @@ var NativeResponsesHostedImageRequestLease = class {
7174
7296
  signal: this.#input.signal,
7175
7297
  ...this.#input.authorizedPreviousResponseId ? {
7176
7298
  authorizedPreviousResponseId: this.#input.authorizedPreviousResponseId,
7177
- authorizedPreviousResponseKnownEmpty: _optionalChain([this, 'access', _342 => _342.#input, 'access', _343 => _343.previousHostedImageState, 'optionalAccess', _344 => _344.hasImageContext]) !== true
7299
+ authorizedPreviousResponseKnownEmpty: _optionalChain([this, 'access', _374 => _374.#input, 'access', _375 => _375.previousHostedImageState, 'optionalAccess', _376 => _376.hasImageContext]) !== true
7178
7300
  } : {},
7179
7301
  mainProviderId: this.#input.mainProviderId,
7180
7302
  ...input.selectedMainAccountId ? { selectedMainAccountId: input.selectedMainAccountId } : {}
@@ -7209,7 +7331,7 @@ var NativeResponsesHostedImageRequestLease = class {
7209
7331
  if (!UPSTREAM_CALL_ID_PATTERN4.test(selected.upstreamCallId)) protocolFailure3();
7210
7332
  }
7211
7333
  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;
7334
+ const hasInheritedContext = _optionalChain([this, 'access', _377 => _377.#input, 'access', _378 => _378.previousHostedImageState, 'optionalAccess', _379 => _379.hasImageContext]) === true;
7213
7335
  const requiresScope = parsedSelection.imageCalls.length > 0 || hasInheritedContext || this.#admission.explicitCallIds.length > 0;
7214
7336
  const publicOutput = [...upstreamBody.output];
7215
7337
  const pendingReceipts = [];
@@ -7226,7 +7348,7 @@ var NativeResponsesHostedImageRequestLease = class {
7226
7348
  signal: this.#input.signal,
7227
7349
  ...this.#input.authorizedPreviousResponseId ? {
7228
7350
  authorizedPreviousResponseId: this.#input.authorizedPreviousResponseId,
7229
- authorizedPreviousResponseKnownEmpty: _optionalChain([this, 'access', _348 => _348.#input, 'access', _349 => _349.previousHostedImageState, 'optionalAccess', _350 => _350.hasImageContext]) !== true
7351
+ authorizedPreviousResponseKnownEmpty: _optionalChain([this, 'access', _380 => _380.#input, 'access', _381 => _381.previousHostedImageState, 'optionalAccess', _382 => _382.hasImageContext]) !== true
7230
7352
  } : {},
7231
7353
  mainProviderId: this.#input.mainProviderId,
7232
7354
  ...input.selectedMainAccountId ? { selectedMainAccountId: input.selectedMainAccountId } : {}
@@ -7272,7 +7394,7 @@ function createNativeResponsesHostedImageIngress(runtimeFactory, options = {}) {
7272
7394
  const createRequestId = _nullishCoalesce(options.createRequestId, () => ( (() => `hosted-image-${_crypto.randomUUID.call(void 0, )}`)));
7273
7395
  return Object.freeze({
7274
7396
  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])) {
7397
+ if (input.operation !== "create" || input.profile !== "native" || !hasImageOwnedResponsesInput(input.body) && !_optionalChain([input, 'access', _383 => _383.previousHostedImageState, 'optionalAccess', _384 => _384.hasImageContext]) && !_optionalChain([input, 'access', _385 => _385.previousHostedImageState, 'optionalAccess', _386 => _386.pendingReceipts, 'access', _387 => _387.length])) {
7276
7398
  return null;
7277
7399
  }
7278
7400
  if (!input.hostedImageGenerationAllowed) {
@@ -7305,7 +7427,7 @@ function createNativeResponsesHostedImageIngress(runtimeFactory, options = {}) {
7305
7427
  const selection = prepareNativeResponsesImageSelection({
7306
7428
  body: input.body,
7307
7429
  admission,
7308
- pendingReceipts: _optionalChain([input, 'access', _356 => _356.previousHostedImageState, 'optionalAccess', _357 => _357.pendingReceipts]),
7430
+ pendingReceipts: _optionalChain([input, 'access', _388 => _388.previousHostedImageState, 'optionalAccess', _389 => _389.pendingReceipts]),
7309
7431
  ...options.createSelectorName ? { createSelectorName: options.createSelectorName } : {}
7310
7432
  });
7311
7433
  return new NativeResponsesHostedImageRequestLease({
@@ -7964,9 +8086,9 @@ function stringList(value, cap) {
7964
8086
  }
7965
8087
  function tavilyConfig(value) {
7966
8088
  const raw = record4(value);
7967
- const apiKey = configString(_optionalChain([raw, 'optionalAccess', _358 => _358["apiKey"]]));
8089
+ const apiKey = configString(_optionalChain([raw, 'optionalAccess', _390 => _390["apiKey"]]));
7968
8090
  if (!apiKey) return void 0;
7969
- const apiHost = configString(_optionalChain([raw, 'optionalAccess', _359 => _359["apiHost"]]));
8091
+ const apiHost = configString(_optionalChain([raw, 'optionalAccess', _391 => _391["apiHost"]]));
7970
8092
  return { apiKey, ...apiHost ? { apiHost } : {} };
7971
8093
  }
7972
8094
  function jinaConfig(value) {
@@ -7978,10 +8100,10 @@ function jinaConfig(value) {
7978
8100
  }
7979
8101
  function searxngConfig(value) {
7980
8102
  const raw = record4(value);
7981
- const apiHost = configString(_optionalChain([raw, 'optionalAccess', _360 => _360["apiHost"]]));
8103
+ const apiHost = configString(_optionalChain([raw, 'optionalAccess', _392 => _392["apiHost"]]));
7982
8104
  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"]]));
8105
+ const basicAuthUsername = configString(_optionalChain([raw, 'optionalAccess', _393 => _393["basicAuthUsername"]]));
8106
+ const basicAuthPassword = configString(_optionalChain([raw, 'optionalAccess', _394 => _394["basicAuthPassword"]]));
7985
8107
  return {
7986
8108
  apiHost,
7987
8109
  ...basicAuthUsername ? { basicAuthUsername } : {},
@@ -7990,9 +8112,9 @@ function searxngConfig(value) {
7990
8112
  }
7991
8113
  function zhipuConfig(value) {
7992
8114
  const raw = record4(value);
7993
- const apiKey = configString(_optionalChain([raw, 'optionalAccess', _363 => _363["apiKey"]]));
8115
+ const apiKey = configString(_optionalChain([raw, 'optionalAccess', _395 => _395["apiKey"]]));
7994
8116
  if (!apiKey) return void 0;
7995
- const apiHost = configString(_optionalChain([raw, 'optionalAccess', _364 => _364["apiHost"]]));
8117
+ const apiHost = configString(_optionalChain([raw, 'optionalAccess', _396 => _396["apiHost"]]));
7996
8118
  return { apiKey, ...apiHost ? { apiHost } : {} };
7997
8119
  }
7998
8120
  function normalizeSearchApiProviderConfigs(value) {
@@ -8144,11 +8266,11 @@ var DEFAULT_ACCOUNT_HEALTH = {
8144
8266
  overloadCooldownMs: 10 * 6e4
8145
8267
  };
8146
8268
  function normalizeAccountHealth(raw) {
8147
- const ah = _optionalChain([raw, 'optionalAccess', _365 => _365.accountHealth]);
8269
+ const ah = _optionalChain([raw, 'optionalAccess', _397 => _397.accountHealth]);
8148
8270
  return {
8149
- overloadCooldownEnabled: _optionalChain([ah, 'optionalAccess', _366 => _366.overloadCooldownEnabled]) !== false,
8271
+ overloadCooldownEnabled: _optionalChain([ah, 'optionalAccess', _398 => _398.overloadCooldownEnabled]) !== false,
8150
8272
  overloadCooldownMs: clampNumber(
8151
- _optionalChain([ah, 'optionalAccess', _367 => _367.overloadCooldownMs]),
8273
+ _optionalChain([ah, 'optionalAccess', _399 => _399.overloadCooldownMs]),
8152
8274
  6e4,
8153
8275
  36e5,
8154
8276
  DEFAULT_ACCOUNT_HEALTH.overloadCooldownMs
@@ -8170,25 +8292,25 @@ var DEFAULT_ALLOWANCE_SCHEDULING = {
8170
8292
  priorityPenalty: 100
8171
8293
  };
8172
8294
  function normalizeAllowanceScheduling(raw) {
8173
- const value = _optionalChain([raw, 'optionalAccess', _368 => _368.allowanceScheduling]);
8295
+ const value = _optionalChain([raw, 'optionalAccess', _400 => _400.allowanceScheduling]);
8174
8296
  const demoteAtPercent = clampNumber(
8175
- _optionalChain([value, 'optionalAccess', _369 => _369.demoteAtPercent]),
8297
+ _optionalChain([value, 'optionalAccess', _401 => _401.demoteAtPercent]),
8176
8298
  0,
8177
8299
  100,
8178
8300
  DEFAULT_ALLOWANCE_SCHEDULING.demoteAtPercent
8179
8301
  );
8180
8302
  const requestedPause = clampNumber(
8181
- _optionalChain([value, 'optionalAccess', _370 => _370.pauseAtPercent]),
8303
+ _optionalChain([value, 'optionalAccess', _402 => _402.pauseAtPercent]),
8182
8304
  0,
8183
8305
  100,
8184
8306
  DEFAULT_ALLOWANCE_SCHEDULING.pauseAtPercent
8185
8307
  );
8186
8308
  return {
8187
- enabled: _optionalChain([value, 'optionalAccess', _371 => _371.enabled]) === true,
8309
+ enabled: _optionalChain([value, 'optionalAccess', _403 => _403.enabled]) === true,
8188
8310
  demoteAtPercent,
8189
8311
  pauseAtPercent: Math.max(demoteAtPercent, requestedPause),
8190
8312
  priorityPenalty: Math.trunc(clampNumber(
8191
- _optionalChain([value, 'optionalAccess', _372 => _372.priorityPenalty]),
8313
+ _optionalChain([value, 'optionalAccess', _404 => _404.priorityPenalty]),
8192
8314
  1,
8193
8315
  1e3,
8194
8316
  DEFAULT_ALLOWANCE_SCHEDULING.priorityPenalty
@@ -8196,29 +8318,29 @@ function normalizeAllowanceScheduling(raw) {
8196
8318
  };
8197
8319
  }
8198
8320
  function normalizeAccountProbe(raw) {
8199
- const ap = _optionalChain([raw, 'optionalAccess', _373 => _373.accountProbe]);
8321
+ const ap = _optionalChain([raw, 'optionalAccess', _405 => _405.accountProbe]);
8200
8322
  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),
8323
+ enabled: _optionalChain([ap, 'optionalAccess', _406 => _406.enabled]) === true,
8324
+ intervalMs: clampNumber(_optionalChain([ap, 'optionalAccess', _407 => _407.intervalMs]), 6e4, 864e5, DEFAULT_ACCOUNT_PROBE.intervalMs),
8325
+ onlyMultiAccount: _optionalChain([ap, 'optionalAccess', _408 => _408.onlyMultiAccount]) !== false,
8326
+ timeoutMs: clampNumber(_optionalChain([ap, 'optionalAccess', _409 => _409.timeoutMs]), 1e3, 6e4, DEFAULT_ACCOUNT_PROBE.timeoutMs),
8205
8327
  historySize: Math.trunc(
8206
- clampNumber(_optionalChain([ap, 'optionalAccess', _378 => _378.historySize]), 1, 200, DEFAULT_ACCOUNT_PROBE.historySize)
8328
+ clampNumber(_optionalChain([ap, 'optionalAccess', _410 => _410.historySize]), 1, 200, DEFAULT_ACCOUNT_PROBE.historySize)
8207
8329
  ),
8208
- staggerMs: clampNumber(_optionalChain([ap, 'optionalAccess', _379 => _379.staggerMs]), 0, 6e4, DEFAULT_ACCOUNT_PROBE.staggerMs)
8330
+ staggerMs: clampNumber(_optionalChain([ap, 'optionalAccess', _411 => _411.staggerMs]), 0, 6e4, DEFAULT_ACCOUNT_PROBE.staggerMs)
8209
8331
  };
8210
8332
  }
8211
8333
  function normalizeAudit(raw) {
8212
- const a = _optionalChain([raw, 'optionalAccess', _380 => _380.audit]);
8334
+ const a = _optionalChain([raw, 'optionalAccess', _412 => _412.audit]);
8213
8335
  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])),
8336
+ enabled: _optionalChain([a, 'optionalAccess', _413 => _413.enabled]) === true,
8337
+ captureBodies: _optionalChain([a, 'optionalAccess', _414 => _414.captureBodies]) === true,
8338
+ maxBodyBytes: normalizeMaxBodyBytes(_optionalChain([a, 'optionalAccess', _415 => _415.maxBodyBytes])),
8217
8339
  retentionDays: Math.trunc(
8218
- clampNumber(_optionalChain([a, 'optionalAccess', _384 => _384.retentionDays]), 1, 365, _audittypes.DEFAULT_AUDIT_CONFIG.retentionDays)
8340
+ clampNumber(_optionalChain([a, 'optionalAccess', _416 => _416.retentionDays]), 1, 365, _audittypes.DEFAULT_AUDIT_CONFIG.retentionDays)
8219
8341
  ),
8220
- compactStreamingBodies: _optionalChain([a, 'optionalAccess', _385 => _385.compactStreamingBodies]) === true,
8221
- trustForwardedFor: _optionalChain([a, 'optionalAccess', _386 => _386.trustForwardedFor]) === true
8342
+ compactStreamingBodies: _optionalChain([a, 'optionalAccess', _417 => _417.compactStreamingBodies]) === true,
8343
+ trustForwardedFor: _optionalChain([a, 'optionalAccess', _418 => _418.trustForwardedFor]) === true
8222
8344
  };
8223
8345
  }
8224
8346
  function normalizeMaxBodyBytes(value) {
@@ -8229,26 +8351,26 @@ function normalizeMaxBodyBytes(value) {
8229
8351
  return Math.trunc(Math.min(1048576, value));
8230
8352
  }
8231
8353
  function normalizeBilling(raw) {
8232
- const b = _optionalChain([raw, 'optionalAccess', _387 => _387.billing]);
8354
+ const b = _optionalChain([raw, 'optionalAccess', _419 => _419.billing]);
8233
8355
  const config = {
8234
- enabled: _optionalChain([b, 'optionalAccess', _388 => _388.enabled]) === true,
8356
+ enabled: _optionalChain([b, 'optionalAccess', _420 => _420.enabled]) === true,
8235
8357
  maxRetryAgeMs: Math.trunc(
8236
- clampNumber(_optionalChain([b, 'optionalAccess', _389 => _389.maxRetryAgeMs]), 6e4, 2592e6, _billingtypes.DEFAULT_BILLING_CONFIG.maxRetryAgeMs)
8358
+ clampNumber(_optionalChain([b, 'optionalAccess', _421 => _421.maxRetryAgeMs]), 6e4, 2592e6, _billingtypes.DEFAULT_BILLING_CONFIG.maxRetryAgeMs)
8237
8359
  )
8238
8360
  };
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;
8361
+ if (typeof _optionalChain([b, 'optionalAccess', _422 => _422.endpoint]) === "string" && b.endpoint.trim()) config.endpoint = b.endpoint.trim();
8362
+ if (typeof _optionalChain([b, 'optionalAccess', _423 => _423.secret]) === "string" && b.secret.length > 0) config.secret = b.secret;
8241
8363
  return config;
8242
8364
  }
8243
8365
  var DEFAULT_FINGERPRINT = { enabled: false };
8244
8366
  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();
8367
+ const f = _optionalChain([raw, 'optionalAccess', _424 => _424.fingerprint]);
8368
+ const out = { enabled: _optionalChain([f, 'optionalAccess', _425 => _425.enabled]) === true };
8369
+ if (typeof _optionalChain([f, 'optionalAccess', _426 => _426.ua]) === "string" && f.ua.trim().length > 0) out.ua = f.ua.trim();
8248
8370
  return out;
8249
8371
  }
8250
8372
  function normalizeVoucher(raw) {
8251
- return { enabled: _optionalChain([raw, 'optionalAccess', _395 => _395.voucher, 'optionalAccess', _396 => _396.enabled]) === true };
8373
+ return { enabled: _optionalChain([raw, 'optionalAccess', _427 => _427.voucher, 'optionalAccess', _428 => _428.enabled]) === true };
8252
8374
  }
8253
8375
  var DEFAULT_ANTHROPIC_SEGMENT = {
8254
8376
  countTokens: { mode: "auto", estimateBudgetMs: 2e3 },
@@ -8261,34 +8383,34 @@ var DEFAULT_ANTHROPIC_SEGMENT = {
8261
8383
  var COUNT_TOKENS_MODES = ["auto", "passthrough", "estimate", "reject"];
8262
8384
  var MODELS_SHAPES = ["auto", "anthropic", "openai"];
8263
8385
  function normalizeAnthropicSegment(raw) {
8264
- const a = _optionalChain([raw, 'optionalAccess', _397 => _397.anthropic]);
8386
+ const a = _optionalChain([raw, 'optionalAccess', _429 => _429.anthropic]);
8265
8387
  return {
8266
8388
  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,
8389
+ mode: COUNT_TOKENS_MODES.includes(String(_optionalChain([a, 'optionalAccess', _430 => _430.countTokens, 'optionalAccess', _431 => _431.mode]))) ? _optionalChain([a, 'optionalAccess', _432 => _432.countTokens, 'optionalAccess', _433 => _433.mode]) : DEFAULT_ANTHROPIC_SEGMENT.countTokens.mode,
8268
8390
  estimateBudgetMs: clampNumber(
8269
- _optionalChain([a, 'optionalAccess', _402 => _402.countTokens, 'optionalAccess', _403 => _403.estimateBudgetMs]),
8391
+ _optionalChain([a, 'optionalAccess', _434 => _434.countTokens, 'optionalAccess', _435 => _435.estimateBudgetMs]),
8270
8392
  100,
8271
8393
  6e4,
8272
8394
  DEFAULT_ANTHROPIC_SEGMENT.countTokens.estimateBudgetMs
8273
8395
  )
8274
8396
  },
8275
- modelsShape: MODELS_SHAPES.includes(String(_optionalChain([a, 'optionalAccess', _404 => _404.modelsShape]))) ? _optionalChain([a, 'optionalAccess', _405 => _405.modelsShape]) : DEFAULT_ANTHROPIC_SEGMENT.modelsShape,
8397
+ modelsShape: MODELS_SHAPES.includes(String(_optionalChain([a, 'optionalAccess', _436 => _436.modelsShape]))) ? _optionalChain([a, 'optionalAccess', _437 => _437.modelsShape]) : DEFAULT_ANTHROPIC_SEGMENT.modelsShape,
8276
8398
  heartbeatIntervalMs: clampNumber(
8277
- _optionalChain([a, 'optionalAccess', _406 => _406.heartbeatIntervalMs]),
8399
+ _optionalChain([a, 'optionalAccess', _438 => _438.heartbeatIntervalMs]),
8278
8400
  0,
8279
8401
  6e5,
8280
8402
  DEFAULT_ANTHROPIC_SEGMENT.heartbeatIntervalMs
8281
8403
  ),
8282
8404
  pdfTextExtraction: {
8283
8405
  budgetMs: clampNumber(
8284
- _optionalChain([a, 'optionalAccess', _407 => _407.pdfTextExtraction, 'optionalAccess', _408 => _408.budgetMs]),
8406
+ _optionalChain([a, 'optionalAccess', _439 => _439.pdfTextExtraction, 'optionalAccess', _440 => _440.budgetMs]),
8285
8407
  100,
8286
8408
  6e4,
8287
8409
  DEFAULT_ANTHROPIC_SEGMENT.pdfTextExtraction.budgetMs
8288
8410
  )
8289
8411
  },
8290
- proxyOauthUsage: _optionalChain([a, 'optionalAccess', _409 => _409.proxyOauthUsage]) === true,
8291
- apiHello: _optionalChain([a, 'optionalAccess', _410 => _410.apiHello]) !== false
8412
+ proxyOauthUsage: _optionalChain([a, 'optionalAccess', _441 => _441.proxyOauthUsage]) === true,
8413
+ apiHello: _optionalChain([a, 'optionalAccess', _442 => _442.apiHello]) !== false
8292
8414
  };
8293
8415
  }
8294
8416
  var PROXY_TYPES = ["http", "https", "socks5"];
@@ -8373,14 +8495,14 @@ function clampNumber(value, min, max, fallback) {
8373
8495
  return Math.min(max, Math.max(min, n));
8374
8496
  }
8375
8497
  function normalizeQueueSegments(raw) {
8376
- const umq = _optionalChain([raw, 'optionalAccess', _411 => _411.userMessageQueue]);
8377
- const cq = _optionalChain([raw, 'optionalAccess', _412 => _412.concurrencyQueue]);
8498
+ const umq = _optionalChain([raw, 'optionalAccess', _443 => _443.userMessageQueue]);
8499
+ const cq = _optionalChain([raw, 'optionalAccess', _444 => _444.concurrencyQueue]);
8378
8500
  return {
8379
8501
  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),
8502
+ enabled: _optionalChain([umq, 'optionalAccess', _445 => _445.enabled]) === true,
8503
+ delayMs: clampNumber(_optionalChain([umq, 'optionalAccess', _446 => _446.delayMs]), 0, 1e4, DEFAULT_USER_MESSAGE_QUEUE.delayMs),
8382
8504
  waitTimeoutMs: clampNumber(
8383
- _optionalChain([umq, 'optionalAccess', _415 => _415.waitTimeoutMs]),
8505
+ _optionalChain([umq, 'optionalAccess', _447 => _447.waitTimeoutMs]),
8384
8506
  1e3,
8385
8507
  3e5,
8386
8508
  DEFAULT_USER_MESSAGE_QUEUE.waitTimeoutMs
@@ -8388,14 +8510,14 @@ function normalizeQueueSegments(raw) {
8388
8510
  },
8389
8511
  concurrencyQueue: {
8390
8512
  maxQueueSizeFactor: clampNumber(
8391
- _optionalChain([cq, 'optionalAccess', _416 => _416.maxQueueSizeFactor]),
8513
+ _optionalChain([cq, 'optionalAccess', _448 => _448.maxQueueSizeFactor]),
8392
8514
  1,
8393
8515
  10,
8394
8516
  DEFAULT_CONCURRENCY_QUEUE.maxQueueSizeFactor
8395
8517
  ),
8396
- minQueueSize: clampNumber(_optionalChain([cq, 'optionalAccess', _417 => _417.minQueueSize]), 1, 100, DEFAULT_CONCURRENCY_QUEUE.minQueueSize),
8518
+ minQueueSize: clampNumber(_optionalChain([cq, 'optionalAccess', _449 => _449.minQueueSize]), 1, 100, DEFAULT_CONCURRENCY_QUEUE.minQueueSize),
8397
8519
  waitTimeoutMs: clampNumber(
8398
- _optionalChain([cq, 'optionalAccess', _418 => _418.waitTimeoutMs]),
8520
+ _optionalChain([cq, 'optionalAccess', _450 => _450.waitTimeoutMs]),
8399
8521
  1e3,
8400
8522
  3e5,
8401
8523
  DEFAULT_CONCURRENCY_QUEUE.waitTimeoutMs
@@ -8494,6 +8616,7 @@ function normalizeBindingTarget(raw) {
8494
8616
  }
8495
8617
  return null;
8496
8618
  }
8619
+ var MAPPING_EFFORT_MAX_LENGTH = 32;
8497
8620
  function normalizeGatewayModelMappings(raw) {
8498
8621
  if (!Array.isArray(raw)) return [];
8499
8622
  const mappings = [];
@@ -8503,12 +8626,14 @@ function normalizeGatewayModelMappings(raw) {
8503
8626
  const source = typeof value.source === "string" ? value.source.trim() : "";
8504
8627
  const target = typeof value.target === "string" ? value.target.trim() : "";
8505
8628
  if (!source || !target) continue;
8506
- mappings.push({ source, target });
8629
+ const rawEffort = typeof value.effort === "string" ? value.effort.trim() : "";
8630
+ const effort = rawEffort && rawEffort.length <= MAPPING_EFFORT_MAX_LENGTH ? rawEffort : void 0;
8631
+ mappings.push(effort ? { source, target, effort } : { source, target });
8507
8632
  }
8508
8633
  return mappings;
8509
8634
  }
8510
8635
  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()])));
8636
+ return Object.values(_nullishCoalesce(config.modelMap, () => ( {}))).some((value) => typeof value === "string" && value.trim()) || Boolean(_optionalChain([config, 'access', _451 => _451.models, 'optionalAccess', _452 => _452.some, 'call', _453 => _453((value) => typeof value === "string" && value.trim())])) || Boolean(_optionalChain([config, 'access', _454 => _454.defaultModel, 'optionalAccess', _455 => _455.trim, 'call', _456 => _456()])) || Boolean(_optionalChain([config, 'access', _457 => _457.backgroundModel, 'optionalAccess', _458 => _458.trim, 'call', _459 => _459()])) || Boolean(Object.values(_nullishCoalesce(config.prefixTargets, () => ( {}))).some((value) => _optionalChain([value, 'optionalAccess', _460 => _460.trim, 'call', _461 => _461()])));
8512
8637
  }
8513
8638
  function splitModelRef(ref) {
8514
8639
  if (typeof ref !== "string") return null;
@@ -8576,7 +8701,7 @@ function legacyEndpointToBindings(config) {
8576
8701
  if (!parsed) continue;
8577
8702
  const route = routeFor(parsed.providerId);
8578
8703
  route[field] = ref;
8579
- if (_optionalChain([config, 'access', _430 => _430.backgroundModelIds, 'optionalAccess', _431 => _431.length])) {
8704
+ if (_optionalChain([config, 'access', _462 => _462.backgroundModelIds, 'optionalAccess', _463 => _463.length])) {
8580
8705
  route.backgroundModelIds = [...config.backgroundModelIds];
8581
8706
  }
8582
8707
  }
@@ -8759,10 +8884,10 @@ function asObject(value) {
8759
8884
  return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
8760
8885
  }
8761
8886
  function anthropicSessionId(body) {
8762
- const userId = _optionalChain([asObject, 'call', _432 => _432(body["metadata"]), 'optionalAccess', _433 => _433["user_id"]]);
8887
+ const userId = _optionalChain([asObject, 'call', _464 => _464(body["metadata"]), 'optionalAccess', _465 => _465["user_id"]]);
8763
8888
  if (typeof userId !== "string" || !userId) return void 0;
8764
8889
  const matched = ANTHROPIC_SESSION_RE.exec(userId);
8765
- return _optionalChain([matched, 'optionalAccess', _434 => _434[1]]);
8890
+ return _optionalChain([matched, 'optionalAccess', _466 => _466[1]]);
8766
8891
  }
8767
8892
  function anthropicContentFingerprint(body) {
8768
8893
  const messages = body["messages"];
@@ -8795,6 +8920,61 @@ function deriveAuditSessionKey(body, headers = {}, options = {}) {
8795
8920
  return gateway.key;
8796
8921
  }
8797
8922
 
8923
+ // src/outbound-api/mappingEffortInjection.ts
8924
+ function isPlainObject(value) {
8925
+ return !!value && typeof value === "object" && !Array.isArray(value);
8926
+ }
8927
+ function hasOpenAiWireReasoningIntent(body) {
8928
+ return _chunkIUL4VWNUcjs.extractReasoningIntent.call(void 0, {
8929
+ model: typeof body["model"] === "string" ? body["model"] : "",
8930
+ reasoning: isPlainObject(body["reasoning"]) ? body["reasoning"] : void 0,
8931
+ reasoning_effort: body["reasoning_effort"]
8932
+ }) !== void 0;
8933
+ }
8934
+ function injectMappingEffortDefault(endpoint, effort, body) {
8935
+ if (!effort) return false;
8936
+ switch (endpoint) {
8937
+ case "chat":
8938
+ if (hasOpenAiWireReasoningIntent(body)) {
8939
+ return false;
8940
+ }
8941
+ body["reasoning_effort"] = effort;
8942
+ return true;
8943
+ case "responses": {
8944
+ if (hasOpenAiWireReasoningIntent(body)) {
8945
+ return false;
8946
+ }
8947
+ const reasoning = body["reasoning"];
8948
+ body["reasoning"] = {
8949
+ ...isPlainObject(reasoning) ? reasoning : {},
8950
+ effort
8951
+ };
8952
+ return true;
8953
+ }
8954
+ case "messages": {
8955
+ if (body["thinking"] !== void 0) return false;
8956
+ if (effort === "none") return false;
8957
+ body["thinking"] = { type: "adaptive" };
8958
+ const outputConfig = body["output_config"];
8959
+ body["output_config"] = {
8960
+ ...isPlainObject(outputConfig) ? outputConfig : {},
8961
+ effort
8962
+ };
8963
+ return true;
8964
+ }
8965
+ case "gemini": {
8966
+ const generationConfig = body["generationConfig"];
8967
+ const config = isPlainObject(generationConfig) ? generationConfig : {};
8968
+ if (config["thinkingConfig"] !== void 0) return false;
8969
+ body["generationConfig"] = {
8970
+ ...config,
8971
+ thinkingConfig: { thinkingLevel: effort }
8972
+ };
8973
+ return true;
8974
+ }
8975
+ }
8976
+ }
8977
+
8798
8978
  // src/outbound-api/outboundApiKeyAuth.ts
8799
8979
 
8800
8980
 
@@ -8940,7 +9120,7 @@ function effectiveOutboundPermissions(value) {
8940
9120
  if (value === void 0) return LEGACY_OUTBOUND_PERMISSIONS;
8941
9121
  try {
8942
9122
  return validateOutboundPermissions(value);
8943
- } catch (e49) {
9123
+ } catch (e50) {
8944
9124
  return [];
8945
9125
  }
8946
9126
  }
@@ -8981,8 +9161,23 @@ function toVerifiedKey(row) {
8981
9161
  if (rateLimit) key.rateLimit = rateLimit;
8982
9162
  const modelRestriction = extractModelRestriction(row);
8983
9163
  if (modelRestriction) key.modelRestriction = modelRestriction;
9164
+ const directTarget = extractBoundUpstream(row);
9165
+ if (directTarget) key.boundUpstream = directTarget;
8984
9166
  return key;
8985
9167
  }
9168
+ function extractBoundUpstream(row) {
9169
+ if (row.boundUpstream && typeof row.boundUpstream === "object") {
9170
+ const target = row.boundUpstream;
9171
+ 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) {
9172
+ return target;
9173
+ }
9174
+ return void 0;
9175
+ }
9176
+ if (typeof row.boundUpstreamProviderId === "string" && row.boundUpstreamProviderId) {
9177
+ return { kind: "provider", providerId: row.boundUpstreamProviderId };
9178
+ }
9179
+ return void 0;
9180
+ }
8986
9181
  async function verifyKey(db, presentedKey, now = Date.now()) {
8987
9182
  if (!presentedKey) return { status: "invalid" };
8988
9183
  const trimmed = presentedKey.trim();
@@ -9191,8 +9386,8 @@ var OutboundRateLimiter = (_class16 = class {
9191
9386
  * recorded (no bucket growth).
9192
9387
  */
9193
9388
  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));
9389
+ const maxRequests = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _467 => _467.maxRequests]), () => ( this.maxRequests));
9390
+ const windowMs = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _468 => _468.windowMs]), () => ( this.windowMs));
9196
9391
  if (maxRequests === 0) return { allowed: true, retryAfterSeconds: 0 };
9197
9392
  const cutoff = now - windowMs;
9198
9393
  const timestamps = (_nullishCoalesce(this.hits.get(apiKeyId), () => ( []))).filter((ts) => ts > cutoff);
@@ -9378,10 +9573,10 @@ async function handleCodexSearchRequest(req, res, deps) {
9378
9573
  let parseFailed = false;
9379
9574
  try {
9380
9575
  parsed = raw ? JSON.parse(raw) : {};
9381
- } catch (e50) {
9576
+ } catch (e51) {
9382
9577
  parseFailed = true;
9383
9578
  }
9384
- _optionalChain([deps, 'access', _437 => _437.onRequestBody, 'optionalCall', _438 => _438(raw, isRecord10(parsed) ? parsed : {})]);
9579
+ _optionalChain([deps, 'access', _469 => _469.onRequestBody, 'optionalCall', _470 => _470(raw, isRecord10(parsed) ? parsed : {})]);
9385
9580
  if (parseFailed) {
9386
9581
  throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({
9387
9582
  status: 400,
@@ -9426,7 +9621,7 @@ function isUserMessageAnthropic(body) {
9426
9621
  if (typeof content === "string") return true;
9427
9622
  if (Array.isArray(content)) {
9428
9623
  const hasToolResult = content.some(
9429
- (block) => _optionalChain([asObject2, 'call', _439 => _439(block), 'optionalAccess', _440 => _440["type"]]) === "tool_result"
9624
+ (block) => _optionalChain([asObject2, 'call', _471 => _471(block), 'optionalAccess', _472 => _472["type"]]) === "tool_result"
9430
9625
  );
9431
9626
  return !hasToolResult;
9432
9627
  }
@@ -9455,7 +9650,7 @@ function isUserMessageGemini(body) {
9455
9650
  if (!lastContent || lastContent["role"] !== "user") return false;
9456
9651
  const parts = asArray(lastContent["parts"]);
9457
9652
  const hasFunctionResponse = parts.some(
9458
- (part) => _optionalChain([asObject2, 'call', _441 => _441(part), 'optionalAccess', _442 => _442["functionResponse"]]) !== void 0
9653
+ (part) => _optionalChain([asObject2, 'call', _473 => _473(part), 'optionalAccess', _474 => _474["functionResponse"]]) !== void 0
9459
9654
  );
9460
9655
  return !hasFunctionResponse;
9461
9656
  }
@@ -9629,14 +9824,14 @@ function newVoucherId() {
9629
9824
  }
9630
9825
  function computeVoucherGrant(voucher, currentKey, now) {
9631
9826
  if (voucher.type === "credit") {
9632
- const current = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _443 => _443.totalCostLimitUsd]), () => ( 0));
9827
+ const current = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _475 => _475.totalCostLimitUsd]), () => ( 0));
9633
9828
  let granted2 = current + (_nullishCoalesce(voucher.creditUsd, () => ( 0)));
9634
9829
  if (voucher.maxTotalCostLimitUsd != null) {
9635
9830
  granted2 = Math.min(granted2, voucher.maxTotalCostLimitUsd);
9636
9831
  }
9637
9832
  return { totalCostLimitUsd: granted2 };
9638
9833
  }
9639
- const currentExpiry = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _444 => _444.expiresAt]), () => ( now));
9834
+ const currentExpiry = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _476 => _476.expiresAt]), () => ( now));
9640
9835
  let granted = currentExpiry + (_nullishCoalesce(voucher.renewalDays, () => ( 0))) * DAY_MS2;
9641
9836
  if (voucher.maxExpiryDays != null) {
9642
9837
  granted = Math.min(granted, now + voucher.maxExpiryDays * DAY_MS2);
@@ -9667,7 +9862,7 @@ function toVoucherInfo(v) {
9667
9862
  // src/outbound-api/voucherRedeem.ts
9668
9863
  function isRedeemRequest(method, url) {
9669
9864
  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(/\/+$/, "")]), () => ( ""));
9865
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _477 => _477.split, 'call', _478 => _478("?"), 'access', _479 => _479[0], 'optionalAccess', _480 => _480.replace, 'call', _481 => _481(/\/+$/, "")]), () => ( ""));
9671
9866
  return path.endsWith("/redeem");
9672
9867
  }
9673
9868
  function writeErr(res, status, message, headers = {}) {
@@ -9697,8 +9892,8 @@ function grantToResult(type, granted) {
9697
9892
  function currentResult(type, keyRow) {
9698
9893
  const result = { type };
9699
9894
  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) {
9895
+ if (_optionalChain([keyRow, 'optionalAccess', _482 => _482.totalCostLimitUsd]) != null) result.totalCostLimitUsd = keyRow.totalCostLimitUsd;
9896
+ } else if (_optionalChain([keyRow, 'optionalAccess', _483 => _483.expiresAt]) != null) {
9702
9897
  result.expiresAt = keyRow.expiresAt;
9703
9898
  }
9704
9899
  return result;
@@ -9736,7 +9931,7 @@ async function handleVoucherRedeem(req, res, deps, voucherEnabled, redeemLimiter
9736
9931
  let code;
9737
9932
  try {
9738
9933
  code = raw ? JSON.parse(raw)["code"] : void 0;
9739
- } catch (e51) {
9934
+ } catch (e52) {
9740
9935
  writeErr(res, 400, "Invalid JSON in request body");
9741
9936
  return;
9742
9937
  }
@@ -9785,7 +9980,7 @@ async function handleVoucherRedeem(req, res, deps, voucherEnabled, redeemLimiter
9785
9980
  const won = await voucherDb.voucherRedeemCas(voucher.id, verifiedKeyId, absolute, now);
9786
9981
  if (!won) {
9787
9982
  const after = await voucherDb.voucherGetByHash(codeHash);
9788
- if (_optionalChain([after, 'optionalAccess', _452 => _452.status]) === "redeemed" && after.redeemedByKeyId === verifiedKeyId) {
9983
+ if (_optionalChain([after, 'optionalAccess', _484 => _484.status]) === "redeemed" && after.redeemedByKeyId === verifiedKeyId) {
9789
9984
  return after.grantApplied === true ? { ok: true, result: currentResult(after.type, await deps.db.outboundApiKeysGetByHash(keyHash)) } : await applyFirstPass(after, recordedAbsolute(after));
9790
9985
  }
9791
9986
  return { ok: false, status: 409, message: "Code was already redeemed" };
@@ -9860,10 +10055,10 @@ function extractPresentedKey(req) {
9860
10055
  }
9861
10056
  const xApiKey = req.headers["x-api-key"];
9862
10057
  const xApi = Array.isArray(xApiKey) ? xApiKey[0] : xApiKey;
9863
- if (_optionalChain([xApi, 'optionalAccess', _453 => _453.trim, 'call', _454 => _454()])) return xApi.trim();
10058
+ if (_optionalChain([xApi, 'optionalAccess', _485 => _485.trim, 'call', _486 => _486()])) return xApi.trim();
9864
10059
  const goog = req.headers["x-goog-api-key"];
9865
10060
  const g = Array.isArray(goog) ? goog[0] : goog;
9866
- return _optionalChain([g, 'optionalAccess', _455 => _455.trim, 'call', _456 => _456()]) || void 0;
10061
+ return _optionalChain([g, 'optionalAccess', _487 => _487.trim, 'call', _488 => _488()]) || void 0;
9867
10062
  }
9868
10063
  function isLoopbackPeer(address) {
9869
10064
  if (!address) return false;
@@ -9873,10 +10068,10 @@ function isLoopbackPeer(address) {
9873
10068
  function selectEndpoint(method, url) {
9874
10069
  if (method !== "POST" || !url) return null;
9875
10070
  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") {
10071
+ if (_optionalChain([openAIOperation, 'optionalAccess', _489 => _489.policyFamily]) === "chat" || _optionalChain([openAIOperation, 'optionalAccess', _490 => _490.policyFamily]) === "responses") {
9877
10072
  return openAIOperation.policyFamily;
9878
10073
  }
9879
- const path = _nullishCoalesce(_optionalChain([url, 'access', _459 => _459.split, 'call', _460 => _460("?"), 'access', _461 => _461[0], 'optionalAccess', _462 => _462.replace, 'call', _463 => _463(/\/+$/, "")]), () => ( ""));
10074
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _491 => _491.split, 'call', _492 => _492("?"), 'access', _493 => _493[0], 'optionalAccess', _494 => _494.replace, 'call', _495 => _495(/\/+$/, "")]), () => ( ""));
9880
10075
  const classified = classifyAnthropicMessagesPath(url);
9881
10076
  if (classified === "messages" || classified === "count_tokens") return "messages";
9882
10077
  const lastSeg = _nullishCoalesce(path.split("/").pop(), () => ( ""));
@@ -9893,32 +10088,126 @@ function extractGeminiModelFromUrl(url) {
9893
10088
  }
9894
10089
  function isModelsListRequest(url) {
9895
10090
  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(/\/+$/, "")]), () => ( ""));
10091
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _496 => _496.split, 'call', _497 => _497("?"), 'access', _498 => _498[0], 'optionalAccess', _499 => _499.replace, 'call', _500 => _500(/\/+$/, "")]), () => ( ""));
9897
10092
  return path.endsWith("/models");
9898
10093
  }
9899
10094
  function isAnthropicOauthUsagePath(url) {
9900
10095
  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(/\/+$/, "")]), () => ( ""));
10096
+ const path = _nullishCoalesce(_optionalChain([url, 'access', _501 => _501.split, 'call', _502 => _502("?"), 'access', _503 => _503[0], 'optionalAccess', _504 => _504.replace, 'call', _505 => _505(/\/+$/, "")]), () => ( ""));
9902
10097
  return path === "/api/oauth/usage";
9903
10098
  }
9904
10099
  function resolveModelsShape(modelsShape, allowedEndpoints) {
9905
10100
  if (modelsShape === "anthropic") return "anthropic";
9906
10101
  if (modelsShape === "openai") return "openai";
9907
- if (_optionalChain([allowedEndpoints, 'optionalAccess', _474 => _474.includes, 'call', _475 => _475("images")])) return "openai";
10102
+ if (_optionalChain([allowedEndpoints, 'optionalAccess', _506 => _506.includes, 'call', _507 => _507("images")])) return "openai";
9908
10103
  if (!allowedEndpoints || allowedEndpoints.length === 0) return "anthropic";
9909
10104
  return allowedEndpoints.includes("messages") ? "anthropic" : "openai";
9910
10105
  }
10106
+ var UPSTREAM_MODELS_TTL_MS = 6e4;
10107
+ var UPSTREAM_MODELS_NEGATIVE_TTL_MS = 5e3;
10108
+ var UPSTREAM_MODELS_TIMEOUT_MS = 1e4;
10109
+ var upstreamModelsCache = /* @__PURE__ */ new Map();
10110
+ var upstreamModelsInFlight = /* @__PURE__ */ new Map();
10111
+ function resolveProviderKeyLiteral(apiKey) {
10112
+ if (!apiKey) return "";
10113
+ if (apiKey.startsWith("$")) return process.env[apiKey.slice(1)] || "";
10114
+ return apiKey;
10115
+ }
10116
+ function buildProviderModelsUrl(baseUrl, format) {
10117
+ const base = baseUrl.trim().replace(/\/+$/, "");
10118
+ if (!base) return null;
10119
+ if (format === "google") {
10120
+ return /\/models$/.test(base) ? base : `${base}/models`;
10121
+ }
10122
+ if (format === "anthropic") {
10123
+ if (base.endsWith("/messages")) return `${base.slice(0, -"/messages".length)}/models`;
10124
+ if (/\/v\d+$/.test(base)) return `${base}/models`;
10125
+ return `${base}/v1/models`;
10126
+ }
10127
+ const completionSuffix = format === "openai-response" ? "/responses" : "/chat/completions";
10128
+ const root = base.endsWith(completionSuffix) ? base.slice(0, -completionSuffix.length) : base;
10129
+ if (root !== base || /\/v\d+$/.test(base)) return `${root}/models`;
10130
+ return `${base}/v1/models`;
10131
+ }
10132
+ async function fetchUpstreamModelsUncached(provider) {
10133
+ const format = _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider);
10134
+ const url = buildProviderModelsUrl(_nullishCoalesce(provider.api_base_url, () => ( "")), format);
10135
+ if (!url) return [];
10136
+ const headers = _chunkTX4UCSOPcjs.getProviderHeaders.call(void 0, provider, resolveProviderKeyLiteral(provider.api_key));
10137
+ delete headers["Content-Type"];
10138
+ headers["Accept"] = "application/json";
10139
+ const response = await _chunkCXRJMNJJcjs.fetchUpstream.call(void 0,
10140
+ url,
10141
+ { method: "GET", headers, signal: AbortSignal.timeout(UPSTREAM_MODELS_TIMEOUT_MS) },
10142
+ { providerId: "byo" }
10143
+ );
10144
+ if (!response.ok) return [];
10145
+ const body = await response.json();
10146
+ const fromData = Array.isArray(_optionalChain([body, 'optionalAccess', _508 => _508.data])) ? body.data.map((entry) => typeof _optionalChain([entry, 'optionalAccess', _509 => _509.id]) === "string" ? entry.id.trim() : "").filter((id) => id !== "") : [];
10147
+ if (fromData.length > 0) return fromData;
10148
+ return Array.isArray(_optionalChain([body, 'optionalAccess', _510 => _510.models])) ? body.models.map(
10149
+ (entry) => typeof _optionalChain([entry, 'optionalAccess', _511 => _511.name]) === "string" ? entry.name.replace(/^models\//, "").trim() : ""
10150
+ ).filter((id) => id !== "") : [];
10151
+ }
10152
+ async function discoverUpstreamModels(provider) {
10153
+ const cached = upstreamModelsCache.get(provider.id);
10154
+ if (cached) {
10155
+ const ttl = cached.ok ? UPSTREAM_MODELS_TTL_MS : UPSTREAM_MODELS_NEGATIVE_TTL_MS;
10156
+ if (Date.now() - cached.at < ttl) return cached.ids;
10157
+ upstreamModelsCache.delete(provider.id);
10158
+ }
10159
+ const existing = upstreamModelsInFlight.get(provider.id);
10160
+ if (existing) return existing;
10161
+ const pending = (async () => {
10162
+ let ids = [];
10163
+ try {
10164
+ ids = await fetchUpstreamModelsUncached(provider);
10165
+ } catch (e53) {
10166
+ ids = [];
10167
+ }
10168
+ upstreamModelsCache.set(provider.id, { at: Date.now(), ids, ok: ids.length > 0 });
10169
+ return ids;
10170
+ })();
10171
+ upstreamModelsInFlight.set(provider.id, pending);
10172
+ try {
10173
+ return await pending;
10174
+ } finally {
10175
+ upstreamModelsInFlight.delete(provider.id);
10176
+ }
10177
+ }
10178
+ async function passthroughProviderModelIds(llmConfig, providerId) {
10179
+ const provider = await llmConfig.getProvider(providerId);
10180
+ if (!provider) return [];
10181
+ const configured = _nullishCoalesce(provider.models, () => ( []));
10182
+ return configured.length > 0 ? configured : await discoverUpstreamModels(provider);
10183
+ }
9911
10184
  var ANTHROPIC_MODELS_CREATED_AT = (/* @__PURE__ */ new Date()).toISOString();
10185
+ function hasWildcardMapping(binding) {
10186
+ return (_nullishCoalesce(binding.modelMappings, () => ( []))).some(
10187
+ (mapping) => mapping.source.includes("*") && mapping.target.trim() !== ""
10188
+ );
10189
+ }
10190
+ async function pushTargetCatalog(llmConfig, target, push) {
10191
+ if (target.kind === "provider") {
10192
+ for (const id of await passthroughProviderModelIds(llmConfig, target.providerId)) {
10193
+ push(id);
10194
+ }
10195
+ } else if (Object.prototype.hasOwnProperty.call(_subscriptionmodelcatalog.SUBSCRIPTION_MODEL_CATALOG, target.providerId)) {
10196
+ for (const id of _subscriptionmodelcatalog.SUBSCRIPTION_MODEL_CATALOG[target.providerId]) {
10197
+ push(id);
10198
+ }
10199
+ }
10200
+ }
10201
+ var MODEL_LIST_ENDPOINTS = ["chat", "responses", "messages", "gemini"];
9912
10202
  function parseModelsLimit(url) {
9913
- const query = _optionalChain([url, 'optionalAccess', _476 => _476.split, 'call', _477 => _477("?"), 'access', _478 => _478[1]]);
10203
+ const query = _optionalChain([url, 'optionalAccess', _512 => _512.split, 'call', _513 => _513("?"), 'access', _514 => _514[1]]);
9914
10204
  if (!query) return void 0;
9915
10205
  const raw = new URLSearchParams(query).get("limit");
9916
10206
  if (raw === null) return void 0;
9917
10207
  const n = Number.parseInt(raw, 10);
9918
10208
  return Number.isFinite(n) && n > 0 ? n : void 0;
9919
10209
  }
9920
- async function writeModelsListAnthropic(res, llmConfig, config, apiKeyId, allowedEndpoints, limit) {
9921
- void allowedEndpoints;
10210
+ async function writeModelsListAnthropic(res, llmConfig, config, apiKeyId, allowedEndpoints, limit, directTarget) {
9922
10211
  const entries2 = [];
9923
10212
  const seen = /* @__PURE__ */ new Set();
9924
10213
  const push = (id, displayName) => {
@@ -9929,32 +10218,40 @@ async function writeModelsListAnthropic(res, llmConfig, config, apiKeyId, allowe
9929
10218
  );
9930
10219
  };
9931
10220
  const viaLabel = (name, ref) => {
9932
- const modelId = ref ? _optionalChain([_chunk57Y2EA2Gcjs.parseModelRef.call(void 0, ref), 'optionalAccess', _479 => _479.modelId]) : void 0;
10221
+ const modelId = ref ? _optionalChain([_chunk57Y2EA2Gcjs.parseModelRef.call(void 0, ref), 'optionalAccess', _515 => _515.modelId]) : void 0;
9933
10222
  return modelId ? `${name} (via ${modelId})` : void 0;
9934
10223
  };
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);
10224
+ for (const endpoint of MODEL_LIST_ENDPOINTS) {
10225
+ if (allowedEndpoints && !allowedEndpoints.includes(endpoint)) continue;
10226
+ for (const binding of candidateGatewayBindings(config.bindings, apiKeyId, endpoint)) {
10227
+ if (binding.modelMode === "passthrough") {
10228
+ await pushTargetCatalog(llmConfig, binding.target, push);
10229
+ continue;
10230
+ }
10231
+ if (_optionalChain([binding, 'access', _516 => _516.modelMappings, 'optionalAccess', _517 => _517.length])) {
10232
+ for (const mapping of binding.modelMappings) {
10233
+ const source = mapping.source.trim();
10234
+ if (source === "" || source.includes("*")) continue;
10235
+ push(source, viaLabel(source, mapping.target));
10236
+ }
10237
+ if (hasWildcardMapping(binding)) {
10238
+ await pushTargetCatalog(llmConfig, binding.target, push);
10239
+ for (const mapping of _nullishCoalesce(binding.modelMappings, () => ( []))) {
10240
+ if (!mapping.source.includes("*") || mapping.target.trim() === "") continue;
10241
+ push(_nullishCoalesce(_optionalChain([_chunk57Y2EA2Gcjs.parseModelRef.call(void 0, mapping.target), 'optionalAccess', _518 => _518.modelId]), () => ( mapping.target.trim())));
10242
+ }
9943
10243
  }
10244
+ continue;
9944
10245
  }
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));
10246
+ for (const [kind, ref] of Object.entries(_nullishCoalesce(binding.modelMap, () => ( {})))) {
10247
+ if (typeof ref !== "string" || ref.trim() === "") continue;
10248
+ push(kind, viaLabel(kind, ref));
9952
10249
  }
9953
- continue;
9954
10250
  }
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));
10251
+ }
10252
+ if (_optionalChain([directTarget, 'optionalAccess', _519 => _519.kind]) === "provider") {
10253
+ for (const id of await passthroughProviderModelIds(llmConfig, directTarget.providerId)) {
10254
+ push(id);
9958
10255
  }
9959
10256
  }
9960
10257
  const limited = limit !== void 0 ? entries2.slice(0, limit) : entries2;
@@ -9962,9 +10259,9 @@ async function writeModelsListAnthropic(res, llmConfig, config, apiKeyId, allowe
9962
10259
  res.end(
9963
10260
  JSON.stringify({
9964
10261
  data: limited,
9965
- first_id: _nullishCoalesce(_optionalChain([limited, 'access', _483 => _483[0], 'optionalAccess', _484 => _484.id]), () => ( null)),
10262
+ first_id: _nullishCoalesce(_optionalChain([limited, 'access', _520 => _520[0], 'optionalAccess', _521 => _521.id]), () => ( null)),
9966
10263
  has_more: limited.length < entries2.length,
9967
- last_id: _nullishCoalesce(_optionalChain([limited, 'access', _485 => _485[limited.length - 1], 'optionalAccess', _486 => _486.id]), () => ( null))
10264
+ last_id: _nullishCoalesce(_optionalChain([limited, 'access', _522 => _522[limited.length - 1], 'optionalAccess', _523 => _523.id]), () => ( null))
9968
10265
  })
9969
10266
  );
9970
10267
  }
@@ -9986,8 +10283,8 @@ function handleOauthUsageProxy(res, config, apiKeyId) {
9986
10283
  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
10284
  const body = {};
9988
10285
  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";
10286
+ const window = _optionalChain([snapshot, 'optionalAccess', _524 => _524.windows, 'access', _525 => _525.find, 'call', _526 => _526((w) => w.id === windowId)]);
10287
+ const usable = _optionalChain([window, 'optionalAccess', _527 => _527.state]) === "fresh";
9991
10288
  body[wireKey] = {
9992
10289
  utilization: usable ? _nullishCoalesce(window.usedPercent, () => ( null)) : null,
9993
10290
  resets_at: usable ? _nullishCoalesce(window.resetsAt, () => ( null)) : null
@@ -9996,29 +10293,172 @@ function handleOauthUsageProxy(res, config, apiKeyId) {
9996
10293
  res.writeHead(200, { "Content-Type": "application/json" });
9997
10294
  res.end(JSON.stringify(body));
9998
10295
  }
9999
- async function writeModelsList(res, llmConfig, config, apiKeyId, allowedEndpoints, imageModels = []) {
10296
+ function directUpstreamRoot(baseUrl, format) {
10297
+ const base = baseUrl.trim().replace(/\/+$/, "");
10298
+ if (!base) return null;
10299
+ if (format === "google") return base.replace(/\/models$/, "");
10300
+ if (format === "anthropic") return base.replace(/\/messages$/, "");
10301
+ if (format === "openai-response") return base.replace(/\/responses$/, "");
10302
+ return base.replace(/\/chat\/completions$/, "");
10303
+ }
10304
+ function directUpstreamUrl(provider, requestUrl) {
10305
+ const root = directUpstreamRoot(
10306
+ _nullishCoalesce(provider.api_base_url, () => ( "")),
10307
+ _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider)
10308
+ );
10309
+ if (!root) return null;
10310
+ const raw = _nullishCoalesce(requestUrl, () => ( "/"));
10311
+ const queryIndex = raw.indexOf("?");
10312
+ const path = (queryIndex >= 0 ? raw.slice(0, queryIndex) : raw) || "/";
10313
+ const query = queryIndex >= 0 ? raw.slice(queryIndex) : "";
10314
+ const versionSegment = _optionalChain([/\/v\d+[a-z]*$/, 'access', _528 => _528.exec, 'call', _529 => _529(root), 'optionalAccess', _530 => _530[0]]);
10315
+ let tail = path;
10316
+ if (versionSegment) {
10317
+ if (path === versionSegment) tail = "";
10318
+ else if (path.startsWith(`${versionSegment}/`)) tail = path.slice(versionSegment.length);
10319
+ }
10320
+ return `${root}${tail}${query}`;
10321
+ }
10322
+ function directUpstreamBinding(target, apiKeyId, priority = 1e3) {
10323
+ return {
10324
+ id: `direct:${apiKeyId}`,
10325
+ name: "direct upstream",
10326
+ enabled: true,
10327
+ keyScope: "selected",
10328
+ apiKeyIds: [apiKeyId],
10329
+ endpoint: "messages",
10330
+ target,
10331
+ priority,
10332
+ fallback: "fail",
10333
+ modelMode: "passthrough"
10334
+ };
10335
+ }
10336
+ async function relayDirectUpstream(req, res, deps, verified, config, concurrencyGate, audit, preReadBody) {
10337
+ const direct = verified.boundUpstream;
10338
+ const providerId = _optionalChain([direct, 'optionalAccess', _531 => _531.kind]) === "provider" ? direct.providerId : "";
10339
+ const provider = await deps.llmConfig.getProvider(providerId);
10340
+ if (!provider) {
10341
+ writeJsonError(
10342
+ res,
10343
+ 503,
10344
+ `direct upstream provider '${providerId}' is not configured for this key`
10345
+ );
10346
+ return;
10347
+ }
10348
+ const url = directUpstreamUrl(provider, req.url);
10349
+ if (!url) {
10350
+ writeJsonError(res, 503, `direct upstream provider '${providerId}' has no base URL`);
10351
+ return;
10352
+ }
10353
+ const concurrencyLimit = verified.maxConcurrency;
10354
+ let releaseConcurrency = null;
10355
+ if (typeof concurrencyLimit === "number" && concurrencyLimit > 0) {
10356
+ const cq = _nullishCoalesce(config.concurrencyQueue, () => ( DEFAULT_CONCURRENCY_QUEUE));
10357
+ const acquisition = concurrencyGate.acquire(verified.id, concurrencyLimit, {
10358
+ maxQueueSizeFactor: cq.maxQueueSizeFactor,
10359
+ minQueueSize: cq.minQueueSize,
10360
+ waitTimeoutMs: cq.waitTimeoutMs
10361
+ });
10362
+ const cancelOnClose = () => acquisition.cancel();
10363
+ res.once("close", cancelOnClose);
10364
+ let slot;
10365
+ try {
10366
+ slot = await acquisition.granted;
10367
+ } catch (err) {
10368
+ res.removeListener("close", cancelOnClose);
10369
+ if (isConcurrencyRejection(err)) {
10370
+ writeJsonError(res, 429, "Concurrency limit exceeded", { "Retry-After": "5" });
10371
+ return;
10372
+ }
10373
+ throw err;
10374
+ }
10375
+ res.removeListener("close", cancelOnClose);
10376
+ const release2 = () => slot.release();
10377
+ releaseConcurrency = release2;
10378
+ res.once("close", release2);
10379
+ }
10380
+ try {
10381
+ const rawBody = preReadBody !== void 0 ? preReadBody : await readBody3(req);
10382
+ if (audit) {
10383
+ audit.setRequestBody(rawBody);
10384
+ try {
10385
+ audit.sessionKey = deriveAuditSessionKey(
10386
+ rawBody ? JSON.parse(rawBody) : {},
10387
+ req.headers,
10388
+ { fallbackKey: verified.id, endpoint: "direct" }
10389
+ );
10390
+ } catch (e54) {
10391
+ }
10392
+ }
10393
+ const headers = _chunkTX4UCSOPcjs.getProviderHeaders.call(void 0, provider, resolveProviderKeyLiteral(provider.api_key));
10394
+ delete headers["Content-Type"];
10395
+ const clientContentType = req.headers["content-type"];
10396
+ if (typeof clientContentType === "string" && clientContentType) {
10397
+ headers["Content-Type"] = clientContentType;
10398
+ }
10399
+ const clientAccept = req.headers["accept"];
10400
+ if (typeof clientAccept === "string" && clientAccept) headers["Accept"] = clientAccept;
10401
+ const hasRequestBody = req.method !== "GET" && req.method !== "HEAD";
10402
+ const upstream = await _chunkCXRJMNJJcjs.fetchUpstream.call(void 0,
10403
+ url,
10404
+ {
10405
+ method: _nullishCoalesce(req.method, () => ( "GET")),
10406
+ headers,
10407
+ ...hasRequestBody ? { body: rawBody } : {},
10408
+ // Client hang-up aborts the upstream call (no egress after cancel).
10409
+ signal: requestLifecycleSignal(req, res)
10410
+ },
10411
+ { providerId: "byo" }
10412
+ );
10413
+ if (audit) audit.provider = provider.id;
10414
+ const responseHeaders = {};
10415
+ const contentType = upstream.headers.get("content-type");
10416
+ if (contentType) responseHeaders["Content-Type"] = contentType;
10417
+ res.writeHead(upstream.status, responseHeaders);
10418
+ if (!upstream.body) {
10419
+ res.end();
10420
+ return;
10421
+ }
10422
+ const bodyStream = _stream.Readable.fromWeb(
10423
+ upstream.body
10424
+ );
10425
+ bodyStream.on("error", () => {
10426
+ res.destroy();
10427
+ });
10428
+ bodyStream.pipe(res);
10429
+ await new Promise((resolve) => {
10430
+ res.once("close", resolve);
10431
+ });
10432
+ } catch (err) {
10433
+ const message = _chunkSVNDB62Dcjs.serializeError.call(void 0, err);
10434
+ if (deps.logger) deps.logger.error("[OutboundApi] direct relay error:", message);
10435
+ else console.error("[OutboundApi] direct relay error:", message);
10436
+ _chunkUIBD2YY5cjs.emitWebhookEvent.call(void 0, { kind: "server.error", at: Date.now(), message });
10437
+ if (audit) audit.error = message;
10438
+ if (!res.headersSent) writeJsonError(res, 502, message);
10439
+ else res.destroy();
10440
+ }
10441
+ }
10442
+ async function writeModelsList(res, llmConfig, config, apiKeyId, allowedEndpoints, imageModels = [], directTarget) {
10000
10443
  const modelIds = [];
10001
- for (const endpoint of ["chat", "responses", "messages", "gemini"]) {
10444
+ for (const endpoint of MODEL_LIST_ENDPOINTS) {
10002
10445
  if (allowedEndpoints && !allowedEndpoints.includes(endpoint)) continue;
10003
10446
  for (const binding of candidateGatewayBindings(config.bindings, apiKeyId, endpoint)) {
10004
10447
  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
- }
10448
+ await pushTargetCatalog(llmConfig, binding.target, (id) => modelIds.push(id));
10016
10449
  continue;
10017
10450
  }
10018
- if (_optionalChain([binding, 'access', _492 => _492.modelMappings, 'optionalAccess', _493 => _493.length])) {
10451
+ if (_optionalChain([binding, 'access', _532 => _532.modelMappings, 'optionalAccess', _533 => _533.length])) {
10019
10452
  modelIds.push(
10020
10453
  ...binding.modelMappings.map((mapping) => mapping.source.trim()).filter((source) => source !== "" && !source.includes("*"))
10021
10454
  );
10455
+ if (hasWildcardMapping(binding)) {
10456
+ await pushTargetCatalog(llmConfig, binding.target, (id) => modelIds.push(id));
10457
+ for (const mapping of _nullishCoalesce(binding.modelMappings, () => ( []))) {
10458
+ if (!mapping.source.includes("*") || mapping.target.trim() === "") continue;
10459
+ modelIds.push(_nullishCoalesce(_optionalChain([_chunk57Y2EA2Gcjs.parseModelRef.call(void 0, mapping.target), 'optionalAccess', _534 => _534.modelId]), () => ( mapping.target.trim())));
10460
+ }
10461
+ }
10022
10462
  continue;
10023
10463
  }
10024
10464
  const endpointConfig = gatewayBindingToEndpointConfig(binding);
@@ -10031,10 +10471,13 @@ async function writeModelsList(res, llmConfig, config, apiKeyId, allowedEndpoint
10031
10471
  if (endpointConfig.backgroundModel) refs.push(endpointConfig.backgroundModel);
10032
10472
  }
10033
10473
  modelIds.push(
10034
- ...refs.map((ref) => _optionalChain([_chunk57Y2EA2Gcjs.parseModelRef.call(void 0, ref), 'optionalAccess', _494 => _494.modelId])).filter((modelId) => modelId !== void 0)
10474
+ ...refs.map((ref) => _optionalChain([_chunk57Y2EA2Gcjs.parseModelRef.call(void 0, ref), 'optionalAccess', _535 => _535.modelId])).filter((modelId) => modelId !== void 0)
10035
10475
  );
10036
10476
  }
10037
10477
  }
10478
+ if (_optionalChain([directTarget, 'optionalAccess', _536 => _536.kind]) === "provider") {
10479
+ modelIds.push(...await passthroughProviderModelIds(llmConfig, directTarget.providerId));
10480
+ }
10038
10481
  modelIds.push(...imageModels);
10039
10482
  const seen = /* @__PURE__ */ new Set();
10040
10483
  const data = modelIds.filter((modelId) => {
@@ -10078,9 +10521,9 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10078
10521
  const anthropicPathClass = classifyAnthropicMessagesPath(req.url);
10079
10522
  const isCountTokens = anthropicPathClass === "count_tokens";
10080
10523
  const classifiedOperation = _chunkG4CZIUIBcjs.classifyOpenAIOperation.call(void 0, req.method, req.url);
10081
- const imageOperation = _optionalChain([classifiedOperation, 'optionalAccess', _495 => _495.policyFamily]) === "images" ? classifiedOperation : null;
10524
+ const imageOperation = _optionalChain([classifiedOperation, 'optionalAccess', _537 => _537.policyFamily]) === "images" ? classifiedOperation : null;
10082
10525
  if (anthropicPathClass !== null) markAnthropicProtocolResponse(res);
10083
- const proxyOauthUsageEnabled = _optionalChain([config, 'access', _496 => _496.anthropic, 'optionalAccess', _497 => _497.proxyOauthUsage]) === true;
10526
+ const proxyOauthUsageEnabled = _optionalChain([config, 'access', _538 => _538.anthropic, 'optionalAccess', _539 => _539.proxyOauthUsage]) === true;
10084
10527
  const isOauthUsagePath = proxyOauthUsageEnabled && isAnthropicOauthUsagePath(req.url);
10085
10528
  if (isOauthUsagePath) markAnthropicProtocolResponse(res);
10086
10529
  const audit = _chunkFX325I5Qcjs.beginAuditCapture.call(void 0, req, res, now, {
@@ -10100,7 +10543,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10100
10543
  const verified = verification.key;
10101
10544
  if (audit) audit.keyId = verified.id;
10102
10545
  if (billing) billing.keyId = verified.id;
10103
- if (verified.loopbackOnly && !isLoopbackPeer(_optionalChain([req, 'access', _498 => _498.socket, 'optionalAccess', _499 => _499.remoteAddress]))) {
10546
+ if (verified.loopbackOnly && !isLoopbackPeer(_optionalChain([req, 'access', _540 => _540.socket, 'optionalAccess', _541 => _541.remoteAddress]))) {
10104
10547
  writeJsonError(res, 403, "This integration key is restricted to loopback clients");
10105
10548
  return;
10106
10549
  }
@@ -10113,7 +10556,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10113
10556
  req,
10114
10557
  res,
10115
10558
  deps,
10116
- _optionalChain([config, 'access', _500 => _500.voucher, 'optionalAccess', _501 => _501.enabled]) === true,
10559
+ _optionalChain([config, 'access', _542 => _542.voucher, 'optionalAccess', _543 => _543.enabled]) === true,
10117
10560
  _nullishCoalesce(redeemLimiter, () => ( getFallbackRedeemLimiter())),
10118
10561
  verified.id,
10119
10562
  _nullishCoalesce(presented, () => ( "")),
@@ -10129,6 +10572,16 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10129
10572
  });
10130
10573
  return;
10131
10574
  }
10575
+ const directProvider = _optionalChain([verified, 'access', _544 => _544.boundUpstream, 'optionalAccess', _545 => _545.kind]) === "provider" ? verified.boundUpstream : null;
10576
+ if (verified.boundUpstream && !directProvider) {
10577
+ config = {
10578
+ ...config,
10579
+ bindings: [
10580
+ ..._nullishCoalesce(config.bindings, () => ( [])),
10581
+ directUpstreamBinding(verified.boundUpstream, verified.id, 1e3)
10582
+ ]
10583
+ };
10584
+ }
10132
10585
  if (isOauthUsagePath) {
10133
10586
  if (req.method !== "GET") {
10134
10587
  writeJsonError(res, 404, `Unsupported: ${req.method} ${req.url}`);
@@ -10162,7 +10615,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10162
10615
  }
10163
10616
  if (isCodexSearchRequest(req.method, req.url)) {
10164
10617
  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)),
10618
+ mode: _nullishCoalesce(_optionalChain([config, 'access', _546 => _546.search, 'optionalAccess', _547 => _547.modes, 'access', _548 => _548.codex]), () => ( _chunkE4QHVXV5cjs.DEFAULT_SEARCH_FRONTEND_MODES.codex)),
10166
10619
  runtime: _nullishCoalesce(deps.searchRuntime, () => ( null)),
10167
10620
  // This handler EXECUTES rather than relays, and `handleOutboundRequest`
10168
10621
  // has no signal of its own to hand down, so it builds one. Without it a
@@ -10185,21 +10638,22 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10185
10638
  writeJsonError(res, 403, "API key is not allowed to access this endpoint");
10186
10639
  return;
10187
10640
  }
10188
- if (resolveModelsShape(_optionalChain([config, 'access', _505 => _505.anthropic, 'optionalAccess', _506 => _506.modelsShape]), verified.allowedEndpoints) === "anthropic") {
10641
+ if (resolveModelsShape(_optionalChain([config, 'access', _549 => _549.anthropic, 'optionalAccess', _550 => _550.modelsShape]), verified.allowedEndpoints) === "anthropic") {
10189
10642
  await writeModelsListAnthropic(
10190
10643
  res,
10191
10644
  deps.llmConfig,
10192
10645
  config,
10193
10646
  verified.id,
10194
10647
  verified.allowedEndpoints,
10195
- parseModelsLimit(req.url)
10648
+ parseModelsLimit(req.url),
10649
+ verified.boundUpstream
10196
10650
  );
10197
10651
  } else {
10198
10652
  let imageModels = [];
10199
10653
  if (verified.allowedEndpoints.includes("images") && deps.imageModelCatalog) {
10200
10654
  try {
10201
10655
  imageModels = await deps.imageModelCatalog.listAvailableModels(verified.id);
10202
- } catch (e52) {
10656
+ } catch (e55) {
10203
10657
  }
10204
10658
  }
10205
10659
  await writeModelsList(
@@ -10208,21 +10662,26 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10208
10662
  config,
10209
10663
  verified.id,
10210
10664
  verified.allowedEndpoints,
10211
- imageModels
10665
+ imageModels,
10666
+ verified.boundUpstream
10212
10667
  );
10213
10668
  }
10214
10669
  return;
10215
10670
  }
10216
10671
  const endpoint = selectEndpoint(req.method, req.url);
10217
10672
  if (!endpoint) {
10673
+ if (directProvider) {
10674
+ await relayDirectUpstream(req, res, deps, verified, config, concurrencyGate, audit);
10675
+ return;
10676
+ }
10218
10677
  writeJsonError(res, 404, `Unsupported: ${req.method} ${req.url}`);
10219
10678
  return;
10220
10679
  }
10221
- if (verified.allowedEndpoints && !verified.allowedEndpoints.includes(endpoint)) {
10680
+ if (verified.allowedEndpoints && !verified.boundUpstream && !verified.allowedEndpoints.includes(endpoint)) {
10222
10681
  writeJsonError(res, 403, "API key is not allowed to access this endpoint");
10223
10682
  return;
10224
10683
  }
10225
- if (candidateGatewayBindings(config.bindings, verified.id, endpoint).length === 0) {
10684
+ if (candidateGatewayBindings(config.bindings, verified.id, endpoint).length === 0 && !directProvider) {
10226
10685
  writeJsonError(res, 503, `endpoint '${endpoint}' has no downstream route for this key`);
10227
10686
  return;
10228
10687
  }
@@ -10287,7 +10746,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10287
10746
  let parsedBody = {};
10288
10747
  try {
10289
10748
  parsedBody = rawBody ? JSON.parse(rawBody) : {};
10290
- } catch (e53) {
10749
+ } catch (e56) {
10291
10750
  writeJsonError(res, 400, "Invalid JSON in request body");
10292
10751
  return;
10293
10752
  }
@@ -10316,22 +10775,31 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10316
10775
  role
10317
10776
  });
10318
10777
  if (bindingResolution.source === "none") {
10778
+ if (directProvider) {
10779
+ await relayDirectUpstream(req, res, deps, verified, config, concurrencyGate, audit, rawBody);
10780
+ return;
10781
+ }
10319
10782
  writeJsonError(res, 503, `endpoint '${endpoint}' has no downstream route for this key`);
10320
10783
  return;
10321
10784
  }
10322
10785
  const effectiveEndpointConfig = bindingResolution.config;
10323
10786
  const bindingAffinitySuffix = `:${bindingResolution.binding.id}`;
10324
10787
  const sessionId = deps.proxyDeps.apiKeyPool ? `outbound:${verified.id}${bindingAffinitySuffix}` : null;
10788
+ let replayBody = rawBody;
10789
+ if (!isCountTokens && effectiveEndpointConfig.reasoningEffort && injectMappingEffortDefault(endpoint, effectiveEndpointConfig.reasoningEffort, parsedBody)) {
10790
+ replayBody = JSON.stringify(parsedBody);
10791
+ }
10325
10792
  const hostedImageGenerationAllowed = verified.allowedEndpoints.includes("images");
10793
+ const listResolvedModel = endpoint === "chat" && bindingResolution.binding.modelMode === "mapped" ? _nullishCoalesce(_optionalChain([resolveGatewayModelMappingRow, 'call', _551 => _551(bindingResolution.binding.modelMappings, requestedModel), 'optionalAccess', _552 => _552.target]), () => ( requestedModel)) : requestedModel;
10326
10794
  const resolved = _chunk57Y2EA2Gcjs.isKindMappedEndpoint.call(void 0, endpoint) || endpoint === "chat" ? await _chunk57Y2EA2Gcjs.resolveRoute.call(void 0, {
10327
10795
  config: effectiveEndpointConfig,
10328
10796
  ingressFormat,
10329
10797
  llmConfig: deps.llmConfig,
10330
10798
  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,
10799
+ // The id the route resolves against: the client's ORIGINAL id for
10800
+ // kind-mapped endpoints (it selects the kind AND is stamped onto
10801
+ // `route.requestedModel`), the mapping-resolved target for chat.
10802
+ requestedModel: listResolvedModel,
10335
10803
  // Attribution: stamp the verified named-key id onto the route.
10336
10804
  apiKeyId: verified.id,
10337
10805
  hostedImageGenerationAllowed
@@ -10346,6 +10814,10 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10346
10814
  hostedImageGenerationAllowed
10347
10815
  });
10348
10816
  if (!resolved.ok) {
10817
+ if (directProvider) {
10818
+ await relayDirectUpstream(req, res, deps, verified, config, concurrencyGate, audit, rawBody);
10819
+ return;
10820
+ }
10349
10821
  writeJsonError(res, resolved.error.status, resolved.error.message);
10350
10822
  return;
10351
10823
  }
@@ -10367,7 +10839,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10367
10839
  }
10368
10840
  let releaseSerial = null;
10369
10841
  const providerKey = resolved.route.providerId;
10370
- if (_optionalChain([config, 'access', _507 => _507.userMessageQueue, 'optionalAccess', _508 => _508.enabled]) && providerKey && !isCountTokens && isUserMessageRequest(endpoint, parsedBody)) {
10842
+ if (_optionalChain([config, 'access', _553 => _553.userMessageQueue, 'optionalAccess', _554 => _554.enabled]) && providerKey && !isCountTokens && isUserMessageRequest(endpoint, parsedBody)) {
10371
10843
  const umq = config.userMessageQueue;
10372
10844
  try {
10373
10845
  const serialSlot = await serialQueue.acquire(providerKey, {
@@ -10397,17 +10869,17 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
10397
10869
  const token = routeMap.addRoute(
10398
10870
  isCountTokens ? {
10399
10871
  ...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])
10872
+ anthropicCountTokensMode: _optionalChain([config, 'access', _555 => _555.anthropic, 'optionalAccess', _556 => _556.countTokens, 'optionalAccess', _557 => _557.mode]),
10873
+ anthropicCountTokensEstimateBudgetMs: _optionalChain([config, 'access', _558 => _558.anthropic, 'optionalAccess', _559 => _559.countTokens, 'optionalAccess', _560 => _560.estimateBudgetMs]),
10874
+ anthropicPdfTextExtractionBudgetMs: _optionalChain([config, 'access', _561 => _561.anthropic, 'optionalAccess', _562 => _562.pdfTextExtraction, 'optionalAccess', _563 => _563.budgetMs])
10403
10875
  } : anthropicPathClass !== null ? {
10404
10876
  ...requestRoute,
10405
- anthropicPdfTextExtractionBudgetMs: _optionalChain([config, 'access', _518 => _518.anthropic, 'optionalAccess', _519 => _519.pdfTextExtraction, 'optionalAccess', _520 => _520.budgetMs])
10877
+ anthropicPdfTextExtractionBudgetMs: _optionalChain([config, 'access', _564 => _564.anthropic, 'optionalAccess', _565 => _565.pdfTextExtraction, 'optionalAccess', _566 => _566.budgetMs])
10406
10878
  } : requestRoute
10407
10879
  );
10408
10880
  try {
10409
10881
  shimAuthHeader(req, token);
10410
- const replay = makeReplayRequest(req, rawBody);
10882
+ const replay = makeReplayRequest(req, replayBody);
10411
10883
  await routeRequest(replay, res, routeMap, deps.proxyDeps);
10412
10884
  } catch (err) {
10413
10885
  if (_chunk25GXJCEZcjs.isBoundAccountSelectionError.call(void 0, err)) {
@@ -10586,7 +11058,7 @@ var OutboundApiServer = (_class19 = class {
10586
11058
  this.server = listener.server;
10587
11059
  this.boundAddr = bindAddr;
10588
11060
  this.boundPort = actualPort;
10589
- if (actualPort !== port) _optionalChain([this, 'access', _521 => _521.onPortChange, 'optionalCall', _522 => _522(actualPort)]);
11061
+ if (actualPort !== port) _optionalChain([this, 'access', _567 => _567.onPortChange, 'optionalCall', _568 => _568(actualPort)]);
10590
11062
  this.logInfo(`[OutboundApiServer] Listening on ${bindAddr}:${actualPort}`);
10591
11063
  return actualPort;
10592
11064
  }
@@ -10629,8 +11101,8 @@ var OutboundApiServer = (_class19 = class {
10629
11101
  this.anthropicConfig = input.anthropic;
10630
11102
  this.searchConfig = input.search;
10631
11103
  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]));
11104
+ this.apiHelloEnabled = _optionalChain([input, 'access', _569 => _569.anthropic, 'optionalAccess', _570 => _570.apiHello]) !== false;
11105
+ _chunkVGBJPHHDcjs.setAnthropicPingHeartbeatMs.call(void 0, _optionalChain([input, 'access', _571 => _571.anthropic, 'optionalAccess', _572 => _572.heartbeatIntervalMs]));
10634
11106
  }
10635
11107
  captureRuntimeSnapshot() {
10636
11108
  return {
@@ -10656,8 +11128,8 @@ var OutboundApiServer = (_class19 = class {
10656
11128
  this.anthropicConfig = snapshot.anthropic;
10657
11129
  this.searchConfig = snapshot.search;
10658
11130
  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]));
11131
+ this.apiHelloEnabled = _optionalChain([snapshot, 'access', _573 => _573.anthropic, 'optionalAccess', _574 => _574.apiHello]) !== false;
11132
+ _chunkVGBJPHHDcjs.setAnthropicPingHeartbeatMs.call(void 0, _optionalChain([snapshot, 'access', _575 => _575.anthropic, 'optionalAccess', _576 => _576.heartbeatIntervalMs]));
10661
11133
  }
10662
11134
  async restoreRuntimeSnapshot(snapshot) {
10663
11135
  const current = this.server;
@@ -10691,22 +11163,22 @@ var OutboundApiServer = (_class19 = class {
10691
11163
  server.close(() => {
10692
11164
  try {
10693
11165
  this.logInfo("[OutboundApiServer] Stopped");
10694
- } catch (e54) {
11166
+ } catch (e57) {
10695
11167
  }
10696
11168
  });
10697
- } catch (e55) {
11169
+ } catch (e58) {
10698
11170
  }
10699
11171
  }
10700
11172
  announcePublishedListener(bindAddr, requestedPort, actualPort) {
10701
11173
  if (actualPort !== requestedPort) {
10702
11174
  try {
10703
- _optionalChain([this, 'access', _531 => _531.onPortChange, 'optionalCall', _532 => _532(actualPort)]);
10704
- } catch (e56) {
11175
+ _optionalChain([this, 'access', _577 => _577.onPortChange, 'optionalCall', _578 => _578(actualPort)]);
11176
+ } catch (e59) {
10705
11177
  }
10706
11178
  }
10707
11179
  try {
10708
11180
  this.logInfo(`[OutboundApiServer] Listening on ${bindAddr}:${actualPort}`);
10709
- } catch (e57) {
11181
+ } catch (e60) {
10710
11182
  }
10711
11183
  }
10712
11184
  /** Per-request handler. Auth is enforced on EVERY request (incl. loopback). */
@@ -10753,7 +11225,7 @@ var OutboundApiServer = (_class19 = class {
10753
11225
  tryServeApiHello(req, res) {
10754
11226
  if (!this.apiHelloEnabled) return false;
10755
11227
  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(/\/+$/, "")]) || "/";
11228
+ const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access', _579 => _579.split, 'call', _580 => _580("?"), 'access', _581 => _581[0], 'optionalAccess', _582 => _582.replace, 'call', _583 => _583(/\/+$/, "")]) || "/";
10757
11229
  if (path !== "/api/hello") return false;
10758
11230
  res.writeHead(200);
10759
11231
  res.end();
@@ -10767,7 +11239,7 @@ var OutboundApiServer = (_class19 = class {
10767
11239
  const provider = this.deps.healthReportProvider;
10768
11240
  if (!provider) return false;
10769
11241
  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(/\/+$/, "")]) || "/";
11242
+ const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access', _584 => _584.split, 'call', _585 => _585("?"), 'access', _586 => _586[0], 'optionalAccess', _587 => _587.replace, 'call', _588 => _588(/\/+$/, "")]) || "/";
10771
11243
  if (path !== "/health" && path !== "/healthz") return false;
10772
11244
  const report = provider();
10773
11245
  res.writeHead(_healthloggingtypes.healthHttpStatus.call(void 0, report.status), { "Content-Type": "application/json" });
@@ -10992,7 +11464,7 @@ function resolveCompletionReasoningPlan(provider, options, target, requestMaxTok
10992
11464
  }
10993
11465
  function resolveOpenAIEffort(provider, options, target) {
10994
11466
  const plan = resolveCompletionReasoningPlan(provider, options, target);
10995
- return _optionalChain([plan, 'optionalAccess', _543 => _543.kind]) === "level" && plan.enabled ? plan.effort : void 0;
11467
+ return _optionalChain([plan, 'optionalAccess', _589 => _589.kind]) === "level" && plan.enabled ? plan.effort : void 0;
10996
11468
  }
10997
11469
  function buildAnthropicReasoningWire(provider, options) {
10998
11470
  const configuredMaxTokens = _nullishCoalesce(options.maxTokens, () => ( LEGACY_ANTHROPIC_MAX_TOKENS));
@@ -11003,7 +11475,7 @@ function buildAnthropicReasoningWire(provider, options) {
11003
11475
  "anthropic",
11004
11476
  legacyBound
11005
11477
  );
11006
- if (_optionalChain([plan, 'optionalAccess', _544 => _544.kind]) === "level" && plan.enabled) {
11478
+ if (_optionalChain([plan, 'optionalAccess', _590 => _590.kind]) === "level" && plan.enabled) {
11007
11479
  return {
11008
11480
  effectiveMaxTokens: configuredMaxTokens,
11009
11481
  thinking: { type: "adaptive" },
@@ -11011,7 +11483,7 @@ function buildAnthropicReasoningWire(provider, options) {
11011
11483
  legacyBudgetEnabled: false
11012
11484
  };
11013
11485
  }
11014
- if (_optionalChain([plan, 'optionalAccess', _545 => _545.kind]) === "budget" && plan.enabled) {
11486
+ if (_optionalChain([plan, 'optionalAccess', _591 => _591.kind]) === "budget" && plan.enabled) {
11015
11487
  return {
11016
11488
  effectiveMaxTokens: legacyBound,
11017
11489
  thinking: { type: "enabled", budget_tokens: plan.budgetTokens },
@@ -11025,13 +11497,13 @@ function buildAnthropicReasoningWire(provider, options) {
11025
11497
  }
11026
11498
  function buildGeminiThinkingConfig(provider, options) {
11027
11499
  const plan = resolveCompletionReasoningPlan(provider, options, "gemini");
11028
- if (_optionalChain([plan, 'optionalAccess', _546 => _546.kind]) === "level") {
11500
+ if (_optionalChain([plan, 'optionalAccess', _592 => _592.kind]) === "level") {
11029
11501
  return {
11030
11502
  includeThoughts: plan.enabled,
11031
11503
  thinkingLevel: plan.effort
11032
11504
  };
11033
11505
  }
11034
- if (_optionalChain([plan, 'optionalAccess', _547 => _547.kind]) === "budget") {
11506
+ if (_optionalChain([plan, 'optionalAccess', _593 => _593.kind]) === "budget") {
11035
11507
  return {
11036
11508
  includeThoughts: plan.enabled,
11037
11509
  thinkingBudget: plan.budgetTokens
@@ -11127,7 +11599,7 @@ async function callAnthropicCompletion(provider, apiKey, options, logger) {
11127
11599
  message: {
11128
11600
  id: `assistant-${Date.now()}`,
11129
11601
  role: "assistant",
11130
- content: _optionalChain([choice2, 'access', _548 => _548.message, 'optionalAccess', _549 => _549.content]) || "",
11602
+ content: _optionalChain([choice2, 'access', _594 => _594.message, 'optionalAccess', _595 => _595.content]) || "",
11131
11603
  timestamp: Date.now()
11132
11604
  },
11133
11605
  usage: openaiResponse2.usage ? {
@@ -11244,7 +11716,7 @@ async function callGeminiCompletion(provider, apiKey, options, logger) {
11244
11716
  const candidate = candidates[0];
11245
11717
  const content = candidate.content;
11246
11718
  let textContent = "";
11247
- if (_optionalChain([content, 'optionalAccess', _550 => _550.parts])) {
11719
+ if (_optionalChain([content, 'optionalAccess', _596 => _596.parts])) {
11248
11720
  for (const part of content.parts) {
11249
11721
  if (part.text) {
11250
11722
  textContent += part.text;
@@ -11372,7 +11844,7 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
11372
11844
  });
11373
11845
  if (!response.ok) {
11374
11846
  const errorText = await response.text();
11375
- _optionalChain([callbacks, 'access', _551 => _551.onError, 'optionalCall', _552 => _552(`API error (${response.status}): ${errorText}`)]);
11847
+ _optionalChain([callbacks, 'access', _597 => _597.onError, 'optionalCall', _598 => _598(`API error (${response.status}): ${errorText}`)]);
11376
11848
  return;
11377
11849
  }
11378
11850
  const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "openai", {
@@ -11382,7 +11854,7 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
11382
11854
  onVideo: callbacks.onVideo,
11383
11855
  onError: callbacks.onError
11384
11856
  });
11385
- _optionalChain([callbacks, 'access', _553 => _553.onDone, 'optionalCall', _554 => _554(
11857
+ _optionalChain([callbacks, 'access', _599 => _599.onDone, 'optionalCall', _600 => _600(
11386
11858
  {
11387
11859
  id: messageId,
11388
11860
  role: "assistant",
@@ -11457,7 +11929,7 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
11457
11929
  logger.info("Streaming Anthropic completion request", {
11458
11930
  url: apiUrl,
11459
11931
  model: anthropicRequest.model,
11460
- messagesCount: _optionalChain([anthropicRequest, 'access', _555 => _555.messages, 'optionalAccess', _556 => _556.length]),
11932
+ messagesCount: _optionalChain([anthropicRequest, 'access', _601 => _601.messages, 'optionalAccess', _602 => _602.length]),
11461
11933
  max_tokens: anthropicRequest.max_tokens,
11462
11934
  temperature: anthropicRequest.temperature,
11463
11935
  stream: anthropicRequest.stream,
@@ -11474,7 +11946,7 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
11474
11946
  if (!response.ok) {
11475
11947
  const errorText = await response.text();
11476
11948
  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}`)]);
11949
+ _optionalChain([callbacks, 'access', _603 => _603.onError, 'optionalCall', _604 => _604(`API error (${response.status}): ${errorText}`)]);
11478
11950
  return;
11479
11951
  }
11480
11952
  const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "anthropic", {
@@ -11485,10 +11957,10 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
11485
11957
  });
11486
11958
  logger.info("Anthropic stream complete", {
11487
11959
  contentLength: result.content.length,
11488
- reasoningLength: _optionalChain([result, 'access', _559 => _559.reasoning, 'optionalAccess', _560 => _560.length]) || 0,
11960
+ reasoningLength: _optionalChain([result, 'access', _605 => _605.reasoning, 'optionalAccess', _606 => _606.length]) || 0,
11489
11961
  blocksCount: result.blocks.length
11490
11962
  });
11491
- _optionalChain([callbacks, 'access', _561 => _561.onDone, 'optionalCall', _562 => _562(
11963
+ _optionalChain([callbacks, 'access', _607 => _607.onDone, 'optionalCall', _608 => _608(
11492
11964
  {
11493
11965
  id: messageId,
11494
11966
  role: "assistant",
@@ -11546,7 +12018,7 @@ async function streamGeminiCompletion(provider, apiKey, options, messageId, call
11546
12018
  if (!response.ok) {
11547
12019
  const errorText = await response.text();
11548
12020
  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}`)]);
12021
+ _optionalChain([callbacks, 'access', _609 => _609.onError, 'optionalCall', _610 => _610(`API error (${response.status}): ${errorText}`)]);
11550
12022
  return;
11551
12023
  }
11552
12024
  const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "gemini", {
@@ -11555,7 +12027,7 @@ async function streamGeminiCompletion(provider, apiKey, options, messageId, call
11555
12027
  onError: callbacks.onError
11556
12028
  });
11557
12029
  logger.info("Gemini stream complete", { contentLength: result.content.length });
11558
- _optionalChain([callbacks, 'access', _565 => _565.onDone, 'optionalCall', _566 => _566(
12030
+ _optionalChain([callbacks, 'access', _611 => _611.onDone, 'optionalCall', _612 => _612(
11559
12031
  {
11560
12032
  id: messageId,
11561
12033
  role: "assistant",
@@ -11605,7 +12077,7 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
11605
12077
  });
11606
12078
  if (!response.ok) {
11607
12079
  const errorText = await response.text();
11608
- _optionalChain([callbacks, 'access', _567 => _567.onError, 'optionalCall', _568 => _568(`API error (${response.status}): ${errorText}`)]);
12080
+ _optionalChain([callbacks, 'access', _613 => _613.onError, 'optionalCall', _614 => _614(`API error (${response.status}): ${errorText}`)]);
11609
12081
  return;
11610
12082
  }
11611
12083
  const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "openai-response", {
@@ -11614,7 +12086,7 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
11614
12086
  onError: callbacks.onError
11615
12087
  });
11616
12088
  logger.info("OpenAI Response API stream complete", { contentLength: result.content.length });
11617
- _optionalChain([callbacks, 'access', _569 => _569.onDone, 'optionalCall', _570 => _570(
12089
+ _optionalChain([callbacks, 'access', _615 => _615.onDone, 'optionalCall', _616 => _616(
11618
12090
  {
11619
12091
  id: messageId,
11620
12092
  role: "assistant",
@@ -11642,7 +12114,7 @@ async function resolveEffectiveMaxTokens(llmConfig, _getProvider, logger, _provi
11642
12114
  }
11643
12115
  try {
11644
12116
  const globalParams = await llmConfig.getGlobalModelParameters();
11645
- if (_optionalChain([globalParams, 'optionalAccess', _571 => _571.maxTokens, 'optionalAccess', _572 => _572.enabled]) && globalParams.maxTokens.value > 0) {
12117
+ if (_optionalChain([globalParams, 'optionalAccess', _617 => _617.maxTokens, 'optionalAccess', _618 => _618.enabled]) && globalParams.maxTokens.value > 0) {
11646
12118
  logger.debug("Using global maxTokens", { maxTokens: globalParams.maxTokens.value });
11647
12119
  return globalParams.maxTokens.value;
11648
12120
  }
@@ -11670,7 +12142,7 @@ async function resolveThinkingBudget(getProvider, logger, providerId, modelId, m
11670
12142
  }
11671
12143
  const thinkingBudget = _thinkingconfig.calculateThinkingBudget.call(void 0, modelId, thinkLevel, maxTokens);
11672
12144
  const provider = await getProvider(providerId);
11673
- const providerName = _optionalChain([provider, 'optionalAccess', _573 => _573.name, 'optionalAccess', _574 => _574.toLowerCase, 'call', _575 => _575()]) || "";
12145
+ const providerName = _optionalChain([provider, 'optionalAccess', _619 => _619.name, 'optionalAccess', _620 => _620.toLowerCase, 'call', _621 => _621()]) || "";
11674
12146
  const apiFormat = provider ? _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider) : "openai";
11675
12147
  if (apiFormat === "anthropic" || providerName === "anthropic" || providerName.includes("claude")) {
11676
12148
  const thinkingConfig = _thinkingconfig.buildAnthropicThinking.call(void 0, modelId, thinkLevel, maxTokens);
@@ -11707,7 +12179,7 @@ function logToolFormat(tools, logger) {
11707
12179
  tools: openaiTools.map((t) => t.function.name),
11708
12180
  firstTool: {
11709
12181
  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)]),
12182
+ description: _optionalChain([firstTool, 'access', _622 => _622.function, 'access', _623 => _623.description, 'optionalAccess', _624 => _624.slice, 'call', _625 => _625(0, 100)]),
11711
12183
  parameters: firstTool.function.parameters
11712
12184
  }
11713
12185
  });
@@ -11718,7 +12190,7 @@ function logToolFormat(tools, logger) {
11718
12190
  tools: anthropicTools.map((t) => t.name),
11719
12191
  firstTool: {
11720
12192
  name: firstTool.name,
11721
- description: _optionalChain([firstTool, 'access', _580 => _580.description, 'optionalAccess', _581 => _581.slice, 'call', _582 => _582(0, 100)]),
12193
+ description: _optionalChain([firstTool, 'access', _626 => _626.description, 'optionalAccess', _627 => _627.slice, 'call', _628 => _628(0, 100)]),
11722
12194
  input_schema: firstTool.input_schema
11723
12195
  }
11724
12196
  });
@@ -11729,9 +12201,9 @@ function logToolFormat(tools, logger) {
11729
12201
  count: allDeclarations.length,
11730
12202
  tools: allDeclarations.map((t) => t.name),
11731
12203
  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])
12204
+ name: _optionalChain([allDeclarations, 'access', _629 => _629[0], 'optionalAccess', _630 => _630.name]),
12205
+ description: _optionalChain([allDeclarations, 'access', _631 => _631[0], 'optionalAccess', _632 => _632.description, 'optionalAccess', _633 => _633.slice, 'call', _634 => _634(0, 100)]),
12206
+ parameters: _optionalChain([allDeclarations, 'access', _635 => _635[0], 'optionalAccess', _636 => _636.parameters])
11735
12207
  }
11736
12208
  });
11737
12209
  }
@@ -11794,7 +12266,7 @@ function buildToolRequest(apiFormat, conversationMessages, actualModel, options,
11794
12266
  function extractDeltaContent(rawJson, apiFormat) {
11795
12267
  const json = rawJson;
11796
12268
  if (apiFormat === "google") {
11797
- const parts = _optionalChain([json, 'access', _591 => _591.candidates, 'optionalAccess', _592 => _592[0], 'optionalAccess', _593 => _593.content, 'optionalAccess', _594 => _594.parts]) || [];
12269
+ const parts = _optionalChain([json, 'access', _637 => _637.candidates, 'optionalAccess', _638 => _638[0], 'optionalAccess', _639 => _639.content, 'optionalAccess', _640 => _640.parts]) || [];
11798
12270
  let text = "";
11799
12271
  for (const part of parts) {
11800
12272
  if (part.thought === true) continue;
@@ -11802,15 +12274,15 @@ function extractDeltaContent(rawJson, apiFormat) {
11802
12274
  }
11803
12275
  return text;
11804
12276
  } else if (apiFormat === "anthropic") {
11805
- return _optionalChain([json, 'access', _595 => _595.delta, 'optionalAccess', _596 => _596.text]) || "";
12277
+ return _optionalChain([json, 'access', _641 => _641.delta, 'optionalAccess', _642 => _642.text]) || "";
11806
12278
  } else {
11807
- return _optionalChain([json, 'access', _597 => _597.choices, 'optionalAccess', _598 => _598[0], 'optionalAccess', _599 => _599.delta, 'optionalAccess', _600 => _600.content]) || "";
12279
+ return _optionalChain([json, 'access', _643 => _643.choices, 'optionalAccess', _644 => _644[0], 'optionalAccess', _645 => _645.delta, 'optionalAccess', _646 => _646.content]) || "";
11808
12280
  }
11809
12281
  }
11810
12282
  function extractDeltaReasoning(rawJson, apiFormat) {
11811
12283
  const json = rawJson;
11812
12284
  if (apiFormat === "google") {
11813
- const parts = _optionalChain([json, 'access', _601 => _601.candidates, 'optionalAccess', _602 => _602[0], 'optionalAccess', _603 => _603.content, 'optionalAccess', _604 => _604.parts]) || [];
12285
+ const parts = _optionalChain([json, 'access', _647 => _647.candidates, 'optionalAccess', _648 => _648[0], 'optionalAccess', _649 => _649.content, 'optionalAccess', _650 => _650.parts]) || [];
11814
12286
  let reasoning = "";
11815
12287
  for (const part of parts) {
11816
12288
  if (part.thought === true && part.text) reasoning += part.text;
@@ -11819,14 +12291,14 @@ function extractDeltaReasoning(rawJson, apiFormat) {
11819
12291
  } else if (apiFormat === "anthropic") {
11820
12292
  return "";
11821
12293
  } 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]) || "");
12294
+ const delta = _optionalChain([json, 'access', _651 => _651.choices, 'optionalAccess', _652 => _652[0], 'optionalAccess', _653 => _653.delta]);
12295
+ return (_optionalChain([delta, 'optionalAccess', _654 => _654.thinking, 'optionalAccess', _655 => _655.content]) || "") + (_optionalChain([delta, 'optionalAccess', _656 => _656.reasoning_content]) || "");
11824
12296
  }
11825
12297
  }
11826
12298
  function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pendingOpenAIToolCalls) {
11827
12299
  const json = rawJson;
11828
12300
  if (apiFormat === "google") {
11829
- const parts = _optionalChain([json, 'access', _611 => _611.candidates, 'optionalAccess', _612 => _612[0], 'optionalAccess', _613 => _613.content, 'optionalAccess', _614 => _614.parts]) || [];
12301
+ const parts = _optionalChain([json, 'access', _657 => _657.candidates, 'optionalAccess', _658 => _658[0], 'optionalAccess', _659 => _659.content, 'optionalAccess', _660 => _660.parts]) || [];
11830
12302
  for (const part of parts) {
11831
12303
  if (part.functionCall) {
11832
12304
  logger.info("Function call detected", { functionCall: part.functionCall });
@@ -11836,13 +12308,13 @@ function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pend
11836
12308
  args: part.functionCall.args || {}
11837
12309
  };
11838
12310
  toolCalls.push(toolCall);
11839
- _optionalChain([callbacks, 'access', _615 => _615.onToolCall, 'optionalCall', _616 => _616(toolCall)]);
12311
+ _optionalChain([callbacks, 'access', _661 => _661.onToolCall, 'optionalCall', _662 => _662(toolCall)]);
11840
12312
  logger.info("Tool called", { toolName: toolCall.name });
11841
12313
  }
11842
12314
  }
11843
12315
  } 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) {
12316
+ const delta = _optionalChain([json, 'access', _663 => _663.choices, 'optionalAccess', _664 => _664[0], 'optionalAccess', _665 => _665.delta]);
12317
+ if (_optionalChain([delta, 'optionalAccess', _666 => _666.tool_calls]) && pendingOpenAIToolCalls) {
11846
12318
  for (const tc of delta.tool_calls) {
11847
12319
  const index = _nullishCoalesce(tc.index, () => ( 0));
11848
12320
  let pending = pendingOpenAIToolCalls.get(index);
@@ -11851,8 +12323,8 @@ function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pend
11851
12323
  pendingOpenAIToolCalls.set(index, pending);
11852
12324
  }
11853
12325
  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;
12326
+ if (_optionalChain([tc, 'access', _667 => _667.function, 'optionalAccess', _668 => _668.name])) pending.name += tc.function.name;
12327
+ if (_optionalChain([tc, 'access', _669 => _669.function, 'optionalAccess', _670 => _670.arguments])) pending.arguments += tc.function.arguments;
11856
12328
  }
11857
12329
  }
11858
12330
  }
@@ -11867,7 +12339,7 @@ function finalizeOpenAIToolCalls(pendingOpenAIToolCalls, toolCalls, callbacks, l
11867
12339
  args: JSON.parse(pending.arguments || "{}")
11868
12340
  };
11869
12341
  toolCalls.push(toolCall);
11870
- _optionalChain([callbacks, 'access', _625 => _625.onToolCall, 'optionalCall', _626 => _626(toolCall)]);
12342
+ _optionalChain([callbacks, 'access', _671 => _671.onToolCall, 'optionalCall', _672 => _672(toolCall)]);
11871
12343
  logger.info("Tool called (OpenAI)", { toolName: toolCall.name, args: toolCall.args });
11872
12344
  } catch (e) {
11873
12345
  logger.error("Failed to parse OpenAI tool call arguments", e instanceof Error ? e : void 0, {
@@ -11881,38 +12353,38 @@ function finalizeOpenAIToolCalls(pendingOpenAIToolCalls, toolCalls, callbacks, l
11881
12353
  function parseStreamChunk(rawJson, apiFormat, callbacks, logger) {
11882
12354
  const json = rawJson;
11883
12355
  if (apiFormat === "google") {
11884
- const candidate = _optionalChain([json, 'access', _627 => _627.candidates, 'optionalAccess', _628 => _628[0]]);
12356
+ const candidate = _optionalChain([json, 'access', _673 => _673.candidates, 'optionalAccess', _674 => _674[0]]);
11885
12357
  if (!candidate) {
11886
12358
  logger.warn("No candidate found in Gemini response");
11887
12359
  return;
11888
12360
  }
11889
- const parts = _optionalChain([candidate, 'access', _629 => _629.content, 'optionalAccess', _630 => _630.parts]) || [];
12361
+ const parts = _optionalChain([candidate, 'access', _675 => _675.content, 'optionalAccess', _676 => _676.parts]) || [];
11890
12362
  for (const part of parts) {
11891
12363
  if (part.thought === true && part.text) {
11892
- _optionalChain([callbacks, 'access', _631 => _631.onReasoning, 'optionalCall', _632 => _632(part.text)]);
12364
+ _optionalChain([callbacks, 'access', _677 => _677.onReasoning, 'optionalCall', _678 => _678(part.text)]);
11893
12365
  continue;
11894
12366
  } else if (part.thoughtSignature && !part.thought) {
11895
12367
  logger.debug("Gemini returned thoughtSignature without thought content");
11896
12368
  }
11897
12369
  if (part.text) {
11898
- _optionalChain([callbacks, 'access', _633 => _633.onDelta, 'optionalCall', _634 => _634(part.text)]);
12370
+ _optionalChain([callbacks, 'access', _679 => _679.onDelta, 'optionalCall', _680 => _680(part.text)]);
11899
12371
  }
11900
12372
  }
11901
12373
  } else if (apiFormat === "anthropic") {
11902
12374
  const delta = json.delta;
11903
- if (_optionalChain([delta, 'optionalAccess', _635 => _635.text])) {
11904
- _optionalChain([callbacks, 'access', _636 => _636.onDelta, 'optionalCall', _637 => _637(delta.text)]);
12375
+ if (_optionalChain([delta, 'optionalAccess', _681 => _681.text])) {
12376
+ _optionalChain([callbacks, 'access', _682 => _682.onDelta, 'optionalCall', _683 => _683(delta.text)]);
11905
12377
  }
11906
12378
  } 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)]);
12379
+ const delta = _optionalChain([json, 'access', _684 => _684.choices, 'optionalAccess', _685 => _685[0], 'optionalAccess', _686 => _686.delta]);
12380
+ if (_optionalChain([delta, 'optionalAccess', _687 => _687.content])) {
12381
+ _optionalChain([callbacks, 'access', _688 => _688.onDelta, 'optionalCall', _689 => _689(delta.content)]);
11910
12382
  }
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)]);
12383
+ if (_optionalChain([delta, 'optionalAccess', _690 => _690.thinking, 'optionalAccess', _691 => _691.content])) {
12384
+ _optionalChain([callbacks, 'access', _692 => _692.onReasoning, 'optionalCall', _693 => _693(delta.thinking.content)]);
11913
12385
  }
11914
- if (_optionalChain([delta, 'optionalAccess', _648 => _648.reasoning_content])) {
11915
- _optionalChain([callbacks, 'access', _649 => _649.onReasoning, 'optionalCall', _650 => _650(delta.reasoning_content)]);
12386
+ if (_optionalChain([delta, 'optionalAccess', _694 => _694.reasoning_content])) {
12387
+ _optionalChain([callbacks, 'access', _695 => _695.onReasoning, 'optionalCall', _696 => _696(delta.reasoning_content)]);
11916
12388
  }
11917
12389
  }
11918
12390
  }
@@ -11925,7 +12397,7 @@ function buildIterationBlocks(iteration, content, reasoning, blocks, callbacks)
11925
12397
  content: reasoning
11926
12398
  };
11927
12399
  blocks.push(thinkingBlock);
11928
- _optionalChain([callbacks, 'access', _651 => _651.onBlock, 'optionalCall', _652 => _652(thinkingBlock)]);
12400
+ _optionalChain([callbacks, 'access', _697 => _697.onBlock, 'optionalCall', _698 => _698(thinkingBlock)]);
11929
12401
  }
11930
12402
  if (content && content.trim()) {
11931
12403
  const textBlock = {
@@ -11934,7 +12406,7 @@ function buildIterationBlocks(iteration, content, reasoning, blocks, callbacks)
11934
12406
  content
11935
12407
  };
11936
12408
  blocks.push(textBlock);
11937
- _optionalChain([callbacks, 'access', _653 => _653.onBlock, 'optionalCall', _654 => _654(textBlock)]);
12409
+ _optionalChain([callbacks, 'access', _699 => _699.onBlock, 'optionalCall', _700 => _700(textBlock)]);
11938
12410
  }
11939
12411
  }
11940
12412
  async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbacks, logger, builtinExecutor) {
@@ -11949,7 +12421,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
11949
12421
  status: "running"
11950
12422
  };
11951
12423
  blocks.push(toolUseBlock);
11952
- _optionalChain([callbacks, 'access', _655 => _655.onBlock, 'optionalCall', _656 => _656(toolUseBlock)]);
12424
+ _optionalChain([callbacks, 'access', _701 => _701.onBlock, 'optionalCall', _702 => _702(toolUseBlock)]);
11953
12425
  try {
11954
12426
  logger.info("Executing tool", { toolName: toolCall.name });
11955
12427
  const mcpTool = mcpTools.find((t) => t.id === toolCall.name);
@@ -11972,8 +12444,8 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
11972
12444
  result = { isError: true, content: [{ type: "text", text: "MCP service not available" }] };
11973
12445
  }
11974
12446
  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);
12447
+ _optionalChain([callbacks, 'access', _703 => _703.onToolResult, 'optionalCall', _704 => _704(toolCall.id, result)]);
12448
+ const resultText = _optionalChain([result, 'access', _705 => _705.content, 'optionalAccess', _706 => _706[0], 'optionalAccess', _707 => _707.text]) || JSON.stringify(result);
11977
12449
  const toolResultBlock = {
11978
12450
  id: `${toolCall.id}_result`,
11979
12451
  type: "tool_result",
@@ -11983,11 +12455,11 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
11983
12455
  isError: result.isError
11984
12456
  };
11985
12457
  blocks.push(toolResultBlock);
11986
- _optionalChain([callbacks, 'access', _662 => _662.onBlock, 'optionalCall', _663 => _663(toolResultBlock)]);
12458
+ _optionalChain([callbacks, 'access', _708 => _708.onBlock, 'optionalCall', _709 => _709(toolResultBlock)]);
11987
12459
  const toolUseBlockRef = blocks.find((b) => b.id === `${toolCall.id}_use`);
11988
12460
  if (toolUseBlockRef && toolUseBlockRef.type === "tool_use") {
11989
12461
  toolUseBlockRef.status = result.isError ? "error" : "completed";
11990
- _optionalChain([callbacks, 'access', _664 => _664.onBlock, 'optionalCall', _665 => _665({ ...toolUseBlockRef })]);
12462
+ _optionalChain([callbacks, 'access', _710 => _710.onBlock, 'optionalCall', _711 => _711({ ...toolUseBlockRef })]);
11991
12463
  }
11992
12464
  toolResults.push({ toolCall, result });
11993
12465
  } catch (error) {
@@ -11997,7 +12469,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
11997
12469
  isError: true,
11998
12470
  content: [{ type: "text", text: `Error: ${errorMessage}` }]
11999
12471
  };
12000
- _optionalChain([callbacks, 'access', _666 => _666.onToolResult, 'optionalCall', _667 => _667(toolCall.id, errorResult)]);
12472
+ _optionalChain([callbacks, 'access', _712 => _712.onToolResult, 'optionalCall', _713 => _713(toolCall.id, errorResult)]);
12001
12473
  const errorToolResultBlock = {
12002
12474
  id: `${toolCall.id}_result`,
12003
12475
  type: "tool_result",
@@ -12007,11 +12479,11 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
12007
12479
  isError: true
12008
12480
  };
12009
12481
  blocks.push(errorToolResultBlock);
12010
- _optionalChain([callbacks, 'access', _668 => _668.onBlock, 'optionalCall', _669 => _669(errorToolResultBlock)]);
12482
+ _optionalChain([callbacks, 'access', _714 => _714.onBlock, 'optionalCall', _715 => _715(errorToolResultBlock)]);
12011
12483
  const errorToolUseBlockRef = blocks.find((b) => b.id === `${toolCall.id}_use`);
12012
12484
  if (errorToolUseBlockRef && errorToolUseBlockRef.type === "tool_use") {
12013
12485
  errorToolUseBlockRef.status = "error";
12014
- _optionalChain([callbacks, 'access', _670 => _670.onBlock, 'optionalCall', _671 => _671({ ...errorToolUseBlockRef })]);
12486
+ _optionalChain([callbacks, 'access', _716 => _716.onBlock, 'optionalCall', _717 => _717({ ...errorToolUseBlockRef })]);
12015
12487
  }
12016
12488
  toolResults.push({ toolCall, result: errorResult });
12017
12489
  }
@@ -12021,7 +12493,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
12021
12493
  function mapToolArguments(args, mcpTool, logger) {
12022
12494
  const mappedArgs = { ...args };
12023
12495
  const toolSchema = mcpTool.inputSchema;
12024
- if (_optionalChain([toolSchema, 'optionalAccess', _672 => _672.properties])) {
12496
+ if (_optionalChain([toolSchema, 'optionalAccess', _718 => _718.properties])) {
12025
12497
  const expectedParams = Object.keys(toolSchema.properties);
12026
12498
  const paramMappings = {
12027
12499
  "search_query": ["query", "q", "searchQuery", "search"],
@@ -12055,25 +12527,25 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
12055
12527
  options.providerId,
12056
12528
  options.model
12057
12529
  );
12058
- const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _673 => _673.actualProviderId]) || options.providerId;
12059
- const actualModel = _optionalChain([routedInfo, 'optionalAccess', _674 => _674.actualModelId]) || options.model;
12530
+ const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _719 => _719.actualProviderId]) || options.providerId;
12531
+ const actualModel = _optionalChain([routedInfo, 'optionalAccess', _720 => _720.actualModelId]) || options.model;
12060
12532
  const provider = await getProvider(actualProviderId);
12061
12533
  if (!provider) {
12062
- _optionalChain([callbacks, 'access', _675 => _675.onError, 'optionalCall', _676 => _676(`Provider not found: ${actualProviderId}`)]);
12534
+ _optionalChain([callbacks, 'access', _721 => _721.onError, 'optionalCall', _722 => _722(`Provider not found: ${actualProviderId}`)]);
12063
12535
  return;
12064
12536
  }
12065
12537
  if (!provider.enabled) {
12066
- _optionalChain([callbacks, 'access', _677 => _677.onError, 'optionalCall', _678 => _678(`Provider is disabled: ${provider.name}`)]);
12538
+ _optionalChain([callbacks, 'access', _723 => _723.onError, 'optionalCall', _724 => _724(`Provider is disabled: ${provider.name}`)]);
12067
12539
  return;
12068
12540
  }
12069
12541
  const { apiKey: effectiveKey } = _chunkA2YMUCBTcjs.resolveProviderEndpoint.call(void 0, provider);
12070
12542
  const apiKey = resolveApiKey2(effectiveKey);
12071
12543
  if (!apiKey) {
12072
- _optionalChain([callbacks, 'access', _679 => _679.onError, 'optionalCall', _680 => _680("API key not configured")]);
12544
+ _optionalChain([callbacks, 'access', _725 => _725.onError, 'optionalCall', _726 => _726("API key not configured")]);
12073
12545
  return;
12074
12546
  }
12075
12547
  const messageId = `msg_${Date.now()}_${Math.random().toString(36).slice(2)}`;
12076
- _optionalChain([callbacks, 'access', _681 => _681.onStart, 'optionalCall', _682 => _682(messageId)]);
12548
+ _optionalChain([callbacks, 'access', _727 => _727.onStart, 'optionalCall', _728 => _728(messageId)]);
12077
12549
  const globalParams = await llmConfig.getGlobalModelParameters();
12078
12550
  const MAX_ITERATIONS = _nullishCoalesce(globalParams.toolMaxTurns, () => ( 100));
12079
12551
  let iteration = 0;
@@ -12120,12 +12592,12 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
12120
12592
  });
12121
12593
  if (!response.ok) {
12122
12594
  const errorText = await response.text();
12123
- _optionalChain([callbacks, 'access', _683 => _683.onError, 'optionalCall', _684 => _684(`API error (${response.status}): ${errorText}`)]);
12595
+ _optionalChain([callbacks, 'access', _729 => _729.onError, 'optionalCall', _730 => _730(`API error (${response.status}): ${errorText}`)]);
12124
12596
  return;
12125
12597
  }
12126
- const reader = _optionalChain([response, 'access', _685 => _685.body, 'optionalAccess', _686 => _686.getReader, 'call', _687 => _687()]);
12598
+ const reader = _optionalChain([response, 'access', _731 => _731.body, 'optionalAccess', _732 => _732.getReader, 'call', _733 => _733()]);
12127
12599
  if (!reader) {
12128
- _optionalChain([callbacks, 'access', _688 => _688.onError, 'optionalCall', _689 => _689("No response body")]);
12600
+ _optionalChain([callbacks, 'access', _734 => _734.onError, 'optionalCall', _735 => _735("No response body")]);
12129
12601
  return;
12130
12602
  }
12131
12603
  const decoder = new TextDecoder();
@@ -12158,7 +12630,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
12158
12630
  logger.debug("Parsed JSON", { json });
12159
12631
  if (json.error) {
12160
12632
  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)}`)]);
12633
+ _optionalChain([callbacks, 'access', _736 => _736.onError, 'optionalCall', _737 => _737(`API Error: ${json.error.message || JSON.stringify(json.error)}`)]);
12162
12634
  return;
12163
12635
  }
12164
12636
  parseStreamChunk(json, apiFormat, callbacks, logger);
@@ -12191,7 +12663,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
12191
12663
  toolCallsLength: toolCalls.length,
12192
12664
  executableToolCallsLength: executableToolCalls.length,
12193
12665
  hasMcpTools: !!options.mcpTools,
12194
- mcpToolsLength: _optionalChain([options, 'access', _692 => _692.mcpTools, 'optionalAccess', _693 => _693.length]),
12666
+ mcpToolsLength: _optionalChain([options, 'access', _738 => _738.mcpTools, 'optionalAccess', _739 => _739.length]),
12195
12667
  hasMcpService: !!mcpService
12196
12668
  });
12197
12669
  if (executableToolCalls.length > 0 && options.mcpTools && (mcpService || builtinExecutor)) {
@@ -12212,7 +12684,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
12212
12684
  builtinExecutor
12213
12685
  );
12214
12686
  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);
12687
+ const resultText = typeof result === "string" ? result : _optionalChain([result, 'access', _740 => _740.content, 'optionalAccess', _741 => _741[0], 'optionalAccess', _742 => _742.text]) || JSON.stringify(result);
12216
12688
  return `Tool ${toolCall.name} result:
12217
12689
  ${resultText}`;
12218
12690
  }).join("\n\n");
@@ -12230,12 +12702,12 @@ ${resultText}`;
12230
12702
  }
12231
12703
  } catch (streamError) {
12232
12704
  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"}`)]);
12705
+ _optionalChain([callbacks, 'access', _743 => _743.onError, 'optionalCall', _744 => _744(`Stream error: ${streamError instanceof Error ? streamError.message : "Unknown error"}`)]);
12234
12706
  return;
12235
12707
  }
12236
12708
  }
12237
12709
  logger.info("Sending final callback", { blocksCount: blocks.length });
12238
- _optionalChain([callbacks, 'access', _699 => _699.onDone, 'optionalCall', _700 => _700({
12710
+ _optionalChain([callbacks, 'access', _745 => _745.onDone, 'optionalCall', _746 => _746({
12239
12711
  id: messageId,
12240
12712
  role: "assistant",
12241
12713
  content: finalContent,
@@ -12246,7 +12718,7 @@ ${resultText}`;
12246
12718
  } catch (error) {
12247
12719
  logger.error("Error in streamWithTools", error instanceof Error ? error : void 0);
12248
12720
  const message = error instanceof Error ? error.message : "Unknown error";
12249
- _optionalChain([callbacks, 'access', _701 => _701.onError, 'optionalCall', _702 => _702(message)]);
12721
+ _optionalChain([callbacks, 'access', _747 => _747.onError, 'optionalCall', _748 => _748(message)]);
12250
12722
  }
12251
12723
  }
12252
12724
 
@@ -12297,8 +12769,8 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
12297
12769
  options.providerId,
12298
12770
  options.model
12299
12771
  );
12300
- const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _703 => _703.actualProviderId]) || options.providerId;
12301
- const actualModel = _optionalChain([routedInfo, 'optionalAccess', _704 => _704.actualModelId]) || options.model;
12772
+ const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _749 => _749.actualProviderId]) || options.providerId;
12773
+ const actualModel = _optionalChain([routedInfo, 'optionalAccess', _750 => _750.actualModelId]) || options.model;
12302
12774
  const provider = await getProvider(actualProviderId);
12303
12775
  if (!provider) {
12304
12776
  return { success: false, error: `Provider not found: ${actualProviderId}` };
@@ -12375,18 +12847,18 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
12375
12847
  { endpointTransformer: void 0 }
12376
12848
  );
12377
12849
  const data = await transformedResponse2.json();
12378
- const choice = _optionalChain([data, 'access', _705 => _705.choices, 'optionalAccess', _706 => _706[0]]);
12850
+ const choice = _optionalChain([data, 'access', _751 => _751.choices, 'optionalAccess', _752 => _752[0]]);
12379
12851
  if (!choice) {
12380
12852
  return { success: false, error: "No choices in response" };
12381
12853
  }
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) => ({
12854
+ const rawToolCalls = _optionalChain([choice, 'access', _753 => _753.message, 'optionalAccess', _754 => _754.tool_calls]);
12855
+ const toolCalls = _optionalChain([rawToolCalls, 'optionalAccess', _755 => _755.map, 'call', _756 => _756((tc) => ({
12384
12856
  id: tc.id,
12385
12857
  name: tc.function.name,
12386
12858
  args: typeof tc.function.arguments === "string" ? JSON.parse(tc.function.arguments) : tc.function.arguments
12387
12859
  }))]);
12388
12860
  const tapped = readUsageFromOpenAIResponse(data.usage);
12389
- if (_optionalChain([recording, 'optionalAccess', _711 => _711.recorder]) && tapped) {
12861
+ if (_optionalChain([recording, 'optionalAccess', _757 => _757.recorder]) && tapped) {
12390
12862
  recording.recorder.record({
12391
12863
  messageId: _nullishCoalesce(options.messageId, () => ( null)),
12392
12864
  parentMessageId: _nullishCoalesce(options.parentMessageId, () => ( null)),
@@ -12404,9 +12876,9 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
12404
12876
  message: {
12405
12877
  id: `msg_${Date.now()}`,
12406
12878
  role: "assistant",
12407
- content: _optionalChain([choice, 'access', _712 => _712.message, 'optionalAccess', _713 => _713.content]) || "",
12879
+ content: _optionalChain([choice, 'access', _758 => _758.message, 'optionalAccess', _759 => _759.content]) || "",
12408
12880
  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,
12881
+ thinking: data.reasoning_content || _optionalChain([choice, 'access', _760 => _760.message, 'optionalAccess', _761 => _761.thinking, 'optionalAccess', _762 => _762.content]) ? { content: data.reasoning_content || _optionalChain([choice, 'access', _763 => _763.message, 'optionalAccess', _764 => _764.thinking, 'optionalAccess', _765 => _765.content]) || "", signature: _optionalChain([choice, 'access', _766 => _766.message, 'optionalAccess', _767 => _767.thinking, 'optionalAccess', _768 => _768.signature]) } : void 0,
12410
12882
  toolCalls
12411
12883
  },
12412
12884
  usage: data.usage ? {
@@ -12427,21 +12899,21 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
12427
12899
  options.providerId,
12428
12900
  options.model
12429
12901
  );
12430
- const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _723 => _723.actualProviderId]) || options.providerId;
12431
- const actualModel = _optionalChain([routedInfo, 'optionalAccess', _724 => _724.actualModelId]) || options.model;
12902
+ const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _769 => _769.actualProviderId]) || options.providerId;
12903
+ const actualModel = _optionalChain([routedInfo, 'optionalAccess', _770 => _770.actualModelId]) || options.model;
12432
12904
  const provider = await getProvider(actualProviderId);
12433
12905
  if (!provider) {
12434
- _optionalChain([callbacks, 'access', _725 => _725.onError, 'optionalCall', _726 => _726(`Provider not found: ${actualProviderId}`)]);
12906
+ _optionalChain([callbacks, 'access', _771 => _771.onError, 'optionalCall', _772 => _772(`Provider not found: ${actualProviderId}`)]);
12435
12907
  return;
12436
12908
  }
12437
12909
  if (!provider.enabled) {
12438
- _optionalChain([callbacks, 'access', _727 => _727.onError, 'optionalCall', _728 => _728(`Provider is disabled: ${provider.name}`)]);
12910
+ _optionalChain([callbacks, 'access', _773 => _773.onError, 'optionalCall', _774 => _774(`Provider is disabled: ${provider.name}`)]);
12439
12911
  return;
12440
12912
  }
12441
12913
  const { apiKey: effectiveKey } = _chunkA2YMUCBTcjs.resolveProviderEndpoint.call(void 0, provider);
12442
12914
  const apiKey = resolveApiKey2(effectiveKey);
12443
12915
  if (!apiKey) {
12444
- _optionalChain([callbacks, 'access', _729 => _729.onError, 'optionalCall', _730 => _730("API key not configured")]);
12916
+ _optionalChain([callbacks, 'access', _775 => _775.onError, 'optionalCall', _776 => _776("API key not configured")]);
12445
12917
  return;
12446
12918
  }
12447
12919
  const { chain, hasTransformers } = await resolveChainWithMain(
@@ -12453,7 +12925,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
12453
12925
  return completeStreamFallback(options, callbacks);
12454
12926
  }
12455
12927
  const messageId = `msg_${Date.now()}`;
12456
- _optionalChain([callbacks, 'access', _731 => _731.onStart, 'optionalCall', _732 => _732(messageId)]);
12928
+ _optionalChain([callbacks, 'access', _777 => _777.onStart, 'optionalCall', _778 => _778(messageId)]);
12457
12929
  const unifiedRequest = buildUnifiedCompletionRequest(actualModel, options, true);
12458
12930
  const transformerProvider = {
12459
12931
  name: provider.name,
@@ -12493,7 +12965,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
12493
12965
  });
12494
12966
  if (!response.ok) {
12495
12967
  const errorText = await response.text();
12496
- _optionalChain([callbacks, 'access', _733 => _733.onError, 'optionalCall', _734 => _734(`API error (${response.status}): ${errorText}`)]);
12968
+ _optionalChain([callbacks, 'access', _779 => _779.onError, 'optionalCall', _780 => _780(`API error (${response.status}): ${errorText}`)]);
12497
12969
  return;
12498
12970
  }
12499
12971
  const transformedResponse2 = await executor.executeResponseChain(
@@ -12503,9 +12975,9 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
12503
12975
  chain,
12504
12976
  { endpointTransformer: void 0 }
12505
12977
  );
12506
- const reader = _optionalChain([transformedResponse2, 'access', _735 => _735.body, 'optionalAccess', _736 => _736.getReader, 'call', _737 => _737()]);
12978
+ const reader = _optionalChain([transformedResponse2, 'access', _781 => _781.body, 'optionalAccess', _782 => _782.getReader, 'call', _783 => _783()]);
12507
12979
  if (!reader) {
12508
- _optionalChain([callbacks, 'access', _738 => _738.onError, 'optionalCall', _739 => _739("No response body")]);
12980
+ _optionalChain([callbacks, 'access', _784 => _784.onError, 'optionalCall', _785 => _785("No response body")]);
12509
12981
  return;
12510
12982
  }
12511
12983
  const decoder = new TextDecoder();
@@ -12523,22 +12995,22 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
12523
12995
  if (data === "[DONE]") continue;
12524
12996
  try {
12525
12997
  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])) {
12998
+ const delta = _optionalChain([json, 'access', _786 => _786.choices, 'optionalAccess', _787 => _787[0], 'optionalAccess', _788 => _788.delta]);
12999
+ if (_optionalChain([delta, 'optionalAccess', _789 => _789.content])) {
12528
13000
  content += delta.content;
12529
- _optionalChain([callbacks, 'access', _744 => _744.onDelta, 'optionalCall', _745 => _745(delta.content)]);
13001
+ _optionalChain([callbacks, 'access', _790 => _790.onDelta, 'optionalCall', _791 => _791(delta.content)]);
12530
13002
  }
12531
- if (_optionalChain([delta, 'optionalAccess', _746 => _746.thinking, 'optionalAccess', _747 => _747.content])) {
13003
+ if (_optionalChain([delta, 'optionalAccess', _792 => _792.thinking, 'optionalAccess', _793 => _793.content])) {
12532
13004
  reasoning += delta.thinking.content;
12533
- _optionalChain([callbacks, 'access', _748 => _748.onReasoning, 'optionalCall', _749 => _749(delta.thinking.content)]);
13005
+ _optionalChain([callbacks, 'access', _794 => _794.onReasoning, 'optionalCall', _795 => _795(delta.thinking.content)]);
12534
13006
  }
12535
- if (_optionalChain([delta, 'optionalAccess', _750 => _750.reasoning_content])) {
13007
+ if (_optionalChain([delta, 'optionalAccess', _796 => _796.reasoning_content])) {
12536
13008
  reasoning += delta.reasoning_content;
12537
- _optionalChain([callbacks, 'access', _751 => _751.onReasoning, 'optionalCall', _752 => _752(delta.reasoning_content)]);
13009
+ _optionalChain([callbacks, 'access', _797 => _797.onReasoning, 'optionalCall', _798 => _798(delta.reasoning_content)]);
12538
13010
  }
12539
13011
  if (json.usage) {
12540
13012
  const tapped = readUsageFromOpenAIResponse(json.usage);
12541
- if (_optionalChain([recording, 'optionalAccess', _753 => _753.recorder]) && tapped) {
13013
+ if (_optionalChain([recording, 'optionalAccess', _799 => _799.recorder]) && tapped) {
12542
13014
  recording.recorder.record({
12543
13015
  messageId: _nullishCoalesce(options.messageId, () => ( null)),
12544
13016
  parentMessageId: _nullishCoalesce(options.parentMessageId, () => ( null)),
@@ -12551,7 +13023,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
12551
13023
  rawUsage: json.usage
12552
13024
  });
12553
13025
  }
12554
- _optionalChain([callbacks, 'access', _754 => _754.onDone, 'optionalCall', _755 => _755(
13026
+ _optionalChain([callbacks, 'access', _800 => _800.onDone, 'optionalCall', _801 => _801(
12555
13027
  {
12556
13028
  id: messageId,
12557
13029
  role: "assistant",
@@ -12572,7 +13044,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
12572
13044
  }
12573
13045
  }
12574
13046
  }
12575
- _optionalChain([callbacks, 'access', _756 => _756.onDone, 'optionalCall', _757 => _757({
13047
+ _optionalChain([callbacks, 'access', _802 => _802.onDone, 'optionalCall', _803 => _803({
12576
13048
  id: messageId,
12577
13049
  role: "assistant",
12578
13050
  content,
@@ -12584,7 +13056,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
12584
13056
  }
12585
13057
  } catch (error) {
12586
13058
  const message = error instanceof Error ? error.message : "Unknown error";
12587
- _optionalChain([callbacks, 'access', _758 => _758.onError, 'optionalCall', _759 => _759(message)]);
13059
+ _optionalChain([callbacks, 'access', _804 => _804.onError, 'optionalCall', _805 => _805(message)]);
12588
13060
  }
12589
13061
  }
12590
13062
 
@@ -12651,8 +13123,8 @@ var CompletionService = (_class21 = class {
12651
13123
  options.providerId,
12652
13124
  options.model
12653
13125
  );
12654
- const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _760 => _760.actualProviderId]) || options.providerId;
12655
- const actualModel = _optionalChain([routedInfo, 'optionalAccess', _761 => _761.actualModelId]) || options.model;
13126
+ const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _806 => _806.actualProviderId]) || options.providerId;
13127
+ const actualModel = _optionalChain([routedInfo, 'optionalAccess', _807 => _807.actualModelId]) || options.model;
12656
13128
  const provider = await this.getProvider(actualProviderId);
12657
13129
  if (!provider) {
12658
13130
  return { success: false, error: `Provider not found: ${actualProviderId}` };
@@ -12685,7 +13157,7 @@ var CompletionService = (_class21 = class {
12685
13157
  this.apiKeyPool.reportSuccess(options.sessionId);
12686
13158
  }
12687
13159
  if (result.success && result.usage && options.sessionId) {
12688
- _optionalChain([this, 'access', _762 => _762.usageEventSink, 'optionalAccess', _763 => _763.emit, 'call', _764 => _764({
13160
+ _optionalChain([this, 'access', _808 => _808.usageEventSink, 'optionalAccess', _809 => _809.emit, 'call', _810 => _810({
12689
13161
  sessionId: options.sessionId,
12690
13162
  modelId: actualModel,
12691
13163
  usage: result.usage,
@@ -12714,8 +13186,8 @@ var CompletionService = (_class21 = class {
12714
13186
  options.model
12715
13187
  );
12716
13188
  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;
13189
+ const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _811 => _811.actualProviderId]) || options.providerId;
13190
+ const actualModel = _optionalChain([routedInfo, 'optionalAccess', _812 => _812.actualModelId]) || options.model;
12719
13191
  this.logger.debug("Resolved provider and model", { actualProviderId, actualModel });
12720
13192
  const provider = await this.getProvider(actualProviderId);
12721
13193
  this.logger.debug("Retrieved provider", provider ? {
@@ -12727,22 +13199,22 @@ var CompletionService = (_class21 = class {
12727
13199
  enabled: provider.enabled
12728
13200
  } : { error: "Provider not found" });
12729
13201
  if (!provider) {
12730
- _optionalChain([callbacks, 'access', _767 => _767.onError, 'optionalCall', _768 => _768(`Provider not found: ${actualProviderId}`)]);
13202
+ _optionalChain([callbacks, 'access', _813 => _813.onError, 'optionalCall', _814 => _814(`Provider not found: ${actualProviderId}`)]);
12731
13203
  return;
12732
13204
  }
12733
13205
  if (!provider.enabled) {
12734
- _optionalChain([callbacks, 'access', _769 => _769.onError, 'optionalCall', _770 => _770(`Provider is disabled: ${provider.name}`)]);
13206
+ _optionalChain([callbacks, 'access', _815 => _815.onError, 'optionalCall', _816 => _816(`Provider is disabled: ${provider.name}`)]);
12735
13207
  return;
12736
13208
  }
12737
13209
  const apiKey = await this.resolveApiKeyForRequest(provider, actualProviderId, options.sessionId);
12738
13210
  if (!apiKey) {
12739
- _optionalChain([callbacks, 'access', _771 => _771.onError, 'optionalCall', _772 => _772("API key not configured")]);
13211
+ _optionalChain([callbacks, 'access', _817 => _817.onError, 'optionalCall', _818 => _818("API key not configured")]);
12740
13212
  return;
12741
13213
  }
12742
13214
  const apiFormat = _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider);
12743
13215
  this.logger.info("Using API format for stream", { apiFormat });
12744
13216
  const messageId = `msg_${Date.now()}`;
12745
- _optionalChain([callbacks, 'access', _773 => _773.onStart, 'optionalCall', _774 => _774(messageId)]);
13217
+ _optionalChain([callbacks, 'access', _819 => _819.onStart, 'optionalCall', _820 => _820(messageId)]);
12746
13218
  const resolvedOptions = { ...options, model: actualModel };
12747
13219
  if (options.sessionId) {
12748
13220
  const sid = options.sessionId;
@@ -12751,14 +13223,14 @@ var CompletionService = (_class21 = class {
12751
13223
  ...callbacks,
12752
13224
  onDone: (message, usage, metrics) => {
12753
13225
  if (usage) {
12754
- _optionalChain([this, 'access', _775 => _775.usageEventSink, 'optionalAccess', _776 => _776.emit, 'call', _777 => _777({
13226
+ _optionalChain([this, 'access', _821 => _821.usageEventSink, 'optionalAccess', _822 => _822.emit, 'call', _823 => _823({
12755
13227
  sessionId: sid,
12756
13228
  modelId: actualModel,
12757
13229
  usage,
12758
13230
  engineOrigin: "completion"
12759
13231
  })]);
12760
13232
  }
12761
- _optionalChain([userOnDone, 'optionalCall', _778 => _778(message, usage, metrics)]);
13233
+ _optionalChain([userOnDone, 'optionalCall', _824 => _824(message, usage, metrics)]);
12762
13234
  }
12763
13235
  };
12764
13236
  }
@@ -12774,11 +13246,11 @@ var CompletionService = (_class21 = class {
12774
13246
  retryState.error = { status, message: error };
12775
13247
  return;
12776
13248
  }
12777
- _optionalChain([callbacks, 'access', _779 => _779.onError, 'optionalCall', _780 => _780(error)]);
13249
+ _optionalChain([callbacks, 'access', _825 => _825.onError, 'optionalCall', _826 => _826(error)]);
12778
13250
  },
12779
13251
  onDone: (message, usage, metrics) => {
12780
13252
  this.apiKeyPool.reportSuccess(options.sessionId);
12781
- _optionalChain([callbacks, 'access', _781 => _781.onDone, 'optionalCall', _782 => _782(message, usage, metrics)]);
13253
+ _optionalChain([callbacks, 'access', _827 => _827.onDone, 'optionalCall', _828 => _828(message, usage, metrics)]);
12782
13254
  }
12783
13255
  };
12784
13256
  await this.callStreamHandler(apiFormat, provider, apiKey, resolvedOptions, messageId, interceptCallbacks);
@@ -12799,7 +13271,7 @@ var CompletionService = (_class21 = class {
12799
13271
  // don't fire onStart again
12800
13272
  });
12801
13273
  } else {
12802
- _optionalChain([callbacks, 'access', _783 => _783.onError, 'optionalCall', _784 => _784(retryState.error.message)]);
13274
+ _optionalChain([callbacks, 'access', _829 => _829.onError, 'optionalCall', _830 => _830(retryState.error.message)]);
12803
13275
  }
12804
13276
  }
12805
13277
  } else {
@@ -12812,7 +13284,7 @@ var CompletionService = (_class21 = class {
12812
13284
  } catch (error) {
12813
13285
  const message = error instanceof Error ? error.message : "Unknown error";
12814
13286
  this.logger.error("Stream completion error", error instanceof Error ? error : void 0, { message });
12815
- _optionalChain([callbacks, 'access', _785 => _785.onError, 'optionalCall', _786 => _786(message)]);
13287
+ _optionalChain([callbacks, 'access', _831 => _831.onError, 'optionalCall', _832 => _832(message)]);
12816
13288
  }
12817
13289
  }
12818
13290
  /**
@@ -12852,7 +13324,7 @@ var CompletionService = (_class21 = class {
12852
13324
  return {
12853
13325
  success: true,
12854
13326
  message: "Connection successful",
12855
- response: _optionalChain([result, 'access', _787 => _787.message, 'optionalAccess', _788 => _788.content]) || "",
13327
+ response: _optionalChain([result, 'access', _833 => _833.message, 'optionalAccess', _834 => _834.content]) || "",
12856
13328
  model: modelId,
12857
13329
  durationMs
12858
13330
  };
@@ -12917,7 +13389,7 @@ ${description}`;
12917
13389
  * 3. Legacy single key from provider config
12918
13390
  */
12919
13391
  async resolveApiKeyForRequest(provider, providerId, sessionId) {
12920
- if (_optionalChain([provider, 'access', _789 => _789.codingPlan, 'optionalAccess', _790 => _790.enabled]) && provider.codingPlan.apiKey) {
13392
+ if (_optionalChain([provider, 'access', _835 => _835.codingPlan, 'optionalAccess', _836 => _836.enabled]) && provider.codingPlan.apiKey) {
12921
13393
  return this.resolveApiKey(provider.codingPlan.apiKey);
12922
13394
  }
12923
13395
  if (this.apiKeyPool) {
@@ -13227,4 +13699,6 @@ ${description}`;
13227
13699
 
13228
13700
 
13229
13701
 
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;
13702
+
13703
+
13704
+ 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.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;