ai 7.0.153 → 7.0.155

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.
Files changed (53) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/index.d.ts +224 -9
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +1071 -893
  5. package/dist/index.js.map +1 -1
  6. package/dist/internal/index.d.ts +54 -7
  7. package/dist/internal/index.d.ts.map +1 -1
  8. package/dist/internal/index.js +29 -399
  9. package/dist/internal/index.js.map +1 -1
  10. package/docs/02-getting-started/02-nextjs-app-router.mdx +2 -2
  11. package/docs/02-getting-started/08-angular.mdx +327 -0
  12. package/docs/02-getting-started/{03-nextjs-pages-router.mdx → 10-nextjs-pages-router.mdx} +12 -20
  13. package/docs/02-getting-started/index.mdx +2 -0
  14. package/docs/03-agents/01-overview.mdx +1 -0
  15. package/docs/03-agents/04-loop-control.mdx +117 -0
  16. package/docs/03-agents/06-tool-approvals.mdx +1 -0
  17. package/docs/03-agents/09-chat-platforms.mdx +164 -0
  18. package/docs/03-agents/index.mdx +6 -0
  19. package/docs/03-ai-sdk-core/16-mcp-tools.mdx +7 -0
  20. package/docs/03-ai-sdk-core/60-telemetry.mdx +16 -3
  21. package/docs/03-ai-sdk-core/65-lifecycle-callbacks.mdx +10 -0
  22. package/docs/04-ai-sdk-ui/21-transport.mdx +86 -0
  23. package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +46 -0
  24. package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +46 -0
  25. package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +35 -0
  26. package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +7 -0
  27. package/docs/07-reference/05-ai-sdk-errors/ai-invalid-prompt-error.mdx +25 -10
  28. package/package.json +11 -11
  29. package/src/agent/create-agent-ui-stream-response.ts +3 -0
  30. package/src/agent/create-agent-ui-stream.ts +16 -0
  31. package/src/agent/pipe-agent-ui-stream-to-response.ts +3 -0
  32. package/src/agent/tool-loop-agent-settings.ts +37 -1
  33. package/src/agent/tool-loop-agent.ts +43 -7
  34. package/src/batch/batch.ts +0 -8
  35. package/src/decide/validate-decision.ts +39 -64
  36. package/src/generate-object/validate-object-generation-input.ts +1 -39
  37. package/src/generate-speech/stream-speech.ts +6 -18
  38. package/src/generate-text/generate-text-events.ts +37 -0
  39. package/src/generate-text/generate-text.ts +521 -373
  40. package/src/generate-text/index.ts +8 -0
  41. package/src/generate-text/prepare-step.ts +12 -0
  42. package/src/generate-text/restricted-telemetry-dispatcher.ts +31 -18
  43. package/src/generate-text/smooth-stream.ts +2 -14
  44. package/src/generate-text/steering.ts +285 -0
  45. package/src/generate-text/step-result.ts +18 -0
  46. package/src/generate-text/stream-text.ts +664 -473
  47. package/src/generate-text/tool-caller-configuration.ts +2 -26
  48. package/src/prompt/prepare-language-model-call-options.ts +0 -50
  49. package/src/prompt/standardize-prompt.ts +9 -58
  50. package/src/telemetry/create-telemetry-dispatcher.ts +3 -0
  51. package/src/telemetry/telemetry.ts +15 -1
  52. package/src/test/mock-sandbox.ts +5 -11
  53. package/src/util/is-caused-by-abort.ts +20 -0
@@ -1,6 +1,5 @@
1
1
  import { DEFAULT_MAX_DOWNLOAD_SIZE, DownloadError, asArray, asSchema, cancelResponseBody, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertUint8ArrayToBase64, detectMediaType, experimental_getToolCaller, fetchUntrustedUrl, filterNullable, getRuntimeEnvironmentUserAgent, isBuffer, isExecutableTool, isFullMediaType, isProviderReference, isUrlSupported, readResponseWithSizeLimit, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, validateTypes, withUserAgentSuffix } from "@ai-sdk/provider-utils";
2
2
  import { AISDKError, APICallError, InvalidPromptError, getErrorMessage } from "@ai-sdk/provider";
3
- import { array, boolean, custom, discriminatedUnion, enum as enum$1, instanceof as instanceof$1, lazy, literal, looseObject, never, null as null$1, number, object, record, string, union, unknown } from "zod/v4";
4
3
  import { GatewayError, gateway } from "@ai-sdk/gateway";
