@ai-sdk/provider-utils 5.0.0-beta.3 → 5.0.0-beta.4

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 CHANGED
@@ -1,5 +1,80 @@
1
1
  # @ai-sdk/provider-utils
2
2
 
3
+ ## 5.0.0-beta.4
4
+
5
+ ### Major Changes
6
+
7
+ - 61753c3: ### `@ai-sdk/openai`: remove redundant `name` argument from `openai.tools.customTool()`
8
+
9
+ `openai.tools.customTool()` no longer accepts a `name` field. the tool name is now derived from the sdk tool key (the object key in the `tools` object).
10
+
11
+ migration: remove the `name` property from `customTool()` calls. the object key is now used as the tool name sent to the openai api.
12
+
13
+ before:
14
+
15
+ ```ts
16
+ tools: {
17
+ write_sql: openai.tools.customTool({
18
+ name: 'write_sql',
19
+ description: '...',
20
+ }),
21
+ }
22
+ ```
23
+
24
+ after:
25
+
26
+ ```ts
27
+ tools: {
28
+ write_sql: openai.tools.customTool({
29
+ description: '...',
30
+ }),
31
+ }
32
+ ```
33
+
34
+ ### `@ai-sdk/provider-utils`: `createToolNameMapping()` no longer accepts the `resolveProviderToolName` parameter
35
+
36
+ before: tool name can be set dynamically
37
+
38
+ ```ts
39
+ const toolNameMapping = createToolNameMapping({
40
+ tools,
41
+ providerToolNames: {
42
+ 'openai.code_interpreter': 'code_interpreter',
43
+ 'openai.file_search': 'file_search',
44
+ 'openai.image_generation': 'image_generation',
45
+ 'openai.local_shell': 'local_shell',
46
+ 'openai.shell': 'shell',
47
+ 'openai.web_search': 'web_search',
48
+ 'openai.web_search_preview': 'web_search_preview',
49
+ 'openai.mcp': 'mcp',
50
+ 'openai.apply_patch': 'apply_patch',
51
+ },
52
+ resolveProviderToolName: tool =>
53
+ tool.id === 'openai.custom'
54
+ ? (tool.args as { name?: string }).name
55
+ : undefined,
56
+ });
57
+ ```
58
+
59
+ after: tool name is static based on `tools` keys
60
+
61
+ ```
62
+ const toolNameMapping = createToolNameMapping({
63
+ tools,
64
+ providerToolNames: {
65
+ 'openai.code_interpreter': 'code_interpreter',
66
+ 'openai.file_search': 'file_search',
67
+ 'openai.image_generation': 'image_generation',
68
+ 'openai.local_shell': 'local_shell',
69
+ 'openai.shell': 'shell',
70
+ 'openai.web_search': 'web_search',
71
+ 'openai.web_search_preview': 'web_search_preview',
72
+ 'openai.mcp': 'mcp',
73
+ 'openai.apply_patch': 'apply_patch',
74
+ }
75
+ });
76
+ ```
77
+
3
78
  ## 5.0.0-beta.3
4
79
 
5
80
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { LanguageModelV3FunctionTool, LanguageModelV3ProviderTool, ImageModelV3File, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, SharedV3ProviderOptions, TypeValidationContext } from '@ai-sdk/provider';
1
+ import { LanguageModelV4FunctionTool, LanguageModelV4ProviderTool, ImageModelV4File, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV4Prompt, SharedV4ProviderOptions, TypeValidationContext } from '@ai-sdk/provider';
2
2
  import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
3
3
  export * from '@standard-schema/spec';
4
4
  import * as z3 from 'zod/v3';
