@warlock.js/ai-anthropic 5.30.0 → 5.31.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/CHANGELOG.md +44 -6
- package/cjs/index.cjs +815 -132
- package/cjs/index.cjs.map +1 -1
- package/esm/config.type.d.mts +107 -4
- package/esm/config.type.d.mts.map +1 -1
- package/esm/index.d.mts +8 -3
- package/esm/index.mjs +7 -1
- package/esm/known-output-limits.mjs +46 -0
- package/esm/known-output-limits.mjs.map +1 -0
- package/esm/known-pricing.d.mts +58 -0
- package/esm/known-pricing.d.mts.map +1 -0
- package/esm/known-pricing.mjs +165 -0
- package/esm/known-pricing.mjs.map +1 -0
- package/esm/model.d.mts +89 -17
- package/esm/model.d.mts.map +1 -1
- package/esm/model.mjs +383 -86
- package/esm/model.mjs.map +1 -1
- package/esm/request.type.d.mts +25 -0
- package/esm/request.type.d.mts.map +1 -0
- package/esm/thinking-mode.d.mts +14 -1
- package/esm/thinking-mode.d.mts.map +1 -1
- package/esm/thinking-mode.mjs +102 -2
- package/esm/thinking-mode.mjs.map +1 -1
- package/esm/utils/cache-usage.mjs +62 -0
- package/esm/utils/cache-usage.mjs.map +1 -0
- package/esm/utils/index.d.mts +3 -0
- package/esm/utils/map-stop-reason.d.mts +1 -0
- package/esm/utils/provider-blocks.d.mts +39 -0
- package/esm/utils/provider-blocks.d.mts.map +1 -0
- package/esm/utils/to-anthropic-messages.d.mts +71 -0
- package/esm/utils/to-anthropic-messages.d.mts.map +1 -0
- package/esm/utils/to-anthropic-messages.mjs +12 -4
- package/esm/utils/to-anthropic-messages.mjs.map +1 -1
- package/esm/utils/to-anthropic-tools.d.mts +19 -0
- package/esm/utils/to-anthropic-tools.d.mts.map +1 -0
- package/esm/utils/wrap-anthropic-error.d.mts +1 -0
- package/esm/utils/wrap-anthropic-error.mjs +6 -1
- package/esm/utils/wrap-anthropic-error.mjs.map +1 -1
- package/llms-full.txt +214 -32
- package/llms.txt +1 -1
- package/package.json +3 -3
- package/skills/README.md +1 -1
- package/skills/setup-anthropic/SKILL.md +214 -32
package/esm/config.type.d.mts
CHANGED
|
@@ -58,6 +58,18 @@ type AnthropicModelConfig = ModelConfig & {
|
|
|
58
58
|
* deployments or capability-degraded testing.
|
|
59
59
|
*/
|
|
60
60
|
vision?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* The model's maximum output tokens, used to size the default
|
|
63
|
+
* `max_tokens` when no `maxTokens` is set. Inferred from known Claude
|
|
64
|
+
* ids (`known-output-limits.ts`: 128K for the Claude 5 family and
|
|
65
|
+
* Opus 4.6–4.8 / Sonnet 4.6, 64K for Opus / Sonnet / Haiku 4.5); set it
|
|
66
|
+
* for gateway or proxy ids the adapter does not recognise. Unknown ids
|
|
67
|
+
* default to 16384.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* anthropic.model({ name: "my-gateway/opus", maxOutputTokens: 128_000 });
|
|
71
|
+
*/
|
|
72
|
+
maxOutputTokens?: number;
|
|
61
73
|
/**
|
|
62
74
|
* Override the inferred `structuredOutput` capability. When omitted,
|
|
63
75
|
* the adapter treats the model as capable and forwards
|
|
@@ -124,6 +136,71 @@ type AnthropicModelConfig = ModelConfig & {
|
|
|
124
136
|
* anthropic.model({ name: "my-gateway/haiku", thinkingMode: "budget" });
|
|
125
137
|
*/
|
|
126
138
|
thinkingMode?: AnthropicThinkingMode;
|
|
139
|
+
/**
|
|
140
|
+
* Override whether the model runs Anthropic's preserved-thinking
|
|
141
|
+
* conversation check (a replayed thinking block is valid only while
|
|
142
|
+
* everything before it is unchanged). When omitted it is inferred from the
|
|
143
|
+
* model name: `true` for Claude Fable 5.1, Opus 5.5, Sonnet 5.5, Haiku 5.5
|
|
144
|
+
* and unknown ids on adaptive thinking; `false` for older models and every
|
|
145
|
+
* budget-mode model.
|
|
146
|
+
*
|
|
147
|
+
* When `true`, assistant turns that client-side compaction kept after its
|
|
148
|
+
* summary (`Message.compaction === "retained"`) are replayed without their
|
|
149
|
+
* thinking blocks, which were produced against the replaced history.
|
|
150
|
+
*/
|
|
151
|
+
preservedThinking?: boolean;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* `clear_tool_uses_20250919` context editing: the API replaces the oldest
|
|
155
|
+
* tool results with a placeholder once the prompt passes `trigger`. Omitted
|
|
156
|
+
* fields use the API defaults (trigger 100,000 input tokens, keep 3 tool
|
|
157
|
+
* uses; Anthropic docs, "Context editing", read 2026-10-17).
|
|
158
|
+
*/
|
|
159
|
+
type AnthropicClearToolUses = {
|
|
160
|
+
/** When clearing starts: an input-token count or a tool-use count. */trigger?: {
|
|
161
|
+
inputTokens: number;
|
|
162
|
+
} | {
|
|
163
|
+
toolUses: number;
|
|
164
|
+
}; /** How many of the most recent tool uses keep their results. */
|
|
165
|
+
keep?: number; /** Apply only when at least this many input tokens can be cleared. */
|
|
166
|
+
clearAtLeast?: number; /** Tool names whose uses and results are never cleared. */
|
|
167
|
+
excludeTools?: string[]; /** Also clear the tool-use inputs: `true` for every tool, or a list of tool names. */
|
|
168
|
+
clearToolInputs?: boolean | string[];
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* `clear_thinking_20251015` context editing: keep thinking blocks for only
|
|
172
|
+
* the most recent `keep` assistant turns, or `"all"`. Omitted, the
|
|
173
|
+
* model's default applies (keep all on Opus 4.5+, Sonnet 4.6+, Haiku 5.5 and
|
|
174
|
+
* the Fable / Mythos models; last turn only on older ones).
|
|
175
|
+
*/
|
|
176
|
+
type AnthropicClearThinking = {
|
|
177
|
+
keep?: number | "all";
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Typed Anthropic context editing (beta `context-management-2025-06-27`,
|
|
181
|
+
* added automatically). Server-side edits don't count as history edits for
|
|
182
|
+
* preserved thinking: the API checks the conversation as you sent it.
|
|
183
|
+
*/
|
|
184
|
+
type AnthropicContextManagement = {
|
|
185
|
+
/** Clear old tool results. `true` uses the API defaults. */clearToolUses?: true | AnthropicClearToolUses; /** Clear thinking blocks from older turns. `true` uses the model default. */
|
|
186
|
+
clearThinking?: true | AnthropicClearThinking;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Server-side compaction at a token threshold (`compact_20260112`, beta
|
|
190
|
+
* `compact-2026-01-12`, added automatically). When the prompt reaches
|
|
191
|
+
* `triggerTokens` the API summarizes earlier context into a `compaction`
|
|
192
|
+
* block at the start of the response; the agent keeps it on the turn's
|
|
193
|
+
* `blocks` and the next request sends it back, so the API drops what came
|
|
194
|
+
* before it. Source: Anthropic docs, "Compaction at a token threshold",
|
|
195
|
+
* read 2026-10-17.
|
|
196
|
+
*/
|
|
197
|
+
type AnthropicServerCompaction = {
|
|
198
|
+
/** Input tokens that trigger compaction. At least 50,000; API default 150,000. */triggerTokens?: number;
|
|
199
|
+
/**
|
|
200
|
+
* Replaces the default summarization prompt entirely. When the request has
|
|
201
|
+
* tools, say "do not call any tools", or the summary step may call one.
|
|
202
|
+
*/
|
|
203
|
+
instructions?: string;
|
|
127
204
|
};
|
|
128
205
|
/**
|
|
129
206
|
* Anthropic-only request options, passed per call (or through the agent's
|
|
@@ -132,14 +209,14 @@ type AnthropicModelConfig = ModelConfig & {
|
|
|
132
209
|
* fallback chain.
|
|
133
210
|
*
|
|
134
211
|
* @example
|
|
135
|
-
* // Server-side compaction (
|
|
212
|
+
* // Server-side compaction and tool-result clearing (betas added for you).
|
|
136
213
|
* const agent = ai.agent({
|
|
137
214
|
* model: anthropic.model({ name: "claude-opus-5-5" }),
|
|
138
215
|
* modelOptions: {
|
|
139
216
|
* providerOptions: {
|
|
140
217
|
* anthropic: {
|
|
141
|
-
*
|
|
142
|
-
*
|
|
218
|
+
* serverCompaction: { triggerTokens: 200_000 },
|
|
219
|
+
* contextManagement: { clearToolUses: { trigger: { inputTokens: 100_000 }, keep: 5 } },
|
|
143
220
|
* },
|
|
144
221
|
* },
|
|
145
222
|
* },
|
|
@@ -187,7 +264,33 @@ type AnthropicCallOptions = {
|
|
|
187
264
|
* is enough). Ignored on budget-mode models.
|
|
188
265
|
*/
|
|
189
266
|
thinkingDisplay?: "summarized" | "omitted" | "updates";
|
|
267
|
+
/**
|
|
268
|
+
* Typed context editing: clear old tool results and/or old thinking
|
|
269
|
+
* blocks server-side. Adds `context_management.edits` and the
|
|
270
|
+
* `context-management-2025-06-27` beta. Cannot be combined with a
|
|
271
|
+
* `context_management` field in `body`.
|
|
272
|
+
*/
|
|
273
|
+
contextManagement?: AnthropicContextManagement;
|
|
274
|
+
/**
|
|
275
|
+
* Server-side compaction at a token threshold: `true` for the API
|
|
276
|
+
* defaults, or `{ triggerTokens, instructions }`. Adds the
|
|
277
|
+
* `compact_20260112` edit and the `compact-2026-01-12` beta. Cannot be
|
|
278
|
+
* combined with a `context_management` field in `body`.
|
|
279
|
+
*/
|
|
280
|
+
serverCompaction?: boolean | AnthropicServerCompaction;
|
|
281
|
+
/**
|
|
282
|
+
* `thinking.block_binding.prefix_mismatch_behavior` (beta
|
|
283
|
+
* `thinking-binding-controls-2026-08-01`, added automatically): what the
|
|
284
|
+
* API does with a replayed thinking block whose conversation changed —
|
|
285
|
+
* `"error"` (a 400) or `"drop_block"` (drop it and every later one,
|
|
286
|
+
* reported in `input_transformations`). Use `"drop_block"` to recover a
|
|
287
|
+
* stored conversation that was edited. Applied to adaptive and
|
|
288
|
+
* budget-mode thinking; ignored, with a debug log, when the request sends
|
|
289
|
+
* thinking in another shape. While set, retained turns are replayed with
|
|
290
|
+
* their thinking blocks and the API decides.
|
|
291
|
+
*/
|
|
292
|
+
thinkingBlockBinding?: "error" | "drop_block";
|
|
190
293
|
};
|
|
191
294
|
//#endregion
|
|
192
|
-
export { AnthropicCallOptions, AnthropicModelConfig, AnthropicSDKConfig };
|
|
295
|
+
export { AnthropicCallOptions, AnthropicClearThinking, AnthropicClearToolUses, AnthropicContextManagement, AnthropicModelConfig, AnthropicSDKConfig, AnthropicServerCompaction };
|
|
193
296
|
//# sourceMappingURL=config.type.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.type.d.mts","names":[],"sources":["../../../../../../../packages/ai-anthropic/src/config.type.ts"],"mappings":";;;;;;;AAiCA;;;;;;;;;;;;;;AAOuC;AAWvC;;;;;;;;;;;;KAlBY,kBAAA,GAAqB,aAAA;EAC/B,QAAA;
|
|
1
|
+
{"version":3,"file":"config.type.d.mts","names":[],"sources":["../../../../../../../packages/ai-anthropic/src/config.type.ts"],"mappings":";;;;;;;AAiCA;;;;;;;;;;;;;;AAOuC;AAWvC;;;;;;;;;;;;KAlBY,kBAAA,GAAqB,aAAA;EAC/B,QAAA;EAoHiB;AAAA;AASnB;;;EAvHE,OAAA,GAAU,MAAA,SAAe,YAAA;AAAA;;;;;;;;AAiIV;KAtHL,oBAAA,GAAuB,WAAA;EA+HD;;;AAAS;AAO3C;;;EA9HE,MAAA;EAgIA;;;;;AAE6C;AAY/C;;;;AAOc;EAzIZ,eAAA;EA6K8B;;;;;;;;EApK9B,gBAAA;EAqLO;;;;;;;;AAqCa;;;;;;;;;;;;EArMpB,aAAA;;;;;;;;EAQA,cAAA;;;;;;;;;;EAUA,SAAA;;;;;;;;;;;;;;;;;;EAkBA,YAAA,GAAe,qBAAqB;;;;;;;;;;;;;EAapC,iBAAA;AAAA;;;;;;;KASU,sBAAA;wEAEV,OAAA;IAAY,WAAA;EAAA;IAA0B,QAAA;EAAA;EAEtC,IAAA;EAEA,YAAA;EAEA,YAAA;EAEA,eAAA;AAAA;;;;;;;KASU,sBAAA;EAA2B,IAAI;AAAA;;;;;;KAO/B,0BAAA;8DAEV,aAAA,UAAuB,sBAAA;EAEvB,aAAA,UAAuB,sBAAsB;AAAA;;;;;;;;;;KAYnC,yBAAA;oFAEV,aAAA;;;;;EAKA,YAAY;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoCF,oBAAA;;;;;;;EAOV,KAAA;;;;;;;;;;EAUA,IAAA,GAAO,MAAA;;;;;;;;;;;EAWP,eAAA;;;;;;;EAOA,iBAAA,GAAoB,0BAAA;;;;;;;EAOpB,gBAAA,aAA6B,yBAAA;;;;;;;;;;;;EAY7B,oBAAA;AAAA"}
|
package/esm/index.d.mts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import { AnthropicThinkingMode } from "./thinking-mode.mjs";
|
|
2
|
-
import { AnthropicCallOptions, AnthropicModelConfig, AnthropicSDKConfig } from "./config.type.mjs";
|
|
1
|
+
import { AnthropicThinkingMode, inferPreservedThinking } from "./thinking-mode.mjs";
|
|
2
|
+
import { AnthropicCallOptions, AnthropicClearThinking, AnthropicClearToolUses, AnthropicContextManagement, AnthropicModelConfig, AnthropicSDKConfig, AnthropicServerCompaction } from "./config.type.mjs";
|
|
3
|
+
import { AnthropicNonStreamingRequest, AnthropicRequest, AnthropicRequestOptions, AnthropicStreamingRequest } from "./request.type.mjs";
|
|
3
4
|
import { AnthropicModel } from "./model.mjs";
|
|
4
5
|
import { AnthropicSDK } from "./sdk.mjs";
|
|
5
|
-
|
|
6
|
+
import { ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_MULTIPLIER, ANTHROPIC_MODEL_PRICING, anthropicPricingFor, withAnthropicCacheWriteRates } from "./known-pricing.mjs";
|
|
7
|
+
import { ANTHROPIC_BLOCK_FORMAT, fromProviderBlocks, toProviderBlocks } from "./utils/provider-blocks.mjs";
|
|
8
|
+
import { AnthropicMessages, ToAnthropicMessagesOptions, toAnthropicMessages } from "./utils/to-anthropic-messages.mjs";
|
|
9
|
+
import { toAnthropicTools } from "./utils/to-anthropic-tools.mjs";
|
|
10
|
+
export { ANTHROPIC_BLOCK_FORMAT, ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_MULTIPLIER, ANTHROPIC_MODEL_PRICING, type AnthropicCallOptions, type AnthropicClearThinking, type AnthropicClearToolUses, type AnthropicContextManagement, type AnthropicMessages, AnthropicModel, type AnthropicModelConfig, type AnthropicNonStreamingRequest, type AnthropicRequest, type AnthropicRequestOptions, AnthropicSDK, type AnthropicSDKConfig, type AnthropicServerCompaction, type AnthropicStreamingRequest, type AnthropicThinkingMode, type ToAnthropicMessagesOptions, anthropicPricingFor, fromProviderBlocks, inferPreservedThinking, toAnthropicMessages, toAnthropicTools, toProviderBlocks, withAnthropicCacheWriteRates };
|
package/esm/index.mjs
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
import { ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_MULTIPLIER, ANTHROPIC_MODEL_PRICING, anthropicPricingFor, withAnthropicCacheWriteRates } from "./known-pricing.mjs";
|
|
2
|
+
import { inferPreservedThinking } from "./thinking-mode.mjs";
|
|
3
|
+
import { ANTHROPIC_BLOCK_FORMAT, fromProviderBlocks, toProviderBlocks } from "./utils/provider-blocks.mjs";
|
|
4
|
+
import { toAnthropicMessages } from "./utils/to-anthropic-messages.mjs";
|
|
5
|
+
import { toAnthropicTools } from "./utils/to-anthropic-tools.mjs";
|
|
6
|
+
import "./utils/index.mjs";
|
|
1
7
|
import { AnthropicModel } from "./model.mjs";
|
|
2
8
|
import { AnthropicSDK } from "./sdk.mjs";
|
|
3
9
|
|
|
4
|
-
export { AnthropicModel, AnthropicSDK };
|
|
10
|
+
export { ANTHROPIC_BLOCK_FORMAT, ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_MULTIPLIER, ANTHROPIC_MODEL_PRICING, AnthropicModel, AnthropicSDK, anthropicPricingFor, fromProviderBlocks, inferPreservedThinking, toAnthropicMessages, toAnthropicTools, toProviderBlocks, withAnthropicCacheWriteRates };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { matchesReleaseRoot } from "./thinking-mode.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../packages/ai-anthropic/src/known-output-limits.ts
|
|
4
|
+
/** Family prefixes whose every release has a 128K output limit. */
|
|
5
|
+
const FAMILY_128K_PREFIXES = [
|
|
6
|
+
"claude-fable-5",
|
|
7
|
+
"claude-mythos-5",
|
|
8
|
+
"claude-opus-5",
|
|
9
|
+
"claude-sonnet-5",
|
|
10
|
+
"claude-haiku-5"
|
|
11
|
+
];
|
|
12
|
+
/** Individual releases, matched as a release root (dated / `@` variants included). */
|
|
13
|
+
const RELEASE_OUTPUT_LIMITS = [
|
|
14
|
+
["claude-opus-4-8", 128e3],
|
|
15
|
+
["claude-opus-4-7", 128e3],
|
|
16
|
+
["claude-opus-4-6", 128e3],
|
|
17
|
+
["claude-sonnet-4-6", 128e3],
|
|
18
|
+
["claude-opus-4-5", 64e3],
|
|
19
|
+
["claude-sonnet-4-5", 64e3],
|
|
20
|
+
["claude-haiku-4-5", 64e3]
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* The documented maximum output tokens of a Claude model, or `undefined`
|
|
24
|
+
* when the id is not a known Claude model. Platform prefixes before
|
|
25
|
+
* `claude-` (`anthropic.`, `us.anthropic.`) and dated or `@` snapshot
|
|
26
|
+
* suffixes are accepted, so the Bedrock / Google Cloud ids of a known
|
|
27
|
+
* model resolve too. Override per model with
|
|
28
|
+
* `anthropic.model({ name, maxOutputTokens })`.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* inferMaxOutputTokens("claude-opus-5-5"); // → 128000
|
|
32
|
+
* inferMaxOutputTokens("claude-haiku-4-5-20251001"); // → 64000
|
|
33
|
+
* inferMaxOutputTokens("my-gateway/model"); // → undefined
|
|
34
|
+
*/
|
|
35
|
+
function inferMaxOutputTokens(modelName) {
|
|
36
|
+
const lowered = modelName.toLowerCase();
|
|
37
|
+
const start = lowered.indexOf("claude-");
|
|
38
|
+
if (start === -1) return;
|
|
39
|
+
const normalized = lowered.slice(start);
|
|
40
|
+
if (FAMILY_128K_PREFIXES.some((prefix) => normalized.startsWith(prefix))) return 128e3;
|
|
41
|
+
for (const [root, limit] of RELEASE_OUTPUT_LIMITS) if (matchesReleaseRoot(normalized, root)) return limit;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { inferMaxOutputTokens };
|
|
46
|
+
//# sourceMappingURL=known-output-limits.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"known-output-limits.mjs","names":[],"sources":["../../../../../../../packages/ai-anthropic/src/known-output-limits.ts"],"sourcesContent":["import { matchesReleaseRoot } from \"./thinking-mode\";\n\n/*\n * Documented maximum output tokens (`max_tokens`) on the synchronous\n * Messages API. Source: Anthropic's model pages and models overview,\n * platform.claude.com/docs/en/about-claude/models/overview and\n * …/models/{opus-4-5,sonnet-4-5,haiku-4-5}/overview, checked 2026-10-17.\n *\n * | Model ids | Max output |\n * |--------------------------------------------------------------|------------|\n * | Claude 5 family: fable-5 / 5.1, mythos-5 / 5.1, opus-5 / 5.5, | 128K |\n * | sonnet-5 / 5.5, haiku-5-5 | |\n * | claude-opus-4-8, claude-opus-4-7, claude-opus-4-6, | 128K |\n * | claude-sonnet-4-6 | |\n * | claude-opus-4-5, claude-sonnet-4-5, claude-haiku-4-5 | 64K |\n *\n * Older models (Claude 3.x, Opus 4 / 4.1, Sonnet 4) are retired and have no\n * entry; like any id not listed they fall back to the adapter default.\n */\n\n/** Family prefixes whose every release has a 128K output limit. */\nconst FAMILY_128K_PREFIXES = [\n \"claude-fable-5\",\n \"claude-mythos-5\",\n \"claude-opus-5\",\n \"claude-sonnet-5\",\n \"claude-haiku-5\",\n];\n\n/** Individual releases, matched as a release root (dated / `@` variants included). */\nconst RELEASE_OUTPUT_LIMITS: ReadonlyArray<readonly [root: string, limit: number]> = [\n [\"claude-opus-4-8\", 128_000],\n [\"claude-opus-4-7\", 128_000],\n [\"claude-opus-4-6\", 128_000],\n [\"claude-sonnet-4-6\", 128_000],\n [\"claude-opus-4-5\", 64_000],\n [\"claude-sonnet-4-5\", 64_000],\n [\"claude-haiku-4-5\", 64_000],\n];\n\n/**\n * The documented maximum output tokens of a Claude model, or `undefined`\n * when the id is not a known Claude model. Platform prefixes before\n * `claude-` (`anthropic.`, `us.anthropic.`) and dated or `@` snapshot\n * suffixes are accepted, so the Bedrock / Google Cloud ids of a known\n * model resolve too. Override per model with\n * `anthropic.model({ name, maxOutputTokens })`.\n *\n * @example\n * inferMaxOutputTokens(\"claude-opus-5-5\"); // → 128000\n * inferMaxOutputTokens(\"claude-haiku-4-5-20251001\"); // → 64000\n * inferMaxOutputTokens(\"my-gateway/model\"); // → undefined\n */\nexport function inferMaxOutputTokens(modelName: string): number | undefined {\n const lowered = modelName.toLowerCase();\n const start = lowered.indexOf(\"claude-\");\n\n if (start === -1) {\n return undefined;\n }\n\n const normalized = lowered.slice(start);\n\n if (FAMILY_128K_PREFIXES.some((prefix) => normalized.startsWith(prefix))) {\n return 128_000;\n }\n\n for (const [root, limit] of RELEASE_OUTPUT_LIMITS) {\n if (matchesReleaseRoot(normalized, root)) {\n return limit;\n }\n }\n\n return undefined;\n}\n"],"mappings":";;;;AAqBA,MAAM,uBAAuB;CAC3B;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAM,wBAA+E;CACnF,CAAC,mBAAmB,KAAO;CAC3B,CAAC,mBAAmB,KAAO;CAC3B,CAAC,mBAAmB,KAAO;CAC3B,CAAC,qBAAqB,KAAO;CAC7B,CAAC,mBAAmB,IAAM;CAC1B,CAAC,qBAAqB,IAAM;CAC5B,CAAC,oBAAoB,IAAM;AAC7B;;;;;;;;;;;;;;AAeA,SAAgB,qBAAqB,WAAuC;CAC1E,MAAM,UAAU,UAAU,YAAY;CACtC,MAAM,QAAQ,QAAQ,QAAQ,SAAS;CAEvC,IAAI,UAAU,IACZ;CAGF,MAAM,aAAa,QAAQ,MAAM,KAAK;CAEtC,IAAI,qBAAqB,MAAM,WAAW,WAAW,WAAW,MAAM,CAAC,GACrE,OAAO;CAGT,KAAK,MAAM,CAAC,MAAM,UAAU,uBAC1B,IAAI,mBAAmB,YAAY,IAAI,GACrC,OAAO;AAKb"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ModelPricing } from "@warlock.js/ai";
|
|
2
|
+
|
|
3
|
+
//#region ../../packages/ai-anthropic/src/known-pricing.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Anthropic's prompt-cache write multipliers, relative to the base input
|
|
6
|
+
* rate: a 5-minute write costs 1.25x, a 1-hour write 2x. They hold for
|
|
7
|
+
* every Claude model on Anthropic's price list.
|
|
8
|
+
*
|
|
9
|
+
* Source: https://platform.claude.com/docs/en/about-claude/pricing
|
|
10
|
+
* (fetched 2026-10-17).
|
|
11
|
+
*/
|
|
12
|
+
declare const ANTHROPIC_CACHE_WRITE_MULTIPLIER = 1.25;
|
|
13
|
+
declare const ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER = 2;
|
|
14
|
+
/**
|
|
15
|
+
* Built-in Claude API list prices, USD per 1,000,000 tokens, keyed by
|
|
16
|
+
* model id. `cachedInput` is the cache-hit rate, `cacheWrite` the
|
|
17
|
+
* 5-minute write rate and `cacheWrite1h` the 1-hour write rate.
|
|
18
|
+
*
|
|
19
|
+
* Source: https://platform.claude.com/docs/en/about-claude/pricing,
|
|
20
|
+
* "Model pricing" table, fetched 2026-10-17. Standard (global) routing,
|
|
21
|
+
* non-batch. Not covered, so pass `pricing` yourself when you need them:
|
|
22
|
+
*
|
|
23
|
+
* - Claude Haiku 5.5 — priced by prompt length (higher rates above
|
|
24
|
+
* 100,000 prompt tokens), which a flat `ModelPricing` cannot express.
|
|
25
|
+
* - US-only inference (`inference_geo: "us"`, 1.1x), fast mode, the Batch
|
|
26
|
+
* API, and Claude on Bedrock / Vertex AI (partner-priced).
|
|
27
|
+
* - Limited-availability models (Mythos) and retired models.
|
|
28
|
+
*
|
|
29
|
+
* Dated snapshot ids (`claude-haiku-4-5-20251001`) resolve to their alias
|
|
30
|
+
* entry through {@link anthropicPricingFor}.
|
|
31
|
+
*/
|
|
32
|
+
declare const ANTHROPIC_MODEL_PRICING: Readonly<Record<string, ModelPricing>>;
|
|
33
|
+
/**
|
|
34
|
+
* Look up the built-in list price for a Claude model id. Accepts the
|
|
35
|
+
* alias (`claude-sonnet-4-5`) or a dated snapshot
|
|
36
|
+
* (`claude-sonnet-4-5-20250929`). Returns `undefined` for any id not in
|
|
37
|
+
* {@link ANTHROPIC_MODEL_PRICING}, so cost stays unknown rather than wrong.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* anthropicPricingFor("claude-haiku-4-5-20251001"); // { input: 1, output: 5, … }
|
|
41
|
+
* anthropicPricingFor("claude-haiku-5-5"); // undefined (prompt-length tiers)
|
|
42
|
+
*/
|
|
43
|
+
declare function anthropicPricingFor(modelName: string): ModelPricing | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Fill the cache-write rates Anthropic derives from the input rate
|
|
46
|
+
* (5-minute writes 1.25x, 1-hour writes 2x) into a pricing entry that
|
|
47
|
+
* omits them, so a caller who supplies only `{ input, output }` is no
|
|
48
|
+
* longer billed nothing for cache writes. Explicit rates always win; the
|
|
49
|
+
* cache-read rate is left alone because it differs per model.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* withAnthropicCacheWriteRates({ input: 3, output: 15 });
|
|
53
|
+
* // { input: 3, output: 15, cacheWrite: 3.75, cacheWrite1h: 6 }
|
|
54
|
+
*/
|
|
55
|
+
declare function withAnthropicCacheWriteRates(pricing: ModelPricing | undefined): ModelPricing | undefined;
|
|
56
|
+
//#endregion
|
|
57
|
+
export { ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_MULTIPLIER, ANTHROPIC_MODEL_PRICING, anthropicPricingFor, withAnthropicCacheWriteRates };
|
|
58
|
+
//# sourceMappingURL=known-pricing.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"known-pricing.d.mts","names":[],"sources":["../../../../../../../packages/ai-anthropic/src/known-pricing.ts"],"mappings":";;;;;AAUA;;;;AAA6C;AAC7C;cADa,gCAAA;AAAA,cACA,mCAAA;;AAAmC;AAoBhD;;;;;;;;;;;;AAA0E;AA+C1E;;;cA/Ca,uBAAA,EAAyB,QAAA,CAAS,MAAA,SAAe,YAAA;AA+CM;AAqBpE;;;;;;;;AAEe;AAvBqD,iBAApD,mBAAA,CAAoB,SAAA,WAAoB,YAAY;;;;;;;;;;;;iBAqBpD,4BAAA,CACd,OAAA,EAAS,YAAA,eACR,YAAY"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
//#region ../../packages/ai-anthropic/src/known-pricing.ts
|
|
2
|
+
/**
|
|
3
|
+
* Anthropic's prompt-cache write multipliers, relative to the base input
|
|
4
|
+
* rate: a 5-minute write costs 1.25x, a 1-hour write 2x. They hold for
|
|
5
|
+
* every Claude model on Anthropic's price list.
|
|
6
|
+
*
|
|
7
|
+
* Source: https://platform.claude.com/docs/en/about-claude/pricing
|
|
8
|
+
* (fetched 2026-10-17).
|
|
9
|
+
*/
|
|
10
|
+
const ANTHROPIC_CACHE_WRITE_MULTIPLIER = 1.25;
|
|
11
|
+
const ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER = 2;
|
|
12
|
+
/**
|
|
13
|
+
* Built-in Claude API list prices, USD per 1,000,000 tokens, keyed by
|
|
14
|
+
* model id. `cachedInput` is the cache-hit rate, `cacheWrite` the
|
|
15
|
+
* 5-minute write rate and `cacheWrite1h` the 1-hour write rate.
|
|
16
|
+
*
|
|
17
|
+
* Source: https://platform.claude.com/docs/en/about-claude/pricing,
|
|
18
|
+
* "Model pricing" table, fetched 2026-10-17. Standard (global) routing,
|
|
19
|
+
* non-batch. Not covered, so pass `pricing` yourself when you need them:
|
|
20
|
+
*
|
|
21
|
+
* - Claude Haiku 5.5 — priced by prompt length (higher rates above
|
|
22
|
+
* 100,000 prompt tokens), which a flat `ModelPricing` cannot express.
|
|
23
|
+
* - US-only inference (`inference_geo: "us"`, 1.1x), fast mode, the Batch
|
|
24
|
+
* API, and Claude on Bedrock / Vertex AI (partner-priced).
|
|
25
|
+
* - Limited-availability models (Mythos) and retired models.
|
|
26
|
+
*
|
|
27
|
+
* Dated snapshot ids (`claude-haiku-4-5-20251001`) resolve to their alias
|
|
28
|
+
* entry through {@link anthropicPricingFor}.
|
|
29
|
+
*/
|
|
30
|
+
const ANTHROPIC_MODEL_PRICING = {
|
|
31
|
+
"claude-fable-5-1": {
|
|
32
|
+
input: 10,
|
|
33
|
+
output: 50,
|
|
34
|
+
cachedInput: .25,
|
|
35
|
+
cacheWrite: 12.5,
|
|
36
|
+
cacheWrite1h: 20
|
|
37
|
+
},
|
|
38
|
+
"claude-fable-5": {
|
|
39
|
+
input: 10,
|
|
40
|
+
output: 50,
|
|
41
|
+
cachedInput: 1,
|
|
42
|
+
cacheWrite: 12.5,
|
|
43
|
+
cacheWrite1h: 20
|
|
44
|
+
},
|
|
45
|
+
"claude-opus-5-5": {
|
|
46
|
+
input: 4,
|
|
47
|
+
output: 20,
|
|
48
|
+
cachedInput: .2,
|
|
49
|
+
cacheWrite: 5,
|
|
50
|
+
cacheWrite1h: 8
|
|
51
|
+
},
|
|
52
|
+
"claude-opus-5": {
|
|
53
|
+
input: 5,
|
|
54
|
+
output: 25,
|
|
55
|
+
cachedInput: .5,
|
|
56
|
+
cacheWrite: 6.25,
|
|
57
|
+
cacheWrite1h: 10
|
|
58
|
+
},
|
|
59
|
+
"claude-opus-4-8": {
|
|
60
|
+
input: 5,
|
|
61
|
+
output: 25,
|
|
62
|
+
cachedInput: .5,
|
|
63
|
+
cacheWrite: 6.25,
|
|
64
|
+
cacheWrite1h: 10
|
|
65
|
+
},
|
|
66
|
+
"claude-opus-4-7": {
|
|
67
|
+
input: 5,
|
|
68
|
+
output: 25,
|
|
69
|
+
cachedInput: .5,
|
|
70
|
+
cacheWrite: 6.25,
|
|
71
|
+
cacheWrite1h: 10
|
|
72
|
+
},
|
|
73
|
+
"claude-opus-4-6": {
|
|
74
|
+
input: 5,
|
|
75
|
+
output: 25,
|
|
76
|
+
cachedInput: .5,
|
|
77
|
+
cacheWrite: 6.25,
|
|
78
|
+
cacheWrite1h: 10
|
|
79
|
+
},
|
|
80
|
+
"claude-opus-4-5": {
|
|
81
|
+
input: 5,
|
|
82
|
+
output: 25,
|
|
83
|
+
cachedInput: .5,
|
|
84
|
+
cacheWrite: 6.25,
|
|
85
|
+
cacheWrite1h: 10
|
|
86
|
+
},
|
|
87
|
+
"claude-sonnet-5-5": {
|
|
88
|
+
input: 2,
|
|
89
|
+
output: 10,
|
|
90
|
+
cachedInput: .1,
|
|
91
|
+
cacheWrite: 2.5,
|
|
92
|
+
cacheWrite1h: 4
|
|
93
|
+
},
|
|
94
|
+
"claude-sonnet-5": {
|
|
95
|
+
input: 2,
|
|
96
|
+
output: 10,
|
|
97
|
+
cachedInput: .2,
|
|
98
|
+
cacheWrite: 2.5,
|
|
99
|
+
cacheWrite1h: 4
|
|
100
|
+
},
|
|
101
|
+
"claude-sonnet-4-6": {
|
|
102
|
+
input: 3,
|
|
103
|
+
output: 15,
|
|
104
|
+
cachedInput: .3,
|
|
105
|
+
cacheWrite: 3.75,
|
|
106
|
+
cacheWrite1h: 6
|
|
107
|
+
},
|
|
108
|
+
"claude-sonnet-4-5": {
|
|
109
|
+
input: 3,
|
|
110
|
+
output: 15,
|
|
111
|
+
cachedInput: .3,
|
|
112
|
+
cacheWrite: 3.75,
|
|
113
|
+
cacheWrite1h: 6
|
|
114
|
+
},
|
|
115
|
+
"claude-haiku-4-5": {
|
|
116
|
+
input: 1,
|
|
117
|
+
output: 5,
|
|
118
|
+
cachedInput: .1,
|
|
119
|
+
cacheWrite: 1.25,
|
|
120
|
+
cacheWrite1h: 2
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
/** A trailing `-YYYYMMDD` snapshot date on a Claude model id. */
|
|
124
|
+
const SNAPSHOT_SUFFIX = /-\d{8}$/;
|
|
125
|
+
/**
|
|
126
|
+
* Look up the built-in list price for a Claude model id. Accepts the
|
|
127
|
+
* alias (`claude-sonnet-4-5`) or a dated snapshot
|
|
128
|
+
* (`claude-sonnet-4-5-20250929`). Returns `undefined` for any id not in
|
|
129
|
+
* {@link ANTHROPIC_MODEL_PRICING}, so cost stays unknown rather than wrong.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* anthropicPricingFor("claude-haiku-4-5-20251001"); // { input: 1, output: 5, … }
|
|
133
|
+
* anthropicPricingFor("claude-haiku-5-5"); // undefined (prompt-length tiers)
|
|
134
|
+
*/
|
|
135
|
+
function anthropicPricingFor(modelName) {
|
|
136
|
+
const exact = ANTHROPIC_MODEL_PRICING[modelName];
|
|
137
|
+
if (exact) return exact;
|
|
138
|
+
return ANTHROPIC_MODEL_PRICING[modelName.replace(SNAPSHOT_SUFFIX, "")];
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Fill the cache-write rates Anthropic derives from the input rate
|
|
142
|
+
* (5-minute writes 1.25x, 1-hour writes 2x) into a pricing entry that
|
|
143
|
+
* omits them, so a caller who supplies only `{ input, output }` is no
|
|
144
|
+
* longer billed nothing for cache writes. Explicit rates always win; the
|
|
145
|
+
* cache-read rate is left alone because it differs per model.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* withAnthropicCacheWriteRates({ input: 3, output: 15 });
|
|
149
|
+
* // { input: 3, output: 15, cacheWrite: 3.75, cacheWrite1h: 6 }
|
|
150
|
+
*/
|
|
151
|
+
function withAnthropicCacheWriteRates(pricing) {
|
|
152
|
+
if (!pricing) return;
|
|
153
|
+
const cacheWrite = pricing.cacheWrite ?? pricing.cachedOutput ?? pricing.input * 1.25;
|
|
154
|
+
const cacheWrite1h = pricing.cacheWrite1h ?? pricing.input * 2;
|
|
155
|
+
if (pricing.cacheWrite === cacheWrite && pricing.cacheWrite1h === cacheWrite1h) return pricing;
|
|
156
|
+
return {
|
|
157
|
+
...pricing,
|
|
158
|
+
cacheWrite,
|
|
159
|
+
cacheWrite1h
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
//#endregion
|
|
164
|
+
export { ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_MULTIPLIER, ANTHROPIC_MODEL_PRICING, anthropicPricingFor, withAnthropicCacheWriteRates };
|
|
165
|
+
//# sourceMappingURL=known-pricing.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"known-pricing.mjs","names":[],"sources":["../../../../../../../packages/ai-anthropic/src/known-pricing.ts"],"sourcesContent":["import type { ModelPricing } from \"@warlock.js/ai\";\n\n/**\n * Anthropic's prompt-cache write multipliers, relative to the base input\n * rate: a 5-minute write costs 1.25x, a 1-hour write 2x. They hold for\n * every Claude model on Anthropic's price list.\n *\n * Source: https://platform.claude.com/docs/en/about-claude/pricing\n * (fetched 2026-10-17).\n */\nexport const ANTHROPIC_CACHE_WRITE_MULTIPLIER = 1.25;\nexport const ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER = 2;\n\n/**\n * Built-in Claude API list prices, USD per 1,000,000 tokens, keyed by\n * model id. `cachedInput` is the cache-hit rate, `cacheWrite` the\n * 5-minute write rate and `cacheWrite1h` the 1-hour write rate.\n *\n * Source: https://platform.claude.com/docs/en/about-claude/pricing,\n * \"Model pricing\" table, fetched 2026-10-17. Standard (global) routing,\n * non-batch. Not covered, so pass `pricing` yourself when you need them:\n *\n * - Claude Haiku 5.5 — priced by prompt length (higher rates above\n * 100,000 prompt tokens), which a flat `ModelPricing` cannot express.\n * - US-only inference (`inference_geo: \"us\"`, 1.1x), fast mode, the Batch\n * API, and Claude on Bedrock / Vertex AI (partner-priced).\n * - Limited-availability models (Mythos) and retired models.\n *\n * Dated snapshot ids (`claude-haiku-4-5-20251001`) resolve to their alias\n * entry through {@link anthropicPricingFor}.\n */\nexport const ANTHROPIC_MODEL_PRICING: Readonly<Record<string, ModelPricing>> = {\n \"claude-fable-5-1\": {\n input: 10,\n output: 50,\n cachedInput: 0.25,\n cacheWrite: 12.5,\n cacheWrite1h: 20,\n },\n \"claude-fable-5\": { input: 10, output: 50, cachedInput: 1, cacheWrite: 12.5, cacheWrite1h: 20 },\n \"claude-opus-5-5\": { input: 4, output: 20, cachedInput: 0.2, cacheWrite: 5, cacheWrite1h: 8 },\n \"claude-opus-5\": { input: 5, output: 25, cachedInput: 0.5, cacheWrite: 6.25, cacheWrite1h: 10 },\n \"claude-opus-4-8\": { input: 5, output: 25, cachedInput: 0.5, cacheWrite: 6.25, cacheWrite1h: 10 },\n \"claude-opus-4-7\": { input: 5, output: 25, cachedInput: 0.5, cacheWrite: 6.25, cacheWrite1h: 10 },\n \"claude-opus-4-6\": { input: 5, output: 25, cachedInput: 0.5, cacheWrite: 6.25, cacheWrite1h: 10 },\n \"claude-opus-4-5\": { input: 5, output: 25, cachedInput: 0.5, cacheWrite: 6.25, cacheWrite1h: 10 },\n \"claude-sonnet-5-5\": { input: 2, output: 10, cachedInput: 0.1, cacheWrite: 2.5, cacheWrite1h: 4 },\n \"claude-sonnet-5\": { input: 2, output: 10, cachedInput: 0.2, cacheWrite: 2.5, cacheWrite1h: 4 },\n \"claude-sonnet-4-6\": {\n input: 3,\n output: 15,\n cachedInput: 0.3,\n cacheWrite: 3.75,\n cacheWrite1h: 6,\n },\n \"claude-sonnet-4-5\": {\n input: 3,\n output: 15,\n cachedInput: 0.3,\n cacheWrite: 3.75,\n cacheWrite1h: 6,\n },\n \"claude-haiku-4-5\": { input: 1, output: 5, cachedInput: 0.1, cacheWrite: 1.25, cacheWrite1h: 2 },\n};\n\n/** A trailing `-YYYYMMDD` snapshot date on a Claude model id. */\nconst SNAPSHOT_SUFFIX = /-\\d{8}$/;\n\n/**\n * Look up the built-in list price for a Claude model id. Accepts the\n * alias (`claude-sonnet-4-5`) or a dated snapshot\n * (`claude-sonnet-4-5-20250929`). Returns `undefined` for any id not in\n * {@link ANTHROPIC_MODEL_PRICING}, so cost stays unknown rather than wrong.\n *\n * @example\n * anthropicPricingFor(\"claude-haiku-4-5-20251001\"); // { input: 1, output: 5, … }\n * anthropicPricingFor(\"claude-haiku-5-5\"); // undefined (prompt-length tiers)\n */\nexport function anthropicPricingFor(modelName: string): ModelPricing | undefined {\n const exact = ANTHROPIC_MODEL_PRICING[modelName];\n\n if (exact) {\n return exact;\n }\n\n return ANTHROPIC_MODEL_PRICING[modelName.replace(SNAPSHOT_SUFFIX, \"\")];\n}\n\n/**\n * Fill the cache-write rates Anthropic derives from the input rate\n * (5-minute writes 1.25x, 1-hour writes 2x) into a pricing entry that\n * omits them, so a caller who supplies only `{ input, output }` is no\n * longer billed nothing for cache writes. Explicit rates always win; the\n * cache-read rate is left alone because it differs per model.\n *\n * @example\n * withAnthropicCacheWriteRates({ input: 3, output: 15 });\n * // { input: 3, output: 15, cacheWrite: 3.75, cacheWrite1h: 6 }\n */\nexport function withAnthropicCacheWriteRates(\n pricing: ModelPricing | undefined,\n): ModelPricing | undefined {\n if (!pricing) {\n return undefined;\n }\n\n const cacheWrite =\n pricing.cacheWrite ?? pricing.cachedOutput ?? pricing.input * ANTHROPIC_CACHE_WRITE_MULTIPLIER;\n const cacheWrite1h = pricing.cacheWrite1h ?? pricing.input * ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER;\n\n if (pricing.cacheWrite === cacheWrite && pricing.cacheWrite1h === cacheWrite1h) {\n return pricing;\n }\n\n return { ...pricing, cacheWrite, cacheWrite1h };\n}\n"],"mappings":";;;;;;;;;AAUA,MAAa,mCAAmC;AAChD,MAAa,sCAAsC;;;;;;;;;;;;;;;;;;;AAoBnD,MAAa,0BAAkE;CAC7E,oBAAoB;EAClB,OAAO;EACP,QAAQ;EACR,aAAa;EACb,YAAY;EACZ,cAAc;CAChB;CACA,kBAAkB;EAAE,OAAO;EAAI,QAAQ;EAAI,aAAa;EAAG,YAAY;EAAM,cAAc;CAAG;CAC9F,mBAAmB;EAAE,OAAO;EAAG,QAAQ;EAAI,aAAa;EAAK,YAAY;EAAG,cAAc;CAAE;CAC5F,iBAAiB;EAAE,OAAO;EAAG,QAAQ;EAAI,aAAa;EAAK,YAAY;EAAM,cAAc;CAAG;CAC9F,mBAAmB;EAAE,OAAO;EAAG,QAAQ;EAAI,aAAa;EAAK,YAAY;EAAM,cAAc;CAAG;CAChG,mBAAmB;EAAE,OAAO;EAAG,QAAQ;EAAI,aAAa;EAAK,YAAY;EAAM,cAAc;CAAG;CAChG,mBAAmB;EAAE,OAAO;EAAG,QAAQ;EAAI,aAAa;EAAK,YAAY;EAAM,cAAc;CAAG;CAChG,mBAAmB;EAAE,OAAO;EAAG,QAAQ;EAAI,aAAa;EAAK,YAAY;EAAM,cAAc;CAAG;CAChG,qBAAqB;EAAE,OAAO;EAAG,QAAQ;EAAI,aAAa;EAAK,YAAY;EAAK,cAAc;CAAE;CAChG,mBAAmB;EAAE,OAAO;EAAG,QAAQ;EAAI,aAAa;EAAK,YAAY;EAAK,cAAc;CAAE;CAC9F,qBAAqB;EACnB,OAAO;EACP,QAAQ;EACR,aAAa;EACb,YAAY;EACZ,cAAc;CAChB;CACA,qBAAqB;EACnB,OAAO;EACP,QAAQ;EACR,aAAa;EACb,YAAY;EACZ,cAAc;CAChB;CACA,oBAAoB;EAAE,OAAO;EAAG,QAAQ;EAAG,aAAa;EAAK,YAAY;EAAM,cAAc;CAAE;AACjG;;AAGA,MAAM,kBAAkB;;;;;;;;;;;AAYxB,SAAgB,oBAAoB,WAA6C;CAC/E,MAAM,QAAQ,wBAAwB;CAEtC,IAAI,OACF,OAAO;CAGT,OAAO,wBAAwB,UAAU,QAAQ,iBAAiB,EAAE;AACtE;;;;;;;;;;;;AAaA,SAAgB,6BACd,SAC0B;CAC1B,IAAI,CAAC,SACH;CAGF,MAAM,aACJ,QAAQ,cAAc,QAAQ,gBAAgB,QAAQ;CACxD,MAAM,eAAe,QAAQ,gBAAgB,QAAQ;CAErD,IAAI,QAAQ,eAAe,cAAc,QAAQ,iBAAiB,cAChE,OAAO;CAGT,OAAO;EAAE,GAAG;EAAS;EAAY;CAAa;AAChD"}
|
package/esm/model.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AnthropicModelConfig } from "./config.type.mjs";
|
|
2
|
+
import { AnthropicNonStreamingRequest, AnthropicRequest, AnthropicRequestOptions, AnthropicStreamingRequest } from "./request.type.mjs";
|
|
2
3
|
import Anthropic from "@anthropic-ai/sdk";
|
|
3
4
|
import { Message, ModelCallOptions, ModelCapabilities, ModelContract, ModelPricing, ModelResponse, ModelStreamChunk } from "@warlock.js/ai";
|
|
4
5
|
|
|
@@ -49,6 +50,9 @@ declare class AnthropicModel implements ModelContract {
|
|
|
49
50
|
private readonly client;
|
|
50
51
|
private readonly config;
|
|
51
52
|
private readonly thinkingMode;
|
|
53
|
+
/** Documented max output tokens of this model, when known. Sizes the default `max_tokens`. */
|
|
54
|
+
private readonly maxOutputTokens?;
|
|
55
|
+
private readonly preservedThinking;
|
|
52
56
|
private readonly logger;
|
|
53
57
|
constructor(client: Anthropic, config: AnthropicModelConfig, provider?: string);
|
|
54
58
|
/**
|
|
@@ -58,6 +62,29 @@ declare class AnthropicModel implements ModelContract {
|
|
|
58
62
|
* instance's `ModelConfig` defaults for this call only.
|
|
59
63
|
*/
|
|
60
64
|
complete(messages: Message[], options?: ModelCallOptions): Promise<ModelResponse>;
|
|
65
|
+
/** Build a detached request snapshot without sending it to Anthropic. */
|
|
66
|
+
buildRequest(messages: Message[], options: ModelCallOptions & {
|
|
67
|
+
stream: true;
|
|
68
|
+
}): AnthropicStreamingRequest;
|
|
69
|
+
buildRequest(messages: Message[], options?: ModelCallOptions & {
|
|
70
|
+
stream?: false;
|
|
71
|
+
}): AnthropicNonStreamingRequest;
|
|
72
|
+
buildRequest(messages: Message[], options?: ModelCallOptions & {
|
|
73
|
+
stream?: boolean;
|
|
74
|
+
}): AnthropicRequest;
|
|
75
|
+
/**
|
|
76
|
+
* `buildRequest()` for the adapter's own calls: a build failure (a reserved
|
|
77
|
+
* body key, a `providerOptions.anthropic.body` value `structuredClone`
|
|
78
|
+
* cannot copy) is logged like a send failure and rejects as an `AIError`.
|
|
79
|
+
* Errors that are not already an `AIError` become an `InvalidRequestError`,
|
|
80
|
+
* since nothing reached Anthropic and retrying cannot help.
|
|
81
|
+
*/
|
|
82
|
+
private buildLoggedRequest;
|
|
83
|
+
/** Send a built request without rebuilding its body or applying model defaults. */
|
|
84
|
+
send(request: AnthropicNonStreamingRequest, options?: AnthropicRequestOptions): Promise<ModelResponse>;
|
|
85
|
+
send(request: AnthropicStreamingRequest, options?: AnthropicRequestOptions): AsyncIterable<ModelStreamChunk>;
|
|
86
|
+
send(request: AnthropicRequest, options?: AnthropicRequestOptions): Promise<ModelResponse> | AsyncIterable<ModelStreamChunk>;
|
|
87
|
+
private completeRequest;
|
|
61
88
|
/**
|
|
62
89
|
* Count the input tokens a request would use, through Anthropic's
|
|
63
90
|
* `messages.countTokens` endpoint (a network call; no tokens are
|
|
@@ -76,8 +103,14 @@ declare class AnthropicModel implements ModelContract {
|
|
|
76
103
|
* arguments have fully accumulated, and a terminal `done` carrying the
|
|
77
104
|
* final finish reason + usage totals. Callers consume it with
|
|
78
105
|
* `for await`.
|
|
106
|
+
*
|
|
107
|
+
* With `options.streamChunks` it also yields `reasoning` for every
|
|
108
|
+
* non-empty `thinking_delta`, `tool-args` for every `input_json_delta`
|
|
109
|
+
* of a client `tool_use` block, and `usage` after `message_start` and
|
|
110
|
+
* each `message_delta` (whose counts are cumulative).
|
|
79
111
|
*/
|
|
80
112
|
stream(messages: Message[], options?: ModelCallOptions): AsyncIterable<ModelStreamChunk>;
|
|
113
|
+
private streamRequest;
|
|
81
114
|
/**
|
|
82
115
|
* Fold one stream event into the per-index block accumulator. Unknown
|
|
83
116
|
* block and delta types (beta `compaction`, future additions) are kept
|
|
@@ -93,16 +126,26 @@ declare class AnthropicModel implements ModelContract {
|
|
|
93
126
|
* and the beta-only body fields); otherwise to `client.messages`. The
|
|
94
127
|
* cancellation signal rides in the request options, as before.
|
|
95
128
|
*/
|
|
96
|
-
private
|
|
129
|
+
private dispatch;
|
|
97
130
|
/**
|
|
98
|
-
* The full request body: the adapter-built
|
|
99
|
-
* `thinking.display` when thinking is sent on an adaptive
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
131
|
+
* The full request body and the beta flags it needs: the adapter-built
|
|
132
|
+
* params, then `thinking.display` when thinking is sent on an adaptive
|
|
133
|
+
* model, the typed `thinkingBlockBinding`, `contextManagement` and
|
|
134
|
+
* `serverCompaction` options, then `providerOptions.anthropic.body`
|
|
135
|
+
* merged last (caller fields win). The body may add fields the adapter
|
|
136
|
+
* does not build (`fallbacks`, …) but may not replace the conversation or
|
|
137
|
+
* the model — see {@link RESERVED_BODY_FIELDS}.
|
|
104
138
|
*/
|
|
105
139
|
private buildBody;
|
|
140
|
+
/**
|
|
141
|
+
* Set `thinking.block_binding.prefix_mismatch_behavior`. It rides on
|
|
142
|
+
* adaptive or budget (`enabled`) thinking. A model that runs adaptive
|
|
143
|
+
* thinking when `thinking` is omitted (every preserved-thinking model) gets
|
|
144
|
+
* an explicit `{ type: "adaptive" }`, which is the same request. Any other
|
|
145
|
+
* shape (`between_tools`, `disabled`) takes no extra field, so the option
|
|
146
|
+
* is skipped with a debug log.
|
|
147
|
+
*/
|
|
148
|
+
private applyBlockBinding;
|
|
106
149
|
/**
|
|
107
150
|
* Assemble the Anthropic request body shared by `complete()` and
|
|
108
151
|
* `stream()` (each adds its own `stream` literal so the SDK's create
|
|
@@ -116,6 +159,20 @@ declare class AnthropicModel implements ModelContract {
|
|
|
116
159
|
* reject any explicit temperature (see `acceptsTemperature`).
|
|
117
160
|
*/
|
|
118
161
|
private buildParams;
|
|
162
|
+
/**
|
|
163
|
+
* The `max_tokens` sent when neither the call nor the model config sets
|
|
164
|
+
* `maxTokens`:
|
|
165
|
+
*
|
|
166
|
+
* - streaming: the model's documented max output, or
|
|
167
|
+
* `DEFAULT_MAX_TOKENS` (16384) for an unknown id;
|
|
168
|
+
* - non-streaming: `DEFAULT_MAX_TOKENS`, capped by the model's max output
|
|
169
|
+
* (the SDK requires streaming for larger non-streaming requests unless
|
|
170
|
+
* the client sets a `timeout`; see `DEFAULT_MAX_TOKENS`).
|
|
171
|
+
*
|
|
172
|
+
* With thinking on, the value is raised to at least the thinking budget
|
|
173
|
+
* plus `MIN_ANSWER_TOKENS`, and never exceeds the model's max output.
|
|
174
|
+
*/
|
|
175
|
+
private resolveDefaultMaxTokens;
|
|
119
176
|
/**
|
|
120
177
|
* Spread-friendly `system` fragment. Returns an empty object when no
|
|
121
178
|
* system prompt was hoisted out of the messages.
|
|
@@ -161,12 +218,18 @@ declare class AnthropicModel implements ModelContract {
|
|
|
161
218
|
* `messages.d.ts:1084`), so the budget is floored at that minimum.
|
|
162
219
|
*
|
|
163
220
|
* The neutral `effort: "none"` ("run without reasoning") is mapped per
|
|
164
|
-
* model:
|
|
165
|
-
* - Claude Sonnet 5.5
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
221
|
+
* model by `noReasoningForm` (see `thinking-mode.ts` for the sources):
|
|
222
|
+
* - Claude Sonnet 5.5: `thinking: { type: "between_tools" }`, its only
|
|
223
|
+
* thinking-off form. It is sent alone — no `output_config.effort` (the
|
|
224
|
+
* model default, `high`, is within the `high`-or-below range it
|
|
225
|
+
* requires) and no `display`, both of which the API rejects alongside it.
|
|
226
|
+
* - Claude Sonnet 5 and Claude Haiku 5.5: `thinking: { type: "disabled" }`
|
|
227
|
+
* with no effort and no `display`. Haiku 5.5 accepts `disabled` only at
|
|
228
|
+
* effort `high` or below; its default (`medium`) applies.
|
|
229
|
+
* - Claude Opus 5: adaptive thinking at `output_config.effort: "low"`.
|
|
230
|
+
* Opus 5 accepts `disabled`, but with it the model can write a tool call
|
|
231
|
+
* as plain text (the call never runs) and leak thinking tags; the lowest
|
|
232
|
+
* effort is the documented alternative.
|
|
170
233
|
* - Opus 5.5 and Fable 5/5.1: no `thinking` field. These models have no
|
|
171
234
|
* thinking-off form (`disabled` and `budget_tokens` are a 400 at every
|
|
172
235
|
* effort), so thinking still runs at the model's default effort. Pass
|
|
@@ -174,6 +237,11 @@ declare class AnthropicModel implements ModelContract {
|
|
|
174
237
|
* - Every other model: no `thinking` field, as before.
|
|
175
238
|
*/
|
|
176
239
|
private buildThinking;
|
|
240
|
+
/**
|
|
241
|
+
* The thinking settings for `reasoning: { effort: "none" }`, per
|
|
242
|
+
* `noReasoningForm(this.name)` (documented on `buildThinking`).
|
|
243
|
+
*/
|
|
244
|
+
private buildNoReasoning;
|
|
177
245
|
/**
|
|
178
246
|
* Spread-friendly tools fragment. Returns an empty object when no
|
|
179
247
|
* tools were supplied so the caller can unconditionally spread it.
|
|
@@ -230,12 +298,16 @@ declare class AnthropicModel implements ModelContract {
|
|
|
230
298
|
/**
|
|
231
299
|
* Normalize Anthropic's `usage` block into the neutral `Usage` shape.
|
|
232
300
|
* Anthropic reports `input_tokens` / `output_tokens` separately with
|
|
233
|
-
* no pre-summed total, so `total` is computed.
|
|
234
|
-
*
|
|
235
|
-
* `cacheWriteTokens`,
|
|
301
|
+
* no pre-summed total, so `total` is computed. `input_tokens` is the
|
|
302
|
+
* uncached remainder only — cache reads (`cachedTokens`) and writes
|
|
303
|
+
* (`cacheWriteTokens`, with the 1-hour share in `cacheWrite1hTokens`)
|
|
304
|
+
* come on top of it — so the usage is marked
|
|
305
|
+
* `inputIncludesCache: false`. Anthropic also reports
|
|
236
306
|
* `output_tokens_details.thinking_tokens` as the reasoning subset of
|
|
237
307
|
* its inclusive `output_tokens`; it is surfaced as `reasoningTokens`
|
|
238
|
-
* when present, without changing the billing total.
|
|
308
|
+
* when present, without changing the billing total. Server-side
|
|
309
|
+
* compaction iterations are added in (see {@link compactionIterationUsage}).
|
|
310
|
+
* `cost` is attached when the model is priced.
|
|
239
311
|
*/
|
|
240
312
|
private extractUsage;
|
|
241
313
|
/**
|