@warlock.js/ai-anthropic 5.30.0 → 5.32.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 +58 -6
- package/cjs/index.cjs +847 -138
- package/cjs/index.cjs.map +1 -1
- package/esm/config.type.d.mts +117 -8
- package/esm/config.type.d.mts.map +1 -1
- package/esm/index.d.mts +9 -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 +63 -0
- package/esm/known-pricing.d.mts.map +1 -0
- package/esm/known-pricing.mjs +172 -0
- package/esm/known-pricing.mjs.map +1 -0
- package/esm/model.d.mts +90 -20
- package/esm/model.d.mts.map +1 -1
- package/esm/model.mjs +389 -88
- package/esm/model.mjs.map +1 -1
- package/esm/request.type.d.mts +23 -0
- package/esm/request.type.d.mts.map +1 -0
- package/esm/sdk.d.mts +1 -3
- package/esm/sdk.d.mts.map +1 -1
- package/esm/thinking-mode.d.mts +14 -2
- 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 +6 -0
- package/esm/utils/index.mjs +1 -1
- package/esm/utils/map-stop-reason.d.mts +1 -0
- package/esm/utils/provider-blocks.d.mts +37 -0
- package/esm/utils/provider-blocks.d.mts.map +1 -0
- package/esm/utils/provider-blocks.mjs +3 -3
- package/esm/utils/provider-blocks.mjs.map +1 -1
- package/esm/utils/server-tool-usage.mjs +17 -0
- package/esm/utils/server-tool-usage.mjs.map +1 -0
- package/esm/utils/to-anthropic-messages.d.mts +69 -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 +17 -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 +248 -32
- package/llms.txt +1 -1
- package/package.json +3 -3
- package/skills/README.md +1 -1
- package/skills/setup-anthropic/SKILL.md +248 -32
package/esm/model.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
5
|
//#region ../../packages/ai-anthropic/src/model.d.ts
|
|
6
6
|
/**
|
|
7
7
|
* Anthropic-backed implementation of `ModelContract`.
|
|
@@ -41,7 +41,7 @@ import { Message, ModelCallOptions, ModelCapabilities, ModelContract, ModelPrici
|
|
|
41
41
|
*
|
|
42
42
|
* const result = await myAgent.execute("Summarize today's news.");
|
|
43
43
|
*/
|
|
44
|
-
declare class AnthropicModel implements ModelContract {
|
|
44
|
+
export declare class AnthropicModel implements ModelContract {
|
|
45
45
|
readonly name: string;
|
|
46
46
|
readonly provider: string;
|
|
47
47
|
readonly capabilities: ModelCapabilities;
|
|
@@ -49,6 +49,9 @@ declare class AnthropicModel implements ModelContract {
|
|
|
49
49
|
private readonly client;
|
|
50
50
|
private readonly config;
|
|
51
51
|
private readonly thinkingMode;
|
|
52
|
+
/** Documented max output tokens of this model, when known. Sizes the default `max_tokens`. */
|
|
53
|
+
private readonly maxOutputTokens?;
|
|
54
|
+
private readonly preservedThinking;
|
|
52
55
|
private readonly logger;
|
|
53
56
|
constructor(client: Anthropic, config: AnthropicModelConfig, provider?: string);
|
|
54
57
|
/**
|
|
@@ -58,6 +61,29 @@ declare class AnthropicModel implements ModelContract {
|
|
|
58
61
|
* instance's `ModelConfig` defaults for this call only.
|
|
59
62
|
*/
|
|
60
63
|
complete(messages: Message[], options?: ModelCallOptions): Promise<ModelResponse>;
|
|
64
|
+
/** Build a detached request snapshot without sending it to Anthropic. */
|
|
65
|
+
buildRequest(messages: Message[], options: ModelCallOptions & {
|
|
66
|
+
stream: true;
|
|
67
|
+
}): AnthropicStreamingRequest;
|
|
68
|
+
buildRequest(messages: Message[], options?: ModelCallOptions & {
|
|
69
|
+
stream?: false;
|
|
70
|
+
}): AnthropicNonStreamingRequest;
|
|
71
|
+
buildRequest(messages: Message[], options?: ModelCallOptions & {
|
|
72
|
+
stream?: boolean;
|
|
73
|
+
}): AnthropicRequest;
|
|
74
|
+
/**
|
|
75
|
+
* `buildRequest()` for the adapter's own calls: a build failure (a reserved
|
|
76
|
+
* body key, a `providerOptions.anthropic.body` value `structuredClone`
|
|
77
|
+
* cannot copy) is logged like a send failure and rejects as an `AIError`.
|
|
78
|
+
* Errors that are not already an `AIError` become an `InvalidRequestError`,
|
|
79
|
+
* since nothing reached Anthropic and retrying cannot help.
|
|
80
|
+
*/
|
|
81
|
+
private buildLoggedRequest;
|
|
82
|
+
/** Send a built request without rebuilding its body or applying model defaults. */
|
|
83
|
+
send(request: AnthropicNonStreamingRequest, options?: AnthropicRequestOptions): Promise<ModelResponse>;
|
|
84
|
+
send(request: AnthropicStreamingRequest, options?: AnthropicRequestOptions): AsyncIterable<ModelStreamChunk>;
|
|
85
|
+
send(request: AnthropicRequest, options?: AnthropicRequestOptions): Promise<ModelResponse> | AsyncIterable<ModelStreamChunk>;
|
|
86
|
+
private completeRequest;
|
|
61
87
|
/**
|
|
62
88
|
* Count the input tokens a request would use, through Anthropic's
|
|
63
89
|
* `messages.countTokens` endpoint (a network call; no tokens are
|
|
@@ -76,8 +102,14 @@ declare class AnthropicModel implements ModelContract {
|
|
|
76
102
|
* arguments have fully accumulated, and a terminal `done` carrying the
|
|
77
103
|
* final finish reason + usage totals. Callers consume it with
|
|
78
104
|
* `for await`.
|
|
105
|
+
*
|
|
106
|
+
* With `options.streamChunks` it also yields `reasoning` for every
|
|
107
|
+
* non-empty `thinking_delta`, `tool-args` for every `input_json_delta`
|
|
108
|
+
* of a client `tool_use` block, and `usage` after `message_start` and
|
|
109
|
+
* each `message_delta` (whose counts are cumulative).
|
|
79
110
|
*/
|
|
80
111
|
stream(messages: Message[], options?: ModelCallOptions): AsyncIterable<ModelStreamChunk>;
|
|
112
|
+
private streamRequest;
|
|
81
113
|
/**
|
|
82
114
|
* Fold one stream event into the per-index block accumulator. Unknown
|
|
83
115
|
* block and delta types (beta `compaction`, future additions) are kept
|
|
@@ -93,16 +125,26 @@ declare class AnthropicModel implements ModelContract {
|
|
|
93
125
|
* and the beta-only body fields); otherwise to `client.messages`. The
|
|
94
126
|
* cancellation signal rides in the request options, as before.
|
|
95
127
|
*/
|
|
96
|
-
private
|
|
128
|
+
private dispatch;
|
|
97
129
|
/**
|
|
98
|
-
* The full request body: the adapter-built
|
|
99
|
-
* `thinking.display` when thinking is sent on an adaptive
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
130
|
+
* The full request body and the beta flags it needs: the adapter-built
|
|
131
|
+
* params, then `thinking.display` when thinking is sent on an adaptive
|
|
132
|
+
* model, the typed `thinkingBlockBinding`, `contextManagement` and
|
|
133
|
+
* `serverCompaction` options, then `providerOptions.anthropic.body`
|
|
134
|
+
* merged last (caller fields win). The body may add fields the adapter
|
|
135
|
+
* does not build (`fallbacks`, …) but may not replace the conversation or
|
|
136
|
+
* the model — see {@link RESERVED_BODY_FIELDS}.
|
|
104
137
|
*/
|
|
105
138
|
private buildBody;
|
|
139
|
+
/**
|
|
140
|
+
* Set `thinking.block_binding.prefix_mismatch_behavior`. It rides on
|
|
141
|
+
* adaptive or budget (`enabled`) thinking. A model that runs adaptive
|
|
142
|
+
* thinking when `thinking` is omitted (every preserved-thinking model) gets
|
|
143
|
+
* an explicit `{ type: "adaptive" }`, which is the same request. Any other
|
|
144
|
+
* shape (`between_tools`, `disabled`) takes no extra field, so the option
|
|
145
|
+
* is skipped with a debug log.
|
|
146
|
+
*/
|
|
147
|
+
private applyBlockBinding;
|
|
106
148
|
/**
|
|
107
149
|
* Assemble the Anthropic request body shared by `complete()` and
|
|
108
150
|
* `stream()` (each adds its own `stream` literal so the SDK's create
|
|
@@ -116,6 +158,20 @@ declare class AnthropicModel implements ModelContract {
|
|
|
116
158
|
* reject any explicit temperature (see `acceptsTemperature`).
|
|
117
159
|
*/
|
|
118
160
|
private buildParams;
|
|
161
|
+
/**
|
|
162
|
+
* The `max_tokens` sent when neither the call nor the model config sets
|
|
163
|
+
* `maxTokens`:
|
|
164
|
+
*
|
|
165
|
+
* - streaming: the model's documented max output, or
|
|
166
|
+
* `DEFAULT_MAX_TOKENS` (16384) for an unknown id;
|
|
167
|
+
* - non-streaming: `DEFAULT_MAX_TOKENS`, capped by the model's max output
|
|
168
|
+
* (the SDK requires streaming for larger non-streaming requests unless
|
|
169
|
+
* the client sets a `timeout`; see `DEFAULT_MAX_TOKENS`).
|
|
170
|
+
*
|
|
171
|
+
* With thinking on, the value is raised to at least the thinking budget
|
|
172
|
+
* plus `MIN_ANSWER_TOKENS`, and never exceeds the model's max output.
|
|
173
|
+
*/
|
|
174
|
+
private resolveDefaultMaxTokens;
|
|
119
175
|
/**
|
|
120
176
|
* Spread-friendly `system` fragment. Returns an empty object when no
|
|
121
177
|
* system prompt was hoisted out of the messages.
|
|
@@ -161,12 +217,18 @@ declare class AnthropicModel implements ModelContract {
|
|
|
161
217
|
* `messages.d.ts:1084`), so the budget is floored at that minimum.
|
|
162
218
|
*
|
|
163
219
|
* The neutral `effort: "none"` ("run without reasoning") is mapped per
|
|
164
|
-
* model:
|
|
165
|
-
* - Claude Sonnet 5.5
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
220
|
+
* model by `noReasoningForm` (see `thinking-mode.ts` for the sources):
|
|
221
|
+
* - Claude Sonnet 5.5: `thinking: { type: "between_tools" }`, its only
|
|
222
|
+
* thinking-off form. It is sent alone — no `output_config.effort` (the
|
|
223
|
+
* model default, `high`, is within the `high`-or-below range it
|
|
224
|
+
* requires) and no `display`, both of which the API rejects alongside it.
|
|
225
|
+
* - Claude Sonnet 5 and Claude Haiku 5.5: `thinking: { type: "disabled" }`
|
|
226
|
+
* with no effort and no `display`. Haiku 5.5 accepts `disabled` only at
|
|
227
|
+
* effort `high` or below; its default (`medium`) applies.
|
|
228
|
+
* - Claude Opus 5: adaptive thinking at `output_config.effort: "low"`.
|
|
229
|
+
* Opus 5 accepts `disabled`, but with it the model can write a tool call
|
|
230
|
+
* as plain text (the call never runs) and leak thinking tags; the lowest
|
|
231
|
+
* effort is the documented alternative.
|
|
170
232
|
* - Opus 5.5 and Fable 5/5.1: no `thinking` field. These models have no
|
|
171
233
|
* thinking-off form (`disabled` and `budget_tokens` are a 400 at every
|
|
172
234
|
* effort), so thinking still runs at the model's default effort. Pass
|
|
@@ -174,6 +236,11 @@ declare class AnthropicModel implements ModelContract {
|
|
|
174
236
|
* - Every other model: no `thinking` field, as before.
|
|
175
237
|
*/
|
|
176
238
|
private buildThinking;
|
|
239
|
+
/**
|
|
240
|
+
* The thinking settings for `reasoning: { effort: "none" }`, per
|
|
241
|
+
* `noReasoningForm(this.name)` (documented on `buildThinking`).
|
|
242
|
+
*/
|
|
243
|
+
private buildNoReasoning;
|
|
177
244
|
/**
|
|
178
245
|
* Spread-friendly tools fragment. Returns an empty object when no
|
|
179
246
|
* tools were supplied so the caller can unconditionally spread it.
|
|
@@ -230,12 +297,16 @@ declare class AnthropicModel implements ModelContract {
|
|
|
230
297
|
/**
|
|
231
298
|
* Normalize Anthropic's `usage` block into the neutral `Usage` shape.
|
|
232
299
|
* Anthropic reports `input_tokens` / `output_tokens` separately with
|
|
233
|
-
* no pre-summed total, so `total` is computed.
|
|
234
|
-
*
|
|
235
|
-
* `cacheWriteTokens`,
|
|
300
|
+
* no pre-summed total, so `total` is computed. `input_tokens` is the
|
|
301
|
+
* uncached remainder only — cache reads (`cachedTokens`) and writes
|
|
302
|
+
* (`cacheWriteTokens`, with the 1-hour share in `cacheWrite1hTokens`)
|
|
303
|
+
* come on top of it — so the usage is marked
|
|
304
|
+
* `inputIncludesCache: false`. Anthropic also reports
|
|
236
305
|
* `output_tokens_details.thinking_tokens` as the reasoning subset of
|
|
237
306
|
* its inclusive `output_tokens`; it is surfaced as `reasoningTokens`
|
|
238
|
-
* when present, without changing the billing total.
|
|
307
|
+
* when present, without changing the billing total. Server-side
|
|
308
|
+
* compaction iterations are added in (see {@link compactionIterationUsage}).
|
|
309
|
+
* `cost` is attached when the model is priced.
|
|
239
310
|
*/
|
|
240
311
|
private extractUsage;
|
|
241
312
|
/**
|
|
@@ -246,5 +317,4 @@ declare class AnthropicModel implements ModelContract {
|
|
|
246
317
|
private logAndWrap;
|
|
247
318
|
}
|
|
248
319
|
//#endregion
|
|
249
|
-
export { AnthropicModel };
|
|
250
320
|
//# sourceMappingURL=model.d.mts.map
|
package/esm/model.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.mts","names":[],"sources":["../../../../../../../packages/ai-anthropic/src/model.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"model.d.mts","names":[],"sources":["../../../../../../../packages/ai-anthropic/src/model.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAoNa,0BAA0B;WACrB;WACA;WACA,cAAc;WACd,UAAU;mBAET;mBACA;mBACA;;mBAEA;mBACA;mBACA;EAEjB,YACE,QAAQ,WACR,QAAQ,sBACR;;;;;;;EAgDW,SAAS,UAAU,WAAW,UAAU,mBAAmB,QAAQ;;EAOzE,aACL,UAAU,WACV,SAAS;IAAqB;MAC7B;EACI,aACL,UAAU,WACV,UAAU;IAAqB;MAC9B;EACI,aACL,UAAU,WACV,UAAU;IAAqB;MAC9B;;;;;;;;UAmBK;;EA+BD,KACL,SAAS,8BACT,UAAU,0BACT,QAAQ;EACJ,KACL,SAAS,2BACT,UAAU,0BACT,cAAc;EACV,KACL,SAAS,kBACT,UAAU,0BACT,QAAQ,iBAAiB,cAAc;UAqB5B;;;;;;;;;;;;EA0CD,YAAY,UAAU,WAAW,UAAU,mBAAmB;;;;;;;;;;;;;EAyC7D,OACZ,UAAU,WACV,UAAU,mBACT,cAAc;UAOF;;;;;;;UAwMP;;UAoDA;;;;;;;UAkBA;;;;;;;;;;UAgCA;;;;;;;;;UA+EA;;;;;;;;;;;;;UAsCA;;;;;;;;;;;;;;UA2DA;;;;;;;;;;;;;UAsBA;;;;;;UA0BA;;;;;;UAeA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA+CA;;;;;UAwCA;;;;;;;;;;;;;;UA8BA;;;;;;;;;UAyCA;;;;;;;;;;;;;UA8BA;;;;;;UAmBA;;;;;;UAYA;;;;;UAuBA;;;;;;;;;;;;;;;UA6BA;;;;;;UAiCA"}
|