From 4cadfacd7e05656f36038d9cb560651cd8778b12 Mon Sep 17 00:00:00 2001 From: Christian Budde Christensen Date: Mon, 8 Dec 2025 10:22:55 +0000 Subject: [PATCH] fix: replace fork import file extension in cjs --- .changeset/shy-terms-rule.md | 5 +++++ agents/src/ipc/inference_proc_executor.ts | 5 ++++- agents/src/ipc/job_proc_executor.ts | 7 ++++++- plugins/livekit/src/turn_detector/index.ts | 7 +++++-- tsup.config.ts | 1 + 5 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 .changeset/shy-terms-rule.md diff --git a/.changeset/shy-terms-rule.md b/.changeset/shy-terms-rule.md new file mode 100644 index 000000000..f48245442 --- /dev/null +++ b/.changeset/shy-terms-rule.md @@ -0,0 +1,5 @@ +--- +'@livekit/agents': patch +--- + +Fork files with cjs extension when running cjs file diff --git a/agents/src/ipc/inference_proc_executor.ts b/agents/src/ipc/inference_proc_executor.ts index 6d6bfcb86..e4551caf4 100644 --- a/agents/src/ipc/inference_proc_executor.ts +++ b/agents/src/ipc/inference_proc_executor.ts @@ -3,6 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 import type { ChildProcess } from 'node:child_process'; import { fork } from 'node:child_process'; +import { extname } from 'node:path'; import { log } from '../log.js'; import { shortuuid } from '../utils.js'; import type { InferenceExecutor } from './inference_executor.js'; @@ -18,6 +19,8 @@ class PendingInference { } } +const currentFileExtension = extname(import.meta.url); + export class InferenceProcExecutor extends SupervisedProc implements InferenceExecutor { #runners: { [id: string]: string }; #activeRequests: { [id: string]: PendingInference } = {}; @@ -55,7 +58,7 @@ export class InferenceProcExecutor extends SupervisedProc implements InferenceEx } createProcess(): ChildProcess { - return fork(new URL('./inference_proc_lazy_main.js', import.meta.url), [ + return fork(new URL(`./inference_proc_lazy_main${currentFileExtension}`, import.meta.url), [ JSON.stringify(this.#runners), ]); } diff --git a/agents/src/ipc/job_proc_executor.ts b/agents/src/ipc/job_proc_executor.ts index b75ebc6df..a1a665935 100644 --- a/agents/src/ipc/job_proc_executor.ts +++ b/agents/src/ipc/job_proc_executor.ts @@ -3,6 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 import type { ChildProcess } from 'node:child_process'; import { fork } from 'node:child_process'; +import { extname } from 'node:path'; import type { RunningJobInfo } from '../job.js'; import { log } from '../log.js'; import type { InferenceExecutor } from './inference_executor.js'; @@ -11,6 +12,8 @@ import { JobStatus } from './job_executor.js'; import type { IPCMessage } from './message.js'; import { SupervisedProc } from './supervised_proc.js'; +const currentFileExtension = extname(import.meta.url); + export class JobProcExecutor extends SupervisedProc implements JobExecutor { #userArgs?: any; // eslint-disable-line @typescript-eslint/no-explicit-any #jobStatus?: JobStatus; @@ -64,7 +67,9 @@ export class JobProcExecutor extends SupervisedProc implements JobExecutor { } createProcess(): ChildProcess { - return fork(new URL('./job_proc_lazy_main.js', import.meta.url), [this.#agent]); + return fork(new URL(`./job_proc_lazy_main${currentFileExtension}`, import.meta.url), [ + this.#agent, + ]); } async mainTask(proc: ChildProcess) { diff --git a/plugins/livekit/src/turn_detector/index.ts b/plugins/livekit/src/turn_detector/index.ts index 5cc2632ac..8ffad4c1b 100644 --- a/plugins/livekit/src/turn_detector/index.ts +++ b/plugins/livekit/src/turn_detector/index.ts @@ -2,6 +2,7 @@ // // SPDX-License-Identifier: Apache-2.0 import { InferenceRunner } from '@livekit/agents'; +import { extname } from 'node:path'; import { INFERENCE_METHOD_EN } from './english.js'; import { INFERENCE_METHOD_MULTILINGUAL } from './multilingual.js'; @@ -10,12 +11,14 @@ export { EnglishModel } from './english.js'; export { MultilingualModel } from './multilingual.js'; export { getUnicodeCategory, normalizeText } from './utils.js'; +const currentFileExtension = extname(import.meta.url); + InferenceRunner.registerRunner( INFERENCE_METHOD_EN, - new URL('./english.js', import.meta.url).toString(), + new URL(`./english${currentFileExtension}`, import.meta.url).toString(), ); InferenceRunner.registerRunner( INFERENCE_METHOD_MULTILINGUAL, - new URL('./multilingual.js', import.meta.url).toString(), + new URL(`./multilingual${currentFileExtension}`, import.meta.url).toString(), ); diff --git a/tsup.config.ts b/tsup.config.ts index ced9ecd15..41db0cbf6 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -24,6 +24,7 @@ const defaultOptions: Options = { // require('../path') → require('../path.cjs') in `.cjs` files // from './path' → from './path.cjs' in `.cjs` files // from '../path' → from '../path.cjs' in `.cjs` files + // (0, import_node_child_process.fork)(new URL("./path.js" → (0, import_node_child_process.fork)(new URL("./path.cjs" in `.cjs` files name: 'fix-cjs-imports', renderChunk(code) { if (this.format === 'cjs') {