@fonoster/autopilot 0.12.7 → 0.12.9

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.
@@ -133,7 +133,12 @@ async function handleVoiceRequest(req, res) {
133
133
  })
134
134
  .filter(Boolean);
135
135
  if (assistantConfig.eventsHook?.url) {
136
- await (0, sendConversationEndedEvent_1.sendConversationEndedEvent)(assistantConfig.eventsHook, chatHistory, callerNumber);
136
+ await (0, sendConversationEndedEvent_1.sendConversationEndedEvent)(assistantConfig.eventsHook, {
137
+ chatHistory: chatHistory,
138
+ phone: ingressNumber,
139
+ appRef,
140
+ sessionRef
141
+ });
137
142
  }
138
143
  });
139
144
  }
@@ -25,6 +25,4 @@ export { increaseIdleTimeoutCount } from "./increaseIdleTimeoutCount";
25
25
  export { cleanSpeech } from "./cleanSpeech";
26
26
  export { appendSpeech } from "./appendSpeech";
27
27
  export { resetIdleTimeoutCount } from "./resetIdleTimeoutCount";
28
- export { setSpeaking } from "./setSpeaking";
29
- export { setSpeakingDone } from "./setSpeakingDone";
30
28
  export { resetState } from "./resetState";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resetState = exports.setSpeakingDone = exports.setSpeaking = exports.resetIdleTimeoutCount = exports.appendSpeech = exports.cleanSpeech = exports.increaseIdleTimeoutCount = exports.announceIdleTimeout = exports.interruptPlayback = exports.announceSystemError = exports.goodbye = exports.greetUser = void 0;
3
+ exports.resetState = exports.resetIdleTimeoutCount = exports.appendSpeech = exports.cleanSpeech = exports.increaseIdleTimeoutCount = exports.announceIdleTimeout = exports.interruptPlayback = exports.announceSystemError = exports.goodbye = exports.greetUser = void 0;
4
4
  /**
5
5
  * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
6
  * http://github.com/fonoster/fonoster
@@ -37,9 +37,5 @@ var appendSpeech_1 = require("./appendSpeech");
37
37
  Object.defineProperty(exports, "appendSpeech", { enumerable: true, get: function () { return appendSpeech_1.appendSpeech; } });
38
38
  var resetIdleTimeoutCount_1 = require("./resetIdleTimeoutCount");
39
39
  Object.defineProperty(exports, "resetIdleTimeoutCount", { enumerable: true, get: function () { return resetIdleTimeoutCount_1.resetIdleTimeoutCount; } });
40
- var setSpeaking_1 = require("./setSpeaking");
41
- Object.defineProperty(exports, "setSpeaking", { enumerable: true, get: function () { return setSpeaking_1.setSpeaking; } });
42
- var setSpeakingDone_1 = require("./setSpeakingDone");
43
- Object.defineProperty(exports, "setSpeakingDone", { enumerable: true, get: function () { return setSpeakingDone_1.setSpeakingDone; } });
44
40
  var resetState_1 = require("./resetState");
45
41
  Object.defineProperty(exports, "resetState", { enumerable: true, get: function () { return resetState_1.resetState; } });
@@ -27,7 +27,6 @@ exports.resetState = (0, xstate_1.assign)(({ context }) => {
27
27
  return {
28
28
  ...context,
29
29
  speechBuffer: "",
30
- idleTimeoutCount: 0,
31
- isSpeaking: false
30
+ idleTimeoutCount: 0
32
31
  };
33
32
  });
@@ -42,7 +42,6 @@ declare const context: ({ input }: {
42
42
  idleTimeoutCount: number;
43
43
  maxSpeechWaitTimeout: number;
44
44
  allowUserBargeIn: boolean;
45
- isSpeaking: boolean;
46
45
  sessionStartTime: number;
47
46
  maxSessionDuration: number;
48
47
  initialDtmf: string;
@@ -18,7 +18,6 @@ const context = ({ input }) => ({
18
18
  idleTimeoutCount: 0,
19
19
  maxSpeechWaitTimeout: input.conversationSettings.maxSpeechWaitTimeout,
20
20
  allowUserBargeIn: input.conversationSettings.allowUserBargeIn,
21
- isSpeaking: false,
22
21
  sessionStartTime: Date.now(),
23
22
  maxSessionDuration: input.conversationSettings.maxSessionDuration,
24
23
  initialDtmf: input.conversationSettings.initialDtmf
@@ -18,4 +18,3 @@
18
18
  */
