@todoforai/voiceloop 0.1.18 → 0.1.20
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 +1 -1
- package/src/index.d.ts +4 -0
- package/src/voice-agent.js +16 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@todoforai/voiceloop",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
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/index.d.ts
CHANGED
|
@@ -242,6 +242,10 @@ export class VoiceAgent {
|
|
|
242
242
|
setSpeed(speed: number): void;
|
|
243
243
|
/** Update the host context (e.g. a re-opened chat); applies from the next turn — no restart. */
|
|
244
244
|
setSysmsg(sysmsg?: string): void;
|
|
245
|
+
/** Append a synthetic tool_use/tool_result pair to history — live host context as an observation
|
|
246
|
+
* the agent "made", keeping the system prompt (and its cache prefix) untouched. `name` should be a
|
|
247
|
+
* tool the agent really has. Result text is bounded like real tool results. */
|
|
248
|
+
pushToolRecord(name: string, args?: Record<string, unknown>, result?: unknown): void;
|
|
245
249
|
/** Mute/unmute the mic (disables the stream's audio tracks → silence to VAD+STT); keeps the pipeline live. */
|
|
246
250
|
setMuted(muted: boolean): void;
|
|
247
251
|
/** Mute/unmute the AI's spoken output (TTS): the reply still streams as text but is never voiced. */
|
package/src/voice-agent.js
CHANGED
|
@@ -604,6 +604,19 @@ export class VoiceAgent {
|
|
|
604
604
|
// turn on. Keeps the running session/history alive — no restart needed.
|
|
605
605
|
setSysmsg(sysmsg) { this.sysmsg = composeSysmsg(sysmsg, this._persona, this.sttLang); this._dropPrefetch(); } // a running speculation was built with the OLD sysmsg
|
|
606
606
|
|
|
607
|
+
// Feed the agent something it "looked up" WITHOUT rewriting the system prompt: a tool_use +
|
|
608
|
+
// tool_result pair appended to history, in the same shape as its own past calls. For live host
|
|
609
|
+
// context (a watched chat that keeps producing output) this beats setSysmsg(): the prompt prefix
|
|
610
|
+
// stays byte-identical (provider prompt cache holds), and the model reads it as a fresh
|
|
611
|
+
// observation rather than a silently mutated system message. `name` should be a tool the agent
|
|
612
|
+
// really has, so a later "check again" is a natural call, not an imitation of a phantom.
|
|
613
|
+
pushToolRecord(name, args = {}, result = '') {
|
|
614
|
+
const id = `host_${Date.now().toString(36)}_${(this._hostRecSeq = (this._hostRecSeq ?? 0) + 1)}`;
|
|
615
|
+
this.history.push({ role: 'assistant', content: [{ type: 'tool_use', id, name, input: args }] });
|
|
616
|
+
this.history.push({ role: 'user', content: [toolResultBlock({ id, result })] });
|
|
617
|
+
this._dropPrefetch(); // the speculation's history base is stale (histLen check would refuse it anyway)
|
|
618
|
+
}
|
|
619
|
+
|
|
607
620
|
// Mute/unmute the mic by disabling the stream's audio tracks: the browser then feeds silence to
|
|
608
621
|
// VAD and STT, so nothing the user says reaches the agent — without dropping the mic permission
|
|
609
622
|
// or tearing down the pipeline. Stored so a mute toggled while paused applies on the next start().
|
|
@@ -1963,7 +1976,9 @@ const CDN_PIPER_WASM = `${CDN}@diffusionstudio/piper-wasm@1.0.0/build/piper_phon
|
|
|
1963
1976
|
const ORT_SPECIFIER = 'onnxruntime-web';
|
|
1964
1977
|
// Dynamic import by URL, hidden from bundlers: Hermes (React Native) rejects `import(expr)` at
|
|
1965
1978
|
// bytecode compile time, so the syntax can't appear in this file even on paths RN never takes.
|
|
1966
|
-
|
|
1979
|
+
// Hermes's runtime parser rejects it too, so the Function is built LAZILY — a top-level
|
|
1980
|
+
// `new Function(...)` would throw at module load and take the whole import down with it.
|
|
1981
|
+
const importUrl = (u) => new Function('u', 'return import(u)')(u);
|
|
1967
1982
|
|
|
1968
1983
|
// OPFS blob cache — same 'piper' directory and url-basename filenames as the lib's own cache, so
|
|
1969
1984
|
// models already downloaded through the lib are reused (and vice versa).
|