@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,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("./Groq"), 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,13 @@
1
+ import { BaseModelParams } from "../types";
2
+ declare enum GroqModel {
3
+ GEMMA7B = "gemma-7b-it",
4
+ LLAMA3_GROQ_70B_8192_TOOL_USE_PREVIEW = "llama3-groq-70b-8192-tool-use-preview",
5
+ LLAMA3_1_8B_INSTANT = "llama-3.1-8b-instant"
6
+ }
7
+ type GroqParams = BaseModelParams & {
8
+ model: GroqModel;
9
+ apiKey: string;
10
+ maxTokens: number;
11
+ temperature: number;
12
+ };
13
+ export { GroqModel, GroqParams };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GroqModel = void 0;
4
+ var GroqModel;
5
+ (function (GroqModel) {
6
+ GroqModel["GEMMA7B"] = "gemma-7b-it";
7
+ GroqModel["LLAMA3_GROQ_70B_8192_TOOL_USE_PREVIEW"] = "llama3-groq-70b-8192-tool-use-preview";
8
+ GroqModel["LLAMA3_1_8B_INSTANT"] = "llama-3.1-8b-instant";
9
+ })(GroqModel || (exports.GroqModel = GroqModel = {}));
@@ -0,0 +1,2 @@
1
+ export * from "./LanguageModelFactory";
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("./LanguageModelFactory"), 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,7 @@
1
+ import { OpenAIParams } from "./types";
2
+ import { AbstractLanguageModel } from "../AbstractLanguageModel";
3
+ declare const LANGUAGE_MODEL_NAME = "llm.openai";
4
+ declare class OpenAI extends AbstractLanguageModel {
5
+ constructor(params: OpenAIParams);
6
+ }
7
+ export { LANGUAGE_MODEL_NAME, OpenAI };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpenAI = exports.LANGUAGE_MODEL_NAME = void 0;
4
+ const openai_1 = require("@langchain/openai");
5
+ const tools_1 = require("../../tools");
6
+ const AbstractLanguageModel_1 = require("../AbstractLanguageModel");
7
+ const LANGUAGE_MODEL_NAME = "llm.openai";
8
+ exports.LANGUAGE_MODEL_NAME = LANGUAGE_MODEL_NAME;
9
+ class OpenAI extends AbstractLanguageModel_1.AbstractLanguageModel {
10
+ constructor(params) {
11
+ const model = new openai_1.ChatOpenAI({
12
+ ...params
13
+ }).bind({
14
+ tools: params.tools.map(tools_1.convertToolToOpenAITool)
15
+ });
16
+ super({
17
+ ...params,
18
+ model
19
+ });
20
+ }
21
+ }
22
+ exports.OpenAI = OpenAI;
@@ -0,0 +1,2 @@
1
+ export * from "./OpenAI";
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("./OpenAI"), 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,12 @@
1
+ import { BaseModelParams } from "../types";
2
+ declare enum OpenAIModel {
3
+ GPT_4O = "gpt-4o",
4
+ GPT_4O_MINI = "gpt-4o-mini"
5
+ }
6
+ type OpenAIParams = BaseModelParams & {
7
+ model: OpenAIModel;
8
+ apiKey: string;
9
+ maxTokens: number;
10
+ temperature: number;
11
+ };
12
+ export { OpenAIModel, OpenAIParams };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpenAIModel = void 0;
4
+ var OpenAIModel;
5
+ (function (OpenAIModel) {
6
+ OpenAIModel["GPT_4O"] = "gpt-4o";
7
+ OpenAIModel["GPT_4O_MINI"] = "gpt-4o-mini";
8
+ })(OpenAIModel || (exports.OpenAIModel = OpenAIModel = {}));
@@ -0,0 +1,19 @@
1
+ import { BaseChatModel } from "@langchain/core/language_models/chat_models";
2
+ import { KnowledgeBase } from "../knowledge";
3
+ import { Tool } from "../tools/type";
4
+ type LanguageModel = {
5
+ invoke: (text: string) => Promise<InvocationResult>;
6
+ };
7
+ type BaseModelParams = {
8
+ systemTemplate: string;
9
+ knowledgeBase: KnowledgeBase;
10
+ tools: Tool[];
11
+ };
12
+ type LanguageModelParams = BaseModelParams & {
13
+ model: BaseChatModel;
14
+ };
15
+ type InvocationResult = {
16
+ type: "say" | "hangup" | "transfer";
17
+ content?: string;
18
+ };
19
+ export { BaseModelParams, InvocationResult, LanguageModel, LanguageModelParams };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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,3 @@
1
+ import { Tool } from "../type";
2
+ declare const hangupToolDefinition: Tool;
3
+ export { hangupToolDefinition };
@@ -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,3 @@
1
+ import { Tool } from "../type";
2
+ declare const transferToolDefinition: Tool;
3
+ export { transferToolDefinition };
@@ -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,3 @@
1
+ import { OpenAITool, Tool } from "./type";
2
+ declare function convertToolToOpenAITool(tool: Tool): OpenAITool;
3
+ export { convertToolToOpenAITool };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertToolToOpenAITool = convertToolToOpenAITool;
4
+ function convertToolToOpenAITool(tool) {
5
+ return {
6
+ type: "function",
7
+ function: {
8
+ ...tool
9
+ }
10
+ };
11
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./ToolsCatalog";
2
+ export * from "./builtin/hangupToolDefinition";
3
+ export * from "./builtin/transferToolDefinition";
4
+ export * from "./convertToolToOpenAITool";
@@ -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 };