@todoforai/voiceloop 0.1.29 → 0.1.30

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@todoforai/voiceloop",
3
- "version": "0.1.29",
3
+ "version": "0.1.30",
4
4
  "description": "Fast, interruptible browser voice agent: VAD → STT → LLM → TTS with real barge-in, echo filtering, streaming first-sentence TTS and tap-to-seek. Zero runtime dependencies.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -305,7 +305,7 @@ export class VoiceAgent {
305
305
  this._onUserTurn(text, { speech: true }); // only a SPOKEN final may adopt the prefetch it seeded
306
306
  },
307
307
  onError: (error) => this.onEvent({ type: 'error', error }),
308
- onFatal: (error) => { this.stop(); this.onEvent({ type: 'error', error }); }, // auth/config — won't self-heal; stop FIRST so the error event sees `closed` (host reconciles `running`)
308
+ onFatal: (error) => { this.stop(); this._teardownPipeline(); this.onEvent({ type: 'error', error }); }, // auth/config — won't self-heal; stop FIRST so the error event sees `closed` (host reconciles `running`); release the mic — the host keeps the agent for typing, so a paused pipeline would hold it indefinitely
309
309
  onClose: () => {},
310
310
  isClosed: () => this._closed,
311
311
  });
@@ -540,11 +540,14 @@ export class VoiceAgent {
540
540
  // session) and before a cold rebuild (mic device switch). After this, start() pays the full cold
541
541
  // cost again. Split out so stop() can pause cheaply without duplicating this.
542
542
  _teardownPipeline() {
543
+ // Mic tracks FIRST, and nothing below may abort the teardown: vad-web's destroy() throws on a
544
+ // created-but-never-started MicVAD (Silero loaded while bootstrap VAD was still active), which
545
+ // used to skip the track stop and leak the mic (tab kept the recording indicator).
546
+ this._stream?.getTracks().forEach(t => t.stop()); this._stream = null;
543
547
  this._capture?.stop(); this._capture = null;
544
- this._vad?.destroy?.(); this._vad = null;
548
+ try { this._vad?.destroy?.(); } catch {} this._vad = null;
545
549
  this._node?.disconnect(); this._node = null;
546
550
  this._ctx?.close(); this._ctx = null;
547
- this._stream?.getTracks().forEach(t => t.stop()); this._stream = null;
548
551
  this._streamDeviceId = undefined;
549
552
  this._tap = []; this._tapSamples = 0; this._tapTotal = 0; this._tapLastMs = 0; this._tapGaps = []; // fresh diagnostics per pipeline
550
553
  }
@@ -1235,7 +1238,7 @@ export class VoiceAgent {
1235
1238
  // A stale build (the pipeline was superseded/torn down while MicVAD.new() resolved) must not
1236
1239
  // stomp the current session's _vad — destroy its own instance and bail (the caller's .then()
1237
1240
  // gen-guard skips the swap too; this guard covers the assignment itself).
1238
- if (gen !== undefined && (gen !== this._pipelineGen || this._closed)) { vad.destroy?.(); throw new Error('superseded'); }
1241
+ if (gen !== undefined && (gen !== this._pipelineGen || this._closed)) { try { vad.destroy?.(); } catch {} throw new Error('superseded'); }
1239
1242
  this._vad = vad;
1240
1243
  // Only actually start listening on Silero right away if the bootstrap VAD has already been
1241
1244
  // swapped out (or never engaged) — otherwise _swapToSileroWhenReady (called after this resolves)