Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shy-terms-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@livekit/agents': patch
---

Fork files with cjs extension when running cjs file
5 changes: 4 additions & 1 deletion agents/src/ipc/inference_proc_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 } = {};
Expand Down Expand Up @@ -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),
]);
}
Expand Down
7 changes: 6 additions & 1 deletion agents/src/ipc/job_proc_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions plugins/livekit/src/turn_detector/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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(),
);
1 change: 1 addition & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down