@fonoster/autopilot 0.7.23 → 0.7.25

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/Autopilot.js CHANGED
@@ -63,7 +63,6 @@ class Autopilot {
63
63
  stop() {
64
64
  logger.verbose("stopping autopilot");
65
65
  this.actor.stop();
66
- this.vadWorker.terminate();
67
66
  }
68
67
  async setupVoiceStream() {
69
68
  const { voice } = this.params;
@@ -5,9 +5,9 @@ declare const conversationSettingsSchema: z.ZodObject<{
5
5
  systemTemplate: z.ZodString;
6
6
  goodbyeMessage: z.ZodString;
7
7
  systemErrorMessage: z.ZodString;
8
- initialDtmf: z.ZodNullable<z.ZodOptional<z.ZodString>>;
8
+ initialDtmf: z.ZodOptional<z.ZodString>;
9
9
  maxSpeechWaitTimeout: z.ZodNumber;
10
- transferOptions: z.ZodNullable<z.ZodOptional<z.ZodObject<{
10
+ transferOptions: z.ZodOptional<z.ZodObject<{
11
11
  phoneNumber: z.ZodString;
12
12
  message: z.ZodString;
13
13
  timeout: z.ZodOptional<z.ZodNumber>;
@@ -19,8 +19,8 @@ declare const conversationSettingsSchema: z.ZodObject<{
19
19
  message: string;
20
20
  phoneNumber: string;
21
21
  timeout?: number | undefined;
22
- }>>>;
23
- idleOptions: z.ZodNullable<z.ZodOptional<z.ZodObject<{
22
+ }>>;
23
+ idleOptions: z.ZodOptional<z.ZodObject<{
24
24
  message: z.ZodString;
25
25
  timeout: z.ZodNumber;
26
26
  maxTimeoutCount: z.ZodNumber;
@@ -32,7 +32,7 @@ declare const conversationSettingsSchema: z.ZodObject<{
32
32
  message: string;
33
33
  timeout: number;
34
34
  maxTimeoutCount: number;
35
- }>>>;
35
+ }>>;
36
36
  vad: z.ZodObject<{
37
37
  pathToModel: z.ZodOptional<z.ZodString>;
38
38
  activationThreshold: z.ZodNumber;
@@ -61,17 +61,17 @@ declare const conversationSettingsSchema: z.ZodObject<{
61
61
  debounceFrames: number;
62
62
  pathToModel?: string | undefined;
63
63
  };
64
- initialDtmf?: string | null | undefined;
64
+ initialDtmf?: string | undefined;
65
65
  transferOptions?: {
66
66
  message: string;
67
67
  phoneNumber: string;
68
68
  timeout?: number | undefined;
69
- } | null | undefined;
69
+ } | undefined;
70
70
  idleOptions?: {
71
71
  message: string;
72
72
  timeout: number;
73
73
  maxTimeoutCount: number;
74
- } | null | undefined;
74
+ } | undefined;
75
75
  }, {
76
76
  firstMessage: string;
77
77
  systemTemplate: string;
@@ -84,17 +84,17 @@ declare const conversationSettingsSchema: z.ZodObject<{
84
84
  debounceFrames: number;
85
85
  pathToModel?: string | undefined;
86
86
  };
87
- initialDtmf?: string | null | undefined;
87
+ initialDtmf?: string | undefined;
88
88
  transferOptions?: {
89
89
  message: string;
90
90
  phoneNumber: string;
91
91
  timeout?: number | undefined;
92
- } | null | undefined;
92
+ } | undefined;
93
93
  idleOptions?: {
94
94
  message: string;
95
95
  timeout: number;
96
96
  maxTimeoutCount: number;
97
- } | null | undefined;
97
+ } | undefined;
98
98
  }>;
99
99
  declare const languageModelConfigSchema: z.ZodObject<{
100
100
  provider: z.ZodNativeEnum<typeof LANGUAGE_MODEL_PROVIDER>;
@@ -297,9 +297,9 @@ declare const assistantSchema: z.ZodObject<{
297
297
  systemTemplate: z.ZodString;
298
298
  goodbyeMessage: z.ZodString;
299
299
  systemErrorMessage: z.ZodString;
300
- initialDtmf: z.ZodNullable<z.ZodOptional<z.ZodString>>;
300
+ initialDtmf: z.ZodOptional<z.ZodString>;
301
301
  maxSpeechWaitTimeout: z.ZodNumber;
302
- transferOptions: z.ZodNullable<z.ZodOptional<z.ZodObject<{
302
+ transferOptions: z.ZodOptional<z.ZodObject<{
303
303
  phoneNumber: z.ZodString;
304
304
  message: z.ZodString;
305
305
  timeout: z.ZodOptional<z.ZodNumber>;
@@ -311,8 +311,8 @@ declare const assistantSchema: z.ZodObject<{
311
311
  message: string;
312
312
  phoneNumber: string;
313
313
  timeout?: number | undefined;
314
- }>>>;
315
- idleOptions: z.ZodNullable<z.ZodOptional<z.ZodObject<{
314
+ }>>;
315
+ idleOptions: z.ZodOptional<z.ZodObject<{
316
316
  message: z.ZodString;
317
317
  timeout: z.ZodNumber;
318
318
  maxTimeoutCount: z.ZodNumber;
@@ -324,7 +324,7 @@ declare const assistantSchema: z.ZodObject<{
324
324
  message: string;
325
325
  timeout: number;
326
326
  maxTimeoutCount: number;
327
- }>>>;
327
+ }>>;
328
328
  vad: z.ZodObject<{
329
329
  pathToModel: z.ZodOptional<z.ZodString>;
330
330
  activationThreshold: z.ZodNumber;
@@ -353,17 +353,17 @@ declare const assistantSchema: z.ZodObject<{
353
353
  debounceFrames: number;
354
354
  pathToModel?: string | undefined;
355
355
  };
356
- initialDtmf?: string | null | undefined;
356
+ initialDtmf?: string | undefined;
357
357
  transferOptions?: {
358
358
  message: string;
359
359
  phoneNumber: string;
360
360
  timeout?: number | undefined;
361
- } | null | undefined;
361
+ } | undefined;
362
362
  idleOptions?: {
363
363
  message: string;
364
364
  timeout: number;
365
365
  maxTimeoutCount: number;
366
- } | null | undefined;
366
+ } | undefined;
367
367
  }, {
368
368
  firstMessage: string;
369
369
  systemTemplate: string;
@@ -376,17 +376,17 @@ declare const assistantSchema: z.ZodObject<{
376
376
  debounceFrames: number;
377
377
  pathToModel?: string | undefined;
378
378
  };
379
- initialDtmf?: string | null | undefined;
379
+ initialDtmf?: string | undefined;
380
380
  transferOptions?: {
381
381
  message: string;
382
382
  phoneNumber: string;
383
383
  timeout?: number | undefined;
384
- } | null | undefined;
384
+ } | undefined;
385
385
  idleOptions?: {
386
386
  message: string;
387
387
  timeout: number;
388
388
  maxTimeoutCount: number;
389
- } | null | undefined;
389
+ } | undefined;
390
390
  }>;
391
391
  languageModel: z.ZodObject<{
392
392
  provider: z.ZodNativeEnum<typeof LANGUAGE_MODEL_PROVIDER>;
@@ -596,17 +596,17 @@ declare const assistantSchema: z.ZodObject<{
596
596
  debounceFrames: number;
597
597
  pathToModel?: string | undefined;
598
598
  };
599
- initialDtmf?: string | null | undefined;
599
+ initialDtmf?: string | undefined;
600
600
  transferOptions?: {
601
601
  message: string;
602
602
  phoneNumber: string;
603
603
  timeout?: number | undefined;
604
- } | null | undefined;
604
+ } | undefined;
605
605
  idleOptions?: {
606
606
  message: string;
607
607
  timeout: number;
608
608
  maxTimeoutCount: number;
609
- } | null | undefined;
609
+ } | undefined;
610
610
  };
