@ai-sdk/google-vertex 4.0.146 → 4.0.148
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 +12 -0
- package/dist/anthropic/edge/index.js +1 -1
- package/dist/anthropic/edge/index.mjs +1 -1
- package/dist/edge/index.d.mts +12 -2
- package/dist/edge/index.d.ts +12 -2
- package/dist/edge/index.js +299 -63
- package/dist/edge/index.js.map +1 -1
- package/dist/edge/index.mjs +291 -48
- package/dist/edge/index.mjs.map +1 -1
- package/dist/index.d.mts +20 -3
- package/dist/index.d.ts +20 -3
- package/dist/index.js +293 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +291 -48
- 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 +1 -1
- package/src/google-vertex-embedding-model.ts +59 -1
- 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/dist/index.js
CHANGED
|
@@ -27,7 +27,7 @@ __export(index_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(index_exports);
|
|
28
28
|
|
|
29
29
|
// src/google-vertex-provider-node.ts
|
|
30
|
-
var
|
|
30
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/google-vertex-auth-google-auth-library.ts
|
|
33
33
|
var import_google_auth_library = require("google-auth-library");
|
|
@@ -46,10 +46,10 @@ function createAuthTokenGenerator(options) {
|
|
|
46
46
|
|
|
47
47
|
// src/google-vertex-provider.ts
|
|
48
48
|
var import_internal3 = require("@ai-sdk/google/internal");
|
|
49
|
-
var
|
|
49
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
50
50
|
|
|
51
51
|
// src/version.ts
|
|
52
|
-
var VERSION = true ? "4.0.
|
|
52
|
+
var VERSION = true ? "4.0.148" : "0.0.0-test";
|
|
53
53
|
|
|
54
54
|
// src/google-vertex-embedding-model.ts
|
|
55
55
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -120,7 +120,6 @@ var googleVertexEmbeddingModelOptions = import_v42.z.object({
|
|
|
120
120
|
var GoogleVertexEmbeddingModel = class {
|
|
121
121
|
constructor(modelId, config) {
|
|
122
122
|
this.specificationVersion = "v3";
|
|
123
|
-
this.maxEmbeddingsPerCall = 2048;
|
|
124
123
|
this.supportsParallelCalls = true;
|
|
125
124
|
this.modelId = modelId;
|
|
126
125
|
this.config = config;
|
|
@@ -128,12 +127,18 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
128
127
|
get provider() {
|
|
129
128
|
return this.config.provider;
|
|
130
129
|
}
|
|
130
|
+
// gemini-embedding-2 models only support :embedContent (one value per call),
|
|
131
|
+
// not the :predict batch endpoint. https://github.com/vercel/ai/issues/15853
|
|
132
|
+
get maxEmbeddingsPerCall() {
|
|
133
|
+
return usesEmbedContentEndpoint(this.modelId) ? 1 : 2048;
|
|
134
|
+
}
|
|
131
135
|
async doEmbed({
|
|
132
136
|
values,
|
|
133
137
|
headers,
|
|
134
138
|
abortSignal,
|
|
135
139
|
providerOptions
|
|
136
140
|
}) {
|
|
141
|
+
var _a;
|
|
137
142
|
let googleOptions = await (0, import_provider_utils2.parseProviderOptions)({
|
|
138
143
|
provider: "vertex",
|
|
139
144
|
providerOptions,
|
|
@@ -159,6 +164,37 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
159
164
|
await (0, import_provider_utils2.resolve)(this.config.headers),
|
|
160
165
|
headers
|
|
161
166
|
);
|
|
167
|
+
if (usesEmbedContentEndpoint(this.modelId)) {
|
|
168
|
+
const {
|
|
169
|
+
responseHeaders: responseHeaders2,
|
|
170
|
+
value: response2,
|
|
171
|
+
rawValue: rawValue2
|
|
172
|
+
} = await (0, import_provider_utils2.postJsonToApi)({
|
|
173
|
+
url: `${this.config.baseURL}/models/${this.modelId}:embedContent`,
|
|
174
|
+
headers: mergedHeaders,
|
|
175
|
+
body: {
|
|
176
|
+
content: { parts: [{ text: values[0] }] },
|
|
177
|
+
embedContentConfig: {
|
|
178
|
+
outputDimensionality: googleOptions.outputDimensionality,
|
|
179
|
+
taskType: googleOptions.taskType,
|
|
180
|
+
title: googleOptions.title,
|
|
181
|
+
autoTruncate: googleOptions.autoTruncate
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
185
|
+
successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
|
|
186
|
+
googleVertexEmbedContentResponseSchema
|
|
187
|
+
),
|
|
188
|
+
abortSignal,
|
|
189
|
+
fetch: this.config.fetch
|
|
190
|
+
});
|
|
191
|
+
return {
|
|
192
|
+
warnings: [],
|
|
193
|
+
embeddings: [response2.embedding.values],
|
|
194
|
+
usage: ((_a = response2.usageMetadata) == null ? void 0 : _a.promptTokenCount) == null ? void 0 : { tokens: response2.usageMetadata.promptTokenCount },
|
|
195
|
+
response: { headers: responseHeaders2, body: rawValue2 }
|
|
196
|
+
};
|
|
197
|
+
}
|
|
162
198
|
const url = `${this.config.baseURL}/models/${this.modelId}:predict`;
|
|
163
199
|
const {
|
|
164
200
|
responseHeaders,
|
|
@@ -212,6 +248,17 @@ var googleVertexTextEmbeddingResponseSchema = import_v43.z.object({
|
|
|
212
248
|
})
|
|
213
249
|
)
|
|
214
250
|
});
|
|
251
|
+
var googleVertexEmbedContentResponseSchema = import_v43.z.object({
|
|
252
|
+
embedding: import_v43.z.object({
|
|
253
|
+
values: import_v43.z.array(import_v43.z.number())
|
|
254
|
+
}),
|
|
255
|
+
usageMetadata: import_v43.z.object({
|
|
256
|
+
promptTokenCount: import_v43.z.number().nullish()
|
|
257
|
+
}).nullish()
|
|
258
|
+
});
|
|
259
|
+
function usesEmbedContentEndpoint(modelId) {
|
|
260
|
+
return modelId === "gemini-embedding-2" || modelId === "gemini-embedding-2-preview";
|
|
261
|
+
}
|
|
215
262
|
|
|
216
263
|
// src/google-vertex-image-model.ts
|
|
217
264
|
var import_internal = require("@ai-sdk/google/internal");
|
|
@@ -555,10 +602,182 @@ var googleVertexTools = {
|
|
|
555
602
|
vertexRagStore: import_internal2.googleTools.vertexRagStore
|
|
556
603
|
};
|
|
557
604
|
|
|
558
|
-
// src/google-vertex-
|
|
559
|
-
var import_provider2 = require("@ai-sdk/provider");
|
|
605
|
+
// src/google-vertex-transcription-model.ts
|
|
560
606
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
607
|
+
var import_v46 = require("zod/v4");
|
|
608
|
+
|
|
609
|
+
// src/google-vertex-transcription-model-options.ts
|
|
561
610
|
var import_v45 = require("zod/v4");
|
|
611
|
+
var googleVertexTranscriptionProviderOptionsSchema = import_v45.z.object({
|
|
612
|
+
/**
|
|
613
|
+
* BCP-47 language codes to recognize (e.g. `['en-US']`), or `['auto']` to let
|
|
614
|
+
* Chirp auto-detect the spoken language. Defaults to `['auto']`. For
|
|
615
|
+
* `telephony`, pass a supported explicit language code.
|
|
616
|
+
*/
|
|
617
|
+
languageCodes: import_v45.z.array(import_v45.z.string()).optional(),
|
|
618
|
+
/**
|
|
619
|
+
* Whether to add punctuation to the transcript. Defaults to `true`.
|
|
620
|
+
*/
|
|
621
|
+
enableAutomaticPunctuation: import_v45.z.boolean().optional(),
|
|
622
|
+
/**
|
|
623
|
+
* Whether to include word-level timestamps. Defaults to `true` so the
|
|
624
|
+
* transcription result can include segments.
|
|
625
|
+
*
|
|
626
|
+
* Enabling word-level timestamps can reduce transcription quality and speed
|
|
627
|
+
* for Chirp models.
|
|
628
|
+
*/
|
|
629
|
+
enableWordTimeOffsets: import_v45.z.boolean().optional(),
|
|
630
|
+
/**
|
|
631
|
+
* The Cloud Speech-to-Text region for the request (e.g. `'us'`, `'eu'`,
|
|
632
|
+
* `'us-central1'`). Defaults to the provider `location`.
|
|
633
|
+
*
|
|
634
|
+
* Note: Speech-to-Text regions differ from Vertex AI regions. Chirp is only
|
|
635
|
+
* available in specific Speech-to-Text regions and is not available in the
|
|
636
|
+
* `global` location.
|
|
637
|
+
*/
|
|
638
|
+
region: import_v45.z.string().optional()
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
// src/google-vertex-transcription-model.ts
|
|
642
|
+
function parseDurationSeconds(value) {
|
|
643
|
+
if (value == null) {
|
|
644
|
+
return void 0;
|
|
645
|
+
}
|
|
646
|
+
const seconds = Number.parseFloat(value);
|
|
647
|
+
return Number.isFinite(seconds) ? seconds : void 0;
|
|
648
|
+
}
|
|
649
|
+
function convertBcp47ToIso6391(value) {
|
|
650
|
+
if (value == null) {
|
|
651
|
+
return void 0;
|
|
652
|
+
}
|
|
653
|
+
try {
|
|
654
|
+
const language = new Intl.Locale(value).language;
|
|
655
|
+
return language.length === 2 ? language : void 0;
|
|
656
|
+
} catch (e) {
|
|
657
|
+
return void 0;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
var GoogleVertexTranscriptionModel = class {
|
|
661
|
+
constructor(modelId, config) {
|
|
662
|
+
this.modelId = modelId;
|
|
663
|
+
this.config = config;
|
|
664
|
+
this.specificationVersion = "v3";
|
|
665
|
+
}
|
|
666
|
+
get provider() {
|
|
667
|
+
return this.config.provider;
|
|
668
|
+
}
|
|
669
|
+
async doGenerate(options) {
|
|
670
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
671
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
672
|
+
const warnings = [];
|
|
673
|
+
let googleOptions;
|
|
674
|
+
for (const provider of ["googleVertex", "vertex", "google"]) {
|
|
675
|
+
googleOptions = await (0, import_provider_utils4.parseProviderOptions)({
|
|
676
|
+
provider,
|
|
677
|
+
providerOptions: options.providerOptions,
|
|
678
|
+
schema: googleVertexTranscriptionProviderOptionsSchema
|
|
679
|
+
});
|
|
680
|
+
if (googleOptions != null) {
|
|
681
|
+
break;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
const region = (_d = googleOptions == null ? void 0 : googleOptions.region) != null ? _d : this.config.location;
|
|
685
|
+
const languageCodes = (_e = googleOptions == null ? void 0 : googleOptions.languageCodes) != null ? _e : ["auto"];
|
|
686
|
+
const content = typeof options.audio === "string" ? options.audio : (0, import_provider_utils4.convertUint8ArrayToBase64)(options.audio);
|
|
687
|
+
const requestBody = {
|
|
688
|
+
config: {
|
|
689
|
+
model: this.modelId,
|
|
690
|
+
languageCodes,
|
|
691
|
+
// Let Speech-to-Text auto-detect the audio encoding (wav/mp3/flac/…).
|
|
692
|
+
autoDecodingConfig: {},
|
|
693
|
+
features: {
|
|
694
|
+
// Word timing populates `segments`.
|
|
695
|
+
enableWordTimeOffsets: (_f = googleOptions == null ? void 0 : googleOptions.enableWordTimeOffsets) != null ? _f : true,
|
|
696
|
+
enableAutomaticPunctuation: (_g = googleOptions == null ? void 0 : googleOptions.enableAutomaticPunctuation) != null ? _g : true
|
|
697
|
+
}
|
|
698
|
+
},
|
|
699
|
+
content
|
|
700
|
+
};
|
|
701
|
+
const host = region === "global" ? "speech.googleapis.com" : `${region}-speech.googleapis.com`;
|
|
702
|
+
const url = `https://${host}/v2/projects/${this.config.project}/locations/${region}/recognizers/_:recognize`;
|
|
703
|
+
const {
|
|
704
|
+
value: response,
|
|
705
|
+
responseHeaders,
|
|
706
|
+
rawValue: rawResponse
|
|
707
|
+
} = await (0, import_provider_utils4.postJsonToApi)({
|
|
708
|
+
url,
|
|
709
|
+
headers: (0, import_provider_utils4.combineHeaders)(
|
|
710
|
+
this.config.headers ? await (0, import_provider_utils4.resolve)(this.config.headers) : void 0,
|
|
711
|
+
options.headers
|
|
712
|
+
),
|
|
713
|
+
body: requestBody,
|
|
714
|
+
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
715
|
+
successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
|
|
716
|
+
googleVertexTranscriptionResponseSchema
|
|
717
|
+
),
|
|
718
|
+
abortSignal: options.abortSignal,
|
|
719
|
+
fetch: this.config.fetch
|
|
720
|
+
});
|
|
721
|
+
const results = (_h = response.results) != null ? _h : [];
|
|
722
|
+
const text = results.map((result) => {
|
|
723
|
+
var _a2, _b2, _c2;
|
|
724
|
+
return (_c2 = (_b2 = (_a2 = result.alternatives) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.transcript) != null ? _c2 : "";
|
|
725
|
+
}).join(" ").trim();
|
|
726
|
+
const segments = results.flatMap(
|
|
727
|
+
(result) => {
|
|
728
|
+
var _a2, _b2, _c2, _d2;
|
|
729
|
+
return (_d2 = (_c2 = (_b2 = (_a2 = result.alternatives) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.words) == null ? void 0 : _c2.flatMap((word) => {
|
|
730
|
+
const startSecond = parseDurationSeconds(word.startOffset);
|
|
731
|
+
const endSecond = parseDurationSeconds(word.endOffset);
|
|
732
|
+
return word.word == null || startSecond == null || endSecond == null ? [] : [{ text: word.word, startSecond, endSecond }];
|
|
733
|
+
})) != null ? _d2 : [];
|
|
734
|
+
}
|
|
735
|
+
);
|
|
736
|
+
const language = convertBcp47ToIso6391((_i = results[0]) == null ? void 0 : _i.languageCode);
|
|
737
|
+
return {
|
|
738
|
+
text,
|
|
739
|
+
segments,
|
|
740
|
+
language,
|
|
741
|
+
durationInSeconds: parseDurationSeconds(
|
|
742
|
+
(_j = response.metadata) == null ? void 0 : _j.totalBilledDuration
|
|
743
|
+
),
|
|
744
|
+
warnings,
|
|
745
|
+
response: {
|
|
746
|
+
timestamp: currentDate,
|
|
747
|
+
modelId: this.modelId,
|
|
748
|
+
headers: responseHeaders,
|
|
749
|
+
body: rawResponse
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
};
|
|
754
|
+
var googleVertexTranscriptionResponseSchema = import_v46.z.object({
|
|
755
|
+
results: import_v46.z.array(
|
|
756
|
+
import_v46.z.object({
|
|
757
|
+
alternatives: import_v46.z.array(
|
|
758
|
+
import_v46.z.object({
|
|
759
|
+
transcript: import_v46.z.string().nullish(),
|
|
760
|
+
words: import_v46.z.array(
|
|
761
|
+
import_v46.z.object({
|
|
762
|
+
word: import_v46.z.string().nullish(),
|
|
763
|
+
startOffset: import_v46.z.string().nullish(),
|
|
764
|
+
endOffset: import_v46.z.string().nullish()
|
|
765
|
+
})
|
|
766
|
+
).nullish()
|
|
767
|
+
})
|
|
768
|
+
).nullish(),
|
|
769
|
+
languageCode: import_v46.z.string().nullish()
|
|
770
|
+
})
|
|
771
|
+
).nullish(),
|
|
772
|
+
metadata: import_v46.z.object({
|
|
773
|
+
totalBilledDuration: import_v46.z.string().nullish()
|
|
774
|
+
}).nullish()
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
// src/google-vertex-video-model.ts
|
|
778
|
+
var import_provider2 = require("@ai-sdk/provider");
|
|
779
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
780
|
+
var import_v47 = require("zod/v4");
|
|
562
781
|
var GoogleVertexVideoModel = class {
|
|
563
782
|
constructor(modelId, config) {
|
|
564
783
|
this.modelId = modelId;
|
|
@@ -575,7 +794,7 @@ var GoogleVertexVideoModel = class {
|
|
|
575
794
|
var _a, _b, _c, _d, _e, _f;
|
|
576
795
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
577
796
|
const warnings = [];
|
|
578
|
-
const vertexOptions = await (0,
|
|
797
|
+
const vertexOptions = await (0, import_provider_utils5.parseProviderOptions)({
|
|
579
798
|
provider: "vertex",
|
|
580
799
|
providerOptions: options.providerOptions,
|
|
581
800
|
schema: googleVertexVideoModelOptionsSchema
|
|
@@ -593,7 +812,7 @@ var GoogleVertexVideoModel = class {
|
|
|
593
812
|
details: "Vertex AI video models require base64-encoded images or GCS URIs. URL will be ignored."
|
|
594
813
|
});
|
|
595
814
|
} else {
|
|
596
|
-
const base64Data = typeof options.image.data === "string" ? options.image.data : (0,
|
|
815
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : (0, import_provider_utils5.convertUint8ArrayToBase64)(options.image.data);
|
|
597
816
|
instance.image = {
|
|
598
817
|
bytesBase64Encoded: base64Data,
|
|
599
818
|
mimeType: options.image.mediaType
|
|
@@ -651,17 +870,17 @@ var GoogleVertexVideoModel = class {
|
|
|
651
870
|
}
|
|
652
871
|
}
|
|
653
872
|
}
|
|
654
|
-
const { value: operation } = await (0,
|
|
873
|
+
const { value: operation } = await (0, import_provider_utils5.postJsonToApi)({
|
|
655
874
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
656
|
-
headers: (0,
|
|
657
|
-
await (0,
|
|
875
|
+
headers: (0, import_provider_utils5.combineHeaders)(
|
|
876
|
+
await (0, import_provider_utils5.resolve)(this.config.headers),
|
|
658
877
|
options.headers
|
|
659
878
|
),
|
|
660
879
|
body: {
|
|
661
880
|
instances,
|
|
662
881
|
parameters
|
|
663
882
|
},
|
|
664
|
-
successfulResponseHandler: (0,
|
|
883
|
+
successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
|
|
665
884
|
vertexOperationSchema
|
|
666
885
|
),
|
|
667
886
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
@@ -687,23 +906,23 @@ var GoogleVertexVideoModel = class {
|
|
|
687
906
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
688
907
|
});
|
|
689
908
|
}
|
|
690
|
-
await (0,
|
|
909
|
+
await (0, import_provider_utils5.delay)(pollIntervalMs);
|
|
691
910
|
if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
|
|
692
911
|
throw new import_provider2.AISDKError({
|
|
693
912
|
name: "VERTEX_VIDEO_GENERATION_ABORTED",
|
|
694
913
|
message: "Video generation request was aborted"
|
|
695
914
|
});
|
|
696
915
|
}
|
|
697
|
-
const { value: statusOperation, responseHeaders: pollHeaders } = await (0,
|
|
916
|
+
const { value: statusOperation, responseHeaders: pollHeaders } = await (0, import_provider_utils5.postJsonToApi)({
|
|
698
917
|
url: `${this.config.baseURL}/models/${this.modelId}:fetchPredictOperation`,
|
|
699
|
-
headers: (0,
|
|
700
|
-
await (0,
|
|
918
|
+
headers: (0, import_provider_utils5.combineHeaders)(
|
|
919
|
+
await (0, import_provider_utils5.resolve)(this.config.headers),
|
|
701
920
|
options.headers
|
|
702
921
|
),
|
|
703
922
|
body: {
|
|
704
923
|
operationName
|
|
705
924
|
},
|
|
706
|
-
successfulResponseHandler: (0,
|
|
925
|
+
successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
|
|
707
926
|
vertexOperationSchema
|
|
708
927
|
),
|
|
709
928
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
@@ -772,38 +991,38 @@ var GoogleVertexVideoModel = class {
|
|
|
772
991
|
};
|
|
773
992
|
}
|
|
774
993
|
};
|
|
775
|
-
var vertexOperationSchema =
|
|
776
|
-
name:
|
|
777
|
-
done:
|
|
778
|
-
error:
|
|
779
|
-
code:
|
|
780
|
-
message:
|
|
781
|
-
status:
|
|
994
|
+
var vertexOperationSchema = import_v47.z.object({
|
|
995
|
+
name: import_v47.z.string().nullish(),
|
|
996
|
+
done: import_v47.z.boolean().nullish(),
|
|
997
|
+
error: import_v47.z.object({
|
|
998
|
+
code: import_v47.z.number().nullish(),
|
|
999
|
+
message: import_v47.z.string(),
|
|
1000
|
+
status: import_v47.z.string().nullish()
|
|
782
1001
|
}).nullish(),
|
|
783
|
-
response:
|
|
784
|
-
videos:
|
|
785
|
-
|
|
786
|
-
bytesBase64Encoded:
|
|
787
|
-
gcsUri:
|
|
788
|
-
mimeType:
|
|
1002
|
+
response: import_v47.z.object({
|
|
1003
|
+
videos: import_v47.z.array(
|
|
1004
|
+
import_v47.z.object({
|
|
1005
|
+
bytesBase64Encoded: import_v47.z.string().nullish(),
|
|
1006
|
+
gcsUri: import_v47.z.string().nullish(),
|
|
1007
|
+
mimeType: import_v47.z.string().nullish()
|
|
789
1008
|
})
|
|
790
1009
|
).nullish(),
|
|
791
|
-
raiMediaFilteredCount:
|
|
1010
|
+
raiMediaFilteredCount: import_v47.z.number().nullish()
|
|
792
1011
|
}).nullish()
|
|
793
1012
|
});
|
|
794
|
-
var googleVertexVideoModelOptionsSchema = (0,
|
|
795
|
-
() => (0,
|
|
796
|
-
|
|
797
|
-
pollIntervalMs:
|
|
798
|
-
pollTimeoutMs:
|
|
799
|
-
personGeneration:
|
|
800
|
-
negativePrompt:
|
|
801
|
-
generateAudio:
|
|
802
|
-
gcsOutputDirectory:
|
|
803
|
-
referenceImages:
|
|
804
|
-
|
|
805
|
-
bytesBase64Encoded:
|
|
806
|
-
gcsUri:
|
|
1013
|
+
var googleVertexVideoModelOptionsSchema = (0, import_provider_utils5.lazySchema)(
|
|
1014
|
+
() => (0, import_provider_utils5.zodSchema)(
|
|
1015
|
+
import_v47.z.object({
|
|
1016
|
+
pollIntervalMs: import_v47.z.number().positive().nullish(),
|
|
1017
|
+
pollTimeoutMs: import_v47.z.number().positive().nullish(),
|
|
1018
|
+
personGeneration: import_v47.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
1019
|
+
negativePrompt: import_v47.z.string().nullish(),
|
|
1020
|
+
generateAudio: import_v47.z.boolean().nullish(),
|
|
1021
|
+
gcsOutputDirectory: import_v47.z.string().nullish(),
|
|
1022
|
+
referenceImages: import_v47.z.array(
|
|
1023
|
+
import_v47.z.object({
|
|
1024
|
+
bytesBase64Encoded: import_v47.z.string().nullish(),
|
|
1025
|
+
gcsUri: import_v47.z.string().nullish()
|
|
807
1026
|
})
|
|
808
1027
|
).nullish()
|
|
809
1028
|
}).passthrough()
|
|
@@ -817,7 +1036,7 @@ function createExpressModeFetch(apiKey, customFetch) {
|
|
|
817
1036
|
const modifiedInit = {
|
|
818
1037
|
...init,
|
|
819
1038
|
headers: {
|
|
820
|
-
...(init == null ? void 0 : init.headers) ? (0,
|
|
1039
|
+
...(init == null ? void 0 : init.headers) ? (0, import_provider_utils6.normalizeHeaders)(init.headers) : {},
|
|
821
1040
|
"x-goog-api-key": apiKey
|
|
822
1041
|
}
|
|
823
1042
|
};
|
|
@@ -825,17 +1044,17 @@ function createExpressModeFetch(apiKey, customFetch) {
|
|
|
825
1044
|
};
|
|
826
1045
|
}
|
|
827
1046
|
function createVertex(options = {}) {
|
|
828
|
-
const apiKey = (0,
|
|
1047
|
+
const apiKey = (0, import_provider_utils6.loadOptionalSetting)({
|
|
829
1048
|
settingValue: options.apiKey,
|
|
830
1049
|
environmentVariableName: "GOOGLE_VERTEX_API_KEY"
|
|
831
1050
|
});
|
|
832
|
-
const loadVertexProject = () => (0,
|
|
1051
|
+
const loadVertexProject = () => (0, import_provider_utils6.loadSetting)({
|
|
833
1052
|
settingValue: options.project,
|
|
834
1053
|
settingName: "project",
|
|
835
1054
|
environmentVariableName: "GOOGLE_VERTEX_PROJECT",
|
|
836
1055
|
description: "Google Vertex project"
|
|
837
1056
|
});
|
|
838
|
-
const loadVertexLocation = () => (0,
|
|
1057
|
+
const loadVertexLocation = () => (0, import_provider_utils6.loadSetting)({
|
|
839
1058
|
settingValue: options.location,
|
|
840
1059
|
settingName: "location",
|
|
841
1060
|
environmentVariableName: "GOOGLE_VERTEX_LOCATION",
|
|
@@ -844,7 +1063,7 @@ function createVertex(options = {}) {
|
|
|
844
1063
|
const loadBaseURL = () => {
|
|
845
1064
|
var _a, _b;
|
|
846
1065
|
if (apiKey) {
|
|
847
|
-
return (_a = (0,
|
|
1066
|
+
return (_a = (0, import_provider_utils6.withoutTrailingSlash)(options.baseURL)) != null ? _a : EXPRESS_MODE_BASE_URL;
|
|
848
1067
|
}
|
|
849
1068
|
const region = loadVertexLocation();
|
|
850
1069
|
const project = loadVertexProject();
|
|
@@ -857,13 +1076,13 @@ function createVertex(options = {}) {
|
|
|
857
1076
|
return `${region}-aiplatform.googleapis.com`;
|
|
858
1077
|
}
|
|
859
1078
|
};
|
|
860
|
-
return (_b = (0,
|
|
1079
|
+
return (_b = (0, import_provider_utils6.withoutTrailingSlash)(options.baseURL)) != null ? _b : `https://${getHost()}/v1beta1/projects/${project}/locations/${region}/publishers/google`;
|
|
861
1080
|
};
|
|
862
1081
|
const createConfig = (name) => {
|
|
863
1082
|
const getHeaders = async () => {
|
|
864
1083
|
var _a;
|
|
865
|
-
const originalHeaders = await (0,
|
|
866
|
-
return (0,
|
|
1084
|
+
const originalHeaders = await (0, import_provider_utils6.resolve)((_a = options.headers) != null ? _a : {});
|
|
1085
|
+
return (0, import_provider_utils6.withUserAgentSuffix)(
|
|
867
1086
|
originalHeaders,
|
|
868
1087
|
`ai-sdk/google-vertex/${VERSION}`
|
|
869
1088
|
);
|
|
@@ -879,7 +1098,7 @@ function createVertex(options = {}) {
|
|
|
879
1098
|
var _a;
|
|
880
1099
|
return new import_internal3.GoogleGenerativeAILanguageModel(modelId, {
|
|
881
1100
|
...createConfig("chat"),
|
|
882
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
1101
|
+
generateId: (_a = options.generateId) != null ? _a : import_provider_utils6.generateId,
|
|
883
1102
|
supportedUrls: () => ({
|
|
884
1103
|
"*": [
|
|
885
1104
|
// HTTP URLs:
|
|
@@ -895,14 +1114,29 @@ function createVertex(options = {}) {
|
|
|
895
1114
|
var _a;
|
|
896
1115
|
return new GoogleVertexImageModel(modelId, {
|
|
897
1116
|
...createConfig("image"),
|
|
898
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
1117
|
+
generateId: (_a = options.generateId) != null ? _a : import_provider_utils6.generateId
|
|
899
1118
|
});
|
|
900
1119
|
};
|
|
901
1120
|
const createVideoModel = (modelId) => {
|
|
902
1121
|
var _a;
|
|
903
1122
|
return new GoogleVertexVideoModel(modelId, {
|
|
904
1123
|
...createConfig("video"),
|
|
905
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
1124
|
+
generateId: (_a = options.generateId) != null ? _a : import_provider_utils6.generateId
|
|
1125
|
+
});
|
|
1126
|
+
};
|
|
1127
|
+
const createTranscriptionModel = (modelId) => {
|
|
1128
|
+
if (apiKey) {
|
|
1129
|
+
throw new Error(
|
|
1130
|
+
"Google Vertex transcription models do not support Express Mode API keys. Use standard Google Cloud credentials instead."
|
|
1131
|
+
);
|
|
1132
|
+
}
|
|
1133
|
+
const config = createConfig("transcription");
|
|
1134
|
+
return new GoogleVertexTranscriptionModel(modelId, {
|
|
1135
|
+
provider: config.provider,
|
|
1136
|
+
headers: config.headers,
|
|
1137
|
+
fetch: config.fetch,
|
|
1138
|
+
project: loadVertexProject(),
|
|
1139
|
+
location: loadVertexLocation()
|
|
906
1140
|
});
|
|
907
1141
|
};
|
|
908
1142
|
const provider = function(modelId) {
|
|
@@ -921,13 +1155,15 @@ function createVertex(options = {}) {
|
|
|
921
1155
|
provider.imageModel = createImageModel;
|
|
922
1156
|
provider.video = createVideoModel;
|
|
923
1157
|
provider.videoModel = createVideoModel;
|
|
1158
|
+
provider.transcription = createTranscriptionModel;
|
|
1159
|
+
provider.transcriptionModel = createTranscriptionModel;
|
|
924
1160
|
provider.tools = googleVertexTools;
|
|
925
1161
|
return provider;
|
|
926
1162
|
}
|
|
927
1163
|
|
|
928
1164
|
// src/google-vertex-provider-node.ts
|
|
929
1165
|
function createVertex2(options = {}) {
|
|
930
|
-
const apiKey = (0,
|
|
1166
|
+
const apiKey = (0, import_provider_utils7.loadOptionalSetting)({
|
|
931
1167
|
settingValue: options.apiKey,
|
|
932
1168
|
environmentVariableName: "GOOGLE_VERTEX_API_KEY"
|
|
933
1169
|
});
|
|
@@ -943,7 +1179,7 @@ function createVertex2(options = {}) {
|
|
|
943
1179
|
...options,
|
|
944
1180
|
headers: async () => ({
|
|
945
1181
|
Authorization: `Bearer ${await generateAuthToken()}`,
|
|
946
|
-
...await (0,
|
|
1182
|
+
...await (0, import_provider_utils7.resolve)(options.headers)
|
|
947
1183
|
})
|
|
948
1184
|
});
|
|
949
1185
|
}
|