@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 CHANGED
@@ -213,6 +213,7 @@ declare enum MicdropClientCommands {
213
213
  }
214
214
  declare enum MicdropServerCommands {
215
215
  Message = "Message",
216
+ PartialAssistantMessage = "PartialAssistantMessage",
216
217
  CancelLastUserMessage = "CancelLastUserMessage",
217
218
  SkipAnswer = "SkipAnswer",
218
219
  EndCall = "EndCall",
@@ -724,6 +725,10 @@ interface MicdropEvents {
724
725
  Error: [MicdropClientError];
725
726
  StateChange: [MicdropState, MicdropState];
726
727
  ToolCall: [MicdropToolCall];
728
+ /** A message was added to the conversation, by the user or the assistant */
729
+ Message: [MicdropConversationItem];
730
+ /** What the assistant is answering, before it is finished */
731
+ PartialAssistantMessage: [string];
727
732
  }
728
733
  interface MicdropReconnectOptions {
729
734
  maxAttempts?: number;
@@ -763,12 +768,19 @@ interface MicdropState {
763
768
  micDevices: MicdropDevice[];
764
769
  speakerDevices: MicdropDevice[];
765
770
  conversation: MicdropConversation;
771
+ /**
772
+ * Answer being written, sent by servers configured with `partialMessages`.
773
+ * Empty the rest of the time, and replaced by a conversation message once
774
+ * the answer is finished.
775
+ */
776
+ partialAssistantMessage: string;
766
777
  error: MicdropClientError | undefined;
767
778
  }
768
779
  declare class MicdropClient extends EventEmitter<MicdropEvents> implements MicdropState {
769
780
  options: MicdropOptions;
770
781
  micRecorder?: MicRecorder;
771
782
  conversation: MicdropConversation;
783
+ partialAssistantMessage: string;
772
784
  error: MicdropClientError | undefined;
773
785
  speakerDevices: MicdropDevice[];
774
786
  micDevices: MicdropDevice[];
@@ -838,6 +850,7 @@ declare class MicdropClient extends EventEmitter<MicdropEvents> implements Micdr
838
850
  private onSpeakerStartPlaying;
839
851
  private onSpeakerStopPlaying;
840
852
  private addMessage;
853
+ private setPartialAssistantMessage;
841
854
  private setError;
842
855
  private notifyStateChange;
843
856
  private log;
package/dist/index.d.ts CHANGED
@@ -213,6 +213,7 @@ declare enum MicdropClientCommands {
213
213
  }
214
214
  declare enum MicdropServerCommands {
215
215
  Message = "Message",
216
+ PartialAssistantMessage = "PartialAssistantMessage",
216
217
  CancelLastUserMessage = "CancelLastUserMessage",
217
218
  SkipAnswer = "SkipAnswer",
218
219
  EndCall = "EndCall",
@@ -724,6 +725,10 @@ interface MicdropEvents {
724
725
  Error: [MicdropClientError];
725
726
  StateChange: [MicdropState, MicdropState];
726
727
  ToolCall: [MicdropToolCall];
728
+ /** A message was added to the conversation, by the user or the assistant */
729
+ Message: [MicdropConversationItem];
730
+ /** What the assistant is answering, before it is finished */
731
+ PartialAssistantMessage: [string];
727
732
  }
728
733
  interface MicdropReconnectOptions {
729
734
  maxAttempts?: number;
@@ -763,12 +768,19 @@ interface MicdropState {
763
768
  micDevices: MicdropDevice[];
764
769
  speakerDevices: MicdropDevice[];
765
770
  conversation: MicdropConversation;
771
+ /**
772
+ * Answer being written, sent by servers configured with `partialMessages`.
773
+ * Empty the rest of the time, and replaced by a conversation message once
774
+ * the answer is finished.
775
+ */
776
+ partialAssistantMessage: string;
766
777
  error: MicdropClientError | undefined;
767
778
  }
768
779
  declare class MicdropClient extends EventEmitter<MicdropEvents> implements MicdropState {
769
780
  options: MicdropOptions;
770
781
  micRecorder?: MicRecorder;
771
782
  conversation: MicdropConversation;
783
+ partialAssistantMessage: string;
772
784
  error: MicdropClientError | undefined;
773
785
  speakerDevices: MicdropDevice[];
774
786
  micDevices: MicdropDevice[];
@@ -838,6 +850,7 @@ declare class MicdropClient extends EventEmitter<MicdropEvents> implements Micdr
838
850
  private onSpeakerStartPlaying;
839
851
  private onSpeakerStopPlaying;
840
852
  private addMessage;
853
+ private setPartialAssistantMessage;
841
854
  private setError;
842
855
  private notifyStateChange;
843
856
  private log;
package/dist/index.js CHANGED
@@ -1409,6 +1409,7 @@ var MicdropClientCommands = /* @__PURE__ */ ((MicdropClientCommands2) => {
1409
1409
  })(MicdropClientCommands || {});
1410
1410
  var MicdropServerCommands = /* @__PURE__ */ ((MicdropServerCommands2) => {
1411
1411
  MicdropServerCommands2["Message"] = "Message";
1412
+ MicdropServerCommands2["PartialAssistantMessage"] = "PartialAssistantMessage";
1412
1413
  MicdropServerCommands2["CancelLastUserMessage"] = "CancelLastUserMessage";
1413
1414
  MicdropServerCommands2["SkipAnswer"] = "SkipAnswer";
1414
1415
  MicdropServerCommands2["EndCall"] = "EndCall";
@@ -1471,6 +1472,7 @@ var MicdropClient = class extends import_eventemitter37.EventEmitter {
1471
1472
  super();
1472
1473
  this.options = options;
1473
1474
  this.conversation = [];
1475
+ this.partialAssistantMessage = "";
1474
1476
  this.speakerDevices = [];
1475
1477
  this.micDevices = [];
1476
1478
  this.startTime = 0;
@@ -1485,6 +1487,7 @@ var MicdropClient = class extends import_eventemitter37.EventEmitter {
1485
1487
  this.options = { ...this.options, ...options };
1486
1488
  this.startTime = Date.now();
1487
1489
  this.conversation = [];
1490
+ this.partialAssistantMessage = "";
1488
1491
  this._isProcessing = true;
1489
1492
  this._isMuted = false;
1490
1493
  this._isPaused = false;
@@ -1500,6 +1503,7 @@ var MicdropClient = class extends import_eventemitter37.EventEmitter {
1500
1503
  await this.startWS();
1501
1504
  };
1502
1505
  this.stop = async () => {
1506
+ this.partialAssistantMessage = "";
1503
1507
  this._isProcessing = false;
1504
1508
  this._isMuted = false;
1505
1509
  this._isPaused = false;
@@ -1577,6 +1581,7 @@ var MicdropClient = class extends import_eventemitter37.EventEmitter {
1577
1581
  this.micRecorder.on("StartSpeaking", () => {
1578
1582
  this.log("User start speaking");
1579
1583
  this.ws?.send("StartSpeaking" /* StartSpeaking */);
1584
+ this.partialAssistantMessage = "";
1580
1585
  this._isProcessing = false;
1581
1586
  this.notifyStateChange();
1582
1587
  Speaker.stopAudio();
@@ -1691,9 +1696,12 @@ var MicdropClient = class extends import_eventemitter37.EventEmitter {
1691
1696
  } catch (error) {
1692
1697
  console.error("[MicdropClient] Error parsing message:", data, error);
1693
1698
  }
1699
+ } else if (data.startsWith("PartialAssistantMessage" /* PartialAssistantMessage */)) {
1700
+ this.setPartialAssistantMessage(data);
1694
1701
  } else if (data === "EndCall" /* EndCall */) {
1695
1702
  this.emit("EndCall");
1696
1703
  } else if (data === "SkipAnswer" /* SkipAnswer */) {
1704
+ this.partialAssistantMessage = "";
1697
1705
  this._isProcessing = false;
1698
1706
  this.notifyStateChange();
1699
1707
  } else if (data === "CancelLastUserMessage" /* CancelLastUserMessage */) {
@@ -1821,6 +1829,7 @@ var MicdropClient = class extends import_eventemitter37.EventEmitter {
1821
1829
  isMicStarted: this.isMicStarted,
1822
1830
  isMicMuted: this.isMicMuted,
1823
1831
  conversation: this.conversation,
1832
+ partialAssistantMessage: this.partialAssistantMessage,
1824
1833
  error: this.error,
1825
1834
  micDeviceId: this.micDeviceId,
1826
1835
  speakerDeviceId: this.speakerDeviceId,
@@ -1908,8 +1917,23 @@ var MicdropClient = class extends import_eventemitter37.EventEmitter {
1908
1917
  }, config.delayMs);
1909
1918
  }
1910
1919
  addMessage(message) {
1920
+ if (message.role === "assistant") this.partialAssistantMessage = "";
1911
1921
  this.conversation = [...this.conversation, message];
1912
1922
  this.notifyStateChange();
1923
+ this.emit("Message", message);
1924
+ }
1925
+ setPartialAssistantMessage(data) {
1926
+ const command = "PartialAssistantMessage" /* PartialAssistantMessage */;
1927
+ let content;
1928
+ try {
1929
+ content = JSON.parse(data.substring(command.length + 1));
1930
+ } catch (error) {
1931
+ console.error("[MicdropClient] Error parsing partial answer:", data);
1932
+ return;
1933
+ }
1934
+ this.partialAssistantMessage = content;
1935
+ this.emit("PartialAssistantMessage", content);
1936
+ this.notifyStateChange();
1913
1937
  }
1914
1938
  setError(error) {
1915
1939
  console.error("[MicdropClient] Error:", error);