@fonoster/autopilot 0.26.0 → 0.30.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 (138) hide show
  1. package/README.md +14 -51
  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/types.d.ts +1 -1
  8. package/dist/models/LanguageModelFactory.d.ts +5 -24
  9. package/dist/models/LanguageModelFactory.js +0 -1
  10. package/dist/models/createLanguageModel.d.ts +2 -2
  11. package/dist/models/evaluations/createEvalEffectiveConfig.d.ts +10 -106
  12. package/dist/models/evaluations/createEvalEffectiveConfig.js +47 -7
  13. package/dist/models/evaluations/createEvaluateIntelligence.d.ts +10 -20
  14. package/dist/models/evaluations/createEvaluateIntelligence.js +32 -23
  15. package/dist/models/evaluations/evalTestCases.d.ts +2 -2
  16. package/dist/models/evaluations/extractAiResponse.d.ts +2 -3
  17. package/dist/models/evaluations/index.d.ts +1 -0
  18. package/dist/models/evaluations/index.js +1 -0
  19. package/dist/models/evaluations/runEval.d.ts +2 -20
  20. package/dist/models/evaluations/session/EvalSession.d.ts +73 -0
  21. package/dist/models/evaluations/session/EvalSession.js +134 -0
  22. package/dist/models/evaluations/session/evaluateSessionScenario.d.ts +58 -0
  23. package/dist/models/evaluations/session/evaluateSessionScenario.js +182 -0
  24. package/dist/{vad → models/evaluations/session}/index.d.ts +3 -2
  25. package/dist/{vad → models/evaluations/session}/index.js +3 -2
  26. package/dist/models/evaluations/session/runSessionEval.d.ts +17 -0
  27. package/dist/models/evaluations/session/runSessionEval.js +59 -0
  28. package/dist/models/evaluations/types.d.ts +7 -6
  29. package/dist/models/types.d.ts +19 -1
  30. package/dist/session/Agent.d.ts +138 -0
  31. package/dist/session/Agent.js +474 -0
  32. package/dist/{loadAssistantFromAPI.d.ts → session/AsyncQueue.d.ts} +12 -7
  33. package/dist/session/AsyncQueue.js +67 -0
  34. package/dist/{machine/guards/index.d.ts → session/config.d.ts} +2 -2
  35. package/dist/session/config.js +27 -0
  36. package/dist/session/convertLegacyAssistant.d.ts +77 -0
  37. package/dist/session/convertLegacyAssistant.js +118 -0
  38. package/dist/session/createAutopilot.d.ts +47 -0
  39. package/dist/session/createAutopilot.js +119 -0
  40. package/dist/session/hosted.d.ts +456 -0
  41. package/dist/session/hosted.js +506 -0
  42. package/dist/{assistants → session}/index.d.ts +11 -2
  43. package/dist/{machine/actors → session}/index.js +11 -3
  44. package/dist/{machine/actions/appendSpeech.js → session/knowledge.d.ts} +14 -17
  45. package/dist/session/knowledge.js +10 -0
  46. package/dist/session/llm.d.ts +86 -0
  47. package/dist/session/llm.js +83 -0
  48. package/dist/session/machine.d.ts +206 -0
  49. package/dist/session/machine.js +126 -0
  50. package/dist/session/main.js +44 -0
  51. package/dist/session/sentences.d.ts +5 -0
  52. package/dist/session/sentences.js +53 -0
  53. package/dist/{machine/actors/index.d.ts → session/think.d.ts} +2 -3
  54. package/dist/{machine/actions/announceSystemError.js → session/think.js} +8 -10
  55. package/dist/session/tools.d.ts +22 -0
  56. package/dist/session/tools.js +83 -0
  57. package/dist/tools/builtin/transferToolDefinition.js +1 -1
  58. package/dist/voice/index.d.ts +0 -1
  59. package/dist/voice/index.js +0 -1
  60. package/dist/voice/types.d.ts +5 -18
  61. package/package.json +13 -14
  62. package/dist/Autopilot.d.ts +0 -14
  63. package/dist/Autopilot.js +0 -133
  64. package/dist/assistants/index.js +0 -36
  65. package/dist/assistants/loadAndValidateAssistant.d.ts +0 -3
  66. package/dist/assistants/loadAndValidateAssistant.js +0 -49
  67. package/dist/assistants/types.d.ts +0 -24
  68. package/dist/assistants/types.js +0 -2
  69. package/dist/envs.d.ts +0 -15
  70. package/dist/envs.js +0 -78
  71. package/dist/handleVoiceRequest.d.ts +0 -3
  72. package/dist/handleVoiceRequest.js +0 -167
  73. package/dist/loadAssistantConfigFromFile.d.ts +0 -3
  74. package/dist/loadAssistantConfigFromFile.js +0 -68
  75. package/dist/loadAssistantFromAPI.js +0 -98
  76. package/dist/machine/actions/announceSystemError.d.ts +0 -4
  77. package/dist/machine/actions/appendSpeech.d.ts +0 -1
  78. package/dist/machine/actions/cleanSpeech.d.ts +0 -1
  79. package/dist/machine/actions/cleanSpeech.js +0 -23
  80. package/dist/machine/actions/goodbye.d.ts +0 -4
  81. package/dist/machine/actions/goodbye.js +0 -31
  82. package/dist/machine/actions/increaseIdleTimeoutCount.d.ts +0 -1
  83. package/dist/machine/actions/increaseIdleTimeoutCount.js +0 -31
  84. package/dist/machine/actions/index.d.ts +0 -26
  85. package/dist/machine/actions/index.js +0 -37
  86. package/dist/machine/actions/interruptPlayback.d.ts +0 -4
  87. package/dist/machine/actions/interruptPlayback.js +0 -43
  88. package/dist/machine/actions/resetIdleTimeoutCount.d.ts +0 -1
  89. package/dist/machine/actions/resetIdleTimeoutCount.js +0 -31
  90. package/dist/machine/actions/resetState.d.ts +0 -1
  91. package/dist/machine/actions/resetState.js +0 -32
  92. package/dist/machine/actors/doAnnounceIdleTimeout.d.ts +0 -4
  93. package/dist/machine/actors/doAnnounceIdleTimeout.js +0 -41
  94. package/dist/machine/actors/doGreetUser.d.ts +0 -4
  95. package/dist/machine/actors/doGreetUser.js +0 -45
  96. package/dist/machine/actors/doProcessUserRequest.d.ts +0 -4
  97. package/dist/machine/actors/doProcessUserRequest.js +0 -75
  98. package/dist/machine/context.d.ts +0 -52
  99. package/dist/machine/context.js +0 -28
  100. package/dist/machine/delays.d.ts +0 -30
  101. package/dist/machine/delays.js +0 -37
  102. package/dist/machine/guards/hasSpeechResult.d.ts +0 -4
  103. package/dist/machine/guards/hasSpeechResult.js +0 -30
  104. package/dist/machine/guards/idleTimeoutCountExceedsMax.d.ts +0 -4
  105. package/dist/machine/guards/idleTimeoutCountExceedsMax.js +0 -31
  106. package/dist/machine/guards/index.js +0 -25
  107. package/dist/machine/index.d.ts +0 -19
  108. package/dist/machine/index.js +0 -23
  109. package/dist/machine/machine.d.ts +0 -408
  110. package/dist/machine/machine.js +0 -206
  111. package/dist/machine/setup.d.ts +0 -328
  112. package/dist/machine/setup.js +0 -116
  113. package/dist/machine/types.d.ts +0 -54
  114. package/dist/machine/types.js +0 -2
  115. package/dist/sendConversationEndedEvent.d.ts +0 -32
  116. package/dist/sendConversationEndedEvent.js +0 -66
  117. package/dist/sendConversationStartedEvent.d.ts +0 -6
  118. package/dist/sendConversationStartedEvent.js +0 -63
  119. package/dist/server.d.ts +0 -2
  120. package/dist/server.js +0 -25
  121. package/dist/types.d.ts +0 -40
  122. package/dist/types.js +0 -8
  123. package/dist/vad/SileroVad.d.ts +0 -18
  124. package/dist/vad/SileroVad.js +0 -40
  125. package/dist/vad/SileroVadModel.d.ts +0 -14
  126. package/dist/vad/SileroVadModel.js +0 -83
  127. package/dist/vad/chunkToFloat32Array.d.ts +0 -20
  128. package/dist/vad/chunkToFloat32Array.js +0 -34
  129. package/dist/vad/createVad.d.ts +0 -3
  130. package/dist/vad/createVad.js +0 -126
  131. package/dist/vad/types.d.ts +0 -60
  132. package/dist/vad/types.js +0 -2
  133. package/dist/vadWorker.js +0 -36
  134. package/dist/voice/Voice.d.ts +0 -61
  135. package/dist/voice/Voice.js +0 -96
  136. package/dist/voiceServerSetup.d.ts +0 -2
  137. package/dist/voiceServerSetup.js +0 -29
  138. /package/dist/{vadWorker.d.ts → session/main.d.ts} +0 -0
