@livekit/agents 0.6.4 → 0.7.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/dist/cli.cjs +8 -0
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +8 -0
- package/dist/cli.js.map +1 -1
- 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 +92 -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 +69 -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} +46 -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} +46 -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 +18 -16
- 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 +18 -16
- 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 +22 -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 +22 -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/cli.ts +9 -0
- 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 +90 -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} +52 -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 +19 -18
- package/src/multimodal/multimodal_agent.ts +13 -9
- package/src/pipeline/agent_output.ts +36 -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,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var import_node_events = __toESM(require("node:events"), 1);
|
|
25
|
+
var import_log = require("../log.cjs");
|
|
26
|
+
const ORPHANED_TIMEOUT = 15 * 1e3;
|
|
27
|
+
(async () => {
|
|
28
|
+
if (process.send) {
|
|
29
|
+
process.on("SIGINT", () => {
|
|
30
|
+
});
|
|
31
|
+
process.on("SIGTERM", () => {
|
|
32
|
+
});
|
|
33
|
+
await (0, import_node_events.once)(process, "message").then(([msg]) => {
|
|
34
|
+
msg = msg;
|
|
35
|
+
if (msg.case !== "initializeRequest") {
|
|
36
|
+
throw new Error("first message must be InitializeRequest");
|
|
37
|
+
}
|
|
38
|
+
(0, import_log.initializeLogger)(msg.value.loggerOptions);
|
|
39
|
+
});
|
|
40
|
+
const logger = (0, import_log.log)().child({ pid: process.pid });
|
|
41
|
+
const runners = await Promise.all(
|
|
42
|
+
Object.entries(JSON.parse(process.argv[2])).map(async ([k, v]) => {
|
|
43
|
+
return [k, await import(v).then((m) => new m.default())];
|
|
44
|
+
})
|
|
45
|
+
).then(Object.fromEntries);
|
|
46
|
+
await Promise.all(
|
|
47
|
+
Object.entries(runners).map(async ([runner, v]) => {
|
|
48
|
+
logger.child({ runner }).debug("initializing inference runner");
|
|
49
|
+
await v.initialize();
|
|
50
|
+
})
|
|
51
|
+
);
|
|
52
|
+
logger.debug("all inference runners initialized");
|
|
53
|
+
process.send({ case: "initializeResponse" });
|
|
54
|
+
const closeEvent = new import_node_events.default();
|
|
55
|
+
const orphanedTimeout = setTimeout(() => {
|
|
56
|
+
logger.warn("process orphaned, shutting down");
|
|
57
|
+
process.exit();
|
|
58
|
+
}, ORPHANED_TIMEOUT);
|
|
59
|
+
const handleInferenceRequest = async ({
|
|
60
|
+
method,
|
|
61
|
+
requestId,
|
|
62
|
+
data
|
|
63
|
+
}) => {
|
|
64
|
+
if (!runners[method]) {
|
|
65
|
+
logger.child({ method }).warn("unknown inference method");
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
const resp = await runners[method].run(data);
|
|
69
|
+
process.send({ case: "inferenceResponse", value: { requestId, data: resp } });
|
|
70
|
+
} catch (error) {
|
|
71
|
+
process.send({ case: "inferenceResponse", value: { requestId, error } });
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
process.on("message", (msg) => {
|
|
75
|
+
switch (msg.case) {
|
|
76
|
+
case "pingRequest":
|
|
77
|
+
orphanedTimeout.refresh();
|
|
78
|
+
process.send({
|
|
79
|
+
case: "pongResponse",
|
|
80
|
+
value: { lastTimestamp: msg.value.timestamp, timestamp: Date.now() }
|
|
81
|
+
});
|
|
82
|
+
break;
|
|
83
|
+
case "shutdownRequest":
|
|
84
|
+
closeEvent.emit("close");
|
|
85
|
+
break;
|
|
86
|
+
case "inferenceRequest":
|
|
87
|
+
handleInferenceRequest(msg.value);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
})();
|
|
92
|
+
//# sourceMappingURL=inference_proc_lazy_main.cjs.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 // don't do anything on SIGTERM\n // Render uses SIGTERM in autoscale, this ensures the processes are properly drained if needed\n process.on('SIGTERM', () => {});\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 }\n})();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGA,yBAAmC;AAEnC,iBAAsC;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F,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":["EventEmitter"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inference_proc_lazy_main.d.ts","sourceRoot":"","sources":["../../src/ipc/inference_proc_lazy_main.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
process.on("SIGTERM", () => {
|
|
9
|
+
});
|
|
10
|
+
await once(process, "message").then(([msg]) => {
|
|
11
|
+
msg = msg;
|
|
12
|
+
if (msg.case !== "initializeRequest") {
|
|
13
|
+
throw new Error("first message must be InitializeRequest");
|
|
14
|
+
}
|
|
15
|
+
initializeLogger(msg.value.loggerOptions);
|
|
16
|
+
});
|
|
17
|
+
const logger = log().child({ pid: process.pid });
|
|
18
|
+
const runners = await Promise.all(
|
|
19
|
+
Object.entries(JSON.parse(process.argv[2])).map(async ([k, v]) => {
|
|
20
|
+
return [k, await import(v).then((m) => new m.default())];
|
|
21
|
+
})
|
|
22
|
+
).then(Object.fromEntries);
|
|
23
|
+
await Promise.all(
|
|
24
|
+
Object.entries(runners).map(async ([runner, v]) => {
|
|
25
|
+
logger.child({ runner }).debug("initializing inference runner");
|
|
26
|
+
await v.initialize();
|
|
27
|
+
})
|
|
28
|
+
);
|
|
29
|
+
logger.debug("all inference runners initialized");
|
|
30
|
+
process.send({ case: "initializeResponse" });
|
|
31
|
+
const closeEvent = new EventEmitter();
|
|
32
|
+
const orphanedTimeout = setTimeout(() => {
|
|
33
|
+
logger.warn("process orphaned, shutting down");
|
|
34
|
+
process.exit();
|
|
35
|
+
}, ORPHANED_TIMEOUT);
|
|
36
|
+
const handleInferenceRequest = async ({
|
|
37
|
+
method,
|
|
38
|
+
requestId,
|
|
39
|
+
data
|
|
40
|
+
}) => {
|
|
41
|
+
if (!runners[method]) {
|
|
42
|
+
logger.child({ method }).warn("unknown inference method");
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const resp = await runners[method].run(data);
|
|
46
|
+
process.send({ case: "inferenceResponse", value: { requestId, data: resp } });
|
|
47
|
+
} catch (error) {
|
|
48
|
+
process.send({ case: "inferenceResponse", value: { requestId, error } });
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
process.on("message", (msg) => {
|
|
52
|
+
switch (msg.case) {
|
|
53
|
+
case "pingRequest":
|
|
54
|
+
orphanedTimeout.refresh();
|
|
55
|
+
process.send({
|
|
56
|
+
case: "pongResponse",
|
|
57
|
+
value: { lastTimestamp: msg.value.timestamp, timestamp: Date.now() }
|
|
58
|
+
});
|
|
59
|
+
break;
|
|
60
|
+
case "shutdownRequest":
|
|
61
|
+
closeEvent.emit("close");
|
|
62
|
+
break;
|
|
63
|
+
case "inferenceRequest":
|
|
64
|
+
handleInferenceRequest(msg.value);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
})();
|
|
69
|
+
//# 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 // don't do anything on SIGTERM\n // Render uses SIGTERM in autoscale, this ensures the processes are properly drained if needed\n process.on('SIGTERM', () => {});\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 }\n})();\n"],"mappings":"AAGA,OAAO,gBAAgB,YAAY;AAEnC,SAAS,kBAAkB,WAAW;AAGtC,MAAM,mBAAmB,KAAK;AAAA,CAE7B,YAAY;AACX,MAAI,QAAQ,MAAM;AAGhB,YAAQ,GAAG,UAAU,MAAM;AAAA,IAAC,CAAC;AAI7B,YAAQ,GAAG,WAAW,MAAM;AAAA,IAAC,CAAC;AAE9B,UAAM,KAAK,SAAS,SAAS,EAAE,KAAK,CAAC,CAAC,GAAG,MAAoB;AAC3D,YAAM;AACN,UAAI,IAAI,SAAS,qBAAqB;AACpC,cAAM,IAAI,MAAM,yCAAyC;AAAA,MAC3D;AACA,uBAAiB,IAAI,MAAM,aAAa;AAAA,IAC1C,CAAC;AACD,UAAM,SAAS,IAAI,EAAE,MAAM,EAAE,KAAK,QAAQ,IAAI,CAAC;AAE/C,UAAM,UAA6C,MAAM,QAAQ;AAAA,MAC/D,OAAO,QAAQ,KAAK,MAAM,QAAQ,KAAK,CAAC,CAAE,CAAC,EAAE,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM;AACjE,eAAO,CAAC,GAAG,MAAM,OAAO,GAAa,KAAK,CAAC,MAAM,IAAI,EA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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: 'startJobRequest', value: { runningJob: info } });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,gCAAqB;AAErB,iBAAoB;AAGpB,0BAA0B;AAE1B,6BAA+B;AAX/B;AAaO,MAAM,wBAAwB,sCAAsC;AAAA,EACzE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,kBAAmC,CAAC;AAAA,EACpC,cAAU,gBAAI;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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AAM,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,qBAAq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