@ai-sdk/provider-utils 4.0.0-beta.37 → 4.0.0-beta.39

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,19 @@
1
1
  # @ai-sdk/provider-utils
2
2
 
3
+ ## 4.0.0-beta.39
4
+
5
+ ### Patch Changes
6
+
7
+ - 954c356: feat(openai): allow custom names for provider-defined tools
8
+ - Updated dependencies [954c356]
9
+ - @ai-sdk/provider@3.0.0-beta.21
10
+
11
+ ## 4.0.0-beta.38
12
+
13
+ ### Patch Changes
14
+
15
+ - 03849b0: move DelayedPromise into provider utils
16
+
3
17
  ## 4.0.0-beta.37
4
18
 
5
19
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, SharedV3ProviderOptions } from '@ai-sdk/provider';
1
+ import { LanguageModelV3FunctionTool, LanguageModelV3ProviderDefinedTool, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, SharedV3ProviderOptions } from '@ai-sdk/provider';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
3
  export * from '@standard-schema/spec';
4
4
  import * as z3 from 'zod/v3';
@@ -16,6 +16,42 @@ declare function combineHeaders(...headers: Array<Record<string, string | undefi
16
16
  */
17
17
  declare function convertAsyncIteratorToReadableStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
18
18
 
19
+ /**
20
+ * Interface for mapping between custom tool names and provider tool names.
21
+ */
22
+ interface ToolNameMapping {
23
+ /**
24
+ * Maps a custom tool name (used by the client) to the provider's tool name.
25
+ * If the custom tool name does not have a mapping, returns the input name.
26
+ *
27
+ * @param customToolName - The custom name of the tool defined by the client.
28
+ * @returns The corresponding provider tool name, or the input name if not mapped.
29
+ */
30
+ toProviderToolName: (customToolName: string) => string;
31
+ /**
32
+ * Maps a provider tool name to the custom tool name used by the client.
33
+ * If the provider tool name does not have a mapping, returns the input name.
34
+ *
35
+ * @param providerToolName - The name of the tool as understood by the provider.
36
+ * @returns The corresponding custom tool name, or the input name if not mapped.
37
+ */
38
+ toCustomToolName: (providerToolName: string) => string;
39
+ }
40
+ /**
41
+ * @param tools - Tools that were passed to the language model.
42
+ * @param providerToolNames - Maps the provider tool ids to the provider tool names.
43
+ */
44
+ declare function createToolNameMapping({ tools, providerToolNames, }: {
45
+ /**
46
+ * Tools that were passed to the language model.
47
+ */
48
+ tools: Array<LanguageModelV3FunctionTool | LanguageModelV3ProviderDefinedTool> | undefined;
49
+ /**
50
+ * Maps the provider tool ids to the provider tool names.
51
+ */
52
+ providerToolNames: Record<`${string}.${string}`, string>;
53
+ }): ToolNameMapping;
54
+
19
55
  /**
20
56
  * Creates a Promise that resolves after a specified delay
21
57
  * @param delayInMs - The delay duration in milliseconds. If null or undefined, resolves immediately.
@@ -27,6 +63,24 @@ declare function delay(delayInMs?: number | null, options?: {
27
63
  abortSignal?: AbortSignal;
28
64
  }): Promise<void>;
29
65
 
66
+ /**
67
+ * Delayed promise. It is only constructed once the value is accessed.
68
+ * This is useful to avoid unhandled promise rejections when the promise is created
69
+ * but not accessed.
70
+ */
71
+ declare class DelayedPromise<T> {
72
+ private status;
73
+ private _promise;
74
+ private _resolve;
75
+ private _reject;
76
+ get promise(): Promise<T>;
77
+ resolve(value: T): void;
78
+ reject(error: unknown): void;
79
+ isResolved(): boolean;
80
+ isRejected(): boolean;
81
+ isPending(): boolean;
82
+ }
83
+
30
84
  /**
31
85
  Extracts the headers from a response object and returns them as a key-value object.
32
86
 
@@ -942,14 +996,10 @@ Tool with provider-defined input and output schemas.
942
996
  */
943
997
  type: 'provider-defined';
944
998
  /**
945
- The ID of the tool. Should follow the format `<provider-name>.<unique-tool-name>`.
999
+ The ID of the tool. Must follow the format `<provider-name>.<unique-tool-name>`.
946
1000
  */
947
1001
  id: `${string}.${string}`;
948
1002
  /**
949
- The name of the tool that the user must use in the tool set.
950
- */
951
- name: string;
952
- /**
953
1003
  The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
954
1004
  */
955
1005
  args: Record<string, unknown>;
@@ -995,9 +1045,8 @@ type ProviderDefinedToolFactory<INPUT, ARGS extends object> = <OUTPUT>(options:
995
1045
  onInputDelta?: Tool<INPUT, OUTPUT>['onInputDelta'];
996
1046
  onInputAvailable?: Tool<INPUT, OUTPUT>['onInputAvailable'];
997
1047
  }) => Tool<INPUT, OUTPUT>;
