ai 5.0.0-canary.22 → 5.0.0-canary.24

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/dist/index.d.mts CHANGED
@@ -610,10 +610,10 @@ onlyBar('bar');
610
610
  */
611
611
  type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
612
612
 
613
- declare const JSONRPCRequestSchema: z.ZodObject<z.objectUtil.extendShape<{
613
+ declare const JSONRPCRequestSchema: z.ZodObject<{
614
614
  jsonrpc: z.ZodLiteral<"2.0">;
615
615
  id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
616
- }, {
616
+ } & {
617
617
  method: z.ZodString;
618
618
  params: z.ZodOptional<z.ZodObject<{
619
619
  _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
@@ -622,7 +622,7 @@ declare const JSONRPCRequestSchema: z.ZodObject<z.objectUtil.extendShape<{
622
622
  }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
623
623
  _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
624
624
  }, z.ZodTypeAny, "passthrough">>>;
625
- }>, "strict", z.ZodTypeAny, {
625
+ }, "strict", z.ZodTypeAny, {
626
626
  id: string | number;
627
627
  method: string;
628
628
  jsonrpc: "2.0";
@@ -700,9 +700,9 @@ declare const JSONRPCErrorSchema: z.ZodObject<{
700
700
  jsonrpc: "2.0";
701
701
  }>;
702
702
  type JSONRPCError = z.infer<typeof JSONRPCErrorSchema>;
703
- declare const JSONRPCNotificationSchema: z.ZodObject<z.objectUtil.extendShape<{
703
+ declare const JSONRPCNotificationSchema: z.ZodObject<{
704
704
  jsonrpc: z.ZodLiteral<"2.0">;
705
- }, {
705
+ } & {
706
706
  method: z.ZodString;
707
707
  params: z.ZodOptional<z.ZodObject<{
708
708
  _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
@@ -711,7 +711,7 @@ declare const JSONRPCNotificationSchema: z.ZodObject<z.objectUtil.extendShape<{
711
711
  }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
712
712
  _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
713
713
  }, z.ZodTypeAny, "passthrough">>>;
714
- }>, "strict", z.ZodTypeAny, {
714
+ }, "strict", z.ZodTypeAny, {
715
715
  method: string;
716
716
  jsonrpc: "2.0";
717
717
  params?: z.objectOutputType<{
@@ -725,10 +725,10 @@ declare const JSONRPCNotificationSchema: z.ZodObject<z.objectUtil.extendShape<{
725
725
  }, z.ZodTypeAny, "passthrough"> | undefined;
726
726
  }>;
727
727
  type JSONRPCNotification = z.infer<typeof JSONRPCNotificationSchema>;
728
- declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
728
+ declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<{
729
729
  jsonrpc: z.ZodLiteral<"2.0">;
730
730
  id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
731
- }, {
731
+ } & {
732
732
  method: z.ZodString;
733
733
  params: z.ZodOptional<z.ZodObject<{
734
734
  _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
@@ -737,7 +737,7 @@ declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
737
737
  }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
738
738
  _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
739
739
  }, z.ZodTypeAny, "passthrough">>>;
740
- }>, "strict", z.ZodTypeAny, {
740
+ }, "strict", z.ZodTypeAny, {
741
741
  id: string | number;
742
742
  method: string;
743
743
  jsonrpc: "2.0";
@@ -751,9 +751,9 @@ declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
751
751
  params?: z.objectInputType<{
752
752
  _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
753
753
  }, z.ZodTypeAny, "passthrough"> | undefined;
754
- }>, z.ZodObject<z.objectUtil.extendShape<{
754
+ }>, z.ZodObject<{
755
755
  jsonrpc: z.ZodLiteral<"2.0">;
756
- }, {
756
+ } & {
757
757
  method: z.ZodString;
758
758
  params: z.ZodOptional<z.ZodObject<{
759
759
  _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
@@ -762,7 +762,7 @@ declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
762
762
  }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
763
763
  _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
764
764
  }, z.ZodTypeAny, "passthrough">>>;
765
- }>, "strict", z.ZodTypeAny, {
765
+ }, "strict", z.ZodTypeAny, {
766
766
  method: string;
767
767
  jsonrpc: "2.0";
768
768
  params?: z.objectOutputType<{
@@ -966,9 +966,9 @@ type McpToolSet<TOOL_SCHEMAS extends ToolSchemas = 'automatic'> = TOOL_SCHEMAS e
966
966
  } : McpToolSet<Record<string, {
967
967
  parameters: ToolParameters<unknown>;
968
968
  }>>;
969
- declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
969
+ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<{
970
970
  _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
971
- }, {
971
+ } & {
972
972
  content: z.ZodArray<z.ZodUnion<[z.ZodObject<{
973
973
  type: z.ZodLiteral<"text">;
974
974
  text: z.ZodString;
@@ -992,7 +992,7 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
992
992
  mimeType: z.ZodString;
993
993
  }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
994
994
  type: z.ZodLiteral<"resource">;
995
- resource: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
995
+ resource: z.ZodUnion<[z.ZodObject<{
996
996
  /**
997
997
  * The URI of this resource.
998
998
  */
@@ -1001,9 +1001,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1001
1001
  * The MIME type of this resource, if known.
1002
1002
  */
1003
1003
  mimeType: z.ZodOptional<z.ZodString>;
1004
- }, {
1004
+ } & {
1005
1005
  text: z.ZodString;
1006
- }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1006
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1007
1007
  /**
1008
1008
  * The URI of this resource.
1009
1009
  */
@@ -1012,9 +1012,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1012
1012
  * The MIME type of this resource, if known.
1013
1013
  */
1014
1014
  mimeType: z.ZodOptional<z.ZodString>;
1015
- }, {
1015
+ } & {
1016
1016
  text: z.ZodString;
1017
- }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1017
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1018
1018
  /**
1019
1019
  * The URI of this resource.
1020
1020
  */
@@ -1023,9 +1023,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1023
1023
  * The MIME type of this resource, if known.
1024
1024
  */
1025
1025
  mimeType: z.ZodOptional<z.ZodString>;
1026
- }, {
1026
+ } & {
1027
1027
  text: z.ZodString;
1028
- }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
1028
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
1029
1029
  /**
1030
1030
  * The URI of this resource.
1031
1031
  */
@@ -1034,9 +1034,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1034
1034
  * The MIME type of this resource, if known.
1035
1035
  */
1036
1036
  mimeType: z.ZodOptional<z.ZodString>;
1037
- }, {
1037
+ } & {
1038
1038
  blob: z.ZodString;
1039
- }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1039
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1040
1040
  /**
1041
1041
  * The URI of this resource.
1042
1042
  */
@@ -1045,9 +1045,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1045
1045
  * The MIME type of this resource, if known.
1046
1046
  */
1047
1047
  mimeType: z.ZodOptional<z.ZodString>;
1048
- }, {
1048
+ } & {
1049
1049
  blob: z.ZodString;
1050
- }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1050
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1051
1051
  /**
1052
1052
  * The URI of this resource.
1053
1053
  */
@@ -1056,12 +1056,12 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1056
1056
  * The MIME type of this resource, if known.
1057
1057
  */
1058
1058
  mimeType: z.ZodOptional<z.ZodString>;
1059
- }, {
1059
+ } & {
1060
1060
  blob: z.ZodString;
1061
- }>, z.ZodTypeAny, "passthrough">>]>;
1061
+ }, z.ZodTypeAny, "passthrough">>]>;
1062
1062
  }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1063
1063
  type: z.ZodLiteral<"resource">;
1064
- resource: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
1064
+ resource: z.ZodUnion<[z.ZodObject<{
1065
1065
  /**
1066
1066
  * The URI of this resource.
1067
1067
  */
@@ -1070,9 +1070,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1070
1070
  * The MIME type of this resource, if known.
1071
1071
  */
1072
1072
  mimeType: z.ZodOptional<z.ZodString>;
1073
- }, {
1073
+ } & {
1074
1074
  text: z.ZodString;
1075
- }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1075
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1076
1076
  /**
1077
1077
  * The URI of this resource.
1078
1078
  */
@@ -1081,9 +1081,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1081
1081
  * The MIME type of this resource, if known.
1082
1082
  */
1083
1083
  mimeType: z.ZodOptional<z.ZodString>;
1084
- }, {
1084
+ } & {
1085
1085
  text: z.ZodString;
1086
- }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1086
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1087
1087
  /**
1088
1088
  * The URI of this resource.
1089
1089
  */
@@ -1092,9 +1092,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1092
1092
  * The MIME type of this resource, if known.
1093
1093
  */
1094
1094
  mimeType: z.ZodOptional<z.ZodString>;
1095
- }, {
1095
+ } & {
1096
1096
  text: z.ZodString;
1097
- }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
1097
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
1098
1098
  /**
1099
1099
  * The URI of this resource.
1100
1100
  */
@@ -1103,9 +1103,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1103
1103
  * The MIME type of this resource, if known.
1104
1104
  */
1105
1105
  mimeType: z.ZodOptional<z.ZodString>;
1106
- }, {
1106
+ } & {
1107
1107
  blob: z.ZodString;
1108
- }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1108
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1109
1109
  /**
1110
1110
  * The URI of this resource.
1111
1111
  */
@@ -1114,9 +1114,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1114
1114
  * The MIME type of this resource, if known.
1115
1115
  */
1116
1116
  mimeType: z.ZodOptional<z.ZodString>;
1117
- }, {
1117
+ } & {
1118
1118
  blob: z.ZodString;
1119
- }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1119
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1120
1120
  /**
1121
1121
  * The URI of this resource.
1122
1122
  */
@@ -1125,12 +1125,12 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1125
1125
  * The MIME type of this resource, if known.
1126
1126
  */
1127
1127
  mimeType: z.ZodOptional<z.ZodString>;
1128
- }, {
1128
+ } & {
1129
1129
  blob: z.ZodString;
1130
- }>, z.ZodTypeAny, "passthrough">>]>;
1130
+ }, z.ZodTypeAny, "passthrough">>]>;
1131
1131
  }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1132
1132
  type: z.ZodLiteral<"resource">;
1133
- resource: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
1133
+ resource: z.ZodUnion<[z.ZodObject<{
1134
1134
  /**
1135
1135
  * The URI of this resource.
1136
1136
  */
@@ -1139,9 +1139,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1139
1139
  * The MIME type of this resource, if known.
1140
1140
  */
1141
1141
  mimeType: z.ZodOptional<z.ZodString>;
1142
- }, {
1142
+ } & {
1143
1143
  text: z.ZodString;
1144
- }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1144
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1145
1145
  /**
1146
1146
  * The URI of this resource.
1147
1147
  */
@@ -1150,9 +1150,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1150
1150
  * The MIME type of this resource, if known.
1151
1151
  */
1152
1152
  mimeType: z.ZodOptional<z.ZodString>;
1153
- }, {
1153
+ } & {
1154
1154
  text: z.ZodString;
1155
- }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1155
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1156
1156
  /**
1157
1157
  * The URI of this resource.
1158
1158
  */
@@ -1161,9 +1161,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1161
1161
  * The MIME type of this resource, if known.
1162
1162
  */
1163
1163
  mimeType: z.ZodOptional<z.ZodString>;
1164
- }, {
1164
+ } & {
1165
1165
  text: z.ZodString;
1166
- }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
1166
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
1167
1167
  /**
1168
1168
  * The URI of this resource.
1169
1169
  */
@@ -1172,9 +1172,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1172
1172
  * The MIME type of this resource, if known.
1173
1173
  */
1174
1174
  mimeType: z.ZodOptional<z.ZodString>;
1175
- }, {
1175
+ } & {
1176
1176
  blob: z.ZodString;
1177
- }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1177
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1178
1178
  /**
1179
1179
  * The URI of this resource.
1180
1180
  */
@@ -1183,9 +1183,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1183
1183
  * The MIME type of this resource, if known.
1184
1184
  */
1185
1185
  mimeType: z.ZodOptional<z.ZodString>;
1186
- }, {
1186
+ } & {
1187
1187
  blob: z.ZodString;
1188
- }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1188
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1189
1189
  /**
1190
1190
  * The URI of this resource.
1191
1191
  */
@@ -1194,14 +1194,14 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1194
1194
  * The MIME type of this resource, if known.
1195
1195
  */
1196
1196
  mimeType: z.ZodOptional<z.ZodString>;
1197
- }, {
1197
+ } & {
1198
1198
  blob: z.ZodString;
1199
- }>, z.ZodTypeAny, "passthrough">>]>;
1199
+ }, z.ZodTypeAny, "passthrough">>]>;
1200
1200
  }, z.ZodTypeAny, "passthrough">>]>, "many">;
1201
1201
  isError: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
1202
- }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1202
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1203
1203
  _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1204
- }, {
1204
+ } & {
1205
1205
  content: z.ZodArray<z.ZodUnion<[z.ZodObject<{
1206
1206
  type: z.ZodLiteral<"text">;
1207
1207
  text: z.ZodString;
@@ -1225,7 +1225,7 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1225
1225
  mimeType: z.ZodString;
1226
1226
  }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
1227
1227
  type: z.ZodLiteral<"resource">;
1228
- resource: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
1228
+ resource: z.ZodUnion<[z.ZodObject<{
1229
1229
  /**
1230
1230
  * The URI of this resource.
1231
1231
  */
@@ -1234,9 +1234,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1234
1234
  * The MIME type of this resource, if known.
1235
1235
  */
1236
1236
  mimeType: z.ZodOptional<z.ZodString>;
1237
- }, {
1237
+ } & {
1238
1238
  text: z.ZodString;
1239
- }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1239
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1240
1240
  /**
1241
1241
  * The URI of this resource.
1242
1242
  */
@@ -1245,9 +1245,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1245
1245
  * The MIME type of this resource, if known.
1246
1246
  */
1247
1247
  mimeType: z.ZodOptional<z.ZodString>;
1248
- }, {
1248
+ } & {
1249
1249
  text: z.ZodString;
1250
- }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1250
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1251
1251
  /**
1252
1252
  * The URI of this resource.
1253
1253
  */
@@ -1256,9 +1256,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1256
1256
  * The MIME type of this resource, if known.
1257
1257
  */
1258
1258
  mimeType: z.ZodOptional<z.ZodString>;
1259
- }, {
1259
+ } & {
1260
1260
  text: z.ZodString;
1261
- }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
1261
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
1262
1262
  /**
1263
1263
  * The URI of this resource.
1264
1264
  */
@@ -1267,9 +1267,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1267
1267
  * The MIME type of this resource, if known.
1268
1268
  */
1269
1269
  mimeType: z.ZodOptional<z.ZodString>;
1270
- }, {
1270
+ } & {
1271
1271
  blob: z.ZodString;
1272
- }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1272
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1273
1273
  /**
1274
1274
  * The URI of this resource.
1275
1275
  */
@@ -1278,9 +1278,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1278
1278
  * The MIME type of this resource, if known.
1279
1279
  */
1280
1280
  mimeType: z.ZodOptional<z.ZodString>;
1281
- }, {
1281
+ } & {
1282
1282
  blob: z.ZodString;
1283
- }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1283
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1284
1284
  /**
1285
1285
  * The URI of this resource.
1286
1286
  */
@@ -1289,12 +1289,12 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1289
1289
  * The MIME type of this resource, if known.
1290
1290
  */
1291
1291
  mimeType: z.ZodOptional<z.ZodString>;
1292
- }, {
1292
+ } & {
1293
1293
  blob: z.ZodString;
1294
- }>, z.ZodTypeAny, "passthrough">>]>;
1294
+ }, z.ZodTypeAny, "passthrough">>]>;
1295
1295
  }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1296
1296
  type: z.ZodLiteral<"resource">;
1297
- resource: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
1297
+ resource: z.ZodUnion<[z.ZodObject<{
1298
1298
  /**
1299
1299
  * The URI of this resource.
1300
1300
  */
@@ -1303,9 +1303,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1303
1303
  * The MIME type of this resource, if known.
1304
1304
  */
1305
1305
  mimeType: z.ZodOptional<z.ZodString>;
1306
- }, {
1306
+ } & {
1307
1307
  text: z.ZodString;
1308
- }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1308
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1309
1309
  /**
1310
1310
  * The URI of this resource.
1311
1311
  */
@@ -1314,9 +1314,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1314
1314
  * The MIME type of this resource, if known.
1315
1315
  */
1316
1316
  mimeType: z.ZodOptional<z.ZodString>;
1317
- }, {
1317
+ } & {
1318
1318
  text: z.ZodString;
1319
- }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1319
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1320
1320
  /**
1321
1321
  * The URI of this resource.
1322
1322
  */
@@ -1325,9 +1325,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1325
1325
  * The MIME type of this resource, if known.
1326
1326
  */
1327
1327
  mimeType: z.ZodOptional<z.ZodString>;
1328
- }, {
1328
+ } & {
1329
1329
  text: z.ZodString;
1330
- }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
1330
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
1331
1331
  /**
1332
1332
  * The URI of this resource.
1333
1333
  */
@@ -1336,9 +1336,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1336
1336
  * The MIME type of this resource, if known.
1337
1337
  */
1338
1338
  mimeType: z.ZodOptional<z.ZodString>;
1339
- }, {
1339
+ } & {
1340
1340
  blob: z.ZodString;
1341
- }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1341
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1342
1342
  /**
1343
1343
  * The URI of this resource.
1344
1344
  */
@@ -1347,9 +1347,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1347
1347
  * The MIME type of this resource, if known.
1348
1348
  */
1349
1349
  mimeType: z.ZodOptional<z.ZodString>;
1350
- }, {
1350
+ } & {
1351
1351
  blob: z.ZodString;
1352
- }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1352
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1353
1353
  /**
1354
1354
  * The URI of this resource.
1355
1355
  */
@@ -1358,12 +1358,12 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1358
1358
  * The MIME type of this resource, if known.
1359
1359
  */
1360
1360
  mimeType: z.ZodOptional<z.ZodString>;
1361
- }, {
1361
+ } & {
1362
1362
  blob: z.ZodString;
1363
- }>, z.ZodTypeAny, "passthrough">>]>;
1363
+ }, z.ZodTypeAny, "passthrough">>]>;
1364
1364
  }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1365
1365
  type: z.ZodLiteral<"resource">;
1366
- resource: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
1366
+ resource: z.ZodUnion<[z.ZodObject<{
1367
1367
  /**
1368
1368
  * The URI of this resource.
1369
1369
  */
@@ -1372,9 +1372,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1372
1372
  * The MIME type of this resource, if known.
1373
1373
  */
1374
1374
  mimeType: z.ZodOptional<z.ZodString>;
1375
- }, {
1375
+ } & {
1376
1376
  text: z.ZodString;
1377
- }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1377
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1378
1378
  /**
1379
1379
  * The URI of this resource.
1380
1380
  */
@@ -1383,9 +1383,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1383
1383
  * The MIME type of this resource, if known.
1384
1384
  */
1385
1385
  mimeType: z.ZodOptional<z.ZodString>;
1386
- }, {
1386
+ } & {
1387
1387
  text: z.ZodString;
1388
- }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1388
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1389
1389
  /**
1390
1390
  * The URI of this resource.
1391
1391
  */
@@ -1394,9 +1394,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1394
1394
  * The MIME type of this resource, if known.
1395
1395
  */
1396
1396
  mimeType: z.ZodOptional<z.ZodString>;
1397
- }, {
1397
+ } & {
1398
1398
  text: z.ZodString;
1399
- }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
1399
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
1400
1400
  /**
1401
1401
  * The URI of this resource.
1402
1402
  */
@@ -1405,9 +1405,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1405
1405
  * The MIME type of this resource, if known.
1406
1406
  */
1407
1407
  mimeType: z.ZodOptional<z.ZodString>;
1408
- }, {
1408
+ } & {
1409
1409
  blob: z.ZodString;
1410
- }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1410
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1411
1411
  /**
1412
1412
  * The URI of this resource.
1413
1413
  */
@@ -1416,9 +1416,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1416
1416
  * The MIME type of this resource, if known.
1417
1417
  */
1418
1418
  mimeType: z.ZodOptional<z.ZodString>;
1419
- }, {
1419
+ } & {
1420
1420
  blob: z.ZodString;
1421
- }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1421
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1422
1422
  /**
1423
1423
  * The URI of this resource.
1424
1424
  */
@@ -1427,14 +1427,14 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1427
1427
  * The MIME type of this resource, if known.
1428
1428
  */
1429
1429
  mimeType: z.ZodOptional<z.ZodString>;
1430
- }, {
1430
+ } & {
1431
1431
  blob: z.ZodString;
1432
- }>, z.ZodTypeAny, "passthrough">>]>;
1432
+ }, z.ZodTypeAny, "passthrough">>]>;
1433
1433
  }, z.ZodTypeAny, "passthrough">>]>, "many">;
1434
1434
  isError: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
1435
- }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1435
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1436
1436
  _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1437
- }, {
1437
+ } & {
1438
1438
  content: z.ZodArray<z.ZodUnion<[z.ZodObject<{
1439
1439
  type: z.ZodLiteral<"text">;
1440
1440
  text: z.ZodString;
@@ -1458,7 +1458,7 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1458
1458
  mimeType: z.ZodString;
1459
1459
  }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
1460
1460
  type: z.ZodLiteral<"resource">;
1461
- resource: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
1461
+ resource: z.ZodUnion<[z.ZodObject<{
1462
1462
  /**
1463
1463
  * The URI of this resource.
1464
1464
  */
@@ -1467,9 +1467,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1467
1467
  * The MIME type of this resource, if known.
1468
1468
  */
1469
1469
  mimeType: z.ZodOptional<z.ZodString>;
1470
- }, {
1470
+ } & {
1471
1471
  text: z.ZodString;
1472
- }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1472
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1473
1473
  /**
1474
1474
  * The URI of this resource.
1475
1475
  */
@@ -1478,9 +1478,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1478
1478
  * The MIME type of this resource, if known.
1479
1479
  */
1480
1480
  mimeType: z.ZodOptional<z.ZodString>;
1481
- }, {
1481
+ } & {
1482
1482
  text: z.ZodString;
1483
- }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1483
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1484
1484
  /**
1485
1485
  * The URI of this resource.
1486
1486
  */
@@ -1489,9 +1489,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1489
1489
  * The MIME type of this resource, if known.
1490
1490
  */
1491
1491
  mimeType: z.ZodOptional<z.ZodString>;
1492
- }, {
1492
+ } & {
1493
1493
  text: z.ZodString;
1494
- }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
1494
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
1495
1495
  /**
1496
1496
  * The URI of this resource.
1497
1497
  */
@@ -1500,9 +1500,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1500
1500
  * The MIME type of this resource, if known.
1501
1501
  */
1502
1502
  mimeType: z.ZodOptional<z.ZodString>;
1503
- }, {
1503
+ } & {
1504
1504
  blob: z.ZodString;
1505
- }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1505
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1506
1506
  /**
1507
1507
  * The URI of this resource.
1508
1508
  */
@@ -1511,9 +1511,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1511
1511
  * The MIME type of this resource, if known.
1512
1512
  */
1513
1513
  mimeType: z.ZodOptional<z.ZodString>;
1514
- }, {
1514
+ } & {
1515
1515
  blob: z.ZodString;
1516
- }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1516
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1517
1517
  /**
1518
1518
  * The URI of this resource.
1519
1519
  */
@@ -1522,12 +1522,12 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1522
1522
  * The MIME type of this resource, if known.
1523
1523
  */
1524
1524
  mimeType: z.ZodOptional<z.ZodString>;
1525
- }, {
1525
+ } & {
1526
1526
  blob: z.ZodString;
1527
- }>, z.ZodTypeAny, "passthrough">>]>;
1527
+ }, z.ZodTypeAny, "passthrough">>]>;
1528
1528
  }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1529
1529
  type: z.ZodLiteral<"resource">;
1530
- resource: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
1530
+ resource: z.ZodUnion<[z.ZodObject<{
1531
1531
  /**
1532
1532
  * The URI of this resource.
1533
1533
  */
@@ -1536,9 +1536,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1536
1536
  * The MIME type of this resource, if known.
1537
1537
  */
1538
1538
  mimeType: z.ZodOptional<z.ZodString>;
1539
- }, {
1539
+ } & {
1540
1540
  text: z.ZodString;
1541
- }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1541
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1542
1542
  /**
1543
1543
  * The URI of this resource.
1544
1544
  */
@@ -1547,9 +1547,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1547
1547
  * The MIME type of this resource, if known.
1548
1548
  */
1549
1549
  mimeType: z.ZodOptional<z.ZodString>;
1550
- }, {
1550
+ } & {
1551
1551
  text: z.ZodString;
1552
- }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1552
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1553
1553
  /**
1554
1554
  * The URI of this resource.
1555
1555
  */
@@ -1558,9 +1558,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1558
1558
  * The MIME type of this resource, if known.
1559
1559
  */
1560
1560
  mimeType: z.ZodOptional<z.ZodString>;
1561
- }, {
1561
+ } & {
1562
1562
  text: z.ZodString;
1563
- }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
1563
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
1564
1564
  /**
1565
1565
  * The URI of this resource.
1566
1566
  */
