@ai-sdk/anthropic 3.0.75 → 3.0.77
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 +13 -0
- package/dist/index.d.mts +99 -4
- package/dist/index.d.ts +99 -4
- package/dist/index.js +810 -454
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +790 -430
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +63 -0
- package/dist/internal/index.d.ts +63 -0
- package/dist/internal/index.js +803 -447
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +789 -429
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +57 -0
- package/package.json +2 -2
- package/src/anthropic-message-metadata.ts +63 -13
- package/src/anthropic-messages-api.ts +113 -11
- package/src/anthropic-messages-language-model.ts +186 -11
- package/src/anthropic-prepare-tools.ts +17 -0
- package/src/anthropic-tools.ts +31 -0
- package/src/convert-anthropic-messages-usage.ts +50 -22
- package/src/convert-to-anthropic-messages-prompt.ts +62 -0
- package/src/tool/advisor_20260301.ts +128 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 3.0.77
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d53314d: feat(anthropic): add the new advisor tool
|
|
8
|
+
|
|
9
|
+
## 3.0.76
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [f591416]
|
|
14
|
+
- @ai-sdk/provider-utils@4.0.27
|
|
15
|
+
|
|
3
16
|
## 3.0.75
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -5,10 +5,17 @@ import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Represents a single iteration in the usage breakdown.
|
|
8
|
-
*
|
|
9
|
-
* usage for each sampling
|
|
8
|
+
*
|
|
9
|
+
* The API returns an iterations array showing usage for each sampling
|
|
10
|
+
* iteration. Iterations can be:
|
|
11
|
+
* - `compaction`: a context compaction step (billed at executor rates).
|
|
12
|
+
* - `message`: an executor sampling iteration (billed at executor rates).
|
|
13
|
+
* - `advisor_message`: an advisor sub-inference (billed at the advisor
|
|
14
|
+
* model's rates; `model` carries the advisor model ID). Advisor token
|
|
15
|
+
* usage is NOT rolled into the top-level usage totals because it bills
|
|
16
|
+
* at a different rate; inspect this array directly for advisor billing.
|
|
10
17
|
*/
|
|
11
|
-
|
|
18
|
+
type AnthropicUsageIteration = {
|
|
12
19
|
type: 'compaction' | 'message';
|
|
13
20
|
/**
|
|
14
21
|
* Number of input tokens consumed in this iteration.
|
|
@@ -18,7 +25,41 @@ interface AnthropicUsageIteration {
|
|
|
18
25
|
* Number of output tokens generated in this iteration.
|
|
19
26
|
*/
|
|
20
27
|
outputTokens: number;
|
|
21
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Number of cache-creation input tokens consumed in this iteration.
|
|
30
|
+
*/
|
|
31
|
+
cacheCreationInputTokens?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Number of cache-read input tokens consumed in this iteration.
|
|
34
|
+
*/
|
|
35
|
+
cacheReadInputTokens?: number;
|
|
36
|
+
} | {
|
|
37
|
+
type: 'advisor_message';
|
|
38
|
+
/**
|
|
39
|
+
* The advisor model that produced this iteration.
|
|
40
|
+
*/
|
|
41
|
+
model: string;
|
|
42
|
+
/**
|
|
43
|
+
* Number of input tokens consumed in this iteration.
|
|
44
|
+
*/
|
|
45
|
+
inputTokens: number;
|
|
46
|
+
/**
|
|
47
|
+
* Number of output tokens generated in this iteration.
|
|
48
|
+
*/
|
|
49
|
+
outputTokens: number;
|
|
50
|
+
/**
|
|
51
|
+
* Number of cache-creation input tokens consumed by this advisor
|
|
52
|
+
* sub-inference. Nonzero when advisor-side caching is enabled and
|
|
53
|
+
* the advisor writes a fresh cache entry.
|
|
54
|
+
*/
|
|
55
|
+
cacheCreationInputTokens?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Number of cache-read input tokens consumed by this advisor
|
|
58
|
+
* sub-inference. Nonzero on the second and later advisor calls
|
|
59
|
+
* when advisor-side caching is enabled.
|
|
60
|
+
*/
|
|
61
|
+
cacheReadInputTokens?: number;
|
|
62
|
+
};
|
|
22
63
|
interface AnthropicMessageMetadata {
|
|
23
64
|
usage: JSONObject;
|
|
24
65
|
cacheCreationInputTokens: number | null;
|
|
@@ -242,6 +283,60 @@ interface AnthropicToolOptions {
|
|
|
242
283
|
}
|
|
243
284
|
|
|
244
285
|
declare const anthropicTools: {
|
|
286
|
+
/**
|
|
287
|
+
* Pairs a faster executor model with a higher-intelligence advisor model
|
|
288
|
+
* that provides strategic guidance mid-generation.
|
|
289
|
+
*
|
|
290
|
+
* The advisor lets a faster, lower-cost executor model consult a
|
|
291
|
+
* higher-intelligence advisor model server-side. The advisor reads the
|
|
292
|
+
* executor's full transcript and produces a plan or course correction;
|
|
293
|
+
* the executor continues with the task, informed by the advice. All of
|
|
294
|
+
* this happens inside a single `/v1/messages` request.
|
|
295
|
+
*
|
|
296
|
+
* Beta header `advisor-tool-2026-03-01` is added automatically when this
|
|
297
|
+
* tool is included.
|
|
298
|
+
*
|
|
299
|
+
* Multi-turn conversations: pass the full assistant content (including
|
|
300
|
+
* `advisor_tool_result` blocks) back to the API on subsequent turns. If
|
|
301
|
+
* you omit the advisor tool from `tools` on a follow-up turn while the
|
|
302
|
+
* message history still contains `advisor_tool_result` blocks, the API
|
|
303
|
+
* returns a `400 invalid_request_error`.
|
|
304
|
+
*
|
|
305
|
+
* Supported executor models: Claude Haiku 4.5, Sonnet 4.6, Opus 4.6,
|
|
306
|
+
* Opus 4.7. The advisor must be at least as capable as the executor.
|
|
307
|
+
*
|
|
308
|
+
* @param model - The advisor model ID (required), e.g. `"claude-opus-4-7"`.
|
|
309
|
+
* @param maxUses - Maximum advisor calls per request (per-request cap).
|
|
310
|
+
* @param caching - Enables prompt caching for the advisor's transcript
|
|
311
|
+
* across calls within a conversation. Worthwhile from ~3 advisor calls
|
|
312
|
+
* per conversation.
|
|
313
|
+
*/
|
|
314
|
+
advisor_20260301: (args: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
|
|
315
|
+
type: "advisor_result";
|
|
316
|
+
text: string;
|
|
317
|
+
} | {
|
|
318
|
+
type: "advisor_redacted_result";
|
|
319
|
+
encryptedContent: string;
|
|
320
|
+
} | {
|
|
321
|
+
type: "advisor_tool_result_error";
|
|
322
|
+
errorCode: string;
|
|
323
|
+
}, {
|
|
324
|
+
model: string;
|
|
325
|
+
maxUses?: number;
|
|
326
|
+
caching?: {
|
|
327
|
+
type: "ephemeral";
|
|
328
|
+
ttl: "5m" | "1h";
|
|
329
|
+
};
|
|
330
|
+
}>>[0]) => _ai_sdk_provider_utils.Tool<{}, {
|
|
331
|
+
type: "advisor_result";
|
|
332
|
+
text: string;
|
|
333
|
+
} | {
|
|
334
|
+
type: "advisor_redacted_result";
|
|
335
|
+
encryptedContent: string;
|
|
336
|
+
} | {
|
|
337
|
+
type: "advisor_tool_result_error";
|
|
338
|
+
errorCode: string;
|
|
339
|
+
}>;
|
|
245
340
|
/**
|
|
246
341
|
* The bash tool enables Claude to execute shell commands in a persistent bash session,
|
|
247
342
|
* allowing system operations, script execution, and command-line automation.
|
package/dist/index.d.ts
CHANGED
|
@@ -5,10 +5,17 @@ import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Represents a single iteration in the usage breakdown.
|
|
8
|
-
*
|
|
9
|
-
* usage for each sampling
|
|
8
|
+
*
|
|
9
|
+
* The API returns an iterations array showing usage for each sampling
|
|
10
|
+
* iteration. Iterations can be:
|
|
11
|
+
* - `compaction`: a context compaction step (billed at executor rates).
|
|
12
|
+
* - `message`: an executor sampling iteration (billed at executor rates).
|
|
13
|
+
* - `advisor_message`: an advisor sub-inference (billed at the advisor
|
|
14
|
+
* model's rates; `model` carries the advisor model ID). Advisor token
|
|
15
|
+
* usage is NOT rolled into the top-level usage totals because it bills
|
|
16
|
+
* at a different rate; inspect this array directly for advisor billing.
|
|
10
17
|
*/
|
|
11
|
-
|
|
18
|
+
type AnthropicUsageIteration = {
|
|
12
19
|
type: 'compaction' | 'message';
|
|
13
20
|
/**
|
|
14
21
|
* Number of input tokens consumed in this iteration.
|
|
@@ -18,7 +25,41 @@ interface AnthropicUsageIteration {
|
|
|
18
25
|
* Number of output tokens generated in this iteration.
|
|
19
26
|
*/
|
|
20
27
|
outputTokens: number;
|
|
21
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Number of cache-creation input tokens consumed in this iteration.
|
|
30
|
+
*/
|
|
31
|
+
cacheCreationInputTokens?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Number of cache-read input tokens consumed in this iteration.
|
|
34
|
+
*/
|
|
35
|
+
cacheReadInputTokens?: number;
|
|
36
|
+
} | {
|
|
37
|
+
type: 'advisor_message';
|
|
38
|
+
/**
|
|
39
|
+
* The advisor model that produced this iteration.
|
|
40
|
+
*/
|
|
41
|
+
model: string;
|
|
42
|
+
/**
|
|
43
|
+
* Number of input tokens consumed in this iteration.
|
|
44
|
+
*/
|
|
45
|
+
inputTokens: number;
|
|
46
|
+
/**
|
|
47
|
+
* Number of output tokens generated in this iteration.
|
|
48
|
+
*/
|
|
49
|
+
outputTokens: number;
|
|
50
|
+
/**
|
|
51
|
+
* Number of cache-creation input tokens consumed by this advisor
|
|
52
|
+
* sub-inference. Nonzero when advisor-side caching is enabled and
|
|
53
|
+
* the advisor writes a fresh cache entry.
|
|
54
|
+
*/
|
|
55
|
+
cacheCreationInputTokens?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Number of cache-read input tokens consumed by this advisor
|
|
58
|
+
* sub-inference. Nonzero on the second and later advisor calls
|
|
59
|
+
* when advisor-side caching is enabled.
|
|
60
|
+
*/
|
|
61
|
+
cacheReadInputTokens?: number;
|
|
62
|
+
};
|
|
22
63
|
interface AnthropicMessageMetadata {
|
|
23
64
|
usage: JSONObject;
|
|
24
65
|
cacheCreationInputTokens: number | null;
|
|
@@ -242,6 +283,60 @@ interface AnthropicToolOptions {
|
|
|
242
283
|
}
|
|
243
284
|
|
|
244
285
|
declare const anthropicTools: {
|
|
286
|
+
/**
|
|
287
|
+
* Pairs a faster executor model with a higher-intelligence advisor model
|
|
288
|
+
* that provides strategic guidance mid-generation.
|
|
289
|
+
*
|
|
290
|
+
* The advisor lets a faster, lower-cost executor model consult a
|
|
291
|
+
* higher-intelligence advisor model server-side. The advisor reads the
|
|
292
|
+
* executor's full transcript and produces a plan or course correction;
|
|
293
|
+
* the executor continues with the task, informed by the advice. All of
|
|
294
|
+
* this happens inside a single `/v1/messages` request.
|
|
295
|
+
*
|
|
296
|
+
* Beta header `advisor-tool-2026-03-01` is added automatically when this
|
|
297
|
+
* tool is included.
|
|
298
|
+
*
|
|
299
|
+
* Multi-turn conversations: pass the full assistant content (including
|
|
300
|
+
* `advisor_tool_result` blocks) back to the API on subsequent turns. If
|
|
301
|
+
* you omit the advisor tool from `tools` on a follow-up turn while the
|
|
302
|
+
* message history still contains `advisor_tool_result` blocks, the API
|
|
303
|
+
* returns a `400 invalid_request_error`.
|
|
304
|
+
*
|
|
305
|
+
* Supported executor models: Claude Haiku 4.5, Sonnet 4.6, Opus 4.6,
|
|
306
|
+
* Opus 4.7. The advisor must be at least as capable as the executor.
|
|
307
|
+
*
|
|
308
|
+
* @param model - The advisor model ID (required), e.g. `"claude-opus-4-7"`.
|
|
309
|
+
* @param maxUses - Maximum advisor calls per request (per-request cap).
|
|
310
|
+
* @param caching - Enables prompt caching for the advisor's transcript
|
|
311
|
+
* across calls within a conversation. Worthwhile from ~3 advisor calls
|
|
312
|
+
* per conversation.
|
|
313
|
+
*/
|
|
314
|
+
advisor_20260301: (args: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
|
|
315
|
+
type: "advisor_result";
|
|
316
|
+
text: string;
|
|
317
|
+
} | {
|
|
318
|
+
type: "advisor_redacted_result";
|
|
319
|
+
encryptedContent: string;
|
|
320
|
+
} | {
|
|
321
|
+
type: "advisor_tool_result_error";
|
|
322
|
+
errorCode: string;
|
|
323
|
+
}, {
|
|
324
|
+
model: string;
|
|
325
|
+
maxUses?: number;
|
|
326
|
+
caching?: {
|
|
327
|
+
type: "ephemeral";
|
|
328
|
+
ttl: "5m" | "1h";
|
|
329
|
+
};
|
|
330
|
+
}>>[0]) => _ai_sdk_provider_utils.Tool<{}, {
|
|
331
|
+
type: "advisor_result";
|
|
332
|
+
text: string;
|
|
333
|
+
} | {
|
|
334
|
+
type: "advisor_redacted_result";
|
|
335
|
+
encryptedContent: string;
|
|
336
|
+
} | {
|
|
337
|
+
type: "advisor_tool_result_error";
|
|
338
|
+
errorCode: string;
|
|
339
|
+
}>;
|
|
245
340
|
/**
|
|
246
341
|
* The bash tool enables Claude to execute shell commands in a persistent bash session,
|
|
247
342
|
* allowing system operations, script execution, and command-line automation.
|