@livekit/agents-plugin-openai 0.0.0-next-20260624041820
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 +201 -0
- package/README.md +18 -0
- package/dist/index.cjs +74 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/llm.cjs +382 -0
- package/dist/llm.cjs.map +1 -0
- package/dist/llm.d.cts +230 -0
- package/dist/llm.d.ts +230 -0
- package/dist/llm.d.ts.map +1 -0
- package/dist/llm.js +357 -0
- package/dist/llm.js.map +1 -0
- package/dist/llm.test.cjs +36 -0
- package/dist/llm.test.cjs.map +1 -0
- package/dist/llm.test.d.cts +2 -0
- package/dist/llm.test.d.ts +2 -0
- package/dist/llm.test.d.ts.map +1 -0
- package/dist/llm.test.js +35 -0
- package/dist/llm.test.js.map +1 -0
- package/dist/models.cjs +50 -0
- package/dist/models.cjs.map +1 -0
- package/dist/models.d.cts +26 -0
- package/dist/models.d.ts +26 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +25 -0
- package/dist/models.js.map +1 -0
- package/dist/realtime/api_proto.cjs +41 -0
- package/dist/realtime/api_proto.cjs.map +1 -0
- package/dist/realtime/api_proto.d.cts +501 -0
- package/dist/realtime/api_proto.d.ts +501 -0
- package/dist/realtime/api_proto.d.ts.map +1 -0
- package/dist/realtime/api_proto.js +13 -0
- package/dist/realtime/api_proto.js.map +1 -0
- package/dist/realtime/index.cjs +25 -0
- package/dist/realtime/index.cjs.map +1 -0
- package/dist/realtime/index.d.cts +3 -0
- package/dist/realtime/index.d.ts +3 -0
- package/dist/realtime/index.d.ts.map +1 -0
- package/dist/realtime/index.js +3 -0
- package/dist/realtime/index.js.map +1 -0
- package/dist/realtime/realtime_model.cjs +1658 -0
- package/dist/realtime/realtime_model.cjs.map +1 -0
- package/dist/realtime/realtime_model.d.cts +202 -0
- package/dist/realtime/realtime_model.d.ts +202 -0
- package/dist/realtime/realtime_model.d.ts.map +1 -0
- package/dist/realtime/realtime_model.js +1637 -0
- package/dist/realtime/realtime_model.js.map +1 -0
- package/dist/realtime/realtime_model.test.cjs +596 -0
- package/dist/realtime/realtime_model.test.cjs.map +1 -0
- package/dist/realtime/realtime_model.test.d.cts +2 -0
- package/dist/realtime/realtime_model.test.d.ts +2 -0
- package/dist/realtime/realtime_model.test.d.ts.map +1 -0
- package/dist/realtime/realtime_model.test.js +600 -0
- package/dist/realtime/realtime_model.test.js.map +1 -0
- package/dist/responses/index.cjs +23 -0
- package/dist/responses/index.cjs.map +1 -0
- package/dist/responses/index.d.cts +2 -0
- package/dist/responses/index.d.ts +2 -0
- package/dist/responses/index.d.ts.map +1 -0
- package/dist/responses/index.js +2 -0
- package/dist/responses/index.js.map +1 -0
- package/dist/responses/llm.cjs +353 -0
- package/dist/responses/llm.cjs.map +1 -0
- package/dist/responses/llm.d.cts +52 -0
- package/dist/responses/llm.d.ts +52 -0
- package/dist/responses/llm.d.ts.map +1 -0
- package/dist/responses/llm.js +327 -0
- package/dist/responses/llm.js.map +1 -0
- package/dist/responses/llm.test.cjs +37 -0
- package/dist/responses/llm.test.cjs.map +1 -0
- package/dist/responses/llm.test.d.cts +2 -0
- package/dist/responses/llm.test.d.ts +2 -0
- package/dist/responses/llm.test.d.ts.map +1 -0
- package/dist/responses/llm.test.js +36 -0
- package/dist/responses/llm.test.js.map +1 -0
- package/dist/stt.cjs +627 -0
- package/dist/stt.cjs.map +1 -0
- package/dist/stt.d.cts +105 -0
- package/dist/stt.d.ts +105 -0
- package/dist/stt.d.ts.map +1 -0
- package/dist/stt.js +605 -0
- package/dist/stt.js.map +1 -0
- package/dist/stt.test.cjs +132 -0
- package/dist/stt.test.cjs.map +1 -0
- package/dist/stt.test.d.cts +2 -0
- package/dist/stt.test.d.ts +2 -0
- package/dist/stt.test.d.ts.map +1 -0
- package/dist/stt.test.js +131 -0
- package/dist/stt.test.js.map +1 -0
- package/dist/tool_utils.cjs +53 -0
- package/dist/tool_utils.cjs.map +1 -0
- package/dist/tool_utils.d.cts +4 -0
- package/dist/tool_utils.d.ts +4 -0
- package/dist/tool_utils.d.ts.map +1 -0
- package/dist/tool_utils.js +29 -0
- package/dist/tool_utils.js.map +1 -0
- package/dist/tool_utils.test.cjs +77 -0
- package/dist/tool_utils.test.cjs.map +1 -0
- package/dist/tool_utils.test.d.cts +2 -0
- package/dist/tool_utils.test.d.ts +2 -0
- package/dist/tool_utils.test.d.ts.map +1 -0
- package/dist/tool_utils.test.js +76 -0
- package/dist/tool_utils.test.js.map +1 -0
- package/dist/tools.cjs +117 -0
- package/dist/tools.cjs.map +1 -0
- package/dist/tools.d.cts +88 -0
- package/dist/tools.d.ts +88 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +90 -0
- package/dist/tools.js.map +1 -0
- package/dist/tts.cjs +141 -0
- package/dist/tts.cjs.map +1 -0
- package/dist/tts.d.cts +42 -0
- package/dist/tts.d.ts +42 -0
- package/dist/tts.d.ts.map +1 -0
- package/dist/tts.js +116 -0
- package/dist/tts.js.map +1 -0
- package/dist/tts.test.cjs +17 -0
- package/dist/tts.test.cjs.map +1 -0
- package/dist/tts.test.d.cts +2 -0
- package/dist/tts.test.d.ts +2 -0
- package/dist/tts.test.d.ts.map +1 -0
- package/dist/tts.test.js +16 -0
- package/dist/tts.test.js.map +1 -0
- package/dist/ws/index.cjs +29 -0
- package/dist/ws/index.cjs.map +1 -0
- package/dist/ws/index.d.cts +3 -0
- package/dist/ws/index.d.ts +3 -0
- package/dist/ws/index.d.ts.map +1 -0
- package/dist/ws/index.js +5 -0
- package/dist/ws/index.js.map +1 -0
- package/dist/ws/llm.cjs +523 -0
- package/dist/ws/llm.cjs.map +1 -0
- package/dist/ws/llm.d.cts +96 -0
- package/dist/ws/llm.d.ts +96 -0
- package/dist/ws/llm.d.ts.map +1 -0
- package/dist/ws/llm.js +505 -0
- package/dist/ws/llm.js.map +1 -0
- package/dist/ws/llm.test.cjs +69 -0
- package/dist/ws/llm.test.cjs.map +1 -0
- package/dist/ws/llm.test.d.cts +2 -0
- package/dist/ws/llm.test.d.ts +2 -0
- package/dist/ws/llm.test.d.ts.map +1 -0
- package/dist/ws/llm.test.js +68 -0
- package/dist/ws/llm.test.js.map +1 -0
- package/dist/ws/types.cjs +129 -0
- package/dist/ws/types.cjs.map +1 -0
- package/dist/ws/types.d.cts +172 -0
- package/dist/ws/types.d.ts +172 -0
- package/dist/ws/types.d.ts.map +1 -0
- package/dist/ws/types.js +96 -0
- package/dist/ws/types.js.map +1 -0
- package/package.json +56 -0
- package/src/index.ts +25 -0
- package/src/llm.test.ts +38 -0
- package/src/llm.ts +553 -0
- package/src/models.ts +235 -0
- package/src/realtime/api_proto.ts +714 -0
- package/src/realtime/index.ts +5 -0
- package/src/realtime/realtime_model.test.ts +793 -0
- package/src/realtime/realtime_model.ts +2116 -0
- package/src/responses/index.ts +4 -0
- package/src/responses/llm.test.ts +39 -0
- package/src/responses/llm.ts +452 -0
- package/src/stt.test.ts +167 -0
- package/src/stt.ts +793 -0
- package/src/tool_utils.test.ts +84 -0
- package/src/tool_utils.ts +46 -0
- package/src/tools.ts +166 -0
- package/src/tts.test.ts +19 -0
- package/src/tts.ts +158 -0
- package/src/ws/index.ts +17 -0
- package/src/ws/llm.test.ts +83 -0
- package/src/ws/llm.ts +710 -0
- package/src/ws/types.ts +132 -0
package/dist/tools.cjs
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var tools_exports = {};
|
|
20
|
+
__export(tools_exports, {
|
|
21
|
+
CodeInterpreter: () => CodeInterpreter,
|
|
22
|
+
FileSearch: () => FileSearch,
|
|
23
|
+
OpenAITool: () => OpenAITool,
|
|
24
|
+
WebSearch: () => WebSearch
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(tools_exports);
|
|
27
|
+
var import_agents = require("@livekit/agents");
|
|
28
|
+
class OpenAITool extends import_agents.llm.ProviderTool {
|
|
29
|
+
}
|
|
30
|
+
class WebSearch extends OpenAITool {
|
|
31
|
+
/** Filters for the search, such as allowed domains. */
|
|
32
|
+
filters;
|
|
33
|
+
/** Amount of context window space to use for the search. */
|
|
34
|
+
searchContextSize;
|
|
35
|
+
/** Approximate location of the user. */
|
|
36
|
+
userLocation;
|
|
37
|
+
constructor({ filters, searchContextSize = "medium", userLocation } = {}) {
|
|
38
|
+
super({ id: "openai_web_search" });
|
|
39
|
+
this.filters = filters;
|
|
40
|
+
this.searchContextSize = searchContextSize;
|
|
41
|
+
this.userLocation = userLocation;
|
|
42
|
+
}
|
|
43
|
+
toToolConfig() {
|
|
44
|
+
const result = {
|
|
45
|
+
type: "web_search",
|
|
46
|
+
search_context_size: this.searchContextSize
|
|
47
|
+
};
|
|
48
|
+
if (this.userLocation !== void 0) {
|
|
49
|
+
result.user_location = this.userLocation;
|
|
50
|
+
}
|
|
51
|
+
if (this.filters !== void 0) {
|
|
52
|
+
result.filters = this.filters;
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
class FileSearch extends OpenAITool {
|
|
58
|
+
/** IDs of the vector stores to search. */
|
|
59
|
+
vectorStoreIds;
|
|
60
|
+
/** Filter to apply to file search results. */
|
|
61
|
+
filters;
|
|
62
|
+
/** Maximum number of results to return. */
|
|
63
|
+
maxNumResults;
|
|
64
|
+
/** Ranking options for search. */
|
|
65
|
+
rankingOptions;
|
|
66
|
+
constructor({
|
|
67
|
+
vectorStoreIds = [],
|
|
68
|
+
filters,
|
|
69
|
+
maxNumResults,
|
|
70
|
+
rankingOptions
|
|
71
|
+
} = {}) {
|
|
72
|
+
super({ id: "openai_file_search" });
|
|
73
|
+
this.vectorStoreIds = [...vectorStoreIds];
|
|
74
|
+
this.filters = filters;
|
|
75
|
+
this.maxNumResults = maxNumResults;
|
|
76
|
+
this.rankingOptions = rankingOptions;
|
|
77
|
+
}
|
|
78
|
+
toToolConfig() {
|
|
79
|
+
const result = {
|
|
80
|
+
type: "file_search",
|
|
81
|
+
vector_store_ids: this.vectorStoreIds
|
|
82
|
+
};
|
|
83
|
+
if (this.filters !== void 0) {
|
|
84
|
+
result.filters = this.filters;
|
|
85
|
+
}
|
|
86
|
+
if (this.maxNumResults !== void 0) {
|
|
87
|
+
result.max_num_results = this.maxNumResults;
|
|
88
|
+
}
|
|
89
|
+
if (this.rankingOptions !== void 0) {
|
|
90
|
+
result.ranking_options = this.rankingOptions;
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
class CodeInterpreter extends OpenAITool {
|
|
96
|
+
/** Code interpreter container ID or configuration. */
|
|
97
|
+
container;
|
|
98
|
+
constructor({ container = null } = {}) {
|
|
99
|
+
super({ id: "openai_code_interpreter" });
|
|
100
|
+
this.container = container;
|
|
101
|
+
}
|
|
102
|
+
toToolConfig() {
|
|
103
|
+
const result = { type: "code_interpreter" };
|
|
104
|
+
if (this.container !== null) {
|
|
105
|
+
result.container = this.container;
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
111
|
+
0 && (module.exports = {
|
|
112
|
+
CodeInterpreter,
|
|
113
|
+
FileSearch,
|
|
114
|
+
OpenAITool,
|
|
115
|
+
WebSearch
|
|
116
|
+
});
|
|
117
|
+
//# sourceMappingURL=tools.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tools.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { llm } from '@livekit/agents';\nimport type OpenAI from 'openai';\n\n/** Base class for OpenAI Responses API provider tools. */\nexport abstract class OpenAITool extends llm.ProviderTool {\n /** Convert this provider tool to the OpenAI Responses API tool configuration. */\n abstract toToolConfig(): Record<string, unknown>;\n}\n\n/**\n * High-level guidance for the amount of context window space to use for web search.\n * OpenAI defaults this to `medium`.\n */\nexport type WebSearchContextSize = 'low' | 'medium' | 'high';\n\n/** Options for the OpenAI web search tool. */\nexport interface WebSearchOptions {\n /**\n * Filters for the search, such as allowed domains. If not provided, all domains are allowed.\n */\n filters?: OpenAI.Responses.WebSearchTool['filters'];\n\n /**\n * Amount of context window space to use for the search. Defaults to `medium`.\n */\n searchContextSize?: WebSearchContextSize | null;\n\n /** Approximate location of the user, such as city, region, country, or timezone. */\n userLocation?: OpenAI.Responses.WebSearchTool['user_location'];\n}\n\n/**\n * Search the Internet for sources related to the prompt.\n *\n * @see https://platform.openai.com/docs/guides/tools-web-search\n */\nexport class WebSearch extends OpenAITool {\n /** Filters for the search, such as allowed domains. */\n readonly filters: OpenAI.Responses.WebSearchTool['filters'] | undefined;\n\n /** Amount of context window space to use for the search. */\n readonly searchContextSize: WebSearchContextSize | null;\n\n /** Approximate location of the user. */\n readonly userLocation: OpenAI.Responses.WebSearchTool['user_location'] | undefined;\n\n constructor({ filters, searchContextSize = 'medium', userLocation }: WebSearchOptions = {}) {\n super({ id: 'openai_web_search' });\n this.filters = filters;\n this.searchContextSize = searchContextSize;\n this.userLocation = userLocation;\n }\n\n toToolConfig(): Record<string, unknown> {\n const result: Record<string, unknown> = {\n type: 'web_search',\n search_context_size: this.searchContextSize,\n };\n if (this.userLocation !== undefined) {\n result.user_location = this.userLocation;\n }\n if (this.filters !== undefined) {\n result.filters = this.filters;\n }\n return result;\n }\n}\n\n/** Options for the OpenAI file search tool. */\nexport interface FileSearchOptions {\n /** IDs of the vector stores to search. */\n vectorStoreIds?: string[];\n\n /** Filter to apply to file search results. */\n filters?: OpenAI.Responses.FileSearchTool['filters'];\n\n /** Maximum number of results to return. This should be between 1 and 50 inclusive. */\n maxNumResults?: number;\n\n /** Ranking options for search, including ranker and score threshold. */\n rankingOptions?: OpenAI.Responses.FileSearchTool.RankingOptions;\n}\n\n/**\n * Search for relevant content from uploaded files.\n *\n * @see https://platform.openai.com/docs/guides/tools-file-search\n */\nexport class FileSearch extends OpenAITool {\n /** IDs of the vector stores to search. */\n readonly vectorStoreIds: string[];\n\n /** Filter to apply to file search results. */\n readonly filters: OpenAI.Responses.FileSearchTool['filters'] | undefined;\n\n /** Maximum number of results to return. */\n readonly maxNumResults: number | undefined;\n\n /** Ranking options for search. */\n readonly rankingOptions: OpenAI.Responses.FileSearchTool.RankingOptions | undefined;\n\n constructor({\n vectorStoreIds = [],\n filters,\n maxNumResults,\n rankingOptions,\n }: FileSearchOptions = {}) {\n super({ id: 'openai_file_search' });\n this.vectorStoreIds = [...vectorStoreIds];\n this.filters = filters;\n this.maxNumResults = maxNumResults;\n this.rankingOptions = rankingOptions;\n }\n\n toToolConfig(): Record<string, unknown> {\n const result: Record<string, unknown> = {\n type: 'file_search',\n vector_store_ids: this.vectorStoreIds,\n };\n if (this.filters !== undefined) {\n result.filters = this.filters;\n }\n if (this.maxNumResults !== undefined) {\n result.max_num_results = this.maxNumResults;\n }\n if (this.rankingOptions !== undefined) {\n result.ranking_options = this.rankingOptions;\n }\n return result;\n }\n}\n\n/** Options for the OpenAI code interpreter tool. */\nexport interface CodeInterpreterOptions {\n /**\n * Code interpreter container. Can be a container ID or an object that specifies uploaded file IDs\n * to make available to the code.\n */\n container?: OpenAI.Responses.Tool.CodeInterpreter['container'] | null;\n}\n\n/**\n * Run Python code to help generate a response to a prompt.\n *\n * @see https://platform.openai.com/docs/guides/tools-code-interpreter\n */\nexport class CodeInterpreter extends OpenAITool {\n /** Code interpreter container ID or configuration. */\n readonly container: OpenAI.Responses.Tool.CodeInterpreter['container'] | null;\n\n constructor({ container = null }: CodeInterpreterOptions = {}) {\n super({ id: 'openai_code_interpreter' });\n this.container = container;\n }\n\n toToolConfig(): Record<string, unknown> {\n const result: Record<string, unknown> = { type: 'code_interpreter' };\n if (this.container !== null) {\n result.container = this.container;\n }\n return result;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAoB;AAIb,MAAe,mBAAmB,kBAAI,aAAa;AAG1D;AA6BO,MAAM,kBAAkB,WAAW;AAAA;AAAA,EAE/B;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA,EAET,YAAY,EAAE,SAAS,oBAAoB,UAAU,aAAa,IAAsB,CAAC,GAAG;AAC1F,UAAM,EAAE,IAAI,oBAAoB,CAAC;AACjC,SAAK,UAAU;AACf,SAAK,oBAAoB;AACzB,SAAK,eAAe;AAAA,EACtB;AAAA,EAEA,eAAwC;AACtC,UAAM,SAAkC;AAAA,MACtC,MAAM;AAAA,MACN,qBAAqB,KAAK;AAAA,IAC5B;AACA,QAAI,KAAK,iBAAiB,QAAW;AACnC,aAAO,gBAAgB,KAAK;AAAA,IAC9B;AACA,QAAI,KAAK,YAAY,QAAW;AAC9B,aAAO,UAAU,KAAK;AAAA,IACxB;AACA,WAAO;AAAA,EACT;AACF;AAsBO,MAAM,mBAAmB,WAAW;AAAA;AAAA,EAEhC;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA,EAET,YAAY;AAAA,IACV,iBAAiB,CAAC;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAuB,CAAC,GAAG;AACzB,UAAM,EAAE,IAAI,qBAAqB,CAAC;AAClC,SAAK,iBAAiB,CAAC,GAAG,cAAc;AACxC,SAAK,UAAU;AACf,SAAK,gBAAgB;AACrB,SAAK,iBAAiB;AAAA,EACxB;AAAA,EAEA,eAAwC;AACtC,UAAM,SAAkC;AAAA,MACtC,MAAM;AAAA,MACN,kBAAkB,KAAK;AAAA,IACzB;AACA,QAAI,KAAK,YAAY,QAAW;AAC9B,aAAO,UAAU,KAAK;AAAA,IACxB;AACA,QAAI,KAAK,kBAAkB,QAAW;AACpC,aAAO,kBAAkB,KAAK;AAAA,IAChC;AACA,QAAI,KAAK,mBAAmB,QAAW;AACrC,aAAO,kBAAkB,KAAK;AAAA,IAChC;AACA,WAAO;AAAA,EACT;AACF;AAgBO,MAAM,wBAAwB,WAAW;AAAA;AAAA,EAErC;AAAA,EAET,YAAY,EAAE,YAAY,KAAK,IAA4B,CAAC,GAAG;AAC7D,UAAM,EAAE,IAAI,0BAA0B,CAAC;AACvC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,eAAwC;AACtC,UAAM,SAAkC,EAAE,MAAM,mBAAmB;AACnE,QAAI,KAAK,cAAc,MAAM;AAC3B,aAAO,YAAY,KAAK;AAAA,IAC1B;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/tools.d.cts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { llm } from '@livekit/agents';
|
|
2
|
+
import type OpenAI from 'openai';
|
|
3
|
+
/** Base class for OpenAI Responses API provider tools. */
|
|
4
|
+
export declare abstract class OpenAITool extends llm.ProviderTool {
|
|
5
|
+
/** Convert this provider tool to the OpenAI Responses API tool configuration. */
|
|
6
|
+
abstract toToolConfig(): Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* High-level guidance for the amount of context window space to use for web search.
|
|
10
|
+
* OpenAI defaults this to `medium`.
|
|
11
|
+
*/
|
|
12
|
+
export type WebSearchContextSize = 'low' | 'medium' | 'high';
|
|
13
|
+
/** Options for the OpenAI web search tool. */
|
|
14
|
+
export interface WebSearchOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Filters for the search, such as allowed domains. If not provided, all domains are allowed.
|
|
17
|
+
*/
|
|
18
|
+
filters?: OpenAI.Responses.WebSearchTool['filters'];
|
|
19
|
+
/**
|
|
20
|
+
* Amount of context window space to use for the search. Defaults to `medium`.
|
|
21
|
+
*/
|
|
22
|
+
searchContextSize?: WebSearchContextSize | null;
|
|
23
|
+
/** Approximate location of the user, such as city, region, country, or timezone. */
|
|
24
|
+
userLocation?: OpenAI.Responses.WebSearchTool['user_location'];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Search the Internet for sources related to the prompt.
|
|
28
|
+
*
|
|
29
|
+
* @see https://platform.openai.com/docs/guides/tools-web-search
|
|
30
|
+
*/
|
|
31
|
+
export declare class WebSearch extends OpenAITool {
|
|
32
|
+
/** Filters for the search, such as allowed domains. */
|
|
33
|
+
readonly filters: OpenAI.Responses.WebSearchTool['filters'] | undefined;
|
|
34
|
+
/** Amount of context window space to use for the search. */
|
|
35
|
+
readonly searchContextSize: WebSearchContextSize | null;
|
|
36
|
+
/** Approximate location of the user. */
|
|
37
|
+
readonly userLocation: OpenAI.Responses.WebSearchTool['user_location'] | undefined;
|
|
38
|
+
constructor({ filters, searchContextSize, userLocation }?: WebSearchOptions);
|
|
39
|
+
toToolConfig(): Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
/** Options for the OpenAI file search tool. */
|
|
42
|
+
export interface FileSearchOptions {
|
|
43
|
+
/** IDs of the vector stores to search. */
|
|
44
|
+
vectorStoreIds?: string[];
|
|
45
|
+
/** Filter to apply to file search results. */
|
|
46
|
+
filters?: OpenAI.Responses.FileSearchTool['filters'];
|
|
47
|
+
/** Maximum number of results to return. This should be between 1 and 50 inclusive. */
|
|
48
|
+
maxNumResults?: number;
|
|
49
|
+
/** Ranking options for search, including ranker and score threshold. */
|
|
50
|
+
rankingOptions?: OpenAI.Responses.FileSearchTool.RankingOptions;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Search for relevant content from uploaded files.
|
|
54
|
+
*
|
|
55
|
+
* @see https://platform.openai.com/docs/guides/tools-file-search
|
|
56
|
+
*/
|
|
57
|
+
export declare class FileSearch extends OpenAITool {
|
|
58
|
+
/** IDs of the vector stores to search. */
|
|
59
|
+
readonly vectorStoreIds: string[];
|
|
60
|
+
/** Filter to apply to file search results. */
|
|
61
|
+
readonly filters: OpenAI.Responses.FileSearchTool['filters'] | undefined;
|
|
62
|
+
/** Maximum number of results to return. */
|
|
63
|
+
readonly maxNumResults: number | undefined;
|
|
64
|
+
/** Ranking options for search. */
|
|
65
|
+
readonly rankingOptions: OpenAI.Responses.FileSearchTool.RankingOptions | undefined;
|
|
66
|
+
constructor({ vectorStoreIds, filters, maxNumResults, rankingOptions, }?: FileSearchOptions);
|
|
67
|
+
toToolConfig(): Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
/** Options for the OpenAI code interpreter tool. */
|
|
70
|
+
export interface CodeInterpreterOptions {
|
|
71
|
+
/**
|
|
72
|
+
* Code interpreter container. Can be a container ID or an object that specifies uploaded file IDs
|
|
73
|
+
* to make available to the code.
|
|
74
|
+
*/
|
|
75
|
+
container?: OpenAI.Responses.Tool.CodeInterpreter['container'] | null;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Run Python code to help generate a response to a prompt.
|
|
79
|
+
*
|
|
80
|
+
* @see https://platform.openai.com/docs/guides/tools-code-interpreter
|
|
81
|
+
*/
|
|
82
|
+
export declare class CodeInterpreter extends OpenAITool {
|
|
83
|
+
/** Code interpreter container ID or configuration. */
|
|
84
|
+
readonly container: OpenAI.Responses.Tool.CodeInterpreter['container'] | null;
|
|
85
|
+
constructor({ container }?: CodeInterpreterOptions);
|
|
86
|
+
toToolConfig(): Record<string, unknown>;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=tools.d.ts.map
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { llm } from '@livekit/agents';
|
|
2
|
+
import type OpenAI from 'openai';
|
|
3
|
+
/** Base class for OpenAI Responses API provider tools. */
|
|
4
|
+
export declare abstract class OpenAITool extends llm.ProviderTool {
|
|
5
|
+
/** Convert this provider tool to the OpenAI Responses API tool configuration. */
|
|
6
|
+
abstract toToolConfig(): Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* High-level guidance for the amount of context window space to use for web search.
|
|
10
|
+
* OpenAI defaults this to `medium`.
|
|
11
|
+
*/
|
|
12
|
+
export type WebSearchContextSize = 'low' | 'medium' | 'high';
|
|
13
|
+
/** Options for the OpenAI web search tool. */
|
|
14
|
+
export interface WebSearchOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Filters for the search, such as allowed domains. If not provided, all domains are allowed.
|
|
17
|
+
*/
|
|
18
|
+
filters?: OpenAI.Responses.WebSearchTool['filters'];
|
|
19
|
+
/**
|
|
20
|
+
* Amount of context window space to use for the search. Defaults to `medium`.
|
|
21
|
+
*/
|
|
22
|
+
searchContextSize?: WebSearchContextSize | null;
|
|
23
|
+
/** Approximate location of the user, such as city, region, country, or timezone. */
|
|
24
|
+
userLocation?: OpenAI.Responses.WebSearchTool['user_location'];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Search the Internet for sources related to the prompt.
|
|
28
|
+
*
|
|
29
|
+
* @see https://platform.openai.com/docs/guides/tools-web-search
|
|
30
|
+
*/
|
|
31
|
+
export declare class WebSearch extends OpenAITool {
|
|
32
|
+
/** Filters for the search, such as allowed domains. */
|
|
33
|
+
readonly filters: OpenAI.Responses.WebSearchTool['filters'] | undefined;
|
|
34
|
+
/** Amount of context window space to use for the search. */
|
|
35
|
+
readonly searchContextSize: WebSearchContextSize | null;
|
|
36
|
+
/** Approximate location of the user. */
|
|
37
|
+
readonly userLocation: OpenAI.Responses.WebSearchTool['user_location'] | undefined;
|
|
38
|
+
constructor({ filters, searchContextSize, userLocation }?: WebSearchOptions);
|
|
39
|
+
toToolConfig(): Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
/** Options for the OpenAI file search tool. */
|
|
42
|
+
export interface FileSearchOptions {
|
|
43
|
+
/** IDs of the vector stores to search. */
|
|
44
|
+
vectorStoreIds?: string[];
|
|
45
|
+
/** Filter to apply to file search results. */
|
|
46
|
+
filters?: OpenAI.Responses.FileSearchTool['filters'];
|
|
47
|
+
/** Maximum number of results to return. This should be between 1 and 50 inclusive. */
|
|
48
|
+
maxNumResults?: number;
|
|
49
|
+
/** Ranking options for search, including ranker and score threshold. */
|
|
50
|
+
rankingOptions?: OpenAI.Responses.FileSearchTool.RankingOptions;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Search for relevant content from uploaded files.
|
|
54
|
+
*
|
|
55
|
+
* @see https://platform.openai.com/docs/guides/tools-file-search
|
|
56
|
+
*/
|
|
57
|
+
export declare class FileSearch extends OpenAITool {
|
|
58
|
+
/** IDs of the vector stores to search. */
|
|
59
|
+
readonly vectorStoreIds: string[];
|
|
60
|
+
/** Filter to apply to file search results. */
|
|
61
|
+
readonly filters: OpenAI.Responses.FileSearchTool['filters'] | undefined;
|
|
62
|
+
/** Maximum number of results to return. */
|
|
63
|
+
readonly maxNumResults: number | undefined;
|
|
64
|
+
/** Ranking options for search. */
|
|
65
|
+
readonly rankingOptions: OpenAI.Responses.FileSearchTool.RankingOptions | undefined;
|
|
66
|
+
constructor({ vectorStoreIds, filters, maxNumResults, rankingOptions, }?: FileSearchOptions);
|
|
67
|
+
toToolConfig(): Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
/** Options for the OpenAI code interpreter tool. */
|
|
70
|
+
export interface CodeInterpreterOptions {
|
|
71
|
+
/**
|
|
72
|
+
* Code interpreter container. Can be a container ID or an object that specifies uploaded file IDs
|
|
73
|
+
* to make available to the code.
|
|
74
|
+
*/
|
|
75
|
+
container?: OpenAI.Responses.Tool.CodeInterpreter['container'] | null;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Run Python code to help generate a response to a prompt.
|
|
79
|
+
*
|
|
80
|
+
* @see https://platform.openai.com/docs/guides/tools-code-interpreter
|
|
81
|
+
*/
|
|
82
|
+
export declare class CodeInterpreter extends OpenAITool {
|
|
83
|
+
/** Code interpreter container ID or configuration. */
|
|
84
|
+
readonly container: OpenAI.Responses.Tool.CodeInterpreter['container'] | null;
|
|
85
|
+
constructor({ container }?: CodeInterpreterOptions);
|
|
86
|
+
toToolConfig(): Record<string, unknown>;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"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"}
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { llm } from "@livekit/agents";
|
|
2
|
+
class OpenAITool extends llm.ProviderTool {
|
|
3
|
+
}
|
|
4
|
+
class WebSearch extends OpenAITool {
|
|
5
|
+
/** Filters for the search, such as allowed domains. */
|
|
6
|
+
filters;
|
|
7
|
+
/** Amount of context window space to use for the search. */
|
|
8
|
+
searchContextSize;
|
|
9
|
+
/** Approximate location of the user. */
|
|
10
|
+
userLocation;
|
|
11
|
+
constructor({ filters, searchContextSize = "medium", userLocation } = {}) {
|
|
12
|
+
super({ id: "openai_web_search" });
|
|
13
|
+
this.filters = filters;
|
|
14
|
+
this.searchContextSize = searchContextSize;
|
|
15
|
+
this.userLocation = userLocation;
|
|
16
|
+
}
|
|
17
|
+
toToolConfig() {
|
|
18
|
+
const result = {
|
|
19
|
+
type: "web_search",
|
|
20
|
+
search_context_size: this.searchContextSize
|
|
21
|
+
};
|
|
22
|
+
if (this.userLocation !== void 0) {
|
|
23
|
+
result.user_location = this.userLocation;
|
|
24
|
+
}
|
|
25
|
+
if (this.filters !== void 0) {
|
|
26
|
+
result.filters = this.filters;
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
class FileSearch extends OpenAITool {
|
|
32
|
+
/** IDs of the vector stores to search. */
|
|
33
|
+
vectorStoreIds;
|
|
34
|
+
/** Filter to apply to file search results. */
|
|
35
|
+
filters;
|
|
36
|
+
/** Maximum number of results to return. */
|
|
37
|
+
maxNumResults;
|
|
38
|
+
/** Ranking options for search. */
|
|
39
|
+
rankingOptions;
|
|
40
|
+
constructor({
|
|
41
|
+
vectorStoreIds = [],
|
|
42
|
+
filters,
|
|
43
|
+
maxNumResults,
|
|
44
|
+
rankingOptions
|
|
45
|
+
} = {}) {
|
|
46
|
+
super({ id: "openai_file_search" });
|
|
47
|
+
this.vectorStoreIds = [...vectorStoreIds];
|
|
48
|
+
this.filters = filters;
|
|
49
|
+
this.maxNumResults = maxNumResults;
|
|
50
|
+
this.rankingOptions = rankingOptions;
|
|
51
|
+
}
|
|
52
|
+
toToolConfig() {
|
|
53
|
+
const result = {
|
|
54
|
+
type: "file_search",
|
|
55
|
+
vector_store_ids: this.vectorStoreIds
|
|
56
|
+
};
|
|
57
|
+
if (this.filters !== void 0) {
|
|
58
|
+
result.filters = this.filters;
|
|
59
|
+
}
|
|
60
|
+
if (this.maxNumResults !== void 0) {
|
|
61
|
+
result.max_num_results = this.maxNumResults;
|
|
62
|
+
}
|
|
63
|
+
if (this.rankingOptions !== void 0) {
|
|
64
|
+
result.ranking_options = this.rankingOptions;
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
class CodeInterpreter extends OpenAITool {
|
|
70
|
+
/** Code interpreter container ID or configuration. */
|
|
71
|
+
container;
|
|
72
|
+
constructor({ container = null } = {}) {
|
|
73
|
+
super({ id: "openai_code_interpreter" });
|
|
74
|
+
this.container = container;
|
|
75
|
+
}
|
|
76
|
+
toToolConfig() {
|
|
77
|
+
const result = { type: "code_interpreter" };
|
|
78
|
+
if (this.container !== null) {
|
|
79
|
+
result.container = this.container;
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
CodeInterpreter,
|
|
86
|
+
FileSearch,
|
|
87
|
+
OpenAITool,
|
|
88
|
+
WebSearch
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tools.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { llm } from '@livekit/agents';\nimport type OpenAI from 'openai';\n\n/** Base class for OpenAI Responses API provider tools. */\nexport abstract class OpenAITool extends llm.ProviderTool {\n /** Convert this provider tool to the OpenAI Responses API tool configuration. */\n abstract toToolConfig(): Record<string, unknown>;\n}\n\n/**\n * High-level guidance for the amount of context window space to use for web search.\n * OpenAI defaults this to `medium`.\n */\nexport type WebSearchContextSize = 'low' | 'medium' | 'high';\n\n/** Options for the OpenAI web search tool. */\nexport interface WebSearchOptions {\n /**\n * Filters for the search, such as allowed domains. If not provided, all domains are allowed.\n */\n filters?: OpenAI.Responses.WebSearchTool['filters'];\n\n /**\n * Amount of context window space to use for the search. Defaults to `medium`.\n */\n searchContextSize?: WebSearchContextSize | null;\n\n /** Approximate location of the user, such as city, region, country, or timezone. */\n userLocation?: OpenAI.Responses.WebSearchTool['user_location'];\n}\n\n/**\n * Search the Internet for sources related to the prompt.\n *\n * @see https://platform.openai.com/docs/guides/tools-web-search\n */\nexport class WebSearch extends OpenAITool {\n /** Filters for the search, such as allowed domains. */\n readonly filters: OpenAI.Responses.WebSearchTool['filters'] | undefined;\n\n /** Amount of context window space to use for the search. */\n readonly searchContextSize: WebSearchContextSize | null;\n\n /** Approximate location of the user. */\n readonly userLocation: OpenAI.Responses.WebSearchTool['user_location'] | undefined;\n\n constructor({ filters, searchContextSize = 'medium', userLocation }: WebSearchOptions = {}) {\n super({ id: 'openai_web_search' });\n this.filters = filters;\n this.searchContextSize = searchContextSize;\n this.userLocation = userLocation;\n }\n\n toToolConfig(): Record<string, unknown> {\n const result: Record<string, unknown> = {\n type: 'web_search',\n search_context_size: this.searchContextSize,\n };\n if (this.userLocation !== undefined) {\n result.user_location = this.userLocation;\n }\n if (this.filters !== undefined) {\n result.filters = this.filters;\n }\n return result;\n }\n}\n\n/** Options for the OpenAI file search tool. */\nexport interface FileSearchOptions {\n /** IDs of the vector stores to search. */\n vectorStoreIds?: string[];\n\n /** Filter to apply to file search results. */\n filters?: OpenAI.Responses.FileSearchTool['filters'];\n\n /** Maximum number of results to return. This should be between 1 and 50 inclusive. */\n maxNumResults?: number;\n\n /** Ranking options for search, including ranker and score threshold. */\n rankingOptions?: OpenAI.Responses.FileSearchTool.RankingOptions;\n}\n\n/**\n * Search for relevant content from uploaded files.\n *\n * @see https://platform.openai.com/docs/guides/tools-file-search\n */\nexport class FileSearch extends OpenAITool {\n /** IDs of the vector stores to search. */\n readonly vectorStoreIds: string[];\n\n /** Filter to apply to file search results. */\n readonly filters: OpenAI.Responses.FileSearchTool['filters'] | undefined;\n\n /** Maximum number of results to return. */\n readonly maxNumResults: number | undefined;\n\n /** Ranking options for search. */\n readonly rankingOptions: OpenAI.Responses.FileSearchTool.RankingOptions | undefined;\n\n constructor({\n vectorStoreIds = [],\n filters,\n maxNumResults,\n rankingOptions,\n }: FileSearchOptions = {}) {\n super({ id: 'openai_file_search' });\n this.vectorStoreIds = [...vectorStoreIds];\n this.filters = filters;\n this.maxNumResults = maxNumResults;\n this.rankingOptions = rankingOptions;\n }\n\n toToolConfig(): Record<string, unknown> {\n const result: Record<string, unknown> = {\n type: 'file_search',\n vector_store_ids: this.vectorStoreIds,\n };\n if (this.filters !== undefined) {\n result.filters = this.filters;\n }\n if (this.maxNumResults !== undefined) {\n result.max_num_results = this.maxNumResults;\n }\n if (this.rankingOptions !== undefined) {\n result.ranking_options = this.rankingOptions;\n }\n return result;\n }\n}\n\n/** Options for the OpenAI code interpreter tool. */\nexport interface CodeInterpreterOptions {\n /**\n * Code interpreter container. Can be a container ID or an object that specifies uploaded file IDs\n * to make available to the code.\n */\n container?: OpenAI.Responses.Tool.CodeInterpreter['container'] | null;\n}\n\n/**\n * Run Python code to help generate a response to a prompt.\n *\n * @see https://platform.openai.com/docs/guides/tools-code-interpreter\n */\nexport class CodeInterpreter extends OpenAITool {\n /** Code interpreter container ID or configuration. */\n readonly container: OpenAI.Responses.Tool.CodeInterpreter['container'] | null;\n\n constructor({ container = null }: CodeInterpreterOptions = {}) {\n super({ id: 'openai_code_interpreter' });\n this.container = container;\n }\n\n toToolConfig(): Record<string, unknown> {\n const result: Record<string, unknown> = { type: 'code_interpreter' };\n if (this.container !== null) {\n result.container = this.container;\n }\n return result;\n }\n}\n"],"mappings":"AAGA,SAAS,WAAW;AAIb,MAAe,mBAAmB,IAAI,aAAa;AAG1D;AA6BO,MAAM,kBAAkB,WAAW;AAAA;AAAA,EAE/B;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA,EAET,YAAY,EAAE,SAAS,oBAAoB,UAAU,aAAa,IAAsB,CAAC,GAAG;AAC1F,UAAM,EAAE,IAAI,oBAAoB,CAAC;AACjC,SAAK,UAAU;AACf,SAAK,oBAAoB;AACzB,SAAK,eAAe;AAAA,EACtB;AAAA,EAEA,eAAwC;AACtC,UAAM,SAAkC;AAAA,MACtC,MAAM;AAAA,MACN,qBAAqB,KAAK;AAAA,IAC5B;AACA,QAAI,KAAK,iBAAiB,QAAW;AACnC,aAAO,gBAAgB,KAAK;AAAA,IAC9B;AACA,QAAI,KAAK,YAAY,QAAW;AAC9B,aAAO,UAAU,KAAK;AAAA,IACxB;AACA,WAAO;AAAA,EACT;AACF;AAsBO,MAAM,mBAAmB,WAAW;AAAA;AAAA,EAEhC;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA,EAET,YAAY;AAAA,IACV,iBAAiB,CAAC;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAuB,CAAC,GAAG;AACzB,UAAM,EAAE,IAAI,qBAAqB,CAAC;AAClC,SAAK,iBAAiB,CAAC,GAAG,cAAc;AACxC,SAAK,UAAU;AACf,SAAK,gBAAgB;AACrB,SAAK,iBAAiB;AAAA,EACxB;AAAA,EAEA,eAAwC;AACtC,UAAM,SAAkC;AAAA,MACtC,MAAM;AAAA,MACN,kBAAkB,KAAK;AAAA,IACzB;AACA,QAAI,KAAK,YAAY,QAAW;AAC9B,aAAO,UAAU,KAAK;AAAA,IACxB;AACA,QAAI,KAAK,kBAAkB,QAAW;AACpC,aAAO,kBAAkB,KAAK;AAAA,IAChC;AACA,QAAI,KAAK,mBAAmB,QAAW;AACrC,aAAO,kBAAkB,KAAK;AAAA,IAChC;AACA,WAAO;AAAA,EACT;AACF;AAgBO,MAAM,wBAAwB,WAAW;AAAA;AAAA,EAErC;AAAA,EAET,YAAY,EAAE,YAAY,KAAK,IAA4B,CAAC,GAAG;AAC7D,UAAM,EAAE,IAAI,0BAA0B,CAAC;AACvC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,eAAwC;AACtC,UAAM,SAAkC,EAAE,MAAM,mBAAmB;AACnE,QAAI,KAAK,cAAc,MAAM;AAC3B,aAAO,YAAY,KAAK;AAAA,IAC1B;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/tts.cjs
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var tts_exports = {};
|
|
20
|
+
__export(tts_exports, {
|
|
21
|
+
ChunkedStream: () => ChunkedStream,
|
|
22
|
+
TTS: () => TTS
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(tts_exports);
|
|
25
|
+
var import_agents = require("@livekit/agents");
|
|
26
|
+
var import_openai = require("openai");
|
|
27
|
+
const OPENAI_TTS_SAMPLE_RATE = 24e3;
|
|
28
|
+
const OPENAI_TTS_CHANNELS = 1;
|
|
29
|
+
const defaultTTSOptions = {
|
|
30
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
31
|
+
model: "tts-1",
|
|
32
|
+
voice: "alloy",
|
|
33
|
+
speed: 1
|
|
34
|
+
};
|
|
35
|
+
class TTS extends import_agents.tts.TTS {
|
|
36
|
+
#opts;
|
|
37
|
+
#client;
|
|
38
|
+
label = "openai.TTS";
|
|
39
|
+
abortController = new AbortController();
|
|
40
|
+
get model() {
|
|
41
|
+
return this.#opts.model;
|
|
42
|
+
}
|
|
43
|
+
get provider() {
|
|
44
|
+
try {
|
|
45
|
+
const url = new URL(this.#client.baseURL);
|
|
46
|
+
return url.host;
|
|
47
|
+
} catch {
|
|
48
|
+
return "api.openai.com";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Create a new instance of OpenAI TTS.
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* `apiKey` must be set to your OpenAI API key, either using the argument or by setting the
|
|
56
|
+
* `OPENAI_API_KEY` environment variable.
|
|
57
|
+
*/
|
|
58
|
+
constructor(opts = defaultTTSOptions) {
|
|
59
|
+
super(OPENAI_TTS_SAMPLE_RATE, OPENAI_TTS_CHANNELS, { streaming: false });
|
|
60
|
+
this.#opts = { ...defaultTTSOptions, ...opts };
|
|
61
|
+
if (this.#opts.apiKey === void 0 && !this.#opts.client) {
|
|
62
|
+
throw new Error("OpenAI API key is required, whether as an argument or as $OPENAI_API_KEY");
|
|
63
|
+
}
|
|
64
|
+
this.#client = this.#opts.client || new import_openai.OpenAI({
|
|
65
|
+
baseURL: this.#opts.baseURL,
|
|
66
|
+
apiKey: this.#opts.apiKey
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
updateOptions(opts) {
|
|
70
|
+
this.#opts = { ...this.#opts, ...opts };
|
|
71
|
+
}
|
|
72
|
+
synthesize(text, connOptions, abortSignal) {
|
|
73
|
+
const signal = abortSignal ? AbortSignal.any([abortSignal, this.abortController.signal]) : this.abortController.signal;
|
|
74
|
+
return new ChunkedStream(
|
|
75
|
+
this,
|
|
76
|
+
text,
|
|
77
|
+
this.#client.audio.speech.create(
|
|
78
|
+
{
|
|
79
|
+
input: text,
|
|
80
|
+
model: this.#opts.model,
|
|
81
|
+
voice: this.#opts.voice,
|
|
82
|
+
instructions: this.#opts.instructions,
|
|
83
|
+
response_format: "pcm",
|
|
84
|
+
speed: this.#opts.speed
|
|
85
|
+
},
|
|
86
|
+
{ signal }
|
|
87
|
+
),
|
|
88
|
+
connOptions,
|
|
89
|
+
signal
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
stream() {
|
|
93
|
+
throw new Error("Streaming is not supported on OpenAI TTS");
|
|
94
|
+
}
|
|
95
|
+
async close() {
|
|
96
|
+
this.abortController.abort();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
class ChunkedStream extends import_agents.tts.ChunkedStream {
|
|
100
|
+
label = "openai.ChunkedStream";
|
|
101
|
+
stream;
|
|
102
|
+
// set Promise<T> to any because OpenAI returns an annoying Response type
|
|
103
|
+
constructor(tts2, text, stream, connOptions, abortSignal) {
|
|
104
|
+
super(text, tts2, connOptions, abortSignal);
|
|
105
|
+
this.stream = stream;
|
|
106
|
+
}
|
|
107
|
+
async run() {
|
|
108
|
+
try {
|
|
109
|
+
const buffer = await this.stream.then((r) => r.arrayBuffer());
|
|
110
|
+
const requestId = (0, import_agents.shortuuid)();
|
|
111
|
+
const audioByteStream = new import_agents.AudioByteStream(OPENAI_TTS_SAMPLE_RATE, OPENAI_TTS_CHANNELS);
|
|
112
|
+
const frames = audioByteStream.write(buffer);
|
|
113
|
+
let lastFrame;
|
|
114
|
+
const sendLastFrame = (segmentId, final) => {
|
|
115
|
+
if (lastFrame) {
|
|
116
|
+
this.queue.put({ requestId, segmentId, frame: lastFrame, final });
|
|
117
|
+
lastFrame = void 0;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
for (const frame of frames) {
|
|
121
|
+
sendLastFrame(requestId, false);
|
|
122
|
+
lastFrame = frame;
|
|
123
|
+
}
|
|
124
|
+
sendLastFrame(requestId, true);
|
|
125
|
+
this.queue.close();
|
|
126
|
+
} catch (error) {
|
|
127
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
throw error;
|
|
131
|
+
} finally {
|
|
132
|
+
this.queue.close();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
137
|
+
0 && (module.exports = {
|
|
138
|
+
ChunkedStream,
|
|
139
|
+
TTS
|
|
140
|
+
});
|
|
141
|
+
//# sourceMappingURL=tts.cjs.map
|
package/dist/tts.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tts.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { type APIConnectOptions, AudioByteStream, shortuuid, tts } from '@livekit/agents';\nimport type { AudioFrame } from '@livekit/rtc-node';\nimport { OpenAI } from 'openai';\nimport type { TTSModels, TTSVoices } from './models.js';\n\nconst OPENAI_TTS_SAMPLE_RATE = 24000;\nconst OPENAI_TTS_CHANNELS = 1;\n\nexport interface TTSOptions {\n model: TTSModels | string;\n voice: TTSVoices;\n speed: number;\n instructions?: string;\n baseURL?: string;\n client?: OpenAI;\n apiKey?: string;\n}\n\nconst defaultTTSOptions: TTSOptions = {\n apiKey: process.env.OPENAI_API_KEY,\n model: 'tts-1',\n voice: 'alloy',\n speed: 1,\n};\n\nexport class TTS extends tts.TTS {\n #opts: TTSOptions;\n #client: OpenAI;\n label = 'openai.TTS';\n private abortController = new AbortController();\n\n get model(): string {\n return this.#opts.model;\n }\n\n get provider(): string {\n try {\n const url = new URL(this.#client.baseURL);\n return url.host;\n } catch {\n return 'api.openai.com';\n }\n }\n\n /**\n * Create a new instance of OpenAI TTS.\n *\n * @remarks\n * `apiKey` must be set to your OpenAI API key, either using the argument or by setting the\n * `OPENAI_API_KEY` environment variable.\n */\n constructor(opts: Partial<TTSOptions> = defaultTTSOptions) {\n super(OPENAI_TTS_SAMPLE_RATE, OPENAI_TTS_CHANNELS, { streaming: false });\n\n this.#opts = { ...defaultTTSOptions, ...opts };\n if (this.#opts.apiKey === undefined && !this.#opts.client) {\n throw new Error('OpenAI API key is required, whether as an argument or as $OPENAI_API_KEY');\n }\n\n this.#client =\n this.#opts.client ||\n new OpenAI({\n baseURL: this.#opts.baseURL,\n apiKey: this.#opts.apiKey,\n });\n }\n\n updateOptions(opts: { model?: TTSModels | string; voice?: TTSVoices; speed?: number }) {\n this.#opts = { ...this.#opts, ...opts };\n }\n\n synthesize(\n text: string,\n connOptions?: APIConnectOptions,\n abortSignal?: AbortSignal,\n ): ChunkedStream {\n const signal = abortSignal\n ? AbortSignal.any([abortSignal, this.abortController.signal])\n : this.abortController.signal;\n return new ChunkedStream(\n this,\n text,\n this.#client.audio.speech.create(\n {\n input: text,\n model: this.#opts.model,\n voice: this.#opts.voice,\n instructions: this.#opts.instructions,\n response_format: 'pcm',\n speed: this.#opts.speed,\n },\n { signal },\n ),\n connOptions,\n signal,\n );\n }\n\n stream(): tts.SynthesizeStream {\n throw new Error('Streaming is not supported on OpenAI TTS');\n }\n\n async close(): Promise<void> {\n this.abortController.abort();\n }\n}\n\nexport class ChunkedStream extends tts.ChunkedStream {\n label = 'openai.ChunkedStream';\n private stream: Promise<any>;\n\n // set Promise<T> to any because OpenAI returns an annoying Response type\n constructor(\n tts: TTS,\n text: string,\n stream: Promise<any>,\n connOptions?: APIConnectOptions,\n abortSignal?: AbortSignal,\n ) {\n super(text, tts, connOptions, abortSignal);\n this.stream = stream;\n }\n\n protected async run() {\n try {\n const buffer = await this.stream.then((r) => r.arrayBuffer());\n const requestId = shortuuid();\n const audioByteStream = new AudioByteStream(OPENAI_TTS_SAMPLE_RATE, OPENAI_TTS_CHANNELS);\n const frames = audioByteStream.write(buffer);\n\n let lastFrame: AudioFrame | undefined;\n const sendLastFrame = (segmentId: string, final: boolean) => {\n if (lastFrame) {\n this.queue.put({ requestId, segmentId, frame: lastFrame, final });\n lastFrame = undefined;\n }\n };\n\n for (const frame of frames) {\n sendLastFrame(requestId, false);\n lastFrame = frame;\n }\n sendLastFrame(requestId, true);\n\n this.queue.close();\n } catch (error) {\n if (error instanceof Error && error.name === 'AbortError') {\n return;\n }\n throw error;\n } finally {\n this.queue.close();\n }\n }\n}\n"],"mappings":"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","names":["tts"]}
|
package/dist/tts.d.cts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type APIConnectOptions, tts } from '@livekit/agents';
|
|
2
|
+
import { OpenAI } from 'openai';
|
|
3
|
+
import type { TTSModels, TTSVoices } from './models.js';
|
|
4
|
+
export interface TTSOptions {
|
|
5
|
+
model: TTSModels | string;
|
|
6
|
+
voice: TTSVoices;
|
|
7
|
+
speed: number;
|
|
8
|
+
instructions?: string;
|
|
9
|
+
baseURL?: string;
|
|
10
|
+
client?: OpenAI;
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare class TTS extends tts.TTS {
|
|
14
|
+
#private;
|
|
15
|
+
label: string;
|
|
16
|
+
private abortController;
|
|
17
|
+
get model(): string;
|
|
18
|
+
get provider(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Create a new instance of OpenAI TTS.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* `apiKey` must be set to your OpenAI API key, either using the argument or by setting the
|
|
24
|
+
* `OPENAI_API_KEY` environment variable.
|
|
25
|
+
*/
|
|
26
|
+
constructor(opts?: Partial<TTSOptions>);
|
|
27
|
+
updateOptions(opts: {
|
|
28
|
+
model?: TTSModels | string;
|
|
29
|
+
voice?: TTSVoices;
|
|
30
|
+
speed?: number;
|
|
31
|
+
}): void;
|
|
32
|
+
synthesize(text: string, connOptions?: APIConnectOptions, abortSignal?: AbortSignal): ChunkedStream;
|
|
33
|
+
stream(): tts.SynthesizeStream;
|
|
34
|
+
close(): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
export declare class ChunkedStream extends tts.ChunkedStream {
|
|
37
|
+
label: string;
|
|
38
|
+
private stream;
|
|
39
|
+
constructor(tts: TTS, text: string, stream: Promise<any>, connOptions?: APIConnectOptions, abortSignal?: AbortSignal);
|
|
40
|
+
protected run(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=tts.d.ts.map
|
package/dist/tts.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type APIConnectOptions, tts } from '@livekit/agents';
|
|
2
|
+
import { OpenAI } from 'openai';
|
|
3
|
+
import type { TTSModels, TTSVoices } from './models.js';
|
|
4
|
+
export interface TTSOptions {
|
|
5
|
+
model: TTSModels | string;
|
|
6
|
+
voice: TTSVoices;
|
|
7
|
+
speed: number;
|
|
8
|
+
instructions?: string;
|
|
9
|
+
baseURL?: string;
|
|
10
|
+
client?: OpenAI;
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare class TTS extends tts.TTS {
|
|
14
|
+
#private;
|
|
15
|
+
label: string;
|
|
16
|
+
private abortController;
|
|
17
|
+
get model(): string;
|
|
18
|
+
get provider(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Create a new instance of OpenAI TTS.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* `apiKey` must be set to your OpenAI API key, either using the argument or by setting the
|
|
24
|
+
* `OPENAI_API_KEY` environment variable.
|
|
25
|
+
*/
|
|
26
|
+
constructor(opts?: Partial<TTSOptions>);
|
|
27
|
+
updateOptions(opts: {
|
|
28
|
+
model?: TTSModels | string;
|
|
29
|
+
voice?: TTSVoices;
|
|
30
|
+
speed?: number;
|
|
31
|
+
}): void;
|
|
32
|
+
synthesize(text: string, connOptions?: APIConnectOptions, abortSignal?: AbortSignal): ChunkedStream;
|
|
33
|
+
stream(): tts.SynthesizeStream;
|
|
34
|
+
close(): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
export declare class ChunkedStream extends tts.ChunkedStream {
|
|
37
|
+
label: string;
|
|
38
|
+
private stream;
|
|
39
|
+
constructor(tts: TTS, text: string, stream: Promise<any>, connOptions?: APIConnectOptions, abortSignal?: AbortSignal);
|
|
40
|
+
protected run(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=tts.d.ts.map
|