@ai-sdk/google 3.0.89 → 3.0.90

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
@@ -7,7 +7,7 @@ import {
7
7
  } from "@ai-sdk/provider-utils";
8
8
 
9
9
  // src/version.ts
10
- var VERSION = true ? "3.0.89" : "0.0.0-test";
10
+ var VERSION = true ? "3.0.90" : "0.0.0-test";
11
11
 
12
12
  // src/google-generative-ai-embedding-model.ts
13
13
  import {
@@ -730,7 +730,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
730
730
  name: part.toolName,
731
731
  response: {
732
732
  name: part.toolName,
733
- content: output.type === "execution-denied" ? (_e = output.reason) != null ? _e : "Tool execution denied." : output.value
733
+ content: output.type === "execution-denied" ? (_e = output.reason) != null ? _e : "Tool call execution denied." : output.value
734
734
  }
735
735
  }
736
736
  });
@@ -3326,6 +3326,19 @@ function convertGoogleInteractionsUsage(usage) {
3326
3326
  raw: usage
3327
3327
  };
3328
3328
  }
3329
+ function getGoogleInteractionsOutputTokensByModality(usage) {
3330
+ const byModality = usage == null ? void 0 : usage.output_tokens_by_modality;
3331
+ if (byModality == null) {
3332
+ return void 0;
3333
+ }
3334
+ const result = {};
3335
+ for (const entry of byModality) {
3336
+ if ((entry == null ? void 0 : entry.modality) != null && entry.tokens != null) {
3337
+ result[entry.modality] = entry.tokens;
3338
+ }
3339
+ }
3340
+ return Object.keys(result).length > 0 ? result : void 0;
3341
+ }
3329
3342
 
3330
3343
  // src/interactions/extract-google-interactions-sources.ts