@@ -1569,9 +1569,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1569
1569
  * The MIME type of this resource, if known.
1570
1570
  */
1571
1571
  mimeType: z.ZodOptional<z.ZodString>;
1572
- }, {
1572
+ } & {
1573
1573
  blob: z.ZodString;
1574
- }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1574
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1575
1575
  /**
1576
1576
  * The URI of this resource.
1577
1577
  */
@@ -1580,9 +1580,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1580
1580
  * The MIME type of this resource, if known.
1581
1581
  */
1582
1582
  mimeType: z.ZodOptional<z.ZodString>;
1583
- }, {
1583
+ } & {
1584
1584
  blob: z.ZodString;
1585
- }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1585
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1586
1586
  /**
1587
1587
  * The URI of this resource.
1588
1588
  */
@@ -1591,12 +1591,12 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1591
1591
  * The MIME type of this resource, if known.
1592
1592
  */
1593
1593
  mimeType: z.ZodOptional<z.ZodString>;
1594
- }, {
1594
+ } & {
1595
1595
  blob: z.ZodString;
1596
- }>, z.ZodTypeAny, "passthrough">>]>;
1596
+ }, z.ZodTypeAny, "passthrough">>]>;
1597
1597
  }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1598
1598
  type: z.ZodLiteral<"resource">;
1599
- resource: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
1599
+ resource: z.ZodUnion<[z.ZodObject<{
1600
1600
  /**
1601
1601
  * The URI of this resource.
1602
1602
  */
@@ -1605,9 +1605,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1605
1605
  * The MIME type of this resource, if known.
1606
1606
  */
1607
1607
  mimeType: z.ZodOptional<z.ZodString>;
1608
- }, {
1608
+ } & {
1609
1609
  text: z.ZodString;
1610
- }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1610
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1611
1611
  /**
1612
1612
  * The URI of this resource.
1613
1613
  */
@@ -1616,9 +1616,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1616
1616
  * The MIME type of this resource, if known.
1617
1617
  */
1618
1618
  mimeType: z.ZodOptional<z.ZodString>;
1619
- }, {
1619
+ } & {
1620
1620
  text: z.ZodString;
1621
- }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1621
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1622
1622
  /**
1623
1623
  * The URI of this resource.
1624
1624
  */
@@ -1627,9 +1627,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1627
1627
  * The MIME type of this resource, if known.
1628
1628
  */
1629
1629
  mimeType: z.ZodOptional<z.ZodString>;
1630
- }, {
1630
+ } & {
1631
1631
  text: z.ZodString;
1632
- }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
1632
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
1633
1633
  /**
1634
1634
  * The URI of this resource.
1635
1635
  */
@@ -1638,9 +1638,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1638
1638
  * The MIME type of this resource, if known.
1639
1639
  */
1640
1640
  mimeType: z.ZodOptional<z.ZodString>;
1641
- }, {
1641
+ } & {
1642
1642
  blob: z.ZodString;
1643
- }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1643
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1644
1644
  /**
1645
1645
  * The URI of this resource.
1646
1646
  */
@@ -1649,9 +1649,9 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1649
1649
  * The MIME type of this resource, if known.
1650
1650
  */
1651
1651
  mimeType: z.ZodOptional<z.ZodString>;
1652
- }, {
1652
+ } & {
1653
1653
  blob: z.ZodString;
1654
- }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1654
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1655
1655
  /**
1656
1656
  * The URI of this resource.
1657
1657
  */
@@ -1660,24 +1660,24 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
1660
1660
  * The MIME type of this resource, if known.
1661
1661
  */
1662
1662
  mimeType: z.ZodOptional<z.ZodString>;
1663
- }, {
1663
+ } & {
1664
1664
  blob: z.ZodString;
1665
- }>, z.ZodTypeAny, "passthrough">>]>;
1665
+ }, z.ZodTypeAny, "passthrough">>]>;
1666
1666
  }, z.ZodTypeAny, "passthrough">>]>, "many">;
1667
1667
  isError: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
1668
- }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
1668
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
1669
1669
  _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1670
- }, {
1670
+ } & {
1671
1671
  toolResult: z.ZodUnknown;
1672
- }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1672
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1673
1673
  _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1674
- }, {
1674
+ } & {
1675
1675
  toolResult: z.ZodUnknown;
1676
- }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1676
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1677
1677
  _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1678
- }, {
1678
+ } & {
1679
1679
  toolResult: z.ZodUnknown;
1680
- }>, z.ZodTypeAny, "passthrough">>]>;
1680
+ }, z.ZodTypeAny, "passthrough">>]>;
1681
1681
  type CallToolResult = z.infer<typeof CallToolResultSchema>;
1682
1682
 
