@livekit/agents 1.0.14 → 1.0.16

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 (133) hide show
  1. package/dist/cli.cjs +12 -12
  2. package/dist/cli.cjs.map +1 -1
  3. package/dist/cli.d.cts +3 -3
  4. package/dist/cli.d.ts +3 -3
  5. package/dist/cli.d.ts.map +1 -1
  6. package/dist/cli.js +13 -13
  7. package/dist/cli.js.map +1 -1
  8. package/dist/inference/stt.cjs.map +1 -1
  9. package/dist/inference/stt.d.ts.map +1 -1
  10. package/dist/inference/stt.js +1 -1
  11. package/dist/inference/stt.js.map +1 -1
  12. package/dist/inference/tts.cjs.map +1 -1
  13. package/dist/inference/tts.d.cts +2 -1
  14. package/dist/inference/tts.d.ts +2 -1
  15. package/dist/inference/tts.d.ts.map +1 -1
  16. package/dist/inference/tts.js +1 -5
  17. package/dist/inference/tts.js.map +1 -1
  18. package/dist/llm/chat_context.cjs +78 -0
  19. package/dist/llm/chat_context.cjs.map +1 -1
  20. package/dist/llm/chat_context.d.cts +16 -0
  21. package/dist/llm/chat_context.d.ts +16 -0
  22. package/dist/llm/chat_context.d.ts.map +1 -1
  23. package/dist/llm/chat_context.js +78 -0
  24. package/dist/llm/chat_context.js.map +1 -1
  25. package/dist/llm/chat_context.test.cjs +531 -0
  26. package/dist/llm/chat_context.test.cjs.map +1 -1
  27. package/dist/llm/chat_context.test.js +531 -0
  28. package/dist/llm/chat_context.test.js.map +1 -1
  29. package/dist/llm/tool_context.cjs +43 -2
  30. package/dist/llm/tool_context.cjs.map +1 -1
  31. package/dist/llm/tool_context.d.cts +39 -11
  32. package/dist/llm/tool_context.d.ts +39 -11
  33. package/dist/llm/tool_context.d.ts.map +1 -1
  34. package/dist/llm/tool_context.js +42 -3
  35. package/dist/llm/tool_context.js.map +1 -1
  36. package/dist/llm/tool_context.test.cjs +197 -0
  37. package/dist/llm/tool_context.test.cjs.map +1 -1
  38. package/dist/llm/tool_context.test.js +175 -0
  39. package/dist/llm/tool_context.test.js.map +1 -1
  40. package/dist/llm/utils.cjs +17 -11
  41. package/dist/llm/utils.cjs.map +1 -1
  42. package/dist/llm/utils.d.cts +1 -2
  43. package/dist/llm/utils.d.ts +1 -2
  44. package/dist/llm/utils.d.ts.map +1 -1
  45. package/dist/llm/utils.js +17 -11
  46. package/dist/llm/utils.js.map +1 -1
  47. package/dist/llm/zod-utils.cjs +99 -0
  48. package/dist/llm/zod-utils.cjs.map +1 -0
  49. package/dist/llm/zod-utils.d.cts +65 -0
  50. package/dist/llm/zod-utils.d.ts +65 -0
  51. package/dist/llm/zod-utils.d.ts.map +1 -0
  52. package/dist/llm/zod-utils.js +61 -0
  53. package/dist/llm/zod-utils.js.map +1 -0
  54. package/dist/llm/zod-utils.test.cjs +389 -0
  55. package/dist/llm/zod-utils.test.cjs.map +1 -0
  56. package/dist/llm/zod-utils.test.js +372 -0
  57. package/dist/llm/zod-utils.test.js.map +1 -0
  58. package/dist/metrics/base.cjs.map +1 -1
  59. package/dist/metrics/base.d.cts +7 -0
  60. package/dist/metrics/base.d.ts +7 -0
  61. package/dist/metrics/base.d.ts.map +1 -1
  62. package/dist/stt/stt.cjs +1 -0
  63. package/dist/stt/stt.cjs.map +1 -1
  64. package/dist/stt/stt.d.cts +7 -1
  65. package/dist/stt/stt.d.ts +7 -1
  66. package/dist/stt/stt.d.ts.map +1 -1
  67. package/dist/stt/stt.js +1 -0
  68. package/dist/stt/stt.js.map +1 -1
  69. package/dist/vad.cjs +16 -0
  70. package/dist/vad.cjs.map +1 -1
  71. package/dist/vad.d.cts +6 -0
  72. package/dist/vad.d.ts +6 -0
  73. package/dist/vad.d.ts.map +1 -1
  74. package/dist/vad.js +16 -0
  75. package/dist/vad.js.map +1 -1
  76. package/dist/voice/agent_activity.cjs +83 -8
  77. package/dist/voice/agent_activity.cjs.map +1 -1
  78. package/dist/voice/agent_activity.d.cts +6 -2
  79. package/dist/voice/agent_activity.d.ts +6 -2
  80. package/dist/voice/agent_activity.d.ts.map +1 -1
  81. package/dist/voice/agent_activity.js +83 -8
  82. package/dist/voice/agent_activity.js.map +1 -1
  83. package/dist/voice/agent_session.cjs +3 -2
  84. package/dist/voice/agent_session.cjs.map +1 -1
  85. package/dist/voice/agent_session.d.cts +2 -1
  86. package/dist/voice/agent_session.d.ts +2 -1
  87. package/dist/voice/agent_session.d.ts.map +1 -1
  88. package/dist/voice/agent_session.js +3 -2
  89. package/dist/voice/agent_session.js.map +1 -1
  90. package/dist/voice/audio_recognition.cjs +138 -16
  91. package/dist/voice/audio_recognition.cjs.map +1 -1
  92. package/dist/voice/audio_recognition.d.cts +11 -0
  93. package/dist/voice/audio_recognition.d.ts +11 -0
  94. package/dist/voice/audio_recognition.d.ts.map +1 -1
  95. package/dist/voice/audio_recognition.js +138 -16
  96. package/dist/voice/audio_recognition.js.map +1 -1
  97. package/dist/voice/generation.cjs +8 -3
  98. package/dist/voice/generation.cjs.map +1 -1
  99. package/dist/voice/generation.d.ts.map +1 -1
  100. package/dist/voice/generation.js +8 -3
  101. package/dist/voice/generation.js.map +1 -1
  102. package/dist/voice/room_io/_input.cjs.map +1 -1
  103. package/dist/voice/room_io/_input.d.ts.map +1 -1
  104. package/dist/voice/room_io/_input.js +0 -1
  105. package/dist/voice/room_io/_input.js.map +1 -1
  106. package/dist/worker.cjs +17 -11
  107. package/dist/worker.cjs.map +1 -1
  108. package/dist/worker.d.cts +16 -9
  109. package/dist/worker.d.ts +16 -9
  110. package/dist/worker.d.ts.map +1 -1
  111. package/dist/worker.js +16 -12
  112. package/dist/worker.js.map +1 -1
  113. package/package.json +5 -4
  114. package/src/cli.ts +17 -17
  115. package/src/inference/stt.ts +2 -1
  116. package/src/inference/tts.ts +2 -5
  117. package/src/llm/__snapshots__/zod-utils.test.ts.snap +341 -0
  118. package/src/llm/chat_context.test.ts +607 -0
  119. package/src/llm/chat_context.ts +106 -0
  120. package/src/llm/tool_context.test.ts +210 -1
  121. package/src/llm/tool_context.ts +101 -17
  122. package/src/llm/utils.ts +18 -15
  123. package/src/llm/zod-utils.test.ts +476 -0
  124. package/src/llm/zod-utils.ts +144 -0
  125. package/src/metrics/base.ts +7 -0
  126. package/src/stt/stt.ts +6 -0
  127. package/src/vad.ts +18 -0
  128. package/src/voice/agent_activity.ts +119 -9
  129. package/src/voice/agent_session.ts +3 -1
  130. package/src/voice/audio_recognition.ts +235 -57
  131. package/src/voice/generation.ts +8 -3
  132. package/src/voice/room_io/_input.ts +1 -1
  133. package/src/worker.ts +29 -18
