@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.
Files changed (178) hide show
  1. package/dist/index.cjs +6 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.ts +3 -1
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +3 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/inference_runner.cjs +38 -0
  8. package/dist/inference_runner.cjs.map +1 -0
  9. package/dist/inference_runner.d.ts +11 -0
  10. package/dist/inference_runner.d.ts.map +1 -0
  11. package/dist/inference_runner.js +14 -0
  12. package/dist/inference_runner.js.map +1 -0
  13. package/dist/ipc/index.cjs +23 -0
  14. package/dist/ipc/index.cjs.map +1 -0
  15. package/dist/ipc/index.d.ts +2 -0
  16. package/dist/ipc/index.d.ts.map +1 -0
  17. package/dist/ipc/index.js +2 -0
  18. package/dist/ipc/index.js.map +1 -0
  19. package/dist/ipc/inference_executor.cjs +17 -0
  20. package/dist/ipc/inference_executor.cjs.map +1 -0
  21. package/dist/ipc/inference_executor.d.ts +4 -0
  22. package/dist/ipc/inference_executor.d.ts.map +1 -0
  23. package/dist/ipc/inference_executor.js +1 -0
  24. package/dist/ipc/inference_executor.js.map +1 -0
  25. package/dist/ipc/inference_proc_executor.cjs +97 -0
  26. package/dist/ipc/inference_proc_executor.cjs.map +1 -0
  27. package/dist/ipc/inference_proc_executor.d.ts +23 -0
  28. package/dist/ipc/inference_proc_executor.d.ts.map +1 -0
  29. package/dist/ipc/inference_proc_executor.js +72 -0
  30. package/dist/ipc/inference_proc_executor.js.map +1 -0
  31. package/dist/ipc/inference_proc_lazy_main.cjs +90 -0
  32. package/dist/ipc/inference_proc_lazy_main.cjs.map +1 -0
  33. package/dist/ipc/inference_proc_lazy_main.d.ts +2 -0
  34. package/dist/ipc/inference_proc_lazy_main.d.ts.map +1 -0
  35. package/dist/ipc/inference_proc_lazy_main.js +67 -0
  36. package/dist/ipc/inference_proc_lazy_main.js.map +1 -0
  37. package/dist/ipc/job_executor.cjs +8 -7
  38. package/dist/ipc/job_executor.cjs.map +1 -1
  39. package/dist/ipc/job_executor.d.ts +14 -15
  40. package/dist/ipc/job_executor.d.ts.map +1 -1
  41. package/dist/ipc/job_executor.js +7 -6
  42. package/dist/ipc/job_executor.js.map +1 -1
  43. package/dist/ipc/job_proc_executor.cjs +108 -0
  44. package/dist/ipc/job_proc_executor.cjs.map +1 -0
  45. package/dist/ipc/job_proc_executor.d.ts +19 -0
  46. package/dist/ipc/job_proc_executor.d.ts.map +1 -0
  47. package/dist/ipc/job_proc_executor.js +83 -0
  48. package/dist/ipc/job_proc_executor.js.map +1 -0
  49. package/dist/ipc/{job_main.cjs → job_proc_lazy_main.cjs} +41 -36
  50. package/dist/ipc/job_proc_lazy_main.cjs.map +1 -0
  51. package/dist/ipc/job_proc_lazy_main.d.ts +2 -0
  52. package/dist/ipc/job_proc_lazy_main.d.ts.map +1 -0
  53. package/dist/ipc/{job_main.js → job_proc_lazy_main.js} +41 -11
  54. package/dist/ipc/job_proc_lazy_main.js.map +1 -0
  55. package/dist/ipc/message.cjs.map +1 -1
  56. package/dist/ipc/message.d.ts +17 -0
  57. package/dist/ipc/message.d.ts.map +1 -1
  58. package/dist/ipc/proc_pool.cjs +30 -4
  59. package/dist/ipc/proc_pool.cjs.map +1 -1
  60. package/dist/ipc/proc_pool.d.ts +5 -1
  61. package/dist/ipc/proc_pool.d.ts.map +1 -1
  62. package/dist/ipc/proc_pool.js +30 -4
  63. package/dist/ipc/proc_pool.js.map +1 -1
  64. package/dist/ipc/{proc_job_executor.cjs → supervised_proc.cjs} +57 -45
  65. package/dist/ipc/supervised_proc.cjs.map +1 -0
  66. package/dist/ipc/supervised_proc.d.ts +30 -0
  67. package/dist/ipc/supervised_proc.d.ts.map +1 -0
  68. package/dist/ipc/{proc_job_executor.js → supervised_proc.js} +53 -31
  69. package/dist/ipc/supervised_proc.js.map +1 -0
  70. package/dist/job.cjs +18 -1
  71. package/dist/job.cjs.map +1 -1
  72. package/dist/job.d.ts +9 -1
  73. package/dist/job.d.ts.map +1 -1
  74. package/dist/job.js +17 -1
  75. package/dist/job.js.map +1 -1
  76. package/dist/multimodal/agent_playout.cjs +13 -14
  77. package/dist/multimodal/agent_playout.cjs.map +1 -1
  78. package/dist/multimodal/agent_playout.d.ts +4 -4
  79. package/dist/multimodal/agent_playout.d.ts.map +1 -1
  80. package/dist/multimodal/agent_playout.js +13 -14
  81. package/dist/multimodal/agent_playout.js.map +1 -1
  82. package/dist/multimodal/multimodal_agent.cjs +12 -8
  83. package/dist/multimodal/multimodal_agent.cjs.map +1 -1
  84. package/dist/multimodal/multimodal_agent.d.ts.map +1 -1
  85. package/dist/multimodal/multimodal_agent.js +13 -9
  86. package/dist/multimodal/multimodal_agent.js.map +1 -1
  87. package/dist/pipeline/agent_output.cjs +20 -4
  88. package/dist/pipeline/agent_output.cjs.map +1 -1
  89. package/dist/pipeline/agent_output.d.ts +4 -2
  90. package/dist/pipeline/agent_output.d.ts.map +1 -1
  91. package/dist/pipeline/agent_output.js +20 -4
  92. package/dist/pipeline/agent_output.js.map +1 -1
  93. package/dist/pipeline/agent_playout.cjs +9 -3
  94. package/dist/pipeline/agent_playout.cjs.map +1 -1
  95. package/dist/pipeline/agent_playout.d.ts +4 -2
  96. package/dist/pipeline/agent_playout.d.ts.map +1 -1
  97. package/dist/pipeline/agent_playout.js +9 -3
  98. package/dist/pipeline/agent_playout.js.map +1 -1
  99. package/dist/pipeline/human_input.cjs +6 -0
  100. package/dist/pipeline/human_input.cjs.map +1 -1
  101. package/dist/pipeline/human_input.d.ts +3 -1
  102. package/dist/pipeline/human_input.d.ts.map +1 -1
  103. package/dist/pipeline/human_input.js +6 -0
  104. package/dist/pipeline/human_input.js.map +1 -1
  105. package/dist/pipeline/pipeline_agent.cjs +79 -12
  106. package/dist/pipeline/pipeline_agent.cjs.map +1 -1
  107. package/dist/pipeline/pipeline_agent.d.ts +8 -0
  108. package/dist/pipeline/pipeline_agent.d.ts.map +1 -1
  109. package/dist/pipeline/pipeline_agent.js +79 -12
  110. package/dist/pipeline/pipeline_agent.js.map +1 -1
  111. package/dist/stt/stream_adapter.cjs +16 -4
  112. package/dist/stt/stream_adapter.cjs.map +1 -1
  113. package/dist/stt/stream_adapter.d.ts.map +1 -1
  114. package/dist/stt/stream_adapter.js +16 -4
  115. package/dist/stt/stream_adapter.js.map +1 -1
  116. package/dist/tokenize/basic/basic.cjs +2 -0
  117. package/dist/tokenize/basic/basic.cjs.map +1 -1
  118. package/dist/tokenize/basic/basic.d.ts +2 -0
  119. package/dist/tokenize/basic/basic.d.ts.map +1 -1
  120. package/dist/tokenize/basic/basic.js +1 -0
  121. package/dist/tokenize/basic/basic.js.map +1 -1
  122. package/dist/tokenize/basic/index.cjs +2 -0
  123. package/dist/tokenize/basic/index.cjs.map +1 -1
  124. package/dist/tokenize/basic/index.d.ts +1 -1
  125. package/dist/tokenize/basic/index.d.ts.map +1 -1
  126. package/dist/tokenize/basic/index.js +8 -1
  127. package/dist/tokenize/basic/index.js.map +1 -1
  128. package/dist/tokenize/token_stream.cjs +5 -3
  129. package/dist/tokenize/token_stream.cjs.map +1 -1
  130. package/dist/tokenize/token_stream.d.ts.map +1 -1
  131. package/dist/tokenize/token_stream.js +5 -3
  132. package/dist/tokenize/token_stream.js.map +1 -1
  133. package/dist/transcription.cjs +203 -86
  134. package/dist/transcription.cjs.map +1 -1
  135. package/dist/transcription.d.ts +24 -17
  136. package/dist/transcription.d.ts.map +1 -1
  137. package/dist/transcription.js +201 -85
  138. package/dist/transcription.js.map +1 -1
  139. package/dist/worker.cjs +42 -9
  140. package/dist/worker.cjs.map +1 -1
  141. package/dist/worker.d.ts +5 -1
  142. package/dist/worker.d.ts.map +1 -1
  143. package/dist/worker.js +42 -9
  144. package/dist/worker.js.map +1 -1
  145. package/package.json +3 -3
  146. package/src/index.ts +3 -1
  147. package/src/inference_runner.ts +19 -0
  148. package/src/ipc/index.ts +5 -0
  149. package/src/ipc/inference_executor.ts +7 -0
  150. package/src/ipc/inference_proc_executor.ts +93 -0
  151. package/src/ipc/inference_proc_lazy_main.ts +86 -0
  152. package/src/ipc/job_executor.ts +15 -17
  153. package/src/ipc/job_proc_executor.ts +112 -0
  154. package/src/ipc/{job_main.ts → job_proc_lazy_main.ts} +44 -14
  155. package/src/ipc/message.ts +14 -1
  156. package/src/ipc/proc_pool.ts +33 -3
  157. package/src/ipc/{proc_job_executor.ts → supervised_proc.ts} +77 -29
  158. package/src/job.ts +21 -0
  159. package/src/multimodal/agent_playout.ts +14 -16
  160. package/src/multimodal/multimodal_agent.ts +13 -9
  161. package/src/pipeline/agent_output.ts +34 -5
  162. package/src/pipeline/agent_playout.ts +10 -1
  163. package/src/pipeline/human_input.ts +8 -0
  164. package/src/pipeline/pipeline_agent.ts +96 -11
  165. package/src/stt/stream_adapter.ts +17 -5
  166. package/src/tokenize/basic/basic.ts +2 -0
  167. package/src/tokenize/basic/index.ts +7 -1
  168. package/src/tokenize/token_stream.ts +6 -3
  169. package/src/transcription.ts +270 -96
  170. package/src/worker.ts +42 -5
  171. package/dist/ipc/job_main.cjs.map +0 -1
  172. package/dist/ipc/job_main.d.ts +0 -8
  173. package/dist/ipc/job_main.d.ts.map +0 -1
  174. package/dist/ipc/job_main.js.map +0 -1
  175. package/dist/ipc/proc_job_executor.cjs.map +0 -1
  176. package/dist/ipc/proc_job_executor.d.ts +0 -15
  177. package/dist/ipc/proc_job_executor.d.ts.map +0 -1
  178. package/dist/ipc/proc_job_executor.js.map +0 -1
