@ai-sdk/anthropic 3.0.34 → 3.0.36
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 +14 -0
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -1
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +15 -0
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +15 -0
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +51 -0
- package/package.json +3 -3
- package/src/anthropic-messages-api.ts +6 -0
- package/src/convert-to-anthropic-messages-prompt.ts +17 -0
package/docs/05-anthropic.mdx
CHANGED
|
@@ -745,6 +745,57 @@ const result = await generateText({
|
|
|
745
745
|
|
|
746
746
|
Claude will construct regex patterns like `weather|temperature|forecast` to find matching tools.
|
|
747
747
|
|
|
748
|
+
#### Custom Tool Search
|
|
749
|
+
|
|
750
|
+
You can implement your own tool search logic (e.g., using embeddings or semantic search) by returning `tool-reference` content blocks via `toModelOutput`:
|
|
751
|
+
|
|
752
|
+
```ts
|
|
753
|
+
import { anthropic } from '@ai-sdk/anthropic';
|
|
754
|
+
import { generateText, tool } from 'ai';
|
|
755
|
+
import { z } from 'zod';
|
|
756
|
+
|
|
757
|
+
const result = await generateText({
|
|
758
|
+
model: anthropic('claude-sonnet-4-5'),
|
|
759
|
+
prompt: 'What is the weather in San Francisco?',
|
|
760
|
+
tools: {
|
|
761
|
+
// Custom search tool
|
|
762
|
+
searchTools: tool({
|
|
763
|
+
description: 'Search for tools by keyword',
|
|
764
|
+
inputSchema: z.object({ query: z.string() }),
|
|
765
|
+
execute: async ({ query }) => {
|
|
766
|
+
// Your custom search logic (embeddings, fuzzy match, etc.)
|
|
767
|
+
const allTools = ['get_weather', 'get_forecast', 'get_temperature'];
|
|
768
|
+
return allTools.filter(name => name.includes(query.toLowerCase()));
|
|
769
|
+
},
|
|
770
|
+
toModelOutput: ({ output }) => ({
|
|
771
|
+
type: 'content',
|
|
772
|
+
value: (output as string[]).map(toolName => ({
|
|
773
|
+
type: 'custom' as const,
|
|
774
|
+
providerOptions: {
|
|
775
|
+
anthropic: {
|
|
776
|
+
type: 'tool-reference',
|
|
777
|
+
toolName,
|
|
778
|
+
},
|
|
779
|
+
},
|
|
780
|
+
})),
|
|
781
|
+
}),
|
|
782
|
+
}),
|
|
783
|
+
|
|
784
|
+
// Deferred tools
|
|
785
|
+
get_weather: tool({
|
|
786
|
+
description: 'Get the current weather',
|
|
787
|
+
inputSchema: z.object({ location: z.string() }),
|
|
788
|
+
execute: async ({ location }) => ({ location, temperature: 72 }),
|
|
789
|
+
providerOptions: {
|
|
790
|
+
anthropic: { deferLoading: true },
|
|
791
|
+
},
|
|
792
|
+
}),
|
|
793
|
+
},
|
|
794
|
+
});
|
|
795
|
+
```
|
|
796
|
+
|
|
797
|
+
This sends `tool_reference` blocks to Anthropic, which loads the corresponding deferred tool schemas into Claude's context.
|
|
798
|
+
|
|
748
799
|
### MCP Connectors
|
|
749
800
|
|
|
750
801
|
Anthropic supports connecting to [MCP servers](https://docs.claude.com/en/docs/agents-and-tools/mcp-connector) as part of their execution.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/anthropic",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.36",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@ai-sdk/provider": "3.0.
|
|
40
|
-
"@ai-sdk/provider-utils": "4.0.
|
|
39
|
+
"@ai-sdk/provider": "3.0.7",
|
|
40
|
+
"@ai-sdk/provider-utils": "4.0.13"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "20.17.24",
|
|
@@ -164,6 +164,11 @@ type AnthropicNestedDocumentContent = Omit<
|
|
|
164
164
|
cache_control?: never;
|
|
165
165
|
};
|
|
166
166
|
|
|
167
|
+
export interface AnthropicToolReferenceContent {
|
|
168
|
+
type: 'tool_reference';
|
|
169
|
+
tool_name: string;
|
|
170
|
+
}
|
|
171
|
+
|
|
167
172
|
export interface AnthropicToolResultContent {
|
|
168
173
|
type: 'tool_result';
|
|
169
174
|
tool_use_id: string;
|
|
@@ -173,6 +178,7 @@ export interface AnthropicToolResultContent {
|
|
|
173
178
|
| AnthropicNestedTextContent
|
|
174
179
|
| AnthropicNestedImageContent
|
|
175
180
|
| AnthropicNestedDocumentContent
|
|
181
|
+
| AnthropicToolReferenceContent
|
|
176
182
|
>;
|
|
177
183
|
is_error: boolean | undefined;
|
|
178
184
|
cache_control: AnthropicCacheControl | undefined;
|
|
@@ -355,6 +355,23 @@ export async function convertToAnthropicMessagesPrompt({
|
|
|
355
355
|
|
|
356
356
|
return undefined;
|
|
357
357
|
}
|
|
358
|
+
case 'custom': {
|
|
359
|
+
const anthropicOptions = contentPart.providerOptions
|
|
360
|
+
?.anthropic as
|
|
361
|
+
| { type: string; toolName?: string }
|
|
362
|
+
| undefined;
|
|
363
|
+
if (anthropicOptions?.type === 'tool-reference') {
|
|
364
|
+
return {
|
|
365
|
+
type: 'tool_reference' as const,
|
|
366
|
+
tool_name: anthropicOptions.toolName!,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
warnings.push({
|
|
370
|
+
type: 'other',
|
|
371
|
+
message: `unsupported custom tool content part`,
|
|
372
|
+
});
|
|
373
|
+
return undefined;
|
|
374
|
+
}
|
|
358
375
|
default: {
|
|
359
376
|
warnings.push({
|
|
360
377
|
type: 'other',
|