@fonoster/autopilot 0.27.0 → 0.31.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 (153) hide show
  1. package/README.md +15 -52
  2. package/dist/index.d.ts +0 -5
  3. package/dist/index.js +0 -5
  4. package/dist/knowledge/AbstractKnowledgeBase.d.ts +3 -2
  5. package/dist/knowledge/AbstractKnowledgeBase.js +2 -7
  6. package/dist/knowledge/FilesKnowledgeBase.d.ts +1 -1
  7. package/dist/knowledge/MeteredEmbeddings.d.ts +47 -0
  8. package/dist/knowledge/MeteredEmbeddings.js +58 -0
  9. package/dist/knowledge/types.d.ts +1 -1
  10. package/dist/models/LanguageModelFactory.d.ts +5 -24
  11. package/dist/models/LanguageModelFactory.js +0 -1
  12. package/dist/models/createLanguageModel.d.ts +2 -2
  13. package/dist/models/createLanguageModel.js +2 -2
  14. package/dist/models/evaluations/createEvalEffectiveConfig.d.ts +10 -106
  15. package/dist/models/evaluations/createEvalEffectiveConfig.js +47 -7
  16. package/dist/models/evaluations/createEvaluateIntelligence.d.ts +21 -20
  17. package/dist/models/evaluations/createEvaluateIntelligence.js +53 -23
  18. package/dist/models/evaluations/createTestTextSimilarity.d.ts +7 -1
  19. package/dist/models/evaluations/createTestTextSimilarity.js +19 -1
  20. package/dist/models/evaluations/evalTestCases.d.ts +2 -2
  21. package/dist/models/evaluations/evalTestCases.js +7 -7
  22. package/dist/models/evaluations/evaluateScenario.js +2 -2
  23. package/dist/models/evaluations/evaluateStep.d.ts +1 -1
  24. package/dist/models/evaluations/evaluateStep.js +2 -2
  25. package/dist/models/evaluations/extractAiResponse.d.ts +2 -3
  26. package/dist/models/evaluations/extractAiResponse.js +3 -3
  27. package/dist/models/evaluations/index.d.ts +1 -0
  28. package/dist/models/evaluations/index.js +1 -0
  29. package/dist/models/evaluations/runEval.d.ts +2 -20
  30. package/dist/models/evaluations/runEval.js +7 -7
  31. package/dist/models/evaluations/session/EvalSession.d.ts +73 -0
  32. package/dist/models/evaluations/session/EvalSession.js +134 -0
  33. package/dist/models/evaluations/session/evaluateSessionScenario.d.ts +58 -0
  34. package/dist/models/evaluations/session/evaluateSessionScenario.js +182 -0
  35. package/dist/{vad → models/evaluations/session}/index.d.ts +3 -2
  36. package/dist/{vad → models/evaluations/session}/index.js +3 -2
  37. package/dist/models/evaluations/session/runSessionEval.d.ts +20 -0
  38. package/dist/models/evaluations/session/runSessionEval.js +59 -0
  39. package/dist/models/evaluations/textSimilaryPrompt.d.ts +1 -1
  40. package/dist/models/evaluations/textSimilaryPrompt.js +1 -1
  41. package/dist/models/evaluations/types.d.ts +7 -6
  42. package/dist/models/types.d.ts +19 -1
  43. package/dist/session/Agent.d.ts +173 -0
  44. package/dist/session/Agent.js +548 -0
  45. package/dist/{loadAssistantFromAPI.d.ts → session/AsyncQueue.d.ts} +12 -7
  46. package/dist/session/AsyncQueue.js +67 -0
  47. package/dist/{machine/guards/index.d.ts → session/config.d.ts} +2 -2
  48. package/dist/session/config.js +27 -0
  49. package/dist/session/createAutopilot.d.ts +48 -0
  50. package/dist/session/createAutopilot.js +151 -0
  51. package/dist/session/hosted.d.ts +454 -0
  52. package/dist/session/hosted.js +501 -0
  53. package/dist/{assistants → session}/index.d.ts +11 -2
  54. package/dist/{machine/actors → session}/index.js +11 -3
  55. package/dist/{machine/actions/appendSpeech.js → session/knowledge.d.ts} +14 -17
  56. package/dist/session/knowledge.js +10 -0
  57. package/dist/session/llm.d.ts +113 -0
  58. package/dist/session/llm.js +127 -0
  59. package/dist/session/machine.d.ts +206 -0
  60. package/dist/session/machine.js +126 -0
  61. package/dist/session/main.js +45 -0
  62. package/dist/session/meteredThink.d.ts +45 -0
  63. package/dist/session/meteredThink.js +125 -0
  64. package/dist/session/sentences.d.ts +5 -0
  65. package/dist/session/sentences.js +53 -0
  66. package/dist/session/telemetry.d.ts +34 -0
  67. package/dist/session/telemetry.js +55 -0
  68. package/dist/{machine/actors/index.d.ts → session/think.d.ts} +2 -3
  69. package/dist/{machine/actions/announceSystemError.js → session/think.js} +8 -10
  70. package/dist/session/tools.d.ts +22 -0
  71. package/dist/session/tools.js +83 -0
  72. package/dist/tools/builtin/transferToolDefinition.js +1 -1
  73. package/dist/voice/index.d.ts +0 -1
  74. package/dist/voice/index.js +0 -1
  75. package/dist/voice/types.d.ts +5 -18
  76. package/package.json +15 -16
  77. package/dist/Autopilot.d.ts +0 -14
  78. package/dist/Autopilot.js +0 -133
  79. package/dist/assistants/index.js +0 -36
  80. package/dist/assistants/loadAndValidateAssistant.d.ts +0 -3
  81. package/dist/assistants/loadAndValidateAssistant.js +0 -49
  82. package/dist/assistants/types.d.ts +0 -24
  83. package/dist/assistants/types.js +0 -2
  84. package/dist/envs.d.ts +0 -15
  85. package/dist/envs.js +0 -78
  86. package/dist/handleVoiceRequest.d.ts +0 -3
  87. package/dist/handleVoiceRequest.js +0 -167
  88. package/dist/loadAssistantConfigFromFile.d.ts +0 -3
  89. package/dist/loadAssistantConfigFromFile.js +0 -68
  90. package/dist/loadAssistantFromAPI.js +0 -98
  91. package/dist/machine/actions/announceSystemError.d.ts +0 -4
  92. package/dist/machine/actions/appendSpeech.d.ts +0 -1
  93. package/dist/machine/actions/cleanSpeech.d.ts +0 -1
  94. package/dist/machine/actions/cleanSpeech.js +0 -23
  95. package/dist/machine/actions/goodbye.d.ts +0 -4
  96. package/dist/machine/actions/goodbye.js +0 -31
  97. package/dist/machine/actions/increaseIdleTimeoutCount.d.ts +0 -1
  98. package/dist/machine/actions/increaseIdleTimeoutCount.js +0 -31
  99. package/dist/machine/actions/index.d.ts +0 -26
  100. package/dist/machine/actions/index.js +0 -37
  101. package/dist/machine/actions/interruptPlayback.d.ts +0 -4
  102. package/dist/machine/actions/interruptPlayback.js +0 -43
  103. package/dist/machine/actions/resetIdleTimeoutCount.d.ts +0 -1
  104. package/dist/machine/actions/resetIdleTimeoutCount.js +0 -31
  105. package/dist/machine/actions/resetState.d.ts +0 -1
  106. package/dist/machine/actions/resetState.js +0 -32
  107. package/dist/machine/actors/doAnnounceIdleTimeout.d.ts +0 -4
  108. package/dist/machine/actors/doAnnounceIdleTimeout.js +0 -41
  109. package/dist/machine/actors/doGreetUser.d.ts +0 -4
  110. package/dist/machine/actors/doGreetUser.js +0 -45
  111. package/dist/machine/actors/doProcessUserRequest.d.ts +0 -4
  112. package/dist/machine/actors/doProcessUserRequest.js +0 -75
  113. package/dist/machine/context.d.ts +0 -52
  114. package/dist/machine/context.js +0 -28
  115. package/dist/machine/delays.d.ts +0 -30
  116. package/dist/machine/delays.js +0 -37
  117. package/dist/machine/guards/hasSpeechResult.d.ts +0 -4
  118. package/dist/machine/guards/hasSpeechResult.js +0 -30
  119. package/dist/machine/guards/idleTimeoutCountExceedsMax.d.ts +0 -4
  120. package/dist/machine/guards/idleTimeoutCountExceedsMax.js +0 -31
  121. package/dist/machine/guards/index.js +0 -25
  122. package/dist/machine/index.d.ts +0 -19
  123. package/dist/machine/index.js +0 -23
  124. package/dist/machine/machine.d.ts +0 -408
  125. package/dist/machine/machine.js +0 -206
  126. package/dist/machine/setup.d.ts +0 -328
  127. package/dist/machine/setup.js +0 -116
  128. package/dist/machine/types.d.ts +0 -54
  129. package/dist/machine/types.js +0 -2
  130. package/dist/sendConversationEndedEvent.d.ts +0 -32
  131. package/dist/sendConversationEndedEvent.js +0 -66
  132. package/dist/sendConversationStartedEvent.d.ts +0 -6
  133. package/dist/sendConversationStartedEvent.js +0 -63
  134. package/dist/server.d.ts +0 -2
  135. package/dist/server.js +0 -25
  136. package/dist/types.d.ts +0 -40
  137. package/dist/types.js +0 -8
  138. package/dist/vad/SileroVad.d.ts +0 -18
  139. package/dist/vad/SileroVad.js +0 -40
  140. package/dist/vad/SileroVadModel.d.ts +0 -14
  141. package/dist/vad/SileroVadModel.js +0 -83
  142. package/dist/vad/chunkToFloat32Array.d.ts +0 -20
  143. package/dist/vad/chunkToFloat32Array.js +0 -34
  144. package/dist/vad/createVad.d.ts +0 -3
  145. package/dist/vad/createVad.js +0 -126
  146. package/dist/vad/types.d.ts +0 -60
  147. package/dist/vad/types.js +0 -2
  148. package/dist/vadWorker.js +0 -36
  149. package/dist/voice/Voice.d.ts +0 -61
  150. package/dist/voice/Voice.js +0 -96
  151. package/dist/voiceServerSetup.d.ts +0 -2
  152. package/dist/voiceServerSetup.js +0 -29
  153. /package/dist/{vadWorker.d.ts → session/main.d.ts} +0 -0
