@ai-sdk/provider 2.1.0-beta.2 → 2.1.0-beta.4
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 +13 -0
- package/dist/index.d.mts +1060 -163
- package/dist/index.d.ts +1060 -163
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { JSONSchema7 } from 'json-schema';
|
2
2
|
export { JSONSchema7, JSONSchema7Definition } from 'json-schema';
|
3
3
|
|
4
|
-
type
|
4
|
+
type SharedV3Headers = Record<string, string>;
|
5
5
|
|
6
6
|
/**
|
7
7
|
A JSON value can be a string, number, boolean, object, array, or null.
|
@@ -13,6 +13,54 @@ type JSONObject = {
|
|
13
13
|
};
|
14
14
|
type JSONArray = JSONValue[];
|
15
15
|
|
16
|
+
/**
|
17
|
+
* Additional provider-specific metadata.
|
18
|
+
* Metadata are additional outputs from the provider.
|
19
|
+
* They are passed through to the provider from the AI SDK
|
20
|
+
* and enable provider-specific functionality
|
21
|
+
* that can be fully encapsulated in the provider.
|
22
|
+
*
|
23
|
+
* This enables us to quickly ship provider-specific functionality
|
24
|
+
* without affecting the core AI SDK.
|
25
|
+
*
|
26
|
+
* The outer record is keyed by the provider name, and the inner
|
27
|
+
* record is keyed by the provider-specific metadata key.
|
28
|
+
*
|
29
|
+
* ```ts
|
30
|
+
* {
|
31
|
+
* "anthropic": {
|
32
|
+
* "cacheControl": { "type": "ephemeral" }
|
33
|
+
* }
|
34
|
+
* }
|
35
|
+
* ```
|
36
|
+
*/
|
37
|
+
type SharedV3ProviderMetadata = Record<string, Record<string, JSONValue>>;
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Additional provider-specific options.
|
41
|
+
* Options are additional input to the provider.
|
42
|
+
* They are passed through to the provider from the AI SDK
|
43
|
+
* and enable provider-specific functionality
|
44
|
+
* that can be fully encapsulated in the provider.
|
45
|
+
*
|
46
|
+
* This enables us to quickly ship provider-specific functionality
|
47
|
+
* without affecting the core AI SDK.
|
48
|
+
*
|
49
|
+
* The outer record is keyed by the provider name, and the inner
|
50
|
+
* record is keyed by the provider-specific metadata key.
|
51
|
+
*
|
52
|
+
* ```ts
|
53
|
+
* {
|
54
|
+
* "anthropic": {
|
55
|
+
* "cacheControl": { "type": "ephemeral" }
|
56
|
+
* }
|
57
|
+
* }
|
58
|
+
* ```
|
59
|
+
*/
|
60
|
+
type SharedV3ProviderOptions = Record<string, Record<string, JSONValue>>;
|
61
|
+
|
62
|
+
type SharedV2Headers = Record<string, string>;
|
63
|
+
|
16
64
|
/**
|
17
65
|
* Additional provider-specific metadata.
|
18
66
|
* Metadata are additional outputs from the provider.
|
@@ -120,7 +168,7 @@ type EmbeddingModelV3<VALUE> = {
|
|
120
168
|
to the provider from the AI SDK and enable provider-specific
|
121
169
|
functionality that can be fully encapsulated in the provider.
|
122
170
|
*/
|
123
|
-
providerOptions?:
|
171
|
+
providerOptions?: SharedV3ProviderOptions;
|
124
172
|
/**
|
125
173
|
Additional HTTP headers to be sent with the request.
|
126
174
|
Only applicable for HTTP-based providers.
|
@@ -142,7 +190,7 @@ type EmbeddingModelV3<VALUE> = {
|
|
142
190
|
from the provider to the AI SDK and enable provider-specific
|
143
191
|
results that can be fully encapsulated in the provider.
|
144
192
|
*/
|
145
|
-
providerMetadata?:
|
193
|
+
providerMetadata?: SharedV3ProviderMetadata;
|
146
194
|
/**
|
147
195
|
Optional response information for debugging purposes.
|
148
196
|
*/
|
@@ -150,7 +198,7 @@ type EmbeddingModelV3<VALUE> = {
|
|
150
198
|
/**
|
151
199
|
Response headers.
|
152
200
|
*/
|
153
|
-
headers?:
|
201
|
+
headers?: SharedV3Headers;
|
154
202
|
/**
|
155
203
|
The response body.
|
156
204
|
*/
|
@@ -525,7 +573,7 @@ type ImageModelV3CallOptions = {
|
|
525
573
|
}
|
526
574
|
```
|
527
575
|
*/
|
528
|
-
providerOptions:
|
576
|
+
providerOptions: SharedV3ProviderOptions;
|
529
577
|
/**
|
530
578
|
Abort signal for cancelling the operation.
|
531
579
|
*/
|
@@ -795,7 +843,7 @@ A tool has a name, a description, and a set of parameters.
|
|
795
843
|
Note: this is **not** the user-facing tool definition. The AI SDK methods will
|
796
844
|
map the user-facing tool definitions to this format.
|
797
845
|
*/
|
798
|
-
type
|
846
|
+
type LanguageModelV3FunctionTool = {
|
799
847
|
/**
|
800
848
|
The type of the tool (always 'function').
|
801
849
|
*/
|
@@ -817,13 +865,13 @@ type LanguageModelV2FunctionTool = {
|
|
817
865
|
/**
|
818
866
|
The provider-specific options for the tool.
|
819
867
|
*/
|
820
|
-
providerOptions?:
|
868
|
+
providerOptions?: SharedV3ProviderOptions;
|
821
869
|
};
|
822
870
|
|
823
871
|
/**
|
824
872
|
Data content. Can be a Uint8Array, base64 encoded data as a string or a URL.
|
825
873
|
*/
|
826
|
-
type
|
874
|
+
type LanguageModelV3DataContent = Uint8Array | string | URL;
|
827
875
|
|
828
876
|
/**
|
829
877
|
A prompt is a list of messages.
|
@@ -834,31 +882,31 @@ tool calls. The validation happens at runtime.
|
|
834
882
|
Note: This is not a user-facing prompt. The AI SDK methods will map the
|
835
883
|
user-facing prompt types such as chat or instruction prompts to this format.
|
836
884
|
*/
|
837
|
-
type
|
838
|
-
type
|
885
|
+
type LanguageModelV3Prompt = Array<LanguageModelV3Message>;
|
886
|
+
type LanguageModelV3Message = ({
|
839
887
|
role: 'system';
|
840
888
|
content: string;
|
841
889
|
} | {
|
842
890
|
role: 'user';
|
843
|
-
content: Array<
|
891
|
+
content: Array<LanguageModelV3TextPart | LanguageModelV3FilePart>;
|
844
892
|
} | {
|
845
893
|
role: 'assistant';
|
846
|
-
content: Array<
|
894
|
+
content: Array<LanguageModelV3TextPart | LanguageModelV3FilePart | LanguageModelV3ReasoningPart | LanguageModelV3ToolCallPart | LanguageModelV3ToolResultPart>;
|
847
895
|
} | {
|
848
896
|
role: 'tool';
|
849
|
-
content: Array<
|
897
|
+
content: Array<LanguageModelV3ToolResultPart>;
|
850
898
|
}) & {
|
851
899
|
/**
|
852
900
|
* Additional provider-specific options. They are passed through
|
853
901
|
* to the provider from the AI SDK and enable provider-specific
|
854
902
|
* functionality that can be fully encapsulated in the provider.
|
855
903
|
*/
|
856
|
-
providerOptions?:
|
904
|
+
providerOptions?: SharedV3ProviderOptions;
|
857
905
|
};
|
858
906
|
/**
|
859
907
|
Text content part of a prompt. It contains a string of text.
|
860
908
|
*/
|
861
|
-
interface
|
909
|
+
interface LanguageModelV3TextPart {
|
862
910
|
type: 'text';
|
863
911
|
/**
|
864
912
|
The text content.
|
@@ -869,12 +917,12 @@ interface LanguageModelV2TextPart {
|
|
869
917
|
* to the provider from the AI SDK and enable provider-specific
|
870
918
|
* functionality that can be fully encapsulated in the provider.
|
871
919
|
*/
|
872
|
-
providerOptions?:
|
920
|
+
providerOptions?: SharedV3ProviderOptions;
|
873
921
|
}
|
874
922
|
/**
|
875
923
|
Reasoning content part of a prompt. It contains a string of reasoning text.
|
876
924
|
*/
|
877
|
-
interface
|
925
|
+
interface LanguageModelV3ReasoningPart {
|
878
926
|
type: 'reasoning';
|
879
927
|
/**
|
880
928
|
The reasoning text.
|
@@ -885,12 +933,12 @@ interface LanguageModelV2ReasoningPart {
|
|
885
933
|
* to the provider from the AI SDK and enable provider-specific
|
886
934
|
* functionality that can be fully encapsulated in the provider.
|
887
935
|
*/
|
888
|
-
providerOptions?:
|
936
|
+
providerOptions?: SharedV3ProviderOptions;
|
889
937
|
}
|
890
938
|
/**
|
891
939
|
File content part of a prompt. It contains a file.
|
892
940
|
*/
|
893
|
-
interface
|
941
|
+
interface LanguageModelV3FilePart {
|
894
942
|
type: 'file';
|
895
943
|
/**
|
896
944
|
* Optional filename of the file.
|
@@ -899,7 +947,7 @@ interface LanguageModelV2FilePart {
|
|
899
947
|
/**
|
900
948
|
File data. Can be a Uint8Array, base64 encoded data as a string or a URL.
|
901
949
|
*/
|
902
|
-
data:
|
950
|
+
data: LanguageModelV3DataContent;
|
903
951
|
/**
|
904
952
|
IANA media type of the file.
|
905
953
|
|
@@ -913,12 +961,12 @@ interface LanguageModelV2FilePart {
|
|
913
961
|
* to the provider from the AI SDK and enable provider-specific
|
914
962
|
* functionality that can be fully encapsulated in the provider.
|
915
963
|
*/
|
916
|
-
providerOptions?:
|
964
|
+
providerOptions?: SharedV3ProviderOptions;
|
917
965
|
}
|
918
966
|
/**
|
919
967
|
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
920
968
|
*/
|
921
|
-
interface
|
969
|
+
interface LanguageModelV3ToolCallPart {
|
922
970
|
type: 'tool-call';
|
923
971
|
/**
|
924
972
|
ID of the tool call. This ID is used to match the tool call with the tool result.
|
@@ -942,12 +990,12 @@ interface LanguageModelV2ToolCallPart {
|
|
942
990
|
* to the provider from the AI SDK and enable provider-specific
|
943
991
|
* functionality that can be fully encapsulated in the provider.
|
944
992
|
*/
|
945
|
-
providerOptions?:
|
993
|
+
providerOptions?: SharedV3ProviderOptions;
|
946
994
|
}
|
947
995
|
/**
|
948
996
|
Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
949
997
|
*/
|
950
|
-
interface
|
998
|
+
interface LanguageModelV3ToolResultPart {
|
951
999
|
type: 'tool-result';
|
952
1000
|
/**
|
953
1001
|
ID of the tool call that this result is associated with.
|
@@ -960,15 +1008,15 @@ interface LanguageModelV2ToolResultPart {
|
|
960
1008
|
/**
|
961
1009
|
Result of the tool call.
|
962
1010
|
*/
|
963
|
-
output:
|
1011
|
+
output: LanguageModelV3ToolResultOutput;
|
964
1012
|
/**
|
965
1013
|
* Additional provider-specific options. They are passed through
|
966
1014
|
* to the provider from the AI SDK and enable provider-specific
|
967
1015
|
* functionality that can be fully encapsulated in the provider.
|
968
1016
|
*/
|
969
|
-
providerOptions?:
|
1017
|
+
providerOptions?: SharedV3ProviderOptions;
|
970
1018
|
}
|
971
|
-
type
|
1019
|
+
type LanguageModelV3ToolResultOutput = {
|
972
1020
|
type: 'text';
|
973
1021
|
value: string;
|
974
1022
|
} | {
|
@@ -1005,7 +1053,7 @@ IANA media type.
|
|
1005
1053
|
/**
|
1006
1054
|
The configuration of a tool that is defined by the provider.
|
1007
1055
|
*/
|
1008
|
-
type
|
1056
|
+
type LanguageModelV3ProviderDefinedTool = {
|
1009
1057
|
/**
|
1010
1058
|
The type of the tool (always 'provider-defined').
|
1011
1059
|
*/
|
@@ -1024,7 +1072,7 @@ type LanguageModelV2ProviderDefinedTool = {
|
|
1024
1072
|
args: Record<string, unknown>;
|
1025
1073
|
};
|
1026
1074
|
|
1027
|
-
type
|
1075
|
+
type LanguageModelV3ToolChoice = {
|
1028
1076
|
type: 'auto';
|
1029
1077
|
} | {
|
1030
1078
|
type: 'none';
|
@@ -1035,7 +1083,7 @@ type LanguageModelV2ToolChoice = {
|
|
1035
1083
|
toolName: string;
|
1036
1084
|
};
|
1037
1085
|
|
1038
|
-
type
|
1086
|
+
type LanguageModelV3CallOptions = {
|
1039
1087
|
/**
|
1040
1088
|
A language mode prompt is a standardized prompt type.
|
1041
1089
|
|
@@ -1044,7 +1092,7 @@ type LanguageModelV2CallOptions = {
|
|
1044
1092
|
That approach allows us to evolve the user facing prompts without breaking
|
1045
1093
|
the language model interface.
|
1046
1094
|
*/
|
1047
|
-
prompt:
|
1095
|
+
prompt: LanguageModelV3Prompt;
|
1048
1096
|
/**
|
1049
1097
|
Maximum number of tokens to generate.
|
1050
1098
|
*/
|
@@ -1110,11 +1158,11 @@ type LanguageModelV2CallOptions = {
|
|
1110
1158
|
/**
|
1111
1159
|
The tools that are available for the model.
|
1112
1160
|
*/
|
1113
|
-
tools?: Array<
|
1161
|
+
tools?: Array<LanguageModelV3FunctionTool | LanguageModelV3ProviderDefinedTool>;
|
1114
1162
|
/**
|
1115
1163
|
Specifies how the tool should be selected. Defaults to 'auto'.
|
1116
1164
|
*/
|
1117
|
-
toolChoice?:
|
1165
|
+
toolChoice?: LanguageModelV3ToolChoice;
|
1118
1166
|
/**
|
1119
1167
|
Include raw chunks in the stream. Only applicable for streaming calls.
|
1120
1168
|
*/
|
@@ -1133,20 +1181,20 @@ type LanguageModelV2CallOptions = {
|
|
1133
1181
|
* to the provider from the AI SDK and enable provider-specific
|
1134
1182
|
* functionality that can be fully encapsulated in the provider.
|
1135
1183
|
*/
|
1136
|
-
providerOptions?:
|
1184
|
+
providerOptions?: SharedV3ProviderOptions;
|
1137
1185
|
};
|
1138
1186
|
|
1139
1187
|
/**
|
1140
1188
|
Warning from the model provider for this call. The call will proceed, but e.g.
|
1141
1189
|
some settings might not be supported, which can lead to suboptimal results.
|
1142
1190
|
*/
|
1143
|
-
type
|
1191
|
+
type LanguageModelV3CallWarning = {
|
1144
1192
|
type: 'unsupported-setting';
|
1145
|
-
setting: Omit<keyof
|
1193
|
+
setting: Omit<keyof LanguageModelV3CallOptions, 'prompt'>;
|
1146
1194
|
details?: string;
|
1147
1195
|
} | {
|
1148
1196
|
type: 'unsupported-tool';
|
1149
|
-
tool:
|
1197
|
+
tool: LanguageModelV3FunctionTool | LanguageModelV3ProviderDefinedTool;
|
1150
1198
|
details?: string;
|
1151
1199
|
} | {
|
1152
1200
|
type: 'other';
|
@@ -1158,7 +1206,7 @@ A file that has been generated by the model.
|
|
1158
1206
|
Generated files as base64 encoded strings or binary data.
|
1159
1207
|
The files should be returned without any unnecessary conversion.
|
1160
1208
|
*/
|
1161
|
-
type
|
1209
|
+
type LanguageModelV3File = {
|
1162
1210
|
type: 'file';
|
1163
1211
|
/**
|
1164
1212
|
The IANA media type of the file, e.g. `image/png` or `audio/mp3`.
|
@@ -1180,19 +1228,19 @@ type LanguageModelV2File = {
|
|
1180
1228
|
/**
|
1181
1229
|
Reasoning that the model has generated.
|
1182
1230
|
*/
|
1183
|
-
type
|
1231
|
+
type LanguageModelV3Reasoning = {
|
1184
1232
|
type: 'reasoning';
|
1185
1233
|
text: string;
|
1186
1234
|
/**
|
1187
1235
|
* Optional provider-specific metadata for the reasoning part.
|
1188
1236
|
*/
|
1189
|
-
providerMetadata?:
|
1237
|
+
providerMetadata?: SharedV3ProviderMetadata;
|
1190
1238
|
};
|
1191
1239
|
|
1192
1240
|
/**
|
1193
1241
|
A source that has been used as input to generate the response.
|
1194
1242
|
*/
|
1195
|
-
type
|
1243
|
+
type LanguageModelV3Source = {
|
1196
1244
|
type: 'source';
|
1197
1245
|
/**
|
1198
1246
|
* The type of source - URL sources reference web content.
|
@@ -1213,7 +1261,7 @@ type LanguageModelV2Source = {
|
|
1213
1261
|
/**
|
1214
1262
|
* Additional provider metadata for the source.
|
1215
1263
|
*/
|
1216
|
-
providerMetadata?:
|
1264
|
+
providerMetadata?: SharedV3ProviderMetadata;
|
1217
1265
|
} | {
|
1218
1266
|
type: 'source';
|
1219
1267
|
/**
|
@@ -1239,25 +1287,25 @@ type LanguageModelV2Source = {
|
|
1239
1287
|
/**
|
1240
1288
|
* Additional provider metadata for the source.
|
1241
1289
|
*/
|
1242
|
-
providerMetadata?:
|
1290
|
+
providerMetadata?: SharedV3ProviderMetadata;
|
1243
1291
|
};
|
1244
1292
|
|
1245
1293
|
/**
|
1246
1294
|
Text that the model has generated.
|
1247
1295
|
*/
|
1248
|
-
type
|
1296
|
+
type LanguageModelV3Text = {
|
1249
1297
|
type: 'text';
|
1250
1298
|
/**
|
1251
1299
|
The text content.
|
1252
1300
|
*/
|
1253
1301
|
text: string;
|
1254
|
-
providerMetadata?:
|
1302
|
+
providerMetadata?: SharedV3ProviderMetadata;
|
1255
1303
|
};
|
1256
1304
|
|
1257
1305
|
/**
|
1258
1306
|
* Tool calls that the model has generated.
|
1259
1307
|
*/
|
1260
|
-
type
|
1308
|
+
type LanguageModelV3ToolCall = {
|
1261
1309
|
type: 'tool-call';
|
1262
1310
|
/**
|
1263
1311
|
* The identifier of the tool call. It must be unique across all tool calls.
|
@@ -1280,13 +1328,13 @@ type LanguageModelV2ToolCall = {
|
|
1280
1328
|
/**
|
1281
1329
|
* Additional provider-specific metadata for the tool call.
|
1282
1330
|
*/
|
1283
|
-
providerMetadata?:
|
1331
|
+
providerMetadata?: SharedV3ProviderMetadata;
|
1284
1332
|
};
|
1285
1333
|
|
1286
1334
|
/**
|
1287
1335
|
Result of a tool call that has been executed by the provider.
|
1288
1336
|
*/
|
1289
|
-
type
|
1337
|
+
type LanguageModelV3ToolResult = {
|
1290
1338
|
type: 'tool-result';
|
1291
1339
|
/**
|
1292
1340
|
* The ID of the tool call that this result is associated with.
|
@@ -1306,17 +1354,28 @@ type LanguageModelV2ToolResult = {
|
|
1306
1354
|
isError?: boolean;
|
1307
1355
|
/**
|
1308
1356
|
* Whether the tool result was generated by the provider.
|
1357
|
+
*
|
1309
1358
|
* If this flag is set to true, the tool result was generated by the provider.
|
1310
1359
|
* If this flag is not set or is false, the tool result was generated by the client.
|
1311
1360
|
*/
|
1312
1361
|
providerExecuted?: boolean;
|
1362
|
+
/**
|
1363
|
+
* Whether the tool result is preliminary.
|
1364
|
+
*
|
1365
|
+
* Preliminary tool results replace each other, e.g. image previews.
|
1366
|
+
* There always has to be a final, non-preliminary tool result.
|
1367
|
+
*
|
1368
|
+
* If this flag is set to true, the tool result is preliminary.
|
1369
|
+
* If this flag is not set or is false, the tool result is not preliminary.
|
1370
|
+
*/
|
1371
|
+
preliminary?: boolean;
|
1313
1372
|
/**
|
1314
1373
|
* Additional provider-specific metadata for the tool result.
|
1315
1374
|
*/
|
1316
|
-
providerMetadata?:
|
1375
|
+
providerMetadata?: SharedV3ProviderMetadata;
|
1317
1376
|
};
|
1318
1377
|
|
1319
|
-
type
|
1378
|
+
type LanguageModelV3Content = LanguageModelV3Text | LanguageModelV3Reasoning | LanguageModelV3File | LanguageModelV3Source | LanguageModelV3ToolCall | LanguageModelV3ToolResult;
|
1320
1379
|
|
1321
1380
|
/**
|
1322
1381
|
Reason why a language model finished generating a response.
|
@@ -1330,9 +1389,9 @@ Can be one of the following:
|
|
1330
1389
|
- `other`: model stopped for other reasons
|
1331
1390
|
- `unknown`: the model has not transmitted a finish reason
|
1332
1391
|
*/
|
1333
|
-
type
|
1392
|
+
type LanguageModelV3FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown';
|
1334
1393
|
|
1335
|
-
interface
|
1394
|
+
interface LanguageModelV3ResponseMetadata {
|
1336
1395
|
/**
|
1337
1396
|
ID for the generated response, if the provider sends one.
|
1338
1397
|
*/
|
@@ -1353,7 +1412,7 @@ Usage information for a language model call.
|
|
1353
1412
|
If your API return additional usage information, you can add it to the
|
1354
1413
|
provider metadata under your provider's key.
|
1355
1414
|
*/
|
1356
|
-
type
|
1415
|
+
type LanguageModelV3Usage = {
|
1357
1416
|
/**
|
1358
1417
|
The number of input (prompt) tokens used.
|
1359
1418
|
*/
|
@@ -1378,57 +1437,57 @@ type LanguageModelV2Usage = {
|
|
1378
1437
|
cachedInputTokens?: number | undefined;
|
1379
1438
|
};
|
1380
1439
|
|
1381
|
-
type
|
1440
|
+
type LanguageModelV3StreamPart = {
|
1382
1441
|
type: 'text-start';
|
1383
|
-
providerMetadata?:
|
1442
|
+
providerMetadata?: SharedV3ProviderMetadata;
|
1384
1443
|
id: string;
|
1385
1444
|
} | {
|
1386
1445
|
type: 'text-delta';
|
1387
1446
|
id: string;
|
1388
|
-
providerMetadata?:
|
1447
|
+
providerMetadata?: SharedV3ProviderMetadata;
|
1389
1448
|
delta: string;
|
1390
1449
|
} | {
|
1391
1450
|
type: 'text-end';
|
1392
|
-
providerMetadata?:
|
1451
|
+
providerMetadata?: SharedV3ProviderMetadata;
|
1393
1452
|
id: string;
|
1394
1453
|
} | {
|
1395
1454
|
type: 'reasoning-start';
|
1396
|
-
providerMetadata?:
|
1455
|
+
providerMetadata?: SharedV3ProviderMetadata;
|
1397
1456
|
id: string;
|
1398
1457
|
} | {
|
1399
1458
|
type: 'reasoning-delta';
|
1400
1459
|
id: string;
|
1401
|
-
providerMetadata?:
|
1460
|
+
providerMetadata?: SharedV3ProviderMetadata;
|
1402
1461
|
delta: string;
|
1403
1462
|
} | {
|
1404
1463
|
type: 'reasoning-end';
|
1405
1464
|
id: string;
|
1406
|
-
providerMetadata?:
|
1465
|
+
providerMetadata?: SharedV3ProviderMetadata;
|
1407
1466
|
} | {
|
1408
1467
|
type: 'tool-input-start';
|
1409
1468
|
id: string;
|
1410
1469
|
toolName: string;
|
1411
|
-
providerMetadata?:
|
1470
|
+
providerMetadata?: SharedV3ProviderMetadata;
|
1412
1471
|
providerExecuted?: boolean;
|
1413
1472
|
} | {
|
1414
1473
|
type: 'tool-input-delta';
|
1415
1474
|
id: string;
|
1416
1475
|
delta: string;
|
1417
|
-
providerMetadata?:
|
1476
|
+
providerMetadata?: SharedV3ProviderMetadata;
|
1418
1477
|
} | {
|
1419
1478
|
type: 'tool-input-end';
|
1420
1479
|
id: string;
|
1421
|
-
providerMetadata?:
|
1422
|
-
} |
|
1480
|
+
providerMetadata?: SharedV3ProviderMetadata;
|
1481
|
+
} | LanguageModelV3ToolCall | LanguageModelV3ToolResult | LanguageModelV3File | LanguageModelV3Source | {
|
1423
1482
|
type: 'stream-start';
|
1424
|
-
warnings: Array<
|
1483
|
+
warnings: Array<LanguageModelV3CallWarning>;
|
1425
1484
|
} | ({
|
1426
1485
|
type: 'response-metadata';
|
1427
|
-
} &
|
1486
|
+
} & LanguageModelV3ResponseMetadata) | {
|
1428
1487
|
type: 'finish';
|
1429
|
-
usage:
|
1430
|
-
finishReason:
|
1431
|
-
providerMetadata?:
|
1488
|
+
usage: LanguageModelV3Usage;
|
1489
|
+
finishReason: LanguageModelV3FinishReason;
|
1490
|
+
providerMetadata?: SharedV3ProviderMetadata;
|
1432
1491
|
} | {
|
1433
1492
|
type: 'raw';
|
1434
1493
|
rawValue: unknown;
|
@@ -1438,13 +1497,13 @@ type LanguageModelV2StreamPart = {
|
|
1438
1497
|
};
|
1439
1498
|
|
1440
1499
|
/**
|
1441
|
-
Specification for a language model that implements the language model interface version
|
1500
|
+
Specification for a language model that implements the language model interface version 3.
|
1442
1501
|
*/
|
1443
|
-
type
|
1502
|
+
type LanguageModelV3 = {
|
1444
1503
|
/**
|
1445
1504
|
The language model must specify which language model interface version it implements.
|
1446
1505
|
*/
|
1447
|
-
readonly specificationVersion: '
|
1506
|
+
readonly specificationVersion: 'v3';
|
1448
1507
|
/**
|
1449
1508
|
Name of the provider for logging purposes.
|
1450
1509
|
*/
|
@@ -1472,25 +1531,25 @@ type LanguageModelV2 = {
|
|
1472
1531
|
Naming: "do" prefix to prevent accidental direct usage of the method
|
1473
1532
|
by the user.
|
1474
1533
|
*/
|
1475
|
-
doGenerate(options:
|
1534
|
+
doGenerate(options: LanguageModelV3CallOptions): PromiseLike<{
|
1476
1535
|
/**
|
1477
1536
|
Ordered content that the model has generated.
|
1478
1537
|
*/
|
1479
|
-
content: Array<
|
1538
|
+
content: Array<LanguageModelV3Content>;
|
1480
1539
|
/**
|
1481
1540
|
Finish reason.
|
1482
1541
|
*/
|
1483
|
-
finishReason:
|
1542
|
+
finishReason: LanguageModelV3FinishReason;
|
1484
1543
|
/**
|
1485
1544
|
Usage information.
|
1486
1545
|
*/
|
1487
|
-
usage:
|
1546
|
+
usage: LanguageModelV3Usage;
|
1488
1547
|
/**
|
1489
1548
|
Additional provider-specific metadata. They are passed through
|
1490
1549
|
from the provider to the AI SDK and enable provider-specific
|
1491
1550
|
results that can be fully encapsulated in the provider.
|
1492
1551
|
*/
|
1493
|
-
providerMetadata?:
|
1552
|
+
providerMetadata?: SharedV3ProviderMetadata;
|
1494
1553
|
/**
|
1495
1554
|
Optional request information for telemetry and debugging purposes.
|
1496
1555
|
*/
|
@@ -1503,11 +1562,11 @@ type LanguageModelV2 = {
|
|
1503
1562
|
/**
|
1504
1563
|
Optional response information for telemetry and debugging purposes.
|
1505
1564
|
*/
|
1506
|
-
response?:
|
1565
|
+
response?: LanguageModelV3ResponseMetadata & {
|
1507
1566
|
/**
|
1508
1567
|
Response headers.
|
1509
1568
|
*/
|
1510
|
-
headers?:
|
1569
|
+
headers?: SharedV3Headers;
|
1511
1570
|
/**
|
1512
1571
|
Response HTTP body.
|
1513
1572
|
*/
|
@@ -1516,7 +1575,7 @@ type LanguageModelV2 = {
|
|
1516
1575
|
/**
|
1517
1576
|
Warnings for the call, e.g. unsupported settings.
|
1518
1577
|
*/
|
1519
|
-
warnings: Array<
|
1578
|
+
warnings: Array<LanguageModelV3CallWarning>;
|
1520
1579
|
}>;
|
1521
1580
|
/**
|
1522
1581
|
Generates a language model output (streaming).
|
@@ -1526,8 +1585,8 @@ type LanguageModelV2 = {
|
|
1526
1585
|
*
|
1527
1586
|
@return A stream of higher-level language model output parts.
|
1528
1587
|
*/
|
1529
|
-
doStream(options:
|
1530
|
-
stream: ReadableStream<
|
1588
|
+
doStream(options: LanguageModelV3CallOptions): PromiseLike<{
|
1589
|
+
stream: ReadableStream<LanguageModelV3StreamPart>;
|
1531
1590
|
/**
|
1532
1591
|
Optional request information for telemetry and debugging purposes.
|
1533
1592
|
*/
|
@@ -1544,41 +1603,41 @@ type LanguageModelV2 = {
|
|
1544
1603
|
/**
|
1545
1604
|
Response headers.
|
1546
1605
|
*/
|
1547
|
-
headers?:
|
1606
|
+
headers?: SharedV3Headers;
|
1548
1607
|
};
|
1549
1608
|
}>;
|
1550
1609
|
};
|
1551
1610
|
|
1552
1611
|
/**
|
1553
|
-
* Experimental middleware for
|
1612
|
+
* Experimental middleware for LanguageModelV3.
|
1554
1613
|
* This type defines the structure for middleware that can be used to modify
|
1555
|
-
* the behavior of
|
1614
|
+
* the behavior of LanguageModelV3 operations.
|
1556
1615
|
*/
|
1557
|
-
type
|
1616
|
+
type LanguageModelV3Middleware = {
|
1558
1617
|
/**
|
1559
|
-
* Middleware specification version. Use `
|
1618
|
+
* Middleware specification version. Use `v3` for the current version.
|
1560
1619
|
*/
|
1561
|
-
middlewareVersion?: '
|
1620
|
+
middlewareVersion?: 'v3' | undefined;
|
1562
1621
|
/**
|
1563
1622
|
* Override the provider name if desired.
|
1564
1623
|
* @param options.model - The language model instance.
|
1565
1624
|
*/
|
1566
1625
|
overrideProvider?: (options: {
|
1567
|
-
model:
|
1626
|
+
model: LanguageModelV3;
|
1568
1627
|
}) => string;
|
1569
1628
|
/**
|
1570
1629
|
* Override the model ID if desired.
|
1571
1630
|
* @param options.model - The language model instance.
|
1572
1631
|
*/
|
1573
1632
|
overrideModelId?: (options: {
|
1574
|
-
model:
|
1633
|
+
model: LanguageModelV3;
|
1575
1634
|
}) => string;
|
1576
1635
|
/**
|
1577
1636
|
* Override the supported URLs if desired.
|
1578
1637
|
* @param options.model - The language model instance.
|
1579
1638
|
*/
|
1580
1639
|
overrideSupportedUrls?: (options: {
|
1581
|
-
model:
|
1640
|
+
model: LanguageModelV3;
|
1582
1641
|
}) => PromiseLike<Record<string, RegExp[]>> | Record<string, RegExp[]>;
|
1583
1642
|
/**
|
1584
1643
|
* Transforms the parameters before they are passed to the language model.
|
@@ -1589,9 +1648,9 @@ type LanguageModelV2Middleware = {
|
|
1589
1648
|
*/
|
1590
1649
|
transformParams?: (options: {
|
1591
1650
|
type: 'generate' | 'stream';
|
1592
|
-
params:
|
1593
|
-
model:
|
1594
|
-
}) => PromiseLike<
|
1651
|
+
params: LanguageModelV3CallOptions;
|
1652
|
+
model: LanguageModelV3;
|
1653
|
+
}) => PromiseLike<LanguageModelV3CallOptions>;
|
1595
1654
|
/**
|
1596
1655
|
* Wraps the generate operation of the language model.
|
1597
1656
|
* @param options - Object containing the generate function, parameters, and model.
|
@@ -1603,11 +1662,11 @@ type LanguageModelV2Middleware = {
|
|
1603
1662
|
* @returns A promise that resolves to the result of the generate operation.
|
1604
1663
|
*/
|
1605
1664
|
wrapGenerate?: (options: {
|
1606
|
-
doGenerate: () => ReturnType<
|
1607
|
-
doStream: () => ReturnType<
|
1608
|
-
params:
|
1609
|
-
model:
|
1610
|
-
}) => Promise<Awaited<ReturnType<
|
1665
|
+
doGenerate: () => ReturnType<LanguageModelV3['doGenerate']>;
|
1666
|
+
doStream: () => ReturnType<LanguageModelV3['doStream']>;
|
1667
|
+
params: LanguageModelV3CallOptions;
|
1668
|
+
model: LanguageModelV3;
|
1669
|
+
}) => Promise<Awaited<ReturnType<LanguageModelV3['doGenerate']>>>;
|
1611
1670
|
/**
|
1612
1671
|
* Wraps the stream operation of the language model.
|
1613
1672
|
*
|
@@ -1620,87 +1679,925 @@ type LanguageModelV2Middleware = {
|
|
1620
1679
|
* @returns A promise that resolves to the result of the stream operation.
|
1621
1680
|
*/
|
1622
1681
|
wrapStream?: (options: {
|
1623
|
-
doGenerate: () => ReturnType<
|
1624
|
-
doStream: () => ReturnType<
|
1625
|
-
params:
|
1626
|
-
model:
|
1627
|
-
}) => PromiseLike<Awaited<ReturnType<
|
1682
|
+
doGenerate: () => ReturnType<LanguageModelV3['doGenerate']>;
|
1683
|
+
doStream: () => ReturnType<LanguageModelV3['doStream']>;
|
1684
|
+
params: LanguageModelV3CallOptions;
|
1685
|
+
model: LanguageModelV3;
|
1686
|
+
}) => PromiseLike<Awaited<ReturnType<LanguageModelV3['doStream']>>>;
|
1628
1687
|
};
|
1629
1688
|
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
* The voice to use for speech synthesis.
|
1638
|
-
* This is provider-specific and may be a voice ID, name, or other identifier.
|
1639
|
-
*/
|
1640
|
-
voice?: string;
|
1641
|
-
/**
|
1642
|
-
* The desired output format for the audio e.g. "mp3", "wav", etc.
|
1643
|
-
*/
|
1644
|
-
outputFormat?: string;
|
1645
|
-
/**
|
1646
|
-
* Instructions for the speech generation e.g. "Speak in a slow and steady tone".
|
1647
|
-
*/
|
1648
|
-
instructions?: string;
|
1689
|
+
/**
|
1690
|
+
A tool has a name, a description, and a set of parameters.
|
1691
|
+
|
1692
|
+
Note: this is **not** the user-facing tool definition. The AI SDK methods will
|
1693
|
+
map the user-facing tool definitions to this format.
|
1694
|
+
*/
|
1695
|
+
type LanguageModelV2FunctionTool = {
|
1649
1696
|
/**
|
1650
|
-
|
1697
|
+
The type of the tool (always 'function').
|
1651
1698
|
*/
|
1652
|
-
|
1699
|
+
type: 'function';
|
1653
1700
|
/**
|
1654
|
-
|
1655
|
-
* or "auto" for automatic language detection. Provider support varies.
|
1701
|
+
The name of the tool. Unique within this model call.
|
1656
1702
|
*/
|
1657
|
-
|
1703
|
+
name: string;
|
1658
1704
|
/**
|
1659
|
-
|
1660
|
-
|
1661
|
-
*
|
1662
|
-
* The outer record is keyed by the provider name, and the inner
|
1663
|
-
* record is keyed by the provider-specific metadata key.
|
1664
|
-
* ```ts
|
1665
|
-
* {
|
1666
|
-
* "openai": {}
|
1667
|
-
* }
|
1668
|
-
* ```
|
1705
|
+
A description of the tool. The language model uses this to understand the
|
1706
|
+
tool's purpose and to provide better completion suggestions.
|
1669
1707
|
*/
|
1670
|
-
|
1708
|
+
description?: string;
|
1671
1709
|
/**
|
1672
|
-
|
1710
|
+
The parameters that the tool expects. The language model uses this to
|
1711
|
+
understand the tool's input requirements and to provide matching suggestions.
|
1673
1712
|
*/
|
1674
|
-
|
1713
|
+
inputSchema: JSONSchema7;
|
1675
1714
|
/**
|
1676
|
-
|
1677
|
-
* Only applicable for HTTP-based providers.
|
1715
|
+
The provider-specific options for the tool.
|
1678
1716
|
*/
|
1679
|
-
|
1717
|
+
providerOptions?: SharedV2ProviderOptions;
|
1680
1718
|
};
|
1681
1719
|
|
1682
1720
|
/**
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
type SpeechModelV2CallWarning = {
|
1687
|
-
type: 'unsupported-setting';
|
1688
|
-
setting: keyof SpeechModelV2CallOptions;
|
1689
|
-
details?: string;
|
1690
|
-
} | {
|
1691
|
-
type: 'other';
|
1692
|
-
message: string;
|
1693
|
-
};
|
1721
|
+
Data content. Can be a Uint8Array, base64 encoded data as a string or a URL.
|
1722
|
+
*/
|
1723
|
+
type LanguageModelV2DataContent = Uint8Array | string | URL;
|
1694
1724
|
|
1695
1725
|
/**
|
1696
|
-
|
1726
|
+
A prompt is a list of messages.
|
1727
|
+
|
1728
|
+
Note: Not all models and prompt formats support multi-modal inputs and
|
1729
|
+
tool calls. The validation happens at runtime.
|
1730
|
+
|
1731
|
+
Note: This is not a user-facing prompt. The AI SDK methods will map the
|
1732
|
+
user-facing prompt types such as chat or instruction prompts to this format.
|
1697
1733
|
*/
|
1698
|
-
type
|
1734
|
+
type LanguageModelV2Prompt = Array<LanguageModelV2Message>;
|
1735
|
+
type LanguageModelV2Message = ({
|
1736
|
+
role: 'system';
|
1737
|
+
content: string;
|
1738
|
+
} | {
|
1739
|
+
role: 'user';
|
1740
|
+
content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart>;
|
1741
|
+
} | {
|
1742
|
+
role: 'assistant';
|
1743
|
+
content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart | LanguageModelV2ReasoningPart | LanguageModelV2ToolCallPart | LanguageModelV2ToolResultPart>;
|
1744
|
+
} | {
|
1745
|
+
role: 'tool';
|
1746
|
+
content: Array<LanguageModelV2ToolResultPart>;
|
1747
|
+
}) & {
|
1699
1748
|
/**
|
1700
|
-
*
|
1701
|
-
*
|
1702
|
-
*
|
1703
|
-
|
1749
|
+
* Additional provider-specific options. They are passed through
|
1750
|
+
* to the provider from the AI SDK and enable provider-specific
|
1751
|
+
* functionality that can be fully encapsulated in the provider.
|
1752
|
+
*/
|
1753
|
+
providerOptions?: SharedV2ProviderOptions;
|
1754
|
+
};
|
1755
|
+
/**
|
1756
|
+
Text content part of a prompt. It contains a string of text.
|
1757
|
+
*/
|
1758
|
+
interface LanguageModelV2TextPart {
|
1759
|
+
type: 'text';
|
1760
|
+
/**
|
1761
|
+
The text content.
|
1762
|
+
*/
|
1763
|
+
text: string;
|
1764
|
+
/**
|
1765
|
+
* Additional provider-specific options. They are passed through
|
1766
|
+
* to the provider from the AI SDK and enable provider-specific
|
1767
|
+
* functionality that can be fully encapsulated in the provider.
|
1768
|
+
*/
|
1769
|
+
providerOptions?: SharedV2ProviderOptions;
|
1770
|
+
}
|
1771
|
+
/**
|
1772
|
+
Reasoning content part of a prompt. It contains a string of reasoning text.
|
1773
|
+
*/
|
1774
|
+
interface LanguageModelV2ReasoningPart {
|
1775
|
+
type: 'reasoning';
|
1776
|
+
/**
|
1777
|
+
The reasoning text.
|
1778
|
+
*/
|
1779
|
+
text: string;
|
1780
|
+
/**
|
1781
|
+
* Additional provider-specific options. They are passed through
|
1782
|
+
* to the provider from the AI SDK and enable provider-specific
|
1783
|
+
* functionality that can be fully encapsulated in the provider.
|
1784
|
+
*/
|
1785
|
+
providerOptions?: SharedV2ProviderOptions;
|
1786
|
+
}
|
1787
|
+
/**
|
1788
|
+
File content part of a prompt. It contains a file.
|
1789
|
+
*/
|
1790
|
+
interface LanguageModelV2FilePart {
|
1791
|
+
type: 'file';
|
1792
|
+
/**
|
1793
|
+
* Optional filename of the file.
|
1794
|
+
*/
|
1795
|
+
filename?: string;
|
1796
|
+
/**
|
1797
|
+
File data. Can be a Uint8Array, base64 encoded data as a string or a URL.
|
1798
|
+
*/
|
1799
|
+
data: LanguageModelV2DataContent;
|
1800
|
+
/**
|
1801
|
+
IANA media type of the file.
|
1802
|
+
|
1803
|
+
Can support wildcards, e.g. `image/*` (in which case the provider needs to take appropriate action).
|
1804
|
+
|
1805
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
1806
|
+
*/
|
1807
|
+
mediaType: string;
|
1808
|
+
/**
|
1809
|
+
* Additional provider-specific options. They are passed through
|
1810
|
+
* to the provider from the AI SDK and enable provider-specific
|
1811
|
+
* functionality that can be fully encapsulated in the provider.
|
1812
|
+
*/
|
1813
|
+
providerOptions?: SharedV2ProviderOptions;
|
1814
|
+
}
|
1815
|
+
/**
|
1816
|
+
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
1817
|
+
*/
|
1818
|
+
interface LanguageModelV2ToolCallPart {
|
1819
|
+
type: 'tool-call';
|
1820
|
+
/**
|
1821
|
+
ID of the tool call. This ID is used to match the tool call with the tool result.
|
1822
|
+
*/
|
1823
|
+
toolCallId: string;
|
1824
|
+
/**
|
1825
|
+
Name of the tool that is being called.
|
1826
|
+
*/
|
1827
|
+
toolName: string;
|
1828
|
+
/**
|
1829
|
+
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
1830
|
+
*/
|
1831
|
+
input: unknown;
|
1832
|
+
/**
|
1833
|
+
* Whether the tool call will be executed by the provider.
|
1834
|
+
* If this flag is not set or is false, the tool call will be executed by the client.
|
1835
|
+
*/
|
1836
|
+
providerExecuted?: boolean;
|
1837
|
+
/**
|
1838
|
+
* Additional provider-specific options. They are passed through
|
1839
|
+
* to the provider from the AI SDK and enable provider-specific
|
1840
|
+
* functionality that can be fully encapsulated in the provider.
|
1841
|
+
*/
|
1842
|
+
providerOptions?: SharedV2ProviderOptions;
|
1843
|
+
}
|
1844
|
+
/**
|
1845
|
+
Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
1846
|
+
*/
|
1847
|
+
interface LanguageModelV2ToolResultPart {
|
1848
|
+
type: 'tool-result';
|
1849
|
+
/**
|
1850
|
+
ID of the tool call that this result is associated with.
|
1851
|
+
*/
|
1852
|
+
toolCallId: string;
|
1853
|
+
/**
|
1854
|
+
Name of the tool that generated this result.
|
1855
|
+
*/
|
1856
|
+
toolName: string;
|
1857
|
+
/**
|
1858
|
+
Result of the tool call.
|
1859
|
+
*/
|
1860
|
+
output: LanguageModelV2ToolResultOutput;
|
1861
|
+
/**
|
1862
|
+
* Additional provider-specific options. They are passed through
|
1863
|
+
* to the provider from the AI SDK and enable provider-specific
|
1864
|
+
* functionality that can be fully encapsulated in the provider.
|
1865
|
+
*/
|
1866
|
+
providerOptions?: SharedV2ProviderOptions;
|
1867
|
+
}
|
1868
|
+
type LanguageModelV2ToolResultOutput = {
|
1869
|
+
type: 'text';
|
1870
|
+
value: string;
|
1871
|
+
} | {
|
1872
|
+
type: 'json';
|
1873
|
+
value: JSONValue;
|
1874
|
+
} | {
|
1875
|
+
type: 'error-text';
|
1876
|
+
value: string;
|
1877
|
+
} | {
|
1878
|
+
type: 'error-json';
|
1879
|
+
value: JSONValue;
|
1880
|
+
} | {
|
1881
|
+
type: 'content';
|
1882
|
+
value: Array<{
|
1883
|
+
type: 'text';
|
1884
|
+
/**
|
1885
|
+
Text content.
|
1886
|
+
*/
|
1887
|
+
text: string;
|
1888
|
+
} | {
|
1889
|
+
type: 'media';
|
1890
|
+
/**
|
1891
|
+
Base-64 encoded media data.
|
1892
|
+
*/
|
1893
|
+
data: string;
|
1894
|
+
/**
|
1895
|
+
IANA media type.
|
1896
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
1897
|
+
*/
|
1898
|
+
mediaType: string;
|
1899
|
+
}>;
|
1900
|
+
};
|
1901
|
+
|
1902
|
+
/**
|
1903
|
+
The configuration of a tool that is defined by the provider.
|
1904
|
+
*/
|
1905
|
+
type LanguageModelV2ProviderDefinedTool = {
|
1906
|
+
/**
|
1907
|
+
The type of the tool (always 'provider-defined').
|
1908
|
+
*/
|
1909
|
+
type: 'provider-defined';
|
1910
|
+
/**
|
1911
|
+
The ID of the tool. Should follow the format `<provider-name>.<unique-tool-name>`.
|
1912
|
+
*/
|
1913
|
+
id: `${string}.${string}`;
|
1914
|
+
/**
|
1915
|
+
The name of the tool that the user must use in the tool set.
|
1916
|
+
*/
|
1917
|
+
name: string;
|
1918
|
+
/**
|
1919
|
+
The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
|
1920
|
+
*/
|
1921
|
+
args: Record<string, unknown>;
|
1922
|
+
};
|
1923
|
+
|
1924
|
+
type LanguageModelV2ToolChoice = {
|
1925
|
+
type: 'auto';
|
1926
|
+
} | {
|
1927
|
+
type: 'none';
|
1928
|
+
} | {
|
1929
|
+
type: 'required';
|
1930
|
+
} | {
|
1931
|
+
type: 'tool';
|
1932
|
+
toolName: string;
|
1933
|
+
};
|
1934
|
+
|
1935
|
+
type LanguageModelV2CallOptions = {
|
1936
|
+
/**
|
1937
|
+
A language mode prompt is a standardized prompt type.
|
1938
|
+
|
1939
|
+
Note: This is **not** the user-facing prompt. The AI SDK methods will map the
|
1940
|
+
user-facing prompt types such as chat or instruction prompts to this format.
|
1941
|
+
That approach allows us to evolve the user facing prompts without breaking
|
1942
|
+
the language model interface.
|
1943
|
+
*/
|
1944
|
+
prompt: LanguageModelV2Prompt;
|
1945
|
+
/**
|
1946
|
+
Maximum number of tokens to generate.
|
1947
|
+
*/
|
1948
|
+
maxOutputTokens?: number;
|
1949
|
+
/**
|
1950
|
+
Temperature setting. The range depends on the provider and model.
|
1951
|
+
*/
|
1952
|
+
temperature?: number;
|
1953
|
+
/**
|
1954
|
+
Stop sequences.
|
1955
|
+
If set, the model will stop generating text when one of the stop sequences is generated.
|
1956
|
+
Providers may have limits on the number of stop sequences.
|
1957
|
+
*/
|
1958
|
+
stopSequences?: string[];
|
1959
|
+
/**
|
1960
|
+
Nucleus sampling.
|
1961
|
+
*/
|
1962
|
+
topP?: number;
|
1963
|
+
/**
|
1964
|
+
Only sample from the top K options for each subsequent token.
|
1965
|
+
|
1966
|
+
Used to remove "long tail" low probability responses.
|
1967
|
+
Recommended for advanced use cases only. You usually only need to use temperature.
|
1968
|
+
*/
|
1969
|
+
topK?: number;
|
1970
|
+
/**
|
1971
|
+
Presence penalty setting. It affects the likelihood of the model to
|
1972
|
+
repeat information that is already in the prompt.
|
1973
|
+
*/
|
1974
|
+
presencePenalty?: number;
|
1975
|
+
/**
|
1976
|
+
Frequency penalty setting. It affects the likelihood of the model
|
1977
|
+
to repeatedly use the same words or phrases.
|
1978
|
+
*/
|
1979
|
+
frequencyPenalty?: number;
|
1980
|
+
/**
|
1981
|
+
Response format. The output can either be text or JSON. Default is text.
|
1982
|
+
|
1983
|
+
If JSON is selected, a schema can optionally be provided to guide the LLM.
|
1984
|
+
*/
|
1985
|
+
responseFormat?: {
|
1986
|
+
type: 'text';
|
1987
|
+
} | {
|
1988
|
+
type: 'json';
|
1989
|
+
/**
|
1990
|
+
* JSON schema that the generated output should conform to.
|
1991
|
+
*/
|
1992
|
+
schema?: JSONSchema7;
|
1993
|
+
/**
|
1994
|
+
* Name of output that should be generated. Used by some providers for additional LLM guidance.
|
1995
|
+
*/
|
1996
|
+
name?: string;
|
1997
|
+
/**
|
1998
|
+
* Description of the output that should be generated. Used by some providers for additional LLM guidance.
|
1999
|
+
*/
|
2000
|
+
description?: string;
|
2001
|
+
};
|
2002
|
+
/**
|
2003
|
+
The seed (integer) to use for random sampling. If set and supported
|
2004
|
+
by the model, calls will generate deterministic results.
|
2005
|
+
*/
|
2006
|
+
seed?: number;
|
2007
|
+
/**
|
2008
|
+
The tools that are available for the model.
|
2009
|
+
*/
|
2010
|
+
tools?: Array<LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool>;
|
2011
|
+
/**
|
2012
|
+
Specifies how the tool should be selected. Defaults to 'auto'.
|
2013
|
+
*/
|
2014
|
+
toolChoice?: LanguageModelV2ToolChoice;
|
2015
|
+
/**
|
2016
|
+
Include raw chunks in the stream. Only applicable for streaming calls.
|
2017
|
+
*/
|
2018
|
+
includeRawChunks?: boolean;
|
2019
|
+
/**
|
2020
|
+
Abort signal for cancelling the operation.
|
2021
|
+
*/
|
2022
|
+
abortSignal?: AbortSignal;
|
2023
|
+
/**
|
2024
|
+
Additional HTTP headers to be sent with the request.
|
2025
|
+
Only applicable for HTTP-based providers.
|
2026
|
+
*/
|
2027
|
+
headers?: Record<string, string | undefined>;
|
2028
|
+
/**
|
2029
|
+
* Additional provider-specific options. They are passed through
|
2030
|
+
* to the provider from the AI SDK and enable provider-specific
|
2031
|
+
* functionality that can be fully encapsulated in the provider.
|
2032
|
+
*/
|
2033
|
+
providerOptions?: SharedV2ProviderOptions;
|
2034
|
+
};
|
2035
|
+
|
2036
|
+
/**
|
2037
|
+
Warning from the model provider for this call. The call will proceed, but e.g.
|
2038
|
+
some settings might not be supported, which can lead to suboptimal results.
|
2039
|
+
*/
|
2040
|
+
type LanguageModelV2CallWarning = {
|
2041
|
+
type: 'unsupported-setting';
|
2042
|
+
setting: Omit<keyof LanguageModelV2CallOptions, 'prompt'>;
|
2043
|
+
details?: string;
|
2044
|
+
} | {
|
2045
|
+
type: 'unsupported-tool';
|
2046
|
+
tool: LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool;
|
2047
|
+
details?: string;
|
2048
|
+
} | {
|
2049
|
+
type: 'other';
|
2050
|
+
message: string;
|
2051
|
+
};
|
2052
|
+
|
2053
|
+
/**
|
2054
|
+
A file that has been generated by the model.
|
2055
|
+
Generated files as base64 encoded strings or binary data.
|
2056
|
+
The files should be returned without any unnecessary conversion.
|
2057
|
+
*/
|
2058
|
+
type LanguageModelV2File = {
|
2059
|
+
type: 'file';
|
2060
|
+
/**
|
2061
|
+
The IANA media type of the file, e.g. `image/png` or `audio/mp3`.
|
2062
|
+
|
2063
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
2064
|
+
*/
|
2065
|
+
mediaType: string;
|
2066
|
+
/**
|
2067
|
+
Generated file data as base64 encoded strings or binary data.
|
2068
|
+
|
2069
|
+
The file data should be returned without any unnecessary conversion.
|
2070
|
+
If the API returns base64 encoded strings, the file data should be returned
|
2071
|
+
as base64 encoded strings. If the API returns binary data, the file data should
|
2072
|
+
be returned as binary data.
|
2073
|
+
*/
|
2074
|
+
data: string | Uint8Array;
|
2075
|
+
};
|
2076
|
+
|
2077
|
+
/**
|
2078
|
+
Reasoning that the model has generated.
|
2079
|
+
*/
|
2080
|
+
type LanguageModelV2Reasoning = {
|
2081
|
+
type: 'reasoning';
|
2082
|
+
text: string;
|
2083
|
+
/**
|
2084
|
+
* Optional provider-specific metadata for the reasoning part.
|
2085
|
+
*/
|
2086
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
2087
|
+
};
|
2088
|
+
|
2089
|
+
/**
|
2090
|
+
A source that has been used as input to generate the response.
|
2091
|
+
*/
|
2092
|
+
type LanguageModelV2Source = {
|
2093
|
+
type: 'source';
|
2094
|
+
/**
|
2095
|
+
* The type of source - URL sources reference web content.
|
2096
|
+
*/
|
2097
|
+
sourceType: 'url';
|
2098
|
+
/**
|
2099
|
+
* The ID of the source.
|
2100
|
+
*/
|
2101
|
+
id: string;
|
2102
|
+
/**
|
2103
|
+
* The URL of the source.
|
2104
|
+
*/
|
2105
|
+
url: string;
|
2106
|
+
/**
|
2107
|
+
* The title of the source.
|
2108
|
+
*/
|
2109
|
+
title?: string;
|
2110
|
+
/**
|
2111
|
+
* Additional provider metadata for the source.
|
2112
|
+
*/
|
2113
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
2114
|
+
} | {
|
2115
|
+
type: 'source';
|
2116
|
+
/**
|
2117
|
+
* The type of source - document sources reference files/documents.
|
2118
|
+
*/
|
2119
|
+
sourceType: 'document';
|
2120
|
+
/**
|
2121
|
+
* The ID of the source.
|
2122
|
+
*/
|
2123
|
+
id: string;
|
2124
|
+
/**
|
2125
|
+
* IANA media type of the document (e.g., 'application/pdf').
|
2126
|
+
*/
|
2127
|
+
mediaType: string;
|
2128
|
+
/**
|
2129
|
+
* The title of the document.
|
2130
|
+
*/
|
2131
|
+
title: string;
|
2132
|
+
/**
|
2133
|
+
* Optional filename of the document.
|
2134
|
+
*/
|
2135
|
+
filename?: string;
|
2136
|
+
/**
|
2137
|
+
* Additional provider metadata for the source.
|
2138
|
+
*/
|
2139
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
2140
|
+
};
|
2141
|
+
|
2142
|
+
/**
|
2143
|
+
Text that the model has generated.
|
2144
|
+
*/
|
2145
|
+
type LanguageModelV2Text = {
|
2146
|
+
type: 'text';
|
2147
|
+
/**
|
2148
|
+
The text content.
|
2149
|
+
*/
|
2150
|
+
text: string;
|
2151
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
2152
|
+
};
|
2153
|
+
|
2154
|
+
/**
|
2155
|
+
* Tool calls that the model has generated.
|
2156
|
+
*/
|
2157
|
+
type LanguageModelV2ToolCall = {
|
2158
|
+
type: 'tool-call';
|
2159
|
+
/**
|
2160
|
+
* The identifier of the tool call. It must be unique across all tool calls.
|
2161
|
+
*/
|
2162
|
+
toolCallId: string;
|
2163
|
+
/**
|
2164
|
+
* The name of the tool that should be called.
|
2165
|
+
*/
|
2166
|
+
toolName: string;
|
2167
|
+
/**
|
2168
|
+
* Stringified JSON object with the tool call arguments. Must match the
|
2169
|
+
* parameters schema of the tool.
|
2170
|
+
*/
|
2171
|
+
input: string;
|
2172
|
+
/**
|
2173
|
+
* Whether the tool call will be executed by the provider.
|
2174
|
+
* If this flag is not set or is false, the tool call will be executed by the client.
|
2175
|
+
*/
|
2176
|
+
providerExecuted?: boolean;
|
2177
|
+
/**
|
2178
|
+
* Additional provider-specific metadata for the tool call.
|
2179
|
+
*/
|
2180
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
2181
|
+
};
|
2182
|
+
|
2183
|
+
/**
|
2184
|
+
Result of a tool call that has been executed by the provider.
|
2185
|
+
*/
|
2186
|
+
type LanguageModelV2ToolResult = {
|
2187
|
+
type: 'tool-result';
|
2188
|
+
/**
|
2189
|
+
* The ID of the tool call that this result is associated with.
|
2190
|
+
*/
|
2191
|
+
toolCallId: string;
|
2192
|
+
/**
|
2193
|
+
* Name of the tool that generated this result.
|
2194
|
+
*/
|
2195
|
+
toolName: string;
|
2196
|
+
/**
|
2197
|
+
* Result of the tool call. This is a JSON-serializable object.
|
2198
|
+
*/
|
2199
|
+
result: unknown;
|
2200
|
+
/**
|
2201
|
+
* Optional flag if the result is an error or an error message.
|
2202
|
+
*/
|
2203
|
+
isError?: boolean;
|
2204
|
+
/**
|
2205
|
+
* Whether the tool result was generated by the provider.
|
2206
|
+
* If this flag is set to true, the tool result was generated by the provider.
|
2207
|
+
* If this flag is not set or is false, the tool result was generated by the client.
|
2208
|
+
*/
|
2209
|
+
providerExecuted?: boolean;
|
2210
|
+
/**
|
2211
|
+
* Additional provider-specific metadata for the tool result.
|
2212
|
+
*/
|
2213
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
2214
|
+
};
|
2215
|
+
|
2216
|
+
type LanguageModelV2Content = LanguageModelV2Text | LanguageModelV2Reasoning | LanguageModelV2File | LanguageModelV2Source | LanguageModelV2ToolCall | LanguageModelV2ToolResult;
|
2217
|
+
|
2218
|
+
/**
|
2219
|
+
Reason why a language model finished generating a response.
|
2220
|
+
|
2221
|
+
Can be one of the following:
|
2222
|
+
- `stop`: model generated stop sequence
|
2223
|
+
- `length`: model generated maximum number of tokens
|
2224
|
+
- `content-filter`: content filter violation stopped the model
|
2225
|
+
- `tool-calls`: model triggered tool calls
|
2226
|
+
- `error`: model stopped because of an error
|
2227
|
+
- `other`: model stopped for other reasons
|
2228
|
+
- `unknown`: the model has not transmitted a finish reason
|
2229
|
+
*/
|
2230
|
+
type LanguageModelV2FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown';
|
2231
|
+
|
2232
|
+
interface LanguageModelV2ResponseMetadata {
|
2233
|
+
/**
|
2234
|
+
ID for the generated response, if the provider sends one.
|
2235
|
+
*/
|
2236
|
+
id?: string;
|
2237
|
+
/**
|
2238
|
+
Timestamp for the start of the generated response, if the provider sends one.
|
2239
|
+
*/
|
2240
|
+
timestamp?: Date;
|
2241
|
+
/**
|
2242
|
+
The ID of the response model that was used to generate the response, if the provider sends one.
|
2243
|
+
*/
|
2244
|
+
modelId?: string;
|
2245
|
+
}
|
2246
|
+
|
2247
|
+
/**
|
2248
|
+
Usage information for a language model call.
|
2249
|
+
|
2250
|
+
If your API return additional usage information, you can add it to the
|
2251
|
+
provider metadata under your provider's key.
|
2252
|
+
*/
|
2253
|
+
type LanguageModelV2Usage = {
|
2254
|
+
/**
|
2255
|
+
The number of input (prompt) tokens used.
|
2256
|
+
*/
|
2257
|
+
inputTokens: number | undefined;
|
2258
|
+
/**
|
2259
|
+
The number of output (completion) tokens used.
|
2260
|
+
*/
|
2261
|
+
outputTokens: number | undefined;
|
2262
|
+
/**
|
2263
|
+
The total number of tokens as reported by the provider.
|
2264
|
+
This number might be different from the sum of `inputTokens` and `outputTokens`
|
2265
|
+
and e.g. include reasoning tokens or other overhead.
|
2266
|
+
*/
|
2267
|
+
totalTokens: number | undefined;
|
2268
|
+
/**
|
2269
|
+
The number of reasoning tokens used.
|
2270
|
+
*/
|
2271
|
+
reasoningTokens?: number | undefined;
|
2272
|
+
/**
|
2273
|
+
The number of cached input tokens.
|
2274
|
+
*/
|
2275
|
+
cachedInputTokens?: number | undefined;
|
2276
|
+
};
|
2277
|
+
|
2278
|
+
type LanguageModelV2StreamPart = {
|
2279
|
+
type: 'text-start';
|
2280
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
2281
|
+
id: string;
|
2282
|
+
} | {
|
2283
|
+
type: 'text-delta';
|
2284
|
+
id: string;
|
2285
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
2286
|
+
delta: string;
|
2287
|
+
} | {
|
2288
|
+
type: 'text-end';
|
2289
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
2290
|
+
id: string;
|
2291
|
+
} | {
|
2292
|
+
type: 'reasoning-start';
|
2293
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
2294
|
+
id: string;
|
2295
|
+
} | {
|
2296
|
+
type: 'reasoning-delta';
|
2297
|
+
id: string;
|
2298
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
2299
|
+
delta: string;
|
2300
|
+
} | {
|
2301
|
+
type: 'reasoning-end';
|
2302
|
+
id: string;
|
2303
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
2304
|
+
} | {
|
2305
|
+
type: 'tool-input-start';
|
2306
|
+
id: string;
|
2307
|
+
toolName: string;
|
2308
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
2309
|
+
providerExecuted?: boolean;
|
2310
|
+
} | {
|
2311
|
+
type: 'tool-input-delta';
|
2312
|
+
id: string;
|
2313
|
+
delta: string;
|
2314
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
2315
|
+
} | {
|
2316
|
+
type: 'tool-input-end';
|
2317
|
+
id: string;
|
2318
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
2319
|
+
} | LanguageModelV2ToolCall | LanguageModelV2ToolResult | LanguageModelV2File | LanguageModelV2Source | {
|
2320
|
+
type: 'stream-start';
|
2321
|
+
warnings: Array<LanguageModelV2CallWarning>;
|
2322
|
+
} | ({
|
2323
|
+
type: 'response-metadata';
|
2324
|
+
} & LanguageModelV2ResponseMetadata) | {
|
2325
|
+
type: 'finish';
|
2326
|
+
usage: LanguageModelV2Usage;
|
2327
|
+
finishReason: LanguageModelV2FinishReason;
|
2328
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
2329
|
+
} | {
|
2330
|
+
type: 'raw';
|
2331
|
+
rawValue: unknown;
|
2332
|
+
} | {
|
2333
|
+
type: 'error';
|
2334
|
+
error: unknown;
|
2335
|
+
};
|
2336
|
+
|
2337
|
+
/**
|
2338
|
+
Specification for a language model that implements the language model interface version 2.
|
2339
|
+
*/
|
2340
|
+
type LanguageModelV2 = {
|
2341
|
+
/**
|
2342
|
+
The language model must specify which language model interface version it implements.
|
2343
|
+
*/
|
2344
|
+
readonly specificationVersion: 'v2';
|
2345
|
+
/**
|
2346
|
+
Name of the provider for logging purposes.
|
2347
|
+
*/
|
2348
|
+
readonly provider: string;
|
2349
|
+
/**
|
2350
|
+
Provider-specific model ID for logging purposes.
|
2351
|
+
*/
|
2352
|
+
readonly modelId: string;
|
2353
|
+
/**
|
2354
|
+
Supported URL patterns by media type for the provider.
|
2355
|
+
|
2356
|
+
The keys are media type patterns or full media types (e.g. `*\/*` for everything, `audio/*`, `video/*`, or `application/pdf`).
|
2357
|
+
and the values are arrays of regular expressions that match the URL paths.
|
2358
|
+
|
2359
|
+
The matching should be against lower-case URLs.
|
2360
|
+
|
2361
|
+
Matched URLs are supported natively by the model and are not downloaded.
|
2362
|
+
|
2363
|
+
@returns A map of supported URL patterns by media type (as a promise or a plain object).
|
2364
|
+
*/
|
2365
|
+
supportedUrls: PromiseLike<Record<string, RegExp[]>> | Record<string, RegExp[]>;
|
2366
|
+
/**
|
2367
|
+
Generates a language model output (non-streaming).
|
2368
|
+
|
2369
|
+
Naming: "do" prefix to prevent accidental direct usage of the method
|
2370
|
+
by the user.
|
2371
|
+
*/
|
2372
|
+
doGenerate(options: LanguageModelV2CallOptions): PromiseLike<{
|
2373
|
+
/**
|
2374
|
+
Ordered content that the model has generated.
|
2375
|
+
*/
|
2376
|
+
content: Array<LanguageModelV2Content>;
|
2377
|
+
/**
|
2378
|
+
Finish reason.
|
2379
|
+
*/
|
2380
|
+
finishReason: LanguageModelV2FinishReason;
|
2381
|
+
/**
|
2382
|
+
Usage information.
|
2383
|
+
*/
|
2384
|
+
usage: LanguageModelV2Usage;
|
2385
|
+
/**
|
2386
|
+
Additional provider-specific metadata. They are passed through
|
2387
|
+
from the provider to the AI SDK and enable provider-specific
|
2388
|
+
results that can be fully encapsulated in the provider.
|
2389
|
+
*/
|
2390
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
2391
|
+
/**
|
2392
|
+
Optional request information for telemetry and debugging purposes.
|
2393
|
+
*/
|
2394
|
+
request?: {
|
2395
|
+
/**
|
2396
|
+
Request HTTP body that was sent to the provider API.
|
2397
|
+
*/
|
2398
|
+
body?: unknown;
|
2399
|
+
};
|
2400
|
+
/**
|
2401
|
+
Optional response information for telemetry and debugging purposes.
|
2402
|
+
*/
|
2403
|
+
response?: LanguageModelV2ResponseMetadata & {
|
2404
|
+
/**
|
2405
|
+
Response headers.
|
2406
|
+
*/
|
2407
|
+
headers?: SharedV2Headers;
|
2408
|
+
/**
|
2409
|
+
Response HTTP body.
|
2410
|
+
*/
|
2411
|
+
body?: unknown;
|
2412
|
+
};
|
2413
|
+
/**
|
2414
|
+
Warnings for the call, e.g. unsupported settings.
|
2415
|
+
*/
|
2416
|
+
warnings: Array<LanguageModelV2CallWarning>;
|
2417
|
+
}>;
|
2418
|
+
/**
|
2419
|
+
Generates a language model output (streaming).
|
2420
|
+
|
2421
|
+
Naming: "do" prefix to prevent accidental direct usage of the method
|
2422
|
+
by the user.
|
2423
|
+
*
|
2424
|
+
@return A stream of higher-level language model output parts.
|
2425
|
+
*/
|
2426
|
+
doStream(options: LanguageModelV2CallOptions): PromiseLike<{
|
2427
|
+
stream: ReadableStream<LanguageModelV2StreamPart>;
|
2428
|
+
/**
|
2429
|
+
Optional request information for telemetry and debugging purposes.
|
2430
|
+
*/
|
2431
|
+
request?: {
|
2432
|
+
/**
|
2433
|
+
Request HTTP body that was sent to the provider API.
|
2434
|
+
*/
|
2435
|
+
body?: unknown;
|
2436
|
+
};
|
2437
|
+
/**
|
2438
|
+
Optional response data.
|
2439
|
+
*/
|
2440
|
+
response?: {
|
2441
|
+
/**
|
2442
|
+
Response headers.
|
2443
|
+
*/
|
2444
|
+
headers?: SharedV2Headers;
|
2445
|
+
};
|
2446
|
+
}>;
|
2447
|
+
};
|
2448
|
+
|
2449
|
+
/**
|
2450
|
+
* Experimental middleware for LanguageModelV2.
|
2451
|
+
* This type defines the structure for middleware that can be used to modify
|
2452
|
+
* the behavior of LanguageModelV2 operations.
|
2453
|
+
*/
|
2454
|
+
type LanguageModelV2Middleware = {
|
2455
|
+
/**
|
2456
|
+
* Middleware specification version. Use `v2` for the current version.
|
2457
|
+
*/
|
2458
|
+
middlewareVersion?: 'v2' | undefined;
|
2459
|
+
/**
|
2460
|
+
* Override the provider name if desired.
|
2461
|
+
* @param options.model - The language model instance.
|
2462
|
+
*/
|
2463
|
+
overrideProvider?: (options: {
|
2464
|
+
model: LanguageModelV2;
|
2465
|
+
}) => string;
|
2466
|
+
/**
|
2467
|
+
* Override the model ID if desired.
|
2468
|
+
* @param options.model - The language model instance.
|
2469
|
+
*/
|
2470
|
+
overrideModelId?: (options: {
|
2471
|
+
model: LanguageModelV2;
|
2472
|
+
}) => string;
|
2473
|
+
/**
|
2474
|
+
* Override the supported URLs if desired.
|
2475
|
+
* @param options.model - The language model instance.
|
2476
|
+
*/
|
2477
|
+
overrideSupportedUrls?: (options: {
|
2478
|
+
model: LanguageModelV2;
|
2479
|
+
}) => PromiseLike<Record<string, RegExp[]>> | Record<string, RegExp[]>;
|
2480
|
+
/**
|
2481
|
+
* Transforms the parameters before they are passed to the language model.
|
2482
|
+
* @param options - Object containing the type of operation and the parameters.
|
2483
|
+
* @param options.type - The type of operation ('generate' or 'stream').
|
2484
|
+
* @param options.params - The original parameters for the language model call.
|
2485
|
+
* @returns A promise that resolves to the transformed parameters.
|
2486
|
+
*/
|
2487
|
+
transformParams?: (options: {
|
2488
|
+
type: 'generate' | 'stream';
|
2489
|
+
params: LanguageModelV2CallOptions;
|
2490
|
+
model: LanguageModelV2;
|
2491
|
+
}) => PromiseLike<LanguageModelV2CallOptions>;
|
2492
|
+
/**
|
2493
|
+
* Wraps the generate operation of the language model.
|
2494
|
+
* @param options - Object containing the generate function, parameters, and model.
|
2495
|
+
* @param options.doGenerate - The original generate function.
|
2496
|
+
* @param options.doStream - The original stream function.
|
2497
|
+
* @param options.params - The parameters for the generate call. If the
|
2498
|
+
* `transformParams` middleware is used, this will be the transformed parameters.
|
2499
|
+
* @param options.model - The language model instance.
|
2500
|
+
* @returns A promise that resolves to the result of the generate operation.
|
2501
|
+
*/
|
2502
|
+
wrapGenerate?: (options: {
|
2503
|
+
doGenerate: () => ReturnType<LanguageModelV2['doGenerate']>;
|
2504
|
+
doStream: () => ReturnType<LanguageModelV2['doStream']>;
|
2505
|
+
params: LanguageModelV2CallOptions;
|
2506
|
+
model: LanguageModelV2;
|
2507
|
+
}) => Promise<Awaited<ReturnType<LanguageModelV2['doGenerate']>>>;
|
2508
|
+
/**
|
2509
|
+
* Wraps the stream operation of the language model.
|
2510
|
+
*
|
2511
|
+
* @param options - Object containing the stream function, parameters, and model.
|
2512
|
+
* @param options.doGenerate - The original generate function.
|
2513
|
+
* @param options.doStream - The original stream function.
|
2514
|
+
* @param options.params - The parameters for the stream call. If the
|
2515
|
+
* `transformParams` middleware is used, this will be the transformed parameters.
|
2516
|
+
* @param options.model - The language model instance.
|
2517
|
+
* @returns A promise that resolves to the result of the stream operation.
|
2518
|
+
*/
|
2519
|
+
wrapStream?: (options: {
|
2520
|
+
doGenerate: () => ReturnType<LanguageModelV2['doGenerate']>;
|
2521
|
+
doStream: () => ReturnType<LanguageModelV2['doStream']>;
|
2522
|
+
params: LanguageModelV2CallOptions;
|
2523
|
+
model: LanguageModelV2;
|
2524
|
+
}) => PromiseLike<Awaited<ReturnType<LanguageModelV2['doStream']>>>;
|
2525
|
+
};
|
2526
|
+
|
2527
|
+
type SpeechModelV2ProviderOptions = Record<string, Record<string, JSONValue>>;
|
2528
|
+
type SpeechModelV2CallOptions = {
|
2529
|
+
/**
|
2530
|
+
* Text to convert to speech.
|
2531
|
+
*/
|
2532
|
+
text: string;
|
2533
|
+
/**
|
2534
|
+
* The voice to use for speech synthesis.
|
2535
|
+
* This is provider-specific and may be a voice ID, name, or other identifier.
|
2536
|
+
*/
|
2537
|
+
voice?: string;
|
2538
|
+
/**
|
2539
|
+
* The desired output format for the audio e.g. "mp3", "wav", etc.
|
2540
|
+
*/
|
2541
|
+
outputFormat?: string;
|
2542
|
+
/**
|
2543
|
+
* Instructions for the speech generation e.g. "Speak in a slow and steady tone".
|
2544
|
+
*/
|
2545
|
+
instructions?: string;
|
2546
|
+
/**
|
2547
|
+
* The speed of the speech generation.
|
2548
|
+
*/
|
2549
|
+
speed?: number;
|
2550
|
+
/**
|
2551
|
+
* The language for speech generation. This should be an ISO 639-1 language code (e.g. "en", "es", "fr")
|
2552
|
+
* or "auto" for automatic language detection. Provider support varies.
|
2553
|
+
*/
|
2554
|
+
language?: string;
|
2555
|
+
/**
|
2556
|
+
* Additional provider-specific options that are passed through to the provider
|
2557
|
+
* as body parameters.
|
2558
|
+
*
|
2559
|
+
* The outer record is keyed by the provider name, and the inner
|
2560
|
+
* record is keyed by the provider-specific metadata key.
|
2561
|
+
* ```ts
|
2562
|
+
* {
|
2563
|
+
* "openai": {}
|
2564
|
+
* }
|
2565
|
+
* ```
|
2566
|
+
*/
|
2567
|
+
providerOptions?: SpeechModelV2ProviderOptions;
|
2568
|
+
/**
|
2569
|
+
* Abort signal for cancelling the operation.
|
2570
|
+
*/
|
2571
|
+
abortSignal?: AbortSignal;
|
2572
|
+
/**
|
2573
|
+
* Additional HTTP headers to be sent with the request.
|
2574
|
+
* Only applicable for HTTP-based providers.
|
2575
|
+
*/
|
2576
|
+
headers?: Record<string, string | undefined>;
|
2577
|
+
};
|
2578
|
+
|
2579
|
+
/**
|
2580
|
+
* Warning from the model provider for this call. The call will proceed, but e.g.
|
2581
|
+
* some settings might not be supported, which can lead to suboptimal results.
|
2582
|
+
*/
|
2583
|
+
type SpeechModelV2CallWarning = {
|
2584
|
+
type: 'unsupported-setting';
|
2585
|
+
setting: keyof SpeechModelV2CallOptions;
|
2586
|
+
details?: string;
|
2587
|
+
} | {
|
2588
|
+
type: 'other';
|
2589
|
+
message: string;
|
2590
|
+
};
|
2591
|
+
|
2592
|
+
/**
|
2593
|
+
* Speech model specification version 2.
|
2594
|
+
*/
|
2595
|
+
type SpeechModelV2 = {
|
2596
|
+
/**
|
2597
|
+
* The speech model must specify which speech model interface
|
2598
|
+
* version it implements. This will allow us to evolve the speech
|
2599
|
+
* model interface and retain backwards compatibility. The different
|
2600
|
+
* implementation versions can be handled as a discriminated union
|
1704
2601
|
* on our side.
|
1705
2602
|
*/
|
1706
2603
|
readonly specificationVersion: 'v2';
|
@@ -1933,7 +2830,7 @@ interface ProviderV3 {
|
|
1933
2830
|
|
1934
2831
|
@throws {NoSuchModelError} If no such model exists.
|
1935
2832
|
*/
|
1936
|
-
languageModel(modelId: string):
|
2833
|
+
languageModel(modelId: string): LanguageModelV3;
|
1937
2834
|
/**
|
1938
2835
|
Returns the text embedding model with the given id.
|
1939
2836
|
The model id is then passed to the provider function to get the model.
|
@@ -2029,4 +2926,4 @@ interface ProviderV2 {
|
|
2029
2926
|
speechModel?(modelId: string): SpeechModelV2;
|
2030
2927
|
}
|
2031
2928
|
|
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 };
|
2929
|
+
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 SharedV3Headers, type SharedV3ProviderMetadata, type SharedV3ProviderOptions, type SpeechModelV2, type SpeechModelV2CallOptions, type SpeechModelV2CallWarning, TooManyEmbeddingValuesForCallError, type TranscriptionModelV2, type TranscriptionModelV2CallOptions, type TranscriptionModelV2CallWarning, TypeValidationError, UnsupportedFunctionalityError, getErrorMessage, isJSONArray, isJSONObject, isJSONValue };
|