@omnicross/core 0.1.8 → 0.1.10
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 +5 -3
- package/dist/auth/GeminiCodeAssistProjectResolver.js +4 -2
- package/dist/{chunk-N5T4M4GU.js → chunk-2UTGX6FM.js} +2 -2
- package/dist/{chunk-32O35CIF.js → chunk-45FHEOKW.js} +22 -7
- package/dist/{chunk-LVUCAWMK.js → chunk-55FMGZ3L.js} +13 -5
- package/dist/{chunk-OF3BECU2.cjs → chunk-56QD3YW6.cjs} +18 -5
- package/dist/{chunk-V4TXMEJS.cjs → chunk-5LNYGCIW.cjs} +15 -7
- package/dist/{chunk-EPN67EGP.cjs → chunk-5UK3KLE2.cjs} +9 -1
- package/dist/chunk-6D4W22P4.js +150 -0
- package/dist/chunk-77USGNRW.cjs +37 -0
- package/dist/chunk-AOFWNWLT.cjs +203 -0
- package/dist/{chunk-UAPBLNN2.js → chunk-AQDON6MB.js} +8 -0
- package/dist/{chunk-LB6EBS6Y.js → chunk-CCVRRJOX.js} +17 -4
- package/dist/{chunk-OVQBNVSV.cjs → chunk-CMVXX7ON.cjs} +42 -27
- package/dist/{chunk-QYC54PMG.js → chunk-FEBAQI5A.js} +255 -92
- package/dist/{chunk-7C7DET6S.js → chunk-GXEZ2R3E.js} +156 -1
- package/dist/{chunk-PEGTIPB3.js → chunk-HKB656B4.js} +37 -43
- package/dist/chunk-N2EIM2XJ.js +203 -0
- package/dist/{chunk-MYYR3HZL.js → chunk-NGYOO5TO.js} +5 -5
- package/dist/{chunk-OKMJLEXX.cjs → chunk-OC6DOOFX.cjs} +5 -5
- package/dist/{chunk-2Z4XM3H5.cjs → chunk-P7EM6BND.cjs} +10 -10
- package/dist/chunk-QUSEZNYS.cjs +150 -0
- package/dist/{chunk-KBM2W6UY.cjs → chunk-RICPANBY.cjs} +41 -24
- package/dist/{chunk-TOVPMMHM.js → chunk-S3DYFEBE.js} +37 -20
- package/dist/{chunk-26K6T2YS.cjs → chunk-TIT74RIL.cjs} +407 -244
- package/dist/{chunk-XPIOJQS2.cjs → chunk-UWDW6PN3.cjs} +159 -4
- package/dist/chunk-WYVGULTQ.js +37 -0
- package/dist/{chunk-OXHNSZ53.cjs → chunk-ZQQUD66M.cjs} +54 -60
- package/dist/completion/CompletionService.cjs +15 -13
- package/dist/completion/CompletionService.js +14 -12
- package/dist/completion.cjs +15 -13
- package/dist/completion.js +14 -12
- package/dist/index.cjs +15 -13
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +14 -12
- package/dist/outbound-api/auditCapture.cjs +2 -2
- package/dist/outbound-api/auditCapture.d.cts +6 -0
- package/dist/outbound-api/auditCapture.d.ts +6 -0
- package/dist/outbound-api/auditCapture.js +1 -1
- package/dist/outbound-api/routeResolver.d.cts +1 -1
- package/dist/outbound-api/routeResolver.d.ts +1 -1
- package/dist/outbound-api/types.d.cts +1 -1
- package/dist/outbound-api/types.d.ts +1 -1
- package/dist/outbound-api.cjs +15 -13
- package/dist/outbound-api.d.cts +3 -2
- package/dist/outbound-api.d.ts +3 -2
- package/dist/outbound-api.js +14 -12
- package/dist/pipeline/AccountAllowanceScheduling.d.cts +1 -1
- package/dist/pipeline/AccountAllowanceScheduling.d.ts +1 -1
- package/dist/pipeline/executeProviderCall.d.cts +2 -0
- package/dist/pipeline/executeProviderCall.d.ts +2 -0
- package/dist/pipeline/resolveProviderChain.d.cts +1 -0
- package/dist/pipeline/resolveProviderChain.d.ts +1 -0
- package/dist/pipeline/resolveSubscriptionChain.d.cts +2 -0
- package/dist/pipeline/resolveSubscriptionChain.d.ts +2 -0
- package/dist/ports/provider-config-source.d.cts +1 -0
- package/dist/ports/provider-config-source.d.ts +1 -0
- package/dist/ports.d.cts +1 -1
- package/dist/ports.d.ts +1 -1
- package/dist/provider-proxy/ProviderProxy.cjs +15 -13
- package/dist/provider-proxy/ProviderProxy.js +14 -12
- package/dist/provider-proxy/ingress/providerProxyShared.cjs +15 -13
- package/dist/provider-proxy/ingress/providerProxyShared.js +14 -12
- package/dist/provider-proxy.cjs +15 -13
- package/dist/provider-proxy.js +14 -12
- package/dist/transformer/TransformerChainExecutor.d.cts +2 -0
- package/dist/transformer/TransformerChainExecutor.d.ts +2 -0
- package/dist/transformer/TransformerService.d.cts +2 -0
- package/dist/transformer/TransformerService.d.ts +2 -0
- package/dist/transformer/transformers/AnthropicTransformer.cjs +4 -2
- package/dist/transformer/transformers/AnthropicTransformer.d.cts +7 -2
- package/dist/transformer/transformers/AnthropicTransformer.d.ts +7 -2
- package/dist/transformer/transformers/AnthropicTransformer.js +3 -1
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.cjs +5 -3
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.d.cts +2 -0
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.d.ts +2 -0
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.js +4 -2
- package/dist/transformer/transformers/GeminiTransformer.cjs +5 -3
- package/dist/transformer/transformers/GeminiTransformer.d.cts +4 -2
- package/dist/transformer/transformers/GeminiTransformer.d.ts +4 -2
- package/dist/transformer/transformers/GeminiTransformer.js +4 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +3 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.d.cts +4 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.d.ts +4 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.js +2 -1
- package/dist/transformer/transformers/OpenAITransformer.cjs +3 -2
- package/dist/transformer/transformers/OpenAITransformer.d.cts +3 -1
- package/dist/transformer/transformers/OpenAITransformer.d.ts +3 -1
- package/dist/transformer/transformers/OpenAITransformer.js +2 -1
- package/dist/transformer/transformers.cjs +10 -8
- package/dist/transformer/transformers.d.cts +2 -0
- package/dist/transformer/transformers.d.ts +2 -0
- package/dist/transformer/transformers.js +9 -7
- package/dist/transformer/types.d.cts +16 -5
- package/dist/transformer/types.d.ts +16 -5
- package/dist/transformer.cjs +28 -9
- package/dist/transformer.d.cts +76 -1
- package/dist/transformer.d.ts +76 -1
- package/dist/transformer.js +28 -9
- package/dist/usage/usage-recorder.cjs +2 -2
- package/dist/usage/usage-recorder.d.cts +12 -2
- package/dist/usage/usage-recorder.d.ts +12 -2
- package/dist/usage/usage-recorder.js +1 -1
- package/dist/usage.cjs +20 -3
- package/dist/usage.d.cts +149 -0
- package/dist/usage.d.ts +149 -0
- package/dist/usage.js +20 -3
- package/package.json +2 -2
- package/dist/chunk-7VU7V2E4.js +0 -0
- package/dist/chunk-FZ46M34D.cjs +0 -1
- /package/dist/{chunk-EYZYXJTJ.cjs → chunk-QVOB2DNX.cjs} +0 -0
- /package/dist/{chunk-46RLHI7D.js → chunk-WTQMX2Q6.js} +0 -0
|
@@ -4,13 +4,13 @@ var _chunkHQP3K7PUcjs = require('./chunk-HQP3K7PU.cjs');
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkZQQUD66Mcjs = require('./chunk-ZQQUD66M.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunk5LNYGCIWcjs = require('./chunk-5LNYGCIW.cjs');
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _chunkCMVXX7ONcjs = require('./chunk-CMVXX7ON.cjs');
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
var _chunkIIRPUVPHcjs = require('./chunk-IIRPUVPH.cjs');
|
|
@@ -36,6 +36,8 @@ var _chunk6RPZADX3cjs = require('./chunk-6RPZADX3.cjs');
|
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
|
|
39
|
+
|
|
40
|
+
|
|
39
41
|
var _chunkJ3QQ6JS5cjs = require('./chunk-J3QQ6JS5.cjs');
|
|
40
42
|
|
|
41
43
|
|
|
@@ -104,13 +106,16 @@ var _chunkQBZJ7P2Tcjs = require('./chunk-QBZJ7P2T.cjs');
|
|
|
104
106
|
var _chunkA2YMUCBTcjs = require('./chunk-A2YMUCBT.cjs');
|
|
105
107
|
|
|
106
108
|
|
|
107
|
-
var
|
|
109
|
+
var _chunkUWDW6PN3cjs = require('./chunk-UWDW6PN3.cjs');
|
|
108
110
|
|
|
109
111
|
|
|
110
112
|
|
|
111
113
|
var _chunkGDIXXKF2cjs = require('./chunk-GDIXXKF2.cjs');
|
|
112
114
|
|
|
113
115
|
|
|
116
|
+
var _chunkAOFWNWLTcjs = require('./chunk-AOFWNWLT.cjs');
|
|
117
|
+
|
|
118
|
+
|
|
114
119
|
var _chunkRJUONLUQcjs = require('./chunk-RJUONLUQ.cjs');
|
|
115
120
|
|
|
116
121
|
|
|
@@ -413,9 +418,6 @@ function addOpenRouterProviderToRequest(requestBody, provider, modelId) {
|
|
|
413
418
|
};
|
|
414
419
|
}
|
|
415
420
|
|
|
416
|
-
// src/completion/DirectApiHandler.ts
|
|
417
|
-
var _thinkingconfig = require('@omnicross/contracts/thinking-config');
|
|
418
|
-
|
|
419
421
|
// src/provider-proxy/ProviderProxy.ts
|
|
420
422
|
var _http = require('http'); var _http2 = _interopRequireDefault(_http);
|
|
421
423
|
|
|
@@ -651,17 +653,17 @@ function getSharedExecutor() {
|
|
|
651
653
|
}
|
|
652
654
|
var sharedResponses = null;
|
|
653
655
|
function getResponsesEndpointTransformer() {
|
|
654
|
-
if (!sharedResponses) sharedResponses = new (0,
|
|
656
|
+
if (!sharedResponses) sharedResponses = new (0, _chunkCMVXX7ONcjs.OpenAIResponseTransformer)();
|
|
655
657
|
return sharedResponses;
|
|
656
658
|
}
|
|
657
659
|
var sharedAnthropic = null;
|
|
658
660
|
function getAnthropicEndpointTransformer() {
|
|
659
|
-
if (!sharedAnthropic) sharedAnthropic = new (0,
|
|
661
|
+
if (!sharedAnthropic) sharedAnthropic = new (0, _chunkZQQUD66Mcjs.AnthropicTransformer)();
|
|
660
662
|
return sharedAnthropic;
|
|
661
663
|
}
|
|
662
664
|
var sharedGemini = null;
|
|
663
665
|
function getGeminiEndpointTransformer() {
|
|
664
|
-
if (!sharedGemini) sharedGemini = new (0,
|
|
666
|
+
if (!sharedGemini) sharedGemini = new (0, _chunk5LNYGCIWcjs.GeminiTransformer)();
|
|
665
667
|
return sharedGemini;
|
|
666
668
|
}
|
|
667
669
|
function readBody(req) {
|
|
@@ -1432,7 +1434,8 @@ async function buildByoPlan(res, route, deps, resolvedModel, isStream) {
|
|
|
1432
1434
|
name: provider.name,
|
|
1433
1435
|
baseUrl: provider.api_base_url,
|
|
1434
1436
|
apiKey,
|
|
1435
|
-
models: provider.models || []
|
|
1437
|
+
models: provider.models || [],
|
|
1438
|
+
modelConfigs: provider.modelConfigs
|
|
1436
1439
|
};
|
|
1437
1440
|
const byoUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: resolvedModel, stream: isStream });
|
|
1438
1441
|
const sameFormat = route.targetProviderFormat === "anthropic" || _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider) === "anthropic";
|
|
@@ -1740,7 +1743,8 @@ async function buildByoPlan2(res, route, deps, resolvedModel, isStream) {
|
|
|
1740
1743
|
name: provider.name,
|
|
1741
1744
|
baseUrl: provider.api_base_url,
|
|
1742
1745
|
apiKey,
|
|
1743
|
-
models: provider.models || []
|
|
1746
|
+
models: provider.models || [],
|
|
1747
|
+
modelConfigs: provider.modelConfigs
|
|
1744
1748
|
};
|
|
1745
1749
|
const byoUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: resolvedModel, stream: isStream });
|
|
1746
1750
|
return {
|
|
@@ -1957,7 +1961,8 @@ async function buildByoPlan3(res, route, deps, resolvedModel, isStream) {
|
|
|
1957
1961
|
name: provider.name,
|
|
1958
1962
|
baseUrl: provider.api_base_url,
|
|
1959
1963
|
apiKey,
|
|
1960
|
-
models: provider.models || []
|
|
1964
|
+
models: provider.models || [],
|
|
1965
|
+
modelConfigs: provider.modelConfigs
|
|
1961
1966
|
};
|
|
1962
1967
|
const byoUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: resolvedModel, stream: isStream });
|
|
1963
1968
|
return {
|
|
@@ -2351,7 +2356,8 @@ async function buildByoPlan4(res, route, deps, resolvedModel, isStream) {
|
|
|
2351
2356
|
name: provider.name,
|
|
2352
2357
|
baseUrl: provider.api_base_url,
|
|
2353
2358
|
apiKey,
|
|
2354
|
-
models: provider.models || []
|
|
2359
|
+
models: provider.models || [],
|
|
2360
|
+
modelConfigs: provider.modelConfigs
|
|
2355
2361
|
};
|
|
2356
2362
|
const byoUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: resolvedModel, stream: isStream });
|
|
2357
2363
|
return {
|
|
@@ -3562,6 +3568,7 @@ var KeyedMutex = (_class5 = class {constructor() { _class5.prototype.__init11.ca
|
|
|
3562
3568
|
|
|
3563
3569
|
// src/outbound-api/outboundApiRouter.ts
|
|
3564
3570
|
var _stream = require('stream');
|
|
3571
|
+
var _subscriptionmodelcatalog = require('@omnicross/contracts/subscription-model-catalog');
|
|
3565
3572
|
|
|
3566
3573
|
// src/outbound-api/apiServerConfig.ts
|
|
3567
3574
|
var _audittypes = require('@omnicross/contracts/audit-types');
|
|
@@ -3659,7 +3666,8 @@ function normalizeAudit(raw) {
|
|
|
3659
3666
|
retentionDays: Math.trunc(
|
|
3660
3667
|
clampNumber(_optionalChain([a, 'optionalAccess', _195 => _195.retentionDays]), 1, 365, _audittypes.DEFAULT_AUDIT_CONFIG.retentionDays)
|
|
3661
3668
|
),
|
|
3662
|
-
|
|
3669
|
+
compactStreamingBodies: _optionalChain([a, 'optionalAccess', _196 => _196.compactStreamingBodies]) === true,
|
|
3670
|
+
trustForwardedFor: _optionalChain([a, 'optionalAccess', _197 => _197.trustForwardedFor]) === true
|
|
3663
3671
|
};
|
|
3664
3672
|
}
|
|
3665
3673
|
function normalizeMaxBodyBytes(value) {
|
|
@@ -3670,26 +3678,26 @@ function normalizeMaxBodyBytes(value) {
|
|
|
3670
3678
|
return Math.trunc(Math.min(1048576, value));
|
|
3671
3679
|
}
|
|
3672
3680
|
function normalizeBilling(raw) {
|
|
3673
|
-
const b = _optionalChain([raw, 'optionalAccess',
|
|
3681
|
+
const b = _optionalChain([raw, 'optionalAccess', _198 => _198.billing]);
|
|
3674
3682
|
const config = {
|
|
3675
|
-
enabled: _optionalChain([b, 'optionalAccess',
|
|
3683
|
+
enabled: _optionalChain([b, 'optionalAccess', _199 => _199.enabled]) === true,
|
|
3676
3684
|
maxRetryAgeMs: Math.trunc(
|
|
3677
|
-
clampNumber(_optionalChain([b, 'optionalAccess',
|
|
3685
|
+
clampNumber(_optionalChain([b, 'optionalAccess', _200 => _200.maxRetryAgeMs]), 6e4, 2592e6, _billingtypes.DEFAULT_BILLING_CONFIG.maxRetryAgeMs)
|
|
3678
3686
|
)
|
|
3679
3687
|
};
|
|
3680
|
-
if (typeof _optionalChain([b, 'optionalAccess',
|
|
3681
|
-
if (typeof _optionalChain([b, 'optionalAccess',
|
|
3688
|
+
if (typeof _optionalChain([b, 'optionalAccess', _201 => _201.endpoint]) === "string" && b.endpoint.trim()) config.endpoint = b.endpoint.trim();
|
|
3689
|
+
if (typeof _optionalChain([b, 'optionalAccess', _202 => _202.secret]) === "string" && b.secret.length > 0) config.secret = b.secret;
|
|
3682
3690
|
return config;
|
|
3683
3691
|
}
|
|
3684
3692
|
var DEFAULT_FINGERPRINT = { enabled: false };
|
|
3685
3693
|
function normalizeFingerprint(raw) {
|
|
3686
|
-
const f = _optionalChain([raw, 'optionalAccess',
|
|
3687
|
-
const out = { enabled: _optionalChain([f, 'optionalAccess',
|
|
3688
|
-
if (typeof _optionalChain([f, 'optionalAccess',
|
|
3694
|
+
const f = _optionalChain([raw, 'optionalAccess', _203 => _203.fingerprint]);
|
|
3695
|
+
const out = { enabled: _optionalChain([f, 'optionalAccess', _204 => _204.enabled]) === true };
|
|
3696
|
+
if (typeof _optionalChain([f, 'optionalAccess', _205 => _205.ua]) === "string" && f.ua.trim().length > 0) out.ua = f.ua.trim();
|
|
3689
3697
|
return out;
|
|
3690
3698
|
}
|
|
3691
3699
|
function normalizeVoucher(raw) {
|
|
3692
|
-
return { enabled: _optionalChain([raw, 'optionalAccess',
|
|
3700
|
+
return { enabled: _optionalChain([raw, 'optionalAccess', _206 => _206.voucher, 'optionalAccess', _207 => _207.enabled]) === true };
|
|
3693
3701
|
}
|
|
3694
3702
|
var PROXY_TYPES = ["http", "https", "socks5"];
|
|
3695
3703
|
function normalizeProxyConfig(raw) {
|
|
@@ -3773,14 +3781,14 @@ function clampNumber(value, min, max, fallback) {
|
|
|
3773
3781
|
return Math.min(max, Math.max(min, n));
|
|
3774
3782
|
}
|
|
3775
3783
|
function normalizeQueueSegments(raw) {
|
|
3776
|
-
const umq = _optionalChain([raw, 'optionalAccess',
|
|
3777
|
-
const cq = _optionalChain([raw, 'optionalAccess',
|
|
3784
|
+
const umq = _optionalChain([raw, 'optionalAccess', _208 => _208.userMessageQueue]);
|
|
3785
|
+
const cq = _optionalChain([raw, 'optionalAccess', _209 => _209.concurrencyQueue]);
|
|
3778
3786
|
return {
|
|
3779
3787
|
userMessageQueue: {
|
|
3780
|
-
enabled: _optionalChain([umq, 'optionalAccess',
|
|
3781
|
-
delayMs: clampNumber(_optionalChain([umq, 'optionalAccess',
|
|
3788
|
+
enabled: _optionalChain([umq, 'optionalAccess', _210 => _210.enabled]) === true,
|
|
3789
|
+
delayMs: clampNumber(_optionalChain([umq, 'optionalAccess', _211 => _211.delayMs]), 0, 1e4, DEFAULT_USER_MESSAGE_QUEUE.delayMs),
|
|
3782
3790
|
waitTimeoutMs: clampNumber(
|
|
3783
|
-
_optionalChain([umq, 'optionalAccess',
|
|
3791
|
+
_optionalChain([umq, 'optionalAccess', _212 => _212.waitTimeoutMs]),
|
|
3784
3792
|
1e3,
|
|
3785
3793
|
3e5,
|
|
3786
3794
|
DEFAULT_USER_MESSAGE_QUEUE.waitTimeoutMs
|
|
@@ -3788,14 +3796,14 @@ function normalizeQueueSegments(raw) {
|
|
|
3788
3796
|
},
|
|
3789
3797
|
concurrencyQueue: {
|
|
3790
3798
|
maxQueueSizeFactor: clampNumber(
|
|
3791
|
-
_optionalChain([cq, 'optionalAccess',
|
|
3799
|
+
_optionalChain([cq, 'optionalAccess', _213 => _213.maxQueueSizeFactor]),
|
|
3792
3800
|
1,
|
|
3793
3801
|
10,
|
|
3794
3802
|
DEFAULT_CONCURRENCY_QUEUE.maxQueueSizeFactor
|
|
3795
3803
|
),
|
|
3796
|
-
minQueueSize: clampNumber(_optionalChain([cq, 'optionalAccess',
|
|
3804
|
+
minQueueSize: clampNumber(_optionalChain([cq, 'optionalAccess', _214 => _214.minQueueSize]), 1, 100, DEFAULT_CONCURRENCY_QUEUE.minQueueSize),
|
|
3797
3805
|
waitTimeoutMs: clampNumber(
|
|
3798
|
-
_optionalChain([cq, 'optionalAccess',
|
|
3806
|
+
_optionalChain([cq, 'optionalAccess', _215 => _215.waitTimeoutMs]),
|
|
3799
3807
|
1e3,
|
|
3800
3808
|
3e5,
|
|
3801
3809
|
DEFAULT_CONCURRENCY_QUEUE.waitTimeoutMs
|
|
@@ -3908,7 +3916,7 @@ function normalizeGatewayModelMappings(raw) {
|
|
|
3908
3916
|
return mappings;
|
|
3909
3917
|
}
|
|
3910
3918
|
function hasConfiguredLegacyModels(config) {
|
|
3911
|
-
return Object.values(_nullishCoalesce(config.modelMap, () => ( {}))).some((value) => typeof value === "string" && value.trim()) || Boolean(_optionalChain([config, 'access',
|
|
3919
|
+
return Object.values(_nullishCoalesce(config.modelMap, () => ( {}))).some((value) => typeof value === "string" && value.trim()) || Boolean(_optionalChain([config, 'access', _216 => _216.models, 'optionalAccess', _217 => _217.some, 'call', _218 => _218((value) => typeof value === "string" && value.trim())])) || Boolean(_optionalChain([config, 'access', _219 => _219.defaultModel, 'optionalAccess', _220 => _220.trim, 'call', _221 => _221()])) || Boolean(_optionalChain([config, 'access', _222 => _222.backgroundModel, 'optionalAccess', _223 => _223.trim, 'call', _224 => _224()])) || Boolean(Object.values(_nullishCoalesce(config.prefixTargets, () => ( {}))).some((value) => _optionalChain([value, 'optionalAccess', _225 => _225.trim, 'call', _226 => _226()])));
|
|
3912
3920
|
}
|
|
3913
3921
|
function splitModelRef(ref) {
|
|
3914
3922
|
if (typeof ref !== "string") return null;
|
|
@@ -3976,7 +3984,7 @@ function legacyEndpointToBindings(config) {
|
|
|
3976
3984
|
if (!parsed) continue;
|
|
3977
3985
|
const route = routeFor(parsed.providerId);
|
|
3978
3986
|
route[field] = ref;
|
|
3979
|
-
if (_optionalChain([config, 'access',
|
|
3987
|
+
if (_optionalChain([config, 'access', _227 => _227.backgroundModelIds, 'optionalAccess', _228 => _228.length])) {
|
|
3980
3988
|
route.backgroundModelIds = [...config.backgroundModelIds];
|
|
3981
3989
|
}
|
|
3982
3990
|
}
|
|
@@ -4126,6 +4134,60 @@ function mergeServerConfig(current, patch) {
|
|
|
4126
4134
|
});
|
|
4127
4135
|
}
|
|
4128
4136
|
|
|
4137
|
+
// src/outbound-api/auditSessionKey.ts
|
|
4138
|
+
|
|
4139
|
+
var EXPLICIT_ID_SOURCES = /* @__PURE__ */ new Set([
|
|
4140
|
+
"session-header",
|
|
4141
|
+
"thread-header",
|
|
4142
|
+
"body-session-id",
|
|
4143
|
+
"body-thread-id",
|
|
4144
|
+
"prompt-cache-key"
|
|
4145
|
+
]);
|
|
4146
|
+
var ANTHROPIC_SESSION_RE = /_session_([A-Za-z0-9][A-Za-z0-9_-]{7,})/;
|
|
4147
|
+
var DIGEST_HEX = 32;
|
|
4148
|
+
function stableDigest(value) {
|
|
4149
|
+
return _crypto.createHash.call(void 0, "sha256").update(value, "utf8").digest("hex").slice(0, DIGEST_HEX);
|
|
4150
|
+
}
|
|
4151
|
+
function asObject(value) {
|
|
4152
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
4153
|
+
}
|
|
4154
|
+
function anthropicSessionId(body) {
|
|
4155
|
+
const userId = _optionalChain([asObject, 'call', _229 => _229(body["metadata"]), 'optionalAccess', _230 => _230["user_id"]]);
|
|
4156
|
+
if (typeof userId !== "string" || !userId) return void 0;
|
|
4157
|
+
const matched = ANTHROPIC_SESSION_RE.exec(userId);
|
|
4158
|
+
return _optionalChain([matched, 'optionalAccess', _231 => _231[1]]);
|
|
4159
|
+
}
|
|
4160
|
+
function anthropicContentFingerprint(body) {
|
|
4161
|
+
const messages = body["messages"];
|
|
4162
|
+
if (!Array.isArray(messages) || messages.length === 0) return void 0;
|
|
4163
|
+
const parts = [];
|
|
4164
|
+
const system = _chunkJ3QQ6JS5cjs.flattenMatchText.call(void 0, body["system"]).trim();
|
|
4165
|
+
if (system) parts.push(system.slice(0, _chunkJ3QQ6JS5cjs.MATCH_TEXT_PER_MESSAGE_CAP));
|
|
4166
|
+
let firstUser = "";
|
|
4167
|
+
for (const entry of messages) {
|
|
4168
|
+
const message = asObject(entry);
|
|
4169
|
+
if (!message || message["role"] !== "user") continue;
|
|
4170
|
+
const text = _chunkJ3QQ6JS5cjs.flattenMatchText.call(void 0, message["content"]).trim();
|
|
4171
|
+
if (!text) continue;
|
|
4172
|
+
firstUser = text.slice(0, _chunkJ3QQ6JS5cjs.MATCH_TEXT_PER_MESSAGE_CAP);
|
|
4173
|
+
break;
|
|
4174
|
+
}
|
|
4175
|
+
if (parts.length === 0 && !firstUser) return void 0;
|
|
4176
|
+
return `${parts.join("\0")}\0${firstUser}`;
|
|
4177
|
+
}
|
|
4178
|
+
function deriveAuditSessionKey(body, headers = {}, options = {}) {
|
|
4179
|
+
const anthropicSession = anthropicSessionId(body);
|
|
4180
|
+
if (anthropicSession) return stableDigest(`anthropic-session\0${anthropicSession}`);
|
|
4181
|
+
const gateway = _chunkJ3QQ6JS5cjs.deriveGatewaySessionKey.call(void 0, body, headers, {
|
|
4182
|
+
...options.fallbackKey !== void 0 ? { fallbackKey: options.fallbackKey } : {},
|
|
4183
|
+
...options.endpoint !== void 0 ? { endpoint: options.endpoint } : {}
|
|
4184
|
+
});
|
|
4185
|
+
if (EXPLICIT_ID_SOURCES.has(gateway.source)) return gateway.key;
|
|
4186
|
+
const fingerprint = anthropicContentFingerprint(body);
|
|
4187
|
+
if (fingerprint) return stableDigest(`anthropic-content\0${fingerprint}`);
|
|
4188
|
+
return gateway.key;
|
|
4189
|
+
}
|
|
4190
|
+
|
|
4129
4191
|
// src/outbound-api/outboundApiKeyAuth.ts
|
|
4130
4192
|
|
|
4131
4193
|
|
|
@@ -4488,8 +4550,8 @@ var OutboundRateLimiter = (_class10 = class {
|
|
|
4488
4550
|
* recorded (no bucket growth).
|
|
4489
4551
|
*/
|
|
4490
4552
|
check(apiKeyId, now = Date.now(), override) {
|
|
4491
|
-
const maxRequests = _nullishCoalesce(_optionalChain([override, 'optionalAccess',
|
|
4492
|
-
const windowMs = _nullishCoalesce(_optionalChain([override, 'optionalAccess',
|
|
4553
|
+
const maxRequests = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _232 => _232.maxRequests]), () => ( this.maxRequests));
|
|
4554
|
+
const windowMs = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _233 => _233.windowMs]), () => ( this.windowMs));
|
|
4493
4555
|
if (maxRequests === 0) return { allowed: true, retryAfterSeconds: 0 };
|
|
4494
4556
|
const cutoff = now - windowMs;
|
|
4495
4557
|
const timestamps = (_nullishCoalesce(this.hits.get(apiKeyId), () => ( []))).filter((ts) => ts > cutoff);
|
|
@@ -4520,7 +4582,7 @@ var OutboundRateLimiter = (_class10 = class {
|
|
|
4520
4582
|
function asArray(v) {
|
|
4521
4583
|
return Array.isArray(v) ? v : [];
|
|
4522
4584
|
}
|
|
4523
|
-
function
|
|
4585
|
+
function asObject2(v) {
|
|
4524
4586
|
return v !== null && typeof v === "object" && !Array.isArray(v) ? v : null;
|
|
4525
4587
|
}
|
|
4526
4588
|
function last(arr) {
|
|
@@ -4528,13 +4590,13 @@ function last(arr) {
|
|
|
4528
4590
|
}
|
|
4529
4591
|
function isUserMessageAnthropic(body) {
|
|
4530
4592
|
const messages = asArray(body["messages"]);
|
|
4531
|
-
const lastMsg =
|
|
4593
|
+
const lastMsg = asObject2(last(messages));
|
|
4532
4594
|
if (!lastMsg || lastMsg["role"] !== "user") return false;
|
|
4533
4595
|
const content = lastMsg["content"];
|
|
4534
4596
|
if (typeof content === "string") return true;
|
|
4535
4597
|
if (Array.isArray(content)) {
|
|
4536
4598
|
const hasToolResult = content.some(
|
|
4537
|
-
(block) => _optionalChain([
|
|
4599
|
+
(block) => _optionalChain([asObject2, 'call', _234 => _234(block), 'optionalAccess', _235 => _235["type"]]) === "tool_result"
|
|
4538
4600
|
);
|
|
4539
4601
|
return !hasToolResult;
|
|
4540
4602
|
}
|
|
@@ -4544,7 +4606,7 @@ function isUserMessageResponses(body) {
|
|
|
4544
4606
|
const input = body["input"];
|
|
4545
4607
|
if (typeof input === "string") return input.length > 0;
|
|
4546
4608
|
if (Array.isArray(input)) {
|
|
4547
|
-
const lastItem =
|
|
4609
|
+
const lastItem = asObject2(last(input));
|
|
4548
4610
|
if (!lastItem) return false;
|
|
4549
4611
|
if (lastItem["type"] === "function_call_output") return false;
|
|
4550
4612
|
return lastItem["role"] === "user";
|
|
@@ -4553,22 +4615,22 @@ function isUserMessageResponses(body) {
|
|
|
4553
4615
|
}
|
|
4554
4616
|
function isUserMessageChat(body) {
|
|
4555
4617
|
const messages = asArray(body["messages"]);
|
|
4556
|
-
const lastMsg =
|
|
4618
|
+
const lastMsg = asObject2(last(messages));
|
|
4557
4619
|
if (!lastMsg) return false;
|
|
4558
4620
|
return lastMsg["role"] === "user";
|
|
4559
4621
|
}
|
|
4560
4622
|
function isUserMessageGemini(body) {
|
|
4561
4623
|
const contents = asArray(body["contents"]);
|
|
4562
|
-
const lastContent =
|
|
4624
|
+
const lastContent = asObject2(last(contents));
|
|
4563
4625
|
if (!lastContent || lastContent["role"] !== "user") return false;
|
|
4564
4626
|
const parts = asArray(lastContent["parts"]);
|
|
4565
4627
|
const hasFunctionResponse = parts.some(
|
|
4566
|
-
(part) => _optionalChain([
|
|
4628
|
+
(part) => _optionalChain([asObject2, 'call', _236 => _236(part), 'optionalAccess', _237 => _237["functionResponse"]]) !== void 0
|
|
4567
4629
|
);
|
|
4568
4630
|
return !hasFunctionResponse;
|
|
4569
4631
|
}
|
|
4570
4632
|
function isUserMessageRequest(endpoint, parsedBody) {
|
|
4571
|
-
const body =
|
|
4633
|
+
const body = asObject2(parsedBody);
|
|
4572
4634
|
if (!body) return false;
|
|
4573
4635
|
switch (endpoint) {
|
|
4574
4636
|
case "messages":
|
|
@@ -4737,14 +4799,14 @@ function newVoucherId() {
|
|
|
4737
4799
|
}
|
|
4738
4800
|
function computeVoucherGrant(voucher, currentKey, now) {
|
|
4739
4801
|
if (voucher.type === "credit") {
|
|
4740
|
-
const current = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess',
|
|
4802
|
+
const current = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _238 => _238.totalCostLimitUsd]), () => ( 0));
|
|
4741
4803
|
let granted2 = current + (_nullishCoalesce(voucher.creditUsd, () => ( 0)));
|
|
4742
4804
|
if (voucher.maxTotalCostLimitUsd != null) {
|
|
4743
4805
|
granted2 = Math.min(granted2, voucher.maxTotalCostLimitUsd);
|
|
4744
4806
|
}
|
|
4745
4807
|
return { totalCostLimitUsd: granted2 };
|
|
4746
4808
|
}
|
|
4747
|
-
const currentExpiry = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess',
|
|
4809
|
+
const currentExpiry = _nullishCoalesce(_optionalChain([currentKey, 'optionalAccess', _239 => _239.expiresAt]), () => ( now));
|
|
4748
4810
|
let granted = currentExpiry + (_nullishCoalesce(voucher.renewalDays, () => ( 0))) * DAY_MS2;
|
|
4749
4811
|
if (voucher.maxExpiryDays != null) {
|
|
4750
4812
|
granted = Math.min(granted, now + voucher.maxExpiryDays * DAY_MS2);
|
|
@@ -4775,7 +4837,7 @@ function toVoucherInfo(v) {
|
|
|
4775
4837
|
// src/outbound-api/voucherRedeem.ts
|
|
4776
4838
|
function isRedeemRequest(method, url) {
|
|
4777
4839
|
if (method !== "POST" || !url) return false;
|
|
4778
|
-
const path = _nullishCoalesce(_optionalChain([url, 'access',
|
|
4840
|
+
const path = _nullishCoalesce(_optionalChain([url, 'access', _240 => _240.split, 'call', _241 => _241("?"), 'access', _242 => _242[0], 'optionalAccess', _243 => _243.replace, 'call', _244 => _244(/\/+$/, "")]), () => ( ""));
|
|
4779
4841
|
return path.endsWith("/redeem");
|
|
4780
4842
|
}
|
|
4781
4843
|
function writeErr(res, status, message, headers = {}) {
|
|
@@ -4805,8 +4867,8 @@ function grantToResult(type, granted) {
|
|
|
4805
4867
|
function currentResult(type, keyRow) {
|
|
4806
4868
|
const result = { type };
|
|
4807
4869
|
if (type === "credit") {
|
|
4808
|
-
if (_optionalChain([keyRow, 'optionalAccess',
|
|
4809
|
-
} else if (_optionalChain([keyRow, 'optionalAccess',
|
|
4870
|
+
if (_optionalChain([keyRow, 'optionalAccess', _245 => _245.totalCostLimitUsd]) != null) result.totalCostLimitUsd = keyRow.totalCostLimitUsd;
|
|
4871
|
+
} else if (_optionalChain([keyRow, 'optionalAccess', _246 => _246.expiresAt]) != null) {
|
|
4810
4872
|
result.expiresAt = keyRow.expiresAt;
|
|
4811
4873
|
}
|
|
4812
4874
|
return result;
|
|
@@ -4893,7 +4955,7 @@ async function handleVoucherRedeem(req, res, deps, voucherEnabled, redeemLimiter
|
|
|
4893
4955
|
const won = await voucherDb.voucherRedeemCas(voucher.id, verifiedKeyId, absolute, now);
|
|
4894
4956
|
if (!won) {
|
|
4895
4957
|
const after = await voucherDb.voucherGetByHash(codeHash);
|
|
4896
|
-
if (_optionalChain([after, 'optionalAccess',
|
|
4958
|
+
if (_optionalChain([after, 'optionalAccess', _247 => _247.status]) === "redeemed" && after.redeemedByKeyId === verifiedKeyId) {
|
|
4897
4959
|
return after.grantApplied === true ? { ok: true, result: currentResult(after.type, await deps.db.outboundApiKeysGetByHash(keyHash)) } : await applyFirstPass(after, recordedAbsolute(after));
|
|
4898
4960
|
}
|
|
4899
4961
|
return { ok: false, status: 409, message: "Code was already redeemed" };
|
|
@@ -4954,10 +5016,10 @@ function extractPresentedKey(req) {
|
|
|
4954
5016
|
}
|
|
4955
5017
|
const xApiKey = req.headers["x-api-key"];
|
|
4956
5018
|
const xApi = Array.isArray(xApiKey) ? xApiKey[0] : xApiKey;
|
|
4957
|
-
if (_optionalChain([xApi, 'optionalAccess',
|
|
5019
|
+
if (_optionalChain([xApi, 'optionalAccess', _248 => _248.trim, 'call', _249 => _249()])) return xApi.trim();
|
|
4958
5020
|
const goog = req.headers["x-goog-api-key"];
|
|
4959
5021
|
const g = Array.isArray(goog) ? goog[0] : goog;
|
|
4960
|
-
return _optionalChain([g, 'optionalAccess',
|
|
5022
|
+
return _optionalChain([g, 'optionalAccess', _250 => _250.trim, 'call', _251 => _251()]) || void 0;
|
|
4961
5023
|
}
|
|
4962
5024
|
function isLoopbackPeer(address) {
|
|
4963
5025
|
if (!address) return false;
|
|
@@ -4966,7 +5028,7 @@ function isLoopbackPeer(address) {
|
|
|
4966
5028
|
}
|
|
4967
5029
|
function selectEndpoint(method, url) {
|
|
4968
5030
|
if (method !== "POST" || !url) return null;
|
|
4969
|
-
const path = _nullishCoalesce(_optionalChain([url, 'access',
|
|
5031
|
+
const path = _nullishCoalesce(_optionalChain([url, 'access', _252 => _252.split, 'call', _253 => _253("?"), 'access', _254 => _254[0], 'optionalAccess', _255 => _255.replace, 'call', _256 => _256(/\/+$/, "")]), () => ( ""));
|
|
4970
5032
|
if (path.endsWith("/chat/completions")) return "chat";
|
|
4971
5033
|
if (path.endsWith("/responses")) return "responses";
|
|
4972
5034
|
if (path.includes("/v1/messages")) return "messages";
|
|
@@ -4984,36 +5046,54 @@ function extractGeminiModelFromUrl(url) {
|
|
|
4984
5046
|
}
|
|
4985
5047
|
function isModelsListRequest(url) {
|
|
4986
5048
|
if (!url) return false;
|
|
4987
|
-
const path = _nullishCoalesce(_optionalChain([url, 'access',
|
|
5049
|
+
const path = _nullishCoalesce(_optionalChain([url, 'access', _257 => _257.split, 'call', _258 => _258("?"), 'access', _259 => _259[0], 'optionalAccess', _260 => _260.replace, 'call', _261 => _261(/\/+$/, "")]), () => ( ""));
|
|
4988
5050
|
return path.endsWith("/models");
|
|
4989
5051
|
}
|
|
4990
|
-
function writeModelsList(res, config, apiKeyId, allowedEndpoints) {
|
|
4991
|
-
const
|
|
4992
|
-
const endpointConfigs = [];
|
|
5052
|
+
async function writeModelsList(res, llmConfig, config, apiKeyId, allowedEndpoints) {
|
|
5053
|
+
const modelIds = [];
|
|
4993
5054
|
for (const endpoint of ["chat", "responses", "messages", "gemini"]) {
|
|
4994
5055
|
if (allowedEndpoints && !allowedEndpoints.includes(endpoint)) continue;
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
(binding
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5056
|
+
for (const binding of candidateGatewayBindings(config.bindings, apiKeyId, endpoint)) {
|
|
5057
|
+
if (binding.modelMode === "passthrough") {
|
|
5058
|
+
if (binding.target.kind === "provider") {
|
|
5059
|
+
const provider = await llmConfig.getProvider(binding.target.providerId);
|
|
5060
|
+
modelIds.push(..._nullishCoalesce(_optionalChain([provider, 'optionalAccess', _262 => _262.models]), () => ( [])));
|
|
5061
|
+
} else if (Object.prototype.hasOwnProperty.call(
|
|
5062
|
+
_subscriptionmodelcatalog.SUBSCRIPTION_MODEL_CATALOG,
|
|
5063
|
+
binding.target.providerId
|
|
5064
|
+
)) {
|
|
5065
|
+
modelIds.push(
|
|
5066
|
+
..._subscriptionmodelcatalog.SUBSCRIPTION_MODEL_CATALOG[binding.target.providerId]
|
|
5067
|
+
);
|
|
5068
|
+
}
|
|
5069
|
+
continue;
|
|
5070
|
+
}
|
|
5071
|
+
if (_optionalChain([binding, 'access', _263 => _263.modelMappings, 'optionalAccess', _264 => _264.length])) {
|
|
5072
|
+
modelIds.push(
|
|
5073
|
+
...binding.modelMappings.map((mapping) => mapping.source.trim()).filter((source) => source !== "" && !source.includes("*"))
|
|
5074
|
+
);
|
|
5075
|
+
continue;
|
|
5076
|
+
}
|
|
5077
|
+
const endpointConfig = gatewayBindingToEndpointConfig(binding);
|
|
5078
|
+
const refs = [];
|
|
5079
|
+
if (endpointConfig.endpoint === "chat") refs.push(..._nullishCoalesce(endpointConfig.models, () => ( [])));
|
|
5080
|
+
else if (endpointConfig.endpoint === "messages" || endpointConfig.endpoint === "responses") {
|
|
5081
|
+
refs.push(...Object.values(_nullishCoalesce(endpointConfig.modelMap, () => ( {}))));
|
|
5082
|
+
} else {
|
|
5083
|
+
if (endpointConfig.defaultModel) refs.push(endpointConfig.defaultModel);
|
|
5084
|
+
if (endpointConfig.backgroundModel) refs.push(endpointConfig.backgroundModel);
|
|
5085
|
+
}
|
|
5086
|
+
modelIds.push(
|
|
5087
|
+
...refs.map((ref) => _optionalChain([_chunk4VZX5F4Tcjs.parseModelRef.call(void 0, ref), 'optionalAccess', _265 => _265.modelId])).filter((modelId) => modelId !== void 0)
|
|
5088
|
+
);
|
|
5009
5089
|
}
|
|
5010
5090
|
}
|
|
5011
5091
|
const seen = /* @__PURE__ */ new Set();
|
|
5012
|
-
const data =
|
|
5013
|
-
if (seen.has(
|
|
5014
|
-
seen.add(
|
|
5092
|
+
const data = modelIds.filter((modelId) => {
|
|
5093
|
+
if (seen.has(modelId)) return false;
|
|
5094
|
+
seen.add(modelId);
|
|
5015
5095
|
return true;
|
|
5016
|
-
}).map((
|
|
5096
|
+
}).map((modelId) => ({ id: modelId, object: "model", owned_by: "omnicross" }));
|
|
5017
5097
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
5018
5098
|
res.end(JSON.stringify({ object: "list", data }));
|
|
5019
5099
|
}
|
|
@@ -5032,7 +5112,7 @@ function shimAuthHeader(req, routeToken) {
|
|
|
5032
5112
|
}
|
|
5033
5113
|
async function handleOutboundRequest(req, res, deps, config, rateLimiter, serialQueue, concurrencyGate, redeemLimiter, redeemMutex) {
|
|
5034
5114
|
const now = Date.now();
|
|
5035
|
-
const audit =
|
|
5115
|
+
const audit = _chunkUWDW6PN3cjs.beginAuditCapture.call(void 0, req, res, now);
|
|
5036
5116
|
const billing = _chunkAPYG5QD7cjs.beginBillingCapture.call(void 0, req, res, now);
|
|
5037
5117
|
const presented = extractPresentedKey(req);
|
|
5038
5118
|
const verification = await verifyKey(deps.db, presented, now);
|
|
@@ -5047,7 +5127,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
5047
5127
|
const verified = verification.key;
|
|
5048
5128
|
if (audit) audit.keyId = verified.id;
|
|
5049
5129
|
if (billing) billing.keyId = verified.id;
|
|
5050
|
-
if (verified.loopbackOnly && !isLoopbackPeer(_optionalChain([req, 'access',
|
|
5130
|
+
if (verified.loopbackOnly && !isLoopbackPeer(_optionalChain([req, 'access', _266 => _266.socket, 'optionalAccess', _267 => _267.remoteAddress]))) {
|
|
5051
5131
|
writeJsonError(res, 403, "This integration key is restricted to loopback clients");
|
|
5052
5132
|
return;
|
|
5053
5133
|
}
|
|
@@ -5060,7 +5140,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
5060
5140
|
req,
|
|
5061
5141
|
res,
|
|
5062
5142
|
deps,
|
|
5063
|
-
_optionalChain([config, 'access',
|
|
5143
|
+
_optionalChain([config, 'access', _268 => _268.voucher, 'optionalAccess', _269 => _269.enabled]) === true,
|
|
5064
5144
|
_nullishCoalesce(redeemLimiter, () => ( getFallbackRedeemLimiter())),
|
|
5065
5145
|
verified.id,
|
|
5066
5146
|
_nullishCoalesce(presented, () => ( "")),
|
|
@@ -5081,7 +5161,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
5081
5161
|
writeJsonError(res, 403, "API key is not allowed to access this endpoint");
|
|
5082
5162
|
return;
|
|
5083
5163
|
}
|
|
5084
|
-
writeModelsList(res, config, verified.id, verified.allowedEndpoints);
|
|
5164
|
+
await writeModelsList(res, deps.llmConfig, config, verified.id, verified.allowedEndpoints);
|
|
5085
5165
|
return;
|
|
5086
5166
|
}
|
|
5087
5167
|
const endpoint = selectEndpoint(req.method, req.url);
|
|
@@ -5162,7 +5242,13 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
5162
5242
|
writeJsonError(res, 400, "Invalid JSON in request body");
|
|
5163
5243
|
return;
|
|
5164
5244
|
}
|
|
5165
|
-
if (audit)
|
|
5245
|
+
if (audit) {
|
|
5246
|
+
audit.setRequestBody(rawBody);
|
|
5247
|
+
audit.sessionKey = deriveAuditSessionKey(parsedBody, req.headers, {
|
|
5248
|
+
fallbackKey: verified.id,
|
|
5249
|
+
endpoint
|
|
5250
|
+
});
|
|
5251
|
+
}
|
|
5166
5252
|
if (endpoint === "gemini" && typeof parsedBody["model"] !== "string") {
|
|
5167
5253
|
const urlModel = extractGeminiModelFromUrl(req.url);
|
|
5168
5254
|
if (urlModel) parsedBody["model"] = urlModel;
|
|
@@ -5229,7 +5315,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
5229
5315
|
}
|
|
5230
5316
|
let releaseSerial = null;
|
|
5231
5317
|
const providerKey = resolved.route.providerId;
|
|
5232
|
-
if (_optionalChain([config, 'access',
|
|
5318
|
+
if (_optionalChain([config, 'access', _270 => _270.userMessageQueue, 'optionalAccess', _271 => _271.enabled]) && providerKey && isUserMessageRequest(endpoint, parsedBody)) {
|
|
5233
5319
|
const umq = config.userMessageQueue;
|
|
5234
5320
|
try {
|
|
5235
5321
|
const serialSlot = await serialQueue.acquire(providerKey, {
|
|
@@ -5369,7 +5455,7 @@ var OutboundApiServer = (_class13 = class {
|
|
|
5369
5455
|
const actualPort = await this.listen(bindAddr, port);
|
|
5370
5456
|
this.boundAddr = bindAddr;
|
|
5371
5457
|
this.boundPort = actualPort;
|
|
5372
|
-
if (actualPort !== port) _optionalChain([this, 'access',
|
|
5458
|
+
if (actualPort !== port) _optionalChain([this, 'access', _272 => _272.onPortChange, 'optionalCall', _273 => _273(actualPort)]);
|
|
5373
5459
|
this.logInfo(`[OutboundApiServer] Listening on ${bindAddr}:${actualPort}`);
|
|
5374
5460
|
return actualPort;
|
|
5375
5461
|
}
|
|
@@ -5438,7 +5524,7 @@ var OutboundApiServer = (_class13 = class {
|
|
|
5438
5524
|
const provider = this.deps.healthReportProvider;
|
|
5439
5525
|
if (!provider) return false;
|
|
5440
5526
|
if (req.method !== "GET" && req.method !== "HEAD") return false;
|
|
5441
|
-
const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access',
|
|
5527
|
+
const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access', _274 => _274.split, 'call', _275 => _275("?"), 'access', _276 => _276[0], 'optionalAccess', _277 => _277.replace, 'call', _278 => _278(/\/+$/, "")]) || "/";
|
|
5442
5528
|
if (path !== "/health" && path !== "/healthz") return false;
|
|
5443
5529
|
const report = provider();
|
|
5444
5530
|
res.writeHead(_healthloggingtypes.healthHttpStatus.call(void 0, report.status), { "Content-Type": "application/json" });
|
|
@@ -5637,6 +5723,70 @@ function __resetOutboundApiServerForTests() {
|
|
|
5637
5723
|
instance2 = null;
|
|
5638
5724
|
}
|
|
5639
5725
|
|
|
5726
|
+
// src/completion/ReasoningRequestBuilder.ts
|
|
5727
|
+
var LEGACY_ANTHROPIC_MAX_TOKENS = 16384;
|
|
5728
|
+
function intentFromOptions(options) {
|
|
5729
|
+
return options.thinkLevel ? { effort: options.thinkLevel, enabled: options.thinkLevel !== "none" } : void 0;
|
|
5730
|
+
}
|
|
5731
|
+
function resolveCompletionReasoningPlan(provider, options, target, requestMaxTokens = options.maxTokens) {
|
|
5732
|
+
return _chunkAOFWNWLTcjs.resolveReasoningPlan.call(void 0, {
|
|
5733
|
+
intent: intentFromOptions(options),
|
|
5734
|
+
model: options.model,
|
|
5735
|
+
provider,
|
|
5736
|
+
target,
|
|
5737
|
+
requestMaxTokens
|
|
5738
|
+
});
|
|
5739
|
+
}
|
|
5740
|
+
function resolveOpenAIEffort(provider, options, target) {
|
|
5741
|
+
const plan = resolveCompletionReasoningPlan(provider, options, target);
|
|
5742
|
+
return _optionalChain([plan, 'optionalAccess', _279 => _279.kind]) === "level" && plan.enabled ? plan.effort : void 0;
|
|
5743
|
+
}
|
|
5744
|
+
function buildAnthropicReasoningWire(provider, options) {
|
|
5745
|
+
const configuredMaxTokens = _nullishCoalesce(options.maxTokens, () => ( LEGACY_ANTHROPIC_MAX_TOKENS));
|
|
5746
|
+
const legacyBound = Math.min(configuredMaxTokens, LEGACY_ANTHROPIC_MAX_TOKENS);
|
|
5747
|
+
const plan = resolveCompletionReasoningPlan(
|
|
5748
|
+
provider,
|
|
5749
|
+
options,
|
|
5750
|
+
"anthropic",
|
|
5751
|
+
legacyBound
|
|
5752
|
+
);
|
|
5753
|
+
if (_optionalChain([plan, 'optionalAccess', _280 => _280.kind]) === "level" && plan.enabled) {
|
|
5754
|
+
return {
|
|
5755
|
+
effectiveMaxTokens: configuredMaxTokens,
|
|
5756
|
+
thinking: { type: "adaptive" },
|
|
5757
|
+
outputConfig: { effort: plan.effort },
|
|
5758
|
+
legacyBudgetEnabled: false
|
|
5759
|
+
};
|
|
5760
|
+
}
|
|
5761
|
+
if (_optionalChain([plan, 'optionalAccess', _281 => _281.kind]) === "budget" && plan.enabled) {
|
|
5762
|
+
return {
|
|
5763
|
+
effectiveMaxTokens: legacyBound,
|
|
5764
|
+
thinking: { type: "enabled", budget_tokens: plan.budgetTokens },
|
|
5765
|
+
legacyBudgetEnabled: true
|
|
5766
|
+
};
|
|
5767
|
+
}
|
|
5768
|
+
return {
|
|
5769
|
+
effectiveMaxTokens: configuredMaxTokens,
|
|
5770
|
+
legacyBudgetEnabled: false
|
|
5771
|
+
};
|
|
5772
|
+
}
|
|
5773
|
+
function buildGeminiThinkingConfig(provider, options) {
|
|
5774
|
+
const plan = resolveCompletionReasoningPlan(provider, options, "gemini");
|
|
5775
|
+
if (_optionalChain([plan, 'optionalAccess', _282 => _282.kind]) === "level") {
|
|
5776
|
+
return {
|
|
5777
|
+
includeThoughts: plan.enabled,
|
|
5778
|
+
thinkingLevel: plan.effort
|
|
5779
|
+
};
|
|
5780
|
+
}
|
|
5781
|
+
if (_optionalChain([plan, 'optionalAccess', _283 => _283.kind]) === "budget") {
|
|
5782
|
+
return {
|
|
5783
|
+
includeThoughts: plan.enabled,
|
|
5784
|
+
thinkingBudget: plan.budgetTokens
|
|
5785
|
+
};
|
|
5786
|
+
}
|
|
5787
|
+
return void 0;
|
|
5788
|
+
}
|
|
5789
|
+
|
|
5640
5790
|
// src/completion/DirectApiHandler.ts
|
|
5641
5791
|
async function callOpenAICompletion(provider, apiKey, options, logger) {
|
|
5642
5792
|
const request = {
|
|
@@ -5648,11 +5798,9 @@ async function callOpenAICompletion(provider, apiKey, options, logger) {
|
|
|
5648
5798
|
stream: false
|
|
5649
5799
|
// For now, non-streaming only
|
|
5650
5800
|
};
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
request.reasoning_effort = effort;
|
|
5655
|
-
}
|
|
5801
|
+
const effort = resolveOpenAIEffort(provider, options, "openai-chat");
|
|
5802
|
+
if (effort) {
|
|
5803
|
+
request.reasoning_effort = effort;
|
|
5656
5804
|
}
|
|
5657
5805
|
const apiUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: false });
|
|
5658
5806
|
const headers = _chunkQ27JY5RGcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
@@ -5689,16 +5837,19 @@ async function callOpenAICompletion(provider, apiKey, options, logger) {
|
|
|
5689
5837
|
}
|
|
5690
5838
|
async function callAnthropicCompletion(provider, apiKey, options, logger) {
|
|
5691
5839
|
const hasImages = options.messages.some((m) => m.images && m.images.length > 0);
|
|
5840
|
+
const reasoningWire = buildAnthropicReasoningWire(provider, options);
|
|
5692
5841
|
if (hasImages) {
|
|
5693
5842
|
const systemMessages = options.messages.filter((m) => m.role === "system");
|
|
5694
5843
|
const nonSystemMessages = options.messages.filter((m) => m.role !== "system");
|
|
5695
5844
|
const anthropicRequest2 = {
|
|
5696
5845
|
model: options.model,
|
|
5697
|
-
max_tokens:
|
|
5698
|
-
temperature: options.temperature,
|
|
5846
|
+
max_tokens: reasoningWire.effectiveMaxTokens,
|
|
5847
|
+
...reasoningWire.legacyBudgetEnabled ? {} : { temperature: options.temperature },
|
|
5699
5848
|
...systemMessages.length > 0 ? { system: systemMessages.map((m) => m.content).join("\n\n") } : {},
|
|
5700
5849
|
messages: nonSystemMessages.map((m) => convertMessageToAnthropic(m)),
|
|
5701
|
-
stream: false
|
|
5850
|
+
stream: false,
|
|
5851
|
+
...reasoningWire.thinking ? { thinking: reasoningWire.thinking } : {},
|
|
5852
|
+
...reasoningWire.outputConfig ? { output_config: reasoningWire.outputConfig } : {}
|
|
5702
5853
|
};
|
|
5703
5854
|
const apiUrl2 = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: false });
|
|
5704
5855
|
const headers2 = _chunkQ27JY5RGcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
@@ -5723,7 +5874,7 @@ async function callAnthropicCompletion(provider, apiKey, options, logger) {
|
|
|
5723
5874
|
message: {
|
|
5724
5875
|
id: `assistant-${Date.now()}`,
|
|
5725
5876
|
role: "assistant",
|
|
5726
|
-
content: _optionalChain([choice2, 'access',
|
|
5877
|
+
content: _optionalChain([choice2, 'access', _284 => _284.message, 'optionalAccess', _285 => _285.content]) || "",
|
|
5727
5878
|
timestamp: Date.now()
|
|
5728
5879
|
},
|
|
5729
5880
|
usage: openaiResponse2.usage ? {
|
|
@@ -5740,14 +5891,24 @@ async function callAnthropicCompletion(provider, apiKey, options, logger) {
|
|
|
5740
5891
|
content: m.content
|
|
5741
5892
|
})),
|
|
5742
5893
|
// Anthropic requires max_tokens; use 16384 default if not explicitly set
|
|
5743
|
-
max_tokens:
|
|
5744
|
-
temperature: options.temperature,
|
|
5894
|
+
max_tokens: reasoningWire.effectiveMaxTokens,
|
|
5895
|
+
temperature: reasoningWire.legacyBudgetEnabled ? void 0 : options.temperature,
|
|
5745
5896
|
stream: false
|
|
5746
5897
|
};
|
|
5747
5898
|
const config = {
|
|
5748
5899
|
defaultModel: options.model
|
|
5749
5900
|
};
|
|
5750
5901
|
const anthropicRequest = _chunkGDIXXKF2cjs.convertOpenAIToAnthropic.call(void 0, openaiRequest, config);
|
|
5902
|
+
const anthropicRequestBody = anthropicRequest;
|
|
5903
|
+
if (reasoningWire.thinking) {
|
|
5904
|
+
anthropicRequestBody.thinking = reasoningWire.thinking;
|
|
5905
|
+
}
|
|
5906
|
+
if (reasoningWire.outputConfig) {
|
|
5907
|
+
anthropicRequestBody.output_config = reasoningWire.outputConfig;
|
|
5908
|
+
}
|
|
5909
|
+
if (reasoningWire.legacyBudgetEnabled) {
|
|
5910
|
+
delete anthropicRequestBody.temperature;
|
|
5911
|
+
}
|
|
5751
5912
|
const apiUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: false });
|
|
5752
5913
|
const headers = _chunkQ27JY5RGcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
5753
5914
|
logger.info("Calling Anthropic completion API", { url: apiUrl, model: options.model });
|
|
@@ -5792,11 +5953,13 @@ async function callGeminiCompletion(provider, apiKey, options, logger) {
|
|
|
5792
5953
|
contents.push(convertMessageToGemini(msg));
|
|
5793
5954
|
}
|
|
5794
5955
|
}
|
|
5956
|
+
const thinkingConfig = buildGeminiThinkingConfig(provider, options);
|
|
5795
5957
|
const request = {
|
|
5796
5958
|
contents,
|
|
5797
5959
|
generationConfig: {
|
|
5798
5960
|
...options.maxTokens !== void 0 ? { maxOutputTokens: options.maxTokens } : {},
|
|
5799
|
-
...options.temperature !== void 0 ? { temperature: options.temperature } : {}
|
|
5961
|
+
...options.temperature !== void 0 ? { temperature: options.temperature } : {},
|
|
5962
|
+
...thinkingConfig ? { thinkingConfig } : {}
|
|
5800
5963
|
}
|
|
5801
5964
|
};
|
|
5802
5965
|
if (systemInstruction) {
|
|
@@ -5828,7 +5991,7 @@ async function callGeminiCompletion(provider, apiKey, options, logger) {
|
|
|
5828
5991
|
const candidate = candidates[0];
|
|
5829
5992
|
const content = candidate.content;
|
|
5830
5993
|
let textContent = "";
|
|
5831
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
5994
|
+
if (_optionalChain([content, 'optionalAccess', _286 => _286.parts])) {
|
|
5832
5995
|
for (const part of content.parts) {
|
|
5833
5996
|
if (part.text) {
|
|
5834
5997
|
textContent += part.text;
|
|
@@ -5867,11 +6030,9 @@ async function callOpenAIResponseCompletion(provider, apiKey, options, logger) {
|
|
|
5867
6030
|
...options.maxTokens !== void 0 ? { max_output_tokens: options.maxTokens } : {},
|
|
5868
6031
|
...options.temperature !== void 0 ? { temperature: options.temperature } : {}
|
|
5869
6032
|
};
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
5873
|
-
request.reasoning = { effort, summary: "auto" };
|
|
5874
|
-
}
|
|
6033
|
+
const responseEffort = resolveOpenAIEffort(provider, options, "openai-responses");
|
|
6034
|
+
if (responseEffort) {
|
|
6035
|
+
request.reasoning = { effort: responseEffort, summary: "auto" };
|
|
5875
6036
|
}
|
|
5876
6037
|
const apiUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: false });
|
|
5877
6038
|
const headers = _chunkQ27JY5RGcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
@@ -5923,7 +6084,6 @@ async function callOpenAIResponseCompletion(provider, apiKey, options, logger) {
|
|
|
5923
6084
|
}
|
|
5924
6085
|
|
|
5925
6086
|
// src/completion/StreamHandler.ts
|
|
5926
|
-
|
|
5927
6087
|
async function streamOpenAICompletion(provider, apiKey, options, messageId, callbacks, logger) {
|
|
5928
6088
|
const request = {
|
|
5929
6089
|
model: options.model,
|
|
@@ -5933,11 +6093,9 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
|
|
|
5933
6093
|
temperature: options.temperature,
|
|
5934
6094
|
stream: true
|
|
5935
6095
|
};
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
request.reasoning_effort = effort;
|
|
5940
|
-
}
|
|
6096
|
+
const effort = resolveOpenAIEffort(provider, options, "openai-chat");
|
|
6097
|
+
if (effort) {
|
|
6098
|
+
request.reasoning_effort = effort;
|
|
5941
6099
|
}
|
|
5942
6100
|
const apiUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: true });
|
|
5943
6101
|
const headers = _chunkQ27JY5RGcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
@@ -5961,7 +6119,7 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
|
|
|
5961
6119
|
});
|
|
5962
6120
|
if (!response.ok) {
|
|
5963
6121
|
const errorText = await response.text();
|
|
5964
|
-
_optionalChain([callbacks, 'access',
|
|
6122
|
+
_optionalChain([callbacks, 'access', _287 => _287.onError, 'optionalCall', _288 => _288(`API error (${response.status}): ${errorText}`)]);
|
|
5965
6123
|
return;
|
|
5966
6124
|
}
|
|
5967
6125
|
const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "openai", {
|
|
@@ -5971,7 +6129,7 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
|
|
|
5971
6129
|
onVideo: callbacks.onVideo,
|
|
5972
6130
|
onError: callbacks.onError
|
|
5973
6131
|
});
|
|
5974
|
-
_optionalChain([callbacks, 'access',
|
|
6132
|
+
_optionalChain([callbacks, 'access', _289 => _289.onDone, 'optionalCall', _290 => _290(
|
|
5975
6133
|
{
|
|
5976
6134
|
id: messageId,
|
|
5977
6135
|
role: "assistant",
|
|
@@ -5987,16 +6145,11 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
|
|
|
5987
6145
|
}
|
|
5988
6146
|
async function streamAnthropicCompletion(provider, apiKey, options, messageId, callbacks, logger) {
|
|
5989
6147
|
const hasImages = options.messages.some((m) => m.images && m.images.length > 0);
|
|
5990
|
-
const
|
|
5991
|
-
|
|
5992
|
-
const thinkingMaxTokens = options.thinkLevel && options.thinkLevel !== "none" ? Math.min(effectiveMaxTokens, MAX_TOKENS_FOR_THINKING) : effectiveMaxTokens;
|
|
5993
|
-
const thinkingConfig = options.thinkLevel && options.thinkLevel !== "none" ? _thinkingconfig.buildAnthropicThinking.call(void 0, options.model, options.thinkLevel, thinkingMaxTokens) : void 0;
|
|
5994
|
-
if (thinkingConfig) {
|
|
5995
|
-
effectiveMaxTokens = thinkingMaxTokens;
|
|
5996
|
-
}
|
|
6148
|
+
const reasoningWire = buildAnthropicReasoningWire(provider, options);
|
|
6149
|
+
const effectiveMaxTokens = reasoningWire.effectiveMaxTokens;
|
|
5997
6150
|
logger.debug("Anthropic thinking configuration", {
|
|
5998
6151
|
thinkLevel: options.thinkLevel,
|
|
5999
|
-
thinkingConfig,
|
|
6152
|
+
thinkingConfig: reasoningWire.thinking,
|
|
6000
6153
|
effectiveMaxTokens
|
|
6001
6154
|
});
|
|
6002
6155
|
let anthropicRequest;
|
|
@@ -6007,12 +6160,15 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
|
|
|
6007
6160
|
model: options.model,
|
|
6008
6161
|
max_tokens: effectiveMaxTokens,
|
|
6009
6162
|
// Omit temperature when thinking is enabled (Anthropic will use default temperature=1)
|
|
6010
|
-
...
|
|
6163
|
+
...reasoningWire.legacyBudgetEnabled ? {} : { temperature: options.temperature },
|
|
6011
6164
|
...systemMessages.length > 0 ? { system: systemMessages.map((m) => m.content).join("\n\n") } : {},
|
|
6012
6165
|
messages: nonSystemMessages.map((m) => convertMessageToAnthropic(m)),
|
|
6013
6166
|
stream: true,
|
|
6014
|
-
...
|
|
6167
|
+
...reasoningWire.thinking ? { thinking: reasoningWire.thinking } : {}
|
|
6015
6168
|
};
|
|
6169
|
+
if (reasoningWire.outputConfig) {
|
|
6170
|
+
anthropicRequest.output_config = reasoningWire.outputConfig;
|
|
6171
|
+
}
|
|
6016
6172
|
} else {
|
|
6017
6173
|
const config = {
|
|
6018
6174
|
defaultModel: options.model
|
|
@@ -6026,12 +6182,17 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
|
|
|
6026
6182
|
// Anthropic requires max_tokens; use adjusted value
|
|
6027
6183
|
max_tokens: effectiveMaxTokens,
|
|
6028
6184
|
// Omit temperature when thinking is enabled (Anthropic will use default temperature=1)
|
|
6029
|
-
temperature:
|
|
6185
|
+
temperature: reasoningWire.legacyBudgetEnabled ? void 0 : options.temperature,
|
|
6030
6186
|
stream: true
|
|
6031
6187
|
};
|
|
6032
6188
|
anthropicRequest = _chunkGDIXXKF2cjs.convertOpenAIToAnthropic.call(void 0, openaiRequest, config);
|
|
6033
|
-
if (
|
|
6034
|
-
anthropicRequest.thinking =
|
|
6189
|
+
if (reasoningWire.thinking) {
|
|
6190
|
+
anthropicRequest.thinking = reasoningWire.thinking;
|
|
6191
|
+
}
|
|
6192
|
+
if (reasoningWire.outputConfig) {
|
|
6193
|
+
anthropicRequest.output_config = reasoningWire.outputConfig;
|
|
6194
|
+
}
|
|
6195
|
+
if (reasoningWire.legacyBudgetEnabled) {
|
|
6035
6196
|
delete anthropicRequest.temperature;
|
|
6036
6197
|
}
|
|
6037
6198
|
}
|
|
@@ -6043,7 +6204,7 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
|
|
|
6043
6204
|
logger.info("Streaming Anthropic completion request", {
|
|
6044
6205
|
url: apiUrl,
|
|
6045
6206
|
model: anthropicRequest.model,
|
|
6046
|
-
messagesCount: _optionalChain([anthropicRequest, 'access',
|
|
6207
|
+
messagesCount: _optionalChain([anthropicRequest, 'access', _291 => _291.messages, 'optionalAccess', _292 => _292.length]),
|
|
6047
6208
|
max_tokens: anthropicRequest.max_tokens,
|
|
6048
6209
|
temperature: anthropicRequest.temperature,
|
|
6049
6210
|
stream: anthropicRequest.stream,
|
|
@@ -6060,7 +6221,7 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
|
|
|
6060
6221
|
if (!response.ok) {
|
|
6061
6222
|
const errorText = await response.text();
|
|
6062
6223
|
logger.error("Anthropic API error", void 0, { status: response.status, errorText });
|
|
6063
|
-
_optionalChain([callbacks, 'access',
|
|
6224
|
+
_optionalChain([callbacks, 'access', _293 => _293.onError, 'optionalCall', _294 => _294(`API error (${response.status}): ${errorText}`)]);
|
|
6064
6225
|
return;
|
|
6065
6226
|
}
|
|
6066
6227
|
const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "anthropic", {
|
|
@@ -6071,10 +6232,10 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
|
|
|
6071
6232
|
});
|
|
6072
6233
|
logger.info("Anthropic stream complete", {
|
|
6073
6234
|
contentLength: result.content.length,
|
|
6074
|
-
reasoningLength: _optionalChain([result, 'access',
|
|
6235
|
+
reasoningLength: _optionalChain([result, 'access', _295 => _295.reasoning, 'optionalAccess', _296 => _296.length]) || 0,
|
|
6075
6236
|
blocksCount: result.blocks.length
|
|
6076
6237
|
});
|
|
6077
|
-
_optionalChain([callbacks, 'access',
|
|
6238
|
+
_optionalChain([callbacks, 'access', _297 => _297.onDone, 'optionalCall', _298 => _298(
|
|
6078
6239
|
{
|
|
6079
6240
|
id: messageId,
|
|
6080
6241
|
role: "assistant",
|
|
@@ -6097,11 +6258,13 @@ async function streamGeminiCompletion(provider, apiKey, options, messageId, call
|
|
|
6097
6258
|
contents.push(convertMessageToGemini(msg));
|
|
6098
6259
|
}
|
|
6099
6260
|
}
|
|
6261
|
+
const thinkingConfig = buildGeminiThinkingConfig(provider, options);
|
|
6100
6262
|
const request = {
|
|
6101
6263
|
contents,
|
|
6102
6264
|
generationConfig: {
|
|
6103
6265
|
...options.maxTokens !== void 0 ? { maxOutputTokens: options.maxTokens } : {},
|
|
6104
|
-
...options.temperature !== void 0 ? { temperature: options.temperature } : {}
|
|
6266
|
+
...options.temperature !== void 0 ? { temperature: options.temperature } : {},
|
|
6267
|
+
...thinkingConfig ? { thinkingConfig } : {}
|
|
6105
6268
|
}
|
|
6106
6269
|
};
|
|
6107
6270
|
if (systemInstruction) {
|
|
@@ -6130,7 +6293,7 @@ async function streamGeminiCompletion(provider, apiKey, options, messageId, call
|
|
|
6130
6293
|
if (!response.ok) {
|
|
6131
6294
|
const errorText = await response.text();
|
|
6132
6295
|
logger.error("Gemini API error", void 0, { status: response.status, errorText });
|
|
6133
|
-
_optionalChain([callbacks, 'access',
|
|
6296
|
+
_optionalChain([callbacks, 'access', _299 => _299.onError, 'optionalCall', _300 => _300(`API error (${response.status}): ${errorText}`)]);
|
|
6134
6297
|
return;
|
|
6135
6298
|
}
|
|
6136
6299
|
const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "gemini", {
|
|
@@ -6139,7 +6302,7 @@ async function streamGeminiCompletion(provider, apiKey, options, messageId, call
|
|
|
6139
6302
|
onError: callbacks.onError
|
|
6140
6303
|
});
|
|
6141
6304
|
logger.info("Gemini stream complete", { contentLength: result.content.length });
|
|
6142
|
-
_optionalChain([callbacks, 'access',
|
|
6305
|
+
_optionalChain([callbacks, 'access', _301 => _301.onDone, 'optionalCall', _302 => _302(
|
|
6143
6306
|
{
|
|
6144
6307
|
id: messageId,
|
|
6145
6308
|
role: "assistant",
|
|
@@ -6167,11 +6330,9 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
|
|
|
6167
6330
|
...options.maxTokens !== void 0 ? { max_output_tokens: options.maxTokens } : {},
|
|
6168
6331
|
...options.temperature !== void 0 ? { temperature: options.temperature } : {}
|
|
6169
6332
|
};
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
request.reasoning = { effort, summary: "auto" };
|
|
6174
|
-
}
|
|
6333
|
+
const responseEffort = resolveOpenAIEffort(provider, options, "openai-responses");
|
|
6334
|
+
if (responseEffort) {
|
|
6335
|
+
request.reasoning = { effort: responseEffort, summary: "auto" };
|
|
6175
6336
|
}
|
|
6176
6337
|
const apiUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: true });
|
|
6177
6338
|
const headers = _chunkQ27JY5RGcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
@@ -6191,7 +6352,7 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
|
|
|
6191
6352
|
});
|
|
6192
6353
|
if (!response.ok) {
|
|
6193
6354
|
const errorText = await response.text();
|
|
6194
|
-
_optionalChain([callbacks, 'access',
|
|
6355
|
+
_optionalChain([callbacks, 'access', _303 => _303.onError, 'optionalCall', _304 => _304(`API error (${response.status}): ${errorText}`)]);
|
|
6195
6356
|
return;
|
|
6196
6357
|
}
|
|
6197
6358
|
const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "openai-response", {
|
|
@@ -6200,7 +6361,7 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
|
|
|
6200
6361
|
onError: callbacks.onError
|
|
6201
6362
|
});
|
|
6202
6363
|
logger.info("OpenAI Response API stream complete", { contentLength: result.content.length });
|
|
6203
|
-
_optionalChain([callbacks, 'access',
|
|
6364
|
+
_optionalChain([callbacks, 'access', _305 => _305.onDone, 'optionalCall', _306 => _306(
|
|
6204
6365
|
{
|
|
6205
6366
|
id: messageId,
|
|
6206
6367
|
role: "assistant",
|
|
@@ -6220,7 +6381,7 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
|
|
|
6220
6381
|
|
|
6221
6382
|
|
|
6222
6383
|
|
|
6223
|
-
|
|
6384
|
+
var _thinkingconfig = require('@omnicross/contracts/thinking-config');
|
|
6224
6385
|
async function resolveEffectiveMaxTokens(llmConfig, _getProvider, logger, _providerId, _modelId, sessionMaxTokens) {
|
|
6225
6386
|
if (sessionMaxTokens !== void 0 && sessionMaxTokens > 0) {
|
|
6226
6387
|
logger.debug("Using session maxTokens", { sessionMaxTokens });
|
|
@@ -6228,7 +6389,7 @@ async function resolveEffectiveMaxTokens(llmConfig, _getProvider, logger, _provi
|
|
|
6228
6389
|
}
|
|
6229
6390
|
try {
|
|
6230
6391
|
const globalParams = await llmConfig.getGlobalModelParameters();
|
|
6231
|
-
if (_optionalChain([globalParams, 'optionalAccess',
|
|
6392
|
+
if (_optionalChain([globalParams, 'optionalAccess', _307 => _307.maxTokens, 'optionalAccess', _308 => _308.enabled]) && globalParams.maxTokens.value > 0) {
|
|
6232
6393
|
logger.debug("Using global maxTokens", { maxTokens: globalParams.maxTokens.value });
|
|
6233
6394
|
return globalParams.maxTokens.value;
|
|
6234
6395
|
}
|
|
@@ -6256,7 +6417,7 @@ async function resolveThinkingBudget(getProvider, logger, providerId, modelId, m
|
|
|
6256
6417
|
}
|
|
6257
6418
|
const thinkingBudget = _thinkingconfig.calculateThinkingBudget.call(void 0, modelId, thinkLevel, maxTokens);
|
|
6258
6419
|
const provider = await getProvider(providerId);
|
|
6259
|
-
const providerName = _optionalChain([provider, 'optionalAccess',
|
|
6420
|
+
const providerName = _optionalChain([provider, 'optionalAccess', _309 => _309.name, 'optionalAccess', _310 => _310.toLowerCase, 'call', _311 => _311()]) || "";
|
|
6260
6421
|
const apiFormat = provider ? _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider) : "openai";
|
|
6261
6422
|
if (apiFormat === "anthropic" || providerName === "anthropic" || providerName.includes("claude")) {
|
|
6262
6423
|
const thinkingConfig = _thinkingconfig.buildAnthropicThinking.call(void 0, modelId, thinkLevel, maxTokens);
|
|
@@ -6293,7 +6454,7 @@ function logToolFormat(tools, logger) {
|
|
|
6293
6454
|
tools: openaiTools.map((t) => t.function.name),
|
|
6294
6455
|
firstTool: {
|
|
6295
6456
|
name: firstTool.function.name,
|
|
6296
|
-
description: _optionalChain([firstTool, 'access',
|
|
6457
|
+
description: _optionalChain([firstTool, 'access', _312 => _312.function, 'access', _313 => _313.description, 'optionalAccess', _314 => _314.slice, 'call', _315 => _315(0, 100)]),
|
|
6297
6458
|
parameters: firstTool.function.parameters
|
|
6298
6459
|
}
|
|
6299
6460
|
});
|
|
@@ -6304,7 +6465,7 @@ function logToolFormat(tools, logger) {
|
|
|
6304
6465
|
tools: anthropicTools.map((t) => t.name),
|
|
6305
6466
|
firstTool: {
|
|
6306
6467
|
name: firstTool.name,
|
|
6307
|
-
description: _optionalChain([firstTool, 'access',
|
|
6468
|
+
description: _optionalChain([firstTool, 'access', _316 => _316.description, 'optionalAccess', _317 => _317.slice, 'call', _318 => _318(0, 100)]),
|
|
6308
6469
|
input_schema: firstTool.input_schema
|
|
6309
6470
|
}
|
|
6310
6471
|
});
|
|
@@ -6315,9 +6476,9 @@ function logToolFormat(tools, logger) {
|
|
|
6315
6476
|
count: allDeclarations.length,
|
|
6316
6477
|
tools: allDeclarations.map((t) => t.name),
|
|
6317
6478
|
firstTool: {
|
|
6318
|
-
name: _optionalChain([allDeclarations, 'access',
|
|
6319
|
-
description: _optionalChain([allDeclarations, 'access',
|
|
6320
|
-
parameters: _optionalChain([allDeclarations, 'access',
|
|
6479
|
+
name: _optionalChain([allDeclarations, 'access', _319 => _319[0], 'optionalAccess', _320 => _320.name]),
|
|
6480
|
+
description: _optionalChain([allDeclarations, 'access', _321 => _321[0], 'optionalAccess', _322 => _322.description, 'optionalAccess', _323 => _323.slice, 'call', _324 => _324(0, 100)]),
|
|
6481
|
+
parameters: _optionalChain([allDeclarations, 'access', _325 => _325[0], 'optionalAccess', _326 => _326.parameters])
|
|
6321
6482
|
}
|
|
6322
6483
|
});
|
|
6323
6484
|
}
|
|
@@ -6351,7 +6512,7 @@ function buildToolRequest(apiFormat, conversationMessages, actualModel, options,
|
|
|
6351
6512
|
// Native Anthropic Messages requires this field. Resolve an absent
|
|
6352
6513
|
// caller cap to the model's real ceiling rather than a small constant —
|
|
6353
6514
|
// see `resolveAnthropicMaxTokens`.
|
|
6354
|
-
max_tokens:
|
|
6515
|
+
max_tokens: _chunkZQQUD66Mcjs.resolveAnthropicMaxTokens.call(void 0, actualModel, options.maxTokens),
|
|
6355
6516
|
temperature: _nullishCoalesce(options.temperature, () => ( 0.7)),
|
|
6356
6517
|
stream: true,
|
|
6357
6518
|
tools: options.tools
|
|
@@ -6380,7 +6541,7 @@ function buildToolRequest(apiFormat, conversationMessages, actualModel, options,
|
|
|
6380
6541
|
function extractDeltaContent(rawJson, apiFormat) {
|
|
6381
6542
|
const json = rawJson;
|
|
6382
6543
|
if (apiFormat === "google") {
|
|
6383
|
-
const parts = _optionalChain([json, 'access',
|
|
6544
|
+
const parts = _optionalChain([json, 'access', _327 => _327.candidates, 'optionalAccess', _328 => _328[0], 'optionalAccess', _329 => _329.content, 'optionalAccess', _330 => _330.parts]) || [];
|
|
6384
6545
|
let text = "";
|
|
6385
6546
|
for (const part of parts) {
|
|
6386
6547
|
if (part.thought === true) continue;
|
|
@@ -6388,15 +6549,15 @@ function extractDeltaContent(rawJson, apiFormat) {
|
|
|
6388
6549
|
}
|
|
6389
6550
|
return text;
|
|
6390
6551
|
} else if (apiFormat === "anthropic") {
|
|
6391
|
-
return _optionalChain([json, 'access',
|
|
6552
|
+
return _optionalChain([json, 'access', _331 => _331.delta, 'optionalAccess', _332 => _332.text]) || "";
|
|
6392
6553
|
} else {
|
|
6393
|
-
return _optionalChain([json, 'access',
|
|
6554
|
+
return _optionalChain([json, 'access', _333 => _333.choices, 'optionalAccess', _334 => _334[0], 'optionalAccess', _335 => _335.delta, 'optionalAccess', _336 => _336.content]) || "";
|
|
6394
6555
|
}
|
|
6395
6556
|
}
|
|
6396
6557
|
function extractDeltaReasoning(rawJson, apiFormat) {
|
|
6397
6558
|
const json = rawJson;
|
|
6398
6559
|
if (apiFormat === "google") {
|
|
6399
|
-
const parts = _optionalChain([json, 'access',
|
|
6560
|
+
const parts = _optionalChain([json, 'access', _337 => _337.candidates, 'optionalAccess', _338 => _338[0], 'optionalAccess', _339 => _339.content, 'optionalAccess', _340 => _340.parts]) || [];
|
|
6400
6561
|
let reasoning = "";
|
|
6401
6562
|
for (const part of parts) {
|
|
6402
6563
|
if (part.thought === true && part.text) reasoning += part.text;
|
|
@@ -6405,14 +6566,14 @@ function extractDeltaReasoning(rawJson, apiFormat) {
|
|
|
6405
6566
|
} else if (apiFormat === "anthropic") {
|
|
6406
6567
|
return "";
|
|
6407
6568
|
} else {
|
|
6408
|
-
const delta = _optionalChain([json, 'access',
|
|
6409
|
-
return (_optionalChain([delta, 'optionalAccess',
|
|
6569
|
+
const delta = _optionalChain([json, 'access', _341 => _341.choices, 'optionalAccess', _342 => _342[0], 'optionalAccess', _343 => _343.delta]);
|
|
6570
|
+
return (_optionalChain([delta, 'optionalAccess', _344 => _344.thinking, 'optionalAccess', _345 => _345.content]) || "") + (_optionalChain([delta, 'optionalAccess', _346 => _346.reasoning_content]) || "");
|
|
6410
6571
|
}
|
|
6411
6572
|
}
|
|
6412
6573
|
function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pendingOpenAIToolCalls) {
|
|
6413
6574
|
const json = rawJson;
|
|
6414
6575
|
if (apiFormat === "google") {
|
|
6415
|
-
const parts = _optionalChain([json, 'access',
|
|
6576
|
+
const parts = _optionalChain([json, 'access', _347 => _347.candidates, 'optionalAccess', _348 => _348[0], 'optionalAccess', _349 => _349.content, 'optionalAccess', _350 => _350.parts]) || [];
|
|
6416
6577
|
for (const part of parts) {
|
|
6417
6578
|
if (part.functionCall) {
|
|
6418
6579
|
logger.info("Function call detected", { functionCall: part.functionCall });
|
|
@@ -6422,13 +6583,13 @@ function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pend
|
|
|
6422
6583
|
args: part.functionCall.args || {}
|
|
6423
6584
|
};
|
|
6424
6585
|
toolCalls.push(toolCall);
|
|
6425
|
-
_optionalChain([callbacks, 'access',
|
|
6586
|
+
_optionalChain([callbacks, 'access', _351 => _351.onToolCall, 'optionalCall', _352 => _352(toolCall)]);
|
|
6426
6587
|
logger.info("Tool called", { toolName: toolCall.name });
|
|
6427
6588
|
}
|
|
6428
6589
|
}
|
|
6429
6590
|
} else if (apiFormat !== "anthropic") {
|
|
6430
|
-
const delta = _optionalChain([json, 'access',
|
|
6431
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
6591
|
+
const delta = _optionalChain([json, 'access', _353 => _353.choices, 'optionalAccess', _354 => _354[0], 'optionalAccess', _355 => _355.delta]);
|
|
6592
|
+
if (_optionalChain([delta, 'optionalAccess', _356 => _356.tool_calls]) && pendingOpenAIToolCalls) {
|
|
6432
6593
|
for (const tc of delta.tool_calls) {
|
|
6433
6594
|
const index = _nullishCoalesce(tc.index, () => ( 0));
|
|
6434
6595
|
let pending = pendingOpenAIToolCalls.get(index);
|
|
@@ -6437,8 +6598,8 @@ function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pend
|
|
|
6437
6598
|
pendingOpenAIToolCalls.set(index, pending);
|
|
6438
6599
|
}
|
|
6439
6600
|
if (tc.id) pending.id = tc.id;
|
|
6440
|
-
if (_optionalChain([tc, 'access',
|
|
6441
|
-
if (_optionalChain([tc, 'access',
|
|
6601
|
+
if (_optionalChain([tc, 'access', _357 => _357.function, 'optionalAccess', _358 => _358.name])) pending.name += tc.function.name;
|
|
6602
|
+
if (_optionalChain([tc, 'access', _359 => _359.function, 'optionalAccess', _360 => _360.arguments])) pending.arguments += tc.function.arguments;
|
|
6442
6603
|
}
|
|
6443
6604
|
}
|
|
6444
6605
|
}
|
|
@@ -6453,7 +6614,7 @@ function finalizeOpenAIToolCalls(pendingOpenAIToolCalls, toolCalls, callbacks, l
|
|
|
6453
6614
|
args: JSON.parse(pending.arguments || "{}")
|
|
6454
6615
|
};
|
|
6455
6616
|
toolCalls.push(toolCall);
|
|
6456
|
-
_optionalChain([callbacks, 'access',
|
|
6617
|
+
_optionalChain([callbacks, 'access', _361 => _361.onToolCall, 'optionalCall', _362 => _362(toolCall)]);
|
|
6457
6618
|
logger.info("Tool called (OpenAI)", { toolName: toolCall.name, args: toolCall.args });
|
|
6458
6619
|
} catch (e) {
|
|
6459
6620
|
logger.error("Failed to parse OpenAI tool call arguments", e instanceof Error ? e : void 0, {
|
|
@@ -6467,38 +6628,38 @@ function finalizeOpenAIToolCalls(pendingOpenAIToolCalls, toolCalls, callbacks, l
|
|
|
6467
6628
|
function parseStreamChunk(rawJson, apiFormat, callbacks, logger) {
|
|
6468
6629
|
const json = rawJson;
|
|
6469
6630
|
if (apiFormat === "google") {
|
|
6470
|
-
const candidate = _optionalChain([json, 'access',
|
|
6631
|
+
const candidate = _optionalChain([json, 'access', _363 => _363.candidates, 'optionalAccess', _364 => _364[0]]);
|
|
6471
6632
|
if (!candidate) {
|
|
6472
6633
|
logger.warn("No candidate found in Gemini response");
|
|
6473
6634
|
return;
|
|
6474
6635
|
}
|
|
6475
|
-
const parts = _optionalChain([candidate, 'access',
|
|
6636
|
+
const parts = _optionalChain([candidate, 'access', _365 => _365.content, 'optionalAccess', _366 => _366.parts]) || [];
|
|
6476
6637
|
for (const part of parts) {
|
|
6477
6638
|
if (part.thought === true && part.text) {
|
|
6478
|
-
_optionalChain([callbacks, 'access',
|
|
6639
|
+
_optionalChain([callbacks, 'access', _367 => _367.onReasoning, 'optionalCall', _368 => _368(part.text)]);
|
|
6479
6640
|
continue;
|
|
6480
6641
|
} else if (part.thoughtSignature && !part.thought) {
|
|
6481
6642
|
logger.debug("Gemini returned thoughtSignature without thought content");
|
|
6482
6643
|
}
|
|
6483
6644
|
if (part.text) {
|
|
6484
|
-
_optionalChain([callbacks, 'access',
|
|
6645
|
+
_optionalChain([callbacks, 'access', _369 => _369.onDelta, 'optionalCall', _370 => _370(part.text)]);
|
|
6485
6646
|
}
|
|
6486
6647
|
}
|
|
6487
6648
|
} else if (apiFormat === "anthropic") {
|
|
6488
6649
|
const delta = json.delta;
|
|
6489
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
6490
|
-
_optionalChain([callbacks, 'access',
|
|
6650
|
+
if (_optionalChain([delta, 'optionalAccess', _371 => _371.text])) {
|
|
6651
|
+
_optionalChain([callbacks, 'access', _372 => _372.onDelta, 'optionalCall', _373 => _373(delta.text)]);
|
|
6491
6652
|
}
|
|
6492
6653
|
} else {
|
|
6493
|
-
const delta = _optionalChain([json, 'access',
|
|
6494
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
6495
|
-
_optionalChain([callbacks, 'access',
|
|
6654
|
+
const delta = _optionalChain([json, 'access', _374 => _374.choices, 'optionalAccess', _375 => _375[0], 'optionalAccess', _376 => _376.delta]);
|
|
6655
|
+
if (_optionalChain([delta, 'optionalAccess', _377 => _377.content])) {
|
|
6656
|
+
_optionalChain([callbacks, 'access', _378 => _378.onDelta, 'optionalCall', _379 => _379(delta.content)]);
|
|
6496
6657
|
}
|
|
6497
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
6498
|
-
_optionalChain([callbacks, 'access',
|
|
6658
|
+
if (_optionalChain([delta, 'optionalAccess', _380 => _380.thinking, 'optionalAccess', _381 => _381.content])) {
|
|
6659
|
+
_optionalChain([callbacks, 'access', _382 => _382.onReasoning, 'optionalCall', _383 => _383(delta.thinking.content)]);
|
|
6499
6660
|
}
|
|
6500
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
6501
|
-
_optionalChain([callbacks, 'access',
|
|
6661
|
+
if (_optionalChain([delta, 'optionalAccess', _384 => _384.reasoning_content])) {
|
|
6662
|
+
_optionalChain([callbacks, 'access', _385 => _385.onReasoning, 'optionalCall', _386 => _386(delta.reasoning_content)]);
|
|
6502
6663
|
}
|
|
6503
6664
|
}
|
|
6504
6665
|
}
|
|
@@ -6511,7 +6672,7 @@ function buildIterationBlocks(iteration, content, reasoning, blocks, callbacks)
|
|
|
6511
6672
|
content: reasoning
|
|
6512
6673
|
};
|
|
6513
6674
|
blocks.push(thinkingBlock);
|
|
6514
|
-
_optionalChain([callbacks, 'access',
|
|
6675
|
+
_optionalChain([callbacks, 'access', _387 => _387.onBlock, 'optionalCall', _388 => _388(thinkingBlock)]);
|
|
6515
6676
|
}
|
|
6516
6677
|
if (content && content.trim()) {
|
|
6517
6678
|
const textBlock = {
|
|
@@ -6520,7 +6681,7 @@ function buildIterationBlocks(iteration, content, reasoning, blocks, callbacks)
|
|
|
6520
6681
|
content
|
|
6521
6682
|
};
|
|
6522
6683
|
blocks.push(textBlock);
|
|
6523
|
-
_optionalChain([callbacks, 'access',
|
|
6684
|
+
_optionalChain([callbacks, 'access', _389 => _389.onBlock, 'optionalCall', _390 => _390(textBlock)]);
|
|
6524
6685
|
}
|
|
6525
6686
|
}
|
|
6526
6687
|
async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbacks, logger, builtinExecutor) {
|
|
@@ -6535,7 +6696,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
6535
6696
|
status: "running"
|
|
6536
6697
|
};
|
|
6537
6698
|
blocks.push(toolUseBlock);
|
|
6538
|
-
_optionalChain([callbacks, 'access',
|
|
6699
|
+
_optionalChain([callbacks, 'access', _391 => _391.onBlock, 'optionalCall', _392 => _392(toolUseBlock)]);
|
|
6539
6700
|
try {
|
|
6540
6701
|
logger.info("Executing tool", { toolName: toolCall.name });
|
|
6541
6702
|
const mcpTool = mcpTools.find((t) => t.id === toolCall.name);
|
|
@@ -6558,8 +6719,8 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
6558
6719
|
result = { isError: true, content: [{ type: "text", text: "MCP service not available" }] };
|
|
6559
6720
|
}
|
|
6560
6721
|
logger.info("Tool result received", { result });
|
|
6561
|
-
_optionalChain([callbacks, 'access',
|
|
6562
|
-
const resultText = _optionalChain([result, 'access',
|
|
6722
|
+
_optionalChain([callbacks, 'access', _393 => _393.onToolResult, 'optionalCall', _394 => _394(toolCall.id, result)]);
|
|
6723
|
+
const resultText = _optionalChain([result, 'access', _395 => _395.content, 'optionalAccess', _396 => _396[0], 'optionalAccess', _397 => _397.text]) || JSON.stringify(result);
|
|
6563
6724
|
const toolResultBlock = {
|
|
6564
6725
|
id: `${toolCall.id}_result`,
|
|
6565
6726
|
type: "tool_result",
|
|
@@ -6569,11 +6730,11 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
6569
6730
|
isError: result.isError
|
|
6570
6731
|
};
|
|
6571
6732
|
blocks.push(toolResultBlock);
|
|
6572
|
-
_optionalChain([callbacks, 'access',
|
|
6733
|
+
_optionalChain([callbacks, 'access', _398 => _398.onBlock, 'optionalCall', _399 => _399(toolResultBlock)]);
|
|
6573
6734
|
const toolUseBlockRef = blocks.find((b) => b.id === `${toolCall.id}_use`);
|
|
6574
6735
|
if (toolUseBlockRef && toolUseBlockRef.type === "tool_use") {
|
|
6575
6736
|
toolUseBlockRef.status = result.isError ? "error" : "completed";
|
|
6576
|
-
_optionalChain([callbacks, 'access',
|
|
6737
|
+
_optionalChain([callbacks, 'access', _400 => _400.onBlock, 'optionalCall', _401 => _401({ ...toolUseBlockRef })]);
|
|
6577
6738
|
}
|
|
6578
6739
|
toolResults.push({ toolCall, result });
|
|
6579
6740
|
} catch (error) {
|
|
@@ -6583,7 +6744,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
6583
6744
|
isError: true,
|
|
6584
6745
|
content: [{ type: "text", text: `Error: ${errorMessage}` }]
|
|
6585
6746
|
};
|
|
6586
|
-
_optionalChain([callbacks, 'access',
|
|
6747
|
+
_optionalChain([callbacks, 'access', _402 => _402.onToolResult, 'optionalCall', _403 => _403(toolCall.id, errorResult)]);
|
|
6587
6748
|
const errorToolResultBlock = {
|
|
6588
6749
|
id: `${toolCall.id}_result`,
|
|
6589
6750
|
type: "tool_result",
|
|
@@ -6593,11 +6754,11 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
6593
6754
|
isError: true
|
|
6594
6755
|
};
|
|
6595
6756
|
blocks.push(errorToolResultBlock);
|
|
6596
|
-
_optionalChain([callbacks, 'access',
|
|
6757
|
+
_optionalChain([callbacks, 'access', _404 => _404.onBlock, 'optionalCall', _405 => _405(errorToolResultBlock)]);
|
|
6597
6758
|
const errorToolUseBlockRef = blocks.find((b) => b.id === `${toolCall.id}_use`);
|
|
6598
6759
|
if (errorToolUseBlockRef && errorToolUseBlockRef.type === "tool_use") {
|
|
6599
6760
|
errorToolUseBlockRef.status = "error";
|
|
6600
|
-
_optionalChain([callbacks, 'access',
|
|
6761
|
+
_optionalChain([callbacks, 'access', _406 => _406.onBlock, 'optionalCall', _407 => _407({ ...errorToolUseBlockRef })]);
|
|
6601
6762
|
}
|
|
6602
6763
|
toolResults.push({ toolCall, result: errorResult });
|
|
6603
6764
|
}
|
|
@@ -6607,7 +6768,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
6607
6768
|
function mapToolArguments(args, mcpTool, logger) {
|
|
6608
6769
|
const mappedArgs = { ...args };
|
|
6609
6770
|
const toolSchema = mcpTool.inputSchema;
|
|
6610
|
-
if (_optionalChain([toolSchema, 'optionalAccess',
|
|
6771
|
+
if (_optionalChain([toolSchema, 'optionalAccess', _408 => _408.properties])) {
|
|
6611
6772
|
const expectedParams = Object.keys(toolSchema.properties);
|
|
6612
6773
|
const paramMappings = {
|
|
6613
6774
|
"search_query": ["query", "q", "searchQuery", "search"],
|
|
@@ -6641,25 +6802,25 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
6641
6802
|
options.providerId,
|
|
6642
6803
|
options.model
|
|
6643
6804
|
);
|
|
6644
|
-
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess',
|
|
6645
|
-
const actualModel = _optionalChain([routedInfo, 'optionalAccess',
|
|
6805
|
+
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _409 => _409.actualProviderId]) || options.providerId;
|
|
6806
|
+
const actualModel = _optionalChain([routedInfo, 'optionalAccess', _410 => _410.actualModelId]) || options.model;
|
|
6646
6807
|
const provider = await getProvider(actualProviderId);
|
|
6647
6808
|
if (!provider) {
|
|
6648
|
-
_optionalChain([callbacks, 'access',
|
|
6809
|
+
_optionalChain([callbacks, 'access', _411 => _411.onError, 'optionalCall', _412 => _412(`Provider not found: ${actualProviderId}`)]);
|
|
6649
6810
|
return;
|
|
6650
6811
|
}
|
|
6651
6812
|
if (!provider.enabled) {
|
|
6652
|
-
_optionalChain([callbacks, 'access',
|
|
6813
|
+
_optionalChain([callbacks, 'access', _413 => _413.onError, 'optionalCall', _414 => _414(`Provider is disabled: ${provider.name}`)]);
|
|
6653
6814
|
return;
|
|
6654
6815
|
}
|
|
6655
6816
|
const { apiKey: effectiveKey } = _chunkA2YMUCBTcjs.resolveProviderEndpoint.call(void 0, provider);
|
|
6656
6817
|
const apiKey = resolveApiKey2(effectiveKey);
|
|
6657
6818
|
if (!apiKey) {
|
|
6658
|
-
_optionalChain([callbacks, 'access',
|
|
6819
|
+
_optionalChain([callbacks, 'access', _415 => _415.onError, 'optionalCall', _416 => _416("API key not configured")]);
|
|
6659
6820
|
return;
|
|
6660
6821
|
}
|
|
6661
6822
|
const messageId = `msg_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
6662
|
-
_optionalChain([callbacks, 'access',
|
|
6823
|
+
_optionalChain([callbacks, 'access', _417 => _417.onStart, 'optionalCall', _418 => _418(messageId)]);
|
|
6663
6824
|
const globalParams = await llmConfig.getGlobalModelParameters();
|
|
6664
6825
|
const MAX_ITERATIONS = _nullishCoalesce(globalParams.toolMaxTurns, () => ( 100));
|
|
6665
6826
|
let iteration = 0;
|
|
@@ -6706,12 +6867,12 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
6706
6867
|
});
|
|
6707
6868
|
if (!response.ok) {
|
|
6708
6869
|
const errorText = await response.text();
|
|
6709
|
-
_optionalChain([callbacks, 'access',
|
|
6870
|
+
_optionalChain([callbacks, 'access', _419 => _419.onError, 'optionalCall', _420 => _420(`API error (${response.status}): ${errorText}`)]);
|
|
6710
6871
|
return;
|
|
6711
6872
|
}
|
|
6712
|
-
const reader = _optionalChain([response, 'access',
|
|
6873
|
+
const reader = _optionalChain([response, 'access', _421 => _421.body, 'optionalAccess', _422 => _422.getReader, 'call', _423 => _423()]);
|
|
6713
6874
|
if (!reader) {
|
|
6714
|
-
_optionalChain([callbacks, 'access',
|
|
6875
|
+
_optionalChain([callbacks, 'access', _424 => _424.onError, 'optionalCall', _425 => _425("No response body")]);
|
|
6715
6876
|
return;
|
|
6716
6877
|
}
|
|
6717
6878
|
const decoder = new TextDecoder();
|
|
@@ -6744,7 +6905,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
6744
6905
|
logger.debug("Parsed JSON", { json });
|
|
6745
6906
|
if (json.error) {
|
|
6746
6907
|
logger.error("API Error", void 0, { error: json.error });
|
|
6747
|
-
_optionalChain([callbacks, 'access',
|
|
6908
|
+
_optionalChain([callbacks, 'access', _426 => _426.onError, 'optionalCall', _427 => _427(`API Error: ${json.error.message || JSON.stringify(json.error)}`)]);
|
|
6748
6909
|
return;
|
|
6749
6910
|
}
|
|
6750
6911
|
parseStreamChunk(json, apiFormat, callbacks, logger);
|
|
@@ -6777,7 +6938,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
6777
6938
|
toolCallsLength: toolCalls.length,
|
|
6778
6939
|
executableToolCallsLength: executableToolCalls.length,
|
|
6779
6940
|
hasMcpTools: !!options.mcpTools,
|
|
6780
|
-
mcpToolsLength: _optionalChain([options, 'access',
|
|
6941
|
+
mcpToolsLength: _optionalChain([options, 'access', _428 => _428.mcpTools, 'optionalAccess', _429 => _429.length]),
|
|
6781
6942
|
hasMcpService: !!mcpService
|
|
6782
6943
|
});
|
|
6783
6944
|
if (executableToolCalls.length > 0 && options.mcpTools && (mcpService || builtinExecutor)) {
|
|
@@ -6798,7 +6959,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
6798
6959
|
builtinExecutor
|
|
6799
6960
|
);
|
|
6800
6961
|
const toolResultsText = toolResults.map(({ toolCall, result }) => {
|
|
6801
|
-
const resultText = typeof result === "string" ? result : _optionalChain([result, 'access',
|
|
6962
|
+
const resultText = typeof result === "string" ? result : _optionalChain([result, 'access', _430 => _430.content, 'optionalAccess', _431 => _431[0], 'optionalAccess', _432 => _432.text]) || JSON.stringify(result);
|
|
6802
6963
|
return `Tool ${toolCall.name} result:
|
|
6803
6964
|
${resultText}`;
|
|
6804
6965
|
}).join("\n\n");
|
|
@@ -6816,12 +6977,12 @@ ${resultText}`;
|
|
|
6816
6977
|
}
|
|
6817
6978
|
} catch (streamError) {
|
|
6818
6979
|
logger.error("Stream processing error", streamError instanceof Error ? streamError : void 0);
|
|
6819
|
-
_optionalChain([callbacks, 'access',
|
|
6980
|
+
_optionalChain([callbacks, 'access', _433 => _433.onError, 'optionalCall', _434 => _434(`Stream error: ${streamError instanceof Error ? streamError.message : "Unknown error"}`)]);
|
|
6820
6981
|
return;
|
|
6821
6982
|
}
|
|
6822
6983
|
}
|
|
6823
6984
|
logger.info("Sending final callback", { blocksCount: blocks.length });
|
|
6824
|
-
_optionalChain([callbacks, 'access',
|
|
6985
|
+
_optionalChain([callbacks, 'access', _435 => _435.onDone, 'optionalCall', _436 => _436({
|
|
6825
6986
|
id: messageId,
|
|
6826
6987
|
role: "assistant",
|
|
6827
6988
|
content: finalContent,
|
|
@@ -6832,7 +6993,7 @@ ${resultText}`;
|
|
|
6832
6993
|
} catch (error) {
|
|
6833
6994
|
logger.error("Error in streamWithTools", error instanceof Error ? error : void 0);
|
|
6834
6995
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
6835
|
-
_optionalChain([callbacks, 'access',
|
|
6996
|
+
_optionalChain([callbacks, 'access', _437 => _437.onError, 'optionalCall', _438 => _438(message)]);
|
|
6836
6997
|
}
|
|
6837
6998
|
}
|
|
6838
6999
|
|
|
@@ -6883,8 +7044,8 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
|
|
|
6883
7044
|
options.providerId,
|
|
6884
7045
|
options.model
|
|
6885
7046
|
);
|
|
6886
|
-
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess',
|
|
6887
|
-
const actualModel = _optionalChain([routedInfo, 'optionalAccess',
|
|
7047
|
+
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _439 => _439.actualProviderId]) || options.providerId;
|
|
7048
|
+
const actualModel = _optionalChain([routedInfo, 'optionalAccess', _440 => _440.actualModelId]) || options.model;
|
|
6888
7049
|
const provider = await getProvider(actualProviderId);
|
|
6889
7050
|
if (!provider) {
|
|
6890
7051
|
return { success: false, error: `Provider not found: ${actualProviderId}` };
|
|
@@ -6914,7 +7075,8 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
|
|
|
6914
7075
|
name: provider.name,
|
|
6915
7076
|
baseUrl: provider.api_base_url,
|
|
6916
7077
|
apiKey,
|
|
6917
|
-
models: provider.models || []
|
|
7078
|
+
models: provider.models || [],
|
|
7079
|
+
modelConfigs: provider.modelConfigs
|
|
6918
7080
|
};
|
|
6919
7081
|
const executor = getSharedExecutor2();
|
|
6920
7082
|
const { response } = await _chunkMUHWHQVMcjs.executeProviderCall.call(void 0, {
|
|
@@ -6960,18 +7122,18 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
|
|
|
6960
7122
|
{ endpointTransformer: void 0 }
|
|
6961
7123
|
);
|
|
6962
7124
|
const data = await transformedResponse.json();
|
|
6963
|
-
const choice = _optionalChain([data, 'access',
|
|
7125
|
+
const choice = _optionalChain([data, 'access', _441 => _441.choices, 'optionalAccess', _442 => _442[0]]);
|
|
6964
7126
|
if (!choice) {
|
|
6965
7127
|
return { success: false, error: "No choices in response" };
|
|
6966
7128
|
}
|
|
6967
|
-
const rawToolCalls = _optionalChain([choice, 'access',
|
|
6968
|
-
const toolCalls = _optionalChain([rawToolCalls, 'optionalAccess',
|
|
7129
|
+
const rawToolCalls = _optionalChain([choice, 'access', _443 => _443.message, 'optionalAccess', _444 => _444.tool_calls]);
|
|
7130
|
+
const toolCalls = _optionalChain([rawToolCalls, 'optionalAccess', _445 => _445.map, 'call', _446 => _446((tc) => ({
|
|
6969
7131
|
id: tc.id,
|
|
6970
7132
|
name: tc.function.name,
|
|
6971
7133
|
args: typeof tc.function.arguments === "string" ? JSON.parse(tc.function.arguments) : tc.function.arguments
|
|
6972
7134
|
}))]);
|
|
6973
7135
|
const tapped = readUsageFromOpenAIResponse(data.usage);
|
|
6974
|
-
if (_optionalChain([recording, 'optionalAccess',
|
|
7136
|
+
if (_optionalChain([recording, 'optionalAccess', _447 => _447.recorder]) && tapped) {
|
|
6975
7137
|
recording.recorder.record({
|
|
6976
7138
|
messageId: _nullishCoalesce(options.messageId, () => ( null)),
|
|
6977
7139
|
parentMessageId: _nullishCoalesce(options.parentMessageId, () => ( null)),
|
|
@@ -6989,9 +7151,9 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
|
|
|
6989
7151
|
message: {
|
|
6990
7152
|
id: `msg_${Date.now()}`,
|
|
6991
7153
|
role: "assistant",
|
|
6992
|
-
content: _optionalChain([choice, 'access',
|
|
7154
|
+
content: _optionalChain([choice, 'access', _448 => _448.message, 'optionalAccess', _449 => _449.content]) || "",
|
|
6993
7155
|
timestamp: Date.now(),
|
|
6994
|
-
thinking: data.reasoning_content || _optionalChain([choice, 'access',
|
|
7156
|
+
thinking: data.reasoning_content || _optionalChain([choice, 'access', _450 => _450.message, 'optionalAccess', _451 => _451.thinking, 'optionalAccess', _452 => _452.content]) ? { content: data.reasoning_content || _optionalChain([choice, 'access', _453 => _453.message, 'optionalAccess', _454 => _454.thinking, 'optionalAccess', _455 => _455.content]) || "", signature: _optionalChain([choice, 'access', _456 => _456.message, 'optionalAccess', _457 => _457.thinking, 'optionalAccess', _458 => _458.signature]) } : void 0,
|
|
6995
7157
|
toolCalls
|
|
6996
7158
|
},
|
|
6997
7159
|
usage: data.usage ? {
|
|
@@ -7012,21 +7174,21 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
7012
7174
|
options.providerId,
|
|
7013
7175
|
options.model
|
|
7014
7176
|
);
|
|
7015
|
-
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess',
|
|
7016
|
-
const actualModel = _optionalChain([routedInfo, 'optionalAccess',
|
|
7177
|
+
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _459 => _459.actualProviderId]) || options.providerId;
|
|
7178
|
+
const actualModel = _optionalChain([routedInfo, 'optionalAccess', _460 => _460.actualModelId]) || options.model;
|
|
7017
7179
|
const provider = await getProvider(actualProviderId);
|
|
7018
7180
|
if (!provider) {
|
|
7019
|
-
_optionalChain([callbacks, 'access',
|
|
7181
|
+
_optionalChain([callbacks, 'access', _461 => _461.onError, 'optionalCall', _462 => _462(`Provider not found: ${actualProviderId}`)]);
|
|
7020
7182
|
return;
|
|
7021
7183
|
}
|
|
7022
7184
|
if (!provider.enabled) {
|
|
7023
|
-
_optionalChain([callbacks, 'access',
|
|
7185
|
+
_optionalChain([callbacks, 'access', _463 => _463.onError, 'optionalCall', _464 => _464(`Provider is disabled: ${provider.name}`)]);
|
|
7024
7186
|
return;
|
|
7025
7187
|
}
|
|
7026
7188
|
const { apiKey: effectiveKey } = _chunkA2YMUCBTcjs.resolveProviderEndpoint.call(void 0, provider);
|
|
7027
7189
|
const apiKey = resolveApiKey2(effectiveKey);
|
|
7028
7190
|
if (!apiKey) {
|
|
7029
|
-
_optionalChain([callbacks, 'access',
|
|
7191
|
+
_optionalChain([callbacks, 'access', _465 => _465.onError, 'optionalCall', _466 => _466("API key not configured")]);
|
|
7030
7192
|
return;
|
|
7031
7193
|
}
|
|
7032
7194
|
const { chain, hasTransformers } = await resolveChainWithMain(
|
|
@@ -7038,13 +7200,14 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
7038
7200
|
return completeStreamFallback(options, callbacks);
|
|
7039
7201
|
}
|
|
7040
7202
|
const messageId = `msg_${Date.now()}`;
|
|
7041
|
-
_optionalChain([callbacks, 'access',
|
|
7203
|
+
_optionalChain([callbacks, 'access', _467 => _467.onStart, 'optionalCall', _468 => _468(messageId)]);
|
|
7042
7204
|
const unifiedRequest = buildUnifiedCompletionRequest(actualModel, options, true);
|
|
7043
7205
|
const transformerProvider = {
|
|
7044
7206
|
name: provider.name,
|
|
7045
7207
|
baseUrl: provider.api_base_url,
|
|
7046
7208
|
apiKey,
|
|
7047
|
-
models: provider.models || []
|
|
7209
|
+
models: provider.models || [],
|
|
7210
|
+
modelConfigs: provider.modelConfigs
|
|
7048
7211
|
};
|
|
7049
7212
|
const executor = getSharedExecutor2();
|
|
7050
7213
|
const { response } = await _chunkMUHWHQVMcjs.executeProviderCall.call(void 0, {
|
|
@@ -7077,7 +7240,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
7077
7240
|
});
|
|
7078
7241
|
if (!response.ok) {
|
|
7079
7242
|
const errorText = await response.text();
|
|
7080
|
-
_optionalChain([callbacks, 'access',
|
|
7243
|
+
_optionalChain([callbacks, 'access', _469 => _469.onError, 'optionalCall', _470 => _470(`API error (${response.status}): ${errorText}`)]);
|
|
7081
7244
|
return;
|
|
7082
7245
|
}
|
|
7083
7246
|
const transformedResponse = await executor.executeResponseChain(
|
|
@@ -7087,9 +7250,9 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
7087
7250
|
chain,
|
|
7088
7251
|
{ endpointTransformer: void 0 }
|
|
7089
7252
|
);
|
|
7090
|
-
const reader = _optionalChain([transformedResponse, 'access',
|
|
7253
|
+
const reader = _optionalChain([transformedResponse, 'access', _471 => _471.body, 'optionalAccess', _472 => _472.getReader, 'call', _473 => _473()]);
|
|
7091
7254
|
if (!reader) {
|
|
7092
|
-
_optionalChain([callbacks, 'access',
|
|
7255
|
+
_optionalChain([callbacks, 'access', _474 => _474.onError, 'optionalCall', _475 => _475("No response body")]);
|
|
7093
7256
|
return;
|
|
7094
7257
|
}
|
|
7095
7258
|
const decoder = new TextDecoder();
|
|
@@ -7107,22 +7270,22 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
7107
7270
|
if (data === "[DONE]") continue;
|
|
7108
7271
|
try {
|
|
7109
7272
|
const json = JSON.parse(data);
|
|
7110
|
-
const delta = _optionalChain([json, 'access',
|
|
7111
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
7273
|
+
const delta = _optionalChain([json, 'access', _476 => _476.choices, 'optionalAccess', _477 => _477[0], 'optionalAccess', _478 => _478.delta]);
|
|
7274
|
+
if (_optionalChain([delta, 'optionalAccess', _479 => _479.content])) {
|
|
7112
7275
|
content += delta.content;
|
|
7113
|
-
_optionalChain([callbacks, 'access',
|
|
7276
|
+
_optionalChain([callbacks, 'access', _480 => _480.onDelta, 'optionalCall', _481 => _481(delta.content)]);
|
|
7114
7277
|
}
|
|
7115
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
7278
|
+
if (_optionalChain([delta, 'optionalAccess', _482 => _482.thinking, 'optionalAccess', _483 => _483.content])) {
|
|
7116
7279
|
reasoning += delta.thinking.content;
|
|
7117
|
-
_optionalChain([callbacks, 'access',
|
|
7280
|
+
_optionalChain([callbacks, 'access', _484 => _484.onReasoning, 'optionalCall', _485 => _485(delta.thinking.content)]);
|
|
7118
7281
|
}
|
|
7119
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
7282
|
+
if (_optionalChain([delta, 'optionalAccess', _486 => _486.reasoning_content])) {
|
|
7120
7283
|
reasoning += delta.reasoning_content;
|
|
7121
|
-
_optionalChain([callbacks, 'access',
|
|
7284
|
+
_optionalChain([callbacks, 'access', _487 => _487.onReasoning, 'optionalCall', _488 => _488(delta.reasoning_content)]);
|
|
7122
7285
|
}
|
|
7123
7286
|
if (json.usage) {
|
|
7124
7287
|
const tapped = readUsageFromOpenAIResponse(json.usage);
|
|
7125
|
-
if (_optionalChain([recording, 'optionalAccess',
|
|
7288
|
+
if (_optionalChain([recording, 'optionalAccess', _489 => _489.recorder]) && tapped) {
|
|
7126
7289
|
recording.recorder.record({
|
|
7127
7290
|
messageId: _nullishCoalesce(options.messageId, () => ( null)),
|
|
7128
7291
|
parentMessageId: _nullishCoalesce(options.parentMessageId, () => ( null)),
|
|
@@ -7135,7 +7298,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
7135
7298
|
rawUsage: json.usage
|
|
7136
7299
|
});
|
|
7137
7300
|
}
|
|
7138
|
-
_optionalChain([callbacks, 'access',
|
|
7301
|
+
_optionalChain([callbacks, 'access', _490 => _490.onDone, 'optionalCall', _491 => _491(
|
|
7139
7302
|
{
|
|
7140
7303
|
id: messageId,
|
|
7141
7304
|
role: "assistant",
|
|
@@ -7156,7 +7319,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
7156
7319
|
}
|
|
7157
7320
|
}
|
|
7158
7321
|
}
|
|
7159
|
-
_optionalChain([callbacks, 'access',
|
|
7322
|
+
_optionalChain([callbacks, 'access', _492 => _492.onDone, 'optionalCall', _493 => _493({
|
|
7160
7323
|
id: messageId,
|
|
7161
7324
|
role: "assistant",
|
|
7162
7325
|
content,
|
|
@@ -7168,7 +7331,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
7168
7331
|
}
|
|
7169
7332
|
} catch (error) {
|
|
7170
7333
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
7171
|
-
_optionalChain([callbacks, 'access',
|
|
7334
|
+
_optionalChain([callbacks, 'access', _494 => _494.onError, 'optionalCall', _495 => _495(message)]);
|
|
7172
7335
|
}
|
|
7173
7336
|
}
|
|
7174
7337
|
|
|
@@ -7235,8 +7398,8 @@ var CompletionService = (_class15 = class {
|
|
|
7235
7398
|
options.providerId,
|
|
7236
7399
|
options.model
|
|
7237
7400
|
);
|
|
7238
|
-
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess',
|
|
7239
|
-
const actualModel = _optionalChain([routedInfo, 'optionalAccess',
|
|
7401
|
+
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _496 => _496.actualProviderId]) || options.providerId;
|
|
7402
|
+
const actualModel = _optionalChain([routedInfo, 'optionalAccess', _497 => _497.actualModelId]) || options.model;
|
|
7240
7403
|
const provider = await this.getProvider(actualProviderId);
|
|
7241
7404
|
if (!provider) {
|
|
7242
7405
|
return { success: false, error: `Provider not found: ${actualProviderId}` };
|
|
@@ -7269,7 +7432,7 @@ var CompletionService = (_class15 = class {
|
|
|
7269
7432
|
this.apiKeyPool.reportSuccess(options.sessionId);
|
|
7270
7433
|
}
|
|
7271
7434
|
if (result.success && result.usage && options.sessionId) {
|
|
7272
|
-
_optionalChain([this, 'access',
|
|
7435
|
+
_optionalChain([this, 'access', _498 => _498.usageEventSink, 'optionalAccess', _499 => _499.emit, 'call', _500 => _500({
|
|
7273
7436
|
sessionId: options.sessionId,
|
|
7274
7437
|
modelId: actualModel,
|
|
7275
7438
|
usage: result.usage,
|
|
@@ -7298,8 +7461,8 @@ var CompletionService = (_class15 = class {
|
|
|
7298
7461
|
options.model
|
|
7299
7462
|
);
|
|
7300
7463
|
this.logger.debug("Resolved routed model", { routedInfo });
|
|
7301
|
-
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess',
|
|
7302
|
-
const actualModel = _optionalChain([routedInfo, 'optionalAccess',
|
|
7464
|
+
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _501 => _501.actualProviderId]) || options.providerId;
|
|
7465
|
+
const actualModel = _optionalChain([routedInfo, 'optionalAccess', _502 => _502.actualModelId]) || options.model;
|
|
7303
7466
|
this.logger.debug("Resolved provider and model", { actualProviderId, actualModel });
|
|
7304
7467
|
const provider = await this.getProvider(actualProviderId);
|
|
7305
7468
|
this.logger.debug("Retrieved provider", provider ? {
|
|
@@ -7311,22 +7474,22 @@ var CompletionService = (_class15 = class {
|
|
|
7311
7474
|
enabled: provider.enabled
|
|
7312
7475
|
} : { error: "Provider not found" });
|
|
7313
7476
|
if (!provider) {
|
|
7314
|
-
_optionalChain([callbacks, 'access',
|
|
7477
|
+
_optionalChain([callbacks, 'access', _503 => _503.onError, 'optionalCall', _504 => _504(`Provider not found: ${actualProviderId}`)]);
|
|
7315
7478
|
return;
|
|
7316
7479
|
}
|
|
7317
7480
|
if (!provider.enabled) {
|
|
7318
|
-
_optionalChain([callbacks, 'access',
|
|
7481
|
+
_optionalChain([callbacks, 'access', _505 => _505.onError, 'optionalCall', _506 => _506(`Provider is disabled: ${provider.name}`)]);
|
|
7319
7482
|
return;
|
|
7320
7483
|
}
|
|
7321
7484
|
const apiKey = await this.resolveApiKeyForRequest(provider, actualProviderId, options.sessionId);
|
|
7322
7485
|
if (!apiKey) {
|
|
7323
|
-
_optionalChain([callbacks, 'access',
|
|
7486
|
+
_optionalChain([callbacks, 'access', _507 => _507.onError, 'optionalCall', _508 => _508("API key not configured")]);
|
|
7324
7487
|
return;
|
|
7325
7488
|
}
|
|
7326
7489
|
const apiFormat = _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider);
|
|
7327
7490
|
this.logger.info("Using API format for stream", { apiFormat });
|
|
7328
7491
|
const messageId = `msg_${Date.now()}`;
|
|
7329
|
-
_optionalChain([callbacks, 'access',
|
|
7492
|
+
_optionalChain([callbacks, 'access', _509 => _509.onStart, 'optionalCall', _510 => _510(messageId)]);
|
|
7330
7493
|
const resolvedOptions = { ...options, model: actualModel };
|
|
7331
7494
|
if (options.sessionId) {
|
|
7332
7495
|
const sid = options.sessionId;
|
|
@@ -7335,14 +7498,14 @@ var CompletionService = (_class15 = class {
|
|
|
7335
7498
|
...callbacks,
|
|
7336
7499
|
onDone: (message, usage, metrics) => {
|
|
7337
7500
|
if (usage) {
|
|
7338
|
-
_optionalChain([this, 'access',
|
|
7501
|
+
_optionalChain([this, 'access', _511 => _511.usageEventSink, 'optionalAccess', _512 => _512.emit, 'call', _513 => _513({
|
|
7339
7502
|
sessionId: sid,
|
|
7340
7503
|
modelId: actualModel,
|
|
7341
7504
|
usage,
|
|
7342
7505
|
engineOrigin: "completion"
|
|
7343
7506
|
})]);
|
|
7344
7507
|
}
|
|
7345
|
-
_optionalChain([userOnDone, 'optionalCall',
|
|
7508
|
+
_optionalChain([userOnDone, 'optionalCall', _514 => _514(message, usage, metrics)]);
|
|
7346
7509
|
}
|
|
7347
7510
|
};
|
|
7348
7511
|
}
|
|
@@ -7358,11 +7521,11 @@ var CompletionService = (_class15 = class {
|
|
|
7358
7521
|
retryState.error = { status, message: error };
|
|
7359
7522
|
return;
|
|
7360
7523
|
}
|
|
7361
|
-
_optionalChain([callbacks, 'access',
|
|
7524
|
+
_optionalChain([callbacks, 'access', _515 => _515.onError, 'optionalCall', _516 => _516(error)]);
|
|
7362
7525
|
},
|
|
7363
7526
|
onDone: (message, usage, metrics) => {
|
|
7364
7527
|
this.apiKeyPool.reportSuccess(options.sessionId);
|
|
7365
|
-
_optionalChain([callbacks, 'access',
|
|
7528
|
+
_optionalChain([callbacks, 'access', _517 => _517.onDone, 'optionalCall', _518 => _518(message, usage, metrics)]);
|
|
7366
7529
|
}
|
|
7367
7530
|
};
|
|
7368
7531
|
await this.callStreamHandler(apiFormat, provider, apiKey, resolvedOptions, messageId, interceptCallbacks);
|
|
@@ -7383,7 +7546,7 @@ var CompletionService = (_class15 = class {
|
|
|
7383
7546
|
// don't fire onStart again
|
|
7384
7547
|
});
|
|
7385
7548
|
} else {
|
|
7386
|
-
_optionalChain([callbacks, 'access',
|
|
7549
|
+
_optionalChain([callbacks, 'access', _519 => _519.onError, 'optionalCall', _520 => _520(retryState.error.message)]);
|
|
7387
7550
|
}
|
|
7388
7551
|
}
|
|
7389
7552
|
} else {
|
|
@@ -7396,7 +7559,7 @@ var CompletionService = (_class15 = class {
|
|
|
7396
7559
|
} catch (error) {
|
|
7397
7560
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
7398
7561
|
this.logger.error("Stream completion error", error instanceof Error ? error : void 0, { message });
|
|
7399
|
-
_optionalChain([callbacks, 'access',
|
|
7562
|
+
_optionalChain([callbacks, 'access', _521 => _521.onError, 'optionalCall', _522 => _522(message)]);
|
|
7400
7563
|
}
|
|
7401
7564
|
}
|
|
7402
7565
|
/**
|
|
@@ -7436,7 +7599,7 @@ var CompletionService = (_class15 = class {
|
|
|
7436
7599
|
return {
|
|
7437
7600
|
success: true,
|
|
7438
7601
|
message: "Connection successful",
|
|
7439
|
-
response: _optionalChain([result, 'access',
|
|
7602
|
+
response: _optionalChain([result, 'access', _523 => _523.message, 'optionalAccess', _524 => _524.content]) || "",
|
|
7440
7603
|
model: modelId,
|
|
7441
7604
|
durationMs
|
|
7442
7605
|
};
|
|
@@ -7501,7 +7664,7 @@ ${description}`;
|
|
|
7501
7664
|
* 3. Legacy single key from provider config
|
|
7502
7665
|
*/
|
|
7503
7666
|
async resolveApiKeyForRequest(provider, providerId, sessionId) {
|
|
7504
|
-
if (_optionalChain([provider, 'access',
|
|
7667
|
+
if (_optionalChain([provider, 'access', _525 => _525.codingPlan, 'optionalAccess', _526 => _526.enabled]) && provider.codingPlan.apiKey) {
|
|
7505
7668
|
return this.resolveApiKey(provider.codingPlan.apiKey);
|
|
7506
7669
|
}
|
|
7507
7670
|
if (this.apiKeyPool) {
|