@pensar/apex 2.1.2 → 2.1.3-canary.9978c1ae

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 (55) hide show
  1. package/build/agent-brysbb20.js +19 -0
  2. package/build/{agent-737mxp3v.js → agent-gf41p56q.js} +8 -8
  3. package/build/{agent-vdrtakz4.js → agent-yz2ygex0.js} +10 -10
  4. package/build/{apps-j0bwey0w.js → apps-yzmjmpf9.js} +16 -16
  5. package/build/{auth-5stxpmga.js → auth-p29y3nzn.js} +16 -16
  6. package/build/authentication-mh5ymtgy.js +19 -0
  7. package/build/blackboxAgent-3z0r12m0.js +19 -0
  8. package/build/{blackboxPentest-2edr9rj3.js → blackboxPentest-dg3b1t6b.js} +14 -14
  9. package/build/{cli-v1aqbv58.js → cli-1xx6s4nh.js} +24882 -26968
  10. package/build/{cli-9z6vwf30.js → cli-24mzbewx.js} +1 -1
  11. package/build/{cli-f7d23ded.js → cli-29yqhrjq.js} +936 -1775
  12. package/build/{cli-gbkj2has.js → cli-366c64xy.js} +3 -3
  13. package/build/{cli-0gk2x2sc.js → cli-704tt332.js} +3 -3
  14. package/build/{cli-xnnkeg5p.js → cli-80jkzpct.js} +1 -1
  15. package/build/{cli-yjbkaqvy.js → cli-bpcymyg8.js} +43 -13
  16. package/build/{cli-tw3fe8bj.js → cli-d4bn60j7.js} +2 -2
  17. package/build/{cli-ks60cc3h.js → cli-dgyyj1b0.js} +30 -30
  18. package/build/{cli-6vs0mtsb.js → cli-ecp92fqe.js} +2 -2
  19. package/build/{cli-6wwpk9d9.js → cli-fex1cvdc.js} +1 -1
  20. package/build/{cli-35czfv00.js → cli-hty9x6e3.js} +68109 -77017
  21. package/build/{cli-jd0c0b91.js → cli-j313zw46.js} +1 -1
  22. package/build/{cli-dqkdnd3c.js → cli-mmc95pfp.js} +88 -49
  23. package/build/{cli-9vzc18m5.js → cli-qnqppth7.js} +8 -8
  24. package/build/{cli-hj3t87r2.js → cli-twhj2d1q.js} +1 -1
  25. package/build/{cli-whtdyc0e.js → cli-zbwmbxpd.js} +3 -3
  26. package/build/cli.js +68 -68
  27. package/build/{config-s5ryv5ez.js → config-t3ny5d68.js} +3 -3
  28. package/build/{doctor-f08gegwc.js → doctor-atj45rne.js} +7 -7
  29. package/build/{fixes-qf4s92z2.js → fixes-pqgk5v9z.js} +16 -16
  30. package/build/{index-gakk2t5q.js → index-7cw66451.js} +18 -18
  31. package/build/{index-x4xefngs.js → index-9j3fxkcg.js} +3 -3
  32. package/build/{index-s8gw83d6.js → index-cm74qg8e.js} +17 -9
  33. package/build/{index-sqjve2bm.js → index-ehk56y92.js} +2 -2
  34. package/build/{index-5h1hjhzw.js → index-eyt8y7cq.js} +10 -10
  35. package/build/{index-mgng15va.js → index-n1yh9e86.js} +909 -456
  36. package/build/{index-c6qz0gve.js → index-n22g9ytc.js} +7 -7
  37. package/build/{index-exvkbve0.js → index-s03jmg2x.js} +4 -4
  38. package/build/{issues-5anqrh2j.js → issues-6gyfhe2j.js} +16 -16
  39. package/build/{logs-q6ankt6m.js → logs-5ga7w81s.js} +16 -16
  40. package/build/{main-3zneyg7p.js → main-3d7dfdvs.js} +17 -93
  41. package/build/{offesecAgent-hsej0pfc.js → offesecAgent-zvj9q4yc.js} +9 -9
  42. package/build/pentest-90d9gtrs.js +28 -0
  43. package/build/{pentests-hyx3c3qa.js → pentests-887d85z1.js} +16 -16
  44. package/build/{targetedPentest-ws0a7frk.js → targetedPentest-56fzgqyw.js} +10 -10
  45. package/build/{targets-9cqrshet.js → targets-63cs73s2.js} +16 -16
  46. package/build/threatModel-gznjwpk9.js +26 -0
  47. package/build/{uninstall-1j469qj7.js → uninstall-6hc47s0e.js} +1 -1
  48. package/build/{upload-ymvhkyq5.js → upload-8kv9v08h.js} +7 -7
  49. package/build/{utils-d1ed6jzf.js → utils-etpb7d2y.js} +6 -6
  50. package/package.json +30 -30
  51. package/build/agent-8w9h3tnw.js +0 -19
  52. package/build/authentication-qswvctj4.js +0 -19
  53. package/build/blackboxAgent-vwm9t3h4.js +0 -19
  54. package/build/pentest-1e30q7rs.js +0 -28
  55. package/build/threatModel-z9b213x8.js +0 -26
