@ai-sdk/google-vertex 5.0.142 → 5.0.144

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/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import { GoogleInteractionsAgentName, GoogleInteractionsModelId } from "@ai-sdk/
4
4
  import { EmbeddingModelV4, Experimental_TranscriptionModelV4StreamOptions, Experimental_VideoModelV4, ImageModelV4, JSONObject, LanguageModelV4, ProviderV4, SpeechModelV4, TranscriptionModelV4 } from "@ai-sdk/provider";
5
5
  import { GoogleLanguageModelOptions, GoogleSpeechModelOptions } from "@ai-sdk/google";
6
6
  //#region src/google-vertex-model-catalog.d.ts
7
- declare const languageModelIds: readonly ["gemini-nano-banana-2.1", "gemini-4-argon", "gemini-4-carbon", "gemini-4-hydrogen", "gemini-3.8-flash", "gemini-3.7-flash", "gemini-3.6-flash", "gemini-3.5-flash", "gemini-3.5-flash-lite", "gemini-2.5-pro", "gemini-2.5-flash", "gemini-2.5-flash-lite", "gemini-2.0-flash-lite", "gemini-2.0-flash", "gemini-2.0-flash-001", "gemini-1.5-flash", "gemini-1.5-flash-001", "gemini-1.5-flash-002", "gemini-1.5-pro", "gemini-1.5-pro-001", "gemini-1.5-pro-002", "gemini-1.0-pro-001", "gemini-1.0-pro-vision-001", "gemini-1.0-pro", "gemini-1.0-pro-002", "gemini-2.0-flash-lite-preview-02-05", "gemini-2.5-flash-preview-09-2025", "gemini-3-pro-preview", "gemini-3-pro-image-preview", "gemini-3-flash-preview", "gemini-3.1-pro-preview", "gemini-3.1-flash-image-preview", "gemini-3.1-flash-lite-preview", "gemini-2.0-pro-exp-02-05", "gemini-2.0-flash-exp"];
7
+ declare const languageModelIds: readonly ["gemini-nano-banana-2.1", "gemini-4-argon", "gemini-4-carbon", "gemini-4-hydrogen", "gemini-4-neon", "gemini-3.8-flash", "gemini-3.7-flash", "gemini-3.6-flash", "gemini-3.5-flash", "gemini-3.5-flash-lite", "gemini-2.5-pro", "gemini-2.5-flash", "gemini-2.5-flash-lite", "gemini-2.0-flash-lite", "gemini-2.0-flash", "gemini-2.0-flash-001", "gemini-1.5-flash", "gemini-1.5-flash-001", "gemini-1.5-flash-002", "gemini-1.5-pro", "gemini-1.5-pro-001", "gemini-1.5-pro-002", "gemini-1.0-pro-001", "gemini-1.0-pro-vision-001", "gemini-1.0-pro", "gemini-1.0-pro-002", "gemini-2.0-flash-lite-preview-02-05", "gemini-2.5-flash-preview-09-2025", "gemini-3-pro-preview", "gemini-3-pro-image-preview", "gemini-3-flash-preview", "gemini-3.1-pro-preview", "gemini-3.1-flash-image-preview", "gemini-3.1-flash-lite-preview", "gemini-2.0-pro-exp-02-05", "gemini-2.0-flash-exp"];
8
8
  declare const imageModelIds: readonly ["gemini-2.5-flash-image", "gemini-3-pro-image-preview", "gemini-3.1-flash-image-preview", "gemini-nano-banana-2.1"];
9
9
  declare const embeddingModelIds: readonly ["textembedding-gecko", "textembedding-gecko@001", "textembedding-gecko@003", "textembedding-gecko-multilingual", "textembedding-gecko-multilingual@001", "text-multilingual-embedding-002", "text-embedding-004", "text-embedding-005", "gemini-embedding-001", "gemini-embedding-2", "gemini-embedding-2-preview"];
10
10
  declare const videoModelIds: readonly ["veo-2.0-generate-preview", "veo-2.0-generate-exp", "veo-2.0-generate-001", "veo-3.0-generate-001", "veo-3.0-fast-generate-001", "veo-3.0-generate-preview", "veo-3.0-fast-generate-preview", "veo-3.1-generate-001", "veo-3.1-fast-generate-001", "veo-3.1-generate-preview", "veo-3.1-fast-generate-preview"];
