@genesislcap/ai-assistant 15.96.0 → 15.96.2-GENC-1665.4
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 +763 -747
- package/dist/dts/chat-driver-node.d.ts +1 -1
- package/dist/dts/chat-driver-node.d.ts.map +1 -1
- package/dist/dts/react.d.ts +8 -8
- package/dist/esm/chat-driver-node.js +1 -1
- package/dist/react.cjs +5 -5
- package/dist/react.mjs +4 -4
- package/package.json +17 -17
package/dist/chat-driver.mjs
CHANGED
|
@@ -1218,10 +1218,13 @@ var SUPPORTED_GEMINI_MODEL_IDS = [
|
|
|
1218
1218
|
];
|
|
1219
1219
|
var SUPPORTED_ANTHROPIC_MODEL_IDS = [
|
|
1220
1220
|
"claude-fable-5",
|
|
1221
|
+
"claude-opus-5-5",
|
|
1221
1222
|
"claude-opus-4-8",
|
|
1222
1223
|
"claude-opus-4-7",
|
|
1224
|
+
"claude-sonnet-5-5",
|
|
1223
1225
|
"claude-sonnet-5",
|
|
1224
1226
|
"claude-sonnet-4-6",
|
|
1227
|
+
"claude-haiku-5-5",
|
|
1225
1228
|
"claude-haiku-4-5-20251001"
|
|
1226
1229
|
];
|
|
1227
1230
|
var SUPPORTED_OPENAI_MODEL_IDS = [
|
|
@@ -1258,14 +1261,40 @@ function scaleTemperature(normalized, { defaultTemp, maxTemp }) {
|
|
|
1258
1261
|
|
|
1259
1262
|
// ../../foundation-ai/dist/esm/utils/token-cost.js
|
|
1260
1263
|
var TOKENS_PER_MILLION = 1e6;
|
|
1264
|
+
var ANTHROPIC_LONG_CONTEXT_THRESHOLD = 1e5;
|
|
1261
1265
|
var ANTHROPIC_PRICING = {
|
|
1262
|
-
"claude-haiku-4-5-20251001": {
|
|
1266
|
+
"claude-haiku-4-5-20251001": {
|
|
1267
|
+
kind: "flat",
|
|
1268
|
+
rate: { promptPerMillion: 1, candidatePerMillion: 5 }
|
|
1269
|
+
},
|
|
1270
|
+
// Haiku 5.5 has two rate cards chosen by prompt length; cache reads are 0.1× the input rate of
|
|
1271
|
+
// whichever card applies, like every other model here.
|
|
1272
|
+
"claude-haiku-5-5": {
|
|
1273
|
+
kind: "tiered",
|
|
1274
|
+
standard: { promptPerMillion: 0.1, candidatePerMillion: 0.5 },
|
|
1275
|
+
longContext: { promptPerMillion: 0.5, candidatePerMillion: 2.5 }
|
|
1276
|
+
},
|
|
1263
1277
|
// Fable 5 — Anthropic's most capable widely-released model; priced above Opus tier.
|
|
1264
|
-
"claude-fable-5": { promptPerMillion: 10, candidatePerMillion: 50 },
|
|
1278
|
+
"claude-fable-5": { kind: "flat", rate: { promptPerMillion: 10, candidatePerMillion: 50 } },
|
|
1279
|
+
// Opus 5.5 — $4 / $20, cheaper than Opus 4.8. Its cache reads are $0.20 / MTok, i.e. 0.05× the
|
|
1280
|
+
// input rate (as on Sonnet 5.5), NOT the 0.1× every older model reads at: the global
|
|
1281
|
+
// multiplier would bill its cache reads at double.
|
|
1282
|
+
"claude-opus-5-5": {
|
|
1283
|
+
kind: "flat",
|
|
1284
|
+
rate: { promptPerMillion: 4, candidatePerMillion: 20 },
|
|
1285
|
+
cacheReadMultiplier: 0.05
|
|
1286
|
+
},
|
|
1265
1287
|
// Opus 4.7 / 4.8 — same $5 / $25 per MTok. Stated per model rather than shared through a
|
|
1266
1288
|
// fall-through, so neither is ever "whatever was left over".
|
|
1267
|
-
"claude-opus-4-8": { promptPerMillion: 5, candidatePerMillion: 25 },
|
|
1268
|
-
"claude-opus-4-7": { promptPerMillion: 5, candidatePerMillion: 25 },
|
|
1289
|
+
"claude-opus-4-8": { kind: "flat", rate: { promptPerMillion: 5, candidatePerMillion: 25 } },
|
|
1290
|
+
"claude-opus-4-7": { kind: "flat", rate: { promptPerMillion: 5, candidatePerMillion: 25 } },
|
|
1291
|
+
// Sonnet 5.5 — same $2 / $10 as Sonnet 5, but its cache reads are $0.10 / MTok (0.05×, like
|
|
1292
|
+
// Opus 5.5), half of Sonnet 5's $0.20.
|
|
1293
|
+
"claude-sonnet-5-5": {
|
|
1294
|
+
kind: "flat",
|
|
1295
|
+
rate: { promptPerMillion: 2, candidatePerMillion: 10 },
|
|
1296
|
+
cacheReadMultiplier: 0.05
|
|
1297
|
+
},
|
|
1269
1298
|
// Sonnet 5 is $2 / $10 — its OWN tier, and CHEAPER than the older Sonnet 4.6 below.
|
|
1270
1299
|
//
|
|
1271
1300
|
// This launched as an introductory rate through 2026-08-31, and an earlier version of this
|
|
@@ -1274,22 +1303,32 @@ var ANTHROPIC_PRICING = {
|
|
|
1274
1303
|
// standard price and cancelled the scheduled increase, so that reasoning is dead and the old
|
|
1275
1304
|
// figure over-charged every Sonnet 5 request by 50%.
|
|
1276
1305
|
// https://platform.claude.com/docs/en/about-claude/pricing#model-pricing
|
|
1277
|
-
"claude-sonnet-5": { promptPerMillion: 2, candidatePerMillion: 10 },
|
|
1306
|
+
"claude-sonnet-5": { kind: "flat", rate: { promptPerMillion: 2, candidatePerMillion: 10 } },
|
|
1278
1307
|
// Sonnet 4.6 remains on the older $3 / $15 Sonnet tier — the newer model is the cheaper one.
|
|
1279
|
-
"claude-sonnet-4-6": { promptPerMillion: 3, candidatePerMillion: 15 }
|
|
1308
|
+
"claude-sonnet-4-6": { kind: "flat", rate: { promptPerMillion: 3, candidatePerMillion: 15 } }
|
|
1280
1309
|
};
|
|
1281
|
-
function anthropicRatesFor(model) {
|
|
1282
|
-
|
|
1310
|
+
function anthropicRatesFor(model, promptTokens = 0) {
|
|
1311
|
+
const pricing = ANTHROPIC_PRICING[model];
|
|
1312
|
+
if (pricing.kind === "flat") {
|
|
1313
|
+
return pricing.rate;
|
|
1314
|
+
}
|
|
1315
|
+
return promptTokens > ANTHROPIC_LONG_CONTEXT_THRESHOLD ? pricing.longContext : pricing.standard;
|
|
1283
1316
|
}
|
|
1284
1317
|
var ANTHROPIC_CACHE_READ_MULTIPLIER = 0.1;
|
|
1318
|
+
function anthropicCacheReadMultiplierFor(model) {
|
|
1319
|
+
var _a;
|
|
1320
|
+
return (_a = ANTHROPIC_PRICING[model].cacheReadMultiplier) !== null && _a !== void 0 ? _a : ANTHROPIC_CACHE_READ_MULTIPLIER;
|
|
1321
|
+
}
|
|
1285
1322
|
var ANTHROPIC_CACHE_WRITE_5M_MULTIPLIER = 1.25;
|
|
1286
1323
|
var ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER = 2;
|
|
1287
1324
|
function anthropicTokenCost(model, usage) {
|
|
1288
|
-
const
|
|
1325
|
+
const promptTokens = usage.uncachedInputTokens + usage.cacheReadTokens + usage.cacheWriteTokens;
|
|
1326
|
+
const { promptPerMillion, candidatePerMillion } = anthropicRatesFor(model, promptTokens);
|
|
1327
|
+
const cacheReadMultiplier = anthropicCacheReadMultiplierFor(model);
|
|
1289
1328
|
const m = TOKENS_PER_MILLION;
|
|
1290
1329
|
const cacheWrite5mTokens = Math.max(0, usage.cacheWriteTokens - usage.cacheWrite1hTokens);
|
|
1291
1330
|
const promptCost = usage.uncachedInputTokens / m * promptPerMillion;
|
|
1292
|
-
const cacheReadCost = usage.cacheReadTokens / m * promptPerMillion *
|
|
1331
|
+
const cacheReadCost = usage.cacheReadTokens / m * promptPerMillion * cacheReadMultiplier;
|
|
1293
1332
|
const cacheWriteCost = cacheWrite5mTokens / m * promptPerMillion * ANTHROPIC_CACHE_WRITE_5M_MULTIPLIER + usage.cacheWrite1hTokens / m * promptPerMillion * ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER;
|
|
1294
1333
|
const candidateCost = usage.outputTokens / m * candidatePerMillion;
|
|
1295
1334
|
const cacheReadFull = usage.cacheReadTokens / m * promptPerMillion;
|
|
@@ -2284,6 +2323,7 @@ var DEFAULT_MODEL = "claude-haiku-4-5-20251001";
|
|
|
2284
2323
|
var DEFAULT_TIMEOUT = 3e5;
|
|
2285
2324
|
var DEFAULT_STALL_TIMEOUT = 3e4;
|
|
2286
2325
|
var DEFAULT_MAX_TOKENS = 4096;
|
|
2326
|
+
var CLAUDE_55_DEFAULT_MAX_TOKENS = 64e3;
|
|
2287
2327
|
var ANTHROPIC_DEFAULT_TEMPERATURE = 1;
|
|
2288
2328
|
var ANTHROPIC_MAX_TEMPERATURE = 1;
|
|
2289
2329
|
function toAnthropicToolChoice(choice) {
|
|
@@ -2297,38 +2337,60 @@ function toAnthropicToolChoice(choice) {
|
|
|
2297
2337
|
}
|
|
2298
2338
|
var ANTHROPIC_CONTEXT_LIMITS = {
|
|
2299
2339
|
"claude-fable-5": 1e6,
|
|
2340
|
+
"claude-opus-5-5": 1e6,
|
|
2300
2341
|
"claude-opus-4-8": 1e6,
|
|
2301
2342
|
"claude-opus-4-7": 1e6,
|
|
2343
|
+
"claude-sonnet-5-5": 1e6,
|
|
2302
2344
|
"claude-sonnet-5": 1e6,
|
|
2303
2345
|
"claude-sonnet-4-6": 1e6,
|
|
2346
|
+
"claude-haiku-5-5": 1e6,
|
|
2304
2347
|
"claude-haiku-4-5-20251001": 2e5
|
|
2305
2348
|
};
|
|
2306
2349
|
var STRUCTURED_OUTPUT_TOOL_NAME = "emit_structured_response";
|
|
2307
2350
|
var SERVER_SIDE_FALLBACK_BETA = "server-side-fallback-2026-06-01";
|
|
2351
|
+
var THINKING_BINDING_CONTROLS_BETA = "thinking-binding-controls-2026-08-01";
|
|
2308
2352
|
function assertSupportedAnthropicModel(model) {
|
|
2309
2353
|
if (!SUPPORTED_ANTHROPIC_MODEL_IDS.includes(model)) {
|
|
2310
2354
|
throw new Error(`AnthropicTransport: unsupported model "${model}". Use one of: ${SUPPORTED_ANTHROPIC_MODEL_IDS.join(", ")}.`);
|
|
2311
2355
|
}
|
|
2312
2356
|
}
|
|
2357
|
+
function isClaude55(model) {
|
|
2358
|
+
return model === "claude-opus-5-5" || model === "claude-sonnet-5-5" || model === "claude-haiku-5-5";
|
|
2359
|
+
}
|
|
2313
2360
|
function rejectsSamplingParams(model) {
|
|
2314
|
-
return model === "claude-fable-5" || model === "claude-opus-4-8" || model === "claude-opus-4-7" || model === "claude-sonnet-5";
|
|
2361
|
+
return model === "claude-fable-5" || model === "claude-opus-4-8" || model === "claude-opus-4-7" || model === "claude-sonnet-5" || isClaude55(model);
|
|
2362
|
+
}
|
|
2363
|
+
function supportsForcedToolChoice(model) {
|
|
2364
|
+
return model !== "claude-opus-5-5" && model !== "claude-sonnet-5-5";
|
|
2315
2365
|
}
|
|
2316
2366
|
function supportsNativeStructuredOutput(model) {
|
|
2317
|
-
return model === "claude-fable-5" || model === "claude-opus-4-8" || model === "claude-sonnet-5" || model === "claude-haiku-4-5-20251001";
|
|
2367
|
+
return model === "claude-fable-5" || model === "claude-opus-4-8" || model === "claude-sonnet-5" || model === "claude-haiku-4-5-20251001" || isClaude55(model);
|
|
2318
2368
|
}
|
|
2319
2369
|
function supportsAdaptiveThinking(model) {
|
|
2320
2370
|
return model !== "claude-haiku-4-5-20251001";
|
|
2321
2371
|
}
|
|
2322
2372
|
function thinkingIsMandatory(model) {
|
|
2323
|
-
return model === "claude-fable-5";
|
|
2373
|
+
return model === "claude-fable-5" || model === "claude-opus-5-5";
|
|
2374
|
+
}
|
|
2375
|
+
function defaultsToThinking(model) {
|
|
2376
|
+
return model === "claude-sonnet-5" || model === "claude-sonnet-5-5" || model === "claude-haiku-5-5" || thinkingIsMandatory(model);
|
|
2377
|
+
}
|
|
2378
|
+
function thinkingOff(model) {
|
|
2379
|
+
return model === "claude-sonnet-5-5" ? { type: "between_tools" } : { type: "disabled" };
|
|
2380
|
+
}
|
|
2381
|
+
var POLICY_EFFORT = {
|
|
2382
|
+
"claude-opus-5-5": { off: "low" }
|
|
2383
|
+
};
|
|
2384
|
+
function sendsBlockBinding(model) {
|
|
2385
|
+
return isClaude55(model);
|
|
2324
2386
|
}
|
|
2325
2387
|
function anthropicThinking(model, policy) {
|
|
2326
|
-
const
|
|
2388
|
+
const thinksByDefault = defaultsToThinking(model);
|
|
2327
2389
|
const adaptive = { type: "adaptive", display: "summarized" };
|
|
2328
2390
|
if (policy === "off") {
|
|
2329
2391
|
if (thinkingIsMandatory(model))
|
|
2330
2392
|
return adaptive;
|
|
2331
|
-
return
|
|
2393
|
+
return thinksByDefault ? thinkingOff(model) : void 0;
|
|
2332
2394
|
}
|
|
2333
2395
|
if (policy === "auto") {
|
|
2334
2396
|
return supportsAdaptiveThinking(model) ? adaptive : void 0;
|
|
@@ -2336,10 +2398,10 @@ function anthropicThinking(model, policy) {
|
|
|
2336
2398
|
if (policy !== void 0) {
|
|
2337
2399
|
return supportsAdaptiveThinking(model) ? adaptive : void 0;
|
|
2338
2400
|
}
|
|
2339
|
-
return
|
|
2401
|
+
return thinksByDefault ? adaptive : void 0;
|
|
2340
2402
|
}
|
|
2341
2403
|
function supportsEffort(model) {
|
|
2342
|
-
return model === "claude-fable-5" || model === "claude-opus-4-8" || model === "claude-sonnet-5";
|
|
2404
|
+
return model === "claude-fable-5" || model === "claude-opus-4-8" || model === "claude-sonnet-5" || isClaude55(model);
|
|
2343
2405
|
}
|
|
2344
2406
|
var ANTHROPIC_EFFORT = {
|
|
2345
2407
|
minimal: "low",
|
|
@@ -2349,8 +2411,11 @@ var ANTHROPIC_EFFORT = {
|
|
|
2349
2411
|
max: "max"
|
|
2350
2412
|
};
|
|
2351
2413
|
function anthropicEffort(model, policy) {
|
|
2352
|
-
|
|
2414
|
+
var _a;
|
|
2415
|
+
if (policy === void 0)
|
|
2353
2416
|
return void 0;
|
|
2417
|
+
if (policy === "auto" || policy === "off")
|
|
2418
|
+
return (_a = POLICY_EFFORT[model]) === null || _a === void 0 ? void 0 : _a[policy];
|
|
2354
2419
|
if (!supportsEffort(model) || !supportsAdaptiveThinking(model))
|
|
2355
2420
|
return void 0;
|
|
2356
2421
|
return ANTHROPIC_EFFORT[policy];
|
|
@@ -2394,11 +2459,14 @@ var AnthropicTransport = class _AnthropicTransport {
|
|
|
2394
2459
|
* outcome the type's own docs promise callers never happens.
|
|
2395
2460
|
*/
|
|
2396
2461
|
clampWarning(policy) {
|
|
2462
|
+
var _a, _b;
|
|
2397
2463
|
switch (policy) {
|
|
2398
2464
|
case void 0:
|
|
2399
2465
|
return void 0;
|
|
2400
2466
|
case "off":
|
|
2401
|
-
|
|
2467
|
+
if (!thinkingIsMandatory(this.model))
|
|
2468
|
+
return void 0;
|
|
2469
|
+
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.`;
|
|
2402
2470
|
case "auto":
|
|
2403
2471
|
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.`;
|
|
2404
2472
|
case "minimal":
|
|
@@ -2407,7 +2475,7 @@ var AnthropicTransport = class _AnthropicTransport {
|
|
|
2407
2475
|
case "high":
|
|
2408
2476
|
case "max":
|
|
2409
2477
|
if (!supportsAdaptiveThinking(this.model) || !supportsEffort(this.model)) {
|
|
2410
|
-
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.`;
|
|
2478
|
+
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.`;
|
|
2411
2479
|
}
|
|
2412
2480
|
return void 0;
|
|
2413
2481
|
default: {
|
|
@@ -2417,10 +2485,11 @@ var AnthropicTransport = class _AnthropicTransport {
|
|
|
2417
2485
|
}
|
|
2418
2486
|
}
|
|
2419
2487
|
constructor(config = {}) {
|
|
2420
|
-
var _a, _b, _c, _d;
|
|
2488
|
+
var _a, _b, _c, _d, _e;
|
|
2421
2489
|
this.lifetimeCostUsd = 0;
|
|
2422
2490
|
this.lifetimeSavingsUsd = 0;
|
|
2423
2491
|
this.warnedThinkingClamped = false;
|
|
2492
|
+
this.warnedToolChoiceDowngraded = false;
|
|
2424
2493
|
this.warnedUnknownServingModels = /* @__PURE__ */ new Set();
|
|
2425
2494
|
const model = (_a = config.model) !== null && _a !== void 0 ? _a : DEFAULT_MODEL;
|
|
2426
2495
|
assertSupportedAnthropicModel(model);
|
|
@@ -2431,6 +2500,10 @@ var AnthropicTransport = class _AnthropicTransport {
|
|
|
2431
2500
|
logger.warn("AnthropicTransport: using claude-sonnet-4-6 \u2014 higher cost than Haiku; use for stronger reasoning or agent tasks.");
|
|
2432
2501
|
} else if (model === "claude-opus-4-7" || model === "claude-opus-4-8") {
|
|
2433
2502
|
logger.warn(`AnthropicTransport: using ${model} \u2014 significantly higher cost; reserve for tasks where Sonnet reliability is insufficient.`);
|
|
2503
|
+
} else if (model === "claude-opus-5-5") {
|
|
2504
|
+
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.");
|
|
2505
|
+
} else if (model === "claude-sonnet-5-5") {
|
|
2506
|
+
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.");
|
|
2434
2507
|
} else if (model === "claude-fable-5") {
|
|
2435
2508
|
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.`);
|
|
2436
2509
|
}
|
|
@@ -2438,7 +2511,8 @@ var AnthropicTransport = class _AnthropicTransport {
|
|
|
2438
2511
|
this.stallTimeout = (_c = config.stallTimeout) !== null && _c !== void 0 ? _c : DEFAULT_STALL_TIMEOUT;
|
|
2439
2512
|
this.apiKey = config.apiKey;
|
|
2440
2513
|
this.serverEndpoint = config.serverEndpoint;
|
|
2441
|
-
this.maxTokens = (_d = config.maxTokens) !== null && _d !== void 0 ? _d : DEFAULT_MAX_TOKENS;
|
|
2514
|
+
this.maxTokens = (_d = config.maxTokens) !== null && _d !== void 0 ? _d : isClaude55(model) ? CLAUDE_55_DEFAULT_MAX_TOKENS : DEFAULT_MAX_TOKENS;
|
|
2515
|
+
this.thinkingBlockBinding = (_e = config.thinkingBlockBinding) !== null && _e !== void 0 ? _e : "drop_block";
|
|
2442
2516
|
}
|
|
2443
2517
|
getConfig() {
|
|
2444
2518
|
return {
|
|
@@ -2478,6 +2552,9 @@ var AnthropicTransport = class _AnthropicTransport {
|
|
|
2478
2552
|
if (useNative) {
|
|
2479
2553
|
body.output_config = Object.assign(Object.assign({}, body.output_config), { format: { type: "json_schema", schema: responseSchema } });
|
|
2480
2554
|
} else if (useForcedTool) {
|
|
2555
|
+
if (!supportsForcedToolChoice(this.model)) {
|
|
2556
|
+
throw new Error(`AnthropicTransport: ${this.model} rejects forced tool_choice and must be listed in supportsNativeStructuredOutput.`);
|
|
2557
|
+
}
|
|
2481
2558
|
body.tools = [
|
|
2482
2559
|
{
|
|
2483
2560
|
name: STRUCTURED_OUTPUT_TOOL_NAME,
|
|
@@ -2487,8 +2564,9 @@ var AnthropicTransport = class _AnthropicTransport {
|
|
|
2487
2564
|
];
|
|
2488
2565
|
body.tool_choice = { type: "tool", name: STRUCTURED_OUTPUT_TOOL_NAME };
|
|
2489
2566
|
}
|
|
2490
|
-
if (this.model
|
|
2491
|
-
body.thinking =
|
|
2567
|
+
if (defaultsToThinking(this.model) && !thinkingIsMandatory(this.model)) {
|
|
2568
|
+
body.thinking = thinkingOff(this.model);
|
|
2569
|
+
}
|
|
2492
2570
|
const response = yield this.post(body);
|
|
2493
2571
|
if (useForcedTool) {
|
|
2494
2572
|
const toolUse = ((_a = response.content) !== null && _a !== void 0 ? _a : []).find((b) => b.type === "tool_use" && b.name === STRUCTURED_OUTPUT_TOOL_NAME);
|
|
@@ -2517,15 +2595,11 @@ var AnthropicTransport = class _AnthropicTransport {
|
|
|
2517
2595
|
if ((_c = options === null || options === void 0 ? void 0 : options.tools) === null || _c === void 0 ? void 0 : _c.length) {
|
|
2518
2596
|
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 } : {}));
|
|
2519
2597
|
}
|
|
2520
|
-
|
|
2521
|
-
const toolChoice = toAnthropicToolChoice(options === null || options === void 0 ? void 0 : options.toolChoice);
|
|
2522
|
-
if (toolChoice)
|
|
2523
|
-
body.tool_choice = toolChoice;
|
|
2524
|
-
}
|
|
2598
|
+
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;
|
|
2525
2599
|
this.warnIfThinkingUnclampable(options === null || options === void 0 ? void 0 : options.thinkingPolicy);
|
|
2526
2600
|
const thinking = anthropicThinking(this.model, options === null || options === void 0 ? void 0 : options.thinkingPolicy);
|
|
2527
2601
|
if (thinking)
|
|
2528
|
-
body.thinking = thinking;
|
|
2602
|
+
body.thinking = this.withBlockBinding(thinking);
|
|
2529
2603
|
const effort = anthropicEffort(this.model, options === null || options === void 0 ? void 0 : options.thinkingPolicy);
|
|
2530
2604
|
if (effort)
|
|
2531
2605
|
body.output_config = Object.assign(Object.assign({}, body.output_config), { effort });
|
|
@@ -2545,13 +2619,76 @@ var AnthropicTransport = class _AnthropicTransport {
|
|
|
2545
2619
|
if (options === null || options === void 0 ? void 0 : options.cachePolicy) {
|
|
2546
2620
|
this.applyCacheControl(body, options.cachePolicy);
|
|
2547
2621
|
}
|
|
2548
|
-
|
|
2549
|
-
|
|
2622
|
+
const tail = [options === null || options === void 0 ? void 0 : options.tailContext, forcedToolNote].filter(Boolean).join("\n\n");
|
|
2623
|
+
if (tail) {
|
|
2624
|
+
this.appendTailContext(body, tail);
|
|
2550
2625
|
}
|
|
2551
2626
|
const response = yield this.post(body, options === null || options === void 0 ? void 0 : options.signal);
|
|
2552
|
-
|
|
2627
|
+
const message = this.fromAnthropicResponse(response, body.max_tokens);
|
|
2628
|
+
if (forcedToolNote && message.responseMeta) {
|
|
2629
|
+
message.responseMeta.toolChoiceDowngraded = true;
|
|
2630
|
+
}
|
|
2631
|
+
return message;
|
|
2553
2632
|
});
|
|
2554
2633
|
}
|
|
2634
|
+
/**
|
|
2635
|
+
* Set `tool_choice` from the caller's {@link ChatToolChoice}. `'required'`/`{ tool }` force a
|
|
2636
|
+
* tool call so a turn can only end via one (e.g. a sub-agent's completion tool); on a model that
|
|
2637
|
+
* rejects forcing they are downgraded (see `downgradeForcedToolChoice`), and the instruction
|
|
2638
|
+
* that replaces them is returned for the tail.
|
|
2639
|
+
*/
|
|
2640
|
+
applyToolChoice(body, choice) {
|
|
2641
|
+
const toolChoice = toAnthropicToolChoice(choice);
|
|
2642
|
+
if (!toolChoice)
|
|
2643
|
+
return void 0;
|
|
2644
|
+
const forced = toolChoice.type === "any" || toolChoice.type === "tool";
|
|
2645
|
+
if (forced && !supportsForcedToolChoice(this.model)) {
|
|
2646
|
+
return this.downgradeForcedToolChoice(toolChoice);
|
|
2647
|
+
}
|
|
2648
|
+
body.tool_choice = toolChoice;
|
|
2649
|
+
return void 0;
|
|
2650
|
+
}
|
|
2651
|
+
/**
|
|
2652
|
+
* Preserved thinking (5.5 family): say what a changed history does to replayed thinking, rather
|
|
2653
|
+
* than inheriting the account default (a 400 on accounts created on or after 2026-08-31).
|
|
2654
|
+
* Adaptive only — `between_tools` and `disabled` reject the field — and a fresh object, so the
|
|
2655
|
+
* shared `adaptive` constant in `anthropicThinking` is never mutated.
|
|
2656
|
+
*/
|
|
2657
|
+
withBlockBinding(thinking) {
|
|
2658
|
+
if (thinking.type !== "adaptive" || !sendsBlockBinding(this.model) || this.thinkingBlockBinding === "omit") {
|
|
2659
|
+
return thinking;
|
|
2660
|
+
}
|
|
2661
|
+
return Object.assign(Object.assign({}, thinking), { block_binding: { prefix_mismatch_behavior: this.thinkingBlockBinding } });
|
|
2662
|
+
}
|
|
2663
|
+
/**
|
|
2664
|
+
* Stand-in for a forced tool call on a model that rejects `tool_choice` `any`/`tool` with a 400
|
|
2665
|
+
* (Opus 5.5, Sonnet 5.5). The request goes out with `tool_choice` omitted (`auto`), and an
|
|
2666
|
+
* instruction naming the tool is returned for the caller to append to the tail.
|
|
2667
|
+
*
|
|
2668
|
+
* **The tools array is left exactly as the caller built it.** It renders first in the prompt, so
|
|
2669
|
+
* it heads both the prompt-cache prefix and the prefix preserved thinking is bound to. Rewriting
|
|
2670
|
+
* a tool only on forced turns (making it `strict`, say) would change those bytes every time an
|
|
2671
|
+
* agent moves between forced and `auto` turns: a cache miss, every replayed thinking block
|
|
2672
|
+
* dropped (or a 400 under `block_binding: 'error'`), and a tool that accepts different arguments
|
|
2673
|
+
* depending on the turn. Whether a tool's arguments are enforced is the caller's decision, made
|
|
2674
|
+
* once per tool with `enforceSchema`, and holds on every turn; a completion tool that is forced
|
|
2675
|
+
* is a good candidate for it.
|
|
2676
|
+
*
|
|
2677
|
+
* `auto` lets the model answer in text instead, so the caller is told: a one-time warning here,
|
|
2678
|
+
* and `responseMeta.toolChoiceDowngraded` on every affected response. In the ChatDriver a
|
|
2679
|
+
* sub-agent that answers in text is held open by the finish-guard completion nudge; a parent
|
|
2680
|
+
* agent that relies on forcing should give itself a `finishGuard` that asks for the call.
|
|
2681
|
+
*/
|
|
2682
|
+
downgradeForcedToolChoice(toolChoice) {
|
|
2683
|
+
if (!this.warnedToolChoiceDowngraded) {
|
|
2684
|
+
this.warnedToolChoiceDowngraded = true;
|
|
2685
|
+
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.`);
|
|
2686
|
+
}
|
|
2687
|
+
if (toolChoice.type === "tool" && toolChoice.name) {
|
|
2688
|
+
return `<system-reminder>Respond to this turn by calling the \`${toolChoice.name}\` tool. Do not reply with text alone.</system-reminder>`;
|
|
2689
|
+
}
|
|
2690
|
+
return "<system-reminder>Respond to this turn by calling one of your tools. Do not reply with text alone.</system-reminder>";
|
|
2691
|
+
}
|
|
2555
2692
|
/**
|
|
2556
2693
|
* Place prompt-cache breakpoints on the outgoing request per the resolved {@link CachePolicy}.
|
|
2557
2694
|
* A breakpoint is `cache_control: {type:'ephemeral'}` on a content block / tool / system block;
|
|
@@ -2851,7 +2988,7 @@ ${att.content}` });
|
|
|
2851
2988
|
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);
|
|
2852
2989
|
}
|
|
2853
2990
|
fromAnthropicResponse(response, effectiveMaxTokens = this.maxTokens) {
|
|
2854
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
2991
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
2855
2992
|
let inputTokens;
|
|
2856
2993
|
let outputTokens;
|
|
2857
2994
|
let cacheReadTokens;
|
|
@@ -2951,6 +3088,16 @@ ${att.content}` });
|
|
|
2951
3088
|
};
|
|
2952
3089
|
if (response.stop_reason)
|
|
2953
3090
|
responseMeta.finishReason = response.stop_reason;
|
|
3091
|
+
if ((_h = response.input_transformations) === null || _h === void 0 ? void 0 : _h.length) {
|
|
3092
|
+
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 } : {}));
|
|
3093
|
+
const dropped = response.input_transformations.filter((t) => t.type === "thinking_dropped");
|
|
3094
|
+
if (dropped.length) {
|
|
3095
|
+
logger.debug(`AnthropicTransport: ${dropped.length} thinking block(s) dropped by ${(_j = response.model) !== null && _j !== void 0 ? _j : this.model}: ${dropped.map((t) => {
|
|
3096
|
+
var _a2, _b2;
|
|
3097
|
+
return `${(_a2 = t.path) !== null && _a2 !== void 0 ? _a2 : "?"} (${(_b2 = t.reason) !== null && _b2 !== void 0 ? _b2 : "unknown"})`;
|
|
3098
|
+
}).join(", ")}`);
|
|
3099
|
+
}
|
|
3100
|
+
}
|
|
2954
3101
|
base.responseMeta = responseMeta;
|
|
2955
3102
|
return base;
|
|
2956
3103
|
}
|
|
@@ -2982,9 +3129,13 @@ ${att.content}` });
|
|
|
2982
3129
|
}
|
|
2983
3130
|
post(body, signal) {
|
|
2984
3131
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2985
|
-
var _a;
|
|
3132
|
+
var _a, _b;
|
|
2986
3133
|
const { url, headers, credentials } = this.buildEndpoint();
|
|
2987
|
-
const
|
|
3134
|
+
const betas = [
|
|
3135
|
+
((_a = body.fallbacks) === null || _a === void 0 ? void 0 : _a.length) ? SERVER_SIDE_FALLBACK_BETA : void 0,
|
|
3136
|
+
((_b = body.thinking) === null || _b === void 0 ? void 0 : _b.type) === "adaptive" && body.thinking.block_binding ? THINKING_BINDING_CONTROLS_BETA : void 0
|
|
3137
|
+
].filter((b) => Boolean(b));
|
|
3138
|
+
const requestHeaders = betas.length ? Object.assign(Object.assign({}, headers), { "anthropic-beta": [headers["anthropic-beta"], ...betas].filter(Boolean).join(",") }) : headers;
|
|
2988
3139
|
return yield postWithRetry({
|
|
2989
3140
|
url,
|
|
2990
3141
|
headers: requestHeaders,
|
|
@@ -13752,6 +13903,7 @@ export {
|
|
|
13752
13903
|
ANTHROPIC_CACHE_READ_MULTIPLIER,
|
|
13753
13904
|
ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER,
|
|
13754
13905
|
ANTHROPIC_CACHE_WRITE_5M_MULTIPLIER,
|
|
13906
|
+
ANTHROPIC_LONG_CONTEXT_THRESHOLD,
|
|
13755
13907
|
AgenticActivityBus,
|
|
13756
13908
|
AnthropicProvider,
|
|
13757
13909
|
AnthropicTransport,
|
|
@@ -13785,6 +13937,7 @@ export {
|
|
|
13785
13937
|
agenticActivityBus,
|
|
13786
13938
|
aiServiceAccessRefusalOf,
|
|
13787
13939
|
aiServiceErrorCodeOf,
|
|
13940
|
+
anthropicCacheReadMultiplierFor,
|
|
13788
13941
|
anthropicRatesFor,
|
|
13789
13942
|
anthropicTokenCost,
|
|
13790
13943
|
assembleDebugLog,
|