1683
1683
  interface MCPClientConfig {
@@ -2123,9 +2123,13 @@ type ToolInvocation = ({
2123
2123
  step?: number;
2124
2124
  } & ToolResult<string, any, any>);
2125
2125
  /**
2126
- * AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
2126
+ The data types that can be used in the UI message for the UI message data parts.
2127
+ */
2128
+ type UIDataTypes = Record<string, unknown>;
2129
+ /**
2130
+ AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
2127
2131
  */
2128
- interface UIMessage<METADATA = unknown> {
2132
+ interface UIMessage<METADATA = unknown, DATA_PARTS extends UIDataTypes = UIDataTypes> {
2129
2133
  /**
2130
2134
  A unique identifier for the message.
2131
2135
  */
@@ -2148,9 +2152,16 @@ interface UIMessage<METADATA = unknown> {
2148
2152
 
2149
2153
  Assistant messages can have text, reasoning, tool invocation, and file parts.
2150
2154
  */
2151
- parts: Array<UIMessagePart>;
2155
+ parts: Array<UIMessagePart<DATA_PARTS>>;
2152
2156
  }
2153
- type UIMessagePart = TextUIPart | ReasoningUIPart | ToolInvocationUIPart | SourceUIPart | FileUIPart | StepStartUIPart;
2157
+ type UIMessagePart<DATA_TYPES extends UIDataTypes> = TextUIPart | ReasoningUIPart | ToolInvocationUIPart | SourceUIPart | FileUIPart | DataUIPart<DATA_TYPES> | StepStartUIPart;
2158
+ type DataUIPart<DATA_TYPES extends UIDataTypes> = ValueOf<{
2159
+ [NAME in keyof DATA_TYPES & string]: {
2160
+ type: `data-${NAME}`;
2161
+ id?: string;
2162
+ value: DATA_TYPES[NAME];
2163
+ };
2164
+ }>;
2154
2165
  /**
2155
2166
  * A text part of a message.
2156
2167
  */
@@ -2193,7 +2204,13 @@ type SourceUIPart = {
2193
2204
  /**
2194
2205
  * The source.
2195
2206
  */
2196
- source: LanguageModelV2Source;
2207
+ source: {
2208
+ sourceType: 'url';
2209
+ id: string;
2210
+ url: string;
2211
+ title?: string;
2212
+ providerMetadata?: Record<string, any>;
2213
+ };
2197
2214
  };
2198
2215
  /**
2199
2216
  * A file part of a message.
@@ -2222,8 +2239,8 @@ type FileUIPart = {
2222
2239
  type StepStartUIPart = {
2223
2240
  type: 'step-start';
2224
2241
  };
2225
- type CreateUIMessage<METADATA = unknown> = Omit<UIMessage<METADATA>, 'id'> & {
2226
- id?: UIMessage<METADATA>['id'];
2242
+ type CreateUIMessage<METADATA = unknown, DATA_TYPES extends UIDataTypes = UIDataTypes> = Omit<UIMessage<METADATA, DATA_TYPES>, 'id'> & {
2243
+ id?: UIMessage<METADATA, DATA_TYPES>['id'];
2227
2244
  };
2228
2245
 
2229
2246
  declare const symbol$3: unique symbol;
@@ -2285,643 +2302,355 @@ declare function pipeTextStreamToResponse({ response, status, statusText, header
2285
2302
  declare function appendClientMessage({ messages, message, }: {
2286
2303
  messages: UIMessage[];
2287
2304
  message: UIMessage;
2288
- }): UIMessage<unknown>[];
2305
+ }): UIMessage<unknown, UIDataTypes>[];
2289
2306
 
2290
- type ChatRequestOptions = {
2307
+ /**
2308
+ The result of an `embed` call.
2309
+ It contains the embedding, the value, and additional information.
2310
+ */
2311
+ interface EmbedResult<VALUE> {
2291
2312
  /**
2292
- Additional headers that should be to be passed to the API endpoint.
2293
- */
2294
- headers?: Record<string, string> | Headers;
2313
+ The value that was embedded.
2314
+ */
2315
+ readonly value: VALUE;
2295
2316
  /**
2296
- Additional body JSON properties that should be sent to the API endpoint.
2297
- */
2298
- body?: object;
2299
- };
2300
- type UseChatOptions<MESSAGE_METADATA = unknown> = {
2317
+ The embedding of the value.
2318
+ */
2319
+ readonly embedding: Embedding;
2301
2320
  /**
2302
- * Schema for the message metadata. Validates the message metadata.
2303
- * Message metadata can be undefined or must match the schema.
2304
- */
2305
- messageMetadataSchema?: Schema<MESSAGE_METADATA>;
2321
+ The embedding token usage.
2322
+ */
2323
+ readonly usage: EmbeddingModelUsage;
2306
2324
  /**
2307
- * The API endpoint that accepts a `{ messages: Message[] }` object and returns
2308
- * a stream of tokens of the AI chat response. Defaults to `/api/chat`.
2309
- */
2310
- api?: string;
2325
+ Optional response data.
2326
+ */
2327
+ readonly response?: {
2328
+ /**
2329
+ Response headers.
2330
+ */
2331
+ headers?: Record<string, string>;
2332
+ /**
2333
+ The response body.
2334
+ */
2335
+ body?: unknown;
2336
+ };
2337
+ }
2338
+
2339
+ /**
2340
+ Embed a value using an embedding model. The type of the value is defined by the embedding model.
2341
+
2342
+ @param model - The embedding model to use.
2343
+ @param value - The value that should be embedded.
2344
+
2345
+ @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
2346
+ @param abortSignal - An optional abort signal that can be used to cancel the call.
2347
+ @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
2348
+
2349
+ @returns A result object that contains the embedding, the value, and additional information.
2350
+ */
2351
+ declare function embed<VALUE>({ model, value, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, experimental_telemetry: telemetry, }: {
2311
2352
  /**
2312
- * A unique identifier for the chat. If not provided, a random one will be
2313
- * generated. When provided, the `useChat` hook with the same `id` will
2314
- * have shared states across components.
2353
+ The embedding model to use.
2354
+ */
2355
+ model: EmbeddingModel<VALUE>;
2356
+ /**
2357
+ The value that should be embedded.
2315
2358
  */
2316
- id?: string;
2359
+ value: VALUE;
2317
2360
  /**
2318
- * Initial messages of the chat. Useful to load an existing chat history.
2361
+ Maximum number of retries per embedding model call. Set to 0 to disable retries.
2362
+
2363
+ @default 2
2319
2364
  */
2320
- initialMessages?: UIMessage<NoInfer<MESSAGE_METADATA>>[];
2365
+ maxRetries?: number;
2321
2366
  /**
2322
- * Initial input of the chat.
2367
+ Abort signal.
2368
+ */
2369
+ abortSignal?: AbortSignal;
2370
+ /**
2371
+ Additional headers to include in the request.
2372
+ Only applicable for HTTP-based providers.
2373
+ */
2374
+ headers?: Record<string, string>;
2375
+ /**
2376
+ Additional provider-specific options. They are passed through
2377
+ to the provider from the AI SDK and enable provider-specific
2378
+ functionality that can be fully encapsulated in the provider.
2379
+ */
2380
+ providerOptions?: ProviderOptions;
2381
+ /**
2382
+ * Optional telemetry configuration (experimental).
2323
2383
  */
2324
- initialInput?: string;
2384
+ experimental_telemetry?: TelemetrySettings;
2385
+ }): Promise<EmbedResult<VALUE>>;
2386
+
2387
+ /**
2388
+ The result of a `embedMany` call.
2389
+ It contains the embeddings, the values, and additional information.
2390
+ */
2391
+ interface EmbedManyResult<VALUE> {
2325
2392
  /**
2326
- Optional callback function that is invoked when a tool call is received.
2327
- Intended for automatic client-side tool execution.
2328
-
2329
- You can optionally return a result for the tool call,
2330
- either synchronously or asynchronously.
2393
+ The values that were embedded.
2331
2394
  */
2332
- onToolCall?: ({ toolCall, }: {
2333
- toolCall: ToolCall<string, unknown>;
2334
- }) => void | Promise<unknown> | unknown;
2395
+ readonly values: Array<VALUE>;
2335
2396
  /**
2336
- * Optional callback function that is called when the assistant message is finished streaming.
2337
- *
2338
- * @param message The message that was streamed.
2339
- */
2340
- onFinish?: (options: {
2341
- message: UIMessage<NoInfer<MESSAGE_METADATA>>;
2342
- }) => void;
2397
+ The embeddings. They are in the same order as the values.
2398
+ */
2399
+ readonly embeddings: Array<Embedding>;
2343
2400
  /**
2344
- * Callback function to be called when an error is encountered.
2345
- */
2346
- onError?: (error: Error) => void;
2401
+ The embedding token usage.
2402
+ */
2403
+ readonly usage: EmbeddingModelUsage;
2347
2404
  /**
2348
- * A way to provide a function that is going to be used for ids for messages and the chat.
2349
- * If not provided the default AI SDK `generateId` is used.
2350
- */
2351
- generateId?: IdGenerator;
2405
+ Optional raw response data.
2406
+ */
2407
+ readonly responses?: Array<{
2408
+ /**
2409
+ Response headers.
2410
+ */
2411
+ headers?: Record<string, string>;
2412
+ /**
2413
+ The response body.
2414
+ */
2415
+ body?: unknown;
2416
+ } | undefined>;
2417
+ }
2418
+
2419
+ /**
2420
+ Embed several values using an embedding model. The type of the value is defined
2421
+ by the embedding model.
2422
+
2423
+ `embedMany` automatically splits large requests into smaller chunks if the model
2424
+ has a limit on how many embeddings can be generated in a single call.
2425
+
2426
+ @param model - The embedding model to use.
2427
+ @param values - The values that should be embedded.
2428
+
2429
+ @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
2430
+ @param abortSignal - An optional abort signal that can be used to cancel the call.
2431
+ @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
2432
+
2433
+ @returns A result object that contains the embeddings, the value, and additional information.
2434
+ */
2435
+ declare function embedMany<VALUE>({ model, values, maxParallelCalls, maxRetries: maxRetriesArg, abortSignal, headers, providerOptions, experimental_telemetry: telemetry, }: {
2352
2436
  /**
2353
- * The credentials mode to be used for the fetch request.
2354
- * Possible values are: 'omit', 'same-origin', 'include'.
2355
- * Defaults to 'same-origin'.
2356
- */
2357
- credentials?: RequestCredentials;
2437
+ The embedding model to use.
2438
+ */
2439
+ model: EmbeddingModel<VALUE>;
2358
2440
  /**
2359
- * HTTP headers to be sent with the API request.
2441
+ The values that should be embedded.
2360
2442
  */
2361
- headers?: Record<string, string> | Headers;
2443
+ values: Array<VALUE>;
2362
2444
  /**
2363
- * Extra body object to be sent with the API request.
2364
- * @example
2365
- * Send a `sessionId` to the API along with the messages.
2366
- * ```js
2367
- * useChat({
2368
- * body: {
2369
- * sessionId: '123',
2370
- * }
2371
- * })
2372
- * ```
2445
+ Maximum number of retries per embedding model call. Set to 0 to disable retries.
2446
+
2447
+ @default 2
2373
2448
  */
2374
- body?: object;
2449
+ maxRetries?: number;
2375
2450
  /**
2376
- Streaming protocol that is used. Defaults to `ui-message`.
2377
- */
2378
- streamProtocol?: 'ui-message' | 'text';
2451
+ Abort signal.
2452
+ */
2453
+ abortSignal?: AbortSignal;
2379
2454
  /**
2380
- Custom fetch implementation. You can use it as a middleware to intercept requests,
2381
- or to provide a custom fetch implementation for e.g. testing.
2382
- */
2383
- fetch?: FetchFunction;
2455
+ Additional headers to include in the request.
2456
+ Only applicable for HTTP-based providers.
2457
+ */
2458
+ headers?: Record<string, string>;
2384
2459
  /**
2385
- Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
2386
- Must be at least 1.
2387
-
2388
- A maximum number is required to prevent infinite loops in the case of misconfigured tools.
2389
-
2390
- By default, it's set to 1, which means that only a single LLM call is made.
2460
+ * Optional telemetry configuration (experimental).
2391
2461
  */
2392
- maxSteps?: number;
2393
- };
2462
+ experimental_telemetry?: TelemetrySettings;
2463
+ /**
2464
+ Additional provider-specific options. They are passed through
2465
+ to the provider from the AI SDK and enable provider-specific
2466
+ functionality that can be fully encapsulated in the provider.
2467
+ */
2468
+ providerOptions?: ProviderOptions;
2469
+ /**
2470
+ * Maximum number of concurrent requests.
2471
+ *
2472
+ * @default Infinity
2473
+ */
2474
+ maxParallelCalls?: number;
2475
+ }): Promise<EmbedManyResult<VALUE>>;
2394
2476
 
2395
- declare const getOriginalFetch$1: () => typeof fetch;
2396
- declare function callChatApi<MESSAGE_METADATA>({ api, body, streamProtocol, credentials, headers, abortController, onUpdate, onFinish, onToolCall, generateId, fetch, lastMessage, requestType, messageMetadataSchema, }: {
2397
- api: string;
2398
- body: Record<string, any>;
2399
- streamProtocol: 'ui-message' | 'text' | undefined;
2400
- credentials: RequestCredentials | undefined;
2401
- headers: HeadersInit | undefined;
2402
- abortController: (() => AbortController | null) | undefined;
2403
- onUpdate: (options: {
2404
- message: UIMessage<MESSAGE_METADATA>;
2405
- }) => void;
2406
- onFinish: UseChatOptions<MESSAGE_METADATA>['onFinish'];
2407
- onToolCall: UseChatOptions<MESSAGE_METADATA>['onToolCall'];
2408
- generateId: IdGenerator;
2409
- fetch: ReturnType<typeof getOriginalFetch$1> | undefined;
2410
- lastMessage: UIMessage<MESSAGE_METADATA> | undefined;
2411
- requestType?: 'generate' | 'resume';
2412
- messageMetadataSchema?: Schema<MESSAGE_METADATA>;
2413
- }): Promise<void>;
2414
-
2415
- declare const getOriginalFetch: () => typeof fetch;
2416
- declare function callCompletionApi({ api, prompt, credentials, headers, body, streamProtocol, setCompletion, setLoading, setError, setAbortController, onFinish, onError, fetch, }: {
2417
- api: string;
2418
- prompt: string;
2419
- credentials: RequestCredentials | undefined;
2420
- headers: HeadersInit | undefined;
2421
- body: Record<string, any>;
2422
- streamProtocol: 'data' | 'text' | undefined;
2423
- setCompletion: (completion: string) => void;
2424
- setLoading: (loading: boolean) => void;
2425
- setError: (error: Error | undefined) => void;
2426
- setAbortController: (abortController: AbortController | null) => void;
2427
- onFinish: ((prompt: string, completion: string) => void) | undefined;
2428
- onError: ((error: Error) => void) | undefined;
2429
- fetch: ReturnType<typeof getOriginalFetch> | undefined;
2430
- }): Promise<string | null | undefined>;
2431
-
2432
- declare function convertFileListToFileUIParts(files: FileList | undefined): Promise<Array<FileUIPart>>;
2433
-
2434
- /**
2435
- Converts an array of messages from useChat into an array of CoreMessages that can be used
2436
- with the AI core functions (e.g. `streamText`).
2437
- */
2438
- declare function convertToModelMessages<TOOLS extends ToolSet = never>(messages: Array<Omit<UIMessage, 'id'>>, options?: {
2439
- tools?: TOOLS;
2440
- }): ModelMessage[];
2441
2477
  /**
2442
- @deprecated Use `convertToModelMessages` instead.
2478
+ A message that was generated during the generation process.
2479
+ It can be either an assistant message or a tool message.
2443
2480
  */
2444
- declare const convertToCoreMessages: typeof convertToModelMessages;
2445
-
2446
- declare function extractMaxToolInvocationStep(toolInvocations: ToolInvocation[] | undefined): number | undefined;
2447
-
2448
- declare function getToolInvocations(message: UIMessage): ToolInvocation[];
2449
-
2450
- declare function processTextStream({ stream, onTextPart, }: {
2451
- stream: ReadableStream<Uint8Array>;
2452
- onTextPart: (chunk: string) => Promise<void> | void;
2453
- }): Promise<void>;
2481
+ type ResponseMessage = AssistantModelMessage | ToolModelMessage;
2454
2482
 
2455
- declare function shouldResubmitMessages({ originalMaxToolInvocationStep, originalMessageCount, maxSteps, messages, }: {
2456
- originalMaxToolInvocationStep: number | undefined;
2457
- originalMessageCount: number;
2458
- maxSteps: number;
2459
- messages: UIMessage[];
2460
- }): boolean;
2461
2483
  /**
2462
- Check if the message is an assistant message with completed tool calls.
2463
- The last step of the message must have at least one tool invocation and
2464
- all tool invocations must have a result.
2484
+ * The result of a single step in the generation process.
2465
2485
  */
2466
- declare function isAssistantMessageWithCompletedToolCalls(message: UIMessage): message is UIMessage & {
2467
- role: 'assistant';
2486
+ type StepResult<TOOLS extends ToolSet> = {
2487
+ /**
2488
+ The content that was generated in the last step.
2489
+ */
2490
+ readonly content: Array<ContentPart<TOOLS>>;
2491
+ /**
2492
+ The generated text.
2493
+ */
2494
+ readonly text: string;
2495
+ /**
2496
+ The reasoning that was generated during the generation.
2497
+ */
2498
+ readonly reasoning: Array<ReasoningPart>;
2499
+ /**
2500
+ The reasoning text that was generated during the generation.
2501
+ */
2502
+ readonly reasoningText: string | undefined;
2503
+ /**
2504
+ The files that were generated during the generation.
2505
+ */
2506
+ readonly files: Array<GeneratedFile>;
2507
+ /**
2508
+ The sources that were used to generate the text.
2509
+ */
2510
+ readonly sources: Array<Source>;
2511
+ /**
2512
+ The tool calls that were made during the generation.
2513
+ */
2514
+ readonly toolCalls: ToolCallArray<TOOLS>;
2515
+ /**
2516
+ The results of the tool calls.
2517
+ */
2518
+ readonly toolResults: ToolResultArray<TOOLS>;
2519
+ /**
2520
+ The reason why the generation finished.
2521
+ */
2522
+ readonly finishReason: FinishReason;
2523
+ /**
2524
+ The token usage of the generated text.
2525
+ */
2526
+ readonly usage: LanguageModelUsage;
2527
+ /**
2528
+ Warnings from the model provider (e.g. unsupported settings).
2529
+ */
2530
+ readonly warnings: CallWarning[] | undefined;
2531
+ /**
2532
+ Additional request information.
2533
+ */
2534
+ readonly request: LanguageModelRequestMetadata;
2535
+ /**
2536
+ Additional response information.
2537
+ */
2538
+ readonly response: LanguageModelResponseMetadata & {
2539
+ /**
2540
+ The response messages that were generated during the call.
2541
+ Response messages can be either assistant messages or tool messages.
2542
+ They contain a generated id.
2543
+ */
2544
+ readonly messages: Array<ResponseMessage>;
2545
+ /**
2546
+ Response body (available only for providers that use HTTP requests).
2547
+ */
2548
+ body?: unknown;
2549
+ };
2550
+ /**
2551
+ Additional provider-specific metadata. They are passed through
2552
+ from the provider to the AI SDK and enable provider-specific
2553
+ results that can be fully encapsulated in the provider.
2554
+ */
2555
+ readonly providerMetadata: ProviderMetadata | undefined;
2468
2556
  };
2469
2557
 
2470
2558
  /**
2471
- * Updates the result of a specific tool invocation in the last message of the given messages array.
2472
- *
2473
- * @param {object} params - The parameters object.
2474
- * @param {UIMessage[]} params.messages - An array of messages, from which the last one is updated.
2475
- * @param {string} params.toolCallId - The unique identifier for the tool invocation to update.
2476
- * @param {unknown} params.toolResult - The result object to attach to the tool invocation.
2477
- * @returns {void} This function does not return anything.
2559
+ The result of a `generateText` call.
2560
+ It contains the generated text, the tool calls that were made during the generation, and the results of the tool calls.
2478
2561
  */
2479
- declare function updateToolCallResult({ messages, toolCallId, toolResult: result, }: {
2480
- messages: UIMessage[];
2481
- toolCallId: string;
2482
- toolResult: unknown;
2483
- }): void;
2484
-
2485
- type CompletionRequestOptions = {
2562
+ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT> {
2486
2563
  /**
2487
- An optional object of headers to be passed to the API endpoint.
2564
+ The content that was generated in the last step.
2488
2565
  */
2489
- headers?: Record<string, string> | Headers;
2566
+ readonly content: Array<ContentPart<TOOLS>>;
2490
2567
  /**
2491
- An optional object to be passed to the API endpoint.
2568
+ The text that was generated in the last step.
2492
2569
  */
2493
- body?: object;
2494
- };
2495
- type UseCompletionOptions = {
2570
+ readonly text: string;
2496
2571
  /**
2497
- * The API endpoint that accepts a `{ prompt: string }` object and returns
2498
- * a stream of tokens of the AI completion response. Defaults to `/api/completion`.
2572
+ The full reasoning that the model has generated in the last step.
2499
2573
  */
2500
- api?: string;
2574
+ readonly reasoning: Array<ReasoningPart>;
2501
2575
  /**
2502
- * An unique identifier for the chat. If not provided, a random one will be
2503
- * generated. When provided, the `useChat` hook with the same `id` will
2504
- * have shared states across components.
2576
+ The reasoning text that the model has generated in the last step. Can be undefined if the model
2577
+ has only generated text.
2505
2578
  */
2506
- id?: string;
2579
+ readonly reasoningText: string | undefined;
2507
2580
  /**
2508
- * Initial prompt input of the completion.
2581
+ The files that were generated in the last step.
2582
+ Empty array if no files were generated.
2583
+ */
2584
+ readonly files: Array<GeneratedFile>;
2585
+ /**
2586
+ Sources that have been used as references in the last step.
2509
2587
  */
2510
- initialInput?: string;
2588
+ readonly sources: Array<Source>;
2511
2589
  /**
2512
- * Initial completion result. Useful to load an existing history.
2590
+ The tool calls that were made in the last step.
2513
2591
  */
2514
- initialCompletion?: string;
2592
+ readonly toolCalls: ToolCallArray<TOOLS>;
2515
2593
  /**
2516
- * Callback function to be called when the completion is finished streaming.
2594
+ The results of the tool calls from the last step.
2517
2595
  */
2518
- onFinish?: (prompt: string, completion: string) => void;
2596
+ readonly toolResults: ToolResultArray<TOOLS>;
2519
2597
  /**
2520
- * Callback function to be called when an error is encountered.
2598
+ The reason why the generation finished.
2521
2599
  */
2522
- onError?: (error: Error) => void;
2600
+ readonly finishReason: FinishReason;
2523
2601
  /**
2524
- * The credentials mode to be used for the fetch request.
2525
- * Possible values are: 'omit', 'same-origin', 'include'.
2526
- * Defaults to 'same-origin'.
2602
+ The token usage of the last step.
2527
2603
  */
2528
- credentials?: RequestCredentials;
2604
+ readonly usage: LanguageModelUsage;
2529
2605
  /**
2530
- * HTTP headers to be sent with the API request.
2606
+ The total token usage of all steps.
2607
+ When there are multiple steps, the usage is the sum of all step usages.
2531
2608
  */
2532
- headers?: Record<string, string> | Headers;
2609
+ readonly totalUsage: LanguageModelUsage;
2533
2610
  /**
2534
- * Extra body object to be sent with the API request.
2535
- * @example
2536
- * Send a `sessionId` to the API along with the prompt.
2537
- * ```js
2538
- * useChat({
2539
- * body: {
2540
- * sessionId: '123',
2541
- * }
2542
- * })
2543
- * ```
2611
+ Warnings from the model provider (e.g. unsupported settings)
2544
2612
  */
2545
- body?: object;
2613
+ readonly warnings: CallWarning[] | undefined;
2546
2614
  /**
2547
- Streaming protocol that is used. Defaults to `data`.
2548
- */
2549
- streamProtocol?: 'data' | 'text';
2615
+ Additional request information.
2616
+ */
2617
+ readonly request: LanguageModelRequestMetadata;
2550
2618
  /**
2551
- Custom fetch implementation. You can use it as a middleware to intercept requests,
2552
- or to provide a custom fetch implementation for e.g. testing.
2553
- */
2554
- fetch?: FetchFunction;
2555
- };
2556
-
2557
- declare const uiMessageStreamPartSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
2558
- type: z.ZodLiteral<"text">;
2559
- value: z.ZodString;
2560
- }, "strip", z.ZodTypeAny, {
2561
- value: string;
2562
- type: "text";
2563
- }, {
2564
- value: string;
2565
- type: "text";
2566
- }>, z.ZodObject<{
2567
- type: z.ZodLiteral<"error">;
2568
- value: z.ZodString;
2569
- }, "strip", z.ZodTypeAny, {
2570
- value: string;
2571
- type: "error";
2572
- }, {
2573
- value: string;
2574
- type: "error";
2575
- }>, z.ZodObject<{
2576
- type: z.ZodLiteral<"tool-call">;
2577
- value: z.ZodObject<{
2578
- toolCallId: z.ZodString;
2579
- toolName: z.ZodString;
2580
- args: z.ZodUnknown;
2581
- }, "strip", z.ZodTypeAny, {
2582
- toolName: string;
2583
- toolCallId: string;
2584
- args?: unknown;
2585
- }, {
2586
- toolName: string;
2587
- toolCallId: string;
2588
- args?: unknown;
2589
- }>;
2590
- }, "strip", z.ZodTypeAny, {
2591
- value: {
2592
- toolName: string;
2593
- toolCallId: string;
2594
- args?: unknown;
2619
+ Additional response information.
2620
+ */
2621
+ readonly response: LanguageModelResponseMetadata & {
2622
+ /**
2623
+ The response messages that were generated during the call. It consists of an assistant message,
2624
+ potentially containing tool calls.
2625
+
2626
+ When there are tool results, there is an additional tool message with the tool results that are available.
2627
+ If there are tools that do not have execute functions, they are not included in the tool results and
2628
+ need to be added separately.
2629
+ */
2630
+ messages: Array<ResponseMessage>;
2631
+ /**
2632
+ Response body (available only for providers that use HTTP requests).
2633
+ */
2634
+ body?: unknown;
2595
2635
  };
2596
- type: "tool-call";
2597
- }, {
2598
- value: {
2599
- toolName: string;
2600
- toolCallId: string;
2601
- args?: unknown;
2602
- };
2603
- type: "tool-call";
2604
- }>, z.ZodObject<{
2605
- type: z.ZodLiteral<"tool-result">;
2606
- value: z.ZodObject<{
2607
- toolCallId: z.ZodString;
2608
- result: z.ZodUnknown;
2609
- providerMetadata: z.ZodOptional<z.ZodAny>;
2610
- }, "strip", z.ZodTypeAny, {
2611
- toolCallId: string;
2612
- result?: unknown;
2613
- providerMetadata?: any;
2614
- }, {
2615
- toolCallId: string;
2616
- result?: unknown;
2617
- providerMetadata?: any;
2618
- }>;
2619
- }, "strip", z.ZodTypeAny, {
2620
- value: {
2621
- toolCallId: string;
2622
- result?: unknown;
2623
- providerMetadata?: any;
2624
- };
2625
- type: "tool-result";
2626
- }, {
2627
- value: {
2628
- toolCallId: string;
2629
- result?: unknown;
2630
- providerMetadata?: any;
2631
- };
2632
- type: "tool-result";
2633
- }>, z.ZodObject<{
2634
- type: z.ZodLiteral<"tool-call-streaming-start">;
2635
- value: z.ZodObject<{
2636
- toolCallId: z.ZodString;
2637
- toolName: z.ZodString;
2638
- }, "strip", z.ZodTypeAny, {
2639
- toolName: string;
2640
- toolCallId: string;
2641
- }, {
2642
- toolName: string;
2643
- toolCallId: string;
2644
- }>;
2645
- }, "strip", z.ZodTypeAny, {
2646
- value: {
2647
- toolName: string;
2648
- toolCallId: string;
2649
- };
2650
- type: "tool-call-streaming-start";
2651
- }, {
2652
- value: {
2653
- toolName: string;
2654
- toolCallId: string;
2655
- };
2656
- type: "tool-call-streaming-start";
2657
- }>, z.ZodObject<{
2658
- type: z.ZodLiteral<"tool-call-delta">;
2659
- value: z.ZodObject<{
2660
- toolCallId: z.ZodString;
2661
- argsTextDelta: z.ZodString;
2662
- }, "strip", z.ZodTypeAny, {
2663
- toolCallId: string;
2664
- argsTextDelta: string;
2665
- }, {
2666
- toolCallId: string;
2667
- argsTextDelta: string;
2668
- }>;
2669
- }, "strip", z.ZodTypeAny, {
2670
- value: {
2671
- toolCallId: string;
2672
- argsTextDelta: string;
2673
- };
2674
- type: "tool-call-delta";
2675
- }, {
2676
- value: {
2677
- toolCallId: string;
2678
- argsTextDelta: string;
2679
- };
2680
- type: "tool-call-delta";
2681
- }>, z.ZodObject<{
2682
- type: z.ZodLiteral<"reasoning">;
2683
- value: z.ZodObject<{
2684
- text: z.ZodString;
2685
- providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
2686
- }, "strip", z.ZodTypeAny, {
2687
- text: string;
2688
- providerMetadata?: Record<string, any> | undefined;
2689
- }, {
2690
- text: string;
2691
- providerMetadata?: Record<string, any> | undefined;
2692
- }>;
2693
- }, "strip", z.ZodTypeAny, {
2694
- value: {
2695
- text: string;
2696
- providerMetadata?: Record<string, any> | undefined;
2697
- };
2698
- type: "reasoning";
2699
- }, {
2700
- value: {
2701
- text: string;
2702
- providerMetadata?: Record<string, any> | undefined;
2703
- };
2704
- type: "reasoning";
2705
- }>, z.ZodObject<{
2706
- type: z.ZodLiteral<"source">;
2707
- value: z.ZodObject<{
2708
- type: z.ZodLiteral<"source">;
2709
- sourceType: z.ZodLiteral<"url">;
2710
- id: z.ZodString;
2711
- url: z.ZodString;
2712
- title: z.ZodOptional<z.ZodString>;
2713
- providerMetadata: z.ZodOptional<z.ZodAny>;
2714
- }, "strip", z.ZodTypeAny, {
2715
- type: "source";
2716
- id: string;
2717
- url: string;
2718
- sourceType: "url";
2719
- providerMetadata?: any;
2720
- title?: string | undefined;
2721
- }, {
2722
- type: "source";
2723
- id: string;
2724
- url: string;
2725
- sourceType: "url";
2726
- providerMetadata?: any;
2727
- title?: string | undefined;
2728
- }>;
2729
- }, "strip", z.ZodTypeAny, {
2730
- value: {
2731
- type: "source";
2732
- id: string;
2733
- url: string;
2734
- sourceType: "url";
2735
- providerMetadata?: any;
2736
- title?: string | undefined;
2737
- };
2738
- type: "source";
2739
- }, {
2740
- value: {
2741
- type: "source";
2742
- id: string;
2743
- url: string;
2744
- sourceType: "url";
2745
- providerMetadata?: any;
2746
- title?: string | undefined;
2747
- };
2748
- type: "source";
2749
- }>, z.ZodObject<{
2750
- type: z.ZodLiteral<"file">;
2751
- value: z.ZodObject<{
2752
- url: z.ZodString;
2753
- mediaType: z.ZodString;
2754
- }, "strip", z.ZodTypeAny, {
2755
- mediaType: string;
2756
- url: string;
2757
- }, {
2758
- mediaType: string;
2759
- url: string;
2760
- }>;
2761
- }, "strip", z.ZodTypeAny, {
2762
- value: {
2763
- mediaType: string;
2764
- url: string;
2765
- };
2766
- type: "file";
2767
- }, {
2768
- value: {
2769
- mediaType: string;
2770
- url: string;
2771
- };
2772
- type: "file";
2773
- }>, z.ZodObject<{
2774
- type: z.ZodLiteral<"metadata">;
2775
- value: z.ZodObject<{
2776
- metadata: z.ZodUnknown;
2777
- }, "strip", z.ZodTypeAny, {
2778
- metadata?: unknown;
2779
- }, {
2780
- metadata?: unknown;
2781
- }>;
2782
- }, "strip", z.ZodTypeAny, {
2783
- value: {
2784
- metadata?: unknown;
2785
- };
2786
- type: "metadata";
2787
- }, {
2788
- value: {
2789
- metadata?: unknown;
2790
- };
2791
- type: "metadata";
2792
- }>, z.ZodObject<{
2793
- type: z.ZodLiteral<"start-step">;
2794
- value: z.ZodObject<{
2795
- metadata: z.ZodUnknown;
2796
- }, "strip", z.ZodTypeAny, {
2797
- metadata?: unknown;
2798
- }, {
2799
- metadata?: unknown;
2800
- }>;
2801
- }, "strip", z.ZodTypeAny, {
2802
- value: {
2803
- metadata?: unknown;
2804
- };
2805
- type: "start-step";
2806
- }, {
2807
- value: {
2808
- metadata?: unknown;
2809
- };
2810
- type: "start-step";
2811
- }>, z.ZodObject<{
2812
- type: z.ZodLiteral<"finish-step">;
2813
- value: z.ZodObject<{
2814
- metadata: z.ZodUnknown;
2815
- }, "strip", z.ZodTypeAny, {
2816
- metadata?: unknown;
2817
- }, {
2818
- metadata?: unknown;
2819
- }>;
2820
- }, "strip", z.ZodTypeAny, {
2821
- value: {
2822
- metadata?: unknown;
2823
- };
2824
- type: "finish-step";
2825
- }, {
2826
- value: {
2827
- metadata?: unknown;
2828
- };
2829
- type: "finish-step";
2830
- }>, z.ZodObject<{
2831
- type: z.ZodLiteral<"start">;
2832
- value: z.ZodObject<{
2833
- messageId: z.ZodOptional<z.ZodString>;
2834
- metadata: z.ZodUnknown;
2835
- }, "strip", z.ZodTypeAny, {
2836
- metadata?: unknown;
2837
- messageId?: string | undefined;
2838
- }, {
2839
- metadata?: unknown;
2840
- messageId?: string | undefined;
2841
- }>;
2842
- }, "strip", z.ZodTypeAny, {
2843
- value: {
2844
- metadata?: unknown;
2845
- messageId?: string | undefined;
2846
- };
2847
- type: "start";
2848
- }, {
2849
- value: {
2850
- metadata?: unknown;
2851
- messageId?: string | undefined;
2852
- };
2853
- type: "start";
2854
- }>, z.ZodObject<{
2855
- type: z.ZodLiteral<"finish">;
2856
- value: z.ZodObject<{
2857
- metadata: z.ZodUnknown;
2858
- }, "strip", z.ZodTypeAny, {
2859
- metadata?: unknown;
2860
- }, {
2861
- metadata?: unknown;
2862
- }>;
2863
- }, "strip", z.ZodTypeAny, {
2864
- value: {
2865
- metadata?: unknown;
2866
- };
2867
- type: "finish";
2868
- }, {
2869
- value: {
2870
- metadata?: unknown;
2871
- };
2872
- type: "finish";
2873
- }>, z.ZodObject<{
2874
- type: z.ZodLiteral<"reasoning-part-finish">;
2875
- value: z.ZodNull;
2876
- }, "strip", z.ZodTypeAny, {
2877
- value: null;
2878
- type: "reasoning-part-finish";
2879
- }, {
2880
- value: null;
2881
- type: "reasoning-part-finish";
2882
- }>]>;
2883
- type UIMessageStreamPart = z.infer<typeof uiMessageStreamPartSchema>;
2884
-
2885
- interface UIMessageStreamWriter {
2886
2636
  /**
2887
- * Appends a data stream part to the stream.
2637
+ Additional provider-specific metadata. They are passed through
2638
+ from the provider to the AI SDK and enable provider-specific
2639
+ results that can be fully encapsulated in the provider.
2888
2640
  */
2889
- write(part: UIMessageStreamPart): void;
2641
+ readonly providerMetadata: ProviderMetadata | undefined;
2890
2642
  /**
2891
- * Merges the contents of another stream to this stream.
2643
+ Details for all steps.
2644
+ You can use this to get information about intermediate steps,
2645
+ such as the tool calls or the response headers.
2892
2646
  */
2893
- merge(stream: ReadableStream<UIMessageStreamPart>): void;
2647
+ readonly steps: Array<StepResult<TOOLS>>;
2894
2648
  /**
2895
- * Error handler that is used by the data stream writer.
2896
- * This is intended for forwarding when merging streams
2897
- * to prevent duplicated error masking.
2649
+ The generated structured output. It uses the `experimental_output` specification.
2898
2650
  */
2899
- onError: ((error: unknown) => string) | undefined;
2900
- }
2901
-
2902
- declare function createUIMessageStream({ execute, onError, }: {
2903
- execute: (writer: UIMessageStreamWriter) => Promise<void> | void;
2904
- onError?: (error: unknown) => string;
2905
- }): ReadableStream<UIMessageStreamPart>;
2906
-
2907
- declare function createUIMessageStreamResponse({ status, statusText, headers, stream, }: ResponseInit & {
2908
- stream: ReadableStream<UIMessageStreamPart>;
2909
- }): Response;
2910
-
2911
- declare function pipeUIMessageStreamToResponse({ response, status, statusText, headers, stream, }: {
2912
- response: ServerResponse;
2913
- stream: ReadableStream<UIMessageStreamPart>;
2914
- } & ResponseInit): void;
2915
-
2916
- declare class JsonToSseTransformStream extends TransformStream<unknown, string> {
2917
- constructor();
2651
+ readonly experimental_output: OUTPUT;
2918
2652
  }
2919
2653
 
2920
- /**
2921
- * Converts a data URL of type text/* to a text string.
2922
- */
2923
- declare function getTextFromDataUrl(dataUrl: string): string;
2924
-
2925
2654
  /**
2926
2655
  Create a type from an object with all keys and nested keys set to optional.
2927
2656
  The helper supports normal objects and Zod schemas (which are resolved automatically).
@@ -2939,445 +2668,544 @@ type PartialObject<ObjectType extends object> = {
2939
2668
  [KeyType in keyof ObjectType]?: DeepPartialInternal<ObjectType[KeyType]>;
2940
2669
  };
2941
2670
 
2942
- /**
2943
- * Performs a deep-equal comparison of two parsed JSON objects.
2944
- *
2945
- * @param {any} obj1 - The first object to compare.
2946
- * @param {any} obj2 - The second object to compare.
2947
- * @returns {boolean} - Returns true if the two objects are deeply equal, false otherwise.
2948
- */
2949
- declare function isDeepEqualData(obj1: any, obj2: any): boolean;
2671
+ interface Output$1<OUTPUT, PARTIAL> {
2672
+ readonly type: 'object' | 'text';
2673
+ responseFormat: LanguageModelV2CallOptions['responseFormat'];
2674
+ parsePartial(options: {
2675
+ text: string;
2676
+ }): Promise<{
2677
+ partial: PARTIAL;
2678
+ } | undefined>;
2679
+ parseOutput(options: {
2680
+ text: string;
2681
+ }, context: {
2682
+ response: LanguageModelResponseMetadata;
2683
+ usage: LanguageModelUsage;
2684
+ finishReason: FinishReason;
2685
+ }): Promise<OUTPUT>;
2686
+ }
2687
+ declare const text: () => Output$1<string, string>;
2688
+ declare const object: <OUTPUT>({ schema: inputSchema, }: {
2689
+ schema: z.Schema<OUTPUT, z.ZodTypeDef, any> | Schema<OUTPUT>;
2690
+ }) => Output$1<OUTPUT, DeepPartial<OUTPUT>>;
2950
2691
 
2951
- declare function parsePartialJson(jsonText: string | undefined): Promise<{
2952
- value: JSONValue$1 | undefined;
2953
- state: 'undefined-input' | 'successful-parse' | 'repaired-parse' | 'failed-parse';
2954
- }>;
2692
+ declare const output_object: typeof object;
2693
+ declare const output_text: typeof text;
2694
+ declare namespace output {
2695
+ export {
2696
+ Output$1 as Output,
2697
+ output_object as object,
2698
+ output_text as text,
2699
+ };
2700
+ }
2955
2701
 
2956
- /**
2957
- * Calculates the cosine similarity between two vectors. This is a useful metric for
2958
- * comparing the similarity of two vectors such as embeddings.
2959
- *
2960
- * @param vector1 - The first vector.
2961
- * @param vector2 - The second vector.
2962
- *
2963
- * @returns The cosine similarity between vector1 and vector2.
2964
- * @returns 0 if either vector is the zero vector.
2965
- *
2966
- * @throws {InvalidArgumentError} If the vectors do not have the same length.
2967
- */
2968
- declare function cosineSimilarity(vector1: number[], vector2: number[]): number;
2702
+ type StopCondition<TOOLS extends ToolSet> = (options: {
2703
+ steps: Array<StepResult<TOOLS>>;
2704
+ }) => PromiseLike<boolean> | boolean;
2705
+ declare function maxSteps(maxSteps: number): StopCondition<any>;
2706
+ declare function hasToolCall(toolName: string): StopCondition<any>;
2969
2707
 
2970
2708
  /**
2971
- * Creates a ReadableStream that emits the provided values with an optional delay between each value.
2972
- *
2973
- * @param options - The configuration options
2974
- * @param options.chunks - Array of values to be emitted by the stream
2975
- * @param options.initialDelayInMs - Optional initial delay in milliseconds before emitting the first value (default: 0). Can be set to `null` to skip the initial delay. The difference between `initialDelayInMs: null` and `initialDelayInMs: 0` is that `initialDelayInMs: null` will emit the values without any delay, while `initialDelayInMs: 0` will emit the values with a delay of 0 milliseconds.
2976
- * @param options.chunkDelayInMs - Optional delay in milliseconds between emitting each value (default: 0). Can be set to `null` to skip the delay. The difference between `chunkDelayInMs: null` and `chunkDelayInMs: 0` is that `chunkDelayInMs: null` will emit the values without any delay, while `chunkDelayInMs: 0` will emit the values with a delay of 0 milliseconds.
2977
- * @returns A ReadableStream that emits the provided values
2978
- */
2979
- declare function simulateReadableStream<T>({ chunks, initialDelayInMs, chunkDelayInMs, _internal, }: {
2980
- chunks: T[];
2981
- initialDelayInMs?: number | null;
2982
- chunkDelayInMs?: number | null;
2983
- _internal?: {
2984
- delay?: (ms: number | null) => Promise<void>;
2985
- };
2986
- }): ReadableStream<T>;
2709
+ Callback that is set using the `onStepFinish` option.
2987
2710
 
2988
- /**
2989
- The result of an `embed` call.
2990
- It contains the embedding, the value, and additional information.
2711
+ @param stepResult - The result of the step.
2991
2712
  */
2992
- interface EmbedResult<VALUE> {
2993
- /**
2994
- The value that was embedded.
2995
- */
2996
- readonly value: VALUE;
2997
- /**
2998
- The embedding of the value.
2999
- */
3000
- readonly embedding: Embedding;
3001
- /**
3002
- The embedding token usage.
3003
- */
3004
- readonly usage: EmbeddingModelUsage;
3005
- /**
3006
- Optional response data.
3007
- */
3008
- readonly response?: {
3009
- /**
3010
- Response headers.
3011
- */
3012
- headers?: Record<string, string>;
3013
- /**
3014
- The response body.
3015
- */
3016
- body?: unknown;
3017
- };
3018
- }
3019
-
2713
+ type GenerateTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
3020
2714
  /**
3021
- Embed a value using an embedding model. The type of the value is defined by the embedding model.
2715
+ Generate a text and call tools for a given prompt using a language model.
3022
2716
 
3023
- @param model - The embedding model to use.
3024
- @param value - The value that should be embedded.
2717
+ This function does not stream the output. If you want to stream the output, use `streamText` instead.
2718
+
2719
+ @param model - The language model to use.
2720
+
2721
+ @param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
2722
+ @param toolChoice - The tool choice strategy. Default: 'auto'.
2723
+
2724
+ @param system - A system message that will be part of the prompt.
2725
+ @param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
2726
+ @param messages - A list of messages. You can either use `prompt` or `messages` but not both.
2727
+
2728
+ @param maxOutputTokens - Maximum number of tokens to generate.
2729
+ @param temperature - Temperature setting.
2730
+ The value is passed through to the provider. The range depends on the provider and model.
2731
+ It is recommended to set either `temperature` or `topP`, but not both.
2732
+ @param topP - Nucleus sampling.
2733
+ The value is passed through to the provider. The range depends on the provider and model.
2734
+ It is recommended to set either `temperature` or `topP`, but not both.
2735
+ @param topK - Only sample from the top K options for each subsequent token.
2736
+ Used to remove "long tail" low probability responses.
2737
+ Recommended for advanced use cases only. You usually only need to use temperature.
2738
+ @param presencePenalty - Presence penalty setting.
2739
+ It affects the likelihood of the model to repeat information that is already in the prompt.
2740
+ The value is passed through to the provider. The range depends on the provider and model.
2741
+ @param frequencyPenalty - Frequency penalty setting.
2742
+ It affects the likelihood of the model to repeatedly use the same words or phrases.
2743
+ The value is passed through to the provider. The range depends on the provider and model.
2744
+ @param stopSequences - Stop sequences.
2745
+ If set, the model will stop generating text when one of the stop sequences is generated.
2746
+ @param seed - The seed (integer) to use for random sampling.
2747
+ If set and supported by the model, calls will generate deterministic results.
3025
2748
 
3026
2749
  @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
3027
2750
  @param abortSignal - An optional abort signal that can be used to cancel the call.
3028
2751
  @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
3029
2752
 
3030
- @returns A result object that contains the embedding, the value, and additional information.
2753
+ @param experimental_generateMessageId - Generate a unique ID for each message.
2754
+
2755
+ @param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
2756
+
2757
+ @returns
2758
+ A result object that contains the generated text, the results of the tool calls, and additional information.
3031
2759
  */
3032
- declare function embed<VALUE>({ model, value, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, experimental_telemetry: telemetry, }: {
3033
- /**
3034
- The embedding model to use.
3035
- */
3036
- model: EmbeddingModel<VALUE>;
2760
+ declare function generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, headers, continueUntil, experimental_output: output, experimental_telemetry: telemetry, providerOptions, experimental_activeTools: activeTools, experimental_prepareStep: prepareStep, experimental_repairToolCall: repairToolCall, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
3037
2761
  /**
3038
- The value that should be embedded.
2762
+ The language model to use.
3039
2763
  */
3040
- value: VALUE;
2764
+ model: LanguageModel;
3041
2765
  /**
3042
- Maximum number of retries per embedding model call. Set to 0 to disable retries.
3043
-
3044
- @default 2
3045
- */
3046
- maxRetries?: number;
2766
+ The tools that the model can call. The model needs to support calling tools.
2767
+ */
2768
+ tools?: TOOLS;
3047
2769
  /**
3048
- Abort signal.
3049
- */
3050
- abortSignal?: AbortSignal;
2770
+ The tool choice strategy. Default: 'auto'.
2771
+ */
2772
+ toolChoice?: ToolChoice<NoInfer<TOOLS>>;
2773
+ continueUntil?: StopCondition<NoInfer<TOOLS>>;
3051
2774
  /**
3052
- Additional headers to include in the request.
3053
- Only applicable for HTTP-based providers.
3054
- */
3055
- headers?: Record<string, string>;
2775
+ Optional telemetry configuration (experimental).
2776
+ */
2777
+ experimental_telemetry?: TelemetrySettings;
3056
2778
  /**
3057
- Additional provider-specific options. They are passed through
3058
- to the provider from the AI SDK and enable provider-specific
3059
- functionality that can be fully encapsulated in the provider.
3060
- */
2779
+ Additional provider-specific options. They are passed through
2780
+ to the provider from the AI SDK and enable provider-specific
2781
+ functionality that can be fully encapsulated in the provider.
2782
+ */
3061
2783
  providerOptions?: ProviderOptions;
3062
2784
  /**
3063
- * Optional telemetry configuration (experimental).
2785
+ Limits the tools that are available for the model to call without
2786
+ changing the tool call and result types in the result.
3064
2787
  */
3065
- experimental_telemetry?: TelemetrySettings;
3066
- }): Promise<EmbedResult<VALUE>>;
3067
-
3068
- /**
3069
- The result of a `embedMany` call.
3070
- It contains the embeddings, the values, and additional information.
3071
- */
3072
- interface EmbedManyResult<VALUE> {
2788
+ experimental_activeTools?: Array<keyof NoInfer<TOOLS>>;
3073
2789
  /**
3074
- The values that were embedded.
3075
- */
3076
- readonly values: Array<VALUE>;
2790
+ Optional specification for parsing structured outputs from the LLM response.
2791
+ */
2792
+ experimental_output?: Output$1<OUTPUT, OUTPUT_PARTIAL>;
3077
2793
  /**
3078
- The embeddings. They are in the same order as the values.
3079
- */
3080
- readonly embeddings: Array<Embedding>;
2794
+ Optional function that you can use to provide different settings for a step.
2795
+
2796
+ @param options - The options for the step.
2797
+ @param options.steps - The steps that have been executed so far.
2798
+ @param options.stepNumber - The number of the step that is being executed.
2799
+ @param options.model - The model that is being used.
2800
+
2801
+ @returns An object that contains the settings for the step.
2802
+ If you return undefined (or for undefined settings), the settings from the outer level will be used.
2803
+ */
2804
+ experimental_prepareStep?: (options: {
2805
+ steps: Array<StepResult<NoInfer<TOOLS>>>;
2806
+ stepNumber: number;
2807
+ model: LanguageModel;
2808
+ }) => PromiseLike<{
2809
+ model?: LanguageModel;
2810
+ toolChoice?: ToolChoice<NoInfer<TOOLS>>;
2811
+ experimental_activeTools?: Array<keyof NoInfer<TOOLS>>;
2812
+ } | undefined>;
3081
2813
  /**
3082
- The embedding token usage.
3083
- */
3084
- readonly usage: EmbeddingModelUsage;
2814
+ A function that attempts to repair a tool call that failed to parse.
2815
+ */
2816
+ experimental_repairToolCall?: ToolCallRepairFunction<NoInfer<TOOLS>>;
3085
2817
  /**
3086
- Optional raw response data.
3087
- */
3088
- readonly responses?: Array<{
3089
- /**
3090
- Response headers.
3091
- */
3092
- headers?: Record<string, string>;
3093
- /**
3094
- The response body.
2818
+ Callback that is called when each step (LLM call) is finished, including intermediate steps.
3095
2819
  */
3096
- body?: unknown;
3097
- } | undefined>;
3098
- }
3099
-
3100
- /**
3101
- Embed several values using an embedding model. The type of the value is defined
3102
- by the embedding model.
3103
-
3104
- `embedMany` automatically splits large requests into smaller chunks if the model
3105
- has a limit on how many embeddings can be generated in a single call.
3106
-
3107
- @param model - The embedding model to use.
3108
- @param values - The values that should be embedded.
2820
+ onStepFinish?: GenerateTextOnStepFinishCallback<NoInfer<TOOLS>>;
2821
+ /**
2822
+ * Internal. For test use only. May change without notice.
2823
+ */
2824
+ _internal?: {
2825
+ generateId?: IdGenerator;
2826
+ currentDate?: () => Date;
2827
+ };
2828
+ }): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
3109
2829
 
3110
- @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
3111
- @param abortSignal - An optional abort signal that can be used to cancel the call.
3112
- @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
2830
+ type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
3113
2831
 
3114
- @returns A result object that contains the embeddings, the value, and additional information.
3115
- */
3116
- declare function embedMany<VALUE>({ model, values, maxParallelCalls, maxRetries: maxRetriesArg, abortSignal, headers, providerOptions, experimental_telemetry: telemetry, }: {
2832
+ type UIMessageStreamOptions = {
3117
2833
  /**
3118
- The embedding model to use.
3119
- */
3120
- model: EmbeddingModel<VALUE>;
2834
+ * Message ID that is sent to the client if a new message is created.
2835
+ * This is intended to be used for the UI message,
2836
+ * if the last original message is not an assistant message
2837
+ * (in which case that message ID is used).
2838
+ */
2839
+ newMessageId?: string;
3121
2840
  /**
3122
- The values that should be embedded.
2841
+ * The original messages.
3123
2842
  */
3124
- values: Array<VALUE>;
2843
+ originalMessages?: UIMessage[];
2844
+ onFinish?: (options: {
2845
+ /**
2846
+ * The updates list of UI messages.
2847
+ */
2848
+ messages: UIMessage[];
2849
+ /**
2850
+ * Indicates whether the response message is a continuation of the last original message,
2851
+ * or if a new message was created.
2852
+ */
2853
+ isContinuation: boolean;
2854
+ /**
2855
+ * The message that was sent to the client as a response
2856
+ * (including the original message if it was extended).
2857
+ */
2858
+ responseMessage: UIMessage;
2859
+ }) => void;
3125
2860
  /**
3126
- Maximum number of retries per embedding model call. Set to 0 to disable retries.
3127
-
3128
- @default 2
2861
+ * Extracts message metadata that will be send to the client.
2862
+ *
2863
+ * Called on `start` and `finish` events.
3129
2864
  */
3130
- maxRetries?: number;
2865
+ messageMetadata?: (options: {
2866
+ part: TextStreamPart<ToolSet> & {
2867
+ type: 'start' | 'finish' | 'start-step' | 'finish-step';
2868
+ };
2869
+ }) => unknown;
3131
2870
  /**
3132
- Abort signal.
3133
- */
3134
- abortSignal?: AbortSignal;
2871
+ * Send reasoning parts to the client.
2872
+ * Default to false.
2873
+ */
2874
+ sendReasoning?: boolean;
3135
2875
  /**
3136
- Additional headers to include in the request.
3137
- Only applicable for HTTP-based providers.
3138
- */
3139
- headers?: Record<string, string>;
2876
+ * Send source parts to the client.
2877
+ * Default to false.
2878
+ */
2879
+ sendSources?: boolean;
3140
2880
  /**
3141
- * Optional telemetry configuration (experimental).
2881
+ * Send the finish event to the client.
2882
+ * Set to false if you are using additional streamText calls
2883
+ * that send additional data.
2884
+ * Default to true.
3142
2885
  */
3143
- experimental_telemetry?: TelemetrySettings;
2886
+ experimental_sendFinish?: boolean;
3144
2887
  /**
3145
- Additional provider-specific options. They are passed through
3146
- to the provider from the AI SDK and enable provider-specific
3147
- functionality that can be fully encapsulated in the provider.
3148
- */
3149
- providerOptions?: ProviderOptions;
2888
+ * Send the message start event to the client.
2889
+ * Set to false if you are using additional streamText calls
2890
+ * and the message start event has already been sent.
2891
+ * Default to true.
2892
+ *
2893
+ * Note: this setting is currently not used, but you should
2894
+ * already set it to false if you are using additional
2895
+ * streamText calls that send additional data to prevent
2896
+ * the message start event from being sent multiple times.
2897
+ */
2898
+ experimental_sendStart?: boolean;
3150
2899
  /**
3151
- * Maximum number of concurrent requests.
2900
+ * Process an error, e.g. to log it. Default to `() => 'An error occurred.'`.
3152
2901
  *
3153
- * @default Infinity
2902
+ * @return error message to include in the data stream.
3154
2903
  */
3155
- maxParallelCalls?: number;
3156
- }): Promise<EmbedManyResult<VALUE>>;
3157
-
2904
+ onError?: (error: unknown) => string;
2905
+ };
2906
+ type ConsumeStreamOptions = {
2907
+ onError?: (error: unknown) => void;
2908
+ };
3158
2909
  /**
3159
- A message that was generated during the generation process.
3160
- It can be either an assistant message or a tool message.
3161
- */
3162
- type ResponseMessage = AssistantModelMessage | ToolModelMessage;
3163
-
3164
- /**
3165
- * The result of a single step in the generation process.
2910
+ A result object for accessing different stream types and additional information.
3166
2911
  */
3167
- type StepResult<TOOLS extends ToolSet> = {
2912
+ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
3168
2913
  /**
3169
2914
  The content that was generated in the last step.
2915
+
2916
+ Resolved when the response is finished.
3170
2917
  */
3171
- readonly content: Array<ContentPart<TOOLS>>;
3172
- /**
3173
- The generated text.
3174
- */
3175
- readonly text: string;
3176
- /**
3177
- The reasoning that was generated during the generation.
3178
- */
3179
- readonly reasoning: Array<ReasoningPart>;
3180
- /**
3181
- The reasoning text that was generated during the generation.
3182
- */
3183
- readonly reasoningText: string | undefined;
3184
- /**
3185
- The files that were generated during the generation.
3186
- */
3187
- readonly files: Array<GeneratedFile>;
3188
- /**
3189
- The sources that were used to generate the text.
3190
- */
3191
- readonly sources: Array<Source>;
3192
- /**
3193
- The tool calls that were made during the generation.
3194
- */
3195
- readonly toolCalls: ToolCallArray<TOOLS>;
3196
- /**
3197
- The results of the tool calls.
3198
- */
3199
- readonly toolResults: ToolResultArray<TOOLS>;
3200
- /**
3201
- The reason why the generation finished.
3202
- */
3203
- readonly finishReason: FinishReason;
3204
- /**
3205
- The token usage of the generated text.
3206
- */
3207
- readonly usage: LanguageModelUsage;
2918
+ readonly content: Promise<Array<ContentPart<TOOLS>>>;
3208
2919
  /**
3209
- Warnings from the model provider (e.g. unsupported settings).
3210
- */
3211
- readonly warnings: CallWarning[] | undefined;
2920
+ The full text that has been generated by the last step.
2921
+
2922
+ Resolved when the response is finished.
2923
+ */
2924
+ readonly text: Promise<string>;
3212
2925
  /**
3213
- Additional request information.
2926
+ The full reasoning that the model has generated.
2927
+
2928
+ Resolved when the response is finished.
3214
2929
  */
3215
- readonly request: LanguageModelRequestMetadata;
2930
+ readonly reasoning: Promise<Array<ReasoningPart>>;
3216
2931
  /**
3217
- Additional response information.
3218
- */
3219
- readonly response: LanguageModelResponseMetadata & {
3220
- /**
3221
- The response messages that were generated during the call.
3222
- Response messages can be either assistant messages or tool messages.
3223
- They contain a generated id.
3224
- */
3225
- readonly messages: Array<ResponseMessage>;
3226
- /**
3227
- Response body (available only for providers that use HTTP requests).
3228
- */
3229
- body?: unknown;
3230
- };
2932
+ The reasoning that has been generated by the last step.
2933
+
2934
+ Resolved when the response is finished.
2935
+ */
2936
+ readonly reasoningText: Promise<string | undefined>;
3231
2937
  /**
3232
- Additional provider-specific metadata. They are passed through
3233
- from the provider to the AI SDK and enable provider-specific
3234
- results that can be fully encapsulated in the provider.
2938
+ Files that have been generated by the model in the last step.
2939
+
2940
+ Resolved when the response is finished.
3235
2941
  */
3236
- readonly providerMetadata: ProviderMetadata | undefined;
3237
- };
3238
-
3239
- /**
3240
- The result of a `generateText` call.
3241
- It contains the generated text, the tool calls that were made during the generation, and the results of the tool calls.
3242
- */
3243
- interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT> {
2942
+ readonly files: Promise<GeneratedFile[]>;
3244
2943
  /**
3245
- The content that was generated in the last step.
2944
+ Sources that have been used as references in the last step.
2945
+
2946
+ Resolved when the response is finished.
3246
2947
  */
3247
- readonly content: Array<ContentPart<TOOLS>>;
2948
+ readonly sources: Promise<Source[]>;
3248
2949
  /**
3249
- The text that was generated in the last step.
2950
+ The tool calls that have been executed in the last step.
2951
+
2952
+ Resolved when the response is finished.
3250
2953
  */
3251
- readonly text: string;
2954
+ readonly toolCalls: Promise<ToolCallUnion<TOOLS>[]>;
3252
2955
  /**
3253
- The full reasoning that the model has generated in the last step.
2956
+ The tool results that have been generated in the last step.
2957
+
2958
+ Resolved when the all tool executions are finished.
3254
2959
  */
3255
- readonly reasoning: Array<ReasoningPart>;
2960
+ readonly toolResults: Promise<ToolResultUnion<TOOLS>[]>;
3256
2961
  /**
3257
- The reasoning text that the model has generated in the last step. Can be undefined if the model
3258
- has only generated text.
2962
+ The reason why the generation finished. Taken from the last step.
2963
+
2964
+ Resolved when the response is finished.
2965
+ */
2966
+ readonly finishReason: Promise<FinishReason>;
2967
+ /**
2968
+ The token usage of the last step.
2969
+
2970
+ Resolved when the response is finished.
3259
2971
  */
3260
- readonly reasoningText: string | undefined;
2972
+ readonly usage: Promise<LanguageModelUsage>;
3261
2973
  /**
3262
- The files that were generated in the last step.
3263
- Empty array if no files were generated.
2974
+ The total token usage of the generated response.
2975
+ When there are multiple steps, the usage is the sum of all step usages.
2976
+
2977
+ Resolved when the response is finished.
3264
2978
  */
3265
- readonly files: Array<GeneratedFile>;
2979
+ readonly totalUsage: Promise<LanguageModelUsage>;
3266
2980
  /**
3267
- Sources that have been used as references in the last step.
3268
- */
3269
- readonly sources: Array<Source>;
2981
+ Warnings from the model provider (e.g. unsupported settings) for the first step.
2982
+ */
2983
+ readonly warnings: Promise<CallWarning[] | undefined>;
3270
2984
  /**
3271
- The tool calls that were made in the last step.
2985
+ Details for all steps.
2986
+ You can use this to get information about intermediate steps,
2987
+ such as the tool calls or the response headers.
3272
2988
  */
3273
- readonly toolCalls: ToolCallArray<TOOLS>;
2989
+ readonly steps: Promise<Array<StepResult<TOOLS>>>;
3274
2990
  /**
3275
- The results of the tool calls from the last step.
3276
- */
3277
- readonly toolResults: ToolResultArray<TOOLS>;
2991
+ Additional request information from the last step.
2992
+ */
2993
+ readonly request: Promise<LanguageModelRequestMetadata>;
3278
2994
  /**
3279
- The reason why the generation finished.
3280
- */
3281
- readonly finishReason: FinishReason;
2995
+ Additional response information from the last step.
2996
+ */
2997
+ readonly response: Promise<LanguageModelResponseMetadata & {
2998
+ /**
2999
+ The response messages that were generated during the call. It consists of an assistant message,
3000
+ potentially containing tool calls.
3001
+
3002
+ When there are tool results, there is an additional tool message with the tool results that are available.
3003
+ If there are tools that do not have execute functions, they are not included in the tool results and
3004
+ need to be added separately.
3005
+ */
3006
+ messages: Array<ResponseMessage>;
3007
+ }>;
3282
3008
  /**
3283
- The token usage of the last step.
3009
+ Additional provider-specific metadata from the last step.
3010
+ Metadata is passed through from the provider to the AI SDK and
3011
+ enables provider-specific results that can be fully encapsulated in the provider.
3284
3012
  */
3285
- readonly usage: LanguageModelUsage;
3013
+ readonly providerMetadata: Promise<ProviderMetadata | undefined>;
3286
3014
  /**
3287
- The total token usage of all steps.
3288
- When there are multiple steps, the usage is the sum of all step usages.
3289
- */
3290
- readonly totalUsage: LanguageModelUsage;
3015
+ A text stream that returns only the generated text deltas. You can use it
3016
+ as either an AsyncIterable or a ReadableStream. When an error occurs, the
3017
+ stream will throw the error.
3018
+ */
3019
+ readonly textStream: AsyncIterableStream<string>;
3291
3020
  /**
3292
- Warnings from the model provider (e.g. unsupported settings)
3293
- */
3294
- readonly warnings: CallWarning[] | undefined;
3021
+ A stream with all events, including text deltas, tool calls, tool results, and
3022
+ errors.
3023
+ You can use it as either an AsyncIterable or a ReadableStream.
3024
+ Only errors that stop the stream, such as network errors, are thrown.
3025
+ */
3026
+ readonly fullStream: AsyncIterableStream<TextStreamPart<TOOLS>>;
3295
3027
  /**
3296
- Additional request information.
3028
+ A stream of partial outputs. It uses the `experimental_output` specification.
3297
3029
  */
3298
- readonly request: LanguageModelRequestMetadata;
3030
+ readonly experimental_partialOutputStream: AsyncIterableStream<PARTIAL_OUTPUT>;
3299
3031
  /**
3300
- Additional response information.
3301
- */
3302
- readonly response: LanguageModelResponseMetadata & {
3303
- /**
3304
- The response messages that were generated during the call. It consists of an assistant message,
3305
- potentially containing tool calls.
3306
-
3307
- When there are tool results, there is an additional tool message with the tool results that are available.
3308
- If there are tools that do not have execute functions, they are not included in the tool results and
3309
- need to be added separately.
3310
- */
3311
- messages: Array<ResponseMessage>;
3312
- /**
3313
- Response body (available only for providers that use HTTP requests).
3314
- */
3315
- body?: unknown;
3316
- };
3032
+ Consumes the stream without processing the parts.
3033
+ This is useful to force the stream to finish.
3034
+ It effectively removes the backpressure and allows the stream to finish,
3035
+ triggering the `onFinish` callback and the promise resolution.
3036
+
3037
+ If an error occurs, it is passed to the optional `onError` callback.
3038
+ */
3039
+ consumeStream(options?: ConsumeStreamOptions): Promise<void>;
3317
3040
  /**
3318
- Additional provider-specific metadata. They are passed through
3319
- from the provider to the AI SDK and enable provider-specific
3320
- results that can be fully encapsulated in the provider.
3321
- */
3322
- readonly providerMetadata: ProviderMetadata | undefined;
3041
+ Converts the result to a UI message stream.
3042
+
3043
+ @param options.getErrorMessage an optional function that converts an error to an error message.
3044
+ @param options.sendUsage whether to send the usage information to the client. Defaults to true.
3045
+ @param options.sendReasoning whether to send the reasoning information to the client. Defaults to false.
3046
+ @param options.sendSources whether to send the sources information to the client. Defaults to false.
3047
+ @param options.experimental_sendFinish whether to send the finish information to the client. Defaults to true.
3048
+ @param options.experimental_sendStart whether to send the start information to the client. Defaults to true.
3049
+
3050
+ @return A UI message stream.
3051
+ */
3052
+ toUIMessageStream(options?: UIMessageStreamOptions): ReadableStream<UIMessageStreamPart>;
3323
3053
  /**
3324
- Details for all steps.
3325
- You can use this to get information about intermediate steps,
3326
- such as the tool calls or the response headers.
3327
- */
3328
- readonly steps: Array<StepResult<TOOLS>>;
3054
+ Writes UI message stream output to a Node.js response-like object.
3055
+ @param response A Node.js response-like object (ServerResponse).
3056
+ @param options.status The status code.
3057
+ @param options.statusText The status text.
3058
+ @param options.headers The headers.
3059
+ @param options.getErrorMessage An optional function that converts an error to an error message.
3060
+ @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
3061
+ @param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
3062
+ */
3063
+ pipeUIMessageStreamToResponse(response: ServerResponse, options?: ResponseInit & UIMessageStreamOptions): void;
3329
3064
  /**
3330
- The generated structured output. It uses the `experimental_output` specification.
3331
- */
3332
- readonly experimental_output: OUTPUT;
3065
+ Writes text delta output to a Node.js response-like object.
3066
+ It sets a `Content-Type` header to `text/plain; charset=utf-8` and
3067
+ writes each text delta as a separate chunk.
3068
+ @param response A Node.js response-like object (ServerResponse).
3069
+ @param init Optional headers, status code, and status text.
3070
+ */
3071
+ pipeTextStreamToResponse(response: ServerResponse, init?: ResponseInit): void;
3072
+ /**
3073
+ Converts the result to a streamed response object with a stream data part stream.
3074
+
3075
+ @param options.status The status code.
3076
+ @param options.statusText The status text.
3077
+ @param options.headers The headers.
3078
+ @param options.getErrorMessage An optional function that converts an error to an error message.
3079
+ @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
3080
+ @param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
3081
+ @return A response object.
3082
+ */
3083
+ toUIMessageStreamResponse(options?: ResponseInit & UIMessageStreamOptions): Response;
3084
+ /**
3085
+ Creates a simple text stream response.
3086
+ Each text delta is encoded as UTF-8 and sent as a separate chunk.
3087
+ Non-text-delta events are ignored.
3088
+ @param init Optional headers, status code, and status text.
3089
+ */
3090
+ toTextStreamResponse(init?: ResponseInit): Response;
3333
3091
  }
3092
+ type TextStreamPart<TOOLS extends ToolSet> = ContentPart<TOOLS> | {
3093
+ type: 'reasoning-part-finish';
3094
+ } | {
3095
+ type: 'tool-call-streaming-start';
3096
+ toolCallId: string;
3097
+ toolName: string;
3098
+ } | {
3099
+ type: 'tool-call-delta';
3100
+ toolCallId: string;
3101
+ toolName: string;
3102
+ argsTextDelta: string;
3103
+ } | {
3104
+ type: 'start-step';
3105
+ request: LanguageModelRequestMetadata;
3106
+ warnings: CallWarning[];
3107
+ } | {
3108
+ type: 'finish-step';
3109
+ response: LanguageModelResponseMetadata;
3110
+ usage: LanguageModelUsage;
3111
+ finishReason: FinishReason;
3112
+ providerMetadata: ProviderMetadata | undefined;
3113
+ } | {
3114
+ type: 'start';
3115
+ } | {
3116
+ type: 'finish';
3117
+ finishReason: FinishReason;
3118
+ totalUsage: LanguageModelUsage;
3119
+ } | {
3120
+ type: 'error';
3121
+ error: unknown;
3122
+ };
3334
3123
 
3335
- interface Output$1<OUTPUT, PARTIAL> {
3336
- readonly type: 'object' | 'text';
3337
- responseFormat: LanguageModelV2CallOptions['responseFormat'];
3338
- parsePartial(options: {
3339
- text: string;
3340
- }): Promise<{
3341
- partial: PARTIAL;
3342
- } | undefined>;
3343
- parseOutput(options: {
3344
- text: string;
3345
- }, context: {
3346
- response: LanguageModelResponseMetadata;
3347
- usage: LanguageModelUsage;
3348
- finishReason: FinishReason;
3349
- }): Promise<OUTPUT>;
3350
- }
3351
- declare const text: () => Output$1<string, string>;
3352
- declare const object: <OUTPUT>({ schema: inputSchema, }: {
3353
- schema: z.Schema<OUTPUT, z.ZodTypeDef, any> | Schema<OUTPUT>;
3354
- }) => Output$1<OUTPUT, DeepPartial<OUTPUT>>;
3124
+ /**
3125
+ * Detects the first chunk in a buffer.
3126
+ *
3127
+ * @param buffer - The buffer to detect the first chunk in.
3128
+ *
3129
+ * @returns The first detected chunk, or `undefined` if no chunk was detected.
3130
+ */
3131
+ type ChunkDetector = (buffer: string) => string | undefined | null;
3132
+ /**
3133
+ * Smooths text streaming output.
3134
+ *
3135
+ * @param delayInMs - The delay in milliseconds between each chunk. Defaults to 10ms. Can be set to `null` to skip the delay.
3136
+ * @param chunking - Controls how the text is chunked for streaming. Use "word" to stream word by word (default), "line" to stream line by line, or provide a custom RegExp pattern for custom chunking.
3137
+ *
3138
+ * @returns A transform stream that smooths text streaming output.
3139
+ */
3140
+ declare function smoothStream<TOOLS extends ToolSet>({ delayInMs, chunking, _internal: { delay }, }?: {
3141
+ delayInMs?: number | null;
3142
+ chunking?: 'word' | 'line' | RegExp | ChunkDetector;
3143
+ /**
3144
+ * Internal. For test use only. May change without notice.
3145
+ */
3146
+ _internal?: {
3147
+ delay?: (delayInMs: number | null) => Promise<void>;
3148
+ };
3149
+ }): (options: {
3150
+ tools: TOOLS;
3151
+ }) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
3355
3152
 
3356
- declare const output_object: typeof object;
3357
- declare const output_text: typeof text;
3358
- declare namespace output {
3359
- export {
3360
- Output$1 as Output,
3361
- output_object as object,
3362
- output_text as text,
3363
- };
3364
- }
3153
+ /**
3154
+ A transformation that is applied to the stream.
3155
+
3156
+ @param stopStream - A function that stops the source stream.
3157
+ @param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
3158
+ */
3159
+ type StreamTextTransform<TOOLS extends ToolSet> = (options: {
3160
+ tools: TOOLS;
3161
+ stopStream: () => void;
3162
+ }) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
3163
+ /**
3164
+ Callback that is set using the `onError` option.
3365
3165
 
3166
+ @param event - The event that is passed to the callback.
3167
+ */
3168
+ type StreamTextOnErrorCallback = (event: {
3169
+ error: unknown;
3170
+ }) => Promise<void> | void;
3366
3171
  /**
3367
3172
  Callback that is set using the `onStepFinish` option.
3368
3173
 
3369
3174
  @param stepResult - The result of the step.
3370
3175
  */
3371
- type GenerateTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
3176
+ type StreamTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
3177
+ /**
3178
+ Callback that is set using the `onChunk` option.
3179
+
3180
+ @param event - The event that is passed to the callback.
3181
+ */
3182
+ type StreamTextOnChunkCallback<TOOLS extends ToolSet> = (event: {
3183
+ chunk: Extract<TextStreamPart<TOOLS>, {
3184
+ type: 'text' | 'reasoning' | 'source' | 'tool-call' | 'tool-call-streaming-start' | 'tool-call-delta' | 'tool-result';
3185
+ }>;
3186
+ }) => Promise<void> | void;
3187
+ /**
3188
+ Callback that is set using the `onFinish` option.
3189
+
3190
+ @param event - The event that is passed to the callback.
3191
+ */
3192
+ type StreamTextOnFinishCallback<TOOLS extends ToolSet> = (event: StepResult<TOOLS> & {
3193
+ /**
3194
+ Details for all steps.
3195
+ */
3196
+ readonly steps: StepResult<TOOLS>[];
3197
+ /**
3198
+ Total usage for all steps. This is the sum of the usage of all steps.
3199
+ */
3200
+ readonly totalUsage: LanguageModelUsage;
3201
+ }) => Promise<void> | void;
3372
3202
  /**
3373
3203
  Generate a text and call tools for a given prompt using a language model.
3374
3204
 
3375
- This function does not stream the output. If you want to stream the output, use `streamText` instead.
3205
+ This function streams the output. If you do not want to stream the output, use `generateText` instead.
3376
3206
 
3377
3207
  @param model - The language model to use.
3378
-
3379
3208
  @param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
3380
- @param toolChoice - The tool choice strategy. Default: 'auto'.
3381
3209
 
3382
3210
  @param system - A system message that will be part of the prompt.
3383
3211
  @param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
@@ -3409,21 +3237,24 @@ If set and supported by the model, calls will generate deterministic results.
3409
3237
  @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
3410
3238
 
3411
3239
  @param maxSteps - Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
3412
- @param experimental_generateMessageId - Generate a unique ID for each message.
3413
3240
 
3241
+ @param onChunk - Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
3242
+ @param onError - Callback that is called when an error occurs during streaming. You can use it to log errors.
3414
3243
  @param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
3244
+ @param onFinish - Callback that is called when the LLM response and all request tool executions
3245
+ (for tools that have an `execute` function) are finished.
3415
3246
 
3416
- @returns
3417
- A result object that contains the generated text, the results of the tool calls, and additional information.
3247
+ @return
3248
+ A result object for accessing different stream types and additional information.
3418
3249
  */
3419
- declare function generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, headers, maxSteps, experimental_output: output, experimental_telemetry: telemetry, providerOptions, experimental_activeTools: activeTools, experimental_prepareStep: prepareStep, experimental_repairToolCall: repairToolCall, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
3250
+ declare function streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, maxSteps, experimental_output: output, experimental_telemetry: telemetry, providerOptions, experimental_toolCallStreaming, toolCallStreaming, experimental_activeTools: activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, onChunk, onError, onFinish, onStepFinish, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
3420
3251
  /**
3421
3252
  The language model to use.
3422
3253
  */
3423
3254
  model: LanguageModel;
3424
3255
  /**
3425
3256
  The tools that the model can call. The model needs to support calling tools.
3426
- */
3257
+ */
3427
3258
  tools?: TOOLS;
3428
3259
  /**
3429
3260
  The tool choice strategy. Default: 'auto'.
@@ -3435,7 +3266,7 @@ Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Mu
3435
3266
  A maximum number is required to prevent infinite loops in the case of misconfigured tools.
3436
3267
 
3437
3268
  By default, it's set to 1, which means that only a single LLM call is made.
3438
- */
3269
+ */
3439
3270
  maxSteps?: number;
3440
3271
  /**
3441
3272
  Optional telemetry configuration (experimental).
@@ -3455,422 +3286,223 @@ changing the tool call and result types in the result.
3455
3286
  /**
3456
3287
  Optional specification for parsing structured outputs from the LLM response.
3457
3288
  */
3458
- experimental_output?: Output$1<OUTPUT, OUTPUT_PARTIAL>;
3459
- /**
3460
- Optional function that you can use to provide different settings for a step.
3461
-
3462
- @param options - The options for the step.
3463
- @param options.steps - The steps that have been executed so far.
3464
- @param options.stepNumber - The number of the step that is being executed.
3465
- @param options.maxSteps - The maximum number of steps.
3466
- @param options.model - The model that is being used.
3467
-
3468
- @returns An object that contains the settings for the step.
3469
- If you return undefined (or for undefined settings), the settings from the outer level will be used.
3470
- */
3471
- experimental_prepareStep?: (options: {
3472
- steps: Array<StepResult<TOOLS>>;
3473
- stepNumber: number;
3474
- maxSteps: number;
3475
- model: LanguageModel;
3476
- }) => PromiseLike<{
3477
- model?: LanguageModel;
3478
- toolChoice?: ToolChoice<TOOLS>;
3479
- experimental_activeTools?: Array<keyof TOOLS>;
3480
- } | undefined>;
3289
+ experimental_output?: Output$1<OUTPUT, PARTIAL_OUTPUT>;
3481
3290
  /**
3482
3291
  A function that attempts to repair a tool call that failed to parse.
3483
3292
  */
3484
3293
  experimental_repairToolCall?: ToolCallRepairFunction<TOOLS>;
3485
3294
  /**
3486
- Callback that is called when each step (LLM call) is finished, including intermediate steps.
3295
+ Enable streaming of tool call deltas as they are generated. Disabled by default.
3296
+ */
3297
+ toolCallStreaming?: boolean;
3298
+ /**
3299
+ @deprecated Use `toolCallStreaming` instead.
3300
+ */
3301
+ experimental_toolCallStreaming?: boolean;
3302
+ /**
3303
+ Optional stream transformations.
3304
+ They are applied in the order they are provided.
3305
+ The stream transformations must maintain the stream structure for streamText to work correctly.
3306
+ */
3307
+ experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
3308
+ /**
3309
+ Callback that is called for each chunk of the stream.
3310
+ The stream processing will pause until the callback promise is resolved.
3311
+ */
3312
+ onChunk?: StreamTextOnChunkCallback<TOOLS>;
3313
+ /**
3314
+ Callback that is invoked when an error occurs during streaming.
3315
+ You can use it to log errors.
3316
+ The stream processing will pause until the callback promise is resolved.
3317
+ */
3318
+ onError?: StreamTextOnErrorCallback;
3319
+ /**
3320
+ Callback that is called when the LLM response and all request tool executions
3321
+ (for tools that have an `execute` function) are finished.
3322
+
3323
+ The usage is the combined usage of all steps.
3324
+ */
3325
+ onFinish?: StreamTextOnFinishCallback<TOOLS>;
3326
+ /**
3327
+ Callback that is called when each step (LLM call) is finished, including intermediate steps.
3487
3328
  */
3488
- onStepFinish?: GenerateTextOnStepFinishCallback<TOOLS>;
3329
+ onStepFinish?: StreamTextOnStepFinishCallback<TOOLS>;
3489
3330
  /**
3490
- * Internal. For test use only. May change without notice.
3331
+ Internal. For test use only. May change without notice.
3491
3332
  */
3492
3333
  _internal?: {
3334
+ now?: () => number;
3493
3335
  generateId?: IdGenerator;
3494
3336
  currentDate?: () => Date;
3495
3337
  };
3496
- }): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
3497
-
3498
- type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
3338
+ }): StreamTextResult<TOOLS, PARTIAL_OUTPUT>;
3499
3339
 
