@ai-sdk/google-vertex 5.0.92 → 5.0.95
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 +34 -0
- package/README.md +11 -11
- 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 +73 -107
- package/dist/edge/index.js.map +1 -1
- package/dist/index.js +74 -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 +51 -13
- package/package.json +6 -6
- package/src/google-vertex-provider-base.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -9,10 +9,9 @@ function createAuthTokenGenerator(options) {
|
|
|
9
9
|
...options
|
|
10
10
|
});
|
|
11
11
|
return async function generateAuthToken() {
|
|
12
|
-
var _a;
|
|
13
12
|
const client = await auth.getClient();
|
|
14
13
|
const token = await client.getAccessToken();
|
|
15
|
-
return
|
|
14
|
+
return token?.token ?? null;
|
|
16
15
|
};
|
|
17
16
|
}
|
|
18
17
|
|
|
@@ -33,7 +32,7 @@ import {
|
|
|
33
32
|
} from "@ai-sdk/provider-utils";
|
|
34
33
|
|
|
35
34
|
// src/version.ts
|
|
36
|
-
var VERSION = true ? "5.0.
|
|
35
|
+
var VERSION = true ? "5.0.95" : "0.0.0-test";
|
|
37
36
|
|
|
38
37
|
// src/google-vertex-embedding-model.ts
|
|
39
38
|
import {
|
|
@@ -142,7 +141,6 @@ var GoogleVertexEmbeddingModel = class _GoogleVertexEmbeddingModel {
|
|
|
142
141
|
abortSignal,
|
|
143
142
|
providerOptions
|
|
144
143
|
}) {
|
|
145
|
-
var _a;
|
|
146
144
|
let googleOptions = await parseProviderOptions({
|
|
147
145
|
provider: "googleVertex",
|
|
148
146
|
providerOptions,
|
|
@@ -162,7 +160,7 @@ var GoogleVertexEmbeddingModel = class _GoogleVertexEmbeddingModel {
|
|
|
162
160
|
schema: googleVertexEmbeddingModelOptions
|
|
163
161
|
});
|
|
164
162
|
}
|
|
165
|
-
googleOptions = googleOptions
|
|
163
|
+
googleOptions = googleOptions ?? {};
|
|
166
164
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
167
165
|
throw new TooManyEmbeddingValuesForCallError({
|
|
168
166
|
provider: this.provider,
|
|
@@ -202,7 +200,7 @@ var GoogleVertexEmbeddingModel = class _GoogleVertexEmbeddingModel {
|
|
|
202
200
|
return {
|
|
203
201
|
warnings: [],
|
|
204
202
|
embeddings: [response2.embedding.values],
|
|
205
|
-
usage:
|
|
203
|
+
usage: response2.usageMetadata?.promptTokenCount == null ? void 0 : { tokens: response2.usageMetadata.promptTokenCount },
|
|
206
204
|
response: { headers: responseHeaders2, body: rawValue2 }
|
|
207
205
|
};
|
|
208
206
|
}
|
|
@@ -300,7 +298,6 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
|
300
298
|
return this.config.provider;
|
|
301
299
|
}
|
|
302
300
|
async doGenerate(options) {
|
|
303
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
304
301
|
if (!this.modelId.startsWith("gemini-")) {
|
|
305
302
|
throw new Error(
|
|
306
303
|
"Google image models other than Gemini are no longer supported. Use a model ID that starts with `gemini-`."
|
|
@@ -360,9 +357,9 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
|
360
357
|
const languageModel = new GoogleLanguageModel(this.modelId, {
|
|
361
358
|
provider: this.config.provider,
|
|
362
359
|
baseURL: this.config.baseURL,
|
|
363
|
-
headers:
|
|
360
|
+
headers: this.config.headers ?? {},
|
|
364
361
|
fetch: this.config.fetch,
|
|
365
|
-
generateId:
|
|
362
|
+
generateId: this.config.generateId ?? defaultGenerateId,
|
|
366
363
|
supportedUrls: () => ({
|
|
367
364
|
"*": [/^https?:\/\/.*$/, /^gs:\/\/.*$/]
|
|
368
365
|
})
|
|
@@ -371,7 +368,7 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
|
371
368
|
responseModalities: _strippedResponseModalities,
|
|
372
369
|
imageConfig: userImageConfig,
|
|
373
370
|
...userVertexOptions
|
|
374
|
-
} =
|
|
371
|
+
} = providerOptions?.googleVertex ?? providerOptions?.vertex ?? {};
|
|
375
372
|
const innerVertexOptions = {
|
|
376
373
|
...userVertexOptions,
|
|
377
374
|
responseModalities: ["IMAGE"],
|
|
@@ -392,7 +389,7 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
|
392
389
|
headers,
|
|
393
390
|
abortSignal
|
|
394
391
|
});
|
|
395
|
-
const currentDate =
|
|
392
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
396
393
|
const images = [];
|
|
397
394
|
for (const part of result.content) {
|
|
398
395
|
if (part.type === "file" && part.mediaType.startsWith("image/") && part.data.type === "data") {
|
|
@@ -413,12 +410,12 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
|
413
410
|
response: {
|
|
414
411
|
timestamp: currentDate,
|
|
415
412
|
modelId: this.modelId,
|
|
416
|
-
headers:
|
|
413
|
+
headers: result.response?.headers
|
|
417
414
|
},
|
|
418
415
|
usage: result.usage ? {
|
|
419
416
|
inputTokens: result.usage.inputTokens.total,
|
|
420
417
|
outputTokens: result.usage.outputTokens.total,
|
|
421
|
-
totalTokens: (
|
|
418
|
+
totalTokens: (result.usage.inputTokens.total ?? 0) + (result.usage.outputTokens.total ?? 0)
|
|
422
419
|
} : void 0
|
|
423
420
|
};
|
|
424
421
|
}
|
|
@@ -459,8 +456,7 @@ var GoogleVertexCloudTTSSpeechModel = class _GoogleVertexCloudTTSSpeechModel {
|
|
|
459
456
|
return this.config.provider;
|
|
460
457
|
}
|
|
461
458
|
async doGenerate(options) {
|
|
462
|
-
|
|
463
|
-
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
459
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
464
460
|
const warnings = [];
|
|
465
461
|
const {
|
|
466
462
|
text,
|
|
@@ -475,9 +471,9 @@ var GoogleVertexCloudTTSSpeechModel = class _GoogleVertexCloudTTSSpeechModel {
|
|
|
475
471
|
if (voice.includes(CHIRP3_HD_VOICE_INFIX)) {
|
|
476
472
|
voiceName = voice;
|
|
477
473
|
const localePrefix = voice.split(CHIRP3_HD_VOICE_INFIX)[0].replace(/-$/, "");
|
|
478
|
-
languageCode = language
|
|
474
|
+
languageCode = language ?? (localePrefix || DEFAULT_LANGUAGE);
|
|
479
475
|
} else {
|
|
480
|
-
languageCode = language
|
|
476
|
+
languageCode = language ?? DEFAULT_LANGUAGE;
|
|
481
477
|
voiceName = `${languageCode}-${CHIRP3_HD_VOICE_INFIX}-${voice}`;
|
|
482
478
|
}
|
|
483
479
|
if (instructions != null) {
|
|
@@ -618,7 +614,7 @@ function convertBcp47ToIso6391(value) {
|
|
|
618
614
|
try {
|
|
619
615
|
const language = new Intl.Locale(value).language;
|
|
620
616
|
return language.length === 2 ? language : void 0;
|
|
621
|
-
} catch
|
|
617
|
+
} catch {
|
|
622
618
|
return void 0;
|
|
623
619
|
}
|
|
624
620
|
}
|
|
@@ -641,8 +637,7 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
|
|
|
641
637
|
return this.config.provider;
|
|
642
638
|
}
|
|
643
639
|
async doGenerate(options) {
|
|
644
|
-
|
|
645
|
-
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
640
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
646
641
|
const warnings = [];
|
|
647
642
|
let googleOptions;
|
|
648
643
|
for (const provider of ["googleVertex", "vertex", "google"]) {
|
|
@@ -655,8 +650,8 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
|
|
|
655
650
|
break;
|
|
656
651
|
}
|
|
657
652
|
}
|
|
658
|
-
const region =
|
|
659
|
-
const languageCodes =
|
|
653
|
+
const region = googleOptions?.region ?? this.config.location;
|
|
654
|
+
const languageCodes = googleOptions?.languageCodes ?? ["auto"];
|
|
660
655
|
const content = typeof options.audio === "string" ? options.audio : convertUint8ArrayToBase64(options.audio);
|
|
661
656
|
const requestBody = {
|
|
662
657
|
config: {
|
|
@@ -666,8 +661,8 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
|
|
|
666
661
|
autoDecodingConfig: {},
|
|
667
662
|
features: {
|
|
668
663
|
// Word timing populates `segments`.
|
|
669
|
-
enableWordTimeOffsets:
|
|
670
|
-
enableAutomaticPunctuation:
|
|
664
|
+
enableWordTimeOffsets: googleOptions?.enableWordTimeOffsets ?? true,
|
|
665
|
+
enableAutomaticPunctuation: googleOptions?.enableAutomaticPunctuation ?? true
|
|
671
666
|
}
|
|
672
667
|
},
|
|
673
668
|
content
|
|
@@ -692,28 +687,22 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
|
|
|
692
687
|
abortSignal: options.abortSignal,
|
|
693
688
|
fetch: this.config.fetch
|
|
694
689
|
});
|
|
695
|
-
const results =
|
|
696
|
-
const text = results.map((result) =>
|
|
697
|
-
var _a2, _b2, _c2;
|
|
698
|
-
return (_c2 = (_b2 = (_a2 = result.alternatives) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.transcript) != null ? _c2 : "";
|
|
699
|
-
}).join(" ").trim();
|
|
690
|
+
const results = response.results ?? [];
|
|
691
|
+
const text = results.map((result) => result.alternatives?.[0]?.transcript ?? "").join(" ").trim();
|
|
700
692
|
const segments = results.flatMap(
|
|
701
|
-
(result) => {
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
return word.word == null || startSecond == null || endSecond == null ? [] : [{ text: word.word, startSecond, endSecond }];
|
|
707
|
-
})) != null ? _d2 : [];
|
|
708
|
-
}
|
|
693
|
+
(result) => result.alternatives?.[0]?.words?.flatMap((word) => {
|
|
694
|
+
const startSecond = parseDurationSeconds(word.startOffset);
|
|
695
|
+
const endSecond = parseDurationSeconds(word.endOffset);
|
|
696
|
+
return word.word == null || startSecond == null || endSecond == null ? [] : [{ text: word.word, startSecond, endSecond }];
|
|
697
|
+
}) ?? []
|
|
709
698
|
);
|
|
710
|
-
const language = convertBcp47ToIso6391(
|
|
699
|
+
const language = convertBcp47ToIso6391(results[0]?.languageCode);
|
|
711
700
|
return {
|
|
712
701
|
text,
|
|
713
702
|
segments,
|
|
714
703
|
language,
|
|
715
704
|
durationInSeconds: parseDurationSeconds(
|
|
716
|
-
|
|
705
|
+
response.metadata?.totalBilledDuration
|
|
717
706
|
),
|
|
718
707
|
warnings,
|
|
719
708
|
response: {
|
|
@@ -846,14 +835,13 @@ var GoogleVertexGeminiTranscriptionModel = class _GoogleVertexGeminiTranscriptio
|
|
|
846
835
|
}
|
|
847
836
|
}
|
|
848
837
|
async doGenerate(options) {
|
|
849
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
850
838
|
if (isLiveTranscriptionModelId(this.modelId)) {
|
|
851
839
|
throw new InvalidArgumentError({
|
|
852
840
|
argument: "modelId",
|
|
853
841
|
message: `Model '${this.modelId}' only supports streaming transcription. Use experimental_streamTranscribe, or a unary model such as 'gemini-3.5-transcribe'.`
|
|
854
842
|
});
|
|
855
843
|
}
|
|
856
|
-
const currentDate =
|
|
844
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
857
845
|
const warnings = [];
|
|
858
846
|
const googleOptions = await this.parseOptions(options.providerOptions);
|
|
859
847
|
const audioTranscriptionConfig = buildAudioTranscriptionConfig(googleOptions);
|
|
@@ -891,23 +879,17 @@ var GoogleVertexGeminiTranscriptionModel = class _GoogleVertexGeminiTranscriptio
|
|
|
891
879
|
abortSignal: options.abortSignal,
|
|
892
880
|
fetch: this.config.fetch
|
|
893
881
|
});
|
|
894
|
-
const parts =
|
|
895
|
-
const plainText = parts.map((part) =>
|
|
896
|
-
|
|
897
|
-
return (_a2 = part.text) != null ? _a2 : "";
|
|
898
|
-
}).join("");
|
|
899
|
-
const transcriptionText = parts.map((part) => {
|
|
900
|
-
var _a2, _b2;
|
|
901
|
-
return (_b2 = (_a2 = part.audioTranscription) == null ? void 0 : _a2.text) != null ? _b2 : "";
|
|
902
|
-
}).join("");
|
|
882
|
+
const parts = response.candidates?.[0]?.content?.parts ?? [];
|
|
883
|
+
const plainText = parts.map((part) => part.text ?? "").join("");
|
|
884
|
+
const transcriptionText = parts.map((part) => part.audioTranscription?.text ?? "").join("");
|
|
903
885
|
const text = plainText !== "" ? plainText : transcriptionText;
|
|
904
886
|
let language;
|
|
905
887
|
const segments = [];
|
|
906
888
|
for (const part of parts) {
|
|
907
889
|
const transcription = part.audioTranscription;
|
|
908
890
|
if (transcription == null) continue;
|
|
909
|
-
language
|
|
910
|
-
for (const word of
|
|
891
|
+
language ??= transcription.languageCode ?? void 0;
|
|
892
|
+
for (const word of transcription.words ?? []) {
|
|
911
893
|
const startSecond = parseOffsetSeconds(word.startOffset);
|
|
912
894
|
const endSecond = parseOffsetSeconds(word.endOffset);
|
|
913
895
|
if (word.word == null || startSecond == null || endSecond == null) {
|
|
@@ -936,14 +918,13 @@ var GoogleVertexGeminiTranscriptionModel = class _GoogleVertexGeminiTranscriptio
|
|
|
936
918
|
};
|
|
937
919
|
}
|
|
938
920
|
async doStream(options) {
|
|
939
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
940
921
|
if (!isLiveTranscriptionModelId(this.modelId)) {
|
|
941
922
|
throw new InvalidArgumentError({
|
|
942
923
|
argument: "modelId",
|
|
943
924
|
message: `Model '${this.modelId}' does not support streaming transcription. Use a live model such as 'gemini-3.5-transcribe-live'.`
|
|
944
925
|
});
|
|
945
926
|
}
|
|
946
|
-
const currentDate =
|
|
927
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
947
928
|
const warnings = [];
|
|
948
929
|
const googleOptions = await this.parseOptions(options.providerOptions);
|
|
949
930
|
validateLiveInputAudioFormat(options.inputAudioFormat);
|
|
@@ -958,7 +939,7 @@ var GoogleVertexGeminiTranscriptionModel = class _GoogleVertexGeminiTranscriptio
|
|
|
958
939
|
);
|
|
959
940
|
const setup = {
|
|
960
941
|
model: modelResource,
|
|
961
|
-
inputAudioTranscription:
|
|
942
|
+
inputAudioTranscription: buildAudioTranscriptionConfig(googleOptions) ?? {}
|
|
962
943
|
};
|
|
963
944
|
return {
|
|
964
945
|
request: { body: setup },
|
|
@@ -971,8 +952,8 @@ var GoogleVertexGeminiTranscriptionModel = class _GoogleVertexGeminiTranscriptio
|
|
|
971
952
|
url,
|
|
972
953
|
headers,
|
|
973
954
|
setup,
|
|
974
|
-
inputAudioRate:
|
|
975
|
-
finishGraceMs:
|
|
955
|
+
inputAudioRate: options.inputAudioFormat.rate ?? 16e3,
|
|
956
|
+
finishGraceMs: this.config._internal?.finishGraceMs ?? defaultFinishGraceMs,
|
|
976
957
|
warnings,
|
|
977
958
|
audio: options.audio,
|
|
978
959
|
abortSignal: options.abortSignal,
|
|
@@ -1036,7 +1017,7 @@ function createVertexLiveTranscriptionStream({
|
|
|
1036
1017
|
void audio.cancel().catch(() => {
|
|
1037
1018
|
});
|
|
1038
1019
|
}
|
|
1039
|
-
connection
|
|
1020
|
+
connection?.close(closeCode);
|
|
1040
1021
|
};
|
|
1041
1022
|
const finishWithError = (error) => {
|
|
1042
1023
|
if (finished) return;
|
|
@@ -1117,7 +1098,6 @@ function createVertexLiveTranscriptionStream({
|
|
|
1117
1098
|
void setupComplete.then(() => finished ? void 0 : sendAudio(socket)).catch(finishWithError);
|
|
1118
1099
|
},
|
|
1119
1100
|
onMessageText: async (text) => {
|
|
1120
|
-
var _a, _b;
|
|
1121
1101
|
if (finished) return;
|
|
1122
1102
|
const parsed = await safeParseJSON({ text });
|
|
1123
1103
|
if (!parsed.success) return;
|
|
@@ -1133,13 +1113,13 @@ function createVertexLiveTranscriptionStream({
|
|
|
1133
1113
|
}
|
|
1134
1114
|
if (message.error != null) {
|
|
1135
1115
|
finishWithError(
|
|
1136
|
-
new Error(
|
|
1116
|
+
new Error(message.error.message ?? "Vertex Live API error")
|
|
1137
1117
|
);
|
|
1138
1118
|
return;
|
|
1139
1119
|
}
|
|
1140
1120
|
const serverContent = message.serverContent;
|
|
1141
|
-
const interim = serverContent
|
|
1142
|
-
if (interim
|
|
1121
|
+
const interim = serverContent?.interimInputTranscription;
|
|
1122
|
+
if (interim?.text) {
|
|
1143
1123
|
schedulePendingFinish();
|
|
1144
1124
|
latestInterim = interim.text;
|
|
1145
1125
|
controller.enqueue({
|
|
@@ -1148,7 +1128,7 @@ function createVertexLiveTranscriptionStream({
|
|
|
1148
1128
|
text: interim.text
|
|
1149
1129
|
});
|
|
1150
1130
|
}
|
|
1151
|
-
const transcription =
|
|
1131
|
+
const transcription = serverContent?.inputTranscription ?? message.inputTranscription;
|
|
1152
1132
|
if (transcription != null) {
|
|
1153
1133
|
if (transcription.languageCode != null) {
|
|
1154
1134
|
language = transcription.languageCode;
|
|
@@ -1167,11 +1147,11 @@ function createVertexLiveTranscriptionStream({
|
|
|
1167
1147
|
completeSegment();
|
|
1168
1148
|
}
|
|
1169
1149
|
}
|
|
1170
|
-
if (serverContent
|
|
1150
|
+
if (serverContent?.turnComplete) {
|
|
1171
1151
|
completeSegment();
|
|
1172
1152
|
}
|
|
1173
|
-
const interactionStatus = serverContent
|
|
1174
|
-
if (audioEnded && (interactionStatus === "IDLE" || interactionStatus === "REQUIRES_ACTION" ||
|
|
1153
|
+
const interactionStatus = serverContent?.interactionStatus;
|
|
1154
|
+
if (audioEnded && (interactionStatus === "IDLE" || interactionStatus === "REQUIRES_ACTION" || serverContent?.turnComplete === true && interactionStatus == null)) {
|
|
1175
1155
|
finish();
|
|
1176
1156
|
}
|
|
1177
1157
|
},
|
|
@@ -1190,7 +1170,7 @@ function createVertexLiveTranscriptionStream({
|
|
|
1190
1170
|
}
|
|
1191
1171
|
finishWithError(
|
|
1192
1172
|
new Error(
|
|
1193
|
-
`Vertex Live transcription WebSocket closed unexpectedly before finishing (code ${code
|
|
1173
|
+
`Vertex Live transcription WebSocket closed unexpectedly before finishing (code ${code ?? "unknown"}${reason ? `, reason: ${reason}` : ""}).`
|
|
1194
1174
|
)
|
|
1195
1175
|
);
|
|
1196
1176
|
}
|
|
@@ -1300,16 +1280,13 @@ var googleVertexVideoModelOptionsSchema = lazySchema(
|
|
|
1300
1280
|
|
|
1301
1281
|
// src/google-vertex-video-model.ts
|
|
1302
1282
|
function getFirstFrameImage(options) {
|
|
1303
|
-
|
|
1304
|
-
return (_b = (_a = options.frameImages) == null ? void 0 : _a.find((frame) => frame.frameType === "first_frame")) == null ? void 0 : _b.image;
|
|
1283
|
+
return options.frameImages?.find((frame) => frame.frameType === "first_frame")?.image;
|
|
1305
1284
|
}
|
|
1306
1285
|
function resolveStartImage(options) {
|
|
1307
|
-
|
|
1308
|
-
return (_a = getFirstFrameImage(options)) != null ? _a : options.image;
|
|
1286
|
+
return getFirstFrameImage(options) ?? options.image;
|
|
1309
1287
|
}
|
|
1310
1288
|
function getLastFrameImage(options) {
|
|
1311
|
-
|
|
1312
|
-
return (_b = (_a = options.frameImages) == null ? void 0 : _a.find((frame) => frame.frameType === "last_frame")) == null ? void 0 : _b.image;
|
|
1289
|
+
return options.frameImages?.find((frame) => frame.frameType === "last_frame")?.image;
|
|
1313
1290
|
}
|
|
1314
1291
|
function getInputReferences(options) {
|
|
1315
1292
|
if (options.frameImages != null && options.frameImages.length > 0) {
|
|
@@ -1355,13 +1332,12 @@ var GoogleVertexVideoModel = class {
|
|
|
1355
1332
|
return 4;
|
|
1356
1333
|
}
|
|
1357
1334
|
async buildRequest(options) {
|
|
1358
|
-
var _a, _b;
|
|
1359
1335
|
const warnings = [];
|
|
1360
|
-
const googleVertexOptions =
|
|
1336
|
+
const googleVertexOptions = await parseProviderOptions4({
|
|
1361
1337
|
provider: "googleVertex",
|
|
1362
1338
|
providerOptions: options.providerOptions,
|
|
1363
1339
|
schema: googleVertexVideoModelOptionsSchema
|
|
1364
|
-
})
|
|
1340
|
+
}) ?? await parseProviderOptions4({
|
|
1365
1341
|
provider: "vertex",
|
|
1366
1342
|
providerOptions: options.providerOptions,
|
|
1367
1343
|
schema: googleVertexVideoModelOptionsSchema
|
|
@@ -1391,7 +1367,7 @@ var GoogleVertexVideoModel = class {
|
|
|
1391
1367
|
const converted = convertInputReferenceImage(reference, warnings);
|
|
1392
1368
|
return converted != null ? [converted] : [];
|
|
1393
1369
|
});
|
|
1394
|
-
} else if (
|
|
1370
|
+
} else if (googleVertexOptions?.referenceImages != null) {
|
|
1395
1371
|
instance.referenceImages = googleVertexOptions.referenceImages;
|
|
1396
1372
|
}
|
|
1397
1373
|
const parameters = {
|
|
@@ -1414,7 +1390,7 @@ var GoogleVertexVideoModel = class {
|
|
|
1414
1390
|
if (options.seed) {
|
|
1415
1391
|
parameters.seed = options.seed;
|
|
1416
1392
|
}
|
|
1417
|
-
const generateAudio =
|
|
1393
|
+
const generateAudio = options.generateAudio ?? googleVertexOptions?.generateAudio;
|
|
1418
1394
|
if (generateAudio != null) {
|
|
1419
1395
|
parameters.generateAudio = generateAudio;
|
|
1420
1396
|
}
|
|
@@ -1452,7 +1428,7 @@ var GoogleVertexVideoModel = class {
|
|
|
1452
1428
|
currentDate
|
|
1453
1429
|
}) {
|
|
1454
1430
|
const response = finalOperation.response;
|
|
1455
|
-
if (!
|
|
1431
|
+
if (!response?.videos || response.videos.length === 0) {
|
|
1456
1432
|
throw new AISDKError({
|
|
1457
1433
|
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
1458
1434
|
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
@@ -1509,8 +1485,7 @@ var GoogleVertexVideoModel = class {
|
|
|
1509
1485
|
};
|
|
1510
1486
|
}
|
|
1511
1487
|
async doStart(options) {
|
|
1512
|
-
|
|
1513
|
-
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1488
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
1514
1489
|
const { instances, parameters, warnings } = await this.buildRequest(options);
|
|
1515
1490
|
const { value: operation, responseHeaders } = await postJsonToApi5({
|
|
1516
1491
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
@@ -1547,8 +1522,7 @@ var GoogleVertexVideoModel = class {
|
|
|
1547
1522
|
};
|
|
1548
1523
|
}
|
|
1549
1524
|
async doStatus(options) {
|
|
1550
|
-
|
|
1551
|
-
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1525
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
1552
1526
|
const { operationName } = options.operation;
|
|
1553
1527
|
const { value: statusOperation, responseHeaders } = await postJsonToApi5({
|
|
1554
1528
|
url: `${this.config.baseURL}/models/${this.modelId}:fetchPredictOperation`,
|
|
@@ -1626,11 +1600,11 @@ function createExpressModeFetch(apiKey, customFetch) {
|
|
|
1626
1600
|
const modifiedInit = {
|
|
1627
1601
|
...init,
|
|
1628
1602
|
headers: {
|
|
1629
|
-
...
|
|
1603
|
+
...init?.headers ? normalizeHeaders(init.headers) : {},
|
|
1630
1604
|
"x-goog-api-key": apiKey
|
|
1631
1605
|
}
|
|
1632
1606
|
};
|
|
1633
|
-
return (customFetch
|
|
1607
|
+
return (customFetch ?? fetch)(url.toString(), modifiedInit);
|
|
1634
1608
|
};
|
|
1635
1609
|
}
|
|
1636
1610
|
function createGoogleVertex(options = {}) {
|
|
@@ -1651,9 +1625,8 @@ function createGoogleVertex(options = {}) {
|
|
|
1651
1625
|
description: "Google Vertex location"
|
|
1652
1626
|
});
|
|
1653
1627
|
const loadBaseURL = ({ endpoint = false } = {}) => {
|
|
1654
|
-
var _a, _b;
|
|
1655
1628
|
if (apiKey) {
|
|
1656
|
-
return
|
|
1629
|
+
return withoutTrailingSlash(options.baseURL) ?? EXPRESS_MODE_BASE_URL;
|
|
1657
1630
|
}
|
|
1658
1631
|
const region = loadGoogleVertexLocation();
|
|
1659
1632
|
const project = loadGoogleVertexProject();
|
|
@@ -1666,12 +1639,11 @@ function createGoogleVertex(options = {}) {
|
|
|
1666
1639
|
return `${region}-aiplatform.googleapis.com`;
|
|
1667
1640
|
}
|
|
1668
1641
|
};
|
|
1669
|
-
return
|
|
1642
|
+
return withoutTrailingSlash(options.baseURL) ?? `https://${getHost()}/v1beta1/projects/${project}/locations/${region}${endpoint ? "" : "/publishers/google"}`;
|
|
1670
1643
|
};
|
|
1671
1644
|
const createConfig = (name, { endpoint = false } = {}) => {
|
|
1672
1645
|
const getHeaders = async () => {
|
|
1673
|
-
|
|
1674
|
-
const originalHeaders = await resolve6((_a = options.headers) != null ? _a : {});
|
|
1646
|
+
const originalHeaders = await resolve6(options.headers ?? {});
|
|
1675
1647
|
return withUserAgentSuffix(
|
|
1676
1648
|
originalHeaders,
|
|
1677
1649
|
`ai-sdk/google-vertex/${VERSION}`
|
|
@@ -1685,7 +1657,6 @@ function createGoogleVertex(options = {}) {
|
|
|
1685
1657
|
};
|
|
1686
1658
|
};
|
|
1687
1659
|
const createChatModel = (modelId) => {
|
|
1688
|
-
var _a, _b, _c;
|
|
1689
1660
|
const endpoint = isEndpointModelId(modelId);
|
|
1690
1661
|
if (endpoint && apiKey) {
|
|
1691
1662
|
throw new Error(
|
|
@@ -1694,7 +1665,7 @@ function createGoogleVertex(options = {}) {
|
|
|
1694
1665
|
}
|
|
1695
1666
|
return new GoogleLanguageModel2(modelId, {
|
|
1696
1667
|
...createConfig("chat", { endpoint }),
|
|
1697
|
-
generateId:
|
|
1668
|
+
generateId: options.generateId ?? generateId,
|
|
1698
1669
|
supportedUrls: () => ({
|
|
1699
1670
|
"*": [
|
|
1700
1671
|
// HTTP URLs:
|
|
@@ -1704,12 +1675,12 @@ function createGoogleVertex(options = {}) {
|
|
|
1704
1675
|
]
|
|
1705
1676
|
}),
|
|
1706
1677
|
downloadToolResultFiles: {
|
|
1707
|
-
maxBytes:
|
|
1678
|
+
maxBytes: options.toolResultDownloads?.maxBytes ?? 7 * 1024 * 1024,
|
|
1679
|
+
supportsGoogleCloudStorageUrls: true
|
|
1708
1680
|
}
|
|
1709
1681
|
});
|
|
1710
1682
|
};
|
|
1711
1683
|
const createInteractionsModel = (modelIdOrAgent) => {
|
|
1712
|
-
var _a;
|
|
1713
1684
|
if (apiKey) {
|
|
1714
1685
|
throw new Error(
|
|
1715
1686
|
"Google Vertex Interactions models do not support Express Mode API keys. Use standard Google Cloud credentials instead."
|
|
@@ -1723,25 +1694,19 @@ function createGoogleVertex(options = {}) {
|
|
|
1723
1694
|
// endpoint-style base URL without the `/publishers/google` suffix that
|
|
1724
1695
|
// the base-model paths carry.
|
|
1725
1696
|
...createConfig("interactions", { endpoint: true }),
|
|
1726
|
-
generateId:
|
|
1697
|
+
generateId: options.generateId ?? generateId
|
|
1727
1698
|
}
|
|
1728
1699
|
);
|
|
1729
1700
|
};
|
|
1730
1701
|
const createEmbeddingModel = (modelId) => new GoogleVertexEmbeddingModel(modelId, createConfig("embedding"));
|
|
1731
|
-
const createImageModel = (modelId) => {
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
var _a;
|
|
1740
|
-
return new GoogleVertexVideoModel(modelId, {
|
|
1741
|
-
...createConfig("video"),
|
|
1742
|
-
generateId: (_a = options.generateId) != null ? _a : generateId
|
|
1743
|
-
});
|
|
1744
|
-
};
|
|
1702
|
+
const createImageModel = (modelId) => new GoogleVertexImageModel(modelId, {
|
|
1703
|
+
...createConfig("image"),
|
|
1704
|
+
generateId: options.generateId ?? generateId
|
|
1705
|
+
});
|
|
1706
|
+
const createVideoModel = (modelId) => new GoogleVertexVideoModel(modelId, {
|
|
1707
|
+
...createConfig("video"),
|
|
1708
|
+
generateId: options.generateId ?? generateId
|
|
1709
|
+
});
|
|
1745
1710
|
const createSpeechModel = (modelId) => {
|
|
1746
1711
|
if (modelId.startsWith("chirp")) {
|
|
1747
1712
|
if (apiKey) {
|