@trycua/cua-driver 0.35.2 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ export interface Availability {
2
+ isAvailable(): boolean;
3
+ }
4
+ export interface CreateDriverHooks {
5
+ platform?: NodeJS.Platform;
6
+ appInstalled?: () => boolean;
7
+ launch?: () => boolean;
8
+ timeoutMs?: number;
9
+ sleep?: (ms: number) => void;
10
+ warn?: (message: string) => void;
11
+ }
12
+ /** Reset the one-time warning (tests only). */
13
+ export declare function resetDaemonWarning(): void;
14
+ export declare function createDriver<T extends Availability>(connect: () => T, createEmbedded: () => T, embedded: boolean, claudeCodeCompatibility: boolean, hooks?: CreateDriverHooks): T;
package/dist/daemon.js ADDED
@@ -0,0 +1,59 @@
1
+ /**
2
+ * macOS daemon preference for `CuaDriver.create()`.
3
+ *
4
+ * An embedded (in-process) runtime on macOS has no AppKit host, so the agent
5
+ * cursor overlay cannot be drawn and permissions are attributed to the host
6
+ * process. The daemon (CuaDriver.app running `serve`) draws the cursor and owns
7
+ * the TCC grants, so on macOS `create()` connects to it, starting it through
8
+ * LaunchServices when the app is installed. No native dependency, so it is
9
+ * testable without the staged library.
10
+ */
11
+ import { spawnSync } from "node:child_process";
12
+ import { existsSync } from "node:fs";
13
+ const APP_NAME = "CuaDriver";
14
+ const APP_PATH = `/Applications/${APP_NAME}.app`;
15
+ const EMBEDDED_ENV = "CUA_DRIVER_EMBEDDED";
16
+ let warned = false;
17
+ /** Reset the one-time warning (tests only). */
18
+ export function resetDaemonWarning() {
19
+ warned = false;
20
+ }
21
+ function launchApp() {
22
+ const result = spawnSync("/usr/bin/open", ["-n", "-g", "-a", APP_NAME, "--args", "serve"], { stdio: "ignore" });
23
+ return result.status === 0;
24
+ }
25
+ function blockingSleep(ms) {
26
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
27
+ }
28
+ export function createDriver(connect, createEmbedded, embedded, claudeCodeCompatibility, hooks = {}) {
29
+ const platform = hooks.platform ?? process.platform;
30
+ if (embedded ||
31
+ claudeCodeCompatibility ||
32
+ platform !== "darwin" ||
33
+ process.env[EMBEDDED_ENV] === "1") {
34
+ return createEmbedded();
35
+ }
36
+ const driver = connect();
37
+ if (driver.isAvailable())
38
+ return driver;
39
+ const installed = (hooks.appInstalled ?? (() => existsSync(APP_PATH)))();
40
+ if (installed && (hooks.launch ?? launchApp)()) {
41
+ const sleep = hooks.sleep ?? blockingSleep;
42
+ const deadline = Date.now() + (hooks.timeoutMs ?? 15_000);
43
+ while (Date.now() < deadline) {
44
+ if (driver.isAvailable())
45
+ return driver;
46
+ sleep(250);
47
+ }
48
+ }
49
+ if (!warned) {
50
+ warned = true;
51
+ const message = "CuaDriver.create() is using the in-process runtime, which cannot draw " +
52
+ "the agent cursor on macOS and attributes permissions to this process. " +
53
+ "Install CuaDriver.app and run `cua-driver serve` (or call " +
54
+ "CuaDriver.connect()) to get the agent cursor, or pass " +
55
+ "{ embedded: true } to silence this warning.";
56
+ (hooks.warn ?? ((m) => process.emitWarning(m)))(message);
57
+ }
58
+ return createEmbedded();
59
+ }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,22 @@
1
+ /**
2
+ * Rust-backed SDK for Cua Driver client applications.
3
+ *
4
+ * Agents should configure `cua-driver mcp` through their runtime's existing
5
+ * MCP client instead of importing a language MCP facade.
6
+ */
7
+ import { CuaDriver as NativeCuaDriver, type CuaDriverLike, type DriverOptions } from "./native/cua_driver_sdk.js";
8
+ /**
9
+ * Options for `CuaDriver.create()`. `embedded: true` forces the in-process
10
+ * runtime on macOS, where `create()` otherwise prefers the CuaDriver.app
11
+ * daemon so the agent cursor overlay and the app's permissions work.
12
+ */
13
+ export type CreateOptions = DriverOptions & {
14
+ embedded?: boolean;
15
+ };
16
+ declare const CuaDriver: typeof NativeCuaDriver & {
17
+ create(options?: CreateOptions): CuaDriverLike;
18
+ };
19
+ type CuaDriver = NativeCuaDriver;
1
20
  export * from "./native/index.js";
21
+ export { CuaDriver };
2
22
  export { default } from "./native/index.js";
package/dist/index.js CHANGED
@@ -4,16 +4,22 @@
4
4
  * Agents should configure `cua-driver mcp` through their runtime's existing
5
5
  * MCP client instead of importing a language MCP facade.
6
6
  */