@@ -6,6 +6,7 @@ import {
6
6
  DownloadError,
7
7
  EmptyResponseBodyError,
8
8
  GatewayAuthenticationError,
9
+ GatewayError,
9
10
  InvalidArgumentError,
10
11
  InvalidPromptError,
11
12
  InvalidResponseDataError,
@@ -18,6 +19,7 @@ import {
18
19
  TypeValidationError,
19
20
  UnsupportedFunctionalityError,
20
21
  asSchema,
22
+ cancelResponseBody,
21
23
  convertBase64ToUint8Array,
22
24
  convertUint8ArrayToBase64,
23
25
  createGatewayProvider,
@@ -26,6 +28,7 @@ import {
26
28
  dynamicTool,
27
29
  executeTool,
28
30
  exports_external,
31
+ fetchWithValidatedRedirects,
29
32
  gateway,
30
33
  generateId,
31
34
  getErrorMessage,
@@ -50,21 +53,20 @@ import {
50
53
  safeParseJSON,
51
54
  safeValidateTypes,
52
55
  tool,
53
- validateDownloadUrl,
54
56
  validateTypes,
55
57
  withUserAgentSuffix,
56
58
  zodSchema
57
- } from "./cli-f7d23ded.js";
59
+ } from "./cli-29yqhrjq.js";
58
60
  import"./cli-gpnb45ck.js";
59
61
  import {
60
62
  __toESM
61
63
  } from "./cli-8rxa073f.js";
62
64
 
63
65
  // node_modules/ai/dist/index.mjs
64
- init_dist2();
65
- init_dist3();
66
- init_dist3();
67
66
  init_dist3();
67
+ init_dist2();
68
+ init_dist2();
69
+ init_dist2();
68
70
  init_dist();
69
71
  init_dist();
70
72
  init_dist();
@@ -85,73 +87,77 @@ init_dist();
85
87
  init_dist();
86
88
  init_dist();
87
89
  init_dist();
88
- init_dist3();
89
90
  init_dist();
90
91
  init_dist2();
91
- init_dist3();
92
- init_dist3();
93
- init_dist3();
94
92
  init_dist();
95
93
  init_dist3();
94
+ init_dist2();
95
+ init_dist2();
96
+ init_dist2();
97
+ init_dist();
98
+ init_dist2();
96
99
  init_v4();
97
100
  init_dist();
98
- init_dist3();
101
+ init_dist2();
99
102
  init_dist();
100
- init_dist3();
103
+ init_dist2();
101
104
  init_v4();
102
105
  init_v4();
103
106
  init_v4();
104
107
  init_v4();
105
108
  init_v4();
106
- init_dist2();
109
+ init_dist3();
107
110
  init_dist();
108
111
  init_dist();
109
112
  init_dist3();
110
- init_dist3();
111
- init_dist3();
113
+ init_dist2();
114
+ init_dist2();
115
+ init_dist2();
116
+ init_dist2();
117
+ init_dist2();
112
118
  init_dist();
113
- init_dist3();
114
- init_dist3();
115
- init_dist3();
119
+ init_dist2();
120
+ init_dist2();
121
+ init_dist2();
116
122
  init_dist();
117
- init_dist3();
118
- init_dist3();
123
+ init_dist2();
124
+ init_dist2();
119
125
  init_v4();
120
- init_dist3();
121
- init_dist3();
122
- init_dist3();
123
- init_dist3();
126
+ init_dist2();
127
+ init_dist2();
128
+ init_dist2();
129
+ init_dist2();
124
130
  init_dist();
125
- init_dist3();
131
+ init_dist2();
126
132
  init_v4();
127
- init_dist3();
128
- init_dist3();
129
- init_dist3();
130
- init_dist3();
133
+ init_dist2();
134
+ init_dist2();
135
+ init_dist2();
136
+ init_dist2();
131
137
  init_dist();
132
- init_dist3();
138
+ init_dist2();
133
139
  init_dist();
134
- init_dist3();
135
- init_dist3();
136
- init_dist3();
137
- init_dist3();
138
- init_dist3();
140
+ init_dist2();
141
+ init_dist2();
142
+ init_dist2();
143
+ init_dist2();
144
+ init_dist2();
139
145
  init_dist();
140
- init_dist3();
146
+ init_dist2();
141
147
  init_dist();
142
148
  init_dist();
143
149
  init_dist();
144
- init_dist3();
145
- init_dist3();
146
- init_dist3();
147
- init_dist3();
148
- init_dist3();
150
+ init_dist2();
151
+ init_dist2();
152
+ init_dist2();
153
+ init_dist2();
154
+ init_dist2();
149
155
  var import_api = __toESM(require_src(), 1);
150
156
  var import_api2 = __toESM(require_src(), 1);
151
157
  var __defProp = Object.defineProperty;
152
158
  var __export = (target, all) => {
153
- for (var name21 in all)
154
- __defProp(target, name21, { get: all[name21], enumerable: true });
159
+ for (var name22 in all)
160
+ __defProp(target, name22, { get: all[name22], enumerable: true });
155
161
  };
156
162
  var name = "AI_InvalidArgumentError";
157
163
  var marker = `vercel.ai.error.${name}`;
@@ -212,155 +218,160 @@ var InvalidToolApprovalError = class extends AISDKError {
212
218
  }
213
219
  };
214
220
  _a3 = symbol3;
215
- var name4 = "AI_InvalidToolInputError";
221
+ var name4 = "AI_InvalidToolApprovalSignatureError";
216
222
  var marker4 = `vercel.ai.error.${name4}`;
217
223
  var symbol4 = Symbol.for(marker4);
218
224
  var _a4;
219
- var InvalidToolInputError = class extends AISDKError {
225
+ var InvalidToolApprovalSignatureError = class extends AISDKError {
220
226
  constructor({
221
- toolInput,
222
- toolName,
223
- cause,
224
- message = `Invalid input for tool ${toolName}: ${getErrorMessage(cause)}`
227
+ approvalId,
228
+ toolCallId,
229
+ reason
225
230
  }) {
226
- super({ name: name4, message, cause });
231
+ super({
232
+ name: name4,
233
+ message: `Tool approval signature verification failed for approval "${approvalId}" (tool call "${toolCallId}"): ${reason}`
234
+ });
227
235
  this[_a4] = true;
228
- this.toolInput = toolInput;
229
- this.toolName = toolName;
236
+ this.approvalId = approvalId;
237
+ this.toolCallId = toolCallId;
230
238
  }
231
239
  static isInstance(error) {
232
240
  return AISDKError.hasMarker(error, marker4);
233
241
  }
234
242
  };
235
243
  _a4 = symbol4;
236
- var name5 = "AI_ToolCallNotFoundForApprovalError";
244
+ var name5 = "AI_InvalidToolInputError";
237
245
  var marker5 = `vercel.ai.error.${name5}`;
238
246
  var symbol5 = Symbol.for(marker5);
239
247
  var _a5;
240
- var ToolCallNotFoundForApprovalError = class extends AISDKError {
248
+ var InvalidToolInputError = class extends AISDKError {
241
249
  constructor({
242
- toolCallId,
243
- approvalId
250
+ toolInput,
251
+ toolName,
252
+ cause,
253
+ message = `Invalid input for tool ${toolName}: ${getErrorMessage(cause)}`
244
254
  }) {
245
- super({
246
- name: name5,
247
- message: `Tool call "${toolCallId}" not found for approval request "${approvalId}".`
248
- });
255
+ super({ name: name5, message, cause });
249
256
  this[_a5] = true;
250
- this.toolCallId = toolCallId;
251
- this.approvalId = approvalId;
257
+ this.toolInput = toolInput;
258
+ this.toolName = toolName;
252
259
  }
253
260
  static isInstance(error) {
254
261
  return AISDKError.hasMarker(error, marker5);
255
262
  }
256
263
  };
257
264
  _a5 = symbol5;
258
- var name6 = "AI_MissingToolResultsError";
265
+ var name6 = "AI_ToolCallNotFoundForApprovalError";
259
266
  var marker6 = `vercel.ai.error.${name6}`;
260
267
  var symbol6 = Symbol.for(marker6);
261
268
  var _a6;
262
- var MissingToolResultsError = class extends AISDKError {
263
- constructor({ toolCallIds }) {
269
+ var ToolCallNotFoundForApprovalError = class extends AISDKError {
270
+ constructor({
271
+ toolCallId,
272
+ approvalId
273
+ }) {
264
274
  super({
265
275
  name: name6,
266
- message: `Tool result${toolCallIds.length > 1 ? "s are" : " is"} missing for tool call${toolCallIds.length > 1 ? "s" : ""} ${toolCallIds.join(", ")}.`
276
+ message: `Tool call "${toolCallId}" not found for approval request "${approvalId}".`
267
277
  });
268
278
  this[_a6] = true;
269
- this.toolCallIds = toolCallIds;
279
+ this.toolCallId = toolCallId;
280
+ this.approvalId = approvalId;
270
281
  }
271
282
  static isInstance(error) {
272
283
  return AISDKError.hasMarker(error, marker6);
273
284
  }
274
285
  };
275
286
  _a6 = symbol6;
276
- var name7 = "AI_NoImageGeneratedError";
287
+ var name7 = "AI_MissingToolResultsError";
277
288
  var marker7 = `vercel.ai.error.${name7}`;
278
289
  var symbol7 = Symbol.for(marker7);
279
290
  var _a7;
280
- var NoImageGeneratedError = class extends AISDKError {
281
- constructor({
282
- message = "No image generated.",
283
- cause,
284
- responses
285
- }) {
286
- super({ name: name7, message, cause });
291
+ var MissingToolResultsError = class extends AISDKError {
292
+ constructor({ toolCallIds }) {
293
+ super({
294
+ name: name7,
295
+ message: `Tool result${toolCallIds.length > 1 ? "s are" : " is"} missing for tool call${toolCallIds.length > 1 ? "s" : ""} ${toolCallIds.join(", ")}.`
296
+ });
287
297
  this[_a7] = true;
288
- this.responses = responses;
298
+ this.toolCallIds = toolCallIds;
289
299
  }
290
300
  static isInstance(error) {
291
301
  return AISDKError.hasMarker(error, marker7);
292
302
  }
293
303
  };
294
304
  _a7 = symbol7;
295
- var name8 = "AI_NoObjectGeneratedError";
305
+ var name8 = "AI_NoImageGeneratedError";
296
306
  var marker8 = `vercel.ai.error.${name8}`;
297
307
  var symbol8 = Symbol.for(marker8);
298
308
  var _a8;
299
- var NoObjectGeneratedError = class extends AISDKError {
309
+ var NoImageGeneratedError = class extends AISDKError {
300
310
  constructor({
301
- message = "No object generated.",
311
+ message = "No image generated.",
302
312
  cause,
303
- text: text2,
304
- response,
305
- usage,
306
- finishReason
313
+ responses
307
314
  }) {
308
315
  super({ name: name8, message, cause });
309
316
  this[_a8] = true;
310
- this.text = text2;
311
- this.response = response;
312
- this.usage = usage;
313
- this.finishReason = finishReason;
317
+ this.responses = responses;
314
318
  }
315
319
  static isInstance(error) {
316
320
  return AISDKError.hasMarker(error, marker8);
317
321
  }
318
322
  };
319
323
  _a8 = symbol8;
320
- var name9 = "AI_NoOutputGeneratedError";
324
+ var name9 = "AI_NoObjectGeneratedError";
321
325
  var marker9 = `vercel.ai.error.${name9}`;
322
326
  var symbol9 = Symbol.for(marker9);
323
327
  var _a9;
324
- var NoOutputGeneratedError = class extends AISDKError {
328
+ var NoObjectGeneratedError = class extends AISDKError {
325
329
  constructor({
326
- message = "No output generated.",
327
- cause
328
- } = {}) {
330
+ message = "No object generated.",
331
+ cause,
332
+ text: text2,
333
+ response,
334
+ usage,
335
+ finishReason
336
+ }) {
329
337
  super({ name: name9, message, cause });
330
338
  this[_a9] = true;
339
+ this.text = text2;
340
+ this.response = response;
341
+ this.usage = usage;
342
+ this.finishReason = finishReason;
331
343
  }
332
344
  static isInstance(error) {
333
345
  return AISDKError.hasMarker(error, marker9);
334
346
  }
335
347
  };
336
348
  _a9 = symbol9;
337
- var name10 = "AI_NoSpeechGeneratedError";
349
+ var name10 = "AI_NoOutputGeneratedError";
338
350
  var marker10 = `vercel.ai.error.${name10}`;
339
351
  var symbol10 = Symbol.for(marker10);
340
352
  var _a10;
341
- var NoSpeechGeneratedError = class extends AISDKError {
342
- constructor(options) {
343
- super({
344
- name: name10,
345
- message: "No speech audio generated."
346
- });
353
+ var NoOutputGeneratedError = class extends AISDKError {
354
+ constructor({
355
+ message = "No output generated.",
356
+ cause
357
+ } = {}) {
358
+ super({ name: name10, message, cause });
347
359
  this[_a10] = true;
348
- this.responses = options.responses;
349
360
  }
350
361
  static isInstance(error) {
351
362
  return AISDKError.hasMarker(error, marker10);
352
363
  }
353
364
  };
354
365
  _a10 = symbol10;
355
- var name11 = "AI_NoTranscriptGeneratedError";
366
+ var name11 = "AI_NoSpeechGeneratedError";
356
367
  var marker11 = `vercel.ai.error.${name11}`;
357
368
  var symbol11 = Symbol.for(marker11);
358
369
  var _a11;
359
- var NoTranscriptGeneratedError = class extends AISDKError {
370
+ var NoSpeechGeneratedError = class extends AISDKError {
360
371
  constructor(options) {
361
372
  super({
362
373
  name: name11,
363
- message: "No transcript generated."
374
+ message: "No speech audio generated."
364
375
  });
365
376
  this[_a11] = true;
366
377
  this.responses = options.responses;
@@ -370,25 +381,43 @@ var NoTranscriptGeneratedError = class extends AISDKError {
370
381
  }
371
382
  };
372
383
  _a11 = symbol11;
373
- var name12 = "AI_NoVideoGeneratedError";
384
+ var name12 = "AI_NoTranscriptGeneratedError";
374
385
  var marker12 = `vercel.ai.error.${name12}`;
375
386
  var symbol12 = Symbol.for(marker12);
376
387
  var _a12;
388
+ var NoTranscriptGeneratedError = class extends AISDKError {
389
+ constructor(options) {
390
+ super({
391
+ name: name12,
392
+ message: "No transcript generated."
393
+ });
394
+ this[_a12] = true;
395
+ this.responses = options.responses;
396
+ }
397
+ static isInstance(error) {
398
+ return AISDKError.hasMarker(error, marker12);
399
+ }
400
+ };
401
+ _a12 = symbol12;
402
+ var name13 = "AI_NoVideoGeneratedError";
403
+ var marker13 = `vercel.ai.error.${name13}`;
404
+ var symbol13 = Symbol.for(marker13);
405
+ var _a13;
377
406
  var NoVideoGeneratedError = class extends AISDKError {
378
407
  constructor({
379
408
  message = "No video generated.",
380
409
  cause,
381
410
  responses
382
411
  }) {
383
- super({ name: name12, message, cause });
384
- this[_a12] = true;
412
+ super({ name: name13, message, cause });
413
+ this[_a13] = true;
385
414
  this.responses = responses;
386
415
  }
387
416
  static isInstance(error) {
388
- return AISDKError.hasMarker(error, marker12);
417
+ return AISDKError.hasMarker(error, marker13);
389
418
  }
390
419
  static isNoVideoGeneratedError(error) {
391
- return error instanceof Error && error.name === name12 && typeof error.responses !== "undefined" ? true : false;
420
+ return error instanceof Error && error.name === name13 && typeof error.responses !== "undefined" ? true : false;
392
421
  }
393
422
  toJSON() {
394
423
  return {
@@ -400,46 +429,46 @@ var NoVideoGeneratedError = class extends AISDKError {
400
429
  };
401
430
  }
402
431
  };
403
- _a12 = symbol12;
404
- var name13 = "AI_NoSuchToolError";
405
- var marker13 = `vercel.ai.error.${name13}`;
406
- var symbol13 = Symbol.for(marker13);
407
- var _a13;
432
+ _a13 = symbol13;
433
+ var name14 = "AI_NoSuchToolError";
434
+ var marker14 = `vercel.ai.error.${name14}`;
435
+ var symbol14 = Symbol.for(marker14);
436
+ var _a14;
408
437
  var NoSuchToolError = class extends AISDKError {
409
438
  constructor({
410
439
  toolName,
411
440
  availableTools = undefined,
412
441
  message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === undefined ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
413
442
  }) {
414
- super({ name: name13, message });
415
- this[_a13] = true;
443
+ super({ name: name14, message });
444
+ this[_a14] = true;
416
445
  this.toolName = toolName;
417
446
  this.availableTools = availableTools;
418
447
  }
419
448
  static isInstance(error) {
420
- return AISDKError.hasMarker(error, marker13);
449
+ return AISDKError.hasMarker(error, marker14);
421
450
  }
422
451
  };
423
- _a13 = symbol13;
424
- var name14 = "AI_ToolCallRepairError";
425
- var marker14 = `vercel.ai.error.${name14}`;
426
- var symbol14 = Symbol.for(marker14);
427
- var _a14;
452
+ _a14 = symbol14;
453
+ var name15 = "AI_ToolCallRepairError";
454
+ var marker15 = `vercel.ai.error.${name15}`;
455
+ var symbol15 = Symbol.for(marker15);
456
+ var _a15;
428
457
  var ToolCallRepairError = class extends AISDKError {
429
458
  constructor({
430
459
  cause,
431
460
  originalError,
432
461
  message = `Error repairing tool call: ${getErrorMessage(cause)}`
433
462
  }) {
434
- super({ name: name14, message, cause });
435
- this[_a14] = true;
463
+ super({ name: name15, message, cause });
464
+ this[_a15] = true;
436
465
  this.originalError = originalError;
437
466
  }
438
467
  static isInstance(error) {
439
- return AISDKError.hasMarker(error, marker14);
468
+ return AISDKError.hasMarker(error, marker15);
440
469
  }
441
470
  };
442
- _a14 = symbol14;
471
+ _a15 = symbol15;
443
472
  var UnsupportedModelVersionError = class extends AISDKError {
444
473
  constructor(options) {
445
474
  super({
@@ -451,102 +480,102 @@ var UnsupportedModelVersionError = class extends AISDKError {
451
480
  this.modelId = options.modelId;
452
481
  }
453
482
  };
454
- var name15 = "AI_UIMessageStreamError";
455
- var marker15 = `vercel.ai.error.${name15}`;
456
- var symbol15 = Symbol.for(marker15);
457
- var _a15;
483
+ var name16 = "AI_UIMessageStreamError";
484
+ var marker16 = `vercel.ai.error.${name16}`;
485
+ var symbol16 = Symbol.for(marker16);
486
+ var _a16;
458
487
  var UIMessageStreamError = class extends AISDKError {
459
488
  constructor({
460
489
  chunkType,
461
490
  chunkId,
462
491
  message
463
492
  }) {
464
- super({ name: name15, message });
465
- this[_a15] = true;
493
+ super({ name: name16, message });
494
+ this[_a16] = true;
466
495
  this.chunkType = chunkType;
467
496
  this.chunkId = chunkId;
468
497
  }
469
498
  static isInstance(error) {
470
- return AISDKError.hasMarker(error, marker15);
499
+ return AISDKError.hasMarker(error, marker16);
471
500
  }
472
501
  };
473
- _a15 = symbol15;
474
- var name16 = "AI_InvalidDataContentError";
475
- var marker16 = `vercel.ai.error.${name16}`;
476
- var symbol16 = Symbol.for(marker16);
477
- var _a16;
502
+ _a16 = symbol16;
503
+ var name17 = "AI_InvalidDataContentError";
504
+ var marker17 = `vercel.ai.error.${name17}`;
505
+ var symbol17 = Symbol.for(marker17);
506
+ var _a17;
478
507
  var InvalidDataContentError = class extends AISDKError {
479
508
  constructor({
480
509
  content,
481
510
  cause,
482
511
  message = `Invalid data content. Expected a base64 string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
483
512
  }) {
484
- super({ name: name16, message, cause });
485
- this[_a16] = true;
513
+ super({ name: name17, message, cause });
514
+ this[_a17] = true;
486
515
  this.content = content;
487
516
  }
488
517
  static isInstance(error) {
489
- return AISDKError.hasMarker(error, marker16);
518
+ return AISDKError.hasMarker(error, marker17);
490
519
  }
491
520
  };
492
- _a16 = symbol16;
493
- var name17 = "AI_InvalidMessageRoleError";
494
- var marker17 = `vercel.ai.error.${name17}`;
495
- var symbol17 = Symbol.for(marker17);
496
- var _a17;
521
+ _a17 = symbol17;
522
+ var name18 = "AI_InvalidMessageRoleError";
523
+ var marker18 = `vercel.ai.error.${name18}`;
524
+ var symbol18 = Symbol.for(marker18);
525
+ var _a18;
497
526
  var InvalidMessageRoleError = class extends AISDKError {
498
527
  constructor({
499
528
  role,
500
529
  message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
501
530
  }) {
502
- super({ name: name17, message });
503
- this[_a17] = true;
531
+ super({ name: name18, message });
532
+ this[_a18] = true;
504
533
  this.role = role;
505
534
  }
506
535
  static isInstance(error) {
507
- return AISDKError.hasMarker(error, marker17);
536
+ return AISDKError.hasMarker(error, marker18);
508
537
  }
509
538
  };
510
- _a17 = symbol17;
511
- var name18 = "AI_MessageConversionError";
512
- var marker18 = `vercel.ai.error.${name18}`;
513
- var symbol18 = Symbol.for(marker18);
514
- var _a18;
539
+ _a18 = symbol18;
540
+ var name19 = "AI_MessageConversionError";
541
+ var marker19 = `vercel.ai.error.${name19}`;
542
+ var symbol19 = Symbol.for(marker19);
543
+ var _a19;
515
544
  var MessageConversionError = class extends AISDKError {
516
545
  constructor({
517
546
  originalMessage,
518
547
  message
519
548
  }) {
520
- super({ name: name18, message });
521
- this[_a18] = true;
549
+ super({ name: name19, message });
550
+ this[_a19] = true;
522
551
  this.originalMessage = originalMessage;
523
552
  }
524
553
  static isInstance(error) {
525
- return AISDKError.hasMarker(error, marker18);
554
+ return AISDKError.hasMarker(error, marker19);
526
555
  }
527
556
  };
528
- _a18 = symbol18;
529
- var name19 = "AI_RetryError";
530
- var marker19 = `vercel.ai.error.${name19}`;
531
- var symbol19 = Symbol.for(marker19);
532
- var _a19;
557
+ _a19 = symbol19;
558
+ var name20 = "AI_RetryError";
559
+ var marker20 = `vercel.ai.error.${name20}`;
560
+ var symbol20 = Symbol.for(marker20);
561
+ var _a20;
533
562
  var RetryError = class extends AISDKError {
534
563
  constructor({
535
564
  message,
536
565
  reason,
537
566
  errors
538
567
  }) {
539
- super({ name: name19, message });
540
- this[_a19] = true;
568
+ super({ name: name20, message });
569
+ this[_a20] = true;
541
570
  this.reason = reason;
542
571
  this.errors = errors;
543
572
  this.lastError = errors[errors.length - 1];
544
573
  }
545
574
  static isInstance(error) {
546
- return AISDKError.hasMarker(error, marker19);
575
+ return AISDKError.hasMarker(error, marker20);
547
576
  }
548
577
  };
549
- _a19 = symbol19;
578
+ _a20 = symbol20;
550
579
  function asArray(value) {
551
580
  return value === undefined ? [] : Array.isArray(value) ? value : [value];
552
581
  }
@@ -798,7 +827,7 @@ function resolveEmbeddingModel(model) {
798
827
  return getGlobalProvider().embeddingModel(model);
799
828
  }
800
829
  function resolveTranscriptionModel(model) {
801
- var _a21, _b;
830
+ var _a22, _b;
802
831
  if (typeof model !== "string") {
803
832
  if (model.specificationVersion !== "v3" && model.specificationVersion !== "v2") {
804
833
  const unsupportedModel = model;
@@ -810,10 +839,10 @@ function resolveTranscriptionModel(model) {
810
839
  }
811
840
  return asTranscriptionModelV3(model);
812
841
  }
813
- return (_b = (_a21 = getGlobalProvider()).transcriptionModel) == null ? undefined : _b.call(_a21, model);
842
+ return (_b = (_a22 = getGlobalProvider()).transcriptionModel) == null ? undefined : _b.call(_a22, model);
814
843
  }
815
844
  function resolveSpeechModel(model) {
816
- var _a21, _b;
845
+ var _a22, _b;
817
846
  if (typeof model !== "string") {
818
847
  if (model.specificationVersion !== "v3" && model.specificationVersion !== "v2") {
819
848
  const unsupportedModel = model;
@@ -825,7 +854,7 @@ function resolveSpeechModel(model) {
825
854
  }
826
855
  return asSpeechModelV3(model);
827
856
  }
828
- return (_b = (_a21 = getGlobalProvider()).speechModel) == null ? undefined : _b.call(_a21, model);
857
+ return (_b = (_a22 = getGlobalProvider()).speechModel) == null ? undefined : _b.call(_a22, model);
829
858
  }
830
859
  function resolveImageModel(model) {
831
860
  if (typeof model !== "string") {
@@ -880,8 +909,8 @@ function resolveRerankingModel(model) {
880
909
  return model;
881
910
  }
882
911
  function getGlobalProvider() {
883
- var _a21;
884
- return (_a21 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a21 : gateway;
912
+ var _a22;
913
+ return (_a22 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a22 : gateway;
885
914
  }
886
915
  function getTotalTimeoutMs(timeout) {
887
916
  if (timeout == null) {
@@ -1104,24 +1133,23 @@ function detectMediaType({
1104
1133
  }
1105
1134
  return;
1106
1135
  }
1107
- var VERSION = "6.0.175";
1136
+ var VERSION = "6.0.208";
1108
1137
  var download = async ({
1109
1138
  url,
1110
1139
  maxBytes,
1111
1140
  abortSignal
1112
1141
  }) => {
1113
- var _a21;
1142
+ var _a22;
1114
1143
  const urlText = url.toString();
1115
- validateDownloadUrl(urlText);
1116
1144
  try {
1117
- const response = await fetch(urlText, {
1118
- headers: withUserAgentSuffix({}, `ai-sdk/${VERSION}`, getRuntimeEnvironmentUserAgent()),
1119
- signal: abortSignal
1145
+ const headers = withUserAgentSuffix({}, `ai-sdk/${VERSION}`, getRuntimeEnvironmentUserAgent());
1146
+ const response = await fetchWithValidatedRedirects({
1147
+ url: urlText,
1148
+ headers,
1149
+ abortSignal
1120
1150
  });
1121
- if (response.redirected) {
1122
- validateDownloadUrl(response.url);
1123
- }
1124
1151
  if (!response.ok) {
1152
+ await cancelResponseBody(response);
1125
1153
  throw new DownloadError({
1126
1154
  url: urlText,
1127
1155
  statusCode: response.status,
@@ -1135,7 +1163,7 @@ var download = async ({
1135
1163
  });
1136
1164
  return {
1137
1165
  data,
1138
- mediaType: (_a21 = response.headers.get("content-type")) != null ? _a21 : undefined
1166
+ mediaType: (_a22 = response.headers.get("content-type")) != null ? _a22 : undefined
1139
1167
  };
1140
1168
  } catch (error) {
1141
1169
  if (DownloadError.isInstance(error)) {
@@ -1164,8 +1192,8 @@ var dataContentSchema = exports_external.union([
1164
1192
  exports_external.instanceof(Uint8Array),
1165
1193
  exports_external.instanceof(ArrayBuffer),
1166
1194
  exports_external.custom((value) => {
1167
- var _a21, _b;
1168
- return (_b = (_a21 = globalThis.Buffer) == null ? undefined : _a21.isBuffer(value)) != null ? _b : false;
1195
+ var _a22, _b;
1196
+ return (_b = (_a22 = globalThis.Buffer) == null ? undefined : _a22.isBuffer(value)) != null ? _b : false;
1169
1197
  }, { message: "Must be a Buffer" })
1170
1198
  ]);
1171
1199
  function convertToLanguageModelV3DataContent(content) {
@@ -1390,7 +1418,10 @@ function convertToLanguageModelMessage({
1390
1418
  type: "tool-result",
1391
1419
  toolCallId: part.toolCallId,
1392
1420
  toolName: part.toolName,
1393
- output: mapToolResultOutput(part.output),
1421
+ output: mapToolResultOutput({
1422
+ output: part.output,
1423
+ downloadedAssets
1424
+ }),
1394
1425
  providerOptions
1395
1426
  };
1396
1427
  }
@@ -1409,7 +1440,10 @@ function convertToLanguageModelMessage({
1409
1440
  type: "tool-result",
1410
1441
  toolCallId: part.toolCallId,
1411
1442
  toolName: part.toolName,
1412
- output: mapToolResultOutput(part.output),
1443
+ output: mapToolResultOutput({
1444
+ output: part.output,
1445
+ downloadedAssets
1446
+ }),
1413
1447
  providerOptions: part.providerOptions
1414
1448
  };
1415
1449
  }
@@ -1433,15 +1467,44 @@ function convertToLanguageModelMessage({
1433
1467
  }
1434
1468
  }
1435
1469
  async function downloadAssets(messages, download2, supportedUrls) {
1436
- const plannedDownloads = messages.filter((message) => message.role === "user").map((message) => message.content).filter((content) => Array.isArray(content)).flat().filter((part) => part.type === "image" || part.type === "file").map((part) => {
1437
- var _a21;
1438
- const mediaType = (_a21 = part.mediaType) != null ? _a21 : part.type === "image" ? "image/*" : undefined;
1439
- let data = part.type === "image" ? part.image : part.data;
1440
- if (typeof data === "string") {
1441
- try {
1442
- data = new URL(data);
1443
- } catch (ignored) {}
1470
+ var _a22;
1471
+ const downloadableFiles = [];
1472
+ for (const message of messages) {
1473
+ if (message.role === "user" && Array.isArray(message.content)) {
1474
+ for (const part of message.content) {
1475
+ if (part.type === "image" || part.type === "file") {
1476
+ downloadableFiles.push({
1477
+ data: part.type === "image" ? part.image : part.data,
1478
+ mediaType: (_a22 = part.mediaType) != null ? _a22 : part.type === "image" ? "image/*" : undefined
1479
+ });
1480
+ }
1481
+ }
1444
1482
  }
1483
+ if (message.role === "tool" || message.role === "assistant") {
1484
+ if (!Array.isArray(message.content)) {
1485
+ continue;
1486
+ }
1487
+ for (const part of message.content) {
1488
+ if (part.type !== "tool-result") {
1489
+ continue;
1490
+ }
1491
+ if (part.output.type !== "content") {
1492
+ continue;
1493
+ }
1494
+ for (const contentPart of part.output.value) {
1495
+ if (contentPart.type === "image-url" || contentPart.type === "file-url") {
1496
+ downloadableFiles.push({
1497
+ data: new URL(contentPart.url),
1498
+ mediaType: contentPart.type === "image-url" ? "image/*" : undefined
1499
+ });
1500
+ }
1501
+ }
1502
+ }
1503
+ }
1504
+ }
1505
+ const plannedDownloads = downloadableFiles.map((part) => {
1506
+ const mediaType = part.mediaType;
1507
+ const { data } = convertToLanguageModelV3DataContent(part.data);
1445
1508
  return { mediaType, data };
1446
1509
  }).filter((part) => part.data instanceof URL).map((part) => ({
1447
1510
  url: part.data,
@@ -1458,7 +1521,7 @@ async function downloadAssets(messages, download2, supportedUrls) {
1458
1521
  ]).filter((file) => file != null));
1459
1522
  }
1460
1523
  function convertPartToLanguageModelPart(part, downloadedAssets) {
1461
- var _a21;
1524
+ var _a22;
1462
1525
  if (part.type === "text") {
1463
1526
  return {
1464
1527
  type: "text",
@@ -1491,7 +1554,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
1491
1554
  switch (type) {
1492
1555
  case "image": {
1493
1556
  if (data instanceof Uint8Array || typeof data === "string") {
1494
- mediaType = (_a21 = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _a21 : mediaType;
1557
+ mediaType = (_a22 = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _a22 : mediaType;
1495
1558
  }
1496
1559
  return {
1497
1560
  type: "file",
@@ -1515,13 +1578,41 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
1515
1578
  }
1516
1579
  }
1517
1580
  }
1518
- function mapToolResultOutput(output) {
1581
+ function mapToolResultOutput({
1582
+ output,
1583
+ downloadedAssets
1584
+ }) {
1519
1585
  if (output.type !== "content") {
1520
1586
  return output;
1521
1587
  }
1522
1588
  return {
1523
1589
  type: "content",
1524
1590
  value: output.value.map((item) => {
1591
+ var _a22, _b;
1592
+ if (item.type === "image-url") {
1593
+ const downloadedFile = downloadedAssets[new URL(item.url).toString()];
1594
+ if (downloadedFile) {
1595
+ return {
1596
+ type: "image-data",
1597
+ data: convertDataContentToBase64String(downloadedFile.data),
1598
+ mediaType: (_a22 = downloadedFile.mediaType) != null ? _a22 : "image/*",
1599
+ providerOptions: item.providerOptions
1600
+ };
1601
+ }
1602
+ return item;
1603
+ }
1604
+ if (item.type === "file-url") {
1605
+ const downloadedFile = downloadedAssets[new URL(item.url).toString()];
1606
+ if (downloadedFile) {
1607
+ return {
1608
+ type: "file-data",
1609
+ data: convertDataContentToBase64String(downloadedFile.data),
1610
+ mediaType: (_b = downloadedFile.mediaType) != null ? _b : "application/octet-stream",
1611
+ providerOptions: item.providerOptions
1612
+ };
1613
+ }
1614
+ return item;
1615
+ }
1525
1616
  if (item.type !== "media") {
1526
1617
  return item;
1527
1618
  }
@@ -1665,9 +1756,9 @@ async function prepareToolsAndToolChoice({
1665
1756
  toolChoice: undefined
1666
1757
  };
1667
1758
  }
1668
- const filteredTools = activeTools != null ? Object.entries(tools).filter(([name21]) => activeTools.includes(name21)) : Object.entries(tools);
1759
+ const filteredTools = activeTools != null ? Object.entries(tools).filter(([name22]) => activeTools.includes(name22)) : Object.entries(tools);
1669
1760
  const languageModelTools = [];
1670
- for (const [name21, tool2] of filteredTools) {
1761
+ for (const [name22, tool2] of filteredTools) {
1671
1762
  const toolType = tool2.type;
1672
1763
  switch (toolType) {
1673
1764
  case undefined:
@@ -1675,7 +1766,7 @@ async function prepareToolsAndToolChoice({
1675
1766
  case "function":
1676
1767
  languageModelTools.push({
1677
1768
  type: "function",
1678
- name: name21,
1769
+ name: name22,
1679
1770
  description: tool2.description,
1680
1771
  inputSchema: await asSchema(tool2.inputSchema).jsonSchema,
1681
1772
  ...tool2.inputExamples != null ? { inputExamples: tool2.inputExamples } : {},
@@ -1686,7 +1777,7 @@ async function prepareToolsAndToolChoice({
1686
1777
  case "provider":
1687
1778
  languageModelTools.push({
1688
1779
  type: "provider",
1689
- name: name21,
1780
+ name: name22,
1690
1781
  id: tool2.id,
1691
1782
  args: tool2.args
1692
1783
  });
@@ -1980,7 +2071,7 @@ function getBaseTelemetryAttributes({
1980
2071
  telemetry,
1981
2072
  headers
1982
2073
  }) {
1983
- var _a21;
2074
+ var _a22;
1984
2075
  return {
1985
2076
  "ai.model.provider": model.provider,
1986
2077
  "ai.model.id": model.modelId,
@@ -1995,7 +2086,7 @@ function getBaseTelemetryAttributes({
1995
2086
  }
1996
2087
  return attributes;
1997
2088
  }, {}),
1998
- ...Object.entries((_a21 = telemetry == null ? undefined : telemetry.metadata) != null ? _a21 : {}).reduce((attributes, [key, value]) => {
2089
+ ...Object.entries((_a22 = telemetry == null ? undefined : telemetry.metadata) != null ? _a22 : {}).reduce((attributes, [key, value]) => {
1999
2090
  attributes[`ai.telemetry.metadata.${key}`] = value;
2000
2091
  return attributes;
2001
2092
  }, {}),
@@ -2011,7 +2102,7 @@ var noopTracer = {
2011
2102
  startSpan() {
2012
2103
  return noopSpan;
2013
2104
  },
2014
- startActiveSpan(name21, arg1, arg2, arg3) {
2105
+ startActiveSpan(name22, arg1, arg2, arg3) {
2015
2106
  if (typeof arg1 === "function") {
2016
2107
  return arg1(noopSpan);
2017
2108
  }
@@ -2076,13 +2167,13 @@ function getTracer({
2076
2167
  return import_api.trace.getTracer("ai");
2077
2168
  }
2078
2169
  async function recordSpan({
2079
- name: name21,
2170
+ name: name22,
2080
2171
  tracer,
2081
2172
  attributes,
2082
2173
  fn,
2083
2174
  endWhenDone = true
2084
2175
  }) {
2085
- return tracer.startActiveSpan(name21, { attributes: await attributes }, async (span) => {
2176
+ return tracer.startActiveSpan(name22, { attributes: await attributes }, async (span) => {
2086
2177
  const ctx = import_api2.context.active();
2087
2178
  try {
2088
2179
  const result = await import_api2.context.with(ctx, () => fn(span));
@@ -2167,13 +2258,13 @@ function registerTelemetryIntegration(integration) {
2167
2258
  globalThis.AI_SDK_TELEMETRY_INTEGRATIONS.push(integration);
2168
2259
  }
2169
2260
  function getGlobalTelemetryIntegrations() {
2170
- var _a21;
2171
- return (_a21 = globalThis.AI_SDK_TELEMETRY_INTEGRATIONS) != null ? _a21 : [];
2261
+ var _a22;
2262
+ return (_a22 = globalThis.AI_SDK_TELEMETRY_INTEGRATIONS) != null ? _a22 : [];
2172
2263
  }
2173
2264
  function bindTelemetryIntegration(integration) {
2174
- var _a21, _b, _c, _d, _e, _f;
2265
+ var _a22, _b, _c, _d, _e, _f;
2175
2266
  return {
2176
- onStart: (_a21 = integration.onStart) == null ? undefined : _a21.bind(integration),
2267
+ onStart: (_a22 = integration.onStart) == null ? undefined : _a22.bind(integration),
2177
2268
  onStepStart: (_b = integration.onStepStart) == null ? undefined : _b.bind(integration),
2178
2269
  onToolCallStart: (_c = integration.onToolCallStart) == null ? undefined : _c.bind(integration),
2179
2270
  onToolCallFinish: (_d = integration.onToolCallFinish) == null ? undefined : _d.bind(integration),
@@ -2243,11 +2334,11 @@ function createNullLanguageModelUsage() {
2243
2334
  };
2244
2335
  }
2245
2336
  function addLanguageModelUsage(usage1, usage2) {
2246
- var _a21, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2337
+ var _a22, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2247
2338
  return {
2248
2339
  inputTokens: addTokenCounts(usage1.inputTokens, usage2.inputTokens),
2249
2340
  inputTokenDetails: {
2250
- noCacheTokens: addTokenCounts((_a21 = usage1.inputTokenDetails) == null ? undefined : _a21.noCacheTokens, (_b = usage2.inputTokenDetails) == null ? undefined : _b.noCacheTokens),
2341
+ noCacheTokens: addTokenCounts((_a22 = usage1.inputTokenDetails) == null ? undefined : _a22.noCacheTokens, (_b = usage2.inputTokenDetails) == null ? undefined : _b.noCacheTokens),
2251
2342
  cacheReadTokens: addTokenCounts((_c = usage1.inputTokenDetails) == null ? undefined : _c.cacheReadTokens, (_d = usage2.inputTokenDetails) == null ? undefined : _d.cacheReadTokens),
2252
2343
  cacheWriteTokens: addTokenCounts((_e = usage1.inputTokenDetails) == null ? undefined : _e.cacheWriteTokens, (_f = usage2.inputTokenDetails) == null ? undefined : _f.cacheWriteTokens)
2253
2344
  },
@@ -2306,7 +2397,7 @@ function getRetryDelayInMs({
2306
2397
  error,
2307
2398
  exponentialBackoffDelay
2308
2399
  }) {
2309
- const headers = error.responseHeaders;
2400
+ const headers = APICallError.isInstance(error) ? error.responseHeaders : APICallError.isInstance(error.cause) ? error.cause.responseHeaders : undefined;
2310
2401
  if (!headers)
2311
2402
  return exponentialBackoffDelay;
2312
2403
  let ms;
@@ -2367,7 +2458,7 @@ async function _retryWithExponentialBackoff(f, {
2367
2458
  errors: newErrors
2368
2459
  });
2369
2460
  }
2370
- if (error instanceof Error && APICallError.isInstance(error) && error.isRetryable === true && tryNumber <= maxRetries) {
2461
+ if (error instanceof Error && (APICallError.isInstance(error) && error.isRetryable === true || GatewayError.isInstance(error) && error.isRetryable === true) && tryNumber <= maxRetries) {
2371
2462
  await delay(getRetryDelayInMs({
2372
2463
  error,
2373
2464
  exponentialBackoffDelay: delayInMs
@@ -2490,8 +2581,8 @@ function collectToolApprovals({
2490
2581
  return { approvedToolApprovals, deniedToolApprovals };
2491
2582
  }
2492
2583
  function now() {
2493
- var _a21, _b;
2494
- return (_b = (_a21 = globalThis == null ? undefined : globalThis.performance) == null ? undefined : _a21.now()) != null ? _b : Date.now();
2584
+ var _a22, _b;
2585
+ return (_b = (_a22 = globalThis == null ? undefined : globalThis.performance) == null ? undefined : _a22.now()) != null ? _b : Date.now();
2495
2586
  }
2496
2587
  async function executeToolCall({
2497
2588
  toolCall,
@@ -2585,7 +2676,8 @@ async function executeToolCall({
2585
2676
  input,
2586
2677
  error,
2587
2678
  dynamic: tool2.type === "dynamic",
2588
- ...toolCall.providerMetadata != null ? { providerMetadata: toolCall.providerMetadata } : {}
2679
+ ...toolCall.providerMetadata != null ? { providerMetadata: toolCall.providerMetadata } : {},
2680
+ ...toolCall.toolMetadata != null ? { toolMetadata: toolCall.toolMetadata } : {}
2589
2681
  };
2590
2682
  }
2591
2683
  const durationMs = now() - startTime;
@@ -2615,7 +2707,8 @@ async function executeToolCall({
2615
2707
  input,
2616
2708
  output,
2617
2709
  dynamic: tool2.type === "dynamic",
2618
- ...toolCall.providerMetadata != null ? { providerMetadata: toolCall.providerMetadata } : {}
2710
+ ...toolCall.providerMetadata != null ? { providerMetadata: toolCall.providerMetadata } : {},
2711
+ ...toolCall.toolMetadata != null ? { toolMetadata: toolCall.toolMetadata } : {}
2619
2712
  };
2620
2713
  }
2621
2714
  });
@@ -2679,6 +2772,151 @@ async function isApprovalNeeded({
2679
2772
  experimental_context
2680
2773
  });
2681
2774
  }
2775
+ var encoder = new TextEncoder;
2776
+ function canonicalJSON(value) {
2777
+ if (value === null || value === undefined) {
2778
+ return JSON.stringify(value);
2779
+ }
2780
+ if (typeof value !== "object") {
2781
+ return JSON.stringify(value);
2782
+ }
2783
+ if (Array.isArray(value)) {
2784
+ return `[${value.map(canonicalJSON).join(",")}]`;
2785
+ }
2786
+ const keys = Object.keys(value).sort();
2787
+ const entries = keys.map((k) => `${JSON.stringify(k)}:${canonicalJSON(value[k])}`);
2788
+ return `{${entries.join(",")}}`;
2789
+ }
2790
+ function toBase64url(bytes) {
2791
+ return convertUint8ArrayToBase64(bytes).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
2792
+ }
2793
+ function fromBase64url(str) {
2794
+ return convertBase64ToUint8Array(str);
2795
+ }
2796
+ async function importKey(secret) {
2797
+ const keyData = typeof secret === "string" ? encoder.encode(secret) : secret;
2798
+ return crypto.subtle.importKey("raw", keyData, { name: "HMAC", hash: "SHA-256" }, false, ["sign", "verify"]);
2799
+ }
2800
+ async function hashInput(input) {
2801
+ const canonical = canonicalJSON(input);
2802
+ const digest = await crypto.subtle.digest("SHA-256", encoder.encode(canonical));
2803
+ return toBase64url(new Uint8Array(digest));
2804
+ }
2805
+ function buildPayload(approvalId, toolCallId, toolName, inputDigest) {
2806
+ return encoder.encode(`${approvalId}
2807
+ ${toolCallId}
2808
+ ${toolName}
2809
+ ${inputDigest}`);
2810
+ }
2811
+ async function signToolApproval({
2812
+ secret,
2813
+ approvalId,
2814
+ toolCallId,
2815
+ toolName,
2816
+ input
2817
+ }) {
2818
+ const key = await importKey(secret);
2819
+ const inputDigest = await hashInput(input);
2820
+ const payload = buildPayload(approvalId, toolCallId, toolName, inputDigest);
2821
+ const sig = await crypto.subtle.sign("HMAC", key, payload);
2822
+ return toBase64url(new Uint8Array(sig));
2823
+ }
2824
+ async function verifyToolApprovalSignature({
2825
+ secret,
2826
+ signature,
2827
+ approvalId,
2828
+ toolCallId,
2829
+ toolName,
2830
+ input
2831
+ }) {
2832
+ const key = await importKey(secret);
2833
+ const inputDigest = await hashInput(input);
2834
+ const payload = buildPayload(approvalId, toolCallId, toolName, inputDigest);
2835
+ const sigBytes = fromBase64url(signature);
2836
+ return crypto.subtle.verify("HMAC", key, sigBytes, payload);
2837
+ }
2838
+ async function maybeSignApproval({
2839
+ secret,
2840
+ approvalId,
2841
+ toolCallId,
2842
+ toolName,
2843
+ input
2844
+ }) {
2845
+ if (secret == null)
2846
+ return;
2847
+ return signToolApproval({ secret, approvalId, toolCallId, toolName, input });
2848
+ }
2849
+ async function validateApprovedToolApprovals({
2850
+ approvedToolApprovals,
2851
+ tools,
2852
+ messages,
2853
+ experimental_context,
2854
+ toolApprovalSecret
2855
+ }) {
2856
+ var _a22;
2857
+ const approved = [];
2858
+ const denied = [];
2859
+ for (const approval of approvedToolApprovals) {
2860
+ const { toolCall, approvalRequest } = approval;
2861
+ const tool2 = tools == null ? undefined : tools[toolCall.toolName];
2862
+ if (toolApprovalSecret != null) {
2863
+ if (approvalRequest.signature == null) {
2864
+ throw new InvalidToolApprovalSignatureError({
2865
+ approvalId: approvalRequest.approvalId,
2866
+ toolCallId: toolCall.toolCallId,
2867
+ reason: "missing signature"
2868
+ });
2869
+ }
2870
+ const valid = await verifyToolApprovalSignature({
2871
+ secret: toolApprovalSecret,
2872
+ signature: approvalRequest.signature,
2873
+ approvalId: approvalRequest.approvalId,
2874
+ toolCallId: toolCall.toolCallId,
2875
+ toolName: toolCall.toolName,
2876
+ input: toolCall.input
2877
+ });
2878
+ if (!valid) {
2879
+ throw new InvalidToolApprovalSignatureError({
2880
+ approvalId: approvalRequest.approvalId,
2881
+ toolCallId: toolCall.toolCallId,
2882
+ reason: "invalid signature"
2883
+ });
2884
+ }
2885
+ }
2886
+ if (tool2 != null && typeof tool2.execute === "function" && tool2.inputSchema != null) {
2887
+ const validation = await safeValidateTypes({
2888
+ value: toolCall.input,
2889
+ schema: asSchema(tool2.inputSchema)
2890
+ });
2891
+ if (!validation.success) {
2892
+ throw new InvalidToolInputError({
2893
+ toolName: toolCall.toolName,
2894
+ toolInput: JSON.stringify(toolCall.input),
2895
+ cause: validation.error
2896
+ });
2897
+ }
2898
+ }
2899
+ const approvalNeeded = tool2 != null && await isApprovalNeeded({
2900
+ tool: tool2,
2901
+ toolCall,
2902
+ messages,
2903
+ experimental_context
2904
+ });
2905
+ if (approvalNeeded) {
2906
+ approved.push(approval);
2907
+ } else {
2908
+ denied.push({
2909
+ ...approval,
2910
+ approvalResponse: {
2911
+ ...approval.approvalResponse,
2912
+ approved: false,
2913
+ reason: (_a22 = approval.approvalResponse.reason) != null ? _a22 : `Tool "${toolCall.toolName}" does not require approval`
2914
+ }
2915
+ });
2916
+ }
2917
+ }
2918
+ return { approvedToolApprovals: approved, deniedToolApprovals: denied };
2919
+ }
2682
2920
  var output_exports = {};
2683
2921
  __export(output_exports, {
2684
2922
  array: () => array,
@@ -2691,6 +2929,10 @@ function fixJson(input) {
2691
2929
  const stack = ["ROOT"];
2692
2930
  let lastValidIndex = -1;
2693
2931
  let literalStart = null;
2932
+ let unicodeEscapeDigits = 0;
2933
+ function isHexDigit(char) {
2934
+ return char >= "0" && char <= "9" || char >= "A" && char <= "F" || char >= "a" && char <= "f";
2935
+ }
2694
2936
  function processValueStart(char, i, swapState) {
2695
2937
  {
2696
2938
  switch (char) {
@@ -2895,7 +3137,22 @@ function fixJson(input) {
2895
3137
  }
2896
3138
  case "INSIDE_STRING_ESCAPE": {
2897
3139
  stack.pop();
2898
- lastValidIndex = i;
3140
+ if (char === "u") {
3141
+ unicodeEscapeDigits = 0;
3142
+ stack.push("INSIDE_STRING_UNICODE_ESCAPE");
3143
+ } else {
3144
+ lastValidIndex = i;
3145
+ }
3146
+ break;
3147
+ }
3148
+ case "INSIDE_STRING_UNICODE_ESCAPE": {
3149
+ if (isHexDigit(char)) {
3150
+ unicodeEscapeDigits++;
3151
+ if (unicodeEscapeDigits === 4) {
3152
+ stack.pop();
3153
+ lastValidIndex = i;
3154
+ }
3155
+ }
2899
3156
  break;
2900
3157
  }
2901
3158
  case "INSIDE_NUMBER": {
@@ -3032,7 +3289,7 @@ var text = () => ({
3032
3289
  });
3033
3290
  var object = ({
3034
3291
  schema: inputSchema,
3035
- name: name21,
3292
+ name: name22,
3036
3293
  description
3037
3294
  }) => {
3038
3295
  const schema = asSchema(inputSchema);
@@ -3041,7 +3298,7 @@ var object = ({
3041
3298
  responseFormat: resolve(schema.jsonSchema).then((jsonSchema2) => ({
3042
3299
  type: "json",
3043
3300
  schema: jsonSchema2,
3044
- ...name21 != null && { name: name21 },
3301
+ ...name22 != null && { name: name22 },
3045
3302
  ...description != null && { description }
3046
3303
  })),
3047
3304
  async parseCompleteOutput({ text: text2 }, context2) {
@@ -3094,7 +3351,7 @@ var object = ({
3094
3351
  };
3095
3352
  var array = ({
3096
3353
  element: inputElementSchema,
3097
- name: name21,
3354
+ name: name22,
3098
3355
  description
3099
3356
  }) => {
3100
3357
  const elementSchema = asSchema(inputElementSchema);
@@ -3113,7 +3370,7 @@ var array = ({
3113
3370
  required: ["elements"],
3114
3371
  additionalProperties: false
3115
3372
  },
3116
- ...name21 != null && { name: name21 },
3373
+ ...name22 != null && { name: name22 },
3117
3374
  ...description != null && { description }
3118
3375
  };
3119
3376
  }),
@@ -3205,7 +3462,7 @@ var array = ({
3205
3462
  };
3206
3463
  var choice = ({
3207
3464
  options: choiceOptions,
3208
- name: name21,
3465
+ name: name22,
3209
3466
  description
3210
3467
  }) => {
3211
3468
  return {
@@ -3221,7 +3478,7 @@ var choice = ({
3221
3478
  required: ["result"],
3222
3479
  additionalProperties: false
3223
3480
  },
3224
- ...name21 != null && { name: name21 },
3481
+ ...name22 != null && { name: name22 },
3225
3482
  ...description != null && { description }
3226
3483
  }),
3227
3484
  async parseCompleteOutput({ text: text2 }, context2) {
@@ -3280,14 +3537,14 @@ var choice = ({
3280
3537
  };
3281
3538
  };
3282
3539
  var json = ({
3283
- name: name21,
3540
+ name: name22,
3284
3541
  description
3285
3542
  } = {}) => {
3286
3543
  return {
3287
3544
  name: "json",
3288
3545
  responseFormat: Promise.resolve({
3289
3546
  type: "json",
3290
- ...name21 != null && { name: name21 },
3547
+ ...name22 != null && { name: name22 },
3291
3548
  ...description != null && { description }
3292
3549
  }),
3293
3550
  async parseCompleteOutput({ text: text2 }, context2) {
@@ -3322,15 +3579,6 @@ var json = ({
3322
3579
  }
3323
3580
  };
3324
3581
  };
3325
- function mergeToolProviderMetadata(toolMetadata, callMetadata) {
3326
- if (toolMetadata == null) {
3327
- return callMetadata;
3328
- }
3329
- if (callMetadata == null) {
3330
- return toolMetadata;
3331
- }
3332
- return { ...toolMetadata, ...callMetadata };
3333
- }
3334
3582
  async function parseToolCall({
3335
3583
  toolCall,
3336
3584
  tools,
@@ -3338,7 +3586,6 @@ async function parseToolCall({
3338
3586
  system,
3339
3587
  messages
3340
3588
  }) {
3341
- var _a21, _b;
3342
3589
  try {
3343
3590
  if (tools == null) {
3344
3591
  if (toolCall.providerExecuted && toolCall.dynamic) {
@@ -3379,6 +3626,7 @@ async function parseToolCall({
3379
3626
  } catch (error) {
3380
3627
  const parsedInput = await safeParseJSON({ text: toolCall.input });
3381
3628
  const input = parsedInput.success ? parsedInput.value : toolCall.input;
3629
+ const tool2 = tools == null ? undefined : tools[toolCall.toolName];
3382
3630
  return {
3383
3631
  type: "tool-call",
3384
3632
  toolCallId: toolCall.toolCallId,
@@ -3387,9 +3635,10 @@ async function parseToolCall({
3387
3635
  dynamic: true,
3388
3636
  invalid: true,
3389
3637
  error,
3390
- title: (_a21 = tools == null ? undefined : tools[toolCall.toolName]) == null ? undefined : _a21.title,
3638
+ title: tool2 == null ? undefined : tool2.title,
3391
3639
  providerExecuted: toolCall.providerExecuted,
3392
- providerMetadata: mergeToolProviderMetadata((_b = tools == null ? undefined : tools[toolCall.toolName]) == null ? undefined : _b.providerMetadata, toolCall.providerMetadata)
3640
+ providerMetadata: toolCall.providerMetadata,
3641
+ ...(tool2 == null ? undefined : tool2.metadata) != null ? { toolMetadata: tool2.metadata } : {}
3393
3642
  };
3394
3643
  }
3395
3644
  }
@@ -3436,14 +3685,14 @@ async function doParseToolCall({
3436
3685
  cause: parseResult.error
3437
3686
  });
3438
3687
  }
3439
- const mergedProviderMetadata = mergeToolProviderMetadata(tool2.providerMetadata, toolCall.providerMetadata);
3440
3688
  return tool2.type === "dynamic" ? {
3441
3689
  type: "tool-call",
3442
3690
  toolCallId: toolCall.toolCallId,
3443
3691
  toolName: toolCall.toolName,
3444
3692
  input: parseResult.value,
3445
3693
  providerExecuted: toolCall.providerExecuted,
3446
- providerMetadata: mergedProviderMetadata,
3694
+ providerMetadata: toolCall.providerMetadata,
3695
+ ...tool2.metadata != null ? { toolMetadata: tool2.metadata } : {},
3447
3696
  dynamic: true,
3448
3697
  title: tool2.title
3449
3698
  } : {
@@ -3452,7 +3701,8 @@ async function doParseToolCall({
3452
3701
  toolName,
3453
3702
  input: parseResult.value,
3454
3703
  providerExecuted: toolCall.providerExecuted,
3455
- providerMetadata: mergedProviderMetadata,
3704
+ providerMetadata: toolCall.providerMetadata,
3705
+ ...tool2.metadata != null ? { toolMetadata: tool2.metadata } : {},
3456
3706
  title: tool2.title
3457
3707
  };
3458
3708
  }
@@ -3528,8 +3778,8 @@ function isLoopFinished() {
3528
3778
  }
3529
3779
  function hasToolCall(toolName) {
3530
3780
  return ({ steps }) => {
3531
- var _a21, _b, _c;
3532
- return (_c = (_b = (_a21 = steps[steps.length - 1]) == null ? undefined : _a21.toolCalls) == null ? undefined : _b.some((toolCall) => toolCall.toolName === toolName)) != null ? _c : false;
3781
+ var _a22, _b, _c;
3782
+ return (_c = (_b = (_a22 = steps[steps.length - 1]) == null ? undefined : _a22.toolCalls) == null ? undefined : _b.some((toolCall) => toolCall.toolName === toolName)) != null ? _c : false;
3533
3783
  };
3534
3784
  }
3535
3785
  async function isStopConditionMet({
@@ -3625,7 +3875,8 @@ async function toResponseMessages({
3625
3875
  content.push({
3626
3876
  type: "tool-approval-request",
3627
3877
  approvalId: part.approvalId,
3628
- toolCallId: part.toolCall.toolCallId
3878
+ toolCallId: part.toolCall.toolCallId,
3879
+ ...part.signature != null ? { signature: part.signature } : {}
3629
3880
  });
3630
3881
  break;
3631
3882
  }
@@ -3712,6 +3963,7 @@ async function generateText({
3712
3963
  experimental_repairToolCall: repairToolCall,
3713
3964
  experimental_download: download2,
3714
3965
  experimental_context,
3966
+ experimental_toolApprovalSecret,
3715
3967
  experimental_include: include,
3716
3968
  _internal: { generateId: generateId2 = originalGenerateId } = {},
3717
3969
  experimental_onStart: onStart,
@@ -3804,11 +4056,27 @@ async function generateText({
3804
4056
  }),
3805
4057
  tracer,
3806
4058
  fn: async (span) => {
3807
- var _a21, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
4059
+ var _a22, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
3808
4060
  const initialMessages = initialPrompt.messages;
3809
4061
  const responseMessages = [];
3810
- const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({ messages: initialMessages });
3811
- const localApprovedToolApprovals = approvedToolApprovals.filter((toolApproval) => !toolApproval.toolCall.providerExecuted);
4062
+ const {
4063
+ approvedToolApprovals,
4064
+ deniedToolApprovals: collectedDeniedToolApprovals
4065
+ } = collectToolApprovals({ messages: initialMessages });
4066
+ const {
4067
+ approvedToolApprovals: localApprovedToolApprovals,
4068
+ deniedToolApprovals: revalidationDeniedToolApprovals
4069
+ } = await validateApprovedToolApprovals({
4070
+ approvedToolApprovals: approvedToolApprovals.filter((toolApproval) => !toolApproval.toolCall.providerExecuted),
4071
+ tools,
4072
+ messages: initialMessages,
4073
+ experimental_context,
4074
+ toolApprovalSecret: experimental_toolApprovalSecret
4075
+ });
4076
+ const deniedToolApprovals = [
4077
+ ...collectedDeniedToolApprovals,
4078
+ ...revalidationDeniedToolApprovals
4079
+ ];
3812
4080
  if (deniedToolApprovals.length > 0 || localApprovedToolApprovals.length > 0) {
3813
4081
  const toolOutputs = await executeTools({
3814
4082
  toolCalls: localApprovedToolApprovals.map((toolApproval) => toolApproval.toolCall),
@@ -3885,7 +4153,7 @@ async function generateText({
3885
4153
  messages: stepInputMessages,
3886
4154
  experimental_context
3887
4155
  }));
3888
- const stepModel = resolveLanguageModel((_a21 = prepareStepResult == null ? undefined : prepareStepResult.model) != null ? _a21 : model);
4156
+ const stepModel = resolveLanguageModel((_a22 = prepareStepResult == null ? undefined : prepareStepResult.model) != null ? _a22 : model);
3889
4157
  const stepModelInfo = {
3890
4158
  provider: stepModel.provider,
3891
4159
  modelId: stepModel.modelId
@@ -3935,7 +4203,7 @@ async function generateText({
3935
4203
  ]
3936
4204
  });
3937
4205
  currentModelResponse = await retry(() => {
3938
- var _a22;
4206
+ var _a23;
3939
4207
  return recordSpan({
3940
4208
  name: "ai.generateText.doGenerate",
3941
4209
  attributes: selectTelemetryAttributes({
@@ -3963,14 +4231,14 @@ async function generateText({
3963
4231
  "gen_ai.request.max_tokens": settings.maxOutputTokens,
3964
4232
  "gen_ai.request.presence_penalty": settings.presencePenalty,
3965
4233
  "gen_ai.request.stop_sequences": settings.stopSequences,
3966
- "gen_ai.request.temperature": (_a22 = settings.temperature) != null ? _a22 : undefined,
4234
+ "gen_ai.request.temperature": (_a23 = settings.temperature) != null ? _a23 : undefined,
3967
4235
  "gen_ai.request.top_k": settings.topK,
3968
4236
  "gen_ai.request.top_p": settings.topP
3969
4237
  }
3970
4238
  }),
3971
4239
  tracer,
3972
4240
  fn: async (span2) => {
3973
- var _a23, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
4241
+ var _a24, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
3974
4242
  const result = await stepModel.doGenerate({
3975
4243
  ...callSettings2,
3976
4244
  tools: stepTools,
@@ -3982,7 +4250,7 @@ async function generateText({
3982
4250
  headers: headersWithUserAgent
3983
4251
  });
3984
4252
  const responseData = {
3985
- id: (_b2 = (_a23 = result.response) == null ? undefined : _a23.id) != null ? _b2 : generateId2(),
4253
+ id: (_b2 = (_a24 = result.response) == null ? undefined : _a24.id) != null ? _b2 : generateId2(),
3986
4254
  timestamp: (_d2 = (_c2 = result.response) == null ? undefined : _c2.timestamp) != null ? _d2 : /* @__PURE__ */ new Date,
3987
4255
  modelId: (_f2 = (_e2 = result.response) == null ? undefined : _e2.modelId) != null ? _f2 : stepModel.modelId,
3988
4256
  headers: (_g2 = result.response) == null ? undefined : _g2.headers,
@@ -4063,10 +4331,19 @@ async function generateText({
4063
4331
  messages: stepInputMessages,
4064
4332
  experimental_context
4065
4333
  })) {
4334
+ const approvalId = generateId2();
4335
+ const signature = await maybeSignApproval({
4336
+ secret: experimental_toolApprovalSecret,
4337
+ approvalId,
4338
+ toolCallId: toolCall.toolCallId,
4339
+ toolName: toolCall.toolName,
4340
+ input: toolCall.input
4341
+ });
4066
4342
  toolApprovalRequests[toolCall.toolCallId] = {
4067
4343
  type: "tool-approval-request",
4068
- approvalId: generateId2(),
4069
- toolCall
4344
+ approvalId,
4345
+ toolCall,
4346
+ ...signature != null ? { signature } : {}
4070
4347
  };
4071
4348
  }
4072
4349
  }
@@ -4428,7 +4705,8 @@ function asContent({
4428
4705
  error: part.result,
4429
4706
  providerExecuted: true,
4430
4707
  dynamic: part.dynamic,
4431
- ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
4708
+ ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
4709
+ ...(tool2 == null ? undefined : tool2.metadata) != null ? { toolMetadata: tool2.metadata } : {}
4432
4710
  });
4433
4711
  } else {
4434
4712
  contentParts.push({
@@ -4439,7 +4717,8 @@ function asContent({
4439
4717
  output: part.result,
4440
4718
  providerExecuted: true,
4441
4719
  dynamic: part.dynamic,
4442
- ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
4720
+ ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
4721
+ ...(tool2 == null ? undefined : tool2.metadata) != null ? { toolMetadata: tool2.metadata } : {}
4443
4722
  });
4444
4723
  }
4445
4724
  break;
@@ -4453,7 +4732,8 @@ function asContent({
4453
4732
  error: part.result,
4454
4733
  providerExecuted: true,
4455
4734
  dynamic: toolCall.dynamic,
4456
- ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
4735
+ ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
4736
+ ...toolCall.toolMetadata != null ? { toolMetadata: toolCall.toolMetadata } : {}
4457
4737
  });
4458
4738
  } else {
4459
4739
  contentParts.push({
@@ -4464,7 +4744,8 @@ function asContent({
4464
4744
  output: part.result,
4465
4745
  providerExecuted: true,
4466
4746
  dynamic: toolCall.dynamic,
4467
- ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
4747
+ ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
4748
+ ...toolCall.toolMetadata != null ? { toolMetadata: toolCall.toolMetadata } : {}
4468
4749
  });
4469
4750
  }
4470
4751
  break;
@@ -4615,6 +4896,7 @@ function getResponseUIMessageId({
4615
4896
  const lastMessage = originalMessages[originalMessages.length - 1];
4616
4897
  return (lastMessage == null ? undefined : lastMessage.role) === "assistant" ? lastMessage.id : typeof responseMessageId === "function" ? responseMessageId() : responseMessageId;
4617
4898
  }
4899
+ var toolMetadataSchema = exports_external.record(exports_external.string(), jsonValueSchema.optional());
4618
4900
  var uiMessageChunkSchema = lazySchema(() => zodSchema(exports_external.union([
4619
4901
  exports_external.strictObject({
4620
4902
  type: exports_external.literal("text-start"),
@@ -4642,6 +4924,7 @@ var uiMessageChunkSchema = lazySchema(() => zodSchema(exports_external.union([
4642
4924
  toolName: exports_external.string(),
4643
4925
  providerExecuted: exports_external.boolean().optional(),
4644
4926
  providerMetadata: providerMetadataSchema.optional(),
4927
+ toolMetadata: toolMetadataSchema.optional(),
4645
4928
  dynamic: exports_external.boolean().optional(),
4646
4929
  title: exports_external.string().optional()
4647
4930
  }),
@@ -4657,6 +4940,7 @@ var uiMessageChunkSchema = lazySchema(() => zodSchema(exports_external.union([
4657
4940
  input: exports_external.unknown(),
4658
4941
  providerExecuted: exports_external.boolean().optional(),
4659
4942
  providerMetadata: providerMetadataSchema.optional(),
4943
+ toolMetadata: toolMetadataSchema.optional(),
4660
4944
  dynamic: exports_external.boolean().optional(),
4661
4945
  title: exports_external.string().optional()
4662
4946
  }),
@@ -4667,6 +4951,7 @@ var uiMessageChunkSchema = lazySchema(() => zodSchema(exports_external.union([
4667
4951
  input: exports_external.unknown(),
4668
4952
  providerExecuted: exports_external.boolean().optional(),
4669
4953
  providerMetadata: providerMetadataSchema.optional(),
4954
+ toolMetadata: toolMetadataSchema.optional(),
4670
4955
  dynamic: exports_external.boolean().optional(),
4671
4956
  errorText: exports_external.string(),
4672
4957
  title: exports_external.string().optional()
@@ -4674,7 +4959,8 @@ var uiMessageChunkSchema = lazySchema(() => zodSchema(exports_external.union([
4674
4959
  exports_external.strictObject({
4675
4960
  type: exports_external.literal("tool-approval-request"),
4676
4961
  approvalId: exports_external.string(),
4677
- toolCallId: exports_external.string()
4962
+ toolCallId: exports_external.string(),
4963
+ signature: exports_external.string().optional()
4678
4964
  }),
4679
4965
  exports_external.strictObject({
4680
4966
  type: exports_external.literal("tool-output-available"),
@@ -4682,6 +4968,7 @@ var uiMessageChunkSchema = lazySchema(() => zodSchema(exports_external.union([
4682
4968
  output: exports_external.unknown(),
4683
4969
  providerExecuted: exports_external.boolean().optional(),
4684
4970
  providerMetadata: providerMetadataSchema.optional(),
4971
+ toolMetadata: toolMetadataSchema.optional(),
4685
4972
  dynamic: exports_external.boolean().optional(),
4686
4973
  preliminary: exports_external.boolean().optional()
4687
4974
  }),
@@ -4691,6 +4978,7 @@ var uiMessageChunkSchema = lazySchema(() => zodSchema(exports_external.union([
4691
4978
  errorText: exports_external.string(),
4692
4979
  providerExecuted: exports_external.boolean().optional(),
4693
4980
  providerMetadata: providerMetadataSchema.optional(),
4981
+ toolMetadata: toolMetadataSchema.optional(),
4694
4982
  dynamic: exports_external.boolean().optional()
4695
4983
  }),
4696
4984
  exports_external.strictObject({
@@ -4775,6 +5063,9 @@ var uiMessageChunkSchema = lazySchema(() => zodSchema(exports_external.union([
4775
5063
  function isDataUIMessageChunk(chunk) {
4776
5064
  return chunk.type.startsWith("data-");
4777
5065
  }
5066
+ function createIdMap() {
5067
+ return /* @__PURE__ */ Object.create(null);
5068
+ }
4778
5069
  function isDataUIPart(part) {
4779
5070
  return part.type.startsWith("data-");
4780
5071
  }
@@ -4815,9 +5106,9 @@ function createStreamingUIMessageState({
4815
5106
  role: "assistant",
4816
5107
  parts: []
4817
5108
  },
4818
- activeTextParts: {},
4819
- activeReasoningParts: {},
4820
- partialToolCalls: {}
5109
+ activeTextParts: createIdMap(),
5110
+ activeReasoningParts: createIdMap(),
5111
+ partialToolCalls: createIdMap()
4821
5112
  };
4822
5113
  }
4823
5114
  function processUIMessageStream({
@@ -4832,7 +5123,7 @@ function processUIMessageStream({
4832
5123
  return stream.pipeThrough(new TransformStream({
4833
5124
  async transform(chunk, controller) {
4834
5125
  await runUpdateMessageJob(async ({ state, write }) => {
4835
- var _a21, _b, _c, _d;
5126
+ var _a22, _b, _c, _d;
4836
5127
  function getToolInvocation(toolCallId) {
4837
5128
  const toolInvocations = state.message.parts.filter(isToolUIPart);
4838
5129
  const toolInvocation = toolInvocations.find((invocation) => invocation.toolCallId === toolCallId);
@@ -4846,7 +5137,7 @@ function processUIMessageStream({
4846
5137
  return toolInvocation;
4847
5138
  }
4848
5139
  function updateToolPart(options) {
4849
- var _a22;
5140
+ var _a23;
4850
5141
  const part = state.message.parts.find((part2) => isStaticToolUIPart(part2) && part2.toolCallId === options.toolCallId);
4851
5142
  const anyOptions = options;
4852
5143
  const anyPart = part;
@@ -4860,7 +5151,10 @@ function processUIMessageStream({
4860
5151
  if (options.title !== undefined) {
4861
5152
  anyPart.title = options.title;
4862
5153
  }
4863
- anyPart.providerExecuted = (_a22 = anyOptions.providerExecuted) != null ? _a22 : part.providerExecuted;
5154
+ if (options.toolMetadata !== undefined) {
5155
+ anyPart.toolMetadata = options.toolMetadata;
5156
+ }
5157
+ anyPart.providerExecuted = (_a23 = anyOptions.providerExecuted) != null ? _a23 : part.providerExecuted;
4864
5158
  const providerMetadata = anyOptions.providerMetadata;
4865
5159
  if (providerMetadata != null) {
4866
5160
  if (options.state === "output-available" || options.state === "output-error") {
@@ -4876,6 +5170,7 @@ function processUIMessageStream({
4876
5170
  toolCallId: options.toolCallId,
4877
5171
  state: options.state,
4878
5172
  title: options.title,
5173
+ ...options.toolMetadata !== undefined ? { toolMetadata: options.toolMetadata } : {},
4879
5174
  input: anyOptions.input,
4880
5175
  output: anyOptions.output,
4881
5176
  rawInput: anyOptions.rawInput,
@@ -4888,7 +5183,7 @@ function processUIMessageStream({
4888
5183
  }
4889
5184
  }
4890
5185
  function updateDynamicToolPart(options) {
4891
- var _a22, _b2;
5186
+ var _a23, _b2;
4892
5187
  const part = state.message.parts.find((part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId);
4893
5188
  const anyOptions = options;
4894
5189
  const anyPart = part;
@@ -4898,11 +5193,14 @@ function processUIMessageStream({
4898
5193
  anyPart.input = anyOptions.input;
4899
5194
  anyPart.output = anyOptions.output;
4900
5195
  anyPart.errorText = anyOptions.errorText;
4901
- anyPart.rawInput = (_a22 = anyOptions.rawInput) != null ? _a22 : anyPart.rawInput;
5196
+ anyPart.rawInput = (_a23 = anyOptions.rawInput) != null ? _a23 : anyPart.rawInput;
4902
5197
  anyPart.preliminary = anyOptions.preliminary;
4903
5198
  if (options.title !== undefined) {
4904
5199
  anyPart.title = options.title;
4905
5200
  }
5201
+ if (options.toolMetadata !== undefined) {
5202
+ anyPart.toolMetadata = options.toolMetadata;
5203
+ }
4906
5204
  anyPart.providerExecuted = (_b2 = anyOptions.providerExecuted) != null ? _b2 : part.providerExecuted;
4907
5205
  const providerMetadata = anyOptions.providerMetadata;
4908
5206
  if (providerMetadata != null) {
@@ -4925,6 +5223,7 @@ function processUIMessageStream({
4925
5223
  preliminary: anyOptions.preliminary,
4926
5224
  providerExecuted: anyOptions.providerExecuted,
4927
5225
  title: options.title,
5226
+ ...options.toolMetadata !== undefined ? { toolMetadata: options.toolMetadata } : {},
4928
5227
  ...anyOptions.providerMetadata != null && (options.state === "output-available" || options.state === "output-error") ? { resultProviderMetadata: anyOptions.providerMetadata } : {},
4929
5228
  ...anyOptions.providerMetadata != null && !(options.state === "output-available" || options.state === "output-error") ? { callProviderMetadata: anyOptions.providerMetadata } : {}
4930
5229
  });
@@ -4969,7 +5268,7 @@ function processUIMessageStream({
4969
5268
  });
4970
5269
  }
4971
5270
  textPart.text += chunk.delta;
4972
- textPart.providerMetadata = (_a21 = chunk.providerMetadata) != null ? _a21 : textPart.providerMetadata;
5271
+ textPart.providerMetadata = (_a22 = chunk.providerMetadata) != null ? _a22 : textPart.providerMetadata;
4973
5272
  write();
4974
5273
  break;
4975
5274
  }
@@ -5069,7 +5368,8 @@ function processUIMessageStream({
5069
5368
  toolName: chunk.toolName,
5070
5369
  index: toolInvocations.length,
5071
5370
  dynamic: chunk.dynamic,
5072
- title: chunk.title
5371
+ title: chunk.title,
5372
+ toolMetadata: chunk.toolMetadata
5073
5373
  };
5074
5374
  if (chunk.dynamic) {
5075
5375
  updateDynamicToolPart({
@@ -5079,6 +5379,7 @@ function processUIMessageStream({
5079
5379
  input: undefined,
5080
5380
  providerExecuted: chunk.providerExecuted,
5081
5381
  title: chunk.title,
5382
+ toolMetadata: chunk.toolMetadata,
5082
5383
  providerMetadata: chunk.providerMetadata
5083
5384
  });
5084
5385
  } else {
@@ -5089,6 +5390,7 @@ function processUIMessageStream({
5089
5390
  input: undefined,
5090
5391
  providerExecuted: chunk.providerExecuted,
5091
5392
  title: chunk.title,
5393
+ toolMetadata: chunk.toolMetadata,
5092
5394
  providerMetadata: chunk.providerMetadata
5093
5395
  });
5094
5396
  }
@@ -5112,7 +5414,8 @@ function processUIMessageStream({
5112
5414
  toolName: partialToolCall.toolName,
5113
5415
  state: "input-streaming",
5114
5416
  input: partialArgs,
5115
- title: partialToolCall.title
5417
+ title: partialToolCall.title,
5418
+ toolMetadata: partialToolCall.toolMetadata
5116
5419
  });
5117
5420
  } else {
5118
5421
  updateToolPart({
@@ -5120,7 +5423,8 @@ function processUIMessageStream({
5120
5423
  toolName: partialToolCall.toolName,
5121
5424
  state: "input-streaming",
5122
5425
  input: partialArgs,
5123
- title: partialToolCall.title
5426
+ title: partialToolCall.title,
5427
+ toolMetadata: partialToolCall.toolMetadata
5124
5428
  });
5125
5429
  }
5126
5430
  write();
@@ -5135,7 +5439,8 @@ function processUIMessageStream({
5135
5439
  input: chunk.input,
5136
5440
  providerExecuted: chunk.providerExecuted,
5137
5441
  providerMetadata: chunk.providerMetadata,
5138
- title: chunk.title
5442
+ title: chunk.title,
5443
+ toolMetadata: chunk.toolMetadata
5139
5444
  });
5140
5445
  } else {
5141
5446
  updateToolPart({
@@ -5145,7 +5450,8 @@ function processUIMessageStream({
5145
5450
  input: chunk.input,
5146
5451
  providerExecuted: chunk.providerExecuted,
5147
5452
  providerMetadata: chunk.providerMetadata,
5148
- title: chunk.title
5453
+ title: chunk.title,
5454
+ toolMetadata: chunk.toolMetadata
5149
5455
  });
5150
5456
  }
5151
5457
  write();
@@ -5167,7 +5473,8 @@ function processUIMessageStream({
5167
5473
  input: chunk.input,
5168
5474
  errorText: chunk.errorText,
5169
5475
  providerExecuted: chunk.providerExecuted,
5170
- providerMetadata: chunk.providerMetadata
5476
+ providerMetadata: chunk.providerMetadata,
5477
+ toolMetadata: chunk.toolMetadata
5171
5478
  });
5172
5479
  } else {
5173
5480
  updateToolPart({
@@ -5178,7 +5485,8 @@ function processUIMessageStream({
5178
5485
  rawInput: chunk.input,
5179
5486
  errorText: chunk.errorText,
5180
5487
  providerExecuted: chunk.providerExecuted,
5181
- providerMetadata: chunk.providerMetadata
5488
+ providerMetadata: chunk.providerMetadata,
5489
+ toolMetadata: chunk.toolMetadata
5182
5490
  });
5183
5491
  }
5184
5492
  write();
@@ -5187,7 +5495,10 @@ function processUIMessageStream({
5187
5495
  case "tool-approval-request": {
5188
5496
  const toolInvocation = getToolInvocation(chunk.toolCallId);
5189
5497
  toolInvocation.state = "approval-requested";
5190
- toolInvocation.approval = { id: chunk.approvalId };
5498
+ toolInvocation.approval = {
5499
+ id: chunk.approvalId,
5500
+ ...chunk.signature != null ? { signature: chunk.signature } : {}
5501
+ };
5191
5502
  write();
5192
5503
  break;
5193
5504
  }
@@ -5209,7 +5520,8 @@ function processUIMessageStream({
5209
5520
  preliminary: chunk.preliminary,
5210
5521
  providerExecuted: chunk.providerExecuted,
5211
5522
  providerMetadata: chunk.providerMetadata,
5212
- title: toolInvocation.title
5523
+ title: toolInvocation.title,
5524
+ toolMetadata: toolInvocation.toolMetadata
5213
5525
  });
5214
5526
  } else {
5215
5527
  updateToolPart({
@@ -5221,7 +5533,8 @@ function processUIMessageStream({
5221
5533
  providerExecuted: chunk.providerExecuted,
5222
5534
  preliminary: chunk.preliminary,
5223
5535
  providerMetadata: chunk.providerMetadata,
5224
- title: toolInvocation.title
5536
+ title: toolInvocation.title,
5537
+ toolMetadata: toolInvocation.toolMetadata
5225
5538
  });
5226
5539
  }
5227
5540
  write();
@@ -5238,7 +5551,8 @@ function processUIMessageStream({
5238
5551
  errorText: chunk.errorText,
5239
5552
  providerExecuted: chunk.providerExecuted,
5240
5553
  providerMetadata: chunk.providerMetadata,
5241
- title: toolInvocation.title
5554
+ title: toolInvocation.title,
5555
+ toolMetadata: toolInvocation.toolMetadata
5242
5556
  });
5243
5557
  } else {
5244
5558
  updateToolPart({
@@ -5250,7 +5564,8 @@ function processUIMessageStream({
5250
5564
  errorText: chunk.errorText,
5251
5565
  providerExecuted: chunk.providerExecuted,
5252
5566
  providerMetadata: chunk.providerMetadata,
5253
- title: toolInvocation.title
5567
+ title: toolInvocation.title,
5568
+ toolMetadata: toolInvocation.toolMetadata
5254
5569
  });
5255
5570
  }
5256
5571
  write();
@@ -5261,8 +5576,8 @@ function processUIMessageStream({
5261
5576
  break;
5262
5577
  }
5263
5578
  case "finish-step": {
5264
- state.activeTextParts = {};
5265
- state.activeReasoningParts = {};
5579
+ state.activeTextParts = createIdMap();
5580
+ state.activeReasoningParts = createIdMap();
5266
5581
  break;
5267
5582
  }
5268
5583
  case "start": {
@@ -5454,13 +5769,13 @@ function createAsyncIterableStream(source) {
5454
5769
  const reader = this.getReader();
5455
5770
  let finished = false;
5456
5771
  async function cleanup(cancelStream) {
5457
- var _a21;
5772
+ var _a22;
5458
5773
  if (finished)
5459
5774
  return;
5460
5775
  finished = true;
5461
5776
  try {
5462
5777
  if (cancelStream) {
5463
- await ((_a21 = reader.cancel) == null ? undefined : _a21.call(reader));
5778
+ await ((_a22 = reader.cancel) == null ? undefined : _a22.call(reader));
5464
5779
  }
5465
5780
  } finally {
5466
5781
  try {
@@ -5603,6 +5918,7 @@ function runToolsTransformation({
5603
5918
  abortSignal,
5604
5919
  repairToolCall,
5605
5920
  experimental_context,
5921
+ toolApprovalSecret,
5606
5922
  generateId: generateId2,
5607
5923
  stepNumber,
5608
5924
  model,
@@ -5708,7 +6024,8 @@ function runToolsTransformation({
5708
6024
  input: toolCall.input,
5709
6025
  error: getErrorMessage2(toolCall.error),
5710
6026
  dynamic: true,
5711
- title: toolCall.title
6027
+ title: toolCall.title,
6028
+ ...toolCall.toolMetadata != null ? { toolMetadata: toolCall.toolMetadata } : {}
5712
6029
  });
5713
6030
  break;
5714
6031
  }
@@ -5731,10 +6048,19 @@ function runToolsTransformation({
5731
6048
  messages,
5732
6049
  experimental_context
5733
6050
  })) {
6051
+ const approvalId = generateId2();
6052
+ const signature = await maybeSignApproval({
6053
+ secret: toolApprovalSecret,
6054
+ approvalId,
6055
+ toolCallId: toolCall.toolCallId,
6056
+ toolName: toolCall.toolName,
6057
+ input: toolCall.input
6058
+ });
5734
6059
  toolResultsStreamController.enqueue({
5735
6060
  type: "tool-approval-request",
5736
- approvalId: generateId2(),
5737
- toolCall
6061
+ approvalId,
6062
+ toolCall,
6063
+ ...signature != null ? { signature } : {}
5738
6064
  });
5739
6065
  break;
5740
6066
  }
@@ -5776,6 +6102,7 @@ function runToolsTransformation({
5776
6102
  }
5777
6103
  case "tool-result": {
5778
6104
  const toolName = chunk.toolName;
6105
+ const toolCall = toolCallsByToolCallId.get(chunk.toolCallId);
5779
6106
  if (chunk.isError) {
5780
6107
  toolResultsStreamController.enqueue({
5781
6108
  type: "tool-error",
@@ -5785,7 +6112,8 @@ function runToolsTransformation({
5785
6112
  providerExecuted: true,
5786
6113
  error: chunk.result,
5787
6114
  dynamic: chunk.dynamic,
5788
- ...chunk.providerMetadata != null ? { providerMetadata: chunk.providerMetadata } : {}
6115
+ ...chunk.providerMetadata != null ? { providerMetadata: chunk.providerMetadata } : {},
6116
+ ...(toolCall == null ? undefined : toolCall.toolMetadata) != null ? { toolMetadata: toolCall.toolMetadata } : {}
5789
6117
  });
5790
6118
  } else {
5791
6119
  controller.enqueue({
@@ -5796,7 +6124,8 @@ function runToolsTransformation({
5796
6124
  output: chunk.result,
5797
6125
  providerExecuted: true,
5798
6126
  dynamic: chunk.dynamic,
5799
- ...chunk.providerMetadata != null ? { providerMetadata: chunk.providerMetadata } : {}
6127
+ ...chunk.providerMetadata != null ? { providerMetadata: chunk.providerMetadata } : {},
6128
+ ...(toolCall == null ? undefined : toolCall.toolMetadata) != null ? { toolMetadata: toolCall.toolMetadata } : {}
5800
6129
  });
5801
6130
  }
5802
6131
  break;
@@ -5837,6 +6166,28 @@ var originalGenerateId2 = createIdGenerator({
5837
6166
  prefix: "aitxt",
5838
6167
  size: 24
5839
6168
  });
6169
+ var isOutputChunkType = {
6170
+ file: true,
6171
+ source: true,
6172
+ "text-start": true,
6173
+ "text-end": true,
6174
+ "text-delta": true,
6175
+ "reasoning-start": true,
6176
+ "reasoning-end": true,
6177
+ "reasoning-delta": true,
6178
+ "tool-input-start": true,
6179
+ "tool-input-end": true,
6180
+ "tool-input-delta": true,
6181
+ "tool-approval-request": true,
6182
+ "tool-call": true,
6183
+ "tool-result": true,
6184
+ "tool-error": true,
6185
+ "stream-start": false,
6186
+ "response-metadata": false,
6187
+ finish: false,
6188
+ error: false,
6189
+ raw: false
6190
+ };
5840
6191
  function streamText({
5841
6192
  model,
5842
6193
  tools,
@@ -5873,6 +6224,7 @@ function streamText({
5873
6224
  experimental_onToolCallStart: onToolCallStart,
5874
6225
  experimental_onToolCallFinish: onToolCallFinish,
5875
6226
  experimental_context,
6227
+ experimental_toolApprovalSecret,
5876
6228
  experimental_include: include,
5877
6229
  _internal: { now: now2 = now, generateId: generateId2 = originalGenerateId2 } = {},
5878
6230
  ...settings
@@ -5922,6 +6274,7 @@ function streamText({
5922
6274
  now: now2,
5923
6275
  generateId: generateId2,
5924
6276
  experimental_context,
6277
+ experimental_toolApprovalSecret,
5925
6278
  download: download2,
5926
6279
  include
5927
6280
  });
@@ -5949,7 +6302,7 @@ function createOutputTransformStream(output) {
5949
6302
  }
5950
6303
  return new TransformStream({
5951
6304
  async transform(chunk, controller) {
5952
- var _a21;
6305
+ var _a22;
5953
6306
  if (chunk.type === "finish-step" && textChunk.length > 0) {
5954
6307
  publishTextChunk({ controller });
5955
6308
  }
@@ -5976,7 +6329,7 @@ function createOutputTransformStream(output) {
5976
6329
  }
5977
6330
  text2 += chunk.text;
5978
6331
  textChunk += chunk.text;
5979
- textProviderMetadata = (_a21 = chunk.providerMetadata) != null ? _a21 : textProviderMetadata;
6332
+ textProviderMetadata = (_a22 = chunk.providerMetadata) != null ? _a22 : textProviderMetadata;
5980
6333
  const result = await output.parsePartialOutput({ text: text2 });
5981
6334
  if (result !== undefined) {
5982
6335
  const currentValue = typeof result.partial === "string" ? result.partial : JSON.stringify(result.partial);
@@ -6029,6 +6382,7 @@ var DefaultStreamTextResult = class {
6029
6382
  onToolCallStart,
6030
6383
  onToolCallFinish,
6031
6384
  experimental_context,
6385
+ experimental_toolApprovalSecret,
6032
6386
  download: download2,
6033
6387
  include
6034
6388
  }) {
@@ -6050,20 +6404,25 @@ var DefaultStreamTextResult = class {
6050
6404
  let recordedRequest = {};
6051
6405
  let recordedWarnings = [];
6052
6406
  const recordedSteps = [];
6407
+ let recordedNoOutputError;
6053
6408
  const pendingDeferredToolCalls = /* @__PURE__ */ new Map;
6054
6409
  let rootSpan;
6055
- let activeTextContent = {};
6056
- let activeReasoningContent = {};
6410
+ let activeTextContent = createIdMap();
6411
+ let activeReasoningContent = createIdMap();
6057
6412
  const eventProcessor = new TransformStream({
6058
6413
  async transform(chunk, controller) {
6059
- var _a21, _b, _c, _d;
6414
+ var _a22, _b, _c, _d;
6060
6415
  controller.enqueue(chunk);
6061
6416
  const { part } = chunk;
6062
6417
  if (part.type === "text-delta" || part.type === "reasoning-delta" || part.type === "source" || part.type === "tool-call" || part.type === "tool-result" || part.type === "tool-input-start" || part.type === "tool-input-delta" || part.type === "raw") {
6063
6418
  await (onChunk == null ? undefined : onChunk({ chunk: part }));
6064
6419
  }
6065
6420
  if (part.type === "error") {
6066
- await onError({ error: wrapGatewayError(part.error) });
6421
+ const error = wrapGatewayError(part.error);
6422
+ if (NoOutputGeneratedError.isInstance(error)) {
6423
+ recordedNoOutputError = error;
6424
+ }
6425
+ await onError({ error });
6067
6426
  }
6068
6427
  if (part.type === "text-start") {
6069
6428
  activeTextContent[part.id] = {
@@ -6086,7 +6445,7 @@ var DefaultStreamTextResult = class {
6086
6445
  return;
6087
6446
  }
6088
6447
  activeText.text += part.text;
6089
- activeText.providerMetadata = (_a21 = part.providerMetadata) != null ? _a21 : activeText.providerMetadata;
6448
+ activeText.providerMetadata = (_a22 = part.providerMetadata) != null ? _a22 : activeText.providerMetadata;
6090
6449
  }
6091
6450
  if (part.type === "text-end") {
6092
6451
  const activeText = activeTextContent[part.id];
@@ -6165,8 +6524,8 @@ var DefaultStreamTextResult = class {
6165
6524
  }
6166
6525
  if (part.type === "start-step") {
6167
6526
  recordedContent = [];
6168
- activeReasoningContent = {};
6169
- activeTextContent = {};
6527
+ activeReasoningContent = createIdMap();
6528
+ activeTextContent = createIdMap();
6170
6529
  recordedRequest = part.request;
6171
6530
  recordedWarnings = part.warnings;
6172
6531
  }
@@ -6212,10 +6571,10 @@ var DefaultStreamTextResult = class {
6212
6571
  }
6213
6572
  },
6214
6573
  async flush(controller) {
6215
- var _a21, _b, _c, _d, _e, _f, _g;
6574
+ var _a22, _b, _c, _d, _e, _f, _g;
6216
6575
  try {
6217
- if (recordedSteps.length === 0) {
6218
- const error = (abortSignal == null ? undefined : abortSignal.aborted) ? abortSignal.reason : new NoOutputGeneratedError({
6576
+ if (recordedSteps.length === 0 || recordedNoOutputError != null) {
6577
+ const error = (abortSignal == null ? undefined : abortSignal.aborted) ? abortSignal.reason : recordedNoOutputError != null ? recordedNoOutputError : new NoOutputGeneratedError({
6219
6578
  message: "No output generated. Check the stream for errors."
6220
6579
  });
6221
6580
  self._finishReason.reject(error);
@@ -6275,13 +6634,13 @@ var DefaultStreamTextResult = class {
6275
6634
  },
6276
6635
  "ai.response.toolCalls": {
6277
6636
  output: () => {
6278
- var _a22;
6279
- return ((_a22 = finalStep.toolCalls) == null ? undefined : _a22.length) ? JSON.stringify(finalStep.toolCalls) : undefined;
6637
+ var _a23;
6638
+ return ((_a23 = finalStep.toolCalls) == null ? undefined : _a23.length) ? JSON.stringify(finalStep.toolCalls) : undefined;
6280
6639
  }
6281
6640
  },
6282
6641
  "ai.response.providerMetadata": JSON.stringify(finalStep.providerMetadata),
6283
6642
  "ai.usage.inputTokens": totalUsage.inputTokens,
6284
- "ai.usage.inputTokenDetails.noCacheTokens": (_a21 = totalUsage.inputTokenDetails) == null ? undefined : _a21.noCacheTokens,
6643
+ "ai.usage.inputTokenDetails.noCacheTokens": (_a22 = totalUsage.inputTokenDetails) == null ? undefined : _a22.noCacheTokens,
6285
6644
  "ai.usage.inputTokenDetails.cacheReadTokens": (_b = totalUsage.inputTokenDetails) == null ? undefined : _b.cacheReadTokens,
6286
6645
  "ai.usage.inputTokenDetails.cacheWriteTokens": (_c = totalUsage.inputTokenDetails) == null ? undefined : _c.cacheWriteTokens,
6287
6646
  "ai.usage.outputTokens": totalUsage.outputTokens,
@@ -6425,8 +6784,20 @@ var DefaultStreamTextResult = class {
6425
6784
  const initialResponseMessages = [];
6426
6785
  const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({ messages: initialMessages });
6427
6786
  if (deniedToolApprovals.length > 0 || approvedToolApprovals.length > 0) {
6428
- const localApprovedToolApprovals = approvedToolApprovals.filter((toolApproval) => !toolApproval.toolCall.providerExecuted);
6429
- const localDeniedToolApprovals = deniedToolApprovals.filter((toolApproval) => !toolApproval.toolCall.providerExecuted);
6787
+ const {
6788
+ approvedToolApprovals: localApprovedToolApprovals,
6789
+ deniedToolApprovals: revalidationDeniedToolApprovals
6790
+ } = await validateApprovedToolApprovals({
6791
+ approvedToolApprovals: approvedToolApprovals.filter((toolApproval) => !toolApproval.toolCall.providerExecuted),
6792
+ tools,
6793
+ messages: initialMessages,
6794
+ experimental_context,
6795
+ toolApprovalSecret: experimental_toolApprovalSecret
6796
+ });
6797
+ const localDeniedToolApprovals = [
6798
+ ...deniedToolApprovals.filter((toolApproval) => !toolApproval.toolCall.providerExecuted),
6799
+ ...revalidationDeniedToolApprovals
6800
+ ];
6430
6801
  const deniedProviderExecutedToolApprovals = deniedToolApprovals.filter((toolApproval) => toolApproval.toolCall.providerExecuted);
6431
6802
  let toolExecutionStepStreamController;
6432
6803
  const toolExecutionStepStream = new ReadableStream({
@@ -6517,7 +6888,7 @@ var DefaultStreamTextResult = class {
6517
6888
  responseMessages,
6518
6889
  usage
6519
6890
  }) {
6520
- var _a21, _b, _c, _d, _e, _f, _g, _h, _i;
6891
+ var _a22, _b, _c, _d, _e, _f, _g, _h, _i;
6521
6892
  const includeRawChunks2 = self.includeRawChunks;
6522
6893
  const stepTimeoutId = stepTimeoutMs != null ? setTimeout(() => stepAbortController.abort(), stepTimeoutMs) : undefined;
6523
6894
  let chunkTimeoutId = undefined;
@@ -6550,7 +6921,7 @@ var DefaultStreamTextResult = class {
6550
6921
  messages: stepInputMessages,
6551
6922
  experimental_context
6552
6923
  }));
6553
- const stepModel = resolveLanguageModel((_a21 = prepareStepResult == null ? undefined : prepareStepResult.model) != null ? _a21 : model);
6924
+ const stepModel = resolveLanguageModel((_a22 = prepareStepResult == null ? undefined : prepareStepResult.model) != null ? _a22 : model);
6554
6925
  const stepModelInfo = {
6555
6926
  provider: stepModel.provider,
6556
6927
  modelId: stepModel.modelId
@@ -6662,6 +7033,7 @@ var DefaultStreamTextResult = class {
6662
7033
  repairToolCall,
6663
7034
  abortSignal,
6664
7035
  experimental_context,
7036
+ toolApprovalSecret: experimental_toolApprovalSecret,
6665
7037
  generateId: generateId2,
6666
7038
  stepNumber: recordedSteps.length,
6667
7039
  model: stepModelInfo,
@@ -6681,6 +7053,8 @@ var DefaultStreamTextResult = class {
6681
7053
  const activeToolCallToolNames = {};
6682
7054
  let stepFinishReason = "other";
6683
7055
  let stepRawFinishReason = undefined;
7056
+ let hasReceivedTerminalChunk = false;
7057
+ let hasReceivedOutputChunk = false;
6684
7058
  let stepUsage = createNullLanguageModelUsage();
6685
7059
  let stepProviderMetadata;
6686
7060
  let stepFirstChunk = true;
@@ -6692,7 +7066,7 @@ var DefaultStreamTextResult = class {
6692
7066
  let activeText = "";
6693
7067
  self.addStream(streamWithToolResults.pipeThrough(new TransformStream({
6694
7068
  async transform(chunk, controller) {
6695
- var _a22, _b2, _c2, _d2, _e2;
7069
+ var _a23, _b2, _c2, _d2, _e2;
6696
7070
  resetChunkTimeout();
6697
7071
  if (chunk.type === "stream-start") {
6698
7072
  warnings = chunk.warnings;
@@ -6714,6 +7088,9 @@ var DefaultStreamTextResult = class {
6714
7088
  });
6715
7089
  }
6716
7090
  const chunkType = chunk.type;
7091
+ if (isOutputChunkType[chunkType]) {
7092
+ hasReceivedOutputChunk = true;
7093
+ }
6717
7094
  switch (chunkType) {
6718
7095
  case "tool-approval-request":
6719
7096
  case "text-start":
@@ -6766,13 +7143,14 @@ var DefaultStreamTextResult = class {
6766
7143
  }
6767
7144
  case "response-metadata": {
6768
7145
  stepResponse = {
6769
- id: (_a22 = chunk.id) != null ? _a22 : stepResponse.id,
7146
+ id: (_a23 = chunk.id) != null ? _a23 : stepResponse.id,
6770
7147
  timestamp: (_b2 = chunk.timestamp) != null ? _b2 : stepResponse.timestamp,
6771
7148
  modelId: (_c2 = chunk.modelId) != null ? _c2 : stepResponse.modelId
6772
7149
  };
6773
7150
  break;
6774
7151
  }
6775
7152
  case "finish": {
7153
+ hasReceivedTerminalChunk = true;
6776
7154
  stepUsage = chunk.usage;
6777
7155
  stepFinishReason = chunk.finishReason;
6778
7156
  stepRawFinishReason = chunk.rawFinishReason;
@@ -6832,6 +7210,7 @@ var DefaultStreamTextResult = class {
6832
7210
  break;
6833
7211
  }
6834
7212
  case "error": {
7213
+ hasReceivedTerminalChunk = true;
6835
7214
  controller.enqueue(chunk);
6836
7215
  stepFinishReason = "error";
6837
7216
  break;
@@ -6849,7 +7228,20 @@ var DefaultStreamTextResult = class {
6849
7228
  }
6850
7229
  },
6851
7230
  async flush(controller) {
6852
- var _a22, _b2, _c2, _d2, _e2, _f2, _g2;
7231
+ var _a23, _b2, _c2, _d2, _e2, _f2, _g2;
7232
+ if (!hasReceivedTerminalChunk && !hasReceivedOutputChunk) {
7233
+ controller.enqueue({
7234
+ type: "error",
7235
+ error: new NoOutputGeneratedError({
7236
+ message: "No output generated. The model stream ended without a finish chunk."
7237
+ })
7238
+ });
7239
+ doStreamSpan.end();
7240
+ clearStepTimeout();
7241
+ clearChunkTimeout();
7242
+ self.closeStream();
7243
+ return;
7244
+ }
6853
7245
  const stepToolCallsJson = stepToolCalls.length > 0 ? JSON.stringify(stepToolCalls) : undefined;
6854
7246
  try {
6855
7247
  doStreamSpan.setAttributes(await selectTelemetryAttributes({
@@ -6863,7 +7255,7 @@ var DefaultStreamTextResult = class {
6863
7255
  "ai.response.model": stepResponse.modelId,
6864
7256
  "ai.response.timestamp": stepResponse.timestamp.toISOString(),
6865
7257
  "ai.usage.inputTokens": stepUsage.inputTokens,
6866
- "ai.usage.inputTokenDetails.noCacheTokens": (_a22 = stepUsage.inputTokenDetails) == null ? undefined : _a22.noCacheTokens,
7258
+ "ai.usage.inputTokenDetails.noCacheTokens": (_a23 = stepUsage.inputTokenDetails) == null ? undefined : _a23.noCacheTokens,
6867
7259
  "ai.usage.inputTokenDetails.cacheReadTokens": (_b2 = stepUsage.inputTokenDetails) == null ? undefined : _b2.cacheReadTokens,
6868
7260
  "ai.usage.inputTokenDetails.cacheWriteTokens": (_c2 = stepUsage.inputTokenDetails) == null ? undefined : _c2.cacheWriteTokens,
6869
7261
  "ai.usage.outputTokens": stepUsage.outputTokens,
@@ -7078,15 +7470,30 @@ var DefaultStreamTextResult = class {
7078
7470
  }
7079
7471
  })));
7080
7472
  }
7473
+ rejectResultPromises(error) {
7474
+ if (this._finishReason.isPending())
7475
+ this._finishReason.reject(error);
7476
+ if (this._rawFinishReason.isPending())
7477
+ this._rawFinishReason.reject(error);
7478
+ if (this._totalUsage.isPending())
7479
+ this._totalUsage.reject(error);
7480
+ if (this._steps.isPending())
7481
+ this._steps.reject(error);
7482
+ }
7081
7483
  async consumeStream(options) {
7082
- var _a21;
7484
+ var _a22;
7083
7485
  try {
7084
7486
  await consumeStream({
7085
7487
  stream: this.fullStream,
7086
- onError: options == null ? undefined : options.onError
7488
+ onError: (error) => {
7489
+ var _a23;
7490
+ this.rejectResultPromises(error);
7491
+ (_a23 = options == null ? undefined : options.onError) == null || _a23.call(options, error);
7492
+ }
7087
7493
  });
7088
7494
  } catch (error) {
7089
- (_a21 = options == null ? undefined : options.onError) == null || _a21.call(options, error);
7495
+ this.rejectResultPromises(error);
7496
+ (_a22 = options == null ? undefined : options.onError) == null || _a22.call(options, error);
7090
7497
  }
7091
7498
  }
7092
7499
  get experimental_partialOutputStream() {
@@ -7102,8 +7509,8 @@ var DefaultStreamTextResult = class {
7102
7509
  })));
7103
7510
  }
7104
7511
  get elementStream() {
7105
- var _a21, _b, _c;
7106
- const transform = (_a21 = this.outputSpecification) == null ? undefined : _a21.createElementStreamTransform();
7512
+ var _a22, _b, _c;
7513
+ const transform = (_a22 = this.outputSpecification) == null ? undefined : _a22.createElementStreamTransform();
7107
7514
  if (transform == null) {
7108
7515
  throw new UnsupportedFunctionalityError({
7109
7516
  functionality: `element streams in ${(_c = (_b = this.outputSpecification) == null ? undefined : _b.name) != null ? _c : "text"} mode`
@@ -7113,8 +7520,8 @@ var DefaultStreamTextResult = class {
7113
7520
  }
7114
7521
  get output() {
7115
7522
  return this.finalStep.then((step) => {
7116
- var _a21;
7117
- const output = (_a21 = this.outputSpecification) != null ? _a21 : text();
7523
+ var _a22;
7524
+ const output = (_a22 = this.outputSpecification) != null ? _a22 : text();
7118
7525
  return output.parseCompleteOutput({ text: step.text }, {
7119
7526
  response: step.response,
7120
7527
  usage: step.usage,
@@ -7131,15 +7538,15 @@ var DefaultStreamTextResult = class {
7131
7538
  sendSources = false,
7132
7539
  sendStart = true,
7133
7540
  sendFinish = true,
7134
- onError = getErrorMessage
7541
+ onError = () => "An error occurred."
7135
7542
  } = {}) {
7136
7543
  const responseMessageId = generateMessageId != null ? getResponseUIMessageId({
7137
7544
  originalMessages,
7138
7545
  responseMessageId: generateMessageId
7139
7546
  }) : undefined;
7140
7547
  const isDynamic = (part) => {
7141
- var _a21;
7142
- const tool2 = (_a21 = this.tools) == null ? undefined : _a21[part.toolName];
7548
+ var _a22;
7549
+ const tool2 = (_a22 = this.tools) == null ? undefined : _a22[part.toolName];
7143
7550
  if (tool2 == null) {
7144
7551
  return part.dynamic;
7145
7552
  }
@@ -7236,6 +7643,7 @@ var DefaultStreamTextResult = class {
7236
7643
  toolName: part.toolName,
7237
7644
  ...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
7238
7645
  ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
7646
+ ...part.toolMetadata != null ? { toolMetadata: part.toolMetadata } : {},
7239
7647
  ...dynamic != null ? { dynamic } : {},
7240
7648
  ...part.title != null ? { title: part.title } : {}
7241
7649
  });
@@ -7259,6 +7667,7 @@ var DefaultStreamTextResult = class {
7259
7667
  input: part.input,
7260
7668
  ...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
7261
7669
  ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
7670
+ ...part.toolMetadata != null ? { toolMetadata: part.toolMetadata } : {},
7262
7671
  ...dynamic != null ? { dynamic } : {},
7263
7672
  errorText: onError(part.error),
7264
7673
  ...part.title != null ? { title: part.title } : {}
@@ -7271,6 +7680,7 @@ var DefaultStreamTextResult = class {
7271
7680
  input: part.input,
7272
7681
  ...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
7273
7682
  ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
7683
+ ...part.toolMetadata != null ? { toolMetadata: part.toolMetadata } : {},
7274
7684
  ...dynamic != null ? { dynamic } : {},
7275
7685
  ...part.title != null ? { title: part.title } : {}
7276
7686
  });
@@ -7281,7 +7691,8 @@ var DefaultStreamTextResult = class {
7281
7691
  controller.enqueue({
7282
7692
  type: "tool-approval-request",
7283
7693
  approvalId: part.approvalId,
7284
- toolCallId: part.toolCall.toolCallId
7694
+ toolCallId: part.toolCall.toolCallId,
7695
+ ...part.signature != null ? { signature: part.signature } : {}
7285
7696
  });
7286
7697
  break;
7287
7698
  }
@@ -7290,9 +7701,10 @@ var DefaultStreamTextResult = class {
7290
7701
  controller.enqueue({
7291
7702
  type: "tool-output-available",
7292
7703
  toolCallId: part.toolCallId,
7293
- output: part.output,
7704
+ output: part.output === undefined ? null : part.output,
7294
7705
  ...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
7295
7706
  ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
7707
+ ...part.toolMetadata != null ? { toolMetadata: part.toolMetadata } : {},
7296
7708
  ...part.preliminary != null ? { preliminary: part.preliminary } : {},
7297
7709
  ...dynamic != null ? { dynamic } : {}
7298
7710
  });
@@ -7306,6 +7718,7 @@ var DefaultStreamTextResult = class {
7306
7718
  errorText: part.providerExecuted ? typeof part.error === "string" ? part.error : JSON.stringify(part.error) : onError(part.error),
7307
7719
  ...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
7308
7720
  ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
7721
+ ...part.toolMetadata != null ? { toolMetadata: part.toolMetadata } : {},
7309
7722
  ...dynamic != null ? { dynamic } : {}
7310
7723
  });
7311
7724
  break;
@@ -7464,7 +7877,7 @@ var ToolLoopAgent = class {
7464
7877
  return this.settings.tools;
7465
7878
  }
7466
7879
  async prepareCall(options) {
7467
- var _a21, _b, _c, _d;
7880
+ var _a22, _b, _c, _d;
7468
7881
  if (this.settings.callOptionsSchema != null && options.options !== undefined) {
7469
7882
  const validatedOptions = await validateTypes({
7470
7883
  value: options.options,
@@ -7476,14 +7889,25 @@ var ToolLoopAgent = class {
7476
7889
  const { onStepFinish: _settingsOnStepFinish, ...settingsWithoutCallback } = this.settings;
7477
7890
  const baseCallArgs = {
7478
7891
  ...settingsWithoutCallback,
7479
- stopWhen: (_a21 = this.settings.stopWhen) != null ? _a21 : stepCountIs(20),
7892
+ stopWhen: (_a22 = this.settings.stopWhen) != null ? _a22 : stepCountIs(20),
7480
7893
  ...options
7481
7894
  };
7482
7895
  const preparedCallArgs = (_d = await ((_c = (_b = this.settings).prepareCall) == null ? undefined : _c.call(_b, baseCallArgs))) != null ? _d : baseCallArgs;
7483
- const { instructions, messages, prompt, ...callArgs } = preparedCallArgs;
7896
+ const {
7897
+ instructions,
7898
+ allowSystemInMessages,
7899
+ messages,
7900
+ prompt,
7901
+ ...callArgs
7902
+ } = preparedCallArgs;
7484
7903
  return {
7485
7904
  ...callArgs,
7486
- ...{ system: instructions, messages, prompt }
7905
+ ...{
7906
+ system: instructions,
7907
+ allowSystemInMessages,
7908
+ messages,
7909
+ prompt
7910
+ }
7487
7911
  };
7488
7912
  }
7489
7913
  mergeOnStepFinishCallbacks(methodCallback) {
@@ -7527,7 +7951,7 @@ var ToolLoopAgent = class {
7527
7951
  };
7528
7952
  function createUIMessageStream({
7529
7953
  execute,
7530
- onError = getErrorMessage2,
7954
+ onError = () => "An error occurred.",
7531
7955
  originalMessages,
7532
7956
  onStepFinish,
7533
7957
  onFinish,
@@ -7610,7 +8034,7 @@ function readUIMessageStream({
7610
8034
  onError,
7611
8035
  terminateOnError = false
7612
8036
  }) {
7613
- var _a21;
8037
+ var _a22;
7614
8038
  let controller;
7615
8039
  let hasErrored = false;
7616
8040
  const outputStream = new ReadableStream({
@@ -7619,7 +8043,7 @@ function readUIMessageStream({
7619
8043
  }
7620
8044
  });
7621
8045
  const state = createStreamingUIMessageState({
7622
- messageId: (_a21 = message == null ? undefined : message.id) != null ? _a21 : "",
8046
+ messageId: (_a22 = message == null ? undefined : message.id) != null ? _a22 : "",
7623
8047
  lastMessage: message
7624
8048
  });
7625
8049
  const handleError = (error) => {
@@ -7679,7 +8103,7 @@ async function convertToModelMessages(messages, options) {
7679
8103
  modelMessages.push({
7680
8104
  role: "user",
7681
8105
  content: message.parts.map((part) => {
7682
- var _a21;
8106
+ var _a22;
7683
8107
  if (isTextUIPart(part)) {
7684
8108
  return {
7685
8109
  type: "text",
@@ -7697,7 +8121,7 @@ async function convertToModelMessages(messages, options) {
7697
8121
  };
7698
8122
  }
7699
8123
  if (isDataUIPart(part)) {
7700
- return (_a21 = options == null ? undefined : options.convertDataPart) == null ? undefined : _a21.call(options, part);
8124
+ return (_a22 = options == null ? undefined : options.convertDataPart) == null ? undefined : _a22.call(options, part);
7701
8125
  }
7702
8126
  }).filter(isNonNullable)
7703
8127
  });
@@ -7707,7 +8131,7 @@ async function convertToModelMessages(messages, options) {
7707
8131
  if (message.parts != null) {
7708
8132
  let block = [];
7709
8133
  async function processBlock() {
7710
- var _a21, _b, _c, _d, _e, _f, _g;
8134
+ var _a22, _b, _c, _d, _e, _f, _g, _h;
7711
8135
  if (block.length === 0) {
7712
8136
  return;
7713
8137
  }
@@ -7740,7 +8164,7 @@ async function convertToModelMessages(messages, options) {
7740
8164
  type: "tool-call",
7741
8165
  toolCallId: part.toolCallId,
7742
8166
  toolName,
7743
- input: part.state === "output-error" ? (_a21 = part.input) != null ? _a21 : ("rawInput" in part) ? part.rawInput : undefined : part.input,
8167
+ input: part.state === "output-error" ? (_a22 = part.input) != null ? _a22 : ("rawInput" in part) ? part.rawInput : undefined : part.input,
7744
8168
  providerExecuted: part.providerExecuted,
7745
8169
  ...part.callProviderMetadata != null ? { providerOptions: part.callProviderMetadata } : {}
7746
8170
  });
@@ -7748,7 +8172,8 @@ async function convertToModelMessages(messages, options) {
7748
8172
  content.push({
7749
8173
  type: "tool-approval-request",
7750
8174
  approvalId: part.approval.id,
7751
- toolCallId: part.toolCallId
8175
+ toolCallId: part.toolCallId,
8176
+ ...part.approval.signature != null ? { signature: part.approval.signature } : {}
7752
8177
  });
7753
8178
  }
7754
8179
  if (part.providerExecuted === true && part.state !== "approval-responded" && (part.state === "output-available" || part.state === "output-error")) {
@@ -7783,8 +8208,8 @@ async function convertToModelMessages(messages, options) {
7783
8208
  content
7784
8209
  });
7785
8210
  const toolParts = block.filter((part) => {
7786
- var _a22;
7787
- return isToolUIPart(part) && (part.providerExecuted !== true || ((_a22 = part.approval) == null ? undefined : _a22.approved) != null);
8211
+ var _a23;
8212
+ return isToolUIPart(part) && (part.providerExecuted !== true || ((_a23 = part.approval) == null ? undefined : _a23.approved) != null);
7788
8213
  });
7789
8214
  if (toolParts.length > 0) {
7790
8215
  {
@@ -7810,7 +8235,7 @@ async function convertToModelMessages(messages, options) {
7810
8235
  toolName: getToolName(toolPart),
7811
8236
  output: {
7812
8237
  type: "error-text",
7813
- value: (_f = toolPart.approval.reason) != null ? _f : "Tool execution denied."
8238
+ value: (_g = (_f = toolPart.approval) == null ? undefined : _f.reason) != null ? _g : "Tool execution denied."
7814
8239
  },
7815
8240
  ...toolPart.callProviderMetadata != null ? { providerOptions: toolPart.callProviderMetadata } : {}
7816
8241
  });
@@ -7827,7 +8252,7 @@ async function convertToModelMessages(messages, options) {
7827
8252
  toolCallId: toolPart.toolCallId,
7828
8253
  input: toolPart.input,
7829
8254
  output: toolPart.state === "output-error" ? toolPart.errorText : toolPart.output,
7830
- tool: (_g = options == null ? undefined : options.tools) == null ? undefined : _g[toolName],
8255
+ tool: (_h = options == null ? undefined : options.tools) == null ? undefined : _h[toolName],
7831
8256
  errorMode: toolPart.state === "output-error" ? "text" : "none"
7832
8257
  }),
7833
8258
  ...toolPart.callProviderMetadata != null ? { providerOptions: toolPart.callProviderMetadata } : {}
@@ -7869,6 +8294,7 @@ async function convertToModelMessages(messages, options) {
7869
8294
  }
7870
8295
  return modelMessages;
7871
8296
  }
8297
+ var toolMetadataSchema2 = exports_external.record(exports_external.string(), jsonValueSchema.optional());
7872
8298
  var uiMessagesSchema = lazySchema(() => zodSchema(exports_external.array(exports_external.object({
7873
8299
  id: exports_external.string(),
7874
8300
  role: exports_external.enum(["system", "user", "assistant"]),
@@ -7920,6 +8346,7 @@ var uiMessagesSchema = lazySchema(() => zodSchema(exports_external.array(exports
7920
8346
  type: exports_external.literal("dynamic-tool"),
7921
8347
  toolName: exports_external.string(),
7922
8348
  toolCallId: exports_external.string(),
8349
+ toolMetadata: toolMetadataSchema2.optional(),
7923
8350
  state: exports_external.literal("input-streaming"),
7924
8351
  input: exports_external.unknown().optional(),
7925
8352
  providerExecuted: exports_external.boolean().optional(),
@@ -7932,6 +8359,7 @@ var uiMessagesSchema = lazySchema(() => zodSchema(exports_external.array(exports
7932
8359
  type: exports_external.literal("dynamic-tool"),
7933
8360
  toolName: exports_external.string(),
7934
8361
  toolCallId: exports_external.string(),
8362
+ toolMetadata: toolMetadataSchema2.optional(),
7935
8363
  state: exports_external.literal("input-available"),
7936
8364
  input: exports_external.unknown(),
7937
8365
  providerExecuted: exports_external.boolean().optional(),
@@ -7944,6 +8372,7 @@ var uiMessagesSchema = lazySchema(() => zodSchema(exports_external.array(exports
7944
8372
  type: exports_external.literal("dynamic-tool"),
7945
8373
  toolName: exports_external.string(),
7946
8374
  toolCallId: exports_external.string(),
8375
+ toolMetadata: toolMetadataSchema2.optional(),
7947
8376
  state: exports_external.literal("approval-requested"),
7948
8377
  input: exports_external.unknown(),
7949
8378
  providerExecuted: exports_external.boolean().optional(),
@@ -7953,13 +8382,15 @@ var uiMessagesSchema = lazySchema(() => zodSchema(exports_external.array(exports
7953
8382
  approval: exports_external.object({
7954
8383
  id: exports_external.string(),
7955
8384
  approved: exports_external.never().optional(),
7956
- reason: exports_external.never().optional()
8385
+ reason: exports_external.never().optional(),
8386
+ signature: exports_external.string().optional()
7957
8387
  })
7958
8388
  }),
7959
8389
  exports_external.object({
7960
8390
  type: exports_external.literal("dynamic-tool"),
7961
8391
  toolName: exports_external.string(),
7962
8392
  toolCallId: exports_external.string(),
8393
+ toolMetadata: toolMetadataSchema2.optional(),
7963
8394
  state: exports_external.literal("approval-responded"),
7964
8395
  input: exports_external.unknown(),
7965
8396
  providerExecuted: exports_external.boolean().optional(),
@@ -7969,13 +8400,15 @@ var uiMessagesSchema = lazySchema(() => zodSchema(exports_external.array(exports
7969
8400
  approval: exports_external.object({
7970
8401
  id: exports_external.string(),
7971
8402
  approved: exports_external.boolean(),
7972
- reason: exports_external.string().optional()
8403
+ reason: exports_external.string().optional(),
8404
+ signature: exports_external.string().optional()
7973
8405
  })
7974
8406
  }),
7975
8407
  exports_external.object({
7976
8408
  type: exports_external.literal("dynamic-tool"),
7977
8409
  toolName: exports_external.string(),
7978
8410
  toolCallId: exports_external.string(),
8411
+ toolMetadata: toolMetadataSchema2.optional(),
7979
8412
  state: exports_external.literal("output-available"),
7980
8413
  input: exports_external.unknown(),
7981
8414
  providerExecuted: exports_external.boolean().optional(),
@@ -7987,15 +8420,17 @@ var uiMessagesSchema = lazySchema(() => zodSchema(exports_external.array(exports
7987
8420
  approval: exports_external.object({
7988
8421
  id: exports_external.string(),
7989
8422
  approved: exports_external.literal(true),
7990
- reason: exports_external.string().optional()
8423
+ reason: exports_external.string().optional(),
8424
+ signature: exports_external.string().optional()
7991
8425
  }).optional()
7992
8426
  }),
7993
8427
  exports_external.object({
7994
8428
  type: exports_external.literal("dynamic-tool"),
7995
8429
  toolName: exports_external.string(),
7996
8430
  toolCallId: exports_external.string(),
8431
+ toolMetadata: toolMetadataSchema2.optional(),
7997
8432
  state: exports_external.literal("output-error"),
7998
- input: exports_external.unknown(),
8433
+ input: exports_external.unknown().optional(),
7999
8434
  rawInput: exports_external.unknown().optional(),
8000
8435
  providerExecuted: exports_external.boolean().optional(),
8001
8436
  output: exports_external.never().optional(),
@@ -8005,13 +8440,15 @@ var uiMessagesSchema = lazySchema(() => zodSchema(exports_external.array(exports
8005
8440
  approval: exports_external.object({
8006
8441
  id: exports_external.string(),
8007
8442
  approved: exports_external.literal(true),
8008
- reason: exports_external.string().optional()
8443
+ reason: exports_external.string().optional(),
8444
+ signature: exports_external.string().optional()
8009
8445
  }).optional()
8010
8446
  }),
8011
8447
  exports_external.object({
8012
8448
  type: exports_external.literal("dynamic-tool"),
8013
8449
  toolName: exports_external.string(),
8014
8450
  toolCallId: exports_external.string(),
8451
+ toolMetadata: toolMetadataSchema2.optional(),
8015
8452
  state: exports_external.literal("output-denied"),
8016
8453
  input: exports_external.unknown(),
8017
8454
  providerExecuted: exports_external.boolean().optional(),
@@ -8021,12 +8458,14 @@ var uiMessagesSchema = lazySchema(() => zodSchema(exports_external.array(exports
8021
8458
  approval: exports_external.object({
8022
8459
  id: exports_external.string(),
8023
8460
  approved: exports_external.literal(false),
8024
- reason: exports_external.string().optional()
8461
+ reason: exports_external.string().optional(),
8462
+ signature: exports_external.string().optional()
8025
8463
  })
8026
8464
  }),
8027
8465
  exports_external.object({
8028
8466
  type: exports_external.string().startsWith("tool-"),
8029
8467
  toolCallId: exports_external.string(),
8468
+ toolMetadata: toolMetadataSchema2.optional(),
8030
8469
  state: exports_external.literal("input-streaming"),
8031
8470
  providerExecuted: exports_external.boolean().optional(),
8032
8471
  callProviderMetadata: providerMetadataSchema.optional(),
@@ -8038,6 +8477,7 @@ var uiMessagesSchema = lazySchema(() => zodSchema(exports_external.array(exports
8038
8477
  exports_external.object({
8039
8478
  type: exports_external.string().startsWith("tool-"),
8040
8479
  toolCallId: exports_external.string(),
8480
+ toolMetadata: toolMetadataSchema2.optional(),
8041
8481
  state: exports_external.literal("input-available"),
8042
8482
  providerExecuted: exports_external.boolean().optional(),
8043
8483
  input: exports_external.unknown(),
@@ -8049,6 +8489,7 @@ var uiMessagesSchema = lazySchema(() => zodSchema(exports_external.array(exports
8049
8489
  exports_external.object({
8050
8490
  type: exports_external.string().startsWith("tool-"),
8051
8491
  toolCallId: exports_external.string(),
8492
+ toolMetadata: toolMetadataSchema2.optional(),
8052
8493
  state: exports_external.literal("approval-requested"),
8053
8494
  input: exports_external.unknown(),
8054
8495
  providerExecuted: exports_external.boolean().optional(),
@@ -8058,12 +8499,14 @@ var uiMessagesSchema = lazySchema(() => zodSchema(exports_external.array(exports
8058
8499
  approval: exports_external.object({
8059
8500
  id: exports_external.string(),
8060
8501
  approved: exports_external.never().optional(),
8061
- reason: exports_external.never().optional()
8502
+ reason: exports_external.never().optional(),
8503
+ signature: exports_external.string().optional()
8062
8504
  })
8063
8505
  }),
8064
8506
  exports_external.object({
8065
8507
  type: exports_external.string().startsWith("tool-"),
8066
8508
  toolCallId: exports_external.string(),
8509
+ toolMetadata: toolMetadataSchema2.optional(),
8067
8510
  state: exports_external.literal("approval-responded"),
8068
8511
  input: exports_external.unknown(),
8069
8512
  providerExecuted: exports_external.boolean().optional(),
@@ -8073,12 +8516,14 @@ var uiMessagesSchema = lazySchema(() => zodSchema(exports_external.array(exports
8073
8516
  approval: exports_external.object({
8074
8517
  id: exports_external.string(),
8075
8518
  approved: exports_external.boolean(),
8076
- reason: exports_external.string().optional()
8519
+ reason: exports_external.string().optional(),
8520
+ signature: exports_external.string().optional()
8077
8521
  })
8078
8522
  }),
8079
8523
  exports_external.object({
8080
8524
  type: exports_external.string().startsWith("tool-"),
8081
8525
  toolCallId: exports_external.string(),
8526
+ toolMetadata: toolMetadataSchema2.optional(),
8082
8527
  state: exports_external.literal("output-available"),
8083
8528
  providerExecuted: exports_external.boolean().optional(),
8084
8529
  input: exports_external.unknown(),
@@ -8090,15 +8535,17 @@ var uiMessagesSchema = lazySchema(() => zodSchema(exports_external.array(exports
8090
8535
  approval: exports_external.object({
8091
8536
  id: exports_external.string(),
8092
8537
  approved: exports_external.literal(true),
8093
- reason: exports_external.string().optional()
8538
+ reason: exports_external.string().optional(),
8539
+ signature: exports_external.string().optional()
8094
8540
  }).optional()
8095
8541
  }),
8096
8542
  exports_external.object({
8097
8543
  type: exports_external.string().startsWith("tool-"),
8098
8544
  toolCallId: exports_external.string(),
8545
+ toolMetadata: toolMetadataSchema2.optional(),
8099
8546
  state: exports_external.literal("output-error"),
8100
8547
  providerExecuted: exports_external.boolean().optional(),
8101
- input: exports_external.unknown(),
8548
+ input: exports_external.unknown().optional(),
8102
8549
  rawInput: exports_external.unknown().optional(),
8103
8550
  output: exports_external.never().optional(),
8104
8551
  errorText: exports_external.string(),
@@ -8107,12 +8554,14 @@ var uiMessagesSchema = lazySchema(() => zodSchema(exports_external.array(exports
8107
8554
  approval: exports_external.object({
8108
8555
  id: exports_external.string(),
8109
8556
  approved: exports_external.literal(true),
8110
- reason: exports_external.string().optional()
8557
+ reason: exports_external.string().optional(),
8558
+ signature: exports_external.string().optional()
8111
8559
  }).optional()
8112
8560
  }),
8113
8561
  exports_external.object({
8114
8562
  type: exports_external.string().startsWith("tool-"),
8115
8563
  toolCallId: exports_external.string(),
8564
+ toolMetadata: toolMetadataSchema2.optional(),
8116
8565
  state: exports_external.literal("output-denied"),
8117
8566
  providerExecuted: exports_external.boolean().optional(),
8118
8567
  input: exports_external.unknown(),
@@ -8122,7 +8571,8 @@ var uiMessagesSchema = lazySchema(() => zodSchema(exports_external.array(exports
8122
8571
  approval: exports_external.object({
8123
8572
  id: exports_external.string(),
8124
8573
  approved: exports_external.literal(false),
8125
- reason: exports_external.string().optional()
8574
+ reason: exports_external.string().optional(),
8575
+ signature: exports_external.string().optional()
8126
8576
  })
8127
8577
  })
8128
8578
  ])).nonempty("Message must contain at least one part")
@@ -8212,7 +8662,7 @@ async function safeValidateUIMessages({
8212
8662
  })
8213
8663
  };
8214
8664
  }
8215
- if (toolPart.state === "input-available" || toolPart.state === "output-available" || toolPart.state === "output-error" && toolPart.input !== undefined) {
8665
+ if (toolPart.state === "input-available" || toolPart.state === "output-available") {
8216
8666
  await validateTypes({
8217
8667
  value: toolPart.input,
8218
8668
  schema: tool2.inputSchema,
@@ -8276,7 +8726,7 @@ async function createAgentUIStream({
8276
8726
  onStepFinish,
8277
8727
  ...uiMessageStreamOptions
8278
8728
  }) {
8279
- var _a21;
8729
+ var _a22;
8280
8730
  const validatedMessages = await validateUIMessages({
8281
8731
  messages: uiMessages,
8282
8732
  tools: agent.tools
@@ -8294,7 +8744,7 @@ async function createAgentUIStream({
8294
8744
  });
8295
8745
  return result.toUIMessageStream({
8296
8746
  ...uiMessageStreamOptions,
8297
- originalMessages: (_a21 = uiMessageStreamOptions.originalMessages) != null ? _a21 : validatedMessages
8747
+ originalMessages: (_a22 = uiMessageStreamOptions.originalMessages) != null ? _a22 : validatedMessages
8298
8748
  });
8299
8749
  }
8300
8750
  async function createAgentUIStreamResponse({
@@ -8378,7 +8828,7 @@ async function embed({
8378
8828
  }),
8379
8829
  tracer,
8380
8830
  fn: async (doEmbedSpan) => {
8381
- var _a21;
8831
+ var _a22, _b;
8382
8832
  const modelResponse = await model.doEmbed({
8383
8833
  values: [value],
8384
8834
  abortSignal,
@@ -8386,7 +8836,7 @@ async function embed({
8386
8836
  providerOptions
8387
8837
  });
8388
8838
  const embedding2 = modelResponse.embeddings[0];
8389
- const usage2 = (_a21 = modelResponse.usage) != null ? _a21 : { tokens: NaN };
8839
+ const usage2 = (_a22 = modelResponse.usage) != null ? _a22 : { tokens: NaN };
8390
8840
  doEmbedSpan.setAttributes(await selectTelemetryAttributes({
8391
8841
  telemetry,
8392
8842
  attributes: {
@@ -8399,7 +8849,7 @@ async function embed({
8399
8849
  return {
8400
8850
  embedding: embedding2,
8401
8851
  usage: usage2,
8402
- warnings: modelResponse.warnings,
8852
+ warnings: (_b = modelResponse.warnings) != null ? _b : [],
8403
8853
  providerMetadata: modelResponse.providerMetadata,
8404
8854
  response: modelResponse.response
8405
8855
  };
@@ -8481,7 +8931,7 @@ async function embedMany({
8481
8931
  }),
8482
8932
  tracer,
8483
8933
  fn: async (span) => {
8484
- var _a21;
8934
+ var _a22;
8485
8935
  const [maxEmbeddingsPerCall, supportsParallelCalls] = await Promise.all([
8486
8936
  model.maxEmbeddingsPerCall,
8487
8937
  model.supportsParallelCalls
@@ -8505,7 +8955,7 @@ async function embedMany({
8505
8955
  }),
8506
8956
  tracer,
8507
8957
  fn: async (doEmbedSpan) => {
8508
- var _a22;
8958
+ var _a23, _b;
8509
8959
  const modelResponse = await model.doEmbed({
8510
8960
  values,
8511
8961
  abortSignal,
@@ -8513,7 +8963,7 @@ async function embedMany({
8513
8963
  providerOptions
8514
8964
  });
8515
8965
  const embeddings3 = modelResponse.embeddings;
8516
- const usage2 = (_a22 = modelResponse.usage) != null ? _a22 : { tokens: NaN };
8966
+ const usage2 = (_a23 = modelResponse.usage) != null ? _a23 : { tokens: NaN };
8517
8967
  doEmbedSpan.setAttributes(await selectTelemetryAttributes({
8518
8968
  telemetry,
8519
8969
  attributes: {
@@ -8526,7 +8976,7 @@ async function embedMany({
8526
8976
  return {
8527
8977
  embeddings: embeddings3,
8528
8978
  usage: usage2,
8529
- warnings: modelResponse.warnings,
8979
+ warnings: (_b = modelResponse.warnings) != null ? _b : [],
8530
8980
  providerMetadata: modelResponse.providerMetadata,
8531
8981
  response: modelResponse.response
8532
8982
  };
@@ -8583,7 +9033,7 @@ async function embedMany({
8583
9033
  }),
8584
9034
  tracer,
8585
9035
  fn: async (doEmbedSpan) => {
8586
- var _a22;
9036
+ var _a23, _b;
8587
9037
  const modelResponse = await model.doEmbed({
8588
9038
  values: chunk,
8589
9039
  abortSignal,
@@ -8591,7 +9041,7 @@ async function embedMany({
8591
9041
  providerOptions
8592
9042
  });
8593
9043
  const embeddings2 = modelResponse.embeddings;
8594
- const usage = (_a22 = modelResponse.usage) != null ? _a22 : { tokens: NaN };
9044
+ const usage = (_a23 = modelResponse.usage) != null ? _a23 : { tokens: NaN };
8595
9045
  doEmbedSpan.setAttributes(await selectTelemetryAttributes({
8596
9046
  telemetry,
8597
9047
  attributes: {
@@ -8604,7 +9054,7 @@ async function embedMany({
8604
9054
  return {
8605
9055
  embeddings: embeddings2,
8606
9056
  usage,
8607
- warnings: modelResponse.warnings,
9057
+ warnings: (_b = modelResponse.warnings) != null ? _b : [],
8608
9058
  providerMetadata: modelResponse.providerMetadata,
8609
9059
  response: modelResponse.response
8610
9060
  };
@@ -8623,7 +9073,7 @@ async function embedMany({
8623
9073
  } else {
8624
9074
  for (const [providerName, metadata] of Object.entries(result.providerMetadata)) {
8625
9075
  providerMetadata[providerName] = {
8626
- ...(_a21 = providerMetadata[providerName]) != null ? _a21 : {},
9076
+ ...(_a22 = providerMetadata[providerName]) != null ? _a22 : {},
8627
9077
  ...metadata
8628
9078
  };
8629
9079
  }
@@ -8679,14 +9129,14 @@ async function generateImage({
8679
9129
  abortSignal,
8680
9130
  headers
8681
9131
  }) {
8682
- var _a21, _b;
9132
+ var _a22, _b;
8683
9133
  const model = resolveImageModel(modelArg);
8684
9134
  const headersWithUserAgent = withUserAgentSuffix(headers != null ? headers : {}, `ai/${VERSION}`);
8685
9135
  const { retry } = prepareRetries({
8686
9136
  maxRetries: maxRetriesArg,
8687
9137
  abortSignal
8688
9138
  });
8689
- const maxImagesPerCallWithDefault = (_a21 = maxImagesPerCall != null ? maxImagesPerCall : await invokeModelMaxImagesPerCall(model)) != null ? _a21 : 1;
9139
+ const maxImagesPerCallWithDefault = (_a22 = maxImagesPerCall != null ? maxImagesPerCall : await invokeModelMaxImagesPerCall(model)) != null ? _a22 : 1;
8690
9140
  const callCount = Math.ceil(n / maxImagesPerCallWithDefault);
8691
9141
  const callImageCounts = Array.from({ length: callCount }, (_, i) => {
8692
9142
  if (i < callCount - 1) {
@@ -8721,13 +9171,13 @@ async function generateImage({
8721
9171
  };
8722
9172
  for (const result of results) {
8723
9173
  images.push(...result.images.map((image) => {
8724
- var _a22;
9174
+ var _a23;
8725
9175
  return new DefaultGeneratedFile({
8726
9176
  data: image,
8727
- mediaType: (_a22 = detectMediaType({
9177
+ mediaType: (_a23 = detectMediaType({
8728
9178
  data: image,
8729
9179
  signatures: imageMediaTypeSignatures
8730
- })) != null ? _a22 : "image/png"
9180
+ })) != null ? _a23 : "image/png"
8731
9181
  });
8732
9182
  }));
8733
9183
  warnings.push(...result.warnings);
@@ -8901,7 +9351,7 @@ var arrayOutputStrategy = (schema) => {
8901
9351
  isFirstDelta,
8902
9352
  isFinalDelta
8903
9353
  }) {
8904
- var _a21;
9354
+ var _a22;
8905
9355
  if (!isJSONObject(value) || !isJSONArray(value.elements)) {
8906
9356
  return {
8907
9357
  success: false,
@@ -8924,7 +9374,7 @@ var arrayOutputStrategy = (schema) => {
8924
9374
  }
8925
9375
  resultArray.push(result.value);
8926
9376
  }
8927
- const publishedElementCount = (_a21 = latestObject == null ? undefined : latestObject.length) != null ? _a21 : 0;
9377
+ const publishedElementCount = (_a22 = latestObject == null ? undefined : latestObject.length) != null ? _a22 : 0;
8928
9378
  let textDelta = "";
8929
9379
  if (isFirstDelta) {
8930
9380
  textDelta += "[";
@@ -8955,13 +9405,15 @@ var arrayOutputStrategy = (schema) => {
8955
9405
  };
8956
9406
  }
8957
9407
  const inputArray = value.elements;
9408
+ const resultArray = [];
8958
9409
  for (const element of inputArray) {
8959
9410
  const result = await safeValidateTypes({ value: element, schema });
8960
9411
  if (!result.success) {
8961
9412
  return result;
8962
9413
  }
9414
+ resultArray.push(result.value);
8963
9415
  }
8964
- return { success: true, value: inputArray };
9416
+ return { success: true, value: resultArray };
8965
9417
  },
8966
9418
  createElementStream(originalStream) {
8967
9419
  let publishedElements = 0;
@@ -9315,7 +9767,7 @@ async function generateObject(options) {
9315
9767
  }),
9316
9768
  tracer,
9317
9769
  fn: async (span) => {
9318
- var _a21;
9770
+ var _a22;
9319
9771
  let result;
9320
9772
  let finishReason;
9321
9773
  let usage;
@@ -9360,7 +9812,7 @@ async function generateObject(options) {
9360
9812
  }),
9361
9813
  tracer,
9362
9814
  fn: async (span2) => {
9363
- var _a22, _b, _c, _d, _e, _f, _g, _h;
9815
+ var _a23, _b, _c, _d, _e, _f, _g, _h;
9364
9816
  const result2 = await model.doGenerate({
9365
9817
  responseFormat: {
9366
9818
  type: "json",
@@ -9375,7 +9827,7 @@ async function generateObject(options) {
9375
9827
  headers: headersWithUserAgent
9376
9828
  });
9377
9829
  const responseData = {
9378
- id: (_b = (_a22 = result2.response) == null ? undefined : _a22.id) != null ? _b : generateId2(),
9830
+ id: (_b = (_a23 = result2.response) == null ? undefined : _a23.id) != null ? _b : generateId2(),
9379
9831
  timestamp: (_d = (_c = result2.response) == null ? undefined : _c.timestamp) != null ? _d : currentDate(),
9380
9832
  modelId: (_f = (_e = result2.response) == null ? undefined : _e.modelId) != null ? _f : model.modelId,
9381
9833
  headers: (_g = result2.response) == null ? undefined : _g.headers,
@@ -9424,7 +9876,7 @@ async function generateObject(options) {
9424
9876
  usage = asLanguageModelUsage(generateResult.usage);
9425
9877
  warnings = generateResult.warnings;
9426
9878
  resultProviderMetadata = generateResult.providerMetadata;
9427
- request = (_a21 = generateResult.request) != null ? _a21 : {};
9879
+ request = (_a22 = generateResult.request) != null ? _a22 : {};
9428
9880
  response = generateResult.responseData;
9429
9881
  reasoning = generateResult.reasoning;
9430
9882
  logWarnings({
@@ -9477,9 +9929,9 @@ var DefaultGenerateObjectResult = class {
9477
9929
  this.reasoning = options.reasoning;
9478
9930
  }
9479
9931
  toJsonResponse(init) {
9480
- var _a21;
9932
+ var _a22;
9481
9933
  return new Response(JSON.stringify(this.object), {
9482
- status: (_a21 = init == null ? undefined : init.status) != null ? _a21 : 200,
9934
+ status: (_a22 = init == null ? undefined : init.status) != null ? _a22 : 200,
9483
9935
  headers: prepareHeaders(init == null ? undefined : init.headers, {
9484
9936
  "content-type": "application/json; charset=utf-8"
9485
9937
  })
@@ -9594,8 +10046,8 @@ function simulateReadableStream({
9594
10046
  chunkDelayInMs = 0,
9595
10047
  _internal
9596
10048
  }) {
9597
- var _a21;
9598
- const delay2 = (_a21 = _internal == null ? undefined : _internal.delay) != null ? _a21 : delay;
10049
+ var _a22;
10050
+ const delay2 = (_a22 = _internal == null ? undefined : _internal.delay) != null ? _a22 : delay;
9599
10051
  let index = 0;
9600
10052
  return new ReadableStream({
9601
10053
  async pull(controller) {
@@ -9850,7 +10302,7 @@ var DefaultStreamObjectResult = class {
9850
10302
  let isFirstDelta = true;
9851
10303
  const transformedStream = stream.pipeThrough(new TransformStream(transformer)).pipeThrough(new TransformStream({
9852
10304
  async transform(chunk, controller) {
9853
- var _a21, _b, _c;
10305
+ var _a22, _b, _c;
9854
10306
  if (typeof chunk === "object" && chunk.type === "stream-start") {
9855
10307
  warnings = chunk.warnings;
9856
10308
  return;
@@ -9897,7 +10349,7 @@ var DefaultStreamObjectResult = class {
9897
10349
  switch (chunk.type) {
9898
10350
  case "response-metadata": {
9899
10351
  fullResponse = {
9900
- id: (_a21 = chunk.id) != null ? _a21 : fullResponse.id,
10352
+ id: (_a22 = chunk.id) != null ? _a22 : fullResponse.id,
9901
10353
  timestamp: (_b = chunk.timestamp) != null ? _b : fullResponse.timestamp,
9902
10354
  modelId: (_c = chunk.modelId) != null ? _c : fullResponse.modelId
9903
10355
  };
@@ -10138,7 +10590,7 @@ async function generateSpeech({
10138
10590
  abortSignal,
10139
10591
  headers
10140
10592
  }) {
10141
- var _a21;
10593
+ var _a22;
10142
10594
  const resolvedModel = resolveSpeechModel(model);
10143
10595
  if (!resolvedModel) {
10144
10596
  throw new Error("Model could not be resolved");
@@ -10170,10 +10622,10 @@ async function generateSpeech({
10170
10622
  return new DefaultSpeechResult({
10171
10623
  audio: new DefaultGeneratedAudioFile({
10172
10624
  data: result.audio,
10173
- mediaType: (_a21 = detectMediaType({
10625
+ mediaType: (_a22 = detectMediaType({
10174
10626
  data: result.audio,
10175
10627
  signatures: audioMediaTypeSignatures
10176
- })) != null ? _a21 : "audio/mp3"
10628
+ })) != null ? _a22 : "audio/mp3"
10177
10629
  }),
10178
10630
  warnings: result.warnings,
10179
10631
  responses: [result.response],
@@ -10182,11 +10634,11 @@ async function generateSpeech({
10182
10634
  }
10183
10635
  var DefaultSpeechResult = class {
10184
10636
  constructor(options) {
10185
- var _a21;
10637
+ var _a22;
10186
10638
  this.audio = options.audio;
10187
10639
  this.warnings = options.warnings;
10188
10640
  this.responses = options.responses;
10189
- this.providerMetadata = (_a21 = options.providerMetadata) != null ? _a21 : {};
10641
+ this.providerMetadata = (_a22 = options.providerMetadata) != null ? _a22 : {};
10190
10642
  }
10191
10643
  };
10192
10644
  function pruneMessages({
@@ -10371,7 +10823,7 @@ async function experimental_generateVideo({
10371
10823
  headers,
10372
10824
  download: downloadFn = defaultDownload
10373
10825
  }) {
10374
- var _a21;
10826
+ var _a22;
10375
10827
  const model = resolveVideoModel(modelArg);
10376
10828
  const headersWithUserAgent = withUserAgentSuffix(headers != null ? headers : {}, `ai/${VERSION}`);
10377
10829
  const { retry } = prepareRetries({
@@ -10379,7 +10831,7 @@ async function experimental_generateVideo({
10379
10831
  abortSignal
10380
10832
  });
10381
10833
  const { prompt, image } = normalizePrompt2(promptArg);
10382
- const maxVideosPerCallWithDefault = (_a21 = maxVideosPerCall != null ? maxVideosPerCall : await invokeModelMaxVideosPerCall(model)) != null ? _a21 : 1;
10834
+ const maxVideosPerCallWithDefault = (_a22 = maxVideosPerCall != null ? maxVideosPerCall : await invokeModelMaxVideosPerCall(model)) != null ? _a22 : 1;
10383
10835
  const callCount = Math.ceil(n / maxVideosPerCallWithDefault);
10384
10836
  const callVideoCounts = Array.from({ length: callCount }, (_, index) => {
10385
10837
  const remaining = n - index * maxVideosPerCallWithDefault;
@@ -10487,7 +10939,7 @@ async function experimental_generateVideo({
10487
10939
  };
10488
10940
  }
10489
10941
  function normalizePrompt2(promptArg) {
10490
- var _a21, _b;
10942
+ var _a22, _b;
10491
10943
  if (typeof promptArg === "string") {
10492
10944
  return {
10493
10945
  prompt: promptArg,
@@ -10512,10 +10964,10 @@ function normalizePrompt2(promptArg) {
10512
10964
  };
10513
10965
  } else {
10514
10966
  const bytes = convertBase64ToUint8Array(dataContent);
10515
- const mediaType = (_a21 = detectMediaType({
10967
+ const mediaType = (_a22 = detectMediaType({
10516
10968
  data: bytes,
10517
10969
  signatures: imageMediaTypeSignatures
10518
- })) != null ? _a21 : "image/png";
10970
+ })) != null ? _a22 : "image/png";
10519
10971
  image = {
10520
10972
  type: "file",
10521
10973
  mediaType,
@@ -10569,8 +11021,8 @@ function defaultTransform(text2) {
10569
11021
  return text2.replace(/^```(?:json)?\s*\n?/, "").replace(/\n?```\s*$/, "").trim();
10570
11022
  }
10571
11023
  function extractJsonMiddleware(options) {
10572
- var _a21;
10573
- const transform = (_a21 = options == null ? undefined : options.transform) != null ? _a21 : defaultTransform;
11024
+ var _a22;
11025
+ const transform = (_a22 = options == null ? undefined : options.transform) != null ? _a22 : defaultTransform;
10574
11026
  const hasCustomTransform = (options == null ? undefined : options.transform) !== undefined;
10575
11027
  return {
10576
11028
  specificationVersion: "v3",
@@ -10591,7 +11043,7 @@ function extractJsonMiddleware(options) {
10591
11043
  },
10592
11044
  wrapStream: async ({ doStream }) => {
10593
11045
  const { stream, ...rest } = await doStream();
10594
- const textBlocks = {};
11046
+ const textBlocks = createIdMap();
10595
11047
  const SUFFIX_BUFFER_SIZE = 12;
10596
11048
  return {
10597
11049
  stream: stream.pipeThrough(new TransformStream({
@@ -10745,7 +11197,7 @@ function extractReasoningMiddleware({
10745
11197
  },
10746
11198
  wrapStream: async ({ doStream }) => {
10747
11199
  const { stream, ...rest } = await doStream();
10748
- const reasoningExtractions = {};
11200
+ const reasoningExtractions = createIdMap();
10749
11201
  let delayedTextStart;
10750
11202
  return {
10751
11203
  stream: stream.pipeThrough(new TransformStream({
@@ -10924,13 +11376,13 @@ function addToolInputExamplesMiddleware({
10924
11376
  return {
10925
11377
  specificationVersion: "v3",
10926
11378
  transformParams: async ({ params }) => {
10927
- var _a21;
10928
- if (!((_a21 = params.tools) == null ? undefined : _a21.length)) {
11379
+ var _a22;
11380
+ if (!((_a22 = params.tools) == null ? undefined : _a22.length)) {
10929
11381
  return params;
10930
11382
  }
10931
11383
  const transformedTools = params.tools.map((tool2) => {
10932
- var _a22;
10933
- if (tool2.type !== "function" || !((_a22 = tool2.inputExamples) == null ? undefined : _a22.length)) {
11384
+ var _a23;
11385
+ if (tool2.type !== "function" || !((_a23 = tool2.inputExamples) == null ? undefined : _a23.length)) {
10934
11386
  return tool2;
10935
11387
  }
10936
11388
  const formattedExamples = tool2.inputExamples.map((example, index) => format(example, index)).join(`
@@ -10976,7 +11428,7 @@ var doWrap = ({
10976
11428
  modelId,
10977
11429
  providerId
10978
11430
  }) => {
10979
- var _a21, _b, _c;
11431
+ var _a22, _b, _c;
10980
11432
  async function doTransform({
10981
11433
  params,
10982
11434
  type
@@ -10985,7 +11437,7 @@ var doWrap = ({
10985
11437
  }
10986
11438
  return {
10987
11439
  specificationVersion: "v3",
10988
- provider: (_a21 = providerId != null ? providerId : overrideProvider == null ? undefined : overrideProvider({ model })) != null ? _a21 : model.provider,
11440
+ provider: (_a22 = providerId != null ? providerId : overrideProvider == null ? undefined : overrideProvider({ model })) != null ? _a22 : model.provider,
10989
11441
  modelId: (_b = modelId != null ? modelId : overrideModelId == null ? undefined : overrideModelId({ model })) != null ? _b : model.modelId,
10990
11442
  supportedUrls: (_c = overrideSupportedUrls == null ? undefined : overrideSupportedUrls({ model })) != null ? _c : model.supportedUrls,
10991
11443
  async doGenerate(params) {
@@ -11030,7 +11482,7 @@ var doWrap2 = ({
11030
11482
  modelId,
11031
11483
  providerId
11032
11484
  }) => {
11033
- var _a21, _b, _c, _d;
11485
+ var _a22, _b, _c, _d;
11034
11486
  async function doTransform({
11035
11487
  params
11036
11488
  }) {
@@ -11038,7 +11490,7 @@ var doWrap2 = ({
11038
11490
  }
11039
11491
  return {
11040
11492
  specificationVersion: "v3",
11041
- provider: (_a21 = providerId != null ? providerId : overrideProvider == null ? undefined : overrideProvider({ model })) != null ? _a21 : model.provider,
11493
+ provider: (_a22 = providerId != null ? providerId : overrideProvider == null ? undefined : overrideProvider({ model })) != null ? _a22 : model.provider,
11042
11494
  modelId: (_b = modelId != null ? modelId : overrideModelId == null ? undefined : overrideModelId({ model })) != null ? _b : model.modelId,
11043
11495
  maxEmbeddingsPerCall: (_c = overrideMaxEmbeddingsPerCall == null ? undefined : overrideMaxEmbeddingsPerCall({ model })) != null ? _c : model.maxEmbeddingsPerCall,
11044
11496
  supportsParallelCalls: (_d = overrideSupportsParallelCalls == null ? undefined : overrideSupportsParallelCalls({ model })) != null ? _d : model.supportsParallelCalls,
@@ -11075,11 +11527,11 @@ var doWrap3 = ({
11075
11527
  modelId,
11076
11528
  providerId
11077
11529
  }) => {
11078
- var _a21, _b, _c;
11530
+ var _a22, _b, _c;
11079
11531
  async function doTransform({ params }) {
11080
11532
  return transformParams ? await transformParams({ params, model }) : params;
11081
11533
  }
11082
- const maxImagesPerCallRaw = (_a21 = overrideMaxImagesPerCall == null ? undefined : overrideMaxImagesPerCall({ model })) != null ? _a21 : model.maxImagesPerCall;
11534
+ const maxImagesPerCallRaw = (_a22 = overrideMaxImagesPerCall == null ? undefined : overrideMaxImagesPerCall({ model })) != null ? _a22 : model.maxImagesPerCall;
11083
11535
  const maxImagesPerCall = maxImagesPerCallRaw instanceof Function ? maxImagesPerCallRaw.bind(model) : maxImagesPerCallRaw;
11084
11536
  return {
11085
11537
  specificationVersion: "v3",
@@ -11217,10 +11669,10 @@ function customProvider({
11217
11669
  };
11218
11670
  }
11219
11671
  var experimental_customProvider = customProvider;
11220
- var name20 = "AI_NoSuchProviderError";
11221
- var marker20 = `vercel.ai.error.${name20}`;
11222
- var symbol20 = Symbol.for(marker20);
11223
- var _a20;
11672
+ var name21 = "AI_NoSuchProviderError";
11673
+ var marker21 = `vercel.ai.error.${name21}`;
11674
+ var symbol21 = Symbol.for(marker21);
11675
+ var _a21;
11224
11676
  var NoSuchProviderError = class extends NoSuchModelError {
11225
11677
  constructor({
11226
11678
  modelId,
@@ -11229,16 +11681,16 @@ var NoSuchProviderError = class extends NoSuchModelError {
11229
11681
  availableProviders,
11230
11682
  message = `No such provider: ${providerId} (available providers: ${availableProviders.join()})`
11231
11683
  }) {
11232
- super({ errorName: name20, modelId, modelType, message });
11233
- this[_a20] = true;
11684
+ super({ errorName: name21, modelId, modelType, message });
11685
+ this[_a21] = true;
11234
11686
  this.providerId = providerId;
11235
11687
  this.availableProviders = availableProviders;
11236
11688
  }
11237
11689
  static isInstance(error) {
11238
- return AISDKError.hasMarker(error, marker20);
11690
+ return AISDKError.hasMarker(error, marker21);
11239
11691
  }
11240
11692
  };
11241
- _a20 = symbol20;
11693
+ _a21 = symbol21;
11242
11694
  function createProviderRegistry(providers, {
11243
11695
  separator = ":",
11244
11696
  languageModelMiddleware,
@@ -11296,9 +11748,9 @@ var DefaultProviderRegistry = class {
11296
11748
  return [id.slice(0, index), id.slice(index + this.separator.length)];
11297
11749
  }
11298
11750
  languageModel(id) {
11299
- var _a21, _b;
11751
+ var _a22, _b;
11300
11752
  const [providerId, modelId] = this.splitId(id, "languageModel");
11301
- let model = (_b = (_a21 = this.getProvider(providerId, "languageModel")).languageModel) == null ? undefined : _b.call(_a21, modelId);
11753
+ let model = (_b = (_a22 = this.getProvider(providerId, "languageModel")).languageModel) == null ? undefined : _b.call(_a22, modelId);
11302
11754
  if (model == null) {
11303
11755
  throw new NoSuchModelError({ modelId: id, modelType: "languageModel" });
11304
11756
  }
@@ -11311,10 +11763,10 @@ var DefaultProviderRegistry = class {
11311
11763
  return model;
11312
11764
  }
11313
11765
  embeddingModel(id) {
11314
- var _a21;
11766
+ var _a22;
11315
11767
  const [providerId, modelId] = this.splitId(id, "embeddingModel");
11316
11768
  const provider = this.getProvider(providerId, "embeddingModel");
11317
- const model = (_a21 = provider.embeddingModel) == null ? undefined : _a21.call(provider, modelId);
11769
+ const model = (_a22 = provider.embeddingModel) == null ? undefined : _a22.call(provider, modelId);
11318
11770
  if (model == null) {
11319
11771
  throw new NoSuchModelError({
11320
11772
  modelId: id,
@@ -11324,10 +11776,10 @@ var DefaultProviderRegistry = class {
11324
11776
  return model;
11325
11777
  }
11326
11778
  imageModel(id) {
11327
- var _a21;
11779
+ var _a22;
11328
11780
  const [providerId, modelId] = this.splitId(id, "imageModel");
11329
11781
  const provider = this.getProvider(providerId, "imageModel");
11330
- let model = (_a21 = provider.imageModel) == null ? undefined : _a21.call(provider, modelId);
11782
+ let model = (_a22 = provider.imageModel) == null ? undefined : _a22.call(provider, modelId);
11331
11783
  if (model == null) {
11332
11784
  throw new NoSuchModelError({ modelId: id, modelType: "imageModel" });
11333
11785
  }
@@ -11340,10 +11792,10 @@ var DefaultProviderRegistry = class {
11340
11792
  return model;
11341
11793
  }
11342
11794
  transcriptionModel(id) {
11343
- var _a21;
11795
+ var _a22;
11344
11796
  const [providerId, modelId] = this.splitId(id, "transcriptionModel");
11345
11797
  const provider = this.getProvider(providerId, "transcriptionModel");
11346
- const model = (_a21 = provider.transcriptionModel) == null ? undefined : _a21.call(provider, modelId);
11798
+ const model = (_a22 = provider.transcriptionModel) == null ? undefined : _a22.call(provider, modelId);
11347
11799
  if (model == null) {
11348
11800
  throw new NoSuchModelError({
11349
11801
  modelId: id,
@@ -11353,20 +11805,20 @@ var DefaultProviderRegistry = class {
11353
11805
  return model;
11354
11806
  }
11355
11807
  speechModel(id) {
11356
- var _a21;
11808
+ var _a22;
11357
11809
  const [providerId, modelId] = this.splitId(id, "speechModel");
11358
11810
  const provider = this.getProvider(providerId, "speechModel");
11359
- const model = (_a21 = provider.speechModel) == null ? undefined : _a21.call(provider, modelId);
11811
+ const model = (_a22 = provider.speechModel) == null ? undefined : _a22.call(provider, modelId);
11360
11812
  if (model == null) {
11361
11813
  throw new NoSuchModelError({ modelId: id, modelType: "speechModel" });
11362
11814
  }
11363
11815
  return model;
11364
11816
  }
11365
11817
  rerankingModel(id) {
11366
- var _a21;
11818
+ var _a22;
11367
11819
  const [providerId, modelId] = this.splitId(id, "rerankingModel");
11368
11820
  const provider = this.getProvider(providerId, "rerankingModel");
11369
- const model = (_a21 = provider.rerankingModel) == null ? undefined : _a21.call(provider, modelId);
11821
+ const model = (_a22 = provider.rerankingModel) == null ? undefined : _a22.call(provider, modelId);
11370
11822
  if (model == null) {
11371
11823
  throw new NoSuchModelError({ modelId: id, modelType: "rerankingModel" });
11372
11824
  }
@@ -11422,7 +11874,7 @@ async function rerank({
11422
11874
  }),
11423
11875
  tracer,
11424
11876
  fn: async () => {
11425
- var _a21, _b;
11877
+ var _a22, _b;
11426
11878
  const { ranking, response, providerMetadata, warnings } = await retry(() => recordSpan({
11427
11879
  name: "ai.rerank.doRerank",
11428
11880
  attributes: selectTelemetryAttributes({
@@ -11481,7 +11933,7 @@ async function rerank({
11481
11933
  providerMetadata,
11482
11934
  response: {
11483
11935
  id: response == null ? undefined : response.id,
11484
- timestamp: (_a21 = response == null ? undefined : response.timestamp) != null ? _a21 : /* @__PURE__ */ new Date,
11936
+ timestamp: (_a22 = response == null ? undefined : response.timestamp) != null ? _a22 : /* @__PURE__ */ new Date,
11485
11937
  modelId: (_b = response == null ? undefined : response.modelId) != null ? _b : model.modelId,
11486
11938
  headers: response == null ? undefined : response.headers,
11487
11939
  body: response == null ? undefined : response.body
@@ -11522,16 +11974,16 @@ async function transcribe({
11522
11974
  const headersWithUserAgent = withUserAgentSuffix(headers != null ? headers : {}, `ai/${VERSION}`);
11523
11975
  const audioData = audio instanceof URL ? (await downloadFn({ url: audio, abortSignal })).data : convertDataContentToUint8Array(audio);
11524
11976
  const result = await retry(() => {
11525
- var _a21;
11977
+ var _a22;
11526
11978
  return resolvedModel.doGenerate({
11527
11979
  audio: audioData,
11528
11980
  abortSignal,
11529
11981
  headers: headersWithUserAgent,
11530
11982
  providerOptions,
11531
- mediaType: (_a21 = detectMediaType({
11983
+ mediaType: (_a22 = detectMediaType({
11532
11984
  data: audioData,
11533
11985
  signatures: audioMediaTypeSignatures
11534
- })) != null ? _a21 : "audio/wav"
11986
+ })) != null ? _a22 : "audio/wav"
11535
11987
  });
11536
11988
  });
11537
11989
  logWarnings({
@@ -11554,14 +12006,14 @@ async function transcribe({
11554
12006
  }
11555
12007
  var DefaultTranscriptionResult = class {
11556
12008
  constructor(options) {
11557
- var _a21;
12009
+ var _a22;
11558
12010
  this.text = options.text;
11559
12011
  this.segments = options.segments;
11560
12012
  this.language = options.language;
11561
12013
  this.durationInSeconds = options.durationInSeconds;
11562
12014
  this.warnings = options.warnings;
11563
12015
  this.responses = options.responses;
11564
- this.providerMetadata = (_a21 = options.providerMetadata) != null ? _a21 : {};
12016
+ this.providerMetadata = (_a22 = options.providerMetadata) != null ? _a22 : {};
11565
12017
  }
11566
12018
  };
11567
12019
  async function processTextStream({
@@ -11593,7 +12045,7 @@ async function callCompletionApi({
11593
12045
  onError,
11594
12046
  fetch: fetch2 = getOriginalFetch()
11595
12047
  }) {
11596
- var _a21;
12048
+ var _a22;
11597
12049
  try {
11598
12050
  setLoading(true);
11599
12051
  setError(undefined);
@@ -11616,7 +12068,7 @@ async function callCompletionApi({
11616
12068
  throw err;
11617
12069
  });
11618
12070
  if (!response.ok) {
11619
- throw new Error((_a21 = await response.text()) != null ? _a21 : "Failed to fetch the chat response.");
12071
+ throw new Error((_a22 = await response.text()) != null ? _a22 : "Failed to fetch the chat response.");
11620
12072
  }
11621
12073
  if (!response.body) {
11622
12074
  throw new Error("The response body is empty.");
@@ -11691,12 +12143,12 @@ async function convertFileListToFileUIParts(files) {
11691
12143
  throw new Error("FileList is not supported in the current environment");
11692
12144
  }
11693
12145
  return Promise.all(Array.from(files).map(async (file) => {
11694
- const { name: name21, type } = file;
12146
+ const { name: name22, type } = file;
11695
12147
  const dataUrl = await new Promise((resolve3, reject) => {
11696
12148
  const reader = new FileReader;
11697
12149
  reader.onload = (readerEvent) => {
11698
- var _a21;
11699
- resolve3((_a21 = readerEvent.target) == null ? undefined : _a21.result);
12150
+ var _a22;
12151
+ resolve3((_a22 = readerEvent.target) == null ? undefined : _a22.result);
11700
12152
  };
11701
12153
  reader.onerror = (error) => reject(error);
11702
12154
  reader.readAsDataURL(file);
@@ -11704,7 +12156,7 @@ async function convertFileListToFileUIParts(files) {
11704
12156
  return {
11705
12157
  type: "file",
11706
12158
  mediaType: type,
11707
- filename: name21,
12159
+ filename: name22,
11708
12160
  url: dataUrl
11709
12161
  };
11710
12162
  }));
@@ -11731,7 +12183,7 @@ var HttpChatTransport = class {
11731
12183
  abortSignal,
11732
12184
  ...options
11733
12185
  }) {
11734
- var _a21, _b, _c, _d, _e;
12186
+ var _a22, _b, _c, _d, _e;
11735
12187
  const resolvedBody = await resolve(this.body);
11736
12188
  const resolvedHeaders = await resolve(this.headers);
11737
12189
  const resolvedCredentials = await resolve(this.credentials);
@@ -11739,7 +12191,7 @@ var HttpChatTransport = class {
11739
12191
  ...normalizeHeaders(resolvedHeaders),
11740
12192
  ...normalizeHeaders(options.headers)
11741
12193
  };
11742
- const preparedRequest = await ((_a21 = this.prepareSendMessagesRequest) == null ? undefined : _a21.call(this, {
12194
+ const preparedRequest = await ((_a22 = this.prepareSendMessagesRequest) == null ? undefined : _a22.call(this, {
11743
12195
  api: this.api,
11744
12196
  id: options.chatId,
11745
12197
  messages: options.messages,
@@ -11781,7 +12233,7 @@ var HttpChatTransport = class {
11781
12233
  return this.processResponseStream(response.body);
11782
12234
  }
11783
12235
  async reconnectToStream(options) {
11784
- var _a21, _b, _c, _d, _e;
12236
+ var _a22, _b, _c, _d, _e;
11785
12237
  const resolvedBody = await resolve(this.body);
11786
12238
  const resolvedHeaders = await resolve(this.headers);
11787
12239
  const resolvedCredentials = await resolve(this.credentials);
@@ -11789,7 +12241,7 @@ var HttpChatTransport = class {
11789
12241
  ...normalizeHeaders(resolvedHeaders),
11790
12242
  ...normalizeHeaders(options.headers)
11791
12243
  };
11792
- const preparedRequest = await ((_a21 = this.prepareReconnectToStreamRequest) == null ? undefined : _a21.call(this, {
12244
+ const preparedRequest = await ((_a22 = this.prepareReconnectToStreamRequest) == null ? undefined : _a22.call(this, {
11793
12245
  api: this.api,
11794
12246
  id: options.chatId,
11795
12247
  body: { ...resolvedBody, ...options.body },
@@ -11853,11 +12305,11 @@ var AbstractChat = class {
11853
12305
  this.activeResponse = undefined;
11854
12306
  this.jobExecutor = new SerialJobExecutor;
11855
12307
  this.sendMessage = async (message, options) => {
11856
- var _a21, _b, _c, _d;
12308
+ var _a22, _b, _c, _d;
11857
12309
  if (message == null) {
11858
12310
  await this.makeRequest({
11859
12311
  trigger: "submit-message",
11860
- messageId: (_a21 = this.lastMessage) == null ? undefined : _a21.id,
12312
+ messageId: (_a22 = this.lastMessage) == null ? undefined : _a22.id,
11861
12313
  ...options
11862
12314
  });
11863
12315
  return;
@@ -11949,11 +12401,11 @@ var AbstractChat = class {
11949
12401
  }
11950
12402
  if (this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) {
11951
12403
  this.shouldSendAutomatically().then((shouldSend) => {
11952
- var _a21;
12404
+ var _a22;
11953
12405
  if (shouldSend) {
11954
12406
  this.makeRequest({
11955
12407
  trigger: "submit-message",
11956
- messageId: (_a21 = this.lastMessage) == null ? undefined : _a21.id,
12408
+ messageId: (_a22 = this.lastMessage) == null ? undefined : _a22.id,
11957
12409
  ...options
11958
12410
  });
11959
12411
  }
@@ -11979,11 +12431,11 @@ var AbstractChat = class {
11979
12431
  }
11980
12432
  if (this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) {
11981
12433
  this.shouldSendAutomatically().then((shouldSend) => {
11982
- var _a21;
12434
+ var _a22;
11983
12435
  if (shouldSend) {
11984
12436
  this.makeRequest({
11985
12437
  trigger: "submit-message",
11986
- messageId: (_a21 = this.lastMessage) == null ? undefined : _a21.id,
12438
+ messageId: (_a22 = this.lastMessage) == null ? undefined : _a22.id,
11987
12439
  ...options
11988
12440
  });
11989
12441
  }
@@ -11992,10 +12444,10 @@ var AbstractChat = class {
11992
12444
  });
11993
12445
  this.addToolResult = this.addToolOutput;
11994
12446
  this.stop = async () => {
11995
- var _a21;
12447
+ var _a22;
11996
12448
  if (this.status !== "streaming" && this.status !== "submitted")
11997
12449
  return;
11998
- if ((_a21 = this.activeResponse) == null ? undefined : _a21.abortController) {
12450
+ if ((_a22 = this.activeResponse) == null ? undefined : _a22.abortController) {
11999
12451
  this.activeResponse.abortController.abort();
12000
12452
  }
12001
12453
  };
@@ -12053,7 +12505,7 @@ var AbstractChat = class {
12053
12505
  body,
12054
12506
  messageId
12055
12507
  }) {
12056
- var _a21, _b, _c;
12508
+ var _a22, _b, _c;
12057
12509
  let resumeStream;
12058
12510
  if (trigger === "resume-stream") {
12059
12511
  try {
@@ -12110,9 +12562,9 @@ var AbstractChat = class {
12110
12562
  const runUpdateMessageJob = (job) => this.jobExecutor.run(() => job({
12111
12563
  state: activeResponse.state,
12112
12564
  write: () => {
12113
- var _a22;
12565
+ var _a23;
12114
12566
  this.setStatus({ status: "streaming" });
12115
- const replaceLastMessage = activeResponse.state.message.id === ((_a22 = this.lastMessage) == null ? undefined : _a22.id);
12567
+ const replaceLastMessage = activeResponse.state.message.id === ((_a23 = this.lastMessage) == null ? undefined : _a23.id);
12116
12568
  if (replaceLastMessage) {
12117
12569
  this.state.replaceMessage(this.state.messages.length - 1, activeResponse.state.message);
12118
12570
  } else {
@@ -12159,7 +12611,7 @@ var AbstractChat = class {
12159
12611
  isAbort,
12160
12612
  isDisconnect,
12161
12613
  isError,
12162
- finishReason: (_a21 = this.activeResponse) == null ? undefined : _a21.state.finishReason
12614
+ finishReason: (_a22 = this.activeResponse) == null ? undefined : _a22.state.finishReason
12163
12615
  });
12164
12616
  } catch (err) {
12165
12617
  console.error(err);
@@ -12383,6 +12835,7 @@ export {
12383
12835
  JsonToSseTransformStream,
12384
12836
  JSONParseError,
12385
12837
  InvalidToolInputError,
12838
+ InvalidToolApprovalSignatureError,
12386
12839
  InvalidToolApprovalError,
12387
12840
  InvalidStreamPartError,
12388
12841
  InvalidResponseDataError,