Files
oh-my-pi/packages/coding-agent/src/eval/js/worker-entry.ts
T
can1357 a7209c2b4f feat(coding-agent-eval): added worker-backed JS runtime with queued runs
- Added worker-backed JS runtime via Transport and WorkerCore, with queued runs, status/error output, and clean teardown.
- Refactored executeInVmContext to reuse worker sessions, route pending runs by id, and fallback inline on spawn failure.
- Added rewrite helpers to convert top-level imports and demote top-level const/let/class declarations for persistence.
- Handled aborts by canceling in-flight tool calls, hard-killing worker sessions, and dropping JS timeout enforcement.
2026-05-12 07:20:43 +02:00

25 lines
648 B
TypeScript

import { parentPort } from "node:worker_threads";
import { WorkerCore } from "./worker-core";
import type { Transport, WorkerInbound, WorkerOutbound } from "./worker-protocol";
if (!parentPort) throw new Error("js worker-entry: missing parentPort");
const port = parentPort;
const transport: Transport = {
send: (msg: WorkerOutbound) => port.postMessage(msg),
onMessage: handler => {
const wrap = (data: unknown): void => handler(data as WorkerInbound);
port.on("message", wrap);
return () => port.off("message", wrap);
},
close: () => {
try {
port.close();
} catch {
// Already closed.
}
},
};
new WorkerCore(transport);