@omnicross/core 0.1.8 → 0.1.9
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-77USGNRW.cjs +37 -0
- package/dist/chunk-AOFWNWLT.cjs +203 -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-CQIJCPMF.js} +177 -77
- 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-KBM2W6UY.cjs → chunk-RICPANBY.cjs} +41 -24
- package/dist/{chunk-TOVPMMHM.js → chunk-S3DYFEBE.js} +37 -20
- package/dist/chunk-WYVGULTQ.js +37 -0
- package/dist/{chunk-26K6T2YS.cjs → chunk-XELFM7KL.cjs} +301 -201
- package/dist/{chunk-OXHNSZ53.cjs → chunk-ZQQUD66M.cjs} +54 -60
- package/dist/completion/CompletionService.cjs +12 -10
- package/dist/completion/CompletionService.js +11 -9
- package/dist/completion.cjs +12 -10
- package/dist/completion.js +11 -9
- package/dist/index.cjs +12 -10
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +11 -9
- 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 +12 -10
- package/dist/outbound-api.d.cts +1 -1
- package/dist/outbound-api.d.ts +1 -1
- package/dist/outbound-api.js +11 -9
- 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 +12 -10
- package/dist/provider-proxy/ProviderProxy.js +11 -9
- package/dist/provider-proxy/ingress/providerProxyShared.cjs +12 -10
- package/dist/provider-proxy/ingress/providerProxyShared.js +11 -9
- package/dist/provider-proxy.cjs +12 -10
- package/dist/provider-proxy.js +11 -9
- 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/package.json +1 -1
- /package/dist/{chunk-FZ46M34D.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');
|
|
@@ -111,6 +111,9 @@ var _chunkXPIOJQS2cjs = require('./chunk-XPIOJQS2.cjs');
|
|
|
111
111
|
var _chunkGDIXXKF2cjs = require('./chunk-GDIXXKF2.cjs');
|
|
112
112
|
|
|
113
113
|
|
|
114
|
+
var _chunkAOFWNWLTcjs = require('./chunk-AOFWNWLT.cjs');
|
|
115
|
+
|
|
116
|
+
|
|
114
117
|
var _chunkRJUONLUQcjs = require('./chunk-RJUONLUQ.cjs');
|
|
115
118
|
|
|
116
119
|
|
|
@@ -413,9 +416,6 @@ function addOpenRouterProviderToRequest(requestBody, provider, modelId) {
|
|
|
413
416
|
};
|
|
414
417
|
}
|
|
415
418
|
|
|
416
|
-
// src/completion/DirectApiHandler.ts
|
|
417
|
-
var _thinkingconfig = require('@omnicross/contracts/thinking-config');
|
|
418
|
-
|
|
419
419
|
// src/provider-proxy/ProviderProxy.ts
|
|
420
420
|
var _http = require('http'); var _http2 = _interopRequireDefault(_http);
|
|
421
421
|
|
|
@@ -651,17 +651,17 @@ function getSharedExecutor() {
|
|
|
651
651
|
}
|
|
652
652
|
var sharedResponses = null;
|
|
653
653
|
function getResponsesEndpointTransformer() {
|
|
654
|
-
if (!sharedResponses) sharedResponses = new (0,
|
|
654
|
+
if (!sharedResponses) sharedResponses = new (0, _chunkCMVXX7ONcjs.OpenAIResponseTransformer)();
|
|
655
655
|
return sharedResponses;
|
|
656
656
|
}
|
|
657
657
|
var sharedAnthropic = null;
|
|
658
658
|
function getAnthropicEndpointTransformer() {
|
|
659
|
-
if (!sharedAnthropic) sharedAnthropic = new (0,
|
|
659
|
+
if (!sharedAnthropic) sharedAnthropic = new (0, _chunkZQQUD66Mcjs.AnthropicTransformer)();
|
|
660
660
|
return sharedAnthropic;
|
|
661
661
|
}
|
|
662
662
|
var sharedGemini = null;
|
|
663
663
|
function getGeminiEndpointTransformer() {
|
|
664
|
-
if (!sharedGemini) sharedGemini = new (0,
|
|
664
|
+
if (!sharedGemini) sharedGemini = new (0, _chunk5LNYGCIWcjs.GeminiTransformer)();
|
|
665
665
|
return sharedGemini;
|
|
666
666
|
}
|
|
667
667
|
function readBody(req) {
|
|
@@ -1432,7 +1432,8 @@ async function buildByoPlan(res, route, deps, resolvedModel, isStream) {
|
|
|
1432
1432
|
name: provider.name,
|
|
1433
1433
|
baseUrl: provider.api_base_url,
|
|
1434
1434
|
apiKey,
|
|
1435
|
-
models: provider.models || []
|
|
1435
|
+
models: provider.models || [],
|
|
1436
|
+
modelConfigs: provider.modelConfigs
|
|
1436
1437
|
};
|
|
1437
1438
|
const byoUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: resolvedModel, stream: isStream });
|
|
1438
1439
|
const sameFormat = route.targetProviderFormat === "anthropic" || _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider) === "anthropic";
|
|
@@ -1740,7 +1741,8 @@ async function buildByoPlan2(res, route, deps, resolvedModel, isStream) {
|
|
|
1740
1741
|
name: provider.name,
|
|
1741
1742
|
baseUrl: provider.api_base_url,
|
|
1742
1743
|
apiKey,
|
|
1743
|
-
models: provider.models || []
|
|
1744
|
+
models: provider.models || [],
|
|
1745
|
+
modelConfigs: provider.modelConfigs
|
|
1744
1746
|
};
|
|
1745
1747
|
const byoUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: resolvedModel, stream: isStream });
|
|
1746
1748
|
return {
|
|
@@ -1957,7 +1959,8 @@ async function buildByoPlan3(res, route, deps, resolvedModel, isStream) {
|
|
|
1957
1959
|
name: provider.name,
|
|
1958
1960
|
baseUrl: provider.api_base_url,
|
|
1959
1961
|
apiKey,
|
|
1960
|
-
models: provider.models || []
|
|
1962
|
+
models: provider.models || [],
|
|
1963
|
+
modelConfigs: provider.modelConfigs
|
|
1961
1964
|
};
|
|
1962
1965
|
const byoUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: resolvedModel, stream: isStream });
|
|
1963
1966
|
return {
|
|
@@ -2351,7 +2354,8 @@ async function buildByoPlan4(res, route, deps, resolvedModel, isStream) {
|
|
|
2351
2354
|
name: provider.name,
|
|
2352
2355
|
baseUrl: provider.api_base_url,
|
|
2353
2356
|
apiKey,
|
|
2354
|
-
models: provider.models || []
|
|
2357
|
+
models: provider.models || [],
|
|
2358
|
+
modelConfigs: provider.modelConfigs
|
|
2355
2359
|
};
|
|
2356
2360
|
const byoUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: resolvedModel, stream: isStream });
|
|
2357
2361
|
return {
|
|
@@ -3562,6 +3566,7 @@ var KeyedMutex = (_class5 = class {constructor() { _class5.prototype.__init11.ca
|
|
|
3562
3566
|
|
|
3563
3567
|
// src/outbound-api/outboundApiRouter.ts
|
|
3564
3568
|
var _stream = require('stream');
|
|
3569
|
+
var _subscriptionmodelcatalog = require('@omnicross/contracts/subscription-model-catalog');
|
|
3565
3570
|
|
|
3566
3571
|
// src/outbound-api/apiServerConfig.ts
|
|
3567
3572
|
var _audittypes = require('@omnicross/contracts/audit-types');
|
|
@@ -4987,33 +4992,51 @@ function isModelsListRequest(url) {
|
|
|
4987
4992
|
const path = _nullishCoalesce(_optionalChain([url, 'access', _253 => _253.split, 'call', _254 => _254("?"), 'access', _255 => _255[0], 'optionalAccess', _256 => _256.replace, 'call', _257 => _257(/\/+$/, "")]), () => ( ""));
|
|
4988
4993
|
return path.endsWith("/models");
|
|
4989
4994
|
}
|
|
4990
|
-
function writeModelsList(res, config, apiKeyId, allowedEndpoints) {
|
|
4991
|
-
const
|
|
4992
|
-
const endpointConfigs = [];
|
|
4995
|
+
async function writeModelsList(res, llmConfig, config, apiKeyId, allowedEndpoints) {
|
|
4996
|
+
const modelIds = [];
|
|
4993
4997
|
for (const endpoint of ["chat", "responses", "messages", "gemini"]) {
|
|
4994
4998
|
if (allowedEndpoints && !allowedEndpoints.includes(endpoint)) continue;
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
(binding
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
4999
|
+
for (const binding of candidateGatewayBindings(config.bindings, apiKeyId, endpoint)) {
|
|
5000
|
+
if (binding.modelMode === "passthrough") {
|
|
5001
|
+
if (binding.target.kind === "provider") {
|
|
5002
|
+
const provider = await llmConfig.getProvider(binding.target.providerId);
|
|
5003
|
+
modelIds.push(..._nullishCoalesce(_optionalChain([provider, 'optionalAccess', _258 => _258.models]), () => ( [])));
|
|
5004
|
+
} else if (Object.prototype.hasOwnProperty.call(
|
|
5005
|
+
_subscriptionmodelcatalog.SUBSCRIPTION_MODEL_CATALOG,
|
|
5006
|
+
binding.target.providerId
|
|
5007
|
+
)) {
|
|
5008
|
+
modelIds.push(
|
|
5009
|
+
..._subscriptionmodelcatalog.SUBSCRIPTION_MODEL_CATALOG[binding.target.providerId]
|
|
5010
|
+
);
|
|
5011
|
+
}
|
|
5012
|
+
continue;
|
|
5013
|
+
}
|
|
5014
|
+
if (_optionalChain([binding, 'access', _259 => _259.modelMappings, 'optionalAccess', _260 => _260.length])) {
|
|
5015
|
+
modelIds.push(
|
|
5016
|
+
...binding.modelMappings.map((mapping) => mapping.source.trim()).filter((source) => source !== "" && !source.includes("*"))
|
|
5017
|
+
);
|
|
5018
|
+
continue;
|
|
5019
|
+
}
|
|
5020
|
+
const endpointConfig = gatewayBindingToEndpointConfig(binding);
|
|
5021
|
+
const refs = [];
|
|
5022
|
+
if (endpointConfig.endpoint === "chat") refs.push(..._nullishCoalesce(endpointConfig.models, () => ( [])));
|
|
5023
|
+
else if (endpointConfig.endpoint === "messages" || endpointConfig.endpoint === "responses") {
|
|
5024
|
+
refs.push(...Object.values(_nullishCoalesce(endpointConfig.modelMap, () => ( {}))));
|
|
5025
|
+
} else {
|
|
5026
|
+
if (endpointConfig.defaultModel) refs.push(endpointConfig.defaultModel);
|
|
5027
|
+
if (endpointConfig.backgroundModel) refs.push(endpointConfig.backgroundModel);
|
|
5028
|
+
}
|
|
5029
|
+
modelIds.push(
|
|
5030
|
+
...refs.map((ref) => _optionalChain([_chunk4VZX5F4Tcjs.parseModelRef.call(void 0, ref), 'optionalAccess', _261 => _261.modelId])).filter((modelId) => modelId !== void 0)
|
|
5031
|
+
);
|
|
5009
5032
|
}
|
|
5010
5033
|
}
|
|
5011
5034
|
const seen = /* @__PURE__ */ new Set();
|
|
5012
|
-
const data =
|
|
5013
|
-
if (seen.has(
|
|
5014
|
-
seen.add(
|
|
5035
|
+
const data = modelIds.filter((modelId) => {
|
|
5036
|
+
if (seen.has(modelId)) return false;
|
|
5037
|
+
seen.add(modelId);
|
|
5015
5038
|
return true;
|
|
5016
|
-
}).map((
|
|
5039
|
+
}).map((modelId) => ({ id: modelId, object: "model", owned_by: "omnicross" }));
|
|
5017
5040
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
5018
5041
|
res.end(JSON.stringify({ object: "list", data }));
|
|
5019
5042
|
}
|
|
@@ -5047,7 +5070,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
5047
5070
|
const verified = verification.key;
|
|
5048
5071
|
if (audit) audit.keyId = verified.id;
|
|
5049
5072
|
if (billing) billing.keyId = verified.id;
|
|
5050
|
-
if (verified.loopbackOnly && !isLoopbackPeer(_optionalChain([req, 'access',
|
|
5073
|
+
if (verified.loopbackOnly && !isLoopbackPeer(_optionalChain([req, 'access', _262 => _262.socket, 'optionalAccess', _263 => _263.remoteAddress]))) {
|
|
5051
5074
|
writeJsonError(res, 403, "This integration key is restricted to loopback clients");
|
|
5052
5075
|
return;
|
|
5053
5076
|
}
|
|
@@ -5060,7 +5083,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
5060
5083
|
req,
|
|
5061
5084
|
res,
|
|
5062
5085
|
deps,
|
|
5063
|
-
_optionalChain([config, 'access',
|
|
5086
|
+
_optionalChain([config, 'access', _264 => _264.voucher, 'optionalAccess', _265 => _265.enabled]) === true,
|
|
5064
5087
|
_nullishCoalesce(redeemLimiter, () => ( getFallbackRedeemLimiter())),
|
|
5065
5088
|
verified.id,
|
|
5066
5089
|
_nullishCoalesce(presented, () => ( "")),
|
|
@@ -5081,7 +5104,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
5081
5104
|
writeJsonError(res, 403, "API key is not allowed to access this endpoint");
|
|
5082
5105
|
return;
|
|
5083
5106
|
}
|
|
5084
|
-
writeModelsList(res, config, verified.id, verified.allowedEndpoints);
|
|
5107
|
+
await writeModelsList(res, deps.llmConfig, config, verified.id, verified.allowedEndpoints);
|
|
5085
5108
|
return;
|
|
5086
5109
|
}
|
|
5087
5110
|
const endpoint = selectEndpoint(req.method, req.url);
|
|
@@ -5229,7 +5252,7 @@ async function handleOutboundRequest(req, res, deps, config, rateLimiter, serial
|
|
|
5229
5252
|
}
|
|
5230
5253
|
let releaseSerial = null;
|
|
5231
5254
|
const providerKey = resolved.route.providerId;
|
|
5232
|
-
if (_optionalChain([config, 'access',
|
|
5255
|
+
if (_optionalChain([config, 'access', _266 => _266.userMessageQueue, 'optionalAccess', _267 => _267.enabled]) && providerKey && isUserMessageRequest(endpoint, parsedBody)) {
|
|
5233
5256
|
const umq = config.userMessageQueue;
|
|
5234
5257
|
try {
|
|
5235
5258
|
const serialSlot = await serialQueue.acquire(providerKey, {
|
|
@@ -5369,7 +5392,7 @@ var OutboundApiServer = (_class13 = class {
|
|
|
5369
5392
|
const actualPort = await this.listen(bindAddr, port);
|
|
5370
5393
|
this.boundAddr = bindAddr;
|
|
5371
5394
|
this.boundPort = actualPort;
|
|
5372
|
-
if (actualPort !== port) _optionalChain([this, 'access',
|
|
5395
|
+
if (actualPort !== port) _optionalChain([this, 'access', _268 => _268.onPortChange, 'optionalCall', _269 => _269(actualPort)]);
|
|
5373
5396
|
this.logInfo(`[OutboundApiServer] Listening on ${bindAddr}:${actualPort}`);
|
|
5374
5397
|
return actualPort;
|
|
5375
5398
|
}
|
|
@@ -5438,7 +5461,7 @@ var OutboundApiServer = (_class13 = class {
|
|
|
5438
5461
|
const provider = this.deps.healthReportProvider;
|
|
5439
5462
|
if (!provider) return false;
|
|
5440
5463
|
if (req.method !== "GET" && req.method !== "HEAD") return false;
|
|
5441
|
-
const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access',
|
|
5464
|
+
const path = _optionalChain([(_nullishCoalesce(req.url, () => ( "/"))), 'access', _270 => _270.split, 'call', _271 => _271("?"), 'access', _272 => _272[0], 'optionalAccess', _273 => _273.replace, 'call', _274 => _274(/\/+$/, "")]) || "/";
|
|
5442
5465
|
if (path !== "/health" && path !== "/healthz") return false;
|
|
5443
5466
|
const report = provider();
|
|
5444
5467
|
res.writeHead(_healthloggingtypes.healthHttpStatus.call(void 0, report.status), { "Content-Type": "application/json" });
|
|
@@ -5637,6 +5660,70 @@ function __resetOutboundApiServerForTests() {
|
|
|
5637
5660
|
instance2 = null;
|
|
5638
5661
|
}
|
|
5639
5662
|
|
|
5663
|
+
// src/completion/ReasoningRequestBuilder.ts
|
|
5664
|
+
var LEGACY_ANTHROPIC_MAX_TOKENS = 16384;
|
|
5665
|
+
function intentFromOptions(options) {
|
|
5666
|
+
return options.thinkLevel ? { effort: options.thinkLevel, enabled: options.thinkLevel !== "none" } : void 0;
|
|
5667
|
+
}
|
|
5668
|
+
function resolveCompletionReasoningPlan(provider, options, target, requestMaxTokens = options.maxTokens) {
|
|
5669
|
+
return _chunkAOFWNWLTcjs.resolveReasoningPlan.call(void 0, {
|
|
5670
|
+
intent: intentFromOptions(options),
|
|
5671
|
+
model: options.model,
|
|
5672
|
+
provider,
|
|
5673
|
+
target,
|
|
5674
|
+
requestMaxTokens
|
|
5675
|
+
});
|
|
5676
|
+
}
|
|
5677
|
+
function resolveOpenAIEffort(provider, options, target) {
|
|
5678
|
+
const plan = resolveCompletionReasoningPlan(provider, options, target);
|
|
5679
|
+
return _optionalChain([plan, 'optionalAccess', _275 => _275.kind]) === "level" && plan.enabled ? plan.effort : void 0;
|
|
5680
|
+
}
|
|
5681
|
+
function buildAnthropicReasoningWire(provider, options) {
|
|
5682
|
+
const configuredMaxTokens = _nullishCoalesce(options.maxTokens, () => ( LEGACY_ANTHROPIC_MAX_TOKENS));
|
|
5683
|
+
const legacyBound = Math.min(configuredMaxTokens, LEGACY_ANTHROPIC_MAX_TOKENS);
|
|
5684
|
+
const plan = resolveCompletionReasoningPlan(
|
|
5685
|
+
provider,
|
|
5686
|
+
options,
|
|
5687
|
+
"anthropic",
|
|
5688
|
+
legacyBound
|
|
5689
|
+
);
|
|
5690
|
+
if (_optionalChain([plan, 'optionalAccess', _276 => _276.kind]) === "level" && plan.enabled) {
|
|
5691
|
+
return {
|
|
5692
|
+
effectiveMaxTokens: configuredMaxTokens,
|
|
5693
|
+
thinking: { type: "adaptive" },
|
|
5694
|
+
outputConfig: { effort: plan.effort },
|
|
5695
|
+
legacyBudgetEnabled: false
|
|
5696
|
+
};
|
|
5697
|
+
}
|
|
5698
|
+
if (_optionalChain([plan, 'optionalAccess', _277 => _277.kind]) === "budget" && plan.enabled) {
|
|
5699
|
+
return {
|
|
5700
|
+
effectiveMaxTokens: legacyBound,
|
|
5701
|
+
thinking: { type: "enabled", budget_tokens: plan.budgetTokens },
|
|
5702
|
+
legacyBudgetEnabled: true
|
|
5703
|
+
};
|
|
5704
|
+
}
|
|
5705
|
+
return {
|
|
5706
|
+
effectiveMaxTokens: configuredMaxTokens,
|
|
5707
|
+
legacyBudgetEnabled: false
|
|
5708
|
+
};
|
|
5709
|
+
}
|
|
5710
|
+
function buildGeminiThinkingConfig(provider, options) {
|
|
5711
|
+
const plan = resolveCompletionReasoningPlan(provider, options, "gemini");
|
|
5712
|
+
if (_optionalChain([plan, 'optionalAccess', _278 => _278.kind]) === "level") {
|
|
5713
|
+
return {
|
|
5714
|
+
includeThoughts: plan.enabled,
|
|
5715
|
+
thinkingLevel: plan.effort
|
|
5716
|
+
};
|
|
5717
|
+
}
|
|
5718
|
+
if (_optionalChain([plan, 'optionalAccess', _279 => _279.kind]) === "budget") {
|
|
5719
|
+
return {
|
|
5720
|
+
includeThoughts: plan.enabled,
|
|
5721
|
+
thinkingBudget: plan.budgetTokens
|
|
5722
|
+
};
|
|
5723
|
+
}
|
|
5724
|
+
return void 0;
|
|
5725
|
+
}
|
|
5726
|
+
|
|
5640
5727
|
// src/completion/DirectApiHandler.ts
|
|
5641
5728
|
async function callOpenAICompletion(provider, apiKey, options, logger) {
|
|
5642
5729
|
const request = {
|
|
@@ -5648,11 +5735,9 @@ async function callOpenAICompletion(provider, apiKey, options, logger) {
|
|
|
5648
5735
|
stream: false
|
|
5649
5736
|
// For now, non-streaming only
|
|
5650
5737
|
};
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
request.reasoning_effort = effort;
|
|
5655
|
-
}
|
|
5738
|
+
const effort = resolveOpenAIEffort(provider, options, "openai-chat");
|
|
5739
|
+
if (effort) {
|
|
5740
|
+
request.reasoning_effort = effort;
|
|
5656
5741
|
}
|
|
5657
5742
|
const apiUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: false });
|
|
5658
5743
|
const headers = _chunkQ27JY5RGcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
@@ -5689,16 +5774,19 @@ async function callOpenAICompletion(provider, apiKey, options, logger) {
|
|
|
5689
5774
|
}
|
|
5690
5775
|
async function callAnthropicCompletion(provider, apiKey, options, logger) {
|
|
5691
5776
|
const hasImages = options.messages.some((m) => m.images && m.images.length > 0);
|
|
5777
|
+
const reasoningWire = buildAnthropicReasoningWire(provider, options);
|
|
5692
5778
|
if (hasImages) {
|
|
5693
5779
|
const systemMessages = options.messages.filter((m) => m.role === "system");
|
|
5694
5780
|
const nonSystemMessages = options.messages.filter((m) => m.role !== "system");
|
|
5695
5781
|
const anthropicRequest2 = {
|
|
5696
5782
|
model: options.model,
|
|
5697
|
-
max_tokens:
|
|
5698
|
-
temperature: options.temperature,
|
|
5783
|
+
max_tokens: reasoningWire.effectiveMaxTokens,
|
|
5784
|
+
...reasoningWire.legacyBudgetEnabled ? {} : { temperature: options.temperature },
|
|
5699
5785
|
...systemMessages.length > 0 ? { system: systemMessages.map((m) => m.content).join("\n\n") } : {},
|
|
5700
5786
|
messages: nonSystemMessages.map((m) => convertMessageToAnthropic(m)),
|
|
5701
|
-
stream: false
|
|
5787
|
+
stream: false,
|
|
5788
|
+
...reasoningWire.thinking ? { thinking: reasoningWire.thinking } : {},
|
|
5789
|
+
...reasoningWire.outputConfig ? { output_config: reasoningWire.outputConfig } : {}
|
|
5702
5790
|
};
|
|
5703
5791
|
const apiUrl2 = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: false });
|
|
5704
5792
|
const headers2 = _chunkQ27JY5RGcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
@@ -5723,7 +5811,7 @@ async function callAnthropicCompletion(provider, apiKey, options, logger) {
|
|
|
5723
5811
|
message: {
|
|
5724
5812
|
id: `assistant-${Date.now()}`,
|
|
5725
5813
|
role: "assistant",
|
|
5726
|
-
content: _optionalChain([choice2, 'access',
|
|
5814
|
+
content: _optionalChain([choice2, 'access', _280 => _280.message, 'optionalAccess', _281 => _281.content]) || "",
|
|
5727
5815
|
timestamp: Date.now()
|
|
5728
5816
|
},
|
|
5729
5817
|
usage: openaiResponse2.usage ? {
|
|
@@ -5740,14 +5828,24 @@ async function callAnthropicCompletion(provider, apiKey, options, logger) {
|
|
|
5740
5828
|
content: m.content
|
|
5741
5829
|
})),
|
|
5742
5830
|
// Anthropic requires max_tokens; use 16384 default if not explicitly set
|
|
5743
|
-
max_tokens:
|
|
5744
|
-
temperature: options.temperature,
|
|
5831
|
+
max_tokens: reasoningWire.effectiveMaxTokens,
|
|
5832
|
+
temperature: reasoningWire.legacyBudgetEnabled ? void 0 : options.temperature,
|
|
5745
5833
|
stream: false
|
|
5746
5834
|
};
|
|
5747
5835
|
const config = {
|
|
5748
5836
|
defaultModel: options.model
|
|
5749
5837
|
};
|
|
5750
5838
|
const anthropicRequest = _chunkGDIXXKF2cjs.convertOpenAIToAnthropic.call(void 0, openaiRequest, config);
|
|
5839
|
+
const anthropicRequestBody = anthropicRequest;
|
|
5840
|
+
if (reasoningWire.thinking) {
|
|
5841
|
+
anthropicRequestBody.thinking = reasoningWire.thinking;
|
|
5842
|
+
}
|
|
5843
|
+
if (reasoningWire.outputConfig) {
|
|
5844
|
+
anthropicRequestBody.output_config = reasoningWire.outputConfig;
|
|
5845
|
+
}
|
|
5846
|
+
if (reasoningWire.legacyBudgetEnabled) {
|
|
5847
|
+
delete anthropicRequestBody.temperature;
|
|
5848
|
+
}
|
|
5751
5849
|
const apiUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: false });
|
|
5752
5850
|
const headers = _chunkQ27JY5RGcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
5753
5851
|
logger.info("Calling Anthropic completion API", { url: apiUrl, model: options.model });
|
|
@@ -5792,11 +5890,13 @@ async function callGeminiCompletion(provider, apiKey, options, logger) {
|
|
|
5792
5890
|
contents.push(convertMessageToGemini(msg));
|
|
5793
5891
|
}
|
|
5794
5892
|
}
|
|
5893
|
+
const thinkingConfig = buildGeminiThinkingConfig(provider, options);
|
|
5795
5894
|
const request = {
|
|
5796
5895
|
contents,
|
|
5797
5896
|
generationConfig: {
|
|
5798
5897
|
...options.maxTokens !== void 0 ? { maxOutputTokens: options.maxTokens } : {},
|
|
5799
|
-
...options.temperature !== void 0 ? { temperature: options.temperature } : {}
|
|
5898
|
+
...options.temperature !== void 0 ? { temperature: options.temperature } : {},
|
|
5899
|
+
...thinkingConfig ? { thinkingConfig } : {}
|
|
5800
5900
|
}
|
|
5801
5901
|
};
|
|
5802
5902
|
if (systemInstruction) {
|
|
@@ -5828,7 +5928,7 @@ async function callGeminiCompletion(provider, apiKey, options, logger) {
|
|
|
5828
5928
|
const candidate = candidates[0];
|
|
5829
5929
|
const content = candidate.content;
|
|
5830
5930
|
let textContent = "";
|
|
5831
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
5931
|
+
if (_optionalChain([content, 'optionalAccess', _282 => _282.parts])) {
|
|
5832
5932
|
for (const part of content.parts) {
|
|
5833
5933
|
if (part.text) {
|
|
5834
5934
|
textContent += part.text;
|
|
@@ -5867,11 +5967,9 @@ async function callOpenAIResponseCompletion(provider, apiKey, options, logger) {
|
|
|
5867
5967
|
...options.maxTokens !== void 0 ? { max_output_tokens: options.maxTokens } : {},
|
|
5868
5968
|
...options.temperature !== void 0 ? { temperature: options.temperature } : {}
|
|
5869
5969
|
};
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
5873
|
-
request.reasoning = { effort, summary: "auto" };
|
|
5874
|
-
}
|
|
5970
|
+
const responseEffort = resolveOpenAIEffort(provider, options, "openai-responses");
|
|
5971
|
+
if (responseEffort) {
|
|
5972
|
+
request.reasoning = { effort: responseEffort, summary: "auto" };
|
|
5875
5973
|
}
|
|
5876
5974
|
const apiUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: false });
|
|
5877
5975
|
const headers = _chunkQ27JY5RGcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
@@ -5923,7 +6021,6 @@ async function callOpenAIResponseCompletion(provider, apiKey, options, logger) {
|
|
|
5923
6021
|
}
|
|
5924
6022
|
|
|
5925
6023
|
// src/completion/StreamHandler.ts
|
|
5926
|
-
|
|
5927
6024
|
async function streamOpenAICompletion(provider, apiKey, options, messageId, callbacks, logger) {
|
|
5928
6025
|
const request = {
|
|
5929
6026
|
model: options.model,
|
|
@@ -5933,11 +6030,9 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
|
|
|
5933
6030
|
temperature: options.temperature,
|
|
5934
6031
|
stream: true
|
|
5935
6032
|
};
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
request.reasoning_effort = effort;
|
|
5940
|
-
}
|
|
6033
|
+
const effort = resolveOpenAIEffort(provider, options, "openai-chat");
|
|
6034
|
+
if (effort) {
|
|
6035
|
+
request.reasoning_effort = effort;
|
|
5941
6036
|
}
|
|
5942
6037
|
const apiUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: true });
|
|
5943
6038
|
const headers = _chunkQ27JY5RGcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
@@ -5961,7 +6056,7 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
|
|
|
5961
6056
|
});
|
|
5962
6057
|
if (!response.ok) {
|
|
5963
6058
|
const errorText = await response.text();
|
|
5964
|
-
_optionalChain([callbacks, 'access',
|
|
6059
|
+
_optionalChain([callbacks, 'access', _283 => _283.onError, 'optionalCall', _284 => _284(`API error (${response.status}): ${errorText}`)]);
|
|
5965
6060
|
return;
|
|
5966
6061
|
}
|
|
5967
6062
|
const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "openai", {
|
|
@@ -5971,7 +6066,7 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
|
|
|
5971
6066
|
onVideo: callbacks.onVideo,
|
|
5972
6067
|
onError: callbacks.onError
|
|
5973
6068
|
});
|
|
5974
|
-
_optionalChain([callbacks, 'access',
|
|
6069
|
+
_optionalChain([callbacks, 'access', _285 => _285.onDone, 'optionalCall', _286 => _286(
|
|
5975
6070
|
{
|
|
5976
6071
|
id: messageId,
|
|
5977
6072
|
role: "assistant",
|
|
@@ -5987,16 +6082,11 @@ async function streamOpenAICompletion(provider, apiKey, options, messageId, call
|
|
|
5987
6082
|
}
|
|
5988
6083
|
async function streamAnthropicCompletion(provider, apiKey, options, messageId, callbacks, logger) {
|
|
5989
6084
|
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
|
-
}
|
|
6085
|
+
const reasoningWire = buildAnthropicReasoningWire(provider, options);
|
|
6086
|
+
const effectiveMaxTokens = reasoningWire.effectiveMaxTokens;
|
|
5997
6087
|
logger.debug("Anthropic thinking configuration", {
|
|
5998
6088
|
thinkLevel: options.thinkLevel,
|
|
5999
|
-
thinkingConfig,
|
|
6089
|
+
thinkingConfig: reasoningWire.thinking,
|
|
6000
6090
|
effectiveMaxTokens
|
|
6001
6091
|
});
|
|
6002
6092
|
let anthropicRequest;
|
|
@@ -6007,12 +6097,15 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
|
|
|
6007
6097
|
model: options.model,
|
|
6008
6098
|
max_tokens: effectiveMaxTokens,
|
|
6009
6099
|
// Omit temperature when thinking is enabled (Anthropic will use default temperature=1)
|
|
6010
|
-
...
|
|
6100
|
+
...reasoningWire.legacyBudgetEnabled ? {} : { temperature: options.temperature },
|
|
6011
6101
|
...systemMessages.length > 0 ? { system: systemMessages.map((m) => m.content).join("\n\n") } : {},
|
|
6012
6102
|
messages: nonSystemMessages.map((m) => convertMessageToAnthropic(m)),
|
|
6013
6103
|
stream: true,
|
|
6014
|
-
...
|
|
6104
|
+
...reasoningWire.thinking ? { thinking: reasoningWire.thinking } : {}
|
|
6015
6105
|
};
|
|
6106
|
+
if (reasoningWire.outputConfig) {
|
|
6107
|
+
anthropicRequest.output_config = reasoningWire.outputConfig;
|
|
6108
|
+
}
|
|
6016
6109
|
} else {
|
|
6017
6110
|
const config = {
|
|
6018
6111
|
defaultModel: options.model
|
|
@@ -6026,12 +6119,17 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
|
|
|
6026
6119
|
// Anthropic requires max_tokens; use adjusted value
|
|
6027
6120
|
max_tokens: effectiveMaxTokens,
|
|
6028
6121
|
// Omit temperature when thinking is enabled (Anthropic will use default temperature=1)
|
|
6029
|
-
temperature:
|
|
6122
|
+
temperature: reasoningWire.legacyBudgetEnabled ? void 0 : options.temperature,
|
|
6030
6123
|
stream: true
|
|
6031
6124
|
};
|
|
6032
6125
|
anthropicRequest = _chunkGDIXXKF2cjs.convertOpenAIToAnthropic.call(void 0, openaiRequest, config);
|
|
6033
|
-
if (
|
|
6034
|
-
anthropicRequest.thinking =
|
|
6126
|
+
if (reasoningWire.thinking) {
|
|
6127
|
+
anthropicRequest.thinking = reasoningWire.thinking;
|
|
6128
|
+
}
|
|
6129
|
+
if (reasoningWire.outputConfig) {
|
|
6130
|
+
anthropicRequest.output_config = reasoningWire.outputConfig;
|
|
6131
|
+
}
|
|
6132
|
+
if (reasoningWire.legacyBudgetEnabled) {
|
|
6035
6133
|
delete anthropicRequest.temperature;
|
|
6036
6134
|
}
|
|
6037
6135
|
}
|
|
@@ -6043,7 +6141,7 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
|
|
|
6043
6141
|
logger.info("Streaming Anthropic completion request", {
|
|
6044
6142
|
url: apiUrl,
|
|
6045
6143
|
model: anthropicRequest.model,
|
|
6046
|
-
messagesCount: _optionalChain([anthropicRequest, 'access',
|
|
6144
|
+
messagesCount: _optionalChain([anthropicRequest, 'access', _287 => _287.messages, 'optionalAccess', _288 => _288.length]),
|
|
6047
6145
|
max_tokens: anthropicRequest.max_tokens,
|
|
6048
6146
|
temperature: anthropicRequest.temperature,
|
|
6049
6147
|
stream: anthropicRequest.stream,
|
|
@@ -6060,7 +6158,7 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
|
|
|
6060
6158
|
if (!response.ok) {
|
|
6061
6159
|
const errorText = await response.text();
|
|
6062
6160
|
logger.error("Anthropic API error", void 0, { status: response.status, errorText });
|
|
6063
|
-
_optionalChain([callbacks, 'access',
|
|
6161
|
+
_optionalChain([callbacks, 'access', _289 => _289.onError, 'optionalCall', _290 => _290(`API error (${response.status}): ${errorText}`)]);
|
|
6064
6162
|
return;
|
|
6065
6163
|
}
|
|
6066
6164
|
const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "anthropic", {
|
|
@@ -6071,10 +6169,10 @@ async function streamAnthropicCompletion(provider, apiKey, options, messageId, c
|
|
|
6071
6169
|
});
|
|
6072
6170
|
logger.info("Anthropic stream complete", {
|
|
6073
6171
|
contentLength: result.content.length,
|
|
6074
|
-
reasoningLength: _optionalChain([result, 'access',
|
|
6172
|
+
reasoningLength: _optionalChain([result, 'access', _291 => _291.reasoning, 'optionalAccess', _292 => _292.length]) || 0,
|
|
6075
6173
|
blocksCount: result.blocks.length
|
|
6076
6174
|
});
|
|
6077
|
-
_optionalChain([callbacks, 'access',
|
|
6175
|
+
_optionalChain([callbacks, 'access', _293 => _293.onDone, 'optionalCall', _294 => _294(
|
|
6078
6176
|
{
|
|
6079
6177
|
id: messageId,
|
|
6080
6178
|
role: "assistant",
|
|
@@ -6097,11 +6195,13 @@ async function streamGeminiCompletion(provider, apiKey, options, messageId, call
|
|
|
6097
6195
|
contents.push(convertMessageToGemini(msg));
|
|
6098
6196
|
}
|
|
6099
6197
|
}
|
|
6198
|
+
const thinkingConfig = buildGeminiThinkingConfig(provider, options);
|
|
6100
6199
|
const request = {
|
|
6101
6200
|
contents,
|
|
6102
6201
|
generationConfig: {
|
|
6103
6202
|
...options.maxTokens !== void 0 ? { maxOutputTokens: options.maxTokens } : {},
|
|
6104
|
-
...options.temperature !== void 0 ? { temperature: options.temperature } : {}
|
|
6203
|
+
...options.temperature !== void 0 ? { temperature: options.temperature } : {},
|
|
6204
|
+
...thinkingConfig ? { thinkingConfig } : {}
|
|
6105
6205
|
}
|
|
6106
6206
|
};
|
|
6107
6207
|
if (systemInstruction) {
|
|
@@ -6130,7 +6230,7 @@ async function streamGeminiCompletion(provider, apiKey, options, messageId, call
|
|
|
6130
6230
|
if (!response.ok) {
|
|
6131
6231
|
const errorText = await response.text();
|
|
6132
6232
|
logger.error("Gemini API error", void 0, { status: response.status, errorText });
|
|
6133
|
-
_optionalChain([callbacks, 'access',
|
|
6233
|
+
_optionalChain([callbacks, 'access', _295 => _295.onError, 'optionalCall', _296 => _296(`API error (${response.status}): ${errorText}`)]);
|
|
6134
6234
|
return;
|
|
6135
6235
|
}
|
|
6136
6236
|
const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "gemini", {
|
|
@@ -6139,7 +6239,7 @@ async function streamGeminiCompletion(provider, apiKey, options, messageId, call
|
|
|
6139
6239
|
onError: callbacks.onError
|
|
6140
6240
|
});
|
|
6141
6241
|
logger.info("Gemini stream complete", { contentLength: result.content.length });
|
|
6142
|
-
_optionalChain([callbacks, 'access',
|
|
6242
|
+
_optionalChain([callbacks, 'access', _297 => _297.onDone, 'optionalCall', _298 => _298(
|
|
6143
6243
|
{
|
|
6144
6244
|
id: messageId,
|
|
6145
6245
|
role: "assistant",
|
|
@@ -6167,11 +6267,9 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
|
|
|
6167
6267
|
...options.maxTokens !== void 0 ? { max_output_tokens: options.maxTokens } : {},
|
|
6168
6268
|
...options.temperature !== void 0 ? { temperature: options.temperature } : {}
|
|
6169
6269
|
};
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
request.reasoning = { effort, summary: "auto" };
|
|
6174
|
-
}
|
|
6270
|
+
const responseEffort = resolveOpenAIEffort(provider, options, "openai-responses");
|
|
6271
|
+
if (responseEffort) {
|
|
6272
|
+
request.reasoning = { effort: responseEffort, summary: "auto" };
|
|
6175
6273
|
}
|
|
6176
6274
|
const apiUrl = _chunkA2YMUCBTcjs.buildProviderApiUrl.call(void 0, provider, { model: options.model, stream: true });
|
|
6177
6275
|
const headers = _chunkQ27JY5RGcjs.getProviderHeaders.call(void 0, provider, apiKey);
|
|
@@ -6191,7 +6289,7 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
|
|
|
6191
6289
|
});
|
|
6192
6290
|
if (!response.ok) {
|
|
6193
6291
|
const errorText = await response.text();
|
|
6194
|
-
_optionalChain([callbacks, 'access',
|
|
6292
|
+
_optionalChain([callbacks, 'access', _299 => _299.onError, 'optionalCall', _300 => _300(`API error (${response.status}): ${errorText}`)]);
|
|
6195
6293
|
return;
|
|
6196
6294
|
}
|
|
6197
6295
|
const result = await _chunkHQP3K7PUcjs.streamSSEResponse.call(void 0, response, "openai-response", {
|
|
@@ -6200,7 +6298,7 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
|
|
|
6200
6298
|
onError: callbacks.onError
|
|
6201
6299
|
});
|
|
6202
6300
|
logger.info("OpenAI Response API stream complete", { contentLength: result.content.length });
|
|
6203
|
-
_optionalChain([callbacks, 'access',
|
|
6301
|
+
_optionalChain([callbacks, 'access', _301 => _301.onDone, 'optionalCall', _302 => _302(
|
|
6204
6302
|
{
|
|
6205
6303
|
id: messageId,
|
|
6206
6304
|
role: "assistant",
|
|
@@ -6220,7 +6318,7 @@ async function streamOpenAIResponseCompletion(provider, apiKey, options, message
|
|
|
6220
6318
|
|
|
6221
6319
|
|
|
6222
6320
|
|
|
6223
|
-
|
|
6321
|
+
var _thinkingconfig = require('@omnicross/contracts/thinking-config');
|
|
6224
6322
|
async function resolveEffectiveMaxTokens(llmConfig, _getProvider, logger, _providerId, _modelId, sessionMaxTokens) {
|
|
6225
6323
|
if (sessionMaxTokens !== void 0 && sessionMaxTokens > 0) {
|
|
6226
6324
|
logger.debug("Using session maxTokens", { sessionMaxTokens });
|
|
@@ -6228,7 +6326,7 @@ async function resolveEffectiveMaxTokens(llmConfig, _getProvider, logger, _provi
|
|
|
6228
6326
|
}
|
|
6229
6327
|
try {
|
|
6230
6328
|
const globalParams = await llmConfig.getGlobalModelParameters();
|
|
6231
|
-
if (_optionalChain([globalParams, 'optionalAccess',
|
|
6329
|
+
if (_optionalChain([globalParams, 'optionalAccess', _303 => _303.maxTokens, 'optionalAccess', _304 => _304.enabled]) && globalParams.maxTokens.value > 0) {
|
|
6232
6330
|
logger.debug("Using global maxTokens", { maxTokens: globalParams.maxTokens.value });
|
|
6233
6331
|
return globalParams.maxTokens.value;
|
|
6234
6332
|
}
|
|
@@ -6256,7 +6354,7 @@ async function resolveThinkingBudget(getProvider, logger, providerId, modelId, m
|
|
|
6256
6354
|
}
|
|
6257
6355
|
const thinkingBudget = _thinkingconfig.calculateThinkingBudget.call(void 0, modelId, thinkLevel, maxTokens);
|
|
6258
6356
|
const provider = await getProvider(providerId);
|
|
6259
|
-
const providerName = _optionalChain([provider, 'optionalAccess',
|
|
6357
|
+
const providerName = _optionalChain([provider, 'optionalAccess', _305 => _305.name, 'optionalAccess', _306 => _306.toLowerCase, 'call', _307 => _307()]) || "";
|
|
6260
6358
|
const apiFormat = provider ? _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider) : "openai";
|
|
6261
6359
|
if (apiFormat === "anthropic" || providerName === "anthropic" || providerName.includes("claude")) {
|
|
6262
6360
|
const thinkingConfig = _thinkingconfig.buildAnthropicThinking.call(void 0, modelId, thinkLevel, maxTokens);
|
|
@@ -6293,7 +6391,7 @@ function logToolFormat(tools, logger) {
|
|
|
6293
6391
|
tools: openaiTools.map((t) => t.function.name),
|
|
6294
6392
|
firstTool: {
|
|
6295
6393
|
name: firstTool.function.name,
|
|
6296
|
-
description: _optionalChain([firstTool, 'access',
|
|
6394
|
+
description: _optionalChain([firstTool, 'access', _308 => _308.function, 'access', _309 => _309.description, 'optionalAccess', _310 => _310.slice, 'call', _311 => _311(0, 100)]),
|
|
6297
6395
|
parameters: firstTool.function.parameters
|
|
6298
6396
|
}
|
|
6299
6397
|
});
|
|
@@ -6304,7 +6402,7 @@ function logToolFormat(tools, logger) {
|
|
|
6304
6402
|
tools: anthropicTools.map((t) => t.name),
|
|
6305
6403
|
firstTool: {
|
|
6306
6404
|
name: firstTool.name,
|
|
6307
|
-
description: _optionalChain([firstTool, 'access',
|
|
6405
|
+
description: _optionalChain([firstTool, 'access', _312 => _312.description, 'optionalAccess', _313 => _313.slice, 'call', _314 => _314(0, 100)]),
|
|
6308
6406
|
input_schema: firstTool.input_schema
|
|
6309
6407
|
}
|
|
6310
6408
|
});
|
|
@@ -6315,9 +6413,9 @@ function logToolFormat(tools, logger) {
|
|
|
6315
6413
|
count: allDeclarations.length,
|
|
6316
6414
|
tools: allDeclarations.map((t) => t.name),
|
|
6317
6415
|
firstTool: {
|
|
6318
|
-
name: _optionalChain([allDeclarations, 'access',
|
|
6319
|
-
description: _optionalChain([allDeclarations, 'access',
|
|
6320
|
-
parameters: _optionalChain([allDeclarations, 'access',
|
|
6416
|
+
name: _optionalChain([allDeclarations, 'access', _315 => _315[0], 'optionalAccess', _316 => _316.name]),
|
|
6417
|
+
description: _optionalChain([allDeclarations, 'access', _317 => _317[0], 'optionalAccess', _318 => _318.description, 'optionalAccess', _319 => _319.slice, 'call', _320 => _320(0, 100)]),
|
|
6418
|
+
parameters: _optionalChain([allDeclarations, 'access', _321 => _321[0], 'optionalAccess', _322 => _322.parameters])
|
|
6321
6419
|
}
|
|
6322
6420
|
});
|
|
6323
6421
|
}
|
|
@@ -6351,7 +6449,7 @@ function buildToolRequest(apiFormat, conversationMessages, actualModel, options,
|
|
|
6351
6449
|
// Native Anthropic Messages requires this field. Resolve an absent
|
|
6352
6450
|
// caller cap to the model's real ceiling rather than a small constant —
|
|
6353
6451
|
// see `resolveAnthropicMaxTokens`.
|
|
6354
|
-
max_tokens:
|
|
6452
|
+
max_tokens: _chunkZQQUD66Mcjs.resolveAnthropicMaxTokens.call(void 0, actualModel, options.maxTokens),
|
|
6355
6453
|
temperature: _nullishCoalesce(options.temperature, () => ( 0.7)),
|
|
6356
6454
|
stream: true,
|
|
6357
6455
|
tools: options.tools
|
|
@@ -6380,7 +6478,7 @@ function buildToolRequest(apiFormat, conversationMessages, actualModel, options,
|
|
|
6380
6478
|
function extractDeltaContent(rawJson, apiFormat) {
|
|
6381
6479
|
const json = rawJson;
|
|
6382
6480
|
if (apiFormat === "google") {
|
|
6383
|
-
const parts = _optionalChain([json, 'access',
|
|
6481
|
+
const parts = _optionalChain([json, 'access', _323 => _323.candidates, 'optionalAccess', _324 => _324[0], 'optionalAccess', _325 => _325.content, 'optionalAccess', _326 => _326.parts]) || [];
|
|
6384
6482
|
let text = "";
|
|
6385
6483
|
for (const part of parts) {
|
|
6386
6484
|
if (part.thought === true) continue;
|
|
@@ -6388,15 +6486,15 @@ function extractDeltaContent(rawJson, apiFormat) {
|
|
|
6388
6486
|
}
|
|
6389
6487
|
return text;
|
|
6390
6488
|
} else if (apiFormat === "anthropic") {
|
|
6391
|
-
return _optionalChain([json, 'access',
|
|
6489
|
+
return _optionalChain([json, 'access', _327 => _327.delta, 'optionalAccess', _328 => _328.text]) || "";
|
|
6392
6490
|
} else {
|
|
6393
|
-
return _optionalChain([json, 'access',
|
|
6491
|
+
return _optionalChain([json, 'access', _329 => _329.choices, 'optionalAccess', _330 => _330[0], 'optionalAccess', _331 => _331.delta, 'optionalAccess', _332 => _332.content]) || "";
|
|
6394
6492
|
}
|
|
6395
6493
|
}
|
|
6396
6494
|
function extractDeltaReasoning(rawJson, apiFormat) {
|
|
6397
6495
|
const json = rawJson;
|
|
6398
6496
|
if (apiFormat === "google") {
|
|
6399
|
-
const parts = _optionalChain([json, 'access',
|
|
6497
|
+
const parts = _optionalChain([json, 'access', _333 => _333.candidates, 'optionalAccess', _334 => _334[0], 'optionalAccess', _335 => _335.content, 'optionalAccess', _336 => _336.parts]) || [];
|
|
6400
6498
|
let reasoning = "";
|
|
6401
6499
|
for (const part of parts) {
|
|
6402
6500
|
if (part.thought === true && part.text) reasoning += part.text;
|
|
@@ -6405,14 +6503,14 @@ function extractDeltaReasoning(rawJson, apiFormat) {
|
|
|
6405
6503
|
} else if (apiFormat === "anthropic") {
|
|
6406
6504
|
return "";
|
|
6407
6505
|
} else {
|
|
6408
|
-
const delta = _optionalChain([json, 'access',
|
|
6409
|
-
return (_optionalChain([delta, 'optionalAccess',
|
|
6506
|
+
const delta = _optionalChain([json, 'access', _337 => _337.choices, 'optionalAccess', _338 => _338[0], 'optionalAccess', _339 => _339.delta]);
|
|
6507
|
+
return (_optionalChain([delta, 'optionalAccess', _340 => _340.thinking, 'optionalAccess', _341 => _341.content]) || "") + (_optionalChain([delta, 'optionalAccess', _342 => _342.reasoning_content]) || "");
|
|
6410
6508
|
}
|
|
6411
6509
|
}
|
|
6412
6510
|
function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pendingOpenAIToolCalls) {
|
|
6413
6511
|
const json = rawJson;
|
|
6414
6512
|
if (apiFormat === "google") {
|
|
6415
|
-
const parts = _optionalChain([json, 'access',
|
|
6513
|
+
const parts = _optionalChain([json, 'access', _343 => _343.candidates, 'optionalAccess', _344 => _344[0], 'optionalAccess', _345 => _345.content, 'optionalAccess', _346 => _346.parts]) || [];
|
|
6416
6514
|
for (const part of parts) {
|
|
6417
6515
|
if (part.functionCall) {
|
|
6418
6516
|
logger.info("Function call detected", { functionCall: part.functionCall });
|
|
@@ -6422,13 +6520,13 @@ function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pend
|
|
|
6422
6520
|
args: part.functionCall.args || {}
|
|
6423
6521
|
};
|
|
6424
6522
|
toolCalls.push(toolCall);
|
|
6425
|
-
_optionalChain([callbacks, 'access',
|
|
6523
|
+
_optionalChain([callbacks, 'access', _347 => _347.onToolCall, 'optionalCall', _348 => _348(toolCall)]);
|
|
6426
6524
|
logger.info("Tool called", { toolName: toolCall.name });
|
|
6427
6525
|
}
|
|
6428
6526
|
}
|
|
6429
6527
|
} else if (apiFormat !== "anthropic") {
|
|
6430
|
-
const delta = _optionalChain([json, 'access',
|
|
6431
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
6528
|
+
const delta = _optionalChain([json, 'access', _349 => _349.choices, 'optionalAccess', _350 => _350[0], 'optionalAccess', _351 => _351.delta]);
|
|
6529
|
+
if (_optionalChain([delta, 'optionalAccess', _352 => _352.tool_calls]) && pendingOpenAIToolCalls) {
|
|
6432
6530
|
for (const tc of delta.tool_calls) {
|
|
6433
6531
|
const index = _nullishCoalesce(tc.index, () => ( 0));
|
|
6434
6532
|
let pending = pendingOpenAIToolCalls.get(index);
|
|
@@ -6437,8 +6535,8 @@ function extractToolCalls(rawJson, apiFormat, toolCalls, callbacks, logger, pend
|
|
|
6437
6535
|
pendingOpenAIToolCalls.set(index, pending);
|
|
6438
6536
|
}
|
|
6439
6537
|
if (tc.id) pending.id = tc.id;
|
|
6440
|
-
if (_optionalChain([tc, 'access',
|
|
6441
|
-
if (_optionalChain([tc, 'access',
|
|
6538
|
+
if (_optionalChain([tc, 'access', _353 => _353.function, 'optionalAccess', _354 => _354.name])) pending.name += tc.function.name;
|
|
6539
|
+
if (_optionalChain([tc, 'access', _355 => _355.function, 'optionalAccess', _356 => _356.arguments])) pending.arguments += tc.function.arguments;
|
|
6442
6540
|
}
|
|
6443
6541
|
}
|
|
6444
6542
|
}
|
|
@@ -6453,7 +6551,7 @@ function finalizeOpenAIToolCalls(pendingOpenAIToolCalls, toolCalls, callbacks, l
|
|
|
6453
6551
|
args: JSON.parse(pending.arguments || "{}")
|
|
6454
6552
|
};
|
|
6455
6553
|
toolCalls.push(toolCall);
|
|
6456
|
-
_optionalChain([callbacks, 'access',
|
|
6554
|
+
_optionalChain([callbacks, 'access', _357 => _357.onToolCall, 'optionalCall', _358 => _358(toolCall)]);
|
|
6457
6555
|
logger.info("Tool called (OpenAI)", { toolName: toolCall.name, args: toolCall.args });
|
|
6458
6556
|
} catch (e) {
|
|
6459
6557
|
logger.error("Failed to parse OpenAI tool call arguments", e instanceof Error ? e : void 0, {
|
|
@@ -6467,38 +6565,38 @@ function finalizeOpenAIToolCalls(pendingOpenAIToolCalls, toolCalls, callbacks, l
|
|
|
6467
6565
|
function parseStreamChunk(rawJson, apiFormat, callbacks, logger) {
|
|
6468
6566
|
const json = rawJson;
|
|
6469
6567
|
if (apiFormat === "google") {
|
|
6470
|
-
const candidate = _optionalChain([json, 'access',
|
|
6568
|
+
const candidate = _optionalChain([json, 'access', _359 => _359.candidates, 'optionalAccess', _360 => _360[0]]);
|
|
6471
6569
|
if (!candidate) {
|
|
6472
6570
|
logger.warn("No candidate found in Gemini response");
|
|
6473
6571
|
return;
|
|
6474
6572
|
}
|
|
6475
|
-
const parts = _optionalChain([candidate, 'access',
|
|
6573
|
+
const parts = _optionalChain([candidate, 'access', _361 => _361.content, 'optionalAccess', _362 => _362.parts]) || [];
|
|
6476
6574
|
for (const part of parts) {
|
|
6477
6575
|
if (part.thought === true && part.text) {
|
|
6478
|
-
_optionalChain([callbacks, 'access',
|
|
6576
|
+
_optionalChain([callbacks, 'access', _363 => _363.onReasoning, 'optionalCall', _364 => _364(part.text)]);
|
|
6479
6577
|
continue;
|
|
6480
6578
|
} else if (part.thoughtSignature && !part.thought) {
|
|
6481
6579
|
logger.debug("Gemini returned thoughtSignature without thought content");
|
|
6482
6580
|
}
|
|
6483
6581
|
if (part.text) {
|
|
6484
|
-
_optionalChain([callbacks, 'access',
|
|
6582
|
+
_optionalChain([callbacks, 'access', _365 => _365.onDelta, 'optionalCall', _366 => _366(part.text)]);
|
|
6485
6583
|
}
|
|
6486
6584
|
}
|
|
6487
6585
|
} else if (apiFormat === "anthropic") {
|
|
6488
6586
|
const delta = json.delta;
|
|
6489
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
6490
|
-
_optionalChain([callbacks, 'access',
|
|
6587
|
+
if (_optionalChain([delta, 'optionalAccess', _367 => _367.text])) {
|
|
6588
|
+
_optionalChain([callbacks, 'access', _368 => _368.onDelta, 'optionalCall', _369 => _369(delta.text)]);
|
|
6491
6589
|
}
|
|
6492
6590
|
} else {
|
|
6493
|
-
const delta = _optionalChain([json, 'access',
|
|
6494
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
6495
|
-
_optionalChain([callbacks, 'access',
|
|
6591
|
+
const delta = _optionalChain([json, 'access', _370 => _370.choices, 'optionalAccess', _371 => _371[0], 'optionalAccess', _372 => _372.delta]);
|
|
6592
|
+
if (_optionalChain([delta, 'optionalAccess', _373 => _373.content])) {
|
|
6593
|
+
_optionalChain([callbacks, 'access', _374 => _374.onDelta, 'optionalCall', _375 => _375(delta.content)]);
|
|
6496
6594
|
}
|
|
6497
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
6498
|
-
_optionalChain([callbacks, 'access',
|
|
6595
|
+
if (_optionalChain([delta, 'optionalAccess', _376 => _376.thinking, 'optionalAccess', _377 => _377.content])) {
|
|
6596
|
+
_optionalChain([callbacks, 'access', _378 => _378.onReasoning, 'optionalCall', _379 => _379(delta.thinking.content)]);
|
|
6499
6597
|
}
|
|
6500
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
6501
|
-
_optionalChain([callbacks, 'access',
|
|
6598
|
+
if (_optionalChain([delta, 'optionalAccess', _380 => _380.reasoning_content])) {
|
|
6599
|
+
_optionalChain([callbacks, 'access', _381 => _381.onReasoning, 'optionalCall', _382 => _382(delta.reasoning_content)]);
|
|
6502
6600
|
}
|
|
6503
6601
|
}
|
|
6504
6602
|
}
|
|
@@ -6511,7 +6609,7 @@ function buildIterationBlocks(iteration, content, reasoning, blocks, callbacks)
|
|
|
6511
6609
|
content: reasoning
|
|
6512
6610
|
};
|
|
6513
6611
|
blocks.push(thinkingBlock);
|
|
6514
|
-
_optionalChain([callbacks, 'access',
|
|
6612
|
+
_optionalChain([callbacks, 'access', _383 => _383.onBlock, 'optionalCall', _384 => _384(thinkingBlock)]);
|
|
6515
6613
|
}
|
|
6516
6614
|
if (content && content.trim()) {
|
|
6517
6615
|
const textBlock = {
|
|
@@ -6520,7 +6618,7 @@ function buildIterationBlocks(iteration, content, reasoning, blocks, callbacks)
|
|
|
6520
6618
|
content
|
|
6521
6619
|
};
|
|
6522
6620
|
blocks.push(textBlock);
|
|
6523
|
-
_optionalChain([callbacks, 'access',
|
|
6621
|
+
_optionalChain([callbacks, 'access', _385 => _385.onBlock, 'optionalCall', _386 => _386(textBlock)]);
|
|
6524
6622
|
}
|
|
6525
6623
|
}
|
|
6526
6624
|
async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbacks, logger, builtinExecutor) {
|
|
@@ -6535,7 +6633,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
6535
6633
|
status: "running"
|
|
6536
6634
|
};
|
|
6537
6635
|
blocks.push(toolUseBlock);
|
|
6538
|
-
_optionalChain([callbacks, 'access',
|
|
6636
|
+
_optionalChain([callbacks, 'access', _387 => _387.onBlock, 'optionalCall', _388 => _388(toolUseBlock)]);
|
|
6539
6637
|
try {
|
|
6540
6638
|
logger.info("Executing tool", { toolName: toolCall.name });
|
|
6541
6639
|
const mcpTool = mcpTools.find((t) => t.id === toolCall.name);
|
|
@@ -6558,8 +6656,8 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
6558
6656
|
result = { isError: true, content: [{ type: "text", text: "MCP service not available" }] };
|
|
6559
6657
|
}
|
|
6560
6658
|
logger.info("Tool result received", { result });
|
|
6561
|
-
_optionalChain([callbacks, 'access',
|
|
6562
|
-
const resultText = _optionalChain([result, 'access',
|
|
6659
|
+
_optionalChain([callbacks, 'access', _389 => _389.onToolResult, 'optionalCall', _390 => _390(toolCall.id, result)]);
|
|
6660
|
+
const resultText = _optionalChain([result, 'access', _391 => _391.content, 'optionalAccess', _392 => _392[0], 'optionalAccess', _393 => _393.text]) || JSON.stringify(result);
|
|
6563
6661
|
const toolResultBlock = {
|
|
6564
6662
|
id: `${toolCall.id}_result`,
|
|
6565
6663
|
type: "tool_result",
|
|
@@ -6569,11 +6667,11 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
6569
6667
|
isError: result.isError
|
|
6570
6668
|
};
|
|
6571
6669
|
blocks.push(toolResultBlock);
|
|
6572
|
-
_optionalChain([callbacks, 'access',
|
|
6670
|
+
_optionalChain([callbacks, 'access', _394 => _394.onBlock, 'optionalCall', _395 => _395(toolResultBlock)]);
|
|
6573
6671
|
const toolUseBlockRef = blocks.find((b) => b.id === `${toolCall.id}_use`);
|
|
6574
6672
|
if (toolUseBlockRef && toolUseBlockRef.type === "tool_use") {
|
|
6575
6673
|
toolUseBlockRef.status = result.isError ? "error" : "completed";
|
|
6576
|
-
_optionalChain([callbacks, 'access',
|
|
6674
|
+
_optionalChain([callbacks, 'access', _396 => _396.onBlock, 'optionalCall', _397 => _397({ ...toolUseBlockRef })]);
|
|
6577
6675
|
}
|
|
6578
6676
|
toolResults.push({ toolCall, result });
|
|
6579
6677
|
} catch (error) {
|
|
@@ -6583,7 +6681,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
6583
6681
|
isError: true,
|
|
6584
6682
|
content: [{ type: "text", text: `Error: ${errorMessage}` }]
|
|
6585
6683
|
};
|
|
6586
|
-
_optionalChain([callbacks, 'access',
|
|
6684
|
+
_optionalChain([callbacks, 'access', _398 => _398.onToolResult, 'optionalCall', _399 => _399(toolCall.id, errorResult)]);
|
|
6587
6685
|
const errorToolResultBlock = {
|
|
6588
6686
|
id: `${toolCall.id}_result`,
|
|
6589
6687
|
type: "tool_result",
|
|
@@ -6593,11 +6691,11 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
6593
6691
|
isError: true
|
|
6594
6692
|
};
|
|
6595
6693
|
blocks.push(errorToolResultBlock);
|
|
6596
|
-
_optionalChain([callbacks, 'access',
|
|
6694
|
+
_optionalChain([callbacks, 'access', _400 => _400.onBlock, 'optionalCall', _401 => _401(errorToolResultBlock)]);
|
|
6597
6695
|
const errorToolUseBlockRef = blocks.find((b) => b.id === `${toolCall.id}_use`);
|
|
6598
6696
|
if (errorToolUseBlockRef && errorToolUseBlockRef.type === "tool_use") {
|
|
6599
6697
|
errorToolUseBlockRef.status = "error";
|
|
6600
|
-
_optionalChain([callbacks, 'access',
|
|
6698
|
+
_optionalChain([callbacks, 'access', _402 => _402.onBlock, 'optionalCall', _403 => _403({ ...errorToolUseBlockRef })]);
|
|
6601
6699
|
}
|
|
6602
6700
|
toolResults.push({ toolCall, result: errorResult });
|
|
6603
6701
|
}
|
|
@@ -6607,7 +6705,7 @@ async function executeToolCalls(toolCalls, mcpTools, mcpService, blocks, callbac
|
|
|
6607
6705
|
function mapToolArguments(args, mcpTool, logger) {
|
|
6608
6706
|
const mappedArgs = { ...args };
|
|
6609
6707
|
const toolSchema = mcpTool.inputSchema;
|
|
6610
|
-
if (_optionalChain([toolSchema, 'optionalAccess',
|
|
6708
|
+
if (_optionalChain([toolSchema, 'optionalAccess', _404 => _404.properties])) {
|
|
6611
6709
|
const expectedParams = Object.keys(toolSchema.properties);
|
|
6612
6710
|
const paramMappings = {
|
|
6613
6711
|
"search_query": ["query", "q", "searchQuery", "search"],
|
|
@@ -6641,25 +6739,25 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
6641
6739
|
options.providerId,
|
|
6642
6740
|
options.model
|
|
6643
6741
|
);
|
|
6644
|
-
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess',
|
|
6645
|
-
const actualModel = _optionalChain([routedInfo, 'optionalAccess',
|
|
6742
|
+
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _405 => _405.actualProviderId]) || options.providerId;
|
|
6743
|
+
const actualModel = _optionalChain([routedInfo, 'optionalAccess', _406 => _406.actualModelId]) || options.model;
|
|
6646
6744
|
const provider = await getProvider(actualProviderId);
|
|
6647
6745
|
if (!provider) {
|
|
6648
|
-
_optionalChain([callbacks, 'access',
|
|
6746
|
+
_optionalChain([callbacks, 'access', _407 => _407.onError, 'optionalCall', _408 => _408(`Provider not found: ${actualProviderId}`)]);
|
|
6649
6747
|
return;
|
|
6650
6748
|
}
|
|
6651
6749
|
if (!provider.enabled) {
|
|
6652
|
-
_optionalChain([callbacks, 'access',
|
|
6750
|
+
_optionalChain([callbacks, 'access', _409 => _409.onError, 'optionalCall', _410 => _410(`Provider is disabled: ${provider.name}`)]);
|
|
6653
6751
|
return;
|
|
6654
6752
|
}
|
|
6655
6753
|
const { apiKey: effectiveKey } = _chunkA2YMUCBTcjs.resolveProviderEndpoint.call(void 0, provider);
|
|
6656
6754
|
const apiKey = resolveApiKey2(effectiveKey);
|
|
6657
6755
|
if (!apiKey) {
|
|
6658
|
-
_optionalChain([callbacks, 'access',
|
|
6756
|
+
_optionalChain([callbacks, 'access', _411 => _411.onError, 'optionalCall', _412 => _412("API key not configured")]);
|
|
6659
6757
|
return;
|
|
6660
6758
|
}
|
|
6661
6759
|
const messageId = `msg_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
6662
|
-
_optionalChain([callbacks, 'access',
|
|
6760
|
+
_optionalChain([callbacks, 'access', _413 => _413.onStart, 'optionalCall', _414 => _414(messageId)]);
|
|
6663
6761
|
const globalParams = await llmConfig.getGlobalModelParameters();
|
|
6664
6762
|
const MAX_ITERATIONS = _nullishCoalesce(globalParams.toolMaxTurns, () => ( 100));
|
|
6665
6763
|
let iteration = 0;
|
|
@@ -6706,12 +6804,12 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
6706
6804
|
});
|
|
6707
6805
|
if (!response.ok) {
|
|
6708
6806
|
const errorText = await response.text();
|
|
6709
|
-
_optionalChain([callbacks, 'access',
|
|
6807
|
+
_optionalChain([callbacks, 'access', _415 => _415.onError, 'optionalCall', _416 => _416(`API error (${response.status}): ${errorText}`)]);
|
|
6710
6808
|
return;
|
|
6711
6809
|
}
|
|
6712
|
-
const reader = _optionalChain([response, 'access',
|
|
6810
|
+
const reader = _optionalChain([response, 'access', _417 => _417.body, 'optionalAccess', _418 => _418.getReader, 'call', _419 => _419()]);
|
|
6713
6811
|
if (!reader) {
|
|
6714
|
-
_optionalChain([callbacks, 'access',
|
|
6812
|
+
_optionalChain([callbacks, 'access', _420 => _420.onError, 'optionalCall', _421 => _421("No response body")]);
|
|
6715
6813
|
return;
|
|
6716
6814
|
}
|
|
6717
6815
|
const decoder = new TextDecoder();
|
|
@@ -6744,7 +6842,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
6744
6842
|
logger.debug("Parsed JSON", { json });
|
|
6745
6843
|
if (json.error) {
|
|
6746
6844
|
logger.error("API Error", void 0, { error: json.error });
|
|
6747
|
-
_optionalChain([callbacks, 'access',
|
|
6845
|
+
_optionalChain([callbacks, 'access', _422 => _422.onError, 'optionalCall', _423 => _423(`API Error: ${json.error.message || JSON.stringify(json.error)}`)]);
|
|
6748
6846
|
return;
|
|
6749
6847
|
}
|
|
6750
6848
|
parseStreamChunk(json, apiFormat, callbacks, logger);
|
|
@@ -6777,7 +6875,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
6777
6875
|
toolCallsLength: toolCalls.length,
|
|
6778
6876
|
executableToolCallsLength: executableToolCalls.length,
|
|
6779
6877
|
hasMcpTools: !!options.mcpTools,
|
|
6780
|
-
mcpToolsLength: _optionalChain([options, 'access',
|
|
6878
|
+
mcpToolsLength: _optionalChain([options, 'access', _424 => _424.mcpTools, 'optionalAccess', _425 => _425.length]),
|
|
6781
6879
|
hasMcpService: !!mcpService
|
|
6782
6880
|
});
|
|
6783
6881
|
if (executableToolCalls.length > 0 && options.mcpTools && (mcpService || builtinExecutor)) {
|
|
@@ -6798,7 +6896,7 @@ async function streamWithTools(options, callbacks, mcpService, llmConfig, getPro
|
|
|
6798
6896
|
builtinExecutor
|
|
6799
6897
|
);
|
|
6800
6898
|
const toolResultsText = toolResults.map(({ toolCall, result }) => {
|
|
6801
|
-
const resultText = typeof result === "string" ? result : _optionalChain([result, 'access',
|
|
6899
|
+
const resultText = typeof result === "string" ? result : _optionalChain([result, 'access', _426 => _426.content, 'optionalAccess', _427 => _427[0], 'optionalAccess', _428 => _428.text]) || JSON.stringify(result);
|
|
6802
6900
|
return `Tool ${toolCall.name} result:
|
|
6803
6901
|
${resultText}`;
|
|
6804
6902
|
}).join("\n\n");
|
|
@@ -6816,12 +6914,12 @@ ${resultText}`;
|
|
|
6816
6914
|
}
|
|
6817
6915
|
} catch (streamError) {
|
|
6818
6916
|
logger.error("Stream processing error", streamError instanceof Error ? streamError : void 0);
|
|
6819
|
-
_optionalChain([callbacks, 'access',
|
|
6917
|
+
_optionalChain([callbacks, 'access', _429 => _429.onError, 'optionalCall', _430 => _430(`Stream error: ${streamError instanceof Error ? streamError.message : "Unknown error"}`)]);
|
|
6820
6918
|
return;
|
|
6821
6919
|
}
|
|
6822
6920
|
}
|
|
6823
6921
|
logger.info("Sending final callback", { blocksCount: blocks.length });
|
|
6824
|
-
_optionalChain([callbacks, 'access',
|
|
6922
|
+
_optionalChain([callbacks, 'access', _431 => _431.onDone, 'optionalCall', _432 => _432({
|
|
6825
6923
|
id: messageId,
|
|
6826
6924
|
role: "assistant",
|
|
6827
6925
|
content: finalContent,
|
|
@@ -6832,7 +6930,7 @@ ${resultText}`;
|
|
|
6832
6930
|
} catch (error) {
|
|
6833
6931
|
logger.error("Error in streamWithTools", error instanceof Error ? error : void 0);
|
|
6834
6932
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
6835
|
-
_optionalChain([callbacks, 'access',
|
|
6933
|
+
_optionalChain([callbacks, 'access', _433 => _433.onError, 'optionalCall', _434 => _434(message)]);
|
|
6836
6934
|
}
|
|
6837
6935
|
}
|
|
6838
6936
|
|
|
@@ -6883,8 +6981,8 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
|
|
|
6883
6981
|
options.providerId,
|
|
6884
6982
|
options.model
|
|
6885
6983
|
);
|
|
6886
|
-
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess',
|
|
6887
|
-
const actualModel = _optionalChain([routedInfo, 'optionalAccess',
|
|
6984
|
+
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _435 => _435.actualProviderId]) || options.providerId;
|
|
6985
|
+
const actualModel = _optionalChain([routedInfo, 'optionalAccess', _436 => _436.actualModelId]) || options.model;
|
|
6888
6986
|
const provider = await getProvider(actualProviderId);
|
|
6889
6987
|
if (!provider) {
|
|
6890
6988
|
return { success: false, error: `Provider not found: ${actualProviderId}` };
|
|
@@ -6914,7 +7012,8 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
|
|
|
6914
7012
|
name: provider.name,
|
|
6915
7013
|
baseUrl: provider.api_base_url,
|
|
6916
7014
|
apiKey,
|
|
6917
|
-
models: provider.models || []
|
|
7015
|
+
models: provider.models || [],
|
|
7016
|
+
modelConfigs: provider.modelConfigs
|
|
6918
7017
|
};
|
|
6919
7018
|
const executor = getSharedExecutor2();
|
|
6920
7019
|
const { response } = await _chunkMUHWHQVMcjs.executeProviderCall.call(void 0, {
|
|
@@ -6960,18 +7059,18 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
|
|
|
6960
7059
|
{ endpointTransformer: void 0 }
|
|
6961
7060
|
);
|
|
6962
7061
|
const data = await transformedResponse.json();
|
|
6963
|
-
const choice = _optionalChain([data, 'access',
|
|
7062
|
+
const choice = _optionalChain([data, 'access', _437 => _437.choices, 'optionalAccess', _438 => _438[0]]);
|
|
6964
7063
|
if (!choice) {
|
|
6965
7064
|
return { success: false, error: "No choices in response" };
|
|
6966
7065
|
}
|
|
6967
|
-
const rawToolCalls = _optionalChain([choice, 'access',
|
|
6968
|
-
const toolCalls = _optionalChain([rawToolCalls, 'optionalAccess',
|
|
7066
|
+
const rawToolCalls = _optionalChain([choice, 'access', _439 => _439.message, 'optionalAccess', _440 => _440.tool_calls]);
|
|
7067
|
+
const toolCalls = _optionalChain([rawToolCalls, 'optionalAccess', _441 => _441.map, 'call', _442 => _442((tc) => ({
|
|
6969
7068
|
id: tc.id,
|
|
6970
7069
|
name: tc.function.name,
|
|
6971
7070
|
args: typeof tc.function.arguments === "string" ? JSON.parse(tc.function.arguments) : tc.function.arguments
|
|
6972
7071
|
}))]);
|
|
6973
7072
|
const tapped = readUsageFromOpenAIResponse(data.usage);
|
|
6974
|
-
if (_optionalChain([recording, 'optionalAccess',
|
|
7073
|
+
if (_optionalChain([recording, 'optionalAccess', _443 => _443.recorder]) && tapped) {
|
|
6975
7074
|
recording.recorder.record({
|
|
6976
7075
|
messageId: _nullishCoalesce(options.messageId, () => ( null)),
|
|
6977
7076
|
parentMessageId: _nullishCoalesce(options.parentMessageId, () => ( null)),
|
|
@@ -6989,9 +7088,9 @@ async function completeWithTransformers(options, llmConfig, getProvider, resolve
|
|
|
6989
7088
|
message: {
|
|
6990
7089
|
id: `msg_${Date.now()}`,
|
|
6991
7090
|
role: "assistant",
|
|
6992
|
-
content: _optionalChain([choice, 'access',
|
|
7091
|
+
content: _optionalChain([choice, 'access', _444 => _444.message, 'optionalAccess', _445 => _445.content]) || "",
|
|
6993
7092
|
timestamp: Date.now(),
|
|
6994
|
-
thinking: data.reasoning_content || _optionalChain([choice, 'access',
|
|
7093
|
+
thinking: data.reasoning_content || _optionalChain([choice, 'access', _446 => _446.message, 'optionalAccess', _447 => _447.thinking, 'optionalAccess', _448 => _448.content]) ? { content: data.reasoning_content || _optionalChain([choice, 'access', _449 => _449.message, 'optionalAccess', _450 => _450.thinking, 'optionalAccess', _451 => _451.content]) || "", signature: _optionalChain([choice, 'access', _452 => _452.message, 'optionalAccess', _453 => _453.thinking, 'optionalAccess', _454 => _454.signature]) } : void 0,
|
|
6995
7094
|
toolCalls
|
|
6996
7095
|
},
|
|
6997
7096
|
usage: data.usage ? {
|
|
@@ -7012,21 +7111,21 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
7012
7111
|
options.providerId,
|
|
7013
7112
|
options.model
|
|
7014
7113
|
);
|
|
7015
|
-
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess',
|
|
7016
|
-
const actualModel = _optionalChain([routedInfo, 'optionalAccess',
|
|
7114
|
+
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _455 => _455.actualProviderId]) || options.providerId;
|
|
7115
|
+
const actualModel = _optionalChain([routedInfo, 'optionalAccess', _456 => _456.actualModelId]) || options.model;
|
|
7017
7116
|
const provider = await getProvider(actualProviderId);
|
|
7018
7117
|
if (!provider) {
|
|
7019
|
-
_optionalChain([callbacks, 'access',
|
|
7118
|
+
_optionalChain([callbacks, 'access', _457 => _457.onError, 'optionalCall', _458 => _458(`Provider not found: ${actualProviderId}`)]);
|
|
7020
7119
|
return;
|
|
7021
7120
|
}
|
|
7022
7121
|
if (!provider.enabled) {
|
|
7023
|
-
_optionalChain([callbacks, 'access',
|
|
7122
|
+
_optionalChain([callbacks, 'access', _459 => _459.onError, 'optionalCall', _460 => _460(`Provider is disabled: ${provider.name}`)]);
|
|
7024
7123
|
return;
|
|
7025
7124
|
}
|
|
7026
7125
|
const { apiKey: effectiveKey } = _chunkA2YMUCBTcjs.resolveProviderEndpoint.call(void 0, provider);
|
|
7027
7126
|
const apiKey = resolveApiKey2(effectiveKey);
|
|
7028
7127
|
if (!apiKey) {
|
|
7029
|
-
_optionalChain([callbacks, 'access',
|
|
7128
|
+
_optionalChain([callbacks, 'access', _461 => _461.onError, 'optionalCall', _462 => _462("API key not configured")]);
|
|
7030
7129
|
return;
|
|
7031
7130
|
}
|
|
7032
7131
|
const { chain, hasTransformers } = await resolveChainWithMain(
|
|
@@ -7038,13 +7137,14 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
7038
7137
|
return completeStreamFallback(options, callbacks);
|
|
7039
7138
|
}
|
|
7040
7139
|
const messageId = `msg_${Date.now()}`;
|
|
7041
|
-
_optionalChain([callbacks, 'access',
|
|
7140
|
+
_optionalChain([callbacks, 'access', _463 => _463.onStart, 'optionalCall', _464 => _464(messageId)]);
|
|
7042
7141
|
const unifiedRequest = buildUnifiedCompletionRequest(actualModel, options, true);
|
|
7043
7142
|
const transformerProvider = {
|
|
7044
7143
|
name: provider.name,
|
|
7045
7144
|
baseUrl: provider.api_base_url,
|
|
7046
7145
|
apiKey,
|
|
7047
|
-
models: provider.models || []
|
|
7146
|
+
models: provider.models || [],
|
|
7147
|
+
modelConfigs: provider.modelConfigs
|
|
7048
7148
|
};
|
|
7049
7149
|
const executor = getSharedExecutor2();
|
|
7050
7150
|
const { response } = await _chunkMUHWHQVMcjs.executeProviderCall.call(void 0, {
|
|
@@ -7077,7 +7177,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
7077
7177
|
});
|
|
7078
7178
|
if (!response.ok) {
|
|
7079
7179
|
const errorText = await response.text();
|
|
7080
|
-
_optionalChain([callbacks, 'access',
|
|
7180
|
+
_optionalChain([callbacks, 'access', _465 => _465.onError, 'optionalCall', _466 => _466(`API error (${response.status}): ${errorText}`)]);
|
|
7081
7181
|
return;
|
|
7082
7182
|
}
|
|
7083
7183
|
const transformedResponse = await executor.executeResponseChain(
|
|
@@ -7087,9 +7187,9 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
7087
7187
|
chain,
|
|
7088
7188
|
{ endpointTransformer: void 0 }
|
|
7089
7189
|
);
|
|
7090
|
-
const reader = _optionalChain([transformedResponse, 'access',
|
|
7190
|
+
const reader = _optionalChain([transformedResponse, 'access', _467 => _467.body, 'optionalAccess', _468 => _468.getReader, 'call', _469 => _469()]);
|
|
7091
7191
|
if (!reader) {
|
|
7092
|
-
_optionalChain([callbacks, 'access',
|
|
7192
|
+
_optionalChain([callbacks, 'access', _470 => _470.onError, 'optionalCall', _471 => _471("No response body")]);
|
|
7093
7193
|
return;
|
|
7094
7194
|
}
|
|
7095
7195
|
const decoder = new TextDecoder();
|
|
@@ -7107,22 +7207,22 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
7107
7207
|
if (data === "[DONE]") continue;
|
|
7108
7208
|
try {
|
|
7109
7209
|
const json = JSON.parse(data);
|
|
7110
|
-
const delta = _optionalChain([json, 'access',
|
|
7111
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
7210
|
+
const delta = _optionalChain([json, 'access', _472 => _472.choices, 'optionalAccess', _473 => _473[0], 'optionalAccess', _474 => _474.delta]);
|
|
7211
|
+
if (_optionalChain([delta, 'optionalAccess', _475 => _475.content])) {
|
|
7112
7212
|
content += delta.content;
|
|
7113
|
-
_optionalChain([callbacks, 'access',
|
|
7213
|
+
_optionalChain([callbacks, 'access', _476 => _476.onDelta, 'optionalCall', _477 => _477(delta.content)]);
|
|
7114
7214
|
}
|
|
7115
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
7215
|
+
if (_optionalChain([delta, 'optionalAccess', _478 => _478.thinking, 'optionalAccess', _479 => _479.content])) {
|
|
7116
7216
|
reasoning += delta.thinking.content;
|
|
7117
|
-
_optionalChain([callbacks, 'access',
|
|
7217
|
+
_optionalChain([callbacks, 'access', _480 => _480.onReasoning, 'optionalCall', _481 => _481(delta.thinking.content)]);
|
|
7118
7218
|
}
|
|
7119
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
7219
|
+
if (_optionalChain([delta, 'optionalAccess', _482 => _482.reasoning_content])) {
|
|
7120
7220
|
reasoning += delta.reasoning_content;
|
|
7121
|
-
_optionalChain([callbacks, 'access',
|
|
7221
|
+
_optionalChain([callbacks, 'access', _483 => _483.onReasoning, 'optionalCall', _484 => _484(delta.reasoning_content)]);
|
|
7122
7222
|
}
|
|
7123
7223
|
if (json.usage) {
|
|
7124
7224
|
const tapped = readUsageFromOpenAIResponse(json.usage);
|
|
7125
|
-
if (_optionalChain([recording, 'optionalAccess',
|
|
7225
|
+
if (_optionalChain([recording, 'optionalAccess', _485 => _485.recorder]) && tapped) {
|
|
7126
7226
|
recording.recorder.record({
|
|
7127
7227
|
messageId: _nullishCoalesce(options.messageId, () => ( null)),
|
|
7128
7228
|
parentMessageId: _nullishCoalesce(options.parentMessageId, () => ( null)),
|
|
@@ -7135,7 +7235,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
7135
7235
|
rawUsage: json.usage
|
|
7136
7236
|
});
|
|
7137
7237
|
}
|
|
7138
|
-
_optionalChain([callbacks, 'access',
|
|
7238
|
+
_optionalChain([callbacks, 'access', _486 => _486.onDone, 'optionalCall', _487 => _487(
|
|
7139
7239
|
{
|
|
7140
7240
|
id: messageId,
|
|
7141
7241
|
role: "assistant",
|
|
@@ -7156,7 +7256,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
7156
7256
|
}
|
|
7157
7257
|
}
|
|
7158
7258
|
}
|
|
7159
|
-
_optionalChain([callbacks, 'access',
|
|
7259
|
+
_optionalChain([callbacks, 'access', _488 => _488.onDone, 'optionalCall', _489 => _489({
|
|
7160
7260
|
id: messageId,
|
|
7161
7261
|
role: "assistant",
|
|
7162
7262
|
content,
|
|
@@ -7168,7 +7268,7 @@ async function completeStreamWithTransformers(options, callbacks, llmConfig, get
|
|
|
7168
7268
|
}
|
|
7169
7269
|
} catch (error) {
|
|
7170
7270
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
7171
|
-
_optionalChain([callbacks, 'access',
|
|
7271
|
+
_optionalChain([callbacks, 'access', _490 => _490.onError, 'optionalCall', _491 => _491(message)]);
|
|
7172
7272
|
}
|
|
7173
7273
|
}
|
|
7174
7274
|
|
|
@@ -7235,8 +7335,8 @@ var CompletionService = (_class15 = class {
|
|
|
7235
7335
|
options.providerId,
|
|
7236
7336
|
options.model
|
|
7237
7337
|
);
|
|
7238
|
-
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess',
|
|
7239
|
-
const actualModel = _optionalChain([routedInfo, 'optionalAccess',
|
|
7338
|
+
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _492 => _492.actualProviderId]) || options.providerId;
|
|
7339
|
+
const actualModel = _optionalChain([routedInfo, 'optionalAccess', _493 => _493.actualModelId]) || options.model;
|
|
7240
7340
|
const provider = await this.getProvider(actualProviderId);
|
|
7241
7341
|
if (!provider) {
|
|
7242
7342
|
return { success: false, error: `Provider not found: ${actualProviderId}` };
|
|
@@ -7269,7 +7369,7 @@ var CompletionService = (_class15 = class {
|
|
|
7269
7369
|
this.apiKeyPool.reportSuccess(options.sessionId);
|
|
7270
7370
|
}
|
|
7271
7371
|
if (result.success && result.usage && options.sessionId) {
|
|
7272
|
-
_optionalChain([this, 'access',
|
|
7372
|
+
_optionalChain([this, 'access', _494 => _494.usageEventSink, 'optionalAccess', _495 => _495.emit, 'call', _496 => _496({
|
|
7273
7373
|
sessionId: options.sessionId,
|
|
7274
7374
|
modelId: actualModel,
|
|
7275
7375
|
usage: result.usage,
|
|
@@ -7298,8 +7398,8 @@ var CompletionService = (_class15 = class {
|
|
|
7298
7398
|
options.model
|
|
7299
7399
|
);
|
|
7300
7400
|
this.logger.debug("Resolved routed model", { routedInfo });
|
|
7301
|
-
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess',
|
|
7302
|
-
const actualModel = _optionalChain([routedInfo, 'optionalAccess',
|
|
7401
|
+
const actualProviderId = _optionalChain([routedInfo, 'optionalAccess', _497 => _497.actualProviderId]) || options.providerId;
|
|
7402
|
+
const actualModel = _optionalChain([routedInfo, 'optionalAccess', _498 => _498.actualModelId]) || options.model;
|
|
7303
7403
|
this.logger.debug("Resolved provider and model", { actualProviderId, actualModel });
|
|
7304
7404
|
const provider = await this.getProvider(actualProviderId);
|
|
7305
7405
|
this.logger.debug("Retrieved provider", provider ? {
|
|
@@ -7311,22 +7411,22 @@ var CompletionService = (_class15 = class {
|
|
|
7311
7411
|
enabled: provider.enabled
|
|
7312
7412
|
} : { error: "Provider not found" });
|
|
7313
7413
|
if (!provider) {
|
|
7314
|
-
_optionalChain([callbacks, 'access',
|
|
7414
|
+
_optionalChain([callbacks, 'access', _499 => _499.onError, 'optionalCall', _500 => _500(`Provider not found: ${actualProviderId}`)]);
|
|
7315
7415
|
return;
|
|
7316
7416
|
}
|
|
7317
7417
|
if (!provider.enabled) {
|
|
7318
|
-
_optionalChain([callbacks, 'access',
|
|
7418
|
+
_optionalChain([callbacks, 'access', _501 => _501.onError, 'optionalCall', _502 => _502(`Provider is disabled: ${provider.name}`)]);
|
|
7319
7419
|
return;
|
|
7320
7420
|
}
|
|
7321
7421
|
const apiKey = await this.resolveApiKeyForRequest(provider, actualProviderId, options.sessionId);
|
|
7322
7422
|
if (!apiKey) {
|
|
7323
|
-
_optionalChain([callbacks, 'access',
|
|
7423
|
+
_optionalChain([callbacks, 'access', _503 => _503.onError, 'optionalCall', _504 => _504("API key not configured")]);
|
|
7324
7424
|
return;
|
|
7325
7425
|
}
|
|
7326
7426
|
const apiFormat = _chunkA2YMUCBTcjs.resolveApiFormat.call(void 0, provider);
|
|
7327
7427
|
this.logger.info("Using API format for stream", { apiFormat });
|
|
7328
7428
|
const messageId = `msg_${Date.now()}`;
|
|
7329
|
-
_optionalChain([callbacks, 'access',
|
|
7429
|
+
_optionalChain([callbacks, 'access', _505 => _505.onStart, 'optionalCall', _506 => _506(messageId)]);
|
|
7330
7430
|
const resolvedOptions = { ...options, model: actualModel };
|
|
7331
7431
|
if (options.sessionId) {
|
|
7332
7432
|
const sid = options.sessionId;
|
|
@@ -7335,14 +7435,14 @@ var CompletionService = (_class15 = class {
|
|
|
7335
7435
|
...callbacks,
|
|
7336
7436
|
onDone: (message, usage, metrics) => {
|
|
7337
7437
|
if (usage) {
|
|
7338
|
-
_optionalChain([this, 'access',
|
|
7438
|
+
_optionalChain([this, 'access', _507 => _507.usageEventSink, 'optionalAccess', _508 => _508.emit, 'call', _509 => _509({
|
|
7339
7439
|
sessionId: sid,
|
|
7340
7440
|
modelId: actualModel,
|
|
7341
7441
|
usage,
|
|
7342
7442
|
engineOrigin: "completion"
|
|
7343
7443
|
})]);
|
|
7344
7444
|
}
|
|
7345
|
-
_optionalChain([userOnDone, 'optionalCall',
|
|
7445
|
+
_optionalChain([userOnDone, 'optionalCall', _510 => _510(message, usage, metrics)]);
|
|
7346
7446
|
}
|
|
7347
7447
|
};
|
|
7348
7448
|
}
|
|
@@ -7358,11 +7458,11 @@ var CompletionService = (_class15 = class {
|
|
|
7358
7458
|
retryState.error = { status, message: error };
|
|
7359
7459
|
return;
|
|
7360
7460
|
}
|
|
7361
|
-
_optionalChain([callbacks, 'access',
|
|
7461
|
+
_optionalChain([callbacks, 'access', _511 => _511.onError, 'optionalCall', _512 => _512(error)]);
|
|
7362
7462
|
},
|
|
7363
7463
|
onDone: (message, usage, metrics) => {
|
|
7364
7464
|
this.apiKeyPool.reportSuccess(options.sessionId);
|
|
7365
|
-
_optionalChain([callbacks, 'access',
|
|
7465
|
+
_optionalChain([callbacks, 'access', _513 => _513.onDone, 'optionalCall', _514 => _514(message, usage, metrics)]);
|
|
7366
7466
|
}
|
|
7367
7467
|
};
|
|
7368
7468
|
await this.callStreamHandler(apiFormat, provider, apiKey, resolvedOptions, messageId, interceptCallbacks);
|
|
@@ -7383,7 +7483,7 @@ var CompletionService = (_class15 = class {
|
|
|
7383
7483
|
// don't fire onStart again
|
|
7384
7484
|
});
|
|
7385
7485
|
} else {
|
|
7386
|
-
_optionalChain([callbacks, 'access',
|
|
7486
|
+
_optionalChain([callbacks, 'access', _515 => _515.onError, 'optionalCall', _516 => _516(retryState.error.message)]);
|
|
7387
7487
|
}
|
|
7388
7488
|
}
|
|
7389
7489
|
} else {
|
|
@@ -7396,7 +7496,7 @@ var CompletionService = (_class15 = class {
|
|
|
7396
7496
|
} catch (error) {
|
|
7397
7497
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
7398
7498
|
this.logger.error("Stream completion error", error instanceof Error ? error : void 0, { message });
|
|
7399
|
-
_optionalChain([callbacks, 'access',
|
|
7499
|
+
_optionalChain([callbacks, 'access', _517 => _517.onError, 'optionalCall', _518 => _518(message)]);
|
|
7400
7500
|
}
|
|
7401
7501
|
}
|
|
7402
7502
|
/**
|
|
@@ -7436,7 +7536,7 @@ var CompletionService = (_class15 = class {
|
|
|
7436
7536
|
return {
|
|
7437
7537
|
success: true,
|
|
7438
7538
|
message: "Connection successful",
|
|
7439
|
-
response: _optionalChain([result, 'access',
|
|
7539
|
+
response: _optionalChain([result, 'access', _519 => _519.message, 'optionalAccess', _520 => _520.content]) || "",
|
|
7440
7540
|
model: modelId,
|
|
7441
7541
|
durationMs
|
|
7442
7542
|
};
|
|
@@ -7501,7 +7601,7 @@ ${description}`;
|
|
|
7501
7601
|
* 3. Legacy single key from provider config
|
|
7502
7602
|
*/
|
|
7503
7603
|
async resolveApiKeyForRequest(provider, providerId, sessionId) {
|
|
7504
|
-
if (_optionalChain([provider, 'access',
|
|
7604
|
+
if (_optionalChain([provider, 'access', _521 => _521.codingPlan, 'optionalAccess', _522 => _522.enabled]) && provider.codingPlan.apiKey) {
|
|
7505
7605
|
return this.resolveApiKey(provider.codingPlan.apiKey);
|
|
7506
7606
|
}
|
|
7507
7607
|
if (this.apiKeyPool) {
|