@ai-sdk/google-vertex 5.0.92 → 5.0.95

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.js CHANGED
@@ -9,10 +9,9 @@ function createAuthTokenGenerator(options) {
9
9
  ...options
10
10
  });
11
11
  return async function generateAuthToken() {
12
- var _a;
13
12
  const client = await auth.getClient();
14
13
  const token = await client.getAccessToken();
15
- return (_a = token == null ? void 0 : token.token) != null ? _a : null;
14
+ return token?.token ?? null;
16
15
  };
17
16
  }
18
17
 
@@ -33,7 +32,7 @@ import {
33
32
  } from "@ai-sdk/provider-utils";
34
33
 
35
34
  // src/version.ts
36
- var VERSION = true ? "5.0.92" : "0.0.0-test";
35
+ var VERSION = true ? "5.0.95" : "0.0.0-test";
37
36
 
38
37
  // src/google-vertex-embedding-model.ts
39
38
  import {
@@ -142,7 +141,6 @@ var GoogleVertexEmbeddingModel = class _GoogleVertexEmbeddingModel {
142
141
  abortSignal,
143
142
  providerOptions
144
143
  }) {
145
- var _a;
146
144
  let googleOptions = await parseProviderOptions({
147
145
  provider: "googleVertex",
148
146
  providerOptions,
@@ -162,7 +160,7 @@ var GoogleVertexEmbeddingModel = class _GoogleVertexEmbeddingModel {
162
160
  schema: googleVertexEmbeddingModelOptions
163
161
  });
164
162
  }
165
- googleOptions = googleOptions != null ? googleOptions : {};
163
+ googleOptions = googleOptions ?? {};
166
164
  if (values.length > this.maxEmbeddingsPerCall) {
167
165
  throw new TooManyEmbeddingValuesForCallError({
168
166
  provider: this.provider,
@@ -202,7 +200,7 @@ var GoogleVertexEmbeddingModel = class _GoogleVertexEmbeddingModel {
202
200
  return {
203
201
  warnings: [],
204
202
  embeddings: [response2.embedding.values],
205
- usage: ((_a = response2.usageMetadata) == null ? void 0 : _a.promptTokenCount) == null ? void 0 : { tokens: response2.usageMetadata.promptTokenCount },
203
+ usage: response2.usageMetadata?.promptTokenCount == null ? void 0 : { tokens: response2.usageMetadata.promptTokenCount },
206
204
  response: { headers: responseHeaders2, body: rawValue2 }
207
205
  };
208
206
  }
@@ -300,7 +298,6 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
300
298
  return this.config.provider;
301
299
  }
302
300
  async doGenerate(options) {
303
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
304
301
  if (!this.modelId.startsWith("gemini-")) {
305
302
  throw new Error(
306
303
  "Google image models other than Gemini are no longer supported. Use a model ID that starts with `gemini-`."
@@ -360,9 +357,9 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
360
357
  const languageModel = new GoogleLanguageModel(this.modelId, {
361
358
  provider: this.config.provider,
362
359
  baseURL: this.config.baseURL,
363
- headers: (_a = this.config.headers) != null ? _a : {},
360
+ headers: this.config.headers ?? {},
364
361
  fetch: this.config.fetch,
365
- generateId: (_b = this.config.generateId) != null ? _b : defaultGenerateId,
362
+ generateId: this.config.generateId ?? defaultGenerateId,
366
363
  supportedUrls: () => ({
367
364
  "*": [/^https?:\/\/.*$/, /^gs:\/\/.*$/]
368
365
  })
@@ -371,7 +368,7 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
371
368
  responseModalities: _strippedResponseModalities,
372
369
  imageConfig: userImageConfig,
373
370
  ...userVertexOptions
374
- } = (_d = (_c = providerOptions == null ? void 0 : providerOptions.googleVertex) != null ? _c : providerOptions == null ? void 0 : providerOptions.vertex) != null ? _d : {};
371
+ } = providerOptions?.googleVertex ?? providerOptions?.vertex ?? {};
375
372
  const innerVertexOptions = {
376
373
  ...userVertexOptions,
377
374
  responseModalities: ["IMAGE"],
@@ -392,7 +389,7 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
392
389
  headers,
393
390
  abortSignal
394
391
  });
395
- const currentDate = (_g = (_f = (_e = this.config._internal) == null ? void 0 : _e.currentDate) == null ? void 0 : _f.call(_e)) != null ? _g : /* @__PURE__ */ new Date();
392
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
396
393
  const images = [];
397
394
  for (const part of result.content) {
398
395
  if (part.type === "file" && part.mediaType.startsWith("image/") && part.data.type === "data") {
@@ -413,12 +410,12 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
413
410
  response: {
414
411
  timestamp: currentDate,
415
412
  modelId: this.modelId,
416
- headers: (_h = result.response) == null ? void 0 : _h.headers
413
+ headers: result.response?.headers
417
414
  },
418
415
  usage: result.usage ? {
419
416
  inputTokens: result.usage.inputTokens.total,
420
417
  outputTokens: result.usage.outputTokens.total,
421
- totalTokens: ((_i = result.usage.inputTokens.total) != null ? _i : 0) + ((_j = result.usage.outputTokens.total) != null ? _j : 0)
418
+ totalTokens: (result.usage.inputTokens.total ?? 0) + (result.usage.outputTokens.total ?? 0)
422
419
  } : void 0
423
420
  };
424
421
  }
@@ -459,8 +456,7 @@ var GoogleVertexCloudTTSSpeechModel = class _GoogleVertexCloudTTSSpeechModel {
459
456
  return this.config.provider;
460
457
  }
461
458
  async doGenerate(options) {
462
- var _a, _b, _c;
463
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
459
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
464
460
  const warnings = [];
465
461
  const {
466
462
  text,
@@ -475,9 +471,9 @@ var GoogleVertexCloudTTSSpeechModel = class _GoogleVertexCloudTTSSpeechModel {
475
471
  if (voice.includes(CHIRP3_HD_VOICE_INFIX)) {
476
472
  voiceName = voice;
477
473
  const localePrefix = voice.split(CHIRP3_HD_VOICE_INFIX)[0].replace(/-$/, "");
478
- languageCode = language != null ? language : localePrefix || DEFAULT_LANGUAGE;
474
+ languageCode = language ?? (localePrefix || DEFAULT_LANGUAGE);
479
475
  } else {
480
- languageCode = language != null ? language : DEFAULT_LANGUAGE;
476
+ languageCode = language ?? DEFAULT_LANGUAGE;
481
477
  voiceName = `${languageCode}-${CHIRP3_HD_VOICE_INFIX}-${voice}`;
482
478
  }
483
479
  if (instructions != null) {
@@ -618,7 +614,7 @@ function convertBcp47ToIso6391(value) {
618
614
  try {
619
615
  const language = new Intl.Locale(value).language;
620
616
  return language.length === 2 ? language : void 0;
621
- } catch (e) {
617
+ } catch {
622
618
  return void 0;
623
619
  }
624
620
  }
@@ -641,8 +637,7 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
641
637
  return this.config.provider;
642
638
  }
643
639
  async doGenerate(options) {
644
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
645
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
640
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
646
641
  const warnings = [];
647
642
  let googleOptions;
648
643
  for (const provider of ["googleVertex", "vertex", "google"]) {
@@ -655,8 +650,8 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
655
650
  break;
656
651
  }
657
652
  }
658
- const region = (_d = googleOptions == null ? void 0 : googleOptions.region) != null ? _d : this.config.location;
659
- const languageCodes = (_e = googleOptions == null ? void 0 : googleOptions.languageCodes) != null ? _e : ["auto"];
653
+ const region = googleOptions?.region ?? this.config.location;
654
+ const languageCodes = googleOptions?.languageCodes ?? ["auto"];
660
655
  const content = typeof options.audio === "string" ? options.audio : convertUint8ArrayToBase64(options.audio);
661
656
  const requestBody = {
662
657
  config: {
@@ -666,8 +661,8 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
666
661
  autoDecodingConfig: {},
667
662
  features: {
668
663
  // Word timing populates `segments`.
669
- enableWordTimeOffsets: (_f = googleOptions == null ? void 0 : googleOptions.enableWordTimeOffsets) != null ? _f : true,
670
- enableAutomaticPunctuation: (_g = googleOptions == null ? void 0 : googleOptions.enableAutomaticPunctuation) != null ? _g : true
664
+ enableWordTimeOffsets: googleOptions?.enableWordTimeOffsets ?? true,
665
+ enableAutomaticPunctuation: googleOptions?.enableAutomaticPunctuation ?? true
671
666
  }
672
667
  },
673
668
  content
@@ -692,28 +687,22 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
692
687
  abortSignal: options.abortSignal,
693
688
  fetch: this.config.fetch
694
689
  });
695
- const results = (_h = response.results) != null ? _h : [];
696
- const text = results.map((result) => {
697
- var _a2, _b2, _c2;
698
- return (_c2 = (_b2 = (_a2 = result.alternatives) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.transcript) != null ? _c2 : "";
699
- }).join(" ").trim();
690
+ const results = response.results ?? [];
691
+ const text = results.map((result) => result.alternatives?.[0]?.transcript ?? "").join(" ").trim();
700
692
  const segments = results.flatMap(
701
- (result) => {
702
- var _a2, _b2, _c2, _d2;
703
- return (_d2 = (_c2 = (_b2 = (_a2 = result.alternatives) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.words) == null ? void 0 : _c2.flatMap((word) => {
704
- const startSecond = parseDurationSeconds(word.startOffset);
705
- const endSecond = parseDurationSeconds(word.endOffset);
706
- return word.word == null || startSecond == null || endSecond == null ? [] : [{ text: word.word, startSecond, endSecond }];
707
- })) != null ? _d2 : [];
708
- }
693
+ (result) => result.alternatives?.[0]?.words?.flatMap((word) => {
694
+ const startSecond = parseDurationSeconds(word.startOffset);
695
+ const endSecond = parseDurationSeconds(word.endOffset);
696
+ return word.word == null || startSecond == null || endSecond == null ? [] : [{ text: word.word, startSecond, endSecond }];
697
+ }) ?? []
709
698
  );
710
- const language = convertBcp47ToIso6391((_i = results[0]) == null ? void 0 : _i.languageCode);
699
+ const language = convertBcp47ToIso6391(results[0]?.languageCode);
711
700
  return {
712
701
  text,
713
702
  segments,
714
703
  language,
715
704
  durationInSeconds: parseDurationSeconds(
716
- (_j = response.metadata) == null ? void 0 : _j.totalBilledDuration
705
+ response.metadata?.totalBilledDuration
717
706
  ),
718
707
  warnings,
719
708
  response: {
@@ -846,14 +835,13 @@ var GoogleVertexGeminiTranscriptionModel = class _GoogleVertexGeminiTranscriptio
846
835
  }
847
836
  }
848
837
  async doGenerate(options) {
849
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
850
838
  if (isLiveTranscriptionModelId(this.modelId)) {
851
839
  throw new InvalidArgumentError({
852
840
  argument: "modelId",
853
841
  message: `Model '${this.modelId}' only supports streaming transcription. Use experimental_streamTranscribe, or a unary model such as 'gemini-3.5-transcribe'.`
854
842
  });
855
843
  }
856
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
844
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
857
845
  const warnings = [];
858
846
  const googleOptions = await this.parseOptions(options.providerOptions);
859
847
  const audioTranscriptionConfig = buildAudioTranscriptionConfig(googleOptions);
@@ -891,23 +879,17 @@ var GoogleVertexGeminiTranscriptionModel = class _GoogleVertexGeminiTranscriptio
891
879
  abortSignal: options.abortSignal,
892
880
  fetch: this.config.fetch
893
881
  });
894
- const parts = (_g = (_f = (_e = (_d = response.candidates) == null ? void 0 : _d[0]) == null ? void 0 : _e.content) == null ? void 0 : _f.parts) != null ? _g : [];
895
- const plainText = parts.map((part) => {
896
- var _a2;
897
- return (_a2 = part.text) != null ? _a2 : "";
898
- }).join("");
899
- const transcriptionText = parts.map((part) => {
900
- var _a2, _b2;
901
- return (_b2 = (_a2 = part.audioTranscription) == null ? void 0 : _a2.text) != null ? _b2 : "";
902
- }).join("");
882
+ const parts = response.candidates?.[0]?.content?.parts ?? [];
883
+ const plainText = parts.map((part) => part.text ?? "").join("");
884
+ const transcriptionText = parts.map((part) => part.audioTranscription?.text ?? "").join("");
903
885
  const text = plainText !== "" ? plainText : transcriptionText;
904
886
  let language;
905
887
  const segments = [];
906
888
  for (const part of parts) {
907
889
  const transcription = part.audioTranscription;
908
890
  if (transcription == null) continue;
909
- language != null ? language : language = (_h = transcription.languageCode) != null ? _h : void 0;
910
- for (const word of (_i = transcription.words) != null ? _i : []) {
891
+ language ??= transcription.languageCode ?? void 0;
892
+ for (const word of transcription.words ?? []) {
911
893
  const startSecond = parseOffsetSeconds(word.startOffset);
912
894
  const endSecond = parseOffsetSeconds(word.endOffset);
913
895
  if (word.word == null || startSecond == null || endSecond == null) {
@@ -936,14 +918,13 @@ var GoogleVertexGeminiTranscriptionModel = class _GoogleVertexGeminiTranscriptio
936
918
  };
937
919
  }
938
920
  async doStream(options) {
939
- var _a, _b, _c, _d, _e, _f, _g;
940
921
  if (!isLiveTranscriptionModelId(this.modelId)) {
941
922
  throw new InvalidArgumentError({
942
923
  argument: "modelId",
943
924
  message: `Model '${this.modelId}' does not support streaming transcription. Use a live model such as 'gemini-3.5-transcribe-live'.`
944
925
  });
945
926
  }
946
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
927
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
947
928
  const warnings = [];
948
929
  const googleOptions = await this.parseOptions(options.providerOptions);
949
930
  validateLiveInputAudioFormat(options.inputAudioFormat);
@@ -958,7 +939,7 @@ var GoogleVertexGeminiTranscriptionModel = class _GoogleVertexGeminiTranscriptio
958
939
  );
959
940
  const setup = {
960
941
  model: modelResource,
961
- inputAudioTranscription: (_d = buildAudioTranscriptionConfig(googleOptions)) != null ? _d : {}
942
+ inputAudioTranscription: buildAudioTranscriptionConfig(googleOptions) ?? {}
962
943
  };
963
944
  return {
964
945
  request: { body: setup },
@@ -971,8 +952,8 @@ var GoogleVertexGeminiTranscriptionModel = class _GoogleVertexGeminiTranscriptio
971
952
  url,
972
953
  headers,
973
954
  setup,
974
- inputAudioRate: (_e = options.inputAudioFormat.rate) != null ? _e : 16e3,
975
- finishGraceMs: (_g = (_f = this.config._internal) == null ? void 0 : _f.finishGraceMs) != null ? _g : defaultFinishGraceMs,
955
+ inputAudioRate: options.inputAudioFormat.rate ?? 16e3,
956
+ finishGraceMs: this.config._internal?.finishGraceMs ?? defaultFinishGraceMs,
976
957
  warnings,
977
958
  audio: options.audio,
978
959
  abortSignal: options.abortSignal,
@@ -1036,7 +1017,7 @@ function createVertexLiveTranscriptionStream({
1036
1017
  void audio.cancel().catch(() => {
1037
1018
  });
1038
1019
  }
1039
- connection == null ? void 0 : connection.close(closeCode);
1020
+ connection?.close(closeCode);
1040
1021
  };
1041
1022
  const finishWithError = (error) => {
1042
1023
  if (finished) return;
@@ -1117,7 +1098,6 @@ function createVertexLiveTranscriptionStream({
1117
1098
  void setupComplete.then(() => finished ? void 0 : sendAudio(socket)).catch(finishWithError);
1118
1099
  },
1119
1100
  onMessageText: async (text) => {
1120
- var _a, _b;
1121
1101
  if (finished) return;
1122
1102
  const parsed = await safeParseJSON({ text });
1123
1103
  if (!parsed.success) return;
@@ -1133,13 +1113,13 @@ function createVertexLiveTranscriptionStream({
1133
1113
  }
1134
1114
  if (message.error != null) {
1135
1115
  finishWithError(
1136
- new Error((_a = message.error.message) != null ? _a : "Vertex Live API error")
1116
+ new Error(message.error.message ?? "Vertex Live API error")
1137
1117
  );
1138
1118
  return;
1139
1119
  }
1140
1120
  const serverContent = message.serverContent;
1141
- const interim = serverContent == null ? void 0 : serverContent.interimInputTranscription;
1142
- if (interim == null ? void 0 : interim.text) {
1121
+ const interim = serverContent?.interimInputTranscription;
1122
+ if (interim?.text) {
1143
1123
  schedulePendingFinish();
1144
1124
  latestInterim = interim.text;
1145
1125
  controller.enqueue({
@@ -1148,7 +1128,7 @@ function createVertexLiveTranscriptionStream({
1148
1128
  text: interim.text
1149
1129
  });
1150
1130
  }
1151
- const transcription = (_b = serverContent == null ? void 0 : serverContent.inputTranscription) != null ? _b : message.inputTranscription;
1131
+ const transcription = serverContent?.inputTranscription ?? message.inputTranscription;
1152
1132
  if (transcription != null) {
1153
1133
  if (transcription.languageCode != null) {
1154
1134
  language = transcription.languageCode;
@@ -1167,11 +1147,11 @@ function createVertexLiveTranscriptionStream({
1167
1147
  completeSegment();
1168
1148
  }
1169
1149
  }
1170
- if (serverContent == null ? void 0 : serverContent.turnComplete) {
1150
+ if (serverContent?.turnComplete) {
1171
1151
  completeSegment();
1172
1152
  }
1173
- const interactionStatus = serverContent == null ? void 0 : serverContent.interactionStatus;
1174
- if (audioEnded && (interactionStatus === "IDLE" || interactionStatus === "REQUIRES_ACTION" || (serverContent == null ? void 0 : serverContent.turnComplete) === true && interactionStatus == null)) {
1153
+ const interactionStatus = serverContent?.interactionStatus;
1154
+ if (audioEnded && (interactionStatus === "IDLE" || interactionStatus === "REQUIRES_ACTION" || serverContent?.turnComplete === true && interactionStatus == null)) {
1175
1155
  finish();
1176
1156
  }
1177
1157
  },
@@ -1190,7 +1170,7 @@ function createVertexLiveTranscriptionStream({
1190
1170
  }
1191
1171
  finishWithError(
1192
1172
  new Error(
1193
- `Vertex Live transcription WebSocket closed unexpectedly before finishing (code ${code != null ? code : "unknown"}${reason ? `, reason: ${reason}` : ""}).`
1173
+ `Vertex Live transcription WebSocket closed unexpectedly before finishing (code ${code ?? "unknown"}${reason ? `, reason: ${reason}` : ""}).`
1194
1174
  )
1195
1175
  );
1196
1176
  }
@@ -1300,16 +1280,13 @@ var googleVertexVideoModelOptionsSchema = lazySchema(
1300
1280
 
1301
1281
  // src/google-vertex-video-model.ts
1302
1282
  function getFirstFrameImage(options) {
1303
- var _a, _b;
1304
- return (_b = (_a = options.frameImages) == null ? void 0 : _a.find((frame) => frame.frameType === "first_frame")) == null ? void 0 : _b.image;
1283
+ return options.frameImages?.find((frame) => frame.frameType === "first_frame")?.image;
1305
1284
  }
1306
1285
  function resolveStartImage(options) {
1307
- var _a;
1308
- return (_a = getFirstFrameImage(options)) != null ? _a : options.image;
1286
+ return getFirstFrameImage(options) ?? options.image;
1309
1287
  }
1310
1288
  function getLastFrameImage(options) {
1311
- var _a, _b;
1312
- return (_b = (_a = options.frameImages) == null ? void 0 : _a.find((frame) => frame.frameType === "last_frame")) == null ? void 0 : _b.image;
1289
+ return options.frameImages?.find((frame) => frame.frameType === "last_frame")?.image;
1313
1290
  }
1314
1291
  function getInputReferences(options) {
1315
1292
  if (options.frameImages != null && options.frameImages.length > 0) {
@@ -1355,13 +1332,12 @@ var GoogleVertexVideoModel = class {
1355
1332
  return 4;
1356
1333
  }
1357
1334
  async buildRequest(options) {
1358
- var _a, _b;
1359
1335
  const warnings = [];
1360
- const googleVertexOptions = (_a = await parseProviderOptions4({
1336
+ const googleVertexOptions = await parseProviderOptions4({
1361
1337
  provider: "googleVertex",
1362
1338
  providerOptions: options.providerOptions,
1363
1339
  schema: googleVertexVideoModelOptionsSchema
1364
- })) != null ? _a : await parseProviderOptions4({
1340
+ }) ?? await parseProviderOptions4({
1365
1341
  provider: "vertex",
1366
1342
  providerOptions: options.providerOptions,
1367
1343
  schema: googleVertexVideoModelOptionsSchema
@@ -1391,7 +1367,7 @@ var GoogleVertexVideoModel = class {
1391
1367
  const converted = convertInputReferenceImage(reference, warnings);
1392
1368
  return converted != null ? [converted] : [];
1393
1369
  });
1394
- } else if ((googleVertexOptions == null ? void 0 : googleVertexOptions.referenceImages) != null) {
1370
+ } else if (googleVertexOptions?.referenceImages != null) {
1395
1371
  instance.referenceImages = googleVertexOptions.referenceImages;
1396
1372
  }
1397
1373
  const parameters = {
@@ -1414,7 +1390,7 @@ var GoogleVertexVideoModel = class {
1414
1390
  if (options.seed) {
1415
1391
  parameters.seed = options.seed;
1416
1392
  }
1417
- const generateAudio = (_b = options.generateAudio) != null ? _b : googleVertexOptions == null ? void 0 : googleVertexOptions.generateAudio;
1393
+ const generateAudio = options.generateAudio ?? googleVertexOptions?.generateAudio;
1418
1394
  if (generateAudio != null) {
1419
1395
  parameters.generateAudio = generateAudio;
1420
1396
  }
@@ -1452,7 +1428,7 @@ var GoogleVertexVideoModel = class {
1452
1428
  currentDate
1453
1429
  }) {
1454
1430
  const response = finalOperation.response;
1455
- if (!(response == null ? void 0 : response.videos) || response.videos.length === 0) {
1431
+ if (!response?.videos || response.videos.length === 0) {
1456
1432
  throw new AISDKError({
1457
1433
  name: "VERTEX_VIDEO_GENERATION_ERROR",
1458
1434
  message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
@@ -1509,8 +1485,7 @@ var GoogleVertexVideoModel = class {
1509
1485
  };
1510
1486
  }
1511
1487
  async doStart(options) {
1512
- var _a, _b, _c;
1513
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1488
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
1514
1489
  const { instances, parameters, warnings } = await this.buildRequest(options);
1515
1490
  const { value: operation, responseHeaders } = await postJsonToApi5({
1516
1491
  url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
@@ -1547,8 +1522,7 @@ var GoogleVertexVideoModel = class {
1547
1522
  };
1548
1523
  }
1549
1524
  async doStatus(options) {
1550
- var _a, _b, _c;
1551
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1525
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
1552
1526
  const { operationName } = options.operation;
1553
1527
  const { value: statusOperation, responseHeaders } = await postJsonToApi5({
1554
1528
  url: `${this.config.baseURL}/models/${this.modelId}:fetchPredictOperation`,
@@ -1626,11 +1600,11 @@ function createExpressModeFetch(apiKey, customFetch) {
1626
1600
  const modifiedInit = {
1627
1601
  ...init,
1628
1602
  headers: {
1629
- ...(init == null ? void 0 : init.headers) ? normalizeHeaders(init.headers) : {},
1603
+ ...init?.headers ? normalizeHeaders(init.headers) : {},
1630
1604
  "x-goog-api-key": apiKey
1631
1605
  }
1632
1606
  };
1633
- return (customFetch != null ? customFetch : fetch)(url.toString(), modifiedInit);
1607
+ return (customFetch ?? fetch)(url.toString(), modifiedInit);
1634
1608
  };
1635
1609
  }
1636
1610
  function createGoogleVertex(options = {}) {
@@ -1651,9 +1625,8 @@ function createGoogleVertex(options = {}) {
1651
1625
  description: "Google Vertex location"
1652
1626
  });
1653
1627
  const loadBaseURL = ({ endpoint = false } = {}) => {
1654
- var _a, _b;
1655
1628
  if (apiKey) {
1656
- return (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : EXPRESS_MODE_BASE_URL;
1629
+ return withoutTrailingSlash(options.baseURL) ?? EXPRESS_MODE_BASE_URL;
1657
1630
  }
1658
1631
  const region = loadGoogleVertexLocation();
1659
1632
  const project = loadGoogleVertexProject();
@@ -1666,12 +1639,11 @@ function createGoogleVertex(options = {}) {
1666
1639
  return `${region}-aiplatform.googleapis.com`;
1667
1640
  }
1668
1641
  };
1669
- return (_b = withoutTrailingSlash(options.baseURL)) != null ? _b : `https://${getHost()}/v1beta1/projects/${project}/locations/${region}${endpoint ? "" : "/publishers/google"}`;
1642
+ return withoutTrailingSlash(options.baseURL) ?? `https://${getHost()}/v1beta1/projects/${project}/locations/${region}${endpoint ? "" : "/publishers/google"}`;
1670
1643
  };
1671
1644
  const createConfig = (name, { endpoint = false } = {}) => {
1672
1645
  const getHeaders = async () => {
1673
- var _a;
1674
- const originalHeaders = await resolve6((_a = options.headers) != null ? _a : {});
1646
+ const originalHeaders = await resolve6(options.headers ?? {});
1675
1647
  return withUserAgentSuffix(
1676
1648
  originalHeaders,
1677
1649
  `ai-sdk/google-vertex/${VERSION}`
@@ -1685,7 +1657,6 @@ function createGoogleVertex(options = {}) {
1685
1657
  };
1686
1658
  };
1687
1659
  const createChatModel = (modelId) => {
1688
- var _a, _b, _c;
1689
1660
  const endpoint = isEndpointModelId(modelId);
1690
1661
  if (endpoint && apiKey) {
1691
1662
  throw new Error(
@@ -1694,7 +1665,7 @@ function createGoogleVertex(options = {}) {
1694
1665
  }
1695
1666
  return new GoogleLanguageModel2(modelId, {
1696
1667
  ...createConfig("chat", { endpoint }),
1697
- generateId: (_a = options.generateId) != null ? _a : generateId,
1668
+ generateId: options.generateId ?? generateId,
1698
1669
  supportedUrls: () => ({
1699
1670
  "*": [
1700
1671
  // HTTP URLs:
@@ -1704,12 +1675,12 @@ function createGoogleVertex(options = {}) {
1704
1675
  ]
1705
1676
  }),
1706
1677
  downloadToolResultFiles: {
1707
- maxBytes: (_c = (_b = options.toolResultDownloads) == null ? void 0 : _b.maxBytes) != null ? _c : 7 * 1024 * 1024
1678
+ maxBytes: options.toolResultDownloads?.maxBytes ?? 7 * 1024 * 1024,
1679
+ supportsGoogleCloudStorageUrls: true
1708
1680
  }
1709
1681
  });
1710
1682
  };
1711
1683
  const createInteractionsModel = (modelIdOrAgent) => {
1712
- var _a;
1713
1684
  if (apiKey) {
1714
1685
  throw new Error(
1715
1686
  "Google Vertex Interactions models do not support Express Mode API keys. Use standard Google Cloud credentials instead."
@@ -1723,25 +1694,19 @@ function createGoogleVertex(options = {}) {
1723
1694
  // endpoint-style base URL without the `/publishers/google` suffix that
1724
1695
  // the base-model paths carry.
1725
1696
  ...createConfig("interactions", { endpoint: true }),
1726
- generateId: (_a = options.generateId) != null ? _a : generateId
1697
+ generateId: options.generateId ?? generateId
1727
1698
  }
1728
1699
  );
1729
1700
  };
1730
1701
  const createEmbeddingModel = (modelId) => new GoogleVertexEmbeddingModel(modelId, createConfig("embedding"));
1731
- const createImageModel = (modelId) => {
1732
- var _a;
1733
- return new GoogleVertexImageModel(modelId, {
1734
- ...createConfig("image"),
1735
- generateId: (_a = options.generateId) != null ? _a : generateId
1736
- });
1737
- };
1738
- const createVideoModel = (modelId) => {
1739
- var _a;
1740
- return new GoogleVertexVideoModel(modelId, {
1741
- ...createConfig("video"),
1742
- generateId: (_a = options.generateId) != null ? _a : generateId
1743
- });
1744
- };
1702
+ const createImageModel = (modelId) => new GoogleVertexImageModel(modelId, {
1703
+ ...createConfig("image"),
1704
+ generateId: options.generateId ?? generateId
1705
+ });
1706
+ const createVideoModel = (modelId) => new GoogleVertexVideoModel(modelId, {
1707
+ ...createConfig("video"),
1708
+ generateId: options.generateId ?? generateId
1709
+ });
1745
1710
  const createSpeechModel = (modelId) => {
1746
1711
  if (modelId.startsWith("chirp")) {
1747
1712
  if (apiKey) {