ai 3.4.4 → 3.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -743,6 +743,15 @@ var dataContentSchema = z.union([
743
743
  { message: "Must be a Buffer" }
744
744
  )
745
745
  ]);
746
+ function convertDataContentToBase64String(content) {
747
+ if (typeof content === "string") {
748
+ return content;
749
+ }
750
+ if (content instanceof ArrayBuffer) {
751
+ return convertUint8ArrayToBase64(new Uint8Array(content));
752
+ }
753
+ return convertUint8ArrayToBase64(content);
754
+ }
746
755
  function convertDataContentToUint8Array(content) {
747
756
  if (content instanceof Uint8Array) {
748
757
  return content;
@@ -864,98 +873,119 @@ function convertToLanguageModelMessage(message, downloadedImages) {
864
873
  }
865
874
  return {
866
875
  role: "user",
867
- content: message.content.map((part) => {
868
- var _a11, _b, _c;
869
- switch (part.type) {
870
- case "text": {
871
- return {
872
- type: "text",
873
- text: part.text,
874
- providerMetadata: part.experimental_providerMetadata
875
- };
876
- }
877
- case "image": {
878
- if (part.image instanceof URL) {
879
- if (downloadedImages == null) {
880
- return {
881
- type: "image",
882
- image: part.image,
883
- mimeType: part.mimeType,
884
- providerMetadata: part.experimental_providerMetadata
885
- };
886
- } else {
887
- const downloadedImage = downloadedImages[part.image.toString()];
888
- return {
889
- type: "image",
890
- image: downloadedImage.data,
891
- mimeType: (_a11 = part.mimeType) != null ? _a11 : downloadedImage.mimeType,
892
- providerMetadata: part.experimental_providerMetadata
893
- };
894
- }
876
+ content: message.content.map(
877
+ (part) => {
878
+ var _a11, _b, _c;
879
+ switch (part.type) {
880
+ case "text": {
881
+ return {
882
+ type: "text",
883
+ text: part.text,
884
+ providerMetadata: part.experimental_providerMetadata
885
+ };
895
886
  }
896
- if (typeof part.image === "string") {
897
- try {
898
- const url = new URL(part.image);
899
- switch (url.protocol) {
900
- case "http:":
901
- case "https:": {
902
- if (downloadedImages == null) {
903
- return {
904
- type: "image",
905
- image: url,
906
- mimeType: part.mimeType,
907
- providerMetadata: part.experimental_providerMetadata
908
- };
909
- } else {
910
- const downloadedImage = downloadedImages[part.image];
911
- return {
912
- type: "image",
913
- image: downloadedImage.data,
914
- mimeType: (_b = part.mimeType) != null ? _b : downloadedImage.mimeType,
915
- providerMetadata: part.experimental_providerMetadata
916
- };
887
+ case "image": {
888
+ if (part.image instanceof URL) {
889
+ if (downloadedImages == null) {
890
+ return {
891
+ type: "image",
892
+ image: part.image,
893
+ mimeType: part.mimeType,
894
+ providerMetadata: part.experimental_providerMetadata
895
+ };
896
+ } else {
897
+ const downloadedImage = downloadedImages[part.image.toString()];
898
+ return {
899
+ type: "image",
900
+ image: downloadedImage.data,
901
+ mimeType: (_a11 = part.mimeType) != null ? _a11 : downloadedImage.mimeType,
902
+ providerMetadata: part.experimental_providerMetadata
903
+ };
904
+ }
905
+ }
906
+ if (typeof part.image === "string") {
907
+ try {
908
+ const url = new URL(part.image);
909
+ switch (url.protocol) {
910
+ case "http:":
911
+ case "https:": {
912
+ if (downloadedImages == null) {
913
+ return {
914
+ type: "image",
915
+ image: url,
916
+ mimeType: part.mimeType,
917
+ providerMetadata: part.experimental_providerMetadata
918
+ };
919
+ } else {
920
+ const downloadedImage = downloadedImages[part.image];
921
+ return {
922
+ type: "image",
923
+ image: downloadedImage.data,
924
+ mimeType: (_b = part.mimeType) != null ? _b : downloadedImage.mimeType,
925
+ providerMetadata: part.experimental_providerMetadata
926
+ };
927
+ }
917
928
  }
918
- }
919
- case "data:": {
920
- try {
921
- const [header, base64Content] = part.image.split(",");
922
- const mimeType = header.split(";")[0].split(":")[1];
923
- if (mimeType == null || base64Content == null) {
924
- throw new Error("Invalid data URL format");
929
+ case "data:": {
930
+ try {
931
+ const [header, base64Content] = part.image.split(",");
932
+ const mimeType = header.split(";")[0].split(":")[1];
933
+ if (mimeType == null || base64Content == null) {
934
+ throw new Error("Invalid data URL format");
935
+ }
936
+ return {
937
+ type: "image",
938
+ image: convertDataContentToUint8Array(base64Content),
939
+ mimeType,
940
+ providerMetadata: part.experimental_providerMetadata
941
+ };
942
+ } catch (error) {
943
+ throw new Error(
944
+ `Error processing data URL: ${getErrorMessage2(
945
+ message
946
+ )}`
947
+ );
925
948
  }
926
- return {
927
- type: "image",
928
- image: convertDataContentToUint8Array(base64Content),
929
- mimeType,
930
- providerMetadata: part.experimental_providerMetadata
931
- };
932
- } catch (error) {
949
+ }
950
+ default: {
933
951
  throw new Error(
934
- `Error processing data URL: ${getErrorMessage2(
935
- message
936
- )}`
952
+ `Unsupported URL protocol: ${url.protocol}`
937
953
  );
938
954
  }
939
955
  }
940
- default: {
941
- throw new Error(
942
- `Unsupported URL protocol: ${url.protocol}`
943
- );
944
- }
956
+ } catch (_ignored) {
945
957
  }
946
- } catch (_ignored) {
947
958
  }
959
+ const imageUint8 = convertDataContentToUint8Array(part.image);
960
+ return {
961
+ type: "image",
962
+ image: imageUint8,
963
+ mimeType: (_c = part.mimeType) != null ? _c : detectImageMimeType(imageUint8),
964
+ providerMetadata: part.experimental_providerMetadata
965
+ };
966
+ }
967
+ case "file": {
968
+ if (part.data instanceof URL) {
969
+ return {
970
+ type: "file",
971
+ data: part.data,
972
+ mimeType: part.mimeType,
973
+ providerMetadata: part.experimental_providerMetadata
974
+ };
975
+ }
976
+ const imageBase64 = convertDataContentToBase64String(
977
+ part.data
978
+ );
979
+ return {
980
+ type: "file",
981
+ data: imageBase64,
982
+ mimeType: part.mimeType,
983
+ providerMetadata: part.experimental_providerMetadata
984
+ };
948
985
  }
949
- const imageUint8 = convertDataContentToUint8Array(part.image);
950
- return {
951
- type: "image",
952
- image: imageUint8,
953
- mimeType: (_c = part.mimeType) != null ? _c : detectImageMimeType(imageUint8),
954
- providerMetadata: part.experimental_providerMetadata
955
- };
956
986
  }
957
987
  }
958
- }).filter((part) => part.type !== "text" || part.text !== ""),
988
+ ).filter((part) => part.type !== "text" || part.text !== ""),
959
989
  providerMetadata: message.experimental_providerMetadata
960
990
  };
961
991
  }
@@ -1216,6 +1246,12 @@ var imagePartSchema = z4.object({
1216
1246
  mimeType: z4.string().optional(),
1217
1247
  experimental_providerMetadata: providerMetadataSchema.optional()
1218
1248
  });
1249
+ var filePartSchema = z4.object({
1250
+ type: z4.literal("file"),
1251
+ data: z4.union([dataContentSchema, z4.instanceof(URL)]),
1252
+ mimeType: z4.string(),
1253
+ experimental_providerMetadata: providerMetadataSchema.optional()
1254
+ });
1219
1255
  var toolCallPartSchema = z4.object({
1220
1256
  type: z4.literal("tool-call"),
1221
1257
  toolCallId: z4.string(),
@@ -1241,7 +1277,7 @@ var coreUserMessageSchema = z5.object({
1241
1277
  role: z5.literal("user"),
1242
1278
  content: z5.union([
1243
1279
  z5.string(),
1244
- z5.array(z5.union([textPartSchema, imagePartSchema]))
1280
+ z5.array(z5.union([textPartSchema, imagePartSchema, filePartSchema]))
1245
1281
  ]),
1246
1282
  experimental_providerMetadata: providerMetadataSchema.optional()
1247
1283
  });
@@ -3203,7 +3239,8 @@ async function generateText({
3203
3239
  ...currentModelResponse.response,
3204
3240
  headers: (_d = currentModelResponse.rawResponse) == null ? void 0 : _d.headers
3205
3241
  },
3206
- experimental_providerMetadata: currentModelResponse.providerMetadata
3242
+ experimental_providerMetadata: currentModelResponse.providerMetadata,
3243
+ isContinued: nextStepType === "continue"
3207
3244
  };
3208
3245
  steps.push(currentStep);
3209
3246
  await (onStepFinish == null ? void 0 : onStepFinish(currentStep));
@@ -4143,7 +4180,8 @@ var DefaultStreamTextResult = class {
4143
4180
  usage: stepUsage,
4144
4181
  experimental_providerMetadata: stepProviderMetadata,
4145
4182
  logprobs: stepLogProbs,
4146
- response: stepResponse
4183
+ response: stepResponse,
4184
+ isContinued: nextStepType === "continue"
4147
4185
  });
4148
4186
  const stepResult = {
4149
4187
  stepType,
@@ -4156,7 +4194,8 @@ var DefaultStreamTextResult = class {
4156
4194
  logprobs: stepLogProbs,
4157
4195
  response: stepResponse,
4158
4196
  rawResponse: self.rawResponse,
4159
- experimental_providerMetadata: stepProviderMetadata
4197
+ experimental_providerMetadata: stepProviderMetadata,
4198
+ isContinued: nextStepType === "continue"
4160
4199
  };
4161
4200
  stepResults.push(stepResult);
4162
4201
  await (onStepFinish == null ? void 0 : onStepFinish(stepResult));
@@ -4432,7 +4471,8 @@ var DefaultStreamTextResult = class {
4432
4471
  usage: sendUsage ? {
4433
4472
  promptTokens: chunk.usage.promptTokens,
4434
4473
  completionTokens: chunk.usage.completionTokens
4435
- } : void 0
4474
+ } : void 0,
4475
+ isContinued: chunk.isContinued
4436
4476
  })
4437
4477
  );
4438
4478
  break;