@livekit/agents 1.0.48 → 1.0.50

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.
Files changed (53) hide show
  1. package/dist/cpu.cjs +189 -0
  2. package/dist/cpu.cjs.map +1 -0
  3. package/dist/cpu.d.cts +24 -0
  4. package/dist/cpu.d.ts +24 -0
  5. package/dist/cpu.d.ts.map +1 -0
  6. package/dist/cpu.js +152 -0
  7. package/dist/cpu.js.map +1 -0
  8. package/dist/cpu.test.cjs +227 -0
  9. package/dist/cpu.test.cjs.map +1 -0
  10. package/dist/cpu.test.js +204 -0
  11. package/dist/cpu.test.js.map +1 -0
  12. package/dist/inference/llm.cjs.map +1 -1
  13. package/dist/inference/llm.d.cts +1 -1
  14. package/dist/inference/llm.d.ts +1 -1
  15. package/dist/inference/llm.d.ts.map +1 -1
  16. package/dist/inference/llm.js.map +1 -1
  17. package/dist/inference/tts.cjs.map +1 -1
  18. package/dist/inference/tts.d.cts +6 -0
  19. package/dist/inference/tts.d.ts +6 -0
  20. package/dist/inference/tts.d.ts.map +1 -1
  21. package/dist/inference/tts.js.map +1 -1
  22. package/dist/ipc/job_proc_lazy_main.cjs +13 -4
  23. package/dist/ipc/job_proc_lazy_main.cjs.map +1 -1
  24. package/dist/ipc/job_proc_lazy_main.js +13 -4
  25. package/dist/ipc/job_proc_lazy_main.js.map +1 -1
  26. package/dist/version.cjs +1 -1
  27. package/dist/version.js +1 -1
  28. package/dist/voice/agent_activity.cjs +39 -8
  29. package/dist/voice/agent_activity.cjs.map +1 -1
  30. package/dist/voice/agent_activity.d.ts.map +1 -1
  31. package/dist/voice/agent_activity.js +40 -9
  32. package/dist/voice/agent_activity.js.map +1 -1
  33. package/dist/voice/agent_session.cjs +27 -1
  34. package/dist/voice/agent_session.cjs.map +1 -1
  35. package/dist/voice/agent_session.d.cts +6 -0
  36. package/dist/voice/agent_session.d.ts +6 -0
  37. package/dist/voice/agent_session.d.ts.map +1 -1
  38. package/dist/voice/agent_session.js +27 -1
  39. package/dist/voice/agent_session.js.map +1 -1
  40. package/dist/worker.cjs +6 -29
  41. package/dist/worker.cjs.map +1 -1
  42. package/dist/worker.d.ts.map +1 -1
  43. package/dist/worker.js +6 -19
  44. package/dist/worker.js.map +1 -1
  45. package/package.json +1 -1
  46. package/src/cpu.test.ts +239 -0
  47. package/src/cpu.ts +173 -0
  48. package/src/inference/llm.ts +2 -0
  49. package/src/inference/tts.ts +8 -1
  50. package/src/ipc/job_proc_lazy_main.ts +15 -4
  51. package/src/voice/agent_activity.ts +68 -10
  52. package/src/voice/agent_session.ts +33 -2
  53. package/src/worker.ts +34 -50
