@fonoster/autopilot 0.5.5 → 0.7.2

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.
Files changed (73) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +3 -0
  3. package/dist/Autopilot.d.ts +15 -0
  4. package/dist/Autopilot.js +86 -0
  5. package/dist/assistants/AssistantSchema.d.ts +25 -0
  6. package/dist/assistants/AssistantSchema.js +32 -0
  7. package/dist/assistants/assistants.d.ts +4 -0
  8. package/dist/assistants/assistants.js +39 -0
  9. package/dist/assistants/index.d.ts +4 -0
  10. package/dist/{cerebro → assistants}/index.js +10 -5
  11. package/dist/assistants/loadAndValidateAssistant.d.ts +3 -0
  12. package/dist/assistants/loadAndValidateAssistant.js +46 -0
  13. package/dist/assistants/types.d.ts +17 -0
  14. package/dist/{events → assistants}/types.js +10 -12
  15. package/dist/envs.d.ts +1 -4
  16. package/dist/envs.js +11 -8
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +4 -11
  19. package/dist/machine/index.d.ts +1 -0
  20. package/dist/machine/index.js +23 -0
  21. package/dist/machine/machine.d.ts +163 -0
  22. package/dist/machine/machine.js +142 -0
  23. package/dist/machine/types.d.ts +29 -0
  24. package/dist/machine/types.js +9 -0
  25. package/dist/runner.d.ts +2 -0
  26. package/dist/runner.js +46 -0
  27. package/dist/types.d.ts +7 -41
  28. package/dist/types.js +0 -7
  29. package/dist/vad/SileroVadModel.d.ts +15 -0
  30. package/dist/vad/SileroVadModel.js +65 -0
  31. package/dist/vad/chunkToFloat32Array.d.ts +2 -0
  32. package/dist/vad/chunkToFloat32Array.js +25 -0
  33. package/dist/vad/index.d.ts +3 -0
  34. package/dist/{file-retention → vad}/index.js +7 -4
  35. package/dist/vad/makeVad.d.ts +2 -0
  36. package/dist/vad/makeVad.js +83 -0
  37. package/dist/vad/micVadTest.d.ts +1 -0
  38. package/dist/vad/micVadTest.js +48 -0
  39. package/dist/vad/types.d.ts +17 -0
  40. package/package.json +34 -28
  41. package/dist/cerebro/cerebro.d.ts +0 -42
  42. package/dist/cerebro/cerebro.js +0 -266
  43. package/dist/cerebro/effects.d.ts +0 -11
  44. package/dist/cerebro/effects.js +0 -113
  45. package/dist/cerebro/helper.d.ts +0 -5
  46. package/dist/cerebro/helper.js +0 -43
  47. package/dist/cerebro/index.d.ts +0 -2
  48. package/dist/cerebro/types.d.ts +0 -40
  49. package/dist/cerebro/types.js +0 -9
  50. package/dist/events/emitter.d.ts +0 -7
  51. package/dist/events/emitter.js +0 -13
  52. package/dist/events/server.d.ts +0 -12
  53. package/dist/events/server.js +0 -67
  54. package/dist/events/types.d.ts +0 -20
  55. package/dist/file-retention/cron.d.ts +0 -2
  56. package/dist/file-retention/cron.js +0 -23
  57. package/dist/file-retention/index.d.ts +0 -1
  58. package/dist/file-retention/task.d.ts +0 -6
  59. package/dist/file-retention/task.js +0 -56
  60. package/dist/intents/df_utils.d.ts +0 -3
  61. package/dist/intents/df_utils.js +0 -39
  62. package/dist/intents/dialogflow_cx.d.ts +0 -43
  63. package/dist/intents/dialogflow_cx.js +0 -102
  64. package/dist/intents/dialogflow_es.d.ts +0 -15
  65. package/dist/intents/dialogflow_es.js +0 -166
  66. package/dist/intents/engines.d.ts +0 -3
  67. package/dist/intents/engines.js +0 -32
  68. package/dist/intents/types.d.ts +0 -25
  69. package/dist/pilot.d.ts +0 -3
  70. package/dist/pilot.js +0 -150
  71. package/dist/util.d.ts +0 -44
  72. package/dist/util.js +0 -105
  73. /package/dist/{intents → vad}/types.js +0 -0
