@ai-sdk/google-vertex 4.0.146 → 4.0.147
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/CHANGELOG.md +6 -0
- package/dist/anthropic/edge/index.js +1 -1
- package/dist/anthropic/edge/index.mjs +1 -1
- package/dist/edge/index.d.mts +11 -1
- package/dist/edge/index.d.ts +11 -1
- package/dist/edge/index.js +251 -62
- package/dist/edge/index.js.map +1 -1
- package/dist/edge/index.mjs +243 -47
- package/dist/edge/index.mjs.map +1 -1
- package/dist/index.d.mts +19 -2
- package/dist/index.d.ts +19 -2
- package/dist/index.js +245 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +243 -47
- package/dist/index.mjs.map +1 -1
- package/dist/maas/edge/index.js +1 -1
- package/dist/maas/edge/index.mjs +1 -1
- package/dist/xai/edge/index.js +1 -1
- package/dist/xai/edge/index.mjs +1 -1
- package/docs/16-google-vertex.mdx +78 -0
- package/package.json +4 -4
- package/src/google-vertex-provider.ts +40 -0
- package/src/google-vertex-transcription-model-options.ts +46 -0
- package/src/google-vertex-transcription-model.ts +214 -0
- package/src/index.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -32,7 +32,7 @@ var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
|
32
32
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
33
33
|
|
|
34
34
|
// src/version.ts
|
|
35
|
-
var VERSION = true ? "4.0.
|
|
35
|
+
var VERSION = true ? "4.0.147" : "0.0.0-test";
|
|
36
36
|
|
|
37
37
|
// src/edge/google-vertex-auth-edge.ts
|
|
38
38
|
var loadCredentials = async () => {
|
package/dist/edge/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EmbeddingModelV3, ProviderV3, LanguageModelV3, ImageModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
|
|
1
|
+
import { EmbeddingModelV3, ProviderV3, LanguageModelV3, ImageModelV3, Experimental_VideoModelV3, TranscriptionModelV3 } from '@ai-sdk/provider';
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
@@ -60,6 +60,8 @@ declare const googleVertexTools: {
|
|
|
60
60
|
}>;
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
+
type GoogleVertexTranscriptionModelId = 'chirp_2' | 'chirp_3' | 'telephony' | (string & {});
|
|
64
|
+
|
|
63
65
|
type GoogleVertexVideoModelId = 'veo-2.0-generate-preview' | 'veo-2.0-generate-exp' | 'veo-2.0-generate-001' | 'veo-3.0-generate-001' | 'veo-3.0-fast-generate-001' | 'veo-3.0-generate-preview' | 'veo-3.0-fast-generate-preview' | 'veo-3.1-generate-001' | 'veo-3.1-fast-generate-001' | 'veo-3.1-generate-preview' | 'veo-3.1-fast-generate-preview' | (string & {});
|
|
64
66
|
|
|
65
67
|
interface GoogleVertexProvider extends ProviderV3 {
|
|
@@ -89,6 +91,14 @@ interface GoogleVertexProvider extends ProviderV3 {
|
|
|
89
91
|
* Creates a model for video generation.
|
|
90
92
|
*/
|
|
91
93
|
videoModel(modelId: GoogleVertexVideoModelId): Experimental_VideoModelV3;
|
|
94
|
+
/**
|
|
95
|
+
* Creates a model for transcription (speech-to-text).
|
|
96
|
+
*/
|
|
97
|
+
transcription(modelId: GoogleVertexTranscriptionModelId): TranscriptionModelV3;
|
|
98
|
+
/**
|
|
99
|
+
* Creates a model for transcription (speech-to-text).
|
|
100
|
+
*/
|
|
101
|
+
transcriptionModel(modelId: GoogleVertexTranscriptionModelId): TranscriptionModelV3;
|
|
92
102
|
}
|
|
93
103
|
interface GoogleVertexProviderSettings$1 {
|
|
94
104
|
/**
|
package/dist/edge/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EmbeddingModelV3, ProviderV3, LanguageModelV3, ImageModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
|
|
1
|
+
import { EmbeddingModelV3, ProviderV3, LanguageModelV3, ImageModelV3, Experimental_VideoModelV3, TranscriptionModelV3 } from '@ai-sdk/provider';
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
@@ -60,6 +60,8 @@ declare const googleVertexTools: {
|
|
|
60
60
|
}>;
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
+
type GoogleVertexTranscriptionModelId = 'chirp_2' | 'chirp_3' | 'telephony' | (string & {});
|
|
64
|
+
|
|
63
65
|
type GoogleVertexVideoModelId = 'veo-2.0-generate-preview' | 'veo-2.0-generate-exp' | 'veo-2.0-generate-001' | 'veo-3.0-generate-001' | 'veo-3.0-fast-generate-001' | 'veo-3.0-generate-preview' | 'veo-3.0-fast-generate-preview' | 'veo-3.1-generate-001' | 'veo-3.1-fast-generate-001' | 'veo-3.1-generate-preview' | 'veo-3.1-fast-generate-preview' | (string & {});
|
|
64
66
|
|
|
65
67
|
interface GoogleVertexProvider extends ProviderV3 {
|
|
@@ -89,6 +91,14 @@ interface GoogleVertexProvider extends ProviderV3 {
|
|
|
89
91
|
* Creates a model for video generation.
|
|
90
92
|
*/
|
|
91
93
|
videoModel(modelId: GoogleVertexVideoModelId): Experimental_VideoModelV3;
|
|
94
|
+
/**
|
|
95
|
+
* Creates a model for transcription (speech-to-text).
|
|
96
|
+
*/
|
|
97
|
+
transcription(modelId: GoogleVertexTranscriptionModelId): TranscriptionModelV3;
|
|
98
|
+
/**
|
|
99
|
+
* Creates a model for transcription (speech-to-text).
|
|
100
|
+
*/
|
|
101
|
+
transcriptionModel(modelId: GoogleVertexTranscriptionModelId): TranscriptionModelV3;
|
|
92
102
|
}
|
|
93
103
|
interface GoogleVertexProviderSettings$1 {
|
|
94
104
|
/**
|
package/dist/edge/index.js
CHANGED
|
@@ -26,14 +26,14 @@ __export(index_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(index_exports);
|
|
27
27
|
|
|
28
28
|
// src/edge/google-vertex-provider-edge.ts
|
|
29
|
-
var
|
|
29
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
30
30
|
|
|
31
31
|
// src/google-vertex-provider.ts
|
|
32
32
|
var import_internal3 = require("@ai-sdk/google/internal");
|
|
33
|
-
var
|
|
33
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
34
34
|
|
|
35
35
|
// src/version.ts
|
|
36
|
-
var VERSION = true ? "4.0.
|
|
36
|
+
var VERSION = true ? "4.0.147" : "0.0.0-test";
|
|
37
37
|
|
|
38
38
|
// src/google-vertex-embedding-model.ts
|
|
39
39
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -539,10 +539,182 @@ var googleVertexTools = {
|
|
|
539
539
|
vertexRagStore: import_internal2.googleTools.vertexRagStore
|
|
540
540
|
};
|
|
541
541
|
|
|
542
|
-
// src/google-vertex-
|
|
543
|
-
var import_provider2 = require("@ai-sdk/provider");
|
|
542
|
+
// src/google-vertex-transcription-model.ts
|
|
544
543
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
544
|
+
var import_v46 = require("zod/v4");
|
|
545
|
+
|
|
546
|
+
// src/google-vertex-transcription-model-options.ts
|
|
545
547
|
var import_v45 = require("zod/v4");
|
|
548
|
+
var googleVertexTranscriptionProviderOptionsSchema = import_v45.z.object({
|
|
549
|
+
/**
|
|
550
|
+
* BCP-47 language codes to recognize (e.g. `['en-US']`), or `['auto']` to let
|
|
551
|
+
* Chirp auto-detect the spoken language. Defaults to `['auto']`. For
|
|
552
|
+
* `telephony`, pass a supported explicit language code.
|
|
553
|
+
*/
|
|
554
|
+
languageCodes: import_v45.z.array(import_v45.z.string()).optional(),
|
|
555
|
+
/**
|
|
556
|
+
* Whether to add punctuation to the transcript. Defaults to `true`.
|
|
557
|
+
*/
|
|
558
|
+
enableAutomaticPunctuation: import_v45.z.boolean().optional(),
|
|
559
|
+
/**
|
|
560
|
+
* Whether to include word-level timestamps. Defaults to `true` so the
|
|
561
|
+
* transcription result can include segments.
|
|
562
|
+
*
|
|
563
|
+
* Enabling word-level timestamps can reduce transcription quality and speed
|
|
564
|
+
* for Chirp models.
|
|
565
|
+
*/
|
|
566
|
+
enableWordTimeOffsets: import_v45.z.boolean().optional(),
|
|
567
|
+
/**
|
|
568
|
+
* The Cloud Speech-to-Text region for the request (e.g. `'us'`, `'eu'`,
|
|
569
|
+
* `'us-central1'`). Defaults to the provider `location`.
|
|
570
|
+
*
|
|
571
|
+
* Note: Speech-to-Text regions differ from Vertex AI regions. Chirp is only
|
|
572
|
+
* available in specific Speech-to-Text regions and is not available in the
|
|
573
|
+
* `global` location.
|
|
574
|
+
*/
|
|
575
|
+
region: import_v45.z.string().optional()
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
// src/google-vertex-transcription-model.ts
|
|
579
|
+
function parseDurationSeconds(value) {
|
|
580
|
+
if (value == null) {
|
|
581
|
+
return void 0;
|
|
582
|
+
}
|
|
583
|
+
const seconds = Number.parseFloat(value);
|
|
584
|
+
return Number.isFinite(seconds) ? seconds : void 0;
|
|
585
|
+
}
|
|
586
|
+
function convertBcp47ToIso6391(value) {
|
|
587
|
+
if (value == null) {
|
|
588
|
+
return void 0;
|
|
589
|
+
}
|
|
590
|
+
try {
|
|
591
|
+
const language = new Intl.Locale(value).language;
|
|
592
|
+
return language.length === 2 ? language : void 0;
|
|
593
|
+
} catch (e) {
|
|
594
|
+
return void 0;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
var GoogleVertexTranscriptionModel = class {
|
|
598
|
+
constructor(modelId, config) {
|
|
599
|
+
this.modelId = modelId;
|
|
600
|
+
this.config = config;
|
|
601
|
+
this.specificationVersion = "v3";
|
|
602
|
+
}
|
|
603
|
+
get provider() {
|
|
604
|
+
return this.config.provider;
|
|
605
|
+
}
|
|
606
|
+
async doGenerate(options) {
|
|
607
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
608
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
609
|
+
const warnings = [];
|
|
610
|
+
let googleOptions;
|
|
611
|
+
for (const provider of ["googleVertex", "vertex", "google"]) {
|
|
612
|
+
googleOptions = await (0, import_provider_utils4.parseProviderOptions)({
|
|
613
|
+
provider,
|
|
614
|
+
providerOptions: options.providerOptions,
|
|
615
|
+
schema: googleVertexTranscriptionProviderOptionsSchema
|
|
616
|
+
});
|
|
617
|
+
if (googleOptions != null) {
|
|
618
|
+
break;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
const region = (_d = googleOptions == null ? void 0 : googleOptions.region) != null ? _d : this.config.location;
|
|
622
|
+
const languageCodes = (_e = googleOptions == null ? void 0 : googleOptions.languageCodes) != null ? _e : ["auto"];
|
|
623
|
+
const content = typeof options.audio === "string" ? options.audio : (0, import_provider_utils4.convertUint8ArrayToBase64)(options.audio);
|
|
624
|
+
const requestBody = {
|
|
625
|
+
config: {
|
|
626
|
+
model: this.modelId,
|
|
627
|
+
languageCodes,
|
|
628
|
+
// Let Speech-to-Text auto-detect the audio encoding (wav/mp3/flac/…).
|
|
629
|
+
autoDecodingConfig: {},
|
|
630
|
+
features: {
|
|
631
|
+
// Word timing populates `segments`.
|
|
632
|
+
enableWordTimeOffsets: (_f = googleOptions == null ? void 0 : googleOptions.enableWordTimeOffsets) != null ? _f : true,
|
|
633
|
+
enableAutomaticPunctuation: (_g = googleOptions == null ? void 0 : googleOptions.enableAutomaticPunctuation) != null ? _g : true
|
|
634
|
+
}
|
|
635
|
+
},
|
|
636
|
+
content
|
|
637
|
+
};
|
|
638
|
+
const host = region === "global" ? "speech.googleapis.com" : `${region}-speech.googleapis.com`;
|
|
639
|
+
const url = `https://${host}/v2/projects/${this.config.project}/locations/${region}/recognizers/_:recognize`;
|
|
640
|
+
const {
|
|
641
|
+
value: response,
|
|
642
|
+
responseHeaders,
|
|
643
|
+
rawValue: rawResponse
|
|
644
|
+
} = await (0, import_provider_utils4.postJsonToApi)({
|
|
645
|
+
url,
|
|
646
|
+
headers: (0, import_provider_utils4.combineHeaders)(
|
|
647
|
+
this.config.headers ? await (0, import_provider_utils4.resolve)(this.config.headers) : void 0,
|
|
648
|
+
options.headers
|
|
649
|
+
),
|
|
650
|
+
body: requestBody,
|
|
651
|
+
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
652
|
+
successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
|
|
653
|
+
googleVertexTranscriptionResponseSchema
|
|
654
|
+
),
|
|
655
|
+
abortSignal: options.abortSignal,
|
|
656
|
+
fetch: this.config.fetch
|
|
657
|
+
});
|
|
658
|
+
const results = (_h = response.results) != null ? _h : [];
|
|
659
|
+
const text = results.map((result) => {
|
|
660
|
+
var _a2, _b2, _c2;
|
|
661
|
+
return (_c2 = (_b2 = (_a2 = result.alternatives) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.transcript) != null ? _c2 : "";
|
|
662
|
+
}).join(" ").trim();
|
|
663
|
+
const segments = results.flatMap(
|
|
664
|
+
(result) => {
|
|
665
|
+
var _a2, _b2, _c2, _d2;
|
|
666
|
+
return (_d2 = (_c2 = (_b2 = (_a2 = result.alternatives) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.words) == null ? void 0 : _c2.flatMap((word) => {
|
|
667
|
+
const startSecond = parseDurationSeconds(word.startOffset);
|
|
668
|
+
const endSecond = parseDurationSeconds(word.endOffset);
|
|
669
|
+
return word.word == null || startSecond == null || endSecond == null ? [] : [{ text: word.word, startSecond, endSecond }];
|
|
670
|
+
})) != null ? _d2 : [];
|
|
671
|
+
}
|
|
672
|
+
);
|
|
673
|
+
const language = convertBcp47ToIso6391((_i = results[0]) == null ? void 0 : _i.languageCode);
|
|
674
|
+
return {
|
|
675
|
+
text,
|
|
676
|
+
segments,
|
|
677
|
+
language,
|
|
678
|
+
durationInSeconds: parseDurationSeconds(
|
|
679
|
+
(_j = response.metadata) == null ? void 0 : _j.totalBilledDuration
|
|
680
|
+
),
|
|
681
|
+
warnings,
|
|
682
|
+
response: {
|
|
683
|
+
timestamp: currentDate,
|
|
684
|
+
modelId: this.modelId,
|
|
685
|
+
headers: responseHeaders,
|
|
686
|
+
body: rawResponse
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
var googleVertexTranscriptionResponseSchema = import_v46.z.object({
|
|
692
|
+
results: import_v46.z.array(
|
|
693
|
+
import_v46.z.object({
|
|
694
|
+
alternatives: import_v46.z.array(
|
|
695
|
+
import_v46.z.object({
|
|
696
|
+
transcript: import_v46.z.string().nullish(),
|
|
697
|
+
words: import_v46.z.array(
|
|
698
|
+
import_v46.z.object({
|
|
699
|
+
word: import_v46.z.string().nullish(),
|
|
700
|
+
startOffset: import_v46.z.string().nullish(),
|
|
701
|
+
endOffset: import_v46.z.string().nullish()
|
|
702
|
+
})
|
|
703
|
+
).nullish()
|
|
704
|
+
})
|
|
705
|
+
).nullish(),
|
|
706
|
+
languageCode: import_v46.z.string().nullish()
|
|
707
|
+
})
|
|
708
|
+
).nullish(),
|
|
709
|
+
metadata: import_v46.z.object({
|
|
710
|
+
totalBilledDuration: import_v46.z.string().nullish()
|
|
711
|
+
}).nullish()
|
|
712
|
+
});
|
|
713
|
+
|
|
714
|
+
// src/google-vertex-video-model.ts
|
|
715
|
+
var import_provider2 = require("@ai-sdk/provider");
|
|
716
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
717
|
+
var import_v47 = require("zod/v4");
|
|
546
718
|
var GoogleVertexVideoModel = class {
|
|
547
719
|
constructor(modelId, config) {
|
|
548
720
|
this.modelId = modelId;
|
|
@@ -559,7 +731,7 @@ var GoogleVertexVideoModel = class {
|
|
|
559
731
|
var _a, _b, _c, _d, _e, _f;
|
|
560
732
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
561
733
|
const warnings = [];
|
|
562
|
-
const vertexOptions = await (0,
|
|
734
|
+
const vertexOptions = await (0, import_provider_utils5.parseProviderOptions)({
|
|
563
735
|
provider: "vertex",
|
|
564
736
|
providerOptions: options.providerOptions,
|
|
565
737
|
schema: googleVertexVideoModelOptionsSchema
|
|
@@ -577,7 +749,7 @@ var GoogleVertexVideoModel = class {
|
|
|
577
749
|
details: "Vertex AI video models require base64-encoded images or GCS URIs. URL will be ignored."
|
|
578
750
|
});
|
|
579
751
|
} else {
|
|
580
|
-
const base64Data = typeof options.image.data === "string" ? options.image.data : (0,
|
|
752
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : (0, import_provider_utils5.convertUint8ArrayToBase64)(options.image.data);
|
|
581
753
|
instance.image = {
|
|
582
754
|
bytesBase64Encoded: base64Data,
|
|
583
755
|
mimeType: options.image.mediaType
|
|
@@ -635,17 +807,17 @@ var GoogleVertexVideoModel = class {
|
|
|
635
807
|
}
|
|
636
808
|
}
|
|
637
809
|
}
|
|
638
|
-
const { value: operation } = await (0,
|
|
810
|
+
const { value: operation } = await (0, import_provider_utils5.postJsonToApi)({
|
|
639
811
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
640
|
-
headers: (0,
|
|
641
|
-
await (0,
|
|
812
|
+
headers: (0, import_provider_utils5.combineHeaders)(
|
|
813
|
+
await (0, import_provider_utils5.resolve)(this.config.headers),
|
|
642
814
|
options.headers
|
|
643
815
|
),
|
|
644
816
|
body: {
|
|
645
817
|
instances,
|
|
646
818
|
parameters
|
|
647
819
|
},
|
|
648
|
-
successfulResponseHandler: (0,
|
|
820
|
+
successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
|
|
649
821
|
vertexOperationSchema
|
|
650
822
|
),
|
|
651
823
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
@@ -671,23 +843,23 @@ var GoogleVertexVideoModel = class {
|
|
|
671
843
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
672
844
|
});
|
|
673
845
|
}
|
|
674
|
-
await (0,
|
|
846
|
+
await (0, import_provider_utils5.delay)(pollIntervalMs);
|
|
675
847
|
if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
|
|
676
848
|
throw new import_provider2.AISDKError({
|
|
677
849
|
name: "VERTEX_VIDEO_GENERATION_ABORTED",
|
|
678
850
|
message: "Video generation request was aborted"
|
|
679
851
|
});
|
|
680
852
|
}
|
|
681
|
-
const { value: statusOperation, responseHeaders: pollHeaders } = await (0,
|
|
853
|
+
const { value: statusOperation, responseHeaders: pollHeaders } = await (0, import_provider_utils5.postJsonToApi)({
|
|
682
854
|
url: `${this.config.baseURL}/models/${this.modelId}:fetchPredictOperation`,
|
|
683
|
-
headers: (0,
|
|
684
|
-
await (0,
|
|
855
|
+
headers: (0, import_provider_utils5.combineHeaders)(
|
|
856
|
+
await (0, import_provider_utils5.resolve)(this.config.headers),
|
|
685
857
|
options.headers
|
|
686
858
|
),
|
|
687
859
|
body: {
|
|
688
860
|
operationName
|
|
689
861
|
},
|
|
690
|
-
successfulResponseHandler: (0,
|
|
862
|
+
successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
|
|
691
863
|
vertexOperationSchema
|
|
692
864
|
),
|
|
693
865
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
@@ -756,38 +928,38 @@ var GoogleVertexVideoModel = class {
|
|
|
756
928
|
};
|
|
757
929
|
}
|
|
758
930
|
};
|
|
759
|
-
var vertexOperationSchema =
|
|
760
|
-
name:
|
|
761
|
-
done:
|
|
762
|
-
error:
|
|
763
|
-
code:
|
|
764
|
-
message:
|
|
765
|
-
status:
|
|
931
|
+
var vertexOperationSchema = import_v47.z.object({
|
|
932
|
+
name: import_v47.z.string().nullish(),
|
|
933
|
+
done: import_v47.z.boolean().nullish(),
|
|
934
|
+
error: import_v47.z.object({
|
|
935
|
+
code: import_v47.z.number().nullish(),
|
|
936
|
+
message: import_v47.z.string(),
|
|
937
|
+
status: import_v47.z.string().nullish()
|
|
766
938
|
}).nullish(),
|
|
767
|
-
response:
|
|
768
|
-
videos:
|
|
769
|
-
|
|
770
|
-
bytesBase64Encoded:
|
|
771
|
-
gcsUri:
|
|
772
|
-
mimeType:
|
|
939
|
+
response: import_v47.z.object({
|
|
940
|
+
videos: import_v47.z.array(
|
|
941
|
+
import_v47.z.object({
|
|
942
|
+
bytesBase64Encoded: import_v47.z.string().nullish(),
|
|
943
|
+
gcsUri: import_v47.z.string().nullish(),
|
|
944
|
+
mimeType: import_v47.z.string().nullish()
|
|
773
945
|
})
|
|
774
946
|
).nullish(),
|
|
775
|
-
raiMediaFilteredCount:
|
|
947
|
+
raiMediaFilteredCount: import_v47.z.number().nullish()
|
|
776
948
|
}).nullish()
|
|
777
949
|
});
|
|
778
|
-
var googleVertexVideoModelOptionsSchema = (0,
|
|
779
|
-
() => (0,
|
|
780
|
-
|
|
781
|
-
pollIntervalMs:
|
|
782
|
-
pollTimeoutMs:
|
|
783
|
-
personGeneration:
|
|
784
|
-
negativePrompt:
|
|
785
|
-
generateAudio:
|
|
786
|
-
gcsOutputDirectory:
|
|
787
|
-
referenceImages:
|
|
788
|
-
|
|
789
|
-
bytesBase64Encoded:
|
|
790
|
-
gcsUri:
|
|
950
|
+
var googleVertexVideoModelOptionsSchema = (0, import_provider_utils5.lazySchema)(
|
|
951
|
+
() => (0, import_provider_utils5.zodSchema)(
|
|
952
|
+
import_v47.z.object({
|
|
953
|
+
pollIntervalMs: import_v47.z.number().positive().nullish(),
|
|
954
|
+
pollTimeoutMs: import_v47.z.number().positive().nullish(),
|
|
955
|
+
personGeneration: import_v47.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
956
|
+
negativePrompt: import_v47.z.string().nullish(),
|
|
957
|
+
generateAudio: import_v47.z.boolean().nullish(),
|
|
958
|
+
gcsOutputDirectory: import_v47.z.string().nullish(),
|
|
959
|
+
referenceImages: import_v47.z.array(
|
|
960
|
+
import_v47.z.object({
|
|
961
|
+
bytesBase64Encoded: import_v47.z.string().nullish(),
|
|
962
|
+
gcsUri: import_v47.z.string().nullish()
|
|
791
963
|
})
|
|
792
964
|
).nullish()
|
|
793
965
|
}).passthrough()
|
|
@@ -801,7 +973,7 @@ function createExpressModeFetch(apiKey, customFetch) {
|
|
|
801
973
|
const modifiedInit = {
|
|
802
974
|
...init,
|
|
803
975
|
headers: {
|
|
804
|
-
...(init == null ? void 0 : init.headers) ? (0,
|
|
976
|
+
...(init == null ? void 0 : init.headers) ? (0, import_provider_utils6.normalizeHeaders)(init.headers) : {},
|
|
805
977
|
"x-goog-api-key": apiKey
|
|
806
978
|
}
|
|
807
979
|
};
|
|
@@ -809,17 +981,17 @@ function createExpressModeFetch(apiKey, customFetch) {
|
|
|
809
981
|
};
|
|
810
982
|
}
|
|
811
983
|
function createVertex(options = {}) {
|
|
812
|
-
const apiKey = (0,
|
|
984
|
+
const apiKey = (0, import_provider_utils6.loadOptionalSetting)({
|
|
813
985
|
settingValue: options.apiKey,
|
|
814
986
|
environmentVariableName: "GOOGLE_VERTEX_API_KEY"
|
|
815
987
|
});
|
|
816
|
-
const loadVertexProject = () => (0,
|
|
988
|
+
const loadVertexProject = () => (0, import_provider_utils6.loadSetting)({
|
|
817
989
|
settingValue: options.project,
|
|
818
990
|
settingName: "project",
|
|
819
991
|
environmentVariableName: "GOOGLE_VERTEX_PROJECT",
|
|
820
992
|
description: "Google Vertex project"
|
|
821
993
|
});
|
|
822
|
-
const loadVertexLocation = () => (0,
|
|
994
|
+
const loadVertexLocation = () => (0, import_provider_utils6.loadSetting)({
|
|
823
995
|
settingValue: options.location,
|
|
824
996
|
settingName: "location",
|
|
825
997
|
environmentVariableName: "GOOGLE_VERTEX_LOCATION",
|
|
@@ -828,7 +1000,7 @@ function createVertex(options = {}) {
|
|
|
828
1000
|
const loadBaseURL = () => {
|
|
829
1001
|
var _a, _b;
|
|
830
1002
|
if (apiKey) {
|
|
831
|
-
return (_a = (0,
|
|
1003
|
+
return (_a = (0, import_provider_utils6.withoutTrailingSlash)(options.baseURL)) != null ? _a : EXPRESS_MODE_BASE_URL;
|
|
832
1004
|
}
|
|
833
1005
|
const region = loadVertexLocation();
|
|
834
1006
|
const project = loadVertexProject();
|
|
@@ -841,13 +1013,13 @@ function createVertex(options = {}) {
|
|
|
841
1013
|
return `${region}-aiplatform.googleapis.com`;
|
|
842
1014
|
}
|
|
843
1015
|
};
|
|
844
|
-
return (_b = (0,
|
|
1016
|
+
return (_b = (0, import_provider_utils6.withoutTrailingSlash)(options.baseURL)) != null ? _b : `https://${getHost()}/v1beta1/projects/${project}/locations/${region}/publishers/google`;
|
|
845
1017
|
};
|
|
846
1018
|
const createConfig = (name) => {
|
|
847
1019
|
const getHeaders = async () => {
|
|
848
1020
|
var _a;
|
|
849
|
-
const originalHeaders = await (0,
|
|
850
|
-
return (0,
|
|
1021
|
+
const originalHeaders = await (0, import_provider_utils6.resolve)((_a = options.headers) != null ? _a : {});
|
|
1022
|
+
return (0, import_provider_utils6.withUserAgentSuffix)(
|
|
851
1023
|
originalHeaders,
|
|
852
1024
|
`ai-sdk/google-vertex/${VERSION}`
|
|
853
1025
|
);
|
|
@@ -863,7 +1035,7 @@ function createVertex(options = {}) {
|
|
|
863
1035
|
var _a;
|
|
864
1036
|
return new import_internal3.GoogleGenerativeAILanguageModel(modelId, {
|
|
865
1037
|
...createConfig("chat"),
|
|
866
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
1038
|
+
generateId: (_a = options.generateId) != null ? _a : import_provider_utils6.generateId,
|
|
867
1039
|
supportedUrls: () => ({
|
|
868
1040
|
"*": [
|
|
869
1041
|
// HTTP URLs:
|
|
@@ -879,14 +1051,29 @@ function createVertex(options = {}) {
|
|
|
879
1051
|
var _a;
|
|
880
1052
|
return new GoogleVertexImageModel(modelId, {
|
|
881
1053
|
...createConfig("image"),
|
|
882
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
1054
|
+
generateId: (_a = options.generateId) != null ? _a : import_provider_utils6.generateId
|
|
883
1055
|
});
|
|
884
1056
|
};
|
|
885
1057
|
const createVideoModel = (modelId) => {
|
|
886
1058
|
var _a;
|
|
887
1059
|
return new GoogleVertexVideoModel(modelId, {
|
|
888
1060
|
...createConfig("video"),
|
|
889
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
1061
|
+
generateId: (_a = options.generateId) != null ? _a : import_provider_utils6.generateId
|
|
1062
|
+
});
|
|
1063
|
+
};
|
|
1064
|
+
const createTranscriptionModel = (modelId) => {
|
|
1065
|
+
if (apiKey) {
|
|
1066
|
+
throw new Error(
|
|
1067
|
+
"Google Vertex transcription models do not support Express Mode API keys. Use standard Google Cloud credentials instead."
|
|
1068
|
+
);
|
|
1069
|
+
}
|
|
1070
|
+
const config = createConfig("transcription");
|
|
1071
|
+
return new GoogleVertexTranscriptionModel(modelId, {
|
|
1072
|
+
provider: config.provider,
|
|
1073
|
+
headers: config.headers,
|
|
1074
|
+
fetch: config.fetch,
|
|
1075
|
+
project: loadVertexProject(),
|
|
1076
|
+
location: loadVertexLocation()
|
|
890
1077
|
});
|
|
891
1078
|
};
|
|
892
1079
|
const provider = function(modelId) {
|
|
@@ -905,28 +1092,30 @@ function createVertex(options = {}) {
|
|
|
905
1092
|
provider.imageModel = createImageModel;
|
|
906
1093
|
provider.video = createVideoModel;
|
|
907
1094
|
provider.videoModel = createVideoModel;
|
|
1095
|
+
provider.transcription = createTranscriptionModel;
|
|
1096
|
+
provider.transcriptionModel = createTranscriptionModel;
|
|
908
1097
|
provider.tools = googleVertexTools;
|
|
909
1098
|
return provider;
|
|
910
1099
|
}
|
|
911
1100
|
|
|
912
1101
|
// src/edge/google-vertex-auth-edge.ts
|
|
913
|
-
var
|
|
1102
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
914
1103
|
var loadCredentials = async () => {
|
|
915
1104
|
try {
|
|
916
1105
|
return {
|
|
917
|
-
clientEmail: (0,
|
|
1106
|
+
clientEmail: (0, import_provider_utils7.loadSetting)({
|
|
918
1107
|
settingValue: void 0,
|
|
919
1108
|
settingName: "clientEmail",
|
|
920
1109
|
environmentVariableName: "GOOGLE_CLIENT_EMAIL",
|
|
921
1110
|
description: "Google client email"
|
|
922
1111
|
}),
|
|
923
|
-
privateKey: (0,
|
|
1112
|
+
privateKey: (0, import_provider_utils7.loadSetting)({
|
|
924
1113
|
settingValue: void 0,
|
|
925
1114
|
settingName: "privateKey",
|
|
926
1115
|
environmentVariableName: "GOOGLE_PRIVATE_KEY",
|
|
927
1116
|
description: "Google private key"
|
|
928
1117
|
}),
|
|
929
|
-
privateKeyId: (0,
|
|
1118
|
+
privateKeyId: (0, import_provider_utils7.loadOptionalSetting)({
|
|
930
1119
|
settingValue: void 0,
|
|
931
1120
|
environmentVariableName: "GOOGLE_PRIVATE_KEY_ID"
|
|
932
1121
|
})
|
|
@@ -995,10 +1184,10 @@ async function generateAuthToken(credentials) {
|
|
|
995
1184
|
const jwt = await buildJwt(creds);
|
|
996
1185
|
const response = await fetch("https://oauth2.googleapis.com/token", {
|
|
997
1186
|
method: "POST",
|
|
998
|
-
headers: (0,
|
|
1187
|
+
headers: (0, import_provider_utils7.withUserAgentSuffix)(
|
|
999
1188
|
{ "Content-Type": "application/x-www-form-urlencoded" },
|
|
1000
1189
|
`ai-sdk/google-vertex/${VERSION}`,
|
|
1001
|
-
(0,
|
|
1190
|
+
(0, import_provider_utils7.getRuntimeEnvironmentUserAgent)()
|
|
1002
1191
|
),
|
|
1003
1192
|
body: new URLSearchParams({
|
|
1004
1193
|
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
|
|
@@ -1017,7 +1206,7 @@ async function generateAuthToken(credentials) {
|
|
|
1017
1206
|
|
|
1018
1207
|
// src/edge/google-vertex-provider-edge.ts
|
|
1019
1208
|
function createVertex2(options = {}) {
|
|
1020
|
-
const apiKey = (0,
|
|
1209
|
+
const apiKey = (0, import_provider_utils8.loadOptionalSetting)({
|
|
1021
1210
|
settingValue: options.apiKey,
|
|
1022
1211
|
environmentVariableName: "GOOGLE_VERTEX_API_KEY"
|
|
1023
1212
|
});
|
|
@@ -1030,7 +1219,7 @@ function createVertex2(options = {}) {
|
|
|
1030
1219
|
Authorization: `Bearer ${await generateAuthToken(
|
|
1031
1220
|
options.googleCredentials
|
|
1032
1221
|
)}`,
|
|
1033
|
-
...await (0,
|
|
1222
|
+
...await (0, import_provider_utils8.resolve)(options.headers)
|
|
1034
1223
|
})
|
|
1035
1224
|
});
|
|
1036
1225
|
}
|