@ai-sdk/provider 0.0.24 → 0.0.26

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,21 @@
1
1
  # @ai-sdk/provider
2
2
 
3
+ ## 0.0.26
4
+
5
+ ### Patch Changes
6
+
7
+ - aa98cdb: chore: more flexible dependency versioning
8
+ - 1486128: feat: add supportsUrl to language model specification
9
+ - 7b937c5: feat (provider-utils): improve id generator robustness
10
+ - 3b1b69a: feat: provider-defined tools
11
+ - 811a317: feat (ai/core): multi-part tool results (incl. images)
12
+
13
+ ## 0.0.25
14
+
15
+ ### Patch Changes
16
+
17
+ - b9b0d7b: feat (ai): access raw request body
18
+
3
19
  ## 0.0.24
4
20
 
5
21
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { JSONSchema7 } from 'json-schema';
2
+ export { JSONSchema7, JSONSchema7Definition } from 'json-schema';
2
3
 
3
4
  /**
4
5
  An embedding is a vector, i.e. an array of numbers.
@@ -82,13 +83,13 @@ type EmbeddingModelV1<VALUE> = {
82
83
  }>;
83
84
  };
84
85
 
85
- declare const symbol$c: unique symbol;
86
+ declare const symbol$d: unique symbol;
86
87
  /**
87
88
  * Custom error class for AI SDK related errors.
88
89
  * @extends Error
89
90
  */
90
91
  declare class AISDKError extends Error {
91
- private readonly [symbol$c];
92
+ private readonly [symbol$d];
92
93
  /**
93
94
  * The underlying cause of the error, if any.
94
95
  */
@@ -125,9 +126,9 @@ declare class AISDKError extends Error {
125
126
  };
126
127
  }
127
128
 
128
- declare const symbol$b: unique symbol;
129
+ declare const symbol$c: unique symbol;
129
130
  declare class APICallError extends AISDKError {
130
- private readonly [symbol$b];
131
+ private readonly [symbol$c];
131
132
  readonly url: string;
132
133
  readonly requestBodyValues: unknown;
133
134
  readonly statusCode?: number;
@@ -169,9 +170,9 @@ declare class APICallError extends AISDKError {
169
170
  };
170
171
  }
171
172
 
