ai 6.0.91 → 6.0.93

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.
@@ -861,20 +861,524 @@ To see `generateText` in action, check out [these examples](#examples).
861
861
  },
862
862
  ],
863
863
  },
864
+ {
865
+ name: 'experimental_onStart',
866
+ type: '(event: OnStartEvent) => PromiseLike<void> | void',
867
+ isOptional: true,
868
+ description:
869
+ 'Callback that is called when the generateText operation begins, before any LLM calls are made. Errors thrown in this callback are silently caught and do not break the generation flow. Experimental (can break in patch releases).',
870
+ properties: [
871
+ {
872
+ type: 'OnStartEvent',
873
+ parameters: [
874
+ {
875
+ name: 'model',
876
+ type: '{ provider: string; modelId: string }',
877
+ description: 'The model being used for the generation.',
878
+ },
879
+ {
880
+ name: 'system',
881
+ type: 'string | SystemModelMessage | Array<SystemModelMessage> | undefined',
882
+ description: 'The system message(s) provided to the model.',
883
+ },
884
+ {
885
+ name: 'prompt',
886
+ type: 'string | Array<ModelMessage> | undefined',
887
+ description:
888
+ 'The prompt string or array of messages if using the prompt option.',
889
+ },
890
+ {
891
+ name: 'messages',
892
+ type: 'Array<ModelMessage> | undefined',
893
+ description: 'The messages array if using the messages option.',
894
+ },
895
+ {
896
+ name: 'tools',
897
+ type: 'TOOLS | undefined',
898
+ description: 'The tools available for this generation.',
899
+ },
900
+ {
901
+ name: 'toolChoice',
902
+ type: 'ToolChoice<TOOLS> | undefined',
903
+ description: 'The tool choice strategy for this generation.',
904
+ },
905
+ {
906
+ name: 'activeTools',
907
+ type: 'Array<keyof TOOLS> | undefined',
908
+ description:
909
+ 'Limits which tools are available for the model to call.',
910
+ },
911
+ {
912
+ name: 'maxOutputTokens',
913
+ type: 'number | undefined',
914
+ description: 'Maximum number of tokens to generate.',
915
+ },
916
+ {
917
+ name: 'temperature',
918
+ type: 'number | undefined',
919
+ description: 'Sampling temperature for generation.',
920
+ },
921
+ {
922
+ name: 'topP',
923
+ type: 'number | undefined',
924
+ description: 'Top-p (nucleus) sampling parameter.',
925
+ },
926
+ {
927
+ name: 'topK',
928
+ type: 'number | undefined',
929
+ description: 'Top-k sampling parameter.',
930
+ },
931
+ {
932
+ name: 'presencePenalty',
933
+ type: 'number | undefined',
934
+ description: 'Presence penalty for generation.',
935
+ },
936
+ {
937
+ name: 'frequencyPenalty',
938
+ type: 'number | undefined',
939
+ description: 'Frequency penalty for generation.',
940
+ },
941
+ {
942
+ name: 'stopSequences',
943
+ type: 'string[] | undefined',
944
+ description: 'Sequences that will stop generation.',
945
+ },
946
+ {
947
+ name: 'seed',
948
+ type: 'number | undefined',
949
+ description: 'Random seed for reproducible generation.',
950
+ },
951
+ {
952
+ name: 'maxRetries',
953
+ type: 'number',
954
+ description: 'Maximum number of retries for failed requests.',
955
+ },
956
+ {
957
+ name: 'timeout',
958
+ type: 'number | { totalMs?: number; stepMs?: number; chunkMs?: number } | undefined',
959
+ description:
960
+ 'Timeout configuration for the generation. Can be a number (milliseconds) or an object with totalMs, stepMs, chunkMs.',
961
+ },
962
+ {
963
+ name: 'headers',
964
+ type: 'Record<string, string | undefined> | undefined',
965
+ description: 'Additional HTTP headers sent with the request.',
966
+ },
967
+ {
968
+ name: 'providerOptions',
969
+ type: 'ProviderOptions | undefined',
970
+ description: 'Additional provider-specific options.',
971
+ },
972
+ {
973
+ name: 'stopWhen',
974
+ type: 'StopCondition<TOOLS> | Array<StopCondition<TOOLS>> | undefined',
975
+ description:
976
+ 'Condition(s) for stopping the generation. When the condition is an array, any of the conditions can be met to stop.',
977
+ },
978
+ {
979
+ name: 'output',
980
+ type: 'OUTPUT | undefined',
981
+ description:
982
+ 'The output specification for structured outputs, if configured.',
983
+ },
984
+ {
985
+ name: 'abortSignal',
986
+ type: 'AbortSignal | undefined',
987
+ description: 'Abort signal for cancelling the operation.',
988
+ },
989
+ {
990
+ name: 'include',
991
+ type: '{ requestBody?: boolean; responseBody?: boolean } | undefined',
992
+ description:
993
+ 'Settings for controlling what data is included in step results.',
994
+ },
995
+ {
996
+ name: 'functionId',
997
+ type: 'string | undefined',
998
+ description:
999
+ 'Identifier from telemetry settings for grouping related operations.',
1000
+ },
1001
+ {
1002
+ name: 'metadata',
1003
+ type: 'Record<string, unknown> | undefined',
1004
+ description: 'Additional metadata passed to the generation.',
1005
+ },
1006
+ {
1007
+ name: 'experimental_context',
1008
+ type: 'unknown',
1009
+ description:
1010
+ 'User-defined context object that flows through the entire generation lifecycle.',
1011
+ },
1012
+ ],
1013
+ },
1014
+ ],
1015
+ },
1016
+ {
1017
+ name: 'experimental_onStepStart',
1018
+ type: '(event: OnStepStartEvent) => PromiseLike<void> | void',
1019
+ isOptional: true,
1020
+ description:
1021
+ 'Callback that is called when a step (LLM call) begins, before the provider is called. Errors thrown in this callback are silently caught and do not break the generation flow. Experimental (can break in patch releases).',
1022
+ properties: [
1023
+ {
1024
+ type: 'OnStepStartEvent',
1025
+ parameters: [
1026
+ {
1027
+ name: 'stepNumber',
1028
+ type: 'number',
1029
+ description: 'Zero-based index of the current step.',
1030
+ },
1031
+ {
1032
+ name: 'model',
1033
+ type: '{ provider: string; modelId: string }',
1034
+ description: 'The model being used for this step.',
1035
+ },
1036
+ {
1037
+ name: 'system',
1038
+ type: 'string | SystemModelMessage | Array<SystemModelMessage> | undefined',
1039
+ description: 'The system message for this step.',
1040
+ },
1041
+ {
1042
+ name: 'messages',
1043
+ type: 'Array<ModelMessage>',
1044
+ description:
1045
+ 'The messages that will be sent to the model for this step. Uses the user-facing ModelMessage format. May be overridden by prepareStep.',
1046
+ },
1047
+ {
1048
+ name: 'tools',
1049
+ type: 'TOOLS | undefined',
1050
+ description: 'The tools available for this generation.',
1051
+ },
1052
+ {
1053
+ name: 'toolChoice',
1054
+ type: 'LanguageModelV3ToolChoice | undefined',
1055
+ description: 'The tool choice configuration for this step.',
1056
+ },
1057
+ {
1058
+ name: 'activeTools',
1059
+ type: 'Array<keyof TOOLS> | undefined',
1060
+ description: 'Limits which tools are available for this step.',
1061
+ },
1062
+ {
1063
+ name: 'steps',
1064
+ type: 'ReadonlyArray<StepResult<TOOLS>>',
1065
+ description:
1066
+ 'Array of results from previous steps (empty for first step).',
1067
+ },
1068
+ {
1069
+ name: 'providerOptions',
1070
+ type: 'ProviderOptions | undefined',
1071
+ description:
1072
+ 'Additional provider-specific options for this step.',
1073
+ },
1074
+ {
1075
+ name: 'timeout',
1076
+ type: 'number | { totalMs?: number; stepMs?: number; chunkMs?: number } | undefined',
1077
+ description:
1078
+ 'Timeout configuration for the generation. Can be a number (milliseconds) or an object with totalMs, stepMs, chunkMs.',
1079
+ },
1080
+ {
1081
+ name: 'headers',
1082
+ type: 'Record<string, string | undefined> | undefined',
1083
+ description: 'Additional HTTP headers sent with the request.',
1084
+ },
1085
+ {
1086
+ name: 'stopWhen',
1087
+ type: 'StopCondition<TOOLS> | Array<StopCondition<TOOLS>> | undefined',
1088
+ description:
1089
+ 'Condition(s) for stopping the generation. When the condition is an array, any of the conditions can be met to stop.',
1090
+ },
1091
+ {
1092
+ name: 'output',
1093
+ type: 'OUTPUT | undefined',
1094
+ description:
1095
+ 'The output specification for structured outputs, if configured.',
1096
+ },
1097
+ {
1098
+ name: 'abortSignal',
1099
+ type: 'AbortSignal | undefined',
1100
+ description: 'Abort signal for cancelling the operation.',
1101
+ },
1102
+ {
1103
+ name: 'include',
1104
+ type: '{ requestBody?: boolean; responseBody?: boolean } | undefined',
1105
+ description:
1106
+ 'Settings for controlling what data is included in step results.',
1107
+ },
1108
+ {
1109
+ name: 'functionId',
1110
+ type: 'string | undefined',
1111
+ description:
1112
+ 'Identifier from telemetry settings for grouping related operations.',
1113
+ },
1114
+ {
1115
+ name: 'metadata',
1116
+ type: 'Record<string, unknown> | undefined',
1117
+ description: 'Additional metadata from telemetry settings.',
1118
+ },
1119
+ {
1120
+ name: 'experimental_context',
1121
+ type: 'unknown',
1122
+ description:
1123
+ 'User-defined context object. May be updated from prepareStep between steps.',
1124
+ },
1125
+ ],
1126
+ },
1127
+ ],
1128
+ },
1129
+ {
1130
+ name: 'experimental_onToolCallStart',
1131
+ type: '(event: OnToolCallStartEvent) => PromiseLike<void> | void',
1132
+ isOptional: true,
1133
+ description:
1134
+ "Callback that is called right before a tool's execute function runs. Errors thrown in this callback are silently caught and do not break the generation flow. Experimental (can break in patch releases).",
1135
+ properties: [
1136
+ {
1137
+ type: 'OnToolCallStartEvent',
1138
+ parameters: [
1139
+ {
1140
+ name: 'stepNumber',
1141
+ type: 'number | undefined',
1142
+ description:
1143
+ 'The zero-based index of the current step where this tool call occurs. May be undefined in streaming contexts.',
1144
+ },
1145
+ {
1146
+ name: 'model',
1147
+ type: '{ provider: string; modelId: string } | undefined',
1148
+ description:
1149
+ 'Information about the model being used. May be undefined in streaming contexts.',
1150
+ },
1151
+ {
1152
+ name: 'toolCall',
1153
+ type: 'TypedToolCall<TOOLS>',
1154
+ description:
1155
+ 'The full tool call object containing toolName, toolCallId, input, and metadata.',
1156
+ },
1157
+ {
1158
+ name: 'messages',
1159
+ type: 'Array<ModelMessage>',
1160
+ description:
1161
+ 'The conversation messages available at tool execution time.',
1162
+ },
1163
+ {
1164
+ name: 'abortSignal',
1165
+ type: 'AbortSignal | undefined',
1166
+ description: 'Signal for cancelling the operation.',
1167
+ },
1168
+ {
1169
+ name: 'functionId',
1170
+ type: 'string | undefined',
1171
+ description:
1172
+ 'Identifier from telemetry settings for grouping related operations.',
1173
+ },
1174
+ {
1175
+ name: 'metadata',
1176
+ type: 'Record<string, unknown> | undefined',
1177
+ description: 'Additional metadata from telemetry settings.',
1178
+ },
1179
+ {
1180
+ name: 'experimental_context',
1181
+ type: 'unknown',
1182
+ description:
1183
+ 'User-defined context object flowing through the generation.',
1184
+ },
1185
+ ],
1186
+ },
1187
+ ],
1188
+ },
1189
+ {
1190
+ name: 'experimental_onToolCallFinish',
1191
+ type: '(event: OnToolCallFinishEvent) => PromiseLike<void> | void',
1192
+ isOptional: true,
1193
+ description:
1194
+ "Callback that is called right after a tool's execute function completes (or errors). Uses a discriminated union on the `success` field: when `success: true`, `output` contains the tool result; when `success: false`, `error` contains the error. Errors thrown in this callback are silently caught and do not break the generation flow. Experimental (can break in patch releases).",
1195
+ properties: [
1196
+ {
1197
+ type: 'OnToolCallFinishEvent',
1198
+ parameters: [
1199
+ {
1200
+ name: 'stepNumber',
1201
+ type: 'number | undefined',
1202
+ description:
1203
+ 'The zero-based index of the current step where this tool call occurred. May be undefined in streaming contexts.',
1204
+ },
1205
+ {
1206
+ name: 'model',
1207
+ type: '{ provider: string; modelId: string } | undefined',
1208
+ description:
1209
+ 'Information about the model being used. May be undefined in streaming contexts.',
1210
+ },
1211
+ {
1212
+ name: 'toolCall',
1213
+ type: 'TypedToolCall<TOOLS>',
1214
+ description:
1215
+ 'The full tool call object containing toolName, toolCallId, input, and metadata.',
1216
+ },
1217
+ {
1218
+ name: 'messages',
1219
+ type: 'Array<ModelMessage>',
1220
+ description:
1221
+ 'The conversation messages available at tool execution time.',
1222
+ },
1223
+ {
1224
+ name: 'abortSignal',
1225
+ type: 'AbortSignal | undefined',
1226
+ description: 'Signal for cancelling the operation.',
1227
+ },
1228
+ {
1229
+ name: 'durationMs',
1230
+ type: 'number',
1231
+ description:
1232
+ 'The wall-clock duration of the tool execution in milliseconds.',
1233
+ },
1234
+ {
1235
+ name: 'functionId',
1236
+ type: 'string | undefined',
1237
+ description:
1238
+ 'Identifier from telemetry settings for grouping related operations.',
1239
+ },
1240
+ {
1241
+ name: 'metadata',
1242
+ type: 'Record<string, unknown> | undefined',
1243
+ description: 'Additional metadata from telemetry settings.',
1244
+ },
1245
+ {
1246
+ name: 'experimental_context',
1247
+ type: 'unknown',
1248
+ description:
1249
+ 'User-defined context object flowing through the generation.',
1250
+ },
1251
+ {
1252
+ name: 'success',
1253
+ type: 'boolean',
1254
+ description:
1255
+ 'Discriminator indicating whether the tool call succeeded. When true, output is available. When false, error is available.',
1256
+ },
1257
+ {
1258
+ name: 'output',
1259
+ type: 'unknown',
1260
+ description:
1261
+ "The tool's return value (only present when `success: true`).",
1262
+ },
1263
+ {
1264
+ name: 'error',
1265
+ type: 'unknown',
1266
+ description:
1267
+ 'The error that occurred during tool execution (only present when `success: false`).',
1268
+ },
1269
+ ],
1270
+ },
1271
+ ],
1272
+ },
864
1273
  {
865
1274
  name: 'onStepFinish',
866
- type: '(result: OnStepFinishResult) => Promise<void> | void',
1275
+ type: '(stepResult: StepResult<TOOLS>) => Promise<void> | void',
867
1276
  isOptional: true,
868
- description: 'Callback that is called when a step is finished.',
1277
+ description:
1278
+ 'Callback that is called when a step is finished. Receives a StepResult object.',
869
1279
  properties: [
870
1280
  {
871
- type: 'OnStepFinishResult',
1281
+ type: 'StepResult',
872
1282
  parameters: [
1283
+ {
1284
+ name: 'stepNumber',
1285
+ type: 'number',
1286
+ description: 'Zero-based index of this step.',
1287
+ },
1288
+ {
1289
+ name: 'model',
1290
+ type: '{ provider: string; modelId: string }',
1291
+ description:
1292
+ 'Information about the model that produced this step.',
1293
+ },
1294
+ {
1295
+ name: 'functionId',
1296
+ type: 'string | undefined',
1297
+ description:
1298
+ 'Identifier from telemetry settings for grouping related operations.',
1299
+ },
1300
+ {
1301
+ name: 'metadata',
1302
+ type: 'Record<string, unknown> | undefined',
1303
+ description: 'Additional metadata from telemetry settings.',
1304
+ },
1305
+ {
1306
+ name: 'experimental_context',
1307
+ type: 'unknown',
1308
+ description:
1309
+ 'User-defined context object flowing through the generation.',
1310
+ },
1311
+ {
1312
+ name: 'content',
1313
+ type: 'Array<ContentPart<TOOLS>>',
1314
+ description: 'The content that was generated in this step.',
1315
+ },
1316
+ {
1317
+ name: 'text',
1318
+ type: 'string',
1319
+ description: 'The generated text.',
1320
+ },
1321
+ {
1322
+ name: 'reasoning',
1323
+ type: 'Array<ReasoningPart>',
1324
+ description:
1325
+ 'The reasoning that was generated during the generation.',
1326
+ },
1327
+ {
1328
+ name: 'reasoningText',
1329
+ type: 'string | undefined',
1330
+ description:
1331
+ 'The reasoning text that was generated during the generation.',
1332
+ },
1333
+ {
1334
+ name: 'files',
1335
+ type: 'Array<GeneratedFile>',
1336
+ description:
1337
+ 'The files that were generated during the generation.',
1338
+ },
1339
+ {
1340
+ name: 'sources',
1341
+ type: 'Array<Source>',
1342
+ description: 'The sources that were used to generate the text.',
1343
+ },
1344
+ {
1345
+ name: 'toolCalls',
1346
+ type: 'Array<TypedToolCall<TOOLS>>',
1347
+ description:
1348
+ 'The tool calls that were made during the generation.',
1349
+ },
1350
+ {
1351
+ name: 'staticToolCalls',
1352
+ type: 'Array<StaticToolCall<TOOLS>>',
1353
+ description: 'The static tool calls that were made in this step.',
1354
+ },
1355
+ {
1356
+ name: 'dynamicToolCalls',
1357
+ type: 'Array<DynamicToolCall>',
1358
+ description:
1359
+ 'The dynamic tool calls that were made in this step.',
1360
+ },
1361
+ {
1362
+ name: 'toolResults',
1363
+ type: 'Array<TypedToolResult<TOOLS>>',
1364
+ description: 'The results of the tool calls.',
1365
+ },
1366
+ {
1367
+ name: 'staticToolResults',
1368
+ type: 'Array<StaticToolResult<TOOLS>>',
1369
+ description:
1370
+ 'The static tool results that were made in this step.',
1371
+ },
1372
+ {
1373
+ name: 'dynamicToolResults',
1374
+ type: 'Array<DynamicToolResult>',
1375
+ description:
1376
+ 'The dynamic tool results that were made in this step.',
1377
+ },
873
1378
  {
874
1379
  name: 'finishReason',
875
1380
  type: '"stop" | "length" | "content-filter" | "tool-calls" | "error" | "other"',
876
- description:
877
- 'The reason the model finished generating the text for the step.',
1381
+ description: 'The unified reason why the generation finished.',
878
1382
  },
879
1383
  {
880
1384
  name: 'rawFinishReason',
@@ -885,98 +1389,7 @@ To see `generateText` in action, check out [these examples](#examples).
885
1389
  {
886
1390
  name: 'usage',
887
1391
  type: 'LanguageModelUsage',
888
- description: 'The token usage of last step.',
889
- properties: [
890
- {
891
- type: 'LanguageModelUsage',
892
- parameters: [
893
- {
894
- name: 'inputTokens',
895
- type: 'number | undefined',
896
- description:
897
- 'The total number of input (prompt) tokens used.',
898
- },
899
- {
900
- name: 'inputTokenDetails',
901
- type: 'LanguageModelInputTokenDetails',
902
- description:
903
- 'Detailed information about the input (prompt) tokens. See also: cached tokens and non-cached tokens.',
904
- properties: [
905
- {
906
- type: 'LanguageModelInputTokenDetails',
907
- parameters: [
908
- {
909
- name: 'noCacheTokens',
910
- type: 'number | undefined',
911
- description:
912
- 'The number of non-cached input (prompt) tokens used.',
913
- },
914
- {
915
- name: 'cacheReadTokens',
916
- type: 'number | undefined',
917
- description:
918
- 'The number of cached input (prompt) tokens read.',
919
- },
920
- {
921
- name: 'cacheWriteTokens',
922
- type: 'number | undefined',
923
- description:
924
- 'The number of cached input (prompt) tokens written.',
925
- },
926
- ],
927
- },
928
- ],
929
- },
930
- {
931
- name: 'outputTokens',
932
- type: 'number | undefined',
933
- description:
934
- 'The number of total output (completion) tokens used.',
935
- },
936
- {
937
- name: 'outputTokenDetails',
938
- type: 'LanguageModelOutputTokenDetails',
939
- description:
940
- 'Detailed information about the output (completion) tokens.',
941
- properties: [
942
- {
943
- type: 'LanguageModelOutputTokenDetails',
944
- parameters: [
945
- {
946
- name: 'textTokens',
947
- type: 'number | undefined',
948
- description: 'The number of text tokens used.',
949
- },
950
- {
951
- name: 'reasoningTokens',
952
- type: 'number | undefined',
953
- description:
954
- 'The number of reasoning tokens used.',
955
- },
956
- ],
957
- },
958
- ],
959
- },
960
- {
961
- name: 'totalTokens',
962
- type: 'number | undefined',
963
- description: 'The total number of tokens used.',
964
- },
965
- {
966
- name: 'raw',
967
- type: 'object | undefined',
968
- isOptional: true,
969
- description:
970
- "Raw usage information from the provider. This is the provider's original usage information and may include additional fields.",
971
- },
972
- ],
973
- },
974
- ],
975
- },
976
- {
977
- name: 'totalUsage',
978
- type: 'LanguageModelUsage',
979
- description: 'The total token usage from all steps.',
1392
+ description: 'The token usage of the generated text.',
980
1393
  properties: [
981
1394
  {
982
1395
  type: 'LanguageModelUsage',
@@ -991,7 +1404,7 @@ To see `generateText` in action, check out [these examples](#examples).
991
1404
  name: 'inputTokenDetails',
992
1405
  type: 'LanguageModelInputTokenDetails',
993
1406
  description:
994
- 'Detailed information about the input (prompt) tokens. See also: cached tokens and non-cached tokens.',
1407
+ 'Detailed information about the input (prompt) tokens.',
995
1408
  properties: [
996
1409
  {
997
1410
  type: 'LanguageModelInputTokenDetails',
@@ -1064,32 +1477,21 @@ To see `generateText` in action, check out [these examples](#examples).
1064
1477
  },
1065
1478
  ],
1066
1479
  },
1067
- {
1068
- name: 'text',
1069
- type: 'string',
1070
- description: 'The full text that has been generated.',
1071
- },
1072
- {
1073
- name: 'toolCalls',
1074
- type: 'ToolCall[]',
1075
- description: 'The tool calls that have been executed.',
1076
- },
1077
- {
1078
- name: 'toolResults',
1079
- type: 'ToolResult[]',
1080
- description: 'The tool results that have been generated.',
1081
- },
1082
1480
  {
1083
1481
  name: 'warnings',
1084
- type: 'Warning[] | undefined',
1482
+ type: 'CallWarning[] | undefined',
1085
1483
  description:
1086
1484
  'Warnings from the model provider (e.g. unsupported settings).',
1087
1485
  },
1486
+ {
1487
+ name: 'request',
1488
+ type: 'LanguageModelRequestMetadata',
1489
+ description: 'Additional request information.',
1490
+ },
1088
1491
  {
1089
1492
  name: 'response',
1090
- type: 'Response',
1091
- isOptional: true,
1092
- description: 'Response metadata.',
1493
+ type: 'LanguageModelResponseMetadata & { messages: Array<ResponseMessage>; body?: unknown }',
1494
+ description: 'Additional response information.',
1093
1495
  properties: [
1094
1496
  {
1095
1497
  type: 'Response',
@@ -1104,13 +1506,12 @@ To see `generateText` in action, check out [these examples](#examples).
1104
1506
  name: 'modelId',
1105
1507
  type: 'string',
1106
1508
  description:
1107
- 'The model that was used to generate the response. The AI SDK uses the response model from the provider response when available, and the model from the function call otherwise.',
1509
+ 'The model that was used to generate the response.',
1108
1510
  },
1109
1511
  {
1110
1512
  name: 'timestamp',
1111
1513
  type: 'Date',
1112
- description:
1113
- 'The timestamp of the response. The AI SDK uses the response timestamp from the provider response when available, and creates a timestamp otherwise.',
1514
+ description: 'The timestamp of the response.',
1114
1515
  },
1115
1516
  {
1116
1517
  name: 'headers',
@@ -1118,28 +1519,29 @@ To see `generateText` in action, check out [these examples](#examples).
1118
1519
  type: 'Record<string, string>',
1119
1520
  description: 'Optional response headers.',
1120
1521
  },
1522
+ {
1523
+ name: 'messages',
1524
+ type: 'Array<ResponseMessage>',
1525
+ description:
1526
+ 'The response messages that were generated during the call.',
1527
+ },
1121
1528
  {
1122
1529
  name: 'body',
1123
1530
  isOptional: true,
1124
1531
  type: 'unknown',
1125
- description: 'Optional response body.',
1532
+ description:
1533
+ 'Response body (available only for providers that use HTTP requests).',
1126
1534
  },
1127
1535
  ],
1128
1536
  },
1129
1537
  ],
1130
1538
  },
1131
- {
1132
- name: 'isContinued',
1133
- type: 'boolean',
1134
- description:
1135
- 'True when there will be a continuation step with a continuation text.',
1136
- },
1137
1539
  {
1138
1540
  name: 'providerMetadata',
1139
- type: 'Record<string,JSONObject> | undefined',
1541
+ type: 'ProviderMetadata | undefined',
1140
1542
  isOptional: true,
1141
1543
  description:
1142
- 'Optional metadata from the provider. The outer key is the provider name. The inner values are the metadata. Details depend on the provider.',
1544
+ 'Additional provider-specific metadata. They are passed through from the provider to the AI SDK and enable provider-specific results that can be fully encapsulated in the provider.',
1143
1545
  },
1144
1546
  ],
1145
1547
  },
@@ -1147,18 +1549,40 @@ To see `generateText` in action, check out [these examples](#examples).
1147
1549
  },
1148
1550
  {
1149
1551
  name: 'onFinish',
1150
- type: '(result: OnFinishResult) => Promise<void> | void',
1552
+ type: '(event: StepResult<TOOLS> & { steps: StepResult<TOOLS>[]; totalUsage: LanguageModelUsage }) => PromiseLike<void> | void',
1151
1553
  isOptional: true,
1152
1554
  description:
1153
- 'Callback that is called when the LLM response and all request tool executions (for tools that have an `execute` function) are finished.',
1555
+ 'Callback that is called when the entire generation completes (all steps finished). The event includes the final step result properties along with aggregated data from all steps.',
1154
1556
  properties: [
1155
1557
  {
1156
- type: 'OnFinishResult',
1558
+ type: 'OnFinishEvent',
1157
1559
  parameters: [
1560
+ {
1561
+ name: 'stepNumber',
1562
+ type: 'number',
1563
+ description: 'Zero-based index of the final step.',
1564
+ },
1565
+ {
1566
+ name: 'model',
1567
+ type: '{ provider: string; modelId: string }',
1568
+ description:
1569
+ 'Information about the model that produced the final step.',
1570
+ },
1571
+ {
1572
+ name: 'functionId',
1573
+ type: 'string | undefined',
1574
+ description:
1575
+ 'Identifier from telemetry settings for grouping related operations.',
1576
+ },
1577
+ {
1578
+ name: 'metadata',
1579
+ type: 'Record<string, unknown> | undefined',
1580
+ description: 'Additional metadata from telemetry settings.',
1581
+ },
1158
1582
  {
1159
1583
  name: 'finishReason',
1160
1584
  type: '"stop" | "length" | "content-filter" | "tool-calls" | "error" | "other"',
1161
- description: 'The reason the model finished generating the text.',
1585
+ description: 'The unified reason why the generation finished.',
1162
1586
  },
1163
1587
  {
1164
1588
  name: 'rawFinishReason',
@@ -1169,7 +1593,8 @@ To see `generateText` in action, check out [these examples](#examples).
1169
1593
  {
1170
1594
  name: 'usage',
1171
1595
  type: 'LanguageModelUsage',
1172
- description: 'The token usage of the generated text.',
1596
+ description:
1597
+ 'The token usage from the final step only (not aggregated).',
1173
1598
  properties: [
1174
1599
  {
1175
1600
  type: 'LanguageModelUsage',
@@ -1184,7 +1609,7 @@ To see `generateText` in action, check out [these examples](#examples).
1184
1609
  name: 'inputTokenDetails',
1185
1610
  type: 'LanguageModelInputTokenDetails',
1186
1611
  description:
1187
- 'Detailed information about the input (prompt) tokens. See also: cached tokens and non-cached tokens.',
1612
+ 'Detailed information about the input (prompt) tokens.',
1188
1613
  properties: [
1189
1614
  {
1190
1615
  type: 'LanguageModelInputTokenDetails',
@@ -1257,11 +1682,47 @@ To see `generateText` in action, check out [these examples](#examples).
1257
1682
  },
1258
1683
  ],
1259
1684
  },
1685
+ {
1686
+ name: 'totalUsage',
1687
+ type: 'LanguageModelUsage',
1688
+ description:
1689
+ 'Aggregated token usage across all steps. This is the sum of the usage from each individual step.',
1690
+ properties: [
1691
+ {
1692
+ type: 'LanguageModelUsage',
1693
+ parameters: [
1694
+ {
1695
+ name: 'inputTokens',
1696
+ type: 'number | undefined',
1697
+ description:
1698
+ 'The total number of input (prompt) tokens used across all steps.',
1699
+ },
1700
+ {
1701
+ name: 'outputTokens',
1702
+ type: 'number | undefined',
1703
+ description:
1704
+ 'The total number of output (completion) tokens used across all steps.',
1705
+ },
1706
+ {
1707
+ name: 'totalTokens',
1708
+ type: 'number | undefined',
1709
+ description:
1710
+ 'The total number of tokens used across all steps.',
1711
+ },
1712
+ ],
1713
+ },
1714
+ ],
1715
+ },
1716
+ {
1717
+ name: 'content',
1718
+ type: 'Array<ContentPart<TOOLS>>',
1719
+ description: 'The content that was generated in the final step.',
1720
+ },
1260
1721
  {
1261
1722
  name: 'providerMetadata',
1262
- type: 'Record<string,Record<string,JSONValue>> | undefined',
1723
+ type: 'ProviderMetadata | undefined',
1263
1724
  description:
1264
- 'Optional metadata from the provider. The outer key is the provider name. The inner values are the metadata. Details depend on the provider.',
1725
+ 'Additional provider-specific metadata from the final step.',
1265
1726
  },
1266
1727
  {
1267
1728
  name: 'text',
@@ -1390,25 +1851,56 @@ To see `generateText` in action, check out [these examples](#examples).
1390
1851
  },
1391
1852
  {
1392
1853
  name: 'toolCalls',
1393
- type: 'ToolCall[]',
1394
- description: 'The tool calls that have been executed.',
1854
+ type: 'Array<TypedToolCall<TOOLS>>',
1855
+ description:
1856
+ 'The tool calls that were made during the generation.',
1857
+ },
1858
+ {
1859
+ name: 'staticToolCalls',
1860
+ type: 'Array<StaticToolCall<TOOLS>>',
1861
+ description:
1862
+ 'The static tool calls that were made in the final step.',
1863
+ },
1864
+ {
1865
+ name: 'dynamicToolCalls',
1866
+ type: 'Array<DynamicToolCall>',
1867
+ description:
1868
+ 'The dynamic tool calls that were made in the final step.',
1395
1869
  },
1396
1870
  {
1397
1871
  name: 'toolResults',
1398
- type: 'ToolResult[]',
1399
- description: 'The tool results that have been generated.',
1872
+ type: 'Array<TypedToolResult<TOOLS>>',
1873
+ description: 'The results of the tool calls.',
1874
+ },
1875
+ {
1876
+ name: 'staticToolResults',
1877
+ type: 'Array<StaticToolResult<TOOLS>>',
1878
+ description:
1879
+ 'The static tool results that were made in the final step.',
1880
+ },
1881
+ {
1882
+ name: 'dynamicToolResults',
1883
+ type: 'Array<DynamicToolResult>',
1884
+ description:
1885
+ 'The dynamic tool results that were made in the final step.',
1400
1886
  },
1401
1887
  {
1402
1888
  name: 'warnings',
1403
- type: 'Warning[] | undefined',
1889
+ type: 'CallWarning[] | undefined',
1404
1890
  description:
1405
1891
  'Warnings from the model provider (e.g. unsupported settings).',
1406
1892
  },
1893
+ {
1894
+ name: 'request',
1895
+ type: 'LanguageModelRequestMetadata',
1896
+ description:
1897
+ 'Additional request information from the final step.',
1898
+ },
1407
1899
  {
1408
1900
  name: 'response',
1409
- type: 'Response',
1410
- isOptional: true,
1411
- description: 'Response metadata.',
1901
+ type: 'LanguageModelResponseMetadata & { messages: Array<ResponseMessage>; body?: unknown }',
1902
+ description:
1903
+ 'Additional response information from the final step.',
1412
1904
  properties: [
1413
1905
  {
1414
1906
  type: 'Response',
@@ -1456,7 +1948,8 @@ To see `generateText` in action, check out [these examples](#examples).
1456
1948
  {
1457
1949
  name: 'experimental_context',
1458
1950
  type: 'unknown',
1459
- description: 'The experimental context.',
1951
+ description:
1952
+ 'The final state of the user-defined context object. This reflects any modifications made during the generation lifecycle via prepareStep or tool execution.',
1460
1953
  },
1461
1954
  ],
1462
1955
  },
@@ -1852,6 +2345,34 @@ To see `generateText` in action, check out [these examples](#examples).
1852
2345
  {
1853
2346
  type: 'StepResult',
1854
2347
  parameters: [
2348
+ {
2349
+ name: 'stepNumber',
2350
+ type: 'number',
2351
+ description: 'The zero-based index of this step.',
2352
+ },
2353
+ {
2354
+ name: 'model',
2355
+ type: '{ provider: string; modelId: string }',
2356
+ description:
2357
+ 'Information about the model that produced this step.',
2358
+ },
2359
+ {
2360
+ name: 'functionId',
2361
+ type: 'string | undefined',
2362
+ description:
2363
+ 'Identifier from telemetry settings for grouping related operations.',
2364
+ },
2365
+ {
2366
+ name: 'metadata',
2367
+ type: 'Record<string, unknown> | undefined',
2368
+ description: 'Additional metadata from telemetry settings.',
2369
+ },
2370
+ {
2371
+ name: 'experimental_context',
2372
+ type: 'unknown',
2373
+ description:
2374
+ 'User-defined context object flowing through the generation.',
2375
+ },
1855
2376
  {
1856
2377
  name: 'content',
1857
2378
  type: 'Array<ContentPart<TOOLS>>',