3500
- type UIMessageStreamOptions = {
3340
+ /**
3341
+ The result of a `generateImage` call.
3342
+ It contains the images and additional information.
3343
+ */
3344
+ interface GenerateImageResult {
3501
3345
  /**
3502
- * Message ID that is sent to the client if a new message is created.
3503
- * This is intended to be used for the UI message,
3504
- * if the last original message is not an assistant message
3505
- * (in which case that message ID is used).
3346
+ The first image that was generated.
3506
3347
  */
3507
- newMessageId?: string;
3348
+ readonly image: GeneratedFile;
3508
3349
  /**
3509
- * The original messages.
3510
- */
3511
- originalMessages?: UIMessage[];
3512
- onFinish?: (options: {
3513
- /**
3514
- * The updates list of UI messages.
3515
- */
3516
- messages: UIMessage[];
3517
- /**
3518
- * Indicates whether the response message is a continuation of the last original message,
3519
- * or if a new message was created.
3520
- */
3521
- isContinuation: boolean;
3522
- /**
3523
- * The message that was sent to the client as a response
3524
- * (including the original message if it was extended).
3525
- */
3526
- responseMessage: UIMessage;
3527
- }) => void;
3350
+ The images that were generated.
3351
+ */
3352
+ readonly images: Array<GeneratedFile>;
3528
3353
  /**
3529
- * Extracts message metadata that will be send to the client.
3530
- *
3531
- * Called on `start` and `finish` events.
3532
- */
3533
- messageMetadata?: (options: {
3534
- part: TextStreamPart<ToolSet> & {
3535
- type: 'start' | 'finish' | 'start-step' | 'finish-step';
3536
- };
3537
- }) => unknown;
3354
+ Warnings for the call, e.g. unsupported settings.
3355
+ */
3356
+ readonly warnings: Array<ImageGenerationWarning>;
3538
3357
  /**
3539
- * Send reasoning parts to the client.
3540
- * Default to false.
3358
+ Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
3541
3359
  */
3542
- sendReasoning?: boolean;
3360
+ readonly responses: Array<ImageModelResponseMetadata>;
3543
3361
  /**
3544
- * Send source parts to the client.
3545
- * Default to false.
3362
+ * Provider-specific metadata. They are passed through from the provider to the AI SDK and enable provider-specific
3363
+ * results that can be fully encapsulated in the provider.
3546
3364
  */
3547
- sendSources?: boolean;
3365
+ readonly providerMetadata: ImageModelProviderMetadata;
3366
+ }
3367
+
3368
+ /**
3369
+ Generates images using an image model.
3370
+
3371
+ @param model - The image model to use.
3372
+ @param prompt - The prompt that should be used to generate the image.
3373
+ @param n - Number of images to generate. Default: 1.
3374
+ @param size - Size of the images to generate. Must have the format `{width}x{height}`.
3375
+ @param aspectRatio - Aspect ratio of the images to generate. Must have the format `{width}:{height}`.
3376
+ @param seed - Seed for the image generation.
3377
+ @param providerOptions - Additional provider-specific options that are passed through to the provider
3378
+ as body parameters.
3379
+ @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
3380
+ @param abortSignal - An optional abort signal that can be used to cancel the call.
3381
+ @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
3382
+
3383
+ @returns A result object that contains the generated images.
3384
+ */
3385
+ declare function generateImage({ model, prompt, n, maxImagesPerCall, size, aspectRatio, seed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
3548
3386
  /**
3549
- * Send the finish event to the client.
3550
- * Set to false if you are using additional streamText calls
3551
- * that send additional data.
3552
- * Default to true.
3553
- */
3554
- experimental_sendFinish?: boolean;
3387
+ The image model to use.
3388
+ */
3389
+ model: ImageModelV2;
3555
3390
  /**
3556
- * Send the message start event to the client.
3557
- * Set to false if you are using additional streamText calls
3558
- * and the message start event has already been sent.
3559
- * Default to true.
3560
- *
3561
- * Note: this setting is currently not used, but you should
3562
- * already set it to false if you are using additional
3563
- * streamText calls that send additional data to prevent
3564
- * the message start event from being sent multiple times.
3391
+ The prompt that should be used to generate the image.
3565
3392
  */
3566
- experimental_sendStart?: boolean;
3393
+ prompt: string;
3567
3394
  /**
3568
- * Process an error, e.g. to log it. Default to `() => 'An error occurred.'`.
3569
- *
3570
- * @return error message to include in the data stream.
3395
+ Number of images to generate.
3571
3396
  */
3572
- onError?: (error: unknown) => string;
3573
- };
3574
- type ConsumeStreamOptions = {
3575
- onError?: (error: unknown) => void;
3576
- };
3577
- /**
3578
- A result object for accessing different stream types and additional information.
3579
- */
3580
- interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
3397
+ n?: number;
3581
3398
  /**
3582
- The content that was generated in the last step.
3583
-
3584
- Resolved when the response is finished.
3399
+ Number of images to generate.
3585
3400
  */
3586
- readonly content: Promise<Array<ContentPart<TOOLS>>>;
3587
- /**
3588
- The full text that has been generated by the last step.
3589
-
3590
- Resolved when the response is finished.
3591
- */
3592
- readonly text: Promise<string>;
3401
+ maxImagesPerCall?: number;
3593
3402
  /**
3594
- The full reasoning that the model has generated.
3595
-
3596
- Resolved when the response is finished.
3403
+ Size of the images to generate. Must have the format `{width}x{height}`. If not provided, the default size will be used.
3597
3404
  */
3598
- readonly reasoning: Promise<Array<ReasoningPart>>;
3599
- /**
3600
- The reasoning that has been generated by the last step.
3601
-
3602
- Resolved when the response is finished.
3603
- */
3604
- readonly reasoningText: Promise<string | undefined>;
3405
+ size?: `${number}x${number}`;
3605
3406
  /**
3606
- Files that have been generated by the model in the last step.
3607
-
3608
- Resolved when the response is finished.
3407
+ Aspect ratio of the images to generate. Must have the format `{width}:{height}`. If not provided, the default aspect ratio will be used.
3609
3408
  */
3610
- readonly files: Promise<GeneratedFile[]>;
3409
+ aspectRatio?: `${number}:${number}`;
3611
3410
  /**
3612
- Sources that have been used as references in the last step.
3613
-
3614
- Resolved when the response is finished.
3411
+ Seed for the image generation. If not provided, the default seed will be used.
3615
3412
  */
3616
- readonly sources: Promise<Source[]>;
3413
+ seed?: number;
3617
3414
  /**
3618
- The tool calls that have been executed in the last step.
3415
+ Additional provider-specific options that are passed through to the provider
3416
+ as body parameters.
3619
3417
 
3620
- Resolved when the response is finished.
3418
+ The outer record is keyed by the provider name, and the inner
3419
+ record is keyed by the provider-specific metadata key.
3420
+ ```ts
3421
+ {
3422
+ "openai": {
3423
+ "style": "vivid"
3424
+ }
3425
+ }
3426
+ ```
3621
3427
  */
3622
- readonly toolCalls: Promise<ToolCallUnion<TOOLS>[]>;
3428
+ providerOptions?: ProviderOptions;
3623
3429
  /**
3624
- The tool results that have been generated in the last step.
3430
+ Maximum number of retries per embedding model call. Set to 0 to disable retries.
3625
3431
 
3626
- Resolved when the all tool executions are finished.
3432
+ @default 2
3627
3433
  */
3628
- readonly toolResults: Promise<ToolResultUnion<TOOLS>[]>;
3434
+ maxRetries?: number;
3629
3435
  /**
3630
- The reason why the generation finished. Taken from the last step.
3631
-
3632
- Resolved when the response is finished.
3436
+ Abort signal.
3437
+ */
3438
+ abortSignal?: AbortSignal;
3439
+ /**
3440
+ Additional headers to include in the request.
3441
+ Only applicable for HTTP-based providers.
3442
+ */
3443
+ headers?: Record<string, string>;
3444
+ }): Promise<GenerateImageResult>;
3445
+
3446
+ /**
3447
+ The result of a `generateObject` call.
3448
+ */
3449
+ interface GenerateObjectResult<OBJECT> {
3450
+ /**
3451
+ The generated object (typed according to the schema).
3633
3452
  */
3634
- readonly finishReason: Promise<FinishReason>;
3453
+ readonly object: OBJECT;
3635
3454
  /**
3636
- The token usage of the last step.
3637
-
3638
- Resolved when the response is finished.
3639
- */
3640
- readonly usage: Promise<LanguageModelUsage>;
3455
+ The reason why the generation finished.
3456
+ */
3457
+ readonly finishReason: FinishReason;
3641
3458
  /**
3642
- The total token usage of the generated response.
3643
- When there are multiple steps, the usage is the sum of all step usages.
3644
-
3645
- Resolved when the response is finished.
3459
+ The token usage of the generated text.
3646
3460
  */
3647
- readonly totalUsage: Promise<LanguageModelUsage>;
3461
+ readonly usage: LanguageModelUsage;
3648
3462
  /**
3649
- Warnings from the model provider (e.g. unsupported settings) for the first step.
3463
+ Warnings from the model provider (e.g. unsupported settings).
3650
3464
  */
3651
- readonly warnings: Promise<CallWarning[] | undefined>;
3465
+ readonly warnings: CallWarning[] | undefined;
3652
3466
  /**
3653
- Details for all steps.
3654
- You can use this to get information about intermediate steps,
3655
- such as the tool calls or the response headers.
3467
+ Additional request information.
3656
3468
  */
3657
- readonly steps: Promise<Array<StepResult<TOOLS>>>;
3658
- /**
3659
- Additional request information from the last step.
3660
- */
3661
- readonly request: Promise<LanguageModelRequestMetadata>;
3469
+ readonly request: LanguageModelRequestMetadata;
3662
3470
  /**
3663
- Additional response information from the last step.
3664
- */
3665
- readonly response: Promise<LanguageModelResponseMetadata & {
3471
+ Additional response information.
3472
+ */
3473
+ readonly response: LanguageModelResponseMetadata & {
3666
3474
  /**
3667
- The response messages that were generated during the call. It consists of an assistant message,
3668
- potentially containing tool calls.
3669
-
3670
- When there are tool results, there is an additional tool message with the tool results that are available.
3671
- If there are tools that do not have execute functions, they are not included in the tool results and
3672
- need to be added separately.
3673
- */
3674
- messages: Array<ResponseMessage>;
3675
- }>;
3475
+ Response body (available only for providers that use HTTP requests).
3476
+ */
3477
+ body?: unknown;
3478
+ };
3676
3479
  /**
3677
- Additional provider-specific metadata from the last step.
3678
- Metadata is passed through from the provider to the AI SDK and
3679
- enables provider-specific results that can be fully encapsulated in the provider.
3480
+ Additional provider-specific metadata. They are passed through
3481
+ from the provider to the AI SDK and enable provider-specific
3482
+ results that can be fully encapsulated in the provider.
3680
3483
  */
3681
- readonly providerMetadata: Promise<ProviderMetadata | undefined>;
3682
- /**
3683
- A text stream that returns only the generated text deltas. You can use it
3684
- as either an AsyncIterable or a ReadableStream. When an error occurs, the
3685
- stream will throw the error.
3686
- */
3687
- readonly textStream: AsyncIterableStream<string>;
3484
+ readonly providerMetadata: ProviderMetadata | undefined;
3688
3485
  /**
3689
- A stream with all events, including text deltas, tool calls, tool results, and
3690
- errors.
3691
- You can use it as either an AsyncIterable or a ReadableStream.
3692
- Only errors that stop the stream, such as network errors, are thrown.
3486
+ Converts the object to a JSON response.
3487
+ The response will have a status code of 200 and a content type of `application/json; charset=utf-8`.
3693
3488
  */
3694
- readonly fullStream: AsyncIterableStream<TextStreamPart<TOOLS>>;
3695
- /**
3696
- A stream of partial outputs. It uses the `experimental_output` specification.
3489
+ toJsonResponse(init?: ResponseInit): Response;
3490
+ }
3491
+
3492
+ /**
3493
+ A function that attempts to repair the raw output of the mode
3494
+ to enable JSON parsing.
3495
+
3496
+ Should return the repaired text or null if the text cannot be repaired.
3697
3497
  */
3698
- readonly experimental_partialOutputStream: AsyncIterableStream<PARTIAL_OUTPUT>;
3699
- /**
3700
- Consumes the stream without processing the parts.
3701
- This is useful to force the stream to finish.
3702
- It effectively removes the backpressure and allows the stream to finish,
3703
- triggering the `onFinish` callback and the promise resolution.
3704
-
3705
- If an error occurs, it is passed to the optional `onError` callback.
3706
- */
3707
- consumeStream(options?: ConsumeStreamOptions): Promise<void>;
3708
- /**
3709
- Converts the result to a UI message stream.
3710
-
3711
- @param options.getErrorMessage an optional function that converts an error to an error message.
3712
- @param options.sendUsage whether to send the usage information to the client. Defaults to true.
3713
- @param options.sendReasoning whether to send the reasoning information to the client. Defaults to false.
3714
- @param options.sendSources whether to send the sources information to the client. Defaults to false.
3715
- @param options.experimental_sendFinish whether to send the finish information to the client. Defaults to true.
3716
- @param options.experimental_sendStart whether to send the start information to the client. Defaults to true.
3717
-
3718
- @return A UI message stream.
3719
- */
3720
- toUIMessageStream(options?: UIMessageStreamOptions): ReadableStream<UIMessageStreamPart>;
3721
- /**
3722
- Writes UI message stream output to a Node.js response-like object.
3723
- @param response A Node.js response-like object (ServerResponse).
3724
- @param options.status The status code.
3725
- @param options.statusText The status text.
3726
- @param options.headers The headers.
3727
- @param options.getErrorMessage An optional function that converts an error to an error message.
3728
- @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
3729
- @param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
3730
- */
3731
- pipeUIMessageStreamToResponse(response: ServerResponse, options?: ResponseInit & UIMessageStreamOptions): void;
3732
- /**
3733
- Writes text delta output to a Node.js response-like object.
3734
- It sets a `Content-Type` header to `text/plain; charset=utf-8` and
3735
- writes each text delta as a separate chunk.
3736
- @param response A Node.js response-like object (ServerResponse).
3737
- @param init Optional headers, status code, and status text.
3738
- */
3739
- pipeTextStreamToResponse(response: ServerResponse, init?: ResponseInit): void;
3740
- /**
3741
- Converts the result to a streamed response object with a stream data part stream.
3742
-
3743
- @param options.status The status code.
3744
- @param options.statusText The status text.
3745
- @param options.headers The headers.
3746
- @param options.getErrorMessage An optional function that converts an error to an error message.
3747
- @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
3748
- @param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
3749
- @return A response object.
3750
- */
3751
- toUIMessageStreamResponse(options?: ResponseInit & UIMessageStreamOptions): Response;
3752
- /**
3753
- Creates a simple text stream response.
3754
- Each text delta is encoded as UTF-8 and sent as a separate chunk.
3755
- Non-text-delta events are ignored.
3756
- @param init Optional headers, status code, and status text.
3757
- */
3758
- toTextStreamResponse(init?: ResponseInit): Response;
3759
- }
3760
- type TextStreamPart<TOOLS extends ToolSet> = ContentPart<TOOLS> | {
3761
- type: 'reasoning-part-finish';
3762
- } | {
3763
- type: 'tool-call-streaming-start';
3764
- toolCallId: string;
3765
- toolName: string;
3766
- } | {
3767
- type: 'tool-call-delta';
3768
- toolCallId: string;
3769
- toolName: string;
3770
- argsTextDelta: string;
3771
- } | {
3772
- type: 'start-step';
3773
- request: LanguageModelRequestMetadata;
3774
- warnings: CallWarning[];
3775
- } | {
3776
- type: 'finish-step';
3777
- response: LanguageModelResponseMetadata;
3778
- usage: LanguageModelUsage;
3779
- finishReason: FinishReason;
3780
- providerMetadata: ProviderMetadata | undefined;
3781
- } | {
3782
- type: 'start';
3783
- } | {
3784
- type: 'finish';
3785
- finishReason: FinishReason;
3786
- totalUsage: LanguageModelUsage;
3787
- } | {
3788
- type: 'error';
3789
- error: unknown;
3790
- };
3791
-
3792
- /**
3793
- * Detects the first chunk in a buffer.
3794
- *
3795
- * @param buffer - The buffer to detect the first chunk in.
3796
- *
3797
- * @returns The first detected chunk, or `undefined` if no chunk was detected.
3798
- */
3799
- type ChunkDetector = (buffer: string) => string | undefined | null;
3800
- /**
3801
- * Smooths text streaming output.
3802
- *
3803
- * @param delayInMs - The delay in milliseconds between each chunk. Defaults to 10ms. Can be set to `null` to skip the delay.
3804
- * @param chunking - Controls how the text is chunked for streaming. Use "word" to stream word by word (default), "line" to stream line by line, or provide a custom RegExp pattern for custom chunking.
3805
- *
3806
- * @returns A transform stream that smooths text streaming output.
3807
- */
3808
- declare function smoothStream<TOOLS extends ToolSet>({ delayInMs, chunking, _internal: { delay }, }?: {
3809
- delayInMs?: number | null;
3810
- chunking?: 'word' | 'line' | RegExp | ChunkDetector;
3811
- /**
3812
- * Internal. For test use only. May change without notice.
3813
- */
3814
- _internal?: {
3815
- delay?: (delayInMs: number | null) => Promise<void>;
3816
- };
3817
- }): (options: {
3818
- tools: TOOLS;
3819
- }) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
3820
-
3821
- /**
3822
- A transformation that is applied to the stream.
3823
-
3824
- @param stopStream - A function that stops the source stream.
3825
- @param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
3826
- */
3827
- type StreamTextTransform<TOOLS extends ToolSet> = (options: {
3828
- tools: TOOLS;
3829
- stopStream: () => void;
3830
- }) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
3831
- /**
3832
- Callback that is set using the `onError` option.
3833
-
3834
- @param event - The event that is passed to the callback.
3835
- */
3836
- type StreamTextOnErrorCallback = (event: {
3837
- error: unknown;
3838
- }) => Promise<void> | void;
3839
- /**
3840
- Callback that is set using the `onStepFinish` option.
3841
-
3842
- @param stepResult - The result of the step.
3843
- */
3844
- type StreamTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
3845
- /**
3846
- Callback that is set using the `onChunk` option.
3847
-
3848
- @param event - The event that is passed to the callback.
3849
- */
3850
- type StreamTextOnChunkCallback<TOOLS extends ToolSet> = (event: {
3851
- chunk: Extract<TextStreamPart<TOOLS>, {
3852
- type: 'text' | 'reasoning' | 'source' | 'tool-call' | 'tool-call-streaming-start' | 'tool-call-delta' | 'tool-result';
3853
- }>;
3854
- }) => Promise<void> | void;
3855
- /**
3856
- Callback that is set using the `onFinish` option.
3857
-
3858
- @param event - The event that is passed to the callback.
3859
- */
3860
- type StreamTextOnFinishCallback<TOOLS extends ToolSet> = (event: StepResult<TOOLS> & {
3861
- /**
3862
- Details for all steps.
3863
- */
3864
- readonly steps: StepResult<TOOLS>[];
3865
- /**
3866
- Total usage for all steps. This is the sum of the usage of all steps.
3867
- */
3868
- readonly totalUsage: LanguageModelUsage;
3869
- }) => Promise<void> | void;
3498
+ type RepairTextFunction = (options: {
3499
+ text: string;
3500
+ error: JSONParseError | TypeValidationError;
3501
+ }) => Promise<string | null>;
3870
3502
  /**
3871
- Generate a text and call tools for a given prompt using a language model.
3503
+ Generate a structured, typed object for a given prompt and schema using a language model.
3872
3504
 
3873
- This function streams the output. If you do not want to stream the output, use `generateText` instead.
3505
+ This function does not stream the output. If you want to stream the output, use `streamObject` instead.
3874
3506
 
3875
3507
  @param model - The language model to use.
3876
3508
  @param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
@@ -3904,461 +3536,212 @@ If set and supported by the model, calls will generate deterministic results.
3904
3536
  @param abortSignal - An optional abort signal that can be used to cancel the call.
3905
3537
  @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
3906
3538
 
3907
- @param maxSteps - Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
3539
+ @param schema - The schema of the object that the model should generate.
3540
+ @param schemaName - Optional name of the output that should be generated.
3541
+ Used by some providers for additional LLM guidance, e.g.
3542
+ via tool or schema name.
3543
+ @param schemaDescription - Optional description of the output that should be generated.
3544
+ Used by some providers for additional LLM guidance, e.g.
3545
+ via tool or schema description.
3908
3546
 
3909
- @param onChunk - Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
3910
- @param onError - Callback that is called when an error occurs during streaming. You can use it to log errors.
3911
- @param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
3912
- @param onFinish - Callback that is called when the LLM response and all request tool executions
3913
- (for tools that have an `execute` function) are finished.
3547
+ @param output - The type of the output.
3914
3548
 
3915
- @return
3916
- A result object for accessing different stream types and additional information.
3917
- */
3918
- declare function streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, maxSteps, experimental_output: output, experimental_telemetry: telemetry, providerOptions, experimental_toolCallStreaming, toolCallStreaming, experimental_activeTools: activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, onChunk, onError, onFinish, onStepFinish, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
3919
- /**
3920
- The language model to use.
3921
- */
3922
- model: LanguageModel;
3923
- /**
3924
- The tools that the model can call. The model needs to support calling tools.
3925
- */
3926
- tools?: TOOLS;
3927
- /**
3928
- The tool choice strategy. Default: 'auto'.
3929
- */
3930
- toolChoice?: ToolChoice<TOOLS>;
3931
- /**
3932
- Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Must be at least 1.
3549
+ - 'object': The output is an object.
3550
+ - 'array': The output is an array.
3551
+ - 'enum': The output is an enum.
3552
+ - 'no-schema': The output is not a schema.
3933
3553
 
3934
- A maximum number is required to prevent infinite loops in the case of misconfigured tools.
3554
+ @param experimental_repairText - A function that attempts to repair the raw output of the mode
3555
+ to enable JSON parsing.
3935
3556
 
3936
- By default, it's set to 1, which means that only a single LLM call is made.
3937
- */
3938
- maxSteps?: number;
3939
- /**
3940
- Optional telemetry configuration (experimental).
3941
- */
3942
- experimental_telemetry?: TelemetrySettings;
3943
- /**
3944
- Additional provider-specific options. They are passed through
3557
+ @param experimental_telemetry - Optional telemetry configuration (experimental).
3558
+
3559
+ @param providerOptions - Additional provider-specific options. They are passed through
3945
3560
  to the provider from the AI SDK and enable provider-specific
3946
3561
  functionality that can be fully encapsulated in the provider.
3562
+
3563
+ @returns
3564
+ A result object that contains the generated object, the finish reason, the token usage, and additional information.
3947
3565
  */