@@ -415,6 +415,11 @@ declare const googleVertexGeminiTranscriptionModelOptions: import("@ai-sdk/provi
415
415
  wordTimestamp?: boolean | undefined;
416
416
  diarization?: boolean | undefined;
417
417
  mode?: "SMART" | "VERBATIM" | undefined;
418
+ streaming?: {
419
+ automaticActivityDetection?: {
420
+ disabled?: boolean | undefined;
421
+ } | undefined;
422
+ } | undefined;
418
423
  }>;
419
424
  type GoogleVertexTranscriptionModelGeminiOptions = InferSchema<typeof googleVertexGeminiTranscriptionModelOptions>;
420
425
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["GoogleVertexProviderSettings","GoogleVertexProviderSettingsOriginal","TranscriptionModelV4StreamOptions"],"sources":["../src/google-vertex-model-catalog.ts","../src/google-vertex-embedding-model-options.ts","../src/google-vertex-transcription-model-options.ts","../src/google-vertex-image-model-options.ts","../src/google-vertex-video-model-options.ts","../src/google-vertex-video-settings.ts","../src/google-vertex-speech-model-options.ts","../src/google-vertex-config.ts","../src/google-vertex-embedding-model.ts","../src/google-vertex-image-settings.ts","../src/google-vertex-options.ts","../src/google-vertex-tools.ts","../src/google-vertex-provider-base.ts","../src/google-vertex-provider.ts","../src/gemini-transcription/google-vertex-gemini-transcription-model-options.ts","../src/gemini-transcription/google-vertex-gemini-transcription-model.ts","../src/version.ts"],"mappings":";;;;;;cA6UM;cAsCA;cAOA;cAcA;cAcA;cAQA;cAEA;cA6CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA0GA;;;;;;;;;;;;;;cA0BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAsCM;EACV,kBAAkB;EAClB,eAAe;EACf,mBAAmB;EACnB,eAAe;EACf,gBAAgB;EAChB,uBAAuB;EACvB,6BAA6B;EAC7B,wBAAwB;EACxB,kBAAkB;EAClB,mBAAmB;;;;KCxnBT,+BACR;cAGS,oEAAiC;;;;;;KAkDlC,oCAAoC,mBACvC;;;KCtDG,mCACR;cAGS,iFAA8C;;;;;;KAsC/C,wCAAwC,mBAC3C;;;KCnDG,gCAAgC,KAC1C;;;KCAU;EAEV;EACA;EAGA;EACA;EACA;EAGA;EAGA,kBAAkB;IAChB;IACA;;GAGD;;;;KCpBS,2BACR;;;KCIQ,4BACR;KAGQ,iCAAiC;;;UCT5B;EACf;EACA;EACA,UAAU,WAAW;E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;UAO3B,sBAAsB;IAC5B,SAAS;IACT,QAAQ;MACT;MAOG;EAKO,YAAA,SAAS,wCACD,QAAQ;UAGb;EAeR,WACJ,SAAS,WAAW,yCACnB,QAAQ,QAAQ,WAAW;EAkJxB,SACJ,SAASC,iDACR,QACD,QAAQ,WAAW,YAAY;;;;qBCjTtB"}
1
+ {"version":3,"file":"index.d.ts","names":["GoogleVertexProviderSettings","GoogleVertexProviderSettingsOriginal","TranscriptionModelV4StreamOptions"],"sources":["../src/google-vertex-model-catalog.ts","../src/google-vertex-embedding-model-options.ts","../src/google-vertex-transcription-model-options.ts","../src/google-vertex-image-model-options.ts","../src/google-vertex-video-model-options.ts","../src/google-vertex-video-settings.ts","../src/google-vertex-speech-model-options.ts","../src/google-vertex-config.ts","../src/google-vertex-embedding-model.ts","../src/google-vertex-image-settings.ts","../src/google-vertex-options.ts","../src/google-vertex-tools.ts","../src/google-vertex-provider-base.ts","../src/google-vertex-provider.ts","../src/gemini-transcription/google-vertex-gemini-transcription-model-options.ts","../src/gemini-transcription/google-vertex-gemini-transcription-model.ts","../src/version.ts"],"mappings":";;;;;;cA8UM;cAuCA;cAOA;cAcA;cAcA;cAQA;cAEA;cA6CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA0GA;;;;;;;;;;;;;;cA0BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAsCM;EACV,kBAAkB;EAClB,eAAe;EACf,mBAAmB;EACnB,eAAe;EACf,gBAAgB;EAChB,uBAAuB;EACvB,6BAA6B;EAC7B,wBAAwB;EACxB,kBAAkB;EAClB,mBAAmB;;;;KC1nBT,+BACR;cAGS,oEAAiC;;;;;;KAkDlC,oCAAoC,mBACvC;;;KCtDG,mCACR;cAGS,iFAA8C;;;;;;KAsC/C,wCAAwC,mBAC3C;;;KCnDG,gCAAgC,KAC1C;;;KCAU;EAEV;EACA;EAGA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AU,WAAW;EACrB,QAAQ;EACR,YAAY;EACZ;EACA;EACA;IACE,oBAAoB;IACpB;;;;;;;;;qBAUS,gDAAgD;WAyBhD,SAAS;mBACD;WAzBV;UAED,oBAAoB,OAAO;;;;UAO3B,sBAAsB;IAC5B,SAAS;IACT,QAAQ;MACT;MAOG;EAKO,YAAA,SAAS,wCACD,QAAQ;UAGb;EAeR,WACJ,SAAS,WAAW,yCACnB,QAAQ,QAAQ,WAAW;EAkJxB,SACJ,SAASC,iDACR,QACD,QAAQ,WAAW,YAAY;;;;qBCzTtB"}
package/dist/index.js CHANGED
@@ -39,7 +39,7 @@ function getGoogleVertexRequestConfig(modelId) {
39
39
  }
