@omnicross/core 0.4.5 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{CompletionService-BniP7j88.d.cts → CompletionService-BJu4AWVc.d.cts} +1 -1
- package/dist/{CompletionService-BqrKPwfA.d.ts → CompletionService-C4W2gBi_.d.ts} +1 -1
- package/dist/{ProviderProxy-Ckr6oTrE.d.ts → ProviderProxy-DxsNi3cO.d.ts} +1 -1
- package/dist/{ProviderProxy-Bz_nkOwq.d.cts → ProviderProxy-OuQPYW2I.d.cts} +1 -1
- package/dist/{chunk-24W3DVGI.js → chunk-5XG6FR5F.js} +1 -1
- package/dist/{chunk-WYUXJKMK.js → chunk-DRUT7H5H.js} +1 -1
- package/dist/{chunk-NCCEWVWY.cjs → chunk-DV7656NN.cjs} +571 -364
- package/dist/{chunk-57Y2EA2G.cjs → chunk-JGRNVH7C.cjs} +1 -1
- package/dist/{chunk-2DMOOZ4F.cjs → chunk-LWBXQXZ3.cjs} +1 -1
- package/dist/{chunk-7PIUVCKK.js → chunk-MZCJL3QU.js} +1 -1
- package/dist/{chunk-LVQOCIES.cjs → chunk-QLVRJ5FS.cjs} +2 -2
- package/dist/{chunk-L4L77G3X.js → chunk-TU4BB776.js} +221 -14
- package/dist/{chunk-ZMERU7D3.js → chunk-VXHN5IDL.js} +1 -1
- package/dist/{chunk-QWNUOR7F.cjs → chunk-ZTN2PVKO.cjs} +1 -1
- package/dist/completion/CompletionService.cjs +6 -6
- package/dist/completion/CompletionService.d.cts +2 -2
- package/dist/completion/CompletionService.d.ts +2 -2
- package/dist/completion/CompletionService.js +5 -5
- package/dist/completion.cjs +6 -6
- package/dist/completion.d.cts +2 -2
- package/dist/completion.d.ts +2 -2
- package/dist/completion.js +5 -5
- package/dist/image-generation.d.cts +4 -4
- package/dist/image-generation.d.ts +4 -4
- package/dist/index.cjs +6 -6
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +5 -5
- package/dist/openai-operation.d.cts +1 -1
- package/dist/openai-operation.d.ts +1 -1
- package/dist/outbound-api/routeResolver.cjs +2 -2
- package/dist/outbound-api/routeResolver.d.cts +5 -5
- package/dist/outbound-api/routeResolver.d.ts +5 -5
- package/dist/outbound-api/routeResolver.js +1 -1
- package/dist/outbound-api/subscriptionRegistryPort.d.cts +9 -1
- package/dist/outbound-api/subscriptionRegistryPort.d.ts +9 -1
- package/dist/outbound-api/types.d.cts +4 -4
- package/dist/outbound-api/types.d.ts +4 -4
- package/dist/outbound-api.cjs +6 -6
- package/dist/outbound-api.d.cts +6 -6
- package/dist/outbound-api.d.ts +6 -6
- package/dist/outbound-api.js +5 -5
- package/dist/pipeline/AccountAllowanceScheduling.d.cts +4 -4
- package/dist/pipeline/AccountAllowanceScheduling.d.ts +4 -4
- package/dist/pipeline/SubscriptionAuthSource.d.cts +11 -0
- package/dist/pipeline/SubscriptionAuthSource.d.ts +11 -0
- package/dist/ports.d.cts +4 -4
- package/dist/ports.d.ts +4 -4
- package/dist/provider-proxy/ProviderProxy.cjs +6 -6
- package/dist/provider-proxy/ProviderProxy.d.cts +2 -2
- package/dist/provider-proxy/ProviderProxy.d.ts +2 -2
- package/dist/provider-proxy/ProviderProxy.js +5 -5
- package/dist/provider-proxy/identity/openCodeGoHeaders.cjs +2 -2
- package/dist/provider-proxy/identity/openCodeGoHeaders.js +1 -1
- package/dist/provider-proxy/ingress/providerProxyShared.cjs +12 -6
- package/dist/provider-proxy/ingress/providerProxyShared.d.cts +36 -2
- package/dist/provider-proxy/ingress/providerProxyShared.d.ts +36 -2
- package/dist/provider-proxy/ingress/providerProxyShared.js +11 -5
- package/dist/provider-proxy/types.d.cts +1 -1
- package/dist/provider-proxy/types.d.ts +1 -1
- package/dist/provider-proxy.cjs +6 -6
- package/dist/provider-proxy.d.cts +6 -6
- package/dist/provider-proxy.d.ts +6 -6
- package/dist/provider-proxy.js +5 -5
- package/dist/{routeResolver-BdNJvTZP.d.cts → routeResolver-BQYMEXer.d.cts} +2 -2
- package/dist/{routeResolver-zVoCx9r3.d.ts → routeResolver-DTfyzaFb.d.ts} +2 -2
- package/dist/transformer/transformers/OpenAITransformer.cjs +2 -2
- package/dist/transformer/transformers/OpenAITransformer.js +1 -1
- package/dist/transformer/transformers.cjs +3 -3
- package/dist/transformer/transformers.js +2 -2
- package/dist/transformer.cjs +3 -3
- package/dist/transformer.js +2 -2
- package/dist/{types-Dt1bgHPg.d.cts → types-BpSkj2JA.d.cts} +3 -3
- package/dist/{types-BVwJQ9ZS.d.cts → types-BsZ1s_a_.d.cts} +1 -1
- package/dist/{types-By9Tg6-I.d.ts → types-Di8VH1c9.d.ts} +12 -0
- package/dist/{types-BSIJdsyl.d.cts → types-Dpr5IAaP.d.cts} +12 -0
- package/dist/{types-IRPv4i1Y.d.ts → types-EReErShW.d.ts} +3 -3
- package/dist/{types-VAHRysdP.d.ts → types-USaixzVP.d.ts} +1 -1
- package/package.json +2 -2
|
@@ -53,7 +53,7 @@ var _chunkRPII3E6Zcjs = require('./chunk-RPII3E6Z.cjs');
|
|
|
53
53
|
var _chunk6RPZADX3cjs = require('./chunk-6RPZADX3.cjs');
|
|
54
54
|
|
|
55
55
|
|
|
56
|
-
var
|
|
56
|
+
var _chunkLWBXQXZ3cjs = require('./chunk-LWBXQXZ3.cjs');
|
|
57
57
|
|
|
58
58
|
|
|
59
59
|
|
|
@@ -118,7 +118,7 @@ var _chunk4YINUUKQcjs = require('./chunk-4YINUUKQ.cjs');
|
|
|
118
118
|
|
|
119
119
|
|
|
120
120
|
|
|
121
|
-
var
|
|
121
|
+
var _chunkJGRNVH7Ccjs = require('./chunk-JGRNVH7C.cjs');
|
|
122
122
|
|
|
123
123
|
|
|
124
124
|
var _chunkQBZJ7P2Tcjs = require('./chunk-QBZJ7P2T.cjs');
|
|
@@ -897,6 +897,124 @@ async function aggregateAnthropicSseToJsonBody(response, rewriteModel, signal) {
|
|
|
897
897
|
if (rewriteModel) message["model"] = rewriteModel;
|
|
898
898
|
return JSON.stringify(message);
|
|
899
899
|
}
|
|
900
|
+
async function aggregateResponsesSseToJsonBody(response, rewriteModel, signal) {
|
|
901
|
+
const text = await readResponseTextWithSignal(response, signal);
|
|
902
|
+
let terminal = null;
|
|
903
|
+
for (const raw of text.split("\n")) {
|
|
904
|
+
const line = raw.trim();
|
|
905
|
+
if (!line.startsWith("data:")) continue;
|
|
906
|
+
const payload = line.slice(5).trim();
|
|
907
|
+
if (!payload || payload === "[DONE]") continue;
|
|
908
|
+
try {
|
|
909
|
+
const ev = JSON.parse(payload);
|
|
910
|
+
if (ev["type"] === "response.completed" || ev["type"] === "response.failed" || ev["type"] === "response.incomplete") {
|
|
911
|
+
const resp = ev["response"];
|
|
912
|
+
if (resp && typeof resp === "object") terminal = resp;
|
|
913
|
+
}
|
|
914
|
+
} catch (e11) {
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
if (!terminal) return null;
|
|
918
|
+
if (rewriteModel && typeof terminal["model"] === "string") terminal["model"] = rewriteModel;
|
|
919
|
+
return JSON.stringify(terminal);
|
|
920
|
+
}
|
|
921
|
+
async function aggregateOpenAIChatChunksToJsonBody(response, rewriteModel, signal) {
|
|
922
|
+
const text = await readResponseTextWithSignal(response, signal);
|
|
923
|
+
let id;
|
|
924
|
+
let created;
|
|
925
|
+
let model;
|
|
926
|
+
let content = "";
|
|
927
|
+
let reasoning = "";
|
|
928
|
+
let finishReason = null;
|
|
929
|
+
let usage;
|
|
930
|
+
const toolCalls = /* @__PURE__ */ new Map();
|
|
931
|
+
let sawChoice = false;
|
|
932
|
+
for (const raw of text.split("\n")) {
|
|
933
|
+
const line = raw.trim();
|
|
934
|
+
if (!line.startsWith("data:")) continue;
|
|
935
|
+
const payload = line.slice(5).trim();
|
|
936
|
+
if (!payload || payload === "[DONE]") continue;
|
|
937
|
+
let ev;
|
|
938
|
+
try {
|
|
939
|
+
ev = JSON.parse(payload);
|
|
940
|
+
} catch (e12) {
|
|
941
|
+
continue;
|
|
942
|
+
}
|
|
943
|
+
if (typeof ev["id"] === "string" && id === void 0) id = ev["id"];
|
|
944
|
+
if (typeof ev["created"] === "number" && created === void 0) created = ev["created"];
|
|
945
|
+
if (typeof ev["model"] === "string" && model === void 0) model = ev["model"];
|
|
946
|
+
if (ev["usage"] && typeof ev["usage"] === "object") {
|
|
947
|
+
usage = ev["usage"];
|
|
948
|
+
}
|
|
949
|
+
const choices = ev["choices"];
|
|
950
|
+
if (!Array.isArray(choices) || choices.length === 0) continue;
|
|
951
|
+
const choice = choices[0];
|
|
952
|
+
if (!choice || typeof choice !== "object") continue;
|
|
953
|
+
sawChoice = true;
|
|
954
|
+
if (typeof choice["finish_reason"] === "string") finishReason = choice["finish_reason"];
|
|
955
|
+
const delta = choice["delta"];
|
|
956
|
+
if (!delta || typeof delta !== "object") continue;
|
|
957
|
+
const d = delta;
|
|
958
|
+
if (typeof d["content"] === "string") content += d["content"];
|
|
959
|
+
if (typeof d["reasoning_content"] === "string") reasoning += d["reasoning_content"];
|
|
960
|
+
const thinking = d["thinking"];
|
|
961
|
+
if (thinking && typeof thinking === "object") {
|
|
962
|
+
const tc = thinking["content"];
|
|
963
|
+
if (typeof tc === "string") reasoning += tc;
|
|
964
|
+
} else if (typeof thinking === "string") {
|
|
965
|
+
reasoning += thinking;
|
|
966
|
+
}
|
|
967
|
+
const tcs = d["tool_calls"];
|
|
968
|
+
if (Array.isArray(tcs)) {
|
|
969
|
+
for (const tcRaw of tcs) {
|
|
970
|
+
if (!tcRaw || typeof tcRaw !== "object") continue;
|
|
971
|
+
const tc = tcRaw;
|
|
972
|
+
const idx = typeof tc["index"] === "number" ? tc["index"] : 0;
|
|
973
|
+
const fn = _nullishCoalesce(tc["function"], () => ( {}));
|
|
974
|
+
const slot = _nullishCoalesce(toolCalls.get(idx), () => ( { id: "", name: "", arguments: "" }));
|
|
975
|
+
if (typeof tc["id"] === "string" && tc["id"]) slot.id = tc["id"];
|
|
976
|
+
if (typeof fn["name"] === "string" && fn["name"]) slot.name = fn["name"];
|
|
977
|
+
if (typeof fn["arguments"] === "string") slot.arguments += fn["arguments"];
|
|
978
|
+
toolCalls.set(idx, slot);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
if (!sawChoice && !usage) return null;
|
|
983
|
+
const message = { role: "assistant", content };
|
|
984
|
+
if (reasoning) message["reasoning_content"] = reasoning;
|
|
985
|
+
if (toolCalls.size > 0) {
|
|
986
|
+
message["tool_calls"] = [...toolCalls.entries()].sort((a, b) => a[0] - b[0]).map(([index, tc]) => ({
|
|
987
|
+
index,
|
|
988
|
+
id: tc.id,
|
|
989
|
+
type: "function",
|
|
990
|
+
function: { name: tc.name, arguments: tc.arguments || "{}" }
|
|
991
|
+
}));
|
|
992
|
+
}
|
|
993
|
+
const completion = {
|
|
994
|
+
id: _nullishCoalesce(id, () => ( "chatcmpl-aggregated")),
|
|
995
|
+
object: "chat.completion",
|
|
996
|
+
created: _nullishCoalesce(created, () => ( Math.floor(Date.now() / 1e3))),
|
|
997
|
+
model: _nullishCoalesce(_nullishCoalesce(rewriteModel, () => ( model)), () => ( "")),
|
|
998
|
+
choices: [{ index: 0, message, finish_reason: _nullishCoalesce(finishReason, () => ( "stop")) }]
|
|
999
|
+
};
|
|
1000
|
+
if (usage) completion["usage"] = usage;
|
|
1001
|
+
return JSON.stringify(completion);
|
|
1002
|
+
}
|
|
1003
|
+
async function sniffIsSseResponse(response) {
|
|
1004
|
+
const contentType = _nullishCoalesce(response.headers.get("Content-Type"), () => ( ""));
|
|
1005
|
+
if (contentType.includes("text/event-stream")) return true;
|
|
1006
|
+
if (!response.body) return false;
|
|
1007
|
+
const peek = response.clone();
|
|
1008
|
+
try {
|
|
1009
|
+
const reader = peek.body.getReader();
|
|
1010
|
+
const { value } = await reader.read();
|
|
1011
|
+
reader.releaseLock();
|
|
1012
|
+
const head = value ? new TextDecoder().decode(value).trimStart() : "";
|
|
1013
|
+
return head.startsWith("event:") || head.startsWith("data:");
|
|
1014
|
+
} catch (e13) {
|
|
1015
|
+
return false;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
900
1018
|
function writeError(res, status, message) {
|
|
901
1019
|
if (isAnthropicProtocolResponse(res)) {
|
|
902
1020
|
writeAnthropicError(res, status, message);
|
|
@@ -963,7 +1081,7 @@ function buildByoRouteActivityMeta(deps, providerId, sessionId) {
|
|
|
963
1081
|
if (!pool || typeof pool.getKeyIdForSession !== "function") return void 0;
|
|
964
1082
|
try {
|
|
965
1083
|
return _nullishCoalesce(pool.getKeyIdForSession(providerId, sessionId), () => ( void 0));
|
|
966
|
-
} catch (
|
|
1084
|
+
} catch (e14) {
|
|
967
1085
|
return void 0;
|
|
968
1086
|
}
|
|
969
1087
|
}
|
|
@@ -1012,7 +1130,7 @@ var ProviderProxyRouteMap = (_class = class {
|
|
|
1012
1130
|
if (!entry) return void 0;
|
|
1013
1131
|
try {
|
|
1014
1132
|
_optionalChain([entry, 'access', _43 => _43.onActivity, 'optionalCall', _44 => _44(Date.now())]);
|
|
1015
|
-
} catch (
|
|
1133
|
+
} catch (e15) {
|
|
1016
1134
|
}
|
|
1017
1135
|
this.armIdleTimer(token, entry);
|
|
1018
1136
|
return entry.context;
|
|
@@ -1072,7 +1190,7 @@ var ProviderProxyRouteMap = (_class = class {
|
|
|
1072
1190
|
this.clearIdleTimer(entry);
|
|
1073
1191
|
try {
|
|
1074
1192
|
_optionalChain([entry, 'access', _48 => _48.onEvicted, 'optionalCall', _49 => _49(reason)]);
|
|
1075
|
-
} catch (
|
|
1193
|
+
} catch (e16) {
|
|
1076
1194
|
}
|
|
1077
1195
|
}
|
|
1078
1196
|
}, _class);
|
|
@@ -1541,13 +1659,13 @@ function recordAnthropicNonStreamUsage(recorder, bodyText, attribution) {
|
|
|
1541
1659
|
parsed.usage,
|
|
1542
1660
|
attribution
|
|
1543
1661
|
);
|
|
1544
|
-
} catch (
|
|
1662
|
+
} catch (e17) {
|
|
1545
1663
|
}
|
|
1546
1664
|
}
|
|
1547
1665
|
function recordAnthropicStreamUsage(recorder, rawUsage, attribution) {
|
|
1548
1666
|
try {
|
|
1549
1667
|
emitAnthropicUsageRecord(recorder, rawUsage, attribution);
|
|
1550
|
-
} catch (
|
|
1668
|
+
} catch (e18) {
|
|
1551
1669
|
}
|
|
1552
1670
|
}
|
|
1553
1671
|
|
|
@@ -1853,7 +1971,7 @@ function rewriteBodyModel(rawBody, model) {
|
|
|
1853
1971
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return rawBody;
|
|
1854
1972
|
parsed.model = model;
|
|
1855
1973
|
return JSON.stringify(parsed);
|
|
1856
|
-
} catch (
|
|
1974
|
+
} catch (e19) {
|
|
1857
1975
|
return rawBody;
|
|
1858
1976
|
}
|
|
1859
1977
|
}
|
|
@@ -1888,7 +2006,7 @@ async function readBoundedBody(response, max = 2048) {
|
|
|
1888
2006
|
try {
|
|
1889
2007
|
const text = await response.clone().text();
|
|
1890
2008
|
return text.slice(0, max);
|
|
1891
|
-
} catch (
|
|
2009
|
+
} catch (e20) {
|
|
1892
2010
|
return void 0;
|
|
1893
2011
|
}
|
|
1894
2012
|
}
|
|
@@ -1905,7 +2023,7 @@ async function markSubscriptionHealth(plan, selectedAccountId, result) {
|
|
|
1905
2023
|
try {
|
|
1906
2024
|
const parsed = JSON.parse(errorBody);
|
|
1907
2025
|
if (typeof _optionalChain([parsed, 'access', _117 => _117.error, 'optionalAccess', _118 => _118.type]) === "string") upstreamErrorType = parsed.error.type;
|
|
1908
|
-
} catch (
|
|
2026
|
+
} catch (e21) {
|
|
1909
2027
|
}
|
|
1910
2028
|
}
|
|
1911
2029
|
}
|
|
@@ -2050,7 +2168,7 @@ function withUpstreamUrl(plan, url) {
|
|
|
2050
2168
|
const original = new URL(resolved);
|
|
2051
2169
|
const target = new URL(url);
|
|
2052
2170
|
return `${target.origin}${original.pathname}${original.search}`;
|
|
2053
|
-
} catch (
|
|
2171
|
+
} catch (e22) {
|
|
2054
2172
|
return url;
|
|
2055
2173
|
}
|
|
2056
2174
|
}
|
|
@@ -2070,7 +2188,7 @@ var MAX_CMAP_ENTRIES = 65536;
|
|
|
2070
2188
|
function extractPdfText(base64, budgetMs = DEFAULT_PDF_TEXT_BUDGET_MS) {
|
|
2071
2189
|
try {
|
|
2072
2190
|
return extract(Buffer.from(base64, "base64"), budgetMs);
|
|
2073
|
-
} catch (
|
|
2191
|
+
} catch (e23) {
|
|
2074
2192
|
return { reason: "no-text-layer" };
|
|
2075
2193
|
}
|
|
2076
2194
|
}
|
|
@@ -2414,13 +2532,13 @@ function recordResponsesNonStreamUsage(recorder, bodyText, attribution) {
|
|
|
2414
2532
|
parsed.usage,
|
|
2415
2533
|
attribution
|
|
2416
2534
|
);
|
|
2417
|
-
} catch (
|
|
2535
|
+
} catch (e24) {
|
|
2418
2536
|
}
|
|
2419
2537
|
}
|
|
2420
2538
|
function recordResponsesStreamUsage(recorder, rawUsage, attribution) {
|
|
2421
2539
|
try {
|
|
2422
2540
|
emitResponsesUsageRecord(recorder, rawUsage, attribution);
|
|
2423
|
-
} catch (
|
|
2541
|
+
} catch (e25) {
|
|
2424
2542
|
}
|
|
2425
2543
|
}
|
|
2426
2544
|
|
|
@@ -2460,7 +2578,7 @@ function parseCodexUsageLimitErrorPayload(bodyText) {
|
|
|
2460
2578
|
...resetsAtMs !== void 0 ? { resetsAtMs } : {},
|
|
2461
2579
|
...typeof planType === "string" && planType ? { planType } : {}
|
|
2462
2580
|
};
|
|
2463
|
-
} catch (
|
|
2581
|
+
} catch (e26) {
|
|
2464
2582
|
return null;
|
|
2465
2583
|
}
|
|
2466
2584
|
}
|
|
@@ -2526,7 +2644,7 @@ function normalizeHostedImageState(value) {
|
|
|
2526
2644
|
hasImageContext: value.hasImageContext,
|
|
2527
2645
|
pendingReceipts: Object.freeze(pendingReceipts)
|
|
2528
2646
|
});
|
|
2529
|
-
} catch (
|
|
2647
|
+
} catch (e27) {
|
|
2530
2648
|
throw new TypeError(INVALID_HOSTED_IMAGE_METADATA);
|
|
2531
2649
|
}
|
|
2532
2650
|
}
|
|
@@ -2625,7 +2743,7 @@ function isResponsesCreateUrl(value) {
|
|
|
2625
2743
|
if (!value) return false;
|
|
2626
2744
|
try {
|
|
2627
2745
|
return new URL(value).pathname.replace(/\/+$/, "").endsWith("/responses");
|
|
2628
|
-
} catch (
|
|
2746
|
+
} catch (e28) {
|
|
2629
2747
|
return false;
|
|
2630
2748
|
}
|
|
2631
2749
|
}
|
|
@@ -2795,7 +2913,7 @@ function deriveResponsesCompactUrl(createUrl) {
|
|
|
2795
2913
|
let url;
|
|
2796
2914
|
try {
|
|
2797
2915
|
url = new URL(createUrl);
|
|
2798
|
-
} catch (
|
|
2916
|
+
} catch (e29) {
|
|
2799
2917
|
throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({
|
|
2800
2918
|
status: 502,
|
|
2801
2919
|
code: "invalid_upstream_url",
|
|
@@ -2985,7 +3103,7 @@ async function buildSubscriptionPlan2(route, deps, resolved, resolvedModel, isSt
|
|
|
2985
3103
|
callerClientHeaders: profile.authStrategy.providerId === "codex" ? _chunkSQU2FGXIcjs.extractCodexClientHeaders.call(void 0, requestHeaders) : void 0,
|
|
2986
3104
|
// opencodego-egress-identity: the caller's own session id, forwarded
|
|
2987
3105
|
// verbatim to opencode.ai (the codex callerClientHeaders precedent).
|
|
2988
|
-
callerOpenCodeSession: profile.authStrategy.providerId === "opencodego" ?
|
|
3106
|
+
callerOpenCodeSession: profile.authStrategy.providerId === "opencodego" ? _chunkLWBXQXZ3cjs.extractOpenCodeSessionHeader.call(void 0, requestHeaders) : void 0,
|
|
2989
3107
|
statefulContinuation: !!affinity,
|
|
2990
3108
|
credential: affinityAccountId ? { kind: "subscription-account", id: affinityAccountId } : { kind: "subscription-account", id: "pending-selection" }
|
|
2991
3109
|
};
|
|
@@ -2997,6 +3115,7 @@ async function resolveGeminiProject(profile, hints) {
|
|
|
2997
3115
|
if (!accessToken) return void 0;
|
|
2998
3116
|
return _optionalChain([_chunkR3HK6R4Bcjs.getGeminiCodeAssistResolver.call(void 0, ), 'optionalAccess', _155 => _155.resolveProject, 'call', _156 => _156(accessToken)]);
|
|
2999
3117
|
}
|
|
3118
|
+
var resolveGeminiProjectForChatBridge = resolveGeminiProject;
|
|
3000
3119
|
async function resolveAntigravityProjectThreaded(profile, hints) {
|
|
3001
3120
|
const headers = {};
|
|
3002
3121
|
await profile.authStrategy.applyHeaders(headers, hints);
|
|
@@ -3073,13 +3192,16 @@ async function applyPlanAuth(body, plan) {
|
|
|
3073
3192
|
});
|
|
3074
3193
|
body.model = actualModel;
|
|
3075
3194
|
plan.transformerProvider.models = [actualModel];
|
|
3076
|
-
if (plan.proxyProviderId === "codex")
|
|
3195
|
+
if (plan.proxyProviderId === "codex") {
|
|
3196
|
+
body.store = false;
|
|
3197
|
+
if (!plan.isStream) body.stream = true;
|
|
3198
|
+
}
|
|
3077
3199
|
return { headers, accountId, actualModel };
|
|
3078
3200
|
}
|
|
3079
3201
|
function decorateCodexHeaders(headers, plan) {
|
|
3080
3202
|
if (plan.proxyProviderId !== "codex") return;
|
|
3081
3203
|
_chunkUKQHBK4Qcjs.fillMissingHeaders.call(void 0, headers, _nullishCoalesce(plan.callerClientHeaders, () => ( {})));
|
|
3082
|
-
_chunkUKQHBK4Qcjs.fillMissingHeaders.call(void 0, headers, { accept: _chunkSQU2FGXIcjs.codexAcceptHeader.call(void 0,
|
|
3204
|
+
_chunkUKQHBK4Qcjs.fillMissingHeaders.call(void 0, headers, { accept: _chunkSQU2FGXIcjs.codexAcceptHeader.call(void 0, true) });
|
|
3083
3205
|
_chunkSQU2FGXIcjs.fillMissingCodexCliIdentity.call(void 0, headers);
|
|
3084
3206
|
}
|
|
3085
3207
|
async function runNative(body, plan, operation, signal) {
|
|
@@ -3367,7 +3489,7 @@ function createNonCollidingSelectorName(tools, createName) {
|
|
|
3367
3489
|
let candidate;
|
|
3368
3490
|
try {
|
|
3369
3491
|
candidate = createName();
|
|
3370
|
-
} catch (
|
|
3492
|
+
} catch (e30) {
|
|
3371
3493
|
throw new (0, _chunkINY54AYXcjs.ImageGenerationError)("image_generation_failed");
|
|
3372
3494
|
}
|
|
3373
3495
|
if (typeof candidate === "string" && SELECTOR_NAME_PATTERN.test(candidate) && !declaredNames.has(candidate)) {
|
|
@@ -3386,7 +3508,7 @@ function parseSelectorPrompt(value) {
|
|
|
3386
3508
|
let parsed;
|
|
3387
3509
|
try {
|
|
3388
3510
|
parsed = JSON.parse(value);
|
|
3389
|
-
} catch (
|
|
3511
|
+
} catch (e31) {
|
|
3390
3512
|
protocolFailure();
|
|
3391
3513
|
}
|
|
3392
3514
|
if (!isRecord4(parsed) || Object.keys(parsed).some((key) => key !== "prompt") || typeof parsed.prompt !== "string" || !parsed.prompt.trim() || parsed.prompt.length > 32e3) {
|
|
@@ -3603,7 +3725,7 @@ function parseSelectorArguments(value) {
|
|
|
3603
3725
|
let parsed;
|
|
3604
3726
|
try {
|
|
3605
3727
|
parsed = JSON.parse(value);
|
|
3606
|
-
} catch (
|
|
3728
|
+
} catch (e32) {
|
|
3607
3729
|
return void 0;
|
|
3608
3730
|
}
|
|
3609
3731
|
if (!isRecord5(parsed) || typeof parsed.query !== "string") return void 0;
|
|
@@ -3731,7 +3853,7 @@ var NativeResponsesSearchLease = class {
|
|
|
3731
3853
|
let parsed;
|
|
3732
3854
|
try {
|
|
3733
3855
|
parsed = JSON.parse(text);
|
|
3734
|
-
} catch (
|
|
3856
|
+
} catch (e33) {
|
|
3735
3857
|
return responseWithBody(input.response, text, false);
|
|
3736
3858
|
}
|
|
3737
3859
|
if (!isRecord6(parsed)) return responseWithBody(input.response, text, false);
|
|
@@ -3877,7 +3999,7 @@ async function handleOpenAIResponsesRequest(res, rawBody, route, deps, requestHe
|
|
|
3877
3999
|
let parsedBody;
|
|
3878
4000
|
try {
|
|
3879
4001
|
parsedBody = JSON.parse(rawBody);
|
|
3880
|
-
} catch (
|
|
4002
|
+
} catch (e34) {
|
|
3881
4003
|
writeError(res, 400, "Invalid JSON in request body");
|
|
3882
4004
|
return;
|
|
3883
4005
|
}
|
|
@@ -4128,6 +4250,30 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
|
|
|
4128
4250
|
})
|
|
4129
4251
|
};
|
|
4130
4252
|
}
|
|
4253
|
+
if (!isStream) {
|
|
4254
|
+
if (await sniffIsSseResponse(providerResponse.response)) {
|
|
4255
|
+
const collapsed = await aggregateResponsesSseToJsonBody(
|
|
4256
|
+
providerResponse.response,
|
|
4257
|
+
route.requestedModel,
|
|
4258
|
+
signal
|
|
4259
|
+
);
|
|
4260
|
+
if (collapsed !== null) {
|
|
4261
|
+
providerResponse = {
|
|
4262
|
+
...providerResponse,
|
|
4263
|
+
response: new Response(collapsed, {
|
|
4264
|
+
status: providerResponse.response.status,
|
|
4265
|
+
headers: { "Content-Type": "application/json" }
|
|
4266
|
+
})
|
|
4267
|
+
};
|
|
4268
|
+
} else {
|
|
4269
|
+
throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({
|
|
4270
|
+
status: 502,
|
|
4271
|
+
code: "upstream_stream_collapse_failed",
|
|
4272
|
+
message: "upstream streamed no terminal response event"
|
|
4273
|
+
});
|
|
4274
|
+
}
|
|
4275
|
+
}
|
|
4276
|
+
}
|
|
4131
4277
|
let overloadRecorded = false;
|
|
4132
4278
|
let usageLimitRecorded = false;
|
|
4133
4279
|
const observeSse = (event) => {
|
|
@@ -4176,7 +4322,7 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
|
|
|
4176
4322
|
try {
|
|
4177
4323
|
const body = JSON.parse(bodyText);
|
|
4178
4324
|
if (body.status !== "failed" && body.status !== "incomplete") recordAffinity(body.id);
|
|
4179
|
-
} catch (
|
|
4325
|
+
} catch (e35) {
|
|
4180
4326
|
}
|
|
4181
4327
|
}
|
|
4182
4328
|
|
|
@@ -4185,7 +4331,7 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
|
|
|
4185
4331
|
let anthropicBody;
|
|
4186
4332
|
try {
|
|
4187
4333
|
anthropicBody = JSON.parse(rawBody);
|
|
4188
|
-
} catch (
|
|
4334
|
+
} catch (e36) {
|
|
4189
4335
|
writeError(res, 400, "Invalid JSON in request body");
|
|
4190
4336
|
return;
|
|
4191
4337
|
}
|
|
@@ -4445,7 +4591,7 @@ function resolveSameFormatBody(anthropicBody, rawBody, plan) {
|
|
|
4445
4591
|
try {
|
|
4446
4592
|
const m = JSON.parse(rawBody).model;
|
|
4447
4593
|
originalModel = typeof m === "string" ? m : void 0;
|
|
4448
|
-
} catch (
|
|
4594
|
+
} catch (e37) {
|
|
4449
4595
|
originalModel = void 0;
|
|
4450
4596
|
}
|
|
4451
4597
|
return plan.resolvedModel !== originalModel ? JSON.stringify(anthropicBody) : rawBody;
|
|
@@ -4541,7 +4687,7 @@ function countTools(tools, budget) {
|
|
|
4541
4687
|
let serialized;
|
|
4542
4688
|
try {
|
|
4543
4689
|
serialized = _nullishCoalesce(JSON.stringify(tool), () => ( ""));
|
|
4544
|
-
} catch (
|
|
4690
|
+
} catch (e38) {
|
|
4545
4691
|
serialized = "";
|
|
4546
4692
|
}
|
|
4547
4693
|
if (!budget.addChars(serialized.length)) return;
|
|
@@ -4586,7 +4732,7 @@ async function handleAnthropicCountTokens(res, rawBody, route, deps, options = {
|
|
|
4586
4732
|
let body;
|
|
4587
4733
|
try {
|
|
4588
4734
|
body = JSON.parse(rawBody);
|
|
4589
|
-
} catch (
|
|
4735
|
+
} catch (e39) {
|
|
4590
4736
|
writeError(res, 400, "Invalid JSON in request body");
|
|
4591
4737
|
return;
|
|
4592
4738
|
}
|
|
@@ -4687,7 +4833,7 @@ async function handleAnthropicMessagesRequest(req, res, route, deps) {
|
|
|
4687
4833
|
const callerAnthropicVersion = Array.isArray(callerVersionRaw) ? callerVersionRaw.join(",") : callerVersionRaw;
|
|
4688
4834
|
const callerIdentity = _chunk6RPZADX3cjs.captureCallerIdentity.call(void 0, _chunkRPII3E6Zcjs.getSharedIdentityStore.call(void 0, ), request.headers);
|
|
4689
4835
|
const callerClientHeaders = extractClaudeClientHeaders(request.headers);
|
|
4690
|
-
const callerOpenCodeSession =
|
|
4836
|
+
const callerOpenCodeSession = _chunkLWBXQXZ3cjs.extractOpenCodeSessionHeader.call(void 0, request.headers);
|
|
4691
4837
|
await handleAnthropicCountTokens(res, rawBody, route, deps, {
|
|
4692
4838
|
callerAnthropicBeta,
|
|
4693
4839
|
callerAnthropicVersion,
|
|
@@ -4710,7 +4856,7 @@ async function handleAnthropicMessagesRequest(req, res, route, deps) {
|
|
|
4710
4856
|
let parsedForSearch;
|
|
4711
4857
|
try {
|
|
4712
4858
|
parsedForSearch = preReadBody ? JSON.parse(preReadBody) : {};
|
|
4713
|
-
} catch (
|
|
4859
|
+
} catch (e40) {
|
|
4714
4860
|
parsedForSearch = void 0;
|
|
4715
4861
|
}
|
|
4716
4862
|
const handled = await handleAnthropicManagedSearch(res, parsedForSearch, {
|
|
@@ -4732,7 +4878,7 @@ async function handleAnthropicMessagesRequest(req, res, route, deps) {
|
|
|
4732
4878
|
const callerAnthropicVersion = Array.isArray(callerVersionRaw) ? callerVersionRaw.join(",") : callerVersionRaw;
|
|
4733
4879
|
const callerIdentity = _chunk6RPZADX3cjs.captureCallerIdentity.call(void 0, _chunkRPII3E6Zcjs.getSharedIdentityStore.call(void 0, ), request.headers);
|
|
4734
4880
|
const callerClientHeaders = extractClaudeClientHeaders(request.headers);
|
|
4735
|
-
const callerOpenCodeSession =
|
|
4881
|
+
const callerOpenCodeSession = _chunkLWBXQXZ3cjs.extractOpenCodeSessionHeader.call(void 0, request.headers);
|
|
4736
4882
|
await handleAnthropicMessagesByo(res, rawBody, route, deps, {
|
|
4737
4883
|
callerAnthropicBeta,
|
|
4738
4884
|
callerAnthropicVersion,
|
|
@@ -4855,13 +5001,13 @@ function recordGeminiNonStreamUsage(recorder, bodyText, attribution) {
|
|
|
4855
5001
|
parsed.usageMetadata,
|
|
4856
5002
|
attribution
|
|
4857
5003
|
);
|
|
4858
|
-
} catch (
|
|
5004
|
+
} catch (e41) {
|
|
4859
5005
|
}
|
|
4860
5006
|
}
|
|
4861
5007
|
function recordGeminiStreamUsage(recorder, rawUsageMetadata, attribution) {
|
|
4862
5008
|
try {
|
|
4863
5009
|
emitGeminiUsageRecord(recorder, rawUsageMetadata, attribution);
|
|
4864
|
-
} catch (
|
|
5010
|
+
} catch (e42) {
|
|
4865
5011
|
}
|
|
4866
5012
|
}
|
|
4867
5013
|
|
|
@@ -4885,7 +5031,7 @@ async function handleGeminiGenerateContentRequest(res, rawBody, url, route, deps
|
|
|
4885
5031
|
let geminiBody;
|
|
4886
5032
|
try {
|
|
4887
5033
|
geminiBody = JSON.parse(rawBody);
|
|
4888
|
-
} catch (
|
|
5034
|
+
} catch (e43) {
|
|
4889
5035
|
writeError(res, 400, "Invalid JSON in request body");
|
|
4890
5036
|
return;
|
|
4891
5037
|
}
|
|
@@ -5095,24 +5241,33 @@ function recordChatCompletionsNonStreamUsage(recorder, bodyText, attribution) {
|
|
|
5095
5241
|
parsed.usage,
|
|
5096
5242
|
attribution
|
|
5097
5243
|
);
|
|
5098
|
-
} catch (
|
|
5244
|
+
} catch (e44) {
|
|
5099
5245
|
}
|
|
5100
5246
|
}
|
|
5101
5247
|
function recordChatCompletionsStreamUsage(recorder, rawUsage, attribution) {
|
|
5102
5248
|
try {
|
|
5103
5249
|
emitChatCompletionsUsageRecord(recorder, rawUsage, attribution);
|
|
5104
|
-
} catch (
|
|
5250
|
+
} catch (e45) {
|
|
5105
5251
|
}
|
|
5106
5252
|
}
|
|
5107
5253
|
|
|
5108
5254
|
// src/provider-proxy/ingress/openaiChatIngress.ts
|
|
5109
|
-
var CHAT_BRIDGE_SUBSCRIPTION_PROVIDERS = /* @__PURE__ */ new Set([
|
|
5255
|
+
var CHAT_BRIDGE_SUBSCRIPTION_PROVIDERS = /* @__PURE__ */ new Set([
|
|
5256
|
+
"claude",
|
|
5257
|
+
"kimi",
|
|
5258
|
+
"grok",
|
|
5259
|
+
"opencodego",
|
|
5260
|
+
"codex",
|
|
5261
|
+
"gemini",
|
|
5262
|
+
"copilot",
|
|
5263
|
+
"antigravity"
|
|
5264
|
+
]);
|
|
5110
5265
|
var IDENTITY_ENDPOINT_TRANSFORMER = { name: "identity-openai-chat" };
|
|
5111
5266
|
async function handleOpenAIChatRequest(res, rawBody, route, deps) {
|
|
5112
5267
|
let chatBody;
|
|
5113
5268
|
try {
|
|
5114
5269
|
chatBody = JSON.parse(rawBody);
|
|
5115
|
-
} catch (
|
|
5270
|
+
} catch (e46) {
|
|
5116
5271
|
writeError(res, 400, "Invalid JSON in request body");
|
|
5117
5272
|
return;
|
|
5118
5273
|
}
|
|
@@ -5120,9 +5275,26 @@ async function handleOpenAIChatRequest(res, rawBody, route, deps) {
|
|
|
5120
5275
|
const resolvedModel = route.model;
|
|
5121
5276
|
chatBody.model = resolvedModel;
|
|
5122
5277
|
try {
|
|
5123
|
-
const plan = route.authMode === "subscription" ? await buildSubscriptionPlan3(res, route, deps, resolvedModel, isStream) : await buildByoPlan4(res, route, deps, resolvedModel, isStream);
|
|
5278
|
+
const plan = route.authMode === "subscription" ? await buildSubscriptionPlan3(res, route, deps, chatBody, resolvedModel, isStream) : await buildByoPlan4(res, route, deps, resolvedModel, isStream);
|
|
5124
5279
|
if (!plan) return;
|
|
5125
|
-
|
|
5280
|
+
let providerResponse = plan.isSubscription ? await runPipelineWithSubscriptionRetry2(chatBody, plan) : await runPipelineWithPoolReporting3(chatBody, plan);
|
|
5281
|
+
if (!isStream) {
|
|
5282
|
+
if (await sniffIsSseResponse(providerResponse.response)) {
|
|
5283
|
+
const collapsed = await aggregateOpenAIChatChunksToJsonBody(providerResponse.response);
|
|
5284
|
+
if (collapsed !== null) {
|
|
5285
|
+
providerResponse = {
|
|
5286
|
+
response: new Response(collapsed, {
|
|
5287
|
+
status: providerResponse.response.status,
|
|
5288
|
+
headers: { "Content-Type": "application/json" }
|
|
5289
|
+
}),
|
|
5290
|
+
rawStatus: providerResponse.rawStatus
|
|
5291
|
+
};
|
|
5292
|
+
} else {
|
|
5293
|
+
writeError(res, 502, "upstream streamed no completable chat chunks");
|
|
5294
|
+
return;
|
|
5295
|
+
}
|
|
5296
|
+
}
|
|
5297
|
+
}
|
|
5126
5298
|
const usageAttribution = {
|
|
5127
5299
|
sessionId: route.sessionId,
|
|
5128
5300
|
providerId: _nullishCoalesce(route.providerId, () => ( "openai")),
|
|
@@ -5214,7 +5386,7 @@ async function buildByoPlan4(res, route, deps, resolvedModel, isStream) {
|
|
|
5214
5386
|
routeSessionId: _nullishCoalesce(route.sessionId, () => ( null))
|
|
5215
5387
|
};
|
|
5216
5388
|
}
|
|
5217
|
-
async function buildSubscriptionPlan3(res, route, deps, resolvedModel, isStream) {
|
|
5389
|
+
async function buildSubscriptionPlan3(res, route, deps, chatBody, resolvedModel, isStream) {
|
|
5218
5390
|
const profile = route.subscriptionProfile;
|
|
5219
5391
|
if (!profile) {
|
|
5220
5392
|
writeError(res, 502, "Subscription mode requires a subscription profile");
|
|
@@ -5225,27 +5397,56 @@ async function buildSubscriptionPlan3(res, route, deps, resolvedModel, isStream)
|
|
|
5225
5397
|
writeError(
|
|
5226
5398
|
res,
|
|
5227
5399
|
501,
|
|
5228
|
-
`the OpenAI-chat\u2192subscription bridge
|
|
5400
|
+
`the OpenAI-chat\u2192subscription bridge does not implement subscription provider '${providerId}' on this endpoint yet (use the /v1/responses endpoint, a Claude/Kimi/Grok/OpenCodeGo subscription, or a BYO provider)`
|
|
5229
5401
|
);
|
|
5230
5402
|
return null;
|
|
5231
5403
|
}
|
|
5232
|
-
|
|
5404
|
+
let mappedModel = resolvedModel;
|
|
5405
|
+
if (profile.modelMapper) {
|
|
5406
|
+
const summary = buildSubscriptionRequestSummary(chatBody);
|
|
5407
|
+
const mapped = profile.modelMapper(resolvedModel, summary, route.subscriptionConfig);
|
|
5408
|
+
mappedModel = mapped.resolvedModel;
|
|
5409
|
+
}
|
|
5410
|
+
const upstreamUrl = _optionalChain([profile, 'access', _284 => _284.resolveUpstreamUrl, 'optionalCall', _285 => _285(mappedModel, route.subscriptionConfig)]);
|
|
5233
5411
|
if (!upstreamUrl) {
|
|
5234
5412
|
writeError(res, 502, "Subscription profile is missing resolveUpstreamUrl");
|
|
5235
5413
|
return null;
|
|
5236
5414
|
}
|
|
5237
5415
|
const auth = _nullishCoalesce(route.auth, () => ( new (0, _chunkRXMF7GNFcjs.SubscriptionAuthSource)(profile)));
|
|
5416
|
+
const chatChainNames = _nullishCoalesce(_optionalChain([profile, 'access', _286 => _286.chatBridgeTransformerNames, 'optionalCall', _287 => _287(mappedModel, route.subscriptionConfig)]), () => ( _optionalChain([profile, 'access', _288 => _288.resolveProviderTransformerNames, 'optionalCall', _289 => _289(mappedModel, route.subscriptionConfig)])));
|
|
5238
5417
|
const chain = _chunkNYUNU75Acjs.resolveSubscriptionChain.call(void 0,
|
|
5239
5418
|
profile,
|
|
5240
5419
|
deps.llmConfig.getTransformerService(),
|
|
5241
|
-
IDENTITY_ENDPOINT_TRANSFORMER
|
|
5420
|
+
IDENTITY_ENDPOINT_TRANSFORMER,
|
|
5421
|
+
chatChainNames
|
|
5242
5422
|
);
|
|
5243
5423
|
const transformerProvider = {
|
|
5244
5424
|
name: providerId,
|
|
5245
5425
|
baseUrl: upstreamUrl,
|
|
5246
5426
|
apiKey: "",
|
|
5247
|
-
models: [
|
|
5427
|
+
models: [mappedModel]
|
|
5248
5428
|
};
|
|
5429
|
+
const sessionKey = _chunkJ3QQ6JS5cjs.deriveSubscriptionSessionKey.call(void 0, chatBody);
|
|
5430
|
+
if (providerId === "gemini") {
|
|
5431
|
+
transformerProvider.geminiProject = await resolveGeminiProjectForChatBridge(profile, {
|
|
5432
|
+
sessionKey,
|
|
5433
|
+
preferredAccountId: route.preferredAccountId,
|
|
5434
|
+
preferredAccountGroup: route.preferredAccountGroup,
|
|
5435
|
+
boundAccountFallbackPolicy: route.boundAccountFallbackPolicy
|
|
5436
|
+
});
|
|
5437
|
+
} else if (providerId === "antigravity") {
|
|
5438
|
+
transformerProvider.geminiProject = await resolveAntigravityProjectThreaded(profile, {
|
|
5439
|
+
resolvedModel: mappedModel,
|
|
5440
|
+
reportSelection: () => {
|
|
5441
|
+
},
|
|
5442
|
+
sessionKey,
|
|
5443
|
+
preferredAccountId: route.preferredAccountId,
|
|
5444
|
+
preferredAccountGroup: route.preferredAccountGroup,
|
|
5445
|
+
boundAccountFallbackPolicy: route.boundAccountFallbackPolicy
|
|
5446
|
+
});
|
|
5447
|
+
}
|
|
5448
|
+
chatBody.model = mappedModel;
|
|
5449
|
+
const resolveUrl = providerId === "antigravity" ? (config) => config.url instanceof URL ? config.url.toString() : typeof config.url === "string" ? config.url : upstreamUrl : () => upstreamUrl;
|
|
5249
5450
|
return {
|
|
5250
5451
|
auth,
|
|
5251
5452
|
preferredAccountId: route.preferredAccountId,
|
|
@@ -5253,12 +5454,13 @@ async function buildSubscriptionPlan3(res, route, deps, resolvedModel, isStream)
|
|
|
5253
5454
|
boundAccountFallbackPolicy: route.boundAccountFallbackPolicy,
|
|
5254
5455
|
chain,
|
|
5255
5456
|
transformerProvider,
|
|
5256
|
-
resolvedModel,
|
|
5457
|
+
resolvedModel: mappedModel,
|
|
5257
5458
|
isStream,
|
|
5258
|
-
resolveUrl
|
|
5459
|
+
resolveUrl,
|
|
5259
5460
|
upstreamUrl,
|
|
5260
5461
|
proxyProviderId: providerId,
|
|
5261
5462
|
isSubscription: true,
|
|
5463
|
+
contentSessionKey: sessionKey,
|
|
5262
5464
|
routeSessionId: _nullishCoalesce(route.sessionId, () => ( null))
|
|
5263
5465
|
};
|
|
5264
5466
|
}
|
|
@@ -5270,6 +5472,7 @@ async function runPipeline3(chatBody, plan) {
|
|
|
5270
5472
|
await auth.applyHeaders(authHeaders, {
|
|
5271
5473
|
upstreamUrl,
|
|
5272
5474
|
model: resolvedModel,
|
|
5475
|
+
sessionKey: plan.contentSessionKey,
|
|
5273
5476
|
preferredAccountId: plan.preferredAccountId,
|
|
5274
5477
|
preferredAccountGroup: plan.preferredAccountGroup,
|
|
5275
5478
|
boundAccountFallbackPolicy: plan.boundAccountFallbackPolicy,
|
|
@@ -5291,6 +5494,7 @@ async function runPipeline3(chatBody, plan) {
|
|
|
5291
5494
|
if (value !== void 0 && !(key in headers)) headers[key] = value;
|
|
5292
5495
|
}
|
|
5293
5496
|
}
|
|
5497
|
+
if (plan.proxyProviderId === "codex") _chunkSQU2FGXIcjs.fillMissingCodexCliIdentity.call(void 0, headers);
|
|
5294
5498
|
return headers;
|
|
5295
5499
|
},
|
|
5296
5500
|
fetchFn: (url, headers, body) => {
|
|
@@ -5311,9 +5515,9 @@ async function runPipeline3(chatBody, plan) {
|
|
|
5311
5515
|
sessionSource: sessionKey ? "route-session-id" : "none",
|
|
5312
5516
|
model: resolvedModel
|
|
5313
5517
|
} : {
|
|
5314
|
-
providerId: _nullishCoalesce(_optionalChain([plan, 'access',
|
|
5518
|
+
providerId: _nullishCoalesce(_optionalChain([plan, 'access', _290 => _290.byoActivity, 'optionalAccess', _291 => _291.providerId]), () => ( transformerProvider.name)),
|
|
5315
5519
|
credentialKind: "provider-key",
|
|
5316
|
-
keyId: _optionalChain([plan, 'access',
|
|
5520
|
+
keyId: _optionalChain([plan, 'access', _292 => _292.byoActivity, 'optionalAccess', _293 => _293.resolveKeyId, 'call', _294 => _294()]),
|
|
5317
5521
|
endpoint: "chat",
|
|
5318
5522
|
sessionKey,
|
|
5319
5523
|
sessionSource: sessionKey ? "route-session-id" : "none",
|
|
@@ -5331,8 +5535,8 @@ async function runPipeline3(chatBody, plan) {
|
|
|
5331
5535
|
}
|
|
5332
5536
|
async function runPipelineWithPoolReporting3(chatBody, plan) {
|
|
5333
5537
|
const first = await runPipeline3(chatBody, plan);
|
|
5334
|
-
const outcome = await _optionalChain([plan, 'access',
|
|
5335
|
-
if (_optionalChain([outcome, 'optionalAccess',
|
|
5538
|
+
const outcome = await _optionalChain([plan, 'access', _295 => _295.auth, 'access', _296 => _296.onResult, 'optionalCall', _297 => _297(first.rawStatus)]);
|
|
5539
|
+
if (_optionalChain([outcome, 'optionalAccess', _298 => _298.rebound])) {
|
|
5336
5540
|
console.log(
|
|
5337
5541
|
"[ProviderProxy:chat] pool re-bound key after status",
|
|
5338
5542
|
first.rawStatus,
|
|
@@ -5345,7 +5549,7 @@ async function runPipelineWithPoolReporting3(chatBody, plan) {
|
|
|
5345
5549
|
async function runPipelineWithSubscriptionRetry2(chatBody, plan) {
|
|
5346
5550
|
const first = await runPipeline3(chatBody, plan);
|
|
5347
5551
|
if (first.rawStatus !== 401) return first;
|
|
5348
|
-
const refreshed = await _optionalChain([plan, 'access',
|
|
5552
|
+
const refreshed = await _optionalChain([plan, 'access', _299 => _299.auth, 'access', _300 => _300.onUnauthorized, 'optionalCall', _301 => _301()]);
|
|
5349
5553
|
if (!refreshed) {
|
|
5350
5554
|
console.warn("[ProviderProxy:chat] 401 not recoverable (onUnauthorized returned false)");
|
|
5351
5555
|
return first;
|
|
@@ -5367,7 +5571,7 @@ function resolveRouteToken(req) {
|
|
|
5367
5571
|
if (fromAuth) return fromAuth;
|
|
5368
5572
|
const googKey = req.headers["x-goog-api-key"];
|
|
5369
5573
|
const value = Array.isArray(googKey) ? googKey[0] : googKey;
|
|
5370
|
-
return _optionalChain([value, 'optionalAccess',
|
|
5574
|
+
return _optionalChain([value, 'optionalAccess', _302 => _302.trim, 'call', _303 => _303()]) || void 0;
|
|
5371
5575
|
}
|
|
5372
5576
|
async function routeRequest(req, res, routes, deps) {
|
|
5373
5577
|
if (classifyAnthropicMessagesPath(req.url) !== null) {
|
|
@@ -5382,7 +5586,7 @@ async function routeRequest(req, res, routes, deps) {
|
|
|
5382
5586
|
const method = req.method;
|
|
5383
5587
|
const url = req.url;
|
|
5384
5588
|
const openAIOperation = _chunkG4CZIUIBcjs.classifyOpenAIOperation.call(void 0, method, url);
|
|
5385
|
-
if (_optionalChain([openAIOperation, 'optionalAccess',
|
|
5589
|
+
if (_optionalChain([openAIOperation, 'optionalAccess', _304 => _304.owner]) === "extension") {
|
|
5386
5590
|
const registry = deps.openAIOperationRegistry;
|
|
5387
5591
|
if (!registry) {
|
|
5388
5592
|
_chunkG4CZIUIBcjs.writeOpenAIOperationError.call(void 0, res, _chunkG4CZIUIBcjs.unsupportedOpenAIOperation.call(void 0, openAIOperation));
|
|
@@ -5404,7 +5608,7 @@ async function routeRequest(req, res, routes, deps) {
|
|
|
5404
5608
|
await handleAnthropicMessagesRequest(req, res, route, deps);
|
|
5405
5609
|
return;
|
|
5406
5610
|
}
|
|
5407
|
-
if (_optionalChain([openAIOperation, 'optionalAccess',
|
|
5611
|
+
if (_optionalChain([openAIOperation, 'optionalAccess', _305 => _305.id]) === "responses.create") {
|
|
5408
5612
|
const abortScope = createResponsesAbortScope({ request: req, response: res });
|
|
5409
5613
|
try {
|
|
5410
5614
|
const rawBody = await readBody(req, abortScope.signal);
|
|
@@ -5435,7 +5639,7 @@ async function routeRequest(req, res, routes, deps) {
|
|
|
5435
5639
|
}
|
|
5436
5640
|
return;
|
|
5437
5641
|
}
|
|
5438
|
-
if (_optionalChain([openAIOperation, 'optionalAccess',
|
|
5642
|
+
if (_optionalChain([openAIOperation, 'optionalAccess', _306 => _306.id]) === "chat.completions.create") {
|
|
5439
5643
|
const rawBody = await readBody(req);
|
|
5440
5644
|
await handleOpenAIChatRequest(res, rawBody, route, deps);
|
|
5441
5645
|
return;
|
|
@@ -5506,7 +5710,7 @@ var ProviderProxy = (_class8 = class {
|
|
|
5506
5710
|
for (const cleanup of [...this.beforeStop]) {
|
|
5507
5711
|
try {
|
|
5508
5712
|
await cleanup();
|
|
5509
|
-
} catch (
|
|
5713
|
+
} catch (e47) {
|
|
5510
5714
|
}
|
|
5511
5715
|
}
|
|
5512
5716
|
this.routes.clear();
|
|
@@ -5792,7 +5996,7 @@ var SYSTEM_ROUTE_LEASE_CLOCK = {
|
|
|
5792
5996
|
now: () => Date.now(),
|
|
5793
5997
|
setTimeout(callback, delayMs) {
|
|
5794
5998
|
const timer = setTimeout(callback, delayMs);
|
|
5795
|
-
_optionalChain([timer, 'access',
|
|
5999
|
+
_optionalChain([timer, 'access', _307 => _307.unref, 'optionalCall', _308 => _308()]);
|
|
5796
6000
|
return timer;
|
|
5797
6001
|
},
|
|
5798
6002
|
clearTimeout(handle) {
|
|
@@ -5886,12 +6090,12 @@ var RouteLeaseManager = (_class10 = class {
|
|
|
5886
6090
|
this.assertOpen();
|
|
5887
6091
|
const route = {
|
|
5888
6092
|
...resolved,
|
|
5889
|
-
sessionId: _nullishCoalesce(_optionalChain([request, 'access',
|
|
6093
|
+
sessionId: _nullishCoalesce(_optionalChain([request, 'access', _309 => _309.execution, 'optionalAccess', _310 => _310.sessionIdHash]), () => ( null)),
|
|
5890
6094
|
routeLease: {
|
|
5891
6095
|
leaseId,
|
|
5892
6096
|
consumer: request.consumer,
|
|
5893
|
-
..._optionalChain([request, 'access',
|
|
5894
|
-
..._optionalChain([request, 'access',
|
|
6097
|
+
..._optionalChain([request, 'access', _311 => _311.execution, 'optionalAccess', _312 => _312.runId]) ? { runId: request.execution.runId } : {},
|
|
6098
|
+
..._optionalChain([request, 'access', _313 => _313.execution, 'optionalAccess', _314 => _314.stageId]) ? { stageId: request.execution.stageId } : {}
|
|
5895
6099
|
}
|
|
5896
6100
|
};
|
|
5897
6101
|
const now = this.clock.now();
|
|
@@ -5946,7 +6150,7 @@ var RouteLeaseManager = (_class10 = class {
|
|
|
5946
6150
|
this.active.set(leaseId, activeLease);
|
|
5947
6151
|
this.idempotency.set(scope, { leaseId, payloadHash: input.payloadHash });
|
|
5948
6152
|
published = true;
|
|
5949
|
-
_optionalChain([this, 'access',
|
|
6153
|
+
_optionalChain([this, 'access', _315 => _315.afterPublish, 'optionalCall', _316 => _316()]);
|
|
5950
6154
|
if (this.closed) {
|
|
5951
6155
|
this.finalize(activeLease, "released");
|
|
5952
6156
|
throw new RouteLeaseError("daemon_not_ready", "route lease manager is shutting down");
|
|
@@ -5983,7 +6187,7 @@ var RouteLeaseManager = (_class10 = class {
|
|
|
5983
6187
|
if (!lease) {
|
|
5984
6188
|
this.pruneTombstones();
|
|
5985
6189
|
const known = this.tombstones.get(leaseId);
|
|
5986
|
-
if (_optionalChain([known, 'optionalAccess',
|
|
6190
|
+
if (_optionalChain([known, 'optionalAccess', _317 => _317.metadata, 'access', _318 => _318.status]) === "expired") {
|
|
5987
6191
|
throw new RouteLeaseError("lease_expired", "route lease has expired");
|
|
5988
6192
|
}
|
|
5989
6193
|
throw new RouteLeaseError("lease_not_found", "route lease was not found");
|
|
@@ -6020,7 +6224,7 @@ var RouteLeaseManager = (_class10 = class {
|
|
|
6020
6224
|
try {
|
|
6021
6225
|
this.finalize(lease, "released");
|
|
6022
6226
|
} catch (error) {
|
|
6023
|
-
_optionalChain([this, 'access',
|
|
6227
|
+
_optionalChain([this, 'access', _319 => _319.logger, 'optionalAccess', _320 => _320.warn, 'call', _321 => _321("route lease cleanup failed during shutdown", { leaseId: lease.leaseId, error: safeErrorName(error) })]);
|
|
6024
6228
|
}
|
|
6025
6229
|
}
|
|
6026
6230
|
}
|
|
@@ -6066,7 +6270,7 @@ var RouteLeaseManager = (_class10 = class {
|
|
|
6066
6270
|
try {
|
|
6067
6271
|
this.routePort.removeRoute(routeToken);
|
|
6068
6272
|
} catch (error) {
|
|
6069
|
-
_optionalChain([this, 'access',
|
|
6273
|
+
_optionalChain([this, 'access', _322 => _322.logger, 'optionalAccess', _323 => _323.warn, 'call', _324 => _324("route lease route cleanup failed", { leaseId, error: safeErrorName(error) })]);
|
|
6070
6274
|
}
|
|
6071
6275
|
}
|
|
6072
6276
|
pruneTombstones() {
|
|
@@ -6091,8 +6295,8 @@ function nonBlank(value) {
|
|
|
6091
6295
|
return typeof value === "string" && value.trim() !== "";
|
|
6092
6296
|
}
|
|
6093
6297
|
function gatewayBindingAllowsKey(binding, apiKeyId) {
|
|
6094
|
-
const scope = _nullishCoalesce(binding.keyScope, () => ( (_optionalChain([binding, 'access',
|
|
6095
|
-
return scope === "all" || Boolean(_optionalChain([binding, 'access',
|
|
6298
|
+
const scope = _nullishCoalesce(binding.keyScope, () => ( (_optionalChain([binding, 'access', _325 => _325.apiKeyIds, 'optionalAccess', _326 => _326.length]) ? "selected" : "all")));
|
|
6299
|
+
return scope === "all" || Boolean(_optionalChain([binding, 'access', _327 => _327.apiKeyIds, 'optionalAccess', _328 => _328.includes, 'call', _329 => _329(apiKeyId)]));
|
|
6096
6300
|
}
|
|
6097
6301
|
function wildcardMatches(pattern, value) {
|
|
6098
6302
|
const escaped = pattern.split("*").map((part) => part.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&")).join(".*");
|
|
@@ -6113,16 +6317,16 @@ function resolveGatewayModelMappingRow(mappings, requestedModel) {
|
|
|
6113
6317
|
return wildcard && nonBlank(wildcard.target) ? { target: wildcard.target.trim(), effort: wildcard.effort } : void 0;
|
|
6114
6318
|
}
|
|
6115
6319
|
function resolveGatewayModelMapping(mappings, requestedModel) {
|
|
6116
|
-
return _optionalChain([resolveGatewayModelMappingRow, 'call',
|
|
6320
|
+
return _optionalChain([resolveGatewayModelMappingRow, 'call', _330 => _330(mappings, requestedModel), 'optionalAccess', _331 => _331.target]);
|
|
6117
6321
|
}
|
|
6118
6322
|
function routeCanServe(binding, requestedModel, role) {
|
|
6119
6323
|
if (binding.modelMode === "passthrough") return nonBlank(requestedModel);
|
|
6120
|
-
if (_optionalChain([binding, 'access',
|
|
6324
|
+
if (_optionalChain([binding, 'access', _332 => _332.modelMappings, 'optionalAccess', _333 => _333.length])) {
|
|
6121
6325
|
return nonBlank(resolveGatewayModelMapping(binding.modelMappings, requestedModel));
|
|
6122
6326
|
}
|
|
6123
|
-
if (
|
|
6327
|
+
if (_chunkJGRNVH7Ccjs.isKindMappedEndpoint.call(void 0, binding.endpoint)) {
|
|
6124
6328
|
const map = _nullishCoalesce(binding.modelMap, () => ( {}));
|
|
6125
|
-
const kind =
|
|
6329
|
+
const kind = _chunkJGRNVH7Ccjs.detectModelKind.call(void 0, binding.endpoint, requestedModel);
|
|
6126
6330
|
if (kind && nonBlank(map[kind])) return true;
|
|
6127
6331
|
if (binding.endpoint === "messages") {
|
|
6128
6332
|
return MESSAGE_FALLBACK_KINDS.some((candidate) => nonBlank(map[candidate]));
|
|
@@ -6130,12 +6334,12 @@ function routeCanServe(binding, requestedModel, role) {
|
|
|
6130
6334
|
return nonBlank(map.codex);
|
|
6131
6335
|
}
|
|
6132
6336
|
if (binding.endpoint === "chat" && binding.dispatchMode === "prefix") {
|
|
6133
|
-
return
|
|
6337
|
+
return _chunkJGRNVH7Ccjs.resolvePrefixTarget.call(void 0, binding.prefixTargets, requestedModel) !== null;
|
|
6134
6338
|
}
|
|
6135
6339
|
if (binding.endpoint === "chat") {
|
|
6136
6340
|
if (!requestedModel) return false;
|
|
6137
6341
|
const wanted = requestedModel.trim().toLowerCase();
|
|
6138
|
-
return (_nullishCoalesce(binding.models, () => ( []))).some((ref) => _optionalChain([modelIdOf, 'call',
|
|
6342
|
+
return (_nullishCoalesce(binding.models, () => ( []))).some((ref) => _optionalChain([modelIdOf, 'call', _334 => _334(ref), 'optionalAccess', _335 => _335.toLowerCase, 'call', _336 => _336()]) === wanted);
|
|
6139
6343
|
}
|
|
6140
6344
|
return role === "background" ? nonBlank(binding.backgroundModel) : nonBlank(binding.defaultModel);
|
|
6141
6345
|
}
|
|
@@ -6168,9 +6372,9 @@ function targetPrefixRefs(target, refs) {
|
|
|
6168
6372
|
function applySingleModel(config, binding, targetModel) {
|
|
6169
6373
|
const ref = targetRef(binding.target, targetModel);
|
|
6170
6374
|
if (!ref) return;
|
|
6171
|
-
if (
|
|
6375
|
+
if (_chunkJGRNVH7Ccjs.isKindMappedEndpoint.call(void 0, binding.endpoint)) {
|
|
6172
6376
|
config.modelMap = Object.fromEntries(
|
|
6173
|
-
|
|
6377
|
+
_chunkJGRNVH7Ccjs.modelKindsForEndpoint.call(void 0, binding.endpoint).map((kind) => [kind, ref])
|
|
6174
6378
|
);
|
|
6175
6379
|
} else if (binding.endpoint === "chat") {
|
|
6176
6380
|
config.models = [ref];
|
|
@@ -6186,13 +6390,13 @@ function gatewayBindingToEndpointConfig(binding, requestedModel) {
|
|
|
6186
6390
|
endpoint: binding.endpoint,
|
|
6187
6391
|
useSubscription: target.kind !== "provider"
|
|
6188
6392
|
};
|
|
6189
|
-
const usesGenericModelHandling = binding.modelMode === "passthrough" || Boolean(_optionalChain([binding, 'access',
|
|
6393
|
+
const usesGenericModelHandling = binding.modelMode === "passthrough" || Boolean(_optionalChain([binding, 'access', _337 => _337.modelMappings, 'optionalAccess', _338 => _338.length]));
|
|
6190
6394
|
const winningMapping = binding.modelMode === "passthrough" ? void 0 : resolveGatewayModelMappingRow(binding.modelMappings, requestedModel);
|
|
6191
|
-
const dynamicModel = binding.modelMode === "passthrough" ? requestedModel : _optionalChain([winningMapping, 'optionalAccess',
|
|
6395
|
+
const dynamicModel = binding.modelMode === "passthrough" ? requestedModel : _optionalChain([winningMapping, 'optionalAccess', _339 => _339.target]);
|
|
6192
6396
|
if (usesGenericModelHandling) {
|
|
6193
6397
|
if (nonBlank(dynamicModel)) applySingleModel(config, binding, dynamicModel);
|
|
6194
|
-
if (_optionalChain([winningMapping, 'optionalAccess',
|
|
6195
|
-
} else if (
|
|
6398
|
+
if (_optionalChain([winningMapping, 'optionalAccess', _340 => _340.effort])) config.reasoningEffort = winningMapping.effort;
|
|
6399
|
+
} else if (_chunkJGRNVH7Ccjs.isKindMappedEndpoint.call(void 0, binding.endpoint)) {
|
|
6196
6400
|
config.modelMap = Object.fromEntries(
|
|
6197
6401
|
Object.entries(_nullishCoalesce(binding.modelMap, () => ( {}))).map(([kind, ref]) => [kind, targetRef(target, ref)])
|
|
6198
6402
|
);
|
|
@@ -6223,7 +6427,7 @@ function candidateGatewayBindings(bindings, apiKeyId, endpoint) {
|
|
|
6223
6427
|
const candidates = (_nullishCoalesce(bindings, () => ( []))).filter(
|
|
6224
6428
|
(binding) => binding.enabled && binding.endpoint === endpoint && gatewayBindingAllowsKey(binding, apiKeyId)
|
|
6225
6429
|
);
|
|
6226
|
-
const scopeOf = (binding) => _nullishCoalesce(binding.keyScope, () => ( (_optionalChain([binding, 'access',
|
|
6430
|
+
const scopeOf = (binding) => _nullishCoalesce(binding.keyScope, () => ( (_optionalChain([binding, 'access', _341 => _341.apiKeyIds, 'optionalAccess', _342 => _342.length]) ? "selected" : "all")));
|
|
6227
6431
|
const scoped = candidates.filter((binding) => scopeOf(binding) === "selected");
|
|
6228
6432
|
const pool = scoped.length > 0 ? scoped : candidates.filter((binding) => scopeOf(binding) === "all");
|
|
6229
6433
|
return pool.sort(
|
|
@@ -6277,7 +6481,7 @@ function syntheticBinding(request) {
|
|
|
6277
6481
|
};
|
|
6278
6482
|
}
|
|
6279
6483
|
function transformerRegistered(llmConfig, name) {
|
|
6280
|
-
return Boolean(_optionalChain([llmConfig, 'access',
|
|
6484
|
+
return Boolean(_optionalChain([llmConfig, 'access', _343 => _343.getTransformerService, 'call', _344 => _344(), 'optionalAccess', _345 => _345.getTransformer, 'call', _346 => _346(name)]));
|
|
6281
6485
|
}
|
|
6282
6486
|
var RouteLeaseTargetResolver = class {
|
|
6283
6487
|
constructor(llmConfig, options = {}) {
|
|
@@ -6291,12 +6495,12 @@ var RouteLeaseTargetResolver = class {
|
|
|
6291
6495
|
await this.preflightTarget(request);
|
|
6292
6496
|
const binding = syntheticBinding(request);
|
|
6293
6497
|
const config = gatewayBindingToEndpointConfig(binding, request.model);
|
|
6294
|
-
const result = await
|
|
6498
|
+
const result = await _chunkJGRNVH7Ccjs.resolveRoute.call(void 0, {
|
|
6295
6499
|
config,
|
|
6296
6500
|
ingressFormat: runtime.ingressFormat,
|
|
6297
6501
|
llmConfig: this.llmConfig,
|
|
6298
6502
|
requestedModel: request.model,
|
|
6299
|
-
sessionId: _nullishCoalesce(_optionalChain([request, 'access',
|
|
6503
|
+
sessionId: _nullishCoalesce(_optionalChain([request, 'access', _347 => _347.execution, 'optionalAccess', _348 => _348.sessionIdHash]), () => ( null))
|
|
6300
6504
|
});
|
|
6301
6505
|
if (!result.ok) {
|
|
6302
6506
|
throw new RouteLeaseError(
|
|
@@ -6319,7 +6523,7 @@ var RouteLeaseTargetResolver = class {
|
|
|
6319
6523
|
throw new RouteLeaseError("model_not_configured", "model is not configured for the provider");
|
|
6320
6524
|
}
|
|
6321
6525
|
if (target.keyId) {
|
|
6322
|
-
const availability = await _optionalChain([this, 'access',
|
|
6526
|
+
const availability = await _optionalChain([this, 'access', _349 => _349.options, 'access', _350 => _350.providerKeys, 'optionalAccess', _351 => _351.getKeyAvailability, 'optionalCall', _352 => _352(
|
|
6323
6527
|
target.providerId,
|
|
6324
6528
|
target.keyId
|
|
6325
6529
|
)]);
|
|
@@ -6332,9 +6536,9 @@ var RouteLeaseTargetResolver = class {
|
|
|
6332
6536
|
}
|
|
6333
6537
|
} else {
|
|
6334
6538
|
const directKey = resolveEnvKey(provider.api_key);
|
|
6335
|
-
const poolAvailability = await _optionalChain([this, 'access',
|
|
6539
|
+
const poolAvailability = await _optionalChain([this, 'access', _353 => _353.options, 'access', _354 => _354.providerKeys, 'optionalAccess', _355 => _355.getPoolAvailability, 'optionalCall', _356 => _356(target.providerId)]);
|
|
6336
6540
|
const poolReady = poolAvailability ? poolAvailability.outcome === "usable" : this.options.providerKeys ? await this.options.providerKeys.hasUsableKeys(target.providerId) : false;
|
|
6337
|
-
if (!directKey && _optionalChain([poolAvailability, 'optionalAccess',
|
|
6541
|
+
if (!directKey && _optionalChain([poolAvailability, 'optionalAccess', _357 => _357.outcome]) === "exhausted") {
|
|
6338
6542
|
throw new RouteLeaseError("upstream_exhausted", "provider key pool is temporarily exhausted", {
|
|
6339
6543
|
retryAfterSeconds: poolAvailability.retryAfterSeconds
|
|
6340
6544
|
});
|
|
@@ -6358,14 +6562,14 @@ var RouteLeaseTargetResolver = class {
|
|
|
6358
6562
|
}
|
|
6359
6563
|
async preflightSubscription(target, model) {
|
|
6360
6564
|
const registry = _chunkQBZJ7P2Tcjs.getSubscriptionRegistryForOutbound.call(void 0, );
|
|
6361
|
-
const profile = _nullishCoalesce(_optionalChain([registry, 'optionalAccess',
|
|
6565
|
+
const profile = _nullishCoalesce(_optionalChain([registry, 'optionalAccess', _358 => _358.getProfile, 'call', _359 => _359(target.providerId)]), () => ( null));
|
|
6362
6566
|
if (!profile) throw new RouteLeaseError("upstream_not_found", "subscription provider was not found");
|
|
6363
|
-
await _optionalChain([this, 'access',
|
|
6364
|
-
const names = _nullishCoalesce(_nullishCoalesce(_optionalChain([profile, 'access',
|
|
6567
|
+
await _optionalChain([this, 'access', _360 => _360.options, 'access', _361 => _361.subscriptions, 'optionalAccess', _362 => _362.assertAvailable, 'call', _363 => _363(target, model)]);
|
|
6568
|
+
const names = _nullishCoalesce(_nullishCoalesce(_optionalChain([profile, 'access', _364 => _364.resolveProviderTransformerNames, 'optionalCall', _365 => _365(model)]), () => ( profile.providerTransformerNames)), () => ( []));
|
|
6365
6569
|
if (names.some((name) => !transformerRegistered(this.llmConfig, name))) {
|
|
6366
6570
|
throw new RouteLeaseError("format_unsupported", "a required transformer is unavailable");
|
|
6367
6571
|
}
|
|
6368
|
-
if (_optionalChain([profile, 'access',
|
|
6572
|
+
if (_optionalChain([profile, 'access', _366 => _366.modelTransformerNames, 'optionalAccess', _367 => _367.some, 'call', _368 => _368((name) => !transformerRegistered(this.llmConfig, name))])) {
|
|
6369
6573
|
throw new RouteLeaseError("format_unsupported", "a required model transformer is unavailable");
|
|
6370
6574
|
}
|
|
6371
6575
|
}
|
|
@@ -6387,7 +6591,7 @@ function createResponsesCompactHandler(options = {}) {
|
|
|
6387
6591
|
const parsed = JSON.parse(rawBody);
|
|
6388
6592
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error();
|
|
6389
6593
|
body = parsed;
|
|
6390
|
-
} catch (
|
|
6594
|
+
} catch (e48) {
|
|
6391
6595
|
throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({
|
|
6392
6596
|
status: 400,
|
|
6393
6597
|
code: "invalid_request_body",
|
|
@@ -6478,7 +6682,7 @@ var BoundedSseFrameDecoder = class {
|
|
|
6478
6682
|
let decoded;
|
|
6479
6683
|
try {
|
|
6480
6684
|
decoded = this.#decoder.decode(chunk, { stream: true });
|
|
6481
|
-
} catch (
|
|
6685
|
+
} catch (e49) {
|
|
6482
6686
|
protocolFailure2();
|
|
6483
6687
|
}
|
|
6484
6688
|
return this.#append(decoded, false);
|
|
@@ -6487,7 +6691,7 @@ var BoundedSseFrameDecoder = class {
|
|
|
6487
6691
|
let tail;
|
|
6488
6692
|
try {
|
|
6489
6693
|
tail = this.#decoder.decode();
|
|
6490
|
-
} catch (
|
|
6694
|
+
} catch (e50) {
|
|
6491
6695
|
protocolFailure2();
|
|
6492
6696
|
}
|
|
6493
6697
|
const frames = this.#append(tail, true);
|
|
@@ -6617,7 +6821,7 @@ var HostedImageSsePipeline = class {
|
|
|
6617
6821
|
if (this.#cancelPromise) return this.#cancelPromise;
|
|
6618
6822
|
this.#cancelled = true;
|
|
6619
6823
|
this.#cancelPromise = Promise.allSettled([
|
|
6620
|
-
_nullishCoalesce(_optionalChain([this, 'access',
|
|
6824
|
+
_nullishCoalesce(_optionalChain([this, 'access', _369 => _369.#reader, 'optionalAccess', _370 => _370.cancel, 'call', _371 => _371(reason)]), () => ( Promise.resolve())),
|
|
6621
6825
|
this.#closeActiveImageIterator(),
|
|
6622
6826
|
this.#options.onCancel()
|
|
6623
6827
|
]).then(() => void 0);
|
|
@@ -6631,7 +6835,7 @@ var HostedImageSsePipeline = class {
|
|
|
6631
6835
|
let parsed;
|
|
6632
6836
|
try {
|
|
6633
6837
|
parsed = JSON.parse(frame2.data);
|
|
6634
|
-
} catch (
|
|
6838
|
+
} catch (e51) {
|
|
6635
6839
|
protocolFailure2();
|
|
6636
6840
|
}
|
|
6637
6841
|
if (!isRecord8(parsed) || typeof parsed.type !== "string" || parsed.type.length > 256) {
|
|
@@ -6988,7 +7192,7 @@ data: ${JSON.stringify(event)}
|
|
|
6988
7192
|
#closeActiveImageIterator() {
|
|
6989
7193
|
if (this.#activeImageIteratorClose) return this.#activeImageIteratorClose;
|
|
6990
7194
|
const iterator = this.#activeImageIterator;
|
|
6991
|
-
if (!_optionalChain([iterator, 'optionalAccess',
|
|
7195
|
+
if (!_optionalChain([iterator, 'optionalAccess', _372 => _372.return])) return Promise.resolve();
|
|
6992
7196
|
this.#activeImageIteratorClose = Promise.resolve(iterator.return()).then(
|
|
6993
7197
|
() => void 0,
|
|
6994
7198
|
() => void 0
|
|
@@ -7025,7 +7229,7 @@ function createNativeResponsesHostedImageSseResponse(options) {
|
|
|
7025
7229
|
},
|
|
7026
7230
|
async cancel(reason) {
|
|
7027
7231
|
await pipeline.cancel(reason);
|
|
7028
|
-
await _optionalChain([iterator, 'access',
|
|
7232
|
+
await _optionalChain([iterator, 'access', _373 => _373.return, 'optionalCall', _374 => _374()]);
|
|
7029
7233
|
}
|
|
7030
7234
|
});
|
|
7031
7235
|
return transformedResponse(options.upstream, body);
|
|
@@ -7097,7 +7301,7 @@ function parseJsonObject(bytes) {
|
|
|
7097
7301
|
let text;
|
|
7098
7302
|
try {
|
|
7099
7303
|
text = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
7100
|
-
} catch (
|
|
7304
|
+
} catch (e52) {
|
|
7101
7305
|
protocolFailure3();
|
|
7102
7306
|
}
|
|
7103
7307
|
try {
|
|
@@ -7270,7 +7474,7 @@ var NativeResponsesHostedImageRequestLease = class {
|
|
|
7270
7474
|
#wrapSse(input) {
|
|
7271
7475
|
const status = _nullishCoalesce(input.rawStatus, () => ( input.response.status));
|
|
7272
7476
|
if (status < 200 || status >= 300) return input.response;
|
|
7273
|
-
const hasInheritedContext = _optionalChain([this, 'access',
|
|
7477
|
+
const hasInheritedContext = _optionalChain([this, 'access', _375 => _375.#input, 'access', _376 => _376.previousHostedImageState, 'optionalAccess', _377 => _377.hasImageContext]) === true;
|
|
7274
7478
|
return createNativeResponsesHostedImageSseResponse({
|
|
7275
7479
|
upstream: input.response,
|
|
7276
7480
|
signal: this.#input.signal,
|
|
@@ -7296,7 +7500,7 @@ var NativeResponsesHostedImageRequestLease = class {
|
|
|
7296
7500
|
signal: this.#input.signal,
|
|
7297
7501
|
...this.#input.authorizedPreviousResponseId ? {
|
|
7298
7502
|
authorizedPreviousResponseId: this.#input.authorizedPreviousResponseId,
|
|
7299
|
-
authorizedPreviousResponseKnownEmpty: _optionalChain([this, 'access',
|
|
7503
|
+
authorizedPreviousResponseKnownEmpty: _optionalChain([this, 'access', _378 => _378.#input, 'access', _379 => _379.previousHostedImageState, 'optionalAccess', _380 => _380.hasImageContext]) !== true
|
|
7300
7504
|
} : {},
|
|
7301
7505
|
mainProviderId: this.#input.mainProviderId,
|
|
7302
7506
|
...input.selectedMainAccountId ? { selectedMainAccountId: input.selectedMainAccountId } : {}
|
|
@@ -7331,7 +7535,7 @@ var NativeResponsesHostedImageRequestLease = class {
|
|
|
7331
7535
|
if (!UPSTREAM_CALL_ID_PATTERN4.test(selected.upstreamCallId)) protocolFailure3();
|
|
7332
7536
|
}
|
|
7333
7537
|
this.#runtime.validateSelection(this.#admission, parsedSelection.selection);
|
|
7334
|
-
const hasInheritedContext = _optionalChain([this, 'access',
|
|
7538
|
+
const hasInheritedContext = _optionalChain([this, 'access', _381 => _381.#input, 'access', _382 => _382.previousHostedImageState, 'optionalAccess', _383 => _383.hasImageContext]) === true;
|
|
7335
7539
|
const requiresScope = parsedSelection.imageCalls.length > 0 || hasInheritedContext || this.#admission.explicitCallIds.length > 0;
|
|
7336
7540
|
const publicOutput = [...upstreamBody.output];
|
|
7337
7541
|
const pendingReceipts = [];
|
|
@@ -7348,7 +7552,7 @@ var NativeResponsesHostedImageRequestLease = class {
|
|
|
7348
7552
|
signal: this.#input.signal,
|
|
7349
7553
|
...this.#input.authorizedPreviousResponseId ? {
|
|
7350
7554
|
authorizedPreviousResponseId: this.#input.authorizedPreviousResponseId,
|
|
7351
|
-
authorizedPreviousResponseKnownEmpty: _optionalChain([this, 'access',
|
|
7555
|
+
authorizedPreviousResponseKnownEmpty: _optionalChain([this, 'access', _384 => _384.#input, 'access', _385 => _385.previousHostedImageState, 'optionalAccess', _386 => _386.hasImageContext]) !== true
|
|
7352
7556
|
} : {},
|
|
7353
7557
|
mainProviderId: this.#input.mainProviderId,
|
|
7354
7558
|
...input.selectedMainAccountId ? { selectedMainAccountId: input.selectedMainAccountId } : {}
|
|
@@ -7394,7 +7598,7 @@ function createNativeResponsesHostedImageIngress(runtimeFactory, options = {}) {
|
|
|
7394
7598
|
const createRequestId = _nullishCoalesce(options.createRequestId, () => ( (() => `hosted-image-${_crypto.randomUUID.call(void 0, )}`)));
|
|
7395
7599
|
return Object.freeze({
|
|
7396
7600
|
prepare: async (input) => {
|
|
7397
|
-
if (input.operation !== "create" || input.profile !== "native" || !hasImageOwnedResponsesInput(input.body) && !_optionalChain([input, 'access',
|
|
7601
|
+
if (input.operation !== "create" || input.profile !== "native" || !hasImageOwnedResponsesInput(input.body) && !_optionalChain([input, 'access', _387 => _387.previousHostedImageState, 'optionalAccess', _388 => _388.hasImageContext]) && !_optionalChain([input, 'access', _389 => _389.previousHostedImageState, 'optionalAccess', _390 => _390.pendingReceipts, 'access', _391 => _391.length])) {
|
|
7398
7602
|
return null;
|
|
7399
7603
|
}
|
|
7400
7604
|
if (!input.hostedImageGenerationAllowed) {
|
|
@@ -7427,7 +7631,7 @@ function createNativeResponsesHostedImageIngress(runtimeFactory, options = {}) {
|
|
|
7427
7631
|
const selection = prepareNativeResponsesImageSelection({
|
|
7428
7632
|
body: input.body,
|
|
7429
7633
|
admission,
|
|
7430
|
-
pendingReceipts: _optionalChain([input, 'access',
|
|
7634
|
+
pendingReceipts: _optionalChain([input, 'access', _392 => _392.previousHostedImageState, 'optionalAccess', _393 => _393.pendingReceipts]),
|
|
7431
7635
|
...options.createSelectorName ? { createSelectorName: options.createSelectorName } : {}
|
|
7432
7636
|
});
|
|
7433
7637
|
return new NativeResponsesHostedImageRequestLease({
|
|
@@ -8086,9 +8290,9 @@ function stringList(value, cap) {
|
|
|
8086
8290
|
}
|
|
8087
8291
|
function tavilyConfig(value) {
|
|
8088
8292
|
const raw = record4(value);
|
|
8089
|
-
const apiKey = configString(_optionalChain([raw, 'optionalAccess',
|
|
8293
|
+
const apiKey = configString(_optionalChain([raw, 'optionalAccess', _394 => _394["apiKey"]]));
|
|
8090
8294
|
if (!apiKey) return void 0;
|
|
8091
|
-
const apiHost = configString(_optionalChain([raw, 'optionalAccess',
|
|
8295
|
+
const apiHost = configString(_optionalChain([raw, 'optionalAccess', _395 => _395["apiHost"]]));
|
|
8092
8296
|
return { apiKey, ...apiHost ? { apiHost } : {} };
|
|
8093
8297
|
}
|
|
8094
8298
|
function jinaConfig(value) {
|
|
@@ -8100,10 +8304,10 @@ function jinaConfig(value) {
|
|
|
8100
8304
|
}
|
|
8101
8305
|
function searxngConfig(value) {
|
|
8102
8306
|
const raw = record4(value);
|
|
8103
|
-
const apiHost = configString(_optionalChain([raw, 'optionalAccess',
|
|
8307
|
+
const apiHost = configString(_optionalChain([raw, 'optionalAccess', _396 => _396["apiHost"]]));
|
|
8104
8308
|
if (!apiHost) return void 0;
|
|
8105
|
-
const basicAuthUsername = configString(_optionalChain([raw, 'optionalAccess',
|
|
8106
|
-
const basicAuthPassword = configString(_optionalChain([raw, 'optionalAccess',
|
|
8309
|
+
const basicAuthUsername = configString(_optionalChain([raw, 'optionalAccess', _397 => _397["basicAuthUsername"]]));
|
|
8310
|
+
const basicAuthPassword = configString(_optionalChain([raw, 'optionalAccess', _398 => _398["basicAuthPassword"]]));
|
|
8107
8311
|
return {
|
|
8108
8312
|
apiHost,
|
|
8109
8313
|
...basicAuthUsername ? { basicAuthUsername } : {},
|
|
@@ -8112,9 +8316,9 @@ function searxngConfig(value) {
|
|
|
8112
8316
|
}
|
|
8113
8317
|
function zhipuConfig(value) {
|
|
8114
8318
|
const raw = record4(value);
|
|
8115
|
-
const apiKey = configString(_optionalChain([raw, 'optionalAccess',
|
|
8319
|
+
const apiKey = configString(_optionalChain([raw, 'optionalAccess', _399 => _399["apiKey"]]));
|
|
8116
8320
|
if (!apiKey) return void 0;
|
|
8117
|
-
const apiHost = configString(_optionalChain([raw, 'optionalAccess',
|
|
8321
|
+
const apiHost = configString(_optionalChain([raw, 'optionalAccess', _400 => _400["apiHost"]]));
|
|
8118
8322
|
return { apiKey, ...apiHost ? { apiHost } : {} };
|
|
8119
8323
|
}
|
|
8120
8324
|
function normalizeSearchApiProviderConfigs(value) {
|
|
@@ -8266,11 +8470,11 @@ var DEFAULT_ACCOUNT_HEALTH = {
|
|
|
8266
8470
|
overloadCooldownMs: 10 * 6e4
|
|
8267
8471
|
};
|
|
8268
8472
|
function normalizeAccountHealth(raw) {
|
|
8269
|
-
const ah = _optionalChain([raw, 'optionalAccess',
|
|
8473
|
+
const ah = _optionalChain([raw, 'optionalAccess', _401 => _401.accountHealth]);
|
|
8270
8474
|
return {
|
|
8271
|
-
overloadCooldownEnabled: _optionalChain([ah, 'optionalAccess',
|
|
8475
|
+
overloadCooldownEnabled: _optionalChain([ah, 'optionalAccess', _402 => _402.overloadCooldownEnabled]) !== false,
|
|
8272
8476
|
overloadCooldownMs: clampNumber(
|
|
8273
|
-
_optionalChain([ah, 'optionalAccess',
|
|
8477
|
+
_optionalChain([ah, 'optionalAccess', _403 => _403.overloadCooldownMs]),
|
|
8274
8478
|
6e4,
|
|
8275
8479
|
36e5,
|
|
8276
8480
|
DEFAULT_ACCOUNT_HEALTH.overloadCooldownMs
|
|
@@ -8292,25 +8496,25 @@ var DEFAULT_ALLOWANCE_SCHEDULING = {
|
|
|
8292
8496
|
priorityPenalty: 100
|
|
8293
8497
|
};
|
|
8294
8498
|
function normalizeAllowanceScheduling(raw) {
|
|
8295
|
-
const value = _optionalChain([raw, 'optionalAccess',
|
|
8499
|
+
const value = _optionalChain([raw, 'optionalAccess', _404 => _404.allowanceScheduling]);
|
|
8296
8500
|
const demoteAtPercent = clampNumber(
|
|
8297
|
-
_optionalChain([value, 'optionalAccess',
|
|
8501
|
+
_optionalChain([value, 'optionalAccess', _405 => _405.demoteAtPercent]),
|
|
8298
8502
|
0,
|
|
8299
8503
|
100,
|
|
8300
8504
|
DEFAULT_ALLOWANCE_SCHEDULING.demoteAtPercent
|
|
8301
8505
|
);
|
|
8302
8506
|
const requestedPause = clampNumber(
|
|
8303
|
-
_optionalChain([value, 'optionalAccess',
|
|
8507
|
+
_optionalChain([value, 'optionalAccess', _406 => _406.pauseAtPercent]),
|
|
8304
8508
|
0,
|
|
8305
8509
|
100,
|
|
8306
8510
|
DEFAULT_ALLOWANCE_SCHEDULING.pauseAtPercent
|
|
8307
8511
|
);
|
|
8308
8512
|
return {
|
|
8309
|
-
enabled: _optionalChain([value, 'optionalAccess',
|
|
8513
|
+
enabled: _optionalChain([value, 'optionalAccess', _407 => _407.enabled]) === true,
|
|
8310
8514
|
demoteAtPercent,
|
|
8311
8515
|
pauseAtPercent: Math.max(demoteAtPercent, requestedPause),
|
|
8312
8516
|
priorityPenalty: Math.trunc(clampNumber(
|
|
8313
|
-
_optionalChain([value, 'optionalAccess',
|
|
8517
|
+
_optionalChain([value, 'optionalAccess', _408 => _408.priorityPenalty]),
|
|
8314
8518
|
1,
|
|
8315
8519
|
1e3,
|
|
8316
8520
|
DEFAULT_ALLOWANCE_SCHEDULING.priorityPenalty
|
|
@@ -8318,29 +8522,29 @@ function normalizeAllowanceScheduling(raw) {
|
|
|
8318
8522
|
};
|
|
8319
8523
|
}
|
|
8320
8524
|
function normalizeAccountProbe(raw) {
|
|
8321
|
-
const ap = _optionalChain([raw, 'optionalAccess',
|
|
8525
|
+
const ap = _optionalChain([raw, 'optionalAccess', _409 => _409.accountProbe]);
|
|
8322
8526
|
return {
|
|
8323
|
-
enabled: _optionalChain([ap, 'optionalAccess',
|
|
8324
|
-
intervalMs: clampNumber(_optionalChain([ap, 'optionalAccess',
|
|
8325
|
-
onlyMultiAccount: _optionalChain([ap, 'optionalAccess',
|
|
8326
|
-
timeoutMs: clampNumber(_optionalChain([ap, 'optionalAccess',
|
|
8527
|
+
enabled: _optionalChain([ap, 'optionalAccess', _410 => _410.enabled]) === true,
|
|
8528
|
+
intervalMs: clampNumber(_optionalChain([ap, 'optionalAccess', _411 => _411.intervalMs]), 6e4, 864e5, DEFAULT_ACCOUNT_PROBE.intervalMs),
|
|
8529
|
+
onlyMultiAccount: _optionalChain([ap, 'optionalAccess', _412 => _412.onlyMultiAccount]) !== false,
|
|
8530
|
+
timeoutMs: clampNumber(_optionalChain([ap, 'optionalAccess', _413 => _413.timeoutMs]), 1e3, 6e4, DEFAULT_ACCOUNT_PROBE.timeoutMs),
|
|
8327
8531
|
historySize: Math.trunc(
|
|
8328
|
-
clampNumber(_optionalChain([ap, 'optionalAccess',
|
|
8532
|
+
clampNumber(_optionalChain([ap, 'optionalAccess', _414 => _414.historySize]), 1, 200, DEFAULT_ACCOUNT_PROBE.historySize)
|
|
8329
8533
|
),
|
|
8330
|
-
staggerMs: clampNumber(_optionalChain([ap, 'optionalAccess',
|
|
8534
|
+
staggerMs: clampNumber(_optionalChain([ap, 'optionalAccess', _415 => _415.staggerMs]), 0, 6e4, DEFAULT_ACCOUNT_PROBE.staggerMs)
|
|
8331
8535
|
};
|
|
8332
8536
|
}
|
|
8333
8537
|
function normalizeAudit(raw) {
|
|
8334
|
-
const a = _optionalChain([raw, 'optionalAccess',
|
|
8538
|
+
const a = _optionalChain([raw, 'optionalAccess', _416 => _416.audit]);
|
|
8335
8539
|
return {
|
|
8336
|
-
enabled: _optionalChain([a, 'optionalAccess',
|
|
8337
|
-
captureBodies: _optionalChain([a, 'optionalAccess',
|
|
8338
|
-
maxBodyBytes: normalizeMaxBodyBytes(_optionalChain([a, 'optionalAccess',
|
|
8540
|
+
enabled: _optionalChain([a, 'optionalAccess', _417 => _417.enabled]) === true,
|
|
8541
|
+
captureBodies: _optionalChain([a, 'optionalAccess', _418 => _418.captureBodies]) === true,
|
|
8542
|
+
maxBodyBytes: normalizeMaxBodyBytes(_optionalChain([a, 'optionalAccess', _419 => _419.maxBodyBytes])),
|
|
8339
8543
|
retentionDays: Math.trunc(
|
|
8340
|
-
clampNumber(_optionalChain([a, 'optionalAccess',
|
|
8544
|
+
clampNumber(_optionalChain([a, 'optionalAccess', _420 => _420.retentionDays]), 1, 365, _audittypes.DEFAULT_AUDIT_CONFIG.retentionDays)
|
|
8341
8545
|
),
|
|
8342
|
-
compactStreamingBodies: _optionalChain([a, 'optionalAccess',
|
|
8343
|
-
trustForwardedFor: _optionalChain([a, 'optionalAccess',
|
|
8546
|
+
compactStreamingBodies: _optionalChain([a, 'optionalAccess', _421 => _421.compactStreamingBodies]) === true,
|
|
8547
|
+
trustForwardedFor: _optionalChain([a, 'optionalAccess', _422 => _422.trustForwardedFor]) === true
|
|
8344
8548
|
};
|
|
8345
8549
|
}
|
|
8346
8550
|
function normalizeMaxBodyBytes(value) {
|
|
@@ -8351,26 +8555,26 @@ function normalizeMaxBodyBytes(value) {
|
|
|
8351
8555
|
return Math.trunc(Math.min(1048576, value));
|
|
8352
8556
|
}
|
|
8353
8557
|
function normalizeBilling(raw) {
|
|
8354
|
-
const b = _optionalChain([raw, 'optionalAccess',
|
|
8558
|
+
const b = _optionalChain([raw, 'optionalAccess', _423 => _423.billing]);
|
|
8355
8559
|
const config = {
|
|
8356
|
-
enabled: _optionalChain([b, 'optionalAccess',
|
|
8560
|
+
enabled: _optionalChain([b, 'optionalAccess', _424 => _424.enabled]) === true,
|
|
8357
8561
|
maxRetryAgeMs: Math.trunc(
|
|
8358
|
-
clampNumber(_optionalChain([b, 'optionalAccess',
|
|
8562
|
+
clampNumber(_optionalChain([b, 'optionalAccess', _425 => _425.maxRetryAgeMs]), 6e4, 2592e6, _billingtypes.DEFAULT_BILLING_CONFIG.maxRetryAgeMs)
|
|
8359
8563
|
)
|
|
8360
8564
|
};
|
|
8361
|
-
if (typeof _optionalChain([b, 'optionalAccess',
|
|
8362
|
-
if (typeof _optionalChain([b, 'optionalAccess',
|
|
8565
|
+
if (typeof _optionalChain([b, 'optionalAccess', _426 => _426.endpoint]) === "string" && b.endpoint.trim()) config.endpoint = b.endpoint.trim();
|
|
8566
|
+
if (typeof _optionalChain([b, 'optionalAccess', _427 => _427.secret]) === "string" && b.secret.length > 0) config.secret = b.secret;
|
|
8363
8567
|
return config;
|
|
8364
8568
|
}
|
|
8365
8569
|
var DEFAULT_FINGERPRINT = { enabled: false };
|
|
8366
8570
|
function normalizeFingerprint(raw) {
|
|
8367
|
-
const f = _optionalChain([raw, 'optionalAccess',
|
|
8368
|
-
const out = { enabled: _optionalChain([f, 'optionalAccess',
|
|
8369
|
-
if (typeof _optionalChain([f, 'optionalAccess',
|
|
8571
|
+
const f = _optionalChain([raw, 'optionalAccess', _428 => _428.fingerprint]);
|
|
8572
|
+
const out = { enabled: _optionalChain([f, 'optionalAccess', _429 => _429.enabled]) === true };
|
|
8573
|
+
if (typeof _optionalChain([f, 'optionalAccess', _430 => _430.ua]) === "string" && f.ua.trim().length > 0) out.ua = f.ua.trim();
|
|
8370
8574
|
return out;
|
|
8371
8575
|
}
|
|
8372
8576
|
function normalizeVoucher(raw) {
|
|
8373
|
-
return { enabled: _optionalChain([raw, 'optionalAccess',
|
|
8577
|
+
return { enabled: _optionalChain([raw, 'optionalAccess', _431 => _431.voucher, 'optionalAccess', _432 => _432.enabled]) === true };
|
|
8374
8578
|
}
|
|
8375
8579
|
var DEFAULT_ANTHROPIC_SEGMENT = {
|
|
8376
8580
|
countTokens: { mode: "auto", estimateBudgetMs: 2e3 },
|
|
@@ -8383,34 +8587,34 @@ var DEFAULT_ANTHROPIC_SEGMENT = {
|
|
|
8383
8587
|
var COUNT_TOKENS_MODES = ["auto", "passthrough", "estimate", "reject"];
|
|
8384
8588
|
var MODELS_SHAPES = ["auto", "anthropic", "openai"];
|
|
8385
8589
|
function normalizeAnthropicSegment(raw) {
|
|
8386
|
-
const a = _optionalChain([raw, 'optionalAccess',
|
|
8590
|
+
const a = _optionalChain([raw, 'optionalAccess', _433 => _433.anthropic]);
|
|
8387
8591
|
return {
|
|
8388
8592
|
countTokens: {
|
|
8389
|
-
mode: COUNT_TOKENS_MODES.includes(String(_optionalChain([a, 'optionalAccess',
|
|
8593
|
+
mode: COUNT_TOKENS_MODES.includes(String(_optionalChain([a, 'optionalAccess', _434 => _434.countTokens, 'optionalAccess', _435 => _435.mode]))) ? _optionalChain([a, 'optionalAccess', _436 => _436.countTokens, 'optionalAccess', _437 => _437.mode]) : DEFAULT_ANTHROPIC_SEGMENT.countTokens.mode,
|
|
8390
8594
|
estimateBudgetMs: clampNumber(
|
|
8391
|
-
_optionalChain([a, 'optionalAccess',
|
|
8595
|
+
_optionalChain([a, 'optionalAccess', _438 => _438.countTokens, 'optionalAccess', _439 => _439.estimateBudgetMs]),
|
|
8392
8596
|
100,
|
|
8393
8597
|
6e4,
|
|
8394
8598
|
DEFAULT_ANTHROPIC_SEGMENT.countTokens.estimateBudgetMs
|
|
8395
8599
|
)
|
|
8396
8600
|
},
|
|
8397
|
-
modelsShape: MODELS_SHAPES.includes(String(_optionalChain([a, 'optionalAccess',
|
|
8601
|
+
modelsShape: MODELS_SHAPES.includes(String(_optionalChain([a, 'optionalAccess', _440 => _440.modelsShape]))) ? _optionalChain([a, 'optionalAccess', _441 => _441.modelsShape]) : DEFAULT_ANTHROPIC_SEGMENT.modelsShape,
|
|
8398
8602
|
heartbeatIntervalMs: clampNumber(
|
|
8399
|
-
_optionalChain([a, 'optionalAccess',
|
|
8603
|
+
_optionalChain([a, 'optionalAccess', _442 => _442.heartbeatIntervalMs]),
|
|
8400
8604
|
0,
|
|
8401
8605
|
6e5,
|
|
8402
8606
|
DEFAULT_ANTHROPIC_SEGMENT.heartbeatIntervalMs
|
|
8403
8607
|
),
|
|
8404
8608
|
pdfTextExtraction: {
|
|
8405
8609
|
budgetMs: clampNumber(
|
|
8406
|
-
_optionalChain([a, 'optionalAccess',
|
|
8610
|
+
_optionalChain([a, 'optionalAccess', _443 => _443.pdfTextExtraction, 'optionalAccess', _444 => _444.budgetMs]),
|
|
8407
8611
|
100,
|
|
8408
8612
|
6e4,
|
|
8409
8613
|
DEFAULT_ANTHROPIC_SEGMENT.pdfTextExtraction.budgetMs
|
|
8410
8614
|
)
|
|
8411
8615
|
},
|
|
8412
|
-
proxyOauthUsage: _optionalChain([a, 'optionalAccess',
|
|
8413
|
-
apiHello: _optionalChain([a, 'optionalAccess',
|
|
8616
|
+
proxyOauthUsage: _optionalChain([a, 'optionalAccess', _445 => _445.proxyOauthUsage]) === true,
|
|
8617
|
+
apiHello: _optionalChain([a, 'optionalAccess', _446 => _446.apiHello]) !== false
|
|
8414
8618
|
};
|
|
8415
8619
|
}
|
|
8416
8620
|
var PROXY_TYPES = ["http", "https", "socks5"];
|
|
@@ -8495,14 +8699,14 @@ function clampNumber(value, min, max, fallback) {
|
|
|
8495
8699
|
return Math.min(max, Math.max(min, n));
|
|
8496
8700
|
}
|
|
8497
8701
|
function normalizeQueueSegments(raw) {
|
|
8498
|
-
const umq = _optionalChain([raw, 'optionalAccess',
|
|
8499
|
-
const cq = _optionalChain([raw, 'optionalAccess',
|
|
8702
|
+
const umq = _optionalChain([raw, 'optionalAccess', _447 => _447.userMessageQueue]);
|
|
8703
|
+
const cq = _optionalChain([raw, 'optionalAccess', _448 => _448.concurrencyQueue]);
|
|
8500
8704
|
return {
|
|
8501
8705
|
userMessageQueue: {
|
|
8502
|
-
enabled: _optionalChain([umq, 'optionalAccess',
|
|
8503
|
-
delayMs: clampNumber(_optionalChain([umq, 'optionalAccess',
|
|
8706
|
+
enabled: _optionalChain([umq, 'optionalAccess', _449 => _449.enabled]) === true,
|
|
8707
|
+
delayMs: clampNumber(_optionalChain([umq, 'optionalAccess', _450 => _450.delayMs]), 0, 1e4, DEFAULT_USER_MESSAGE_QUEUE.delayMs),
|
|
8504
8708
|
waitTimeoutMs: clampNumber(
|
|
8505
|
-
_optionalChain([umq, 'optionalAccess',
|
|
8709
|
+
_optionalChain([umq, 'optionalAccess', _451 => _451.waitTimeoutMs]),
|
|
8506
8710
|
1e3,
|
|
8507
8711
|
3e5,
|
|
8508
8712
|
DEFAULT_USER_MESSAGE_QUEUE.waitTimeoutMs
|
|
@@ -8510,14 +8714,14 @@ function normalizeQueueSegments(raw) {
|
|
|
8510
8714
|
},
|
|
8511
8715
|
concurrencyQueue: {
|
|
8512
8716
|
maxQueueSizeFactor: clampNumber(
|
|
8513
|
-
_optionalChain([cq, 'optionalAccess',
|
|
8717
|
+
_optionalChain([cq, 'optionalAccess', _452 => _452.maxQueueSizeFactor]),
|
|
8514
8718
|
1,
|
|
8515
8719
|
10,
|
|
8516
8720
|
DEFAULT_CONCURRENCY_QUEUE.maxQueueSizeFactor
|
|
8517
8721
|
),
|
|
8518
|
-
minQueueSize: clampNumber(_optionalChain([cq, 'optionalAccess',
|
|
8722
|
+
minQueueSize: clampNumber(_optionalChain([cq, 'optionalAccess', _453 => _453.minQueueSize]), 1, 100, DEFAULT_CONCURRENCY_QUEUE.minQueueSize),
|
|
8519
8723
|
waitTimeoutMs: clampNumber(
|
|
8520
|
-
_optionalChain([cq, 'optionalAccess',
|
|
8724
|
+
_optionalChain([cq, 'optionalAccess', _454 => _454.waitTimeoutMs]),
|
|
8521
8725
|
1e3,
|
|
8522
8726
|
3e5,
|
|
8523
8727
|
DEFAULT_CONCURRENCY_QUEUE.waitTimeoutMs
|
|
@@ -8528,11 +8732,11 @@ function normalizeQueueSegments(raw) {
|
|
|
8528
8732
|
var ALL_ENDPOINTS = ["chat", "responses", "messages", "gemini"];
|
|
8529
8733
|
function blankModelMap(endpoint) {
|
|
8530
8734
|
const modelMap = {};
|
|
8531
|
-
for (const kind of
|
|
8735
|
+
for (const kind of _chunkJGRNVH7Ccjs.modelKindsForEndpoint.call(void 0, endpoint)) modelMap[kind] = "";
|
|
8532
8736
|
return modelMap;
|
|
8533
8737
|
}
|
|
8534
8738
|
function defaultEndpointConfig(endpoint) {
|
|
8535
|
-
if (
|
|
8739
|
+
if (_chunkJGRNVH7Ccjs.isKindMappedEndpoint.call(void 0, endpoint)) {
|
|
8536
8740
|
return { endpoint, modelMap: blankModelMap(endpoint), useSubscription: false };
|
|
8537
8741
|
}
|
|
8538
8742
|
if (endpoint === "chat") {
|
|
@@ -8562,10 +8766,10 @@ function normalizeEndpointConfig(e) {
|
|
|
8562
8766
|
const boundAccountFallbackPolicy = boundAccountId ? e.boundAccountFallbackPolicy === "pool" ? "pool" : "strict" : void 0;
|
|
8563
8767
|
const boundKeyId = typeof e.boundKeyId === "string" && e.boundKeyId.trim() !== "" ? e.boundKeyId : void 0;
|
|
8564
8768
|
let config;
|
|
8565
|
-
if (
|
|
8769
|
+
if (_chunkJGRNVH7Ccjs.isKindMappedEndpoint.call(void 0, endpoint)) {
|
|
8566
8770
|
const rawMap = e.modelMap && typeof e.modelMap === "object" ? e.modelMap : {};
|
|
8567
8771
|
const modelMap = {};
|
|
8568
|
-
for (const kind of
|
|
8772
|
+
for (const kind of _chunkJGRNVH7Ccjs.modelKindsForEndpoint.call(void 0, endpoint)) {
|
|
8569
8773
|
const v = rawMap[kind];
|
|
8570
8774
|
modelMap[kind] = typeof v === "string" ? v : "";
|
|
8571
8775
|
}
|
|
@@ -8633,7 +8837,7 @@ function normalizeGatewayModelMappings(raw) {
|
|
|
8633
8837
|
return mappings;
|
|
8634
8838
|
}
|
|
8635
8839
|
function hasConfiguredLegacyModels(config) {
|
|
8636
|
-
return Object.values(_nullishCoalesce(config.modelMap, () => ( {}))).some((value) => typeof value === "string" && value.trim()) || Boolean(_optionalChain([config, 'access',
|
|
8840
|
+
return Object.values(_nullishCoalesce(config.modelMap, () => ( {}))).some((value) => typeof value === "string" && value.trim()) || Boolean(_optionalChain([config, 'access', _455 => _455.models, 'optionalAccess', _456 => _456.some, 'call', _457 => _457((value) => typeof value === "string" && value.trim())])) || Boolean(_optionalChain([config, 'access', _458 => _458.defaultModel, 'optionalAccess', _459 => _459.trim, 'call', _460 => _460()])) || Boolean(_optionalChain([config, 'access', _461 => _461.backgroundModel, 'optionalAccess', _462 => _462.trim, 'call', _463 => _463()])) || Boolean(Object.values(_nullishCoalesce(config.prefixTargets, () => ( {}))).some((value) => _optionalChain([value, 'optionalAccess', _464 => _464.trim, 'call', _465 => _465()])));
|
|
8637
8841
|
}
|
|
8638
8842
|
function splitModelRef(ref) {
|
|
8639
8843
|
if (typeof ref !== "string") return null;
|
|
@@ -8701,7 +8905,7 @@ function legacyEndpointToBindings(config) {
|
|
|
8701
8905
|
if (!parsed) continue;
|
|
8702
8906
|
const route = routeFor(parsed.providerId);
|
|
8703
8907
|
route[field] = ref;
|
|
8704
|
-
if (_optionalChain([config, 'access',
|
|
8908
|
+
if (_optionalChain([config, 'access', _466 => _466.backgroundModelIds, 'optionalAccess', _467 => _467.length])) {
|
|
8705
8909
|
route.backgroundModelIds = [...config.backgroundModelIds];
|
|
8706
8910
|
}
|
|
8707
8911
|
}
|
|
@@ -8884,10 +9088,10 @@ function asObject(value) {
|
|
|
8884
9088
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
8885
9089
|
}
|
|
8886
9090
|
function anthropicSessionId(body) {
|
|
8887
|
-
const userId = _optionalChain([asObject, 'call',
|
|
9091
|
+
const userId = _optionalChain([asObject, 'call', _468 => _468(body["metadata"]), 'optionalAccess', _469 => _469["user_id"]]);
|
|
8888
9092
|
if (typeof userId !== "string" || !userId) return void 0;
|
|
8889
9093
|
const matched = ANTHROPIC_SESSION_RE.exec(userId);
|
|
8890
|
-
return _optionalChain([matched, 'optionalAccess',
|
|
9094
|
+
return _optionalChain([matched, 'optionalAccess', _470 => _470[1]]);
|
|
8891
9095
|
}
|
|
8892
9096
|
function anthropicContentFingerprint(body) {
|
|
8893
9097
|
const messages = body["messages"];
|
|
@@ -9120,7 +9324,7 @@ function effectiveOutboundPermissions(value) {
|
|
|
9120
9324
|
if (value === void 0) return LEGACY_OUTBOUND_PERMISSIONS;
|
|
9121
9325
|
try {
|
|
9122
9326
|
return validateOutboundPermissions(value);
|
|
9123
|
-
} catch (
|
|
9327
|
+
} catch (e53) {
|
|
9124
9328
|
return [];
|
|
9125
9329
|
}
|
|
9126
9330
|
}
|
|
@@ -9386,8 +9590,8 @@ var OutboundRateLimiter = (_class16 = class {
|
|
|
9386
9590
|
* recorded (no bucket growth).
|
|
9387
9591
|
*/
|
|
9388
9592
|
check(apiKeyId, now = Date.now(), override) {
|
|
9389
|
-
const maxRequests = _nullishCoalesce(_optionalChain([override, 'optionalAccess',
|
|
9390
|
-
const windowMs = _nullishCoalesce(_optionalChain([override, 'optionalAccess',
|
|
9593
|
+
const maxRequests = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _471 => _471.maxRequests]), () => ( this.maxRequests));
|
|
9594
|
+
const windowMs = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _472 => _472.windowMs]), () => ( this.windowMs));
|
|
9391
9595
|
if (maxRequests === 0) return { allowed: true, retryAfterSeconds: 0 };
|
|
9392
9596
|
const cutoff = now - windowMs;
|
|
9393
9597
|
const timestamps = (_nullishCoalesce(this.hits.get(apiKeyId), () => ( []))).filter((ts) => ts > cutoff);
|
|
@@ -9573,10 +9777,10 @@ async function handleCodexSearchRequest(req, res, deps) {
|
|
|
9573
9777
|
let parseFailed = false;
|
|
9574
9778
|
try {
|
|
9575
9779
|
parsed = raw ? JSON.parse(raw) : {};
|
|
9576
|
-
} catch (
|
|
9780
|
+
} catch (e54) {
|
|
9577
9781
|
parseFailed = true;
|
|
9578
9782
|
}
|
|
9579
|
-
_optionalChain([deps, 'access',
|
|
9783
|
+
_optionalChain([deps, 'access', _473 => _473.onRequestBody, 'optionalCall', _474 => _474(raw, isRecord10(parsed) ? parsed : {})]);
|
|
9580
9784
|
if (parseFailed) {
|
|
9581
9785
|
throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({
|
|
9582
9786
|
status: 400,
|
|
@@ -9621,7 +9825,7 @@ function isUserMessageAnthropic(body) {
|
|
|
9621
9825
|
if (typeof content === "string") return true;
|
|
9622
9826
|
if (Array.isArray(content)) {
|
|
9623
9827
|
const hasToolResult = content.some(
|
|
9624
|
-
(block) => _optionalChain([asObject2, 'call',
|
|
9828
|
+
(block) => _optionalChain([asObject2, 'call', _475 => _475(block), 'optionalAccess', _476 => _476["type"]]) === "tool_result"
|
|
9625
9829
|
);
|
|
9626
9830
|
return !hasToolResult;
|
|
9627
9831
|
}
|
|
@@ -9650,7 +9854,7 @@ function isUserMessageGemini(body) {
|
|
|
9650
9854
|
if (!lastContent || lastContent["role"] !== "user") return false;
|
|
9651
9855
|
const parts = asArray(lastContent["parts"]);
|
|
9652
9856
|
const hasFunctionResponse = parts.some(
|
|
9653
|
-
(part) => _optionalChain([asObject2, 'call',
|
|
9857
|
+
(part) => _optionalChain([asObject2, 'call', _477 => _477(part), 'optionalAccess', _478 => _478["functionResponse"]]) !== void 0
|
|
9654
9858
|
);
|
|
9655
9859
|
return !hasFunctionResponse;
|
|
9656
9860
|
}
|
|
@@ -9824,14 +10028,14 @@ function newVoucherId() {
|
|
|
9824
10028
|
}
|
|
9825
10029
|
function computeVoucherGrant(voucher, currentKey, now) {
|
|
9826
10030
|
if (voucher.type === "credit") {
|
|
9827
|
-
const current = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess',
|
|
10031
|
+
const current = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _479 => _479.totalCostLimitUsd]), () => ( 0));
|
|
9828
10032
|
let granted2 = current + (_nullishCoalesce(voucher.creditUsd, () => ( 0)));
|
|
9829
10033
|
if (voucher.maxTotalCostLimitUsd != null) {
|
|
9830
10034
|
granted2 = Math.min(granted2, voucher.maxTotalCostLimitUsd);
|
|
9831
10035
|
}
|
|
9832
10036
|
return { totalCostLimitUsd: granted2 };
|
|
9833
10037
|
}
|
|
9834
|
-
const currentExpiry = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess',
|
|
10038
|
+
const currentExpiry = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _480 => _480.expiresAt]), () => ( now));
|
|
9835
10039
|
let granted = currentExpiry + (_nullishCoalesce(voucher.renewalDays, () => ( 0))) * DAY_MS2;
|
|
9836
10040
|
if (voucher.maxExpiryDays != null) {
|
|
9837
10041
|
granted = Math.min(granted, now + voucher.maxExpiryDays * DAY_MS2);
|
|
@@ -9862,7 +10066,7 @@ function toVoucherInfo(v) {
|
|
|
9862
10066
|
// src/outbound-api/voucherRedeem.ts
|
|
9863
10067
|
function isRedeemRequest(method, url) {
|
|
9864
10068
|
if (method !== "POST" || !url) return false;
|
|
9865
|
-
const path = _nullishCoalesce(_optionalChain([url, 'access',
|
|
10069
|
+
const path = _nullishCoalesce(_optionalChain([url, 'access', _481 => _481.split, 'call', _482 => _482("?"), 'access', _483 => _483[0], 'optionalAccess', _484 => _484.replace, 'call', _485 => _485(/\/+$/, "")]), () => ( ""));
|
|
9866
10070
|
return path.endsWith("/redeem");
|
|
9867
10071
|
}
|
|
9868
10072
|
function writeErr(res, status, message, headers = {}) {
|
|
@@ -9892,8 +10096,8 @@ function grantToResult(type, granted) {
|
|
|
9892
10096
|
function currentResult(type, keyRow) {
|
|
9893
10097
|
const result = { type };
|
|
9894
10098
|
if (type === "credit") {
|
|
9895
|
-
if (_optionalChain([keyRow, 'optionalAccess',
|
|
9896
|
-
} else if (_optionalChain([keyRow, 'optionalAccess',
|
|
10099
|
+
if (_optionalChain([keyRow, 'optionalAccess', _486 => _486.totalCostLimitUsd]) != null) result.totalCostLimitUsd = keyRow.totalCostLimitUsd;
|
|
10100
|
+
} else if (_optionalChain([keyRow, 'optionalAccess', _487 => _487.expiresAt]) != null) {
|
|
9897
10101
|
result.expiresAt = keyRow.expiresAt;
|
|
9898
10102
|
}
|
|
9899
10103
|
return result;
|
|
@@ -9931,7 +10135,7 @@ async function handleVoucherRedeem(req, res, deps, voucherEnabled, redeemLimiter
|
|
|
9931
10135
|
let code;
|
|
9932
10136
|
try {
|
|
9933
10137
|
code = raw ? JSON.parse(raw)["code"] : void 0;
|
|
9934
|
-
} catch (
|
|
10138
|
+
} catch (e55) {
|
|
9935
10139
|
writeErr(res, 400, "Invalid JSON in request body");
|
|
9936
10140
|
return;
|
|
9937
10141
|
}
|
|
@@ -9980,7 +10184,7 @@ async function handleVoucherRedeem(req, res, deps, voucherEnabled, redeemLimiter
|
|
|
9980
10184
|
const won = await voucherDb.voucherRedeemCas(voucher.id, verifiedKeyId, absolute, now);
|
|
9981
10185
|
if (!won) {
|
|
9982
10186
|
const after = await voucherDb.voucherGetByHash(codeHash);
|
|
9983
|
-
if (_optionalChain([after, 'optionalAccess',
|
|
10187
|
+
if (_optionalChain([after, 'optionalAccess', _488 => _488.status]) === "redeemed" && after.redeemedByKeyId === verifiedKeyId) {
|
|
9984
10188
|
return after.grantApplied === true ? { ok: true, result: currentResult(after.type, await deps.db.outboundApiKeysGetByHash(keyHash)) } : await applyFirstPass(after, recordedAbsolute(after));
|
|
9985
10189
|
}
|
|
9986
10190
|
return { ok: false, status: 409, message: "Code was already redeemed" };
|
|
@@ -10055,10 +10259,10 @@ function extractPresentedKey(req) {
|
|
|
10055
10259
|
}
|
|
10056
10260
|
const xApiKey = req.headers["x-api-key"];
|
|
10057
10261
|
const xApi = Array.isArray(xApiKey) ? xApiKey[0] : xApiKey;
|
|
10058
|
-
if (_optionalChain([xApi, 'optionalAccess',
|
|
10262
|
+
if (_optionalChain([xApi, 'optionalAccess', _489 => _489.trim, 'call', _490 => _490()])) return xApi.trim();
|
|
10059
10263
|
const goog = req.headers["x-goog-api-key"];
|
|
10060
10264
|
const g = Array.isArray(goog) ? goog[0] : goog;
|
|
10061
|
-
return _optionalChain([g, 'optionalAccess',
|
|
10265
|
+
return _optionalChain([g, 'optionalAccess', _491 => _491.trim, 'call', _492 => _492()]) || void 0;
|
|
10062
10266
|
}
|
|
10063
10267
|
function isLoopbackPeer(address) {
|
|
10064
10268
|
if (!address) return false;
|
|
@@ -10068,10 +10272,10 @@ function isLoopbackPeer(address) {
|
|
|
10068
10272
|
function selectEndpoint(method, url) {
|
|
10069
10273
|
if (method !== "POST" || !url) return null;
|
|
10070
10274
|
const openAIOperation = _chunkG4CZIUIBcjs.classifyOpenAIOperation.call(void 0, method, url);
|
|
10071
|
-
if (_optionalChain([openAIOperation, 'optionalAccess',
|
|
10275
|
+
if (_optionalChain([openAIOperation, 'optionalAccess', _493 => _493.policyFamily]) === "chat" || _optionalChain([openAIOperation, 'optionalAccess', _494 => _494.policyFamily]) === "responses") {
|
|
10072
10276
|
return openAIOperation.policyFamily;
|
|
10073
10277
|
}
|
|
10074
|
-
const path = _nullishCoalesce(_optionalChain([url, 'access',
|
|
10278
|
+
const path = _nullishCoalesce(_optionalChain([url, 'access', _495 => _495.split, 'call', _496 => _496("?"), 'access', _497 => _497[0], 'optionalAccess', _498 => _498.replace, 'call', _499 => _499(/\/+$/, "")]), () => ( ""));
|
|
10075
10279
|
const classified = classifyAnthropicMessagesPath(url);
|
|
10076
10280
|
if (classified === "messages" || classified === "count_tokens") return "messages";
|
|
10077
10281
|
const lastSeg = _nullishCoalesce(path.split("/").pop(), () => ( ""));
|
|
@@ -10088,18 +10292,18 @@ function extractGeminiModelFromUrl(url) {
|
|
|
10088
10292
|
}
|
|
10089
10293
|
function isModelsListRequest(url) {
|
|
10090
10294
|
if (!url) return false;
|
|
10091
|
-
const path = _nullishCoalesce(_optionalChain([url, 'access',
|
|
10295
|
+
const path = _nullishCoalesce(_optionalChain([url, 'access', _500 => _500.split, 'call', _501 => _501("?"), 'access', _502 => _502[0], 'optionalAccess', _503 => _503.replace, 'call', _504 => _504(/\/+$/, "")]), () => ( ""));
|
|
10092
10296
|
return path.endsWith("/models");
|
|
10093
10297
|
}
|
|
10094
10298
|
function isAnthropicOauthUsagePath(url) {
|
|
10095
10299
|
if (!url) return false;
|
|
10096
|
-
const path = _nullishCoalesce(_optionalChain([url, 'access',
|
|
10300
|
+
const path = _nullishCoalesce(_optionalChain([url, 'access', _505 => _505.split, 'call', _506 => _506("?"), 'access', _507 => _507[0], 'optionalAccess', _508 => _508.replace, 'call', _509 => _509(/\/+$/, "")]), () => ( ""));
|
|
10097
10301
|
return path === "/api/oauth/usage";
|
|
10098
10302
|
}
|
|
10099
10303
|
function resolveModelsShape(modelsShape, allowedEndpoints) {
|
|
10100
10304
|
if (modelsShape === "anthropic") return "anthropic";
|
|
10101
10305
|
if (modelsShape === "openai") return "openai";
|
|
10102
|
-
if (_optionalChain([allowedEndpoints, 'optionalAccess',
|
|
10306
|
+
if (_optionalChain([allowedEndpoints, 'optionalAccess', _510 => _510.includes, 'call', _511 => _511("images")])) return "openai";
|
|
10103
10307
|
if (!allowedEndpoints || allowedEndpoints.length === 0) return "anthropic";
|
|
10104
10308
|
return allowedEndpoints.includes("messages") ? "anthropic" : "openai";
|
|
10105
10309
|
}
|
|
@@ -10143,10 +10347,10 @@ async function fetchUpstreamModelsUncached(provider) {
|
|
|
10143
10347
|
);
|
|
10144
10348
|
if (!response.ok) return [];
|
|
10145
10349
|
const body = await response.json();
|
|
10146
|
-
const fromData = Array.isArray(_optionalChain([body, 'optionalAccess',
|
|
10350
|
+
const fromData = Array.isArray(_optionalChain([body, 'optionalAccess', _512 => _512.data])) ? body.data.map((entry) => typeof _optionalChain([entry, 'optionalAccess', _513 => _513.id]) === "string" ? entry.id.trim() : "").filter((id) => id !== "") : [];
|
|
10147
10351
|
if (fromData.length > 0) return fromData;
|
|
10148
|
-
return Array.isArray(_optionalChain([body, 'optionalAccess',
|
|
10149
|
-
(entry) => typeof _optionalChain([entry, 'optionalAccess',
|
|
10352
|
+
return Array.isArray(_optionalChain([body, 'optionalAccess', _514 => _514.models])) ? body.models.map(
|
|
10353
|
+
(entry) => typeof _optionalChain([entry, 'optionalAccess', _515 => _515.name]) === "string" ? entry.name.replace(/^models\//, "").trim() : ""
|
|
10150
10354
|
).filter((id) => id !== "") : [];
|
|
10151
10355
|
}
|
|
10152
10356
|
async function discoverUpstreamModels(provider) {
|
|
@@ -10162,7 +10366,7 @@ async function discoverUpstreamModels(provider) {
|
|
|
10162
10366
|
let ids = [];
|
|
10163
10367
|
try {
|
|
10164
10368
|
ids = await fetchUpstreamModelsUncached(provider);
|
|
10165
|
-
} catch (
|
|
10369
|
+
} catch (e56) {
|
|
10166
10370
|
ids = [];
|
|
10167
10371
|
}
|
|
10168
10372
|
upstreamModelsCache.set(provider.id, { at: Date.now(), ids, ok: ids.length > 0 });
|
|
@@ -10200,7 +10404,7 @@ async function pushTargetCatalog(llmConfig, target, push) {
|
|
|
10200
10404
|
}
|
|
10201
10405
|
var MODEL_LIST_ENDPOINTS = ["chat", "responses", "messages", "gemini"];
|
|
10202
10406
|
function parseModelsLimit(url) {
|
|
10203
|
-
const query = _optionalChain([url, 'optionalAccess',
|
|
10407
|
+
const query = _optionalChain([url, 'optionalAccess', _516 => _516.split, 'call', _517 => _517("?"), 'access', _518 => _518[1]]);
|
|
10204
10408
|
if (!query) return void 0;
|
|
10205
10409
|
const raw = new URLSearchParams(query).get("limit");
|
|
10206
10410
|
if (raw === null) return void 0;
|
|
@@ -10218,7 +10422,7 @@ async function writeModelsListAnthropic(res, llmConfig, config, apiKeyId, allowe
|
|
|
10218
10422
|
);
|
|
10219
10423
|
};
|
|
10220
10424
|
const viaLabel = (name, ref) => {
|
|
10221
|
-
const modelId = ref ? _optionalChain([
|
|
10425
|
+
const modelId = ref ? _optionalChain([_chunkJGRNVH7Ccjs.parseModelRef.call(void 0, ref), 'optionalAccess', _519 => _519.modelId]) : void 0;
|
|
10222
10426
|
return modelId ? `${name} (via ${modelId})` : void 0;
|
|
10223
10427
|
};
|
|
10224
10428
|
for (const endpoint of MODEL_LIST_ENDPOINTS) {
|
|
@@ -10228,7 +10432,7 @@ async function writeModelsListAnthropic(res, llmConfig, config, apiKeyId, allowe
|
|
|
10228
10432
|
await pushTargetCatalog(llmConfig, binding.target, push);
|
|
10229
10433
|
continue;
|
|
10230
10434
|
}
|
|
10231
|
-
if (_optionalChain([binding, 'access',
|
|
10435
|
+
if (_optionalChain([binding, 'access', _520 => _520.modelMappings, 'optionalAccess', _521 => _521.length])) {
|
|
10232
10436
|
for (const mapping of binding.modelMappings) {
|
|
10233
10437
|
const source = mapping.source.trim();
|
|
10234
10438
|
if (source === "" || source.includes("*")) continue;
|
|
@@ -10238,7 +10442,7 @@ async function writeModelsListAnthropic(res, llmConfig, config, apiKeyId, allowe
|
|
|
10238
10442
|
await pushTargetCatalog(llmConfig, binding.target, push);
|
|
10239
10443
|
for (const mapping of _nullishCoalesce(binding.modelMappings, () => ( []))) {
|
|
10240
10444
|
if (!mapping.source.includes("*") || mapping.target.trim() === "") continue;
|
|
10241
|
-
push(_nullishCoalesce(_optionalChain([
|
|
10445
|
+
push(_nullishCoalesce(_optionalChain([_chunkJGRNVH7Ccjs.parseModelRef.call(void 0, mapping.target), 'optionalAccess', _522 => _522.modelId]), () => ( mapping.target.trim())));
|
|
10242
10446
|
}
|
|
10243
10447
|
}
|
|
10244
10448
|
continue;
|
|
@@ -10249,7 +10453,7 @@ async function writeModelsListAnthropic(res, llmConfig, config, apiKeyId, allowe
|
|
|
10249
10453
|
}
|
|
10250
10454
|
}
|
|
10251
10455
|
}
|
|
10252
|
-
if (_optionalChain([directTarget, 'optionalAccess',
|
|
10456
|
+
if (_optionalChain([directTarget, 'optionalAccess', _523 => _523.kind]) === "provider") {
|
|
10253
10457
|
for (const id of await passthroughProviderModelIds(llmConfig, directTarget.providerId)) {
|
|
10254
10458
|
push(id);
|
|
10255
10459
|
}
|
|
@@ -10259,9 +10463,9 @@ async function writeModelsListAnthropic(res, llmConfig, config, apiKeyId, allowe
|
|
|
10259
10463
|
res.end(
|
|
10260
10464
|
JSON.stringify({
|
|
10261
10465
|
data: limited,
|
|
10262
|
-
first_id: _nullishCoalesce(_optionalChain([limited, 'access',
|
|
10466
|
+
first_id: _nullishCoalesce(_optionalChain([limited, 'access', _524 => _524[0], 'optionalAccess', _525 => _525.id]), () => ( null)),
|
|
10263
10467
|
has_more: limited.length < entries2.length,
|
|
10264
|
-
last_id: _nullishCoalesce(_optionalChain([limited, 'access',
|
|
10468
|
+
last_id: _nullishCoalesce(_optionalChain([limited, 'access', _526 => _526[limited.length - 1], 'optionalAccess', _527 => _527.id]), () => ( null))
|
|
10265
10469
|
})
|
|
10266
10470
|
);
|
|
10267
10471
|
}
|
|
@@ -10283,8 +10487,8 @@ function handleOauthUsageProxy(res, config, apiKeyId) {
|
|
|
10283
10487
|
const snapshot = _nullishCoalesce(_nullishCoalesce((preferredAccountId !== void 0 ? snapshots.find((s) => s.accountId === preferredAccountId) : void 0), () => ( snapshots.find((s) => s.windows.some((w) => w.state === "fresh")))), () => ( snapshots[0]));
|
|
10284
10488
|
const body = {};
|
|
10285
10489
|
for (const [wireKey, windowId] of OAUTH_USAGE_WINDOW_IDS) {
|
|
10286
|
-
const window = _optionalChain([snapshot, 'optionalAccess',
|
|
10287
|
-
const usable = _optionalChain([window, 'optionalAccess',
|
|
10490
|
+
const window = _optionalChain([snapshot, 'optionalAccess', _528 => _528.windows, 'access', _529 => _529.find, 'call', _530 => _530((w) => w.id === windowId)]);
|
|
10491
|
+
const usable = _optionalChain([window, 'optionalAccess', _531 => _531.state]) === "fresh";
|
|
10288
10492
|
body[wireKey] = {
|
|
10289
10493
|
utilization: usable ? _nullishCoalesce(window.usedPercent, () => ( null)) : null,
|
|
10290
10494
|
resets_at: usable ? _nullishCoalesce(window.resetsAt, () => ( null)) : null
|
|
@@ -10311,7 +10515,7 @@ function directUpstreamUrl(provider, requestUrl) {
|
|
|
10311
10515
|
const queryIndex = raw.indexOf("?");
|
|
10312
10516
|
const path = (queryIndex >= 0 ? raw.slice(0, queryIndex) : raw) || "/";
|
|
10313
10517
|
const query = queryIndex >= 0 ? raw.slice(queryIndex) : "";
|
|
10314
|
-
const versionSegment = _optionalChain([/\/v\d+[a-z]*$/, 'access',
|
|
10518
|
+
const versionSegment = _optionalChain([/\/v\d+[a-z]*$/, 'access', _532 => _532.exec, 'call', _533 => _533(root), 'optionalAccess', _534 => _534[0]]);
|
|
10315
10519
|
let tail = path;
|
|
10316
10520
|
if (versionSegment) {
|
|
10317
10521
|
if (path === versionSegment) tail = "";
|
|
@@ -10335,7 +10539,7 @@ function directUpstreamBinding(target, apiKeyId, priority = 1e3) {
|
|
|
10335
10539
|
}
|
|
10336
10540
|
async function relayDirectUpstream(req, res, deps, verified, config, concurrencyGate, audit, preReadBody) {
|
|
10337
10541
|
const direct = verified.boundUpstream;
|
|
10338
|
-
const providerId = _optionalChain([direct, 'optionalAccess',
|
|
10542
|
+
const providerId = _optionalChain([direct, 'optionalAccess', _535 => _535.kind]) === "provider" ? direct.providerId : "";
|
|
10339
10543
|
const provider = await deps.llmConfig.getProvider(providerId);
|
|
10340
10544
|
if (!provider) {
|
|
10341
10545
|
writeJsonError(
|
|
@@ -10387,7 +10591,7 @@ async function relayDirectUpstream(req, res, deps, verified, config, concurrency
|
|
|
10387
10591
|
req.headers,
|
|
10388
10592
|
{ fallbackKey: verified.id, endpoint: "direct" }
|
|
10389
10593
|
);
|
|
10390
|
-
} catch (
|
|
10594
|
+
} catch (e57) {
|
|
10391
10595
|
}
|
|
10392
10596
|
}
|
|
10393
10597
|
const headers = _chunkTX4UCSOPcjs.getProviderHeaders.call(void 0, provider, resolveProviderKeyLiteral(provider.api_key));
|
|
@@ -10448,7 +10652,7 @@ async function writeModelsList(res, llmConfig, config, apiKeyId, allowedEndpoint
|
|
|
10448
10652
|
await pushTargetCatalog(llmConfig, binding.target, (id) => modelIds.push(id));
|
|
10449
10653
|
continue;
|
|
10450
10654
|
}
|
|
10451
|
-
if (_optionalChain([binding, 'access',
|
|
10655
|
+
if (_optionalChain([binding, 'access', _536 => _536.modelMappings, 'optionalAccess', _537 => _537.length])) {
|
|
10452
10656
|
modelIds.push(
|
|
10453
10657
|
...binding.modelMappings.map((mapping) => mapping.source.trim()).filter((source) => source !== "" && !source.includes("*"))
|
|
10454
10658
|
);
|
|
@@ -10456,7 +10660,7 @@ async function writeModelsList(res, llmConfig, config, apiKeyId, allowedEndpoint
|
|
|
10456
10660
|
await pushTargetCatalog(llmConfig, binding.target, (id) => modelIds.push(id));
|
|
10457
10661
|
for (const mapping of _nullishCoalesce(binding.modelMappings, () => ( []))) {
|
|
10458
10662
|
if (!mapping.source.includes("*") || mapping.target.trim() === "") continue;
|
|
10459
|
-
modelIds.push(_nullishCoalesce(_optionalChain([
|
|
10663
|
+
modelIds.push(_nullishCoalesce(_optionalChain([_chunkJGRNVH7Ccjs.parseModelRef.call(void 0, mapping.target), 'optionalAccess', _538 => _538.modelId]), () => ( mapping.target.trim())));
|
|
10460
10664
|
}
|
|
10461
10665
|
}
|
|
10462
10666
|
continue;
|
|
@@ -10471,11 +10675,11 @@ async function writeModelsList(res, llmConfig, config, apiKeyId, allowedEndpoint
|
|
|
10471
10675
|
if (endpointConfig.backgroundModel) refs.push(endpointConfig.backgroundModel);
|
|
10472
10676
|
}
|
|
10473
10677
|
modelIds.push(
|
|
10474
|
-
...refs.map((ref) => _optionalChain([
|
|
10678
|
+
...refs.map((ref) => _optionalChain([_chunkJGRNVH7Ccjs.parseModelRef.call(void 0, ref), 'optionalAccess', _539 => _539.modelId])).filter((modelId) => modelId !== void 0)
|
|
10475
10679
|
);
|
|
10476
10680
|
}
|
|
10477
10681
|
}
|
|
10478
|
-
if (_optionalChain([directTarget, 'optionalAccess',
|
|
10682
|
+
if (_optionalChain([directTarget, 'optionalAccess', _540 => _540.kind]) === "provider") {
|
|
10479
10683
|
modelIds.push(...await passthroughProviderModelIds(llmConfig, directTarget.providerId));
|
|
10480
10684
|
}
|
|
10481
10685
|
modelIds.push(...imageModels);
|
|
@@ -10521,9 +10725,9 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
10521
10725
|
const anthropicPathClass = classifyAnthropicMessagesPath(req.url);
|
|
10522
10726
|
const isCountTokens = anthropicPathClass === "count_tokens";
|
|
10523
10727
|
const classifiedOperation = _chunkG4CZIUIBcjs.classifyOpenAIOperation.call(void 0, req.method, req.url);
|
|
10524
|
-
const imageOperation = _optionalChain([classifiedOperation, 'optionalAccess',
|
|
10728
|
+
const imageOperation = _optionalChain([classifiedOperation, 'optionalAccess', _541 => _541.policyFamily]) === "images" ? classifiedOperation : null;
|
|
10525
10729
|
if (anthropicPathClass !== null) markAnthropicProtocolResponse(res);
|
|
10526
|
-
const proxyOauthUsageEnabled = _optionalChain([config, 'access',
|
|
10730
|
+
const proxyOauthUsageEnabled = _optionalChain([config, 'access', _542 => _542.anthropic, 'optionalAccess', _543 => _543.proxyOauthUsage]) === true;
|
|
10527
10731
|
const isOauthUsagePath = proxyOauthUsageEnabled && isAnthropicOauthUsagePath(req.url);
|
|
10528
10732
|
if (isOauthUsagePath) markAnthropicProtocolResponse(res);
|
|
10529
10733
|
const audit = _chunkFX325I5Qcjs.beginAuditCapture.call(void 0, req, res, now, {
|
|
@@ -10543,7 +10747,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
10543
10747
|
const verified = verification.key;
|
|
10544
10748
|
if (audit) audit.keyId = verified.id;
|
|
10545
10749
|
if (billing) billing.keyId = verified.id;
|
|
10546
|
-
if (verified.loopbackOnly && !isLoopbackPeer(_optionalChain([req, 'access',
|
|
10750
|
+
if (verified.loopbackOnly && !isLoopbackPeer(_optionalChain([req, 'access', _544 => _544.socket, 'optionalAccess', _545 => _545.remoteAddress]))) {
|
|
10547
10751
|
writeJsonError(res, 403, "This integration key is restricted to loopback clients");
|
|
10548
10752
|
return;
|
|
10549
10753
|
}
|
|
@@ -10556,7 +10760,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
10556
10760
|
req,
|
|
10557
10761
|
res,
|
|
10558
10762
|
deps,
|
|
10559
|
-
_optionalChain([config, 'access',
|
|
10763
|
+
_optionalChain([config, 'access', _546 => _546.voucher, 'optionalAccess', _547 => _547.enabled]) === true,
|
|
10560
10764
|
_nullishCoalesce(redeemLimiter, () => ( getFallbackRedeemLimiter())),
|
|
10561
10765
|
verified.id,
|
|
10562
10766
|
_nullishCoalesce(presented, () => ( "")),
|
|
@@ -10572,7 +10776,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
10572
10776
|
});
|
|
10573
10777
|
return;
|
|
10574
10778
|
}
|
|
10575
|
-
const directProvider = _optionalChain([verified, 'access',
|
|
10779
|
+
const directProvider = _optionalChain([verified, 'access', _548 => _548.boundUpstream, 'optionalAccess', _549 => _549.kind]) === "provider" ? verified.boundUpstream : null;
|
|
10576
10780
|
if (verified.boundUpstream && !directProvider) {
|
|
10577
10781
|
config = {
|
|
10578
10782
|
...config,
|
|
@@ -10615,7 +10819,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
10615
10819
|
}
|
|
10616
10820
|
if (isCodexSearchRequest(req.method, req.url)) {
|
|
10617
10821
|
await handleCodexSearchRequest(req, res, {
|
|
10618
|
-
mode: _nullishCoalesce(_optionalChain([config, 'access',
|
|
10822
|
+
mode: _nullishCoalesce(_optionalChain([config, 'access', _550 => _550.search, 'optionalAccess', _551 => _551.modes, 'access', _552 => _552.codex]), () => ( _chunkE4QHVXV5cjs.DEFAULT_SEARCH_FRONTEND_MODES.codex)),
|
|
10619
10823
|
runtime: _nullishCoalesce(deps.searchRuntime, () => ( null)),
|
|
10620
10824
|
// This handler EXECUTES rather than relays, and `handleOutboundRequest`
|
|
10621
10825
|
// has no signal of its own to hand down, so it builds one. Without it a
|
|
@@ -10638,7 +10842,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
10638
10842
|
writeJsonError(res, 403, "API key is not allowed to access this endpoint");
|
|
10639
10843
|
return;
|
|
10640
10844
|
}
|
|
10641
|
-
if (resolveModelsShape(_optionalChain([config, 'access',
|
|
10845
|
+
if (resolveModelsShape(_optionalChain([config, 'access', _553 => _553.anthropic, 'optionalAccess', _554 => _554.modelsShape]), verified.allowedEndpoints) === "anthropic") {
|
|
10642
10846
|
await writeModelsListAnthropic(
|
|
10643
10847
|
res,
|
|
10644
10848
|
deps.llmConfig,
|
|
@@ -10653,7 +10857,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
10653
10857
|
if (verified.allowedEndpoints.includes("images") && deps.imageModelCatalog) {
|
|
10654
10858
|
try {
|
|
10655
10859
|
imageModels = await deps.imageModelCatalog.listAvailableModels(verified.id);
|
|
10656
|
-
} catch (
|
|
10860
|
+
} catch (e58) {
|
|
10657
10861
|
}
|
|
10658
10862
|
}
|
|
10659
10863
|
await writeModelsList(
|
|
@@ -10741,12 +10945,12 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
10741
10945
|
res.once("close", release2);
|
|
10742
10946
|
}
|
|
10743
10947
|
try {
|
|
10744
|
-
const ingressFormat =
|
|
10948
|
+
const ingressFormat = _chunkJGRNVH7Ccjs.endpointToIngressFormat.call(void 0, endpoint);
|
|
10745
10949
|
const rawBody = await readBody3(req);
|
|
10746
10950
|
let parsedBody = {};
|
|
10747
10951
|
try {
|
|
10748
10952
|
parsedBody = rawBody ? JSON.parse(rawBody) : {};
|
|
10749
|
-
} catch (
|
|
10953
|
+
} catch (e59) {
|
|
10750
10954
|
writeJsonError(res, 400, "Invalid JSON in request body");
|
|
10751
10955
|
return;
|
|
10752
10956
|
}
|
|
@@ -10761,8 +10965,8 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
10761
10965
|
const urlModel = extractGeminiModelFromUrl(req.url);
|
|
10762
10966
|
if (urlModel) parsedBody["model"] = urlModel;
|
|
10763
10967
|
}
|
|
10764
|
-
const requestedModel =
|
|
10765
|
-
const role =
|
|
10968
|
+
const requestedModel = _chunkJGRNVH7Ccjs.extractRequestedModel.call(void 0, ingressFormat, parsedBody);
|
|
10969
|
+
const role = _chunkJGRNVH7Ccjs.isKindMappedEndpoint.call(void 0, endpoint) || endpoint === "chat" ? void 0 : _chunkJGRNVH7Ccjs.detectRequestRole.call(void 0, ingressFormat, parsedBody, {
|
|
10766
10970
|
// Role detection precedes the route pick (the pick consumes the
|
|
10767
10971
|
// role), so the hint is the union across the candidate routes.
|
|
10768
10972
|
backgroundModelIds: candidateBackgroundModelIds(config.bindings, verified.id, endpoint)
|
|
@@ -10790,8 +10994,8 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
10790
10994
|
replayBody = JSON.stringify(parsedBody);
|
|
10791
10995
|
}
|
|
10792
10996
|
const hostedImageGenerationAllowed = verified.allowedEndpoints.includes("images");
|
|
10793
|
-
const listResolvedModel = endpoint === "chat" && bindingResolution.binding.modelMode === "mapped" ? _nullishCoalesce(_optionalChain([resolveGatewayModelMappingRow, 'call',
|
|
10794
|
-
const resolved =
|
|
10997
|
+
const listResolvedModel = endpoint === "chat" && bindingResolution.binding.modelMode === "mapped" ? _nullishCoalesce(_optionalChain([resolveGatewayModelMappingRow, 'call', _555 => _555(bindingResolution.binding.modelMappings, requestedModel), 'optionalAccess', _556 => _556.target]), () => ( requestedModel)) : requestedModel;
|
|
10998
|
+
const resolved = _chunkJGRNVH7Ccjs.isKindMappedEndpoint.call(void 0, endpoint) || endpoint === "chat" ? await _chunkJGRNVH7Ccjs.resolveRoute.call(void 0, {
|
|
10795
10999
|
config: effectiveEndpointConfig,
|
|
10796
11000
|
ingressFormat,
|
|
10797
11001
|
llmConfig: deps.llmConfig,
|
|
@@ -10803,7 +11007,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
10803
11007
|
// Attribution: stamp the verified named-key id onto the route.
|
|
10804
11008
|
apiKeyId: verified.id,
|
|
10805
11009
|
hostedImageGenerationAllowed
|
|
10806
|
-
}) : await
|
|
11010
|
+
}) : await _chunkJGRNVH7Ccjs.resolveRoute.call(void 0, {
|
|
10807
11011
|
config: effectiveEndpointConfig,
|
|
10808
11012
|
role,
|
|
10809
11013
|
ingressFormat,
|
|
@@ -10839,7 +11043,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
10839
11043
|
}
|
|
10840
11044
|
let releaseSerial = null;
|
|
10841
11045
|
const providerKey = resolved.route.providerId;
|
|
10842
|
-
if (_optionalChain([config, 'access',
|
|
11046
|
+
if (_optionalChain([config, 'access', _557 => _557.userMessageQueue, 'optionalAccess', _558 => _558.enabled]) && providerKey && !isCountTokens && isUserMessageRequest(endpoint, parsedBody)) {
|
|
10843
11047
|
const umq = config.userMessageQueue;
|
|
10844
11048
|
try {
|
|
10845
11049
|
const serialSlot = await serialQueue.acquire(providerKey, {
|
|
@@ -10869,12 +11073,12 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
10869
11073
|
const token = routeMap.addRoute(
|
|
10870
11074
|
isCountTokens ? {
|
|
10871
11075
|
...requestRoute,
|
|
10872
|
-
anthropicCountTokensMode: _optionalChain([config, 'access',
|
|
10873
|
-
anthropicCountTokensEstimateBudgetMs: _optionalChain([config, 'access',
|
|
10874
|
-
anthropicPdfTextExtractionBudgetMs: _optionalChain([config, 'access',
|
|
11076
|
+
anthropicCountTokensMode: _optionalChain([config, 'access', _559 => _559.anthropic, 'optionalAccess', _560 => _560.countTokens, 'optionalAccess', _561 => _561.mode]),
|
|
11077
|
+
anthropicCountTokensEstimateBudgetMs: _optionalChain([config, 'access', _562 => _562.anthropic, 'optionalAccess', _563 => _563.countTokens, 'optionalAccess', _564 => _564.estimateBudgetMs]),
|
|
11078
|
+
anthropicPdfTextExtractionBudgetMs: _optionalChain([config, 'access', _565 => _565.anthropic, 'optionalAccess', _566 => _566.pdfTextExtraction, 'optionalAccess', _567 => _567.budgetMs])
|
|
10875
11079
|
} : anthropicPathClass !== null ? {
|
|
10876
11080
|
...requestRoute,
|
|
10877
|
-
anthropicPdfTextExtractionBudgetMs: _optionalChain([config, 'access',
|
|
11081
|
+
anthropicPdfTextExtractionBudgetMs: _optionalChain([config, 'access', _568 => _568.anthropic, 'optionalAccess', _569 => _569.pdfTextExtraction, 'optionalAccess', _570 => _570.budgetMs])
|
|
10878
11082
|
} : requestRoute
|
|
10879
11083
|
);
|
|
10880
11084
|
try {
|
|
@@ -11058,7 +11262,7 @@ var OutboundApiServer = (_class19 = class {
|
|
|
11058
11262
|
this.server = listener.server;
|
|
11059
11263
|
this.boundAddr = bindAddr;
|
|
11060
11264
|
this.boundPort = actualPort;
|
|
11061
|
-
if (actualPort !== port) _optionalChain([this, 'access',
|
|
11265
|
+
if (actualPort !== port) _optionalChain([this, 'access', _571 => _571.onPortChange, 'optionalCall', _572 => _572(actualPort)]);
|
|
11062
11266
|
this.logInfo(`[OutboundApiServer] Listening on ${bindAddr}:${actualPort}`);
|
|
11063
11267
|
return actualPort;
|
|
11064
11268
|
}
|
|
@@ -11101,8 +11305,8 @@ var OutboundApiServer = (_class19 = class {
|
|
|
11101
11305
|
this.anthropicConfig = input.anthropic;
|
|
11102
11306
|
this.searchConfig = input.search;
|
|
11103
11307
|
this.imagesEnabled = input.imagesEnabled === true;
|
|
11104
|
-
this.apiHelloEnabled = _optionalChain([input, 'access',
|
|
11105
|
-
_chunkVGBJPHHDcjs.setAnthropicPingHeartbeatMs.call(void 0, _optionalChain([input, 'access',
|
|
11308
|
+
this.apiHelloEnabled = _optionalChain([input, 'access', _573 => _573.anthropic, 'optionalAccess', _574 => _574.apiHello]) !== false;
|
|
11309
|
+
_chunkVGBJPHHDcjs.setAnthropicPingHeartbeatMs.call(void 0, _optionalChain([input, 'access', _575 => _575.anthropic, 'optionalAccess', _576 => _576.heartbeatIntervalMs]));
|
|
11106
11310
|
}
|
|
11107
11311
|
captureRuntimeSnapshot() {
|
|
11108
11312
|
return {
|
|
@@ -11128,8 +11332,8 @@ var OutboundApiServer = (_class19 = class {
|
|
|
11128
11332
|
this.anthropicConfig = snapshot.anthropic;
|
|
11129
11333
|
this.searchConfig = snapshot.search;
|
|
11130
11334
|
this.imagesEnabled = snapshot.imagesEnabled;
|
|
11131
|
-
this.apiHelloEnabled = _optionalChain([snapshot, 'access',
|
|
11132
|
-
_chunkVGBJPHHDcjs.setAnthropicPingHeartbeatMs.call(void 0, _optionalChain([snapshot, 'access',
|
|
11335
|
+
this.apiHelloEnabled = _optionalChain([snapshot, 'access', _577 => _577.anthropic, 'optionalAccess', _578 => _578.apiHello]) !== false;
|
|
11336
|
+
_chunkVGBJPHHDcjs.setAnthropicPingHeartbeatMs.call(void 0, _optionalChain([snapshot, 'access', _579 => _579.anthropic, 'optionalAccess', _580 => _580.heartbeatIntervalMs]));
|
|
11133
11337
|
}
|
|
11134
11338
|
async restoreRuntimeSnapshot(snapshot) {
|
|
11135
11339
|
const current = this.server;
|
|
@@ -11163,22 +11367,22 @@ var OutboundApiServer = (_class19 = class {
|
|
|
11163
11367
|
server.close(() => {
|
|
11164
11368
|
try {
|
|
11165
11369
|
this.logInfo("[OutboundApiServer] Stopped");
|
|
11166
|
-
} catch (
|
|
11370
|
+
} catch (e60) {
|
|
11167
11371
|
}
|
|
11168
11372
|
});
|
|
11169
|
-
} catch (
|
|
11373
|
+
} catch (e61) {
|
|
11170
11374
|
}
|
|
11171
11375
|
}
|
|
11172
11376
|
announcePublishedListener(bindAddr, requestedPort, actualPort) {
|
|
11173
11377
|
if (actualPort !== requestedPort) {
|
|
11174
11378
|
try {
|
|
11175
|
-
_optionalChain([this, 'access',
|
|
11176
|
-
} catch (
|
|
11379
|
+
_optionalChain([this, 'access', _581 => _581.onPortChange, 'optionalCall', _582 => _582(actualPort)]);
|
|
11380
|
+
} catch (e62) {
|
|
11177
11381
|
}
|
|
11178
11382
|
}
|
|
11179
11383
|
try {
|
|
11180
11384
|
this.logInfo(`[OutboundApiServer] Listening on ${bindAddr}:${actualPort}`);
|
|
11181
|
-
} catch (
|
|
11385
|
+
} catch (e63) {
|
|
11182
11386
|
}
|
|
11183
11387
|
}
|
|
11184
11388
|
/** Per-request handler. Auth is enforced on EVERY request (incl. loopback). */
|
|
@@ -11225,7 +11429,7 @@ var OutboundApiServer = (_class19 = class {
|
|
|
11225
11429
|
tryServeApiHello(req, res) {
|
|
11226
11430
|
if (!this.apiHelloEnabled) return false;
|
|
11227
11431
|
if (req.method !== "HEAD") return false;
|
|
11228
|
-
const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access',
|
|
11432
|
+
const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access', _583 => _583.split, 'call', _584 => _584("?"), 'access', _585 => _585[0], 'optionalAccess', _586 => _586.replace, 'call', _587 => _587(/\/+$/, "")]) || "/";
|
|
11229
11433
|
if (path !== "/api/hello") return false;
|
|
11230
11434
|
res.writeHead(200);
|
|
11231
11435
|
res.end();
|
|
@@ -11239,7 +11443,7 @@ var OutboundApiServer = (_class19 = class {
|
|
|
11239
11443
|
const provider = this.deps.healthReportProvider;
|
|
11240
11444
|
if (!provider) return false;
|
|
11241
11445
|
if (req.method !== "GET" && req.method !== "HEAD") return false;
|
|
11242
|
-
const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access',
|
|
11446
|
+
const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access', _588 => _588.split, 'call', _589 => _589("?"), 'access', _590 => _590[0], 'optionalAccess', _591 => _591.replace, 'call', _592 => _592(/\/+$/, "")]) || "/";
|
|
11243
11447
|
if (path !== "/health" && path !== "/healthz") return false;
|
|
11244
11448
|
const report = provider();
|
|
11245
11449
|
res.writeHead(_healthloggingtypes.healthHttpStatus.call(void 0, report.status), { "Content-Type": "application/json" });
|
|
@@ -11464,7 +11668,7 @@ function resolveCompletionReasoningPlan(provider, options, target, requestMaxTok
|
|
|
11464
11668
|
}
|
|
11465
11669
|
function resolveOpenAIEffort(provider, options, target) {
|
|
11466
11670
|
const plan = resolveCompletionReasoningPlan(provider, options, target);
|
|
11467
|
-
return _optionalChain([plan, 'optionalAccess',
|
|
11671
|
+
return _optionalChain([plan, 'optionalAccess', _593 => _593.kind]) === "level" && plan.enabled ? plan.effort : void 0;
|
|
11468
11672
|
}
|
|
11469
11673
|
function buildAnthropicReasoningWire(provider, options) {
|
|
11470
11674
|
const configuredMaxTokens = _nullishCoalesce(options.maxTokens, () => ( LEGACY_ANTHROPIC_MAX_TOKENS));
|
|
@@ -11475,7 +11679,7 @@ function buildAnthropicReasoningWire(provider, options) {
|
|
|
11475
11679
|
"anthropic",
|
|
11476
11680
|
legacyBound
|
|
11477
11681
|
);
|
|
11478
|
-
if (_optionalChain([plan, 'optionalAccess',
|
|
11682
|
+
if (_optionalChain([plan, 'optionalAccess', _594 => _594.kind]) === "level" && plan.enabled) {
|
|
11479
11683
|
return {
|
|
11480
11684
|
effectiveMaxTokens: configuredMaxTokens,
|
|
11481
11685
|
thinking: { type: "adaptive" },
|
|
@@ -11483,7 +11687,7 @@ function buildAnthropicReasoningWire(provider, options) {
|
|
|
11483
11687
|
legacyBudgetEnabled: false
|
|
11484
11688
|
};
|
|
11485
11689
|
}
|
|
11486
|
-
if (_optionalChain([plan, 'optionalAccess',
|
|
11690
|
+
if (_optionalChain([plan, 'optionalAccess', _595 => _595.kind]) === "budget" && plan.enabled) {
|
|
11487
11691
|
return {
|
|
11488
11692
|
effectiveMaxTokens: legacyBound,
|
|
11489
11693
|
thinking: { type: "enabled", budget_tokens: plan.budgetTokens },
|
|
@@ -11497,13 +11701,13 @@ function buildAnthropicReasoningWire(provider, options) {
|
|
|
11497
11701
|
}
|
|
11498
11702
|
function buildGeminiThinkingConfig(provider, options) {
|
|
11499
11703
|
const plan = resolveCompletionReasoningPlan(provider, options, "gemini");
|
|
11500
|
-
if (_optionalChain([plan, 'optionalAccess',
|
|
11704
|
+
if (_optionalChain([plan, 'optionalAccess', _596 => _596.kind]) === "level") {
|
|
11501
11705
|
return {
|
|
11502
11706
|
includeThoughts: plan.enabled,
|
|
11503
11707
|
thinkingLevel: plan.effort
|
|
11504
11708
|
};
|
|
11505
11709
|
}
|
|
11506
|
-
if (_optionalChain([plan, 'optionalAccess',
|
|
11710
|
+
if (_optionalChain([plan, 'optionalAccess', _597 => _597.kind]) === "budget") {
|
|
11507
11711
|
return {
|
|
11508
11712
|
includeThoughts: plan.enabled,
|
|
11509
11713
|
thinkingBudget: plan.budgetTokens
|
|
@@ -11599,7 +11803,7 @@ async function callAnthropicCompletion(provider, apiKey, options, logger) {
|
|
|
11599
11803
|
message: {
|
|
11600
11804
|
id: `assistant-${Date.now()}`,
|
|
11601
11805
|
role: "assistant",
|
|
11602
|
-
content: _optionalChain([choice2, 'access',
|
|
11806
|
+
content: _optionalChain([choice2, 'access', _598 => _598.message, 'optionalAccess', _599 => _599.content]) || "",
|
|
11603
11807
|
timestamp: Date.now()
|
|
11604
11808
|
},
|
|
11605
11809
|
usage: openaiResponse2.usage ? {
|
|
@@ -11716,7 +11920,7 @@ async function callGeminiCompletion(provider, apiKey, options, logger) {
|
|
|
11716
11920
|
const candidate = candidates[0];
|
|
11717
11921
|
const content = candidate.content;
|
|
11718
11922
|
let textContent = "";
|
|
11719
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
11923
|
+
if (_optionalChain([content, 'optionalAccess', _600 => _600.parts])) {
|
|
11720
11924
|
for (const part of content.parts) {
|
|
11721
11925
|
if (part.text) {
|
|
11722
11926
|
textContent += part.text;
|
|
@@ -11844,7 +12048,7 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
|
|
|
11844
12048
|
});
|
|
11845
12049
|
if (!response.ok) {
|
|
11846
12050
|
const errorText = await response.text();
|
|
11847
|
-
_optionalChain([callbacks, 'access',
|
|
12051
|
+
_optionalChain([callbacks, 'access', _601 => _601.onError, 'optionalCall', _602 => _602(`API error (${response.status}): ${errorText}`)]);
|
|
11848
12052
|
return;
|
|
11849
12053
|
}
|
|
11850
12054
|
const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "openai", {
|
|
@@ -11854,7 +12058,7 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
|
|
|
11854
12058
|
onVideo: callbacks.onVideo,
|
|
11855
12059
|
onError: callbacks.onError
|
|
11856
12060
|
});
|
|
11857
|
-
_optionalChain([callbacks, 'access',
|
|
12061
|
+
_optionalChain([callbacks, 'access', _603 => _603.onDone, 'optionalCall', _604 => _604(
|
|
11858
12062
|
{
|
|
11859
12063
|
id: messageId,
|
|
11860
12064
|
role: "assistant",
|
|
@@ -11929,7 +12133,7 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
|
|
|
11929
12133
|
logger.info("Streaming Anthropic completion request", {
|
|
11930
12134
|
url: apiUrl,
|
|
11931
12135
|
model: anthropicRequest.model,
|
|
11932
|
-
messagesCount: _optionalChain([anthropicRequest, 'access',
|
|
12136
|
+
messagesCount: _optionalChain([anthropicRequest, 'access', _605 => _605.messages, 'optionalAccess', _606 => _606.length]),
|
|
11933
12137
|
max_tokens: anthropicRequest.max_tokens,
|
|
11934
12138
|
temperature: anthropicRequest.temperature,
|
|
11935
12139
|
stream: anthropicRequest.stream,
|
|
@@ -11946,7 +12150,7 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
|
|
|
11946
12150
|
if (!response.ok) {
|
|
11947
12151
|
const errorText = await response.text();
|
|
11948
12152
|
logger.error("Anthropic API error", void 0, { status: response.status, errorText });
|
|
11949
|
-
_optionalChain([callbacks, 'access',
|
|
12153
|
+
_optionalChain([callbacks, 'access', _607 => _607.onError, 'optionalCall', _608 => _608(`API error (${response.status}): ${errorText}`)]);
|
|
11950
12154
|
return;
|
|
11951
12155
|
}
|
|
11952
12156
|
const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "anthropic", {
|
|
@@ -11957,10 +12161,10 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
|
|
|
11957
12161
|
});
|
|
11958
12162
|
logger.info("Anthropic stream complete", {
|
|
11959
12163
|
contentLength: result.content.length,
|
|
11960
|
-
reasoningLength: _optionalChain([result, 'access',
|
|
12164
|
+
reasoningLength: _optionalChain([result, 'access', _609 => _609.reasoning, 'optionalAccess', _610 => _610.length]) || 0,
|
|
11961
12165
|
blocksCount: result.blocks.length
|
|
11962
12166
|
});
|
|
11963
|
-
_optionalChain([callbacks, 'access',
|
|
12167
|
+
_optionalChain([callbacks, 'access', _611 => _611.onDone, 'optionalCall', _612 => _612(
|
|
11964
12168
|
{
|
|
11965
12169
|
id: messageId,
|
|
11966
12170
|
role: "assistant",
|
|
@@ -12018,7 +12222,7 @@ async function streamGeminiCompletion(provider, apiKey, options, messageId, call
|
|
|
12018
12222
|
if (!response.ok) {
|
|
12019
12223
|
const errorText = await response.text();
|
|
12020
12224
|
logger.error("Gemini API error", void 0, { status: response.status, errorText });
|
|
12021
|
-
_optionalChain([callbacks, 'access',
|
|
12225
|
+
_optionalChain([callbacks, 'access', _613 => _613.onError, 'optionalCall', _614 => _614(`API error (${response.status}): ${errorText}`)]);
|
|
12022
12226
|
return;
|
|
12023
12227
|
}
|
|
12024
12228
|
const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "gemini", {
|
|
@@ -12027,7 +12231,7 @@ async function streamGeminiCompletion(provider, apiKey, options, messageId, call
|
|
|
12027
12231
|
onError: callbacks.onError
|
|
12028
12232
|
});
|
|
12029
12233
|
logger.info("Gemini stream complete", { contentLength: result.content.length });
|
|
12030
|
-
_optionalChain([callbacks, 'access',
|
|
12234
|
+
_optionalChain([callbacks, 'access', _615 => _615.onDone, 'optionalCall', _616 => _616(
|
|
12031
12235
|
{
|
|
12032
12236
|
id: messageId,
|
|
12033
12237
|
role: "assistant",
|
|
@@ -12077,7 +12281,7 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
|
|
|
12077
12281
|
});
|
|
12078
12282
|
if (!response.ok) {
|
|
12079
12283
|
const errorText = await response.text();
|
|
12080
|
-
_optionalChain([callbacks, 'access',
|
|
12284
|
+
_optionalChain([callbacks, 'access', _617 => _617.onError, 'optionalCall', _618 => _618(`API error (${response.status}): ${errorText}`)]);
|
|
12081
12285
|
return;
|
|
12082
12286
|
}
|
|
12083
12287
|
const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "openai-response", {
|
|
@@ -12086,7 +12290,7 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
|
|
|
12086
12290
|
onError: callbacks.onError
|
|
12087
12291
|
});
|
|
12088
12292
|
logger.info("OpenAI Response API stream complete", { contentLength: result.content.length });
|
|
12089
|
-
_optionalChain([callbacks, 'access',
|
|
12293
|
+
_optionalChain([callbacks, 'access', _619 => _619.onDone, 'optionalCall', _620 => _620(
|
|
12090
12294
|
{
|
|
12091
12295
|
id: messageId,
|
|
12092
12296
|
role: "assistant",
|
|
@@ -12114,7 +12318,7 @@ async function resolveEffectiveMaxTokens(llmConfig, _getProvider, logger, _provi
|
|
|
12114
12318
|
}
|
|
12115
12319
|
try {
|
|
12116
12320
|
const globalParams = await llmConfig.getGlobalModelParameters();
|
|
12117
|
-
if (_optionalChain([globalParams, 'optionalAccess',
|
|
12321
|
+
if (_optionalChain([globalParams, 'optionalAccess', _621 => _621.maxTokens, 'optionalAccess', _622 => _622.enabled]) && globalParams.maxTokens.value > 0) {
|
|
12118
12322
|
logger.debug("Using global maxTokens", { maxTokens: globalParams.maxTokens.value });
|
|
12119
12323
|
return globalParams.maxTokens.value;
|
|
12120
12324
|
}
|
|
@@ -12142,7 +12346,7 @@ async function resolveThinkingBudget(getProvider, logger, providerId, modelId, m
|
|
|
12142
12346
|
}
|
|
12143
12347
|
const thinkingBudget = _thinkingconfig.calculateThinkingBudget.call(void 0, modelId, thinkLevel, maxTokens);
|
|
12144
12348
|
const provider = await getProvider(providerId);
|
|
12145
|
-
const providerName = _optionalChain([provider, 'optionalAccess',
|
|
12349
|
+
const providerName = _optionalChain([provider, 'optionalAccess', _623 => _623.name, 'optionalAccess', _624 => _624.toLowerCase, 'call', _625 => _625()]) || "";
|
|
12146
12350
|
const apiFormat = provider ? _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider) : "openai";
|
|
12147
12351
|
if (apiFormat === "anthropic" || providerName === "anthropic" || providerName.includes("claude")) {
|
|
12148
12352
|
const thinkingConfig = _thinkingconfig.buildAnthropicThinking.call(void 0, modelId, thinkLevel, maxTokens);
|
|
@@ -12179,7 +12383,7 @@ function logToolFormat(tools, logger) {
|
|
|
12179
12383
|
tools: openaiTools.map((t) => t.function.name),
|
|
12180
12384
|
firstTool: {
|
|
12181
12385
|
name: firstTool.function.name,
|
|
12182
|
-
description: _optionalChain([firstTool, 'access',
|
|
12386
|
+
description: _optionalChain([firstTool, 'access', _626 => _626.function, 'access', _627 => _627.description, 'optionalAccess', _628 => _628.slice, 'call', _629 => _629(0, 100)]),
|
|
12183
12387
|
parameters: firstTool.function.parameters
|
|
12184
12388
|
}
|
|
12185
12389
|
});
|
|
@@ -12190,7 +12394,7 @@ function logToolFormat(tools, logger) {
|
|
|
12190
12394
|
tools: anthropicTools.map((t) => t.name),
|
|
12191
12395
|
firstTool: {
|
|
12192
12396
|
name: firstTool.name,
|
|
12193
|
-
description: _optionalChain([firstTool, 'access',
|
|
12397
|
+
description: _optionalChain([firstTool, 'access', _630 => _630.description, 'optionalAccess', _631 => _631.slice, 'call', _632 => _632(0, 100)]),
|
|
12194
12398
|
input_schema: firstTool.input_schema
|
|
12195
12399
|
}
|
|
12196
12400
|
});
|
|
@@ -12201,9 +12405,9 @@ function logToolFormat(tools, logger) {
|
|
|
12201
12405
|
count: allDeclarations.length,
|
|
12202
12406
|
tools: allDeclarations.map((t) => t.name),
|
|
12203
12407
|
firstTool: {
|
|
12204
|
-
name: _optionalChain([allDeclarations, 'access',
|
|
12205
|
-
description: _optionalChain([allDeclarations, 'access',
|
|
12206
|
-
parameters: _optionalChain([allDeclarations, 'access',
|
|
12408
|
+
name: _optionalChain([allDeclarations, 'access', _633 => _633[0], 'optionalAccess', _634 => _634.name]),
|
|
12409
|
+
description: _optionalChain([allDeclarations, 'access', _635 => _635[0], 'optionalAccess', _636 => _636.description, 'optionalAccess', _637 => _637.slice, 'call', _638 => _638(0, 100)]),
|
|
12410
|
+
parameters: _optionalChain([allDeclarations, 'access', _639 => _639[0], 'optionalAccess', _640 => _640.parameters])
|
|
12207
12411
|
}
|
|
12208
12412
|
});
|
|
12209
12413
|
}
|
|
@@ -12266,7 +12470,7 @@ function buildToolRequest(apiFormat, conversationMessages, actualModel, options,
|
|
|
12266
12470
|
function extractDeltaContent(rawJson, apiFormat) {
|
|
12267
12471
|
const json = rawJson;
|
|
12268
12472
|
if (apiFormat === "google") {
|
|
12269
|
-
const parts = _optionalChain([json, 'access',
|
|
12473
|
+
const parts = _optionalChain([json, 'access', _641 => _641.candidates, 'optionalAccess', _642 => _642[0], 'optionalAccess', _643 => _643.content, 'optionalAccess', _644 => _644.parts]) || [];
|
|
12270
12474
|
let text = "";
|
|
12271
12475
|
for (const part of parts) {
|
|
12272
12476
|
if (part.thought === true) continue;
|
|
@@ -12274,15 +12478,15 @@ function extractDeltaContent(rawJson, apiFormat) {
|
|
|
12274
12478
|
}
|
|
12275
12479
|
return text;
|
|
12276
12480
|
} else if (apiFormat === "anthropic") {
|
|
12277
|
-
return _optionalChain([json, 'access',
|
|
12481
|
+
return _optionalChain([json, 'access', _645 => _645.delta, 'optionalAccess', _646 => _646.text]) || "";
|
|
12278
12482
|
} else {
|
|
12279
|
-
return _optionalChain([json, 'access',
|
|
12483
|
+
return _optionalChain([json, 'access', _647 => _647.choices, 'optionalAccess', _648 => _648[0], 'optionalAccess', _649 => _649.delta, 'optionalAccess', _650 => _650.content]) || "";
|
|
12280
12484
|
}
|
|
12281
12485
|
}
|
|
12282
12486
|
function extractDeltaReasoning(rawJson, apiFormat) {
|
|
12283
12487
|
const json = rawJson;
|
|
12284
12488
|
if (apiFormat === "google") {
|
|
12285
|
-
const parts = _optionalChain([json, 'access',
|
|
12489
|
+
const parts = _optionalChain([json, 'access', _651 => _651.candidates, 'optionalAccess', _652 => _652[0], 'optionalAccess', _653 => _653.content, 'optionalAccess', _654 => _654.parts]) || [];
|
|
12286
12490
|
let reasoning = "";
|
|
12287
12491
|
for (const part of parts) {
|
|
12288
12492
|
if (part.thought === true && part.text) reasoning += part.text;
|
|
@@ -12291,14 +12495,14 @@ function extractDeltaReasoning(rawJson, apiFormat) {
|
|
|
12291
12495
|
} else if (apiFormat === "anthropic") {
|
|
12292
12496
|
return "";
|
|
12293
12497
|
} else {
|
|
12294
|
-
const delta = _optionalChain([json, 'access',
|
|
12295
|
-
return (_optionalChain([delta, 'optionalAccess',
|
|
12498
|
+
const delta = _optionalChain([json, 'access', _655 => _655.choices, 'optionalAccess', _656 => _656[0], 'optionalAccess', _657 => _657.delta]);
|
|
12499
|
+
return (_optionalChain([delta, 'optionalAccess', _658 => _658.thinking, 'optionalAccess', _659 => _659.content]) || "") + (_optionalChain([delta, 'optionalAccess', _660 => _660.reasoning_content]) || "");
|
|
12296
12500
|
}
|
|
12297
12501
|
}
|
|
12298
12502
|
function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pendingOpenAIToolCalls) {
|
|
12299
12503
|
const json = rawJson;
|
|
12300
12504
|
if (apiFormat === "google") {
|
|
12301
|
-
const parts = _optionalChain([json, 'access',
|
|
12505
|
+
const parts = _optionalChain([json, 'access', _661 => _661.candidates, 'optionalAccess', _662 => _662[0], 'optionalAccess', _663 => _663.content, 'optionalAccess', _664 => _664.parts]) || [];
|
|
12302
12506
|
for (const part of parts) {
|
|
12303
12507
|
if (part.functionCall) {
|
|
12304
12508
|
logger.info("Function call detected", { functionCall: part.functionCall });
|
|
@@ -12308,13 +12512,13 @@ function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pend
|
|
|
12308
12512
|
args: part.functionCall.args || {}
|
|
12309
12513
|
};
|
|
12310
12514
|
toolCalls.push(toolCall);
|
|
12311
|
-
_optionalChain([callbacks, 'access',
|
|
12515
|
+
_optionalChain([callbacks, 'access', _665 => _665.onToolCall, 'optionalCall', _666 => _666(toolCall)]);
|
|
12312
12516
|
logger.info("Tool called", { toolName: toolCall.name });
|
|
12313
12517
|
}
|
|
12314
12518
|
}
|
|
12315
12519
|
} else if (apiFormat !== "anthropic") {
|
|
12316
|
-
const delta = _optionalChain([json, 'access',
|
|
12317
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
12520
|
+
const delta = _optionalChain([json, 'access', _667 => _667.choices, 'optionalAccess', _668 => _668[0], 'optionalAccess', _669 => _669.delta]);
|
|
12521
|
+
if (_optionalChain([delta, 'optionalAccess', _670 => _670.tool_calls]) && pendingOpenAIToolCalls) {
|
|
12318
12522
|
for (const tc of delta.tool_calls) {
|
|
12319
12523
|
const index = _nullishCoalesce(tc.index, () => ( 0));
|
|
12320
12524
|
let pending = pendingOpenAIToolCalls.get(index);
|
|
@@ -12323,8 +12527,8 @@ function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pend
|
|
|
12323
12527
|
pendingOpenAIToolCalls.set(index, pending);
|
|
12324
12528
|
}
|
|
12325
12529
|
if (tc.id) pending.id = tc.id;
|
|
12326
|
-
if (_optionalChain([tc, 'access',
|
|
12327
|
-
if (_optionalChain([tc, 'access',
|
|
12530
|
+
if (_optionalChain([tc, 'access', _671 => _671.function, 'optionalAccess', _672 => _672.name])) pending.name += tc.function.name;
|
|
12531
|
+
if (_optionalChain([tc, 'access', _673 => _673.function, 'optionalAccess', _674 => _674.arguments])) pending.arguments += tc.function.arguments;
|
|
12328
12532
|
}
|
|
12329
12533
|
}
|
|
12330
12534
|
}
|
|
@@ -12339,7 +12543,7 @@ function finalizeOpenAIToolCalls(pendingOpenAIToolCalls, toolCalls, callbacks, l
|
|
|
12339
12543
|
args: JSON.parse(pending.arguments || "{}")
|
|
12340
12544
|
};
|
|
12341
12545
|
toolCalls.push(toolCall);
|
|
12342
|
-
_optionalChain([callbacks, 'access',
|
|
12546
|
+
_optionalChain([callbacks, 'access', _675 => _675.onToolCall, 'optionalCall', _676 => _676(toolCall)]);
|
|
12343
12547
|
logger.info("Tool called (OpenAI)", { toolName: toolCall.name, args: toolCall.args });
|
|
12344
12548
|
} catch (e) {
|
|
12345
12549
|
logger.error("Failed to parse OpenAI tool call arguments", e instanceof Error ? e : void 0, {
|
|
@@ -12353,38 +12557,38 @@ function finalizeOpenAIToolCalls(pendingOpenAIToolCalls, toolCalls, callbacks, l
|
|
|
12353
12557
|
function parseStreamChunk(rawJson, apiFormat, callbacks, logger) {
|
|
12354
12558
|
const json = rawJson;
|
|
12355
12559
|
if (apiFormat === "google") {
|
|
12356
|
-
const candidate = _optionalChain([json, 'access',
|
|
12560
|
+
const candidate = _optionalChain([json, 'access', _677 => _677.candidates, 'optionalAccess', _678 => _678[0]]);
|
|
12357
12561
|
if (!candidate) {
|
|
12358
12562
|
logger.warn("No candidate found in Gemini response");
|
|
12359
12563
|
return;
|
|
12360
12564
|
}
|
|
12361
|
-
const parts = _optionalChain([candidate, 'access',
|
|
12565
|
+
const parts = _optionalChain([candidate, 'access', _679 => _679.content, 'optionalAccess', _680 => _680.parts]) || [];
|
|
12362
12566
|
for (const part of parts) {
|
|
12363
12567
|
if (part.thought === true && part.text) {
|
|
12364
|
-
_optionalChain([callbacks, 'access',
|
|
12568
|
+
_optionalChain([callbacks, 'access', _681 => _681.onReasoning, 'optionalCall', _682 => _682(part.text)]);
|
|
12365
12569
|
continue;
|
|
12366
12570
|
} else if (part.thoughtSignature && !part.thought) {
|
|
12367
12571
|
logger.debug("Gemini returned thoughtSignature without thought content");
|
|
12368
12572
|
}
|
|
12369
12573
|
if (part.text) {
|
|
12370
|
-
_optionalChain([callbacks, 'access',
|
|
12574
|
+
_optionalChain([callbacks, 'access', _683 => _683.onDelta, 'optionalCall', _684 => _684(part.text)]);
|
|
12371
12575
|
}
|
|
12372
12576
|
}
|
|
12373
12577
|
} else if (apiFormat === "anthropic") {
|
|
12374
12578
|
const delta = json.delta;
|
|
12375
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
12376
|
-
_optionalChain([callbacks, 'access',
|
|
12579
|
+
if (_optionalChain([delta, 'optionalAccess', _685 => _685.text])) {
|
|
12580
|
+
_optionalChain([callbacks, 'access', _686 => _686.onDelta, 'optionalCall', _687 => _687(delta.text)]);
|
|
12377
12581
|
}
|
|
12378
12582
|
} else {
|
|
12379
|
-
const delta = _optionalChain([json, 'access',
|
|
12380
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
12381
|
-
_optionalChain([callbacks, 'access',
|
|
12583
|
+
const delta = _optionalChain([json, 'access', _688 => _688.choices, 'optionalAccess', _689 => _689[0], 'optionalAccess', _690 => _690.delta]);
|
|
12584
|
+
if (_optionalChain([delta, 'optionalAccess', _691 => _691.content])) {
|
|
12585
|
+
_optionalChain([callbacks, 'access', _692 => _692.onDelta, 'optionalCall', _693 => _693(delta.content)]);
|
|
12382
12586
|
}
|
|
12383
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
12384
|
-
_optionalChain([callbacks, 'access',
|
|
12587
|
+
if (_optionalChain([delta, 'optionalAccess', _694 => _694.thinking, 'optionalAccess', _695 => _695.content])) {
|
|
12588
|
+
_optionalChain([callbacks, 'access', _696 => _696.onReasoning, 'optionalCall', _697 => _697(delta.thinking.content)]);
|
|
12385
12589
|
}
|
|
12386
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
12387
|
-
_optionalChain([callbacks, 'access',
|
|
12590
|
+
if (_optionalChain([delta, 'optionalAccess', _698 => _698.reasoning_content])) {
|
|
12591
|
+
_optionalChain([callbacks, 'access', _699 => _699.onReasoning, 'optionalCall', _700 => _700(delta.reasoning_content)]);
|
|
12388
12592
|
}
|
|
12389
12593
|
}
|
|
12390
12594
|
}
|
|
@@ -12397,7 +12601,7 @@ function buildIterationBlocks(iteration, content, reasoning, blocks, callbacks)
|
|
|
12397
12601
|
content: reasoning
|
|
12398
12602
|
};
|
|
12399
12603
|
blocks.push(thinkingBlock);
|
|
12400
|
-
_optionalChain([callbacks, 'access',
|
|
12604
|
+
_optionalChain([callbacks, 'access', _701 => _701.onBlock, 'optionalCall', _702 => _702(thinkingBlock)]);
|
|
12401
12605
|
}
|
|
12402
12606
|
if (content && content.trim()) {
|
|
12403
12607
|
const textBlock = {
|
|
@@ -12406,7 +12610,7 @@ function buildIterationBlocks(iteration, content, reasoning, blocks, callbacks)
|
|
|
12406
12610
|
content
|
|
12407
12611
|
};
|
|
12408
12612
|
blocks.push(textBlock);
|
|
12409
|
-
_optionalChain([callbacks, 'access',
|
|
12613
|
+
_optionalChain([callbacks, 'access', _703 => _703.onBlock, 'optionalCall', _704 => _704(textBlock)]);
|
|
12410
12614
|
}
|
|
12411
12615
|
}
|
|
12412
12616
|
async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbacks, logger, builtinExecutor) {
|
|
@@ -12421,7 +12625,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
12421
12625
|
status: "running"
|
|
12422
12626
|
};
|
|
12423
12627
|
blocks.push(toolUseBlock);
|
|
12424
|
-
_optionalChain([callbacks, 'access',
|
|
12628
|
+
_optionalChain([callbacks, 'access', _705 => _705.onBlock, 'optionalCall', _706 => _706(toolUseBlock)]);
|
|
12425
12629
|
try {
|
|
12426
12630
|
logger.info("Executing tool", { toolName: toolCall.name });
|
|
12427
12631
|
const mcpTool = mcpTools.find((t) => t.id === toolCall.name);
|
|
@@ -12444,8 +12648,8 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
12444
12648
|
result = { isError: true, content: [{ type: "text", text: "MCP service not available" }] };
|
|
12445
12649
|
}
|
|
12446
12650
|
logger.info("Tool result received", { result });
|
|
12447
|
-
_optionalChain([callbacks, 'access',
|
|
12448
|
-
const resultText = _optionalChain([result, 'access',
|
|
12651
|
+
_optionalChain([callbacks, 'access', _707 => _707.onToolResult, 'optionalCall', _708 => _708(toolCall.id, result)]);
|
|
12652
|
+
const resultText = _optionalChain([result, 'access', _709 => _709.content, 'optionalAccess', _710 => _710[0], 'optionalAccess', _711 => _711.text]) || JSON.stringify(result);
|
|
12449
12653
|
const toolResultBlock = {
|
|
12450
12654
|
id: `${toolCall.id}_result`,
|
|
12451
12655
|
type: "tool_result",
|
|
@@ -12455,11 +12659,11 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
12455
12659
|
isError: result.isError
|
|
12456
12660
|
};
|
|
12457
12661
|
blocks.push(toolResultBlock);
|
|
12458
|
-
_optionalChain([callbacks, 'access',
|
|
12662
|
+
_optionalChain([callbacks, 'access', _712 => _712.onBlock, 'optionalCall', _713 => _713(toolResultBlock)]);
|
|
12459
12663
|
const toolUseBlockRef = blocks.find((b) => b.id === `${toolCall.id}_use`);
|
|
12460
12664
|
if (toolUseBlockRef && toolUseBlockRef.type === "tool_use") {
|
|
12461
12665
|
toolUseBlockRef.status = result.isError ? "error" : "completed";
|
|
12462
|
-
_optionalChain([callbacks, 'access',
|
|
12666
|
+
_optionalChain([callbacks, 'access', _714 => _714.onBlock, 'optionalCall', _715 => _715({ ...toolUseBlockRef })]);
|
|
12463
12667
|
}
|
|
12464
12668
|
toolResults.push({ toolCall, result });
|
|
12465
12669
|
} catch (error) {
|
|
@@ -12469,7 +12673,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
12469
12673
|
isError: true,
|
|
12470
12674
|
content: [{ type: "text", text: `Error: ${errorMessage}` }]
|
|
12471
12675
|
};
|
|
12472
|
-
_optionalChain([callbacks, 'access',
|
|
12676
|
+
_optionalChain([callbacks, 'access', _716 => _716.onToolResult, 'optionalCall', _717 => _717(toolCall.id, errorResult)]);
|
|
12473
12677
|
const errorToolResultBlock = {
|
|
12474
12678
|
id: `${toolCall.id}_result`,
|
|
12475
12679
|
type: "tool_result",
|
|
@@ -12479,11 +12683,11 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
12479
12683
|
isError: true
|
|
12480
12684
|
};
|
|
12481
12685
|
blocks.push(errorToolResultBlock);
|
|
12482
|
-
_optionalChain([callbacks, 'access',
|
|
12686
|
+
_optionalChain([callbacks, 'access', _718 => _718.onBlock, 'optionalCall', _719 => _719(errorToolResultBlock)]);
|
|
12483
12687
|
const errorToolUseBlockRef = blocks.find((b) => b.id === `${toolCall.id}_use`);
|
|
12484
12688
|
if (errorToolUseBlockRef && errorToolUseBlockRef.type === "tool_use") {
|
|
12485
12689
|
errorToolUseBlockRef.status = "error";
|
|
12486
|
-
_optionalChain([callbacks, 'access',
|
|
12690
|
+
_optionalChain([callbacks, 'access', _720 => _720.onBlock, 'optionalCall', _721 => _721({ ...errorToolUseBlockRef })]);
|
|
12487
12691
|
}
|
|
12488
12692
|
toolResults.push({ toolCall, result: errorResult });
|
|
12489
12693
|
}
|
|
@@ -12493,7 +12697,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
12493
12697
|
function mapToolArguments(args, mcpTool, logger) {
|
|
12494
12698
|
const mappedArgs = { ...args };
|
|
12495
12699
|
const toolSchema = mcpTool.inputSchema;
|
|
12496
|
-
if (_optionalChain([toolSchema, 'optionalAccess',
|
|
12700
|
+
if (_optionalChain([toolSchema, 'optionalAccess', _722 => _722.properties])) {
|
|
12497
12701
|
const expectedParams = Object.keys(toolSchema.properties);
|
|
12498
12702
|
const paramMappings = {
|
|
12499
12703
|
"search_query": ["query", "q", "searchQuery", "search"],
|
|
@@ -12527,25 +12731,25 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
12527
12731
|
options.providerId,
|
|
12528
12732
|
options.model
|
|
12529
12733
|
);
|
|
12530
|
-
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess',
|
|
12531
|
-
const actualModel = _optionalChain([routedInfo, 'optionalAccess',
|
|
12734
|
+
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _723 => _723.actualProviderId]) || options.providerId;
|
|
12735
|
+
const actualModel = _optionalChain([routedInfo, 'optionalAccess', _724 => _724.actualModelId]) || options.model;
|
|
12532
12736
|
const provider = await getProvider(actualProviderId);
|
|
12533
12737
|
if (!provider) {
|
|
12534
|
-
_optionalChain([callbacks, 'access',
|
|
12738
|
+
_optionalChain([callbacks, 'access', _725 => _725.onError, 'optionalCall', _726 => _726(`Provider not found: ${actualProviderId}`)]);
|
|
12535
12739
|
return;
|
|
12536
12740
|
}
|
|
12537
12741
|
if (!provider.enabled) {
|
|
12538
|
-
_optionalChain([callbacks, 'access',
|
|
12742
|
+
_optionalChain([callbacks, 'access', _727 => _727.onError, 'optionalCall', _728 => _728(`Provider is disabled: ${provider.name}`)]);
|
|
12539
12743
|
return;
|
|
12540
12744
|
}
|
|
12541
12745
|
const { apiKey: effectiveKey } = _chunkA2YMUCBTcjs.resolveProviderEndpoint.call(void 0, provider);
|
|
12542
12746
|
const apiKey = resolveApiKey2(effectiveKey);
|
|
12543
12747
|
if (!apiKey) {
|
|
12544
|
-
_optionalChain([callbacks, 'access',
|
|
12748
|
+
_optionalChain([callbacks, 'access', _729 => _729.onError, 'optionalCall', _730 => _730("API key not configured")]);
|
|
12545
12749
|
return;
|
|
12546
12750
|
}
|
|
12547
12751
|
const messageId = `msg_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
12548
|
-
_optionalChain([callbacks, 'access',
|
|
12752
|
+
_optionalChain([callbacks, 'access', _731 => _731.onStart, 'optionalCall', _732 => _732(messageId)]);
|
|
12549
12753
|
const globalParams = await llmConfig.getGlobalModelParameters();
|
|
12550
12754
|
const MAX_ITERATIONS = _nullishCoalesce(globalParams.toolMaxTurns, () => ( 100));
|
|
12551
12755
|
let iteration = 0;
|
|
@@ -12592,12 +12796,12 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
12592
12796
|
});
|
|
12593
12797
|
if (!response.ok) {
|
|
12594
12798
|
const errorText = await response.text();
|
|
12595
|
-
_optionalChain([callbacks, 'access',
|
|
12799
|
+
_optionalChain([callbacks, 'access', _733 => _733.onError, 'optionalCall', _734 => _734(`API error (${response.status}): ${errorText}`)]);
|
|
12596
12800
|
return;
|
|
12597
12801
|
}
|
|
12598
|
-
const reader = _optionalChain([response, 'access',
|
|
12802
|
+
const reader = _optionalChain([response, 'access', _735 => _735.body, 'optionalAccess', _736 => _736.getReader, 'call', _737 => _737()]);
|
|
12599
12803
|
if (!reader) {
|
|
12600
|
-
_optionalChain([callbacks, 'access',
|
|
12804
|
+
_optionalChain([callbacks, 'access', _738 => _738.onError, 'optionalCall', _739 => _739("No response body")]);
|
|
12601
12805
|
return;
|
|
12602
12806
|
}
|
|
12603
12807
|
const decoder = new TextDecoder();
|
|
@@ -12630,7 +12834,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
12630
12834
|
logger.debug("Parsed JSON", { json });
|
|
12631
12835
|
if (json.error) {
|
|
12632
12836
|
logger.error("API Error", void 0, { error: json.error });
|
|
12633
|
-
_optionalChain([callbacks, 'access',
|
|
12837
|
+
_optionalChain([callbacks, 'access', _740 => _740.onError, 'optionalCall', _741 => _741(`API Error: ${json.error.message || JSON.stringify(json.error)}`)]);
|
|
12634
12838
|
return;
|
|
12635
12839
|
}
|
|
12636
12840
|
parseStreamChunk(json, apiFormat, callbacks, logger);
|
|
@@ -12663,7 +12867,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
12663
12867
|
toolCallsLength: toolCalls.length,
|
|
12664
12868
|
executableToolCallsLength: executableToolCalls.length,
|
|
12665
12869
|
hasMcpTools: !!options.mcpTools,
|
|
12666
|
-
mcpToolsLength: _optionalChain([options, 'access',
|
|
12870
|
+
mcpToolsLength: _optionalChain([options, 'access', _742 => _742.mcpTools, 'optionalAccess', _743 => _743.length]),
|
|
12667
12871
|
hasMcpService: !!mcpService
|
|
12668
12872
|
});
|
|
12669
12873
|
if (executableToolCalls.length > 0 && options.mcpTools && (mcpService || builtinExecutor)) {
|
|
@@ -12684,7 +12888,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
12684
12888
|
builtinExecutor
|
|
12685
12889
|
);
|
|
12686
12890
|
const toolResultsText = toolResults.map(({ toolCall, result }) => {
|
|
12687
|
-
const resultText = typeof result === "string" ? result : _optionalChain([result, 'access',
|
|
12891
|
+
const resultText = typeof result === "string" ? result : _optionalChain([result, 'access', _744 => _744.content, 'optionalAccess', _745 => _745[0], 'optionalAccess', _746 => _746.text]) || JSON.stringify(result);
|
|
12688
12892
|
return `Tool ${toolCall.name} result:
|
|
12689
12893
|
${resultText}`;
|
|
12690
12894
|
}).join("\n\n");
|
|
@@ -12702,12 +12906,12 @@ ${resultText}`;
|
|
|
12702
12906
|
}
|
|
12703
12907
|
} catch (streamError) {
|
|
12704
12908
|
logger.error("Stream processing error", streamError instanceof Error ? streamError : void 0);
|
|
12705
|
-
_optionalChain([callbacks, 'access',
|
|
12909
|
+
_optionalChain([callbacks, 'access', _747 => _747.onError, 'optionalCall', _748 => _748(`Stream error: ${streamError instanceof Error ? streamError.message : "Unknown error"}`)]);
|
|
12706
12910
|
return;
|
|
12707
12911
|
}
|
|
12708
12912
|
}
|
|
12709
12913
|
logger.info("Sending final callback", { blocksCount: blocks.length });
|
|
12710
|
-
_optionalChain([callbacks, 'access',
|
|
12914
|
+
_optionalChain([callbacks, 'access', _749 => _749.onDone, 'optionalCall', _750 => _750({
|
|
12711
12915
|
id: messageId,
|
|
12712
12916
|
role: "assistant",
|
|
12713
12917
|
content: finalContent,
|
|
@@ -12718,7 +12922,7 @@ ${resultText}`;
|
|
|
12718
12922
|
} catch (error) {
|
|
12719
12923
|
logger.error("Error in streamWithTools", error instanceof Error ? error : void 0);
|
|
12720
12924
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
12721
|
-
_optionalChain([callbacks, 'access',
|
|
12925
|
+
_optionalChain([callbacks, 'access', _751 => _751.onError, 'optionalCall', _752 => _752(message)]);
|
|
12722
12926
|
}
|
|
12723
12927
|
}
|
|
12724
12928
|
|
|
@@ -12769,8 +12973,8 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
|
|
|
12769
12973
|
options.providerId,
|
|
12770
12974
|
options.model
|
|
12771
12975
|
);
|
|
12772
|
-
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess',
|
|
12773
|
-
const actualModel = _optionalChain([routedInfo, 'optionalAccess',
|
|
12976
|
+
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _753 => _753.actualProviderId]) || options.providerId;
|
|
12977
|
+
const actualModel = _optionalChain([routedInfo, 'optionalAccess', _754 => _754.actualModelId]) || options.model;
|
|
12774
12978
|
const provider = await getProvider(actualProviderId);
|
|
12775
12979
|
if (!provider) {
|
|
12776
12980
|
return { success: false, error: `Provider not found: ${actualProviderId}` };
|
|
@@ -12847,18 +13051,18 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
|
|
|
12847
13051
|
{ endpointTransformer: void 0 }
|
|
12848
13052
|
);
|
|
12849
13053
|
const data = await transformedResponse2.json();
|
|
12850
|
-
const choice = _optionalChain([data, 'access',
|
|
13054
|
+
const choice = _optionalChain([data, 'access', _755 => _755.choices, 'optionalAccess', _756 => _756[0]]);
|
|
12851
13055
|
if (!choice) {
|
|
12852
13056
|
return { success: false, error: "No choices in response" };
|
|
12853
13057
|
}
|
|
12854
|
-
const rawToolCalls = _optionalChain([choice, 'access',
|
|
12855
|
-
const toolCalls = _optionalChain([rawToolCalls, 'optionalAccess',
|
|
13058
|
+
const rawToolCalls = _optionalChain([choice, 'access', _757 => _757.message, 'optionalAccess', _758 => _758.tool_calls]);
|
|
13059
|
+
const toolCalls = _optionalChain([rawToolCalls, 'optionalAccess', _759 => _759.map, 'call', _760 => _760((tc) => ({
|
|
12856
13060
|
id: tc.id,
|
|
12857
13061
|
name: tc.function.name,
|
|
12858
13062
|
args: typeof tc.function.arguments === "string" ? JSON.parse(tc.function.arguments) : tc.function.arguments
|
|
12859
13063
|
}))]);
|
|
12860
13064
|
const tapped = readUsageFromOpenAIResponse(data.usage);
|
|
12861
|
-
if (_optionalChain([recording, 'optionalAccess',
|
|
13065
|
+
if (_optionalChain([recording, 'optionalAccess', _761 => _761.recorder]) && tapped) {
|
|
12862
13066
|
recording.recorder.record({
|
|
12863
13067
|
messageId: _nullishCoalesce(options.messageId, () => ( null)),
|
|
12864
13068
|
parentMessageId: _nullishCoalesce(options.parentMessageId, () => ( null)),
|
|
@@ -12876,9 +13080,9 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
|
|
|
12876
13080
|
message: {
|
|
12877
13081
|
id: `msg_${Date.now()}`,
|
|
12878
13082
|
role: "assistant",
|
|
12879
|
-
content: _optionalChain([choice, 'access',
|
|
13083
|
+
content: _optionalChain([choice, 'access', _762 => _762.message, 'optionalAccess', _763 => _763.content]) || "",
|
|
12880
13084
|
timestamp: Date.now(),
|
|
12881
|
-
thinking: data.reasoning_content || _optionalChain([choice, 'access',
|
|
13085
|
+
thinking: data.reasoning_content || _optionalChain([choice, 'access', _764 => _764.message, 'optionalAccess', _765 => _765.thinking, 'optionalAccess', _766 => _766.content]) ? { content: data.reasoning_content || _optionalChain([choice, 'access', _767 => _767.message, 'optionalAccess', _768 => _768.thinking, 'optionalAccess', _769 => _769.content]) || "", signature: _optionalChain([choice, 'access', _770 => _770.message, 'optionalAccess', _771 => _771.thinking, 'optionalAccess', _772 => _772.signature]) } : void 0,
|
|
12882
13086
|
toolCalls
|
|
12883
13087
|
},
|
|
12884
13088
|
usage: data.usage ? {
|
|
@@ -12899,21 +13103,21 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
12899
13103
|
options.providerId,
|
|
12900
13104
|
options.model
|
|
12901
13105
|
);
|
|
12902
|
-
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess',
|
|
12903
|
-
const actualModel = _optionalChain([routedInfo, 'optionalAccess',
|
|
13106
|
+
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _773 => _773.actualProviderId]) || options.providerId;
|
|
13107
|
+
const actualModel = _optionalChain([routedInfo, 'optionalAccess', _774 => _774.actualModelId]) || options.model;
|
|
12904
13108
|
const provider = await getProvider(actualProviderId);
|
|
12905
13109
|
if (!provider) {
|
|
12906
|
-
_optionalChain([callbacks, 'access',
|
|
13110
|
+
_optionalChain([callbacks, 'access', _775 => _775.onError, 'optionalCall', _776 => _776(`Provider not found: ${actualProviderId}`)]);
|
|
12907
13111
|
return;
|
|
12908
13112
|
}
|
|
12909
13113
|
if (!provider.enabled) {
|
|
12910
|
-
_optionalChain([callbacks, 'access',
|
|
13114
|
+
_optionalChain([callbacks, 'access', _777 => _777.onError, 'optionalCall', _778 => _778(`Provider is disabled: ${provider.name}`)]);
|
|
12911
13115
|
return;
|
|
12912
13116
|
}
|
|
12913
13117
|
const { apiKey: effectiveKey } = _chunkA2YMUCBTcjs.resolveProviderEndpoint.call(void 0, provider);
|
|
12914
13118
|
const apiKey = resolveApiKey2(effectiveKey);
|
|
12915
13119
|
if (!apiKey) {
|
|
12916
|
-
_optionalChain([callbacks, 'access',
|
|
13120
|
+
_optionalChain([callbacks, 'access', _779 => _779.onError, 'optionalCall', _780 => _780("API key not configured")]);
|
|
12917
13121
|
return;
|
|
12918
13122
|
}
|
|
12919
13123
|
const { chain, hasTransformers } = await resolveChainWithMain(
|
|
@@ -12925,7 +13129,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
12925
13129
|
return completeStreamFallback(options, callbacks);
|
|
12926
13130
|
}
|
|
12927
13131
|
const messageId = `msg_${Date.now()}`;
|
|
12928
|
-
_optionalChain([callbacks, 'access',
|
|
13132
|
+
_optionalChain([callbacks, 'access', _781 => _781.onStart, 'optionalCall', _782 => _782(messageId)]);
|
|
12929
13133
|
const unifiedRequest = buildUnifiedCompletionRequest(actualModel, options, true);
|
|
12930
13134
|
const transformerProvider = {
|
|
12931
13135
|
name: provider.name,
|
|
@@ -12965,7 +13169,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
12965
13169
|
});
|
|
12966
13170
|
if (!response.ok) {
|
|
12967
13171
|
const errorText = await response.text();
|
|
12968
|
-
_optionalChain([callbacks, 'access',
|
|
13172
|
+
_optionalChain([callbacks, 'access', _783 => _783.onError, 'optionalCall', _784 => _784(`API error (${response.status}): ${errorText}`)]);
|
|
12969
13173
|
return;
|
|
12970
13174
|
}
|
|
12971
13175
|
const transformedResponse2 = await executor.executeResponseChain(
|
|
@@ -12975,9 +13179,9 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
12975
13179
|
chain,
|
|
12976
13180
|
{ endpointTransformer: void 0 }
|
|
12977
13181
|
);
|
|
12978
|
-
const reader = _optionalChain([transformedResponse2, 'access',
|
|
13182
|
+
const reader = _optionalChain([transformedResponse2, 'access', _785 => _785.body, 'optionalAccess', _786 => _786.getReader, 'call', _787 => _787()]);
|
|
12979
13183
|
if (!reader) {
|
|
12980
|
-
_optionalChain([callbacks, 'access',
|
|
13184
|
+
_optionalChain([callbacks, 'access', _788 => _788.onError, 'optionalCall', _789 => _789("No response body")]);
|
|
12981
13185
|
return;
|
|
12982
13186
|
}
|
|
12983
13187
|
const decoder = new TextDecoder();
|
|
@@ -12995,22 +13199,22 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
12995
13199
|
if (data === "[DONE]") continue;
|
|
12996
13200
|
try {
|
|
12997
13201
|
const json = JSON.parse(data);
|
|
12998
|
-
const delta = _optionalChain([json, 'access',
|
|
12999
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
13202
|
+
const delta = _optionalChain([json, 'access', _790 => _790.choices, 'optionalAccess', _791 => _791[0], 'optionalAccess', _792 => _792.delta]);
|
|
13203
|
+
if (_optionalChain([delta, 'optionalAccess', _793 => _793.content])) {
|
|
13000
13204
|
content += delta.content;
|
|
13001
|
-
_optionalChain([callbacks, 'access',
|
|
13205
|
+
_optionalChain([callbacks, 'access', _794 => _794.onDelta, 'optionalCall', _795 => _795(delta.content)]);
|
|
13002
13206
|
}
|
|
13003
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
13207
|
+
if (_optionalChain([delta, 'optionalAccess', _796 => _796.thinking, 'optionalAccess', _797 => _797.content])) {
|
|
13004
13208
|
reasoning += delta.thinking.content;
|
|
13005
|
-
_optionalChain([callbacks, 'access',
|
|
13209
|
+
_optionalChain([callbacks, 'access', _798 => _798.onReasoning, 'optionalCall', _799 => _799(delta.thinking.content)]);
|
|
13006
13210
|
}
|
|
13007
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
13211
|
+
if (_optionalChain([delta, 'optionalAccess', _800 => _800.reasoning_content])) {
|
|
13008
13212
|
reasoning += delta.reasoning_content;
|
|
13009
|
-
_optionalChain([callbacks, 'access',
|
|
13213
|
+
_optionalChain([callbacks, 'access', _801 => _801.onReasoning, 'optionalCall', _802 => _802(delta.reasoning_content)]);
|
|
13010
13214
|
}
|
|
13011
13215
|
if (json.usage) {
|
|
13012
13216
|
const tapped = readUsageFromOpenAIResponse(json.usage);
|
|
13013
|
-
if (_optionalChain([recording, 'optionalAccess',
|
|
13217
|
+
if (_optionalChain([recording, 'optionalAccess', _803 => _803.recorder]) && tapped) {
|
|
13014
13218
|
recording.recorder.record({
|
|
13015
13219
|
messageId: _nullishCoalesce(options.messageId, () => ( null)),
|
|
13016
13220
|
parentMessageId: _nullishCoalesce(options.parentMessageId, () => ( null)),
|
|
@@ -13023,7 +13227,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
13023
13227
|
rawUsage: json.usage
|
|
13024
13228
|
});
|
|
13025
13229
|
}
|
|
13026
|
-
_optionalChain([callbacks, 'access',
|
|
13230
|
+
_optionalChain([callbacks, 'access', _804 => _804.onDone, 'optionalCall', _805 => _805(
|
|
13027
13231
|
{
|
|
13028
13232
|
id: messageId,
|
|
13029
13233
|
role: "assistant",
|
|
@@ -13044,7 +13248,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
13044
13248
|
}
|
|
13045
13249
|
}
|
|
13046
13250
|
}
|
|
13047
|
-
_optionalChain([callbacks, 'access',
|
|
13251
|
+
_optionalChain([callbacks, 'access', _806 => _806.onDone, 'optionalCall', _807 => _807({
|
|
13048
13252
|
id: messageId,
|
|
13049
13253
|
role: "assistant",
|
|
13050
13254
|
content,
|
|
@@ -13056,7 +13260,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
13056
13260
|
}
|
|
13057
13261
|
} catch (error) {
|
|
13058
13262
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
13059
|
-
_optionalChain([callbacks, 'access',
|
|
13263
|
+
_optionalChain([callbacks, 'access', _808 => _808.onError, 'optionalCall', _809 => _809(message)]);
|
|
13060
13264
|
}
|
|
13061
13265
|
}
|
|
13062
13266
|
|
|
@@ -13123,8 +13327,8 @@ var CompletionService = (_class21 = class {
|
|
|
13123
13327
|
options.providerId,
|
|
13124
13328
|
options.model
|
|
13125
13329
|
);
|
|
13126
|
-
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess',
|
|
13127
|
-
const actualModel = _optionalChain([routedInfo, 'optionalAccess',
|
|
13330
|
+
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _810 => _810.actualProviderId]) || options.providerId;
|
|
13331
|
+
const actualModel = _optionalChain([routedInfo, 'optionalAccess', _811 => _811.actualModelId]) || options.model;
|
|
13128
13332
|
const provider = await this.getProvider(actualProviderId);
|
|
13129
13333
|
if (!provider) {
|
|
13130
13334
|
return { success: false, error: `Provider not found: ${actualProviderId}` };
|
|
@@ -13157,7 +13361,7 @@ var CompletionService = (_class21 = class {
|
|
|
13157
13361
|
this.apiKeyPool.reportSuccess(options.sessionId);
|
|
13158
13362
|
}
|
|
13159
13363
|
if (result.success && result.usage && options.sessionId) {
|
|
13160
|
-
_optionalChain([this, 'access',
|
|
13364
|
+
_optionalChain([this, 'access', _812 => _812.usageEventSink, 'optionalAccess', _813 => _813.emit, 'call', _814 => _814({
|
|
13161
13365
|
sessionId: options.sessionId,
|
|
13162
13366
|
modelId: actualModel,
|
|
13163
13367
|
usage: result.usage,
|
|
@@ -13186,8 +13390,8 @@ var CompletionService = (_class21 = class {
|
|
|
13186
13390
|
options.model
|
|
13187
13391
|
);
|
|
13188
13392
|
this.logger.debug("Resolved routed model", { routedInfo });
|
|
13189
|
-
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess',
|
|
13190
|
-
const actualModel = _optionalChain([routedInfo, 'optionalAccess',
|
|
13393
|
+
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _815 => _815.actualProviderId]) || options.providerId;
|
|
13394
|
+
const actualModel = _optionalChain([routedInfo, 'optionalAccess', _816 => _816.actualModelId]) || options.model;
|
|
13191
13395
|
this.logger.debug("Resolved provider and model", { actualProviderId, actualModel });
|
|
13192
13396
|
const provider = await this.getProvider(actualProviderId);
|
|
13193
13397
|
this.logger.debug("Retrieved provider", provider ? {
|
|
@@ -13199,22 +13403,22 @@ var CompletionService = (_class21 = class {
|
|
|
13199
13403
|
enabled: provider.enabled
|
|
13200
13404
|
} : { error: "Provider not found" });
|
|
13201
13405
|
if (!provider) {
|
|
13202
|
-
_optionalChain([callbacks, 'access',
|
|
13406
|
+
_optionalChain([callbacks, 'access', _817 => _817.onError, 'optionalCall', _818 => _818(`Provider not found: ${actualProviderId}`)]);
|
|
13203
13407
|
return;
|
|
13204
13408
|
}
|
|
13205
13409
|
if (!provider.enabled) {
|
|
13206
|
-
_optionalChain([callbacks, 'access',
|
|
13410
|
+
_optionalChain([callbacks, 'access', _819 => _819.onError, 'optionalCall', _820 => _820(`Provider is disabled: ${provider.name}`)]);
|
|
13207
13411
|
return;
|
|
13208
13412
|
}
|
|
13209
13413
|
const apiKey = await this.resolveApiKeyForRequest(provider, actualProviderId, options.sessionId);
|
|
13210
13414
|
if (!apiKey) {
|
|
13211
|
-
_optionalChain([callbacks, 'access',
|
|
13415
|
+
_optionalChain([callbacks, 'access', _821 => _821.onError, 'optionalCall', _822 => _822("API key not configured")]);
|
|
13212
13416
|
return;
|
|
13213
13417
|
}
|
|
13214
13418
|
const apiFormat = _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider);
|
|
13215
13419
|
this.logger.info("Using API format for stream", { apiFormat });
|
|
13216
13420
|
const messageId = `msg_${Date.now()}`;
|
|
13217
|
-
_optionalChain([callbacks, 'access',
|
|
13421
|
+
_optionalChain([callbacks, 'access', _823 => _823.onStart, 'optionalCall', _824 => _824(messageId)]);
|
|
13218
13422
|
const resolvedOptions = { ...options, model: actualModel };
|
|
13219
13423
|
if (options.sessionId) {
|
|
13220
13424
|
const sid = options.sessionId;
|
|
@@ -13223,14 +13427,14 @@ var CompletionService = (_class21 = class {
|
|
|
13223
13427
|
...callbacks,
|
|
13224
13428
|
onDone: (message, usage, metrics) => {
|
|
13225
13429
|
if (usage) {
|
|
13226
|
-
_optionalChain([this, 'access',
|
|
13430
|
+
_optionalChain([this, 'access', _825 => _825.usageEventSink, 'optionalAccess', _826 => _826.emit, 'call', _827 => _827({
|
|
13227
13431
|
sessionId: sid,
|
|
13228
13432
|
modelId: actualModel,
|
|
13229
13433
|
usage,
|
|
13230
13434
|
engineOrigin: "completion"
|
|
13231
13435
|
})]);
|
|
13232
13436
|
}
|
|
13233
|
-
_optionalChain([userOnDone, 'optionalCall',
|
|
13437
|
+
_optionalChain([userOnDone, 'optionalCall', _828 => _828(message, usage, metrics)]);
|
|
13234
13438
|
}
|
|
13235
13439
|
};
|
|
13236
13440
|
}
|
|
@@ -13246,11 +13450,11 @@ var CompletionService = (_class21 = class {
|
|
|
13246
13450
|
retryState.error = { status, message: error };
|
|
13247
13451
|
return;
|
|
13248
13452
|
}
|
|
13249
|
-
_optionalChain([callbacks, 'access',
|
|
13453
|
+
_optionalChain([callbacks, 'access', _829 => _829.onError, 'optionalCall', _830 => _830(error)]);
|
|
13250
13454
|
},
|
|
13251
13455
|
onDone: (message, usage, metrics) => {
|
|
13252
13456
|
this.apiKeyPool.reportSuccess(options.sessionId);
|
|
13253
|
-
_optionalChain([callbacks, 'access',
|
|
13457
|
+
_optionalChain([callbacks, 'access', _831 => _831.onDone, 'optionalCall', _832 => _832(message, usage, metrics)]);
|
|
13254
13458
|
}
|
|
13255
13459
|
};
|
|
13256
13460
|
await this.callStreamHandler(apiFormat, provider, apiKey, resolvedOptions, messageId, interceptCallbacks);
|
|
@@ -13271,7 +13475,7 @@ var CompletionService = (_class21 = class {
|
|
|
13271
13475
|
// don't fire onStart again
|
|
13272
13476
|
});
|
|
13273
13477
|
} else {
|
|
13274
|
-
_optionalChain([callbacks, 'access',
|
|
13478
|
+
_optionalChain([callbacks, 'access', _833 => _833.onError, 'optionalCall', _834 => _834(retryState.error.message)]);
|
|
13275
13479
|
}
|
|
13276
13480
|
}
|
|
13277
13481
|
} else {
|
|
@@ -13284,7 +13488,7 @@ var CompletionService = (_class21 = class {
|
|
|
13284
13488
|
} catch (error) {
|
|
13285
13489
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
13286
13490
|
this.logger.error("Stream completion error", error instanceof Error ? error : void 0, { message });
|
|
13287
|
-
_optionalChain([callbacks, 'access',
|
|
13491
|
+
_optionalChain([callbacks, 'access', _835 => _835.onError, 'optionalCall', _836 => _836(message)]);
|
|
13288
13492
|
}
|
|
13289
13493
|
}
|
|
13290
13494
|
/**
|
|
@@ -13324,7 +13528,7 @@ var CompletionService = (_class21 = class {
|
|
|
13324
13528
|
return {
|
|
13325
13529
|
success: true,
|
|
13326
13530
|
message: "Connection successful",
|
|
13327
|
-
response: _optionalChain([result, 'access',
|
|
13531
|
+
response: _optionalChain([result, 'access', _837 => _837.message, 'optionalAccess', _838 => _838.content]) || "",
|
|
13328
13532
|
model: modelId,
|
|
13329
13533
|
durationMs
|
|
13330
13534
|
};
|
|
@@ -13389,7 +13593,7 @@ ${description}`;
|
|
|
13389
13593
|
* 3. Legacy single key from provider config
|
|
13390
13594
|
*/
|
|
13391
13595
|
async resolveApiKeyForRequest(provider, providerId, sessionId) {
|
|
13392
|
-
if (_optionalChain([provider, 'access',
|
|
13596
|
+
if (_optionalChain([provider, 'access', _839 => _839.codingPlan, 'optionalAccess', _840 => _840.enabled]) && provider.codingPlan.apiKey) {
|
|
13393
13597
|
return this.resolveApiKey(provider.codingPlan.apiKey);
|
|
13394
13598
|
}
|
|
13395
13599
|
if (this.apiKeyPool) {
|
|
@@ -13701,4 +13905,7 @@ ${description}`;
|
|
|
13701
13905
|
|
|
13702
13906
|
|
|
13703
13907
|
|
|
13704
|
-
|
|
13908
|
+
|
|
13909
|
+
|
|
13910
|
+
|
|
13911
|
+
exports.CompletionService = CompletionService; exports.register = register; exports.emit = emit; exports.attach = attach; exports.release = release; exports.convertMessageToOpenAI = convertMessageToOpenAI; exports.convertMessageToAnthropic = convertMessageToAnthropic; exports.convertMessageToGemini = convertMessageToGemini; exports.getOpenRouterProviderConfig = getOpenRouterProviderConfig; exports.addOpenRouterProviderToRequest = addOpenRouterProviderToRequest; exports.getSharedExecutor = getSharedExecutor; exports.getResponsesEndpointTransformer = getResponsesEndpointTransformer; exports.getAnthropicEndpointTransformer = getAnthropicEndpointTransformer; exports.getGeminiEndpointTransformer = getGeminiEndpointTransformer; exports.readBody = readBody; exports.cancelDiscardedResponse = cancelDiscardedResponse; exports.projectUpstreamResponseHeaders = projectUpstreamResponseHeaders; exports.relayResponse = relayResponse; exports.aggregateAnthropicSseToJsonBody = aggregateAnthropicSseToJsonBody; exports.aggregateResponsesSseToJsonBody = aggregateResponsesSseToJsonBody; exports.aggregateOpenAIChatChunksToJsonBody = aggregateOpenAIChatChunksToJsonBody; exports.sniffIsSseResponse = sniffIsSseResponse; exports.writeError = writeError; exports.writeBoundAccountError = writeBoundAccountError; exports.resolvePoolBoundKey = resolvePoolBoundKey; exports.buildByoRouteActivityMeta = buildByoRouteActivityMeta; exports.DEFAULT_ROUTE_IDLE_MS = DEFAULT_ROUTE_IDLE_MS; exports.ProviderProxyRouteMap = ProviderProxyRouteMap; exports.previousResponseNotFound = previousResponseNotFound; exports.ResponsesAffinityStore = ResponsesAffinityStore; exports.getResponsesAffinityStore = getResponsesAffinityStore; exports.classifyResponsesProfile = classifyResponsesProfile; exports.extractRouteToken = extractRouteToken; exports.isLoopbackAddress = isLoopbackAddress; exports.ProviderProxy = ProviderProxy; exports.ROUTE_LEASE_REQUEST_SCHEMA = ROUTE_LEASE_REQUEST_SCHEMA; exports.ROUTE_LEASE_RESULT_SCHEMA = ROUTE_LEASE_RESULT_SCHEMA; exports.ROUTE_LEASE_CAPABILITIES_SCHEMA = ROUTE_LEASE_CAPABILITIES_SCHEMA; exports.ROUTE_LEASE_API_VERSION = ROUTE_LEASE_API_VERSION; exports.ROUTE_LEASE_DEFAULT_TTL_SECONDS = ROUTE_LEASE_DEFAULT_TTL_SECONDS; exports.ROUTE_LEASE_MAX_TTL_SECONDS = ROUTE_LEASE_MAX_TTL_SECONDS; exports.ROUTE_LEASE_MAX_IDEMPOTENCY_BYTES = ROUTE_LEASE_MAX_IDEMPOTENCY_BYTES; exports.ROUTE_LEASE_MAX_CONSUMER_BYTES = ROUTE_LEASE_MAX_CONSUMER_BYTES; exports.ROUTE_LEASE_MAX_EXECUTION_ID_BYTES = ROUTE_LEASE_MAX_EXECUTION_ID_BYTES; exports.ROUTE_LEASE_MAX_SESSION_ID_BYTES = ROUTE_LEASE_MAX_SESSION_ID_BYTES; exports.ROUTE_LEASE_MAX_MODEL_BYTES = ROUTE_LEASE_MAX_MODEL_BYTES; exports.ROUTE_LEASE_SESSION_HASH_DOMAIN = ROUTE_LEASE_SESSION_HASH_DOMAIN; exports.ROUTE_LEASE_CODEX_TOKEN_ENV = ROUTE_LEASE_CODEX_TOKEN_ENV; exports.ROUTE_LEASE_RUNTIMES = ROUTE_LEASE_RUNTIMES; exports.ROUTE_LEASE_CAPABILITIES = ROUTE_LEASE_CAPABILITIES; exports.ROUTE_LEASE_RUNTIME_TABLE = ROUTE_LEASE_RUNTIME_TABLE; exports.RouteLeaseError = RouteLeaseError; exports.normalizeRouteLeaseIdempotencyKey = normalizeRouteLeaseIdempotencyKey; exports.normalizeRouteLeaseTtl = normalizeRouteLeaseTtl; exports.hashRouteLeaseSessionId = hashRouteLeaseSessionId; exports.canonicalizeRouteLeasePayload = canonicalizeRouteLeasePayload; exports.hashRouteLeasePayload = hashRouteLeasePayload; exports.parseRouteLeaseCreate = parseRouteLeaseCreate; exports.routeLeaseRuntime = routeLeaseRuntime; exports.SYSTEM_ROUTE_LEASE_CLOCK = SYSTEM_ROUTE_LEASE_CLOCK; exports.RouteLeaseManager = RouteLeaseManager; exports.gatewayBindingToEndpointConfig = gatewayBindingToEndpointConfig; exports.candidateGatewayBindings = candidateGatewayBindings; exports.candidateBackgroundModelIds = candidateBackgroundModelIds; exports.resolveGatewayBinding = resolveGatewayBinding; exports.RouteLeaseTargetResolver = RouteLeaseTargetResolver; exports.createResponsesCompactHandler = createResponsesCompactHandler; exports.registerResponsesCompactOperation = registerResponsesCompactOperation; exports.createNativeResponsesHostedImageIngress = createNativeResponsesHostedImageIngress; exports.getProviderProxy = getProviderProxy; exports.__resetProviderProxyForTests = __resetProviderProxyForTests; exports.KeyedMutex = KeyedMutex; exports.IMAGE_SERVER_HARD_CEILINGS = IMAGE_SERVER_HARD_CEILINGS; exports.DEFAULT_IMAGES_SERVER_CONFIG = DEFAULT_IMAGES_SERVER_CONFIG; exports.normalizeImagesServerConfig = normalizeImagesServerConfig; exports.validateImagesServerConfig = validateImagesServerConfig; exports.DEFAULT_SEARCH_SERVER_CONFIG = DEFAULT_SEARCH_SERVER_CONFIG; exports.normalizeSearchApiProviderConfigs = normalizeSearchApiProviderConfigs; exports.normalizeSearchServerConfig = normalizeSearchServerConfig; exports.validateSearchServerConfig = validateSearchServerConfig; exports.OUTBOUND_API_SERVER_CONFIG_KEY = OUTBOUND_API_SERVER_CONFIG_KEY; exports.DEFAULT_USER_MESSAGE_QUEUE = DEFAULT_USER_MESSAGE_QUEUE; exports.DEFAULT_CONCURRENCY_QUEUE = DEFAULT_CONCURRENCY_QUEUE; exports.DEFAULT_ACCOUNT_PROBE = DEFAULT_ACCOUNT_PROBE; exports.DEFAULT_ALLOWANCE_SCHEDULING = DEFAULT_ALLOWANCE_SCHEDULING; exports.normalizeAllowanceScheduling = normalizeAllowanceScheduling; exports.normalizeAccountProbe = normalizeAccountProbe; exports.normalizeAudit = normalizeAudit; exports.normalizeBilling = normalizeBilling; exports.DEFAULT_FINGERPRINT = DEFAULT_FINGERPRINT; exports.normalizeFingerprint = normalizeFingerprint; exports.normalizeVoucher = normalizeVoucher; exports.normalizeProxyConfig = normalizeProxyConfig; exports.normalizeProxySegment = normalizeProxySegment; exports.normalizeWebhookDestination = normalizeWebhookDestination; exports.normalizeWebhookSegment = normalizeWebhookSegment; exports.normalizeQueueSegments = normalizeQueueSegments; exports.normalizePrefixTargets = normalizePrefixTargets; exports.legacyEndpointsToBindings = legacyEndpointsToBindings; exports.normalizeGatewayBindings = normalizeGatewayBindings; exports.defaultServerConfig = defaultServerConfig; exports.normalizeServerConfig = normalizeServerConfig; exports.loadServerConfig = loadServerConfig; exports.saveServerConfig = saveServerConfig; exports.mergeServerConfig = mergeServerConfig; exports.injectMappingEffortDefault = injectMappingEffortDefault; exports.computeKeyExpiry = computeKeyExpiry; exports.checkKeyQuota = checkKeyQuota; exports.randomBase62 = randomBase62; exports.hashKey = hashKey; exports.createNamedKey = createNamedKey; exports.createIntegrationKey = createIntegrationKey; exports.LEGACY_OUTBOUND_PERMISSIONS = LEGACY_OUTBOUND_PERMISSIONS; exports.validateOutboundPermissions = validateOutboundPermissions; exports.effectiveOutboundPermissions = effectiveOutboundPermissions; exports.verifyKey = verifyKey; exports.verifyPresentedKey = verifyPresentedKey; exports.ConcurrencyQueueFullError = ConcurrencyQueueFullError; exports.ConcurrencyWaitTimeoutError = ConcurrencyWaitTimeoutError; exports.ConcurrencyWaitCancelledError = ConcurrencyWaitCancelledError; exports.isConcurrencyRejection = isConcurrencyRejection; exports.OutboundConcurrencyGate = OutboundConcurrencyGate; exports.OutboundRateLimiter = OutboundRateLimiter; exports.codexSearchRoutePath = codexSearchRoutePath; exports.isCodexSearchRequest = isCodexSearchRequest; exports.handleCodexSearchRequest = handleCodexSearchRequest; exports.isUserMessageRequest = isUserMessageRequest; exports.SerialQueueTimeoutError = SerialQueueTimeoutError; exports.isSerialQueueTimeout = isSerialQueueTimeout; exports.UserMessageSerialQueue = UserMessageSerialQueue; exports.generateVoucherCode = generateVoucherCode; exports.hashVoucherCode = hashVoucherCode; exports.voucherCodePrefix = voucherCodePrefix; exports.newVoucherId = newVoucherId; exports.computeVoucherGrant = computeVoucherGrant; exports.toVoucherInfo = toVoucherInfo; exports.isRedeemRequest = isRedeemRequest; exports.handleVoucherRedeem = handleVoucherRedeem; exports.DEFAULT_OUTBOUND_PORT = DEFAULT_OUTBOUND_PORT; exports.OutboundApiServer = OutboundApiServer; exports.formatUrls = formatUrls; exports.startOfLocalDay = startOfLocalDay; exports.startOfLocalWeek = startOfLocalWeek; exports.KeySpendTracker = KeySpendTracker; exports.getOutboundApiServer = getOutboundApiServer; exports.__resetOutboundApiServerForTests = __resetOutboundApiServerForTests;
|