@ai-sdk/google-vertex 5.0.49 → 5.0.51

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
@@ -1,5 +1,5 @@
1
1
  // src/google-vertex-provider.ts
2
- import { loadOptionalSetting as loadOptionalSetting2, resolve as resolve6 } from "@ai-sdk/provider-utils";
2
+ import { loadOptionalSetting as loadOptionalSetting2, resolve as resolve7 } from "@ai-sdk/provider-utils";
3
3
 
4
4
  // src/google-vertex-auth-google-auth-library.ts
5
5
  import { GoogleAuth } from "google-auth-library";
@@ -27,13 +27,13 @@ import {
27
27
  loadOptionalSetting,
28
28
  loadSetting,
29
29
  normalizeHeaders,
30
- resolve as resolve5,
30
+ resolve as resolve6,
31
31
  withoutTrailingSlash,
32
32
  withUserAgentSuffix
33
33
  } from "@ai-sdk/provider-utils";
34
34
 
35
35
  // src/version.ts
36
- var VERSION = true ? "5.0.49" : "0.0.0-test";
36
+ var VERSION = true ? "5.0.51" : "0.0.0-test";
37
37
 
38
38
  // src/google-vertex-embedding-model.ts
39
39
  import {
@@ -644,6 +644,127 @@ function getBase64Data(file) {
644
644
  return convertUint8ArrayToBase64(file.data);
645
645
  }
646
646
 
647
+ // src/google-vertex-cloud-tts-speech-model.ts
648
+ import {
649
+ combineHeaders as combineHeaders3,
650
+ convertBase64ToUint8Array,
651
+ createJsonResponseHandler as createJsonResponseHandler3,
652
+ postJsonToApi as postJsonToApi3,
653
+ resolve as resolve3,
654
+ serializeModelOptions as serializeModelOptions3,
655
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3,
656
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3
657
+ } from "@ai-sdk/provider-utils";
658
+ import { z as z6 } from "zod/v4";
659
+ var DEFAULT_VOICE = "Kore";
660
+ var DEFAULT_LANGUAGE = "en-US";
661
+ var CHIRP3_HD_VOICE_INFIX = "Chirp3-HD";
662
+ var CLOUD_TTS_SYNTHESIZE_URL = "https://texttospeech.googleapis.com/v1/text:synthesize";
663
+ var GoogleVertexCloudTTSSpeechModel = class _GoogleVertexCloudTTSSpeechModel {
664
+ constructor(modelId, config) {
665
+ this.modelId = modelId;
666
+ this.config = config;
667
+ this.specificationVersion = "v4";
668
+ }
669
+ static [WORKFLOW_SERIALIZE3](model) {
670
+ return serializeModelOptions3({
671
+ modelId: model.modelId,
672
+ config: model.config
673
+ });
674
+ }
675
+ static [WORKFLOW_DESERIALIZE3](options) {
676
+ return new _GoogleVertexCloudTTSSpeechModel(options.modelId, options.config);
677
+ }
678
+ get provider() {
679
+ return this.config.provider;
680
+ }
681
+ async doGenerate(options) {
682
+ var _a, _b, _c;
683
+ const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
684
+ const warnings = [];
685
+ const {
686
+ text,
687
+ voice = DEFAULT_VOICE,
688
+ outputFormat,
689
+ instructions,
690
+ speed,
691
+ language
692
+ } = options;
693
+ let voiceName;
694
+ let languageCode;
695
+ if (voice.includes(CHIRP3_HD_VOICE_INFIX)) {
696
+ voiceName = voice;
697
+ const localePrefix = voice.split(CHIRP3_HD_VOICE_INFIX)[0].replace(/-$/, "");
698
+ languageCode = language != null ? language : localePrefix || DEFAULT_LANGUAGE;
699
+ } else {
700
+ languageCode = language != null ? language : DEFAULT_LANGUAGE;
701
+ voiceName = `${languageCode}-${CHIRP3_HD_VOICE_INFIX}-${voice}`;
702
+ }
703
+ if (instructions != null) {
704
+ warnings.push({
705
+ type: "unsupported",
706
+ feature: "instructions",
707
+ details: "Google Cloud Text-to-Speech Chirp 3: HD voices do not support the `instructions` option. It was ignored."
708
+ });
709
+ }
710
+ if (outputFormat != null && outputFormat !== "wav") {
711
+ warnings.push({
712
+ type: "unsupported",
713
+ feature: "outputFormat",
714
+ details: `Unsupported output format: ${outputFormat}. Using wav instead.`
715
+ });
716
+ }
717
+ const requestBody = {
718
+ input: { text },
719
+ voice: { languageCode, name: voiceName },
720
+ audioConfig: {
721
+ audioEncoding: "LINEAR16",
722
+ ...speed != null ? { speakingRate: speed } : {}
723
+ }
724
+ };
725
+ const {
726
+ value: response,
727
+ responseHeaders,
728
+ rawValue: rawResponse
729
+ } = await postJsonToApi3({
730
+ url: CLOUD_TTS_SYNTHESIZE_URL,
731
+ headers: combineHeaders3(
732
+ this.config.headers ? await resolve3(this.config.headers) : void 0,
733
+ options.headers
734
+ ),
735
+ body: requestBody,
736
+ failedResponseHandler: googleVertexFailedResponseHandler,
737
+ successfulResponseHandler: createJsonResponseHandler3(
738
+ googleVertexCloudTTSResponseSchema
739
+ ),
740
+ abortSignal: options.abortSignal,
741
+ fetch: this.config.fetch
742
+ });
743
+ const audio = response.audioContent != null ? convertBase64ToUint8Array(response.audioContent) : new Uint8Array(0);
744
+ return {
745
+ audio,
746
+ warnings,
747
+ request: {
748
+ body: JSON.stringify(requestBody)
749
+ },
750
+ response: {
751
+ timestamp: currentDate,
752
+ modelId: this.modelId,
753
+ headers: responseHeaders,
754
+ body: rawResponse
755
+ },
756
+ providerMetadata: {
757
+ google: {
758
+ mimeType: "audio/wav"
759
+ }
760
+ }
761
+ };
762
+ }
763
+ };
764
+ var googleVertexCloudTTSResponseSchema = z6.object({
765
+ audioContent: z6.string().nullish()
766
+ });
767
+
647
768
  // src/google-vertex-tools.ts
648
769
  import { googleTools } from "@ai-sdk/google/internal";
649
770
  var googleVertexTools = {
@@ -658,31 +779,31 @@ var googleVertexTools = {
658
779
 
659
780
  // src/google-vertex-transcription-model.ts
660
781
  import {
661
- combineHeaders as combineHeaders3,
782
+ combineHeaders as combineHeaders4,
662
783
  convertUint8ArrayToBase64 as convertUint8ArrayToBase642,
663
- createJsonResponseHandler as createJsonResponseHandler3,
784
+ createJsonResponseHandler as createJsonResponseHandler4,
664
785
  parseProviderOptions as parseProviderOptions3,
665
- postJsonToApi as postJsonToApi3,
666
- resolve as resolve3,
667
- serializeModelOptions as serializeModelOptions3,
668
- WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3,
669
- WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3
786
+ postJsonToApi as postJsonToApi4,
787
+ resolve as resolve4,
788
+ serializeModelOptions as serializeModelOptions4,
789
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE4,
790
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE4
670
791
  } from "@ai-sdk/provider-utils";
671
- import { z as z7 } from "zod/v4";
792
+ import { z as z8 } from "zod/v4";
672
793
 
673
794
  // src/google-vertex-transcription-model-options.ts
674
- import { z as z6 } from "zod/v4";
675
- var googleVertexTranscriptionProviderOptionsSchema = z6.object({
795
+ import { z as z7 } from "zod/v4";
796
+ var googleVertexTranscriptionProviderOptionsSchema = z7.object({
676
797
  /**
677
798
  * BCP-47 language codes to recognize (e.g. `['en-US']`), or `['auto']` to let
678
799
  * Chirp auto-detect the spoken language. Defaults to `['auto']`. For
679
800
  * `telephony`, pass a supported explicit language code.
680
801
  */
681
- languageCodes: z6.array(z6.string()).optional(),
802
+ languageCodes: z7.array(z7.string()).optional(),
682
803
  /**
683
804
  * Whether to add punctuation to the transcript. Defaults to `true`.
684
805
  */
685
- enableAutomaticPunctuation: z6.boolean().optional(),
806
+ enableAutomaticPunctuation: z7.boolean().optional(),
686
807
  /**
687
808
  * Whether to include word-level timestamps. Defaults to `true` so the
688
809
  * transcription result can include segments.
@@ -690,7 +811,7 @@ var googleVertexTranscriptionProviderOptionsSchema = z6.object({
690
811
  * Enabling word-level timestamps can reduce transcription quality and speed
691
812
  * for Chirp models.
692
813
  */
693
- enableWordTimeOffsets: z6.boolean().optional(),
814
+ enableWordTimeOffsets: z7.boolean().optional(),
694
815
  /**
695
816
  * The Cloud Speech-to-Text region for the request (e.g. `'us'`, `'eu'`,
696
817
  * `'us-central1'`). Defaults to the provider `location`.
@@ -699,7 +820,7 @@ var googleVertexTranscriptionProviderOptionsSchema = z6.object({
699
820
  * available in specific Speech-to-Text regions and is not available in the
700
821
  * `global` location.
701
822
  */
702
- region: z6.string().optional()
823
+ region: z7.string().optional()
703
824
  });
704
825
 
705
826
  // src/google-vertex-transcription-model.ts
@@ -727,13 +848,13 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
727
848
  this.config = config;
728
849
  this.specificationVersion = "v4";
729
850
  }
730
- static [WORKFLOW_SERIALIZE3](model) {
731
- return serializeModelOptions3({
851
+ static [WORKFLOW_SERIALIZE4](model) {
852
+ return serializeModelOptions4({
732
853
  modelId: model.modelId,
733
854
  config: model.config
734
855
  });
735
856
  }
736
- static [WORKFLOW_DESERIALIZE3](options) {
857
+ static [WORKFLOW_DESERIALIZE4](options) {
737
858
  return new _GoogleVertexTranscriptionModel(options.modelId, options.config);
738
859
  }
739
860
  get provider() {
@@ -777,15 +898,15 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
777
898
  value: response,
778
899
  responseHeaders,
779
900
  rawValue: rawResponse
780
- } = await postJsonToApi3({
901
+ } = await postJsonToApi4({
781
902
  url,
782
- headers: combineHeaders3(
783
- this.config.headers ? await resolve3(this.config.headers) : void 0,
903
+ headers: combineHeaders4(
904
+ this.config.headers ? await resolve4(this.config.headers) : void 0,
784
905
  options.headers
785
906
  ),
786
907
  body: requestBody,
787
908
  failedResponseHandler: googleVertexFailedResponseHandler,
788
- successfulResponseHandler: createJsonResponseHandler3(
909
+ successfulResponseHandler: createJsonResponseHandler4(
789
910
  googleVertexTranscriptionResponseSchema
790
911
  ),
791
912
  abortSignal: options.abortSignal,
@@ -824,26 +945,26 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
824
945
  };
825
946
  }
826
947
  };
827
- var googleVertexTranscriptionResponseSchema = z7.object({
828
- results: z7.array(
829
- z7.object({
830
- alternatives: z7.array(
831
- z7.object({
832
- transcript: z7.string().nullish(),
833
- words: z7.array(
834
- z7.object({
835
- word: z7.string().nullish(),
836
- startOffset: z7.string().nullish(),
837
- endOffset: z7.string().nullish()
948
+ var googleVertexTranscriptionResponseSchema = z8.object({
949
+ results: z8.array(
950
+ z8.object({
951
+ alternatives: z8.array(
952
+ z8.object({
953
+ transcript: z8.string().nullish(),
954
+ words: z8.array(
955
+ z8.object({
956
+ word: z8.string().nullish(),
957
+ startOffset: z8.string().nullish(),
958
+ endOffset: z8.string().nullish()
838
959
  })
839
960
  ).nullish()
840
961
  })
841
962
  ).nullish(),
842
- languageCode: z7.string().nullish()
963
+ languageCode: z8.string().nullish()
843
964
  })
844
965
  ).nullish(),
845
- metadata: z7.object({
846
- totalBilledDuration: z7.string().nullish()
966
+ metadata: z8.object({
967
+ totalBilledDuration: z8.string().nullish()
847
968
  }).nullish()
848
969
  });
849
970
 
@@ -852,31 +973,31 @@ import {
852
973
  AISDKError
853
974
  } from "@ai-sdk/provider";
854
975
  import {
855
- combineHeaders as combineHeaders4,
976
+ combineHeaders as combineHeaders5,
856
977
  convertUint8ArrayToBase64 as convertUint8ArrayToBase643,
857
- createJsonResponseHandler as createJsonResponseHandler4,
978
+ createJsonResponseHandler as createJsonResponseHandler5,
858
979
  parseProviderOptions as parseProviderOptions4,
859
- postJsonToApi as postJsonToApi4,
860
- resolve as resolve4
980
+ postJsonToApi as postJsonToApi5,
981
+ resolve as resolve5
861
982
  } from "@ai-sdk/provider-utils";
862
- import { z as z9 } from "zod/v4";
983
+ import { z as z10 } from "zod/v4";
863
984
 
864
985
  // src/google-vertex-video-model-options.ts
865
986
  import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
866
- import { z as z8 } from "zod/v4";
987
+ import { z as z9 } from "zod/v4";
867
988
  var googleVertexVideoModelOptionsSchema = lazySchema(
868
989
  () => zodSchema(
869
- z8.looseObject({
870
- pollIntervalMs: z8.number().positive().nullish(),
871
- pollTimeoutMs: z8.number().positive().nullish(),
872
- personGeneration: z8.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
873
- negativePrompt: z8.string().nullish(),
874
- generateAudio: z8.boolean().nullish(),
875
- gcsOutputDirectory: z8.string().nullish(),
876
- referenceImages: z8.array(
877
- z8.object({
878
- bytesBase64Encoded: z8.string().nullish(),
879
- gcsUri: z8.string().nullish()
990
+ z9.looseObject({
991
+ pollIntervalMs: z9.number().positive().nullish(),
992
+ pollTimeoutMs: z9.number().positive().nullish(),
993
+ personGeneration: z9.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
994
+ negativePrompt: z9.string().nullish(),
995
+ generateAudio: z9.boolean().nullish(),
996
+ gcsOutputDirectory: z9.string().nullish(),
997
+ referenceImages: z9.array(
998
+ z9.object({
999
+ bytesBase64Encoded: z9.string().nullish(),
1000
+ gcsUri: z9.string().nullish()
880
1001
  })
881
1002
  ).nullish()
882
1003
  })
@@ -1097,17 +1218,17 @@ var GoogleVertexVideoModel = class {
1097
1218
  var _a, _b, _c;
1098
1219
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1099
1220
  const { instances, parameters, warnings } = await this.buildRequest(options);
1100
- const { value: operation, responseHeaders } = await postJsonToApi4({
1221
+ const { value: operation, responseHeaders } = await postJsonToApi5({
1101
1222
  url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
1102
- headers: combineHeaders4(
1103
- await resolve4(this.config.headers),
1223
+ headers: combineHeaders5(
1224
+ await resolve5(this.config.headers),
1104
1225
  options.headers
1105
1226
  ),
1106
1227
  body: {
1107
1228
  instances,
1108
1229
  parameters
1109
1230
  },
1110
- successfulResponseHandler: createJsonResponseHandler4(
1231
+ successfulResponseHandler: createJsonResponseHandler5(
1111
1232
  googleVertexOperationSchema
1112
1233
  ),
1113
1234
  failedResponseHandler: googleVertexFailedResponseHandler,
@@ -1135,16 +1256,16 @@ var GoogleVertexVideoModel = class {
1135
1256
  var _a, _b, _c;
1136
1257
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1137
1258
  const { operationName } = options.operation;
1138
- const { value: statusOperation, responseHeaders } = await postJsonToApi4({
1259
+ const { value: statusOperation, responseHeaders } = await postJsonToApi5({
1139
1260
  url: `${this.config.baseURL}/models/${this.modelId}:fetchPredictOperation`,
1140
- headers: combineHeaders4(
1141
- await resolve4(this.config.headers),
1261
+ headers: combineHeaders5(
1262
+ await resolve5(this.config.headers),
1142
1263
  options.headers
1143
1264
  ),
1144
1265
  body: {
1145
1266
  operationName
1146
1267
  },
1147
- successfulResponseHandler: createJsonResponseHandler4(
1268
+ successfulResponseHandler: createJsonResponseHandler5(
1148
1269
  googleVertexOperationSchema
1149
1270
  ),
1150
1271
  failedResponseHandler: googleVertexFailedResponseHandler,
@@ -1180,23 +1301,23 @@ var GoogleVertexVideoModel = class {
1180
1301
  });
1181
1302
  }
1182
1303
  };
1183
- var googleVertexOperationSchema = z9.object({
1184
- name: z9.string().nullish(),
1185
- done: z9.boolean().nullish(),
1186
- error: z9.object({
1187
- code: z9.number().nullish(),
1188
- message: z9.string(),
1189
- status: z9.string().nullish()
1304
+ var googleVertexOperationSchema = z10.object({
1305
+ name: z10.string().nullish(),
1306
+ done: z10.boolean().nullish(),
1307
+ error: z10.object({
1308
+ code: z10.number().nullish(),
1309
+ message: z10.string(),
1310
+ status: z10.string().nullish()
1190
1311
  }).nullish(),
1191
- response: z9.object({
1192
- videos: z9.array(
1193
- z9.object({
1194
- bytesBase64Encoded: z9.string().nullish(),
1195
- gcsUri: z9.string().nullish(),
1196
- mimeType: z9.string().nullish()
1312
+ response: z10.object({
1313
+ videos: z10.array(
1314
+ z10.object({
1315
+ bytesBase64Encoded: z10.string().nullish(),
1316
+ gcsUri: z10.string().nullish(),
1317
+ mimeType: z10.string().nullish()
1197
1318
  })
1198
1319
  ).nullish(),
1199
- raiMediaFilteredCount: z9.number().nullish()
1320
+ raiMediaFilteredCount: z10.number().nullish()
1200
1321
  }).nullish()
1201
1322
  });
1202
1323
 
@@ -1256,7 +1377,7 @@ function createGoogleVertex(options = {}) {
1256
1377
  const createConfig = (name, { endpoint = false } = {}) => {
1257
1378
  const getHeaders = async () => {
1258
1379
  var _a;
1259
- const originalHeaders = await resolve5((_a = options.headers) != null ? _a : {});
1380
+ const originalHeaders = await resolve6((_a = options.headers) != null ? _a : {});
1260
1381
  return withUserAgentSuffix(
1261
1382
  originalHeaders,
1262
1383
  `ai-sdk/google-vertex/${VERSION}`
@@ -1324,7 +1445,22 @@ function createGoogleVertex(options = {}) {
1324
1445
  generateId: (_a = options.generateId) != null ? _a : generateId
1325
1446
  });
1326
1447
  };
1327
- const createSpeechModel = (modelId) => new GoogleSpeechModel(modelId, createConfig("speech"));
1448
+ const createSpeechModel = (modelId) => {
1449
+ if (modelId.startsWith("chirp")) {
1450
+ if (apiKey) {
1451
+ throw new Error(
1452
+ "Google Vertex Chirp speech models do not support Express Mode API keys. Use standard Google Cloud credentials instead."
1453
+ );
1454
+ }
1455
+ const config = createConfig("speech");
1456
+ return new GoogleVertexCloudTTSSpeechModel(modelId, {
1457
+ provider: config.provider,
1458
+ headers: config.headers,
1459
+ fetch: config.fetch
1460
+ });
1461
+ }
1462
+ return new GoogleSpeechModel(modelId, createConfig("speech"));
1463
+ };
1328
1464
  const createTranscriptionModel = (modelId) => {
1329
1465
  if (apiKey) {
1330
1466
  throw new Error(
@@ -1383,7 +1519,7 @@ function createGoogleVertex2(options = {}) {
1383
1519
  ...options,
1384
1520
  headers: async () => ({
1385
1521
  Authorization: `Bearer ${await generateAuthToken()}`,
1386
- ...await resolve6(options.headers)
1522
+ ...await resolve7(options.headers)
1387
1523
  })
1388
1524
  });
1389
1525
  }