@fonoster/autopilot 0.7.23 → 0.7.26
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/README.md +1 -1
- package/dist/Autopilot.js +5 -2
- package/dist/assistants/AssistantSchema.d.ts +28 -28
- package/dist/assistants/AssistantSchema.js +42 -14
- package/dist/assistants/index.js +1 -1
- package/dist/handleVoiceRequest.js +17 -7
- package/dist/loadAssistantConfig.js +17 -7
- package/dist/machine/machine.d.ts +0 -1
- package/dist/machine/machine.js +1 -9
- package/dist/machine/types.d.ts +0 -1
- package/dist/models/ollama/types.d.ts +1 -1
- package/dist/models/ollama/types.js +1 -1
- package/dist/tools/ToolSchema.js +5 -2
- package/dist/vad/makeVad.js +17 -7
- package/dist/voice/Voice.d.ts +9 -0
- package/dist/voice/Voice.js +8 -2
- package/dist/voice/types.d.ts +1 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -90,7 +90,7 @@ The Autopilot supports multiple language model providers. The following is a lis
|
|
|
90
90
|
|------------|------------------------------------------------------------|------------------------------------------------------------------------------|
|
|
91
91
|
| OpenAI | OpenAI provides various GPT models for conversational AI | `gpt-4o`, `gpt-4o-mini`, `gpt-3.5-turbo`, `gpt-4-turbo` |
|
|
92
92
|
| Groq | Groq offers high-performance AI models optimized for speed | `gemm-7b-it`, `llama3-groq-70b-8192-tool-use-preview`, `llama3-1-8b-instant` |
|
|
93
|
-
| Ollama | Self-hosted Ollama models | `
|
|
93
|
+
| Ollama | Self-hosted Ollama models | `llama3-groq-tool-use` |
|
|
94
94
|
|
|
95
95
|
## Adding Knowledge Base
|
|
96
96
|
|
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;
|
|
@@ -71,7 +70,9 @@ class Autopilot {
|
|
|
71
70
|
stream.onData(this.handleVoicePayload.bind(this));
|
|
72
71
|
this.vadWorker.on("message", (event) => {
|
|
73
72
|
logger.verbose("received speech event from vad", { event });
|
|
74
|
-
|
|
73
|
+
if (event === "SPEECH_START") {
|
|
74
|
+
this.actor.send({ type: "SPEECH_START" });
|
|
75
|
+
}
|
|
75
76
|
});
|
|
76
77
|
}
|
|
77
78
|
handleVoicePayload(chunk) {
|
|
@@ -88,6 +89,8 @@ class Autopilot {
|
|
|
88
89
|
stream.onData((speech) => {
|
|
89
90
|
logger.verbose("received speech result", { speech });
|
|
90
91
|
if (speech) {
|
|
92
|
+
// Testing using STT for both VAD and STT (experimental)
|
|
93
|
+
this.actor.send({ type: "SPEECH_END" });
|
|
91
94
|
this.actor.send({ type: "SPEECH_RESULT", speech });
|
|
92
95
|
}
|
|
93
96
|
});
|
|
@@ -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.
|
|
8
|
+
initialDtmf: z.ZodOptional<z.ZodString>;
|
|
9
9
|
maxSpeechWaitTimeout: z.ZodNumber;
|
|
10
|
-
transferOptions: z.
|
|
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.
|
|
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 |
|
|
64
|
+
initialDtmf?: string | undefined;
|
|
65
65
|
transferOptions?: {
|
|
66
66
|
message: string;
|
|
67
67
|
phoneNumber: string;
|
|
68
68
|
timeout?: number | undefined;
|
|
69
|
-
} |
|
|
69
|
+
} | undefined;
|
|
70
70
|
idleOptions?: {
|
|
71
71
|
message: string;
|
|
72
72
|
timeout: number;
|
|
73
73
|
maxTimeoutCount: number;
|
|
74
|
-
} |
|
|
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 |
|
|
87
|
+
initialDtmf?: string | undefined;
|
|
88
88
|
transferOptions?: {
|
|
89
89
|
message: string;
|
|
90
90
|
phoneNumber: string;
|
|
91
91
|
timeout?: number | undefined;
|
|
92
|
-
} |
|
|
92
|
+
} | undefined;
|
|
93
93
|
idleOptions?: {
|
|
94
94
|
message: string;
|
|
95
95
|
timeout: number;
|
|
96
96
|
maxTimeoutCount: number;
|
|
97
|
-
} |
|
|
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.
|
|
300
|
+
initialDtmf: z.ZodOptional<z.ZodString>;
|
|
301
301
|
maxSpeechWaitTimeout: z.ZodNumber;
|
|
302
|
-
transferOptions: z.
|
|
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.
|
|
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 |
|
|
356
|
+
initialDtmf?: string | undefined;
|
|
357
357
|
transferOptions?: {
|
|
358
358
|
message: string;
|
|
359
359
|
phoneNumber: string;
|
|
360
360
|
timeout?: number | undefined;
|
|
361
|
-
} |
|
|
361
|
+
} | undefined;
|
|
362
362
|
idleOptions?: {
|
|
363
363
|
message: string;
|
|
364
364
|
timeout: number;
|
|
365
365
|
maxTimeoutCount: number;
|
|
366
|
-
} |
|
|
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 |
|
|
379
|
+
initialDtmf?: string | undefined;
|
|
380
380
|
transferOptions?: {
|
|
381
381
|
message: string;
|
|
382
382
|
phoneNumber: string;
|
|
383
383
|
timeout?: number | undefined;
|
|
384
|
-
} |
|
|
384
|
+
} | undefined;
|
|
385
385
|
idleOptions?: {
|
|
386
386
|
message: string;
|
|
387
387
|
timeout: number;
|
|
388
388
|
maxTimeoutCount: number;
|
|
389
|
-
} |
|
|
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 |
|
|
599
|
+
initialDtmf?: string | undefined;
|
|
600
600
|
transferOptions?: {
|
|
601
601
|
message: string;
|
|
602
602
|
phoneNumber: string;
|
|
603
603
|
timeout?: number | undefined;
|
|
604
|
-
} |
|
|
604
|
+
} | undefined;
|
|
605
605
|
idleOptions?: {
|
|
606
606
|
message: string;
|
|
607
607
|
timeout: number;
|
|
608
608
|
maxTimeoutCount: number;
|
|
609
|
-
} |
|
|
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 |
|
|
657
|
+
initialDtmf?: string | undefined;
|
|
658
658
|
transferOptions?: {
|
|
659
659
|
message: string;
|
|
660
660
|
phoneNumber: string;
|
|
661
661
|
timeout?: number | undefined;
|
|
662
|
-
} |
|
|
662
|
+
} | undefined;
|
|
663
663
|
idleOptions?: {
|
|
664
664
|
message: string;
|
|
665
665
|
timeout: number;
|
|
666
666
|
maxTimeoutCount: number;
|
|
667
|
-
} |
|
|
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
|
|
31
|
-
|
|
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
|
|
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
|
|
44
|
-
|
|
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
|
|
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
|
|
62
|
-
|
|
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
|
});
|
package/dist/assistants/index.js
CHANGED
|
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./loadAndValidateAssistant"), exports);
|
|
18
17
|
/*
|
|
19
18
|
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
20
19
|
* http://github.com/fonoster/fonoster
|
|
@@ -33,4 +32,5 @@ __exportStar(require("./loadAndValidateAssistant"), exports);
|
|
|
33
32
|
* See the License for the specific language governing permissions and
|
|
34
33
|
* limitations under the License.
|
|
35
34
|
*/
|
|
35
|
+
__exportStar(require("./loadAndValidateAssistant"), exports);
|
|
36
36
|
__exportStar(require("./types"), exports);
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.handleVoiceRequest = handleVoiceRequest;
|
|
27
37
|
/*
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.loadAssistantConfig = loadAssistantConfig;
|
|
27
37
|
/*
|
|
@@ -158,7 +158,6 @@ declare const machine: import("xstate").StateMachine<AutopilotContext, {
|
|
|
158
158
|
maxIdleTimeoutCount: number;
|
|
159
159
|
idleTimeoutCount: number;
|
|
160
160
|
maxSpeechWaitTimeout: number;
|
|
161
|
-
speechResponseStartTime: number;
|
|
162
161
|
speechResponseTime: number;
|
|
163
162
|
isSpeaking: false;
|
|
164
163
|
};
|
package/dist/machine/machine.js
CHANGED
|
@@ -19,7 +19,6 @@ exports.machine = void 0;
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
-
const perf_hooks_1 = require("perf_hooks");
|
|
23
22
|
const logger_1 = require("@fonoster/logger");
|
|
24
23
|
const xstate_1 = require("xstate");
|
|
25
24
|
const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
|
|
@@ -135,18 +134,11 @@ const machine = (0, xstate_1.setup)({
|
|
|
135
134
|
logger.verbose("called processUserRequest action", {
|
|
136
135
|
speechBuffer: context.speechBuffer
|
|
137
136
|
});
|
|
138
|
-
context.speechResponseStartTime = perf_hooks_1.performance.now();
|
|
139
137
|
// Stop any speech that might be playing
|
|
140
138
|
context.voice.stopSpeech();
|
|
141
139
|
const languageModel = context.languageModel;
|
|
142
140
|
const speech = context.speechBuffer.trim();
|
|
143
141
|
const response = await languageModel.invoke(speech);
|
|
144
|
-
const speechResponseTime = perf_hooks_1.performance.now() - context.speechResponseStartTime;
|
|
145
|
-
context.speechResponseTime = Math.round(speechResponseTime);
|
|
146
|
-
context.speechResponseStartTime = 0;
|
|
147
|
-
logger.verbose("response from language model", {
|
|
148
|
-
speechResponseTime
|
|
149
|
-
});
|
|
150
142
|
try {
|
|
151
143
|
if (response.type === "say" && !response.content) {
|
|
152
144
|
logger.verbose("call might already be hung up");
|
|
@@ -164,6 +156,7 @@ const machine = (0, xstate_1.setup)({
|
|
|
164
156
|
});
|
|
165
157
|
const message = context.transferMessage;
|
|
166
158
|
await context.voice.say(message);
|
|
159
|
+
await context.voice.stopStreams();
|
|
167
160
|
await context.voice.transfer(context.transferPhoneNumber, {
|
|
168
161
|
record: true,
|
|
169
162
|
timeout: 30
|
|
@@ -196,7 +189,6 @@ const machine = (0, xstate_1.setup)({
|
|
|
196
189
|
maxIdleTimeoutCount: input.conversationSettings.idleOptions?.maxTimeoutCount || 3,
|
|
197
190
|
idleTimeoutCount: 0,
|
|
198
191
|
maxSpeechWaitTimeout: input.conversationSettings.maxSpeechWaitTimeout,
|
|
199
|
-
speechResponseStartTime: 0,
|
|
200
192
|
speechResponseTime: 0,
|
|
201
193
|
isSpeaking: false
|
|
202
194
|
}),
|
package/dist/machine/types.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.OllamaModel = void 0;
|
|
4
4
|
var OllamaModel;
|
|
5
5
|
(function (OllamaModel) {
|
|
6
|
-
OllamaModel["
|
|
6
|
+
OllamaModel["LLAMA_3_GROQ_TOOL_USE"] = "llama3-groq-tool-use";
|
|
7
7
|
})(OllamaModel || (exports.OllamaModel = OllamaModel = {}));
|
package/dist/tools/ToolSchema.js
CHANGED
|
@@ -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
|
})
|
package/dist/vad/makeVad.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.makeVad = makeVad;
|
|
27
37
|
/* eslint-disable no-loops/no-loops */
|
package/dist/voice/Voice.d.ts
CHANGED
|
@@ -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 };
|
package/dist/voice/Voice.js
CHANGED
|
@@ -40,7 +40,7 @@ class VoiceImpl {
|
|
|
40
40
|
const stream = await this.voice.sgather({
|
|
41
41
|
source: common_1.StreamGatherSource.SPEECH
|
|
42
42
|
});
|
|
43
|
-
|
|
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
|
-
|
|
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;
|
package/dist/voice/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/autopilot",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.26",
|
|
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.
|
|
39
|
-
"@fonoster/logger": "^0.7.
|
|
40
|
-
"@fonoster/types": "^0.7.
|
|
41
|
-
"@fonoster/voice": "^0.7.
|
|
38
|
+
"@fonoster/common": "^0.7.26",
|
|
39
|
+
"@fonoster/logger": "^0.7.26",
|
|
40
|
+
"@fonoster/types": "^0.7.26",
|
|
41
|
+
"@fonoster/voice": "^0.7.26",
|
|
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": "
|
|
59
|
+
"gitHead": "248493c67d8ef2ba66d3d0426cffc0f3dd49dbeb"
|
|
60
60
|
}
|