@memberjunction/realtime-widget 6.3.0-edge.0 → 6.3.0-edge.2

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.
@@ -40,14 +40,14 @@ import {
40
40
  VideoSourceSeenNote,
41
41
  VideoSourceTurnedOffNote,
42
42
  VideoSourceTurnedOnNote
43
- } from "./chunk-MIJGWKAT.js";
43
+ } from "./chunk-CIZSPKQR.js";
44
44
  import {
45
45
  BaseSingleton,
46
46
  MJGlobal,
47
47
  RegisterClass,
48
48
  __commonJS,
49
49
  __toESM
50
- } from "./chunk-3SGPPDAR.js";
50
+ } from "./chunk-KHEWGJIZ.js";
51
51
 
52
52
  // ../../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js
53
53
  var require_retry_operation = __commonJS({
@@ -1050,6 +1050,14 @@ var BaseRealtimeClient = class _BaseRealtimeClient {
1050
1050
  get RequiresFreshTokenPerReconnect() {
1051
1051
  return true;
1052
1052
  }
1053
+ /**
1054
+ * Whether a credential is minted ahead, shortly before the current one expires, for the next reconnect to use.
1055
+ * `false` for a driver whose credential only opens one connection, which outlives it: each reconnect mints its own,
1056
+ * so one minted ahead is never used.
1057
+ */
1058
+ get RefreshesCredentialAhead() {
1059
+ return true;
1060
+ }
1053
1061
  /**
1054
1062
  * How many connections `credential` may open, or `undefined` for no limit (the default). A driver whose provider
1055
1063
  * counts uses on a credential overrides it, so the client re-mints before it would open a connection the
@@ -1142,7 +1150,7 @@ var BaseRealtimeClient = class _BaseRealtimeClient {
1142
1150
  return this.currentCredential;
1143
1151
  }
1144
1152
  scheduleCredentialRefresh() {
1145
- if (!this.SupportsMidCallReconnect || !this.tokenRefreshCallback || this.reconnectController.IsDisposed) {
1153
+ if (!this.RefreshesCredentialAhead || !this.SupportsMidCallReconnect || !this.tokenRefreshCallback || this.reconnectController.IsDisposed) {
1146
1154
  return;
1147
1155
  }
1148
1156
  this.reconnectController.ScheduleCredentialRefresh(this.currentCredential.ExpiresAt, () => {
@@ -1695,12 +1703,19 @@ var RealtimePcmPlayback = class {
1695
1703
  }
1696
1704
  }
1697
1705
  }
1706
+ /** Resumes the audio context if the browser constructed or left it suspended. */
1707
+ ensureRunning() {
1708
+ if (this.context.state === "suspended" && typeof this.context.resume === "function") {
1709
+ void this.context.resume().catch(() => void 0);
1710
+ }
1711
+ }
1698
1712
  /** @inheritdoc */
1699
1713
  Enqueue(pcm16, mediaTimeMs) {
1700
1714
  const samples = Pcm16ToFloat32(pcm16);
1701
1715
  if (samples.length === 0) {
1702
1716
  return;
1703
1717
  }
1718
+ this.ensureRunning();
1704
1719
  const buffer = this.context.createBuffer(1, samples.length, this.sampleRate);
1705
1720
  buffer.copyToChannel(samples, 0);
1706
1721
  const source = this.context.createBufferSource();
@@ -1766,6 +1781,7 @@ var RealtimePcmPlayback = class {
1766
1781
  * goes on without that element's voice.
1767
1782
  */
1768
1783
  ConnectMediaElement(element) {
1784
+ this.ensureRunning();
1769
1785
  if (this.connectedElements.has(element)) {
1770
1786
  return;
1771
1787
  }
@@ -4171,6 +4187,10 @@ var IMAGE_FRAME_DECODER = {
4171
4187
  };
4172
4188
 
4173
4189
  // ../../AI/RealtimeClient/dist/media/decoders/mseFmp4Decoder.js
4190
+ var DEFAULT_FMP4_PROBE_TYPES = [
4191
+ 'video/mp4; codecs="avc1.42c01f, mp4a.40.2"',
4192
+ 'video/mp4; codecs="avc1.42c01f"'
4193
+ ];
4174
4194
  var TRIM_STEP_SECONDS = 5;
4175
4195
  var QUOTA_BACK_BUFFER_SECONDS = 2;
4176
4196
  var MAX_PENDING_PIECES = 600;
@@ -4190,10 +4210,23 @@ function mseTypeOf(init) {
4190
4210
  }
4191
4211
  return `video/mp4; codecs="${tracks.map((track) => track.Codec).join(", ")}"`;
4192
4212
  }
4213
+ function resolvePlayableMseType(mimeType) {
4214
+ const ms = mediaSourceClass();
4215
+ if (!ms) {
4216
+ return null;
4217
+ }
4218
+ if (ms.Class.isTypeSupported(mimeType)) {
4219
+ return mimeType;
4220
+ }
4221
+ if (MimeEssence(mimeType) === "video/mp4" && !MimeCodec(mimeType)) {
4222
+ return DEFAULT_FMP4_PROBE_TYPES.find((candidate) => ms.Class.isTypeSupported(candidate)) ?? null;
4223
+ }
4224
+ return null;
4225
+ }
4193
4226
  var MseFmp4Decoder = class {
4194
4227
  /** Whether this browser can play `mimeType` through MSE. */
4195
4228
  static CanPlay(mimeType) {
4196
- return mediaSourceClass()?.Class.isTypeSupported(mimeType) ?? false;
4229
+ return resolvePlayableMseType(mimeType) !== null;
4197
4230
  }
4198
4231
  /** @param context The player this decoder plays for. */
4199
4232
  constructor(context) {
@@ -4302,7 +4335,7 @@ var MseFmp4Decoder = class {
4302
4335
  }
4303
4336
  this.detach();
4304
4337
  const mse = mediaSourceClass();
4305
- if (!mse || !mse.Class.isTypeSupported(this.mimeType)) {
4338
+ if (!mse || !resolvePlayableMseType(this.mimeType)) {
4306
4339
  this.context.Report("unsupported", `This browser cannot play ${this.mimeType} through Media Source Extensions.`);
4307
4340
  return;
4308
4341
  }
@@ -4371,10 +4404,13 @@ var MseFmp4Decoder = class {
4371
4404
  this.handleAppendError(err);
4372
4405
  }
4373
4406
  }
4374
- /** The type for a source buffer that takes `init`: the init's own codecs when this browser plays them, else the player's type. */
4407
+ /** The type for a source buffer that takes `init`: the init's own codecs when this browser plays them, else the player's resolved MSE type. */
4375
4408
  typeFor(init) {
4376
4409
  const fromInit = init ? mseTypeOf(init) : null;
4377
- return fromInit && mediaSourceClass()?.Class.isTypeSupported(fromInit) ? fromInit : this.mimeType;
4410
+ if (fromInit && mediaSourceClass()?.Class.isTypeSupported(fromInit)) {
4411
+ return fromInit;
4412
+ }
4413
+ return resolvePlayableMseType(this.mimeType) ?? this.mimeType;
4378
4414
  }
4379
4415
  /**
4380
4416
  * Switches the source buffer to an init segment's codecs before the init is appended, when they differ from the
@@ -27755,6 +27791,10 @@ var GeminiRealtimeClient = class GeminiRealtimeClient2 extends BaseRealtimeClien
27755
27791
  this.interactionInProgress = false;
27756
27792
  this.toolBatchBarrier = new RealtimeToolBatchBarrier();
27757
27793
  this.assistantSafetyBackstopTimer = null;
27794
+ this.blockingBatchOwed = /* @__PURE__ */ new Set();
27795
+ this.blockingBatchExpired = /* @__PURE__ */ new Set();
27796
+ this.blockingBatchStarted = false;
27797
+ this.blockingBatchCommitHeld = false;
27758
27798
  this.pendingAssistantText = "";
27759
27799
  this.pendingUserText = "";
27760
27800
  this.pendingThoughtText = "";
@@ -27773,6 +27813,9 @@ var GeminiRealtimeClient = class GeminiRealtimeClient2 extends BaseRealtimeClien
27773
27813
  static {
27774
27814
  this.ASSISTANT_SAFETY_BACKSTOP_MS = 15e3;
27775
27815
  }
27816
+ static {
27817
+ this.BLOCKING_TOOL_REPLY_BACKSTOP_MS = 1e4;
27818
+ }
27776
27819
  static {
27777
27820
  this.GEMINI_LIVE_CONNECTION_SECONDS = 600;
27778
27821
  }
@@ -27878,6 +27921,14 @@ var GeminiRealtimeClient = class GeminiRealtimeClient2 extends BaseRealtimeClien
27878
27921
  get isNonBlocking() {
27879
27922
  return !this.supportsBlocking;
27880
27923
  }
27924
+ /**
27925
+ * Whether tool-call frames are tracked as blocking batches: blocking tooling on the `turnComplete`
27926
+ * idle signal. Gemini waits for every result of a frame before it answers, while one result marks
27927
+ * the client busy for the reply.
27928
+ */
27929
+ get tracksBlockingBatch() {
27930
+ return !this.isNonBlocking && this.idleSignal === "turnComplete";
27931
+ }
27881
27932
  // ── BaseRealtimeClient: connection lifecycle ───────────────────────────────
27882
27933
  /**
27883
27934
  * Opens the client-direct Gemini Live session: creates the playout engine, connects with
@@ -27936,6 +27987,7 @@ var GeminiRealtimeClient = class GeminiRealtimeClient2 extends BaseRealtimeClien
27936
27987
  this.cameraStream = cameraStream ?? null;
27937
27988
  this.clearSafetyBackstop();
27938
27989
  this.toolBatchBarrier.Clear();
27990
+ this.closeBlockingBatch();
27939
27991
  this.firstVideoSendTimestamp = 0;
27940
27992
  this.lastVideoSendTimestamp = 0;
27941
27993
  this.videoFramesSent = 0;
@@ -28301,7 +28353,8 @@ var GeminiRealtimeClient = class GeminiRealtimeClient2 extends BaseRealtimeClien
28301
28353
  return false;
28302
28354
  }
28303
28355
  const name = this.pendingToolCallNames.get(callID) ?? "";
28304
- this.enqueueOrRun(() => this.sendToolResponseTurn(callID, name, outputJson), !this.isNonBlocking);
28356
+ const waitsForTurn = !this.isNonBlocking && !this.skipsTurnWaitInBatch(callID);
28357
+ this.enqueueOrRun(() => this.sendToolResponseTurn(callID, name, outputJson), waitsForTurn, callID);
28305
28358
  }
28306
28359
  /**
28307
28360
  * Mutes / unmutes by toggling the mic tracks' `enabled` flag: the capture pipeline stays
@@ -28698,6 +28751,7 @@ var GeminiRealtimeClient = class GeminiRealtimeClient2 extends BaseRealtimeClien
28698
28751
  if (this.sendHeldMicAudio()) {
28699
28752
  this.noteUnansweredSpeech();
28700
28753
  }
28754
+ this.releaseHeldBatchCommitAfterMove();
28701
28755
  this.flushQueuedSends();
28702
28756
  return true;
28703
28757
  }
@@ -28787,6 +28841,7 @@ var GeminiRealtimeClient = class GeminiRealtimeClient2 extends BaseRealtimeClien
28787
28841
  for (const callID of this.pendingToolCallNames.keys()) {
28788
28842
  this.callsFromBeforeReseed.add(callID);
28789
28843
  }
28844
+ this.closeBlockingBatch();
28790
28845
  }
28791
28846
  if (!handle && context.ConversationSeed && context.ConversationSeed.Entries.length > 0) {
28792
28847
  if (target.Transport === "relay") {
@@ -28894,6 +28949,7 @@ var GeminiRealtimeClient = class GeminiRealtimeClient2 extends BaseRealtimeClien
28894
28949
  this.connectionReady = true;
28895
28950
  this.setState("listening");
28896
28951
  this.sendHeldMicAudio();
28952
+ this.releaseHeldBatchCommitAfterMove();
28897
28953
  this.flushQueuedSends();
28898
28954
  }
28899
28955
  /** Every resume attempt failed: the session ends with a fatal error. */
@@ -28936,8 +28992,8 @@ var GeminiRealtimeClient = class GeminiRealtimeClient2 extends BaseRealtimeClien
28936
28992
  this.scheduleSafetyBackstop();
28937
28993
  }
28938
28994
  } else if (status === "IDLE") {
28939
- this.clearSafetyBackstop();
28940
28995
  if (this.idleSignal === "interactionStatus") {
28996
+ this.clearSafetyBackstop();
28941
28997
  this.handleIdleTerminal();
28942
28998
  } else {
28943
28999
  this.interactionInProgress = false;
@@ -29117,6 +29173,9 @@ var GeminiRealtimeClient = class GeminiRealtimeClient2 extends BaseRealtimeClien
29117
29173
  }
29118
29174
  for (const part of modelTurn.parts) {
29119
29175
  if (part.thought && part.text) {
29176
+ if (this.tracksBlockingBatch && this.assistantSafetyBackstopTimer) {
29177
+ this.scheduleSafetyBackstop(GeminiRealtimeClient_1.BLOCKING_TOOL_REPLY_BACKSTOP_MS);
29178
+ }
29120
29179
  this.pendingThoughtText += part.text;
29121
29180
  this.emitTranscript({
29122
29181
  Role: "Assistant",
@@ -29184,7 +29243,12 @@ var GeminiRealtimeClient = class GeminiRealtimeClient2 extends BaseRealtimeClien
29184
29243
  if (this.currentState === "speaking") {
29185
29244
  this.currentState = "connected";
29186
29245
  }
29187
- this.responseActive = false;
29246
+ if (!this.blockingBatchInProgress) {
29247
+ this.responseActive = false;
29248
+ }
29249
+ }
29250
+ if (this.tracksBlockingBatch) {
29251
+ this.openBlockingBatch(functionCalls.map((call) => call.id ?? ""));
29188
29252
  }
29189
29253
  for (const call of functionCalls) {
29190
29254
  const callID = call.id ?? "";
@@ -29211,10 +29275,12 @@ var GeminiRealtimeClient = class GeminiRealtimeClient2 extends BaseRealtimeClien
29211
29275
  this.finalizeAssistantTranscript();
29212
29276
  this.finalizeThoughtTranscript();
29213
29277
  if (this.idleSignal === "turnComplete") {
29278
+ this.clearSafetyBackstop();
29214
29279
  this.endTurnUnlessToolCallPending();
29215
29280
  this.responseActive = false;
29216
29281
  this.activeResponseKind = "normal";
29217
29282
  this.openClientTurn = false;
29283
+ this.blockingBatchCommitHeld = false;
29218
29284
  this.flushQueuedSends();
29219
29285
  if (this.currentState === "speaking") {
29220
29286
  this.setState("listening");
@@ -29236,11 +29302,15 @@ var GeminiRealtimeClient = class GeminiRealtimeClient2 extends BaseRealtimeClien
29236
29302
  this.finalizeAssistantTranscript();
29237
29303
  this.activeResponseKind = "normal";
29238
29304
  this.finalizeThoughtTranscript();
29239
- if (this.openClientTurn && this.toolResponseAwaitsCommit) {
29240
- this.session?.sendClientContent({ turnComplete: true });
29305
+ const keepBatchCommitForMove = this.blockingBatchCommitHeld && this.openClientTurn && !this.connectionReady;
29306
+ if (!keepBatchCommitForMove) {
29307
+ if (this.openClientTurn && (this.toolResponseAwaitsCommit || this.blockingBatchCommitHeld)) {
29308
+ this.session?.sendClientContent({ turnComplete: true });
29309
+ }
29310
+ this.openClientTurn = false;
29311
+ this.toolResponseAwaitsCommit = false;
29312
+ this.blockingBatchCommitHeld = false;
29241
29313
  }
29242
- this.openClientTurn = false;
29243
- this.toolResponseAwaitsCommit = false;
29244
29314
  this.flushQueuedSends();
29245
29315
  if (this.currentState === "speaking" && !this.IsAudioPlaying) {
29246
29316
  this.setState("listening");
@@ -29257,6 +29327,8 @@ var GeminiRealtimeClient = class GeminiRealtimeClient2 extends BaseRealtimeClien
29257
29327
  if (this.idleSignal === "interactionStatus") {
29258
29328
  this.interactionInProgress = true;
29259
29329
  this.scheduleSafetyBackstop();
29330
+ } else {
29331
+ this.clearSafetyBackstop();
29260
29332
  }
29261
29333
  if (this.currentState !== "speaking") {
29262
29334
  this.setState("speaking");
@@ -29353,11 +29425,12 @@ var GeminiRealtimeClient = class GeminiRealtimeClient2 extends BaseRealtimeClien
29353
29425
  *
29354
29426
  * @param send The send.
29355
29427
  * @param waitsForTurn Whether the send waits for a turn in flight (`false` for a non-blocking
29356
- * tool result, which goes out while the model talks).
29428
+ * tool result, which goes out while the model talks, and for a blocking batch's later results).
29429
+ * @param toolCallID The call a tool-result send answers, so {@link drainBlockingBatchResults} can find it.
29357
29430
  */
29358
- enqueueOrRun(send, waitsForTurn = true) {
29431
+ enqueueOrRun(send, waitsForTurn = true, toolCallID) {
29359
29432
  if (!this.connectionReady || waitsForTurn && this.responseActive) {
29360
- this.queuedSends.push(send);
29433
+ this.queuedSends.push({ Run: send, ToolCallID: toolCallID });
29361
29434
  return;
29362
29435
  }
29363
29436
  send();
@@ -29370,8 +29443,90 @@ var GeminiRealtimeClient = class GeminiRealtimeClient2 extends BaseRealtimeClien
29370
29443
  flushQueuedSends() {
29371
29444
  while (!this.responseActive && this.connectionReady && this.queuedSends.length > 0) {
29372
29445
  const send = this.queuedSends.shift();
29373
- send?.();
29446
+ send?.Run();
29447
+ }
29448
+ }
29449
+ // ── Blocking tool-call batch (see tracksBlockingBatch) ─────────────────────
29450
+ /** A `toolCall` frame: open a batch, or join the open one while its results are still owed. */
29451
+ openBlockingBatch(callIDs) {
29452
+ this.clearSafetyBackstop();
29453
+ this.blockingBatchExpired.clear();
29454
+ if (this.blockingBatchOwed.size === 0) {
29455
+ this.blockingBatchStarted = false;
29456
+ }
29457
+ for (const callID of callIDs) {
29458
+ this.blockingBatchOwed.add(callID);
29459
+ }
29460
+ }
29461
+ /**
29462
+ * Whether a blocking result goes out without waiting for the turn in flight: once the batch's first result
29463
+ * went out (and marked the client busy for the reply), the batch's other results do; so does a late result of
29464
+ * a batch the barrier expired. Before the first result nothing skips, so a user turn that took the floor first
29465
+ * keeps it. A call from before a re-seed never skips: its late result starts a reply of its own.
29466
+ */
29467
+ skipsTurnWaitInBatch(callID) {
29468
+ if (!this.tracksBlockingBatch || this.callsFromBeforeReseed.has(callID)) {
29469
+ return false;
29374
29470
  }
29471
+ return this.blockingBatchStarted && this.blockingBatchOwed.has(callID) || this.blockingBatchExpired.has(callID);
29472
+ }
29473
+ /**
29474
+ * Whether the open batch still owes results other than this call's, so the reply is not next yet. Only OTHER
29475
+ * owed calls count: a result the batch does not owe (a duplicate, or a stale result of an expired batch) does not
29476
+ * complete it.
29477
+ */
29478
+ batchOwesOtherResults(callID) {
29479
+ return this.blockingBatchOwed.size - (this.blockingBatchOwed.has(callID) ? 1 : 0) > 0;
29480
+ }
29481
+ /** A started batch still owes results: the reply comes after them, so the client stays busy for it. */
29482
+ get blockingBatchInProgress() {
29483
+ return this.tracksBlockingBatch && this.blockingBatchStarted && this.blockingBatchOwed.size > 0;
29484
+ }
29485
+ /** A queued send is a batch result that skips the turn wait (see {@link drainBlockingBatchResults}). */
29486
+ isQueuedBatchResult(send) {
29487
+ return send.ToolCallID !== void 0 && this.skipsTurnWaitInBatch(send.ToolCallID);
29488
+ }
29489
+ /**
29490
+ * Whether a batch result other than this call's is still queued and about to be drained (the barrier expired the
29491
+ * batch, or results were queued while the session moved): the commit waits for the last of them.
29492
+ */
29493
+ batchResultQueuedAfter(callID) {
29494
+ return this.queuedSends.some((send) => send.ToolCallID !== callID && this.isQueuedBatchResult(send));
29495
+ }
29496
+ /**
29497
+ * A blocking result went out: when the batch still owes results, send the ones already queued (only those,
29498
+ * in queue order); when it is complete, arm the no-output backstop for the reply.
29499
+ */
29500
+ afterBlockingResult(callID) {
29501
+ if (!this.tracksBlockingBatch) {
29502
+ return;
29503
+ }
29504
+ this.blockingBatchExpired.delete(callID);
29505
+ if (this.blockingBatchOwed.delete(callID) && this.blockingBatchOwed.size > 0) {
29506
+ this.blockingBatchStarted = true;
29507
+ }
29508
+ this.drainBlockingBatchResults();
29509
+ if (this.blockingBatchOwed.size === 0 && this.responseActive) {
29510
+ this.scheduleSafetyBackstop(GeminiRealtimeClient_1.BLOCKING_TOOL_REPLY_BACKSTOP_MS);
29511
+ }
29512
+ }
29513
+ /** Sends the batch's queued results in queue order; every other queued send stays where it is. Re-entrant. */
29514
+ drainBlockingBatchResults() {
29515
+ while (this.connectionReady) {
29516
+ const index = this.queuedSends.findIndex((send2) => this.isQueuedBatchResult(send2));
29517
+ if (index < 0) {
29518
+ return;
29519
+ }
29520
+ const [send] = this.queuedSends.splice(index, 1);
29521
+ send.Run();
29522
+ }
29523
+ }
29524
+ /** No batch any more (connect, disconnect, re-seed). */
29525
+ closeBlockingBatch() {
29526
+ this.blockingBatchOwed.clear();
29527
+ this.blockingBatchExpired.clear();
29528
+ this.blockingBatchStarted = false;
29529
+ this.blockingBatchCommitHeld = false;
29375
29530
  }
29376
29531
  /**
29377
29532
  * Sends a user turn that TRIGGERS generation (`turnComplete: true`), stamping the upcoming
@@ -29390,6 +29545,8 @@ var GeminiRealtimeClient = class GeminiRealtimeClient2 extends BaseRealtimeClien
29390
29545
  if (this.idleSignal === "interactionStatus") {
29391
29546
  this.interactionInProgress = true;
29392
29547
  this.scheduleSafetyBackstop();
29548
+ } else {
29549
+ this.clearSafetyBackstop();
29393
29550
  }
29394
29551
  this.activeResponseKind = kind;
29395
29552
  if (emitSpeaking) {
@@ -29466,16 +29623,23 @@ var GeminiRealtimeClient = class GeminiRealtimeClient2 extends BaseRealtimeClien
29466
29623
  if (this.isNonBlocking) {
29467
29624
  this.toolResponseAwaitsCommit = this.toolResponseAwaitsCommit || this.openClientTurn;
29468
29625
  } else {
29469
- if (this.openClientTurn) {
29626
+ const othersOwed = this.tracksBlockingBatch && this.batchOwesOtherResults(callID);
29627
+ const batchResultsFollow = othersOwed || this.tracksBlockingBatch && this.batchResultQueuedAfter(callID);
29628
+ const holdCommit = this.openClientTurn && batchResultsFollow;
29629
+ if (this.openClientTurn && !holdCommit) {
29470
29630
  session.sendClientContent({ turnComplete: true });
29471
29631
  this.openClientTurn = false;
29472
29632
  }
29473
- this.responseActive = true;
29474
- this.activeResponseKind = "normal";
29475
- this.setState("speaking");
29633
+ this.blockingBatchCommitHeld = holdCommit;
29634
+ if (!(othersOwed && !this.blockingBatchOwed.has(callID))) {
29635
+ this.responseActive = true;
29636
+ this.activeResponseKind = "normal";
29637
+ this.setState("speaking");
29638
+ }
29476
29639
  }
29477
29640
  this.pendingToolCallNames.delete(callID);
29478
29641
  this.endTurnIfToolResultsIn(sched !== FunctionResponseScheduling.SILENT);
29642
+ this.afterBlockingResult(callID);
29479
29643
  }
29480
29644
  /**
29481
29645
  * Parses a JSON-stringified tool result into the structured object Gemini's
@@ -29510,10 +29674,64 @@ var GeminiRealtimeClient = class GeminiRealtimeClient2 extends BaseRealtimeClien
29510
29674
  handleSafetyBackstopTrigger() {
29511
29675
  this.handleIdleTerminal();
29512
29676
  }
29677
+ /**
29678
+ * The tool-batch barrier stopped waiting for a result. It records a result at SEND time, so the missing ones may
29679
+ * be slow, never coming (a cancelled call), or queued behind another turn. A blocking batch expires: its queued
29680
+ * results go out whatever {@link responseActive} is (a late one still skips the turn wait), a held commit goes
29681
+ * out, and the backstop guards the reply.
29682
+ */
29513
29683
  handleToolBatchTimeout() {
29684
+ if (this.tracksBlockingBatch) {
29685
+ for (const callID of this.blockingBatchOwed) {
29686
+ this.blockingBatchExpired.add(callID);
29687
+ }
29688
+ this.blockingBatchOwed.clear();
29689
+ this.blockingBatchStarted = false;
29690
+ this.drainBlockingBatchResults();
29691
+ this.releaseHeldBatchCommit();
29692
+ }
29514
29693
  if (this.idleSignal === "turnComplete") {
29515
29694
  this.flushQueuedSends();
29516
29695
  }
29696
+ if (this.tracksBlockingBatch && this.responseActive) {
29697
+ this.scheduleSafetyBackstop(GeminiRealtimeClient_1.BLOCKING_TOOL_REPLY_BACKSTOP_MS);
29698
+ }
29699
+ }
29700
+ /**
29701
+ * Sends a commit held for a batch that will not reach its last result; a turn that already ended needs none. The
29702
+ * commit asks for the reply, so the client is busy for it and the no-output backstop guards it.
29703
+ */
29704
+ releaseHeldBatchCommit() {
29705
+ if (!this.blockingBatchCommitHeld) {
29706
+ return;
29707
+ }
29708
+ if (!this.openClientTurn) {
29709
+ this.blockingBatchCommitHeld = false;
29710
+ return;
29711
+ }
29712
+ if (!this.connectionReady) {
29713
+ return;
29714
+ }
29715
+ this.session?.sendClientContent({ turnComplete: true });
29716
+ this.openClientTurn = false;
29717
+ this.blockingBatchCommitHeld = false;
29718
+ this.responseActive = true;
29719
+ this.activeResponseKind = "normal";
29720
+ this.scheduleSafetyBackstop(GeminiRealtimeClient_1.BLOCKING_TOOL_REPLY_BACKSTOP_MS);
29721
+ }
29722
+ /**
29723
+ * The session continues on a connection (a completed move, or the old one after a failed attempt). Batch results
29724
+ * queued during the move go out first; a commit still held while the batch owes nothing then goes out, so it is
29725
+ * not stranded. A re-seed closed the batch already, so this does nothing there.
29726
+ */
29727
+ releaseHeldBatchCommitAfterMove() {
29728
+ if (!this.tracksBlockingBatch) {
29729
+ return;
29730
+ }
29731
+ this.drainBlockingBatchResults();
29732
+ if (this.blockingBatchOwed.size === 0) {
29733
+ this.releaseHeldBatchCommit();
29734
+ }
29517
29735
  }
29518
29736
  /** Resets the per-session response state machine (used on Disconnect). */
29519
29737
  resetResponseState() {
@@ -29529,6 +29747,7 @@ var GeminiRealtimeClient = class GeminiRealtimeClient2 extends BaseRealtimeClien
29529
29747
  this.queuedSends = [];
29530
29748
  this.pendingToolCallNames.clear();
29531
29749
  this.toolBatchBarrier.Clear();
29750
+ this.closeBlockingBatch();
29532
29751
  this.clearSafetyBackstop();
29533
29752
  }
29534
29753
  /** Updates the client's own state view and emits the change to the host. */
@@ -31296,13 +31515,114 @@ AssemblyAIRealtimeClient = __decorate5([
31296
31515
  RegisterClass(BaseRealtimeClient, "assemblyai")
31297
31516
  ], AssemblyAIRealtimeClient);
31298
31517
 
31299
- // ../../AI/RealtimeClient/dist/drivers/xaiRealtimeClient.js
31518
+ // ../../AI/RealtimeClient/dist/drivers/assemblyAIVoiceRealtimeClient.js
31300
31519
  var __decorate6 = function(decorators, target, key, desc) {
31301
31520
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
31302
31521
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
31303
31522
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
31304
31523
  return c > 3 && r && Object.defineProperty(target, key, r), r;
31305
31524
  };
31525
+ var ASSEMBLYAI_VOICE_PCM_SAMPLE_RATE = 24e3;
31526
+ var AssemblyAIVoiceRealtimeClient = class AssemblyAIVoiceRealtimeClient2 extends OpenAIProtocolWebSocketRealtimeClient {
31527
+ constructor() {
31528
+ super(...arguments);
31529
+ this.timeLimitReached = false;
31530
+ }
31531
+ /** @inheritdoc */
31532
+ get providerDebugLabel() {
31533
+ return "AssemblyAIVoiceRealtimeClient";
31534
+ }
31535
+ /** @inheritdoc — the server decides when a connection must be replaced, and says so in the minted config. */
31536
+ get DefaultCallDurationSeconds() {
31537
+ return void 0;
31538
+ }
31539
+ /** @inheritdoc — a proxy ticket opens one connection, and the call outlives it. */
31540
+ get RefreshesCredentialAhead() {
31541
+ return false;
31542
+ }
31543
+ /** @inheritdoc — the proxy URL is the credential. */
31544
+ openProviderSocket(config) {
31545
+ this.timeLimitReached = false;
31546
+ return this.createSocket(config.EphemeralToken);
31547
+ }
31548
+ /** @inheritdoc — the agent sends it once it can hear and speak. */
31549
+ get waitsForSessionCreated() {
31550
+ return true;
31551
+ }
31552
+ /** @inheritdoc — none: the server applied it (see the class docs). */
31553
+ resolveSessionObject(_config) {
31554
+ return {};
31555
+ }
31556
+ /** @inheritdoc */
31557
+ resolveSampleRate(config) {
31558
+ const rate = config.SessionConfig?.["sampleRate"];
31559
+ return typeof rate === "number" && rate > 0 ? rate : ASSEMBLYAI_VOICE_PCM_SAMPLE_RATE;
31560
+ }
31561
+ /** @inheritdoc — the server always ends a reply with `response.done`, so a tool call need not release it early. */
31562
+ get releasesBusyFlagOnToolCall() {
31563
+ return false;
31564
+ }
31565
+ /** @inheritdoc */
31566
+ get unexpectedCloseMessage() {
31567
+ return "AssemblyAI voice connection closed unexpectedly";
31568
+ }
31569
+ /** @inheritdoc — a call that reached its time limit ends; any other lost connection is recovered. */
31570
+ handleSocketClose() {
31571
+ if (this.timeLimitReached && !this.closedByConsumer && this.currentState !== "error" && this.currentState !== "closed") {
31572
+ this.emitError({ Message: "Call time limit reached", Code: REALTIME_CLIENT_TIME_LIMIT_ERROR_CODE, Fatal: true });
31573
+ this.setState("error");
31574
+ return;
31575
+ }
31576
+ super.handleSocketClose();
31577
+ }
31578
+ /**
31579
+ * @inheritdoc — first finishes the transcript of a reply in progress. The server ends a reply when it has played, not
31580
+ * when it was written, so a hang-up during one would lose it from the conversation.
31581
+ */
31582
+ async Disconnect() {
31583
+ const spoken = this.pendingAssistantText;
31584
+ this.pendingAssistantText = "";
31585
+ if (spoken.trim().length > 0) {
31586
+ this.emitTranscript({ Role: "Assistant", Text: spoken, IsFinal: true, Kind: this.activeResponseKind });
31587
+ }
31588
+ await super.Disconnect();
31589
+ }
31590
+ /** Creates the websocket. Production wraps the platform `WebSocket`. */
31591
+ createSocket(url) {
31592
+ const WS = globalThis.WebSocket;
31593
+ if (!WS) {
31594
+ throw new Error("AssemblyAIVoiceRealtimeClient requires a global WebSocket (browser or Node 22+).");
31595
+ }
31596
+ const ws = new WS(url);
31597
+ const seam = {
31598
+ onopen: null,
31599
+ onmessage: null,
31600
+ onerror: null,
31601
+ onclose: null,
31602
+ send: (data) => ws.send(data),
31603
+ close: () => ws.close()
31604
+ };
31605
+ ws.onopen = () => seam.onopen?.();
31606
+ ws.onmessage = (event) => seam.onmessage?.(String(event.data));
31607
+ ws.onerror = () => seam.onerror?.("AssemblyAI voice websocket error");
31608
+ ws.onclose = (event) => {
31609
+ this.timeLimitReached = event?.code === REALTIME_RELAY_TIME_LIMIT_CLOSE_CODE;
31610
+ seam.onclose?.();
31611
+ };
31612
+ return seam;
31613
+ }
31614
+ };
31615
+ AssemblyAIVoiceRealtimeClient = __decorate6([
31616
+ RegisterClass(BaseRealtimeClient, "assemblyai-voice")
31617
+ ], AssemblyAIVoiceRealtimeClient);
31618
+
31619
+ // ../../AI/RealtimeClient/dist/drivers/xaiRealtimeClient.js
31620
+ var __decorate7 = function(decorators, target, key, desc) {
31621
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
31622
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
31623
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
31624
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
31625
+ };
31306
31626
  var XAI_REALTIME_WS_URL = "wss://api.x.ai/v1/realtime";
31307
31627
  var XAI_CLIENT_SECRET_SUBPROTOCOL_PREFIX = "xai-client-secret.";
31308
31628
  var XAI_PCM_SAMPLE_RATE = 24e3;
@@ -31465,12 +31785,12 @@ var xAIRealtimeClient = class xAIRealtimeClient2 extends OpenAIProtocolWebSocket
31465
31785
  }
31466
31786
  }
31467
31787
  };
31468
- xAIRealtimeClient = __decorate6([
31788
+ xAIRealtimeClient = __decorate7([
31469
31789
  RegisterClass(BaseRealtimeClient, "xai")
31470
31790
  ], xAIRealtimeClient);
31471
31791
 
31472
31792
  // ../../AI/RealtimeClient/dist/drivers/elevenRealtimeClient.js
31473
- var __decorate7 = function(decorators, target, key, desc) {
31793
+ var __decorate8 = function(decorators, target, key, desc) {
31474
31794
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
31475
31795
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
31476
31796
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -31553,12 +31873,12 @@ var ElevenRealtimeClient = class ElevenRealtimeClient2 extends OpenAIProtocolWeb
31553
31873
  }
31554
31874
  }
31555
31875
  };
31556
- ElevenRealtimeClient = __decorate7([
31876
+ ElevenRealtimeClient = __decorate8([
31557
31877
  RegisterClass(BaseRealtimeClient, "eleven-realtime")
31558
31878
  ], ElevenRealtimeClient);
31559
31879
 
31560
31880
  // ../../AI/RealtimeClient/dist/drivers/huggingFaceRealtimeClient.js
31561
- var __decorate8 = function(decorators, target, key, desc) {
31881
+ var __decorate9 = function(decorators, target, key, desc) {
31562
31882
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
31563
31883
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
31564
31884
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -31642,12 +31962,12 @@ var HuggingFaceRealtimeClient = class HuggingFaceRealtimeClient2 extends OpenAIP
31642
31962
  return seam;
31643
31963
  }
31644
31964
  };
31645
- HuggingFaceRealtimeClient = __decorate8([
31965
+ HuggingFaceRealtimeClient = __decorate9([
31646
31966
  RegisterClass(BaseRealtimeClient, "huggingface")
31647
31967
  ], HuggingFaceRealtimeClient);
31648
31968
 
31649
31969
  // ../../AI/RealtimeClient/dist/drivers/openAILiveClient.js
31650
- var __decorate9 = function(decorators, target, key, desc) {
31970
+ var __decorate10 = function(decorators, target, key, desc) {
31651
31971
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
31652
31972
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
31653
31973
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -32527,7 +32847,7 @@ var OpenAILiveClient = class OpenAILiveClient2 extends BaseRealtimeClient {
32527
32847
  }
32528
32848
  }
32529
32849
  };
32530
- OpenAILiveClient = OpenAILiveClient_1 = __decorate9([
32850
+ OpenAILiveClient = OpenAILiveClient_1 = __decorate10([
32531
32851
  RegisterClass(BaseRealtimeClient, "openai-live"),
32532
32852
  RegisterClass(BaseRealtimeClient, "OpenAILiveRealtime")
32533
32853
  ], OpenAILiveClient);
@@ -32641,7 +32961,7 @@ var WidgetChannelHost = class {
32641
32961
  };
32642
32962
 
32643
32963
  // dist/voice/channels/whiteboard-channel.js
32644
- var __decorate10 = function(decorators, target, key, desc) {
32964
+ var __decorate11 = function(decorators, target, key, desc) {
32645
32965
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
32646
32966
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
32647
32967
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -32820,7 +33140,7 @@ var WidgetWhiteboardChannel = class WidgetWhiteboardChannel2 extends BaseWidgetC
32820
33140
  return JSON.stringify({ ok: true, action: description, shapeCount: this.shapeCount });
32821
33141
  }
32822
33142
  };
32823
- WidgetWhiteboardChannel = __decorate10([
33143
+ WidgetWhiteboardChannel = __decorate11([
32824
33144
  RegisterClass(BaseWidgetChannel, CHANNEL_NAME)
32825
33145
  ], WidgetWhiteboardChannel);
32826
33146
  function LoadWidgetWhiteboardChannel() {