@ai-sdk/google-vertex 4.0.231 → 4.0.232

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
@@ -284,7 +284,7 @@ var import_internal3 = require("@ai-sdk/google/internal");
284
284
  var import_provider_utils10 = require("@ai-sdk/provider-utils");
285
285
 
286
286
  // src/version.ts
287
- var VERSION = true ? "4.0.231" : "0.0.0-test";
287
+ var VERSION = true ? "4.0.232" : "0.0.0-test";
288
288
 
289
289
  // src/google-vertex-embedding-model.ts
290
290
  var import_provider2 = require("@ai-sdk/provider");
@@ -852,6 +852,7 @@ var googleVertexTools = {
852
852
  };
853
853
 
854
854
  // src/google-vertex-transcription-model.ts
855
+ var import_provider3 = require("@ai-sdk/provider");
855
856
  var import_provider_utils8 = require("@ai-sdk/provider-utils");
856
857
  var import_v48 = require("zod/v4");
857
858
 
@@ -881,7 +882,8 @@ var googleVertexTranscriptionProviderOptionsSchema = (0, import_provider_utils7.
881
882
  enableWordTimeOffsets: import_v47.z.boolean().optional(),
882
883
  /**
883
884
  * The Cloud Speech-to-Text region for the request (e.g. `'us'`, `'eu'`,
884
- * `'us-central1'`). Defaults to the provider `location`.
885
+ * `'us-central1'`). Defaults to the provider `location`. Must be a single
886
+ * DNS label (letters, digits, and hyphens).
885
887
  *
886
888
  * Note: Speech-to-Text regions differ from Vertex AI regions. Chirp is only
887
889
  * available in specific Speech-to-Text regions and is not available in the
@@ -921,7 +923,7 @@ var GoogleVertexTranscriptionModel = class {
921
923
  return this.config.provider;
922
924
  }
923
925
  async doGenerate(options) {
924
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
926
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
925
927
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
926
928
  const warnings = [];
927
929
  let googleOptions;
@@ -936,7 +938,13 @@ var GoogleVertexTranscriptionModel = class {
936
938
  }
937
939
  }
938
940
  const region = (_d = googleOptions == null ? void 0 : googleOptions.region) != null ? _d : this.config.location;
939
- const languageCodes = (_e = googleOptions == null ? void 0 : googleOptions.languageCodes) != null ? _e : ["auto"];
941
+ if (((_e = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i.exec(region)) == null ? void 0 : _e[0]) !== region) {
942
+ throw new import_provider3.InvalidArgumentError({
943
+ argument: (googleOptions == null ? void 0 : googleOptions.region) != null ? "region" : "location",
944
+ message: "Invalid Google Cloud Speech-to-Text region. Expected a single DNS label (letters, digits, and hyphens)."
945
+ });
946
+ }
947
+ const languageCodes = (_f = googleOptions == null ? void 0 : googleOptions.languageCodes) != null ? _f : ["auto"];
940
948
  const content = typeof options.audio === "string" ? options.audio : (0, import_provider_utils8.convertUint8ArrayToBase64)(options.audio);
941
949
  const requestBody = {
942
950
  config: {
@@ -946,14 +954,20 @@ var GoogleVertexTranscriptionModel = class {
946
954
  autoDecodingConfig: {},
947
955
  features: {
948
956
  // Word timing populates `segments`.
949
- enableWordTimeOffsets: (_f = googleOptions == null ? void 0 : googleOptions.enableWordTimeOffsets) != null ? _f : true,
950
- enableAutomaticPunctuation: (_g = googleOptions == null ? void 0 : googleOptions.enableAutomaticPunctuation) != null ? _g : true
957
+ enableWordTimeOffsets: (_g = googleOptions == null ? void 0 : googleOptions.enableWordTimeOffsets) != null ? _g : true,
958
+ enableAutomaticPunctuation: (_h = googleOptions == null ? void 0 : googleOptions.enableAutomaticPunctuation) != null ? _h : true
951
959
  }
952
960
  },
953
961
  content
954
962
  };
955
963
  const host = region === "global" ? "speech.googleapis.com" : `${region}-speech.googleapis.com`;
956
964
  const url = `https://${host}/v2/projects/${this.config.project}/locations/${region}/recognizers/_:recognize`;
965
+ if (new URL(url).origin !== `https://${host.toLowerCase()}`) {
966
+ throw new import_provider3.InvalidArgumentError({
967
+ argument: (googleOptions == null ? void 0 : googleOptions.region) != null ? "region" : "location",
968
+ message: "Invalid Google Cloud Speech-to-Text endpoint origin."
969
+ });
970
+ }
957
971
  const {
958
972
  value: response,
959
973
  responseHeaders,
@@ -972,7 +986,7 @@ var GoogleVertexTranscriptionModel = class {
972
986
  abortSignal: options.abortSignal,
973
987
  fetch: this.config.fetch
974
988
  });
975
- const results = (_h = response.results) != null ? _h : [];
989
+ const results = (_i = response.results) != null ? _i : [];
976
990
  const text = results.map((result) => {
977
991
  var _a2, _b2, _c2;
978
992
  return (_c2 = (_b2 = (_a2 = result.alternatives) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.transcript) != null ? _c2 : "";
@@ -987,13 +1001,13 @@ var GoogleVertexTranscriptionModel = class {
987
1001
  })) != null ? _d2 : [];
988
1002
  }
989
1003
  );
990
- const language = convertBcp47ToIso6391((_i = results[0]) == null ? void 0 : _i.languageCode);
1004
+ const language = convertBcp47ToIso6391((_j = results[0]) == null ? void 0 : _j.languageCode);
991
1005
  return {
992
1006
  text,
993
1007
  segments,
994
1008
  language,
995
1009
  durationInSeconds: parseDurationSeconds(
996
- (_j = response.metadata) == null ? void 0 : _j.totalBilledDuration
1010
+ (_k = response.metadata) == null ? void 0 : _k.totalBilledDuration
997
1011
  ),
998
1012
  warnings,
999
1013
  response: {
@@ -1033,7 +1047,7 @@ var googleVertexTranscriptionResponseSchema = (0, import_provider_utils8.lazySch
1033
1047
  );
1034
1048
 
1035
1049
  // src/google-vertex-video-model.ts
1036
- var import_provider3 = require("@ai-sdk/provider");
1050
+ var import_provider4 = require("@ai-sdk/provider");
1037
1051
  var import_provider_utils9 = require("@ai-sdk/provider-utils");
1038
1052
  var import_v49 = require("zod/v4");
1039
1053
  function getFirstFrameImage(options) {
@@ -1196,7 +1210,7 @@ var GoogleVertexVideoModel = class {
1196
1210
  });
1197
1211
  const operationName = operation.name;
1198
1212
  if (!operationName) {
1199
- throw new import_provider3.AISDKError({
1213
+ throw new import_provider4.AISDKError({
1200
1214
  name: "VERTEX_VIDEO_GENERATION_ERROR",
1201
1215
  message: "No operation name returned from API"
1202
1216
  });
@@ -1208,14 +1222,14 @@ var GoogleVertexVideoModel = class {
1208
1222
  let responseHeaders;
1209
1223
  while (!finalOperation.done) {
1210
1224
  if (Date.now() - startTime > pollTimeoutMs) {
1211
- throw new import_provider3.AISDKError({
1225
+ throw new import_provider4.AISDKError({
1212
1226
  name: "VERTEX_VIDEO_GENERATION_TIMEOUT",
1213
1227
  message: `Video generation timed out after ${pollTimeoutMs}ms`
1214
1228
  });
1215
1229
  }
1216
1230
  await (0, import_provider_utils9.delay)(pollIntervalMs);
1217
1231
  if ((_g = options.abortSignal) == null ? void 0 : _g.aborted) {
1218
- throw new import_provider3.AISDKError({
1232
+ throw new import_provider4.AISDKError({
1219
1233
  name: "VERTEX_VIDEO_GENERATION_ABORTED",
1220
1234
  message: "Video generation request was aborted"
1221
1235
  });
@@ -1240,14 +1254,14 @@ var GoogleVertexVideoModel = class {
1240
1254
  responseHeaders = pollHeaders;
1241
1255
  }
1242
1256
  if (finalOperation.error) {
1243
- throw new import_provider3.AISDKError({
1257
+ throw new import_provider4.AISDKError({
1244
1258
  name: "VERTEX_VIDEO_GENERATION_FAILED",
1245
1259
  message: `Video generation failed: ${finalOperation.error.message}`
1246
1260
  });
1247
1261
  }
1248
1262
  const response = finalOperation.response;
1249
1263
  if (!(response == null ? void 0 : response.videos) || response.videos.length === 0) {
1250
- throw new import_provider3.AISDKError({
1264
+ throw new import_provider4.AISDKError({
1251
1265
  name: "VERTEX_VIDEO_GENERATION_ERROR",
1252
1266
  message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
1253
1267
  });
@@ -1277,7 +1291,7 @@ var GoogleVertexVideoModel = class {
1277
1291
  }
1278
1292
  }
1279
1293
  if (videos.length === 0) {
1280
- throw new import_provider3.AISDKError({
1294
+ throw new import_provider4.AISDKError({
1281
1295
  name: "VERTEX_VIDEO_GENERATION_ERROR",
1282
1296
  message: "No valid videos in response"
1283
1297
  });