@@ -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,SAAS,MAAM,iBAAiB;AAChC,SAAS,kBAAkB;AAC3B,SAAS,cAAc,YAAY;AACnC,SAAS,qBAAqB;AAE9B,SAAqB,eAAe;AACpC,SAAS,mBAAmB,YAAY,kBAAuC;AAC/E,SAAS,kBAAkB,WAAW;AACtC,SAAS,oCAAoC;AAI7C,MAAM,mBAAmB,KAAK;AAO9B,MAAM,iBAAiB;AAAA,EACrB,UAAU,IAAI,QAA6D,CAAC,YAAY;AACtF,SAAK,UAAU;AAAA,EACjB,CAAC;AAAA,EACD,QAAQ,KAA0D;AAChE;AAAA,EACF;AACF;AAEA,MAAM,UAAuC;AAAA,EAC3C,YAAgD,CAAC;AAAA,EAEjD,cAAc;AACZ,YAAQ,GAAG,WAAW,CAAC,QAAoB;AACzC,cAAQ,IAAI,MAAM;AAAA,QAChB,KAAK;AACH,gBAAM,MAAM,KAAK,UAAU,IAAI,MAAM,SAAS;AAC9C,iBAAO,KAAK,UAAU,IAAI,MAAM,SAAS;AACzC,cAAI,CAAC,KAAK;AACR,gBAAI,EAAE,MAAM,EAAE,MAAM,IAAI,MAAM,CAAC,EAAE,KAAK,wCAAwC;AAC9E;AAAA,UACF;AACA,cAAI,QAAQ,IAAI,KAAK;AACrB;AAAA,MACJ;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,YAAY,QAAgB,MAAiC;AACjE,UAAM,YAAY,m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AM;AACvC,aAAO,KAAK,iCAAiC;AAC7C,cAAQ,KAAK;AAAA,IACf,GAAG,gBAAgB;AAEnB,YAAQ,GAAG,WAAW,CAAC,QAAoB;AACzC,cAAQ,IAAI,MAAM;AAAA,QAChB,KAAK,eAAe;AAClB,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;AAAA,QACA,KAAK,mBAAmB;AACtB,cAAI,KAAK;AACP,kBAAM,IAAI,MAAM,0BAA0B;AAAA,UAC5C;AAEA,mBAAS,OAAO,MAAM,EAAE,OAAO,IAAI,MAAM,WAAW,IAAI,GAAG,CAAC;AAE5D,gBAAM,SAAS,MAAM,MAAM,OAAO,IAAI,MAAM,YAAY,YAAY,MAAM;AAC1E,iBAAO,MAAM,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":["agent"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ipc/message.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { RunningJobInfo } from '../job.js';\nimport type { LoggerOptions } from '../log.js';\n\nexport type IPCMessage =\n | {\n case: 'initializeRequest';\n value: { loggerOptions: LoggerOptions };\n }\n | {\n case: 'initializeResponse';\n value: undefined;\n }\n | {\n case: 'pingRequest';\n value: { timestamp: number };\n }\n | {\n case: 'pongResponse';\n value: { lastTimestamp: number; timestamp: number };\n }\n | {\n case: 'startJobRequest';\n value: { runningJob: RunningJobInfo };\n }\n | {\n case: 'shutdownRequest';\n value: { reason?: string };\n }\n | {\n case: 'exiting';\n value: { reason?: string };\n }\n | {\n case: 'done';\n value: undefined;\n };\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../src/ipc/message.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { RunningJobInfo } from '../job.js';\nimport type { LoggerOptions } from '../log.js';\n\nexport type IPCMessage =\n | {\n case: 'initializeRequest';\n value: {\n loggerOptions: LoggerOptions;\n pingInterval?: number;\n pingTimeout?: number;\n highPingThreshold?: number;\n };\n }\n | {\n case: 'initializeResponse';\n value: undefined;\n }\n | {\n case: 'pingRequest';\n value: { timestamp: number };\n }\n | {\n case: 'pongResponse';\n value: { lastTimestamp: number; timestamp: number };\n }\n | {\n case: 'startJobRequest';\n value: { runningJob: RunningJobInfo };\n }\n | {\n case: 'shutdownRequest';\n value: { reason?: string };\n }\n | {\n case: 'inferenceRequest';\n value: { method: string; requestId: string; data: unknown };\n }\n | {\n case: 'inferenceResponse';\n value: { requestId: string; data: unknown; error?: Error };\n }\n | {\n case: 'exiting';\n value: { reason?: string };\n }\n | {\n case: 'done';\n value: undefined;\n };\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -4,6 +4,9 @@ export type IPCMessage = {
4
4
  case: 'initializeRequest';
5
5
  value: {
6
6
  loggerOptions: LoggerOptions;
7
+ pingInterval?: number;
8
+ pingTimeout?: number;
9
+ highPingThreshold?: number;
7
10
  };