19
19
  export { idleTimeoutCountExceedsMax } from "./idleTimeoutCountExceedsMax";
20
20
  export { hasSpeechResult } from "./hasSpeechResult";
21
- export { isSpeaking } from "./isSpeaking";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isSpeaking = exports.hasSpeechResult = exports.idleTimeoutCountExceedsMax = void 0;
3
+ exports.hasSpeechResult = exports.idleTimeoutCountExceedsMax = void 0;
4
4
  /**
5
5
  * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
6
  * http://github.com/fonoster/fonoster
@@ -23,5 +23,3 @@ var idleTimeoutCountExceedsMax_1 = require("./idleTimeoutCountExceedsMax");
23
23
  Object.defineProperty(exports, "idleTimeoutCountExceedsMax", { enumerable: true, get: function () { return idleTimeoutCountExceedsMax_1.idleTimeoutCountExceedsMax; } });
24
24
  var hasSpeechResult_1 = require("./hasSpeechResult");
25
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; } });
@@ -29,14 +29,6 @@ declare const machine: import("xstate").StateMachine<any, import("./types").Auto
29
29
  type: "resetState";
30
30
  params: unknown;
31
31
  };
32
- setSpeaking: {
33
- type: "setSpeaking";
34
- params: unknown;
35
- };
36
- setSpeakingDone: {
37
- type: "setSpeakingDone";
38
- params: unknown;
39
- };
40
32
  greetUser: {
41
33
  type: "greetUser";
42
34
  params: unknown;
@@ -58,10 +50,6 @@ declare const machine: import("xstate").StateMachine<any, import("./types").Auto
58
50
  params: unknown;
59
51
  };
60
52
  }>, import("xstate").Values<{
61
- isSpeaking: {
62
- type: "isSpeaking";
63
- params: unknown;
64
- };
65
53
  idleTimeoutCountExceedsMax: {
66
54
  type: "idleTimeoutCountExceedsMax";
67
55
  params: unknown;
@@ -70,12 +58,12 @@ declare const machine: import("xstate").StateMachine<any, import("./types").Auto
70
58
  type: "hasSpeechResult";
71
59
  params: unknown;
72
60
  };
73
- }>, "IDLE_TIMEOUT" | "MAX_SPEECH_WAIT_TIMEOUT" | "MAX_SESSION_DURATION", "hangup" | "greeting" | "idle" | "listeningToUser" | "transitioningToIdle" | "waitingForSpeechTimeout" | "processingUserRequest", string, {
61
+ }>, "IDLE_TIMEOUT" | "MAX_SPEECH_WAIT_TIMEOUT" | "MAX_SESSION_DURATION", "hangup" | "greeting" | "idle" | "listeningToUser" | "waitingForSpeechTimeout" | "processingUserRequest", string, {
74
62
  conversationSettings: import("..").ConversationSettings;
75
63
  languageModel: import("..").LanguageModel;
76
64
  voice: import("..").Voice;
77
65
  }, {}, import("xstate").EventObject, import("xstate").MetaObject, {
78
- /** @xstate-layout N4IgpgJg5mDOIC5QDMB2BBAkgYgB6wBcBDAsAOiOVICcAKAWXQA0B9AZQFE23MB5AORYARAKoAldABU+-AJTY0WANoAGALqJQABwD2sAJYF9O1JpC5EAWgDMAJgCcZAGwOAjAA4V9pyusB2e3cAGhAAT0RbAFYAFjIHJwDrJ2jXWxU06IBfTJDFTDIoajAwI1QobFUNJBBdAyMTMwsED1cyf28-O08nJ3dXJxDwhHtrSLJ7Px6o+1TbUb9s3Ix8-QgAGzBsNgAFDg4AYQAJdkl0MUlKs1rDY1NqpvsVPzJ3SLm-W3dozoS-QcQ-O5bOMVE5-H4VB4AtFbIsQHkyKsNnhCCRyJQaLRMEIADIcFjSegcXgiSTyBFIsCXarXep3UBNGIqcaRPqBeyPXxOSL-ZrWVytVIzSL2WzRFQqaKRaxwinrTb4YikChUMB0bF4gmYIkkskKZaI+VKVxVbR6G4Ne6IayOXoTQEpdIqSJg3kC9y2qW2b3eIHRKWyg0EahEVB1W76MqSHSYeUVdRXc10xrWr7jMG2blfdzWaLWSVu1xeMgQwGigUBAKBrBkNb6QhgVCRqDRkSwNVbXYHY5iLgiHEXBM0pO3FMIZLuF5g+zRafeCbRXlJZkcvwxBwSlLimU5eEGusNptRnRtjuKtEqzEa-GE4mk8n7+ukI8tk-t6jUs3hy0MxACjwlp0rJio8URrm6KhAiWRYir4kSuP4czVvkADuRA3GUABiOjUGw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cZx5r+JXJW5etfGSylRZ8i7fRBVI0niVJgghaxFeV1WuhI1steyX6Z27ZqF37PXBuaBwWXZaxzwFYtMkCWbUkLfpjx5aa2WStTmpchimN01iPap4bJdSIs+g+5Wy2D8KSw5z4QmV8Z7DPX5HdvApfyIcpQK0FP10sEjCLcAURVIxIwtGPwbvaXxDdtOKEp+quUv+prsp24Hisb5DRWlMbBSBDJSJu2aHDDpsFJ5aUlaWAmgA */
79
67
  readonly context: ({ input }: {
80
68
  input: {
81
69
  voice: import("..").Voice;
@@ -99,7 +87,6 @@ declare const machine: import("xstate").StateMachine<any, import("./types").Auto
99
87
  idleTimeoutCount: number;
100
88
  maxSpeechWaitTimeout: number;
101
89
  allowUserBargeIn: boolean;
102
- isSpeaking: boolean;
103
90
  sessionStartTime: number;
104
91
  maxSessionDuration: number;
105
92
  initialDtmf: string;
@@ -119,8 +106,6 @@ declare const machine: import("xstate").StateMachine<any, import("./types").Auto
119
106
  readonly idle: {
120
107
  readonly entry: readonly [{
121
108
  readonly type: "cleanSpeech";
122
- }, {
123
- readonly type: "setSpeakingDone";
124
109
  }];
125
110
  readonly on: {
126
111
  readonly SPEECH_START: {
@@ -139,27 +124,21 @@ declare const machine: import("xstate").StateMachine<any, import("./types").Auto
139
124
  params: undefined;
140
125
  }>;
141
126
  }, {
142
- readonly target: "transitioningToIdle";
127
+ readonly target: "idle";
143
128
  readonly actions: readonly [{
144
129
  readonly type: "increaseIdleTimeoutCount";
145
130
  }, {
146
131
  readonly type: "announceIdleTimeout";
147
132
  }];
133
+ readonly reenter: true;
148
134
  }];
149
135
  };
150
136
  };
151
- readonly transitioningToIdle: {
152
- readonly always: {
153
- readonly target: "idle";
154
- };
155
- };
156
137
  readonly listeningToUser: {
157
138
  readonly entry: readonly [{
158
139
  readonly type: "interruptPlayback";
159
140
  }, {
160
141
  readonly type: "resetIdleTimeoutCount";
161
- }, {
162
- readonly type: "setSpeaking";
163
142
  }];
164
143
  readonly on: {
165
144
  readonly SPEECH_RESULT: {
@@ -173,7 +152,7 @@ declare const machine: import("xstate").StateMachine<any, import("./types").Auto
173
152
  };
174
153
  readonly after: {
175
154
  readonly IDLE_TIMEOUT: readonly [{
176
- readonly target: "transitioningToIdle";
155
+ readonly target: "idle";
177
156
  readonly actions: readonly [{
178
157
  readonly type: "increaseIdleTimeoutCount";
179
158
  }, {
@@ -218,6 +197,9 @@ declare const machine: import("xstate").StateMachine<any, import("./types").Auto
218
197
  readonly guard: ({ context }: import("xstate/dist/declarations/src/guards").GuardArgs<any, {
219
198
  type: "SPEECH_START";
220
199
  }>) => any;
200
+ readonly actions: readonly [{
201
+ readonly type: "cleanSpeech";
202
+ }];
221
203
  };
222
204
  readonly SPEECH_RESULT: {
223
205
  readonly target: "processingUserRequest";
@@ -227,6 +209,7 @@ declare const machine: import("xstate").StateMachine<any, import("./types").Auto
227
209
  }, {
228
210
  readonly type: "appendSpeech";
229
211
  }];
212
+ readonly reenter: true;
230
213
  };
231
214
  };
232
215
  readonly invoke: {
@@ -23,7 +23,7 @@ const xstate_1 = require("xstate");
23
23
  const context_1 = require("./context");
24
24
  const setup_1 = require("./setup");
25
25
  const machine = setup_1.machineSetup.createMachine({
26
- /** @xstate-layout N4IgpgJg5mDOIC5QDMB2BBAkgYgB6wBcBDAsAOiOVICcAKAWXQA0B9AZQFE23MB5AORYARAKoAldABU+-AJTY0WANoAGALqJQABwD2sAJYF9O1JpC5EAWgDMAJgCcZAGwOAjAA4V9pyusB2e3cAGhAAT0RbAFYAFjIHJwDrJ2jXWxU06IBfTJDFTDIoajAwI1QobFUNJBBdAyMTMwsED1cyf28-O08nJ3dXJxDwhHtrSLJ7Px6o+1TbUb9s3Ix8-QgAGzBsNgAFDg4AYQAJdkl0MUlKs1rDY1NqpvsVPzJ3SLm-W3dozoS-QcQ-O5bOMVE5-H4VB4AtFbIsQHkyKsNnhCCRyJQaLRMEIADIcFjSegcXgiSTyBFIsCXarXep3UBNGIqcaRPqBeyPXxOSL-ZrWVytVIzSL2WzR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ji7xWhUsgtGoHRvzgAxykXagxDAABHUC4AgiATHISMADcdAAa3IBFUvSzLIygHK8sK4qEEq9KSHuKovMQ-jzEQOZ3g6QY-HGc9xjaPkLzIZk+m3ToQiCZKGoy2Aspa-s2qKwhIPMthzkufq+PpIb+R5e1rDsYtRR6SVPD5DCyCdYJnEhSFkgo9t6rSjattagq9rYxNoJTNg0zgrMzvXAIFK9CFBlLcTj2rPd7WvTpOm8Y9SxydtUB0CA4DMfIYYtc7mksQIJhcDxvF8AJgjCcKW08V65Old4eWdG8OzvIoSnUimc2QyxfjiSsSJLEii0GPlPFcZx5r+JXJW5etfGSylRZ8i7fRBVI0niVJgghaxFeV1WuhI1steyX6Z27ZqF37PXBuaBwWXZaxzwFYtMkCWbUkLfpjx5aa2WStTmpchimN01iPap4bJdSIs+g+5Wy2D8KSw5z4QmV8Z7DPX5HdvApfyIcpQK0FP10sEjCLcAURVIxIwtGPwbvaXxDdtOKEp+quUv+prsp24Hisb5DRWlMbBSBDJSJu2aHDDpsFJ5aUlaWAmgA */
27
27
  context: context_1.context,
28
28
  id: "fnAI",
29
29
  initial: "greeting",
@@ -38,7 +38,7 @@ const machine = setup_1.machineSetup.createMachine({
38
38
  }
39
39
  },
40
40
  idle: {
41
- entry: [{ type: "cleanSpeech" }, { type: "setSpeakingDone" }],
41
+ entry: [{ type: "cleanSpeech" }],
42
42
  on: {
43
43
  SPEECH_START: {
44
44
  target: "listeningToUser",
@@ -53,29 +53,18 @@ const machine = setup_1.machineSetup.createMachine({
53
53
  guard: (0, xstate_1.and)(["idleTimeoutCountExceedsMax"])
54
54
  },
55
55
  {
56
- target: "transitioningToIdle",
56
+ target: "idle",
57
57
  actions: [
58
58
  { type: "increaseIdleTimeoutCount" },
59
59
  { type: "announceIdleTimeout" }
60
- ]
60
+ ],
61
+ reenter: true
61
62
  }
62
63
  ]
63
64
  }
64
65
  },
65
- transitioningToIdle: {
66
- // This intermediate state is necessary to ensure the IDLE_TIMEOUT
67
- // event is properly reset and retriggered when returning to idle.
68
- // Without it, the timer would not restart correctly.
69
- always: {
70
- target: "idle"
71
- }
72
- },
73
66
  listeningToUser: {
74
- entry: [
75
- { type: "interruptPlayback" },
76
- { type: "resetIdleTimeoutCount" },
77
- { type: "setSpeaking" }
78
- ],
67
+ entry: [{ type: "interruptPlayback" }, { type: "resetIdleTimeoutCount" }],
79
68
  on: {
80
69
  SPEECH_RESULT: {
81
70
  target: "waitingForSpeechTimeout",
@@ -89,7 +78,7 @@ const machine = setup_1.machineSetup.createMachine({
89
78
  after: {
90
79
  IDLE_TIMEOUT: [
91
80
  {
92
- target: "transitioningToIdle",
81
+ target: "idle",
93
82
  actions: [
94
83
  { type: "increaseIdleTimeoutCount" },
95
84
  { type: "announceIdleTimeout" }
@@ -127,12 +116,17 @@ const machine = setup_1.machineSetup.createMachine({
127
116
  SPEECH_START: {
128
117
  target: "listeningToUser",
129
118
  description: "Event from VAD or similar system.",
130
- guard: ({ context }) => context.allowUserBargeIn
119
+ guard: ({ context }) => context.allowUserBargeIn,
120
+ // We assume that the user wants to steer the conversation
121
+ // back to the agent so we clean the speech buffer
122
+ actions: [{ type: "cleanSpeech" }]
131
123
  },
132
124
  SPEECH_RESULT: {
125
+ // This makes sure result that
133
126
  target: "processingUserRequest",
134
127
  description: "Append speech and go back to listening.",
135
- actions: [{ type: "interruptPlayback" }, { type: "appendSpeech" }]
128
+ actions: [{ type: "interruptPlayback" }, { type: "appendSpeech" }],
129
+ reenter: true
136
130
  }
137
131
  },
138
132
  invoke: {
@@ -30,14 +30,6 @@ declare const machineSetup: {
30
30
  type: "resetState";
31
31
  params: unknown;
32
32
  };
33
- setSpeaking: {
34
- type: "setSpeaking";
35
- params: unknown;
36
- };
37
- setSpeakingDone: {
38
- type: "setSpeakingDone";
39
- params: unknown;
40
- };
41
33
  greetUser: {
42
34
  type: "greetUser";
43
35
  params: unknown;
@@ -59,10 +51,6 @@ declare const machineSetup: {
59
51
  params: unknown;
60
52
  };
61
53
  }>, import("xstate").Values<{
62
- isSpeaking: {
63
- type: "isSpeaking";
64
- params: unknown;
65
- };
66
54
  idleTimeoutCountExceedsMax: {
67
55
  type: "idleTimeoutCountExceedsMax";
68
56
  params: unknown;
@@ -106,14 +94,6 @@ declare const machineSetup: {
106
94
  type: "resetState";
107
95
  params: unknown;
108
96
  };
109
- setSpeaking: {
110
- type: "setSpeaking";
111
- params: unknown;
112
- };
113
- setSpeakingDone: {
114
- type: "setSpeakingDone";
115
- params: unknown;
116
- };
117
97
  greetUser: {
118
98
  type: "greetUser";
119
99
  params: unknown;
@@ -135,10 +115,6 @@ declare const machineSetup: {
135
115
  params: unknown;
136
116
  };
137
117
  }>, import("xstate").Values<{
138
- isSpeaking: {
139
- type: "isSpeaking";
140
- params: unknown;
141
- };
142
118
  idleTimeoutCountExceedsMax: {
143
119
  type: "idleTimeoutCountExceedsMax";
144
120
  params: unknown;
@@ -105,21 +105,8 @@ const machineSetup = (0, xstate_1.setup)({
105
105
  return {
106
106
  ...context,
107
107
  speechBuffer: "",
108
- idleTimeoutCount: 0,
109
- isSpeaking: false
108
+ idleTimeoutCount: 0
110
109
  };
111
- }),
112
- setSpeaking: (0, xstate_1.assign)(({ context }) => {
113
- logger.verbose("called the setSpeaking action", { isSpeaking: true });
114
- context.isSpeaking = true;
115
- return context;
116
- }),
117
- setSpeakingDone: (0, xstate_1.assign)(({ context }) => {
118
- logger.verbose("called the setSpeakingDone action", {
119
- isSpeaking: false
120
- });
121
- context.isSpeaking = false;
122
- return context;
123
110
  })
124
111
  },
125
112
  guards,
@@ -35,7 +35,6 @@ type AutopilotContext = {
35
35
  maxSpeechWaitTimeout: number;
36
36
  speechBuffer: string;
37
37
  speechResponseTime: number;
38
- isSpeaking: boolean;
39
38
  knowledgeBaseSourceUrl?: string;
40
39
  initialDtmf?: string;
41
40
  };
@@ -22,4 +22,9 @@ export type EventsHook = {
22
22
  events: EventsHookAllowedEvents[];
23
23
  headers?: Record<string, string>;
24
24
  };
25
- export declare function sendConversationEndedEvent(eventsHook: EventsHook, chatHistory: Record<string, string>[], phone: string): Promise<void>;
25
+ export declare function sendConversationEndedEvent(eventsHook: EventsHook, data: {
26
+ chatHistory: Record<string, string>[];
27
+ phone: string;
28
+ appRef: string;
29
+ sessionRef: string;
30
+ }): Promise<void>;
@@ -22,7 +22,8 @@ exports.sendConversationEndedEvent = sendConversationEndedEvent;
22
22
  const common_1 = require("@fonoster/common");
23
23
  const logger_1 = require("@fonoster/logger");
24
24
  const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
25
- async function sendConversationEndedEvent(eventsHook, chatHistory, phone) {
25
+ async function sendConversationEndedEvent(eventsHook, data) {
26
+ const { chatHistory, phone, appRef, sessionRef } = data;
26
27
  if (!eventsHook?.events.includes(common_1.EventsHookAllowedEvents.CONVERSATION_ENDED) &&
27
28
  !eventsHook?.events.includes(common_1.EventsHookAllowedEvents.ALL)) {
28
29
  return;
@@ -30,6 +31,8 @@ async function sendConversationEndedEvent(eventsHook, chatHistory, phone) {
30
31
  const parsedEventsHook = common_1.eventsHookSchema.parse(eventsHook);
31
32
  const body = {
32
33
  eventType: common_1.EventsHookAllowedEvents.CONVERSATION_ENDED,
34
+ appRef,
35
+ sessionRef,
33
36
  phone,
34
37
  chatHistory
35
38
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/autopilot",
3
- "version": "0.12.7",
3
+ "version": "0.12.9",
4
4
  "description": "Voice AI for the Fonoster platform",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -59,5 +59,5 @@
59
59
  "xstate": "^5.17.3",
60
60
  "zod": "^3.23.8"
61
61
  },
62
- "gitHead": "933cdb1ed355459db6f34786128f73b143c6c91c"
62
+ "gitHead": "082170cc2626a2c21ce1b2d657203aef88e7f043"
63
63
  }
@@ -1 +0,0 @@
1
- export declare const setSpeaking: import("xstate").ActionFunction<import("xstate").MachineContext, import("xstate").AnyEventObject, import("xstate").EventObject, {}, import("xstate").ProvidedActor, never, never, never, never>;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setSpeaking = 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.setSpeaking = (0, xstate_1.assign)(({ context }) => {
26
- logger.verbose("called the setSpeaking action", { isSpeaking: true });
27
- context.isSpeaking = true;
28
- return context;
29
- });
@@ -1 +0,0 @@
1
- export declare const setSpeakingDone: import("xstate").ActionFunction<import("xstate").MachineContext, import("xstate").AnyEventObject, import("xstate").EventObject, {}, import("xstate").ProvidedActor, never, never, never, never>;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setSpeakingDone = 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.setSpeakingDone = (0, xstate_1.assign)(({ context }) => {
26
- logger.verbose("called the setSpeakingDone action", { isSpeaking: false });
27
- context.isSpeaking = false;
28
- return context;
29
- });
@@ -1,4 +0,0 @@
1
- import { AutopilotContext } from "../types";
2
- export declare const isSpeaking: ({ context }: {
3
- context: AutopilotContext;
4
- }) => boolean;
@@ -1,30 +0,0 @@
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;