@genesislcap/foundation-ai 15.95.2-GENC-1665.2 → 15.96.0
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/dts/index.d.ts +1 -1
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/transports/anthropic-transport.d.ts +1 -49
- package/dist/dts/transports/anthropic-transport.d.ts.map +1 -1
- package/dist/dts/types/chat.types.d.ts +13 -21
- package/dist/dts/types/chat.types.d.ts.map +1 -1
- package/dist/dts/types/config.types.d.ts +2 -3
- package/dist/dts/types/config.types.d.ts.map +1 -1
- package/dist/dts/utils/token-cost.d.ts +1 -25
- package/dist/dts/utils/token-cost.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/transports/anthropic-transport.js +45 -250
- package/dist/esm/types/config.types.js +0 -3
- package/dist/esm/utils/token-cost.js +11 -69
- package/dist/foundation-ai.api.json +33 -154
- package/dist/foundation-ai.d.ts +17 -100
- package/package.json +9 -9
|
@@ -13,16 +13,6 @@ const DEFAULT_MODEL = 'claude-haiku-4-5-20251001';
|
|
|
13
13
|
const DEFAULT_TIMEOUT = 300000; // healthy >200s generations observed at 128k max_tokens; wall clock is a last resort
|
|
14
14
|
const DEFAULT_STALL_TIMEOUT = 30000; // inactivity window on the framed proxy path; pings arrive every 5s
|
|
15
15
|
const DEFAULT_MAX_TOKENS = 4096;
|
|
16
|
-
/**
|
|
17
|
-
* The `max_tokens` a 5.5 model gets when the caller sets none. They think on every turn, and the
|
|
18
|
-
* thinking is billed out of the same `max_tokens` (stated for Haiku 5.5), so 4,096 can be spent
|
|
19
|
-
* before any text or tool call is written. Anthropic recommends 64,000 for agent work: in its
|
|
20
|
-
* tests only 7 of about 18,000 turns ran longer, cost per solved task did not rise, and Opus 5.5
|
|
21
|
-
* solved 57.6% at 16,384 against 75.6% at 64,000. `max_tokens` is only a cap and the model
|
|
22
|
-
* cannot see it, so a higher one bills nothing extra on a turn that stops short of it. All three
|
|
23
|
-
* allow 128K.
|
|
24
|
-
*/
|
|
25
|
-
const CLAUDE_55_DEFAULT_MAX_TOKENS = 64000;
|
|
26
16
|
/** Anthropic's native default + ceiling temperature — https://docs.claude.com/en/api/messages */
|
|
27
17
|
const ANTHROPIC_DEFAULT_TEMPERATURE = 1;
|
|
28
18
|
const ANTHROPIC_MAX_TEMPERATURE = 1;
|
|
@@ -45,13 +35,10 @@ function toAnthropicToolChoice(choice) {
|
|
|
45
35
|
*/
|
|
46
36
|
const ANTHROPIC_CONTEXT_LIMITS = {
|
|
47
37
|
'claude-fable-5': 1000000,
|
|
48
|
-
'claude-opus-5-5': 1000000,
|
|
49
38
|
'claude-opus-4-8': 1000000,
|
|
50
39
|
'claude-opus-4-7': 1000000,
|
|
51
|
-
'claude-sonnet-5-5': 1000000,
|
|
52
40
|
'claude-sonnet-5': 1000000,
|
|
53
41
|
'claude-sonnet-4-6': 1000000,
|
|
54
|
-
'claude-haiku-5-5': 1000000,
|
|
55
42
|
'claude-haiku-4-5-20251001': 200000,
|
|
56
43
|
};
|
|
57
44
|
/**
|
|
@@ -62,51 +49,24 @@ const ANTHROPIC_CONTEXT_LIMITS = {
|
|
|
62
49
|
const STRUCTURED_OUTPUT_TOOL_NAME = 'emit_structured_response';
|
|
63
50
|
/** Beta flag enabling the server-side `fallbacks` request parameter (refusal rescue). */
|
|
64
51
|
const SERVER_SIDE_FALLBACK_BETA = 'server-side-fallback-2026-06-01';
|
|
65
|
-
/**
|
|
66
|
-
* Beta flag that lets a request set `thinking.block_binding` and adds `input_transformations` to
|
|
67
|
-
* every response. Without it the field is a 400 (`block_binding: Extra inputs are not permitted`).
|
|
68
|
-
*/
|
|
69
|
-
const THINKING_BINDING_CONTROLS_BETA = 'thinking-binding-controls-2026-08-01';
|
|
70
52
|
function assertSupportedAnthropicModel(model) {
|
|
71
53
|
if (!SUPPORTED_ANTHROPIC_MODEL_IDS.includes(model)) {
|
|
72
54
|
throw new Error(`AnthropicTransport: unsupported model "${model}". Use one of: ${SUPPORTED_ANTHROPIC_MODEL_IDS.join(', ')}.`);
|
|
73
55
|
}
|
|
74
56
|
}
|
|
75
|
-
/**
|
|
76
|
-
* The Claude 5.5 family. Grouped because they share the API changes this transport has to route
|
|
77
|
-
* around — no non-default sampling parameters, `output_config` (effort + format), and *preserved
|
|
78
|
-
* thinking*: a replayed thinking block is valid only while everything sent before it is
|
|
79
|
-
* byte-identical (see {@link sendsBlockBinding}). Each capability below still lists its models
|
|
80
|
-
* explicitly where the three differ.
|
|
81
|
-
*/
|
|
82
|
-
function isClaude55(model) {
|
|
83
|
-
return (model === 'claude-opus-5-5' || model === 'claude-sonnet-5-5' || model === 'claude-haiku-5-5');
|
|
84
|
-
}
|
|
85
57
|
/**
|
|
86
58
|
* Models that reject non-default sampling parameters (`temperature`/`top_p`/`top_k`) with a 400 —
|
|
87
|
-
* the Opus 4.7+ / Sonnet 5 / Fable 5 generation
|
|
88
|
-
* still accept them.
|
|
59
|
+
* the Opus 4.7+ / Sonnet 5 / Fable 5 generation. Sonnet 4.6 and Haiku 4.5 still accept them.
|
|
89
60
|
*/
|
|
90
61
|
function rejectsSamplingParams(model) {
|
|
91
62
|
return (model === 'claude-fable-5' ||
|
|
92
63
|
model === 'claude-opus-4-8' ||
|
|
93
64
|
model === 'claude-opus-4-7' ||
|
|
94
|
-
model === 'claude-sonnet-5'
|
|
95
|
-
isClaude55(model));
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Whether the model accepts a FORCED `tool_choice` (`{type:'any'}` or `{type:'tool'}`). Opus 5.5
|
|
99
|
-
* and Sonnet 5.5 return a 400 for both (`tool_choice: type "tool" and "any" are not supported for
|
|
100
|
-
* this model.`); see {@link AnthropicTransport} for the `auto` + instruction fallback they get.
|
|
101
|
-
* Haiku 5.5 still accepts forcing — the response then skips thinking, as on older models — so it
|
|
102
|
-
* keeps today's behaviour. `{type:'none'}` is unaffected everywhere.
|
|
103
|
-
*/
|
|
104
|
-
function supportsForcedToolChoice(model) {
|
|
105
|
-
return model !== 'claude-opus-5-5' && model !== 'claude-sonnet-5-5';
|
|
65
|
+
model === 'claude-sonnet-5');
|
|
106
66
|
}
|
|
107
67
|
/**
|
|
108
68
|
* Whether the model enforces structured output natively via decode-time `output_config.format`
|
|
109
|
-
* (json_schema). True for Fable 5, Opus 4.8, Sonnet 5, Haiku 4.5
|
|
69
|
+
* (json_schema). True for Fable 5, Opus 4.8, Sonnet 5, and Haiku 4.5; false for Opus 4.7 and
|
|
110
70
|
* Sonnet 4.6, which fall back to the forced-tool approach on the one-shot path. `output_config`
|
|
111
71
|
* composes with a live `tools` array, so no tool-vs-schema gating is needed on this provider.
|
|
112
72
|
*/
|
|
@@ -114,8 +74,7 @@ function supportsNativeStructuredOutput(model) {
|
|
|
114
74
|
return (model === 'claude-fable-5' ||
|
|
115
75
|
model === 'claude-opus-4-8' ||
|
|
116
76
|
model === 'claude-sonnet-5' ||
|
|
117
|
-
model === 'claude-haiku-4-5-20251001'
|
|
118
|
-
isClaude55(model));
|
|
77
|
+
model === 'claude-haiku-4-5-20251001');
|
|
119
78
|
}
|
|
120
79
|
/**
|
|
121
80
|
* Whether a model accepts `thinking: {type:'adaptive'}` at all. Everything from the 4.6
|
|
@@ -128,63 +87,10 @@ function supportsAdaptiveThinking(model) {
|
|
|
128
87
|
/**
|
|
129
88
|
* Models that think **unconditionally** — `{type:'disabled'}` is a 400, not a no-op. The same
|
|
130
89
|
* constraint exists on the other provider (Gemini 2.5 Pro), so this is a property of flagship
|
|
131
|
-
* reasoning models rather than an Anthropic quirk; see `ChatThinkingPolicy`.
|
|
132
|
-
* `disabled` at every effort level.
|
|
90
|
+
* reasoning models rather than an Anthropic quirk; see `ChatThinkingPolicy`.
|
|
133
91
|
*/
|
|
134
92
|
function thinkingIsMandatory(model) {
|
|
135
|
-
return model === 'claude-fable-5'
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Models that run adaptive thinking when the request omits `thinking`. On the others (Opus 4.8 /
|
|
139
|
-
* 4.7, Sonnet 4.6, Haiku 4.5) adaptive thinking is opt-in.
|
|
140
|
-
*/
|
|
141
|
-
function defaultsToThinking(model) {
|
|
142
|
-
return (model === 'claude-sonnet-5' ||
|
|
143
|
-
model === 'claude-sonnet-5-5' ||
|
|
144
|
-
model === 'claude-haiku-5-5' ||
|
|
145
|
-
thinkingIsMandatory(model));
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* How `thinkingPolicy: 'off'` is expressed on a model that thinks by default and CAN stop.
|
|
149
|
-
*
|
|
150
|
-
* - Sonnet 5.5 rejects `{type:'disabled'}`; its off switch is `{type:'between_tools'}` — no
|
|
151
|
-
* extended thinking, only short progress notes between tool calls. It takes no other field
|
|
152
|
-
* inside `thinking` and is accepted only at effort `high` or below (the default), which is all
|
|
153
|
-
* an `'off'` turn ever sends.
|
|
154
|
-
* - Sonnet 5 and Haiku 5.5 take `{type:'disabled'}` (Haiku 5.5 only at effort `high` or below,
|
|
155
|
-
* again the only effort an `'off'` turn sends).
|
|
156
|
-
*/
|
|
157
|
-
function thinkingOff(model) {
|
|
158
|
-
return model === 'claude-sonnet-5-5' ? { type: 'between_tools' } : { type: 'disabled' };
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Explicit `output_config.effort` for `'auto'` and `'off'` on models where the API default would
|
|
162
|
-
* not mean what the policy promises.
|
|
163
|
-
*
|
|
164
|
-
* Opus 5.5 cannot turn thinking off, so `'off'` sends the lowest effort instead — the model then
|
|
165
|
-
* thinks little or not at all — rather than silently billing a full-depth turn.
|
|
166
|
-
*
|
|
167
|
-
* `'auto'` sends nothing on every model, so it runs at the model's own default depth. On Opus 5.5
|
|
168
|
-
* and Haiku 5.5 that is `medium`, a level below the `high` of the others, and it is the depth
|
|
169
|
-
* Anthropic recommends starting from: on its SWE-bench Pro runs Opus 5.5 at `medium` cost $0.21
|
|
170
|
-
* per task against $0.29 at `high`, for 92.8% solved against 95.3%
|
|
171
|
-
* (https://platform.claude.com/docs/en/about-claude/models/optimizing-for-cost-and-intelligence).
|
|
172
|
-
* A caller that needs more asks for a graded level (`'high'`) explicitly.
|
|
173
|
-
*/
|
|
174
|
-
const POLICY_EFFORT = {
|
|
175
|
-
'claude-opus-5-5': { off: 'low' },
|
|
176
|
-
};
|
|
177
|
-
/**
|
|
178
|
-
* Whether to send `thinking.block_binding` (and its beta) on this model. The 5.5 family runs
|
|
179
|
-
* preserved thinking's history-editing check: a replayed thinking block is valid only while the
|
|
180
|
-
* system prompt, the tools and every earlier message are byte-identical to when it was produced.
|
|
181
|
-
* On an account created on or after 2026-08-31 a mismatch is a 400 by default; `drop_block`
|
|
182
|
-
* instead drops the block (and every later one) for that request and reports it in
|
|
183
|
-
* `input_transformations`. Only valid alongside adaptive thinking — `between_tools` and
|
|
184
|
-
* `disabled` reject the field.
|
|
185
|
-
*/
|
|
186
|
-
function sendsBlockBinding(model) {
|
|
187
|
-
return isClaude55(model);
|
|
93
|
+
return model === 'claude-fable-5';
|
|
188
94
|
}
|
|
189
95
|
/**
|
|
190
96
|
* Extended-thinking posture for a request, given the model and the caller's
|
|
@@ -219,15 +125,14 @@ function sendsBlockBinding(model) {
|
|
|
219
125
|
* keeps the request identical to the one those models have always received.
|
|
220
126
|
*/
|
|
221
127
|
function anthropicThinking(model, policy) {
|
|
222
|
-
const
|
|
128
|
+
const defaultsToThinking = model === 'claude-sonnet-5' || thinkingIsMandatory(model);
|
|
223
129
|
const adaptive = { type: 'adaptive', display: 'summarized' };
|
|
224
130
|
if (policy === 'off') {
|
|
225
|
-
// Cannot be turned off — keep the model's default rather than 400 the turn
|
|
226
|
-
// drops to its lowest effort; see POLICY_EFFORT).
|
|
131
|
+
// Cannot be turned off — keep the model's default rather than 400 the turn.
|
|
227
132
|
if (thinkingIsMandatory(model))
|
|
228
133
|
return adaptive;
|
|
229
134
|
// Already off by default: omitting and disabling are the same request.
|
|
230
|
-
return
|
|
135
|
+
return defaultsToThinking ? { type: 'disabled' } : undefined;
|
|
231
136
|
}
|
|
232
137
|
if (policy === 'auto') {
|
|
233
138
|
return supportsAdaptiveThinking(model) ? adaptive : undefined;
|
|
@@ -239,7 +144,7 @@ function anthropicThinking(model, policy) {
|
|
|
239
144
|
return supportsAdaptiveThinking(model) ? adaptive : undefined;
|
|
240
145
|
}
|
|
241
146
|
// policy === undefined → the per-model default, unchanged.
|
|
242
|
-
return
|
|
147
|
+
return defaultsToThinking ? adaptive : undefined;
|
|
243
148
|
}
|
|
244
149
|
/**
|
|
245
150
|
* Whether the model accepts `output_config.effort`.
|
|
@@ -258,10 +163,7 @@ function anthropicThinking(model, policy) {
|
|
|
258
163
|
* it is confirmed to accept it.
|
|
259
164
|
*/
|
|
260
165
|
function supportsEffort(model) {
|
|
261
|
-
return
|
|
262
|
-
model === 'claude-opus-4-8' ||
|
|
263
|
-
model === 'claude-sonnet-5' ||
|
|
264
|
-
isClaude55(model));
|
|
166
|
+
return model === 'claude-fable-5' || model === 'claude-opus-4-8' || model === 'claude-sonnet-5';
|
|
265
167
|
}
|
|
266
168
|
/**
|
|
267
169
|
* `output_config.effort` for a graded policy.
|
|
@@ -281,11 +183,8 @@ const ANTHROPIC_EFFORT = {
|
|
|
281
183
|
max: 'max',
|
|
282
184
|
};
|
|
283
185
|
function anthropicEffort(model, policy) {
|
|
284
|
-
|
|
285
|
-
if (policy === undefined)
|
|
186
|
+
if (policy === undefined || policy === 'auto' || policy === 'off')
|
|
286
187
|
return undefined;
|
|
287
|
-
if (policy === 'auto' || policy === 'off')
|
|
288
|
-
return (_a = POLICY_EFFORT[model]) === null || _a === void 0 ? void 0 : _a[policy];
|
|
289
188
|
if (!supportsEffort(model) || !supportsAdaptiveThinking(model))
|
|
290
189
|
return undefined;
|
|
291
190
|
return ANTHROPIC_EFFORT[policy];
|
|
@@ -379,16 +278,13 @@ export class AnthropicTransport {
|
|
|
379
278
|
* outcome the type's own docs promise callers never happens.
|
|
380
279
|
*/
|
|
381
280
|
clampWarning(policy) {
|
|
382
|
-
var _a, _b;
|
|
383
281
|
switch (policy) {
|
|
384
282
|
case undefined:
|
|
385
283
|
return undefined;
|
|
386
284
|
case 'off':
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
? `AnthropicTransport: thinkingPolicy 'off' approximated — ${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.`
|
|
391
|
-
: `AnthropicTransport: thinkingPolicy 'off' ignored — ${this.model} always thinks and rejects an explicit disable. Reasoning tokens are still billed as output; switch model if you need them gone.`;
|
|
285
|
+
return thinkingIsMandatory(this.model)
|
|
286
|
+
? `AnthropicTransport: thinkingPolicy 'off' ignored — ${this.model} always thinks and rejects an explicit disable. Reasoning tokens are still billed as output; switch model if you need them gone.`
|
|
287
|
+
: undefined;
|
|
392
288
|
case 'auto':
|
|
393
289
|
return supportsAdaptiveThinking(this.model)
|
|
394
290
|
? undefined
|
|
@@ -399,7 +295,7 @@ export class AnthropicTransport {
|
|
|
399
295
|
case 'high':
|
|
400
296
|
case 'max':
|
|
401
297
|
if (!supportsAdaptiveThinking(this.model) || !supportsEffort(this.model)) {
|
|
402
|
-
return `AnthropicTransport: thinkingPolicy '${policy}' ignored — ${this.model} predates output_config.effort, so this turn runs at its default posture. Use Opus 4.8
|
|
298
|
+
return `AnthropicTransport: thinkingPolicy '${policy}' ignored — ${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.`;
|
|
403
299
|
}
|
|
404
300
|
// A clamp WITHIN the supported ladder is documented on the type (Anthropic has no
|
|
405
301
|
// 'minimal'), costs nothing, and would be noise on every turn of a vision loop.
|
|
@@ -411,7 +307,7 @@ export class AnthropicTransport {
|
|
|
411
307
|
}
|
|
412
308
|
}
|
|
413
309
|
constructor(config = {}) {
|
|
414
|
-
var _a, _b, _c, _d
|
|
310
|
+
var _a, _b, _c, _d;
|
|
415
311
|
/**
|
|
416
312
|
* Estimated USD cost accumulated across every successful request on this
|
|
417
313
|
* transport instance. Convenience accessor for non-chat consumers
|
|
@@ -430,8 +326,6 @@ export class AnthropicTransport {
|
|
|
430
326
|
* on this model. Latched, because it would otherwise fire on every turn of a tool loop.
|
|
431
327
|
*/
|
|
432
328
|
this.warnedThinkingClamped = false;
|
|
433
|
-
/** Set once the forced-tool-choice downgrade has been logged; see `downgradeForcedToolChoice`. */
|
|
434
|
-
this.warnedToolChoiceDowngraded = false;
|
|
435
329
|
/**
|
|
436
330
|
* Serving-model ids already reported as unrecognised. Per-id rather than a single flag, so a
|
|
437
331
|
* second unknown model is still announced. See {@link AnthropicTransport.servingModel}.
|
|
@@ -449,12 +343,6 @@ export class AnthropicTransport {
|
|
|
449
343
|
else if (model === 'claude-opus-4-7' || model === 'claude-opus-4-8') {
|
|
450
344
|
logger.warn(`AnthropicTransport: using ${model} — significantly higher cost; reserve for tasks where Sonnet reliability is insufficient.`);
|
|
451
345
|
}
|
|
452
|
-
else if (model === 'claude-opus-5-5') {
|
|
453
|
-
logger.warn('AnthropicTransport: using claude-opus-5-5 — Opus tier ($4 / $20 per MTok) with thinking always on (effort defaults to medium). Reserve for tasks where Sonnet reliability is insufficient.');
|
|
454
|
-
}
|
|
455
|
-
else if (model === 'claude-sonnet-5-5') {
|
|
456
|
-
logger.warn('AnthropicTransport: using claude-sonnet-5-5 — 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.');
|
|
457
|
-
}
|
|
458
346
|
else if (model === 'claude-fable-5') {
|
|
459
347
|
logger.warn('AnthropicTransport: using claude-fable-5 — 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 ≥30-day data retention (unavailable under ZDR) and may return stop_reason "refusal"; pair with an Opus 4.8 fallback.');
|
|
460
348
|
}
|
|
@@ -462,9 +350,7 @@ export class AnthropicTransport {
|
|
|
462
350
|
this.stallTimeout = (_c = config.stallTimeout) !== null && _c !== void 0 ? _c : DEFAULT_STALL_TIMEOUT;
|
|
463
351
|
this.apiKey = config.apiKey;
|
|
464
352
|
this.serverEndpoint = config.serverEndpoint;
|
|
465
|
-
this.maxTokens =
|
|
466
|
-
(_d = config.maxTokens) !== null && _d !== void 0 ? _d : (isClaude55(model) ? CLAUDE_55_DEFAULT_MAX_TOKENS : DEFAULT_MAX_TOKENS);
|
|
467
|
-
this.thinkingBlockBinding = (_e = config.thinkingBlockBinding) !== null && _e !== void 0 ? _e : 'drop_block';
|
|
353
|
+
this.maxTokens = (_d = config.maxTokens) !== null && _d !== void 0 ? _d : DEFAULT_MAX_TOKENS;
|
|
468
354
|
}
|
|
469
355
|
getConfig() {
|
|
470
356
|
return {
|
|
@@ -509,12 +395,6 @@ export class AnthropicTransport {
|
|
|
509
395
|
body.output_config = Object.assign(Object.assign({}, body.output_config), { format: { type: 'json_schema', schema: responseSchema } });
|
|
510
396
|
}
|
|
511
397
|
else if (useForcedTool) {
|
|
512
|
-
// Unreachable on a model that rejects forced tool use: every such model (Opus 5.5,
|
|
513
|
-
// Sonnet 5.5) has native structured output and takes the branch above. Asserted so a model
|
|
514
|
-
// added to one list but not the other fails loudly here rather than as a 400.
|
|
515
|
-
if (!supportsForcedToolChoice(this.model)) {
|
|
516
|
-
throw new Error(`AnthropicTransport: ${this.model} rejects forced tool_choice and must be listed in supportsNativeStructuredOutput.`);
|
|
517
|
-
}
|
|
518
398
|
body.tools = [
|
|
519
399
|
{
|
|
520
400
|
name: STRUCTURED_OUTPUT_TOOL_NAME,
|
|
@@ -524,16 +404,13 @@ export class AnthropicTransport {
|
|
|
524
404
|
];
|
|
525
405
|
body.tool_choice = { type: 'tool', name: STRUCTURED_OUTPUT_TOOL_NAME };
|
|
526
406
|
}
|
|
527
|
-
// Sonnet 5
|
|
528
|
-
//
|
|
529
|
-
//
|
|
530
|
-
//
|
|
531
|
-
//
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
if (defaultsToThinking(this.model) && !thinkingIsMandatory(this.model)) {
|
|
535
|
-
body.thinking = thinkingOff(this.model);
|
|
536
|
-
}
|
|
407
|
+
// Sonnet 5 runs adaptive thinking by default; disable it for one-shot prompts — the reasoning
|
|
408
|
+
// would be billed but discarded. Fable 5 runs thinking unconditionally (cannot be disabled — a
|
|
409
|
+
// 400), so it is left on; its summary is simply unused here. Not routed through
|
|
410
|
+
// `anthropicThinking`: this path wants the summary suppressed rather than returned, so a
|
|
411
|
+
// clamped Fable 5 must keep omitting the field rather than opting into `display:'summarized'`.
|
|
412
|
+
if (this.model === 'claude-sonnet-5')
|
|
413
|
+
body.thinking = { type: 'disabled' };
|
|
537
414
|
const response = yield this.post(body);
|
|
538
415
|
if (useForcedTool) {
|
|
539
416
|
const toolUse = ((_a = response.content) !== null && _a !== void 0 ? _a : []).find((b) => b.type === 'tool_use' && b.name === STRUCTURED_OUTPUT_TOOL_NAME);
|
|
@@ -549,7 +426,7 @@ export class AnthropicTransport {
|
|
|
549
426
|
// ── ChatTransport (multi-turn chat) ────────────────────────────────────
|
|
550
427
|
sendChatMessage(history, userMessage, options) {
|
|
551
428
|
return __awaiter(this, void 0, void 0, function* () {
|
|
552
|
-
var _a, _b, _c, _d, _e
|
|
429
|
+
var _a, _b, _c, _d, _e;
|
|
553
430
|
// The models this request could actually be served by — the configured one plus any
|
|
554
431
|
// fallback target. Needed when replaying reasoning: a signature is only valid for the
|
|
555
432
|
// model that produced it, so stored blocks are replayed only when their producer is
|
|
@@ -581,9 +458,11 @@ export class AnthropicTransport {
|
|
|
581
458
|
// Map the requested tool-call mode to Anthropic's tool_choice — only
|
|
582
459
|
// meaningful when tools exist. `'required'`/`{ tool }` force a tool call so
|
|
583
460
|
// a turn can only end via one (e.g. a sub-agent's completion tool).
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
461
|
+
if ((_d = body.tools) === null || _d === void 0 ? void 0 : _d.length) {
|
|
462
|
+
const toolChoice = toAnthropicToolChoice(options === null || options === void 0 ? void 0 : options.toolChoice);
|
|
463
|
+
if (toolChoice)
|
|
464
|
+
body.tool_choice = toolChoice;
|
|
465
|
+
}
|
|
587
466
|
// Extended thinking. Adaptive regardless of `tool_choice` — first-party has no
|
|
588
467
|
// forced-tool-vs-thinking restriction (that's Bedrock-only) and adaptive self-regulates on
|
|
589
468
|
// mechanical turns. The per-turn `thinkingPolicy` overrides the per-model default; an
|
|
@@ -591,7 +470,7 @@ export class AnthropicTransport {
|
|
|
591
470
|
this.warnIfThinkingUnclampable(options === null || options === void 0 ? void 0 : options.thinkingPolicy);
|
|
592
471
|
const thinking = anthropicThinking(this.model, options === null || options === void 0 ? void 0 : options.thinkingPolicy);
|
|
593
472
|
if (thinking)
|
|
594
|
-
body.thinking =
|
|
473
|
+
body.thinking = thinking;
|
|
595
474
|
// Reasoning DEPTH rides in `output_config.effort`, a different field from `thinking`.
|
|
596
475
|
// MERGED, never assigned: structured output writes `format` into the same object further
|
|
597
476
|
// down, and either write clobbering the other is silent — the request stays valid, it just
|
|
@@ -627,7 +506,7 @@ export class AnthropicTransport {
|
|
|
627
506
|
// Refusal fallback chain (e.g. Fable 5 → Opus 4.8). Sent as the server-side `fallbacks`
|
|
628
507
|
// param; `post` adds the required beta header when this is present. A refused turn is
|
|
629
508
|
// re-run on the next model in one round trip.
|
|
630
|
-
if ((
|
|
509
|
+
if ((_e = options === null || options === void 0 ? void 0 : options.fallbacks) === null || _e === void 0 ? void 0 : _e.length) {
|
|
631
510
|
body.fallbacks = options.fallbacks.map((f) => f.maxTokens != null ? { model: f.model, max_tokens: f.maxTokens } : { model: f.model });
|
|
632
511
|
}
|
|
633
512
|
// Place prompt-cache breakpoints per the resolved policy (no-op for `'default'`/absent).
|
|
@@ -635,83 +514,14 @@ export class AnthropicTransport {
|
|
|
635
514
|
this.applyCacheControl(body, options.cachePolicy);
|
|
636
515
|
}
|
|
637
516
|
// Inject never-stored tail context AFTER the cache breakpoints, so this per-turn volatile
|
|
638
|
-
// block stays outside the cached prefix. The caller has already framed it.
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
// family, invalidate every replayed thinking block whenever the tool choice changed.
|
|
642
|
-
const tail = [options === null || options === void 0 ? void 0 : options.tailContext, forcedToolNote].filter(Boolean).join('\n\n');
|
|
643
|
-
if (tail) {
|
|
644
|
-
this.appendTailContext(body, tail);
|
|
517
|
+
// block stays outside the cached prefix. The caller has already framed it.
|
|
518
|
+
if (options === null || options === void 0 ? void 0 : options.tailContext) {
|
|
519
|
+
this.appendTailContext(body, options.tailContext);
|
|
645
520
|
}
|
|
646
521
|
const response = yield this.post(body, options === null || options === void 0 ? void 0 : options.signal);
|
|
647
|
-
|
|
648
|
-
if (forcedToolNote && message.responseMeta) {
|
|
649
|
-
message.responseMeta.toolChoiceDowngraded = true;
|
|
650
|
-
}
|
|
651
|
-
return message;
|
|
522
|
+
return this.fromAnthropicResponse(response, body.max_tokens);
|
|
652
523
|
});
|
|
653
524
|
}
|
|
654
|
-
/**
|
|
655
|
-
* Set `tool_choice` from the caller's {@link ChatToolChoice}. `'required'`/`{ tool }` force a
|
|
656
|
-
* tool call so a turn can only end via one (e.g. a sub-agent's completion tool); on a model that
|
|
657
|
-
* rejects forcing they are downgraded (see `downgradeForcedToolChoice`), and the instruction
|
|
658
|
-
* that replaces them is returned for the tail.
|
|
659
|
-
*/
|
|
660
|
-
applyToolChoice(body, choice, tools) {
|
|
661
|
-
const toolChoice = toAnthropicToolChoice(choice);
|
|
662
|
-
if (!toolChoice)
|
|
663
|
-
return undefined;
|
|
664
|
-
const forced = toolChoice.type === 'any' || toolChoice.type === 'tool';
|
|
665
|
-
if (forced && !supportsForcedToolChoice(this.model)) {
|
|
666
|
-
return this.downgradeForcedToolChoice(body, toolChoice, tools);
|
|
667
|
-
}
|
|
668
|
-
body.tool_choice = toolChoice;
|
|
669
|
-
return undefined;
|
|
670
|
-
}
|
|
671
|
-
/**
|
|
672
|
-
* Preserved thinking (5.5 family): say what a changed history does to replayed thinking, rather
|
|
673
|
-
* than inheriting the account default (a 400 on accounts created on or after 2026-08-31).
|
|
674
|
-
* Adaptive only — `between_tools` and `disabled` reject the field — and a fresh object, so the
|
|
675
|
-
* shared `adaptive` constant in `anthropicThinking` is never mutated.
|
|
676
|
-
*/
|
|
677
|
-
withBlockBinding(thinking) {
|
|
678
|
-
if (thinking.type !== 'adaptive' ||
|
|
679
|
-
!sendsBlockBinding(this.model) ||
|
|
680
|
-
this.thinkingBlockBinding === 'omit') {
|
|
681
|
-
return thinking;
|
|
682
|
-
}
|
|
683
|
-
return Object.assign(Object.assign({}, thinking), { block_binding: { prefix_mismatch_behavior: this.thinkingBlockBinding } });
|
|
684
|
-
}
|
|
685
|
-
/**
|
|
686
|
-
* Stand-in for a forced tool call on a model that rejects `tool_choice` `any`/`tool` with a 400
|
|
687
|
-
* (Opus 5.5, Sonnet 5.5). The request goes out with `tool_choice` omitted (`auto`), and:
|
|
688
|
-
*
|
|
689
|
-
* - for a NAMED tool, that tool's schema is enforced (`strict: true`), so a call that does
|
|
690
|
-
* happen has valid arguments — the half of forcing that `auto` can still guarantee. Not done
|
|
691
|
-
* for `'required'`: enforcing every tool in a large surface can exceed the provider's
|
|
692
|
-
* per-request compilation limits, and a tool the caller enforced already carries it;
|
|
693
|
-
* - an instruction naming the tool is returned for the caller to append to the tail.
|
|
694
|
-
*
|
|
695
|
-
* `auto` lets the model answer in text instead, so the caller is told: a one-time warning here,
|
|
696
|
-
* and `responseMeta.toolChoiceDowngraded` on every affected response, which a driver uses to
|
|
697
|
-
* nudge and retry once when no tool was called.
|
|
698
|
-
*/
|
|
699
|
-
downgradeForcedToolChoice(body, toolChoice, tools) {
|
|
700
|
-
var _a, _b;
|
|
701
|
-
if (!this.warnedToolChoiceDowngraded) {
|
|
702
|
-
this.warnedToolChoiceDowngraded = true;
|
|
703
|
-
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 — check responseMeta.toolChoiceDowngraded.`);
|
|
704
|
-
}
|
|
705
|
-
if (toolChoice.type === 'tool' && toolChoice.name) {
|
|
706
|
-
const index = (_b = (_a = body.tools) === null || _a === void 0 ? void 0 : _a.findIndex((t) => t.name === toolChoice.name)) !== null && _b !== void 0 ? _b : -1;
|
|
707
|
-
const source = tools.find((t) => t.name === toolChoice.name);
|
|
708
|
-
if (index >= 0 && source && body.tools && !body.tools[index].strict) {
|
|
709
|
-
body.tools[index] = Object.assign(Object.assign({}, body.tools[index]), { input_schema: enforceAnthropicToolSchema(source.parameters, source.name), strict: true });
|
|
710
|
-
}
|
|
711
|
-
return `<system-reminder>Respond to this turn by calling the \`${toolChoice.name}\` tool. Do not reply with text alone.</system-reminder>`;
|
|
712
|
-
}
|
|
713
|
-
return '<system-reminder>Respond to this turn by calling one of your tools. Do not reply with text alone.</system-reminder>';
|
|
714
|
-
}
|
|
715
525
|
/**
|
|
716
526
|
* Place prompt-cache breakpoints on the outgoing request per the resolved {@link CachePolicy}.
|
|
717
527
|
* A breakpoint is `cache_control: {type:'ephemeral'}` on a content block / tool / system block;
|
|
@@ -1060,7 +870,7 @@ export class AnthropicTransport {
|
|
|
1060
870
|
fromAnthropicResponse(response,
|
|
1061
871
|
/** The cap ACTUALLY sent this turn — a per-turn `maxTokens` overrides the instance one. */
|
|
1062
872
|
effectiveMaxTokens = this.maxTokens) {
|
|
1063
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
873
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1064
874
|
let inputTokens;
|
|
1065
875
|
let outputTokens;
|
|
1066
876
|
let cacheReadTokens;
|
|
@@ -1246,16 +1056,6 @@ export class AnthropicTransport {
|
|
|
1246
1056
|
// Both now ride the same always-present object as every other reason.
|
|
1247
1057
|
if (response.stop_reason)
|
|
1248
1058
|
responseMeta.finishReason = response.stop_reason;
|
|
1249
|
-
// Preserved thinking: blocks the API dropped (or let through) because the conversation before
|
|
1250
|
-
// them changed. Surfaced so a harness can count which of its history edits cost reasoning;
|
|
1251
|
-
// an empty array — the healthy case — is left off.
|
|
1252
|
-
if ((_h = response.input_transformations) === null || _h === void 0 ? void 0 : _h.length) {
|
|
1253
|
-
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 } : {}))));
|
|
1254
|
-
const dropped = response.input_transformations.filter((t) => t.type === 'thinking_dropped');
|
|
1255
|
-
if (dropped.length) {
|
|
1256
|
-
logger.debug(`AnthropicTransport: ${dropped.length} thinking block(s) dropped by ${(_j = response.model) !== null && _j !== void 0 ? _j : this.model}: ${dropped.map((t) => { var _a, _b; return `${(_a = t.path) !== null && _a !== void 0 ? _a : '?'} (${(_b = t.reason) !== null && _b !== void 0 ? _b : 'unknown'})`; }).join(', ')}`);
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
1059
|
base.responseMeta = responseMeta;
|
|
1260
1060
|
return base;
|
|
1261
1061
|
}
|
|
@@ -1288,19 +1088,14 @@ export class AnthropicTransport {
|
|
|
1288
1088
|
}
|
|
1289
1089
|
post(body, signal) {
|
|
1290
1090
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1291
|
-
var _a
|
|
1091
|
+
var _a;
|
|
1292
1092
|
const { url, headers, credentials } = this.buildEndpoint();
|
|
1293
|
-
//
|
|
1294
|
-
//
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
? THINKING_BINDING_CONTROLS_BETA
|
|
1300
|
-
: undefined,
|
|
1301
|
-
].filter((b) => Boolean(b));
|
|
1302
|
-
const requestHeaders = betas.length
|
|
1303
|
-
? Object.assign(Object.assign({}, headers), { 'anthropic-beta': [headers['anthropic-beta'], ...betas].filter(Boolean).join(',') }) : headers;
|
|
1093
|
+
// The server-side `fallbacks` param is gated behind a beta flag; add it per-request only
|
|
1094
|
+
// when a fallback chain is set (the param without the header is a 400, and vice-versa is fine).
|
|
1095
|
+
const requestHeaders = ((_a = body.fallbacks) === null || _a === void 0 ? void 0 : _a.length)
|
|
1096
|
+
? Object.assign(Object.assign({}, headers), { 'anthropic-beta': [headers['anthropic-beta'], SERVER_SIDE_FALLBACK_BETA]
|
|
1097
|
+
.filter(Boolean)
|
|
1098
|
+
.join(',') }) : headers;
|
|
1304
1099
|
return (yield postWithRetry({
|
|
1305
1100
|
url,
|
|
1306
1101
|
headers: requestHeaders,
|
|
@@ -12,13 +12,10 @@ export const SUPPORTED_GEMINI_MODEL_IDS = [
|
|
|
12
12
|
/** @beta */
|
|
13
13
|
export const SUPPORTED_ANTHROPIC_MODEL_IDS = [
|
|
14
14
|
'claude-fable-5',
|
|
15
|
-
'claude-opus-5-5',
|
|
16
15
|
'claude-opus-4-8',
|
|
17
16
|
'claude-opus-4-7',
|
|
18
|
-
'claude-sonnet-5-5',
|
|
19
17
|
'claude-sonnet-5',
|
|
20
18
|
'claude-sonnet-4-6',
|
|
21
|
-
'claude-haiku-5-5',
|
|
22
19
|
'claude-haiku-4-5-20251001',
|
|
23
20
|
];
|
|
24
21
|
/** @beta */
|