@ai-sdk/provider-utils 5.0.0-beta.8 → 5.0.0-beta.9

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,13 @@
1
1
  # @ai-sdk/provider-utils
2
2
 
3
+ ## 5.0.0-beta.9
4
+
5
+ ### Patch Changes
6
+
7
+ - 2e17091: fix(types): move shared tool set utility types into provider-utils
8
+
9
+ Moved `ToolSet`, `InferToolSetContext`, and `UnionToIntersection` into `@ai-sdk/provider-utils` and updated `ai` internals to import them directly from there. This keeps the shared tool typing utilities colocated with the core tool type definitions.
10
+
3
11
  ## 5.0.0-beta.8
4
12
 
5
13
  ### Major Changes
package/dist/index.d.mts CHANGED
@@ -1485,6 +1485,37 @@ type InferToolInput<TOOL extends Tool<any, any, any>> = TOOL extends Tool<infer
1485
1485
  */
1486
1486
  type InferToolOutput<TOOL extends Tool<any, any, any>> = TOOL extends Tool<any, infer OUTPUT, any> ? OUTPUT : never;
1487
1487
 
1488
+ /**
1489
+ * A mapping of tool names to tool definitions.
1490
+ */
1491
+ type ToolSet = Record<string, (Tool<never, never, any> | Tool<any, any, any> | Tool<any, never, any> | Tool<never, any, any>) & Pick<Tool<any, any, any>, 'execute' | 'onInputAvailable' | 'onInputStart' | 'onInputDelta' | 'needsApproval'>>;
1492
+
1493
+ /**
1494
+ * Converts a union type `U` into an intersection type.
1495
+ *
1496
+ * For example:
1497
+ * type A = { a: number };
1498
+ * type B = { b: string };
1499
+ * type Union = A | B;
1500
+ * type Intersection = UnionToIntersection<Union>;
1501
+ * // Intersection is: { a: number } & { b: string }
1502
+ *
1503
+ * This is useful when you have a union of object types and need a type with all possible properties.
1504
+ */
1505
+ type UnionToIntersection<U> = (U extends unknown ? (arg: U) => void : never) extends (arg: infer I) => void ? I : never;
1506
+
1507
+ /**
1508
+ * Infer the context type for a tool set.
1509
+ *
1510
+ * The inferred type contains all properties required by the contexts of the
1511
+ * tools in the set.
1512
+ *
1513
+ * If there are incompatible properties, they will be of type `never`.
1514
+ */
1515
+ type InferToolSetContext<TOOLS extends ToolSet> = UnionToIntersection<{
1516
+ [K in keyof TOOLS]: InferToolContext<NoInfer<TOOLS[K]>>;
1517
+ }[keyof TOOLS]>;
1518
+
1488
1519
  /**
1489
1520
  * Typed tool call that is returned by generateText and streamText.
1490
1521
  * It contains the tool call ID, the tool name, and the tool arguments.
@@ -1544,4 +1575,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
1544
1575
  dynamic?: boolean;
1545
1576
  }
1546
1577
 
1547
- export { type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, 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, isCustomReasoning, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
1578
+ export { type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type InferToolSetContext, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type ToolSet, 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, isCustomReasoning, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
package/dist/index.d.ts CHANGED
@@ -1485,6 +1485,37 @@ type InferToolInput<TOOL extends Tool<any, any, any>> = TOOL extends Tool<infer
1485
1485
  */
1486
1486
  type InferToolOutput<TOOL extends Tool<any, any, any>> = TOOL extends Tool<any, infer OUTPUT, any> ? OUTPUT : never;
1487
1487
 
