@ai-sdk/google-vertex 5.0.143 → 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
@@ -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;cAuCA;cAOA;cAcA;cAcA;cAQA;cAEA;cA6CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA0GA;;;;;;;;;;;;;;cA0BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAsCM;EACV,kBAAkB;EAClB,eAAe;EACf,mBAAmB;E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AW;;;;;EAMrB,QAAQ;EAGR;;;;EAKA;;;;;;EAOA,YAAY;;;;;EAMZ;;;;IAIE;;;;;UCjNa,qCAAqCC;;;;;;;EAOpD,oBAAoB;;wBAKN,mBACd,UAAS,+BACR;;;;qBAmCU,cAAY;;;KCjDb,yCACR;;;;;;;cASS,8EAA2C;;;;;;;KAuC5C,8CAA8C,mBACjD;;;UCiCC;EACR;;EAEA;EACA,UAAU,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;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAS,4BAA4B;;;;EAKjD,cACE,SAAS,mCACR;;;;EAKH,mBACE,SAAS,mCACR;;UAGYA;;;;;;;EAOf,SAAS;;;;EAKT;;;;EAKA;;;;;;;;EASA,UAAU,WAAW;;;;;EAMrB,QAAQ;EAGR;;;;EAKA;;;;;;EAOA,YAAY;;;;;EAMZ;;;;IAIE;;;;;UCjNa,qCAAqCC;;;;;;;EAOpD,oBAAoB;;wBAKN,mBACd,UAAS,+BACR;;;;qBAmCU,cAAY;;;KCjDb,yCACR;;;;;;;cASS,8EAA2C;;;;;;;;;;;;KA8D5C,8CAA8C,mBACjD;;;UCkBC;EACR;;EAEA;EACA,UAAU,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.143";
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." },
@@ -1112,17 +1113,38 @@ const googleVertexGeminiTranscriptionModelOptions = lazySchema(() => zodSchema(z
1112
1113
  * disfluency removal, inline self-corrections, structured formatting
1113
1114
  * (lists, numbers, dates, paragraph breaks), and grammar/casing polish.
1114
1115
  */
1115
- 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()
1116
1132
  })));
1117
1133
  //#endregion
1118
1134
  //#region src/gemini-transcription/google-vertex-gemini-transcription-model.ts
1119
1135
  const liveWebSocketPath = "google.cloud.aiplatform.v1.LlmBidiService/BidiGenerateContent";
1120
1136
  /**
1121
- * After the input audio has ended, finish when no terminal signal
1122
- * (`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.
1123
1140
  * Trailing transcripts reset the timer.
1124
1141
  */
1125
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;
1126
1148
  /** Live transcription is only supported by `*-live` model variants. */
1127
1149
  function isLiveTranscriptionModelId(modelId) {
1128
1150
  return getGoogleVertexRequestConfig(modelId).transcription?.live === true;
@@ -1273,9 +1295,11 @@ var GoogleVertexGeminiTranscriptionModel = class GoogleVertexGeminiTranscription
1273
1295
  const { project, location } = this.config;
1274
1296
  const modelResource = `projects/${project}/locations/${location}/publishers/google/models/${this.modelId}`;
1275
1297
  const url = new URL(`wss://${vertexHost(location)}/ws/${liveWebSocketPath}`);
1298
+ const manualActivityDetection = googleOptions?.streaming?.automaticActivityDetection?.disabled === true;
1276
1299
  const setup = {
1277
1300
  model: modelResource,
1278
- inputAudioTranscription: buildAudioTranscriptionConfig(googleOptions) ?? {}
1301
+ inputAudioTranscription: buildAudioTranscriptionConfig(googleOptions) ?? {},
1302
+ ...manualActivityDetection ? { realtimeInputConfig: { automaticActivityDetection: { disabled: true } } } : {}
1279
1303
  };
1280
1304
  return {
1281
1305
  request: { body: setup },
@@ -1289,6 +1313,7 @@ var GoogleVertexGeminiTranscriptionModel = class GoogleVertexGeminiTranscription
1289
1313
  headers,
1290
1314
  setup,
1291
1315
  inputAudioRate: options.inputAudioFormat.rate ?? 16e3,
1316
+ manualActivityDetection,
1292
1317
  finishGraceMs: this.config._internal?.finishGraceMs ?? defaultFinishGraceMs,
1293
1318
  warnings,
1294
1319
  audio: options.audio,
@@ -1298,7 +1323,7 @@ var GoogleVertexGeminiTranscriptionModel = class GoogleVertexGeminiTranscription
1298
1323
  };
1299
1324
  }
