Skip to content

Commit e2b9e4b

Browse files
authored
feat (provider): add name for provider defined tools for future validation (#6838)
## Background Tool names for provider defined tools were removed in #6815. They are needed for future validation of the tool setup. ## Summary Add provider defined tool names back. ## Future Work Validate that provider defined tools are used with their correct name in `streamText` and `generateText` requests.
1 parent cc62234 commit e2b9e4b

22 files changed

+383
-323
lines changed

‎.changeset/brown-geckos-tell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ai-sdk/provider': major
3+
---
4+
5+
feat (provider): add name for provider defined tools for future validation

‎packages/ai/core/generate-text/generate-text.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,7 @@ describe('generateText', () => {
17521752
web_search: {
17531753
type: 'provider-defined',
17541754
id: 'test.web_search',
1755+
name: 'web_search',
17551756
inputSchema: z.object({ value: z.string() }),
17561757
outputSchema: z.object({ value: z.string() }),
17571758
args: {},

‎packages/ai/core/generate-text/stream-text.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7594,6 +7594,7 @@ describe('streamText', () => {
75947594
web_search: {
75957595
type: 'provider-defined',
75967596
id: 'test.web_search',
7597+
name: 'web_search',
75977598
inputSchema: z.object({ value: z.string() }),
75987599
outputSchema: z.object({ value: z.string() }),
75997600
args: {},

‎packages/ai/core/generate-text/to-response-messages.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ describe('toResponseMessages', () => {
613613
web_search: tool({
614614
type: 'provider-defined',
615615
id: 'test.web_search',
616+
name: 'web_search',
616617
inputSchema: z.object({
617618
query: z.string(),
618619
}),

‎packages/ai/core/prompt/prepare-tools-and-tool-choice.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const mockTools: ToolSet = {
1818
const mockProviderDefinedTool: Tool = {
1919
type: 'provider-defined',
2020
id: 'provider.tool-id',
21+
name: 'tool-id',
2122
args: { key: 'value' },
2223
inputSchema: z.object({}),
2324
};

‎packages/anthropic/src/anthropic-messages-language-model.test.ts

Lines changed: 309 additions & 300 deletions
Large diffs are not rendered by default.

‎packages/anthropic/src/anthropic-prepare-tools.test.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,19 @@ it('should correctly prepare provider-defined tools', () => {
4848
{
4949
type: 'provider-defined',
5050
id: 'anthropic.computer_20241022',
51+
name: 'computer',
5152
args: { displayWidthPx: 800, displayHeightPx: 600, displayNumber: 1 },
5253
},
5354
{
5455
type: 'provider-defined',
5556
id: 'anthropic.text_editor_20241022',
57+
name: 'text_editor',
5658
args: {},
5759
},
5860
{
5961
type: 'provider-defined',
6062
id: 'anthropic.bash_20241022',
63+
name: 'bash',
6164
args: {},
6265
},
6366
],
@@ -89,22 +92,26 @@ it('should add warnings for unsupported tools', () => {
8992
{
9093
type: 'provider-defined',
9194
id: 'unsupported.tool',
95+
name: 'unsupported_tool',
9296
args: {},
9397
},
9498
],
9599
});
96100
expect(result.tools).toEqual([]);
97101
expect(result.toolChoice).toBeUndefined();
98-
expect(result.toolWarnings).toEqual([
99-
{
100-
type: 'unsupported-tool',
101-
tool: {
102-
type: 'provider-defined',
103-
id: 'unsupported.tool',
104-
args: {},
102+
expect(result.toolWarnings).toMatchInlineSnapshot(`
103+
[
104+
{
105+
"tool": {
106+
"args": {},
107+
"id": "unsupported.tool",
108+
"name": "unsupported_tool",
109+
"type": "provider-defined",
110+
},
111+
"type": "unsupported-tool",
105112
},
106-
},
107-
]);
113+
]
114+
`);
108115
});
109116

110117
it('should handle tool choice "auto"', () => {

‎packages/anthropic/src/tool/bash_20241022.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const bash_20241022 = createProviderDefinedToolFactory<
1616
{}
1717
>({
1818
id: 'anthropic.bash_20241022',
19+
name: 'bash',
1920
inputSchema: z.object({
2021
command: z.string(),
2122
restart: z.boolean().optional(),

‎packages/anthropic/src/tool/bash_20250124.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const bash_20250124 = createProviderDefinedToolFactory<
1616
{}
1717
>({
1818
id: 'anthropic.bashTool_20250124',
19+
name: 'bash',
1920
inputSchema: z.object({
2021
command: z.string(),
2122
restart: z.boolean().optional(),

‎packages/anthropic/src/tool/computer_20241022.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const computer_20241022 = createProviderDefinedToolFactory<
5858
}
5959
>({
6060
id: 'anthropic.computer_20241022',
61+
name: 'computer',
6162
inputSchema: z.object({
6263
action: z.enum([
6364
'key',

0 commit comments

Comments
 (0)