@fonoster/autopilot 0.8.26 → 0.8.28

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.
@@ -24,7 +24,7 @@ exports.loadAndValidateAssistant = loadAndValidateAssistant;
24
24
  */
25
25
  const fs_1 = __importDefault(require("fs"));
26
26
  const logger_1 = require("@fonoster/logger");
27
- const AssistantSchema_1 = require("../assistants/AssistantSchema");
27
+ const common_1 = require("@fonoster/common");
28
28
  const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
29
29
  function loadAndValidateAssistant(path) {
30
30
  if (!fs_1.default.existsSync(path)) {
@@ -34,7 +34,7 @@ function loadAndValidateAssistant(path) {
34
34
  try {
35
35
  const fileContent = fs_1.default.readFileSync(path, "utf8");
36
36
  const assistant = JSON.parse(fileContent);
37
- return AssistantSchema_1.assistantSchema.parse(assistant);
37
+ return common_1.assistantSchema.parse(assistant);
38
38
  }
39
39
  catch (e) {
40
40
  logger.error("error parsing or validating assistant file", {
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { assistantSchema, conversationSettingsSchema, languageModelConfigSchema } from "./AssistantSchema";
2
+ import { assistantSchema, conversationSettingsSchema, languageModelConfigSchema } from "@fonoster/common";
3
3
  type ConversationSettings = z.infer<typeof conversationSettingsSchema>;
4
4
  type LanguageModelConfig = z.infer<typeof languageModelConfigSchema>;
5
5
  type AssistantConfig = z.infer<typeof assistantSchema>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createLanguageModel = createLanguageModel;
4
+ // @ts-nocheck - All inputs are validated by the APIServer
4
5
  /*
5
6
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
6
7
  * http://github.com/fonoster/fonoster
@@ -28,7 +29,6 @@ function createLanguageModel(params) {
28
29
  ? [_1.hangupToolDefinition, _1.transferToolDefinition]
29
30
  : [_1.hangupToolDefinition]);
30
31
  return _1.LanguageModelFactory.getLanguageModel(languageModelSettings.provider, {
31
- // @ts-expect-error don't know the model type here
32
32
  model: languageModelSettings.model,
33
33
  apiKey: languageModelSettings.apiKey,
34
34
  maxTokens: languageModelSettings.maxTokens,
package/dist/envs.d.ts CHANGED
@@ -1,10 +1,14 @@
1
+ export declare const SKIP_IDENTITY: boolean;
1
2
  export declare const AWS_S3_ACCESS_KEY_ID: string | undefined;
2
3
  export declare const AWS_S3_ENDPOINT: string | undefined;
3
4
  export declare const AWS_S3_REGION: string;
4
5
  export declare const AWS_S3_SECRET_ACCESS_KEY: string | undefined;
5
6
  export declare const KNOWLEDGE_BASE_ENABLED: boolean;
6
7
  export declare const NODE_ENV: string;
7
- export declare const SKIP_IDENTITY: boolean;
8
8
  export declare const UNSTRUCTURED_API_KEY: string | undefined;
9
9
  export declare const UNSTRUCTURED_API_URL: string;
10
10
  export declare const SILERO_VAD_MODEL_PATH: string;
11
+ export declare const CONVERSATION_PROVIDER: string;
12
+ export declare const CONVERSATION_PROVIDER_FILE: string;
13
+ export declare const APISERVER_ENDPOINT: string;
14
+ export declare const INTEGRATIONS_FILE: string;
package/dist/envs.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SILERO_VAD_MODEL_PATH = exports.UNSTRUCTURED_API_URL = exports.UNSTRUCTURED_API_KEY = exports.SKIP_IDENTITY = exports.NODE_ENV = exports.KNOWLEDGE_BASE_ENABLED = exports.AWS_S3_SECRET_ACCESS_KEY = exports.AWS_S3_REGION = exports.AWS_S3_ENDPOINT = exports.AWS_S3_ACCESS_KEY_ID = void 0;
6
+ exports.INTEGRATIONS_FILE = exports.APISERVER_ENDPOINT = exports.CONVERSATION_PROVIDER_FILE = exports.CONVERSATION_PROVIDER = exports.SILERO_VAD_MODEL_PATH = exports.UNSTRUCTURED_API_URL = exports.UNSTRUCTURED_API_KEY = exports.NODE_ENV = exports.KNOWLEDGE_BASE_ENABLED = exports.AWS_S3_SECRET_ACCESS_KEY = exports.AWS_S3_REGION = exports.AWS_S3_ENDPOINT = exports.AWS_S3_ACCESS_KEY_ID = exports.SKIP_IDENTITY = void 0;
7
7
  /*
8
8
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
9
9
  * http://github.com/fonoster/fonoster
@@ -25,20 +25,41 @@ exports.SILERO_VAD_MODEL_PATH = exports.UNSTRUCTURED_API_URL = exports.UNSTRUCTU
25
25
  const path_1 = require("path");
26
26
  const common_1 = require("@fonoster/common");
27
27
  const dotenv_1 = __importDefault(require("dotenv"));
28
+ const types_1 = require("./types");
28
29
  if (process.env.NODE_ENV === "dev") {
29
30
  dotenv_1.default.config({ path: (0, path_1.join)(__dirname, "..", "..", "..", ".env") });
30
31
  }
31
32
  const e = process.env;
33
+ exports.SKIP_IDENTITY = e.SKIP_IDENTITY === "true";
32
34
  exports.AWS_S3_ACCESS_KEY_ID = e.AWS_S3_ACCESS_KEY_ID;
33
35
  exports.AWS_S3_ENDPOINT = e.AWS_S3_ENDPOINT;
34
36
  exports.AWS_S3_REGION = e.AWS_S3_REGION ?? "us-east-1";
35
37
  exports.AWS_S3_SECRET_ACCESS_KEY = e.AWS_S3_SECRET_ACCESS_KEY;
36
38
  exports.KNOWLEDGE_BASE_ENABLED = e.KNOWLEDGE_BASE_ENABLED === "true";
37
39
  exports.NODE_ENV = e.NODE_ENV || "production";
38
- exports.SKIP_IDENTITY = e.SKIP_IDENTITY === "true";
39
40
  exports.UNSTRUCTURED_API_KEY = e.UNSTRUCTURED_API_KEY;
40
41
  exports.UNSTRUCTURED_API_URL = e.UNSTRUCTURED_API_URL ?? "https://api.unstructuredapp.io/general/v0/general";
41
42
  exports.SILERO_VAD_MODEL_PATH = e.SILERO_VAD_MODEL_PATH ?? (0, path_1.join)(__dirname, "..", "silero_vad.onnx");
43
+ exports.CONVERSATION_PROVIDER = e.CONVERSATION_PROVIDER
44
+ ? e.CONVERSATION_PROVIDER
45
+ : types_1.ConversationProvider.FILE;
46
+ exports.CONVERSATION_PROVIDER_FILE = e.CONVERSATION_PROVIDER_FILE
47
+ ? e.CONVERSATION_PROVIDER_FILE
48
+ : `${process.cwd()}/config/assistant.json`;
49
+ exports.APISERVER_ENDPOINT = e.APISERVER_ENDPOINT
50
+ ? e.APISERVER_ENDPOINT
51
+ : "apiserver:50051";
52
+ exports.INTEGRATIONS_FILE = e.INTEGRATIONS_FILE
53
+ ? e.INTEGRATIONS_FILE
54
+ : `${process.cwd()}/config/integrations.json`;
55
+ if (exports.CONVERSATION_PROVIDER.toLocaleLowerCase() !== types_1.ConversationProvider.API &&
56
+ exports.CONVERSATION_PROVIDER.toLocaleLowerCase() !== types_1.ConversationProvider.FILE) {
57
+ console.error("CONVERSATION_PROVIDER must be set to 'api' or 'file'");
58
+ process.exit(1);
59
+ }
60
+ if (exports.CONVERSATION_PROVIDER.toLocaleLowerCase() === types_1.ConversationProvider.API) {
61
+ (0, common_1.assertFileExists)(exports.INTEGRATIONS_FILE);
62
+ }
42
63
  if (exports.KNOWLEDGE_BASE_ENABLED) {
43
64
  (0, common_1.assertEnvsAreSet)([
44
65
  "AWS_S3_ACCESS_KEY_ID",
@@ -32,8 +32,12 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
35
38
  Object.defineProperty(exports, "__esModule", { value: true });
36
39
  exports.handleVoiceRequest = handleVoiceRequest;
40
+ // @ts-nocheck - All inputs are validated by the APIServer
37
41
  /*
38
42
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
39
43
  * http://github.com/fonoster/fonoster
@@ -58,6 +62,8 @@ const createLanguageModel_1 = require("./createLanguageModel");
58
62
  const envs_1 = require("./envs");
59
63
  const loadAssistantConfigFromFile_1 = require("./loadAssistantConfigFromFile");
60
64
  const _1 = __importStar(require("."));
65
+ const loadAssistantFromAPI_1 = require("./loadAssistantFromAPI");
66
+ const fs_1 = __importDefault(require("fs"));
61
67
  const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
62
68
  async function handleVoiceRequest(req, res) {
63
69
  const { accessKeyId, ingressNumber, sessionRef, appRef, callDirection } = req;
@@ -68,7 +74,9 @@ async function handleVoiceRequest(req, res) {
68
74
  appRef,
69
75
  metadata: req.metadata
70
76
  });
71
- const assistantConfig = (0, loadAssistantConfigFromFile_1.loadAssistantConfigFromFile)(`${process.cwd()}/config/assistant.json`);
77
+ const assistantConfig = envs_1.CONVERSATION_PROVIDER === _1.ConversationProvider.FILE
78
+ ? (0, loadAssistantConfigFromFile_1.loadAssistantConfigFromFile)(envs_1.CONVERSATION_PROVIDER_FILE)
79
+ : await (0, loadAssistantFromAPI_1.loadAssistantFromAPI)(req, JSON.parse(fs_1.default.readFileSync(envs_1.INTEGRATIONS_FILE, "utf8")));
72
80
  let knowledgeBase;
73
81
  if (envs_1.KNOWLEDGE_BASE_ENABLED) {
74
82
  knowledgeBase = new _1.S3KnowledgeBase({
@@ -101,8 +109,9 @@ async function handleVoiceRequest(req, res) {
101
109
  callerNumber: req.callerNumber
102
110
  }
103
111
  });
112
+ const { conversationSettings } = assistantConfig;
104
113
  const autopilot = new _1.default({
105
- conversationSettings: assistantConfig.conversationSettings,
114
+ conversationSettings,
106
115
  voice,
107
116
  languageModel
108
117
  });
@@ -54,7 +54,15 @@ exports.loadAssistantConfigFromFile = loadAssistantConfigFromFile;
54
54
  */
55
55
  const path = __importStar(require("path"));
56
56
  const _1 = require(".");
57
+ const logger_1 = require("@fonoster/logger");
58
+ const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
57
59
  function loadAssistantConfigFromFile(pathToAssistantConfig) {
58
- const assistantPath = path.resolve(process.cwd(), pathToAssistantConfig);
59
- return (0, _1.loadAndValidateAssistant)(assistantPath);
60
+ try {
61
+ const assistantPath = path.resolve(process.cwd(), pathToAssistantConfig);
62
+ return (0, _1.loadAndValidateAssistant)(assistantPath);
63
+ }
64
+ catch (error) {
65
+ logger.error("Error loading assistant config from file", error);
66
+ throw error;
67
+ }
60
68
  }
@@ -0,0 +1,7 @@
1
+ import { VoiceRequest } from "@fonoster/common";
2
+ import { AssistantConfig } from "./assistants";
3
+ declare function loadAssistantFromAPI(req: VoiceRequest, integrations: {
4
+ productRef: string;
5
+ credentials: Record<string, unknown>;
6
+ }[]): Promise<AssistantConfig>;
7
+ export { loadAssistantFromAPI };
@@ -0,0 +1,94 @@
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
+ // @ts-nocheck - All inputs are validated by the APIServer
38
+ /*
39
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
40
+ * http://github.com/fonoster/fonoster
41
+ *
42
+ * This file is part of Fonoster
43
+ *
44
+ * Licensed under the MIT License (the "License");
45
+ * you may not use this file except in compliance with
46
+ * the License. You may obtain a copy of the License at
47
+ *
48
+ * https://opensource.org/licenses/MIT
49
+ *
50
+ * Unless required by applicable law or agreed to in writing, software
51
+ * distributed under the License is distributed on an "AS IS" BASIS,
52
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
53
+ * See the License for the specific language governing permissions and
54
+ * limitations under the License.
55
+ */
56
+ const common_1 = require("@fonoster/common");
57
+ const SDK = __importStar(require("@fonoster/sdk"));
58
+ const envs_1 = require("./envs");
59
+ const logger_1 = require("@fonoster/logger");
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
+ const assistantConfig = app.intelligence?.config;
87
+ assistantConfig.languageModel.apiKey = credentials?.apiKey;
88
+ resolve(assistantConfig);
89
+ })
90
+ .catch((err) => {
91
+ reject(new Error(`Failed to load assistant config from API: ${err}`));
92
+ });
93
+ });
94
+ }
@@ -79,238 +79,86 @@ declare const machine: import("xstate").StateMachine<AutopilotContext, {
79
79
  type: "isNotSpeaking";
80
80
  params: unknown;
81
81
  };
82
- }>, "IDLE_TIMEOUT" | "MAX_SPEECH_WAIT_TIMEOUT", "hangup" | "greeting" | "idle" | "waitingForUserRequest" | "transitioningToIdle" | "updatingSpeech" | "processingUserRequest", string, {
82
+ }>, "IDLE_TIMEOUT" | "MAX_SPEECH_WAIT_TIMEOUT", {}, string, {
83
83
  conversationSettings: ConversationSettings;
84
84
  languageModel: LanguageModel;
85
85
  voice: Voice;
86
- }, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").MetaObject, {
87
- readonly context: ({ input }: {
88
- spawn: {
89
- <TSrc extends "doProcessUserRequest">(logic: TSrc, ...[options]: {
90
- src: "doProcessUserRequest";
91
- logic: import("xstate").PromiseActorLogic<void, {
92
- context: AutopilotContext;
93
- }, import("xstate").EventObject>;
94
- id: string | undefined;
95
- } extends infer T ? T extends {
96
- src: "doProcessUserRequest";
97
- logic: import("xstate").PromiseActorLogic<void, {
98
- context: AutopilotContext;
99
- }, import("xstate").EventObject>;
100
- id: string | undefined;
101
- } ? T extends {
102
- src: TSrc;
103
- } ? import("xstate").ConditionalRequired<[options?: ({
104
- id?: T["id"] | undefined;
105
- systemId?: string;
106
- input?: import("xstate").InputFrom<T["logic"]> | undefined;
107
- syncSnapshot?: boolean;
108
- } & { [K in import("xstate").RequiredActorOptions<T>]: unknown; }) | undefined], import("xstate").IsNotNever<import("xstate").RequiredActorOptions<T>>> : never : never : never): import("xstate").ActorRefFromLogic<import("xstate").GetConcreteByKey<{
109
- src: "doProcessUserRequest";
110
- logic: import("xstate").PromiseActorLogic<void, {
111
- context: AutopilotContext;
112
- }, import("xstate").EventObject>;
113
- id: string | undefined;
114
- }, "src", TSrc>["logic"]>;
115
- <TLogic extends import("xstate").AnyActorLogic>(src: TLogic, ...[options]: import("xstate").ConditionalRequired<[options?: ({
116
- id?: never;
117
- systemId?: string;
118
- input?: import("xstate").InputFrom<TLogic> | undefined;
119
- syncSnapshot?: boolean;
120
- } & { [K in import("xstate").RequiredLogicInput<TLogic>]: unknown; }) | undefined], import("xstate").IsNotNever<import("xstate").RequiredLogicInput<TLogic>>>): import("xstate").ActorRefFromLogic<TLogic>;
121
- };
122
- input: {
123
- conversationSettings: ConversationSettings;
124
- languageModel: LanguageModel;
125
- voice: Voice;
126
- };
127
- self: import("xstate").ActorRef<import("xstate").MachineSnapshot<AutopilotContext, {
128
- type: "SPEECH_START";
129
- } | {
130
- type: "SPEECH_END";
131
- } | {
132
- type: "SPEECH_RESULT";
133
- speech: string;
134
- } | {
135
- type: "USER_REQUEST_PROCESSED";
136
- }, Record<string, import("xstate").AnyActorRef | undefined>, import("xstate").StateValue, string, unknown, any, any>, {
137
- type: "SPEECH_START";
138
- } | {
139
- type: "SPEECH_END";
140
- } | {
141
- type: "SPEECH_RESULT";
142
- speech: string;
143
- } | {
144
- type: "USER_REQUEST_PROCESSED";
145
- }, import("xstate").AnyEventObject>;
146
- }) => {
147
- sessionRef: string;
148
- voice: Voice;
149
- languageModel: LanguageModel;
150
- speechBuffer: string;
151
- firstMessage: string | undefined;
152
- goodbyeMessage: string;
153
- transferMessage: string | undefined;
154
- transferPhoneNumber: string | undefined;
155
- systemErrorMessage: string;
156
- idleMessage: string;
157
- idleTimeout: number;
158
- maxIdleTimeoutCount: number;
159
- idleTimeoutCount: number;
160
- maxSpeechWaitTimeout: number;
161
- speechResponseTime: number;
162
- isSpeaking: false;
86
+ }, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").MetaObject, import("xstate").MachineConfig<AutopilotContext, {
87
+ type: "SPEECH_START";
88
+ } | {
89
+ type: "SPEECH_END";
90
+ } | {
91
+ type: "SPEECH_RESULT";
92
+ speech: string;
93
+ } | {
94
+ type: "USER_REQUEST_PROCESSED";
95
+ }, {
96
+ src: "doProcessUserRequest";
97
+ logic: import("xstate").PromiseActorLogic<void, {
98
+ context: AutopilotContext;
99
+ }, import("xstate").EventObject>;
100
+ id: string | undefined;
101
+ }, import("xstate").Values<{
102
+ greetUser: {
103
+ type: "greetUser";
104
+ params: unknown;
163
105
  };
164
- readonly id: "fnAI";
165
- readonly initial: "greeting";
166
- readonly states: {
167
- readonly greeting: {
168
- readonly always: {
169
- readonly target: "idle";
170
- };
171
- readonly entry: {
172
- readonly type: "greetUser";
173
- };
174
- };
175
- readonly idle: {
176
- readonly on: {
177
- readonly SPEECH_START: {
178
- readonly target: "waitingForUserRequest";
179
- readonly description: "Event from VAD system.";
180
- };
181
- readonly SPEECH_RESULT: {
182
- readonly target: "waitingForUserRequest";
183
- readonly description: "Event from Speech to Text provider.";
184
- };
185
- };
186
- readonly after: {
187
- readonly IDLE_TIMEOUT: readonly [{
188
- readonly target: "hangup";
189
- readonly actions: {
190
- readonly type: "goodbye";
191
- };
192
- readonly guard: {
193
- readonly type: "idleTimeoutCountExceedsMax";
194
- };
195
- }, {
196
- readonly target: "transitioningToIdle";
197
- readonly actions: readonly [{
198
- readonly type: "increaseIdleTimeoutCount";
199
- }, {
200
- readonly type: "announceIdleTimeout";
201
- }];
202
- }];
203
- };
204
- };
205
- readonly waitingForUserRequest: {
206
- readonly always: {
207
- readonly target: "updatingSpeech";
208
- };
209
- readonly entry: readonly [{
210
- readonly type: "cleanSpeech";
211
- }, {
212
- readonly type: "interruptPlayback";
213
- }, {
214
- readonly type: "resetIdleTimeoutCount";
215
- }, {
216
- readonly type: "setSpeaking";
217
- }];
218
- };
219
- readonly hangup: {
220
- readonly type: "final";
221
- };
222
- readonly transitioningToIdle: {
223
- readonly always: {
224
- readonly target: "idle";
225
- };
226
- };
227
- readonly updatingSpeech: {
228
- readonly on: {
229
- readonly SPEECH_RESULT: readonly [{
230
- readonly target: "processingUserRequest";
231
- readonly actions: {
232
- readonly type: "appendSpeech";
233
- };
234
- readonly guard: {
235
- readonly type: "isNotSpeaking";
236
- };
237
- readonly description: "Speech result from the Speech to Text provider.";
238
- }, {
239
- readonly target: "updatingSpeech";
240
- readonly actions: {
241
- readonly type: "appendSpeech";
242
- };
243
- }];
244
- readonly SPEECH_END: readonly [{
245
- readonly target: "processingUserRequest";
246
- readonly actions: {
247
- readonly type: "setSpeakingDone";
248
- };
249
- readonly guard: {
250
- readonly type: "hasSpeechResult";
251
- };
252
- readonly description: "Event from VAD or similar system.";
253
- }, {
254
- readonly target: "updatingSpeech";
255
- readonly actions: {
256
- readonly type: "setSpeakingDone";
257
- };
258
- }];
259
- };
260
- readonly after: {
261
- readonly MAX_SPEECH_WAIT_TIMEOUT: {
262
- readonly target: "processingUserRequest";
263
- };
264
- };
265
- };
266
- readonly processingUserRequest: {
267
- readonly on: {
268
- readonly SPEECH_START: {
269
- readonly target: "waitingForUserRequest";
270
- readonly description: "Event from VAD or similar system.";
271
- };
272
- };
273
- readonly invoke: {
274
- readonly src: "doProcessUserRequest";
275
- readonly input: ({ context }: {
276
- context: AutopilotContext;
277
- event: {
278
- type: "SPEECH_START";
279
- } | {
280
- type: "SPEECH_END";
281
- } | {
282
- type: "SPEECH_RESULT";
283
- speech: string;
284
- } | {
285
- type: "USER_REQUEST_PROCESSED";
286
- };
287
- self: import("xstate").ActorRef<import("xstate").MachineSnapshot<AutopilotContext, {
288
- type: "SPEECH_START";
289
- } | {
290
- type: "SPEECH_END";
291
- } | {
292
- type: "SPEECH_RESULT";
293
- speech: string;
294
- } | {
295
- type: "USER_REQUEST_PROCESSED";
296
- }, Record<string, import("xstate").AnyActorRef>, import("xstate").StateValue, string, unknown, any, any>, {
297
- type: "SPEECH_START";
298
- } | {
299
- type: "SPEECH_END";
300
- } | {
301
- type: "SPEECH_RESULT";
302
- speech: string;
303
- } | {
304
- type: "USER_REQUEST_PROCESSED";
305
- }, import("xstate").AnyEventObject>;
306
- }) => {
307
- context: AutopilotContext;
308
- };
309
- readonly onDone: {
310
- readonly target: "idle";
311
- };
312
- };
313
- };
106
+ goodbye: {
107
+ type: "goodbye";
108
+ params: unknown;
109
+ };
110
+ announceSystemError: {
111
+ type: "announceSystemError";
112
+ params: unknown;
113
+ };
114
+ interruptPlayback: {
115
+ type: "interruptPlayback";
116
+ params: unknown;
117
+ };
118
+ announceIdleTimeout: {
119
+ type: "announceIdleTimeout";
120
+ params: unknown;
121
+ };
122
+ increaseIdleTimeoutCount: {
123
+ type: "increaseIdleTimeoutCount";
124
+ params: import("xstate").NonReducibleUnknown;
314
125
  };
315
- }>;
126
+ cleanSpeech: {
127
+ type: "cleanSpeech";
128
+ params: import("xstate").NonReducibleUnknown;
129
+ };
130
+ appendSpeech: {
131
+ type: "appendSpeech";
132
+ params: import("xstate").NonReducibleUnknown;
133
+ };
134
+ resetIdleTimeoutCount: {
135
+ type: "resetIdleTimeoutCount";
136
+ params: import("xstate").NonReducibleUnknown;
137
+ };
138
+ setSpeaking: {
139
+ type: "setSpeaking";
140
+ params: import("xstate").NonReducibleUnknown;
141
+ };
142
+ setSpeakingDone: {
143
+ type: "setSpeakingDone";
144
+ params: import("xstate").NonReducibleUnknown;
145
+ };
146
+ }>, import("xstate").Values<{
147
+ idleTimeoutCountExceedsMax: {
148
+ type: "idleTimeoutCountExceedsMax";
149
+ params: unknown;
150
+ };
151
+ hasSpeechResult: {
152
+ type: "hasSpeechResult";
153
+ params: unknown;
154
+ };
155
+ isNotSpeaking: {
156
+ type: "isNotSpeaking";
157
+ params: unknown;
158
+ };
159
+ }>, "IDLE_TIMEOUT" | "MAX_SPEECH_WAIT_TIMEOUT", string, {
160
+ conversationSettings: ConversationSettings;
161
+ languageModel: LanguageModel;
162
+ voice: Voice;
163
+ }, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").MetaObject>>;
316
164
  export { machine };
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.machine = void 0;
4
+ // @ts-nocheck - All inputs are validated by the APIServer
4
5
  /*
5
6
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
6
7
  * http://github.com/fonoster/fonoster
@@ -3,16 +3,16 @@ import { GroqParams } from "./groq";
3
3
  import { OllamaParams } from "./ollama";
4
4
  import { OpenAIParams } from "./openai";
5
5
  import { BaseModelParams, TelephonyContext } from "./types";
6
- import { LANGUAGE_MODEL_PROVIDER } from "../types";
6
+ import { LanguageModelProvider } from "../types";
7
7
  import { Voice } from "../voice";
8
8
  type LanguageModelConstructor<T extends BaseModelParams = BaseModelParams> = new (options: T, voice: Voice, telephonyContext: TelephonyContext) => AbstractLanguageModel;
9
9
  type LanguageModelConfigMap = {
10
- [LANGUAGE_MODEL_PROVIDER.OPENAI]: OpenAIParams;
11
- [LANGUAGE_MODEL_PROVIDER.GROQ]: GroqParams;
12
- [LANGUAGE_MODEL_PROVIDER.OLLAMA]: OllamaParams;
10
+ [LanguageModelProvider.OPENAI]: OpenAIParams;
11
+ [LanguageModelProvider.GROQ]: GroqParams;
12
+ [LanguageModelProvider.OLLAMA]: OllamaParams;
13
13
  };
14
14
  declare class LanguageModelFactory {
15
- private static languageModels;
15
+ private static readonly languageModels;
16
16
  static registerLanguageModel<T extends BaseModelParams>(name: string, ctor: LanguageModelConstructor<T>): void;
17
17
  static getLanguageModel<T extends keyof LanguageModelConfigMap>(languageModel: T, config: LanguageModelConfigMap[T], voice: Voice, telephonyContext: TelephonyContext): AbstractLanguageModel;
18
18
  }
@@ -4,7 +4,7 @@ declare enum OllamaModel {
4
4
  }
5
5
  type OllamaParams = BaseModelParams & {
6
6
  model: OllamaModel;
7
- baseUrl: string;
7
+ baseUrl?: string;
8
8
  maxTokens: number;
9
9
  temperature: number;
10
10
  };
package/dist/types.d.ts CHANGED
@@ -1,14 +1,18 @@
1
1
  import { ConversationSettings } from "./assistants";
2
2
  import { LanguageModel } from "./models";
3
3
  import { Voice } from "./voice";
4
- declare enum LANGUAGE_MODEL_PROVIDER {
4
+ declare enum LanguageModelProvider {
5
5
  OPENAI = "openai",
6
6
  GROQ = "groq",
7
7
  OLLAMA = "ollama"
8
8
  }
9
+ declare enum ConversationProvider {
10
+ FILE = "file",
11
+ API = "api"
12
+ }
9
13
  type AutopilotParams = {
10
14
  voice: Voice;
11
15
  conversationSettings: ConversationSettings;
12
16
  languageModel: LanguageModel;
13
17
  };
14
- export { AutopilotParams, LANGUAGE_MODEL_PROVIDER };
18
+ export { AutopilotParams, LanguageModelProvider, ConversationProvider };