@micdrop/client 2.0.5 → 2.0.7

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, MicdropToolCall as MicdropToolCall$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,53 @@ 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
+ CancelLastUserMessage = "CancelLastUserMessage",
223
+ SkipAnswer = "SkipAnswer",
224
+ EndCall = "EndCall",
225
+ ToolCall = "ToolCall"
226
+ }
227
+ interface MicdropCallSummary {
228
+ conversation: MicdropConversation;
229
+ duration: number;
230
+ }
231
+ type MicdropConversationItem = MicdropConversationMessage | MicdropConversationToolCall | MicdropConversationToolResult;
232
+ type MicdropConversation = Array<MicdropConversationItem>;
233
+ type MicdropAnswerMetadata = {
234
+ [key: string]: any;
235
+ };
236
+ interface MicdropConversationMessage<Data extends MicdropAnswerMetadata = MicdropAnswerMetadata> {
237
+ role: 'system' | 'user' | 'assistant';
238
+ content: string;
239
+ metadata?: Data;
240
+ }
241
+ interface MicdropConversationToolCall {
242
+ role: 'tool_call';
243
+ toolCallId: string;
244
+ toolName: string;
245
+ parameters: string;
246
+ }
247
+ interface MicdropConversationToolResult {
248
+ role: 'tool_result';
249
+ toolCallId: string;
250
+ toolName: string;
251
+ output: string;
252
+ }
253
+ interface MicdropToolCall {
254
+ name: string;
255
+ parameters: any;
256
+ output: any;
257
+ }
258
+ type DeepPartial<T> = T extends object ? {
259
+ [P in keyof T]?: DeepPartial<T[P]>;
260
+ } : T;
261
+
217
262
  declare enum MicdropClientErrorCode {
218
263
  MissingUrl = "MissingUrl",
219
264
  Mic = "Mic",
@@ -235,7 +280,7 @@ interface MicdropEvents {
235
280
  EndCall: [];
236
281
  Error: [MicdropClientError];
237
282
  StateChange: [MicdropState];
238
- ToolCall: [MicdropToolCall$1];
283
+ ToolCall: [MicdropToolCall];
239
284
  }
240
285
  interface MicdropOptions {
241
286
  url?: string;
@@ -258,13 +303,13 @@ interface MicdropState {
258
303
  speakerDeviceId: string | undefined;
259
304
  micDevices: MediaDeviceInfo[];
260
305
  speakerDevices: MediaDeviceInfo[];
261
- conversation: MicdropConversation$1;
306
+ conversation: MicdropConversation;
262
307
  error: MicdropClientError | undefined;
263
308
  }
264
309
  declare class MicdropClient extends EventEmitter<MicdropEvents> implements MicdropState {
265
310
  options: MicdropOptions;
266
311
  micRecorder?: MicRecorder;
267
- conversation: MicdropConversation$1;
312
+ conversation: MicdropConversation;
268
313
  error: MicdropClientError | undefined;
269
314
  speakerDevices: MediaDeviceInfo[];
270
315
  micDevices: MediaDeviceInfo[];
@@ -274,7 +319,7 @@ declare class MicdropClient extends EventEmitter<MicdropEvents> implements Micdr
274
319
  private _isProcessing;
275
320
  private _isPaused;
276
321
  constructor(options?: MicdropOptions);
277
- get vad(): VAD$1 | undefined;
322
+ get vad(): VAD | undefined;
278
323
  get isStarted(): boolean;
279
324
  get isStarting(): boolean;
280
325
  get isPaused(): boolean;
@@ -318,111 +363,4 @@ declare class MicdropClient extends EventEmitter<MicdropEvents> implements Micdr
318
363
 
319
364
  declare const Micdrop: MicdropClient;
320
365
 
321
- declare class Logger {
322
- private readonly name;
323
- constructor(name: string);
324
- log(...message: any[]): void;
325
- }
326
-
327
- interface AgentOptions {
328
- systemPrompt: string;
329
- }
330
- interface AgentEvents {
331
- Message: [MicdropConversationMessage];
332
- CancelLastUserMessage: [];
333
- CancelLastAssistantMessage: [];
334
- SkipAnswer: [];
335
- EndCall: [];
336
- ToolCall: [MicdropToolCall];
337
- }
338
- declare abstract class Agent<Options extends AgentOptions = AgentOptions> extends EventEmitter<AgentEvents> {
339
- protected options: Options;
340
- logger?: Logger;
341
- conversation: MicdropConversation;
342
- constructor(options: Options);
343
- abstract answer(): Readable;
344
- abstract cancel(): void;
345
- addUserMessage(text: string, metadata?: MicdropAnswerMetadata): void;
346
- addAssistantMessage(text: string, metadata?: MicdropAnswerMetadata): void;
347
- protected addMessage(role: 'user' | 'assistant' | 'system', text: string, metadata?: MicdropAnswerMetadata): void;
348
- protected endCall(): void;
349
- protected cancelLastUserMessage(): void;
350
- protected cancelLastAssistantMessage(): void;
351
- protected skipAnswer(): void;
352
- protected log(...message: any[]): void;
353
- destroy(): void;
354
- }
355
-
356
- declare const MIME_TYPE_TO_EXTENSION: {
357
- readonly 'audio/wav': "wav";
358
- readonly 'audio/ogg': "ogg";
359
- readonly 'audio/mpeg': "mp3";
360
- readonly 'audio/webm': "webm";
361
- readonly 'audio/mp4': "mp4";
362
- readonly 'audio/flac': "flac";
363
- };
364
- interface STTEvents {
365
- Transcript: [string];
366
- }
367
- declare abstract class STT extends EventEmitter<STTEvents> {
368
- protected mimeType?: keyof typeof MIME_TYPE_TO_EXTENSION;
369
- logger?: Logger;
370
- transcribe(audioStream: Readable): void;
371
- protected log(...message: any[]): void;
372
- destroy(): void;
373
- protected get extension(): string;
374
- private detectMimeType;
375
- }
376
-
377
- declare abstract class TTS {
378
- logger?: Logger;
379
- abstract speak(textStream: Readable): Readable;
380
- abstract cancel(): void;
381
- protected log(...message: any[]): void;
382
- destroy(): void;
383
- }
384
-
385
- declare enum MicdropClientCommands {
386
- StartSpeaking = "StartSpeaking",
387
- StopSpeaking = "StopSpeaking",
388
- Mute = "Mute"
389
- }
390
- declare enum MicdropServerCommands {
391
- Message = "Message",
392
- CancelLastAssistantMessage = "CancelLastAssistantMessage",
393
- CancelLastUserMessage = "CancelLastUserMessage",
394
- SkipAnswer = "SkipAnswer",
395
- EndCall = "EndCall",
396
- ToolCall = "ToolCall"
397
- }
398
- interface MicdropConfig {
399
- firstMessage?: string;
400
- generateFirstMessage?: boolean;
401
- agent: Agent;
402
- stt: STT;
403
- tts: TTS;
404
- onEnd?(call: MicdropCallSummary): void;
405
- }
406
- interface MicdropCallSummary {
407
- conversation: MicdropConversation;
408
- duration: number;
409
- }
410
- type MicdropConversation = MicdropConversationMessage[];
411
- type MicdropAnswerMetadata = {
412
- [key: string]: any;
413
- };
414
- interface MicdropConversationMessage<Data extends MicdropAnswerMetadata = MicdropAnswerMetadata> {
415
- role: 'system' | 'user' | 'assistant';
416
- content: string;
417
- metadata?: Data;
418
- }
419
- interface MicdropToolCall {
420
- name: string;
421
- parameters: any;
422
- output: any;
423
- }
424
- type DeepPartial<T> = T extends object ? {
425
- [P in keyof T]?: DeepPartial<T[P]>;
426
- } : T;
427
-
428
- 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, type MicdropToolCall, MultipleVAD, SileroVAD, type SileroVADOptions, Speaker, VAD, type VADConfig, type VADConfigName, type VADEvents, VADStatus, VolumeVAD, type VolumeVADOptions, getClientErrorFromWSCloseEvent, getClientErrorFromWSCloseEventCode, getVAD };
366
+ 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, MicdropToolCall as MicdropToolCall$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,53 @@ 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
+ CancelLastUserMessage = "CancelLastUserMessage",
223
+ SkipAnswer = "SkipAnswer",
224
+ EndCall = "EndCall",
225
+ ToolCall = "ToolCall"
226
+ }
227
+ interface MicdropCallSummary {
228
+ conversation: MicdropConversation;
229
+ duration: number;
230
+ }
231
+ type MicdropConversationItem = MicdropConversationMessage | MicdropConversationToolCall | MicdropConversationToolResult;
232
+ type MicdropConversation = Array<MicdropConversationItem>;
233
+ type MicdropAnswerMetadata = {
234
+ [key: string]: any;
235
+ };
236
+ interface MicdropConversationMessage<Data extends MicdropAnswerMetadata = MicdropAnswerMetadata> {
237
+ role: 'system' | 'user' | 'assistant';
238
+ content: string;
239
+ metadata?: Data;
240
+ }
241
+ interface MicdropConversationToolCall {
242
+ role: 'tool_call';
243
+ toolCallId: string;
244
+ toolName: string;
245
+ parameters: string;
246
+ }
247
+ interface MicdropConversationToolResult {
248
+ role: 'tool_result';
249
+ toolCallId: string;
250
+ toolName: string;
251
+ output: string;
252
+ }
253
+ interface MicdropToolCall {
254
+ name: string;
255
+ parameters: any;
256
+ output: any;
257
+ }
258
+ type DeepPartial<T> = T extends object ? {
259
+ [P in keyof T]?: DeepPartial<T[P]>;
260
+ } : T;
261
+
217
262
  declare enum MicdropClientErrorCode {
218
263
  MissingUrl = "MissingUrl",
219
264
  Mic = "Mic",
@@ -235,7 +280,7 @@ interface MicdropEvents {
235
280
  EndCall: [];
236
281
  Error: [MicdropClientError];
237
282
  StateChange: [MicdropState];
238
- ToolCall: [MicdropToolCall$1];
283
+ ToolCall: [MicdropToolCall];
239
284
  }
240
285
  interface MicdropOptions {
241
286
  url?: string;
@@ -258,13 +303,13 @@ interface MicdropState {
258
303
  speakerDeviceId: string | undefined;
259
304
  micDevices: MediaDeviceInfo[];
260
305
  speakerDevices: MediaDeviceInfo[];
261
- conversation: MicdropConversation$1;
306
+ conversation: MicdropConversation;
262
307
  error: MicdropClientError | undefined;
263
308
  }
264
309
  declare class MicdropClient extends EventEmitter<MicdropEvents> implements MicdropState {
265
310
  options: MicdropOptions;
266
311
  micRecorder?: MicRecorder;
267
- conversation: MicdropConversation$1;
312
+ conversation: MicdropConversation;
268
313
  error: MicdropClientError | undefined;
269
314
  speakerDevices: MediaDeviceInfo[];
270
315
  micDevices: MediaDeviceInfo[];
@@ -274,7 +319,7 @@ declare class MicdropClient extends EventEmitter<MicdropEvents> implements Micdr
274
319
  private _isProcessing;
275
320
  private _isPaused;
276
321
  constructor(options?: MicdropOptions);
277
- get vad(): VAD$1 | undefined;
322
+ get vad(): VAD | undefined;
278
323
  get isStarted(): boolean;
279
324
  get isStarting(): boolean;
280
325
  get isPaused(): boolean;
@@ -318,111 +363,4 @@ declare class MicdropClient extends EventEmitter<MicdropEvents> implements Micdr
318
363
 
319
364
  declare const Micdrop: MicdropClient;
320
365
 
321
- declare class Logger {
322
- private readonly name;
323
- constructor(name: string);
324
- log(...message: any[]): void;
325
- }
326
-
327
- interface AgentOptions {
328
- systemPrompt: string;
329
- }
330
- interface AgentEvents {
331
- Message: [MicdropConversationMessage];
332
- CancelLastUserMessage: [];
333
- CancelLastAssistantMessage: [];
334
- SkipAnswer: [];
335
- EndCall: [];
336
- ToolCall: [MicdropToolCall];
337
- }
338
- declare abstract class Agent<Options extends AgentOptions = AgentOptions> extends EventEmitter<AgentEvents> {
339
- protected options: Options;
340
- logger?: Logger;
341
- conversation: MicdropConversation;
342
- constructor(options: Options);
343
- abstract answer(): Readable;
344
- abstract cancel(): void;
345
- addUserMessage(text: string, metadata?: MicdropAnswerMetadata): void;
346
- addAssistantMessage(text: string, metadata?: MicdropAnswerMetadata): void;
347
- protected addMessage(role: 'user' | 'assistant' | 'system', text: string, metadata?: MicdropAnswerMetadata): void;
348
- protected endCall(): void;
349
- protected cancelLastUserMessage(): void;
350
- protected cancelLastAssistantMessage(): void;
351
- protected skipAnswer(): void;
352
- protected log(...message: any[]): void;
353
- destroy(): void;
354
- }
355
-
356
- declare const MIME_TYPE_TO_EXTENSION: {
357
- readonly 'audio/wav': "wav";
358
- readonly 'audio/ogg': "ogg";
359
- readonly 'audio/mpeg': "mp3";
360
- readonly 'audio/webm': "webm";
361
- readonly 'audio/mp4': "mp4";
362
- readonly 'audio/flac': "flac";
363
- };
364
- interface STTEvents {
365
- Transcript: [string];
366
- }
367
- declare abstract class STT extends EventEmitter<STTEvents> {
368
- protected mimeType?: keyof typeof MIME_TYPE_TO_EXTENSION;
369
- logger?: Logger;
370
- transcribe(audioStream: Readable): void;
371
- protected log(...message: any[]): void;
372
- destroy(): void;
373
- protected get extension(): string;
374
- private detectMimeType;
375
- }
376
-
377
- declare abstract class TTS {
378
- logger?: Logger;
379
- abstract speak(textStream: Readable): Readable;
380
- abstract cancel(): void;
381
- protected log(...message: any[]): void;
382
- destroy(): void;
383
- }
384
-
385
- declare enum MicdropClientCommands {
386
- StartSpeaking = "StartSpeaking",
387
- StopSpeaking = "StopSpeaking",
388
- Mute = "Mute"
389
- }
390
- declare enum MicdropServerCommands {
391
- Message = "Message",
392
- CancelLastAssistantMessage = "CancelLastAssistantMessage",
393
- CancelLastUserMessage = "CancelLastUserMessage",
394
- SkipAnswer = "SkipAnswer",
395
- EndCall = "EndCall",
396
- ToolCall = "ToolCall"
397
- }
398
- interface MicdropConfig {
399
- firstMessage?: string;
400
- generateFirstMessage?: boolean;
401
- agent: Agent;
402
- stt: STT;
403
- tts: TTS;
404
- onEnd?(call: MicdropCallSummary): void;
405
- }
406
- interface MicdropCallSummary {
407
- conversation: MicdropConversation;
408
- duration: number;
409
- }
410
- type MicdropConversation = MicdropConversationMessage[];
411
- type MicdropAnswerMetadata = {
412
- [key: string]: any;
413
- };
414
- interface MicdropConversationMessage<Data extends MicdropAnswerMetadata = MicdropAnswerMetadata> {
415
- role: 'system' | 'user' | 'assistant';
416
- content: string;
417
- metadata?: Data;
418
- }
419
- interface MicdropToolCall {
420
- name: string;
421
- parameters: any;
422
- output: any;
423
- }
424
- type DeepPartial<T> = T extends object ? {
425
- [P in keyof T]?: DeepPartial<T[P]>;
426
- } : T;
427
-
428
- 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, type MicdropToolCall, MultipleVAD, SileroVAD, type SileroVADOptions, Speaker, VAD, type VADConfig, type VADConfigName, type VADEvents, VADStatus, VolumeVAD, type VolumeVADOptions, getClientErrorFromWSCloseEvent, getClientErrorFromWSCloseEventCode, getVAD };
366
+ 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,22 @@ 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["CancelLastUserMessage"] = "CancelLastUserMessage";
891
+ MicdropServerCommands2["SkipAnswer"] = "SkipAnswer";
892
+ MicdropServerCommands2["EndCall"] = "EndCall";
893
+ MicdropServerCommands2["ToolCall"] = "ToolCall";
894
+ return MicdropServerCommands2;
895
+ })(MicdropServerCommands || {});
896
+
881
897
  // src/client/MicdropClientError.ts
882
898
  var MicdropClientErrorCode = /* @__PURE__ */ ((MicdropClientErrorCode2) => {
883
899
  MicdropClientErrorCode2["MissingUrl"] = "MissingUrl";
@@ -1088,19 +1104,17 @@ var MicdropClient = class extends import_eventemitter36.EventEmitter {
1088
1104
  }
1089
1105
  } else if (event.data === "EndCall" /* EndCall */) {
1090
1106
  this.emit("EndCall");
1091
- } else if (event.data === "CancelLastAssistantMessage" /* CancelLastAssistantMessage */) {
1092
- const lastMessage = this.conversation[this.conversation.length - 1];
1093
- if (lastMessage?.role === "assistant") {
1094
- this.conversation = this.conversation.slice(0, -1);
1095
- this.notifyStateChange();
1096
- }
1097
1107
  } else if (event.data === "SkipAnswer" /* SkipAnswer */) {
1098
1108
  this._isProcessing = false;
1099
1109
  this.notifyStateChange();
1100
1110
  } else if (event.data === "CancelLastUserMessage" /* CancelLastUserMessage */) {
1101
- const lastMessage = this.conversation[this.conversation.length - 1];
1102
- if (lastMessage?.role === "user") {
1103
- this.conversation = this.conversation.slice(0, -1);
1111
+ const lastMessage = this.conversation.findLastIndex(
1112
+ (message) => message.role === "user"
1113
+ );
1114
+ if (lastMessage !== -1) {
1115
+ this.conversation = this.conversation.filter(
1116
+ (_, index) => index !== lastMessage
1117
+ );
1104
1118
  this._isProcessing = false;
1105
1119
  this.notifyStateChange();
1106
1120
  }
@@ -1279,23 +1293,6 @@ if (!window.micdropClient) {
1279
1293
  window.micdropClient = new MicdropClient();
1280
1294
  }
1281
1295
  var Micdrop = window.micdropClient;
1282
-
1283
- // ../server/src/types.ts
1284
- var MicdropClientCommands = /* @__PURE__ */ ((MicdropClientCommands2) => {
1285
- MicdropClientCommands2["StartSpeaking"] = "StartSpeaking";
1286
- MicdropClientCommands2["StopSpeaking"] = "StopSpeaking";
1287
- MicdropClientCommands2["Mute"] = "Mute";
1288
- return MicdropClientCommands2;
1289
- })(MicdropClientCommands || {});
1290
- var MicdropServerCommands = /* @__PURE__ */ ((MicdropServerCommands2) => {
1291
- MicdropServerCommands2["Message"] = "Message";
1292
- MicdropServerCommands2["CancelLastAssistantMessage"] = "CancelLastAssistantMessage";
1293
- MicdropServerCommands2["CancelLastUserMessage"] = "CancelLastUserMessage";
1294
- MicdropServerCommands2["SkipAnswer"] = "SkipAnswer";
1295
- MicdropServerCommands2["EndCall"] = "EndCall";
1296
- MicdropServerCommands2["ToolCall"] = "ToolCall";
1297
- return MicdropServerCommands2;
1298
- })(MicdropServerCommands || {});
1299
1296
  // Annotate the CommonJS export names for ESM import in node:
1300
1297
  0 && (module.exports = {
1301
1298
  LocalStorageKeys,