@ai-sdk/provider 2.1.0-beta.2 → 2.1.0-beta.3
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 +6 -0
- package/dist/index.d.mts +840 -2
- package/dist/index.d.ts +840 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
@@ -792,6 +792,844 @@ type ImageModelV2 = {
|
|
792
792
|
/**
|
793
793
|
A tool has a name, a description, and a set of parameters.
|
794
794
|
|
795
|
+
Note: this is **not** the user-facing tool definition. The AI SDK methods will
|
796
|
+
map the user-facing tool definitions to this format.
|
797
|
+
*/
|
798
|
+
type LanguageModelV3FunctionTool = {
|
799
|
+
/**
|
800
|
+
The type of the tool (always 'function').
|
801
|
+
*/
|
802
|
+
type: 'function';
|
803
|
+
/**
|
804
|
+
The name of the tool. Unique within this model call.
|
805
|
+
*/
|
806
|
+
name: string;
|
807
|
+
/**
|
808
|
+
A description of the tool. The language model uses this to understand the
|
809
|
+
tool's purpose and to provide better completion suggestions.
|
810
|
+
*/
|
811
|
+
description?: string;
|
812
|
+
/**
|
813
|
+
The parameters that the tool expects. The language model uses this to
|
814
|
+
understand the tool's input requirements and to provide matching suggestions.
|
815
|
+
*/
|
816
|
+
inputSchema: JSONSchema7;
|
817
|
+
/**
|
818
|
+
The provider-specific options for the tool.
|
819
|
+
*/
|
820
|
+
providerOptions?: SharedV2ProviderOptions;
|
821
|
+
};
|
822
|
+
|
823
|
+
/**
|
824
|
+
Data content. Can be a Uint8Array, base64 encoded data as a string or a URL.
|
825
|
+
*/
|
826
|
+
type LanguageModelV3DataContent = Uint8Array | string | URL;
|
827
|
+
|
828
|
+
/**
|
829
|
+
A prompt is a list of messages.
|
830
|
+
|
831
|
+
Note: Not all models and prompt formats support multi-modal inputs and
|
832
|
+
tool calls. The validation happens at runtime.
|
833
|
+
|
834
|
+
Note: This is not a user-facing prompt. The AI SDK methods will map the
|
835
|
+
user-facing prompt types such as chat or instruction prompts to this format.
|
836
|
+
*/
|
837
|
+
type LanguageModelV3Prompt = Array<LanguageModelV3Message>;
|
838
|
+
type LanguageModelV3Message = ({
|
839
|
+
role: 'system';
|
840
|
+
content: string;
|
841
|
+
} | {
|
842
|
+
role: 'user';
|
843
|
+
content: Array<LanguageModelV3TextPart | LanguageModelV3FilePart>;
|
844
|
+
} | {
|
845
|
+
role: 'assistant';
|
846
|
+
content: Array<LanguageModelV3TextPart | LanguageModelV3FilePart | LanguageModelV3ReasoningPart | LanguageModelV3ToolCallPart | LanguageModelV3ToolResultPart>;
|
847
|
+
} | {
|
848
|
+
role: 'tool';
|
849
|
+
content: Array<LanguageModelV3ToolResultPart>;
|
850
|
+
}) & {
|
851
|
+
/**
|
852
|
+
* Additional provider-specific options. They are passed through
|
853
|
+
* to the provider from the AI SDK and enable provider-specific
|
854
|
+
* functionality that can be fully encapsulated in the provider.
|
855
|
+
*/
|
856
|
+
providerOptions?: SharedV2ProviderOptions;
|
857
|
+
};
|
858
|
+
/**
|
859
|
+
Text content part of a prompt. It contains a string of text.
|
860
|
+
*/
|
861
|
+
interface LanguageModelV3TextPart {
|
862
|
+
type: 'text';
|
863
|
+
/**
|
864
|
+
The text content.
|
865
|
+
*/
|
866
|
+
text: string;
|
867
|
+
/**
|
868
|
+
* Additional provider-specific options. They are passed through
|
869
|
+
* to the provider from the AI SDK and enable provider-specific
|
870
|
+
* functionality that can be fully encapsulated in the provider.
|
871
|
+
*/
|
872
|
+
providerOptions?: SharedV2ProviderOptions;
|
873
|
+
}
|
874
|
+
/**
|
875
|
+
Reasoning content part of a prompt. It contains a string of reasoning text.
|
876
|
+
*/
|
877
|
+
interface LanguageModelV3ReasoningPart {
|
878
|
+
type: 'reasoning';
|
879
|
+
/**
|
880
|
+
The reasoning text.
|
881
|
+
*/
|
882
|
+
text: string;
|
883
|
+
/**
|
884
|
+
* Additional provider-specific options. They are passed through
|
885
|
+
* to the provider from the AI SDK and enable provider-specific
|
886
|
+
* functionality that can be fully encapsulated in the provider.
|
887
|
+
*/
|
888
|
+
providerOptions?: SharedV2ProviderOptions;
|
889
|
+
}
|
890
|
+
/**
|
891
|
+
File content part of a prompt. It contains a file.
|
892
|
+
*/
|
893
|
+
interface LanguageModelV3FilePart {
|
894
|
+
type: 'file';
|
895
|
+
/**
|
896
|
+
* Optional filename of the file.
|
897
|
+
*/
|
898
|
+
filename?: string;
|
899
|
+
/**
|
900
|
+
File data. Can be a Uint8Array, base64 encoded data as a string or a URL.
|
901
|
+
*/
|
902
|
+
data: LanguageModelV3DataContent;
|
903
|
+
/**
|
904
|
+
IANA media type of the file.
|
905
|
+
|
906
|
+
Can support wildcards, e.g. `image/*` (in which case the provider needs to take appropriate action).
|
907
|
+
|
908
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
909
|
+
*/
|
910
|
+
mediaType: string;
|
911
|
+
/**
|
912
|
+
* Additional provider-specific options. They are passed through
|
913
|
+
* to the provider from the AI SDK and enable provider-specific
|
914
|
+
* functionality that can be fully encapsulated in the provider.
|
915
|
+
*/
|
916
|
+
providerOptions?: SharedV2ProviderOptions;
|
917
|
+
}
|
918
|
+
/**
|
919
|
+
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
920
|
+
*/
|
921
|
+
interface LanguageModelV3ToolCallPart {
|
922
|
+
type: 'tool-call';
|
923
|
+
/**
|
924
|
+
ID of the tool call. This ID is used to match the tool call with the tool result.
|
925
|
+
*/
|
926
|
+
toolCallId: string;
|
927
|
+
/**
|
928
|
+
Name of the tool that is being called.
|
929
|
+
*/
|
930
|
+
toolName: string;
|
931
|
+
/**
|
932
|
+
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
933
|
+
*/
|
934
|
+
input: unknown;
|
935
|
+
/**
|
936
|
+
* Whether the tool call will be executed by the provider.
|
937
|
+
* If this flag is not set or is false, the tool call will be executed by the client.
|
938
|
+
*/
|
939
|
+
providerExecuted?: boolean;
|
940
|
+
/**
|
941
|
+
* Additional provider-specific options. They are passed through
|
942
|
+
* to the provider from the AI SDK and enable provider-specific
|
943
|
+
* functionality that can be fully encapsulated in the provider.
|
944
|
+
*/
|
945
|
+
providerOptions?: SharedV2ProviderOptions;
|
946
|
+
}
|
947
|
+
/**
|
948
|
+
Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
949
|
+
*/
|
950
|
+
interface LanguageModelV3ToolResultPart {
|
951
|
+
type: 'tool-result';
|
952
|
+
/**
|
953
|
+
ID of the tool call that this result is associated with.
|
954
|
+
*/
|
955
|
+
toolCallId: string;
|
956
|
+
/**
|
957
|
+
Name of the tool that generated this result.
|
958
|
+
*/
|
959
|
+
toolName: string;
|
960
|
+
/**
|
961
|
+
Result of the tool call.
|
962
|
+
*/
|
963
|
+
output: LanguageModelV3ToolResultOutput;
|
964
|
+
/**
|
965
|
+
* Additional provider-specific options. They are passed through
|
966
|
+
* to the provider from the AI SDK and enable provider-specific
|
967
|
+
* functionality that can be fully encapsulated in the provider.
|
968
|
+
*/
|
969
|
+
providerOptions?: SharedV2ProviderOptions;
|
970
|
+
}
|
971
|
+
type LanguageModelV3ToolResultOutput = {
|
972
|
+
type: 'text';
|
973
|
+
value: string;
|
974
|
+
} | {
|
975
|
+
type: 'json';
|
976
|
+
value: JSONValue;
|
977
|
+
} | {
|
978
|
+
type: 'error-text';
|
979
|
+
value: string;
|
980
|
+
} | {
|
981
|
+
type: 'error-json';
|
982
|
+
value: JSONValue;
|
983
|
+
} | {
|
984
|
+
type: 'content';
|
985
|
+
value: Array<{
|
986
|
+
type: 'text';
|
987
|
+
/**
|
988
|
+
Text content.
|
989
|
+
*/
|
990
|
+
text: string;
|
991
|
+
} | {
|
992
|
+
type: 'media';
|
993
|
+
/**
|
994
|
+
Base-64 encoded media data.
|
995
|
+
*/
|
996
|
+
data: string;
|
997
|
+
/**
|
998
|
+
IANA media type.
|
999
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
1000
|
+
*/
|
1001
|
+
mediaType: string;
|
1002
|
+
}>;
|
1003
|
+
};
|
1004
|
+
|
1005
|
+
/**
|
1006
|
+
The configuration of a tool that is defined by the provider.
|
1007
|
+
*/
|
1008
|
+
type LanguageModelV3ProviderDefinedTool = {
|
1009
|
+
/**
|
1010
|
+
The type of the tool (always 'provider-defined').
|
1011
|
+
*/
|
1012
|
+
type: 'provider-defined';
|
1013
|
+
/**
|
1014
|
+
The ID of the tool. Should follow the format `<provider-name>.<unique-tool-name>`.
|
1015
|
+
*/
|
1016
|
+
id: `${string}.${string}`;
|
1017
|
+
/**
|
1018
|
+
The name of the tool that the user must use in the tool set.
|
1019
|
+
*/
|
1020
|
+
name: string;
|
1021
|
+
/**
|
1022
|
+
The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
|
1023
|
+
*/
|
1024
|
+
args: Record<string, unknown>;
|
1025
|
+
};
|
1026
|
+
|
1027
|
+
type LanguageModelV3ToolChoice = {
|
1028
|
+
type: 'auto';
|
1029
|
+
} | {
|
1030
|
+
type: 'none';
|
1031
|
+
} | {
|
1032
|
+
type: 'required';
|
1033
|
+
} | {
|
1034
|
+
type: 'tool';
|
1035
|
+
toolName: string;
|
1036
|
+
};
|
1037
|
+
|
1038
|
+
type LanguageModelV3CallOptions = {
|
1039
|
+
/**
|
1040
|
+
A language mode prompt is a standardized prompt type.
|
1041
|
+
|
1042
|
+
Note: This is **not** the user-facing prompt. The AI SDK methods will map the
|
1043
|
+
user-facing prompt types such as chat or instruction prompts to this format.
|
1044
|
+
That approach allows us to evolve the user facing prompts without breaking
|
1045
|
+
the language model interface.
|
1046
|
+
*/
|
1047
|
+
prompt: LanguageModelV3Prompt;
|
1048
|
+
/**
|
1049
|
+
Maximum number of tokens to generate.
|
1050
|
+
*/
|
1051
|
+
maxOutputTokens?: number;
|
1052
|
+
/**
|
1053
|
+
Temperature setting. The range depends on the provider and model.
|
1054
|
+
*/
|
1055
|
+
temperature?: number;
|
1056
|
+
/**
|
1057
|
+
Stop sequences.
|
1058
|
+
If set, the model will stop generating text when one of the stop sequences is generated.
|
1059
|
+
Providers may have limits on the number of stop sequences.
|
1060
|
+
*/
|
1061
|
+
stopSequences?: string[];
|
1062
|
+
/**
|
1063
|
+
Nucleus sampling.
|
1064
|
+
*/
|
1065
|
+
topP?: number;
|
1066
|
+
/**
|
1067
|
+
Only sample from the top K options for each subsequent token.
|
1068
|
+
|
1069
|
+
Used to remove "long tail" low probability responses.
|
1070
|
+
Recommended for advanced use cases only. You usually only need to use temperature.
|
1071
|
+
*/
|
1072
|
+
topK?: number;
|
1073
|
+
/**
|
1074
|
+
Presence penalty setting. It affects the likelihood of the model to
|
1075
|
+
repeat information that is already in the prompt.
|
1076
|
+
*/
|
1077
|
+
presencePenalty?: number;
|
1078
|
+
/**
|
1079
|
+
Frequency penalty setting. It affects the likelihood of the model
|
1080
|
+
to repeatedly use the same words or phrases.
|
1081
|
+
*/
|
1082
|
+
frequencyPenalty?: number;
|
1083
|
+
/**
|
1084
|
+
Response format. The output can either be text or JSON. Default is text.
|
1085
|
+
|
1086
|
+
If JSON is selected, a schema can optionally be provided to guide the LLM.
|
1087
|
+
*/
|
1088
|
+
responseFormat?: {
|
1089
|
+
type: 'text';
|
1090
|
+
} | {
|
1091
|
+
type: 'json';
|
1092
|
+
/**
|
1093
|
+
* JSON schema that the generated output should conform to.
|
1094
|
+
*/
|
1095
|
+
schema?: JSONSchema7;
|
1096
|
+
/**
|
1097
|
+
* Name of output that should be generated. Used by some providers for additional LLM guidance.
|
1098
|
+
*/
|
1099
|
+
name?: string;
|
1100
|
+
/**
|
1101
|
+
* Description of the output that should be generated. Used by some providers for additional LLM guidance.
|
1102
|
+
*/
|
1103
|
+
description?: string;
|
1104
|
+
};
|
1105
|
+
/**
|
1106
|
+
The seed (integer) to use for random sampling. If set and supported
|
1107
|
+
by the model, calls will generate deterministic results.
|
1108
|
+
*/
|
1109
|
+
seed?: number;
|
1110
|
+
/**
|
1111
|
+
The tools that are available for the model.
|
1112
|
+
*/
|
1113
|
+
tools?: Array<LanguageModelV3FunctionTool | LanguageModelV3ProviderDefinedTool>;
|
1114
|
+
/**
|
1115
|
+
Specifies how the tool should be selected. Defaults to 'auto'.
|
1116
|
+
*/
|
1117
|
+
toolChoice?: LanguageModelV3ToolChoice;
|
1118
|
+
/**
|
1119
|
+
Include raw chunks in the stream. Only applicable for streaming calls.
|
1120
|
+
*/
|
1121
|
+
includeRawChunks?: boolean;
|
1122
|
+
/**
|
1123
|
+
Abort signal for cancelling the operation.
|
1124
|
+
*/
|
1125
|
+
abortSignal?: AbortSignal;
|
1126
|
+
/**
|
1127
|
+
Additional HTTP headers to be sent with the request.
|
1128
|
+
Only applicable for HTTP-based providers.
|
1129
|
+
*/
|
1130
|
+
headers?: Record<string, string | undefined>;
|
1131
|
+
/**
|
1132
|
+
* Additional provider-specific options. They are passed through
|
1133
|
+
* to the provider from the AI SDK and enable provider-specific
|
1134
|
+
* functionality that can be fully encapsulated in the provider.
|
1135
|
+
*/
|
1136
|
+
providerOptions?: SharedV2ProviderOptions;
|
1137
|
+
};
|
1138
|
+
|
1139
|
+
/**
|
1140
|
+
Warning from the model provider for this call. The call will proceed, but e.g.
|
1141
|
+
some settings might not be supported, which can lead to suboptimal results.
|
1142
|
+
*/
|
1143
|
+
type LanguageModelV3CallWarning = {
|
1144
|
+
type: 'unsupported-setting';
|
1145
|
+
setting: Omit<keyof LanguageModelV3CallOptions, 'prompt'>;
|
1146
|
+
details?: string;
|
1147
|
+
} | {
|
1148
|
+
type: 'unsupported-tool';
|
1149
|
+
tool: LanguageModelV3FunctionTool | LanguageModelV3ProviderDefinedTool;
|
1150
|
+
details?: string;
|
1151
|
+
} | {
|
1152
|
+
type: 'other';
|
1153
|
+
message: string;
|
1154
|
+
};
|
1155
|
+
|
1156
|
+
/**
|
1157
|
+
A file that has been generated by the model.
|
1158
|
+
Generated files as base64 encoded strings or binary data.
|
1159
|
+
The files should be returned without any unnecessary conversion.
|
1160
|
+
*/
|
1161
|
+
type LanguageModelV3File = {
|
1162
|
+
type: 'file';
|
1163
|
+
/**
|
1164
|
+
The IANA media type of the file, e.g. `image/png` or `audio/mp3`.
|
1165
|
+
|
1166
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
1167
|
+
*/
|
1168
|
+
mediaType: string;
|
1169
|
+
/**
|
1170
|
+
Generated file data as base64 encoded strings or binary data.
|
1171
|
+
|
1172
|
+
The file data should be returned without any unnecessary conversion.
|
1173
|
+
If the API returns base64 encoded strings, the file data should be returned
|
1174
|
+
as base64 encoded strings. If the API returns binary data, the file data should
|
1175
|
+
be returned as binary data.
|
1176
|
+
*/
|
1177
|
+
data: string | Uint8Array;
|
1178
|
+
};
|
1179
|
+
|
1180
|
+
/**
|
1181
|
+
Reasoning that the model has generated.
|
1182
|
+
*/
|
1183
|
+
type LanguageModelV3Reasoning = {
|
1184
|
+
type: 'reasoning';
|
1185
|
+
text: string;
|
1186
|
+
/**
|
1187
|
+
* Optional provider-specific metadata for the reasoning part.
|
1188
|
+
*/
|
1189
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1190
|
+
};
|
1191
|
+
|
1192
|
+
/**
|
1193
|
+
A source that has been used as input to generate the response.
|
1194
|
+
*/
|
1195
|
+
type LanguageModelV3Source = {
|
1196
|
+
type: 'source';
|
1197
|
+
/**
|
1198
|
+
* The type of source - URL sources reference web content.
|
1199
|
+
*/
|
1200
|
+
sourceType: 'url';
|
1201
|
+
/**
|
1202
|
+
* The ID of the source.
|
1203
|
+
*/
|
1204
|
+
id: string;
|
1205
|
+
/**
|
1206
|
+
* The URL of the source.
|
1207
|
+
*/
|
1208
|
+
url: string;
|
1209
|
+
/**
|
1210
|
+
* The title of the source.
|
1211
|
+
*/
|
1212
|
+
title?: string;
|
1213
|
+
/**
|
1214
|
+
* Additional provider metadata for the source.
|
1215
|
+
*/
|
1216
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1217
|
+
} | {
|
1218
|
+
type: 'source';
|
1219
|
+
/**
|
1220
|
+
* The type of source - document sources reference files/documents.
|
1221
|
+
*/
|
1222
|
+
sourceType: 'document';
|
1223
|
+
/**
|
1224
|
+
* The ID of the source.
|
1225
|
+
*/
|
1226
|
+
id: string;
|
1227
|
+
/**
|
1228
|
+
* IANA media type of the document (e.g., 'application/pdf').
|
1229
|
+
*/
|
1230
|
+
mediaType: string;
|
1231
|
+
/**
|
1232
|
+
* The title of the document.
|
1233
|
+
*/
|
1234
|
+
title: string;
|
1235
|
+
/**
|
1236
|
+
* Optional filename of the document.
|
1237
|
+
*/
|
1238
|
+
filename?: string;
|
1239
|
+
/**
|
1240
|
+
* Additional provider metadata for the source.
|
1241
|
+
*/
|
1242
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1243
|
+
};
|
1244
|
+
|
1245
|
+
/**
|
1246
|
+
Text that the model has generated.
|
1247
|
+
*/
|
1248
|
+
type LanguageModelV3Text = {
|
1249
|
+
type: 'text';
|
1250
|
+
/**
|
1251
|
+
The text content.
|
1252
|
+
*/
|
1253
|
+
text: string;
|
1254
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1255
|
+
};
|
1256
|
+
|
1257
|
+
/**
|
1258
|
+
* Tool calls that the model has generated.
|
1259
|
+
*/
|
1260
|
+
type LanguageModelV3ToolCall = {
|
1261
|
+
type: 'tool-call';
|
1262
|
+
/**
|
1263
|
+
* The identifier of the tool call. It must be unique across all tool calls.
|
1264
|
+
*/
|
1265
|
+
toolCallId: string;
|
1266
|
+
/**
|
1267
|
+
* The name of the tool that should be called.
|
1268
|
+
*/
|
1269
|
+
toolName: string;
|
1270
|
+
/**
|
1271
|
+
* Stringified JSON object with the tool call arguments. Must match the
|
1272
|
+
* parameters schema of the tool.
|
1273
|
+
*/
|
1274
|
+
input: string;
|
1275
|
+
/**
|
1276
|
+
* Whether the tool call will be executed by the provider.
|
1277
|
+
* If this flag is not set or is false, the tool call will be executed by the client.
|
1278
|
+
*/
|
1279
|
+
providerExecuted?: boolean;
|
1280
|
+
/**
|
1281
|
+
* Additional provider-specific metadata for the tool call.
|
1282
|
+
*/
|
1283
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1284
|
+
};
|
1285
|
+
|
1286
|
+
/**
|
1287
|
+
Result of a tool call that has been executed by the provider.
|
1288
|
+
*/
|
1289
|
+
type LanguageModelV3ToolResult = {
|
1290
|
+
type: 'tool-result';
|
1291
|
+
/**
|
1292
|
+
* The ID of the tool call that this result is associated with.
|
1293
|
+
*/
|
1294
|
+
toolCallId: string;
|
1295
|
+
/**
|
1296
|
+
* Name of the tool that generated this result.
|
1297
|
+
*/
|
1298
|
+
toolName: string;
|
1299
|
+
/**
|
1300
|
+
* Result of the tool call. This is a JSON-serializable object.
|
1301
|
+
*/
|
1302
|
+
result: unknown;
|
1303
|
+
/**
|
1304
|
+
* Optional flag if the result is an error or an error message.
|
1305
|
+
*/
|
1306
|
+
isError?: boolean;
|
1307
|
+
/**
|
1308
|
+
* Whether the tool result was generated by the provider.
|
1309
|
+
* If this flag is set to true, the tool result was generated by the provider.
|
1310
|
+
* If this flag is not set or is false, the tool result was generated by the client.
|
1311
|
+
*/
|
1312
|
+
providerExecuted?: boolean;
|
1313
|
+
/**
|
1314
|
+
* Additional provider-specific metadata for the tool result.
|
1315
|
+
*/
|
1316
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1317
|
+
};
|
1318
|
+
|
1319
|
+
type LanguageModelV3Content = LanguageModelV3Text | LanguageModelV3Reasoning | LanguageModelV3File | LanguageModelV3Source | LanguageModelV3ToolCall | LanguageModelV3ToolResult;
|
1320
|
+
|
1321
|
+
/**
|
1322
|
+
Reason why a language model finished generating a response.
|
1323
|
+
|
1324
|
+
Can be one of the following:
|
1325
|
+
- `stop`: model generated stop sequence
|
1326
|
+
- `length`: model generated maximum number of tokens
|
1327
|
+
- `content-filter`: content filter violation stopped the model
|
1328
|
+
- `tool-calls`: model triggered tool calls
|
1329
|
+
- `error`: model stopped because of an error
|
1330
|
+
- `other`: model stopped for other reasons
|
1331
|
+
- `unknown`: the model has not transmitted a finish reason
|
1332
|
+
*/
|
1333
|
+
type LanguageModelV3FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown';
|
1334
|
+
|
1335
|
+
interface LanguageModelV3ResponseMetadata {
|
1336
|
+
/**
|
1337
|
+
ID for the generated response, if the provider sends one.
|
1338
|
+
*/
|
1339
|
+
id?: string;
|
1340
|
+
/**
|
1341
|
+
Timestamp for the start of the generated response, if the provider sends one.
|
1342
|
+
*/
|
1343
|
+
timestamp?: Date;
|
1344
|
+
/**
|
1345
|
+
The ID of the response model that was used to generate the response, if the provider sends one.
|
1346
|
+
*/
|
1347
|
+
modelId?: string;
|
1348
|
+
}
|
1349
|
+
|
1350
|
+
/**
|
1351
|
+
Usage information for a language model call.
|
1352
|
+
|
1353
|
+
If your API return additional usage information, you can add it to the
|
1354
|
+
provider metadata under your provider's key.
|
1355
|
+
*/
|
1356
|
+
type LanguageModelV3Usage = {
|
1357
|
+
/**
|
1358
|
+
The number of input (prompt) tokens used.
|
1359
|
+
*/
|
1360
|
+
inputTokens: number | undefined;
|
1361
|
+
/**
|
1362
|
+
The number of output (completion) tokens used.
|
1363
|
+
*/
|
1364
|
+
outputTokens: number | undefined;
|
1365
|
+
/**
|
1366
|
+
The total number of tokens as reported by the provider.
|
1367
|
+
This number might be different from the sum of `inputTokens` and `outputTokens`
|
1368
|
+
and e.g. include reasoning tokens or other overhead.
|
1369
|
+
*/
|
1370
|
+
totalTokens: number | undefined;
|
1371
|
+
/**
|
1372
|
+
The number of reasoning tokens used.
|
1373
|
+
*/
|
1374
|
+
reasoningTokens?: number | undefined;
|
1375
|
+
/**
|
1376
|
+
The number of cached input tokens.
|
1377
|
+
*/
|
1378
|
+
cachedInputTokens?: number | undefined;
|
1379
|
+
};
|
1380
|
+
|
1381
|
+
type LanguageModelV3StreamPart = {
|
1382
|
+
type: 'text-start';
|
1383
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1384
|
+
id: string;
|
1385
|
+
} | {
|
1386
|
+
type: 'text-delta';
|
1387
|
+
id: string;
|
1388
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1389
|
+
delta: string;
|
1390
|
+
} | {
|
1391
|
+
type: 'text-end';
|
1392
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1393
|
+
id: string;
|
1394
|
+
} | {
|
1395
|
+
type: 'reasoning-start';
|
1396
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1397
|
+
id: string;
|
1398
|
+
} | {
|
1399
|
+
type: 'reasoning-delta';
|
1400
|
+
id: string;
|
1401
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1402
|
+
delta: string;
|
1403
|
+
} | {
|
1404
|
+
type: 'reasoning-end';
|
1405
|
+
id: string;
|
1406
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1407
|
+
} | {
|
1408
|
+
type: 'tool-input-start';
|
1409
|
+
id: string;
|
1410
|
+
toolName: string;
|
1411
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1412
|
+
providerExecuted?: boolean;
|
1413
|
+
} | {
|
1414
|
+
type: 'tool-input-delta';
|
1415
|
+
id: string;
|
1416
|
+
delta: string;
|
1417
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1418
|
+
} | {
|
1419
|
+
type: 'tool-input-end';
|
1420
|
+
id: string;
|
1421
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1422
|
+
} | LanguageModelV3ToolCall | LanguageModelV3ToolResult | LanguageModelV3File | LanguageModelV3Source | {
|
1423
|
+
type: 'stream-start';
|
1424
|
+
warnings: Array<LanguageModelV3CallWarning>;
|
1425
|
+
} | ({
|
1426
|
+
type: 'response-metadata';
|
1427
|
+
} & LanguageModelV3ResponseMetadata) | {
|
1428
|
+
type: 'finish';
|
1429
|
+
usage: LanguageModelV3Usage;
|
1430
|
+
finishReason: LanguageModelV3FinishReason;
|
1431
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1432
|
+
} | {
|
1433
|
+
type: 'raw';
|
1434
|
+
rawValue: unknown;
|
1435
|
+
} | {
|
1436
|
+
type: 'error';
|
1437
|
+
error: unknown;
|
1438
|
+
};
|
1439
|
+
|
1440
|
+
/**
|
1441
|
+
Specification for a language model that implements the language model interface version 3.
|
1442
|
+
*/
|
1443
|
+
type LanguageModelV3 = {
|
1444
|
+
/**
|
1445
|
+
The language model must specify which language model interface version it implements.
|
1446
|
+
*/
|
1447
|
+
readonly specificationVersion: 'v3';
|
1448
|
+
/**
|
1449
|
+
Name of the provider for logging purposes.
|
1450
|
+
*/
|
1451
|
+
readonly provider: string;
|
1452
|
+
/**
|
1453
|
+
Provider-specific model ID for logging purposes.
|
1454
|
+
*/
|
1455
|
+
readonly modelId: string;
|
1456
|
+
/**
|
1457
|
+
Supported URL patterns by media type for the provider.
|
1458
|
+
|
1459
|
+
The keys are media type patterns or full media types (e.g. `*\/*` for everything, `audio/*`, `video/*`, or `application/pdf`).
|
1460
|
+
and the values are arrays of regular expressions that match the URL paths.
|
1461
|
+
|
1462
|
+
The matching should be against lower-case URLs.
|
1463
|
+
|
1464
|
+
Matched URLs are supported natively by the model and are not downloaded.
|
1465
|
+
|
1466
|
+
@returns A map of supported URL patterns by media type (as a promise or a plain object).
|
1467
|
+
*/
|
1468
|
+
supportedUrls: PromiseLike<Record<string, RegExp[]>> | Record<string, RegExp[]>;
|
1469
|
+
/**
|
1470
|
+
Generates a language model output (non-streaming).
|
1471
|
+
|
1472
|
+
Naming: "do" prefix to prevent accidental direct usage of the method
|
1473
|
+
by the user.
|
1474
|
+
*/
|
1475
|
+
doGenerate(options: LanguageModelV3CallOptions): PromiseLike<{
|
1476
|
+
/**
|
1477
|
+
Ordered content that the model has generated.
|
1478
|
+
*/
|
1479
|
+
content: Array<LanguageModelV3Content>;
|
1480
|
+
/**
|
1481
|
+
Finish reason.
|
1482
|
+
*/
|
1483
|
+
finishReason: LanguageModelV3FinishReason;
|
1484
|
+
/**
|
1485
|
+
Usage information.
|
1486
|
+
*/
|
1487
|
+
usage: LanguageModelV3Usage;
|
1488
|
+
/**
|
1489
|
+
Additional provider-specific metadata. They are passed through
|
1490
|
+
from the provider to the AI SDK and enable provider-specific
|
1491
|
+
results that can be fully encapsulated in the provider.
|
1492
|
+
*/
|
1493
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1494
|
+
/**
|
1495
|
+
Optional request information for telemetry and debugging purposes.
|
1496
|
+
*/
|
1497
|
+
request?: {
|
1498
|
+
/**
|
1499
|
+
Request HTTP body that was sent to the provider API.
|
1500
|
+
*/
|
1501
|
+
body?: unknown;
|
1502
|
+
};
|
1503
|
+
/**
|
1504
|
+
Optional response information for telemetry and debugging purposes.
|
1505
|
+
*/
|
1506
|
+
response?: LanguageModelV3ResponseMetadata & {
|
1507
|
+
/**
|
1508
|
+
Response headers.
|
1509
|
+
*/
|
1510
|
+
headers?: SharedV2Headers;
|
1511
|
+
/**
|
1512
|
+
Response HTTP body.
|
1513
|
+
*/
|
1514
|
+
body?: unknown;
|
1515
|
+
};
|
1516
|
+
/**
|
1517
|
+
Warnings for the call, e.g. unsupported settings.
|
1518
|
+
*/
|
1519
|
+
warnings: Array<LanguageModelV3CallWarning>;
|
1520
|
+
}>;
|
1521
|
+
/**
|
1522
|
+
Generates a language model output (streaming).
|
1523
|
+
|
1524
|
+
Naming: "do" prefix to prevent accidental direct usage of the method
|
1525
|
+
by the user.
|
1526
|
+
*
|
1527
|
+
@return A stream of higher-level language model output parts.
|
1528
|
+
*/
|
1529
|
+
doStream(options: LanguageModelV3CallOptions): PromiseLike<{
|
1530
|
+
stream: ReadableStream<LanguageModelV3StreamPart>;
|
1531
|
+
/**
|
1532
|
+
Optional request information for telemetry and debugging purposes.
|
1533
|
+
*/
|
1534
|
+
request?: {
|
1535
|
+
/**
|
1536
|
+
Request HTTP body that was sent to the provider API.
|
1537
|
+
*/
|
1538
|
+
body?: unknown;
|
1539
|
+
};
|
1540
|
+
/**
|
1541
|
+
Optional response data.
|
1542
|
+
*/
|
1543
|
+
response?: {
|
1544
|
+
/**
|
1545
|
+
Response headers.
|
1546
|
+
*/
|
1547
|
+
headers?: SharedV2Headers;
|
1548
|
+
};
|
1549
|
+
}>;
|
1550
|
+
};
|
1551
|
+
|
1552
|
+
/**
|
1553
|
+
* Experimental middleware for LanguageModelV3.
|
1554
|
+
* This type defines the structure for middleware that can be used to modify
|
1555
|
+
* the behavior of LanguageModelV3 operations.
|
1556
|
+
*/
|
1557
|
+
type LanguageModelV3Middleware = {
|
1558
|
+
/**
|
1559
|
+
* Middleware specification version. Use `v3` for the current version.
|
1560
|
+
*/
|
1561
|
+
middlewareVersion?: 'v3' | undefined;
|
1562
|
+
/**
|
1563
|
+
* Override the provider name if desired.
|
1564
|
+
* @param options.model - The language model instance.
|
1565
|
+
*/
|
1566
|
+
overrideProvider?: (options: {
|
1567
|
+
model: LanguageModelV3;
|
1568
|
+
}) => string;
|
1569
|
+
/**
|
1570
|
+
* Override the model ID if desired.
|
1571
|
+
* @param options.model - The language model instance.
|
1572
|
+
*/
|
1573
|
+
overrideModelId?: (options: {
|
1574
|
+
model: LanguageModelV3;
|
1575
|
+
}) => string;
|
1576
|
+
/**
|
1577
|
+
* Override the supported URLs if desired.
|
1578
|
+
* @param options.model - The language model instance.
|
1579
|
+
*/
|
1580
|
+
overrideSupportedUrls?: (options: {
|
1581
|
+
model: LanguageModelV3;
|
1582
|
+
}) => PromiseLike<Record<string, RegExp[]>> | Record<string, RegExp[]>;
|
1583
|
+
/**
|
1584
|
+
* Transforms the parameters before they are passed to the language model.
|
1585
|
+
* @param options - Object containing the type of operation and the parameters.
|
1586
|
+
* @param options.type - The type of operation ('generate' or 'stream').
|
1587
|
+
* @param options.params - The original parameters for the language model call.
|
1588
|
+
* @returns A promise that resolves to the transformed parameters.
|
1589
|
+
*/
|
1590
|
+
transformParams?: (options: {
|
1591
|
+
type: 'generate' | 'stream';
|
1592
|
+
params: LanguageModelV3CallOptions;
|
1593
|
+
model: LanguageModelV3;
|
1594
|
+
}) => PromiseLike<LanguageModelV3CallOptions>;
|
1595
|
+
/**
|
1596
|
+
* Wraps the generate operation of the language model.
|
1597
|
+
* @param options - Object containing the generate function, parameters, and model.
|
1598
|
+
* @param options.doGenerate - The original generate function.
|
1599
|
+
* @param options.doStream - The original stream function.
|
1600
|
+
* @param options.params - The parameters for the generate call. If the
|
1601
|
+
* `transformParams` middleware is used, this will be the transformed parameters.
|
1602
|
+
* @param options.model - The language model instance.
|
1603
|
+
* @returns A promise that resolves to the result of the generate operation.
|
1604
|
+
*/
|
1605
|
+
wrapGenerate?: (options: {
|
1606
|
+
doGenerate: () => ReturnType<LanguageModelV3['doGenerate']>;
|
1607
|
+
doStream: () => ReturnType<LanguageModelV3['doStream']>;
|
1608
|
+
params: LanguageModelV3CallOptions;
|
1609
|
+
model: LanguageModelV3;
|
1610
|
+
}) => Promise<Awaited<ReturnType<LanguageModelV3['doGenerate']>>>;
|
1611
|
+
/**
|
1612
|
+
* Wraps the stream operation of the language model.
|
1613
|
+
*
|
1614
|
+
* @param options - Object containing the stream function, parameters, and model.
|
1615
|
+
* @param options.doGenerate - The original generate function.
|
1616
|
+
* @param options.doStream - The original stream function.
|
1617
|
+
* @param options.params - The parameters for the stream call. If the
|
1618
|
+
* `transformParams` middleware is used, this will be the transformed parameters.
|
1619
|
+
* @param options.model - The language model instance.
|
1620
|
+
* @returns A promise that resolves to the result of the stream operation.
|
1621
|
+
*/
|
1622
|
+
wrapStream?: (options: {
|
1623
|
+
doGenerate: () => ReturnType<LanguageModelV3['doGenerate']>;
|
1624
|
+
doStream: () => ReturnType<LanguageModelV3['doStream']>;
|
1625
|
+
params: LanguageModelV3CallOptions;
|
1626
|
+
model: LanguageModelV3;
|
1627
|
+
}) => PromiseLike<Awaited<ReturnType<LanguageModelV3['doStream']>>>;
|
1628
|
+
};
|
1629
|
+
|
1630
|
+
/**
|
1631
|
+
A tool has a name, a description, and a set of parameters.
|
1632
|
+
|
795
1633
|
Note: this is **not** the user-facing tool definition. The AI SDK methods will
|
796
1634
|
map the user-facing tool definitions to this format.
|
797
1635
|
*/
|
@@ -1933,7 +2771,7 @@ interface ProviderV3 {
|
|
1933
2771
|
|
1934
2772
|
@throws {NoSuchModelError} If no such model exists.
|
1935
2773
|
*/
|
1936
|
-
languageModel(modelId: string):
|
2774
|
+
languageModel(modelId: string): LanguageModelV3;
|
1937
2775
|
/**
|
1938
2776
|
Returns the text embedding model with the given id.
|
1939
2777
|
The model id is then passed to the provider function to get the model.
|
@@ -2029,4 +2867,4 @@ interface ProviderV2 {
|
|
2029
2867
|
speechModel?(modelId: string): SpeechModelV2;
|
2030
2868
|
}
|
2031
2869
|
|
2032
|
-
export { AISDKError, APICallError, type EmbeddingModelV2, type EmbeddingModelV2Embedding, type EmbeddingModelV3, type EmbeddingModelV3Embedding, EmptyResponseBodyError, type ImageModelV2, type ImageModelV2CallOptions, type ImageModelV2CallWarning, type ImageModelV2ProviderMetadata, type ImageModelV3, type ImageModelV3CallOptions, type ImageModelV3CallWarning, type ImageModelV3ProviderMetadata, InvalidArgumentError, InvalidPromptError, InvalidResponseDataError, type JSONArray, type JSONObject, JSONParseError, type JSONValue, type LanguageModelV2, type LanguageModelV2CallOptions, type LanguageModelV2CallWarning, type LanguageModelV2Content, type LanguageModelV2DataContent, type LanguageModelV2File, type LanguageModelV2FilePart, type LanguageModelV2FinishReason, type LanguageModelV2FunctionTool, type LanguageModelV2Message, type LanguageModelV2Middleware, type LanguageModelV2Prompt, type LanguageModelV2ProviderDefinedTool, type LanguageModelV2Reasoning, type LanguageModelV2ReasoningPart, type LanguageModelV2ResponseMetadata, type LanguageModelV2Source, type LanguageModelV2StreamPart, type LanguageModelV2Text, type LanguageModelV2TextPart, type LanguageModelV2ToolCall, type LanguageModelV2ToolCallPart, type LanguageModelV2ToolChoice, type LanguageModelV2ToolResultOutput, type LanguageModelV2ToolResultPart, type LanguageModelV2Usage, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, type ProviderV2, type ProviderV3, type SharedV2Headers, type SharedV2ProviderMetadata, type SharedV2ProviderOptions, type SpeechModelV2, type SpeechModelV2CallOptions, type SpeechModelV2CallWarning, TooManyEmbeddingValuesForCallError, type TranscriptionModelV2, type TranscriptionModelV2CallOptions, type TranscriptionModelV2CallWarning, TypeValidationError, UnsupportedFunctionalityError, getErrorMessage, isJSONArray, isJSONObject, isJSONValue };
|
2870
|
+
export { AISDKError, APICallError, type EmbeddingModelV2, type EmbeddingModelV2Embedding, type EmbeddingModelV3, type EmbeddingModelV3Embedding, EmptyResponseBodyError, type ImageModelV2, type ImageModelV2CallOptions, type ImageModelV2CallWarning, type ImageModelV2ProviderMetadata, type ImageModelV3, type ImageModelV3CallOptions, type ImageModelV3CallWarning, type ImageModelV3ProviderMetadata, InvalidArgumentError, InvalidPromptError, InvalidResponseDataError, type JSONArray, type JSONObject, JSONParseError, type JSONValue, type LanguageModelV2, type LanguageModelV2CallOptions, type LanguageModelV2CallWarning, type LanguageModelV2Content, type LanguageModelV2DataContent, type LanguageModelV2File, type LanguageModelV2FilePart, type LanguageModelV2FinishReason, type LanguageModelV2FunctionTool, type LanguageModelV2Message, type LanguageModelV2Middleware, type LanguageModelV2Prompt, type LanguageModelV2ProviderDefinedTool, type LanguageModelV2Reasoning, type LanguageModelV2ReasoningPart, type LanguageModelV2ResponseMetadata, type LanguageModelV2Source, type LanguageModelV2StreamPart, type LanguageModelV2Text, type LanguageModelV2TextPart, type LanguageModelV2ToolCall, type LanguageModelV2ToolCallPart, type LanguageModelV2ToolChoice, type LanguageModelV2ToolResultOutput, type LanguageModelV2ToolResultPart, type LanguageModelV2Usage, type LanguageModelV3, type LanguageModelV3CallOptions, type LanguageModelV3CallWarning, type LanguageModelV3Content, type LanguageModelV3DataContent, type LanguageModelV3File, type LanguageModelV3FilePart, type LanguageModelV3FinishReason, type LanguageModelV3FunctionTool, type LanguageModelV3Message, type LanguageModelV3Middleware, type LanguageModelV3Prompt, type LanguageModelV3ProviderDefinedTool, type LanguageModelV3Reasoning, type LanguageModelV3ReasoningPart, type LanguageModelV3ResponseMetadata, type LanguageModelV3Source, type LanguageModelV3StreamPart, type LanguageModelV3Text, type LanguageModelV3TextPart, type LanguageModelV3ToolCall, type LanguageModelV3ToolCallPart, type LanguageModelV3ToolChoice, type LanguageModelV3ToolResult, type LanguageModelV3ToolResultOutput, type LanguageModelV3ToolResultPart, type LanguageModelV3Usage, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, type ProviderV2, type ProviderV3, type SharedV2Headers, type SharedV2ProviderMetadata, type SharedV2ProviderOptions, type SpeechModelV2, type SpeechModelV2CallOptions, type SpeechModelV2CallWarning, TooManyEmbeddingValuesForCallError, type TranscriptionModelV2, type TranscriptionModelV2CallOptions, type TranscriptionModelV2CallWarning, TypeValidationError, UnsupportedFunctionalityError, getErrorMessage, isJSONArray, isJSONObject, isJSONValue };
|