@@ -1,8 +1,8 @@
1
1
  // SPDX-FileCopyrightText: 2025 LiveKit, Inc.
2
2
  //
3
3
  // SPDX-License-Identifier: Apache-2.0
4
+ import type { AudioFrame } from '@livekit/rtc-node';
4
5
  import {
5
- AudioFrame,
6
6
  AudioStream,
7
7
  type NoiseCancellationOptions,
8
8
  RemoteParticipant,
package/src/worker.ts CHANGED
@@ -10,7 +10,8 @@ import {
10
10
  WorkerMessage,
11
11
  WorkerStatus,
12
12
  } from '@livekit/protocol';
13
- import { AccessToken, ParticipantInfo, RoomServiceClient } from 'livekit-server-sdk';
13
+ import type { ParticipantInfo } from 'livekit-server-sdk';
14
+ import { AccessToken, RoomServiceClient } from 'livekit-server-sdk';
14
15
  import { EventEmitter } from 'node:events';
15
16
  import os from 'node:os';
16
17
  import { WebSocket } from 'ws';
@@ -79,7 +80,7 @@ const defaultRequestFunc = async (ctx: JobRequest) => {
79
80
  };
80
81
 
81
82
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
82
- const defaultCpuLoad = async (worker: Worker): Promise<number> => {
83
+ const defaultCpuLoad = async (worker: AgentServer): Promise<number> => {
83
84
  return new Promise((resolve) => {
84
85
  const cpus1 = os.cpus();
85
86
 
@@ -141,17 +142,17 @@ export class WorkerPermissions {
141
142
  *
142
143
  * This class is mostly useful in conjunction with {@link cli.runApp}.
143
144
  */
144
- export class WorkerOptions {
145
+ export class ServerOptions {
145
146
  agent: string;
146
147
  requestFunc: (job: JobRequest) => Promise<void>;
147
- loadFunc: (worker: Worker) => Promise<number>;
148
+ loadFunc: (worker: AgentServer) => Promise<number>;
148
149
  loadThreshold: number;
149
150
  numIdleProcesses: number;
150
151
  shutdownProcessTimeout: number;
151
152
  initializeProcessTimeout: number;
152
153
  permissions: WorkerPermissions;
153
154
  agentName: string;
154
- workerType: JobType;
155
+ serverType: JobType;
155
156
  maxRetry: number;
156
157
  wsURL: string;
157
158
  apiKey?: string;
@@ -175,7 +176,7 @@ export class WorkerOptions {
175
176
  initializeProcessTimeout = 10 * 1000,
176
177
  permissions = new WorkerPermissions(),
177
178
  agentName = '',
178
- workerType = JobType.JT_ROOM,
179
+ serverType = JobType.JT_ROOM,
179
180
  maxRetry = MAX_RECONNECT_ATTEMPTS,
180
181
  wsURL = 'ws://localhost:7880',
181
182
  apiKey = undefined,
@@ -195,7 +196,7 @@ export class WorkerOptions {
195
196
  agent: string;
196
197
  requestFunc?: (job: JobRequest) => Promise<void>;
197
198
  /** Called to determine the current load of the worker. Should return a value between 0 and 1. */
198
- loadFunc?: (worker: Worker) => Promise<number>;
199
+ loadFunc?: (worker: AgentServer) => Promise<number>;
199
200
  /** When the load exceeds this threshold, the worker will be marked as unavailable. */
200
201
  loadThreshold?: number;
201
202
  numIdleProcesses?: number;
@@ -203,7 +204,7 @@ export class WorkerOptions {
203
204
  initializeProcessTimeout?: number;
204
205
  permissions?: WorkerPermissions;
205
206
  agentName?: string;
206
- workerType?: JobType;
207
+ serverType?: JobType;
207
208
  maxRetry?: number;
208
209
  wsURL?: string;
209
210
  apiKey?: string;
@@ -228,7 +229,7 @@ export class WorkerOptions {
228
229
  this.initializeProcessTimeout = initializeProcessTimeout;
229
230
  this.permissions = permissions;
230
231
  this.agentName = agentName;
231
- this.workerType = workerType;
232
+ this.serverType = serverType;
232
233
  this.maxRetry = maxRetry;
233
234
  this.wsURL = wsURL;
234
235
  this.apiKey = apiKey;
@@ -261,8 +262,8 @@ class PendingAssignment {
261
262
  * you don't have access to a command line, such as a headless program, or one that uses Agents
262
263
  * behind a wrapper.
263
264
  */
264
- export class Worker {
265
- #opts: WorkerOptions;
265
+ export class AgentServer {
266
+ #opts: ServerOptions;
266
267
  #procPool: ProcPool;
267
268
 
268
269
  #id = 'unregistered';
@@ -279,23 +280,23 @@ export class Worker {
279
280
  #logger = log().child({ version });
280
281
  #inferenceExecutor?: InferenceProcExecutor;
281
282
 
282
- /** @throws {@link MissingCredentialsError} if URL, API key or API secret are missing */
283
- constructor(opts: WorkerOptions) {
283
+ /* @throws {@link MissingCredentialsError} if URL, API key or API secret are missing */
284
+ constructor(opts: ServerOptions) {
284
285
  opts.wsURL = opts.wsURL || process.env.LIVEKIT_URL || '';
285
286
  opts.apiKey = opts.apiKey || process.env.LIVEKIT_API_KEY || '';
286
287
  opts.apiSecret = opts.apiSecret || process.env.LIVEKIT_API_SECRET || '';
287
288
 
288
289
  if (opts.wsURL === '')
289
290
  throw new MissingCredentialsError(
290
- 'URL is required: Set LIVEKIT_URL, run with --url, or pass wsURL in WorkerOptions',
291
+ 'URL is required: Set LIVEKIT_URL, run with --url, or pass wsURL in ServerOptions',
291
292
  );
292
293
  if (opts.apiKey === '')
293
294
  throw new MissingCredentialsError(
294
- 'API Key is required: Set LIVEKIT_API_KEY, run with --api-key, or pass apiKey in WorkerOptions',
295
+ 'API Key is required: Set LIVEKIT_API_KEY, run with --api-key, or pass apiKey in ServerOptions',
295
296
  );
296
297
  if (opts.apiSecret === '')
297
298
  throw new MissingCredentialsError(
298
- 'API Secret is required: Set LIVEKIT_API_SECRET, run with --api-secret, or pass apiSecret in WorkerOptions',
299
+ 'API Secret is required: Set LIVEKIT_API_SECRET, run with --api-secret, or pass apiSecret in ServerOptions',
299
300
  );
300
301
 
301
302
  if (opts.workerToken) {
@@ -340,7 +341,7 @@ export class Worker {
340
341
  this.#opts = opts;
341
342
  this.#httpServer = new HTTPServer(opts.host, opts.port, () => ({
342
343
  agent_name: opts.agentName,
343
- worker_type: JobType[opts.workerType],
344
+ worker_type: JobType[opts.serverType],
344
345
  active_jobs: this.activeJobs.length,
345
346
  sdk_version: version,
346
347
  project_type: PROJECT_TYPE,
@@ -610,7 +611,7 @@ export class Worker {
610
611
  message: {
611
612
  case: 'register',
612
613
  value: {
613
- type: this.#opts.workerType,
614
+ type: this.#opts.serverType,
614
615
  agentName: this.#opts.agentName,
615
616
  allowedPermissions: new ParticipantPermission({
616
617
  canPublish: this.#opts.permissions.canPublish,
@@ -788,3 +789,13 @@ export class Worker {
788
789
  await this.#close.await;
789
790
  }
790
791
  }
792
+
793
+ /**
794
+ * @deprecated Use {@link AgentServer} instead. This alias is provided for backward compatibility.
795
+ */
796
+ export const Worker = AgentServer;
797
+
798
+ /**
799
+ * @deprecated Use {@link ServerOptions} instead. This alias is provided for backward compatibility.
800
+ */
801
+ export const WorkerOptions = ServerOptions;