@@ -41,20 +41,15 @@ interface ToolNameMapping {
41
41
  * @param tools - Tools that were passed to the language model.
42
42
  * @param providerToolNames - Maps the provider tool ids to the provider tool names.
43
43
  */
44
- declare function createToolNameMapping({ tools, providerToolNames, resolveProviderToolName, }: {
44
+ declare function createToolNameMapping({ tools, providerToolNames, }: {
45
45
  /**
46
46
  * Tools that were passed to the language model.
47
47
  */
48
- tools: Array<LanguageModelV3FunctionTool | LanguageModelV3ProviderTool> | undefined;
48
+ tools: Array<LanguageModelV4FunctionTool | LanguageModelV4ProviderTool> | undefined;
49
49
  /**
50
50
  * Maps the provider tool ids to the provider tool names.
51
51
  */
52
52
  providerToolNames: Record<`${string}.${string}`, string>;
53
- /**
54
- * Optional resolver for provider tool names that cannot be represented as
55
- * static id -> name mappings (e.g. dynamic provider names).
56
- */
57
- resolveProviderToolName?: (tool: LanguageModelV3ProviderTool) => string | undefined;
58
53
  }): ToolNameMapping;
59
54
 
60
55
  /**
@@ -97,13 +92,13 @@ declare function extractResponseHeaders(response: Response): {
97
92
  };
98
93
 
99
94
  /**
100
- * Convert an ImageModelV3File to a URL or data URI string.
95
+ * Convert an ImageModelV4File to a URL or data URI string.
101
96
  *
102
97
  * If the file is a URL, it returns the URL as-is.
103
98
  * If the file is base64 data, it returns a data URI with the base64 data.
104
99
  * If the file is a Uint8Array, it converts it to base64 and returns a data URI.
105
100
  */
106
- declare function convertImageModelFileToDataUri(file: ImageModelV3File): string;
101
+ declare function convertImageModelFileToDataUri(file: ImageModelV4File): string;
107
102
 
108
103
  /**
109
104
  * Converts an input object to FormData for multipart/form-data requests.
@@ -390,11 +385,11 @@ declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedR
390
385
  declare function getRuntimeEnvironmentUserAgent(globalThisAny?: any): string;
391
386
 
392
387
  declare function injectJsonInstructionIntoMessages({ messages, schema, schemaPrefix, schemaSuffix, }: {
393
- messages: LanguageModelV3Prompt;
388
+ messages: LanguageModelV4Prompt;
394
389
  schema?: JSONSchema7;
395
390
  schemaPrefix?: string;
396
391
  schemaSuffix?: string;
397
- }): LanguageModelV3Prompt;
392
+ }): LanguageModelV4Prompt;
398
393
 
399
394
  declare function isAbortError(error: unknown): error is Error;
400
395
 
@@ -549,7 +544,7 @@ type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
549
544
  * They are passed through to the provider from the AI SDK and enable
550
545
  * provider-specific functionality that can be fully encapsulated in the provider.
551
546
  */
552
- type ProviderOptions = SharedV3ProviderOptions;
547
+ type ProviderOptions = SharedV4ProviderOptions;
553
548
 
554
549
  /**
555
550
  * Text content part of a prompt. It contains a string of text.
@@ -1145,6 +1140,8 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
1145
1140
  * Optional conversion function that maps the tool result to an output that can be used by the language model.
1146
1141
  *
1147
1142
  * If not provided, the tool result will be sent as a JSON object.
1143
+ *
1144
+ * This function is invoked on the server by `convertToModelMessages`, so ensure that you pass the same "tools" (ToolSet) to both "convertToModelMessages" and "streamText" (or other generation APIs).
1148
1145
  */
1149
1146
  toModelOutput?: (options: {
1150
1147
  /**
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { LanguageModelV3FunctionTool, LanguageModelV3ProviderTool, ImageModelV3File, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, SharedV3ProviderOptions, TypeValidationContext } from '@ai-sdk/provider';
1
+ import { LanguageModelV4FunctionTool, LanguageModelV4ProviderTool, ImageModelV4File, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV4Prompt, SharedV4ProviderOptions, TypeValidationContext } from '@ai-sdk/provider';
2
2
  import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
3
3
  export * from '@standard-schema/spec';
4
4
  import * as z3 from 'zod/v3';
@@ -41,20 +41,15 @@ interface ToolNameMapping {
41
41
  * @param tools - Tools that were passed to the language model.
42
42
  * @param providerToolNames - Maps the provider tool ids to the provider tool names.
43
43
  */
44
- declare function createToolNameMapping({ tools, providerToolNames, resolveProviderToolName, }: {
44
+ declare function createToolNameMapping({ tools, providerToolNames, }: {
45
45
  /**
46
46
  * Tools that were passed to the language model.
47
47
  */
48
- tools: Array<LanguageModelV3FunctionTool | LanguageModelV3ProviderTool> | undefined;
48
+ tools: Array<LanguageModelV4FunctionTool | LanguageModelV4ProviderTool> | undefined;
49
49
  /**
50
50
  * Maps the provider tool ids to the provider tool names.
51
51
  */
52
52
  providerToolNames: Record<`${string}.${string}`, string>;
53
- /**
54
- * Optional resolver for provider tool names that cannot be represented as
55
- * static id -> name mappings (e.g. dynamic provider names).
56
- */
57
- resolveProviderToolName?: (tool: LanguageModelV3ProviderTool) => string | undefined;
58
53
  }): ToolNameMapping;
59
54
 
60
55
  /**
@@ -97,13 +92,13 @@ declare function extractResponseHeaders(response: Response): {
97
92
  };
98
93
 
99
94
  /**
100
- * Convert an ImageModelV3File to a URL or data URI string.
95
+ * Convert an ImageModelV4File to a URL or data URI string.
101
96
  *
102
97
  * If the file is a URL, it returns the URL as-is.
103
98
  * If the file is base64 data, it returns a data URI with the base64 data.
104
99
  * If the file is a Uint8Array, it converts it to base64 and returns a data URI.
105
100
  */
106
- declare function convertImageModelFileToDataUri(file: ImageModelV3File): string;
101
+ declare function convertImageModelFileToDataUri(file: ImageModelV4File): string;
107
102
 
108
103
  /**
109
104
  * Converts an input object to FormData for multipart/form-data requests.
@@ -390,11 +385,11 @@ declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedR
390
385
  declare function getRuntimeEnvironmentUserAgent(globalThisAny?: any): string;
391
386
 
392
387
  declare function injectJsonInstructionIntoMessages({ messages, schema, schemaPrefix, schemaSuffix, }: {
393
- messages: LanguageModelV3Prompt;
388
+ messages: LanguageModelV4Prompt;
394
389
  schema?: JSONSchema7;
395
390
  schemaPrefix?: string;
396
391
  schemaSuffix?: string;
397
- }): LanguageModelV3Prompt;
392
+ }): LanguageModelV4Prompt;
398
393
 
399
394
  declare function isAbortError(error: unknown): error is Error;
400
395
 
@@ -549,7 +544,7 @@ type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
549
544
  * They are passed through to the provider from the AI SDK and enable
550
545
  * provider-specific functionality that can be fully encapsulated in the provider.
551
546
  */
552
- type ProviderOptions = SharedV3ProviderOptions;
547
+ type ProviderOptions = SharedV4ProviderOptions;
553
548
 
554
549
  /**
555
550
  * Text content part of a prompt. It contains a string of text.
@@ -1145,6 +1140,8 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
1145
1140
  * Optional conversion function that maps the tool result to an output that can be used by the language model.
1146
1141
  *
1147
1142
  * If not provided, the tool result will be sent as a JSON object.
1143
+ *
1144
+ * This function is invoked on the server by `convertToModelMessages`, so ensure that you pass the same "tools" (ToolSet) to both "convertToModelMessages" and "streamText" (or other generation APIs).
1148
1145
  */
1149
1146
  toModelOutput?: (options: {
1150
1147
  /**
package/dist/index.js CHANGED
@@ -146,30 +146,25 @@ function convertAsyncIteratorToReadableStream(iterator) {
146
146
  // src/create-tool-name-mapping.ts
147
147
  function createToolNameMapping({
148
148
  tools = [],
149
- providerToolNames,
150
- resolveProviderToolName
149
+ providerToolNames
151
150
  }) {
152
- var _a2;
153
151
  const customToolNameToProviderToolName = {};
154
152
  const providerToolNameToCustomToolName = {};
155
153
  for (const tool2 of tools) {
156
- if (tool2.type === "provider") {
157
- const providerToolName = (_a2 = resolveProviderToolName == null ? void 0 : resolveProviderToolName(tool2)) != null ? _a2 : tool2.id in providerToolNames ? providerToolNames[tool2.id] : void 0;
158
- if (providerToolName == null) {
159
- continue;
160
- }
154
+ if (tool2.type === "provider" && tool2.id in providerToolNames) {
155
+ const providerToolName = providerToolNames[tool2.id];
161
156
  customToolNameToProviderToolName[tool2.name] = providerToolName;
162
157
  providerToolNameToCustomToolName[providerToolName] = tool2.name;
163
158
  }
164
159
  }
165
160
  return {
166
161
  toProviderToolName: (customToolName) => {
167
- var _a3;
168
- return (_a3 = customToolNameToProviderToolName[customToolName]) != null ? _a3 : customToolName;
162
+ var _a2;
163
+ return (_a2 = customToolNameToProviderToolName[customToolName]) != null ? _a2 : customToolName;
169
164
  },
170
165
  toCustomToolName: (providerToolName) => {
171
- var _a3;
172
- return (_a3 = providerToolNameToCustomToolName[providerToolName]) != null ? _a3 : providerToolName;
166
+ var _a2;
167
+ return (_a2 = providerToolNameToCustomToolName[providerToolName]) != null ? _a2 : providerToolName;
173
168
  }
174
169
  };
175
170
  }
@@ -675,7 +670,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
675
670
  }
676
671
 
677
672
  // src/version.ts
678
- var VERSION = true ? "5.0.0-beta.3" : "0.0.0-test";
673
+ var VERSION = true ? "5.0.0-beta.4" : "0.0.0-test";
679
674
 
680
675
  // src/get-from-api.ts
681
676
  var getOriginalFetch = () => globalThis.fetch;