@livekit/agents-plugin-openai 1.4.9 → 1.5.0

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 (84) hide show
  1. package/dist/index.cjs +4 -2
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +1 -0
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +2 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/llm.cjs +8 -2
  9. package/dist/llm.cjs.map +1 -1
  10. package/dist/llm.d.cts +4 -3
  11. package/dist/llm.d.ts +4 -3
  12. package/dist/llm.d.ts.map +1 -1
  13. package/dist/llm.js +8 -2
  14. package/dist/llm.js.map +1 -1
  15. package/dist/models.cjs +12 -3
  16. package/dist/models.cjs.map +1 -1
  17. package/dist/models.d.cts +7 -1
  18. package/dist/models.d.ts +7 -1
  19. package/dist/models.d.ts.map +1 -1
  20. package/dist/models.js +11 -3
  21. package/dist/models.js.map +1 -1
  22. package/dist/realtime/api_proto.cjs.map +1 -1
  23. package/dist/realtime/api_proto.d.cts +1 -0
  24. package/dist/realtime/api_proto.d.ts +1 -0
  25. package/dist/realtime/api_proto.d.ts.map +1 -1
  26. package/dist/realtime/api_proto.js.map +1 -1
  27. package/dist/realtime/realtime_model.cjs +85 -27
  28. package/dist/realtime/realtime_model.cjs.map +1 -1
  29. package/dist/realtime/realtime_model.d.cts +2 -1
  30. package/dist/realtime/realtime_model.d.ts +2 -1
  31. package/dist/realtime/realtime_model.d.ts.map +1 -1
  32. package/dist/realtime/realtime_model.js +85 -27
  33. package/dist/realtime/realtime_model.js.map +1 -1
  34. package/dist/realtime/realtime_model.test.cjs +28 -0
  35. package/dist/realtime/realtime_model.test.cjs.map +1 -1
  36. package/dist/realtime/realtime_model.test.js +28 -0
  37. package/dist/realtime/realtime_model.test.js.map +1 -1
  38. package/dist/responses/llm.cjs +15 -18
  39. package/dist/responses/llm.cjs.map +1 -1
  40. package/dist/responses/llm.d.cts +4 -2
  41. package/dist/responses/llm.d.ts +4 -2
  42. package/dist/responses/llm.d.ts.map +1 -1
  43. package/dist/responses/llm.js +15 -18
  44. package/dist/responses/llm.js.map +1 -1
  45. package/dist/tool_utils.cjs +53 -0
  46. package/dist/tool_utils.cjs.map +1 -0
  47. package/dist/tool_utils.d.cts +4 -0
  48. package/dist/tool_utils.d.ts +4 -0
  49. package/dist/tool_utils.d.ts.map +1 -0
  50. package/dist/tool_utils.js +29 -0
  51. package/dist/tool_utils.js.map +1 -0
  52. package/dist/tool_utils.test.cjs +77 -0
  53. package/dist/tool_utils.test.cjs.map +1 -0
  54. package/dist/tool_utils.test.d.cts +2 -0
  55. package/dist/tool_utils.test.d.ts +2 -0
  56. package/dist/tool_utils.test.d.ts.map +1 -0
  57. package/dist/tool_utils.test.js +76 -0
  58. package/dist/tool_utils.test.js.map +1 -0
  59. package/dist/tools.cjs +117 -0
  60. package/dist/tools.cjs.map +1 -0
  61. package/dist/tools.d.cts +88 -0
  62. package/dist/tools.d.ts +88 -0
  63. package/dist/tools.d.ts.map +1 -0
  64. package/dist/tools.js +90 -0
  65. package/dist/tools.js.map +1 -0
  66. package/dist/ws/llm.cjs +15 -18
  67. package/dist/ws/llm.cjs.map +1 -1
  68. package/dist/ws/llm.d.cts +5 -3
  69. package/dist/ws/llm.d.ts +5 -3
  70. package/dist/ws/llm.d.ts.map +1 -1
  71. package/dist/ws/llm.js +15 -18
  72. package/dist/ws/llm.js.map +1 -1
  73. package/package.json +7 -7
  74. package/src/index.ts +1 -0
  75. package/src/llm.ts +16 -3
  76. package/src/models.ts +18 -3
  77. package/src/realtime/api_proto.ts +1 -0
  78. package/src/realtime/realtime_model.test.ts +38 -0
  79. package/src/realtime/realtime_model.ts +104 -28
  80. package/src/responses/llm.ts +27 -23
  81. package/src/tool_utils.test.ts +84 -0
  82. package/src/tool_utils.ts +46 -0
  83. package/src/tools.ts +166 -0
  84. package/src/ws/llm.ts +25 -24
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":[]}
@@ -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,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.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AM,CAAC,MAAM,EAAE,OAAO,CAAC;CAOxC"}
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/ws/llm.cjs CHANGED
@@ -26,6 +26,8 @@ __export(llm_exports, {
26
26
  module.exports = __toCommonJS(llm_exports);
27
27
  var import_agents = require("@livekit/agents");
28
28
  var import_ws = require("ws");
29
+ var import_models = require("../models.cjs");
30
+ var import_tool_utils = require("../tool_utils.cjs");
29
31
  var import_types = require("./types.cjs");
30
32
  const OPENAI_RESPONSES_WS_URL = "wss://api.openai.com/v1/responses";
31
33
  const WS_MAX_SESSION_DURATION = 36e5;
@@ -124,6 +126,12 @@ class WSLLM extends import_agents.llm.LLM {
124
126
  constructor(opts = defaultLLMOptions) {
125
127
  super();
126
128
  this.#opts = { ...defaultLLMOptions, ...opts };
129
+ if (this.#opts.reasoning === void 0) {
130
+ const effort = (0, import_models.defaultReasoningEffort)(this.#opts.model);
131
+ if (effort !== void 0) {
132
+ this.#opts.reasoning = { effort };
133
+ }
134
+ }
127
135
  if (!this.#opts.apiKey) {
128
136
  throw new Error("OpenAI API key is required, whether as an argument or as $OPENAI_API_KEY");
129
137
  }
@@ -165,16 +173,17 @@ class WSLLM extends import_agents.llm.LLM {
165
173
  }
166
174
  chat({
167
175
  chatCtx,
168
- toolCtx,
176
+ toolCtx: toolCtxInput,
169
177
  connOptions = import_agents.DEFAULT_API_CONNECT_OPTIONS,
170
178
  parallelToolCalls,
171
179
  toolChoice,
172
180
  extraKwargs
173
181
  }) {
174
182
  var _a;
183
+ const toolCtx = import_agents.llm.toToolContext(toolCtxInput);
175
184
  const modelOptions = { ...extraKwargs ?? {} };
176
185
  parallelToolCalls = parallelToolCalls !== void 0 ? parallelToolCalls : this.#opts.parallelToolCalls;
177
- if (toolCtx && Object.keys(toolCtx).length > 0 && parallelToolCalls !== void 0) {
186
+ if (toolCtx && Object.keys(toolCtx.functionTools).length > 0 && parallelToolCalls !== void 0) {
178
187
  modelOptions.parallel_tool_calls = parallelToolCalls;
179
188
  }
180
189
  toolChoice = toolChoice !== void 0 ? toolChoice : this.#opts.toolChoice;
@@ -196,6 +205,9 @@ class WSLLM extends import_agents.llm.LLM {
196
205
  if (this.#opts.maxOutputTokens !== void 0) {
197
206
  modelOptions.max_output_tokens = this.#opts.maxOutputTokens;
198
207
  }
208
+ if (this.#opts.reasoning !== void 0) {
209
+ modelOptions.reasoning = this.#opts.reasoning;
210
+ }
199
211
  let inputChatCtx = chatCtx;
200
212
  let prevResponseId;
201
213
  const canUseStoredResponse = modelOptions.store !== false;
@@ -292,22 +304,7 @@ class WSLLMStream extends import_agents.llm.LLMStream {
292
304
  const messages = await chatCtx.toProviderFormat(
293
305
  "openai.responses"
294
306
  );
295
- const tools = this.toolCtx ? import_agents.llm.sortedToolEntries(this.toolCtx).map(([name, func]) => {
296
- const oaiParams = {
297
- type: "function",
298
- name,
299
- description: func.description,
300
- parameters: import_agents.llm.toJsonSchema(
301
- func.parameters,
302
- true,
303
- this.#strictToolSchema
304
- )
305
- };
306
- if (this.#strictToolSchema) {
307
- oaiParams.strict = true;
308
- }
309
- return oaiParams;
310
- }) : void 0;
307
+ const tools = this.toolCtx ? (0, import_tool_utils.toResponsesTools)(this.toolCtx, this.#strictToolSchema) : void 0;
311
308
  const requestOptions = { ...this.#modelOptions };
312
309
  if (!tools) {
313
310
  delete requestOptions.tool_choice;