@livekit/agents 0.4.6 → 0.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.
- package/README.md +17 -0
- package/dist/audio.cjs +77 -0
- package/dist/audio.cjs.map +1 -0
- package/dist/audio.js +48 -37
- package/dist/audio.js.map +1 -1
- package/dist/cli.cjs +131 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.js +96 -122
- package/dist/cli.js.map +1 -1
- package/dist/generator.cjs +36 -0
- package/dist/generator.cjs.map +1 -0
- package/dist/generator.js +8 -22
- package/dist/generator.js.map +1 -1
- package/dist/http_server.cjs +72 -0
- package/dist/http_server.cjs.map +1 -0
- package/dist/http_server.d.ts +1 -1
- package/dist/http_server.js +44 -47
- package/dist/http_server.js.map +1 -1
- package/dist/index.cjs +78 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +26 -28
- package/dist/index.js.map +1 -1
- package/dist/ipc/job_executor.cjs +33 -0
- package/dist/ipc/job_executor.cjs.map +1 -0
- package/dist/ipc/job_executor.js +7 -4
- package/dist/ipc/job_executor.js.map +1 -1
- package/dist/ipc/job_main.cjs +147 -0
- package/dist/ipc/job_main.cjs.map +1 -0
- package/dist/ipc/job_main.d.ts +1 -1
- package/dist/ipc/job_main.js +103 -103
- package/dist/ipc/job_main.js.map +1 -1
- package/dist/ipc/message.cjs +17 -0
- package/dist/ipc/message.cjs.map +1 -0
- package/dist/ipc/message.js +0 -1
- package/dist/ipc/message.js.map +1 -1
- package/dist/ipc/proc_job_executor.cjs +174 -0
- package/dist/ipc/proc_job_executor.cjs.map +1 -0
- package/dist/ipc/proc_job_executor.js +130 -126
- package/dist/ipc/proc_job_executor.js.map +1 -1
- package/dist/ipc/proc_pool.cjs +126 -0
- package/dist/ipc/proc_pool.cjs.map +1 -0
- package/dist/ipc/proc_pool.js +93 -96
- package/dist/ipc/proc_pool.js.map +1 -1
- package/dist/job.cjs +230 -0
- package/dist/job.cjs.map +1 -0
- package/dist/job.js +195 -198
- package/dist/job.js.map +1 -1
- package/dist/llm/chat_context.cjs +131 -0
- package/dist/llm/chat_context.cjs.map +1 -0
- package/dist/llm/chat_context.js +98 -86
- package/dist/llm/chat_context.js.map +1 -1
- package/dist/llm/function_context.cjs +103 -0
- package/dist/llm/function_context.cjs.map +1 -0
- package/dist/llm/function_context.js +72 -81
- package/dist/llm/function_context.js.map +1 -1
- package/dist/llm/function_context.test.cjs +218 -0
- package/dist/llm/function_context.test.cjs.map +1 -0
- package/dist/llm/function_context.test.js +209 -210
- package/dist/llm/function_context.test.js.map +1 -1
- package/dist/llm/index.cjs +43 -0
- package/dist/llm/index.cjs.map +1 -0
- package/dist/llm/index.js +22 -6
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/llm.cjs +76 -0
- package/dist/llm/llm.cjs.map +1 -0
- package/dist/llm/llm.js +48 -42
- package/dist/llm/llm.js.map +1 -1
- package/dist/log.cjs +57 -0
- package/dist/log.cjs.map +1 -0
- package/dist/log.js +27 -26
- package/dist/log.js.map +1 -1
- package/dist/multimodal/agent_playout.cjs +228 -0
- package/dist/multimodal/agent_playout.cjs.map +1 -0
- package/dist/multimodal/agent_playout.d.ts +1 -1
- package/dist/multimodal/agent_playout.js +193 -180
- package/dist/multimodal/agent_playout.js.map +1 -1
- package/dist/multimodal/index.cjs +25 -0
- package/dist/multimodal/index.cjs.map +1 -0
- package/dist/multimodal/index.js +2 -5
- package/dist/multimodal/index.js.map +1 -1
- package/dist/multimodal/multimodal_agent.cjs +404 -0
- package/dist/multimodal/multimodal_agent.cjs.map +1 -0
- package/dist/multimodal/multimodal_agent.d.ts +1 -1
- package/dist/multimodal/multimodal_agent.js +351 -330
- package/dist/multimodal/multimodal_agent.js.map +1 -1
- package/dist/pipeline/agent_output.cjs +172 -0
- package/dist/pipeline/agent_output.cjs.map +1 -0
- package/dist/pipeline/agent_output.js +136 -138
- package/dist/pipeline/agent_output.js.map +1 -1
- package/dist/pipeline/agent_playout.cjs +169 -0
- package/dist/pipeline/agent_playout.cjs.map +1 -0
- package/dist/pipeline/agent_playout.js +126 -136
- package/dist/pipeline/agent_playout.js.map +1 -1
- package/dist/pipeline/human_input.cjs +158 -0
- package/dist/pipeline/human_input.cjs.map +1 -0
- package/dist/pipeline/human_input.js +124 -125
- package/dist/pipeline/human_input.js.map +1 -1
- package/dist/pipeline/index.cjs +31 -0
- package/dist/pipeline/index.cjs.map +1 -0
- package/dist/pipeline/index.js +8 -4
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/pipeline_agent.cjs +642 -0
- package/dist/pipeline/pipeline_agent.cjs.map +1 -0
- package/dist/pipeline/pipeline_agent.js +595 -651
- package/dist/pipeline/pipeline_agent.js.map +1 -1
- package/dist/pipeline/speech_handle.cjs +128 -0
- package/dist/pipeline/speech_handle.cjs.map +1 -0
- package/dist/pipeline/speech_handle.js +102 -100
- package/dist/pipeline/speech_handle.js.map +1 -1
- package/dist/plugin.cjs +46 -0
- package/dist/plugin.cjs.map +1 -0
- package/dist/plugin.js +20 -20
- package/dist/plugin.js.map +1 -1
- package/dist/stt/index.cjs +38 -0
- package/dist/stt/index.cjs.map +1 -0
- package/dist/stt/index.js +13 -5
- package/dist/stt/index.js.map +1 -1
- package/dist/stt/stream_adapter.cjs +87 -0
- package/dist/stt/stream_adapter.cjs.map +1 -0
- package/dist/stt/stream_adapter.js +58 -55
- package/dist/stt/stream_adapter.js.map +1 -1
- package/dist/stt/stt.cjs +98 -0
- package/dist/stt/stt.cjs.map +1 -0
- package/dist/stt/stt.js +63 -98
- package/dist/stt/stt.js.map +1 -1
- package/dist/tokenize/basic/basic.cjs +98 -0
- package/dist/tokenize/basic/basic.cjs.map +1 -0
- package/dist/tokenize/basic/basic.js +56 -45
- package/dist/tokenize/basic/basic.js.map +1 -1
- package/dist/tokenize/basic/hyphenator.cjs +425 -0
- package/dist/tokenize/basic/hyphenator.cjs.map +1 -0
- package/dist/tokenize/basic/hyphenator.js +66 -82
- package/dist/tokenize/basic/hyphenator.js.map +1 -1
- package/dist/tokenize/basic/index.cjs +35 -0
- package/dist/tokenize/basic/index.cjs.map +1 -0
- package/dist/tokenize/basic/index.js +7 -4
- package/dist/tokenize/basic/index.js.map +1 -1
- package/dist/tokenize/basic/paragraph.cjs +57 -0
- package/dist/tokenize/basic/paragraph.cjs.map +1 -0
- package/dist/tokenize/basic/paragraph.js +30 -35
- package/dist/tokenize/basic/paragraph.js.map +1 -1
- package/dist/tokenize/basic/sentence.cjs +83 -0
- package/dist/tokenize/basic/sentence.cjs.map +1 -0
- package/dist/tokenize/basic/sentence.js +56 -57
- package/dist/tokenize/basic/sentence.js.map +1 -1
- package/dist/tokenize/basic/word.cjs +44 -0
- package/dist/tokenize/basic/word.cjs.map +1 -0
- package/dist/tokenize/basic/word.js +17 -20
- package/dist/tokenize/basic/word.js.map +1 -1
- package/dist/tokenize/index.cjs +55 -0
- package/dist/tokenize/index.cjs.map +1 -0
- package/dist/tokenize/index.js +18 -7
- package/dist/tokenize/index.js.map +1 -1
- package/dist/tokenize/token_stream.cjs +164 -0
- package/dist/tokenize/token_stream.cjs.map +1 -0
- package/dist/tokenize/token_stream.js +133 -139
- package/dist/tokenize/token_stream.js.map +1 -1
- package/dist/tokenize/tokenizer.cjs +184 -0
- package/dist/tokenize/tokenizer.cjs.map +1 -0
- package/dist/tokenize/tokenizer.js +138 -99
- package/dist/tokenize/tokenizer.js.map +1 -1
- package/dist/transcription.cjs +131 -0
- package/dist/transcription.cjs.map +1 -0
- package/dist/transcription.js +99 -96
- package/dist/transcription.js.map +1 -1
- package/dist/tts/index.cjs +38 -0
- package/dist/tts/index.cjs.map +1 -0
- package/dist/tts/index.js +13 -5
- package/dist/tts/index.js.map +1 -1
- package/dist/tts/stream_adapter.cjs +78 -0
- package/dist/tts/stream_adapter.cjs.map +1 -0
- package/dist/tts/stream_adapter.js +50 -47
- package/dist/tts/stream_adapter.js.map +1 -1
- package/dist/tts/tts.cjs +127 -0
- package/dist/tts/tts.cjs.map +1 -0
- package/dist/tts/tts.js +90 -120
- package/dist/tts/tts.js.map +1 -1
- package/dist/utils.cjs +284 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.js +242 -247
- package/dist/utils.js.map +1 -1
- package/dist/vad.cjs +92 -0
- package/dist/vad.cjs.map +1 -0
- package/dist/vad.js +57 -52
- package/dist/vad.js.map +1 -1
- package/dist/version.cjs +29 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.js +4 -4
- package/dist/version.js.map +1 -1
- package/dist/worker.cjs +576 -0
- package/dist/worker.cjs.map +1 -0
- package/dist/worker.d.ts +1 -1
- package/dist/worker.js +511 -484
- package/dist/worker.js.map +1 -1
- package/package.json +18 -8
- package/src/ipc/job_main.ts +66 -64
- package/src/pipeline/pipeline_agent.ts +23 -23
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
3
|
+
|
|
4
|
+
SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
-->
|
|
6
|
+
# LiveKit Agents for Node.js
|
|
7
|
+
|
|
8
|
+
The Agents Framework is designed for building realtime, programmable
|
|
9
|
+
participants that run on servers. Use it to create conversational, multi-modal
|
|
10
|
+
voice agents that can see, hear, and understand.
|
|
11
|
+
|
|
12
|
+
This package contains the main LiveKit Agents SDK. Refer to the
|
|
13
|
+
[documentation](https://docs.livekit.io/agents/overview/) for information on how
|
|
14
|
+
to use it, or browse the [API
|
|
15
|
+
reference](https://docs.livekit.io/agents-js/modules/agents.html). See the
|
|
16
|
+
[repository](https://github.com/livekit/agents-js) for more information about
|
|
17
|
+
the framework as a whole.
|
package/dist/audio.cjs
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
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 audio_exports = {};
|
|
20
|
+
__export(audio_exports, {
|
|
21
|
+
AudioByteStream: () => AudioByteStream
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(audio_exports);
|
|
24
|
+
var import_rtc_node = require("@livekit/rtc-node");
|
|
25
|
+
var import_log = require("./log.cjs");
|
|
26
|
+
class AudioByteStream {
|
|
27
|
+
#sampleRate;
|
|
28
|
+
#numChannels;
|
|
29
|
+
#bytesPerFrame;
|
|
30
|
+
#buf;
|
|
31
|
+
#logger = (0, import_log.log)();
|
|
32
|
+
constructor(sampleRate, numChannels, samplesPerChannel = null) {
|
|
33
|
+
this.#sampleRate = sampleRate;
|
|
34
|
+
this.#numChannels = numChannels;
|
|
35
|
+
if (samplesPerChannel === null) {
|
|
36
|
+
samplesPerChannel = Math.floor(sampleRate / 50);
|
|
37
|
+
}
|
|
38
|
+
this.#bytesPerFrame = numChannels * samplesPerChannel * 2;
|
|
39
|
+
this.#buf = new Int8Array();
|
|
40
|
+
}
|
|
41
|
+
write(data) {
|
|
42
|
+
this.#buf = new Int8Array([...this.#buf, ...new Int8Array(data)]);
|
|
43
|
+
const frames = [];
|
|
44
|
+
while (this.#buf.length >= this.#bytesPerFrame) {
|
|
45
|
+
const frameData = this.#buf.slice(0, this.#bytesPerFrame);
|
|
46
|
+
this.#buf = this.#buf.slice(this.#bytesPerFrame);
|
|
47
|
+
frames.push(
|
|
48
|
+
new import_rtc_node.AudioFrame(
|
|
49
|
+
new Int16Array(frameData.buffer),
|
|
50
|
+
this.#sampleRate,
|
|
51
|
+
this.#numChannels,
|
|
52
|
+
frameData.length / 2
|
|
53
|
+
)
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
return frames;
|
|
57
|
+
}
|
|
58
|
+
flush() {
|
|
59
|
+
if (this.#buf.length % (2 * this.#numChannels) !== 0) {
|
|
60
|
+
this.#logger.warn("AudioByteStream: incomplete frame during flush, dropping");
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
return [
|
|
64
|
+
new import_rtc_node.AudioFrame(
|
|
65
|
+
new Int16Array(this.#buf.buffer),
|
|
66
|
+
this.#sampleRate,
|
|
67
|
+
this.#numChannels,
|
|
68
|
+
this.#buf.length / 2
|
|
69
|
+
)
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
AudioByteStream
|
|
76
|
+
});
|
|
77
|
+
//# sourceMappingURL=audio.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/audio.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { AudioFrame } from '@livekit/rtc-node';\nimport { log } from './log.js';\n\n/** AudioByteStream translates between LiveKit AudioFrame packets and raw byte data. */\nexport class AudioByteStream {\n #sampleRate: number;\n #numChannels: number;\n #bytesPerFrame: number;\n #buf: Int8Array;\n #logger = log();\n\n constructor(sampleRate: number, numChannels: number, samplesPerChannel: number | null = null) {\n this.#sampleRate = sampleRate;\n this.#numChannels = numChannels;\n\n if (samplesPerChannel === null) {\n samplesPerChannel = Math.floor(sampleRate / 50); // 20ms by default\n }\n\n this.#bytesPerFrame = numChannels * samplesPerChannel * 2; // 2 bytes per sample (Int16)\n this.#buf = new Int8Array();\n }\n\n write(data: ArrayBuffer): AudioFrame[] {\n this.#buf = new Int8Array([...this.#buf, ...new Int8Array(data)]);\n\n const frames: AudioFrame[] = [];\n while (this.#buf.length >= this.#bytesPerFrame) {\n const frameData = this.#buf.slice(0, this.#bytesPerFrame);\n this.#buf = this.#buf.slice(this.#bytesPerFrame);\n\n frames.push(\n new AudioFrame(\n new Int16Array(frameData.buffer),\n this.#sampleRate,\n this.#numChannels,\n frameData.length / 2,\n ),\n );\n }\n\n return frames;\n }\n\n flush(): AudioFrame[] {\n if (this.#buf.length % (2 * this.#numChannels) !== 0) {\n this.#logger.warn('AudioByteStream: incomplete frame during flush, dropping');\n return [];\n }\n\n return [\n new AudioFrame(\n new Int16Array(this.#buf.buffer),\n this.#sampleRate,\n this.#numChannels,\n this.#buf.length / 2,\n ),\n ];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAA2B;AAC3B,iBAAoB;AAGb,MAAM,gBAAgB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,cAAU,gBAAI;AAAA,EAEd,YAAY,YAAoB,aAAqB,oBAAmC,MAAM;AAC5F,SAAK,cAAc;AACnB,SAAK,eAAe;AAEpB,QAAI,sBAAsB,MAAM;AAC9B,0BAAoB,KAAK,MAAM,aAAa,EAAE;AAAA,IAChD;AAEA,SAAK,iBAAiB,cAAc,oBAAoB;AACxD,SAAK,OAAO,IAAI,UAAU;AAAA,EAC5B;AAAA,EAEA,MAAM,MAAiC;AACrC,SAAK,OAAO,IAAI,UAAU,CAAC,GAAG,KAAK,MAAM,GAAG,IAAI,UAAU,IAAI,CAAC,CAAC;AAEhE,UAAM,SAAuB,CAAC;AAC9B,WAAO,KAAK,KAAK,UAAU,KAAK,gBAAgB;AAC9C,YAAM,YAAY,KAAK,KAAK,MAAM,GAAG,KAAK,cAAc;AACxD,WAAK,OAAO,KAAK,KAAK,MAAM,KAAK,cAAc;AAE/C,aAAO;AAAA,QACL,IAAI;AAAA,UACF,IAAI,WAAW,UAAU,MAAM;AAAA,UAC/B,KAAK;AAAA,UACL,KAAK;AAAA,UACL,UAAU,SAAS;AAAA,QACrB;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,QAAsB;AACpB,QAAI,KAAK,KAAK,UAAU,IAAI,KAAK,kBAAkB,GAAG;AACpD,WAAK,QAAQ,KAAK,0DAA0D;AAC5E,aAAO,CAAC;AAAA,IACV;AAEA,WAAO;AAAA,MACL,IAAI;AAAA,QACF,IAAI,WAAW,KAAK,KAAK,MAAM;AAAA,QAC/B,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK,KAAK,SAAS;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/audio.js
CHANGED
|
@@ -1,42 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.#sampleRate = sampleRate;
|
|
15
|
-
this.#numChannels = numChannels;
|
|
16
|
-
if (samplesPerChannel === null) {
|
|
17
|
-
samplesPerChannel = Math.floor(sampleRate / 50); // 20ms by default
|
|
18
|
-
}
|
|
19
|
-
this.#bytesPerFrame = numChannels * samplesPerChannel * 2; // 2 bytes per sample (Int16)
|
|
20
|
-
this.#buf = new Int8Array();
|
|
1
|
+
import { AudioFrame } from "@livekit/rtc-node";
|
|
2
|
+
import { log } from "./log.js";
|
|
3
|
+
class AudioByteStream {
|
|
4
|
+
#sampleRate;
|
|
5
|
+
#numChannels;
|
|
6
|
+
#bytesPerFrame;
|
|
7
|
+
#buf;
|
|
8
|
+
#logger = log();
|
|
9
|
+
constructor(sampleRate, numChannels, samplesPerChannel = null) {
|
|
10
|
+
this.#sampleRate = sampleRate;
|
|
11
|
+
this.#numChannels = numChannels;
|
|
12
|
+
if (samplesPerChannel === null) {
|
|
13
|
+
samplesPerChannel = Math.floor(sampleRate / 50);
|
|
21
14
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
this.#bytesPerFrame = numChannels * samplesPerChannel * 2;
|
|
16
|
+
this.#buf = new Int8Array();
|
|
17
|
+
}
|
|
18
|
+
write(data) {
|
|
19
|
+
this.#buf = new Int8Array([...this.#buf, ...new Int8Array(data)]);
|
|
20
|
+
const frames = [];
|
|
21
|
+
while (this.#buf.length >= this.#bytesPerFrame) {
|
|
22
|
+
const frameData = this.#buf.slice(0, this.#bytesPerFrame);
|
|
23
|
+
this.#buf = this.#buf.slice(this.#bytesPerFrame);
|
|
24
|
+
frames.push(
|
|
25
|
+
new AudioFrame(
|
|
26
|
+
new Int16Array(frameData.buffer),
|
|
27
|
+
this.#sampleRate,
|
|
28
|
+
this.#numChannels,
|
|
29
|
+
frameData.length / 2
|
|
30
|
+
)
|
|
31
|
+
);
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
new AudioFrame(new Int16Array(this.#buf.buffer), this.#sampleRate, this.#numChannels, this.#buf.length / 2),
|
|
39
|
-
];
|
|
33
|
+
return frames;
|
|
34
|
+
}
|
|
35
|
+
flush() {
|
|
36
|
+
if (this.#buf.length % (2 * this.#numChannels) !== 0) {
|
|
37
|
+
this.#logger.warn("AudioByteStream: incomplete frame during flush, dropping");
|
|
38
|
+
return [];
|
|
40
39
|
}
|
|
40
|
+
return [
|
|
41
|
+
new AudioFrame(
|
|
42
|
+
new Int16Array(this.#buf.buffer),
|
|
43
|
+
this.#sampleRate,
|
|
44
|
+
this.#numChannels,
|
|
45
|
+
this.#buf.length / 2
|
|
46
|
+
)
|
|
47
|
+
];
|
|
48
|
+
}
|
|
41
49
|
}
|
|
50
|
+
export {
|
|
51
|
+
AudioByteStream
|
|
52
|
+
};
|
|
42
53
|
//# sourceMappingURL=audio.js.map
|
package/dist/audio.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/audio.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { AudioFrame } from '@livekit/rtc-node';\nimport { log } from './log.js';\n\n/** AudioByteStream translates between LiveKit AudioFrame packets and raw byte data. */\nexport class AudioByteStream {\n #sampleRate: number;\n #numChannels: number;\n #bytesPerFrame: number;\n #buf: Int8Array;\n #logger = log();\n\n constructor(sampleRate: number, numChannels: number, samplesPerChannel: number | null = null) {\n this.#sampleRate = sampleRate;\n this.#numChannels = numChannels;\n\n if (samplesPerChannel === null) {\n samplesPerChannel = Math.floor(sampleRate / 50); // 20ms by default\n }\n\n this.#bytesPerFrame = numChannels * samplesPerChannel * 2; // 2 bytes per sample (Int16)\n this.#buf = new Int8Array();\n }\n\n write(data: ArrayBuffer): AudioFrame[] {\n this.#buf = new Int8Array([...this.#buf, ...new Int8Array(data)]);\n\n const frames: AudioFrame[] = [];\n while (this.#buf.length >= this.#bytesPerFrame) {\n const frameData = this.#buf.slice(0, this.#bytesPerFrame);\n this.#buf = this.#buf.slice(this.#bytesPerFrame);\n\n frames.push(\n new AudioFrame(\n new Int16Array(frameData.buffer),\n this.#sampleRate,\n this.#numChannels,\n frameData.length / 2,\n ),\n );\n }\n\n return frames;\n }\n\n flush(): AudioFrame[] {\n if (this.#buf.length % (2 * this.#numChannels) !== 0) {\n this.#logger.warn('AudioByteStream: incomplete frame during flush, dropping');\n return [];\n }\n\n return [\n new AudioFrame(\n new Int16Array(this.#buf.buffer),\n this.#sampleRate,\n this.#numChannels,\n this.#buf.length / 2,\n ),\n ];\n }\n}\n"],"mappings":"AAGA,SAAS,kBAAkB;AAC3B,SAAS,WAAW;AAGb,MAAM,gBAAgB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU,IAAI;AAAA,EAEd,YAAY,YAAoB,aAAqB,oBAAmC,MAAM;AAC5F,SAAK,cAAc;AACnB,SAAK,eAAe;AAEpB,QAAI,sBAAsB,MAAM;AAC9B,0BAAoB,KAAK,MAAM,aAAa,EAAE;AAAA,IAChD;AAEA,SAAK,iBAAiB,cAAc,oBAAoB;AACxD,SAAK,OAAO,IAAI,UAAU;AAAA,EAC5B;AAAA,EAEA,MAAM,MAAiC;AACrC,SAAK,OAAO,IAAI,UAAU,CAAC,GAAG,KAAK,MAAM,GAAG,IAAI,UAAU,IAAI,CAAC,CAAC;AAEhE,UAAM,SAAuB,CAAC;AAC9B,WAAO,KAAK,KAAK,UAAU,KAAK,gBAAgB;AAC9C,YAAM,YAAY,KAAK,KAAK,MAAM,GAAG,KAAK,cAAc;AACxD,WAAK,OAAO,KAAK,KAAK,MAAM,KAAK,cAAc;AAE/C,aAAO;AAAA,QACL,IAAI;AAAA,UACF,IAAI,WAAW,UAAU,MAAM;AAAA,UAC/B,KAAK;AAAA,UACL,KAAK;AAAA,UACL,UAAU,SAAS;AAAA,QACrB;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,QAAsB;AACpB,QAAI,KAAK,KAAK,UAAU,IAAI,KAAK,kBAAkB,GAAG;AACpD,WAAK,QAAQ,KAAK,0DAA0D;AAC5E,aAAO,CAAC;AAAA,IACV;AAEA,WAAO;AAAA,MACL,IAAI;AAAA,QACF,IAAI,WAAW,KAAK,KAAK,MAAM;AAAA,QAC/B,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK,KAAK,SAAS;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
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 cli_exports = {};
|
|
20
|
+
__export(cli_exports, {
|
|
21
|
+
runApp: () => runApp
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(cli_exports);
|
|
24
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
25
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
26
|
+
var import_commander = require("commander");
|
|
27
|
+
var import_log = require("./log.cjs");
|
|
28
|
+
var import_version = require("./version.cjs");
|
|
29
|
+
var import_worker = require("./worker.cjs");
|
|
30
|
+
const runWorker = async (args) => {
|
|
31
|
+
(0, import_log.initializeLogger)({ pretty: !args.production, level: args.opts.logLevel });
|
|
32
|
+
const logger = (0, import_log.log)();
|
|
33
|
+
const { production: _, ...opts } = args.opts;
|
|
34
|
+
const worker = new import_worker.Worker(new import_worker.WorkerOptions({ production: args.production, ...opts }));
|
|
35
|
+
if (args.room) {
|
|
36
|
+
worker.event.once("worker_registered", () => {
|
|
37
|
+
logger.info(`connecting to room ${args.room}`);
|
|
38
|
+
worker.simulateJob(args.room, args.participantIdentity);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
process.once("SIGINT", async () => {
|
|
42
|
+
process.once("SIGINT", () => {
|
|
43
|
+
logger.info("worker closed forcefully");
|
|
44
|
+
process.exit(130);
|
|
45
|
+
});
|
|
46
|
+
if (args.production) {
|
|
47
|
+
await worker.drain();
|
|
48
|
+
}
|
|
49
|
+
await worker.close();
|
|
50
|
+
logger.info("worker closed");
|
|
51
|
+
process.exit(130);
|
|
52
|
+
});
|
|
53
|
+
try {
|
|
54
|
+
await worker.run();
|
|
55
|
+
} catch {
|
|
56
|
+
logger.fatal("worker failed");
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const runApp = (opts) => {
|
|
61
|
+
const program = new import_commander.Command().name("agents").description("LiveKit Agents CLI").version(import_version.version).addOption(
|
|
62
|
+
new import_commander.Option("--log-level <level>", "Set the logging level").choices(["trace", "debug", "info", "warn", "error", "fatal"]).default("info").env("LOG_LEVEL")
|
|
63
|
+
).addOption(
|
|
64
|
+
new import_commander.Option("--url <string>", "LiveKit server or Cloud project websocket URL").env(
|
|
65
|
+
"LIVEKIT_URL"
|
|
66
|
+
)
|
|
67
|
+
).addOption(
|
|
68
|
+
new import_commander.Option("--api-key <string>", "LiveKit server or Cloud project's API key").env(
|
|
69
|
+
"LIVEKIT_API_KEY"
|
|
70
|
+
)
|
|
71
|
+
).addOption(
|
|
72
|
+
new import_commander.Option("--api-secret <string>", "LiveKit server or Cloud project's API secret").env(
|
|
73
|
+
"LIVEKIT_API_SECRET"
|
|
74
|
+
)
|
|
75
|
+
).action(() => {
|
|
76
|
+
if (
|
|
77
|
+
// do not run CLI if origin file is agents/ipc/job_main.js
|
|
78
|
+
process.argv[1] !== new URL("ipc/job_main.js", importMetaUrl).pathname && process.argv.length < 3
|
|
79
|
+
) {
|
|
80
|
+
program.help();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
program.command("start").description("Start the worker in production mode").action(() => {
|
|
84
|
+
const options = program.optsWithGlobals();
|
|
85
|
+
opts.wsURL = options.url || opts.wsURL;
|
|
86
|
+
opts.apiKey = options.apiKey || opts.apiKey;
|
|
87
|
+
opts.apiSecret = options.apiSecret || opts.apiSecret;
|
|
88
|
+
opts.logLevel = options.logLevel || opts.logLevel;
|
|
89
|
+
runWorker({
|
|
90
|
+
opts,
|
|
91
|
+
production: true,
|
|
92
|
+
watch: false
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
program.command("dev").description("Start the worker in development mode").addOption(
|
|
96
|
+
new import_commander.Option("--log-level <level>", "Set the logging level").choices(["trace", "debug", "info", "warn", "error", "fatal"]).default("debug").env("LOG_LEVEL")
|
|
97
|
+
).action(() => {
|
|
98
|
+
const options = program.optsWithGlobals();
|
|
99
|
+
opts.wsURL = options.url || opts.wsURL;
|
|
100
|
+
opts.apiKey = options.apiKey || opts.apiKey;
|
|
101
|
+
opts.apiSecret = options.apiSecret || opts.apiSecret;
|
|
102
|
+
opts.logLevel = options.logLevel || opts.logLevel;
|
|
103
|
+
runWorker({
|
|
104
|
+
opts,
|
|
105
|
+
production: false,
|
|
106
|
+
watch: false
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
program.command("connect").description("Connect to a specific room").requiredOption("--room <string>", "Room name to connect to").option("--participant-identity <string>", "Identity of user to listen to").addOption(
|
|
110
|
+
new import_commander.Option("--log-level <level>", "Set the logging level").choices(["trace", "debug", "info", "warn", "error", "fatal"]).default("debug").env("LOG_LEVEL")
|
|
111
|
+
).action((...[, command]) => {
|
|
112
|
+
const options = command.optsWithGlobals();
|
|
113
|
+
opts.wsURL = options.url || opts.wsURL;
|
|
114
|
+
opts.apiKey = options.apiKey || opts.apiKey;
|
|
115
|
+
opts.apiSecret = options.apiSecret || opts.apiSecret;
|
|
116
|
+
opts.logLevel = options.logLevel || opts.logLevel;
|
|
117
|
+
runWorker({
|
|
118
|
+
opts,
|
|
119
|
+
production: false,
|
|
120
|
+
watch: false,
|
|
121
|
+
room: options.room,
|
|
122
|
+
participantIdentity: options.participantIdentity
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
program.parse();
|
|
126
|
+
};
|
|
127
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
128
|
+
0 && (module.exports = {
|
|
129
|
+
runApp
|
|
130
|
+
});
|
|
131
|
+
//# sourceMappingURL=cli.cjs.map
|
package/dist/cli.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts","../../node_modules/.pnpm/tsup@8.3.5_@microsoft+api-extractor@7.43.7_@types+node@22.5.5__postcss@8.4.38_tsx@4.19.2_typescript@5.4.5/node_modules/tsup/assets/cjs_shims.js"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { Command, Option } from 'commander';\nimport type { EventEmitter } from 'node:events';\nimport { initializeLogger, log } from './log.js';\nimport { version } from './version.js';\nimport { Worker, WorkerOptions } from './worker.js';\n\ntype CliArgs = {\n opts: WorkerOptions;\n production: boolean;\n watch: boolean;\n event?: EventEmitter;\n room?: string;\n participantIdentity?: string;\n};\n\nconst runWorker = async (args: CliArgs) => {\n initializeLogger({ pretty: !args.production, level: args.opts.logLevel });\n const logger = log();\n\n // though `production` is defined in WorkerOptions, it will always be overriddden by CLI.\n const { production: _, ...opts } = args.opts; // eslint-disable-line @typescript-eslint/no-unused-vars\n const worker = new Worker(new WorkerOptions({ production: args.production, ...opts }));\n\n if (args.room) {\n worker.event.once('worker_registered', () => {\n logger.info(`connecting to room ${args.room}`);\n worker.simulateJob(args.room!, args.participantIdentity);\n });\n }\n\n process.once('SIGINT', async () => {\n // allow C-c C-c for force interrupt\n process.once('SIGINT', () => {\n logger.info('worker closed forcefully');\n process.exit(130); // SIGINT exit code\n });\n if (args.production) {\n await worker.drain();\n }\n await worker.close();\n logger.info('worker closed');\n process.exit(130); // SIGINT exit code\n });\n\n try {\n await worker.run();\n } catch {\n logger.fatal('worker failed');\n process.exit(1);\n }\n};\n\n/**\n * Exposes a CLI for creating a new worker, in development or production mode.\n *\n * @param opts - Options to launch the worker with\n * @example\n * ```\n * if (process.argv[1] === fileURLToPath(import.meta.url)) {\n * cli.runApp(new WorkerOptions({ agent: import.meta.filename }));\n * }\n * ```\n */\nexport const runApp = (opts: WorkerOptions) => {\n const program = new Command()\n .name('agents')\n .description('LiveKit Agents CLI')\n .version(version)\n .addOption(\n new Option('--log-level <level>', 'Set the logging level')\n .choices(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])\n .default('info')\n .env('LOG_LEVEL'),\n )\n .addOption(\n new Option('--url <string>', 'LiveKit server or Cloud project websocket URL').env(\n 'LIVEKIT_URL',\n ),\n )\n .addOption(\n new Option('--api-key <string>', \"LiveKit server or Cloud project's API key\").env(\n 'LIVEKIT_API_KEY',\n ),\n )\n .addOption(\n new Option('--api-secret <string>', \"LiveKit server or Cloud project's API secret\").env(\n 'LIVEKIT_API_SECRET',\n ),\n )\n .action(() => {\n if (\n // do not run CLI if origin file is agents/ipc/job_main.js\n process.argv[1] !== new URL('ipc/job_main.js', import.meta.url).pathname &&\n process.argv.length < 3\n ) {\n program.help();\n }\n });\n\n program\n .command('start')\n .description('Start the worker in production mode')\n .action(() => {\n const options = program.optsWithGlobals();\n opts.wsURL = options.url || opts.wsURL;\n opts.apiKey = options.apiKey || opts.apiKey;\n opts.apiSecret = options.apiSecret || opts.apiSecret;\n opts.logLevel = options.logLevel || opts.logLevel;\n runWorker({\n opts,\n production: true,\n watch: false,\n });\n });\n\n program\n .command('dev')\n .description('Start the worker in development mode')\n .addOption(\n new Option('--log-level <level>', 'Set the logging level')\n .choices(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])\n .default('debug')\n .env('LOG_LEVEL'),\n )\n .action(() => {\n const options = program.optsWithGlobals();\n opts.wsURL = options.url || opts.wsURL;\n opts.apiKey = options.apiKey || opts.apiKey;\n opts.apiSecret = options.apiSecret || opts.apiSecret;\n opts.logLevel = options.logLevel || opts.logLevel;\n runWorker({\n opts,\n production: false,\n watch: false,\n });\n });\n\n program\n .command('connect')\n .description('Connect to a specific room')\n .requiredOption('--room <string>', 'Room name to connect to')\n .option('--participant-identity <string>', 'Identity of user to listen to')\n .addOption(\n new Option('--log-level <level>', 'Set the logging level')\n .choices(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])\n .default('debug')\n .env('LOG_LEVEL'),\n )\n .action((...[, command]) => {\n const options = command.optsWithGlobals();\n opts.wsURL = options.url || opts.wsURL;\n opts.apiKey = options.apiKey || opts.apiKey;\n opts.apiSecret = options.apiSecret || opts.apiSecret;\n opts.logLevel = options.logLevel || opts.logLevel;\n runWorker({\n opts,\n production: false,\n watch: false,\n room: options.room,\n participantIdentity: options.participantIdentity,\n });\n });\n\n program.parse();\n};\n","// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () =>\n typeof document === 'undefined'\n ? new URL(`file:${__filename}`).href\n : (document.currentScript && document.currentScript.src) ||\n new URL('main.js', document.baseURI).href\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n"],"mappings":"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","names":[]}
|
package/dist/cli.js
CHANGED
|
@@ -1,131 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import { initializeLogger, log } from './log.js';
|
|
6
|
-
import { version } from './version.js';
|
|
7
|
-
import { Worker, WorkerOptions } from './worker.js';
|
|
1
|
+
import { Command, Option } from "commander";
|
|
2
|
+
import { initializeLogger, log } from "./log.js";
|
|
3
|
+
import { version } from "./version.js";
|
|
4
|
+
import { Worker, WorkerOptions } from "./worker.js";
|
|
8
5
|
const runWorker = async (args) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
worker.simulateJob(args.room, args.participantIdentity);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
process.once('SIGINT', async () => {
|
|
21
|
-
// allow C-c C-c for force interrupt
|
|
22
|
-
process.once('SIGINT', () => {
|
|
23
|
-
logger.info('worker closed forcefully');
|
|
24
|
-
process.exit(130); // SIGINT exit code
|
|
25
|
-
});
|
|
26
|
-
if (args.production) {
|
|
27
|
-
await worker.drain();
|
|
28
|
-
}
|
|
29
|
-
await worker.close();
|
|
30
|
-
logger.info('worker closed');
|
|
31
|
-
process.exit(130); // SIGINT exit code
|
|
6
|
+
initializeLogger({ pretty: !args.production, level: args.opts.logLevel });
|
|
7
|
+
const logger = log();
|
|
8
|
+
const { production: _, ...opts } = args.opts;
|
|
9
|
+
const worker = new Worker(new WorkerOptions({ production: args.production, ...opts }));
|
|
10
|
+
if (args.room) {
|
|
11
|
+
worker.event.once("worker_registered", () => {
|
|
12
|
+
logger.info(`connecting to room ${args.room}`);
|
|
13
|
+
worker.simulateJob(args.room, args.participantIdentity);
|
|
32
14
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
15
|
+
}
|
|
16
|
+
process.once("SIGINT", async () => {
|
|
17
|
+
process.once("SIGINT", () => {
|
|
18
|
+
logger.info("worker closed forcefully");
|
|
19
|
+
process.exit(130);
|
|
20
|
+
});
|
|
21
|
+
if (args.production) {
|
|
22
|
+
await worker.drain();
|
|
39
23
|
}
|
|
24
|
+
await worker.close();
|
|
25
|
+
logger.info("worker closed");
|
|
26
|
+
process.exit(130);
|
|
27
|
+
});
|
|
28
|
+
try {
|
|
29
|
+
await worker.run();
|
|
30
|
+
} catch {
|
|
31
|
+
logger.fatal("worker failed");
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
40
34
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
.description('Start the worker in production mode')
|
|
75
|
-
.action(() => {
|
|
76
|
-
const options = program.optsWithGlobals();
|
|
77
|
-
opts.wsURL = options.url || opts.wsURL;
|
|
78
|
-
opts.apiKey = options.apiKey || opts.apiKey;
|
|
79
|
-
opts.apiSecret = options.apiSecret || opts.apiSecret;
|
|
80
|
-
opts.logLevel = options.logLevel || opts.logLevel;
|
|
81
|
-
runWorker({
|
|
82
|
-
opts,
|
|
83
|
-
production: true,
|
|
84
|
-
watch: false,
|
|
85
|
-
});
|
|
35
|
+
const runApp = (opts) => {
|
|
36
|
+
const program = new Command().name("agents").description("LiveKit Agents CLI").version(version).addOption(
|
|
37
|
+
new Option("--log-level <level>", "Set the logging level").choices(["trace", "debug", "info", "warn", "error", "fatal"]).default("info").env("LOG_LEVEL")
|
|
38
|
+
).addOption(
|
|
39
|
+
new Option("--url <string>", "LiveKit server or Cloud project websocket URL").env(
|
|
40
|
+
"LIVEKIT_URL"
|
|
41
|
+
)
|
|
42
|
+
).addOption(
|
|
43
|
+
new Option("--api-key <string>", "LiveKit server or Cloud project's API key").env(
|
|
44
|
+
"LIVEKIT_API_KEY"
|
|
45
|
+
)
|
|
46
|
+
).addOption(
|
|
47
|
+
new Option("--api-secret <string>", "LiveKit server or Cloud project's API secret").env(
|
|
48
|
+
"LIVEKIT_API_SECRET"
|
|
49
|
+
)
|
|
50
|
+
).action(() => {
|
|
51
|
+
if (
|
|
52
|
+
// do not run CLI if origin file is agents/ipc/job_main.js
|
|
53
|
+
process.argv[1] !== new URL("ipc/job_main.js", import.meta.url).pathname && process.argv.length < 3
|
|
54
|
+
) {
|
|
55
|
+
program.help();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
program.command("start").description("Start the worker in production mode").action(() => {
|
|
59
|
+
const options = program.optsWithGlobals();
|
|
60
|
+
opts.wsURL = options.url || opts.wsURL;
|
|
61
|
+
opts.apiKey = options.apiKey || opts.apiKey;
|
|
62
|
+
opts.apiSecret = options.apiSecret || opts.apiSecret;
|
|
63
|
+
opts.logLevel = options.logLevel || opts.logLevel;
|
|
64
|
+
runWorker({
|
|
65
|
+
opts,
|
|
66
|
+
production: true,
|
|
67
|
+
watch: false
|
|
86
68
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
runWorker({
|
|
101
|
-
opts,
|
|
102
|
-
production: false,
|
|
103
|
-
watch: false,
|
|
104
|
-
});
|
|
69
|
+
});
|
|
70
|
+
program.command("dev").description("Start the worker in development mode").addOption(
|
|
71
|
+
new Option("--log-level <level>", "Set the logging level").choices(["trace", "debug", "info", "warn", "error", "fatal"]).default("debug").env("LOG_LEVEL")
|
|
72
|
+
).action(() => {
|
|
73
|
+
const options = program.optsWithGlobals();
|
|
74
|
+
opts.wsURL = options.url || opts.wsURL;
|
|
75
|
+
opts.apiKey = options.apiKey || opts.apiKey;
|
|
76
|
+
opts.apiSecret = options.apiSecret || opts.apiSecret;
|
|
77
|
+
opts.logLevel = options.logLevel || opts.logLevel;
|
|
78
|
+
runWorker({
|
|
79
|
+
opts,
|
|
80
|
+
production: false,
|
|
81
|
+
watch: false
|
|
105
82
|
});
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
runWorker({
|
|
122
|
-
opts,
|
|
123
|
-
production: false,
|
|
124
|
-
watch: false,
|
|
125
|
-
room: options.room,
|
|
126
|
-
participantIdentity: options.participantIdentity,
|
|
127
|
-
});
|
|
83
|
+
});
|
|
84
|
+
program.command("connect").description("Connect to a specific room").requiredOption("--room <string>", "Room name to connect to").option("--participant-identity <string>", "Identity of user to listen to").addOption(
|
|
85
|
+
new Option("--log-level <level>", "Set the logging level").choices(["trace", "debug", "info", "warn", "error", "fatal"]).default("debug").env("LOG_LEVEL")
|
|
86
|
+
).action((...[, command]) => {
|
|
87
|
+
const options = command.optsWithGlobals();
|
|
88
|
+
opts.wsURL = options.url || opts.wsURL;
|
|
89
|
+
opts.apiKey = options.apiKey || opts.apiKey;
|
|
90
|
+
opts.apiSecret = options.apiSecret || opts.apiSecret;
|
|
91
|
+
opts.logLevel = options.logLevel || opts.logLevel;
|
|
92
|
+
runWorker({
|
|
93
|
+
opts,
|
|
94
|
+
production: false,
|
|
95
|
+
watch: false,
|
|
96
|
+
room: options.room,
|
|
97
|
+
participantIdentity: options.participantIdentity
|
|
128
98
|
});
|
|
129
|
-
|
|
99
|
+
});
|
|
100
|
+
program.parse();
|
|
101
|
+
};
|
|
102
|
+
export {
|
|
103
|
+
runApp
|
|
130
104
|
};
|
|
131
105
|
//# sourceMappingURL=cli.js.map
|