@livekit/agents 0.4.6 → 0.5.1
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.d.ts +6 -1
- package/dist/job.d.ts.map +1 -1
- 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.d.ts +1 -1
- package/dist/tokenize/basic/basic.d.ts.map +1 -1
- 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 +89 -0
- package/dist/tokenize/basic/sentence.cjs.map +1 -0
- package/dist/tokenize/basic/sentence.d.ts.map +1 -1
- package/dist/tokenize/basic/sentence.js +62 -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/tokenize/tokenizer.test.cjs +220 -0
- package/dist/tokenize/tokenizer.test.cjs.map +1 -0
- package/dist/tokenize/tokenizer.test.d.ts +2 -0
- package/dist/tokenize/tokenizer.test.d.ts.map +1 -0
- package/dist/tokenize/tokenizer.test.js +219 -0
- package/dist/tokenize/tokenizer.test.js.map +1 -0
- 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 +577 -0
- package/dist/worker.cjs.map +1 -0
- package/dist/worker.d.ts +1 -1
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +512 -484
- package/dist/worker.js.map +1 -1
- package/package.json +18 -8
- package/src/ipc/job_main.ts +66 -64
- package/src/job.ts +3 -2
- package/src/pipeline/pipeline_agent.ts +23 -23
- package/src/tokenize/basic/basic.ts +1 -1
- package/src/tokenize/basic/sentence.ts +14 -8
- package/src/tokenize/tokenizer.test.ts +255 -0
- package/src/worker.ts +1 -0
package/dist/ipc/proc_pool.js
CHANGED
|
@@ -1,105 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.agent = agent;
|
|
22
|
-
if (numIdleProcesses > 0) {
|
|
23
|
-
this.procMutex = new MultiMutex(numIdleProcesses);
|
|
24
|
-
}
|
|
25
|
-
this.initializeTimeout = initializeTimeout;
|
|
26
|
-
this.closeTimeout = closeTimeout;
|
|
27
|
-
}
|
|
28
|
-
get processes() {
|
|
29
|
-
return this.executors;
|
|
1
|
+
import { MultiMutex, Mutex } from "@livekit/mutex";
|
|
2
|
+
import { Queue } from "../utils.js";
|
|
3
|
+
import { ProcJobExecutor } from "./proc_job_executor.js";
|
|
4
|
+
class ProcPool {
|
|
5
|
+
agent;
|
|
6
|
+
initializeTimeout;
|
|
7
|
+
closeTimeout;
|
|
8
|
+
executors = [];
|
|
9
|
+
tasks = [];
|
|
10
|
+
started = false;
|
|
11
|
+
closed = false;
|
|
12
|
+
controller = new AbortController();
|
|
13
|
+
initMutex = new Mutex();
|
|
14
|
+
procMutex;
|
|
15
|
+
procUnlock;
|
|
16
|
+
warmedProcQueue = new Queue();
|
|
17
|
+
constructor(agent, numIdleProcesses, initializeTimeout, closeTimeout) {
|
|
18
|
+
this.agent = agent;
|
|
19
|
+
if (numIdleProcesses > 0) {
|
|
20
|
+
this.procMutex = new MultiMutex(numIdleProcesses);
|
|
30
21
|
}
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
this.initializeTimeout = initializeTimeout;
|
|
23
|
+
this.closeTimeout = closeTimeout;
|
|
24
|
+
}
|
|
25
|
+
get processes() {
|
|
26
|
+
return this.executors;
|
|
27
|
+
}
|
|
28
|
+
getByJobId(id) {
|
|
29
|
+
return this.executors.find((x) => x.runningJob && x.runningJob.job.id === id) || null;
|
|
30
|
+
}
|
|
31
|
+
async launchJob(info) {
|
|
32
|
+
let proc;
|
|
33
|
+
if (this.procMutex) {
|
|
34
|
+
proc = await this.warmedProcQueue.get();
|
|
35
|
+
if (this.procUnlock) {
|
|
36
|
+
this.procUnlock();
|
|
37
|
+
this.procUnlock = void 0;
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
proc = new ProcJobExecutor(this.agent, this.initializeTimeout, this.closeTimeout);
|
|
41
|
+
this.executors.push(proc);
|
|
42
|
+
await proc.start();
|
|
43
|
+
await proc.initialize();
|
|
33
44
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
await proc.launchJob(info);
|
|
46
|
+
}
|
|
47
|
+
async procWatchTask() {
|
|
48
|
+
const proc = new ProcJobExecutor(this.agent, this.initializeTimeout, this.closeTimeout);
|
|
49
|
+
try {
|
|
50
|
+
this.executors.push(proc);
|
|
51
|
+
const unlock = await this.initMutex.lock();
|
|
52
|
+
if (this.closed) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
await proc.start();
|
|
56
|
+
try {
|
|
57
|
+
await proc.initialize();
|
|
58
|
+
await this.warmedProcQueue.put(proc);
|
|
59
|
+
} catch {
|
|
60
|
+
if (this.procUnlock) {
|
|
61
|
+
this.procUnlock();
|
|
62
|
+
this.procUnlock = void 0;
|
|
48
63
|
}
|
|
49
|
-
|
|
64
|
+
}
|
|
65
|
+
unlock();
|
|
66
|
+
await proc.join();
|
|
67
|
+
} finally {
|
|
68
|
+
this.executors.splice(this.executors.indexOf(proc));
|
|
50
69
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const unlock = await this.initMutex.lock();
|
|
56
|
-
if (this.closed) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
await proc.start();
|
|
60
|
-
try {
|
|
61
|
-
await proc.initialize();
|
|
62
|
-
await this.warmedProcQueue.put(proc);
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
65
|
-
if (this.procUnlock) {
|
|
66
|
-
this.procUnlock();
|
|
67
|
-
this.procUnlock = undefined;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
unlock();
|
|
71
|
-
await proc.join();
|
|
72
|
-
}
|
|
73
|
-
finally {
|
|
74
|
-
this.executors.splice(this.executors.indexOf(proc));
|
|
75
|
-
}
|
|
70
|
+
}
|
|
71
|
+
start() {
|
|
72
|
+
if (this.started) {
|
|
73
|
+
return;
|
|
76
74
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const task = this.procWatchTask();
|
|
89
|
-
this.tasks.push(task);
|
|
90
|
-
task.finally(() => this.tasks.splice(this.tasks.indexOf(task)));
|
|
91
|
-
}
|
|
92
|
-
}
|
|
75
|
+
this.started = true;
|
|
76
|
+
this.run(this.controller.signal);
|
|
77
|
+
}
|
|
78
|
+
async run(signal) {
|
|
79
|
+
if (this.procMutex) {
|
|
80
|
+
while (!signal.aborted) {
|
|
81
|
+
this.procUnlock = await this.procMutex.lock();
|
|
82
|
+
const task = this.procWatchTask();
|
|
83
|
+
this.tasks.push(task);
|
|
84
|
+
task.finally(() => this.tasks.splice(this.tasks.indexOf(task)));
|
|
85
|
+
}
|
|
93
86
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
this.closed = true;
|
|
99
|
-
this.controller.abort();
|
|
100
|
-
this.warmedProcQueue.items.forEach((e) => e.close());
|
|
101
|
-
this.executors.forEach((e) => e.close());
|
|
102
|
-
await Promise.allSettled(this.tasks);
|
|
87
|
+
}
|
|
88
|
+
async close() {
|
|
89
|
+
if (!this.started) {
|
|
90
|
+
return;
|
|
103
91
|
}
|
|
92
|
+
this.closed = true;
|
|
93
|
+
this.controller.abort();
|
|
94
|
+
this.warmedProcQueue.items.forEach((e) => e.close());
|
|
95
|
+
this.executors.forEach((e) => e.close());
|
|
96
|
+
await Promise.allSettled(this.tasks);
|
|
97
|
+
}
|
|
104
98
|
}
|
|
99
|
+
export {
|
|
100
|
+
ProcPool
|
|
101
|
+
};
|
|
105
102
|
//# sourceMappingURL=proc_pool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/ipc/proc_pool.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { MultiMutex, Mutex } from '@livekit/mutex';\nimport type { RunningJobInfo } from '../job.js';\nimport { Queue } from '../utils.js';\nimport type { JobExecutor } from './job_executor.js';\nimport { ProcJobExecutor } from './proc_job_executor.js';\n\nexport class ProcPool {\n agent: string;\n initializeTimeout: number;\n closeTimeout: number;\n executors: JobExecutor[] = [];\n tasks: Promise<void>[] = [];\n started = false;\n closed = false;\n controller = new AbortController();\n initMutex = new Mutex();\n procMutex?: MultiMutex;\n procUnlock?: () => void;\n warmedProcQueue = new Queue<JobExecutor>();\n\n constructor(\n agent: string,\n numIdleProcesses: number,\n initializeTimeout: number,\n closeTimeout: number,\n ) {\n this.agent = agent;\n if (numIdleProcesses > 0) {\n this.procMutex = new MultiMutex(numIdleProcesses);\n }\n this.initializeTimeout = initializeTimeout;\n this.closeTimeout = closeTimeout;\n }\n\n get processes(): JobExecutor[] {\n return this.executors;\n }\n\n getByJobId(id: string): JobExecutor | null {\n return this.executors.find((x) => x.runningJob && x.runningJob.job.id === id) || null;\n }\n\n async launchJob(info: RunningJobInfo) {\n let proc: JobExecutor;\n if (this.procMutex) {\n proc = await this.warmedProcQueue.get();\n if (this.procUnlock) {\n this.procUnlock();\n this.procUnlock = undefined;\n }\n } else {\n proc = new ProcJobExecutor(this.agent, this.initializeTimeout, this.closeTimeout);\n this.executors.push(proc);\n await proc.start();\n await proc.initialize();\n }\n await proc.launchJob(info);\n }\n\n async procWatchTask() {\n const proc = new ProcJobExecutor(this.agent, this.initializeTimeout, this.closeTimeout);\n\n try {\n this.executors.push(proc);\n\n const unlock = await this.initMutex.lock();\n if (this.closed) {\n return;\n }\n\n await proc.start();\n try {\n await proc.initialize();\n await this.warmedProcQueue.put(proc);\n } catch {\n if (this.procUnlock) {\n this.procUnlock();\n this.procUnlock = undefined;\n }\n }\n\n unlock();\n await proc.join();\n } finally {\n this.executors.splice(this.executors.indexOf(proc));\n }\n }\n\n start() {\n if (this.started) {\n return;\n }\n\n this.started = true;\n this.run(this.controller.signal);\n }\n\n async run(signal: AbortSignal) {\n if (this.procMutex) {\n while (!signal.aborted) {\n this.procUnlock = await this.procMutex.lock();\n const task = this.procWatchTask();\n this.tasks.push(task);\n task.finally(() => this.tasks.splice(this.tasks.indexOf(task)));\n }\n }\n }\n\n async close() {\n if (!this.started) {\n return;\n }\n this.closed = true;\n this.controller.abort();\n this.warmedProcQueue.items.forEach((e) => e.close());\n this.executors.forEach((e) => e.close());\n await Promise.allSettled(this.tasks);\n }\n}\n"],"mappings":"AAGA,SAAS,YAAY,aAAa;AAElC,SAAS,aAAa;AAEtB,SAAS,uBAAuB;AAEzB,MAAM,SAAS;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAA2B,CAAC;AAAA,EAC5B,QAAyB,CAAC;AAAA,EAC1B,UAAU;AAAA,EACV,SAAS;AAAA,EACT,aAAa,IAAI,gBAAgB;AAAA,EACjC,YAAY,IAAI,MAAM;AAAA,EACtB;AAAA,EACA;AAAA,EACA,kBAAkB,IAAI,MAAmB;AAAA,EAEzC,YACE,OACA,kBACA,mBACA,cACA;AACA,SAAK,QAAQ;AACb,QAAI,mBAAmB,GAAG;AACxB,WAAK,YAAY,IAAI,WAAW,gBAAgB;AAAA,IAClD;AACA,SAAK,oBAAoB;AACzB,SAAK,eAAe;AAAA,EACtB;AAAA,EAEA,IAAI,YAA2B;AAC7B,WAAO,KAAK;AAAA,EAC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B,QAAI,KAAK,WAAW;AAClB,aAAO,CAAC,OAAO,SAAS;AACtB,aAAK,aAAa,MAAM,KAAK,UAAU,KAAK;AAC5C,cAAM,OAAO,KAAK,cAAc;AAChC,aAAK,MAAM,KAAK,IAAI;AACpB,aAAK,QAAQ,MAAM,KAAK,MAAM,OAAO,KAAK,MAAM,QAAQ,IAAI,CAAC,CAAC;AAAA,MAChE;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,QAAQ;AACZ,QAAI,CAAC,KAAK,SAAS;AACjB;AAAA,IACF;AACA,SAAK,SAAS;AACd,SAAK,WAAW,MAAM;AACtB,SAAK,gBAAgB,MAAM,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;AACnD,SAAK,UAAU,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;AACvC,UAAM,QAAQ,WAAW,KAAK,KAAK;AAAA,EACrC;AACF;","names":[]}
|
package/dist/job.cjs
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
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 job_exports = {};
|
|
20
|
+
__export(job_exports, {
|
|
21
|
+
AutoSubscribe: () => AutoSubscribe,
|
|
22
|
+
FunctionExistsError: () => FunctionExistsError,
|
|
23
|
+
JobContext: () => JobContext,
|
|
24
|
+
JobProcess: () => JobProcess,
|
|
25
|
+
JobRequest: () => JobRequest
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(job_exports);
|
|
28
|
+
var import_rtc_node = require("@livekit/rtc-node");
|
|
29
|
+
var import_log = require("./log.cjs");
|
|
30
|
+
var AutoSubscribe = /* @__PURE__ */ ((AutoSubscribe2) => {
|
|
31
|
+
AutoSubscribe2[AutoSubscribe2["SUBSCRIBE_ALL"] = 0] = "SUBSCRIBE_ALL";
|
|
32
|
+
AutoSubscribe2[AutoSubscribe2["SUBSCRIBE_NONE"] = 1] = "SUBSCRIBE_NONE";
|
|
33
|
+
AutoSubscribe2[AutoSubscribe2["VIDEO_ONLY"] = 2] = "VIDEO_ONLY";
|
|
34
|
+
AutoSubscribe2[AutoSubscribe2["AUDIO_ONLY"] = 3] = "AUDIO_ONLY";
|
|
35
|
+
return AutoSubscribe2;
|
|
36
|
+
})(AutoSubscribe || {});
|
|
37
|
+
class FunctionExistsError extends Error {
|
|
38
|
+
constructor(msg) {
|
|
39
|
+
super(msg);
|
|
40
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
class JobContext {
|
|
44
|
+
#proc;
|
|
45
|
+
#info;
|
|
46
|
+
#room;
|
|
47
|
+
#onConnect;
|
|
48
|
+
#onShutdown;
|
|
49
|
+
/** @internal */
|
|
50
|
+
shutdownCallbacks = [];
|
|
51
|
+
#participantEntrypoints = [];
|
|
52
|
+
#participantTasks = {};
|
|
53
|
+
#logger;
|
|
54
|
+
constructor(proc, info, room, onConnect, onShutdown) {
|
|
55
|
+
this.#proc = proc;
|
|
56
|
+
this.#info = info;
|
|
57
|
+
this.#room = room;
|
|
58
|
+
this.#onConnect = onConnect;
|
|
59
|
+
this.#onShutdown = onShutdown;
|
|
60
|
+
this.onParticipantConnected = this.onParticipantConnected.bind(this);
|
|
61
|
+
this.#room.on(import_rtc_node.RoomEvent.ParticipantConnected, this.onParticipantConnected);
|
|
62
|
+
this.#logger = (0, import_log.log)().child({ info: this.#info });
|
|
63
|
+
}
|
|
64
|
+
get proc() {
|
|
65
|
+
return this.#proc;
|
|
66
|
+
}
|
|
67
|
+
get job() {
|
|
68
|
+
return this.#info.job;
|
|
69
|
+
}
|
|
70
|
+
/** @returns The room the agent was called into */
|
|
71
|
+
get room() {
|
|
72
|
+
return this.#room;
|
|
73
|
+
}
|
|
74
|
+
/** @returns The agent's participant if connected to the room, otherwise `undefined` */
|
|
75
|
+
get agent() {
|
|
76
|
+
return this.#room.localParticipant;
|
|
77
|
+
}
|
|
78
|
+
/** Adds a promise to be awaited when {@link JobContext.shutdown | shutdown} is called. */
|
|
79
|
+
addShutdownCallback(callback) {
|
|
80
|
+
this.shutdownCallbacks.push(callback);
|
|
81
|
+
}
|
|
82
|
+
async waitForParticipant(identity) {
|
|
83
|
+
if (!this.#room.isConnected) {
|
|
84
|
+
throw new Error("room is not connected");
|
|
85
|
+
}
|
|
86
|
+
for (const p of this.#room.remoteParticipants.values()) {
|
|
87
|
+
if ((!identity || p.identity === identity) && p.info.kind != import_rtc_node.ParticipantKind.AGENT) {
|
|
88
|
+
return p;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return new Promise((resolve, reject) => {
|
|
92
|
+
const onParticipantConnected = (participant) => {
|
|
93
|
+
if ((!identity || participant.identity === identity) && participant.info.kind != import_rtc_node.ParticipantKind.AGENT) {
|
|
94
|
+
clearHandlers();
|
|
95
|
+
resolve(participant);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const onDisconnected = () => {
|
|
99
|
+
clearHandlers();
|
|
100
|
+
reject(new Error("Room disconnected while waiting for participant"));
|
|
101
|
+
};
|
|
102
|
+
const clearHandlers = () => {
|
|
103
|
+
this.#room.off(import_rtc_node.RoomEvent.ParticipantConnected, onParticipantConnected);
|
|
104
|
+
this.#room.off(import_rtc_node.RoomEvent.Disconnected, onDisconnected);
|
|
105
|
+
};
|
|
106
|
+
this.#room.on(import_rtc_node.RoomEvent.ParticipantConnected, onParticipantConnected);
|
|
107
|
+
this.#room.on(import_rtc_node.RoomEvent.Disconnected, onDisconnected);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Connects the agent to the room.
|
|
112
|
+
*
|
|
113
|
+
* @remarks
|
|
114
|
+
* It is recommended to run this command as early in the function as possible, as executing it
|
|
115
|
+
* later may cause noticeable delay between user and agent joins.
|
|
116
|
+
*
|
|
117
|
+
* @see {@link https://github.com/livekit/node-sdks/tree/main/packages/livekit-rtc#readme |
|
|
118
|
+
* @livekit/rtc-node} for more information about the parameters.
|
|
119
|
+
*/
|
|
120
|
+
async connect(e2ee, autoSubscribe = 0 /* SUBSCRIBE_ALL */, rtcConfig) {
|
|
121
|
+
const opts = {
|
|
122
|
+
e2ee,
|
|
123
|
+
autoSubscribe: autoSubscribe == 0 /* SUBSCRIBE_ALL */,
|
|
124
|
+
rtcConfig,
|
|
125
|
+
dynacast: false
|
|
126
|
+
};
|
|
127
|
+
await this.#room.connect(this.#info.url, this.#info.token, opts);
|
|
128
|
+
this.#onConnect();
|
|
129
|
+
this.#room.remoteParticipants.forEach(this.onParticipantConnected);
|
|
130
|
+
if ([3 /* AUDIO_ONLY */, 2 /* VIDEO_ONLY */].includes(autoSubscribe)) {
|
|
131
|
+
this.#room.remoteParticipants.forEach((p) => {
|
|
132
|
+
p.trackPublications.forEach((pub) => {
|
|
133
|
+
if (autoSubscribe === 3 /* AUDIO_ONLY */ && pub.kind === import_rtc_node.TrackKind.KIND_AUDIO || autoSubscribe === 2 /* VIDEO_ONLY */ && pub.kind === import_rtc_node.TrackKind.KIND_VIDEO) {
|
|
134
|
+
pub.setSubscribed(true);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Gracefully shuts down the job, and runs all shutdown promises.
|
|
142
|
+
*
|
|
143
|
+
* @param reason - Optional reason for shutdown
|
|
144
|
+
*/
|
|
145
|
+
shutdown(reason = "") {
|
|
146
|
+
this.#onShutdown(reason);
|
|
147
|
+
}
|
|
148
|
+
/** @internal */
|
|
149
|
+
onParticipantConnected(p) {
|
|
150
|
+
var _a;
|
|
151
|
+
for (const callback of this.#participantEntrypoints) {
|
|
152
|
+
if (((_a = this.#participantTasks[p.identity]) == null ? void 0 : _a.callback) == callback) {
|
|
153
|
+
this.#logger.warn(
|
|
154
|
+
"a participant has joined before a prior prticipant task matching the same identity has finished:",
|
|
155
|
+
p.identity
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
const result = callback(this, p);
|
|
159
|
+
result.finally(() => delete this.#participantTasks[p.identity]);
|
|
160
|
+
this.#participantTasks[p.identity] = { callback, result };
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Adds a promise to be awaited whenever a new participant joins the room.
|
|
165
|
+
*
|
|
166
|
+
* @throws {@link FunctionExistsError} if an entrypoint already exists
|
|
167
|
+
*/
|
|
168
|
+
addParticipantEntrypoint(callback) {
|
|
169
|
+
if (this.#participantEntrypoints.includes(callback)) {
|
|
170
|
+
throw new FunctionExistsError("entrypoints cannot be added more than once");
|
|
171
|
+
}
|
|
172
|
+
this.#participantEntrypoints.push(callback);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
class JobProcess {
|
|
176
|
+
#pid = process.pid;
|
|
177
|
+
userData = {};
|
|
178
|
+
get pid() {
|
|
179
|
+
return this.#pid;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
class JobRequest {
|
|
183
|
+
#job;
|
|
184
|
+
#onReject;
|
|
185
|
+
#onAccept;
|
|
186
|
+
/** @internal */
|
|
187
|
+
constructor(job, onReject, onAccept) {
|
|
188
|
+
this.#job = job;
|
|
189
|
+
this.#onReject = onReject;
|
|
190
|
+
this.#onAccept = onAccept;
|
|
191
|
+
}
|
|
192
|
+
/** @returns The ID of the job, set by the LiveKit server */
|
|
193
|
+
get id() {
|
|
194
|
+
return this.#job.id;
|
|
195
|
+
}
|
|
196
|
+
/** @see {@link https://www.npmjs.com/package/@livekit/protocol | @livekit/protocol} */
|
|
197
|
+
get job() {
|
|
198
|
+
return this.#job;
|
|
199
|
+
}
|
|
200
|
+
/** @see {@link https://www.npmjs.com/package/@livekit/protocol | @livekit/protocol} */
|
|
201
|
+
get room() {
|
|
202
|
+
return this.#job.room;
|
|
203
|
+
}
|
|
204
|
+
/** @see {@link https://www.npmjs.com/package/@livekit/protocol | @livekit/protocol} */
|
|
205
|
+
get publisher() {
|
|
206
|
+
return this.#job.participant;
|
|
207
|
+
}
|
|
208
|
+
/** @returns The agent's name, as set in {@link WorkerOptions} */
|
|
209
|
+
get agentName() {
|
|
210
|
+
return this.#job.agentName;
|
|
211
|
+
}
|
|
212
|
+
/** Rejects the job. */
|
|
213
|
+
async reject() {
|
|
214
|
+
await this.#onReject();
|
|
215
|
+
}
|
|
216
|
+
/** Accepts the job, launching it on an idle child process. */
|
|
217
|
+
async accept(name = "", identity = "", metadata = "", attributes) {
|
|
218
|
+
if (identity === "") identity = "agent-" + this.id;
|
|
219
|
+
this.#onAccept({ name, identity, metadata, attributes });
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
223
|
+
0 && (module.exports = {
|
|
224
|
+
AutoSubscribe,
|
|
225
|
+
FunctionExistsError,
|
|
226
|
+
JobContext,
|
|
227
|
+
JobProcess,
|
|
228
|
+
JobRequest
|
|
229
|
+
});
|
|
230
|
+
//# sourceMappingURL=job.cjs.map
|
package/dist/job.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/job.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type * as proto from '@livekit/protocol';\nimport type {\n E2EEOptions,\n LocalParticipant,\n RemoteParticipant,\n Room,\n RtcConfiguration,\n} from '@livekit/rtc-node';\nimport { ParticipantKind, RoomEvent, TrackKind } from '@livekit/rtc-node';\nimport type { Logger } from 'pino';\nimport { log } from './log.js';\n\n/** Which tracks, if any, should the agent automatically subscribe to? */\nexport enum AutoSubscribe {\n SUBSCRIBE_ALL,\n SUBSCRIBE_NONE,\n VIDEO_ONLY,\n AUDIO_ONLY,\n}\n\nexport type JobAcceptArguments = {\n name: string;\n identity: string;\n metadata: string;\n attributes?: { [key: string]: string };\n};\n\nexport type RunningJobInfo = {\n acceptArguments: JobAcceptArguments;\n job: proto.Job;\n url: string;\n token: string;\n};\n\n/** Attempted to add a function callback, but the function already exists. */\nexport class FunctionExistsError extends Error {\n constructor(msg?: string) {\n super(msg);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** The job and environment context as seen by the agent, accessible by the entrypoint function. */\nexport class JobContext {\n #proc: JobProcess;\n #info: RunningJobInfo;\n #room: Room;\n #onConnect: () => void;\n #onShutdown: (s: string) => void;\n /** @internal */\n shutdownCallbacks: (() => Promise<void>)[] = [];\n #participantEntrypoints: ((job: JobContext, p: RemoteParticipant) => Promise<void>)[] = [];\n #participantTasks: {\n [id: string]: {\n callback: (job: JobContext, p: RemoteParticipant) => Promise<void>;\n result: Promise<void>;\n };\n } = {};\n #logger: Logger;\n\n constructor(\n proc: JobProcess,\n info: RunningJobInfo,\n room: Room,\n onConnect: () => void,\n onShutdown: (s: string) => void,\n ) {\n this.#proc = proc;\n this.#info = info;\n this.#room = room;\n this.#onConnect = onConnect;\n this.#onShutdown = onShutdown;\n this.onParticipantConnected = this.onParticipantConnected.bind(this);\n this.#room.on(RoomEvent.ParticipantConnected, this.onParticipantConnected);\n this.#logger = log().child({ info: this.#info });\n }\n\n get proc(): JobProcess {\n return this.#proc;\n }\n\n get job(): proto.Job {\n return this.#info.job;\n }\n\n /** @returns The room the agent was called into */\n get room(): Room {\n return this.#room;\n }\n\n /** @returns The agent's participant if connected to the room, otherwise `undefined` */\n get agent(): LocalParticipant | undefined {\n return this.#room.localParticipant;\n }\n\n /** Adds a promise to be awaited when {@link JobContext.shutdown | shutdown} is called. */\n addShutdownCallback(callback: () => Promise<void>) {\n this.shutdownCallbacks.push(callback);\n }\n\n async waitForParticipant(identity?: string): Promise<RemoteParticipant> {\n if (!this.#room.isConnected) {\n throw new Error('room is not connected');\n }\n\n for (const p of this.#room.remoteParticipants.values()) {\n if ((!identity || p.identity === identity) && p.info.kind != ParticipantKind.AGENT) {\n return p;\n }\n }\n\n return new Promise((resolve, reject) => {\n const onParticipantConnected = (participant: RemoteParticipant) => {\n if (\n (!identity || participant.identity === identity) &&\n participant.info.kind != ParticipantKind.AGENT\n ) {\n clearHandlers();\n resolve(participant);\n }\n };\n const onDisconnected = () => {\n clearHandlers();\n reject(new Error('Room disconnected while waiting for participant'));\n };\n\n const clearHandlers = () => {\n this.#room.off(RoomEvent.ParticipantConnected, onParticipantConnected);\n this.#room.off(RoomEvent.Disconnected, onDisconnected);\n };\n\n this.#room.on(RoomEvent.ParticipantConnected, onParticipantConnected);\n this.#room.on(RoomEvent.Disconnected, onDisconnected);\n });\n }\n\n /**\n * Connects the agent to the room.\n *\n * @remarks\n * It is recommended to run this command as early in the function as possible, as executing it\n * later may cause noticeable delay between user and agent joins.\n *\n * @see {@link https://github.com/livekit/node-sdks/tree/main/packages/livekit-rtc#readme |\n * @livekit/rtc-node} for more information about the parameters.\n */\n async connect(\n e2ee?: E2EEOptions,\n autoSubscribe: AutoSubscribe = AutoSubscribe.SUBSCRIBE_ALL,\n rtcConfig?: RtcConfiguration,\n ) {\n const opts = {\n e2ee,\n autoSubscribe: autoSubscribe == AutoSubscribe.SUBSCRIBE_ALL,\n rtcConfig,\n dynacast: false,\n };\n\n await this.#room.connect(this.#info.url, this.#info.token, opts);\n this.#onConnect();\n\n this.#room.remoteParticipants.forEach(this.onParticipantConnected);\n\n if ([AutoSubscribe.AUDIO_ONLY, AutoSubscribe.VIDEO_ONLY].includes(autoSubscribe)) {\n this.#room.remoteParticipants.forEach((p) => {\n p.trackPublications.forEach((pub) => {\n if (\n (autoSubscribe === AutoSubscribe.AUDIO_ONLY && pub.kind === TrackKind.KIND_AUDIO) ||\n (autoSubscribe === AutoSubscribe.VIDEO_ONLY && pub.kind === TrackKind.KIND_VIDEO)\n ) {\n pub.setSubscribed(true);\n }\n });\n });\n }\n }\n\n /**\n * Gracefully shuts down the job, and runs all shutdown promises.\n *\n * @param reason - Optional reason for shutdown\n */\n shutdown(reason = '') {\n this.#onShutdown(reason);\n }\n\n /** @internal */\n onParticipantConnected(p: RemoteParticipant) {\n for (const callback of this.#participantEntrypoints) {\n if (this.#participantTasks[p.identity]?.callback == callback) {\n this.#logger.warn(\n 'a participant has joined before a prior prticipant task matching the same identity has finished:',\n p.identity,\n );\n }\n const result = callback(this, p);\n result.finally(() => delete this.#participantTasks[p.identity]);\n this.#participantTasks[p.identity] = { callback, result };\n }\n }\n\n /**\n * Adds a promise to be awaited whenever a new participant joins the room.\n *\n * @throws {@link FunctionExistsError} if an entrypoint already exists\n */\n addParticipantEntrypoint(callback: (job: JobContext, p: RemoteParticipant) => Promise<void>) {\n if (this.#participantEntrypoints.includes(callback)) {\n throw new FunctionExistsError('entrypoints cannot be added more than once');\n }\n\n this.#participantEntrypoints.push(callback);\n }\n}\n\nexport class JobProcess {\n #pid = process.pid;\n userData: { [id: string]: unknown } = {};\n\n get pid(): number {\n return this.#pid;\n }\n}\n\n/**\n * A request sent by the server to spawn a new agent job.\n *\n * @remarks\n * For most applications, this is best left to the default, which simply accepts the job and\n * handles the logic inside the entrypoint function. This class is useful for vetting which\n * requests should fill idle processes and which should be outright rejected.\n */\nexport class JobRequest {\n #job: proto.Job;\n #onReject: () => Promise<void>;\n #onAccept: (args: JobAcceptArguments) => Promise<void>;\n\n /** @internal */\n constructor(\n job: proto.Job,\n onReject: () => Promise<void>,\n onAccept: (args: JobAcceptArguments) => Promise<void>,\n ) {\n this.#job = job;\n this.#onReject = onReject;\n this.#onAccept = onAccept;\n }\n\n /** @returns The ID of the job, set by the LiveKit server */\n get id(): string {\n return this.#job.id;\n }\n\n /** @see {@link https://www.npmjs.com/package/@livekit/protocol | @livekit/protocol} */\n get job(): proto.Job {\n return this.#job;\n }\n\n /** @see {@link https://www.npmjs.com/package/@livekit/protocol | @livekit/protocol} */\n get room(): proto.Room | undefined {\n return this.#job.room;\n }\n\n /** @see {@link https://www.npmjs.com/package/@livekit/protocol | @livekit/protocol} */\n get publisher(): proto.ParticipantInfo | undefined {\n return this.#job.participant;\n }\n\n /** @returns The agent's name, as set in {@link WorkerOptions} */\n get agentName(): string {\n return this.#job.agentName;\n }\n\n /** Rejects the job. */\n async reject() {\n await this.#onReject();\n }\n\n /** Accepts the job, launching it on an idle child process. */\n async accept(name = '', identity = '', metadata = '', attributes?: { [key: string]: string }) {\n if (identity === '') identity = 'agent-' + this.id;\n\n this.#onAccept({ name, identity, metadata, attributes });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,sBAAsD;AAEtD,iBAAoB;AAGb,IAAK,gBAAL,kBAAKA,mBAAL;AACL,EAAAA,8BAAA;AACA,EAAAA,8BAAA;AACA,EAAAA,8BAAA;AACA,EAAAA,8BAAA;AAJU,SAAAA;AAAA,GAAA;AAsBL,MAAM,4BAA4B,MAAM;AAAA,EAC7C,YAAY,KAAc;AACxB,UAAM,GAAG;AACT,WAAO,eAAe,MAAM,WAAW,SAAS;AAAA,EAClD;AACF;AAGO,MAAM,WAAW;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAEA,oBAA6C,CAAC;AAAA,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AU,EAAE,MAAM,UAAU,UAAU,WAAW,CAAC;AAAA,EACzD;AACF;","names":["AutoSubscribe"]}
|
package/dist/job.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ export type JobAcceptArguments = {
|
|
|
11
11
|
name: string;
|
|
12
12
|
identity: string;
|
|
13
13
|
metadata: string;
|
|
14
|
+
attributes?: {
|
|
15
|
+
[key: string]: string;
|
|
16
|
+
};
|
|
14
17
|
};
|
|
15
18
|
export type RunningJobInfo = {
|
|
16
19
|
acceptArguments: JobAcceptArguments;
|
|
@@ -95,6 +98,8 @@ export declare class JobRequest {
|
|
|
95
98
|
/** Rejects the job. */
|
|
96
99
|
reject(): Promise<void>;
|
|
97
100
|
/** Accepts the job, launching it on an idle child process. */
|
|
98
|
-
accept(name?: string, identity?: string, metadata?: string
|
|
101
|
+
accept(name?: string, identity?: string, metadata?: string, attributes?: {
|
|
102
|
+
[key: string]: string;
|
|
103
|
+
}): Promise<void>;
|
|
99
104
|
}
|
|
100
105
|
//# sourceMappingURL=job.d.ts.map
|
package/dist/job.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"job.d.ts","sourceRoot":"","sources":["../src/job.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,IAAI,EACJ,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAK3B,yEAAyE;AACzE,oBAAY,aAAa;IACvB,aAAa,IAAA;IACb,cAAc,IAAA;IACd,UAAU,IAAA;IACV,UAAU,IAAA;CACX;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"job.d.ts","sourceRoot":"","sources":["../src/job.ts"],"names":[],"mappings":"AAGA,O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