@livekit/agents 0.6.4 → 0.7.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/dist/index.cjs +6 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/inference_runner.cjs +38 -0
- package/dist/inference_runner.cjs.map +1 -0
- package/dist/inference_runner.d.ts +11 -0
- package/dist/inference_runner.d.ts.map +1 -0
- package/dist/inference_runner.js +14 -0
- package/dist/inference_runner.js.map +1 -0
- package/dist/ipc/index.cjs +23 -0
- package/dist/ipc/index.cjs.map +1 -0
- package/dist/ipc/index.d.ts +2 -0
- package/dist/ipc/index.d.ts.map +1 -0
- package/dist/ipc/index.js +2 -0
- package/dist/ipc/index.js.map +1 -0
- package/dist/ipc/inference_executor.cjs +17 -0
- package/dist/ipc/inference_executor.cjs.map +1 -0
- package/dist/ipc/inference_executor.d.ts +4 -0
- package/dist/ipc/inference_executor.d.ts.map +1 -0
- package/dist/ipc/inference_executor.js +1 -0
- package/dist/ipc/inference_executor.js.map +1 -0
- package/dist/ipc/inference_proc_executor.cjs +97 -0
- package/dist/ipc/inference_proc_executor.cjs.map +1 -0
- package/dist/ipc/inference_proc_executor.d.ts +23 -0
- package/dist/ipc/inference_proc_executor.d.ts.map +1 -0
- package/dist/ipc/inference_proc_executor.js +72 -0
- package/dist/ipc/inference_proc_executor.js.map +1 -0
- package/dist/ipc/inference_proc_lazy_main.cjs +90 -0
- package/dist/ipc/inference_proc_lazy_main.cjs.map +1 -0
- package/dist/ipc/inference_proc_lazy_main.d.ts +2 -0
- package/dist/ipc/inference_proc_lazy_main.d.ts.map +1 -0
- package/dist/ipc/inference_proc_lazy_main.js +67 -0
- package/dist/ipc/inference_proc_lazy_main.js.map +1 -0
- package/dist/ipc/job_executor.cjs +8 -7
- package/dist/ipc/job_executor.cjs.map +1 -1
- package/dist/ipc/job_executor.d.ts +14 -15
- package/dist/ipc/job_executor.d.ts.map +1 -1
- package/dist/ipc/job_executor.js +7 -6
- package/dist/ipc/job_executor.js.map +1 -1
- package/dist/ipc/job_proc_executor.cjs +108 -0
- package/dist/ipc/job_proc_executor.cjs.map +1 -0
- package/dist/ipc/job_proc_executor.d.ts +19 -0
- package/dist/ipc/job_proc_executor.d.ts.map +1 -0
- package/dist/ipc/job_proc_executor.js +83 -0
- package/dist/ipc/job_proc_executor.js.map +1 -0
- package/dist/ipc/{job_main.cjs → job_proc_lazy_main.cjs} +41 -36
- package/dist/ipc/job_proc_lazy_main.cjs.map +1 -0
- package/dist/ipc/job_proc_lazy_main.d.ts +2 -0
- package/dist/ipc/job_proc_lazy_main.d.ts.map +1 -0
- package/dist/ipc/{job_main.js → job_proc_lazy_main.js} +41 -11
- package/dist/ipc/job_proc_lazy_main.js.map +1 -0
- package/dist/ipc/message.cjs.map +1 -1
- package/dist/ipc/message.d.ts +17 -0
- package/dist/ipc/message.d.ts.map +1 -1
- package/dist/ipc/proc_pool.cjs +30 -4
- package/dist/ipc/proc_pool.cjs.map +1 -1
- package/dist/ipc/proc_pool.d.ts +5 -1
- package/dist/ipc/proc_pool.d.ts.map +1 -1
- package/dist/ipc/proc_pool.js +30 -4
- package/dist/ipc/proc_pool.js.map +1 -1
- package/dist/ipc/{proc_job_executor.cjs → supervised_proc.cjs} +57 -45
- package/dist/ipc/supervised_proc.cjs.map +1 -0
- package/dist/ipc/supervised_proc.d.ts +30 -0
- package/dist/ipc/supervised_proc.d.ts.map +1 -0
- package/dist/ipc/{proc_job_executor.js → supervised_proc.js} +53 -31
- package/dist/ipc/supervised_proc.js.map +1 -0
- package/dist/job.cjs +18 -1
- package/dist/job.cjs.map +1 -1
- package/dist/job.d.ts +9 -1
- package/dist/job.d.ts.map +1 -1
- package/dist/job.js +17 -1
- package/dist/job.js.map +1 -1
- package/dist/multimodal/agent_playout.cjs +13 -14
- package/dist/multimodal/agent_playout.cjs.map +1 -1
- package/dist/multimodal/agent_playout.d.ts +4 -4
- package/dist/multimodal/agent_playout.d.ts.map +1 -1
- package/dist/multimodal/agent_playout.js +13 -14
- package/dist/multimodal/agent_playout.js.map +1 -1
- package/dist/multimodal/multimodal_agent.cjs +12 -8
- package/dist/multimodal/multimodal_agent.cjs.map +1 -1
- package/dist/multimodal/multimodal_agent.d.ts.map +1 -1
- package/dist/multimodal/multimodal_agent.js +13 -9
- package/dist/multimodal/multimodal_agent.js.map +1 -1
- package/dist/pipeline/agent_output.cjs +20 -4
- package/dist/pipeline/agent_output.cjs.map +1 -1
- package/dist/pipeline/agent_output.d.ts +4 -2
- package/dist/pipeline/agent_output.d.ts.map +1 -1
- package/dist/pipeline/agent_output.js +20 -4
- package/dist/pipeline/agent_output.js.map +1 -1
- package/dist/pipeline/agent_playout.cjs +9 -3
- package/dist/pipeline/agent_playout.cjs.map +1 -1
- package/dist/pipeline/agent_playout.d.ts +4 -2
- package/dist/pipeline/agent_playout.d.ts.map +1 -1
- package/dist/pipeline/agent_playout.js +9 -3
- package/dist/pipeline/agent_playout.js.map +1 -1
- package/dist/pipeline/human_input.cjs +6 -0
- package/dist/pipeline/human_input.cjs.map +1 -1
- package/dist/pipeline/human_input.d.ts +3 -1
- package/dist/pipeline/human_input.d.ts.map +1 -1
- package/dist/pipeline/human_input.js +6 -0
- package/dist/pipeline/human_input.js.map +1 -1
- package/dist/pipeline/pipeline_agent.cjs +79 -12
- package/dist/pipeline/pipeline_agent.cjs.map +1 -1
- package/dist/pipeline/pipeline_agent.d.ts +8 -0
- package/dist/pipeline/pipeline_agent.d.ts.map +1 -1
- package/dist/pipeline/pipeline_agent.js +79 -12
- package/dist/pipeline/pipeline_agent.js.map +1 -1
- package/dist/stt/stream_adapter.cjs +16 -4
- package/dist/stt/stream_adapter.cjs.map +1 -1
- package/dist/stt/stream_adapter.d.ts.map +1 -1
- package/dist/stt/stream_adapter.js +16 -4
- package/dist/stt/stream_adapter.js.map +1 -1
- package/dist/tokenize/basic/basic.cjs +2 -0
- package/dist/tokenize/basic/basic.cjs.map +1 -1
- package/dist/tokenize/basic/basic.d.ts +2 -0
- package/dist/tokenize/basic/basic.d.ts.map +1 -1
- package/dist/tokenize/basic/basic.js +1 -0
- package/dist/tokenize/basic/basic.js.map +1 -1
- package/dist/tokenize/basic/index.cjs +2 -0
- package/dist/tokenize/basic/index.cjs.map +1 -1
- package/dist/tokenize/basic/index.d.ts +1 -1
- package/dist/tokenize/basic/index.d.ts.map +1 -1
- package/dist/tokenize/basic/index.js +8 -1
- package/dist/tokenize/basic/index.js.map +1 -1
- package/dist/tokenize/token_stream.cjs +5 -3
- package/dist/tokenize/token_stream.cjs.map +1 -1
- package/dist/tokenize/token_stream.d.ts.map +1 -1
- package/dist/tokenize/token_stream.js +5 -3
- package/dist/tokenize/token_stream.js.map +1 -1
- package/dist/transcription.cjs +203 -86
- package/dist/transcription.cjs.map +1 -1
- package/dist/transcription.d.ts +24 -17
- package/dist/transcription.d.ts.map +1 -1
- package/dist/transcription.js +201 -85
- package/dist/transcription.js.map +1 -1
- package/dist/worker.cjs +42 -9
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.ts +5 -1
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +42 -9
- package/dist/worker.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +3 -1
- package/src/inference_runner.ts +19 -0
- package/src/ipc/index.ts +5 -0
- package/src/ipc/inference_executor.ts +7 -0
- package/src/ipc/inference_proc_executor.ts +93 -0
- package/src/ipc/inference_proc_lazy_main.ts +86 -0
- package/src/ipc/job_executor.ts +15 -17
- package/src/ipc/job_proc_executor.ts +112 -0
- package/src/ipc/{job_main.ts → job_proc_lazy_main.ts} +44 -14
- package/src/ipc/message.ts +14 -1
- package/src/ipc/proc_pool.ts +33 -3
- package/src/ipc/{proc_job_executor.ts → supervised_proc.ts} +77 -29
- package/src/job.ts +21 -0
- package/src/multimodal/agent_playout.ts +14 -16
- package/src/multimodal/multimodal_agent.ts +13 -9
- package/src/pipeline/agent_output.ts +34 -5
- package/src/pipeline/agent_playout.ts +10 -1
- package/src/pipeline/human_input.ts +8 -0
- package/src/pipeline/pipeline_agent.ts +96 -11
- package/src/stt/stream_adapter.ts +17 -5
- package/src/tokenize/basic/basic.ts +2 -0
- package/src/tokenize/basic/index.ts +7 -1
- package/src/tokenize/token_stream.ts +6 -3
- package/src/transcription.ts +270 -96
- package/src/worker.ts +42 -5
- package/dist/ipc/job_main.cjs.map +0 -1
- package/dist/ipc/job_main.d.ts +0 -8
- package/dist/ipc/job_main.d.ts.map +0 -1
- package/dist/ipc/job_main.js.map +0 -1
- package/dist/ipc/proc_job_executor.cjs.map +0 -1
- package/dist/ipc/proc_job_executor.d.ts +0 -15
- package/dist/ipc/proc_job_executor.d.ts.map +0 -1
- package/dist/ipc/proc_job_executor.js.map +0 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import EventEmitter, { once } from "node:events";
|
|
2
|
+
import { initializeLogger, log } from "../log.js";
|
|
3
|
+
const ORPHANED_TIMEOUT = 15 * 1e3;
|
|
4
|
+
(async () => {
|
|
5
|
+
if (process.send) {
|
|
6
|
+
process.on("SIGINT", () => {
|
|
7
|
+
});
|
|
8
|
+
await once(process, "message").then(([msg]) => {
|
|
9
|
+
msg = msg;
|
|
10
|
+
if (msg.case !== "initializeRequest") {
|
|
11
|
+
throw new Error("first message must be InitializeRequest");
|
|
12
|
+
}
|
|
13
|
+
initializeLogger(msg.value.loggerOptions);
|
|
14
|
+
});
|
|
15
|
+
const logger = log().child({ pid: process.pid });
|
|
16
|
+
const runners = await Promise.all(
|
|
17
|
+
Object.entries(JSON.parse(process.argv[2])).map(async ([k, v]) => {
|
|
18
|
+
return [k, await import(v).then((m) => new m.default())];
|
|
19
|
+
})
|
|
20
|
+
).then(Object.fromEntries);
|
|
21
|
+
await Promise.all(
|
|
22
|
+
Object.entries(runners).map(async ([runner, v]) => {
|
|
23
|
+
logger.child({ runner }).debug("initializing inference runner");
|
|
24
|
+
await v.initialize();
|
|
25
|
+
})
|
|
26
|
+
);
|
|
27
|
+
logger.debug("all inference runners initialized");
|
|
28
|
+
process.send({ case: "initializeResponse" });
|
|
29
|
+
const closeEvent = new EventEmitter();
|
|
30
|
+
const orphanedTimeout = setTimeout(() => {
|
|
31
|
+
logger.warn("process orphaned, shutting down");
|
|
32
|
+
process.exit();
|
|
33
|
+
}, ORPHANED_TIMEOUT);
|
|
34
|
+
const handleInferenceRequest = async ({
|
|
35
|
+
method,
|
|
36
|
+
requestId,
|
|
37
|
+
data
|
|
38
|
+
}) => {
|
|
39
|
+
if (!runners[method]) {
|
|
40
|
+
logger.child({ method }).warn("unknown inference method");
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const resp = await runners[method].run(data);
|
|
44
|
+
process.send({ case: "inferenceResponse", value: { requestId, data: resp } });
|
|
45
|
+
} catch (error) {
|
|
46
|
+
process.send({ case: "inferenceResponse", value: { requestId, error } });
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
process.on("message", (msg) => {
|
|
50
|
+
switch (msg.case) {
|
|
51
|
+
case "pingRequest":
|
|
52
|
+
orphanedTimeout.refresh();
|
|
53
|
+
process.send({
|
|
54
|
+
case: "pongResponse",
|
|
55
|
+
value: { lastTimestamp: msg.value.timestamp, timestamp: Date.now() }
|
|
56
|
+
});
|
|
57
|
+
break;
|
|
58
|
+
case "shutdownRequest":
|
|
59
|
+
closeEvent.emit("close");
|
|
60
|
+
break;
|
|
61
|
+
case "inferenceRequest":
|
|
62
|
+
handleInferenceRequest(msg.value);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
})();
|
|
67
|
+
//# sourceMappingURL=inference_proc_lazy_main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/ipc/inference_proc_lazy_main.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport EventEmitter, { once } from 'node:events';\nimport type { InferenceRunner } from '../inference_runner.js';\nimport { initializeLogger, log } from '../log.js';\nimport type { IPCMessage } from './message.js';\n\nconst ORPHANED_TIMEOUT = 15 * 1000;\n\n(async () => {\n if (process.send) {\n // don't do anything on C-c\n // this is handled in cli, triggering a termination of all child processes at once.\n process.on('SIGINT', () => {});\n\n await once(process, 'message').then(([msg]: IPCMessage[]) => {\n msg = msg!;\n if (msg.case !== 'initializeRequest') {\n throw new Error('first message must be InitializeRequest');\n }\n initializeLogger(msg.value.loggerOptions);\n });\n const logger = log().child({ pid: process.pid });\n\n const runners: { [id: string]: InferenceRunner } = await Promise.all(\n Object.entries(JSON.parse(process.argv[2]!)).map(async ([k, v]) => {\n return [k, await import(v as string).then((m) => new m.default())];\n }),\n ).then(Object.fromEntries);\n\n await Promise.all(\n Object.entries(runners).map(async ([runner, v]) => {\n logger.child({ runner }).debug('initializing inference runner');\n await v.initialize();\n }),\n );\n logger.debug('all inference runners initialized');\n process.send({ case: 'initializeResponse' });\n\n const closeEvent = new EventEmitter();\n\n const orphanedTimeout = setTimeout(() => {\n logger.warn('process orphaned, shutting down');\n process.exit();\n }, ORPHANED_TIMEOUT);\n\n const handleInferenceRequest = async ({\n method,\n requestId,\n data,\n }: {\n method: string;\n requestId: string;\n data: unknown;\n }) => {\n if (!runners[method]) {\n logger.child({ method }).warn('unknown inference method');\n }\n\n try {\n const resp = await runners[method]!.run(data);\n process.send!({ case: 'inferenceResponse', value: { requestId, data: resp } });\n } catch (error) {\n process.send!({ case: 'inferenceResponse', value: { requestId, error } });\n }\n };\n\n process.on('message', (msg: IPCMessage) => {\n switch (msg.case) {\n case 'pingRequest':\n orphanedTimeout.refresh();\n process.send!({\n case: 'pongResponse',\n value: { lastTimestamp: msg.value.timestamp, timestamp: Date.now() },\n });\n break;\n case 'shutdownRequest':\n closeEvent.emit('close');\n break;\n case 'inferenceRequest':\n handleInferenceRequest(msg.value);\n }\n });\n }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;AAAA,IACF,MAIM;AACJ,UAAI,CAAC,QAAQ,MAAM,GAAG;AACpB,eAAO,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,0BAA0B;AAAA,MAC1D;AAEA,UAAI;AACF,cAAM,OAAO,MAAM,QAAQ,MAAM,EAAG,IAAI,IAAI;AAC5C,gBAAQ,KAAM,EAAE,MAAM,qBAAqB,OAAO,EAAE,WAAW,MAAM,KAAK,EAAE,CAAC;AAAA,MAC/E,SAAS,OAAO;AACd,gBAAQ,KAAM,EAAE,MAAM,qBAAqB,OAAO,EAAE,WAAW,MAAM,EAAE,CAAC;AAAA,MAC1E;AAAA,IACF;AAEA,YAAQ,GAAG,WAAW,CAAC,QAAoB;AACzC,cAAQ,IAAI,MAAM;AAAA,QAChB,KAAK;AACH,0BAAgB,QAAQ;AACxB,kBAAQ,KAAM;AAAA,YACZ,MAAM;AAAA,YACN,OAAO,EAAE,eAAe,IAAI,MAAM,WAAW,WAAW,KAAK,IAAI,EAAE;AAAA,UACrE,CAAC;AACD;AAAA,QACF,KAAK;AACH,qBAAW,KAAK,OAAO;AACvB;AAAA,QACF,KAAK;AACH,iCAAuB,IAAI,KAAK;AAAA,MACpC;AAAA,IACF,CAAC;AAAA,EACH;AACF,GAAG;","names":[]}
|
|
@@ -18,16 +18,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var job_executor_exports = {};
|
|
20
20
|
__export(job_executor_exports, {
|
|
21
|
-
|
|
21
|
+
JobStatus: () => JobStatus
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(job_executor_exports);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
var JobStatus = /* @__PURE__ */ ((JobStatus2) => {
|
|
25
|
+
JobStatus2[JobStatus2["RUNNING"] = 0] = "RUNNING";
|
|
26
|
+
JobStatus2[JobStatus2["FAILED"] = 1] = "FAILED";
|
|
27
|
+
JobStatus2[JobStatus2["SUCCESS"] = 2] = "SUCCESS";
|
|
28
|
+
return JobStatus2;
|
|
29
|
+
})(JobStatus || {});
|
|
29
30
|
// Annotate the CommonJS export names for ESM import in node:
|
|
30
31
|
0 && (module.exports = {
|
|
31
|
-
|
|
32
|
+
JobStatus
|
|
32
33
|
});
|
|
33
34
|
//# sourceMappingURL=job_executor.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ipc/job_executor.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { RunningJobInfo } from '../job.js';\n\nexport interface
|
|
1
|
+
{"version":3,"sources":["../../src/ipc/job_executor.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { RunningJobInfo } from '../job.js';\n\nexport interface JobExecutor {\n started: boolean;\n userArguments: any;\n runningJob: RunningJobInfo | undefined;\n status: JobStatus;\n\n start(): Promise<void>;\n join(): Promise<void>;\n initialize(): Promise<void>;\n close(): Promise<void>;\n launchJob(info: RunningJobInfo): Promise<void>;\n}\n\nexport enum JobStatus {\n RUNNING,\n FAILED,\n SUCCESS,\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,IAAK,YAAL,kBAAKA,eAAL;AACL,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AAHU,SAAAA;AAAA,GAAA;","names":["JobStatus"]}
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import type { RunningJobInfo } from '../job.js';
|
|
2
|
-
export interface
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export interface JobExecutor {
|
|
3
|
+
started: boolean;
|
|
4
|
+
userArguments: any;
|
|
5
|
+
runningJob: RunningJobInfo | undefined;
|
|
6
|
+
status: JobStatus;
|
|
7
|
+
start(): Promise<void>;
|
|
8
|
+
join(): Promise<void>;
|
|
9
|
+
initialize(): Promise<void>;
|
|
10
|
+
close(): Promise<void>;
|
|
11
|
+
launchJob(info: RunningJobInfo): Promise<void>;
|
|
6
12
|
}
|
|
7
|
-
export declare
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
abstract get started(): boolean;
|
|
12
|
-
abstract get runningJob(): RunningJobInfo | undefined;
|
|
13
|
-
abstract start(): Promise<void>;
|
|
14
|
-
abstract join(): Promise<void>;
|
|
15
|
-
abstract initialize(): Promise<void>;
|
|
16
|
-
abstract close(): Promise<void>;
|
|
17
|
-
abstract launchJob(info: RunningJobInfo): Promise<void>;
|
|
13
|
+
export declare enum JobStatus {
|
|
14
|
+
RUNNING = 0,
|
|
15
|
+
FAILED = 1,
|
|
16
|
+
SUCCESS = 2
|
|
18
17
|
}
|
|
19
18
|
//# sourceMappingURL=job_executor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"job_executor.d.ts","sourceRoot":"","sources":["../../src/ipc/job_executor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"job_executor.d.ts","sourceRoot":"","sources":["../../src/ipc/job_executor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,GAAG,CAAC;IACnB,UAAU,EAAE,cAAc,GAAG,SAAS,CAAC;IACvC,MAAM,EAAE,SAAS,CAAC;IAElB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,SAAS,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD;AAED,oBAAY,SAAS;IACnB,OAAO,IAAA;IACP,MAAM,IAAA;IACN,OAAO,IAAA;CACR"}
|
package/dist/ipc/job_executor.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var JobStatus = /* @__PURE__ */ ((JobStatus2) => {
|
|
2
|
+
JobStatus2[JobStatus2["RUNNING"] = 0] = "RUNNING";
|
|
3
|
+
JobStatus2[JobStatus2["FAILED"] = 1] = "FAILED";
|
|
4
|
+
JobStatus2[JobStatus2["SUCCESS"] = 2] = "SUCCESS";
|
|
5
|
+
return JobStatus2;
|
|
6
|
+
})(JobStatus || {});
|
|
6
7
|
export {
|
|
7
|
-
|
|
8
|
+
JobStatus
|
|
8
9
|
};
|
|
9
10
|
//# sourceMappingURL=job_executor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ipc/job_executor.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { RunningJobInfo } from '../job.js';\n\nexport interface
|
|
1
|
+
{"version":3,"sources":["../../src/ipc/job_executor.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { RunningJobInfo } from '../job.js';\n\nexport interface JobExecutor {\n started: boolean;\n userArguments: any;\n runningJob: RunningJobInfo | undefined;\n status: JobStatus;\n\n start(): Promise<void>;\n join(): Promise<void>;\n initialize(): Promise<void>;\n close(): Promise<void>;\n launchJob(info: RunningJobInfo): Promise<void>;\n}\n\nexport enum JobStatus {\n RUNNING,\n FAILED,\n SUCCESS,\n}\n"],"mappings":"AAkBO,IAAK,YAAL,kBAAKA,eAAL;AACL,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AAHU,SAAAA;AAAA,GAAA;","names":["JobStatus"]}
|
|
@@ -0,0 +1,108 @@
|
|
|
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_proc_executor_exports = {};
|
|
20
|
+
__export(job_proc_executor_exports, {
|
|
21
|
+
JobProcExecutor: () => JobProcExecutor
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(job_proc_executor_exports);
|
|
24
|
+
var import_node_child_process = require("node:child_process");
|
|
25
|
+
var import_log = require("../log.cjs");
|
|
26
|
+
var import_job_executor = require("./job_executor.cjs");
|
|
27
|
+
var import_supervised_proc = require("./supervised_proc.cjs");
|
|
28
|
+
const import_meta = {};
|
|
29
|
+
class JobProcExecutor extends import_supervised_proc.SupervisedProc {
|
|
30
|
+
#userArgs;
|
|
31
|
+
#jobStatus;
|
|
32
|
+
#runningJob;
|
|
33
|
+
#agent;
|
|
34
|
+
#inferenceExecutor;
|
|
35
|
+
#inferenceTasks = [];
|
|
36
|
+
#logger = (0, import_log.log)();
|
|
37
|
+
constructor(agent, inferenceExecutor, initializeTimeout, closeTimeout, memoryWarnMB, memoryLimitMB, pingInterval, pingTimeout, highPingThreshold) {
|
|
38
|
+
super(
|
|
39
|
+
initializeTimeout,
|
|
40
|
+
closeTimeout,
|
|
41
|
+
memoryWarnMB,
|
|
42
|
+
memoryLimitMB,
|
|
43
|
+
pingInterval,
|
|
44
|
+
pingTimeout,
|
|
45
|
+
highPingThreshold
|
|
46
|
+
);
|
|
47
|
+
this.#agent = agent;
|
|
48
|
+
this.#inferenceExecutor = inferenceExecutor;
|
|
49
|
+
}
|
|
50
|
+
get status() {
|
|
51
|
+
if (this.#jobStatus) {
|
|
52
|
+
return this.#jobStatus;
|
|
53
|
+
}
|
|
54
|
+
throw new Error("job status not available");
|
|
55
|
+
}
|
|
56
|
+
get userArguments() {
|
|
57
|
+
return this.#userArgs;
|
|
58
|
+
}
|
|
59
|
+
set userArguments(args) {
|
|
60
|
+
this.#userArgs = args;
|
|
61
|
+
}
|
|
62
|
+
get runningJob() {
|
|
63
|
+
return this.#runningJob;
|
|
64
|
+
}
|
|
65
|
+
createProcess() {
|
|
66
|
+
return (0, import_node_child_process.fork)(new URL(import_meta.resolve("./job_proc_lazy_main.js")), [this.#agent]);
|
|
67
|
+
}
|
|
68
|
+
async mainTask(proc) {
|
|
69
|
+
proc.on("message", (msg) => {
|
|
70
|
+
switch (msg.case) {
|
|
71
|
+
case "inferenceRequest":
|
|
72
|
+
this.#inferenceTasks.push(this.#doInferenceTask(proc, msg.value));
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
async #doInferenceTask(proc, req) {
|
|
77
|
+
if (!this.#inferenceExecutor) {
|
|
78
|
+
this.#logger.warn("inference request received but no inference executor");
|
|
79
|
+
proc.send({
|
|
80
|
+
case: "inferenceResponse",
|
|
81
|
+
value: { requestId: req.requestId, error: new Error("no inference executor") }
|
|
82
|
+
});
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const data = await this.#inferenceExecutor.doInference(req.method, req.data);
|
|
87
|
+
proc.send({ case: "inferenceResponse", value: { requestId: req.requestId, data } });
|
|
88
|
+
} catch (error) {
|
|
89
|
+
proc.send({ case: "inferenceResponse", value: { requestId: req.requestId, error } });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async launchJob(info) {
|
|
93
|
+
if (this.#runningJob) {
|
|
94
|
+
throw Error("process already has a running job");
|
|
95
|
+
}
|
|
96
|
+
if (!this.init.done) {
|
|
97
|
+
throw Error("process not initialized");
|
|
98
|
+
}
|
|
99
|
+
this.#jobStatus = import_job_executor.JobStatus.RUNNING;
|
|
100
|
+
this.#runningJob = info;
|
|
101
|
+
this.proc.send({ case: "startJobRequest", value: { runningJob: info } });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {
|
|
106
|
+
JobProcExecutor
|
|
107
|
+
});
|
|
108
|
+
//# sourceMappingURL=job_proc_executor.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/ipc/job_proc_executor.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { ChildProcess } from 'node:child_process';\nimport { fork } from 'node:child_process';\nimport type { RunningJobInfo } from '../job.js';\nimport { log } from '../log.js';\nimport type { InferenceExecutor } from './inference_executor.js';\nimport type { JobExecutor } from './job_executor.js';\nimport { JobStatus } from './job_executor.js';\nimport type { IPCMessage } from './message.js';\nimport { SupervisedProc } from './supervised_proc.js';\n\nexport class JobProcExecutor extends SupervisedProc implements JobExecutor {\n #userArgs?: any;\n #jobStatus?: JobStatus;\n #runningJob?: RunningJobInfo;\n #agent: string;\n #inferenceExecutor?: InferenceExecutor;\n #inferenceTasks: Promise<void>[] = [];\n #logger = log();\n\n constructor(\n agent: string,\n inferenceExecutor: InferenceExecutor | undefined,\n initializeTimeout: number,\n closeTimeout: number,\n memoryWarnMB: number,\n memoryLimitMB: number,\n pingInterval: number,\n pingTimeout: number,\n highPingThreshold: number,\n ) {\n super(\n initializeTimeout,\n closeTimeout,\n memoryWarnMB,\n memoryLimitMB,\n pingInterval,\n pingTimeout,\n highPingThreshold,\n );\n this.#agent = agent;\n this.#inferenceExecutor = inferenceExecutor;\n }\n\n get status(): JobStatus {\n if (this.#jobStatus) {\n return this.#jobStatus;\n }\n throw new Error('job status not available');\n }\n\n get userArguments(): any {\n return this.#userArgs;\n }\n\n set userArguments(args: any) {\n this.#userArgs = args;\n }\n\n get runningJob(): RunningJobInfo | undefined {\n return this.#runningJob;\n }\n\n createProcess(): ChildProcess {\n return fork(new URL(import.meta.resolve('./job_proc_lazy_main.js')), [this.#agent]);\n }\n\n async mainTask(proc: ChildProcess) {\n proc.on('message', (msg: IPCMessage) => {\n switch (msg.case) {\n case 'inferenceRequest':\n this.#inferenceTasks.push(this.#doInferenceTask(proc, msg.value));\n }\n });\n }\n\n async #doInferenceTask(\n proc: ChildProcess,\n req: { method: string; requestId: string; data: unknown },\n ) {\n if (!this.#inferenceExecutor) {\n this.#logger.warn('inference request received but no inference executor');\n proc.send({\n case: 'inferenceResponse',\n value: { requestId: req.requestId, error: new Error('no inference executor') },\n });\n return;\n }\n\n try {\n const data = await this.#inferenceExecutor.doInference(req.method, req.data);\n proc.send({ case: 'inferenceResponse', value: { requestId: req.requestId, data } });\n } catch (error) {\n proc.send({ case: 'inferenceResponse', value: { requestId: req.requestId, error } });\n }\n }\n\n async launchJob(info: RunningJobInfo) {\n if (this.#runningJob) {\n throw Error('process already has a running job');\n }\n if (!this.init.done) {\n throw Error('process not initialized');\n }\n this.#jobStatus = JobStatus.RUNNING;\n this.#runningJob = info;\n\n this.proc!.send({ case: 'startJobR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,WAAK,KAAK;AAAA,QACR,MAAM;AAAA,QACN,OAAO,EAAE,WAAW,IAAI,WAAW,OAAO,IAAI,MAAM,uBAAuB,EAAE;AAAA,MAC/E,CAAC;AACD;AAAA,IACF;AAEA,QAAI;AACF,YAAM,OAAO,MAAM,KAAK,mBAAmB,YAAY,IAAI,QAAQ,IAAI,IAAI;AAC3E,WAAK,KAAK,EAAE,MAAM,qBAAqB,OAAO,EAAE,WAAW,IAAI,WAAW,KAAK,EAAE,CAAC;AAAA,IACpF,SAAS,OAAO;AACd,WAAK,KAAK,EAAE,MAAM,qBAAqB,OAAO,EAAE,WAAW,IAAI,WAAW,MAAM,EAAE,CAAC;AAAA,IACrF;AAAA,EACF;AAAA,EAEA,MAAM,UAAU,MAAsB;AACpC,QAAI,KAAK,aAAa;AACpB,YAAM,MAAM,mCAAmC;AAAA,IACjD;AACA,QAAI,CAAC,KAAK,KAAK,MAAM;AACnB,YAAM,MAAM,yBAAyB;AAAA,IACvC;AACA,SAAK,aAAa,8BAAU;AAC5B,SAAK,cAAc;AAEnB,SAAK,KAAM,KAAK,EAAE,MAAM,mBAAmB,OAAO,EAAE,YAAY,KAAK,EAAE,CAAC;AAAA,EAC1E;AACF;","names":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import type { ChildProcess } from 'node:child_process';
|
|
3
|
+
import type { RunningJobInfo } from '../job.js';
|
|
4
|
+
import type { InferenceExecutor } from './inference_executor.js';
|
|
5
|
+
import type { JobExecutor } from './job_executor.js';
|
|
6
|
+
import { JobStatus } from './job_executor.js';
|
|
7
|
+
import { SupervisedProc } from './supervised_proc.js';
|
|
8
|
+
export declare class JobProcExecutor extends SupervisedProc implements JobExecutor {
|
|
9
|
+
#private;
|
|
10
|
+
constructor(agent: string, inferenceExecutor: InferenceExecutor | undefined, initializeTimeout: number, closeTimeout: number, memoryWarnMB: number, memoryLimitMB: number, pingInterval: number, pingTimeout: number, highPingThreshold: number);
|
|
11
|
+
get status(): JobStatus;
|
|
12
|
+
get userArguments(): any;
|
|
13
|
+
set userArguments(args: any);
|
|
14
|
+
get runningJob(): RunningJobInfo | undefined;
|
|
15
|
+
createProcess(): ChildProcess;
|
|
16
|
+
mainTask(proc: ChildProcess): Promise<void>;
|
|
17
|
+
launchJob(info: RunningJobInfo): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=job_proc_executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job_proc_executor.d.ts","sourceRoot":"","sources":["../../src/ipc/job_proc_executor.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,qBAAa,eAAgB,SAAQ,cAAe,YAAW,WAAW;;gBAUtE,KAAK,EAAE,MAAM,EACb,iBAAiB,EAAE,iBAAiB,GAAG,SAAS,EAChD,iBAAiB,EAAE,MAAM,EACzB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,iBAAiB,EAAE,MAAM;IAe3B,IAAI,MAAM,IAAI,SAAS,CAKtB;IAED,IAAI,aAAa,IAAI,GAAG,CAEvB;IAED,IAAI,aAAa,CAAC,IAAI,EAAE,GAAG,EAE1B;IAED,IAAI,UAAU,IAAI,cAAc,GAAG,SAAS,CAE3C;IAED,aAAa,IAAI,YAAY;IAIvB,QAAQ,CAAC,IAAI,EAAE,YAAY;IA8B3B,SAAS,CAAC,IAAI,EAAE,cAAc;CAYrC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { fork } from "node:child_process";
|
|
2
|
+
import { log } from "../log.js";
|
|
3
|
+
import { JobStatus } from "./job_executor.js";
|
|
4
|
+
import { SupervisedProc } from "./supervised_proc.js";
|
|
5
|
+
class JobProcExecutor extends SupervisedProc {
|
|
6
|
+
#userArgs;
|
|
7
|
+
#jobStatus;
|
|
8
|
+
#runningJob;
|
|
9
|
+
#agent;
|
|
10
|
+
#inferenceExecutor;
|
|
11
|
+
#inferenceTasks = [];
|
|
12
|
+
#logger = log();
|
|
13
|
+
constructor(agent, inferenceExecutor, initializeTimeout, closeTimeout, memoryWarnMB, memoryLimitMB, pingInterval, pingTimeout, highPingThreshold) {
|
|
14
|
+
super(
|
|
15
|
+
initializeTimeout,
|
|
16
|
+
closeTimeout,
|
|
17
|
+
memoryWarnMB,
|
|
18
|
+
memoryLimitMB,
|
|
19
|
+
pingInterval,
|
|
20
|
+
pingTimeout,
|
|
21
|
+
highPingThreshold
|
|
22
|
+
);
|
|
23
|
+
this.#agent = agent;
|
|
24
|
+
this.#inferenceExecutor = inferenceExecutor;
|
|
25
|
+
}
|
|
26
|
+
get status() {
|
|
27
|
+
if (this.#jobStatus) {
|
|
28
|
+
return this.#jobStatus;
|
|
29
|
+
}
|
|
30
|
+
throw new Error("job status not available");
|
|
31
|
+
}
|
|
32
|
+
get userArguments() {
|
|
33
|
+
return this.#userArgs;
|
|
34
|
+
}
|
|
35
|
+
set userArguments(args) {
|
|
36
|
+
this.#userArgs = args;
|
|
37
|
+
}
|
|
38
|
+
get runningJob() {
|
|
39
|
+
return this.#runningJob;
|
|
40
|
+
}
|
|
41
|
+
createProcess() {
|
|
42
|
+
return fork(new URL(import.meta.resolve("./job_proc_lazy_main.js")), [this.#agent]);
|
|
43
|
+
}
|
|
44
|
+
async mainTask(proc) {
|
|
45
|
+
proc.on("message", (msg) => {
|
|
46
|
+
switch (msg.case) {
|
|
47
|
+
case "inferenceRequest":
|
|
48
|
+
this.#inferenceTasks.push(this.#doInferenceTask(proc, msg.value));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async #doInferenceTask(proc, req) {
|
|
53
|
+
if (!this.#inferenceExecutor) {
|
|
54
|
+
this.#logger.warn("inference request received but no inference executor");
|
|
55
|
+
proc.send({
|
|
56
|
+
case: "inferenceResponse",
|
|
57
|
+
value: { requestId: req.requestId, error: new Error("no inference executor") }
|
|
58
|
+
});
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const data = await this.#inferenceExecutor.doInference(req.method, req.data);
|
|
63
|
+
proc.send({ case: "inferenceResponse", value: { requestId: req.requestId, data } });
|
|
64
|
+
} catch (error) {
|
|
65
|
+
proc.send({ case: "inferenceResponse", value: { requestId: req.requestId, error } });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async launchJob(info) {
|
|
69
|
+
if (this.#runningJob) {
|
|
70
|
+
throw Error("process already has a running job");
|
|
71
|
+
}
|
|
72
|
+
if (!this.init.done) {
|
|
73
|
+
throw Error("process not initialized");
|
|
74
|
+
}
|
|
75
|
+
this.#jobStatus = JobStatus.RUNNING;
|
|
76
|
+
this.#runningJob = info;
|
|
77
|
+
this.proc.send({ case: "startJobRequest", value: { runningJob: info } });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export {
|
|
81
|
+
JobProcExecutor
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=job_proc_executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/ipc/job_proc_executor.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { ChildProcess } from 'node:child_process';\nimport { fork } from 'node:child_process';\nimport type { RunningJobInfo } from '../job.js';\nimport { log } from '../log.js';\nimport type { InferenceExecutor } from './inference_executor.js';\nimport type { JobExecutor } from './job_executor.js';\nimport { JobStatus } from './job_executor.js';\nimport type { IPCMessage } from './message.js';\nimport { SupervisedProc } from './supervised_proc.js';\n\nexport class JobProcExecutor extends SupervisedProc implements JobExecutor {\n #userArgs?: any;\n #jobStatus?: JobStatus;\n #runningJob?: RunningJobInfo;\n #agent: string;\n #inferenceExecutor?: InferenceExecutor;\n #inferenceTasks: Promise<void>[] = [];\n #logger = log();\n\n constructor(\n agent: string,\n inferenceExecutor: InferenceExecutor | undefined,\n initializeTimeout: number,\n closeTimeout: number,\n memoryWarnMB: number,\n memoryLimitMB: number,\n pingInterval: number,\n pingTimeout: number,\n highPingThreshold: number,\n ) {\n super(\n initializeTimeout,\n closeTimeout,\n memoryWarnMB,\n memoryLimitMB,\n pingInterval,\n pingTimeout,\n highPingThreshold,\n );\n this.#agent = agent;\n this.#inferenceExecutor = inferenceExecutor;\n }\n\n get status(): JobStatus {\n if (this.#jobStatus) {\n return this.#jobStatus;\n }\n throw new Error('job status not available');\n }\n\n get userArguments(): any {\n return this.#userArgs;\n }\n\n set userArguments(args: any) {\n this.#userArgs = args;\n }\n\n get runningJob(): RunningJobInfo | undefined {\n return this.#runningJob;\n }\n\n createProcess(): ChildProcess {\n return fork(new URL(import.meta.resolve('./job_proc_lazy_main.js')), [this.#agent]);\n }\n\n async mainTask(proc: ChildProcess) {\n proc.on('message', (msg: IPCMessage) => {\n switch (msg.case) {\n case 'inferenceRequest':\n this.#inferenceTasks.push(this.#doInferenceTask(proc, msg.value));\n }\n });\n }\n\n async #doInferenceTask(\n proc: ChildProcess,\n req: { method: string; requestId: string; data: unknown },\n ) {\n if (!this.#inferenceExecutor) {\n this.#logger.warn('inference request received but no inference executor');\n proc.send({\n case: 'inferenceResponse',\n value: { requestId: req.requestId, error: new Error('no inference executor') },\n });\n return;\n }\n\n try {\n const data = await this.#inferenceExecutor.doInference(req.method, req.data);\n proc.send({ case: 'inferenceResponse', value: { requestId: req.requestId, data } });\n } catch (error) {\n proc.send({ case: 'inferenceResponse', value: { requestId: req.requestId, error } });\n }\n }\n\n async launchJob(info: RunningJobInfo) {\n if (this.#runningJob) {\n throw Error('process already has a running job');\n }\n if (!this.init.done) {\n throw Error('process not initialized');\n }\n this.#jobStatus = JobStatus.RUNNING;\n this.#runningJob = info;\n\n this.proc!.send({ case: 'startJobRequest', value: { runningJob: info } });\n }\n}\n"],"mappings":"AAIA,SAAS,YAAY;AAErB,SAAS,WAAW;AAGpB,SAAS,iBAAiB;AAE1B,SAAS,sBAAsB;AAExB,MAAM,wBAAwB,eAAsC;AAAA,EACzE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,kBAAmC,CAAC;AAAA,EACpC,UAAU,IAAI;AAAA,EAEd,YACE,OACA,mBACA,mBACA,cACA,cACA,eACA,cACA,aACA,mBACA;AACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AACA,SAAK,SAAS;AACd,SAAK,qBAAqB;AAAA,EAC5B;AAAA,EAEA,IAAI,SAAoB;AACtB,QAAI,KAAK,YAAY;AACnB,aAAO,KAAK;AAAA,IACd;AACA,UAAM,IAAI,MAAM,0BAA0B;AAAA,EAC5C;AAAA,EAEA,IAAI,gBAAqB;AACvB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,cAAc,MAAW;AAC3B,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,IAAI,aAAyC;AAC3C,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,gBAA8B;AAC5B,WAAO,KAAK,IAAI,IAAI,YAAY,QAAQ,yBAAyB,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC;AAAA,EACpF;AAAA,EAEA,MAAM,SAAS,MAAoB;AACjC,SAAK,GAAG,WAAW,CAAC,QAAoB;AACtC,cAAQ,IAAI,MAAM;AAAA,QAChB,KAAK;AACH,eAAK,gBAAgB,KAAK,KAAK,iBAAiB,MAAM,IAAI,KAAK,CAAC;AAAA,MACpE;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,iBACJ,MACA,KACA;AACA,QAAI,CAAC,KAAK,oBAAoB;AAC5B,WAAK,QAAQ,KAAK,sDAAsD;AACxE,WAAK,KAAK;AAAA,QACR,MAAM;AAAA,QACN,OAAO,EAAE,WAAW,IAAI,WAAW,OAAO,IAAI,MAAM,uBAAuB,EAAE;AAAA,MAC/E,CAAC;AACD;AAAA,IACF;AAEA,QAAI;AACF,YAAM,OAAO,MAAM,KAAK,mBAAmB,YAAY,IAAI,QAAQ,IAAI,IAAI;AAC3E,WAAK,KAAK,EAAE,MAAM,qBAAqB,OAAO,EAAE,WAAW,IAAI,WAAW,KAAK,EAAE,CAAC;AAAA,IACpF,SAAS,OAAO;AACd,WAAK,KAAK,EAAE,MAAM,qBAAqB,OAAO,EAAE,WAAW,IAAI,WAAW,MAAM,EAAE,CAAC;AAAA,IACrF;AAAA,EACF;AAAA,EAEA,MAAM,UAAU,MAAsB;AACpC,QAAI,KAAK,aAAa;AACpB,YAAM,MAAM,mCAAmC;AAAA,IACjD;AACA,QAAI,CAAC,KAAK,KAAK,MAAM;AACnB,YAAM,MAAM,yBAAyB;AAAA,IACvC;AACA,SAAK,aAAa,UAAU;AAC5B,SAAK,cAAc;AAEnB,SAAK,KAAM,KAAK,EAAE,MAAM,mBAAmB,OAAO,EAAE,YAAY,KAAK,EAAE,CAAC;AAAA,EAC1E;AACF;","names":[]}
|
|
@@ -1,41 +1,49 @@
|
|
|
1
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_main_exports = {};
|
|
20
|
-
__export(job_main_exports, {
|
|
21
|
-
runProcess: () => runProcess
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(job_main_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
2
|
var import_rtc_node = require("@livekit/rtc-node");
|
|
27
|
-
var
|
|
3
|
+
var import_node_crypto = require("node:crypto");
|
|
28
4
|
var import_node_events = require("node:events");
|
|
29
5
|
var import_node_url = require("node:url");
|
|
30
6
|
var import_generator = require("../generator.cjs");
|
|
31
7
|
var import_job = require("../job.cjs");
|
|
32
|
-
var import_job2 = require("../job.cjs");
|
|
33
8
|
var import_log = require("../log.cjs");
|
|
34
9
|
var import_worker = require("../worker.cjs");
|
|
35
10
|
const ORPHANED_TIMEOUT = 15 * 1e3;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
11
|
+
class PendingInference {
|
|
12
|
+
promise = new Promise((resolve) => {
|
|
13
|
+
this.resolve = resolve;
|
|
14
|
+
});
|
|
15
|
+
resolve(arg) {
|
|
16
|
+
arg;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
class InfClient {
|
|
20
|
+
#requests = {};
|
|
21
|
+
constructor() {
|
|
22
|
+
process.on("message", (msg) => {
|
|
23
|
+
switch (msg.case) {
|
|
24
|
+
case "inferenceResponse":
|
|
25
|
+
const fut = this.#requests[msg.value.requestId];
|
|
26
|
+
delete this.#requests[msg.value.requestId];
|
|
27
|
+
if (!fut) {
|
|
28
|
+
(0, import_log.log)().child({ resp: msg.value }).warn("received unexpected inference response");
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
fut.resolve(msg.value);
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async doInference(method, data) {
|
|
37
|
+
const requestId = "inference_job_" + import_node_crypto.randomUUID;
|
|
38
|
+
process.send({ case: "inferenceRequest", value: { requestId, method, data } });
|
|
39
|
+
this.#requests[requestId] = new PendingInference();
|
|
40
|
+
const resp = await this.#requests[requestId].promise;
|
|
41
|
+
if (resp.error) {
|
|
42
|
+
throw new Error(`inference of ${method} failed: ${resp.error.message}`);
|
|
43
|
+
}
|
|
44
|
+
return resp.data;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
39
47
|
const startJob = (proc, func, info, closeEvent, logger) => {
|
|
40
48
|
let connect = false;
|
|
41
49
|
let shutdown = false;
|
|
@@ -50,7 +58,8 @@ const startJob = (proc, func, info, closeEvent, logger) => {
|
|
|
50
58
|
shutdown = true;
|
|
51
59
|
closeEvent.emit("close", true, reason);
|
|
52
60
|
};
|
|
53
|
-
const ctx = new import_job.JobContext(proc, info, room, onConnect, onShutdown);
|
|
61
|
+
const ctx = new import_job.JobContext(proc, info, room, onConnect, onShutdown, new InfClient());
|
|
62
|
+
new import_job.CurrentJobContext(ctx);
|
|
54
63
|
const task = new Promise(async () => {
|
|
55
64
|
const unconnectedTimeout = setTimeout(() => {
|
|
56
65
|
if (!(connect || shutdown)) {
|
|
@@ -99,7 +108,7 @@ const startJob = (proc, func, info, closeEvent, logger) => {
|
|
|
99
108
|
}
|
|
100
109
|
(0, import_log.initializeLogger)(msg.value.loggerOptions);
|
|
101
110
|
});
|
|
102
|
-
const proc = new
|
|
111
|
+
const proc = new import_job.JobProcess();
|
|
103
112
|
let logger = (0, import_log.log)().child({ pid: proc.pid });
|
|
104
113
|
logger.debug("initializing job runner");
|
|
105
114
|
agent.prewarm(proc);
|
|
@@ -140,8 +149,4 @@ const startJob = (proc, func, info, closeEvent, logger) => {
|
|
|
140
149
|
});
|
|
141
150
|
}
|
|
142
151
|
})();
|
|
143
|
-
|
|
144
|
-
0 && (module.exports = {
|
|
145
|
-
runProcess
|
|
146
|
-
});
|
|
147
|
-
//# sourceMappingURL=job_main.cjs.map
|
|
152
|
+
//# sourceMappingURL=job_proc_lazy_main.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/ipc/job_proc_lazy_main.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { Room, RoomEvent } from '@livekit/rtc-node';\nimport { randomUUID } from 'node:crypto';\nimport { EventEmitter, once } from 'node:events';\nimport { pathToFileURL } from 'node:url';\nimport type { Logger } from 'pino';\nimport { type Agent, isAgent } from '../generator.js';\nimport { CurrentJobContext, JobContext, JobProcess, type RunningJobInfo } from '../job.js';\nimport { initializeLogger, log } from '../log.js';\nimport { defaultInitializeProcessFunc } from '../worker.js';\nimport type { InferenceExecutor } from './inference_executor.js';\nimport type { IPCMessage } from './message.js';\n\nconst ORPHANED_TIMEOUT = 15 * 1000;\n\ntype JobTask = {\n ctx: JobContext;\n task: Promise<void>;\n};\n\nclass PendingInference {\n promise = new Promise<{ requestId: string; data: unknown; error?: Error }>((resolve) => {\n this.resolve = resolve; // this is how JavaScript lets you resolve promises externally\n });\n resolve(arg: { requestId: string; data: unknown; error?: Error }) {\n arg; // useless call to counteract TypeScript E6133\n }\n}\n\nclass InfClient implements InferenceExecutor {\n #requests: { [id: string]: PendingInference } = {};\n\n constructor() {\n process.on('message', (msg: IPCMessage) => {\n switch (msg.case) {\n case 'inferenceResponse':\n const fut = this.#requests[msg.value.requestId];\n delete this.#requests[msg.value.requestId];\n if (!fut) {\n log().child({ resp: msg.value }).warn('received unexpected inference response');\n return;\n }\n fut.resolve(msg.value);\n break;\n }\n });\n }\n\n async doInference(method: string, data: unknown): Promise<unknown> {\n const requestId = 'inference_job_' + randomUUID;\n process.send!({ case: 'inferenceRequest', value: { requestId, method, data } });\n this.#requests[requestId] = new PendingInference();\n const resp = await this.#requests[requestId]!.promise;\n if (resp.error) {\n throw new Error(`inference of ${method} failed: ${resp.error.message}`);\n }\n return resp.data;\n }\n}\n\nconst startJob = (\n proc: JobProcess,\n func: (ctx: JobContext) => Promise<void>,\n info: RunningJobInfo,\n closeEvent: EventEmitter,\n logger: Logger,\n): JobTask => {\n let connect = false;\n let shutdown = false;\n\n const room = new Room();\n room.on(RoomEvent.Disconnected, () => {\n closeEvent.emit('close', false);\n });\n\n const onConnect = () => {\n connect = true;\n };\n const onShutdown = (reason: string) => {\n shutdown = true;\n closeEvent.emit('close', true, reason);\n };\n\n const ctx = new JobContext(proc, info, room, onConnect, onShutdown, new InfClient());\n new CurrentJobContext(ctx);\n\n const task = new Promise<void>(async () => {\n const unconnectedTimeout = setTimeout(() => {\n if (!(connect || shutdown)) {\n logger.warn(\n 'room not connect after job_entry was called after 10 seconds, ',\n 'did you forget to call ctx.connect()?',\n );\n }\n }, 10000);\n func(ctx).finally(() => clearTimeout(unconnectedTimeout));\n\n await once(closeEvent, 'close').then((close) => {\n logger.debug('shutting down');\n process.send!({ case: 'exiting', value: { reason: close[1] } });\n });\n\n await room.disconnect();\n logger.debug('disconnected from room');\n\n const shutdownTasks = [];\n for (const callback of ctx.shutdownCallbacks) {\n shutdownTasks.push(callback());\n }\n await Promise.all(shutdownTasks).catch(() => logger.error('error while shutting down the job'));\n\n process.send!({ case: 'done' });\n process.exit();\n });\n\n return { ctx, task };\n};\n\n(async () => {\n if (process.send) {\n // process.argv:\n // [0] `node'\n // [1] import.meta.filename\n // [2] import.meta.filename of function containing entry file\n const moduleFile = process.argv[2];\n const agent: Agent = await import(pathToFileURL(moduleFile!).pathname).then((module) => {\n const agent = module.default;\n if (agent === undefined || !isAgent(agent)) {\n throw new Error(`Unable to load agent: Missing or invalid default export in ${moduleFile}`);\n }\n return agent;\n });\n if (!agent.prewarm) {\n agent.prewarm = defaultInitializeProcessFunc;\n }\n\n // don't do anything on C-c\n // this is handled in cli, triggering a termination of all child processes at once.\n process.on('SIGINT', () => {});\n\n await once(process, 'message').then(([msg]: IPCMessage[]) => {\n msg = msg!;\n if (msg.case !== 'initializeRequest') {\n throw new Error('first message must be InitializeRequest');\n }\n initializeLogger(msg.value.loggerOptions);\n });\n const proc = new JobProcess();\n let logger = log().child({ pid: proc.pid });\n\n logger.debug('initializing job runner');\n agent.prewarm(proc);\n logger.debug('job runner initialized');\n process.send({ case: 'initializeResponse' });\n\n let job: JobTask | undefined = undefined;\n const closeEvent = new EventEmitter();\n\n const orphanedTimeout = setTimeout(() => {\n logger.warn('process orphaned, shutting down');\n process.exit();\n }, ORPHANED_TIMEOUT);\n\n process.on('message', (msg: IPCMessage) => {\n switch (msg.case) {\n case 'pingRequest': {\n orphanedTimeout.refresh();\n process.send!({\n case: 'pongResponse',\n value: { lastTimestamp: msg.value.timestamp, timestamp: Date.now() },\n });\n break;\n }\n case 'startJobRequest': {\n if (job) {\n throw new Error('job task already running');\n }\n\n logger = logger.child({ jobID: msg.value.runningJob.job.id });\n\n job = startJob(proc, agent.entry, msg.value.runningJob, closeEvent, logger);\n logger.debug('job started');\n break;\n }\n case 'shutdownRequest': {\n if (!job) {\n break;\n }\n closeEvent.emit('close', '');\n }\n }\n });\n }\n})();\n"],"mappings":";AAGA,sBAAgC;AAChC,yBAA2B;AAC3B,yBAAmC;AACnC,sBAA8B;AAE9B,uBAAoC;AACpC,iBAA+E;AAC/E,iBAAsC;AACtC,oBAA6C;AAI7C,MAAM,mBAAmB,KAA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,aAAa;AAC1B;AAAA,QACF;AAAA,QACA,KAAK,mBAAmB;AACtB,cAAI,CAAC,KAAK;AACR;AAAA,UACF;AACA,qBAAW,KAAK,SAAS,EAAE;AAAA,QAC7B;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF,GAAG;","names":["module","agent"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job_proc_lazy_main.d.ts","sourceRoot":"","sources":["../../src/ipc/job_proc_lazy_main.ts"],"names":[],"mappings":""}
|
|
@@ -1,16 +1,48 @@
|
|
|
1
1
|
import { Room, RoomEvent } from "@livekit/rtc-node";
|
|
2
|
-
import {
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { EventEmitter, once } from "node:events";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
import { isAgent } from "../generator.js";
|
|
6
|
-
import { JobContext } from "../job.js";
|
|
7
|
-
import { JobProcess } from "../job.js";
|
|
6
|
+
import { CurrentJobContext, JobContext, JobProcess } from "../job.js";
|
|
8
7
|
import { initializeLogger, log } from "../log.js";
|
|
9
8
|
import { defaultInitializeProcessFunc } from "../worker.js";
|
|
10
9
|
const ORPHANED_TIMEOUT = 15 * 1e3;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
class PendingInference {
|
|
11
|
+
promise = new Promise((resolve) => {
|
|
12
|
+
this.resolve = resolve;
|
|
13
|
+
});
|
|
14
|
+
resolve(arg) {
|
|
15
|
+
arg;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
class InfClient {
|
|
19
|
+
#requests = {};
|
|
20
|
+
constructor() {
|
|
21
|
+
process.on("message", (msg) => {
|
|
22
|
+
switch (msg.case) {
|
|
23
|
+
case "inferenceResponse":
|
|
24
|
+
const fut = this.#requests[msg.value.requestId];
|
|
25
|
+
delete this.#requests[msg.value.requestId];
|
|
26
|
+
if (!fut) {
|
|
27
|
+
log().child({ resp: msg.value }).warn("received unexpected inference response");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
fut.resolve(msg.value);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
async doInference(method, data) {
|
|
36
|
+
const requestId = "inference_job_" + randomUUID;
|
|
37
|
+
process.send({ case: "inferenceRequest", value: { requestId, method, data } });
|
|
38
|
+
this.#requests[requestId] = new PendingInference();
|
|
39
|
+
const resp = await this.#requests[requestId].promise;
|
|
40
|
+
if (resp.error) {
|
|
41
|
+
throw new Error(`inference of ${method} failed: ${resp.error.message}`);
|
|
42
|
+
}
|
|
43
|
+
return resp.data;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
14
46
|
const startJob = (proc, func, info, closeEvent, logger) => {
|
|
15
47
|
let connect = false;
|
|
16
48
|
let shutdown = false;
|
|
@@ -25,7 +57,8 @@ const startJob = (proc, func, info, closeEvent, logger) => {
|
|
|
25
57
|
shutdown = true;
|
|
26
58
|
closeEvent.emit("close", true, reason);
|
|
27
59
|
};
|
|
28
|
-
const ctx = new JobContext(proc, info, room, onConnect, onShutdown);
|
|
60
|
+
const ctx = new JobContext(proc, info, room, onConnect, onShutdown, new InfClient());
|
|
61
|
+
new CurrentJobContext(ctx);
|
|
29
62
|
const task = new Promise(async () => {
|
|
30
63
|
const unconnectedTimeout = setTimeout(() => {
|
|
31
64
|
if (!(connect || shutdown)) {
|
|
@@ -115,7 +148,4 @@ const startJob = (proc, func, info, closeEvent, logger) => {
|
|
|
115
148
|
});
|
|
116
149
|
}
|
|
117
150
|
})();
|
|
118
|
-
|
|
119
|
-
runProcess
|
|
120
|
-
};
|
|
121
|
-
//# sourceMappingURL=job_main.js.map
|
|
151
|
+
//# sourceMappingURL=job_proc_lazy_main.js.map
|