3948
- providerOptions?: ProviderOptions;
3949
- /**
3950
- Limits the tools that are available for the model to call without
3951
- changing the tool call and result types in the result.
3952
- */
3953
- experimental_activeTools?: Array<keyof TOOLS>;
3566
+ declare function generateObject<RESULT extends SCHEMA extends z.Schema ? Output extends 'array' ? Array<z.infer<SCHEMA>> : z.infer<SCHEMA> : SCHEMA extends Schema<infer T> ? Output extends 'array' ? Array<T> : T : never, SCHEMA extends z.Schema | Schema = z.Schema<JSONValue$1>, Output extends 'object' | 'array' | 'enum' | 'no-schema' = RESULT extends string ? 'enum' : 'object'>(options: Omit<CallSettings, 'stopSequences'> & Prompt & (Output extends 'enum' ? {
3954
3567
  /**
3955
- Optional specification for parsing structured outputs from the LLM response.
3956
- */
3957
- experimental_output?: Output$1<OUTPUT, PARTIAL_OUTPUT>;
3568
+ The enum values that the model should use.
3569
+ */
3570
+ enum: Array<RESULT>;
3571
+ mode?: 'json';
3572
+ output: 'enum';
3573
+ } : Output extends 'no-schema' ? {} : {
3958
3574
  /**
3959
- A function that attempts to repair a tool call that failed to parse.
3960
- */
3961
- experimental_repairToolCall?: ToolCallRepairFunction<TOOLS>;
3575
+ The schema of the object that the model should generate.
3576
+ */
3577
+ schema: SCHEMA;
3962
3578
  /**
3963
- Enable streaming of tool call deltas as they are generated. Disabled by default.
3964
- */
3965
- toolCallStreaming?: boolean;
3579
+ Optional name of the output that should be generated.
3580
+ Used by some providers for additional LLM guidance, e.g.
3581
+ via tool or schema name.
3582
+ */
3583
+ schemaName?: string;
3966
3584
  /**
3967
- @deprecated Use `toolCallStreaming` instead.
3968
- */
3969
- experimental_toolCallStreaming?: boolean;
3585
+ Optional description of the output that should be generated.
3586
+ Used by some providers for additional LLM guidance, e.g.
3587
+ via tool or schema description.
3588
+ */
3589
+ schemaDescription?: string;
3970
3590
  /**
3971
- Optional stream transformations.
3972
- They are applied in the order they are provided.
3973
- The stream transformations must maintain the stream structure for streamText to work correctly.
3974
- */
3975
- experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
3591
+ The mode to use for object generation.
3592
+
3593
+ The schema is converted into a JSON schema and used in one of the following ways
3594
+
3595
+ - 'auto': The provider will choose the best mode for the model.
3596
+ - 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
3597
+ - 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
3598
+
3599
+ Please note that most providers do not support all modes.
3600
+
3601
+ Default and recommended: 'auto' (best mode for the model).
3602
+ */
3603
+ mode?: 'auto' | 'json' | 'tool';
3604
+ }) & {
3605
+ output?: Output;
3976
3606
  /**
3977
- Callback that is called for each chunk of the stream.
3978
- The stream processing will pause until the callback promise is resolved.
3607
+ The language model to use.
3979
3608
  */
3980
- onChunk?: StreamTextOnChunkCallback<TOOLS>;
3609
+ model: LanguageModel;
3981
3610
  /**
3982
- Callback that is invoked when an error occurs during streaming.
3983
- You can use it to log errors.
3984
- The stream processing will pause until the callback promise is resolved.
3611
+ A function that attempts to repair the raw output of the mode
3612
+ to enable JSON parsing.
3985
3613
  */
3986
- onError?: StreamTextOnErrorCallback;
3614
+ experimental_repairText?: RepairTextFunction;
3987
3615
  /**
3988
- Callback that is called when the LLM response and all request tool executions
3989
- (for tools that have an `execute` function) are finished.
3990
-
3991
- The usage is the combined usage of all steps.
3992
- */
3993
- onFinish?: StreamTextOnFinishCallback<TOOLS>;
3616
+ Optional telemetry configuration (experimental).
3617
+ */
3618
+ experimental_telemetry?: TelemetrySettings;
3994
3619
  /**
3995
- Callback that is called when each step (LLM call) is finished, including intermediate steps.
3996
- */
3997
- onStepFinish?: StreamTextOnStepFinishCallback<TOOLS>;
3620
+ Additional provider-specific options. They are passed through
3621
+ to the provider from the AI SDK and enable provider-specific
3622
+ functionality that can be fully encapsulated in the provider.
3623
+ */
3624
+ providerOptions?: ProviderOptions;
3998
3625
  /**
3999
- Internal. For test use only. May change without notice.
3626
+ * Internal. For test use only. May change without notice.
4000
3627
  */
4001
3628
  _internal?: {
4002
- now?: () => number;
4003
- generateId?: IdGenerator;
3629
+ generateId?: () => string;
4004
3630
  currentDate?: () => Date;
4005
3631
  };
4006
- }): StreamTextResult<TOOLS, PARTIAL_OUTPUT>;
3632
+ }): Promise<GenerateObjectResult<RESULT>>;
4007
3633
 
