@fonoster/autopilot 0.5.5 → 0.7.2
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.
- package/LICENSE +2 -2
- package/README.md +3 -0
- package/dist/Autopilot.d.ts +15 -0
- package/dist/Autopilot.js +86 -0
- package/dist/assistants/AssistantSchema.d.ts +25 -0
- package/dist/assistants/AssistantSchema.js +32 -0
- package/dist/assistants/assistants.d.ts +4 -0
- package/dist/assistants/assistants.js +39 -0
- package/dist/assistants/index.d.ts +4 -0
- package/dist/{cerebro → assistants}/index.js +10 -5
- package/dist/assistants/loadAndValidateAssistant.d.ts +3 -0
- package/dist/assistants/loadAndValidateAssistant.js +46 -0
- package/dist/assistants/types.d.ts +17 -0
- package/dist/{events → assistants}/types.js +10 -12
- package/dist/envs.d.ts +1 -4
- package/dist/envs.js +11 -8
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -11
- package/dist/machine/index.d.ts +1 -0
- package/dist/machine/index.js +23 -0
- package/dist/machine/machine.d.ts +163 -0
- package/dist/machine/machine.js +142 -0
- package/dist/machine/types.d.ts +29 -0
- package/dist/machine/types.js +9 -0
- package/dist/runner.d.ts +2 -0
- package/dist/runner.js +46 -0
- package/dist/types.d.ts +7 -41
- package/dist/types.js +0 -7
- package/dist/vad/SileroVadModel.d.ts +15 -0
- package/dist/vad/SileroVadModel.js +65 -0
- package/dist/vad/chunkToFloat32Array.d.ts +2 -0
- package/dist/vad/chunkToFloat32Array.js +25 -0
- package/dist/vad/index.d.ts +3 -0
- package/dist/{file-retention → vad}/index.js +7 -4
- package/dist/vad/makeVad.d.ts +2 -0
- package/dist/vad/makeVad.js +83 -0
- package/dist/vad/micVadTest.d.ts +1 -0
- package/dist/vad/micVadTest.js +48 -0
- package/dist/vad/types.d.ts +17 -0
- package/package.json +34 -28
- package/dist/cerebro/cerebro.d.ts +0 -42
- package/dist/cerebro/cerebro.js +0 -266
- package/dist/cerebro/effects.d.ts +0 -11
- package/dist/cerebro/effects.js +0 -113
- package/dist/cerebro/helper.d.ts +0 -5
- package/dist/cerebro/helper.js +0 -43
- package/dist/cerebro/index.d.ts +0 -2
- package/dist/cerebro/types.d.ts +0 -40
- package/dist/cerebro/types.js +0 -9
- package/dist/events/emitter.d.ts +0 -7
- package/dist/events/emitter.js +0 -13
- package/dist/events/server.d.ts +0 -12
- package/dist/events/server.js +0 -67
- package/dist/events/types.d.ts +0 -20
- package/dist/file-retention/cron.d.ts +0 -2
- package/dist/file-retention/cron.js +0 -23
- package/dist/file-retention/index.d.ts +0 -1
- package/dist/file-retention/task.d.ts +0 -6
- package/dist/file-retention/task.js +0 -56
- package/dist/intents/df_utils.d.ts +0 -3
- package/dist/intents/df_utils.js +0 -39
- package/dist/intents/dialogflow_cx.d.ts +0 -43
- package/dist/intents/dialogflow_cx.js +0 -102
- package/dist/intents/dialogflow_es.d.ts +0 -15
- package/dist/intents/dialogflow_es.js +0 -166
- package/dist/intents/engines.d.ts +0 -3
- package/dist/intents/engines.js +0 -32
- package/dist/intents/types.d.ts +0 -25
- package/dist/pilot.d.ts +0 -3
- package/dist/pilot.js +0 -150
- package/dist/util.d.ts +0 -44
- package/dist/util.js +0 -105
- /package/dist/{intents → vad}/types.js +0 -0
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2024 Fonoster Inc
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<a href="https://gitpod.io/#https://github.com/fonoster/fonoster"> <img src="https://img.shields.io/badge/Contribute%20with-Gitpod-908a85?logo=gitpod" alt="Contribute with Gitpod" />
|
|
2
|
+
|
|
3
|
+
This module is part of the [Fonoster](https://fonoster.com) project. By itself, it does not do much. It is intended to be used as a dependency for other modules. For more information about the project, please visit [https://github.com/fonoster/fonoster](https://github.com/fonoster/fonoster)(../apiserver/README.md)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AutopilotConfig } from "./types";
|
|
2
|
+
declare class Autopilot {
|
|
3
|
+
private config;
|
|
4
|
+
private assistant;
|
|
5
|
+
private actor;
|
|
6
|
+
private voice;
|
|
7
|
+
constructor(config: AutopilotConfig);
|
|
8
|
+
start(): void;
|
|
9
|
+
private createActor;
|
|
10
|
+
private subscribeToActorState;
|
|
11
|
+
private setupVoiceStream;
|
|
12
|
+
private handleVoicePayload;
|
|
13
|
+
private setupSpeechGathering;
|
|
14
|
+
}
|
|
15
|
+
export { Autopilot };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Autopilot = 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 logger_1 = require("@fonoster/logger");
|
|
24
|
+
const xstate_1 = require("xstate");
|
|
25
|
+
const assistants_1 = require("./assistants");
|
|
26
|
+
const machine_1 = require("./machine/machine");
|
|
27
|
+
const vad_1 = require("./vad");
|
|
28
|
+
const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
|
|
29
|
+
class Autopilot {
|
|
30
|
+
constructor(config) {
|
|
31
|
+
this.config = config;
|
|
32
|
+
this.assistant = (0, assistants_1.makeAssistant)(config.assistantConfig);
|
|
33
|
+
this.actor = this.createActor();
|
|
34
|
+
this.voice = config.voice;
|
|
35
|
+
}
|
|
36
|
+
start() {
|
|
37
|
+
this.actor.start();
|
|
38
|
+
this.setupSpeechGathering();
|
|
39
|
+
this.setupVoiceStream();
|
|
40
|
+
this.subscribeToActorState();
|
|
41
|
+
}
|
|
42
|
+
createActor() {
|
|
43
|
+
const { voice } = this.config;
|
|
44
|
+
const { firstMessage } = this.config.assistantConfig;
|
|
45
|
+
return (0, xstate_1.createActor)(machine_1.machine, {
|
|
46
|
+
input: { firstMessage, voice, assistant: this.assistant }
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
subscribeToActorState() {
|
|
50
|
+
this.actor.subscribe((state) => {
|
|
51
|
+
logger.verbose("actor's new state is", { state: state.value });
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async setupVoiceStream() {
|
|
55
|
+
const stream = await this.config.voice.stream({
|
|
56
|
+
direction: common_1.StreamDirection.OUT
|
|
57
|
+
});
|
|
58
|
+
const vad = await (0, vad_1.makeVad)();
|
|
59
|
+
stream.onPayload(this.handleVoicePayload(vad));
|
|
60
|
+
}
|
|
61
|
+
handleVoicePayload(vad) {
|
|
62
|
+
return async (payload) => {
|
|
63
|
+
try {
|
|
64
|
+
// TODO: Investigate why we need to cast this to Float32Array
|
|
65
|
+
const data = payload.data;
|
|
66
|
+
await vad(data, (event) => {
|
|
67
|
+
if (event === "SPEECH_START" || event === "SPEECH_END") {
|
|
68
|
+
this.actor.send({ type: event });
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
logger.error("an error occurred while processing vad", err);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
async setupSpeechGathering() {
|
|
78
|
+
const stream = await this.voice.sgather({
|
|
79
|
+
source: common_1.StreamGatherSource.SPEECH
|
|
80
|
+
});
|
|
81
|
+
stream.onPayload((payload) => {
|
|
82
|
+
this.actor.send({ type: "HUMAN_PROMPT", speech: payload.speech });
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.Autopilot = Autopilot;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { Model } from "./types";
|
|
3
|
+
declare const AssistantSchema: z.ZodObject<{
|
|
4
|
+
name: z.ZodString;
|
|
5
|
+
firstMessage: z.ZodString;
|
|
6
|
+
systemTemplate: z.ZodString;
|
|
7
|
+
model: z.ZodNativeEnum<typeof Model>;
|
|
8
|
+
temperature: z.ZodNumber;
|
|
9
|
+
maxTokens: z.ZodNumber;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
systemTemplate: string;
|
|
12
|
+
model: Model;
|
|
13
|
+
temperature: number;
|
|
14
|
+
maxTokens: number;
|
|
15
|
+
name: string;
|
|
16
|
+
firstMessage: string;
|
|
17
|
+
}, {
|
|
18
|
+
systemTemplate: string;
|
|
19
|
+
model: Model;
|
|
20
|
+
temperature: number;
|
|
21
|
+
maxTokens: number;
|
|
22
|
+
name: string;
|
|
23
|
+
firstMessage: string;
|
|
24
|
+
}>;
|
|
25
|
+
export { AssistantSchema };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AssistantSchema = 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 zod_1 = require("zod");
|
|
23
|
+
const types_1 = require("./types");
|
|
24
|
+
const AssistantSchema = zod_1.z.object({
|
|
25
|
+
name: zod_1.z.string(),
|
|
26
|
+
firstMessage: zod_1.z.string(),
|
|
27
|
+
systemTemplate: zod_1.z.string(),
|
|
28
|
+
model: zod_1.z.nativeEnum(types_1.Model),
|
|
29
|
+
temperature: zod_1.z.number(),
|
|
30
|
+
maxTokens: zod_1.z.number()
|
|
31
|
+
});
|
|
32
|
+
exports.AssistantSchema = AssistantSchema;
|
|
@@ -0,0 +1,4 @@
|
|
|
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 };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeAssistant = makeAssistant;
|
|
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 output_parsers_1 = require("@langchain/core/output_parsers");
|
|
23
|
+
const prompts_1 = require("@langchain/core/prompts");
|
|
24
|
+
const openai_1 = require("@langchain/openai");
|
|
25
|
+
function makeAssistant(config) {
|
|
26
|
+
const model = new openai_1.ChatOpenAI({
|
|
27
|
+
model: config.model,
|
|
28
|
+
apiKey: config.apiKey,
|
|
29
|
+
maxTokens: config.maxTokens,
|
|
30
|
+
temperature: config.temperature
|
|
31
|
+
});
|
|
32
|
+
const { systemTemplate } = config;
|
|
33
|
+
const parser = new output_parsers_1.StringOutputParser();
|
|
34
|
+
const promptTemplate = prompts_1.ChatPromptTemplate.fromMessages([
|
|
35
|
+
["system", systemTemplate],
|
|
36
|
+
["user", "{text}"]
|
|
37
|
+
]);
|
|
38
|
+
return promptTemplate.pipe(model).pipe(parser);
|
|
39
|
+
}
|
|
@@ -14,11 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.loadAndValidateAssistant = exports.makeAssistant = void 0;
|
|
17
18
|
/*
|
|
18
|
-
* Copyright (C)
|
|
19
|
-
* http://github.com/fonoster/
|
|
19
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
20
|
+
* http://github.com/fonoster/fonoster
|
|
20
21
|
*
|
|
21
|
-
* This file is part of
|
|
22
|
+
* This file is part of Fonoster
|
|
22
23
|
*
|
|
23
24
|
* Licensed under the MIT License (the "License");
|
|
24
25
|
* you may not use this file except in compliance with
|
|
@@ -32,5 +33,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
33
|
* See the License for the specific language governing permissions and
|
|
33
34
|
* limitations under the License.
|
|
34
35
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
var assistants_1 = require("./assistants");
|
|
37
|
+
Object.defineProperty(exports, "makeAssistant", { enumerable: true, get: function () { return assistants_1.makeAssistant; } });
|
|
38
|
+
var loadAndValidateAssistant_1 = require("./loadAndValidateAssistant");
|
|
39
|
+
Object.defineProperty(exports, "loadAndValidateAssistant", { enumerable: true, get: function () { return loadAndValidateAssistant_1.loadAndValidateAssistant; } });
|
|
40
|
+
__exportStar(require("./AssistantSchema"), exports);
|
|
41
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
exports.loadAndValidateAssistant = loadAndValidateAssistant;
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
9
|
+
* http://github.com/fonoster/fonoster
|
|
10
|
+
*
|
|
11
|
+
* This file is part of Fonoster
|
|
12
|
+
*
|
|
13
|
+
* Licensed under the MIT License (the "License");
|
|
14
|
+
* you may not use this file except in compliance with
|
|
15
|
+
* the License. You may obtain a copy of the License at
|
|
16
|
+
*
|
|
17
|
+
* https://opensource.org/licenses/MIT
|
|
18
|
+
*
|
|
19
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
20
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
|
+
* See the License for the specific language governing permissions and
|
|
23
|
+
* limitations under the License.
|
|
24
|
+
*/
|
|
25
|
+
const fs_1 = __importDefault(require("fs"));
|
|
26
|
+
const logger_1 = require("@fonoster/logger");
|
|
27
|
+
const AssistantSchema_1 = require("./AssistantSchema");
|
|
28
|
+
const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
|
|
29
|
+
function loadAndValidateAssistant(path) {
|
|
30
|
+
if (!fs_1.default.existsSync(path)) {
|
|
31
|
+
logger.error("assistant file not found", { path });
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const fileContent = fs_1.default.readFileSync(path, "utf8");
|
|
36
|
+
const assistant = JSON.parse(fileContent);
|
|
37
|
+
return AssistantSchema_1.AssistantSchema.parse(assistant);
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
logger.error("error parsing or validating assistant file", {
|
|
41
|
+
path,
|
|
42
|
+
error: e.message
|
|
43
|
+
});
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare enum Model {
|
|
2
|
+
GPT_3 = "gpt-3",
|
|
3
|
+
GPT_4 = "gpt-4",
|
|
4
|
+
GPT_4O_MINI = "gpt-4o-mini"
|
|
5
|
+
}
|
|
6
|
+
type AssistantFromJson = {
|
|
7
|
+
name: string;
|
|
8
|
+
firstMessage: string;
|
|
9
|
+
systemTemplate: string;
|
|
10
|
+
model: Model;
|
|
11
|
+
temperature: number;
|
|
12
|
+
maxTokens: number;
|
|
13
|
+
};
|
|
14
|
+
type AssistantConfig = AssistantFromJson & {
|
|
15
|
+
apiKey: string;
|
|
16
|
+
};
|
|
17
|
+
export { AssistantFromJson, AssistantConfig, Model };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Model = void 0;
|
|
4
4
|
/*
|
|
5
|
-
* Copyright (C)
|
|
6
|
-
* http://github.com/fonoster/
|
|
5
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
6
|
+
* http://github.com/fonoster/fonoster
|
|
7
7
|
*
|
|
8
|
-
* This file is part of
|
|
8
|
+
* This file is part of Fonoster
|
|
9
9
|
*
|
|
10
10
|
* Licensed under the MIT License (the "License");
|
|
11
11
|
* you may not use this file except in compliance with
|
|
@@ -19,11 +19,9 @@ exports.CLIENT_EVENTS = void 0;
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
-
var
|
|
23
|
-
(function (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
CLIENT_EVENTS["HANGUP"] = "HANGUP";
|
|
29
|
-
})(CLIENT_EVENTS || (exports.CLIENT_EVENTS = CLIENT_EVENTS = {}));
|
|
22
|
+
var Model;
|
|
23
|
+
(function (Model) {
|
|
24
|
+
Model["GPT_3"] = "gpt-3";
|
|
25
|
+
Model["GPT_4"] = "gpt-4";
|
|
26
|
+
Model["GPT_4O_MINI"] = "gpt-4o-mini";
|
|
27
|
+
})(Model || (exports.Model = Model = {}));
|
package/dist/envs.d.ts
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const APISERVER_AUTOPILOT_DEFAULT_LANGUAGE_CODE: string;
|
|
3
|
-
export declare const APISERVER_AUTOPILOT_MEDIA_BUSY_MESSAGE: string;
|
|
4
|
-
export declare const APISERVER_AUTOPILOT_MEDIA_NOANSWER_MESSAGE: string;
|
|
1
|
+
export declare const OPENAI_API_KEY: string | undefined;
|
package/dist/envs.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
6
|
+
exports.OPENAI_API_KEY = void 0;
|
|
4
7
|
/*
|
|
5
|
-
* Copyright (C)
|
|
8
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
6
9
|
* http://github.com/fonoster/fonoster
|
|
7
10
|
*
|
|
8
11
|
* This file is part of Fonoster
|
|
@@ -19,9 +22,9 @@ exports.APISERVER_AUTOPILOT_MEDIA_NOANSWER_MESSAGE = exports.APISERVER_AUTOPILOT
|
|
|
19
22
|
* See the License for the specific language governing permissions and
|
|
20
23
|
* limitations under the License.
|
|
21
24
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
exports.
|
|
25
|
+
const path_1 = require("path");
|
|
26
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
27
|
+
if (process.env.NODE_ENV === "dev") {
|
|
28
|
+
dotenv_1.default.config({ path: (0, path_1.join)(process.cwd(), ".env") });
|
|
29
|
+
}
|
|
30
|
+
exports.OPENAI_API_KEY = process.env.OPENAI_API_KEY;
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export { machine } from "./machine";
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.machine = void 0;
|
|
6
4
|
/*
|
|
7
|
-
* Copyright (C)
|
|
5
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
8
6
|
* http://github.com/fonoster/fonoster
|
|
9
7
|
*
|
|
10
8
|
* This file is part of Fonoster
|
|
@@ -21,10 +19,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
21
19
|
* See the License for the specific language governing permissions and
|
|
22
20
|
* limitations under the License.
|
|
23
21
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
(0, pilot_1.default)({
|
|
27
|
-
defaultLanguageCode: envs_1.APISERVER_AUTOPILOT_DEFAULT_LANGUAGE_CODE,
|
|
28
|
-
port: envs_1.APISERVER_AUTOPILOT_PORT,
|
|
29
|
-
eventsServerEnabled: false
|
|
30
|
-
});
|
|
22
|
+
var machine_1 = require("./machine");
|
|
23
|
+
Object.defineProperty(exports, "machine", { enumerable: true, get: function () { return machine_1.machine; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { machine } from "./machine";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.machine = 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
|
+
var machine_1 = require("./machine");
|
|
23
|
+
Object.defineProperty(exports, "machine", { enumerable: true, get: function () { return machine_1.machine; } });
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
declare const machine: import("xstate").StateMachine<{
|
|
2
|
+
firstMessage: string;
|
|
3
|
+
voice: import("@fonoster/voice").VoiceResponse;
|
|
4
|
+
assistant: import("../assistants/assistants").Assistant;
|
|
5
|
+
playbackRef: string;
|
|
6
|
+
speechBuffer: string;
|
|
7
|
+
speechResponseStartTime: number;
|
|
8
|
+
speechResponseTime: number;
|
|
9
|
+
}, {
|
|
10
|
+
type: "SPEECH_START";
|
|
11
|
+
} | {
|
|
12
|
+
type: "SPEECH_END";
|
|
13
|
+
} | {
|
|
14
|
+
type: "SESSION_END";
|
|
15
|
+
} | {
|
|
16
|
+
type: "HUMAN_PROMPT";
|
|
17
|
+
speech: string;
|
|
18
|
+
}, {}, never, import("xstate").Values<{
|
|
19
|
+
sendGreeting: {
|
|
20
|
+
type: "sendGreeting";
|
|
21
|
+
params: unknown;
|
|
22
|
+
};
|
|
23
|
+
interruptMachineSpeaking: {
|
|
24
|
+
type: "interruptMachineSpeaking";
|
|
25
|
+
params: unknown;
|
|
26
|
+
};
|
|
27
|
+
appendSpeech: {
|
|
28
|
+
type: "appendSpeech";
|
|
29
|
+
params: unknown;
|
|
30
|
+
};
|
|
31
|
+
processHumanRequest: {
|
|
32
|
+
type: "processHumanRequest";
|
|
33
|
+
params: unknown;
|
|
34
|
+
};
|
|
35
|
+
hangup: {
|
|
36
|
+
type: "hangup";
|
|
37
|
+
params: unknown;
|
|
38
|
+
};
|
|
39
|
+
}>, {
|
|
40
|
+
type: "hasSpeechBuffer";
|
|
41
|
+
params: unknown;
|
|
42
|
+
}, never, "hangup" | "welcome" | "machineListening" | "humanSpeaking", string, {
|
|
43
|
+
firstMessage: string;
|
|
44
|
+
voice: import("@fonoster/voice").VoiceResponse;
|
|
45
|
+
assistant: import("../assistants/assistants").Assistant;
|
|
46
|
+
}, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").MetaObject, {
|
|
47
|
+
readonly context: ({ input }: {
|
|
48
|
+
spawn: {
|
|
49
|
+
<TSrc extends never>(logic: TSrc, ...[options]: never): import("xstate").ActorRefFromLogic<never>;
|
|
50
|
+
<TLogic extends import("xstate").AnyActorLogic>(src: TLogic, options?: {
|
|
51
|
+
id?: never;
|
|
52
|
+
systemId?: string;
|
|
53
|
+
input?: import("xstate").InputFrom<TLogic> | undefined;
|
|
54
|
+
syncSnapshot?: boolean;
|
|
55
|
+
} | undefined): import("xstate").ActorRefFromLogic<TLogic>;
|
|
56
|
+
};
|
|
57
|
+
input: {
|
|
58
|
+
firstMessage: string;
|
|
59
|
+
voice: import("@fonoster/voice").VoiceResponse;
|
|
60
|
+
assistant: import("../assistants/assistants").Assistant;
|
|
61
|
+
};
|
|
62
|
+
self: import("xstate").ActorRef<import("xstate").MachineSnapshot<{
|
|
63
|
+
firstMessage: string;
|
|
64
|
+
voice: import("@fonoster/voice").VoiceResponse;
|
|
65
|
+
assistant: import("../assistants/assistants").Assistant;
|
|
66
|
+
playbackRef: string;
|
|
67
|
+
speechBuffer: string;
|
|
68
|
+
speechResponseStartTime: number;
|
|
69
|
+
speechResponseTime: number;
|
|
70
|
+
}, {
|
|
71
|
+
type: "SPEECH_START";
|
|
72
|
+
} | {
|
|
73
|
+
type: "SPEECH_END";
|
|
74
|
+
} | {
|
|
75
|
+
type: "SESSION_END";
|
|
76
|
+
} | {
|
|
77
|
+
type: "HUMAN_PROMPT";
|
|
78
|
+
speech: string;
|
|
79
|
+
}, Record<string, import("xstate").AnyActorRef | undefined>, import("xstate").StateValue, string, unknown, any, any>, {
|
|
80
|
+
type: "SPEECH_START";
|
|
81
|
+
} | {
|
|
82
|
+
type: "SPEECH_END";
|
|
83
|
+
} | {
|
|
84
|
+
type: "SESSION_END";
|
|
85
|
+
} | {
|
|
86
|
+
type: "HUMAN_PROMPT";
|
|
87
|
+
speech: string;
|
|
88
|
+
}, import("xstate").AnyEventObject>;
|
|
89
|
+
}) => {
|
|
90
|
+
firstMessage: string;
|
|
91
|
+
voice: import("@fonoster/voice").VoiceResponse;
|
|
92
|
+
assistant: import("@langchain/core/runnables").Runnable<any, string, import("@langchain/core/runnables").RunnableConfig>;
|
|
93
|
+
playbackRef: string;
|
|
94
|
+
speechBuffer: string;
|
|
95
|
+
speechResponseStartTime: number;
|
|
96
|
+
speechResponseTime: number;
|
|
97
|
+
};
|
|
98
|
+
readonly id: "fnAI";
|
|
99
|
+
readonly initial: "welcome";
|
|
100
|
+
readonly states: {
|
|
101
|
+
readonly welcome: {
|
|
102
|
+
readonly entry: {
|
|
103
|
+
readonly type: "sendGreeting";
|
|
104
|
+
};
|
|
105
|
+
readonly always: {
|
|
106
|
+
readonly target: "machineListening";
|
|
107
|
+
};
|
|
108
|
+
readonly description: "The initial state where the AI greets the Human.";
|
|
109
|
+
};
|
|
110
|
+
readonly machineListening: {
|
|
111
|
+
readonly on: {
|
|
112
|
+
readonly SPEECH_START: {
|
|
113
|
+
readonly target: "humanSpeaking";
|
|
114
|
+
readonly description: "This must be triggered by a VAD or similar system.";
|
|
115
|
+
};
|
|
116
|
+
readonly HUMAN_PROMPT: {
|
|
117
|
+
readonly actions: {
|
|
118
|
+
readonly type: "appendSpeech";
|
|
119
|
+
};
|
|
120
|
+
readonly description: "Appends the speech to the buffer.";
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
readonly description: "The state where the AI is actively listening in conversation.";
|
|
124
|
+
};
|
|
125
|
+
readonly humanSpeaking: {
|
|
126
|
+
readonly entry: {
|
|
127
|
+
readonly type: "interruptMachineSpeaking";
|
|
128
|
+
};
|
|
129
|
+
readonly on: {
|
|
130
|
+
readonly HUMAN_PROMPT: {
|
|
131
|
+
readonly actions: {
|
|
132
|
+
readonly type: "appendSpeech";
|
|
133
|
+
};
|
|
134
|
+
readonly description: "Appends the speech to the buffer.";
|
|
135
|
+
};
|
|
136
|
+
readonly SPEECH_END: {
|
|
137
|
+
readonly target: "machineListening";
|
|
138
|
+
readonly actions: {
|
|
139
|
+
readonly type: "processHumanRequest";
|
|
140
|
+
};
|
|
141
|
+
readonly guard: {
|
|
142
|
+
readonly type: "hasSpeechBuffer";
|
|
143
|
+
};
|
|
144
|
+
readonly description: "This must be triggered by a VAD or similar system.";
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
readonly description: "The state where the AI detects Human speech while it is speaking.";
|
|
148
|
+
};
|
|
149
|
+
readonly hangup: {
|
|
150
|
+
readonly type: "final";
|
|
151
|
+
readonly entry: {
|
|
152
|
+
readonly type: "hangup";
|
|
153
|
+
};
|
|
154
|
+
readonly on: {
|
|
155
|
+
readonly SESSION_END: {
|
|
156
|
+
readonly target: "hangup";
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
readonly description: "The final state where the AI terminates the conversation due to inactivity.";
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
}>;
|
|
163
|
+
export { machine };
|