@micdrop/client 3.1.0 → 3.2.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/dist/index.d.mts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1345,6 +1345,7 @@ var MicdropClientCommands = /* @__PURE__ */ ((MicdropClientCommands2) => {
|
|
|
1345
1345
|
})(MicdropClientCommands || {});
|
|
1346
1346
|
var MicdropServerCommands = /* @__PURE__ */ ((MicdropServerCommands2) => {
|
|
1347
1347
|
MicdropServerCommands2["Message"] = "Message";
|
|
1348
|
+
MicdropServerCommands2["PartialAssistantMessage"] = "PartialAssistantMessage";
|
|
1348
1349
|
MicdropServerCommands2["CancelLastUserMessage"] = "CancelLastUserMessage";
|
|
1349
1350
|
MicdropServerCommands2["SkipAnswer"] = "SkipAnswer";
|
|
1350
1351
|
MicdropServerCommands2["EndCall"] = "EndCall";
|
|
@@ -1407,6 +1408,7 @@ var MicdropClient = class extends EventEmitter7 {
|
|
|
1407
1408
|
super();
|
|
1408
1409
|
this.options = options;
|
|
1409
1410
|
this.conversation = [];
|
|
1411
|
+
this.partialAssistantMessage = "";
|
|
1410
1412
|
this.speakerDevices = [];
|
|
1411
1413
|
this.micDevices = [];
|
|
1412
1414
|
this.startTime = 0;
|
|
@@ -1421,6 +1423,7 @@ var MicdropClient = class extends EventEmitter7 {
|
|
|
1421
1423
|
this.options = { ...this.options, ...options };
|
|
1422
1424
|
this.startTime = Date.now();
|
|
1423
1425
|
this.conversation = [];
|
|
1426
|
+
this.partialAssistantMessage = "";
|
|
1424
1427
|
this._isProcessing = true;
|
|
1425
1428
|
this._isMuted = false;
|
|
1426
1429
|
this._isPaused = false;
|
|
@@ -1436,6 +1439,7 @@ var MicdropClient = class extends EventEmitter7 {
|
|
|
1436
1439
|
await this.startWS();
|
|
1437
1440
|
};
|
|
1438
1441
|
this.stop = async () => {
|
|
1442
|
+
this.partialAssistantMessage = "";
|
|
1439
1443
|
this._isProcessing = false;
|
|
1440
1444
|
this._isMuted = false;
|
|
1441
1445
|
this._isPaused = false;
|
|
@@ -1513,6 +1517,7 @@ var MicdropClient = class extends EventEmitter7 {
|
|
|
1513
1517
|
this.micRecorder.on("StartSpeaking", () => {
|
|
1514
1518
|
this.log("User start speaking");
|
|
1515
1519
|
this.ws?.send("StartSpeaking" /* StartSpeaking */);
|
|
1520
|
+
this.partialAssistantMessage = "";
|
|
1516
1521
|
this._isProcessing = false;
|
|
1517
1522
|
this.notifyStateChange();
|
|
1518
1523
|
Speaker.stopAudio();
|
|
@@ -1627,9 +1632,12 @@ var MicdropClient = class extends EventEmitter7 {
|
|
|
1627
1632
|
} catch (error) {
|
|
1628
1633
|
console.error("[MicdropClient] Error parsing message:", data, error);
|
|
1629
1634
|
}
|
|
1635
|
+
} else if (data.startsWith("PartialAssistantMessage" /* PartialAssistantMessage */)) {
|
|
1636
|
+
this.setPartialAssistantMessage(data);
|
|
1630
1637
|
} else if (data === "EndCall" /* EndCall */) {
|
|
1631
1638
|
this.emit("EndCall");
|
|
1632
1639
|
} else if (data === "SkipAnswer" /* SkipAnswer */) {
|
|
1640
|
+
this.partialAssistantMessage = "";
|
|
1633
1641
|
this._isProcessing = false;
|
|
1634
1642
|
this.notifyStateChange();
|
|
1635
1643
|
} else if (data === "CancelLastUserMessage" /* CancelLastUserMessage */) {
|
|
@@ -1757,6 +1765,7 @@ var MicdropClient = class extends EventEmitter7 {
|
|
|
1757
1765
|
isMicStarted: this.isMicStarted,
|
|
1758
1766
|
isMicMuted: this.isMicMuted,
|
|
1759
1767
|
conversation: this.conversation,
|
|
1768
|
+
partialAssistantMessage: this.partialAssistantMessage,
|
|
1760
1769
|
error: this.error,
|
|
1761
1770
|
micDeviceId: this.micDeviceId,
|
|
1762
1771
|
speakerDeviceId: this.speakerDeviceId,
|
|
@@ -1844,8 +1853,23 @@ var MicdropClient = class extends EventEmitter7 {
|
|
|
1844
1853
|
}, config.delayMs);
|
|
1845
1854
|
}
|
|
1846
1855
|
addMessage(message) {
|
|
1856
|
+
if (message.role === "assistant") this.partialAssistantMessage = "";
|
|
1847
1857
|
this.conversation = [...this.conversation, message];
|
|
1848
1858
|
this.notifyStateChange();
|
|
1859
|
+
this.emit("Message", message);
|
|
1860
|
+
}
|
|
1861
|
+
setPartialAssistantMessage(data) {
|
|
1862
|
+
const command = "PartialAssistantMessage" /* PartialAssistantMessage */;
|
|
1863
|
+
let content;
|
|
1864
|
+
try {
|
|
1865
|
+
content = JSON.parse(data.substring(command.length + 1));
|
|
1866
|
+
} catch (error) {
|
|
1867
|
+
console.error("[MicdropClient] Error parsing partial answer:", data);
|
|
1868
|
+
return;
|
|
1869
|
+
}
|
|
1870
|
+
this.partialAssistantMessage = content;
|
|
1871
|
+
this.emit("PartialAssistantMessage", content);
|
|
1872
|
+
this.notifyStateChange();
|
|
1849
1873
|
}
|
|
1850
1874
|
setError(error) {
|
|
1851
1875
|
console.error("[MicdropClient] Error:", error);
|