4008
3634
  /**
4009
- The result of a `generateImage` call.
4010
- It contains the images and additional information.
3635
+ * Converts a data URL of type text/* to a text string.
4011
3636
  */
4012
- interface GenerateImageResult {
4013
- /**
4014
- The first image that was generated.
4015
- */
4016
- readonly image: GeneratedFile;
4017
- /**
4018
- The images that were generated.
4019
- */
4020
- readonly images: Array<GeneratedFile>;
4021
- /**
4022
- Warnings for the call, e.g. unsupported settings.
4023
- */
4024
- readonly warnings: Array<ImageGenerationWarning>;
4025
- /**
4026
- Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
4027
- */
4028
- readonly responses: Array<ImageModelResponseMetadata>;
4029
- /**
4030
- * Provider-specific metadata. They are passed through from the provider to the AI SDK and enable provider-specific
4031
- * results that can be fully encapsulated in the provider.
4032
- */
4033
- readonly providerMetadata: ImageModelProviderMetadata;
4034
- }
3637
+ declare function getTextFromDataUrl(dataUrl: string): string;
4035
3638
 
4036
3639
  /**
4037
- Generates images using an image model.
3640
+ * Performs a deep-equal comparison of two parsed JSON objects.
3641
+ *
3642
+ * @param {any} obj1 - The first object to compare.
3643
+ * @param {any} obj2 - The second object to compare.
3644
+ * @returns {boolean} - Returns true if the two objects are deeply equal, false otherwise.
3645
+ */
3646
+ declare function isDeepEqualData(obj1: any, obj2: any): boolean;
4038
3647
 
4039
- @param model - The image model to use.
4040
- @param prompt - The prompt that should be used to generate the image.
4041
- @param n - Number of images to generate. Default: 1.
4042
- @param size - Size of the images to generate. Must have the format `{width}x{height}`.
4043
- @param aspectRatio - Aspect ratio of the images to generate. Must have the format `{width}:{height}`.
4044
- @param seed - Seed for the image generation.
4045
- @param providerOptions - Additional provider-specific options that are passed through to the provider
4046
- as body parameters.
4047
- @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
4048
- @param abortSignal - An optional abort signal that can be used to cancel the call.
4049
- @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
3648
+ declare function parsePartialJson(jsonText: string | undefined): Promise<{
3649
+ value: JSONValue$1 | undefined;
3650
+ state: 'undefined-input' | 'successful-parse' | 'repaired-parse' | 'failed-parse';
3651
+ }>;
4050
3652
 
4051
- @returns A result object that contains the generated images.
3653
+ /**
3654
+ * Calculates the cosine similarity between two vectors. This is a useful metric for
3655
+ * comparing the similarity of two vectors such as embeddings.
3656
+ *
3657
+ * @param vector1 - The first vector.
3658
+ * @param vector2 - The second vector.
3659
+ *
3660
+ * @returns The cosine similarity between vector1 and vector2.
3661
+ * @returns 0 if either vector is the zero vector.
3662
+ *
3663
+ * @throws {InvalidArgumentError} If the vectors do not have the same length.
4052
3664
  */