8
11
  } | {
9
12
  case: 'initializeResponse';
@@ -29,6 +32,20 @@ export type IPCMessage = {
29
32
  value: {
30
33
  reason?: string;
31
34
  };
35
+ } | {
36
+ case: 'inferenceRequest';
37
+ value: {
38
+ method: string;
39
+ requestId: string;
40
+ data: unknown;
41
+ };
42
+ } | {
43
+ case: 'inferenceResponse';
44
+ value: {
45
+ requestId: string;
46
+ data: unknown;
47
+ error?: Error;
48
+ };
32
49
  } | {
33
50
  case: 'exiting';
34
51
  value: {
@@ -1 +1 @@
1
- {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/ipc/message.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,MAAM,MAAM,UAAU,GAClB;IACE,IAAI,EAAE,mBAAmB,CAAC;IAC1B,KAAK,EAAE;QAAE,aAAa,EAAE,aAAa,CAAA;KAAE,CAAC;CACzC,GACD;IACE,IAAI,EAAE,oBAAoB,CAAC;IAC3B,KAAK,EAAE,SAAS,CAAC;CAClB,GACD;IACE,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CAC9B,GACD;IACE,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CACrD,GACD;IACE,IAAI,EAAE,iBAAiB,CAAC;IACxB,KAAK,EAAE;QAAE,UAAU,EAAE,cAAc,CAAA;KAAE,CAAC;CACvC,GACD;IACE,IAAI,EAAE,iBAAiB,CAAC;IACxB,KAAK,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5B,GACD;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5B,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,SAAS,CAAC;CAClB,CAAC"}
1
+ {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/ipc/message.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,MA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,EAAE,SAAS,CAAC;CAClB,CAAC"}
@@ -23,7 +23,7 @@ __export(proc_pool_exports, {
23
23
  module.exports = __toCommonJS(proc_pool_exports);
24
24
  var import_mutex = require("@livekit/mutex");
25
25
  var import_utils = require("../utils.cjs");
26
- var import_proc_job_executor = require("./proc_job_executor.cjs");
26
+ var import_job_proc_executor = require("./job_proc_executor.cjs");
27
27
  class ProcPool {
28
28
  agent;
29
29
  initializeTimeout;
@@ -37,13 +37,19 @@ class ProcPool {
37
37
  procMutex;
38
38
  procUnlock;
39
39
  warmedProcQueue = new import_utils.Queue();
40
- constructor(agent, numIdleProcesses, initializeTimeout, closeTimeout) {
40
+ inferenceExecutor;
41
+ memoryWarnMB;
42
+ memoryLimitMB;
43
+ constructor(agent, numIdleProcesses, initializeTimeout, closeTimeout, inferenceExecutor, memoryWarnMB, memoryLimitMB) {
41
44
  this.agent = agent;
42
45
  if (numIdleProcesses > 0) {
43
46
  this.procMutex = new import_mutex.MultiMutex(numIdleProcesses);
44
47
  }
45
48
  this.initializeTimeout = initializeTimeout;
46
49
  this.closeTimeout = closeTimeout;
50
+ this.inferenceExecutor = inferenceExecutor;
51
+ this.memoryWarnMB = memoryWarnMB;
52
+ this.memoryLimitMB = memoryLimitMB;
47
53
  }
48
54
  get processes() {
49
55
  return this.executors;
@@ -60,7 +66,17 @@ class ProcPool {
60
66
  this.procUnlock = void 0;
61
67
  }
62
68
  } else {
63
- proc = new import_proc_job_executor.ProcJobExecutor(this.agent, this.initializeTimeout, this.closeTimeout);
69
+ proc = new import_job_proc_executor.JobProcExecutor(
70
+ this.agent,
71
+ this.inferenceExecutor,
72
+ this.initializeTimeout,
73
+ this.closeTimeout,
74
+ this.memoryWarnMB,
75
+ this.memoryLimitMB,
76
+ 2500,
77
+ 6e4,
78
+ 500
79
+ );
64
80
  this.executors.push(proc);
65
81
  await proc.start();
66
82
  await proc.initialize();
@@ -68,7 +84,17 @@ class ProcPool {
68
84
  await proc.launchJob(info);
69
85
  }
70
86
  async procWatchTask() {
71
- const proc = new import_proc_job_executor.ProcJobExecutor(this.agent, this.initializeTimeout, this.closeTimeout);
87
+ const proc = new import_job_proc_executor.JobProcExecutor(
88
+ this.agent,
89
+ this.inferenceExecutor,
90
+ this.initializeTimeout,
91
+ this.closeTimeout,
92
+ this.memoryWarnMB,
93
+ this.memoryLimitMB,
94
+ 2500,
95
+ 6e4,
96
+ 500
97
+ );
72
98
  try {
73
99
  this.executors.push(proc);
74
100
  const unlock = await this.initMutex.lock();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ipc/proc_pool.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { MultiMutex, Mutex } from '@livekit/mutex';\nimport type { RunningJobInfo } from '../job.js';\nimport { Queue } from '../utils.js';\nimport type { JobExecutor } from './job_executor.js';\nimport { ProcJobExecutor } from './proc_job_executor.js';\n\nexport class ProcPool {\n agent: string;\n initializeTimeout: number;\n closeTimeout: number;\n executors: JobExecutor[] = [];\n tasks: Promise<void>[] = [];\n started = false;\n closed = false;\n controller = new AbortController();\n initMutex = new Mutex();\n procMutex?: MultiMutex;\n procUnlock?: () => void;\n warmedProcQueue = new Queue<JobExecutor>();\n\n constructor(\n agent: string,\n numIdleProcesses: number,\n initializeTimeout: number,\n closeTimeout: number,\n ) {\n this.agent = agent;\n if (numIdleProcesses > 0) {\n this.procMutex = new MultiMutex(numIdleProcesses);\n }\n this.initializeTimeout = initializeTimeout;\n this.closeTimeout = closeTimeout;\n }\n\n get processes(): JobExecutor[] {\n return this.executors;\n }\n\n getByJobId(id: string): JobExecutor | null {\n return this.executors.find((x) => x.runningJob && x.runningJob.job.id === id) || null;\n }\n\n async launchJob(info: RunningJobInfo) {\n let proc: JobExecutor;\n if (this.procMutex) {\n proc = await this.warmedProcQueue.get();\n if (this.procUnlock) {\n this.procUnlock();\n this.procUnlock = undefined;\n }\n } else {\n proc = new ProcJobExecutor(this.agent, this.initializeTimeout, this.closeTimeout);\n this.executors.push(proc);\n await proc.start();\n await proc.initialize();\n }\n await proc.launchJob(info);\n }\n\n async procWatchTask() {\n const proc = new ProcJobExecutor(this.agent, this.initializeTimeout, this.closeTimeout);\n\n try {\n this.executors.push(proc);\n\n const unlock = await this.initMutex.lock();\n if (this.closed) {\n return;\n }\n\n await proc.start();\n try {\n await proc.initialize();\n await this.warmedProcQueue.put(proc);\n } catch {\n if (this.procUnlock) {\n this.procUnlock();\n this.procUnlock = undefined;\n }\n }\n\n unlock();\n await proc.join();\n } finally {\n this.executors.splice(this.executors.indexOf(proc));\n }\n }\n\n start() {\n if (this.started) {\n return;\n }\n\n this.started = true;\n this.run(this.controller.signal);\n }\n\n async run(signal: AbortSignal) {\n if (this.procMutex) {\n while (!signal.aborted) {\n this.procUnlock = await this.procMutex.lock();\n const task = this.procWatchTask();\n this.tasks.push(task);\n task.finally(() => this.tasks.splice(this.tasks.indexOf(task)));\n }\n }\n }\n\n async close() {\n if (!this.started) {\n return;\n }\n this.closed = true;\n this.controller.abort();\n this.warmedProcQueue.items.forEach((e) => e.close());\n this.executors.forEach((e) => e.close());\n await Promise.allSettled(this.tasks);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAkC;AAElC,mBAAsB;AAEtB,+BAAgC;AAEzB,MAAM,SAAS;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAA2B,CAAC;AAAA,EAC5B,QAAyB,CAAC;AAAA,EAC1B,UAAU;AAAA,EACV,SAAS;AAAA,EACT,aAAa,IAAI,gBAAgB;AAAA,EACjC,YAAY,IAAI,mBAAM;AAAA,EACtB;AAAA,EACA;AAAA,EACA,kBAAkB,IAAI,mBAAmB;AAAA,EAEzC,YACE,OACA,kBACA,mBACA,cACA;AACA,SAAK,QAAQ;AACb,QAAI,mBAAmB,GAAG;AACxB,WAAK,YAAY,IAAI,wBAAW,gBAAgB;AAAA,IACl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ACF;AAEA,SAAK,UAAU;AACf,SAAK,IAAI,KAAK,WAAW,MAAM;AAAA,EACjC;AAAA,EAEA,MAAM,IAAI,QAAqB;AAC7B,QAAI,KAAK,WAAW;AAClB,aAAO,CAAC,OAAO,SAAS;AACtB,aAAK,aAAa,MAAM,KAAK,UAAU,KAAK;AAC5C,cAAM,OAAO,KAAK,cAAc;AAChC,aAAK,MAAM,KAAK,IAAI;AACpB,aAAK,QAAQ,MAAM,KAAK,MAAM,OAAO,KAAK,MAAM,QAAQ,IAAI,CAAC,CAAC;AAAA,MAChE;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,QAAQ;AACZ,QAAI,CAAC,KAAK,SAAS;AACjB;AAAA,IACF;AACA,SAAK,SAAS;AACd,SAAK,WAAW,MAAM;AACtB,SAAK,gBAAgB,MAAM,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;AACnD,SAAK,UAAU,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;AACvC,UAAM,QAAQ,WAAW,KAAK,KAAK;AAAA,EACrC;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/ipc/proc_pool.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { MultiMutex, Mutex } from '@livekit/mutex';\nimport type { RunningJobInfo } from '../job.js';\nimport { Queue } from '../utils.js';\nimport type { InferenceExecutor } from './inference_executor.js';\nimport type { JobExecutor } from './job_executor.js';\nimport { JobProcExecutor } from './job_proc_executor.js';\n\nexport class ProcPool {\n agent: string;\n initializeTimeout: number;\n closeTimeout: number;\n executors: JobExecutor[] = [];\n tasks: Promise<void>[] = [];\n started = false;\n closed = false;\n controller = new AbortController();\n initMutex = new Mutex();\n procMutex?: MultiMutex;\n procUnlock?: () => void;\n warmedProcQueue = new Queue<JobExecutor>();\n inferenceExecutor?: InferenceExecutor;\n memoryWarnMB: number;\n memoryLimitMB: number;\n\n constructor(\n agent: string,\n numIdleProcesses: number,\n initializeTimeout: number,\n closeTimeout: number,\n inferenceExecutor: InferenceExecutor | undefined,\n memoryWarnMB: number,\n memoryLimitMB: number,\n ) {\n this.agent = agent;\n if (numIdleProcesses > 0) {\n this.procMutex = new MultiMutex(numIdleProcesses);\n }\n this.initializeTimeout = initializeTimeout;\n this.closeTimeout = closeTimeout;\n this.inferenceExecutor = inferenceExecutor;\n this.memoryWarnMB = memoryWarnMB;\n this.memoryLimitMB = memoryLimitMB;\n }\n\n get processes(): JobExecutor[] {\n return this.executors;\n }\n\n getByJobId(id: string): JobExecutor | null {\n return this.executors.find((x) => x.runningJob && x.runningJob.job.id === id) || null;\n }\n\n async launchJob(info: RunningJobInfo) {\n let proc: JobExecutor;\n if (this.procMutex) {\n proc = await this.warmedProcQueue.get();\n if (this.procUnlock) {\n this.procUnlock();\n this.procUnlock = undefined;\n }\n } else {\n proc = new JobProcExecutor(\n this.agent,\n this.inferenceExecutor,\n this.initializeTimeout,\n this.closeTimeout,\n this.memoryWarnMB,\n this.memoryLimitMB,\n 2500,\n 60000,\n 500,\n );\n this.executors.push(proc);\n await proc.start();\n await proc.initialize();\n }\n await proc.launchJob(info);\n }\n\n async procWatchTask() {\n const proc = new JobProcExecutor(\n this.agent,\n this.inferenceExecutor,\n this.initializeTimeout,\n this.closeTimeout,\n this.memoryWarnMB,\n this.memoryLimitMB,\n 2500,\n 60000,\n 500,\n );\n\n try {\n this.executors.push(proc);\n\n const unlock = await this.initMutex.lock();\n if (this.closed) {\n return;\n }\n\n await proc.start();\n try {\n await proc.initialize();\n await this.warmedProcQueue.put(proc);\n } catch {\n if (this.procUnlock) {\n this.procUnlock();\n this.procUnlock = undefined;\n }\n }\n\n unlock();\n await proc.join();\n } finally {\n this.executors.splice(this.executors.indexOf(proc));\n }\n }\n\n start() {\n if (this.started) {\n return;\n }\n\n this.started = true;\n this.run(this.controller.signal);\n }\n\n async run(signal: AbortSignal) {\n if (this.procMutex) {\n while (!signal.aborted) {\n this.procUnlock = await this.procMutex.lock();\n const task = this.procWatchTask();\n this.tasks.push(task);\n task.finally(() => this.tasks.splice(this.tasks.indexOf(task)));\n }\n }\n }\n\n async close() {\n if (!this.started) {\n return;\n }\n this.closed = true;\n this.controller.abort();\n this.warmedProcQueue.items.forEach((e) => e.close());\n this.executors.forEach((e) => e.close());\n await Promise.allSettled(this.tasks);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAkC;AAElC,mBAAsB;AAGtB,+BAAgC;AAEzB,MAAM,SAAS;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAA2B,CAAC;AAAA,EAC5B,QAAyB,CAAC;AAAA,EAC1B,UAAU;AAAA,EACV,SAAS;AAAA,EACT,aAAa,IAAI,gBAAgB;AAAA,EACjC,YAAY,IAAI,mBAAM;AAAA,EACtB;AAAA,EACA;AAAA,EACA,kBAAkB,IAAI,mBAAmB;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YACE,OACA,kBACA,mBACA,cACA,mBACA,cACA,eACA;AACA,SAAK,QAAQ;AACb,QAAI,mBAAmB,GAAG;AACxB,WAAK,YAAY,IAAI,wBAAW,gBAAgB;AAAA,IAClD;AACA,SAAK,oBAAoB;AACzB,SAAK,eAAe;AACpB,SAAK,oBAAoB;AACzB,SAAK,eAAe;AACpB,SAAK,gBAAgB;AAAA,EACvB;AAAA,EAEA,IAAI,YAA2B;AAC7B,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,WAAW,IAAgC;AACzC,WAAO,KAAK,UAAU,KAAK,CAAC,MAAM,EAAE,cAAc,EAAE,WAAW,IAAI,OAAO,EAAE,KAAK;AAAA,EACnF;AAAA,EAEA,MAAM,UAAU,MAAsB;AACpC,QAAI;AACJ,QAAI,KAAK,WAAW;AAClB,aAAO,MAAM,KAAK,gBAAgB,IAAI;AACtC,UAAI,KAAK,YAAY;AACnB,aAAK,WAAW;AAChB,aAAK,aAAa;A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,OAAO,KAAK,cAAc;AAChC,aAAK,MAAM,KAAK,IAAI;AACpB,aAAK,QAAQ,MAAM,KAAK,MAAM,OAAO,KAAK,MAAM,QAAQ,IAAI,CAAC,CAAC;AAAA,MAChE;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,QAAQ;AACZ,QAAI,CAAC,KAAK,SAAS;AACjB;AAAA,IACF;AACA,SAAK,SAAS;AACd,SAAK,WAAW,MAAM;AACtB,SAAK,gBAAgB,MAAM,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;AACnD,SAAK,UAAU,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;AACvC,UAAM,QAAQ,WAAW,KAAK,KAAK;AAAA,EACrC;AACF;","names":[]}
@@ -1,6 +1,7 @@
1
1
  import { MultiMutex, Mutex } from '@livekit/mutex';
2
2
  import type { RunningJobInfo } from '../job.js';
3
3
  import { Queue } from '../utils.js';
4
+ import type { InferenceExecutor } from './inference_executor.js';
4
5
  import type { JobExecutor } from './job_executor.js';
5
6
  export declare class ProcPool {
6
7
  agent: string;
@@ -15,7 +16,10 @@ export declare class ProcPool {
15
16
  procMutex?: MultiMutex;
16
17
  procUnlock?: () => void;
17
18
  warmedProcQueue: Queue<JobExecutor>;
18
- constructor(agent: string, numIdleProcesses: number, initializeTimeout: number, closeTimeout: number);
19
+ inferenceExecutor?: InferenceExecutor;
20
+ memoryWarnMB: number;
21
+ memoryLimitMB: number;
22
+ constructor(agent: string, numIdleProcesses: number, initializeTimeout: number, closeTimeout: number, inferenceExecutor: InferenceExecutor | undefined, memoryWarnMB: number, memoryLimitMB: number);
19
23
  get processes(): JobExecutor[];
20
24
  getByJobId(id: string): JobExecutor | null;
21
25
  launchJob(info: RunningJobInfo): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"proc_pool.d.ts","sourceRoot":"","sources":["../../src/ipc/proc_pool.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,gBAAg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AAC;AAGrD,qBAAa,QAAQ;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,WAAW,EAAE,CAAM;IAC9B,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAM;IAC5B,OAAO,UAAS;IAChB,MAAM,UAAS;IACf,UAAU,kBAAyB;IACnC,SAAS,QAAe;IACxB,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,eAAe,qBAA4B;IAC3C,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;gBAGpB,KAAK,EAAE,MAAM,EACb,gBAAgB,EAAE,MAAM,EACxB,iBAAiB,EAAE,MAAM,EACzB,YAAY,EAAE,MAAM,EACpB,iBAAiB,EAAE,iBAAiB,GAAG,SAAS,EAChD,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM;IAavB,IAAI,SAAS,IAAI,WAAW,EAAE,CAE7B;IAED,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IAIpC,SAAS,CAAC,IAAI,EAAE,cAAc;IA2B9B,aAAa;IAuCnB,KAAK;IASC,GAAG,CAAC,MAAM,EAAE,WAAW;IAWvB,KAAK;CAUZ"}
@@ -1,6 +1,6 @@
1
1
  import { MultiMutex, Mutex } from "@livekit/mutex";
2
2
  import { Queue } from "../utils.js";
3
- import { ProcJobExecutor } from "./proc_job_executor.js";
3
+ import { JobProcExecutor } from "./job_proc_executor.js";
4
4
  class ProcPool {
5
5
  agent;
6
6
  initializeTimeout;
@@ -14,13 +14,19 @@ class ProcPool {
14
14
  procMutex;
15
15
  procUnlock;
16
16
  warmedProcQueue = new Queue();
17
- constructor(agent, numIdleProcesses, initializeTimeout, closeTimeout) {
17
+ inferenceExecutor;
18
+ memoryWarnMB;
19
+ memoryLimitMB;
20
+ constructor(agent, numIdleProcesses, initializeTimeout, closeTimeout, inferenceExecutor, memoryWarnMB, memoryLimitMB) {
18
21
  this.agent = agent;
19
22
  if (numIdleProcesses > 0) {
20
23
  this.procMutex = new MultiMutex(numIdleProcesses);
21
24
  }
22
25
  this.initializeTimeout = initializeTimeout;
23
26
  this.closeTimeout = closeTimeout;
27
+ this.inferenceExecutor = inferenceExecutor;
28
+ this.memoryWarnMB = memoryWarnMB;
29
+ this.memoryLimitMB = memoryLimitMB;
24
30
  }
25
31
  get processes() {
26
32
  return this.executors;
@@ -37,7 +43,17 @@ class ProcPool {
37
43
  this.procUnlock = void 0;
38
44
  }
39
45
  } else {
40
- proc = new ProcJobExecutor(this.agent, this.initializeTimeout, this.closeTimeout);
46
+ proc = new JobProcExecutor(
47
+ this.agent,
48
+ this.inferenceExecutor,
49
+ this.initializeTimeout,
50
+ this.closeTimeout,
51
+ this.memoryWarnMB,
52
+ this.memoryLimitMB,
53
+ 2500,
54
+ 6e4,
55
+ 500
56
+ );
41
57
  this.executors.push(proc);
42
58
  await proc.start();
43
59
  await proc.initialize();
@@ -45,7 +61,17 @@ class ProcPool {
45
61
  await proc.launchJob(info);
46
62
  }
47
63
  async procWatchTask() {
48
- const proc = new ProcJobExecutor(this.agent, this.initializeTimeout, this.closeTimeout);
64
+ const proc = new JobProcExecutor(
65
+ this.agent,
66
+ this.inferenceExecutor,
67
+ this.initializeTimeout,
68
+ this.closeTimeout,
69
+ this.memoryWarnMB,
70
+ this.memoryLimitMB,
71
+ 2500,
72
+ 6e4,
73
+ 500
74
+ );
49
75
  try {
50
76
  this.executors.push(proc);
51
77
  const unlock = await this.initMutex.lock();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ipc/proc_pool.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { MultiMutex, Mutex } from '@livekit/mutex';\nimport type { RunningJobInfo } from '../job.js';\nimport { Queue } from '../utils.js';\nimport type { JobExecutor } from './job_executor.js';\nimport { ProcJobExecutor } from './proc_job_executor.js';\n\nexport class ProcPool {\n agent: string;\n initializeTimeout: number;\n closeTimeout: number;\n executors: JobExecutor[] = [];\n tasks: Promise<void>[] = [];\n started = false;\n closed = false;\n controller = new AbortController();\n initMutex = new Mutex();\n procMutex?: MultiMutex;\n procUnlock?: () => void;\n warmedProcQueue = new Queue<JobExecutor>();\n\n constructor(\n agent: string,\n numIdleProcesses: number,\n initializeTimeout: number,\n closeTimeout: number,\n ) {\n this.agent = agent;\n if (numIdleProcesses > 0) {\n this.procMutex = new MultiMutex(numIdleProcesses);\n }\n this.initializeTimeout = initializeTimeout;\n this.closeTimeout = closeTimeout;\n }\n\n get processes(): JobExecutor[] {\n return this.executors;\n }\n\n getByJobId(id: string): JobExecutor | null {\n return this.executors.find((x) => x.runningJob && x.runningJob.job.id === id) || null;\n }\n\n async launchJob(info: RunningJobInfo) {\n let proc: JobExecutor;\n if (this.procMutex) {\n proc = await this.warmedProcQueue.get();\n if (this.procUnlock) {\n this.procUnlock();\n this.procUnlock = undefined;\n }\n } else {\n proc = new ProcJobExecutor(this.agent, this.initializeTimeout, this.closeTimeout);\n this.executors.push(proc);\n await proc.start();\n await proc.initialize();\n }\n await proc.launchJob(info);\n }\n\n async procWatchTask() {\n const proc = new ProcJobExecutor(this.agent, this.initializeTimeout, this.closeTimeout);\n\n try {\n this.executors.push(proc);\n\n const unlock = await this.initMutex.lock();\n if (this.closed) {\n return;\n }\n\n await proc.start();\n try {\n await proc.initialize();\n await this.warmedProcQueue.put(proc);\n } catch {\n if (this.procUnlock) {\n this.procUnlock();\n this.procUnlock = undefined;\n }\n }\n\n unlock();\n await proc.join();\n } finally {\n this.executors.splice(this.executors.indexOf(proc));\n }\n }\n\n start() {\n if (this.started) {\n return;\n }\n\n this.started = true;\n this.run(this.controller.signal);\n }\n\n async run(signal: AbortSignal) {\n if (this.procMutex) {\n while (!signal.aborted) {\n this.procUnlock = await this.procMutex.lock();\n const task = this.procWatchTask();\n this.tasks.push(task);\n task.finally(() => this.tasks.splice(this.tasks.indexOf(task)));\n }\n }\n }\n\n async close() {\n if (!this.started) {\n return;\n }\n this.closed = true;\n this.controller.abort();\n this.warmedProcQueue.items.forEach((e) => e.close());\n this.executors.forEach((e) => e.close());\n await Promise.allSettled(this.tasks);\n }\n}\n"],"mappings":"AAGA,SAAS,YAAY,aAAa;AAElC,SAAS,aAAa;AAEtB,SAAS,uBAAuB;AAEzB,MAAM,SAAS;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAA2B,CAAC;AAAA,EAC5B,QAAyB,CAAC;AAAA,EAC1B,UAAU;AAAA,EACV,SAAS;AAAA,EACT,aAAa,IAAI,gBAAgB;AAAA,EACjC,YAAY,IAAI,MAAM;AAAA,EACtB;AAAA,EACA;AAAA,EACA,kBAAkB,IAAI,MAAmB;AAAA,EAEzC,YACE,OACA,kBACA,mBACA,cACA;AACA,SAAK,QAAQ;AACb,QAAI,mBAAmB,GAAG;AACxB,WAAK,YAAY,IAAI,WAAW,gBAAgB;AAAA,IAClD;AACA,SAAK,oBAAoB;AACzB,SAAK,eAAe;AAAA,EACtB;AAAA,EAEA,IAAI,YAA2B;AAC7B,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,WAAW,IAAgC;AACzC,WAAO,KAAK,UAAU,KAAK,CAAC,MAAM,EAAE,cAAc,EAAE,WAAW,IAAI,OAAO,EAAE,KAAK;AAAA,EACnF;AAAA,EAEA,MAAM,UAAU,MAAsB;AACpC,QAAI;AACJ,QAAI,KAAK,WAAW;AAClB,aAAO,MAAM,KAAK,gBAAgB,IAAI;AACtC,UAAI,KAAK,YAAY;AACnB,aAAK,WAAW;AAChB,aAAK,aAAa;AAAA,MACpB;AAAA,IACF,OAAO;AACL,aAAO,IAAI,gBAAgB,KAAK,OAAO,KAAK,mBAAmB,KAAK,YAAY;AAChF,WAAK,U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AAM,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;AACnD,SAAK,UAAU,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;AACvC,UAAM,QAAQ,WAAW,KAAK,KAAK;AAAA,EACrC;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/ipc/proc_pool.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { MultiMutex, Mutex } from '@livekit/mutex';\nimport type { RunningJobInfo } from '../job.js';\nimport { Queue } from '../utils.js';\nimport type { InferenceExecutor } from './inference_executor.js';\nimport type { JobExecutor } from './job_executor.js';\nimport { JobProcExecutor } from './job_proc_executor.js';\n\nexport class ProcPool {\n agent: string;\n initializeTimeout: number;\n closeTimeout: number;\n executors: JobExecutor[] = [];\n tasks: Promise<void>[] = [];\n started = false;\n closed = false;\n controller = new AbortController();\n initMutex = new Mutex();\n procMutex?: MultiMutex;\n procUnlock?: () => void;\n warmedProcQueue = new Queue<JobExecutor>();\n inferenceExecutor?: InferenceExecutor;\n memoryWarnMB: number;\n memoryLimitMB: number;\n\n constructor(\n agent: string,\n numIdleProcesses: number,\n initializeTimeout: number,\n closeTimeout: number,\n inferenceExecutor: InferenceExecutor | undefined,\n memoryWarnMB: number,\n memoryLimitMB: number,\n ) {\n this.agent = agent;\n if (numIdleProcesses > 0) {\n this.procMutex = new MultiMutex(numIdleProcesses);\n }\n this.initializeTimeout = initializeTimeout;\n this.closeTimeout = closeTimeout;\n this.inferenceExecutor = inferenceExecutor;\n this.memoryWarnMB = memoryWarnMB;\n this.memoryLimitMB = memoryLimitMB;\n }\n\n get processes(): JobExecutor[] {\n return this.executors;\n }\n\n getByJobId(id: string): JobExecutor | null {\n return this.executors.find((x) => x.runningJob && x.runningJob.job.id === id) || null;\n }\n\n async launchJob(info: RunningJobInfo) {\n let proc: JobExecutor;\n if (this.procMutex) {\n proc = await this.warmedProcQueue.get();\n if (this.procUnlock) {\n this.procUnlock();\n this.procUnlock = undefined;\n }\n } else {\n proc = new JobProcExecutor(\n this.agent,\n this.inferenceExecutor,\n this.initializeTimeout,\n this.closeTimeout,\n this.memoryWarnMB,\n this.memoryLimitMB,\n 2500,\n 60000,\n 500,\n );\n this.executors.push(proc);\n await proc.start();\n await proc.initialize();\n }\n await proc.launchJob(info);\n }\n\n async procWatchTask() {\n const proc = new JobProcExecutor(\n this.agent,\n this.inferenceExecutor,\n this.initializeTimeout,\n this.closeTimeout,\n this.memoryWarnMB,\n this.memoryLimitMB,\n 2500,\n 60000,\n 500,\n );\n\n try {\n this.executors.push(proc);\n\n const unlock = await this.initMutex.lock();\n if (this.closed) {\n return;\n }\n\n await proc.start();\n try {\n await proc.initialize();\n await this.warmedProcQueue.put(proc);\n } catch {\n if (this.procUnlock) {\n this.procUnlock();\n this.procUnlock = undefined;\n }\n }\n\n unlock();\n await proc.join();\n } finally {\n this.executors.splice(this.executors.indexOf(proc));\n }\n }\n\n start() {\n if (this.started) {\n return;\n }\n\n this.started = true;\n this.run(this.controller.signal);\n }\n\n async run(signal: AbortSignal) {\n if (this.procMutex) {\n while (!signal.aborted) {\n this.procUnlock = await this.procMutex.lock();\n const task = this.procWatchTask();\n this.tasks.push(task);\n task.finally(() => this.tasks.splice(this.tasks.indexOf(task)));\n }\n }\n }\n\n async close() {\n if (!this.started) {\n return;\n }\n this.closed = true;\n this.controller.abort();\n this.warmedProcQueue.items.forEach((e) => e.close());\n this.executors.forEach((e) => e.close());\n await Promise.allSettled(this.tasks);\n }\n}\n"],"mappings":"AAGA,SAAS,YAAY,aAAa;AAElC,SAAS,aAAa;AAGtB,SAAS,uBAAuB;AAEzB,MAAM,SAAS;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAA2B,CAAC;AAAA,EAC5B,QAAyB,CAAC;AAAA,EAC1B,UAAU;AAAA,EACV,SAAS;AAAA,EACT,aAAa,IAAI,gBAAgB;AAAA,EACjC,YAAY,IAAI,MAAM;AAAA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wnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,41 +15,36 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var proc_job_executor_exports = {};
30
- __export(proc_job_executor_exports, {
31
- ProcJobExecutor: () => ProcJobExecutor
19
+ var supervised_proc_exports = {};
20
+ __export(supervised_proc_exports, {
21
+ SupervisedProc: () => SupervisedProc
32
22
  });
33
- module.exports = __toCommonJS(proc_job_executor_exports);
23
+ module.exports = __toCommonJS(supervised_proc_exports);
34
24
  var import_node_events = require("node:events");
35
25
  var import_log = require("../log.cjs");
36
26
  var import_utils = require("../utils.cjs");
37
- var import_job_executor = require("./job_executor.cjs");
38
- class ProcJobExecutor extends import_job_executor.JobExecutor {
27
+ class SupervisedProc {
39
28
  #opts;
40
29
  #started = false;
41
30
  #closing = false;
42
31
  #runningJob = void 0;
43
- #proc;
32
+ proc;
44
33
  #pingInterval;
34
+ #memoryWatch;
45
35
  #pongTimeout;
46
- #init = new import_utils.Future();
36
+ init = new import_utils.Future();
47
37
  #join = new import_utils.Future();
48
38
  #logger = (0, import_log.log)().child({ runningJob: this.#runningJob });
49
- constructor(agent, initializeTimeout, closeTimeout) {
50
- super();
39
+ constructor(initializeTimeout, closeTimeout, memoryWarnMB, memoryLimitMB, pingInterval, pingTimeout, highPingThreshold) {
51
40
  this.#opts = {
52
- agent,
53
41
  initializeTimeout,
54
- closeTimeout
42
+ closeTimeout,
43
+ memoryWarnMB,
44
+ memoryLimitMB,
45
+ pingInterval,
46
+ pingTimeout,
47
+ highPingThreshold
55
48
  };
56
49
  }
57
50
  get started() {
@@ -66,32 +59,41 @@ class ProcJobExecutor extends import_job_executor.JobExecutor {
66
59
  } else if (this.#closing) {
67
60
  throw new Error("runner is closed");
68
61
  }
69
- this.#proc = await import("./job_main.cjs").then(
70
- (m) => m.runProcess({
71
- agentFile: this.#opts.agent
72
- })
73
- );
62
+ this.proc = this.createProcess();
74
63
  this.#started = true;
75
64
  this.run();
76
65
  }
77
66
  async run() {
78
- await this.#init.await;
67
+ await this.init.await;
79
68
  this.#pingInterval = setInterval(() => {
80
- this.#proc.send({ case: "pingRequest", value: { timestamp: Date.now() } });
81
- }, this.PING_INTERVAL);
69
+ this.proc.send({ case: "pingRequest", value: { timestamp: Date.now() } });
70
+ }, this.#opts.pingInterval);
82
71
  this.#pongTimeout = setTimeout(() => {
83
72
  this.#logger.warn("job is unresponsive");
84
73
  clearTimeout(this.#pongTimeout);
85
74
  clearInterval(this.#pingInterval);
86
- this.#proc.kill();
75
+ this.proc.kill();
87
76
  this.#join.resolve();
88
- }, this.PING_TIMEOUT);
77
+ }, this.#opts.pingTimeout);
78
+ this.#memoryWatch = setInterval(() => {
79
+ const memoryMB = process.memoryUsage().heapUsed / (1024 * 1024);
80
+ if (this.#opts.memoryLimitMB > 0 && memoryMB > this.#opts.memoryLimitMB) {
81
+ this.#logger.child({ memoryUsageMB: memoryMB, memoryLimitMB: this.#opts.memoryLimitMB }).error("process exceeded memory limit, killing process");
82
+ this.close();
83
+ } else if (this.#opts.memoryWarnMB > 0 && memoryMB > this.#opts.memoryWarnMB) {
84
+ this.#logger.child({
85
+ memoryUsageMB: memoryMB,
86
+ memoryWarnMB: this.#opts.memoryWarnMB,
87
+ memoryLimitMB: this.#opts.memoryLimitMB
88
+ }).error("process memory usage is high");
89
+ }
90
+ });
89
91
  const listener = (msg) => {
90
92
  var _a;
91
93
  switch (msg.case) {
92
94
  case "pongResponse": {
93
95
  const delay = Date.now() - msg.value.timestamp;
94
- if (delay > this.HIGH_PING_THRESHOLD) {
96
+ if (delay > this.#opts.highPingThreshold) {
95
97
  this.#logger.child({ delay }).warn("job executor is unresponsive");
96
98
  }
97
99
  (_a = this.#pongTimeout) == null ? void 0 : _a.refresh();
@@ -103,20 +105,22 @@ class ProcJobExecutor extends import_job_executor.JobExecutor {
103
105
  }
104
106
  case "done": {
105
107
  this.#closing = true;
106
- this.#proc.off("message", listener);
108
+ this.proc.off("message", listener);
107
109
  this.#join.resolve();
108
110
  break;
109
111
  }
110
112
  }
111
113
  };
112
- this.#proc.on("message", listener);
113
- this.#proc.on("error", (err) => {
114
+ this.proc.on("message", listener);
115
+ this.proc.on("error", (err) => {
114
116
  if (this.#closing) return;
115
117
  this.#logger.child({ err }).warn("job process exited unexpectedly; this likely means the error above caused a crash");
116
118
  clearTimeout(this.#pongTimeout);
117
119
  clearInterval(this.#pingInterval);
120
+ clearInterval(this.#memoryWatch);
118
121
  this.#join.resolve();
119
122
  });
123
+ this.mainTask(this.proc);
120
124
  await this.#join.await;
121
125
  }
122
126
  async join() {
@@ -128,17 +132,25 @@ class ProcJobExecutor extends import_job_executor.JobExecutor {
128
132
  async initialize() {
129
133
  const timer = setTimeout(() => {
130
134
  const err = new Error("runner initialization timed out");
131
- this.#init.reject(err);
135
+ this.init.reject(err);
132
136
  throw err;
133
137
  }, this.#opts.initializeTimeout);
134
- this.#proc.send({ case: "initializeRequest", value: { loggerOptions: import_log.loggerOptions } });
135
- await (0, import_node_events.once)(this.#proc, "message").then(([msg]) => {
138
+ this.proc.send({
139
+ case: "initializeRequest",
140
+ value: {
141
+ loggerOptions: import_log.loggerOptions,
142
+ pingInterval: this.#opts.pingInterval,
143
+ pingTimeout: this.#opts.pingTimeout,
144
+ highPingThreshold: this.#opts.highPingThreshold
145
+ }
146
+ });
147
+ await (0, import_node_events.once)(this.proc, "message").then(([msg]) => {
136
148
  clearTimeout(timer);
137
149
  if (msg.case !== "initializeResponse") {
138
150
  throw new Error("first message must be InitializeResponse");
139
151
  }
140
152
  });
141
- this.#init.resolve();
153
+ this.init.resolve();
142
154
  }
143
155
  async close() {
144
156
  if (!this.#started) {
@@ -146,10 +158,10 @@ class ProcJobExecutor extends import_job_executor.JobExecutor {
146
158
  }
147
159
  this.#closing = true;
148
160
  if (!this.#runningJob) {
149
- this.#proc.kill();
161
+ this.proc.kill();
150
162
  this.#join.resolve();
151
163
  }
152
- this.#proc.send({ case: "shutdownRequest" });
164
+ this.proc.send({ case: "shutdownRequest" });
153
165
  const timer = setTimeout(() => {
154
166
  this.#logger.error("job shutdown is taking too much time");
155
167
  }, this.#opts.closeTimeout);
@@ -164,11 +176,11 @@ class ProcJobExecutor extends import_job_executor.JobExecutor {
164
176
  throw new Error("executor already has a running job");
165
177
  }
166
178
  this.#runningJob = info;
167
- this.#proc.send({ case: "startJobRequest", value: { runningJob: info } });
179
+ this.proc.send({ case: "startJobRequest", value: { runningJob: info } });
168
180
  }
169
181
  }
170
182
  // Annotate the CommonJS export names for ESM import in node:
171
183
  0 && (module.exports = {
172
- ProcJobExecutor
184
+ SupervisedProc
173
185
  });
174
- //# sourceMappingURL=proc_job_executor.cjs.map
186
+ //# sourceMappingURL=supervised_proc.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ipc/supervised_proc.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { ChildProcess } from 'node:child_process';\nimport { once } from 'node:events';\nimport type { RunningJobInfo } from '../job.js';\nimport { log, loggerOptions } from '../log.js';\nimport { Future } from '../utils.js';\nimport type { IPCMessage } from './message.js';\n\nexport interface ProcOpts {\n initializeTimeout: number;\n closeTimeout: number;\n memoryWarnMB: number;\n memoryLimitMB: number;\n pingInterval: number;\n pingTimeout: number;\n highPingThreshold: number;\n}\n\nexport abstract class SupervisedProc {\n #opts: ProcOpts;\n #started = false;\n #closing = false;\n #runningJob?: RunningJobInfo = undefined;\n proc?: ChildProcess;\n #pingInterval?: ReturnType<typeof setInterval>;\n #memoryWatch?: ReturnType<typeof setInterval>;\n #pongTimeout?: ReturnType<typeof setTimeout>;\n protected init = new Future();\n #join = new Future();\n #logger = log().child({ runningJob: this.#runningJob });\n\n constructor(\n initializeTimeout: number,\n closeTimeout: number,\n memoryWarnMB: number,\n memoryLimitMB: number,\n pingInterval: number,\n pingTimeout: number,\n highPingThreshold: number,\n ) {\n this.#opts = {\n initializeTimeout,\n closeTimeout,\n memoryWarnMB,\n memoryLimitMB,\n pingInterval,\n pingTimeout,\n highPingThreshold,\n };\n }\n\n abstract createProcess(): ChildProcess;\n abstract mainTask(child: ChildProcess): Promise<void>;\n\n get started(): boolean {\n return this.#started;\n }\n\n get runningJob(): RunningJobInfo | undefined {\n return this.#runningJob;\n }\n\n async start() {\n if (this.#started) {\n throw new Error('runner already started');\n } else if (this.#closing) {\n throw new Error('runner is closed');\n }\n\n this.proc = this.createProcess();\n\n this.#started = true;\n this.run();\n }\n\n async run() {\n await this.init.await;\n\n this.#pingInterval = setInterval(() => {\n this.proc!.send({ case: 'pingRequest', value: { timestamp: Date.now() } });\n }, this.#opts.pingInterval);\n\n this.#pongTimeout = setTimeout(() => {\n this.#logger.warn('job is unresponsive');\n clearTimeout(this.#pongTimeout);\n clearInterval(this.#pingInterval);\n this.proc!.kill();\n this.#join.resolve();\n }, this.#opts.pingTimeout);\n\n this.#memoryWatch = setInterval(() => {\n const memoryMB = process.memoryUsage().heapUsed / (1024 * 1024);\n if (this.#opts.memoryLimitMB > 0 && memoryMB > this.#opts.memoryLimitMB) {\n this.#logger\n .child({ memoryUsageMB: memoryMB, memoryLimitMB: this.#opts.memoryLimitMB })\n .error('process exceeded memory limit, killing process');\n this.close();\n } else if (this.#opts.memoryWarnMB > 0 && memoryMB > this.#opts.memoryWarnMB) {\n this.#logger\n .child({\n memoryUsageMB: memoryMB,\n memoryWarnMB: this.#opts.memoryWarnMB,\n memoryLimitMB: this.#opts.memoryLimitMB,\n })\n .error('process memory usage is high');\n }\n });\n\n const listener = (msg: IPCMessage) => {\n switch (msg.case) {\n case 'pongResponse': {\n const delay = Date.now() - msg.value.timestamp;\n if (delay > this.#opts.highPingThreshold) {\n this.#logger.child({ delay }).warn('job executor is unresponsive');\n }\n this.#pongTimeout?.refresh();\n break;\n }\n case 'exiting': {\n this.#logger.child({ reason: msg.value.reason }).debug('job exiting');\n break;\n }\n case 'done': {\n this.#closing = true;\n this.proc!.off('message', listener);\n this.#join.resolve();\n break;\n }\n }\n };\n this.proc!.on('message', listener);\n this.proc!.on('error', (err) => {\n if (this.#closing) return;\n this.#logger\n .child({ err })\n .warn('job process exited unexpectedly; this likely means the error above caused a crash');\n clearTimeout(this.#pongTimeout);\n clearInterval(this.#pingInterval);\n clearInterval(this.#memoryWatch);\n this.#join.resolve();\n });\n\n this.mainTask(this.proc!);\n\n await this.#join.await;\n }\n\n async join() {\n if (!this.#started) {\n throw new Error('runner not started');\n }\n\n await this.#join.await;\n }\n\n async initialize() {\n const timer = setTimeout(() => {\n const err = new Error('runner initialization timed out');\n this.init.reject(err);\n throw err;\n }, this.#opts.initializeTimeout);\n this.proc!.send({\n case: 'initializeRequest',\n value: {\n loggerOptions,\n pingInterval: this.#opts.pingInterval,\n pingTimeout: this.#opts.pingTimeout,\n highPingThreshold: this.#opts.highPingThreshold,\n },\n });\n await once(this.proc!, 'message').then(([msg]: IPCMessage[]) => {\n clearTimeout(timer);\n if (msg!.case !== 'initializeResponse') {\n throw new Error('first message must be InitializeResponse');\n }\n });\n this.init.resolve();\n }\n\n async close() {\n if (!this.#started) {\n return;\n }\n this.#closing = true;\n\n if (!this.#runningJob) {\n this.proc!.kill();\n this.#join.resolve();\n }\n\n this.proc!.send({ case: 'shutdownRequest' });\n\n const timer = setTimeout(() => {\n this.#logger.error('job shutdown is taking too much time');\n }, this.#opts.closeTimeout);\n await this.#join.await.then(() => {\n clearTimeout(timer);\n clearTimeout(this.#pongTimeout);\n clearInterval(this.#pingInterval);\n });\n }\n\n async launchJob(info: RunningJobInfo) {\n if (this.#runningJob) {\n throw new Error('executor already has a running job');\n }\n this.#runningJob = info;\n this.proc!.send({ case: 'startJobRequest', value: { runningJob: info } });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,yBAAqB;AAErB,iBAAmC;AACnC,mBAAuB;AAahB,MAAe,eAAe;AAAA,EACnC;AAAA,EACA,WAAW;AAAA,EACX,WAAW;AAAA,EACX,cAA+B;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACU,OAAO,IAAI,oBAAO;AAAA,EAC5B,QAAQ,IAAI,oBAAO;AAAA,EACnB,cAAU,gBAAI,EAAE,MAAM,EAAE,YAAY,KAAK,YAAY,CAAC;AAAA,EAEtD,YACE,mBACA,cACA,cACA,eACA,cACA,aACA,mBACA;AACA,SAAK,QAAQ;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EAKA,IAAI,UAAmB;AACrB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,aAAyC;AAC3C,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAM,QAAQ;AACZ,QAAI,KAAK,UAAU;AACjB,YAAM,IAAI,MAAM,wBAAwB;AAAA,IAC1C,WAAW,KAAK,UAAU;AACxB,YAAM,IAAI,MAAM,kBAAkB;AAAA,IACpC;AAEA,SAAK,OAAO,KAAK,cAAc;AAE/B,SAAK,WAAW;AAChB,SAAK,IAAI;AAAA,EACX;AAAA,EAEA,MAAM,MAAM;AACV,UAAM,KAAK,KAAK;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,KAAK,QAAQ;AAAA,EACpB;AAAA,EAEA,MAAM,QAAQ;AACZ,QAAI,CAAC,KAAK,UAAU;AAClB;AAAA,IACF;AACA,SAAK,WAAW;AAEhB,QAAI,CAAC,KAAK,aAAa;AACrB,WAAK,KAAM,KAAK;AAChB,WAAK,MAAM,QAAQ;AAAA,IACrB;AAEA,SAAK,KAAM,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE3C,UAAM,QAAQ,WAAW,MAAM;AAC7B,WAAK,QAAQ,MAAM,sCAAsC;AAAA,IAC3D,GAAG,KAAK,MAAM,YAAY;AAC1B,UAAM,KAAK,MAAM,MAAM,KAAK,MAAM;AAChC,mBAAa,KAAK;AAClB,mBAAa,KAAK,YAAY;AAC9B,oBAAc,KAAK,aAAa;AAAA,IAClC,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,UAAU,MAAsB;AACpC,QAAI,KAAK,aAAa;AACpB,YAAM,IAAI,MAAM,oCAAoC;AAAA,IACtD;AACA,SAAK,cAAc;AACnB,SAAK,KAAM,KAAK,EAAE,MAAM,mBAAmB,OAAO,EAAE,YAAY,KAAK,EAAE,CAAC;AAAA,EAC1E;AACF;","names":[]}
@@ -0,0 +1,30 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type { ChildProcess } from 'node:child_process';
3
+ import type { RunningJobInfo } from '../job.js';
4
+ import { Future } from '../utils.js';
5
+ export interface ProcOpts {
6
+ initializeTimeout: number;
7
+ closeTimeout: number;
8
+ memoryWarnMB: number;
9
+ memoryLimitMB: number;
10
+ pingInterval: number;
11
+ pingTimeout: number;
12
+ highPingThreshold: number;
13
+ }
14
+ export declare abstract class SupervisedProc {
15
+ #private;
16
+ proc?: ChildProcess;
17
+ protected init: Future;
18
+ constructor(initializeTimeout: number, closeTimeout: number, memoryWarnMB: number, memoryLimitMB: number, pingInterval: number, pingTimeout: number, highPingThreshold: number);
19
+ abstract createProcess(): ChildProcess;
20
+ abstract mainTask(child: ChildProcess): Promise<void>;
21
+ get started(): boolean;
22
+ get runningJob(): RunningJobInfo | undefined;
23
+ start(): Promise<void>;
24
+ run(): Promise<void>;
25
+ join(): Promise<void>;
26
+ initialize(): Promise<void>;
27
+ close(): Promise<void>;
28
+ launchJob(info: RunningJobInfo): Promise<void>;
29
+ }
30
+ //# sourceMappingURL=supervised_proc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"supervised_proc.d.ts","sourceRoot":"","sources":["../../src/ipc/supervised_proc.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,MAAM,WAAW,QAAQ;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,8BAAsB,cAAc;;IAKlC,IAAI,CAAC,EAAE,YAAY,CAAC;IAIpB,SAAS,CAAC,IAAI,SAAgB;gBAK5B,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;IAa3B,QAAQ,CAAC,aAAa,IAAI,YAAY;IACtC,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAErD,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,UAAU,IAAI,cAAc,GAAG,SAAS,CAE3C;IAEK,KAAK;IAaL,GAAG;IAwEH,IAAI;IAQJ,UAAU;IAwBV,KAAK;IAuBL,SAAS,CAAC,IAAI,EAAE,cAAc;CAOrC"}