@todoforai/voiceloop 0.1.7 → 0.1.8

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.7",
3
+ "version": "0.1.8",
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",
package/src/stt.js CHANGED
@@ -24,6 +24,11 @@
24
24
  // pipeline for it — start() just opens the provider. Implies nativeEOT (the
25
25
  // provider closes its own turns via unsolicited onFinal). It exposes open()/
26
26
  // close() + setEnabled() (mute), and drives barge-in the normal way via onPartial.
27
+ // prefetchMs: <ms> how long the agent waits for this provider's interim to go STABLE before
28
+ // speculating on the LLM (default TUNING.PREFETCH_MS, 200). It only pays if
29
+ // the provider leaves that much room between its last interim and the turn
30
+ // close; set 0 when it doesn't (Flux ends turns semantically, ~21ms behind).
31
+ // Lower = fewer missed speculations, more started-then-aborted requests.
27
32
  //
28
33
  // Adding a provider = write a factory + register it in STT_PROVIDERS below. The VoiceAgent owns
29
34
  // the mic + VAD and just forwards feed/commit/close, so providers never touch audio capture.
@@ -321,10 +321,13 @@ export class VoiceAgent {
321
321
  // decides end-of-turn semantically does not (deepgram flux: 21ms median, measured) and must
322
322
  // speculate on the interim tick instead. Providers set `prefetchMs` when 200ms won't land.
323
323
  clearTimeout(this._prefetchTimer); this._prefetchTimer = null;
324
- if (this._prefetch && interim && this._prefetch.text !== interim) this._dropPrefetch(); // transcript moved on → the running speculation is stale, stop paying for it
324
+ if (this._prefetch && this._prefetch.text !== interim) this._dropPrefetch(); // transcript moved on (a RETRACTION to '' included) → the running speculation is stale, stop paying for it
325
325
  if (interim && this.state === 'listening' && !this._held && !this._echoRef) {
326
326
  const delay = this.stt.prefetchMs ?? TUNING.PREFETCH_MS ?? 200;
327
- this._prefetchTimer = setTimeout(() => this._startPrefetch(interim), delay);
327
+ // 0 means "this tick": a timer would hand the turn's own onFinal a chance to land first
328
+ // (it clears the timer), which is exactly the miss this flag exists to avoid.
329
+ if (delay > 0) this._prefetchTimer = setTimeout(() => this._startPrefetch(interim), delay);
330
+ else this._startPrefetch(interim);
328
331
  }
329
332
  },
330
333
  onFinal: (text, ms) => {
@@ -845,14 +848,16 @@ export class VoiceAgent {
845
848
  // histLen is checked BEFORE _runTurn pushes this turn's own user message (see call site).
846
849
  if (!p || p.text !== text || p.ctl.signal.aborted || p.histLen !== this.history.length) {
847
850
  // Which guard rejected: adoption is worth ~600ms (the whole LLM TTFT lands on the critical
848
- // path without it), so a silent miss is invisible latency. `text` mismatch is the expected
849
- // one (the user kept talking); the others mean the speculation was raced or aborted.
851
+ // path without it), so a silent miss is invisible latency. `none` = no speculation was even
852
+ // running (it never started, or the turn beat it); `text` = the user kept talking, the
853
+ // expected one; `aborted`/`histLen` = it was raced. Lengths, not transcripts: diag is a
854
+ // telemetry channel and tends to get logged and kept, so it carries no speech content.
850
855
  this.onEvent?.({ type: 'diag', diag: 'prefetch-miss',
851
856
  why: !p ? 'none' : p.text !== text ? 'text' : p.ctl.signal.aborted ? 'aborted' : 'histLen',
852
- text, pre: p?.text });
857
+ len: text.length, preLen: p?.text.length });
853
858
  this._dropPrefetch(); return null;
854
859
  }
855
- this.onEvent?.({ type: 'diag', diag: 'prefetch-hit', text });
860
+ this.onEvent?.({ type: 'diag', diag: 'prefetch-hit', len: text.length });
856
861
  this._prefetch = null; // timer already cleared: successful adoption is only reached from a spoken onFinal
857
862
  p.commit(); // turn committed → open the tool gate; held-back tool calls execute now
858
863
  return { ctl: p.ctl, gen: (async function* () { const f = await p.first; if (!f.done) { yield f.value; yield* p.gen; } })() };