4053
- declare function generateImage({ model, prompt, n, maxImagesPerCall, size, aspectRatio, seed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
3665
+ declare function cosineSimilarity(vector1: number[], vector2: number[]): number;
3666
+
3667
+ /**
3668
+ * Creates a ReadableStream that emits the provided values with an optional delay between each value.
3669
+ *
3670
+ * @param options - The configuration options
3671
+ * @param options.chunks - Array of values to be emitted by the stream
3672
+ * @param options.initialDelayInMs - Optional initial delay in milliseconds before emitting the first value (default: 0). Can be set to `null` to skip the initial delay. The difference between `initialDelayInMs: null` and `initialDelayInMs: 0` is that `initialDelayInMs: null` will emit the values without any delay, while `initialDelayInMs: 0` will emit the values with a delay of 0 milliseconds.
3673
+ * @param options.chunkDelayInMs - Optional delay in milliseconds between emitting each value (default: 0). Can be set to `null` to skip the delay. The difference between `chunkDelayInMs: null` and `chunkDelayInMs: 0` is that `chunkDelayInMs: null` will emit the values without any delay, while `chunkDelayInMs: 0` will emit the values with a delay of 0 milliseconds.
3674
+ * @returns A ReadableStream that emits the provided values
3675
+ */
3676
+ declare function simulateReadableStream<T>({ chunks, initialDelayInMs, chunkDelayInMs, _internal, }: {
3677
+ chunks: T[];
3678
+ initialDelayInMs?: number | null;
3679
+ chunkDelayInMs?: number | null;
3680
+ _internal?: {
3681
+ delay?: (ms: number | null) => Promise<void>;
3682
+ };
3683
+ }): ReadableStream<T>;
3684
+
3685
+ /**
3686
+ The result of a `streamObject` call that contains the partial object stream and additional information.
3687
+ */
3688
+ interface StreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM> {
4054
3689
  /**
4055
- The image model to use.
3690
+ Warnings from the model provider (e.g. unsupported settings)
4056
3691
  */
4057
- model: ImageModelV2;
4058
- /**
4059
- The prompt that should be used to generate the image.
4060
- */
4061
- prompt: string;
3692
+ readonly warnings: Promise<CallWarning[] | undefined>;
4062
3693
  /**
4063
- Number of images to generate.
4064
- */
4065
- n?: number;
3694
+ The token usage of the generated response. Resolved when the response is finished.
3695
+ */
3696
+ readonly usage: Promise<LanguageModelUsage>;
4066
3697
  /**
4067
- Number of images to generate.
3698
+ Additional provider-specific metadata. They are passed through
3699
+ from the provider to the AI SDK and enable provider-specific
3700
+ results that can be fully encapsulated in the provider.
4068
3701
  */
4069
- maxImagesPerCall?: number;
3702
+ readonly providerMetadata: Promise<ProviderMetadata | undefined>;
4070
3703
  /**
4071
- Size of the images to generate. Must have the format `{width}x{height}`. If not provided, the default size will be used.
4072
- */
4073
- size?: `${number}x${number}`;
3704
+ Additional request information from the last step.
3705
+ */
3706
+ readonly request: Promise<LanguageModelRequestMetadata>;
4074
3707
  /**
4075
- Aspect ratio of the images to generate. Must have the format `{width}:{height}`. If not provided, the default aspect ratio will be used.
4076
- */
4077
- aspectRatio?: `${number}:${number}`;
3708
+ Additional response information.
3709
+ */
3710
+ readonly response: Promise<LanguageModelResponseMetadata>;
4078
3711
  /**
4079
- Seed for the image generation. If not provided, the default seed will be used.
4080
- */
4081
- seed?: number;
3712
+ The generated object (typed according to the schema). Resolved when the response is finished.
3713
+ */
3714
+ readonly object: Promise<RESULT>;
4082
3715
  /**
4083
- Additional provider-specific options that are passed through to the provider
4084
- as body parameters.
3716
+ Stream of partial objects. It gets more complete as the stream progresses.
4085
3717
 
4086
- The outer record is keyed by the provider name, and the inner
4087
- record is keyed by the provider-specific metadata key.
4088
- ```ts
4089
- {
4090
- "openai": {
4091
- "style": "vivid"
4092
- }
4093
- }
4094
- ```
3718
+ Note that the partial object is not validated.
3719
+ If you want to be certain that the actual content matches your schema, you need to implement your own validation for partial results.
4095
3720
  */
4096
- providerOptions?: ProviderOptions;
3721
+ readonly partialObjectStream: AsyncIterableStream<PARTIAL>;
4097
3722
  /**
4098
- Maximum number of retries per embedding model call. Set to 0 to disable retries.
4099
-
4100
- @default 2
3723
+ * Stream over complete array elements. Only available if the output strategy is set to `array`.
4101
3724
  */
4102
- maxRetries?: number;
4103
- /**
4104
- Abort signal.
4105
- */
4106
- abortSignal?: AbortSignal;
4107
- /**
4108
- Additional headers to include in the request.
4109
- Only applicable for HTTP-based providers.
4110
- */
4111
- headers?: Record<string, string>;
4112
- }): Promise<GenerateImageResult>;
4113
-
4114
- /**
4115
- The result of a `generateObject` call.
4116
- */
4117
- interface GenerateObjectResult<OBJECT> {
4118
- /**
4119
- The generated object (typed according to the schema).
4120
- */
4121
- readonly object: OBJECT;
3725
+ readonly elementStream: ELEMENT_STREAM;
4122
3726
  /**
4123
- The reason why the generation finished.
3727
+ Text stream of the JSON representation of the generated object. It contains text chunks.
3728
+ When the stream is finished, the object is valid JSON that can be parsed.
4124
3729
  */
4125
- readonly finishReason: FinishReason;
3730
+ readonly textStream: AsyncIterableStream<string>;
4126
3731
  /**
4127
- The token usage of the generated text.
3732
+ Stream of different types of events, including partial objects, errors, and finish events.
3733
+ Only errors that stop the stream, such as network errors, are thrown.
4128
3734
  */
4129
- readonly usage: LanguageModelUsage;
3735
+ readonly fullStream: AsyncIterableStream<ObjectStreamPart<PARTIAL>>;
4130
3736
  /**
4131
- Warnings from the model provider (e.g. unsupported settings).
3737
+ Writes text delta output to a Node.js response-like object.
3738
+ It sets a `Content-Type` header to `text/plain; charset=utf-8` and
3739
+ writes each text delta as a separate chunk.
3740
+
3741
+ @param response A Node.js response-like object (ServerResponse).
3742
+ @param init Optional headers, status code, and status text.
4132
3743
  */
4133
- readonly warnings: CallWarning[] | undefined;
4134
- /**
4135
- Additional request information.
4136
- */
4137
- readonly request: LanguageModelRequestMetadata;
4138
- /**
4139
- Additional response information.
4140
- */
4141
- readonly response: LanguageModelResponseMetadata & {
4142
- /**
4143
- Response body (available only for providers that use HTTP requests).
4144
- */
4145
- body?: unknown;
4146
- };
4147
- /**
4148
- Additional provider-specific metadata. They are passed through
4149
- from the provider to the AI SDK and enable provider-specific
4150
- results that can be fully encapsulated in the provider.
4151
- */
4152
- readonly providerMetadata: ProviderMetadata | undefined;
4153
- /**
4154
- Converts the object to a JSON response.
4155
- The response will have a status code of 200 and a content type of `application/json; charset=utf-8`.
4156
- */
4157
- toJsonResponse(init?: ResponseInit): Response;
4158
- }
4159
-
4160
- /**
4161
- A function that attempts to repair the raw output of the mode
4162
- to enable JSON parsing.
4163
-
4164
- Should return the repaired text or null if the text cannot be repaired.
4165
- */
4166
- type RepairTextFunction = (options: {
4167
- text: string;
4168
- error: JSONParseError | TypeValidationError;
4169
- }) => Promise<string | null>;
4170
- /**
4171
- Generate a structured, typed object for a given prompt and schema using a language model.
4172
-
4173
- This function does not stream the output. If you want to stream the output, use `streamObject` instead.
4174
-
4175
- @param model - The language model to use.
4176
- @param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
4177
-
4178
- @param system - A system message that will be part of the prompt.
4179
- @param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
4180
- @param messages - A list of messages. You can either use `prompt` or `messages` but not both.
4181
-
4182
- @param maxOutputTokens - Maximum number of tokens to generate.
4183
- @param temperature - Temperature setting.
4184
- The value is passed through to the provider. The range depends on the provider and model.
4185
- It is recommended to set either `temperature` or `topP`, but not both.
4186
- @param topP - Nucleus sampling.
4187
- The value is passed through to the provider. The range depends on the provider and model.
4188
- It is recommended to set either `temperature` or `topP`, but not both.
4189
- @param topK - Only sample from the top K options for each subsequent token.
4190
- Used to remove "long tail" low probability responses.
4191
- Recommended for advanced use cases only. You usually only need to use temperature.
4192
- @param presencePenalty - Presence penalty setting.
4193
- It affects the likelihood of the model to repeat information that is already in the prompt.
4194
- The value is passed through to the provider. The range depends on the provider and model.
4195
- @param frequencyPenalty - Frequency penalty setting.
4196
- It affects the likelihood of the model to repeatedly use the same words or phrases.
4197
- The value is passed through to the provider. The range depends on the provider and model.
4198
- @param stopSequences - Stop sequences.
4199
- If set, the model will stop generating text when one of the stop sequences is generated.
4200
- @param seed - The seed (integer) to use for random sampling.
4201
- If set and supported by the model, calls will generate deterministic results.
4202
-
4203
- @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
4204
- @param abortSignal - An optional abort signal that can be used to cancel the call.
4205
- @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
4206
-
4207
- @param schema - The schema of the object that the model should generate.
4208
- @param schemaName - Optional name of the output that should be generated.
4209
- Used by some providers for additional LLM guidance, e.g.
4210
- via tool or schema name.
4211
- @param schemaDescription - Optional description of the output that should be generated.
4212
- Used by some providers for additional LLM guidance, e.g.
4213
- via tool or schema description.
4214
-
4215
- @param output - The type of the output.
4216
-
4217
- - 'object': The output is an object.
4218
- - 'array': The output is an array.
4219
- - 'enum': The output is an enum.
4220
- - 'no-schema': The output is not a schema.
4221
-
4222
- @param experimental_repairText - A function that attempts to repair the raw output of the mode
4223
- to enable JSON parsing.
4224
-
4225
- @param experimental_telemetry - Optional telemetry configuration (experimental).
4226
-
4227
- @param providerOptions - Additional provider-specific options. They are passed through
4228
- to the provider from the AI SDK and enable provider-specific
4229
- functionality that can be fully encapsulated in the provider.
4230
-
4231
- @returns
4232
- A result object that contains the generated object, the finish reason, the token usage, and additional information.
4233
- */
4234
- declare function generateObject<RESULT extends SCHEMA extends z.Schema ? Output extends 'array' ? Array<z.infer<SCHEMA>> : z.infer<SCHEMA> : SCHEMA extends Schema<infer T> ? Output extends 'array' ? Array<T> : T : never, SCHEMA extends z.Schema | Schema = z.Schema<JSONValue$1>, Output extends 'object' | 'array' | 'enum' | 'no-schema' = RESULT extends string ? 'enum' : 'object'>(options: Omit<CallSettings, 'stopSequences'> & Prompt & (Output extends 'enum' ? {
4235
- /**
4236
- The enum values that the model should use.
4237
- */
4238
- enum: Array<RESULT>;
4239
- mode?: 'json';
4240
- output: 'enum';
4241
- } : Output extends 'no-schema' ? {} : {
4242
- /**
4243
- The schema of the object that the model should generate.
4244
- */
4245
- schema: SCHEMA;
4246
- /**
4247
- Optional name of the output that should be generated.
4248
- Used by some providers for additional LLM guidance, e.g.
4249
- via tool or schema name.
4250
- */
4251
- schemaName?: string;
4252
- /**
4253
- Optional description of the output that should be generated.
4254
- Used by some providers for additional LLM guidance, e.g.
4255
- via tool or schema description.
4256
- */
4257
- schemaDescription?: string;
4258
- /**
4259
- The mode to use for object generation.
4260
-
4261
- The schema is converted into a JSON schema and used in one of the following ways
4262
-
4263
- - 'auto': The provider will choose the best mode for the model.
4264
- - 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
4265
- - 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
4266
-
4267
- Please note that most providers do not support all modes.
4268
-
4269
- Default and recommended: 'auto' (best mode for the model).
4270
- */
4271
- mode?: 'auto' | 'json' | 'tool';
4272
- }) & {
4273
- output?: Output;
4274
- /**
4275
- The language model to use.
4276
- */
4277
- model: LanguageModel;
4278
- /**
4279
- A function that attempts to repair the raw output of the mode
4280
- to enable JSON parsing.
4281
- */
4282
- experimental_repairText?: RepairTextFunction;
4283
- /**
4284
- Optional telemetry configuration (experimental).
4285
- */
4286
- experimental_telemetry?: TelemetrySettings;
4287
- /**
4288
- Additional provider-specific options. They are passed through
4289
- to the provider from the AI SDK and enable provider-specific
4290
- functionality that can be fully encapsulated in the provider.
4291
- */
4292
- providerOptions?: ProviderOptions;
4293
- /**
4294
- * Internal. For test use only. May change without notice.
4295
- */
4296
- _internal?: {
4297
- generateId?: () => string;
4298
- currentDate?: () => Date;
4299
- };
4300
- }): Promise<GenerateObjectResult<RESULT>>;
4301
-
4302
- /**
4303
- The result of a `streamObject` call that contains the partial object stream and additional information.
4304
- */
4305
- interface StreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM> {
4306
- /**
4307
- Warnings from the model provider (e.g. unsupported settings)
4308
- */
4309
- readonly warnings: Promise<CallWarning[] | undefined>;
4310
- /**
4311
- The token usage of the generated response. Resolved when the response is finished.
4312
- */
4313
- readonly usage: Promise<LanguageModelUsage>;
4314
- /**
4315
- Additional provider-specific metadata. They are passed through
4316
- from the provider to the AI SDK and enable provider-specific
4317
- results that can be fully encapsulated in the provider.
4318
- */
4319
- readonly providerMetadata: Promise<ProviderMetadata | undefined>;
4320
- /**
4321
- Additional request information from the last step.
4322
- */
4323
- readonly request: Promise<LanguageModelRequestMetadata>;
4324
- /**
4325
- Additional response information.
4326
- */
4327
- readonly response: Promise<LanguageModelResponseMetadata>;
4328
- /**
4329
- The generated object (typed according to the schema). Resolved when the response is finished.
4330
- */
4331
- readonly object: Promise<RESULT>;
4332
- /**
4333
- Stream of partial objects. It gets more complete as the stream progresses.
4334
-
4335
- Note that the partial object is not validated.
4336
- If you want to be certain that the actual content matches your schema, you need to implement your own validation for partial results.
4337
- */
4338
- readonly partialObjectStream: AsyncIterableStream<PARTIAL>;
4339
- /**
4340
- * Stream over complete array elements. Only available if the output strategy is set to `array`.
4341
- */
4342
- readonly elementStream: ELEMENT_STREAM;
4343
- /**
4344
- Text stream of the JSON representation of the generated object. It contains text chunks.
4345
- When the stream is finished, the object is valid JSON that can be parsed.
4346
- */
4347
- readonly textStream: AsyncIterableStream<string>;
4348
- /**
4349
- Stream of different types of events, including partial objects, errors, and finish events.
4350
- Only errors that stop the stream, such as network errors, are thrown.
4351
- */
4352
- readonly fullStream: AsyncIterableStream<ObjectStreamPart<PARTIAL>>;
4353
- /**
4354
- Writes text delta output to a Node.js response-like object.
4355
- It sets a `Content-Type` header to `text/plain; charset=utf-8` and
4356
- writes each text delta as a separate chunk.
4357
-
4358
- @param response A Node.js response-like object (ServerResponse).
4359
- @param init Optional headers, status code, and status text.
4360
- */
4361
- pipeTextStreamToResponse(response: ServerResponse$1, init?: ResponseInit): void;
3744
+ pipeTextStreamToResponse(response: ServerResponse$1, init?: ResponseInit): void;
4362
3745
  /**
4363
3746
  Creates a simple text stream response.
4364
3747
  The response has a `Content-Type` header set to `text/plain; charset=utf-8`.
@@ -4754,144 +4137,817 @@ declare function customProvider<LANGUAGE_MODELS extends Record<string, LanguageM
4754
4137
  declare const experimental_customProvider: typeof customProvider;
4755
4138
  type ExtractModelId<MODELS extends Record<string, unknown>> = Extract<keyof MODELS, string>;
4756
4139
 
4757
- declare const symbol: unique symbol;
4758
- declare class NoSuchProviderError extends NoSuchModelError {
4759
- private readonly [symbol];
4760
- readonly providerId: string;
4761
- readonly availableProviders: string[];
4762
- constructor({ modelId, modelType, providerId, availableProviders, message, }: {
4763
- modelId: string;
4764
- modelType: 'languageModel' | 'textEmbeddingModel';
4765
- providerId: string;
4766
- availableProviders: string[];
4767
- message?: string;
4768
- });
4769
- static isInstance(error: unknown): error is NoSuchProviderError;
4770
- }
4140
+ declare const symbol: unique symbol;
4141
+ declare class NoSuchProviderError extends NoSuchModelError {
4142
+ private readonly [symbol];
4143
+ readonly providerId: string;
4144
+ readonly availableProviders: string[];
4145
+ constructor({ modelId, modelType, providerId, availableProviders, message, }: {
4146
+ modelId: string;
4147
+ modelType: 'languageModel' | 'textEmbeddingModel';
4148
+ providerId: string;
4149
+ availableProviders: string[];
4150
+ message?: string;
4151
+ });
4152
+ static isInstance(error: unknown): error is NoSuchProviderError;
4153
+ }
4154
+
4155
+ type ExtractLiteralUnion<T> = T extends string ? string extends T ? never : T : never;
4156
+ interface ProviderRegistryProvider<PROVIDERS extends Record<string, ProviderV2> = Record<string, ProviderV2>, SEPARATOR extends string = ':'> {
4157
+ languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['languageModel']>>[0]>}` : never): LanguageModel;
4158
+ languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): LanguageModel;
4159
+ textEmbeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['textEmbeddingModel']>>[0]>}` : never): EmbeddingModel<string>;
4160
+ textEmbeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): EmbeddingModel<string>;
4161
+ imageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['imageModel']>>[0]>}` : never): ImageModel;
4162
+ imageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): ImageModel;
4163
+ }
4164
+ /**
4165
+ * Creates a registry for the given providers.
4166
+ */
4167
+ declare function createProviderRegistry<PROVIDERS extends Record<string, ProviderV2>, SEPARATOR extends string = ':'>(providers: PROVIDERS, { separator, }?: {
4168
+ separator?: SEPARATOR;
4169
+ }): ProviderRegistryProvider<PROVIDERS, SEPARATOR>;
4170
+ /**
4171
+ * @deprecated Use `createProviderRegistry` instead.
4172
+ */
4173
+ declare const experimental_createProviderRegistry: typeof createProviderRegistry;
4174
+
4175
+ /**
4176
+ The result of a `transcribe` call.
4177
+ It contains the transcript and additional information.
4178
+ */
4179
+ interface TranscriptionResult {
4180
+ /**
4181
+ * The complete transcribed text from the audio.
4182
+ */
4183
+ readonly text: string;
4184
+ /**
4185
+ * Array of transcript segments with timing information.
4186
+ * Each segment represents a portion of the transcribed text with start and end times.
4187
+ */
4188
+ readonly segments: Array<{
4189
+ /**
4190
+ * The text content of this segment.
4191
+ */
4192
+ readonly text: string;
4193
+ /**
4194
+ * The start time of this segment in seconds.
4195
+ */
4196
+ readonly startSecond: number;
4197
+ /**
4198
+ * The end time of this segment in seconds.
4199
+ */
4200
+ readonly endSecond: number;
4201
+ }>;
4202
+ /**
4203
+ * The detected language of the audio content, as an ISO-639-1 code (e.g., 'en' for English).
4204
+ * May be undefined if the language couldn't be detected.
4205
+ */
4206
+ readonly language: string | undefined;
4207
+ /**
4208
+ * The total duration of the audio file in seconds.
4209
+ * May be undefined if the duration couldn't be determined.
4210
+ */
4211
+ readonly durationInSeconds: number | undefined;
4212
+ /**
4213
+ Warnings for the call, e.g. unsupported settings.
4214
+ */
4215
+ readonly warnings: Array<TranscriptionWarning>;
4216
+ /**
4217
+ Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
4218
+ */
4219
+ readonly responses: Array<TranscriptionModelResponseMetadata>;
4220
+ /**
4221
+ Provider metadata from the provider.
4222
+ */
4223
+ readonly providerMetadata: Record<string, Record<string, JSONValue$1>>;
4224
+ }
4225
+
4226
+ /**
4227
+ Generates transcripts using a transcription model.
4228
+
4229
+ @param model - The transcription model to use.
4230
+ @param audio - The audio data to transcribe as DataContent (string | Uint8Array | ArrayBuffer | Buffer) or a URL.
4231
+ @param providerOptions - Additional provider-specific options that are passed through to the provider
4232
+ as body parameters.
4233
+ @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
4234
+ @param abortSignal - An optional abort signal that can be used to cancel the call.
4235
+ @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
4236
+
4237
+ @returns A result object that contains the generated transcript.
4238
+ */
4239
+ declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
4240
+ /**
4241
+ The transcription model to use.
4242
+ */
4243
+ model: TranscriptionModelV1;
4244
+ /**
4245
+ The audio data to transcribe.
4246
+ */
4247
+ audio: DataContent | URL;
4248
+ /**
4249
+ Additional provider-specific options that are passed through to the provider
4250
+ as body parameters.
4251
+
4252
+ The outer record is keyed by the provider name, and the inner
4253
+ record is keyed by the provider-specific metadata key.
4254
+ ```ts
4255
+ {
4256
+ "openai": {
4257
+ "temperature": 0
4258
+ }
4259
+ }
4260
+ ```
4261
+ */
4262
+ providerOptions?: ProviderOptions;
4263
+ /**
4264
+ Maximum number of retries per transcript model call. Set to 0 to disable retries.
4265
+
4266
+ @default 2
4267
+ */
4268
+ maxRetries?: number;
4269
+ /**
4270
+ Abort signal.
4271
+ */
4272
+ abortSignal?: AbortSignal;
4273
+ /**
4274
+ Additional headers to include in the request.
4275
+ Only applicable for HTTP-based providers.
4276
+ */
4277
+ headers?: Record<string, string>;
4278
+ }): Promise<TranscriptionResult>;
4279
+
4280
+ type UIMessageStreamPart = {
4281
+ type: 'text';
4282
+ text: string;
4283
+ } | {
4284
+ type: 'error';
4285
+ errorText: string;
4286
+ } | {
4287
+ type: 'tool-call';
4288
+ toolCallId: string;
4289
+ toolName: string;
4290
+ args: unknown;
4291
+ } | {
4292
+ type: 'tool-result';
4293
+ toolCallId: string;
4294
+ result: unknown;
4295
+ providerMetadata?: ProviderMetadata;
4296
+ } | {
4297
+ type: 'tool-call-streaming-start';
4298
+ toolCallId: string;
4299
+ toolName: string;
4300
+ } | {
4301
+ type: 'tool-call-delta';
4302
+ toolCallId: string;
4303
+ argsTextDelta: string;
4304
+ } | {
4305
+ type: 'reasoning';
4306
+ text: string;
4307
+ providerMetadata?: ProviderMetadata;
4308
+ } | {
4309
+ type: 'source';
4310
+ sourceType: 'url';
4311
+ id: string;
4312
+ url: string;
4313
+ title?: string;
4314
+ providerMetadata?: ProviderMetadata;
4315
+ } | {
4316
+ type: 'file';
4317
+ url: string;
4318
+ mediaType: string;
4319
+ } | {
4320
+ type: `data-${string}`;
4321
+ id?: string;
4322
+ data: unknown;
4323
+ } | {
4324
+ type: 'metadata';
4325
+ metadata: unknown;
4326
+ } | {
4327
+ type: 'start-step';
4328
+ metadata?: unknown;
4329
+ } | {
4330
+ type: 'finish-step';
4331
+ metadata?: unknown;
4332
+ } | {
4333
+ type: 'start';
4334
+ messageId?: string;
4335
+ metadata?: unknown;
4336
+ } | {
4337
+ type: 'finish';
4338
+ metadata?: unknown;
4339
+ } | {
4340
+ type: 'reasoning-part-finish';
4341
+ };
4342
+
4343
+ type Job = () => Promise<void>;
4344
+
4345
+ declare class SerialJobExecutor {
4346
+ private queue;
4347
+ private isProcessing;
4348
+ private processQueue;
4349
+ run(job: Job): Promise<void>;
4350
+ }
4351
+
4352
+ interface UIMessageStreamWriter {
4353
+ /**
4354
+ * Appends a data stream part to the stream.
4355
+ */
4356
+ write(part: UIMessageStreamPart): void;
4357
+ /**
4358
+ * Merges the contents of another stream to this stream.
4359
+ */
4360
+ merge(stream: ReadableStream<UIMessageStreamPart>): void;
4361
+ /**
4362
+ * Error handler that is used by the data stream writer.
4363
+ * This is intended for forwarding when merging streams
4364
+ * to prevent duplicated error masking.
4365
+ */
4366
+ onError: ((error: unknown) => string) | undefined;
4367
+ }
4368
+
4369
+ declare function createUIMessageStream({ execute, onError, }: {
4370
+ execute: (writer: UIMessageStreamWriter) => Promise<void> | void;
4371
+ onError?: (error: unknown) => string;
4372
+ }): ReadableStream<UIMessageStreamPart>;
4373
+
4374
+ declare function createUIMessageStreamResponse({ status, statusText, headers, stream, }: ResponseInit & {
4375
+ stream: ReadableStream<UIMessageStreamPart>;
4376
+ }): Response;
4377
+
4378
+ declare function pipeUIMessageStreamToResponse({ response, status, statusText, headers, stream, }: {
4379
+ response: ServerResponse;
4380
+ stream: ReadableStream<UIMessageStreamPart>;
4381
+ } & ResponseInit): void;
4382
+
4383
+ declare class JsonToSseTransformStream extends TransformStream<unknown, string> {
4384
+ constructor();
4385
+ }
4386
+
4387
+ interface ChatTransport<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> {
4388
+ submitMessages: (options: {
4389
+ chatId: string;
4390
+ messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
4391
+ abortController: AbortController;
4392
+ body?: object;
4393
+ headers?: Record<string, string> | Headers;
4394
+ requestType: 'generate' | 'resume';
4395
+ }) => Promise<ReadableStream<UIMessageStreamPart>>;
4396
+ }
4397
+ declare class DefaultChatTransport<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> implements ChatTransport<MESSAGE_METADATA, DATA_TYPES> {
4398
+ private api;
4399
+ private credentials?;
4400
+ private headers?;
4401
+ private body?;
4402
+ private streamProtocol?;
4403
+ private fetch?;
4404
+ private prepareRequestBody?;
4405
+ constructor({ api, credentials, headers, body, streamProtocol, fetch, prepareRequestBody, }: {
4406
+ api: string;
4407
+ /**
4408
+ * The credentials mode to be used for the fetch request.
4409
+ * Possible values are: 'omit', 'same-origin', 'include'.
4410
+ * Defaults to 'same-origin'.
4411
+ */
4412
+ credentials?: RequestCredentials;
4413
+ /**
4414
+ * HTTP headers to be sent with the API request.
4415
+ */
4416
+ headers?: Record<string, string> | Headers;
4417
+ /**
4418
+ * Extra body object to be sent with the API request.
4419
+ * @example
4420
+ * Send a `sessionId` to the API along with the messages.
4421
+ * ```js
4422
+ * useChat({
4423
+ * body: {
4424
+ * sessionId: '123',
4425
+ * }
4426
+ * })
4427
+ * ```
4428
+ */
4429
+ body?: object;
4430
+ /**
4431
+ Streaming protocol that is used. Defaults to `ui-message`.
4432
+ */
4433
+ streamProtocol?: 'ui-message' | 'text';
4434
+ /**
4435
+ Custom fetch implementation. You can use it as a middleware to intercept requests,
4436
+ or to provide a custom fetch implementation for e.g. testing.
4437
+ */
4438
+ fetch?: FetchFunction;
4439
+ /**
4440
+ * When a function is provided, it will be used
4441
+ * to prepare the request body for the chat API. This can be useful for
4442
+ * customizing the request body based on the messages and data in the chat.
4443
+ *
4444
+ * @param id The id of the chat.
4445
+ * @param messages The current messages in the chat.
4446
+ * @param requestBody The request body object passed in the chat request.
4447
+ */
4448
+ prepareRequestBody?: (options: {
4449
+ id: string;
4450
+ messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
4451
+ requestBody?: object;
4452
+ }) => unknown;
4453
+ });
4454
+ submitMessages({ chatId, messages, abortController, body, headers, requestType, }: Parameters<ChatTransport<MESSAGE_METADATA, DATA_TYPES>['submitMessages']>[0]): Promise<ReadableStream<UIMessageStreamPart>>;
4455
+ }
4456
+
4457
+ type StreamingUIMessageState<MESSAGE_METADATA = unknown, DATA_TYPES extends UIDataTypes = UIDataTypes> = {
4458
+ message: UIMessage<MESSAGE_METADATA, DATA_TYPES>;
4459
+ activeTextPart: TextUIPart | undefined;
4460
+ activeReasoningPart: ReasoningUIPart | undefined;
4461
+ partialToolCalls: Record<string, {
4462
+ text: string;
4463
+ step: number;
4464
+ index: number;
4465
+ toolName: string;
4466
+ }>;
4467
+ step: number;
4468
+ };
4469
+
4470
+ interface ChatStoreSubscriber {
4471
+ onChatChanged: (event: ChatStoreEvent) => void;
4472
+ }
4473
+ interface ChatStoreEvent {
4474
+ type: 'chat-messages-changed' | 'chat-status-changed';
4475
+ chatId: number | string;
4476
+ error?: Error;
4477
+ }
4478
+ type ChatStatus = 'submitted' | 'streaming' | 'ready' | 'error';
4479
+ interface Chat<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> {
4480
+ status: ChatStatus;
4481
+ messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
4482
+ error?: Error;
4483
+ activeResponse?: {
4484
+ state: StreamingUIMessageState<MESSAGE_METADATA>;
4485
+ abortController?: AbortController;
4486
+ };
4487
+ jobExecutor: SerialJobExecutor;
4488
+ }
4489
+ type ExtendedCallOptions<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> = ChatRequestOptions & {
4490
+ onError?: (error: Error) => void;
4491
+ /**
4492
+ Optional callback function that is invoked when a tool call is received.
4493
+ Intended for automatic client-side tool execution.
4494
+
4495
+ You can optionally return a result for the tool call,
4496
+ either synchronously or asynchronously.
4497
+ */
4498
+ onToolCall?: ({ toolCall, }: {
4499
+ toolCall: ToolCall<string, unknown>;
4500
+ }) => void | Promise<unknown> | unknown;
4501
+ /**
4502
+ * Optional callback function that is called when the assistant message is finished streaming.
4503
+ *
4504
+ * @param message The message that was streamed.
4505
+ */
4506
+ onFinish?: (options: {
4507
+ message: UIMessage<MESSAGE_METADATA, DATA_TYPES>;
4508
+ }) => void;
4509
+ };
4510
+ declare class ChatStore<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> {
4511
+ private chats;
4512
+ private subscribers;
4513
+ private generateId;
4514
+ private messageMetadataSchema;
4515
+ private transport;
4516
+ private maxSteps;
4517
+ constructor({ chats, generateId, messageMetadataSchema, transport, maxSteps, }: {
4518
+ chats?: {
4519
+ [id: string]: {
4520
+ messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
4521
+ };
4522
+ };
4523
+ generateId?: UseChatOptions['generateId'];
4524
+ messageMetadataSchema?: Schema<MESSAGE_METADATA>;
4525
+ transport: ChatTransport<MESSAGE_METADATA, DATA_TYPES>;
4526
+ maxSteps?: number;
4527
+ });
4528
+ hasChat(id: string): boolean;
4529
+ addChat(id: string, messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[]): void;
4530
+ getChats(): [string, Chat<MESSAGE_METADATA, DATA_TYPES>][];
4531
+ get chatCount(): number;
4532
+ getStatus(id: string): ChatStatus;
4533
+ setStatus({ id, status, error, }: {
4534
+ id: string;
4535
+ status: Chat<MESSAGE_METADATA, DATA_TYPES>['status'];
4536
+ error?: Error;
4537
+ }): void;
4538
+ getError(id: string): Error | undefined;
4539
+ getMessages(id: string): UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
4540
+ getLastMessage(id: string): UIMessage<MESSAGE_METADATA, DATA_TYPES>;
4541
+ subscribe(subscriber: ChatStoreSubscriber): () => void;
4542
+ setMessages({ id, messages, }: {
4543
+ id: string;
4544
+ messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
4545
+ }): void;
4546
+ removeAssistantResponse(id: string): void;
4547
+ submitMessage({ chatId, message, headers, body, onError, onToolCall, onFinish, }: ExtendedCallOptions<MESSAGE_METADATA, DATA_TYPES> & {
4548
+ chatId: string;
4549
+ message: CreateUIMessage<MESSAGE_METADATA, DATA_TYPES>;
4550
+ }): Promise<void>;
4551
+ resubmitLastUserMessage({ chatId, headers, body, onError, onToolCall, onFinish, }: ExtendedCallOptions<MESSAGE_METADATA, DATA_TYPES> & {
4552
+ chatId: string;
4553
+ }): Promise<null | undefined>;
4554
+ resumeStream({ chatId, headers, body, onError, onToolCall, onFinish, }: ExtendedCallOptions<MESSAGE_METADATA, DATA_TYPES> & {
4555
+ chatId: string;
4556
+ }): Promise<null | undefined>;
4557
+ addToolResult({ chatId, toolCallId, result, }: {
4558
+ chatId: string;
4559
+ toolCallId: string;
4560
+ result: unknown;
4561
+ }): Promise<void>;
4562
+ stopStream({ chatId }: {
4563
+ chatId: string;
4564
+ }): Promise<void>;
4565
+ private emit;
4566
+ private getChat;
4567
+ private triggerRequest;
4568
+ }
4569
+
4570
+ type ChatRequestOptions = {
4571
+ /**
4572
+ Additional headers that should be to be passed to the API endpoint.
4573
+ */
4574
+ headers?: Record<string, string> | Headers;
4575
+ /**
4576
+ Additional body JSON properties that should be sent to the API endpoint.
4577
+ */
4578
+ body?: object;
4579
+ };
4580
+ type UseChatOptions<MESSAGE_METADATA = unknown, DATA_TYPES extends UIDataTypes = UIDataTypes> = {
4581
+ /**
4582
+ * A unique identifier for the chat. If not provided, a random one will be
4583
+ * generated. When provided, the `useChat` hook with the same `id` will
4584
+ * have shared states across components.
4585
+ */
4586
+ id?: string;
4587
+ /**
4588
+ * Initial input of the chat.
4589
+ */
4590
+ initialInput?: string;
4591
+ /**
4592
+ Optional callback function that is invoked when a tool call is received.
4593
+ Intended for automatic client-side tool execution.
4594
+
4595
+ You can optionally return a result for the tool call,
4596
+ either synchronously or asynchronously.
4597
+ */
4598
+ onToolCall?: ({ toolCall, }: {
4599
+ toolCall: ToolCall<string, unknown>;
4600
+ }) => void | Promise<unknown> | unknown;
4601
+ /**
4602
+ * Optional callback function that is called when the assistant message is finished streaming.
4603
+ *
4604
+ * @param message The message that was streamed.
4605
+ */
4606
+ onFinish?: (options: {
4607
+ message: UIMessage<MESSAGE_METADATA, DATA_TYPES>;
4608
+ }) => void;
4609
+ /**
4610
+ * Callback function to be called when an error is encountered.
4611
+ */
4612
+ onError?: (error: Error) => void;
4613
+ /**
4614
+ * A way to provide a function that is going to be used for ids for messages and the chat.
4615
+ * If not provided the default AI SDK `generateId` is used.
4616
+ */
4617
+ generateId?: IdGenerator;
4618
+ /**
4619
+ * Optional chat store. Default is used when not provided.
4620
+ */
4621
+ chatStore?: ChatStore<MESSAGE_METADATA, DATA_TYPES>;
4622
+ };
4623
+ type OriginalUseChatOptions<MESSAGE_METADATA = unknown> = {
4624
+ /**
4625
+ * Schema for the message metadata. Validates the message metadata.
4626
+ * Message metadata can be undefined or must match the schema.
4627
+ */
4628
+ messageMetadataSchema?: Schema<MESSAGE_METADATA>;
4629
+ /**
4630
+ * The API endpoint that accepts a `{ messages: Message[] }` object and returns
4631
+ * a stream of tokens of the AI chat response. Defaults to `/api/chat`.
4632
+ */
4633
+ api?: string;
4634
+ /**
4635
+ * A unique identifier for the chat. If not provided, a random one will be
4636
+ * generated. When provided, the `useChat` hook with the same `id` will
4637
+ * have shared states across components.
4638
+ */
4639
+ id?: string;
4640
+ /**
4641
+ * Initial messages of the chat. Useful to load an existing chat history.
4642
+ */
4643
+ initialMessages?: UIMessage<NoInfer<MESSAGE_METADATA>>[];
4644
+ /**
4645
+ * Initial input of the chat.
4646
+ */
4647
+ initialInput?: string;
4648
+ /**
4649
+ Optional callback function that is invoked when a tool call is received.
4650
+ Intended for automatic client-side tool execution.
4651
+
4652
+ You can optionally return a result for the tool call,
4653
+ either synchronously or asynchronously.
4654
+ */
4655
+ onToolCall?: ({ toolCall, }: {
4656
+ toolCall: ToolCall<string, unknown>;
4657
+ }) => void | Promise<unknown> | unknown;
4658
+ /**
4659
+ * Optional callback function that is called when the assistant message is finished streaming.
4660
+ *
4661
+ * @param message The message that was streamed.
4662
+ */
4663
+ onFinish?: (options: {
4664
+ message: UIMessage<NoInfer<MESSAGE_METADATA>>;
4665
+ }) => void;
4666
+ /**
4667
+ * Callback function to be called when an error is encountered.
4668
+ */
4669
+ onError?: (error: Error) => void;
4670
+ /**
4671
+ * A way to provide a function that is going to be used for ids for messages and the chat.
4672
+ * If not provided the default AI SDK `generateId` is used.
4673
+ */
4674
+ generateId?: IdGenerator;
4675
+ /**
4676
+ * The credentials mode to be used for the fetch request.
4677
+ * Possible values are: 'omit', 'same-origin', 'include'.
4678
+ * Defaults to 'same-origin'.
4679
+ */
4680
+ credentials?: RequestCredentials;
4681
+ /**
4682
+ * HTTP headers to be sent with the API request.
4683
+ */
4684
+ headers?: Record<string, string> | Headers;
4685
+ /**
4686
+ * Extra body object to be sent with the API request.
4687
+ * @example
4688
+ * Send a `sessionId` to the API along with the messages.
4689
+ * ```js
4690
+ * useChat({
4691
+ * body: {
4692
+ * sessionId: '123',
4693
+ * }
4694
+ * })
4695
+ * ```
4696
+ */
4697
+ body?: object;
4698
+ /**
4699
+ Streaming protocol that is used. Defaults to `ui-message`.
4700
+ */
4701
+ streamProtocol?: 'ui-message' | 'text';
4702
+ /**
4703
+ Custom fetch implementation. You can use it as a middleware to intercept requests,
4704
+ or to provide a custom fetch implementation for e.g. testing.
4705
+ */
4706
+ fetch?: FetchFunction;
4707
+ /**
4708
+ Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
4709
+ Must be at least 1.
4710
+
4711
+ A maximum number is required to prevent infinite loops in the case of misconfigured tools.
4712
+
4713
+ By default, it's set to 1, which means that only a single LLM call is made.
4714
+ */
4715
+ maxSteps?: number;
4716
+ };
4717
+
4718
+ declare const getOriginalFetch$1: () => typeof fetch;
4719
+ declare function callChatApi<MESSAGE_METADATA>({ api, body, streamProtocol, credentials, headers, abortController, onUpdate, onFinish, onToolCall, generateId, fetch, lastMessage, requestType, messageMetadataSchema, }: {
4720
+ api: string;
4721
+ body: Record<string, any>;
4722
+ streamProtocol: 'ui-message' | 'text' | undefined;
4723
+ credentials: RequestCredentials | undefined;
4724
+ headers: HeadersInit | undefined;
4725
+ abortController: (() => AbortController | null) | undefined;
4726
+ onUpdate: (options: {
4727
+ message: UIMessage<MESSAGE_METADATA>;
4728
+ }) => void;
4729
+ onFinish: UseChatOptions<MESSAGE_METADATA>['onFinish'];
4730
+ onToolCall: UseChatOptions<MESSAGE_METADATA>['onToolCall'];
4731
+ generateId: IdGenerator;
4732
+ fetch: ReturnType<typeof getOriginalFetch$1> | undefined;
4733
+ lastMessage: UIMessage<MESSAGE_METADATA> | undefined;
4734
+ requestType?: 'generate' | 'resume';
4735
+ messageMetadataSchema?: Schema<MESSAGE_METADATA>;
4736
+ }): Promise<void>;
4737
+
4738
+ declare const getOriginalFetch: () => typeof fetch;
4739
+ declare function callCompletionApi({ api, prompt, credentials, headers, body, streamProtocol, setCompletion, setLoading, setError, setAbortController, onFinish, onError, fetch, }: {
4740
+ api: string;
4741
+ prompt: string;
4742
+ credentials: RequestCredentials | undefined;
4743
+ headers: HeadersInit | undefined;
4744
+ body: Record<string, any>;
4745
+ streamProtocol: 'data' | 'text' | undefined;
4746
+ setCompletion: (completion: string) => void;
4747
+ setLoading: (loading: boolean) => void;
4748
+ setError: (error: Error | undefined) => void;
4749
+ setAbortController: (abortController: AbortController | null) => void;
4750
+ onFinish: ((prompt: string, completion: string) => void) | undefined;
4751
+ onError: ((error: Error) => void) | undefined;
4752
+ fetch: ReturnType<typeof getOriginalFetch> | undefined;
4753
+ }): Promise<string | null | undefined>;
4754
+
4755
+ declare function convertFileListToFileUIParts(files: FileList | undefined): Promise<Array<FileUIPart>>;
4771
4756
 
