@fonoster/autopilot 0.7.4 → 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.
- package/README.md +156 -2
- package/dist/Autopilot.d.ts +3 -7
- package/dist/Autopilot.js +19 -36
- package/dist/assistants/AssistantSchema.d.ts +575 -30
- package/dist/assistants/AssistantSchema.js +41 -13
- package/dist/assistants/index.d.ts +1 -3
- package/dist/assistants/index.js +1 -6
- package/dist/assistants/loadAndValidateAssistant.d.ts +2 -2
- package/dist/assistants/loadAndValidateAssistant.js +3 -3
- package/dist/assistants/types.d.ts +6 -24
- package/dist/assistants/types.js +0 -25
- package/dist/createLanguageModel.d.ts +3 -0
- package/dist/createLanguageModel.js +40 -0
- package/dist/envs.d.ts +1 -0
- package/dist/envs.js +2 -1
- package/dist/handleVoiceRequest.d.ts +3 -0
- package/dist/handleVoiceRequest.js +66 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.js +23 -3
- package/dist/knowledge/AbstractKnowledgeBase.d.ts +13 -0
- package/dist/knowledge/AbstractKnowledgeBase.js +18 -0
- package/dist/knowledge/FilesKnowledgeBase.d.ts +12 -0
- package/dist/knowledge/FilesKnowledgeBase.js +50 -0
- package/dist/knowledge/index.d.ts +3 -0
- package/dist/knowledge/index.js +37 -0
- package/dist/knowledge/types.d.ts +4 -0
- package/dist/knowledge/types.js +2 -0
- package/dist/loadAssistantConfig.d.ts +3 -0
- package/dist/loadAssistantConfig.js +26 -0
- package/dist/loadKnowledgeBase.d.ts +3 -0
- package/dist/loadKnowledgeBase.js +29 -0
- package/dist/machine/machine.d.ts +27 -28
- package/dist/machine/machine.js +44 -30
- package/dist/models/AbstractLanguageModel.d.ts +11 -0
- package/dist/models/AbstractLanguageModel.js +78 -0
- package/dist/models/LanguageModelFactory.d.ts +16 -0
- package/dist/models/LanguageModelFactory.js +44 -0
- package/dist/models/chatHistory.d.ts +6 -0
- package/dist/models/chatHistory.js +32 -0
- package/dist/models/createChain.d.ts +7 -0
- package/dist/models/createChain.js +15 -0
- package/dist/models/createPromptTemplate.d.ts +2 -0
- package/dist/{assistants/assistants.js → models/createPromptTemplate.js} +7 -16
- package/dist/models/groq/Groq.d.ts +7 -0
- package/dist/models/groq/Groq.js +22 -0
- package/dist/models/groq/index.d.ts +2 -0
- package/dist/models/groq/index.js +36 -0
- package/dist/models/groq/types.d.ts +13 -0
- package/dist/models/groq/types.js +9 -0
- package/dist/models/index.d.ts +2 -0
- package/dist/models/index.js +36 -0
- package/dist/models/openai/OpenAI.d.ts +7 -0
- package/dist/models/openai/OpenAI.js +22 -0
- package/dist/models/openai/index.d.ts +2 -0
- package/dist/models/openai/index.js +36 -0
- package/dist/models/openai/types.d.ts +12 -0
- package/dist/models/openai/types.js +8 -0
- package/dist/models/types.d.ts +19 -0
- package/dist/models/types.js +2 -0
- package/dist/server.js +23 -0
- package/dist/tools/ToolSchema.d.ts +107 -0
- package/dist/tools/ToolSchema.js +64 -0
- package/dist/tools/ToolsCatalog.d.ts +11 -0
- package/dist/tools/ToolsCatalog.js +52 -0
- package/dist/tools/builtin/hangupToolDefinition.d.ts +3 -0
- package/dist/tools/builtin/hangupToolDefinition.js +35 -0
- package/dist/tools/builtin/transferToolDefinition.d.ts +3 -0
- package/dist/tools/builtin/transferToolDefinition.js +35 -0
- package/dist/tools/convertToolToOpenAITool.d.ts +3 -0
- package/dist/tools/convertToolToOpenAITool.js +11 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.js +38 -0
- package/dist/tools/sendRequest.d.ts +11 -0
- package/dist/tools/sendRequest.js +43 -0
- package/dist/tools/type.d.ts +8 -0
- package/dist/tools/type.js +2 -0
- package/dist/types.d.ts +14 -6
- package/dist/types.js +6 -0
- package/dist/vad/SileroVad.d.ts +8 -0
- package/dist/vad/SileroVad.js +39 -0
- package/dist/vad/index.d.ts +1 -2
- package/dist/vad/index.js +1 -2
- package/dist/vad/makeVad.d.ts +1 -1
- package/dist/vad/makeVad.js +2 -2
- package/dist/vad/types.d.ts +4 -2
- package/dist/voice/Voice.d.ts +25 -0
- package/dist/voice/Voice.js +81 -0
- package/dist/voice/index.d.ts +2 -0
- package/dist/voice/index.js +36 -0
- package/dist/voice/types.d.ts +23 -0
- package/dist/voice/types.js +2 -0
- package/dist/voiceServerSetup.d.ts +2 -0
- package/dist/{runner.js → voiceServerSetup.js} +5 -22
- package/package.json +15 -7
- package/dist/assistants/assistants.d.ts +0 -4
- package/dist/machine/machinev0.d.ts +0 -163
- package/dist/machine/machinev0.js +0 -142
- package/dist/machine/types.d.ts +0 -29
- package/dist/machine/types.js +0 -9
- package/dist/runner.d.ts +0 -2
- package/dist/vad/micVadTest.js +0 -48
- /package/dist/{vad/micVadTest.d.ts → server.d.ts} +0 -0
package/dist/server.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
5
|
+
* http://github.com/fonoster/fonoster
|
|
6
|
+
*
|
|
7
|
+
* This file is part of Fonoster
|
|
8
|
+
*
|
|
9
|
+
* Licensed under the MIT License (the "License");
|
|
10
|
+
* you may not use this file except in compliance with
|
|
11
|
+
* the License. You may obtain a copy of the License at
|
|
12
|
+
*
|
|
13
|
+
* https://opensource.org/licenses/MIT
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
* See the License for the specific language governing permissions and
|
|
19
|
+
* limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
const voiceServerSetup_1 = require("./voiceServerSetup");
|
|
22
|
+
const skipIdentity = process.env.NODE_ENV === "dev";
|
|
23
|
+
(0, voiceServerSetup_1.startVoiceServer)(skipIdentity);
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare enum AllowedOperations {
|
|
3
|
+
GET = "get",
|
|
4
|
+
POST = "post",
|
|
5
|
+
BUILT_IN = "built-in"
|
|
6
|
+
}
|
|
7
|
+
declare const toolSchema: z.ZodObject<{
|
|
8
|
+
name: z.ZodString;
|
|
9
|
+
description: z.ZodString;
|
|
10
|
+
parameters: z.ZodObject<{
|
|
11
|
+
type: z.ZodEnum<["object", "array"]>;
|
|
12
|
+
properties: z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodObject<{
|
|
13
|
+
type: z.ZodString;
|
|
14
|
+
format: z.ZodOptional<z.ZodString>;
|
|
15
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
16
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
|
+
type: string;
|
|
18
|
+
format?: string | undefined;
|
|
19
|
+
pattern?: string | undefined;
|
|
20
|
+
}, {
|
|
21
|
+
type: string;
|
|
22
|
+
format?: string | undefined;
|
|
23
|
+
pattern?: string | undefined;
|
|
24
|
+
}>, {
|
|
25
|
+
type: string;
|
|
26
|
+
format?: string | undefined;
|
|
27
|
+
pattern?: string | undefined;
|
|
28
|
+
}, {
|
|
29
|
+
type: string;
|
|
30
|
+
format?: string | undefined;
|
|
31
|
+
pattern?: string | undefined;
|
|
32
|
+
}>>;
|
|
33
|
+
required: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
34
|
+
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
type: "object" | "array";
|
|
36
|
+
properties: Record<string, {
|
|
37
|
+
type: string;
|
|
38
|
+
format?: string | undefined;
|
|
39
|
+
pattern?: string | undefined;
|
|
40
|
+
}>;
|
|
41
|
+
required?: string[] | undefined;
|
|
42
|
+
}, {
|
|
43
|
+
type: "object" | "array";
|
|
44
|
+
properties: Record<string, {
|
|
45
|
+
type: string;
|
|
46
|
+
format?: string | undefined;
|
|
47
|
+
pattern?: string | undefined;
|
|
48
|
+
}>;
|
|
49
|
+
required?: string[] | undefined;
|
|
50
|
+
}>;
|
|
51
|
+
operation: z.ZodEffects<z.ZodObject<{
|
|
52
|
+
type: z.ZodNativeEnum<typeof AllowedOperations>;
|
|
53
|
+
url: z.ZodOptional<z.ZodString>;
|
|
54
|
+
waitForResponse: z.ZodOptional<z.ZodBoolean>;
|
|
55
|
+
}, "strip", z.ZodTypeAny, {
|
|
56
|
+
type: AllowedOperations;
|
|
57
|
+
url?: string | undefined;
|
|
58
|
+
waitForResponse?: boolean | undefined;
|
|
59
|
+
}, {
|
|
60
|
+
type: AllowedOperations;
|
|
61
|
+
url?: string | undefined;
|
|
62
|
+
waitForResponse?: boolean | undefined;
|
|
63
|
+
}>, {
|
|
64
|
+
type: AllowedOperations;
|
|
65
|
+
url?: string | undefined;
|
|
66
|
+
waitForResponse?: boolean | undefined;
|
|
67
|
+
}, {
|
|
68
|
+
type: AllowedOperations;
|
|
69
|
+
url?: string | undefined;
|
|
70
|
+
waitForResponse?: boolean | undefined;
|
|
71
|
+
}>;
|
|
72
|
+
}, "strip", z.ZodTypeAny, {
|
|
73
|
+
name: string;
|
|
74
|
+
description: string;
|
|
75
|
+
parameters: {
|
|
76
|
+
type: "object" | "array";
|
|
77
|
+
properties: Record<string, {
|
|
78
|
+
type: string;
|
|
79
|
+
format?: string | undefined;
|
|
80
|
+
pattern?: string | undefined;
|
|
81
|
+
}>;
|
|
82
|
+
required?: string[] | undefined;
|
|
83
|
+
};
|
|
84
|
+
operation: {
|
|
85
|
+
type: AllowedOperations;
|
|
86
|
+
url?: string | undefined;
|
|
87
|
+
waitForResponse?: boolean | undefined;
|
|
88
|
+
};
|
|
89
|
+
}, {
|
|
90
|
+
name: string;
|
|
91
|
+
description: string;
|
|
92
|
+
parameters: {
|
|
93
|
+
type: "object" | "array";
|
|
94
|
+
properties: Record<string, {
|
|
95
|
+
type: string;
|
|
96
|
+
format?: string | undefined;
|
|
97
|
+
pattern?: string | undefined;
|
|
98
|
+
}>;
|
|
99
|
+
required?: string[] | undefined;
|
|
100
|
+
};
|
|
101
|
+
operation: {
|
|
102
|
+
type: AllowedOperations;
|
|
103
|
+
url?: string | undefined;
|
|
104
|
+
waitForResponse?: boolean | undefined;
|
|
105
|
+
};
|
|
106
|
+
}>;
|
|
107
|
+
export { AllowedOperations, toolSchema };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toolSchema = exports.AllowedOperations = 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
|
+
var AllowedOperations;
|
|
24
|
+
(function (AllowedOperations) {
|
|
25
|
+
AllowedOperations["GET"] = "get";
|
|
26
|
+
AllowedOperations["POST"] = "post";
|
|
27
|
+
AllowedOperations["BUILT_IN"] = "built-in";
|
|
28
|
+
})(AllowedOperations || (exports.AllowedOperations = AllowedOperations = {}));
|
|
29
|
+
const propertySchema = zod_1.z
|
|
30
|
+
.object({
|
|
31
|
+
type: zod_1.z.string(),
|
|
32
|
+
format: zod_1.z.string().optional(),
|
|
33
|
+
pattern: zod_1.z.string().optional()
|
|
34
|
+
})
|
|
35
|
+
.refine((data) => {
|
|
36
|
+
return !("format" in data && "pattern" in data);
|
|
37
|
+
}, {
|
|
38
|
+
message: "Property can only have either 'format' or 'pattern', not both."
|
|
39
|
+
});
|
|
40
|
+
const toolSchema = zod_1.z.object({
|
|
41
|
+
name: zod_1.z.string(),
|
|
42
|
+
description: zod_1.z.string(),
|
|
43
|
+
parameters: zod_1.z.object({
|
|
44
|
+
type: zod_1.z.enum(["object", "array"]),
|
|
45
|
+
properties: zod_1.z.record(propertySchema),
|
|
46
|
+
required: zod_1.z.array(zod_1.z.string()).optional()
|
|
47
|
+
}),
|
|
48
|
+
operation: zod_1.z
|
|
49
|
+
.object({
|
|
50
|
+
type: zod_1.z.nativeEnum(AllowedOperations),
|
|
51
|
+
// Make url required if operation type is not built-in
|
|
52
|
+
url: zod_1.z.string().optional(),
|
|
53
|
+
waitForResponse: zod_1.z.boolean().optional()
|
|
54
|
+
})
|
|
55
|
+
.superRefine(({ url, type }, ctx) => {
|
|
56
|
+
if (type !== AllowedOperations.BUILT_IN && !url) {
|
|
57
|
+
ctx.addIssue({
|
|
58
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
59
|
+
message: "Url is required for non built-in operations."
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
});
|
|
64
|
+
exports.toolSchema = toolSchema;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Tool } from "./type";
|
|
2
|
+
declare class ToolsCatalog {
|
|
3
|
+
private tools;
|
|
4
|
+
constructor(tools: Tool[]);
|
|
5
|
+
invokeTool(toolName: string, args: Record<string, unknown>): Promise<{
|
|
6
|
+
result: string;
|
|
7
|
+
}>;
|
|
8
|
+
addTool(toolDef: Tool): void;
|
|
9
|
+
listTools(): Tool[];
|
|
10
|
+
}
|
|
11
|
+
export { ToolsCatalog };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToolsCatalog = 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 logger_1 = require("@fonoster/logger");
|
|
23
|
+
const sendRequest_1 = require("./sendRequest");
|
|
24
|
+
const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
|
|
25
|
+
class ToolsCatalog {
|
|
26
|
+
constructor(tools) {
|
|
27
|
+
this.tools = new Map();
|
|
28
|
+
tools.forEach((tool) => {
|
|
29
|
+
logger.verbose(`adding the '${tool.name}' tool to the catalog`);
|
|
30
|
+
this.addTool(tool);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async invokeTool(toolName, args) {
|
|
34
|
+
const tool = this.tools.get(toolName);
|
|
35
|
+
if (!tool) {
|
|
36
|
+
throw new Error(`Tool '${toolName}' not found in the catalog`);
|
|
37
|
+
}
|
|
38
|
+
return await (0, sendRequest_1.sendRequest)({
|
|
39
|
+
method: tool.operation.type,
|
|
40
|
+
url: tool.operation.url,
|
|
41
|
+
waitForResponse: tool.operation.waitForResponse,
|
|
42
|
+
body: args
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
addTool(toolDef) {
|
|
46
|
+
this.tools.set(toolDef.name, toolDef);
|
|
47
|
+
}
|
|
48
|
+
listTools() {
|
|
49
|
+
return Array.from(this.tools.values());
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.ToolsCatalog = ToolsCatalog;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hangupToolDefinition = 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 ToolSchema_1 = require("../ToolSchema");
|
|
23
|
+
const hangupToolDefinition = {
|
|
24
|
+
name: "hangup",
|
|
25
|
+
description: "Hangup the call and end the conversation",
|
|
26
|
+
parameters: {
|
|
27
|
+
type: "object",
|
|
28
|
+
properties: {},
|
|
29
|
+
required: ["message"]
|
|
30
|
+
},
|
|
31
|
+
operation: {
|
|
32
|
+
type: ToolSchema_1.AllowedOperations.BUILT_IN
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.hangupToolDefinition = hangupToolDefinition;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transferToolDefinition = 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 ToolSchema_1 = require("../ToolSchema");
|
|
23
|
+
const transferToolDefinition = {
|
|
24
|
+
name: "transfer",
|
|
25
|
+
description: "Transfer the call to a live agent",
|
|
26
|
+
parameters: {
|
|
27
|
+
type: "object",
|
|
28
|
+
properties: {},
|
|
29
|
+
required: []
|
|
30
|
+
},
|
|
31
|
+
operation: {
|
|
32
|
+
type: ToolSchema_1.AllowedOperations.BUILT_IN
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.transferToolDefinition = transferToolDefinition;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/*
|
|
18
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
19
|
+
* http://github.com/fonoster/fonoster
|
|
20
|
+
*
|
|
21
|
+
* This file is part of Fonoster
|
|
22
|
+
*
|
|
23
|
+
* Licensed under the MIT License (the "License");
|
|
24
|
+
* you may not use this file except in compliance with
|
|
25
|
+
* the License. You may obtain a copy of the License at
|
|
26
|
+
*
|
|
27
|
+
* https://opensource.org/licenses/MIT
|
|
28
|
+
*
|
|
29
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
30
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
31
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
32
|
+
* See the License for the specific language governing permissions and
|
|
33
|
+
* limitations under the License.
|
|
34
|
+
*/
|
|
35
|
+
__exportStar(require("./ToolsCatalog"), exports);
|
|
36
|
+
__exportStar(require("./builtin/hangupToolDefinition"), exports);
|
|
37
|
+
__exportStar(require("./builtin/transferToolDefinition"), exports);
|
|
38
|
+
__exportStar(require("./convertToolToOpenAITool"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AllowedOperations } from "./ToolSchema";
|
|
2
|
+
declare function sendRequest(input: {
|
|
3
|
+
method: AllowedOperations;
|
|
4
|
+
url: string;
|
|
5
|
+
waitForResponse: boolean;
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
body?: Record<string, unknown>;
|
|
8
|
+
}): Promise<{
|
|
9
|
+
result: string;
|
|
10
|
+
}>;
|
|
11
|
+
export { sendRequest };
|
|
@@ -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
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 {
|
|
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,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;
|
package/dist/vad/index.d.ts
CHANGED
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("./
|
|
36
|
+
__exportStar(require("./SileroVad"), exports);
|
|
37
37
|
__exportStar(require("./types"), exports);
|
|
38
|
-
__exportStar(require("./makeVad"), exports);
|
package/dist/vad/makeVad.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare function makeVad(pathToModel?: string): Promise<(chunk: Uint8Array, callback: (event: "SPEECH_START" | "SPEECH_END"
|
|
1
|
+
declare function makeVad(pathToModel?: string): Promise<(chunk: Uint8Array, callback: (event: "SPEECH_START" | "SPEECH_END") => void) => Promise<void>>;
|
|
2
2
|
export { makeVad };
|
package/dist/vad/makeVad.js
CHANGED
|
@@ -65,13 +65,13 @@ 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
72
|
else if (isSpeechActive) {
|
|
73
73
|
isSpeechActive = false;
|
|
74
|
-
callback("SPEECH_END"
|
|
74
|
+
callback("SPEECH_END");
|
|
75
75
|
return processBuffer(remainingBuffer);
|
|
76
76
|
}
|
|
77
77
|
return processBuffer(remainingBuffer);
|
package/dist/vad/types.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
type Vad =
|
|
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 {
|
|
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 };
|