1300
1325
  };
1301
- 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 }) {
1302
1327
  let finished = false;
1303
1328
  let cleanup = () => {};
1304
1329
  return new ReadableStream({
@@ -1317,6 +1342,8 @@ function createVertexLiveTranscriptionStream({ webSocket, url, headers, setup, i
1317
1342
  let audioEnded = false;
1318
1343
  let usageMetadata;
1319
1344
  let finishTimer;
1345
+ let lastVoiceActivity;
1346
+ let sentAudioBytes = 0;
1320
1347
  const segmentId = () => `google-segment-${segmentCounter}`;
1321
1348
  const cancelPendingFinish = () => {
1322
1349
  if (finishTimer != null) {
@@ -1359,6 +1386,8 @@ function createVertexLiveTranscriptionStream({ webSocket, url, headers, setup, i
1359
1386
  segmentBuffer = "";
1360
1387
  segmentCounter++;
1361
1388
  };
1389
+ const getSentAudioMs = () => sentAudioBytes / (inputAudioRate * 2) * 1e3;
1390
+ const isTranscriptionComplete = () => lastVoiceActivity?.type === "ACTIVITY_END" && segmentBuffer === "" && latestInterim === "" && (lastVoiceActivity.audioOffsetMs ?? 0) >= getSentAudioMs() - audioEndToleranceMs;
1362
1391
  const finish = () => {
1363
1392
  if (finished) return;
1364
1393
  completeSegment();
@@ -1378,13 +1407,17 @@ function createVertexLiveTranscriptionStream({ webSocket, url, headers, setup, i
1378
1407
  cleanup(1e3);
1379
1408
  };
1380
1409
  const sendAudio = async (socket) => {
1410
+ if (manualActivityDetection) socket.send(JSON.stringify({ realtimeInput: { activityStart: {} } }));
1381
1411
  audioReader = audio.getReader();
1382
1412
  try {
1383
1413
  while (true) {
1384
1414
  const { done, value } = await audioReader.read();
1385
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;
1386
1419
  socket.send(JSON.stringify({ realtimeInput: { audio: {
1387
- data: convertToBase64(value),
1420
+ data,
1388
1421
  mimeType: `audio/pcm;rate=${inputAudioRate}`
1389
1422
  } } }));
1390
1423
  await waitForWebSocketBufferDrain(socket);
@@ -1394,9 +1427,10 @@ function createVertexLiveTranscriptionStream({ webSocket, url, headers, setup, i
1394
1427
  audioReader = void 0;
1395
1428
  }
1396
1429
  if (!finished) {
1397
- socket.send(JSON.stringify({ realtimeInput: { audioStreamEnd: true } }));
1430
+ socket.send(JSON.stringify({ realtimeInput: manualActivityDetection ? { activityEnd: {} } : { audioStreamEnd: true } }));
1398
1431
  audioEnded = true;
1399
- schedulePendingFinish();
1432
+ if (isTranscriptionComplete()) finish();
1433
+ else schedulePendingFinish();
1400
1434
  }
1401
1435
  };
1402
1436
  connection = connectToWebSocket({
@@ -1425,6 +1459,13 @@ function createVertexLiveTranscriptionStream({ webSocket, url, headers, setup, i
1425
1459
  });
1426
1460
  if (message.setupComplete != null) resolveSetupComplete();
1427
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
+ }
1428
1469
  if (message.error != null) {
1429
1470
  finishWithError(new Error(message.error.message ?? "Vertex Live API error"));
1430
1471
  return;
@@ -1455,9 +1496,9 @@ function createVertexLiveTranscriptionStream({ webSocket, url, headers, setup, i
1455
1496
  }
1456
1497
  if (transcription.finished === true) completeSegment();
1457
1498
  }
1458
- if (serverContent?.turnComplete) completeSegment();
1499
+ if (serverContent?.generationComplete || serverContent?.turnComplete) completeSegment();
1459
1500
  const interactionStatus = serverContent?.interactionStatus;
1460
- 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();
1461
1502
  },
1462
1503
  onSocketError: () => {
1463
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 })." : "")));