1488
+ /**
1489
+ * A mapping of tool names to tool definitions.
1490
+ */
1491
+ type ToolSet = Record<string, (Tool<never, never, any> | Tool<any, any, any> | Tool<any, never, any> | Tool<never, any, any>) & Pick<Tool<any, any, any>, 'execute' | 'onInputAvailable' | 'onInputStart' | 'onInputDelta' | 'needsApproval'>>;
1492
+
1493
+ /**
1494
+ * Converts a union type `U` into an intersection type.
1495
+ *
1496
+ * For example:
1497
+ * type A = { a: number };
1498
+ * type B = { b: string };
1499
+ * type Union = A | B;
1500
+ * type Intersection = UnionToIntersection<Union>;
1501
+ * // Intersection is: { a: number } & { b: string }
1502
+ *
1503
+ * This is useful when you have a union of object types and need a type with all possible properties.
1504
+ */
1505
+ type UnionToIntersection<U> = (U extends unknown ? (arg: U) => void : never) extends (arg: infer I) => void ? I : never;
1506
+
1507
+ /**
1508
+ * Infer the context type for a tool set.
1509
+ *
1510
+ * The inferred type contains all properties required by the contexts of the
1511
+ * tools in the set.
1512
+ *
1513
+ * If there are incompatible properties, they will be of type `never`.
1514
+ */
1515
+ type InferToolSetContext<TOOLS extends ToolSet> = UnionToIntersection<{
1516
+ [K in keyof TOOLS]: InferToolContext<NoInfer<TOOLS[K]>>;
1517
+ }[keyof TOOLS]>;
1518
+
1488
1519
  /**
1489
1520
  * Typed tool call that is returned by generateText and streamText.
1490
1521
  * It contains the tool call ID, the tool name, and the tool arguments.
@@ -1544,4 +1575,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
1544
1575
  dynamic?: boolean;
1545
1576
  }
1546
1577
 
1547
- export { type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, 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, isCustomReasoning, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
1578
+ export { type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type InferToolSetContext, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type ToolSet, 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, isCustomReasoning, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
package/dist/index.js CHANGED
@@ -676,7 +676,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
676
676
  }
677
677
 
678
678
  // src/version.ts
679
- var VERSION = true ? "5.0.0-beta.8" : "0.0.0-test";
679
+ var VERSION = true ? "5.0.0-beta.9" : "0.0.0-test";
680
680
 
681
681
  // src/get-from-api.ts
682
682
  var getOriginalFetch = () => globalThis.fetch;
package/dist/index.mjs CHANGED
@@ -577,7 +577,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
577
577
  }
578
578
 
579
579
  // src/version.ts
580
- var VERSION = true ? "5.0.0-beta.8" : "0.0.0-test";
580
+ var VERSION = true ? "5.0.0-beta.9" : "0.0.0-test";
581
581
 
582
582
  // src/get-from-api.ts
583
583
  var getOriginalFetch = () => globalThis.fetch;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/provider-utils",
3
- "version": "5.0.0-beta.8",
3
+ "version": "5.0.0-beta.9",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -19,6 +19,7 @@ export { executeTool } from './execute-tool';
19
19
  export type { InferToolContext } from './infer-tool-context';
20
20
  export type { InferToolInput } from './infer-tool-input';
21
21
  export type { InferToolOutput } from './infer-tool-output';
22
+ export type { InferToolSetContext } from './infer-tool-set-context';
22
23
  export type { ModelMessage } from './model-message';
23
24
  export type { ProviderOptions } from './provider-options';
24
25
  export type { SystemModelMessage } from './system-model-message';
@@ -30,6 +31,7 @@ export {
30
31
  type ToolExecutionOptions,
31
32
  type ToolNeedsApprovalFunction,
32
33
  } from './tool';
34
+ export type { ToolSet } from './tool-set';
33
35
  export type { ToolApprovalRequest } from './tool-approval-request';
34
36
  export type { ToolApprovalResponse } from './tool-approval-response';
35
37
  export type { ToolCall } from './tool-call';
@@ -0,0 +1,17 @@
1
+ import type { InferToolContext } from './infer-tool-context';
2
+ import type { ToolSet } from './tool-set';
3
+ import type { UnionToIntersection } from './union-to-intersection';
4
+
5
+ /**
6
+ * Infer the context type for a tool set.
7
+ *
8
+ * The inferred type contains all properties required by the contexts of the
9
+ * tools in the set.
10
+ *
11
+ * If there are incompatible properties, they will be of type `never`.
12
+ */
13
+ export type InferToolSetContext<TOOLS extends ToolSet> = UnionToIntersection<
14
+ {
15
+ [K in keyof TOOLS]: InferToolContext<NoInfer<TOOLS[K]>>;
16
+ }[keyof TOOLS]
17
+ >;
@@ -0,0 +1,22 @@
1
+ import type { Tool } from './tool';
2
+
3
+ /**
4
+ * A mapping of tool names to tool definitions.
5
+ */
6
+ export type ToolSet = Record<
7
+ string,
8
+ (
9
+ | Tool<never, never, any>
10
+ | Tool<any, any, any>
11
+ | Tool<any, never, any>
12
+ | Tool<never, any, any>
13
+ ) &
14
+ Pick<
15
+ Tool<any, any, any>,
16
+ | 'execute'
17
+ | 'onInputAvailable'
18
+ | 'onInputStart'
19
+ | 'onInputDelta'
20
+ | 'needsApproval'
21
+ >
22
+ >;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Converts a union type `U` into an intersection type.
3
+ *
4
+ * For example:
5
+ * type A = { a: number };
6
+ * type B = { b: string };
7
+ * type Union = A | B;
8
+ * type Intersection = UnionToIntersection<Union>;
9
+ * // Intersection is: { a: number } & { b: string }
10
+ *
11
+ * This is useful when you have a union of object types and need a type with all possible properties.
12
+ */
13
+ export type UnionToIntersection<U> = (
14
+ U extends unknown ? (arg: U) => void : never
15
+ ) extends (arg: infer I) => void
16
+ ? I
17
+ : never;