172
- declare const symbol$a: unique symbol;
173
+ declare const symbol$b: unique symbol;
173
174
  declare class EmptyResponseBodyError extends AISDKError {
174
- private readonly [symbol$a];
175
+ private readonly [symbol$b];
175
176
  constructor({ message }?: {
176
177
  message?: string;
177
178
  });
@@ -184,6 +185,21 @@ declare class EmptyResponseBodyError extends AISDKError {
184
185
 
185
186
  declare function getErrorMessage(error: unknown | undefined): string;
186
187
 
188
+ declare const symbol$a: unique symbol;
189
+ /**
190
+ * A function argument is invalid.
191
+ */
192
+ declare class InvalidArgumentError extends AISDKError {
193
+ private readonly [symbol$a];
194
+ readonly argument: string;
195
+ constructor({ message, cause, argument, }: {
196
+ argument: string;
197
+ message: string;
198
+ cause?: unknown;
199
+ });
200
+ static isInstance(error: unknown): error is InvalidArgumentError;
201
+ }
202
+
187
203
  declare const symbol$9: unique symbol;
188
204
  /**
189
205
  * A prompt is invalid. This error should be thrown by providers when they cannot
@@ -535,8 +551,7 @@ map the user-facing tool definitions to this format.
535
551
  */
536
552
  type LanguageModelV1FunctionTool = {
537
553
  /**
538
- The type of the tool. Only functions for now, but this gives us room to
539
- add more specific tool types in the future and use a discriminated union.
554
+ The type of the tool (always 'function').
540
555
  */
541
556
  type: 'function';
542
557
  /**
@@ -708,6 +723,27 @@ interface LanguageModelV1ToolResultPart {
708
723
  */
709
724
  isError?: boolean;
710
725
  /**
726
+ Tool results as an array of parts. This enables advanced tool results including images.
727
+ When this is used, the `result` field should be ignored (if the provider supports content).
728
+ */
729
+ content?: Array<{
730
+ type: 'text';
731
+ /**
732
+ Text content.
733
+ */
734
+ text: string;
735
+ } | {
736
+ type: 'image';
737
+ /**
738
+ base-64 encoded image data
739
+ */
740
+ data: string;
741
+ /**
742
+ Mime type of the image.
743
+ */
744
+ mimeType?: string;
745
+ }>;
746
+ /**
711
747
  * Additional provider-specific metadata. They are passed through
712
748
  * to the provider from the AI SDK and enable provider-specific
713
749
  * functionality that can be fully encapsulated in the provider.
@@ -715,6 +751,28 @@ interface LanguageModelV1ToolResultPart {
715
751
  providerMetadata?: LanguageModelV1ProviderMetadata;
716
752
  }
717
753
 
754
+ /**
755
+ The configuration of a tool that is defined by the provider.
756
+ */
757
+ type LanguageModelV1ProviderDefinedTool = {
758
+ /**
759
+ The type of the tool (always 'provider-defined').
760
+ */
761
+ type: 'provider-defined';
762
+ /**
763
+ The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
764
+ */
765
+ id: `${string}.${string}`;
766
+ /**
767
+ The name of the tool. Unique within this model call.
768
+ */
769
+ name: string;
770
+ /**
771
+ The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
772
+ */
773
+ args: Record<string, unknown>;
774
+ };
775
+
718
776
  type LanguageModelV1ToolChoice = {
719
777
  type: 'auto';
720
778
  } | {
@@ -751,7 +809,7 @@ type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
751
809
  /**
752
810
  The tools that are available for the model.
753
811
  */
754
- tools?: Array<LanguageModelV1FunctionTool>;
812
+ tools?: Array<LanguageModelV1FunctionTool | LanguageModelV1ProviderDefinedTool>;
755
813
  /**
756
814
  Specifies how the tool should be selected. Defaults to 'auto'.
757
815
  */
@@ -799,6 +857,10 @@ type LanguageModelV1CallWarning = {
799
857
  type: 'unsupported-setting';
800
858
  setting: keyof LanguageModelV1CallSettings;
801
859
  details?: string;
860
+ } | {
861
+ type: 'unsupported-tool';
862
+ tool: LanguageModelV1FunctionTool | LanguageModelV1ProviderDefinedTool;
863
+ details?: string;
802
864
  } | {
803
865
  type: 'other';
804
866
  message: string;
@@ -895,6 +957,14 @@ type LanguageModelV1 = {
895
957
  */
896
958
  readonly supportsStructuredOutputs?: boolean;
897
959
  /**
960
+ Checks if the model supports the given URL for file parts natively.
961
+ If the model does not support the URL,
962
+ the AI SDK will download the file and pass the file data to the model.
963
+
964
+ When undefined, the AI SDK will download the file.
965
+ */
966
+ supportsUrl?(url: URL): boolean;
967
+ /**
898
968
  Generates a language model output (non-streaming).
899
969
 
900
970
  Naming: "do" prefix to prevent accidental direct usage of the method
@@ -946,6 +1016,19 @@ type LanguageModelV1 = {
946
1016
  */
947
1017
  headers?: Record<string, string>;
948
1018
  };
1019
+ /**
1020
+ Optional request information for telemetry and debugging purposes.
1021
+ */
1022
+ request?: {
1023
+ /**
1024
+ Raw request HTTP body that was sent to the provider API as a string (JSON should be stringified).
1025
+ Non-HTTP(s) providers should not set this.
1026
+ */
1027
+ body?: string;
1028
+ };
1029
+ /**
1030
+ Optional response information for telemetry and debugging purposes.
1031
+ */
949
1032
  response?: {
950
1033
  /**
951
1034
  ID for the generated response, if the provider sends one.
@@ -1009,6 +1092,16 @@ type LanguageModelV1 = {
1009
1092
  */
1010
1093
  headers?: Record<string, string>;
1011
1094
  };
1095
+ /**
1096
+ Optional request information for telemetry and debugging purposes.
1097
+ */
1098
+ request?: {
1099
+ /**
1100
+ Raw request HTTP body that was sent to the provider API as a string (JSON should be stringified).
1101
+ Non-HTTP(s) providers should not set this.
1102
+ */
1103
+ body?: string;
1104
+ };
1012
1105
  warnings?: LanguageModelV1CallWarning[];
1013
1106
  }>;
1014
1107
  };
@@ -1070,4 +1163,4 @@ interface ProviderV1 {
1070
1163
  textEmbeddingModel(modelId: string): EmbeddingModelV1<string>;
1071
1164
  }
1072
1165
 
1073
- export { AISDKError, APICallError, type EmbeddingModelV1, type EmbeddingModelV1Embedding, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, type JSONArray, type JSONObject, JSONParseError, type JSONValue, type LanguageModelV1, type LanguageModelV1CallOptions, type LanguageModelV1CallWarning, type LanguageModelV1FilePart, type LanguageModelV1FinishReason, type LanguageModelV1FunctionTool, type LanguageModelV1FunctionToolCall, type LanguageModelV1ImagePart, type LanguageModelV1LogProbs, type LanguageModelV1Message, type LanguageModelV1Prompt, type LanguageModelV1ProviderMetadata, type LanguageModelV1StreamPart, type LanguageModelV1TextPart, type LanguageModelV1ToolCallPart, type LanguageModelV1ToolChoice, type LanguageModelV1ToolResultPart, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, type ProviderV1, TooManyEmbeddingValuesForCallError, TypeValidationError, UnsupportedFunctionalityError, getErrorMessage, isJSONArray, isJSONObject, isJSONValue };
1166
+ export { AISDKError, APICallError, type EmbeddingModelV1, type EmbeddingModelV1Embedding, EmptyResponseBodyError, InvalidArgumentError, InvalidPromptError, InvalidResponseDataError, type JSONArray, type JSONObject, JSONParseError, type JSONValue, type LanguageModelV1, type LanguageModelV1CallOptions, type LanguageModelV1CallWarning, type LanguageModelV1FilePart, type LanguageModelV1FinishReason, type LanguageModelV1FunctionTool, type LanguageModelV1FunctionToolCall, type LanguageModelV1ImagePart, type LanguageModelV1LogProbs, type LanguageModelV1Message, type LanguageModelV1Prompt, type LanguageModelV1ProviderDefinedTool, type LanguageModelV1ProviderMetadata, type LanguageModelV1StreamPart, type LanguageModelV1TextPart, type LanguageModelV1ToolCallPart, type LanguageModelV1ToolChoice, type LanguageModelV1ToolResultPart, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, type ProviderV1, TooManyEmbeddingValuesForCallError, TypeValidationError, UnsupportedFunctionalityError, getErrorMessage, isJSONArray, isJSONObject, isJSONValue };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { JSONSchema7 } from 'json-schema';
2
+ export { JSONSchema7, JSONSchema7Definition } from 'json-schema';
2
3
 
3
4
  /**
4
5
  An embedding is a vector, i.e. an array of numbers.
@@ -82,13 +83,13 @@ type EmbeddingModelV1<VALUE> = {
82
83
  }>;
83
84
  };
84
85
 
85
- declare const symbol$c: unique symbol;
86
+ declare const symbol$d: unique symbol;
86
87
  /**
87
88
  * Custom error class for AI SDK related errors.
88
89
  * @extends Error
89
90
  */
90
91
  declare class AISDKError extends Error {
91
- private readonly [symbol$c];
92
+ private readonly [symbol$d];
92
93
  /**
93
94
  * The underlying cause of the error, if any.
94
95
  */
@@ -125,9 +126,9 @@ declare class AISDKError extends Error {
125
126
  };
126
127
  }
127
128
 
128
- declare const symbol$b: unique symbol;
129
+ declare const symbol$c: unique symbol;
129
130
  declare class APICallError extends AISDKError {
130
- private readonly [symbol$b];
131
+ private readonly [symbol$c];
131
132
  readonly url: string;
132
133
  readonly requestBodyValues: unknown;
133
134
  readonly statusCode?: number;
@@ -169,9 +170,9 @@ declare class APICallError extends AISDKError {
169
170
  };
170
171
  }
171
172
 
172
- declare const symbol$a: unique symbol;
173
+ declare const symbol$b: unique symbol;
173
174
  declare class EmptyResponseBodyError extends AISDKError {
174
- private readonly [symbol$a];
175
+ private readonly [symbol$b];
175
176
  constructor({ message }?: {
176
177
  message?: string;
177
178
  });
@@ -184,6 +185,21 @@ declare class EmptyResponseBodyError extends AISDKError {
184
185
 
185
186
  declare function getErrorMessage(error: unknown | undefined): string;
186
187
 
188
+ declare const symbol$a: unique symbol;
189
+ /**
190
+ * A function argument is invalid.
191
+ */
192
+ declare class InvalidArgumentError extends AISDKError {
193
+ private readonly [symbol$a];
194
+ readonly argument: string;
195
+ constructor({ message, cause, argument, }: {
196
+ argument: string;
197
+ message: string;
198
+ cause?: unknown;
199
+ });
200
+ static isInstance(error: unknown): error is InvalidArgumentError;
201
+ }
202
+
187
203
  declare const symbol$9: unique symbol;
188
204
  /**
189
205
  * A prompt is invalid. This error should be thrown by providers when they cannot
@@ -535,8 +551,7 @@ map the user-facing tool definitions to this format.
535
551
  */
536
552
  type LanguageModelV1FunctionTool = {
537
553
  /**
538
- The type of the tool. Only functions for now, but this gives us room to
539
- add more specific tool types in the future and use a discriminated union.
554
+ The type of the tool (always 'function').
540
555
  */
541
556
  type: 'function';
542
557
  /**
@@ -708,6 +723,27 @@ interface LanguageModelV1ToolResultPart {
708
723
  */
709
724
  isError?: boolean;
710
725
  /**
726
+ Tool results as an array of parts. This enables advanced tool results including images.
727
+ When this is used, the `result` field should be ignored (if the provider supports content).
728
+ */
729
+ content?: Array<{
730
+ type: 'text';
731
+ /**
732
+ Text content.
733
+ */
734
+ text: string;
735
+ } | {
736
+ type: 'image';
737
+ /**
738
+ base-64 encoded image data
739
+ */
740
+ data: string;
741
+ /**
742
+ Mime type of the image.
743
+ */
744
+ mimeType?: string;
745
+ }>;
746
+ /**
711
747
  * Additional provider-specific metadata. They are passed through
712
748
  * to the provider from the AI SDK and enable provider-specific
713
749
  * functionality that can be fully encapsulated in the provider.
@@ -715,6 +751,28 @@ interface LanguageModelV1ToolResultPart {
715
751
  providerMetadata?: LanguageModelV1ProviderMetadata;
716
752
  }
717
753
 
754
+ /**
755
+ The configuration of a tool that is defined by the provider.
756
+ */
757
+ type LanguageModelV1ProviderDefinedTool = {
758
+ /**
759
+ The type of the tool (always 'provider-defined').
760
+ */
761
+ type: 'provider-defined';
762
+ /**
763
+ The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
764
+ */
765
+ id: `${string}.${string}`;
766
+ /**
767
+ The name of the tool. Unique within this model call.
768
+ */
769
+ name: string;
770
+ /**
771
+ The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
772
+ */
773
+ args: Record<string, unknown>;
774
+ };
775
+
718
776
  type LanguageModelV1ToolChoice = {
719
777
  type: 'auto';
720
778
  } | {
@@ -751,7 +809,7 @@ type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
751
809
  /**
752
810
  The tools that are available for the model.
753
811
  */
754
- tools?: Array<LanguageModelV1FunctionTool>;
812
+ tools?: Array<LanguageModelV1FunctionTool | LanguageModelV1ProviderDefinedTool>;
755
813
  /**
756
814
  Specifies how the tool should be selected. Defaults to 'auto'.
757
815
  */
@@ -799,6 +857,10 @@ type LanguageModelV1CallWarning = {
799
857
  type: 'unsupported-setting';
800
858
  setting: keyof LanguageModelV1CallSettings;
801
859
  details?: string;
860
+ } | {
861
+ type: 'unsupported-tool';
862
+ tool: LanguageModelV1FunctionTool | LanguageModelV1ProviderDefinedTool;
863
+ details?: string;
802
864
  } | {
803
865
  type: 'other';
804
866
  message: string;
@@ -895,6 +957,14 @@ type LanguageModelV1 = {
895
957
  */
896
958
  readonly supportsStructuredOutputs?: boolean;
897
959
  /**
960
+ Checks if the model supports the given URL for file parts natively.
961
+ If the model does not support the URL,
962
+ the AI SDK will download the file and pass the file data to the model.
963
+
964
+ When undefined, the AI SDK will download the file.
965
+ */
966
+ supportsUrl?(url: URL): boolean;
967
+ /**
898
968
  Generates a language model output (non-streaming).
899
969
 
900
970
  Naming: "do" prefix to prevent accidental direct usage of the method
@@ -946,6 +1016,19 @@ type LanguageModelV1 = {
946
1016
  */
947
1017
  headers?: Record<string, string>;
948
1018
  };
1019
+ /**
1020
+ Optional request information for telemetry and debugging purposes.
1021
+ */
1022
+ request?: {
1023
+ /**
1024
+ Raw request HTTP body that was sent to the provider API as a string (JSON should be stringified).
1025
+ Non-HTTP(s) providers should not set this.
1026
+ */
1027
+ body?: string;
1028
+ };
1029
+ /**
1030
+ Optional response information for telemetry and debugging purposes.
1031
+ */
949
1032
  response?: {
950
1033
  /**
951
1034
  ID for the generated response, if the provider sends one.
@@ -1009,6 +1092,16 @@ type LanguageModelV1 = {
1009
1092
  */
1010
1093
  headers?: Record<string, string>;
1011
1094
  };
1095
+ /**
1096
+ Optional request information for telemetry and debugging purposes.
1097
+ */
1098
+ request?: {
1099
+ /**
1100
+ Raw request HTTP body that was sent to the provider API as a string (JSON should be stringified).
1101
+ Non-HTTP(s) providers should not set this.
1102
+ */
1103
+ body?: string;
1104
+ };
1012
1105
  warnings?: LanguageModelV1CallWarning[];
1013
1106
  }>;
1014
1107
  };
@@ -1070,4 +1163,4 @@ interface ProviderV1 {
1070
1163
  textEmbeddingModel(modelId: string): EmbeddingModelV1<string>;
1071
1164
  }
1072
1165
 
1073
- export { AISDKError, APICallError, type EmbeddingModelV1, type EmbeddingModelV1Embedding, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, type JSONArray, type JSONObject, JSONParseError, type JSONValue, type LanguageModelV1, type LanguageModelV1CallOptions, type LanguageModelV1CallWarning, type LanguageModelV1FilePart, type LanguageModelV1FinishReason, type LanguageModelV1FunctionTool, type LanguageModelV1FunctionToolCall, type LanguageModelV1ImagePart, type LanguageModelV1LogProbs, type LanguageModelV1Message, type LanguageModelV1Prompt, type LanguageModelV1ProviderMetadata, type LanguageModelV1StreamPart, type LanguageModelV1TextPart, type LanguageModelV1ToolCallPart, type LanguageModelV1ToolChoice, type LanguageModelV1ToolResultPart, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, type ProviderV1, TooManyEmbeddingValuesForCallError, TypeValidationError, UnsupportedFunctionalityError, getErrorMessage, isJSONArray, isJSONObject, isJSONValue };
1166
+ export { AISDKError, APICallError, type EmbeddingModelV1, type EmbeddingModelV1Embedding, EmptyResponseBodyError, InvalidArgumentError, InvalidPromptError, InvalidResponseDataError, type JSONArray, type JSONObject, JSONParseError, type JSONValue, type LanguageModelV1, type LanguageModelV1CallOptions, type LanguageModelV1CallWarning, type LanguageModelV1FilePart, type LanguageModelV1FinishReason, type LanguageModelV1FunctionTool, type LanguageModelV1FunctionToolCall, type LanguageModelV1ImagePart, type LanguageModelV1LogProbs, type LanguageModelV1Message, type LanguageModelV1Prompt, type LanguageModelV1ProviderDefinedTool, type LanguageModelV1ProviderMetadata, type LanguageModelV1StreamPart, type LanguageModelV1TextPart, type LanguageModelV1ToolCallPart, type LanguageModelV1ToolChoice, type LanguageModelV1ToolResultPart, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, type ProviderV1, TooManyEmbeddingValuesForCallError, TypeValidationError, UnsupportedFunctionalityError, getErrorMessage, isJSONArray, isJSONObject, isJSONValue };