@micdrop/client 2.0.4 → 2.0.6

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
@@ -1,6 +1,4 @@
1
1
  import { EventEmitter } from 'eventemitter3';
2
- import { MicdropConversation as MicdropConversation$1, VAD as VAD$1 } from '@micdrop/client';
3
- import { Readable } from 'stream';
4
2
 
5
3
  interface AudioAnalyserEvents {
6
4
  volume: [number];
@@ -214,6 +212,54 @@ declare class VolumeVAD extends VAD {
214
212
  declare const Mic: Mic$1;
215
213
  declare const Speaker: Speaker$1;
216
214
 
215
+ declare enum MicdropClientCommands {
216
+ StartSpeaking = "StartSpeaking",
217
+ StopSpeaking = "StopSpeaking",
218
+ Mute = "Mute"
219
+ }
220
+ declare enum MicdropServerCommands {
221
+ Message = "Message",
222
+ CancelLastAssistantMessage = "CancelLastAssistantMessage",
223
+ CancelLastUserMessage = "CancelLastUserMessage",
224
+ SkipAnswer = "SkipAnswer",
225
+ EndCall = "EndCall",
226
+ ToolCall = "ToolCall"
227
+ }
228
+ interface MicdropCallSummary {
229
+ conversation: MicdropConversation;
230
+ duration: number;
231
+ }
232
+ type MicdropConversationItem = MicdropConversationMessage | MicdropConversationToolCall | MicdropConversationToolResult;
233
+ type MicdropConversation = Array<MicdropConversationItem>;
234
+ type MicdropAnswerMetadata = {
235
+ [key: string]: any;
236
+ };
237
+ interface MicdropConversationMessage<Data extends MicdropAnswerMetadata = MicdropAnswerMetadata> {
238
+ role: 'system' | 'user' | 'assistant';
239
+ content: string;
240
+ metadata?: Data;
241
+ }
242
+ interface MicdropConversationToolCall {
243
+ role: 'tool_call';
244
+ toolCallId: string;
245
+ toolName: string;
246
+ parameters: string;
247
+ }
248
+ interface MicdropConversationToolResult {
249
+ role: 'tool_result';
250
+ toolCallId: string;
251
+ toolName: string;
252
+ output: string;
253
+ }
254
+ interface MicdropToolCall {
255
+ name: string;
256
+ parameters: any;
257
+ output: any;
258
+ }
259
+ type DeepPartial<T> = T extends object ? {
260
+ [P in keyof T]?: DeepPartial<T[P]>;
261
+ } : T;
262
+
217
263
  declare enum MicdropClientErrorCode {
218
264
  MissingUrl = "MissingUrl",
219
265
  Mic = "Mic",
@@ -235,6 +281,7 @@ interface MicdropEvents {
235
281
  EndCall: [];
236
282
  Error: [MicdropClientError];
237
283
  StateChange: [MicdropState];
284
+ ToolCall: [MicdropToolCall];
238
285
  }
239
286
  interface MicdropOptions {
240
287
  url?: string;
@@ -257,13 +304,13 @@ interface MicdropState {
257
304
  speakerDeviceId: string | undefined;
258
305
  micDevices: MediaDeviceInfo[];
259
306
  speakerDevices: MediaDeviceInfo[];
260
- conversation: MicdropConversation$1;
307
+ conversation: MicdropConversation;
261
308
  error: MicdropClientError | undefined;
262
309
  }
263
310
  declare class MicdropClient extends EventEmitter<MicdropEvents> implements MicdropState {
264
311
  options: MicdropOptions;
265
312
  micRecorder?: MicRecorder;
266
- conversation: MicdropConversation$1;
313
+ conversation: MicdropConversation;
267
314
  error: MicdropClientError | undefined;
268
315
  speakerDevices: MediaDeviceInfo[];
269
316
  micDevices: MediaDeviceInfo[];
@@ -273,7 +320,7 @@ declare class MicdropClient extends EventEmitter<MicdropEvents> implements Micdr
273
320
  private _isProcessing;
274
321
  private _isPaused;
275
322
  constructor(options?: MicdropOptions);
276
- get vad(): VAD$1 | undefined;
323
+ get vad(): VAD | undefined;
277
324
  get isStarted(): boolean;
278
325
  get isStarting(): boolean;
279
326
  get isPaused(): boolean;
@@ -317,104 +364,4 @@ declare class MicdropClient extends EventEmitter<MicdropEvents> implements Micdr
317
364
 
318
365
  declare const Micdrop: MicdropClient;
319
366
 
320
- declare class Logger {
321
- private readonly name;
322
- constructor(name: string);
323
- log(...message: any[]): void;
324
- }
325
-
326
- interface AgentOptions {
327
- systemPrompt: string;
328
- }
329
- interface AgentEvents {
330
- Message: [MicdropConversationMessage];
331
- CancelLastUserMessage: [];
332
- CancelLastAssistantMessage: [];
333
- SkipAnswer: [];
334
- EndCall: [];
335
- }
336
- declare abstract class Agent<Options extends AgentOptions = AgentOptions> extends EventEmitter<AgentEvents> {
337
- protected options: Options;
338
- logger?: Logger;
339
- conversation: MicdropConversation;
340
- constructor(options: Options);
341
- abstract answer(): Readable;
342
- abstract cancel(): void;
343
- addUserMessage(text: string, metadata?: MicdropAnswerMetadata): void;
344
- addAssistantMessage(text: string, metadata?: MicdropAnswerMetadata): void;
345
- protected addMessage(role: 'user' | 'assistant' | 'system', text: string, metadata?: MicdropAnswerMetadata): void;
346
- protected endCall(): void;
347
- protected cancelLastUserMessage(): void;
348
- protected cancelLastAssistantMessage(): void;
349
- protected skipAnswer(): void;
350
- protected log(...message: any[]): void;
351
- destroy(): void;
352
- }
353
-
354
- declare const MIME_TYPE_TO_EXTENSION: {
355
- readonly 'audio/wav': "wav";
356
- readonly 'audio/ogg': "ogg";
357
- readonly 'audio/mpeg': "mp3";
358
- readonly 'audio/webm': "webm";
359
- readonly 'audio/mp4': "mp4";
360
- readonly 'audio/flac': "flac";
361
- };
362
- interface STTEvents {
363
- Transcript: [string];
364
- }
365
- declare abstract class STT extends EventEmitter<STTEvents> {
366
- protected mimeType?: keyof typeof MIME_TYPE_TO_EXTENSION;
367
- logger?: Logger;
368
- transcribe(audioStream: Readable): void;
369
- protected log(...message: any[]): void;
370
- destroy(): void;
371
- protected get extension(): string;
372
- private detectMimeType;
373
- }
374
-
375
- declare abstract class TTS {
376
- logger?: Logger;
377
- abstract speak(textStream: Readable): Readable;
378
- abstract cancel(): void;
379
- protected log(...message: any[]): void;
380
- destroy(): void;
381
- }
382
-
383
- declare enum MicdropClientCommands {
384
- StartSpeaking = "StartSpeaking",
385
- StopSpeaking = "StopSpeaking",
386
- Mute = "Mute"
387
- }
388
- declare enum MicdropServerCommands {
389
- Message = "Message",
390
- CancelLastAssistantMessage = "CancelLastAssistantMessage",
391
- CancelLastUserMessage = "CancelLastUserMessage",
392
- SkipAnswer = "SkipAnswer",
393
- EndCall = "EndCall"
394
- }
395
- interface MicdropConfig {
396
- firstMessage?: string;
397
- generateFirstMessage?: boolean;
398
- agent: Agent;
399
- stt: STT;
400
- tts: TTS;
401
- onEnd?(call: MicdropCallSummary): void;
402
- }
403
- interface MicdropCallSummary {
404
- conversation: MicdropConversation;
405
- duration: number;
406
- }
407
- type MicdropConversation = MicdropConversationMessage[];
408
- type MicdropAnswerMetadata = {
409
- [key: string]: any;
410
- };
411
- interface MicdropConversationMessage<Data extends MicdropAnswerMetadata = MicdropAnswerMetadata> {
412
- role: 'system' | 'user' | 'assistant';
413
- content: string;
414
- metadata?: Data;
415
- }
416
- type DeepPartial<T> = T extends object ? {
417
- [P in keyof T]?: DeepPartial<T[P]>;
418
- } : T;
419
-
420
- export { type DeepPartial, LocalStorageKeys, Mic, MicRecorder, type MicRecorderEvents, type MicRecorderState, Micdrop, type MicdropAnswerMetadata, type MicdropCallSummary, MicdropClient, MicdropClientCommands, MicdropClientError, MicdropClientErrorCode, type MicdropConfig, type MicdropConversation, type MicdropConversationMessage, type MicdropEvents, type MicdropOptions, MicdropServerCommands, type MicdropState, MultipleVAD, SileroVAD, type SileroVADOptions, Speaker, VAD, type VADConfig, type VADConfigName, type VADEvents, VADStatus, VolumeVAD, type VolumeVADOptions, getClientErrorFromWSCloseEvent, getClientErrorFromWSCloseEventCode, getVAD };
367
+ export { type DeepPartial, LocalStorageKeys, Mic, MicRecorder, type MicRecorderEvents, type MicRecorderState, Micdrop, type MicdropAnswerMetadata, type MicdropCallSummary, MicdropClient, MicdropClientCommands, MicdropClientError, MicdropClientErrorCode, type MicdropConversation, type MicdropConversationItem, type MicdropConversationMessage, type MicdropConversationToolCall, type MicdropConversationToolResult, type MicdropEvents, type MicdropOptions, MicdropServerCommands, type MicdropState, type MicdropToolCall, MultipleVAD, SileroVAD, type SileroVADOptions, Speaker, VAD, type VADConfig, type VADConfigName, type VADEvents, VADStatus, VolumeVAD, type VolumeVADOptions, getClientErrorFromWSCloseEvent, getClientErrorFromWSCloseEventCode, getVAD };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  import { EventEmitter } from 'eventemitter3';
2
- import { MicdropConversation as MicdropConversation$1, VAD as VAD$1 } from '@micdrop/client';
3
- import { Readable } from 'stream';
4
2
 
5
3
  interface AudioAnalyserEvents {
6
4
  volume: [number];
@@ -214,6 +212,54 @@ declare class VolumeVAD extends VAD {
214
212
  declare const Mic: Mic$1;
215
213
  declare const Speaker: Speaker$1;
216
214
 
215
+ declare enum MicdropClientCommands {
216
+ StartSpeaking = "StartSpeaking",
217
+ StopSpeaking = "StopSpeaking",
218
+ Mute = "Mute"
219
+ }
220
+ declare enum MicdropServerCommands {
221
+ Message = "Message",
222
+ CancelLastAssistantMessage = "CancelLastAssistantMessage",
223
+ CancelLastUserMessage = "CancelLastUserMessage",
224
+ SkipAnswer = "SkipAnswer",
225
+ EndCall = "EndCall",
226
+ ToolCall = "ToolCall"
227
+ }
228
+ interface MicdropCallSummary {
229
+ conversation: MicdropConversation;
230
+ duration: number;
231
+ }
232
+ type MicdropConversationItem = MicdropConversationMessage | MicdropConversationToolCall | MicdropConversationToolResult;
233
+ type MicdropConversation = Array<MicdropConversationItem>;
234
+ type MicdropAnswerMetadata = {
235
+ [key: string]: any;
236
+ };
237
+ interface MicdropConversationMessage<Data extends MicdropAnswerMetadata = MicdropAnswerMetadata> {
238
+ role: 'system' | 'user' | 'assistant';
239
+ content: string;
240
+ metadata?: Data;
241
+ }
242
+ interface MicdropConversationToolCall {
243
+ role: 'tool_call';
244
+ toolCallId: string;
245
+ toolName: string;
246
+ parameters: string;
247
+ }
248
+ interface MicdropConversationToolResult {
249
+ role: 'tool_result';
250
+ toolCallId: string;
251
+ toolName: string;
252
+ output: string;
253
+ }
254
+ interface MicdropToolCall {
255
+ name: string;
256
+ parameters: any;
257
+ output: any;
258
+ }
259
+ type DeepPartial<T> = T extends object ? {
260
+ [P in keyof T]?: DeepPartial<T[P]>;
261
+ } : T;
262
+
217
263
  declare enum MicdropClientErrorCode {
218
264
  MissingUrl = "MissingUrl",
219
265
  Mic = "Mic",
@@ -235,6 +281,7 @@ interface MicdropEvents {
235
281
  EndCall: [];
236
282
  Error: [MicdropClientError];
237
283
  StateChange: [MicdropState];
284
+ ToolCall: [MicdropToolCall];
238
285
  }
239
286
  interface MicdropOptions {
240
287
  url?: string;
@@ -257,13 +304,13 @@ interface MicdropState {
257
304
  speakerDeviceId: string | undefined;
258
305
  micDevices: MediaDeviceInfo[];
259
306
  speakerDevices: MediaDeviceInfo[];
260
- conversation: MicdropConversation$1;
307
+ conversation: MicdropConversation;
261
308
  error: MicdropClientError | undefined;
262
309
  }
263
310
  declare class MicdropClient extends EventEmitter<MicdropEvents> implements MicdropState {
264
311
  options: MicdropOptions;
265
312
  micRecorder?: MicRecorder;
266
- conversation: MicdropConversation$1;
313
+ conversation: MicdropConversation;
267
314
  error: MicdropClientError | undefined;
268
315
  speakerDevices: MediaDeviceInfo[];
269
316
  micDevices: MediaDeviceInfo[];
@@ -273,7 +320,7 @@ declare class MicdropClient extends EventEmitter<MicdropEvents> implements Micdr
273
320
  private _isProcessing;
274
321
  private _isPaused;
275
322
  constructor(options?: MicdropOptions);
276
- get vad(): VAD$1 | undefined;
323
+ get vad(): VAD | undefined;
277
324
  get isStarted(): boolean;
278
325
  get isStarting(): boolean;
279
326
  get isPaused(): boolean;
@@ -317,104 +364,4 @@ declare class MicdropClient extends EventEmitter<MicdropEvents> implements Micdr
317
364
 
318
365
  declare const Micdrop: MicdropClient;
319
366
 
320
- declare class Logger {
321
- private readonly name;
322
- constructor(name: string);
323
- log(...message: any[]): void;
324
- }
325
-
326
- interface AgentOptions {
327
- systemPrompt: string;
328
- }
329
- interface AgentEvents {
330
- Message: [MicdropConversationMessage];
331
- CancelLastUserMessage: [];
332
- CancelLastAssistantMessage: [];
333
- SkipAnswer: [];
334
- EndCall: [];
335
- }
336
- declare abstract class Agent<Options extends AgentOptions = AgentOptions> extends EventEmitter<AgentEvents> {
337
- protected options: Options;
338
- logger?: Logger;
339
- conversation: MicdropConversation;
340
- constructor(options: Options);
341
- abstract answer(): Readable;
342
- abstract cancel(): void;
343
- addUserMessage(text: string, metadata?: MicdropAnswerMetadata): void;
344
- addAssistantMessage(text: string, metadata?: MicdropAnswerMetadata): void;
345
- protected addMessage(role: 'user' | 'assistant' | 'system', text: string, metadata?: MicdropAnswerMetadata): void;
346
- protected endCall(): void;
347
- protected cancelLastUserMessage(): void;
348
- protected cancelLastAssistantMessage(): void;
349
- protected skipAnswer(): void;
350
- protected log(...message: any[]): void;
351
- destroy(): void;
352
- }
353
-
354
- declare const MIME_TYPE_TO_EXTENSION: {
355
- readonly 'audio/wav': "wav";
356
- readonly 'audio/ogg': "ogg";
357
- readonly 'audio/mpeg': "mp3";
358
- readonly 'audio/webm': "webm";
359
- readonly 'audio/mp4': "mp4";
360
- readonly 'audio/flac': "flac";
361
- };
362
- interface STTEvents {
363
- Transcript: [string];
364
- }
365
- declare abstract class STT extends EventEmitter<STTEvents> {
366
- protected mimeType?: keyof typeof MIME_TYPE_TO_EXTENSION;
367
- logger?: Logger;
368
- transcribe(audioStream: Readable): void;
369
- protected log(...message: any[]): void;
370
- destroy(): void;
371
- protected get extension(): string;
372
- private detectMimeType;
373
- }
374
-
375
- declare abstract class TTS {
376
- logger?: Logger;
377
- abstract speak(textStream: Readable): Readable;
378
- abstract cancel(): void;
379
- protected log(...message: any[]): void;
380
- destroy(): void;
381
- }
382
-
383
- declare enum MicdropClientCommands {
384
- StartSpeaking = "StartSpeaking",
385
- StopSpeaking = "StopSpeaking",
386
- Mute = "Mute"
387
- }
388
- declare enum MicdropServerCommands {
389
- Message = "Message",
390
- CancelLastAssistantMessage = "CancelLastAssistantMessage",
391
- CancelLastUserMessage = "CancelLastUserMessage",
392
- SkipAnswer = "SkipAnswer",
393
- EndCall = "EndCall"
394
- }
395
- interface MicdropConfig {
396
- firstMessage?: string;
397
- generateFirstMessage?: boolean;
398
- agent: Agent;
399
- stt: STT;
400
- tts: TTS;
401
- onEnd?(call: MicdropCallSummary): void;
402
- }
403
- interface MicdropCallSummary {
404
- conversation: MicdropConversation;
405
- duration: number;
406
- }
407
- type MicdropConversation = MicdropConversationMessage[];
408
- type MicdropAnswerMetadata = {
409
- [key: string]: any;
410
- };
411
- interface MicdropConversationMessage<Data extends MicdropAnswerMetadata = MicdropAnswerMetadata> {
412
- role: 'system' | 'user' | 'assistant';
413
- content: string;
414
- metadata?: Data;
415
- }
416
- type DeepPartial<T> = T extends object ? {
417
- [P in keyof T]?: DeepPartial<T[P]>;
418
- } : T;
419
-
420
- export { type DeepPartial, LocalStorageKeys, Mic, MicRecorder, type MicRecorderEvents, type MicRecorderState, Micdrop, type MicdropAnswerMetadata, type MicdropCallSummary, MicdropClient, MicdropClientCommands, MicdropClientError, MicdropClientErrorCode, type MicdropConfig, type MicdropConversation, type MicdropConversationMessage, type MicdropEvents, type MicdropOptions, MicdropServerCommands, type MicdropState, MultipleVAD, SileroVAD, type SileroVADOptions, Speaker, VAD, type VADConfig, type VADConfigName, type VADEvents, VADStatus, VolumeVAD, type VolumeVADOptions, getClientErrorFromWSCloseEvent, getClientErrorFromWSCloseEventCode, getVAD };
367
+ export { type DeepPartial, LocalStorageKeys, Mic, MicRecorder, type MicRecorderEvents, type MicRecorderState, Micdrop, type MicdropAnswerMetadata, type MicdropCallSummary, MicdropClient, MicdropClientCommands, MicdropClientError, MicdropClientErrorCode, type MicdropConversation, type MicdropConversationItem, type MicdropConversationMessage, type MicdropConversationToolCall, type MicdropConversationToolResult, type MicdropEvents, type MicdropOptions, MicdropServerCommands, type MicdropState, type MicdropToolCall, MultipleVAD, SileroVAD, type SileroVADOptions, Speaker, VAD, type VADConfig, type VADConfigName, type VADEvents, VADStatus, VolumeVAD, type VolumeVADOptions, getClientErrorFromWSCloseEvent, getClientErrorFromWSCloseEventCode, getVAD };
package/dist/index.js CHANGED
@@ -878,6 +878,23 @@ var Speaker2 = window.micdropSpeaker;
878
878
  // src/client/MicdropClient.ts
879
879
  var import_eventemitter36 = require("eventemitter3");
880
880
 
881
+ // ../server/src/types.ts
882
+ var MicdropClientCommands = /* @__PURE__ */ ((MicdropClientCommands2) => {
883
+ MicdropClientCommands2["StartSpeaking"] = "StartSpeaking";
884
+ MicdropClientCommands2["StopSpeaking"] = "StopSpeaking";
885
+ MicdropClientCommands2["Mute"] = "Mute";
886
+ return MicdropClientCommands2;
887
+ })(MicdropClientCommands || {});
888
+ var MicdropServerCommands = /* @__PURE__ */ ((MicdropServerCommands2) => {
889
+ MicdropServerCommands2["Message"] = "Message";
890
+ MicdropServerCommands2["CancelLastAssistantMessage"] = "CancelLastAssistantMessage";
891
+ MicdropServerCommands2["CancelLastUserMessage"] = "CancelLastUserMessage";
892
+ MicdropServerCommands2["SkipAnswer"] = "SkipAnswer";
893
+ MicdropServerCommands2["EndCall"] = "EndCall";
894
+ MicdropServerCommands2["ToolCall"] = "ToolCall";
895
+ return MicdropServerCommands2;
896
+ })(MicdropServerCommands || {});
897
+
881
898
  // src/client/MicdropClientError.ts
882
899
  var MicdropClientErrorCode = /* @__PURE__ */ ((MicdropClientErrorCode2) => {
883
900
  MicdropClientErrorCode2["MissingUrl"] = "MissingUrl";
@@ -1073,11 +1090,19 @@ var MicdropClient = class extends import_eventemitter36.EventEmitter {
1073
1090
  } else if (typeof event.data !== "string") {
1074
1091
  console.warn(`[MicdropClient] Unknown message type: ${event.data}`);
1075
1092
  } else if (event.data.startsWith("Message" /* Message */)) {
1076
- const message = JSON.parse(
1077
- event.data.substring("Message" /* Message */.length + 1)
1078
- );
1079
- this._isProcessing = false;
1080
- this.addMessage(message);
1093
+ try {
1094
+ const message = JSON.parse(
1095
+ event.data.substring("Message" /* Message */.length + 1)
1096
+ );
1097
+ this._isProcessing = false;
1098
+ this.addMessage(message);
1099
+ } catch (error) {
1100
+ console.error(
1101
+ "[MicdropClient] Error parsing message:",
1102
+ event.data,
1103
+ error
1104
+ );
1105
+ }
1081
1106
  } else if (event.data === "EndCall" /* EndCall */) {
1082
1107
  this.emit("EndCall");
1083
1108
  } else if (event.data === "CancelLastAssistantMessage" /* CancelLastAssistantMessage */) {
@@ -1096,6 +1121,19 @@ var MicdropClient = class extends import_eventemitter36.EventEmitter {
1096
1121
  this._isProcessing = false;
1097
1122
  this.notifyStateChange();
1098
1123
  }
1124
+ } else if (event.data.startsWith("ToolCall" /* ToolCall */)) {
1125
+ try {
1126
+ const toolCall = JSON.parse(
1127
+ event.data.substring("ToolCall" /* ToolCall */.length + 1)
1128
+ );
1129
+ this.emit("ToolCall", toolCall);
1130
+ } catch (error) {
1131
+ console.error(
1132
+ "[MicdropClient] Error parsing tool call:",
1133
+ event.data,
1134
+ error
1135
+ );
1136
+ }
1099
1137
  }
1100
1138
  };
1101
1139
  this.onWSClose = (event) => {
@@ -1258,22 +1296,6 @@ if (!window.micdropClient) {
1258
1296
  window.micdropClient = new MicdropClient();
1259
1297
  }
1260
1298
  var Micdrop = window.micdropClient;
1261
-
1262
- // ../server/src/types.ts
1263
- var MicdropClientCommands = /* @__PURE__ */ ((MicdropClientCommands2) => {
1264
- MicdropClientCommands2["StartSpeaking"] = "StartSpeaking";
1265
- MicdropClientCommands2["StopSpeaking"] = "StopSpeaking";
1266
- MicdropClientCommands2["Mute"] = "Mute";
1267
- return MicdropClientCommands2;
1268
- })(MicdropClientCommands || {});
1269
- var MicdropServerCommands = /* @__PURE__ */ ((MicdropServerCommands2) => {
1270
- MicdropServerCommands2["Message"] = "Message";
1271
- MicdropServerCommands2["CancelLastAssistantMessage"] = "CancelLastAssistantMessage";
1272
- MicdropServerCommands2["CancelLastUserMessage"] = "CancelLastUserMessage";
1273
- MicdropServerCommands2["SkipAnswer"] = "SkipAnswer";
1274
- MicdropServerCommands2["EndCall"] = "EndCall";
1275
- return MicdropServerCommands2;
1276
- })(MicdropServerCommands || {});
1277
1299
  // Annotate the CommonJS export names for ESM import in node:
1278
1300
  0 && (module.exports = {
1279
1301
  LocalStorageKeys,