@fonoster/autopilot 0.8.51 → 0.8.56

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 (80) hide show
  1. package/dist/Autopilot.js +6 -5
  2. package/dist/handleVoiceRequest.js +4 -3
  3. package/dist/machine/actions/announceIdleTimeout.d.ts +4 -0
  4. package/dist/machine/actions/announceIdleTimeout.js +30 -0
  5. package/dist/machine/actions/announceSystemError.d.ts +4 -0
  6. package/dist/machine/actions/announceSystemError.js +30 -0
  7. package/dist/machine/actions/appendSpeech.d.ts +1 -0
  8. package/dist/machine/actions/appendSpeech.js +35 -0
  9. package/dist/machine/actions/cleanSpeech.d.ts +1 -0
  10. package/dist/machine/actions/cleanSpeech.js +23 -0
  11. package/dist/machine/actions/goodbye.d.ts +4 -0
  12. package/dist/machine/actions/goodbye.js +31 -0
  13. package/dist/machine/actions/greetUser.d.ts +4 -0
  14. package/dist/machine/actions/greetUser.js +33 -0
  15. package/dist/machine/actions/increaseIdleTimeoutCount.d.ts +1 -0
  16. package/dist/machine/actions/increaseIdleTimeoutCount.js +31 -0
  17. package/dist/machine/actions/index.d.ts +12 -0
  18. package/dist/machine/actions/index.js +45 -0
  19. package/dist/machine/actions/interruptPlayback.d.ts +4 -0
  20. package/dist/machine/actions/interruptPlayback.js +30 -0
  21. package/dist/machine/actions/resetIdleTimeoutCount.d.ts +1 -0
  22. package/dist/machine/actions/resetIdleTimeoutCount.js +31 -0
  23. package/dist/machine/actions/resetState.d.ts +1 -0
  24. package/dist/machine/actions/resetState.js +33 -0
  25. package/dist/machine/actions/setSpeaking.d.ts +1 -0
  26. package/dist/machine/actions/setSpeaking.js +29 -0
  27. package/dist/machine/actions/setSpeakingDone.d.ts +1 -0
  28. package/dist/machine/actions/setSpeakingDone.js +29 -0
  29. package/dist/machine/actors/doProcessUserRequest.d.ts +4 -0
  30. package/dist/machine/actors/doProcessUserRequest.js +65 -0
  31. package/dist/machine/actors/index.d.ts +1 -0
  32. package/dist/machine/actors/index.js +35 -0
  33. package/dist/machine/context.d.ts +22 -0
  34. package/dist/machine/context.js +41 -0
  35. package/dist/machine/delays.d.ts +12 -0
  36. package/dist/machine/delays.js +31 -0
  37. package/dist/machine/guards/hasSpeechResult.d.ts +4 -0
  38. package/dist/machine/guards/hasSpeechResult.js +30 -0
  39. package/dist/machine/guards/idleTimeoutCountExceedsMax.d.ts +4 -0
  40. package/dist/machine/guards/idleTimeoutCountExceedsMax.js +31 -0
  41. package/dist/machine/guards/index.d.ts +3 -0
  42. package/dist/machine/guards/index.js +27 -0
  43. package/dist/machine/guards/isSpeaking.d.ts +4 -0
  44. package/dist/machine/guards/isSpeaking.js +30 -0
  45. package/dist/machine/machine.d.ts +222 -74
  46. package/dist/machine/machine.js +19 -221
  47. package/dist/machine/setup.d.ts +172 -0
  48. package/dist/machine/setup.js +81 -0
  49. package/dist/models/AbstractLanguageModel.js +34 -15
  50. package/dist/{createLanguageModel.d.ts → models/createLanguageModel.d.ts} +2 -2
  51. package/dist/{createLanguageModel.js → models/createLanguageModel.js} +7 -12
  52. package/dist/models/evaluations/createTestTextSimilarity.d.ts +6 -0
  53. package/dist/models/evaluations/createTestTextSimilarity.js +43 -0
  54. package/dist/models/evaluations/evals.d.ts +3 -0
  55. package/dist/models/evaluations/evals.js +38 -0
  56. package/dist/models/evaluations/evaluateScenario.d.ts +2 -0
  57. package/dist/models/evaluations/evaluateScenario.js +23 -0
  58. package/dist/models/evaluations/evaluateStep.d.ts +2 -0
  59. package/dist/models/evaluations/evaluateStep.js +55 -0
  60. package/dist/models/evaluations/evaluateTextResponse.d.ts +8 -0
  61. package/dist/models/evaluations/evaluateTextResponse.js +28 -0
  62. package/dist/models/evaluations/evaluateToolCalls.d.ts +6 -0
  63. package/dist/models/evaluations/evaluateToolCalls.js +61 -0
  64. package/dist/models/evaluations/index.d.ts +2 -0
  65. package/dist/models/evaluations/index.js +36 -0
  66. package/dist/models/evaluations/printEval.d.ts +2 -0
  67. package/dist/models/evaluations/printEval.js +79 -0
  68. package/dist/models/evaluations/textSimilaryPrompt.d.ts +1 -0
  69. package/dist/models/evaluations/textSimilaryPrompt.js +41 -0
  70. package/dist/models/evaluations/types.d.ts +41 -0
  71. package/dist/models/evaluations/types.js +8 -0
  72. package/dist/models/index.d.ts +1 -0
  73. package/dist/models/index.js +1 -0
  74. package/dist/models/toolInvocation.d.ts +2 -4
  75. package/dist/models/toolInvocation.js +7 -5
  76. package/dist/models/types.d.ts +2 -0
  77. package/dist/voice/Voice.d.ts +8 -2
  78. package/dist/voice/Voice.js +4 -1
  79. package/dist/voice/types.d.ts +4 -1
  80. package/package.json +14 -12
