@ai-sdk/provider-utils 4.0.0-beta.16 → 4.0.0-beta.18

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
+ ## 4.0.0-beta.18
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [81d4308]
8
+ - @ai-sdk/provider@3.0.0-beta.7
9
+
10
+ ## 4.0.0-beta.17
11
+
12
+ ### Patch Changes
13
+
14
+ - 703459a: feat: tool execution approval for dynamic tools
15
+
3
16
  ## 4.0.0-beta.16
4
17
 
5
18
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -641,6 +641,26 @@ interface ToolCallOptions {
641
641
  */
642
642
  experimental_context?: unknown;
643
643
  }
644
+ /**
645
+ * Function that is called to determine if the tool needs approval before it can be executed.
646
+ */
647
+ type ToolNeedsApprovalFunction<INPUT> = (input: INPUT, options: {
648
+ /**
649
+ * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
650
+ */
651
+ toolCallId: string;
652
+ /**
653
+ * Messages that were sent to the language model to initiate the response that contained the tool call.
654
+ * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
655
+ */
656
+ messages: ModelMessage[];
657
+ /**
658
+ * Additional context.
659
+ *
660
+ * Experimental (can break in patch releases).
661
+ */
662
+ experimental_context?: unknown;
663
+ }) => boolean | PromiseLike<boolean>;
644
664
  type ToolExecuteFunction<INPUT, OUTPUT> = (input: INPUT, options: ToolCallOptions) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT;
645
665
  type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
