@ai-sdk/provider-utils 4.0.15 → 4.0.17

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,17 @@
1
1
  # @ai-sdk/provider-utils
2
2
 
3
+ ## 4.0.17
4
+
5
+ ### Patch Changes
6
+
7
+ - 08336f1: fix(bedrock): strip file extensions from filename
8
+
9
+ ## 4.0.16
10
+
11
+ ### Patch Changes
12
+
13
+ - 58bc42d: feat(provider/openai): support custom tools with alias mapping
14
+
3
15
  ## 4.0.15
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -41,7 +41,7 @@ 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, }: {
44
+ declare function createToolNameMapping({ tools, providerToolNames, resolveProviderToolName, }: {
45
45
  /**
46
46
  * Tools that were passed to the language model.
47
47
  */
@@ -50,6 +50,11 @@ declare function createToolNameMapping({ tools, providerToolNames, }: {
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;
53
58
  }): ToolNameMapping;
54
59
 
55
60
  /**
@@ -1271,6 +1276,16 @@ type Resolvable<T> = MaybePromiseLike<T> | (() => MaybePromiseLike<T>);
1271
1276
  */
1272
1277
  declare function resolve<T>(value: Resolvable<T>): Promise<T>;
1273
1278
 
1279
+ /**
1280
+ * Strips file extension segments from a filename.
1281
+ *
1282
+ * Examples:
1283
+ * - "report.pdf" -> "report"
1284
+ * - "archive.tar.gz" -> "archive"
1285
+ * - "filename" -> "filename"
1286
+ */
1287
+ declare function stripFileExtension(filename: string): string;
1288
+
1274
1289
  declare function convertBase64ToUint8Array(base64String: string): Uint8Array<ArrayBuffer>;
1275
1290
  declare function convertUint8ArrayToBase64(array: Uint8Array): string;
1276
1291
  declare function convertToBase64(value: string | Uint8Array): string;
@@ -1406,4 +1421,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
1406
1421
  */
1407
1422
  type ToolCallOptions = ToolExecutionOptions;
1408
1423
 
1409
- export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, 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 ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, 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 ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, 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, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
1424
+ export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, 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 ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, 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 ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, 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, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
package/dist/index.d.ts CHANGED
@@ -41,7 +41,7 @@ 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, }: {
44
+ declare function createToolNameMapping({ tools, providerToolNames, resolveProviderToolName, }: {
45
45
  /**
46
46
  * Tools that were passed to the language model.
47
47
  */
@@ -50,6 +50,11 @@ declare function createToolNameMapping({ tools, providerToolNames, }: {
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;
53
58
  }): ToolNameMapping;
54
59
 
55
60
  /**
@@ -1271,6 +1276,16 @@ type Resolvable<T> = MaybePromiseLike<T> | (() => MaybePromiseLike<T>);
1271
1276
  */
1272
1277
  declare function resolve<T>(value: Resolvable<T>): Promise<T>;
1273
1278
 
1279
+ /**
1280
+ * Strips file extension segments from a filename.
1281
+ *
1282
+ * Examples:
1283
+ * - "report.pdf" -> "report"
1284
+ * - "archive.tar.gz" -> "archive"
1285
+ * - "filename" -> "filename"
1286
+ */
1287
+ declare function stripFileExtension(filename: string): string;
1288
+
1274
1289
  declare function convertBase64ToUint8Array(base64String: string): Uint8Array<ArrayBuffer>;
1275
1290
  declare function convertUint8ArrayToBase64(array: Uint8Array): string;
1276
1291
  declare function convertToBase64(value: string | Uint8Array): string;
@@ -1406,4 +1421,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
1406
1421
  */
1407
1422
  type ToolCallOptions = ToolExecutionOptions;
1408
1423
 
1409
- export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, 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 ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, 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 ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, 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, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
1424
+ export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, 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 ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, 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 ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, 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, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
package/dist/index.js CHANGED
@@ -84,6 +84,7 @@ __export(src_exports, {
84
84
  resolve: () => resolve,
85
85
  safeParseJSON: () => safeParseJSON,
86
86
  safeValidateTypes: () => safeValidateTypes,
87
+ stripFileExtension: () => stripFileExtension,
87
88
  tool: () => tool,
88
89
  validateTypes: () => validateTypes,
89
90
  withUserAgentSuffix: () => withUserAgentSuffix,
@@ -144,25 +145,30 @@ function convertAsyncIteratorToReadableStream(iterator) {
144
145
  // src/create-tool-name-mapping.ts
145
146
  function createToolNameMapping({
146
147
  tools = [],
147
- providerToolNames
148
+ providerToolNames,
149
+ resolveProviderToolName
148
150
  }) {
151
+ var _a2;
149
152
  const customToolNameToProviderToolName = {};
150
153
  const providerToolNameToCustomToolName = {};
151
154
  for (const tool2 of tools) {
152
- if (tool2.type === "provider" && tool2.id in providerToolNames) {
153
- const providerToolName = providerToolNames[tool2.id];
155
+ if (tool2.type === "provider") {
156
+ const providerToolName = (_a2 = resolveProviderToolName == null ? void 0 : resolveProviderToolName(tool2)) != null ? _a2 : tool2.id in providerToolNames ? providerToolNames[tool2.id] : void 0;
157
+ if (providerToolName == null) {
158
+ continue;
159
+ }
154
160
  customToolNameToProviderToolName[tool2.name] = providerToolName;
155
161
  providerToolNameToCustomToolName[providerToolName] = tool2.name;
156
162
  }
157
163
  }
158
164
  return {
159
165
  toProviderToolName: (customToolName) => {
160
- var _a2;
161
- return (_a2 = customToolNameToProviderToolName[customToolName]) != null ? _a2 : customToolName;
166
+ var _a3;
167
+ return (_a3 = customToolNameToProviderToolName[customToolName]) != null ? _a3 : customToolName;
162
168
  },
163
169
  toCustomToolName: (providerToolName) => {
164
- var _a2;
165
- return (_a2 = providerToolNameToCustomToolName[providerToolName]) != null ? _a2 : providerToolName;
170
+ var _a3;
171
+ return (_a3 = providerToolNameToCustomToolName[providerToolName]) != null ? _a3 : providerToolName;
166
172
  }
167
173
  };
168
174
  }
@@ -568,7 +574,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
568
574
  }
569
575
 
570
576
  // src/version.ts
571
- var VERSION = true ? "4.0.15" : "0.0.0-test";
577
+ var VERSION = true ? "4.0.17" : "0.0.0-test";
572
578
 
573
579
  // src/get-from-api.ts
574
580
  var getOriginalFetch = () => globalThis.fetch;
@@ -2636,6 +2642,12 @@ var createStatusCodeErrorResponseHandler = () => async ({ response, url, request
2636
2642
  };
2637
2643
  };
2638
2644
 
2645
+ // src/strip-file-extension.ts
2646
+ function stripFileExtension(filename) {
2647
+ const firstDotIndex = filename.indexOf(".");
2648
+ return firstDotIndex === -1 ? filename : filename.slice(0, firstDotIndex);
2649
+ }
2650
+
2639
2651
  // src/without-trailing-slash.ts
2640
2652
  function withoutTrailingSlash(url) {
2641
2653
  return url == null ? void 0 : url.replace(/\/$/, "");
@@ -2723,6 +2735,7 @@ var import_stream2 = require("eventsource-parser/stream");
2723
2735
  resolve,
2724
2736
  safeParseJSON,
2725
2737
  safeValidateTypes,
2738
+ stripFileExtension,
2726
2739
  tool,
2727
2740
  validateTypes,
2728
2741
  withUserAgentSuffix,