611
611
  languageModel: {
612
612
  model: string;
@@ -654,17 +654,17 @@ declare const assistantSchema: z.ZodObject<{
654
654
  debounceFrames: number;
655
655
  pathToModel?: string | undefined;
656
656
  };
657
- initialDtmf?: string | null | undefined;
657
+ initialDtmf?: string | undefined;
658
658
  transferOptions?: {
659
659
  message: string;
660
660
  phoneNumber: string;
661
661
  timeout?: number | undefined;
662
- } | null | undefined;
662
+ } | undefined;
663
663
  idleOptions?: {
664
664
  message: string;
665
665
  timeout: number;
666
666
  maxTimeoutCount: number;
667
- } | null | undefined;
667
+ } | undefined;
668
668
  };
669
669
  languageModel: {
670
670
  model: string;
@@ -19,6 +19,7 @@ exports.languageModelConfigSchema = exports.conversationSettingsSchema = exports
19
19
  * See the License for the specific language governing permissions and
20
20
  * limitations under the License.
21
21
  */
22
+ const common_1 = require("@fonoster/common");
22
23
  const zod_1 = require("zod");
23
24
  const ToolSchema_1 = require("../tools/ToolSchema");
24
25
  const types_1 = require("../types");
@@ -27,43 +28,70 @@ const conversationSettingsSchema = zod_1.z.object({
27
28
  systemTemplate: zod_1.z.string(),
28
29
  goodbyeMessage: zod_1.z.string(),
29
30
  systemErrorMessage: zod_1.z.string(),
30
- initialDtmf: zod_1.z.string().optional().nullable(),
31
- maxSpeechWaitTimeout: zod_1.z.number(),
31
+ initialDtmf: zod_1.z
32
+ .string()
33
+ .regex(/^[0-9*#]+$/, { message: common_1.Messages.VALID_DTMF })
34
+ .optional(),
35
+ maxSpeechWaitTimeout: zod_1.z
36
+ .number()
37
+ .int({ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE })
38
+ .positive({ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE }),
32
39
  transferOptions: zod_1.z
33
40
  .object({
34
41
  phoneNumber: zod_1.z.string(),
35
42
  message: zod_1.z.string(),
36
- timeout: zod_1.z.number().optional()
43
+ timeout: zod_1.z
44
+ .number()
45
+ .int({ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE })
46
+ .positive({ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE })
47
+ .optional()
37
48
  })
38
- .optional()
39
- .nullable(),
49
+ .optional(),
40
50
  idleOptions: zod_1.z
41
51
  .object({
42
52
  message: zod_1.z.string(),
43
- timeout: zod_1.z.number(),
44
- maxTimeoutCount: zod_1.z.number()
53
+ timeout: zod_1.z
54
+ .number()
55
+ .int({ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE })
56
+ .positive({ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE }),
57
+ maxTimeoutCount: zod_1.z
58
+ .number()
59
+ .int({ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE })
60
+ .positive({ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE })
45
61
  })
46
- .optional()
47
- .nullable(),
62
+ .optional(),
48
63
  vad: zod_1.z.object({
49
64
  pathToModel: zod_1.z.string().optional(),
50
65
  activationThreshold: zod_1.z.number(),
51
66
  deactivationThreshold: zod_1.z.number(),
52
- debounceFrames: zod_1.z.number()
67
+ debounceFrames: zod_1.z
68
+ .number()
69
+ .int({ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE })
70
+ .positive({ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE })
53
71
  })
54
72
  });
55
73
  exports.conversationSettingsSchema = conversationSettingsSchema;
56
74
  const languageModelConfigSchema = zod_1.z.object({
57
- provider: zod_1.z.nativeEnum(types_1.LANGUAGE_MODEL_PROVIDER),
75
+ provider: zod_1.z.nativeEnum(types_1.LANGUAGE_MODEL_PROVIDER, {
76
+ message: "Invalid language model provider."
77
+ }),
58
78
  apiKey: zod_1.z.string().optional(),
59
79
  model: zod_1.z.string(),
60
80
  temperature: zod_1.z.number(),
61
- maxTokens: zod_1.z.number(),
62
- baseUrl: zod_1.z.string().optional(),
81
+ maxTokens: zod_1.z
82
+ .number()
83
+ .int({ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE })
84
+ .positive({ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE }),
85
+ baseUrl: zod_1.z
86
+ .string()
87
+ .url({
88
+ message: common_1.Messages.VALID_URL
89
+ })
90
+ .optional(),
63
91
  knowledgeBase: zod_1.z.array(zod_1.z.object({
64
92
  type: zod_1.z.enum(["s3", "file"]),
65
93
  title: zod_1.z.string(),
66
- url: zod_1.z.string()
94
+ url: zod_1.z.string().url({ message: common_1.Messages.VALID_URL })
67
95
  })),
68
96
  tools: zod_1.z.array(ToolSchema_1.toolSchema)
69
97
  });
@@ -164,6 +164,7 @@ const machine = (0, xstate_1.setup)({
164
164
  });
165
165
  const message = context.transferMessage;
166
166
  await context.voice.say(message);
167
+ await context.voice.stopStreams();
167
168
  await context.voice.transfer(context.transferPhoneNumber, {
168
169
  record: true,
169
170
  timeout: 30
@@ -19,6 +19,7 @@ exports.toolSchema = exports.AllowedOperations = void 0;
19
19
  * See the License for the specific language governing permissions and
20
20
  * limitations under the License.
21
21
  */
22
+ const common_1 = require("@fonoster/common");
22
23
  const zod_1 = require("zod");
23
24
  var AllowedOperations;
24
25
  (function (AllowedOperations) {
@@ -48,9 +49,11 @@ const toolSchema = zod_1.z.object({
48
49
  requestStartMessage: zod_1.z.string().optional(),
49
50
  operation: zod_1.z
50
51
  .object({
51
- type: zod_1.z.nativeEnum(AllowedOperations),
52
+ type: zod_1.z.nativeEnum(AllowedOperations, {
53
+ message: "Invalid operation type"
54
+ }),
52
55
  // Make url required if operation type is not built-in
53
- url: zod_1.z.string().optional(),
56
+ url: zod_1.z.string().url({ message: common_1.Messages.VALID_URL }).optional(),
54
57
  waitForResponse: zod_1.z.boolean().optional(),
55
58
  headers: zod_1.z.record(zod_1.z.string()).optional()
56
59
  })
@@ -4,6 +4,14 @@ declare class VoiceImpl implements Voice {
4
4
  private voice;
5
5
  private playbackRef;
6
6
  sessionRef: string;
7
+ sgatherStream: {
8
+ stop: () => Promise<void>;
9
+ onData: (cb: (speech: string) => void) => void;
10
+ };
11
+ vadStream: {
12
+ stop: () => Promise<void>;
13
+ onData: (cb: (chunk: Uint8Array) => void) => void;
14
+ };
7
15
  constructor(sessionRef: string, voice: VoiceResponse);
8
16
  answer(): Promise<void>;
9
17
  hangup(): Promise<void>;
@@ -21,5 +29,6 @@ declare class VoiceImpl implements Voice {
21
29
  timeout: number;
22
30
  }): Promise<void>;
23
31
  stopSpeech(): Promise<void>;
32
+ stopStreams(): Promise<void>;
24
33
  }
25
34
  export { VoiceImpl };
@@ -40,7 +40,7 @@ class VoiceImpl {
40
40
  const stream = await this.voice.sgather({
41
41
  source: common_1.StreamGatherSource.SPEECH
42
42
  });
43
- return {
43
+ this.sgatherStream = {
44
44
  stop: async () => {
45
45
  stream.close();
46
46
  stream.cleanup(() => { });
@@ -51,10 +51,11 @@ class VoiceImpl {
51
51
  });
52
52
  }
53
53
  };
54
+ return this.sgatherStream;
54
55
  }
55
56
  async stream() {
56
57
  const stream = await this.voice.stream();
57
- return {
58
+ this.vadStream = {
58
59
  stop: async () => {
59
60
  stream.close();
60
61
  stream.cleanup(() => { });
@@ -65,6 +66,7 @@ class VoiceImpl {
65
66
  });
66
67
  }
67
68
  };
69
+ return this.vadStream;
68
70
  }
69
71
  async transfer(to, options) {
70
72
  const { record, timeout } = options;
@@ -77,5 +79,9 @@ class VoiceImpl {
77
79
  async stopSpeech() {
78
80
  await this.voice.playbackControl(this.playbackRef, common_1.PlaybackControlAction.STOP);
79
81
  }
82
+ async stopStreams() {
83
+ await this.vadStream.stop();
84
+ await this.sgatherStream.stop();
85
+ }
80
86
  }
81
87
  exports.VoiceImpl = VoiceImpl;
@@ -19,5 +19,6 @@ type Voice = {
19
19
  transfer: (destination: string, options?: TransferOptions) => Promise<void>;
20
20
  stream: () => Promise<Stream>;
21
21
  stopSpeech: () => Promise<void>;
22
+ stopStreams: () => Promise<void>;
22
23
  };
23
24
  export { TransferOptions, Voice };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/autopilot",
3
- "version": "0.7.23",
3
+ "version": "0.7.25",
4
4
  "description": "Voice AI for the Fonoster platform",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -35,10 +35,10 @@
35
35
  "url": "https://github.com/fonoster/fonoster/issues"
36
36
  },
37
37
  "dependencies": {
38
- "@fonoster/common": "^0.7.22",
38
+ "@fonoster/common": "^0.7.25",
39
39
  "@fonoster/logger": "^0.7.22",
40
- "@fonoster/types": "^0.7.22",
41
- "@fonoster/voice": "^0.7.22",
40
+ "@fonoster/types": "^0.7.25",
41
+ "@fonoster/voice": "^0.7.25",
42
42
  "@langchain/community": "^0.2.31",
43
43
  "@langchain/core": "^0.2.32",
44
44
  "@langchain/groq": "^0.0.17",
@@ -56,5 +56,5 @@
56
56
  "devDependencies": {
57
57
  "typescript": "^5.5.4"
58
58
  },
59
- "gitHead": "eaf6ffdfdaaed15b6077f36b0aaa529d5eed8048"
59
+ "gitHead": "f5dbfe479bd50b105ce3eb4b3c260503ef718f57"
60
60
  }