@fonoster/autopilot 0.7.3 → 0.7.5

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 (102) hide show
  1. package/README.md +156 -2
  2. package/dist/Autopilot.d.ts +3 -7
  3. package/dist/Autopilot.js +26 -35
  4. package/dist/assistants/AssistantSchema.d.ts +579 -13
  5. package/dist/assistants/AssistantSchema.js +42 -7
  6. package/dist/assistants/index.d.ts +1 -3
  7. package/dist/assistants/index.js +1 -6
  8. package/dist/assistants/loadAndValidateAssistant.d.ts +2 -2
  9. package/dist/assistants/loadAndValidateAssistant.js +3 -3
  10. package/dist/assistants/types.d.ts +6 -17
  11. package/dist/assistants/types.js +0 -25
  12. package/dist/createLanguageModel.d.ts +3 -0
  13. package/dist/createLanguageModel.js +40 -0
  14. package/dist/envs.d.ts +1 -0
  15. package/dist/envs.js +2 -1
  16. package/dist/handleVoiceRequest.d.ts +3 -0
  17. package/dist/handleVoiceRequest.js +66 -0
  18. package/dist/index.d.ts +9 -1
  19. package/dist/index.js +23 -3
  20. package/dist/knowledge/AbstractKnowledgeBase.d.ts +13 -0
  21. package/dist/knowledge/AbstractKnowledgeBase.js +18 -0
  22. package/dist/knowledge/FilesKnowledgeBase.d.ts +12 -0
  23. package/dist/knowledge/FilesKnowledgeBase.js +50 -0
  24. package/dist/knowledge/index.d.ts +3 -0
  25. package/dist/knowledge/index.js +37 -0
  26. package/dist/knowledge/types.d.ts +4 -0
  27. package/dist/knowledge/types.js +2 -0
  28. package/dist/loadAssistantConfig.d.ts +3 -0
  29. package/dist/loadAssistantConfig.js +26 -0
  30. package/dist/loadKnowledgeBase.d.ts +3 -0
  31. package/dist/loadKnowledgeBase.js +29 -0
  32. package/dist/machine/machine.d.ts +188 -73
  33. package/dist/machine/machine.js +240 -73
  34. package/dist/models/AbstractLanguageModel.d.ts +11 -0
  35. package/dist/models/AbstractLanguageModel.js +78 -0
  36. package/dist/models/LanguageModelFactory.d.ts +16 -0
  37. package/dist/models/LanguageModelFactory.js +44 -0
  38. package/dist/models/chatHistory.d.ts +6 -0
  39. package/dist/models/chatHistory.js +32 -0
  40. package/dist/models/createChain.d.ts +7 -0
  41. package/dist/models/createChain.js +15 -0
  42. package/dist/models/createPromptTemplate.d.ts +2 -0
  43. package/dist/{assistants/assistants.js → models/createPromptTemplate.js} +7 -16
  44. package/dist/models/groq/Groq.d.ts +7 -0
  45. package/dist/models/groq/Groq.js +22 -0
  46. package/dist/models/groq/index.d.ts +2 -0
  47. package/dist/models/groq/index.js +36 -0
  48. package/dist/models/groq/types.d.ts +13 -0
  49. package/dist/models/groq/types.js +9 -0
  50. package/dist/models/index.d.ts +2 -0
  51. package/dist/models/index.js +36 -0
  52. package/dist/models/openai/OpenAI.d.ts +7 -0
  53. package/dist/models/openai/OpenAI.js +22 -0
  54. package/dist/models/openai/index.d.ts +2 -0
  55. package/dist/models/openai/index.js +36 -0
  56. package/dist/models/openai/types.d.ts +12 -0
  57. package/dist/models/openai/types.js +8 -0
  58. package/dist/models/types.d.ts +19 -0
  59. package/dist/models/types.js +2 -0
  60. package/dist/server.js +23 -0
  61. package/dist/tools/ToolSchema.d.ts +107 -0
  62. package/dist/tools/ToolSchema.js +64 -0
  63. package/dist/tools/ToolsCatalog.d.ts +11 -0
  64. package/dist/tools/ToolsCatalog.js +52 -0
  65. package/dist/tools/builtin/hangupToolDefinition.d.ts +3 -0
  66. package/dist/tools/builtin/hangupToolDefinition.js +35 -0
  67. package/dist/tools/builtin/transferToolDefinition.d.ts +3 -0
  68. package/dist/tools/builtin/transferToolDefinition.js +35 -0
  69. package/dist/tools/convertToolToOpenAITool.d.ts +3 -0
  70. package/dist/tools/convertToolToOpenAITool.js +11 -0
  71. package/dist/tools/index.d.ts +4 -0
  72. package/dist/tools/index.js +38 -0
  73. package/dist/tools/sendRequest.d.ts +11 -0
  74. package/dist/tools/sendRequest.js +43 -0
  75. package/dist/tools/type.d.ts +8 -0
  76. package/dist/tools/type.js +2 -0
  77. package/dist/types.d.ts +14 -6
  78. package/dist/types.js +6 -0
  79. package/dist/vad/SileroVad.d.ts +8 -0
  80. package/dist/vad/SileroVad.js +39 -0
  81. package/dist/vad/chunkToFloat32Array.d.ts +1 -1
  82. package/dist/vad/chunkToFloat32Array.js +17 -3
  83. package/dist/vad/index.d.ts +1 -2
  84. package/dist/vad/index.js +1 -2
  85. package/dist/vad/makeVad.d.ts +1 -1
  86. package/dist/vad/makeVad.js +5 -7
  87. package/dist/vad/types.d.ts +4 -2
  88. package/dist/voice/Voice.d.ts +25 -0
  89. package/dist/voice/Voice.js +81 -0
  90. package/dist/voice/index.d.ts +2 -0
  91. package/dist/voice/index.js +36 -0
  92. package/dist/voice/types.d.ts +23 -0
  93. package/dist/voice/types.js +2 -0
  94. package/dist/voiceServerSetup.d.ts +2 -0
  95. package/dist/{runner.js → voiceServerSetup.js} +5 -22
  96. package/package.json +15 -7
  97. package/dist/assistants/assistants.d.ts +0 -4
  98. package/dist/machine/types.d.ts +0 -29
  99. package/dist/machine/types.js +0 -9
  100. package/dist/runner.d.ts +0 -2
  101. package/dist/vad/micVadTest.js +0 -48
  102. /package/dist/{vad/micVadTest.d.ts → server.d.ts} +0 -0
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendRequest = sendRequest;
4
+ /*
5
+ * Copyright (C) 2024 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 zod_1 = require("zod");
23
+ const ToolSchema_1 = require("./ToolSchema");
24
+ const responseSchema = zod_1.z.object({
25
+ result: zod_1.z.string()
26
+ });
27
+ async function sendRequest(input) {
28
+ const { url, method, body, headers, waitForResponse } = input;
29
+ const options = {
30
+ method,
31
+ headers,
32
+ body: method === ToolSchema_1.AllowedOperations.POST ? JSON.stringify(body) : undefined
33
+ };
34
+ if (waitForResponse && method === ToolSchema_1.AllowedOperations.POST) {
35
+ setTimeout(() => fetch(url, options), 0);
36
+ return { result: "request sent" };
37
+ }
38
+ else {
39
+ const response = await fetch(url, options);
40
+ const data = await response.json();
41
+ return responseSchema.parse(data);
42
+ }
43
+ }
@@ -0,0 +1,8 @@
1
+ import { z } from "zod";
2
+ import { toolSchema } from "./ToolSchema";
3
+ type Tool = z.infer<typeof toolSchema>;
4
+ type OpenAITool = {
5
+ type: "function";
6
+ function: Omit<Tool, "operation">;
7
+ };
8
+ export { OpenAITool, Tool };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/types.d.ts CHANGED
@@ -1,7 +1,15 @@
1
- import { VoiceResponse } from "@fonoster/voice";
2
- import { AssistantConfig } from "./assistants/types";
3
- type AutopilotConfig = {
4
- voice: VoiceResponse;
5
- assistantConfig: AssistantConfig;
1
+ import { ConversationSettings } from "./assistants";
2
+ import { LanguageModel } from "./models";
3
+ import { Vad } from "./vad";
4
+ import { Voice } from "./voice";
5
+ declare enum LANGUAGE_MODEL_PROVIDER {
6
+ OPENAI = "openai",
7
+ GROQ = "groq"
8
+ }
9
+ type AutopilotParams = {
10
+ voice: Voice;
11
+ vad: Vad;
12
+ conversationSettings: ConversationSettings;
13
+ languageModel: LanguageModel;
6
14
  };
7
- export { AutopilotConfig };
15
+ export { AutopilotParams, LANGUAGE_MODEL_PROVIDER };
package/dist/types.js CHANGED
@@ -1,2 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LANGUAGE_MODEL_PROVIDER = void 0;
4
+ var LANGUAGE_MODEL_PROVIDER;
5
+ (function (LANGUAGE_MODEL_PROVIDER) {
6
+ LANGUAGE_MODEL_PROVIDER["OPENAI"] = "openai";
7
+ LANGUAGE_MODEL_PROVIDER["GROQ"] = "groq";
8
+ })(LANGUAGE_MODEL_PROVIDER || (exports.LANGUAGE_MODEL_PROVIDER = LANGUAGE_MODEL_PROVIDER = {}));
@@ -0,0 +1,8 @@
1
+ import { Vad } from "./types";
2
+ declare class SileroVad implements Vad {
3
+ private vad;
4
+ constructor();
5
+ private init;
6
+ processChunk(data: Uint8Array, callback: (event: "SPEECH_START" | "SPEECH_END") => void): void;
7
+ }
8
+ export { SileroVad };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SileroVad = void 0;
4
+ /* eslint-disable no-loops/no-loops */
5
+ /*
6
+ * Copyright (C) 2024 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 makeVad_1 = require("./makeVad");
24
+ class SileroVad {
25
+ constructor() {
26
+ this.init();
27
+ }
28
+ async init() {
29
+ // FIXME: It feels not to do this in the constructor
30
+ this.vad = await (0, makeVad_1.makeVad)();
31
+ }
32
+ processChunk(data, callback) {
33
+ if (!this.vad) {
34
+ throw new Error("VAD not initialized)");
35
+ }
36
+ this.vad(data, callback);
37
+ }
38
+ }
39
+ exports.SileroVad = SileroVad;
@@ -1,2 +1,2 @@
1
- declare function chunkToFloat32Array(chunk: Float32Array): Float32Array;
1
+ declare function chunkToFloat32Array(chunk: Uint8Array): Float32Array;
2
2
  export { chunkToFloat32Array };
@@ -1,6 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.chunkToFloat32Array = chunkToFloat32Array;
4
2
  /*
5
3
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
6
4
  * http://github.com/fonoster/fonoster
@@ -19,7 +17,23 @@ exports.chunkToFloat32Array = chunkToFloat32Array;
19
17
  * See the License for the specific language governing permissions and
20
18
  * limitations under the License.
21
19
  */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.chunkToFloat32Array = chunkToFloat32Array;
