@ai-sdk/provider-utils 3.1.0-beta.6 → 3.1.0-beta.8
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 +15 -0
- package/dist/index.d.mts +43 -3
- package/dist/index.d.ts +43 -3
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# @ai-sdk/provider-utils
|
2
2
|
|
3
|
+
## 3.1.0-beta.8
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- e06565c: feat(provider-utils): add needsApproval support to provider-defined tools
|
8
|
+
|
9
|
+
## 3.1.0-beta.7
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- e8109d3: feat: tool execution approval
|
14
|
+
- Updated dependencies [046aa3b]
|
15
|
+
- Updated dependencies [e8109d3]
|
16
|
+
- @ai-sdk/provider@2.1.0-beta.5
|
17
|
+
|
3
18
|
## 3.1.0-beta.6
|
4
19
|
|
5
20
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
@@ -517,6 +517,21 @@ interface ToolResultPart {
|
|
517
517
|
providerOptions?: ProviderOptions;
|
518
518
|
}
|
519
519
|
|
520
|
+
/**
|
521
|
+
* Tool approval request prompt part.
|
522
|
+
*/
|
523
|
+
type ToolApprovalRequest = {
|
524
|
+
type: 'tool-approval-request';
|
525
|
+
/**
|
526
|
+
* ID of the tool approval.
|
527
|
+
*/
|
528
|
+
approvalId: string;
|
529
|
+
/**
|
530
|
+
* ID of the tool call that the approval request is for.
|
531
|
+
*/
|
532
|
+
toolCallId: string;
|
533
|
+
};
|
534
|
+
|
520
535
|
/**
|
521
536
|
An assistant message. It can contain text, tool calls, or a combination of text and tool calls.
|
522
537
|
*/
|
@@ -534,7 +549,7 @@ type AssistantModelMessage = {
|
|
534
549
|
Content of an assistant message.
|
535
550
|
It can be a string or an array of text, image, reasoning, redacted reasoning, and tool call parts.
|
536
551
|
*/
|
537
|
-
type AssistantContent = string | Array<TextPart | FilePart | ReasoningPart | ToolCallPart | ToolResultPart>;
|
552
|
+
type AssistantContent = string | Array<TextPart | FilePart | ReasoningPart | ToolCallPart | ToolResultPart | ToolApprovalRequest>;
|
538
553
|
|
539
554
|
/**
|
540
555
|
A system message. It can contain system information.
|
@@ -554,6 +569,25 @@ type SystemModelMessage = {
|
|
554
569
|
providerOptions?: ProviderOptions;
|
555
570
|
};
|
556
571
|
|
572
|
+
/**
|
573
|
+
* Tool approval response prompt part.
|
574
|
+
*/
|
575
|
+
type ToolApprovalResponse = {
|
576
|
+
type: 'tool-approval-response';
|
577
|
+
/**
|
578
|
+
* ID of the tool approval.
|
579
|
+
*/
|
580
|
+
approvalId: string;
|
581
|
+
/**
|
582
|
+
* Flag indicating whether the approval was granted or denied.
|
583
|
+
*/
|
584
|
+
approved: boolean;
|
585
|
+
/**
|
586
|
+
* Optional reason for the approval or denial.
|
587
|
+
*/
|
588
|
+
reason?: string;
|
589
|
+
};
|
590
|
+
|
557
591
|
/**
|
558
592
|
A tool message. It contains the result of one or more tool calls.
|
559
593
|
*/
|
@@ -570,7 +604,7 @@ type ToolModelMessage = {
|
|
570
604
|
/**
|
571
605
|
Content of a tool message. It is an array of tool result parts.
|
572
606
|
*/
|
573
|
-
type ToolContent = Array<ToolResultPart>;
|
607
|
+
type ToolContent = Array<ToolResultPart | ToolApprovalResponse>;
|
574
608
|
|
575
609
|
/**
|
576
610
|
A user message. It can contain text or a combination of text and images.
|
@@ -662,6 +696,10 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
|
|
662
696
|
*/
|
663
697
|
inputSchema: FlexibleSchema<INPUT>;
|
664
698
|
/**
|
699
|
+
Whether the tool needs approval before it can be executed.
|
700
|
+
*/
|
701
|
+
needsApproval?: boolean;
|
702
|
+
/**
|
665
703
|
* Optional function that is called when the argument streaming starts.
|
666
704
|
* Only called when the tool is used in a streaming context.
|
667
705
|
*/
|
@@ -746,6 +784,7 @@ declare function dynamicTool(tool: {
|
|
746
784
|
|
747
785
|
type ProviderDefinedToolFactory<INPUT, ARGS extends object> = <OUTPUT>(options: ARGS & {
|
748
786
|
execute?: ToolExecuteFunction<INPUT, OUTPUT>;
|
787
|
+
needsApproval?: Tool<INPUT, OUTPUT>['needsApproval'];
|
749
788
|
toModelOutput?: Tool<INPUT, OUTPUT>['toModelOutput'];
|
750
789
|
onInputStart?: Tool<INPUT, OUTPUT>['onInputStart'];
|
751
790
|
onInputDelta?: Tool<INPUT, OUTPUT>['onInputDelta'];
|
@@ -758,6 +797,7 @@ declare function createProviderDefinedToolFactory<INPUT, ARGS extends object>({
|
|
758
797
|
}): ProviderDefinedToolFactory<INPUT, ARGS>;
|
759
798
|
type ProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object> = (options: ARGS & {
|
760
799
|
execute?: ToolExecuteFunction<INPUT, OUTPUT>;
|
800
|
+
needsApproval?: Tool<INPUT, OUTPUT>['needsApproval'];
|
761
801
|
toModelOutput?: Tool<INPUT, OUTPUT>['toModelOutput'];
|
762
802
|
onInputStart?: Tool<INPUT, OUTPUT>['onInputStart'];
|
763
803
|
onInputDelta?: Tool<INPUT, OUTPUT>['onInputDelta'];
|
@@ -908,4 +948,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
908
948
|
|
909
949
|
declare const VERSION: string;
|
910
950
|
|
911
|
-
export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, 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 ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type Validator, asSchema, asValidator, 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, isValidator, jsonSchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateTypes, validator, validatorSymbol, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
951
|
+
export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, 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, type Validator, asSchema, asValidator, 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, isValidator, jsonSchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateTypes, validator, validatorSymbol, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.d.ts
CHANGED
@@ -517,6 +517,21 @@ interface ToolResultPart {
|
|
517
517
|
providerOptions?: ProviderOptions;
|
518
518
|
}
|
519
519
|
|
520
|
+
/**
|
521
|
+
* Tool approval request prompt part.
|
522
|
+
*/
|
523
|
+
type ToolApprovalRequest = {
|
524
|
+
type: 'tool-approval-request';
|
525
|
+
/**
|
526
|
+
* ID of the tool approval.
|
527
|
+
*/
|
528
|
+
approvalId: string;
|
529
|
+
/**
|
530
|
+
* ID of the tool call that the approval request is for.
|
531
|
+
*/
|
532
|
+
toolCallId: string;
|
533
|
+
};
|
534
|
+
|
520
535
|
/**
|
521
536
|
An assistant message. It can contain text, tool calls, or a combination of text and tool calls.
|
522
537
|
*/
|
@@ -534,7 +549,7 @@ type AssistantModelMessage = {
|
|
534
549
|
Content of an assistant message.
|
535
550
|
It can be a string or an array of text, image, reasoning, redacted reasoning, and tool call parts.
|
536
551
|
*/
|
537
|
-
type AssistantContent = string | Array<TextPart | FilePart | ReasoningPart | ToolCallPart | ToolResultPart>;
|
552
|
+
type AssistantContent = string | Array<TextPart | FilePart | ReasoningPart | ToolCallPart | ToolResultPart | ToolApprovalRequest>;
|
538
553
|
|
539
554
|
/**
|
540
555
|
A system message. It can contain system information.
|
@@ -554,6 +569,25 @@ type SystemModelMessage = {
|
|
554
569
|
providerOptions?: ProviderOptions;
|
555
570
|
};
|
556
571
|
|
572
|
+
/**
|
573
|
+
* Tool approval response prompt part.
|
574
|
+
*/
|
575
|
+
type ToolApprovalResponse = {
|
576
|
+
type: 'tool-approval-response';
|
577
|
+
/**
|
578
|
+
* ID of the tool approval.
|
579
|
+
*/
|
580
|
+
approvalId: string;
|
581
|
+
/**
|
582
|
+
* Flag indicating whether the approval was granted or denied.
|
583
|
+
*/
|
584
|
+
approved: boolean;
|
585
|
+
/**
|
586
|
+
* Optional reason for the approval or denial.
|
587
|
+
*/
|
588
|
+
reason?: string;
|
589
|
+
};
|
590
|
+
|
557
591
|
/**
|
558
592
|
A tool message. It contains the result of one or more tool calls.
|
559
593
|
*/
|
@@ -570,7 +604,7 @@ type ToolModelMessage = {
|
|
570
604
|
/**
|
571
605
|
Content of a tool message. It is an array of tool result parts.
|
572
606
|
*/
|
573
|
-
type ToolContent = Array<ToolResultPart>;
|
607
|
+
type ToolContent = Array<ToolResultPart | ToolApprovalResponse>;
|
574
608
|
|
575
609
|
/**
|
576
610
|
A user message. It can contain text or a combination of text and images.
|
@@ -662,6 +696,10 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
|
|
662
696
|
*/
|
663
697
|
inputSchema: FlexibleSchema<INPUT>;
|
664
698
|
/**
|
699
|
+
Whether the tool needs approval before it can be executed.
|
700
|
+
*/
|
701
|
+
needsApproval?: boolean;
|
702
|
+
/**
|
665
703
|
* Optional function that is called when the argument streaming starts.
|
666
704
|
* Only called when the tool is used in a streaming context.
|
667
705
|
*/
|
@@ -746,6 +784,7 @@ declare function dynamicTool(tool: {
|
|
746
784
|
|
747
785
|
type ProviderDefinedToolFactory<INPUT, ARGS extends object> = <OUTPUT>(options: ARGS & {
|
748
786
|
execute?: ToolExecuteFunction<INPUT, OUTPUT>;
|
787
|
+
needsApproval?: Tool<INPUT, OUTPUT>['needsApproval'];
|
749
788
|
toModelOutput?: Tool<INPUT, OUTPUT>['toModelOutput'];
|
750
789
|
onInputStart?: Tool<INPUT, OUTPUT>['onInputStart'];
|
751
790
|
onInputDelta?: Tool<INPUT, OUTPUT>['onInputDelta'];
|
@@ -758,6 +797,7 @@ declare function createProviderDefinedToolFactory<INPUT, ARGS extends object>({
|
|
758
797
|
}): ProviderDefinedToolFactory<INPUT, ARGS>;
|
759
798
|
type ProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object> = (options: ARGS & {
|
760
799
|
execute?: ToolExecuteFunction<INPUT, OUTPUT>;
|
800
|
+
needsApproval?: Tool<INPUT, OUTPUT>['needsApproval'];
|
761
801
|
toModelOutput?: Tool<INPUT, OUTPUT>['toModelOutput'];
|
762
802
|
onInputStart?: Tool<INPUT, OUTPUT>['onInputStart'];
|
763
803
|
onInputDelta?: Tool<INPUT, OUTPUT>['onInputDelta'];
|
@@ -908,4 +948,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
908
948
|
|
909
949
|
declare const VERSION: string;
|
910
950
|
|
911
|
-
export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, 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 ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type Validator, asSchema, asValidator, 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, isValidator, jsonSchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateTypes, validator, validatorSymbol, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
951
|
+
export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, 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, type Validator, asSchema, asValidator, 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, isValidator, jsonSchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateTypes, validator, validatorSymbol, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.js
CHANGED
@@ -284,7 +284,7 @@ function handleFetchError({
|
|
284
284
|
}
|
285
285
|
|
286
286
|
// src/version.ts
|
287
|
-
var VERSION = true ? "3.1.0-beta.
|
287
|
+
var VERSION = true ? "3.1.0-beta.8" : "0.0.0-test";
|
288
288
|
|
289
289
|
// src/get-from-api.ts
|
290
290
|
var getOriginalFetch = () => globalThis.fetch;
|
@@ -844,6 +844,7 @@ function createProviderDefinedToolFactory({
|
|
844
844
|
return ({
|
845
845
|
execute,
|
846
846
|
outputSchema,
|
847
|
+
needsApproval,
|
847
848
|
toModelOutput,
|
848
849
|
onInputStart,
|
849
850
|
onInputDelta,
|
@@ -857,6 +858,7 @@ function createProviderDefinedToolFactory({
|
|
857
858
|
inputSchema,
|
858
859
|
outputSchema,
|
859
860
|
execute,
|
861
|
+
needsApproval,
|
860
862
|
toModelOutput,
|
861
863
|
onInputStart,
|
862
864
|
onInputDelta,
|
@@ -871,6 +873,7 @@ function createProviderDefinedToolFactoryWithOutputSchema({
|
|
871
873
|
}) {
|
872
874
|
return ({
|
873
875
|
execute,
|
876
|
+
needsApproval,
|
874
877
|
toModelOutput,
|
875
878
|
onInputStart,
|
876
879
|
onInputDelta,
|
@@ -884,6 +887,7 @@ function createProviderDefinedToolFactoryWithOutputSchema({
|
|
884
887
|
inputSchema,
|
885
888
|
outputSchema,
|
886
889
|
execute,
|
890
|
+
needsApproval,
|
887
891
|
toModelOutput,
|
888
892
|
onInputStart,
|
889
893
|
onInputDelta,
|