ai 6.0.172 → 6.0.173

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.
@@ -152,7 +152,7 @@ function detectMediaType({
152
152
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
153
153
 
154
154
  // src/version.ts
155
- var VERSION = true ? "6.0.172" : "0.0.0-test";
155
+ var VERSION = true ? "6.0.173" : "0.0.0-test";
156
156
 
157
157
  // src/util/download/download.ts
158
158
  var download = async ({
@@ -131,7 +131,7 @@ import {
131
131
  } from "@ai-sdk/provider-utils";
132
132
 
133
133
  // src/version.ts
134
- var VERSION = true ? "6.0.172" : "0.0.0-test";
134
+ var VERSION = true ? "6.0.173" : "0.0.0-test";
135
135
 
136
136
  // src/util/download/download.ts
137
137
  var download = async ({
@@ -119,16 +119,22 @@ You can pass such settings to the `generateImage` function
119
119
  using the `providerOptions` parameter. The options for the provider
120
120
  (`openai` in the example below) become request body properties.
121
121
 
122
- ```tsx highlight={"9"}
122
+ ```tsx highlight={"12"}
123
123
  import { generateImage } from 'ai';
124
- import { openai } from '@ai-sdk/openai';
124
+ import {
125
+ openai,
126
+ type OpenAIImageModelGenerationOptions,
127
+ } from '@ai-sdk/openai';
125
128
 
126
129
  const { image } = await generateImage({
127
130
  model: openai.image('dall-e-3'),
128
131
  prompt: 'Santa Claus driving a Cadillac',
129
132
  size: '1024x1024',
130
133
  providerOptions: {
131
- openai: { style: 'vivid', quality: 'hd' },
134
+ openai: {
135
+ style: 'vivid',
136
+ quality: 'hd',
137
+ } satisfies OpenAIImageModelGenerationOptions,
132
138
  },
133
139
  });
134
140
  ```
@@ -169,6 +169,13 @@ export const weatherTool = tool({
169
169
  description:
170
170
  'Additional provider-specific metadata. They are passed through to the provider from the AI SDK and enable provider-specific functionality that can be fully encapsulated in the provider.',
171
171
  },
172
+ {
173
+ name: 'providerMetadata',
174
+ isOptional: true,
175
+ type: 'ProviderMetadata',
176
+ description:
177
+ "Optional metadata about the tool itself (e.g. its source). It is propagated onto the resulting tool call's providerMetadata so consumers can read it from tool call/result parts and UI message parts. Useful for sources of dynamic tools (e.g. an MCP server) to identify themselves.",
178
+ },
172
179
  {
173
180
  name: 'type',
174
181
  isOptional: true,
@@ -152,6 +152,13 @@ export const customTool = dynamicTool({
152
152
  isOptional: true,
153
153
  type: 'ProviderOptions',
154
154
  description: 'Additional provider-specific metadata.'
155
+ },
156
+ {
157
+ name: 'providerMetadata',
158
+ isOptional: true,
159
+ type: 'ProviderMetadata',
160
+ description:
161
+ "Optional metadata about the tool itself (e.g. its source). It is propagated onto the resulting tool call's providerMetadata so consumers can read it from tool call/result parts and UI message parts. Useful for sources of dynamic tools (e.g. an MCP server) to identify themselves."
155
162
  }
156
163
  ]
157
164
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "6.0.172",
3
+ "version": "6.0.173",
4
4
  "description": "AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -45,9 +45,9 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@opentelemetry/api": "1.9.0",
48
- "@ai-sdk/gateway": "3.0.107",
48
+ "@ai-sdk/gateway": "3.0.108",
49
49
  "@ai-sdk/provider": "3.0.10",
50
- "@ai-sdk/provider-utils": "4.0.25"
50
+ "@ai-sdk/provider-utils": "4.0.26"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@edge-runtime/vm": "^5.0.0",
@@ -9,10 +9,31 @@ import {
9
9
  import { InvalidToolInputError } from '../error/invalid-tool-input-error';
10
10
  import { NoSuchToolError } from '../error/no-such-tool-error';
11
11
  import { ToolCallRepairError } from '../error/tool-call-repair-error';
12
+ import type { ProviderMetadata } from '../types';
12
13
  import type { DynamicToolCall, TypedToolCall } from './tool-call';
13
14
  import type { ToolCallRepairFunction } from './tool-call-repair-function';
14
15
  import type { ToolSet } from './tool-set';
15
16
 
17
+ /**
18
+ * Merge the tool's static `providerMetadata` (e.g. an MCP server name)
19
+ * with the `providerMetadata` returned by the language model on the tool
20
+ * call. Model-supplied metadata wins on conflicting top-level namespaces.
21
+ */
22
+ function mergeToolProviderMetadata(
23
+ toolMetadata: ProviderMetadata | undefined,
24
+ callMetadata: ProviderMetadata | undefined,
25
+ ): ProviderMetadata | undefined {
26
+ if (toolMetadata == null) {
27
+ return callMetadata;
28
+ }
29
+
30
+ if (callMetadata == null) {
31
+ return toolMetadata;
32
+ }
33
+
34
+ return { ...toolMetadata, ...callMetadata };
35
+ }
36
+
16
37
  export async function parseToolCall<TOOLS extends ToolSet>({
17
38
  toolCall,
18
39
  tools,
@@ -93,7 +114,10 @@ export async function parseToolCall<TOOLS extends ToolSet>({
93
114
  error,
94
115
  title: tools?.[toolCall.toolName]?.title,
95
116
  providerExecuted: toolCall.providerExecuted,
96
- providerMetadata: toolCall.providerMetadata,
117
+ providerMetadata: mergeToolProviderMetadata(
118
+ tools?.[toolCall.toolName]?.providerMetadata,
119
+ toolCall.providerMetadata,
120
+ ),
97
121
  };
98
122
  }
99
123
  }
@@ -165,6 +189,11 @@ async function doParseToolCall<TOOLS extends ToolSet>({
165
189
  });
166
190
  }
167
191
 
192
+ const mergedProviderMetadata = mergeToolProviderMetadata(
193
+ tool.providerMetadata,
194
+ toolCall.providerMetadata,
195
+ );
196
+
168
197
  return tool.type === 'dynamic'
169
198
  ? {
170
199
  type: 'tool-call',
@@ -172,7 +201,7 @@ async function doParseToolCall<TOOLS extends ToolSet>({
172
201
  toolName: toolCall.toolName,
173
202
  input: parseResult.value,
174
203
  providerExecuted: toolCall.providerExecuted,
175
- providerMetadata: toolCall.providerMetadata,
204
+ providerMetadata: mergedProviderMetadata,
176
205
  dynamic: true,
177
206
  title: tool.title,
178
207
  }
@@ -182,7 +211,7 @@ async function doParseToolCall<TOOLS extends ToolSet>({
182
211
  toolName,
183
212
  input: parseResult.value,
184
213
  providerExecuted: toolCall.providerExecuted,
185
- providerMetadata: toolCall.providerMetadata,
214
+ providerMetadata: mergedProviderMetadata,
186
215
  title: tool.title,
187
216
  };
188
217
  }