@@ -1,42 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { EffectsManager } from "./effects";
4
- import { Intent, IntentsEngine } from "../intents/types";
5
- import { SGatherStream, VoiceRequest, VoiceResponse } from "@fonoster/voice";
6
- import { CerebroConfig, CerebroStatus } from "./types";
7
- import Events from "events";
8
- export declare class Cerebro {
9
- voiceResponse: VoiceResponse;
10
- cerebroEvents: Events;
11
- voiceRequest: VoiceRequest;
12
- status: CerebroStatus;
13
- activationTimeout: number;
14
- maxIteractionsBeforeHangup: number;
15
- failedInteractions: number;
16
- activeTimer: NodeJS.Timer;
17
- interactionTimer: NodeJS.Timer;
18
- intentsEngine: IntentsEngine;
19
- stream: SGatherStream;
20
- config: CerebroConfig;
21
- lastIntent: Intent;
22
- effects: EffectsManager;
23
- interactionsTimer: NodeJS.Timeout;
24
- isCallHandover: boolean;
25
- isDead: boolean;
26
- constructor(config: CerebroConfig);
27
- wake(): Promise<void>;
28
- sleep(): Promise<void>;
29
- startActiveTimer(): void;
30
- resetActiveTimer(): void;
31
- /**
32
- * Start the interactions timer
33
- * If the user doesn't say anything we should play the welcome message
34
- * If it gets played twice many times we should hangup
35
- * If the user says something we should reset the timer
36
- * If we just finish an effect we should reset the timer
37
- */
38
- startInteractionTimer(): void;
39
- resetInteractionTimer(): void;
40
- stopPlayback(): Promise<void>;
41
- cleanup(): Promise<void>;
42
- }
@@ -1,266 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Cerebro = void 0;
7
- /* eslint-disable require-jsdoc */
8
- /*
9
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
10
- * http://github.com/fonoster/rox
11
- *
12
- * This file is part of Rox AI
13
- *
14
- * Licensed under the MIT License (the "License");
15
- * you may not use this file except in compliance with
16
- * the License. You may obtain a copy of the License at
17
- *
18
- * https://opensource.org/licenses/MIT
19
- *
20
- * Unless required by applicable law or agreed to in writing, software
21
- * distributed under the License is distributed on an "AS IS" BASIS,
22
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
- * See the License for the specific language governing permissions and
24
- * limitations under the License.
25
- */
26
- const effects_1 = require("./effects");
27
- const types_1 = require("./types");
28
- const util_1 = require("../util");
29
- const types_2 = require("../events/types");
30
- const logger_1 = require("@fonoster/logger");
31
- const events_1 = __importDefault(require("events"));
32
- const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
33
- class Cerebro {
34
- voiceResponse;
35
- cerebroEvents;
36
- voiceRequest;
37
- status;
38
- activationTimeout;
39
- maxIteractionsBeforeHangup = 2;
40
- failedInteractions = 0;
41
- activeTimer;
42
- interactionTimer;
43
- intentsEngine;
44
- stream;
45
- config;
46
- lastIntent;
47
- effects;
48
- interactionsTimer;
49
- isCallHandover = false;
50
- isDead = false;
51
- constructor(config) {
52
- this.voiceResponse = config.voiceResponse;
53
- this.voiceRequest = config.voiceRequest;
54
- this.cerebroEvents = new events_1.default();
55
- this.status = types_1.CerebroStatus.SLEEP;
56
- this.activationTimeout = config.activationTimeout || 15000;
57
- this.intentsEngine = config.intentsEngine;
58
- this.effects = new effects_1.EffectsManager({
59
- playbackId: config.voiceConfig.playbackId,
60
- eventsClient: config.eventsClient,
61
- voice: config.voiceResponse,
62
- voiceConfig: config.voiceConfig,
63
- activationIntentId: config.activationIntentId,
64
- transfer: config.transfer
65
- });
66
- this.config = config;
67
- }
68
- // Subscribe to events
69
- async wake() {
70
- this.status = types_1.CerebroStatus.AWAKE_PASSIVE;
71
- // This timer becomes active only if we don't have an activation intent
72
- if (!this.config.activationIntentId) {
73
- this.startInteractionTimer();
74
- }
75
- this.voiceResponse.on("error", (error) => {
76
- this.cerebroEvents.emit("error", error);
77
- (0, logger_1.ulogger)({
78
- accessKeyId: this.voiceRequest.accessKeyId,
79
- eventType: logger_1.ULogType.APP,
80
- level: "error",
81
- message: error.message
82
- });
83
- });
84
- const speechConfig = { source: "speech,dtmf" };
85
- if (this.config.alternativeLanguageCode) {
86
- speechConfig.model = "command_and_search";
87
- speechConfig.alternativeLanguageCodes = [
88
- this.config.alternativeLanguageCode
89
- ];
90
- }
91
- this.stream = await this.voiceResponse.sgather(speechConfig);
92
- this.stream.on("transcript", async (data) => {
93
- if (data.isFinal && data.transcript) {
94
- logger.verbose("clear interactions timer", {
95
- sessionId: this.voiceRequest.sessionId
96
- });
97
- clearTimeout(this.interactionsTimer);
98
- const intent = await this.intentsEngine.findIntent(data.transcript, {
99
- telephony: {
100
- caller_id: this.voiceRequest.callerNumber
101
- }
102
- });
103
- logger.verbose("cerebro received new transcription from user", {
104
- sessionId: this.voiceRequest.sessionId,
105
- text: data.transcript,
106
- ref: intent.ref,
107
- confidence: intent.confidence
108
- });
109
- if (intent.effects.find((e) => e.type === "hangup") ||
110
- intent.effects.find((e) => e.type === "transfer")) {
111
- logger.verbose("call hand over: stop all the timers and close the stream", {
112
- sessionId: this.voiceRequest.sessionId
113
- });
114
- clearTimeout(this.activeTimer);
115
- clearTimeout(this.interactionsTimer);
116
- this.voiceResponse.closeMediaPipe();
117
- this.isCallHandover = true;
118
- }
119
- await this.effects.invokeEffects(intent, this.status, async () => {
120
- await this.stopPlayback();
121
- if (this.config.activationIntentId === intent.ref) {
122
- (0, util_1.sendClientEvent)(this.config.eventsClient, {
123
- eventName: types_2.CLIENT_EVENTS.RECOGNIZING
124
- });
125
- if (this.status === types_1.CerebroStatus.AWAKE_ACTIVE) {
126
- this.resetActiveTimer();
127
- }
128
- else {
129
- this.startActiveTimer();
130
- }
131
- }
132
- }, () => {
133
- logger.verbose("invokeEffects cleanup callback", {
134
- sessionId: this.voiceRequest.sessionId
135
- });
136
- this.cleanup();
137
- });
138
- if (this.isDead || this.isCallHandover) {
139
- try {
140
- logger.verbose("the call was handover or cerebro was cleaned up", {
141
- sessionId: this.voiceRequest.sessionId
142
- });
143
- this.voiceResponse.hangup();
144
- }
145
- catch (e) {
146
- // All we can do is try as the call may have already been hung up
147
- }
148
- return;
149
- }
150
- logger.verbose("cerebro finished processing intent effects", {
151
- sessionId: this.voiceRequest.sessionId
152
- });
153
- // Reset the interactions timer
154
- if (!this.config.activationIntentId) {
155
- this.resetInteractionTimer();
156
- }
157
- // WARNING: It doesn't appear that we are using this anywhere
158
- this.lastIntent = intent;
159
- }
160
- });
161
- }
162
- // Unsubscribe from events
163
- async sleep() {
164
- logger.verbose("cerebro timeout and is going to sleep");
165
- await this.voiceResponse.closeMediaPipe();
166
- this.stream.close();
167
- this.status = types_1.CerebroStatus.SLEEP;
168
- }
169
- startActiveTimer() {
170
- this.status = types_1.CerebroStatus.AWAKE_ACTIVE;
171
- this.activeTimer = setTimeout(() => {
172
- this.status = types_1.CerebroStatus.AWAKE_PASSIVE;
173
- (0, util_1.sendClientEvent)(this.config.eventsClient, {
174
- eventName: types_2.CLIENT_EVENTS.RECOGNIZING_FINISHED
175
- });
176
- logger.verbose("cerebro changed awake status", { status: this.status });
177
- }, this.activationTimeout);
178
- logger.verbose("cerebro changed awake status", { status: this.status });
179
- }
180
- resetActiveTimer() {
181
- logger.verbose("cerebro is reseting awake status");
182
- clearTimeout(this.activeTimer);
183
- this.startActiveTimer();
184
- }
185
- /**
186
- * Start the interactions timer
187
- * If the user doesn't say anything we should play the welcome message
188
- * If it gets played twice many times we should hangup
189
- * If the user says something we should reset the timer
190
- * If we just finish an effect we should reset the timer
191
- */
192
- startInteractionTimer() {
193
- logger.verbose("cerebro is starting interactions timer", {
194
- sessionId: this.voiceRequest.sessionId
195
- });
196
- this.interactionsTimer = setInterval(async () => {
197
- this.failedInteractions++;
198
- logger.verbose("cerebro is counting interactions", {
199
- sessionId: this.voiceRequest.sessionId,
200
- failedInteractions: this.failedInteractions
201
- });
202
- // Fix hard coded intent
203
- let intentId = "welcome";
204
- if (this.failedInteractions >= this.maxIteractionsBeforeHangup) {
205
- logger.verbose("there was no interaction so for a long time so we hangup", {
206
- sessionId: this.voiceRequest.sessionId
207
- });
208
- // Fix hard coded intent
209
- intentId = "goodbye";
210
- clearTimeout(this.interactionsTimer);
211
- }
212
- const intent = await this.intentsEngine.findIntentWithEvent(intentId, {
213
- telephony: {
214
- caller_id: this.voiceRequest.callerNumber
215
- }
216
- });
217
- await this.effects.invokeEffects(intent, this.status, () => {
218
- logger.verbose("invokeEffects callback", {
219
- sessionId: this.voiceRequest.sessionId
220
- });
221
- }, () => {
222
- logger.verbose("invokeEffects cleanup callback", {
223
- sessionId: this.voiceRequest.sessionId
224
- });
225
- this.cleanup();
226
- });
227
- }, this.activationTimeout);
228
- }
229
- resetInteractionTimer() {
230
- logger.verbose("cerebro is reseting interactions timer", {
231
- sessionId: this.voiceRequest.sessionId
232
- });
233
- // Reset the failed interactions timer
234
- this.failedInteractions = 0;
235
- clearTimeout(this.interactionsTimer);
236
- this.startInteractionTimer();
237
- }
238
- async stopPlayback() {
239
- const { playbackId } = this.config.voiceConfig;
240
- if (playbackId) {
241
- try {
242
- const playbackControl = this.voiceResponse.playback(playbackId);
243
- logger.verbose("cerebro is stoping playback", { playbackId });
244
- await playbackControl.stop();
245
- }
246
- catch (e) {
247
- (0, logger_1.ulogger)({
248
- accessKeyId: this.voiceRequest.accessKeyId,
249
- eventType: logger_1.ULogType.APP,
250
- level: "error",
251
- message: e.message
252
- });
253
- }
254
- }
255
- }
256
- // Cleanup all timers and events
257
- async cleanup() {
258
- this.isDead = true;
259
- await this.voiceResponse.closeMediaPipe();
260
- this.stream.close();
261
- this.cerebroEvents.removeAllListeners();
262
- clearTimeout(this.activeTimer);
263
- clearTimeout(this.interactionsTimer);
264
- }
265
- }
266
- exports.Cerebro = Cerebro;
@@ -1,11 +0,0 @@
1
- import { VoiceResponse } from "@fonoster/voice";
2
- import { Intent } from "../intents/types";
3
- import { EffectsManagerConfig, CerebroStatus, Effect } from "./types";
4
- export declare class EffectsManager {
5
- voice: VoiceResponse;
6
- config: EffectsManagerConfig;
7
- constructor(config: EffectsManagerConfig);
8
- invokeEffects(intent: Intent, status: CerebroStatus, activateCallback: () => void, cleanupCallback: () => void): Promise<void>;
9
- run(effect: Effect): Promise<void>;
10
- transferEffect(effect: Effect): Promise<void>;
11
- }
@@ -1,113 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EffectsManager = void 0;
4
- const nanoid_1 = require("nanoid");
5
- const helper_1 = require("./helper");
6
- const types_1 = require("./types");
7
- const util_1 = require("../util");
8
- const types_2 = require("../events/types");
9
- const logger_1 = require("@fonoster/logger");
10
- const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
11
- class EffectsManager {
12
- voice;
13
- config;
14
- constructor(config) {
15
- this.voice = config.voice;
16
- this.config = config;
17
- }
18
- async invokeEffects(intent, status, activateCallback, cleanupCallback) {
19
- activateCallback();
20
- logger.verbose("intent received", { intentRef: intent.ref });
21
- if (this.config.activationIntentId === intent.ref) {
22
- logger.verbose("fired activation intent");
23
- return;
24
- }
25
- else if (this.config.activationIntentId &&
26
- status != types_1.CerebroStatus.AWAKE_ACTIVE) {
27
- logger.verbose("received an intent but cerebro is not awake");
28
- // If we have activation intent cerebro needs and active status
29
- // before we can have any effects
30
- return;
31
- }
32
- // eslint-disable-next-line no-loops/no-loops
33
- for (const e of intent.effects) {
34
- try {
35
- logger.verbose("effects running", { type: e.type });
36
- await this.run(e);
37
- }
38
- catch (e) {
39
- const axiosError = e;
40
- if (axiosError.response?.status !== 404) {
41
- logger.error("error running effect", { error: e });
42
- return;
43
- }
44
- cleanupCallback();
45
- }
46
- }
47
- }
48
- async run(effect) {
49
- switch (effect.type) {
50
- case "say":
51
- await this.voice.say(effect.parameters["response"], this.config.voiceConfig);
52
- break;
53
- case "hangup":
54
- await this.voice.hangup();
55
- (0, util_1.sendClientEvent)(this.config.eventsClient, {
56
- eventName: types_2.CLIENT_EVENTS.HANGUP
57
- });
58
- break;
59
- case "transfer":
60
- // TODO: Add record effect
61
- await this.transferEffect(effect);
62
- break;
63
- case "send_data":
64
- // Only send if client support events
65
- (0, util_1.sendClientEvent)(this.config.eventsClient, {
66
- eventName: types_2.CLIENT_EVENTS.RECOGNIZING_FINISHED
67
- });
68
- (0, util_1.sendClientEvent)(this.config.eventsClient, {
69
- eventName: types_2.CLIENT_EVENTS.INTENT,
70
- intent: effect.parameters
71
- });
72
- break;
73
- default:
74
- throw new Error(`effects received unknown effect ${effect.type}`);
75
- }
76
- }
77
- async transferEffect(effect) {
78
- await this.voice.closeMediaPipe();
79
- const stream = await this.voice.dial(effect.parameters["destination"]);
80
- const playbackId = (0, nanoid_1.nanoid)();
81
- const control = this.voice.playback(playbackId);
82
- let stay = true;
83
- const moveForward = async () => {
84
- stay = false;
85
- await control.stop();
86
- };
87
- stream.on("answer", () => {
88
- logger.verbose("call answered", {
89
- destination: effect.parameters["destination"]
90
- });
91
- moveForward();
92
- });
93
- stream.on("busy", async () => {
94
- logger.verbose("call busy", {
95
- destination: effect.parameters["destination"]
96
- });
97
- await moveForward();
98
- await (0, helper_1.playBusyAndHangup)(this.voice, playbackId, this.config);
99
- });
100
- stream.on("noanswer", async () => {
101
- logger.verbose("call no answer", {
102
- destination: effect.parameters["destination"]
103
- });
104
- await moveForward();
105
- await (0, helper_1.playNoAnswerAndHangup)(this.voice, playbackId, this.config);
106
- });
107
- // eslint-disable-next-line no-loops/no-loops
108
- while (stay) {
109
- await (0, helper_1.playTransfering)(this.voice, playbackId, this.config);
110
- }
111
- }
112
- }
113
- exports.EffectsManager = EffectsManager;
@@ -1,5 +0,0 @@
1
- import { VoiceResponse } from "@fonoster/voice";
2
- import { EffectsManagerConfig } from "./types";
3
- export declare const playTransfering: (voice: VoiceResponse, playbackId: string, config: EffectsManagerConfig) => Promise<void>;
4
- export declare const playBusyAndHangup: (voice: VoiceResponse, playbackId: string, config: EffectsManagerConfig) => Promise<void>;
5
- export declare const playNoAnswerAndHangup: (voice: VoiceResponse, playbackId: string, config: EffectsManagerConfig) => Promise<void>;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.playNoAnswerAndHangup = exports.playBusyAndHangup = exports.playTransfering = void 0;
4
- const playOrSay = async (param) => {
5
- if (param.media) {
6
- await param.voice.play("sound:" + param.media, {
7
- playbackId: param.playbackId
8
- });
9
- }
10
- if (param.message) {
11
- if (param.voiceConfig) {
12
- param.voiceConfig.playbackId = param.playbackId;
13
- }
14
- else {
15
- param.voiceConfig = { playbackId: param.playbackId };
16
- }
17
- await param.voice.say(param.message, param.voiceConfig);
18
- }
19
- };
20
- const playTransfering = async (voice, playbackId, config) => await playOrSay({
21
- voice,
22
- voiceConfig: config.voiceConfig,
23
- playbackId,
24
- media: config.transfer?.media,
25
- message: config.transfer?.message
26
- });
27
- exports.playTransfering = playTransfering;
28
- const playBusyAndHangup = async (voice, playbackId, config) => await playOrSay({
29
- voice,
30
- voiceConfig: config.voiceConfig,
31
- playbackId,
32
- media: config.transfer?.mediaBusy,
33
- message: config.transfer?.messageBusy
34
- });
35
- exports.playBusyAndHangup = playBusyAndHangup;
36
- const playNoAnswerAndHangup = async (voice, playbackId, config) => await playOrSay({
37
- voice,
38
- voiceConfig: config.voiceConfig,
39
- playbackId,
40
- media: config.transfer?.mediaNoAnswer,
41
- message: config.transfer?.messageNoAnswer
42
- });
43
- exports.playNoAnswerAndHangup = playNoAnswerAndHangup;
@@ -1,2 +0,0 @@
1
- export * from "./cerebro";
2
- export * from "./effects";
@@ -1,40 +0,0 @@
1
- import { VoiceResponse } from "@fonoster/voice";
2
- import { VoiceRequest } from "@fonoster/voice/dist/types";
3
- import { EventsClient } from "../events/emitter";
4
- import { IntentsEngine } from "../intents/types";
5
- export declare enum CerebroStatus {
6
- SLEEP = 0,
7
- AWAKE_ACTIVE = 1,
8
- AWAKE_PASSIVE = 2
9
- }
10
- export interface CerebroConfig {
11
- voiceRequest: VoiceRequest;
12
- voiceResponse: VoiceResponse;
13
- activationTimeout?: number;
14
- activationIntentId?: string;
15
- intentsEngine: IntentsEngine;
16
- voiceConfig: Record<string, string | string[]>;
17
- eventsClient: EventsClient | null;
18
- transfer?: Transfer;
19
- alternativeLanguageCode?: string;
20
- }
21
- export interface Transfer {
22
- media?: string;
23
- mediaNoAnswer?: string;
24
- mediaBusy?: string;
25
- message?: string;
26
- messageNoAnswer?: string;
27
- messageBusy?: string;
28
- }
29
- export interface EffectsManagerConfig {
30
- eventsClient: EventsClient | null;
31
- voice: VoiceResponse;
32
- voiceConfig: Record<string, unknown>;
33
- activationIntentId?: string;
34
- playbackId: string;
35
- transfer?: Transfer;
36
- }
37
- export interface Effect {
38
- type: "say" | "hangup" | "send_data" | "transfer";
39
- parameters: Record<string, unknown>;
40
- }
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CerebroStatus = void 0;
4
- var CerebroStatus;
5
- (function (CerebroStatus) {
6
- CerebroStatus[CerebroStatus["SLEEP"] = 0] = "SLEEP";
7
- CerebroStatus[CerebroStatus["AWAKE_ACTIVE"] = 1] = "AWAKE_ACTIVE";
8
- CerebroStatus[CerebroStatus["AWAKE_PASSIVE"] = 2] = "AWAKE_PASSIVE";
9
- })(CerebroStatus || (exports.CerebroStatus = CerebroStatus = {}));
@@ -1,7 +0,0 @@
1
- import { EventEmitter, ClientEvent } from "./types";
2
- import WebSocket = require("ws");
3
- export declare class EventsClient implements EventEmitter {
4
- ws: WebSocket;
5
- constructor(ws: WebSocket);
6
- send(event: ClientEvent): void;
7
- }
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EventsClient = void 0;
4
- class EventsClient {
5
- ws;
6
- constructor(ws) {
7
- this.ws = ws;
8
- }
9
- send(event) {
10
- this.ws.send(JSON.stringify(event));
11
- }
12
- }
13
- exports.EventsClient = EventsClient;
@@ -1,12 +0,0 @@
1
- import { EventsClient } from "./emitter";
2
- import WebSocket = require("ws");
3
- export declare class EventsServer {
4
- clientConnections: Map<string, WebSocket>;
5
- wss: WebSocket.Server;
6
- port: number;
7
- constructor(clientConnections: Map<string, WebSocket>, port?: number);
8
- start(): void;
9
- getConnection(clientId: string): EventsClient | null;
10
- removeConnection(clientId: string): void;
11
- }
12
- export declare const eventsServer: EventsServer;
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.eventsServer = exports.EventsServer = void 0;
4
- /* eslint-disable require-jsdoc */
5
- /*
6
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
7
- * http://github.com/fonoster/rox
8
- *
9
- * This file is part of Rox AI
10
- *
11
- * Licensed under the MIT License (the "License");
12
- * you may not use this file except in compliance with
13
- * the License. You may obtain a copy of the License at
14
- *
15
- * https://opensource.org/licenses/MIT
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- */
23
- const emitter_1 = require("./emitter");
24
- const logger_1 = require("@fonoster/logger");
25
- const WebSocket = require("ws");
26
- const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
27
- // Events server
28
- class EventsServer {
29
- clientConnections;
30
- wss;
31
- port;
32
- constructor(clientConnections, port = 3001) {
33
- this.port = port;
34
- this.wss = new WebSocket.Server({ port });
35
- this.clientConnections = clientConnections;
36
- }
37
- start() {
38
- this.wss.on("connection", (ws) => {
39
- logger.verbose("received a new client connection");
40
- ws.on("message", (data) => {
41
- // Once we receive the first and only message from client we
42
- // save the client in the clientConnections map
43
- const clientId = JSON.parse(data.toString()).clientId;
44
- this.clientConnections.set(clientId, ws);
45
- logger.verbose("added clientId to list of connections", { clientId });
46
- });
47
- ws.send(JSON.stringify({
48
- name: "connected",
49
- payload: {}
50
- }));
51
- });
52
- logger.verbose("starting events server", { port: this.port });
53
- }
54
- getConnection(clientId) {
55
- const connection = this.clientConnections.get(clientId);
56
- if (!connection) {
57
- return null;
58
- }
59
- return new emitter_1.EventsClient(connection);
60
- }
61
- removeConnection(clientId) {
62
- this.clientConnections.delete(clientId);
63
- }
64
- }
65
- exports.EventsServer = EventsServer;
66
- // Starting events server
67
- exports.eventsServer = new EventsServer(new Map());
@@ -1,20 +0,0 @@
1
- export declare enum CLIENT_EVENTS {
2
- RECOGNIZING = "RECOGNIZING",
3
- ANSWERED = "ANSWERED",
4
- RECOGNIZING_FINISHED = "RECOGNIZING_FINISHED",
5
- INTENT = "INTENT",
6
- HANGUP = "HANGUP"
7
- }
8
- export interface EventEmitter {
9
- send(payload?: ClientEvent): void;
10
- }
11
- export interface Intent {
12
- icon?: string;
13
- title: string;
14
- description: string;
15
- transcript: string;
16
- }
17
- export interface ClientEvent {
18
- eventName: CLIENT_EVENTS;
19
- intent?: Intent;
20
- }
@@ -1,2 +0,0 @@
1
- import { ServerConfig } from "../types";
2
- export declare const startFileRetentionPolicy: (config: ServerConfig) => void;