Skip to content

Commit

Permalink
fix(job_main): import using URLs, not paths (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbsp authored Oct 5, 2024
1 parent 39669af commit 0a0e108
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-donkeys-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@livekit/agents": patch
---

fix usage on Windows by importing using URLs, not paths
6 changes: 3 additions & 3 deletions agents/src/ipc/job_main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { ChildProcess } from 'child_process';
import { fork } from 'child_process';
import { EventEmitter, once } from 'events';
import type { Logger } from 'pino';
import { fileURLToPath } from 'url';
import { pathToFileURL } from 'url';
import { type Agent, isAgent } from '../generator.js';
import type { RunningJobInfo } from '../job.js';
import { JobContext } from '../job.js';
Expand All @@ -28,7 +28,7 @@ type JobTask = {
};

export const runProcess = (args: StartArgs): ChildProcess => {
return fork(fileURLToPath(import.meta.url), [args.agentFile]);
return fork(new URL(import.meta.url), [args.agentFile]);
};

const startJob = (
Expand Down Expand Up @@ -94,7 +94,7 @@ if (process.send) {
// [1] import.meta.filename
// [2] import.meta.filename of function containing entry file
const moduleFile = process.argv[2];
const agent: Agent = await import(moduleFile).then((module) => {
const agent: Agent = await import(pathToFileURL(moduleFile).href).then((module) => {
const agent = module.default;
if (agent === undefined || !isAgent(agent)) {
throw new Error(`Unable to load agent: Missing or invalid default export in ${moduleFile}`);
Expand Down

0 comments on commit 0a0e108

Please sign in to comment.