5
4
  //#region src/util/async-iterable-stream.ts
6
5
  /**
@@ -111,7 +110,7 @@ function asAsyncIterableStream(stream) {
111
110
  }
112
111
  //#endregion
113
112
  //#region src/version.ts
114
- const VERSION = "7.0.153";
113
+ const VERSION = "7.0.155";
115
114
  //#endregion
116
115
  //#region src/util/download/download.ts
117
116
  /**
@@ -1093,323 +1092,9 @@ function resolveToolDescription({ tool, toolName, toolsContext, experimental_san
1093
1092
  });
1094
1093
  }
1095
1094
  //#endregion
1096
- //#region src/util/zod.ts
1097
- const z = {
1098
- array,
1099
- boolean,
1100
- custom,
1101
- discriminatedUnion,
1102
- enum: enum$1,
1103
- instanceof: instanceof$1,
1104
- lazy,
1105
- literal,
1106
- looseObject,
1107
- never,
1108
- null: null$1,
1109
- number,
1110
- object,
1111
- record,
1112
- string,
1113
- union,
1114
- unknown
1115
- };
1116
- //#endregion
1117
- //#region src/types/json-value.ts
1118
- const jsonValueSchema = z.lazy(() => z.union([
1119
- z.null(),
1120
- z.string(),
1121
- z.number(),
1122
- z.boolean(),
1123
- z.record(z.string(), jsonValueSchema.optional()),
1124
- z.array(jsonValueSchema)
1125
- ]));
1126
- //#endregion
1127
- //#region src/types/provider-metadata.ts
1128
- const providerMetadataSchema = z.record(z.string(), z.record(z.string(), jsonValueSchema.optional()));
1129
- //#endregion
1130
- //#region src/prompt/content-part.ts
1131
- const fileInlineDataSchema = z.union([
1132
- z.string(),
1133
- z.instanceof(Uint8Array),
1134
- z.instanceof(ArrayBuffer),
1135
- z.custom(isBuffer, { message: "Must be a Buffer" })
1136
- ]);
1137
- const providerReferenceSchema = z.record(z.string(), z.string());
1138
- /**
1139
- * @internal
1140
- */
1141
- const textPartSchema = z.object({
1142
- type: z.literal("text"),
1143
- text: z.string(),
1144
- providerOptions: providerMetadataSchema.optional()
1145
- });
1146
- /**
1147
- * @internal
1148
- * @deprecated Use `filePartSchema` with `mediaType: 'image'` instead:
1149
- * `{ type: 'file', mediaType: 'image', data: { type: 'data', data } }`.
1150
- */
1151
- const imagePartSchema = z.object({
1152
- type: z.literal("image"),
1153
- image: z.union([
1154
- fileInlineDataSchema,
1155
- z.instanceof(URL),
1156
- providerReferenceSchema
1157
- ]),
1158
- mediaType: z.string().optional(),
1159
- providerOptions: providerMetadataSchema.optional()
1160
- });
1161
- const taggedFileDataSchema = z.discriminatedUnion("type", [
1162
- z.object({
1163
- type: z.literal("data"),
1164
- data: fileInlineDataSchema
1165
- }),
1166
- z.object({
1167
- type: z.literal("url"),
1168
- url: z.instanceof(URL)
1169
- }),
1170
- z.object({
1171
- type: z.literal("reference"),
1172
- reference: providerReferenceSchema
1173
- }),
1174
- z.object({
1175
- type: z.literal("text"),
1176
- text: z.string()
1177
- })
1178
- ]);
1179
- const taggedReasoningFileDataSchema = z.discriminatedUnion("type", [z.object({
1180
- type: z.literal("data"),
1181
- data: fileInlineDataSchema
1182
- }), z.object({
1183
- type: z.literal("url"),
1184
- url: z.instanceof(URL)
1185
- })]);
1186
- /**
1187
- * @internal
1188
- */
1189
- const filePartSchema = z.object({
1190
- type: z.literal("file"),
1191
- data: z.union([
1192
- taggedFileDataSchema,
1193
- fileInlineDataSchema,
1194
- z.instanceof(URL),
1195
- providerReferenceSchema
1196
- ]),
1197
- filename: z.string().optional(),
1198
- mediaType: z.string(),
1199
- providerOptions: providerMetadataSchema.optional()
1200
- });
1201
- /**
1202
- * @internal
1203
- */
1204
- const reasoningPartSchema = z.object({
1205
- type: z.literal("reasoning"),
1206
- text: z.string(),
1207
- providerOptions: providerMetadataSchema.optional()
1208
- });
1209
- /**
1210
- * @internal
1211
- */
1212
- const customPartSchema = z.object({
1213
- type: z.literal("custom"),
1214
- kind: z.string().transform((value) => value),
1215
- providerOptions: providerMetadataSchema.optional()
1216
- });
1217
- /**
1218
- * @internal
1219
- */
1220
- const reasoningFilePartSchema = z.object({
1221
- type: z.literal("reasoning-file"),
1222
- data: z.union([
1223
- taggedReasoningFileDataSchema,
1224
- fileInlineDataSchema,
1225
- z.instanceof(URL)
1226
- ]),
1227
- mediaType: z.string(),
1228
- providerOptions: providerMetadataSchema.optional()
1229
- });
1230
- /**
1231
- * @internal
1232
- */
1233
- const toolCallPartSchema = z.object({
1234
- type: z.literal("tool-call"),
1235
- toolCallId: z.string(),
1236
- toolName: z.string(),
1237
- input: z.unknown(),
1238
- providerOptions: providerMetadataSchema.optional(),
1239
- providerExecuted: z.boolean().optional()
1240
- });
1241
- /**
1242
- * @internal
1243
- */
1244
- const outputSchema = z.discriminatedUnion("type", [
1245
- z.object({
1246
- type: z.literal("text"),
1247
- value: z.string(),
1248
- providerOptions: providerMetadataSchema.optional()
1249
- }),
1250
- z.object({
1251
- type: z.literal("json"),
1252
- value: jsonValueSchema,
1253
- providerOptions: providerMetadataSchema.optional()
1254
- }),
1255
- z.object({
1256
- type: z.literal("execution-denied"),
1257
- reason: z.string().optional(),
1258
- providerOptions: providerMetadataSchema.optional()
1259
- }),
1260
- z.object({
1261
- type: z.literal("error-text"),
1262
- value: z.string(),
1263
- providerOptions: providerMetadataSchema.optional()
1264
- }),
1265
- z.object({
1266
- type: z.literal("error-json"),
1267
- value: jsonValueSchema,
1268
- providerOptions: providerMetadataSchema.optional()
1269
- }),
1270
- z.object({
1271
- type: z.literal("content"),
1272
- value: z.array(z.union([
1273
- z.object({
1274
- type: z.literal("text"),
1275
- text: z.string(),
1276
- providerOptions: providerMetadataSchema.optional()
1277
- }),
1278
- z.object({
1279
- type: z.literal("file"),
1280
- data: taggedFileDataSchema,
1281
- mediaType: z.string(),
1282
- filename: z.string().optional(),
1283
- providerOptions: providerMetadataSchema.optional()
1284
- }),
1285
- z.object({
1286
- type: z.literal("file-data"),
1287
- data: z.string(),
1288
- mediaType: z.string(),
1289
- filename: z.string().optional(),
1290
- providerOptions: providerMetadataSchema.optional()
1291
- }),
1292
- z.object({
1293
- type: z.literal("file-url"),
1294
- url: z.string(),
1295
- mediaType: z.string().optional(),
1296
- providerOptions: providerMetadataSchema.optional()
1297
- }),
1298
- z.object({
1299
- type: z.literal("file-id"),
1300
- fileId: z.union([z.string(), z.record(z.string(), z.string())]),
1301
- providerOptions: providerMetadataSchema.optional()
1302
- }),
1303
- z.object({
1304
- type: z.literal("file-reference"),
1305
- providerReference: z.record(z.string(), z.string()),
1306
- providerOptions: providerMetadataSchema.optional()
1307
- }),
1308
- z.object({
1309
- type: z.literal("image-data"),
1310
- data: z.string(),
1311
- mediaType: z.string(),
1312
- providerOptions: providerMetadataSchema.optional()
1313
- }),
1314
- z.object({
1315
- type: z.literal("image-url"),
1316
- url: z.string(),
1317
- providerOptions: providerMetadataSchema.optional()
1318
- }),
1319
- z.object({
1320
- type: z.literal("image-file-id"),
1321
- fileId: z.union([z.string(), z.record(z.string(), z.string())]),
1322
- providerOptions: providerMetadataSchema.optional()
1323
- }),
1324
- z.object({
1325
- type: z.literal("image-file-reference"),
1326
- providerReference: z.record(z.string(), z.string()),
1327
- providerOptions: providerMetadataSchema.optional()
1328
- }),
1329
- z.object({
1330
- type: z.literal("custom"),
1331
- providerOptions: providerMetadataSchema.optional()
1332
- })
1333
- ]))
1334
- })
1335
- ]);
1336
- /**
1337
- * @internal
1338
- */
1339
- const toolResultPartSchema = z.object({
1340
- type: z.literal("tool-result"),
1341
- toolCallId: z.string(),
1342
- toolName: z.string(),
1343
- output: outputSchema,
1344
- providerOptions: providerMetadataSchema.optional()
1345
- });
1346
- /**
1347
- * @internal
1348
- */
1349
- const toolApprovalRequestSchema = z.object({
1350
- type: z.literal("tool-approval-request"),
1351
- approvalId: z.string(),
1352
- toolCallId: z.string(),
1353
- reason: z.string().optional(),
1354
- isAutomatic: z.boolean().optional(),
1355
- signature: z.string().optional(),
1356
- inputSchemaInput: z.unknown().optional()
1357
- });
1358
- /**
1359
- * @internal
1360
- */
1361
- const toolApprovalResponseSchema = z.object({
1362
- type: z.literal("tool-approval-response"),
1363
- approvalId: z.string(),
1364
- approved: z.boolean(),
1365
- reason: z.string().optional()
1366
- });
1367
- //#endregion
1368
- //#region src/prompt/message.ts
1369
- const systemModelMessageSchema = z.object({
1370
- role: z.literal("system"),
1371
- content: z.string(),
1372
- providerOptions: providerMetadataSchema.optional()
1373
- });
1374
- const userModelMessageSchema = z.object({
1375
- role: z.literal("user"),
1376
- content: z.union([z.string(), z.array(z.union([
1377
- textPartSchema,
1378
- imagePartSchema,
1379
- filePartSchema
1380
- ]))]),
1381
- providerOptions: providerMetadataSchema.optional()
1382
- });
1383
- const assistantModelMessageSchema = z.object({
1384
- role: z.literal("assistant"),
1385
- content: z.union([z.string(), z.array(z.union([
1386
- textPartSchema,
1387
- customPartSchema,
1388
- filePartSchema,
1389
- reasoningPartSchema,
1390
- reasoningFilePartSchema,
1391
- toolCallPartSchema,
1392
- toolResultPartSchema,
1393
- toolApprovalRequestSchema
1394
- ]))]),
1395
- providerOptions: providerMetadataSchema.optional()
1396
- });
1397
- const toolModelMessageSchema = z.object({
1398
- role: z.literal("tool"),
1399
- content: z.array(z.union([toolResultPartSchema, toolApprovalResponseSchema])),
1400
- providerOptions: providerMetadataSchema.optional()
1401
- });
1402
- const modelMessageSchema = z.union([
1403
- systemModelMessageSchema,
1404
- userModelMessageSchema,
1405
- assistantModelMessageSchema,
1406
- toolModelMessageSchema
1407
- ]);
1408
- //#endregion
1409
1095
  //#region src/prompt/standardize-prompt.ts