@@ -1,408 +0,0 @@
1
- declare const machine: import("xstate").StateMachine<any, import("./types").AutopilotEvents, {
2
- [x: string]: import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<void, {
3
- context: import("./types").AutopilotContext;
4
- }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<void, {
5
- context: import("./types").AutopilotContext;
6
- }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<void, {
7
- context: import("./types").AutopilotContext;
8
- }, import("xstate").EventObject>>;
9
- }, import("xstate").Values<{
10
- doProcessUserRequest: {
11
- src: "doProcessUserRequest";
12
- logic: import("xstate").PromiseActorLogic<void, {
13
- context: import("./types").AutopilotContext;
14
- }, import("xstate").EventObject>;
15
- id: string;
16
- };
17
- doGreetUser: {
18
- src: "doGreetUser";
19
- logic: import("xstate").PromiseActorLogic<void, {
20
- context: import("./types").AutopilotContext;
21
- }, import("xstate").EventObject>;
22
- id: string;
23
- };
24
- doAnnounceIdleTimeout: {
25
- src: "doAnnounceIdleTimeout";
26
- logic: import("xstate").PromiseActorLogic<void, {
27
- context: import("./types").AutopilotContext;
28
- }, import("xstate").EventObject>;
29
- id: string;
30
- };
31
- }>, import("xstate").Values<{
32
- appendSpeech: {
33
- type: "appendSpeech";
34
- params: unknown;
35
- };
36
- cleanSpeech: {
37
- type: "cleanSpeech";
38
- params: unknown;
39
- };
40
- increaseIdleTimeoutCount: {
41
- type: "increaseIdleTimeoutCount";
42
- params: unknown;
43
- };
44
- resetIdleTimeoutCount: {
45
- type: "resetIdleTimeoutCount";
46
- params: unknown;
47
- };
48
- resetState: {
49
- type: "resetState";
50
- params: unknown;
51
- };
52
- goodbye: {
53
- type: "goodbye";
54
- params: unknown;
55
- };
56
- announceSystemError: {
57
- type: "announceSystemError";
58
- params: unknown;
59
- };
60
- interruptPlayback: {
61
- type: "interruptPlayback";
62
- params: unknown;
63
- };
64
- }>, import("xstate").Values<{
65
- idleTimeoutCountExceedsMax: {
66
- type: "idleTimeoutCountExceedsMax";
67
- params: unknown;
68
- };
69
- hasSpeechResult: {
70
- type: "hasSpeechResult";
71
- params: unknown;
72
- };
73
- }>, "IDLE_TIMEOUT" | "MAX_SPEECH_WAIT_TIMEOUT" | "MAX_SESSION_DURATION", "hangup" | "greeting" | "idle" | "listeningToUser" | "announcingIdleTimeout" | "waitingForSpeechTimeout" | "processingUserRequest", string, {
74
- conversationSettings: import("..").ConversationSettings;
75
- languageModel: import("..").LanguageModel;
76
- voice: import("..").Voice;
77
- }, {}, import("xstate").EventObject, import("xstate").MetaObject, {
78
- readonly context: ({ input }: {
79
- input: {
80
- voice: import("..").Voice;
81
- languageModel: import("..").LanguageModel;
82
- conversationSettings: import("..").ConversationSettings;
83
- };
84
- }) => {
85
- mediaSessionRef: string;
86
- voice: import("..").Voice;
87
- languageModel: import("..").LanguageModel;
88
- speechBuffer: string;
89
- firstMessage: string;
90
- goodbyeMessage: string;
91
- transferMessage: string;
92
- transferPhoneNumber: string;
93
- transferTimeout: number;
94
- systemErrorMessage: string;
95
- idleMessage: string;
96
- idleTimeout: number;
97
- maxIdleTimeoutCount: number;
98
- idleTimeoutCount: number;
99
- maxSpeechWaitTimeout: number;
100
- allowUserBargeIn: boolean;
101
- sessionStartTime: number;
102
- maxSessionDuration: number;
103
- initialDtmf: string;
104
- previousState: any;
105
- hasLateSpeech: boolean;
106
- isFirstTurn: boolean;
107
- };
108
- readonly id: "fnAI";
109
- readonly initial: "greeting";
110
- readonly states: {
111
- readonly greeting: {
112
- readonly invoke: {
113
- readonly src: "doGreetUser";
114
- readonly description: "Answer the call and play the first message";
115
- readonly input: ({ context }: {
116
- context: any;
117
- event: import("./types").AutopilotEvents;
118
- self: import("xstate").ActorRef<import("xstate").MachineSnapshot<any, import("./types").AutopilotEvents, Record<string, import("xstate").AnyActorRef>, import("xstate").StateValue, string, unknown, any, any>, import("./types").AutopilotEvents, import("xstate").AnyEventObject>;
119
- }) => {
120
- context: any;
121
- };
122
- readonly onDone: {
123
- readonly target: "idle";
124
- readonly description: "Transition to idle after the initial greeting.";
125
- };
126
- readonly onError: {
127
- readonly target: "idle";
128
- };
129
- };
130
- readonly on: {
131
- readonly SPEECH_START: {
132
- readonly target: "listeningToUser";
133
- readonly description: "The user barged in during the greeting.";
134
- };
135
- };
136
- };
137
- readonly idle: {
138
- readonly entry: readonly [{
139
- readonly type: "cleanSpeech";
140
- }];
141
- readonly on: {
142
- readonly SPEECH_START: {
143
- readonly target: "listeningToUser";
144
- readonly description: "Event from VAD system.";
145
- };
146
- };
147
- readonly after: {
148
- readonly IDLE_TIMEOUT: readonly [{
149
- readonly target: "hangup";
150
- readonly actions: {
151
- readonly type: "goodbye";
152
- };
153
- readonly guard: import("xstate/dist/declarations/src/guards").GuardPredicate<any, import("./types").AutopilotEvents, unknown, {
154
- type: "idleTimeoutCountExceedsMax";
155
- params: undefined;
156
- }>;
157
- }, {
158
- readonly target: "announcingIdleTimeout";
159
- }];
160
- };
161
- };
162
- readonly announcingIdleTimeout: {
163
- readonly entry: readonly [{
164
- readonly type: "increaseIdleTimeoutCount";
165
- }];
166
- readonly invoke: {
167
- readonly src: "doAnnounceIdleTimeout";
168
- readonly description: "Play the idle message";
169
- readonly input: ({ context }: {
170
- context: any;
171
- event: import("./types").AutopilotEvents;
172
- self: import("xstate").ActorRef<import("xstate").MachineSnapshot<any, import("./types").AutopilotEvents, Record<string, import("xstate").AnyActorRef>, import("xstate").StateValue, string, unknown, any, any>, import("./types").AutopilotEvents, import("xstate").AnyEventObject>;
173
- }) => {
174
- context: any;
175
- };
176
- readonly onDone: {
177
- readonly target: "idle";
178
- readonly description: "Re-arm the idle clock once the idle message finishes.";
179
- };
180
- readonly onError: {
181
- readonly target: "idle";
182
- };
183
- };
184
- readonly on: {
185
- readonly SPEECH_START: {
186
- readonly target: "listeningToUser";
187
- readonly description: "The user spoke while the idle message was playing.";
188
- };
189
- };
190
- };
191
- readonly listeningToUser: {
192
- readonly entry: readonly [{
193
- readonly type: "interruptPlayback";
194
- }, {
195
- readonly type: "resetIdleTimeoutCount";
196
- }, import("xstate").ActionFunction<any, import("./types").AutopilotEvents, import("./types").AutopilotEvents, undefined, import("xstate").Values<{
197
- doProcessUserRequest: {
198
- src: "doProcessUserRequest";
199
- logic: import("xstate").PromiseActorLogic<void, {
200
- context: import("./types").AutopilotContext;
201
- }, import("xstate").EventObject>;
202
- id: string;
203
- };
204
- doGreetUser: {
205
- src: "doGreetUser";
206
- logic: import("xstate").PromiseActorLogic<void, {
207
- context: import("./types").AutopilotContext;
208
- }, import("xstate").EventObject>;
209
- id: string;
210
- };
211
- doAnnounceIdleTimeout: {
212
- src: "doAnnounceIdleTimeout";
213
- logic: import("xstate").PromiseActorLogic<void, {
214
- context: import("./types").AutopilotContext;
215
- }, import("xstate").EventObject>;
216
- id: string;
217
- };
218
- }>, never, never, never, never>];
219
- readonly on: {
220
- readonly SPEECH_RESULT: {
221
- readonly target: "waitingForSpeechTimeout";
222
- readonly actions: {
223
- readonly type: "appendSpeech";
224
- };
225
- readonly description: "Append final speech and process the request.";
226
- readonly reenter: true;
227
- };
228
- };
229
- readonly after: {
230
- readonly IDLE_TIMEOUT: readonly [{
231
- readonly target: "hangup";
232
- readonly actions: {
233
- readonly type: "goodbye";
234
- };
235
- readonly guard: import("xstate/dist/declarations/src/guards").GuardPredicate<any, import("./types").AutopilotEvents, unknown, {
236
- type: "idleTimeoutCountExceedsMax";
237
- params: undefined;
238
- }>;
239
- }, {
240
- readonly target: "announcingIdleTimeout";
241
- }];
242
- };
243
- };
244
- readonly waitingForSpeechTimeout: {
245
- readonly on: {
246
- readonly SPEECH_START: {
247
- readonly target: "listeningToUser";
248
- readonly description: "User started speaking again.";
249
- readonly guard: ({ context }: import("xstate/dist/declarations/src/guards").GuardArgs<any, {
250
- type: "SPEECH_START";
251
- }>) => any;
252
- };
253
- readonly SPEECH_RESULT: {
254
- readonly target: "waitingForSpeechTimeout";
255
- readonly description: "Capture late speech, but only once.";
256
- readonly guard: ({ context }: import("xstate/dist/declarations/src/guards").GuardArgs<any, {
257
- type: "SPEECH_RESULT";
258
- speech: string;
259
- responseTime: number;
260
- }>) => boolean;
261
- readonly actions: readonly [{
262
- readonly type: "appendSpeech";
263
- }, import("xstate").ActionFunction<any, {
264
- type: "SPEECH_RESULT";
265
- speech: string;
266
- responseTime: number;
267
- }, import("./types").AutopilotEvents, undefined, import("xstate").Values<{
268
- doProcessUserRequest: {
269
- src: "doProcessUserRequest";
270
- logic: import("xstate").PromiseActorLogic<void, {
271
- context: import("./types").AutopilotContext;
272
- }, import("xstate").EventObject>;
273
- id: string;
274
- };
275
- doGreetUser: {
276
- src: "doGreetUser";
277
- logic: import("xstate").PromiseActorLogic<void, {
278
- context: import("./types").AutopilotContext;
279
- }, import("xstate").EventObject>;
280
- id: string;
281
- };
282
- doAnnounceIdleTimeout: {
283
- src: "doAnnounceIdleTimeout";
284
- logic: import("xstate").PromiseActorLogic<void, {
285
- context: import("./types").AutopilotContext;
286
- }, import("xstate").EventObject>;
287
- id: string;
288
- };
289
- }>, never, never, never, never>];
290
- };
291
- };
292
- readonly after: {
293
- readonly MAX_SPEECH_WAIT_TIMEOUT: {
294
- readonly target: "processingUserRequest";
295
- readonly description: "This will give the person time to breathe and speak again.";
296
- readonly reenter: true;
297
- };
298
- };
299
- };
300
- readonly hangup: {
301
- readonly type: "final";
302
- };
303
- readonly processingUserRequest: {
304
- readonly on: {
305
- readonly SPEECH_START: {
306
- readonly target: "listeningToUser";
307
- readonly description: "Event from VAD or similar system.";
308
- readonly guard: ({ context }: import("xstate/dist/declarations/src/guards").GuardArgs<any, {
309
- type: "SPEECH_START";
310
- }>) => any;
311
- readonly actions: readonly [{
312
- readonly type: "cleanSpeech";
313
- }];
314
- };
315
- readonly SPEECH_RESULT: {
316
- readonly target: "processingUserRequest";
317
- readonly description: "Capture only a single late speech across the entire request processing.";
318
- readonly guard: ({ context }: import("xstate/dist/declarations/src/guards").GuardArgs<any, {
319
- type: "SPEECH_RESULT";
320
- speech: string;
321
- responseTime: number;
322
- }>) => boolean;
323
- readonly actions: readonly [{
324
- readonly type: "interruptPlayback";
325
- }, {
326
- readonly type: "appendSpeech";
327
- }, import("xstate").ActionFunction<any, {
328
- type: "SPEECH_RESULT";
329
- speech: string;
330
- responseTime: number;
331
- }, import("./types").AutopilotEvents, undefined, import("xstate").Values<{
332
- doProcessUserRequest: {
333
- src: "doProcessUserRequest";
334
- logic: import("xstate").PromiseActorLogic<void, {
335
- context: import("./types").AutopilotContext;
336
- }, import("xstate").EventObject>;
337
- id: string;
338
- };
339
- doGreetUser: {
340
- src: "doGreetUser";
341
- logic: import("xstate").PromiseActorLogic<void, {
342
- context: import("./types").AutopilotContext;
343
- }, import("xstate").EventObject>;
344
- id: string;
345
- };
346
- doAnnounceIdleTimeout: {
347
- src: "doAnnounceIdleTimeout";
348
- logic: import("xstate").PromiseActorLogic<void, {
349
- context: import("./types").AutopilotContext;
350
- }, import("xstate").EventObject>;
351
- id: string;
352
- };
353
- }>, never, never, never, never>];
354
- readonly reenter: true;
355
- };
356
- };
357
- readonly invoke: {
358
- readonly src: "doProcessUserRequest";
359
- readonly description: "Process the user request";
360
- readonly input: ({ context }: {
361
- context: any;
362
- event: import("./types").AutopilotEvents;
363
- self: import("xstate").ActorRef<import("xstate").MachineSnapshot<any, import("./types").AutopilotEvents, Record<string, import("xstate").AnyActorRef>, import("xstate").StateValue, string, unknown, any, any>, import("./types").AutopilotEvents, import("xstate").AnyEventObject>;
364
- }) => {
365
- context: any;
366
- };
367
- readonly onDone: {
368
- readonly target: "listeningToUser";
369
- readonly reenter: true;
370
- readonly actions: readonly [{
371
- readonly type: "cleanSpeech";
372
- }, import("xstate").ActionFunction<any, import("xstate").DoneActorEvent<void, string>, import("./types").AutopilotEvents, undefined, import("xstate").Values<{
373
- doProcessUserRequest: {
374
- src: "doProcessUserRequest";
375
- logic: import("xstate").PromiseActorLogic<void, {
376
- context: import("./types").AutopilotContext;
377
- }, import("xstate").EventObject>;
378
- id: string;
379
- };
380
- doGreetUser: {
381
- src: "doGreetUser";
382
- logic: import("xstate").PromiseActorLogic<void, {
383
- context: import("./types").AutopilotContext;
384
- }, import("xstate").EventObject>;
385
- id: string;
386
- };
387
- doAnnounceIdleTimeout: {
388
- src: "doAnnounceIdleTimeout";
389
- logic: import("xstate").PromiseActorLogic<void, {
390
- context: import("./types").AutopilotContext;
391
- }, import("xstate").EventObject>;
392
- id: string;
393
- };
394
- }>, never, never, never, never>];
395
- };
396
- };
397
- };
398
- };
399
- readonly after: {
400
- readonly MAX_SESSION_DURATION: {
401
- readonly target: ".hangup";
402
- readonly actions: {
403
- readonly type: "goodbye";
404
- };
405
- };
406
- };
407
- }>;
408
- export { machine };
@@ -1,206 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.machine = 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
- const xstate_2 = require("xstate");
24
- const context_1 = require("./context");
25
- const setup_1 = require("./setup");
26
- const machine = setup_1.machineSetup.createMachine({
27
- context: context_1.context,
28
- id: "fnAI",
29
- initial: "greeting",
30
- states: {
31
- greeting: {
32
- // The greeting is invoked (not fired-and-forgotten) so the machine only
33
- // moves to "idle", and therefore only arms the idle clock, once the
34
- // first message has been fully played.
35
- invoke: {
36
- src: "doGreetUser",
37
- description: "Answer the call and play the first message",
38
- input: ({ context }) => ({ context }),
39
- onDone: {
40
- target: "idle",
41
- description: "Transition to idle after the initial greeting."
42
- },
43
- onError: {
44
- target: "idle"
45
- }
46
- },
47
- on: {
48
- SPEECH_START: {
49
- target: "listeningToUser",
50
- description: "The user barged in during the greeting."
51
- }
52
- }
53
- },
54
- idle: {
55
- entry: [{ type: "cleanSpeech" }],
56
- on: {
57
- SPEECH_START: {
58
- target: "listeningToUser",
59
- description: "Event from VAD system."
60
- }
61
- },
62
- after: {
63
- IDLE_TIMEOUT: [
64
- {
65
- target: "hangup",
66
- actions: { type: "goodbye" },
67
- guard: (0, xstate_1.and)(["idleTimeoutCountExceedsMax"])
68
- },
69
- {
70
- target: "announcingIdleTimeout"
71
- }
72
- ]
73
- }
74
- },
75
- announcingIdleTimeout: {
76
- // A dedicated state, with no IDLE_TIMEOUT of its own, so the idle clock
77
- // is stopped while the idle message plays. It is re-armed only when the
78
- // message finishes and the machine goes back to "idle". This prevents
79
- // back-to-back idle announcements (and a premature hangup) when the
80
- // idle timeout is short relative to the message duration.
81
- entry: [{ type: "increaseIdleTimeoutCount" }],
82
- invoke: {
83
- src: "doAnnounceIdleTimeout",
84
- description: "Play the idle message",
85
- input: ({ context }) => ({ context }),
86
- onDone: {
87
- target: "idle",
88
- description: "Re-arm the idle clock once the idle message finishes."
89
- },
90
- onError: {
91
- target: "idle"
92
- }
93
- },
94
- on: {
95
- SPEECH_START: {
96
- target: "listeningToUser",
97
- description: "The user spoke while the idle message was playing."
98
- }
99
- }
100
- },
101
- listeningToUser: {
102
- entry: [
103
- { type: "interruptPlayback" },
104
- { type: "resetIdleTimeoutCount" },
105
- (0, xstate_2.assign)({ hasLateSpeech: false })
106
- ],
107
- on: {
108
- SPEECH_RESULT: {
109
- target: "waitingForSpeechTimeout",
110
- actions: {
111
- type: "appendSpeech"
112
- },
113
- description: "Append final speech and process the request.",
114
- reenter: true
115
- }
116
- },
117
- after: {
118
- IDLE_TIMEOUT: [
119
- {
120
- target: "hangup",
121
- actions: { type: "goodbye" },
122
- guard: (0, xstate_1.and)(["idleTimeoutCountExceedsMax"])
123
- },
124
- {
125
- target: "announcingIdleTimeout"
126
- }
127
- ]
128
- }
129
- },
130
- waitingForSpeechTimeout: {
131
- on: {
132
- SPEECH_START: {
133
- target: "listeningToUser",
134
- description: "User started speaking again.",
135
- guard: ({ context }) => context.allowUserBargeIn
136
- },
137
- SPEECH_RESULT: {
138
- target: "waitingForSpeechTimeout",
139
- description: "Capture late speech, but only once.",
140
- guard: ({ context }) => !context.hasLateSpeech,
141
- actions: [{ type: "appendSpeech" }, (0, xstate_2.assign)({ hasLateSpeech: true })]
142
- }
143
- },
144
- after: {
145
- MAX_SPEECH_WAIT_TIMEOUT: {
146
- target: "processingUserRequest",
147
- description: "This will give the person time to breathe and speak again.",
148
- reenter: true
149
- }
150
- }
151
- },
152
- hangup: {
153
- type: "final"
154
- },
155
- processingUserRequest: {
156
- on: {
157
- SPEECH_START: {
158
- target: "listeningToUser",
159
- description: "Event from VAD or similar system.",
160
- guard: ({ context }) => context.allowUserBargeIn,
161
- // We assume that the user wants to steer the conversation
162
- // back to the agent so we clean the speech buffer
163
- actions: [{ type: "cleanSpeech" }]
164
- },
165
- SPEECH_RESULT: {
166
- target: "processingUserRequest",
167
- description: "Capture only a single late speech across the entire request processing.",
168
- guard: ({ context }) => context.allowUserBargeIn && !context.hasLateSpeech,
169
- actions: [
170
- { type: "interruptPlayback" },
171
- { type: "appendSpeech" },
172
- (0, xstate_2.assign)(({ self }) => {
173
- return {
174
- previousState: self.getSnapshot().value,
175
- hasLateSpeech: true
176
- };
177
- })
178
- ],
179
- reenter: true
180
- }
181
- },
182
- invoke: {
183
- src: "doProcessUserRequest",
184
- description: "Process the user request",
185
- input: ({ context }) => ({ context }),
186
- onDone: {
187
- target: "listeningToUser",
188
- reenter: true,
189
- actions: [
190
- { type: "cleanSpeech" },
191
- (0, xstate_2.assign)({
192
- isFirstTurn: false
193
- })
194
- ]
195
- }
196
- }
197
- }
198
- },
199
- after: {
200
- MAX_SESSION_DURATION: {
201
- target: ".hangup",
202
- actions: { type: "goodbye" }
203
- }
204
- }
205
- });
206
- exports.machine = machine;