@micdrop/client 3.6.0 → 3.7.0
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/README.md +1 -1
- package/dist/index.d.mts +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.js +59 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -335,6 +335,47 @@ var storage = {
|
|
|
335
335
|
}
|
|
336
336
|
};
|
|
337
337
|
|
|
338
|
+
// ../server/src/types.ts
|
|
339
|
+
var MicdropClientCommands = /* @__PURE__ */ ((MicdropClientCommands2) => {
|
|
340
|
+
MicdropClientCommands2["StartSpeaking"] = "StartSpeaking";
|
|
341
|
+
MicdropClientCommands2["StopSpeaking"] = "StopSpeaking";
|
|
342
|
+
MicdropClientCommands2["Mute"] = "Mute";
|
|
343
|
+
return MicdropClientCommands2;
|
|
344
|
+
})(MicdropClientCommands || {});
|
|
345
|
+
var MicdropServerCommands = /* @__PURE__ */ ((MicdropServerCommands2) => {
|
|
346
|
+
MicdropServerCommands2["Message"] = "Message";
|
|
347
|
+
MicdropServerCommands2["PartialAssistantMessage"] = "PartialAssistantMessage";
|
|
348
|
+
MicdropServerCommands2["CancelLastUserMessage"] = "CancelLastUserMessage";
|
|
349
|
+
MicdropServerCommands2["SkipAnswer"] = "SkipAnswer";
|
|
350
|
+
MicdropServerCommands2["EndCall"] = "EndCall";
|
|
351
|
+
MicdropServerCommands2["ToolCall"] = "ToolCall";
|
|
352
|
+
MicdropServerCommands2["Classification"] = "Classification";
|
|
353
|
+
MicdropServerCommands2["SampleRate"] = "SampleRate";
|
|
354
|
+
return MicdropServerCommands2;
|
|
355
|
+
})(MicdropServerCommands || {});
|
|
356
|
+
var DEFAULT_SAMPLE_RATE = 16e3;
|
|
357
|
+
function currentTurn(conversation) {
|
|
358
|
+
let start = conversation.length;
|
|
359
|
+
while (start > 0) {
|
|
360
|
+
const item = conversation[start - 1];
|
|
361
|
+
if (item.role !== "user" || item.metadata?.classification) break;
|
|
362
|
+
start--;
|
|
363
|
+
}
|
|
364
|
+
const messages = conversation.slice(start);
|
|
365
|
+
return {
|
|
366
|
+
transcript: messages.map((message) => message.content).join(" "),
|
|
367
|
+
messages,
|
|
368
|
+
before: conversation.slice(0, start)
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
function getTurnClassification(conversation) {
|
|
372
|
+
for (let index = conversation.length - 1; index >= 0; index--) {
|
|
373
|
+
const item = conversation[index];
|
|
374
|
+
if (item.role === "user") return item.metadata?.classification;
|
|
375
|
+
}
|
|
376
|
+
return void 0;
|
|
377
|
+
}
|
|
378
|
+
|
|
338
379
|
// src/audio/Speaker.ts
|
|
339
380
|
var SpeakerController = class extends EventEmitter2 {
|
|
340
381
|
constructor() {
|
|
@@ -399,7 +440,7 @@ var SpeakerController = class extends EventEmitter2 {
|
|
|
399
440
|
* @param pcm - Mono samples as 16 bits integers, or the bytes holding them
|
|
400
441
|
* @param sampleRate - Sample rate of `pcm`, in Hz
|
|
401
442
|
*/
|
|
402
|
-
playAudio(pcm, sampleRate =
|
|
443
|
+
playAudio(pcm, sampleRate = DEFAULT_SAMPLE_RATE) {
|
|
403
444
|
try {
|
|
404
445
|
const samples = pcm instanceof Int16Array ? pcm : new Int16Array(pcm);
|
|
405
446
|
this.getDriver().play(samples, sampleRate);
|
|
@@ -1586,45 +1627,6 @@ var Speaker = globalScope.micdropSpeaker;
|
|
|
1586
1627
|
// src/client/MicdropClient.ts
|
|
1587
1628
|
import { EventEmitter as EventEmitter7 } from "eventemitter3";
|
|
1588
1629
|
|
|
1589
|
-
// ../server/src/types.ts
|
|
1590
|
-
var MicdropClientCommands = /* @__PURE__ */ ((MicdropClientCommands2) => {
|
|
1591
|
-
MicdropClientCommands2["StartSpeaking"] = "StartSpeaking";
|
|
1592
|
-
MicdropClientCommands2["StopSpeaking"] = "StopSpeaking";
|
|
1593
|
-
MicdropClientCommands2["Mute"] = "Mute";
|
|
1594
|
-
return MicdropClientCommands2;
|
|
1595
|
-
})(MicdropClientCommands || {});
|
|
1596
|
-
var MicdropServerCommands = /* @__PURE__ */ ((MicdropServerCommands2) => {
|
|
1597
|
-
MicdropServerCommands2["Message"] = "Message";
|
|
1598
|
-
MicdropServerCommands2["PartialAssistantMessage"] = "PartialAssistantMessage";
|
|
1599
|
-
MicdropServerCommands2["CancelLastUserMessage"] = "CancelLastUserMessage";
|
|
1600
|
-
MicdropServerCommands2["SkipAnswer"] = "SkipAnswer";
|
|
1601
|
-
MicdropServerCommands2["EndCall"] = "EndCall";
|
|
1602
|
-
MicdropServerCommands2["ToolCall"] = "ToolCall";
|
|
1603
|
-
MicdropServerCommands2["Classification"] = "Classification";
|
|
1604
|
-
return MicdropServerCommands2;
|
|
1605
|
-
})(MicdropServerCommands || {});
|
|
1606
|
-
function currentTurn(conversation) {
|
|
1607
|
-
let start = conversation.length;
|
|
1608
|
-
while (start > 0) {
|
|
1609
|
-
const item = conversation[start - 1];
|
|
1610
|
-
if (item.role !== "user" || item.metadata?.classification) break;
|
|
1611
|
-
start--;
|
|
1612
|
-
}
|
|
1613
|
-
const messages = conversation.slice(start);
|
|
1614
|
-
return {
|
|
1615
|
-
transcript: messages.map((message) => message.content).join(" "),
|
|
1616
|
-
messages,
|
|
1617
|
-
before: conversation.slice(0, start)
|
|
1618
|
-
};
|
|
1619
|
-
}
|
|
1620
|
-
function getTurnClassification(conversation) {
|
|
1621
|
-
for (let index = conversation.length - 1; index >= 0; index--) {
|
|
1622
|
-
const item = conversation[index];
|
|
1623
|
-
if (item.role === "user") return item.metadata?.classification;
|
|
1624
|
-
}
|
|
1625
|
-
return void 0;
|
|
1626
|
-
}
|
|
1627
|
-
|
|
1628
1630
|
// src/client/MicdropClientError.ts
|
|
1629
1631
|
var MicdropClientErrorCode = /* @__PURE__ */ ((MicdropClientErrorCode2) => {
|
|
1630
1632
|
MicdropClientErrorCode2["MissingUrl"] = "MissingUrl";
|
|
@@ -1731,6 +1733,8 @@ var MicdropClient = class extends EventEmitter7 {
|
|
|
1731
1733
|
this.startTime = 0;
|
|
1732
1734
|
this.lastNotifiedState = this.state;
|
|
1733
1735
|
this._isProcessing = false;
|
|
1736
|
+
// Rate of the assistant voice, announced by the server whenever it changes
|
|
1737
|
+
this.assistantSampleRate = DEFAULT_SAMPLE_RATE;
|
|
1734
1738
|
this._isMuted = false;
|
|
1735
1739
|
this._isPaused = false;
|
|
1736
1740
|
// The call as start() and the connection leave it. The public status also
|
|
@@ -1983,7 +1987,7 @@ var MicdropClient = class extends EventEmitter7 {
|
|
|
1983
1987
|
if (data instanceof ArrayBuffer) {
|
|
1984
1988
|
this.log("Received audio", data.byteLength);
|
|
1985
1989
|
if (this.isPaused || this.isUserSpeaking) return;
|
|
1986
|
-
Speaker.playAudio(new Int16Array(data));
|
|
1990
|
+
Speaker.playAudio(new Int16Array(data), this.assistantSampleRate);
|
|
1987
1991
|
this._isProcessing = false;
|
|
1988
1992
|
this.notifyStateChange();
|
|
1989
1993
|
return;
|
|
@@ -1993,6 +1997,17 @@ var MicdropClient = class extends EventEmitter7 {
|
|
|
1993
1997
|
return;
|
|
1994
1998
|
}
|
|
1995
1999
|
this.log("Received message:", data);
|
|
2000
|
+
if (data.startsWith("SampleRate" /* SampleRate */)) {
|
|
2001
|
+
const sampleRate = Number(
|
|
2002
|
+
data.substring("SampleRate" /* SampleRate */.length + 1)
|
|
2003
|
+
);
|
|
2004
|
+
if (Number.isFinite(sampleRate) && sampleRate > 0) {
|
|
2005
|
+
this.assistantSampleRate = sampleRate;
|
|
2006
|
+
} else {
|
|
2007
|
+
console.error("[MicdropClient] Invalid sample rate:", data);
|
|
2008
|
+
}
|
|
2009
|
+
return;
|
|
2010
|
+
}
|
|
1996
2011
|
if (data.startsWith("Message" /* Message */)) {
|
|
1997
2012
|
try {
|
|
1998
2013
|
const message = JSON.parse(
|
|
@@ -2249,6 +2264,7 @@ var MicdropClient = class extends EventEmitter7 {
|
|
|
2249
2264
|
const ws = new WebSocket(this.options.url);
|
|
2250
2265
|
ws.binaryType = "arraybuffer";
|
|
2251
2266
|
this.ws = ws;
|
|
2267
|
+
this.assistantSampleRate = DEFAULT_SAMPLE_RATE;
|
|
2252
2268
|
this.notifyStateChange();
|
|
2253
2269
|
const isCurrent = () => this.ws === ws;
|
|
2254
2270
|
ws.onopen = () => isCurrent() && this.onWSOpen();
|
|
@@ -2367,6 +2383,7 @@ if (!globalScope2.micdropClient) {
|
|
|
2367
2383
|
var Micdrop = globalScope2.micdropClient;
|
|
2368
2384
|
export {
|
|
2369
2385
|
CONFIRM_MARGIN,
|
|
2386
|
+
DEFAULT_SAMPLE_RATE,
|
|
2370
2387
|
DEFAULT_TURN_MAX_WAIT,
|
|
2371
2388
|
ECHO_TAIL,
|
|
2372
2389
|
LazySession,
|