@ai-sdk/google-vertex 5.0.65 → 5.0.67
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 +15 -0
- package/dist/anthropic/edge/index.js +1 -1
- package/dist/edge/index.d.ts +7 -1
- package/dist/edge/index.js +571 -45
- package/dist/edge/index.js.map +1 -1
- package/dist/index.d.ts +67 -3
- package/dist/index.js +572 -45
- package/dist/index.js.map +1 -1
- package/dist/maas/edge/index.js +1 -1
- package/dist/xai/edge/index.js +1 -1
- package/package.json +2 -2
- package/src/gemini-transcription/google-vertex-gemini-transcription-model-options.ts +51 -0
- package/src/gemini-transcription/google-vertex-gemini-transcription-model.ts +709 -0
- package/src/google-vertex-provider-base.ts +25 -0
- package/src/index.ts +5 -0
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/google-vertex-provider.ts
|
|
2
|
-
import { loadOptionalSetting as loadOptionalSetting2, resolve as
|
|
2
|
+
import { loadOptionalSetting as loadOptionalSetting2, resolve as resolve7 } from "@ai-sdk/provider-utils";
|
|
3
3
|
|
|
4
4
|
// src/google-vertex-auth-google-auth-library.ts
|
|
5
5
|
import { GoogleAuth } from "google-auth-library";
|
|
@@ -27,13 +27,13 @@ import {
|
|
|
27
27
|
loadOptionalSetting,
|
|
28
28
|
loadSetting,
|
|
29
29
|
normalizeHeaders,
|
|
30
|
-
resolve as
|
|
30
|
+
resolve as resolve6,
|
|
31
31
|
withoutTrailingSlash,
|
|
32
32
|
withUserAgentSuffix
|
|
33
33
|
} from "@ai-sdk/provider-utils";
|
|
34
34
|
|
|
35
35
|
// src/version.ts
|
|
36
|
-
var VERSION = true ? "5.0.
|
|
36
|
+
var VERSION = true ? "5.0.67" : "0.0.0-test";
|
|
37
37
|
|
|
38
38
|
// src/google-vertex-embedding-model.ts
|
|
39
39
|
import {
|
|
@@ -753,36 +753,551 @@ var googleVertexTranscriptionResponseSchema = z6.object({
|
|
|
753
753
|
}).nullish()
|
|
754
754
|
});
|
|
755
755
|
|
|
756
|
-
// src/google-vertex-
|
|
756
|
+
// src/gemini-transcription/google-vertex-gemini-transcription-model.ts
|
|
757
757
|
import {
|
|
758
|
-
|
|
758
|
+
InvalidArgumentError
|
|
759
759
|
} from "@ai-sdk/provider";
|
|
760
760
|
import {
|
|
761
761
|
combineHeaders as combineHeaders4,
|
|
762
|
-
|
|
762
|
+
connectToWebSocket,
|
|
763
|
+
convertToBase64 as convertToBase642,
|
|
763
764
|
createJsonResponseHandler as createJsonResponseHandler4,
|
|
764
765
|
parseProviderOptions as parseProviderOptions3,
|
|
765
766
|
postJsonToApi as postJsonToApi4,
|
|
766
|
-
resolve as resolve4
|
|
767
|
+
resolve as resolve4,
|
|
768
|
+
safeParseJSON,
|
|
769
|
+
serializeModelOptions as serializeModelOptions5,
|
|
770
|
+
waitForWebSocketBufferDrain,
|
|
771
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE5,
|
|
772
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE5
|
|
767
773
|
} from "@ai-sdk/provider-utils";
|
|
768
774
|
import { z as z8 } from "zod/v4";
|
|
769
775
|
|
|
776
|
+
// src/gemini-transcription/google-vertex-gemini-transcription-model-options.ts
|
|
777
|
+
import { z as z7 } from "zod/v4";
|
|
778
|
+
var googleVertexGeminiTranscriptionModelOptions = z7.object({
|
|
779
|
+
/**
|
|
780
|
+
* BCP-47 language codes providing hints about the languages present in the
|
|
781
|
+
* audio. If omitted or empty, defaults to automatic language detection.
|
|
782
|
+
*/
|
|
783
|
+
languageCodes: z7.array(z7.string()).optional(),
|
|
784
|
+
/**
|
|
785
|
+
* Custom vocabulary phrases, which bias the speech recognition model
|
|
786
|
+
* toward recognizing specific terms.
|
|
787
|
+
*/
|
|
788
|
+
customVocabulary: z7.array(z7.string()).optional(),
|
|
789
|
+
/**
|
|
790
|
+
* Enables word-level timestamp generation.
|
|
791
|
+
*/
|
|
792
|
+
wordTimestamp: z7.boolean().optional(),
|
|
793
|
+
/**
|
|
794
|
+
* Enables speaker diarization.
|
|
795
|
+
*/
|
|
796
|
+
diarization: z7.boolean().optional(),
|
|
797
|
+
/**
|
|
798
|
+
* Transcription output formatting mode.
|
|
799
|
+
*
|
|
800
|
+
* - `VERBATIM` (default): exact literal transcript preserving filler
|
|
801
|
+
* words, repetitions, and false starts.
|
|
802
|
+
* - `SMART`: cleans up and structures the transcript in real time —
|
|
803
|
+
* disfluency removal, inline self-corrections, structured formatting
|
|
804
|
+
* (lists, numbers, dates, paragraph breaks), and grammar/casing polish.
|
|
805
|
+
*/
|
|
806
|
+
mode: z7.enum(["SMART", "VERBATIM"]).optional()
|
|
807
|
+
});
|
|
808
|
+
|
|
809
|
+
// src/gemini-transcription/google-vertex-gemini-transcription-model.ts
|
|
810
|
+
var liveWebSocketPath = "google.cloud.aiplatform.v1.LlmBidiService/BidiGenerateContent";
|
|
811
|
+
var defaultFinishGraceMs = 3e3;
|
|
812
|
+
function isLiveTranscriptionModelId(modelId) {
|
|
813
|
+
return modelId.includes("-live");
|
|
814
|
+
}
|
|
815
|
+
function vertexHost(location) {
|
|
816
|
+
if (location === "global") return "aiplatform.googleapis.com";
|
|
817
|
+
if (location === "eu" || location === "us") {
|
|
818
|
+
return `aiplatform.${location}.rep.googleapis.com`;
|
|
819
|
+
}
|
|
820
|
+
return `${location}-aiplatform.googleapis.com`;
|
|
821
|
+
}
|
|
822
|
+
var GoogleVertexGeminiTranscriptionModel = class _GoogleVertexGeminiTranscriptionModel {
|
|
823
|
+
constructor(modelId, config) {
|
|
824
|
+
this.modelId = modelId;
|
|
825
|
+
this.config = config;
|
|
826
|
+
this.specificationVersion = "v4";
|
|
827
|
+
}
|
|
828
|
+
static [WORKFLOW_SERIALIZE5](model) {
|
|
829
|
+
return serializeModelOptions5({
|
|
830
|
+
modelId: model.modelId,
|
|
831
|
+
config: model.config
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
static [WORKFLOW_DESERIALIZE5](options) {
|
|
835
|
+
return new _GoogleVertexGeminiTranscriptionModel(
|
|
836
|
+
options.modelId,
|
|
837
|
+
options.config
|
|
838
|
+
);
|
|
839
|
+
}
|
|
840
|
+
get provider() {
|
|
841
|
+
return this.config.provider;
|
|
842
|
+
}
|
|
843
|
+
async parseOptions(providerOptions) {
|
|
844
|
+
for (const provider of ["googleVertex", "vertex", "google"]) {
|
|
845
|
+
const parsed = await parseProviderOptions3({
|
|
846
|
+
provider,
|
|
847
|
+
providerOptions,
|
|
848
|
+
schema: googleVertexGeminiTranscriptionModelOptions
|
|
849
|
+
});
|
|
850
|
+
if (parsed != null) return parsed;
|
|
851
|
+
}
|
|
852
|
+
return void 0;
|
|
853
|
+
}
|
|
854
|
+
async doGenerate(options) {
|
|
855
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
856
|
+
if (isLiveTranscriptionModelId(this.modelId)) {
|
|
857
|
+
throw new InvalidArgumentError({
|
|
858
|
+
argument: "modelId",
|
|
859
|
+
message: `Model '${this.modelId}' only supports streaming transcription. Use experimental_streamTranscribe, or a unary model such as 'gemini-3.5-transcribe'.`
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
863
|
+
const warnings = [];
|
|
864
|
+
const googleOptions = await this.parseOptions(options.providerOptions);
|
|
865
|
+
const audioTranscriptionConfig = buildAudioTranscriptionConfig(googleOptions);
|
|
866
|
+
const requestBody = {
|
|
867
|
+
contents: [
|
|
868
|
+
{
|
|
869
|
+
role: "user",
|
|
870
|
+
parts: [
|
|
871
|
+
{
|
|
872
|
+
inlineData: {
|
|
873
|
+
mimeType: options.mediaType,
|
|
874
|
+
data: convertToBase642(options.audio)
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
]
|
|
878
|
+
}
|
|
879
|
+
],
|
|
880
|
+
...audioTranscriptionConfig != null ? { generationConfig: { audioTranscriptionConfig } } : {}
|
|
881
|
+
};
|
|
882
|
+
const {
|
|
883
|
+
value: response,
|
|
884
|
+
responseHeaders,
|
|
885
|
+
rawValue: rawResponse
|
|
886
|
+
} = await postJsonToApi4({
|
|
887
|
+
url: `${this.config.baseURL}/models/${this.modelId}:generateContent`,
|
|
888
|
+
headers: combineHeaders4(
|
|
889
|
+
this.config.headers ? await resolve4(this.config.headers) : void 0,
|
|
890
|
+
options.headers
|
|
891
|
+
),
|
|
892
|
+
body: requestBody,
|
|
893
|
+
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
894
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
895
|
+
googleVertexGeminiTranscriptionResponseSchema
|
|
896
|
+
),
|
|
897
|
+
abortSignal: options.abortSignal,
|
|
898
|
+
fetch: this.config.fetch
|
|
899
|
+
});
|
|
900
|
+
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 : [];
|
|
901
|
+
const plainText = parts.map((part) => {
|
|
902
|
+
var _a2;
|
|
903
|
+
return (_a2 = part.text) != null ? _a2 : "";
|
|
904
|
+
}).join("");
|
|
905
|
+
const transcriptionText = parts.map((part) => {
|
|
906
|
+
var _a2, _b2;
|
|
907
|
+
return (_b2 = (_a2 = part.audioTranscription) == null ? void 0 : _a2.text) != null ? _b2 : "";
|
|
908
|
+
}).join("");
|
|
909
|
+
const text = plainText !== "" ? plainText : transcriptionText;
|
|
910
|
+
let language;
|
|
911
|
+
const segments = [];
|
|
912
|
+
for (const part of parts) {
|
|
913
|
+
const transcription = part.audioTranscription;
|
|
914
|
+
if (transcription == null) continue;
|
|
915
|
+
language != null ? language : language = (_h = transcription.languageCode) != null ? _h : void 0;
|
|
916
|
+
for (const word of (_i = transcription.words) != null ? _i : []) {
|
|
917
|
+
const startSecond = parseOffsetSeconds(word.startOffset);
|
|
918
|
+
const endSecond = parseOffsetSeconds(word.endOffset);
|
|
919
|
+
if (word.word == null || startSecond == null || endSecond == null) {
|
|
920
|
+
continue;
|
|
921
|
+
}
|
|
922
|
+
segments.push({ text: word.word, startSecond, endSecond });
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
return {
|
|
926
|
+
text,
|
|
927
|
+
segments,
|
|
928
|
+
language,
|
|
929
|
+
durationInSeconds: void 0,
|
|
930
|
+
warnings,
|
|
931
|
+
response: {
|
|
932
|
+
timestamp: currentDate,
|
|
933
|
+
modelId: this.modelId,
|
|
934
|
+
headers: responseHeaders,
|
|
935
|
+
body: rawResponse
|
|
936
|
+
},
|
|
937
|
+
...response.usageMetadata != null ? {
|
|
938
|
+
providerMetadata: {
|
|
939
|
+
google: { usageMetadata: response.usageMetadata }
|
|
940
|
+
}
|
|
941
|
+
} : {}
|
|
942
|
+
};
|
|
943
|
+
}
|
|
944
|
+
async doStream(options) {
|
|
945
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
946
|
+
if (!isLiveTranscriptionModelId(this.modelId)) {
|
|
947
|
+
throw new InvalidArgumentError({
|
|
948
|
+
argument: "modelId",
|
|
949
|
+
message: `Model '${this.modelId}' does not support streaming transcription. Use a live model such as 'gemini-3.5-transcribe-live'.`
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
953
|
+
const warnings = [];
|
|
954
|
+
const googleOptions = await this.parseOptions(options.providerOptions);
|
|
955
|
+
validateLiveInputAudioFormat(options.inputAudioFormat);
|
|
956
|
+
const headers = combineHeaders4(
|
|
957
|
+
this.config.headers ? await resolve4(this.config.headers) : void 0,
|
|
958
|
+
options.headers
|
|
959
|
+
);
|
|
960
|
+
const { project, location } = this.config;
|
|
961
|
+
const modelResource = `projects/${project}/locations/${location}/publishers/google/models/${this.modelId}`;
|
|
962
|
+
const url = new URL(
|
|
963
|
+
`wss://${vertexHost(location)}/ws/${liveWebSocketPath}`
|
|
964
|
+
);
|
|
965
|
+
const setup = {
|
|
966
|
+
model: modelResource,
|
|
967
|
+
inputAudioTranscription: (_d = buildAudioTranscriptionConfig(googleOptions)) != null ? _d : {}
|
|
968
|
+
};
|
|
969
|
+
return {
|
|
970
|
+
request: { body: setup },
|
|
971
|
+
response: {
|
|
972
|
+
timestamp: currentDate,
|
|
973
|
+
modelId: this.modelId
|
|
974
|
+
},
|
|
975
|
+
stream: createVertexLiveTranscriptionStream({
|
|
976
|
+
webSocket: this.config.webSocket,
|
|
977
|
+
url,
|
|
978
|
+
headers,
|
|
979
|
+
setup,
|
|
980
|
+
inputAudioRate: (_e = options.inputAudioFormat.rate) != null ? _e : 16e3,
|
|
981
|
+
finishGraceMs: (_g = (_f = this.config._internal) == null ? void 0 : _f.finishGraceMs) != null ? _g : defaultFinishGraceMs,
|
|
982
|
+
warnings,
|
|
983
|
+
audio: options.audio,
|
|
984
|
+
abortSignal: options.abortSignal,
|
|
985
|
+
includeRawChunks: options.includeRawChunks
|
|
986
|
+
})
|
|
987
|
+
};
|
|
988
|
+
}
|
|
989
|
+
};
|
|
990
|
+
function createVertexLiveTranscriptionStream({
|
|
991
|
+
webSocket,
|
|
992
|
+
url,
|
|
993
|
+
headers,
|
|
994
|
+
setup,
|
|
995
|
+
inputAudioRate,
|
|
996
|
+
finishGraceMs,
|
|
997
|
+
warnings,
|
|
998
|
+
audio,
|
|
999
|
+
abortSignal,
|
|
1000
|
+
includeRawChunks
|
|
1001
|
+
}) {
|
|
1002
|
+
let finished = false;
|
|
1003
|
+
let cleanup = () => {
|
|
1004
|
+
};
|
|
1005
|
+
return new ReadableStream({
|
|
1006
|
+
start: (controller) => {
|
|
1007
|
+
let audioReader;
|
|
1008
|
+
let connection;
|
|
1009
|
+
let resolveSetupComplete;
|
|
1010
|
+
const setupComplete = new Promise((resolvePromise) => {
|
|
1011
|
+
resolveSetupComplete = resolvePromise;
|
|
1012
|
+
});
|
|
1013
|
+
let segmentCounter = 0;
|
|
1014
|
+
let segmentBuffer = "";
|
|
1015
|
+
let fullText = "";
|
|
1016
|
+
let latestInterim = "";
|
|
1017
|
+
let language;
|
|
1018
|
+
let audioEnded = false;
|
|
1019
|
+
let usageMetadata;
|
|
1020
|
+
let finishTimer;
|
|
1021
|
+
const segmentId = () => `google-segment-${segmentCounter}`;
|
|
1022
|
+
const cancelPendingFinish = () => {
|
|
1023
|
+
if (finishTimer != null) {
|
|
1024
|
+
clearTimeout(finishTimer);
|
|
1025
|
+
finishTimer = void 0;
|
|
1026
|
+
}
|
|
1027
|
+
};
|
|
1028
|
+
const schedulePendingFinish = () => {
|
|
1029
|
+
if (finished || !audioEnded) return;
|
|
1030
|
+
cancelPendingFinish();
|
|
1031
|
+
finishTimer = setTimeout(() => {
|
|
1032
|
+
finishTimer = void 0;
|
|
1033
|
+
finish();
|
|
1034
|
+
}, finishGraceMs);
|
|
1035
|
+
};
|
|
1036
|
+
cleanup = (closeCode) => {
|
|
1037
|
+
cancelPendingFinish();
|
|
1038
|
+
if (audioReader != null) {
|
|
1039
|
+
void audioReader.cancel().catch(() => {
|
|
1040
|
+
});
|
|
1041
|
+
} else {
|
|
1042
|
+
void audio.cancel().catch(() => {
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
connection == null ? void 0 : connection.close(closeCode);
|
|
1046
|
+
};
|
|
1047
|
+
const finishWithError = (error) => {
|
|
1048
|
+
if (finished) return;
|
|
1049
|
+
finished = true;
|
|
1050
|
+
cleanup();
|
|
1051
|
+
controller.error(error);
|
|
1052
|
+
};
|
|
1053
|
+
const completeSegment = () => {
|
|
1054
|
+
if (segmentBuffer === "") {
|
|
1055
|
+
if (latestInterim === "") return;
|
|
1056
|
+
segmentBuffer = latestInterim;
|
|
1057
|
+
}
|
|
1058
|
+
latestInterim = "";
|
|
1059
|
+
controller.enqueue({
|
|
1060
|
+
type: "transcript-final",
|
|
1061
|
+
id: segmentId(),
|
|
1062
|
+
text: segmentBuffer
|
|
1063
|
+
});
|
|
1064
|
+
fullText += fullText === "" ? segmentBuffer : ` ${segmentBuffer}`;
|
|
1065
|
+
segmentBuffer = "";
|
|
1066
|
+
segmentCounter++;
|
|
1067
|
+
};
|
|
1068
|
+
const finish = () => {
|
|
1069
|
+
if (finished) return;
|
|
1070
|
+
completeSegment();
|
|
1071
|
+
finished = true;
|
|
1072
|
+
controller.enqueue({
|
|
1073
|
+
type: "finish",
|
|
1074
|
+
text: fullText,
|
|
1075
|
+
segments: [],
|
|
1076
|
+
language,
|
|
1077
|
+
durationInSeconds: void 0,
|
|
1078
|
+
...usageMetadata != null ? { providerMetadata: { google: { usageMetadata } } } : {}
|
|
1079
|
+
});
|
|
1080
|
+
controller.close();
|
|
1081
|
+
cleanup(1e3);
|
|
1082
|
+
};
|
|
1083
|
+
const sendAudio = async (socket) => {
|
|
1084
|
+
audioReader = audio.getReader();
|
|
1085
|
+
try {
|
|
1086
|
+
while (true) {
|
|
1087
|
+
const { done, value } = await audioReader.read();
|
|
1088
|
+
if (done || finished) break;
|
|
1089
|
+
socket.send(
|
|
1090
|
+
JSON.stringify({
|
|
1091
|
+
realtimeInput: {
|
|
1092
|
+
audio: {
|
|
1093
|
+
data: convertToBase642(value),
|
|
1094
|
+
mimeType: `audio/pcm;rate=${inputAudioRate}`
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
})
|
|
1098
|
+
);
|
|
1099
|
+
await waitForWebSocketBufferDrain(socket);
|
|
1100
|
+
}
|
|
1101
|
+
} finally {
|
|
1102
|
+
audioReader.releaseLock();
|
|
1103
|
+
audioReader = void 0;
|
|
1104
|
+
}
|
|
1105
|
+
if (!finished) {
|
|
1106
|
+
socket.send(
|
|
1107
|
+
JSON.stringify({ realtimeInput: { audioStreamEnd: true } })
|
|
1108
|
+
);
|
|
1109
|
+
audioEnded = true;
|
|
1110
|
+
schedulePendingFinish();
|
|
1111
|
+
}
|
|
1112
|
+
};
|
|
1113
|
+
connection = connectToWebSocket({
|
|
1114
|
+
url,
|
|
1115
|
+
headers,
|
|
1116
|
+
webSocket,
|
|
1117
|
+
abortSignal,
|
|
1118
|
+
onAbort: finishWithError,
|
|
1119
|
+
onProcessingError: finishWithError,
|
|
1120
|
+
onOpen: (socket) => {
|
|
1121
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
1122
|
+
socket.send(JSON.stringify({ setup }));
|
|
1123
|
+
void setupComplete.then(() => finished ? void 0 : sendAudio(socket)).catch(finishWithError);
|
|
1124
|
+
},
|
|
1125
|
+
onMessageText: async (text) => {
|
|
1126
|
+
var _a, _b;
|
|
1127
|
+
if (finished) return;
|
|
1128
|
+
const parsed = await safeParseJSON({ text });
|
|
1129
|
+
if (!parsed.success) return;
|
|
1130
|
+
const message = parsed.value;
|
|
1131
|
+
if (includeRawChunks) {
|
|
1132
|
+
controller.enqueue({ type: "raw", rawValue: message });
|
|
1133
|
+
}
|
|
1134
|
+
if (message.setupComplete != null) {
|
|
1135
|
+
resolveSetupComplete();
|
|
1136
|
+
}
|
|
1137
|
+
if (message.usageMetadata != null) {
|
|
1138
|
+
usageMetadata = message.usageMetadata;
|
|
1139
|
+
}
|
|
1140
|
+
if (message.error != null) {
|
|
1141
|
+
finishWithError(
|
|
1142
|
+
new Error((_a = message.error.message) != null ? _a : "Vertex Live API error")
|
|
1143
|
+
);
|
|
1144
|
+
return;
|
|
1145
|
+
}
|
|
1146
|
+
const serverContent = message.serverContent;
|
|
1147
|
+
const interim = serverContent == null ? void 0 : serverContent.interimInputTranscription;
|
|
1148
|
+
if (interim == null ? void 0 : interim.text) {
|
|
1149
|
+
schedulePendingFinish();
|
|
1150
|
+
latestInterim = interim.text;
|
|
1151
|
+
controller.enqueue({
|
|
1152
|
+
type: "transcript-partial",
|
|
1153
|
+
id: segmentId(),
|
|
1154
|
+
text: interim.text
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
const transcription = (_b = serverContent == null ? void 0 : serverContent.inputTranscription) != null ? _b : message.inputTranscription;
|
|
1158
|
+
if (transcription != null) {
|
|
1159
|
+
if (transcription.languageCode != null) {
|
|
1160
|
+
language = transcription.languageCode;
|
|
1161
|
+
}
|
|
1162
|
+
if (transcription.text) {
|
|
1163
|
+
schedulePendingFinish();
|
|
1164
|
+
latestInterim = "";
|
|
1165
|
+
segmentBuffer += transcription.text;
|
|
1166
|
+
controller.enqueue({
|
|
1167
|
+
type: "transcript-delta",
|
|
1168
|
+
id: segmentId(),
|
|
1169
|
+
delta: transcription.text
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
if (transcription.finished === true) {
|
|
1173
|
+
completeSegment();
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
if (serverContent == null ? void 0 : serverContent.turnComplete) {
|
|
1177
|
+
completeSegment();
|
|
1178
|
+
}
|
|
1179
|
+
const interactionStatus = serverContent == null ? void 0 : serverContent.interactionStatus;
|
|
1180
|
+
if (audioEnded && (interactionStatus === "IDLE" || interactionStatus === "REQUIRES_ACTION" || (serverContent == null ? void 0 : serverContent.turnComplete) === true && interactionStatus == null)) {
|
|
1181
|
+
finish();
|
|
1182
|
+
}
|
|
1183
|
+
},
|
|
1184
|
+
onSocketError: () => {
|
|
1185
|
+
finishWithError(
|
|
1186
|
+
new Error(
|
|
1187
|
+
"Vertex Live transcription error." + (webSocket == null ? " Note: the native WebSocket implementation cannot send the Authorization header required by Vertex. Pass a header-capable WebSocket implementation (e.g. the 'ws' package) via createVertex({ webSocket })." : "")
|
|
1188
|
+
)
|
|
1189
|
+
);
|
|
1190
|
+
},
|
|
1191
|
+
onClose: ({ code, reason }) => {
|
|
1192
|
+
if (finished) return;
|
|
1193
|
+
if (audioEnded) {
|
|
1194
|
+
finish();
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
finishWithError(
|
|
1198
|
+
new Error(
|
|
1199
|
+
`Vertex Live transcription WebSocket closed unexpectedly before finishing (code ${code != null ? code : "unknown"}${reason ? `, reason: ${reason}` : ""}).`
|
|
1200
|
+
)
|
|
1201
|
+
);
|
|
1202
|
+
}
|
|
1203
|
+
});
|
|
1204
|
+
},
|
|
1205
|
+
cancel: () => {
|
|
1206
|
+
if (finished) return;
|
|
1207
|
+
finished = true;
|
|
1208
|
+
cleanup();
|
|
1209
|
+
}
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
function buildAudioTranscriptionConfig(options) {
|
|
1213
|
+
if (options == null) return void 0;
|
|
1214
|
+
const config = {};
|
|
1215
|
+
if (options.languageCodes != null) {
|
|
1216
|
+
config.languageCodes = options.languageCodes;
|
|
1217
|
+
}
|
|
1218
|
+
if (options.customVocabulary != null) {
|
|
1219
|
+
config.customVocabulary = options.customVocabulary;
|
|
1220
|
+
}
|
|
1221
|
+
if (options.wordTimestamp != null) {
|
|
1222
|
+
config.wordTimestamp = options.wordTimestamp;
|
|
1223
|
+
}
|
|
1224
|
+
if (options.diarization != null) {
|
|
1225
|
+
config.diarization = options.diarization;
|
|
1226
|
+
}
|
|
1227
|
+
if (options.mode != null) {
|
|
1228
|
+
config.mode = options.mode;
|
|
1229
|
+
}
|
|
1230
|
+
return Object.keys(config).length > 0 ? config : void 0;
|
|
1231
|
+
}
|
|
1232
|
+
function validateLiveInputAudioFormat(inputAudioFormat) {
|
|
1233
|
+
if (inputAudioFormat.type !== "audio/pcm" || inputAudioFormat.rate != null && inputAudioFormat.rate !== 16e3) {
|
|
1234
|
+
throw new InvalidArgumentError({
|
|
1235
|
+
argument: "inputAudioFormat",
|
|
1236
|
+
message: "The Gemini Live transcription API only supports 16kHz 16-bit PCM input audio."
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
function parseOffsetSeconds(offset) {
|
|
1241
|
+
if (offset == null) return void 0;
|
|
1242
|
+
const parsed = Number.parseFloat(offset);
|
|
1243
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
1244
|
+
}
|
|
1245
|
+
var googleVertexGeminiTranscriptionWordSchema = z8.object({
|
|
1246
|
+
word: z8.string().nullish(),
|
|
1247
|
+
startOffset: z8.string().nullish(),
|
|
1248
|
+
endOffset: z8.string().nullish()
|
|
1249
|
+
});
|
|
1250
|
+
var googleVertexGeminiTranscriptionResponseSchema = z8.object({
|
|
1251
|
+
candidates: z8.array(
|
|
1252
|
+
z8.object({
|
|
1253
|
+
content: z8.object({
|
|
1254
|
+
parts: z8.array(
|
|
1255
|
+
z8.object({
|
|
1256
|
+
text: z8.string().nullish(),
|
|
1257
|
+
audioTranscription: z8.object({
|
|
1258
|
+
text: z8.string().nullish(),
|
|
1259
|
+
languageCode: z8.string().nullish(),
|
|
1260
|
+
speakerLabel: z8.string().nullish(),
|
|
1261
|
+
words: z8.array(googleVertexGeminiTranscriptionWordSchema).nullish()
|
|
1262
|
+
}).nullish()
|
|
1263
|
+
})
|
|
1264
|
+
).nullish()
|
|
1265
|
+
}).nullish()
|
|
1266
|
+
})
|
|
1267
|
+
).nullish(),
|
|
1268
|
+
usageMetadata: z8.record(z8.string(), z8.unknown()).nullish()
|
|
1269
|
+
});
|
|
1270
|
+
|
|
1271
|
+
// src/google-vertex-video-model.ts
|
|
1272
|
+
import {
|
|
1273
|
+
AISDKError
|
|
1274
|
+
} from "@ai-sdk/provider";
|
|
1275
|
+
import {
|
|
1276
|
+
combineHeaders as combineHeaders5,
|
|
1277
|
+
convertUint8ArrayToBase64 as convertUint8ArrayToBase642,
|
|
1278
|
+
createJsonResponseHandler as createJsonResponseHandler5,
|
|
1279
|
+
parseProviderOptions as parseProviderOptions4,
|
|
1280
|
+
postJsonToApi as postJsonToApi5,
|
|
1281
|
+
resolve as resolve5
|
|
1282
|
+
} from "@ai-sdk/provider-utils";
|
|
1283
|
+
import { z as z10 } from "zod/v4";
|
|
1284
|
+
|
|
770
1285
|
// src/google-vertex-video-model-options.ts
|
|
771
1286
|
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
772
|
-
import { z as
|
|
1287
|
+
import { z as z9 } from "zod/v4";
|
|
773
1288
|
var googleVertexVideoModelOptionsSchema = lazySchema(
|
|
774
1289
|
() => zodSchema(
|
|
775
|
-
|
|
776
|
-
pollIntervalMs:
|
|
777
|
-
pollTimeoutMs:
|
|
778
|
-
personGeneration:
|
|
779
|
-
negativePrompt:
|
|
780
|
-
generateAudio:
|
|
781
|
-
gcsOutputDirectory:
|
|
782
|
-
referenceImages:
|
|
783
|
-
|
|
784
|
-
bytesBase64Encoded:
|
|
785
|
-
gcsUri:
|
|
1290
|
+
z9.looseObject({
|
|
1291
|
+
pollIntervalMs: z9.number().positive().nullish(),
|
|
1292
|
+
pollTimeoutMs: z9.number().positive().nullish(),
|
|
1293
|
+
personGeneration: z9.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
1294
|
+
negativePrompt: z9.string().nullish(),
|
|
1295
|
+
generateAudio: z9.boolean().nullish(),
|
|
1296
|
+
gcsOutputDirectory: z9.string().nullish(),
|
|
1297
|
+
referenceImages: z9.array(
|
|
1298
|
+
z9.object({
|
|
1299
|
+
bytesBase64Encoded: z9.string().nullish(),
|
|
1300
|
+
gcsUri: z9.string().nullish()
|
|
786
1301
|
})
|
|
787
1302
|
).nullish()
|
|
788
1303
|
})
|
|
@@ -848,11 +1363,11 @@ var GoogleVertexVideoModel = class {
|
|
|
848
1363
|
async buildRequest(options) {
|
|
849
1364
|
var _a, _b;
|
|
850
1365
|
const warnings = [];
|
|
851
|
-
const googleVertexOptions = (_a = await
|
|
1366
|
+
const googleVertexOptions = (_a = await parseProviderOptions4({
|
|
852
1367
|
provider: "googleVertex",
|
|
853
1368
|
providerOptions: options.providerOptions,
|
|
854
1369
|
schema: googleVertexVideoModelOptionsSchema
|
|
855
|
-
})) != null ? _a : await
|
|
1370
|
+
})) != null ? _a : await parseProviderOptions4({
|
|
856
1371
|
provider: "vertex",
|
|
857
1372
|
providerOptions: options.providerOptions,
|
|
858
1373
|
schema: googleVertexVideoModelOptionsSchema
|
|
@@ -1003,17 +1518,17 @@ var GoogleVertexVideoModel = class {
|
|
|
1003
1518
|
var _a, _b, _c;
|
|
1004
1519
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1005
1520
|
const { instances, parameters, warnings } = await this.buildRequest(options);
|
|
1006
|
-
const { value: operation, responseHeaders } = await
|
|
1521
|
+
const { value: operation, responseHeaders } = await postJsonToApi5({
|
|
1007
1522
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
1008
|
-
headers:
|
|
1009
|
-
await
|
|
1523
|
+
headers: combineHeaders5(
|
|
1524
|
+
await resolve5(this.config.headers),
|
|
1010
1525
|
options.headers
|
|
1011
1526
|
),
|
|
1012
1527
|
body: {
|
|
1013
1528
|
instances,
|
|
1014
1529
|
parameters
|
|
1015
1530
|
},
|
|
1016
|
-
successfulResponseHandler:
|
|
1531
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
1017
1532
|
googleVertexOperationSchema
|
|
1018
1533
|
),
|
|
1019
1534
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
@@ -1041,16 +1556,16 @@ var GoogleVertexVideoModel = class {
|
|
|
1041
1556
|
var _a, _b, _c;
|
|
1042
1557
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1043
1558
|
const { operationName } = options.operation;
|
|
1044
|
-
const { value: statusOperation, responseHeaders } = await
|
|
1559
|
+
const { value: statusOperation, responseHeaders } = await postJsonToApi5({
|
|
1045
1560
|
url: `${this.config.baseURL}/models/${this.modelId}:fetchPredictOperation`,
|
|
1046
|
-
headers:
|
|
1047
|
-
await
|
|
1561
|
+
headers: combineHeaders5(
|
|
1562
|
+
await resolve5(this.config.headers),
|
|
1048
1563
|
options.headers
|
|
1049
1564
|
),
|
|
1050
1565
|
body: {
|
|
1051
1566
|
operationName
|
|
1052
1567
|
},
|
|
1053
|
-
successfulResponseHandler:
|
|
1568
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
1054
1569
|
googleVertexOperationSchema
|
|
1055
1570
|
),
|
|
1056
1571
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
@@ -1086,23 +1601,23 @@ var GoogleVertexVideoModel = class {
|
|
|
1086
1601
|
});
|
|
1087
1602
|
}
|
|
1088
1603
|
};
|
|
1089
|
-
var googleVertexOperationSchema =
|
|
1090
|
-
name:
|
|
1091
|
-
done:
|
|
1092
|
-
error:
|
|
1093
|
-
code:
|
|
1094
|
-
message:
|
|
1095
|
-
status:
|
|
1604
|
+
var googleVertexOperationSchema = z10.object({
|
|
1605
|
+
name: z10.string().nullish(),
|
|
1606
|
+
done: z10.boolean().nullish(),
|
|
1607
|
+
error: z10.object({
|
|
1608
|
+
code: z10.number().nullish(),
|
|
1609
|
+
message: z10.string(),
|
|
1610
|
+
status: z10.string().nullish()
|
|
1096
1611
|
}).nullish(),
|
|
1097
|
-
response:
|
|
1098
|
-
videos:
|
|
1099
|
-
|
|
1100
|
-
bytesBase64Encoded:
|
|
1101
|
-
gcsUri:
|
|
1102
|
-
mimeType:
|
|
1612
|
+
response: z10.object({
|
|
1613
|
+
videos: z10.array(
|
|
1614
|
+
z10.object({
|
|
1615
|
+
bytesBase64Encoded: z10.string().nullish(),
|
|
1616
|
+
gcsUri: z10.string().nullish(),
|
|
1617
|
+
mimeType: z10.string().nullish()
|
|
1103
1618
|
})
|
|
1104
1619
|
).nullish(),
|
|
1105
|
-
raiMediaFilteredCount:
|
|
1620
|
+
raiMediaFilteredCount: z10.number().nullish()
|
|
1106
1621
|
}).nullish()
|
|
1107
1622
|
});
|
|
1108
1623
|
|
|
@@ -1162,7 +1677,7 @@ function createGoogleVertex(options = {}) {
|
|
|
1162
1677
|
const createConfig = (name, { endpoint = false } = {}) => {
|
|
1163
1678
|
const getHeaders = async () => {
|
|
1164
1679
|
var _a;
|
|
1165
|
-
const originalHeaders = await
|
|
1680
|
+
const originalHeaders = await resolve6((_a = options.headers) != null ? _a : {});
|
|
1166
1681
|
return withUserAgentSuffix(
|
|
1167
1682
|
originalHeaders,
|
|
1168
1683
|
`ai-sdk/google-vertex/${VERSION}`
|
|
@@ -1253,6 +1768,17 @@ function createGoogleVertex(options = {}) {
|
|
|
1253
1768
|
);
|
|
1254
1769
|
}
|
|
1255
1770
|
const config = createConfig("transcription");
|
|
1771
|
+
if (modelId.startsWith("gemini")) {
|
|
1772
|
+
return new GoogleVertexGeminiTranscriptionModel(modelId, {
|
|
1773
|
+
provider: config.provider,
|
|
1774
|
+
baseURL: loadBaseURL(),
|
|
1775
|
+
headers: config.headers,
|
|
1776
|
+
fetch: config.fetch,
|
|
1777
|
+
webSocket: options.webSocket,
|
|
1778
|
+
project: loadGoogleVertexProject(),
|
|
1779
|
+
location: loadGoogleVertexLocation()
|
|
1780
|
+
});
|
|
1781
|
+
}
|
|
1256
1782
|
return new GoogleVertexTranscriptionModel(modelId, {
|
|
1257
1783
|
provider: config.provider,
|
|
1258
1784
|
headers: config.headers,
|
|
@@ -1304,12 +1830,13 @@ function createGoogleVertex2(options = {}) {
|
|
|
1304
1830
|
...options,
|
|
1305
1831
|
headers: async () => ({
|
|
1306
1832
|
Authorization: `Bearer ${await generateAuthToken()}`,
|
|
1307
|
-
...await
|
|
1833
|
+
...await resolve7(options.headers)
|
|
1308
1834
|
})
|
|
1309
1835
|
});
|
|
1310
1836
|
}
|
|
1311
1837
|
var googleVertex = createGoogleVertex2();
|
|
1312
1838
|
export {
|
|
1839
|
+
GoogleVertexGeminiTranscriptionModel,
|
|
1313
1840
|
VERSION,
|
|
1314
1841
|
createGoogleVertex2 as createGoogleVertex,
|
|
1315
1842
|
createGoogleVertex2 as createVertex,
|