@ai-sdk/google-vertex 4.0.189 → 4.0.193
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 +33 -0
- package/dist/anthropic/edge/index.js +1 -1
- package/dist/anthropic/edge/index.mjs +1 -1
- package/dist/edge/index.js +280 -68
- package/dist/edge/index.js.map +1 -1
- package/dist/edge/index.mjs +266 -45
- package/dist/edge/index.mjs.map +1 -1
- package/dist/index.d.mts +47 -4
- package/dist/index.d.ts +47 -4
- package/dist/index.js +380 -166
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +377 -155
- 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/package.json +5 -5
- package/src/gemini-transcription/google-vertex-gemini-transcription-model-options.ts +51 -0
- package/src/gemini-transcription/google-vertex-gemini-transcription-model.ts +253 -0
- package/src/google-vertex-provider.ts +14 -0
- package/src/index.ts +5 -0
package/dist/edge/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/edge/google-vertex-provider-edge.ts
|
|
2
|
-
import { loadOptionalSetting as loadOptionalSetting3, resolve as
|
|
2
|
+
import { loadOptionalSetting as loadOptionalSetting3, resolve as resolve7 } from "@ai-sdk/provider-utils";
|
|
3
3
|
|
|
4
4
|
// src/google-vertex-provider.ts
|
|
5
5
|
import {
|
|
@@ -11,13 +11,13 @@ import {
|
|
|
11
11
|
loadOptionalSetting,
|
|
12
12
|
loadSetting,
|
|
13
13
|
normalizeHeaders,
|
|
14
|
-
resolve as
|
|
14
|
+
resolve as resolve6,
|
|
15
15
|
withoutTrailingSlash,
|
|
16
16
|
withUserAgentSuffix
|
|
17
17
|
} from "@ai-sdk/provider-utils";
|
|
18
18
|
|
|
19
19
|
// src/version.ts
|
|
20
|
-
var VERSION = true ? "4.0.
|
|
20
|
+
var VERSION = true ? "4.0.193" : "0.0.0-test";
|
|
21
21
|
|
|
22
22
|
// src/google-vertex-embedding-model.ts
|
|
23
23
|
import {
|
|
@@ -766,22 +766,235 @@ var googleVertexTranscriptionResponseSchema = z6.object({
|
|
|
766
766
|
}).nullish()
|
|
767
767
|
});
|
|
768
768
|
|
|
769
|
+
// src/gemini-transcription/google-vertex-gemini-transcription-model.ts
|
|
770
|
+
import {
|
|
771
|
+
InvalidArgumentError
|
|
772
|
+
} from "@ai-sdk/provider";
|
|
773
|
+
import {
|
|
774
|
+
combineHeaders as combineHeaders4,
|
|
775
|
+
convertToBase64 as convertToBase642,
|
|
776
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
777
|
+
parseProviderOptions as parseProviderOptions4,
|
|
778
|
+
postJsonToApi as postJsonToApi4,
|
|
779
|
+
resolve as resolve4
|
|
780
|
+
} from "@ai-sdk/provider-utils";
|
|
781
|
+
import { z as z8 } from "zod/v4";
|
|
782
|
+
|
|
783
|
+
// src/gemini-transcription/google-vertex-gemini-transcription-model-options.ts
|
|
784
|
+
import { z as z7 } from "zod/v4";
|
|
785
|
+
var googleVertexGeminiTranscriptionModelOptions = z7.object({
|
|
786
|
+
/**
|
|
787
|
+
* BCP-47 language codes providing hints about the languages present in the
|
|
788
|
+
* audio. If omitted or empty, defaults to automatic language detection.
|
|
789
|
+
*/
|
|
790
|
+
languageCodes: z7.array(z7.string()).optional(),
|
|
791
|
+
/**
|
|
792
|
+
* Custom vocabulary phrases, which bias the speech recognition model
|
|
793
|
+
* toward recognizing specific terms.
|
|
794
|
+
*/
|
|
795
|
+
customVocabulary: z7.array(z7.string()).optional(),
|
|
796
|
+
/**
|
|
797
|
+
* Enables word-level timestamp generation.
|
|
798
|
+
*/
|
|
799
|
+
wordTimestamp: z7.boolean().optional(),
|
|
800
|
+
/**
|
|
801
|
+
* Enables speaker diarization.
|
|
802
|
+
*/
|
|
803
|
+
diarization: z7.boolean().optional(),
|
|
804
|
+
/**
|
|
805
|
+
* Transcription output formatting mode.
|
|
806
|
+
*
|
|
807
|
+
* - `VERBATIM` (default): exact literal transcript preserving filler
|
|
808
|
+
* words, repetitions, and false starts.
|
|
809
|
+
* - `SMART`: cleans up and structures the transcript in real time —
|
|
810
|
+
* disfluency removal, inline self-corrections, structured formatting
|
|
811
|
+
* (lists, numbers, dates, paragraph breaks), and grammar/casing polish.
|
|
812
|
+
*/
|
|
813
|
+
mode: z7.enum(["SMART", "VERBATIM"]).optional()
|
|
814
|
+
});
|
|
815
|
+
|
|
816
|
+
// src/gemini-transcription/google-vertex-gemini-transcription-model.ts
|
|
817
|
+
function isLiveTranscriptionModelId(modelId) {
|
|
818
|
+
return modelId.includes("-live");
|
|
819
|
+
}
|
|
820
|
+
var GoogleVertexGeminiTranscriptionModel = class {
|
|
821
|
+
constructor(modelId, config) {
|
|
822
|
+
this.modelId = modelId;
|
|
823
|
+
this.config = config;
|
|
824
|
+
this.specificationVersion = "v3";
|
|
825
|
+
}
|
|
826
|
+
get provider() {
|
|
827
|
+
return this.config.provider;
|
|
828
|
+
}
|
|
829
|
+
async parseOptions(providerOptions) {
|
|
830
|
+
for (const provider of ["googleVertex", "vertex", "google"]) {
|
|
831
|
+
const parsed = await parseProviderOptions4({
|
|
832
|
+
provider,
|
|
833
|
+
providerOptions,
|
|
834
|
+
schema: googleVertexGeminiTranscriptionModelOptions
|
|
835
|
+
});
|
|
836
|
+
if (parsed != null) return parsed;
|
|
837
|
+
}
|
|
838
|
+
return void 0;
|
|
839
|
+
}
|
|
840
|
+
async doGenerate(options) {
|
|
841
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
842
|
+
if (isLiveTranscriptionModelId(this.modelId)) {
|
|
843
|
+
throw new InvalidArgumentError({
|
|
844
|
+
argument: "modelId",
|
|
845
|
+
message: `Model '${this.modelId}' only supports streaming transcription, which requires AI SDK v7. Use a unary model such as 'gemini-3.5-transcribe'.`
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
849
|
+
const warnings = [];
|
|
850
|
+
const googleOptions = await this.parseOptions(options.providerOptions);
|
|
851
|
+
const audioTranscriptionConfig = buildAudioTranscriptionConfig(googleOptions);
|
|
852
|
+
const requestBody = {
|
|
853
|
+
contents: [
|
|
854
|
+
{
|
|
855
|
+
role: "user",
|
|
856
|
+
parts: [
|
|
857
|
+
{
|
|
858
|
+
inlineData: {
|
|
859
|
+
mimeType: options.mediaType,
|
|
860
|
+
data: convertToBase642(options.audio)
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
]
|
|
864
|
+
}
|
|
865
|
+
],
|
|
866
|
+
...audioTranscriptionConfig != null ? { generationConfig: { audioTranscriptionConfig } } : {}
|
|
867
|
+
};
|
|
868
|
+
const {
|
|
869
|
+
value: response,
|
|
870
|
+
responseHeaders,
|
|
871
|
+
rawValue: rawResponse
|
|
872
|
+
} = await postJsonToApi4({
|
|
873
|
+
url: `${this.config.baseURL}/models/${this.modelId}:generateContent`,
|
|
874
|
+
headers: combineHeaders4(
|
|
875
|
+
this.config.headers ? await resolve4(this.config.headers) : void 0,
|
|
876
|
+
options.headers
|
|
877
|
+
),
|
|
878
|
+
body: requestBody,
|
|
879
|
+
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
880
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
881
|
+
googleVertexGeminiTranscriptionResponseSchema
|
|
882
|
+
),
|
|
883
|
+
abortSignal: options.abortSignal,
|
|
884
|
+
fetch: this.config.fetch
|
|
885
|
+
});
|
|
886
|
+
const parts = (_g = (_f = (_e = (_d = response.candidates) == null ? void 0 : _d[0]) == null ? void 0 : _e.content) == null ? void 0 : _f.parts) != null ? _g : [];
|
|
887
|
+
const plainText = parts.map((part) => {
|
|
888
|
+
var _a2;
|
|
889
|
+
return (_a2 = part.text) != null ? _a2 : "";
|
|
890
|
+
}).join("");
|
|
891
|
+
const transcriptionText = parts.map((part) => {
|
|
892
|
+
var _a2, _b2;
|
|
893
|
+
return (_b2 = (_a2 = part.audioTranscription) == null ? void 0 : _a2.text) != null ? _b2 : "";
|
|
894
|
+
}).join("");
|
|
895
|
+
const text = plainText !== "" ? plainText : transcriptionText;
|
|
896
|
+
let language;
|
|
897
|
+
const segments = [];
|
|
898
|
+
for (const part of parts) {
|
|
899
|
+
const transcription = part.audioTranscription;
|
|
900
|
+
if (transcription == null) continue;
|
|
901
|
+
language != null ? language : language = (_h = transcription.languageCode) != null ? _h : void 0;
|
|
902
|
+
for (const word of (_i = transcription.words) != null ? _i : []) {
|
|
903
|
+
const startSecond = parseOffsetSeconds(word.startOffset);
|
|
904
|
+
const endSecond = parseOffsetSeconds(word.endOffset);
|
|
905
|
+
if (word.word == null || startSecond == null || endSecond == null) {
|
|
906
|
+
continue;
|
|
907
|
+
}
|
|
908
|
+
segments.push({ text: word.word, startSecond, endSecond });
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
return {
|
|
912
|
+
text,
|
|
913
|
+
segments,
|
|
914
|
+
language,
|
|
915
|
+
durationInSeconds: void 0,
|
|
916
|
+
warnings,
|
|
917
|
+
response: {
|
|
918
|
+
timestamp: currentDate,
|
|
919
|
+
modelId: this.modelId,
|
|
920
|
+
headers: responseHeaders,
|
|
921
|
+
body: rawResponse
|
|
922
|
+
},
|
|
923
|
+
...response.usageMetadata != null ? {
|
|
924
|
+
providerMetadata: {
|
|
925
|
+
google: { usageMetadata: response.usageMetadata }
|
|
926
|
+
}
|
|
927
|
+
} : {}
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
};
|
|
931
|
+
function buildAudioTranscriptionConfig(options) {
|
|
932
|
+
if (options == null) return void 0;
|
|
933
|
+
const config = {};
|
|
934
|
+
if (options.languageCodes != null) {
|
|
935
|
+
config.languageCodes = options.languageCodes;
|
|
936
|
+
}
|
|
937
|
+
if (options.customVocabulary != null) {
|
|
938
|
+
config.customVocabulary = options.customVocabulary;
|
|
939
|
+
}
|
|
940
|
+
if (options.wordTimestamp != null) {
|
|
941
|
+
config.wordTimestamp = options.wordTimestamp;
|
|
942
|
+
}
|
|
943
|
+
if (options.diarization != null) {
|
|
944
|
+
config.diarization = options.diarization;
|
|
945
|
+
}
|
|
946
|
+
if (options.mode != null) {
|
|
947
|
+
config.mode = options.mode;
|
|
948
|
+
}
|
|
949
|
+
return Object.keys(config).length > 0 ? config : void 0;
|
|
950
|
+
}
|
|
951
|
+
function parseOffsetSeconds(offset) {
|
|
952
|
+
if (offset == null) return void 0;
|
|
953
|
+
const parsed = Number.parseFloat(offset);
|
|
954
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
955
|
+
}
|
|
956
|
+
var googleVertexGeminiTranscriptionWordSchema = z8.object({
|
|
957
|
+
word: z8.string().nullish(),
|
|
958
|
+
startOffset: z8.string().nullish(),
|
|
959
|
+
endOffset: z8.string().nullish()
|
|
960
|
+
});
|
|
961
|
+
var googleVertexGeminiTranscriptionResponseSchema = z8.object({
|
|
962
|
+
candidates: z8.array(
|
|
963
|
+
z8.object({
|
|
964
|
+
content: z8.object({
|
|
965
|
+
parts: z8.array(
|
|
966
|
+
z8.object({
|
|
967
|
+
text: z8.string().nullish(),
|
|
968
|
+
audioTranscription: z8.object({
|
|
969
|
+
text: z8.string().nullish(),
|
|
970
|
+
languageCode: z8.string().nullish(),
|
|
971
|
+
speakerLabel: z8.string().nullish(),
|
|
972
|
+
words: z8.array(googleVertexGeminiTranscriptionWordSchema).nullish()
|
|
973
|
+
}).nullish()
|
|
974
|
+
})
|
|
975
|
+
).nullish()
|
|
976
|
+
}).nullish()
|
|
977
|
+
})
|
|
978
|
+
).nullish(),
|
|
979
|
+
usageMetadata: z8.record(z8.string(), z8.unknown()).nullish()
|
|
980
|
+
});
|
|
981
|
+
|
|
769
982
|
// src/google-vertex-video-model.ts
|
|
770
983
|
import {
|
|
771
984
|
AISDKError
|
|
772
985
|
} from "@ai-sdk/provider";
|
|
773
986
|
import {
|
|
774
|
-
combineHeaders as
|
|
987
|
+
combineHeaders as combineHeaders5,
|
|
775
988
|
convertUint8ArrayToBase64 as convertUint8ArrayToBase643,
|
|
776
|
-
createJsonResponseHandler as
|
|
989
|
+
createJsonResponseHandler as createJsonResponseHandler5,
|
|
777
990
|
delay,
|
|
778
991
|
lazySchema,
|
|
779
|
-
parseProviderOptions as
|
|
780
|
-
postJsonToApi as
|
|
781
|
-
resolve as
|
|
992
|
+
parseProviderOptions as parseProviderOptions5,
|
|
993
|
+
postJsonToApi as postJsonToApi5,
|
|
994
|
+
resolve as resolve5,
|
|
782
995
|
zodSchema
|
|
783
996
|
} from "@ai-sdk/provider-utils";
|
|
784
|
-
import { z as
|
|
997
|
+
import { z as z9 } from "zod/v4";
|
|
785
998
|
function getFirstFrameImage(options) {
|
|
786
999
|
var _a, _b;
|
|
787
1000
|
return (_b = (_a = options.frameImages) == null ? void 0 : _a.find((frame) => frame.frameType === "first_frame")) == null ? void 0 : _b.image;
|
|
@@ -841,7 +1054,7 @@ var GoogleVertexVideoModel = class {
|
|
|
841
1054
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
842
1055
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
843
1056
|
const warnings = [];
|
|
844
|
-
const vertexOptions = await
|
|
1057
|
+
const vertexOptions = await parseProviderOptions5({
|
|
845
1058
|
provider: "vertex",
|
|
846
1059
|
providerOptions: options.providerOptions,
|
|
847
1060
|
schema: googleVertexVideoModelOptionsSchema
|
|
@@ -923,17 +1136,17 @@ var GoogleVertexVideoModel = class {
|
|
|
923
1136
|
}
|
|
924
1137
|
}
|
|
925
1138
|
}
|
|
926
|
-
const { value: operation } = await
|
|
1139
|
+
const { value: operation } = await postJsonToApi5({
|
|
927
1140
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
928
|
-
headers:
|
|
929
|
-
await
|
|
1141
|
+
headers: combineHeaders5(
|
|
1142
|
+
await resolve5(this.config.headers),
|
|
930
1143
|
options.headers
|
|
931
1144
|
),
|
|
932
1145
|
body: {
|
|
933
1146
|
instances,
|
|
934
1147
|
parameters
|
|
935
1148
|
},
|
|
936
|
-
successfulResponseHandler:
|
|
1149
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
937
1150
|
vertexOperationSchema
|
|
938
1151
|
),
|
|
939
1152
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
@@ -966,16 +1179,16 @@ var GoogleVertexVideoModel = class {
|
|
|
966
1179
|
message: "Video generation request was aborted"
|
|
967
1180
|
});
|
|
968
1181
|
}
|
|
969
|
-
const { value: statusOperation, responseHeaders: pollHeaders } = await
|
|
1182
|
+
const { value: statusOperation, responseHeaders: pollHeaders } = await postJsonToApi5({
|
|
970
1183
|
url: `${this.config.baseURL}/models/${this.modelId}:fetchPredictOperation`,
|
|
971
|
-
headers:
|
|
972
|
-
await
|
|
1184
|
+
headers: combineHeaders5(
|
|
1185
|
+
await resolve5(this.config.headers),
|
|
973
1186
|
options.headers
|
|
974
1187
|
),
|
|
975
1188
|
body: {
|
|
976
1189
|
operationName
|
|
977
1190
|
},
|
|
978
|
-
successfulResponseHandler:
|
|
1191
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
979
1192
|
vertexOperationSchema
|
|
980
1193
|
),
|
|
981
1194
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
@@ -1044,38 +1257,38 @@ var GoogleVertexVideoModel = class {
|
|
|
1044
1257
|
};
|
|
1045
1258
|
}
|
|
1046
1259
|
};
|
|
1047
|
-
var vertexOperationSchema =
|
|
1048
|
-
name:
|
|
1049
|
-
done:
|
|
1050
|
-
error:
|
|
1051
|
-
code:
|
|
1052
|
-
message:
|
|
1053
|
-
status:
|
|
1260
|
+
var vertexOperationSchema = z9.object({
|
|
1261
|
+
name: z9.string().nullish(),
|
|
1262
|
+
done: z9.boolean().nullish(),
|
|
1263
|
+
error: z9.object({
|
|
1264
|
+
code: z9.number().nullish(),
|
|
1265
|
+
message: z9.string(),
|
|
1266
|
+
status: z9.string().nullish()
|
|
1054
1267
|
}).nullish(),
|
|
1055
|
-
response:
|
|
1056
|
-
videos:
|
|
1057
|
-
|
|
1058
|
-
bytesBase64Encoded:
|
|
1059
|
-
gcsUri:
|
|
1060
|
-
mimeType:
|
|
1268
|
+
response: z9.object({
|
|
1269
|
+
videos: z9.array(
|
|
1270
|
+
z9.object({
|
|
1271
|
+
bytesBase64Encoded: z9.string().nullish(),
|
|
1272
|
+
gcsUri: z9.string().nullish(),
|
|
1273
|
+
mimeType: z9.string().nullish()
|
|
1061
1274
|
})
|
|
1062
1275
|
).nullish(),
|
|
1063
|
-
raiMediaFilteredCount:
|
|
1276
|
+
raiMediaFilteredCount: z9.number().nullish()
|
|
1064
1277
|
}).nullish()
|
|
1065
1278
|
});
|
|
1066
1279
|
var googleVertexVideoModelOptionsSchema = lazySchema(
|
|
1067
1280
|
() => zodSchema(
|
|
1068
|
-
|
|
1069
|
-
pollIntervalMs:
|
|
1070
|
-
pollTimeoutMs:
|
|
1071
|
-
personGeneration:
|
|
1072
|
-
negativePrompt:
|
|
1073
|
-
generateAudio:
|
|
1074
|
-
gcsOutputDirectory:
|
|
1075
|
-
referenceImages:
|
|
1076
|
-
|
|
1077
|
-
bytesBase64Encoded:
|
|
1078
|
-
gcsUri:
|
|
1281
|
+
z9.object({
|
|
1282
|
+
pollIntervalMs: z9.number().positive().nullish(),
|
|
1283
|
+
pollTimeoutMs: z9.number().positive().nullish(),
|
|
1284
|
+
personGeneration: z9.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
1285
|
+
negativePrompt: z9.string().nullish(),
|
|
1286
|
+
generateAudio: z9.boolean().nullish(),
|
|
1287
|
+
gcsOutputDirectory: z9.string().nullish(),
|
|
1288
|
+
referenceImages: z9.array(
|
|
1289
|
+
z9.object({
|
|
1290
|
+
bytesBase64Encoded: z9.string().nullish(),
|
|
1291
|
+
gcsUri: z9.string().nullish()
|
|
1079
1292
|
})
|
|
1080
1293
|
).nullish()
|
|
1081
1294
|
}).passthrough()
|
|
@@ -1134,7 +1347,7 @@ function createVertex(options = {}) {
|
|
|
1134
1347
|
const createConfig = (name, { endpoint = false } = {}) => {
|
|
1135
1348
|
const getHeaders = async () => {
|
|
1136
1349
|
var _a;
|
|
1137
|
-
const originalHeaders = await
|
|
1350
|
+
const originalHeaders = await resolve6((_a = options.headers) != null ? _a : {});
|
|
1138
1351
|
return withUserAgentSuffix(
|
|
1139
1352
|
originalHeaders,
|
|
1140
1353
|
`ai-sdk/google-vertex/${VERSION}`
|
|
@@ -1203,6 +1416,14 @@ function createVertex(options = {}) {
|
|
|
1203
1416
|
);
|
|
1204
1417
|
}
|
|
1205
1418
|
const config = createConfig("transcription");
|
|
1419
|
+
if (modelId.startsWith("gemini")) {
|
|
1420
|
+
return new GoogleVertexGeminiTranscriptionModel(modelId, {
|
|
1421
|
+
provider: config.provider,
|
|
1422
|
+
baseURL: loadBaseURL(),
|
|
1423
|
+
headers: config.headers,
|
|
1424
|
+
fetch: config.fetch
|
|
1425
|
+
});
|
|
1426
|
+
}
|
|
1206
1427
|
return new GoogleVertexTranscriptionModel(modelId, {
|
|
1207
1428
|
provider: config.provider,
|
|
1208
1429
|
headers: config.headers,
|
|
@@ -1360,7 +1581,7 @@ function createVertex2(options = {}) {
|
|
|
1360
1581
|
Authorization: `Bearer ${await generateAuthToken(
|
|
1361
1582
|
options.googleCredentials
|
|
1362
1583
|
)}`,
|
|
1363
|
-
...await
|
|
1584
|
+
...await resolve7(options.headers)
|
|
1364
1585
|
})
|
|
1365
1586
|
});
|
|
1366
1587
|
}
|