@@ -341,13 +341,27 @@ class AgentActivity {
341
341
  attachAudioInput(audioStream) {
342
342
  void this.audioStream.close();
343
343
  this.audioStream = new import_multi_input_stream.MultiInputStream();
344
+ const aecWarmupAudioFilter = new import_web.TransformStream({
345
+ transform: (frame, controller) => {
346
+ const shouldDiscardForAecWarmup = this.agentSession.agentState === "speaking" && this.agentSession._aecWarmupRemaining > 0;
347
+ if (!shouldDiscardForAecWarmup) {
348
+ controller.enqueue(frame);
349
+ }
350
+ }
351
+ });
344
352
  this.audioStreamId = this.audioStream.addInputStream(audioStream);
345
- const [realtimeAudioStream, recognitionAudioStream] = this.audioStream.stream.tee();
346
- if (this.realtimeSession) {
353
+ if (this.realtimeSession && this.audioRecognition) {
354
+ const [realtimeAudioStream, recognitionAudioStream] = this.audioStream.stream.pipeThrough(aecWarmupAudioFilter).tee();
347
355
  this.realtimeSession.setInputAudioStream(realtimeAudioStream);
348
- }
349
- if (this.audioRecognition) {
350
356
  this.audioRecognition.setInputAudioStream(recognitionAudioStream);
357
+ } else if (this.realtimeSession) {
358
+ this.realtimeSession.setInputAudioStream(
359
+ this.audioStream.stream.pipeThrough(aecWarmupAudioFilter)
360
+ );
361
+ } else if (this.audioRecognition) {
362
+ this.audioRecognition.setInputAudioStream(
363
+ this.audioStream.stream.pipeThrough(aecWarmupAudioFilter)
364
+ );
351
365
  }
352
366
  }
353
367
  detachAudioInput() {
@@ -543,6 +557,9 @@ class AgentActivity {
543
557
  }
544
558
  interruptByAudioActivity() {
545
559
  var _a, _b;
560
+ if (this.agentSession._aecWarmupRemaining > 0) {
561
+ return;
562
+ }
546
563
  if (this.llm instanceof import_llm.RealtimeModel && this.llm.capabilities.turnDetection) {
547
564
  return;
548
565
  }
@@ -719,6 +736,9 @@ class AgentActivity {
719
736
  throw new Error("Speech queue is empty");
720
737
  }
721
738
  const speechHandle = heapItem[2];
739
+ if (speechHandle.interrupted || speechHandle.done()) {
740
+ continue;
741
+ }
722
742
  this._currentSpeech = speechHandle;
723
743
  speechHandle._authorizeGeneration();
724
744
  await speechHandle._waitForGeneration();
@@ -861,7 +881,16 @@ ${instructions}`;
861
881
  speech.interrupt(force);
862
882
  }
863
883
  (_a = this.realtimeSession) == null ? void 0 : _a.interrupt();
864
- if (currentSpeech === void 0) {
884
+ if (force) {
885
+ for (const task of this.speechTasks) {
886
+ task.cancel();
887
+ }
888
+ if (currentSpeech && !currentSpeech.done()) {
889
+ currentSpeech._markDone();
890
+ }
891
+ this.speechQueue.clear();
892
+ future.resolve();
893
+ } else if (currentSpeech === void 0) {
865
894
  future.resolve();
866
895
  } else {
867
896
  currentSpeech.addDoneCallback(() => {
@@ -1229,9 +1258,7 @@ ${instructions}`;
1229
1258
  audioOutput.clearBuffer();
1230
1259
  }
1231
1260
  replyAbortController.abort();
1232
- await Promise.allSettled(
1233
- tasks.map((task) => task.cancelAndWait(AgentActivity.REPLY_TASK_CANCEL_TIMEOUT))
1234
- );
1261
+ await (0, import_utils.cancelAndWait)(tasks, AgentActivity.REPLY_TASK_CANCEL_TIMEOUT);
1235
1262
  let forwardedText = (textOut == null ? void 0 : textOut.text) || "";
1236
1263
  if (audioOutput) {
1237
1264
  const playbackEv = await audioOutput.waitForPlayout();
@@ -1861,6 +1888,10 @@ ${instructions}`;
1861
1888
  const unlock = await this.lock.lock();
1862
1889
  try {
1863
1890
  this.cancelPreemptiveGeneration();
1891
+ await (0, import_utils.cancelAndWait)(Array.from(this.speechTasks), AgentActivity.REPLY_TASK_CANCEL_TIMEOUT);
1892
+ if (this._currentSpeech && !this._currentSpeech.done()) {
1893
+ this._currentSpeech._markDone();
1894
+ }
1864
1895
  await this._closeSessionResources();
1865
1896
  if (this._mainTask) {
1866
1897
  await this._mainTask.cancelAndWait();