1410
1096
  /**
1411
- * Converts a prompt input into a standardized prompt with validated model
1412
- * messages.
1097
+ * Converts a prompt input into a standardized prompt with model messages.
1413
1098
  *
1414
1099
  * @param prompt - The prompt definition to standardize.
1415
1100
  * Set `allowSystemInMessages` to true to allow system messages in the
@@ -1419,27 +1104,10 @@ const modelMessageSchema = z.union([
1419
1104
  * @throws {InvalidPromptError} When the prompt is invalid.
1420
1105
  */
1421
1106
  async function standardizePrompt({ allowSystemInMessages = false, system, instructions = system, prompt, messages }) {
1422
- if (prompt == null && messages == null) throw new InvalidPromptError({
1423
- prompt,
1424
- message: "prompt or messages must be defined"
1425
- });
1426
- if (prompt != null && messages != null) throw new InvalidPromptError({
1427
- prompt,
1428
- message: "prompt and messages cannot be defined at the same time"
1429
- });
1430
- if (typeof instructions !== "string" && !asArray(instructions).every((message) => message.role === "system")) throw new InvalidPromptError({
1431
- prompt,
1432
- message: "instructions must be a string, SystemModelMessage, or array of SystemModelMessage"
1433
- });
1434
- if (prompt != null && typeof prompt === "string") messages = [{
1107
+ messages = prompt == null ? messages : typeof prompt === "string" ? [{
1435
1108
  role: "user",
1436
1109
  content: prompt
1437
- }];
1438
- else if (prompt != null && Array.isArray(prompt)) messages = prompt;
1439
- else if (messages == null) throw new InvalidPromptError({
1440
- prompt,
1441
- message: "prompt or messages must be defined"
1442
- });
1110
+ }] : prompt;
1443
1111
  if (messages.length === 0) throw new InvalidPromptError({
1444
1112
  prompt,
1445
1113
  message: "messages must not be empty"
@@ -1448,15 +1116,6 @@ async function standardizePrompt({ allowSystemInMessages = false, system, instru
1448
1116
  prompt,
1449
1117
  message: "System messages are not allowed in the prompt or messages fields. Use the instructions option instead."
1450
1118
  });
1451
- const validationResult = await safeValidateTypes({
1452
- value: messages,
1453
- schema: z.array(modelMessageSchema)
1454
- });
1455
- if (!validationResult.success) throw new InvalidPromptError({
1456
- prompt,
1457
- message: "The messages do not match the ModelMessage[] schema.",
1458
- cause: validationResult.error
1459
- });
1460
1119
  return {
1461
1120
  messages,
1462
1121
  instructions
@@ -1499,41 +1158,6 @@ function prepareLanguageModelCallOptions({ maxOutputTokens, temperature, topP, t
1499
1158
  message: "maxOutputTokens must be >= 1"
1500
1159
  });
1501
1160
  }
1502
- if (temperature != null) {
1503
- if (typeof temperature !== "number") throw new InvalidArgumentError({
1504
- parameter: "temperature",
1505
- value: temperature,
1506
- message: "temperature must be a number"
1507
- });
1508
- }
1509
- if (topP != null) {
1510
- if (typeof topP !== "number") throw new InvalidArgumentError({
1511
- parameter: "topP",
1512
- value: topP,
1513
- message: "topP must be a number"
1514
- });
1515
- }
1516
- if (topK != null) {
1517
- if (typeof topK !== "number") throw new InvalidArgumentError({
1518
- parameter: "topK",
1519
- value: topK,
1520
- message: "topK must be a number"
1521
- });
1522
- }
1523
- if (presencePenalty != null) {
1524
- if (typeof presencePenalty !== "number") throw new InvalidArgumentError({
1525
- parameter: "presencePenalty",
1526
- value: presencePenalty,
1527
- message: "presencePenalty must be a number"
1528
- });
1529
- }
1530
- if (frequencyPenalty != null) {
1531
- if (typeof frequencyPenalty !== "number") throw new InvalidArgumentError({
1532
- parameter: "frequencyPenalty",
1533
- value: frequencyPenalty,
1534
- message: "frequencyPenalty must be a number"
1535
- });
1536
- }
1537
1161
  if (seed != null) {
1538
1162
  if (!Number.isInteger(seed)) throw new InvalidArgumentError({
1539
1163
  parameter: "seed",
@@ -2380,7 +2004,8 @@ function augmentEvent(event, telemetry, filterContext = false) {
2380
2004
  const augmentedEvent = Object.assign(Object.create(Object.getPrototypeOf(event)), event, {
2381
2005
  recordInputs: telemetry.recordInputs,
2382
2006
  recordOutputs: telemetry.recordOutputs,
2383
- functionId: telemetry.functionId
2007
+ functionId: telemetry.functionId,
2008
+ aiVersion: VERSION
2384
2009
  });
2385
2010
  if (filterContext && event != null && typeof event === "object" && "runtimeContext" in event) augmentedEvent.runtimeContext = filterIncludedContext({
2386
2011
  context: event.runtimeContext,
@@ -2457,6 +2082,7 @@ function createTelemetryDispatcher({ telemetry }) {
2457
2082
  onToolExecutionStart: mergeTelemetryCallback("onToolExecutionStart"),
2458
2083
  onToolExecutionEnd: mergeTelemetryCallback("onToolExecutionEnd"),
2459
2084
  onStepEnd: onStepEnd == null && onStepFinish == null ? void 0 : mergeCallbacks(onStepEnd, onStepFinish),
2085
+ onStepError: mergeTelemetryCallback("onStepError"),
2460
2086
  onObjectStepStart: mergeTelemetryCallback("onObjectStepStart"),
2461
2087
  onObjectStepEnd: mergeTelemetryCallback("onObjectStepEnd"),
2462
2088
  onEmbedStart: mergeTelemetryCallback("onEmbedStart"),
@@ -2578,7 +2204,7 @@ function convertToReasoningOutputs(parts) {
2578
2204
  //#endregion
2579
2205
  //#region src/generate-text/step-result.ts
2580
2206
  var DefaultStepResult = class {
2581
- constructor({ callId, stepNumber, provider, modelId, runtimeContext, toolsContext, content, finishReason, rawFinishReason, usage, performance, warnings, request, response, providerMetadata }) {
2207
+ constructor({ callId, stepNumber, provider, modelId, runtimeContext, toolsContext, content, finishReason, rawFinishReason, usage, performance, warnings, request, response, providerMetadata, steeringMessages }) {
2582
2208
  this.callId = callId;
2583
2209
  this.stepNumber = stepNumber;
2584
2210
  this.model = {
@@ -2596,6 +2222,7 @@ var DefaultStepResult = class {
2596
2222
  this.request = request;
2597
2223
  this.response = response;
2598
2224
  this.providerMetadata = providerMetadata;
2225
+ if (steeringMessages != null && steeringMessages.length > 0) this.experimental_steeringMessages = steeringMessages;
2599
2226
  }
2600
2227
  get text() {
2601
2228
  return this.content.filter((part) => part.type === "text").map((part) => part.text).join("");
@@ -2659,7 +2286,8 @@ function restrictStepResult({ step, includeRuntimeContext, includeToolsContext }
2659
2286
  warnings: step.warnings,
2660
2287
  request: step.request,
2661
2288
  response: step.response,
2662
- providerMetadata: step.providerMetadata
2289
+ providerMetadata: step.providerMetadata,
2290
+ steeringMessages: step.experimental_steeringMessages
2663
2291
  });
2664
2292
  }
2665
2293
  /**
@@ -2668,6 +2296,22 @@ function restrictStepResult({ step, includeRuntimeContext, includeToolsContext }
2668
2296
  */
2669
2297
  function createRestrictedTelemetryDispatcher({ telemetry, includeRuntimeContext, includeToolsContext }) {
2670
2298
  const telemetryDispatcher = createTelemetryDispatcher({ telemetry });
2299
+ const restrictStepStartEvent = (event) => ({
2300
+ ...event,
2301
+ runtimeContext: filterIncludedContext({
2302
+ context: event.runtimeContext,
2303
+ includeContext: includeRuntimeContext
2304
+ }),
2305
+ steps: event.steps.map((step) => restrictStepResult({
2306
+ step,
2307
+ includeRuntimeContext,
2308
+ includeToolsContext
2309
+ })),
2310
+ toolsContext: filterToolsContext({
2311
+ toolsContext: event.toolsContext,
2312
+ includeToolsContext
2313
+ })
2314
+ });
2671
2315
  return {
2672
2316
  ...telemetryDispatcher,
2673
2317
  onStart: (event) => telemetryDispatcher.onStart?.({
@@ -2681,22 +2325,7 @@ function createRestrictedTelemetryDispatcher({ telemetry, includeRuntimeContext,
2681
2325
  includeToolsContext
2682
2326
  })
2683
2327
  }),
2684
- onStepStart: (event) => telemetryDispatcher.onStepStart?.({
2685
- ...event,
2686
- runtimeContext: filterIncludedContext({
2687
- context: event.runtimeContext,
2688
- includeContext: includeRuntimeContext
2689
- }),
2690
- steps: event.steps.map((step) => restrictStepResult({
2691
- step,
2692
- includeRuntimeContext,
2693
- includeToolsContext
2694
- })),
2695
- toolsContext: filterToolsContext({
2696
- toolsContext: event.toolsContext,
2697
- includeToolsContext
2698
- })
2699
- }),
2328
+ onStepStart: (event) => telemetryDispatcher.onStepStart?.(restrictStepStartEvent(event)),
2700
2329
  onStepEnd: (event) => telemetryDispatcher.onStepEnd?.(restrictStepResult({
2701
2330
  step: event,
2702
2331
  includeRuntimeContext,
@@ -2707,6 +2336,7 @@ function createRestrictedTelemetryDispatcher({ telemetry, includeRuntimeContext,
2707
2336
  includeRuntimeContext,
2708
2337
  includeToolsContext
2709
2338
  })),
2339
+ onStepError: (event) => telemetryDispatcher.onStepError?.(restrictStepStartEvent(event)),
2710
2340
  onEnd: (event) => telemetryDispatcher.onEnd?.(((restrictedSteps) => {
2711
2341
  return {
2712
2342
  ...event,