998
- declare function createProviderDefinedToolFactory<INPUT, ARGS extends object>({ id, name, inputSchema, }: {
1048
+ declare function createProviderDefinedToolFactory<INPUT, ARGS extends object>({ id, inputSchema, }: {
999
1049
  id: `${string}.${string}`;
1000
- name: string;
1001
1050
  inputSchema: FlexibleSchema<INPUT>;
1002
1051
  }): ProviderDefinedToolFactory<INPUT, ARGS>;
1003
1052
  type ProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object> = (options: ARGS & {
@@ -1008,9 +1057,8 @@ type ProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends obje
1008
1057
  onInputDelta?: Tool<INPUT, OUTPUT>['onInputDelta'];
1009
1058
  onInputAvailable?: Tool<INPUT, OUTPUT>['onInputAvailable'];
1010
1059
  }) => Tool<INPUT, OUTPUT>;
1011
- declare function createProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object>({ id, name, inputSchema, outputSchema, }: {
1060
+ declare function createProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object>({ id, inputSchema, outputSchema, }: {
1012
1061
  id: `${string}.${string}`;
1013
- name: string;
1014
1062
  inputSchema: FlexibleSchema<INPUT>;
1015
1063
  outputSchema: FlexibleSchema<OUTPUT>;
1016
1064
  }): ProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS>;
@@ -1155,4 +1203,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
1155
1203
  dynamic?: boolean;
1156
1204
  }
1157
1205
 
1158
- export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
1206
+ export { type AssistantContent, type AssistantModelMessage, type DataContent, DelayedPromise, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, SharedV3ProviderOptions } from '@ai-sdk/provider';
1
+ import { LanguageModelV3FunctionTool, LanguageModelV3ProviderDefinedTool, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, SharedV3ProviderOptions } from '@ai-sdk/provider';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
3
  export * from '@standard-schema/spec';
4
4
  import * as z3 from 'zod/v3';
@@ -16,6 +16,42 @@ declare function combineHeaders(...headers: Array<Record<string, string | undefi
16
16
  */
17
17
  declare function convertAsyncIteratorToReadableStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
18
18
 
19
+ /**
20
+ * Interface for mapping between custom tool names and provider tool names.
21
+ */
22
+ interface ToolNameMapping {
23
+ /**
24
+ * Maps a custom tool name (used by the client) to the provider's tool name.
25
+ * If the custom tool name does not have a mapping, returns the input name.
26
+ *
27
+ * @param customToolName - The custom name of the tool defined by the client.
28
+ * @returns The corresponding provider tool name, or the input name if not mapped.
29
+ */
30
+ toProviderToolName: (customToolName: string) => string;
31
+ /**
32
+ * Maps a provider tool name to the custom tool name used by the client.
33
+ * If the provider tool name does not have a mapping, returns the input name.
34
+ *
35
+ * @param providerToolName - The name of the tool as understood by the provider.
36
+ * @returns The corresponding custom tool name, or the input name if not mapped.
37
+ */
38
+ toCustomToolName: (providerToolName: string) => string;
39
+ }
40
+ /**
41
+ * @param tools - Tools that were passed to the language model.
42
+ * @param providerToolNames - Maps the provider tool ids to the provider tool names.
43
+ */
44
+ declare function createToolNameMapping({ tools, providerToolNames, }: {
45
+ /**
46
+ * Tools that were passed to the language model.
47
+ */
48
+ tools: Array<LanguageModelV3FunctionTool | LanguageModelV3ProviderDefinedTool> | undefined;
49
+ /**
50
+ * Maps the provider tool ids to the provider tool names.
51
+ */
52
+ providerToolNames: Record<`${string}.${string}`, string>;
53
+ }): ToolNameMapping;
54
+
19
55
  /**
20
56
  * Creates a Promise that resolves after a specified delay
21
57
  * @param delayInMs - The delay duration in milliseconds. If null or undefined, resolves immediately.
@@ -27,6 +63,24 @@ declare function delay(delayInMs?: number | null, options?: {
27
63
  abortSignal?: AbortSignal;
28
64
  }): Promise<void>;
29
65
 
66
+ /**
67
+ * Delayed promise. It is only constructed once the value is accessed.
68
+ * This is useful to avoid unhandled promise rejections when the promise is created
69
+ * but not accessed.
70
+ */
71
+ declare class DelayedPromise<T> {
72
+ private status;
73
+ private _promise;
74
+ private _resolve;
75
+ private _reject;
76
+ get promise(): Promise<T>;
77
+ resolve(value: T): void;
78
+ reject(error: unknown): void;
79
+ isResolved(): boolean;
80
+ isRejected(): boolean;
81
+ isPending(): boolean;
82
+ }
83
+
30
84
  /**
31
85
  Extracts the headers from a response object and returns them as a key-value object.
32
86
 
@@ -942,14 +996,10 @@ Tool with provider-defined input and output schemas.
942
996
  */
943
997
  type: 'provider-defined';
944
998
  /**
945
- The ID of the tool. Should follow the format `<provider-name>.<unique-tool-name>`.
999
+ The ID of the tool. Must follow the format `<provider-name>.<unique-tool-name>`.
946
1000
  */
947
1001
  id: `${string}.${string}`;
948
1002
  /**
949
- The name of the tool that the user must use in the tool set.
950
- */
951
- name: string;
952
- /**
953
1003
  The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
954
1004
  */
955
1005
  args: Record<string, unknown>;
@@ -995,9 +1045,8 @@ type ProviderDefinedToolFactory<INPUT, ARGS extends object> = <OUTPUT>(options:
995
1045
  onInputDelta?: Tool<INPUT, OUTPUT>['onInputDelta'];
996
1046
  onInputAvailable?: Tool<INPUT, OUTPUT>['onInputAvailable'];
997
1047
  }) => Tool<INPUT, OUTPUT>;
998
- declare function createProviderDefinedToolFactory<INPUT, ARGS extends object>({ id, name, inputSchema, }: {
1048
+ declare function createProviderDefinedToolFactory<INPUT, ARGS extends object>({ id, inputSchema, }: {
999
1049
  id: `${string}.${string}`;
1000
- name: string;
1001
1050
  inputSchema: FlexibleSchema<INPUT>;
1002
1051
  }): ProviderDefinedToolFactory<INPUT, ARGS>;
1003
1052
  type ProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object> = (options: ARGS & {
@@ -1008,9 +1057,8 @@ type ProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends obje
1008
1057
  onInputDelta?: Tool<INPUT, OUTPUT>['onInputDelta'];
1009
1058
  onInputAvailable?: Tool<INPUT, OUTPUT>['onInputAvailable'];
1010
1059
  }) => Tool<INPUT, OUTPUT>;
1011
- declare function createProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object>({ id, name, inputSchema, outputSchema, }: {
1060
+ declare function createProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object>({ id, inputSchema, outputSchema, }: {
1012
1061
  id: `${string}.${string}`;
1013
- name: string;
1014
1062
  inputSchema: FlexibleSchema<INPUT>;
1015
1063
  outputSchema: FlexibleSchema<OUTPUT>;
1016
1064
  }): ProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS>;
@@ -1155,4 +1203,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
1155
1203
  dynamic?: boolean;
1156
1204
  }
1157
1205
 
1158
- export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
1206
+ export { type AssistantContent, type AssistantModelMessage, type DataContent, DelayedPromise, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
package/dist/index.js CHANGED
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  // src/index.ts
32
32
  var src_exports = {};
33
33
  __export(src_exports, {
34
+ DelayedPromise: () => DelayedPromise,
34
35
  EventSourceParserStream: () => import_stream2.EventSourceParserStream,
35
36
  VERSION: () => VERSION,
36
37
  asSchema: () => asSchema,
@@ -47,6 +48,7 @@ __export(src_exports, {
47
48
  createProviderDefinedToolFactory: () => createProviderDefinedToolFactory,
48
49
  createProviderDefinedToolFactoryWithOutputSchema: () => createProviderDefinedToolFactoryWithOutputSchema,
49
50
  createStatusCodeErrorResponseHandler: () => createStatusCodeErrorResponseHandler,
51
+ createToolNameMapping: () => createToolNameMapping,
50
52
  delay: () => delay,
51
53
  dynamicTool: () => dynamicTool,
52
54
  executeTool: () => executeTool,
@@ -134,6 +136,32 @@ function convertAsyncIteratorToReadableStream(iterator) {
134
136
  });
135
137
  }
136
138
 
139
+ // src/create-tool-name-mapping.ts
140
+ function createToolNameMapping({
141
+ tools = [],
142
+ providerToolNames
143
+ }) {
144
+ const customToolNameToProviderToolName = {};
145
+ const providerToolNameToCustomToolName = {};
146
+ for (const tool2 of tools) {
147
+ if (tool2.type === "provider-defined" && tool2.id in providerToolNames) {
148
+ const providerToolName = providerToolNames[tool2.id];
149
+ customToolNameToProviderToolName[tool2.name] = providerToolName;
150
+ providerToolNameToCustomToolName[providerToolName] = tool2.name;
151
+ }
152
+ }
153
+ return {
154
+ toProviderToolName: (customToolName) => {
155
+ var _a;
156
+ return (_a = customToolNameToProviderToolName[customToolName]) != null ? _a : customToolName;
157
+ },
158
+ toCustomToolName: (providerToolName) => {
159
+ var _a;
160
+ return (_a = providerToolNameToCustomToolName[providerToolName]) != null ? _a : providerToolName;
161
+ }
162
+ };
163
+ }
164
+
137
165
  // src/delay.ts
138
166
  async function delay(delayInMs, options) {
139
167
  if (delayInMs == null) {
@@ -164,6 +192,53 @@ function createAbortError() {
164
192
  return new DOMException("Delay was aborted", "AbortError");
165
193
  }
166
194
 
195
+ // src/delayed-promise.ts
196
+ var DelayedPromise = class {
197
+ constructor() {
198
+ this.status = { type: "pending" };
199
+ this._resolve = void 0;
200
+ this._reject = void 0;
201
+ }
202
+ get promise() {
203
+ if (this._promise) {
204
+ return this._promise;
205
+ }
206
+ this._promise = new Promise((resolve2, reject) => {
207
+ if (this.status.type === "resolved") {
208
+ resolve2(this.status.value);
209
+ } else if (this.status.type === "rejected") {
210
+ reject(this.status.error);
211
+ }
212
+ this._resolve = resolve2;
213
+ this._reject = reject;
214
+ });
215
+ return this._promise;
216
+ }
217
+ resolve(value) {
218
+ var _a;
219
+ this.status = { type: "resolved", value };
220
+ if (this._promise) {
221
+ (_a = this._resolve) == null ? void 0 : _a.call(this, value);
222
+ }
223
+ }
224
+ reject(error) {
225
+ var _a;
226
+ this.status = { type: "rejected", error };
227
+ if (this._promise) {
228
+ (_a = this._reject) == null ? void 0 : _a.call(this, error);
229
+ }
230
+ }
231
+ isResolved() {
232
+ return this.status.type === "resolved";
233
+ }
234
+ isRejected() {
235
+ return this.status.type === "rejected";
236
+ }
237
+ isPending() {
238
+ return this.status.type === "pending";
239
+ }
240
+ };
241
+
167
242
  // src/extract-response-headers.ts
168
243
  function extractResponseHeaders(response) {
169
244
  return Object.fromEntries([...response.headers]);
@@ -303,7 +378,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
303
378
  }
304
379
 
305
380
  // src/version.ts
306
- var VERSION = true ? "4.0.0-beta.37" : "0.0.0-test";
381
+ var VERSION = true ? "4.0.0-beta.39" : "0.0.0-test";
307
382
 
308
383
  // src/get-from-api.ts
309
384
  var getOriginalFetch = () => globalThis.fetch;
@@ -2178,7 +2253,6 @@ function dynamicTool(tool2) {
2178
2253
  // src/provider-defined-tool-factory.ts
2179
2254
  function createProviderDefinedToolFactory({
2180
2255
  id,
2181
- name,
2182
2256
  inputSchema
2183
2257
  }) {
2184
2258
  return ({
@@ -2193,7 +2267,6 @@ function createProviderDefinedToolFactory({
2193
2267
  }) => tool({
2194
2268
  type: "provider-defined",
2195
2269
  id,
2196
- name,
2197
2270
  args,
2198
2271
  inputSchema,
2199
2272
  outputSchema,
@@ -2207,7 +2280,6 @@ function createProviderDefinedToolFactory({
2207
2280
  }
2208
2281
  function createProviderDefinedToolFactoryWithOutputSchema({
2209
2282
  id,
2210
- name,
2211
2283
  inputSchema,
2212
2284
  outputSchema
2213
2285
  }) {
@@ -2222,7 +2294,6 @@ function createProviderDefinedToolFactoryWithOutputSchema({
2222
2294
  }) => tool({
2223
2295
  type: "provider-defined",
2224
2296
  id,
2225
- name,
2226
2297
  args,
2227
2298
  inputSchema,
2228
2299
  outputSchema,
@@ -2441,6 +2512,7 @@ __reExport(src_exports, require("@standard-schema/spec"), module.exports);
2441
2512
  var import_stream2 = require("eventsource-parser/stream");
2442
2513
  // Annotate the CommonJS export names for ESM import in node:
2443
2514
  0 && (module.exports = {
2515
+ DelayedPromise,
2444
2516
  EventSourceParserStream,
2445
2517
  VERSION,
2446
2518
  asSchema,
@@ -2457,6 +2529,7 @@ var import_stream2 = require("eventsource-parser/stream");
2457
2529
  createProviderDefinedToolFactory,
2458
2530
  createProviderDefinedToolFactoryWithOutputSchema,
2459
2531
  createStatusCodeErrorResponseHandler,
2532
+ createToolNameMapping,
2460
2533
  delay,
2461
2534
  dynamicTool,
2462
2535
  executeTool,