index.js 1.3 KB

12345678910111213141516171819202122232425
  1. const path = require("path");
  2. // Discriminated union: { isSupported: false } on non-darwin,
  3. // { isSupported: true, ...nativeFns } on darwin. Cross-platform consumers
  4. // (claude-cli-internal) require() unconditionally and narrow on isSupported.
  5. if (process.platform !== "darwin") {
  6. module.exports = { isSupported: false };
  7. } else {
  8. // COMPUTER_USE_INPUT_NODE_PATH: escape hatch for bundlers. Bun's --compile
  9. // embeds the .node as an asset, not in a node_modules tree — __dirname is
  10. // the exe dir and ../prebuilds/ doesn't exist. The consuming build bakes
  11. // this var to the embedded asset's path. Unset → normal node_modules layout.
  12. //
  13. // key()/keys() dispatch enigo work onto DispatchQueue.main via
  14. // dispatch2::run_on_main, then block a tokio worker on a channel. Under
  15. // Electron (CFRunLoop drains the main queue) this works; under libuv
  16. // (Node/bun) the main queue never drains and the promise hangs. Consumers
  17. // running under libuv must pump CFRunLoop while key()/keys() are pending —
  18. // e.g. claude-cli-internal borrows @ant/computer-use-swift's _drainMainRunLoop.
  19. const native = require(
  20. process.env.COMPUTER_USE_INPUT_NODE_PATH ??
  21. path.resolve(__dirname, "../prebuilds/computer-use-input.node"),
  22. );
  23. module.exports = { isSupported: true, ...native };
  24. }