ai 3.1.5 → 3.1.7

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.
@@ -204,7 +204,15 @@ function convertDataContentToUint8Array(content) {
204
204
  return content;
205
205
  }
206
206
  if (typeof content === "string") {
207
- return convertBase64ToUint8Array(content);
207
+ try {
208
+ return convertBase64ToUint8Array(content);
209
+ } catch (error) {
210
+ throw new InvalidDataContentError({
211
+ message: "Invalid data content. Content string is not a base64-encoded image.",
212
+ content,
213
+ cause: error
214
+ });
215
+ }
208
216
  }
209
217
  if (content instanceof ArrayBuffer) {
210
218
  return new Uint8Array(content);
@@ -588,7 +596,7 @@ var dataMessageStreamPart = {
588
596
  };
589
597
  }
590
598
  };
591
- var toolCallStreamPart = {
599
+ var toolCallsStreamPart = {
592
600
  code: "7",
593
601
  name: "tool_calls",
594
602
  parse: (value) => {
@@ -615,6 +623,36 @@ var messageAnnotationsStreamPart = {
615
623
  return { type: "message_annotations", value };
616
624
  }
617
625
  };
626
+ var toolCallStreamPart = {
627
+ code: "9",
628
+ name: "tool_call",
629
+ parse: (value) => {
630
+ if (value == null || typeof value !== "object" || !("toolCallId" in value) || typeof value.toolCallId !== "string" || !("toolName" in value) || typeof value.toolName !== "string" || !("args" in value) || typeof value.args !== "object") {
631
+ throw new Error(
632
+ '"tool_call" parts expect an object with a "toolCallId", "toolName", and "args" property.'
633
+ );
634
+ }
635
+ return {
636
+ type: "tool_call",
637
+ value
638
+ };
639
+ }
640
+ };
641
+ var toolResultStreamPart = {
642
+ code: "a",
643
+ name: "tool_result",
644
+ parse: (value) => {
645
+ if (value == null || typeof value !== "object" || !("toolCallId" in value) || typeof value.toolCallId !== "string" || !("toolName" in value) || typeof value.toolName !== "string" || !("args" in value) || typeof value.args !== "object" || !("result" in value)) {
646
+ throw new Error(
647
+ '"tool_result" parts expect an object with a "toolCallId", "toolName", "args", and "result" property.'
648
+ );
649
+ }
650
+ return {
651
+ type: "tool_result",
652
+ value
653
+ };
654
+ }
655
+ };
618
656
  var streamParts = [
619
657
  textStreamPart,
620
658
  functionCallStreamPart,
@@ -623,8 +661,10 @@ var streamParts = [
623
661
  assistantMessageStreamPart,
624
662
  assistantControlDataStreamPart,
625
663
  dataMessageStreamPart,
664
+ toolCallsStreamPart,
665
+ messageAnnotationsStreamPart,
626
666
  toolCallStreamPart,
627
- messageAnnotationsStreamPart
667
+ toolResultStreamPart
628
668
  ];
629
669
  var streamPartsByCode = {
630
670
  [textStreamPart.code]: textStreamPart,
@@ -634,8 +674,10 @@ var streamPartsByCode = {
634
674
  [assistantMessageStreamPart.code]: assistantMessageStreamPart,
635
675
  [assistantControlDataStreamPart.code]: assistantControlDataStreamPart,
636
676
  [dataMessageStreamPart.code]: dataMessageStreamPart,
677
+ [toolCallsStreamPart.code]: toolCallsStreamPart,
678
+ [messageAnnotationsStreamPart.code]: messageAnnotationsStreamPart,
637
679
  [toolCallStreamPart.code]: toolCallStreamPart,
638
- [messageAnnotationsStreamPart.code]: messageAnnotationsStreamPart
680
+ [toolResultStreamPart.code]: toolResultStreamPart
639
681
  };
640
682
  var StreamStringPrefixes = {
641
683
  [textStreamPart.name]: textStreamPart.code,
@@ -645,8 +687,10 @@ var StreamStringPrefixes = {
645
687
  [assistantMessageStreamPart.name]: assistantMessageStreamPart.code,
646
688
  [assistantControlDataStreamPart.name]: assistantControlDataStreamPart.code,
647
689
  [dataMessageStreamPart.name]: dataMessageStreamPart.code,
690
+ [toolCallsStreamPart.name]: toolCallsStreamPart.code,
691
+ [messageAnnotationsStreamPart.name]: messageAnnotationsStreamPart.code,
648
692
  [toolCallStreamPart.name]: toolCallStreamPart.code,
649
- [messageAnnotationsStreamPart.name]: messageAnnotationsStreamPart.code
693
+ [toolResultStreamPart.name]: toolResultStreamPart.code
650
694
  };
651
695
  var validCodes = streamParts.map((part) => part.code);
652
696
  var parseStreamPart = (line) => {
@@ -1170,7 +1214,7 @@ function createStreamableUI(initialValue) {
1170
1214
  }
1171
1215
  }
1172
1216
  warnUnclosedStream();
1173
- return {
1217
+ const streamable2 = {
1174
1218
  /**
1175
1219
  * The value of the streamable UI. This can be returned from a Server Action and received by the client.
1176
1220
  */
@@ -1182,7 +1226,7 @@ function createStreamableUI(initialValue) {
1182
1226
  assertStream(".update()");
1183
1227
  if (value === currentValue) {
1184
1228
  warnUnclosedStream();
1185
- return;
1229
+ return streamable2;
1186
1230
  }
1187
1231
  const resolvable = createResolvablePromise();
1188
1232
  currentValue = value;
@@ -1190,6 +1234,7 @@ function createStreamableUI(initialValue) {
1190
1234
  resolve = resolvable.resolve;
1191
1235
  reject = resolvable.reject;
1192
1236
  warnUnclosedStream();
1237
+ return streamable2;
1193
1238
  },
1194
1239
  /**
1195
1240
  * This method is used to append a new UI node to the end of the old one.
@@ -1215,6 +1260,7 @@ function createStreamableUI(initialValue) {
1215
1260
  resolve = resolvable.resolve;
1216
1261
  reject = resolvable.reject;
1217
1262
  warnUnclosedStream();
1263
+ return streamable2;
1218
1264
  },
1219
1265
  /**
1220
1266
  * This method is used to signal that there is an error in the UI stream.
@@ -1227,6 +1273,7 @@ function createStreamableUI(initialValue) {
1227
1273
  }
1228
1274
  closed = true;
1229
1275
  reject(error);
1276
+ return streamable2;
1230
1277
  },
1231
1278
  /**
1232
1279
  * This method marks the UI node as finalized. You can either call it without any parameters or with a new UI node as the final state.
@@ -1242,11 +1289,13 @@ function createStreamableUI(initialValue) {
1242
1289
  closed = true;
1243
1290
  if (args.length) {
1244
1291
  resolve({ value: args[0], done: true });
1245
- return;
1292
+ return streamable2;
1246
1293
  }
1247
1294
  resolve({ value: currentValue, done: true });
1295
+ return streamable2;
1248
1296
  }
1249
1297
  };
1298
+ return streamable2;
1250
1299
  }
1251
1300
  var STREAMABLE_VALUE_INTERNAL_LOCK = Symbol("streamable.value.lock");
1252
1301
  function createStreamableValue(initialValue) {
@@ -1343,7 +1392,7 @@ function createStreamableValueImpl(initialValue) {
1343
1392
  }
1344
1393
  currentValue = value;
1345
1394
  }
1346
- return {
1395
+ const streamable2 = {
1347
1396
  /**
1348
1397
  * @internal This is an internal lock to prevent the value from being
1349
1398
  * updated by the user.
@@ -1370,6 +1419,7 @@ function createStreamableValueImpl(initialValue) {
1370
1419
  currentPromise = resolvable.promise;
1371
1420
  resolvePrevious(createWrapped());
1372
1421
  warnUnclosedStream();
1422
+ return streamable2;
1373
1423
  },
1374
1424
  /**
1375
1425
  * This method is used to append a delta string to the current value. It
@@ -1407,6 +1457,7 @@ function createStreamableValueImpl(initialValue) {
1407
1457
  currentPromise = resolvable.promise;
1408
1458
  resolvePrevious(createWrapped());
1409
1459
  warnUnclosedStream();
1460
+ return streamable2;
1410
1461
  },
1411
1462
  /**
1412
1463
  * This method is used to signal that there is an error in the value stream.
@@ -1422,6 +1473,7 @@ function createStreamableValueImpl(initialValue) {
1422
1473
  currentError = error;
1423
1474
  currentPromise = void 0;
1424
1475
  resolvable.resolve({ error });
1476
+ return streamable2;
1425
1477
  },
1426
1478
  /**
1427
1479
  * This method marks the value as finalized. You can either call it without
@@ -1441,11 +1493,13 @@ function createStreamableValueImpl(initialValue) {
1441
1493
  if (args.length) {
1442
1494
  updateValueStates(args[0]);
1443
1495
  resolvable.resolve(createWrapped());
1444
- return;
1496
+ return streamable2;
1445
1497
  }
1446
1498
  resolvable.resolve({});
1499
+ return streamable2;
1447
1500
  }
1448
1501
  };
1502
+ return streamable2;
1449
1503
  }
1450
1504
  function render(options) {
1451
1505
  const ui = createStreamableUI(options.initial);