646
666
  type ToolOutputProperties<INPUT, OUTPUT> = NeverOptional<OUTPUT, {
@@ -685,23 +705,7 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
685
705
  /**
686
706
  Whether the tool needs approval before it can be executed.
687
707
  */
688
- needsApproval?: boolean | ((input: [INPUT] extends [never] ? unknown : INPUT, options: {
689
- /**
690
- * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
691
- */
692
- toolCallId: string;
693
- /**
694
- * Messages that were sent to the language model to initiate the response that contained the tool call.
695
- * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
696
- */
697
- messages: ModelMessage[];
698
- /**
699
- * Additional context.
700
- *
701
- * Experimental (can break in patch releases).
702
- */
703
- experimental_context?: unknown;
704
- }) => boolean | PromiseLike<boolean>);
708
+ needsApproval?: boolean | ToolNeedsApprovalFunction<[INPUT] extends [never] ? unknown : INPUT>;
705
709
  /**
706
710
  * Optional function that is called when the argument streaming starts.
707
711
  * Only called when the tool is used in a streaming context.
@@ -773,7 +777,7 @@ declare function tool<INPUT>(tool: Tool<INPUT, never>): Tool<INPUT, never>;
773
777
  declare function tool<OUTPUT>(tool: Tool<never, OUTPUT>): Tool<never, OUTPUT>;
774
778
  declare function tool(tool: Tool<never, never>): Tool<never, never>;
775
779
  /**
776
- Helper function for defining a dynamic tool.
780
+ * Defines a dynamic tool.
777
781
  */
778
782
  declare function dynamicTool(tool: {
779
783
  description?: string;
@@ -781,6 +785,10 @@ declare function dynamicTool(tool: {
781
785
  inputSchema: FlexibleSchema<unknown>;
782
786
  execute: ToolExecuteFunction<unknown, unknown>;
783
787
  toModelOutput?: (output: unknown) => LanguageModelV3ToolResultPart['output'];
788
+ /**
789
+ * Whether the tool needs approval before it can be executed.
790
+ */
791
+ needsApproval?: boolean | ToolNeedsApprovalFunction<unknown>;
784
792
  }): Tool<unknown, unknown> & {
785
793
  type: 'dynamic';
786
794
  };
@@ -953,4 +961,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
953
961
  dynamic?: boolean;
954
962
  }
955
963
 
956
- export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, 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 ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
964
+ export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, 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 ToolModelMessage, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
package/dist/index.d.ts CHANGED
@@ -641,6 +641,26 @@ interface ToolCallOptions {
641
641
  */
642
642
  experimental_context?: unknown;
643
643
  }
644
+ /**
645
+ * Function that is called to determine if the tool needs approval before it can be executed.
646
+ */
647
+ type ToolNeedsApprovalFunction<INPUT> = (input: INPUT, options: {
648
+ /**
649
+ * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
650
+ */
651
+ toolCallId: string;
652
+ /**
653
+ * Messages that were sent to the language model to initiate the response that contained the tool call.
654
+ * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
655
+ */
656
+ messages: ModelMessage[];
657
+ /**
658
+ * Additional context.
659
+ *
660
+ * Experimental (can break in patch releases).
661
+ */
662
+ experimental_context?: unknown;
663
+ }) => boolean | PromiseLike<boolean>;
644
664
  type ToolExecuteFunction<INPUT, OUTPUT> = (input: INPUT, options: ToolCallOptions) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT;
645
665
  type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
646
666
  type ToolOutputProperties<INPUT, OUTPUT> = NeverOptional<OUTPUT, {
@@ -685,23 +705,7 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
685
705
  /**
686
706
  Whether the tool needs approval before it can be executed.
687
707
  */
688
- needsApproval?: boolean | ((input: [INPUT] extends [never] ? unknown : INPUT, options: {
689
- /**
690
- * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
691
- */
692
- toolCallId: string;
693
- /**
694
- * Messages that were sent to the language model to initiate the response that contained the tool call.
695
- * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
696
- */
697
- messages: ModelMessage[];
698
- /**
699
- * Additional context.
700
- *
701
- * Experimental (can break in patch releases).
702
- */
703
- experimental_context?: unknown;
704
- }) => boolean | PromiseLike<boolean>);
708
+ needsApproval?: boolean | ToolNeedsApprovalFunction<[INPUT] extends [never] ? unknown : INPUT>;
705
709
  /**
706
710
  * Optional function that is called when the argument streaming starts.
707
711
  * Only called when the tool is used in a streaming context.
@@ -773,7 +777,7 @@ declare function tool<INPUT>(tool: Tool<INPUT, never>): Tool<INPUT, never>;
773
777
  declare function tool<OUTPUT>(tool: Tool<never, OUTPUT>): Tool<never, OUTPUT>;
774
778
  declare function tool(tool: Tool<never, never>): Tool<never, never>;
775
779
  /**
776
- Helper function for defining a dynamic tool.
780
+ * Defines a dynamic tool.
777
781
  */
778
782
  declare function dynamicTool(tool: {
779
783
  description?: string;
@@ -781,6 +785,10 @@ declare function dynamicTool(tool: {
781
785
  inputSchema: FlexibleSchema<unknown>;
782
786
  execute: ToolExecuteFunction<unknown, unknown>;
783
787
  toModelOutput?: (output: unknown) => LanguageModelV3ToolResultPart['output'];
788
+ /**
789
+ * Whether the tool needs approval before it can be executed.
790
+ */
791
+ needsApproval?: boolean | ToolNeedsApprovalFunction<unknown>;
784
792
  }): Tool<unknown, unknown> & {
785
793
  type: 'dynamic';
786
794
  };
@@ -953,4 +961,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
953
961
  dynamic?: boolean;
954
962
  }
955
963
 
956
- export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, 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 ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
964
+ export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, 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 ToolModelMessage, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
package/dist/index.js CHANGED
@@ -280,7 +280,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
280
280
  }
281
281
 
282
282
  // src/version.ts
283
- var VERSION = true ? "4.0.0-beta.16" : "0.0.0-test";
283
+ var VERSION = true ? "4.0.0-beta.18" : "0.0.0-test";
284
284
 
285
285
  // src/get-from-api.ts
286
286
  var getOriginalFetch = () => globalThis.fetch;