@ai-sdk/provider-utils 5.0.0-canary.39 → 5.0.0-canary.41

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,18 @@
1
1
  # @ai-sdk/provider-utils
2
2
 
3
+ ## 5.0.0-canary.41
4
+
5
+ ### Patch Changes
6
+
7
+ - 28dfa06: fix: support tools with optional context
8
+ - e93fa91: rename Sandbox.executeCommand to Sandbox.runCommand
9
+
10
+ ## 5.0.0-canary.40
11
+
12
+ ### Patch Changes
13
+
14
+ - a7de9c9: fix: make sandbox experimental
15
+
3
16
  ## 5.0.0-canary.39
4
17
 
5
18
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1285,7 +1285,7 @@ type ModelMessage = SystemModelMessage | UserModelMessage | AssistantModelMessag
1285
1285
  /**
1286
1286
  * Sandbox environment that can execute commands.
1287
1287
  */
1288
- type Sandbox = {
1288
+ type Experimental_Sandbox = {
1289
1289
  /**
1290
1290
  * Description of the sandbox environment that can be added to the agent's instructions
1291
1291
  * so that the agent knows about relevant details such as the root directory, exposed
@@ -1293,9 +1293,9 @@ type Sandbox = {
1293
1293
  */
1294
1294
  readonly description: string;
1295
1295
  /**
1296
- * Execute a command in the sandbox.
1296
+ * Run a command in the sandbox.
1297
1297
  */
1298
- readonly executeCommand: (options: {
1298
+ readonly runCommand: (options: {
1299
1299
  /**
1300
1300
  * Command to execute in the sandbox.
1301
1301
  */
@@ -1356,7 +1356,7 @@ interface ToolExecutionOptions<CONTEXT extends Context | unknown | never> {
1356
1356
  /**
1357
1357
  * The sandbox environment that the tool is operating in.
1358
1358
  */
1359
- sandbox?: Sandbox;
1359
+ experimental_sandbox?: Experimental_Sandbox;
1360
1360
  }
1361
1361
  /**
1362
1362
  * Function that executes the tool and returns either a single result or a stream of results.
@@ -1519,12 +1519,12 @@ type BaseFunctionTool<INPUT extends JSONValue | unknown | never = any, OUTPUT ex
1519
1519
  * decide when and how to call the tool.
1520
1520
  *
1521
1521
  * Provide a string for a fixed description, or a function that returns a
1522
- * string from the current `context` (and optional `sandbox`) when the
1522
+ * string from the current `context` (and optional `experimental_sandbox`) when the
1523
1523
  * description should vary per call.
1524
1524
  */
1525
1525
  description?: string | ((options: {
1526
1526
  context: NoInfer<CONTEXT>;
1527
- sandbox?: Sandbox;
1527
+ experimental_sandbox?: Experimental_Sandbox;
1528
1528
  }) => string);
1529
1529
  /**
1530
1530
  * Strict mode setting for the tool.
@@ -1971,10 +1971,25 @@ type ExecutableTool<TOOL extends Tool = Tool> = TOOL & {
1971
1971
  */
1972
1972
  declare function isExecutableTool<TOOL extends Tool>(tool: TOOL | undefined): tool is ExecutableTool<TOOL>;
1973
1973
 
1974
+ /**
1975
+ * Detects the `any` type so untyped tools can be treated as having no explicit
1976
+ * context type.
1977
+ */
1978
+ type IsAny<T> = 0 extends 1 & T ? true : false;
1979
+ /**
1980
+ * Detects exact empty object contexts, including `{}` combined with
1981
+ * `undefined`, which do not provide tool-specific context properties.
1982
+ */
1983
+ type IsEmptyObject<T> = keyof NonNullable<T> extends never ? true : false;
1984
+ /**
1985
+ * Detects context types that come from omitted or broad context declarations
1986
+ * rather than a concrete tool context schema.
1987
+ */
1988
+ type IsUntypedContext<CONTEXT> = IsAny<CONTEXT> extends true ? true : unknown extends CONTEXT ? true : IsEmptyObject<CONTEXT> extends true ? true : string extends keyof CONTEXT ? CONTEXT extends Context ? true : false : false;
1974
1989
  /**
1975
1990
  * Infer the context type of a tool.
1976
1991
  */
1977
- type InferToolContext<TOOL extends Tool> = TOOL extends Tool<any, any, infer CONTEXT> ? HasRequiredKey<CONTEXT> extends true ? CONTEXT : never : never;
1992
+ type InferToolContext<TOOL extends Tool> = TOOL extends Tool<any, any, infer CONTEXT> ? IsUntypedContext<CONTEXT> extends true ? never : CONTEXT : never;
1978
1993
 
1979
1994
  /**
1980
1995
  * Infer the input type of a tool.
@@ -2017,16 +2032,36 @@ declare function executeTool<TOOL extends Tool>({ tool, input, options, }: {
2017
2032
  */
2018
2033
  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'>>;
2019
2034
 
2035
+ /**
2036
+ * Builds the required portion of the tool context map for tools whose context
2037
+ * type does not include `undefined`.
2038
+ */
2039
+ type RequiredToolSetContext<TOOLS extends ToolSet> = {
2040
+ [K in keyof TOOLS as InferToolContext<NoInfer<TOOLS[K]>> extends never ? never : undefined extends InferToolContext<NoInfer<TOOLS[K]>> ? never : K]: InferToolContext<NoInfer<TOOLS[K]>>;
2041
+ };
2042
+ /**
2043
+ * Builds the optional portion of the tool context map for tools whose context
2044
+ * object itself may be `undefined`.
2045
+ */
2046
+ type OptionalToolSetContext<TOOLS extends ToolSet> = {
2047
+ [K in keyof TOOLS as InferToolContext<NoInfer<TOOLS[K]>> extends never ? never : undefined extends InferToolContext<NoInfer<TOOLS[K]>> ? K : never]?: InferToolContext<NoInfer<TOOLS[K]>>;
2048
+ };
2049
+ /**
2050
+ * Flattens intersected mapped types so type equality assertions and editor
2051
+ * hovers show the resulting object shape.
2052
+ */
2053
+ type Normalize<OBJECT> = {
2054
+ [KEY in keyof OBJECT]: OBJECT[KEY];
2055
+ };
2020
2056
  /**
2021
2057
  * Infer the context type for a tool set.
2022
2058
  *
2023
- * The inferred type maps each tool name to its required context type.
2059
+ * The inferred type maps each contextual tool name to its context type.
2024
2060
  *
2025
- * Tools without required context properties are omitted from the result.
2061
+ * Tools without concrete context are omitted. Tool contexts that include
2062
+ * `undefined` are represented as optional properties.
2026
2063
  */
2027
- type InferToolSetContext<TOOLS extends ToolSet> = {
2028
- [K in keyof TOOLS as InferToolContext<NoInfer<TOOLS[K]>> extends never ? never : K]: InferToolContext<NoInfer<TOOLS[K]>>;
2029
- };
2064
+ type InferToolSetContext<TOOLS extends ToolSet> = Normalize<RequiredToolSetContext<TOOLS> & OptionalToolSetContext<TOOLS>>;
2030
2065
 
2031
2066
  /**
2032
2067
  * Typed tool call that is returned by generateText and streamText.
@@ -2087,4 +2122,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
2087
2122
  dynamic?: boolean;
2088
2123
  }
2089
2124
 
2090
- export { type Arrayable, type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type DynamicTool, type ExecutableTool, type FetchFunction, type FileData, type FileDataData, type FileDataReference, type FileDataText, type FileDataUrl, type FilePart, type FlexibleSchema, type FunctionTool, type HasRequiredKey, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type InferToolSetContext, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderDefinedTool, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderExecutedTool, type ProviderExecutedToolFactory, type ProviderOptions, type ProviderReference, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Sandbox, type Schema, type StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, 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, asArray, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertInlineFileDataToUint8Array, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, detectMediaType, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, filterNullable, generateId, getFromApi, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, injectJsonInstructionIntoMessages, isAbortError, isBuffer, isCustomReasoning, isExecutableTool, isFullMediaType, isNonNullable, isParsableJson, isProviderReference, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, resolveFullMediaType, resolveProviderReference, safeParseJSON, safeValidateTypes, serializeModelOptions, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
2125
+ export { type Arrayable, type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type DynamicTool, type ExecutableTool, type Experimental_Sandbox, type FetchFunction, type FileData, type FileDataData, type FileDataReference, type FileDataText, type FileDataUrl, type FilePart, type FlexibleSchema, type FunctionTool, type HasRequiredKey, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type InferToolSetContext, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderDefinedTool, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderExecutedTool, type ProviderExecutedToolFactory, type ProviderOptions, type ProviderReference, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, 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, asArray, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertInlineFileDataToUint8Array, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, detectMediaType, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, filterNullable, generateId, getFromApi, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, injectJsonInstructionIntoMessages, isAbortError, isBuffer, isCustomReasoning, isExecutableTool, isFullMediaType, isNonNullable, isParsableJson, isProviderReference, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, resolveFullMediaType, resolveProviderReference, safeParseJSON, safeValidateTypes, serializeModelOptions, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
package/dist/index.js CHANGED
@@ -862,7 +862,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
862
862
  }
863
863
 
864
864
  // src/version.ts
865
- var VERSION = true ? "5.0.0-canary.39" : "0.0.0-test";
865
+ var VERSION = true ? "5.0.0-canary.41" : "0.0.0-test";
866
866
 
867
867
  // src/get-from-api.ts
868
868
  var getOriginalFetch = () => globalThis.fetch;