@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.
- package/dist/cli.cjs +12 -12
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +3 -3
- package/dist/cli.d.ts +3 -3
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +13 -13
- package/dist/cli.js.map +1 -1
- package/dist/inference/stt.cjs.map +1 -1
- package/dist/inference/stt.d.ts.map +1 -1
- package/dist/inference/stt.js +1 -1
- package/dist/inference/stt.js.map +1 -1
- package/dist/inference/tts.cjs.map +1 -1
- package/dist/inference/tts.d.cts +2 -1
- package/dist/inference/tts.d.ts +2 -1
- package/dist/inference/tts.d.ts.map +1 -1
- package/dist/inference/tts.js +1 -5
- package/dist/inference/tts.js.map +1 -1
- package/dist/llm/chat_context.cjs +78 -0
- package/dist/llm/chat_context.cjs.map +1 -1
- package/dist/llm/chat_context.d.cts +16 -0
- package/dist/llm/chat_context.d.ts +16 -0
- package/dist/llm/chat_context.d.ts.map +1 -1
- package/dist/llm/chat_context.js +78 -0
- package/dist/llm/chat_context.js.map +1 -1
- package/dist/llm/chat_context.test.cjs +531 -0
- package/dist/llm/chat_context.test.cjs.map +1 -1
- package/dist/llm/chat_context.test.js +531 -0
- package/dist/llm/chat_context.test.js.map +1 -1
- package/dist/llm/tool_context.cjs +43 -2
- package/dist/llm/tool_context.cjs.map +1 -1
- package/dist/llm/tool_context.d.cts +39 -11
- package/dist/llm/tool_context.d.ts +39 -11
- package/dist/llm/tool_context.d.ts.map +1 -1
- package/dist/llm/tool_context.js +42 -3
- package/dist/llm/tool_context.js.map +1 -1
- package/dist/llm/tool_context.test.cjs +197 -0
- package/dist/llm/tool_context.test.cjs.map +1 -1
- package/dist/llm/tool_context.test.js +175 -0
- package/dist/llm/tool_context.test.js.map +1 -1
- package/dist/llm/utils.cjs +17 -11
- package/dist/llm/utils.cjs.map +1 -1
- package/dist/llm/utils.d.cts +1 -2
- package/dist/llm/utils.d.ts +1 -2
- package/dist/llm/utils.d.ts.map +1 -1
- package/dist/llm/utils.js +17 -11
- package/dist/llm/utils.js.map +1 -1
- package/dist/llm/zod-utils.cjs +99 -0
- package/dist/llm/zod-utils.cjs.map +1 -0
- package/dist/llm/zod-utils.d.cts +65 -0
- package/dist/llm/zod-utils.d.ts +65 -0
- package/dist/llm/zod-utils.d.ts.map +1 -0
- package/dist/llm/zod-utils.js +61 -0
- package/dist/llm/zod-utils.js.map +1 -0
- package/dist/llm/zod-utils.test.cjs +389 -0
- package/dist/llm/zod-utils.test.cjs.map +1 -0
- package/dist/llm/zod-utils.test.js +372 -0
- package/dist/llm/zod-utils.test.js.map +1 -0
- package/dist/metrics/base.cjs.map +1 -1
- package/dist/metrics/base.d.cts +7 -0
- package/dist/metrics/base.d.ts +7 -0
- package/dist/metrics/base.d.ts.map +1 -1
- package/dist/stt/stt.cjs +1 -0
- package/dist/stt/stt.cjs.map +1 -1
- package/dist/stt/stt.d.cts +7 -1
- package/dist/stt/stt.d.ts +7 -1
- package/dist/stt/stt.d.ts.map +1 -1
- package/dist/stt/stt.js +1 -0
- package/dist/stt/stt.js.map +1 -1
- package/dist/vad.cjs +16 -0
- package/dist/vad.cjs.map +1 -1
- package/dist/vad.d.cts +6 -0
- package/dist/vad.d.ts +6 -0
- package/dist/vad.d.ts.map +1 -1
- package/dist/vad.js +16 -0
- package/dist/vad.js.map +1 -1
- package/dist/voice/agent_activity.cjs +83 -8
- package/dist/voice/agent_activity.cjs.map +1 -1
- package/dist/voice/agent_activity.d.cts +6 -2
- package/dist/voice/agent_activity.d.ts +6 -2
- package/dist/voice/agent_activity.d.ts.map +1 -1
- package/dist/voice/agent_activity.js +83 -8
- package/dist/voice/agent_activity.js.map +1 -1
- package/dist/voice/agent_session.cjs +3 -2
- package/dist/voice/agent_session.cjs.map +1 -1
- package/dist/voice/agent_session.d.cts +2 -1
- package/dist/voice/agent_session.d.ts +2 -1
- package/dist/voice/agent_session.d.ts.map +1 -1
- package/dist/voice/agent_session.js +3 -2
- package/dist/voice/agent_session.js.map +1 -1
- package/dist/voice/audio_recognition.cjs +138 -16
- package/dist/voice/audio_recognition.cjs.map +1 -1
- package/dist/voice/audio_recognition.d.cts +11 -0
- package/dist/voice/audio_recognition.d.ts +11 -0
- package/dist/voice/audio_recognition.d.ts.map +1 -1
- package/dist/voice/audio_recognition.js +138 -16
- package/dist/voice/audio_recognition.js.map +1 -1
- package/dist/voice/generation.cjs +8 -3
- package/dist/voice/generation.cjs.map +1 -1
- package/dist/voice/generation.d.ts.map +1 -1
- package/dist/voice/generation.js +8 -3
- package/dist/voice/generation.js.map +1 -1
- package/dist/voice/room_io/_input.cjs.map +1 -1
- package/dist/voice/room_io/_input.d.ts.map +1 -1
- package/dist/voice/room_io/_input.js +0 -1
- package/dist/voice/room_io/_input.js.map +1 -1
- package/dist/worker.cjs +17 -11
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.cts +16 -9
- package/dist/worker.d.ts +16 -9
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +16 -12
- package/dist/worker.js.map +1 -1
- package/package.json +5 -4
- package/src/cli.ts +17 -17
- package/src/inference/stt.ts +2 -1
- package/src/inference/tts.ts +2 -5
- package/src/llm/__snapshots__/zod-utils.test.ts.snap +341 -0
- package/src/llm/chat_context.test.ts +607 -0
- package/src/llm/chat_context.ts +106 -0
- package/src/llm/tool_context.test.ts +210 -1
- package/src/llm/tool_context.ts +101 -17
- package/src/llm/utils.ts +18 -15
- package/src/llm/zod-utils.test.ts +476 -0
- package/src/llm/zod-utils.ts +144 -0
- package/src/metrics/base.ts +7 -0
- package/src/stt/stt.ts +6 -0
- package/src/vad.ts +18 -0
- package/src/voice/agent_activity.ts +119 -9
- package/src/voice/agent_session.ts +3 -1
- package/src/voice/audio_recognition.ts +235 -57
- package/src/voice/generation.ts +8 -3
- package/src/voice/room_io/_input.ts +1 -1
- package/src/worker.ts +29 -18
package/src/worker.ts
CHANGED
|
@@ -10,7 +10,8 @@ import {
|
|
|
10
10
|
WorkerMessage,
|
|
11
11
|
WorkerStatus,
|
|
12
12
|
} from '@livekit/protocol';
|
|
13
|
-
import {
|
|
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:
|
|
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
|
|
145
|
+
export class ServerOptions {
|
|
145
146
|
agent: string;
|
|
146
147
|
requestFunc: (job: JobRequest) => Promise<void>;
|
|
147
|
-
loadFunc: (worker:
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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.
|
|
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
|
|
265
|
-
#opts:
|
|
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
|
-
|
|
283
|
-
constructor(opts:
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
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.
|
|
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;
|