3331
3344
  var KNOWN_DOC_EXTENSIONS = {
@@ -3577,7 +3590,7 @@ function buildGoogleInteractionsStreamTransform({
3577
3590
  controller.enqueue({ type: "stream-start", warnings });
3578
3591
  },
3579
3592
  transform(chunk, controller) {
3580
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
3593
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
3581
3594
  if (includeRawChunks) {
3582
3595
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
3583
3596
  }
@@ -3766,9 +3779,37 @@ function buildGoogleInteractionsStreamTransform({
3766
3779
  }
3767
3780
  break;
3768
3781
  }
3782
+ if (dtype === "video" && (open.kind === "pending_model_output" || open.kind === "text")) {
3783
+ const videoDelta = event.delta;
3784
+ const google2 = {};
3785
+ if (interactionId != null) google2.interactionId = interactionId;
3786
+ const providerMetadata = Object.keys(google2).length > 0 ? { google: google2 } : void 0;
3787
+ if ((videoDelta == null ? void 0 : videoDelta.data) != null && videoDelta.data.length > 0) {
3788
+ controller.enqueue({
3789
+ type: "file",
3790
+ mediaType: (_m = videoDelta.mime_type) != null ? _m : "video/mp4",
3791
+ data: videoDelta.data,
3792
+ ...providerMetadata ? { providerMetadata } : {}
3793
+ });
3794
+ } else if ((videoDelta == null ? void 0 : videoDelta.uri) != null && videoDelta.uri.length > 0) {
3795
+ const uriProviderMetadata = {
3796
+ google: {
3797
+ ...interactionId != null ? { interactionId } : {},
3798
+ videoUri: videoDelta.uri
3799
+ }
3800
+ };
3801
+ controller.enqueue({
3802
+ type: "file",
3803
+ mediaType: (_n = videoDelta.mime_type) != null ? _n : "video/mp4",
3804
+ data: "",
3805
+ providerMetadata: uriProviderMetadata
3806
+ });
3807
+ }
3808
+ break;
3809
+ }
3769
3810
  const delta = event.delta;
3770
3811
  if (open.kind === "text" && (delta == null ? void 0 : delta.type) === "text") {
3771
- const text = (_m = delta.text) != null ? _m : "";
3812
+ const text = (_o = delta.text) != null ? _o : "";
3772
3813
  if (text.length > 0) {
3773
3814
  controller.enqueue({
3774
3815
  type: "text-delta",
@@ -3871,7 +3912,7 @@ function buildGoogleInteractionsStreamTransform({
3871
3912
  if (open.data != null && open.data.length > 0) {
3872
3913
  controller.enqueue({
3873
3914
  type: "file",
3874
- mediaType: (_n = open.mimeType) != null ? _n : "image/png",
3915
+ mediaType: (_p = open.mimeType) != null ? _p : "image/png",
3875
3916
  data: open.data,
3876
3917
  ...providerMetadata ? { providerMetadata } : {}
3877
3918
  });
@@ -3884,7 +3925,7 @@ function buildGoogleInteractionsStreamTransform({
3884
3925
  };
3885
3926
  controller.enqueue({
3886
3927
  type: "file",
3887
- mediaType: (_o = open.mimeType) != null ? _o : "image/png",
3928
+ mediaType: (_q = open.mimeType) != null ? _q : "image/png",
3888
3929
  data: "",
3889
3930
  providerMetadata: uriProviderMetadata
3890
3931
  });
@@ -3911,7 +3952,7 @@ function buildGoogleInteractionsStreamTransform({
3911
3952
  type: "tool-call",
3912
3953
  toolCallId: open.toolCallId,
3913
3954
  toolName: open.toolName,
3914
- input: JSON.stringify((_p = open.arguments) != null ? _p : {}),
3955
+ input: JSON.stringify((_r = open.arguments) != null ? _r : {}),
3915
3956
  providerExecuted: true
3916
3957
  });
3917
3958
  open.callEmitted = true;
@@ -3920,7 +3961,7 @@ function buildGoogleInteractionsStreamTransform({
3920
3961
  type: "tool-result",
3921
3962
  toolCallId: open.callId,
3922
3963
  toolName: open.toolName,
3923
- result: (_q = open.result) != null ? _q : null
3964
+ result: (_s = open.result) != null ? _s : null
3924
3965
  });
3925
3966
  open.resultEmitted = true;
3926
3967
  const sources = builtinToolResultToSources({
@@ -3974,7 +4015,7 @@ function buildGoogleInteractionsStreamTransform({
3974
4015
  case "error": {
3975
4016
  const event = value;
3976
4017
  finishStatus = "failed";
3977
- const errorPayload = (_r = event.error) != null ? _r : {
4018
+ const errorPayload = (_t = event.error) != null ? _t : {
3978
4019
  message: "Unknown interaction error"
3979
4020
  };
3980
4021
  controller.enqueue({ type: "error", error: errorPayload });
@@ -3992,10 +4033,12 @@ function buildGoogleInteractionsStreamTransform({
3992
4033
  }),
3993
4034
  raw: finishStatus
3994
4035
  };
4036
+ const outputTokensByModality = getGoogleInteractionsOutputTokensByModality(usage);
3995
4037
  const providerMetadata = {
3996
4038
  google: {
3997
4039
  ...interactionId != null ? { interactionId } : {},
3998
- ...serviceTier != null ? { serviceTier } : {}
4040
+ ...serviceTier != null ? { serviceTier } : {},
4041
+ ...outputTokensByModality != null ? { outputTokensByModality } : {}
3999
4042
  }
4000
4043
  };
4001
4044
  controller.enqueue({
@@ -4487,9 +4530,16 @@ var contentBlockSchema = () => {
4487
4530
  resolution: z15.enum(["low", "medium", "high", "ultra_high"]).nullish(),
4488
4531
  uri: z15.string().nullish()
4489
4532
  }).loose();
4533
+ const videoContent = z15.object({
4534
+ type: z15.literal("video"),
4535
+ data: z15.string().nullish(),
4536
+ mime_type: z15.string().nullish(),
4537
+ uri: z15.string().nullish()
4538
+ }).loose();
4490
4539
  return z15.union([
4491
4540
  textContent,
4492
4541
  imageContent,
4542
+ videoContent,
4493
4543
  z15.object({ type: z15.string() }).loose()
4494
4544
  ]);
4495
4545
  };
@@ -4636,6 +4686,12 @@ var googleInteractionsEventSchema = lazySchema13(
4636
4686
  resolution: z15.enum(["low", "medium", "high", "ultra_high"]).nullish(),
4637
4687
  uri: z15.string().nullish()
4638
4688
  }).loose();
4689
+ const stepDeltaVideo = z15.object({
4690
+ type: z15.literal("video"),
4691
+ data: z15.string().nullish(),
4692
+ mime_type: z15.string().nullish(),
4693
+ uri: z15.string().nullish()
4694
+ }).loose();
4639
4695
  const stepDeltaBuiltinToolCall = z15.object({
4640
4696
  type: z15.enum(BUILTIN_TOOL_CALL_STEP_TYPES),
4641
4697
  id: z15.string().nullish(),
@@ -4658,6 +4714,7 @@ var googleInteractionsEventSchema = lazySchema13(
4658
4714
  const stepDeltaUnion = z15.union([
4659
4715
  stepDeltaText,
4660
4716
  stepDeltaImage,
4717
+ stepDeltaVideo,
4661
4718
  stepDeltaThoughtSummary,
4662
4719
  stepDeltaThoughtSignature,
4663
4720
  stepDeltaArgumentsDelta,
@@ -4949,7 +5006,7 @@ function parseGoogleInteractionsOutputs({
4949
5006
  generateId: generateId3,
4950
5007
  interactionId
4951
5008
  }) {
4952
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
5009
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
4953
5010
  const content = [];
4954
5011
  let hasFunctionCall = false;
4955
5012
  if (steps == null) {
@@ -5002,6 +5059,28 @@ function parseGoogleInteractionsOutputs({
5002
5059
  }
5003
5060
  });
5004
5061
  }
5062
+ } else if (blockType === "video") {
5063
+ const video = block;
5064
+ if (video.data != null && video.data.length > 0) {
5065
+ content.push({
5066
+ type: "file",
5067
+ mediaType: (_e = video.mime_type) != null ? _e : "video/mp4",
5068
+ data: video.data,
5069
+ ...googleProviderMetadata({ interactionId })
5070
+ });
5071
+ } else if (video.uri != null && video.uri.length > 0) {
5072
+ content.push({
5073
+ type: "file",
5074
+ mediaType: (_f = video.mime_type) != null ? _f : "video/mp4",
5075
+ data: "",
5076
+ providerMetadata: {
5077
+ google: {
5078
+ ...interactionId != null ? { interactionId } : {},
5079
+ videoUri: video.uri
5080
+ }
5081
+ }
5082
+ });
5083
+ }
5005
5084
  }
5006
5085
  }
5007
5086
  break;
@@ -5029,7 +5108,7 @@ function parseGoogleInteractionsOutputs({
5029
5108
  type: "tool-call",
5030
5109
  toolCallId: call.id,
5031
5110
  toolName: call.name,
5032
- input: JSON.stringify((_e = call.arguments) != null ? _e : {}),
5111
+ input: JSON.stringify((_g = call.arguments) != null ? _g : {}),
5033
5112
  ...googleProviderMetadata({
5034
5113
  signature: call.signature,
5035
5114
  interactionId
@@ -5040,23 +5119,23 @@ function parseGoogleInteractionsOutputs({
5040
5119
  default: {
5041
5120
  if (BUILTIN_TOOL_CALL_TYPES2.has(type)) {
5042
5121
  const call = step;
5043
- const toolName = type === "mcp_server_tool_call" ? (_f = call.name) != null ? _f : "mcp_server_tool" : builtinToolNameFromCallType2(type);
5044
- const input = JSON.stringify((_g = call.arguments) != null ? _g : {});
5122
+ const toolName = type === "mcp_server_tool_call" ? (_h = call.name) != null ? _h : "mcp_server_tool" : builtinToolNameFromCallType2(type);
5123
+ const input = JSON.stringify((_i = call.arguments) != null ? _i : {});
5045
5124
  content.push({
5046
5125
  type: "tool-call",
5047
- toolCallId: (_h = call.id) != null ? _h : generateId3(),
5126
+ toolCallId: (_j = call.id) != null ? _j : generateId3(),
5048
5127
  toolName,
5049
5128
  input,
5050
5129
  providerExecuted: true
5051
5130
  });
5052
5131
  } else if (BUILTIN_TOOL_RESULT_TYPES2.has(type)) {
5053
5132
  const result = step;
5054
- const toolName = type === "mcp_server_tool_result" ? (_i = result.name) != null ? _i : "mcp_server_tool" : builtinToolNameFromResultType2(type);
5133
+ const toolName = type === "mcp_server_tool_result" ? (_k = result.name) != null ? _k : "mcp_server_tool" : builtinToolNameFromResultType2(type);
5055
5134
  content.push({
5056
5135
  type: "tool-result",
5057
- toolCallId: (_j = result.call_id) != null ? _j : generateId3(),
5136
+ toolCallId: (_l = result.call_id) != null ? _l : generateId3(),
5058
5137
  toolName,
5059
- result: (_k = result.result) != null ? _k : null
5138
+ result: (_m = result.result) != null ? _m : null
5060
5139
  });
5061
5140
  const sources = builtinToolResultToSources({
5062
5141
  block: step,
@@ -5954,10 +6033,14 @@ var GoogleInteractionsLanguageModel = class {
5954
6033
  raw: response.status
5955
6034
  };
5956
6035
  const serviceTier = (_e = (_d = response.service_tier) != null ? _d : responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _e : void 0;
6036
+ const outputTokensByModality = getGoogleInteractionsOutputTokensByModality(
6037
+ response.usage
6038
+ );
5957
6039
  const providerMetadata = {
5958
6040
  google: {
5959
6041
  ...interactionId != null ? { interactionId } : {},
5960
- ...serviceTier != null ? { serviceTier } : {}
6042
+ ...serviceTier != null ? { serviceTier } : {},
6043
+ ...outputTokensByModality != null ? { outputTokensByModality } : {}
5961
6044
  }
5962
6045
  };
5963
6046
  let timestamp;
@@ -6121,6 +6204,34 @@ function pruneUndefined(obj) {
6121
6204
  }
6122
6205
 
6123
6206
  // src/google-provider.ts
6207
+ var supportedExternalUrlMediaTypes = [
6208
+ "text/html",
6209
+ "text/css",
6210
+ "text/plain",
6211
+ "text/xml",
6212
+ "text/csv",
6213
+ "text/rtf",
6214
+ "text/javascript",
6215
+ "application/json",
6216
+ "application/pdf",
6217
+ "image/bmp",
6218
+ "image/jpeg",
6219
+ "image/png",
6220
+ "image/webp",
6221
+ "video/mp4",
6222
+ "video/mpeg",
6223
+ "video/quicktime",
6224
+ "video/avi",
6225
+ "video/x-flv",
6226
+ "video/mpg",
6227
+ "video/webm",
6228
+ "video/wmv",
6229
+ "video/3gpp"
6230
+ ];
6231
+ var externalHttpsUrlPattern = /^https:\/\/.*$/;
6232
+ function supportsExternalFileUrls(modelId) {
6233
+ return /(^|\/)gemini-/.test(modelId) && !/(^|\/)gemini-2\.0/.test(modelId);
6234
+ }
6124
6235
  function createGoogleGenerativeAI(options = {}) {
6125
6236
  var _a, _b;
6126
6237
  const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
@@ -6153,7 +6264,13 @@ function createGoogleGenerativeAI(options = {}) {
6153
6264
  `^https://(?:www\\.)?youtube\\.com/watch\\?v=[\\w-]+(?:&[\\w=&.-]*)?$`
6154
6265
  ),
6155
6266
  new RegExp(`^https://youtu\\.be/[\\w-]+(?:\\?[\\w=&.-]*)?$`)
6156
- ]
6267
+ ],
6268
+ ...supportsExternalFileUrls(modelId) ? Object.fromEntries(
6269
+ supportedExternalUrlMediaTypes.map((mediaType) => [
6270
+ mediaType,
6271
+ [externalHttpsUrlPattern]
6272
+ ])
6273
+ ) : {}
6157
6274
  }),
6158
6275
  fetch: options.fetch
6159
6276
  });