22
+ // This version of the chunkToFloat32Array accounts for the case where
23
+ // the byteOffset is misaligned.
24
+ //
25
+ // Q. Would it be the same if we just created a new Uint8Array from the chunk?
22
26
  function chunkToFloat32Array(chunk) {
23
- const int16Array = new Int16Array(chunk.buffer, chunk.byteOffset, chunk.byteLength / Int16Array.BYTES_PER_ELEMENT);
27
+ // Check if byteOffset is not aligned
28
+ const alignedByteOffset = chunk.byteOffset % Int16Array.BYTES_PER_ELEMENT === 0;
29
+ let int16Array;
30
+ if (alignedByteOffset) {
31
+ int16Array = new Int16Array(chunk.buffer, chunk.byteOffset, chunk.byteLength / Int16Array.BYTES_PER_ELEMENT);
32
+ }
33
+ else {
34
+ // Create a new aligned Uint8Array and then an Int16Array from it
35
+ const alignedChunk = new Uint8Array(chunk);
36
+ int16Array = new Int16Array(alignedChunk.buffer, alignedChunk.byteOffset, alignedChunk.byteLength / Int16Array.BYTES_PER_ELEMENT);
37
+ }
24
38
  return new Float32Array(Array.from(int16Array, (sample) => sample / 32768.0));
25
39
  }
