@omnicross/core 0.3.0 → 0.4.0
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/auth/GeminiCodeAssistProjectResolver.cjs +3 -3
- package/dist/auth/GeminiCodeAssistProjectResolver.js +2 -2
- package/dist/{chunk-HVBBDBS3.cjs → chunk-2T6D7LWE.cjs} +96 -9
- package/dist/{chunk-VL5TUDTM.js → chunk-5DJSOFEP.js} +6 -1
- package/dist/{chunk-LKDAN4D7.js → chunk-5TEWZN5J.js} +112 -38
- package/dist/{chunk-6QQG7YG3.cjs → chunk-BKXC4XM6.cjs} +3 -3
- package/dist/{chunk-OPRS4IQZ.js → chunk-C3NPMQTK.js} +2 -2
- package/dist/{chunk-HOMUGKHR.js → chunk-GTDQCW3H.js} +29 -2
- package/dist/{chunk-23S5OPIO.js → chunk-HDXSPXIN.js} +1 -1
- package/dist/{chunk-MKF46GNZ.js → chunk-PF7YQBKX.js} +91 -4
- package/dist/{chunk-VSYQ6XYN.cjs → chunk-QEOV6Y4E.cjs} +516 -442
- package/dist/{chunk-U47LQXPB.js → chunk-QRXOLINS.js} +4 -1
- package/dist/{chunk-YNJNTCSQ.cjs → chunk-TX3AEV6H.cjs} +2 -2
- package/dist/{chunk-OIKREZVQ.cjs → chunk-TX4UCSOP.cjs} +30 -3
- package/dist/{chunk-T6NWPIYZ.cjs → chunk-YEVWA4C7.cjs} +4 -1
- package/dist/{chunk-4Z3ZLLC2.cjs → chunk-ZSA44G7J.cjs} +13 -8
- package/dist/completion/CompletionService.cjs +8 -8
- package/dist/completion/CompletionService.js +7 -7
- package/dist/completion.cjs +14 -8
- package/dist/completion.d.cts +22 -1
- package/dist/completion.d.ts +22 -1
- package/dist/completion.js +14 -8
- package/dist/index.cjs +14 -8
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +14 -8
- package/dist/outbound-api/routeResolver.cjs +2 -2
- package/dist/outbound-api/routeResolver.js +1 -1
- package/dist/outbound-api.cjs +8 -8
- package/dist/outbound-api.js +7 -7
- package/dist/pipeline/AccountAllowanceScheduling.cjs +3 -3
- package/dist/pipeline/AccountAllowanceScheduling.js +2 -2
- package/dist/pipeline/AccountAllowanceStore.cjs +6 -2
- package/dist/pipeline/AccountAllowanceStore.d.cts +41 -1
- package/dist/pipeline/AccountAllowanceStore.d.ts +41 -1
- package/dist/pipeline/AccountAllowanceStore.js +5 -1
- package/dist/pipeline/LlmConfigProviderAuth.cjs +2 -2
- package/dist/pipeline/LlmConfigProviderAuth.js +1 -1
- package/dist/pipeline/SubscriptionAuthSource.cjs +4 -4
- package/dist/pipeline/SubscriptionAuthSource.js +3 -3
- package/dist/pipeline/upstreamFetch.cjs +3 -3
- package/dist/pipeline/upstreamFetch.js +2 -2
- package/dist/provider-proxy/ProviderProxy.cjs +8 -8
- package/dist/provider-proxy/ProviderProxy.js +7 -7
- package/dist/provider-proxy/ingress/providerProxyShared.cjs +8 -8
- package/dist/provider-proxy/ingress/providerProxyShared.js +7 -7
- package/dist/provider-proxy.cjs +8 -8
- package/dist/provider-proxy.js +7 -7
- package/package.json +2 -2
|
@@ -62,7 +62,7 @@ var _chunkKQBLZMP6cjs = require('./chunk-KQBLZMP6.cjs');
|
|
|
62
62
|
|
|
63
63
|
|
|
64
64
|
|
|
65
|
-
var
|
|
65
|
+
var _chunkTX4UCSOPcjs = require('./chunk-TX4UCSOP.cjs');
|
|
66
66
|
|
|
67
67
|
|
|
68
68
|
var _chunkQXD4MV2Xcjs = require('./chunk-QXD4MV2X.cjs');
|
|
@@ -78,13 +78,13 @@ var _chunkOTZC4TNHcjs = require('./chunk-OTZC4TNH.cjs');
|
|
|
78
78
|
var _chunk7LRTPNFLcjs = require('./chunk-7LRTPNFL.cjs');
|
|
79
79
|
|
|
80
80
|
|
|
81
|
-
var
|
|
81
|
+
var _chunkTX3AEV6Hcjs = require('./chunk-TX3AEV6H.cjs');
|
|
82
82
|
|
|
83
83
|
|
|
84
84
|
var _chunkSVNDB62Dcjs = require('./chunk-SVNDB62D.cjs');
|
|
85
85
|
|
|
86
86
|
|
|
87
|
-
var
|
|
87
|
+
var _chunkBKXC4XM6cjs = require('./chunk-BKXC4XM6.cjs');
|
|
88
88
|
|
|
89
89
|
|
|
90
90
|
|
|
@@ -109,7 +109,7 @@ var _chunk4YINUUKQcjs = require('./chunk-4YINUUKQ.cjs');
|
|
|
109
109
|
|
|
110
110
|
|
|
111
111
|
|
|
112
|
-
var
|
|
112
|
+
var _chunkYEVWA4C7cjs = require('./chunk-YEVWA4C7.cjs');
|
|
113
113
|
|
|
114
114
|
|
|
115
115
|
var _chunkQBZJ7P2Tcjs = require('./chunk-QBZJ7P2T.cjs');
|
|
@@ -137,10 +137,10 @@ var _chunkGDIXXKF2cjs = require('./chunk-GDIXXKF2.cjs');
|
|
|
137
137
|
var _chunkIUL4VWNUcjs = require('./chunk-IUL4VWNU.cjs');
|
|
138
138
|
|
|
139
139
|
|
|
140
|
-
var
|
|
140
|
+
var _chunkZSA44G7Jcjs = require('./chunk-ZSA44G7J.cjs');
|
|
141
141
|
|
|
142
142
|
|
|
143
|
-
var
|
|
143
|
+
var _chunk2T6D7LWEcjs = require('./chunk-2T6D7LWE.cjs');
|
|
144
144
|
|
|
145
145
|
|
|
146
146
|
var _chunkNKVZ6Z3Ycjs = require('./chunk-NKVZ6Z3Y.cjs');
|
|
@@ -1545,7 +1545,7 @@ async function buildSubscriptionPlan(res, route, deps, anthropicBody, routeModel
|
|
|
1545
1545
|
function buildSubscriptionIterationPlan(profile, route, deps, resolvedModel, isStream, scenario, sessionKey) {
|
|
1546
1546
|
const upstreamUrl = _optionalChain([profile, 'access', _103 => _103.resolveUpstreamUrl, 'optionalCall', _104 => _104(resolvedModel, route.subscriptionConfig)]);
|
|
1547
1547
|
if (!upstreamUrl) return null;
|
|
1548
|
-
const auth = _nullishCoalesce(route.auth, () => ( new (0,
|
|
1548
|
+
const auth = _nullishCoalesce(route.auth, () => ( new (0, _chunkTX3AEV6Hcjs.SubscriptionAuthSource)(profile)));
|
|
1549
1549
|
const sameFormat = profile.mode === "pass-through" || upstreamUrl.endsWith("/v1/messages");
|
|
1550
1550
|
const overrideNames = _optionalChain([profile, 'access', _105 => _105.resolveProviderTransformerNames, 'optionalCall', _106 => _106(
|
|
1551
1551
|
resolvedModel,
|
|
@@ -1669,7 +1669,7 @@ async function runPipeline(anthropicBody, plan, reportSelection, signal) {
|
|
|
1669
1669
|
},
|
|
1670
1670
|
fetchFn: (url, headers, body) => {
|
|
1671
1671
|
console.info(`[ProviderProxy:anthropic] -> ${url} model=${resolvedModel} stream=${isStream}`);
|
|
1672
|
-
return
|
|
1672
|
+
return _chunkZSA44G7Jcjs.fetchUpstream.call(void 0,
|
|
1673
1673
|
url,
|
|
1674
1674
|
{ method: "POST", headers, body: JSON.stringify(body), signal },
|
|
1675
1675
|
{
|
|
@@ -1739,7 +1739,7 @@ async function runSubscriptionSameFormatFetch(rawBody, plan, reportSelection, op
|
|
|
1739
1739
|
`[ProviderProxy:anthropic] (subscription same-format) -> ${_nullishCoalesce(urlOverride, () => ( plan.upstreamUrl))} model=${outboundModel} stream=${plan.isStream}`
|
|
1740
1740
|
);
|
|
1741
1741
|
let activityRecordId;
|
|
1742
|
-
const response = await
|
|
1742
|
+
const response = await _chunkZSA44G7Jcjs.fetchUpstream.call(void 0,
|
|
1743
1743
|
_nullishCoalesce(urlOverride, () => ( plan.upstreamUrl)),
|
|
1744
1744
|
{ method: "POST", headers, body: outboundBody, signal: options.signal },
|
|
1745
1745
|
{
|
|
@@ -2297,6 +2297,67 @@ function recordResponsesStreamUsage(recorder, rawUsage, attribution) {
|
|
|
2297
2297
|
}
|
|
2298
2298
|
}
|
|
2299
2299
|
|
|
2300
|
+
// src/provider-proxy/ingress/codexUsageLimitDetection.ts
|
|
2301
|
+
var PROVIDER_ID = "codex";
|
|
2302
|
+
var DEFAULT_QUOTA_COOLDOWN_MS = 5 * 6e4;
|
|
2303
|
+
var QUOTA_EXHAUSTED_PERCENT = 90;
|
|
2304
|
+
var BODY_SCAN_LIMIT = 4096;
|
|
2305
|
+
function parseTryAgainDeadline(bodyText) {
|
|
2306
|
+
const match = bodyText.match(/try again (?:at|on)\s+(.+?)(?:[.\n]|$)/i);
|
|
2307
|
+
if (!match) return void 0;
|
|
2308
|
+
const cleaned = match[1].replace(/(\d+)(st|nd|rd|th)/giu, "$1").trim();
|
|
2309
|
+
const ms = Date.parse(cleaned);
|
|
2310
|
+
return Number.isFinite(ms) ? ms : void 0;
|
|
2311
|
+
}
|
|
2312
|
+
var CODEX_USAGE_LIMIT_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
2313
|
+
"usage_limit_reached",
|
|
2314
|
+
"usage_not_included",
|
|
2315
|
+
"rate_limit_exceeded"
|
|
2316
|
+
]);
|
|
2317
|
+
function parseCodexUsageLimitErrorPayload(bodyText) {
|
|
2318
|
+
const raw = bodyText.slice(0, BODY_SCAN_LIMIT * 4).trim();
|
|
2319
|
+
if (!raw.startsWith("{")) return null;
|
|
2320
|
+
try {
|
|
2321
|
+
const parsed = JSON.parse(raw);
|
|
2322
|
+
const error = _optionalChain([parsed, 'optionalAccess', _129 => _129.error]);
|
|
2323
|
+
const code = _optionalChain([error, 'optionalAccess', _130 => _130.code]);
|
|
2324
|
+
if (typeof code !== "string" || !CODEX_USAGE_LIMIT_ERROR_CODES.has(code)) return null;
|
|
2325
|
+
const resetsAt = _optionalChain([error, 'optionalAccess', _131 => _131.resets_at]);
|
|
2326
|
+
let resetsAtMs;
|
|
2327
|
+
if (typeof resetsAt === "number" && Number.isFinite(resetsAt) && resetsAt > 0) {
|
|
2328
|
+
resetsAtMs = resetsAt > 1e11 ? resetsAt : resetsAt * 1e3;
|
|
2329
|
+
}
|
|
2330
|
+
const planType = _optionalChain([error, 'optionalAccess', _132 => _132.plan_type]);
|
|
2331
|
+
return {
|
|
2332
|
+
code,
|
|
2333
|
+
...resetsAtMs !== void 0 ? { resetsAtMs } : {},
|
|
2334
|
+
...typeof planType === "string" && planType ? { planType } : {}
|
|
2335
|
+
};
|
|
2336
|
+
} catch (e21) {
|
|
2337
|
+
return null;
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
function deadlineFromAllowanceSnapshot(accountId, now) {
|
|
2341
|
+
const snapshot = _chunk2T6D7LWEcjs.getSharedAccountAllowanceStore.call(void 0, ).get(PROVIDER_ID, accountId, now);
|
|
2342
|
+
if (!snapshot) return void 0;
|
|
2343
|
+
const candidates = snapshot.windows.filter(
|
|
2344
|
+
(w) => typeof w.usedPercent === "number" && w.usedPercent >= QUOTA_EXHAUSTED_PERCENT && typeof w.resetsAt === "string"
|
|
2345
|
+
).map((w) => ({ ms: Date.parse(w.resetsAt), usedPercent: w.usedPercent })).filter((x) => Number.isFinite(x.ms) && x.ms > now).sort((a, b) => b.usedPercent - a.usedPercent);
|
|
2346
|
+
return _optionalChain([candidates, 'access', _133 => _133[0], 'optionalAccess', _134 => _134.ms]);
|
|
2347
|
+
}
|
|
2348
|
+
function resolveCodexQuotaDeadline(accountId, bodyText, now = Date.now()) {
|
|
2349
|
+
const structured = parseCodexUsageLimitErrorPayload(bodyText);
|
|
2350
|
+
const structuredDeadline = _optionalChain([structured, 'optionalAccess', _135 => _135.resetsAtMs]) !== void 0 && structured.resetsAtMs > now ? structured.resetsAtMs : void 0;
|
|
2351
|
+
const parsed = parseTryAgainDeadline(bodyText);
|
|
2352
|
+
const parsedDeadline = parsed !== void 0 && parsed > now ? parsed : void 0;
|
|
2353
|
+
return _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(deadlineFromAllowanceSnapshot(accountId, now), () => ( structuredDeadline)), () => ( parsedDeadline)), () => ( now + DEFAULT_QUOTA_COOLDOWN_MS));
|
|
2354
|
+
}
|
|
2355
|
+
function markCodexUsageLimitExhaustion(accountId, bodyText, now = Date.now()) {
|
|
2356
|
+
if (!accountId) return;
|
|
2357
|
+
const deadline = resolveCodexQuotaDeadline(accountId, bodyText, now);
|
|
2358
|
+
_chunk7LRTPNFLcjs.getSharedAccountHealth.call(void 0, ).markQuotaExhausted(PROVIDER_ID, accountId, deadline, now);
|
|
2359
|
+
}
|
|
2360
|
+
|
|
2300
2361
|
// src/provider-proxy/responses/responsesAffinity.ts
|
|
2301
2362
|
function previousResponseNotFound() {
|
|
2302
2363
|
return new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({
|
|
@@ -2338,7 +2399,7 @@ function normalizeHostedImageState(value) {
|
|
|
2338
2399
|
hasImageContext: value.hasImageContext,
|
|
2339
2400
|
pendingReceipts: Object.freeze(pendingReceipts)
|
|
2340
2401
|
});
|
|
2341
|
-
} catch (
|
|
2402
|
+
} catch (e22) {
|
|
2342
2403
|
throw new TypeError(INVALID_HOSTED_IMAGE_METADATA);
|
|
2343
2404
|
}
|
|
2344
2405
|
}
|
|
@@ -2382,7 +2443,7 @@ var ResponsesAffinityStore = (_class6 = class {
|
|
|
2382
2443
|
const entry = this.entries.get(responseId);
|
|
2383
2444
|
const now = this.now();
|
|
2384
2445
|
if (!entry || entry.expiresAt <= now || entry.providerId !== scope.providerId || entry.clientScope !== scope.clientScope || entry.sessionKey !== scope.sessionKey) {
|
|
2385
|
-
if (_optionalChain([entry, 'optionalAccess',
|
|
2446
|
+
if (_optionalChain([entry, 'optionalAccess', _136 => _136.expiresAt]) !== void 0 && entry.expiresAt <= now) {
|
|
2386
2447
|
this.entries.delete(responseId);
|
|
2387
2448
|
}
|
|
2388
2449
|
throw previousResponseNotFound();
|
|
@@ -2412,42 +2473,12 @@ function getResponsesAffinityStore(owner) {
|
|
|
2412
2473
|
return store;
|
|
2413
2474
|
}
|
|
2414
2475
|
|
|
2415
|
-
// src/provider-proxy/ingress/codexUsageLimitDetection.ts
|
|
2416
|
-
var PROVIDER_ID = "codex";
|
|
2417
|
-
var DEFAULT_QUOTA_COOLDOWN_MS = 5 * 6e4;
|
|
2418
|
-
var QUOTA_EXHAUSTED_PERCENT = 90;
|
|
2419
|
-
function parseTryAgainDeadline(bodyText) {
|
|
2420
|
-
const match = bodyText.match(/try again (?:at|on)\s+(.+?)(?:[.\n]|$)/i);
|
|
2421
|
-
if (!match) return void 0;
|
|
2422
|
-
const cleaned = match[1].replace(/(\d+)(st|nd|rd|th)/giu, "$1").trim();
|
|
2423
|
-
const ms = Date.parse(cleaned);
|
|
2424
|
-
return Number.isFinite(ms) ? ms : void 0;
|
|
2425
|
-
}
|
|
2426
|
-
function deadlineFromAllowanceSnapshot(accountId, now) {
|
|
2427
|
-
const snapshot = _chunkHVBBDBS3cjs.getSharedAccountAllowanceStore.call(void 0, ).get(PROVIDER_ID, accountId, now);
|
|
2428
|
-
if (!snapshot) return void 0;
|
|
2429
|
-
const candidates = snapshot.windows.filter(
|
|
2430
|
-
(w) => typeof w.usedPercent === "number" && w.usedPercent >= QUOTA_EXHAUSTED_PERCENT && typeof w.resetsAt === "string"
|
|
2431
|
-
).map((w) => ({ ms: Date.parse(w.resetsAt), usedPercent: w.usedPercent })).filter((x) => Number.isFinite(x.ms) && x.ms > now).sort((a, b) => b.usedPercent - a.usedPercent);
|
|
2432
|
-
return _optionalChain([candidates, 'access', _130 => _130[0], 'optionalAccess', _131 => _131.ms]);
|
|
2433
|
-
}
|
|
2434
|
-
function resolveCodexQuotaDeadline(accountId, bodyText, now = Date.now()) {
|
|
2435
|
-
const parsed = parseTryAgainDeadline(bodyText);
|
|
2436
|
-
const parsedDeadline = parsed !== void 0 && parsed > now ? parsed : void 0;
|
|
2437
|
-
return _nullishCoalesce(_nullishCoalesce(deadlineFromAllowanceSnapshot(accountId, now), () => ( parsedDeadline)), () => ( now + DEFAULT_QUOTA_COOLDOWN_MS));
|
|
2438
|
-
}
|
|
2439
|
-
function markCodexUsageLimitExhaustion(accountId, bodyText, now = Date.now()) {
|
|
2440
|
-
if (!accountId) return;
|
|
2441
|
-
const deadline = resolveCodexQuotaDeadline(accountId, bodyText, now);
|
|
2442
|
-
_chunk7LRTPNFLcjs.getSharedAccountHealth.call(void 0, ).markQuotaExhausted(PROVIDER_ID, accountId, deadline, now);
|
|
2443
|
-
}
|
|
2444
|
-
|
|
2445
2476
|
// src/provider-proxy/responses/responsesProfile.ts
|
|
2446
2477
|
function classifyResponsesProfile(declaration) {
|
|
2447
2478
|
if (declaration.authMode === "byo") {
|
|
2448
2479
|
return declaration.providerApiFormat === "openai-response" ? "native" : "reduced";
|
|
2449
2480
|
}
|
|
2450
|
-
if (declaration.subscriptionProviderId === "codex" && _optionalChain([declaration, 'access',
|
|
2481
|
+
if (declaration.subscriptionProviderId === "codex" && _optionalChain([declaration, 'access', _137 => _137.subscriptionTransformerNames, 'optionalAccess', _138 => _138.includes, 'call', _139 => _139("openai-response")]) && isResponsesCreateUrl(declaration.upstreamUrl)) {
|
|
2451
2482
|
return "native";
|
|
2452
2483
|
}
|
|
2453
2484
|
return "reduced";
|
|
@@ -2467,7 +2498,7 @@ function isResponsesCreateUrl(value) {
|
|
|
2467
2498
|
if (!value) return false;
|
|
2468
2499
|
try {
|
|
2469
2500
|
return new URL(value).pathname.replace(/\/+$/, "").endsWith("/responses");
|
|
2470
|
-
} catch (
|
|
2501
|
+
} catch (e23) {
|
|
2471
2502
|
return false;
|
|
2472
2503
|
}
|
|
2473
2504
|
}
|
|
@@ -2637,7 +2668,7 @@ function deriveResponsesCompactUrl(createUrl) {
|
|
|
2637
2668
|
let url;
|
|
2638
2669
|
try {
|
|
2639
2670
|
url = new URL(createUrl);
|
|
2640
|
-
} catch (
|
|
2671
|
+
} catch (e24) {
|
|
2641
2672
|
throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({
|
|
2642
2673
|
status: 502,
|
|
2643
2674
|
code: "invalid_upstream_url",
|
|
@@ -2679,7 +2710,7 @@ async function resolveResponsesRouteProfile(route, deps, resolvedModel) {
|
|
|
2679
2710
|
if (!subscriptionProfile) {
|
|
2680
2711
|
throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({ status: 502, code: "provider_configuration_error", message: "Subscription route is missing its profile" });
|
|
2681
2712
|
}
|
|
2682
|
-
const upstreamUrl = _optionalChain([subscriptionProfile, 'access',
|
|
2713
|
+
const upstreamUrl = _optionalChain([subscriptionProfile, 'access', _140 => _140.resolveUpstreamUrl, 'optionalCall', _141 => _141(resolvedModel)]);
|
|
2683
2714
|
if (!upstreamUrl) {
|
|
2684
2715
|
throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({ status: 502, code: "provider_configuration_error", message: "Subscription profile is missing its Responses URL" });
|
|
2685
2716
|
}
|
|
@@ -2716,7 +2747,7 @@ async function buildResponsesCallPlan(route, deps, resolved, resolvedModel, isSt
|
|
|
2716
2747
|
async function buildByoPlan(route, deps, resolved, resolvedModel, isStream, affinity) {
|
|
2717
2748
|
const providerId = route.providerId;
|
|
2718
2749
|
const provider = resolved.provider;
|
|
2719
|
-
const affinityKeyId = _optionalChain([affinity, 'optionalAccess',
|
|
2750
|
+
const affinityKeyId = _optionalChain([affinity, 'optionalAccess', _142 => _142.credential, 'access', _143 => _143.kind]) === "byo-key" ? affinity.credential.id : void 0;
|
|
2720
2751
|
const preferredKeyId = _nullishCoalesce(affinityKeyId, () => ( route.preferredKeyId));
|
|
2721
2752
|
const apiKey = await resolvePoolBoundKey(
|
|
2722
2753
|
deps,
|
|
@@ -2730,9 +2761,9 @@ async function buildByoPlan(route, deps, resolved, resolvedModel, isStream, affi
|
|
|
2730
2761
|
if (affinity) throw previousResponseNotFound();
|
|
2731
2762
|
throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({ status: 502, code: "provider_configuration_error", message: "Provider credential is unavailable" });
|
|
2732
2763
|
}
|
|
2733
|
-
const selectedKeyId = _nullishCoalesce(preferredKeyId, () => ( (route.sessionId && typeof _optionalChain([deps, 'access',
|
|
2764
|
+
const selectedKeyId = _nullishCoalesce(preferredKeyId, () => ( (route.sessionId && typeof _optionalChain([deps, 'access', _144 => _144.apiKeyPool, 'optionalAccess', _145 => _145.getKeyIdForSession]) === "function" ? _nullishCoalesce(deps.apiKeyPool.getKeyIdForSession(providerId, route.sessionId), () => ( void 0)) : void 0)));
|
|
2734
2765
|
const credential = selectedKeyId ? { kind: "byo-key", id: selectedKeyId } : { kind: "provider-key", id: providerId };
|
|
2735
|
-
const auth = affinityKeyId ? new (0,
|
|
2766
|
+
const auth = affinityKeyId ? new (0, _chunkTX4UCSOPcjs.LlmConfigProviderAuth)({ provider, apiKey, apiKeyPool: null, providerId, sessionId: route.sessionId }) : _nullishCoalesce(route.auth, () => ( new (0, _chunkTX4UCSOPcjs.LlmConfigProviderAuth)({
|
|
2736
2767
|
provider,
|
|
2737
2768
|
apiKey,
|
|
2738
2769
|
apiKeyPool: _nullishCoalesce(deps.apiKeyPool, () => ( null)),
|
|
@@ -2762,7 +2793,7 @@ async function buildByoPlan(route, deps, resolved, resolvedModel, isStream, affi
|
|
|
2762
2793
|
statefulContinuation: !!affinity,
|
|
2763
2794
|
credential,
|
|
2764
2795
|
resolveCredential: () => {
|
|
2765
|
-
const keyId = route.sessionId && typeof _optionalChain([deps, 'access',
|
|
2796
|
+
const keyId = route.sessionId && typeof _optionalChain([deps, 'access', _146 => _146.apiKeyPool, 'optionalAccess', _147 => _147.getKeyIdForSession]) === "function" ? deps.apiKeyPool.getKeyIdForSession(providerId, route.sessionId) : null;
|
|
2766
2797
|
return keyId ? { kind: "byo-key", id: keyId } : credential;
|
|
2767
2798
|
}
|
|
2768
2799
|
};
|
|
@@ -2770,8 +2801,8 @@ async function buildByoPlan(route, deps, resolved, resolvedModel, isStream, affi
|
|
|
2770
2801
|
async function buildSubscriptionPlan2(route, deps, resolved, resolvedModel, isStream, sessionKey, sessionSource, requestHeaders, affinity) {
|
|
2771
2802
|
const profile = route.subscriptionProfile;
|
|
2772
2803
|
const upstreamUrl = resolved.upstreamUrl;
|
|
2773
|
-
const affinityAccountId = _optionalChain([affinity, 'optionalAccess',
|
|
2774
|
-
const auth = _nullishCoalesce(route.auth, () => ( new (0,
|
|
2804
|
+
const affinityAccountId = _optionalChain([affinity, 'optionalAccess', _148 => _148.credential, 'access', _149 => _149.kind]) === "subscription-account" ? affinity.credential.id : void 0;
|
|
2805
|
+
const auth = _nullishCoalesce(route.auth, () => ( new (0, _chunkTX3AEV6Hcjs.SubscriptionAuthSource)(profile)));
|
|
2775
2806
|
const chain = resolved.profile === "native" ? { providerTransformers: [], modelTransformers: [] } : _chunkNYUNU75Acjs.resolveSubscriptionChain.call(void 0,
|
|
2776
2807
|
profile,
|
|
2777
2808
|
deps.llmConfig.getTransformerService(),
|
|
@@ -2817,7 +2848,7 @@ async function resolveGeminiProject(profile, hints) {
|
|
|
2817
2848
|
await profile.authStrategy.applyHeaders(headers, hints);
|
|
2818
2849
|
const accessToken = (_nullishCoalesce(_nullishCoalesce(headers.Authorization, () => ( headers.authorization)), () => ( ""))).replace(/^Bearer\s+/i, "").trim();
|
|
2819
2850
|
if (!accessToken) return void 0;
|
|
2820
|
-
return _optionalChain([_chunkR3HK6R4Bcjs.getGeminiCodeAssistResolver.call(void 0, ), 'optionalAccess',
|
|
2851
|
+
return _optionalChain([_chunkR3HK6R4Bcjs.getGeminiCodeAssistResolver.call(void 0, ), 'optionalAccess', _150 => _150.resolveProject, 'call', _151 => _151(accessToken)]);
|
|
2821
2852
|
}
|
|
2822
2853
|
async function executeResponsesUpstream(body, plan, operation, signal) {
|
|
2823
2854
|
const run = () => plan.profile === "native" ? runNative(body, plan, operation, signal) : runReduced(body, plan, signal);
|
|
@@ -2825,16 +2856,16 @@ async function executeResponsesUpstream(body, plan, operation, signal) {
|
|
|
2825
2856
|
throwIfResponsesAborted(signal);
|
|
2826
2857
|
if (!plan.statefulContinuation) {
|
|
2827
2858
|
if (plan.proxyProviderId === "byo") {
|
|
2828
|
-
const outcome = await _optionalChain([plan, 'access',
|
|
2829
|
-
if (_optionalChain([outcome, 'optionalAccess',
|
|
2830
|
-
await _optionalChain([result, 'access',
|
|
2859
|
+
const outcome = await _optionalChain([plan, 'access', _152 => _152.auth, 'access', _153 => _153.onResult, 'optionalCall', _154 => _154(result.rawStatus)]);
|
|
2860
|
+
if (_optionalChain([outcome, 'optionalAccess', _155 => _155.rebound])) {
|
|
2861
|
+
await _optionalChain([result, 'access', _156 => _156.response, 'access', _157 => _157.body, 'optionalAccess', _158 => _158.cancel, 'call', _159 => _159(), 'access', _160 => _160.catch, 'call', _161 => _161(() => void 0)]);
|
|
2831
2862
|
throwIfResponsesAborted(signal);
|
|
2832
2863
|
result = await run();
|
|
2833
2864
|
}
|
|
2834
2865
|
} else if (result.rawStatus === 401) {
|
|
2835
|
-
const refreshed = await _optionalChain([plan, 'access',
|
|
2866
|
+
const refreshed = await _optionalChain([plan, 'access', _162 => _162.auth, 'access', _163 => _163.onUnauthorized, 'optionalCall', _164 => _164(plan.sessionKey)]);
|
|
2836
2867
|
if (refreshed) {
|
|
2837
|
-
await _optionalChain([result, 'access',
|
|
2868
|
+
await _optionalChain([result, 'access', _165 => _165.response, 'access', _166 => _166.body, 'optionalAccess', _167 => _167.cancel, 'call', _168 => _168(), 'access', _169 => _169.catch, 'call', _170 => _170(() => void 0)]);
|
|
2838
2869
|
throwIfResponsesAborted(signal);
|
|
2839
2870
|
result = await run();
|
|
2840
2871
|
}
|
|
@@ -2876,7 +2907,7 @@ async function runNative(body, plan, operation, signal) {
|
|
|
2876
2907
|
decorateCodexHeaders(headers, plan);
|
|
2877
2908
|
const url = operation === "compact" ? deriveResponsesCompactUrl(plan.upstreamUrl) : plan.upstreamUrl;
|
|
2878
2909
|
let activityRecordId;
|
|
2879
|
-
const response = await
|
|
2910
|
+
const response = await _chunkZSA44G7Jcjs.fetchUpstream.call(void 0,
|
|
2880
2911
|
url,
|
|
2881
2912
|
{ method: "POST", headers, body: JSON.stringify(body), signal },
|
|
2882
2913
|
{
|
|
@@ -2899,7 +2930,7 @@ async function runNative(body, plan, operation, signal) {
|
|
|
2899
2930
|
accountId,
|
|
2900
2931
|
actualModel,
|
|
2901
2932
|
activityRecordId,
|
|
2902
|
-
credential: accountId ? { kind: "subscription-account", id: accountId } : _nullishCoalesce(_optionalChain([plan, 'access',
|
|
2933
|
+
credential: accountId ? { kind: "subscription-account", id: accountId } : _nullishCoalesce(_optionalChain([plan, 'access', _171 => _171.resolveCredential, 'optionalCall', _172 => _172()]), () => ( plan.credential))
|
|
2903
2934
|
};
|
|
2904
2935
|
}
|
|
2905
2936
|
async function runReduced(body, plan, signal) {
|
|
@@ -2924,7 +2955,7 @@ async function runReduced(body, plan, signal) {
|
|
|
2924
2955
|
decorateCodexHeaders(headers, plan);
|
|
2925
2956
|
return headers;
|
|
2926
2957
|
},
|
|
2927
|
-
fetchFn: (url, headers, requestBody) =>
|
|
2958
|
+
fetchFn: (url, headers, requestBody) => _chunkZSA44G7Jcjs.fetchUpstream.call(void 0,
|
|
2928
2959
|
url,
|
|
2929
2960
|
{ method: "POST", headers, body: JSON.stringify(requestBody), signal },
|
|
2930
2961
|
{
|
|
@@ -2953,7 +2984,7 @@ async function runReduced(body, plan, signal) {
|
|
|
2953
2984
|
accountId,
|
|
2954
2985
|
actualModel,
|
|
2955
2986
|
activityRecordId,
|
|
2956
|
-
credential: accountId ? { kind: "subscription-account", id: accountId } : _nullishCoalesce(_optionalChain([plan, 'access',
|
|
2987
|
+
credential: accountId ? { kind: "subscription-account", id: accountId } : _nullishCoalesce(_optionalChain([plan, 'access', _173 => _173.resolveCredential, 'optionalCall', _174 => _174()]), () => ( plan.credential))
|
|
2957
2988
|
};
|
|
2958
2989
|
}
|
|
2959
2990
|
var MAX_QUOTA_RETRIES = 3;
|
|
@@ -2976,7 +3007,7 @@ function record(value) {
|
|
|
2976
3007
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
2977
3008
|
}
|
|
2978
3009
|
function hasResponsesHostedImageWork(body, previousState) {
|
|
2979
|
-
if (_optionalChain([previousState, 'optionalAccess',
|
|
3010
|
+
if (_optionalChain([previousState, 'optionalAccess', _175 => _175.hasImageContext]) || _optionalChain([previousState, 'optionalAccess', _176 => _176.pendingReceipts, 'access', _177 => _177.length])) return true;
|
|
2980
3011
|
if (Array.isArray(body.tools) && body.tools.some((tool) => record(tool) && tool.type === "image_generation")) {
|
|
2981
3012
|
return true;
|
|
2982
3013
|
}
|
|
@@ -3160,7 +3191,7 @@ function createNonCollidingSelectorName(tools, createName) {
|
|
|
3160
3191
|
let candidate;
|
|
3161
3192
|
try {
|
|
3162
3193
|
candidate = createName();
|
|
3163
|
-
} catch (
|
|
3194
|
+
} catch (e25) {
|
|
3164
3195
|
throw new (0, _chunkUPQIWJIEcjs.ImageGenerationError)("image_generation_failed");
|
|
3165
3196
|
}
|
|
3166
3197
|
if (typeof candidate === "string" && SELECTOR_NAME_PATTERN.test(candidate) && !declaredNames.has(candidate)) {
|
|
@@ -3179,7 +3210,7 @@ function parseSelectorPrompt(value) {
|
|
|
3179
3210
|
let parsed;
|
|
3180
3211
|
try {
|
|
3181
3212
|
parsed = JSON.parse(value);
|
|
3182
|
-
} catch (
|
|
3213
|
+
} catch (e26) {
|
|
3183
3214
|
protocolFailure();
|
|
3184
3215
|
}
|
|
3185
3216
|
if (!isRecord4(parsed) || Object.keys(parsed).some((key) => key !== "prompt") || typeof parsed.prompt !== "string" || !parsed.prompt.trim() || parsed.prompt.length > 32e3) {
|
|
@@ -3396,7 +3427,7 @@ function parseSelectorArguments(value) {
|
|
|
3396
3427
|
let parsed;
|
|
3397
3428
|
try {
|
|
3398
3429
|
parsed = JSON.parse(value);
|
|
3399
|
-
} catch (
|
|
3430
|
+
} catch (e27) {
|
|
3400
3431
|
return void 0;
|
|
3401
3432
|
}
|
|
3402
3433
|
if (!isRecord5(parsed) || typeof parsed.query !== "string") return void 0;
|
|
@@ -3524,7 +3555,7 @@ var NativeResponsesSearchLease = class {
|
|
|
3524
3555
|
let parsed;
|
|
3525
3556
|
try {
|
|
3526
3557
|
parsed = JSON.parse(text);
|
|
3527
|
-
} catch (
|
|
3558
|
+
} catch (e28) {
|
|
3528
3559
|
return responseWithBody(input.response, text, false);
|
|
3529
3560
|
}
|
|
3530
3561
|
if (!isRecord6(parsed)) return responseWithBody(input.response, text, false);
|
|
@@ -3624,11 +3655,25 @@ function responsesSearchDisabledError() {
|
|
|
3624
3655
|
// src/provider-proxy/ingress/openaiResponsesIngress.ts
|
|
3625
3656
|
var SERVER_OVERLOADED_CODES = /* @__PURE__ */ new Set(["server_is_overloaded", "slow_down"]);
|
|
3626
3657
|
function isCodexServerOverloadEvent(event) {
|
|
3627
|
-
|
|
3628
|
-
const
|
|
3629
|
-
const code = _optionalChain([error, 'optionalAccess', _175 => _175["code"]]);
|
|
3658
|
+
const error = codexResponseFailedError(event);
|
|
3659
|
+
const code = _optionalChain([error, 'optionalAccess', _178 => _178["code"]]);
|
|
3630
3660
|
return typeof code === "string" && SERVER_OVERLOADED_CODES.has(code);
|
|
3631
3661
|
}
|
|
3662
|
+
function codexResponseFailedError(event) {
|
|
3663
|
+
if (event["type"] !== "response.failed") return void 0;
|
|
3664
|
+
const error = _optionalChain([event, 'access', _179 => _179["response"], 'optionalAccess', _180 => _180["error"]]);
|
|
3665
|
+
return error && typeof error === "object" ? error : void 0;
|
|
3666
|
+
}
|
|
3667
|
+
var USAGE_LIMIT_CODES = /* @__PURE__ */ new Set(["usage_limit_reached", "usage_not_included"]);
|
|
3668
|
+
function isCodexUsageLimitEvent(event) {
|
|
3669
|
+
const error = codexResponseFailedError(event);
|
|
3670
|
+
const code = _optionalChain([error, 'optionalAccess', _181 => _181["code"]]);
|
|
3671
|
+
return typeof code === "string" && USAGE_LIMIT_CODES.has(code);
|
|
3672
|
+
}
|
|
3673
|
+
function codexUsageLimitEventBody(event) {
|
|
3674
|
+
const error = codexResponseFailedError(event);
|
|
3675
|
+
return JSON.stringify({ error: _nullishCoalesce(error, () => ( {})) });
|
|
3676
|
+
}
|
|
3632
3677
|
var SAFE_INJECTED_CACHE_KEY_SOURCES = /* @__PURE__ */ new Set([
|
|
3633
3678
|
"session-header",
|
|
3634
3679
|
"thread-header",
|
|
@@ -3656,7 +3701,7 @@ async function handleOpenAIResponsesRequest(res, rawBody, route, deps, requestHe
|
|
|
3656
3701
|
let parsedBody;
|
|
3657
3702
|
try {
|
|
3658
3703
|
parsedBody = JSON.parse(rawBody);
|
|
3659
|
-
} catch (
|
|
3704
|
+
} catch (e29) {
|
|
3660
3705
|
writeError(res, 400, "Invalid JSON in request body");
|
|
3661
3706
|
return;
|
|
3662
3707
|
}
|
|
@@ -3669,7 +3714,7 @@ async function handleOpenAIResponsesRequest(res, rawBody, route, deps, requestHe
|
|
|
3669
3714
|
return;
|
|
3670
3715
|
}
|
|
3671
3716
|
const responsesBody = parsedBody;
|
|
3672
|
-
_optionalChain([onStreamModeResolved, 'optionalCall',
|
|
3717
|
+
_optionalChain([onStreamModeResolved, 'optionalCall', _182 => _182(responsesBody.stream === true)]);
|
|
3673
3718
|
try {
|
|
3674
3719
|
await handleResponsesOperation(
|
|
3675
3720
|
res,
|
|
@@ -3702,7 +3747,7 @@ async function handleOpenAIResponsesRequest(res, rawBody, route, deps, requestHe
|
|
|
3702
3747
|
}
|
|
3703
3748
|
const errMsg = _chunkSVNDB62Dcjs.serializeError.call(void 0, err);
|
|
3704
3749
|
console.error("[ProviderProxy:responses] Pipeline error:", errMsg);
|
|
3705
|
-
writeError(res,
|
|
3750
|
+
writeError(res, _chunkBKXC4XM6cjs.isAccountAllowanceExhaustedError.call(void 0, err) ? 429 : 502, errMsg);
|
|
3706
3751
|
}
|
|
3707
3752
|
return;
|
|
3708
3753
|
}
|
|
@@ -3749,7 +3794,7 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
|
|
|
3749
3794
|
throw error;
|
|
3750
3795
|
}
|
|
3751
3796
|
const cacheKeyAttribution = operation === "create" ? ensureCodexPromptCacheKey(responsesBody, plan.proxyProviderId, derivedSession) : { cacheKeySource: "none", cacheKeyInjected: false };
|
|
3752
|
-
const previousHostedImageState = _optionalChain([affinity, 'optionalAccess',
|
|
3797
|
+
const previousHostedImageState = _optionalChain([affinity, 'optionalAccess', _183 => _183.hostedImage]);
|
|
3753
3798
|
const hasHostedImageWork = operation === "create" && hasResponsesHostedImageWork(
|
|
3754
3799
|
responsesBody,
|
|
3755
3800
|
previousHostedImageState
|
|
@@ -3779,7 +3824,7 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
|
|
|
3779
3824
|
message: "Hosted image generation requires an authenticated outbound key"
|
|
3780
3825
|
});
|
|
3781
3826
|
}
|
|
3782
|
-
const searchMode = operation === "create" ? _nullishCoalesce(_optionalChain([deps, 'access',
|
|
3827
|
+
const searchMode = operation === "create" ? _nullishCoalesce(_optionalChain([deps, 'access', _184 => _184.searchFrontendModes, 'optionalAccess', _185 => _185.responses]), () => ( _chunkE4QHVXV5cjs.DEFAULT_SEARCH_FRONTEND_MODES.responses)) : "native";
|
|
3783
3828
|
const wantsHostedSearch = operation === "create" && hasResponsesHostedSearchWork(responsesBody);
|
|
3784
3829
|
if (wantsHostedSearch && searchMode === "off") {
|
|
3785
3830
|
throw responsesSearchDisabledError();
|
|
@@ -3834,16 +3879,16 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
|
|
|
3834
3879
|
let providerResponse;
|
|
3835
3880
|
try {
|
|
3836
3881
|
if (hostedImageRequest) {
|
|
3837
|
-
_optionalChain([route, 'access',
|
|
3882
|
+
_optionalChain([route, 'access', _186 => _186.suppressAuditBodies, 'optionalCall', _187 => _187()]);
|
|
3838
3883
|
}
|
|
3839
3884
|
providerResponse = await executeResponsesUpstream(
|
|
3840
|
-
_nullishCoalesce(_nullishCoalesce(_optionalChain([searchRequest, 'optionalAccess',
|
|
3885
|
+
_nullishCoalesce(_nullishCoalesce(_optionalChain([searchRequest, 'optionalAccess', _188 => _188.upstreamBody]), () => ( _optionalChain([hostedImageRequest, 'optionalAccess', _189 => _189.upstreamBody]))), () => ( responsesBody)),
|
|
3841
3886
|
plan,
|
|
3842
3887
|
operation,
|
|
3843
3888
|
signal
|
|
3844
3889
|
);
|
|
3845
3890
|
} catch (error) {
|
|
3846
|
-
await _optionalChain([hostedImageRequest, 'optionalAccess',
|
|
3891
|
+
await _optionalChain([hostedImageRequest, 'optionalAccess', _190 => _190.dispose, 'call', _191 => _191()]);
|
|
3847
3892
|
if (affinity && _chunk25GXJCEZcjs.isBoundAccountSelectionError.call(void 0, error)) {
|
|
3848
3893
|
throw previousResponseNotFound();
|
|
3849
3894
|
}
|
|
@@ -3864,7 +3909,7 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
|
|
|
3864
3909
|
extractUsage(event) {
|
|
3865
3910
|
if (event.type !== "response.completed") return null;
|
|
3866
3911
|
const response = event.response;
|
|
3867
|
-
return _optionalChain([response, 'optionalAccess',
|
|
3912
|
+
return _optionalChain([response, 'optionalAccess', _192 => _192.usage]);
|
|
3868
3913
|
},
|
|
3869
3914
|
onUsage(rawUsage) {
|
|
3870
3915
|
recordResponsesStreamUsage(usageRecorder, rawUsage, usageAttribution);
|
|
@@ -3908,9 +3953,20 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
|
|
|
3908
3953
|
};
|
|
3909
3954
|
}
|
|
3910
3955
|
let overloadRecorded = false;
|
|
3956
|
+
let usageLimitRecorded = false;
|
|
3911
3957
|
const observeSse = (event) => {
|
|
3912
3958
|
if (event.type === "response.completed") {
|
|
3913
|
-
recordAffinity(_optionalChain([event, 'access',
|
|
3959
|
+
recordAffinity(_optionalChain([event, 'access', _193 => _193.response, 'optionalAccess', _194 => _194.id]));
|
|
3960
|
+
}
|
|
3961
|
+
if (!usageLimitRecorded && isCodexUsageLimitEvent(event)) {
|
|
3962
|
+
usageLimitRecorded = true;
|
|
3963
|
+
if (providerResponse.accountId) {
|
|
3964
|
+
markCodexUsageLimitExhaustion(
|
|
3965
|
+
providerResponse.accountId,
|
|
3966
|
+
codexUsageLimitEventBody(event)
|
|
3967
|
+
);
|
|
3968
|
+
}
|
|
3969
|
+
return;
|
|
3914
3970
|
}
|
|
3915
3971
|
if (overloadRecorded || !isCodexServerOverloadEvent(event)) return;
|
|
3916
3972
|
overloadRecorded = true;
|
|
@@ -3937,14 +3993,14 @@ async function handleResponsesOperation(res, responsesBody, route, deps, request
|
|
|
3937
3993
|
signal
|
|
3938
3994
|
);
|
|
3939
3995
|
} finally {
|
|
3940
|
-
await _optionalChain([hostedImageRequest, 'optionalAccess',
|
|
3996
|
+
await _optionalChain([hostedImageRequest, 'optionalAccess', _195 => _195.dispose, 'call', _196 => _196()]);
|
|
3941
3997
|
}
|
|
3942
3998
|
if (!bodyText) return;
|
|
3943
3999
|
if (usageRecorder) recordResponsesNonStreamUsage(usageRecorder, bodyText, usageAttribution);
|
|
3944
4000
|
try {
|
|
3945
4001
|
const body = JSON.parse(bodyText);
|
|
3946
4002
|
if (body.status !== "failed" && body.status !== "incomplete") recordAffinity(body.id);
|
|
3947
|
-
} catch (
|
|
4003
|
+
} catch (e30) {
|
|
3948
4004
|
}
|
|
3949
4005
|
}
|
|
3950
4006
|
|
|
@@ -3953,7 +4009,7 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
|
|
|
3953
4009
|
let anthropicBody;
|
|
3954
4010
|
try {
|
|
3955
4011
|
anthropicBody = JSON.parse(rawBody);
|
|
3956
|
-
} catch (
|
|
4012
|
+
} catch (e31) {
|
|
3957
4013
|
writeError(res, 400, "Invalid JSON in request body");
|
|
3958
4014
|
return;
|
|
3959
4015
|
}
|
|
@@ -3991,7 +4047,7 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
|
|
|
3991
4047
|
extractUsage(event) {
|
|
3992
4048
|
if (event["type"] === "message_start") {
|
|
3993
4049
|
const msg = event["message"];
|
|
3994
|
-
const u = _optionalChain([msg, 'optionalAccess',
|
|
4050
|
+
const u = _optionalChain([msg, 'optionalAccess', _197 => _197["usage"]]);
|
|
3995
4051
|
if (u) anthropicInputUsage = u;
|
|
3996
4052
|
return null;
|
|
3997
4053
|
}
|
|
@@ -4009,11 +4065,29 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
|
|
|
4009
4065
|
const overloadActivityId = providerResponse.activityRecordId;
|
|
4010
4066
|
const overloadAccountId = providerResponse.accountId;
|
|
4011
4067
|
let overloadRecorded = false;
|
|
4068
|
+
let usageLimitRecorded = false;
|
|
4012
4069
|
const codexOverloadDetector = plan.isSubscription && !plan.sameFormat && plan.transformerProvider.name === "codex" ? (event) => {
|
|
4070
|
+
if (!usageLimitRecorded) {
|
|
4071
|
+
let limitHit = isCodexUsageLimitEvent(event);
|
|
4072
|
+
if (!limitHit && event["type"] === "error") {
|
|
4073
|
+
const message = _optionalChain([event, 'access', _198 => _198["error"], 'optionalAccess', _199 => _199["message"]]);
|
|
4074
|
+
limitHit = typeof message === "string" && (message.includes("usage_limit_reached") || message.includes("usage_not_included"));
|
|
4075
|
+
}
|
|
4076
|
+
if (limitHit) {
|
|
4077
|
+
usageLimitRecorded = true;
|
|
4078
|
+
if (overloadAccountId) {
|
|
4079
|
+
markCodexUsageLimitExhaustion(
|
|
4080
|
+
overloadAccountId,
|
|
4081
|
+
codexUsageLimitEventBody(event)
|
|
4082
|
+
);
|
|
4083
|
+
}
|
|
4084
|
+
return;
|
|
4085
|
+
}
|
|
4086
|
+
}
|
|
4013
4087
|
if (overloadRecorded) return;
|
|
4014
4088
|
let hit = isCodexServerOverloadEvent(event);
|
|
4015
4089
|
if (!hit && event["type"] === "error") {
|
|
4016
|
-
const message = _optionalChain([event, 'access',
|
|
4090
|
+
const message = _optionalChain([event, 'access', _200 => _200["error"], 'optionalAccess', _201 => _201["message"]]);
|
|
4017
4091
|
hit = typeof message === "string" && (message.includes("server_is_overloaded") || message.includes("slow_down"));
|
|
4018
4092
|
}
|
|
4019
4093
|
if (!hit) return;
|
|
@@ -4034,7 +4108,7 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
|
|
|
4034
4108
|
let inbandOverloadRecorded = false;
|
|
4035
4109
|
const inbandOverloadObserver = plan.isSubscription && plan.sameFormat && overloadAccountId ? (event) => {
|
|
4036
4110
|
if (inbandOverloadRecorded || event["type"] !== "error") return;
|
|
4037
|
-
const errorType = _optionalChain([event, 'access',
|
|
4111
|
+
const errorType = _optionalChain([event, 'access', _202 => _202["error"], 'optionalAccess', _203 => _203["type"]]);
|
|
4038
4112
|
if (errorType !== "overloaded_error") return;
|
|
4039
4113
|
inbandOverloadRecorded = true;
|
|
4040
4114
|
_chunk7LRTPNFLcjs.getSharedAccountHealth.call(void 0, ).recordUpstreamOutcome(
|
|
@@ -4071,7 +4145,7 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
|
|
|
4071
4145
|
recordAnthropicNonStreamUsage(deps.usageRecorder, bodyText, usageAttribution);
|
|
4072
4146
|
}
|
|
4073
4147
|
} catch (err) {
|
|
4074
|
-
if (_optionalChain([options, 'access',
|
|
4148
|
+
if (_optionalChain([options, 'access', _204 => _204.signal, 'optionalAccess', _205 => _205.aborted])) return;
|
|
4075
4149
|
if (err instanceof DocumentNotSupportedError || err instanceof UnsupportedContentBlockError) {
|
|
4076
4150
|
writeError(res, 400, `${err.message} [code: ${err.code}]`);
|
|
4077
4151
|
return;
|
|
@@ -4082,7 +4156,7 @@ async function handleAnthropicMessagesByo(res, rawBody, route, deps, options = {
|
|
|
4082
4156
|
}
|
|
4083
4157
|
const errMsg = _chunkSVNDB62Dcjs.serializeError.call(void 0, err);
|
|
4084
4158
|
console.error("[ProviderProxy:anthropic] Pipeline error:", errMsg);
|
|
4085
|
-
writeError(res,
|
|
4159
|
+
writeError(res, _chunkBKXC4XM6cjs.isAccountAllowanceExhaustedError.call(void 0, err) ? 429 : 502, errMsg);
|
|
4086
4160
|
}
|
|
4087
4161
|
}
|
|
4088
4162
|
async function buildByoPlan2(res, route, deps, resolvedModel, isStream) {
|
|
@@ -4108,7 +4182,7 @@ async function buildByoPlan2(res, route, deps, resolvedModel, isStream) {
|
|
|
4108
4182
|
writeError(res, 502, "API key not configured");
|
|
4109
4183
|
return null;
|
|
4110
4184
|
}
|
|
4111
|
-
const auth = _nullishCoalesce(route.auth, () => ( new (0,
|
|
4185
|
+
const auth = _nullishCoalesce(route.auth, () => ( new (0, _chunkTX4UCSOPcjs.LlmConfigProviderAuth)({
|
|
4112
4186
|
provider,
|
|
4113
4187
|
apiKey,
|
|
4114
4188
|
apiKeyPool: _nullishCoalesce(deps.apiKeyPool, () => ( null)),
|
|
@@ -4137,7 +4211,7 @@ async function buildByoPlan2(res, route, deps, resolvedModel, isStream) {
|
|
|
4137
4211
|
isSubscription: false,
|
|
4138
4212
|
provider,
|
|
4139
4213
|
apiKey,
|
|
4140
|
-
extendedContextEnabled: _nullishCoalesce(_optionalChain([route, 'access',
|
|
4214
|
+
extendedContextEnabled: _nullishCoalesce(_optionalChain([route, 'access', _206 => _206.anthropicSdkHints, 'optionalAccess', _207 => _207.extendedContext, 'optionalAccess', _208 => _208.enabled]), () => ( false))
|
|
4141
4215
|
};
|
|
4142
4216
|
}
|
|
4143
4217
|
async function runSameFormatFetch(bodyToSend, plan, options, keyOverride, urlOverride) {
|
|
@@ -4146,8 +4220,8 @@ async function runSameFormatFetch(bodyToSend, plan, options, keyOverride, urlOve
|
|
|
4146
4220
|
throw new Error("[ProviderProxy:anthropic] same-format BYO path requires a provider row");
|
|
4147
4221
|
}
|
|
4148
4222
|
const effectiveKey = _nullishCoalesce(_nullishCoalesce(keyOverride, () => ( apiKey)), () => ( ""));
|
|
4149
|
-
const headers =
|
|
4150
|
-
const callerBeta = _optionalChain([options, 'access',
|
|
4223
|
+
const headers = _chunkTX4UCSOPcjs.getProviderHeaders.call(void 0, provider, effectiveKey);
|
|
4224
|
+
const callerBeta = _optionalChain([options, 'access', _209 => _209.callerAnthropicBeta, 'optionalAccess', _210 => _210.trim, 'call', _211 => _211()]);
|
|
4151
4225
|
if (callerBeta) {
|
|
4152
4226
|
const existing = _nullishCoalesce(headers["anthropic-beta"], () => ( headers["Anthropic-Beta"]));
|
|
4153
4227
|
const parts = new Set(
|
|
@@ -4159,11 +4233,11 @@ async function runSameFormatFetch(bodyToSend, plan, options, keyOverride, urlOve
|
|
|
4159
4233
|
}
|
|
4160
4234
|
}
|
|
4161
4235
|
_chunkGBHYAGX3cjs.injectExtendedContextBeta.call(void 0, headers, resolvedModel, _nullishCoalesce(extendedContextEnabled, () => ( false)));
|
|
4162
|
-
const callerVersion = _optionalChain([options, 'access',
|
|
4236
|
+
const callerVersion = _optionalChain([options, 'access', _212 => _212.callerAnthropicVersion, 'optionalAccess', _213 => _213.trim, 'call', _214 => _214()]);
|
|
4163
4237
|
headers["anthropic-version"] = callerVersion || DEFAULT_ANTHROPIC_VERSION;
|
|
4164
4238
|
const url = _nullishCoalesce(urlOverride, () => ( _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: resolvedModel, stream: isStream })));
|
|
4165
4239
|
console.info(`[ProviderProxy:anthropic] (same-format) -> ${url} model=${resolvedModel} stream=${isStream}`);
|
|
4166
|
-
const response = await
|
|
4240
|
+
const response = await _chunkZSA44G7Jcjs.fetchUpstream.call(void 0,
|
|
4167
4241
|
url,
|
|
4168
4242
|
{ method: "POST", headers, body: bodyToSend, signal: options.signal },
|
|
4169
4243
|
{ providerId: "byo" }
|
|
@@ -4175,7 +4249,7 @@ function resolveSameFormatBody(anthropicBody, rawBody, plan) {
|
|
|
4175
4249
|
try {
|
|
4176
4250
|
const m = JSON.parse(rawBody).model;
|
|
4177
4251
|
originalModel = typeof m === "string" ? m : void 0;
|
|
4178
|
-
} catch (
|
|
4252
|
+
} catch (e32) {
|
|
4179
4253
|
originalModel = void 0;
|
|
4180
4254
|
}
|
|
4181
4255
|
return plan.resolvedModel !== originalModel ? JSON.stringify(anthropicBody) : rawBody;
|
|
@@ -4184,8 +4258,8 @@ async function runPipelineWithPoolReporting(anthropicBody, rawBody, plan, option
|
|
|
4184
4258
|
const sameFormatBody = plan.sameFormat ? resolveSameFormatBody(anthropicBody, rawBody, plan) : rawBody;
|
|
4185
4259
|
const runOnce = (keyOverride) => plan.sameFormat ? runSameFormatFetch(sameFormatBody, plan, options, keyOverride) : runPipeline(anthropicBody, plan, void 0, options.signal);
|
|
4186
4260
|
const first = await runOnce();
|
|
4187
|
-
const outcome = await _optionalChain([plan, 'access',
|
|
4188
|
-
if (_optionalChain([outcome, 'optionalAccess',
|
|
4261
|
+
const outcome = await _optionalChain([plan, 'access', _215 => _215.auth, 'access', _216 => _216.onResult, 'optionalCall', _217 => _217(first.rawStatus)]);
|
|
4262
|
+
if (_optionalChain([outcome, 'optionalAccess', _218 => _218.rebound])) {
|
|
4189
4263
|
console.info(
|
|
4190
4264
|
"[ProviderProxy:anthropic] pool re-bound key after status",
|
|
4191
4265
|
first.rawStatus,
|
|
@@ -4271,7 +4345,7 @@ function countTools(tools, budget) {
|
|
|
4271
4345
|
let serialized;
|
|
4272
4346
|
try {
|
|
4273
4347
|
serialized = _nullishCoalesce(JSON.stringify(tool), () => ( ""));
|
|
4274
|
-
} catch (
|
|
4348
|
+
} catch (e33) {
|
|
4275
4349
|
serialized = "";
|
|
4276
4350
|
}
|
|
4277
4351
|
if (!budget.addChars(serialized.length)) return;
|
|
@@ -4316,7 +4390,7 @@ async function handleAnthropicCountTokens(res, rawBody, route, deps, options = {
|
|
|
4316
4390
|
let body;
|
|
4317
4391
|
try {
|
|
4318
4392
|
body = JSON.parse(rawBody);
|
|
4319
|
-
} catch (
|
|
4393
|
+
} catch (e34) {
|
|
4320
4394
|
writeError(res, 400, "Invalid JSON in request body");
|
|
4321
4395
|
return;
|
|
4322
4396
|
}
|
|
@@ -4348,14 +4422,14 @@ async function handleAnthropicCountTokens(res, rawBody, route, deps, options = {
|
|
|
4348
4422
|
const providerResponse = plan.isSubscription ? await runSubscriptionCountTokensFetch(bodyToSend, plan, options, countTokensUrl) : await runByoCountTokensFetch(bodyToSend, plan, options, countTokensUrl);
|
|
4349
4423
|
await relayResponse(res, providerResponse.response, false, void 0, void 0, void 0, options.signal);
|
|
4350
4424
|
} catch (err) {
|
|
4351
|
-
if (_optionalChain([options, 'access',
|
|
4425
|
+
if (_optionalChain([options, 'access', _219 => _219.signal, 'optionalAccess', _220 => _220.aborted])) return;
|
|
4352
4426
|
if (_chunk25GXJCEZcjs.isBoundAccountSelectionError.call(void 0, err)) {
|
|
4353
4427
|
writeBoundAccountError(res, err);
|
|
4354
4428
|
return;
|
|
4355
4429
|
}
|
|
4356
4430
|
const errMsg = _chunkSVNDB62Dcjs.serializeError.call(void 0, err);
|
|
4357
4431
|
console.error("[ProviderProxy:anthropic] count_tokens error:", errMsg);
|
|
4358
|
-
writeError(res,
|
|
4432
|
+
writeError(res, _chunkBKXC4XM6cjs.isAccountAllowanceExhaustedError.call(void 0, err) ? 429 : 502, errMsg);
|
|
4359
4433
|
}
|
|
4360
4434
|
}
|
|
4361
4435
|
function writeCountTokensEstimate(res, body, budgetMs) {
|
|
@@ -4370,8 +4444,8 @@ function writeCountTokensEstimate(res, body, budgetMs) {
|
|
|
4370
4444
|
async function runByoCountTokensFetch(bodyToSend, plan, options, url) {
|
|
4371
4445
|
const runOnce = (keyOverride) => runSameFormatFetch(bodyToSend, plan, options, keyOverride, url);
|
|
4372
4446
|
const first = await runOnce();
|
|
4373
|
-
const outcome = await _optionalChain([plan, 'access',
|
|
4374
|
-
if (_optionalChain([outcome, 'optionalAccess',
|
|
4447
|
+
const outcome = await _optionalChain([plan, 'access', _221 => _221.auth, 'access', _222 => _222.onResult, 'optionalCall', _223 => _223(first.rawStatus)]);
|
|
4448
|
+
if (_optionalChain([outcome, 'optionalAccess', _224 => _224.rebound])) {
|
|
4375
4449
|
await cancelDiscardedResponse(first.response);
|
|
4376
4450
|
console.info(
|
|
4377
4451
|
"[ProviderProxy:anthropic] pool re-bound key after status",
|
|
@@ -4389,7 +4463,7 @@ async function runSubscriptionCountTokensFetch(bodyToSend, plan, options, url) {
|
|
|
4389
4463
|
// src/provider-proxy/ingress/anthropicPathMatch.ts
|
|
4390
4464
|
function classifyAnthropicMessagesPath(url) {
|
|
4391
4465
|
if (!url) return null;
|
|
4392
|
-
const path = _nullishCoalesce(_optionalChain([url, 'access',
|
|
4466
|
+
const path = _nullishCoalesce(_optionalChain([url, 'access', _225 => _225.split, 'call', _226 => _226("?"), 'access', _227 => _227[0], 'optionalAccess', _228 => _228.replace, 'call', _229 => _229(/\/+$/, "")]), () => ( ""));
|
|
4393
4467
|
if (path.endsWith("/v1/messages/count_tokens")) return "count_tokens";
|
|
4394
4468
|
if (path.endsWith("/v1/messages")) return "messages";
|
|
4395
4469
|
if (/\/v1\/messages\/.+/.test(path)) return "unsupported-subpath";
|
|
@@ -4431,14 +4505,14 @@ async function handleAnthropicMessagesRequest(req, res, route, deps) {
|
|
|
4431
4505
|
}
|
|
4432
4506
|
return;
|
|
4433
4507
|
}
|
|
4434
|
-
const searchMode = _nullishCoalesce(_optionalChain([deps, 'access',
|
|
4435
|
-
const routeSuppliedSearchBackend = _nullishCoalesce(_optionalChain([route, 'access',
|
|
4508
|
+
const searchMode = _nullishCoalesce(_optionalChain([deps, 'access', _230 => _230.searchFrontendModes, 'optionalAccess', _231 => _231.anthropic]), () => ( _chunkE4QHVXV5cjs.DEFAULT_SEARCH_FRONTEND_MODES.anthropic));
|
|
4509
|
+
const routeSuppliedSearchBackend = _nullishCoalesce(_optionalChain([route, 'access', _232 => _232.anthropicSdkHints, 'optionalAccess', _233 => _233.webSearchService]), () => ( null));
|
|
4436
4510
|
if (searchMode !== "native" && !routeSuppliedSearchBackend) {
|
|
4437
4511
|
const preReadBody = await readBody(req);
|
|
4438
4512
|
let parsedForSearch;
|
|
4439
4513
|
try {
|
|
4440
4514
|
parsedForSearch = preReadBody ? JSON.parse(preReadBody) : {};
|
|
4441
|
-
} catch (
|
|
4515
|
+
} catch (e35) {
|
|
4442
4516
|
parsedForSearch = void 0;
|
|
4443
4517
|
}
|
|
4444
4518
|
const handled = await handleAnthropicManagedSearch(res, parsedForSearch, {
|
|
@@ -4563,10 +4637,10 @@ function emitGeminiUsageRecord(recorder, rawUsageMetadata, attribution) {
|
|
|
4563
4637
|
providerId: attribution.providerId,
|
|
4564
4638
|
model: attribution.model,
|
|
4565
4639
|
apiKeyId: attribution.apiKeyId,
|
|
4566
|
-
runId: _nullishCoalesce(_optionalChain([attribution, 'access',
|
|
4567
|
-
routeLeaseId: _nullishCoalesce(_optionalChain([attribution, 'access',
|
|
4568
|
-
routeLeaseConsumer: _nullishCoalesce(_optionalChain([attribution, 'access',
|
|
4569
|
-
routeLeaseStageId: _nullishCoalesce(_optionalChain([attribution, 'access',
|
|
4640
|
+
runId: _nullishCoalesce(_optionalChain([attribution, 'access', _234 => _234.routeLease, 'optionalAccess', _235 => _235.runId]), () => ( null)),
|
|
4641
|
+
routeLeaseId: _nullishCoalesce(_optionalChain([attribution, 'access', _236 => _236.routeLease, 'optionalAccess', _237 => _237.leaseId]), () => ( null)),
|
|
4642
|
+
routeLeaseConsumer: _nullishCoalesce(_optionalChain([attribution, 'access', _238 => _238.routeLease, 'optionalAccess', _239 => _239.consumer]), () => ( null)),
|
|
4643
|
+
routeLeaseStageId: _nullishCoalesce(_optionalChain([attribution, 'access', _240 => _240.routeLease, 'optionalAccess', _241 => _241.stageId]), () => ( null)),
|
|
4570
4644
|
auditResponse: attribution.auditResponse,
|
|
4571
4645
|
engineOrigin: "codex-ingress",
|
|
4572
4646
|
usage: tapped,
|
|
@@ -4581,13 +4655,13 @@ function recordGeminiNonStreamUsage(recorder, bodyText, attribution) {
|
|
|
4581
4655
|
parsed.usageMetadata,
|
|
4582
4656
|
attribution
|
|
4583
4657
|
);
|
|
4584
|
-
} catch (
|
|
4658
|
+
} catch (e36) {
|
|
4585
4659
|
}
|
|
4586
4660
|
}
|
|
4587
4661
|
function recordGeminiStreamUsage(recorder, rawUsageMetadata, attribution) {
|
|
4588
4662
|
try {
|
|
4589
4663
|
emitGeminiUsageRecord(recorder, rawUsageMetadata, attribution);
|
|
4590
|
-
} catch (
|
|
4664
|
+
} catch (e37) {
|
|
4591
4665
|
}
|
|
4592
4666
|
}
|
|
4593
4667
|
|
|
@@ -4596,14 +4670,14 @@ var GENERATE_CONTENT_ACTION = ":generateContent";
|
|
|
4596
4670
|
var STREAM_GENERATE_CONTENT_ACTION = ":streamGenerateContent";
|
|
4597
4671
|
function isGeminiGenerateContentRequest(method, url) {
|
|
4598
4672
|
if (method !== "POST" || !url) return false;
|
|
4599
|
-
const path = _nullishCoalesce(_optionalChain([url, 'access',
|
|
4673
|
+
const path = _nullishCoalesce(_optionalChain([url, 'access', _242 => _242.split, 'call', _243 => _243("?"), 'access', _244 => _244[0], 'optionalAccess', _245 => _245.replace, 'call', _246 => _246(/\/+$/, "")]), () => ( ""));
|
|
4600
4674
|
const lastSegment = _nullishCoalesce(path.split("/").pop(), () => ( ""));
|
|
4601
4675
|
return lastSegment.includes(STREAM_GENERATE_CONTENT_ACTION) || lastSegment.includes(GENERATE_CONTENT_ACTION);
|
|
4602
4676
|
}
|
|
4603
4677
|
function isGeminiStreamRequest(url) {
|
|
4604
4678
|
if (!url) return false;
|
|
4605
4679
|
const [path, query = ""] = url.split("?");
|
|
4606
|
-
const lastSegment = _nullishCoalesce((_nullishCoalesce(_optionalChain([path, 'optionalAccess',
|
|
4680
|
+
const lastSegment = _nullishCoalesce((_nullishCoalesce(_optionalChain([path, 'optionalAccess', _247 => _247.replace, 'call', _248 => _248(/\/+$/, "")]), () => ( ""))).split("/").pop(), () => ( ""));
|
|
4607
4681
|
if (lastSegment.includes(STREAM_GENERATE_CONTENT_ACTION)) return true;
|
|
4608
4682
|
return /(^|&)alt=sse(&|$)/.test(query);
|
|
4609
4683
|
}
|
|
@@ -4611,7 +4685,7 @@ async function handleGeminiGenerateContentRequest(res, rawBody, url, route, deps
|
|
|
4611
4685
|
let geminiBody;
|
|
4612
4686
|
try {
|
|
4613
4687
|
geminiBody = JSON.parse(rawBody);
|
|
4614
|
-
} catch (
|
|
4688
|
+
} catch (e38) {
|
|
4615
4689
|
writeError(res, 400, "Invalid JSON in request body");
|
|
4616
4690
|
return;
|
|
4617
4691
|
}
|
|
@@ -4684,7 +4758,7 @@ async function buildByoPlan3(res, route, deps, resolvedModel, isStream) {
|
|
|
4684
4758
|
writeError(res, 502, "API key not configured");
|
|
4685
4759
|
return null;
|
|
4686
4760
|
}
|
|
4687
|
-
const auth = _nullishCoalesce(route.auth, () => ( new (0,
|
|
4761
|
+
const auth = _nullishCoalesce(route.auth, () => ( new (0, _chunkTX4UCSOPcjs.LlmConfigProviderAuth)({
|
|
4688
4762
|
provider,
|
|
4689
4763
|
apiKey,
|
|
4690
4764
|
apiKeyPool: _nullishCoalesce(deps.apiKeyPool, () => ( null)),
|
|
@@ -4735,7 +4809,7 @@ async function runPipeline2(geminiBody, plan) {
|
|
|
4735
4809
|
},
|
|
4736
4810
|
fetchFn: (url, headers, body) => {
|
|
4737
4811
|
console.log(`[ProviderProxy:gemini] -> ${url} model=${resolvedModel} stream=${isStream}`);
|
|
4738
|
-
return
|
|
4812
|
+
return _chunkZSA44G7Jcjs.fetchUpstream.call(void 0,
|
|
4739
4813
|
url,
|
|
4740
4814
|
{ method: "POST", headers, body: JSON.stringify(body) },
|
|
4741
4815
|
{ providerId: "byo" }
|
|
@@ -4750,8 +4824,8 @@ async function runPipeline2(geminiBody, plan) {
|
|
|
4750
4824
|
}
|
|
4751
4825
|
async function runPipelineWithPoolReporting2(geminiBody, plan) {
|
|
4752
4826
|
const first = await runPipeline2(geminiBody, plan);
|
|
4753
|
-
const outcome = await _optionalChain([plan, 'access',
|
|
4754
|
-
if (_optionalChain([outcome, 'optionalAccess',
|
|
4827
|
+
const outcome = await _optionalChain([plan, 'access', _249 => _249.auth, 'access', _250 => _250.onResult, 'optionalCall', _251 => _251(first.rawStatus)]);
|
|
4828
|
+
if (_optionalChain([outcome, 'optionalAccess', _252 => _252.rebound])) {
|
|
4755
4829
|
console.log(
|
|
4756
4830
|
"[ProviderProxy:gemini] pool re-bound key after status",
|
|
4757
4831
|
first.rawStatus,
|
|
@@ -4790,10 +4864,10 @@ function emitChatCompletionsUsageRecord(recorder, rawUsage, attribution) {
|
|
|
4790
4864
|
providerId: attribution.providerId,
|
|
4791
4865
|
model: attribution.model,
|
|
4792
4866
|
apiKeyId: attribution.apiKeyId,
|
|
4793
|
-
runId: _nullishCoalesce(_optionalChain([attribution, 'access',
|
|
4794
|
-
routeLeaseId: _nullishCoalesce(_optionalChain([attribution, 'access',
|
|
4795
|
-
routeLeaseConsumer: _nullishCoalesce(_optionalChain([attribution, 'access',
|
|
4796
|
-
routeLeaseStageId: _nullishCoalesce(_optionalChain([attribution, 'access',
|
|
4867
|
+
runId: _nullishCoalesce(_optionalChain([attribution, 'access', _253 => _253.routeLease, 'optionalAccess', _254 => _254.runId]), () => ( null)),
|
|
4868
|
+
routeLeaseId: _nullishCoalesce(_optionalChain([attribution, 'access', _255 => _255.routeLease, 'optionalAccess', _256 => _256.leaseId]), () => ( null)),
|
|
4869
|
+
routeLeaseConsumer: _nullishCoalesce(_optionalChain([attribution, 'access', _257 => _257.routeLease, 'optionalAccess', _258 => _258.consumer]), () => ( null)),
|
|
4870
|
+
routeLeaseStageId: _nullishCoalesce(_optionalChain([attribution, 'access', _259 => _259.routeLease, 'optionalAccess', _260 => _260.stageId]), () => ( null)),
|
|
4797
4871
|
auditResponse: attribution.auditResponse,
|
|
4798
4872
|
engineOrigin: "codex-ingress",
|
|
4799
4873
|
usage: tapped,
|
|
@@ -4808,13 +4882,13 @@ function recordChatCompletionsNonStreamUsage(recorder, bodyText, attribution) {
|
|
|
4808
4882
|
parsed.usage,
|
|
4809
4883
|
attribution
|
|
4810
4884
|
);
|
|
4811
|
-
} catch (
|
|
4885
|
+
} catch (e39) {
|
|
4812
4886
|
}
|
|
4813
4887
|
}
|
|
4814
4888
|
function recordChatCompletionsStreamUsage(recorder, rawUsage, attribution) {
|
|
4815
4889
|
try {
|
|
4816
4890
|
emitChatCompletionsUsageRecord(recorder, rawUsage, attribution);
|
|
4817
|
-
} catch (
|
|
4891
|
+
} catch (e40) {
|
|
4818
4892
|
}
|
|
4819
4893
|
}
|
|
4820
4894
|
|
|
@@ -4825,7 +4899,7 @@ async function handleOpenAIChatRequest(res, rawBody, route, deps) {
|
|
|
4825
4899
|
let chatBody;
|
|
4826
4900
|
try {
|
|
4827
4901
|
chatBody = JSON.parse(rawBody);
|
|
4828
|
-
} catch (
|
|
4902
|
+
} catch (e41) {
|
|
4829
4903
|
writeError(res, 400, "Invalid JSON in request body");
|
|
4830
4904
|
return;
|
|
4831
4905
|
}
|
|
@@ -4871,7 +4945,7 @@ async function handleOpenAIChatRequest(res, rawBody, route, deps) {
|
|
|
4871
4945
|
}
|
|
4872
4946
|
const errMsg = _chunkSVNDB62Dcjs.serializeError.call(void 0, err);
|
|
4873
4947
|
console.error("[ProviderProxy:chat] Pipeline error:", errMsg);
|
|
4874
|
-
writeError(res,
|
|
4948
|
+
writeError(res, _chunkBKXC4XM6cjs.isAccountAllowanceExhaustedError.call(void 0, err) ? 429 : 502, errMsg);
|
|
4875
4949
|
}
|
|
4876
4950
|
}
|
|
4877
4951
|
async function buildByoPlan4(res, route, deps, resolvedModel, isStream) {
|
|
@@ -4897,7 +4971,7 @@ async function buildByoPlan4(res, route, deps, resolvedModel, isStream) {
|
|
|
4897
4971
|
writeError(res, 502, "API key not configured");
|
|
4898
4972
|
return null;
|
|
4899
4973
|
}
|
|
4900
|
-
const auth = _nullishCoalesce(route.auth, () => ( new (0,
|
|
4974
|
+
const auth = _nullishCoalesce(route.auth, () => ( new (0, _chunkTX4UCSOPcjs.LlmConfigProviderAuth)({
|
|
4901
4975
|
provider,
|
|
4902
4976
|
apiKey,
|
|
4903
4977
|
apiKeyPool: _nullishCoalesce(deps.apiKeyPool, () => ( null)),
|
|
@@ -4940,12 +5014,12 @@ async function buildSubscriptionPlan3(res, route, deps, resolvedModel, isStream)
|
|
|
4940
5014
|
);
|
|
4941
5015
|
return null;
|
|
4942
5016
|
}
|
|
4943
|
-
const upstreamUrl = _optionalChain([profile, 'access',
|
|
5017
|
+
const upstreamUrl = _optionalChain([profile, 'access', _261 => _261.resolveUpstreamUrl, 'optionalCall', _262 => _262(resolvedModel)]);
|
|
4944
5018
|
if (!upstreamUrl) {
|
|
4945
5019
|
writeError(res, 502, "Subscription profile is missing resolveUpstreamUrl");
|
|
4946
5020
|
return null;
|
|
4947
5021
|
}
|
|
4948
|
-
const auth = _nullishCoalesce(route.auth, () => ( new (0,
|
|
5022
|
+
const auth = _nullishCoalesce(route.auth, () => ( new (0, _chunkTX3AEV6Hcjs.SubscriptionAuthSource)(profile)));
|
|
4949
5023
|
const chain = _chunkNYUNU75Acjs.resolveSubscriptionChain.call(void 0,
|
|
4950
5024
|
profile,
|
|
4951
5025
|
deps.llmConfig.getTransformerService(),
|
|
@@ -5005,7 +5079,7 @@ async function runPipeline3(chatBody, plan) {
|
|
|
5005
5079
|
},
|
|
5006
5080
|
fetchFn: (url, headers, body) => {
|
|
5007
5081
|
console.log(`[ProviderProxy:chat] -> ${url} model=${resolvedModel} stream=${isStream}`);
|
|
5008
|
-
return
|
|
5082
|
+
return _chunkZSA44G7Jcjs.fetchUpstream.call(void 0,
|
|
5009
5083
|
url,
|
|
5010
5084
|
{ method: "POST", headers, body: JSON.stringify(body) },
|
|
5011
5085
|
{ providerId: plan.proxyProviderId, accountId: proxyAccountId }
|
|
@@ -5020,8 +5094,8 @@ async function runPipeline3(chatBody, plan) {
|
|
|
5020
5094
|
}
|
|
5021
5095
|
async function runPipelineWithPoolReporting3(chatBody, plan) {
|
|
5022
5096
|
const first = await runPipeline3(chatBody, plan);
|
|
5023
|
-
const outcome = await _optionalChain([plan, 'access',
|
|
5024
|
-
if (_optionalChain([outcome, 'optionalAccess',
|
|
5097
|
+
const outcome = await _optionalChain([plan, 'access', _263 => _263.auth, 'access', _264 => _264.onResult, 'optionalCall', _265 => _265(first.rawStatus)]);
|
|
5098
|
+
if (_optionalChain([outcome, 'optionalAccess', _266 => _266.rebound])) {
|
|
5025
5099
|
console.log(
|
|
5026
5100
|
"[ProviderProxy:chat] pool re-bound key after status",
|
|
5027
5101
|
first.rawStatus,
|
|
@@ -5034,7 +5108,7 @@ async function runPipelineWithPoolReporting3(chatBody, plan) {
|
|
|
5034
5108
|
async function runPipelineWithSubscriptionRetry2(chatBody, plan) {
|
|
5035
5109
|
const first = await runPipeline3(chatBody, plan);
|
|
5036
5110
|
if (first.rawStatus !== 401) return first;
|
|
5037
|
-
const refreshed = await _optionalChain([plan, 'access',
|
|
5111
|
+
const refreshed = await _optionalChain([plan, 'access', _267 => _267.auth, 'access', _268 => _268.onUnauthorized, 'optionalCall', _269 => _269()]);
|
|
5038
5112
|
if (!refreshed) {
|
|
5039
5113
|
console.warn("[ProviderProxy:chat] 401 not recoverable (onUnauthorized returned false)");
|
|
5040
5114
|
return first;
|
|
@@ -5056,7 +5130,7 @@ function resolveRouteToken(req) {
|
|
|
5056
5130
|
if (fromAuth) return fromAuth;
|
|
5057
5131
|
const googKey = req.headers["x-goog-api-key"];
|
|
5058
5132
|
const value = Array.isArray(googKey) ? googKey[0] : googKey;
|
|
5059
|
-
return _optionalChain([value, 'optionalAccess',
|
|
5133
|
+
return _optionalChain([value, 'optionalAccess', _270 => _270.trim, 'call', _271 => _271()]) || void 0;
|
|
5060
5134
|
}
|
|
5061
5135
|
async function routeRequest(req, res, routes, deps) {
|
|
5062
5136
|
if (classifyAnthropicMessagesPath(req.url) !== null) {
|
|
@@ -5071,7 +5145,7 @@ async function routeRequest(req, res, routes, deps) {
|
|
|
5071
5145
|
const method = req.method;
|
|
5072
5146
|
const url = req.url;
|
|
5073
5147
|
const openAIOperation = _chunkG4CZIUIBcjs.classifyOpenAIOperation.call(void 0, method, url);
|
|
5074
|
-
if (_optionalChain([openAIOperation, 'optionalAccess',
|
|
5148
|
+
if (_optionalChain([openAIOperation, 'optionalAccess', _272 => _272.owner]) === "extension") {
|
|
5075
5149
|
const registry = deps.openAIOperationRegistry;
|
|
5076
5150
|
if (!registry) {
|
|
5077
5151
|
_chunkG4CZIUIBcjs.writeOpenAIOperationError.call(void 0, res, _chunkG4CZIUIBcjs.unsupportedOpenAIOperation.call(void 0, openAIOperation));
|
|
@@ -5093,7 +5167,7 @@ async function routeRequest(req, res, routes, deps) {
|
|
|
5093
5167
|
await handleAnthropicMessagesRequest(req, res, route, deps);
|
|
5094
5168
|
return;
|
|
5095
5169
|
}
|
|
5096
|
-
if (_optionalChain([openAIOperation, 'optionalAccess',
|
|
5170
|
+
if (_optionalChain([openAIOperation, 'optionalAccess', _273 => _273.id]) === "responses.create") {
|
|
5097
5171
|
const abortScope = createResponsesAbortScope({ request: req, response: res });
|
|
5098
5172
|
try {
|
|
5099
5173
|
const rawBody = await readBody(req, abortScope.signal);
|
|
@@ -5124,7 +5198,7 @@ async function routeRequest(req, res, routes, deps) {
|
|
|
5124
5198
|
}
|
|
5125
5199
|
return;
|
|
5126
5200
|
}
|
|
5127
|
-
if (_optionalChain([openAIOperation, 'optionalAccess',
|
|
5201
|
+
if (_optionalChain([openAIOperation, 'optionalAccess', _274 => _274.id]) === "chat.completions.create") {
|
|
5128
5202
|
const rawBody = await readBody(req);
|
|
5129
5203
|
await handleOpenAIChatRequest(res, rawBody, route, deps);
|
|
5130
5204
|
return;
|
|
@@ -5195,7 +5269,7 @@ var ProviderProxy = (_class8 = class {
|
|
|
5195
5269
|
for (const cleanup of [...this.beforeStop]) {
|
|
5196
5270
|
try {
|
|
5197
5271
|
await cleanup();
|
|
5198
|
-
} catch (
|
|
5272
|
+
} catch (e42) {
|
|
5199
5273
|
}
|
|
5200
5274
|
}
|
|
5201
5275
|
this.routes.clear();
|
|
@@ -5481,7 +5555,7 @@ var SYSTEM_ROUTE_LEASE_CLOCK = {
|
|
|
5481
5555
|
now: () => Date.now(),
|
|
5482
5556
|
setTimeout(callback, delayMs) {
|
|
5483
5557
|
const timer = setTimeout(callback, delayMs);
|
|
5484
|
-
_optionalChain([timer, 'access',
|
|
5558
|
+
_optionalChain([timer, 'access', _275 => _275.unref, 'optionalCall', _276 => _276()]);
|
|
5485
5559
|
return timer;
|
|
5486
5560
|
},
|
|
5487
5561
|
clearTimeout(handle) {
|
|
@@ -5575,12 +5649,12 @@ var RouteLeaseManager = (_class10 = class {
|
|
|
5575
5649
|
this.assertOpen();
|
|
5576
5650
|
const route = {
|
|
5577
5651
|
...resolved,
|
|
5578
|
-
sessionId: _nullishCoalesce(_optionalChain([request, 'access',
|
|
5652
|
+
sessionId: _nullishCoalesce(_optionalChain([request, 'access', _277 => _277.execution, 'optionalAccess', _278 => _278.sessionIdHash]), () => ( null)),
|
|
5579
5653
|
routeLease: {
|
|
5580
5654
|
leaseId,
|
|
5581
5655
|
consumer: request.consumer,
|
|
5582
|
-
..._optionalChain([request, 'access',
|
|
5583
|
-
..._optionalChain([request, 'access',
|
|
5656
|
+
..._optionalChain([request, 'access', _279 => _279.execution, 'optionalAccess', _280 => _280.runId]) ? { runId: request.execution.runId } : {},
|
|
5657
|
+
..._optionalChain([request, 'access', _281 => _281.execution, 'optionalAccess', _282 => _282.stageId]) ? { stageId: request.execution.stageId } : {}
|
|
5584
5658
|
}
|
|
5585
5659
|
};
|
|
5586
5660
|
const now = this.clock.now();
|
|
@@ -5635,7 +5709,7 @@ var RouteLeaseManager = (_class10 = class {
|
|
|
5635
5709
|
this.active.set(leaseId, activeLease);
|
|
5636
5710
|
this.idempotency.set(scope, { leaseId, payloadHash: input.payloadHash });
|
|
5637
5711
|
published = true;
|
|
5638
|
-
_optionalChain([this, 'access',
|
|
5712
|
+
_optionalChain([this, 'access', _283 => _283.afterPublish, 'optionalCall', _284 => _284()]);
|
|
5639
5713
|
if (this.closed) {
|
|
5640
5714
|
this.finalize(activeLease, "released");
|
|
5641
5715
|
throw new RouteLeaseError("daemon_not_ready", "route lease manager is shutting down");
|
|
@@ -5672,7 +5746,7 @@ var RouteLeaseManager = (_class10 = class {
|
|
|
5672
5746
|
if (!lease) {
|
|
5673
5747
|
this.pruneTombstones();
|
|
5674
5748
|
const known = this.tombstones.get(leaseId);
|
|
5675
|
-
if (_optionalChain([known, 'optionalAccess',
|
|
5749
|
+
if (_optionalChain([known, 'optionalAccess', _285 => _285.metadata, 'access', _286 => _286.status]) === "expired") {
|
|
5676
5750
|
throw new RouteLeaseError("lease_expired", "route lease has expired");
|
|
5677
5751
|
}
|
|
5678
5752
|
throw new RouteLeaseError("lease_not_found", "route lease was not found");
|
|
@@ -5709,7 +5783,7 @@ var RouteLeaseManager = (_class10 = class {
|
|
|
5709
5783
|
try {
|
|
5710
5784
|
this.finalize(lease, "released");
|
|
5711
5785
|
} catch (error) {
|
|
5712
|
-
_optionalChain([this, 'access',
|
|
5786
|
+
_optionalChain([this, 'access', _287 => _287.logger, 'optionalAccess', _288 => _288.warn, 'call', _289 => _289("route lease cleanup failed during shutdown", { leaseId: lease.leaseId, error: safeErrorName(error) })]);
|
|
5713
5787
|
}
|
|
5714
5788
|
}
|
|
5715
5789
|
}
|
|
@@ -5755,7 +5829,7 @@ var RouteLeaseManager = (_class10 = class {
|
|
|
5755
5829
|
try {
|
|
5756
5830
|
this.routePort.removeRoute(routeToken);
|
|
5757
5831
|
} catch (error) {
|
|
5758
|
-
_optionalChain([this, 'access',
|
|
5832
|
+
_optionalChain([this, 'access', _290 => _290.logger, 'optionalAccess', _291 => _291.warn, 'call', _292 => _292("route lease route cleanup failed", { leaseId, error: safeErrorName(error) })]);
|
|
5759
5833
|
}
|
|
5760
5834
|
}
|
|
5761
5835
|
pruneTombstones() {
|
|
@@ -5780,8 +5854,8 @@ function nonBlank(value) {
|
|
|
5780
5854
|
return typeof value === "string" && value.trim() !== "";
|
|
5781
5855
|
}
|
|
5782
5856
|
function gatewayBindingAllowsKey(binding, apiKeyId) {
|
|
5783
|
-
const scope = _nullishCoalesce(binding.keyScope, () => ( (_optionalChain([binding, 'access',
|
|
5784
|
-
return scope === "all" || Boolean(_optionalChain([binding, 'access',
|
|
5857
|
+
const scope = _nullishCoalesce(binding.keyScope, () => ( (_optionalChain([binding, 'access', _293 => _293.apiKeyIds, 'optionalAccess', _294 => _294.length]) ? "selected" : "all")));
|
|
5858
|
+
return scope === "all" || Boolean(_optionalChain([binding, 'access', _295 => _295.apiKeyIds, 'optionalAccess', _296 => _296.includes, 'call', _297 => _297(apiKeyId)]));
|
|
5785
5859
|
}
|
|
5786
5860
|
function wildcardMatches(pattern, value) {
|
|
5787
5861
|
const escaped = pattern.split("*").map((part) => part.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&")).join(".*");
|
|
@@ -5801,12 +5875,12 @@ function resolveGatewayModelMapping(mappings, requestedModel) {
|
|
|
5801
5875
|
}
|
|
5802
5876
|
function routeCanServe(binding, requestedModel, role) {
|
|
5803
5877
|
if (binding.modelMode === "passthrough") return nonBlank(requestedModel);
|
|
5804
|
-
if (_optionalChain([binding, 'access',
|
|
5878
|
+
if (_optionalChain([binding, 'access', _298 => _298.modelMappings, 'optionalAccess', _299 => _299.length])) {
|
|
5805
5879
|
return nonBlank(resolveGatewayModelMapping(binding.modelMappings, requestedModel));
|
|
5806
5880
|
}
|
|
5807
|
-
if (
|
|
5881
|
+
if (_chunkYEVWA4C7cjs.isKindMappedEndpoint.call(void 0, binding.endpoint)) {
|
|
5808
5882
|
const map = _nullishCoalesce(binding.modelMap, () => ( {}));
|
|
5809
|
-
const kind =
|
|
5883
|
+
const kind = _chunkYEVWA4C7cjs.detectModelKind.call(void 0, binding.endpoint, requestedModel);
|
|
5810
5884
|
if (kind && nonBlank(map[kind])) return true;
|
|
5811
5885
|
if (binding.endpoint === "messages") {
|
|
5812
5886
|
return MESSAGE_FALLBACK_KINDS.some((candidate) => nonBlank(map[candidate]));
|
|
@@ -5814,12 +5888,12 @@ function routeCanServe(binding, requestedModel, role) {
|
|
|
5814
5888
|
return nonBlank(map.codex);
|
|
5815
5889
|
}
|
|
5816
5890
|
if (binding.endpoint === "chat" && binding.dispatchMode === "prefix") {
|
|
5817
|
-
return
|
|
5891
|
+
return _chunkYEVWA4C7cjs.resolvePrefixTarget.call(void 0, binding.prefixTargets, requestedModel) !== null;
|
|
5818
5892
|
}
|
|
5819
5893
|
if (binding.endpoint === "chat") {
|
|
5820
5894
|
if (!requestedModel) return false;
|
|
5821
5895
|
const wanted = requestedModel.trim().toLowerCase();
|
|
5822
|
-
return (_nullishCoalesce(binding.models, () => ( []))).some((ref) => _optionalChain([modelIdOf, 'call',
|
|
5896
|
+
return (_nullishCoalesce(binding.models, () => ( []))).some((ref) => _optionalChain([modelIdOf, 'call', _300 => _300(ref), 'optionalAccess', _301 => _301.toLowerCase, 'call', _302 => _302()]) === wanted);
|
|
5823
5897
|
}
|
|
5824
5898
|
return role === "background" ? nonBlank(binding.backgroundModel) : nonBlank(binding.defaultModel);
|
|
5825
5899
|
}
|
|
@@ -5852,9 +5926,9 @@ function targetPrefixRefs(target, refs) {
|
|
|
5852
5926
|
function applySingleModel(config, binding, targetModel) {
|
|
5853
5927
|
const ref = targetRef(binding.target, targetModel);
|
|
5854
5928
|
if (!ref) return;
|
|
5855
|
-
if (
|
|
5929
|
+
if (_chunkYEVWA4C7cjs.isKindMappedEndpoint.call(void 0, binding.endpoint)) {
|
|
5856
5930
|
config.modelMap = Object.fromEntries(
|
|
5857
|
-
|
|
5931
|
+
_chunkYEVWA4C7cjs.modelKindsForEndpoint.call(void 0, binding.endpoint).map((kind) => [kind, ref])
|
|
5858
5932
|
);
|
|
5859
5933
|
} else if (binding.endpoint === "chat") {
|
|
5860
5934
|
config.models = [ref];
|
|
@@ -5870,11 +5944,11 @@ function gatewayBindingToEndpointConfig(binding, requestedModel) {
|
|
|
5870
5944
|
endpoint: binding.endpoint,
|
|
5871
5945
|
useSubscription: target.kind !== "provider"
|
|
5872
5946
|
};
|
|
5873
|
-
const usesGenericModelHandling = binding.modelMode === "passthrough" || Boolean(_optionalChain([binding, 'access',
|
|
5947
|
+
const usesGenericModelHandling = binding.modelMode === "passthrough" || Boolean(_optionalChain([binding, 'access', _303 => _303.modelMappings, 'optionalAccess', _304 => _304.length]));
|
|
5874
5948
|
const dynamicModel = binding.modelMode === "passthrough" ? requestedModel : resolveGatewayModelMapping(binding.modelMappings, requestedModel);
|
|
5875
5949
|
if (usesGenericModelHandling) {
|
|
5876
5950
|
if (nonBlank(dynamicModel)) applySingleModel(config, binding, dynamicModel);
|
|
5877
|
-
} else if (
|
|
5951
|
+
} else if (_chunkYEVWA4C7cjs.isKindMappedEndpoint.call(void 0, binding.endpoint)) {
|
|
5878
5952
|
config.modelMap = Object.fromEntries(
|
|
5879
5953
|
Object.entries(_nullishCoalesce(binding.modelMap, () => ( {}))).map(([kind, ref]) => [kind, targetRef(target, ref)])
|
|
5880
5954
|
);
|
|
@@ -5905,7 +5979,7 @@ function candidateGatewayBindings(bindings, apiKeyId, endpoint) {
|
|
|
5905
5979
|
const candidates = (_nullishCoalesce(bindings, () => ( []))).filter(
|
|
5906
5980
|
(binding) => binding.enabled && binding.endpoint === endpoint && gatewayBindingAllowsKey(binding, apiKeyId)
|
|
5907
5981
|
);
|
|
5908
|
-
const scopeOf = (binding) => _nullishCoalesce(binding.keyScope, () => ( (_optionalChain([binding, 'access',
|
|
5982
|
+
const scopeOf = (binding) => _nullishCoalesce(binding.keyScope, () => ( (_optionalChain([binding, 'access', _305 => _305.apiKeyIds, 'optionalAccess', _306 => _306.length]) ? "selected" : "all")));
|
|
5909
5983
|
const scoped = candidates.filter((binding) => scopeOf(binding) === "selected");
|
|
5910
5984
|
const pool = scoped.length > 0 ? scoped : candidates.filter((binding) => scopeOf(binding) === "all");
|
|
5911
5985
|
return pool.sort(
|
|
@@ -5959,7 +6033,7 @@ function syntheticBinding(request) {
|
|
|
5959
6033
|
};
|
|
5960
6034
|
}
|
|
5961
6035
|
function transformerRegistered(llmConfig, name) {
|
|
5962
|
-
return Boolean(_optionalChain([llmConfig, 'access',
|
|
6036
|
+
return Boolean(_optionalChain([llmConfig, 'access', _307 => _307.getTransformerService, 'call', _308 => _308(), 'optionalAccess', _309 => _309.getTransformer, 'call', _310 => _310(name)]));
|
|
5963
6037
|
}
|
|
5964
6038
|
var RouteLeaseTargetResolver = class {
|
|
5965
6039
|
constructor(llmConfig, options = {}) {
|
|
@@ -5973,12 +6047,12 @@ var RouteLeaseTargetResolver = class {
|
|
|
5973
6047
|
await this.preflightTarget(request);
|
|
5974
6048
|
const binding = syntheticBinding(request);
|
|
5975
6049
|
const config = gatewayBindingToEndpointConfig(binding, request.model);
|
|
5976
|
-
const result = await
|
|
6050
|
+
const result = await _chunkYEVWA4C7cjs.resolveRoute.call(void 0, {
|
|
5977
6051
|
config,
|
|
5978
6052
|
ingressFormat: runtime.ingressFormat,
|
|
5979
6053
|
llmConfig: this.llmConfig,
|
|
5980
6054
|
requestedModel: request.model,
|
|
5981
|
-
sessionId: _nullishCoalesce(_optionalChain([request, 'access',
|
|
6055
|
+
sessionId: _nullishCoalesce(_optionalChain([request, 'access', _311 => _311.execution, 'optionalAccess', _312 => _312.sessionIdHash]), () => ( null))
|
|
5982
6056
|
});
|
|
5983
6057
|
if (!result.ok) {
|
|
5984
6058
|
throw new RouteLeaseError(
|
|
@@ -6001,7 +6075,7 @@ var RouteLeaseTargetResolver = class {
|
|
|
6001
6075
|
throw new RouteLeaseError("model_not_configured", "model is not configured for the provider");
|
|
6002
6076
|
}
|
|
6003
6077
|
if (target.keyId) {
|
|
6004
|
-
const availability = await _optionalChain([this, 'access',
|
|
6078
|
+
const availability = await _optionalChain([this, 'access', _313 => _313.options, 'access', _314 => _314.providerKeys, 'optionalAccess', _315 => _315.getKeyAvailability, 'optionalCall', _316 => _316(
|
|
6005
6079
|
target.providerId,
|
|
6006
6080
|
target.keyId
|
|
6007
6081
|
)]);
|
|
@@ -6014,9 +6088,9 @@ var RouteLeaseTargetResolver = class {
|
|
|
6014
6088
|
}
|
|
6015
6089
|
} else {
|
|
6016
6090
|
const directKey = resolveEnvKey(provider.api_key);
|
|
6017
|
-
const poolAvailability = await _optionalChain([this, 'access',
|
|
6091
|
+
const poolAvailability = await _optionalChain([this, 'access', _317 => _317.options, 'access', _318 => _318.providerKeys, 'optionalAccess', _319 => _319.getPoolAvailability, 'optionalCall', _320 => _320(target.providerId)]);
|
|
6018
6092
|
const poolReady = poolAvailability ? poolAvailability.outcome === "usable" : this.options.providerKeys ? await this.options.providerKeys.hasUsableKeys(target.providerId) : false;
|
|
6019
|
-
if (!directKey && _optionalChain([poolAvailability, 'optionalAccess',
|
|
6093
|
+
if (!directKey && _optionalChain([poolAvailability, 'optionalAccess', _321 => _321.outcome]) === "exhausted") {
|
|
6020
6094
|
throw new RouteLeaseError("upstream_exhausted", "provider key pool is temporarily exhausted", {
|
|
6021
6095
|
retryAfterSeconds: poolAvailability.retryAfterSeconds
|
|
6022
6096
|
});
|
|
@@ -6040,14 +6114,14 @@ var RouteLeaseTargetResolver = class {
|
|
|
6040
6114
|
}
|
|
6041
6115
|
async preflightSubscription(target, model) {
|
|
6042
6116
|
const registry = _chunkQBZJ7P2Tcjs.getSubscriptionRegistryForOutbound.call(void 0, );
|
|
6043
|
-
const profile = _nullishCoalesce(_optionalChain([registry, 'optionalAccess',
|
|
6117
|
+
const profile = _nullishCoalesce(_optionalChain([registry, 'optionalAccess', _322 => _322.getProfile, 'call', _323 => _323(target.providerId)]), () => ( null));
|
|
6044
6118
|
if (!profile) throw new RouteLeaseError("upstream_not_found", "subscription provider was not found");
|
|
6045
|
-
await _optionalChain([this, 'access',
|
|
6046
|
-
const names = _nullishCoalesce(_nullishCoalesce(_optionalChain([profile, 'access',
|
|
6119
|
+
await _optionalChain([this, 'access', _324 => _324.options, 'access', _325 => _325.subscriptions, 'optionalAccess', _326 => _326.assertAvailable, 'call', _327 => _327(target, model)]);
|
|
6120
|
+
const names = _nullishCoalesce(_nullishCoalesce(_optionalChain([profile, 'access', _328 => _328.resolveProviderTransformerNames, 'optionalCall', _329 => _329(model)]), () => ( profile.providerTransformerNames)), () => ( []));
|
|
6047
6121
|
if (names.some((name) => !transformerRegistered(this.llmConfig, name))) {
|
|
6048
6122
|
throw new RouteLeaseError("format_unsupported", "a required transformer is unavailable");
|
|
6049
6123
|
}
|
|
6050
|
-
if (_optionalChain([profile, 'access',
|
|
6124
|
+
if (_optionalChain([profile, 'access', _330 => _330.modelTransformerNames, 'optionalAccess', _331 => _331.some, 'call', _332 => _332((name) => !transformerRegistered(this.llmConfig, name))])) {
|
|
6051
6125
|
throw new RouteLeaseError("format_unsupported", "a required model transformer is unavailable");
|
|
6052
6126
|
}
|
|
6053
6127
|
}
|
|
@@ -6069,7 +6143,7 @@ function createResponsesCompactHandler(options = {}) {
|
|
|
6069
6143
|
const parsed = JSON.parse(rawBody);
|
|
6070
6144
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error();
|
|
6071
6145
|
body = parsed;
|
|
6072
|
-
} catch (
|
|
6146
|
+
} catch (e43) {
|
|
6073
6147
|
throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({
|
|
6074
6148
|
status: 400,
|
|
6075
6149
|
code: "invalid_request_body",
|
|
@@ -6160,7 +6234,7 @@ var BoundedSseFrameDecoder = class {
|
|
|
6160
6234
|
let decoded;
|
|
6161
6235
|
try {
|
|
6162
6236
|
decoded = this.#decoder.decode(chunk, { stream: true });
|
|
6163
|
-
} catch (
|
|
6237
|
+
} catch (e44) {
|
|
6164
6238
|
protocolFailure2();
|
|
6165
6239
|
}
|
|
6166
6240
|
return this.#append(decoded, false);
|
|
@@ -6169,7 +6243,7 @@ var BoundedSseFrameDecoder = class {
|
|
|
6169
6243
|
let tail;
|
|
6170
6244
|
try {
|
|
6171
6245
|
tail = this.#decoder.decode();
|
|
6172
|
-
} catch (
|
|
6246
|
+
} catch (e45) {
|
|
6173
6247
|
protocolFailure2();
|
|
6174
6248
|
}
|
|
6175
6249
|
const frames = this.#append(tail, true);
|
|
@@ -6299,7 +6373,7 @@ var HostedImageSsePipeline = class {
|
|
|
6299
6373
|
if (this.#cancelPromise) return this.#cancelPromise;
|
|
6300
6374
|
this.#cancelled = true;
|
|
6301
6375
|
this.#cancelPromise = Promise.allSettled([
|
|
6302
|
-
_nullishCoalesce(_optionalChain([this, 'access',
|
|
6376
|
+
_nullishCoalesce(_optionalChain([this, 'access', _333 => _333.#reader, 'optionalAccess', _334 => _334.cancel, 'call', _335 => _335(reason)]), () => ( Promise.resolve())),
|
|
6303
6377
|
this.#closeActiveImageIterator(),
|
|
6304
6378
|
this.#options.onCancel()
|
|
6305
6379
|
]).then(() => void 0);
|
|
@@ -6313,7 +6387,7 @@ var HostedImageSsePipeline = class {
|
|
|
6313
6387
|
let parsed;
|
|
6314
6388
|
try {
|
|
6315
6389
|
parsed = JSON.parse(frame2.data);
|
|
6316
|
-
} catch (
|
|
6390
|
+
} catch (e46) {
|
|
6317
6391
|
protocolFailure2();
|
|
6318
6392
|
}
|
|
6319
6393
|
if (!isRecord8(parsed) || typeof parsed.type !== "string" || parsed.type.length > 256) {
|
|
@@ -6670,7 +6744,7 @@ data: ${JSON.stringify(event)}
|
|
|
6670
6744
|
#closeActiveImageIterator() {
|
|
6671
6745
|
if (this.#activeImageIteratorClose) return this.#activeImageIteratorClose;
|
|
6672
6746
|
const iterator = this.#activeImageIterator;
|
|
6673
|
-
if (!_optionalChain([iterator, 'optionalAccess',
|
|
6747
|
+
if (!_optionalChain([iterator, 'optionalAccess', _336 => _336.return])) return Promise.resolve();
|
|
6674
6748
|
this.#activeImageIteratorClose = Promise.resolve(iterator.return()).then(
|
|
6675
6749
|
() => void 0,
|
|
6676
6750
|
() => void 0
|
|
@@ -6707,7 +6781,7 @@ function createNativeResponsesHostedImageSseResponse(options) {
|
|
|
6707
6781
|
},
|
|
6708
6782
|
async cancel(reason) {
|
|
6709
6783
|
await pipeline.cancel(reason);
|
|
6710
|
-
await _optionalChain([iterator, 'access',
|
|
6784
|
+
await _optionalChain([iterator, 'access', _337 => _337.return, 'optionalCall', _338 => _338()]);
|
|
6711
6785
|
}
|
|
6712
6786
|
});
|
|
6713
6787
|
return transformedResponse(options.upstream, body);
|
|
@@ -6779,7 +6853,7 @@ function parseJsonObject(bytes) {
|
|
|
6779
6853
|
let text;
|
|
6780
6854
|
try {
|
|
6781
6855
|
text = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
6782
|
-
} catch (
|
|
6856
|
+
} catch (e47) {
|
|
6783
6857
|
protocolFailure3();
|
|
6784
6858
|
}
|
|
6785
6859
|
try {
|
|
@@ -6952,7 +7026,7 @@ var NativeResponsesHostedImageRequestLease = class {
|
|
|
6952
7026
|
#wrapSse(input) {
|
|
6953
7027
|
const status = _nullishCoalesce(input.rawStatus, () => ( input.response.status));
|
|
6954
7028
|
if (status < 200 || status >= 300) return input.response;
|
|
6955
|
-
const hasInheritedContext = _optionalChain([this, 'access',
|
|
7029
|
+
const hasInheritedContext = _optionalChain([this, 'access', _339 => _339.#input, 'access', _340 => _340.previousHostedImageState, 'optionalAccess', _341 => _341.hasImageContext]) === true;
|
|
6956
7030
|
return createNativeResponsesHostedImageSseResponse({
|
|
6957
7031
|
upstream: input.response,
|
|
6958
7032
|
signal: this.#input.signal,
|
|
@@ -6978,7 +7052,7 @@ var NativeResponsesHostedImageRequestLease = class {
|
|
|
6978
7052
|
signal: this.#input.signal,
|
|
6979
7053
|
...this.#input.authorizedPreviousResponseId ? {
|
|
6980
7054
|
authorizedPreviousResponseId: this.#input.authorizedPreviousResponseId,
|
|
6981
|
-
authorizedPreviousResponseKnownEmpty: _optionalChain([this, 'access',
|
|
7055
|
+
authorizedPreviousResponseKnownEmpty: _optionalChain([this, 'access', _342 => _342.#input, 'access', _343 => _343.previousHostedImageState, 'optionalAccess', _344 => _344.hasImageContext]) !== true
|
|
6982
7056
|
} : {},
|
|
6983
7057
|
mainProviderId: this.#input.mainProviderId,
|
|
6984
7058
|
...input.selectedMainAccountId ? { selectedMainAccountId: input.selectedMainAccountId } : {}
|
|
@@ -7013,7 +7087,7 @@ var NativeResponsesHostedImageRequestLease = class {
|
|
|
7013
7087
|
if (!UPSTREAM_CALL_ID_PATTERN4.test(selected.upstreamCallId)) protocolFailure3();
|
|
7014
7088
|
}
|
|
7015
7089
|
this.#runtime.validateSelection(this.#admission, parsedSelection.selection);
|
|
7016
|
-
const hasInheritedContext = _optionalChain([this, 'access',
|
|
7090
|
+
const hasInheritedContext = _optionalChain([this, 'access', _345 => _345.#input, 'access', _346 => _346.previousHostedImageState, 'optionalAccess', _347 => _347.hasImageContext]) === true;
|
|
7017
7091
|
const requiresScope = parsedSelection.imageCalls.length > 0 || hasInheritedContext || this.#admission.explicitCallIds.length > 0;
|
|
7018
7092
|
const publicOutput = [...upstreamBody.output];
|
|
7019
7093
|
const pendingReceipts = [];
|
|
@@ -7030,7 +7104,7 @@ var NativeResponsesHostedImageRequestLease = class {
|
|
|
7030
7104
|
signal: this.#input.signal,
|
|
7031
7105
|
...this.#input.authorizedPreviousResponseId ? {
|
|
7032
7106
|
authorizedPreviousResponseId: this.#input.authorizedPreviousResponseId,
|
|
7033
|
-
authorizedPreviousResponseKnownEmpty: _optionalChain([this, 'access',
|
|
7107
|
+
authorizedPreviousResponseKnownEmpty: _optionalChain([this, 'access', _348 => _348.#input, 'access', _349 => _349.previousHostedImageState, 'optionalAccess', _350 => _350.hasImageContext]) !== true
|
|
7034
7108
|
} : {},
|
|
7035
7109
|
mainProviderId: this.#input.mainProviderId,
|
|
7036
7110
|
...input.selectedMainAccountId ? { selectedMainAccountId: input.selectedMainAccountId } : {}
|
|
@@ -7076,7 +7150,7 @@ function createNativeResponsesHostedImageIngress(runtimeFactory, options = {}) {
|
|
|
7076
7150
|
const createRequestId = _nullishCoalesce(options.createRequestId, () => ( (() => `hosted-image-${_crypto.randomUUID.call(void 0, )}`)));
|
|
7077
7151
|
return Object.freeze({
|
|
7078
7152
|
prepare: async (input) => {
|
|
7079
|
-
if (input.operation !== "create" || input.profile !== "native" || !hasImageOwnedResponsesInput(input.body) && !_optionalChain([input, 'access',
|
|
7153
|
+
if (input.operation !== "create" || input.profile !== "native" || !hasImageOwnedResponsesInput(input.body) && !_optionalChain([input, 'access', _351 => _351.previousHostedImageState, 'optionalAccess', _352 => _352.hasImageContext]) && !_optionalChain([input, 'access', _353 => _353.previousHostedImageState, 'optionalAccess', _354 => _354.pendingReceipts, 'access', _355 => _355.length])) {
|
|
7080
7154
|
return null;
|
|
7081
7155
|
}
|
|
7082
7156
|
if (!input.hostedImageGenerationAllowed) {
|
|
@@ -7109,7 +7183,7 @@ function createNativeResponsesHostedImageIngress(runtimeFactory, options = {}) {
|
|
|
7109
7183
|
const selection = prepareNativeResponsesImageSelection({
|
|
7110
7184
|
body: input.body,
|
|
7111
7185
|
admission,
|
|
7112
|
-
pendingReceipts: _optionalChain([input, 'access',
|
|
7186
|
+
pendingReceipts: _optionalChain([input, 'access', _356 => _356.previousHostedImageState, 'optionalAccess', _357 => _357.pendingReceipts]),
|
|
7113
7187
|
...options.createSelectorName ? { createSelectorName: options.createSelectorName } : {}
|
|
7114
7188
|
});
|
|
7115
7189
|
return new NativeResponsesHostedImageRequestLease({
|
|
@@ -7701,9 +7775,9 @@ function stringList(value, cap) {
|
|
|
7701
7775
|
}
|
|
7702
7776
|
function tavilyConfig(value) {
|
|
7703
7777
|
const raw = record4(value);
|
|
7704
|
-
const apiKey = configString(_optionalChain([raw, 'optionalAccess',
|
|
7778
|
+
const apiKey = configString(_optionalChain([raw, 'optionalAccess', _358 => _358["apiKey"]]));
|
|
7705
7779
|
if (!apiKey) return void 0;
|
|
7706
|
-
const apiHost = configString(_optionalChain([raw, 'optionalAccess',
|
|
7780
|
+
const apiHost = configString(_optionalChain([raw, 'optionalAccess', _359 => _359["apiHost"]]));
|
|
7707
7781
|
return { apiKey, ...apiHost ? { apiHost } : {} };
|
|
7708
7782
|
}
|
|
7709
7783
|
function jinaConfig(value) {
|
|
@@ -7715,10 +7789,10 @@ function jinaConfig(value) {
|
|
|
7715
7789
|
}
|
|
7716
7790
|
function searxngConfig(value) {
|
|
7717
7791
|
const raw = record4(value);
|
|
7718
|
-
const apiHost = configString(_optionalChain([raw, 'optionalAccess',
|
|
7792
|
+
const apiHost = configString(_optionalChain([raw, 'optionalAccess', _360 => _360["apiHost"]]));
|
|
7719
7793
|
if (!apiHost) return void 0;
|
|
7720
|
-
const basicAuthUsername = configString(_optionalChain([raw, 'optionalAccess',
|
|
7721
|
-
const basicAuthPassword = configString(_optionalChain([raw, 'optionalAccess',
|
|
7794
|
+
const basicAuthUsername = configString(_optionalChain([raw, 'optionalAccess', _361 => _361["basicAuthUsername"]]));
|
|
7795
|
+
const basicAuthPassword = configString(_optionalChain([raw, 'optionalAccess', _362 => _362["basicAuthPassword"]]));
|
|
7722
7796
|
return {
|
|
7723
7797
|
apiHost,
|
|
7724
7798
|
...basicAuthUsername ? { basicAuthUsername } : {},
|
|
@@ -7727,9 +7801,9 @@ function searxngConfig(value) {
|
|
|
7727
7801
|
}
|
|
7728
7802
|
function zhipuConfig(value) {
|
|
7729
7803
|
const raw = record4(value);
|
|
7730
|
-
const apiKey = configString(_optionalChain([raw, 'optionalAccess',
|
|
7804
|
+
const apiKey = configString(_optionalChain([raw, 'optionalAccess', _363 => _363["apiKey"]]));
|
|
7731
7805
|
if (!apiKey) return void 0;
|
|
7732
|
-
const apiHost = configString(_optionalChain([raw, 'optionalAccess',
|
|
7806
|
+
const apiHost = configString(_optionalChain([raw, 'optionalAccess', _364 => _364["apiHost"]]));
|
|
7733
7807
|
return { apiKey, ...apiHost ? { apiHost } : {} };
|
|
7734
7808
|
}
|
|
7735
7809
|
function normalizeSearchApiProviderConfigs(value) {
|
|
@@ -7881,11 +7955,11 @@ var DEFAULT_ACCOUNT_HEALTH = {
|
|
|
7881
7955
|
overloadCooldownMs: 10 * 6e4
|
|
7882
7956
|
};
|
|
7883
7957
|
function normalizeAccountHealth(raw) {
|
|
7884
|
-
const ah = _optionalChain([raw, 'optionalAccess',
|
|
7958
|
+
const ah = _optionalChain([raw, 'optionalAccess', _365 => _365.accountHealth]);
|
|
7885
7959
|
return {
|
|
7886
|
-
overloadCooldownEnabled: _optionalChain([ah, 'optionalAccess',
|
|
7960
|
+
overloadCooldownEnabled: _optionalChain([ah, 'optionalAccess', _366 => _366.overloadCooldownEnabled]) !== false,
|
|
7887
7961
|
overloadCooldownMs: clampNumber(
|
|
7888
|
-
_optionalChain([ah, 'optionalAccess',
|
|
7962
|
+
_optionalChain([ah, 'optionalAccess', _367 => _367.overloadCooldownMs]),
|
|
7889
7963
|
6e4,
|
|
7890
7964
|
36e5,
|
|
7891
7965
|
DEFAULT_ACCOUNT_HEALTH.overloadCooldownMs
|
|
@@ -7907,25 +7981,25 @@ var DEFAULT_ALLOWANCE_SCHEDULING = {
|
|
|
7907
7981
|
priorityPenalty: 100
|
|
7908
7982
|
};
|
|
7909
7983
|
function normalizeAllowanceScheduling(raw) {
|
|
7910
|
-
const value = _optionalChain([raw, 'optionalAccess',
|
|
7984
|
+
const value = _optionalChain([raw, 'optionalAccess', _368 => _368.allowanceScheduling]);
|
|
7911
7985
|
const demoteAtPercent = clampNumber(
|
|
7912
|
-
_optionalChain([value, 'optionalAccess',
|
|
7986
|
+
_optionalChain([value, 'optionalAccess', _369 => _369.demoteAtPercent]),
|
|
7913
7987
|
0,
|
|
7914
7988
|
100,
|
|
7915
7989
|
DEFAULT_ALLOWANCE_SCHEDULING.demoteAtPercent
|
|
7916
7990
|
);
|
|
7917
7991
|
const requestedPause = clampNumber(
|
|
7918
|
-
_optionalChain([value, 'optionalAccess',
|
|
7992
|
+
_optionalChain([value, 'optionalAccess', _370 => _370.pauseAtPercent]),
|
|
7919
7993
|
0,
|
|
7920
7994
|
100,
|
|
7921
7995
|
DEFAULT_ALLOWANCE_SCHEDULING.pauseAtPercent
|
|
7922
7996
|
);
|
|
7923
7997
|
return {
|
|
7924
|
-
enabled: _optionalChain([value, 'optionalAccess',
|
|
7998
|
+
enabled: _optionalChain([value, 'optionalAccess', _371 => _371.enabled]) === true,
|
|
7925
7999
|
demoteAtPercent,
|
|
7926
8000
|
pauseAtPercent: Math.max(demoteAtPercent, requestedPause),
|
|
7927
8001
|
priorityPenalty: Math.trunc(clampNumber(
|
|
7928
|
-
_optionalChain([value, 'optionalAccess',
|
|
8002
|
+
_optionalChain([value, 'optionalAccess', _372 => _372.priorityPenalty]),
|
|
7929
8003
|
1,
|
|
7930
8004
|
1e3,
|
|
7931
8005
|
DEFAULT_ALLOWANCE_SCHEDULING.priorityPenalty
|
|
@@ -7933,29 +8007,29 @@ function normalizeAllowanceScheduling(raw) {
|
|
|
7933
8007
|
};
|
|
7934
8008
|
}
|
|
7935
8009
|
function normalizeAccountProbe(raw) {
|
|
7936
|
-
const ap = _optionalChain([raw, 'optionalAccess',
|
|
8010
|
+
const ap = _optionalChain([raw, 'optionalAccess', _373 => _373.accountProbe]);
|
|
7937
8011
|
return {
|
|
7938
|
-
enabled: _optionalChain([ap, 'optionalAccess',
|
|
7939
|
-
intervalMs: clampNumber(_optionalChain([ap, 'optionalAccess',
|
|
7940
|
-
onlyMultiAccount: _optionalChain([ap, 'optionalAccess',
|
|
7941
|
-
timeoutMs: clampNumber(_optionalChain([ap, 'optionalAccess',
|
|
8012
|
+
enabled: _optionalChain([ap, 'optionalAccess', _374 => _374.enabled]) === true,
|
|
8013
|
+
intervalMs: clampNumber(_optionalChain([ap, 'optionalAccess', _375 => _375.intervalMs]), 6e4, 864e5, DEFAULT_ACCOUNT_PROBE.intervalMs),
|
|
8014
|
+
onlyMultiAccount: _optionalChain([ap, 'optionalAccess', _376 => _376.onlyMultiAccount]) !== false,
|
|
8015
|
+
timeoutMs: clampNumber(_optionalChain([ap, 'optionalAccess', _377 => _377.timeoutMs]), 1e3, 6e4, DEFAULT_ACCOUNT_PROBE.timeoutMs),
|
|
7942
8016
|
historySize: Math.trunc(
|
|
7943
|
-
clampNumber(_optionalChain([ap, 'optionalAccess',
|
|
8017
|
+
clampNumber(_optionalChain([ap, 'optionalAccess', _378 => _378.historySize]), 1, 200, DEFAULT_ACCOUNT_PROBE.historySize)
|
|
7944
8018
|
),
|
|
7945
|
-
staggerMs: clampNumber(_optionalChain([ap, 'optionalAccess',
|
|
8019
|
+
staggerMs: clampNumber(_optionalChain([ap, 'optionalAccess', _379 => _379.staggerMs]), 0, 6e4, DEFAULT_ACCOUNT_PROBE.staggerMs)
|
|
7946
8020
|
};
|
|
7947
8021
|
}
|
|
7948
8022
|
function normalizeAudit(raw) {
|
|
7949
|
-
const a = _optionalChain([raw, 'optionalAccess',
|
|
8023
|
+
const a = _optionalChain([raw, 'optionalAccess', _380 => _380.audit]);
|
|
7950
8024
|
return {
|
|
7951
|
-
enabled: _optionalChain([a, 'optionalAccess',
|
|
7952
|
-
captureBodies: _optionalChain([a, 'optionalAccess',
|
|
7953
|
-
maxBodyBytes: normalizeMaxBodyBytes(_optionalChain([a, 'optionalAccess',
|
|
8025
|
+
enabled: _optionalChain([a, 'optionalAccess', _381 => _381.enabled]) === true,
|
|
8026
|
+
captureBodies: _optionalChain([a, 'optionalAccess', _382 => _382.captureBodies]) === true,
|
|
8027
|
+
maxBodyBytes: normalizeMaxBodyBytes(_optionalChain([a, 'optionalAccess', _383 => _383.maxBodyBytes])),
|
|
7954
8028
|
retentionDays: Math.trunc(
|
|
7955
|
-
clampNumber(_optionalChain([a, 'optionalAccess',
|
|
8029
|
+
clampNumber(_optionalChain([a, 'optionalAccess', _384 => _384.retentionDays]), 1, 365, _audittypes.DEFAULT_AUDIT_CONFIG.retentionDays)
|
|
7956
8030
|
),
|
|
7957
|
-
compactStreamingBodies: _optionalChain([a, 'optionalAccess',
|
|
7958
|
-
trustForwardedFor: _optionalChain([a, 'optionalAccess',
|
|
8031
|
+
compactStreamingBodies: _optionalChain([a, 'optionalAccess', _385 => _385.compactStreamingBodies]) === true,
|
|
8032
|
+
trustForwardedFor: _optionalChain([a, 'optionalAccess', _386 => _386.trustForwardedFor]) === true
|
|
7959
8033
|
};
|
|
7960
8034
|
}
|
|
7961
8035
|
function normalizeMaxBodyBytes(value) {
|
|
@@ -7966,26 +8040,26 @@ function normalizeMaxBodyBytes(value) {
|
|
|
7966
8040
|
return Math.trunc(Math.min(1048576, value));
|
|
7967
8041
|
}
|
|
7968
8042
|
function normalizeBilling(raw) {
|
|
7969
|
-
const b = _optionalChain([raw, 'optionalAccess',
|
|
8043
|
+
const b = _optionalChain([raw, 'optionalAccess', _387 => _387.billing]);
|
|
7970
8044
|
const config = {
|
|
7971
|
-
enabled: _optionalChain([b, 'optionalAccess',
|
|
8045
|
+
enabled: _optionalChain([b, 'optionalAccess', _388 => _388.enabled]) === true,
|
|
7972
8046
|
maxRetryAgeMs: Math.trunc(
|
|
7973
|
-
clampNumber(_optionalChain([b, 'optionalAccess',
|
|
8047
|
+
clampNumber(_optionalChain([b, 'optionalAccess', _389 => _389.maxRetryAgeMs]), 6e4, 2592e6, _billingtypes.DEFAULT_BILLING_CONFIG.maxRetryAgeMs)
|
|
7974
8048
|
)
|
|
7975
8049
|
};
|
|
7976
|
-
if (typeof _optionalChain([b, 'optionalAccess',
|
|
7977
|
-
if (typeof _optionalChain([b, 'optionalAccess',
|
|
8050
|
+
if (typeof _optionalChain([b, 'optionalAccess', _390 => _390.endpoint]) === "string" && b.endpoint.trim()) config.endpoint = b.endpoint.trim();
|
|
8051
|
+
if (typeof _optionalChain([b, 'optionalAccess', _391 => _391.secret]) === "string" && b.secret.length > 0) config.secret = b.secret;
|
|
7978
8052
|
return config;
|
|
7979
8053
|
}
|
|
7980
8054
|
var DEFAULT_FINGERPRINT = { enabled: false };
|
|
7981
8055
|
function normalizeFingerprint(raw) {
|
|
7982
|
-
const f = _optionalChain([raw, 'optionalAccess',
|
|
7983
|
-
const out = { enabled: _optionalChain([f, 'optionalAccess',
|
|
7984
|
-
if (typeof _optionalChain([f, 'optionalAccess',
|
|
8056
|
+
const f = _optionalChain([raw, 'optionalAccess', _392 => _392.fingerprint]);
|
|
8057
|
+
const out = { enabled: _optionalChain([f, 'optionalAccess', _393 => _393.enabled]) === true };
|
|
8058
|
+
if (typeof _optionalChain([f, 'optionalAccess', _394 => _394.ua]) === "string" && f.ua.trim().length > 0) out.ua = f.ua.trim();
|
|
7985
8059
|
return out;
|
|
7986
8060
|
}
|
|
7987
8061
|
function normalizeVoucher(raw) {
|
|
7988
|
-
return { enabled: _optionalChain([raw, 'optionalAccess',
|
|
8062
|
+
return { enabled: _optionalChain([raw, 'optionalAccess', _395 => _395.voucher, 'optionalAccess', _396 => _396.enabled]) === true };
|
|
7989
8063
|
}
|
|
7990
8064
|
var DEFAULT_ANTHROPIC_SEGMENT = {
|
|
7991
8065
|
countTokens: { mode: "auto", estimateBudgetMs: 2e3 },
|
|
@@ -7998,34 +8072,34 @@ var DEFAULT_ANTHROPIC_SEGMENT = {
|
|
|
7998
8072
|
var COUNT_TOKENS_MODES = ["auto", "passthrough", "estimate", "reject"];
|
|
7999
8073
|
var MODELS_SHAPES = ["auto", "anthropic", "openai"];
|
|
8000
8074
|
function normalizeAnthropicSegment(raw) {
|
|
8001
|
-
const a = _optionalChain([raw, 'optionalAccess',
|
|
8075
|
+
const a = _optionalChain([raw, 'optionalAccess', _397 => _397.anthropic]);
|
|
8002
8076
|
return {
|
|
8003
8077
|
countTokens: {
|
|
8004
|
-
mode: COUNT_TOKENS_MODES.includes(String(_optionalChain([a, 'optionalAccess',
|
|
8078
|
+
mode: COUNT_TOKENS_MODES.includes(String(_optionalChain([a, 'optionalAccess', _398 => _398.countTokens, 'optionalAccess', _399 => _399.mode]))) ? _optionalChain([a, 'optionalAccess', _400 => _400.countTokens, 'optionalAccess', _401 => _401.mode]) : DEFAULT_ANTHROPIC_SEGMENT.countTokens.mode,
|
|
8005
8079
|
estimateBudgetMs: clampNumber(
|
|
8006
|
-
_optionalChain([a, 'optionalAccess',
|
|
8080
|
+
_optionalChain([a, 'optionalAccess', _402 => _402.countTokens, 'optionalAccess', _403 => _403.estimateBudgetMs]),
|
|
8007
8081
|
100,
|
|
8008
8082
|
6e4,
|
|
8009
8083
|
DEFAULT_ANTHROPIC_SEGMENT.countTokens.estimateBudgetMs
|
|
8010
8084
|
)
|
|
8011
8085
|
},
|
|
8012
|
-
modelsShape: MODELS_SHAPES.includes(String(_optionalChain([a, 'optionalAccess',
|
|
8086
|
+
modelsShape: MODELS_SHAPES.includes(String(_optionalChain([a, 'optionalAccess', _404 => _404.modelsShape]))) ? _optionalChain([a, 'optionalAccess', _405 => _405.modelsShape]) : DEFAULT_ANTHROPIC_SEGMENT.modelsShape,
|
|
8013
8087
|
heartbeatIntervalMs: clampNumber(
|
|
8014
|
-
_optionalChain([a, 'optionalAccess',
|
|
8088
|
+
_optionalChain([a, 'optionalAccess', _406 => _406.heartbeatIntervalMs]),
|
|
8015
8089
|
0,
|
|
8016
8090
|
6e5,
|
|
8017
8091
|
DEFAULT_ANTHROPIC_SEGMENT.heartbeatIntervalMs
|
|
8018
8092
|
),
|
|
8019
8093
|
pdfTextExtraction: {
|
|
8020
8094
|
budgetMs: clampNumber(
|
|
8021
|
-
_optionalChain([a, 'optionalAccess',
|
|
8095
|
+
_optionalChain([a, 'optionalAccess', _407 => _407.pdfTextExtraction, 'optionalAccess', _408 => _408.budgetMs]),
|
|
8022
8096
|
100,
|
|
8023
8097
|
6e4,
|
|
8024
8098
|
DEFAULT_ANTHROPIC_SEGMENT.pdfTextExtraction.budgetMs
|
|
8025
8099
|
)
|
|
8026
8100
|
},
|
|
8027
|
-
proxyOauthUsage: _optionalChain([a, 'optionalAccess',
|
|
8028
|
-
apiHello: _optionalChain([a, 'optionalAccess',
|
|
8101
|
+
proxyOauthUsage: _optionalChain([a, 'optionalAccess', _409 => _409.proxyOauthUsage]) === true,
|
|
8102
|
+
apiHello: _optionalChain([a, 'optionalAccess', _410 => _410.apiHello]) !== false
|
|
8029
8103
|
};
|
|
8030
8104
|
}
|
|
8031
8105
|
var PROXY_TYPES = ["http", "https", "socks5"];
|
|
@@ -8110,14 +8184,14 @@ function clampNumber(value, min, max, fallback) {
|
|
|
8110
8184
|
return Math.min(max, Math.max(min, n));
|
|
8111
8185
|
}
|
|
8112
8186
|
function normalizeQueueSegments(raw) {
|
|
8113
|
-
const umq = _optionalChain([raw, 'optionalAccess',
|
|
8114
|
-
const cq = _optionalChain([raw, 'optionalAccess',
|
|
8187
|
+
const umq = _optionalChain([raw, 'optionalAccess', _411 => _411.userMessageQueue]);
|
|
8188
|
+
const cq = _optionalChain([raw, 'optionalAccess', _412 => _412.concurrencyQueue]);
|
|
8115
8189
|
return {
|
|
8116
8190
|
userMessageQueue: {
|
|
8117
|
-
enabled: _optionalChain([umq, 'optionalAccess',
|
|
8118
|
-
delayMs: clampNumber(_optionalChain([umq, 'optionalAccess',
|
|
8191
|
+
enabled: _optionalChain([umq, 'optionalAccess', _413 => _413.enabled]) === true,
|
|
8192
|
+
delayMs: clampNumber(_optionalChain([umq, 'optionalAccess', _414 => _414.delayMs]), 0, 1e4, DEFAULT_USER_MESSAGE_QUEUE.delayMs),
|
|
8119
8193
|
waitTimeoutMs: clampNumber(
|
|
8120
|
-
_optionalChain([umq, 'optionalAccess',
|
|
8194
|
+
_optionalChain([umq, 'optionalAccess', _415 => _415.waitTimeoutMs]),
|
|
8121
8195
|
1e3,
|
|
8122
8196
|
3e5,
|
|
8123
8197
|
DEFAULT_USER_MESSAGE_QUEUE.waitTimeoutMs
|
|
@@ -8125,14 +8199,14 @@ function normalizeQueueSegments(raw) {
|
|
|
8125
8199
|
},
|
|
8126
8200
|
concurrencyQueue: {
|
|
8127
8201
|
maxQueueSizeFactor: clampNumber(
|
|
8128
|
-
_optionalChain([cq, 'optionalAccess',
|
|
8202
|
+
_optionalChain([cq, 'optionalAccess', _416 => _416.maxQueueSizeFactor]),
|
|
8129
8203
|
1,
|
|
8130
8204
|
10,
|
|
8131
8205
|
DEFAULT_CONCURRENCY_QUEUE.maxQueueSizeFactor
|
|
8132
8206
|
),
|
|
8133
|
-
minQueueSize: clampNumber(_optionalChain([cq, 'optionalAccess',
|
|
8207
|
+
minQueueSize: clampNumber(_optionalChain([cq, 'optionalAccess', _417 => _417.minQueueSize]), 1, 100, DEFAULT_CONCURRENCY_QUEUE.minQueueSize),
|
|
8134
8208
|
waitTimeoutMs: clampNumber(
|
|
8135
|
-
_optionalChain([cq, 'optionalAccess',
|
|
8209
|
+
_optionalChain([cq, 'optionalAccess', _418 => _418.waitTimeoutMs]),
|
|
8136
8210
|
1e3,
|
|
8137
8211
|
3e5,
|
|
8138
8212
|
DEFAULT_CONCURRENCY_QUEUE.waitTimeoutMs
|
|
@@ -8143,11 +8217,11 @@ function normalizeQueueSegments(raw) {
|
|
|
8143
8217
|
var ALL_ENDPOINTS = ["chat", "responses", "messages", "gemini"];
|
|
8144
8218
|
function blankModelMap(endpoint) {
|
|
8145
8219
|
const modelMap = {};
|
|
8146
|
-
for (const kind of
|
|
8220
|
+
for (const kind of _chunkYEVWA4C7cjs.modelKindsForEndpoint.call(void 0, endpoint)) modelMap[kind] = "";
|
|
8147
8221
|
return modelMap;
|
|
8148
8222
|
}
|
|
8149
8223
|
function defaultEndpointConfig(endpoint) {
|
|
8150
|
-
if (
|
|
8224
|
+
if (_chunkYEVWA4C7cjs.isKindMappedEndpoint.call(void 0, endpoint)) {
|
|
8151
8225
|
return { endpoint, modelMap: blankModelMap(endpoint), useSubscription: false };
|
|
8152
8226
|
}
|
|
8153
8227
|
if (endpoint === "chat") {
|
|
@@ -8177,10 +8251,10 @@ function normalizeEndpointConfig(e) {
|
|
|
8177
8251
|
const boundAccountFallbackPolicy = boundAccountId ? e.boundAccountFallbackPolicy === "pool" ? "pool" : "strict" : void 0;
|
|
8178
8252
|
const boundKeyId = typeof e.boundKeyId === "string" && e.boundKeyId.trim() !== "" ? e.boundKeyId : void 0;
|
|
8179
8253
|
let config;
|
|
8180
|
-
if (
|
|
8254
|
+
if (_chunkYEVWA4C7cjs.isKindMappedEndpoint.call(void 0, endpoint)) {
|
|
8181
8255
|
const rawMap = e.modelMap && typeof e.modelMap === "object" ? e.modelMap : {};
|
|
8182
8256
|
const modelMap = {};
|
|
8183
|
-
for (const kind of
|
|
8257
|
+
for (const kind of _chunkYEVWA4C7cjs.modelKindsForEndpoint.call(void 0, endpoint)) {
|
|
8184
8258
|
const v = rawMap[kind];
|
|
8185
8259
|
modelMap[kind] = typeof v === "string" ? v : "";
|
|
8186
8260
|
}
|
|
@@ -8245,7 +8319,7 @@ function normalizeGatewayModelMappings(raw) {
|
|
|
8245
8319
|
return mappings;
|
|
8246
8320
|
}
|
|
8247
8321
|
function hasConfiguredLegacyModels(config) {
|
|
8248
|
-
return Object.values(_nullishCoalesce(config.modelMap, () => ( {}))).some((value) => typeof value === "string" && value.trim()) || Boolean(_optionalChain([config, 'access',
|
|
8322
|
+
return Object.values(_nullishCoalesce(config.modelMap, () => ( {}))).some((value) => typeof value === "string" && value.trim()) || Boolean(_optionalChain([config, 'access', _419 => _419.models, 'optionalAccess', _420 => _420.some, 'call', _421 => _421((value) => typeof value === "string" && value.trim())])) || Boolean(_optionalChain([config, 'access', _422 => _422.defaultModel, 'optionalAccess', _423 => _423.trim, 'call', _424 => _424()])) || Boolean(_optionalChain([config, 'access', _425 => _425.backgroundModel, 'optionalAccess', _426 => _426.trim, 'call', _427 => _427()])) || Boolean(Object.values(_nullishCoalesce(config.prefixTargets, () => ( {}))).some((value) => _optionalChain([value, 'optionalAccess', _428 => _428.trim, 'call', _429 => _429()])));
|
|
8249
8323
|
}
|
|
8250
8324
|
function splitModelRef(ref) {
|
|
8251
8325
|
if (typeof ref !== "string") return null;
|
|
@@ -8313,7 +8387,7 @@ function legacyEndpointToBindings(config) {
|
|
|
8313
8387
|
if (!parsed) continue;
|
|
8314
8388
|
const route = routeFor(parsed.providerId);
|
|
8315
8389
|
route[field] = ref;
|
|
8316
|
-
if (_optionalChain([config, 'access',
|
|
8390
|
+
if (_optionalChain([config, 'access', _430 => _430.backgroundModelIds, 'optionalAccess', _431 => _431.length])) {
|
|
8317
8391
|
route.backgroundModelIds = [...config.backgroundModelIds];
|
|
8318
8392
|
}
|
|
8319
8393
|
}
|
|
@@ -8496,10 +8570,10 @@ function asObject(value) {
|
|
|
8496
8570
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
8497
8571
|
}
|
|
8498
8572
|
function anthropicSessionId(body) {
|
|
8499
|
-
const userId = _optionalChain([asObject, 'call',
|
|
8573
|
+
const userId = _optionalChain([asObject, 'call', _432 => _432(body["metadata"]), 'optionalAccess', _433 => _433["user_id"]]);
|
|
8500
8574
|
if (typeof userId !== "string" || !userId) return void 0;
|
|
8501
8575
|
const matched = ANTHROPIC_SESSION_RE.exec(userId);
|
|
8502
|
-
return _optionalChain([matched, 'optionalAccess',
|
|
8576
|
+
return _optionalChain([matched, 'optionalAccess', _434 => _434[1]]);
|
|
8503
8577
|
}
|
|
8504
8578
|
function anthropicContentFingerprint(body) {
|
|
8505
8579
|
const messages = body["messages"];
|
|
@@ -8677,7 +8751,7 @@ function effectiveOutboundPermissions(value) {
|
|
|
8677
8751
|
if (value === void 0) return LEGACY_OUTBOUND_PERMISSIONS;
|
|
8678
8752
|
try {
|
|
8679
8753
|
return validateOutboundPermissions(value);
|
|
8680
|
-
} catch (
|
|
8754
|
+
} catch (e48) {
|
|
8681
8755
|
return [];
|
|
8682
8756
|
}
|
|
8683
8757
|
}
|
|
@@ -8928,8 +9002,8 @@ var OutboundRateLimiter = (_class16 = class {
|
|
|
8928
9002
|
* recorded (no bucket growth).
|
|
8929
9003
|
*/
|
|
8930
9004
|
check(apiKeyId, now = Date.now(), override) {
|
|
8931
|
-
const maxRequests = _nullishCoalesce(_optionalChain([override, 'optionalAccess',
|
|
8932
|
-
const windowMs = _nullishCoalesce(_optionalChain([override, 'optionalAccess',
|
|
9005
|
+
const maxRequests = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _435 => _435.maxRequests]), () => ( this.maxRequests));
|
|
9006
|
+
const windowMs = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _436 => _436.windowMs]), () => ( this.windowMs));
|
|
8933
9007
|
if (maxRequests === 0) return { allowed: true, retryAfterSeconds: 0 };
|
|
8934
9008
|
const cutoff = now - windowMs;
|
|
8935
9009
|
const timestamps = (_nullishCoalesce(this.hits.get(apiKeyId), () => ( []))).filter((ts) => ts > cutoff);
|
|
@@ -9115,10 +9189,10 @@ async function handleCodexSearchRequest(req, res, deps) {
|
|
|
9115
9189
|
let parseFailed = false;
|
|
9116
9190
|
try {
|
|
9117
9191
|
parsed = raw ? JSON.parse(raw) : {};
|
|
9118
|
-
} catch (
|
|
9192
|
+
} catch (e49) {
|
|
9119
9193
|
parseFailed = true;
|
|
9120
9194
|
}
|
|
9121
|
-
_optionalChain([deps, 'access',
|
|
9195
|
+
_optionalChain([deps, 'access', _437 => _437.onRequestBody, 'optionalCall', _438 => _438(raw, isRecord10(parsed) ? parsed : {})]);
|
|
9122
9196
|
if (parseFailed) {
|
|
9123
9197
|
throw new (0, _chunkG4CZIUIBcjs.OpenAIOperationError)({
|
|
9124
9198
|
status: 400,
|
|
@@ -9163,7 +9237,7 @@ function isUserMessageAnthropic(body) {
|
|
|
9163
9237
|
if (typeof content === "string") return true;
|
|
9164
9238
|
if (Array.isArray(content)) {
|
|
9165
9239
|
const hasToolResult = content.some(
|
|
9166
|
-
(block) => _optionalChain([asObject2, 'call',
|
|
9240
|
+
(block) => _optionalChain([asObject2, 'call', _439 => _439(block), 'optionalAccess', _440 => _440["type"]]) === "tool_result"
|
|
9167
9241
|
);
|
|
9168
9242
|
return !hasToolResult;
|
|
9169
9243
|
}
|
|
@@ -9192,7 +9266,7 @@ function isUserMessageGemini(body) {
|
|
|
9192
9266
|
if (!lastContent || lastContent["role"] !== "user") return false;
|
|
9193
9267
|
const parts = asArray(lastContent["parts"]);
|
|
9194
9268
|
const hasFunctionResponse = parts.some(
|
|
9195
|
-
(part) => _optionalChain([asObject2, 'call',
|
|
9269
|
+
(part) => _optionalChain([asObject2, 'call', _441 => _441(part), 'optionalAccess', _442 => _442["functionResponse"]]) !== void 0
|
|
9196
9270
|
);
|
|
9197
9271
|
return !hasFunctionResponse;
|
|
9198
9272
|
}
|
|
@@ -9366,14 +9440,14 @@ function newVoucherId() {
|
|
|
9366
9440
|
}
|
|
9367
9441
|
function computeVoucherGrant(voucher, currentKey, now) {
|
|
9368
9442
|
if (voucher.type === "credit") {
|
|
9369
|
-
const current = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess',
|
|
9443
|
+
const current = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _443 => _443.totalCostLimitUsd]), () => ( 0));
|
|
9370
9444
|
let granted2 = current + (_nullishCoalesce(voucher.creditUsd, () => ( 0)));
|
|
9371
9445
|
if (voucher.maxTotalCostLimitUsd != null) {
|
|
9372
9446
|
granted2 = Math.min(granted2, voucher.maxTotalCostLimitUsd);
|
|
9373
9447
|
}
|
|
9374
9448
|
return { totalCostLimitUsd: granted2 };
|
|
9375
9449
|
}
|
|
9376
|
-
const currentExpiry = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess',
|
|
9450
|
+
const currentExpiry = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _444 => _444.expiresAt]), () => ( now));
|
|
9377
9451
|
let granted = currentExpiry + (_nullishCoalesce(voucher.renewalDays, () => ( 0))) * DAY_MS2;
|
|
9378
9452
|
if (voucher.maxExpiryDays != null) {
|
|
9379
9453
|
granted = Math.min(granted, now + voucher.maxExpiryDays * DAY_MS2);
|
|
@@ -9404,7 +9478,7 @@ function toVoucherInfo(v) {
|
|
|
9404
9478
|
// src/outbound-api/voucherRedeem.ts
|
|
9405
9479
|
function isRedeemRequest(method, url) {
|
|
9406
9480
|
if (method !== "POST" || !url) return false;
|
|
9407
|
-
const path = _nullishCoalesce(_optionalChain([url, 'access',
|
|
9481
|
+
const path = _nullishCoalesce(_optionalChain([url, 'access', _445 => _445.split, 'call', _446 => _446("?"), 'access', _447 => _447[0], 'optionalAccess', _448 => _448.replace, 'call', _449 => _449(/\/+$/, "")]), () => ( ""));
|
|
9408
9482
|
return path.endsWith("/redeem");
|
|
9409
9483
|
}
|
|
9410
9484
|
function writeErr(res, status, message, headers = {}) {
|
|
@@ -9434,8 +9508,8 @@ function grantToResult(type, granted) {
|
|
|
9434
9508
|
function currentResult(type, keyRow) {
|
|
9435
9509
|
const result = { type };
|
|
9436
9510
|
if (type === "credit") {
|
|
9437
|
-
if (_optionalChain([keyRow, 'optionalAccess',
|
|
9438
|
-
} else if (_optionalChain([keyRow, 'optionalAccess',
|
|
9511
|
+
if (_optionalChain([keyRow, 'optionalAccess', _450 => _450.totalCostLimitUsd]) != null) result.totalCostLimitUsd = keyRow.totalCostLimitUsd;
|
|
9512
|
+
} else if (_optionalChain([keyRow, 'optionalAccess', _451 => _451.expiresAt]) != null) {
|
|
9439
9513
|
result.expiresAt = keyRow.expiresAt;
|
|
9440
9514
|
}
|
|
9441
9515
|
return result;
|
|
@@ -9473,7 +9547,7 @@ async function handleVoucherRedeem(req, res, deps, voucherEnabled, redeemLimiter
|
|
|
9473
9547
|
let code;
|
|
9474
9548
|
try {
|
|
9475
9549
|
code = raw ? JSON.parse(raw)["code"] : void 0;
|
|
9476
|
-
} catch (
|
|
9550
|
+
} catch (e50) {
|
|
9477
9551
|
writeErr(res, 400, "Invalid JSON in request body");
|
|
9478
9552
|
return;
|
|
9479
9553
|
}
|
|
@@ -9522,7 +9596,7 @@ async function handleVoucherRedeem(req, res, deps, voucherEnabled, redeemLimiter
|
|
|
9522
9596
|
const won = await voucherDb.voucherRedeemCas(voucher.id, verifiedKeyId, absolute, now);
|
|
9523
9597
|
if (!won) {
|
|
9524
9598
|
const after = await voucherDb.voucherGetByHash(codeHash);
|
|
9525
|
-
if (_optionalChain([after, 'optionalAccess',
|
|
9599
|
+
if (_optionalChain([after, 'optionalAccess', _452 => _452.status]) === "redeemed" && after.redeemedByKeyId === verifiedKeyId) {
|
|
9526
9600
|
return after.grantApplied === true ? { ok: true, result: currentResult(after.type, await deps.db.outboundApiKeysGetByHash(keyHash)) } : await applyFirstPass(after, recordedAbsolute(after));
|
|
9527
9601
|
}
|
|
9528
9602
|
return { ok: false, status: 409, message: "Code was already redeemed" };
|
|
@@ -9597,10 +9671,10 @@ function extractPresentedKey(req) {
|
|
|
9597
9671
|
}
|
|
9598
9672
|
const xApiKey = req.headers["x-api-key"];
|
|
9599
9673
|
const xApi = Array.isArray(xApiKey) ? xApiKey[0] : xApiKey;
|
|
9600
|
-
if (_optionalChain([xApi, 'optionalAccess',
|
|
9674
|
+
if (_optionalChain([xApi, 'optionalAccess', _453 => _453.trim, 'call', _454 => _454()])) return xApi.trim();
|
|
9601
9675
|
const goog = req.headers["x-goog-api-key"];
|
|
9602
9676
|
const g = Array.isArray(goog) ? goog[0] : goog;
|
|
9603
|
-
return _optionalChain([g, 'optionalAccess',
|
|
9677
|
+
return _optionalChain([g, 'optionalAccess', _455 => _455.trim, 'call', _456 => _456()]) || void 0;
|
|
9604
9678
|
}
|
|
9605
9679
|
function isLoopbackPeer(address) {
|
|
9606
9680
|
if (!address) return false;
|
|
@@ -9610,10 +9684,10 @@ function isLoopbackPeer(address) {
|
|
|
9610
9684
|
function selectEndpoint(method, url) {
|
|
9611
9685
|
if (method !== "POST" || !url) return null;
|
|
9612
9686
|
const openAIOperation = _chunkG4CZIUIBcjs.classifyOpenAIOperation.call(void 0, method, url);
|
|
9613
|
-
if (_optionalChain([openAIOperation, 'optionalAccess',
|
|
9687
|
+
if (_optionalChain([openAIOperation, 'optionalAccess', _457 => _457.policyFamily]) === "chat" || _optionalChain([openAIOperation, 'optionalAccess', _458 => _458.policyFamily]) === "responses") {
|
|
9614
9688
|
return openAIOperation.policyFamily;
|
|
9615
9689
|
}
|
|
9616
|
-
const path = _nullishCoalesce(_optionalChain([url, 'access',
|
|
9690
|
+
const path = _nullishCoalesce(_optionalChain([url, 'access', _459 => _459.split, 'call', _460 => _460("?"), 'access', _461 => _461[0], 'optionalAccess', _462 => _462.replace, 'call', _463 => _463(/\/+$/, "")]), () => ( ""));
|
|
9617
9691
|
const classified = classifyAnthropicMessagesPath(url);
|
|
9618
9692
|
if (classified === "messages" || classified === "count_tokens") return "messages";
|
|
9619
9693
|
const lastSeg = _nullishCoalesce(path.split("/").pop(), () => ( ""));
|
|
@@ -9630,24 +9704,24 @@ function extractGeminiModelFromUrl(url) {
|
|
|
9630
9704
|
}
|
|
9631
9705
|
function isModelsListRequest(url) {
|
|
9632
9706
|
if (!url) return false;
|
|
9633
|
-
const path = _nullishCoalesce(_optionalChain([url, 'access',
|
|
9707
|
+
const path = _nullishCoalesce(_optionalChain([url, 'access', _464 => _464.split, 'call', _465 => _465("?"), 'access', _466 => _466[0], 'optionalAccess', _467 => _467.replace, 'call', _468 => _468(/\/+$/, "")]), () => ( ""));
|
|
9634
9708
|
return path.endsWith("/models");
|
|
9635
9709
|
}
|
|
9636
9710
|
function isAnthropicOauthUsagePath(url) {
|
|
9637
9711
|
if (!url) return false;
|
|
9638
|
-
const path = _nullishCoalesce(_optionalChain([url, 'access',
|
|
9712
|
+
const path = _nullishCoalesce(_optionalChain([url, 'access', _469 => _469.split, 'call', _470 => _470("?"), 'access', _471 => _471[0], 'optionalAccess', _472 => _472.replace, 'call', _473 => _473(/\/+$/, "")]), () => ( ""));
|
|
9639
9713
|
return path === "/api/oauth/usage";
|
|
9640
9714
|
}
|
|
9641
9715
|
function resolveModelsShape(modelsShape, allowedEndpoints) {
|
|
9642
9716
|
if (modelsShape === "anthropic") return "anthropic";
|
|
9643
9717
|
if (modelsShape === "openai") return "openai";
|
|
9644
|
-
if (_optionalChain([allowedEndpoints, 'optionalAccess',
|
|
9718
|
+
if (_optionalChain([allowedEndpoints, 'optionalAccess', _474 => _474.includes, 'call', _475 => _475("images")])) return "openai";
|
|
9645
9719
|
if (!allowedEndpoints || allowedEndpoints.length === 0) return "anthropic";
|
|
9646
9720
|
return allowedEndpoints.includes("messages") ? "anthropic" : "openai";
|
|
9647
9721
|
}
|
|
9648
9722
|
var ANTHROPIC_MODELS_CREATED_AT = (/* @__PURE__ */ new Date()).toISOString();
|
|
9649
9723
|
function parseModelsLimit(url) {
|
|
9650
|
-
const query = _optionalChain([url, 'optionalAccess',
|
|
9724
|
+
const query = _optionalChain([url, 'optionalAccess', _476 => _476.split, 'call', _477 => _477("?"), 'access', _478 => _478[1]]);
|
|
9651
9725
|
if (!query) return void 0;
|
|
9652
9726
|
const raw = new URLSearchParams(query).get("limit");
|
|
9653
9727
|
if (raw === null) return void 0;
|
|
@@ -9666,14 +9740,14 @@ async function writeModelsListAnthropic(res, llmConfig, config, apiKeyId, allowe
|
|
|
9666
9740
|
);
|
|
9667
9741
|
};
|
|
9668
9742
|
const viaLabel = (name, ref) => {
|
|
9669
|
-
const modelId = ref ? _optionalChain([
|
|
9743
|
+
const modelId = ref ? _optionalChain([_chunkYEVWA4C7cjs.parseModelRef.call(void 0, ref), 'optionalAccess', _479 => _479.modelId]) : void 0;
|
|
9670
9744
|
return modelId ? `${name} (via ${modelId})` : void 0;
|
|
9671
9745
|
};
|
|
9672
9746
|
for (const binding of candidateGatewayBindings(config.bindings, apiKeyId, "messages")) {
|
|
9673
9747
|
if (binding.modelMode === "passthrough") {
|
|
9674
9748
|
if (binding.target.kind === "provider") {
|
|
9675
9749
|
const provider = await llmConfig.getProvider(binding.target.providerId);
|
|
9676
|
-
for (const id of _nullishCoalesce(_optionalChain([provider, 'optionalAccess',
|
|
9750
|
+
for (const id of _nullishCoalesce(_optionalChain([provider, 'optionalAccess', _480 => _480.models]), () => ( []))) push(id);
|
|
9677
9751
|
} else if (Object.prototype.hasOwnProperty.call(_subscriptionmodelcatalog.SUBSCRIPTION_MODEL_CATALOG, binding.target.providerId)) {
|
|
9678
9752
|
for (const id of _subscriptionmodelcatalog.SUBSCRIPTION_MODEL_CATALOG[binding.target.providerId]) {
|
|
9679
9753
|
push(id);
|
|
@@ -9681,7 +9755,7 @@ async function writeModelsListAnthropic(res, llmConfig, config, apiKeyId, allowe
|
|
|
9681
9755
|
}
|
|
9682
9756
|
continue;
|
|
9683
9757
|
}
|
|
9684
|
-
if (_optionalChain([binding, 'access',
|
|
9758
|
+
if (_optionalChain([binding, 'access', _481 => _481.modelMappings, 'optionalAccess', _482 => _482.length])) {
|
|
9685
9759
|
for (const mapping of binding.modelMappings) {
|
|
9686
9760
|
const source = mapping.source.trim();
|
|
9687
9761
|
if (source === "" || source.includes("*")) continue;
|
|
@@ -9699,9 +9773,9 @@ async function writeModelsListAnthropic(res, llmConfig, config, apiKeyId, allowe
|
|
|
9699
9773
|
res.end(
|
|
9700
9774
|
JSON.stringify({
|
|
9701
9775
|
data: limited,
|
|
9702
|
-
first_id: _nullishCoalesce(_optionalChain([limited, 'access',
|
|
9776
|
+
first_id: _nullishCoalesce(_optionalChain([limited, 'access', _483 => _483[0], 'optionalAccess', _484 => _484.id]), () => ( null)),
|
|
9703
9777
|
has_more: limited.length < entries2.length,
|
|
9704
|
-
last_id: _nullishCoalesce(_optionalChain([limited, 'access',
|
|
9778
|
+
last_id: _nullishCoalesce(_optionalChain([limited, 'access', _485 => _485[limited.length - 1], 'optionalAccess', _486 => _486.id]), () => ( null))
|
|
9705
9779
|
})
|
|
9706
9780
|
);
|
|
9707
9781
|
}
|
|
@@ -9718,13 +9792,13 @@ function handleOauthUsageProxy(res, config, apiKeyId) {
|
|
|
9718
9792
|
writeJsonError(res, 404, "No Claude subscription route is bound to this key");
|
|
9719
9793
|
return;
|
|
9720
9794
|
}
|
|
9721
|
-
const snapshots =
|
|
9795
|
+
const snapshots = _chunk2T6D7LWEcjs.getSharedAccountAllowanceStore.call(void 0, ).list({ providerId: "claude" });
|
|
9722
9796
|
const preferredAccountId = claudeBinding.target.kind === "account" ? claudeBinding.target.accountId : void 0;
|
|
9723
9797
|
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]));
|
|
9724
9798
|
const body = {};
|
|
9725
9799
|
for (const [wireKey, windowId] of OAUTH_USAGE_WINDOW_IDS) {
|
|
9726
|
-
const window = _optionalChain([snapshot, 'optionalAccess',
|
|
9727
|
-
const usable = _optionalChain([window, 'optionalAccess',
|
|
9800
|
+
const window = _optionalChain([snapshot, 'optionalAccess', _487 => _487.windows, 'access', _488 => _488.find, 'call', _489 => _489((w) => w.id === windowId)]);
|
|
9801
|
+
const usable = _optionalChain([window, 'optionalAccess', _490 => _490.state]) === "fresh";
|
|
9728
9802
|
body[wireKey] = {
|
|
9729
9803
|
utilization: usable ? _nullishCoalesce(window.usedPercent, () => ( null)) : null,
|
|
9730
9804
|
resets_at: usable ? _nullishCoalesce(window.resetsAt, () => ( null)) : null
|
|
@@ -9741,7 +9815,7 @@ async function writeModelsList(res, llmConfig, config, apiKeyId, allowedEndpoint
|
|
|
9741
9815
|
if (binding.modelMode === "passthrough") {
|
|
9742
9816
|
if (binding.target.kind === "provider") {
|
|
9743
9817
|
const provider = await llmConfig.getProvider(binding.target.providerId);
|
|
9744
|
-
modelIds.push(..._nullishCoalesce(_optionalChain([provider, 'optionalAccess',
|
|
9818
|
+
modelIds.push(..._nullishCoalesce(_optionalChain([provider, 'optionalAccess', _491 => _491.models]), () => ( [])));
|
|
9745
9819
|
} else if (Object.prototype.hasOwnProperty.call(
|
|
9746
9820
|
_subscriptionmodelcatalog.SUBSCRIPTION_MODEL_CATALOG,
|
|
9747
9821
|
binding.target.providerId
|
|
@@ -9752,7 +9826,7 @@ async function writeModelsList(res, llmConfig, config, apiKeyId, allowedEndpoint
|
|
|
9752
9826
|
}
|
|
9753
9827
|
continue;
|
|
9754
9828
|
}
|
|
9755
|
-
if (_optionalChain([binding, 'access',
|
|
9829
|
+
if (_optionalChain([binding, 'access', _492 => _492.modelMappings, 'optionalAccess', _493 => _493.length])) {
|
|
9756
9830
|
modelIds.push(
|
|
9757
9831
|
...binding.modelMappings.map((mapping) => mapping.source.trim()).filter((source) => source !== "" && !source.includes("*"))
|
|
9758
9832
|
);
|
|
@@ -9768,7 +9842,7 @@ async function writeModelsList(res, llmConfig, config, apiKeyId, allowedEndpoint
|
|
|
9768
9842
|
if (endpointConfig.backgroundModel) refs.push(endpointConfig.backgroundModel);
|
|
9769
9843
|
}
|
|
9770
9844
|
modelIds.push(
|
|
9771
|
-
...refs.map((ref) => _optionalChain([
|
|
9845
|
+
...refs.map((ref) => _optionalChain([_chunkYEVWA4C7cjs.parseModelRef.call(void 0, ref), 'optionalAccess', _494 => _494.modelId])).filter((modelId) => modelId !== void 0)
|
|
9772
9846
|
);
|
|
9773
9847
|
}
|
|
9774
9848
|
}
|
|
@@ -9815,9 +9889,9 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
9815
9889
|
const anthropicPathClass = classifyAnthropicMessagesPath(req.url);
|
|
9816
9890
|
const isCountTokens = anthropicPathClass === "count_tokens";
|
|
9817
9891
|
const classifiedOperation = _chunkG4CZIUIBcjs.classifyOpenAIOperation.call(void 0, req.method, req.url);
|
|
9818
|
-
const imageOperation = _optionalChain([classifiedOperation, 'optionalAccess',
|
|
9892
|
+
const imageOperation = _optionalChain([classifiedOperation, 'optionalAccess', _495 => _495.policyFamily]) === "images" ? classifiedOperation : null;
|
|
9819
9893
|
if (anthropicPathClass !== null) markAnthropicProtocolResponse(res);
|
|
9820
|
-
const proxyOauthUsageEnabled = _optionalChain([config, 'access',
|
|
9894
|
+
const proxyOauthUsageEnabled = _optionalChain([config, 'access', _496 => _496.anthropic, 'optionalAccess', _497 => _497.proxyOauthUsage]) === true;
|
|
9821
9895
|
const isOauthUsagePath = proxyOauthUsageEnabled && isAnthropicOauthUsagePath(req.url);
|
|
9822
9896
|
if (isOauthUsagePath) markAnthropicProtocolResponse(res);
|
|
9823
9897
|
const audit = _chunkFX325I5Qcjs.beginAuditCapture.call(void 0, req, res, now, {
|
|
@@ -9837,7 +9911,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
9837
9911
|
const verified = verification.key;
|
|
9838
9912
|
if (audit) audit.keyId = verified.id;
|
|
9839
9913
|
if (billing) billing.keyId = verified.id;
|
|
9840
|
-
if (verified.loopbackOnly && !isLoopbackPeer(_optionalChain([req, 'access',
|
|
9914
|
+
if (verified.loopbackOnly && !isLoopbackPeer(_optionalChain([req, 'access', _498 => _498.socket, 'optionalAccess', _499 => _499.remoteAddress]))) {
|
|
9841
9915
|
writeJsonError(res, 403, "This integration key is restricted to loopback clients");
|
|
9842
9916
|
return;
|
|
9843
9917
|
}
|
|
@@ -9850,7 +9924,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
9850
9924
|
req,
|
|
9851
9925
|
res,
|
|
9852
9926
|
deps,
|
|
9853
|
-
_optionalChain([config, 'access',
|
|
9927
|
+
_optionalChain([config, 'access', _500 => _500.voucher, 'optionalAccess', _501 => _501.enabled]) === true,
|
|
9854
9928
|
_nullishCoalesce(redeemLimiter, () => ( getFallbackRedeemLimiter())),
|
|
9855
9929
|
verified.id,
|
|
9856
9930
|
_nullishCoalesce(presented, () => ( "")),
|
|
@@ -9899,7 +9973,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
9899
9973
|
}
|
|
9900
9974
|
if (isCodexSearchRequest(req.method, req.url)) {
|
|
9901
9975
|
await handleCodexSearchRequest(req, res, {
|
|
9902
|
-
mode: _nullishCoalesce(_optionalChain([config, 'access',
|
|
9976
|
+
mode: _nullishCoalesce(_optionalChain([config, 'access', _502 => _502.search, 'optionalAccess', _503 => _503.modes, 'access', _504 => _504.codex]), () => ( _chunkE4QHVXV5cjs.DEFAULT_SEARCH_FRONTEND_MODES.codex)),
|
|
9903
9977
|
runtime: _nullishCoalesce(deps.searchRuntime, () => ( null)),
|
|
9904
9978
|
// This handler EXECUTES rather than relays, and `handleOutboundRequest`
|
|
9905
9979
|
// has no signal of its own to hand down, so it builds one. Without it a
|
|
@@ -9922,7 +9996,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
9922
9996
|
writeJsonError(res, 403, "API key is not allowed to access this endpoint");
|
|
9923
9997
|
return;
|
|
9924
9998
|
}
|
|
9925
|
-
if (resolveModelsShape(_optionalChain([config, 'access',
|
|
9999
|
+
if (resolveModelsShape(_optionalChain([config, 'access', _505 => _505.anthropic, 'optionalAccess', _506 => _506.modelsShape]), verified.allowedEndpoints) === "anthropic") {
|
|
9926
10000
|
await writeModelsListAnthropic(
|
|
9927
10001
|
res,
|
|
9928
10002
|
deps.llmConfig,
|
|
@@ -9936,7 +10010,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
9936
10010
|
if (verified.allowedEndpoints.includes("images") && deps.imageModelCatalog) {
|
|
9937
10011
|
try {
|
|
9938
10012
|
imageModels = await deps.imageModelCatalog.listAvailableModels(verified.id);
|
|
9939
|
-
} catch (
|
|
10013
|
+
} catch (e51) {
|
|
9940
10014
|
}
|
|
9941
10015
|
}
|
|
9942
10016
|
await writeModelsList(
|
|
@@ -10019,12 +10093,12 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
10019
10093
|
res.once("close", release2);
|
|
10020
10094
|
}
|
|
10021
10095
|
try {
|
|
10022
|
-
const ingressFormat =
|
|
10096
|
+
const ingressFormat = _chunkYEVWA4C7cjs.endpointToIngressFormat.call(void 0, endpoint);
|
|
10023
10097
|
const rawBody = await readBody3(req);
|
|
10024
10098
|
let parsedBody = {};
|
|
10025
10099
|
try {
|
|
10026
10100
|
parsedBody = rawBody ? JSON.parse(rawBody) : {};
|
|
10027
|
-
} catch (
|
|
10101
|
+
} catch (e52) {
|
|
10028
10102
|
writeJsonError(res, 400, "Invalid JSON in request body");
|
|
10029
10103
|
return;
|
|
10030
10104
|
}
|
|
@@ -10039,8 +10113,8 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
10039
10113
|
const urlModel = extractGeminiModelFromUrl(req.url);
|
|
10040
10114
|
if (urlModel) parsedBody["model"] = urlModel;
|
|
10041
10115
|
}
|
|
10042
|
-
const requestedModel =
|
|
10043
|
-
const role =
|
|
10116
|
+
const requestedModel = _chunkYEVWA4C7cjs.extractRequestedModel.call(void 0, ingressFormat, parsedBody);
|
|
10117
|
+
const role = _chunkYEVWA4C7cjs.isKindMappedEndpoint.call(void 0, endpoint) || endpoint === "chat" ? void 0 : _chunkYEVWA4C7cjs.detectRequestRole.call(void 0, ingressFormat, parsedBody, {
|
|
10044
10118
|
// Role detection precedes the route pick (the pick consumes the
|
|
10045
10119
|
// role), so the hint is the union across the candidate routes.
|
|
10046
10120
|
backgroundModelIds: candidateBackgroundModelIds(config.bindings, verified.id, endpoint)
|
|
@@ -10060,7 +10134,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
10060
10134
|
const bindingAffinitySuffix = `:${bindingResolution.binding.id}`;
|
|
10061
10135
|
const sessionId = deps.proxyDeps.apiKeyPool ? `outbound:${verified.id}${bindingAffinitySuffix}` : null;
|
|
10062
10136
|
const hostedImageGenerationAllowed = verified.allowedEndpoints.includes("images");
|
|
10063
|
-
const resolved =
|
|
10137
|
+
const resolved = _chunkYEVWA4C7cjs.isKindMappedEndpoint.call(void 0, endpoint) || endpoint === "chat" ? await _chunkYEVWA4C7cjs.resolveRoute.call(void 0, {
|
|
10064
10138
|
config: effectiveEndpointConfig,
|
|
10065
10139
|
ingressFormat,
|
|
10066
10140
|
llmConfig: deps.llmConfig,
|
|
@@ -10072,7 +10146,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
10072
10146
|
// Attribution: stamp the verified named-key id onto the route.
|
|
10073
10147
|
apiKeyId: verified.id,
|
|
10074
10148
|
hostedImageGenerationAllowed
|
|
10075
|
-
}) : await
|
|
10149
|
+
}) : await _chunkYEVWA4C7cjs.resolveRoute.call(void 0, {
|
|
10076
10150
|
config: effectiveEndpointConfig,
|
|
10077
10151
|
role,
|
|
10078
10152
|
ingressFormat,
|
|
@@ -10104,7 +10178,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
10104
10178
|
}
|
|
10105
10179
|
let releaseSerial = null;
|
|
10106
10180
|
const providerKey = resolved.route.providerId;
|
|
10107
|
-
if (_optionalChain([config, 'access',
|
|
10181
|
+
if (_optionalChain([config, 'access', _507 => _507.userMessageQueue, 'optionalAccess', _508 => _508.enabled]) && providerKey && !isCountTokens && isUserMessageRequest(endpoint, parsedBody)) {
|
|
10108
10182
|
const umq = config.userMessageQueue;
|
|
10109
10183
|
try {
|
|
10110
10184
|
const serialSlot = await serialQueue.acquire(providerKey, {
|
|
@@ -10134,12 +10208,12 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
10134
10208
|
const token = routeMap.addRoute(
|
|
10135
10209
|
isCountTokens ? {
|
|
10136
10210
|
...requestRoute,
|
|
10137
|
-
anthropicCountTokensMode: _optionalChain([config, 'access',
|
|
10138
|
-
anthropicCountTokensEstimateBudgetMs: _optionalChain([config, 'access',
|
|
10139
|
-
anthropicPdfTextExtractionBudgetMs: _optionalChain([config, 'access',
|
|
10211
|
+
anthropicCountTokensMode: _optionalChain([config, 'access', _509 => _509.anthropic, 'optionalAccess', _510 => _510.countTokens, 'optionalAccess', _511 => _511.mode]),
|
|
10212
|
+
anthropicCountTokensEstimateBudgetMs: _optionalChain([config, 'access', _512 => _512.anthropic, 'optionalAccess', _513 => _513.countTokens, 'optionalAccess', _514 => _514.estimateBudgetMs]),
|
|
10213
|
+
anthropicPdfTextExtractionBudgetMs: _optionalChain([config, 'access', _515 => _515.anthropic, 'optionalAccess', _516 => _516.pdfTextExtraction, 'optionalAccess', _517 => _517.budgetMs])
|
|
10140
10214
|
} : anthropicPathClass !== null ? {
|
|
10141
10215
|
...requestRoute,
|
|
10142
|
-
anthropicPdfTextExtractionBudgetMs: _optionalChain([config, 'access',
|
|
10216
|
+
anthropicPdfTextExtractionBudgetMs: _optionalChain([config, 'access', _518 => _518.anthropic, 'optionalAccess', _519 => _519.pdfTextExtraction, 'optionalAccess', _520 => _520.budgetMs])
|
|
10143
10217
|
} : requestRoute
|
|
10144
10218
|
);
|
|
10145
10219
|
try {
|
|
@@ -10169,7 +10243,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
10169
10243
|
else console.error("[OutboundApi] dispatch error:", message);
|
|
10170
10244
|
_chunkUIBD2YY5cjs.emitWebhookEvent.call(void 0, { kind: "server.error", at: Date.now(), message });
|
|
10171
10245
|
if (audit) audit.error = message;
|
|
10172
|
-
writeJsonError(res,
|
|
10246
|
+
writeJsonError(res, _chunkBKXC4XM6cjs.isAccountAllowanceExhaustedError.call(void 0, err) ? 429 : 502, message);
|
|
10173
10247
|
} finally {
|
|
10174
10248
|
routeMap.removeRoute(token);
|
|
10175
10249
|
if (releaseSerial) releaseSerial();
|
|
@@ -10323,7 +10397,7 @@ var OutboundApiServer = (_class19 = class {
|
|
|
10323
10397
|
this.server = listener.server;
|
|
10324
10398
|
this.boundAddr = bindAddr;
|
|
10325
10399
|
this.boundPort = actualPort;
|
|
10326
|
-
if (actualPort !== port) _optionalChain([this, 'access',
|
|
10400
|
+
if (actualPort !== port) _optionalChain([this, 'access', _521 => _521.onPortChange, 'optionalCall', _522 => _522(actualPort)]);
|
|
10327
10401
|
this.logInfo(`[OutboundApiServer] Listening on ${bindAddr}:${actualPort}`);
|
|
10328
10402
|
return actualPort;
|
|
10329
10403
|
}
|
|
@@ -10366,8 +10440,8 @@ var OutboundApiServer = (_class19 = class {
|
|
|
10366
10440
|
this.anthropicConfig = input.anthropic;
|
|
10367
10441
|
this.searchConfig = input.search;
|
|
10368
10442
|
this.imagesEnabled = input.imagesEnabled === true;
|
|
10369
|
-
this.apiHelloEnabled = _optionalChain([input, 'access',
|
|
10370
|
-
_chunk6DDYNS2Bcjs.setAnthropicPingHeartbeatMs.call(void 0, _optionalChain([input, 'access',
|
|
10443
|
+
this.apiHelloEnabled = _optionalChain([input, 'access', _523 => _523.anthropic, 'optionalAccess', _524 => _524.apiHello]) !== false;
|
|
10444
|
+
_chunk6DDYNS2Bcjs.setAnthropicPingHeartbeatMs.call(void 0, _optionalChain([input, 'access', _525 => _525.anthropic, 'optionalAccess', _526 => _526.heartbeatIntervalMs]));
|
|
10371
10445
|
}
|
|
10372
10446
|
captureRuntimeSnapshot() {
|
|
10373
10447
|
return {
|
|
@@ -10393,8 +10467,8 @@ var OutboundApiServer = (_class19 = class {
|
|
|
10393
10467
|
this.anthropicConfig = snapshot.anthropic;
|
|
10394
10468
|
this.searchConfig = snapshot.search;
|
|
10395
10469
|
this.imagesEnabled = snapshot.imagesEnabled;
|
|
10396
|
-
this.apiHelloEnabled = _optionalChain([snapshot, 'access',
|
|
10397
|
-
_chunk6DDYNS2Bcjs.setAnthropicPingHeartbeatMs.call(void 0, _optionalChain([snapshot, 'access',
|
|
10470
|
+
this.apiHelloEnabled = _optionalChain([snapshot, 'access', _527 => _527.anthropic, 'optionalAccess', _528 => _528.apiHello]) !== false;
|
|
10471
|
+
_chunk6DDYNS2Bcjs.setAnthropicPingHeartbeatMs.call(void 0, _optionalChain([snapshot, 'access', _529 => _529.anthropic, 'optionalAccess', _530 => _530.heartbeatIntervalMs]));
|
|
10398
10472
|
}
|
|
10399
10473
|
async restoreRuntimeSnapshot(snapshot) {
|
|
10400
10474
|
const current = this.server;
|
|
@@ -10428,22 +10502,22 @@ var OutboundApiServer = (_class19 = class {
|
|
|
10428
10502
|
server.close(() => {
|
|
10429
10503
|
try {
|
|
10430
10504
|
this.logInfo("[OutboundApiServer] Stopped");
|
|
10431
|
-
} catch (
|
|
10505
|
+
} catch (e53) {
|
|
10432
10506
|
}
|
|
10433
10507
|
});
|
|
10434
|
-
} catch (
|
|
10508
|
+
} catch (e54) {
|
|
10435
10509
|
}
|
|
10436
10510
|
}
|
|
10437
10511
|
announcePublishedListener(bindAddr, requestedPort, actualPort) {
|
|
10438
10512
|
if (actualPort !== requestedPort) {
|
|
10439
10513
|
try {
|
|
10440
|
-
_optionalChain([this, 'access',
|
|
10441
|
-
} catch (
|
|
10514
|
+
_optionalChain([this, 'access', _531 => _531.onPortChange, 'optionalCall', _532 => _532(actualPort)]);
|
|
10515
|
+
} catch (e55) {
|
|
10442
10516
|
}
|
|
10443
10517
|
}
|
|
10444
10518
|
try {
|
|
10445
10519
|
this.logInfo(`[OutboundApiServer] Listening on ${bindAddr}:${actualPort}`);
|
|
10446
|
-
} catch (
|
|
10520
|
+
} catch (e56) {
|
|
10447
10521
|
}
|
|
10448
10522
|
}
|
|
10449
10523
|
/** Per-request handler. Auth is enforced on EVERY request (incl. loopback). */
|
|
@@ -10490,7 +10564,7 @@ var OutboundApiServer = (_class19 = class {
|
|
|
10490
10564
|
tryServeApiHello(req, res) {
|
|
10491
10565
|
if (!this.apiHelloEnabled) return false;
|
|
10492
10566
|
if (req.method !== "HEAD") return false;
|
|
10493
|
-
const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access',
|
|
10567
|
+
const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access', _533 => _533.split, 'call', _534 => _534("?"), 'access', _535 => _535[0], 'optionalAccess', _536 => _536.replace, 'call', _537 => _537(/\/+$/, "")]) || "/";
|
|
10494
10568
|
if (path !== "/api/hello") return false;
|
|
10495
10569
|
res.writeHead(200);
|
|
10496
10570
|
res.end();
|
|
@@ -10504,7 +10578,7 @@ var OutboundApiServer = (_class19 = class {
|
|
|
10504
10578
|
const provider = this.deps.healthReportProvider;
|
|
10505
10579
|
if (!provider) return false;
|
|
10506
10580
|
if (req.method !== "GET" && req.method !== "HEAD") return false;
|
|
10507
|
-
const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access',
|
|
10581
|
+
const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access', _538 => _538.split, 'call', _539 => _539("?"), 'access', _540 => _540[0], 'optionalAccess', _541 => _541.replace, 'call', _542 => _542(/\/+$/, "")]) || "/";
|
|
10508
10582
|
if (path !== "/health" && path !== "/healthz") return false;
|
|
10509
10583
|
const report = provider();
|
|
10510
10584
|
res.writeHead(_healthloggingtypes.healthHttpStatus.call(void 0, report.status), { "Content-Type": "application/json" });
|
|
@@ -10729,7 +10803,7 @@ function resolveCompletionReasoningPlan(provider, options, target, requestMaxTok
|
|
|
10729
10803
|
}
|
|
10730
10804
|
function resolveOpenAIEffort(provider, options, target) {
|
|
10731
10805
|
const plan = resolveCompletionReasoningPlan(provider, options, target);
|
|
10732
|
-
return _optionalChain([plan, 'optionalAccess',
|
|
10806
|
+
return _optionalChain([plan, 'optionalAccess', _543 => _543.kind]) === "level" && plan.enabled ? plan.effort : void 0;
|
|
10733
10807
|
}
|
|
10734
10808
|
function buildAnthropicReasoningWire(provider, options) {
|
|
10735
10809
|
const configuredMaxTokens = _nullishCoalesce(options.maxTokens, () => ( LEGACY_ANTHROPIC_MAX_TOKENS));
|
|
@@ -10740,7 +10814,7 @@ function buildAnthropicReasoningWire(provider, options) {
|
|
|
10740
10814
|
"anthropic",
|
|
10741
10815
|
legacyBound
|
|
10742
10816
|
);
|
|
10743
|
-
if (_optionalChain([plan, 'optionalAccess',
|
|
10817
|
+
if (_optionalChain([plan, 'optionalAccess', _544 => _544.kind]) === "level" && plan.enabled) {
|
|
10744
10818
|
return {
|
|
10745
10819
|
effectiveMaxTokens: configuredMaxTokens,
|
|
10746
10820
|
thinking: { type: "adaptive" },
|
|
@@ -10748,7 +10822,7 @@ function buildAnthropicReasoningWire(provider, options) {
|
|
|
10748
10822
|
legacyBudgetEnabled: false
|
|
10749
10823
|
};
|
|
10750
10824
|
}
|
|
10751
|
-
if (_optionalChain([plan, 'optionalAccess',
|
|
10825
|
+
if (_optionalChain([plan, 'optionalAccess', _545 => _545.kind]) === "budget" && plan.enabled) {
|
|
10752
10826
|
return {
|
|
10753
10827
|
effectiveMaxTokens: legacyBound,
|
|
10754
10828
|
thinking: { type: "enabled", budget_tokens: plan.budgetTokens },
|
|
@@ -10762,13 +10836,13 @@ function buildAnthropicReasoningWire(provider, options) {
|
|
|
10762
10836
|
}
|
|
10763
10837
|
function buildGeminiThinkingConfig(provider, options) {
|
|
10764
10838
|
const plan = resolveCompletionReasoningPlan(provider, options, "gemini");
|
|
10765
|
-
if (_optionalChain([plan, 'optionalAccess',
|
|
10839
|
+
if (_optionalChain([plan, 'optionalAccess', _546 => _546.kind]) === "level") {
|
|
10766
10840
|
return {
|
|
10767
10841
|
includeThoughts: plan.enabled,
|
|
10768
10842
|
thinkingLevel: plan.effort
|
|
10769
10843
|
};
|
|
10770
10844
|
}
|
|
10771
|
-
if (_optionalChain([plan, 'optionalAccess',
|
|
10845
|
+
if (_optionalChain([plan, 'optionalAccess', _547 => _547.kind]) === "budget") {
|
|
10772
10846
|
return {
|
|
10773
10847
|
includeThoughts: plan.enabled,
|
|
10774
10848
|
thinkingBudget: plan.budgetTokens
|
|
@@ -10793,7 +10867,7 @@ async function callOpenAICompletion(provider, apiKey, options, logger) {
|
|
|
10793
10867
|
request.reasoning_effort = effort;
|
|
10794
10868
|
}
|
|
10795
10869
|
const apiUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: false });
|
|
10796
|
-
const headers =
|
|
10870
|
+
const headers = _chunkTX4UCSOPcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
10797
10871
|
logger.info("Calling OpenAI completion API", { url: apiUrl, model: options.model });
|
|
10798
10872
|
const response = await fetch(apiUrl, {
|
|
10799
10873
|
method: "POST",
|
|
@@ -10842,7 +10916,7 @@ async function callAnthropicCompletion(provider, apiKey, options, logger) {
|
|
|
10842
10916
|
...reasoningWire.outputConfig ? { output_config: reasoningWire.outputConfig } : {}
|
|
10843
10917
|
};
|
|
10844
10918
|
const apiUrl2 = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: false });
|
|
10845
|
-
const headers2 =
|
|
10919
|
+
const headers2 = _chunkTX4UCSOPcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
10846
10920
|
logger.info("Calling Anthropic completion API with images", { url: apiUrl2, model: options.model });
|
|
10847
10921
|
const response2 = await fetch(apiUrl2, {
|
|
10848
10922
|
method: "POST",
|
|
@@ -10864,7 +10938,7 @@ async function callAnthropicCompletion(provider, apiKey, options, logger) {
|
|
|
10864
10938
|
message: {
|
|
10865
10939
|
id: `assistant-${Date.now()}`,
|
|
10866
10940
|
role: "assistant",
|
|
10867
|
-
content: _optionalChain([choice2, 'access',
|
|
10941
|
+
content: _optionalChain([choice2, 'access', _548 => _548.message, 'optionalAccess', _549 => _549.content]) || "",
|
|
10868
10942
|
timestamp: Date.now()
|
|
10869
10943
|
},
|
|
10870
10944
|
usage: openaiResponse2.usage ? {
|
|
@@ -10900,7 +10974,7 @@ async function callAnthropicCompletion(provider, apiKey, options, logger) {
|
|
|
10900
10974
|
delete anthropicRequestBody.temperature;
|
|
10901
10975
|
}
|
|
10902
10976
|
const apiUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: false });
|
|
10903
|
-
const headers =
|
|
10977
|
+
const headers = _chunkTX4UCSOPcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
10904
10978
|
logger.info("Calling Anthropic completion API", { url: apiUrl, model: options.model });
|
|
10905
10979
|
const response = await fetch(apiUrl, {
|
|
10906
10980
|
method: "POST",
|
|
@@ -10956,7 +11030,7 @@ async function callGeminiCompletion(provider, apiKey, options, logger) {
|
|
|
10956
11030
|
request.systemInstruction = systemInstruction;
|
|
10957
11031
|
}
|
|
10958
11032
|
const apiUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: false });
|
|
10959
|
-
const headers =
|
|
11033
|
+
const headers = _chunkTX4UCSOPcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
10960
11034
|
logger.info("Calling Gemini completion API", { url: apiUrl, model: options.model });
|
|
10961
11035
|
const response = await fetch(apiUrl, {
|
|
10962
11036
|
method: "POST",
|
|
@@ -10981,7 +11055,7 @@ async function callGeminiCompletion(provider, apiKey, options, logger) {
|
|
|
10981
11055
|
const candidate = candidates[0];
|
|
10982
11056
|
const content = candidate.content;
|
|
10983
11057
|
let textContent = "";
|
|
10984
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
11058
|
+
if (_optionalChain([content, 'optionalAccess', _550 => _550.parts])) {
|
|
10985
11059
|
for (const part of content.parts) {
|
|
10986
11060
|
if (part.text) {
|
|
10987
11061
|
textContent += part.text;
|
|
@@ -11025,7 +11099,7 @@ async function callOpenAIResponseCompletion(provider, apiKey, options, logger) {
|
|
|
11025
11099
|
request.reasoning = { effort: responseEffort, summary: "auto" };
|
|
11026
11100
|
}
|
|
11027
11101
|
const apiUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: false });
|
|
11028
|
-
const headers =
|
|
11102
|
+
const headers = _chunkTX4UCSOPcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
11029
11103
|
logger.info("Calling OpenAI Response API", { url: apiUrl, model: options.model });
|
|
11030
11104
|
const response = await fetch(apiUrl, {
|
|
11031
11105
|
method: "POST",
|
|
@@ -11088,7 +11162,7 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
|
|
|
11088
11162
|
request.reasoning_effort = effort;
|
|
11089
11163
|
}
|
|
11090
11164
|
const apiUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: true });
|
|
11091
|
-
const headers =
|
|
11165
|
+
const headers = _chunkTX4UCSOPcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
11092
11166
|
if (options.nativeSearchAugmentation) {
|
|
11093
11167
|
_chunkJMJBSACDcjs.applyAugmentation.call(void 0, request, options.nativeSearchAugmentation);
|
|
11094
11168
|
}
|
|
@@ -11109,7 +11183,7 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
|
|
|
11109
11183
|
});
|
|
11110
11184
|
if (!response.ok) {
|
|
11111
11185
|
const errorText = await response.text();
|
|
11112
|
-
_optionalChain([callbacks, 'access',
|
|
11186
|
+
_optionalChain([callbacks, 'access', _551 => _551.onError, 'optionalCall', _552 => _552(`API error (${response.status}): ${errorText}`)]);
|
|
11113
11187
|
return;
|
|
11114
11188
|
}
|
|
11115
11189
|
const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "openai", {
|
|
@@ -11119,7 +11193,7 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
|
|
|
11119
11193
|
onVideo: callbacks.onVideo,
|
|
11120
11194
|
onError: callbacks.onError
|
|
11121
11195
|
});
|
|
11122
|
-
_optionalChain([callbacks, 'access',
|
|
11196
|
+
_optionalChain([callbacks, 'access', _553 => _553.onDone, 'optionalCall', _554 => _554(
|
|
11123
11197
|
{
|
|
11124
11198
|
id: messageId,
|
|
11125
11199
|
role: "assistant",
|
|
@@ -11187,14 +11261,14 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
|
|
|
11187
11261
|
}
|
|
11188
11262
|
}
|
|
11189
11263
|
const apiUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: true });
|
|
11190
|
-
const headers =
|
|
11264
|
+
const headers = _chunkTX4UCSOPcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
11191
11265
|
if (options.nativeSearchAugmentation) {
|
|
11192
11266
|
_chunkJMJBSACDcjs.applyAugmentation.call(void 0, anthropicRequest, options.nativeSearchAugmentation);
|
|
11193
11267
|
}
|
|
11194
11268
|
logger.info("Streaming Anthropic completion request", {
|
|
11195
11269
|
url: apiUrl,
|
|
11196
11270
|
model: anthropicRequest.model,
|
|
11197
|
-
messagesCount: _optionalChain([anthropicRequest, 'access',
|
|
11271
|
+
messagesCount: _optionalChain([anthropicRequest, 'access', _555 => _555.messages, 'optionalAccess', _556 => _556.length]),
|
|
11198
11272
|
max_tokens: anthropicRequest.max_tokens,
|
|
11199
11273
|
temperature: anthropicRequest.temperature,
|
|
11200
11274
|
stream: anthropicRequest.stream,
|
|
@@ -11211,7 +11285,7 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
|
|
|
11211
11285
|
if (!response.ok) {
|
|
11212
11286
|
const errorText = await response.text();
|
|
11213
11287
|
logger.error("Anthropic API error", void 0, { status: response.status, errorText });
|
|
11214
|
-
_optionalChain([callbacks, 'access',
|
|
11288
|
+
_optionalChain([callbacks, 'access', _557 => _557.onError, 'optionalCall', _558 => _558(`API error (${response.status}): ${errorText}`)]);
|
|
11215
11289
|
return;
|
|
11216
11290
|
}
|
|
11217
11291
|
const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "anthropic", {
|
|
@@ -11222,10 +11296,10 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
|
|
|
11222
11296
|
});
|
|
11223
11297
|
logger.info("Anthropic stream complete", {
|
|
11224
11298
|
contentLength: result.content.length,
|
|
11225
|
-
reasoningLength: _optionalChain([result, 'access',
|
|
11299
|
+
reasoningLength: _optionalChain([result, 'access', _559 => _559.reasoning, 'optionalAccess', _560 => _560.length]) || 0,
|
|
11226
11300
|
blocksCount: result.blocks.length
|
|
11227
11301
|
});
|
|
11228
|
-
_optionalChain([callbacks, 'access',
|
|
11302
|
+
_optionalChain([callbacks, 'access', _561 => _561.onDone, 'optionalCall', _562 => _562(
|
|
11229
11303
|
{
|
|
11230
11304
|
id: messageId,
|
|
11231
11305
|
role: "assistant",
|
|
@@ -11261,7 +11335,7 @@ async function streamGeminiCompletion(provider, apiKey, options, messageId, call
|
|
|
11261
11335
|
request.systemInstruction = systemInstruction;
|
|
11262
11336
|
}
|
|
11263
11337
|
const apiUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: true });
|
|
11264
|
-
const headers =
|
|
11338
|
+
const headers = _chunkTX4UCSOPcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
11265
11339
|
if (options.nativeSearchAugmentation) {
|
|
11266
11340
|
_chunkJMJBSACDcjs.applyAugmentation.call(void 0, request, options.nativeSearchAugmentation);
|
|
11267
11341
|
}
|
|
@@ -11283,7 +11357,7 @@ async function streamGeminiCompletion(provider, apiKey, options, messageId, call
|
|
|
11283
11357
|
if (!response.ok) {
|
|
11284
11358
|
const errorText = await response.text();
|
|
11285
11359
|
logger.error("Gemini API error", void 0, { status: response.status, errorText });
|
|
11286
|
-
_optionalChain([callbacks, 'access',
|
|
11360
|
+
_optionalChain([callbacks, 'access', _563 => _563.onError, 'optionalCall', _564 => _564(`API error (${response.status}): ${errorText}`)]);
|
|
11287
11361
|
return;
|
|
11288
11362
|
}
|
|
11289
11363
|
const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "gemini", {
|
|
@@ -11292,7 +11366,7 @@ async function streamGeminiCompletion(provider, apiKey, options, messageId, call
|
|
|
11292
11366
|
onError: callbacks.onError
|
|
11293
11367
|
});
|
|
11294
11368
|
logger.info("Gemini stream complete", { contentLength: result.content.length });
|
|
11295
|
-
_optionalChain([callbacks, 'access',
|
|
11369
|
+
_optionalChain([callbacks, 'access', _565 => _565.onDone, 'optionalCall', _566 => _566(
|
|
11296
11370
|
{
|
|
11297
11371
|
id: messageId,
|
|
11298
11372
|
role: "assistant",
|
|
@@ -11325,7 +11399,7 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
|
|
|
11325
11399
|
request.reasoning = { effort: responseEffort, summary: "auto" };
|
|
11326
11400
|
}
|
|
11327
11401
|
const apiUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: true });
|
|
11328
|
-
const headers =
|
|
11402
|
+
const headers = _chunkTX4UCSOPcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
11329
11403
|
logger.info("Streaming OpenAI Response API request", {
|
|
11330
11404
|
url: apiUrl,
|
|
11331
11405
|
providerId: options.providerId,
|
|
@@ -11342,7 +11416,7 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
|
|
|
11342
11416
|
});
|
|
11343
11417
|
if (!response.ok) {
|
|
11344
11418
|
const errorText = await response.text();
|
|
11345
|
-
_optionalChain([callbacks, 'access',
|
|
11419
|
+
_optionalChain([callbacks, 'access', _567 => _567.onError, 'optionalCall', _568 => _568(`API error (${response.status}): ${errorText}`)]);
|
|
11346
11420
|
return;
|
|
11347
11421
|
}
|
|
11348
11422
|
const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "openai-response", {
|
|
@@ -11351,7 +11425,7 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
|
|
|
11351
11425
|
onError: callbacks.onError
|
|
11352
11426
|
});
|
|
11353
11427
|
logger.info("OpenAI Response API stream complete", { contentLength: result.content.length });
|
|
11354
|
-
_optionalChain([callbacks, 'access',
|
|
11428
|
+
_optionalChain([callbacks, 'access', _569 => _569.onDone, 'optionalCall', _570 => _570(
|
|
11355
11429
|
{
|
|
11356
11430
|
id: messageId,
|
|
11357
11431
|
role: "assistant",
|
|
@@ -11379,7 +11453,7 @@ async function resolveEffectiveMaxTokens(llmConfig, _getProvider, logger, _provi
|
|
|
11379
11453
|
}
|
|
11380
11454
|
try {
|
|
11381
11455
|
const globalParams = await llmConfig.getGlobalModelParameters();
|
|
11382
|
-
if (_optionalChain([globalParams, 'optionalAccess',
|
|
11456
|
+
if (_optionalChain([globalParams, 'optionalAccess', _571 => _571.maxTokens, 'optionalAccess', _572 => _572.enabled]) && globalParams.maxTokens.value > 0) {
|
|
11383
11457
|
logger.debug("Using global maxTokens", { maxTokens: globalParams.maxTokens.value });
|
|
11384
11458
|
return globalParams.maxTokens.value;
|
|
11385
11459
|
}
|
|
@@ -11407,7 +11481,7 @@ async function resolveThinkingBudget(getProvider, logger, providerId, modelId, m
|
|
|
11407
11481
|
}
|
|
11408
11482
|
const thinkingBudget = _thinkingconfig.calculateThinkingBudget.call(void 0, modelId, thinkLevel, maxTokens);
|
|
11409
11483
|
const provider = await getProvider(providerId);
|
|
11410
|
-
const providerName = _optionalChain([provider, 'optionalAccess',
|
|
11484
|
+
const providerName = _optionalChain([provider, 'optionalAccess', _573 => _573.name, 'optionalAccess', _574 => _574.toLowerCase, 'call', _575 => _575()]) || "";
|
|
11411
11485
|
const apiFormat = provider ? _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider) : "openai";
|
|
11412
11486
|
if (apiFormat === "anthropic" || providerName === "anthropic" || providerName.includes("claude")) {
|
|
11413
11487
|
const thinkingConfig = _thinkingconfig.buildAnthropicThinking.call(void 0, modelId, thinkLevel, maxTokens);
|
|
@@ -11444,7 +11518,7 @@ function logToolFormat(tools, logger) {
|
|
|
11444
11518
|
tools: openaiTools.map((t) => t.function.name),
|
|
11445
11519
|
firstTool: {
|
|
11446
11520
|
name: firstTool.function.name,
|
|
11447
|
-
description: _optionalChain([firstTool, 'access',
|
|
11521
|
+
description: _optionalChain([firstTool, 'access', _576 => _576.function, 'access', _577 => _577.description, 'optionalAccess', _578 => _578.slice, 'call', _579 => _579(0, 100)]),
|
|
11448
11522
|
parameters: firstTool.function.parameters
|
|
11449
11523
|
}
|
|
11450
11524
|
});
|
|
@@ -11455,7 +11529,7 @@ function logToolFormat(tools, logger) {
|
|
|
11455
11529
|
tools: anthropicTools.map((t) => t.name),
|
|
11456
11530
|
firstTool: {
|
|
11457
11531
|
name: firstTool.name,
|
|
11458
|
-
description: _optionalChain([firstTool, 'access',
|
|
11532
|
+
description: _optionalChain([firstTool, 'access', _580 => _580.description, 'optionalAccess', _581 => _581.slice, 'call', _582 => _582(0, 100)]),
|
|
11459
11533
|
input_schema: firstTool.input_schema
|
|
11460
11534
|
}
|
|
11461
11535
|
});
|
|
@@ -11466,9 +11540,9 @@ function logToolFormat(tools, logger) {
|
|
|
11466
11540
|
count: allDeclarations.length,
|
|
11467
11541
|
tools: allDeclarations.map((t) => t.name),
|
|
11468
11542
|
firstTool: {
|
|
11469
|
-
name: _optionalChain([allDeclarations, 'access',
|
|
11470
|
-
description: _optionalChain([allDeclarations, 'access',
|
|
11471
|
-
parameters: _optionalChain([allDeclarations, 'access',
|
|
11543
|
+
name: _optionalChain([allDeclarations, 'access', _583 => _583[0], 'optionalAccess', _584 => _584.name]),
|
|
11544
|
+
description: _optionalChain([allDeclarations, 'access', _585 => _585[0], 'optionalAccess', _586 => _586.description, 'optionalAccess', _587 => _587.slice, 'call', _588 => _588(0, 100)]),
|
|
11545
|
+
parameters: _optionalChain([allDeclarations, 'access', _589 => _589[0], 'optionalAccess', _590 => _590.parameters])
|
|
11472
11546
|
}
|
|
11473
11547
|
});
|
|
11474
11548
|
}
|
|
@@ -11531,7 +11605,7 @@ function buildToolRequest(apiFormat, conversationMessages, actualModel, options,
|
|
|
11531
11605
|
function extractDeltaContent(rawJson, apiFormat) {
|
|
11532
11606
|
const json = rawJson;
|
|
11533
11607
|
if (apiFormat === "google") {
|
|
11534
|
-
const parts = _optionalChain([json, 'access',
|
|
11608
|
+
const parts = _optionalChain([json, 'access', _591 => _591.candidates, 'optionalAccess', _592 => _592[0], 'optionalAccess', _593 => _593.content, 'optionalAccess', _594 => _594.parts]) || [];
|
|
11535
11609
|
let text = "";
|
|
11536
11610
|
for (const part of parts) {
|
|
11537
11611
|
if (part.thought === true) continue;
|
|
@@ -11539,15 +11613,15 @@ function extractDeltaContent(rawJson, apiFormat) {
|
|
|
11539
11613
|
}
|
|
11540
11614
|
return text;
|
|
11541
11615
|
} else if (apiFormat === "anthropic") {
|
|
11542
|
-
return _optionalChain([json, 'access',
|
|
11616
|
+
return _optionalChain([json, 'access', _595 => _595.delta, 'optionalAccess', _596 => _596.text]) || "";
|
|
11543
11617
|
} else {
|
|
11544
|
-
return _optionalChain([json, 'access',
|
|
11618
|
+
return _optionalChain([json, 'access', _597 => _597.choices, 'optionalAccess', _598 => _598[0], 'optionalAccess', _599 => _599.delta, 'optionalAccess', _600 => _600.content]) || "";
|
|
11545
11619
|
}
|
|
11546
11620
|
}
|
|
11547
11621
|
function extractDeltaReasoning(rawJson, apiFormat) {
|
|
11548
11622
|
const json = rawJson;
|
|
11549
11623
|
if (apiFormat === "google") {
|
|
11550
|
-
const parts = _optionalChain([json, 'access',
|
|
11624
|
+
const parts = _optionalChain([json, 'access', _601 => _601.candidates, 'optionalAccess', _602 => _602[0], 'optionalAccess', _603 => _603.content, 'optionalAccess', _604 => _604.parts]) || [];
|
|
11551
11625
|
let reasoning = "";
|
|
11552
11626
|
for (const part of parts) {
|
|
11553
11627
|
if (part.thought === true && part.text) reasoning += part.text;
|
|
@@ -11556,14 +11630,14 @@ function extractDeltaReasoning(rawJson, apiFormat) {
|
|
|
11556
11630
|
} else if (apiFormat === "anthropic") {
|
|
11557
11631
|
return "";
|
|
11558
11632
|
} else {
|
|
11559
|
-
const delta = _optionalChain([json, 'access',
|
|
11560
|
-
return (_optionalChain([delta, 'optionalAccess',
|
|
11633
|
+
const delta = _optionalChain([json, 'access', _605 => _605.choices, 'optionalAccess', _606 => _606[0], 'optionalAccess', _607 => _607.delta]);
|
|
11634
|
+
return (_optionalChain([delta, 'optionalAccess', _608 => _608.thinking, 'optionalAccess', _609 => _609.content]) || "") + (_optionalChain([delta, 'optionalAccess', _610 => _610.reasoning_content]) || "");
|
|
11561
11635
|
}
|
|
11562
11636
|
}
|
|
11563
11637
|
function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pendingOpenAIToolCalls) {
|
|
11564
11638
|
const json = rawJson;
|
|
11565
11639
|
if (apiFormat === "google") {
|
|
11566
|
-
const parts = _optionalChain([json, 'access',
|
|
11640
|
+
const parts = _optionalChain([json, 'access', _611 => _611.candidates, 'optionalAccess', _612 => _612[0], 'optionalAccess', _613 => _613.content, 'optionalAccess', _614 => _614.parts]) || [];
|
|
11567
11641
|
for (const part of parts) {
|
|
11568
11642
|
if (part.functionCall) {
|
|
11569
11643
|
logger.info("Function call detected", { functionCall: part.functionCall });
|
|
@@ -11573,13 +11647,13 @@ function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pend
|
|
|
11573
11647
|
args: part.functionCall.args || {}
|
|
11574
11648
|
};
|
|
11575
11649
|
toolCalls.push(toolCall);
|
|
11576
|
-
_optionalChain([callbacks, 'access',
|
|
11650
|
+
_optionalChain([callbacks, 'access', _615 => _615.onToolCall, 'optionalCall', _616 => _616(toolCall)]);
|
|
11577
11651
|
logger.info("Tool called", { toolName: toolCall.name });
|
|
11578
11652
|
}
|
|
11579
11653
|
}
|
|
11580
11654
|
} else if (apiFormat !== "anthropic") {
|
|
11581
|
-
const delta = _optionalChain([json, 'access',
|
|
11582
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
11655
|
+
const delta = _optionalChain([json, 'access', _617 => _617.choices, 'optionalAccess', _618 => _618[0], 'optionalAccess', _619 => _619.delta]);
|
|
11656
|
+
if (_optionalChain([delta, 'optionalAccess', _620 => _620.tool_calls]) && pendingOpenAIToolCalls) {
|
|
11583
11657
|
for (const tc of delta.tool_calls) {
|
|
11584
11658
|
const index = _nullishCoalesce(tc.index, () => ( 0));
|
|
11585
11659
|
let pending = pendingOpenAIToolCalls.get(index);
|
|
@@ -11588,8 +11662,8 @@ function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pend
|
|
|
11588
11662
|
pendingOpenAIToolCalls.set(index, pending);
|
|
11589
11663
|
}
|
|
11590
11664
|
if (tc.id) pending.id = tc.id;
|
|
11591
|
-
if (_optionalChain([tc, 'access',
|
|
11592
|
-
if (_optionalChain([tc, 'access',
|
|
11665
|
+
if (_optionalChain([tc, 'access', _621 => _621.function, 'optionalAccess', _622 => _622.name])) pending.name += tc.function.name;
|
|
11666
|
+
if (_optionalChain([tc, 'access', _623 => _623.function, 'optionalAccess', _624 => _624.arguments])) pending.arguments += tc.function.arguments;
|
|
11593
11667
|
}
|
|
11594
11668
|
}
|
|
11595
11669
|
}
|
|
@@ -11604,7 +11678,7 @@ function finalizeOpenAIToolCalls(pendingOpenAIToolCalls, toolCalls, callbacks, l
|
|
|
11604
11678
|
args: JSON.parse(pending.arguments || "{}")
|
|
11605
11679
|
};
|
|
11606
11680
|
toolCalls.push(toolCall);
|
|
11607
|
-
_optionalChain([callbacks, 'access',
|
|
11681
|
+
_optionalChain([callbacks, 'access', _625 => _625.onToolCall, 'optionalCall', _626 => _626(toolCall)]);
|
|
11608
11682
|
logger.info("Tool called (OpenAI)", { toolName: toolCall.name, args: toolCall.args });
|
|
11609
11683
|
} catch (e) {
|
|
11610
11684
|
logger.error("Failed to parse OpenAI tool call arguments", e instanceof Error ? e : void 0, {
|
|
@@ -11618,38 +11692,38 @@ function finalizeOpenAIToolCalls(pendingOpenAIToolCalls, toolCalls, callbacks, l
|
|
|
11618
11692
|
function parseStreamChunk(rawJson, apiFormat, callbacks, logger) {
|
|
11619
11693
|
const json = rawJson;
|
|
11620
11694
|
if (apiFormat === "google") {
|
|
11621
|
-
const candidate = _optionalChain([json, 'access',
|
|
11695
|
+
const candidate = _optionalChain([json, 'access', _627 => _627.candidates, 'optionalAccess', _628 => _628[0]]);
|
|
11622
11696
|
if (!candidate) {
|
|
11623
11697
|
logger.warn("No candidate found in Gemini response");
|
|
11624
11698
|
return;
|
|
11625
11699
|
}
|
|
11626
|
-
const parts = _optionalChain([candidate, 'access',
|
|
11700
|
+
const parts = _optionalChain([candidate, 'access', _629 => _629.content, 'optionalAccess', _630 => _630.parts]) || [];
|
|
11627
11701
|
for (const part of parts) {
|
|
11628
11702
|
if (part.thought === true && part.text) {
|
|
11629
|
-
_optionalChain([callbacks, 'access',
|
|
11703
|
+
_optionalChain([callbacks, 'access', _631 => _631.onReasoning, 'optionalCall', _632 => _632(part.text)]);
|
|
11630
11704
|
continue;
|
|
11631
11705
|
} else if (part.thoughtSignature && !part.thought) {
|
|
11632
11706
|
logger.debug("Gemini returned thoughtSignature without thought content");
|
|
11633
11707
|
}
|
|
11634
11708
|
if (part.text) {
|
|
11635
|
-
_optionalChain([callbacks, 'access',
|
|
11709
|
+
_optionalChain([callbacks, 'access', _633 => _633.onDelta, 'optionalCall', _634 => _634(part.text)]);
|
|
11636
11710
|
}
|
|
11637
11711
|
}
|
|
11638
11712
|
} else if (apiFormat === "anthropic") {
|
|
11639
11713
|
const delta = json.delta;
|
|
11640
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
11641
|
-
_optionalChain([callbacks, 'access',
|
|
11714
|
+
if (_optionalChain([delta, 'optionalAccess', _635 => _635.text])) {
|
|
11715
|
+
_optionalChain([callbacks, 'access', _636 => _636.onDelta, 'optionalCall', _637 => _637(delta.text)]);
|
|
11642
11716
|
}
|
|
11643
11717
|
} else {
|
|
11644
|
-
const delta = _optionalChain([json, 'access',
|
|
11645
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
11646
|
-
_optionalChain([callbacks, 'access',
|
|
11718
|
+
const delta = _optionalChain([json, 'access', _638 => _638.choices, 'optionalAccess', _639 => _639[0], 'optionalAccess', _640 => _640.delta]);
|
|
11719
|
+
if (_optionalChain([delta, 'optionalAccess', _641 => _641.content])) {
|
|
11720
|
+
_optionalChain([callbacks, 'access', _642 => _642.onDelta, 'optionalCall', _643 => _643(delta.content)]);
|
|
11647
11721
|
}
|
|
11648
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
11649
|
-
_optionalChain([callbacks, 'access',
|
|
11722
|
+
if (_optionalChain([delta, 'optionalAccess', _644 => _644.thinking, 'optionalAccess', _645 => _645.content])) {
|
|
11723
|
+
_optionalChain([callbacks, 'access', _646 => _646.onReasoning, 'optionalCall', _647 => _647(delta.thinking.content)]);
|
|
11650
11724
|
}
|
|
11651
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
11652
|
-
_optionalChain([callbacks, 'access',
|
|
11725
|
+
if (_optionalChain([delta, 'optionalAccess', _648 => _648.reasoning_content])) {
|
|
11726
|
+
_optionalChain([callbacks, 'access', _649 => _649.onReasoning, 'optionalCall', _650 => _650(delta.reasoning_content)]);
|
|
11653
11727
|
}
|
|
11654
11728
|
}
|
|
11655
11729
|
}
|
|
@@ -11662,7 +11736,7 @@ function buildIterationBlocks(iteration, content, reasoning, blocks, callbacks)
|
|
|
11662
11736
|
content: reasoning
|
|
11663
11737
|
};
|
|
11664
11738
|
blocks.push(thinkingBlock);
|
|
11665
|
-
_optionalChain([callbacks, 'access',
|
|
11739
|
+
_optionalChain([callbacks, 'access', _651 => _651.onBlock, 'optionalCall', _652 => _652(thinkingBlock)]);
|
|
11666
11740
|
}
|
|
11667
11741
|
if (content && content.trim()) {
|
|
11668
11742
|
const textBlock = {
|
|
@@ -11671,7 +11745,7 @@ function buildIterationBlocks(iteration, content, reasoning, blocks, callbacks)
|
|
|
11671
11745
|
content
|
|
11672
11746
|
};
|
|
11673
11747
|
blocks.push(textBlock);
|
|
11674
|
-
_optionalChain([callbacks, 'access',
|
|
11748
|
+
_optionalChain([callbacks, 'access', _653 => _653.onBlock, 'optionalCall', _654 => _654(textBlock)]);
|
|
11675
11749
|
}
|
|
11676
11750
|
}
|
|
11677
11751
|
async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbacks, logger, builtinExecutor) {
|
|
@@ -11686,7 +11760,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
11686
11760
|
status: "running"
|
|
11687
11761
|
};
|
|
11688
11762
|
blocks.push(toolUseBlock);
|
|
11689
|
-
_optionalChain([callbacks, 'access',
|
|
11763
|
+
_optionalChain([callbacks, 'access', _655 => _655.onBlock, 'optionalCall', _656 => _656(toolUseBlock)]);
|
|
11690
11764
|
try {
|
|
11691
11765
|
logger.info("Executing tool", { toolName: toolCall.name });
|
|
11692
11766
|
const mcpTool = mcpTools.find((t) => t.id === toolCall.name);
|
|
@@ -11709,8 +11783,8 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
11709
11783
|
result = { isError: true, content: [{ type: "text", text: "MCP service not available" }] };
|
|
11710
11784
|
}
|
|
11711
11785
|
logger.info("Tool result received", { result });
|
|
11712
|
-
_optionalChain([callbacks, 'access',
|
|
11713
|
-
const resultText = _optionalChain([result, 'access',
|
|
11786
|
+
_optionalChain([callbacks, 'access', _657 => _657.onToolResult, 'optionalCall', _658 => _658(toolCall.id, result)]);
|
|
11787
|
+
const resultText = _optionalChain([result, 'access', _659 => _659.content, 'optionalAccess', _660 => _660[0], 'optionalAccess', _661 => _661.text]) || JSON.stringify(result);
|
|
11714
11788
|
const toolResultBlock = {
|
|
11715
11789
|
id: `${toolCall.id}_result`,
|
|
11716
11790
|
type: "tool_result",
|
|
@@ -11720,11 +11794,11 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
11720
11794
|
isError: result.isError
|
|
11721
11795
|
};
|
|
11722
11796
|
blocks.push(toolResultBlock);
|
|
11723
|
-
_optionalChain([callbacks, 'access',
|
|
11797
|
+
_optionalChain([callbacks, 'access', _662 => _662.onBlock, 'optionalCall', _663 => _663(toolResultBlock)]);
|
|
11724
11798
|
const toolUseBlockRef = blocks.find((b) => b.id === `${toolCall.id}_use`);
|
|
11725
11799
|
if (toolUseBlockRef && toolUseBlockRef.type === "tool_use") {
|
|
11726
11800
|
toolUseBlockRef.status = result.isError ? "error" : "completed";
|
|
11727
|
-
_optionalChain([callbacks, 'access',
|
|
11801
|
+
_optionalChain([callbacks, 'access', _664 => _664.onBlock, 'optionalCall', _665 => _665({ ...toolUseBlockRef })]);
|
|
11728
11802
|
}
|
|
11729
11803
|
toolResults.push({ toolCall, result });
|
|
11730
11804
|
} catch (error) {
|
|
@@ -11734,7 +11808,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
11734
11808
|
isError: true,
|
|
11735
11809
|
content: [{ type: "text", text: `Error: ${errorMessage}` }]
|
|
11736
11810
|
};
|
|
11737
|
-
_optionalChain([callbacks, 'access',
|
|
11811
|
+
_optionalChain([callbacks, 'access', _666 => _666.onToolResult, 'optionalCall', _667 => _667(toolCall.id, errorResult)]);
|
|
11738
11812
|
const errorToolResultBlock = {
|
|
11739
11813
|
id: `${toolCall.id}_result`,
|
|
11740
11814
|
type: "tool_result",
|
|
@@ -11744,11 +11818,11 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
11744
11818
|
isError: true
|
|
11745
11819
|
};
|
|
11746
11820
|
blocks.push(errorToolResultBlock);
|
|
11747
|
-
_optionalChain([callbacks, 'access',
|
|
11821
|
+
_optionalChain([callbacks, 'access', _668 => _668.onBlock, 'optionalCall', _669 => _669(errorToolResultBlock)]);
|
|
11748
11822
|
const errorToolUseBlockRef = blocks.find((b) => b.id === `${toolCall.id}_use`);
|
|
11749
11823
|
if (errorToolUseBlockRef && errorToolUseBlockRef.type === "tool_use") {
|
|
11750
11824
|
errorToolUseBlockRef.status = "error";
|
|
11751
|
-
_optionalChain([callbacks, 'access',
|
|
11825
|
+
_optionalChain([callbacks, 'access', _670 => _670.onBlock, 'optionalCall', _671 => _671({ ...errorToolUseBlockRef })]);
|
|
11752
11826
|
}
|
|
11753
11827
|
toolResults.push({ toolCall, result: errorResult });
|
|
11754
11828
|
}
|
|
@@ -11758,7 +11832,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
11758
11832
|
function mapToolArguments(args, mcpTool, logger) {
|
|
11759
11833
|
const mappedArgs = { ...args };
|
|
11760
11834
|
const toolSchema = mcpTool.inputSchema;
|
|
11761
|
-
if (_optionalChain([toolSchema, 'optionalAccess',
|
|
11835
|
+
if (_optionalChain([toolSchema, 'optionalAccess', _672 => _672.properties])) {
|
|
11762
11836
|
const expectedParams = Object.keys(toolSchema.properties);
|
|
11763
11837
|
const paramMappings = {
|
|
11764
11838
|
"search_query": ["query", "q", "searchQuery", "search"],
|
|
@@ -11792,25 +11866,25 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
11792
11866
|
options.providerId,
|
|
11793
11867
|
options.model
|
|
11794
11868
|
);
|
|
11795
|
-
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess',
|
|
11796
|
-
const actualModel = _optionalChain([routedInfo, 'optionalAccess',
|
|
11869
|
+
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _673 => _673.actualProviderId]) || options.providerId;
|
|
11870
|
+
const actualModel = _optionalChain([routedInfo, 'optionalAccess', _674 => _674.actualModelId]) || options.model;
|
|
11797
11871
|
const provider = await getProvider(actualProviderId);
|
|
11798
11872
|
if (!provider) {
|
|
11799
|
-
_optionalChain([callbacks, 'access',
|
|
11873
|
+
_optionalChain([callbacks, 'access', _675 => _675.onError, 'optionalCall', _676 => _676(`Provider not found: ${actualProviderId}`)]);
|
|
11800
11874
|
return;
|
|
11801
11875
|
}
|
|
11802
11876
|
if (!provider.enabled) {
|
|
11803
|
-
_optionalChain([callbacks, 'access',
|
|
11877
|
+
_optionalChain([callbacks, 'access', _677 => _677.onError, 'optionalCall', _678 => _678(`Provider is disabled: ${provider.name}`)]);
|
|
11804
11878
|
return;
|
|
11805
11879
|
}
|
|
11806
11880
|
const { apiKey: effectiveKey } = _chunkA2YMUCBTcjs.resolveProviderEndpoint.call(void 0, provider);
|
|
11807
11881
|
const apiKey = resolveApiKey2(effectiveKey);
|
|
11808
11882
|
if (!apiKey) {
|
|
11809
|
-
_optionalChain([callbacks, 'access',
|
|
11883
|
+
_optionalChain([callbacks, 'access', _679 => _679.onError, 'optionalCall', _680 => _680("API key not configured")]);
|
|
11810
11884
|
return;
|
|
11811
11885
|
}
|
|
11812
11886
|
const messageId = `msg_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
11813
|
-
_optionalChain([callbacks, 'access',
|
|
11887
|
+
_optionalChain([callbacks, 'access', _681 => _681.onStart, 'optionalCall', _682 => _682(messageId)]);
|
|
11814
11888
|
const globalParams = await llmConfig.getGlobalModelParameters();
|
|
11815
11889
|
const MAX_ITERATIONS = _nullishCoalesce(globalParams.toolMaxTurns, () => ( 100));
|
|
11816
11890
|
let iteration = 0;
|
|
@@ -11844,7 +11918,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
11844
11918
|
if (options.nativeSearchAugmentation) {
|
|
11845
11919
|
_chunkJMJBSACDcjs.applyAugmentation.call(void 0, requestBody, options.nativeSearchAugmentation);
|
|
11846
11920
|
}
|
|
11847
|
-
const headers =
|
|
11921
|
+
const headers = _chunkTX4UCSOPcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
11848
11922
|
logger.info("Sending tool call request", {
|
|
11849
11923
|
url,
|
|
11850
11924
|
headers,
|
|
@@ -11857,12 +11931,12 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
11857
11931
|
});
|
|
11858
11932
|
if (!response.ok) {
|
|
11859
11933
|
const errorText = await response.text();
|
|
11860
|
-
_optionalChain([callbacks, 'access',
|
|
11934
|
+
_optionalChain([callbacks, 'access', _683 => _683.onError, 'optionalCall', _684 => _684(`API error (${response.status}): ${errorText}`)]);
|
|
11861
11935
|
return;
|
|
11862
11936
|
}
|
|
11863
|
-
const reader = _optionalChain([response, 'access',
|
|
11937
|
+
const reader = _optionalChain([response, 'access', _685 => _685.body, 'optionalAccess', _686 => _686.getReader, 'call', _687 => _687()]);
|
|
11864
11938
|
if (!reader) {
|
|
11865
|
-
_optionalChain([callbacks, 'access',
|
|
11939
|
+
_optionalChain([callbacks, 'access', _688 => _688.onError, 'optionalCall', _689 => _689("No response body")]);
|
|
11866
11940
|
return;
|
|
11867
11941
|
}
|
|
11868
11942
|
const decoder = new TextDecoder();
|
|
@@ -11895,7 +11969,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
11895
11969
|
logger.debug("Parsed JSON", { json });
|
|
11896
11970
|
if (json.error) {
|
|
11897
11971
|
logger.error("API Error", void 0, { error: json.error });
|
|
11898
|
-
_optionalChain([callbacks, 'access',
|
|
11972
|
+
_optionalChain([callbacks, 'access', _690 => _690.onError, 'optionalCall', _691 => _691(`API Error: ${json.error.message || JSON.stringify(json.error)}`)]);
|
|
11899
11973
|
return;
|
|
11900
11974
|
}
|
|
11901
11975
|
parseStreamChunk(json, apiFormat, callbacks, logger);
|
|
@@ -11928,7 +12002,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
11928
12002
|
toolCallsLength: toolCalls.length,
|
|
11929
12003
|
executableToolCallsLength: executableToolCalls.length,
|
|
11930
12004
|
hasMcpTools: !!options.mcpTools,
|
|
11931
|
-
mcpToolsLength: _optionalChain([options, 'access',
|
|
12005
|
+
mcpToolsLength: _optionalChain([options, 'access', _692 => _692.mcpTools, 'optionalAccess', _693 => _693.length]),
|
|
11932
12006
|
hasMcpService: !!mcpService
|
|
11933
12007
|
});
|
|
11934
12008
|
if (executableToolCalls.length > 0 && options.mcpTools && (mcpService || builtinExecutor)) {
|
|
@@ -11949,7 +12023,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
11949
12023
|
builtinExecutor
|
|
11950
12024
|
);
|
|
11951
12025
|
const toolResultsText = toolResults.map(({ toolCall, result }) => {
|
|
11952
|
-
const resultText = typeof result === "string" ? result : _optionalChain([result, 'access',
|
|
12026
|
+
const resultText = typeof result === "string" ? result : _optionalChain([result, 'access', _694 => _694.content, 'optionalAccess', _695 => _695[0], 'optionalAccess', _696 => _696.text]) || JSON.stringify(result);
|
|
11953
12027
|
return `Tool ${toolCall.name} result:
|
|
11954
12028
|
${resultText}`;
|
|
11955
12029
|
}).join("\n\n");
|
|
@@ -11967,12 +12041,12 @@ ${resultText}`;
|
|
|
11967
12041
|
}
|
|
11968
12042
|
} catch (streamError) {
|
|
11969
12043
|
logger.error("Stream processing error", streamError instanceof Error ? streamError : void 0);
|
|
11970
|
-
_optionalChain([callbacks, 'access',
|
|
12044
|
+
_optionalChain([callbacks, 'access', _697 => _697.onError, 'optionalCall', _698 => _698(`Stream error: ${streamError instanceof Error ? streamError.message : "Unknown error"}`)]);
|
|
11971
12045
|
return;
|
|
11972
12046
|
}
|
|
11973
12047
|
}
|
|
11974
12048
|
logger.info("Sending final callback", { blocksCount: blocks.length });
|
|
11975
|
-
_optionalChain([callbacks, 'access',
|
|
12049
|
+
_optionalChain([callbacks, 'access', _699 => _699.onDone, 'optionalCall', _700 => _700({
|
|
11976
12050
|
id: messageId,
|
|
11977
12051
|
role: "assistant",
|
|
11978
12052
|
content: finalContent,
|
|
@@ -11983,7 +12057,7 @@ ${resultText}`;
|
|
|
11983
12057
|
} catch (error) {
|
|
11984
12058
|
logger.error("Error in streamWithTools", error instanceof Error ? error : void 0);
|
|
11985
12059
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
11986
|
-
_optionalChain([callbacks, 'access',
|
|
12060
|
+
_optionalChain([callbacks, 'access', _701 => _701.onError, 'optionalCall', _702 => _702(message)]);
|
|
11987
12061
|
}
|
|
11988
12062
|
}
|
|
11989
12063
|
|
|
@@ -12034,8 +12108,8 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
|
|
|
12034
12108
|
options.providerId,
|
|
12035
12109
|
options.model
|
|
12036
12110
|
);
|
|
12037
|
-
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess',
|
|
12038
|
-
const actualModel = _optionalChain([routedInfo, 'optionalAccess',
|
|
12111
|
+
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _703 => _703.actualProviderId]) || options.providerId;
|
|
12112
|
+
const actualModel = _optionalChain([routedInfo, 'optionalAccess', _704 => _704.actualModelId]) || options.model;
|
|
12039
12113
|
const provider = await getProvider(actualProviderId);
|
|
12040
12114
|
if (!provider) {
|
|
12041
12115
|
return { success: false, error: `Provider not found: ${actualProviderId}` };
|
|
@@ -12078,7 +12152,7 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
|
|
|
12078
12152
|
extendedContext: options.useExtendedContext ? { enabled: true, model: actualModel } : void 0,
|
|
12079
12153
|
resolveUrl: (config) => config.url instanceof URL ? config.url.toString() : _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: actualModel, stream: false }),
|
|
12080
12154
|
buildHeaders: (config) => ({
|
|
12081
|
-
...
|
|
12155
|
+
..._chunkTX4UCSOPcjs.getProviderHeaders.call(void 0, provider, apiKey),
|
|
12082
12156
|
...config.headers,
|
|
12083
12157
|
..._chunkUNEFIWXIcjs.isOpenRouterProvider.call(void 0, provider) ? _chunkUNEFIWXIcjs.OPENROUTER_APP_HEADERS : {}
|
|
12084
12158
|
}),
|
|
@@ -12112,18 +12186,18 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
|
|
|
12112
12186
|
{ endpointTransformer: void 0 }
|
|
12113
12187
|
);
|
|
12114
12188
|
const data = await transformedResponse2.json();
|
|
12115
|
-
const choice = _optionalChain([data, 'access',
|
|
12189
|
+
const choice = _optionalChain([data, 'access', _705 => _705.choices, 'optionalAccess', _706 => _706[0]]);
|
|
12116
12190
|
if (!choice) {
|
|
12117
12191
|
return { success: false, error: "No choices in response" };
|
|
12118
12192
|
}
|
|
12119
|
-
const rawToolCalls = _optionalChain([choice, 'access',
|
|
12120
|
-
const toolCalls = _optionalChain([rawToolCalls, 'optionalAccess',
|
|
12193
|
+
const rawToolCalls = _optionalChain([choice, 'access', _707 => _707.message, 'optionalAccess', _708 => _708.tool_calls]);
|
|
12194
|
+
const toolCalls = _optionalChain([rawToolCalls, 'optionalAccess', _709 => _709.map, 'call', _710 => _710((tc) => ({
|
|
12121
12195
|
id: tc.id,
|
|
12122
12196
|
name: tc.function.name,
|
|
12123
12197
|
args: typeof tc.function.arguments === "string" ? JSON.parse(tc.function.arguments) : tc.function.arguments
|
|
12124
12198
|
}))]);
|
|
12125
12199
|
const tapped = readUsageFromOpenAIResponse(data.usage);
|
|
12126
|
-
if (_optionalChain([recording, 'optionalAccess',
|
|
12200
|
+
if (_optionalChain([recording, 'optionalAccess', _711 => _711.recorder]) && tapped) {
|
|
12127
12201
|
recording.recorder.record({
|
|
12128
12202
|
messageId: _nullishCoalesce(options.messageId, () => ( null)),
|
|
12129
12203
|
parentMessageId: _nullishCoalesce(options.parentMessageId, () => ( null)),
|
|
@@ -12141,9 +12215,9 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
|
|
|
12141
12215
|
message: {
|
|
12142
12216
|
id: `msg_${Date.now()}`,
|
|
12143
12217
|
role: "assistant",
|
|
12144
|
-
content: _optionalChain([choice, 'access',
|
|
12218
|
+
content: _optionalChain([choice, 'access', _712 => _712.message, 'optionalAccess', _713 => _713.content]) || "",
|
|
12145
12219
|
timestamp: Date.now(),
|
|
12146
|
-
thinking: data.reasoning_content || _optionalChain([choice, 'access',
|
|
12220
|
+
thinking: data.reasoning_content || _optionalChain([choice, 'access', _714 => _714.message, 'optionalAccess', _715 => _715.thinking, 'optionalAccess', _716 => _716.content]) ? { content: data.reasoning_content || _optionalChain([choice, 'access', _717 => _717.message, 'optionalAccess', _718 => _718.thinking, 'optionalAccess', _719 => _719.content]) || "", signature: _optionalChain([choice, 'access', _720 => _720.message, 'optionalAccess', _721 => _721.thinking, 'optionalAccess', _722 => _722.signature]) } : void 0,
|
|
12147
12221
|
toolCalls
|
|
12148
12222
|
},
|
|
12149
12223
|
usage: data.usage ? {
|
|
@@ -12164,21 +12238,21 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
12164
12238
|
options.providerId,
|
|
12165
12239
|
options.model
|
|
12166
12240
|
);
|
|
12167
|
-
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess',
|
|
12168
|
-
const actualModel = _optionalChain([routedInfo, 'optionalAccess',
|
|
12241
|
+
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _723 => _723.actualProviderId]) || options.providerId;
|
|
12242
|
+
const actualModel = _optionalChain([routedInfo, 'optionalAccess', _724 => _724.actualModelId]) || options.model;
|
|
12169
12243
|
const provider = await getProvider(actualProviderId);
|
|
12170
12244
|
if (!provider) {
|
|
12171
|
-
_optionalChain([callbacks, 'access',
|
|
12245
|
+
_optionalChain([callbacks, 'access', _725 => _725.onError, 'optionalCall', _726 => _726(`Provider not found: ${actualProviderId}`)]);
|
|
12172
12246
|
return;
|
|
12173
12247
|
}
|
|
12174
12248
|
if (!provider.enabled) {
|
|
12175
|
-
_optionalChain([callbacks, 'access',
|
|
12249
|
+
_optionalChain([callbacks, 'access', _727 => _727.onError, 'optionalCall', _728 => _728(`Provider is disabled: ${provider.name}`)]);
|
|
12176
12250
|
return;
|
|
12177
12251
|
}
|
|
12178
12252
|
const { apiKey: effectiveKey } = _chunkA2YMUCBTcjs.resolveProviderEndpoint.call(void 0, provider);
|
|
12179
12253
|
const apiKey = resolveApiKey2(effectiveKey);
|
|
12180
12254
|
if (!apiKey) {
|
|
12181
|
-
_optionalChain([callbacks, 'access',
|
|
12255
|
+
_optionalChain([callbacks, 'access', _729 => _729.onError, 'optionalCall', _730 => _730("API key not configured")]);
|
|
12182
12256
|
return;
|
|
12183
12257
|
}
|
|
12184
12258
|
const { chain, hasTransformers } = await resolveChainWithMain(
|
|
@@ -12190,7 +12264,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
12190
12264
|
return completeStreamFallback(options, callbacks);
|
|
12191
12265
|
}
|
|
12192
12266
|
const messageId = `msg_${Date.now()}`;
|
|
12193
|
-
_optionalChain([callbacks, 'access',
|
|
12267
|
+
_optionalChain([callbacks, 'access', _731 => _731.onStart, 'optionalCall', _732 => _732(messageId)]);
|
|
12194
12268
|
const unifiedRequest = buildUnifiedCompletionRequest(actualModel, options, true);
|
|
12195
12269
|
const transformerProvider = {
|
|
12196
12270
|
name: provider.name,
|
|
@@ -12209,7 +12283,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
12209
12283
|
extendedContext: options.useExtendedContext ? { enabled: true, model: actualModel } : void 0,
|
|
12210
12284
|
resolveUrl: (config) => config.url instanceof URL ? config.url.toString() : _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: actualModel, stream: true }),
|
|
12211
12285
|
buildHeaders: (config) => ({
|
|
12212
|
-
...
|
|
12286
|
+
..._chunkTX4UCSOPcjs.getProviderHeaders.call(void 0, provider, apiKey),
|
|
12213
12287
|
...config.headers,
|
|
12214
12288
|
..._chunkUNEFIWXIcjs.isOpenRouterProvider.call(void 0, provider) ? _chunkUNEFIWXIcjs.OPENROUTER_APP_HEADERS : {}
|
|
12215
12289
|
}),
|
|
@@ -12230,7 +12304,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
12230
12304
|
});
|
|
12231
12305
|
if (!response.ok) {
|
|
12232
12306
|
const errorText = await response.text();
|
|
12233
|
-
_optionalChain([callbacks, 'access',
|
|
12307
|
+
_optionalChain([callbacks, 'access', _733 => _733.onError, 'optionalCall', _734 => _734(`API error (${response.status}): ${errorText}`)]);
|
|
12234
12308
|
return;
|
|
12235
12309
|
}
|
|
12236
12310
|
const transformedResponse2 = await executor.executeResponseChain(
|
|
@@ -12240,9 +12314,9 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
12240
12314
|
chain,
|
|
12241
12315
|
{ endpointTransformer: void 0 }
|
|
12242
12316
|
);
|
|
12243
|
-
const reader = _optionalChain([transformedResponse2, 'access',
|
|
12317
|
+
const reader = _optionalChain([transformedResponse2, 'access', _735 => _735.body, 'optionalAccess', _736 => _736.getReader, 'call', _737 => _737()]);
|
|
12244
12318
|
if (!reader) {
|
|
12245
|
-
_optionalChain([callbacks, 'access',
|
|
12319
|
+
_optionalChain([callbacks, 'access', _738 => _738.onError, 'optionalCall', _739 => _739("No response body")]);
|
|
12246
12320
|
return;
|
|
12247
12321
|
}
|
|
12248
12322
|
const decoder = new TextDecoder();
|
|
@@ -12260,22 +12334,22 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
12260
12334
|
if (data === "[DONE]") continue;
|
|
12261
12335
|
try {
|
|
12262
12336
|
const json = JSON.parse(data);
|
|
12263
|
-
const delta = _optionalChain([json, 'access',
|
|
12264
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
12337
|
+
const delta = _optionalChain([json, 'access', _740 => _740.choices, 'optionalAccess', _741 => _741[0], 'optionalAccess', _742 => _742.delta]);
|
|
12338
|
+
if (_optionalChain([delta, 'optionalAccess', _743 => _743.content])) {
|
|
12265
12339
|
content += delta.content;
|
|
12266
|
-
_optionalChain([callbacks, 'access',
|
|
12340
|
+
_optionalChain([callbacks, 'access', _744 => _744.onDelta, 'optionalCall', _745 => _745(delta.content)]);
|
|
12267
12341
|
}
|
|
12268
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
12342
|
+
if (_optionalChain([delta, 'optionalAccess', _746 => _746.thinking, 'optionalAccess', _747 => _747.content])) {
|
|
12269
12343
|
reasoning += delta.thinking.content;
|
|
12270
|
-
_optionalChain([callbacks, 'access',
|
|
12344
|
+
_optionalChain([callbacks, 'access', _748 => _748.onReasoning, 'optionalCall', _749 => _749(delta.thinking.content)]);
|
|
12271
12345
|
}
|
|
12272
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
12346
|
+
if (_optionalChain([delta, 'optionalAccess', _750 => _750.reasoning_content])) {
|
|
12273
12347
|
reasoning += delta.reasoning_content;
|
|
12274
|
-
_optionalChain([callbacks, 'access',
|
|
12348
|
+
_optionalChain([callbacks, 'access', _751 => _751.onReasoning, 'optionalCall', _752 => _752(delta.reasoning_content)]);
|
|
12275
12349
|
}
|
|
12276
12350
|
if (json.usage) {
|
|
12277
12351
|
const tapped = readUsageFromOpenAIResponse(json.usage);
|
|
12278
|
-
if (_optionalChain([recording, 'optionalAccess',
|
|
12352
|
+
if (_optionalChain([recording, 'optionalAccess', _753 => _753.recorder]) && tapped) {
|
|
12279
12353
|
recording.recorder.record({
|
|
12280
12354
|
messageId: _nullishCoalesce(options.messageId, () => ( null)),
|
|
12281
12355
|
parentMessageId: _nullishCoalesce(options.parentMessageId, () => ( null)),
|
|
@@ -12288,7 +12362,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
12288
12362
|
rawUsage: json.usage
|
|
12289
12363
|
});
|
|
12290
12364
|
}
|
|
12291
|
-
_optionalChain([callbacks, 'access',
|
|
12365
|
+
_optionalChain([callbacks, 'access', _754 => _754.onDone, 'optionalCall', _755 => _755(
|
|
12292
12366
|
{
|
|
12293
12367
|
id: messageId,
|
|
12294
12368
|
role: "assistant",
|
|
@@ -12309,7 +12383,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
12309
12383
|
}
|
|
12310
12384
|
}
|
|
12311
12385
|
}
|
|
12312
|
-
_optionalChain([callbacks, 'access',
|
|
12386
|
+
_optionalChain([callbacks, 'access', _756 => _756.onDone, 'optionalCall', _757 => _757({
|
|
12313
12387
|
id: messageId,
|
|
12314
12388
|
role: "assistant",
|
|
12315
12389
|
content,
|
|
@@ -12321,7 +12395,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
12321
12395
|
}
|
|
12322
12396
|
} catch (error) {
|
|
12323
12397
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
12324
|
-
_optionalChain([callbacks, 'access',
|
|
12398
|
+
_optionalChain([callbacks, 'access', _758 => _758.onError, 'optionalCall', _759 => _759(message)]);
|
|
12325
12399
|
}
|
|
12326
12400
|
}
|
|
12327
12401
|
|
|
@@ -12388,8 +12462,8 @@ var CompletionService = (_class21 = class {
|
|
|
12388
12462
|
options.providerId,
|
|
12389
12463
|
options.model
|
|
12390
12464
|
);
|
|
12391
|
-
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess',
|
|
12392
|
-
const actualModel = _optionalChain([routedInfo, 'optionalAccess',
|
|
12465
|
+
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _760 => _760.actualProviderId]) || options.providerId;
|
|
12466
|
+
const actualModel = _optionalChain([routedInfo, 'optionalAccess', _761 => _761.actualModelId]) || options.model;
|
|
12393
12467
|
const provider = await this.getProvider(actualProviderId);
|
|
12394
12468
|
if (!provider) {
|
|
12395
12469
|
return { success: false, error: `Provider not found: ${actualProviderId}` };
|
|
@@ -12422,7 +12496,7 @@ var CompletionService = (_class21 = class {
|
|
|
12422
12496
|
this.apiKeyPool.reportSuccess(options.sessionId);
|
|
12423
12497
|
}
|
|
12424
12498
|
if (result.success && result.usage && options.sessionId) {
|
|
12425
|
-
_optionalChain([this, 'access',
|
|
12499
|
+
_optionalChain([this, 'access', _762 => _762.usageEventSink, 'optionalAccess', _763 => _763.emit, 'call', _764 => _764({
|
|
12426
12500
|
sessionId: options.sessionId,
|
|
12427
12501
|
modelId: actualModel,
|
|
12428
12502
|
usage: result.usage,
|
|
@@ -12451,8 +12525,8 @@ var CompletionService = (_class21 = class {
|
|
|
12451
12525
|
options.model
|
|
12452
12526
|
);
|
|
12453
12527
|
this.logger.debug("Resolved routed model", { routedInfo });
|
|
12454
|
-
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess',
|
|
12455
|
-
const actualModel = _optionalChain([routedInfo, 'optionalAccess',
|
|
12528
|
+
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _765 => _765.actualProviderId]) || options.providerId;
|
|
12529
|
+
const actualModel = _optionalChain([routedInfo, 'optionalAccess', _766 => _766.actualModelId]) || options.model;
|
|
12456
12530
|
this.logger.debug("Resolved provider and model", { actualProviderId, actualModel });
|
|
12457
12531
|
const provider = await this.getProvider(actualProviderId);
|
|
12458
12532
|
this.logger.debug("Retrieved provider", provider ? {
|
|
@@ -12464,22 +12538,22 @@ var CompletionService = (_class21 = class {
|
|
|
12464
12538
|
enabled: provider.enabled
|
|
12465
12539
|
} : { error: "Provider not found" });
|
|
12466
12540
|
if (!provider) {
|
|
12467
|
-
_optionalChain([callbacks, 'access',
|
|
12541
|
+
_optionalChain([callbacks, 'access', _767 => _767.onError, 'optionalCall', _768 => _768(`Provider not found: ${actualProviderId}`)]);
|
|
12468
12542
|
return;
|
|
12469
12543
|
}
|
|
12470
12544
|
if (!provider.enabled) {
|
|
12471
|
-
_optionalChain([callbacks, 'access',
|
|
12545
|
+
_optionalChain([callbacks, 'access', _769 => _769.onError, 'optionalCall', _770 => _770(`Provider is disabled: ${provider.name}`)]);
|
|
12472
12546
|
return;
|
|
12473
12547
|
}
|
|
12474
12548
|
const apiKey = await this.resolveApiKeyForRequest(provider, actualProviderId, options.sessionId);
|
|
12475
12549
|
if (!apiKey) {
|
|
12476
|
-
_optionalChain([callbacks, 'access',
|
|
12550
|
+
_optionalChain([callbacks, 'access', _771 => _771.onError, 'optionalCall', _772 => _772("API key not configured")]);
|
|
12477
12551
|
return;
|
|
12478
12552
|
}
|
|
12479
12553
|
const apiFormat = _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider);
|
|
12480
12554
|
this.logger.info("Using API format for stream", { apiFormat });
|
|
12481
12555
|
const messageId = `msg_${Date.now()}`;
|
|
12482
|
-
_optionalChain([callbacks, 'access',
|
|
12556
|
+
_optionalChain([callbacks, 'access', _773 => _773.onStart, 'optionalCall', _774 => _774(messageId)]);
|
|
12483
12557
|
const resolvedOptions = { ...options, model: actualModel };
|
|
12484
12558
|
if (options.sessionId) {
|
|
12485
12559
|
const sid = options.sessionId;
|
|
@@ -12488,14 +12562,14 @@ var CompletionService = (_class21 = class {
|
|
|
12488
12562
|
...callbacks,
|
|
12489
12563
|
onDone: (message, usage, metrics) => {
|
|
12490
12564
|
if (usage) {
|
|
12491
|
-
_optionalChain([this, 'access',
|
|
12565
|
+
_optionalChain([this, 'access', _775 => _775.usageEventSink, 'optionalAccess', _776 => _776.emit, 'call', _777 => _777({
|
|
12492
12566
|
sessionId: sid,
|
|
12493
12567
|
modelId: actualModel,
|
|
12494
12568
|
usage,
|
|
12495
12569
|
engineOrigin: "completion"
|
|
12496
12570
|
})]);
|
|
12497
12571
|
}
|
|
12498
|
-
_optionalChain([userOnDone, 'optionalCall',
|
|
12572
|
+
_optionalChain([userOnDone, 'optionalCall', _778 => _778(message, usage, metrics)]);
|
|
12499
12573
|
}
|
|
12500
12574
|
};
|
|
12501
12575
|
}
|
|
@@ -12511,11 +12585,11 @@ var CompletionService = (_class21 = class {
|
|
|
12511
12585
|
retryState.error = { status, message: error };
|
|
12512
12586
|
return;
|
|
12513
12587
|
}
|
|
12514
|
-
_optionalChain([callbacks, 'access',
|
|
12588
|
+
_optionalChain([callbacks, 'access', _779 => _779.onError, 'optionalCall', _780 => _780(error)]);
|
|
12515
12589
|
},
|
|
12516
12590
|
onDone: (message, usage, metrics) => {
|
|
12517
12591
|
this.apiKeyPool.reportSuccess(options.sessionId);
|
|
12518
|
-
_optionalChain([callbacks, 'access',
|
|
12592
|
+
_optionalChain([callbacks, 'access', _781 => _781.onDone, 'optionalCall', _782 => _782(message, usage, metrics)]);
|
|
12519
12593
|
}
|
|
12520
12594
|
};
|
|
12521
12595
|
await this.callStreamHandler(apiFormat, provider, apiKey, resolvedOptions, messageId, interceptCallbacks);
|
|
@@ -12536,7 +12610,7 @@ var CompletionService = (_class21 = class {
|
|
|
12536
12610
|
// don't fire onStart again
|
|
12537
12611
|
});
|
|
12538
12612
|
} else {
|
|
12539
|
-
_optionalChain([callbacks, 'access',
|
|
12613
|
+
_optionalChain([callbacks, 'access', _783 => _783.onError, 'optionalCall', _784 => _784(retryState.error.message)]);
|
|
12540
12614
|
}
|
|
12541
12615
|
}
|
|
12542
12616
|
} else {
|
|
@@ -12549,7 +12623,7 @@ var CompletionService = (_class21 = class {
|
|
|
12549
12623
|
} catch (error) {
|
|
12550
12624
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
12551
12625
|
this.logger.error("Stream completion error", error instanceof Error ? error : void 0, { message });
|
|
12552
|
-
_optionalChain([callbacks, 'access',
|
|
12626
|
+
_optionalChain([callbacks, 'access', _785 => _785.onError, 'optionalCall', _786 => _786(message)]);
|
|
12553
12627
|
}
|
|
12554
12628
|
}
|
|
12555
12629
|
/**
|
|
@@ -12589,7 +12663,7 @@ var CompletionService = (_class21 = class {
|
|
|
12589
12663
|
return {
|
|
12590
12664
|
success: true,
|
|
12591
12665
|
message: "Connection successful",
|
|
12592
|
-
response: _optionalChain([result, 'access',
|
|
12666
|
+
response: _optionalChain([result, 'access', _787 => _787.message, 'optionalAccess', _788 => _788.content]) || "",
|
|
12593
12667
|
model: modelId,
|
|
12594
12668
|
durationMs
|
|
12595
12669
|
};
|
|
@@ -12654,7 +12728,7 @@ ${description}`;
|
|
|
12654
12728
|
* 3. Legacy single key from provider config
|
|
12655
12729
|
*/
|
|
12656
12730
|
async resolveApiKeyForRequest(provider, providerId, sessionId) {
|
|
12657
|
-
if (_optionalChain([provider, 'access',
|
|
12731
|
+
if (_optionalChain([provider, 'access', _789 => _789.codingPlan, 'optionalAccess', _790 => _790.enabled]) && provider.codingPlan.apiKey) {
|
|
12658
12732
|
return this.resolveApiKey(provider.codingPlan.apiKey);
|
|
12659
12733
|
}
|
|
12660
12734
|
if (this.apiKeyPool) {
|