@fonoster/autopilot 0.5.4 → 0.7.0

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 (61) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +3 -0
  3. package/dist/Autopilot.d.ts +7 -0
  4. package/dist/Autopilot.js +58 -0
  5. package/dist/assistants/assistants.d.ts +4 -0
  6. package/dist/assistants/assistants.js +39 -0
  7. package/dist/assistants/examples.d.ts +10 -0
  8. package/dist/assistants/examples.js +96 -0
  9. package/dist/assistants/index.d.ts +2 -0
  10. package/dist/{file-retention → assistants}/index.js +7 -4
  11. package/dist/assistants/types.d.ts +13 -0
  12. package/dist/{events → assistants}/types.js +10 -12
  13. package/dist/demo.d.ts +1 -0
  14. package/dist/demo.js +57 -0
  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 +108 -0
  22. package/dist/machine/machine.js +111 -0
  23. package/dist/machine/types.d.ts +21 -0
  24. package/dist/machine/types.js +9 -0
  25. package/dist/types.d.ts +14 -41
  26. package/dist/types.js +0 -7
  27. package/package.json +29 -27
  28. package/dist/cerebro/cerebro.d.ts +0 -42
  29. package/dist/cerebro/cerebro.js +0 -266
  30. package/dist/cerebro/effects.d.ts +0 -11
  31. package/dist/cerebro/effects.js +0 -113
  32. package/dist/cerebro/helper.d.ts +0 -5
  33. package/dist/cerebro/helper.js +0 -43
  34. package/dist/cerebro/index.d.ts +0 -2
  35. package/dist/cerebro/index.js +0 -36
  36. package/dist/cerebro/types.d.ts +0 -40
  37. package/dist/cerebro/types.js +0 -9
  38. package/dist/events/emitter.d.ts +0 -7
  39. package/dist/events/emitter.js +0 -13
  40. package/dist/events/server.d.ts +0 -12
  41. package/dist/events/server.js +0 -67
  42. package/dist/events/types.d.ts +0 -20
  43. package/dist/file-retention/cron.d.ts +0 -2
  44. package/dist/file-retention/cron.js +0 -23
  45. package/dist/file-retention/index.d.ts +0 -1
  46. package/dist/file-retention/task.d.ts +0 -6
  47. package/dist/file-retention/task.js +0 -56
  48. package/dist/intents/df_utils.d.ts +0 -3
  49. package/dist/intents/df_utils.js +0 -39
  50. package/dist/intents/dialogflow_cx.d.ts +0 -43
  51. package/dist/intents/dialogflow_cx.js +0 -102
  52. package/dist/intents/dialogflow_es.d.ts +0 -15
  53. package/dist/intents/dialogflow_es.js +0 -166
  54. package/dist/intents/engines.d.ts +0 -3
  55. package/dist/intents/engines.js +0 -32
  56. package/dist/intents/types.d.ts +0 -25
  57. package/dist/intents/types.js +0 -2
  58. package/dist/pilot.d.ts +0 -3
  59. package/dist/pilot.js +0 -150
  60. package/dist/util.d.ts +0 -44
  61. package/dist/util.js +0 -105
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.machine = void 0;
13
+ /*
14
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
15
+ * http://github.com/fonoster/fonoster
16
+ *
17
+ * This file is part of Fonoster
18
+ *
19
+ * Licensed under the MIT License (the "License");
20
+ * you may not use this file except in compliance with
21
+ * the License. You may obtain a copy of the License at
22
+ *
23
+ * https://opensource.org/licenses/MIT
24
+ *
25
+ * Unless required by applicable law or agreed to in writing, software
26
+ * distributed under the License is distributed on an "AS IS" BASIS,
27
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
+ * See the License for the specific language governing permissions and
29
+ * limitations under the License.
30
+ */
31
+ const logger_1 = require("@fonoster/logger");
32
+ const xstate_1 = require("xstate");
33
+ const types_1 = require("./types");
34
+ const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
35
+ exports.machine = (0, xstate_1.setup)({
36
+ types: types_1.types,
37
+ actions: {
38
+ sendGreeting: function (_a) {
39
+ return __awaiter(this, arguments, void 0, function* ({ context }) {
40
+ yield context.voice.answer();
41
+ yield context.voice.say(context.firstMessage);
42
+ });
43
+ },
44
+ interruptAISpeaking: function () {
45
+ logger.verbose("interruptAISpeaking");
46
+ },
47
+ processHumanRequest: function (_a) {
48
+ return __awaiter(this, arguments, void 0, function* ({ context, event }) {
49
+ const speech = event.speech;
50
+ logger.verbose("human request", { speech });
51
+ const response = yield context.assistant.invoke({
52
+ text: speech
53
+ });
54
+ logger.verbose("assistant response", { response });
55
+ yield context.voice.say(response);
56
+ });
57
+ },
58
+ hangup: function (_a) {
59
+ return __awaiter(this, arguments, void 0, function* ({ context }) {
60
+ yield context.voice.hangup();
61
+ });
62
+ }
63
+ }
64
+ }).createMachine({
65
+ context: ({ input }) => ({
66
+ firstMessage: input.firstMessage,
67
+ voice: input.voice,
68
+ assistant: input.assistant
69
+ }),
70
+ id: "fnAI",
71
+ initial: "welcome",
72
+ states: {
73
+ welcome: {
74
+ always: {
75
+ target: "active"
76
+ },
77
+ entry: {
78
+ type: "sendGreeting"
79
+ },
80
+ description: "The initial state where the AI greets the Human."
81
+ },
82
+ active: {
83
+ on: {
84
+ HUMAN_PROMPT: {
85
+ target: "active",
86
+ actions: {
87
+ type: "processHumanRequest"
88
+ },
89
+ description: "This must be triggered when speech to text ends."
90
+ }
91
+ },
92
+ description: "The state where the AI is actively engaged in conversation."
93
+ },
94
+ humanSpeaking: {
95
+ always: {
96
+ target: "active"
97
+ },
98
+ entry: {
99
+ type: "interruptAISpeaking"
100
+ },
101
+ description: "The state where the AI detects Human speech while it is speaking."
102
+ },
103
+ hangup: {
104
+ type: "final",
105
+ description: "The final state where the AI terminates the conversation due to inactivity.",
106
+ entry: {
107
+ type: "hangup"
108
+ }
109
+ }
110
+ }
111
+ });
@@ -0,0 +1,21 @@
1
+ import { VoiceResponse } from "@fonoster/voice";
2
+ import { Assistant } from "../assistants/assistants";
3
+ declare const types: {
4
+ context: {
5
+ firstMessage: string;
6
+ voice: VoiceResponse;
7
+ assistant: Assistant;
8
+ };
9
+ input: {
10
+ firstMessage: string;
11
+ voice: VoiceResponse;
12
+ assistant: Assistant;
13
+ };
14
+ events: {
15
+ type: "VOICE_DETECTED";
16
+ } | {
17
+ type: "HUMAN_PROMPT";
18
+ speech: string;
19
+ };
20
+ };
21
+ export { types };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.types = void 0;
4
+ const types = {
5
+ context: {},
6
+ input: {},
7
+ events: {}
8
+ };
9
+ exports.types = types;
package/dist/types.d.ts CHANGED
@@ -1,41 +1,14 @@
1
- export interface ServerConfig {
2
- port: number;
3
- defaultLanguageCode: string;
4
- eventsServerEnabled: boolean;
5
- /**
6
- * Enable file retention policy
7
- *
8
- * @default true
9
- */
10
- fileRetentionPolicyEnabled?: boolean;
11
- /**
12
- * Directory where the file retention policy will be executed
13
- *
14
- * @default os.tmpdir()
15
- */
16
- fileRetentionPolicyDirectory?: string;
17
- /**
18
- * Cron expression to run the file retention policy
19
- *
20
- * @default 0 0 * * *
21
- * @see https://crontab.guru/#0_0_*_*_*
22
- */
23
- fileRetentionPolicyCronExpression?: string;
24
- /**
25
- * Max age in hours to keep files
26
- *
27
- * @default 24
28
- */
29
- fileRetentionPolicyMaxAge?: number;
30
- /**
31
- * File extension to be deleted
32
- *
33
- * @default .sln24
34
- */
35
- fileRetentionPolicyExtension?: string;
36
- }
37
- export declare enum TTSVendor {
38
- GOOGLE = "google",
39
- AMAZON = "amazon",
40
- MICROSOFT = "microsoft"
41
- }
1
+ import { VoiceResponse } from "@fonoster/voice";
2
+ import { Model } from "./assistants/types";
3
+ type AutopilotConfig = {
4
+ voice: VoiceResponse;
5
+ firstMessage: string;
6
+ assistantConfig: {
7
+ apiKey: string;
8
+ model: Model;
9
+ temperature: number;
10
+ maxTokens: number;
11
+ systemTemplate: string;
12
+ };
13
+ };
14
+ export { AutopilotConfig };
package/dist/types.js CHANGED
@@ -1,9 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TTSVendor = void 0;
4
- var TTSVendor;
5
- (function (TTSVendor) {
6
- TTSVendor["GOOGLE"] = "google";
7
- TTSVendor["AMAZON"] = "amazon";
8
- TTSVendor["MICROSOFT"] = "microsoft";
9
- })(TTSVendor || (exports.TTSVendor = TTSVendor = {}));
package/package.json CHANGED
@@ -1,41 +1,43 @@
1
1
  {
2
2
  "name": "@fonoster/autopilot",
3
- "version": "0.5.4",
3
+ "version": "0.7.0",
4
+ "description": "Voice AI for the Fonoster platform",
5
+ "author": "Pedro Sanders <psanders@fonoster.com>",
6
+ "homepage": "https://github.com/fonoster/fonoster#readme",
4
7
  "license": "MIT",
5
8
  "main": "dist/index",
6
9
  "types": "dist/index",
7
- "bin": {
8
- "run": "./bin/run",
9
- "rox": "./bin/run"
10
+ "directories": {
11
+ "src": "src",
12
+ "test": "test"
10
13
  },
11
14
  "scripts": {
12
- "build": "tsc --build ./tsconfig.json"
13
- },
14
- "dependencies": {
15
- "@fonoster/apps": "^0.5.4",
16
- "@fonoster/googleasr": "^0.5.4",
17
- "@fonoster/googletts": "^0.5.4",
18
- "@fonoster/logger": "^0.5.4",
19
- "@fonoster/secrets": "^0.5.4",
20
- "@fonoster/voice": "^0.5.4",
21
- "@google-cloud/dialogflow": "^4.3.1",
22
- "@google-cloud/dialogflow-cx": "^2.13.0",
23
- "date-fns": "^2.29.3",
24
- "nanoid": "^3.1.25",
25
- "node-cron": "^3.0.2",
26
- "pb-util": "^1.0.2",
27
- "uuid": "^8.3.2",
28
- "ws": "^8.1.0"
29
- },
30
- "devDependencies": {
31
- "@types/ws": "^7.4.7"
15
+ "prebuild": "rimraf ./dist tsconfig.tsbuildinfo",
16
+ "build": "tsc -b tsconfig.json",
17
+ "clean": "rimraf ./dist node_modules tsconfig.tsbuildinfo"
32
18
  },
33
19
  "files": [
34
- "/bin",
35
- "/dist"
20
+ "dist"
36
21
  ],
37
22
  "publishConfig": {
38
23
  "access": "public"
39
24
  },
40
- "gitHead": "a1dae664944ab191e925e49346e0916f8c8347a1"
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/fonoster/fonoster.git"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/fonoster/fonoster/issues"
31
+ },
32
+ "dependencies": {
33
+ "@fonoster/logger": "^0.7.0",
34
+ "@fonoster/voice": "^0.7.0",
35
+ "@langchain/openai": "^0.2.7",
36
+ "dotenv": "^16.4.5",
37
+ "xstate": "^5.17.3"
38
+ },
39
+ "devDependencies": {
40
+ "typescript": "^5.5.4"
41
+ },
42
+ "gitHead": "afa950ace3b1d022b6dc8be0c3b87a6b8a5ba3c5"
41
43
  }
@@ -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
- }