@@ -1,98 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
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
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.loadAssistantFromAPI = loadAssistantFromAPI;
37
- /**
38
- * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
39
- * http://github.com/fonoster/fonoster
40
- *
41
- * This file is part of Fonoster
42
- *
43
- * Licensed under the MIT License (the "License");
44
- * you may not use this file except in compliance with
45
- * the License. You may obtain a copy of the License at
46
- *
47
- * https://opensource.org/licenses/MIT
48
- *
49
- * Unless required by applicable law or agreed to in writing, software
50
- * distributed under the License is distributed on an "AS IS" BASIS,
51
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
52
- * See the License for the specific language governing permissions and
53
- * limitations under the License.
54
- */
55
- const common_1 = require("@fonoster/common");
56
- const common_2 = require("@fonoster/common");
57
- const logger_1 = require("@fonoster/logger");
58
- const SDK = __importStar(require("@fonoster/sdk"));
59
- const envs_1 = require("./envs");
60
- const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
61
- function loadAssistantFromAPI(req,
62
- // TODO: Add validation for integrations
63
- integrations) {
64
- return new Promise((resolve, reject) => {
65
- const clientConfig = {
66
- accessKeyId: req.accessKeyId,
67
- endpoint: envs_1.APISERVER_ENDPOINT,
68
- allowInsecure: true,
69
- withoutInterceptors: true
70
- };
71
- const client = new SDK.Client(clientConfig);
72
- client.setAccessToken(req.sessionToken);
73
- const applications = new SDK.Applications(client);
74
- logger.verbose(`loading assistant config from api`, {
75
- apiserver: envs_1.APISERVER_ENDPOINT,
76
- appRef: req.appRef
77
- });
78
- applications
79
- .getApplication(req.appRef)
80
- .then((app) => {
81
- logger.verbose(`get credentials for assistant`, {
82
- appRef: req.appRef,
83
- productRef: app.intelligence.productRef
84
- });
85
- const credentials = (0, common_1.findIntegrationsCredentials)(integrations, app.intelligence.productRef);
86
- resolve(common_2.assistantSchema.parse({
87
- ...app.intelligence.config,
88
- languageModel: {
89
- ...app.intelligence.config.languageModel,
90
- apiKey: credentials.apiKey
91
- }
92
- }));
93
- })
94
- .catch((err) => {
95
- reject(new Error(`Failed to load assistant config from API: ${err}`));
96
- });
97
- });
98
- }
@@ -1,4 +0,0 @@
1
- import { AutopilotContext } from "../types";
2
- export declare const announceSystemError: ({ context }: {
3
- context: AutopilotContext;
4
- }) => Promise<void>;
@@ -1 +0,0 @@
1
- export declare const appendSpeech: import("xstate").ActionFunction<import("xstate").MachineContext, import("xstate").AnyEventObject, import("xstate").EventObject, {}, import("xstate").ProvidedActor, never, never, never, never>;
@@ -1 +0,0 @@
1
- export declare const cleanSpeech: import("xstate").ActionFunction<import("xstate").MachineContext, import("xstate").AnyEventObject, import("xstate").EventObject, {}, import("xstate").ProvidedActor, never, never, never, never>;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cleanSpeech = void 0;
4
- /**
5
- * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
- * http://github.com/fonoster/fonoster
7
- *
8
- * This file is part of Fonoster
9
- *
10
- * Licensed under the MIT License (the "License");
11
- * you may not use this file except in compliance with
12
- * the License. You may obtain a copy of the License at
13
- *
14
- * https://opensource.org/licenses/MIT
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
- const xstate_1 = require("xstate");
23
- exports.cleanSpeech = (0, xstate_1.assign)({ speechBuffer: "" });
@@ -1,4 +0,0 @@
1
- import { AutopilotContext } from "../types";
2
- export declare const goodbye: ({ context }: {
3
- context: AutopilotContext;
4
- }) => Promise<void>;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.goodbye = void 0;
4
- /**
5
- * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
- * http://github.com/fonoster/fonoster
7
- *
8
- * This file is part of Fonoster
9
- *
10
- * Licensed under the MIT License (the "License");
11
- * you may not use this file except in compliance with
12
- * the License. You may obtain a copy of the License at
13
- *
14
- * https://opensource.org/licenses/MIT
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
- const logger_1 = require("@fonoster/logger");
23
- const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
24
- const goodbye = async ({ context }) => {
25
- logger.verbose("called the goodbye action", {
26
- goodbyeMessage: context.goodbyeMessage
27
- });
28
- await context.voice.say(context.goodbyeMessage);
29
- await context.voice.hangup();
30
- };
31
- exports.goodbye = goodbye;
@@ -1 +0,0 @@
1
- export declare const increaseIdleTimeoutCount: import("xstate").ActionFunction<import("xstate").MachineContext, import("xstate").AnyEventObject, import("xstate").EventObject, {}, import("xstate").ProvidedActor, never, never, never, never>;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.increaseIdleTimeoutCount = void 0;
4
- /**
5
- * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
- * http://github.com/fonoster/fonoster
7
- *
8
- * This file is part of Fonoster
9
- *
10
- * Licensed under the MIT License (the "License");
11
- * you may not use this file except in compliance with
12
- * the License. You may obtain a copy of the License at
13
- *
14
- * https://opensource.org/licenses/MIT
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
- const logger_1 = require("@fonoster/logger");
23
- const xstate_1 = require("xstate");
24
- const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
25
- exports.increaseIdleTimeoutCount = (0, xstate_1.assign)(({ context }) => {
26
- logger.verbose("called the increaseIdleTimeoutCount action", {
27
- idleTimeoutCount: context.idleTimeoutCount + 1
28
- });
29
- context.idleTimeoutCount++;
30
- return context;
31
- });
@@ -1,26 +0,0 @@
1
- /**
2
- * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
3
- * http://github.com/fonoster/fonoster
4
- *
5
- * This file is part of Fonoster
6
- *
7
- * Licensed under the MIT License (the "License");
8
- * you may not use this file except in compliance with
9
- * the License. You may obtain a copy of the License at
10
- *
11
- * https://opensource.org/licenses/MIT
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- */
19
- export { goodbye } from "./goodbye";
20
- export { announceSystemError } from "./announceSystemError";
21
- export { interruptPlayback } from "./interruptPlayback";
22
- export { increaseIdleTimeoutCount } from "./increaseIdleTimeoutCount";
23
- export { cleanSpeech } from "./cleanSpeech";
24
- export { appendSpeech } from "./appendSpeech";
25
- export { resetIdleTimeoutCount } from "./resetIdleTimeoutCount";
26
- export { resetState } from "./resetState";
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resetState = exports.resetIdleTimeoutCount = exports.appendSpeech = exports.cleanSpeech = exports.increaseIdleTimeoutCount = exports.interruptPlayback = exports.announceSystemError = exports.goodbye = void 0;
4
- /**
5
- * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
- * http://github.com/fonoster/fonoster
7
- *
8
- * This file is part of Fonoster
9
- *
10
- * Licensed under the MIT License (the "License");
11
- * you may not use this file except in compliance with
12
- * the License. You may obtain a copy of the License at
13
- *
14
- * https://opensource.org/licenses/MIT
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
- var goodbye_1 = require("./goodbye");
23
- Object.defineProperty(exports, "goodbye", { enumerable: true, get: function () { return goodbye_1.goodbye; } });
24
- var announceSystemError_1 = require("./announceSystemError");
25
- Object.defineProperty(exports, "announceSystemError", { enumerable: true, get: function () { return announceSystemError_1.announceSystemError; } });
26
- var interruptPlayback_1 = require("./interruptPlayback");
27
- Object.defineProperty(exports, "interruptPlayback", { enumerable: true, get: function () { return interruptPlayback_1.interruptPlayback; } });
28
- var increaseIdleTimeoutCount_1 = require("./increaseIdleTimeoutCount");
29
- Object.defineProperty(exports, "increaseIdleTimeoutCount", { enumerable: true, get: function () { return increaseIdleTimeoutCount_1.increaseIdleTimeoutCount; } });
30
- var cleanSpeech_1 = require("./cleanSpeech");
31
- Object.defineProperty(exports, "cleanSpeech", { enumerable: true, get: function () { return cleanSpeech_1.cleanSpeech; } });
32
- var appendSpeech_1 = require("./appendSpeech");
33
- Object.defineProperty(exports, "appendSpeech", { enumerable: true, get: function () { return appendSpeech_1.appendSpeech; } });
34
- var resetIdleTimeoutCount_1 = require("./resetIdleTimeoutCount");
35
- Object.defineProperty(exports, "resetIdleTimeoutCount", { enumerable: true, get: function () { return resetIdleTimeoutCount_1.resetIdleTimeoutCount; } });
36
- var resetState_1 = require("./resetState");
37
- Object.defineProperty(exports, "resetState", { enumerable: true, get: function () { return resetState_1.resetState; } });
@@ -1,4 +0,0 @@
1
- import { AutopilotContext } from "../types";
2
- export declare const interruptPlayback: ({ context }: {
3
- context: AutopilotContext;
4
- }) => Promise<void>;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.interruptPlayback = void 0;
4
- /**
5
- * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
- * http://github.com/fonoster/fonoster
7
- *
8
- * This file is part of Fonoster
9
- *
10
- * Licensed under the MIT License (the "License");
11
- * you may not use this file except in compliance with
12
- * the License. You may obtain a copy of the License at
13
- *
14
- * https://opensource.org/licenses/MIT
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
- const logger_1 = require("@fonoster/logger");
23
- const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
24
- const interruptPlayback = async ({ context }) => {
25
- logger.verbose("called the interruptPlayback action", {
26
- mediaSessionRef: context.mediaSessionRef
27
- });
28
- try {
29
- await context.voice.stopSpeech();
30
- }
31
- catch (error) {
32
- // The call may have hung up (or the session otherwise ended) right as we
33
- // asked it to stop speaking, so the underlying verb never gets a
34
- // response and rejects. There's nothing left to interrupt at that point,
35
- // so this is expected and must not escape as an unhandled rejection —
36
- // this action isn't awaited by the state machine.
37
- logger.verbose("stopSpeech failed while interrupting playback", {
38
- mediaSessionRef: context.mediaSessionRef,
39
- error
40
- });
41
- }
42
- };
43
- exports.interruptPlayback = interruptPlayback;
@@ -1 +0,0 @@
1
- export declare const resetIdleTimeoutCount: import("xstate").ActionFunction<import("xstate").MachineContext, import("xstate").AnyEventObject, import("xstate").EventObject, {}, import("xstate").ProvidedActor, never, never, never, never>;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resetIdleTimeoutCount = void 0;
4
- /**
5
- * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
- * http://github.com/fonoster/fonoster
7
- *
8
- * This file is part of Fonoster
9
- *
10
- * Licensed under the MIT License (the "License");
11
- * you may not use this file except in compliance with
12
- * the License. You may obtain a copy of the License at
13
- *
14
- * https://opensource.org/licenses/MIT
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
- const logger_1 = require("@fonoster/logger");
23
- const xstate_1 = require("xstate");
24
- const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
25
- exports.resetIdleTimeoutCount = (0, xstate_1.assign)(({ context }) => {
26
- logger.verbose("called the resetIdleTimeoutCount action", {
27
- idleTimeoutCount: 0
28
- });
29
- context.idleTimeoutCount = 0;
30
- return context;
31
- });
@@ -1 +0,0 @@
1
- export declare const resetState: import("xstate").ActionFunction<import("xstate").MachineContext, import("xstate").AnyEventObject, import("xstate").EventObject, {}, import("xstate").ProvidedActor, never, never, never, never>;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resetState = void 0;
4
- /**
5
- * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
- * http://github.com/fonoster/fonoster
7
- *
8
- * This file is part of Fonoster
9
- *
10
- * Licensed under the MIT License (the "License");
11
- * you may not use this file except in compliance with
12
- * the License. You may obtain a copy of the License at
13
- *
14
- * https://opensource.org/licenses/MIT
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
- const logger_1 = require("@fonoster/logger");
23
- const xstate_1 = require("xstate");
24
- const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
25
- exports.resetState = (0, xstate_1.assign)(({ context }) => {
26
- logger.verbose("called the resetState action");
27
- return {
28
- ...context,
29
- speechBuffer: "",
30
- idleTimeoutCount: 0
31
- };
32
- });
@@ -1,4 +0,0 @@
1
- import { AutopilotContext } from "../types";
2
- export declare const doAnnounceIdleTimeout: import("xstate").PromiseActorLogic<void, {
3
- context: AutopilotContext;
4
- }, import("xstate").EventObject>;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.doAnnounceIdleTimeout = void 0;
4
- /**
5
- * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
- * http://github.com/fonoster/fonoster
7
- *
8
- * This file is part of Fonoster
9
- *
10
- * Licensed under the MIT License (the "License");
11
- * you may not use this file except in compliance with
12
- * the License. You may obtain a copy of the License at
13
- *
14
- * https://opensource.org/licenses/MIT
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
- const logger_1 = require("@fonoster/logger");
23
- const xstate_1 = require("xstate");
24
- const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
25
- // Invoked (not fired-and-forgotten) so the machine stays in
26
- // "announcingIdleTimeout" until the idle message has been fully played. The
27
- // idle clock is re-armed only when the machine returns to "idle", so the time
28
- // the assistant spends talking never counts as user silence.
29
- exports.doAnnounceIdleTimeout = (0, xstate_1.fromPromise)(async ({ input }) => {
30
- const { context } = input;
31
- logger.verbose("called the doAnnounceIdleTimeout actor", {
32
- idleMessage: context.idleMessage,
33
- idleTimeoutCount: context.idleTimeoutCount
34
- });
35
- try {
36
- await context.voice.say(context.idleMessage);
37
- }
38
- catch (error) {
39
- logger.error("error while announcing the idle timeout", { error });
40
- }
41
- });
@@ -1,4 +0,0 @@
1
- import { AutopilotContext } from "../types";
2
- export declare const doGreetUser: import("xstate").PromiseActorLogic<void, {
3
- context: AutopilotContext;
4
- }, import("xstate").EventObject>;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.doGreetUser = void 0;
4
- /**
5
- * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
- * http://github.com/fonoster/fonoster
7
- *
8
- * This file is part of Fonoster
9
- *
10
- * Licensed under the MIT License (the "License");
11
- * you may not use this file except in compliance with
12
- * the License. You may obtain a copy of the License at
13
- *
14
- * https://opensource.org/licenses/MIT
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
- const logger_1 = require("@fonoster/logger");
23
- const xstate_1 = require("xstate");
24
- const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
25
- // Invoked (not fired-and-forgotten) so the machine stays in "greeting" until
26
- // the first message has been fully played. Otherwise the idle clock would start
27
- // while the assistant is still talking.
28
- exports.doGreetUser = (0, xstate_1.fromPromise)(async ({ input }) => {
29
- const { context } = input;
30
- logger.verbose("called the doGreetUser actor", {
31
- firstMessage: context.firstMessage
32
- });
33
- try {
34
- await context.voice.answer();
35
- if (context.initialDtmf) {
36
- await context.voice.playDtmf(context.initialDtmf);
37
- }
38
- if (context.firstMessage) {
39
- await context.voice.say(context.firstMessage);
40
- }
41
- }
42
- catch (error) {
43
- logger.error("error while greeting the user", { error });
44
- }
45
- });
@@ -1,4 +0,0 @@
1
- import { AutopilotContext } from "../types";
2
- export declare const doProcessUserRequest: import("xstate").PromiseActorLogic<void, {
3
- context: AutopilotContext;
4
- }, import("xstate").EventObject>;
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.doProcessUserRequest = void 0;
4
- /**
5
- * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
- * http://github.com/fonoster/fonoster
7
- *
8
- * This file is part of Fonoster
9
- *
10
- * Licensed under the MIT License (the "License");
11
- * you may not use this file except in compliance with
12
- * the License. You may obtain a copy of the License at
13
- *
14
- * https://opensource.org/licenses/MIT
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
- const logger_1 = require("@fonoster/logger");
23
- const xstate_1 = require("xstate");
24
- const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
25
- exports.doProcessUserRequest = (0, xstate_1.fromPromise)(async ({ input }) => {
26
- const { context } = input;
27
- logger.verbose("called processUserRequest actor", {
28
- speechBuffer: context.speechBuffer,
29
- hasLateSpeech: context.hasLateSpeech
30
- });
31
- // Stop any speech that might be playing. The call may have already hung
32
- // up, in which case the underlying verb rejects because it never gets a
33
- // response - there's nothing left to interrupt, so we swallow it rather
34
- // than let it fail the whole actor.
35
- try {
36
- await context.voice.stopSpeech();
37
- }
38
- catch (error) {
39
- logger.verbose("stopSpeech failed while processing user request", {
40
- mediaSessionRef: context.mediaSessionRef,
41
- error
42
- });
43
- }
44
- const languageModel = context.languageModel;
45
- const speech = context.speechBuffer.trim();
46
- const response = await languageModel.invoke(speech, context.hasLateSpeech);
47
- try {
48
- if (response.type === "say" && !response.content) {
49
- logger.warn("ignoring say response with no content");
50
- return;
51
- }
52
- else if (response.type === "hangup") {
53
- await context.voice.say(context.goodbyeMessage);
54
- await context.voice.hangup();
55
- return;
56
- }
57
- else if (response.type === "transfer") {
58
- logger.verbose("transferring call to a number in the PSTN", {
59
- phoneNumber: context.transferPhoneNumber
60
- });
61
- await context.voice.say(context.transferMessage);
62
- await context.voice.stopStreams();
63
- await context.voice.transfer(context.transferPhoneNumber, {
64
- record: true,
65
- timeout: context.transferTimeout / 1000
66
- });
67
- return;
68
- }
69
- await context.voice.say(response.content);
70
- }
71
- catch (error) {
72
- logger.error("error processing user request", { error });
73
- await context.voice.say(context.systemErrorMessage);
74
- }
75
- });
@@ -1,52 +0,0 @@
1
- /**
2
- * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
3
- * http://github.com/fonoster/fonoster
4
- *
5
- * This file is part of Fonoster
6
- *
7
- * Licensed under the MIT License (the "License");
8
- * you may not use this file except in compliance with
9
- * the License. You may obtain a copy of the License at
10
- *
11
- * https://opensource.org/licenses/MIT
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- */
19
- import { ConversationSettings } from "../assistants";
20
- import { LanguageModel } from "../models";
21
- import { Voice } from "../voice";
22
- declare const context: ({ input }: {
23
- input: {
24
- voice: Voice;
25
- languageModel: LanguageModel;
26
- conversationSettings: ConversationSettings;
27
- };
28
- }) => {
29
- mediaSessionRef: string;
30
- voice: Voice;
31
- languageModel: LanguageModel;
32
- speechBuffer: string;
33
- firstMessage: string;
34
- goodbyeMessage: string;
35
- transferMessage: string;
36
- transferPhoneNumber: string;
37
- transferTimeout: number;
38
- systemErrorMessage: string;
39
- idleMessage: string;
40
- idleTimeout: number;
41
- maxIdleTimeoutCount: number;
42
- idleTimeoutCount: number;
43
- maxSpeechWaitTimeout: number;
44
- allowUserBargeIn: boolean;
45
- sessionStartTime: number;
46
- maxSessionDuration: number;
47
- initialDtmf: string;
48
- previousState: any;
49
- hasLateSpeech: boolean;
50
- isFirstTurn: boolean;
51
- };
52
- export { context };
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.context = void 0;
4
- const context = ({ input }) => ({
5
- mediaSessionRef: input.voice.mediaSessionRef,
6
- voice: input.voice,
7
- languageModel: input.languageModel,
8
- speechBuffer: "",
9
- firstMessage: input.conversationSettings.firstMessage,
10
- goodbyeMessage: input.conversationSettings.goodbyeMessage,
11
- transferMessage: input.conversationSettings.transferOptions?.message,
12
- transferPhoneNumber: input.conversationSettings.transferOptions?.phoneNumber,
13
- transferTimeout: input.conversationSettings.transferOptions?.timeout,
14
- systemErrorMessage: input.conversationSettings.systemErrorMessage,
15
- idleMessage: input.conversationSettings.idleOptions.message,
16
- idleTimeout: input.conversationSettings.idleOptions.timeout,
17
- maxIdleTimeoutCount: input.conversationSettings.idleOptions.maxTimeoutCount,
18
- idleTimeoutCount: 0,
19
- maxSpeechWaitTimeout: input.conversationSettings.maxSpeechWaitTimeout,
20
- allowUserBargeIn: input.conversationSettings.allowUserBargeIn,
21
- sessionStartTime: Date.now(),
22
- maxSessionDuration: input.conversationSettings.maxSessionDuration,
23
- initialDtmf: input.conversationSettings.initialDtmf,
24
- previousState: null,
25
- hasLateSpeech: false,
26
- isFirstTurn: true
27
- });
28
- exports.context = context;