@@ -1,3 +1,2 @@
1
- export * from "./SileroVadModel";
1
+ export * from "./SileroVad";
2
2
  export * from "./types";
3
- export * from "./makeVad";
package/dist/vad/index.js CHANGED
@@ -33,6 +33,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
33
  * See the License for the specific language governing permissions and
34
34
  * limitations under the License.
35
35
  */
36
- __exportStar(require("./SileroVadModel"), exports);
36
+ __exportStar(require("./SileroVad"), exports);
37
37
  __exportStar(require("./types"), exports);
38
- __exportStar(require("./makeVad"), exports);
@@ -1,2 +1,2 @@
1
- declare function makeVad(pathToModel?: string): Promise<(chunk: Float32Array, callback: (event: "SPEECH_START" | "SPEECH_END", data: Record<string, unknown>) => void) => Promise<void>>;
1
+ declare function makeVad(pathToModel?: string): Promise<(chunk: Uint8Array, callback: (event: "SPEECH_START" | "SPEECH_END") => void) => Promise<void>>;
2
2
  export { makeVad };
@@ -65,16 +65,14 @@ async function makeVad(pathToModel) {
65
65
  if (result.isSpeech > 0.5) {
66
66
  if (!isSpeechActive) {
67
67
  isSpeechActive = true;
68
- callback("SPEECH_START", {});
68
+ callback("SPEECH_START");
69
69
  return processBuffer(remainingBuffer);
70
70
  }
71
71
  }
72
- else {
73
- if (isSpeechActive) {
74
- isSpeechActive = false;
75
- callback("SPEECH_END", {});
76
- return processBuffer(remainingBuffer);
77
- }
72
+ else if (isSpeechActive) {
73
+ isSpeechActive = false;
74
+ callback("SPEECH_END");
75
+ return processBuffer(remainingBuffer);
78
76
  }
79
77
  return processBuffer(remainingBuffer);
80
78
  };
@@ -1,4 +1,6 @@
1
- type Vad = (chunk: Float32Array, cb: (event: string) => void) => Promise<void>;
1
+ type Vad = {
2
+ processChunk: (chunk: Uint8Array, callback: (event: "SPEECH_START" | "SPEECH_END") => void) => void;
3
+ };
2
4
  type SpeechProbabilities = {
3
5
  notSpeech: number;
4
6
  isSpeech: number;
@@ -14,4 +16,4 @@ type ONNXRuntimeAPI = {
14
16
  new (type: "float32", data: Float32Array, dims: [1, number]): unknown;
15
17
  };
16
18
  };
17
- export { SpeechProbabilities, ONNXRuntimeAPI, Vad };
19
+ export { ONNXRuntimeAPI, SpeechProbabilities, Vad };
@@ -0,0 +1,25 @@
1
+ import { VoiceResponse } from "@fonoster/voice";
2
+ import { Voice } from "./types";
3
+ declare class VoiceImpl implements Voice {
4
+ private voice;
5
+ private playbackRef;
6
+ sessionRef: string;
7
+ constructor(sessionRef: string, voice: VoiceResponse);
8
+ answer(): Promise<void>;
9
+ hangup(): Promise<void>;
10
+ say(text: string): Promise<void>;
11
+ sgather(): Promise<{
12
+ stop: () => Promise<void>;
13
+ onData: (cb: (speech: string) => void) => void;
14
+ }>;
15
+ stream(): Promise<{
16
+ stop: () => Promise<void>;
17
+ onData: (cb: (chunk: Uint8Array) => void) => void;
18
+ }>;
19
+ transfer(to: string, options: {
20
+ record: boolean;
21
+ timeout: number;
22
+ }): Promise<void>;
23
+ stopSpeech(): Promise<void>;
24
+ }
25
+ export { VoiceImpl };
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VoiceImpl = void 0;
4
+ /*
5
+ * Copyright (C) 2024 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 common_1 = require("@fonoster/common");
23
+ const uuid_1 = require("uuid");
24
+ class VoiceImpl {
25
+ constructor(sessionRef, voice) {
26
+ this.voice = voice;
27
+ this.sessionRef = sessionRef;
28
+ this.playbackRef = (0, uuid_1.v4)();
29
+ }
30
+ async answer() {
31
+ await this.voice.answer();
32
+ }
33
+ async hangup() {
34
+ await this.voice.hangup();
35
+ }
36
+ async say(text) {
37
+ await this.voice.say(text, { playbackRef: this.playbackRef });
38
+ }
39
+ async sgather() {
40
+ const stream = await this.voice.sgather({
41
+ source: common_1.StreamGatherSource.SPEECH
42
+ });
43
+ return {
44
+ stop: async () => {
45
+ stream.close();
46
+ stream.cleanup(() => { });
47
+ },
48
+ onData: (cb) => {
49
+ stream.onPayload((payload) => {
50
+ cb(payload.speech);
51
+ });
52
+ }
53
+ };
54
+ }
55
+ async stream() {
56
+ const stream = await this.voice.stream();
57
+ return {
58
+ stop: async () => {
59
+ stream.close();
60
+ stream.cleanup(() => { });
61
+ },
62
+ onData: (cb) => {
63
+ stream.onPayload((payload) => {
64
+ cb(payload.data);
65
+ });
66
+ }
67
+ };
68
+ }
69
+ async transfer(to, options) {
70
+ const { record, timeout } = options;
71
+ const effectiveOptions = {
72
+ recordDirection: record ? common_1.DialRecordDirection.BOTH : undefined,
73
+ timeout
74
+ };
75
+ await this.voice.dial(to, effectiveOptions);
76
+ }
77
+ async stopSpeech() {
78
+ await this.voice.playbackControl(this.playbackRef, common_1.PlaybackControlAction.STOP);
79
+ }
80
+ }
81
+ exports.VoiceImpl = VoiceImpl;
@@ -0,0 +1,2 @@
1
+ export * from "./Voice";
2
+ export * from "./types";
@@ -0,0 +1,36 @@
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
+ __exportStar(require("./Voice"), exports);
18
+ /*
19
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
20
+ * http://github.com/fonoster/fonoster
21
+ *
22
+ * This file is part of Fonoster
23
+ *
24
+ * Licensed under the MIT License (the "License");
25
+ * you may not use this file except in compliance with
26
+ * the License. You may obtain a copy of the License at
27
+ *
28
+ * https://opensource.org/licenses/MIT
29
+ *
30
+ * Unless required by applicable law or agreed to in writing, software
31
+ * distributed under the License is distributed on an "AS IS" BASIS,
32
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33
+ * See the License for the specific language governing permissions and
34
+ * limitations under the License.
35
+ */
36
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,23 @@
1
+ type GatherStream = {
2
+ stop: () => Promise<void>;
3
+ onData: (cb: (speech: string) => void) => void;
4
+ };
5
+ type Stream = {
6
+ stop: () => Promise<void>;
7
+ onData: (cb: (chunk: Uint8Array) => void) => void;
8
+ };
9
+ type TransferOptions = {
10
+ timeout?: number;
11
+ record?: boolean;
12
+ };
13
+ type Voice = {
14
+ sessionRef: string;
15
+ answer: () => Promise<void>;
16
+ hangup: () => Promise<void>;
17
+ say: (text: string) => Promise<void>;
18
+ sgather: () => Promise<GatherStream>;
19
+ transfer: (destination: string, options?: TransferOptions) => Promise<void>;
20
+ stream: () => Promise<Stream>;
21
+ stopSpeech: () => Promise<void>;
22
+ };
23
+ export { TransferOptions, Voice };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ declare function startVoiceServer(skipIdentity: boolean): void;
2
+ export { startVoiceServer };
@@ -1,9 +1,9 @@
1
- #!/usr/bin/env node
2
1
  "use strict";
3
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
4
  };