@@ -0,0 +1,35 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /*
18
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
19
+ * http://github.com/fonoster/fonoster
20
+ *
21
+ * This file is part of Fonoster
22
+ *
23
+ * Licensed under the MIT License (the "License");
24
+ * you may not use this file except in compliance with
25
+ * the License. You may obtain a copy of the License at
26
+ *
27
+ * https://opensource.org/licenses/MIT
28
+ *
29
+ * Unless required by applicable law or agreed to in writing, software
30
+ * distributed under the License is distributed on an "AS IS" BASIS,
31
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
+ * See the License for the specific language governing permissions and
33
+ * limitations under the License.
34
+ */
35
+ __exportStar(require("./doProcessUserRequest"), exports);
@@ -0,0 +1,22 @@
1
+ declare const context: ({ input }: {
2
+ input: any;
3
+ }) => {
4
+ sessionRef: any;
5
+ voice: any;
6
+ languageModel: any;
7
+ speechBuffer: string;
8
+ firstMessage: any;
9
+ goodbyeMessage: any;
10
+ transferMessage: any;
11
+ transferPhoneNumber: any;
12
+ systemErrorMessage: any;
13
+ idleMessage: any;
14
+ idleTimeout: any;
15
+ maxIdleTimeoutCount: any;
16
+ idleTimeoutCount: number;
17
+ maxSpeechWaitTimeout: any;
18
+ isSpeaking: boolean;
19
+ sessionStartTime: number;
20
+ maxSessionDuration: any;
21
+ };
22
+ export { context };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.context = 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 context = ({ input }) => ({
23
+ sessionRef: input.voice.sessionRef,
24
+ voice: input.voice,
25
+ languageModel: input.languageModel,
26
+ speechBuffer: "",
27
+ firstMessage: input.conversationSettings.firstMessage,
28
+ goodbyeMessage: input.conversationSettings.goodbyeMessage,
29
+ transferMessage: input.conversationSettings.transferOptions?.message,
30
+ transferPhoneNumber: input.conversationSettings.transferOptions?.phoneNumber,
31
+ systemErrorMessage: input.conversationSettings.systemErrorMessage,
32
+ idleMessage: input.conversationSettings.idleOptions?.message || "",
33
+ idleTimeout: input.conversationSettings.idleOptions?.timeout || 10000,
34
+ maxIdleTimeoutCount: input.conversationSettings.idleOptions?.maxTimeoutCount || 3,
35
+ idleTimeoutCount: 0,
36
+ maxSpeechWaitTimeout: input.conversationSettings.maxSpeechWaitTimeout,
37
+ isSpeaking: false,
38
+ sessionStartTime: Date.now(),
39
+ maxSessionDuration: input.conversationSettings.maxSessionDuration
40
+ });
41
+ exports.context = context;
@@ -0,0 +1,12 @@
1
+ declare const delays: {
2
+ IDLE_TIMEOUT: ({ context }: {
3
+ context: any;
4
+ }) => any;
5
+ MAX_SPEECH_WAIT_TIMEOUT: ({ context }: {
6
+ context: any;
7
+ }) => any;
8
+ SESSION_TIMEOUT: ({ context }: {
9
+ context: any;
10
+ }) => number;
11
+ };
12
+ export { delays as default };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = void 0;
4
+ // @ts-nocheck - All inputs are validated by the APIServer
5
+ /*
6
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
7
+ * http://github.com/fonoster/fonoster
8
+ *
9
+ * This file is part of Fonoster
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 delays = {
24
+ IDLE_TIMEOUT: ({ context }) => context.idleTimeout,
25
+ MAX_SPEECH_WAIT_TIMEOUT: ({ context }) => context.maxSpeechWaitTimeout,
26
+ SESSION_TIMEOUT: ({ context }) => {
27
+ const elapsed = Date.now() - context.sessionStartTime;
28
+ return Math.max(0, context.maxSessionDuration - elapsed);
29
+ }
30
+ };
31
+ exports.default = delays;
@@ -0,0 +1,4 @@
1
+ import { AutopilotContext } from "../types";
2
+ export declare const hasSpeechResult: ({ context }: {
3
+ context: AutopilotContext;
4
+ }) => boolean;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasSpeechResult = 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 hasSpeechResult = ({ context }) => {
25
+ logger.verbose("called the hasSpeechResult guard", {
26
+ speechBuffer: context.speechBuffer
27
+ });
28
+ return Boolean(context.speechBuffer);
29
+ };
30
+ exports.hasSpeechResult = hasSpeechResult;
@@ -0,0 +1,4 @@
1
+ import { AutopilotContext } from "../types";
2
+ export declare const idleTimeoutCountExceedsMax: ({ context }: {
3
+ context: AutopilotContext;
4
+ }) => boolean;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.idleTimeoutCountExceedsMax = 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 idleTimeoutCountExceedsMax = ({ context }) => {
25
+ logger.verbose("called the idleTimeoutCountExceedsMax guard", {
26
+ idleTimeoutCount: context.idleTimeoutCount + 1,
27
+ maxIdleTimeoutCount: context.maxIdleTimeoutCount
28
+ });
29
+ return context.idleTimeoutCount + 1 > context.maxIdleTimeoutCount;
30
+ };
31
+ exports.idleTimeoutCountExceedsMax = idleTimeoutCountExceedsMax;
@@ -0,0 +1,3 @@
1
+ export { idleTimeoutCountExceedsMax } from "./idleTimeoutCountExceedsMax";
2
+ export { hasSpeechResult } from "./hasSpeechResult";
3
+ export { isSpeaking } from "./isSpeaking";
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isSpeaking = exports.hasSpeechResult = exports.idleTimeoutCountExceedsMax = 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 idleTimeoutCountExceedsMax_1 = require("./idleTimeoutCountExceedsMax");
23
+ Object.defineProperty(exports, "idleTimeoutCountExceedsMax", { enumerable: true, get: function () { return idleTimeoutCountExceedsMax_1.idleTimeoutCountExceedsMax; } });
24
+ var hasSpeechResult_1 = require("./hasSpeechResult");
25
+ Object.defineProperty(exports, "hasSpeechResult", { enumerable: true, get: function () { return hasSpeechResult_1.hasSpeechResult; } });
26
+ var isSpeaking_1 = require("./isSpeaking");
27
+ Object.defineProperty(exports, "isSpeaking", { enumerable: true, get: function () { return isSpeaking_1.isSpeaking; } });
@@ -0,0 +1,4 @@
1
+ import { AutopilotContext } from "../types";
2
+ export declare const isSpeaking: ({ context }: {
3
+ context: AutopilotContext;
4
+ }) => boolean;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isSpeaking = 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 isSpeaking = ({ context }) => {
25
+ logger.verbose("called the isSpeaking guard", {
26
+ isSpeaking: context.isSpeaking
27
+ });
28
+ return context.isSpeaking;
29
+ };
30
+ exports.isSpeaking = isSpeaking;
@@ -1,33 +1,30 @@
1
- import { AutopilotContext } from "./types";
2
- import { ConversationSettings } from "../assistants";
3
- import { LanguageModel } from "../models";
4
- import { Voice } from "../voice";
5
- declare const machine: import("xstate").StateMachine<AutopilotContext, {
1
+ declare const machine: import("xstate").StateMachine<any, {
6
2
  type: "SPEECH_START";
7
3
  } | {
8
4
  type: "SPEECH_END";
9
5
  } | {
10
6
  type: "SPEECH_RESULT";
11
7
  speech: string;
8
+ responseTime: number;
12
9
  }, {
13
10
  [x: string]: import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<void, {
14
- context: AutopilotContext;
11
+ context: import("./types").AutopilotContext;
15
12
  }, import("xstate").EventObject>> | undefined;
16
13
  }, {
17
14
  src: "doProcessUserRequest";
18
15
  logic: import("xstate").PromiseActorLogic<void, {
19
- context: AutopilotContext;
16
+ context: import("./types").AutopilotContext;
20
17
  }, import("xstate").EventObject>;
21
18
  id: string | undefined;
22
19
  }, import("xstate").Values<{
23
- greetUser: {
24
- type: "greetUser";
25
- params: unknown;
26
- };
27
20
  goodbye: {
28
21
  type: "goodbye";
29
22
  params: unknown;
30
23
  };
24
+ greetUser: {
25
+ type: "greetUser";
26
+ params: unknown;
27
+ };
31
28
  announceSystemError: {
32
29
  type: "announceSystemError";
33
30
  params: unknown;
@@ -68,75 +65,226 @@ declare const machine: import("xstate").StateMachine<AutopilotContext, {
68
65
  type: "resetState";
69
66
  params: import("xstate").NonReducibleUnknown;
70
67
  };
71
- }>, never, "IDLE_TIMEOUT" | "MAX_SPEECH_WAIT_TIMEOUT" | "SESSION_TIMEOUT", {}, string, {
72
- conversationSettings: ConversationSettings;
73
- languageModel: LanguageModel;
74
- voice: Voice;
75
- }, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").MetaObject, import("xstate").MachineConfig<AutopilotContext, {
76
- type: "SPEECH_START";
77
- } | {
78
- type: "SPEECH_END";
79
- } | {
80
- type: "SPEECH_RESULT";
81
- speech: string;
82
- }, {
83
- src: "doProcessUserRequest";
84
- logic: import("xstate").PromiseActorLogic<void, {
85
- context: AutopilotContext;
86
- }, import("xstate").EventObject>;
87
- id: string | undefined;
88
- }, import("xstate").Values<{
89
- greetUser: {
90
- type: "greetUser";
91
- params: unknown;
92
- };
93
- goodbye: {
94
- type: "goodbye";
95
- params: unknown;
96
- };
97
- announceSystemError: {
98
- type: "announceSystemError";
68
+ }>, import("xstate").Values<{
69
+ isSpeaking: {
70
+ type: "isSpeaking";
99
71
  params: unknown;
100
72
  };
101
- interruptPlayback: {
102
- type: "interruptPlayback";
73
+ idleTimeoutCountExceedsMax: {
74
+ type: "idleTimeoutCountExceedsMax";
103
75
  params: unknown;
104
76
  };
105
- announceIdleTimeout: {
106
- type: "announceIdleTimeout";
77
+ hasSpeechResult: {
78
+ type: "hasSpeechResult";
107
79
  params: unknown;
108
80
  };
109
- increaseIdleTimeoutCount: {
110
- type: "increaseIdleTimeoutCount";
111
- params: import("xstate").NonReducibleUnknown;
112
- };
113
- cleanSpeech: {
114
- type: "cleanSpeech";
115
- params: import("xstate").NonReducibleUnknown;
116
- };
117
- appendSpeech: {
118
- type: "appendSpeech";
119
- params: import("xstate").NonReducibleUnknown;
120
- };
121
- resetIdleTimeoutCount: {
122
- type: "resetIdleTimeoutCount";
123
- params: import("xstate").NonReducibleUnknown;
124
- };
125
- setSpeaking: {
126
- type: "setSpeaking";
127
- params: import("xstate").NonReducibleUnknown;
81
+ }>, "IDLE_TIMEOUT" | "MAX_SPEECH_WAIT_TIMEOUT" | "SESSION_TIMEOUT", "hangup" | "greeting" | "idle" | "listeningToUser" | "transitioningToIdle" | "processingUserRequest" | "waitingForSpeechTimeout", string, {
82
+ conversationSettings: import("..").ConversationSettings;
83
+ languageModel: import("..").LanguageModel;
84
+ voice: import("..").Voice;
85
+ }, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").MetaObject, {
86
+ /** @xstate-layout N4IgpgJg5mDOIC5QDMB2BBAkgOigJzDABcBLVKAYgG0AGAXUVAAcB7WE0l1RkAD0QCMADgHYAzAHYAnADYJYgExCaMmSJkAaEAE9EUsQFZsUiaoUGpAhQsMSAvna1os2EhAA2YCgGUACgFF-AGEACQB9bwAVdAAlSNoGJBBWdk5uJP4EAQMAFiFxHLkJbLEaAxkBCS1dLIEcnPFFZSkpHIklQwcnDBw3Tx8A4PCY-28AVQAZePoeFI4SLh5MyzFsBUrzHJMrAxtqxAkcoxyFHMqt0pbsrpBnXo8vXlgiAEMiMGwX5He8AApMAAiE38YUimAAsv4APJjSIASgod1cDwSszY80WGUQMgMRgEUhokgMYjyMlKAn2WQUJmwEnK23a5jEQhuSL6j2ebw+Xx+-yBILBkJh8MRPWRnioAkSzHRaSWgjqNGwQnkNAU0iEYi1VR0emy2Bk+iOpU1bRkrLFRDwL1QqQWqDIUEiLEwD2oMySczlWIQygUtOyORohX0uLJlKkBlE7WJNEqZJVKgtLncJGeYAd5GdY1gYDwA0CoTC-gAcgDUZ7Zfb5VkNdgDMUVAZTYGDJSxDjjMShLGJNI+wJzY5bmLU+nM06WDm8wWhsWy5Lpckq5jQJkBGVRKdTKozhZLO2o8qtQY44dynSysmcGP3hPs7n835C8NRpNpkuvdWfZUpPkGwIVjWJquQKBGg7GB2ZQ0CYYhSDY17YAA7i88zkAAYiweDeEwhAAMYABaRCQAC2YAsAArkQs5FlEsQfmidqrnwggduIzYKCopw0DQdLlJSuISNgbRBpY1LrKcOSIShaFQJh2G4WAhHEWRlHUc+c4jOMUwVjKTHpGuiBiHU9YqFs6y8SqFSUiI4jWJYBKamSJIGNJqGkBhWE4fhRGkeRVEUE8rzvJ83x5r84LoAAGhEgxFgA6lgkSghC0KwgiSIyR5cleYpyl+WpunLvpNZ5A0Hb1AmwaSZS5iiLsWpklYwg9hILLDpl7mOvJ3lKb5qkBUFXKhbykUxRpCVJSlQrpaKLhZd1uU+Sp-lEIujEYgZLEIKeeK4lsgFtW1pRtrqO0CKswZRsGZJBsIQ7dC4TB4CweFwOw5DTngMRgAAjhRcDURAXAfGQABuLAANYfEiz2ve9jpfT9-2Awg4OvW89oJEVX7MeuuwyNgarNpU8akqdNRWPUxg8TQQjrDI9lSR1Ypw29sAfVASN-QDzw0eEdFxDjK5beuPYNJqhyWGamp05SchGHIvEXUIhrGQIDjDqgLAQHAPB3Bt3qGQgAC0F2E8SphCH+GqHEolIm0YLTO-T1u5Gq9SIfghDZYb37GybQj-pIag2zbJxCBGCiE200ikko9TyIh7J+3jiANv6FSDtSFSJ4SUcx328HBoSdKdCzLhWja+mOs6rqeKnot6kY5JRpIzIkh2EZbMq8GM8ISjwQ2iG3hmtdTo+jc1tkEEcXBKzWzIvGUhIKjGNS0iAcyZ6uRXOALZ5CnLQVVFTz60fYC1JxFzxOL8Wd8+0qcViEtH8inIhBE2lAFFMGfxuARMiIP8eQ6Z00MJHM6F1rDCVMDBOkcCVAPRHE9F67NObcxRs8f+21rBHiOvBQcZwWianlgScQJho7kkULkXeDggA */
87
+ readonly context: ({ input }: {
88
+ input: any;
89
+ }) => {
90
+ sessionRef: any;
91
+ voice: any;
92
+ languageModel: any;
93
+ speechBuffer: string;
94
+ firstMessage: any;
95
+ goodbyeMessage: any;
96
+ transferMessage: any;
97
+ transferPhoneNumber: any;
98
+ systemErrorMessage: any;
99
+ idleMessage: any;
100
+ idleTimeout: any;
101
+ maxIdleTimeoutCount: any;
102
+ idleTimeoutCount: number;
103
+ maxSpeechWaitTimeout: any;
104
+ isSpeaking: boolean;
105
+ sessionStartTime: number;
106
+ maxSessionDuration: any;
128
107
  };
