@todoforai/voiceloop 0.1.22 → 0.1.24

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.
@@ -0,0 +1,6 @@
1
+ {
2
+ "account": {
3
+ "id": "16b8c73d88d470f6d39fee082391723e",
4
+ "name": "Havlikmarcell@gmail.com's Account"
5
+ }
6
+ }
@@ -7,6 +7,7 @@ out only what each hop needs.
7
7
  | route | returns | why |
8
8
  |---|---|---|
9
9
  | `POST /stt/token` | `{ token, expires_in }` | short-TTL Deepgram key; the browser opens the WS itself |
10
+ | `POST /stt/soniox-token` | `{ token, expires_in }` | short-TTL Soniox key (same shape) |
10
11
  | `POST /tts` | `audio/mpeg` | ElevenLabs proxy — the `xi-api-key` stays server-side |
11
12
  | `POST /llm` | OpenAI-format SSE | Anthropic proxy — Claude has no short-TTL key to mint, so the key stays here |
12
13
 
@@ -17,6 +18,7 @@ out only what each hop needs.
17
18
  ```sh
18
19
  wrangler deploy
19
20
  wrangler secret put DEEPGRAM_API_KEY
21
+ wrangler secret put SONIOX_API_KEY
20
22
  wrangler secret put ELEVENLABS_API_KEY
21
23
  wrangler secret put ANTHROPIC_API_KEY
22
24
  ```
@@ -4,10 +4,11 @@
4
4
  // never reach the page, so this Worker holds them and hands out only what each hop needs:
5
5
  //
6
6
  // POST /stt/token → { token, expires_in } short-TTL Deepgram key (browser opens the WS itself)
7
+ // POST /stt/soniox-token → same shape short-TTL Soniox key
7
8
  // POST /tts → audio/mpeg bytes ElevenLabs proxy (the xi-api-key stays here)
8
9
  // POST /llm → OpenAI-format SSE Anthropic proxy (there is no short-TTL key to mint)
9
10
  //
10
- // Secrets (wrangler secret put): DEEPGRAM_API_KEY, ELEVENLABS_API_KEY, ANTHROPIC_API_KEY.
11
+ // Secrets (wrangler secret put): DEEPGRAM_API_KEY, SONIOX_API_KEY, ELEVENLABS_API_KEY, ANTHROPIC_API_KEY.
11
12
  // ALLOWED_ORIGINS (var) is a comma-separated allowlist — these routes spend real money, so an
12
13
  // open CORS policy is an open wallet.
13
14
  //
