@genesislcap/ai-assistant 15.96.1 → 15.96.2-GENC-1665.5
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/chat-driver.cjs +191 -36
- package/dist/chat-driver.cjs.map +3 -3
- package/dist/chat-driver.mjs +189 -36
- package/dist/chat-driver.mjs.map +3 -3
- package/dist/custom-elements.json +16 -0
- package/dist/dts/chat-driver-node.d.ts +1 -1
- package/dist/dts/chat-driver-node.d.ts.map +1 -1
- package/dist/esm/chat-driver-node.js +1 -1
- package/package.json +17 -17
package/dist/chat-driver.cjs
CHANGED
|
@@ -27,6 +27,7 @@ __export(chat_driver_node_exports, {
|
|
|
27
27
|
ANTHROPIC_CACHE_READ_MULTIPLIER: () => ANTHROPIC_CACHE_READ_MULTIPLIER,
|
|
28
28
|
ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER: () => ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER,
|
|
29
29
|
ANTHROPIC_CACHE_WRITE_5M_MULTIPLIER: () => ANTHROPIC_CACHE_WRITE_5M_MULTIPLIER,
|
|
30
|
+
ANTHROPIC_LONG_CONTEXT_THRESHOLD: () => ANTHROPIC_LONG_CONTEXT_THRESHOLD,
|
|
30
31
|
AgenticActivityBus: () => AgenticActivityBus,
|
|
31
32
|
AnthropicProvider: () => AnthropicProvider,
|
|
32
33
|
AnthropicTransport: () => AnthropicTransport,
|
|
@@ -60,6 +61,7 @@ __export(chat_driver_node_exports, {
|
|
|
60
61
|
agenticActivityBus: () => agenticActivityBus,
|
|
61
62
|
aiServiceAccessRefusalOf: () => aiServiceAccessRefusalOf,
|
|
62
63
|
aiServiceErrorCodeOf: () => aiServiceErrorCodeOf,
|
|
64
|
+
anthropicCacheReadMultiplierFor: () => anthropicCacheReadMultiplierFor,
|
|
63
65
|
anthropicRatesFor: () => anthropicRatesFor,
|
|
64
66
|
anthropicTokenCost: () => anthropicTokenCost,
|
|
65
67
|
assembleDebugLog: () => assembleDebugLog,
|
|
@@ -1315,10 +1317,13 @@ var SUPPORTED_GEMINI_MODEL_IDS = [
|
|
|
1315
1317
|
];
|
|
1316
1318
|
var SUPPORTED_ANTHROPIC_MODEL_IDS = [
|
|
1317
1319
|
"claude-fable-5",
|
|
1320
|
+
"claude-opus-5-5",
|
|
1318
1321
|
"claude-opus-4-8",
|
|
1319
1322
|
"claude-opus-4-7",
|
|
1323
|
+
"claude-sonnet-5-5",
|
|
1320
1324
|
"claude-sonnet-5",
|
|
1321
1325
|
"claude-sonnet-4-6",
|
|
1326
|
+
"claude-haiku-5-5",
|
|
1322
1327
|
"claude-haiku-4-5-20251001"
|
|
1323
1328
|
];
|
|
1324
1329
|
var SUPPORTED_OPENAI_MODEL_IDS = [
|
|
@@ -1355,14 +1360,40 @@ function scaleTemperature(normalized, { defaultTemp, maxTemp }) {
|
|
|
1355
1360
|
|
|
1356
1361
|
// ../../foundation-ai/dist/esm/utils/token-cost.js
|
|
1357
1362
|
var TOKENS_PER_MILLION = 1e6;
|
|
1363
|
+
var ANTHROPIC_LONG_CONTEXT_THRESHOLD = 1e5;
|
|
1358
1364
|
var ANTHROPIC_PRICING = {
|
|
1359
|
-
"claude-haiku-4-5-20251001": {
|
|
1365
|
+
"claude-haiku-4-5-20251001": {
|
|
1366
|
+
kind: "flat",
|
|
1367
|
+
rate: { promptPerMillion: 1, candidatePerMillion: 5 }
|
|
1368
|
+
},
|
|
1369
|
+
// Haiku 5.5 has two rate cards chosen by prompt length; cache reads are 0.1× the input rate of
|
|
1370
|
+
// whichever card applies, like every other model here.
|
|
1371
|
+
"claude-haiku-5-5": {
|
|
1372
|
+
kind: "tiered",
|
|
1373
|
+
standard: { promptPerMillion: 0.1, candidatePerMillion: 0.5 },
|
|
1374
|
+
longContext: { promptPerMillion: 0.5, candidatePerMillion: 2.5 }
|
|
1375
|
+
},
|
|
1360
1376
|
// Fable 5 — Anthropic's most capable widely-released model; priced above Opus tier.
|
|
1361
|
-
"claude-fable-5": { promptPerMillion: 10, candidatePerMillion: 50 },
|
|
1377
|
+
"claude-fable-5": { kind: "flat", rate: { promptPerMillion: 10, candidatePerMillion: 50 } },
|
|
1378
|
+
// Opus 5.5 — $4 / $20, cheaper than Opus 4.8. Its cache reads are $0.20 / MTok, i.e. 0.05× the
|
|
1379
|
+
// input rate (as on Sonnet 5.5), NOT the 0.1× every older model reads at: the global
|
|
1380
|
+
// multiplier would bill its cache reads at double.
|
|
1381
|
+
"claude-opus-5-5": {
|
|
1382
|
+
kind: "flat",
|
|
1383
|
+
rate: { promptPerMillion: 4, candidatePerMillion: 20 },
|
|
1384
|
+
cacheReadMultiplier: 0.05
|
|
1385
|
+
},
|
|
1362
1386
|
// Opus 4.7 / 4.8 — same $5 / $25 per MTok. Stated per model rather than shared through a
|
|
1363
1387
|
// fall-through, so neither is ever "whatever was left over".
|
|
1364
|
-
"claude-opus-4-8": { promptPerMillion: 5, candidatePerMillion: 25 },
|
|
1365
|
-
"claude-opus-4-7": { promptPerMillion: 5, candidatePerMillion: 25 },
|
|
1388
|
+
"claude-opus-4-8": { kind: "flat", rate: { promptPerMillion: 5, candidatePerMillion: 25 } },
|
|
1389
|
+
"claude-opus-4-7": { kind: "flat", rate: { promptPerMillion: 5, candidatePerMillion: 25 } },
|
|
1390
|
+
// Sonnet 5.5 — same $2 / $10 as Sonnet 5, but its cache reads are $0.10 / MTok (0.05×, like
|
|
1391
|
+
// Opus 5.5), half of Sonnet 5's $0.20.
|
|
1392
|
+
"claude-sonnet-5-5": {
|
|
1393
|
+
kind: "flat",
|
|
1394
|
+
rate: { promptPerMillion: 2, candidatePerMillion: 10 },
|
|
1395
|
+
cacheReadMultiplier: 0.05
|
|
1396
|
+
},
|
|
1366
1397
|
// Sonnet 5 is $2 / $10 — its OWN tier, and CHEAPER than the older Sonnet 4.6 below.
|
|
1367
1398
|
//
|
|
1368
1399
|
// This launched as an introductory rate through 2026-08-31, and an earlier version of this
|
|
@@ -1371,22 +1402,32 @@ var ANTHROPIC_PRICING = {
|
|
|
1371
1402
|
// standard price and cancelled the scheduled increase, so that reasoning is dead and the old
|
|
1372
1403
|
// figure over-charged every Sonnet 5 request by 50%.
|
|
1373
1404
|
// https://platform.claude.com/docs/en/about-claude/pricing#model-pricing
|
|
1374
|
-
"claude-sonnet-5": { promptPerMillion: 2, candidatePerMillion: 10 },
|
|
1405
|
+
"claude-sonnet-5": { kind: "flat", rate: { promptPerMillion: 2, candidatePerMillion: 10 } },
|
|
1375
1406
|
// Sonnet 4.6 remains on the older $3 / $15 Sonnet tier — the newer model is the cheaper one.
|
|
1376
|
-
"claude-sonnet-4-6": { promptPerMillion: 3, candidatePerMillion: 15 }
|
|
1407
|
+
"claude-sonnet-4-6": { kind: "flat", rate: { promptPerMillion: 3, candidatePerMillion: 15 } }
|
|
1377
1408
|
};
|
|
1378
|
-
function anthropicRatesFor(model) {
|
|
1379
|
-
|
|
1409
|
+
function anthropicRatesFor(model, promptTokens = 0) {
|
|
1410
|
+
const pricing = ANTHROPIC_PRICING[model];
|
|
1411
|
+
if (pricing.kind === "flat") {
|
|
1412
|
+
return pricing.rate;
|
|
1413
|
+
}
|
|
1414
|
+
return promptTokens > ANTHROPIC_LONG_CONTEXT_THRESHOLD ? pricing.longContext : pricing.standard;
|
|
1380
1415
|
}
|
|
1381
1416
|
var ANTHROPIC_CACHE_READ_MULTIPLIER = 0.1;
|
|
1417
|
+
function anthropicCacheReadMultiplierFor(model) {
|
|
1418
|
+
var _a;
|
|
1419
|
+
return (_a = ANTHROPIC_PRICING[model].cacheReadMultiplier) !== null && _a !== void 0 ? _a : ANTHROPIC_CACHE_READ_MULTIPLIER;
|
|
1420
|
+
}
|
|
1382
1421
|
var ANTHROPIC_CACHE_WRITE_5M_MULTIPLIER = 1.25;
|
|
1383
1422
|
var ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER = 2;
|
|
1384
1423
|
function anthropicTokenCost(model, usage) {
|
|
1385
|
-
const
|
|
1424
|
+
const promptTokens = usage.uncachedInputTokens + usage.cacheReadTokens + usage.cacheWriteTokens;
|
|
1425
|
+
const { promptPerMillion, candidatePerMillion } = anthropicRatesFor(model, promptTokens);
|
|
1426
|
+
const cacheReadMultiplier = anthropicCacheReadMultiplierFor(model);
|
|
1386
1427
|
const m = TOKENS_PER_MILLION;
|
|
1387
1428
|
const cacheWrite5mTokens = Math.max(0, usage.cacheWriteTokens - usage.cacheWrite1hTokens);
|
|
1388
1429
|
const promptCost = usage.uncachedInputTokens / m * promptPerMillion;
|
|
1389
|
-
const cacheReadCost = usage.cacheReadTokens / m * promptPerMillion *
|
|
1430
|
+
const cacheReadCost = usage.cacheReadTokens / m * promptPerMillion * cacheReadMultiplier;
|
|
1390
1431
|
const cacheWriteCost = cacheWrite5mTokens / m * promptPerMillion * ANTHROPIC_CACHE_WRITE_5M_MULTIPLIER + usage.cacheWrite1hTokens / m * promptPerMillion * ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER;
|
|
1391
1432
|
const candidateCost = usage.outputTokens / m * candidatePerMillion;
|
|
1392
1433
|
const cacheReadFull = usage.cacheReadTokens / m * promptPerMillion;
|
|
@@ -2381,6 +2422,7 @@ var DEFAULT_MODEL = "claude-haiku-4-5-20251001";
|
|
|
2381
2422
|
var DEFAULT_TIMEOUT = 3e5;
|
|
2382
2423
|
var DEFAULT_STALL_TIMEOUT = 3e4;
|
|
2383
2424
|
var DEFAULT_MAX_TOKENS = 4096;
|
|
2425
|
+
var CLAUDE_55_DEFAULT_MAX_TOKENS = 64e3;
|
|
2384
2426
|
var ANTHROPIC_DEFAULT_TEMPERATURE = 1;
|
|
2385
2427
|
var ANTHROPIC_MAX_TEMPERATURE = 1;
|
|
2386
2428
|
function toAnthropicToolChoice(choice) {
|
|
@@ -2394,38 +2436,60 @@ function toAnthropicToolChoice(choice) {
|
|
|
2394
2436
|
}
|
|
2395
2437
|
var ANTHROPIC_CONTEXT_LIMITS = {
|
|
2396
2438
|
"claude-fable-5": 1e6,
|
|
2439
|
+
"claude-opus-5-5": 1e6,
|
|
2397
2440
|
"claude-opus-4-8": 1e6,
|
|
2398
2441
|
"claude-opus-4-7": 1e6,
|
|
2442
|
+
"claude-sonnet-5-5": 1e6,
|
|
2399
2443
|
"claude-sonnet-5": 1e6,
|
|
2400
2444
|
"claude-sonnet-4-6": 1e6,
|
|
2445
|
+
"claude-haiku-5-5": 1e6,
|
|
2401
2446
|
"claude-haiku-4-5-20251001": 2e5
|
|
2402
2447
|
};
|
|
2403
2448
|
var STRUCTURED_OUTPUT_TOOL_NAME = "emit_structured_response";
|
|
2404
2449
|
var SERVER_SIDE_FALLBACK_BETA = "server-side-fallback-2026-06-01";
|
|
2450
|
+
var THINKING_BINDING_CONTROLS_BETA = "thinking-binding-controls-2026-08-01";
|
|
2405
2451
|
function assertSupportedAnthropicModel(model) {
|
|
2406
2452
|
if (!SUPPORTED_ANTHROPIC_MODEL_IDS.includes(model)) {
|
|
2407
2453
|
throw new Error(`AnthropicTransport: unsupported model "${model}". Use one of: ${SUPPORTED_ANTHROPIC_MODEL_IDS.join(", ")}.`);
|
|
2408
2454
|
}
|
|
2409
2455
|
}
|
|
2456
|
+
function isClaude55(model) {
|
|
2457
|
+
return model === "claude-opus-5-5" || model === "claude-sonnet-5-5" || model === "claude-haiku-5-5";
|
|
2458
|
+
}
|
|
2410
2459
|
function rejectsSamplingParams(model) {
|
|
2411
|
-
return model === "claude-fable-5" || model === "claude-opus-4-8" || model === "claude-opus-4-7" || model === "claude-sonnet-5";
|
|
2460
|
+
return model === "claude-fable-5" || model === "claude-opus-4-8" || model === "claude-opus-4-7" || model === "claude-sonnet-5" || isClaude55(model);
|
|
2461
|
+
}
|
|
2462
|
+
function supportsForcedToolChoice(model) {
|
|
2463
|
+
return model !== "claude-opus-5-5" && model !== "claude-sonnet-5-5";
|
|
2412
2464
|
}
|
|
2413
2465
|
function supportsNativeStructuredOutput(model) {
|
|
2414
|
-
return model === "claude-fable-5" || model === "claude-opus-4-8" || model === "claude-sonnet-5" || model === "claude-haiku-4-5-20251001";
|
|
2466
|
+
return model === "claude-fable-5" || model === "claude-opus-4-8" || model === "claude-sonnet-5" || model === "claude-haiku-4-5-20251001" || isClaude55(model);
|
|
2415
2467
|
}
|
|
2416
2468
|
function supportsAdaptiveThinking(model) {
|
|
2417
2469
|
return model !== "claude-haiku-4-5-20251001";
|
|
2418
2470
|
}
|
|
2419
2471
|
function thinkingIsMandatory(model) {
|
|
2420
|
-
return model === "claude-fable-5";
|
|
2472
|
+
return model === "claude-fable-5" || model === "claude-opus-5-5";
|
|
2473
|
+
}
|
|
2474
|
+
function defaultsToThinking(model) {
|
|
2475
|
+
return model === "claude-sonnet-5" || model === "claude-sonnet-5-5" || model === "claude-haiku-5-5" || thinkingIsMandatory(model);
|
|
2476
|
+
}
|
|
2477
|
+
function thinkingOff(model) {
|
|
2478
|
+
return model === "claude-sonnet-5-5" ? { type: "between_tools" } : { type: "disabled" };
|
|
2479
|
+
}
|
|
2480
|
+
var POLICY_EFFORT = {
|
|
2481
|
+
"claude-opus-5-5": { off: "low" }
|
|
2482
|
+
};
|
|
2483
|
+
function sendsBlockBinding(model) {
|
|
2484
|
+
return isClaude55(model);
|
|
2421
2485
|
}
|
|
2422
2486
|
function anthropicThinking(model, policy) {
|
|
2423
|
-
const
|
|
2487
|
+
const thinksByDefault = defaultsToThinking(model);
|
|
2424
2488
|
const adaptive = { type: "adaptive", display: "summarized" };
|
|
2425
2489
|
if (policy === "off") {
|
|
2426
2490
|
if (thinkingIsMandatory(model))
|
|
2427
2491
|
return adaptive;
|
|
2428
|
-
return
|
|
2492
|
+
return thinksByDefault ? thinkingOff(model) : void 0;
|
|
2429
2493
|
}
|
|
2430
2494
|
if (policy === "auto") {
|
|
2431
2495
|
return supportsAdaptiveThinking(model) ? adaptive : void 0;
|
|
@@ -2433,10 +2497,10 @@ function anthropicThinking(model, policy) {
|
|
|
2433
2497
|
if (policy !== void 0) {
|
|
2434
2498
|
return supportsAdaptiveThinking(model) ? adaptive : void 0;
|
|
2435
2499
|
}
|
|
2436
|
-
return
|
|
2500
|
+
return thinksByDefault ? adaptive : void 0;
|
|
2437
2501
|
}
|
|
2438
2502
|
function supportsEffort(model) {
|
|
2439
|
-
return model === "claude-fable-5" || model === "claude-opus-4-8" || model === "claude-sonnet-5";
|
|
2503
|
+
return model === "claude-fable-5" || model === "claude-opus-4-8" || model === "claude-sonnet-5" || isClaude55(model);
|
|
2440
2504
|
}
|
|
2441
2505
|
var ANTHROPIC_EFFORT = {
|
|
2442
2506
|
minimal: "low",
|
|
@@ -2446,8 +2510,11 @@ var ANTHROPIC_EFFORT = {
|
|
|
2446
2510
|
max: "max"
|
|
2447
2511
|
};
|
|
2448
2512
|
function anthropicEffort(model, policy) {
|
|
2449
|
-
|
|
2513
|
+
var _a;
|
|
2514
|
+
if (policy === void 0)
|
|
2450
2515
|
return void 0;
|
|
2516
|
+
if (policy === "auto" || policy === "off")
|
|
2517
|
+
return (_a = POLICY_EFFORT[model]) === null || _a === void 0 ? void 0 : _a[policy];
|
|
2451
2518
|
if (!supportsEffort(model) || !supportsAdaptiveThinking(model))
|
|
2452
2519
|
return void 0;
|
|
2453
2520
|
return ANTHROPIC_EFFORT[policy];
|
|
@@ -2491,11 +2558,14 @@ var AnthropicTransport = class _AnthropicTransport {
|
|
|
2491
2558
|
* outcome the type's own docs promise callers never happens.
|
|
2492
2559
|
*/
|
|
2493
2560
|
clampWarning(policy) {
|
|
2561
|
+
var _a, _b;
|
|
2494
2562
|
switch (policy) {
|
|
2495
2563
|
case void 0:
|
|
2496
2564
|
return void 0;
|
|
2497
2565
|
case "off":
|
|
2498
|
-
|
|
2566
|
+
if (!thinkingIsMandatory(this.model))
|
|
2567
|
+
return void 0;
|
|
2568
|
+
return ((_a = POLICY_EFFORT[this.model]) === null || _a === void 0 ? void 0 : _a.off) ? `AnthropicTransport: thinkingPolicy 'off' approximated \u2014 ${this.model} always thinks and rejects an explicit disable, so the turn runs at effort '${(_b = POLICY_EFFORT[this.model]) === null || _b === void 0 ? void 0 : _b.off}' instead. It may still think a little, billed as output.` : `AnthropicTransport: thinkingPolicy 'off' ignored \u2014 ${this.model} always thinks and rejects an explicit disable. Reasoning tokens are still billed as output; switch model if you need them gone.`;
|
|
2499
2569
|
case "auto":
|
|
2500
2570
|
return supportsAdaptiveThinking(this.model) ? void 0 : `AnthropicTransport: thinkingPolicy 'auto' ignored \u2014 ${this.model} does not support adaptive thinking, so this turn runs without reasoning. Use a Sonnet or Opus tier if the agent needs it.`;
|
|
2501
2571
|
case "minimal":
|
|
@@ -2504,7 +2574,7 @@ var AnthropicTransport = class _AnthropicTransport {
|
|
|
2504
2574
|
case "high":
|
|
2505
2575
|
case "max":
|
|
2506
2576
|
if (!supportsAdaptiveThinking(this.model) || !supportsEffort(this.model)) {
|
|
2507
|
-
return `AnthropicTransport: thinkingPolicy '${policy}' ignored \u2014 ${this.model} predates output_config.effort, so this turn runs at its default posture. Use Opus 4.8, Sonnet 5, or Fable 5 to set reasoning depth.`;
|
|
2577
|
+
return `AnthropicTransport: thinkingPolicy '${policy}' ignored \u2014 ${this.model} predates output_config.effort, so this turn runs at its default posture. Use Opus 4.8 or later, Sonnet 5 or later, Haiku 5.5, or Fable 5 to set reasoning depth.`;
|
|
2508
2578
|
}
|
|
2509
2579
|
return void 0;
|
|
2510
2580
|
default: {
|
|
@@ -2514,10 +2584,11 @@ var AnthropicTransport = class _AnthropicTransport {
|
|
|
2514
2584
|
}
|
|
2515
2585
|
}
|
|
2516
2586
|
constructor(config = {}) {
|
|
2517
|
-
var _a, _b, _c, _d;
|
|
2587
|
+
var _a, _b, _c, _d, _e;
|
|
2518
2588
|
this.lifetimeCostUsd = 0;
|
|
2519
2589
|
this.lifetimeSavingsUsd = 0;
|
|
2520
2590
|
this.warnedThinkingClamped = false;
|
|
2591
|
+
this.warnedToolChoiceDowngraded = false;
|
|
2521
2592
|
this.warnedUnknownServingModels = /* @__PURE__ */ new Set();
|
|
2522
2593
|
const model = (_a = config.model) !== null && _a !== void 0 ? _a : DEFAULT_MODEL;
|
|
2523
2594
|
assertSupportedAnthropicModel(model);
|
|
@@ -2528,6 +2599,10 @@ var AnthropicTransport = class _AnthropicTransport {
|
|
|
2528
2599
|
logger.warn("AnthropicTransport: using claude-sonnet-4-6 \u2014 higher cost than Haiku; use for stronger reasoning or agent tasks.");
|
|
2529
2600
|
} else if (model === "claude-opus-4-7" || model === "claude-opus-4-8") {
|
|
2530
2601
|
logger.warn(`AnthropicTransport: using ${model} \u2014 significantly higher cost; reserve for tasks where Sonnet reliability is insufficient.`);
|
|
2602
|
+
} else if (model === "claude-opus-5-5") {
|
|
2603
|
+
logger.warn("AnthropicTransport: using claude-opus-5-5 \u2014 Opus tier ($4 / $20 per MTok) with thinking always on (effort defaults to medium). Reserve for tasks where Sonnet reliability is insufficient.");
|
|
2604
|
+
} else if (model === "claude-sonnet-5-5") {
|
|
2605
|
+
logger.warn("AnthropicTransport: using claude-sonnet-5-5 \u2014 standard Sonnet tier ($2 / $10 per MTok), higher cost than Haiku, and adaptive thinking runs by default so reasoning tokens add to output cost. Use for stronger reasoning or agent tasks.");
|
|
2531
2606
|
} else if (model === "claude-fable-5") {
|
|
2532
2607
|
logger.warn(`AnthropicTransport: using claude-fable-5 \u2014 Anthropic's most capable model, priced above Opus tier ($10 / $50 per MTok) with thinking always on. Reserve for the hardest reasoning/long-horizon work. Requires \u226530-day data retention (unavailable under ZDR) and may return stop_reason "refusal"; pair with an Opus 4.8 fallback.`);
|
|
2533
2608
|
}
|
|
@@ -2535,7 +2610,8 @@ var AnthropicTransport = class _AnthropicTransport {
|
|
|
2535
2610
|
this.stallTimeout = (_c = config.stallTimeout) !== null && _c !== void 0 ? _c : DEFAULT_STALL_TIMEOUT;
|
|
2536
2611
|
this.apiKey = config.apiKey;
|
|
2537
2612
|
this.serverEndpoint = config.serverEndpoint;
|
|
2538
|
-
this.maxTokens = (_d = config.maxTokens) !== null && _d !== void 0 ? _d : DEFAULT_MAX_TOKENS;
|
|
2613
|
+
this.maxTokens = (_d = config.maxTokens) !== null && _d !== void 0 ? _d : isClaude55(model) ? CLAUDE_55_DEFAULT_MAX_TOKENS : DEFAULT_MAX_TOKENS;
|
|
2614
|
+
this.thinkingBlockBinding = (_e = config.thinkingBlockBinding) !== null && _e !== void 0 ? _e : "drop_block";
|
|
2539
2615
|
}
|
|
2540
2616
|
getConfig() {
|
|
2541
2617
|
return {
|
|
@@ -2575,6 +2651,9 @@ var AnthropicTransport = class _AnthropicTransport {
|
|
|
2575
2651
|
if (useNative) {
|
|
2576
2652
|
body.output_config = Object.assign(Object.assign({}, body.output_config), { format: { type: "json_schema", schema: responseSchema } });
|
|
2577
2653
|
} else if (useForcedTool) {
|
|
2654
|
+
if (!supportsForcedToolChoice(this.model)) {
|
|
2655
|
+
throw new Error(`AnthropicTransport: ${this.model} rejects forced tool_choice and must be listed in supportsNativeStructuredOutput.`);
|
|
2656
|
+
}
|
|
2578
2657
|
body.tools = [
|
|
2579
2658
|
{
|
|
2580
2659
|
name: STRUCTURED_OUTPUT_TOOL_NAME,
|
|
@@ -2584,8 +2663,9 @@ var AnthropicTransport = class _AnthropicTransport {
|
|
|
2584
2663
|
];
|
|
2585
2664
|
body.tool_choice = { type: "tool", name: STRUCTURED_OUTPUT_TOOL_NAME };
|
|
2586
2665
|
}
|
|
2587
|
-
if (this.model
|
|
2588
|
-
body.thinking =
|
|
2666
|
+
if (defaultsToThinking(this.model) && !thinkingIsMandatory(this.model)) {
|
|
2667
|
+
body.thinking = thinkingOff(this.model);
|
|
2668
|
+
}
|
|
2589
2669
|
const response = yield this.post(body);
|
|
2590
2670
|
if (useForcedTool) {
|
|
2591
2671
|
const toolUse = ((_a = response.content) !== null && _a !== void 0 ? _a : []).find((b) => b.type === "tool_use" && b.name === STRUCTURED_OUTPUT_TOOL_NAME);
|
|
@@ -2614,15 +2694,11 @@ var AnthropicTransport = class _AnthropicTransport {
|
|
|
2614
2694
|
if ((_c = options === null || options === void 0 ? void 0 : options.tools) === null || _c === void 0 ? void 0 : _c.length) {
|
|
2615
2695
|
body.tools = options.tools.map((t) => Object.assign({ name: t.name, description: t.description, input_schema: t.enforceSchema ? enforceAnthropicToolSchema(t.parameters, t.name) : t.parameters }, t.enforceSchema ? { strict: true } : {}));
|
|
2616
2696
|
}
|
|
2617
|
-
|
|
2618
|
-
const toolChoice = toAnthropicToolChoice(options === null || options === void 0 ? void 0 : options.toolChoice);
|
|
2619
|
-
if (toolChoice)
|
|
2620
|
-
body.tool_choice = toolChoice;
|
|
2621
|
-
}
|
|
2697
|
+
const forcedToolNote = ((_d = body.tools) === null || _d === void 0 ? void 0 : _d.length) ? this.applyToolChoice(body, options === null || options === void 0 ? void 0 : options.toolChoice) : void 0;
|
|
2622
2698
|
this.warnIfThinkingUnclampable(options === null || options === void 0 ? void 0 : options.thinkingPolicy);
|
|
2623
2699
|
const thinking = anthropicThinking(this.model, options === null || options === void 0 ? void 0 : options.thinkingPolicy);
|
|
2624
2700
|
if (thinking)
|
|
2625
|
-
body.thinking = thinking;
|
|
2701
|
+
body.thinking = this.withBlockBinding(thinking);
|
|
2626
2702
|
const effort = anthropicEffort(this.model, options === null || options === void 0 ? void 0 : options.thinkingPolicy);
|
|
2627
2703
|
if (effort)
|
|
2628
2704
|
body.output_config = Object.assign(Object.assign({}, body.output_config), { effort });
|
|
@@ -2642,13 +2718,76 @@ var AnthropicTransport = class _AnthropicTransport {
|
|
|
2642
2718
|
if (options === null || options === void 0 ? void 0 : options.cachePolicy) {
|
|
2643
2719
|
this.applyCacheControl(body, options.cachePolicy);
|
|
2644
2720
|
}
|
|
2645
|
-
|
|
2646
|
-
|
|
2721
|
+
const tail = [options === null || options === void 0 ? void 0 : options.tailContext, forcedToolNote].filter(Boolean).join("\n\n");
|
|
2722
|
+
if (tail) {
|
|
2723
|
+
this.appendTailContext(body, tail);
|
|
2647
2724
|
}
|
|
2648
2725
|
const response = yield this.post(body, options === null || options === void 0 ? void 0 : options.signal);
|
|
2649
|
-
|
|
2726
|
+
const message = this.fromAnthropicResponse(response, body.max_tokens);
|
|
2727
|
+
if (forcedToolNote && message.responseMeta) {
|
|
2728
|
+
message.responseMeta.toolChoiceDowngraded = true;
|
|
2729
|
+
}
|
|
2730
|
+
return message;
|
|
2650
2731
|
});
|
|
2651
2732
|
}
|
|
2733
|
+
/**
|
|
2734
|
+
* Set `tool_choice` from the caller's {@link ChatToolChoice}. `'required'`/`{ tool }` force a
|
|
2735
|
+
* tool call so a turn can only end via one (e.g. a sub-agent's completion tool); on a model that
|
|
2736
|
+
* rejects forcing they are downgraded (see `downgradeForcedToolChoice`), and the instruction
|
|
2737
|
+
* that replaces them is returned for the tail.
|
|
2738
|
+
*/
|
|
2739
|
+
applyToolChoice(body, choice) {
|
|
2740
|
+
const toolChoice = toAnthropicToolChoice(choice);
|
|
2741
|
+
if (!toolChoice)
|
|
2742
|
+
return void 0;
|
|
2743
|
+
const forced = toolChoice.type === "any" || toolChoice.type === "tool";
|
|
2744
|
+
if (forced && !supportsForcedToolChoice(this.model)) {
|
|
2745
|
+
return this.downgradeForcedToolChoice(toolChoice);
|
|
2746
|
+
}
|
|
2747
|
+
body.tool_choice = toolChoice;
|
|
2748
|
+
return void 0;
|
|
2749
|
+
}
|
|
2750
|
+
/**
|
|
2751
|
+
* Preserved thinking (5.5 family): say what a changed history does to replayed thinking, rather
|
|
2752
|
+
* than inheriting the account default (a 400 on accounts created on or after 2026-08-31).
|
|
2753
|
+
* Adaptive only — `between_tools` and `disabled` reject the field — and a fresh object, so the
|
|
2754
|
+
* shared `adaptive` constant in `anthropicThinking` is never mutated.
|
|
2755
|
+
*/
|
|
2756
|
+
withBlockBinding(thinking) {
|
|
2757
|
+
if (thinking.type !== "adaptive" || !sendsBlockBinding(this.model) || this.thinkingBlockBinding === "omit") {
|
|
2758
|
+
return thinking;
|
|
2759
|
+
}
|
|
2760
|
+
return Object.assign(Object.assign({}, thinking), { block_binding: { prefix_mismatch_behavior: this.thinkingBlockBinding } });
|
|
2761
|
+
}
|
|
2762
|
+
/**
|
|
2763
|
+
* Stand-in for a forced tool call on a model that rejects `tool_choice` `any`/`tool` with a 400
|
|
2764
|
+
* (Opus 5.5, Sonnet 5.5). The request goes out with `tool_choice` omitted (`auto`), and an
|
|
2765
|
+
* instruction naming the tool is returned for the caller to append to the tail.
|
|
2766
|
+
*
|
|
2767
|
+
* **The tools array is left exactly as the caller built it.** It renders first in the prompt, so
|
|
2768
|
+
* it heads both the prompt-cache prefix and the prefix preserved thinking is bound to. Rewriting
|
|
2769
|
+
* a tool only on forced turns (making it `strict`, say) would change those bytes every time an
|
|
2770
|
+
* agent moves between forced and `auto` turns: a cache miss, every replayed thinking block
|
|
2771
|
+
* dropped (or a 400 under `block_binding: 'error'`), and a tool that accepts different arguments
|
|
2772
|
+
* depending on the turn. Whether a tool's arguments are enforced is the caller's decision, made
|
|
2773
|
+
* once per tool with `enforceSchema`, and holds on every turn; a completion tool that is forced
|
|
2774
|
+
* is a good candidate for it.
|
|
2775
|
+
*
|
|
2776
|
+
* `auto` lets the model answer in text instead, so the caller is told: a one-time warning here,
|
|
2777
|
+
* and `responseMeta.toolChoiceDowngraded` on every affected response. In the ChatDriver a
|
|
2778
|
+
* sub-agent that answers in text is held open by the finish-guard completion nudge; a parent
|
|
2779
|
+
* agent that relies on forcing should give itself a `finishGuard` that asks for the call.
|
|
2780
|
+
*/
|
|
2781
|
+
downgradeForcedToolChoice(toolChoice) {
|
|
2782
|
+
if (!this.warnedToolChoiceDowngraded) {
|
|
2783
|
+
this.warnedToolChoiceDowngraded = true;
|
|
2784
|
+
logger.warn(`AnthropicTransport: ${this.model} rejects a forced tool_choice; sending 'auto' with an instruction to call the tool instead. A reply may still come back without a tool call \u2014 check responseMeta.toolChoiceDowngraded.`);
|
|
2785
|
+
}
|
|
2786
|
+
if (toolChoice.type === "tool" && toolChoice.name) {
|
|
2787
|
+
return `<system-reminder>Respond to this turn by calling the \`${toolChoice.name}\` tool. Do not reply with text alone.</system-reminder>`;
|
|
2788
|
+
}
|
|
2789
|
+
return "<system-reminder>Respond to this turn by calling one of your tools. Do not reply with text alone.</system-reminder>";
|
|
2790
|
+
}
|
|
2652
2791
|
/**
|
|
2653
2792
|
* Place prompt-cache breakpoints on the outgoing request per the resolved {@link CachePolicy}.
|
|
2654
2793
|
* A breakpoint is `cache_control: {type:'ephemeral'}` on a content block / tool / system block;
|
|
@@ -2948,7 +3087,7 @@ ${att.content}` });
|
|
|
2948
3087
|
return this.logTokenUsage(model, (_e = usage.input_tokens) !== null && _e !== void 0 ? _e : 0, (_f = usage.output_tokens) !== null && _f !== void 0 ? _f : 0, cacheRead, cacheCreation, cacheCreation1h);
|
|
2949
3088
|
}
|
|
2950
3089
|
fromAnthropicResponse(response, effectiveMaxTokens = this.maxTokens) {
|
|
2951
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
3090
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
2952
3091
|
let inputTokens;
|
|
2953
3092
|
let outputTokens;
|
|
2954
3093
|
let cacheReadTokens;
|
|
@@ -3048,6 +3187,16 @@ ${att.content}` });
|
|
|
3048
3187
|
};
|
|
3049
3188
|
if (response.stop_reason)
|
|
3050
3189
|
responseMeta.finishReason = response.stop_reason;
|
|
3190
|
+
if ((_h = response.input_transformations) === null || _h === void 0 ? void 0 : _h.length) {
|
|
3191
|
+
responseMeta.inputTransformations = response.input_transformations.map((t) => Object.assign(Object.assign({ type: t.type }, t.path != null ? { path: t.path } : {}), t.reason != null ? { reason: t.reason } : {}));
|
|
3192
|
+
const dropped = response.input_transformations.filter((t) => t.type === "thinking_dropped");
|
|
3193
|
+
if (dropped.length) {
|
|
3194
|
+
logger.debug(`AnthropicTransport: ${dropped.length} thinking block(s) dropped by ${(_j = response.model) !== null && _j !== void 0 ? _j : this.model}: ${dropped.map((t) => {
|
|
3195
|
+
var _a2, _b2;
|
|
3196
|
+
return `${(_a2 = t.path) !== null && _a2 !== void 0 ? _a2 : "?"} (${(_b2 = t.reason) !== null && _b2 !== void 0 ? _b2 : "unknown"})`;
|
|
3197
|
+
}).join(", ")}`);
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3051
3200
|
base.responseMeta = responseMeta;
|
|
3052
3201
|
return base;
|
|
3053
3202
|
}
|
|
@@ -3079,9 +3228,13 @@ ${att.content}` });
|
|
|
3079
3228
|
}
|
|
3080
3229
|
post(body, signal) {
|
|
3081
3230
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3082
|
-
var _a;
|
|
3231
|
+
var _a, _b;
|
|
3083
3232
|
const { url, headers, credentials } = this.buildEndpoint();
|
|
3084
|
-
const
|
|
3233
|
+
const betas = [
|
|
3234
|
+
((_a = body.fallbacks) === null || _a === void 0 ? void 0 : _a.length) ? SERVER_SIDE_FALLBACK_BETA : void 0,
|
|
3235
|
+
((_b = body.thinking) === null || _b === void 0 ? void 0 : _b.type) === "adaptive" && body.thinking.block_binding ? THINKING_BINDING_CONTROLS_BETA : void 0
|
|
3236
|
+
].filter((b) => Boolean(b));
|
|
3237
|
+
const requestHeaders = betas.length ? Object.assign(Object.assign({}, headers), { "anthropic-beta": [headers["anthropic-beta"], ...betas].filter(Boolean).join(",") }) : headers;
|
|
3085
3238
|
return yield postWithRetry({
|
|
3086
3239
|
url,
|
|
3087
3240
|
headers: requestHeaders,
|
|
@@ -13850,6 +14003,7 @@ function collectRows(messages, depth, subAgentOf) {
|
|
|
13850
14003
|
ANTHROPIC_CACHE_READ_MULTIPLIER,
|
|
13851
14004
|
ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER,
|
|
13852
14005
|
ANTHROPIC_CACHE_WRITE_5M_MULTIPLIER,
|
|
14006
|
+
ANTHROPIC_LONG_CONTEXT_THRESHOLD,
|
|
13853
14007
|
AgenticActivityBus,
|
|
13854
14008
|
AnthropicProvider,
|
|
13855
14009
|
AnthropicTransport,
|
|
@@ -13883,6 +14037,7 @@ function collectRows(messages, depth, subAgentOf) {
|
|
|
13883
14037
|
agenticActivityBus,
|
|
13884
14038
|
aiServiceAccessRefusalOf,
|
|
13885
14039
|
aiServiceErrorCodeOf,
|
|
14040
|
+
anthropicCacheReadMultiplierFor,
|
|
13886
14041
|
anthropicRatesFor,
|
|
13887
14042
|
anthropicTokenCost,
|
|
13888
14043
|
assembleDebugLog,
|