@ai-sdk/google-vertex 5.0.93 → 5.0.96
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 +48 -0
- package/dist/anthropic/edge/index.js +23 -28
- package/dist/anthropic/edge/index.js.map +1 -1
- package/dist/anthropic/index.js +23 -29
- package/dist/anthropic/index.js.map +1 -1
- package/dist/edge/index.js +84 -107
- package/dist/edge/index.js.map +1 -1
- package/dist/index.js +85 -109
- package/dist/index.js.map +1 -1
- package/dist/maas/edge/index.js +6 -11
- package/dist/maas/edge/index.js.map +1 -1
- package/dist/maas/index.js +6 -12
- package/dist/maas/index.js.map +1 -1
- package/dist/xai/edge/index.js +10 -16
- package/dist/xai/edge/index.js.map +1 -1
- package/dist/xai/index.js +10 -17
- package/dist/xai/index.js.map +1 -1
- package/docs/16-google-vertex.mdx +38 -0
- package/package.json +7 -7
- package/src/google-vertex-image-model.ts +16 -0
- package/src/google-vertex-provider-base.ts +1 -0
package/dist/edge/index.js
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
} from "@ai-sdk/provider-utils";
|
|
19
19
|
|
|
20
20
|
// src/version.ts
|
|
21
|
-
var VERSION = true ? "5.0.
|
|
21
|
+
var VERSION = true ? "5.0.96" : "0.0.0-test";
|
|
22
22
|
|
|
23
23
|
// src/google-vertex-embedding-model.ts
|
|
24
24
|
import {
|
|
@@ -127,7 +127,6 @@ var GoogleVertexEmbeddingModel = class _GoogleVertexEmbeddingModel {
|
|
|
127
127
|
abortSignal,
|
|
128
128
|
providerOptions
|
|
129
129
|
}) {
|
|
130
|
-
var _a;
|
|
131
130
|
let googleOptions = await parseProviderOptions({
|
|
132
131
|
provider: "googleVertex",
|
|
133
132
|
providerOptions,
|
|
@@ -147,7 +146,7 @@ var GoogleVertexEmbeddingModel = class _GoogleVertexEmbeddingModel {
|
|
|
147
146
|
schema: googleVertexEmbeddingModelOptions
|
|
148
147
|
});
|
|
149
148
|
}
|
|
150
|
-
googleOptions = googleOptions
|
|
149
|
+
googleOptions = googleOptions ?? {};
|
|
151
150
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
152
151
|
throw new TooManyEmbeddingValuesForCallError({
|
|
153
152
|
provider: this.provider,
|
|
@@ -187,7 +186,7 @@ var GoogleVertexEmbeddingModel = class _GoogleVertexEmbeddingModel {
|
|
|
187
186
|
return {
|
|
188
187
|
warnings: [],
|
|
189
188
|
embeddings: [response2.embedding.values],
|
|
190
|
-
usage:
|
|
189
|
+
usage: response2.usageMetadata?.promptTokenCount == null ? void 0 : { tokens: response2.usageMetadata.promptTokenCount },
|
|
191
190
|
response: { headers: responseHeaders2, body: rawValue2 }
|
|
192
191
|
};
|
|
193
192
|
}
|
|
@@ -265,6 +264,11 @@ import {
|
|
|
265
264
|
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
266
265
|
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
267
266
|
} from "@ai-sdk/provider-utils";
|
|
267
|
+
var googleVertexImageModelsWithFileInputSupport = /* @__PURE__ */ new Set([
|
|
268
|
+
"gemini-2.5-flash-image",
|
|
269
|
+
"gemini-3-pro-image-preview",
|
|
270
|
+
"gemini-3.1-flash-image-preview"
|
|
271
|
+
]);
|
|
268
272
|
var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
269
273
|
constructor(modelId, config) {
|
|
270
274
|
this.modelId = modelId;
|
|
@@ -281,11 +285,16 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
|
281
285
|
static [WORKFLOW_DESERIALIZE2](options) {
|
|
282
286
|
return new _GoogleVertexImageModel(options.modelId, options.config);
|
|
283
287
|
}
|
|
288
|
+
get supportsFileInputs() {
|
|
289
|
+
return googleVertexImageModelsWithFileInputSupport.has(this.modelId) ? true : void 0;
|
|
290
|
+
}
|
|
291
|
+
get supportsMaskInputs() {
|
|
292
|
+
return this.supportsFileInputs === true ? false : void 0;
|
|
293
|
+
}
|
|
284
294
|
get provider() {
|
|
285
295
|
return this.config.provider;
|
|
286
296
|
}
|
|
287
297
|
async doGenerate(options) {
|
|
288
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
289
298
|
if (!this.modelId.startsWith("gemini-")) {
|
|
290
299
|
throw new Error(
|
|
291
300
|
"Google image models other than Gemini are no longer supported. Use a model ID that starts with `gemini-`."
|
|
@@ -345,9 +354,9 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
|
345
354
|
const languageModel = new GoogleLanguageModel(this.modelId, {
|
|
346
355
|
provider: this.config.provider,
|
|
347
356
|
baseURL: this.config.baseURL,
|
|
348
|
-
headers:
|
|
357
|
+
headers: this.config.headers ?? {},
|
|
349
358
|
fetch: this.config.fetch,
|
|
350
|
-
generateId:
|
|
359
|
+
generateId: this.config.generateId ?? defaultGenerateId,
|
|
351
360
|
supportedUrls: () => ({
|
|
352
361
|
"*": [/^https?:\/\/.*$/, /^gs:\/\/.*$/]
|
|
353
362
|
})
|
|
@@ -356,7 +365,7 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
|
356
365
|
responseModalities: _strippedResponseModalities,
|
|
357
366
|
imageConfig: userImageConfig,
|
|
358
367
|
...userVertexOptions
|
|
359
|
-
} =
|
|
368
|
+
} = providerOptions?.googleVertex ?? providerOptions?.vertex ?? {};
|
|
360
369
|
const innerVertexOptions = {
|
|
361
370
|
...userVertexOptions,
|
|
362
371
|
responseModalities: ["IMAGE"],
|
|
@@ -377,7 +386,7 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
|
377
386
|
headers,
|
|
378
387
|
abortSignal
|
|
379
388
|
});
|
|
380
|
-
const currentDate =
|
|
389
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
381
390
|
const images = [];
|
|
382
391
|
for (const part of result.content) {
|
|
383
392
|
if (part.type === "file" && part.mediaType.startsWith("image/") && part.data.type === "data") {
|
|
@@ -398,12 +407,12 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
|
398
407
|
response: {
|
|
399
408
|
timestamp: currentDate,
|
|
400
409
|
modelId: this.modelId,
|
|
401
|
-
headers:
|
|
410
|
+
headers: result.response?.headers
|
|
402
411
|
},
|
|
403
412
|
usage: result.usage ? {
|
|
404
413
|
inputTokens: result.usage.inputTokens.total,
|
|
405
414
|
outputTokens: result.usage.outputTokens.total,
|
|
406
|
-
totalTokens: (
|
|
415
|
+
totalTokens: (result.usage.inputTokens.total ?? 0) + (result.usage.outputTokens.total ?? 0)
|
|
407
416
|
} : void 0
|
|
408
417
|
};
|
|
409
418
|
}
|
|
@@ -444,8 +453,7 @@ var GoogleVertexCloudTTSSpeechModel = class _GoogleVertexCloudTTSSpeechModel {
|
|
|
444
453
|
return this.config.provider;
|
|
445
454
|
}
|
|
446
455
|
async doGenerate(options) {
|
|
447
|
-
|
|
448
|
-
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
456
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
449
457
|
const warnings = [];
|
|
450
458
|
const {
|
|
451
459
|
text,
|
|
@@ -460,9 +468,9 @@ var GoogleVertexCloudTTSSpeechModel = class _GoogleVertexCloudTTSSpeechModel {
|
|
|
460
468
|
if (voice.includes(CHIRP3_HD_VOICE_INFIX)) {
|
|
461
469
|
voiceName = voice;
|
|
462
470
|
const localePrefix = voice.split(CHIRP3_HD_VOICE_INFIX)[0].replace(/-$/, "");
|
|
463
|
-
languageCode = language
|
|
471
|
+
languageCode = language ?? (localePrefix || DEFAULT_LANGUAGE);
|
|
464
472
|
} else {
|
|
465
|
-
languageCode = language
|
|
473
|
+
languageCode = language ?? DEFAULT_LANGUAGE;
|
|
466
474
|
voiceName = `${languageCode}-${CHIRP3_HD_VOICE_INFIX}-${voice}`;
|
|
467
475
|
}
|
|
468
476
|
if (instructions != null) {
|
|
@@ -603,7 +611,7 @@ function convertBcp47ToIso6391(value) {
|
|
|
603
611
|
try {
|
|
604
612
|
const language = new Intl.Locale(value).language;
|
|
605
613
|
return language.length === 2 ? language : void 0;
|
|
606
|
-
} catch
|
|
614
|
+
} catch {
|
|
607
615
|
return void 0;
|
|
608
616
|
}
|
|
609
617
|
}
|
|
@@ -626,8 +634,7 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
|
|
|
626
634
|
return this.config.provider;
|
|
627
635
|
}
|
|
628
636
|
async doGenerate(options) {
|
|
629
|
-
|
|
630
|
-
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
637
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
631
638
|
const warnings = [];
|
|
632
639
|
let googleOptions;
|
|
633
640
|
for (const provider of ["googleVertex", "vertex", "google"]) {
|
|
@@ -640,8 +647,8 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
|
|
|
640
647
|
break;
|
|
641
648
|
}
|
|
642
649
|
}
|
|
643
|
-
const region =
|
|
644
|
-
const languageCodes =
|
|
650
|
+
const region = googleOptions?.region ?? this.config.location;
|
|
651
|
+
const languageCodes = googleOptions?.languageCodes ?? ["auto"];
|
|
645
652
|
const content = typeof options.audio === "string" ? options.audio : convertUint8ArrayToBase64(options.audio);
|
|
646
653
|
const requestBody = {
|
|
647
654
|
config: {
|
|
@@ -651,8 +658,8 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
|
|
|
651
658
|
autoDecodingConfig: {},
|
|
652
659
|
features: {
|
|
653
660
|
// Word timing populates `segments`.
|
|
654
|
-
enableWordTimeOffsets:
|
|
655
|
-
enableAutomaticPunctuation:
|
|
661
|
+
enableWordTimeOffsets: googleOptions?.enableWordTimeOffsets ?? true,
|
|
662
|
+
enableAutomaticPunctuation: googleOptions?.enableAutomaticPunctuation ?? true
|
|
656
663
|
}
|
|
657
664
|
},
|
|
658
665
|
content
|
|
@@ -677,28 +684,22 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
|
|
|
677
684
|
abortSignal: options.abortSignal,
|
|
678
685
|
fetch: this.config.fetch
|
|
679
686
|
});
|
|
680
|
-
const results =
|
|
681
|
-
const text = results.map((result) =>
|
|
682
|
-
var _a2, _b2, _c2;
|
|
683
|
-
return (_c2 = (_b2 = (_a2 = result.alternatives) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.transcript) != null ? _c2 : "";
|
|
684
|
-
}).join(" ").trim();
|
|
687
|
+
const results = response.results ?? [];
|
|
688
|
+
const text = results.map((result) => result.alternatives?.[0]?.transcript ?? "").join(" ").trim();
|
|
685
689
|
const segments = results.flatMap(
|
|
686
|
-
(result) => {
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
return word.word == null || startSecond == null || endSecond == null ? [] : [{ text: word.word, startSecond, endSecond }];
|
|
692
|
-
})) != null ? _d2 : [];
|
|
693
|
-
}
|
|
690
|
+
(result) => result.alternatives?.[0]?.words?.flatMap((word) => {
|
|
691
|
+
const startSecond = parseDurationSeconds(word.startOffset);
|
|
692
|
+
const endSecond = parseDurationSeconds(word.endOffset);
|
|
693
|
+
return word.word == null || startSecond == null || endSecond == null ? [] : [{ text: word.word, startSecond, endSecond }];
|
|
694
|
+
}) ?? []
|
|
694
695
|
);
|
|
695
|
-
const language = convertBcp47ToIso6391(
|
|
696
|
+
const language = convertBcp47ToIso6391(results[0]?.languageCode);
|
|
696
697
|
return {
|
|
697
698
|
text,
|
|
698
699
|
segments,
|
|
699
700
|
language,
|
|
700
701
|
durationInSeconds: parseDurationSeconds(
|
|
701
|
-
|
|
702
|
+
response.metadata?.totalBilledDuration
|
|
702
703
|
),
|
|
703
704
|
warnings,
|
|
704
705
|
response: {
|
|
@@ -831,14 +832,13 @@ var GoogleVertexGeminiTranscriptionModel = class _GoogleVertexGeminiTranscriptio
|
|
|
831
832
|
}
|
|
832
833
|
}
|
|
833
834
|
async doGenerate(options) {
|
|
834
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
835
835
|
if (isLiveTranscriptionModelId(this.modelId)) {
|
|
836
836
|
throw new InvalidArgumentError({
|
|
837
837
|
argument: "modelId",
|
|
838
838
|
message: `Model '${this.modelId}' only supports streaming transcription. Use experimental_streamTranscribe, or a unary model such as 'gemini-3.5-transcribe'.`
|
|
839
839
|
});
|
|
840
840
|
}
|
|
841
|
-
const currentDate =
|
|
841
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
842
842
|
const warnings = [];
|
|
843
843
|
const googleOptions = await this.parseOptions(options.providerOptions);
|
|
844
844
|
const audioTranscriptionConfig = buildAudioTranscriptionConfig(googleOptions);
|
|
@@ -876,23 +876,17 @@ var GoogleVertexGeminiTranscriptionModel = class _GoogleVertexGeminiTranscriptio
|
|
|
876
876
|
abortSignal: options.abortSignal,
|
|
877
877
|
fetch: this.config.fetch
|
|
878
878
|
});
|
|
879
|
-
const parts =
|
|
880
|
-
const plainText = parts.map((part) =>
|
|
881
|
-
|
|
882
|
-
return (_a2 = part.text) != null ? _a2 : "";
|
|
883
|
-
}).join("");
|
|
884
|
-
const transcriptionText = parts.map((part) => {
|
|
885
|
-
var _a2, _b2;
|
|
886
|
-
return (_b2 = (_a2 = part.audioTranscription) == null ? void 0 : _a2.text) != null ? _b2 : "";
|
|
887
|
-
}).join("");
|
|
879
|
+
const parts = response.candidates?.[0]?.content?.parts ?? [];
|
|
880
|
+
const plainText = parts.map((part) => part.text ?? "").join("");
|
|
881
|
+
const transcriptionText = parts.map((part) => part.audioTranscription?.text ?? "").join("");
|
|
888
882
|
const text = plainText !== "" ? plainText : transcriptionText;
|
|
889
883
|
let language;
|
|
890
884
|
const segments = [];
|
|
891
885
|
for (const part of parts) {
|
|
892
886
|
const transcription = part.audioTranscription;
|
|
893
887
|
if (transcription == null) continue;
|
|
894
|
-
language
|
|
895
|
-
for (const word of
|
|
888
|
+
language ??= transcription.languageCode ?? void 0;
|
|
889
|
+
for (const word of transcription.words ?? []) {
|
|
896
890
|
const startSecond = parseOffsetSeconds(word.startOffset);
|
|
897
891
|
const endSecond = parseOffsetSeconds(word.endOffset);
|
|
898
892
|
if (word.word == null || startSecond == null || endSecond == null) {
|
|
@@ -921,14 +915,13 @@ var GoogleVertexGeminiTranscriptionModel = class _GoogleVertexGeminiTranscriptio
|
|
|
921
915
|
};
|
|
922
916
|
}
|
|
923
917
|
async doStream(options) {
|
|
924
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
925
918
|
if (!isLiveTranscriptionModelId(this.modelId)) {
|
|
926
919
|
throw new InvalidArgumentError({
|
|
927
920
|
argument: "modelId",
|
|
928
921
|
message: `Model '${this.modelId}' does not support streaming transcription. Use a live model such as 'gemini-3.5-transcribe-live'.`
|
|
929
922
|
});
|
|
930
923
|
}
|
|
931
|
-
const currentDate =
|
|
924
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
932
925
|
const warnings = [];
|
|
933
926
|
const googleOptions = await this.parseOptions(options.providerOptions);
|
|
934
927
|
validateLiveInputAudioFormat(options.inputAudioFormat);
|
|
@@ -943,7 +936,7 @@ var GoogleVertexGeminiTranscriptionModel = class _GoogleVertexGeminiTranscriptio
|
|
|
943
936
|
);
|
|
944
937
|
const setup = {
|
|
945
938
|
model: modelResource,
|
|
946
|
-
inputAudioTranscription:
|
|
939
|
+
inputAudioTranscription: buildAudioTranscriptionConfig(googleOptions) ?? {}
|
|
947
940
|
};
|
|
948
941
|
return {
|
|
949
942
|
request: { body: setup },
|
|
@@ -956,8 +949,8 @@ var GoogleVertexGeminiTranscriptionModel = class _GoogleVertexGeminiTranscriptio
|
|
|
956
949
|
url,
|
|
957
950
|
headers,
|
|
958
951
|
setup,
|
|
959
|
-
inputAudioRate:
|
|
960
|
-
finishGraceMs:
|
|
952
|
+
inputAudioRate: options.inputAudioFormat.rate ?? 16e3,
|
|
953
|
+
finishGraceMs: this.config._internal?.finishGraceMs ?? defaultFinishGraceMs,
|
|
961
954
|
warnings,
|
|
962
955
|
audio: options.audio,
|
|
963
956
|
abortSignal: options.abortSignal,
|
|
@@ -1021,7 +1014,7 @@ function createVertexLiveTranscriptionStream({
|
|
|
1021
1014
|
void audio.cancel().catch(() => {
|
|
1022
1015
|
});
|
|
1023
1016
|
}
|
|
1024
|
-
connection
|
|
1017
|
+
connection?.close(closeCode);
|
|
1025
1018
|
};
|
|
1026
1019
|
const finishWithError = (error) => {
|
|
1027
1020
|
if (finished) return;
|
|
@@ -1102,7 +1095,6 @@ function createVertexLiveTranscriptionStream({
|
|
|
1102
1095
|
void setupComplete.then(() => finished ? void 0 : sendAudio(socket)).catch(finishWithError);
|
|
1103
1096
|
},
|
|
1104
1097
|
onMessageText: async (text) => {
|
|
1105
|
-
var _a, _b;
|
|
1106
1098
|
if (finished) return;
|
|
1107
1099
|
const parsed = await safeParseJSON({ text });
|
|
1108
1100
|
if (!parsed.success) return;
|
|
@@ -1118,13 +1110,13 @@ function createVertexLiveTranscriptionStream({
|
|
|
1118
1110
|
}
|
|
1119
1111
|
if (message.error != null) {
|
|
1120
1112
|
finishWithError(
|
|
1121
|
-
new Error(
|
|
1113
|
+
new Error(message.error.message ?? "Vertex Live API error")
|
|
1122
1114
|
);
|
|
1123
1115
|
return;
|
|
1124
1116
|
}
|
|
1125
1117
|
const serverContent = message.serverContent;
|
|
1126
|
-
const interim = serverContent
|
|
1127
|
-
if (interim
|
|
1118
|
+
const interim = serverContent?.interimInputTranscription;
|
|
1119
|
+
if (interim?.text) {
|
|
1128
1120
|
schedulePendingFinish();
|
|
1129
1121
|
latestInterim = interim.text;
|
|
1130
1122
|
controller.enqueue({
|
|
@@ -1133,7 +1125,7 @@ function createVertexLiveTranscriptionStream({
|
|
|
1133
1125
|
text: interim.text
|
|
1134
1126
|
});
|
|
1135
1127
|
}
|
|
1136
|
-
const transcription =
|
|
1128
|
+
const transcription = serverContent?.inputTranscription ?? message.inputTranscription;
|
|
1137
1129
|
if (transcription != null) {
|
|
1138
1130
|
if (transcription.languageCode != null) {
|
|
1139
1131
|
language = transcription.languageCode;
|
|
@@ -1152,11 +1144,11 @@ function createVertexLiveTranscriptionStream({
|
|
|
1152
1144
|
completeSegment();
|
|
1153
1145
|
}
|
|
1154
1146
|
}
|
|
1155
|
-
if (serverContent
|
|
1147
|
+
if (serverContent?.turnComplete) {
|
|
1156
1148
|
completeSegment();
|
|
1157
1149
|
}
|
|
1158
|
-
const interactionStatus = serverContent
|
|
1159
|
-
if (audioEnded && (interactionStatus === "IDLE" || interactionStatus === "REQUIRES_ACTION" ||
|
|
1150
|
+
const interactionStatus = serverContent?.interactionStatus;
|
|
1151
|
+
if (audioEnded && (interactionStatus === "IDLE" || interactionStatus === "REQUIRES_ACTION" || serverContent?.turnComplete === true && interactionStatus == null)) {
|
|
1160
1152
|
finish();
|
|
1161
1153
|
}
|
|
1162
1154
|
},
|
|
@@ -1175,7 +1167,7 @@ function createVertexLiveTranscriptionStream({
|
|
|
1175
1167
|
}
|
|
1176
1168
|
finishWithError(
|
|
1177
1169
|
new Error(
|
|
1178
|
-
`Vertex Live transcription WebSocket closed unexpectedly before finishing (code ${code
|
|
1170
|
+
`Vertex Live transcription WebSocket closed unexpectedly before finishing (code ${code ?? "unknown"}${reason ? `, reason: ${reason}` : ""}).`
|
|
1179
1171
|
)
|
|
1180
1172
|
);
|
|
1181
1173
|
}
|
|
@@ -1285,16 +1277,13 @@ var googleVertexVideoModelOptionsSchema = lazySchema(
|
|
|
1285
1277
|
|
|
1286
1278
|
// src/google-vertex-video-model.ts
|
|
1287
1279
|
function getFirstFrameImage(options) {
|
|
1288
|
-
|
|
1289
|
-
return (_b = (_a = options.frameImages) == null ? void 0 : _a.find((frame) => frame.frameType === "first_frame")) == null ? void 0 : _b.image;
|
|
1280
|
+
return options.frameImages?.find((frame) => frame.frameType === "first_frame")?.image;
|
|
1290
1281
|
}
|
|
1291
1282
|
function resolveStartImage(options) {
|
|
1292
|
-
|
|
1293
|
-
return (_a = getFirstFrameImage(options)) != null ? _a : options.image;
|
|
1283
|
+
return getFirstFrameImage(options) ?? options.image;
|
|
1294
1284
|
}
|
|
1295
1285
|
function getLastFrameImage(options) {
|
|
1296
|
-
|
|
1297
|
-
return (_b = (_a = options.frameImages) == null ? void 0 : _a.find((frame) => frame.frameType === "last_frame")) == null ? void 0 : _b.image;
|
|
1286
|
+
return options.frameImages?.find((frame) => frame.frameType === "last_frame")?.image;
|
|
1298
1287
|
}
|
|
1299
1288
|
function getInputReferences(options) {
|
|
1300
1289
|
if (options.frameImages != null && options.frameImages.length > 0) {
|
|
@@ -1340,13 +1329,12 @@ var GoogleVertexVideoModel = class {
|
|
|
1340
1329
|
return 4;
|
|
1341
1330
|
}
|
|
1342
1331
|
async buildRequest(options) {
|
|
1343
|
-
var _a, _b;
|
|
1344
1332
|
const warnings = [];
|
|
1345
|
-
const googleVertexOptions =
|
|
1333
|
+
const googleVertexOptions = await parseProviderOptions4({
|
|
1346
1334
|
provider: "googleVertex",
|
|
1347
1335
|
providerOptions: options.providerOptions,
|
|
1348
1336
|
schema: googleVertexVideoModelOptionsSchema
|
|
1349
|
-
})
|
|
1337
|
+
}) ?? await parseProviderOptions4({
|
|
1350
1338
|
provider: "vertex",
|
|
1351
1339
|
providerOptions: options.providerOptions,
|
|
1352
1340
|
schema: googleVertexVideoModelOptionsSchema
|
|
@@ -1376,7 +1364,7 @@ var GoogleVertexVideoModel = class {
|
|
|
1376
1364
|
const converted = convertInputReferenceImage(reference, warnings);
|
|
1377
1365
|
return converted != null ? [converted] : [];
|
|
1378
1366
|
});
|
|
1379
|
-
} else if (
|
|
1367
|
+
} else if (googleVertexOptions?.referenceImages != null) {
|
|
1380
1368
|
instance.referenceImages = googleVertexOptions.referenceImages;
|
|
1381
1369
|
}
|
|
1382
1370
|
const parameters = {
|
|
@@ -1399,7 +1387,7 @@ var GoogleVertexVideoModel = class {
|
|
|
1399
1387
|
if (options.seed) {
|
|
1400
1388
|
parameters.seed = options.seed;
|
|
1401
1389
|
}
|
|
1402
|
-
const generateAudio =
|
|
1390
|
+
const generateAudio = options.generateAudio ?? googleVertexOptions?.generateAudio;
|
|
1403
1391
|
if (generateAudio != null) {
|
|
1404
1392
|
parameters.generateAudio = generateAudio;
|
|
1405
1393
|
}
|
|
@@ -1437,7 +1425,7 @@ var GoogleVertexVideoModel = class {
|
|
|
1437
1425
|
currentDate
|
|
1438
1426
|
}) {
|
|
1439
1427
|
const response = finalOperation.response;
|
|
1440
|
-
if (!
|
|
1428
|
+
if (!response?.videos || response.videos.length === 0) {
|
|
1441
1429
|
throw new AISDKError({
|
|
1442
1430
|
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
1443
1431
|
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
@@ -1494,8 +1482,7 @@ var GoogleVertexVideoModel = class {
|
|
|
1494
1482
|
};
|
|
1495
1483
|
}
|
|
1496
1484
|
async doStart(options) {
|
|
1497
|
-
|
|
1498
|
-
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1485
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
1499
1486
|
const { instances, parameters, warnings } = await this.buildRequest(options);
|
|
1500
1487
|
const { value: operation, responseHeaders } = await postJsonToApi5({
|
|
1501
1488
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
@@ -1532,8 +1519,7 @@ var GoogleVertexVideoModel = class {
|
|
|
1532
1519
|
};
|
|
1533
1520
|
}
|
|
1534
1521
|
async doStatus(options) {
|
|
1535
|
-
|
|
1536
|
-
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1522
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
1537
1523
|
const { operationName } = options.operation;
|
|
1538
1524
|
const { value: statusOperation, responseHeaders } = await postJsonToApi5({
|
|
1539
1525
|
url: `${this.config.baseURL}/models/${this.modelId}:fetchPredictOperation`,
|
|
@@ -1611,11 +1597,11 @@ function createExpressModeFetch(apiKey, customFetch) {
|
|
|
1611
1597
|
const modifiedInit = {
|
|
1612
1598
|
...init,
|
|
1613
1599
|
headers: {
|
|
1614
|
-
...
|
|
1600
|
+
...init?.headers ? normalizeHeaders(init.headers) : {},
|
|
1615
1601
|
"x-goog-api-key": apiKey
|
|
1616
1602
|
}
|
|
1617
1603
|
};
|
|
1618
|
-
return (customFetch
|
|
1604
|
+
return (customFetch ?? fetch)(url.toString(), modifiedInit);
|
|
1619
1605
|
};
|
|
1620
1606
|
}
|
|
1621
1607
|
function createGoogleVertex(options = {}) {
|
|
@@ -1636,9 +1622,8 @@ function createGoogleVertex(options = {}) {
|
|
|
1636
1622
|
description: "Google Vertex location"
|
|
1637
1623
|
});
|
|
1638
1624
|
const loadBaseURL = ({ endpoint = false } = {}) => {
|
|
1639
|
-
var _a, _b;
|
|
1640
1625
|
if (apiKey) {
|
|
1641
|
-
return
|
|
1626
|
+
return withoutTrailingSlash(options.baseURL) ?? EXPRESS_MODE_BASE_URL;
|
|
1642
1627
|
}
|
|
1643
1628
|
const region = loadGoogleVertexLocation();
|
|
1644
1629
|
const project = loadGoogleVertexProject();
|
|
@@ -1651,12 +1636,11 @@ function createGoogleVertex(options = {}) {
|
|
|
1651
1636
|
return `${region}-aiplatform.googleapis.com`;
|
|
1652
1637
|
}
|
|
1653
1638
|
};
|
|
1654
|
-
return
|
|
1639
|
+
return withoutTrailingSlash(options.baseURL) ?? `https://${getHost()}/v1beta1/projects/${project}/locations/${region}${endpoint ? "" : "/publishers/google"}`;
|
|
1655
1640
|
};
|
|
1656
1641
|
const createConfig = (name, { endpoint = false } = {}) => {
|
|
1657
1642
|
const getHeaders = async () => {
|
|
1658
|
-
|
|
1659
|
-
const originalHeaders = await resolve6((_a = options.headers) != null ? _a : {});
|
|
1643
|
+
const originalHeaders = await resolve6(options.headers ?? {});
|
|
1660
1644
|
return withUserAgentSuffix(
|
|
1661
1645
|
originalHeaders,
|
|
1662
1646
|
`ai-sdk/google-vertex/${VERSION}`
|
|
@@ -1670,7 +1654,6 @@ function createGoogleVertex(options = {}) {
|
|
|
1670
1654
|
};
|
|
1671
1655
|
};
|
|
1672
1656
|
const createChatModel = (modelId) => {
|
|
1673
|
-
var _a, _b, _c;
|
|
1674
1657
|
const endpoint = isEndpointModelId(modelId);
|
|
1675
1658
|
if (endpoint && apiKey) {
|
|
1676
1659
|
throw new Error(
|
|
@@ -1679,7 +1662,7 @@ function createGoogleVertex(options = {}) {
|
|
|
1679
1662
|
}
|
|
1680
1663
|
return new GoogleLanguageModel2(modelId, {
|
|
1681
1664
|
...createConfig("chat", { endpoint }),
|
|
1682
|
-
generateId:
|
|
1665
|
+
generateId: options.generateId ?? generateId,
|
|
1683
1666
|
supportedUrls: () => ({
|
|
1684
1667
|
"*": [
|
|
1685
1668
|
// HTTP URLs:
|
|
@@ -1689,12 +1672,12 @@ function createGoogleVertex(options = {}) {
|
|
|
1689
1672
|
]
|
|
1690
1673
|
}),
|
|
1691
1674
|
downloadToolResultFiles: {
|
|
1692
|
-
maxBytes:
|
|
1675
|
+
maxBytes: options.toolResultDownloads?.maxBytes ?? 7 * 1024 * 1024,
|
|
1676
|
+
supportsGoogleCloudStorageUrls: true
|
|
1693
1677
|
}
|
|
1694
1678
|
});
|
|
1695
1679
|
};
|
|
1696
1680
|
const createInteractionsModel = (modelIdOrAgent) => {
|
|
1697
|
-
var _a;
|
|
1698
1681
|
if (apiKey) {
|
|
1699
1682
|
throw new Error(
|
|
1700
1683
|
"Google Vertex Interactions models do not support Express Mode API keys. Use standard Google Cloud credentials instead."
|
|
@@ -1708,25 +1691,19 @@ function createGoogleVertex(options = {}) {
|
|
|
1708
1691
|
// endpoint-style base URL without the `/publishers/google` suffix that
|
|
1709
1692
|
// the base-model paths carry.
|
|
1710
1693
|
...createConfig("interactions", { endpoint: true }),
|
|
1711
|
-
generateId:
|
|
1694
|
+
generateId: options.generateId ?? generateId
|
|
1712
1695
|
}
|
|
1713
1696
|
);
|
|
1714
1697
|
};
|
|
1715
1698
|
const createEmbeddingModel = (modelId) => new GoogleVertexEmbeddingModel(modelId, createConfig("embedding"));
|
|
1716
|
-
const createImageModel = (modelId) => {
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
var _a;
|
|
1725
|
-
return new GoogleVertexVideoModel(modelId, {
|
|
1726
|
-
...createConfig("video"),
|
|
1727
|
-
generateId: (_a = options.generateId) != null ? _a : generateId
|
|
1728
|
-
});
|
|
1729
|
-
};
|
|
1699
|
+
const createImageModel = (modelId) => new GoogleVertexImageModel(modelId, {
|
|
1700
|
+
...createConfig("image"),
|
|
1701
|
+
generateId: options.generateId ?? generateId
|
|
1702
|
+
});
|
|
1703
|
+
const createVideoModel = (modelId) => new GoogleVertexVideoModel(modelId, {
|
|
1704
|
+
...createConfig("video"),
|
|
1705
|
+
generateId: options.generateId ?? generateId
|
|
1706
|
+
});
|
|
1730
1707
|
const createSpeechModel = (modelId) => {
|
|
1731
1708
|
if (modelId.startsWith("chirp")) {
|
|
1732
1709
|
if (apiKey) {
|