@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/provider-utils",
3
- "version": "4.0.15",
3
+ "version": "4.0.17",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -33,6 +33,7 @@ export interface ToolNameMapping {
33
33
  export function createToolNameMapping({
34
34
  tools = [],
35
35
  providerToolNames,
36
+ resolveProviderToolName,
36
37
  }: {
37
38
  /**
38
39
  * Tools that were passed to the language model.
@@ -45,13 +46,28 @@ export function createToolNameMapping({
45
46
  * Maps the provider tool ids to the provider tool names.
46
47
  */
47
48
  providerToolNames: Record<`${string}.${string}`, string>;
49
+
50
+ /**
51
+ * Optional resolver for provider tool names that cannot be represented as
52
+ * static id -> name mappings (e.g. dynamic provider names).
53
+ */
54
+ resolveProviderToolName?: (
55
+ tool: LanguageModelV3ProviderTool,
56
+ ) => string | undefined;
48
57
  }): ToolNameMapping {
49
58
  const customToolNameToProviderToolName: Record<string, string> = {};
50
59
  const providerToolNameToCustomToolName: Record<string, string> = {};
51
60
 
52
61
  for (const tool of tools) {
53
- if (tool.type === 'provider' && tool.id in providerToolNames) {
54
- const providerToolName = providerToolNames[tool.id];
62
+ if (tool.type === 'provider') {
63
+ const providerToolName =
64
+ resolveProviderToolName?.(tool) ??
65
+ (tool.id in providerToolNames ? providerToolNames[tool.id] : undefined);
66
+
67
+ if (providerToolName == null) {
68
+ continue;
69
+ }
70
+
55
71
  customToolNameToProviderToolName[tool.name] = providerToolName;
56
72
  providerToolNameToCustomToolName[providerToolName] = tool.name;
57
73
  }
package/src/index.ts CHANGED
@@ -54,6 +54,7 @@ export {
54
54
  type Schema,
55
55
  type ValidationResult,
56
56
  } from './schema';
57
+ export { stripFileExtension } from './strip-file-extension';
57
58
  export * from './uint8-utils';
58
59
  export * from './validate-types';
59
60
  export { VERSION } from './version';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Strips file extension segments from a filename.
3
+ *
4
+ * Examples:
5
+ * - "report.pdf" -> "report"
6
+ * - "archive.tar.gz" -> "archive"
7
+ * - "filename" -> "filename"
8
+ */
9
+ export function stripFileExtension(filename: string): string {
10
+ const firstDotIndex = filename.indexOf('.');
11
+
12
+ return firstDotIndex === -1 ? filename : filename.slice(0, firstDotIndex);
13
+ }