6
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.startVoiceServer = startVoiceServer;
7
7
  /*
8
8
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
9
9
  * http://github.com/fonoster/fonoster
@@ -22,25 +22,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
22
22
  * See the License for the specific language governing permissions and
23
23
  * limitations under the License.
24
24
  */
25
- const logger_1 = require("@fonoster/logger");
26
25
  const voice_1 = __importDefault(require("@fonoster/voice"));
27
- const assistants_1 = require("./assistants");
28
- const Autopilot_1 = require("./Autopilot");
29
- const envs_1 = require("./envs");
30
- const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
31
- const skipIdentity = process.env.NODE_ENV === "dev";
32
- new voice_1.default({ skipIdentity }).listen(async (req, voice) => {
33
- const { ingressNumber, sessionRef, appRef } = req;
34
- logger.verbose("voice request", { ingressNumber, sessionRef, appRef });
35
- const assistantPath = process.argv[2];
36
- const assistant = (0, assistants_1.loadAndValidateAssistant)(assistantPath);
37
- logger.verbose("interacting with assistant", { name: assistant.name });
38
- const autopilot = new Autopilot_1.Autopilot({
39
- voice,
40
- assistantConfig: {
41
- ...assistant,
42
- apiKey: envs_1.OPENAI_API_KEY
43
- }
44
- });
45
- autopilot.start();
46
- });
26
+ const handleVoiceRequest_1 = require("./handleVoiceRequest");
27
+ function startVoiceServer(skipIdentity) {
28
+ new voice_1.default({ skipIdentity }).listen(handleVoiceRequest_1.handleVoiceRequest);
29
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/autopilot",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
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",
@@ -14,7 +14,8 @@
14
14
  "scripts": {
15
15
  "prebuild": "rimraf ./dist tsconfig.tsbuildinfo",
16
16
  "build": "tsc -b tsconfig.json",
17
- "clean": "rimraf ./dist node_modules tsconfig.tsbuildinfo"
17
+ "clean": "rimraf ./dist node_modules tsconfig.tsbuildinfo",
18
+ "generate:readme": "node ../../.scripts/gen-readme.js"
18
19
  },
19
20
  "bin": {
20
21
  "autopilot": "./dist/runner.js"
@@ -34,17 +35,24 @@
34
35
  "url": "https://github.com/fonoster/fonoster/issues"
35
36
  },
36
37
  "dependencies": {
37
- "@fonoster/logger": "^0.7.2",
38
- "@fonoster/voice": "^0.7.3",
39
- "@langchain/openai": "^0.2.7",
38
+ "@fonoster/common": "^0.7.5",
39
+ "@fonoster/logger": "^0.7.5",
40
+ "@fonoster/voice": "^0.7.5",
41
+ "@langchain/community": "^0.2.31",
42
+ "@langchain/core": "^0.2.31",
43
+ "@langchain/groq": "^0.0.17",
44
+ "@langchain/openai": "^0.2.8",
45
+ "cheerio": "^1.0.0",
40
46
  "dotenv": "^16.4.5",
47
+ "langchain": "^0.2.17",
41
48
  "onnxruntime-node": "^1.19.0",
49
+ "pdf-parse": "^1.1.1",
50
+ "uuid": "^10.0.0",
42
51
  "xstate": "^5.17.3",
43
52
  "zod": "^3.23.8"
44
53
  },
45
54
  "devDependencies": {
46
- "node-record-lpcm16": "^1.0.1",
47
55
  "typescript": "^5.5.4"
48
56
  },
49
- "gitHead": "97aa6649691819fe8a704b96bc62b1b142162393"
57
+ "gitHead": "cf28444503e4e698ccc001e061c7c918a4204757"
50
58
  }