@@ -99,7 +100,7 @@ export default {
99
100
  // Everything below mints a credential or bills a provider. /stt/token mints at most one
100
101
  // credential per 5 min so it takes the tight limiter; /tts fires once per spoken SENTENCE and
101
102
  // /llm once per turn plus prefetch, so the conversation hot path gets its own, roomier window.
102
- const limiter = url.pathname === '/stt/token' ? env.PAID_RATE_LIMITER : env.CONVO_RATE_LIMITER;
103
+ const limiter = url.pathname.startsWith('/stt/') ? env.PAID_RATE_LIMITER : env.CONVO_RATE_LIMITER;
103
104
  if (await rateLimited(req, env, limiter)) return json({ error: 'rate limited — try again in a minute' }, 429, origin);
104
105
 
105
106
  if (url.pathname === '/stt/token') {
@@ -115,6 +116,18 @@ export default {
115
116
  return json({ token: body.access_token, expires_in: body.expires_in ?? 300 }, 200, origin);
116
117
  }
117
118
 
119
+ if (url.pathname === '/stt/soniox-token') {
120
+ if (!env.SONIOX_API_KEY) return json({ error: 'SONIOX_API_KEY not configured' }, 500, origin);
121
+ const r = await fetch('https://api.soniox.com/v1/auth/temporary-api-key', {
122
+ method: 'POST',
123
+ headers: { authorization: `Bearer ${env.SONIOX_API_KEY}`, 'content-type': 'application/json' },
124
+ body: JSON.stringify({ usage_type: 'transcribe_websocket', expires_in_seconds: 300 }),
125
+ });
126
+ const body = await r.json().catch(() => ({}));
127
+ if (!r.ok || !body.api_key) return json({ error: body.message || body.error || 'mint failed' }, 502, origin);
128
+ return json({ token: body.api_key, expires_in: 300 }, 200, origin);
129
+ }
130
+
118
131
  if (url.pathname === '/tts') {
119
132
  if (!env.ELEVENLABS_API_KEY) return json({ error: 'ELEVENLABS_API_KEY not configured' }, 500, origin);
120
133
  const { text, voice_id, model_id, output_format } = await req.json().catch(() => ({}));
@@ -1,5 +1,5 @@
1
1
  name = "voiceloop-token"
2
- main = "src/index.js"
2
+ main = "index.js"
3
3
  compatibility_date = "2026-01-01"
4
4
 
5
5
  [vars]
package/index.html CHANGED
@@ -318,13 +318,24 @@
318
318
  </main>
319
319
 
320
320
  <script type="module">
321
- import { VoiceAgent, PiperTTS, ElevenLabsTTS, makeOpenAILLM, unlockAudio, prewarmVoice, STT_PROVIDERS, sttSelfCaptures, LANG_NAMES } from './src/index.js';
321
+ import { VoiceAgent, PiperTTS, ElevenLabsTTS, makeOpenAILLM, unlockAudio, prewarmVoice, warmDeepgramToken, warmSonioxToken, STT_PROVIDERS, sttSelfCaptures, LANG_NAMES } from './src/index.js';
322
322
 
323
323
  // Load VAD/WASM + build the Silero session while the page sits idle — but ONLY for a provider that
324
324
  // will actually use it. A selfCapture provider (webspeech) builds no pipeline, so prewarming there
325
325
  // downloads an ONNX model to feed a detector that never runs.
326
326
  const prewarmIfPipelined = () => { if (!sttSelfCaptures($('sttProvider').value)) prewarmVoice(); };
327
327
 
328
+ // Pay the per-hop cold costs while idle, not on ▶: the STT token mint (0.6–2.7s when it races the
329
+ // mic/VAD start) and the LLM route's DNS+TLS. Both keyed on the current field values so a change
330
+ // re-warms the NEW target; all best-effort — open() re-mints and the first turn reconnects on miss.
331
+ const STT_TOKEN_WARMERS = { deepgram: warmDeepgramToken, soniox: warmSonioxToken };
332
+ const prewarmRoutes = () => {
333
+ const warm = STT_TOKEN_WARMERS[$('sttProvider').value], tokenUrl = $('sttTokenUrl').value.trim();
334
+ if (warm && tokenUrl) warm(tokenUrl, $('apiKey').value.trim()).catch(() => {});
335
+ const llmUrl = $('mode').value === 'llm' ? $('llmUrl').value.trim() : $('mode').value === 'hosted' ? HOSTED_LLM_URL : '';
336
+ if (llmUrl) fetch(llmUrl, { method: 'HEAD', signal: AbortSignal.timeout(3000) }).catch(() => {});
337
+ };
338
+
328
339
  const $ = id => document.getElementById(id);
329
340
  const fill = (id, entries) => $(id).append(...entries.map(([value, textContent]) =>
330
341
  Object.assign(document.createElement('option'), { value, textContent })));
@@ -461,7 +472,7 @@ function onSettingChanged() {
461
472
  for (const id of ['llmUrl', 'model']) $(id).disabled = !custom;
462
473
  $('sttTokenUrl').disabled = self;
463
474
  $('apiKey').disabled = !custom && self; // used as LLM Bearer OR token-route X-API-Key — dead only when neither hop exists
464
- showPipeline(); prewarmIfPipelined();
475
+ showPipeline(); prewarmIfPipelined(); prewarmRoutes();
465
476
  }
466
477
 
467
478
  // ── the orb's level ─────────────────────────────────────────────────────────
@@ -743,6 +754,7 @@ const applyTts = () => {
743
754
  wireModelProgress();
744
755
  dropAgent('tts');
745
756
  loadVoices();
757
+ if (tts instanceof ElevenLabsTTS) tts.warm().catch(() => {}); // DNS+TLS now, not 2.5s after ▶ (Piper's 60MB stays behind the click)
746
758
  log('tts →', $('ttsProvider').value);
747
759
  };
748
760
  let ttsUrlTimer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@todoforai/voiceloop",
3
- "version": "0.1.22",
3
+ "version": "0.1.24",
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",
@@ -407,11 +407,16 @@ export class VoiceAgent {
407
407
  try {
408
408
  stream = await navigator.mediaDevices.getUserMedia({ audio });
409
409
  } catch (e) {
410
- // The saved mic id no longer exists on this machine (unplugged / different device / stale
411
- // cross-profile localStorage) — `exact` throws OverconstrainedError instead of falling back.
412
- // Retry once on the system default so a stale preference doesn't brick the whole session.
413
- if (deviceId && e.name === 'OverconstrainedError') stream = await navigator.mediaDevices.getUserMedia({ audio: { ...audio, deviceId: undefined } });
414
- else throw e;
410
+ // OverconstrainedError ("Invalid constraint" on WebKit) has two causes:
411
+ // - the saved mic id no longer exists here (unplugged / different device / stale
412
+ // cross-profile localStorage) — `exact` rejects instead of falling back;
413
+ // - WebKitGTK (Tauri on Linux) treats the bare DSP constraints as REQUIRED, so
414
+ // channelCount/autoGainControl can be unsatisfiable even with no deviceId.
415
+ // Degrade in that order — a default mic with default DSP beats no session at all.
416
+ if (e.name !== 'OverconstrainedError') throw e;
417
+ stream = await navigator.mediaDevices.getUserMedia({ audio: { ...audio, deviceId: undefined } })
418
+ .catch(() => navigator.mediaDevices.getUserMedia({ audio: true }))
419
+ .catch(() => { throw e; });
415
420
  }
416
421
  } catch (e) {
417
422
  // Mic open failed (permission denied / no device / constraints). We already optimistically
@@ -974,6 +979,11 @@ export class VoiceAgent {
974
979
  // so it could only ever become a stuck spinner — drop it. The outcome chunk still lands.
975
980
  if (finalized || !item.id || known) continue;
976
981
  accept(item).announced = true;
982
+ // While the cursor is live the answer is only published on playback ticks, so the host's
983
+ // copy may lag the tokens generated just before this call. Publish the exact answer at
984
+ // the boundary FIRST: a host that splits the reply around its calls (text → chip → text
985
+ // after the result) then cuts at the model's real position, not a frame-old one.
986
+ if (self._cursorLive) self.onEvent({ type: 'assistant', text: self._replyText, full: answer, final: false, turn });
977
987
  self.onEvent({ type: 'tool', name: item.tool, id: item.id, args: item.args, running: true });
978
988
  continue;
979
989
  }