40
40
  //#endregion
41
41
  //#region src/version.ts
42
- const VERSION = "5.0.142";
42
+ const VERSION = "5.0.144";
43
43
  //#endregion
44
44
  //#region src/google-vertex-error.ts
45
45
  const googleVertexErrorDataSchema = lazySchema(() => zodSchema(z.object({ error: z.object({
@@ -315,7 +315,8 @@ const googleVertexProviderOptions = {
315
315
  customVocabulary: { description: "Vocabulary hints for Gemini transcription." },
316
316
  wordTimestamp: { description: "Include Gemini word timestamps." },
317
317
  diarization: { description: "Enable Gemini speaker diarization." },
318
- mode: { description: "Verbatim or smart Gemini transcription formatting." }
318
+ mode: { description: "Verbatim or smart Gemini transcription formatting." },
319
+ streaming: { description: "Live Gemini voice activity detection." }
319
320
  },
320
321
  video: {
321
322
  pollIntervalMs: { description: "Polling interval." },
@@ -446,6 +447,7 @@ const languageModelIds = [
446
447
  "gemini-4-argon",
447
448
  "gemini-4-carbon",
448
449
  "gemini-4-hydrogen",
450
+ "gemini-4-neon",
449
451
  "gemini-3.8-flash",
450
452
  "gemini-3.7-flash",
451
453
  "gemini-3.6-flash",
@@ -1111,17 +1113,38 @@ const googleVertexGeminiTranscriptionModelOptions = lazySchema(() => zodSchema(z
1111
1113
  * disfluency removal, inline self-corrections, structured formatting
1112
1114
  * (lists, numbers, dates, paragraph breaks), and grammar/casing polish.
1113
1115
  */
1114
- mode: z.enum(["SMART", "VERBATIM"]).optional()
1116
+ mode: z.enum(["SMART", "VERBATIM"]).optional(),
1117
+ /**
1118
+ * Options for live transcription models such as
1119
+ * `gemini-3.5-transcribe-live`.
1120
+ */
1121
+ streaming: z.object({
1122
+ /**
1123
+ * Server-side voice activity detection, which splits the audio into
1124
+ * segments at pauses (enabled by default).
1125
+ *
1126
+ * Set `disabled: true` for push-to-talk input: the whole audio
1127
+ * stream is then transcribed as a single turn, without splitting at
1128
+ * pauses, and the transcript is finalized as soon as the audio
1129
+ * stream ends.
1130
+ */
1131
+ automaticActivityDetection: z.object({ disabled: z.boolean().optional() }).optional() }).optional()
1115
1132
  })));
1116
1133
  //#endregion
1117
1134
  //#region src/gemini-transcription/google-vertex-gemini-transcription-model.ts
1118
1135
  const liveWebSocketPath = "google.cloud.aiplatform.v1.LlmBidiService/BidiGenerateContent";
1119
1136
  /**
1120
- * After the input audio has ended, finish when no terminal signal
1121
- * (`turnComplete` / idle `interactionStatus`) arrives within this window.
1137
+ * After the input audio has ended, finish when no terminal signal (idle
1138
+ * `interactionStatus`, `turnComplete`, or server VAD showing that all audio
1139
+ * was transcribed) arrives within this window.
1122
1140
  * Trailing transcripts reset the timer.
1123
1141
  */
1124
1142
  const defaultFinishGraceMs = 3e3;
1143
+ /**
1144
+ * Speech that server VAD ended within this distance of the end of the sent
1145
+ * audio counts as ending at the end of the audio.
1146
+ */
1147
+ const audioEndToleranceMs = 250;
1125
1148
  /** Live transcription is only supported by `*-live` model variants. */
1126
1149
  function isLiveTranscriptionModelId(modelId) {
1127
1150
  return getGoogleVertexRequestConfig(modelId).transcription?.live === true;
@@ -1272,9 +1295,11 @@ var GoogleVertexGeminiTranscriptionModel = class GoogleVertexGeminiTranscription
1272
1295
  const { project, location } = this.config;
1273
1296
  const modelResource = `projects/${project}/locations/${location}/publishers/google/models/${this.modelId}`;
1274
1297
  const url = new URL(`wss://${vertexHost(location)}/ws/${liveWebSocketPath}`);
1298
+ const manualActivityDetection = googleOptions?.streaming?.automaticActivityDetection?.disabled === true;
1275
1299
  const setup = {
1276
1300
  model: modelResource,
1277
- inputAudioTranscription: buildAudioTranscriptionConfig(googleOptions) ?? {}
1301
+ inputAudioTranscription: buildAudioTranscriptionConfig(googleOptions) ?? {},
1302
+ ...manualActivityDetection ? { realtimeInputConfig: { automaticActivityDetection: { disabled: true } } } : {}
1278
1303
  };
1279
1304
  return {
1280
1305
  request: { body: setup },
@@ -1288,6 +1313,7 @@ var GoogleVertexGeminiTranscriptionModel = class GoogleVertexGeminiTranscription
1288
1313
  headers,
1289
1314
  setup,
1290
1315
  inputAudioRate: options.inputAudioFormat.rate ?? 16e3,
1316
+ manualActivityDetection,
1291
1317
  finishGraceMs: this.config._internal?.finishGraceMs ?? defaultFinishGraceMs,
1292
1318
  warnings,
1293
1319
  audio: options.audio,
@@ -1297,7 +1323,7 @@ var GoogleVertexGeminiTranscriptionModel = class GoogleVertexGeminiTranscription
1297
1323
  };
1298
1324
  }
1299
1325
  };
1300
- function createVertexLiveTranscriptionStream({ webSocket, url, headers, setup, inputAudioRate, finishGraceMs, warnings, audio, abortSignal, includeRawChunks }) {
1326
+ function createVertexLiveTranscriptionStream({ webSocket, url, headers, setup, inputAudioRate, manualActivityDetection, finishGraceMs, warnings, audio, abortSignal, includeRawChunks }) {
1301
1327
  let finished = false;
1302
1328
  let cleanup = () => {};
1303
1329
  return new ReadableStream({
@@ -1316,6 +1342,8 @@ function createVertexLiveTranscriptionStream({ webSocket, url, headers, setup, i
1316
1342
  let audioEnded = false;
1317
1343
  let usageMetadata;
1318
1344
  let finishTimer;
1345
+ let lastVoiceActivity;
1346
+ let sentAudioBytes = 0;
1319
1347
  const segmentId = () => `google-segment-${segmentCounter}`;
1320
1348
  const cancelPendingFinish = () => {
1321
1349
  if (finishTimer != null) {
@@ -1358,6 +1386,8 @@ function createVertexLiveTranscriptionStream({ webSocket, url, headers, setup, i
1358
1386
  segmentBuffer = "";
1359
1387
  segmentCounter++;
1360
1388
  };
1389
+ const getSentAudioMs = () => sentAudioBytes / (inputAudioRate * 2) * 1e3;
1390
+ const isTranscriptionComplete = () => lastVoiceActivity?.type === "ACTIVITY_END" && segmentBuffer === "" && latestInterim === "" && (lastVoiceActivity.audioOffsetMs ?? 0) >= getSentAudioMs() - audioEndToleranceMs;
1361
1391
  const finish = () => {
1362
1392
  if (finished) return;
1363
1393
  completeSegment();
@@ -1377,13 +1407,17 @@ function createVertexLiveTranscriptionStream({ webSocket, url, headers, setup, i
1377
1407
  cleanup(1e3);
1378
1408
  };
1379
1409
  const sendAudio = async (socket) => {
1410
+ if (manualActivityDetection) socket.send(JSON.stringify({ realtimeInput: { activityStart: {} } }));
1380
1411
  audioReader = audio.getReader();
1381
1412
  try {
1382
1413
  while (true) {
1383
1414
  const { done, value } = await audioReader.read();
1384
1415
  if (done || finished) break;
1416
+ const data = convertToBase64(value);
1417
+ const padding = data.endsWith("==") ? 2 : data.endsWith("=") ? 1 : 0;
1418
+ sentAudioBytes += data.length * 3 / 4 - padding;
1385
1419
  socket.send(JSON.stringify({ realtimeInput: { audio: {
1386
- data: convertToBase64(value),
1420
+ data,
1387
1421
  mimeType: `audio/pcm;rate=${inputAudioRate}`
1388
1422
  } } }));
1389
1423
  await waitForWebSocketBufferDrain(socket);
@@ -1393,9 +1427,10 @@ function createVertexLiveTranscriptionStream({ webSocket, url, headers, setup, i
1393
1427
  audioReader = void 0;
1394
1428
  }
1395
1429
  if (!finished) {
1396
- socket.send(JSON.stringify({ realtimeInput: { audioStreamEnd: true } }));
1430
+ socket.send(JSON.stringify({ realtimeInput: manualActivityDetection ? { activityEnd: {} } : { audioStreamEnd: true } }));
1397
1431
  audioEnded = true;
1398
- schedulePendingFinish();
1432
+ if (isTranscriptionComplete()) finish();
1433
+ else schedulePendingFinish();
1399
1434
  }
1400
1435
  };
1401
1436
  connection = connectToWebSocket({
@@ -1424,6 +1459,13 @@ function createVertexLiveTranscriptionStream({ webSocket, url, headers, setup, i
1424
1459
  });
1425
1460
  if (message.setupComplete != null) resolveSetupComplete();
1426
1461
  if (message.usageMetadata != null) usageMetadata = message.usageMetadata;
1462
+ if (message.voiceActivity?.type != null) {
1463
+ const audioOffsetSeconds = parseOffsetSeconds(message.voiceActivity.audioOffset);
1464
+ lastVoiceActivity = {
1465
+ type: message.voiceActivity.type,
1466
+ audioOffsetMs: audioOffsetSeconds != null ? audioOffsetSeconds * 1e3 : void 0
1467
+ };
1468
+ }
1427
1469
  if (message.error != null) {
1428
1470
  finishWithError(new Error(message.error.message ?? "Vertex Live API error"));
1429
1471
  return;
@@ -1454,9 +1496,9 @@ function createVertexLiveTranscriptionStream({ webSocket, url, headers, setup, i
1454
1496
  }
1455
1497
  if (transcription.finished === true) completeSegment();
1456
1498
  }
1457
- if (serverContent?.turnComplete) completeSegment();
1499
+ if (serverContent?.generationComplete || serverContent?.turnComplete) completeSegment();
1458
1500
  const interactionStatus = serverContent?.interactionStatus;
1459
- if (audioEnded && (interactionStatus === "IDLE" || interactionStatus === "REQUIRES_ACTION" || serverContent?.turnComplete === true && interactionStatus == null)) finish();
1501
+ if (audioEnded && (interactionStatus === "IDLE" || interactionStatus === "REQUIRES_ACTION" || serverContent?.turnComplete === true && interactionStatus == null || isTranscriptionComplete())) finish();
1460
1502
  },
1461
1503
  onSocketError: () => {
1462
1504
  finishWithError(/* @__PURE__ */ new Error("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 })." : "")));