@@ -1,4 +0,0 @@
1
- import { AssistantConfig } from "./types";
2
- type Assistant = ReturnType<typeof makeAssistant>;
3
- declare function makeAssistant(config: AssistantConfig): import("@langchain/core/runnables").Runnable<any, string, import("@langchain/core/runnables").RunnableConfig>;
4
- export { makeAssistant, Assistant };
@@ -1,29 +0,0 @@
1
- import { VoiceResponse } from "@fonoster/voice";
2
- import { Assistant } from "../assistants/assistants";
3
- declare const types: {
4
- context: {
5
- firstMessage: string;
6
- voice: VoiceResponse;
7
- assistant: Assistant;
8
- playbackRef: string;
9
- speechBuffer: string;
10
- speechResponseStartTime: number;
11
- speechResponseTime: number;
12
- };
13
- input: {
14
- firstMessage: string;
15
- voice: VoiceResponse;
16
- assistant: Assistant;
17
- };
18
- events: {
19
- type: "SPEECH_START";
20
- } | {
21
- type: "SPEECH_END";
22
- } | {
23
- type: "SESSION_END";
24
- } | {
25
- type: "HUMAN_PROMPT";
26
- speech: string;
27
- };
28
- };
29
- export { types };
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.types = void 0;
4
- const types = {
5
- context: {},
6
- input: {},
7
- events: {}
8
- };
9
- exports.types = types;
package/dist/runner.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,48 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- /*
7
- * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
8
- * http://github.com/fonoster/fonoster
9
- *
10
- * This file is part of Fonoster
11
- *
12
- * Licensed under the MIT License (the "License");
13
- * you may not use this file except in compliance with
14
- * the License. You may obtain a copy of the License at
15
- *
16
- * https://opensource.org/licenses/MIT
17
- *
18
- * Unless required by applicable law or agreed to in writing, software
19
- * distributed under the License is distributed on an "AS IS" BASIS,
20
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
- * See the License for the specific language governing permissions and
22
- * limitations under the License.
23
- */
24
- const logger_1 = require("@fonoster/logger");
25
- const node_record_lpcm16_1 = __importDefault(require("node-record-lpcm16"));
26
- const makeVad_1 = require("./makeVad");
27
- const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
28
- async function main() {
29
- const vad = await (0, makeVad_1.makeVad)();
30
- // Start recording from the default microphone
31
- const mic = node_record_lpcm16_1.default
32
- .record({
33
- sampleRate: 16000, // 16 kHz sample rate
34
- channels: 1,
35
- threshold: 0.5
36
- })
37
- .stream();
38
- mic.on("data", async (data) => {
39
- const chunk = new Float32Array(data.buffer);
40
- await vad(chunk, (event, _data) => {
41
- logger.info("vad event:", { event, data: _data });
42
- });
43
- });
44
- mic.on("error", (err) => {
45
- logger.error("an error occurred:", { err });
46
- });
47
- }
48
- main().catch(logger.error);
File without changes