129
- setSpeakingDone: {
130
- type: "setSpeakingDone";
131
- params: import("xstate").NonReducibleUnknown;
132
- };
133
- resetState: {
134
- type: "resetState";
135
- params: import("xstate").NonReducibleUnknown;
108
+ readonly id: "fnAI";
109
+ readonly initial: "greeting";
110
+ readonly states: {
111
+ readonly greeting: {
112
+ readonly always: {
113
+ readonly target: "idle";
114
+ readonly description: "Transition to idle after the initial greeting.";
115
+ };
116
+ readonly entry: {
117
+ readonly type: "greetUser";
118
+ };
119
+ };
120
+ readonly idle: {
121
+ readonly entry: {
122
+ readonly type: "cleanSpeech";
123
+ };
124
+ readonly on: {
125
+ readonly SPEECH_START: {
126
+ readonly target: "listeningToUser";
127
+ readonly description: "Event from VAD system.";
128
+ };
129
+ readonly SPEECH_RESULT: {
130
+ readonly target: "listeningToUser";
131
+ readonly description: "Detected speech before SPEECH_START event.";
132
+ readonly actions: readonly [{
133
+ readonly type: "appendSpeech";
134
+ }];
135
+ };
136
+ };
137
+ readonly after: {
138
+ readonly IDLE_TIMEOUT: readonly [{
139
+ readonly target: "hangup";
140
+ readonly actions: {
141
+ readonly type: "goodbye";
142
+ };
143
+ readonly guard: import("xstate/dist/declarations/src/guards").GuardPredicate<any, {
144
+ type: "SPEECH_START";
145
+ } | {
146
+ type: "SPEECH_END";
147
+ } | {
148
+ type: "SPEECH_RESULT";
149
+ speech: string;
150
+ responseTime: number;
151
+ }, unknown, {
152
+ type: "idleTimeoutCountExceedsMax";
153
+ params: undefined;
154
+ } | ({
155
+ type: "isSpeaking";
156
+ params: undefined;
157
+ } & import("xstate").ParameterizedObject)>;
158
+ }, {
159
+ readonly target: "transitioningToIdle";
160
+ readonly actions: readonly [{
161
+ readonly type: "increaseIdleTimeoutCount";
162
+ }, {
163
+ readonly type: "announceIdleTimeout";
164
+ }];
165
+ }];
166
+ };
167
+ };
168
+ readonly transitioningToIdle: {
169
+ readonly always: {
170
+ readonly target: "idle";
171
+ };
172
+ };
173
+ readonly listeningToUser: {
174
+ readonly entry: readonly [{
175
+ readonly type: "interruptPlayback";
176
+ }, {
177
+ readonly type: "resetIdleTimeoutCount";
178
+ }, {
179
+ readonly type: "setSpeaking";
180
+ }];
181
+ readonly on: {
182
+ readonly SPEECH_END: readonly [{
183
+ readonly target: "processingUserRequest";
184
+ readonly guard: "hasSpeechResult";
185
+ readonly actions: readonly [{
186
+ readonly type: "setSpeakingDone";
187
+ }];
188
+ readonly description: "Process the request immediately since we already speech.";
189
+ }, {
190
+ readonly target: "waitingForSpeechTimeout";
191
+ readonly guard: import("xstate/dist/declarations/src/guards").GuardPredicate<any, {
192
+ type: "SPEECH_END";
193
+ }, unknown, {
194
+ type: "hasSpeechResult";
195
+ params: undefined;
196
+ }>;
197
+ readonly actions: readonly [{
198
+ readonly type: "setSpeakingDone";
199
+ }];
200
+ readonly description: "Wait for more speech since we don't have any speech yet.";
201
+ }];
202
+ readonly SPEECH_RESULT: readonly [{
203
+ readonly actions: {
204
+ readonly type: "appendSpeech";
205
+ };
206
+ readonly guard: "isSpeaking";
207
+ readonly description: "The user is still speaking. With only want to append the speech.";
208
+ }];
209
+ };
210
+ };
211
+ readonly waitingForSpeechTimeout: {
212
+ readonly on: {
213
+ readonly SPEECH_START: {
214
+ readonly target: "listeningToUser";
215
+ readonly description: "User started speaking again.";
216
+ };
217
+ readonly SPEECH_RESULT: {
218
+ readonly target: "processingUserRequest";
219
+ readonly actions: {
220
+ readonly type: "appendSpeech";
221
+ };
222
+ readonly description: "Append final speech and process the request.";
223
+ };
224
+ };
225
+ readonly after: {
226
+ readonly MAX_SPEECH_WAIT_TIMEOUT: readonly [{
227
+ readonly target: "processingUserRequest";
228
+ readonly description: "Proceed to process the request as we have speech and the user is not speaking.";
229
+ readonly guard: "hasSpeechResult";
230
+ }, {
231
+ readonly target: "idle";
232
+ readonly description: "We have no speech and the user is not speaking. Return to idle.";
233
+ }];
234
+ };
235
+ };
236
+ readonly hangup: {
237
+ readonly type: "final";
238
+ };
239
+ readonly processingUserRequest: {
240
+ readonly on: {
241
+ readonly SPEECH_START: {
242
+ readonly target: "listeningToUser";
243
+ readonly description: "Event from VAD or similar system.";
244
+ readonly actions: readonly [{
245
+ readonly type: "cleanSpeech";
246
+ }];
247
+ };
248
+ };
249
+ readonly invoke: {
250
+ readonly src: "doProcessUserRequest";
251
+ readonly description: "Process the user request";
252
+ readonly input: ({ context }: {
253
+ context: any;
254
+ event: {
255
+ type: "SPEECH_START";
256
+ } | {
257
+ type: "SPEECH_END";
258
+ } | {
259
+ type: "SPEECH_RESULT";
260
+ speech: string;
261
+ responseTime: number;
262
+ };
263
+ self: import("xstate").ActorRef<import("xstate").MachineSnapshot<any, {
264
+ type: "SPEECH_START";
265
+ } | {
266
+ type: "SPEECH_END";
267
+ } | {
268
+ type: "SPEECH_RESULT";
269
+ speech: string;
270
+ responseTime: number;
271
+ }, Record<string, import("xstate").AnyActorRef>, import("xstate").StateValue, string, unknown, any, any>, {
272
+ type: "SPEECH_START";
273
+ } | {
274
+ type: "SPEECH_END";
275
+ } | {
276
+ type: "SPEECH_RESULT";
277
+ speech: string;
278
+ responseTime: number;
279
+ }, import("xstate").AnyEventObject>;
280
+ }) => {
281
+ context: any;
282
+ };
283
+ readonly onDone: {
284
+ readonly target: "idle";
285
+ };
286
+ };
287
+ };
136
288
  };
137
- }>, never, "IDLE_TIMEOUT" | "MAX_SPEECH_WAIT_TIMEOUT" | "SESSION_TIMEOUT", string, {
138
- conversationSettings: ConversationSettings;
139
- languageModel: LanguageModel;
140
- voice: Voice;
141
- }, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").MetaObject>>;
289
+ }>;
142
290
  export { machine };