4772
- type ExtractLiteralUnion<T> = T extends string ? string extends T ? never : T : never;
4773
- interface ProviderRegistryProvider<PROVIDERS extends Record<string, ProviderV2> = Record<string, ProviderV2>, SEPARATOR extends string = ':'> {
4774
- languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['languageModel']>>[0]>}` : never): LanguageModel;
4775
- languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): LanguageModel;
4776
- textEmbeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['textEmbeddingModel']>>[0]>}` : never): EmbeddingModel<string>;
4777
- textEmbeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): EmbeddingModel<string>;
4778
- imageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['imageModel']>>[0]>}` : never): ImageModel;
4779
- imageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): ImageModel;
4780
- }
4781
4757
  /**
4782
- * Creates a registry for the given providers.
4758
+ Converts an array of messages from useChat into an array of CoreMessages that can be used
4759
+ with the AI core functions (e.g. `streamText`).
4783
4760
  */
4784
- declare function createProviderRegistry<PROVIDERS extends Record<string, ProviderV2>, SEPARATOR extends string = ':'>(providers: PROVIDERS, { separator, }?: {
4785
- separator?: SEPARATOR;
4786
- }): ProviderRegistryProvider<PROVIDERS, SEPARATOR>;
4761
+ declare function convertToModelMessages<TOOLS extends ToolSet = never>(messages: Array<Omit<UIMessage, 'id'>>, options?: {
4762
+ tools?: TOOLS;
4763
+ }): ModelMessage[];
4787
4764
  /**
4788
- * @deprecated Use `createProviderRegistry` instead.
4765
+ @deprecated Use `convertToModelMessages` instead.
4789
4766
  */
4790
- declare const experimental_createProviderRegistry: typeof createProviderRegistry;
4767
+ declare const convertToCoreMessages: typeof convertToModelMessages;
4791
4768
 
4792
- /**
4793
- The result of a `transcribe` call.
4794
- It contains the transcript and additional information.
4795
- */
4796
- interface TranscriptionResult {
4769
+ declare function defaultChatStore<MESSAGE_METADATA = unknown, DATA_TYPES extends UIDataTypes = UIDataTypes>({ api, fetch, streamProtocol, credentials, headers, body, prepareRequestBody, generateId, messageMetadataSchema, maxSteps, chats, }: {
4797
4770
  /**
4798
- * The complete transcribed text from the audio.
4771
+ * Schema for the message metadata. Validates the message metadata.
4772
+ * Message metadata can be undefined or must match the schema.
4799
4773
  */
4800
- readonly text: string;
4774
+ messageMetadataSchema?: Schema<MESSAGE_METADATA>;
4801
4775
  /**
4802
- * Array of transcript segments with timing information.
4803
- * Each segment represents a portion of the transcribed text with start and end times.
4776
+ * The API endpoint that accepts a `{ messages: Message[] }` object and returns
4777
+ * a stream of tokens of the AI chat response.
4804
4778
  */
4805
- readonly segments: Array<{
4806
- /**
4807
- * The text content of this segment.
4808
- */
4809
- readonly text: string;
4810
- /**
4811
- * The start time of this segment in seconds.
4812
- */
4813
- readonly startSecond: number;
4814
- /**
4815
- * The end time of this segment in seconds.
4816
- */
4817
- readonly endSecond: number;
4818
- }>;
4779
+ api: string;
4819
4780
  /**
4820
- * The detected language of the audio content, as an ISO-639-1 code (e.g., 'en' for English).
4821
- * May be undefined if the language couldn't be detected.
4781
+ * A way to provide a function that is going to be used for ids for messages and the chat.
4782
+ * If not provided the default AI SDK `generateId` is used.
4822
4783
  */
4823
- readonly language: string | undefined;
4784
+ generateId?: IdGenerator;
4824
4785
  /**
4825
- * The total duration of the audio file in seconds.
4826
- * May be undefined if the duration couldn't be determined.
4786
+ * The credentials mode to be used for the fetch request.
4787
+ * Possible values are: 'omit', 'same-origin', 'include'.
4788
+ * Defaults to 'same-origin'.
4827
4789
  */
4828
- readonly durationInSeconds: number | undefined;
4790
+ credentials?: RequestCredentials;
4829
4791
  /**
4830
- Warnings for the call, e.g. unsupported settings.
4831
- */
4832
- readonly warnings: Array<TranscriptionWarning>;
4792
+ * HTTP headers to be sent with the API request.
4793
+ */
4794
+ headers?: Record<string, string> | Headers;
4833
4795
  /**
4834
- Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
4796
+ * Extra body object to be sent with the API request.
4797
+ * @example
4798
+ * Send a `sessionId` to the API along with the messages.
4799
+ * ```js
4800
+ * useChat({
4801
+ * body: {
4802
+ * sessionId: '123',
4803
+ * }
4804
+ * })
4805
+ * ```
4835
4806
  */
4836
- readonly responses: Array<TranscriptionModelResponseMetadata>;
4807
+ body?: object;
4837
4808
  /**
4838
- Provider metadata from the provider.
4809
+ Streaming protocol that is used. Defaults to `ui-message`.
4810
+ */
4811
+ streamProtocol?: 'ui-message' | 'text';
4812
+ /**
4813
+ Custom fetch implementation. You can use it as a middleware to intercept requests,
4814
+ or to provide a custom fetch implementation for e.g. testing.
4815
+ */
4816
+ fetch?: FetchFunction;
4817
+ /**
4818
+ Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
4819
+ Must be at least 1.
4820
+
4821
+ A maximum number is required to prevent infinite loops in the case of misconfigured tools.
4822
+
4823
+ By default, it's set to 1, which means that only a single LLM call is made.
4824
+ */
4825
+ maxSteps?: number;
4826
+ /**
4827
+ * When a function is provided, it will be used
4828
+ * to prepare the request body for the chat API. This can be useful for
4829
+ * customizing the request body based on the messages and data in the chat.
4830
+ *
4831
+ * @param id The id of the chat.
4832
+ * @param messages The current messages in the chat.
4833
+ * @param requestBody The request body object passed in the chat request.
4839
4834
  */
4840
- readonly providerMetadata: Record<string, Record<string, JSONValue$1>>;
4841
- }
4835
+ prepareRequestBody?: (options: {
4836
+ id: string;
4837
+ messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
4838
+ requestBody?: object;
4839
+ }) => unknown;
4840
+ chats?: {
4841
+ [id: string]: {
4842
+ messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
4843
+ };
4844
+ };
4845
+ }): ChatStore<MESSAGE_METADATA, DATA_TYPES>;
4842
4846
 
4843
- /**
4844
- Generates transcripts using a transcription model.
4847
+ declare function extractMaxToolInvocationStep(toolInvocations: ToolInvocation[] | undefined): number | undefined;
4845
4848
 
4846
- @param model - The transcription model to use.
4847
- @param audio - The audio data to transcribe as DataContent (string | Uint8Array | ArrayBuffer | Buffer) or a URL.
4848
- @param providerOptions - Additional provider-specific options that are passed through to the provider
4849
- as body parameters.
4850
- @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
4851
- @param abortSignal - An optional abort signal that can be used to cancel the call.
4852
- @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
4849
+ declare function getToolInvocations(message: UIMessage): ToolInvocation[];
4853
4850
 
4854
- @returns A result object that contains the generated transcript.
4851
+ declare function shouldResubmitMessages({ originalMaxToolInvocationStep, originalMessageCount, maxSteps, messages, }: {
4852
+ originalMaxToolInvocationStep: number | undefined;
4853
+ originalMessageCount: number;
4854
+ maxSteps: number;
4855
+ messages: UIMessage[];
4856
+ }): boolean;
4857
+ /**
4858
+ Check if the message is an assistant message with completed tool calls.
4859
+ The last step of the message must have at least one tool invocation and
4860
+ all tool invocations must have a result.
4855
4861
  */
4856
- declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
4862
+ declare function isAssistantMessageWithCompletedToolCalls(message: UIMessage): message is UIMessage & {
4863
+ role: 'assistant';
4864
+ };
4865
+
4866
+ /**
4867
+ * Updates the result of a specific tool invocation in the last message of the given messages array.
4868
+ *
4869
+ * @param {object} params - The parameters object.
4870
+ * @param {UIMessage[]} params.messages - An array of messages, from which the last one is updated.
4871
+ * @param {string} params.toolCallId - The unique identifier for the tool invocation to update.
4872
+ * @param {unknown} params.toolResult - The result object to attach to the tool invocation.
4873
+ * @returns {void} This function does not return anything.
4874
+ */
4875
+ declare function updateToolCallResult({ messages, toolCallId, toolResult: result, }: {
4876
+ messages: UIMessage[];
4877
+ toolCallId: string;
4878
+ toolResult: unknown;
4879
+ }): void;
4880
+
4881
+ type CompletionRequestOptions = {
4857
4882
  /**
4858
- The transcription model to use.
4883
+ An optional object of headers to be passed to the API endpoint.
4884
+ */
4885
+ headers?: Record<string, string> | Headers;
4886
+ /**
4887
+ An optional object to be passed to the API endpoint.
4859
4888
  */
4860
- model: TranscriptionModelV1;
4889
+ body?: object;
4890
+ };
4891
+ type UseCompletionOptions = {
4861
4892
  /**
4862
- The audio data to transcribe.
4893
+ * The API endpoint that accepts a `{ prompt: string }` object and returns
4894
+ * a stream of tokens of the AI completion response. Defaults to `/api/completion`.
4863
4895
  */
4864
- audio: DataContent | URL;
4896
+ api?: string;
4865
4897
  /**
4866
- Additional provider-specific options that are passed through to the provider
4867
- as body parameters.
4868
-
4869
- The outer record is keyed by the provider name, and the inner
4870
- record is keyed by the provider-specific metadata key.
4871
- ```ts
4872
- {
4873
- "openai": {
4874
- "temperature": 0
4875
- }
4876
- }
4877
- ```
4878
- */
4879
- providerOptions?: ProviderOptions;
4898
+ * An unique identifier for the chat. If not provided, a random one will be
4899
+ * generated. When provided, the `useChat` hook with the same `id` will
4900
+ * have shared states across components.
4901
+ */
4902
+ id?: string;
4880
4903
  /**
4881
- Maximum number of retries per transcript model call. Set to 0 to disable retries.
4882
-
4883
- @default 2
4904
+ * Initial prompt input of the completion.
4884
4905
  */
4885
- maxRetries?: number;
4906
+ initialInput?: string;
4886
4907
  /**
4887
- Abort signal.
4888
- */
4889
- abortSignal?: AbortSignal;
4908
+ * Initial completion result. Useful to load an existing history.
4909
+ */
4910
+ initialCompletion?: string;
4890
4911
  /**
4891
- Additional headers to include in the request.
4892
- Only applicable for HTTP-based providers.
4893
- */
4894
- headers?: Record<string, string>;
4895
- }): Promise<TranscriptionResult>;
4912
+ * Callback function to be called when the completion is finished streaming.
4913
+ */
4914
+ onFinish?: (prompt: string, completion: string) => void;
4915
+ /**
4916
+ * Callback function to be called when an error is encountered.
4917
+ */
4918
+ onError?: (error: Error) => void;
4919
+ /**
4920
+ * The credentials mode to be used for the fetch request.
4921
+ * Possible values are: 'omit', 'same-origin', 'include'.
4922
+ * Defaults to 'same-origin'.
4923
+ */
4924
+ credentials?: RequestCredentials;
4925
+ /**
4926
+ * HTTP headers to be sent with the API request.
4927
+ */
4928
+ headers?: Record<string, string> | Headers;
4929
+ /**
4930
+ * Extra body object to be sent with the API request.
4931
+ * @example
4932
+ * Send a `sessionId` to the API along with the prompt.
4933
+ * ```js
4934
+ * useChat({
4935
+ * body: {
4936
+ * sessionId: '123',
4937
+ * }
4938
+ * })
4939
+ * ```
4940
+ */
4941
+ body?: object;
4942
+ /**
4943
+ Streaming protocol that is used. Defaults to `data`.
4944
+ */
4945
+ streamProtocol?: 'data' | 'text';
4946
+ /**
4947
+ Custom fetch implementation. You can use it as a middleware to intercept requests,
4948
+ or to provide a custom fetch implementation for e.g. testing.
4949
+ */
4950
+ fetch?: FetchFunction;
4951
+ };
4896
4952
 
4897
- export { AssistantContent, AssistantModelMessage, CallSettings, CallWarning, ChatRequestOptions, ChunkDetector, CompletionRequestOptions, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataContent, DeepPartial, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FilePart, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, ImagePart, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolArgumentsError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, MessageConversionError, ModelMessage, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, Prompt, Provider, ProviderMetadata, ProviderOptions, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RetryError, SourceUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, SystemModelMessage, TelemetrySettings, TextPart, TextStreamPart, TextUIPart, Tool, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolInvocation, ToolInvocationUIPart, ToolModelMessage, ToolResultPart, ToolResultUnion, ToolSet, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIMessage, UIMessagePart, UIMessageStreamOptions, UIMessageStreamPart, UIMessageStreamWriter, UseChatOptions, UseCompletionOptions, UserContent, UserModelMessage, appendClientMessage, assistantModelMessageSchema, callChatApi, callCompletionApi, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractMaxToolInvocationStep, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolInvocations, isAssistantMessageWithCompletedToolCalls, isDeepEqualData, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, processTextStream, shouldResubmitMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, streamObject, streamText, systemModelMessageSchema, tool, toolModelMessageSchema, updateToolCallResult, userModelMessageSchema, wrapLanguageModel };
4953
+ export { AssistantContent, AssistantModelMessage, CallSettings, CallWarning, ChatRequestOptions, ChatStatus, ChatStore, ChatStoreEvent, ChatTransport, ChunkDetector, CompletionRequestOptions, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataContent, DataUIPart, DeepPartial, DefaultChatTransport, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FilePart, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, ImagePart, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolArgumentsError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, MessageConversionError, ModelMessage, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, OriginalUseChatOptions, output as Output, Prompt, Provider, ProviderMetadata, ProviderOptions, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RetryError, SourceUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, SystemModelMessage, TelemetrySettings, TextPart, TextStreamPart, TextUIPart, Tool, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolInvocation, ToolInvocationUIPart, ToolModelMessage, ToolResultPart, ToolResultUnion, ToolSet, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIDataTypes, UIMessage, UIMessagePart, UIMessageStreamOptions, UIMessageStreamPart, UIMessageStreamWriter, UseChatOptions, UseCompletionOptions, UserContent, UserModelMessage, appendClientMessage, assistantModelMessageSchema, callChatApi, callCompletionApi, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultChatStore, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractMaxToolInvocationStep, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolInvocations, hasToolCall, isAssistantMessageWithCompletedToolCalls, isDeepEqualData, maxSteps, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, shouldResubmitMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, streamObject, streamText, systemModelMessageSchema, tool, toolModelMessageSchema, updateToolCallResult, userModelMessageSchema, wrapLanguageModel };