@nexus-cortex/core 4.124.45 → 4.124.47
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/.env.defaults +90 -1
- package/dist/adapters/ChatCompletionsAPIAdapter.d.ts.map +1 -1
- package/dist/adapters/ChatCompletionsAPIAdapter.js +10 -0
- package/dist/adapters/ChatCompletionsAPIAdapter.js.map +1 -1
- package/dist/adapters/GatewayTranslationLayer.d.ts.map +1 -1
- package/dist/adapters/GatewayTranslationLayer.js +33 -0
- package/dist/adapters/GatewayTranslationLayer.js.map +1 -1
- package/dist/adapters/ServerSideToolDetection.d.ts.map +1 -1
- package/dist/adapters/ServerSideToolDetection.js +5 -1
- package/dist/adapters/ServerSideToolDetection.js.map +1 -1
- package/dist/config/SettingsSchema.js +2 -2
- package/dist/config/SettingsSchema.js.map +1 -1
- package/dist/config/effectiveConfig.d.ts.map +1 -1
- package/dist/config/effectiveConfig.js +9 -0
- package/dist/config/effectiveConfig.js.map +1 -1
- package/dist/models/cards/xai/grok-4-3-chat.d.ts +15 -0
- package/dist/models/cards/xai/grok-4-3-chat.d.ts.map +1 -0
- package/dist/models/cards/xai/grok-4-3-chat.js +28 -0
- package/dist/models/cards/xai/grok-4-3-chat.js.map +1 -0
- package/dist/models/cards/xai/grok-build-0-1-chat.d.ts +17 -0
- package/dist/models/cards/xai/grok-build-0-1-chat.d.ts.map +1 -0
- package/dist/models/cards/xai/grok-build-0-1-chat.js +31 -0
- package/dist/models/cards/xai/grok-build-0-1-chat.js.map +1 -0
- package/dist/models/cards/xai/index.d.ts +2 -0
- package/dist/models/cards/xai/index.d.ts.map +1 -1
- package/dist/models/cards/xai/index.js +2 -0
- package/dist/models/cards/xai/index.js.map +1 -1
- package/dist/models/configurators/XAIConfigurator.d.ts +7 -1
- package/dist/models/configurators/XAIConfigurator.d.ts.map +1 -1
- package/dist/models/configurators/XAIConfigurator.js +15 -3
- package/dist/models/configurators/XAIConfigurator.js.map +1 -1
- package/dist/models/registry/ModularModelRegistry.d.ts.map +1 -1
- package/dist/models/registry/ModularModelRegistry.js +2 -0
- package/dist/models/registry/ModularModelRegistry.js.map +1 -1
- package/dist/orchestrator/APIClient.d.ts +4 -0
- package/dist/orchestrator/APIClient.d.ts.map +1 -1
- package/dist/orchestrator/APIClient.js +181 -25
- package/dist/orchestrator/APIClient.js.map +1 -1
- package/dist/orchestrator/CortexOrchestrator.d.ts.map +1 -1
- package/dist/orchestrator/CortexOrchestrator.js +8 -2
- package/dist/orchestrator/CortexOrchestrator.js.map +1 -1
- package/dist/orchestrator/appendOnlyHistory.d.ts.map +1 -1
- package/dist/orchestrator/appendOnlyHistory.js +4 -0
- package/dist/orchestrator/appendOnlyHistory.js.map +1 -1
- package/dist/orchestrator/geminiExplicitCache.d.ts +79 -0
- package/dist/orchestrator/geminiExplicitCache.d.ts.map +1 -0
- package/dist/orchestrator/geminiExplicitCache.js +324 -0
- package/dist/orchestrator/geminiExplicitCache.js.map +1 -0
- package/dist/orchestrator/transportEffortFixes.d.ts +62 -0
- package/dist/orchestrator/transportEffortFixes.d.ts.map +1 -0
- package/dist/orchestrator/transportEffortFixes.js +114 -0
- package/dist/orchestrator/transportEffortFixes.js.map +1 -0
- package/dist/orchestrator/xaiChatTransport.d.ts +27 -0
- package/dist/orchestrator/xaiChatTransport.d.ts.map +1 -0
- package/dist/orchestrator/xaiChatTransport.js +33 -0
- package/dist/orchestrator/xaiChatTransport.js.map +1 -0
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModularModelRegistry.js","sourceRoot":"","sources":["../../../src/models/registry/ModularModelRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,6CAA6C;AAC7C,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,cAAc,MAAM,4BAA4B,CAAC;AAC7D,OAA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KAAK,CAAC,MAAM,CAAC,aAAa,GAAG,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,YAAY,CACrE,CAAC;YACF,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QAChC,CAAC;aAAM,IAAI,MAAM,CAAC,MAAM,KAAK,UAAU,IAAI,MAAM,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YACzE,OAAO,MAAM,CAAC,QAAQ,CAAC;QACzB,CAAC;QAED,wEAAwE;QACxE,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,GAAG,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC;IAC1E,CAAC;IAED;;;OAGG;IACH,YAAY;QACV,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1C,CAAC;CACF"}
|
|
@@ -75,7 +75,11 @@ export declare class APIClient {
|
|
|
75
75
|
private openaiClient?;
|
|
76
76
|
private googleClient?;
|
|
77
77
|
private googleGenAIClient?;
|
|
78
|
+
/** HB-GEMINI-EXPLICIT-CACHE (DARK): per-client cachedContents snapshots, keyed by session + head. Inert when off. */
|
|
79
|
+
private geminiCache;
|
|
78
80
|
constructor();
|
|
81
|
+
/** HB-GEMINI-EXPLICIT-CACHE: best-effort DELETE of every live Gemini cachedContents snapshot (session end). */
|
|
82
|
+
disposeGeminiCaches(): Promise<void>;
|
|
79
83
|
/**
|
|
80
84
|
* Decode HTML entities in an object (recursive)
|
|
81
85
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"APIClient.d.ts","sourceRoot":"","sources":["../../src/orchestrator/APIClient.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"APIClient.d.ts","sourceRoot":"","sources":["../../src/orchestrator/APIClient.ts"],"names":[],"mappings":"AAA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sBAAsB;IAqBpC;;;;;;;;;OASG;YACW,cAAc;IAoE5B;;;;;;;;;;OAUG;IACH,OAAO,CAAC,qCAAqC;IAuD7C;;;;;OAKG;YACW,gBAAgB;IAuM9B;;;;;OAKG;YACW,sBAAsB;IAsDpC;;;OAGG;YACW,uBAAuB;IAqFrC;;;;;;OAMG;YACW,sBAAsB;IA+CpC;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;IA2rBzB;;;;;;OAMG;IACH,OAAO,CAAC,wBAAwB;IAiMhC;;;;;;OAMG;IACH,OAAO,CAAC,kBAAkB;IAgX1B;;;;;;OAMG;IACH,OAAO,CAAC,wBAAwB;IAkEhC;;;OAGG;IACH,OAAO,CAAC,yBAAyB;IAyQjC;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAyDxB;;;OAGG;YACW,aAAa;IA8G3B;;;;;;;;;OASG;IACH,OAAO,CAAC,eAAe;CA8UxB"}
|
|
@@ -21,6 +21,9 @@ import { assertCompletionBody } from './completionBodyGuard.js';
|
|
|
21
21
|
import { parseHFCompletion, normalizeToolCallArguments } from '../models/hfSpace/normalize.js';
|
|
22
22
|
import { isResponsesInlineRemindersEnabled, inlineRemindersForResponses, isResponsesStopReasonEnabled, isAnthropicHistoryCacheEnabled, applyAnthropicHistoryCache, countAnthropicBreakpoints, } from './transportFixes.js';
|
|
23
23
|
import { isGeminiSystemFixEnabled, isOpenAICacheKeyEnabled, isStreamUsageEnabled, applyAnthropicCacheLevers, streamFinalUsage, } from './transportCacheFixes.js';
|
|
24
|
+
import { isAnthropicEffortEnabled, isGeminiToolsThinkingEnabled, anthropicOutputEffort, anthropicMaxEffortBudget, } from './transportEffortFixes.js';
|
|
25
|
+
import { GeminiExplicitCacheManager, isGeminiExplicitCacheEnabled, isCacheUseFailure, geminiBaseFromEndpoint, } from './geminiExplicitCache.js';
|
|
26
|
+
import { isXAIChatRoute, xaiChatReasoningEffort } from './xaiChatTransport.js';
|
|
24
27
|
import { anthropicCredentialService, CredentialError } from '../config/AnthropicCredentialService.js';
|
|
25
28
|
/**
|
|
26
29
|
* Anthropic families on the adaptive-thinking-only request surface — sending
|
|
@@ -60,9 +63,18 @@ export class APIClient {
|
|
|
60
63
|
openaiClient;
|
|
61
64
|
googleClient;
|
|
62
65
|
googleGenAIClient;
|
|
66
|
+
/** HB-GEMINI-EXPLICIT-CACHE (DARK): per-client cachedContents snapshots, keyed by session + head. Inert when off. */
|
|
67
|
+
geminiCache = new GeminiExplicitCacheManager({ fetchImpl: (url, init) => cortexProxyFetch(url, init) });
|
|
63
68
|
constructor() {
|
|
64
69
|
// Initialize clients lazily when needed
|
|
65
70
|
}
|
|
71
|
+
/** HB-GEMINI-EXPLICIT-CACHE: best-effort DELETE of every live Gemini cachedContents snapshot (session end). */
|
|
72
|
+
async disposeGeminiCaches() {
|
|
73
|
+
try {
|
|
74
|
+
await this.geminiCache.disposeAll(process.env['GEMINI_API_KEY']);
|
|
75
|
+
}
|
|
76
|
+
catch { /* best-effort */ }
|
|
77
|
+
}
|
|
66
78
|
/**
|
|
67
79
|
* Decode HTML entities in an object (recursive)
|
|
68
80
|
*
|
|
@@ -382,6 +394,11 @@ export class APIClient {
|
|
|
382
394
|
process.env.DEBUG_THINKING === 'true'
|
|
383
395
|
? { type: 'adaptive', display: 'summarized' }
|
|
384
396
|
: { type: 'adaptive' };
|
|
397
|
+
// DARK (CORTEX_ANTHROPIC_EFFORT): the action/request effort reaches adaptive families as output_config.effort.
|
|
398
|
+
const outputEffort = isAnthropicEffortEnabled() ? anthropicOutputEffort(reasoningEffort) : undefined;
|
|
399
|
+
if (outputEffort) {
|
|
400
|
+
anthropicRequest.output_config = { ...(anthropicRequest.output_config || {}), effort: outputEffort };
|
|
401
|
+
}
|
|
385
402
|
}
|
|
386
403
|
else {
|
|
387
404
|
const budgetMap = {
|
|
@@ -390,7 +407,11 @@ export class APIClient {
|
|
|
390
407
|
medium: 10000,
|
|
391
408
|
high: 50000,
|
|
392
409
|
};
|
|
393
|
-
|
|
410
|
+
// DARK (CORTEX_ANTHROPIC_EFFORT): 'max' gets a large budget clamped below max_tokens (was the 10000 fallback).
|
|
411
|
+
const maxBudget = isAnthropicEffortEnabled() && reasoningEffort === 'max'
|
|
412
|
+
? anthropicMaxEffortBudget(anthropicRequest.max_tokens)
|
|
413
|
+
: undefined;
|
|
414
|
+
const budgetTokens = maxBudget ?? (reasoningEffort ? (budgetMap[reasoningEffort] || 10000) : 10000);
|
|
394
415
|
anthropicRequest.thinking = {
|
|
395
416
|
type: 'enabled',
|
|
396
417
|
budget_tokens: budgetTokens
|
|
@@ -675,6 +696,13 @@ export class APIClient {
|
|
|
675
696
|
.replace('/messages', '')
|
|
676
697
|
.replace('/responses', '');
|
|
677
698
|
const defaultHeaders = {};
|
|
699
|
+
// xAI chat/completions (third xAI transport, DARK — reachable only via an xAI 'chat' card / XAI_API_MODE=chat):
|
|
700
|
+
// `x-grok-conv-id` sticky routing, mirroring the xAI Messages path's header (xAI prompt-caching docs: the cached prefix
|
|
701
|
+
// lives on one backend instance). Header-only — the request body / cached prefix is unchanged.
|
|
702
|
+
const xaiChat = isXAIChatRoute(modelConfig);
|
|
703
|
+
if (xaiChat && request.conversationId) {
|
|
704
|
+
defaultHeaders['x-grok-conv-id'] = request.conversationId;
|
|
705
|
+
}
|
|
678
706
|
// Reuse cached openai client when possible (matches the streaming path's
|
|
679
707
|
// pre-refactor behavior; now applied uniformly).
|
|
680
708
|
const client = modelConfig.provider.toLowerCase() === 'openai' && this.openaiClient
|
|
@@ -707,6 +735,8 @@ export class APIClient {
|
|
|
707
735
|
const reasoningEffort = transformedParams.reasoningEffort
|
|
708
736
|
|| modelConfig.reasoning?.effort
|
|
709
737
|
|| 'medium';
|
|
738
|
+
// xAI chat: the REQUEST/action effort only (the card default is resolved by xaiChatReasoningEffort's capability gate).
|
|
739
|
+
const xaiRequestedEffort = transformedParams.reasoningEffort;
|
|
710
740
|
delete transformedParams.reasoningEffort;
|
|
711
741
|
if (process.env.DEBUG === 'true') {
|
|
712
742
|
console.log(`[Effort] outbound reasoning_effort=${reasoningEffort} (source: ${request.parameters?.reasoningEffort ? 'request/pulse' : (modelConfig.reasoning?.effort ? 'card' : 'default')})`);
|
|
@@ -735,6 +765,12 @@ export class APIClient {
|
|
|
735
765
|
...transformedParams,
|
|
736
766
|
...(opts.stream ? { stream: true } : {}),
|
|
737
767
|
};
|
|
768
|
+
// xAI chat: the gateway's params.model (= registry id, e.g. 'grok-4.3-chat') is spread AFTER `model:` above and would
|
|
769
|
+
// send the registry id; the chat cards carry the wire name in `modelId` (resolved into request.modelId). Scoped to xAI
|
|
770
|
+
// chat so every other chat/completions provider keeps its existing bytes (pre-existing for any chat card whose id ≠
|
|
771
|
+
// modelId, e.g. gpt-5.1-reasoning — reported, not changed here).
|
|
772
|
+
if (xaiChat)
|
|
773
|
+
chatRequest.model = request.modelId;
|
|
738
774
|
// R19b: OpenAI chat/completions REJECTS `reasoning_effort` + tools for
|
|
739
775
|
// some gpt-5 variants (`gpt-5.4`, possibly others) with
|
|
740
776
|
// "400 Function tools with reasoning_effort are not supported for ... in /v1/chat/completions".
|
|
@@ -747,10 +783,23 @@ export class APIClient {
|
|
|
747
783
|
// deepseek runs (reasoning + tools, no forced choice) are fine — so drop reasoning ONLY when a
|
|
748
784
|
// tool_choice is actually forced. OpenAI's R19b case (tools alone) stays as-is.
|
|
749
785
|
const hasForcedToolChoice = !!request.toolChoice;
|
|
786
|
+
// R19b STAYS (live probe 2026-10-03): gpt-5.4-nano AND gpt-5.6-luna still 400 "Function tools with reasoning_effort are not
|
|
787
|
+
// supported … in /v1/chat/completions. To use function tools, use /v1/responses" — CORTEX_OPENAI_TOOLS_REASONING is Responses-only.
|
|
750
788
|
const dropReasoningForToolCompat = (willAttachTools && isChatCompletionsRoute && modelConfig.provider === 'openai') ||
|
|
751
789
|
(hasForcedToolChoice && isChatCompletionsRoute && modelConfig.provider === 'deepseek');
|
|
752
|
-
//
|
|
753
|
-
|
|
790
|
+
// xAI chat/completions: per-card capability gate — reasoning_effort only for cards that declare an effort
|
|
791
|
+
// (grok-4.3-class); grok-build-0.1 400s on it and never gets it. Sampling params are kept (xAI accepts temperature/top_p
|
|
792
|
+
// with reasoning; only presence/frequency penalties + stop are rejected, and this builder never adds those).
|
|
793
|
+
if (xaiChat) {
|
|
794
|
+
const xaiEffort = disableThinking ? undefined : xaiChatReasoningEffort(xaiRequestedEffort, modelConfig);
|
|
795
|
+
if (xaiEffort)
|
|
796
|
+
chatRequest.reasoning_effort = xaiEffort;
|
|
797
|
+
if (process.env.DEBUG === 'true' || process.env.DEBUG_THINKING === 'true') {
|
|
798
|
+
console.log(`[DEBUG APIClient] xAI chat reasoning_effort=${xaiEffort ?? '(not sent)'} for ${modelConfig.id}`);
|
|
799
|
+
}
|
|
800
|
+
// Enable reasoning for OpenAI models that support it (GPT-5 family, o-series)
|
|
801
|
+
}
|
|
802
|
+
else if (modelConfig.reasoning?.supported &&
|
|
754
803
|
!disableThinking &&
|
|
755
804
|
reasoningEffort !== 'none' &&
|
|
756
805
|
!dropReasoningForToolCompat) {
|
|
@@ -1255,20 +1304,33 @@ export class APIClient {
|
|
|
1255
1304
|
console.log(`[DEBUG APIClient] Request body tools wrapper:`, JSON.stringify(requestBody.tools[0], null, 2).substring(0, 500));
|
|
1256
1305
|
}
|
|
1257
1306
|
}
|
|
1258
|
-
|
|
1259
|
-
const httpResponse = await cortexProxyFetch(url, {
|
|
1307
|
+
const postBody = (body) => cortexProxyFetch(url, {
|
|
1260
1308
|
method: 'POST',
|
|
1261
1309
|
headers: {
|
|
1262
1310
|
'Content-Type': 'application/json',
|
|
1263
1311
|
[modelConfig.api.authHeader]: apiKey
|
|
1264
1312
|
},
|
|
1265
|
-
body: JSON.stringify(
|
|
1313
|
+
body: JSON.stringify(body)
|
|
1266
1314
|
});
|
|
1315
|
+
// HB-GEMINI-EXPLICIT-CACHE (DARK, CORTEX_GEMINI_EXPLICIT_CACHE): off → no plan → the original body, unchanged.
|
|
1316
|
+
const cacheCtx = { sessionId: request.conversationId, modelId, apiKey, baseUrl: geminiBaseFromEndpoint(modelConfig.api.endpoint) };
|
|
1317
|
+
const cached = isGeminiExplicitCacheEnabled() ? await this.geminiCache.prepare(cacheCtx, 'rest', requestBody) : null;
|
|
1318
|
+
// Make HTTP request
|
|
1319
|
+
let httpResponse = await postBody(cached ? cached.body : requestBody);
|
|
1320
|
+
let usedCache = !!cached;
|
|
1321
|
+
if (cached && !httpResponse.ok && isCacheUseFailure(httpResponse.status)) {
|
|
1322
|
+
const errorText = await httpResponse.text();
|
|
1323
|
+
this.geminiCache.invalidate(cached.plan, `use_${httpResponse.status} ${errorText.replace(/\s+/g, ' ').slice(0, 160)}`, cacheCtx);
|
|
1324
|
+
usedCache = false;
|
|
1325
|
+
httpResponse = await postBody(requestBody); // the normal full request, once
|
|
1326
|
+
}
|
|
1267
1327
|
if (!httpResponse.ok) {
|
|
1268
1328
|
const errorText = await httpResponse.text();
|
|
1269
1329
|
throw new Error(`Google GenerateContent API error (${httpResponse.status}): ${errorText}`);
|
|
1270
1330
|
}
|
|
1271
1331
|
const data = await httpResponse.json();
|
|
1332
|
+
if (cached && usedCache)
|
|
1333
|
+
this.geminiCache.recordUsage(cached.plan, data?.usageMetadata);
|
|
1272
1334
|
// Return full response (same structure as SDK)
|
|
1273
1335
|
// The response has: candidates, usageMetadata, modelVersion, responseId
|
|
1274
1336
|
return {
|
|
@@ -1403,6 +1465,11 @@ export class APIClient {
|
|
|
1403
1465
|
process.env.DEBUG_THINKING === 'true'
|
|
1404
1466
|
? { type: 'adaptive', display: 'summarized' }
|
|
1405
1467
|
: { type: 'adaptive' };
|
|
1468
|
+
// DARK (CORTEX_ANTHROPIC_EFFORT): parity with the non-streaming path.
|
|
1469
|
+
const outputEffort = isAnthropicEffortEnabled() ? anthropicOutputEffort(reasoningEffort) : undefined;
|
|
1470
|
+
if (outputEffort) {
|
|
1471
|
+
anthropicRequest.output_config = { ...(anthropicRequest.output_config || {}), effort: outputEffort };
|
|
1472
|
+
}
|
|
1406
1473
|
if (process.env.DEBUG === 'true' || process.env.DEBUG_THINKING === 'true') {
|
|
1407
1474
|
console.log(`[DEBUG APIClient] Adaptive thinking for ${modelConfig.id}${process.env.DEBUG_THINKING === 'true' ? ' (display: summarized)' : ''}`);
|
|
1408
1475
|
}
|
|
@@ -1414,7 +1481,11 @@ export class APIClient {
|
|
|
1414
1481
|
medium: 10000,
|
|
1415
1482
|
high: 50000,
|
|
1416
1483
|
};
|
|
1417
|
-
|
|
1484
|
+
// DARK (CORTEX_ANTHROPIC_EFFORT): parity with the non-streaming path ('max' → clamped large budget).
|
|
1485
|
+
const maxBudget = isAnthropicEffortEnabled() && reasoningEffort === 'max'
|
|
1486
|
+
? anthropicMaxEffortBudget(anthropicRequest.max_tokens)
|
|
1487
|
+
: undefined;
|
|
1488
|
+
const budgetTokens = maxBudget ?? (reasoningEffort ? (budgetMap[reasoningEffort] || 10000) : 10000);
|
|
1418
1489
|
anthropicRequest.thinking = {
|
|
1419
1490
|
type: 'enabled',
|
|
1420
1491
|
budget_tokens: budgetTokens
|
|
@@ -2616,14 +2687,34 @@ export class APIClient {
|
|
|
2616
2687
|
// Write full request body to file for inspection
|
|
2617
2688
|
import('fs').then(fs => fs.writeFileSync('/tmp/gemini-request-' + modelId + '.json', JSON.stringify(requestBody, null, 2)));
|
|
2618
2689
|
}
|
|
2619
|
-
//
|
|
2620
|
-
const
|
|
2690
|
+
// HB-GEMINI-EXPLICIT-CACHE (DARK, CORTEX_GEMINI_EXPLICIT_CACHE): off → the original single fetch, unchanged.
|
|
2691
|
+
const geminiCacheOn = isGeminiExplicitCacheEnabled();
|
|
2692
|
+
const streamCache = {};
|
|
2693
|
+
let lastChunkUsage = undefined;
|
|
2694
|
+
const postStream = (body) => cortexProxyFetch(url, {
|
|
2621
2695
|
method: 'POST',
|
|
2622
2696
|
headers: {
|
|
2623
2697
|
'Content-Type': 'application/json'
|
|
2624
2698
|
},
|
|
2625
|
-
body: JSON.stringify(
|
|
2699
|
+
body: JSON.stringify(body)
|
|
2626
2700
|
});
|
|
2701
|
+
// Start the fetch request
|
|
2702
|
+
const fetchPromise = !geminiCacheOn
|
|
2703
|
+
? postStream(requestBody)
|
|
2704
|
+
: (async () => {
|
|
2705
|
+
const cacheCtx = { sessionId: request.conversationId, modelId, apiKey, baseUrl: geminiBaseFromEndpoint(modelConfig.api.endpoint) };
|
|
2706
|
+
const cached = await this.geminiCache.prepare(cacheCtx, 'rest', requestBody);
|
|
2707
|
+
let res = await postStream(cached ? cached.body : requestBody);
|
|
2708
|
+
if (cached && !res.ok && isCacheUseFailure(res.status)) {
|
|
2709
|
+
const errorText = await res.text();
|
|
2710
|
+
this.geminiCache.invalidate(cached.plan, `use_${res.status} ${errorText.replace(/\s+/g, ' ').slice(0, 160)}`, cacheCtx);
|
|
2711
|
+
res = await postStream(requestBody); // the normal full request, once
|
|
2712
|
+
}
|
|
2713
|
+
else if (cached) {
|
|
2714
|
+
streamCache.plan = cached.plan;
|
|
2715
|
+
}
|
|
2716
|
+
return res;
|
|
2717
|
+
})();
|
|
2627
2718
|
// Shared state for collecting all chunks
|
|
2628
2719
|
const allChunks = [];
|
|
2629
2720
|
let fullText = '';
|
|
@@ -2679,6 +2770,9 @@ export class APIClient {
|
|
|
2679
2770
|
if (chunk.candidates?.[0]) {
|
|
2680
2771
|
lastCandidate = chunk.candidates[0];
|
|
2681
2772
|
}
|
|
2773
|
+
// Gemini reports usageMetadata on the CHUNK, not the candidate (captured only with the cache lever on).
|
|
2774
|
+
if (geminiCacheOn && chunk.usageMetadata)
|
|
2775
|
+
lastChunkUsage = chunk.usageMetadata;
|
|
2682
2776
|
// Extract parts from candidates
|
|
2683
2777
|
const parts = chunk.candidates?.[0]?.content?.parts;
|
|
2684
2778
|
if (parts && Array.isArray(parts)) {
|
|
@@ -2764,11 +2858,13 @@ export class APIClient {
|
|
|
2764
2858
|
if (streamingError) {
|
|
2765
2859
|
throw streamingError;
|
|
2766
2860
|
}
|
|
2861
|
+
if (streamCache.plan)
|
|
2862
|
+
this.geminiCache.recordUsage(streamCache.plan, lastChunkUsage);
|
|
2767
2863
|
// Return final response structure matching Google SDK format
|
|
2768
2864
|
return {
|
|
2769
2865
|
text: () => fullText,
|
|
2770
2866
|
candidates: lastCandidate ? [lastCandidate] : [],
|
|
2771
|
-
usageMetadata: lastCandidate?.usageMetadata
|
|
2867
|
+
usageMetadata: lastCandidate?.usageMetadata ?? (geminiCacheOn ? lastChunkUsage : undefined)
|
|
2772
2868
|
};
|
|
2773
2869
|
})();
|
|
2774
2870
|
return {
|
|
@@ -2862,12 +2958,22 @@ export class APIClient {
|
|
|
2862
2958
|
Object.assign(config, generationConfig);
|
|
2863
2959
|
}
|
|
2864
2960
|
// CRITICAL: thinkingConfig and tools CANNOT coexist
|
|
2961
|
+
// (DARK CORTEX_GEMINI_TOOLS_THINKING: a Gemini 2.0-era observation — on, thinking is sent WITH tools.)
|
|
2865
2962
|
const hasTools = request.tools && request.tools.length > 0;
|
|
2963
|
+
const geminiToolsThinking = isGeminiToolsThinkingEnabled();
|
|
2866
2964
|
if (_modelConfig.reasoning?.supported && _modelConfig.reasoning?.pattern === 'interleaved' && !disableThinking && !hasTools) {
|
|
2867
|
-
config.thinkingConfig =
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2965
|
+
config.thinkingConfig = geminiToolsThinking && config.thinkingConfig
|
|
2966
|
+
// effort-mapped thinkingLevel/thinkingBudget from the gateway; keep the thought summaries this path always asked for
|
|
2967
|
+
? { includeThoughts: true, ...config.thinkingConfig }
|
|
2968
|
+
: {
|
|
2969
|
+
includeThoughts: true,
|
|
2970
|
+
thinkingBudget: 10000
|
|
2971
|
+
};
|
|
2972
|
+
}
|
|
2973
|
+
else if (_modelConfig.reasoning?.supported && _modelConfig.reasoning?.pattern === 'interleaved' && !disableThinking && hasTools && geminiToolsThinking) {
|
|
2974
|
+
// Non-streaming: no includeThoughts — this response is converted by the message-level adapter, which would turn
|
|
2975
|
+
// thought-summary parts into visible text. Effort-mapped config from the gateway, else the no-tools default budget.
|
|
2976
|
+
config.thinkingConfig = config.thinkingConfig ?? { thinkingBudget: 10000 };
|
|
2871
2977
|
}
|
|
2872
2978
|
// Add tools to config if present
|
|
2873
2979
|
if (hasTools && request.tools) {
|
|
@@ -2898,6 +3004,24 @@ export class APIClient {
|
|
|
2898
3004
|
if (process.env.DEBUG === 'true') {
|
|
2899
3005
|
console.log(`[DEBUG APIClient SDK] Non-streaming request for model: ${modelId}`);
|
|
2900
3006
|
}
|
|
3007
|
+
// HB-GEMINI-EXPLICIT-CACHE (DARK, CORTEX_GEMINI_EXPLICIT_CACHE): off → the original single call, unchanged.
|
|
3008
|
+
if (isGeminiExplicitCacheEnabled()) {
|
|
3009
|
+
const cacheCtx = { sessionId: request.conversationId, modelId, apiKey: process.env['GEMINI_API_KEY'] ?? '' };
|
|
3010
|
+
const cached = await this.geminiCache.prepare(cacheCtx, 'sdk', sdkRequest);
|
|
3011
|
+
if (cached) {
|
|
3012
|
+
try {
|
|
3013
|
+
const r = await this.googleGenAIClient.models.generateContent(cached.body);
|
|
3014
|
+
this.geminiCache.recordUsage(cached.plan, r?.usageMetadata);
|
|
3015
|
+
return { data: r, status: 200, headers: {} };
|
|
3016
|
+
}
|
|
3017
|
+
catch (e) {
|
|
3018
|
+
if (!isCacheUseFailure(e?.status))
|
|
3019
|
+
throw e;
|
|
3020
|
+
this.geminiCache.invalidate(cached.plan, `use_${e.status} ${String(e?.message ?? '').slice(0, 160)}`, cacheCtx);
|
|
3021
|
+
// fall through: the normal full request, once
|
|
3022
|
+
}
|
|
3023
|
+
}
|
|
3024
|
+
}
|
|
2901
3025
|
const response = await this.googleGenAIClient.models.generateContent(sdkRequest);
|
|
2902
3026
|
return {
|
|
2903
3027
|
data: response,
|
|
@@ -2954,16 +3078,24 @@ export class APIClient {
|
|
|
2954
3078
|
// Following Claude/Grok pattern: Skip if disableThinking flag is set (used for continuation requests)
|
|
2955
3079
|
// CRITICAL: thinkingConfig and tools CANNOT coexist — Google API returns empty responses when both present
|
|
2956
3080
|
const hasTools = request.tools && request.tools.length > 0;
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
// -
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
3081
|
+
// DARK (CORTEX_GEMINI_TOOLS_THINKING): on, thinking is sent WITH tools (effort-mapped by the gateway).
|
|
3082
|
+
const geminiToolsThinking = isGeminiToolsThinkingEnabled();
|
|
3083
|
+
if (_modelConfig.reasoning?.supported && _modelConfig.reasoning?.pattern === 'interleaved' && !disableThinking && (!hasTools || geminiToolsThinking)) {
|
|
3084
|
+
if (geminiToolsThinking && config.thinkingConfig) {
|
|
3085
|
+
// effort-mapped thinkingLevel/thinkingBudget from the gateway (+ thought summaries; the stream parser filters part.thought)
|
|
3086
|
+
config.thinkingConfig = { includeThoughts: true, ...config.thinkingConfig };
|
|
3087
|
+
}
|
|
3088
|
+
else {
|
|
3089
|
+
config.thinkingConfig = {
|
|
3090
|
+
includeThoughts: true, // Enable thought summaries in response
|
|
3091
|
+
// Gemini 2.5 Flash supports thinkingBudget (0-24576)
|
|
3092
|
+
// -1 = dynamic (model decides), or set explicit budget like Claude's 10000
|
|
3093
|
+
// Set to 10000 tokens to encourage verbose reasoning like Claude
|
|
3094
|
+
thinkingBudget: 10000
|
|
3095
|
+
};
|
|
3096
|
+
}
|
|
2965
3097
|
if (process.env.DEBUG === 'true') {
|
|
2966
|
-
console.log(`[DEBUG APIClient SDK] Extended thinking enabled for ${modelId}
|
|
3098
|
+
console.log(`[DEBUG APIClient SDK] Extended thinking enabled for ${modelId}: ${JSON.stringify(config.thinkingConfig)}`);
|
|
2967
3099
|
}
|
|
2968
3100
|
}
|
|
2969
3101
|
else if (hasTools && process.env.DEBUG === 'true') {
|
|
@@ -3015,10 +3147,32 @@ export class APIClient {
|
|
|
3015
3147
|
const streamCompletePromise = new Promise((resolve) => {
|
|
3016
3148
|
resolveComplete = resolve;
|
|
3017
3149
|
});
|
|
3150
|
+
// HB-GEMINI-EXPLICIT-CACHE (DARK, CORTEX_GEMINI_EXPLICIT_CACHE): off → the original single call, unchanged.
|
|
3151
|
+
const sdkCacheOn = isGeminiExplicitCacheEnabled();
|
|
3152
|
+
const sdkStream = {};
|
|
3153
|
+
const openSdkStream = async (client) => {
|
|
3154
|
+
if (!sdkCacheOn)
|
|
3155
|
+
return client.models.generateContentStream(sdkRequest);
|
|
3156
|
+
const cacheCtx = { sessionId: request.conversationId, modelId, apiKey: process.env['GEMINI_API_KEY'] ?? '' };
|
|
3157
|
+
const cached = await this.geminiCache.prepare(cacheCtx, 'sdk', sdkRequest);
|
|
3158
|
+
if (cached) {
|
|
3159
|
+
try {
|
|
3160
|
+
const s = await client.models.generateContentStream(cached.body);
|
|
3161
|
+
sdkStream.plan = cached.plan;
|
|
3162
|
+
return s;
|
|
3163
|
+
}
|
|
3164
|
+
catch (e) {
|
|
3165
|
+
if (!isCacheUseFailure(e?.status))
|
|
3166
|
+
throw e;
|
|
3167
|
+
this.geminiCache.invalidate(cached.plan, `use_${e.status} ${String(e?.message ?? '').slice(0, 160)}`, cacheCtx);
|
|
3168
|
+
}
|
|
3169
|
+
}
|
|
3170
|
+
return client.models.generateContentStream(sdkRequest); // the normal full request (once, on a cache failure)
|
|
3171
|
+
};
|
|
3018
3172
|
const chunks = async function* (client) {
|
|
3019
3173
|
try {
|
|
3020
3174
|
// Stream using new SDK (SINGLE API call)
|
|
3021
|
-
const stream = await client
|
|
3175
|
+
const stream = await openSdkStream(client);
|
|
3022
3176
|
if (process.env.DEBUG === 'true') {
|
|
3023
3177
|
console.log(`[DEBUG APIClient SDK] Stream started for model: ${modelId}`);
|
|
3024
3178
|
}
|
|
@@ -3176,6 +3330,8 @@ export class APIClient {
|
|
|
3176
3330
|
const finalMessage = (async () => {
|
|
3177
3331
|
// Wait for chunks generator to complete
|
|
3178
3332
|
await streamCompletePromise;
|
|
3333
|
+
if (sdkStream.plan)
|
|
3334
|
+
this.geminiCache.recordUsage(sdkStream.plan, lastChunk?.usageMetadata);
|
|
3179
3335
|
// Return final response structure matching Google SDK format
|
|
3180
3336
|
// This matches the structure expected by the orchestrator
|
|
3181
3337
|
return {
|