Files
oh-my-pi/packages/coding-agent/test/fixtures/compiled-worker-selector-host.ts
can1357 ef852af986 feat(computer): implemented modular desktop backend and script workflows
- Replaced monolithic desktop native bindings and action batching with a modular cross-platform backend structure supporting Wayland, X11, macOS, and Win32.
- Updated the computer tool schema and supervisor to execute persistent JavaScript script runs with timeout clamping and asynchronous tool calling.
- Integrated accessibility (AX) tree snapshotting, node querying, and bounds-based hit testing across platform desktop layers.
- Added native clipboard bindings and updated coding-agent prompts, renderers, and tests to validate script-based computer workflows.
2026-08-02 19:46:25 +02:00

36 lines
1.4 KiB
TypeScript

import { parentPort } from "node:worker_threads";
import { installWorkerInbox, WORKER_HOST_SELECTOR_PREFIX } from "@oh-my-pi/pi-utils/worker-host";
import { COMPUTER_WORKER_ARG } from "../../src/tools/computer/protocol";
const STATS_WORKER_ARG = `${WORKER_HOST_SELECTOR_PREFIX}stats_sync`;
declare const self: Worker & {
onmessage: ((event: MessageEvent<{ kind: "ping" }>) => void) | null;
};
if (Bun.isMainThread) {
const worker = new Worker(Bun.main, { type: "module", argv: [STATS_WORKER_ARG] });
const response = Promise.withResolvers<unknown>();
worker.addEventListener("message", event => response.resolve(event.data));
worker.addEventListener("error", event => response.reject(event.error ?? new Error(event.message)));
worker.postMessage({ kind: "ping" });
try {
process.stdout.write(`${JSON.stringify(await response.promise)}\n`);
} finally {
worker.terminate();
}
} else {
const selector = process.argv.find(arg => arg.startsWith(WORKER_HOST_SELECTOR_PREFIX));
if (selector === COMPUTER_WORKER_ARG) {
if (!parentPort) throw new Error("compiled worker fixture: missing parentPort");
installWorkerInbox(parentPort);
await import("../../src/tools/computer/worker-entry");
} else if (selector === STATS_WORKER_ARG) {
self.onmessage = (_event: MessageEvent<{ kind: "ping" }>) => {
self.postMessage({ ok: true, kind: "pong" });
};
} else {
throw new Error(`unknown worker selector: ${selector}`);
}
}