@ai-sdk/provider-utils 4.0.15 → 4.0.16

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,11 @@
1
1
  # @ai-sdk/provider-utils
2
2
 
3
+ ## 4.0.16
4
+
5
+ ### Patch Changes
6
+
7
+ - 58bc42d: feat(provider/openai): support custom tools with alias mapping
8
+
3
9
  ## 4.0.15
4
10
 
5
11
  ### 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
  /**
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
  /**
package/dist/index.js CHANGED
@@ -144,25 +144,30 @@ function convertAsyncIteratorToReadableStream(iterator) {
144
144
  // src/create-tool-name-mapping.ts
145
145
  function createToolNameMapping({
146
146
  tools = [],
147
- providerToolNames
147
+ providerToolNames,
148
+ resolveProviderToolName
148
149
  }) {
150
+ var _a2;
149
151
  const customToolNameToProviderToolName = {};
150
152
  const providerToolNameToCustomToolName = {};
151
153
  for (const tool2 of tools) {
152
- if (tool2.type === "provider" && tool2.id in providerToolNames) {
153
- const providerToolName = providerToolNames[tool2.id];
154
+ if (tool2.type === "provider") {
155
+ const providerToolName = (_a2 = resolveProviderToolName == null ? void 0 : resolveProviderToolName(tool2)) != null ? _a2 : tool2.id in providerToolNames ? providerToolNames[tool2.id] : void 0;
156
+ if (providerToolName == null) {
157
+ continue;
158
+ }
154
159
  customToolNameToProviderToolName[tool2.name] = providerToolName;
155
160
  providerToolNameToCustomToolName[providerToolName] = tool2.name;
156
161
  }
157
162
  }
158
163
  return {
159
164
  toProviderToolName: (customToolName) => {
160
- var _a2;
161
- return (_a2 = customToolNameToProviderToolName[customToolName]) != null ? _a2 : customToolName;
165
+ var _a3;
166
+ return (_a3 = customToolNameToProviderToolName[customToolName]) != null ? _a3 : customToolName;
162
167
  },
163
168
  toCustomToolName: (providerToolName) => {
164
- var _a2;
165
- return (_a2 = providerToolNameToCustomToolName[providerToolName]) != null ? _a2 : providerToolName;
169
+ var _a3;
170
+ return (_a3 = providerToolNameToCustomToolName[providerToolName]) != null ? _a3 : providerToolName;
166
171
  }
167
172
  };
168
173
  }
@@ -568,7 +573,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
568
573
  }
569
574
 
570
575
  // src/version.ts
571
- var VERSION = true ? "4.0.15" : "0.0.0-test";
576
+ var VERSION = true ? "4.0.16" : "0.0.0-test";
572
577
 
573
578
  // src/get-from-api.ts
574
579
  var getOriginalFetch = () => globalThis.fetch;