7
- import { CuaDriver, SdkClientKind } from "./native/cua_driver_sdk.js";
7
+ import { CuaDriver as NativeCuaDriver, SdkClientKind, } from "./native/cua_driver_sdk.js";
8
+ import { createDriver } from "./daemon.js";
9
+ const CuaDriver = NativeCuaDriver;
8
10
  // The same native library backs Python and TypeScript. The package root tags
9
11
  // both the canonical same-process constructor and the temporary daemon
10
12
  // compatibility constructor with the importing runtime.
11
- CuaDriver.create = (options) => CuaDriver.createWithClientKind(options, SdkClientKind.Typescript);
12
- CuaDriver.createConfigured = (options) => CuaDriver.createConfiguredWithClientKind(options, SdkClientKind.Typescript);
13
- CuaDriver.createConfiguredWithAuthorizationHost = (options, host) => CuaDriver.createConfiguredWithAuthorizationHostAndClientKind(options, host, SdkClientKind.Typescript);
14
- CuaDriver.createConfiguredWithActivityObserver = (options, observer) => CuaDriver.createConfiguredWithActivityObserverAndClientKind(options, observer, SdkClientKind.Typescript);
15
- CuaDriver.createConfiguredWithHostIntegrations = (options, host, observer) => CuaDriver.createConfiguredWithHostIntegrationsAndClientKind(options, host, observer, SdkClientKind.Typescript);
16
- CuaDriver.createPrivateWorker = (options) => CuaDriver.createPrivateWorkerWithClientKind(options, SdkClientKind.Typescript);
17
- CuaDriver.connect = (socketPath) => CuaDriver.connectWithClientKind(socketPath, SdkClientKind.Typescript);
13
+ NativeCuaDriver.create = (options) => {
14
+ const { embedded, ...driverOptions } = options ?? {};
15
+ return createDriver(() => NativeCuaDriver.connectWithClientKind(undefined, SdkClientKind.Typescript), () => NativeCuaDriver.createWithClientKind(options === undefined ? undefined : driverOptions, SdkClientKind.Typescript), embedded === true, driverOptions.claudeCodeCompatibility === true);
16
+ };
17
+ NativeCuaDriver.createConfigured = (options) => NativeCuaDriver.createConfiguredWithClientKind(options, SdkClientKind.Typescript);
18
+ NativeCuaDriver.createConfiguredWithAuthorizationHost = (options, host) => NativeCuaDriver.createConfiguredWithAuthorizationHostAndClientKind(options, host, SdkClientKind.Typescript);
19
+ NativeCuaDriver.createConfiguredWithActivityObserver = (options, observer) => NativeCuaDriver.createConfiguredWithActivityObserverAndClientKind(options, observer, SdkClientKind.Typescript);
20
+ NativeCuaDriver.createConfiguredWithHostIntegrations = (options, host, observer) => NativeCuaDriver.createConfiguredWithHostIntegrationsAndClientKind(options, host, observer, SdkClientKind.Typescript);
21
+ NativeCuaDriver.createPrivateWorker = (options) => NativeCuaDriver.createPrivateWorkerWithClientKind(options, SdkClientKind.Typescript);
22
+ NativeCuaDriver.connect = (socketPath) => NativeCuaDriver.connectWithClientKind(socketPath, SdkClientKind.Typescript);
18
23
  export * from "./native/index.js";
24
+ export { CuaDriver };
19
25
  export { default } from "./native/index.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycua/cua-driver",
3
- "version": "0.35.2",
3
+ "version": "0.36.0",
4
4
  "description": "Rust-backed Cua Driver SDK and embedded Node host",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -38,7 +38,9 @@
38
38
  "dist/fleet.js",
39
39
  "dist/fleet.d.ts",
40
40
  "dist/native",
41
- "README.md"
41
+ "README.md",
42
+ "dist/daemon.js",
43
+ "dist/daemon.d.ts"
42
44
  ],
43
45
  "publishConfig": {
44
46
  "access": "public"
@@ -48,11 +50,11 @@
48
50
  "@ubjs/node": "0.31.0-3"
49
51
  },
50
52
  "optionalDependencies": {
51
- "@trycua/cua-driver-darwin-arm64": "0.35.2",
52
- "@trycua/cua-driver-darwin-x64": "0.35.2",
53
- "@trycua/cua-driver-linux-arm64-gnu": "0.35.2",
54
- "@trycua/cua-driver-linux-x64-gnu": "0.35.2",
55
- "@trycua/cua-driver-win32-arm64-msvc": "0.35.2",
56
- "@trycua/cua-driver-win32-x64-msvc": "0.35.2"
53
+ "@trycua/cua-driver-darwin-arm64": "0.36.0",
54
+ "@trycua/cua-driver-darwin-x64": "0.36.0",
55
+ "@trycua/cua-driver-linux-arm64-gnu": "0.36.0",
56
+ "@trycua/cua-driver-linux-x64-gnu": "0.36.0",
57
+ "@trycua/cua-driver-win32-arm64-msvc": "0.36.0",
58
+ "@trycua/cua-driver-win32-x64-msvc": "0.36.0"
57
59
  }
58
60
  }