Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

feat(cua-driver)!: replace language MCP clients with Rust SDKs (#2341)

Francesco Bonaccib8a0f32a06c7
diff --git a/.github/scripts/tests/test_cua_driver_release_wiring.py b/.github/scripts/tests/test_cua_driver_release_wiring.py
index 037fc52a82..0b44efd0ad 100644
--- a/.github/scripts/tests/test_cua_driver_release_wiring.py
+++ b/.github/scripts/tests/test_cua_driver_release_wiring.py
@@ -178,6 +178,10 @@ class TestCuaDriverReleaseWiring(unittest.TestCase):
self.assertIn('"path": "rust/Cargo.toml"', config)
self.assertIn('"path": "python/pyproject.toml"', config)
self.assertIn('"path": "python/src/cua_driver/__init__.py"', config)
+ self.assertIn('"path": "typescript/package.json"', config)
+ self.assertEqual(
+ config.count('"path": "typescript/package-lock.json"'), 2
+ )
self.assertIn('"path": "scripts/_install-rust.sh"', config)
self.assertIn('"path": "scripts/install.ps1"', config)
self.assertIn('"path": "rust/Skills/cua-driver/SKILL.md"', config)
diff --git a/.github/scripts/validate_release_versions.py b/.github/scripts/validate_release_versions.py
index 6111b405f7..8435903494 100644
--- a/.github/scripts/validate_release_versions.py
+++ b/.github/scripts/validate_release_versions.py
@@ -40,12 +40,23 @@ def driver_versions(root: Path) -> tuple[str, dict[str, str]]:
expected = (base / "rust/VERSION").read_text().strip()
cargo = tomllib.loads((base / "rust/Cargo.toml").read_text())
python_project = tomllib.loads((base / "python/pyproject.toml").read_text())
+ typescript_package = json.loads(
+ (base / "typescript/package.json").read_text()
+ )
+ typescript_lock = json.loads(
+ (base / "typescript/package-lock.json").read_text()
+ )
values = {
"rust/Cargo.toml": str(cargo["workspace"]["package"]["version"]),
"python/pyproject.toml": str(python_project["project"]["version"]),
"python/src/cua_driver/__init__.py": read_match(
base / "python/src/cua_driver/__init__.py", r'^__version__\s*=\s*"([^"]+)"'
),
+ "typescript/package.json": str(typescript_package["version"]),
+ "typescript/package-lock.json": str(typescript_lock["version"]),
+ "typescript/package-lock.json:root": str(
+ typescript_lock["packages"][""]["version"]
+ ),
"scripts/_install-rust.sh": read_match(
base / "scripts/_install-rust.sh", r'^CUA_DRIVER_RS_BAKED_VERSION="([^"]+)"'
),
diff --git a/.github/workflows/cd-py-cua-driver.yml b/.github/workflows/cd-py-cua-driver.yml
index cd3727f15c..3f03c41b72 100644
--- a/.github/workflows/cd-py-cua-driver.yml
+++ b/.github/workflows/cd-py-cua-driver.yml
@@ -129,6 +129,12 @@ jobs:
cd libs/cua-driver/python
python build_wheel.py --version "${{ needs.get-version.outputs.version }}" --arch "${{ matrix.arch }}"
+ - name: Load generated UniFFI bindings from the built wheel
+ shell: bash
+ run: |
+ python -m pip install --force-reinstall libs/cua-driver/python/dist/*.whl
+ python -c "from cua_driver import CuaDriver; print(CuaDriver.connect(None).socket_path())"
+
- name: List built artifacts
shell: bash
run: |
diff --git a/.github/workflows/cd-rust-cua-driver.yml b/.github/workflows/cd-rust-cua-driver.yml
index f7e88fe874..7f16ce518c 100644
--- a/.github/workflows/cd-rust-cua-driver.yml
+++ b/.github/workflows/cd-rust-cua-driver.yml
@@ -120,7 +120,7 @@ jobs:
rust-cua-driver-rs-linux-${{ matrix.arch }}-
- name: Build (release)
working-directory: libs/cua-driver/rust
- run: cargo build --locked -p cua-driver --release --features portal-input --target ${{ matrix.target }}
+ run: cargo build --locked -p cua-driver -p cua-driver-sdk --release --features cua-driver/portal-input --target ${{ matrix.target }}
- name: Package
working-directory: libs/cua-driver/rust
run: |
@@ -130,11 +130,13 @@ jobs:
STAGE="cua-driver-rs-${VERSION}-${LABEL}"
mkdir -p "release/${STAGE}"
cp "target/${TARGET}/release/cua-driver" "release/${STAGE}/"
+ cp "target/${TARGET}/release/libcua_driver_sdk.so" "release/${STAGE}/"
cp ../../LICENSE.md "release/${STAGE}/LICENSE" 2>/dev/null || true
(cd release && tar -czf "${STAGE}.tar.gz" "${STAGE}")
- # Bare binary tarball — single file (cua-driver) at the archive root,
- # mirroring the Swift cua-driver `*-binary.tar.gz` convention.
- tar -czf "release/${STAGE}-binary.tar.gz" -C "release/${STAGE}" cua-driver
+ # Bare runtime tarball: CLI plus the UniFFI library consumed by the
+ # Python and Node imported-SDK packages.
+ tar -czf "release/${STAGE}-binary.tar.gz" -C "release/${STAGE}" \
+ cua-driver libcua_driver_sdk.so
ls -lh "release/${STAGE}.tar.gz" "release/${STAGE}-binary.tar.gz"
- uses: actions/upload-artifact@v4
with:
@@ -200,7 +202,7 @@ jobs:
# `cua-driver-uia.exe` is the Windows-only sibling daemon that runs
# at UIAccess integrity so SendInput / UI Automation can cross UIPI
# into UWP apps — see crates/cua-driver-uia/ and #1602.
- run: cargo build --locked -p cua-driver -p cua-driver-uia --release --target ${{ matrix.target }}
+ run: cargo build --locked -p cua-driver -p cua-driver-uia -p cua-driver-sdk --release --target ${{ matrix.target }}
- name: Package
working-directory: libs/cua-driver/rust
shell: pwsh
@@ -212,6 +214,7 @@ jobs:
New-Item -ItemType Directory -Force -Path "release/$stage" | Out-Null
Copy-Item "target/$target/release/cua-driver.exe" "release/$stage/"
Copy-Item "target/$target/release/cua-driver-uia.exe" "release/$stage/"
+ Copy-Item "target/$target/release/cua_driver_sdk.dll" "release/$stage/"
if (Test-Path "../../LICENSE.md") { Copy-Item "../../LICENSE.md" "release/$stage/LICENSE" }
# Zip the directory itself (no trailing /*) so the archive contains
# the top-level "$stage" wrapper dir — install.ps1 walks into
@@ -226,7 +229,7 @@ jobs:
# to UIAccess integrity on a default-policy machine. The main CLI/MCP
# binary stays fully functional regardless; uia is opt-in dead-weight
# until signed.
- Compress-Archive -Path "release/$stage/cua-driver.exe","release/$stage/cua-driver-uia.exe" -DestinationPath "release/$stage-binary.zip" -Force
+ Compress-Archive -Path "release/$stage/cua-driver.exe","release/$stage/cua-driver-uia.exe","release/$stage/cua_driver_sdk.dll" -DestinationPath "release/$stage-binary.zip" -Force
Get-ChildItem "release/$stage*.zip"
- uses: actions/upload-artifact@v4
with:
@@ -318,18 +321,24 @@ jobs:
rust-cua-driver-rs-darwin-universal-
- name: Build arm64
working-directory: libs/cua-driver/rust
- run: cargo build --locked -p cua-driver --release --target aarch64-apple-darwin
+ run: cargo build --locked -p cua-driver -p cua-driver-sdk --release --target aarch64-apple-darwin
- name: Build x86_64
working-directory: libs/cua-driver/rust
- run: cargo build --locked -p cua-driver --release --target x86_64-apple-darwin
+ run: cargo build --locked -p cua-driver -p cua-driver-sdk --release --target x86_64-apple-darwin
- name: Create universal binary (lipo)
working-directory: libs/cua-driver/rust
run: |
ARM64="target/aarch64-apple-darwin/release/cua-driver"
X86="target/x86_64-apple-darwin/release/cua-driver"
+ SDK_ARM64="target/aarch64-apple-darwin/release/libcua_driver_sdk.dylib"
+ SDK_X86="target/x86_64-apple-darwin/release/libcua_driver_sdk.dylib"
mkdir -p release/universal
lipo -create "$ARM64" "$X86" -output release/universal/cua-driver
+ lipo -create "$SDK_ARM64" "$SDK_X86" -output release/universal/libcua_driver_sdk.dylib
lipo -info release/universal/cua-driver
+ lipo -info release/universal/libcua_driver_sdk.dylib
+ test "$(otool -D release/universal/libcua_driver_sdk.dylib | tail -n 1)" = \
+ '@rpath/libcua_driver_sdk.dylib'
- name: Codesign universal binary (hardened runtime)
if: env.DO_NOTARIZE == 'true'
working-directory: libs/cua-driver/rust
@@ -341,7 +350,10 @@ jobs:
codesign --force --timestamp --options runtime \
--entitlements scripts/CuaDriver.entitlements \
--sign "$IDENTITY" release/universal/cua-driver
+ codesign --force --timestamp --options runtime \
+ --sign "$IDENTITY" release/universal/libcua_driver_sdk.dylib
codesign --verify --strict --verbose=2 release/universal/cua-driver
+ codesign --verify --strict --verbose=2 release/universal/libcua_driver_sdk.dylib
- name: Assemble CuaDriver.app bundle
working-directory: libs/cua-driver/rust
run: |
@@ -426,6 +438,7 @@ jobs:
# that download by arch still get the universal slice
# (matches the Swift `cd-swift-cua-driver.yml` convention).
cp release/universal/cua-driver "release/${STAGE}/"
+ cp release/universal/libcua_driver_sdk.dylib "release/${STAGE}/"
# Ship the .app bundle in every macOS tarball so install.sh
# can drop it into /Applications/CuaDriver.app for TCC
# attribution (issue #1525). Tarball callers that want only
@@ -434,12 +447,10 @@ jobs:
cp ../../LICENSE.md "release/${STAGE}/LICENSE" 2>/dev/null || true
(cd release && tar -czf "${STAGE}.tar.gz" "${STAGE}")
done
- # Bare universal binary — single-file tarball matching Swift's
- # `cua-driver-${VERSION}-darwin-universal-binary.tar.gz`. NO
- # bundle here: callers that fetch the bare tarball deliberately
- # skipped the .app workflow.
+ # Bare runtime tarball: universal CLI plus universal UniFFI library.
+ # No app bundle: callers of this asset deliberately skip that flow.
tar -czf "release/cua-driver-rs-${VERSION}-darwin-universal-binary.tar.gz" \
- -C release/universal cua-driver
+ -C release/universal cua-driver libcua_driver_sdk.dylib
ls -lh release/*.tar.gz
- uses: actions/upload-artifact@v4
with:
diff --git a/.github/workflows/ci-cua-driver-contract-clients.yml b/.github/workflows/ci-cua-driver-contract-clients.yml
new file mode 100644
index 0000000000..ecdcb76ee8
--- /dev/null
+++ b/.github/workflows/ci-cua-driver-contract-clients.yml
@@ -0,0 +1,180 @@
+name: "CI: cua-driver contract clients"
+
+on:
+ pull_request:
+ paths:
+ - "libs/cua-driver/contract/**"
+ - "libs/cua-driver/examples/agent-sdks/**"
+ - "libs/cua-driver/typescript/**"
+ - "libs/cua-driver/python/**"
+ - "libs/cua-driver/rust/Cargo.toml"
+ - "libs/cua-driver/rust/Cargo.lock"
+ - "libs/cua-driver/rust/crates/cua-driver/**"
+ - "libs/cua-driver/rust/crates/cua-driver-contract/**"
+ - "libs/cua-driver/rust/crates/cua-driver-bindgen/**"
+ - "libs/cua-driver/rust/crates/cua-driver-core/**"
+ - "libs/cua-driver/rust/crates/cua-driver-sdk/**"
+ - "libs/cua-driver/rust/crates/cua-driver-testkit/**"
+ - "libs/cua-driver/rust/crates/platform-linux/**"
+ - "libs/cua-driver/rust/crates/platform-macos/**"
+ - "libs/cua-driver/rust/crates/platform-windows/**"
+ - "libs/cua-driver/scripts/generate-uniffi-bindings.mjs"
+ - "libs/cua-driver/scripts/stage-uniffi-library.mjs"
+ - ".github/workflows/ci-cua-driver-contract-clients.yml"
+ push:
+ branches: [main]
+ paths:
+ - "libs/cua-driver/contract/**"
+ - "libs/cua-driver/examples/agent-sdks/**"
+ - "libs/cua-driver/typescript/**"
+ - "libs/cua-driver/python/**"
+ - "libs/cua-driver/rust/Cargo.toml"
+ - "libs/cua-driver/rust/Cargo.lock"
+ - "libs/cua-driver/rust/crates/cua-driver/**"
+ - "libs/cua-driver/rust/crates/cua-driver-contract/**"
+ - "libs/cua-driver/rust/crates/cua-driver-bindgen/**"
+ - "libs/cua-driver/rust/crates/cua-driver-core/**"
+ - "libs/cua-driver/rust/crates/cua-driver-sdk/**"
+ - "libs/cua-driver/rust/crates/cua-driver-testkit/**"
+ - "libs/cua-driver/rust/crates/platform-linux/**"
+ - "libs/cua-driver/rust/crates/platform-macos/**"
+ - "libs/cua-driver/rust/crates/platform-windows/**"
+ - "libs/cua-driver/scripts/generate-uniffi-bindings.mjs"
+ - "libs/cua-driver/scripts/stage-uniffi-library.mjs"
+ - ".github/workflows/ci-cua-driver-contract-clients.yml"
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+concurrency:
+ group: ci-cua-driver-contract-clients-${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ runtime-parity:
+ name: Portable contract parity (${{ matrix.os }})
+ runs-on: ${{ matrix.os }}
+ timeout-minutes: 30
+ strategy:
+ fail-fast: false
+ matrix:
+ os: [ubuntu-latest, macos-latest, windows-latest]
+ steps:
+ - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
+ - uses: dtolnay/rust-toolchain@stable
+ - uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2
+ with:
+ workspaces: "libs/cua-driver/rust -> target"
+ - name: Install Linux build dependencies
+ if: runner.os == 'Linux'
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y --no-install-recommends \
+ clang pkg-config libdbus-1-dev libpipewire-0.3-dev libspa-0.2-dev \
+ libei-dev libxkbcommon-dev libx11-dev libxi-dev libxtst-dev libxext-dev
+ - name: Prove portable contracts match the live registry
+ working-directory: libs/cua-driver/rust
+ run: cargo test --locked -p cua-driver --test schema_consistency_test portable_desktop_contracts_are_accepted_by_active_backend
+
+ - name: Compile the UniFFI SDK library
+ working-directory: libs/cua-driver/rust
+ run: cargo check --locked -p cua-driver-sdk
+
+ verify:
+ name: Generated contract and SDK bindings
+ runs-on: ubuntu-latest
+ timeout-minutes: 15
+ steps:
+ - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
+ - uses: dtolnay/rust-toolchain@stable
+ - uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2
+ with:
+ workspaces: "libs/cua-driver/rust -> target"
+ - uses: actions/setup-python@v5
+ with:
+ python-version: "3.12"
+ - uses: actions/setup-node@v4
+ with:
+ node-version: "22"
+ cache: npm
+ cache-dependency-path: |
+ libs/cua-driver/typescript/package-lock.json
+ libs/cua-driver/examples/agent-sdks/package-lock.json
+
+ - name: Install TypeScript SDK dependencies
+ working-directory: libs/cua-driver/typescript
+ run: npm ci
+
+ - name: Verify generated files
+ working-directory: libs/cua-driver/rust
+ run: cargo run --locked -p cua-driver-contract --bin cua-contract-gen -- all --check
+
+ - name: Verify generated UniFFI bindings
+ working-directory: libs/cua-driver
+ run: node scripts/generate-uniffi-bindings.mjs --check
+
+ - name: Test contract crate
+ working-directory: libs/cua-driver/rust
+ run: cargo test --locked -p cua-driver-contract
+
+ - name: Test UniFFI Rust implementation
+ working-directory: libs/cua-driver/rust
+ run: cargo test --locked -p cua-driver-sdk
+
+ - name: Test live contract parity
+ working-directory: libs/cua-driver/rust
+ run: cargo test --locked -p cua-driver-core --test contract_parity
+
+ - name: Test Python release packaging helpers
+ working-directory: libs/cua-driver/python
+ run: |
+ python -m pip install pytest
+ python -m pytest tests/test_build_wheel.py -q
+
+ - name: Build and stage host-native UniFFI library
+ working-directory: libs/cua-driver
+ run: |
+ npm --prefix typescript run build
+ node scripts/stage-uniffi-library.mjs
+
+ - name: Test Python UniFFI loader
+ working-directory: libs/cua-driver/python
+ run: CUA_DRIVER_REQUIRE_UNIFFI=1 PYTHONPATH=src python -m unittest tests/test_uniffi_loader.py -v
+
+ - name: Test TypeScript SDK
+ working-directory: libs/cua-driver/typescript
+ run: npm run typecheck && CUA_DRIVER_REQUIRE_UNIFFI=1 npm test && npm audit --audit-level=high
+
+ - name: Verify Python native package contents
+ working-directory: libs/cua-driver
+ run: |
+ python -m pip install build hatchling
+ CUA_DRIVER_WHEEL_TAG=py3-none-manylinux_2_31_x86_64 \
+ python -m build --wheel --outdir /tmp/cua-driver-wheels python
+ unzip -l /tmp/cua-driver-wheels/*.whl | grep -F 'cua_driver/libcua_driver_sdk.so'
+ python -m pip install --target /tmp/cua-driver-wheel-smoke /tmp/cua-driver-wheels/*.whl
+ PYTHONPATH=/tmp/cua-driver-wheel-smoke python -c \
+ "from cua_driver import CuaDriver; print(CuaDriver.connect(None).socket_path())"
+
+ - name: Verify Node native package contents
+ working-directory: libs/cua-driver/typescript
+ run: |
+ mkdir -p /tmp/cua-driver-npm/smoke
+ npm pack --pack-destination /tmp/cua-driver-npm
+ tar -tzf /tmp/cua-driver-npm/*.tgz | grep -F 'package/dist/native/libcua_driver_sdk.so'
+ npm install --prefix /tmp/cua-driver-npm/smoke /tmp/cua-driver-npm/*.tgz
+ cd /tmp/cua-driver-npm/smoke
+ node --input-type=module -e \
+ "const sdk = await import('@trycua/cua-driver'); const driver = sdk.CuaDriver.connect(undefined); console.log(driver.socketPath()); driver.uniffiDestroy()"
+
+ - name: Check Python agent SDK example
+ run: python -m py_compile libs/cua-driver/examples/agent-sdks/claude_agent.py
+
+ - name: Install agent SDK example dependencies
+ working-directory: libs/cua-driver/examples/agent-sdks
+ run: npm ci
+
+ - name: Check TypeScript agent SDK example
+ working-directory: libs/cua-driver/examples/agent-sdks
+ run: npm run typecheck
diff --git a/.github/workflows/ci-rust-linux.yml b/.github/workflows/ci-rust-linux.yml
index c00d2c70fe..a3e78602c0 100644
--- a/.github/workflows/ci-rust-linux.yml
+++ b/.github/workflows/ci-rust-linux.yml
@@ -7,6 +7,7 @@ on:
- "libs/cua-driver/rust/Cargo.toml"
- "libs/cua-driver/rust/Cargo.lock"
- "libs/cua-driver/rust/crates/cua-driver/**"
+ - "libs/cua-driver/rust/crates/cua-driver-contract/**"
- "libs/cua-driver/rust/crates/cua-driver-core/**"
- "libs/cua-driver/rust/crates/cua-driver-testkit/**"
- "libs/cua-driver/rust/crates/cursor-overlay/**"
@@ -24,6 +25,7 @@ on:
- "libs/cua-driver/rust/Cargo.toml"
- "libs/cua-driver/rust/Cargo.lock"
- "libs/cua-driver/rust/crates/cua-driver/**"
+ - "libs/cua-driver/rust/crates/cua-driver-contract/**"
- "libs/cua-driver/rust/crates/cua-driver-core/**"
- "libs/cua-driver/rust/crates/cua-driver-testkit/**"
- "libs/cua-driver/rust/crates/cursor-overlay/**"
@@ -62,7 +64,7 @@ jobs:
libei-dev libxkbcommon-dev libx11-dev libxi-dev libxtst-dev libxext-dev
- name: Run Linux Rust tests
working-directory: libs/cua-driver/rust
- run: cargo test -p cua-driver -p cua-driver-core -p cua-driver-testkit -p platform-linux --all-targets --locked
+ run: cargo test -p cua-driver -p cua-driver-contract -p cua-driver-core -p cua-driver-testkit -p platform-linux --all-targets --locked
- name: Compile portable GNOME/KDE portal input
working-directory: libs/cua-driver/rust
run: cargo check -p cua-driver --features portal-input --locked
diff --git a/docs/content/docs/reference/cua-driver/mcp-tools.mdx b/docs/content/docs/reference/cua-driver/mcp-tools.mdx
index 2a1eeb8874..b05c08555d 100644
--- a/docs/content/docs/reference/cua-driver/mcp-tools.mdx
+++ b/docs/content/docs/reference/cua-driver/mcp-tools.mdx
@@ -106,13 +106,17 @@ Capture a full-display vision screenshot in true screen pixels (no downscale), f
Return the logical size of the main display in points plus its backing scale factor. Agents click in points; Retina displays have scale_factor 2.0. Requires no TCC permissions.
-**Arguments:** none.
+**Arguments:**
+
+- `session` (string, optional): Optional session id: declares/uses the agent cursor and per-session state for this run. The same id works over MCP, the CLI, or the raw socket, and follows the run across apps/windows. Omit to run cursor-less.
### `get_cursor_position`
Return the current mouse cursor position in screen points (origin top-left).
-**Arguments:** none.
+**Arguments:**
+
+- `session` (string, optional): Optional session id: declares/uses the agent cursor and per-session state for this run. The same id works over MCP, the CLI, or the raw socket, and follows the run across apps/windows. Omit to run cursor-less.
### `get_config`
diff --git a/libs/cua-driver/README.md b/libs/cua-driver/README.md
index 1fad5d536d..2206d3362f 100644
--- a/libs/cua-driver/README.md
+++ b/libs/cua-driver/README.md
@@ -4,12 +4,28 @@ Background computer-use driver for any agents. Speaks MCP over stdio; drives nat
**[Documentation](https://cua.ai/docs/cua-driver)** - Installation, guides, and API reference.
+## Integration surfaces
+
+- **Cua as an agent MCP or CLI:** MCP-capable agents connect directly to
+ `cua-driver mcp`; shell-oriented agents and automation can use
+ `cua-driver call`. No generated Cua language client is required.
+- **Cua as an application SDK:** Python applications import `cua_driver`;
+ TypeScript applications import `@trycua/cua-driver`. Both package roots call
+ one Rust daemon-client implementation through UniFFI.
+
+The language packages are for client applications, not agents. They contain no
+language-native MCP facade and have no `/sdk`, `/mcp`, or `/native` public
+suffix. MCP remains implemented by the `cua-driver` executable as the
+runtime-neutral agent boundary.
+
## Repository Layout
| Path | Purpose |
| ------------------------------- | ---------------------------------------------------------------------- |
-| `rust/` | Cargo workspace for the driver daemon, platform crates, and Rust tests |
-| `python/` | Python package wrapper and package tests |
+| `rust/` | Cargo workspace for the daemon, UniFFI SDK, platform crates, and tests |
+| `python/` | Python SDK, bundled-binary wrapper, and package tests |
+| `contract/` | Experimental generated SDK contract and fixtures |
+| `typescript/` | Generated TypeScript SDK |
| `tests/fixtures/` | Source-built GUI harness apps and shared fixtures |
| `rust/crates/cua-driver/tests/` | Rust integration tests for the driver and GUI harnesses |
| `scripts/` | Install, uninstall, local build, and VM sync helpers |
@@ -18,6 +34,20 @@ Background computer-use driver for any agents. Speaks MCP over stdio; drives nat
Start with `rust/README.md`, `rust/crates/cua-driver/tests/README.md`, and
`tests/fixtures/README.md` when changing driver behavior or tests.
+The contract-first SDK architecture is documented in
+[`contract/README.md`](contract/README.md). The Rust contract crate generates
+the checked-in manifest and supplies the typed inputs used by the live daemon
+and UniFFI SDK.
+
+The imported SDK bindings are generated by
+`scripts/generate-uniffi-bindings.mjs`. It calls the same daemon through the
+shared Rust socket protocol; it does not embed the OS automation engine.
+
+For direct agent integrations, see the
+[`examples/agent-sdks`](examples/agent-sdks/README.md) Codex and Claude Agent
+SDK examples. They connect the agent to `cua-driver mcp` without importing a
+generated Cua client.
+
Contributor documentation:
- `docs/test-matrix.md` maps unit and canonical harness E2E suites.
diff --git a/libs/cua-driver/contract/README.md b/libs/cua-driver/contract/README.md
new file mode 100644
index 0000000000..7d1c0d823b
--- /dev/null
+++ b/libs/cua-driver/contract/README.md
@@ -0,0 +1,86 @@
+# Experimental cua-driver SDK contract
+
+This directory contains the checked-in, generated contract for the first
+portable cua-driver SDK slice. The Rust crate at
+`rust/crates/cua-driver-contract` is the source of truth. It generates this
+manifest and exports the request/result records consumed by the live daemon and
+the UniFFI SDK. Python and TypeScript bindings are generated from the compiled
+Rust library by `scripts/generate-uniffi-bindings.mjs`.
+
+The prototype intentionally keeps execution, platform integration, policy, and
+permission handling in the native Cua Driver process. Imported SDKs call the
+daemon through the shared Rust socket client; they do not route through MCP or
+embed platform code. Agents independently use the public `cua-driver mcp`
+surface through their runtime's existing MCP client.
+
+## Scope and compatibility
+
+The typed slice covers the cross-platform session lifecycle tools:
+
+- `start_session`
+- `escalate_session`
+- `get_session_state`
+- `end_session`
+
+It also covers the portable whole-desktop loop:
+
+- `get_desktop_state`
+- `get_screen_size`
+- `get_cursor_position`
+- `move_cursor` with the required `scope="desktop"`
+- `click` with the required `scope="desktop"`
+- `drag` and `scroll` in native desktop coordinates
+- `type_text`, `press_key`, and `hotkey` against the foreground application
+
+Session contracts are marked `canonical_runtime`: the same typed Rust input,
+output, and metadata declaration builds the live MCP tool. Desktop contracts
+are marked `portable_subset`: their typed Rust inputs are a deliberately
+narrower projection of the richer macOS, Linux, and Windows runtime schemas.
+Each platform's desktop branch deserializes that projection before acting,
+while window/element-only fields remain in the richer live schema. Successful
+SDK-path structured payloads are validated against the shared Rust output
+types in the live registry.
+
+The platform schemas remain richer by design; they are not an independent SDK
+manifest. A cross-platform CI matrix proves every portable schema is accepted
+by each live registry, and the published tools resolve their capability tokens
+from the contract rather than a second runtime map.
+
+Both SDKs retain a generic tool call so runtime-discovered and
+platform-specific tools remain usable. The generated manifest records tool
+platforms, capabilities, annotations, input schemas, and experimental success
+schemas. Success schemas are not advertised as live MCP `outputSchema` values
+until every transport path has passed parity tests.
+
+Compatibility is tracked separately at each boundary:
+
+| Field | Current | Meaning |
+| --- | --- | --- |
+| `contract_version` | `0.2.0` | Generated manifest and typed SDK shape |
+| `tools_list_schema_version` | `1` | cua-driver `tools/list` extension shape |
+| `capability_version` | `1` | Additive capability-token vocabulary |
+| `mcp_protocol_version` | `2025-06-18` | MCP initialization protocol served to agent runtimes |
+
+This implementation does not use WASM. UniFFI distributes one Rust
+daemon-client implementation to Python and Node while preserving the daemon's
+permission identity and runtime ownership. The language packages do not
+generate or maintain separate MCP transports.
+
+## Generate and verify
+
+From `libs/cua-driver/rust`:
+
+```bash
+cargo run -p cua-driver-contract --bin cua-contract-gen -- all
+cargo run -p cua-driver-contract --bin cua-contract-gen -- all --check
+cargo test -p cua-driver-contract
+cargo test -p cua-driver-core --test contract_parity
+cargo test -p cua-driver --test schema_consistency_test \
+ portable_desktop_contracts_are_accepted_by_active_backend
+```
+
+SDK loader tests live in `python/tests/test_uniffi_loader.py` and
+`typescript/test/native-loader.test.mjs`. CI checks the manifest generator,
+deterministically regenerates both UniFFI binding sets, verifies parity against
+the live tool registry, and crosses the real Python and Node FFI loaders into a
+deterministic daemon-socket fixture.
diff --git a/libs/cua-driver/contract/fixtures/image-result.json b/libs/cua-driver/contract/fixtures/image-result.json
new file mode 100644
index 0000000000..24e8c8428c
--- /dev/null
+++ b/libs/cua-driver/contract/fixtures/image-result.json
@@ -0,0 +1,19 @@
+{
+ "result": {
+ "content": [
+ {
+ "type": "text",
+ "text": "captured"
+ },
+ {
+ "type": "image",
+ "mimeType": "image/png",
+ "data": "iVBORw0KGgo="
+ }
+ ],
+ "structuredContent": {
+ "path": "/tmp/capture.png",
+ "verified": true
+ }
+ }
+}
diff --git a/libs/cua-driver/contract/fixtures/session-success.json b/libs/cua-driver/contract/fixtures/session-success.json
new file mode 100644
index 0000000000..4eed5bc147
--- /dev/null
+++ b/libs/cua-driver/contract/fixtures/session-success.json
@@ -0,0 +1,20 @@
+{
+ "result": {
+ "content": [
+ {
+ "type": "text",
+ "text": "Session 'demo' is active."
+ }
+ ],
+ "structuredContent": {
+ "session": "demo",
+ "capture_scope": "auto",
+ "effective_scope": "window",
+ "desktop_unlocked": false,
+ "escalation_reason": null,
+ "escalation_detail": null,
+ "active": true,
+ "revived": false
+ }
+ }
+}
diff --git a/libs/cua-driver/contract/fixtures/tool-refusal.json b/libs/cua-driver/contract/fixtures/tool-refusal.json
new file mode 100644
index 0000000000..409130d78f
--- /dev/null
+++ b/libs/cua-driver/contract/fixtures/tool-refusal.json
@@ -0,0 +1,18 @@
+{
+ "result": {
+ "content": [
+ {
+ "type": "text",
+ "text": "Foreground delivery requires an explicit retry."
+ }
+ ],
+ "isError": true,
+ "structuredContent": {
+ "status": "refused",
+ "refusal": {
+ "code": "foreground_required",
+ "message": "Retry only after the model verifies background delivery failed."
+ }
+ }
+ }
+}
diff --git a/libs/cua-driver/contract/manifest.json b/libs/cua-driver/contract/manifest.json
new file mode 100644
index 0000000000..f5e6c998cf
--- /dev/null
+++ b/libs/cua-driver/contract/manifest.json
@@ -0,0 +1,1036 @@
+{
+ "generated_notice": "Generated by cua-contract-gen; do not edit by hand.",
+ "experimental": true,
+ "contract_version": "0.2.0",
+ "tools_list_schema_version": "1",
+ "capability_version": "1",
+ "mcp_protocol_version": "2025-06-18",
+ "transport": "mcp_stdio",
+ "tools": [
+ {
+ "name": "click",
+ "description": "Click an absolute point in get_desktop_state coordinates without targeting a window.",
+ "platforms": [
+ "macos",
+ "windows",
+ "linux"
+ ],
+ "capabilities": [
+ "input.pointer.click",
+ "input.pointer.click.left",
+ "accessibility.element_tokens"
+ ],
+ "annotations": {
+ "read_only": false,
+ "destructive": true,
+ "idempotent": false,
+ "open_world": true
+ },
+ "schema_mode": "portable_subset",
+ "input_schema": {
+ "additionalProperties": false,
+ "properties": {
+ "button": {
+ "enum": [
+ "left",
+ "right",
+ "middle"
+ ],
+ "type": "string"
+ },
+ "count": {
+ "maximum": 3,
+ "minimum": 1,
+ "type": "integer"
+ },
+ "scope": {
+ "const": "desktop"
+ },
+ "session": {
+ "description": "Optional session id.",
+ "type": "string"
+ },
+ "x": {
+ "type": "number"
+ },
+ "y": {
+ "type": "number"
+ }
+ },
+ "required": [
+ "x",
+ "y",
+ "scope"
+ ],
+ "type": "object"
+ },
+ "success_output_schema": {
+ "additionalProperties": true,
+ "properties": {
+ "scope": {
+ "const": "desktop"
+ },
+ "verified": {
+ "type": "boolean"
+ },
+ "x": {
+ "type": "number"
+ },
+ "y": {
+ "type": "number"
+ }
+ },
+ "type": "object"
+ }
+ },
+ {
+ "name": "drag",
+ "description": "Drag between two absolute points in get_desktop_state coordinates.",
+ "platforms": [
+ "macos",
+ "windows",
+ "linux"
+ ],
+ "capabilities": [
+ "input.pointer.drag"
+ ],
+ "annotations": {
+ "read_only": false,
+ "destructive": true,
+ "idempotent": false,
+ "open_world": true
+ },
+ "schema_mode": "portable_subset",
+ "input_schema": {
+ "additionalProperties": false,
+ "properties": {
+ "button": {
+ "enum": [
+ "left",
+ "right",
+ "middle"
+ ],
+ "type": "string"
+ },
+ "duration_ms": {
+ "maximum": 10000,
+ "minimum": 0,
+ "type": "integer"
+ },
+ "from_x": {
+ "type": "number"
+ },
+ "from_y": {
+ "type": "number"
+ },
+ "modifier": {
+ "items": {
+ "type": "string"
+ },
+ "type": "array"
+ },
+ "scope": {
+ "const": "desktop"
+ },
+ "session": {
+ "description": "Optional session id.",
+ "type": "string"
+ },
+ "steps": {
+ "maximum": 200,
+ "minimum": 1,
+ "type": "integer"
+ },
+ "to_x": {
+ "type": "number"
+ },
+ "to_y": {
+ "type": "number"
+ }
+ },
+ "required": [
+ "from_x",
+ "from_y",
+ "to_x",
+ "to_y",
+ "scope"
+ ],
+ "type": "object"
+ },
+ "success_output_schema": {
+ "additionalProperties": true,
+ "properties": {
+ "effect": {
+ "type": "string"
+ },
+ "scope": {
+ "const": "desktop"
+ },
+ "verified": {
+ "type": "boolean"
+ }
+ },
+ "type": "object"
+ }
+ },
+ {
+ "name": "end_session",
+ "description": "End a session declared with `start_session`: removes its agent cursor, stops any recording it owns, and clears its per-session config. Call this when a run finishes so its cursor doesn't linger (otherwise the idle-TTL reclaims it after a period of inactivity). Idempotent.",
+ "platforms": [
+ "macos",
+ "windows",
+ "linux"
+ ],
+ "capabilities": [
+ "session.lifecycle.end"
+ ],
+ "annotations": {
+ "read_only": false,
+ "destructive": true,
+ "idempotent": true,
+ "open_world": false
+ },
+ "schema_mode": "canonical_runtime",
+ "input_schema": {
+ "additionalProperties": true,
+ "properties": {
+ "session": {
+ "description": "The session id to end.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "session"
+ ],
+ "type": "object"
+ },
+ "success_output_schema": {
+ "additionalProperties": true,
+ "properties": {
+ "active": {
+ "const": false
+ },
+ "session": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "session",
+ "active"
+ ],
+ "type": "object"
+ }
+ },
+ {
+ "name": "escalate_session",
+ "description": "Unlock the desktop phase of an auto capture-scope session after the window action ladder has been exhausted and verified. This is a one-way transition for the live session and records a bounded reason.",
+ "platforms": [
+ "macos",
+ "windows",
+ "linux"
+ ],
+ "capabilities": [
+ "session.capture_scope.escalate"
+ ],
+ "annotations": {
+ "read_only": false,
+ "destructive": false,
+ "idempotent": false,
+ "open_world": false
+ },
+ "schema_mode": "canonical_runtime",
+ "input_schema": {
+ "additionalProperties": true,
+ "properties": {
+ "detail": {
+ "description": "Optional bounded diagnostic detail. Never use secrets or page content.",
+ "maxLength": 200,
+ "type": "string"
+ },
+ "reason": {
+ "enum": [
+ "ax_tree_pixel_mismatch",
+ "background_delivery_failed",
+ "foreground_ineffective",
+ "no_window_target",
+ "other"
+ ],
+ "type": "string"
+ },
+ "session": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "session",
+ "reason"
+ ],
+ "type": "object"
+ },
+ "success_output_schema": {
+ "additionalProperties": true,
+ "properties": {
+ "capture_scope": {
+ "enum": [
+ "auto",
+ "window",
+ "desktop"
+ ],
+ "type": "string"
+ },
+ "desktop_unlocked": {
+ "type": "boolean"
+ },
+ "effective_scope": {
+ "enum": [
+ "window",
+ "desktop"
+ ],
+ "type": "string"
+ },
+ "escalation_detail": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "escalation_reason": {
+ "anyOf": [
+ {
+ "enum": [
+ "ax_tree_pixel_mismatch",
+ "background_delivery_failed",
+ "foreground_ineffective",
+ "no_window_target",
+ "other"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "session": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "session",
+ "capture_scope",
+ "effective_scope",
+ "desktop_unlocked",
+ "escalation_reason",
+ "escalation_detail"
+ ],
+ "type": "object"
+ }
+ },
+ {
+ "name": "get_cursor_position",
+ "description": "Return the OS cursor position when the platform can observe it.",
+ "platforms": [
+ "macos",
+ "windows",
+ "linux"
+ ],
+ "capabilities": [
+ "screen.cursor.position"
+ ],
+ "annotations": {
+ "read_only": true,
+ "destructive": false,
+ "idempotent": true,
+ "open_world": false
+ },
+ "schema_mode": "portable_subset",
+ "input_schema": {
+ "additionalProperties": false,
+ "properties": {
+ "session": {
+ "description": "Optional session id.",
+ "type": "string"
+ }
+ },
+ "required": [],
+ "type": "object"
+ },
+ "success_output_schema": {
+ "additionalProperties": true,
+ "properties": {
+ "available": {
+ "type": "boolean"
+ },
+ "source": {
+ "type": "string"
+ },
+ "x": {
+ "type": "number"
+ },
+ "y": {
+ "type": "number"
+ }
+ },
+ "type": "object"
+ }
+ },
+ {
+ "name": "get_desktop_state",
+ "description": "Capture the complete primary display at native resolution for a desktop-scope GUI loop.",
+ "platforms": [
+ "macos",
+ "windows",
+ "linux"
+ ],
+ "capabilities": [
+ "screen.capture",
+ "screen.dimensions"
+ ],
+ "annotations": {
+ "read_only": true,
+ "destructive": false,
+ "idempotent": false,
+ "open_world": false
+ },
+ "schema_mode": "portable_subset",
+ "input_schema": {
+ "additionalProperties": false,
+ "properties": {
+ "screenshot_out_file": {
+ "description": "Write the PNG here instead of returning base64.",
+ "type": "string"
+ },
+ "session": {
+ "description": "Optional session id.",
+ "type": "string"
+ }
+ },
+ "required": [],
+ "type": "object"
+ },
+ "success_output_schema": {
+ "additionalProperties": true,
+ "properties": {
+ "display": {
+ "type": "string"
+ },
+ "platform": {
+ "enum": [
+ "macos",
+ "linux",
+ "windows"
+ ],
+ "type": "string"
+ },
+ "scale_factor": {
+ "type": "number"
+ },
+ "screen_height": {
+ "type": "integer"
+ },
+ "screen_width": {
+ "type": "integer"
+ },
+ "screenshot_file_path": {
+ "type": "string"
+ },
+ "screenshot_height": {
+ "type": "integer"
+ },
+ "screenshot_mime_type": {
+ "const": "image/png"
+ },
+ "screenshot_width": {
+ "type": "integer"
+ }
+ },
+ "required": [
+ "platform",
+ "display",
+ "screenshot_width",
+ "screenshot_height",
+ "screen_width",
+ "screen_height",
+ "scale_factor",
+ "screenshot_mime_type"
+ ],
+ "type": "object"
+ }
+ },
+ {
+ "name": "get_screen_size",
+ "description": "Return the primary display dimensions and scale factor in the platform's desktop coordinate space.",
+ "platforms": [
+ "macos",
+ "windows",
+ "linux"
+ ],
+ "capabilities": [
+ "screen.dimensions"
+ ],
+ "annotations": {
+ "read_only": true,
+ "destructive": false,
+ "idempotent": true,
+ "open_world": false
+ },
+ "schema_mode": "portable_subset",
+ "input_schema": {
+ "additionalProperties": false,
+ "properties": {
+ "session": {
+ "description": "Optional session id.",
+ "type": "string"
+ }
+ },
+ "required": [],
+ "type": "object"
+ },
+ "success_output_schema": {
+ "additionalProperties": true,
+ "properties": {
+ "height": {
+ "type": "number"
+ },
+ "scale_factor": {
+ "type": "number"
+ },
+ "width": {
+ "type": "number"
+ }
+ },
+ "required": [
+ "width",
+ "height",
+ "scale_factor"
+ ],
+ "type": "object"
+ }
+ },
+ {
+ "name": "get_session_state",
+ "description": "Read the live session's capture policy and effective scope.",
+ "platforms": [
+ "macos",
+ "windows",
+ "linux"
+ ],
+ "capabilities": [
+ "session.capture_scope.read"
+ ],
+ "annotations": {
+ "read_only": true,
+ "destructive": false,
+ "idempotent": true,
+ "open_world": false
+ },
+ "schema_mode": "canonical_runtime",
+ "input_schema": {
+ "additionalProperties": true,
+ "properties": {
+ "session": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "session"
+ ],
+ "type": "object"
+ },
+ "success_output_schema": {
+ "additionalProperties": true,
+ "properties": {
+ "capture_scope": {
+ "enum": [
+ "auto",
+ "window",
+ "desktop"
+ ],
+ "type": "string"
+ },
+ "desktop_unlocked": {
+ "type": "boolean"
+ },
+ "effective_scope": {
+ "enum": [
+ "window",
+ "desktop"
+ ],
+ "type": "string"
+ },
+ "escalation_detail": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "escalation_reason": {
+ "anyOf": [
+ {
+ "enum": [
+ "ax_tree_pixel_mismatch",
+ "background_delivery_failed",
+ "foreground_ineffective",
+ "no_window_target",
+ "other"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "session": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "session",
+ "capture_scope",
+ "effective_scope",
+ "desktop_unlocked",
+ "escalation_reason",
+ "escalation_detail"
+ ],
+ "type": "object"
+ }
+ },
+ {
+ "name": "hotkey",
+ "description": "Press a key chord in the foreground desktop application.",
+ "platforms": [
+ "macos",
+ "windows",
+ "linux"
+ ],
+ "capabilities": [
+ "input.keyboard.hotkey"
+ ],
+ "annotations": {
+ "read_only": false,
+ "destructive": true,
+ "idempotent": false,
+ "open_world": true
+ },
+ "schema_mode": "portable_subset",
+ "input_schema": {
+ "additionalProperties": false,
+ "properties": {
+ "keys": {
+ "items": {
+ "type": "string"
+ },
+ "minItems": 2,
+ "type": "array"
+ },
+ "scope": {
+ "const": "desktop"
+ },
+ "session": {
+ "description": "Optional session id.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "keys",
+ "scope"
+ ],
+ "type": "object"
+ },
+ "success_output_schema": {
+ "additionalProperties": true,
+ "properties": {
+ "effect": {
+ "type": "string"
+ },
+ "scope": {
+ "const": "desktop"
+ },
+ "verified": {
+ "type": "boolean"
+ }
+ },
+ "type": "object"
+ }
+ },
+ {
+ "name": "move_cursor",
+ "description": "Move the real OS pointer in get_desktop_state coordinates.",
+ "platforms": [
+ "macos",
+ "windows",
+ "linux"
+ ],
+ "capabilities": [
+ "agent_cursor.move",
+ "input.pointer.move"
+ ],
+ "annotations": {
+ "read_only": false,
+ "destructive": false,
+ "idempotent": true,
+ "open_world": false
+ },
+ "schema_mode": "portable_subset",
+ "input_schema": {
+ "additionalProperties": false,
+ "properties": {
+ "scope": {
+ "const": "desktop"
+ },
+ "session": {
+ "description": "Optional session id.",
+ "type": "string"
+ },
+ "x": {
+ "type": "number"
+ },
+ "y": {
+ "type": "number"
+ }
+ },
+ "required": [
+ "x",
+ "y",
+ "scope"
+ ],
+ "type": "object"
+ },
+ "success_output_schema": {
+ "additionalProperties": true,
+ "properties": {
+ "scope": {
+ "const": "desktop"
+ },
+ "x": {
+ "type": "number"
+ },
+ "y": {
+ "type": "number"
+ }
+ },
+ "type": "object"
+ }
+ },
+ {
+ "name": "press_key",
+ "description": "Press one key, with optional modifiers, in the foreground desktop application.",
+ "platforms": [
+ "macos",
+ "windows",
+ "linux"
+ ],
+ "capabilities": [
+ "input.keyboard.press",
+ "accessibility.element_tokens"
+ ],
+ "annotations": {
+ "read_only": false,
+ "destructive": true,
+ "idempotent": false,
+ "open_world": true
+ },
+ "schema_mode": "portable_subset",
+ "input_schema": {
+ "additionalProperties": false,
+ "properties": {
+ "key": {
+ "type": "string"
+ },
+ "modifiers": {
+ "items": {
+ "type": "string"
+ },
+ "type": "array"
+ },
+ "scope": {
+ "const": "desktop"
+ },
+ "session": {
+ "description": "Optional session id.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "key",
+ "scope"
+ ],
+ "type": "object"
+ },
+ "success_output_schema": {
+ "additionalProperties": true,
+ "properties": {
+ "effect": {
+ "type": "string"
+ },
+ "scope": {
+ "const": "desktop"
+ },
+ "verified": {
+ "type": "boolean"
+ }
+ },
+ "type": "object"
+ }
+ },
+ {
+ "name": "scroll",
+ "description": "Scroll at an absolute point in get_desktop_state coordinates.",
+ "platforms": [
+ "macos",
+ "windows",
+ "linux"
+ ],
+ "capabilities": [
+ "input.pointer.scroll",
+ "accessibility.element_tokens"
+ ],
+ "annotations": {
+ "read_only": false,
+ "destructive": false,
+ "idempotent": false,
+ "open_world": true
+ },
+ "schema_mode": "portable_subset",
+ "input_schema": {
+ "additionalProperties": false,
+ "properties": {
+ "amount": {
+ "maximum": 50,
+ "minimum": 1,
+ "type": "integer"
+ },
+ "by": {
+ "enum": [
+ "line",
+ "page"
+ ],
+ "type": "string"
+ },
+ "direction": {
+ "enum": [
+ "up",
+ "down",
+ "left",
+ "right"
+ ],
+ "type": "string"
+ },
+ "scope": {
+ "const": "desktop"
+ },
+ "session": {
+ "description": "Optional session id.",
+ "type": "string"
+ },
+ "x": {
+ "type": "number"
+ },
+ "y": {
+ "type": "number"
+ }
+ },
+ "required": [
+ "x",
+ "y",
+ "direction",
+ "scope"
+ ],
+ "type": "object"
+ },
+ "success_output_schema": {
+ "additionalProperties": true,
+ "properties": {
+ "effect": {
+ "type": "string"
+ },
+ "scope": {
+ "const": "desktop"
+ },
+ "verified": {
+ "type": "boolean"
+ }
+ },
+ "type": "object"
+ }
+ },
+ {
+ "name": "start_session",
+ "description": "Declare a session — a named, color-coded identity for THIS agent run. Pass a stable `session` id and choose capture_scope=auto|window|desktop; the agent cursor, capture policy, per-session config, and recording all key on it, and it follows the run across any apps/windows. The cursor's color is derived from the id, so distinct runs are visually distinct. A cursor is shown only for a declared session — call this (or pass `session` on your first action) to opt in. Idempotent: re-calling with the same id just refreshes its idle-TTL. End it with `end_session` (or let the idle-TTL reclaim it). Concurrent runs/subagents each pass their own `session` to get their own cursor.",
+ "platforms": [
+ "macos",
+ "windows",
+ "linux"
+ ],
+ "capabilities": [
+ "session.lifecycle.start",
+ "session.capture_scope"
+ ],
+ "annotations": {
+ "read_only": false,
+ "destructive": false,
+ "idempotent": true,
+ "open_world": false
+ },
+ "schema_mode": "canonical_runtime",
+ "input_schema": {
+ "additionalProperties": true,
+ "properties": {
+ "capture_scope": {
+ "default": "auto",
+ "description": "Per-session perception/action modality. auto starts window-only and requires explicit escalation before desktop tools; window and desktop are strict. Immutable for the live session.",
+ "enum": [
+ "auto",
+ "window",
+ "desktop"
+ ],
+ "type": "string"
+ },
+ "session": {
+ "description": "Stable session id for this run (e.g. \"research-run-1\").",
+ "type": "string"
+ }
+ },
+ "required": [
+ "session"
+ ],
+ "type": "object"
+ },
+ "success_output_schema": {
+ "additionalProperties": true,
+ "properties": {
+ "active": {
+ "type": "boolean"
+ },
+ "capture_scope": {
+ "enum": [
+ "auto",
+ "window",
+ "desktop"
+ ],
+ "type": "string"
+ },
+ "desktop_unlocked": {
+ "type": "boolean"
+ },
+ "effective_scope": {
+ "enum": [
+ "window",
+ "desktop"
+ ],
+ "type": "string"
+ },
+ "escalation_detail": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "escalation_reason": {
+ "anyOf": [
+ {
+ "enum": [
+ "ax_tree_pixel_mismatch",
+ "background_delivery_failed",
+ "foreground_ineffective",
+ "no_window_target",
+ "other"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "revived": {
+ "type": "boolean"
+ },
+ "session": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "session",
+ "capture_scope",
+ "effective_scope",
+ "desktop_unlocked",
+ "escalation_reason",
+ "escalation_detail",
+ "active",
+ "revived"
+ ],
+ "type": "object"
+ }
+ },
+ {
+ "name": "type_text",
+ "description": "Type text into the current foreground desktop application.",
+ "platforms": [
+ "macos",
+ "windows",
+ "linux"
+ ],
+ "capabilities": [
+ "input.keyboard.type",
+ "input.keyboard.type.terminal_safe",
+ "accessibility.element_tokens"
+ ],
+ "annotations": {
+ "read_only": false,
+ "destructive": true,
+ "idempotent": false,
+ "open_world": true
+ },
+ "schema_mode": "portable_subset",
+ "input_schema": {
+ "additionalProperties": false,
+ "properties": {
+ "scope": {
+ "const": "desktop"
+ },
+ "session": {
+ "description": "Optional session id.",
+ "type": "string"
+ },
+ "text": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "text",
+ "scope"
+ ],
+ "type": "object"
+ },
+ "success_output_schema": {
+ "additionalProperties": true,
+ "properties": {
+ "effect": {
+ "type": "string"
+ },
+ "scope": {
+ "const": "desktop"
+ },
+ "verified": {
+ "type": "boolean"
+ }
+ },
+ "type": "object"
+ }
+ }
+ ]
+}
diff --git a/libs/cua-driver/docs/sdk-rust-source-of-truth-and-uniffi-evaluation-plan.md b/libs/cua-driver/docs/sdk-rust-source-of-truth-and-uniffi-evaluation-plan.md
new file mode 100644
index 0000000000..d276f6c36d
--- /dev/null
+++ b/libs/cua-driver/docs/sdk-rust-source-of-truth-and-uniffi-evaluation-plan.md
@@ -0,0 +1,679 @@
+# Cua Driver SDK Rust source-of-truth and UniFFI evaluation plan
+
+Status: superseded by the final package-boundary decision in PR #2341
+
+Applies to: PR #2341 and follow-up SDK/runtime work
+
+Primary objective: eliminate manual contract/runtime bookkeeping before publishing the Python and TypeScript SDKs
+
+Decision rationale: [Cua Driver integration surfaces: MCP/CLI and SDK bindings](why-cua-driver-uses-mcp-instead-of-uniffi.md)
+
+> **Final decision update (2026-07-21):** the evaluation below records the
+> sequence and evidence that led to the implementation, but its interim
+> recommendation to retain Python and TypeScript MCP facades is no longer
+> current. The language packages now expose only the Rust-backed UniFFI SDK at
+> their package roots. Agents use `cua-driver mcp` through their runtime's
+> existing MCP client. The thin language MCP clients and their generator were
+> removed before publication.
+
+## Executive decision
+
+Proceed with the Rust source-of-truth work while separating the agent boundary
+from the imported SDK boundary. MCP/CLI is the baseline agent architecture;
+UniFFI remains a candidate for distributing a Rust SDK/server implementation.
+
+The recommended sequence is:
+
+1. Immediately prove that PR #2341's ten portable desktop contracts are valid
+ subsets of every live platform schema.
+2. Make a transport-free Rust specification crate the single owner of typed
+ inputs, structured outputs, metadata, capabilities, platform presence, and
+ portable projections.
+3. Move live platform implementations onto those shared types incrementally,
+ beginning with the four already-canonical session tools and then a genuinely
+ divergent desktop slice.
+4. Keep MCP and the CLI as the canonical agent integration. MCP-capable agents
+ do not need a generated Cua client; prove this with Python Claude Agent SDK
+ and TypeScript Codex SDK examples.
+5. Keep the generated Python and TypeScript packages as typed MCP client SDKs
+ for application code, without claiming that they add runtime portability.
+6. Run a time-boxed, language-split UniFFI spike for consumers that want a
+ shared Rust implementation, especially server-hosting or embedded SDK
+ consumers. Treat Python as the mature target and TypeScript as a separate
+ third-party toolchain evaluation.
+7. Adopt UniFFI for a language only if it is reproducible, centralizes
+ meaningful Rust behavior, and passes the packaging and runtime gates below.
+
+Directly embedding the GUI engine is not part of the current client-generation
+work. The existing runtime assumes a shared daemon, process-global state, and
+OS-specific main-thread and permission behavior that a host-process library
+cannot safely inherit without a separate design. A UniFFI facade over a shared
+Rust daemon client and a UniFFI embedded/server SDK are distinct candidates.
+
+## Confirmed current state
+
+### PR #2341
+
+- `cua-driver-contract` declares fourteen typed tools: four session lifecycle
+ tools and ten portable desktop-loop tools.
+- The manifest, Python argument classes/methods, and TypeScript
+ interfaces/methods are generated from that Rust contract crate.
+- The Python and TypeScript SDKs communicate with `cua-driver mcp` over stdio.
+- Both SDKs retain generic calls and `tools/list` access for runtime-discovered
+ and platform-specific tools.
+- Generated files have an ownership inventory and a real `--check` drift mode.
+- The language packages' public classes are `CuaDriver` and
+ `AsyncCuaDriver` in Python, and `CuaDriver` in TypeScript.
+
+### What parity exists today
+
+The four session tools build their live `ToolDef` metadata from canonical
+contracts through `ToolDef::from_contract`. Their invocation logic remains
+handwritten, so this proves metadata parity, not behavioral or output parity.
+
+The ten desktop contracts are separately authored `portable_subset`
+declarations. The platform crates do not consume those input types and instead
+own richer handwritten `ToolDef` schemas plus field-by-field `ArgsExt` parsing.
+No test currently proves that each portable input schema is accepted by every
+corresponding live platform schema.
+
+Capabilities also have two declaration sites today: the runtime capability map
+and each `ToolContract`. Existing tests compare them, but do not eliminate the
+duplicate ownership.
+
+### Platform roster and runtime shape
+
+Registration-based counts at this revision are approximately:
+
+- macOS: 48 tools;
+- Windows: 49 tools; and
+- Linux: 52 tools.
+
+These counts must be verified against live `tools/list` on each OS before being
+used as release evidence. They must not become fixed global assertions because
+the rosters intentionally differ and evolve. For example, Windows registers
+`debug_window_info`, while Linux registers four additional pointer primitives.
+
+The daemon serves concurrent connections through one shared registry and tool
+state. Core session hooks, activity, element tokens, and other facilities use
+process-global singletons. On macOS, AppKit surfaces require the main thread and
+permission identity is tied to the executable. These constraints are central to
+the transport decision.
+
+### What Fleet proves about UniFFI
+
+Fleet provides a strong precedent for official UniFFI targets such as Python,
+Kotlin, Swift, and Ruby: its checked-in generator uses pinned Rust dependencies
+and supports regeneration checking.
+
+Fleet also contains generated TypeScript examples:
+
+- a Node N-API path using `uniffi-bindgen-react-native`, `@ubjs/core`, and
+ `@ubjs/node` to load a native `cdylib`; and
+- a browser/WASM path.
+
+Those TypeScript artifacts prove feasibility, not a production-ready generation
+pipeline. In the inspected tree, TypeScript is absent from Fleet's main
+generation/check script, the React Native generator is not pinned in the Rust
+workspace, the example `@ubjs/*` dependencies use `latest`, and the browser
+WASM glue depends on configuration and generation that are not checked in.
+
+Therefore:
+
+- do not describe Fleet's TypeScript path as a reproducible template;
+- use Cua Driver's existing deterministic `--check` flow as the standard the
+ TypeScript UniFFI spike must meet; and
+- evaluate Python and TypeScript UniFFI adoption independently.
+
+## Required invariants
+
+1. Rust remains the only owner of GUI execution, permissions, policy, session
+ state, and platform integration.
+2. Python and TypeScript do not reimplement OS automation behavior.
+3. Every published typed method maps to Rust input and result types consumed by
+ the live implementation.
+4. MCP remains available regardless of the binding decision.
+5. Experimental and runtime-only tools remain reachable through a generic
+ call until intentionally promoted.
+6. A transport never resends a state-changing tool call automatically.
+ Bounded retries inside one platform implementation remain allowed when they
+ are part of that single invocation and preserve its semantics.
+7. Generated files are deterministic, ownership-scoped, atomically replaced,
+ and checked for drift in CI.
+8. Platform availability is explicit at the tool, variant, and field levels.
+9. Capabilities and risk metadata have exactly one authoritative declaration.
+10. Mixed MCP content remains a transport envelope: typed structured results do
+ not erase text, images, refusals, degraded results, or diagnostics.
+
+## Target architecture and public surfaces
+
+```text
+Transport-free Rust ToolSpec + typed inputs/results
+ |
+ +--> live ToolDef and tools/list metadata
+ +--> runtime typed input parsing
+ +--> structured-result validation
+ +--> portable and platform-rich projections
+ +--> contract manifest
+ +--> optional typed MCP-client generation
+ +--> optional UniFFI implementation exports
+
+Agent surface:
+Codex / Claude / other agent ---- MCP stdio ---- native daemon ---- OS APIs
+Shell automation ---------------- CLI call ----- native daemon ---- OS APIs
+
+Imported application SDK surface:
+Python/TS typed client ----------- MCP stdio ---- native daemon ---- OS APIs
+ or
+Language binding ---------------- UniFFI ------- Rust daemon client ---- daemon
+ or, after a separate host-runtime design
+Language binding ---------------- UniFFI ------- embedded Rust engine ---- OS APIs
+```
+
+The transport-free specifications should live in the existing
+`cua-driver-contract` crate or a narrowly scoped sibling `rlib`. All platform
+crates must be able to depend on the types without importing MCP framing or a
+public SDK runtime.
+
+The typed layer must distinguish:
+
+- the typed command input;
+- the typed successful `structuredContent` payload, when present;
+- stable typed refusals/errors; and
+- the MCP content envelope that can contain text, images, and diagnostics.
+
+A blanket adapter must not pretend every tool result is one serializable success
+object. Agent examples must use the existing agent SDK's MCP client directly;
+otherwise they would obscure the distinction this plan depends on.
+
+## Workstream A0: close PR #2341's immediate parity gap
+
+Add a mechanical subset-and-existence test for the ten desktop contracts before
+the larger refactor.
+
+For every declared platform and portable desktop tool, the test must prove:
+
+1. the live registry contains the tool;
+2. every portable property exists in the live input schema;
+3. portable required fields remain required live;
+4. portable types, enum/const values, bounds, and closed-object behavior are no
+ broader than the live schema allows;
+5. portable annotations and capability tokens are compatible with the live
+ tool; and
+6. the test fails on a deliberately introduced incompatible field change.
+
+Implement a small schema-subset checker for the schema constructs used by the
+ten contracts. Do not claim general JSON Schema implication. Fail explicitly on
+an unsupported keyword so the test cannot silently accept an unproven case.
+
+### A0 acceptance gate
+
+- All ten portable contracts pass against macOS, Windows, and Linux registries.
+- The workflow runs when a contract, platform `ToolDef`, registry, or capability
+ map changes.
+- PR #2341's description accurately says this proves portable input/metadata
+ compatibility, not full runtime behavior.
+
+## Workstream A: make Rust the true source of truth
+
+### A1. Establish the transport-free specification model
+
+Define a `ToolSpec` model containing:
+
+- canonical name and description;
+- typed input;
+- typed structured success payload, if applicable;
+- stable refusal/error shapes;
+- annotations and risk metadata;
+- the sole capability declaration;
+- per-platform tool presence;
+- portable versus rich exposure metadata; and
+- schema and contract versions.
+
+Add the new dependency from the macOS, Windows, and Linux platform crates to
+the specification crate. Keep dependency direction acyclic and transport-free.
+
+Do not commit to `schemars` up front. First run a schema-dialect spike on one
+session input and one complex desktop input. It must reproduce the existing
+required/optional, closed-object, enum/const, nullability, default, and bounds
+semantics with a bounded override surface. If it cannot, keep the existing
+schema builders while still making typed Rust inputs authoritative.
+
+### A2. Add typed runtime adaptation
+
+Introduce an adapter that:
+
+1. deserializes MCP arguments into the shared typed input;
+2. calls the platform implementation with that input;
+3. validates/serializes stable structured output when declared;
+4. preserves the existing MCP text/image/diagnostic envelope; and
+5. normalizes stable errors without erasing platform diagnostics.
+
+For a migrated tool, the live `ToolDef` must be derived from its spec and the
+platform implementation must not retain a second schema literal or field-by-
+field `ArgsExt` parser.
+
+Start with the four session tools because their live metadata already comes
+from canonical contracts. This proves the adapter and output model with the
+lowest platform risk.
+
+### A3. Model platform presence and rich variants once
+
+The model must cover both field-level richness and tool-set divergence:
+
+- portable desktop coordinates versus window/element targeting;
+- platform-only fields and enum variants;
+- Windows-only tools such as `debug_window_info`; and
+- Linux-only low-level pointer primitives.
+
+Portable SDK inputs must be derived projections of richer typed declarations,
+not parallel handwritten schemas. If one public union would be misleading,
+define separate typed commands such as `DesktopClickInput` and
+`WindowClickInput`, but route them to the same implementation family.
+
+### A4. Prove a divergent vertical slice
+
+Migrate:
+
+- `start_session` and `end_session` for lifecycle and structured output;
+- `get_desktop_state` for image plus structured metadata;
+- `click` for portable versus rich targeting and destructive annotations;
+- `get_window_state` for window-focused richness; and
+- at least one tool absent from one or more platforms to prove presence
+ modeling.
+
+The slice is complete only when:
+
+- all participating platform implementations consume shared inputs;
+- live `tools/list` metadata is spec-derived;
+- representative structured results validate against their declared schemas;
+- the MCP envelope preserves text and images; and
+- generated Python and TypeScript methods pass executable fixture tests.
+
+### A5. Migrate the current fourteen-tool SDK surface
+
+After the slice stabilizes, migrate all fourteen methods currently generated by
+PR #2341. Remove duplicated schemas and ad hoc parsing for those tools. Keep
+compatibility aliases only in dispatch and hidden from `tools/list` and SDKs.
+
+### A6. Expand by tool family
+
+Migrate stable tools in independently reviewable families:
+
+1. remaining perception and desktop input;
+2. window and app lifecycle;
+3. browser;
+4. recording and replay;
+5. cursor, configuration, and diagnostics; and
+6. remaining platform-specific stable tools.
+
+Each runtime roster entry must be classified as stable typed, experimental
+generic-only, compatibility alias, or internal/hidden. Do not encode one global
+tool count.
+
+## Workstream B: separate agent integration from SDK distribution
+
+### Agent integration: direct MCP/CLI — baseline recommendation
+
+Configure each agent runtime's existing MCP client with `cua-driver mcp`, or
+use `cua-driver call` from shell-oriented agents. Do not require generated Cua
+language clients in this path. Maintain runnable Python Claude Agent SDK and
+TypeScript Codex SDK examples as proof.
+
+This is the O(1) agent-protocol surface: one MCP server is consumable from N
+MCP-capable runtimes. Generated clients add ergonomics for applications, not
+interoperability for these agents.
+
+### SDK option 1: thin generated MCP clients
+
+Continue generating Python and TypeScript types/methods while small native
+transports speak MCP stdio directly.
+
+This preserves:
+
+- the daemon's permission identity and main-thread ownership;
+- process and crash isolation;
+- the current generic `tools/list` / `tools/call` escape hatch;
+- small language packages without an additional client `cdylib`; and
+- Cua Driver's already-reproducible TypeScript generation/check pipeline.
+
+The remaining handwritten language code is a few small transport, result, and
+facade modules. This is a typed remote-client SDK, not a native implementation
+binding. Measure it against the actual application SDK requirement.
+
+### SDK option 2: UniFFI facade over a Rust daemon client — gated spike
+
+Build a platform-neutral Rust client that owns MCP framing and result
+normalization while still launching or connecting to the native driver daemon.
+Export only the vertical-slice API through UniFFI.
+
+Run two distinct experiments:
+
+- Python through official UniFFI support; and
+- Node TypeScript through `uniffi-bindgen-react-native` and `@ubjs/node`.
+
+The TypeScript experiment starts from a green-field reproducibility assumption,
+not from Fleet's manual artifacts. It must add:
+
+- exact pinned generator and runtime versions;
+- an in-repository generation command;
+- deterministic owned outputs and `--check` mode;
+- a lockfile and publishable package definition;
+- host `cdylib` resolution from Cargo compiler-artifact output; and
+- isolated package tests for every supported platform/architecture.
+
+Do not implement browser/WASM packaging for local desktop automation in this
+spike.
+
+The purpose of this option is to implement application client behavior once in
+Rust and distribute that implementation to N runtimes. Merely moving JSON-RPC
+framing into Rust is insufficient benefit; the spike must identify the shared
+lifecycle, normalization, policy, or server-composition behavior it owns.
+
+### SDK option 3: UniFFI embedded/server implementation — separate proposal
+
+This is the path for application developers who want to create or embed a Cua
+server. Do not treat it as a fallback transport change. A separate proposal
+would first need to eliminate or explicitly host:
+
+- process-global session and element-token state;
+- one-registry assumptions and concurrent-session cleanup hazards;
+- macOS AppKit main-thread ownership and permission identity;
+- Windows interactive-session, UIAccess, foreground, and overlay behavior;
+- Linux compositor, X11/Wayland, and session-bus integration; and
+- host crash, runtime, and cancellation coupling.
+
+### B1. Measure the SDK candidates
+
+For SDK option 1 and each language-specific SDK option 2 spike, record:
+
+- generated and handwritten maintained source lines;
+- wheel/npm artifact size by platform and architecture;
+- cold start, first call, and steady-state read-only call latency;
+- sync and async Python behavior and async TypeScript behavior;
+- error, refusal, image, and structured-result fidelity;
+- generic runtime-only tool access;
+- install and native-loader failure modes;
+- release-matrix and CI duration changes; and
+- current timeout/deadline behavior without implying tool cancellation.
+
+### B2. Language-split SDK decision gate
+
+Decide Python and TypeScript independently. UniFFI may pass for Python and fail
+for TypeScript.
+
+Adopt SDK option 2 for a language only if:
+
+- it materially reduces maintained SDK behavior;
+- generated outputs are reproducible and drift-checked in-repository;
+- all generator/runtime dependencies are pinned;
+- installation, startup, generic access, and error fidelity do not regress;
+- its full supported artifact matrix passes; and
+- MCP remains available as a public boundary.
+
+For TypeScript, failure to provide pinned deterministic generation and CI
+checking is an automatic rejection regardless of runtime benchmark results.
+
+Otherwise retain SDK option 1. The source-of-truth work is complete and
+valuable regardless of this decision. Neither outcome changes direct MCP/CLI
+as the recommended agent integration.
+
+## Workstream D: define cancellation and timeout semantics
+
+Cancellation is not currently a runtime capability: dispatch awaits a tool
+directly, serve-layer deadlines do not cancel a running action, and individual
+tools contain their own bounded retry/polling behavior.
+
+Do not block A0 or the initial typed migration on inventing cancellation.
+Before claiming cancellation parity or adopting a UniFFI transport, make one
+explicit decision:
+
+1. implement caller cancellation by threading a token/deadline through the
+ `Tool` trait and typed adapter, defining safe interruption points and action
+ completion semantics; or
+2. document best-effort client deadlines that stop waiting but do not cancel an
+ in-flight tool.
+
+In either case, transports must never automatically resend an ambiguous
+state-changing request. Tests must distinguish transport resend, caller
+cancellation, and bounded retries within one tool invocation.
+
+## Verification plan
+
+### Contract and source tests
+
+- A0 subset/existence parity for all ten portable desktop contracts.
+- Every generated stable method maps to exactly one Rust spec.
+- Every migrated platform tool consumes its shared input type.
+- Migrated tools contain no second `ToolDef` schema or `ArgsExt` parser.
+- Capabilities have one declaration site.
+- Per-platform presence and portable projections are mechanically derived.
+- Generated manifest and SDK outputs are deterministic and drift-free.
+
+### Runtime behavior tests
+
+- Minimal valid inputs use the same typed adapter as MCP.
+- Invalid types, missing fields, unknown fields, bounds, and enums produce
+ stable errors.
+- Representative structured results validate against success schemas.
+- Text, images, refusals, verification metadata, degraded results, and platform
+ diagnostics survive unchanged.
+- Compatibility aliases invoke canonical implementations but stay hidden.
+- Deadline/cancellation tests assert only the semantics actually implemented by
+ Workstream D.
+
+### Platform tests
+
+- macOS, Windows, and Linux compile and run registry/schema parity tests.
+- Live roster evidence is captured from the exact source revision.
+- Fixture-backed calls cover session lifecycle, desktop perception, pointer,
+ keyboard, and window state without uncontrolled CI actions.
+- Platform-only tools and fields appear only where declared.
+- Session capture scopes (`auto`, `window`, and `desktop`) enforce identical
+ policy behavior through generic calls and every generated binding option.
+
+### Package tests
+
+- Build isolated Python wheels and npm tarballs.
+- Install into empty consumers with no repository-relative imports.
+- Verify exact native artifact provenance and load paths.
+- Run one common MCP fixture suite through every candidate.
+- Assert public class names and reject stale `Client` exports.
+- Assert package contents contain no stale generated/platform artifacts.
+
+## CI and release wiring
+
+The contract/SDK workflow must trigger on changes to:
+
+- the specification crate and generated manifests;
+- platform `ToolDef`, registry, and migrated implementation code;
+- shared result/content envelopes and capability declarations;
+- generators and ownership inventories; and
+- Python, TypeScript, native artifact, and packaging code.
+
+Required jobs:
+
+- Rust formatting and contract/unit tests;
+- A0 subset/existence checks for all three platform registries;
+- typed runtime and structured-output tests for migrated tools;
+- deterministic generation check mode;
+- Python sync/async tests and isolated wheel consumption;
+- TypeScript typecheck/tests and isolated npm consumption; and
+- UniFFI generation/artifact jobs only while a spike or adopted binding exists.
+
+Do not publish either binding option during the comparison.
+
+## Delivery sequence
+
+Keep commits independently reviewable:
+
+1. `test(cua-driver): prove portable desktop contracts match live schemas`
+2. `refactor(cua-driver): collapse tool capability ownership`
+3. `refactor(cua-driver): introduce transport-free typed tool specs`
+4. `refactor(cua-driver): route session tools through typed runtime adapter`
+5. `refactor(cua-driver): migrate divergent desktop vertical slice`
+6. `refactor(cua-driver): migrate current portable desktop SDK tools`
+7. `test(cua-driver): spike UniFFI Python Rust daemon client`
+8. `test(cua-driver): evaluate reproducible UniFFI Node bindings`
+9. Decision commit: remove each rejected spike or adopt its production wiring.
+10. Follow-up PRs: migrate stable tool families.
+
+Before PR #2341 merges, land A0 and update its description to state the exact
+guarantee. The complete typed-runtime migration can follow without presenting
+the current manifest as full runtime parity.
+
+## Completion criteria
+
+### PR #2341 parity gap is closed when
+
+- every portable contract is proven to exist and be accepted by each declared
+ live platform schema;
+- CI reruns that proof for every relevant contract/runtime change; and
+- the PR description distinguishes subset compatibility from behavior parity.
+
+### Typed Rust source-of-truth is complete for the current SDK when
+
+- all fourteen generated methods use Rust inputs/results consumed by their live
+ implementations;
+- migrated tools have no duplicate schemas or ad hoc field parsing;
+- live metadata and representative structured outputs pass parity tests;
+- capabilities have one owner;
+- all three registries pass their declared support checks; and
+- changing a Rust field causes a compile failure or deterministic generated
+ diff in every consumer.
+
+### UniFFI evaluation is complete when
+
+- the target product is explicit: typed daemon client or embedded/server SDK;
+- direct agent MCP examples remain independent of every generated client;
+- thin typed clients and each language-specific UniFFI prototype pass
+ equivalent behavior and artifact tests for the selected SDK target;
+- measurements and platform matrices are recorded;
+- Python and TypeScript decisions are documented independently;
+- any adopted TypeScript pipeline is pinned, reproducible, and CI-checked; and
+- all rejected spike code is removed.
+
+### Broader typed SDK coverage is complete when
+
+Every public runtime tool is either typed with explicit platform support or
+intentionally classified as generic-only, with no unclassified `tools/list`
+entry on any supported OS.
+
+## Principal risks
+
+| Risk | Mitigation |
+| -------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
+| Portable declarations drift before the refactor finishes | Land A0 first and trigger it on platform/runtime changes. |
+| Derived schema dialect differs from existing contracts | Gate `schemars` on a dialect-reproduction spike; keep bounded explicit builders if needed. |
+| Platform richness creates unusable public unions | Model separate typed commands and explicit per-platform presence from one spec family. |
+| Mixed MCP results do not fit one typed output | Type only structured payloads and stable errors; preserve the content envelope. |
+| Migration scope expands across large platform files | Start with session tools, prove one divergent slice, then migrate by family. |
+| TypeScript UniFFI inherits an immature toolchain | Treat it as green-field, pin everything, require deterministic generation and CI checking. |
+| Native client libraries complicate distribution | Measure the full matrix and retain thin MCP unless benefit is material. |
+| Cancellation is claimed but not implemented | Complete Workstream D or document non-cancelling deadline semantics. |
+| Direct embedding breaks permission or global-state assumptions | Keep it outside this plan and require a separate OS-specific proof. |
+
+## Non-goals
+
+- Reimplementing GUI actions in Python or TypeScript.
+- Removing the MCP server or CLI.
+- Publishing experimental packages during the comparison.
+- Promising browser-local desktop automation through WASM.
+- Directly embedding the GUI engine as part of the SDK-generation work.
+- Migrating every runtime tool before the typed foundation and decision gate are
+ stable.
+
+## Review disposition
+
+Claude Code Opus independently reviewed the repository, the original plan,
+the three platform registries, the current SDK generators, and Fleet's UniFFI
+artifacts. This revision incorporates its must-fix findings:
+
+- Fleet TypeScript is described as feasible but not reproducibly wired;
+- the live tool counts and parity claims are corrected;
+- A0 closes the immediate portable-subset gap;
+- capability ownership and platform-crate dependencies are explicit;
+- schema derivation is gated instead of assumed;
+- typed structured output is separated from mixed MCP content;
+- cancellation is treated as missing runtime design work; and
+- UniFFI adoption is language-split; direct MCP/CLI remains the agent baseline,
+ while thin MCP and UniFFI are compared only for imported application SDKs.
+
+## Implementation outcome and binding decision (2026-07-21)
+
+The implementation keeps MCP/CLI as the public agent boundary and makes typed
+Rust the source for the current fourteen-tool typed-client SDK surface:
+
+- Schemars-derived Rust input and structured-output types deterministically
+ generate the checked-in manifest and Python/TypeScript sources.
+- The four session tools consume the types directly. Each OS desktop branch
+ deserializes the shared portable projection before acting, while its richer
+ window/element path remains available to generic MCP callers.
+- Successful SDK-path structured payloads are deserialized through the shared
+ Rust output types in the live registry. The MCP content envelope remains
+ unchanged, including images, text, diagnostics, and errors.
+- The ten portable schemas are checked as logical subsets of each live
+ platform schema on Linux, macOS, and Windows. Unknown schema keywords fail
+ the implication checker closed.
+- Capability tokens for all fourteen tools resolve from the contract; the
+ legacy runtime capability map now covers only non-SDK tools.
+
+### Measured typed MCP-client baseline
+
+Measurements were taken from this checkout at version `0.10.0` before package
+publication:
+
+| Candidate | Maintained source | Generated source | Universal package |
+| ------------------ | ----------------: | ---------------: | --------------------------------------------: |
+| Python MCP SDK | 676 lines | 331 lines | 10,666-byte pure-Python wheel |
+| TypeScript MCP SDK | 278 lines | 275 lines | 4,923-byte npm tarball; 19,506 bytes unpacked |
+
+Both clients retain generic `call_tool` access and preserve the full MCP
+content/result envelope. Their executable fixture suites cover initialization,
+typed calls, errors, images, and generic runtime-only calls.
+
+### UniFFI repository spike
+
+The comparison used the latest checked-in Fleet precedent at
+`c2ba0b5e94d0f2c06d0c7efb0913803ca0a616af` rather than creating a second
+throwaway binding implementation with the same toolchain:
+
+- Fleet proves that official UniFFI Python bindings can be generated,
+ drift-checked, and exercised against a host-native cdylib.
+- Fleet also proves that Node and browser TypeScript generation is technically
+ possible through `uniffi-bindgen-react-native`; this is not merely WASM.
+- The checked-in Fleet TypeScript roots contain about 4,777 generated lines
+ (220 KiB), require `@ubjs/core`, `@ubjs/node`, and a colocated native cdylib,
+ and are not part of Fleet's pinned four-language generation/check script.
+ The runnable example declares those runtime/build dependencies as `latest`.
+- The Fleet Python generated root contains about 5,675 lines (228 KiB) for its
+ larger API. Those source sizes are toolchain evidence, not a like-for-like
+ API-size benchmark.
+
+### Current pull-request package decision
+
+**Python: retain the typed MCP client in this pull request.** UniFFI itself
+passes the feasibility and reproducibility gate, but Cua Driver does not yet
+have a shared Rust daemon client with meaningful application behavior. A
+facade over today's transport would add a per-platform, per-architecture cdylib
+and native-loader failure mode to a 10.4 KiB universal wheel while still
+speaking to the existing daemon.
+
+**TypeScript: retain the typed MCP client in this pull request.** The current
+precedent fails the plan's automatic adoption gate: generation is outside the
+pinned drift-check script, the runtime packages are unpinned, and consumers
+must locate a host-native library. Technical feasibility does not yet make it a
+reproducible npm release pipeline.
+
+This package decision does not reject a UniFFI embedded/server SDK and does not
+claim the generated clients improve MCP interoperability. MCP-capable agents
+should connect directly, as the agent examples demonstrate. A follow-up SDK
+proposal must decide whether its consumer needs a shared Rust daemon client or
+an embedded/server implementation, then evaluate UniFFI against that target.
+
+No rejected UniFFI spike code is retained. Cold-start and steady-state
+comparisons are intentionally not claimed: neither native candidate passed the
+packaging/reproducibility pre-gates that justify producing a release-matrix
+prototype. Reconsider Python when a reusable Rust daemon client or supported
+embedded host exists; reconsider TypeScript after pinned generation,
+deterministic CI checking, and native package loading land in the repository.
diff --git a/libs/cua-driver/docs/uniffi-sdk-implementation-journal.md b/libs/cua-driver/docs/uniffi-sdk-implementation-journal.md
new file mode 100644
index 0000000000..b6ead463f0
--- /dev/null
+++ b/libs/cua-driver/docs/uniffi-sdk-implementation-journal.md
@@ -0,0 +1,105 @@
+# UniFFI imported-SDK implementation journal
+
+Status: package-root SDK cleanup validated locally; pull-request exact-head CI pending
+
+## Definition of done
+
+Deliver an experimental imported-SDK vertical slice in pull request #2341 where:
+
+- Rust request types used by the live daemon are also the types exported through UniFFI.
+- A Rust `CuaDriver` object invokes the existing daemon protocol without routing through MCP.
+- Python and Node/TypeScript bindings are generated deterministically from the compiled Rust library.
+- Host-native loader tests exercise calls across both FFI boundaries.
+- CI checks Rust parity, generated-file drift, packaging inputs, and both loaders.
+- MCP/CLI remains the supported agent integration boundary; UniFFI is for applications importing Cua as an SDK.
+
+## Frozen baseline
+
+- Branch: `codex/experimental-cua-driver-contract-sdk`
+- Starting head: `07cec13ec1ecf2336d842b156993a83d4f713bfe`
+- Upstream main at start: `d5a5e33d6d0b5dc4998c4985bc0704d6df2b0a1d`
+- UniFFI: `0.31.0`, matching the repository's Fleet SDK precedent.
+- Node generator/runtime: `uniffi-bindgen-react-native` / `@ubjs/*` `0.31.0-3`.
+
+## Architecture decision
+
+The FFI library is a daemon client, not an in-process copy of the GUI engine. This preserves the daemon's process-wide session state, permission ownership, platform event-loop constraints, policy enforcement, and timeout behavior. The shared Rust contract remains transport-free and is consumed by both live tool handlers and the exported UniFFI methods.
+
+The public integration split remains:
+
+- Agent MCP/CLI: language-neutral protocol boundary, no generated client required.
+- Imported SDK: generated Python and Node/TypeScript bindings backed by one Rust implementation.
+
+The product boundary is reflected directly in packaging:
+
+- Python client applications import the Rust-backed SDK from `cua_driver`.
+- TypeScript client applications import it from `@trycua/cua-driver`.
+- Agents configure `cua-driver mcp` through their runtime's existing MCP client
+ and do not import either language package.
+- The language-native MCP facades and their contract generator were removed.
+- No public `.sdk`, `/sdk`, `.mcp`, `/mcp`, `.native`, or `/native` alias exists;
+ `native` remains only an internal loader/artifact term.
+
+## Initial audit
+
+- The live session handlers and desktop backends already deserialize `cua-driver-contract` request types.
+- Successful structured responses are validated against output types from that same crate.
+- The daemon socket protocol is currently defined inside the binary crate; it must be moved into shared Rust code so the binary, proxy, CLI, and UniFFI library use the same wire implementation.
+- Python UniFFI generation and colocated library loading are supported upstream.
+- Node N-API generation is available through `ubrn generate napi bindings`; it loads the same `cdylib` through `@ubjs/node` and currently requires a separately orchestrated Rust build.
+
+## Verification log
+
+### Rust and contract
+
+- `cargo check --locked --workspace --all-targets` passed. Existing
+ cross-platform example warnings remain outside this change.
+- `cargo test --locked -p cua-driver` passed: 115 unit tests and all enabled
+ integration suites passed; GUI/environment-dependent cases remained ignored.
+- `cargo test --locked -p cua-driver-core` passed: 329 unit tests, 2 contract
+ parity tests, and 3 session lifecycle tests.
+- `cargo test --locked -p cua-driver-sdk` passed: 4 tests covering published
+ method parity, typed desktop calls, typed session output, and tool discovery.
+- `cargo run --locked -p cua-driver-contract --bin cua-contract-gen -- all --check`
+ passed.
+- `node scripts/generate-uniffi-bindings.mjs --check` rebuilt the release
+ `cdylib` and reproduced every checked-in Python and TypeScript binding.
+
+### Language loaders and packages
+
+- Python generated-loader test: 1 passed across `ctypes` -> UniFFI -> Rust ->
+ Unix socket, and asserted all 14 typed methods are exported.
+- Python release-helper tests: 3 passed, including native-library membership
+ for every release archive target.
+- TypeScript typecheck and the actual N-API loader call passed, including all
+ 14 methods and proof that the removed package subpaths are not exported.
+- `npm audit --audit-level=high`: 0 vulnerabilities.
+- A built macOS arm64 wheel was installed into a clean Python 3.12 environment;
+ `cua_driver.CuaDriver.connect(None)` loaded the packaged library and
+ returned the canonical daemon socket path.
+- An actual 382.3 kB npm tarball (1.2 MB unpacked) was installed into a clean
+ project; the root imported without native code and
+ `@trycua/cua-driver` loaded the packaged dylib successfully.
+- The macOS dylib install ID is the relocatable
+ `@rpath/libcua_driver_sdk.dylib`, and release CI asserts it before signing.
+- After promoting the SDK to each package root, a fresh macOS arm64 wheel and
+ npm tarball were installed into clean Python 3.12 and Node projects. Both
+ roots loaded the Rust library and returned the canonical socket path; Python
+ contained no `sdk` or `native` module, Node exported no `/sdk`, `/native`, or
+ `/mcp` subpath, and neither artifact contained the removed MCP facade files.
+- Package-root cleanup validation passed: Python real-loader test (1), Python
+ packaging/wrapper tests (13 passed, 3 binary-dependent skips), TypeScript
+ typecheck, Node real-loader test (1), and `npm audit` (0 vulnerabilities).
+
+### CI and release boundary
+
+- The PR workflow parses successfully and checks deterministic generation,
+ Rust parity on Linux/macOS/Windows, both Linux FFI loaders, installed wheel
+ and npm-tarball smoke tests, and package contents.
+- Rust release artifacts now carry the SDK library on Linux, macOS, and
+ Windows. The Python release matrix installs every built wheel and imports the
+ generated binding before PyPI publication.
+- Full multi-OS/architecture assembly for one npm publication remains a stated
+ release gate. This pull request must not publish a host-local npm tarball.
+- MCP/CLI remains unchanged as the agent boundary; the language package roots
+ are the Rust-backed application SDK.
diff --git a/libs/cua-driver/docs/why-cua-driver-uses-mcp-instead-of-uniffi.md b/libs/cua-driver/docs/why-cua-driver-uses-mcp-instead-of-uniffi.md
new file mode 100644
index 0000000000..63f26b6824
--- /dev/null
+++ b/libs/cua-driver/docs/why-cua-driver-uses-mcp-instead-of-uniffi.md
@@ -0,0 +1,384 @@
+# Cua Driver integration surfaces: MCP/CLI and SDK bindings
+
+Status: accepted and implemented as an experimental imported-SDK vertical slice
+
+Decision date: 2026-07-21
+
+This document separates two Cua products that were previously discussed as if
+they were one: Cua as a tool used by an agent, and Cua as an API imported by an
+application. MCP and UniFFI solve different boundaries in those products and
+are not competing protocol choices.
+
+## The product distinction
+
+| Surface | Consumer | Public shape | What provides runtime portability |
+| -------------------------- | --------------------------------------------------------- | --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
+| Cua as an agent MCP or CLI | Codex, Claude Code, another agent, or a shell | `cua-driver mcp` and `cua-driver call` | MCP and the executable protocol already work from any capable runtime. |
+| Cua as an imported SDK | Python, TypeScript, Swift, Kotlin, or another application | `cua_driver` or `@trycua/cua-driver` | Python and Node call a shared Rust daemon-client implementation through experimental UniFFI bindings. |
+
+The [Codex and Claude Agent SDK examples](../examples/agent-sdks/README.md)
+make the first surface concrete. Each agent SDK receives the same stdio MCP
+server declaration and discovers the driver tools itself. Neither example
+imports a generated Cua client.
+
+## Decision
+
+1. Keep MCP and the CLI as the canonical agent boundary. Do not require a Cua
+ language package merely to connect an MCP-capable agent.
+2. Make `cua-driver` and `@trycua/cua-driver` application SDK packages backed
+ by UniFFI. Remove their language-native MCP facades because those duplicate
+ a runtime-neutral protocol client that agent runtimes already provide. This
+ deliberately makes the package API breaking before publication.
+3. Export the shared Rust request records for all 14 typed tools and the shared
+ typed session results. Desktop structured results retain platform extension
+ fields, so the native SDK preserves them in `ToolResult.structured_json`
+ while the live registry validates them with the canonical Rust result types.
+4. Use UniFFI as an SDK/server-composition architecture, not as a replacement
+ for the agent MCP boundary. The first slice exports a shared Rust daemon
+ client that application-owned servers can compose.
+5. Do not claim that direct engine embedding is ready today. Daemon-owned
+ state, permission identity, and OS event-loop behavior still require an
+ explicit embedding design.
+
+This corrects an earlier framing in which a thin MCP client and UniFFI were
+treated as alternatives for the same job.
+
+## Cua as an agent MCP or CLI
+
+```text
+Codex / Claude / another agent
+ -> that agent runtime's existing MCP client
+ -> cua-driver mcp
+ -> native driver daemon
+ -> OS APIs
+
+shell or automation
+ -> cua-driver call
+ -> native driver daemon
+ -> OS APIs
+```
+
+MCP already defines tool discovery, invocation, results, and errors across
+language runtimes. A Python agent and a TypeScript agent can consume the same
+server without Cua generating either agent's protocol client. Adding generated
+Python and TypeScript wrappers does not make this surface more runtime-neutral.
+
+Application code that wants autocomplete and typed direct calls uses the
+Rust-backed packages instead. The CLI remains useful for one-shot shell
+automation and deterministic lifecycle calls around an agent run.
+
+## Cua as an imported SDK
+
+The removed thin MCP facade used this architecture:
+
+```text
+application
+ -> generated Python or TypeScript method
+ -> small language-native MCP transport
+ -> cua-driver mcp
+ -> native driver daemon
+```
+
+The imported SDK implemented by this change uses:
+
+```text
+application
+ -> generated UniFFI binding
+ -> libcua_driver_sdk
+ - exported typed interfaces
+ - result normalization and error mapping
+ - shared daemon framing, timeouts, and observation metadata
+ -> native driver daemon
+ -> OS APIs
+```
+
+The retained architecture is where the O(1)-implementation-to-N-runtimes argument
+applies. Product behavior implemented once in Rust can be exported to N
+language runtimes without maintaining N behavioral clients. There is still
+per-platform and per-architecture native artifact, loader, signing, and CI
+work, so packaging is not literally constant effort. The important benefit is
+that behavior and interfaces do not get independently reimplemented in every
+language.
+
+The implementation calls the daemon's direct socket protocol, not MCP. The CLI,
+MCP proxy, and UniFFI library now import the same Rust request/response and
+socket implementation from `cua-driver-core`, so timeout or framing changes
+cannot drift by language. Application code can compose that object behind its
+own server without reimplementing the Cua protocol. Direct engine embedding
+remains a separate future architecture.
+
+## Public entrypoint vocabulary
+
+The package name is the SDK entrypoint; no transport suffix is required:
+
+| Runtime | Rust-backed application SDK | Agent integration |
+| --- | --- | --- |
+| Python | `cua_driver` | Configure `cua-driver mcp` in the agent runtime |
+| TypeScript | `@trycua/cua-driver` | Configure `cua-driver mcp` in the agent runtime |
+
+There is no public `/sdk`, `/mcp`, or `/native` entrypoint. “Native” describes
+the private generated loader and platform library, not the product API. The
+Python `_native` modules and TypeScript `dist/native` folder remain private
+implementation paths because they colocate UniFFI output with its platform
+library.
+
+## MCP and UniFFI are orthogonal
+
+MCP answers: "How does an agent or process call a tool across a service
+boundary?"
+
+UniFFI answers: "How does application code in several languages call one Rust
+library implementation?"
+
+A product can support both. MCP remains the language-neutral agent boundary,
+while UniFFI bindings can let application developers host or compose the Rust
+server/client implementation. Removing MCP is neither required nor desirable
+for adopting UniFFI.
+
+## Why Fleet is useful precedent
+
+Fleet places substantial portable client behavior in a Rust library loaded by
+the host application:
+
+```text
+application
+ -> generated UniFFI binding
+ -> libcyclops_sdk
+ - authentication and token refresh
+ - resource lifecycle and polling
+ - route construction and validation
+ - concurrency control
+ -> host-provided HttpClient
+ -> remote Fleet API
+```
+
+Fleet's Rust SDK contains behavior that would otherwise be repeated in every
+language. For example, [`client.rs`](../../fleet/sdk/src/client.rs) owns client
+configuration and namespace lifecycle locks. [`transport.rs`](../../fleet/sdk/src/transport.rs)
+owns OAuth token caching and refresh. The pool, claim, and service modules own
+polling, request construction, validation, and lifecycle rules.
+
+The host language supplies an [`HttpClient`](../../fleet/sdk/src/transport.rs)
+callback. This lets Python, Swift, Kotlin, Ruby, or TypeScript use a suitable
+HTTP implementation while Rust keeps the product behavior. UniFFI therefore
+replaces substantial duplicated implementations, and the shared library is the
+component the language API is meant to call.
+
+Fleet also has a mature checked-in generation path for Python, Kotlin, Swift,
+and Ruby. Its [`generate-sdk-bindings.sh`](../../fleet/scripts/generate-sdk-bindings.sh)
+script pins UniFFI through the Rust workspace, generates into temporary roots,
+tracks owned files, and checks drift.
+
+Fleet's Node and browser artifacts also establish an important fact: TypeScript
+UniFFI is not limited to WASM. The checked-in Node path uses
+`uniffi-bindgen-react-native`, `@ubjs/core`, `@ubjs/node`, and a colocated native
+library. That path proves feasibility. Its generator/runtime pinning and npm
+release matrix still need to be assessed independently before Cua copies the
+packaging design.
+
+Fleet therefore demonstrates the relevant architecture: bindings are for
+consumers that want the shared implementation, including consumers that may
+create a server. MCP clients do not need those bindings merely to call an
+already-running MCP server.
+
+## What the SDK adds
+
+The UniFFI surface adds:
+
+- one Rust implementation of daemon discovery, calls, error mapping, and result
+ normalization for Python and Node;
+- generated bindings for every one of the 14 published typed request records;
+- canonical typed session results generated from the same Rust records returned
+ by the live handlers; and
+- an open-ended `call_tool` JSON escape hatch for runtime and server adapters.
+
+It does not add:
+
+- agent/runtime interoperability, because MCP already provides it;
+- an in-process GUI engine; or
+- automatic publication of every native OS/architecture artifact.
+
+The host application now calls Rust in process, but Rust deliberately delegates
+GUI execution to the daemon. A host can build a server around this library; it
+does not receive an embedded automation engine.
+
+## Compatibility and migration
+
+Promoting UniFFI to the package roots is a deliberate breaking change to the
+pre-release language APIs. It removes Python `AsyncCuaDriver`,
+`CuaDriver.stdio()`, `*Args`, and transport classes, and removes the equivalent
+TypeScript async facade and stdio transport. The replacement `CuaDriver` is the
+synchronous Rust-backed SDK object created with `CuaDriver.connect(...)`.
+
+Application consumers migrate their typed calls to the generated UniFFI input
+records. Agent integrations remove the Cua language-package client entirely
+and configure `cua-driver mcp` through the agent SDK's existing MCP support.
+
+Package and runtime compatibility are harder to preserve. Native bindings add
+failure modes that JavaScript and Python code can encounter before the SDK
+connects to the driver:
+
+- The package must contain a compatible library for each supported OS and
+ architecture.
+- The loader must find that library and satisfy platform signing and security
+ policy.
+- Native artifacts must work in each supported host, including Node-based
+ desktop runtimes.
+- Import-time native failures need a defined fallback path.
+
+Consider an Electron application on Windows ARM64. The current TypeScript SDK
+can load as JavaScript and launch the installed driver. If UniFFI becomes the
+only transport, the same import may require a matching native artifact and
+loader. A missing build, incompatible host runtime, signing rejection, or
+library lookup failure can stop the application before it makes a driver call.
+The TypeScript method signatures could remain unchanged while installation and
+startup behavior break for that consumer.
+
+The SDK must remain experimental until the complete platform and host matrix
+loads successfully. Its package root intentionally requires the matching
+native artifact; loader failures are therefore a documented package/runtime
+compatibility risk rather than an implicit fallback to the removed MCP facade.
+
+An embedded/server SDK is a new product surface and should be versioned as
+such. Moving existing consumers from an out-of-process daemon to an in-process
+engine can be behaviorally breaking even when method signatures match, because
+permission identity, state lifetime, crash isolation, concurrency, and startup
+requirements change.
+
+Removing the executable MCP boundary or changing those behaviors would be a
+separate breaking change. The package cleanup removes only duplicated language
+MCP clients; `cua-driver mcp` remains supported. Adding a separate embedded SDK
+can be additive, while silently changing this daemon client to embed the engine
+would change process identity, permission ownership, state lifetime, and
+failure isolation.
+
+## Why direct engine embedding still needs design work
+
+UniFFI could remove MCP only if Cua Driver moved the GUI engine into the SDK
+consumer. The current runtime is not designed for that arrangement.
+
+The public CLI routes tool execution through the required daemon so policy,
+session state, and OS integration have one owner. On macOS, permission prompts
+and grants attach to the running driver identity, and UI work depends on the
+daemon's run loop. Windows also has daemon and UIAccess process concerns. Some
+authorization and runtime configuration is fixed for the daemon lifetime. The
+relevant startup and proxy rules are in [`cli.rs`](../rust/crates/cua-driver/src/cli.rs).
+
+Embedding would therefore require decisions about host identity, permission
+attribution, global state, event-loop ownership, concurrency, crash recovery,
+and coexistence between multiple host applications. Binding the current Rust
+functions would not answer those questions. We should treat an embedded driver
+as its own product architecture, with OS-specific proofs, rather than as a
+client-generation change.
+
+## Costs and limitations
+
+The MCP choice has costs that should remain visible:
+
+- Requests and results cross a JSON and process boundary.
+- Python and TypeScript each maintain a small transport implementation.
+- The SDK must manage proxy startup, shutdown, timeouts, and protocol-version
+ negotiation.
+- Stable typed methods and the open-ended MCP envelope need separate modeling.
+- Large screenshots pass through the protocol instead of an in-process buffer.
+
+The implemented UniFFI SDK removes the language-native MCP hop but retains the
+daemon process and JSON socket boundary. Its benefit is implementation and
+interface distribution, not a claimed screenshot-throughput improvement. An
+embedded/server SDK could remove the process hop only after the runtime issues
+above are solved. No performance claim is part of this decision without a
+comparable implementation and benchmark.
+
+Desktop successful results also remain an extensible protocol envelope rather
+than closed UniFFI records. Their canonical Rust validators intentionally carry
+per-platform extension maps, which UniFFI cannot export as arbitrary
+`serde_json::Value`. The SDK therefore returns typed text/image/error metadata
+plus `structured_json` and `raw_json`; only the stable session results cross FFI
+as dedicated records. Converting desktop results to closed records later would
+require either a versioned stable core plus an extension JSON field or a
+breaking removal of currently preserved platform data.
+
+## Why Rust and the runtime still have parity
+
+UniFFI is one way to make language bindings call Rust-defined interfaces. It is
+not the only way to prevent contract drift.
+
+The Cua Driver [`cua-driver-contract`](../rust/crates/cua-driver-contract/src/lib.rs)
+crate binds each published tool to typed Rust inputs and successful structured
+outputs. Those types produce the manifest and are exported through the compiled
+UniFFI SDK. The live session handlers consume the same inputs directly. Each
+desktop backend deserializes the shared portable projection before acting, and
+the live registry validates successful structured payloads with the same Rust
+output types. CI also proves that every portable schema is accepted by each
+supported OS registry.
+
+This closes the contract/runtime bookkeeping gap without generating a second
+Python or TypeScript MCP contract layer. MCP remains the agent process boundary;
+UniFFI distributes the Rust application SDK implementation. The contract
+architecture is described in the [contract README](../contract/README.md).
+
+## Implemented generation and packaging boundary
+
+Mozilla UniFFI `0.31.0` generates Python from the compiled `cdylib` metadata.
+Node generation uses the separately maintained
+`uniffi-bindgen-react-native`/UBRN `0.31.0-3` N-API target plus pinned
+`@ubjs/core` and `@ubjs/node` runtimes. The checked-in outputs are regenerated
+into temporary roots, tracked by ownership manifests, and compared byte for
+byte in CI.
+
+One current UBRN limitation is explicit and tested: version `0.31.0-3` cannot
+configure an external UniFFI component to load symbols from the parent SDK
+`cdylib`. The generator therefore performs one asserted post-processing step so
+the contract namespace and SDK namespace both load `libcua_driver_sdk`. If the
+expected generated selector changes, generation fails instead of silently
+patching an unrelated string.
+
+Python wheels are already platform-specific and the Rust release workflow now
+places the matching SDK library beside the CLI in each release runtime archive.
+The wheel builder moves that library next to the generated Python modules, and
+CI inspects the wheel and runs it across the FFI boundary. Node host-native
+assembly, `npm pack` inspection, and a real N-API loader test are also present.
+The npm package must not be published from a single developer host: release CI
+still needs to assemble the full Node OS/architecture matrix or split native
+artifacts into optional platform packages.
+
+## UniFFI follow-up gates
+
+Evaluate the two SDK targets separately.
+
+Before making the UniFFI path the default or publishing it as production-ready:
+
+1. Assemble and load-test the Node native artifact on every supported release
+ OS and architecture.
+2. Decide whether Node ships one multi-platform package or optional platform
+ packages and verify installation in Node-based desktop runtimes.
+3. Add release signing/notarization evidence for the native library everywhere
+ the platform requires it.
+4. Run the executable MCP boundary and imported SDK through the same daemon
+ conformance corpus so behavior remains equivalent across the two product
+ surfaces.
+
+For a UniFFI embedded/server SDK, proceed only after there is an officially
+supported host model with documented permission identity, event-loop ownership,
+state isolation, concurrency, and recovery. Measurement that MCP framing or
+process transfer materially affects supported workloads strengthens this case
+but does not replace the host-runtime design.
+
+Python and TypeScript should be evaluated independently because their binding,
+loader, and packaging toolchains differ. MCP and the CLI remain supported for
+agents regardless of either SDK decision.
+
+## Evidence snapshot
+
+This decision used:
+
+- Fleet commit `c2ba0b5e94d0f2c06d0c7efb0913803ca0a616af`, which added the checked-in
+ Go and TypeScript UniFFI artifacts;
+- Cua Driver SDK commit `896172754074f8c7ac26745685989df661714da6` before this
+ explanatory document;
+- the implementation measurements and adoption gates in the
+ [Rust source-of-truth and UniFFI evaluation](sdk-rust-source-of-truth-and-uniffi-evaluation-plan.md).
+
+The Fleet source had not changed between its cited commit and the latest
+`main` inspected on 2026-07-21. Recheck the generation and packaging claims if
+Fleet's binding pipeline changes.
diff --git a/libs/cua-driver/examples/agent-sdks/README.md b/libs/cua-driver/examples/agent-sdks/README.md
new file mode 100644
index 0000000000..c209070279
--- /dev/null
+++ b/libs/cua-driver/examples/agent-sdks/README.md
@@ -0,0 +1,75 @@
+# Use Cua Driver from agent SDKs
+
+These examples show **Cua as an agent tool**. Codex and Claude connect directly
+to `cua-driver mcp`; the agent SDK is the MCP client and discovers the live tool
+surface through `tools/list`.
+
+This is intentionally different from **Cua as an imported SDK**. An application
+that wants typed, programmatic calls can import the Python `cua-driver` package
+or the TypeScript `@trycua/cua-driver` package. Those packages are Rust-backed
+UniFFI SDKs that call the daemon directly; they do not provide MCP clients.
+
+## Prerequisites
+
+1. Install Cua Driver, grant the host OS permissions, and ensure its daemon is
+ running.
+2. Put `cua-driver` on `PATH`, or set `CUA_DRIVER_BIN` to its absolute path.
+3. Authenticate the selected agent SDK. The Codex SDK can use an existing Codex
+ login or `CODEX_API_KEY`; the Claude Agent SDK can use an existing Claude
+ Code login or `ANTHROPIC_API_KEY`.
+
+Both scripts create a unique Cua session with `cua-driver call start_session`,
+give that session ID to the agent, and call `end_session` in a `finally` block.
+The session's capture scope comes from `CUA_CAPTURE_SCOPE` and defaults to
+`auto`. Valid values are `auto`, `window`, and `desktop`.
+
+The examples let the model execute GUI actions without an interactive approval
+prompt. Run them only with a task you trust, and keep purchases, messages,
+deletions, credential entry, and other irreversible actions out of unattended
+prompts.
+
+## Python: Claude Agent SDK
+
+```bash
+cd libs/cua-driver/examples/agent-sdks
+python3.10 -m venv .venv
+.venv/bin/pip install -r requirements.txt
+
+CUA_CAPTURE_SCOPE=auto \
+ .venv/bin/python claude_agent.py \
+ "Open Calculator, compute 19 * 23, and report the result"
+```
+
+`tools=[]` removes Claude Code's built-in tools, `strict_mcp_config=True`
+ignores unrelated user/project MCP servers, and the `cua_driver` server is the
+only tool source supplied to the run.
+
+## TypeScript: Codex SDK
+
+```bash
+cd libs/cua-driver/examples/agent-sdks
+npm install
+
+CUA_CAPTURE_SCOPE=window \
+ npm run codex -- \
+ "Inspect the active app and summarize what is visible without changing it"
+```
+
+The Codex thread uses a read-only filesystem sandbox and `approvalPolicy:
+"never"`; desktop actions still happen through the separately configured
+`cua_driver` MCP server. The prompt tells Codex not to substitute shell or
+filesystem operations for the MCP tools.
+
+## Local checks without running an agent
+
+These checks do not require API credentials or a live desktop:
+
+```bash
+python3.10 -m py_compile claude_agent.py
+npm run typecheck
+```
+
+The examples intentionally do not import the Cua Driver language packages.
+That absence is the architectural point: an MCP-capable agent already has a
+runtime-neutral client. Use the packages only when application code wants
+typed direct calls rather than an agent-controlled tool loop.
diff --git a/libs/cua-driver/examples/agent-sdks/claude_agent.py b/libs/cua-driver/examples/agent-sdks/claude_agent.py
new file mode 100644
index 0000000000..e6ea17c6aa
--- /dev/null
+++ b/libs/cua-driver/examples/agent-sdks/claude_agent.py
@@ -0,0 +1,124 @@
+"""Run a Claude Agent SDK desktop task through Cua Driver's MCP server."""
+
+from __future__ import annotations
+
+import argparse
+import asyncio
+import json
+import os
+import shutil
+from pathlib import Path
+from typing import Literal, cast
+from uuid import uuid4
+
+from claude_agent_sdk import ClaudeAgentOptions, ClaudeSDKClient, ResultMessage
+
+CaptureScope = Literal["auto", "window", "desktop"]
+
+
+def parse_args() -> argparse.Namespace:
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument("task", help="Trusted desktop task for Claude to perform")
+ return parser.parse_args()
+
+
+def driver_binary() -> str:
+ configured = os.environ.get("CUA_DRIVER_BIN")
+ if configured:
+ return configured
+ discovered = shutil.which("cua-driver")
+ if discovered:
+ return discovered
+ raise RuntimeError("cua-driver is not on PATH; set CUA_DRIVER_BIN")
+
+
+def capture_scope() -> CaptureScope:
+ value = os.environ.get("CUA_CAPTURE_SCOPE", "auto")
+ if value not in {"auto", "window", "desktop"}:
+ raise ValueError("CUA_CAPTURE_SCOPE must be auto, window, or desktop")
+ return cast(CaptureScope, value)
+
+
+async def driver_call(binary: str, tool: str, arguments: dict[str, str]) -> None:
+ process = await asyncio.create_subprocess_exec(
+ binary,
+ "call",
+ tool,
+ json.dumps(arguments),
+ stdout=asyncio.subprocess.PIPE,
+ stderr=asyncio.subprocess.PIPE,
+ )
+ stdout, stderr = await process.communicate()
+ if process.returncode != 0:
+ detail = stderr.decode().strip() or stdout.decode().strip()
+ raise RuntimeError(f"cua-driver call {tool} failed: {detail}")
+
+
+def agent_prompt(task: str, session: str, scope: CaptureScope) -> str:
+ return f"""Complete this desktop task through the cua_driver MCP server:
+
+{task}
+
+The host has already started session {session!r} with capture scope {scope!r}.
+Use only cua_driver MCP tools for desktop observation and interaction. Do not
+substitute shell, filesystem, web, or code-execution tools. Pass session
+{session!r} to every Cua tool that accepts a session. Inspect state before each
+action and verify state after it. Do not call start_session or end_session; the
+host owns lifecycle cleanup. Do not perform purchases, send messages, delete
+data, expose credentials, or take another irreversible action unless the task
+explicitly requests that exact action. Return a concise result and mention any
+step you could not verify.
+"""
+
+
+async def run(task: str) -> None:
+ binary = driver_binary()
+ scope = capture_scope()
+ session = f"claude-agent-{uuid4().hex[:12]}"
+ started = False
+
+ try:
+ await driver_call(
+ binary,
+ "start_session",
+ {"session": session, "capture_scope": scope},
+ )
+ started = True
+
+ options = ClaudeAgentOptions(
+ model=os.environ.get("CLAUDE_MODEL"),
+ cwd=Path.cwd(),
+ tools=[],
+ mcp_servers={
+ "cua_driver": {
+ "type": "stdio",
+ "command": binary,
+ "args": ["mcp"],
+ }
+ },
+ strict_mcp_config=True,
+ allowed_tools=["mcp__cua_driver"],
+ permission_mode="dontAsk",
+ max_turns=40,
+ )
+
+ final_result: ResultMessage | None = None
+ async with ClaudeSDKClient(options=options) as client:
+ await client.query(agent_prompt(task, session, scope))
+ async for message in client.receive_response():
+ if isinstance(message, ResultMessage):
+ final_result = message
+
+ if final_result is None:
+ raise RuntimeError("Claude Agent SDK returned no final result")
+ if final_result.is_error:
+ raise RuntimeError(final_result.result or ", ".join(final_result.errors or []))
+ print(final_result.result or "Claude completed the task without a text result.")
+ finally:
+ if started:
+ await driver_call(binary, "end_session", {"session": session})
+
+
+if __name__ == "__main__":
+ arguments = parse_args()
+ asyncio.run(run(arguments.task))
diff --git a/libs/cua-driver/examples/agent-sdks/codex-sdk-mcp-types.d.ts b/libs/cua-driver/examples/agent-sdks/codex-sdk-mcp-types.d.ts
new file mode 100644
index 0000000000..011014b681
--- /dev/null
+++ b/libs/cua-driver/examples/agent-sdks/codex-sdk-mcp-types.d.ts
@@ -0,0 +1,9 @@
+// @openai/codex-sdk exposes this upstream type without declaring the MCP SDK
+// as a package dependency. The example only reads Codex's final text, so this
+// structural declaration is sufficient and avoids adding an unused runtime.
+declare module '@modelcontextprotocol/sdk/types.js' {
+ export interface ContentBlock {
+ type: string;
+ [key: string]: unknown;
+ }
+}
diff --git a/libs/cua-driver/examples/agent-sdks/codex_agent.ts b/libs/cua-driver/examples/agent-sdks/codex_agent.ts
new file mode 100644
index 0000000000..f84028ed3f
--- /dev/null
+++ b/libs/cua-driver/examples/agent-sdks/codex_agent.ts
@@ -0,0 +1,98 @@
+/** Run a Codex SDK desktop task through Cua Driver's MCP server. */
+
+import { execFile } from 'node:child_process';
+import process from 'node:process';
+import { promisify } from 'node:util';
+import { randomUUID } from 'node:crypto';
+
+import { Codex } from '@openai/codex-sdk';
+
+type CaptureScope = 'auto' | 'window' | 'desktop';
+
+const execFileAsync = promisify(execFile);
+
+function taskFromArgs(): string {
+ const task = process.argv.slice(2).join(' ').trim();
+ if (!task) {
+ throw new Error('usage: npm run codex -- "<trusted desktop task>"');
+ }
+ return task;
+}
+
+function captureScope(): CaptureScope {
+ const value = process.env.CUA_CAPTURE_SCOPE ?? 'auto';
+ if (value !== 'auto' && value !== 'window' && value !== 'desktop') {
+ throw new Error('CUA_CAPTURE_SCOPE must be auto, window, or desktop');
+ }
+ return value;
+}
+
+async function driverCall(
+ binary: string,
+ tool: string,
+ args: Record<string, string>
+): Promise<void> {
+ await execFileAsync(binary, ['call', tool, JSON.stringify(args)], {
+ timeout: 30_000,
+ });
+}
+
+function agentPrompt(task: string, session: string, scope: CaptureScope): string {
+ return `Complete this desktop task through the cua_driver MCP server:
+
+${task}
+
+The host has already started session ${JSON.stringify(session)} with capture
+scope ${JSON.stringify(scope)}. Use only cua_driver MCP tools for desktop
+observation and interaction. Do not substitute shell, filesystem, web, or code
+execution. Pass session ${JSON.stringify(session)} to every Cua tool that
+accepts a session. Inspect state before each action and verify state after it.
+Do not call start_session or end_session; the host owns lifecycle cleanup. Do
+not perform purchases, send messages, delete data, expose credentials, or take
+another irreversible action unless the task explicitly requests that exact
+action. Return a concise result and mention any step you could not verify.`;
+}
+
+async function main(): Promise<void> {
+ const task = taskFromArgs();
+ const binary = process.env.CUA_DRIVER_BIN ?? 'cua-driver';
+ const scope = captureScope();
+ const session = `codex-agent-${randomUUID().slice(0, 12)}`;
+ let started = false;
+
+ try {
+ await driverCall(binary, 'start_session', {
+ session,
+ capture_scope: scope,
+ });
+ started = true;
+
+ const codex = new Codex({
+ config: {
+ mcp_servers: {
+ cua_driver: {
+ command: binary,
+ args: ['mcp'],
+ startup_timeout_sec: 30,
+ },
+ },
+ },
+ });
+ const model = process.env.CODEX_MODEL;
+ const thread = codex.startThread({
+ ...(model ? { model } : {}),
+ sandboxMode: 'read-only',
+ approvalPolicy: 'never',
+ skipGitRepoCheck: true,
+ });
+
+ const result = await thread.run(agentPrompt(task, session, scope));
+ console.log(result.finalResponse);
+ } finally {
+ if (started) {
+ await driverCall(binary, 'end_session', { session });
+ }
+ }
+}
+
+await main();
diff --git a/libs/cua-driver/examples/agent-sdks/package-lock.json b/libs/cua-driver/examples/agent-sdks/package-lock.json
new file mode 100644
index 0000000000..2180187141
--- /dev/null
+++ b/libs/cua-driver/examples/agent-sdks/package-lock.json
@@ -0,0 +1,725 @@
+{
+ "name": "cua-driver-agent-sdk-examples",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "cua-driver-agent-sdk-examples",
+ "dependencies": {
+ "@openai/codex-sdk": "0.145.0"
+ },
+ "devDependencies": {
+ "@types/node": "22.17.0",
+ "tsx": "4.20.3",
+ "typescript": "5.9.2"
+ }
+ },
+ "node_modules/@esbuild/aix-ppc64": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.12.tgz",
+ "integrity": "sha512-Hhmwd6CInZ3dwpuGTF8fJG6yoWmsToE+vYgD4nytZVxcu1ulHpUQRAB1UJ8+N1Am3Mz4+xOByoQoSZf4D+CpkA==",
+ "cpu": [
+ "ppc64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "aix"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/android-arm": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.25.12.tgz",
+ "integrity": "sha512-VJ+sKvNA/GE7Ccacc9Cha7bpS8nyzVv0jdVgwNDaR4gDMC/2TTRc33Ip8qrNYUcpkOHUT5OZ0bUcNNVZQ9RLlg==",
+ "cpu": [
+ "arm"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/android-arm64": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.25.12.tgz",
+ "integrity": "sha512-6AAmLG7zwD1Z159jCKPvAxZd4y/VTO0VkprYy+3N2FtJ8+BQWFXU+OxARIwA46c5tdD9SsKGZ/1ocqBS/gAKHg==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/android-x64": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.25.12.tgz",
+ "integrity": "sha512-5jbb+2hhDHx5phYR2By8GTWEzn6I9UqR11Kwf22iKbNpYrsmRB18aX/9ivc5cabcUiAT/wM+YIZ6SG9QO6a8kg==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/darwin-arm64": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.25.12.tgz",
+ "integrity": "sha512-N3zl+lxHCifgIlcMUP5016ESkeQjLj/959RxxNYIthIg+CQHInujFuXeWbWMgnTo4cp5XVHqFPmpyu9J65C1Yg==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/darwin-x64": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.25.12.tgz",
+ "integrity": "sha512-HQ9ka4Kx21qHXwtlTUVbKJOAnmG1ipXhdWTmNXiPzPfWKpXqASVcWdnf2bnL73wgjNrFXAa3yYvBSd9pzfEIpA==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/freebsd-arm64": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.12.tgz",
+ "integrity": "sha512-gA0Bx759+7Jve03K1S0vkOu5Lg/85dou3EseOGUes8flVOGxbhDDh/iZaoek11Y8mtyKPGF3vP8XhnkDEAmzeg==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "freebsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/freebsd-x64": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.25.12.tgz",
+ "integrity": "sha512-TGbO26Yw2xsHzxtbVFGEXBFH0FRAP7gtcPE7P5yP7wGy7cXK2oO7RyOhL5NLiqTlBh47XhmIUXuGciXEqYFfBQ==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "freebsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-arm": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.25.12.tgz",
+ "integrity": "sha512-lPDGyC1JPDou8kGcywY0YILzWlhhnRjdof3UlcoqYmS9El818LLfJJc3PXXgZHrHCAKs/Z2SeZtDJr5MrkxtOw==",
+ "cpu": [
+ "arm"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-arm64": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.25.12.tgz",
+ "integrity": "sha512-8bwX7a8FghIgrupcxb4aUmYDLp8pX06rGh5HqDT7bB+8Rdells6mHvrFHHW2JAOPZUbnjUpKTLg6ECyzvas2AQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-ia32": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.25.12.tgz",
+ "integrity": "sha512-0y9KrdVnbMM2/vG8KfU0byhUN+EFCny9+8g202gYqSSVMonbsCfLjUO+rCci7pM0WBEtz+oK/PIwHkzxkyharA==",
+ "cpu": [
+ "ia32"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-loong64": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.25.12.tgz",
+ "integrity": "sha512-h///Lr5a9rib/v1GGqXVGzjL4TMvVTv+s1DPoxQdz7l/AYv6LDSxdIwzxkrPW438oUXiDtwM10o9PmwS/6Z0Ng==",
+ "cpu": [
+ "loong64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-mips64el": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.25.12.tgz",
+ "integrity": "sha512-iyRrM1Pzy9GFMDLsXn1iHUm18nhKnNMWscjmp4+hpafcZjrr2WbT//d20xaGljXDBYHqRcl8HnxbX6uaA/eGVw==",
+ "cpu": [
+ "mips64el"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-ppc64": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.25.12.tgz",
+ "integrity": "sha512-9meM/lRXxMi5PSUqEXRCtVjEZBGwB7P/D4yT8UG/mwIdze2aV4Vo6U5gD3+RsoHXKkHCfSxZKzmDssVlRj1QQA==",
+ "cpu": [
+ "ppc64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-riscv64": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.25.12.tgz",
+ "integrity": "sha512-Zr7KR4hgKUpWAwb1f3o5ygT04MzqVrGEGXGLnj15YQDJErYu/BGg+wmFlIDOdJp0PmB0lLvxFIOXZgFRrdjR0w==",
+ "cpu": [
+ "riscv64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-s390x": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.25.12.tgz",
+ "integrity": "sha512-MsKncOcgTNvdtiISc/jZs/Zf8d0cl/t3gYWX8J9ubBnVOwlk65UIEEvgBORTiljloIWnBzLs4qhzPkJcitIzIg==",
+ "cpu": [
+ "s390x"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-x64": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.25.12.tgz",
+ "integrity": "sha512-uqZMTLr/zR/ed4jIGnwSLkaHmPjOjJvnm6TVVitAa08SLS9Z0VM8wIRx7gWbJB5/J54YuIMInDquWyYvQLZkgw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/netbsd-arm64": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.12.tgz",
+ "integrity": "sha512-xXwcTq4GhRM7J9A8Gv5boanHhRa/Q9KLVmcyXHCTaM4wKfIpWkdXiMog/KsnxzJ0A1+nD+zoecuzqPmCRyBGjg==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "netbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/netbsd-x64": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.25.12.tgz",
+ "integrity": "sha512-Ld5pTlzPy3YwGec4OuHh1aCVCRvOXdH8DgRjfDy/oumVovmuSzWfnSJg+VtakB9Cm0gxNO9BzWkj6mtO1FMXkQ==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "netbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/openbsd-arm64": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.12.tgz",
+ "integrity": "sha512-fF96T6KsBo/pkQI950FARU9apGNTSlZGsv1jZBAlcLL1MLjLNIWPBkj5NlSz8aAzYKg+eNqknrUJ24QBybeR5A==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "openbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/openbsd-x64": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.25.12.tgz",
+ "integrity": "sha512-MZyXUkZHjQxUvzK7rN8DJ3SRmrVrke8ZyRusHlP+kuwqTcfWLyqMOE3sScPPyeIXN/mDJIfGXvcMqCgYKekoQw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "openbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/openharmony-arm64": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.25.12.tgz",
+ "integrity": "sha512-rm0YWsqUSRrjncSXGA7Zv78Nbnw4XL6/dzr20cyrQf7ZmRcsovpcRBdhD43Nuk3y7XIoW2OxMVvwuRvk9XdASg==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "openharmony"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/sunos-x64": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.25.12.tgz",
+ "integrity": "sha512-3wGSCDyuTHQUzt0nV7bocDy72r2lI33QL3gkDNGkod22EsYl04sMf0qLb8luNKTOmgF/eDEDP5BFNwoBKH441w==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "sunos"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/win32-arm64": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.25.12.tgz",
+ "integrity": "sha512-rMmLrur64A7+DKlnSuwqUdRKyd3UE7oPJZmnljqEptesKM8wx9J8gx5u0+9Pq0fQQW8vqeKebwNXdfOyP+8Bsg==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/win32-ia32": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.25.12.tgz",
+ "integrity": "sha512-HkqnmmBoCbCwxUKKNPBixiWDGCpQGVsrQfJoVGYLPT41XWF8lHuE5N6WhVia2n4o5QK5M4tYr21827fNhi4byQ==",
+ "cpu": [
+ "ia32"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/win32-x64": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.25.12.tgz",
+ "integrity": "sha512-alJC0uCZpTFrSL0CCDjcgleBXPnCrEAhTBILpeAp7M/OFgoqtAetfBzX0xM00MUsVVPpVjlPuMbREqnZCXaTnA==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@openai/codex": {
+ "version": "0.145.0",
+ "resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.145.0.tgz",
+ "integrity": "sha512-/PSPSFujjjmiyVFvG2yu/grOFhsWdokTH8t2KGWhXSo/M5n/dIDsnbsnO82/7bLtIoDuzQf7ATBUMWqPWQINlQ==",
+ "license": "Apache-2.0",
+ "bin": {
+ "codex": "bin/codex.js"
+ },
+ "engines": {
+ "node": ">=16"
+ },
+ "optionalDependencies": {
+ "@openai/codex-darwin-arm64": "npm:@openai/[email protected]",
+ "@openai/codex-darwin-x64": "npm:@openai/[email protected]",
+ "@openai/codex-linux-arm64": "npm:@openai/[email protected]",
+ "@openai/codex-linux-x64": "npm:@openai/[email protected]",
+ "@openai/codex-win32-arm64": "npm:@openai/[email protected]",
+ "@openai/codex-win32-x64": "npm:@openai/[email protected]"
+ }
+ },
+ "node_modules/@openai/codex-darwin-arm64": {
+ "name": "@openai/codex",
+ "version": "0.145.0-darwin-arm64",
+ "resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.145.0-darwin-arm64.tgz",
+ "integrity": "sha512-h6aQ0UxnaP8mIM/9/qPAH9MNkRliJo88toq1T36IxNM2L5JSU0TFamu+MZn7YkFgDsrp0RfiI+97Tm8AVVxqtA==",
+ "cpu": [
+ "arm64"
+ ],
+ "license": "Apache-2.0",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">=16"
+ }
+ },
+ "node_modules/@openai/codex-darwin-x64": {
+ "name": "@openai/codex",
+ "version": "0.145.0-darwin-x64",
+ "resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.145.0-darwin-x64.tgz",
+ "integrity": "sha512-FCYzVKCa9VoLtg9gVyzKpqylonfgZrfcWZN6HsXAZPeuo8CukdMqdgTUOhDn2V6h3MbqS0z6VqQVKUllN/yKhA==",
+ "cpu": [
+ "x64"
+ ],
+ "license": "Apache-2.0",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">=16"
+ }
+ },
+ "node_modules/@openai/codex-linux-arm64": {
+ "name": "@openai/codex",
+ "version": "0.145.0-linux-arm64",
+ "resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.145.0-linux-arm64.tgz",
+ "integrity": "sha512-8OLcPXaAol/FOrRoDxWhIiHIFa73KRsM41EKocjRZOwiT4TcelzJWn3dHyiuSb7teWF25rrslvSPyvhULYRRCQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "license": "Apache-2.0",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=16"
+ }
+ },
+ "node_modules/@openai/codex-linux-x64": {
+ "name": "@openai/codex",
+ "version": "0.145.0-linux-x64",
+ "resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.145.0-linux-x64.tgz",
+ "integrity": "sha512-u8w8LLv3DvsfrDCoswLIemZ0SoNEXyi511WsfFsSiYUazk9qMsB/NtU8N9vhAfN7mZAxLFoMex4v66JjHuZWwA==",
+ "cpu": [
+ "x64"
+ ],
+ "license": "Apache-2.0",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=16"
+ }
+ },
+ "node_modules/@openai/codex-sdk": {
+ "version": "0.145.0",
+ "resolved": "https://registry.npmjs.org/@openai/codex-sdk/-/codex-sdk-0.145.0.tgz",
+ "integrity": "sha512-lBviqBKnomEXNpdjfDzUoz/H+VZuK75m2oR8dQSmL2zUpnklfAsTneuaSg23NOoE+vw/Qhbxp8ePy9te973yfw==",
+ "license": "Apache-2.0",
+ "dependencies": {
+ "@openai/codex": "0.145.0"
+ },
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@openai/codex-win32-arm64": {
+ "name": "@openai/codex",
+ "version": "0.145.0-win32-arm64",
+ "resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.145.0-win32-arm64.tgz",
+ "integrity": "sha512-sub61rjEFevi1i3Zx7nAd4JM5XxoNFqMqFc5LfTo2xSI8ixHjFvEYDFDXwXOftT04n3Ht1Wh271ioUZpDiEjEg==",
+ "cpu": [
+ "arm64"
+ ],
+ "license": "Apache-2.0",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=16"
+ }
+ },
+ "node_modules/@openai/codex-win32-x64": {
+ "name": "@openai/codex",
+ "version": "0.145.0-win32-x64",
+ "resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.145.0-win32-x64.tgz",
+ "integrity": "sha512-u0h9lk094CaXRSqE34SBW2dRaQTPa6fASXqehczWH9QdsU62mBsiAgAdp6tCG4i+YzPmmhjD8FdXNnYGNmwuMg==",
+ "cpu": [
+ "x64"
+ ],
+ "license": "Apache-2.0",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=16"
+ }
+ },
+ "node_modules/@types/node": {
+ "version": "22.17.0",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-22.17.0.tgz",
+ "integrity": "sha512-bbAKTCqX5aNVryi7qXVMi+OkB3w/OyblodicMbvE38blyAz7GxXf6XYhklokijuPwwVg9sDLKRxt0ZHXQwZVfQ==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "undici-types": "~6.21.0"
+ }
+ },
+ "node_modules/esbuild": {
+ "version": "0.25.12",
+ "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.12.tgz",
+ "integrity": "sha512-bbPBYYrtZbkt6Os6FiTLCTFxvq4tt3JKall1vRwshA3fdVztsLAatFaZobhkBC8/BrPetoa0oksYoKXoG4ryJg==",
+ "dev": true,
+ "hasInstallScript": true,
+ "license": "MIT",
+ "bin": {
+ "esbuild": "bin/esbuild"
+ },
+ "engines": {
+ "node": ">=18"
+ },
+ "optionalDependencies": {
+ "@esbuild/aix-ppc64": "0.25.12",
+ "@esbuild/android-arm": "0.25.12",
+ "@esbuild/android-arm64": "0.25.12",
+ "@esbuild/android-x64": "0.25.12",
+ "@esbuild/darwin-arm64": "0.25.12",
+ "@esbuild/darwin-x64": "0.25.12",
+ "@esbuild/freebsd-arm64": "0.25.12",
+ "@esbuild/freebsd-x64": "0.25.12",
+ "@esbuild/linux-arm": "0.25.12",
+ "@esbuild/linux-arm64": "0.25.12",
+ "@esbuild/linux-ia32": "0.25.12",
+ "@esbuild/linux-loong64": "0.25.12",
+ "@esbuild/linux-mips64el": "0.25.12",
+ "@esbuild/linux-ppc64": "0.25.12",
+ "@esbuild/linux-riscv64": "0.25.12",
+ "@esbuild/linux-s390x": "0.25.12",
+ "@esbuild/linux-x64": "0.25.12",
+ "@esbuild/netbsd-arm64": "0.25.12",
+ "@esbuild/netbsd-x64": "0.25.12",
+ "@esbuild/openbsd-arm64": "0.25.12",
+ "@esbuild/openbsd-x64": "0.25.12",
+ "@esbuild/openharmony-arm64": "0.25.12",
+ "@esbuild/sunos-x64": "0.25.12",
+ "@esbuild/win32-arm64": "0.25.12",
+ "@esbuild/win32-ia32": "0.25.12",
+ "@esbuild/win32-x64": "0.25.12"
+ }
+ },
+ "node_modules/fsevents": {
+ "version": "2.3.3",
+ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
+ "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
+ "dev": true,
+ "hasInstallScript": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
+ }
+ },
+ "node_modules/get-tsconfig": {
+ "version": "4.14.0",
+ "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.14.0.tgz",
+ "integrity": "sha512-yTb+8DXzDREzgvYmh6s9vHsSVCHeC0G3PI5bEXNBHtmshPnO+S5O7qgLEOn0I5QvMy6kpZN8K1NKGyilLb93wA==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "resolve-pkg-maps": "^1.0.0"
+ },
+ "funding": {
+ "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1"
+ }
+ },
+ "node_modules/resolve-pkg-maps": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz",
+ "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==",
+ "dev": true,
+ "license": "MIT",
+ "funding": {
+ "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1"
+ }
+ },
+ "node_modules/tsx": {
+ "version": "4.20.3",
+ "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.20.3.tgz",
+ "integrity": "sha512-qjbnuR9Tr+FJOMBqJCW5ehvIo/buZq7vH7qD7JziU98h6l3qGy0a/yPFjwO+y0/T7GFpNgNAvEcPPVfyT8rrPQ==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "esbuild": "~0.25.0",
+ "get-tsconfig": "^4.7.5"
+ },
+ "bin": {
+ "tsx": "dist/cli.mjs"
+ },
+ "engines": {
+ "node": ">=18.0.0"
+ },
+ "optionalDependencies": {
+ "fsevents": "~2.3.3"
+ }
+ },
+ "node_modules/typescript": {
+ "version": "5.9.2",
+ "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.2.tgz",
+ "integrity": "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A==",
+ "dev": true,
+ "license": "Apache-2.0",
+ "bin": {
+ "tsc": "bin/tsc",
+ "tsserver": "bin/tsserver"
+ },
+ "engines": {
+ "node": ">=14.17"
+ }
+ },
+ "node_modules/undici-types": {
+ "version": "6.21.0",
+ "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
+ "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
+ "dev": true,
+ "license": "MIT"
+ }
+ }
+}
diff --git a/libs/cua-driver/examples/agent-sdks/package.json b/libs/cua-driver/examples/agent-sdks/package.json
new file mode 100644
index 0000000000..026e260af3
--- /dev/null
+++ b/libs/cua-driver/examples/agent-sdks/package.json
@@ -0,0 +1,17 @@
+{
+ "name": "cua-driver-agent-sdk-examples",
+ "private": true,
+ "type": "module",
+ "scripts": {
+ "codex": "tsx codex_agent.ts",
+ "typecheck": "tsc --noEmit"
+ },
+ "dependencies": {
+ "@openai/codex-sdk": "0.145.0"
+ },
+ "devDependencies": {
+ "@types/node": "22.17.0",
+ "tsx": "4.20.3",
+ "typescript": "5.9.2"
+ }
+}
diff --git a/libs/cua-driver/examples/agent-sdks/requirements.txt b/libs/cua-driver/examples/agent-sdks/requirements.txt
new file mode 100644
index 0000000000..f560964f00
--- /dev/null
+++ b/libs/cua-driver/examples/agent-sdks/requirements.txt
@@ -0,0 +1 @@
+claude-agent-sdk==0.2.124
diff --git a/libs/cua-driver/examples/agent-sdks/tsconfig.json b/libs/cua-driver/examples/agent-sdks/tsconfig.json
new file mode 100644
index 0000000000..469777dd65
--- /dev/null
+++ b/libs/cua-driver/examples/agent-sdks/tsconfig.json
@@ -0,0 +1,12 @@
+{
+ "compilerOptions": {
+ "lib": ["ES2022"],
+ "module": "NodeNext",
+ "moduleResolution": "NodeNext",
+ "noEmit": true,
+ "strict": true,
+ "target": "ES2022",
+ "types": ["node"]
+ },
+ "include": ["codex_agent.ts", "*.d.ts"]
+}
diff --git a/libs/cua-driver/python/.cua-driver-uniffi-generated-files b/libs/cua-driver/python/.cua-driver-uniffi-generated-files
new file mode 100644
index 0000000000..9e03c8978e
--- /dev/null
+++ b/libs/cua-driver/python/.cua-driver-uniffi-generated-files
@@ -0,0 +1,3 @@
+# Generated by scripts/generate-uniffi-bindings.mjs; one owned path per line.
+src/cua_driver/_native.py
+src/cua_driver/_native_contract.py
diff --git a/libs/cua-driver/python/.gitignore b/libs/cua-driver/python/.gitignore
index be583c0539..7c5a1986e1 100644
--- a/libs/cua-driver/python/.gitignore
+++ b/libs/cua-driver/python/.gitignore
@@ -9,6 +9,9 @@ __pycache__/
# Downloaded binaries and archives
downloads/
src/cua_driver/bin/
+src/cua_driver/*.dylib
+src/cua_driver/*.so
+src/cua_driver/*.dll
# Virtual environments
venv/
diff --git a/libs/cua-driver/python/README.md b/libs/cua-driver/python/README.md
index 5a56e18329..b8c90350fb 100644
--- a/libs/cua-driver/python/README.md
+++ b/libs/cua-driver/python/README.md
@@ -1,53 +1,86 @@
-# cua-driver
+# cua-driver Python SDK
-Python wrapper for [cua-driver](https://github.com/trycua/cua/tree/main/libs/cua-driver) - a cross-platform MCP (Model Context Protocol) server for computer-use automation.
+Rust-backed Python SDK and bundled executable for
+[Cua Driver](https://github.com/trycua/cua/tree/main/libs/cua-driver).
+
+## Product boundary
+
+This package is for client applications importing Cua Driver as an SDK:
+
+```python
+from cua_driver import CuaDriver
+```
+
+It does not contain a Python MCP client. Agents already have runtime-neutral
+MCP clients and should configure the bundled server directly:
+
+```text
+cua-driver mcp
+```
+
+The removed pre-release MCP facade used `CuaDriver.stdio()`,
+`AsyncCuaDriver`, `*Args`, and transport classes. Application code migrates to
+the synchronous Rust-backed methods shown below; agent code removes the Cua
+package import and supplies `cua-driver mcp` to its agent SDK.
## Installation
Install and usage docs live at https://cua.ai/docs/how-to-guides/driver/install
and https://cua.ai/docs/reference/cua-driver/mcp-tools.
-## Usage
+The wheel contains generated UniFFI bindings, a platform-specific Rust SDK
+library, and the `cua-driver` executable. The daemon must be running and have
+the required OS permissions before SDK calls are made.
-The package provides a `cua-driver` command that wraps the native Rust binary.
-See the canonical tool reference at https://cua.ai/docs/reference/cua-driver/mcp-tools.
+## SDK example
-## Python API
+```python
+from cua_driver import (
+ CaptureScope,
+ CuaDriver,
+ EndSessionInput,
+ GetDesktopStateInput,
+ StartSessionInput,
+)
+
+driver = CuaDriver.connect(None) # or pass an explicit daemon socket path
+driver.start_session(
+ StartSessionInput(session="demo", capture_scope=CaptureScope.DESKTOP)
+)
+try:
+ desktop = driver.get_desktop_state(
+ GetDesktopStateInput(session="demo", screenshot_out_file=None)
+ )
+ print(desktop.images[0].mime_type)
+finally:
+ driver.end_session(EndSessionInput(session="demo"))
+```
+
+The SDK is currently synchronous. Desktop calls return a typed `ToolResult`
+with text, images, verification/error metadata, and `structured_json` /
+`raw_json` for platform-extensible results. Session lifecycle calls return
+dedicated generated records.
-You can also use the Python API directly:
+## Binary wrapper
+
+The package also exposes the bundled executable:
```python
-from cua_driver import run_cua_driver, get_binary_path
+from cua_driver import get_binary_path, run_cua_driver
-# Run with custom args
+print(get_binary_path())
exit_code = run_cua_driver(["mcp"])
-
-# Get path to bundled binary
-binary_path = get_binary_path()
```
-## Features
-
-- **Cross-platform**: Works on macOS (universal), Linux (x86_64), and Windows (x86_64/ARM64)
-- **Zero dependencies**: Pure Python wrapper with no external dependencies
-- **Stdio passthrough**: Transparent piping for MCP protocol communication
-- **Bundled binary**: No separate installation required - the Rust binary is included in the wheel
-
-## Platform Support
+## Platform support
| Platform | Architecture | Status |
-|----------|-------------|---------|
-| macOS | Universal (ARM64 + x86_64) | ✅ Supported |
-| Linux | x86_64 | ✅ Supported |
-| Windows | x86_64 | ✅ Supported |
-| Windows | ARM64 | ✅ Supported |
+| --- | --- | --- |
+| macOS | Universal (ARM64 + x86_64) | Supported |
+| Linux | x86_64 | Supported |
+| Windows | x86_64 | Supported |
+| Windows | ARM64 | Supported |
## License
-MIT License - see [LICENSE](https://github.com/trycua/cua/blob/main/LICENSE.md)
-
-## Links
-
-- [GitHub Repository](https://github.com/trycua/cua)
-- [Documentation](https://cua.ai/docs)
-- [Issue Tracker](https://github.com/trycua/cua/issues)
+MIT License — see [LICENSE](https://github.com/trycua/cua/blob/main/LICENSE.md).
diff --git a/libs/cua-driver/python/build_wheel.py b/libs/cua-driver/python/build_wheel.py
index de342dcc4d..24cfb0e030 100644
--- a/libs/cua-driver/python/build_wheel.py
+++ b/libs/cua-driver/python/build_wheel.py
@@ -105,14 +105,14 @@ def get_release_url(version: str, platform_name: str, arch: str) -> tuple[str, l
if platform_name == "darwin":
# Universal binary tarball
filename = f"cua-driver-rs-{version}-darwin-universal-binary.tar.gz"
- binary_names = ["cua-driver"]
+ binary_names = ["cua-driver", "libcua_driver_sdk.dylib"]
elif platform_name == "linux":
filename = f"cua-driver-rs-{version}-linux-{arch}-binary.tar.gz"
- binary_names = ["cua-driver"]
+ binary_names = ["cua-driver", "libcua_driver_sdk.so"]
elif platform_name == "windows":
filename = f"cua-driver-rs-{version}-windows-{arch}-binary.zip"
# Windows includes both main executable and UIAccess worker
- binary_names = ["cua-driver.exe", "cua-driver-uia.exe"]
+ binary_names = ["cua-driver.exe", "cua-driver-uia.exe", "cua_driver_sdk.dll"]
else:
raise ValueError(f"Unknown platform: {platform_name}")
@@ -321,7 +321,11 @@ def main():
print("[OK] Cached archive checksum verified")
# Extract binaries
- extract_binaries(archive_path, binary_names, bin_dir)
+ extracted = extract_binaries(archive_path, binary_names, bin_dir)
+ native_library = next(
+ path for path in extracted if path.suffix in {".dylib", ".so", ".dll"}
+ )
+ shutil.move(native_library, script_dir / "src" / "cua_driver" / native_library.name)
else:
print("Skipping download (using existing binary)")
@@ -334,6 +338,18 @@ def main():
f"Run without --skip-download or place binary manually."
)
+ native_library_name = {
+ "darwin": "libcua_driver_sdk.dylib",
+ "linux": "libcua_driver_sdk.so",
+ "windows": "cua_driver_sdk.dll",
+ }[platform_name]
+ native_library_path = script_dir / "src" / "cua_driver" / native_library_name
+ if not native_library_path.exists():
+ raise FileNotFoundError(
+ f"UniFFI library not found at {native_library_path}. "
+ "Use a current release asset or stage a local release build."
+ )
+
print(f"\nBinary ready at: {binary_path}")
print(f"Binary size: {binary_path.stat().st_size / 1024 / 1024:.2f} MB")
diff --git a/libs/cua-driver/python/pyproject.toml b/libs/cua-driver/python/pyproject.toml
index 5186a55d51..dd9cabb33b 100644
--- a/libs/cua-driver/python/pyproject.toml
+++ b/libs/cua-driver/python/pyproject.toml
@@ -5,7 +5,7 @@ build-backend = "hatchling.build"
[project]
name = "cua-driver"
version = "0.10.0"
-description = "Python wrapper for cua-driver - cross-platform MCP server for computer-use automation"
+description = "Rust-backed Cua Driver SDK and bundled executable for client applications"
readme = "README.md"
license = { text = "MIT" }
authors = [
@@ -17,6 +17,7 @@ keywords = [
"automation",
"accessibility",
"screen-capture",
+ "sdk",
]
classifiers = [
"Development Status :: 4 - Beta",
@@ -52,6 +53,9 @@ cua-driver = "cua_driver.__main__:main"
packages = ["src/cua_driver"]
artifacts = [
"src/cua_driver/bin/*",
+ "src/cua_driver/*.dylib",
+ "src/cua_driver/*.so",
+ "src/cua_driver/*.dll",
]
pure-python = false
diff --git a/libs/cua-driver/python/src/cua_driver/__init__.py b/libs/cua-driver/python/src/cua_driver/__init__.py
index bbd7b01082..d1dcd42058 100644
--- a/libs/cua-driver/python/src/cua_driver/__init__.py
+++ b/libs/cua-driver/python/src/cua_driver/__init__.py
@@ -1,11 +1,72 @@
-"""Python wrapper for cua-driver - cross-platform MCP server.
+"""Rust-backed SDK and binary wrapper for Cua Driver client applications.
-This package provides a thin Python wrapper around the cua-driver Rust binary,
-enabling pip-installable access to the MCP server for computer-use automation.
+Agents should configure the bundled ``cua-driver mcp`` executable directly
+through their runtime's MCP client instead of importing a language MCP facade.
"""
__version__ = "0.10.0" # x-release-please-version
-from .wrapper import run_cua_driver, get_binary_path
+from ._native import CuaDriver, DriverError, ImageContent, ToolResult
+from ._native_contract import (
+ CaptureScope,
+ ClickButton,
+ ClickInput,
+ DesktopScope,
+ DragInput,
+ EndSessionInput,
+ EndSessionOutput,
+ EffectiveScope,
+ EscalateSessionInput,
+ EscalationReason,
+ GetCursorPositionInput,
+ GetDesktopStateInput,
+ GetScreenSizeInput,
+ GetSessionStateInput,
+ HotkeyInput,
+ MoveCursorInput,
+ Platform,
+ PressKeyInput,
+ ScrollBy,
+ ScrollDirection,
+ ScrollInput,
+ SessionStateOutput,
+ StartSessionInput,
+ StartSessionOutput,
+ TypeTextInput,
+)
+from .wrapper import get_binary_path, run_cua_driver
-__all__ = ["run_cua_driver", "get_binary_path", "__version__"]
+__all__ = [
+ "CaptureScope",
+ "ClickButton",
+ "ClickInput",
+ "CuaDriver",
+ "DesktopScope",
+ "DragInput",
+ "DriverError",
+ "EffectiveScope",
+ "EndSessionInput",
+ "EndSessionOutput",
+ "EscalateSessionInput",
+ "EscalationReason",
+ "GetCursorPositionInput",
+ "GetDesktopStateInput",
+ "GetScreenSizeInput",
+ "GetSessionStateInput",
+ "HotkeyInput",
+ "ImageContent",
+ "MoveCursorInput",
+ "Platform",
+ "PressKeyInput",
+ "ScrollBy",
+ "ScrollDirection",
+ "ScrollInput",
+ "SessionStateOutput",
+ "StartSessionInput",
+ "StartSessionOutput",
+ "ToolResult",
+ "TypeTextInput",
+ "__version__",
+ "get_binary_path",
+ "run_cua_driver",
+]
diff --git a/libs/cua-driver/python/src/cua_driver/_native.py b/libs/cua-driver/python/src/cua_driver/_native.py
new file mode 100644
index 0000000000..db2321487d
--- /dev/null
+++ b/libs/cua-driver/python/src/cua_driver/_native.py
@@ -0,0 +1,1807 @@
+# This file was autogenerated by some hot garbage in the `uniffi` crate.
+# Trust me, you don't want to mess with it!
+
+# Common helper code.
+#
+# Ideally this would live in a separate .py file where it can be unittested etc
+# in isolation, and perhaps even published as a re-useable package.
+#
+# However, it's important that the details of how this helper code works (e.g. the
+# way that different builtin types are passed across the FFI) exactly match what's
+# expected by the rust code on the other side of the interface. In practice right
+# now that means coming from the exact some version of `uniffi` that was used to
+# compile the rust component. The easiest way to ensure this is to bundle the Python
+# helpers directly inline like we're doing here.
+
+from __future__ import annotations
+import os
+import sys
+import ctypes
+from dataclasses import dataclass
+import enum
+import struct
+import contextlib
+import datetime
+import threading
+import itertools
+import traceback
+import typing
+import platform
+import cua_driver._native_contract
+
+
+# Used for default argument values
+_DEFAULT = object() # type: typing.Any
+
+
+class _UniffiRustBuffer(ctypes.Structure):
+ _fields_ = [
+ ("capacity", ctypes.c_uint64),
+ ("len", ctypes.c_uint64),
+ ("data", ctypes.POINTER(ctypes.c_char)),
+ ]
+
+ @staticmethod
+ def default():
+ return _UniffiRustBuffer(0, 0, None)
+
+ @staticmethod
+ def alloc(size):
+ return _uniffi_rust_call(_UniffiLib.ffi_cua_driver_sdk_rustbuffer_alloc, size)
+
+ @staticmethod
+ def reserve(rbuf, additional):
+ return _uniffi_rust_call(_UniffiLib.ffi_cua_driver_sdk_rustbuffer_reserve, rbuf, additional)
+
+ def free(self):
+ return _uniffi_rust_call(_UniffiLib.ffi_cua_driver_sdk_rustbuffer_free, self)
+
+ def __str__(self):
+ return "_UniffiRustBuffer(capacity={}, len={}, data={})".format(
+ self.capacity,
+ self.len,
+ self.data[0:self.len]
+ )
+
+ @contextlib.contextmanager
+ def alloc_with_builder(*args):
+ """Context-manger to allocate a buffer using a _UniffiRustBufferBuilder.
+
+ The allocated buffer will be automatically freed if an error occurs, ensuring that
+ we don't accidentally leak it.
+ """
+ builder = _UniffiRustBufferBuilder()
+ try:
+ yield builder
+ except:
+ builder.discard()
+ raise
+
+ @contextlib.contextmanager
+ def consume_with_stream(self):
+ """Context-manager to consume a buffer using a _UniffiRustBufferStream.
+
+ The _UniffiRustBuffer will be freed once the context-manager exits, ensuring that we don't
+ leak it even if an error occurs.
+ """
+ try:
+ s = _UniffiRustBufferStream.from_rust_buffer(self)
+ yield s
+ if s.remaining() != 0:
+ raise RuntimeError(f"junk data left in buffer at end of consume_with_stream {s.remaining()}")
+ finally:
+ self.free()
+
+ @contextlib.contextmanager
+ def read_with_stream(self):
+ """Context-manager to read a buffer using a _UniffiRustBufferStream.
+
+ This is like consume_with_stream, but doesn't free the buffer afterwards.
+ It should only be used with borrowed `_UniffiRustBuffer` data.
+ """
+ s = _UniffiRustBufferStream.from_rust_buffer(self)
+ yield s
+ if s.remaining() != 0:
+ raise RuntimeError(f"junk data left in buffer at end of read_with_stream {s.remaining()}")
+
+class _UniffiForeignBytes(ctypes.Structure):
+ _fields_ = [
+ ("len", ctypes.c_int32),
+ ("data", ctypes.POINTER(ctypes.c_char)),
+ ]
+
+ def __str__(self):
+ return "_UniffiForeignBytes(len={}, data={})".format(self.len, self.data[0:self.len])
+
+
+class _UniffiRustBufferStream:
+ """
+ Helper for structured reading of bytes from a _UniffiRustBuffer
+ """
+
+ def __init__(self, data, len):
+ self.data = data
+ self.len = len
+ self.offset = 0
+
+ @classmethod
+ def from_rust_buffer(cls, buf):
+ return cls(buf.data, buf.len)
+
+ def remaining(self):
+ return self.len - self.offset
+
+ def _unpack_from(self, size, format):
+ if self.offset + size > self.len:
+ raise InternalError("read past end of rust buffer")
+ value = struct.unpack(format, self.data[self.offset:self.offset+size])[0]
+ self.offset += size
+ return value
+
+ def read(self, size):
+ if self.offset + size > self.len:
+ raise InternalError("read past end of rust buffer")
+ data = self.data[self.offset:self.offset+size]
+ self.offset += size
+ return data
+
+ def read_i8(self):
+ return self._unpack_from(1, ">b")
+
+ def read_u8(self):
+ return self._unpack_from(1, ">B")
+
+ def read_i16(self):
+ return self._unpack_from(2, ">h")
+
+ def read_u16(self):
+ return self._unpack_from(2, ">H")
+
+ def read_i32(self):
+ return self._unpack_from(4, ">i")
+
+ def read_u32(self):
+ return self._unpack_from(4, ">I")
+
+ def read_i64(self):
+ return self._unpack_from(8, ">q")
+
+ def read_u64(self):
+ return self._unpack_from(8, ">Q")
+
+ def read_float(self):
+ v = self._unpack_from(4, ">f")
+ return v
+
+ def read_double(self):
+ return self._unpack_from(8, ">d")
+
+class _UniffiRustBufferBuilder:
+ """
+ Helper for structured writing of bytes into a _UniffiRustBuffer.
+ """
+
+ def __init__(self):
+ self.rbuf = _UniffiRustBuffer.alloc(16)
+ self.rbuf.len = 0
+
+ def finalize(self):
+ rbuf = self.rbuf
+ self.rbuf = None
+ return rbuf
+
+ def discard(self):
+ if self.rbuf is not None:
+ rbuf = self.finalize()
+ rbuf.free()
+
+ @contextlib.contextmanager
+ def _reserve(self, num_bytes):
+ if self.rbuf.len + num_bytes > self.rbuf.capacity:
+ self.rbuf = _UniffiRustBuffer.reserve(self.rbuf, num_bytes)
+ yield None
+ self.rbuf.len += num_bytes
+
+ def _pack_into(self, size, format, value):
+ with self._reserve(size):
+ # XXX TODO: I feel like I should be able to use `struct.pack_into` here but can't figure it out.
+ for i, byte in enumerate(struct.pack(format, value)):
+ self.rbuf.data[self.rbuf.len + i] = byte
+
+ def write(self, value):
+ with self._reserve(len(value)):
+ for i, byte in enumerate(value):
+ self.rbuf.data[self.rbuf.len + i] = byte
+
+ def write_i8(self, v):
+ self._pack_into(1, ">b", v)
+
+ def write_u8(self, v):
+ self._pack_into(1, ">B", v)
+
+ def write_i16(self, v):
+ self._pack_into(2, ">h", v)
+
+ def write_u16(self, v):
+ self._pack_into(2, ">H", v)
+
+ def write_i32(self, v):
+ self._pack_into(4, ">i", v)
+
+ def write_u32(self, v):
+ self._pack_into(4, ">I", v)
+
+ def write_i64(self, v):
+ self._pack_into(8, ">q", v)
+
+ def write_u64(self, v):
+ self._pack_into(8, ">Q", v)
+
+ def write_float(self, v):
+ self._pack_into(4, ">f", v)
+
+ def write_double(self, v):
+ self._pack_into(8, ">d", v)
+
+ def write_c_size_t(self, v):
+ self._pack_into(ctypes.sizeof(ctypes.c_size_t) , "@N", v)
+# A handful of classes and functions to support the generated data structures.
+# This would be a good candidate for isolating in its own ffi-support lib.
+
+class InternalError(Exception):
+ pass
+
+class _UniffiRustCallStatus(ctypes.Structure):
+ """
+ Error runtime.
+ """
+ _fields_ = [
+ ("code", ctypes.c_int8),
+ ("error_buf", _UniffiRustBuffer),
+ ]
+
+ # These match the values from the uniffi::rustcalls module
+ CALL_SUCCESS = 0
+ CALL_ERROR = 1
+ CALL_UNEXPECTED_ERROR = 2
+
+ @staticmethod
+ def default():
+ return _UniffiRustCallStatus(code=_UniffiRustCallStatus.CALL_SUCCESS, error_buf=_UniffiRustBuffer.default())
+
+ def __str__(self):
+ if self.code == _UniffiRustCallStatus.CALL_SUCCESS:
+ return "_UniffiRustCallStatus(CALL_SUCCESS)"
+ elif self.code == _UniffiRustCallStatus.CALL_ERROR:
+ return "_UniffiRustCallStatus(CALL_ERROR)"
+ elif self.code == _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR:
+ return "_UniffiRustCallStatus(CALL_UNEXPECTED_ERROR)"
+ else:
+ return "_UniffiRustCallStatus(<invalid code>)"
+
+def _uniffi_rust_call(fn, *args):
+ # Call a rust function
+ return _uniffi_rust_call_with_error(None, fn, *args)
+
+def _uniffi_rust_call_with_error(error_ffi_converter, fn, *args):
+ # Call a rust function and handle any errors
+ #
+ # This function is used for rust calls that return Result<> and therefore can set the CALL_ERROR status code.
+ # error_ffi_converter must be set to the _UniffiConverter for the error class that corresponds to the result.
+ call_status = _UniffiRustCallStatus.default()
+
+ args_with_error = args + (ctypes.byref(call_status),)
+ result = fn(*args_with_error)
+ _uniffi_check_call_status(error_ffi_converter, call_status)
+ return result
+
+def _uniffi_check_call_status(error_ffi_converter, call_status):
+ if call_status.code == _UniffiRustCallStatus.CALL_SUCCESS:
+ pass
+ elif call_status.code == _UniffiRustCallStatus.CALL_ERROR:
+ if error_ffi_converter is None:
+ call_status.error_buf.free()
+ raise InternalError("_uniffi_rust_call_with_error: CALL_ERROR, but error_ffi_converter is None")
+ else:
+ raise error_ffi_converter.lift(call_status.error_buf)
+ elif call_status.code == _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR:
+ # When the rust code sees a panic, it tries to construct a _UniffiRustBuffer
+ # with the message. But if that code panics, then it just sends back
+ # an empty buffer.
+ if call_status.error_buf.len > 0:
+ msg = _UniffiFfiConverterString.lift(call_status.error_buf)
+ else:
+ msg = "Unknown rust panic"
+ raise InternalError(msg)
+ else:
+ raise InternalError("Invalid _UniffiRustCallStatus code: {}".format(
+ call_status.code))
+
+def _uniffi_trait_interface_call(call_status, make_call, write_return_value):
+ try:
+ return write_return_value(make_call())
+ except Exception as e:
+ call_status.code = _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR
+ call_status.error_buf = _UniffiFfiConverterString.lower(repr(e))
+
+def _uniffi_trait_interface_call_with_error(call_status, make_call, write_return_value, error_type, lower_error):
+ try:
+ try:
+ return write_return_value(make_call())
+ except error_type as e:
+ call_status.code = _UniffiRustCallStatus.CALL_ERROR
+ call_status.error_buf = lower_error(e)
+ except Exception as e:
+ call_status.code = _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR
+ call_status.error_buf = _UniffiFfiConverterString.lower(repr(e))
+# Initial value and increment amount for handles.
+# These ensure that Python-generated handles always have the lowest bit set
+_UNIFFI_HANDLEMAP_INITIAL = 1
+_UNIFFI_HANDLEMAP_DELTA = 2
+
+class _UniffiHandleMap:
+ """
+ A map where inserting, getting and removing data is synchronized with a lock.
+ """
+
+ def __init__(self):
+ # type Handle = int
+ self._map = {} # type: Dict[Handle, Any]
+ self._lock = threading.Lock()
+ self._counter = _UNIFFI_HANDLEMAP_INITIAL
+
+ def insert(self, obj):
+ with self._lock:
+ return self._insert(obj)
+
+ """Low-level insert, this assumes `self._lock` is held."""
+ def _insert(self, obj):
+ handle = self._counter
+ self._counter += _UNIFFI_HANDLEMAP_DELTA
+ self._map[handle] = obj
+ return handle
+
+ def get(self, handle):
+ try:
+ with self._lock:
+ return self._map[handle]
+ except KeyError:
+ raise InternalError(f"_UniffiHandleMap.get: Invalid handle {handle}")
+
+ def clone(self, handle):
+ try:
+ with self._lock:
+ obj = self._map[handle]
+ return self._insert(obj)
+ except KeyError:
+ raise InternalError(f"_UniffiHandleMap.clone: Invalid handle {handle}")
+
+ def remove(self, handle):
+ try:
+ with self._lock:
+ return self._map.pop(handle)
+ except KeyError:
+ raise InternalError(f"_UniffiHandleMap.remove: Invalid handle: {handle}")
+
+ def __len__(self):
+ return len(self._map)
+# Types conforming to `_UniffiConverterPrimitive` pass themselves directly over the FFI.
+class _UniffiConverterPrimitive:
+ @classmethod
+ def lift(cls, value):
+ return value
+
+ @classmethod
+ def lower(cls, value):
+ return value
+
+class _UniffiConverterPrimitiveInt(_UniffiConverterPrimitive):
+ @classmethod
+ def check_lower(cls, value):
+ try:
+ value = value.__index__()
+ except Exception:
+ raise TypeError("'{}' object cannot be interpreted as an integer".format(type(value).__name__))
+ if not isinstance(value, int):
+ raise TypeError("__index__ returned non-int (type {})".format(type(value).__name__))
+ if not cls.VALUE_MIN <= value < cls.VALUE_MAX:
+ raise ValueError("{} requires {} <= value < {}".format(cls.CLASS_NAME, cls.VALUE_MIN, cls.VALUE_MAX))
+
+class _UniffiConverterPrimitiveFloat(_UniffiConverterPrimitive):
+ @classmethod
+ def check_lower(cls, value):
+ try:
+ value = value.__float__()
+ except Exception:
+ raise TypeError("must be real number, not {}".format(type(value).__name__))
+ if not isinstance(value, float):
+ raise TypeError("__float__ returned non-float (type {})".format(type(value).__name__))
+
+# Helper class for wrapper types that will always go through a _UniffiRustBuffer.
+# Classes should inherit from this and implement the `read` and `write` static methods.
+class _UniffiConverterRustBuffer:
+ @classmethod
+ def lift(cls, rbuf):
+ with rbuf.consume_with_stream() as stream:
+ return cls.read(stream)
+
+ @classmethod
+ def lower(cls, value):
+ with _UniffiRustBuffer.alloc_with_builder() as builder:
+ cls.write(value, builder)
+ return builder.finalize()
+
+# Contains loading, initialization code, and the FFI Function declarations.
+# Define some ctypes FFI types that we use in the library
+
+"""
+Function pointer for a Rust task, which a callback function that takes a opaque pointer
+"""
+_UNIFFI_RUST_TASK = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_int8)
+
+def _uniffi_future_callback_t(return_type):
+ """
+ Factory function to create callback function types for async functions
+ """
+ return ctypes.CFUNCTYPE(None, ctypes.c_uint64, return_type, _UniffiRustCallStatus)
+
+def _uniffi_load_indirect():
+ """
+ This is how we find and load the dynamic library provided by the component.
+ For now we just look it up by name.
+ """
+ if sys.platform == "darwin":
+ libname = "lib{}.dylib"
+ elif sys.platform.startswith("win"):
+ # As of python3.8, ctypes does not seem to search $PATH when loading DLLs.
+ # We could use `os.add_dll_directory` to configure the search path, but
+ # it doesn't feel right to mess with application-wide settings. Let's
+ # assume that the `.dll` is next to the `.py` file and load by full path.
+ libname = os.path.join(
+ os.path.dirname(__file__),
+ "{}.dll",
+ )
+ else:
+ # Anything else must be an ELF platform - Linux, *BSD, Solaris/illumos
+ libname = "lib{}.so"
+
+ libname = libname.format("cua_driver_sdk")
+ path = os.path.join(os.path.dirname(__file__), libname)
+ lib = ctypes.cdll.LoadLibrary(path)
+ return lib
+
+def _uniffi_check_contract_api_version(lib):
+ # Get the bindings contract version from our ComponentInterface
+ bindings_contract_version = 30
+ # Get the scaffolding contract version by calling the into the dylib
+ scaffolding_contract_version = lib.ffi_cua_driver_sdk_uniffi_contract_version()
+ if bindings_contract_version != scaffolding_contract_version:
+ raise InternalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
+
+def _uniffi_check_api_checksums(lib):
+ if lib.uniffi_cua_driver_sdk_checksum_constructor_cuadriver_connect() != 42154:
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
+ if lib.uniffi_cua_driver_sdk_checksum_method_cuadriver_call_tool() != 31445:
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
+ if lib.uniffi_cua_driver_sdk_checksum_method_cuadriver_click() != 34118:
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
+ if lib.uniffi_cua_driver_sdk_checksum_method_cuadriver_drag() != 35252:
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
+ if lib.uniffi_cua_driver_sdk_checksum_method_cuadriver_end_session() != 33990:
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
+ if lib.uniffi_cua_driver_sdk_checksum_method_cuadriver_escalate_session() != 37358:
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
+ if lib.uniffi_cua_driver_sdk_checksum_method_cuadriver_get_cursor_position() != 54043:
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
+ if lib.uniffi_cua_driver_sdk_checksum_method_cuadriver_get_desktop_state() != 32992:
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
+ if lib.uniffi_cua_driver_sdk_checksum_method_cuadriver_get_screen_size() != 15250:
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
+ if lib.uniffi_cua_driver_sdk_checksum_method_cuadriver_get_session_state() != 51055:
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
+ if lib.uniffi_cua_driver_sdk_checksum_method_cuadriver_hotkey() != 3135:
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
+ if lib.uniffi_cua_driver_sdk_checksum_method_cuadriver_is_available() != 42961:
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
+ if lib.uniffi_cua_driver_sdk_checksum_method_cuadriver_list_tools_json() != 43987:
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
+ if lib.uniffi_cua_driver_sdk_checksum_method_cuadriver_move_cursor() != 11209:
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
+ if lib.uniffi_cua_driver_sdk_checksum_method_cuadriver_press_key() != 17425:
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
+ if lib.uniffi_cua_driver_sdk_checksum_method_cuadriver_scroll() != 21614:
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
+ if lib.uniffi_cua_driver_sdk_checksum_method_cuadriver_socket_path() != 24461:
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
+ if lib.uniffi_cua_driver_sdk_checksum_method_cuadriver_start_session() != 53509:
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
+ if lib.uniffi_cua_driver_sdk_checksum_method_cuadriver_type_text() != 19673:
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
+
+# A ctypes library to expose the extern-C FFI definitions.
+# This is an implementation detail which will be called internally by the public API.
+
+_UniffiLib = _uniffi_load_indirect()
+_UniffiLib.ffi_cua_driver_sdk_rustbuffer_alloc.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_sdk_rustbuffer_alloc.restype = _UniffiRustBuffer
+_UniffiLib.ffi_cua_driver_sdk_rustbuffer_from_bytes.argtypes = (
+ _UniffiForeignBytes,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_sdk_rustbuffer_from_bytes.restype = _UniffiRustBuffer
+_UniffiLib.ffi_cua_driver_sdk_rustbuffer_free.argtypes = (
+ _UniffiRustBuffer,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_sdk_rustbuffer_free.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rustbuffer_reserve.argtypes = (
+ _UniffiRustBuffer,
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_sdk_rustbuffer_reserve.restype = _UniffiRustBuffer
+_UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK = ctypes.CFUNCTYPE(None,ctypes.c_uint64,ctypes.c_int8,
+)
+_UNIFFI_FOREIGN_FUTURE_DROPPED_CALLBACK = ctypes.CFUNCTYPE(None,ctypes.c_uint64,
+)
+class _UniffiForeignFutureDroppedCallbackStruct(ctypes.Structure):
+ _fields_ = [
+ ("handle", ctypes.c_uint64),
+ ("free", _UNIFFI_FOREIGN_FUTURE_DROPPED_CALLBACK),
+ ]
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_u8.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_u8.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_u8.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_u8.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_u8.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_u8.restype = ctypes.c_uint8
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_u8.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_u8.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_i8.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_i8.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_i8.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_i8.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_i8.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_i8.restype = ctypes.c_int8
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_i8.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_i8.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_u16.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_u16.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_u16.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_u16.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_u16.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_u16.restype = ctypes.c_uint16
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_u16.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_u16.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_i16.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_i16.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_i16.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_i16.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_i16.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_i16.restype = ctypes.c_int16
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_i16.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_i16.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_u32.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_u32.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_u32.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_u32.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_u32.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_u32.restype = ctypes.c_uint32
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_u32.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_u32.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_i32.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_i32.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_i32.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_i32.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_i32.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_i32.restype = ctypes.c_int32
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_i32.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_i32.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_u64.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_u64.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_u64.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_u64.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_u64.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_u64.restype = ctypes.c_uint64
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_u64.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_u64.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_i64.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_i64.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_i64.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_i64.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_i64.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_i64.restype = ctypes.c_int64
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_i64.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_i64.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_f32.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_f32.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_f32.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_f32.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_f32.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_f32.restype = ctypes.c_float
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_f32.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_f32.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_f64.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_f64.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_f64.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_f64.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_f64.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_f64.restype = ctypes.c_double
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_f64.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_f64.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_rust_buffer.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_rust_buffer.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_rust_buffer.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_rust_buffer.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_rust_buffer.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_rust_buffer.restype = _UniffiRustBuffer
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_rust_buffer.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_rust_buffer.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_void.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_poll_void.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_void.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_cancel_void.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_void.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_complete_void.restype = None
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_void.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_sdk_rust_future_free_void.restype = None
+_UniffiLib.uniffi_cua_driver_sdk_fn_clone_cuadriver.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_clone_cuadriver.restype = ctypes.c_uint64
+_UniffiLib.uniffi_cua_driver_sdk_fn_free_cuadriver.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_free_cuadriver.restype = None
+_UniffiLib.uniffi_cua_driver_sdk_fn_constructor_cuadriver_connect.argtypes = (
+ _UniffiRustBuffer,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_constructor_cuadriver_connect.restype = ctypes.c_uint64
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_call_tool.argtypes = (
+ ctypes.c_uint64,
+ _UniffiRustBuffer,
+ _UniffiRustBuffer,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_call_tool.restype = _UniffiRustBuffer
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_click.argtypes = (
+ ctypes.c_uint64,
+ cua_driver._native_contract._UniffiRustBuffer,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_click.restype = _UniffiRustBuffer
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_drag.argtypes = (
+ ctypes.c_uint64,
+ cua_driver._native_contract._UniffiRustBuffer,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_drag.restype = _UniffiRustBuffer
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_end_session.argtypes = (
+ ctypes.c_uint64,
+ cua_driver._native_contract._UniffiRustBuffer,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_end_session.restype = cua_driver._native_contract._UniffiRustBuffer
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_escalate_session.argtypes = (
+ ctypes.c_uint64,
+ cua_driver._native_contract._UniffiRustBuffer,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_escalate_session.restype = cua_driver._native_contract._UniffiRustBuffer
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_get_cursor_position.argtypes = (
+ ctypes.c_uint64,
+ cua_driver._native_contract._UniffiRustBuffer,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_get_cursor_position.restype = _UniffiRustBuffer
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_get_desktop_state.argtypes = (
+ ctypes.c_uint64,
+ cua_driver._native_contract._UniffiRustBuffer,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_get_desktop_state.restype = _UniffiRustBuffer
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_get_screen_size.argtypes = (
+ ctypes.c_uint64,
+ cua_driver._native_contract._UniffiRustBuffer,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_get_screen_size.restype = _UniffiRustBuffer
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_get_session_state.argtypes = (
+ ctypes.c_uint64,
+ cua_driver._native_contract._UniffiRustBuffer,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_get_session_state.restype = cua_driver._native_contract._UniffiRustBuffer
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_hotkey.argtypes = (
+ ctypes.c_uint64,
+ cua_driver._native_contract._UniffiRustBuffer,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_hotkey.restype = _UniffiRustBuffer
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_is_available.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_is_available.restype = ctypes.c_int8
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_list_tools_json.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_list_tools_json.restype = _UniffiRustBuffer
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_move_cursor.argtypes = (
+ ctypes.c_uint64,
+ cua_driver._native_contract._UniffiRustBuffer,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_move_cursor.restype = _UniffiRustBuffer
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_press_key.argtypes = (
+ ctypes.c_uint64,
+ cua_driver._native_contract._UniffiRustBuffer,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_press_key.restype = _UniffiRustBuffer
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_scroll.argtypes = (
+ ctypes.c_uint64,
+ cua_driver._native_contract._UniffiRustBuffer,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_scroll.restype = _UniffiRustBuffer
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_socket_path.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_socket_path.restype = _UniffiRustBuffer
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_start_session.argtypes = (
+ ctypes.c_uint64,
+ cua_driver._native_contract._UniffiRustBuffer,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_start_session.restype = cua_driver._native_contract._UniffiRustBuffer
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_type_text.argtypes = (
+ ctypes.c_uint64,
+ cua_driver._native_contract._UniffiRustBuffer,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_type_text.restype = _UniffiRustBuffer
+_UniffiLib.ffi_cua_driver_sdk_uniffi_contract_version.argtypes = (
+)
+_UniffiLib.ffi_cua_driver_sdk_uniffi_contract_version.restype = ctypes.c_uint32
+_UniffiLib.uniffi_cua_driver_sdk_checksum_constructor_cuadriver_connect.argtypes = (
+)
+_UniffiLib.uniffi_cua_driver_sdk_checksum_constructor_cuadriver_connect.restype = ctypes.c_uint16
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_call_tool.argtypes = (
+)
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_call_tool.restype = ctypes.c_uint16
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_click.argtypes = (
+)
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_click.restype = ctypes.c_uint16
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_drag.argtypes = (
+)
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_drag.restype = ctypes.c_uint16
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_end_session.argtypes = (
+)
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_end_session.restype = ctypes.c_uint16
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_escalate_session.argtypes = (
+)
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_escalate_session.restype = ctypes.c_uint16
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_get_cursor_position.argtypes = (
+)
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_get_cursor_position.restype = ctypes.c_uint16
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_get_desktop_state.argtypes = (
+)
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_get_desktop_state.restype = ctypes.c_uint16
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_get_screen_size.argtypes = (
+)
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_get_screen_size.restype = ctypes.c_uint16
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_get_session_state.argtypes = (
+)
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_get_session_state.restype = ctypes.c_uint16
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_hotkey.argtypes = (
+)
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_hotkey.restype = ctypes.c_uint16
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_is_available.argtypes = (
+)
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_is_available.restype = ctypes.c_uint16
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_list_tools_json.argtypes = (
+)
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_list_tools_json.restype = ctypes.c_uint16
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_move_cursor.argtypes = (
+)
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_move_cursor.restype = ctypes.c_uint16
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_press_key.argtypes = (
+)
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_press_key.restype = ctypes.c_uint16
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_scroll.argtypes = (
+)
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_scroll.restype = ctypes.c_uint16
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_socket_path.argtypes = (
+)
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_socket_path.restype = ctypes.c_uint16
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_start_session.argtypes = (
+)
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_start_session.restype = ctypes.c_uint16
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_type_text.argtypes = (
+)
+_UniffiLib.uniffi_cua_driver_sdk_checksum_method_cuadriver_type_text.restype = ctypes.c_uint16
+
+_uniffi_check_contract_api_version(_UniffiLib)
+# _uniffi_check_api_checksums(_UniffiLib)
+
+
+
+# Public interface members begin here.
+
+
+class _UniffiFfiConverterString:
+ @staticmethod
+ def check_lower(value):
+ if not isinstance(value, str):
+ raise TypeError("argument must be str, not {}".format(type(value).__name__))
+ return value
+
+ @staticmethod
+ def read(buf):
+ size = buf.read_i32()
+ if size < 0:
+ raise InternalError("Unexpected negative string length")
+ utf8_bytes = buf.read(size)
+ return utf8_bytes.decode("utf-8")
+
+ @staticmethod
+ def write(value, buf):
+ utf8_bytes = value.encode("utf-8")
+ buf.write_i32(len(utf8_bytes))
+ buf.write(utf8_bytes)
+
+ @staticmethod
+ def lift(buf):
+ with buf.consume_with_stream() as stream:
+ return stream.read(stream.remaining()).decode("utf-8")
+
+ @staticmethod
+ def lower(value):
+ with _UniffiRustBuffer.alloc_with_builder() as builder:
+ builder.write(value.encode("utf-8"))
+ return builder.finalize()
+
+@dataclass
+class ImageContent:
+ def __init__(self, *, mime_type:str, data_base64:str):
+ self.mime_type = mime_type
+ self.data_base64 = data_base64
+
+
+
+
+ def __str__(self):
+ return "ImageContent(mime_type={}, data_base64={})".format(self.mime_type, self.data_base64)
+ def __eq__(self, other):
+ if self.mime_type != other.mime_type:
+ return False
+ if self.data_base64 != other.data_base64:
+ return False
+ return True
+
+class _UniffiFfiConverterTypeImageContent(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ return ImageContent(
+ mime_type=_UniffiFfiConverterString.read(buf),
+ data_base64=_UniffiFfiConverterString.read(buf),
+ )
+
+ @staticmethod
+ def check_lower(value):
+ _UniffiFfiConverterString.check_lower(value.mime_type)
+ _UniffiFfiConverterString.check_lower(value.data_base64)
+
+ @staticmethod
+ def write(value, buf):
+ _UniffiFfiConverterString.write(value.mime_type, buf)
+ _UniffiFfiConverterString.write(value.data_base64, buf)
+
+class _UniffiFfiConverterSequenceTypeImageContent(_UniffiConverterRustBuffer):
+ @classmethod
+ def check_lower(cls, value):
+ for item in value:
+ _UniffiFfiConverterTypeImageContent.check_lower(item)
+
+ @classmethod
+ def write(cls, value, buf):
+ items = len(value)
+ buf.write_i32(items)
+ for item in value:
+ _UniffiFfiConverterTypeImageContent.write(item, buf)
+
+ @classmethod
+ def read(cls, buf):
+ count = buf.read_i32()
+ if count < 0:
+ raise InternalError("Unexpected negative sequence length")
+
+ return [
+ _UniffiFfiConverterTypeImageContent.read(buf) for i in range(count)
+ ]
+
+class _UniffiFfiConverterOptionalString(_UniffiConverterRustBuffer):
+ @classmethod
+ def check_lower(cls, value):
+ if value is not None:
+ _UniffiFfiConverterString.check_lower(value)
+
+ @classmethod
+ def write(cls, value, buf):
+ if value is None:
+ buf.write_u8(0)
+ return
+
+ buf.write_u8(1)
+ _UniffiFfiConverterString.write(value, buf)
+
+ @classmethod
+ def read(cls, buf):
+ flag = buf.read_u8()
+ if flag == 0:
+ return None
+ elif flag == 1:
+ return _UniffiFfiConverterString.read(buf)
+ else:
+ raise InternalError("Unexpected flag byte for optional type")
+
+class _UniffiFfiConverterBoolean:
+ @classmethod
+ def check_lower(cls, value):
+ return not not value
+
+ @classmethod
+ def lower(cls, value):
+ return 1 if value else 0
+
+ @staticmethod
+ def lift(value):
+ return value != 0
+
+ @classmethod
+ def read(cls, buf):
+ return cls.lift(buf.read_u8())
+
+ @classmethod
+ def write(cls, value, buf):
+ buf.write_u8(value)
+
+class _UniffiFfiConverterOptionalBoolean(_UniffiConverterRustBuffer):
+ @classmethod
+ def check_lower(cls, value):
+ if value is not None:
+ _UniffiFfiConverterBoolean.check_lower(value)
+
+ @classmethod
+ def write(cls, value, buf):
+ if value is None:
+ buf.write_u8(0)
+ return
+
+ buf.write_u8(1)
+ _UniffiFfiConverterBoolean.write(value, buf)
+
+ @classmethod
+ def read(cls, buf):
+ flag = buf.read_u8()
+ if flag == 0:
+ return None
+ elif flag == 1:
+ return _UniffiFfiConverterBoolean.read(buf)
+ else:
+ raise InternalError("Unexpected flag byte for optional type")
+
+@dataclass
+class ToolResult:
+ """
+ Transport-neutral result envelope used for open-ended tool calls and
+ desktop tools whose platform extensions are intentionally preserved as JSON.
+"""
+ def __init__(self, *, text:str, images:typing.List[ImageContent], structured_json:typing.Optional[str], is_error:bool, error_code:typing.Optional[str], verified:typing.Optional[bool], degraded:bool, raw_json:str):
+ self.text = text
+ self.images = images
+ self.structured_json = structured_json
+ self.is_error = is_error
+ self.error_code = error_code
+ self.verified = verified
+ self.degraded = degraded
+ self.raw_json = raw_json
+
+
+
+
+ def __str__(self):
+ return "ToolResult(text={}, images={}, structured_json={}, is_error={}, error_code={}, verified={}, degraded={}, raw_json={})".format(self.text, self.images, self.structured_json, self.is_error, self.error_code, self.verified, self.degraded, self.raw_json)
+ def __eq__(self, other):
+ if self.text != other.text:
+ return False
+ if self.images != other.images:
+ return False
+ if self.structured_json != other.structured_json:
+ return False
+ if self.is_error != other.is_error:
+ return False
+ if self.error_code != other.error_code:
+ return False
+ if self.verified != other.verified:
+ return False
+ if self.degraded != other.degraded:
+ return False
+ if self.raw_json != other.raw_json:
+ return False
+ return True
+
+class _UniffiFfiConverterTypeToolResult(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ return ToolResult(
+ text=_UniffiFfiConverterString.read(buf),
+ images=_UniffiFfiConverterSequenceTypeImageContent.read(buf),
+ structured_json=_UniffiFfiConverterOptionalString.read(buf),
+ is_error=_UniffiFfiConverterBoolean.read(buf),
+ error_code=_UniffiFfiConverterOptionalString.read(buf),
+ verified=_UniffiFfiConverterOptionalBoolean.read(buf),
+ degraded=_UniffiFfiConverterBoolean.read(buf),
+ raw_json=_UniffiFfiConverterString.read(buf),
+ )
+
+ @staticmethod
+ def check_lower(value):
+ _UniffiFfiConverterString.check_lower(value.text)
+ _UniffiFfiConverterSequenceTypeImageContent.check_lower(value.images)
+ _UniffiFfiConverterOptionalString.check_lower(value.structured_json)
+ _UniffiFfiConverterBoolean.check_lower(value.is_error)
+ _UniffiFfiConverterOptionalString.check_lower(value.error_code)
+ _UniffiFfiConverterOptionalBoolean.check_lower(value.verified)
+ _UniffiFfiConverterBoolean.check_lower(value.degraded)
+ _UniffiFfiConverterString.check_lower(value.raw_json)
+
+ @staticmethod
+ def write(value, buf):
+ _UniffiFfiConverterString.write(value.text, buf)
+ _UniffiFfiConverterSequenceTypeImageContent.write(value.images, buf)
+ _UniffiFfiConverterOptionalString.write(value.structured_json, buf)
+ _UniffiFfiConverterBoolean.write(value.is_error, buf)
+ _UniffiFfiConverterOptionalString.write(value.error_code, buf)
+ _UniffiFfiConverterOptionalBoolean.write(value.verified, buf)
+ _UniffiFfiConverterBoolean.write(value.degraded, buf)
+ _UniffiFfiConverterString.write(value.raw_json, buf)
+
+
+
+# DriverError
+# We want to define each variant as a nested class that's also a subclass,
+# which is tricky in Python. To accomplish this we're going to create each
+# class separately, then manually add the child classes to the base class's
+# __dict__. All of this happens in dummy class to avoid polluting the module
+# namespace.
+class DriverError(Exception):
+ pass
+
+_UniffiTempDriverError = DriverError
+
+class DriverError: # type: ignore
+
+ class Configuration(_UniffiTempDriverError):
+
+ def __init__(self, reason):
+ super().__init__(", ".join([
+ "reason={!r}".format(reason),
+ ]))
+ self.reason = reason
+
+ def __repr__(self):
+ return "DriverError.Configuration({})".format(str(self))
+ _UniffiTempDriverError.Configuration = Configuration # type: ignore
+ class InvalidArguments(_UniffiTempDriverError):
+
+ def __init__(self, tool, reason):
+ super().__init__(", ".join([
+ "tool={!r}".format(tool),
+ "reason={!r}".format(reason),
+ ]))
+ self.tool = tool
+ self.reason = reason
+
+ def __repr__(self):
+ return "DriverError.InvalidArguments({})".format(str(self))
+ _UniffiTempDriverError.InvalidArguments = InvalidArguments # type: ignore
+ class Transport(_UniffiTempDriverError):
+
+ def __init__(self, socket_path, reason):
+ super().__init__(", ".join([
+ "socket_path={!r}".format(socket_path),
+ "reason={!r}".format(reason),
+ ]))
+ self.socket_path = socket_path
+ self.reason = reason
+
+ def __repr__(self):
+ return "DriverError.Transport({})".format(str(self))
+ _UniffiTempDriverError.Transport = Transport # type: ignore
+ class Protocol(_UniffiTempDriverError):
+
+ def __init__(self, reason):
+ super().__init__(", ".join([
+ "reason={!r}".format(reason),
+ ]))
+ self.reason = reason
+
+ def __repr__(self):
+ return "DriverError.Protocol({})".format(str(self))
+ _UniffiTempDriverError.Protocol = Protocol # type: ignore
+ class Tool(_UniffiTempDriverError):
+
+ def __init__(self, tool, message, error_code):
+ super().__init__(", ".join([
+ "tool={!r}".format(tool),
+ "message={!r}".format(message),
+ "error_code={!r}".format(error_code),
+ ]))
+ self.tool = tool
+ self.message = message
+ self.error_code = error_code
+
+ def __repr__(self):
+ return "DriverError.Tool({})".format(str(self))
+ _UniffiTempDriverError.Tool = Tool # type: ignore
+
+DriverError = _UniffiTempDriverError # type: ignore
+del _UniffiTempDriverError
+
+
+class _UniffiFfiConverterTypeDriverError(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ variant = buf.read_i32()
+ if variant == 1:
+ return DriverError.Configuration(
+ _UniffiFfiConverterString.read(buf),
+ )
+ if variant == 2:
+ return DriverError.InvalidArguments(
+ _UniffiFfiConverterString.read(buf),
+ _UniffiFfiConverterString.read(buf),
+ )
+ if variant == 3:
+ return DriverError.Transport(
+ _UniffiFfiConverterString.read(buf),
+ _UniffiFfiConverterString.read(buf),
+ )
+ if variant == 4:
+ return DriverError.Protocol(
+ _UniffiFfiConverterString.read(buf),
+ )
+ if variant == 5:
+ return DriverError.Tool(
+ _UniffiFfiConverterString.read(buf),
+ _UniffiFfiConverterString.read(buf),
+ _UniffiFfiConverterString.read(buf),
+ )
+ raise InternalError("Raw enum value doesn't match any cases")
+
+ @staticmethod
+ def check_lower(value):
+ if isinstance(value, DriverError.Configuration):
+ _UniffiFfiConverterString.check_lower(value.reason)
+ return
+ if isinstance(value, DriverError.InvalidArguments):
+ _UniffiFfiConverterString.check_lower(value.tool)
+ _UniffiFfiConverterString.check_lower(value.reason)
+ return
+ if isinstance(value, DriverError.Transport):
+ _UniffiFfiConverterString.check_lower(value.socket_path)
+ _UniffiFfiConverterString.check_lower(value.reason)
+ return
+ if isinstance(value, DriverError.Protocol):
+ _UniffiFfiConverterString.check_lower(value.reason)
+ return
+ if isinstance(value, DriverError.Tool):
+ _UniffiFfiConverterString.check_lower(value.tool)
+ _UniffiFfiConverterString.check_lower(value.message)
+ _UniffiFfiConverterString.check_lower(value.error_code)
+ return
+
+ @staticmethod
+ def write(value, buf):
+ if isinstance(value, DriverError.Configuration):
+ buf.write_i32(1)
+ _UniffiFfiConverterString.write(value.reason, buf)
+ if isinstance(value, DriverError.InvalidArguments):
+ buf.write_i32(2)
+ _UniffiFfiConverterString.write(value.tool, buf)
+ _UniffiFfiConverterString.write(value.reason, buf)
+ if isinstance(value, DriverError.Transport):
+ buf.write_i32(3)
+ _UniffiFfiConverterString.write(value.socket_path, buf)
+ _UniffiFfiConverterString.write(value.reason, buf)
+ if isinstance(value, DriverError.Protocol):
+ buf.write_i32(4)
+ _UniffiFfiConverterString.write(value.reason, buf)
+ if isinstance(value, DriverError.Tool):
+ buf.write_i32(5)
+ _UniffiFfiConverterString.write(value.tool, buf)
+ _UniffiFfiConverterString.write(value.message, buf)
+ _UniffiFfiConverterString.write(value.error_code, buf)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+class CuaDriverProtocol(typing.Protocol):
+
+ def call_tool(self, name: str,arguments_json: str) -> ToolResult:
+ """
+ Escape hatch for forward-compatible tools and application-owned server
+ adapters. Typed methods below serialize the same canonical Rust inputs.
+"""
+ raise NotImplementedError
+ def click(self, input: cua_driver._native_contract.ClickInput) -> ToolResult:
+ raise NotImplementedError
+ def drag(self, input: cua_driver._native_contract.DragInput) -> ToolResult:
+ raise NotImplementedError
+ def end_session(self, input: cua_driver._native_contract.EndSessionInput) -> cua_driver._native_contract.EndSessionOutput:
+ raise NotImplementedError
+ def escalate_session(self, input: cua_driver._native_contract.EscalateSessionInput) -> cua_driver._native_contract.SessionStateOutput:
+ raise NotImplementedError
+ def get_cursor_position(self, input: cua_driver._native_contract.GetCursorPositionInput) -> ToolResult:
+ raise NotImplementedError
+ def get_desktop_state(self, input: cua_driver._native_contract.GetDesktopStateInput) -> ToolResult:
+ raise NotImplementedError
+ def get_screen_size(self, input: cua_driver._native_contract.GetScreenSizeInput) -> ToolResult:
+ raise NotImplementedError
+ def get_session_state(self, input: cua_driver._native_contract.GetSessionStateInput) -> cua_driver._native_contract.SessionStateOutput:
+ raise NotImplementedError
+ def hotkey(self, input: cua_driver._native_contract.HotkeyInput) -> ToolResult:
+ raise NotImplementedError
+ def is_available(self, ) -> bool:
+ raise NotImplementedError
+ def list_tools_json(self, ) -> str:
+ raise NotImplementedError
+ def move_cursor(self, input: cua_driver._native_contract.MoveCursorInput) -> ToolResult:
+ raise NotImplementedError
+ def press_key(self, input: cua_driver._native_contract.PressKeyInput) -> ToolResult:
+ raise NotImplementedError
+ def scroll(self, input: cua_driver._native_contract.ScrollInput) -> ToolResult:
+ raise NotImplementedError
+ def socket_path(self, ) -> str:
+ raise NotImplementedError
+ def start_session(self, input: cua_driver._native_contract.StartSessionInput) -> cua_driver._native_contract.StartSessionOutput:
+ raise NotImplementedError
+ def type_text(self, input: cua_driver._native_contract.TypeTextInput) -> ToolResult:
+ raise NotImplementedError
+
+class CuaDriver(CuaDriverProtocol):
+
+ _handle: ctypes.c_uint64
+ @classmethod
+ def connect(cls, socket_path: typing.Optional[str]) -> CuaDriver:
+ """
+ Connect to the default installed daemon or an explicitly selected socket.
+ Construction does not launch a process or perform I/O.
+"""
+
+ _UniffiFfiConverterOptionalString.check_lower(socket_path)
+ _uniffi_lowered_args = (
+ _UniffiFfiConverterOptionalString.lower(socket_path),
+ )
+ _uniffi_lift_return = _UniffiFfiConverterTypeCuaDriver.lift
+ _uniffi_error_converter = _UniffiFfiConverterTypeDriverError
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
+ _uniffi_error_converter,
+ _UniffiLib.uniffi_cua_driver_sdk_fn_constructor_cuadriver_connect,
+ *_uniffi_lowered_args,
+ )
+ return cls._uniffi_make_instance(_uniffi_ffi_result)
+
+ def __init__(self, *args, **kwargs):
+ raise ValueError("This class has no default constructor")
+
+ def __del__(self):
+ # In case of partial initialization of instances.
+ handle = getattr(self, "_handle", None)
+ if handle is not None:
+ _uniffi_rust_call(_UniffiLib.uniffi_cua_driver_sdk_fn_free_cuadriver, handle)
+
+ def _uniffi_clone_handle(self):
+ return _uniffi_rust_call(_UniffiLib.uniffi_cua_driver_sdk_fn_clone_cuadriver, self._handle)
+
+ # Used by alternative constructors or any methods which return this type.
+ @classmethod
+ def _uniffi_make_instance(cls, handle):
+ # Lightly yucky way to bypass the usual __init__ logic
+ # and just create a new instance with the required handle.
+ inst = cls.__new__(cls)
+ inst._handle = handle
+ return inst
+ def call_tool(self, name: str,arguments_json: str) -> ToolResult:
+ """
+ Escape hatch for forward-compatible tools and application-owned server
+ adapters. Typed methods below serialize the same canonical Rust inputs.
+"""
+
+ _UniffiFfiConverterString.check_lower(name)
+
+ _UniffiFfiConverterString.check_lower(arguments_json)
+ _uniffi_lowered_args = (
+ self._uniffi_clone_handle(),
+ _UniffiFfiConverterString.lower(name),
+ _UniffiFfiConverterString.lower(arguments_json),
+ )
+ _uniffi_lift_return = _UniffiFfiConverterTypeToolResult.lift
+ _uniffi_error_converter = _UniffiFfiConverterTypeDriverError
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
+ _uniffi_error_converter,
+ _UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_call_tool,
+ *_uniffi_lowered_args,
+ )
+ return _uniffi_lift_return(_uniffi_ffi_result)
+ def click(self, input: cua_driver._native_contract.ClickInput) -> ToolResult:
+
+ cua_driver._native_contract._UniffiFfiConverterTypeClickInput.check_lower(input)
+ _uniffi_lowered_args = (
+ self._uniffi_clone_handle(),
+ cua_driver._native_contract._UniffiFfiConverterTypeClickInput.lower(input),
+ )
+ _uniffi_lift_return = _UniffiFfiConverterTypeToolResult.lift
+ _uniffi_error_converter = _UniffiFfiConverterTypeDriverError
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
+ _uniffi_error_converter,
+ _UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_click,
+ *_uniffi_lowered_args,
+ )
+ return _uniffi_lift_return(_uniffi_ffi_result)
+ def drag(self, input: cua_driver._native_contract.DragInput) -> ToolResult:
+
+ cua_driver._native_contract._UniffiFfiConverterTypeDragInput.check_lower(input)
+ _uniffi_lowered_args = (
+ self._uniffi_clone_handle(),
+ cua_driver._native_contract._UniffiFfiConverterTypeDragInput.lower(input),
+ )
+ _uniffi_lift_return = _UniffiFfiConverterTypeToolResult.lift
+ _uniffi_error_converter = _UniffiFfiConverterTypeDriverError
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
+ _uniffi_error_converter,
+ _UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_drag,
+ *_uniffi_lowered_args,
+ )
+ return _uniffi_lift_return(_uniffi_ffi_result)
+ def end_session(self, input: cua_driver._native_contract.EndSessionInput) -> cua_driver._native_contract.EndSessionOutput:
+
+ cua_driver._native_contract._UniffiFfiConverterTypeEndSessionInput.check_lower(input)
+ _uniffi_lowered_args = (
+ self._uniffi_clone_handle(),
+ cua_driver._native_contract._UniffiFfiConverterTypeEndSessionInput.lower(input),
+ )
+ _uniffi_lift_return = cua_driver._native_contract._UniffiFfiConverterTypeEndSessionOutput.lift
+ _uniffi_error_converter = _UniffiFfiConverterTypeDriverError
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
+ _uniffi_error_converter,
+ _UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_end_session,
+ *_uniffi_lowered_args,
+ )
+ return _uniffi_lift_return(_uniffi_ffi_result)
+ def escalate_session(self, input: cua_driver._native_contract.EscalateSessionInput) -> cua_driver._native_contract.SessionStateOutput:
+
+ cua_driver._native_contract._UniffiFfiConverterTypeEscalateSessionInput.check_lower(input)
+ _uniffi_lowered_args = (
+ self._uniffi_clone_handle(),
+ cua_driver._native_contract._UniffiFfiConverterTypeEscalateSessionInput.lower(input),
+ )
+ _uniffi_lift_return = cua_driver._native_contract._UniffiFfiConverterTypeSessionStateOutput.lift
+ _uniffi_error_converter = _UniffiFfiConverterTypeDriverError
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
+ _uniffi_error_converter,
+ _UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_escalate_session,
+ *_uniffi_lowered_args,
+ )
+ return _uniffi_lift_return(_uniffi_ffi_result)
+ def get_cursor_position(self, input: cua_driver._native_contract.GetCursorPositionInput) -> ToolResult:
+
+ cua_driver._native_contract._UniffiFfiConverterTypeGetCursorPositionInput.check_lower(input)
+ _uniffi_lowered_args = (
+ self._uniffi_clone_handle(),
+ cua_driver._native_contract._UniffiFfiConverterTypeGetCursorPositionInput.lower(input),
+ )
+ _uniffi_lift_return = _UniffiFfiConverterTypeToolResult.lift
+ _uniffi_error_converter = _UniffiFfiConverterTypeDriverError
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
+ _uniffi_error_converter,
+ _UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_get_cursor_position,
+ *_uniffi_lowered_args,
+ )
+ return _uniffi_lift_return(_uniffi_ffi_result)
+ def get_desktop_state(self, input: cua_driver._native_contract.GetDesktopStateInput) -> ToolResult:
+
+ cua_driver._native_contract._UniffiFfiConverterTypeGetDesktopStateInput.check_lower(input)
+ _uniffi_lowered_args = (
+ self._uniffi_clone_handle(),
+ cua_driver._native_contract._UniffiFfiConverterTypeGetDesktopStateInput.lower(input),
+ )
+ _uniffi_lift_return = _UniffiFfiConverterTypeToolResult.lift
+ _uniffi_error_converter = _UniffiFfiConverterTypeDriverError
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
+ _uniffi_error_converter,
+ _UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_get_desktop_state,
+ *_uniffi_lowered_args,
+ )
+ return _uniffi_lift_return(_uniffi_ffi_result)
+ def get_screen_size(self, input: cua_driver._native_contract.GetScreenSizeInput) -> ToolResult:
+
+ cua_driver._native_contract._UniffiFfiConverterTypeGetScreenSizeInput.check_lower(input)
+ _uniffi_lowered_args = (
+ self._uniffi_clone_handle(),
+ cua_driver._native_contract._UniffiFfiConverterTypeGetScreenSizeInput.lower(input),
+ )
+ _uniffi_lift_return = _UniffiFfiConverterTypeToolResult.lift
+ _uniffi_error_converter = _UniffiFfiConverterTypeDriverError
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
+ _uniffi_error_converter,
+ _UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_get_screen_size,
+ *_uniffi_lowered_args,
+ )
+ return _uniffi_lift_return(_uniffi_ffi_result)
+ def get_session_state(self, input: cua_driver._native_contract.GetSessionStateInput) -> cua_driver._native_contract.SessionStateOutput:
+
+ cua_driver._native_contract._UniffiFfiConverterTypeGetSessionStateInput.check_lower(input)
+ _uniffi_lowered_args = (
+ self._uniffi_clone_handle(),
+ cua_driver._native_contract._UniffiFfiConverterTypeGetSessionStateInput.lower(input),
+ )
+ _uniffi_lift_return = cua_driver._native_contract._UniffiFfiConverterTypeSessionStateOutput.lift
+ _uniffi_error_converter = _UniffiFfiConverterTypeDriverError
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
+ _uniffi_error_converter,
+ _UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_get_session_state,
+ *_uniffi_lowered_args,
+ )
+ return _uniffi_lift_return(_uniffi_ffi_result)
+ def hotkey(self, input: cua_driver._native_contract.HotkeyInput) -> ToolResult:
+
+ cua_driver._native_contract._UniffiFfiConverterTypeHotkeyInput.check_lower(input)
+ _uniffi_lowered_args = (
+ self._uniffi_clone_handle(),
+ cua_driver._native_contract._UniffiFfiConverterTypeHotkeyInput.lower(input),
+ )
+ _uniffi_lift_return = _UniffiFfiConverterTypeToolResult.lift
+ _uniffi_error_converter = _UniffiFfiConverterTypeDriverError
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
+ _uniffi_error_converter,
+ _UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_hotkey,
+ *_uniffi_lowered_args,
+ )
+ return _uniffi_lift_return(_uniffi_ffi_result)
+ def is_available(self, ) -> bool:
+ _uniffi_lowered_args = (
+ self._uniffi_clone_handle(),
+ )
+ _uniffi_lift_return = _UniffiFfiConverterBoolean.lift
+ _uniffi_error_converter = None
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
+ _uniffi_error_converter,
+ _UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_is_available,
+ *_uniffi_lowered_args,
+ )
+ return _uniffi_lift_return(_uniffi_ffi_result)
+ def list_tools_json(self, ) -> str:
+ _uniffi_lowered_args = (
+ self._uniffi_clone_handle(),
+ )
+ _uniffi_lift_return = _UniffiFfiConverterString.lift
+ _uniffi_error_converter = _UniffiFfiConverterTypeDriverError
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
+ _uniffi_error_converter,
+ _UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_list_tools_json,
+ *_uniffi_lowered_args,
+ )
+ return _uniffi_lift_return(_uniffi_ffi_result)
+ def move_cursor(self, input: cua_driver._native_contract.MoveCursorInput) -> ToolResult:
+
+ cua_driver._native_contract._UniffiFfiConverterTypeMoveCursorInput.check_lower(input)
+ _uniffi_lowered_args = (
+ self._uniffi_clone_handle(),
+ cua_driver._native_contract._UniffiFfiConverterTypeMoveCursorInput.lower(input),
+ )
+ _uniffi_lift_return = _UniffiFfiConverterTypeToolResult.lift
+ _uniffi_error_converter = _UniffiFfiConverterTypeDriverError
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
+ _uniffi_error_converter,
+ _UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_move_cursor,
+ *_uniffi_lowered_args,
+ )
+ return _uniffi_lift_return(_uniffi_ffi_result)
+ def press_key(self, input: cua_driver._native_contract.PressKeyInput) -> ToolResult:
+
+ cua_driver._native_contract._UniffiFfiConverterTypePressKeyInput.check_lower(input)
+ _uniffi_lowered_args = (
+ self._uniffi_clone_handle(),
+ cua_driver._native_contract._UniffiFfiConverterTypePressKeyInput.lower(input),
+ )
+ _uniffi_lift_return = _UniffiFfiConverterTypeToolResult.lift
+ _uniffi_error_converter = _UniffiFfiConverterTypeDriverError
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
+ _uniffi_error_converter,
+ _UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_press_key,
+ *_uniffi_lowered_args,
+ )
+ return _uniffi_lift_return(_uniffi_ffi_result)
+ def scroll(self, input: cua_driver._native_contract.ScrollInput) -> ToolResult:
+
+ cua_driver._native_contract._UniffiFfiConverterTypeScrollInput.check_lower(input)
+ _uniffi_lowered_args = (
+ self._uniffi_clone_handle(),
+ cua_driver._native_contract._UniffiFfiConverterTypeScrollInput.lower(input),
+ )
+ _uniffi_lift_return = _UniffiFfiConverterTypeToolResult.lift
+ _uniffi_error_converter = _UniffiFfiConverterTypeDriverError
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
+ _uniffi_error_converter,
+ _UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_scroll,
+ *_uniffi_lowered_args,
+ )
+ return _uniffi_lift_return(_uniffi_ffi_result)
+ def socket_path(self, ) -> str:
+ _uniffi_lowered_args = (
+ self._uniffi_clone_handle(),
+ )
+ _uniffi_lift_return = _UniffiFfiConverterString.lift
+ _uniffi_error_converter = None
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
+ _uniffi_error_converter,
+ _UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_socket_path,
+ *_uniffi_lowered_args,
+ )
+ return _uniffi_lift_return(_uniffi_ffi_result)
+ def start_session(self, input: cua_driver._native_contract.StartSessionInput) -> cua_driver._native_contract.StartSessionOutput:
+
+ cua_driver._native_contract._UniffiFfiConverterTypeStartSessionInput.check_lower(input)
+ _uniffi_lowered_args = (
+ self._uniffi_clone_handle(),
+ cua_driver._native_contract._UniffiFfiConverterTypeStartSessionInput.lower(input),
+ )
+ _uniffi_lift_return = cua_driver._native_contract._UniffiFfiConverterTypeStartSessionOutput.lift
+ _uniffi_error_converter = _UniffiFfiConverterTypeDriverError
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
+ _uniffi_error_converter,
+ _UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_start_session,
+ *_uniffi_lowered_args,
+ )
+ return _uniffi_lift_return(_uniffi_ffi_result)
+ def type_text(self, input: cua_driver._native_contract.TypeTextInput) -> ToolResult:
+
+ cua_driver._native_contract._UniffiFfiConverterTypeTypeTextInput.check_lower(input)
+ _uniffi_lowered_args = (
+ self._uniffi_clone_handle(),
+ cua_driver._native_contract._UniffiFfiConverterTypeTypeTextInput.lower(input),
+ )
+ _uniffi_lift_return = _UniffiFfiConverterTypeToolResult.lift
+ _uniffi_error_converter = _UniffiFfiConverterTypeDriverError
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
+ _uniffi_error_converter,
+ _UniffiLib.uniffi_cua_driver_sdk_fn_method_cuadriver_type_text,
+ *_uniffi_lowered_args,
+ )
+ return _uniffi_lift_return(_uniffi_ffi_result)
+
+
+
+
+
+class _UniffiFfiConverterTypeCuaDriver:
+ @staticmethod
+ def lift(value: int) -> CuaDriver:
+ return CuaDriver._uniffi_make_instance(value)
+
+ @staticmethod
+ def check_lower(value: CuaDriver):
+ if not isinstance(value, CuaDriver):
+ raise TypeError("Expected CuaDriver instance, {} found".format(type(value).__name__))
+
+ @staticmethod
+ def lower(value: CuaDriver) -> ctypes.c_uint64:
+ return value._uniffi_clone_handle()
+
+ @classmethod
+ def read(cls, buf: _UniffiRustBuffer) -> CuaDriver:
+ ptr = buf.read_u64()
+ if ptr == 0:
+ raise InternalError("Raw handle value was null")
+ return cls.lift(ptr)
+
+ @classmethod
+ def write(cls, value: CuaDriver, buf: _UniffiRustBuffer):
+ buf.write_u64(cls.lower(value))
+
+class _UniffiFfiConverterUInt8(_UniffiConverterPrimitiveInt):
+ CLASS_NAME = "u8"
+ VALUE_MIN = 0
+ VALUE_MAX = 2**8
+
+ @staticmethod
+ def read(buf):
+ return buf.read_u8()
+
+ @staticmethod
+ def write(value, buf):
+ buf.write_u8(value)
+
+__all__ = [
+ "InternalError",
+ "DriverError",
+ "ImageContent",
+ "ToolResult",
+ "CuaDriver",
+ "CuaDriverProtocol",
+]
diff --git a/libs/cua-driver/python/src/cua_driver/_native_contract.py b/libs/cua-driver/python/src/cua_driver/_native_contract.py
new file mode 100644
index 0000000000..21493ca62f
--- /dev/null
+++ b/libs/cua-driver/python/src/cua_driver/_native_contract.py
@@ -0,0 +1,2255 @@
+# This file was autogenerated by some hot garbage in the `uniffi` crate.
+# Trust me, you don't want to mess with it!
+
+# Common helper code.
+#
+# Ideally this would live in a separate .py file where it can be unittested etc
+# in isolation, and perhaps even published as a re-useable package.
+#
+# However, it's important that the details of how this helper code works (e.g. the
+# way that different builtin types are passed across the FFI) exactly match what's
+# expected by the rust code on the other side of the interface. In practice right
+# now that means coming from the exact some version of `uniffi` that was used to
+# compile the rust component. The easiest way to ensure this is to bundle the Python
+# helpers directly inline like we're doing here.
+
+from __future__ import annotations
+import os
+import sys
+import ctypes
+from dataclasses import dataclass
+import enum
+import struct
+import contextlib
+import datetime
+import threading
+import itertools
+import traceback
+import typing
+import platform
+
+
+# Used for default argument values
+_DEFAULT = object() # type: typing.Any
+
+
+class _UniffiRustBuffer(ctypes.Structure):
+ _fields_ = [
+ ("capacity", ctypes.c_uint64),
+ ("len", ctypes.c_uint64),
+ ("data", ctypes.POINTER(ctypes.c_char)),
+ ]
+
+ @staticmethod
+ def default():
+ return _UniffiRustBuffer(0, 0, None)
+
+ @staticmethod
+ def alloc(size):
+ return _uniffi_rust_call(_UniffiLib.ffi_cua_driver_contract_rustbuffer_alloc, size)
+
+ @staticmethod
+ def reserve(rbuf, additional):
+ return _uniffi_rust_call(_UniffiLib.ffi_cua_driver_contract_rustbuffer_reserve, rbuf, additional)
+
+ def free(self):
+ return _uniffi_rust_call(_UniffiLib.ffi_cua_driver_contract_rustbuffer_free, self)
+
+ def __str__(self):
+ return "_UniffiRustBuffer(capacity={}, len={}, data={})".format(
+ self.capacity,
+ self.len,
+ self.data[0:self.len]
+ )
+
+ @contextlib.contextmanager
+ def alloc_with_builder(*args):
+ """Context-manger to allocate a buffer using a _UniffiRustBufferBuilder.
+
+ The allocated buffer will be automatically freed if an error occurs, ensuring that
+ we don't accidentally leak it.
+ """
+ builder = _UniffiRustBufferBuilder()
+ try:
+ yield builder
+ except:
+ builder.discard()
+ raise
+
+ @contextlib.contextmanager
+ def consume_with_stream(self):
+ """Context-manager to consume a buffer using a _UniffiRustBufferStream.
+
+ The _UniffiRustBuffer will be freed once the context-manager exits, ensuring that we don't
+ leak it even if an error occurs.
+ """
+ try:
+ s = _UniffiRustBufferStream.from_rust_buffer(self)
+ yield s
+ if s.remaining() != 0:
+ raise RuntimeError(f"junk data left in buffer at end of consume_with_stream {s.remaining()}")
+ finally:
+ self.free()
+
+ @contextlib.contextmanager
+ def read_with_stream(self):
+ """Context-manager to read a buffer using a _UniffiRustBufferStream.
+
+ This is like consume_with_stream, but doesn't free the buffer afterwards.
+ It should only be used with borrowed `_UniffiRustBuffer` data.
+ """
+ s = _UniffiRustBufferStream.from_rust_buffer(self)
+ yield s
+ if s.remaining() != 0:
+ raise RuntimeError(f"junk data left in buffer at end of read_with_stream {s.remaining()}")
+
+class _UniffiForeignBytes(ctypes.Structure):
+ _fields_ = [
+ ("len", ctypes.c_int32),
+ ("data", ctypes.POINTER(ctypes.c_char)),
+ ]
+
+ def __str__(self):
+ return "_UniffiForeignBytes(len={}, data={})".format(self.len, self.data[0:self.len])
+
+
+class _UniffiRustBufferStream:
+ """
+ Helper for structured reading of bytes from a _UniffiRustBuffer
+ """
+
+ def __init__(self, data, len):
+ self.data = data
+ self.len = len
+ self.offset = 0
+
+ @classmethod
+ def from_rust_buffer(cls, buf):
+ return cls(buf.data, buf.len)
+
+ def remaining(self):
+ return self.len - self.offset
+
+ def _unpack_from(self, size, format):
+ if self.offset + size > self.len:
+ raise InternalError("read past end of rust buffer")
+ value = struct.unpack(format, self.data[self.offset:self.offset+size])[0]
+ self.offset += size
+ return value
+
+ def read(self, size):
+ if self.offset + size > self.len:
+ raise InternalError("read past end of rust buffer")
+ data = self.data[self.offset:self.offset+size]
+ self.offset += size
+ return data
+
+ def read_i8(self):
+ return self._unpack_from(1, ">b")
+
+ def read_u8(self):
+ return self._unpack_from(1, ">B")
+
+ def read_i16(self):
+ return self._unpack_from(2, ">h")
+
+ def read_u16(self):
+ return self._unpack_from(2, ">H")
+
+ def read_i32(self):
+ return self._unpack_from(4, ">i")
+
+ def read_u32(self):
+ return self._unpack_from(4, ">I")
+
+ def read_i64(self):
+ return self._unpack_from(8, ">q")
+
+ def read_u64(self):
+ return self._unpack_from(8, ">Q")
+
+ def read_float(self):
+ v = self._unpack_from(4, ">f")
+ return v
+
+ def read_double(self):
+ return self._unpack_from(8, ">d")
+
+class _UniffiRustBufferBuilder:
+ """
+ Helper for structured writing of bytes into a _UniffiRustBuffer.
+ """
+
+ def __init__(self):
+ self.rbuf = _UniffiRustBuffer.alloc(16)
+ self.rbuf.len = 0
+
+ def finalize(self):
+ rbuf = self.rbuf
+ self.rbuf = None
+ return rbuf
+
+ def discard(self):
+ if self.rbuf is not None:
+ rbuf = self.finalize()
+ rbuf.free()
+
+ @contextlib.contextmanager
+ def _reserve(self, num_bytes):
+ if self.rbuf.len + num_bytes > self.rbuf.capacity:
+ self.rbuf = _UniffiRustBuffer.reserve(self.rbuf, num_bytes)
+ yield None
+ self.rbuf.len += num_bytes
+
+ def _pack_into(self, size, format, value):
+ with self._reserve(size):
+ # XXX TODO: I feel like I should be able to use `struct.pack_into` here but can't figure it out.
+ for i, byte in enumerate(struct.pack(format, value)):
+ self.rbuf.data[self.rbuf.len + i] = byte
+
+ def write(self, value):
+ with self._reserve(len(value)):
+ for i, byte in enumerate(value):
+ self.rbuf.data[self.rbuf.len + i] = byte
+
+ def write_i8(self, v):
+ self._pack_into(1, ">b", v)
+
+ def write_u8(self, v):
+ self._pack_into(1, ">B", v)
+
+ def write_i16(self, v):
+ self._pack_into(2, ">h", v)
+
+ def write_u16(self, v):
+ self._pack_into(2, ">H", v)
+
+ def write_i32(self, v):
+ self._pack_into(4, ">i", v)
+
+ def write_u32(self, v):
+ self._pack_into(4, ">I", v)
+
+ def write_i64(self, v):
+ self._pack_into(8, ">q", v)
+
+ def write_u64(self, v):
+ self._pack_into(8, ">Q", v)
+
+ def write_float(self, v):
+ self._pack_into(4, ">f", v)
+
+ def write_double(self, v):
+ self._pack_into(8, ">d", v)
+
+ def write_c_size_t(self, v):
+ self._pack_into(ctypes.sizeof(ctypes.c_size_t) , "@N", v)
+# A handful of classes and functions to support the generated data structures.
+# This would be a good candidate for isolating in its own ffi-support lib.
+
+class InternalError(Exception):
+ pass
+
+class _UniffiRustCallStatus(ctypes.Structure):
+ """
+ Error runtime.
+ """
+ _fields_ = [
+ ("code", ctypes.c_int8),
+ ("error_buf", _UniffiRustBuffer),
+ ]
+
+ # These match the values from the uniffi::rustcalls module
+ CALL_SUCCESS = 0
+ CALL_ERROR = 1
+ CALL_UNEXPECTED_ERROR = 2
+
+ @staticmethod
+ def default():
+ return _UniffiRustCallStatus(code=_UniffiRustCallStatus.CALL_SUCCESS, error_buf=_UniffiRustBuffer.default())
+
+ def __str__(self):
+ if self.code == _UniffiRustCallStatus.CALL_SUCCESS:
+ return "_UniffiRustCallStatus(CALL_SUCCESS)"
+ elif self.code == _UniffiRustCallStatus.CALL_ERROR:
+ return "_UniffiRustCallStatus(CALL_ERROR)"
+ elif self.code == _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR:
+ return "_UniffiRustCallStatus(CALL_UNEXPECTED_ERROR)"
+ else:
+ return "_UniffiRustCallStatus(<invalid code>)"
+
+def _uniffi_rust_call(fn, *args):
+ # Call a rust function
+ return _uniffi_rust_call_with_error(None, fn, *args)
+
+def _uniffi_rust_call_with_error(error_ffi_converter, fn, *args):
+ # Call a rust function and handle any errors
+ #
+ # This function is used for rust calls that return Result<> and therefore can set the CALL_ERROR status code.
+ # error_ffi_converter must be set to the _UniffiConverter for the error class that corresponds to the result.
+ call_status = _UniffiRustCallStatus.default()
+
+ args_with_error = args + (ctypes.byref(call_status),)
+ result = fn(*args_with_error)
+ _uniffi_check_call_status(error_ffi_converter, call_status)
+ return result
+
+def _uniffi_check_call_status(error_ffi_converter, call_status):
+ if call_status.code == _UniffiRustCallStatus.CALL_SUCCESS:
+ pass
+ elif call_status.code == _UniffiRustCallStatus.CALL_ERROR:
+ if error_ffi_converter is None:
+ call_status.error_buf.free()
+ raise InternalError("_uniffi_rust_call_with_error: CALL_ERROR, but error_ffi_converter is None")
+ else:
+ raise error_ffi_converter.lift(call_status.error_buf)
+ elif call_status.code == _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR:
+ # When the rust code sees a panic, it tries to construct a _UniffiRustBuffer
+ # with the message. But if that code panics, then it just sends back
+ # an empty buffer.
+ if call_status.error_buf.len > 0:
+ msg = _UniffiFfiConverterString.lift(call_status.error_buf)
+ else:
+ msg = "Unknown rust panic"
+ raise InternalError(msg)
+ else:
+ raise InternalError("Invalid _UniffiRustCallStatus code: {}".format(
+ call_status.code))
+
+def _uniffi_trait_interface_call(call_status, make_call, write_return_value):
+ try:
+ return write_return_value(make_call())
+ except Exception as e:
+ call_status.code = _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR
+ call_status.error_buf = _UniffiFfiConverterString.lower(repr(e))
+
+def _uniffi_trait_interface_call_with_error(call_status, make_call, write_return_value, error_type, lower_error):
+ try:
+ try:
+ return write_return_value(make_call())
+ except error_type as e:
+ call_status.code = _UniffiRustCallStatus.CALL_ERROR
+ call_status.error_buf = lower_error(e)
+ except Exception as e:
+ call_status.code = _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR
+ call_status.error_buf = _UniffiFfiConverterString.lower(repr(e))
+# Initial value and increment amount for handles.
+# These ensure that Python-generated handles always have the lowest bit set
+_UNIFFI_HANDLEMAP_INITIAL = 1
+_UNIFFI_HANDLEMAP_DELTA = 2
+
+class _UniffiHandleMap:
+ """
+ A map where inserting, getting and removing data is synchronized with a lock.
+ """
+
+ def __init__(self):
+ # type Handle = int
+ self._map = {} # type: Dict[Handle, Any]
+ self._lock = threading.Lock()
+ self._counter = _UNIFFI_HANDLEMAP_INITIAL
+
+ def insert(self, obj):
+ with self._lock:
+ return self._insert(obj)
+
+ """Low-level insert, this assumes `self._lock` is held."""
+ def _insert(self, obj):
+ handle = self._counter
+ self._counter += _UNIFFI_HANDLEMAP_DELTA
+ self._map[handle] = obj
+ return handle
+
+ def get(self, handle):
+ try:
+ with self._lock:
+ return self._map[handle]
+ except KeyError:
+ raise InternalError(f"_UniffiHandleMap.get: Invalid handle {handle}")
+
+ def clone(self, handle):
+ try:
+ with self._lock:
+ obj = self._map[handle]
+ return self._insert(obj)
+ except KeyError:
+ raise InternalError(f"_UniffiHandleMap.clone: Invalid handle {handle}")
+
+ def remove(self, handle):
+ try:
+ with self._lock:
+ return self._map.pop(handle)
+ except KeyError:
+ raise InternalError(f"_UniffiHandleMap.remove: Invalid handle: {handle}")
+
+ def __len__(self):
+ return len(self._map)
+# Types conforming to `_UniffiConverterPrimitive` pass themselves directly over the FFI.
+class _UniffiConverterPrimitive:
+ @classmethod
+ def lift(cls, value):
+ return value
+
+ @classmethod
+ def lower(cls, value):
+ return value
+
+class _UniffiConverterPrimitiveInt(_UniffiConverterPrimitive):
+ @classmethod
+ def check_lower(cls, value):
+ try:
+ value = value.__index__()
+ except Exception:
+ raise TypeError("'{}' object cannot be interpreted as an integer".format(type(value).__name__))
+ if not isinstance(value, int):
+ raise TypeError("__index__ returned non-int (type {})".format(type(value).__name__))
+ if not cls.VALUE_MIN <= value < cls.VALUE_MAX:
+ raise ValueError("{} requires {} <= value < {}".format(cls.CLASS_NAME, cls.VALUE_MIN, cls.VALUE_MAX))
+
+class _UniffiConverterPrimitiveFloat(_UniffiConverterPrimitive):
+ @classmethod
+ def check_lower(cls, value):
+ try:
+ value = value.__float__()
+ except Exception:
+ raise TypeError("must be real number, not {}".format(type(value).__name__))
+ if not isinstance(value, float):
+ raise TypeError("__float__ returned non-float (type {})".format(type(value).__name__))
+
+# Helper class for wrapper types that will always go through a _UniffiRustBuffer.
+# Classes should inherit from this and implement the `read` and `write` static methods.
+class _UniffiConverterRustBuffer:
+ @classmethod
+ def lift(cls, rbuf):
+ with rbuf.consume_with_stream() as stream:
+ return cls.read(stream)
+
+ @classmethod
+ def lower(cls, value):
+ with _UniffiRustBuffer.alloc_with_builder() as builder:
+ cls.write(value, builder)
+ return builder.finalize()
+
+# Contains loading, initialization code, and the FFI Function declarations.
+# Define some ctypes FFI types that we use in the library
+
+"""
+Function pointer for a Rust task, which a callback function that takes a opaque pointer
+"""
+_UNIFFI_RUST_TASK = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_int8)
+
+def _uniffi_future_callback_t(return_type):
+ """
+ Factory function to create callback function types for async functions
+ """
+ return ctypes.CFUNCTYPE(None, ctypes.c_uint64, return_type, _UniffiRustCallStatus)
+
+def _uniffi_load_indirect():
+ """
+ This is how we find and load the dynamic library provided by the component.
+ For now we just look it up by name.
+ """
+ if sys.platform == "darwin":
+ libname = "lib{}.dylib"
+ elif sys.platform.startswith("win"):
+ # As of python3.8, ctypes does not seem to search $PATH when loading DLLs.
+ # We could use `os.add_dll_directory` to configure the search path, but
+ # it doesn't feel right to mess with application-wide settings. Let's
+ # assume that the `.dll` is next to the `.py` file and load by full path.
+ libname = os.path.join(
+ os.path.dirname(__file__),
+ "{}.dll",
+ )
+ else:
+ # Anything else must be an ELF platform - Linux, *BSD, Solaris/illumos
+ libname = "lib{}.so"
+
+ libname = libname.format("cua_driver_sdk")
+ path = os.path.join(os.path.dirname(__file__), libname)
+ lib = ctypes.cdll.LoadLibrary(path)
+ return lib
+
+def _uniffi_check_contract_api_version(lib):
+ # Get the bindings contract version from our ComponentInterface
+ bindings_contract_version = 30
+ # Get the scaffolding contract version by calling the into the dylib
+ scaffolding_contract_version = lib.ffi_cua_driver_contract_uniffi_contract_version()
+ if bindings_contract_version != scaffolding_contract_version:
+ raise InternalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
+
+def _uniffi_check_api_checksums(lib):
+ pass
+
+# A ctypes library to expose the extern-C FFI definitions.
+# This is an implementation detail which will be called internally by the public API.
+
+_UniffiLib = _uniffi_load_indirect()
+_UniffiLib.ffi_cua_driver_contract_rustbuffer_alloc.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_contract_rustbuffer_alloc.restype = _UniffiRustBuffer
+_UniffiLib.ffi_cua_driver_contract_rustbuffer_from_bytes.argtypes = (
+ _UniffiForeignBytes,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_contract_rustbuffer_from_bytes.restype = _UniffiRustBuffer
+_UniffiLib.ffi_cua_driver_contract_rustbuffer_free.argtypes = (
+ _UniffiRustBuffer,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_contract_rustbuffer_free.restype = None
+_UniffiLib.ffi_cua_driver_contract_rustbuffer_reserve.argtypes = (
+ _UniffiRustBuffer,
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_contract_rustbuffer_reserve.restype = _UniffiRustBuffer
+_UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK = ctypes.CFUNCTYPE(None,ctypes.c_uint64,ctypes.c_int8,
+)
+_UNIFFI_FOREIGN_FUTURE_DROPPED_CALLBACK = ctypes.CFUNCTYPE(None,ctypes.c_uint64,
+)
+class _UniffiForeignFutureDroppedCallbackStruct(ctypes.Structure):
+ _fields_ = [
+ ("handle", ctypes.c_uint64),
+ ("free", _UNIFFI_FOREIGN_FUTURE_DROPPED_CALLBACK),
+ ]
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_u8.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_u8.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_u8.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_u8.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_u8.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_u8.restype = ctypes.c_uint8
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_u8.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_u8.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_i8.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_i8.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_i8.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_i8.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_i8.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_i8.restype = ctypes.c_int8
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_i8.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_i8.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_u16.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_u16.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_u16.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_u16.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_u16.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_u16.restype = ctypes.c_uint16
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_u16.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_u16.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_i16.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_i16.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_i16.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_i16.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_i16.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_i16.restype = ctypes.c_int16
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_i16.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_i16.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_u32.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_u32.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_u32.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_u32.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_u32.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_u32.restype = ctypes.c_uint32
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_u32.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_u32.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_i32.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_i32.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_i32.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_i32.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_i32.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_i32.restype = ctypes.c_int32
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_i32.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_i32.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_u64.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_u64.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_u64.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_u64.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_u64.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_u64.restype = ctypes.c_uint64
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_u64.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_u64.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_i64.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_i64.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_i64.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_i64.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_i64.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_i64.restype = ctypes.c_int64
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_i64.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_i64.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_f32.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_f32.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_f32.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_f32.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_f32.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_f32.restype = ctypes.c_float
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_f32.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_f32.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_f64.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_f64.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_f64.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_f64.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_f64.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_f64.restype = ctypes.c_double
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_f64.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_f64.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_rust_buffer.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_rust_buffer.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_rust_buffer.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_rust_buffer.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_rust_buffer.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_rust_buffer.restype = _UniffiRustBuffer
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_rust_buffer.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_rust_buffer.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_void.argtypes = (
+ ctypes.c_uint64,
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_poll_void.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_void.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_cancel_void.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_void.argtypes = (
+ ctypes.c_uint64,
+ ctypes.POINTER(_UniffiRustCallStatus),
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_complete_void.restype = None
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_void.argtypes = (
+ ctypes.c_uint64,
+)
+_UniffiLib.ffi_cua_driver_contract_rust_future_free_void.restype = None
+_UniffiLib.ffi_cua_driver_contract_uniffi_contract_version.argtypes = (
+)
+_UniffiLib.ffi_cua_driver_contract_uniffi_contract_version.restype = ctypes.c_uint32
+
+_uniffi_check_contract_api_version(_UniffiLib)
+# _uniffi_check_api_checksums(_UniffiLib)
+
+
+
+# Public interface members begin here.
+
+
+class _UniffiFfiConverterFloat64(_UniffiConverterPrimitiveFloat):
+ @staticmethod
+ def read(buf):
+ return buf.read_double()
+
+ @staticmethod
+ def write(value, buf):
+ buf.write_double(value)
+
+
+
+
+
+
+class DesktopScope(enum.Enum):
+
+ DESKTOP = 0
+
+
+
+class _UniffiFfiConverterTypeDesktopScope(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ variant = buf.read_i32()
+ if variant == 1:
+ return DesktopScope.DESKTOP
+ raise InternalError("Raw enum value doesn't match any cases")
+
+ @staticmethod
+ def check_lower(value):
+ if value == DesktopScope.DESKTOP:
+ return
+ raise ValueError(value)
+
+ @staticmethod
+ def write(value, buf):
+ if value == DesktopScope.DESKTOP:
+ buf.write_i32(1)
+
+
+
+class _UniffiFfiConverterString:
+ @staticmethod
+ def check_lower(value):
+ if not isinstance(value, str):
+ raise TypeError("argument must be str, not {}".format(type(value).__name__))
+ return value
+
+ @staticmethod
+ def read(buf):
+ size = buf.read_i32()
+ if size < 0:
+ raise InternalError("Unexpected negative string length")
+ utf8_bytes = buf.read(size)
+ return utf8_bytes.decode("utf-8")
+
+ @staticmethod
+ def write(value, buf):
+ utf8_bytes = value.encode("utf-8")
+ buf.write_i32(len(utf8_bytes))
+ buf.write(utf8_bytes)
+
+ @staticmethod
+ def lift(buf):
+ with buf.consume_with_stream() as stream:
+ return stream.read(stream.remaining()).decode("utf-8")
+
+ @staticmethod
+ def lower(value):
+ with _UniffiRustBuffer.alloc_with_builder() as builder:
+ builder.write(value.encode("utf-8"))
+ return builder.finalize()
+
+class _UniffiFfiConverterOptionalString(_UniffiConverterRustBuffer):
+ @classmethod
+ def check_lower(cls, value):
+ if value is not None:
+ _UniffiFfiConverterString.check_lower(value)
+
+ @classmethod
+ def write(cls, value, buf):
+ if value is None:
+ buf.write_u8(0)
+ return
+
+ buf.write_u8(1)
+ _UniffiFfiConverterString.write(value, buf)
+
+ @classmethod
+ def read(cls, buf):
+ flag = buf.read_u8()
+ if flag == 0:
+ return None
+ elif flag == 1:
+ return _UniffiFfiConverterString.read(buf)
+ else:
+ raise InternalError("Unexpected flag byte for optional type")
+
+
+
+
+
+
+class ClickButton(enum.Enum):
+
+ LEFT = 0
+
+ RIGHT = 1
+
+ MIDDLE = 2
+
+
+
+class _UniffiFfiConverterTypeClickButton(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ variant = buf.read_i32()
+ if variant == 1:
+ return ClickButton.LEFT
+ if variant == 2:
+ return ClickButton.RIGHT
+ if variant == 3:
+ return ClickButton.MIDDLE
+ raise InternalError("Raw enum value doesn't match any cases")
+
+ @staticmethod
+ def check_lower(value):
+ if value == ClickButton.LEFT:
+ return
+ if value == ClickButton.RIGHT:
+ return
+ if value == ClickButton.MIDDLE:
+ return
+ raise ValueError(value)
+
+ @staticmethod
+ def write(value, buf):
+ if value == ClickButton.LEFT:
+ buf.write_i32(1)
+ if value == ClickButton.RIGHT:
+ buf.write_i32(2)
+ if value == ClickButton.MIDDLE:
+ buf.write_i32(3)
+
+
+
+class _UniffiFfiConverterOptionalTypeClickButton(_UniffiConverterRustBuffer):
+ @classmethod
+ def check_lower(cls, value):
+ if value is not None:
+ _UniffiFfiConverterTypeClickButton.check_lower(value)
+
+ @classmethod
+ def write(cls, value, buf):
+ if value is None:
+ buf.write_u8(0)
+ return
+
+ buf.write_u8(1)
+ _UniffiFfiConverterTypeClickButton.write(value, buf)
+
+ @classmethod
+ def read(cls, buf):
+ flag = buf.read_u8()
+ if flag == 0:
+ return None
+ elif flag == 1:
+ return _UniffiFfiConverterTypeClickButton.read(buf)
+ else:
+ raise InternalError("Unexpected flag byte for optional type")
+
+class _UniffiFfiConverterUInt32(_UniffiConverterPrimitiveInt):
+ CLASS_NAME = "u32"
+ VALUE_MIN = 0
+ VALUE_MAX = 2**32
+
+ @staticmethod
+ def read(buf):
+ return buf.read_u32()
+
+ @staticmethod
+ def write(value, buf):
+ buf.write_u32(value)
+
+class _UniffiFfiConverterOptionalUInt32(_UniffiConverterRustBuffer):
+ @classmethod
+ def check_lower(cls, value):
+ if value is not None:
+ _UniffiFfiConverterUInt32.check_lower(value)
+
+ @classmethod
+ def write(cls, value, buf):
+ if value is None:
+ buf.write_u8(0)
+ return
+
+ buf.write_u8(1)
+ _UniffiFfiConverterUInt32.write(value, buf)
+
+ @classmethod
+ def read(cls, buf):
+ flag = buf.read_u8()
+ if flag == 0:
+ return None
+ elif flag == 1:
+ return _UniffiFfiConverterUInt32.read(buf)
+ else:
+ raise InternalError("Unexpected flag byte for optional type")
+
+@dataclass
+class ClickInput:
+ def __init__(self, *, x:float, y:float, scope:DesktopScope, session:typing.Optional[str], button:typing.Optional[ClickButton], count:typing.Optional[int]):
+ self.x = x
+ self.y = y
+ self.scope = scope
+ self.session = session
+ self.button = button
+ self.count = count
+
+
+
+
+ def __str__(self):
+ return "ClickInput(x={}, y={}, scope={}, session={}, button={}, count={})".format(self.x, self.y, self.scope, self.session, self.button, self.count)
+ def __eq__(self, other):
+ if self.x != other.x:
+ return False
+ if self.y != other.y:
+ return False
+ if self.scope != other.scope:
+ return False
+ if self.session != other.session:
+ return False
+ if self.button != other.button:
+ return False
+ if self.count != other.count:
+ return False
+ return True
+
+class _UniffiFfiConverterTypeClickInput(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ return ClickInput(
+ x=_UniffiFfiConverterFloat64.read(buf),
+ y=_UniffiFfiConverterFloat64.read(buf),
+ scope=_UniffiFfiConverterTypeDesktopScope.read(buf),
+ session=_UniffiFfiConverterOptionalString.read(buf),
+ button=_UniffiFfiConverterOptionalTypeClickButton.read(buf),
+ count=_UniffiFfiConverterOptionalUInt32.read(buf),
+ )
+
+ @staticmethod
+ def check_lower(value):
+ _UniffiFfiConverterFloat64.check_lower(value.x)
+ _UniffiFfiConverterFloat64.check_lower(value.y)
+ _UniffiFfiConverterTypeDesktopScope.check_lower(value.scope)
+ _UniffiFfiConverterOptionalString.check_lower(value.session)
+ _UniffiFfiConverterOptionalTypeClickButton.check_lower(value.button)
+ _UniffiFfiConverterOptionalUInt32.check_lower(value.count)
+
+ @staticmethod
+ def write(value, buf):
+ _UniffiFfiConverterFloat64.write(value.x, buf)
+ _UniffiFfiConverterFloat64.write(value.y, buf)
+ _UniffiFfiConverterTypeDesktopScope.write(value.scope, buf)
+ _UniffiFfiConverterOptionalString.write(value.session, buf)
+ _UniffiFfiConverterOptionalTypeClickButton.write(value.button, buf)
+ _UniffiFfiConverterOptionalUInt32.write(value.count, buf)
+
+class _UniffiFfiConverterUInt64(_UniffiConverterPrimitiveInt):
+ CLASS_NAME = "u64"
+ VALUE_MIN = 0
+ VALUE_MAX = 2**64
+
+ @staticmethod
+ def read(buf):
+ return buf.read_u64()
+
+ @staticmethod
+ def write(value, buf):
+ buf.write_u64(value)
+
+class _UniffiFfiConverterOptionalUInt64(_UniffiConverterRustBuffer):
+ @classmethod
+ def check_lower(cls, value):
+ if value is not None:
+ _UniffiFfiConverterUInt64.check_lower(value)
+
+ @classmethod
+ def write(cls, value, buf):
+ if value is None:
+ buf.write_u8(0)
+ return
+
+ buf.write_u8(1)
+ _UniffiFfiConverterUInt64.write(value, buf)
+
+ @classmethod
+ def read(cls, buf):
+ flag = buf.read_u8()
+ if flag == 0:
+ return None
+ elif flag == 1:
+ return _UniffiFfiConverterUInt64.read(buf)
+ else:
+ raise InternalError("Unexpected flag byte for optional type")
+
+class _UniffiFfiConverterSequenceString(_UniffiConverterRustBuffer):
+ @classmethod
+ def check_lower(cls, value):
+ for item in value:
+ _UniffiFfiConverterString.check_lower(item)
+
+ @classmethod
+ def write(cls, value, buf):
+ items = len(value)
+ buf.write_i32(items)
+ for item in value:
+ _UniffiFfiConverterString.write(item, buf)
+
+ @classmethod
+ def read(cls, buf):
+ count = buf.read_i32()
+ if count < 0:
+ raise InternalError("Unexpected negative sequence length")
+
+ return [
+ _UniffiFfiConverterString.read(buf) for i in range(count)
+ ]
+
+class _UniffiFfiConverterOptionalSequenceString(_UniffiConverterRustBuffer):
+ @classmethod
+ def check_lower(cls, value):
+ if value is not None:
+ _UniffiFfiConverterSequenceString.check_lower(value)
+
+ @classmethod
+ def write(cls, value, buf):
+ if value is None:
+ buf.write_u8(0)
+ return
+
+ buf.write_u8(1)
+ _UniffiFfiConverterSequenceString.write(value, buf)
+
+ @classmethod
+ def read(cls, buf):
+ flag = buf.read_u8()
+ if flag == 0:
+ return None
+ elif flag == 1:
+ return _UniffiFfiConverterSequenceString.read(buf)
+ else:
+ raise InternalError("Unexpected flag byte for optional type")
+
+@dataclass
+class DragInput:
+ def __init__(self, *, from_x:float, from_y:float, to_x:float, to_y:float, scope:DesktopScope, session:typing.Optional[str], duration_ms:typing.Optional[int], steps:typing.Optional[int], button:typing.Optional[ClickButton], modifier:typing.Optional[typing.List[str]]):
+ self.from_x = from_x
+ self.from_y = from_y
+ self.to_x = to_x
+ self.to_y = to_y
+ self.scope = scope
+ self.session = session
+ self.duration_ms = duration_ms
+ self.steps = steps
+ self.button = button
+ self.modifier = modifier
+
+
+
+
+ def __str__(self):
+ return "DragInput(from_x={}, from_y={}, to_x={}, to_y={}, scope={}, session={}, duration_ms={}, steps={}, button={}, modifier={})".format(self.from_x, self.from_y, self.to_x, self.to_y, self.scope, self.session, self.duration_ms, self.steps, self.button, self.modifier)
+ def __eq__(self, other):
+ if self.from_x != other.from_x:
+ return False
+ if self.from_y != other.from_y:
+ return False
+ if self.to_x != other.to_x:
+ return False
+ if self.to_y != other.to_y:
+ return False
+ if self.scope != other.scope:
+ return False
+ if self.session != other.session:
+ return False
+ if self.duration_ms != other.duration_ms:
+ return False
+ if self.steps != other.steps:
+ return False
+ if self.button != other.button:
+ return False
+ if self.modifier != other.modifier:
+ return False
+ return True
+
+class _UniffiFfiConverterTypeDragInput(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ return DragInput(
+ from_x=_UniffiFfiConverterFloat64.read(buf),
+ from_y=_UniffiFfiConverterFloat64.read(buf),
+ to_x=_UniffiFfiConverterFloat64.read(buf),
+ to_y=_UniffiFfiConverterFloat64.read(buf),
+ scope=_UniffiFfiConverterTypeDesktopScope.read(buf),
+ session=_UniffiFfiConverterOptionalString.read(buf),
+ duration_ms=_UniffiFfiConverterOptionalUInt64.read(buf),
+ steps=_UniffiFfiConverterOptionalUInt64.read(buf),
+ button=_UniffiFfiConverterOptionalTypeClickButton.read(buf),
+ modifier=_UniffiFfiConverterOptionalSequenceString.read(buf),
+ )
+
+ @staticmethod
+ def check_lower(value):
+ _UniffiFfiConverterFloat64.check_lower(value.from_x)
+ _UniffiFfiConverterFloat64.check_lower(value.from_y)
+ _UniffiFfiConverterFloat64.check_lower(value.to_x)
+ _UniffiFfiConverterFloat64.check_lower(value.to_y)
+ _UniffiFfiConverterTypeDesktopScope.check_lower(value.scope)
+ _UniffiFfiConverterOptionalString.check_lower(value.session)
+ _UniffiFfiConverterOptionalUInt64.check_lower(value.duration_ms)
+ _UniffiFfiConverterOptionalUInt64.check_lower(value.steps)
+ _UniffiFfiConverterOptionalTypeClickButton.check_lower(value.button)
+ _UniffiFfiConverterOptionalSequenceString.check_lower(value.modifier)
+
+ @staticmethod
+ def write(value, buf):
+ _UniffiFfiConverterFloat64.write(value.from_x, buf)
+ _UniffiFfiConverterFloat64.write(value.from_y, buf)
+ _UniffiFfiConverterFloat64.write(value.to_x, buf)
+ _UniffiFfiConverterFloat64.write(value.to_y, buf)
+ _UniffiFfiConverterTypeDesktopScope.write(value.scope, buf)
+ _UniffiFfiConverterOptionalString.write(value.session, buf)
+ _UniffiFfiConverterOptionalUInt64.write(value.duration_ms, buf)
+ _UniffiFfiConverterOptionalUInt64.write(value.steps, buf)
+ _UniffiFfiConverterOptionalTypeClickButton.write(value.button, buf)
+ _UniffiFfiConverterOptionalSequenceString.write(value.modifier, buf)
+
+@dataclass
+class EndSessionInput:
+ def __init__(self, *, session:str):
+ self.session = session
+
+
+
+
+ def __str__(self):
+ return "EndSessionInput(session={})".format(self.session)
+ def __eq__(self, other):
+ if self.session != other.session:
+ return False
+ return True
+
+class _UniffiFfiConverterTypeEndSessionInput(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ return EndSessionInput(
+ session=_UniffiFfiConverterString.read(buf),
+ )
+
+ @staticmethod
+ def check_lower(value):
+ _UniffiFfiConverterString.check_lower(value.session)
+
+ @staticmethod
+ def write(value, buf):
+ _UniffiFfiConverterString.write(value.session, buf)
+
+class _UniffiFfiConverterBoolean:
+ @classmethod
+ def check_lower(cls, value):
+ return not not value
+
+ @classmethod
+ def lower(cls, value):
+ return 1 if value else 0
+
+ @staticmethod
+ def lift(value):
+ return value != 0
+
+ @classmethod
+ def read(cls, buf):
+ return cls.lift(buf.read_u8())
+
+ @classmethod
+ def write(cls, value, buf):
+ buf.write_u8(value)
+
+@dataclass
+class EndSessionOutput:
+ """
+ Successful structured result returned by `end_session`.
+"""
+ def __init__(self, *, session:str, active:bool):
+ self.session = session
+ self.active = active
+
+
+
+
+ def __str__(self):
+ return "EndSessionOutput(session={}, active={})".format(self.session, self.active)
+ def __eq__(self, other):
+ if self.session != other.session:
+ return False
+ if self.active != other.active:
+ return False
+ return True
+
+class _UniffiFfiConverterTypeEndSessionOutput(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ return EndSessionOutput(
+ session=_UniffiFfiConverterString.read(buf),
+ active=_UniffiFfiConverterBoolean.read(buf),
+ )
+
+ @staticmethod
+ def check_lower(value):
+ _UniffiFfiConverterString.check_lower(value.session)
+ _UniffiFfiConverterBoolean.check_lower(value.active)
+
+ @staticmethod
+ def write(value, buf):
+ _UniffiFfiConverterString.write(value.session, buf)
+ _UniffiFfiConverterBoolean.write(value.active, buf)
+
+
+
+
+
+
+class EscalationReason(enum.Enum):
+
+ AX_TREE_PIXEL_MISMATCH = 0
+
+ BACKGROUND_DELIVERY_FAILED = 1
+
+ FOREGROUND_INEFFECTIVE = 2
+
+ NO_WINDOW_TARGET = 3
+
+ OTHER = 4
+
+
+
+class _UniffiFfiConverterTypeEscalationReason(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ variant = buf.read_i32()
+ if variant == 1:
+ return EscalationReason.AX_TREE_PIXEL_MISMATCH
+ if variant == 2:
+ return EscalationReason.BACKGROUND_DELIVERY_FAILED
+ if variant == 3:
+ return EscalationReason.FOREGROUND_INEFFECTIVE
+ if variant == 4:
+ return EscalationReason.NO_WINDOW_TARGET
+ if variant == 5:
+ return EscalationReason.OTHER
+ raise InternalError("Raw enum value doesn't match any cases")
+
+ @staticmethod
+ def check_lower(value):
+ if value == EscalationReason.AX_TREE_PIXEL_MISMATCH:
+ return
+ if value == EscalationReason.BACKGROUND_DELIVERY_FAILED:
+ return
+ if value == EscalationReason.FOREGROUND_INEFFECTIVE:
+ return
+ if value == EscalationReason.NO_WINDOW_TARGET:
+ return
+ if value == EscalationReason.OTHER:
+ return
+ raise ValueError(value)
+
+ @staticmethod
+ def write(value, buf):
+ if value == EscalationReason.AX_TREE_PIXEL_MISMATCH:
+ buf.write_i32(1)
+ if value == EscalationReason.BACKGROUND_DELIVERY_FAILED:
+ buf.write_i32(2)
+ if value == EscalationReason.FOREGROUND_INEFFECTIVE:
+ buf.write_i32(3)
+ if value == EscalationReason.NO_WINDOW_TARGET:
+ buf.write_i32(4)
+ if value == EscalationReason.OTHER:
+ buf.write_i32(5)
+
+
+
+@dataclass
+class EscalateSessionInput:
+ def __init__(self, *, session:str, reason:EscalationReason, detail:typing.Optional[str]):
+ self.session = session
+ self.reason = reason
+ self.detail = detail
+
+
+
+
+ def __str__(self):
+ return "EscalateSessionInput(session={}, reason={}, detail={})".format(self.session, self.reason, self.detail)
+ def __eq__(self, other):
+ if self.session != other.session:
+ return False
+ if self.reason != other.reason:
+ return False
+ if self.detail != other.detail:
+ return False
+ return True
+
+class _UniffiFfiConverterTypeEscalateSessionInput(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ return EscalateSessionInput(
+ session=_UniffiFfiConverterString.read(buf),
+ reason=_UniffiFfiConverterTypeEscalationReason.read(buf),
+ detail=_UniffiFfiConverterOptionalString.read(buf),
+ )
+
+ @staticmethod
+ def check_lower(value):
+ _UniffiFfiConverterString.check_lower(value.session)
+ _UniffiFfiConverterTypeEscalationReason.check_lower(value.reason)
+ _UniffiFfiConverterOptionalString.check_lower(value.detail)
+
+ @staticmethod
+ def write(value, buf):
+ _UniffiFfiConverterString.write(value.session, buf)
+ _UniffiFfiConverterTypeEscalationReason.write(value.reason, buf)
+ _UniffiFfiConverterOptionalString.write(value.detail, buf)
+
+@dataclass
+class GetCursorPositionInput:
+ def __init__(self, *, session:typing.Optional[str]):
+ self.session = session
+
+
+
+
+ def __str__(self):
+ return "GetCursorPositionInput(session={})".format(self.session)
+ def __eq__(self, other):
+ if self.session != other.session:
+ return False
+ return True
+
+class _UniffiFfiConverterTypeGetCursorPositionInput(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ return GetCursorPositionInput(
+ session=_UniffiFfiConverterOptionalString.read(buf),
+ )
+
+ @staticmethod
+ def check_lower(value):
+ _UniffiFfiConverterOptionalString.check_lower(value.session)
+
+ @staticmethod
+ def write(value, buf):
+ _UniffiFfiConverterOptionalString.write(value.session, buf)
+
+@dataclass
+class GetDesktopStateInput:
+ def __init__(self, *, session:typing.Optional[str], screenshot_out_file:typing.Optional[str]):
+ self.session = session
+ self.screenshot_out_file = screenshot_out_file
+
+
+
+
+ def __str__(self):
+ return "GetDesktopStateInput(session={}, screenshot_out_file={})".format(self.session, self.screenshot_out_file)
+ def __eq__(self, other):
+ if self.session != other.session:
+ return False
+ if self.screenshot_out_file != other.screenshot_out_file:
+ return False
+ return True
+
+class _UniffiFfiConverterTypeGetDesktopStateInput(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ return GetDesktopStateInput(
+ session=_UniffiFfiConverterOptionalString.read(buf),
+ screenshot_out_file=_UniffiFfiConverterOptionalString.read(buf),
+ )
+
+ @staticmethod
+ def check_lower(value):
+ _UniffiFfiConverterOptionalString.check_lower(value.session)
+ _UniffiFfiConverterOptionalString.check_lower(value.screenshot_out_file)
+
+ @staticmethod
+ def write(value, buf):
+ _UniffiFfiConverterOptionalString.write(value.session, buf)
+ _UniffiFfiConverterOptionalString.write(value.screenshot_out_file, buf)
+
+@dataclass
+class GetScreenSizeInput:
+ def __init__(self, *, session:typing.Optional[str]):
+ self.session = session
+
+
+
+
+ def __str__(self):
+ return "GetScreenSizeInput(session={})".format(self.session)
+ def __eq__(self, other):
+ if self.session != other.session:
+ return False
+ return True
+
+class _UniffiFfiConverterTypeGetScreenSizeInput(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ return GetScreenSizeInput(
+ session=_UniffiFfiConverterOptionalString.read(buf),
+ )
+
+ @staticmethod
+ def check_lower(value):
+ _UniffiFfiConverterOptionalString.check_lower(value.session)
+
+ @staticmethod
+ def write(value, buf):
+ _UniffiFfiConverterOptionalString.write(value.session, buf)
+
+@dataclass
+class GetSessionStateInput:
+ def __init__(self, *, session:str):
+ self.session = session
+
+
+
+
+ def __str__(self):
+ return "GetSessionStateInput(session={})".format(self.session)
+ def __eq__(self, other):
+ if self.session != other.session:
+ return False
+ return True
+
+class _UniffiFfiConverterTypeGetSessionStateInput(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ return GetSessionStateInput(
+ session=_UniffiFfiConverterString.read(buf),
+ )
+
+ @staticmethod
+ def check_lower(value):
+ _UniffiFfiConverterString.check_lower(value.session)
+
+ @staticmethod
+ def write(value, buf):
+ _UniffiFfiConverterString.write(value.session, buf)
+
+@dataclass
+class HotkeyInput:
+ def __init__(self, *, keys:typing.List[str], scope:DesktopScope, session:typing.Optional[str]):
+ self.keys = keys
+ self.scope = scope
+ self.session = session
+
+
+
+
+ def __str__(self):
+ return "HotkeyInput(keys={}, scope={}, session={})".format(self.keys, self.scope, self.session)
+ def __eq__(self, other):
+ if self.keys != other.keys:
+ return False
+ if self.scope != other.scope:
+ return False
+ if self.session != other.session:
+ return False
+ return True
+
+class _UniffiFfiConverterTypeHotkeyInput(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ return HotkeyInput(
+ keys=_UniffiFfiConverterSequenceString.read(buf),
+ scope=_UniffiFfiConverterTypeDesktopScope.read(buf),
+ session=_UniffiFfiConverterOptionalString.read(buf),
+ )
+
+ @staticmethod
+ def check_lower(value):
+ _UniffiFfiConverterSequenceString.check_lower(value.keys)
+ _UniffiFfiConverterTypeDesktopScope.check_lower(value.scope)
+ _UniffiFfiConverterOptionalString.check_lower(value.session)
+
+ @staticmethod
+ def write(value, buf):
+ _UniffiFfiConverterSequenceString.write(value.keys, buf)
+ _UniffiFfiConverterTypeDesktopScope.write(value.scope, buf)
+ _UniffiFfiConverterOptionalString.write(value.session, buf)
+
+@dataclass
+class MoveCursorInput:
+ def __init__(self, *, x:float, y:float, scope:DesktopScope, session:typing.Optional[str]):
+ self.x = x
+ self.y = y
+ self.scope = scope
+ self.session = session
+
+
+
+
+ def __str__(self):
+ return "MoveCursorInput(x={}, y={}, scope={}, session={})".format(self.x, self.y, self.scope, self.session)
+ def __eq__(self, other):
+ if self.x != other.x:
+ return False
+ if self.y != other.y:
+ return False
+ if self.scope != other.scope:
+ return False
+ if self.session != other.session:
+ return False
+ return True
+
+class _UniffiFfiConverterTypeMoveCursorInput(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ return MoveCursorInput(
+ x=_UniffiFfiConverterFloat64.read(buf),
+ y=_UniffiFfiConverterFloat64.read(buf),
+ scope=_UniffiFfiConverterTypeDesktopScope.read(buf),
+ session=_UniffiFfiConverterOptionalString.read(buf),
+ )
+
+ @staticmethod
+ def check_lower(value):
+ _UniffiFfiConverterFloat64.check_lower(value.x)
+ _UniffiFfiConverterFloat64.check_lower(value.y)
+ _UniffiFfiConverterTypeDesktopScope.check_lower(value.scope)
+ _UniffiFfiConverterOptionalString.check_lower(value.session)
+
+ @staticmethod
+ def write(value, buf):
+ _UniffiFfiConverterFloat64.write(value.x, buf)
+ _UniffiFfiConverterFloat64.write(value.y, buf)
+ _UniffiFfiConverterTypeDesktopScope.write(value.scope, buf)
+ _UniffiFfiConverterOptionalString.write(value.session, buf)
+
+@dataclass
+class PressKeyInput:
+ def __init__(self, *, key:str, scope:DesktopScope, session:typing.Optional[str], modifiers:typing.Optional[typing.List[str]]):
+ self.key = key
+ self.scope = scope
+ self.session = session
+ self.modifiers = modifiers
+
+
+
+
+ def __str__(self):
+ return "PressKeyInput(key={}, scope={}, session={}, modifiers={})".format(self.key, self.scope, self.session, self.modifiers)
+ def __eq__(self, other):
+ if self.key != other.key:
+ return False
+ if self.scope != other.scope:
+ return False
+ if self.session != other.session:
+ return False
+ if self.modifiers != other.modifiers:
+ return False
+ return True
+
+class _UniffiFfiConverterTypePressKeyInput(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ return PressKeyInput(
+ key=_UniffiFfiConverterString.read(buf),
+ scope=_UniffiFfiConverterTypeDesktopScope.read(buf),
+ session=_UniffiFfiConverterOptionalString.read(buf),
+ modifiers=_UniffiFfiConverterOptionalSequenceString.read(buf),
+ )
+
+ @staticmethod
+ def check_lower(value):
+ _UniffiFfiConverterString.check_lower(value.key)
+ _UniffiFfiConverterTypeDesktopScope.check_lower(value.scope)
+ _UniffiFfiConverterOptionalString.check_lower(value.session)
+ _UniffiFfiConverterOptionalSequenceString.check_lower(value.modifiers)
+
+ @staticmethod
+ def write(value, buf):
+ _UniffiFfiConverterString.write(value.key, buf)
+ _UniffiFfiConverterTypeDesktopScope.write(value.scope, buf)
+ _UniffiFfiConverterOptionalString.write(value.session, buf)
+ _UniffiFfiConverterOptionalSequenceString.write(value.modifiers, buf)
+
+
+
+
+
+
+class ScrollDirection(enum.Enum):
+
+ UP = 0
+
+ DOWN = 1
+
+ LEFT = 2
+
+ RIGHT = 3
+
+
+
+class _UniffiFfiConverterTypeScrollDirection(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ variant = buf.read_i32()
+ if variant == 1:
+ return ScrollDirection.UP
+ if variant == 2:
+ return ScrollDirection.DOWN
+ if variant == 3:
+ return ScrollDirection.LEFT
+ if variant == 4:
+ return ScrollDirection.RIGHT
+ raise InternalError("Raw enum value doesn't match any cases")
+
+ @staticmethod
+ def check_lower(value):
+ if value == ScrollDirection.UP:
+ return
+ if value == ScrollDirection.DOWN:
+ return
+ if value == ScrollDirection.LEFT:
+ return
+ if value == ScrollDirection.RIGHT:
+ return
+ raise ValueError(value)
+
+ @staticmethod
+ def write(value, buf):
+ if value == ScrollDirection.UP:
+ buf.write_i32(1)
+ if value == ScrollDirection.DOWN:
+ buf.write_i32(2)
+ if value == ScrollDirection.LEFT:
+ buf.write_i32(3)
+ if value == ScrollDirection.RIGHT:
+ buf.write_i32(4)
+
+
+
+
+
+
+
+
+class ScrollBy(enum.Enum):
+
+ LINE = 0
+
+ PAGE = 1
+
+
+
+class _UniffiFfiConverterTypeScrollBy(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ variant = buf.read_i32()
+ if variant == 1:
+ return ScrollBy.LINE
+ if variant == 2:
+ return ScrollBy.PAGE
+ raise InternalError("Raw enum value doesn't match any cases")
+
+ @staticmethod
+ def check_lower(value):
+ if value == ScrollBy.LINE:
+ return
+ if value == ScrollBy.PAGE:
+ return
+ raise ValueError(value)
+
+ @staticmethod
+ def write(value, buf):
+ if value == ScrollBy.LINE:
+ buf.write_i32(1)
+ if value == ScrollBy.PAGE:
+ buf.write_i32(2)
+
+
+
+class _UniffiFfiConverterOptionalTypeScrollBy(_UniffiConverterRustBuffer):
+ @classmethod
+ def check_lower(cls, value):
+ if value is not None:
+ _UniffiFfiConverterTypeScrollBy.check_lower(value)
+
+ @classmethod
+ def write(cls, value, buf):
+ if value is None:
+ buf.write_u8(0)
+ return
+
+ buf.write_u8(1)
+ _UniffiFfiConverterTypeScrollBy.write(value, buf)
+
+ @classmethod
+ def read(cls, buf):
+ flag = buf.read_u8()
+ if flag == 0:
+ return None
+ elif flag == 1:
+ return _UniffiFfiConverterTypeScrollBy.read(buf)
+ else:
+ raise InternalError("Unexpected flag byte for optional type")
+
+@dataclass
+class ScrollInput:
+ def __init__(self, *, x:float, y:float, direction:ScrollDirection, scope:DesktopScope, session:typing.Optional[str], by:typing.Optional[ScrollBy], amount:typing.Optional[int]):
+ self.x = x
+ self.y = y
+ self.direction = direction
+ self.scope = scope
+ self.session = session
+ self.by = by
+ self.amount = amount
+
+
+
+
+ def __str__(self):
+ return "ScrollInput(x={}, y={}, direction={}, scope={}, session={}, by={}, amount={})".format(self.x, self.y, self.direction, self.scope, self.session, self.by, self.amount)
+ def __eq__(self, other):
+ if self.x != other.x:
+ return False
+ if self.y != other.y:
+ return False
+ if self.direction != other.direction:
+ return False
+ if self.scope != other.scope:
+ return False
+ if self.session != other.session:
+ return False
+ if self.by != other.by:
+ return False
+ if self.amount != other.amount:
+ return False
+ return True
+
+class _UniffiFfiConverterTypeScrollInput(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ return ScrollInput(
+ x=_UniffiFfiConverterFloat64.read(buf),
+ y=_UniffiFfiConverterFloat64.read(buf),
+ direction=_UniffiFfiConverterTypeScrollDirection.read(buf),
+ scope=_UniffiFfiConverterTypeDesktopScope.read(buf),
+ session=_UniffiFfiConverterOptionalString.read(buf),
+ by=_UniffiFfiConverterOptionalTypeScrollBy.read(buf),
+ amount=_UniffiFfiConverterOptionalUInt64.read(buf),
+ )
+
+ @staticmethod
+ def check_lower(value):
+ _UniffiFfiConverterFloat64.check_lower(value.x)
+ _UniffiFfiConverterFloat64.check_lower(value.y)
+ _UniffiFfiConverterTypeScrollDirection.check_lower(value.direction)
+ _UniffiFfiConverterTypeDesktopScope.check_lower(value.scope)
+ _UniffiFfiConverterOptionalString.check_lower(value.session)
+ _UniffiFfiConverterOptionalTypeScrollBy.check_lower(value.by)
+ _UniffiFfiConverterOptionalUInt64.check_lower(value.amount)
+
+ @staticmethod
+ def write(value, buf):
+ _UniffiFfiConverterFloat64.write(value.x, buf)
+ _UniffiFfiConverterFloat64.write(value.y, buf)
+ _UniffiFfiConverterTypeScrollDirection.write(value.direction, buf)
+ _UniffiFfiConverterTypeDesktopScope.write(value.scope, buf)
+ _UniffiFfiConverterOptionalString.write(value.session, buf)
+ _UniffiFfiConverterOptionalTypeScrollBy.write(value.by, buf)
+ _UniffiFfiConverterOptionalUInt64.write(value.amount, buf)
+
+
+
+
+
+
+class CaptureScope(enum.Enum):
+
+ AUTO = 0
+
+ WINDOW = 1
+
+ DESKTOP = 2
+
+
+
+class _UniffiFfiConverterTypeCaptureScope(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ variant = buf.read_i32()
+ if variant == 1:
+ return CaptureScope.AUTO
+ if variant == 2:
+ return CaptureScope.WINDOW
+ if variant == 3:
+ return CaptureScope.DESKTOP
+ raise InternalError("Raw enum value doesn't match any cases")
+
+ @staticmethod
+ def check_lower(value):
+ if value == CaptureScope.AUTO:
+ return
+ if value == CaptureScope.WINDOW:
+ return
+ if value == CaptureScope.DESKTOP:
+ return
+ raise ValueError(value)
+
+ @staticmethod
+ def write(value, buf):
+ if value == CaptureScope.AUTO:
+ buf.write_i32(1)
+ if value == CaptureScope.WINDOW:
+ buf.write_i32(2)
+ if value == CaptureScope.DESKTOP:
+ buf.write_i32(3)
+
+
+
+
+
+
+
+
+class EffectiveScope(enum.Enum):
+
+ WINDOW = 0
+
+ DESKTOP = 1
+
+
+
+class _UniffiFfiConverterTypeEffectiveScope(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ variant = buf.read_i32()
+ if variant == 1:
+ return EffectiveScope.WINDOW
+ if variant == 2:
+ return EffectiveScope.DESKTOP
+ raise InternalError("Raw enum value doesn't match any cases")
+
+ @staticmethod
+ def check_lower(value):
+ if value == EffectiveScope.WINDOW:
+ return
+ if value == EffectiveScope.DESKTOP:
+ return
+ raise ValueError(value)
+
+ @staticmethod
+ def write(value, buf):
+ if value == EffectiveScope.WINDOW:
+ buf.write_i32(1)
+ if value == EffectiveScope.DESKTOP:
+ buf.write_i32(2)
+
+
+
+class _UniffiFfiConverterOptionalTypeEscalationReason(_UniffiConverterRustBuffer):
+ @classmethod
+ def check_lower(cls, value):
+ if value is not None:
+ _UniffiFfiConverterTypeEscalationReason.check_lower(value)
+
+ @classmethod
+ def write(cls, value, buf):
+ if value is None:
+ buf.write_u8(0)
+ return
+
+ buf.write_u8(1)
+ _UniffiFfiConverterTypeEscalationReason.write(value, buf)
+
+ @classmethod
+ def read(cls, buf):
+ flag = buf.read_u8()
+ if flag == 0:
+ return None
+ elif flag == 1:
+ return _UniffiFfiConverterTypeEscalationReason.read(buf)
+ else:
+ raise InternalError("Unexpected flag byte for optional type")
+
+@dataclass
+class SessionStateOutput:
+ """
+ Successful structured result shared by session state and escalation tools.
+"""
+ def __init__(self, *, session:str, capture_scope:CaptureScope, effective_scope:EffectiveScope, desktop_unlocked:bool, escalation_reason:typing.Optional[EscalationReason], escalation_detail:typing.Optional[str]):
+ self.session = session
+ self.capture_scope = capture_scope
+ self.effective_scope = effective_scope
+ self.desktop_unlocked = desktop_unlocked
+ self.escalation_reason = escalation_reason
+ self.escalation_detail = escalation_detail
+
+
+
+
+ def __str__(self):
+ return "SessionStateOutput(session={}, capture_scope={}, effective_scope={}, desktop_unlocked={}, escalation_reason={}, escalation_detail={})".format(self.session, self.capture_scope, self.effective_scope, self.desktop_unlocked, self.escalation_reason, self.escalation_detail)
+ def __eq__(self, other):
+ if self.session != other.session:
+ return False
+ if self.capture_scope != other.capture_scope:
+ return False
+ if self.effective_scope != other.effective_scope:
+ return False
+ if self.desktop_unlocked != other.desktop_unlocked:
+ return False
+ if self.escalation_reason != other.escalation_reason:
+ return False
+ if self.escalation_detail != other.escalation_detail:
+ return False
+ return True
+
+class _UniffiFfiConverterTypeSessionStateOutput(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ return SessionStateOutput(
+ session=_UniffiFfiConverterString.read(buf),
+ capture_scope=_UniffiFfiConverterTypeCaptureScope.read(buf),
+ effective_scope=_UniffiFfiConverterTypeEffectiveScope.read(buf),
+ desktop_unlocked=_UniffiFfiConverterBoolean.read(buf),
+ escalation_reason=_UniffiFfiConverterOptionalTypeEscalationReason.read(buf),
+ escalation_detail=_UniffiFfiConverterOptionalString.read(buf),
+ )
+
+ @staticmethod
+ def check_lower(value):
+ _UniffiFfiConverterString.check_lower(value.session)
+ _UniffiFfiConverterTypeCaptureScope.check_lower(value.capture_scope)
+ _UniffiFfiConverterTypeEffectiveScope.check_lower(value.effective_scope)
+ _UniffiFfiConverterBoolean.check_lower(value.desktop_unlocked)
+ _UniffiFfiConverterOptionalTypeEscalationReason.check_lower(value.escalation_reason)
+ _UniffiFfiConverterOptionalString.check_lower(value.escalation_detail)
+
+ @staticmethod
+ def write(value, buf):
+ _UniffiFfiConverterString.write(value.session, buf)
+ _UniffiFfiConverterTypeCaptureScope.write(value.capture_scope, buf)
+ _UniffiFfiConverterTypeEffectiveScope.write(value.effective_scope, buf)
+ _UniffiFfiConverterBoolean.write(value.desktop_unlocked, buf)
+ _UniffiFfiConverterOptionalTypeEscalationReason.write(value.escalation_reason, buf)
+ _UniffiFfiConverterOptionalString.write(value.escalation_detail, buf)
+
+class _UniffiFfiConverterOptionalTypeCaptureScope(_UniffiConverterRustBuffer):
+ @classmethod
+ def check_lower(cls, value):
+ if value is not None:
+ _UniffiFfiConverterTypeCaptureScope.check_lower(value)
+
+ @classmethod
+ def write(cls, value, buf):
+ if value is None:
+ buf.write_u8(0)
+ return
+
+ buf.write_u8(1)
+ _UniffiFfiConverterTypeCaptureScope.write(value, buf)
+
+ @classmethod
+ def read(cls, buf):
+ flag = buf.read_u8()
+ if flag == 0:
+ return None
+ elif flag == 1:
+ return _UniffiFfiConverterTypeCaptureScope.read(buf)
+ else:
+ raise InternalError("Unexpected flag byte for optional type")
+
+@dataclass
+class StartSessionInput:
+ def __init__(self, *, session:str, capture_scope:typing.Optional[CaptureScope]):
+ self.session = session
+ self.capture_scope = capture_scope
+
+
+
+
+ def __str__(self):
+ return "StartSessionInput(session={}, capture_scope={})".format(self.session, self.capture_scope)
+ def __eq__(self, other):
+ if self.session != other.session:
+ return False
+ if self.capture_scope != other.capture_scope:
+ return False
+ return True
+
+class _UniffiFfiConverterTypeStartSessionInput(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ return StartSessionInput(
+ session=_UniffiFfiConverterString.read(buf),
+ capture_scope=_UniffiFfiConverterOptionalTypeCaptureScope.read(buf),
+ )
+
+ @staticmethod
+ def check_lower(value):
+ _UniffiFfiConverterString.check_lower(value.session)
+ _UniffiFfiConverterOptionalTypeCaptureScope.check_lower(value.capture_scope)
+
+ @staticmethod
+ def write(value, buf):
+ _UniffiFfiConverterString.write(value.session, buf)
+ _UniffiFfiConverterOptionalTypeCaptureScope.write(value.capture_scope, buf)
+
+@dataclass
+class StartSessionOutput:
+ """
+ Successful structured result returned by `start_session`.
+"""
+ def __init__(self, *, state:SessionStateOutput, active:bool, revived:bool):
+ self.state = state
+ self.active = active
+ self.revived = revived
+
+
+
+
+ def __str__(self):
+ return "StartSessionOutput(state={}, active={}, revived={})".format(self.state, self.active, self.revived)
+ def __eq__(self, other):
+ if self.state != other.state:
+ return False
+ if self.active != other.active:
+ return False
+ if self.revived != other.revived:
+ return False
+ return True
+
+class _UniffiFfiConverterTypeStartSessionOutput(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ return StartSessionOutput(
+ state=_UniffiFfiConverterTypeSessionStateOutput.read(buf),
+ active=_UniffiFfiConverterBoolean.read(buf),
+ revived=_UniffiFfiConverterBoolean.read(buf),
+ )
+
+ @staticmethod
+ def check_lower(value):
+ _UniffiFfiConverterTypeSessionStateOutput.check_lower(value.state)
+ _UniffiFfiConverterBoolean.check_lower(value.active)
+ _UniffiFfiConverterBoolean.check_lower(value.revived)
+
+ @staticmethod
+ def write(value, buf):
+ _UniffiFfiConverterTypeSessionStateOutput.write(value.state, buf)
+ _UniffiFfiConverterBoolean.write(value.active, buf)
+ _UniffiFfiConverterBoolean.write(value.revived, buf)
+
+@dataclass
+class TypeTextInput:
+ def __init__(self, *, text:str, scope:DesktopScope, session:typing.Optional[str]):
+ self.text = text
+ self.scope = scope
+ self.session = session
+
+
+
+
+ def __str__(self):
+ return "TypeTextInput(text={}, scope={}, session={})".format(self.text, self.scope, self.session)
+ def __eq__(self, other):
+ if self.text != other.text:
+ return False
+ if self.scope != other.scope:
+ return False
+ if self.session != other.session:
+ return False
+ return True
+
+class _UniffiFfiConverterTypeTypeTextInput(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ return TypeTextInput(
+ text=_UniffiFfiConverterString.read(buf),
+ scope=_UniffiFfiConverterTypeDesktopScope.read(buf),
+ session=_UniffiFfiConverterOptionalString.read(buf),
+ )
+
+ @staticmethod
+ def check_lower(value):
+ _UniffiFfiConverterString.check_lower(value.text)
+ _UniffiFfiConverterTypeDesktopScope.check_lower(value.scope)
+ _UniffiFfiConverterOptionalString.check_lower(value.session)
+
+ @staticmethod
+ def write(value, buf):
+ _UniffiFfiConverterString.write(value.text, buf)
+ _UniffiFfiConverterTypeDesktopScope.write(value.scope, buf)
+ _UniffiFfiConverterOptionalString.write(value.session, buf)
+
+
+
+
+
+
+class Platform(enum.Enum):
+
+ MACOS = 0
+
+ WINDOWS = 1
+
+ LINUX = 2
+
+
+
+class _UniffiFfiConverterTypePlatform(_UniffiConverterRustBuffer):
+ @staticmethod
+ def read(buf):
+ variant = buf.read_i32()
+ if variant == 1:
+ return Platform.MACOS
+ if variant == 2:
+ return Platform.WINDOWS
+ if variant == 3:
+ return Platform.LINUX
+ raise InternalError("Raw enum value doesn't match any cases")
+
+ @staticmethod
+ def check_lower(value):
+ if value == Platform.MACOS:
+ return
+ if value == Platform.WINDOWS:
+ return
+ if value == Platform.LINUX:
+ return
+ raise ValueError(value)
+
+ @staticmethod
+ def write(value, buf):
+ if value == Platform.MACOS:
+ buf.write_i32(1)
+ if value == Platform.WINDOWS:
+ buf.write_i32(2)
+ if value == Platform.LINUX:
+ buf.write_i32(3)
+
+
+
+class _UniffiFfiConverterUInt8(_UniffiConverterPrimitiveInt):
+ CLASS_NAME = "u8"
+ VALUE_MIN = 0
+ VALUE_MAX = 2**8
+
+ @staticmethod
+ def read(buf):
+ return buf.read_u8()
+
+ @staticmethod
+ def write(value, buf):
+ buf.write_u8(value)
+
+__all__ = [
+ "InternalError",
+ "DesktopScope",
+ "ClickButton",
+ "EscalationReason",
+ "ScrollDirection",
+ "ScrollBy",
+ "CaptureScope",
+ "EffectiveScope",
+ "Platform",
+ "ClickInput",
+ "DragInput",
+ "EndSessionInput",
+ "EndSessionOutput",
+ "EscalateSessionInput",
+ "GetCursorPositionInput",
+ "GetDesktopStateInput",
+ "GetScreenSizeInput",
+ "GetSessionStateInput",
+ "HotkeyInput",
+ "MoveCursorInput",
+ "PressKeyInput",
+ "ScrollInput",
+ "SessionStateOutput",
+ "StartSessionInput",
+ "StartSessionOutput",
+ "TypeTextInput",
+]
diff --git a/libs/cua-driver/python/tests/test_build_wheel.py b/libs/cua-driver/python/tests/test_build_wheel.py
index fac7c6d79a..8ad14a27e3 100644
--- a/libs/cua-driver/python/tests/test_build_wheel.py
+++ b/libs/cua-driver/python/tests/test_build_wheel.py
@@ -23,6 +23,22 @@ def test_wheel_tags_are_platform_specific():
assert build_wheel.get_wheel_tag("windows", "arm64") == "py3-none-win_arm64"
+def test_release_archives_include_cli_and_uniffi_library():
+ build_wheel = load_build_wheel_module()
+
+ _, darwin_files = build_wheel.get_release_url("1.2.3", "darwin", "universal")
+ _, linux_files = build_wheel.get_release_url("1.2.3", "linux", "x86_64")
+ _, windows_files = build_wheel.get_release_url("1.2.3", "windows", "arm64")
+
+ assert darwin_files == ["cua-driver", "libcua_driver_sdk.dylib"]
+ assert linux_files == ["cua-driver", "libcua_driver_sdk.so"]
+ assert windows_files == [
+ "cua-driver.exe",
+ "cua-driver-uia.exe",
+ "cua_driver_sdk.dll",
+ ]
+
+
def test_license_metadata_stays_legacy_upload_compatible():
pyproject = Path(__file__).resolve().parents[1] / "pyproject.toml"
pyproject_text = pyproject.read_text()
diff --git a/libs/cua-driver/python/tests/test_uniffi_loader.py b/libs/cua-driver/python/tests/test_uniffi_loader.py
new file mode 100644
index 0000000000..8a4d1d2c4b
--- /dev/null
+++ b/libs/cua-driver/python/tests/test_uniffi_loader.py
@@ -0,0 +1,112 @@
+from __future__ import annotations
+
+import importlib.util
+import json
+import os
+import platform
+import socket
+import tempfile
+import threading
+import unittest
+from pathlib import Path
+
+
+def _library_name() -> str:
+ if os.name == "nt":
+ return "cua_driver_sdk.dll"
+ if platform.system() == "Darwin":
+ return "libcua_driver_sdk.dylib"
+ return "libcua_driver_sdk.so"
+
+
+LIBRARY = Path(__file__).parents[1] / "src" / "cua_driver" / _library_name()
+
+
[email protected](LIBRARY.exists(), "host-native UniFFI library is not staged")
[email protected](os.name == "nt", "Unix socket fixture")
+class SdkLoaderTests(unittest.TestCase):
+ def test_generated_python_sdk_calls_the_rust_daemon_interface(self) -> None:
+ import cua_driver
+ from cua_driver import (
+ CuaDriver,
+ EffectiveScope,
+ GetDesktopStateInput,
+ StartSessionOutput,
+ )
+
+ self.assertIsNotNone(EffectiveScope)
+ self.assertIsNotNone(StartSessionOutput)
+ self.assertIs(cua_driver.CuaDriver, CuaDriver)
+ self.assertFalse(hasattr(cua_driver, "AsyncCuaDriver"))
+ self.assertFalse(hasattr(cua_driver, "StdioMcpTransport"))
+ self.assertIsNone(importlib.util.find_spec("cua_driver.sdk"))
+ self.assertIsNone(importlib.util.find_spec("cua_driver.native"))
+
+ with tempfile.TemporaryDirectory() as directory:
+ socket_path = str(Path(directory) / "driver.sock")
+ listener = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ listener.bind(socket_path)
+ listener.listen(1)
+ captured: list[dict[str, object]] = []
+
+ def serve() -> None:
+ connection, _ = listener.accept()
+ with connection:
+ line = connection.makefile("r", encoding="utf-8").readline()
+ captured.append(json.loads(line))
+ response = {
+ "ok": True,
+ "result": {
+ "content": [
+ {"type": "text", "text": "python ffi"},
+ {
+ "type": "image",
+ "mimeType": "image/png",
+ "data": "cG5n",
+ },
+ ],
+ "structuredContent": {"verified": True},
+ "isError": False,
+ },
+ }
+ connection.sendall((json.dumps(response) + "\n").encode())
+
+ server = threading.Thread(target=serve)
+ server.start()
+ driver = CuaDriver.connect(socket_path)
+ expected_methods = {
+ "start_session",
+ "escalate_session",
+ "get_session_state",
+ "end_session",
+ "get_desktop_state",
+ "get_screen_size",
+ "get_cursor_position",
+ "move_cursor",
+ "click",
+ "drag",
+ "scroll",
+ "type_text",
+ "press_key",
+ "hotkey",
+ }
+ self.assertTrue(all(hasattr(driver, name) for name in expected_methods))
+ result = driver.get_desktop_state(
+ GetDesktopStateInput(session="python-run", screenshot_out_file=None)
+ )
+ server.join(timeout=5)
+ listener.close()
+
+ self.assertEqual(result.text, "python ffi")
+ self.assertEqual(result.images[0].mime_type, "image/png")
+ self.assertTrue(result.verified)
+ self.assertEqual(captured[0]["name"], "get_desktop_state")
+ self.assertEqual(captured[0]["args"], {"session": "python-run"})
+
+
+if os.environ.get("CUA_DRIVER_REQUIRE_UNIFFI") == "1" and not LIBRARY.exists():
+ raise RuntimeError(f"required staged UniFFI library is missing: {LIBRARY}")
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/libs/cua-driver/rust/Cargo.lock b/libs/cua-driver/rust/Cargo.lock
index 89e7f85975..1021d9bdb5 100644
--- a/libs/cua-driver/rust/Cargo.lock
+++ b/libs/cua-driver/rust/Cargo.lock
@@ -56,6 +56,12 @@ dependencies = [
"yansi-term",
]
+[[package]]
+name = "anstyle"
+version = "1.0.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
+
[[package]]
name = "anyhow"
version = "1.0.102"
@@ -107,6 +113,48 @@ dependencies = [
"zbus",
]
+[[package]]
+name = "askama"
+version = "0.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f75363874b771be265f4ffe307ca705ef6f3baa19011c149da8674a87f1b75c4"
+dependencies = [
+ "askama_derive",
+ "itoa",
+ "percent-encoding",
+ "serde",
+ "serde_json",
+]
+
+[[package]]
+name = "askama_derive"
+version = "0.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "129397200fe83088e8a68407a8e2b1f826cf0086b21ccdb866a722c8bcd3a94f"
+dependencies = [
+ "askama_parser",
+ "basic-toml",
+ "memchr",
+ "proc-macro2",
+ "quote",
+ "rustc-hash 2.1.3",
+ "serde",
+ "serde_derive",
+ "syn",
+]
+
+[[package]]
+name = "askama_parser"
+version = "0.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d6ab5630b3d5eaf232620167977f95eb51f3432fc76852328774afbd242d4358"
+dependencies = [
+ "memchr",
+ "serde",
+ "serde_derive",
+ "winnow 0.7.15",
+]
+
[[package]]
name = "async-broadcast"
version = "0.7.2"
@@ -307,6 +355,15 @@ version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
+[[package]]
+name = "basic-toml"
+version = "0.1.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ba62675e8242a4c4e806d12f11d136e626e6c8361d6b829310732241652a178a"
+dependencies = [
+ "serde",
+]
+
[[package]]
name = "bindgen"
version = "0.69.5"
@@ -323,7 +380,7 @@ dependencies = [
"proc-macro2",
"quote",
"regex",
- "rustc-hash",
+ "rustc-hash 1.1.0",
"shlex",
"syn",
]
@@ -463,6 +520,38 @@ dependencies = [
"tracing",
]
+[[package]]
+name = "camino"
+version = "1.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5f2d30e4173c4026932d51d31d6b0613b1fd3014bf3f9f8943d4ba139c437ba0"
+dependencies = [
+ "serde_core",
+]
+
+[[package]]
+name = "cargo-platform"
+version = "0.1.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e35af189006b9c0f00a064685c727031e3ed2d8020f7ba284d78cc2671bd36ea"
+dependencies = [
+ "serde",
+]
+
+[[package]]
+name = "cargo_metadata"
+version = "0.19.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dd5eb614ed4c27c5d706420e4320fbe3216ab31fa1c33cd8246ac36dae4479ba"
+dependencies = [
+ "camino",
+ "cargo-platform",
+ "semver",
+ "serde",
+ "serde_json",
+ "thiserror 2.0.18",
+]
+
[[package]]
name = "cc"
version = "1.2.62"
@@ -543,6 +632,45 @@ dependencies = [
"libloading",
]
+[[package]]
+name = "clap"
+version = "4.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1ddb117e43bbf7dacf0a4190fef4d345b9bad68dfc649cb349e7d17d28428e51"
+dependencies = [
+ "clap_builder",
+ "clap_derive",
+]
+
+[[package]]
+name = "clap_builder"
+version = "4.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f"
+dependencies = [
+ "anstyle",
+ "clap_lex",
+ "strsim",
+]
+
+[[package]]
+name = "clap_derive"
+version = "4.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f2ce8604710f6733aa641a2b3731eaa1e8b3d9973d5e3565da11800813f997a9"
+dependencies = [
+ "heck",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "clap_lex"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9"
+
[[package]]
name = "cobs"
version = "0.3.0"
@@ -725,6 +853,7 @@ dependencies = [
"anyhow",
"async-trait",
"base64",
+ "cua-driver-contract",
"cua-driver-core",
"cua-driver-testkit",
"cursor-overlay",
@@ -752,12 +881,30 @@ dependencies = [
"windows 0.61.3",
]
+[[package]]
+name = "cua-driver-bindgen"
+version = "0.10.0"
+dependencies = [
+ "uniffi",
+]
+
+[[package]]
+name = "cua-driver-contract"
+version = "0.10.0"
+dependencies = [
+ "schemars",
+ "serde",
+ "serde_json",
+ "uniffi",
+]
+
[[package]]
name = "cua-driver-core"
version = "0.10.0"
dependencies = [
"anyhow",
"async-trait",
+ "cua-driver-contract",
"futures-util",
"image",
"libc",
@@ -777,6 +924,19 @@ dependencies = [
"windows 0.58.0",
]
+[[package]]
+name = "cua-driver-sdk"
+version = "0.10.0"
+dependencies = [
+ "cua-driver-contract",
+ "cua-driver-core",
+ "serde",
+ "serde_json",
+ "tempfile",
+ "thiserror 1.0.69",
+ "uniffi",
+]
+
[[package]]
name = "cua-driver-testkit"
version = "0.10.0"
@@ -908,6 +1068,12 @@ version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2"
+[[package]]
+name = "dyn-clone"
+version = "1.0.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555"
+
[[package]]
name = "either"
version = "1.16.0"
@@ -1201,6 +1367,15 @@ dependencies = [
"num",
]
+[[package]]
+name = "fs-err"
+version = "2.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "88a41f105fe1d5b6b34b2055e3dc59bb79b46b48b2040b9e6c7b4b5de097aa41"
+dependencies = [
+ "autocfg",
+]
+
[[package]]
name = "funty"
version = "2.0.0"
@@ -1385,6 +1560,17 @@ dependencies = [
"regex-syntax",
]
+[[package]]
+name = "goblin"
+version = "0.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1b363a30c165f666402fe6a3024d3bec7ebc898f96a4a23bd1c99f8dbf3f4f47"
+dependencies = [
+ "log",
+ "plain",
+ "scroll",
+]
+
[[package]]
name = "hashbrown"
version = "0.15.5"
@@ -2350,6 +2536,12 @@ version = "0.3.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e"
+[[package]]
+name = "plain"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
+
[[package]]
name = "platform-linux"
version = "0.10.0"
@@ -2361,6 +2553,7 @@ dependencies = [
"base64",
"calloop",
"crossbeam-channel",
+ "cua-driver-contract",
"cua-driver-core",
"cursor-overlay",
"dirs",
@@ -2402,6 +2595,7 @@ dependencies = [
"block2",
"core-foundation",
"core-graphics",
+ "cua-driver-contract",
"cua-driver-core",
"cursor-overlay",
"foreign-types 0.5.0",
@@ -2432,6 +2626,7 @@ dependencies = [
"anyhow",
"async-trait",
"base64",
+ "cua-driver-contract",
"cua-driver-core",
"cursor-overlay",
"image",
@@ -2821,6 +3016,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
+[[package]]
+name = "rustc-hash"
+version = "2.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d"
+
[[package]]
name = "rustc_version"
version = "0.4.1"
@@ -2917,6 +3118,31 @@ dependencies = [
"windows-sys 0.61.2",
]
+[[package]]
+name = "schemars"
+version = "1.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a2b42f36aa1cd011945615b92222f6bf73c599a102a300334cd7f8dbeec726cc"
+dependencies = [
+ "dyn-clone",
+ "ref-cast",
+ "schemars_derive",
+ "serde",
+ "serde_json",
+]
+
+[[package]]
+name = "schemars_derive"
+version = "1.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7d115b50f4aaeea07e79c1912f645c7513d81715d0420f8bc77a18c6260b307f"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "serde_derive_internals",
+ "syn",
+]
+
[[package]]
name = "scopeguard"
version = "1.2.0"
@@ -2933,6 +3159,26 @@ dependencies = [
"apple-metal",
]
+[[package]]
+name = "scroll"
+version = "0.12.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6ab8598aa408498679922eff7fa985c25d58a90771bd6be794434c5277eab1a6"
+dependencies = [
+ "scroll_derive",
+]
+
+[[package]]
+name = "scroll_derive"
+version = "0.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1783eabc414609e28a5ba76aee5ddd52199f7107a0b24c2e9746a1ecc34a683d"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
[[package]]
name = "security-framework"
version = "3.7.0"
@@ -2961,6 +3207,10 @@ name = "semver"
version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
+dependencies = [
+ "serde",
+ "serde_core",
+]
[[package]]
name = "serde"
@@ -2992,6 +3242,17 @@ dependencies = [
"syn",
]
+[[package]]
+name = "serde_derive_internals"
+version = "0.29.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
[[package]]
name = "serde_json"
version = "1.0.149"
@@ -3140,6 +3401,12 @@ version = "1.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
+[[package]]
+name = "smawk"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e8e2fb0f499abb4d162f2bedad68f5ef91a1682b5a03596ddb67efd37768d100"
+
[[package]]
name = "socket2"
version = "0.6.3"
@@ -3177,6 +3444,12 @@ dependencies = [
"float-cmp",
]
+[[package]]
+name = "strsim"
+version = "0.11.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
+
[[package]]
name = "subtle"
version = "2.6.1"
@@ -3263,6 +3536,15 @@ dependencies = [
"windows-sys 0.61.2",
]
+[[package]]
+name = "textwrap"
+version = "0.16.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c13547615a44dc9c452a8a534638acdf07120d4b6847c8178705da06306a3057"
+dependencies = [
+ "smawk",
+]
+
[[package]]
name = "thiserror"
version = "1.0.69"
@@ -3691,6 +3973,127 @@ version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
+[[package]]
+name = "uniffi"
+version = "0.31.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b8c6dec3fc6645f71a16a3fa9ff57991028153bd194ca97f4b55e610c73ce66a"
+dependencies = [
+ "anyhow",
+ "camino",
+ "cargo_metadata",
+ "clap",
+ "uniffi_bindgen",
+ "uniffi_core",
+ "uniffi_macros",
+ "uniffi_pipeline",
+]
+
+[[package]]
+name = "uniffi_bindgen"
+version = "0.31.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4ed0150801958d4825da56a41c71f000a457ac3a4613fa9647df78ac4b6b6881"
+dependencies = [
+ "anyhow",
+ "askama",
+ "camino",
+ "cargo_metadata",
+ "fs-err",
+ "glob",
+ "goblin",
+ "heck",
+ "indexmap",
+ "once_cell",
+ "serde",
+ "tempfile",
+ "textwrap",
+ "toml",
+ "uniffi_internal_macros",
+ "uniffi_meta",
+ "uniffi_pipeline",
+ "uniffi_udl",
+]
+
+[[package]]
+name = "uniffi_core"
+version = "0.31.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b0ef62e69762fbb9386dcb6c87cd3dd05d525fa8a3a579a290892e60ddbda47e"
+dependencies = [
+ "anyhow",
+ "bytes",
+ "once_cell",
+ "static_assertions",
+]
+
+[[package]]
+name = "uniffi_internal_macros"
+version = "0.31.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "98f51ebca0d9a4b2aa6c644d5ede45c56f73906b96403c08a1985e75ccb64a01"
+dependencies = [
+ "anyhow",
+ "indexmap",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "uniffi_macros"
+version = "0.31.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "db9d12529f1223d014fd501e5f29ca0884d15d6ed5ddddd9f506e55350327dc3"
+dependencies = [
+ "camino",
+ "fs-err",
+ "once_cell",
+ "proc-macro2",
+ "quote",
+ "serde",
+ "syn",
+ "toml",
+ "uniffi_meta",
+]
+
+[[package]]
+name = "uniffi_meta"
+version = "0.31.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9df6d413db2827c68588f8149d30d49b71d540d46539e435b23a7f7dbd4d4f86"
+dependencies = [
+ "anyhow",
+ "siphasher",
+ "uniffi_internal_macros",
+ "uniffi_pipeline",
+]
+
+[[package]]
+name = "uniffi_pipeline"
+version = "0.31.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a806dddc8208f22efd7e95a5cdf88ed43d0f3271e8f63b47e757a8bbdb43b63a"
+dependencies = [
+ "anyhow",
+ "heck",
+ "indexmap",
+ "tempfile",
+ "uniffi_internal_macros",
+]
+
+[[package]]
+name = "uniffi_udl"
+version = "0.31.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0d1a7339539bf6f6fa3e9b534dece13f778bda2d54b1a6d4e40b4d6090ac26e7"
+dependencies = [
+ "anyhow",
+ "textwrap",
+ "uniffi_meta",
+ "weedle2",
+]
+
[[package]]
name = "unsafe-libyaml"
version = "0.2.11"
@@ -4056,6 +4459,15 @@ dependencies = [
"rustls-pki-types",
]
+[[package]]
+name = "weedle2"
+version = "5.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "998d2c24ec099a87daf9467808859f9d82b61f1d9c9701251aea037f514eae0e"
+dependencies = [
+ "nom 7.1.3",
+]
+
[[package]]
name = "winapi"
version = "0.3.9"
diff --git a/libs/cua-driver/rust/Cargo.toml b/libs/cua-driver/rust/Cargo.toml
index a6364c00f9..0b9aee6878 100644
--- a/libs/cua-driver/rust/Cargo.toml
+++ b/libs/cua-driver/rust/Cargo.toml
@@ -2,6 +2,9 @@
resolver = "2"
members = [
"crates/cua-driver",
+ "crates/cua-driver-contract",
+ "crates/cua-driver-sdk",
+ "crates/cua-driver-bindgen",
"crates/cua-driver-testkit",
"crates/cua-driver-uia",
"crates/cua-driver-core",
@@ -30,3 +33,4 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
base64 = "0.22"
uuid = { version = "1", features = ["v4"] }
image = { version = "0.25", default-features = false, features = ["png", "jpeg"] }
+uniffi = "=0.31.0"
diff --git a/libs/cua-driver/rust/crates/cua-driver-bindgen/Cargo.toml b/libs/cua-driver/rust/crates/cua-driver-bindgen/Cargo.toml
new file mode 100644
index 0000000000..3656a49662
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver-bindgen/Cargo.toml
@@ -0,0 +1,15 @@
+[package]
+name = "cua-driver-bindgen"
+version.workspace = true
+edition.workspace = true
+authors.workspace = true
+license.workspace = true
+repository.workspace = true
+publish = false
+
+[[bin]]
+name = "cua-driver-bindgen"
+path = "src/main.rs"
+
+[dependencies]
+uniffi = { workspace = true, features = ["cli"] }
diff --git a/libs/cua-driver/rust/crates/cua-driver-bindgen/src/main.rs b/libs/cua-driver/rust/crates/cua-driver-bindgen/src/main.rs
new file mode 100644
index 0000000000..a01b547061
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver-bindgen/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ uniffi::uniffi_bindgen_main();
+}
diff --git a/libs/cua-driver/rust/crates/cua-driver-contract/Cargo.toml b/libs/cua-driver/rust/crates/cua-driver-contract/Cargo.toml
new file mode 100644
index 0000000000..d673387918
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver-contract/Cargo.toml
@@ -0,0 +1,15 @@
+[package]
+name = "cua-driver-contract"
+version.workspace = true
+edition.workspace = true
+publish = false
+
+[[bin]]
+name = "cua-contract-gen"
+path = "src/bin/cua-contract-gen.rs"
+
+[dependencies]
+serde = { workspace = true }
+serde_json = { workspace = true }
+schemars = "1.2.1"
+uniffi.workspace = true
diff --git a/libs/cua-driver/rust/crates/cua-driver-contract/src/bin/cua-contract-gen.rs b/libs/cua-driver/rust/crates/cua-driver-contract/src/bin/cua-contract-gen.rs
new file mode 100644
index 0000000000..08a4d864f1
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver-contract/src/bin/cua-contract-gen.rs
@@ -0,0 +1,108 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 Cua AI, Inc.
+
+use cua_driver_contract::manifest;
+use std::fs;
+use std::path::{Path, PathBuf};
+
+fn main() {
+ if let Err(error) = run() {
+ eprintln!("cua-contract-gen: {error}");
+ std::process::exit(1);
+ }
+}
+
+fn run() -> Result<(), String> {
+ let args: Vec<String> = std::env::args().skip(1).collect();
+ let check = args.iter().any(|arg| arg == "--check");
+ let target = args
+ .iter()
+ .find(|arg| !arg.starts_with('-'))
+ .map(String::as_str)
+ .unwrap_or("all");
+ if !matches!(target, "all" | "manifest") {
+ return Err("usage: cua-contract-gen [all|manifest] [--check]".into());
+ }
+
+ let mut contents = serde_json::to_string_pretty(&manifest()).map_err(|e| e.to_string())?;
+ contents.push('\n');
+ write_or_check(
+ &driver_root()?.join("contract/manifest.json"),
+ &contents,
+ check,
+ )
+}
+
+fn driver_root() -> Result<PathBuf, String> {
+ let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
+ crate_dir
+ .parent()
+ .and_then(Path::parent)
+ .and_then(Path::parent)
+ .map(Path::to_path_buf)
+ .ok_or_else(|| "could not resolve libs/cua-driver root".into())
+}
+
+fn write_or_check(path: &Path, expected: &str, check: bool) -> Result<(), String> {
+ if check {
+ let actual = fs::read_to_string(path)
+ .map_err(|error| format!("{} is missing: {error}", path.display()))?;
+ if actual != expected {
+ return Err(format!(
+ "{} is stale; run `cargo run -p cua-driver-contract --bin cua-contract-gen -- all`",
+ path.display()
+ ));
+ }
+ println!("checked {}", path.display());
+ return Ok(());
+ }
+
+ if path.is_symlink() {
+ return Err(format!(
+ "refusing to overwrite generated symlink {}",
+ path.display()
+ ));
+ }
+ let parent = path
+ .parent()
+ .ok_or_else(|| format!("{} has no parent", path.display()))?;
+ fs::create_dir_all(parent).map_err(|error| error.to_string())?;
+ let temporary = parent.join(format!(
+ ".{}.tmp.{}",
+ path.file_name().unwrap_or_default().to_string_lossy(),
+ std::process::id()
+ ));
+ fs::write(&temporary, expected).map_err(|error| error.to_string())?;
+
+ if path.exists() {
+ let backup = parent.join(format!(
+ ".{}.bak.{}",
+ path.file_name().unwrap_or_default().to_string_lossy(),
+ std::process::id()
+ ));
+ fs::rename(path, &backup).map_err(|error| error.to_string())?;
+ if let Err(error) = fs::rename(&temporary, path) {
+ let _ = fs::rename(&backup, path);
+ let _ = fs::remove_file(&temporary);
+ return Err(error.to_string());
+ }
+ fs::remove_file(backup).map_err(|error| error.to_string())?;
+ } else {
+ fs::rename(&temporary, path).map_err(|error| error.to_string())?;
+ }
+ println!("generated {}", path.display());
+ Ok(())
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn manifest_output_is_pretty_and_newline_terminated() {
+ let mut output = serde_json::to_string_pretty(&manifest()).expect("serialize manifest");
+ output.push('\n');
+ assert!(output.starts_with("{\n"));
+ assert!(output.ends_with("\n"));
+ }
+}
diff --git a/libs/cua-driver/rust/crates/cua-driver-contract/src/compatibility.rs b/libs/cua-driver/rust/crates/cua-driver-contract/src/compatibility.rs
new file mode 100644
index 0000000000..44f7aeba05
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver-contract/src/compatibility.rs
@@ -0,0 +1,382 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 Cua AI, Inc.
+
+//! Mechanical compatibility checks between portable SDK schemas and live tools.
+//!
+//! This module intentionally implements only the JSON Schema dialect used by
+//! the current portable desktop contracts. It proves implication in one
+//! direction: every value accepted by the portable schema is also accepted by
+//! the live schema. Encountering an unknown validation keyword is an error, not
+//! an invitation to silently claim parity.
+
+use std::collections::BTreeSet;
+
+use serde_json::Value;
+
+const SUPPORTED_KEYWORDS: &[&str] = &[
+ "type",
+ "const",
+ "enum",
+ "minimum",
+ "maximum",
+ "minLength",
+ "maxLength",
+ "minItems",
+ "maxItems",
+ "items",
+ "required",
+ "properties",
+ "additionalProperties",
+];
+
+const ANNOTATION_KEYWORDS: &[&str] = &["description", "default", "title", "examples"];
+
+/// Return every reason `portable` is not a subset of `live`.
+///
+/// An empty result proves that any input accepted by `portable` is accepted by
+/// `live` for the supported dialect. This is not a general JSON Schema
+/// implication engine.
+pub fn schema_subset_violations(portable: &Value, live: &Value) -> Vec<String> {
+ let mut violations = Vec::new();
+ compare_schema("$", portable, live, &mut violations);
+ violations
+}
+
+fn compare_schema(path: &str, portable: &Value, live: &Value, violations: &mut Vec<String>) {
+ let Some(portable_object) = portable.as_object() else {
+ violations.push(format!("{path}: portable schema must be an object"));
+ return;
+ };
+ let Some(live_object) = live.as_object() else {
+ violations.push(format!("{path}: live schema must be an object"));
+ return;
+ };
+
+ check_keywords(path, "portable", portable_object.keys(), violations);
+ check_keywords(path, "live", live_object.keys(), violations);
+
+ compare_type(path, portable, live, violations);
+ compare_allowed_values(path, portable, live, violations);
+ compare_lower_bound(path, "minimum", portable, live, violations);
+ compare_upper_bound(path, "maximum", portable, live, violations);
+ compare_lower_bound(path, "minLength", portable, live, violations);
+ compare_upper_bound(path, "maxLength", portable, live, violations);
+ compare_lower_bound(path, "minItems", portable, live, violations);
+ compare_upper_bound(path, "maxItems", portable, live, violations);
+
+ if let Some(live_items) = live.get("items") {
+ match portable.get("items") {
+ Some(portable_items) => compare_schema(
+ &format!("{path}.items"),
+ portable_items,
+ live_items,
+ violations,
+ ),
+ None => violations.push(format!(
+ "{path}: live constrains array items but portable does not"
+ )),
+ }
+ }
+
+ compare_object(path, portable, live, violations);
+}
+
+fn check_keywords<'a>(
+ path: &str,
+ side: &str,
+ keys: impl Iterator<Item = &'a String>,
+ violations: &mut Vec<String>,
+) {
+ for key in keys {
+ if !SUPPORTED_KEYWORDS.contains(&key.as_str())
+ && !ANNOTATION_KEYWORDS.contains(&key.as_str())
+ {
+ violations.push(format!("{path}: unsupported {side} schema keyword `{key}`"));
+ }
+ }
+}
+
+fn compare_type(path: &str, portable: &Value, live: &Value, violations: &mut Vec<String>) {
+ let Some(live_type) = live.get("type").and_then(Value::as_str) else {
+ return;
+ };
+ let Some(portable_type) = portable.get("type").and_then(Value::as_str) else {
+ if let Some(values) = allowed_values(portable) {
+ for value in values {
+ if !value_matches_type(value, live_type) {
+ violations.push(format!(
+ "{path}: portable value {value} does not satisfy live type `{live_type}`"
+ ));
+ }
+ }
+ } else {
+ violations.push(format!(
+ "{path}: live requires type `{live_type}` but portable has no type constraint"
+ ));
+ }
+ return;
+ };
+
+ let compatible =
+ portable_type == live_type || (portable_type == "integer" && live_type == "number");
+ if !compatible {
+ violations.push(format!(
+ "{path}: portable type `{portable_type}` is not a subset of live type `{live_type}`"
+ ));
+ }
+}
+
+fn value_matches_type(value: &Value, expected: &str) -> bool {
+ match expected {
+ "null" => value.is_null(),
+ "boolean" => value.is_boolean(),
+ "object" => value.is_object(),
+ "array" => value.is_array(),
+ "number" => value.is_number(),
+ "integer" => value.as_i64().is_some() || value.as_u64().is_some(),
+ "string" => value.is_string(),
+ _ => false,
+ }
+}
+
+fn allowed_values(schema: &Value) -> Option<Vec<&Value>> {
+ if let Some(value) = schema.get("const") {
+ return Some(vec![value]);
+ }
+ schema
+ .get("enum")
+ .and_then(Value::as_array)
+ .map(|values| values.iter().collect())
+}
+
+fn compare_allowed_values(
+ path: &str,
+ portable: &Value,
+ live: &Value,
+ violations: &mut Vec<String>,
+) {
+ let Some(live_values) = allowed_values(live) else {
+ return;
+ };
+ let Some(portable_values) = allowed_values(portable) else {
+ violations.push(format!(
+ "{path}: live restricts allowed values but portable does not"
+ ));
+ return;
+ };
+ for value in portable_values {
+ if !live_values.contains(&value) {
+ violations.push(format!(
+ "{path}: portable value {value} is not accepted by the live schema"
+ ));
+ }
+ }
+}
+
+fn numeric_keyword<'a>(schema: &'a Value, keyword: &str) -> Option<&'a Value> {
+ schema.get(keyword)
+}
+
+fn number(value: &Value) -> Option<f64> {
+ value.as_f64()
+}
+
+fn compare_lower_bound(
+ path: &str,
+ keyword: &str,
+ portable: &Value,
+ live: &Value,
+ violations: &mut Vec<String>,
+) {
+ let Some(live_value) = numeric_keyword(live, keyword) else {
+ return;
+ };
+ let Some(live_number) = number(live_value) else {
+ violations.push(format!("{path}.{keyword}: live bound must be numeric"));
+ return;
+ };
+ let Some(portable_value) = numeric_keyword(portable, keyword) else {
+ violations.push(format!(
+ "{path}: live defines {keyword}={live_value} but portable does not"
+ ));
+ return;
+ };
+ let Some(portable_number) = number(portable_value) else {
+ violations.push(format!("{path}.{keyword}: portable bound must be numeric"));
+ return;
+ };
+ if portable_number < live_number {
+ violations.push(format!(
+ "{path}: portable {keyword}={portable_value} is broader than live {keyword}={live_value}"
+ ));
+ }
+}
+
+fn compare_upper_bound(
+ path: &str,
+ keyword: &str,
+ portable: &Value,
+ live: &Value,
+ violations: &mut Vec<String>,
+) {
+ let Some(live_value) = numeric_keyword(live, keyword) else {
+ return;
+ };
+ let Some(live_number) = number(live_value) else {
+ violations.push(format!("{path}.{keyword}: live bound must be numeric"));
+ return;
+ };
+ let Some(portable_value) = numeric_keyword(portable, keyword) else {
+ violations.push(format!(
+ "{path}: live defines {keyword}={live_value} but portable does not"
+ ));
+ return;
+ };
+ let Some(portable_number) = number(portable_value) else {
+ violations.push(format!("{path}.{keyword}: portable bound must be numeric"));
+ return;
+ };
+ if portable_number > live_number {
+ violations.push(format!(
+ "{path}: portable {keyword}={portable_value} is broader than live {keyword}={live_value}"
+ ));
+ }
+}
+
+fn string_set(schema: &Value, keyword: &str) -> BTreeSet<String> {
+ schema
+ .get(keyword)
+ .and_then(Value::as_array)
+ .into_iter()
+ .flatten()
+ .filter_map(Value::as_str)
+ .map(str::to_owned)
+ .collect()
+}
+
+fn compare_object(path: &str, portable: &Value, live: &Value, violations: &mut Vec<String>) {
+ let portable_properties = portable.get("properties").and_then(Value::as_object);
+ let live_properties = live.get("properties").and_then(Value::as_object);
+
+ if let Some(portable_properties) = portable_properties {
+ let Some(live_properties) = live_properties else {
+ violations.push(format!(
+ "{path}: portable declares properties but live schema does not"
+ ));
+ return;
+ };
+ for (name, portable_property) in portable_properties {
+ let property_path = format!("{path}.properties.{name}");
+ let Some(live_property) = live_properties.get(name) else {
+ violations.push(format!("{property_path}: missing from live schema"));
+ continue;
+ };
+ compare_schema(&property_path, portable_property, live_property, violations);
+ }
+ }
+
+ let portable_required = string_set(portable, "required");
+ let live_required = string_set(live, "required");
+ for required in live_required.difference(&portable_required) {
+ violations.push(format!(
+ "{path}: live requires `{required}` but portable clients may omit it"
+ ));
+ }
+
+ let portable_additional = portable
+ .get("additionalProperties")
+ .and_then(Value::as_bool)
+ .unwrap_or(true);
+ let live_additional = live
+ .get("additionalProperties")
+ .and_then(Value::as_bool)
+ .unwrap_or(true);
+ if portable_additional && !live_additional {
+ violations.push(format!(
+ "{path}: portable permits additional properties but live rejects them"
+ ));
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use serde_json::json;
+
+ use super::*;
+
+ #[test]
+ fn narrower_portable_object_is_accepted() {
+ let portable = json!({
+ "type": "object",
+ "required": ["x", "scope"],
+ "properties": {
+ "x": { "type": "integer", "minimum": 1 },
+ "scope": { "const": "desktop" }
+ },
+ "additionalProperties": false
+ });
+ let live = json!({
+ "type": "object",
+ "required": ["x"],
+ "properties": {
+ "x": { "type": "number", "minimum": 0 },
+ "scope": { "type": "string", "enum": ["window", "desktop"] },
+ "pid": { "type": "integer" }
+ },
+ "additionalProperties": false
+ });
+ assert!(schema_subset_violations(&portable, &live).is_empty());
+ }
+
+ #[test]
+ fn missing_property_and_live_requirement_fail() {
+ let portable = json!({
+ "type": "object",
+ "properties": { "x": { "type": "number" } },
+ "additionalProperties": false
+ });
+ let live = json!({
+ "type": "object",
+ "required": ["pid"],
+ "properties": { "pid": { "type": "integer" } },
+ "additionalProperties": false
+ });
+ let violations = schema_subset_violations(&portable, &live);
+ assert!(violations
+ .iter()
+ .any(|value| value.contains("properties.x")));
+ assert!(violations
+ .iter()
+ .any(|value| value.contains("requires `pid`")));
+ }
+
+ #[test]
+ fn broader_enum_and_bounds_fail() {
+ let portable = json!({ "type": "integer", "enum": [1, 2], "minimum": 0 });
+ let live = json!({ "type": "integer", "enum": [1], "minimum": 1 });
+ let violations = schema_subset_violations(&portable, &live);
+ assert!(violations
+ .iter()
+ .any(|value| value.contains("portable value 2")));
+ assert!(violations.iter().any(|value| value.contains("minimum")));
+ }
+
+ #[test]
+ fn unknown_validation_keyword_fails_closed() {
+ let portable = json!({ "type": "string", "pattern": "^[a-z]+$" });
+ let live = json!({ "type": "string" });
+ let violations = schema_subset_violations(&portable, &live);
+ assert_eq!(violations.len(), 1);
+ assert!(violations[0].contains("unsupported portable schema keyword `pattern`"));
+ }
+
+ #[test]
+ fn additional_property_domain_must_be_accepted_live() {
+ let portable = json!({ "type": "object" });
+ let live = json!({ "type": "object", "additionalProperties": false });
+ let violations = schema_subset_violations(&portable, &live);
+ assert!(violations
+ .iter()
+ .any(|value| value.contains("portable permits additional properties")));
+ }
+}
diff --git a/libs/cua-driver/rust/crates/cua-driver-contract/src/desktop.rs b/libs/cua-driver/rust/crates/cua-driver-contract/src/desktop.rs
new file mode 100644
index 0000000000..6c281decfb
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver-contract/src/desktop.rs
@@ -0,0 +1,201 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 Cua AI, Inc.
+
+//! Cross-platform desktop-loop contracts.
+//!
+//! These schemas intentionally expose only the intersection accepted by the
+//! macOS, Linux, and Windows backends. They generate safe client methods but
+//! do not replace the richer platform-owned runtime schemas.
+
+use crate::{
+ ClickInput, ClickOutput, CursorPositionOutput, DesktopActionOutput, DesktopStateOutput,
+ DragInput, GetCursorPositionInput, GetDesktopStateInput, GetScreenSizeInput, HotkeyInput,
+ MoveCursorInput, MoveCursorOutput, Platform, PressKeyInput, SchemaMode, ScreenSizeOutput,
+ ScrollInput, ToolAnnotations, ToolContract, ToolInput, ToolOutput, TypeTextInput,
+};
+
+const ALL_PLATFORMS: [Platform; 3] = [Platform::Macos, Platform::Windows, Platform::Linux];
+
+pub fn contracts() -> Vec<ToolContract> {
+ vec![
+ get_desktop_state(),
+ get_screen_size(),
+ get_cursor_position(),
+ move_cursor(),
+ click(),
+ drag(),
+ scroll(),
+ type_text(),
+ press_key(),
+ hotkey(),
+ ]
+}
+
+fn contract<I: ToolInput, O: ToolOutput>(
+ name: &str,
+ description: &str,
+ capabilities: &[&str],
+ annotations: ToolAnnotations,
+) -> ToolContract {
+ assert_eq!(name, I::TOOL_NAME, "typed input is bound to the wrong tool");
+ ToolContract {
+ name: name.into(),
+ description: description.into(),
+ platforms: ALL_PLATFORMS.to_vec(),
+ aliases: Vec::new(),
+ capabilities: capabilities.iter().map(|value| (*value).into()).collect(),
+ annotations,
+ schema_mode: SchemaMode::PortableSubset,
+ input_schema: I::input_schema(),
+ success_output_schema: Some(O::output_schema()),
+ output_validator: crate::validate_typed_output::<O>,
+ }
+}
+
+fn get_desktop_state() -> ToolContract {
+ contract::<GetDesktopStateInput, DesktopStateOutput>(
+ "get_desktop_state",
+ "Capture the complete primary display at native resolution for a desktop-scope GUI loop.",
+ &["screen.capture", "screen.dimensions"],
+ ToolAnnotations {
+ read_only: true,
+ destructive: false,
+ idempotent: false,
+ open_world: false,
+ },
+ )
+}
+
+fn get_screen_size() -> ToolContract {
+ contract::<GetScreenSizeInput, ScreenSizeOutput>(
+ "get_screen_size",
+ "Return the primary display dimensions and scale factor in the platform's desktop coordinate space.",
+ &["screen.dimensions"],
+ ToolAnnotations {
+ read_only: true,
+ destructive: false,
+ idempotent: true,
+ open_world: false,
+ },
+ )
+}
+
+fn get_cursor_position() -> ToolContract {
+ contract::<GetCursorPositionInput, CursorPositionOutput>(
+ "get_cursor_position",
+ "Return the OS cursor position when the platform can observe it.",
+ &["screen.cursor.position"],
+ ToolAnnotations {
+ read_only: true,
+ destructive: false,
+ idempotent: true,
+ open_world: false,
+ },
+ )
+}
+
+fn move_cursor() -> ToolContract {
+ contract::<MoveCursorInput, MoveCursorOutput>(
+ "move_cursor",
+ "Move the real OS pointer in get_desktop_state coordinates.",
+ &["agent_cursor.move", "input.pointer.move"],
+ ToolAnnotations {
+ read_only: false,
+ destructive: false,
+ idempotent: true,
+ open_world: false,
+ },
+ )
+}
+
+fn click() -> ToolContract {
+ contract::<ClickInput, ClickOutput>(
+ "click",
+ "Click an absolute point in get_desktop_state coordinates without targeting a window.",
+ &[
+ "input.pointer.click",
+ "input.pointer.click.left",
+ "accessibility.element_tokens",
+ ],
+ ToolAnnotations {
+ read_only: false,
+ destructive: true,
+ idempotent: false,
+ open_world: true,
+ },
+ )
+}
+
+fn drag() -> ToolContract {
+ contract::<DragInput, DesktopActionOutput>(
+ "drag",
+ "Drag between two absolute points in get_desktop_state coordinates.",
+ &["input.pointer.drag"],
+ ToolAnnotations {
+ read_only: false,
+ destructive: true,
+ idempotent: false,
+ open_world: true,
+ },
+ )
+}
+
+fn scroll() -> ToolContract {
+ contract::<ScrollInput, DesktopActionOutput>(
+ "scroll",
+ "Scroll at an absolute point in get_desktop_state coordinates.",
+ &["input.pointer.scroll", "accessibility.element_tokens"],
+ ToolAnnotations {
+ read_only: false,
+ destructive: false,
+ idempotent: false,
+ open_world: true,
+ },
+ )
+}
+
+fn type_text() -> ToolContract {
+ contract::<TypeTextInput, DesktopActionOutput>(
+ "type_text",
+ "Type text into the current foreground desktop application.",
+ &[
+ "input.keyboard.type",
+ "input.keyboard.type.terminal_safe",
+ "accessibility.element_tokens",
+ ],
+ ToolAnnotations {
+ read_only: false,
+ destructive: true,
+ idempotent: false,
+ open_world: true,
+ },
+ )
+}
+
+fn press_key() -> ToolContract {
+ contract::<PressKeyInput, DesktopActionOutput>(
+ "press_key",
+ "Press one key, with optional modifiers, in the foreground desktop application.",
+ &["input.keyboard.press", "accessibility.element_tokens"],
+ ToolAnnotations {
+ read_only: false,
+ destructive: true,
+ idempotent: false,
+ open_world: true,
+ },
+ )
+}
+
+fn hotkey() -> ToolContract {
+ contract::<HotkeyInput, DesktopActionOutput>(
+ "hotkey",
+ "Press a key chord in the foreground desktop application.",
+ &["input.keyboard.hotkey"],
+ ToolAnnotations {
+ read_only: false,
+ destructive: true,
+ idempotent: false,
+ open_world: true,
+ },
+ )
+}
diff --git a/libs/cua-driver/rust/crates/cua-driver-contract/src/inputs.rs b/libs/cua-driver/rust/crates/cua-driver-contract/src/inputs.rs
new file mode 100644
index 0000000000..8bd5c2bca6
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver-contract/src/inputs.rs
@@ -0,0 +1,529 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 Cua AI, Inc.
+
+//! Typed inputs for the published Cua Driver SDK surface.
+//!
+//! These types are transport-free. The contract generator derives JSON Schema
+//! from them, and live Rust handlers deserialize the same types before acting.
+
+use schemars::{json_schema, JsonSchema, Schema, SchemaGenerator};
+use serde::{de::DeserializeOwned, Deserialize, Serialize};
+use serde_json::Value;
+
+pub trait ToolInput: Serialize + DeserializeOwned + JsonSchema {
+ const TOOL_NAME: &'static str;
+
+ fn input_schema() -> Value {
+ let settings = schemars::generate::SchemaSettings::draft2020_12().with(|settings| {
+ settings.meta_schema = None;
+ settings.inline_subschemas = true;
+ });
+ let schema = settings.into_generator().into_root_schema_for::<Self>();
+ let mut value = serde_json::to_value(schema).expect("tool input schema serializes");
+ normalize_schema(&mut value);
+ value
+ }
+}
+
+fn normalize_schema(value: &mut Value) {
+ match value {
+ Value::Object(object) => {
+ object.remove("title");
+ if object.get("type").and_then(Value::as_str) == Some("object") {
+ object
+ .entry("properties")
+ .or_insert_with(|| Value::Object(serde_json::Map::new()));
+ object
+ .entry("required")
+ .or_insert_with(|| Value::Array(Vec::new()));
+ object
+ .entry("additionalProperties")
+ .or_insert(Value::Bool(true));
+ }
+ for child in object.values_mut() {
+ normalize_schema(child);
+ }
+ }
+ Value::Array(values) => {
+ for child in values {
+ normalize_schema(child);
+ }
+ }
+ _ => {}
+ }
+}
+
+fn string_schema(generator: &mut SchemaGenerator) -> Schema {
+ String::json_schema(generator)
+}
+
+fn string_list_schema(generator: &mut SchemaGenerator) -> Schema {
+ Vec::<String>::json_schema(generator)
+}
+
+fn number_schema(_: &mut SchemaGenerator) -> Schema {
+ json_schema!({ "type": "number" })
+}
+
+fn click_button_schema(generator: &mut SchemaGenerator) -> Schema {
+ ClickButton::json_schema(generator)
+}
+
+fn scroll_by_schema(generator: &mut SchemaGenerator) -> Schema {
+ ScrollBy::json_schema(generator)
+}
+
+fn click_count_schema(_: &mut SchemaGenerator) -> Schema {
+ json_schema!({ "type": "integer", "minimum": 1, "maximum": 3 })
+}
+
+fn drag_duration_schema(_: &mut SchemaGenerator) -> Schema {
+ json_schema!({ "type": "integer", "minimum": 0, "maximum": 10000 })
+}
+
+fn drag_steps_schema(_: &mut SchemaGenerator) -> Schema {
+ json_schema!({ "type": "integer", "minimum": 1, "maximum": 200 })
+}
+
+fn scroll_amount_schema(_: &mut SchemaGenerator) -> Schema {
+ json_schema!({ "type": "integer", "minimum": 1, "maximum": 50 })
+}
+
+fn escalation_detail_schema(_: &mut SchemaGenerator) -> Schema {
+ json_schema!({ "type": "string", "maxLength": 200 })
+}
+
+fn capture_scope_schema(_: &mut SchemaGenerator) -> Schema {
+ json_schema!({
+ "type": "string",
+ "enum": ["auto", "window", "desktop"],
+ "default": "auto"
+ })
+}
+
+#[derive(
+ Debug, Clone, Copy, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq, uniffi::Enum,
+)]
+#[serde(rename_all = "snake_case")]
+pub enum CaptureScope {
+ #[default]
+ Auto,
+ Window,
+ Desktop,
+}
+
+impl CaptureScope {
+ pub fn parse(value: &str) -> Option<Self> {
+ match value {
+ "auto" => Some(Self::Auto),
+ "window" => Some(Self::Window),
+ "desktop" => Some(Self::Desktop),
+ _ => None,
+ }
+ }
+
+ pub const fn as_str(self) -> &'static str {
+ match self {
+ Self::Auto => "auto",
+ Self::Window => "window",
+ Self::Desktop => "desktop",
+ }
+ }
+}
+
+impl std::fmt::Display for CaptureScope {
+ fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ formatter.write_str(self.as_str())
+ }
+}
+
+#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq, Eq, uniffi::Enum)]
+#[serde(rename_all = "snake_case")]
+pub enum EscalationReason {
+ AxTreePixelMismatch,
+ BackgroundDeliveryFailed,
+ ForegroundIneffective,
+ NoWindowTarget,
+ Other,
+}
+
+impl EscalationReason {
+ pub fn parse(value: &str) -> Option<Self> {
+ match value {
+ "ax_tree_pixel_mismatch" => Some(Self::AxTreePixelMismatch),
+ "background_delivery_failed" => Some(Self::BackgroundDeliveryFailed),
+ "foreground_ineffective" => Some(Self::ForegroundIneffective),
+ "no_window_target" => Some(Self::NoWindowTarget),
+ "other" => Some(Self::Other),
+ _ => None,
+ }
+ }
+
+ pub const fn as_str(self) -> &'static str {
+ match self {
+ Self::AxTreePixelMismatch => "ax_tree_pixel_mismatch",
+ Self::BackgroundDeliveryFailed => "background_delivery_failed",
+ Self::ForegroundIneffective => "foreground_ineffective",
+ Self::NoWindowTarget => "no_window_target",
+ Self::Other => "other",
+ }
+ }
+}
+
+#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, uniffi::Enum)]
+pub enum DesktopScope {
+ #[serde(rename = "desktop")]
+ Desktop,
+}
+
+impl JsonSchema for DesktopScope {
+ fn schema_name() -> std::borrow::Cow<'static, str> {
+ "DesktopScope".into()
+ }
+
+ fn json_schema(_: &mut SchemaGenerator) -> Schema {
+ json_schema!({ "const": "desktop" })
+ }
+}
+
+#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq, Eq, uniffi::Enum)]
+#[serde(rename_all = "snake_case")]
+pub enum ClickButton {
+ Left,
+ Right,
+ Middle,
+}
+
+impl ClickButton {
+ pub const fn as_str(self) -> &'static str {
+ match self {
+ Self::Left => "left",
+ Self::Right => "right",
+ Self::Middle => "middle",
+ }
+ }
+}
+
+#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq, Eq, uniffi::Enum)]
+#[serde(rename_all = "snake_case")]
+pub enum ScrollDirection {
+ Up,
+ Down,
+ Left,
+ Right,
+}
+
+impl ScrollDirection {
+ pub const fn as_str(self) -> &'static str {
+ match self {
+ Self::Up => "up",
+ Self::Down => "down",
+ Self::Left => "left",
+ Self::Right => "right",
+ }
+ }
+}
+
+#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq, Eq, uniffi::Enum)]
+#[serde(rename_all = "snake_case")]
+pub enum ScrollBy {
+ Line,
+ Page,
+}
+
+impl ScrollBy {
+ pub const fn as_str(self) -> &'static str {
+ match self {
+ Self::Line => "line",
+ Self::Page => "page",
+ }
+ }
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, uniffi::Record)]
+pub struct StartSessionInput {
+ /// Stable session id for this run (e.g. "research-run-1").
+ pub session: String,
+ /// Per-session perception/action modality. auto starts window-only and requires explicit escalation before desktop tools; window and desktop are strict. Immutable for the live session.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "capture_scope_schema")]
+ pub capture_scope: Option<CaptureScope>,
+}
+
+impl ToolInput for StartSessionInput {
+ const TOOL_NAME: &'static str = "start_session";
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, uniffi::Record)]
+pub struct EscalateSessionInput {
+ pub session: String,
+ pub reason: EscalationReason,
+ /// Optional bounded diagnostic detail. Never use secrets or page content.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "escalation_detail_schema")]
+ pub detail: Option<String>,
+}
+
+impl ToolInput for EscalateSessionInput {
+ const TOOL_NAME: &'static str = "escalate_session";
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, uniffi::Record)]
+pub struct GetSessionStateInput {
+ pub session: String,
+}
+
+impl ToolInput for GetSessionStateInput {
+ const TOOL_NAME: &'static str = "get_session_state";
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, uniffi::Record)]
+pub struct EndSessionInput {
+ /// The session id to end.
+ pub session: String,
+}
+
+impl ToolInput for EndSessionInput {
+ const TOOL_NAME: &'static str = "end_session";
+}
+
+#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, uniffi::Record)]
+#[serde(deny_unknown_fields)]
+pub struct GetDesktopStateInput {
+ /// Optional session id.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "string_schema")]
+ pub session: Option<String>,
+ /// Write the PNG here instead of returning base64.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "string_schema")]
+ pub screenshot_out_file: Option<String>,
+}
+
+impl ToolInput for GetDesktopStateInput {
+ const TOOL_NAME: &'static str = "get_desktop_state";
+}
+
+#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, uniffi::Record)]
+#[serde(deny_unknown_fields)]
+pub struct GetScreenSizeInput {
+ /// Optional session id.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "string_schema")]
+ pub session: Option<String>,
+}
+
+impl ToolInput for GetScreenSizeInput {
+ const TOOL_NAME: &'static str = "get_screen_size";
+}
+
+#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, uniffi::Record)]
+#[serde(deny_unknown_fields)]
+pub struct GetCursorPositionInput {
+ /// Optional session id.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "string_schema")]
+ pub session: Option<String>,
+}
+
+impl ToolInput for GetCursorPositionInput {
+ const TOOL_NAME: &'static str = "get_cursor_position";
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, uniffi::Record)]
+#[serde(deny_unknown_fields)]
+pub struct MoveCursorInput {
+ #[schemars(schema_with = "number_schema")]
+ pub x: f64,
+ #[schemars(schema_with = "number_schema")]
+ pub y: f64,
+ pub scope: DesktopScope,
+ /// Optional session id.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "string_schema")]
+ pub session: Option<String>,
+}
+
+impl ToolInput for MoveCursorInput {
+ const TOOL_NAME: &'static str = "move_cursor";
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, uniffi::Record)]
+#[serde(deny_unknown_fields)]
+pub struct ClickInput {
+ #[schemars(schema_with = "number_schema")]
+ pub x: f64,
+ #[schemars(schema_with = "number_schema")]
+ pub y: f64,
+ pub scope: DesktopScope,
+ /// Optional session id.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "string_schema")]
+ pub session: Option<String>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "click_button_schema")]
+ pub button: Option<ClickButton>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "click_count_schema")]
+ pub count: Option<u32>,
+}
+
+impl ToolInput for ClickInput {
+ const TOOL_NAME: &'static str = "click";
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, uniffi::Record)]
+#[serde(deny_unknown_fields)]
+pub struct DragInput {
+ #[schemars(schema_with = "number_schema")]
+ pub from_x: f64,
+ #[schemars(schema_with = "number_schema")]
+ pub from_y: f64,
+ #[schemars(schema_with = "number_schema")]
+ pub to_x: f64,
+ #[schemars(schema_with = "number_schema")]
+ pub to_y: f64,
+ pub scope: DesktopScope,
+ /// Optional session id.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "string_schema")]
+ pub session: Option<String>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "drag_duration_schema")]
+ pub duration_ms: Option<u64>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "drag_steps_schema")]
+ pub steps: Option<u64>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "click_button_schema")]
+ pub button: Option<ClickButton>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "string_list_schema")]
+ pub modifier: Option<Vec<String>>,
+}
+
+impl ToolInput for DragInput {
+ const TOOL_NAME: &'static str = "drag";
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, uniffi::Record)]
+#[serde(deny_unknown_fields)]
+pub struct ScrollInput {
+ #[schemars(schema_with = "number_schema")]
+ pub x: f64,
+ #[schemars(schema_with = "number_schema")]
+ pub y: f64,
+ pub direction: ScrollDirection,
+ pub scope: DesktopScope,
+ /// Optional session id.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "string_schema")]
+ pub session: Option<String>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "scroll_by_schema")]
+ pub by: Option<ScrollBy>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "scroll_amount_schema")]
+ pub amount: Option<u64>,
+}
+
+impl ToolInput for ScrollInput {
+ const TOOL_NAME: &'static str = "scroll";
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, uniffi::Record)]
+#[serde(deny_unknown_fields)]
+pub struct TypeTextInput {
+ pub text: String,
+ pub scope: DesktopScope,
+ /// Optional session id.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "string_schema")]
+ pub session: Option<String>,
+}
+
+impl ToolInput for TypeTextInput {
+ const TOOL_NAME: &'static str = "type_text";
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, uniffi::Record)]
+#[serde(deny_unknown_fields)]
+pub struct PressKeyInput {
+ pub key: String,
+ pub scope: DesktopScope,
+ /// Optional session id.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "string_schema")]
+ pub session: Option<String>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "string_list_schema")]
+ pub modifiers: Option<Vec<String>>,
+}
+
+impl ToolInput for PressKeyInput {
+ const TOOL_NAME: &'static str = "press_key";
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, uniffi::Record)]
+#[serde(deny_unknown_fields)]
+pub struct HotkeyInput {
+ #[schemars(length(min = 2))]
+ pub keys: Vec<String>,
+ pub scope: DesktopScope,
+ /// Optional session id.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "string_schema")]
+ pub session: Option<String>,
+}
+
+impl ToolInput for HotkeyInput {
+ const TOOL_NAME: &'static str = "hotkey";
+}
+
+#[cfg(test)]
+mod tests {
+ use serde_json::json;
+
+ use super::*;
+
+ #[test]
+ fn generated_click_schema_matches_driver_dialect() {
+ let schema = ClickInput::input_schema();
+ assert_eq!(schema["type"], "object");
+ assert_eq!(schema["additionalProperties"], false);
+ assert_eq!(schema["required"], json!(["x", "y", "scope"]));
+ assert_eq!(schema["properties"]["scope"], json!({ "const": "desktop" }));
+ assert_eq!(
+ schema["properties"]["button"],
+ json!({ "type": "string", "enum": ["left", "right", "middle"] })
+ );
+ assert_eq!(
+ schema["properties"]["count"],
+ json!({ "type": "integer", "minimum": 1, "maximum": 3 })
+ );
+ }
+
+ #[test]
+ fn generated_session_schema_preserves_default_and_open_input() {
+ let schema = StartSessionInput::input_schema();
+ assert_eq!(schema["additionalProperties"], true);
+ assert_eq!(schema["required"], json!(["session"]));
+ assert_eq!(schema["properties"]["capture_scope"]["default"], "auto");
+ assert_eq!(
+ schema["properties"]["capture_scope"]["enum"],
+ json!(["auto", "window", "desktop"])
+ );
+ }
+
+ #[test]
+ fn serde_and_schema_reject_unknown_fields() {
+ let error = serde_json::from_value::<ClickInput>(json!({
+ "x": 1,
+ "y": 2,
+ "scope": "desktop",
+ "pid": 3
+ }))
+ .expect_err("portable input must reject runtime-only fields");
+ assert!(error.to_string().contains("unknown field `pid`"));
+ }
+}
diff --git a/libs/cua-driver/rust/crates/cua-driver-contract/src/lib.rs b/libs/cua-driver/rust/crates/cua-driver-contract/src/lib.rs
new file mode 100644
index 0000000000..7ca8b5e221
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver-contract/src/lib.rs
@@ -0,0 +1,327 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 Cua AI, Inc.
+
+//! Canonical, platform-neutral contract declarations for cua-driver clients.
+//!
+//! This crate deliberately contains no transport or platform implementation.
+//! The native driver remains the only execution engine; this package owns the
+//! typed inputs/results and versioned declarations used by the live runtime
+//! and to generate experimental client SDKs.
+
+use serde::{Deserialize, Serialize};
+use serde_json::Value;
+use std::collections::{BTreeMap, BTreeSet};
+use std::sync::OnceLock;
+
+pub mod compatibility;
+mod desktop;
+mod inputs;
+mod outputs;
+mod session;
+
+pub use inputs::{
+ CaptureScope, ClickButton, ClickInput, DesktopScope, DragInput, EndSessionInput,
+ EscalateSessionInput, EscalationReason, GetCursorPositionInput, GetDesktopStateInput,
+ GetScreenSizeInput, GetSessionStateInput, HotkeyInput, MoveCursorInput, PressKeyInput,
+ ScrollBy, ScrollDirection, ScrollInput, StartSessionInput, ToolInput, TypeTextInput,
+};
+pub use outputs::{
+ ClickOutput, CursorPositionOutput, DesktopActionOutput, DesktopStateOutput, EffectiveScope,
+ EndSessionOutput, MoveCursorOutput, ScreenSizeOutput, SessionStateOutput, StartSessionOutput,
+ ToolOutput,
+};
+
+/// Shape version for the MCP `tools/list` result emitted by cua-driver.
+pub const TOOLS_LIST_SCHEMA_VERSION: &str = "1";
+
+/// Version of the additive capability-token vocabulary.
+pub const CAPABILITY_VERSION: &str = "1";
+
+/// Shape version for the checked-in generated client contract.
+pub const CONTRACT_VERSION: &str = "0.2.0";
+
+/// MCP protocol version used by current cua-driver clients.
+pub const MCP_PROTOCOL_VERSION: &str = "2025-06-18";
+
+#[derive(
+ Debug,
+ Clone,
+ Copy,
+ Serialize,
+ Deserialize,
+ schemars::JsonSchema,
+ PartialEq,
+ Eq,
+ PartialOrd,
+ Ord,
+ uniffi::Enum,
+)]
+#[serde(rename_all = "snake_case")]
+pub enum Platform {
+ Macos,
+ Windows,
+ Linux,
+}
+
+uniffi::setup_scaffolding!("cua_driver_contract");
+
+/// Whether a client contract is also the canonical live MCP schema, or a
+/// deliberately narrower cross-platform subset accepted by every backend.
+#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
+#[serde(rename_all = "snake_case")]
+pub enum SchemaMode {
+ CanonicalRuntime,
+ PortableSubset,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
+pub struct ToolAnnotations {
+ pub read_only: bool,
+ pub destructive: bool,
+ pub idempotent: bool,
+ pub open_world: bool,
+}
+
+pub type OutputValidator = fn(Value) -> Result<(), String>;
+
+fn default_output_validator() -> OutputValidator {
+ |_| Ok(())
+}
+
+pub(crate) fn validate_typed_output<T: ToolOutput>(value: Value) -> Result<(), String> {
+ let output = serde_json::from_value::<T>(value).map_err(|error| error.to_string())?;
+ output.validate()
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct ToolContract {
+ pub name: String,
+ pub description: String,
+ pub platforms: Vec<Platform>,
+ #[serde(default, skip_serializing_if = "Vec::is_empty")]
+ pub aliases: Vec<String>,
+ pub capabilities: Vec<String>,
+ pub annotations: ToolAnnotations,
+ pub schema_mode: SchemaMode,
+ pub input_schema: Value,
+ /// Schema for successful `structuredContent` only. It is experimental and
+ /// is not advertised as MCP `outputSchema` until transport parity is proven.
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub success_output_schema: Option<Value>,
+ /// Runtime-only validator bound to the same Rust output type that produced
+ /// `success_output_schema`; omitted from the generated manifest.
+ #[serde(skip, default = "default_output_validator")]
+ pub(crate) output_validator: OutputValidator,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct ContractManifest {
+ pub generated_notice: String,
+ pub experimental: bool,
+ pub contract_version: String,
+ pub tools_list_schema_version: String,
+ pub capability_version: String,
+ pub mcp_protocol_version: String,
+ pub transport: String,
+ pub tools: Vec<ToolContract>,
+}
+
+pub fn manifest() -> ContractManifest {
+ let mut tools = session::contracts();
+ tools.extend(desktop::contracts());
+ tools.sort_by(|left, right| left.name.cmp(&right.name));
+ ContractManifest {
+ generated_notice: "Generated by cua-contract-gen; do not edit by hand.".into(),
+ experimental: true,
+ contract_version: CONTRACT_VERSION.into(),
+ tools_list_schema_version: TOOLS_LIST_SCHEMA_VERSION.into(),
+ capability_version: CAPABILITY_VERSION.into(),
+ mcp_protocol_version: MCP_PROTOCOL_VERSION.into(),
+ transport: "mcp_stdio".into(),
+ tools,
+ }
+}
+
+pub fn tool_contract(name: &str) -> Option<ToolContract> {
+ manifest().tools.into_iter().find(|tool| tool.name == name)
+}
+
+#[derive(Debug)]
+struct ToolIndexEntry {
+ capabilities: Vec<String>,
+ input_fields: BTreeSet<String>,
+ output_validator: OutputValidator,
+}
+
+fn tool_index() -> &'static BTreeMap<String, ToolIndexEntry> {
+ static INDEX: OnceLock<BTreeMap<String, ToolIndexEntry>> = OnceLock::new();
+ INDEX.get_or_init(|| {
+ manifest()
+ .tools
+ .into_iter()
+ .map(|tool| {
+ let input_fields = tool
+ .input_schema
+ .get("properties")
+ .and_then(Value::as_object)
+ .into_iter()
+ .flatten()
+ .map(|(name, _)| name.clone())
+ .collect();
+ (
+ tool.name,
+ ToolIndexEntry {
+ capabilities: tool.capabilities,
+ input_fields,
+ output_validator: tool.output_validator,
+ },
+ )
+ })
+ .collect()
+ })
+}
+
+/// Return capability tokens for one published tool without rebuilding schemas
+/// on every live `tools/list` entry.
+pub fn tool_capabilities(name: &str) -> Option<Vec<String>> {
+ tool_index()
+ .get(name)
+ .map(|entry| entry.capabilities.clone())
+}
+
+/// Names owned by a published portable input projection.
+pub fn tool_input_fields(name: &str) -> Option<&'static BTreeSet<String>> {
+ tool_index().get(name).map(|entry| &entry.input_fields)
+}
+
+/// Validate a successful structured payload against the Rust output type that
+/// also generates its SDK schema. Returns `Ok(false)` for non-SDK tools.
+pub fn validate_success_output(name: &str, value: Value) -> Result<bool, String> {
+ if let Some(entry) = tool_index().get(name) {
+ (entry.output_validator)(value)?;
+ Ok(true)
+ } else {
+ Ok(false)
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn manifest_is_sorted_and_versioned() {
+ let manifest = manifest();
+ let names: Vec<_> = manifest
+ .tools
+ .iter()
+ .map(|tool| tool.name.as_str())
+ .collect();
+ let mut sorted = names.clone();
+ sorted.sort_unstable();
+ assert_eq!(names, sorted);
+ assert_eq!(manifest.contract_version, "0.2.0");
+ assert!(manifest.experimental);
+ }
+
+ #[test]
+ fn every_contract_has_success_schema_and_platforms() {
+ for tool in manifest().tools {
+ assert!(!tool.platforms.is_empty(), "{} has no platform", tool.name);
+ assert!(
+ tool.success_output_schema.is_some(),
+ "{} has no success output schema",
+ tool.name
+ );
+ }
+ }
+
+ #[test]
+ fn desktop_contracts_are_explicit_portable_subsets() {
+ for name in [
+ "click",
+ "drag",
+ "get_cursor_position",
+ "get_desktop_state",
+ "get_screen_size",
+ "hotkey",
+ "move_cursor",
+ "press_key",
+ "scroll",
+ "type_text",
+ ] {
+ assert_eq!(
+ tool_contract(name).expect("desktop contract").schema_mode,
+ SchemaMode::PortableSubset,
+ "{name}"
+ );
+ }
+ }
+
+ #[test]
+ fn session_success_schemas_require_every_typed_field() {
+ let start = tool_contract("start_session").expect("start_session contract");
+ let success_schema = start.success_output_schema.expect("success schema");
+ let required = success_schema["required"]
+ .as_array()
+ .expect("required array")
+ .iter()
+ .filter_map(Value::as_str)
+ .collect::<Vec<_>>();
+ assert_eq!(
+ required,
+ [
+ "session",
+ "capture_scope",
+ "effective_scope",
+ "desktop_unlocked",
+ "escalation_reason",
+ "escalation_detail",
+ "active",
+ "revived",
+ ]
+ );
+ }
+
+ #[test]
+ fn typed_success_outputs_accept_extensions_and_reject_wrong_common_fields() {
+ assert_eq!(
+ validate_success_output(
+ "get_screen_size",
+ serde_json::json!({
+ "width": 1512,
+ "height": 982,
+ "scale_factor": 2,
+ "backend": "core_graphics"
+ }),
+ ),
+ Ok(true)
+ );
+ assert!(validate_success_output(
+ "get_screen_size",
+ serde_json::json!({
+ "width": "1512",
+ "height": 982,
+ "scale_factor": 2
+ }),
+ )
+ .is_err());
+ assert!(validate_success_output(
+ "end_session",
+ serde_json::json!({"session": "run", "active": true}),
+ )
+ .is_err());
+ }
+
+ #[test]
+ fn every_published_tool_has_a_live_typed_output_validator() {
+ for contract in manifest().tools {
+ let invalid = serde_json::json!([]);
+ assert!(
+ validate_success_output(&contract.name, invalid).is_err(),
+ "{} has no typed output validator",
+ contract.name
+ );
+ }
+ }
+}
diff --git a/libs/cua-driver/rust/crates/cua-driver-contract/src/outputs.rs b/libs/cua-driver/rust/crates/cua-driver-contract/src/outputs.rs
new file mode 100644
index 0000000000..ab50f173bc
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver-contract/src/outputs.rs
@@ -0,0 +1,285 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 Cua AI, Inc.
+
+use crate::{CaptureScope, DesktopScope, EscalationReason, Platform};
+use schemars::{generate::SchemaSettings, JsonSchema};
+use serde::{de::DeserializeOwned, Deserialize, Serialize};
+use serde_json::{Map, Value};
+use std::collections::BTreeMap;
+
+/// Transport-free structured result used by both the live runtime and SDK generation.
+pub trait ToolOutput: Serialize + DeserializeOwned + JsonSchema {
+ fn validate(&self) -> Result<(), String> {
+ Ok(())
+ }
+
+ fn output_schema() -> Value {
+ let mut settings = SchemaSettings::draft2020_12();
+ settings.inline_subschemas = true;
+ settings.meta_schema = None;
+ let mut schema =
+ serde_json::to_value(settings.into_generator().into_root_schema_for::<Self>())
+ .expect("JSON Schema serializes");
+ strip_schema_titles(&mut schema);
+ if let Some(object) = schema.as_object_mut() {
+ object.insert("additionalProperties".into(), Value::Bool(true));
+ object
+ .entry("properties")
+ .or_insert_with(|| Value::Object(Map::new()));
+ }
+ schema
+ }
+}
+
+fn strip_schema_titles(value: &mut Value) {
+ match value {
+ Value::Object(object) => {
+ object.remove("title");
+ object.remove("description");
+ for child in object.values_mut() {
+ strip_schema_titles(child);
+ }
+ }
+ Value::Array(values) => values.iter_mut().for_each(strip_schema_titles),
+ _ => {}
+ }
+}
+
+#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq, Eq, uniffi::Enum)]
+#[serde(rename_all = "snake_case")]
+pub enum EffectiveScope {
+ Window,
+ Desktop,
+}
+
+impl EffectiveScope {
+ pub const fn as_str(self) -> &'static str {
+ match self {
+ Self::Window => "window",
+ Self::Desktop => "desktop",
+ }
+ }
+}
+
+/// Successful structured result shared by session state and escalation tools.
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq, uniffi::Record)]
+pub struct SessionStateOutput {
+ pub session: String,
+ pub capture_scope: CaptureScope,
+ pub effective_scope: EffectiveScope,
+ pub desktop_unlocked: bool,
+ #[schemars(required, schema_with = "nullable_escalation_reason_schema")]
+ pub escalation_reason: Option<EscalationReason>,
+ #[schemars(required, schema_with = "nullable_string_schema")]
+ pub escalation_detail: Option<String>,
+}
+
+impl ToolOutput for SessionStateOutput {}
+
+/// Successful structured result returned by `start_session`.
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq, uniffi::Record)]
+pub struct StartSessionOutput {
+ #[serde(flatten)]
+ pub state: SessionStateOutput,
+ pub active: bool,
+ pub revived: bool,
+}
+
+impl ToolOutput for StartSessionOutput {}
+
+/// Successful structured result returned by `end_session`.
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq, uniffi::Record)]
+pub struct EndSessionOutput {
+ pub session: String,
+ #[schemars(schema_with = "inactive_schema")]
+ pub active: bool,
+}
+
+impl ToolOutput for EndSessionOutput {
+ fn validate(&self) -> Result<(), String> {
+ if self.active {
+ Err("active must be false".into())
+ } else {
+ Ok(())
+ }
+ }
+}
+
+fn inactive_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
+ schemars::json_schema!({ "const": false })
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
+pub struct DesktopStateOutput {
+ #[schemars(schema_with = "platform_schema")]
+ pub platform: Platform,
+ pub display: String,
+ #[schemars(schema_with = "integer_schema")]
+ pub screenshot_width: u64,
+ #[schemars(schema_with = "integer_schema")]
+ pub screenshot_height: u64,
+ #[schemars(schema_with = "integer_schema")]
+ pub screen_width: u64,
+ #[schemars(schema_with = "integer_schema")]
+ pub screen_height: u64,
+ #[schemars(schema_with = "number_schema")]
+ pub scale_factor: f64,
+ #[schemars(schema_with = "png_mime_schema")]
+ pub screenshot_mime_type: String,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "string_schema")]
+ pub screenshot_file_path: Option<String>,
+ #[serde(flatten)]
+ pub extensions: BTreeMap<String, Value>,
+}
+
+impl ToolOutput for DesktopStateOutput {
+ fn validate(&self) -> Result<(), String> {
+ if self.screenshot_mime_type == "image/png" {
+ Ok(())
+ } else {
+ Err("screenshot_mime_type must be image/png".into())
+ }
+ }
+}
+
+fn png_mime_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
+ schemars::json_schema!({ "const": "image/png" })
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
+pub struct ScreenSizeOutput {
+ #[schemars(schema_with = "number_schema")]
+ pub width: f64,
+ #[schemars(schema_with = "number_schema")]
+ pub height: f64,
+ #[schemars(schema_with = "number_schema")]
+ pub scale_factor: f64,
+ #[serde(flatten)]
+ pub extensions: BTreeMap<String, Value>,
+}
+
+impl ToolOutput for ScreenSizeOutput {}
+
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
+pub struct CursorPositionOutput {
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "number_schema")]
+ pub x: Option<f64>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "number_schema")]
+ pub y: Option<f64>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "boolean_schema")]
+ pub available: Option<bool>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "string_schema")]
+ pub source: Option<String>,
+ #[serde(flatten)]
+ pub extensions: BTreeMap<String, Value>,
+}
+
+impl ToolOutput for CursorPositionOutput {}
+
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
+pub struct MoveCursorOutput {
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "desktop_scope_schema")]
+ pub scope: Option<DesktopScope>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "number_schema")]
+ pub x: Option<f64>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "number_schema")]
+ pub y: Option<f64>,
+ #[serde(flatten)]
+ pub extensions: BTreeMap<String, Value>,
+}
+
+impl ToolOutput for MoveCursorOutput {}
+
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
+pub struct ClickOutput {
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "desktop_scope_schema")]
+ pub scope: Option<DesktopScope>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "number_schema")]
+ pub x: Option<f64>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "number_schema")]
+ pub y: Option<f64>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "boolean_schema")]
+ pub verified: Option<bool>,
+ #[serde(flatten)]
+ pub extensions: BTreeMap<String, Value>,
+}
+
+impl ToolOutput for ClickOutput {}
+
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
+pub struct DesktopActionOutput {
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "desktop_scope_schema")]
+ pub scope: Option<DesktopScope>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "string_schema")]
+ pub effect: Option<String>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ #[schemars(schema_with = "boolean_schema")]
+ pub verified: Option<bool>,
+ #[serde(flatten)]
+ pub extensions: BTreeMap<String, Value>,
+}
+
+impl ToolOutput for DesktopActionOutput {}
+
+fn string_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
+ schemars::json_schema!({ "type": "string" })
+}
+
+fn boolean_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
+ schemars::json_schema!({ "type": "boolean" })
+}
+
+fn number_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
+ schemars::json_schema!({ "type": "number" })
+}
+
+fn integer_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
+ schemars::json_schema!({ "type": "integer" })
+}
+
+fn desktop_scope_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
+ schemars::json_schema!({ "const": "desktop" })
+}
+
+fn platform_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
+ schemars::json_schema!({
+ "type": "string",
+ "enum": ["macos", "linux", "windows"]
+ })
+}
+
+fn nullable_string_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
+ schemars::json_schema!({ "anyOf": [{ "type": "string" }, { "type": "null" }] })
+}
+
+fn nullable_escalation_reason_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
+ schemars::json_schema!({
+ "anyOf": [
+ {
+ "type": "string",
+ "enum": [
+ "ax_tree_pixel_mismatch",
+ "background_delivery_failed",
+ "foreground_ineffective",
+ "no_window_target",
+ "other"
+ ]
+ },
+ { "type": "null" }
+ ]
+ })
+}
diff --git a/libs/cua-driver/rust/crates/cua-driver-contract/src/session.rs b/libs/cua-driver/rust/crates/cua-driver-contract/src/session.rs
new file mode 100644
index 0000000000..3e6fef5d65
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver-contract/src/session.rs
@@ -0,0 +1,91 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 Cua AI, Inc.
+
+use crate::{
+ EndSessionInput, EndSessionOutput, EscalateSessionInput, GetSessionStateInput, Platform,
+ SchemaMode, SessionStateOutput, StartSessionInput, StartSessionOutput, ToolAnnotations,
+ ToolContract, ToolInput, ToolOutput,
+};
+
+const ALL_PLATFORMS: [Platform; 3] = [Platform::Macos, Platform::Windows, Platform::Linux];
+
+pub fn contracts() -> Vec<ToolContract> {
+ vec![start(), escalate(), get_state(), end()]
+}
+
+fn contract<I: ToolInput, O: ToolOutput>(
+ name: &str,
+ description: &str,
+ capabilities: &[&str],
+ annotations: ToolAnnotations,
+) -> ToolContract {
+ assert_eq!(name, I::TOOL_NAME, "typed input is bound to the wrong tool");
+ ToolContract {
+ name: name.into(),
+ description: description.into(),
+ platforms: ALL_PLATFORMS.to_vec(),
+ aliases: Vec::new(),
+ capabilities: capabilities.iter().map(|value| (*value).into()).collect(),
+ annotations,
+ schema_mode: SchemaMode::CanonicalRuntime,
+ input_schema: I::input_schema(),
+ success_output_schema: Some(O::output_schema()),
+ output_validator: crate::validate_typed_output::<O>,
+ }
+}
+
+fn start() -> ToolContract {
+ contract::<StartSessionInput, StartSessionOutput>(
+ "start_session",
+ "Declare a session — a named, color-coded identity for THIS agent run. Pass a stable `session` id and choose capture_scope=auto|window|desktop; the agent cursor, capture policy, per-session config, and recording all key on it, and it follows the run across any apps/windows. The cursor's color is derived from the id, so distinct runs are visually distinct. A cursor is shown only for a declared session — call this (or pass `session` on your first action) to opt in. Idempotent: re-calling with the same id just refreshes its idle-TTL. End it with `end_session` (or let the idle-TTL reclaim it). Concurrent runs/subagents each pass their own `session` to get their own cursor.",
+ &["session.lifecycle.start", "session.capture_scope"],
+ ToolAnnotations {
+ read_only: false,
+ destructive: false,
+ idempotent: true,
+ open_world: false,
+ },
+ )
+}
+
+fn escalate() -> ToolContract {
+ contract::<EscalateSessionInput, SessionStateOutput>(
+ "escalate_session",
+ "Unlock the desktop phase of an auto capture-scope session after the window action ladder has been exhausted and verified. This is a one-way transition for the live session and records a bounded reason.",
+ &["session.capture_scope.escalate"],
+ ToolAnnotations {
+ read_only: false,
+ destructive: false,
+ idempotent: false,
+ open_world: false,
+ },
+ )
+}
+
+fn get_state() -> ToolContract {
+ contract::<GetSessionStateInput, SessionStateOutput>(
+ "get_session_state",
+ "Read the live session's capture policy and effective scope.",
+ &["session.capture_scope.read"],
+ ToolAnnotations {
+ read_only: true,
+ destructive: false,
+ idempotent: true,
+ open_world: false,
+ },
+ )
+}
+
+fn end() -> ToolContract {
+ contract::<EndSessionInput, EndSessionOutput>(
+ "end_session",
+ "End a session declared with `start_session`: removes its agent cursor, stops any recording it owns, and clears its per-session config. Call this when a run finishes so its cursor doesn't linger (otherwise the idle-TTL reclaims it after a period of inactivity). Idempotent.",
+ &["session.lifecycle.end"],
+ ToolAnnotations {
+ read_only: false,
+ destructive: true,
+ idempotent: true,
+ open_world: false,
+ },
+ )
+}
diff --git a/libs/cua-driver/rust/crates/cua-driver-contract/uniffi.toml b/libs/cua-driver/rust/crates/cua-driver-contract/uniffi.toml
new file mode 100644
index 0000000000..d9791929f9
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver-contract/uniffi.toml
@@ -0,0 +1,2 @@
+[bindings.python]
+cdylib_name = "cua_driver_sdk"
diff --git a/libs/cua-driver/rust/crates/cua-driver-core/Cargo.toml b/libs/cua-driver/rust/crates/cua-driver-core/Cargo.toml
index 5b356bca66..2fa6f159a0 100644
--- a/libs/cua-driver/rust/crates/cua-driver-core/Cargo.toml
+++ b/libs/cua-driver/rust/crates/cua-driver-core/Cargo.toml
@@ -9,6 +9,7 @@ yaml = ["dep:serde_yaml_ng", "dep:regex"]
rego = ["dep:regorus"]
[dependencies]
+cua-driver-contract = { path = "../cua-driver-contract" }
tokio = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
diff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/capture_scope.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/capture_scope.rs
index e6e05d0061..3a7d4c3549 100644
--- a/libs/cua-driver/rust/crates/cua-driver-core/src/capture_scope.rs
+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/capture_scope.rs
@@ -5,94 +5,13 @@
//! policy state: doing so would let an anonymous proxy connection bypass the
//! per-session contract.
-use serde::{Deserialize, Serialize};
-use serde_json::{json, Value};
+use serde_json::Value;
use std::collections::HashMap;
-use std::fmt;
use std::sync::{Mutex, OnceLock};
-#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
-#[serde(rename_all = "snake_case")]
-pub enum CaptureScopePolicy {
- #[default]
- Auto,
- Window,
- Desktop,
-}
-
-impl CaptureScopePolicy {
- pub fn parse(value: &str) -> Option<Self> {
- match value {
- "auto" => Some(Self::Auto),
- "window" => Some(Self::Window),
- "desktop" => Some(Self::Desktop),
- _ => None,
- }
- }
-
- pub fn as_str(self) -> &'static str {
- match self {
- Self::Auto => "auto",
- Self::Window => "window",
- Self::Desktop => "desktop",
- }
- }
-}
-
-impl fmt::Display for CaptureScopePolicy {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- f.write_str(self.as_str())
- }
-}
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
-#[serde(rename_all = "snake_case")]
-pub enum EffectiveCaptureScope {
- Window,
- Desktop,
-}
-
-impl EffectiveCaptureScope {
- pub fn as_str(self) -> &'static str {
- match self {
- Self::Window => "window",
- Self::Desktop => "desktop",
- }
- }
-}
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
-#[serde(rename_all = "snake_case")]
-pub enum EscalationReason {
- AxTreePixelMismatch,
- BackgroundDeliveryFailed,
- ForegroundIneffective,
- NoWindowTarget,
- Other,
-}
-
-impl EscalationReason {
- pub fn parse(value: &str) -> Option<Self> {
- match value {
- "ax_tree_pixel_mismatch" => Some(Self::AxTreePixelMismatch),
- "background_delivery_failed" => Some(Self::BackgroundDeliveryFailed),
- "foreground_ineffective" => Some(Self::ForegroundIneffective),
- "no_window_target" => Some(Self::NoWindowTarget),
- "other" => Some(Self::Other),
- _ => None,
- }
- }
-
- pub fn as_str(self) -> &'static str {
- match self {
- Self::AxTreePixelMismatch => "ax_tree_pixel_mismatch",
- Self::BackgroundDeliveryFailed => "background_delivery_failed",
- Self::ForegroundIneffective => "foreground_ineffective",
- Self::NoWindowTarget => "no_window_target",
- Self::Other => "other",
- }
- }
-}
+pub use cua_driver_contract::{
+ CaptureScope as CaptureScopePolicy, EffectiveScope as EffectiveCaptureScope, EscalationReason,
+};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SessionCaptureScope {
@@ -122,14 +41,18 @@ impl SessionCaptureScope {
}
pub fn as_json(&self, session: &str) -> Value {
- json!({
- "session": session,
- "capture_scope": self.policy.as_str(),
- "effective_scope": self.effective_scope().as_str(),
- "desktop_unlocked": self.desktop_unlocked,
- "escalation_reason": self.escalation_reason.map(EscalationReason::as_str),
- "escalation_detail": self.escalation_detail,
- })
+ serde_json::to_value(self.output(session)).expect("session output serializes")
+ }
+
+ pub fn output(&self, session: &str) -> cua_driver_contract::SessionStateOutput {
+ cua_driver_contract::SessionStateOutput {
+ session: session.to_owned(),
+ capture_scope: self.policy,
+ effective_scope: self.effective_scope(),
+ desktop_unlocked: self.desktop_unlocked,
+ escalation_reason: self.escalation_reason,
+ escalation_detail: self.escalation_detail.clone(),
+ }
}
}
@@ -359,6 +282,7 @@ pub fn enforce_tool(tool_name: &str, args: &Value) -> Result<(), ScopeViolation>
#[cfg(test)]
mod tests {
use super::*;
+ use serde_json::json;
fn fresh(prefix: &str) -> String {
format!("capture-scope-{prefix}-{}", std::process::id())
diff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/daemon.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/daemon.rs
new file mode 100644
index 0000000000..7ece9c79c8
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/daemon.rs
@@ -0,0 +1,258 @@
+//! Shared Cua Driver daemon wire protocol and synchronous client.
+//!
+//! The daemon, CLI, MCP proxy, and imported SDK all use these exact request,
+//! response, probing, timeout, and framing rules. Keeping them outside the
+//! binary crate prevents language bindings from growing an independent
+//! implementation of the native transport.
+
+use serde::{Deserialize, Serialize};
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub enum ToolObservationOrigin {
+ McpProxy,
+ Direct,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct DaemonRequest {
+ pub method: String,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub name: Option<String>,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub args: Option<serde_json::Value>,
+ /// Transport-owned connection identity. Public session identity remains
+ /// in `args.session`; callers must not use this field to select policy.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub session_id: Option<String>,
+ /// Bounded internal routing metadata for exactly-once completion
+ /// observation. Older peers ignore this additive field.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub observation_origin: Option<ToolObservationOrigin>,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct DaemonResponse {
+ pub ok: bool,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub result: Option<serde_json::Value>,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub error: Option<String>,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub exit_code: Option<i32>,
+}
+
+impl DaemonResponse {
+ pub fn ok(result: serde_json::Value) -> Self {
+ Self {
+ ok: true,
+ result: Some(result),
+ error: None,
+ exit_code: None,
+ }
+ }
+
+ pub fn err(message: impl Into<String>, exit_code: i32) -> Self {
+ Self {
+ ok: false,
+ result: None,
+ error: Some(message.into()),
+ exit_code: Some(exit_code),
+ }
+ }
+}
+
+/// Return the platform socket or pipe path for an installed-product namespace.
+/// The executable chooses its release/local namespace; imported SDKs use the
+/// release namespace unless the caller supplies an explicit path.
+pub fn socket_path_for_namespace(namespace: &str) -> String {
+ #[cfg(target_os = "macos")]
+ {
+ let home = std::env::var("HOME").unwrap_or_else(|_| "/tmp".into());
+ format!("{home}/Library/Caches/{namespace}/{namespace}.sock")
+ }
+ #[cfg(target_os = "linux")]
+ {
+ let home = std::env::var("HOME").unwrap_or_else(|_| "/tmp".into());
+ format!("{home}/.cache/{namespace}/{namespace}.sock")
+ }
+ #[cfg(target_os = "windows")]
+ {
+ format!(r"\\.\pipe\{namespace}")
+ }
+ #[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
+ {
+ format!("/tmp/{namespace}.sock")
+ }
+}
+
+/// Probe whether a daemon is listening on `socket_path`.
+///
+/// On Windows this uses `WaitNamedPipeW` without consuming a pipe instance.
+/// Unix probes with the protocol's read-only `list` request.
+pub fn is_daemon_listening(socket_path: &str) -> bool {
+ #[cfg(target_os = "windows")]
+ {
+ use std::os::windows::ffi::OsStrExt;
+
+ #[link(name = "kernel32")]
+ extern "system" {
+ fn WaitNamedPipeW(lp_named_pipe_name: *const u16, timeout_ms: u32) -> i32;
+ }
+
+ let wide: Vec<u16> = std::ffi::OsStr::new(socket_path)
+ .encode_wide()
+ .chain(std::iter::once(0))
+ .collect();
+ // NMPWAIT_NOWAIT == 1.
+ unsafe { WaitNamedPipeW(wide.as_ptr(), 1) != 0 }
+ }
+ #[cfg(not(target_os = "windows"))]
+ {
+ let request = DaemonRequest {
+ method: "list".into(),
+ name: None,
+ args: None,
+ session_id: None,
+ observation_origin: None,
+ };
+ send_request(socket_path, &request)
+ .ok()
+ .is_some_and(|response| response.ok)
+ }
+}
+
+/// Send one newline-delimited request and read one response.
+///
+/// Unix reads and writes retry transient timeouts until a 120-second overall
+/// deadline so slow accessibility walks and large screenshots are supported.
+#[cfg(unix)]
+pub fn send_request(socket_path: &str, request: &DaemonRequest) -> anyhow::Result<DaemonResponse> {
+ use std::io::Read;
+ use std::os::unix::net::UnixStream;
+ use std::time::{Duration, Instant};
+
+ let mut stream = UnixStream::connect(socket_path)
+ .map_err(|error| anyhow::anyhow!("connect to {socket_path}: {error}"))?;
+ stream.set_write_timeout(Some(Duration::from_secs(5)))?;
+ stream.set_read_timeout(Some(Duration::from_secs(10)))?;
+
+ let mut writer = stream.try_clone()?;
+ let line = serde_json::to_string(request)? + "\n";
+ let write_deadline = Instant::now() + Duration::from_secs(120);
+ crate::socket_io::write_all_with_retry(&mut writer, line.as_bytes(), write_deadline)?;
+
+ let overall_deadline = Instant::now() + Duration::from_secs(120);
+ let mut buffer = Vec::with_capacity(64 * 1024);
+ let mut chunk = [0_u8; 64 * 1024];
+ let response_line = loop {
+ if let Some(newline) = buffer.iter().position(|&byte| byte == b'\n') {
+ break String::from_utf8_lossy(&buffer[..newline]).into_owned();
+ }
+ match stream.read(&mut chunk) {
+ Ok(0) if buffer.is_empty() => {
+ anyhow::bail!("daemon closed connection without response");
+ }
+ Ok(0) => break String::from_utf8_lossy(&buffer).into_owned(),
+ Ok(read) => buffer.extend_from_slice(&chunk[..read]),
+ Err(error) if error.kind() == std::io::ErrorKind::Interrupted => continue,
+ Err(error)
+ if matches!(
+ error.kind(),
+ std::io::ErrorKind::WouldBlock | std::io::ErrorKind::TimedOut
+ ) =>
+ {
+ if Instant::now() >= overall_deadline {
+ anyhow::bail!(
+ "timed out after 120s waiting for daemon response (received {} bytes so far)",
+ buffer.len()
+ );
+ }
+ }
+ Err(error) => return Err(error.into()),
+ }
+ };
+
+ Ok(serde_json::from_str(&response_line)?)
+}
+
+#[cfg(not(unix))]
+pub fn send_request(socket_path: &str, request: &DaemonRequest) -> anyhow::Result<DaemonResponse> {
+ #[cfg(target_os = "windows")]
+ {
+ use std::io::{BufRead, BufReader, Write};
+ use std::time::Duration;
+
+ let deadline = std::time::Instant::now() + Duration::from_secs(3);
+ let pipe = loop {
+ match std::fs::OpenOptions::new()
+ .read(true)
+ .write(true)
+ .open(socket_path)
+ {
+ Ok(pipe) => break pipe,
+ Err(_) if std::time::Instant::now() < deadline => {
+ std::thread::sleep(Duration::from_millis(50));
+ }
+ Err(error) => anyhow::bail!("connect to named pipe {socket_path}: {error}"),
+ }
+ };
+
+ let mut writer = pipe.try_clone()?;
+ writer.write_all((serde_json::to_string(request)? + "\n").as_bytes())?;
+ writer.flush()?;
+
+ let response_line = BufReader::new(pipe)
+ .lines()
+ .next()
+ .ok_or_else(|| anyhow::anyhow!("daemon closed connection without response"))??;
+ Ok(serde_json::from_str(&response_line)?)
+ }
+ #[cfg(not(target_os = "windows"))]
+ {
+ anyhow::bail!("daemon client not supported on this platform (socket path: {socket_path})");
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::{socket_path_for_namespace, DaemonRequest, DaemonResponse, ToolObservationOrigin};
+
+ #[test]
+ fn socket_path_keeps_the_selected_namespace() {
+ let path = socket_path_for_namespace("cua-driver-test");
+ assert!(path.contains("cua-driver-test"));
+ }
+
+ #[test]
+ fn legacy_request_without_additive_fields_deserializes() {
+ let request: DaemonRequest = serde_json::from_value(serde_json::json!({
+ "method": "call",
+ "name": "get_screen_size",
+ "args": {}
+ }))
+ .unwrap();
+ assert_eq!(request.session_id, None);
+ assert_eq!(request.observation_origin, None);
+ }
+
+ #[test]
+ fn response_helpers_preserve_wire_shape() {
+ let ok = DaemonResponse::ok(serde_json::json!({"value": 1}));
+ assert!(ok.ok);
+ assert_eq!(ok.result.unwrap()["value"], 1);
+
+ let error = DaemonResponse::err("nope", 64);
+ assert!(!error.ok);
+ assert_eq!(error.error.as_deref(), Some("nope"));
+ assert_eq!(error.exit_code, Some(64));
+ }
+
+ #[test]
+ fn observation_origin_is_snake_case() {
+ assert_eq!(
+ serde_json::to_value(ToolObservationOrigin::McpProxy).unwrap(),
+ "mcp_proxy"
+ );
+ }
+}
diff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/lib.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/lib.rs
index 3a22669594..750a1cbaaf 100644
--- a/libs/cua-driver/rust/crates/cua-driver-core/src/lib.rs
+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/lib.rs
@@ -39,6 +39,7 @@ pub mod capture_scope;
pub mod cdp;
pub mod consent;
pub mod cursor_sampler;
+pub mod daemon;
pub mod element_cache;
pub mod element_token;
pub mod ffmpeg_install;
diff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/session_tools.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/session_tools.rs
index def290844b..4797b83442 100644
--- a/libs/cua-driver/rust/crates/cua-driver-core/src/session_tools.rs
+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/session_tools.rs
@@ -11,13 +11,15 @@
//! fields, but lifecycle and policy tools accept only the public `session`
//! name. Transport metadata can never mint or alter capture policy.
-use crate::capture_scope::{
- bind_session, escalate_session, get_session, BindError, CaptureScopePolicy, EscalateError,
- EscalationReason,
-};
+use crate::capture_scope::{bind_session, escalate_session, get_session, BindError, EscalateError};
use crate::protocol::ToolResult;
use crate::tool::{Tool, ToolDef};
+use crate::tool_args::parse_typed_input;
use async_trait::async_trait;
+use cua_driver_contract::{
+ CaptureScope, EndSessionInput, EscalateSessionInput, EscalationReason, GetSessionStateInput,
+ StartSessionInput,
+};
use serde_json::{json, Value};
use std::sync::OnceLock;
@@ -31,27 +33,6 @@ fn session_id_of(args: &Value) -> Option<String> {
.map(|s| s.to_owned())
}
-fn capture_scope_arg(args: &Value) -> Result<Option<CaptureScopePolicy>, ToolResult> {
- let Some(raw) = args.get("capture_scope") else {
- return Ok(None);
- };
- let Some(raw) = raw.as_str() else {
- return Err(ToolResult::error(
- "start_session.capture_scope must be one of: auto, window, desktop.",
- )
- .with_structured(json!({ "code": "invalid_capture_scope" })));
- };
- CaptureScopePolicy::parse(raw).map(Some).ok_or_else(|| {
- ToolResult::error(format!(
- "invalid capture_scope '{raw}'; expected auto, window, or desktop"
- ))
- .with_structured(json!({
- "code": "invalid_capture_scope",
- "capture_scope": raw,
- }))
- })
-}
-
// ── start_session ─────────────────────────────────────────────────────────────
pub struct StartSessionTool;
@@ -61,52 +42,35 @@ static START_DEF: OnceLock<ToolDef> = OnceLock::new();
#[async_trait]
impl Tool for StartSessionTool {
fn def(&self) -> &ToolDef {
- START_DEF.get_or_init(|| ToolDef {
- name: "start_session".into(),
- description:
- "Declare a session — a named, color-coded identity for THIS agent run. \
- Pass a stable `session` id and choose capture_scope=auto|window|desktop; \
- the agent cursor, capture policy, per-session config, and recording all \
- key on it, and it follows the run across any apps/windows. \
- The cursor's color is derived from the id, so distinct runs are visually \
- distinct. A cursor is shown only for a declared session — call this (or \
- pass `session` on your first action) to opt in. Idempotent: re-calling \
- with the same id just refreshes its idle-TTL. End it with `end_session` \
- (or let the idle-TTL reclaim it). Concurrent runs/subagents each pass \
- their own `session` to get their own cursor."
- .into(),
- input_schema: json!({
- "type": "object",
- "required": ["session"],
- "properties": {
- "session": {
- "type": "string",
- "description": "Stable session id for this run (e.g. \"research-run-1\")."
- },
- "capture_scope": {
- "type": "string",
- "enum": ["auto", "window", "desktop"],
- "default": "auto",
- "description": "Per-session perception/action modality. auto starts window-only and requires explicit escalation before desktop tools; window and desktop are strict. Immutable for the live session."
- }
- },
- "additionalProperties": true
- }),
- read_only: false,
- destructive: false,
- idempotent: true,
- open_world: false,
- })
+ START_DEF.get_or_init(|| session_tool_def("start_session"))
}
async fn invoke(&self, args: Value) -> ToolResult {
let Some(id) = session_id_of(&args) else {
return ToolResult::error("start_session requires a non-empty `session` id.");
};
- let requested = match capture_scope_arg(&args) {
- Ok(scope) => scope,
+ if let Some(raw) = args.get("capture_scope") {
+ let Some(raw) = raw.as_str() else {
+ return ToolResult::error(
+ "start_session.capture_scope must be one of: auto, window, desktop.",
+ )
+ .with_structured(json!({ "code": "invalid_capture_scope" }));
+ };
+ if CaptureScope::parse(raw).is_none() {
+ return ToolResult::error(format!(
+ "invalid capture_scope '{raw}'; expected auto, window, or desktop"
+ ))
+ .with_structured(json!({
+ "code": "invalid_capture_scope",
+ "capture_scope": raw,
+ }));
+ }
+ }
+ let input = match parse_typed_input::<StartSessionInput>("start_session", args) {
+ Ok(input) => input,
Err(result) => return result,
};
+ let requested = input.capture_scope;
let was_ended = crate::session::is_session_ended(&id);
if !was_ended {
match bind_session(&id, requested) {
@@ -163,11 +127,12 @@ impl Tool for StartSessionTool {
// Refresh (or begin) the session's idle-TTL clock. The cursor appears on
// the first action carrying this `session`.
crate::session::touch_session(&id);
- let mut structured = scope.as_json(&id);
- if let Some(object) = structured.as_object_mut() {
- object.insert("active".to_owned(), Value::Bool(true));
- object.insert("revived".to_owned(), Value::Bool(revived));
- }
+ let structured = serde_json::to_value(cua_driver_contract::StartSessionOutput {
+ state: scope.output(&id),
+ active: true,
+ revived,
+ })
+ .expect("start_session output serializes");
ToolResult::text(format!(
"✅ Session '{id}' is active with capture_scope='{}'.",
scope.policy
@@ -185,37 +150,7 @@ static ESCALATE_DEF: OnceLock<ToolDef> = OnceLock::new();
#[async_trait]
impl Tool for EscalateSessionTool {
fn def(&self) -> &ToolDef {
- ESCALATE_DEF.get_or_init(|| ToolDef {
- name: "escalate_session".into(),
- description: "Unlock the desktop phase of an auto capture-scope session after the window action ladder has been exhausted and verified. This is a one-way transition for the live session and records a bounded reason.".into(),
- input_schema: json!({
- "type": "object",
- "required": ["session", "reason"],
- "properties": {
- "session": { "type": "string" },
- "reason": {
- "type": "string",
- "enum": [
- "ax_tree_pixel_mismatch",
- "background_delivery_failed",
- "foreground_ineffective",
- "no_window_target",
- "other"
- ]
- },
- "detail": {
- "type": "string",
- "maxLength": 200,
- "description": "Optional bounded diagnostic detail. Never use secrets or page content."
- }
- },
- "additionalProperties": true
- }),
- read_only: false,
- destructive: false,
- idempotent: false,
- open_world: false,
- })
+ ESCALATE_DEF.get_or_init(|| session_tool_def("escalate_session"))
}
async fn invoke(&self, args: Value) -> ToolResult {
@@ -223,16 +158,28 @@ impl Tool for EscalateSessionTool {
return ToolResult::error("escalate_session requires a public `session` id.")
.with_structured(json!({ "code": "session_required" }));
};
- let Some(reason) = args
+ if args
.get("reason")
.and_then(Value::as_str)
.and_then(EscalationReason::parse)
- else {
+ .is_none()
+ {
return ToolResult::error("escalate_session.reason is invalid.")
.with_structured(json!({ "code": "invalid_escalation_reason" }));
+ }
+ let input = match parse_typed_input::<EscalateSessionInput>("escalate_session", args) {
+ Ok(input) => input,
+ Err(result) => return result,
};
- let detail = args.get("detail").and_then(Value::as_str);
- match escalate_session(&id, reason, detail) {
+ if input
+ .detail
+ .as_ref()
+ .is_some_and(|detail| detail.chars().count() > 200)
+ {
+ return ToolResult::error("escalate_session.detail must be at most 200 characters.")
+ .with_structured(json!({ "code": "invalid_escalation_detail" }));
+ }
+ match escalate_session(&id, input.reason, input.detail.as_deref()) {
Ok(state) => ToolResult::text(format!("✅ Session '{id}' escalated to desktop scope."))
.with_structured(state.as_json(&id)),
Err(error) => {
@@ -272,20 +219,7 @@ static GET_STATE_DEF: OnceLock<ToolDef> = OnceLock::new();
#[async_trait]
impl Tool for GetSessionStateTool {
fn def(&self) -> &ToolDef {
- GET_STATE_DEF.get_or_init(|| ToolDef {
- name: "get_session_state".into(),
- description: "Read the live session's capture policy and effective scope.".into(),
- input_schema: json!({
- "type": "object",
- "required": ["session"],
- "properties": { "session": { "type": "string" } },
- "additionalProperties": true
- }),
- read_only: true,
- destructive: false,
- idempotent: true,
- open_world: false,
- })
+ GET_STATE_DEF.get_or_init(|| session_tool_def("get_session_state"))
}
async fn invoke(&self, args: Value) -> ToolResult {
@@ -293,6 +227,9 @@ impl Tool for GetSessionStateTool {
return ToolResult::error("get_session_state requires a public `session` id.")
.with_structured(json!({ "code": "session_required" }));
};
+ if let Err(result) = parse_typed_input::<GetSessionStateInput>("get_session_state", args) {
+ return result;
+ }
let Some(state) = get_session(&id) else {
return ToolResult::error(format!("session '{id}' is not active"))
.with_structured(json!({ "code": "session_not_started", "session": id }));
@@ -315,41 +252,33 @@ static END_DEF: OnceLock<ToolDef> = OnceLock::new();
#[async_trait]
impl Tool for EndSessionTool {
fn def(&self) -> &ToolDef {
- END_DEF.get_or_init(|| ToolDef {
- name: "end_session".into(),
- description: "End a session declared with `start_session`: removes its agent cursor, \
- stops any recording it owns, and clears its per-session config. Call this \
- when a run finishes so its cursor doesn't linger (otherwise the idle-TTL \
- reclaims it after a period of inactivity). Idempotent."
- .into(),
- input_schema: json!({
- "type": "object",
- "required": ["session"],
- "properties": {
- "session": {
- "type": "string",
- "description": "The session id to end."
- }
- },
- "additionalProperties": true
- }),
- read_only: false,
- destructive: true,
- idempotent: true,
- open_world: false,
- })
+ END_DEF.get_or_init(|| session_tool_def("end_session"))
}
async fn invoke(&self, args: Value) -> ToolResult {
let Some(id) = session_id_of(&args) else {
return ToolResult::error("end_session requires a non-empty `session` id.");
};
+ if let Err(result) = parse_typed_input::<EndSessionInput>("end_session", args) {
+ return result;
+ }
crate::session::end_session(&id);
- ToolResult::text(format!("✅ Session '{id}' ended."))
- .with_structured(json!({ "session": id, "active": false }))
+ ToolResult::text(format!("✅ Session '{id}' ended.")).with_structured(
+ serde_json::to_value(cua_driver_contract::EndSessionOutput {
+ session: id,
+ active: false,
+ })
+ .expect("end_session output serializes"),
+ )
}
}
+fn session_tool_def(name: &str) -> ToolDef {
+ let contract = cua_driver_contract::tool_contract(name)
+ .unwrap_or_else(|| panic!("canonical contract missing {name}"));
+ ToolDef::from_contract(&contract)
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/tool.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/tool.rs
index d6cd558de6..2a05cfe30c 100644
--- a/libs/cua-driver/rust/crates/cua-driver-core/src/tool.rs
+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/tool.rs
@@ -17,14 +17,7 @@ use crate::{
tool_args::ArgsExt,
};
-/// MCP `tools/list` capability-vocabulary version. Bumped on BREAKING
-/// changes only (renaming a capability token, removing a capability
-/// claim from a tool). Additive changes — new capability tokens, new
-/// tools, new tools that newly claim an existing token — keep the
-/// version. Downstream consumers (Hermes, Codex) read this to gate
-/// strict-vs-tolerant capability matching. See
-/// `default_capabilities_for` for the live vocabulary.
-pub const CAPABILITY_VERSION: &str = "1";
+pub use cua_driver_contract::{CAPABILITY_VERSION, TOOLS_LIST_SCHEMA_VERSION};
/// Metadata for a single tool.
#[derive(Debug, Clone)]
@@ -39,17 +32,33 @@ pub struct ToolDef {
}
impl ToolDef {
+ /// Build the runtime MCP definition from a canonical client contract.
+ /// Only migrated tools use this bridge; platform-specific tools continue
+ /// to own their live schemas until they can pass parity checks.
+ pub fn from_contract(contract: &cua_driver_contract::ToolContract) -> Self {
+ assert_eq!(
+ contract.schema_mode,
+ cua_driver_contract::SchemaMode::CanonicalRuntime,
+ "portable subset contracts cannot replace live runtime schemas"
+ );
+ Self {
+ name: contract.name.clone(),
+ description: contract.description.clone(),
+ input_schema: contract.input_schema.clone(),
+ read_only: contract.annotations.read_only,
+ destructive: contract.annotations.destructive,
+ idempotent: contract.annotations.idempotent,
+ open_world: contract.annotations.open_world,
+ }
+ }
+
pub fn to_list_entry(&self) -> Value {
// `capabilities` is always emitted (even when empty) so consumers
// can rely on the key existing. Additive only — old consumers
// that ignore the field keep working unchanged.
//
- // Capabilities are resolved from the centralised
- // `default_capabilities_for` name → tokens map. Keeping the
- // mapping in one place — rather than scattered across every
- // per-platform tool literal — means adding a new capability
- // claim is a one-file change, and sibling PRs touching
- // individual tool files don't conflict with this surface.
+ // Published SDK tools resolve capabilities from their typed Rust
+ // contract. The legacy map remains only for runtime-only tools.
let caps = default_capabilities_for(&self.name);
let risk = crate::authorization::risk_metadata_json(&self.name);
serde_json::json!({
@@ -114,6 +123,9 @@ impl ToolDef {
/// Tools with no entry get `[]` — that's fine, it just means
/// downstream consumers fall back to matching by tool name for them.
pub fn default_capabilities_for(tool_name: &str) -> Vec<String> {
+ if let Some(capabilities) = cua_driver_contract::tool_capabilities(tool_name) {
+ return capabilities;
+ }
let caps: &[&str] = match tool_name {
// ── input.pointer ────────────────────────────────────────────
//
@@ -122,11 +134,6 @@ pub fn default_capabilities_for(tool_name: &str) -> Vec<String> {
// `accessibility.element_tokens` token so consumers can branch
// on its presence — Hermes' wrapper currently does this by name
// for each tool; the capability token removes that coupling.
- "click" => &[
- "input.pointer.click",
- "input.pointer.click.left",
- "accessibility.element_tokens",
- ],
"double_click" => &[
"input.pointer.click",
"input.pointer.click.left",
@@ -138,19 +145,10 @@ pub fn default_capabilities_for(tool_name: &str) -> Vec<String> {
"input.pointer.click.right",
"accessibility.element_tokens",
],
- "drag" => &["input.pointer.drag"],
"mouse_drag" => &["input.pointer.drag"],
"parallel_mouse_drag" => &["input.pointer.drag"],
"mouse_button_down" => &["input.pointer.button"],
"mouse_button_up" => &["input.pointer.button"],
- "scroll" => &["input.pointer.scroll", "accessibility.element_tokens"],
- "move_cursor" => &[
- // Window scope moves the agent overlay; explicit desktop scope
- // moves the real OS pointer.
- "agent_cursor.move",
- "input.pointer.move",
- ],
-
// ── input.keyboard ───────────────────────────────────────────
// `type_text` claims `terminal_safe` because every platform
// implementation detects terminal-emulator targets (bundle id
@@ -161,11 +159,6 @@ pub fn default_capabilities_for(tool_name: &str) -> Vec<String> {
// Terminal / mintty / GVim, etc. See the per-platform
// `terminal` module for the matched list and the structured
// `path: "ax" | "key_events"` field on the response.
- "type_text" => &[
- "input.keyboard.type",
- "input.keyboard.type.terminal_safe",
- "accessibility.element_tokens",
- ],
// `type_text_chars` is a deprecated alias resolved at invoke
// time on macOS/Windows. On Linux it's still registered (see
// platform-linux/impl_.rs). The Linux implementation runs
@@ -174,8 +167,6 @@ pub fn default_capabilities_for(tool_name: &str) -> Vec<String> {
// contract is intentionally narrower than `type_text`'s. It
// still accepts `element_token`, hence the tokens claim.
"type_text_chars" => &["input.keyboard.type", "accessibility.element_tokens"],
- "press_key" => &["input.keyboard.press", "accessibility.element_tokens"],
- "hotkey" => &["input.keyboard.hotkey"],
"set_value" => &[
// Bulk-set an editable field's value — semantically a
// typing surface, even though the implementation skips
@@ -194,10 +185,6 @@ pub fn default_capabilities_for(tool_name: &str) -> Vec<String> {
"screen.capture.window",
"screen.capture.region",
],
- "get_screen_size" => &["screen.dimensions"],
- "get_desktop_state" => &["screen.capture", "screen.dimensions"],
- "get_cursor_position" => &["screen.cursor.position"],
-
// ── accessibility / window state ─────────────────────────────
"get_accessibility_tree" => &["accessibility.tree", "accessibility.tree.structured"],
"get_window_state" => &[
@@ -237,12 +224,6 @@ pub fn default_capabilities_for(tool_name: &str) -> Vec<String> {
"get_config" => &["system.config.read"],
"set_config" => &["system.config.write"],
- // ── sessions ─────────────────────────────────────────────────
- "start_session" => &["session.lifecycle.start", "session.capture_scope"],
- "escalate_session" => &["session.capture_scope.escalate"],
- "get_session_state" => &["session.capture_scope.read"],
- "end_session" => &["session.lifecycle.end"],
-
// ── agent cursor ─────────────────────────────────────────────
"set_agent_cursor_enabled" => &["agent_cursor.set_enabled"],
"set_agent_cursor_motion" => &["agent_cursor.set_motion"],
@@ -369,7 +350,7 @@ impl ToolRegistry {
serde_json::json!({
"tools": list,
"capability_version": CAPABILITY_VERSION,
- "schema_version": "1",
+ "schema_version": TOOLS_LIST_SCHEMA_VERSION,
})
}
@@ -441,7 +422,30 @@ impl ToolRegistry {
})
.flatten();
- let result = tool.invoke(args.clone()).await;
+ let mut result = tool.invoke(args.clone()).await;
+ let validate_portable_output = match resolved_name {
+ "get_desktop_state" | "get_screen_size" | "get_cursor_position" => true,
+ "move_cursor" | "click" | "drag" | "scroll" | "type_text" | "press_key" | "hotkey" => {
+ args.get("scope").and_then(Value::as_str) == Some("desktop")
+ }
+ _ => true,
+ };
+ if result.is_error != Some(true) && validate_portable_output {
+ if let Some(structured) = result.structured_content.clone() {
+ if let Err(error) =
+ cua_driver_contract::validate_success_output(resolved_name, structured)
+ {
+ result = ToolResult::error(format!(
+ "internal typed output mismatch for {resolved_name}: {error}"
+ ))
+ .with_structured(serde_json::json!({
+ "code": "typed_output_mismatch",
+ "tool": resolved_name,
+ "detail": error,
+ }));
+ }
+ }
+ }
// Use the original name for downstream code paths below so the
// exit-code matching and recording paths keep treating the alias
// as a distinct call site.
diff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/tool_args.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/tool_args.rs
index b357fcf568..4282bb54fb 100644
--- a/libs/cua-driver/rust/crates/cua-driver-core/src/tool_args.rs
+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/tool_args.rs
@@ -26,10 +26,58 @@
//! See `libs/cua-driver/rust/docs/dedup-audit.md` for the audit trail
//! that motivated this extraction.
-use serde_json::Value;
+use serde::de::DeserializeOwned;
+use serde_json::{json, Value};
use crate::protocol::ToolResult;
+/// Deserialize one transport-free Rust input type from MCP arguments.
+///
+/// Published SDK tools use this before invoking platform behavior, so the
+/// generated schema and the live parser share the same Rust definition.
+pub fn parse_typed_input<T: DeserializeOwned>(
+ tool_name: &str,
+ mut args: Value,
+) -> Result<T, ToolResult> {
+ // Public callers cannot supply reserved arguments: ingress strips them
+ // before trusted session/approval context is injected. Keep that internal
+ // transport metadata out of the transport-free contract types as well.
+ sanitize_reserved_args(&mut args);
+ serde_json::from_value(args).map_err(|error| {
+ ToolResult::error(format!("{tool_name}: invalid arguments: {error}")).with_structured(
+ json!({
+ "code": "invalid_arguments",
+ "tool": tool_name,
+ "detail": error.to_string(),
+ }),
+ )
+ })
+}
+
+/// Deserialize the portable portion of a richer live tool input.
+///
+/// Platform handlers may accept window-targeting or diagnostic fields that are
+/// intentionally absent from the generated cross-platform SDK method. This
+/// projects only fields owned by the portable Rust type, then deserializes that
+/// type so both surfaces share field names, types, enums, and defaults without
+/// rejecting legitimate platform-rich arguments.
+pub fn parse_typed_projection<T: cua_driver_contract::ToolInput>(
+ tool_name: &str,
+ args: &Value,
+) -> Result<T, ToolResult> {
+ let Some(source) = args.as_object() else {
+ return parse_typed_input(tool_name, args.clone());
+ };
+ let properties = cua_driver_contract::tool_input_fields(T::TOOL_NAME)
+ .expect("typed tool input is indexed in the published contract");
+ let projected = source
+ .iter()
+ .filter(|(name, _)| properties.contains(*name))
+ .map(|(name, value)| (name.clone(), value.clone()))
+ .collect();
+ parse_typed_input(tool_name, Value::Object(projected))
+}
+
/// Remove transport-reserved arguments supplied by a public caller. Trusted
/// ingress code calls this before injecting session or approval context, so a
/// tool request cannot forge underscore-prefixed transport evidence.
@@ -41,7 +89,8 @@ pub fn sanitize_reserved_args(args: &mut Value) {
#[cfg(test)]
mod reserved_args_tests {
- use super::sanitize_reserved_args;
+ use super::{parse_typed_input, parse_typed_projection, sanitize_reserved_args};
+ use cua_driver_contract::{ClickButton, ClickInput, GetScreenSizeInput};
use serde_json::json;
#[test]
@@ -61,6 +110,60 @@ mod reserved_args_tests {
})
);
}
+
+ #[test]
+ fn typed_input_ignores_trusted_transport_metadata_but_rejects_public_unknown_fields() {
+ let input = parse_typed_input::<GetScreenSizeInput>(
+ "get_screen_size",
+ json!({"session": "public", "_session_id": "trusted"}),
+ )
+ .expect("trusted transport metadata is not part of the public contract");
+ assert_eq!(input.session.as_deref(), Some("public"));
+
+ let error = parse_typed_input::<GetScreenSizeInput>(
+ "get_screen_size",
+ json!({"pid": 42, "_session_id": "trusted"}),
+ )
+ .expect_err("ordinary unknown fields remain invalid");
+ assert_eq!(error.is_error, Some(true));
+ assert!(matches!(
+ &error.content[0],
+ crate::protocol::Content::Text { text, .. }
+ if text.contains("unknown field `pid`")
+ ));
+ }
+
+ #[test]
+ fn typed_projection_preserves_rich_platform_fields_without_bypassing_portable_types() {
+ let input = parse_typed_projection::<ClickInput>(
+ "click",
+ &json!({
+ "x": 10,
+ "y": 20.5,
+ "scope": "desktop",
+ "button": "right",
+ "pid": 42,
+ "delivery_mode": "foreground"
+ }),
+ )
+ .expect("rich fields are projected away");
+ assert_eq!(input.x, 10.0);
+ assert_eq!(input.button, Some(ClickButton::Right));
+
+ let error = parse_typed_projection::<ClickInput>(
+ "click",
+ &json!({"x": "10", "y": 20, "scope": "desktop", "pid": 42}),
+ )
+ .expect_err("portable field types are still enforced");
+ assert_eq!(error.is_error, Some(true));
+ assert_eq!(
+ error
+ .structured_content
+ .as_ref()
+ .and_then(|value| value.get("code")),
+ Some(&json!("invalid_arguments"))
+ );
+ }
}
/// Format the canonical "missing required field" error.
diff --git a/libs/cua-driver/rust/crates/cua-driver-core/tests/contract_parity.rs b/libs/cua-driver/rust/crates/cua-driver-core/tests/contract_parity.rs
new file mode 100644
index 0000000000..18291a7e97
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver-core/tests/contract_parity.rs
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 Cua AI, Inc.
+
+use cua_driver_contract::{manifest, SchemaMode, CAPABILITY_VERSION, TOOLS_LIST_SCHEMA_VERSION};
+use cua_driver_core::tool::{default_capabilities_for, ToolRegistry};
+
+#[test]
+fn canonical_session_contract_matches_live_registry() {
+ let mut registry = ToolRegistry::new();
+ registry.register_session_tools();
+ let live = registry.tools_list();
+
+ assert_eq!(live["schema_version"], TOOLS_LIST_SCHEMA_VERSION);
+ assert_eq!(live["capability_version"], CAPABILITY_VERSION);
+
+ for contract in manifest()
+ .tools
+ .into_iter()
+ .filter(|contract| contract.schema_mode == SchemaMode::CanonicalRuntime)
+ {
+ let entry = live["tools"]
+ .as_array()
+ .expect("live tools array")
+ .iter()
+ .find(|entry| entry["name"] == contract.name)
+ .unwrap_or_else(|| panic!("{} missing from live registry", contract.name));
+ assert_eq!(entry["description"], contract.description, "description");
+ assert_eq!(entry["inputSchema"], contract.input_schema, "inputSchema");
+ assert_eq!(
+ entry["annotations"]["readOnlyHint"], contract.annotations.read_only,
+ "readOnlyHint"
+ );
+ assert_eq!(
+ entry["annotations"]["destructiveHint"], contract.annotations.destructive,
+ "destructiveHint"
+ );
+ assert_eq!(
+ entry["annotations"]["idempotentHint"], contract.annotations.idempotent,
+ "idempotentHint"
+ );
+ assert_eq!(
+ entry["annotations"]["openWorldHint"], contract.annotations.open_world,
+ "openWorldHint"
+ );
+ assert_eq!(
+ default_capabilities_for(&contract.name),
+ contract.capabilities,
+ "capabilities"
+ );
+ assert_eq!(
+ entry["capabilities"],
+ serde_json::json!(contract.capabilities)
+ );
+ }
+}
+
+#[test]
+fn every_generated_contract_uses_live_capability_tokens() {
+ for contract in manifest().tools {
+ assert_eq!(
+ default_capabilities_for(&contract.name),
+ contract.capabilities,
+ "{} capabilities",
+ contract.name
+ );
+ }
+}
diff --git a/libs/cua-driver/rust/crates/cua-driver-sdk/Cargo.toml b/libs/cua-driver/rust/crates/cua-driver-sdk/Cargo.toml
new file mode 100644
index 0000000000..df60e51445
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver-sdk/Cargo.toml
@@ -0,0 +1,24 @@
+[package]
+name = "cua-driver-sdk"
+version.workspace = true
+edition.workspace = true
+authors.workspace = true
+license.workspace = true
+repository.workspace = true
+description = "UniFFI-backed imported SDK for the Cua Driver daemon"
+publish = false
+
+[lib]
+crate-type = ["rlib", "cdylib"]
+
+[dependencies]
+cua-driver-contract = { path = "../cua-driver-contract" }
+cua-driver-core = { path = "../cua-driver-core", default-features = false }
+serde = { workspace = true }
+serde_json = { workspace = true }
+thiserror = { workspace = true }
+uniffi.workspace = true
+
+[dev-dependencies]
+tempfile = "3"
+uniffi = { workspace = true, features = ["bindgen"] }
diff --git a/libs/cua-driver/rust/crates/cua-driver-sdk/build.rs b/libs/cua-driver/rust/crates/cua-driver-sdk/build.rs
new file mode 100644
index 0000000000..dce50e269d
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver-sdk/build.rs
@@ -0,0 +1,5 @@
+fn main() {
+ if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("macos") {
+ println!("cargo:rustc-cdylib-link-arg=-Wl,-install_name,@rpath/libcua_driver_sdk.dylib");
+ }
+}
diff --git a/libs/cua-driver/rust/crates/cua-driver-sdk/src/lib.rs b/libs/cua-driver/rust/crates/cua-driver-sdk/src/lib.rs
new file mode 100644
index 0000000000..030daf7cdd
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver-sdk/src/lib.rs
@@ -0,0 +1,465 @@
+//! Canonical Rust implementation for imported Cua Driver SDKs.
+//!
+//! This library intentionally talks to the existing daemon rather than
+//! embedding the platform automation engine. Python and Node bindings therefore
+//! share one implementation while retaining the daemon's permission ownership,
+//! session state, policy enforcement, and platform event-loop constraints.
+
+use cua_driver_contract::{
+ ClickInput, DragInput, EndSessionInput, EndSessionOutput, EscalateSessionInput,
+ GetCursorPositionInput, GetDesktopStateInput, GetScreenSizeInput, GetSessionStateInput,
+ HotkeyInput, MoveCursorInput, PressKeyInput, ScrollInput, SessionStateOutput,
+ StartSessionInput, StartSessionOutput, ToolInput, TypeTextInput,
+};
+use cua_driver_core::daemon::{
+ is_daemon_listening, send_request, socket_path_for_namespace, DaemonRequest,
+ ToolObservationOrigin,
+};
+use serde::Serialize;
+use serde_json::Value;
+use std::sync::Arc;
+use thiserror::Error;
+
+#[derive(Debug, Clone, PartialEq, Eq, uniffi::Record)]
+pub struct ImageContent {
+ pub mime_type: String,
+ pub data_base64: String,
+}
+
+/// Transport-neutral result envelope used for open-ended tool calls and
+/// desktop tools whose platform extensions are intentionally preserved as JSON.
+#[derive(Debug, Clone, PartialEq, uniffi::Record)]
+pub struct ToolResult {
+ pub text: String,
+ pub images: Vec<ImageContent>,
+ pub structured_json: Option<String>,
+ pub is_error: bool,
+ pub error_code: Option<String>,
+ pub verified: Option<bool>,
+ pub degraded: bool,
+ pub raw_json: String,
+}
+
+#[derive(Debug, Error, uniffi::Error)]
+pub enum DriverError {
+ #[error("invalid SDK configuration: {reason}")]
+ Configuration { reason: String },
+ #[error("invalid arguments for {tool}: {reason}")]
+ InvalidArguments { tool: String, reason: String },
+ #[error("daemon transport error on {socket_path}: {reason}")]
+ Transport { socket_path: String, reason: String },
+ #[error("invalid daemon response: {reason}")]
+ Protocol { reason: String },
+ #[error("{tool} failed: {message}")]
+ Tool {
+ tool: String,
+ message: String,
+ error_code: String,
+ },
+}
+
+#[derive(uniffi::Object)]
+pub struct CuaDriver {
+ socket_path: String,
+}
+
+macro_rules! desktop_tool_methods {
+ ($callback:ident) => {
+ $callback! {
+ get_desktop_state: GetDesktopStateInput,
+ get_screen_size: GetScreenSizeInput,
+ get_cursor_position: GetCursorPositionInput,
+ move_cursor: MoveCursorInput,
+ click: ClickInput,
+ drag: DragInput,
+ scroll: ScrollInput,
+ type_text: TypeTextInput,
+ press_key: PressKeyInput,
+ hotkey: HotkeyInput,
+ }
+ };
+}
+
+macro_rules! define_desktop_tool_methods {
+ ($($method:ident: $input:ty,)*) => {
+ #[uniffi::export]
+ impl CuaDriver {
+ $(
+ pub fn $method(&self, input: $input) -> Result<ToolResult, DriverError> {
+ self.invoke_typed(<$input as ToolInput>::TOOL_NAME, input)
+ }
+ )*
+ }
+ };
+}
+
+macro_rules! define_exported_tool_names {
+ ($($method:ident: $input:ty,)*) => {
+ #[cfg(test)]
+ const EXPORTED_TOOL_NAMES: &[&str] = &[
+ <StartSessionInput as ToolInput>::TOOL_NAME,
+ <EscalateSessionInput as ToolInput>::TOOL_NAME,
+ <GetSessionStateInput as ToolInput>::TOOL_NAME,
+ <EndSessionInput as ToolInput>::TOOL_NAME,
+ $(<$input as ToolInput>::TOOL_NAME,)*
+ ];
+ };
+}
+
+desktop_tool_methods!(define_exported_tool_names);
+
+#[uniffi::export]
+impl CuaDriver {
+ /// Connect to the default installed daemon or an explicitly selected socket.
+ /// Construction does not launch a process or perform I/O.
+ #[uniffi::constructor]
+ pub fn connect(socket_path: Option<String>) -> Result<Arc<Self>, DriverError> {
+ let socket_path = socket_path.unwrap_or_else(|| socket_path_for_namespace("cua-driver"));
+ if socket_path.trim().is_empty() {
+ return Err(DriverError::Configuration {
+ reason: "socket_path must not be empty".into(),
+ });
+ }
+ Ok(Arc::new(Self { socket_path }))
+ }
+
+ pub fn socket_path(&self) -> String {
+ self.socket_path.clone()
+ }
+
+ pub fn is_available(&self) -> bool {
+ is_daemon_listening(&self.socket_path)
+ }
+
+ /// Escape hatch for forward-compatible tools and application-owned server
+ /// adapters. Typed methods below serialize the same canonical Rust inputs.
+ pub fn call_tool(
+ &self,
+ name: String,
+ arguments_json: String,
+ ) -> Result<ToolResult, DriverError> {
+ let arguments = parse_arguments(&name, &arguments_json)?;
+ self.invoke(&name, arguments)
+ }
+
+ pub fn list_tools_json(&self) -> Result<String, DriverError> {
+ let request = DaemonRequest {
+ method: "list".into(),
+ name: None,
+ args: None,
+ session_id: None,
+ observation_origin: Some(ToolObservationOrigin::Direct),
+ };
+ let response =
+ send_request(&self.socket_path, &request).map_err(|error| DriverError::Transport {
+ socket_path: self.socket_path.clone(),
+ reason: error.to_string(),
+ })?;
+ if !response.ok {
+ return Err(DriverError::Protocol {
+ reason: response
+ .error
+ .unwrap_or_else(|| "list request failed".into()),
+ });
+ }
+ serde_json::to_string(&response.result.unwrap_or(Value::Null)).map_err(|error| {
+ DriverError::Protocol {
+ reason: error.to_string(),
+ }
+ })
+ }
+
+ pub fn start_session(
+ &self,
+ input: StartSessionInput,
+ ) -> Result<StartSessionOutput, DriverError> {
+ self.invoke_typed(StartSessionInput::TOOL_NAME, input)
+ .and_then(|result| result.typed_success(StartSessionInput::TOOL_NAME))
+ }
+
+ pub fn escalate_session(
+ &self,
+ input: EscalateSessionInput,
+ ) -> Result<SessionStateOutput, DriverError> {
+ self.invoke_typed(EscalateSessionInput::TOOL_NAME, input)
+ .and_then(|result| result.typed_success(EscalateSessionInput::TOOL_NAME))
+ }
+
+ pub fn get_session_state(
+ &self,
+ input: GetSessionStateInput,
+ ) -> Result<SessionStateOutput, DriverError> {
+ self.invoke_typed(GetSessionStateInput::TOOL_NAME, input)
+ .and_then(|result| result.typed_success(GetSessionStateInput::TOOL_NAME))
+ }
+
+ pub fn end_session(&self, input: EndSessionInput) -> Result<EndSessionOutput, DriverError> {
+ self.invoke_typed(EndSessionInput::TOOL_NAME, input)
+ .and_then(|result| result.typed_success(EndSessionInput::TOOL_NAME))
+ }
+}
+
+desktop_tool_methods!(define_desktop_tool_methods);
+
+impl CuaDriver {
+ fn invoke_typed<T: Serialize>(&self, name: &str, input: T) -> Result<ToolResult, DriverError> {
+ let arguments =
+ serde_json::to_value(input).map_err(|error| DriverError::InvalidArguments {
+ tool: name.into(),
+ reason: error.to_string(),
+ })?;
+ self.invoke(name, arguments)
+ }
+
+ fn invoke(&self, name: &str, arguments: Value) -> Result<ToolResult, DriverError> {
+ if !arguments.is_object() {
+ return Err(DriverError::InvalidArguments {
+ tool: name.into(),
+ reason: "arguments must be a JSON object".into(),
+ });
+ }
+ let request = DaemonRequest {
+ method: "call".into(),
+ name: Some(name.into()),
+ args: Some(arguments),
+ session_id: None,
+ observation_origin: Some(ToolObservationOrigin::Direct),
+ };
+ let response =
+ send_request(&self.socket_path, &request).map_err(|error| DriverError::Transport {
+ socket_path: self.socket_path.clone(),
+ reason: error.to_string(),
+ })?;
+ if !response.ok {
+ return Err(DriverError::Tool {
+ tool: name.into(),
+ message: response
+ .error
+ .unwrap_or_else(|| "daemon rejected the request".into()),
+ error_code: response
+ .exit_code
+ .map(|code| code.to_string())
+ .unwrap_or_default(),
+ });
+ }
+ normalize_result(response.result.ok_or_else(|| DriverError::Protocol {
+ reason: format!("{name} response omitted result"),
+ })?)
+ }
+}
+
+impl ToolResult {
+ fn typed_success<T: serde::de::DeserializeOwned>(self, tool: &str) -> Result<T, DriverError> {
+ if self.is_error {
+ return Err(DriverError::Tool {
+ tool: tool.into(),
+ message: self.text,
+ error_code: self.error_code.unwrap_or_default(),
+ });
+ }
+ let structured = self.structured_json.ok_or_else(|| DriverError::Protocol {
+ reason: format!("{tool} response omitted structuredContent"),
+ })?;
+ serde_json::from_str(&structured).map_err(|error| DriverError::Protocol {
+ reason: format!("{tool} returned an invalid typed result: {error}"),
+ })
+ }
+}
+
+fn parse_arguments(tool: &str, arguments_json: &str) -> Result<Value, DriverError> {
+ let value: Value =
+ serde_json::from_str(arguments_json).map_err(|error| DriverError::InvalidArguments {
+ tool: tool.into(),
+ reason: error.to_string(),
+ })?;
+ if !value.is_object() {
+ return Err(DriverError::InvalidArguments {
+ tool: tool.into(),
+ reason: "arguments must be a JSON object".into(),
+ });
+ }
+ Ok(value)
+}
+
+fn normalize_result(raw: Value) -> Result<ToolResult, DriverError> {
+ let object = raw.as_object().ok_or_else(|| DriverError::Protocol {
+ reason: "tool result must be a JSON object".into(),
+ })?;
+ let mut text_parts = Vec::new();
+ let mut images = Vec::new();
+ if let Some(content) = object.get("content").and_then(Value::as_array) {
+ for item in content.iter().filter_map(Value::as_object) {
+ match item.get("type").and_then(Value::as_str) {
+ Some("text") => {
+ if let Some(text) = item.get("text").and_then(Value::as_str) {
+ text_parts.push(text.to_owned());
+ }
+ }
+ Some("image") => {
+ if let (Some(mime_type), Some(data_base64)) = (
+ item.get("mimeType").and_then(Value::as_str),
+ item.get("data").and_then(Value::as_str),
+ ) {
+ images.push(ImageContent {
+ mime_type: mime_type.into(),
+ data_base64: data_base64.into(),
+ });
+ }
+ }
+ _ => {}
+ }
+ }
+ }
+
+ let structured = object
+ .get("structuredContent")
+ .filter(|value| value.is_object());
+ let error_code = structured.and_then(|value| {
+ value
+ .get("code")
+ .and_then(Value::as_str)
+ .or_else(|| value.get("refusal")?.get("code")?.as_str())
+ .map(str::to_owned)
+ });
+ let verified = structured
+ .and_then(|value| value.get("verified"))
+ .and_then(Value::as_bool);
+ let degraded = structured
+ .and_then(|value| value.get("degraded"))
+ .and_then(Value::as_bool)
+ .unwrap_or(false);
+
+ Ok(ToolResult {
+ text: text_parts.join("\n"),
+ images,
+ structured_json: structured.map(Value::to_string),
+ is_error: object
+ .get("isError")
+ .and_then(Value::as_bool)
+ .unwrap_or(false),
+ error_code,
+ verified,
+ degraded,
+ raw_json: raw.to_string(),
+ })
+}
+
+uniffi::setup_scaffolding!("cua_driver_sdk");
+
+#[cfg(all(test, unix))]
+mod tests {
+ use super::*;
+ use std::io::{BufRead, BufReader, Write};
+ use std::os::unix::net::UnixListener;
+
+ #[test]
+ fn exported_typed_methods_cover_every_published_contract() {
+ let mut expected = cua_driver_contract::manifest()
+ .tools
+ .into_iter()
+ .map(|tool| tool.name)
+ .collect::<Vec<_>>();
+ expected.sort();
+ let mut exported = EXPORTED_TOOL_NAMES.to_vec();
+ exported.sort_unstable();
+ assert_eq!(exported, expected);
+ }
+
+ fn serve_once(response: Value) -> (tempfile::TempDir, String, std::thread::JoinHandle<Value>) {
+ let directory = tempfile::tempdir().unwrap();
+ let socket = directory.path().join("driver.sock");
+ let listener = UnixListener::bind(&socket).unwrap();
+ let handle = std::thread::spawn(move || {
+ let (stream, _) = listener.accept().unwrap();
+ let mut line = String::new();
+ BufReader::new(stream.try_clone().unwrap())
+ .read_line(&mut line)
+ .unwrap();
+ let request: Value = serde_json::from_str(&line).unwrap();
+ let mut writer = stream;
+ writeln!(writer, "{}", response).unwrap();
+ request
+ });
+ (directory, socket.to_string_lossy().into_owned(), handle)
+ }
+
+ #[test]
+ fn typed_desktop_call_serializes_contract_and_normalizes_result() {
+ let response = serde_json::json!({
+ "ok": true,
+ "result": {
+ "content": [
+ {"type": "text", "text": "captured"},
+ {"type": "image", "mimeType": "image/png", "data": "cG5n"}
+ ],
+ "structuredContent": {"screenshot_width": 2, "verified": true},
+ "isError": false
+ }
+ });
+ let (_directory, socket, server) = serve_once(response);
+ let driver = CuaDriver::connect(Some(socket)).unwrap();
+ let result = driver
+ .get_desktop_state(GetDesktopStateInput {
+ session: Some("run-1".into()),
+ screenshot_out_file: None,
+ })
+ .unwrap();
+ assert_eq!(result.text, "captured");
+ assert_eq!(result.images[0].mime_type, "image/png");
+ assert_eq!(result.verified, Some(true));
+
+ let request = server.join().unwrap();
+ assert_eq!(request["method"], "call");
+ assert_eq!(request["name"], "get_desktop_state");
+ assert_eq!(request["args"], serde_json::json!({"session": "run-1"}));
+ assert_eq!(request["observation_origin"], "direct");
+ }
+
+ #[test]
+ fn tool_discovery_uses_the_shared_direct_daemon_protocol() {
+ let response = serde_json::json!({
+ "ok": true,
+ "result": [{"name": "get_desktop_state"}]
+ });
+ let (_directory, socket, server) = serve_once(response);
+ let driver = CuaDriver::connect(Some(socket)).unwrap();
+ let tools: Value = serde_json::from_str(&driver.list_tools_json().unwrap()).unwrap();
+ assert_eq!(tools[0]["name"], "get_desktop_state");
+
+ let request = server.join().unwrap();
+ assert_eq!(request["method"], "list");
+ assert_eq!(request["observation_origin"], "direct");
+ }
+
+ #[test]
+ fn session_method_returns_the_canonical_typed_output() {
+ let response = serde_json::json!({
+ "ok": true,
+ "result": {
+ "content": [{"type": "text", "text": "started"}],
+ "structuredContent": {
+ "session": "run-2",
+ "capture_scope": "auto",
+ "effective_scope": "window",
+ "desktop_unlocked": false,
+ "escalation_reason": null,
+ "escalation_detail": null,
+ "active": true,
+ "revived": false
+ },
+ "isError": false
+ }
+ });
+ let (_directory, socket, server) = serve_once(response);
+ let driver = CuaDriver::connect(Some(socket)).unwrap();
+ let output = driver
+ .start_session(StartSessionInput {
+ session: "run-2".into(),
+ capture_scope: Some(cua_driver_contract::CaptureScope::Auto),
+ })
+ .unwrap();
+ assert!(output.active);
+ assert_eq!(output.state.session, "run-2");
+ server.join().unwrap();
+ }
+}
diff --git a/libs/cua-driver/rust/crates/cua-driver-sdk/uniffi.toml b/libs/cua-driver/rust/crates/cua-driver-sdk/uniffi.toml
new file mode 100644
index 0000000000..ff12e5d66f
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver-sdk/uniffi.toml
@@ -0,0 +1,5 @@
+[bindings.python]
+cdylib_name = "cua_driver_sdk"
+
+[bindings.python.external_packages]
+cua_driver_contract = "cua_driver._native_contract"
diff --git a/libs/cua-driver/rust/crates/cua-driver/Cargo.toml b/libs/cua-driver/rust/crates/cua-driver/Cargo.toml
index 658102d1c2..cc79c916dd 100644
--- a/libs/cua-driver/rust/crates/cua-driver/Cargo.toml
+++ b/libs/cua-driver/rust/crates/cua-driver/Cargo.toml
@@ -77,6 +77,7 @@ embed-resource = "2"
# Shared integration-test harness (MCP/CLI transports, child reaping, paths,
# response accessors). Dev-only — never linked into the shipped driver.
cua-driver-testkit = { path = "../cua-driver-testkit" }
+cua-driver-contract = { path = "../cua-driver-contract" }
tokio = { workspace = true, features = ["full"] }
image = { workspace = true }
base64 = { workspace = true }
diff --git a/libs/cua-driver/rust/crates/cua-driver/src/proxy.rs b/libs/cua-driver/rust/crates/cua-driver/src/proxy.rs
index 9cb1d716da..f046ad1e17 100644
--- a/libs/cua-driver/rust/crates/cua-driver/src/proxy.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/src/proxy.rs
@@ -482,10 +482,9 @@ fn fetch_tools_list_from_daemon(
.unwrap_or_else(|| {
serde_json::Value::String(cua_driver_core::tool::CAPABILITY_VERSION.to_owned())
});
- let schema_version = result
- .get("schema_version")
- .cloned()
- .unwrap_or_else(|| serde_json::Value::String("1".to_owned()));
+ let schema_version = result.get("schema_version").cloned().unwrap_or_else(|| {
+ serde_json::Value::String(cua_driver_core::tool::TOOLS_LIST_SCHEMA_VERSION.to_owned())
+ });
let daemon_observes_tool_calls = daemon_owns_tool_observation(&result);
diff --git a/libs/cua-driver/rust/crates/cua-driver/src/serve.rs b/libs/cua-driver/rust/crates/cua-driver/src/serve.rs
index e8f90bd3fe..c9a6822c35 100644
--- a/libs/cua-driver/rust/crates/cua-driver/src/serve.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/src/serve.rs
@@ -17,10 +17,14 @@
//! Linux — ~/.cache/cua-driver/cua-driver.sock
//! Windows — \\.\pipe\cua-driver (TODO: use named pipe; stubs only for now)
-use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use std::sync::{Mutex, OnceLock};
+pub use cua_driver_core::daemon::{
+ is_daemon_listening, send_request, socket_path_for_namespace, DaemonRequest, DaemonResponse,
+ ToolObservationOrigin,
+};
+
static ACTIVE_PROXY_SESSIONS: OnceLock<Mutex<HashSet<String>>> = OnceLock::new();
fn active_proxy_sessions() -> &'static Mutex<HashSet<String>> {
@@ -245,25 +249,7 @@ fn register_recording_session_end_hook(
/// Returns the platform default socket/pipe path.
pub fn default_socket_path() -> String {
- let namespace = crate::bundle::state_namespace();
- #[cfg(target_os = "macos")]
- {
- let home = std::env::var("HOME").unwrap_or_else(|_| "/tmp".into());
- format!("{home}/Library/Caches/{namespace}/{namespace}.sock")
- }
- #[cfg(target_os = "linux")]
- {
- let home = std::env::var("HOME").unwrap_or_else(|_| "/tmp".into());
- format!("{home}/.cache/{namespace}/{namespace}.sock")
- }
- #[cfg(target_os = "windows")]
- {
- format!(r"\\.\pipe\{namespace}")
- }
- #[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
- {
- "/tmp/cua-driver.sock".to_owned()
- }
+ socket_path_for_namespace(crate::bundle::state_namespace())
}
/// On Windows, returns the named-pipe path of the uiAccess-elevated worker
@@ -309,68 +295,6 @@ pub fn default_pid_file_path() -> String {
// ── Protocol types ────────────────────────────────────────────────────────────
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
-#[serde(rename_all = "snake_case")]
-pub enum ToolObservationOrigin {
- McpProxy,
- Direct,
-}
-
-#[derive(Debug, Serialize, Deserialize)]
-pub struct DaemonRequest {
- pub method: String,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub name: Option<String>,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub args: Option<serde_json::Value>,
- /// MCP-session identity minted once per `cua-driver mcp` proxy process and
- /// stamped on every forwarded request. The daemon uses it to OWN and CLEAN
- /// UP session-scoped state (recording, config overrides). Absent (`None`)
- /// means an anonymous/"global" session — a one-shot `cua-driver call` or a
- /// legacy proxy that predates this field — which keeps today's behavior.
- /// `skip_serializing_if = Option::is_none` makes the absent case
- /// byte-identical on the wire, so old clients and daemons interoperate.
- /// serde defaults a missing field to `None` on deserialize.
- #[serde(default, skip_serializing_if = "Option::is_none")]
- pub session_id: Option<String>,
- /// Bounded internal routing metadata for exactly-once completion
- /// observation. New proxies set `mcp_proxy` only after the daemon
- /// advertises ownership; direct protocol clients may set `direct`.
- /// Older peers ignore the additive field.
- #[serde(default, skip_serializing_if = "Option::is_none")]
- pub observation_origin: Option<ToolObservationOrigin>,
-}
-
-#[derive(Debug, Serialize, Deserialize)]
-pub struct DaemonResponse {
- pub ok: bool,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub result: Option<serde_json::Value>,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub error: Option<String>,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub exit_code: Option<i32>,
-}
-
-impl DaemonResponse {
- pub fn ok(result: serde_json::Value) -> Self {
- Self {
- ok: true,
- result: Some(result),
- error: None,
- exit_code: None,
- }
- }
- pub fn err(msg: impl Into<String>, code: i32) -> Self {
- Self {
- ok: false,
- result: None,
- error: Some(msg.into()),
- exit_code: Some(code),
- }
- }
-}
-
fn daemon_observation_transport(req: &DaemonRequest) -> Option<crate::telemetry::Transport> {
match req.observation_origin {
Some(ToolObservationOrigin::McpProxy) => Some(crate::telemetry::Transport::McpStdio),
@@ -537,61 +461,6 @@ async fn invoke_daemon_tool(
))
}
-// ── Client ────────────────────────────────────────────────────────────────────
-
-/// Probe whether a daemon is listening on `socket_path`.
-///
-/// On Windows this uses `WaitNamedPipeW` with a tiny timeout, which checks
-/// whether a pipe instance is available **without consuming one**. The
-/// previous design (sending a `list` request) opened a pipe instance,
-/// then the immediately-following real `send_request` had to wait for the
-/// daemon to spin up its NEXT instance — that race made real tool calls
-/// (especially state-dependent ones like `click` that need the daemon's
-/// element_index cache) miss the shared daemon state. See the conversation around the
-/// "Element 3 not in cache" bug for the diagnosis.
-///
-/// `WaitNamedPipeW(name, 1)`:
-/// - Returns TRUE if an instance is currently available.
-/// - Returns FALSE if not available within 1 ms.
-/// - Does NOT consume the instance — that's reserved for the actual call.
-pub fn is_daemon_listening(socket_path: &str) -> bool {
- #[cfg(target_os = "windows")]
- {
- use std::os::windows::ffi::OsStrExt;
-
- // Raw FFI to `WaitNamedPipeW` so this crate doesn't have to pull in
- // the `windows` crate as a direct dependency just for one probe.
- // `kernel32.dll` is implicitly linked on Windows targets.
- #[link(name = "kernel32")]
- extern "system" {
- fn WaitNamedPipeW(lpNamedPipeName: *const u16, nTimeOut: u32) -> i32;
- }
-
- let wide: Vec<u16> = std::ffi::OsStr::new(socket_path)
- .encode_wide()
- .chain(std::iter::once(0))
- .collect();
- // NMPWAIT_NOWAIT == 1: "do not wait at all"; returns nonzero only if an
- // instance is immediately available. We don't want to block here —
- // this is a one-shot existence probe.
- unsafe { WaitNamedPipeW(wide.as_ptr(), 1) != 0 }
- }
- #[cfg(not(target_os = "windows"))]
- {
- let req = DaemonRequest {
- method: "list".into(),
- name: None,
- args: None,
- session_id: None,
- observation_origin: None,
- };
- send_request(socket_path, &req)
- .ok()
- .map(|r| r.ok)
- .unwrap_or(false)
- }
-}
-
/// Read the PID stored in `pid_file_path`, if any.
pub fn read_pid_file(pid_file_path: &str) -> Option<u32> {
std::fs::read_to_string(pid_file_path)
@@ -599,124 +468,6 @@ pub fn read_pid_file(pid_file_path: &str) -> Option<u32> {
.and_then(|s| s.trim().parse().ok())
}
-/// Send a request to the daemon and return the response.
-/// Uses a 3-second connect timeout (by polling) and a 10-second read timeout.
-#[cfg(unix)]
-pub fn send_request(socket_path: &str, req: &DaemonRequest) -> anyhow::Result<DaemonResponse> {
- use std::io::Read;
- use std::os::unix::net::UnixStream;
- use std::time::{Duration, Instant};
-
- let mut stream = UnixStream::connect(socket_path)
- .map_err(|e| anyhow::anyhow!("connect to {socket_path}: {e}"))?;
- stream.set_write_timeout(Some(Duration::from_secs(5)))?;
- // Per-read timeout acts as a liveness poll, NOT a hard cap on the whole
- // response: an AX-heavy `get_window_state` (slow tree walk) or a multi-MB
- // SOM screenshot can legitimately take longer than one window to produce.
- stream.set_read_timeout(Some(Duration::from_secs(10)))?;
-
- let mut w = stream.try_clone()?;
- let line = serde_json::to_string(req)? + "\n";
- // EAGAIN-aware write: a daemon momentarily too busy to read our request
- // (backpressure under concurrent slow tools) makes the 5s SO_SNDTIMEO write
- // time out. Treat that like the read loop below does (#1997) — keep retrying
- // until an overall deadline — instead of failing with a fatal "Resource
- // temporarily unavailable (os error 35)" transport error. Mirrors the 120s
- // read budget.
- let write_deadline = Instant::now() + Duration::from_secs(120);
- cua_driver_core::socket_io::write_all_with_retry(&mut w, line.as_bytes(), write_deadline)?;
-
- // Read the single newline-terminated response line. A blocking UnixStream
- // with SO_RCVTIMEO returns `WouldBlock`/`TimedOut` (EAGAIN, os error 35)
- // when the timeout elapses with no bytes ready — that is NOT a transport
- // failure, just "the daemon is still working". Previously this surfaced as
- // a fatal `daemon transport error … Resource temporarily unavailable`
- // (#1864). Loop and keep waiting (re-arming the per-read poll) until we
- // have a full line, the daemon closes the connection, or an overall
- // deadline generous enough for the slowest AX walk / largest response.
- let overall_deadline = Instant::now() + Duration::from_secs(120);
- let mut buf: Vec<u8> = Vec::with_capacity(64 * 1024);
- let mut chunk = [0u8; 64 * 1024];
- let resp_line = loop {
- if let Some(nl) = buf.iter().position(|&b| b == b'\n') {
- break String::from_utf8_lossy(&buf[..nl]).into_owned();
- }
- match stream.read(&mut chunk) {
- Ok(0) => {
- // EOF. Use whatever we buffered (some daemons close right after
- // a final unterminated line); otherwise the daemon hung up.
- if buf.is_empty() {
- anyhow::bail!("daemon closed connection without response");
- }
- break String::from_utf8_lossy(&buf).into_owned();
- }
- Ok(n) => buf.extend_from_slice(&chunk[..n]),
- Err(e) if e.kind() == std::io::ErrorKind::Interrupted => continue,
- Err(e)
- if matches!(
- e.kind(),
- std::io::ErrorKind::WouldBlock | std::io::ErrorKind::TimedOut
- ) =>
- {
- if Instant::now() >= overall_deadline {
- anyhow::bail!(
- "timed out after 120s waiting for daemon response \
- (received {} bytes so far)",
- buf.len()
- );
- }
- continue;
- }
- Err(e) => return Err(e.into()),
- }
- };
- let resp: DaemonResponse = serde_json::from_str(&resp_line)?;
- Ok(resp)
-}
-
-#[cfg(not(unix))]
-pub fn send_request(socket_path: &str, req: &DaemonRequest) -> anyhow::Result<DaemonResponse> {
- #[cfg(target_os = "windows")]
- {
- use std::io::{BufRead, BufReader, Write};
- use std::time::Duration;
-
- // Retry opening the pipe — server may still be starting.
- let deadline = std::time::Instant::now() + Duration::from_secs(3);
- let pipe = loop {
- match std::fs::OpenOptions::new()
- .read(true)
- .write(true)
- .open(socket_path)
- {
- Ok(f) => break f,
- Err(_) if std::time::Instant::now() < deadline => {
- std::thread::sleep(Duration::from_millis(50));
- }
- Err(e) => anyhow::bail!("connect to named pipe {socket_path}: {e}"),
- }
- };
-
- let mut writer = pipe.try_clone()?;
- let line = serde_json::to_string(req)? + "\n";
- writer.write_all(line.as_bytes())?;
- writer.flush()?;
-
- // Server writes one JSON line then flushes; pipe stays open until we drop it.
- let reader = BufReader::new(pipe);
- let resp_line = reader
- .lines()
- .next()
- .ok_or_else(|| anyhow::anyhow!("daemon closed connection without response"))??;
- let resp: DaemonResponse = serde_json::from_str(&resp_line)?;
- Ok(resp)
- }
- #[cfg(not(target_os = "windows"))]
- {
- anyhow::bail!("daemon client not supported on this platform (socket path: {socket_path})");
- }
-}
-
// ── Server ────────────────────────────────────────────────────────────────────
/// Run the daemon server. Binds `socket_path`, writes `pid_file_path`,
@@ -859,7 +610,7 @@ pub async fn run_serve(
let resp = DaemonResponse::ok(serde_json::json!({
"tools": tools,
"capability_version": cua_driver_core::tool::CAPABILITY_VERSION,
- "schema_version": "1",
+ "schema_version": cua_driver_core::tool::TOOLS_LIST_SCHEMA_VERSION,
"tool_observation_owner": "daemon",
}));
let _ = writer.write_all(
@@ -1379,7 +1130,7 @@ pub async fn run_serve(
let resp = DaemonResponse::ok(serde_json::json!({
"tools": tools,
"capability_version": cua_driver_core::tool::CAPABILITY_VERSION,
- "schema_version": "1",
+ "schema_version": cua_driver_core::tool::TOOLS_LIST_SCHEMA_VERSION,
"tool_observation_owner": "daemon",
}));
let _ = writer.write_all(
diff --git a/libs/cua-driver/rust/crates/cua-driver/tests/schema_consistency_test.rs b/libs/cua-driver/rust/crates/cua-driver/tests/schema_consistency_test.rs
index b79bbce9aa..f7a6aa9e85 100644
--- a/libs/cua-driver/rust/crates/cua-driver/tests/schema_consistency_test.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/tests/schema_consistency_test.rs
@@ -13,9 +13,12 @@
//! drift in the first place. It is NOT `#[ignore]`d — `tools/list` needs no GUI,
//! permissions, or display, so it runs in normal CI.
+use cua_driver_contract::{
+ compatibility::schema_subset_violations, manifest, Platform, SchemaMode,
+};
use cua_driver_core::tool_schema::shared_schema_violations;
use cua_driver_testkit::RawDriver;
-use serde_json::json;
+use serde_json::{json, Value};
#[test]
fn registered_tool_contracts_match_on_active_backend() {
@@ -71,6 +74,113 @@ fn registered_tool_contracts_match_on_active_backend() {
);
}
+#[test]
+fn portable_desktop_contracts_are_accepted_by_active_backend() {
+ let Some(mut driver) = RawDriver::spawn() else {
+ // Binary not built — testkit already printed a skip note.
+ return;
+ };
+
+ driver.send(&json!({
+ "jsonrpc": "2.0", "id": 1, "method": "initialize",
+ "params": {
+ "protocolVersion": "2024-11-05",
+ "capabilities": {},
+ "clientInfo": { "name": "portable-contract-gate", "version": "1" }
+ }
+ }));
+ let _ = driver.recv();
+
+ driver.send(&json!({ "jsonrpc": "2.0", "id": 2, "method": "tools/list" }));
+ let response = driver.recv();
+ let live_tools = response["result"]["tools"]
+ .as_array()
+ .expect("tools/list must return result.tools");
+
+ let active_platform = if cfg!(target_os = "macos") {
+ Platform::Macos
+ } else if cfg!(target_os = "windows") {
+ Platform::Windows
+ } else if cfg!(target_os = "linux") {
+ Platform::Linux
+ } else {
+ panic!("portable contract parity is unsupported on this target")
+ };
+
+ let mut violations = Vec::new();
+ for contract in manifest()
+ .tools
+ .into_iter()
+ .filter(|contract| contract.schema_mode == SchemaMode::PortableSubset)
+ .filter(|contract| contract.platforms.contains(&active_platform))
+ {
+ let Some(live) = live_tools
+ .iter()
+ .find(|entry| entry["name"].as_str() == Some(&contract.name))
+ else {
+ violations.push(format!("{}: missing from live registry", contract.name));
+ continue;
+ };
+
+ let live_schema = live
+ .get("inputSchema")
+ .or_else(|| live.get("input_schema"))
+ .unwrap_or(&Value::Null);
+ violations.extend(
+ schema_subset_violations(&contract.input_schema, live_schema)
+ .into_iter()
+ .map(|violation| format!("{}: {violation}", contract.name)),
+ );
+
+ let annotations = &live["annotations"];
+ for (name, actual, expected) in [
+ (
+ "readOnlyHint",
+ annotations["readOnlyHint"].as_bool(),
+ contract.annotations.read_only,
+ ),
+ (
+ "destructiveHint",
+ annotations["destructiveHint"].as_bool(),
+ contract.annotations.destructive,
+ ),
+ (
+ "idempotentHint",
+ annotations["idempotentHint"].as_bool(),
+ contract.annotations.idempotent,
+ ),
+ (
+ "openWorldHint",
+ annotations["openWorldHint"].as_bool(),
+ contract.annotations.open_world,
+ ),
+ ] {
+ if actual != Some(expected) {
+ violations.push(format!(
+ "{}: annotation {name} is {actual:?}, expected {expected}",
+ contract.name
+ ));
+ }
+ }
+
+ if live["capabilities"] != json!(contract.capabilities) {
+ violations.push(format!(
+ "{}: live capabilities {} differ from portable capabilities {}",
+ contract.name,
+ live["capabilities"],
+ json!(contract.capabilities)
+ ));
+ }
+ }
+
+ assert!(
+ violations.is_empty(),
+ "portable SDK contracts are not accepted by the active backend ({} violation(s)):\n {}",
+ violations.len(),
+ violations.join("\n ")
+ );
+}
+
#[test]
fn health_report_is_callable_through_authorized_mcp_surface() {
let Some(mut driver) = RawDriver::spawn() else {
diff --git a/libs/cua-driver/rust/crates/platform-linux/Cargo.toml b/libs/cua-driver/rust/crates/platform-linux/Cargo.toml
index debfc3cff4..538f2419d2 100644
--- a/libs/cua-driver/rust/crates/platform-linux/Cargo.toml
+++ b/libs/cua-driver/rust/crates/platform-linux/Cargo.toml
@@ -12,6 +12,7 @@ thiserror = { workspace = true }
tracing = { workspace = true }
async-trait = "0.1"
cua-driver-core = { path = "../cua-driver-core" }
+cua-driver-contract = { path = "../cua-driver-contract" }
cursor-overlay = { path = "../cursor-overlay" }
pip-preview = { path = "../pip-preview" }
# tiny-skia for cursor rendering (shared cross-platform)
diff --git a/libs/cua-driver/rust/crates/platform-linux/src/tools/impl_.rs b/libs/cua-driver/rust/crates/platform-linux/src/tools/impl_.rs
index 7f12769b5b..fb790a9377 100644
--- a/libs/cua-driver/rust/crates/platform-linux/src/tools/impl_.rs
+++ b/libs/cua-driver/rust/crates/platform-linux/src/tools/impl_.rs
@@ -1,10 +1,14 @@
//! Real Linux tool implementations (compiled only on Linux).
use async_trait::async_trait;
+use cua_driver_contract::{
+ ClickButton, ClickInput, DragInput, GetCursorPositionInput, GetDesktopStateInput,
+ GetScreenSizeInput, HotkeyInput, MoveCursorInput, PressKeyInput, ScrollInput, TypeTextInput,
+};
use cua_driver_core::{
protocol::ToolResult,
tool::{Tool, ToolDef, ToolRegistry},
- tool_args::ArgsExt,
+ tool_args::{parse_typed_input, parse_typed_projection, ArgsExt},
};
use serde_json::{json, Value};
use std::fs;
@@ -1775,20 +1779,18 @@ impl Tool for ClickTool {
"suggestion": "pass scope=desktop",
}));
}
- let button_raw = args.str_or("button", "left").to_lowercase();
- if !matches!(button_raw.as_str(), "" | "left" | "right" | "middle") {
- return ToolResult::error(format!(
- "click: unknown button \"{button_raw}\" — expected one of left, right, middle."
- ));
+ let input = match parse_typed_projection::<ClickInput>("click", &args) {
+ Ok(input) => input,
+ Err(result) => return result,
+ };
+ let button = parse_mouse_button(input.button.unwrap_or(ClickButton::Left).as_str());
+ let sx = input.x as i32;
+ let sy = input.y as i32;
+ let n = input.count.unwrap_or(1) as usize;
+ if n == 0 {
+ return ToolResult::error("click.count must be at least 1.")
+ .with_structured(json!({ "code": "invalid_arguments" }));
}
- let button = parse_mouse_button(if button_raw.is_empty() {
- "left"
- } else {
- &button_raw
- });
- let sx = args.f64_or("x", 0.0) as i32;
- let sy = args.f64_or("y", 0.0) as i32;
- let n = args.u64_or("count", 1) as usize;
// Glide the agent-cursor overlay to the click point first (the macOS
// / Windows desktop paths already do this). Without it the overlay
// sits idle elsewhere while only the real pointer warps, so a viewer
@@ -2227,13 +2229,13 @@ impl Tool for TypeTextTool {
async fn invoke(&self, args: Value) -> ToolResult {
use cua_driver_core::tool_args::ArgsExt;
if args.opt_str("scope").as_deref() == Some("desktop") && args.get("pid").is_none() {
- let text = match args.require_str("text") {
- Ok(value) => {
- cua_driver_core::text_sanitize::strip_trailing_agent_protocol_tags(&value)
- .into_owned()
- }
- Err(error) => return error,
+ let input = match parse_typed_projection::<TypeTextInput>("type_text", &args) {
+ Ok(input) => input,
+ Err(result) => return result,
};
+ let text =
+ cua_driver_core::text_sanitize::strip_trailing_agent_protocol_tags(&input.text)
+ .into_owned();
let wayland = crate::wayland::wayland_input_enabled();
let path = if wayland { "wayland_focused" } else { "xtest" };
let result = tokio::task::spawn_blocking(move || {
@@ -2806,12 +2808,13 @@ impl Tool for PressKeyTool {
async fn invoke(&self, args: Value) -> ToolResult {
use cua_driver_core::tool_args::ArgsExt;
if args.opt_str("scope").as_deref() == Some("desktop") && args.get("pid").is_none() {
- let key = match args.require_str("key") {
- Ok(value) => value,
- Err(error) => return error,
+ let input = match parse_typed_projection::<PressKeyInput>("press_key", &args) {
+ Ok(input) => input,
+ Err(result) => return result,
};
+ let key = input.key;
let display = key.clone();
- let modifiers: Vec<String> = args.str_array("modifiers");
+ let modifiers = input.modifiers.unwrap_or_default();
let wayland = crate::wayland::wayland_input_enabled();
let path = if wayland { "wayland_focused" } else { "xtest" };
let result = tokio::task::spawn_blocking(move || {
@@ -3099,7 +3102,15 @@ impl Tool for HotkeyTool {
async fn invoke(&self, args: Value) -> ToolResult {
use cua_driver_core::tool_args::ArgsExt;
if args.opt_str("scope").as_deref() == Some("desktop") && args.get("pid").is_none() {
- let keys: Vec<String> = args.str_array("keys");
+ let input = match parse_typed_projection::<HotkeyInput>("hotkey", &args) {
+ Ok(input) => input,
+ Err(result) => return result,
+ };
+ let keys = input.keys;
+ if keys.len() < 2 {
+ return ToolResult::error("hotkey.keys must contain at least two keys.")
+ .with_structured(json!({ "code": "invalid_arguments" }));
+ }
let modifiers: Vec<String> = keys
.iter()
.filter(|key| is_modifier(key))
@@ -3491,19 +3502,14 @@ impl Tool for ScrollTool {
&& args.get("pid").is_none()
&& args.get("window_id").is_none()
{
- let direction = match args.require_str("direction") {
- Ok(value) => value,
- Err(error) => return error,
+ let input = match parse_typed_projection::<ScrollInput>("scroll", &args) {
+ Ok(input) => input,
+ Err(result) => return result,
};
- let x = match args.require_f64("x") {
- Ok(value) => value.round() as i32,
- Err(error) => return error,
- };
- let y = match args.require_f64("y") {
- Ok(value) => value.round() as i32,
- Err(error) => return error,
- };
- let amount = args.u64_or("amount", 3).clamp(1, 50) as usize;
+ let direction = input.direction.as_str().to_owned();
+ let x = input.x.round() as i32;
+ let y = input.y.round() as i32;
+ let amount = input.amount.unwrap_or(3).clamp(1, 50) as usize;
let display = direction.clone();
let wayland = crate::wayland::wayland_input_enabled();
let path = if wayland { "wayland_desktop" } else { "xtest" };
@@ -4348,25 +4354,14 @@ impl Tool for DragTool {
&& args.get("pid").is_none()
&& args.get("window_id").is_none()
{
- let coordinate = |key: &str| {
- args.opt_f64(key)
- .or_else(|| args.opt_i64(key).map(|value| value as f64))
- };
- let Some(from_x) = coordinate("from_x") else {
- return ToolResult::error("Missing: from_x");
- };
- let Some(from_y) = coordinate("from_y") else {
- return ToolResult::error("Missing: from_y");
+ let input = match parse_typed_projection::<DragInput>("drag", &args) {
+ Ok(input) => input,
+ Err(result) => return result,
};
- let Some(to_x) = coordinate("to_x") else {
- return ToolResult::error("Missing: to_x");
- };
- let Some(to_y) = coordinate("to_y") else {
- return ToolResult::error("Missing: to_y");
- };
- let button = parse_mouse_button(&args.str_or("button", "left"));
- let duration_ms = args.u64_or("duration_ms", 500).min(10_000);
- let steps = args.u64_or("steps", 20).clamp(1, 200) as usize;
+ let (from_x, from_y, to_x, to_y) = (input.from_x, input.from_y, input.to_x, input.to_y);
+ let button = parse_mouse_button(input.button.unwrap_or(ClickButton::Left).as_str());
+ let duration_ms = input.duration_ms.unwrap_or(500).min(10_000);
+ let steps = input.steps.unwrap_or(20).clamp(1, 200) as usize;
let wayland = crate::wayland::wayland_input_enabled();
let path = if wayland { "wayland_desktop" } else { "xtest" };
let result = tokio::task::spawn_blocking(move || {
@@ -5556,14 +5551,19 @@ impl Tool for GetScreenSizeTool {
scale factor. Agents click in points; Retina displays have scale_factor 2.0. \
Requires no TCC permissions."
.into(),
- input_schema: json!({"type":"object","properties":{},"additionalProperties":false}),
+ input_schema: json!({"type":"object","properties":{
+ "session": cua_driver_core::tool_schema::session_schema()
+ },"additionalProperties":false}),
read_only: true,
destructive: false,
idempotent: true,
open_world: false,
})
}
- async fn invoke(&self, _args: Value) -> ToolResult {
+ async fn invoke(&self, args: Value) -> ToolResult {
+ if let Err(result) = parse_typed_input::<GetScreenSizeInput>("get_screen_size", args) {
+ return result;
+ }
let result = tokio::task::spawn_blocking(|| {
// X11 reports pixel dimensions; scale factor on X11 is not
// well-defined per-monitor, so report 1.0 (matches DPI-unaware
@@ -5637,7 +5637,11 @@ impl Tool for GetDesktopStateTool {
}
async fn invoke(&self, args: Value) -> ToolResult {
- let out_file = args.opt_str("screenshot_out_file");
+ let input = match parse_typed_input::<GetDesktopStateInput>("get_desktop_state", args) {
+ Ok(input) => input,
+ Err(result) => return result,
+ };
+ let out_file = input.screenshot_out_file;
let result = tokio::task::spawn_blocking(move || -> anyhow::Result<_> {
// Vision-only: capture the FULL DISPLAY at native size. No downscale
@@ -5726,14 +5730,21 @@ impl Tool for GetCursorPositionTool {
description:
"Return the current mouse cursor position in screen points (origin top-left)."
.into(),
- input_schema: json!({"type":"object","properties":{},"additionalProperties":false}),
+ input_schema: json!({"type":"object","properties":{
+ "session": cua_driver_core::tool_schema::session_schema()
+ },"additionalProperties":false}),
read_only: true,
destructive: false,
idempotent: true,
open_world: false,
})
}
- async fn invoke(&self, _args: Value) -> ToolResult {
+ async fn invoke(&self, args: Value) -> ToolResult {
+ if let Err(result) =
+ parse_typed_input::<GetCursorPositionInput>("get_cursor_position", args)
+ {
+ return result;
+ }
// Native Wayland: there's no protocol for clients to query the real
// global cursor position. Fall back to the synthetic registry that
// records every `motion_absolute` this process emits.
@@ -5791,9 +5802,12 @@ impl Tool for MoveCursorTool {
}
async fn invoke(&self, args: Value) -> ToolResult {
use cua_driver_core::tool_args::ArgsExt;
- let x = args.f64_or("x", 0.0);
- let y = args.f64_or("y", 0.0);
if args.opt_str("scope").as_deref() == Some("desktop") {
+ let input = match parse_typed_projection::<MoveCursorInput>("move_cursor", &args) {
+ Ok(input) => input,
+ Err(result) => return result,
+ };
+ let (x, y) = (input.x, input.y);
let xi = x.round() as i32;
let yi = y.round() as i32;
let result = if crate::wayland::wayland_input_enabled() {
@@ -5816,6 +5830,8 @@ impl Tool for MoveCursorTool {
Err(error) => ToolResult::error(format!("Task error: {error}")),
};
}
+ let x = args.f64_or("x", 0.0);
+ let y = args.f64_or("y", 0.0);
let window_id = args.get("window_id").and_then(|v| v.as_u64());
let cursor_id = resolve_cursor_key(&args);
self.state.cursor_registry.update_position(&cursor_id, x, y);
diff --git a/libs/cua-driver/rust/crates/platform-macos/Cargo.toml b/libs/cua-driver/rust/crates/platform-macos/Cargo.toml
index b37a7af046..629a4f5408 100644
--- a/libs/cua-driver/rust/crates/platform-macos/Cargo.toml
+++ b/libs/cua-driver/rust/crates/platform-macos/Cargo.toml
@@ -19,6 +19,7 @@ uuid = { workspace = true }
# to frame (a plain HashMap would flicker overlapping cursors).
indexmap = "2"
cua-driver-core = { path = "../cua-driver-core" }
+cua-driver-contract = { path = "../cua-driver-contract" }
cursor-overlay = { path = "../cursor-overlay" }
pip-preview = { path = "../pip-preview" }
diff --git a/libs/cua-driver/rust/crates/platform-macos/src/tools/click.rs b/libs/cua-driver/rust/crates/platform-macos/src/tools/click.rs
index e418027e54..4d4726ca04 100644
--- a/libs/cua-driver/rust/crates/platform-macos/src/tools/click.rs
+++ b/libs/cua-driver/rust/crates/platform-macos/src/tools/click.rs
@@ -14,9 +14,11 @@
//! to full-window space using the most recent `zoom` context stored per-pid.
use async_trait::async_trait;
+use cua_driver_contract::{ClickButton, ClickInput};
use cua_driver_core::{
protocol::ToolResult,
tool::{Tool, ToolDef},
+ tool_args::parse_typed_projection,
};
use serde_json::Value;
use std::sync::Arc;
@@ -167,14 +169,12 @@ impl Tool for ClickTool {
"suggestion": "pass scope=\"desktop\"",
}));
}
- let sx_shot = args
- .opt_f64("x")
- .or_else(|| args.opt_i64("x").map(|i| i as f64))
- .unwrap_or(0.0);
- let sy_shot = args
- .opt_f64("y")
- .or_else(|| args.opt_i64("y").map(|i| i as f64))
- .unwrap_or(0.0);
+ let input = match parse_typed_projection::<ClickInput>("click", &args) {
+ Ok(input) => input,
+ Err(result) => return result,
+ };
+ let sx_shot = input.x;
+ let sy_shot = input.y;
// ── Desktop-screenshot pixels → logical screen points ──────────────
// The vision invariant: the pixel an agent reads off the screenshot it
// was handed is the pixel that gets clicked. `get_desktop_state`
@@ -206,18 +206,17 @@ impl Tool for ClickTool {
.unwrap_or(1.0);
let sx = sx_shot / desktop_ratio;
let sy = sy_shot / desktop_ratio;
- let button = match args.str_or("button", "left").to_lowercase().as_str() {
- "right" => "right",
- "middle" => "middle",
- "" | "left" => "left",
- other => {
- return ToolResult::error(format!(
- "click: unknown button \"{other}\" — expected one of left, right, middle."
- ))
- }
+ let button = match input.button.unwrap_or(ClickButton::Left) {
+ ClickButton::Left => "left",
+ ClickButton::Right => "right",
+ ClickButton::Middle => "middle",
+ }
+ .to_owned();
+ let count = input.count.unwrap_or(1) as usize;
+ if count == 0 {
+ return ToolResult::error("click.count must be at least 1.")
+ .with_structured(serde_json::json!({ "code": "invalid_arguments" }));
}
- .to_string();
- let count = args.u64_or("count", 1) as usize;
// Glide the session's agent cursor to the screen point for visibility.
let cursor_key = super::cursor_tools::resolve_cursor_key(&args);
crate::cursor::overlay::animate_cursor_to(cursor_key.clone(), sx, sy).await;
diff --git a/libs/cua-driver/rust/crates/platform-macos/src/tools/drag.rs b/libs/cua-driver/rust/crates/platform-macos/src/tools/drag.rs
index 1e88ae09b8..ba1fa203bd 100644
--- a/libs/cua-driver/rust/crates/platform-macos/src/tools/drag.rs
+++ b/libs/cua-driver/rust/crates/platform-macos/src/tools/drag.rs
@@ -8,9 +8,11 @@
//! recent zoom crop context, same as click/double_click.
use async_trait::async_trait;
+use cua_driver_contract::{ClickButton, DragInput};
use cua_driver_core::{
protocol::ToolResult,
tool::{Tool, ToolDef},
+ tool_args::parse_typed_projection,
};
use serde_json::Value;
use std::sync::Arc;
@@ -114,36 +116,20 @@ impl Tool for DragTool {
&& args.get("pid").is_none()
&& args.get("window_id").is_none()
{
- let coordinate = |key: &str| {
- args.opt_f64(key)
- .or_else(|| args.opt_i64(key).map(|value| value as f64))
- };
- let Some(from_x) = coordinate("from_x") else {
- return ToolResult::error("Missing required parameter: from_x");
- };
- let Some(from_y) = coordinate("from_y") else {
- return ToolResult::error("Missing required parameter: from_y");
- };
- let Some(to_x) = coordinate("to_x") else {
- return ToolResult::error("Missing required parameter: to_x");
- };
- let Some(to_y) = coordinate("to_y") else {
- return ToolResult::error("Missing required parameter: to_y");
+ let input = match parse_typed_projection::<DragInput>("drag", &args) {
+ Ok(input) => input,
+ Err(result) => return result,
};
+ let (from_x, from_y, to_x, to_y) = (input.from_x, input.from_y, input.to_x, input.to_y);
let (from_x, from_y) = super::desktop_screenshot_point(from_x, from_y).await;
let (to_x, to_y) = super::desktop_screenshot_point(to_x, to_y).await;
- let duration_ms = args.u64_or("duration_ms", 500).min(10_000);
- let steps = args.u64_or("steps", 20).clamp(1, 200) as usize;
- let modifiers: Vec<String> = args.str_array("modifier");
- let button = match args.str_or("button", "left").to_lowercase().as_str() {
- "left" => DragButton::Left,
- "right" => DragButton::Right,
- "middle" => DragButton::Middle,
- other => {
- return ToolResult::error(format!(
- "Unknown button '{other}' — expected left, right, or middle."
- ))
- }
+ let duration_ms = input.duration_ms.unwrap_or(500).min(10_000);
+ let steps = input.steps.unwrap_or(20).clamp(1, 200) as usize;
+ let modifiers = input.modifier.unwrap_or_default();
+ let button = match input.button.unwrap_or(ClickButton::Left) {
+ ClickButton::Left => DragButton::Left,
+ ClickButton::Right => DragButton::Right,
+ ClickButton::Middle => DragButton::Middle,
};
let result = tokio::task::spawn_blocking(move || {
let modifier_refs: Vec<&str> = modifiers.iter().map(String::as_str).collect();
diff --git a/libs/cua-driver/rust/crates/platform-macos/src/tools/get_cursor_position.rs b/libs/cua-driver/rust/crates/platform-macos/src/tools/get_cursor_position.rs
index f0466c81b3..ae9ece755b 100644
--- a/libs/cua-driver/rust/crates/platform-macos/src/tools/get_cursor_position.rs
+++ b/libs/cua-driver/rust/crates/platform-macos/src/tools/get_cursor_position.rs
@@ -1,7 +1,9 @@
use async_trait::async_trait;
+use cua_driver_contract::GetCursorPositionInput;
use cua_driver_core::{
protocol::ToolResult,
tool::{Tool, ToolDef},
+ tool_args::parse_typed_input,
};
use serde_json::Value;
@@ -12,8 +14,11 @@ static DEF: std::sync::OnceLock<ToolDef> = std::sync::OnceLock::new();
fn def() -> &'static ToolDef {
DEF.get_or_init(|| ToolDef {
name: "get_cursor_position".into(),
- description: "Return the current mouse cursor position in screen points (origin top-left).".into(),
- input_schema: serde_json::json!({"type":"object","properties":{},"additionalProperties":false}),
+ description: "Return the current mouse cursor position in screen points (origin top-left)."
+ .into(),
+ input_schema: serde_json::json!({"type":"object","properties":{
+ "session": cua_driver_core::tool_schema::session_schema()
+ },"additionalProperties":false}),
read_only: true,
destructive: false,
idempotent: true,
@@ -27,7 +32,12 @@ impl Tool for GetCursorPositionTool {
def()
}
- async fn invoke(&self, _args: Value) -> ToolResult {
+ async fn invoke(&self, args: Value) -> ToolResult {
+ if let Err(result) =
+ parse_typed_input::<GetCursorPositionInput>("get_cursor_position", args)
+ {
+ return result;
+ }
// Create a null event and query its location to get cursor position.
use core_graphics::{
event::CGEvent,
diff --git a/libs/cua-driver/rust/crates/platform-macos/src/tools/get_desktop_state.rs b/libs/cua-driver/rust/crates/platform-macos/src/tools/get_desktop_state.rs
index 18d424f527..cdbd3402eb 100644
--- a/libs/cua-driver/rust/crates/platform-macos/src/tools/get_desktop_state.rs
+++ b/libs/cua-driver/rust/crates/platform-macos/src/tools/get_desktop_state.rs
@@ -12,9 +12,11 @@
//! `structuredContent` object.
use async_trait::async_trait;
+use cua_driver_contract::GetDesktopStateInput;
use cua_driver_core::{
protocol::{Content, ToolResult},
tool::{Tool, ToolDef},
+ tool_args::parse_typed_input,
};
use serde_json::Value;
@@ -55,9 +57,11 @@ impl Tool for GetDesktopStateTool {
}
async fn invoke(&self, args: Value) -> ToolResult {
- use cua_driver_core::tool_args::ArgsExt;
-
- let screenshot_out_file = args.opt_str("screenshot_out_file").map(|s| {
+ let input = match parse_typed_input::<GetDesktopStateInput>("get_desktop_state", args) {
+ Ok(input) => input,
+ Err(result) => return result,
+ };
+ let screenshot_out_file = input.screenshot_out_file.map(|s| {
// Expand ~ prefix (mirrors get_window_state).
if s.starts_with("~/") {
let home = std::env::var("HOME").unwrap_or_default();
diff --git a/libs/cua-driver/rust/crates/platform-macos/src/tools/get_screen_size.rs b/libs/cua-driver/rust/crates/platform-macos/src/tools/get_screen_size.rs
index 85ec8792a4..d1df99da7c 100644
--- a/libs/cua-driver/rust/crates/platform-macos/src/tools/get_screen_size.rs
+++ b/libs/cua-driver/rust/crates/platform-macos/src/tools/get_screen_size.rs
@@ -1,7 +1,9 @@
use async_trait::async_trait;
+use cua_driver_contract::GetScreenSizeInput;
use cua_driver_core::{
protocol::ToolResult,
tool::{Tool, ToolDef},
+ tool_args::parse_typed_input,
};
use serde_json::Value;
@@ -15,8 +17,11 @@ fn def() -> &'static ToolDef {
name: "get_screen_size".into(),
description: "Return the logical size of the main display in points plus its backing \
scale factor. Agents click in points; Retina displays have scale_factor 2.0. \
- Requires no TCC permissions.".into(),
- input_schema: serde_json::json!({"type":"object","properties":{},"additionalProperties":false}),
+ Requires no TCC permissions."
+ .into(),
+ input_schema: serde_json::json!({"type":"object","properties":{
+ "session": cua_driver_core::tool_schema::session_schema()
+ },"additionalProperties":false}),
read_only: true,
destructive: false,
idempotent: true,
@@ -30,7 +35,10 @@ impl Tool for GetScreenSizeTool {
def()
}
- async fn invoke(&self, _args: Value) -> ToolResult {
+ async fn invoke(&self, args: Value) -> ToolResult {
+ if let Err(result) = parse_typed_input::<GetScreenSizeInput>("get_screen_size", args) {
+ return result;
+ }
match main_screen_size() {
Some((w, h, scale)) => {
// Matches Swift text format 1:1.
diff --git a/libs/cua-driver/rust/crates/platform-macos/src/tools/hotkey.rs b/libs/cua-driver/rust/crates/platform-macos/src/tools/hotkey.rs
index e9a68a79b7..93c6ce6a99 100644
--- a/libs/cua-driver/rust/crates/platform-macos/src/tools/hotkey.rs
+++ b/libs/cua-driver/rust/crates/platform-macos/src/tools/hotkey.rs
@@ -1,7 +1,9 @@
use async_trait::async_trait;
+use cua_driver_contract::HotkeyInput;
use cua_driver_core::{
protocol::ToolResult,
tool::{Tool, ToolDef},
+ tool_args::parse_typed_projection,
};
use libc;
use serde_json::Value;
@@ -103,7 +105,15 @@ impl Tool for HotkeyTool {
&& args.get("pid").is_none()
&& args.get("window_id").is_none()
{
- let raw_keys = args.str_array("keys");
+ let input = match parse_typed_projection::<HotkeyInput>("hotkey", &args) {
+ Ok(input) => input,
+ Err(result) => return result,
+ };
+ let raw_keys = input.keys;
+ if raw_keys.len() < 2 {
+ return ToolResult::error("hotkey.keys must contain at least two keys.")
+ .with_structured(serde_json::json!({ "code": "invalid_arguments" }));
+ }
let modifiers: Vec<String> = raw_keys
.iter()
.filter(|key| is_modifier(key))
diff --git a/libs/cua-driver/rust/crates/platform-macos/src/tools/move_cursor.rs b/libs/cua-driver/rust/crates/platform-macos/src/tools/move_cursor.rs
index dd7809d6ae..1ad762d71b 100644
--- a/libs/cua-driver/rust/crates/platform-macos/src/tools/move_cursor.rs
+++ b/libs/cua-driver/rust/crates/platform-macos/src/tools/move_cursor.rs
@@ -1,7 +1,9 @@
use async_trait::async_trait;
+use cua_driver_contract::MoveCursorInput;
use cua_driver_core::{
protocol::ToolResult,
tool::{Tool, ToolDef},
+ tool_args::parse_typed_projection,
};
use serde_json::Value;
use std::sync::Arc;
@@ -53,15 +55,12 @@ impl Tool for MoveCursorTool {
async fn invoke(&self, args: Value) -> ToolResult {
use cua_driver_core::tool_args::ArgsExt;
- let x = match args.require_f64("x") {
- Ok(v) => v,
- Err(e) => return e,
- };
- let y = match args.require_f64("y") {
- Ok(v) => v,
- Err(e) => return e,
- };
if args.opt_str("scope").as_deref() == Some("desktop") {
+ let input = match parse_typed_projection::<MoveCursorInput>("move_cursor", &args) {
+ Ok(input) => input,
+ Err(result) => return result,
+ };
+ let (x, y) = (input.x, input.y);
let (x, y) = super::desktop_screenshot_point(x, y).await;
let result =
tokio::task::spawn_blocking(move || crate::input::mouse::move_cursor_desktop(x, y))
@@ -82,6 +81,14 @@ impl Tool for MoveCursorTool {
Err(error) => ToolResult::error(format!("desktop pointer task failed: {error}")),
};
}
+ let x = match args.require_f64("x") {
+ Ok(v) => v,
+ Err(e) => return e,
+ };
+ let y = match args.require_f64("y") {
+ Ok(v) => v,
+ Err(e) => return e,
+ };
let cursor_id = super::cursor_tools::resolve_cursor_key(&args);
self.state.cursor_registry.update_position(&cursor_id, x, y);
diff --git a/libs/cua-driver/rust/crates/platform-macos/src/tools/press_key.rs b/libs/cua-driver/rust/crates/platform-macos/src/tools/press_key.rs
index 0dbebddd8c..6649bdf921 100644
--- a/libs/cua-driver/rust/crates/platform-macos/src/tools/press_key.rs
+++ b/libs/cua-driver/rust/crates/platform-macos/src/tools/press_key.rs
@@ -1,7 +1,9 @@
use async_trait::async_trait;
+use cua_driver_contract::PressKeyInput;
use cua_driver_core::{
protocol::ToolResult,
tool::{Tool, ToolDef},
+ tool_args::parse_typed_projection,
};
use libc;
use serde_json::Value;
@@ -83,11 +85,12 @@ impl Tool for PressKeyTool {
&& args.get("pid").is_none()
&& args.get("window_id").is_none()
{
- let key = match args.require_str("key") {
- Ok(value) => value,
- Err(error) => return error,
+ let input = match parse_typed_projection::<PressKeyInput>("press_key", &args) {
+ Ok(input) => input,
+ Err(result) => return result,
};
- let modifiers: Vec<String> = args.str_array("modifiers");
+ let key = input.key;
+ let modifiers = input.modifiers.unwrap_or_default();
let key_for_input = key.clone();
let result = tokio::task::spawn_blocking(move || {
let modifier_refs: Vec<&str> = modifiers.iter().map(String::as_str).collect();
diff --git a/libs/cua-driver/rust/crates/platform-macos/src/tools/scroll.rs b/libs/cua-driver/rust/crates/platform-macos/src/tools/scroll.rs
index 05235e9de8..fd68ac9194 100644
--- a/libs/cua-driver/rust/crates/platform-macos/src/tools/scroll.rs
+++ b/libs/cua-driver/rust/crates/platform-macos/src/tools/scroll.rs
@@ -1,8 +1,10 @@
use async_trait::async_trait;
use core_foundation::base::{CFRelease, CFTypeRef};
+use cua_driver_contract::{ScrollBy, ScrollDirection, ScrollInput};
use cua_driver_core::{
protocol::ToolResult,
tool::{Tool, ToolDef},
+ tool_args::parse_typed_projection,
};
use serde_json::Value;
use std::sync::Arc;
@@ -116,35 +118,24 @@ impl Tool for ScrollTool {
&& args.get("pid").is_none()
&& args.get("window_id").is_none()
{
- let direction = match args.require_str("direction") {
- Ok(value) => value,
- Err(error) => return error,
+ let input = match parse_typed_projection::<ScrollInput>("scroll", &args) {
+ Ok(input) => input,
+ Err(result) => return result,
};
- let x = match args.require_f64("x") {
- Ok(value) => value,
- Err(error) => return error,
- };
- let y = match args.require_f64("y") {
- Ok(value) => value,
- Err(error) => return error,
- };
- let by = args.str_or("by", "line");
- let amount = args.u64_or("amount", 3).clamp(1, 50) as usize;
- let step = if by == "page" {
+ let (x, y) = (input.x, input.y);
+ let direction = input.direction.as_str();
+ let by = input.by.unwrap_or(ScrollBy::Line).as_str();
+ let amount = input.amount.unwrap_or(3).clamp(1, 50) as usize;
+ let step = if input.by == Some(ScrollBy::Page) {
WHEEL_STEP_PAGE_PX
} else {
WHEEL_STEP_LINE_PX
};
- let (delta_y, delta_x) = match direction.as_str() {
- "down" => (-step, 0),
- "up" => (step, 0),
- "right" => (0, -step),
- "left" => (0, step),
- other => {
- return ToolResult::error(format!(
- "unknown scroll direction '{other}'; expected up, down, left, or right"
- ))
- }
+ let (delta_y, delta_x) = match input.direction {
+ ScrollDirection::Down => (-step, 0),
+ ScrollDirection::Up => (step, 0),
+ ScrollDirection::Right => (0, -step),
+ ScrollDirection::Left => (0, step),
};
let (x, y) = super::desktop_screenshot_point(x, y).await;
let result = tokio::task::spawn_blocking(move || {
diff --git a/libs/cua-driver/rust/crates/platform-macos/src/tools/type_text.rs b/libs/cua-driver/rust/crates/platform-macos/src/tools/type_text.rs
index f8dc939af6..8f7fdc686c 100644
--- a/libs/cua-driver/rust/crates/platform-macos/src/tools/type_text.rs
+++ b/libs/cua-driver/rust/crates/platform-macos/src/tools/type_text.rs
@@ -22,9 +22,11 @@
//! (e.g., to trigger live-search debounce handlers).
use async_trait::async_trait;
+use cua_driver_contract::TypeTextInput;
use cua_driver_core::{
protocol::ToolResult,
tool::{Tool, ToolDef},
+ tool_args::parse_typed_projection,
};
use serde_json::Value;
use std::sync::Arc;
@@ -135,13 +137,13 @@ impl Tool for TypeTextTool {
&& args.get("pid").is_none()
&& args.get("window_id").is_none()
{
- let text = match args.require_str("text") {
- Ok(value) => {
- cua_driver_core::text_sanitize::strip_trailing_agent_protocol_tags(&value)
- .into_owned()
- }
- Err(error) => return error,
+ let input = match parse_typed_projection::<TypeTextInput>("type_text", &args) {
+ Ok(input) => input,
+ Err(result) => return result,
};
+ let text =
+ cua_driver_core::text_sanitize::strip_trailing_agent_protocol_tags(&input.text)
+ .into_owned();
let delay_ms = args.u64_or("delay_ms", 30).min(200);
let result = tokio::task::spawn_blocking(move || {
crate::input::keyboard::type_text_global(&text, delay_ms)
diff --git a/libs/cua-driver/rust/crates/platform-windows/Cargo.toml b/libs/cua-driver/rust/crates/platform-windows/Cargo.toml
index bd64e08e43..727570ad4d 100644
--- a/libs/cua-driver/rust/crates/platform-windows/Cargo.toml
+++ b/libs/cua-driver/rust/crates/platform-windows/Cargo.toml
@@ -12,6 +12,7 @@ thiserror = { workspace = true }
tracing = { workspace = true }
async-trait = "0.1"
cua-driver-core = { path = "../cua-driver-core" }
+cua-driver-contract = { path = "../cua-driver-contract" }
cursor-overlay = { path = "../cursor-overlay" }
pip-preview = { path = "../pip-preview" }
# IndexMap gives the keyed cursor render collection deterministic
diff --git a/libs/cua-driver/rust/crates/platform-windows/src/tools/impl_.rs b/libs/cua-driver/rust/crates/platform-windows/src/tools/impl_.rs
index 2c41e7e684..644b9839ab 100644
--- a/libs/cua-driver/rust/crates/platform-windows/src/tools/impl_.rs
+++ b/libs/cua-driver/rust/crates/platform-windows/src/tools/impl_.rs
@@ -208,9 +208,15 @@ async fn overlay_glide_to(key: &str, sx: f64, sy: f64) {
}
crate::overlay::animate_cursor_to(key.to_owned(), sx, sy).await;
}
+use cua_driver_contract::{
+ ClickButton, ClickInput, DragInput, GetCursorPositionInput, GetDesktopStateInput,
+ GetScreenSizeInput, HotkeyInput, MoveCursorInput, PressKeyInput, ScrollDirection, ScrollInput,
+ TypeTextInput,
+};
use cua_driver_core::{
protocol::ToolResult,
tool::{Tool, ToolDef, ToolRegistry},
+ tool_args::{parse_typed_input, parse_typed_projection},
};
use serde_json::{json, Value};
use std::sync::{Arc, RwLock};
@@ -2512,22 +2518,23 @@ impl Tool for ClickTool {
"suggestion": "pass scope=desktop",
}));
}
- // Resolve button (reuse the same validation as the pid path).
- let button_raw = args.str_or("button", "left").to_lowercase();
- if !matches!(button_raw.as_str(), "" | "left" | "right" | "middle") {
- return ToolResult::error(format!(
- "click: unknown button \"{button_raw}\" — expected one of left, right, middle."
- ));
- }
- let button = if button_raw.is_empty() {
- "left".to_string()
- } else {
- button_raw
+ let input = match parse_typed_projection::<ClickInput>("click", &args) {
+ Ok(input) => input,
+ Err(result) => return result,
};
- let count = args.u64_or("count", 1) as usize;
+ let button = input
+ .button
+ .unwrap_or(ClickButton::Left)
+ .as_str()
+ .to_owned();
+ let count = input.count.unwrap_or(1) as usize;
+ if count == 0 {
+ return ToolResult::error("click.count must be at least 1.")
+ .with_structured(json!({ "code": "invalid_arguments" }));
+ }
let modifiers: Vec<String> = args.str_array("modifier");
- let sx = args.f64_or("x", 0.0) as i32;
- let sy = args.f64_or("y", 0.0) as i32;
+ let sx = input.x as i32;
+ let sy = input.y as i32;
// Resolve the application window before moving the agent cursor.
// WindowFromPoint can return a transparent layered overlay, and the
@@ -3471,22 +3478,18 @@ impl Tool for TypeTextTool {
async fn invoke(&self, args: Value) -> ToolResult {
use crate::input::delivery::{DeliveryMode, EventKind};
use cua_driver_core::tool_args::ArgsExt;
- let text_raw = match args.require_str("text") {
- Ok(v) => v,
- Err(e) => return e,
- };
let cursor_key = resolve_cursor_key(&args);
- // Strip trailing agent-protocol closing tags before delivery —
- // catches the case where an LLM hallucinated its own tool-
- // invocation tags into the text param (see text_sanitize docs).
- // Returns Cow::Borrowed on the no-match fast path so the common
- // case is allocation-free.
- let text = cua_driver_core::text_sanitize::strip_trailing_agent_protocol_tags(&text_raw)
- .into_owned();
if args.get("scope").and_then(Value::as_str) == Some("desktop")
&& args.get("pid").is_none()
&& args.get("window_id").is_none()
{
+ let input = match parse_typed_projection::<TypeTextInput>("type_text", &args) {
+ Ok(input) => input,
+ Err(result) => return result,
+ };
+ let text =
+ cua_driver_core::text_sanitize::strip_trailing_agent_protocol_tags(&input.text)
+ .into_owned();
let hwnd = match crate::input::mouse::foreground_window() {
Ok(hwnd) => hwnd,
Err(error) => return ToolResult::error(error.to_string()),
@@ -3508,6 +3511,17 @@ impl Tool for TypeTextTool {
Err(error) => ToolResult::error(format!("desktop type task failed: {error}")),
};
}
+ let text_raw = match args.require_str("text") {
+ Ok(v) => v,
+ Err(e) => return e,
+ };
+ // Strip trailing agent-protocol closing tags before delivery —
+ // catches the case where an LLM hallucinated its own tool-
+ // invocation tags into the text param (see text_sanitize docs).
+ // Returns Cow::Borrowed on the no-match fast path so the common
+ // case is allocation-free.
+ let text = cua_driver_core::text_sanitize::strip_trailing_agent_protocol_tags(&text_raw)
+ .into_owned();
let raw_pid = match args.require_i64("pid") {
Ok(v) => v,
Err(e) => return e,
@@ -4133,15 +4147,16 @@ impl Tool for PressKeyTool {
async fn invoke(&self, args: Value) -> ToolResult {
use crate::input::delivery::{DeliveryMode, EventKind};
use cua_driver_core::tool_args::ArgsExt;
- let key = match args.require_str("key") {
- Ok(v) => v,
- Err(e) => return e,
- };
- let mods: Vec<String> = args.str_array("modifiers");
if args.get("scope").and_then(Value::as_str) == Some("desktop")
&& args.get("pid").is_none()
&& args.get("window_id").is_none()
{
+ let input = match parse_typed_projection::<PressKeyInput>("press_key", &args) {
+ Ok(input) => input,
+ Err(result) => return result,
+ };
+ let key = input.key;
+ let mods = input.modifiers.unwrap_or_default();
let hwnd = match crate::input::mouse::foreground_window() {
Ok(hwnd) => hwnd,
Err(error) => return ToolResult::error(error.to_string()),
@@ -4164,6 +4179,11 @@ impl Tool for PressKeyTool {
Err(error) => ToolResult::error(format!("desktop key task failed: {error}")),
};
}
+ let key = match args.require_str("key") {
+ Ok(v) => v,
+ Err(e) => return e,
+ };
+ let mods: Vec<String> = args.str_array("modifiers");
let raw_pid = match args.require_i64("pid") {
Ok(v) => v,
Err(e) => return e,
@@ -4473,6 +4493,56 @@ impl Tool for HotkeyTool {
async fn invoke(&self, args: Value) -> ToolResult {
use crate::input::delivery::{DeliveryMode, EventKind};
use cua_driver_core::tool_args::ArgsExt;
+ if args.get("scope").and_then(Value::as_str) == Some("desktop")
+ && args.get("pid").is_none()
+ && args.get("window_id").is_none()
+ {
+ let input = match parse_typed_projection::<HotkeyInput>("hotkey", &args) {
+ Ok(input) => input,
+ Err(result) => return result,
+ };
+ if input.keys.len() < 2 {
+ return ToolResult::error("hotkey.keys must contain at least two keys.")
+ .with_structured(json!({ "code": "invalid_arguments" }));
+ }
+ let mods: Vec<String> = input
+ .keys
+ .iter()
+ .filter(|key| is_modifier(key))
+ .cloned()
+ .collect();
+ let Some(key) = input
+ .keys
+ .iter()
+ .rev()
+ .find(|key| !is_modifier(key))
+ .cloned()
+ else {
+ return ToolResult::error("keys must include at least one non-modifier key.");
+ };
+ let full_keys = input.keys;
+ let hwnd = match crate::input::mouse::foreground_window() {
+ Ok(hwnd) => hwnd,
+ Err(error) => return ToolResult::error(error.to_string()),
+ };
+ let key_display = full_keys.join("+");
+ return match tokio::task::spawn_blocking(move || {
+ let modifiers: Vec<&str> = mods.iter().map(String::as_str).collect();
+ crate::input::send_key_synthesized(hwnd, &key, &modifiers)
+ })
+ .await
+ {
+ Ok(Ok(())) => ToolResult::text(format!(
+ "Sent {key_display} to the foreground application (scope:desktop)."
+ ))
+ .with_structured(json!({
+ "scope": "desktop", "path": "SendInput", "keys": full_keys,
+ "effect": "unverifiable"
+ })),
+ Ok(Err(error)) => ToolResult::error(error.to_string()),
+ Err(error) => ToolResult::error(format!("desktop hotkey task failed: {error}")),
+ };
+ }
// Parse keys array (Swift's only path). Legacy key+modifiers shape
// still accepted as a Rust-side convenience.
let (key, mods, full_keys) = if let Some(arr) = args.get("keys") {
@@ -4509,32 +4579,6 @@ impl Tool for HotkeyTool {
} else {
return ToolResult::error("Missing required array field keys.");
};
- if args.get("scope").and_then(Value::as_str) == Some("desktop")
- && args.get("pid").is_none()
- && args.get("window_id").is_none()
- {
- let hwnd = match crate::input::mouse::foreground_window() {
- Ok(hwnd) => hwnd,
- Err(error) => return ToolResult::error(error.to_string()),
- };
- let key_display = full_keys.join("+");
- return match tokio::task::spawn_blocking(move || {
- let modifiers: Vec<&str> = mods.iter().map(String::as_str).collect();
- crate::input::send_key_synthesized(hwnd, &key, &modifiers)
- })
- .await
- {
- Ok(Ok(())) => ToolResult::text(format!(
- "Sent {key_display} to the foreground application (scope:desktop)."
- ))
- .with_structured(json!({
- "scope": "desktop", "path": "SendInput", "keys": full_keys,
- "effect": "unverifiable"
- })),
- Ok(Err(error)) => ToolResult::error(error.to_string()),
- Err(error) => ToolResult::error(format!("desktop hotkey task failed: {error}")),
- };
- }
let hwnd_opt = args.opt_u64("window_id");
let raw_pid = match args.require_i64("pid") {
Ok(v) => v,
@@ -4975,14 +5019,6 @@ impl Tool for ScrollTool {
async fn invoke(&self, args: Value) -> ToolResult {
use crate::input::delivery::{DeliveryMode, EventKind};
use cua_driver_core::tool_args::ArgsExt;
- // `direction` is required in both the pid path and the window-less
- // desktop path, so resolve it before the pid check.
- let direction = match args.get("direction").and_then(|v| v.as_str()) {
- Some(d) => d.to_owned(),
- None => return ToolResult::error("Missing required string field direction."),
- };
- let amount = args.u64_or("amount", 3).clamp(1, 50) as u32;
-
// ── Window-less screen-absolute branch (capture_scope="desktop") ──────
// No pid/window_id + numeric x,y + desktop scope → synthesize a wheel
// event at the screen point via SendInput. The wheel routes to whatever
@@ -5003,22 +5039,23 @@ impl Tool for ScrollTool {
"suggestion": "pass scope=desktop",
}));
}
- let sx = args.f64_or("x", 0.0) as i32;
- let sy = args.f64_or("y", 0.0) as i32;
+ let input = match parse_typed_projection::<ScrollInput>("scroll", &args) {
+ Ok(input) => input,
+ Err(error) => return error,
+ };
+ let sx = input.x as i32;
+ let sy = input.y as i32;
+ let direction = input.direction;
+ let amount = input.amount.unwrap_or(3) as u32;
// Direction → (horizontal?, sign). Positive ticks = up / right.
- let (horizontal, sign) = match direction.as_str() {
- "up" => (false, 1),
- "down" => (false, -1),
- "right" => (true, 1),
- "left" => (true, -1),
- other => {
- return ToolResult::error(format!(
- "scroll: unknown direction \"{other}\" — expected up, down, left, right."
- ))
- }
+ let (horizontal, sign) = match direction {
+ ScrollDirection::Up => (false, 1),
+ ScrollDirection::Down => (false, -1),
+ ScrollDirection::Right => (true, 1),
+ ScrollDirection::Left => (true, -1),
};
let ticks = sign * amount as i32;
- let dir_disp = direction.clone();
+ let dir_disp = direction.as_str();
let result = tokio::task::spawn_blocking(move || {
crate::input::send_wheel_synthesized(sx, sy, ticks, horizontal)
})
@@ -5032,6 +5069,13 @@ impl Tool for ScrollTool {
};
}
+ // Window-scoped arguments retain the richer platform contract.
+ let direction = match args.get("direction").and_then(|v| v.as_str()) {
+ Some(d) => d.to_owned(),
+ None => return ToolResult::error("Missing required string field direction."),
+ };
+ let amount = args.u64_or("amount", 3).clamp(1, 50) as u32;
+
// Swift error wording 1:1.
let raw_pid = match args.get("pid").and_then(|v| v.as_i64()) {
Some(p) => p,
@@ -6202,22 +6246,17 @@ impl Tool for DragTool {
&& args.get("pid").is_none()
&& args.get("window_id").is_none()
{
- let required = |key: &str| {
- args.opt_f64(key)
- .or_else(|| args.opt_i64(key).map(|value| value as f64))
- };
- let (from_x, from_y, to_x, to_y) = match (
- required("from_x"),
- required("from_y"),
- required("to_x"),
- required("to_y"),
- ) {
- (Some(a), Some(b), Some(c), Some(d)) => (a as i32, b as i32, c as i32, d as i32),
- _ => return ToolResult::error("from_x, from_y, to_x, and to_y are required."),
+ let input = match parse_typed_projection::<DragInput>("drag", &args) {
+ Ok(input) => input,
+ Err(error) => return error,
};
- let duration_ms = args.u64_or("duration_ms", 500);
- let steps = args.u64_or("steps", 20) as usize;
- let button = args.str_or("button", "left");
+ let from_x = input.from_x as i32;
+ let from_y = input.from_y as i32;
+ let to_x = input.to_x as i32;
+ let to_y = input.to_y as i32;
+ let duration_ms = input.duration_ms.unwrap_or(500);
+ let steps = input.steps.unwrap_or(20) as usize;
+ let button = input.button.unwrap_or(ClickButton::Left).as_str();
let hwnd = match crate::input::mouse::foreground_window() {
Ok(hwnd) => hwnd,
Err(error) => return ToolResult::error(error.to_string()),
@@ -6542,11 +6581,16 @@ impl Tool for GetScreenSizeTool {
description: "Return the size of the main display in physical pixels plus its display \
scale factor. On Windows, screenshots and pixel clicks use this same physical-pixel \
coordinate space. Requires no special permissions.".into(),
- input_schema: json!({"type":"object","properties":{},"additionalProperties":false}),
+ input_schema: json!({"type":"object","properties":{
+ "session": cua_driver_core::tool_schema::session_schema()
+ },"additionalProperties":false}),
read_only: true, destructive: false, idempotent: true, open_world: false,
})
}
- async fn invoke(&self, _args: Value) -> ToolResult {
+ async fn invoke(&self, args: Value) -> ToolResult {
+ if let Err(error) = parse_typed_input::<GetScreenSizeInput>("get_screen_size", args) {
+ return error;
+ }
use windows::Win32::UI::HiDpi::GetDpiForSystem;
// With permonitorv2 DPI awareness (set in cua-driver.manifest),
// SM_CXSCREEN/SM_CYSCREEN return PHYSICAL pixels — the same
@@ -6601,9 +6645,11 @@ impl Tool for GetDesktopStateTool {
async fn invoke(&self, args: Value) -> ToolResult {
use cua_driver_core::protocol::Content;
- use cua_driver_core::tool_args::ArgsExt;
-
- let screenshot_out_file = args.opt_str("screenshot_out_file");
+ let input = match parse_typed_input::<GetDesktopStateInput>("get_desktop_state", args) {
+ Ok(input) => input,
+ Err(error) => return error,
+ };
+ let screenshot_out_file = input.screenshot_out_file;
// True screen geometry in physical pixels (same space as the capture).
let (screen_width, screen_height) = physical_screen_size();
@@ -6680,14 +6726,20 @@ impl Tool for GetCursorPositionTool {
description:
"Return the current mouse cursor position in screen points (origin top-left)."
.into(),
- input_schema: json!({"type":"object","properties":{},"additionalProperties":false}),
+ input_schema: json!({"type":"object","properties":{
+ "session": cua_driver_core::tool_schema::session_schema()
+ },"additionalProperties":false}),
read_only: true,
destructive: false,
idempotent: true,
open_world: false,
})
}
- async fn invoke(&self, _args: Value) -> ToolResult {
+ async fn invoke(&self, args: Value) -> ToolResult {
+ if let Err(error) = parse_typed_input::<GetCursorPositionInput>("get_cursor_position", args)
+ {
+ return error;
+ }
use windows::Win32::Foundation::POINT;
use windows::Win32::UI::WindowsAndMessaging::GetCursorPos;
let mut pt = POINT { x: 0, y: 0 };
@@ -6729,9 +6781,13 @@ impl Tool for MoveCursorTool {
}
async fn invoke(&self, args: Value) -> ToolResult {
use cua_driver_core::tool_args::ArgsExt;
- let x = args.f64_or("x", 0.0);
- let y = args.f64_or("y", 0.0);
if args.get("scope").and_then(Value::as_str) == Some("desktop") {
+ let input = match parse_typed_projection::<MoveCursorInput>("move_cursor", &args) {
+ Ok(input) => input,
+ Err(error) => return error,
+ };
+ let x = input.x;
+ let y = input.y;
return match crate::input::mouse::move_cursor_desktop(x as i32, y as i32) {
Ok(()) => ToolResult::text(format!(
"Moved the OS pointer to ({x:.1}, {y:.1}) (scope:desktop)."
@@ -6742,6 +6798,8 @@ impl Tool for MoveCursorTool {
Err(error) => ToolResult::error(error.to_string()),
};
}
+ let x = args.f64_or("x", 0.0);
+ let y = args.f64_or("y", 0.0);
// Cursor key precedence: caller-declared `session` > legacy `cursor_id`
// > NO_CURSOR. An anonymous run (no session) has no cursor to move.
let cursor_key = resolve_cursor_key(&args);
diff --git a/libs/cua-driver/scripts/_install-rust.sh b/libs/cua-driver/scripts/_install-rust.sh
index 7efac0b7cd..a7cf6f6725 100644
--- a/libs/cua-driver/scripts/_install-rust.sh
+++ b/libs/cua-driver/scripts/_install-rust.sh
@@ -578,8 +578,9 @@ tar -xzf "$TMP_DIR/$TARBALL" -C "$TMP_DIR"
# ├── CuaDriver.app/ (minimal bundle; copy of the same binary
# │ lives at Contents/MacOS/cua-driver)
# └── LICENSE
-# Linux bare-binary tarball expands to:
-# cua-driver (single file at the archive root)
+# Linux bare-runtime tarball expands to:
+# cua-driver and libcua_driver_sdk.so at the archive root. The installer
+# consumes the CLI; SDK packaging consumes the colocated library.
case "$LABEL" in
darwin-*)
STAGE="cua-driver-rs-${VERSION}-darwin-universal"
diff --git a/libs/cua-driver/scripts/generate-uniffi-bindings.mjs b/libs/cua-driver/scripts/generate-uniffi-bindings.mjs
new file mode 100644
index 0000000000..b3462b1128
--- /dev/null
+++ b/libs/cua-driver/scripts/generate-uniffi-bindings.mjs
@@ -0,0 +1,212 @@
+#!/usr/bin/env node
+
+import { spawnSync } from "node:child_process"
+import {
+ existsSync,
+ lstatSync,
+ mkdirSync,
+ mkdtempSync,
+ readFileSync,
+ readdirSync,
+ renameSync,
+ rmSync,
+ unlinkSync,
+ writeFileSync,
+} from "node:fs"
+import { tmpdir } from "node:os"
+import { dirname, isAbsolute, join, resolve } from "node:path"
+import { fileURLToPath } from "node:url"
+
+const scriptDirectory = dirname(fileURLToPath(import.meta.url))
+const driverRoot = resolve(scriptDirectory, "..")
+const rustRoot = join(driverRoot, "rust")
+const pythonRoot = join(driverRoot, "python")
+const typescriptRoot = join(driverRoot, "typescript")
+const check = process.argv.includes("--check")
+
+function run(command, args, cwd) {
+ const result = spawnSync(command, args, { cwd, stdio: "inherit" })
+ if (result.error) throw result.error
+ if (result.status !== 0) {
+ throw new Error(`${command} exited with status ${result.status}`)
+ }
+}
+
+function nativeLibraryPath() {
+ const file =
+ process.platform === "darwin"
+ ? "libcua_driver_sdk.dylib"
+ : process.platform === "win32"
+ ? "cua_driver_sdk.dll"
+ : "libcua_driver_sdk.so"
+ return join(rustRoot, "target", "release", file)
+}
+
+function normalizeWhitespace(source) {
+ const output = source
+ .replaceAll("\r\n", "\n")
+ .split("\n")
+ .map((line) => line.replace(/[ \t]+$/u, ""))
+ .join("\n")
+ return output.endsWith("\n") ? output : `${output}\n`
+}
+
+function normalizeTypeScript(name, source) {
+ let output = normalizeWhitespace(source)
+ // NodeNext requires emitted relative ESM imports to carry their .js suffix.
+ output = output.replace(
+ /(from\s+["']\.\/[A-Za-z0-9_-]+)(["'])/g,
+ "$1.js$2",
+ )
+ if (name === "cua_driver_contract-ffi.ts") {
+ const needle = 'crateName: "cua_driver_contract"'
+ const matches = output.split(needle).length - 1
+ if (matches !== 1) {
+ throw new Error(`expected one contract Node library selector, found ${matches}`)
+ }
+ // The contract namespace is linked into the SDK cdylib. UBRN 0.31.0-3
+ // cannot configure a shared cdylib name for an external component.
+ output = output.replace(needle, 'crateName: "cua_driver_sdk"')
+ }
+ return output
+}
+
+function inventoryContents(paths) {
+ return [
+ "# Generated by scripts/generate-uniffi-bindings.mjs; one owned path per line.",
+ ...paths.slice().sort(),
+ "",
+ ].join("\n")
+}
+
+function assertOwnedPath(path) {
+ const parts = path.split(/[\\/]/)
+ if (
+ isAbsolute(path) ||
+ parts.some((part) => part === "" || part === "." || part === "..")
+ ) {
+ throw new Error(`invalid generated ownership path: ${path}`)
+ }
+ return path
+}
+
+function applyGroup(root, inventoryName, files) {
+ const inventory = join(root, inventoryName)
+ const previous = existsSync(inventory)
+ ? readFileSync(inventory, "utf8")
+ .split("\n")
+ .filter((line) => line && !line.startsWith("#"))
+ .map(assertOwnedPath)
+ : []
+ const expected = Object.keys(files).map(assertOwnedPath).sort()
+ const planned = { ...files, [inventoryName]: inventoryContents(expected) }
+
+ if (check) {
+ const differences = previous.filter((path) => !expected.includes(path))
+ for (const [path, contents] of Object.entries(planned)) {
+ const destination = join(root, path)
+ if (!existsSync(destination) || readFileSync(destination, "utf8") !== contents) {
+ differences.push(path)
+ }
+ }
+ if (differences.length) {
+ throw new Error(`stale UniFFI generated files under ${root}: ${differences.join(", ")}`)
+ }
+ return
+ }
+
+ for (const stale of previous.filter((path) => !expected.includes(path))) {
+ const destination = join(root, stale)
+ if (existsSync(destination)) {
+ if (lstatSync(destination).isSymbolicLink()) {
+ throw new Error(`refusing to prune generated symlink ${destination}`)
+ }
+ unlinkSync(destination)
+ }
+ }
+ for (const [path, contents] of Object.entries(planned)) {
+ const destination = join(root, path)
+ if (existsSync(destination) && lstatSync(destination).isSymbolicLink()) {
+ throw new Error(`refusing to overwrite generated symlink ${destination}`)
+ }
+ mkdirSync(dirname(destination), { recursive: true })
+ const temporary = `${destination}.tmp.${process.pid}`
+ writeFileSync(temporary, contents)
+ renameSync(temporary, destination)
+ }
+}
+
+const temporaryRoot = mkdtempSync(join(tmpdir(), "cua-driver-uniffi-"))
+try {
+ run("cargo", ["build", "--locked", "--release", "-p", "cua-driver-sdk"], rustRoot)
+ const library = nativeLibraryPath()
+ if (!existsSync(library)) throw new Error(`missing built SDK library ${library}`)
+
+ const pythonOutput = join(temporaryRoot, "python")
+ run(
+ "cargo",
+ [
+ "run",
+ "--locked",
+ "-p",
+ "cua-driver-bindgen",
+ "--",
+ "generate",
+ "--library",
+ library,
+ "--language",
+ "python",
+ "--out-dir",
+ pythonOutput,
+ "--no-format",
+ ],
+ rustRoot,
+ )
+
+ const typescriptOutput = join(temporaryRoot, "typescript")
+ const ubrn = join(
+ typescriptRoot,
+ "node_modules",
+ ".bin",
+ process.platform === "win32" ? "ubrn.cmd" : "ubrn",
+ )
+ if (!existsSync(ubrn)) {
+ throw new Error("missing pinned UBRN generator; run npm ci in libs/cua-driver/typescript")
+ }
+ run(
+ ubrn,
+ [
+ "generate",
+ "napi",
+ "bindings",
+ "--library",
+ library,
+ "--ts-dir",
+ typescriptOutput,
+ "--lib-colocated",
+ "--no-format",
+ ],
+ rustRoot,
+ )
+
+ applyGroup(pythonRoot, ".cua-driver-uniffi-generated-files", {
+ "src/cua_driver/_native.py": normalizeWhitespace(
+ readFileSync(join(pythonOutput, "cua_driver_sdk.py"), "utf8"),
+ ),
+ "src/cua_driver/_native_contract.py": normalizeWhitespace(
+ readFileSync(join(pythonOutput, "cua_driver_contract.py"), "utf8"),
+ ),
+ })
+
+ const typescriptFiles = {}
+ for (const name of readdirSync(typescriptOutput).filter((name) => name.endsWith(".ts"))) {
+ typescriptFiles[`src/native/${name}`] = normalizeTypeScript(
+ name,
+ readFileSync(join(typescriptOutput, name), "utf8"),
+ )
+ }
+ applyGroup(typescriptRoot, ".cua-driver-uniffi-generated-files", typescriptFiles)
+ console.log(check ? "UniFFI bindings are up to date." : "Generated UniFFI bindings.")
+} finally {
+ rmSync(temporaryRoot, { recursive: true, force: true })
+}
diff --git a/libs/cua-driver/scripts/stage-uniffi-library.mjs b/libs/cua-driver/scripts/stage-uniffi-library.mjs
new file mode 100644
index 0000000000..4c88ec6133
--- /dev/null
+++ b/libs/cua-driver/scripts/stage-uniffi-library.mjs
@@ -0,0 +1,27 @@
+#!/usr/bin/env node
+
+import { copyFileSync, existsSync, mkdirSync } from "node:fs"
+import { dirname, join, resolve } from "node:path"
+import { fileURLToPath } from "node:url"
+
+const driverRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..")
+const file =
+ process.platform === "darwin"
+ ? "libcua_driver_sdk.dylib"
+ : process.platform === "win32"
+ ? "cua_driver_sdk.dll"
+ : "libcua_driver_sdk.so"
+const source = join(driverRoot, "rust", "target", "release", file)
+if (!existsSync(source)) {
+ throw new Error(`missing ${source}; build cua-driver-sdk --release first`)
+}
+
+const destinations = [
+ join(driverRoot, "python", "src", "cua_driver", file),
+ join(driverRoot, "typescript", "dist", "native", file),
+]
+for (const destination of destinations) {
+ mkdirSync(dirname(destination), { recursive: true })
+ copyFileSync(source, destination)
+ console.log(`staged ${destination}`)
+}
diff --git a/libs/cua-driver/typescript/.cua-driver-uniffi-generated-files b/libs/cua-driver/typescript/.cua-driver-uniffi-generated-files
new file mode 100644
index 0000000000..8ba32dcd18
--- /dev/null
+++ b/libs/cua-driver/typescript/.cua-driver-uniffi-generated-files
@@ -0,0 +1,6 @@
+# Generated by scripts/generate-uniffi-bindings.mjs; one owned path per line.
+src/native/cua_driver_contract-ffi.ts
+src/native/cua_driver_contract.ts
+src/native/cua_driver_sdk-ffi.ts
+src/native/cua_driver_sdk.ts
+src/native/index.ts
diff --git a/libs/cua-driver/typescript/.gitignore b/libs/cua-driver/typescript/.gitignore
new file mode 100644
index 0000000000..4f09da0c5c
--- /dev/null
+++ b/libs/cua-driver/typescript/.gitignore
@@ -0,0 +1,5 @@
+dist/
+node_modules/
+src/native/*.dylib
+src/native/*.so
+src/native/*.dll
diff --git a/libs/cua-driver/typescript/README.md b/libs/cua-driver/typescript/README.md
new file mode 100644
index 0000000000..6d59f587c6
--- /dev/null
+++ b/libs/cua-driver/typescript/README.md
@@ -0,0 +1,63 @@
+# cua-driver TypeScript SDK
+
+Rust-backed TypeScript/Node SDK for Cua Driver client applications.
+
+## Product boundary
+
+This package has one public entrypoint:
+
+```ts
+import { CuaDriver } from "@trycua/cua-driver"
+```
+
+It does not contain a TypeScript MCP client. Agents already have
+runtime-neutral MCP clients and should configure the executable directly:
+
+```text
+cua-driver mcp
+```
+
+The removed pre-release MCP facade used `CuaDriver.stdio()`, async methods,
+`*Args` interfaces, and a TypeScript stdio transport. Application code migrates
+to the synchronous Rust-backed methods shown below; agent code removes the Cua
+package import and supplies `cua-driver mcp` to its agent SDK.
+
+## SDK example
+
+```ts
+import {
+ CaptureScope,
+ CuaDriver,
+ EndSessionInput,
+ GetDesktopStateInput,
+ StartSessionInput,
+} from "@trycua/cua-driver"
+
+const driver = CuaDriver.connect(undefined) // default installed daemon socket
+driver.startSession(
+ StartSessionInput.new({
+ session: "demo",
+ captureScope: CaptureScope.Desktop,
+ }),
+)
+
+try {
+ const desktop = driver.getDesktopState(
+ GetDesktopStateInput.new({ session: "demo" }),
+ )
+ console.log(desktop.images[0]?.mimeType)
+} finally {
+ driver.endSession(EndSessionInput.new({ session: "demo" }))
+ driver.uniffiDestroy()
+}
+```
+
+The SDK is currently synchronous and requires a native library matching the
+host OS and architecture. Desktop calls return a typed `ToolResult` with text,
+images, verification/error metadata, and `structuredJson` / `rawJson` for
+platform-extensible results. Session lifecycle calls return dedicated
+generated records.
+
+Host-native assembly and loader tests are implemented. Publishing the npm
+package still requires assembling and testing the complete platform-library
+matrix rather than packing a developer's local library.
diff --git a/libs/cua-driver/typescript/package-lock.json b/libs/cua-driver/typescript/package-lock.json
new file mode 100644
index 0000000000..43b1988cae
--- /dev/null
+++ b/libs/cua-driver/typescript/package-lock.json
@@ -0,0 +1,202 @@
+{
+ "name": "@trycua/cua-driver",
+ "version": "0.10.0",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "@trycua/cua-driver",
+ "version": "0.10.0",
+ "license": "MIT",
+ "dependencies": {
+ "@ubjs/core": "0.31.0-3",
+ "@ubjs/node": "0.31.0-3"
+ },
+ "devDependencies": {
+ "@types/node": "^22.0.0",
+ "typescript": "^5.7.0",
+ "uniffi-bindgen-react-native": "0.31.0-3"
+ }
+ },
+ "node_modules/@types/node": {
+ "version": "22.20.1",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-22.20.1.tgz",
+ "integrity": "sha512-EANqOCF9QFyra+4pfxUcX9STKJpCLjMbObVzljIJomAWSnuSIEAvyzEU53GaajbXJEgdh0iEcPL+DGvpUd4k1Q==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "undici-types": "~6.21.0"
+ }
+ },
+ "node_modules/@ubjs/core": {
+ "version": "0.31.0-3",
+ "resolved": "https://registry.npmjs.org/@ubjs/core/-/core-0.31.0-3.tgz",
+ "integrity": "sha512-39XrJgUZ2VVb561sSnkXPhczNoeBsNiSRArecsV0JE7CJq69ajFkcn9/tBAUS2NpgHkLIDU+z6Ks2+1wXnboxg==",
+ "license": "MPL-2.0"
+ },
+ "node_modules/@ubjs/node": {
+ "version": "0.31.0-3",
+ "resolved": "https://registry.npmjs.org/@ubjs/node/-/node-0.31.0-3.tgz",
+ "integrity": "sha512-qNMpi2LICNwxGXZyRF8fSDBSpbezyZbEsydrbiMPJOmtOWr4tmZIEl7jkWGHVGShoBvHfFo4eHp5B4UVP928Cg==",
+ "license": "MPL-2.0",
+ "optionalDependencies": {
+ "@ubjs/node-darwin-arm64": "0.31.0-3",
+ "@ubjs/node-darwin-x64": "0.31.0-3",
+ "@ubjs/node-linux-arm64-gnu": "0.31.0-3",
+ "@ubjs/node-linux-arm64-musl": "0.31.0-3",
+ "@ubjs/node-linux-x64-gnu": "0.31.0-3",
+ "@ubjs/node-linux-x64-musl": "0.31.0-3",
+ "@ubjs/node-win32-arm64-msvc": "0.31.0-3",
+ "@ubjs/node-win32-x64-msvc": "0.31.0-3"
+ }
+ },
+ "node_modules/@ubjs/node-darwin-arm64": {
+ "version": "0.31.0-3",
+ "resolved": "https://registry.npmjs.org/@ubjs/node-darwin-arm64/-/node-darwin-arm64-0.31.0-3.tgz",
+ "integrity": "sha512-GGQVPLkVo4Gc8qVLW4IGvS8bjl8eHXyeP4a97ntGmsAdXwE5gsS29o8xUEFROjhwHKD+9sgVeblCSWVG3CpHsw==",
+ "cpu": [
+ "arm64"
+ ],
+ "license": "MPL-2.0",
+ "optional": true,
+ "os": [
+ "darwin"
+ ]
+ },
+ "node_modules/@ubjs/node-darwin-x64": {
+ "version": "0.31.0-3",
+ "resolved": "https://registry.npmjs.org/@ubjs/node-darwin-x64/-/node-darwin-x64-0.31.0-3.tgz",
+ "integrity": "sha512-2sc47u4XFYOsbmP5EW+Gx8m/yGrYnfFDFQm6+kz7goSWTNg84eEiz3COs9HKJDVuNJ5Khv5XipTO8CFadMLXCw==",
+ "cpu": [
+ "x64"
+ ],
+ "license": "MPL-2.0",
+ "optional": true,
+ "os": [
+ "darwin"
+ ]
+ },
+ "node_modules/@ubjs/node-linux-arm64-gnu": {
+ "version": "0.31.0-3",
+ "resolved": "https://registry.npmjs.org/@ubjs/node-linux-arm64-gnu/-/node-linux-arm64-gnu-0.31.0-3.tgz",
+ "integrity": "sha512-YStVXhYz/5jvlWf/p4fhiVT72unYAbGugifFC9QmO/+hnroQDAQ5t8SARbsc15G4olMcamdIB+GETiUB7gmaYg==",
+ "cpu": [
+ "arm64"
+ ],
+ "libc": [
+ "glibc"
+ ],
+ "license": "MPL-2.0",
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@ubjs/node-linux-arm64-musl": {
+ "version": "0.31.0-3",
+ "resolved": "https://registry.npmjs.org/@ubjs/node-linux-arm64-musl/-/node-linux-arm64-musl-0.31.0-3.tgz",
+ "integrity": "sha512-Izp4nvfy/LmibzFowAztkoDOksCR2fb2zl6fh1ojR1HEsg0rAGruxtI8d3fn8DI0lBXwqmn6SF///oD4mFNJPQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "libc": [
+ "musl"
+ ],
+ "license": "MPL-2.0",
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@ubjs/node-linux-x64-gnu": {
+ "version": "0.31.0-3",
+ "resolved": "https://registry.npmjs.org/@ubjs/node-linux-x64-gnu/-/node-linux-x64-gnu-0.31.0-3.tgz",
+ "integrity": "sha512-Xdm21blyg5U/kW6s7OMvgrr8coGTkUlt26DVR9x8gKISif+E3YwdEskbFScWqystAiJnfjw7xHEc8UMu0Qlz7Q==",
+ "cpu": [
+ "x64"
+ ],
+ "libc": [
+ "glibc"
+ ],
+ "license": "MPL-2.0",
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@ubjs/node-linux-x64-musl": {
+ "version": "0.31.0-3",
+ "resolved": "https://registry.npmjs.org/@ubjs/node-linux-x64-musl/-/node-linux-x64-musl-0.31.0-3.tgz",
+ "integrity": "sha512-fFQ9BWS6i2LUH9SJgD9oEiKXXo/say59vHy7usFe1t7C2xvwvP34f5SuxXmWP9R8fHyA0aC4kIZ+TTwyHSv1Kw==",
+ "cpu": [
+ "x64"
+ ],
+ "libc": [
+ "musl"
+ ],
+ "license": "MPL-2.0",
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@ubjs/node-win32-arm64-msvc": {
+ "version": "0.31.0-3",
+ "resolved": "https://registry.npmjs.org/@ubjs/node-win32-arm64-msvc/-/node-win32-arm64-msvc-0.31.0-3.tgz",
+ "integrity": "sha512-ID6rSz1NmPsWTNBBNAw4OnJ5Dj8pcbtNJtdPB3OxcGigLBd/e0x7buhSI7os6Mo5iYtEdCynBRQHFJwub5XSPg==",
+ "cpu": [
+ "arm64"
+ ],
+ "license": "MPL-2.0",
+ "optional": true,
+ "os": [
+ "win32"
+ ]
+ },
+ "node_modules/@ubjs/node-win32-x64-msvc": {
+ "version": "0.31.0-3",
+ "resolved": "https://registry.npmjs.org/@ubjs/node-win32-x64-msvc/-/node-win32-x64-msvc-0.31.0-3.tgz",
+ "integrity": "sha512-wevs+Y+szwcCUT8IJFbB4/1nfxyRv/51l8oG7FGUPWD1xLPyuHfJBG27C+PDeC7KRzes/2n6aLo4DGZbr/LYTw==",
+ "cpu": [
+ "x64"
+ ],
+ "license": "MPL-2.0",
+ "optional": true,
+ "os": [
+ "win32"
+ ]
+ },
+ "node_modules/typescript": {
+ "version": "5.9.3",
+ "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
+ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
+ "dev": true,
+ "license": "Apache-2.0",
+ "bin": {
+ "tsc": "bin/tsc",
+ "tsserver": "bin/tsserver"
+ },
+ "engines": {
+ "node": ">=14.17"
+ }
+ },
+ "node_modules/undici-types": {
+ "version": "6.21.0",
+ "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
+ "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/uniffi-bindgen-react-native": {
+ "version": "0.31.0-3",
+ "resolved": "https://registry.npmjs.org/uniffi-bindgen-react-native/-/uniffi-bindgen-react-native-0.31.0-3.tgz",
+ "integrity": "sha512-br7giBJRr/j00rdMXhOZGMGuDWMAVUcxC9O3lco0KRqzEAxUz00+gegPW5tKamvKbrnj7NB682XUCYrcagtxFA==",
+ "dev": true,
+ "license": "MPL-2.0",
+ "bin": {
+ "ubrn": "bin/cli.cjs",
+ "uniffi-bindgen-react-native": "bin/cli.cjs"
+ }
+ }
+ }
+}
diff --git a/libs/cua-driver/typescript/package.json b/libs/cua-driver/typescript/package.json
new file mode 100644
index 0000000000..a9450fe942
--- /dev/null
+++ b/libs/cua-driver/typescript/package.json
@@ -0,0 +1,42 @@
+{
+ "name": "@trycua/cua-driver",
+ "version": "0.10.0",
+ "description": "Rust-backed Cua Driver SDK for client applications",
+ "type": "module",
+ "license": "MIT",
+ "main": "./dist/index.js",
+ "types": "./dist/index.d.ts",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/index.js"
+ }
+ },
+ "files": [
+ "dist/index.js",
+ "dist/index.d.ts",
+ "dist/native",
+ "README.md"
+ ],
+ "publishConfig": {
+ "access": "public"
+ },
+ "scripts": {
+ "build": "tsc -p tsconfig.json",
+ "prepack": "npm run build",
+ "typecheck": "tsc -p tsconfig.json --noEmit",
+ "test": "npm run build && node --test test/*.test.mjs",
+ "generate:uniffi": "node ../scripts/generate-uniffi-bindings.mjs",
+ "generate:uniffi:check": "node ../scripts/generate-uniffi-bindings.mjs --check",
+ "stage:uniffi": "node ../scripts/stage-uniffi-library.mjs"
+ },
+ "devDependencies": {
+ "@types/node": "^22.0.0",
+ "typescript": "^5.7.0",
+ "uniffi-bindgen-react-native": "0.31.0-3"
+ },
+ "dependencies": {
+ "@ubjs/core": "0.31.0-3",
+ "@ubjs/node": "0.31.0-3"
+ }
+}
diff --git a/libs/cua-driver/typescript/src/index.ts b/libs/cua-driver/typescript/src/index.ts
new file mode 100644
index 0000000000..90cc50ddfc
--- /dev/null
+++ b/libs/cua-driver/typescript/src/index.ts
@@ -0,0 +1,8 @@
+/**
+ * Rust-backed SDK for Cua Driver client applications.
+ *
+ * Agents should configure `cua-driver mcp` through their runtime's existing
+ * MCP client instead of importing a language MCP facade.
+ */
+export * from "./native/index.js"
+export { default } from "./native/index.js"
diff --git a/libs/cua-driver/typescript/src/native/cua_driver_contract-ffi.ts b/libs/cua-driver/typescript/src/native/cua_driver_contract-ffi.ts
new file mode 100644
index 0000000000..f83a073895
--- /dev/null
+++ b/libs/cua-driver/typescript/src/native/cua_driver_contract-ffi.ts
@@ -0,0 +1,369 @@
+// This file was autogenerated by some hot garbage in the `uniffi-bindgen-react-native` crate.
+// Trust me, you don't want to mess with it!
+/* tslint:disable */
+/* eslint-disable */
+// @ts-nocheck
+
+import lib from "@ubjs/node";
+const { UniffiNativeModule, FfiType, resolveLibPath } = lib;
+
+import {
+ type StructuralEquality as UniffiStructuralEquality,
+ type UniffiForeignFuture as RuntimeUniffiForeignFuture,
+ type UniffiRustCallStatus,
+ type UniffiGcObject,
+ type UniffiRustFutureContinuationCallback as RuntimeUniffiRustFutureContinuationCallback,
+ type UniffiResult,
+} from '@ubjs/core';
+
+const DEFINITIONS = {
+ symbols: {
+ rustbuffer_alloc: "ffi_cua_driver_contract_rustbuffer_alloc",
+ rustbuffer_free: "ffi_cua_driver_contract_rustbuffer_free",
+ rustbuffer_from_bytes: "ffi_cua_driver_contract_rustbuffer_from_bytes",
+ },
+ functions: {
+ "ffi_cua_driver_contract_rust_future_poll_u8": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_cancel_u8": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_complete_u8": {
+ args: [FfiType.Handle],
+ ret: FfiType.UInt8,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_contract_rust_future_free_u8": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_poll_i8": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_cancel_i8": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_complete_i8": {
+ args: [FfiType.Handle],
+ ret: FfiType.Int8,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_contract_rust_future_free_i8": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_poll_u16": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_cancel_u16": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_complete_u16": {
+ args: [FfiType.Handle],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_contract_rust_future_free_u16": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_poll_i16": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_cancel_i16": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_complete_i16": {
+ args: [FfiType.Handle],
+ ret: FfiType.Int16,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_contract_rust_future_free_i16": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_poll_u32": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_cancel_u32": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_complete_u32": {
+ args: [FfiType.Handle],
+ ret: FfiType.UInt32,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_contract_rust_future_free_u32": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_poll_i32": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_cancel_i32": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_complete_i32": {
+ args: [FfiType.Handle],
+ ret: FfiType.Int32,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_contract_rust_future_free_i32": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_poll_u64": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_cancel_u64": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_complete_u64": {
+ args: [FfiType.Handle],
+ ret: FfiType.Handle,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_contract_rust_future_free_u64": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_poll_i64": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_cancel_i64": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_complete_i64": {
+ args: [FfiType.Handle],
+ ret: FfiType.Int64,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_contract_rust_future_free_i64": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_poll_f32": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_cancel_f32": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_complete_f32": {
+ args: [FfiType.Handle],
+ ret: FfiType.Float32,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_contract_rust_future_free_f32": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_poll_f64": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_cancel_f64": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_complete_f64": {
+ args: [FfiType.Handle],
+ ret: FfiType.Float64,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_contract_rust_future_free_f64": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_poll_rust_buffer": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_cancel_rust_buffer": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_complete_rust_buffer": {
+ args: [FfiType.Handle],
+ ret: FfiType.RustBuffer,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_contract_rust_future_free_rust_buffer": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_poll_void": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_cancel_void": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_rust_future_complete_void": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_contract_rust_future_free_void": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_contract_uniffi_contract_version": {
+ args: [],
+ ret: FfiType.UInt32,
+ hasRustCallStatus: false,
+ },
+ },
+ callbacks: {
+ "RustFutureContinuationCallback": {
+ args: [FfiType.Handle, FfiType.Int8],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ForeignFutureDroppedCallback": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ },
+ structs: {
+ "ForeignFutureDroppedCallbackStruct": [
+ { name: "handle", type: FfiType.Handle },
+ { name: "free", type: FfiType.Callback("ForeignFutureDroppedCallback") },
+ ],
+ },
+} as const;
+
+interface NativeModuleInterface {
+ ffi_cua_driver_contract_rust_future_poll_u8(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_contract_rust_future_cancel_u8(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_complete_u8(handle: bigint, uniffi_out_err: UniffiRustCallStatus): number;
+ ffi_cua_driver_contract_rust_future_free_u8(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_poll_i8(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_contract_rust_future_cancel_i8(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_complete_i8(handle: bigint, uniffi_out_err: UniffiRustCallStatus): number;
+ ffi_cua_driver_contract_rust_future_free_i8(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_poll_u16(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_contract_rust_future_cancel_u16(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_complete_u16(handle: bigint, uniffi_out_err: UniffiRustCallStatus): number;
+ ffi_cua_driver_contract_rust_future_free_u16(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_poll_i16(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_contract_rust_future_cancel_i16(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_complete_i16(handle: bigint, uniffi_out_err: UniffiRustCallStatus): number;
+ ffi_cua_driver_contract_rust_future_free_i16(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_poll_u32(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_contract_rust_future_cancel_u32(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_complete_u32(handle: bigint, uniffi_out_err: UniffiRustCallStatus): number;
+ ffi_cua_driver_contract_rust_future_free_u32(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_poll_i32(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_contract_rust_future_cancel_i32(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_complete_i32(handle: bigint, uniffi_out_err: UniffiRustCallStatus): number;
+ ffi_cua_driver_contract_rust_future_free_i32(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_poll_u64(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_contract_rust_future_cancel_u64(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_complete_u64(handle: bigint, uniffi_out_err: UniffiRustCallStatus): bigint;
+ ffi_cua_driver_contract_rust_future_free_u64(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_poll_i64(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_contract_rust_future_cancel_i64(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_complete_i64(handle: bigint, uniffi_out_err: UniffiRustCallStatus): bigint;
+ ffi_cua_driver_contract_rust_future_free_i64(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_poll_f32(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_contract_rust_future_cancel_f32(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_complete_f32(handle: bigint, uniffi_out_err: UniffiRustCallStatus): number;
+ ffi_cua_driver_contract_rust_future_free_f32(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_poll_f64(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_contract_rust_future_cancel_f64(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_complete_f64(handle: bigint, uniffi_out_err: UniffiRustCallStatus): number;
+ ffi_cua_driver_contract_rust_future_free_f64(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_poll_rust_buffer(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_contract_rust_future_cancel_rust_buffer(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_complete_rust_buffer(handle: bigint, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
+ ffi_cua_driver_contract_rust_future_free_rust_buffer(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_poll_void(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_contract_rust_future_cancel_void(handle: bigint): void;
+ ffi_cua_driver_contract_rust_future_complete_void(handle: bigint, uniffi_out_err: UniffiRustCallStatus): void;
+ ffi_cua_driver_contract_rust_future_free_void(handle: bigint): void;
+ ffi_cua_driver_contract_uniffi_contract_version(): number;
+ // Codegen call sites use these via `nativeModule().rustbuffer_alloc(...)`
+ // and `nativeModule().rustbuffer_free(...)`. The runtime's registered
+ // module exposes them as method properties.
+ rustbuffer_alloc(n: number): Uint8Array;
+ rustbuffer_free(view: Uint8Array): void;
+}
+
+let _nativeModule: NativeModuleInterface | undefined;
+const getter: () => NativeModuleInterface = () => {
+ if (!_nativeModule) {
+ const libPath = resolveLibPath({
+ crateName: "cua_driver_sdk",
+ callerUrl: import.meta.url,
+ });
+ const mod_ = UniffiNativeModule.open(libPath);
+ _nativeModule = mod_.register(DEFINITIONS) as unknown as NativeModuleInterface;
+ }
+ return _nativeModule;
+};
+export default getter;
+
+// Structs and function types for calling back into Typescript from Rust.
+export type UniffiRustFutureContinuationCallback = (data: bigint, pollResult: number) => void;
+export type UniffiForeignFutureDroppedCallback = (handle: bigint) => void;
+export type UniffiForeignFutureDroppedCallbackStruct = {
+ handle: bigint;
+ free: UniffiForeignFutureDroppedCallback;
+};
diff --git a/libs/cua-driver/typescript/src/native/cua_driver_contract.ts b/libs/cua-driver/typescript/src/native/cua_driver_contract.ts
new file mode 100644
index 0000000000..c8750c93b0
--- /dev/null
+++ b/libs/cua-driver/typescript/src/native/cua_driver_contract.ts
@@ -0,0 +1,1259 @@
+// This file was autogenerated by some hot garbage in the `uniffi-bindgen-react-native` crate.
+// Trust me, you don't want to mess with it!
+/* tslint:disable */
+/* eslint-disable */
+// @ts-nocheck
+import nativeModule from "./cua_driver_contract-ffi.js";
+import { type UniffiRustFutureContinuationCallback, type UniffiForeignFutureDroppedCallback, type UniffiForeignFutureDroppedCallbackStruct,
+} from "./cua_driver_contract-ffi.js";
+import { type UniffiByteArray, AbstractFfiConverterByteArray, FfiConverterArray, FfiConverterBool, FfiConverterFloat64, FfiConverterInt32, FfiConverterOptional, FfiConverterUInt32, FfiConverterUInt64, FfiConverterUInt8, RustBuffer, UniffiEnum, UniffiInternalError, UniffiRustCaller, uniffiCreateFfiConverterString, uniffiCreateRecord,
+} from "@ubjs/core";
+const uniffiCaller = new UniffiRustCaller(() => ({ code: 0 }));
+
+const uniffiIsDebug =
+ // @ts-ignore -- The process global might not be defined
+ typeof process !== "object" ||
+ // @ts-ignore -- The process global might not be defined
+ process?.env?.NODE_ENV !== "production" ||
+ false;
+
+// Public interface members begin here.
+
+export enum DesktopScope {
+ Desktop
+}
+
+const FfiConverterTypeDesktopScope = (() => {
+ const ordinalConverter = FfiConverterInt32;
+ type TypeName = DesktopScope;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ switch (ordinalConverter.read(from)) {
+ case 1: return DesktopScope.Desktop;
+ default: throw new UniffiInternalError.UnexpectedEnumCase();
+ }
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ switch (value) {
+ case DesktopScope.Desktop: return ordinalConverter.write(1, into);
+ }
+ }
+ allocationSize(value: TypeName): number {
+ return ordinalConverter.allocationSize(0);
+ }
+ }
+ return new FFIConverter();
+})();
+
+const stringConverter = (() => {
+ const encoder = new TextEncoder();
+ const decoder = new TextDecoder();
+ return {
+ stringToBytes: (s: string) => encoder.encode(s),
+ bytesToString: (ab: UniffiByteArray) => decoder.decode(ab),
+ stringByteLength: (s: string) => encoder.encode(s).byteLength,
+ writeStringIntoBuffer: (s: string, buf: any, offset: number): number => {
+ const view = new Uint8Array(
+ buf.arrayBuffer,
+ offset,
+ buf.arrayBuffer.byteLength - offset,
+ );
+ return encoder.encodeInto(s, view).written;
+ },
+ readStringFromBuffer: (buf: any, offset: number, length: number): string =>
+ decoder.decode(new Uint8Array(buf.arrayBuffer, offset, length)),
+ };
+})();
+const FfiConverterString = uniffiCreateFfiConverterString(stringConverter);
+
+export enum ClickButton {
+ Left,
+ Right,
+ Middle
+}
+
+const FfiConverterTypeClickButton = (() => {
+ const ordinalConverter = FfiConverterInt32;
+ type TypeName = ClickButton;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ switch (ordinalConverter.read(from)) {
+ case 1: return ClickButton.Left;
+ case 2: return ClickButton.Right;
+ case 3: return ClickButton.Middle;
+ default: throw new UniffiInternalError.UnexpectedEnumCase();
+ }
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ switch (value) {
+ case ClickButton.Left: return ordinalConverter.write(1, into);
+ case ClickButton.Right: return ordinalConverter.write(2, into);
+ case ClickButton.Middle: return ordinalConverter.write(3, into);
+ }
+ }
+ allocationSize(value: TypeName): number {
+ return ordinalConverter.allocationSize(0);
+ }
+ }
+ return new FFIConverter();
+})();
+
+export type ClickInput = {
+ x: number,
+ y: number,
+ scope: DesktopScope,
+ /**
+ * Optional session id.
+ */
+ session?: string,
+ button?: ClickButton,
+ count?: number
+}
+
+/**
+ * Generated factory for {@link ClickInput} record objects.
+ */
+export const ClickInput = (() => {
+ const defaults = () => ({
+ });
+ const create = (() => {
+ return uniffiCreateRecord<ClickInput, ReturnType<typeof defaults>>(defaults);
+ })();
+ return Object.freeze({
+ create,
+ new: create,
+ defaults: () => Object.freeze(defaults()) as Partial<ClickInput>,
+ });
+})();
+
+const FfiConverterTypeClickInput = (() => {
+ type TypeName = ClickInput;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ return {
+ x: FfiConverterFloat64.read(from),
+ y: FfiConverterFloat64.read(from),
+ scope: FfiConverterTypeDesktopScope.read(from),
+ session: FfiConverterOptionalString.read(from),
+ button: FfiConverterOptionalTypeClickButton.read(from),
+ count: FfiConverterOptionalUInt32.read(from)
+ };
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ FfiConverterFloat64.write(value.x, into);
+ FfiConverterFloat64.write(value.y, into);
+ FfiConverterTypeDesktopScope.write(value.scope, into);
+ FfiConverterOptionalString.write(value.session, into);
+ FfiConverterOptionalTypeClickButton.write(value.button, into);
+ FfiConverterOptionalUInt32.write(value.count, into);
+ }
+ allocationSize(value: TypeName): number {
+ return FfiConverterFloat64.allocationSize(value.x) +
+ FfiConverterFloat64.allocationSize(value.y) +
+ FfiConverterTypeDesktopScope.allocationSize(value.scope) +
+ FfiConverterOptionalString.allocationSize(value.session) +
+ FfiConverterOptionalTypeClickButton.allocationSize(value.button) +
+ FfiConverterOptionalUInt32.allocationSize(value.count);
+
+ }
+ };
+ return new FFIConverter();
+})();
+
+export type DragInput = {
+ fromX: number,
+ fromY: number,
+ toX: number,
+ toY: number,
+ scope: DesktopScope,
+ /**
+ * Optional session id.
+ */
+ session?: string,
+ durationMs?: bigint,
+ steps?: bigint,
+ button?: ClickButton,
+ modifier?: Array<string>
+}
+
+/**
+ * Generated factory for {@link DragInput} record objects.
+ */
+export const DragInput = (() => {
+ const defaults = () => ({
+ });
+ const create = (() => {
+ return uniffiCreateRecord<DragInput, ReturnType<typeof defaults>>(defaults);
+ })();
+ return Object.freeze({
+ create,
+ new: create,
+ defaults: () => Object.freeze(defaults()) as Partial<DragInput>,
+ });
+})();
+
+const FfiConverterTypeDragInput = (() => {
+ type TypeName = DragInput;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ return {
+ fromX: FfiConverterFloat64.read(from),
+ fromY: FfiConverterFloat64.read(from),
+ toX: FfiConverterFloat64.read(from),
+ toY: FfiConverterFloat64.read(from),
+ scope: FfiConverterTypeDesktopScope.read(from),
+ session: FfiConverterOptionalString.read(from),
+ durationMs: FfiConverterOptionalUInt64.read(from),
+ steps: FfiConverterOptionalUInt64.read(from),
+ button: FfiConverterOptionalTypeClickButton.read(from),
+ modifier: FfiConverterOptionalSequenceString.read(from)
+ };
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ FfiConverterFloat64.write(value.fromX, into);
+ FfiConverterFloat64.write(value.fromY, into);
+ FfiConverterFloat64.write(value.toX, into);
+ FfiConverterFloat64.write(value.toY, into);
+ FfiConverterTypeDesktopScope.write(value.scope, into);
+ FfiConverterOptionalString.write(value.session, into);
+ FfiConverterOptionalUInt64.write(value.durationMs, into);
+ FfiConverterOptionalUInt64.write(value.steps, into);
+ FfiConverterOptionalTypeClickButton.write(value.button, into);
+ FfiConverterOptionalSequenceString.write(value.modifier, into);
+ }
+ allocationSize(value: TypeName): number {
+ return FfiConverterFloat64.allocationSize(value.fromX) +
+ FfiConverterFloat64.allocationSize(value.fromY) +
+ FfiConverterFloat64.allocationSize(value.toX) +
+ FfiConverterFloat64.allocationSize(value.toY) +
+ FfiConverterTypeDesktopScope.allocationSize(value.scope) +
+ FfiConverterOptionalString.allocationSize(value.session) +
+ FfiConverterOptionalUInt64.allocationSize(value.durationMs) +
+ FfiConverterOptionalUInt64.allocationSize(value.steps) +
+ FfiConverterOptionalTypeClickButton.allocationSize(value.button) +
+ FfiConverterOptionalSequenceString.allocationSize(value.modifier);
+
+ }
+ };
+ return new FFIConverter();
+})();
+
+export type EndSessionInput = {
+ /**
+ * The session id to end.
+ */
+ session: string
+}
+
+/**
+ * Generated factory for {@link EndSessionInput} record objects.
+ */
+export const EndSessionInput = (() => {
+ const defaults = () => ({
+ });
+ const create = (() => {
+ return uniffiCreateRecord<EndSessionInput, ReturnType<typeof defaults>>(defaults);
+ })();
+ return Object.freeze({
+ create,
+ new: create,
+ defaults: () => Object.freeze(defaults()) as Partial<EndSessionInput>,
+ });
+})();
+
+const FfiConverterTypeEndSessionInput = (() => {
+ type TypeName = EndSessionInput;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ return {
+ session: FfiConverterString.read(from)
+ };
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ FfiConverterString.write(value.session, into);
+ }
+ allocationSize(value: TypeName): number {
+ return FfiConverterString.allocationSize(value.session);
+
+ }
+ };
+ return new FFIConverter();
+})();
+
+/**
+ * Successful structured result returned by `end_session`.
+ */
+export type EndSessionOutput = {
+ session: string,
+ active: boolean
+}
+
+/**
+ * Generated factory for {@link EndSessionOutput} record objects.
+ */
+export const EndSessionOutput = (() => {
+ const defaults = () => ({
+ });
+ const create = (() => {
+ return uniffiCreateRecord<EndSessionOutput, ReturnType<typeof defaults>>(defaults);
+ })();
+ return Object.freeze({
+ create,
+ new: create,
+ defaults: () => Object.freeze(defaults()) as Partial<EndSessionOutput>,
+ });
+})();
+
+const FfiConverterTypeEndSessionOutput = (() => {
+ type TypeName = EndSessionOutput;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ return {
+ session: FfiConverterString.read(from),
+ active: FfiConverterBool.read(from)
+ };
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ FfiConverterString.write(value.session, into);
+ FfiConverterBool.write(value.active, into);
+ }
+ allocationSize(value: TypeName): number {
+ return FfiConverterString.allocationSize(value.session) +
+ FfiConverterBool.allocationSize(value.active);
+
+ }
+ };
+ return new FFIConverter();
+})();
+
+export enum EscalationReason {
+ AxTreePixelMismatch,
+ BackgroundDeliveryFailed,
+ ForegroundIneffective,
+ NoWindowTarget,
+ Other
+}
+
+const FfiConverterTypeEscalationReason = (() => {
+ const ordinalConverter = FfiConverterInt32;
+ type TypeName = EscalationReason;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ switch (ordinalConverter.read(from)) {
+ case 1: return EscalationReason.AxTreePixelMismatch;
+ case 2: return EscalationReason.BackgroundDeliveryFailed;
+ case 3: return EscalationReason.ForegroundIneffective;
+ case 4: return EscalationReason.NoWindowTarget;
+ case 5: return EscalationReason.Other;
+ default: throw new UniffiInternalError.UnexpectedEnumCase();
+ }
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ switch (value) {
+ case EscalationReason.AxTreePixelMismatch: return ordinalConverter.write(1, into);
+ case EscalationReason.BackgroundDeliveryFailed: return ordinalConverter.write(2, into);
+ case EscalationReason.ForegroundIneffective: return ordinalConverter.write(3, into);
+ case EscalationReason.NoWindowTarget: return ordinalConverter.write(4, into);
+ case EscalationReason.Other: return ordinalConverter.write(5, into);
+ }
+ }
+ allocationSize(value: TypeName): number {
+ return ordinalConverter.allocationSize(0);
+ }
+ }
+ return new FFIConverter();
+})();
+
+export type EscalateSessionInput = {
+ session: string,
+ reason: EscalationReason,
+ /**
+ * Optional bounded diagnostic detail. Never use secrets or page content.
+ */
+ detail?: string
+}
+
+/**
+ * Generated factory for {@link EscalateSessionInput} record objects.
+ */
+export const EscalateSessionInput = (() => {
+ const defaults = () => ({
+ });
+ const create = (() => {
+ return uniffiCreateRecord<EscalateSessionInput, ReturnType<typeof defaults>>(defaults);
+ })();
+ return Object.freeze({
+ create,
+ new: create,
+ defaults: () => Object.freeze(defaults()) as Partial<EscalateSessionInput>,
+ });
+})();
+
+const FfiConverterTypeEscalateSessionInput = (() => {
+ type TypeName = EscalateSessionInput;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ return {
+ session: FfiConverterString.read(from),
+ reason: FfiConverterTypeEscalationReason.read(from),
+ detail: FfiConverterOptionalString.read(from)
+ };
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ FfiConverterString.write(value.session, into);
+ FfiConverterTypeEscalationReason.write(value.reason, into);
+ FfiConverterOptionalString.write(value.detail, into);
+ }
+ allocationSize(value: TypeName): number {
+ return FfiConverterString.allocationSize(value.session) +
+ FfiConverterTypeEscalationReason.allocationSize(value.reason) +
+ FfiConverterOptionalString.allocationSize(value.detail);
+
+ }
+ };
+ return new FFIConverter();
+})();
+
+export type GetCursorPositionInput = {
+ /**
+ * Optional session id.
+ */
+ session?: string
+}
+
+/**
+ * Generated factory for {@link GetCursorPositionInput} record objects.
+ */
+export const GetCursorPositionInput = (() => {
+ const defaults = () => ({
+ });
+ const create = (() => {
+ return uniffiCreateRecord<GetCursorPositionInput, ReturnType<typeof defaults>>(defaults);
+ })();
+ return Object.freeze({
+ create,
+ new: create,
+ defaults: () => Object.freeze(defaults()) as Partial<GetCursorPositionInput>,
+ });
+})();
+
+const FfiConverterTypeGetCursorPositionInput = (() => {
+ type TypeName = GetCursorPositionInput;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ return {
+ session: FfiConverterOptionalString.read(from)
+ };
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ FfiConverterOptionalString.write(value.session, into);
+ }
+ allocationSize(value: TypeName): number {
+ return FfiConverterOptionalString.allocationSize(value.session);
+
+ }
+ };
+ return new FFIConverter();
+})();
+
+export type GetDesktopStateInput = {
+ /**
+ * Optional session id.
+ */
+ session?: string,
+ /**
+ * Write the PNG here instead of returning base64.
+ */
+ screenshotOutFile?: string
+}
+
+/**
+ * Generated factory for {@link GetDesktopStateInput} record objects.
+ */
+export const GetDesktopStateInput = (() => {
+ const defaults = () => ({
+ });
+ const create = (() => {
+ return uniffiCreateRecord<GetDesktopStateInput, ReturnType<typeof defaults>>(defaults);
+ })();
+ return Object.freeze({
+ create,
+ new: create,
+ defaults: () => Object.freeze(defaults()) as Partial<GetDesktopStateInput>,
+ });
+})();
+
+const FfiConverterTypeGetDesktopStateInput = (() => {
+ type TypeName = GetDesktopStateInput;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ return {
+ session: FfiConverterOptionalString.read(from),
+ screenshotOutFile: FfiConverterOptionalString.read(from)
+ };
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ FfiConverterOptionalString.write(value.session, into);
+ FfiConverterOptionalString.write(value.screenshotOutFile, into);
+ }
+ allocationSize(value: TypeName): number {
+ return FfiConverterOptionalString.allocationSize(value.session) +
+ FfiConverterOptionalString.allocationSize(value.screenshotOutFile);
+
+ }
+ };
+ return new FFIConverter();
+})();
+
+export type GetScreenSizeInput = {
+ /**
+ * Optional session id.
+ */
+ session?: string
+}
+
+/**
+ * Generated factory for {@link GetScreenSizeInput} record objects.
+ */
+export const GetScreenSizeInput = (() => {
+ const defaults = () => ({
+ });
+ const create = (() => {
+ return uniffiCreateRecord<GetScreenSizeInput, ReturnType<typeof defaults>>(defaults);
+ })();
+ return Object.freeze({
+ create,
+ new: create,
+ defaults: () => Object.freeze(defaults()) as Partial<GetScreenSizeInput>,
+ });
+})();
+
+const FfiConverterTypeGetScreenSizeInput = (() => {
+ type TypeName = GetScreenSizeInput;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ return {
+ session: FfiConverterOptionalString.read(from)
+ };
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ FfiConverterOptionalString.write(value.session, into);
+ }
+ allocationSize(value: TypeName): number {
+ return FfiConverterOptionalString.allocationSize(value.session);
+
+ }
+ };
+ return new FFIConverter();
+})();
+
+export type GetSessionStateInput = {
+ session: string
+}
+
+/**
+ * Generated factory for {@link GetSessionStateInput} record objects.
+ */
+export const GetSessionStateInput = (() => {
+ const defaults = () => ({
+ });
+ const create = (() => {
+ return uniffiCreateRecord<GetSessionStateInput, ReturnType<typeof defaults>>(defaults);
+ })();
+ return Object.freeze({
+ create,
+ new: create,
+ defaults: () => Object.freeze(defaults()) as Partial<GetSessionStateInput>,
+ });
+})();
+
+const FfiConverterTypeGetSessionStateInput = (() => {
+ type TypeName = GetSessionStateInput;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ return {
+ session: FfiConverterString.read(from)
+ };
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ FfiConverterString.write(value.session, into);
+ }
+ allocationSize(value: TypeName): number {
+ return FfiConverterString.allocationSize(value.session);
+
+ }
+ };
+ return new FFIConverter();
+})();
+
+export type HotkeyInput = {
+ keys: Array<string>,
+ scope: DesktopScope,
+ /**
+ * Optional session id.
+ */
+ session?: string
+}
+
+/**
+ * Generated factory for {@link HotkeyInput} record objects.
+ */
+export const HotkeyInput = (() => {
+ const defaults = () => ({
+ });
+ const create = (() => {
+ return uniffiCreateRecord<HotkeyInput, ReturnType<typeof defaults>>(defaults);
+ })();
+ return Object.freeze({
+ create,
+ new: create,
+ defaults: () => Object.freeze(defaults()) as Partial<HotkeyInput>,
+ });
+})();
+
+const FfiConverterTypeHotkeyInput = (() => {
+ type TypeName = HotkeyInput;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ return {
+ keys: FfiConverterSequenceString.read(from),
+ scope: FfiConverterTypeDesktopScope.read(from),
+ session: FfiConverterOptionalString.read(from)
+ };
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ FfiConverterSequenceString.write(value.keys, into);
+ FfiConverterTypeDesktopScope.write(value.scope, into);
+ FfiConverterOptionalString.write(value.session, into);
+ }
+ allocationSize(value: TypeName): number {
+ return FfiConverterSequenceString.allocationSize(value.keys) +
+ FfiConverterTypeDesktopScope.allocationSize(value.scope) +
+ FfiConverterOptionalString.allocationSize(value.session);
+
+ }
+ };
+ return new FFIConverter();
+})();
+
+export type MoveCursorInput = {
+ x: number,
+ y: number,
+ scope: DesktopScope,
+ /**
+ * Optional session id.
+ */
+ session?: string
+}
+
+/**
+ * Generated factory for {@link MoveCursorInput} record objects.
+ */
+export const MoveCursorInput = (() => {
+ const defaults = () => ({
+ });
+ const create = (() => {
+ return uniffiCreateRecord<MoveCursorInput, ReturnType<typeof defaults>>(defaults);
+ })();
+ return Object.freeze({
+ create,
+ new: create,
+ defaults: () => Object.freeze(defaults()) as Partial<MoveCursorInput>,
+ });
+})();
+
+const FfiConverterTypeMoveCursorInput = (() => {
+ type TypeName = MoveCursorInput;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ return {
+ x: FfiConverterFloat64.read(from),
+ y: FfiConverterFloat64.read(from),
+ scope: FfiConverterTypeDesktopScope.read(from),
+ session: FfiConverterOptionalString.read(from)
+ };
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ FfiConverterFloat64.write(value.x, into);
+ FfiConverterFloat64.write(value.y, into);
+ FfiConverterTypeDesktopScope.write(value.scope, into);
+ FfiConverterOptionalString.write(value.session, into);
+ }
+ allocationSize(value: TypeName): number {
+ return FfiConverterFloat64.allocationSize(value.x) +
+ FfiConverterFloat64.allocationSize(value.y) +
+ FfiConverterTypeDesktopScope.allocationSize(value.scope) +
+ FfiConverterOptionalString.allocationSize(value.session);
+
+ }
+ };
+ return new FFIConverter();
+})();
+
+export type PressKeyInput = {
+ key: string,
+ scope: DesktopScope,
+ /**
+ * Optional session id.
+ */
+ session?: string,
+ modifiers?: Array<string>
+}
+
+/**
+ * Generated factory for {@link PressKeyInput} record objects.
+ */
+export const PressKeyInput = (() => {
+ const defaults = () => ({
+ });
+ const create = (() => {
+ return uniffiCreateRecord<PressKeyInput, ReturnType<typeof defaults>>(defaults);
+ })();
+ return Object.freeze({
+ create,
+ new: create,
+ defaults: () => Object.freeze(defaults()) as Partial<PressKeyInput>,
+ });
+})();
+
+const FfiConverterTypePressKeyInput = (() => {
+ type TypeName = PressKeyInput;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ return {
+ key: FfiConverterString.read(from),
+ scope: FfiConverterTypeDesktopScope.read(from),
+ session: FfiConverterOptionalString.read(from),
+ modifiers: FfiConverterOptionalSequenceString.read(from)
+ };
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ FfiConverterString.write(value.key, into);
+ FfiConverterTypeDesktopScope.write(value.scope, into);
+ FfiConverterOptionalString.write(value.session, into);
+ FfiConverterOptionalSequenceString.write(value.modifiers, into);
+ }
+ allocationSize(value: TypeName): number {
+ return FfiConverterString.allocationSize(value.key) +
+ FfiConverterTypeDesktopScope.allocationSize(value.scope) +
+ FfiConverterOptionalString.allocationSize(value.session) +
+ FfiConverterOptionalSequenceString.allocationSize(value.modifiers);
+
+ }
+ };
+ return new FFIConverter();
+})();
+
+export enum ScrollDirection {
+ Up,
+ Down,
+ Left,
+ Right
+}
+
+const FfiConverterTypeScrollDirection = (() => {
+ const ordinalConverter = FfiConverterInt32;
+ type TypeName = ScrollDirection;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ switch (ordinalConverter.read(from)) {
+ case 1: return ScrollDirection.Up;
+ case 2: return ScrollDirection.Down;
+ case 3: return ScrollDirection.Left;
+ case 4: return ScrollDirection.Right;
+ default: throw new UniffiInternalError.UnexpectedEnumCase();
+ }
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ switch (value) {
+ case ScrollDirection.Up: return ordinalConverter.write(1, into);
+ case ScrollDirection.Down: return ordinalConverter.write(2, into);
+ case ScrollDirection.Left: return ordinalConverter.write(3, into);
+ case ScrollDirection.Right: return ordinalConverter.write(4, into);
+ }
+ }
+ allocationSize(value: TypeName): number {
+ return ordinalConverter.allocationSize(0);
+ }
+ }
+ return new FFIConverter();
+})();
+
+export enum ScrollBy {
+ Line,
+ Page
+}
+
+const FfiConverterTypeScrollBy = (() => {
+ const ordinalConverter = FfiConverterInt32;
+ type TypeName = ScrollBy;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ switch (ordinalConverter.read(from)) {
+ case 1: return ScrollBy.Line;
+ case 2: return ScrollBy.Page;
+ default: throw new UniffiInternalError.UnexpectedEnumCase();
+ }
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ switch (value) {
+ case ScrollBy.Line: return ordinalConverter.write(1, into);
+ case ScrollBy.Page: return ordinalConverter.write(2, into);
+ }
+ }
+ allocationSize(value: TypeName): number {
+ return ordinalConverter.allocationSize(0);
+ }
+ }
+ return new FFIConverter();
+})();
+
+export type ScrollInput = {
+ x: number,
+ y: number,
+ direction: ScrollDirection,
+ scope: DesktopScope,
+ /**
+ * Optional session id.
+ */
+ session?: string,
+ by?: ScrollBy,
+ amount?: bigint
+}
+
+/**
+ * Generated factory for {@link ScrollInput} record objects.
+ */
+export const ScrollInput = (() => {
+ const defaults = () => ({
+ });
+ const create = (() => {
+ return uniffiCreateRecord<ScrollInput, ReturnType<typeof defaults>>(defaults);
+ })();
+ return Object.freeze({
+ create,
+ new: create,
+ defaults: () => Object.freeze(defaults()) as Partial<ScrollInput>,
+ });
+})();
+
+const FfiConverterTypeScrollInput = (() => {
+ type TypeName = ScrollInput;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ return {
+ x: FfiConverterFloat64.read(from),
+ y: FfiConverterFloat64.read(from),
+ direction: FfiConverterTypeScrollDirection.read(from),
+ scope: FfiConverterTypeDesktopScope.read(from),
+ session: FfiConverterOptionalString.read(from),
+ by: FfiConverterOptionalTypeScrollBy.read(from),
+ amount: FfiConverterOptionalUInt64.read(from)
+ };
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ FfiConverterFloat64.write(value.x, into);
+ FfiConverterFloat64.write(value.y, into);
+ FfiConverterTypeScrollDirection.write(value.direction, into);
+ FfiConverterTypeDesktopScope.write(value.scope, into);
+ FfiConverterOptionalString.write(value.session, into);
+ FfiConverterOptionalTypeScrollBy.write(value.by, into);
+ FfiConverterOptionalUInt64.write(value.amount, into);
+ }
+ allocationSize(value: TypeName): number {
+ return FfiConverterFloat64.allocationSize(value.x) +
+ FfiConverterFloat64.allocationSize(value.y) +
+ FfiConverterTypeScrollDirection.allocationSize(value.direction) +
+ FfiConverterTypeDesktopScope.allocationSize(value.scope) +
+ FfiConverterOptionalString.allocationSize(value.session) +
+ FfiConverterOptionalTypeScrollBy.allocationSize(value.by) +
+ FfiConverterOptionalUInt64.allocationSize(value.amount);
+
+ }
+ };
+ return new FFIConverter();
+})();
+
+export enum CaptureScope {
+ Auto,
+ Window,
+ Desktop
+}
+
+const FfiConverterTypeCaptureScope = (() => {
+ const ordinalConverter = FfiConverterInt32;
+ type TypeName = CaptureScope;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ switch (ordinalConverter.read(from)) {
+ case 1: return CaptureScope.Auto;
+ case 2: return CaptureScope.Window;
+ case 3: return CaptureScope.Desktop;
+ default: throw new UniffiInternalError.UnexpectedEnumCase();
+ }
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ switch (value) {
+ case CaptureScope.Auto: return ordinalConverter.write(1, into);
+ case CaptureScope.Window: return ordinalConverter.write(2, into);
+ case CaptureScope.Desktop: return ordinalConverter.write(3, into);
+ }
+ }
+ allocationSize(value: TypeName): number {
+ return ordinalConverter.allocationSize(0);
+ }
+ }
+ return new FFIConverter();
+})();
+
+export enum EffectiveScope {
+ Window,
+ Desktop
+}
+
+const FfiConverterTypeEffectiveScope = (() => {
+ const ordinalConverter = FfiConverterInt32;
+ type TypeName = EffectiveScope;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ switch (ordinalConverter.read(from)) {
+ case 1: return EffectiveScope.Window;
+ case 2: return EffectiveScope.Desktop;
+ default: throw new UniffiInternalError.UnexpectedEnumCase();
+ }
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ switch (value) {
+ case EffectiveScope.Window: return ordinalConverter.write(1, into);
+ case EffectiveScope.Desktop: return ordinalConverter.write(2, into);
+ }
+ }
+ allocationSize(value: TypeName): number {
+ return ordinalConverter.allocationSize(0);
+ }
+ }
+ return new FFIConverter();
+})();
+
+/**
+ * Successful structured result shared by session state and escalation tools.
+ */
+export type SessionStateOutput = {
+ session: string,
+ captureScope: CaptureScope,
+ effectiveScope: EffectiveScope,
+ desktopUnlocked: boolean,
+ escalationReason?: EscalationReason,
+ escalationDetail?: string
+}
+
+/**
+ * Generated factory for {@link SessionStateOutput} record objects.
+ */
+export const SessionStateOutput = (() => {
+ const defaults = () => ({
+ });
+ const create = (() => {
+ return uniffiCreateRecord<SessionStateOutput, ReturnType<typeof defaults>>(defaults);
+ })();
+ return Object.freeze({
+ create,
+ new: create,
+ defaults: () => Object.freeze(defaults()) as Partial<SessionStateOutput>,
+ });
+})();
+
+const FfiConverterTypeSessionStateOutput = (() => {
+ type TypeName = SessionStateOutput;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ return {
+ session: FfiConverterString.read(from),
+ captureScope: FfiConverterTypeCaptureScope.read(from),
+ effectiveScope: FfiConverterTypeEffectiveScope.read(from),
+ desktopUnlocked: FfiConverterBool.read(from),
+ escalationReason: FfiConverterOptionalTypeEscalationReason.read(from),
+ escalationDetail: FfiConverterOptionalString.read(from)
+ };
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ FfiConverterString.write(value.session, into);
+ FfiConverterTypeCaptureScope.write(value.captureScope, into);
+ FfiConverterTypeEffectiveScope.write(value.effectiveScope, into);
+ FfiConverterBool.write(value.desktopUnlocked, into);
+ FfiConverterOptionalTypeEscalationReason.write(value.escalationReason, into);
+ FfiConverterOptionalString.write(value.escalationDetail, into);
+ }
+ allocationSize(value: TypeName): number {
+ return FfiConverterString.allocationSize(value.session) +
+ FfiConverterTypeCaptureScope.allocationSize(value.captureScope) +
+ FfiConverterTypeEffectiveScope.allocationSize(value.effectiveScope) +
+ FfiConverterBool.allocationSize(value.desktopUnlocked) +
+ FfiConverterOptionalTypeEscalationReason.allocationSize(value.escalationReason) +
+ FfiConverterOptionalString.allocationSize(value.escalationDetail);
+
+ }
+ };
+ return new FFIConverter();
+})();
+
+export type StartSessionInput = {
+ /**
+ * Stable session id for this run (e.g. "research-run-1").
+ */
+ session: string,
+ /**
+ * Per-session perception/action modality. auto starts window-only and requires explicit escalation before desktop tools; window and desktop are strict. Immutable for the live session.
+ */
+ captureScope?: CaptureScope
+}
+
+/**
+ * Generated factory for {@link StartSessionInput} record objects.
+ */
+export const StartSessionInput = (() => {
+ const defaults = () => ({
+ });
+ const create = (() => {
+ return uniffiCreateRecord<StartSessionInput, ReturnType<typeof defaults>>(defaults);
+ })();
+ return Object.freeze({
+ create,
+ new: create,
+ defaults: () => Object.freeze(defaults()) as Partial<StartSessionInput>,
+ });
+})();
+
+const FfiConverterTypeStartSessionInput = (() => {
+ type TypeName = StartSessionInput;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ return {
+ session: FfiConverterString.read(from),
+ captureScope: FfiConverterOptionalTypeCaptureScope.read(from)
+ };
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ FfiConverterString.write(value.session, into);
+ FfiConverterOptionalTypeCaptureScope.write(value.captureScope, into);
+ }
+ allocationSize(value: TypeName): number {
+ return FfiConverterString.allocationSize(value.session) +
+ FfiConverterOptionalTypeCaptureScope.allocationSize(value.captureScope);
+
+ }
+ };
+ return new FFIConverter();
+})();
+
+/**
+ * Successful structured result returned by `start_session`.
+ */
+export type StartSessionOutput = {
+ state: SessionStateOutput,
+ active: boolean,
+ revived: boolean
+}
+
+/**
+ * Generated factory for {@link StartSessionOutput} record objects.
+ */
+export const StartSessionOutput = (() => {
+ const defaults = () => ({
+ });
+ const create = (() => {
+ return uniffiCreateRecord<StartSessionOutput, ReturnType<typeof defaults>>(defaults);
+ })();
+ return Object.freeze({
+ create,
+ new: create,
+ defaults: () => Object.freeze(defaults()) as Partial<StartSessionOutput>,
+ });
+})();
+
+const FfiConverterTypeStartSessionOutput = (() => {
+ type TypeName = StartSessionOutput;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ return {
+ state: FfiConverterTypeSessionStateOutput.read(from),
+ active: FfiConverterBool.read(from),
+ revived: FfiConverterBool.read(from)
+ };
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ FfiConverterTypeSessionStateOutput.write(value.state, into);
+ FfiConverterBool.write(value.active, into);
+ FfiConverterBool.write(value.revived, into);
+ }
+ allocationSize(value: TypeName): number {
+ return FfiConverterTypeSessionStateOutput.allocationSize(value.state) +
+ FfiConverterBool.allocationSize(value.active) +
+ FfiConverterBool.allocationSize(value.revived);
+
+ }
+ };
+ return new FFIConverter();
+})();
+
+export type TypeTextInput = {
+ text: string,
+ scope: DesktopScope,
+ /**
+ * Optional session id.
+ */
+ session?: string
+}
+
+/**
+ * Generated factory for {@link TypeTextInput} record objects.
+ */
+export const TypeTextInput = (() => {
+ const defaults = () => ({
+ });
+ const create = (() => {
+ return uniffiCreateRecord<TypeTextInput, ReturnType<typeof defaults>>(defaults);
+ })();
+ return Object.freeze({
+ create,
+ new: create,
+ defaults: () => Object.freeze(defaults()) as Partial<TypeTextInput>,
+ });
+})();
+
+const FfiConverterTypeTypeTextInput = (() => {
+ type TypeName = TypeTextInput;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ return {
+ text: FfiConverterString.read(from),
+ scope: FfiConverterTypeDesktopScope.read(from),
+ session: FfiConverterOptionalString.read(from)
+ };
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ FfiConverterString.write(value.text, into);
+ FfiConverterTypeDesktopScope.write(value.scope, into);
+ FfiConverterOptionalString.write(value.session, into);
+ }
+ allocationSize(value: TypeName): number {
+ return FfiConverterString.allocationSize(value.text) +
+ FfiConverterTypeDesktopScope.allocationSize(value.scope) +
+ FfiConverterOptionalString.allocationSize(value.session);
+
+ }
+ };
+ return new FFIConverter();
+})();
+
+export enum Platform {
+ Macos,
+ Windows,
+ Linux
+}
+
+const FfiConverterTypePlatform = (() => {
+ const ordinalConverter = FfiConverterInt32;
+ type TypeName = Platform;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ switch (ordinalConverter.read(from)) {
+ case 1: return Platform.Macos;
+ case 2: return Platform.Windows;
+ case 3: return Platform.Linux;
+ default: throw new UniffiInternalError.UnexpectedEnumCase();
+ }
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ switch (value) {
+ case Platform.Macos: return ordinalConverter.write(1, into);
+ case Platform.Windows: return ordinalConverter.write(2, into);
+ case Platform.Linux: return ordinalConverter.write(3, into);
+ }
+ }
+ allocationSize(value: TypeName): number {
+ return ordinalConverter.allocationSize(0);
+ }
+ }
+ return new FFIConverter();
+})();
+
+// FfiConverter for string | undefined
+const FfiConverterOptionalString = new FfiConverterOptional(FfiConverterString);
+
+// FfiConverter for ClickButton | undefined
+const FfiConverterOptionalTypeClickButton = new FfiConverterOptional(FfiConverterTypeClickButton);
+
+// FfiConverter for number | undefined
+const FfiConverterOptionalUInt32 = new FfiConverterOptional(FfiConverterUInt32);
+
+// FfiConverter for bigint | undefined
+const FfiConverterOptionalUInt64 = new FfiConverterOptional(FfiConverterUInt64);
+
+// FfiConverter for Array<string>
+const FfiConverterSequenceString = new FfiConverterArray(FfiConverterString);
+
+// FfiConverter for Array<string> | undefined
+const FfiConverterOptionalSequenceString = new FfiConverterOptional(FfiConverterSequenceString);
+
+// FfiConverter for ScrollBy | undefined
+const FfiConverterOptionalTypeScrollBy = new FfiConverterOptional(FfiConverterTypeScrollBy);
+
+// FfiConverter for EscalationReason | undefined
+const FfiConverterOptionalTypeEscalationReason = new FfiConverterOptional(FfiConverterTypeEscalationReason);
+
+// FfiConverter for CaptureScope | undefined
+const FfiConverterOptionalTypeCaptureScope = new FfiConverterOptional(FfiConverterTypeCaptureScope);
+
+
+/**
+ * This should be called before anything else.
+ *
+ * It is likely that this is being done for you by the library's `index.ts`.
+ *
+ * It checks versions of uniffi between when the Rust scaffolding was generated
+ * and when the bindings were generated.
+ *
+ * It also initializes the machinery to enable Rust to talk back to Javascript.
+ */
+function uniffiEnsureInitialized() {
+ // Get the bindings contract version from our ComponentInterface
+ const bindingsContractVersion = 30;
+ // Get the scaffolding contract version by calling the into the dylib
+ const scaffoldingContractVersion = nativeModule().ffi_cua_driver_contract_uniffi_contract_version();
+ if (bindingsContractVersion !== scaffoldingContractVersion) {
+ throw new UniffiInternalError.ContractVersionMismatch(scaffoldingContractVersion, bindingsContractVersion);
+ }
+
+ }
+
+export default Object.freeze({
+ initialize: uniffiEnsureInitialized,
+ converters: {
+ FfiConverterTypeCaptureScope,
+ FfiConverterTypeClickButton,
+ FfiConverterTypeClickInput,
+ FfiConverterTypeDesktopScope,
+ FfiConverterTypeDragInput,
+ FfiConverterTypeEffectiveScope,
+ FfiConverterTypeEndSessionInput,
+ FfiConverterTypeEndSessionOutput,
+ FfiConverterTypeEscalateSessionInput,
+ FfiConverterTypeEscalationReason,
+ FfiConverterTypeGetCursorPositionInput,
+ FfiConverterTypeGetDesktopStateInput,
+ FfiConverterTypeGetScreenSizeInput,
+ FfiConverterTypeGetSessionStateInput,
+ FfiConverterTypeHotkeyInput,
+ FfiConverterTypeMoveCursorInput,
+ FfiConverterTypePlatform,
+ FfiConverterTypePressKeyInput,
+ FfiConverterTypeScrollBy,
+ FfiConverterTypeScrollDirection,
+ FfiConverterTypeScrollInput,
+ FfiConverterTypeSessionStateOutput,
+ FfiConverterTypeStartSessionInput,
+ FfiConverterTypeStartSessionOutput,
+ FfiConverterTypeTypeTextInput,
+ }
+});
diff --git a/libs/cua-driver/typescript/src/native/cua_driver_sdk-ffi.ts b/libs/cua-driver/typescript/src/native/cua_driver_sdk-ffi.ts
new file mode 100644
index 0000000000..a1ff45ee01
--- /dev/null
+++ b/libs/cua-driver/typescript/src/native/cua_driver_sdk-ffi.ts
@@ -0,0 +1,609 @@
+// This file was autogenerated by some hot garbage in the `uniffi-bindgen-react-native` crate.
+// Trust me, you don't want to mess with it!
+/* tslint:disable */
+/* eslint-disable */
+// @ts-nocheck
+
+import lib from "@ubjs/node";
+const { UniffiNativeModule, FfiType, resolveLibPath } = lib;
+
+import {
+ type StructuralEquality as UniffiStructuralEquality,
+ type UniffiForeignFuture as RuntimeUniffiForeignFuture,
+ type UniffiRustCallStatus,
+ type UniffiGcObject,
+ type UniffiRustFutureContinuationCallback as RuntimeUniffiRustFutureContinuationCallback,
+ type UniffiResult,
+} from '@ubjs/core';
+
+const DEFINITIONS = {
+ symbols: {
+ rustbuffer_alloc: "ffi_cua_driver_sdk_rustbuffer_alloc",
+ rustbuffer_free: "ffi_cua_driver_sdk_rustbuffer_free",
+ rustbuffer_from_bytes: "ffi_cua_driver_sdk_rustbuffer_from_bytes",
+ },
+ functions: {
+ "ffi_cua_driver_sdk_rust_future_poll_u8": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_cancel_u8": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_complete_u8": {
+ args: [FfiType.Handle],
+ ret: FfiType.UInt8,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_sdk_rust_future_free_u8": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_poll_i8": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_cancel_i8": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_complete_i8": {
+ args: [FfiType.Handle],
+ ret: FfiType.Int8,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_sdk_rust_future_free_i8": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_poll_u16": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_cancel_u16": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_complete_u16": {
+ args: [FfiType.Handle],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_sdk_rust_future_free_u16": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_poll_i16": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_cancel_i16": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_complete_i16": {
+ args: [FfiType.Handle],
+ ret: FfiType.Int16,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_sdk_rust_future_free_i16": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_poll_u32": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_cancel_u32": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_complete_u32": {
+ args: [FfiType.Handle],
+ ret: FfiType.UInt32,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_sdk_rust_future_free_u32": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_poll_i32": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_cancel_i32": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_complete_i32": {
+ args: [FfiType.Handle],
+ ret: FfiType.Int32,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_sdk_rust_future_free_i32": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_poll_u64": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_cancel_u64": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_complete_u64": {
+ args: [FfiType.Handle],
+ ret: FfiType.Handle,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_sdk_rust_future_free_u64": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_poll_i64": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_cancel_i64": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_complete_i64": {
+ args: [FfiType.Handle],
+ ret: FfiType.Int64,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_sdk_rust_future_free_i64": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_poll_f32": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_cancel_f32": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_complete_f32": {
+ args: [FfiType.Handle],
+ ret: FfiType.Float32,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_sdk_rust_future_free_f32": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_poll_f64": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_cancel_f64": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_complete_f64": {
+ args: [FfiType.Handle],
+ ret: FfiType.Float64,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_sdk_rust_future_free_f64": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_poll_rust_buffer": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_cancel_rust_buffer": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_complete_rust_buffer": {
+ args: [FfiType.Handle],
+ ret: FfiType.RustBuffer,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_sdk_rust_future_free_rust_buffer": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_poll_void": {
+ args: [FfiType.Handle, FfiType.Callback("RustFutureContinuationCallback"), FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_cancel_void": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ffi_cua_driver_sdk_rust_future_complete_void": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_sdk_rust_future_free_void": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "uniffi_cua_driver_sdk_fn_clone_cuadriver": {
+ args: [FfiType.Handle],
+ ret: FfiType.Handle,
+ hasRustCallStatus: true,
+ },
+ "uniffi_cua_driver_sdk_fn_free_cuadriver": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: true,
+ },
+ "uniffi_cua_driver_sdk_fn_constructor_cuadriver_connect": {
+ args: [FfiType.RustBuffer],
+ ret: FfiType.Handle,
+ hasRustCallStatus: true,
+ },
+ "uniffi_cua_driver_sdk_fn_method_cuadriver_call_tool": {
+ args: [FfiType.Handle, FfiType.RustBuffer, FfiType.RustBuffer],
+ ret: FfiType.RustBuffer,
+ hasRustCallStatus: true,
+ },
+ "uniffi_cua_driver_sdk_fn_method_cuadriver_click": {
+ args: [FfiType.Handle, FfiType.RustBuffer],
+ ret: FfiType.RustBuffer,
+ hasRustCallStatus: true,
+ },
+ "uniffi_cua_driver_sdk_fn_method_cuadriver_drag": {
+ args: [FfiType.Handle, FfiType.RustBuffer],
+ ret: FfiType.RustBuffer,
+ hasRustCallStatus: true,
+ },
+ "uniffi_cua_driver_sdk_fn_method_cuadriver_end_session": {
+ args: [FfiType.Handle, FfiType.RustBuffer],
+ ret: FfiType.RustBuffer,
+ hasRustCallStatus: true,
+ },
+ "uniffi_cua_driver_sdk_fn_method_cuadriver_escalate_session": {
+ args: [FfiType.Handle, FfiType.RustBuffer],
+ ret: FfiType.RustBuffer,
+ hasRustCallStatus: true,
+ },
+ "uniffi_cua_driver_sdk_fn_method_cuadriver_get_cursor_position": {
+ args: [FfiType.Handle, FfiType.RustBuffer],
+ ret: FfiType.RustBuffer,
+ hasRustCallStatus: true,
+ },
+ "uniffi_cua_driver_sdk_fn_method_cuadriver_get_desktop_state": {
+ args: [FfiType.Handle, FfiType.RustBuffer],
+ ret: FfiType.RustBuffer,
+ hasRustCallStatus: true,
+ },
+ "uniffi_cua_driver_sdk_fn_method_cuadriver_get_screen_size": {
+ args: [FfiType.Handle, FfiType.RustBuffer],
+ ret: FfiType.RustBuffer,
+ hasRustCallStatus: true,
+ },
+ "uniffi_cua_driver_sdk_fn_method_cuadriver_get_session_state": {
+ args: [FfiType.Handle, FfiType.RustBuffer],
+ ret: FfiType.RustBuffer,
+ hasRustCallStatus: true,
+ },
+ "uniffi_cua_driver_sdk_fn_method_cuadriver_hotkey": {
+ args: [FfiType.Handle, FfiType.RustBuffer],
+ ret: FfiType.RustBuffer,
+ hasRustCallStatus: true,
+ },
+ "uniffi_cua_driver_sdk_fn_method_cuadriver_is_available": {
+ args: [FfiType.Handle],
+ ret: FfiType.Int8,
+ hasRustCallStatus: true,
+ },
+ "uniffi_cua_driver_sdk_fn_method_cuadriver_list_tools_json": {
+ args: [FfiType.Handle],
+ ret: FfiType.RustBuffer,
+ hasRustCallStatus: true,
+ },
+ "uniffi_cua_driver_sdk_fn_method_cuadriver_move_cursor": {
+ args: [FfiType.Handle, FfiType.RustBuffer],
+ ret: FfiType.RustBuffer,
+ hasRustCallStatus: true,
+ },
+ "uniffi_cua_driver_sdk_fn_method_cuadriver_press_key": {
+ args: [FfiType.Handle, FfiType.RustBuffer],
+ ret: FfiType.RustBuffer,
+ hasRustCallStatus: true,
+ },
+ "uniffi_cua_driver_sdk_fn_method_cuadriver_scroll": {
+ args: [FfiType.Handle, FfiType.RustBuffer],
+ ret: FfiType.RustBuffer,
+ hasRustCallStatus: true,
+ },
+ "uniffi_cua_driver_sdk_fn_method_cuadriver_socket_path": {
+ args: [FfiType.Handle],
+ ret: FfiType.RustBuffer,
+ hasRustCallStatus: true,
+ },
+ "uniffi_cua_driver_sdk_fn_method_cuadriver_start_session": {
+ args: [FfiType.Handle, FfiType.RustBuffer],
+ ret: FfiType.RustBuffer,
+ hasRustCallStatus: true,
+ },
+ "uniffi_cua_driver_sdk_fn_method_cuadriver_type_text": {
+ args: [FfiType.Handle, FfiType.RustBuffer],
+ ret: FfiType.RustBuffer,
+ hasRustCallStatus: true,
+ },
+ "ffi_cua_driver_sdk_uniffi_contract_version": {
+ args: [],
+ ret: FfiType.UInt32,
+ hasRustCallStatus: false,
+ },
+ "uniffi_cua_driver_sdk_checksum_constructor_cuadriver_connect": {
+ args: [],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: false,
+ },
+ "uniffi_cua_driver_sdk_checksum_method_cuadriver_call_tool": {
+ args: [],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: false,
+ },
+ "uniffi_cua_driver_sdk_checksum_method_cuadriver_click": {
+ args: [],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: false,
+ },
+ "uniffi_cua_driver_sdk_checksum_method_cuadriver_drag": {
+ args: [],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: false,
+ },
+ "uniffi_cua_driver_sdk_checksum_method_cuadriver_end_session": {
+ args: [],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: false,
+ },
+ "uniffi_cua_driver_sdk_checksum_method_cuadriver_escalate_session": {
+ args: [],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: false,
+ },
+ "uniffi_cua_driver_sdk_checksum_method_cuadriver_get_cursor_position": {
+ args: [],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: false,
+ },
+ "uniffi_cua_driver_sdk_checksum_method_cuadriver_get_desktop_state": {
+ args: [],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: false,
+ },
+ "uniffi_cua_driver_sdk_checksum_method_cuadriver_get_screen_size": {
+ args: [],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: false,
+ },
+ "uniffi_cua_driver_sdk_checksum_method_cuadriver_get_session_state": {
+ args: [],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: false,
+ },
+ "uniffi_cua_driver_sdk_checksum_method_cuadriver_hotkey": {
+ args: [],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: false,
+ },
+ "uniffi_cua_driver_sdk_checksum_method_cuadriver_is_available": {
+ args: [],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: false,
+ },
+ "uniffi_cua_driver_sdk_checksum_method_cuadriver_list_tools_json": {
+ args: [],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: false,
+ },
+ "uniffi_cua_driver_sdk_checksum_method_cuadriver_move_cursor": {
+ args: [],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: false,
+ },
+ "uniffi_cua_driver_sdk_checksum_method_cuadriver_press_key": {
+ args: [],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: false,
+ },
+ "uniffi_cua_driver_sdk_checksum_method_cuadriver_scroll": {
+ args: [],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: false,
+ },
+ "uniffi_cua_driver_sdk_checksum_method_cuadriver_socket_path": {
+ args: [],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: false,
+ },
+ "uniffi_cua_driver_sdk_checksum_method_cuadriver_start_session": {
+ args: [],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: false,
+ },
+ "uniffi_cua_driver_sdk_checksum_method_cuadriver_type_text": {
+ args: [],
+ ret: FfiType.UInt16,
+ hasRustCallStatus: false,
+ },
+ },
+ callbacks: {
+ "RustFutureContinuationCallback": {
+ args: [FfiType.Handle, FfiType.Int8],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ "ForeignFutureDroppedCallback": {
+ args: [FfiType.Handle],
+ ret: FfiType.Void,
+ hasRustCallStatus: false,
+ },
+ },
+ structs: {
+ "ForeignFutureDroppedCallbackStruct": [
+ { name: "handle", type: FfiType.Handle },
+ { name: "free", type: FfiType.Callback("ForeignFutureDroppedCallback") },
+ ],
+ },
+} as const;
+
+interface NativeModuleInterface {
+ ffi_cua_driver_sdk_rust_future_poll_u8(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_sdk_rust_future_cancel_u8(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_complete_u8(handle: bigint, uniffi_out_err: UniffiRustCallStatus): number;
+ ffi_cua_driver_sdk_rust_future_free_u8(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_poll_i8(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_sdk_rust_future_cancel_i8(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_complete_i8(handle: bigint, uniffi_out_err: UniffiRustCallStatus): number;
+ ffi_cua_driver_sdk_rust_future_free_i8(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_poll_u16(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_sdk_rust_future_cancel_u16(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_complete_u16(handle: bigint, uniffi_out_err: UniffiRustCallStatus): number;
+ ffi_cua_driver_sdk_rust_future_free_u16(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_poll_i16(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_sdk_rust_future_cancel_i16(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_complete_i16(handle: bigint, uniffi_out_err: UniffiRustCallStatus): number;
+ ffi_cua_driver_sdk_rust_future_free_i16(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_poll_u32(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_sdk_rust_future_cancel_u32(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_complete_u32(handle: bigint, uniffi_out_err: UniffiRustCallStatus): number;
+ ffi_cua_driver_sdk_rust_future_free_u32(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_poll_i32(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_sdk_rust_future_cancel_i32(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_complete_i32(handle: bigint, uniffi_out_err: UniffiRustCallStatus): number;
+ ffi_cua_driver_sdk_rust_future_free_i32(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_poll_u64(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_sdk_rust_future_cancel_u64(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_complete_u64(handle: bigint, uniffi_out_err: UniffiRustCallStatus): bigint;
+ ffi_cua_driver_sdk_rust_future_free_u64(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_poll_i64(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_sdk_rust_future_cancel_i64(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_complete_i64(handle: bigint, uniffi_out_err: UniffiRustCallStatus): bigint;
+ ffi_cua_driver_sdk_rust_future_free_i64(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_poll_f32(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_sdk_rust_future_cancel_f32(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_complete_f32(handle: bigint, uniffi_out_err: UniffiRustCallStatus): number;
+ ffi_cua_driver_sdk_rust_future_free_f32(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_poll_f64(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_sdk_rust_future_cancel_f64(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_complete_f64(handle: bigint, uniffi_out_err: UniffiRustCallStatus): number;
+ ffi_cua_driver_sdk_rust_future_free_f64(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_poll_rust_buffer(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_sdk_rust_future_cancel_rust_buffer(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_complete_rust_buffer(handle: bigint, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
+ ffi_cua_driver_sdk_rust_future_free_rust_buffer(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_poll_void(handle: bigint, callback: UniffiRustFutureContinuationCallback, callbackData: bigint): void;
+ ffi_cua_driver_sdk_rust_future_cancel_void(handle: bigint): void;
+ ffi_cua_driver_sdk_rust_future_complete_void(handle: bigint, uniffi_out_err: UniffiRustCallStatus): void;
+ ffi_cua_driver_sdk_rust_future_free_void(handle: bigint): void;
+ uniffi_cua_driver_sdk_fn_clone_cuadriver(ptr: bigint, uniffi_out_err: UniffiRustCallStatus): bigint;
+ uniffi_cua_driver_sdk_fn_free_cuadriver(ptr: bigint, uniffi_out_err: UniffiRustCallStatus): void;
+ uniffi_cua_driver_sdk_fn_constructor_cuadriver_connect(socketPath: Uint8Array, uniffi_out_err: UniffiRustCallStatus): bigint;
+ uniffi_cua_driver_sdk_fn_method_cuadriver_call_tool(uniffiSelf: bigint, name: Uint8Array, argumentsJson: Uint8Array, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
+ uniffi_cua_driver_sdk_fn_method_cuadriver_click(uniffiSelf: bigint, input: Uint8Array, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
+ uniffi_cua_driver_sdk_fn_method_cuadriver_drag(uniffiSelf: bigint, input: Uint8Array, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
+ uniffi_cua_driver_sdk_fn_method_cuadriver_end_session(uniffiSelf: bigint, input: Uint8Array, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
+ uniffi_cua_driver_sdk_fn_method_cuadriver_escalate_session(uniffiSelf: bigint, input: Uint8Array, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
+ uniffi_cua_driver_sdk_fn_method_cuadriver_get_cursor_position(uniffiSelf: bigint, input: Uint8Array, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
+ uniffi_cua_driver_sdk_fn_method_cuadriver_get_desktop_state(uniffiSelf: bigint, input: Uint8Array, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
+ uniffi_cua_driver_sdk_fn_method_cuadriver_get_screen_size(uniffiSelf: bigint, input: Uint8Array, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
+ uniffi_cua_driver_sdk_fn_method_cuadriver_get_session_state(uniffiSelf: bigint, input: Uint8Array, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
+ uniffi_cua_driver_sdk_fn_method_cuadriver_hotkey(uniffiSelf: bigint, input: Uint8Array, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
+ uniffi_cua_driver_sdk_fn_method_cuadriver_is_available(uniffiSelf: bigint, uniffi_out_err: UniffiRustCallStatus): number;
+ uniffi_cua_driver_sdk_fn_method_cuadriver_list_tools_json(uniffiSelf: bigint, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
+ uniffi_cua_driver_sdk_fn_method_cuadriver_move_cursor(uniffiSelf: bigint, input: Uint8Array, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
+ uniffi_cua_driver_sdk_fn_method_cuadriver_press_key(uniffiSelf: bigint, input: Uint8Array, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
+ uniffi_cua_driver_sdk_fn_method_cuadriver_scroll(uniffiSelf: bigint, input: Uint8Array, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
+ uniffi_cua_driver_sdk_fn_method_cuadriver_socket_path(uniffiSelf: bigint, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
+ uniffi_cua_driver_sdk_fn_method_cuadriver_start_session(uniffiSelf: bigint, input: Uint8Array, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
+ uniffi_cua_driver_sdk_fn_method_cuadriver_type_text(uniffiSelf: bigint, input: Uint8Array, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
+ ffi_cua_driver_sdk_uniffi_contract_version(): number;
+ uniffi_cua_driver_sdk_checksum_constructor_cuadriver_connect(): number;
+ uniffi_cua_driver_sdk_checksum_method_cuadriver_call_tool(): number;
+ uniffi_cua_driver_sdk_checksum_method_cuadriver_click(): number;
+ uniffi_cua_driver_sdk_checksum_method_cuadriver_drag(): number;
+ uniffi_cua_driver_sdk_checksum_method_cuadriver_end_session(): number;
+ uniffi_cua_driver_sdk_checksum_method_cuadriver_escalate_session(): number;
+ uniffi_cua_driver_sdk_checksum_method_cuadriver_get_cursor_position(): number;
+ uniffi_cua_driver_sdk_checksum_method_cuadriver_get_desktop_state(): number;
+ uniffi_cua_driver_sdk_checksum_method_cuadriver_get_screen_size(): number;
+ uniffi_cua_driver_sdk_checksum_method_cuadriver_get_session_state(): number;
+ uniffi_cua_driver_sdk_checksum_method_cuadriver_hotkey(): number;
+ uniffi_cua_driver_sdk_checksum_method_cuadriver_is_available(): number;
+ uniffi_cua_driver_sdk_checksum_method_cuadriver_list_tools_json(): number;
+ uniffi_cua_driver_sdk_checksum_method_cuadriver_move_cursor(): number;
+ uniffi_cua_driver_sdk_checksum_method_cuadriver_press_key(): number;
+ uniffi_cua_driver_sdk_checksum_method_cuadriver_scroll(): number;
+ uniffi_cua_driver_sdk_checksum_method_cuadriver_socket_path(): number;
+ uniffi_cua_driver_sdk_checksum_method_cuadriver_start_session(): number;
+ uniffi_cua_driver_sdk_checksum_method_cuadriver_type_text(): number;
+ // Codegen call sites use these via `nativeModule().rustbuffer_alloc(...)`
+ // and `nativeModule().rustbuffer_free(...)`. The runtime's registered
+ // module exposes them as method properties.
+ rustbuffer_alloc(n: number): Uint8Array;
+ rustbuffer_free(view: Uint8Array): void;
+}
+
+let _nativeModule: NativeModuleInterface | undefined;
+const getter: () => NativeModuleInterface = () => {
+ if (!_nativeModule) {
+ const libPath = resolveLibPath({
+ crateName: "cua_driver_sdk",
+ callerUrl: import.meta.url,
+ });
+ const mod_ = UniffiNativeModule.open(libPath);
+ _nativeModule = mod_.register(DEFINITIONS) as unknown as NativeModuleInterface;
+ }
+ return _nativeModule;
+};
+export default getter;
+
+// Structs and function types for calling back into Typescript from Rust.
+export type UniffiRustFutureContinuationCallback = (data: bigint, pollResult: number) => void;
+export type UniffiForeignFutureDroppedCallback = (handle: bigint) => void;
+export type UniffiForeignFutureDroppedCallbackStruct = {
+ handle: bigint;
+ free: UniffiForeignFutureDroppedCallback;
+};
diff --git a/libs/cua-driver/typescript/src/native/cua_driver_sdk.ts b/libs/cua-driver/typescript/src/native/cua_driver_sdk.ts
new file mode 100644
index 0000000000..5ad8b0135b
--- /dev/null
+++ b/libs/cua-driver/typescript/src/native/cua_driver_sdk.ts
@@ -0,0 +1,1058 @@
+// This file was autogenerated by some hot garbage in the `uniffi-bindgen-react-native` crate.
+// Trust me, you don't want to mess with it!
+/* tslint:disable */
+/* eslint-disable */
+// @ts-nocheck
+import nativeModule from "./cua_driver_sdk-ffi.js";
+import { type UniffiRustFutureContinuationCallback, type UniffiForeignFutureDroppedCallback, type UniffiForeignFutureDroppedCallbackStruct,
+} from "./cua_driver_sdk-ffi.js";
+import { type ClickInput, type DragInput, type EndSessionInput, type EndSessionOutput, type EscalateSessionInput, type GetCursorPositionInput, type GetDesktopStateInput, type GetScreenSizeInput, type GetSessionStateInput, type HotkeyInput, type MoveCursorInput, type PressKeyInput, type ScrollInput, type SessionStateOutput, type StartSessionInput, type StartSessionOutput, type TypeTextInput,
+} from "./cua_driver_contract.js";
+import { type FfiConverter, type UniffiByteArray, type UniffiGcObject, type UniffiHandle, type UniffiObjectFactory, AbstractFfiConverterByteArray, FfiConverterArray, FfiConverterBool, FfiConverterInt32, FfiConverterObject, FfiConverterOptional, FfiConverterUInt8, RustBuffer, UniffiAbstractObject, UniffiError, UniffiInternalError, UniffiRustCaller, destructorGuardSymbol, pointerLiteralSymbol, uniffiCreateFfiConverterString, uniffiCreateRecord, uniffiTypeNameSymbol, variantOrdinalSymbol,
+} from "@ubjs/core";
+import uniffiCuaDriverContractModule from "./cua_driver_contract.js";
+const { FfiConverterTypeClickInput, FfiConverterTypeDragInput, FfiConverterTypeEndSessionInput, FfiConverterTypeEndSessionOutput, FfiConverterTypeEscalateSessionInput, FfiConverterTypeGetCursorPositionInput, FfiConverterTypeGetDesktopStateInput, FfiConverterTypeGetScreenSizeInput, FfiConverterTypeGetSessionStateInput, FfiConverterTypeHotkeyInput, FfiConverterTypeMoveCursorInput, FfiConverterTypePressKeyInput, FfiConverterTypeScrollInput, FfiConverterTypeSessionStateOutput, FfiConverterTypeStartSessionInput, FfiConverterTypeStartSessionOutput, FfiConverterTypeTypeTextInput } = uniffiCuaDriverContractModule.converters;
+const uniffiCaller = new UniffiRustCaller(() => ({ code: 0 }));
+
+const uniffiIsDebug =
+ // @ts-ignore -- The process global might not be defined
+ typeof process !== "object" ||
+ // @ts-ignore -- The process global might not be defined
+ process?.env?.NODE_ENV !== "production" ||
+ false;
+
+// Public interface members begin here.
+
+const stringConverter = (() => {
+ const encoder = new TextEncoder();
+ const decoder = new TextDecoder();
+ return {
+ stringToBytes: (s: string) => encoder.encode(s),
+ bytesToString: (ab: UniffiByteArray) => decoder.decode(ab),
+ stringByteLength: (s: string) => encoder.encode(s).byteLength,
+ writeStringIntoBuffer: (s: string, buf: any, offset: number): number => {
+ const view = new Uint8Array(
+ buf.arrayBuffer,
+ offset,
+ buf.arrayBuffer.byteLength - offset,
+ );
+ return encoder.encodeInto(s, view).written;
+ },
+ readStringFromBuffer: (buf: any, offset: number, length: number): string =>
+ decoder.decode(new Uint8Array(buf.arrayBuffer, offset, length)),
+ };
+})();
+const FfiConverterString = uniffiCreateFfiConverterString(stringConverter);
+
+export type ImageContent = {
+ mimeType: string,
+ dataBase64: string
+}
+
+/**
+ * Generated factory for {@link ImageContent} record objects.
+ */
+export const ImageContent = (() => {
+ const defaults = () => ({
+ });
+ const create = (() => {
+ return uniffiCreateRecord<ImageContent, ReturnType<typeof defaults>>(defaults);
+ })();
+ return Object.freeze({
+ create,
+ new: create,
+ defaults: () => Object.freeze(defaults()) as Partial<ImageContent>,
+ });
+})();
+
+const FfiConverterTypeImageContent = (() => {
+ type TypeName = ImageContent;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ return {
+ mimeType: FfiConverterString.read(from),
+ dataBase64: FfiConverterString.read(from)
+ };
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ FfiConverterString.write(value.mimeType, into);
+ FfiConverterString.write(value.dataBase64, into);
+ }
+ allocationSize(value: TypeName): number {
+ return FfiConverterString.allocationSize(value.mimeType) +
+ FfiConverterString.allocationSize(value.dataBase64);
+
+ }
+ };
+ return new FFIConverter();
+})();
+
+/**
+ * Transport-neutral result envelope used for open-ended tool calls and
+ * desktop tools whose platform extensions are intentionally preserved as JSON.
+ */
+export type ToolResult = {
+ text: string,
+ images: Array<ImageContent>,
+ structuredJson?: string,
+ isError: boolean,
+ errorCode?: string,
+ verified?: boolean,
+ degraded: boolean,
+ rawJson: string
+}
+
+/**
+ * Generated factory for {@link ToolResult} record objects.
+ */
+export const ToolResult = (() => {
+ const defaults = () => ({
+ });
+ const create = (() => {
+ return uniffiCreateRecord<ToolResult, ReturnType<typeof defaults>>(defaults);
+ })();
+ return Object.freeze({
+ create,
+ new: create,
+ defaults: () => Object.freeze(defaults()) as Partial<ToolResult>,
+ });
+})();
+
+const FfiConverterTypeToolResult = (() => {
+ type TypeName = ToolResult;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ return {
+ text: FfiConverterString.read(from),
+ images: FfiConverterSequenceTypeImageContent.read(from),
+ structuredJson: FfiConverterOptionalString.read(from),
+ isError: FfiConverterBool.read(from),
+ errorCode: FfiConverterOptionalString.read(from),
+ verified: FfiConverterOptionalBoolean.read(from),
+ degraded: FfiConverterBool.read(from),
+ rawJson: FfiConverterString.read(from)
+ };
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ FfiConverterString.write(value.text, into);
+ FfiConverterSequenceTypeImageContent.write(value.images, into);
+ FfiConverterOptionalString.write(value.structuredJson, into);
+ FfiConverterBool.write(value.isError, into);
+ FfiConverterOptionalString.write(value.errorCode, into);
+ FfiConverterOptionalBoolean.write(value.verified, into);
+ FfiConverterBool.write(value.degraded, into);
+ FfiConverterString.write(value.rawJson, into);
+ }
+ allocationSize(value: TypeName): number {
+ return FfiConverterString.allocationSize(value.text) +
+ FfiConverterSequenceTypeImageContent.allocationSize(value.images) +
+ FfiConverterOptionalString.allocationSize(value.structuredJson) +
+ FfiConverterBool.allocationSize(value.isError) +
+ FfiConverterOptionalString.allocationSize(value.errorCode) +
+ FfiConverterOptionalBoolean.allocationSize(value.verified) +
+ FfiConverterBool.allocationSize(value.degraded) +
+ FfiConverterString.allocationSize(value.rawJson);
+
+ }
+ };
+ return new FFIConverter();
+})();
+
+
+// Error type: DriverError
+export enum DriverError_Tags {
+ Configuration = "Configuration",
+ InvalidArguments = "InvalidArguments",
+ Transport = "Transport",
+ Protocol = "Protocol",
+ Tool = "Tool"
+}
+export const DriverError = (() => {
+
+ type Configuration__interface = {
+ tag: DriverError_Tags.Configuration;
+ inner:
+Readonly<{reason: string}>
+ };
+ class Configuration_ extends UniffiError implements Configuration__interface {
+ /**
+ * @private
+ * This field is private and should not be used, use `tag` instead.
+ */
+ readonly [uniffiTypeNameSymbol] = "DriverError";
+ readonly tag = DriverError_Tags.Configuration;
+ readonly inner:
+Readonly<{reason: string}>;
+ constructor(
+inner: {reason: string }) {
+ super("DriverError", "Configuration");
+
+ this.inner = Object.freeze(inner);
+ }
+ static new(
+inner: {reason: string }): Configuration_ {
+ return new Configuration_(inner);
+ }
+
+ static instanceOf(obj: any): obj is Configuration_ {
+ return obj.tag === DriverError_Tags.Configuration;
+ }
+ static hasInner(obj: any): obj is Configuration_ {
+ return Configuration_.instanceOf(obj);
+ }
+
+ static getInner(obj: Configuration_):
+Readonly<{reason: string}> {
+ return obj.inner;
+ }
+
+ }
+
+ type InvalidArguments__interface = {
+ tag: DriverError_Tags.InvalidArguments;
+ inner:
+Readonly<{tool: string; reason: string}>
+ };
+ class InvalidArguments_ extends UniffiError implements InvalidArguments__interface {
+ /**
+ * @private
+ * This field is private and should not be used, use `tag` instead.
+ */
+ readonly [uniffiTypeNameSymbol] = "DriverError";
+ readonly tag = DriverError_Tags.InvalidArguments;
+ readonly inner:
+Readonly<{tool: string; reason: string}>;
+ constructor(
+inner: {tool: string; reason: string }) {
+ super("DriverError", "InvalidArguments");
+
+ this.inner = Object.freeze(inner);
+ }
+ static new(
+inner: {tool: string; reason: string }): InvalidArguments_ {
+ return new InvalidArguments_(inner);
+ }
+
+ static instanceOf(obj: any): obj is InvalidArguments_ {
+ return obj.tag === DriverError_Tags.InvalidArguments;
+ }
+ static hasInner(obj: any): obj is InvalidArguments_ {
+ return InvalidArguments_.instanceOf(obj);
+ }
+
+ static getInner(obj: InvalidArguments_):
+Readonly<{tool: string; reason: string}> {
+ return obj.inner;
+ }
+
+ }
+
+ type Transport__interface = {
+ tag: DriverError_Tags.Transport;
+ inner:
+Readonly<{socketPath: string; reason: string}>
+ };
+ class Transport_ extends UniffiError implements Transport__interface {
+ /**
+ * @private
+ * This field is private and should not be used, use `tag` instead.
+ */
+ readonly [uniffiTypeNameSymbol] = "DriverError";
+ readonly tag = DriverError_Tags.Transport;
+ readonly inner:
+Readonly<{socketPath: string; reason: string}>;
+ constructor(
+inner: {socketPath: string; reason: string }) {
+ super("DriverError", "Transport");
+
+ this.inner = Object.freeze(inner);
+ }
+ static new(
+inner: {socketPath: string; reason: string }): Transport_ {
+ return new Transport_(inner);
+ }
+
+ static instanceOf(obj: any): obj is Transport_ {
+ return obj.tag === DriverError_Tags.Transport;
+ }
+ static hasInner(obj: any): obj is Transport_ {
+ return Transport_.instanceOf(obj);
+ }
+
+ static getInner(obj: Transport_):
+Readonly<{socketPath: string; reason: string}> {
+ return obj.inner;
+ }
+
+ }
+
+ type Protocol__interface = {
+ tag: DriverError_Tags.Protocol;
+ inner:
+Readonly<{reason: string}>
+ };
+ class Protocol_ extends UniffiError implements Protocol__interface {
+ /**
+ * @private
+ * This field is private and should not be used, use `tag` instead.
+ */
+ readonly [uniffiTypeNameSymbol] = "DriverError";
+ readonly tag = DriverError_Tags.Protocol;
+ readonly inner:
+Readonly<{reason: string}>;
+ constructor(
+inner: {reason: string }) {
+ super("DriverError", "Protocol");
+
+ this.inner = Object.freeze(inner);
+ }
+ static new(
+inner: {reason: string }): Protocol_ {
+ return new Protocol_(inner);
+ }
+
+ static instanceOf(obj: any): obj is Protocol_ {
+ return obj.tag === DriverError_Tags.Protocol;
+ }
+ static hasInner(obj: any): obj is Protocol_ {
+ return Protocol_.instanceOf(obj);
+ }
+
+ static getInner(obj: Protocol_):
+Readonly<{reason: string}> {
+ return obj.inner;
+ }
+
+ }
+
+ type Tool__interface = {
+ tag: DriverError_Tags.Tool;
+ inner:
+Readonly<{tool: string; message: string; errorCode: string}>
+ };
+ class Tool_ extends UniffiError implements Tool__interface {
+ /**
+ * @private
+ * This field is private and should not be used, use `tag` instead.
+ */
+ readonly [uniffiTypeNameSymbol] = "DriverError";
+ readonly tag = DriverError_Tags.Tool;
+ readonly inner:
+Readonly<{tool: string; message: string; errorCode: string}>;
+ constructor(
+inner: {tool: string; message: string; errorCode: string }) {
+ super("DriverError", "Tool");
+
+ this.inner = Object.freeze(inner);
+ }
+ static new(
+inner: {tool: string; message: string; errorCode: string }): Tool_ {
+ return new Tool_(inner);
+ }
+
+ static instanceOf(obj: any): obj is Tool_ {
+ return obj.tag === DriverError_Tags.Tool;
+ }
+ static hasInner(obj: any): obj is Tool_ {
+ return Tool_.instanceOf(obj);
+ }
+
+ static getInner(obj: Tool_):
+Readonly<{tool: string; message: string; errorCode: string}> {
+ return obj.inner;
+ }
+
+ }
+
+ function instanceOf(obj: any): obj is DriverError {
+ return obj[uniffiTypeNameSymbol] === "DriverError";
+ }
+
+ return Object.freeze({
+ instanceOf,
+ Configuration: Configuration_,
+ InvalidArguments: InvalidArguments_,
+ Transport: Transport_,
+ Protocol: Protocol_,
+ Tool: Tool_
+ });
+
+})();
+export type DriverError = InstanceType<
+ typeof DriverError['Configuration' | 'InvalidArguments' | 'Transport' | 'Protocol' | 'Tool']
+>;
+
+// FfiConverter for enum DriverError
+const FfiConverterTypeDriverError = (() => {
+ const ordinalConverter = FfiConverterInt32;
+ type TypeName = DriverError;
+ class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
+ read(from: RustBuffer): TypeName {
+ switch (ordinalConverter.read(from)) {
+ case 1: return new DriverError.Configuration({reason: FfiConverterString.read(from) });
+ case 2: return new DriverError.InvalidArguments({tool: FfiConverterString.read(from), reason: FfiConverterString.read(from) });
+ case 3: return new DriverError.Transport({socketPath: FfiConverterString.read(from), reason: FfiConverterString.read(from) });
+ case 4: return new DriverError.Protocol({reason: FfiConverterString.read(from) });
+ case 5: return new DriverError.Tool({tool: FfiConverterString.read(from), message: FfiConverterString.read(from), errorCode: FfiConverterString.read(from) });
+ default: throw new UniffiInternalError.UnexpectedEnumCase();
+ }
+ }
+ write(value: TypeName, into: RustBuffer): void {
+ switch (value.tag) {
+ case DriverError_Tags.Configuration: {
+ ordinalConverter.write(1, into);
+ const inner = value.inner;
+ FfiConverterString.write(inner.reason, into);
+ return;
+ }
+ case DriverError_Tags.InvalidArguments: {
+ ordinalConverter.write(2, into);
+ const inner = value.inner;
+ FfiConverterString.write(inner.tool, into);
+ FfiConverterString.write(inner.reason, into);
+ return;
+ }
+ case DriverError_Tags.Transport: {
+ ordinalConverter.write(3, into);
+ const inner = value.inner;
+ FfiConverterString.write(inner.socketPath, into);
+ FfiConverterString.write(inner.reason, into);
+ return;
+ }
+ case DriverError_Tags.Protocol: {
+ ordinalConverter.write(4, into);
+ const inner = value.inner;
+ FfiConverterString.write(inner.reason, into);
+ return;
+ }
+ case DriverError_Tags.Tool: {
+ ordinalConverter.write(5, into);
+ const inner = value.inner;
+ FfiConverterString.write(inner.tool, into);
+ FfiConverterString.write(inner.message, into);
+ FfiConverterString.write(inner.errorCode, into);
+ return;
+ }
+ default:
+ // Throwing from here means that DriverError_Tags hasn't matched an ordinal.
+ throw new UniffiInternalError.UnexpectedEnumCase();
+ }
+ }
+ allocationSize(value: TypeName): number {
+ switch (value.tag) {
+ case DriverError_Tags.Configuration: {
+ const inner = value.inner;
+ let size = ordinalConverter.allocationSize(1);
+ size += FfiConverterString.allocationSize(inner.reason);
+ return size;
+ }
+ case DriverError_Tags.InvalidArguments: {
+ const inner = value.inner;
+ let size = ordinalConverter.allocationSize(2);
+ size += FfiConverterString.allocationSize(inner.tool);
+ size += FfiConverterString.allocationSize(inner.reason);
+ return size;
+ }
+ case DriverError_Tags.Transport: {
+ const inner = value.inner;
+ let size = ordinalConverter.allocationSize(3);
+ size += FfiConverterString.allocationSize(inner.socketPath);
+ size += FfiConverterString.allocationSize(inner.reason);
+ return size;
+ }
+ case DriverError_Tags.Protocol: {
+ const inner = value.inner;
+ let size = ordinalConverter.allocationSize(4);
+ size += FfiConverterString.allocationSize(inner.reason);
+ return size;
+ }
+ case DriverError_Tags.Tool: {
+ const inner = value.inner;
+ let size = ordinalConverter.allocationSize(5);
+ size += FfiConverterString.allocationSize(inner.tool);
+ size += FfiConverterString.allocationSize(inner.message);
+ size += FfiConverterString.allocationSize(inner.errorCode);
+ return size;
+ }
+ default: throw new UniffiInternalError.UnexpectedEnumCase();
+ }
+ }
+ }
+ return new FFIConverter();
+})();
+
+export interface CuaDriverLike {
+
+/**
+ * Escape hatch for forward-compatible tools and application-owned server
+ * adapters. Typed methods below serialize the same canonical Rust inputs.
+ */
+ callTool(name: string, argumentsJson: string) /*throws*/: ToolResult;
+ click(input: ClickInput) /*throws*/: ToolResult;
+ drag(input: DragInput) /*throws*/: ToolResult;
+ endSession(input: EndSessionInput) /*throws*/: EndSessionOutput;
+ escalateSession(input: EscalateSessionInput) /*throws*/: SessionStateOutput;
+ getCursorPosition(input: GetCursorPositionInput) /*throws*/: ToolResult;
+ getDesktopState(input: GetDesktopStateInput) /*throws*/: ToolResult;
+ getScreenSize(input: GetScreenSizeInput) /*throws*/: ToolResult;
+ getSessionState(input: GetSessionStateInput) /*throws*/: SessionStateOutput;
+ hotkey(input: HotkeyInput) /*throws*/: ToolResult;
+ isAvailable(): boolean;
+ listToolsJson() /*throws*/: string;
+ moveCursor(input: MoveCursorInput) /*throws*/: ToolResult;
+ pressKey(input: PressKeyInput) /*throws*/: ToolResult;
+ scroll(input: ScrollInput) /*throws*/: ToolResult;
+ socketPath(): string;
+ startSession(input: StartSessionInput) /*throws*/: StartSessionOutput;
+ typeText(input: TypeTextInput) /*throws*/: ToolResult;
+}
+/**
+ * @deprecated Use `CuaDriverLike` instead.
+ */
+export type CuaDriverInterface = CuaDriverLike;
+
+
+export class CuaDriver extends UniffiAbstractObject implements CuaDriverLike {
+
+ readonly [uniffiTypeNameSymbol] = "CuaDriver";
+ readonly [destructorGuardSymbol]: UniffiGcObject;
+ readonly [pointerLiteralSymbol]: UniffiHandle;
+ // No primary constructor declared for this class.
+private constructor(pointer: UniffiHandle) {
+ super();
+ this[pointerLiteralSymbol] = pointer;
+ this[destructorGuardSymbol] = uniffiTypeCuaDriverObjectFactory.bless(pointer);
+}
+
+
+/**
+ * Connect to the default installed daemon or an explicitly selected socket.
+ * Construction does not launch a process or perform I/O.
+ */
+ static connect(socketPath: string | undefined): CuaDriverLike /*throws*/ {
+ return FfiConverterTypeCuaDriver.lift(uniffiCaller.rustCallWithError(
+ /*liftError:*/ FfiConverterTypeDriverError.lift.bind(FfiConverterTypeDriverError),
+ /*caller:*/ (callStatus) => {
+ return nativeModule().uniffi_cua_driver_sdk_fn_constructor_cuadriver_connect(
+ FfiConverterOptionalString.lower(socketPath, nativeModule().rustbuffer_alloc),
+ callStatus);
+ },
+ /*liftString:*/ FfiConverterString.lift.bind(FfiConverterString),
+ ));
+ }
+
+
+
+/**
+ * Escape hatch for forward-compatible tools and application-owned server
+ * adapters. Typed methods below serialize the same canonical Rust inputs.
+ */
+ callTool(name: string, argumentsJson: string): ToolResult /*throws*/ {
+ return ((__rb: Uint8Array) => {
+ try {
+ return FfiConverterTypeToolResult.lift(__rb);
+ } finally {
+ nativeModule().rustbuffer_free(__rb);
+ }
+ })(uniffiCaller.rustCallWithError(
+ /*liftError:*/ FfiConverterTypeDriverError.lift.bind(FfiConverterTypeDriverError),
+ /*caller:*/ (callStatus) => {
+ return nativeModule().uniffi_cua_driver_sdk_fn_method_cuadriver_call_tool(
+ uniffiTypeCuaDriverObjectFactory.clonePointer(this),
+ FfiConverterString.lower(name, nativeModule().rustbuffer_alloc),
+ FfiConverterString.lower(argumentsJson, nativeModule().rustbuffer_alloc),
+ callStatus);
+ },
+ /*liftString:*/ FfiConverterString.lift.bind(FfiConverterString),
+ ));
+ }
+
+ click(input: ClickInput): ToolResult /*throws*/ {
+ return ((__rb: Uint8Array) => {
+ try {
+ return FfiConverterTypeToolResult.lift(__rb);
+ } finally {
+ nativeModule().rustbuffer_free(__rb);
+ }
+ })(uniffiCaller.rustCallWithError(
+ /*liftError:*/ FfiConverterTypeDriverError.lift.bind(FfiConverterTypeDriverError),
+ /*caller:*/ (callStatus) => {
+ return nativeModule().uniffi_cua_driver_sdk_fn_method_cuadriver_click(
+ uniffiTypeCuaDriverObjectFactory.clonePointer(this),
+ FfiConverterTypeClickInput.lower(input, nativeModule().rustbuffer_alloc),
+ callStatus);
+ },
+ /*liftString:*/ FfiConverterString.lift.bind(FfiConverterString),
+ ));
+ }
+
+ drag(input: DragInput): ToolResult /*throws*/ {
+ return ((__rb: Uint8Array) => {
+ try {
+ return FfiConverterTypeToolResult.lift(__rb);
+ } finally {
+ nativeModule().rustbuffer_free(__rb);
+ }
+ })(uniffiCaller.rustCallWithError(
+ /*liftError:*/ FfiConverterTypeDriverError.lift.bind(FfiConverterTypeDriverError),
+ /*caller:*/ (callStatus) => {
+ return nativeModule().uniffi_cua_driver_sdk_fn_method_cuadriver_drag(
+ uniffiTypeCuaDriverObjectFactory.clonePointer(this),
+ FfiConverterTypeDragInput.lower(input, nativeModule().rustbuffer_alloc),
+ callStatus);
+ },
+ /*liftString:*/ FfiConverterString.lift.bind(FfiConverterString),
+ ));
+ }
+
+ endSession(input: EndSessionInput): EndSessionOutput /*throws*/ {
+ return ((__rb: Uint8Array) => {
+ try {
+ return FfiConverterTypeEndSessionOutput.lift(__rb);
+ } finally {
+ nativeModule().rustbuffer_free(__rb);
+ }
+ })(uniffiCaller.rustCallWithError(
+ /*liftError:*/ FfiConverterTypeDriverError.lift.bind(FfiConverterTypeDriverError),
+ /*caller:*/ (callStatus) => {
+ return nativeModule().uniffi_cua_driver_sdk_fn_method_cuadriver_end_session(
+ uniffiTypeCuaDriverObjectFactory.clonePointer(this),
+ FfiConverterTypeEndSessionInput.lower(input, nativeModule().rustbuffer_alloc),
+ callStatus);
+ },
+ /*liftString:*/ FfiConverterString.lift.bind(FfiConverterString),
+ ));
+ }
+
+ escalateSession(input: EscalateSessionInput): SessionStateOutput /*throws*/ {
+ return ((__rb: Uint8Array) => {
+ try {
+ return FfiConverterTypeSessionStateOutput.lift(__rb);
+ } finally {
+ nativeModule().rustbuffer_free(__rb);
+ }
+ })(uniffiCaller.rustCallWithError(
+ /*liftError:*/ FfiConverterTypeDriverError.lift.bind(FfiConverterTypeDriverError),
+ /*caller:*/ (callStatus) => {
+ return nativeModule().uniffi_cua_driver_sdk_fn_method_cuadriver_escalate_session(
+ uniffiTypeCuaDriverObjectFactory.clonePointer(this),
+ FfiConverterTypeEscalateSessionInput.lower(input, nativeModule().rustbuffer_alloc),
+ callStatus);
+ },
+ /*liftString:*/ FfiConverterString.lift.bind(FfiConverterString),
+ ));
+ }
+
+ getCursorPosition(input: GetCursorPositionInput): ToolResult /*throws*/ {
+ return ((__rb: Uint8Array) => {
+ try {
+ return FfiConverterTypeToolResult.lift(__rb);
+ } finally {
+ nativeModule().rustbuffer_free(__rb);
+ }
+ })(uniffiCaller.rustCallWithError(
+ /*liftError:*/ FfiConverterTypeDriverError.lift.bind(FfiConverterTypeDriverError),
+ /*caller:*/ (callStatus) => {
+ return nativeModule().uniffi_cua_driver_sdk_fn_method_cuadriver_get_cursor_position(
+ uniffiTypeCuaDriverObjectFactory.clonePointer(this),
+ FfiConverterTypeGetCursorPositionInput.lower(input, nativeModule().rustbuffer_alloc),
+ callStatus);
+ },
+ /*liftString:*/ FfiConverterString.lift.bind(FfiConverterString),
+ ));
+ }
+
+ getDesktopState(input: GetDesktopStateInput): ToolResult /*throws*/ {
+ return ((__rb: Uint8Array) => {
+ try {
+ return FfiConverterTypeToolResult.lift(__rb);
+ } finally {
+ nativeModule().rustbuffer_free(__rb);
+ }
+ })(uniffiCaller.rustCallWithError(
+ /*liftError:*/ FfiConverterTypeDriverError.lift.bind(FfiConverterTypeDriverError),
+ /*caller:*/ (callStatus) => {
+ return nativeModule().uniffi_cua_driver_sdk_fn_method_cuadriver_get_desktop_state(
+ uniffiTypeCuaDriverObjectFactory.clonePointer(this),
+ FfiConverterTypeGetDesktopStateInput.lower(input, nativeModule().rustbuffer_alloc),
+ callStatus);
+ },
+ /*liftString:*/ FfiConverterString.lift.bind(FfiConverterString),
+ ));
+ }
+
+ getScreenSize(input: GetScreenSizeInput): ToolResult /*throws*/ {
+ return ((__rb: Uint8Array) => {
+ try {
+ return FfiConverterTypeToolResult.lift(__rb);
+ } finally {
+ nativeModule().rustbuffer_free(__rb);
+ }
+ })(uniffiCaller.rustCallWithError(
+ /*liftError:*/ FfiConverterTypeDriverError.lift.bind(FfiConverterTypeDriverError),
+ /*caller:*/ (callStatus) => {
+ return nativeModule().uniffi_cua_driver_sdk_fn_method_cuadriver_get_screen_size(
+ uniffiTypeCuaDriverObjectFactory.clonePointer(this),
+ FfiConverterTypeGetScreenSizeInput.lower(input, nativeModule().rustbuffer_alloc),
+ callStatus);
+ },
+ /*liftString:*/ FfiConverterString.lift.bind(FfiConverterString),
+ ));
+ }
+
+ getSessionState(input: GetSessionStateInput): SessionStateOutput /*throws*/ {
+ return ((__rb: Uint8Array) => {
+ try {
+ return FfiConverterTypeSessionStateOutput.lift(__rb);
+ } finally {
+ nativeModule().rustbuffer_free(__rb);
+ }
+ })(uniffiCaller.rustCallWithError(
+ /*liftError:*/ FfiConverterTypeDriverError.lift.bind(FfiConverterTypeDriverError),
+ /*caller:*/ (callStatus) => {
+ return nativeModule().uniffi_cua_driver_sdk_fn_method_cuadriver_get_session_state(
+ uniffiTypeCuaDriverObjectFactory.clonePointer(this),
+ FfiConverterTypeGetSessionStateInput.lower(input, nativeModule().rustbuffer_alloc),
+ callStatus);
+ },
+ /*liftString:*/ FfiConverterString.lift.bind(FfiConverterString),
+ ));
+ }
+
+ hotkey(input: HotkeyInput): ToolResult /*throws*/ {
+ return ((__rb: Uint8Array) => {
+ try {
+ return FfiConverterTypeToolResult.lift(__rb);
+ } finally {
+ nativeModule().rustbuffer_free(__rb);
+ }
+ })(uniffiCaller.rustCallWithError(
+ /*liftError:*/ FfiConverterTypeDriverError.lift.bind(FfiConverterTypeDriverError),
+ /*caller:*/ (callStatus) => {
+ return nativeModule().uniffi_cua_driver_sdk_fn_method_cuadriver_hotkey(
+ uniffiTypeCuaDriverObjectFactory.clonePointer(this),
+ FfiConverterTypeHotkeyInput.lower(input, nativeModule().rustbuffer_alloc),
+ callStatus);
+ },
+ /*liftString:*/ FfiConverterString.lift.bind(FfiConverterString),
+ ));
+ }
+
+ isAvailable(): boolean {
+ return FfiConverterBool.lift(uniffiCaller.rustCall(
+ /*caller:*/ (callStatus) => {
+ return nativeModule().uniffi_cua_driver_sdk_fn_method_cuadriver_is_available(
+ uniffiTypeCuaDriverObjectFactory.clonePointer(this),
+ callStatus);
+ },
+ /*liftString:*/ FfiConverterString.lift.bind(FfiConverterString),
+ ));
+ }
+
+ listToolsJson(): string /*throws*/ {
+ return ((__rb: Uint8Array) => {
+ try {
+ return FfiConverterString.lift(__rb);
+ } finally {
+ nativeModule().rustbuffer_free(__rb);
+ }
+ })(uniffiCaller.rustCallWithError(
+ /*liftError:*/ FfiConverterTypeDriverError.lift.bind(FfiConverterTypeDriverError),
+ /*caller:*/ (callStatus) => {
+ return nativeModule().uniffi_cua_driver_sdk_fn_method_cuadriver_list_tools_json(
+ uniffiTypeCuaDriverObjectFactory.clonePointer(this),
+ callStatus);
+ },
+ /*liftString:*/ FfiConverterString.lift.bind(FfiConverterString),
+ ));
+ }
+
+ moveCursor(input: MoveCursorInput): ToolResult /*throws*/ {
+ return ((__rb: Uint8Array) => {
+ try {
+ return FfiConverterTypeToolResult.lift(__rb);
+ } finally {
+ nativeModule().rustbuffer_free(__rb);
+ }
+ })(uniffiCaller.rustCallWithError(
+ /*liftError:*/ FfiConverterTypeDriverError.lift.bind(FfiConverterTypeDriverError),
+ /*caller:*/ (callStatus) => {
+ return nativeModule().uniffi_cua_driver_sdk_fn_method_cuadriver_move_cursor(
+ uniffiTypeCuaDriverObjectFactory.clonePointer(this),
+ FfiConverterTypeMoveCursorInput.lower(input, nativeModule().rustbuffer_alloc),
+ callStatus);
+ },
+ /*liftString:*/ FfiConverterString.lift.bind(FfiConverterString),
+ ));
+ }
+
+ pressKey(input: PressKeyInput): ToolResult /*throws*/ {
+ return ((__rb: Uint8Array) => {
+ try {
+ return FfiConverterTypeToolResult.lift(__rb);
+ } finally {
+ nativeModule().rustbuffer_free(__rb);
+ }
+ })(uniffiCaller.rustCallWithError(
+ /*liftError:*/ FfiConverterTypeDriverError.lift.bind(FfiConverterTypeDriverError),
+ /*caller:*/ (callStatus) => {
+ return nativeModule().uniffi_cua_driver_sdk_fn_method_cuadriver_press_key(
+ uniffiTypeCuaDriverObjectFactory.clonePointer(this),
+ FfiConverterTypePressKeyInput.lower(input, nativeModule().rustbuffer_alloc),
+ callStatus);
+ },
+ /*liftString:*/ FfiConverterString.lift.bind(FfiConverterString),
+ ));
+ }
+
+ scroll(input: ScrollInput): ToolResult /*throws*/ {
+ return ((__rb: Uint8Array) => {
+ try {
+ return FfiConverterTypeToolResult.lift(__rb);
+ } finally {
+ nativeModule().rustbuffer_free(__rb);
+ }
+ })(uniffiCaller.rustCallWithError(
+ /*liftError:*/ FfiConverterTypeDriverError.lift.bind(FfiConverterTypeDriverError),
+ /*caller:*/ (callStatus) => {
+ return nativeModule().uniffi_cua_driver_sdk_fn_method_cuadriver_scroll(
+ uniffiTypeCuaDriverObjectFactory.clonePointer(this),
+ FfiConverterTypeScrollInput.lower(input, nativeModule().rustbuffer_alloc),
+ callStatus);
+ },
+ /*liftString:*/ FfiConverterString.lift.bind(FfiConverterString),
+ ));
+ }
+
+ socketPath(): string {
+ return ((__rb: Uint8Array) => {
+ try {
+ return FfiConverterString.lift(__rb);
+ } finally {
+ nativeModule().rustbuffer_free(__rb);
+ }
+ })(uniffiCaller.rustCall(
+ /*caller:*/ (callStatus) => {
+ return nativeModule().uniffi_cua_driver_sdk_fn_method_cuadriver_socket_path(
+ uniffiTypeCuaDriverObjectFactory.clonePointer(this),
+ callStatus);
+ },
+ /*liftString:*/ FfiConverterString.lift.bind(FfiConverterString),
+ ));
+ }
+
+ startSession(input: StartSessionInput): StartSessionOutput /*throws*/ {
+ return ((__rb: Uint8Array) => {
+ try {
+ return FfiConverterTypeStartSessionOutput.lift(__rb);
+ } finally {
+ nativeModule().rustbuffer_free(__rb);
+ }
+ })(uniffiCaller.rustCallWithError(
+ /*liftError:*/ FfiConverterTypeDriverError.lift.bind(FfiConverterTypeDriverError),
+ /*caller:*/ (callStatus) => {
+ return nativeModule().uniffi_cua_driver_sdk_fn_method_cuadriver_start_session(
+ uniffiTypeCuaDriverObjectFactory.clonePointer(this),
+ FfiConverterTypeStartSessionInput.lower(input, nativeModule().rustbuffer_alloc),
+ callStatus);
+ },
+ /*liftString:*/ FfiConverterString.lift.bind(FfiConverterString),
+ ));
+ }
+
+ typeText(input: TypeTextInput): ToolResult /*throws*/ {
+ return ((__rb: Uint8Array) => {
+ try {
+ return FfiConverterTypeToolResult.lift(__rb);
+ } finally {
+ nativeModule().rustbuffer_free(__rb);
+ }
+ })(uniffiCaller.rustCallWithError(
+ /*liftError:*/ FfiConverterTypeDriverError.lift.bind(FfiConverterTypeDriverError),
+ /*caller:*/ (callStatus) => {
+ return nativeModule().uniffi_cua_driver_sdk_fn_method_cuadriver_type_text(
+ uniffiTypeCuaDriverObjectFactory.clonePointer(this),
+ FfiConverterTypeTypeTextInput.lower(input, nativeModule().rustbuffer_alloc),
+ callStatus);
+ },
+ /*liftString:*/ FfiConverterString.lift.bind(FfiConverterString),
+ ));
+ }
+
+
+ uniffiDestroy(): void {
+ const ptr = (this as any)[destructorGuardSymbol];
+ if (ptr !== undefined) {
+ const pointer = uniffiTypeCuaDriverObjectFactory.pointer(this);
+ uniffiTypeCuaDriverObjectFactory.freePointer(pointer);
+ uniffiTypeCuaDriverObjectFactory.unbless(ptr);
+ delete (this as any)[destructorGuardSymbol];
+ }
+ }
+
+ static instanceOf(obj_: any): obj_ is CuaDriver {
+ return uniffiTypeCuaDriverObjectFactory.isConcreteType(obj_);
+ }
+
+
+}
+
+const uniffiTypeCuaDriverObjectFactory: UniffiObjectFactory<CuaDriverLike> = (() => {
+
+ /// <reference lib="es2021" />
+ const registry = typeof FinalizationRegistry !== 'undefined' ? new FinalizationRegistry<UniffiHandle>((heldValue: UniffiHandle) => {
+ uniffiTypeCuaDriverObjectFactory.freePointer(heldValue);
+ }) : null;
+
+ return {
+ create(pointer: UniffiHandle): CuaDriverLike {
+ const instance = Object.create(CuaDriver.prototype);
+ instance[pointerLiteralSymbol] = pointer;
+ instance[destructorGuardSymbol] = this.bless(pointer);
+ instance[uniffiTypeNameSymbol] = "CuaDriver";
+ return instance;
+ },
+
+
+ bless(p: UniffiHandle): UniffiGcObject {
+ const ptr = {
+ p, // make sure this object doesn't get optimized away.
+ markDestroyed: () => undefined,
+ };
+ if (registry) {
+ registry.register(ptr, p, ptr);
+ }
+ return ptr;
+ },
+
+ unbless(ptr_: UniffiGcObject) {
+ if (registry) {
+ registry.unregister(ptr_);
+ }
+ },
+
+ pointer(obj_: CuaDriverLike): UniffiHandle {
+ if ((obj_ as any)[destructorGuardSymbol] === undefined) {
+ throw new UniffiInternalError.UnexpectedNullPointer();
+ }
+ return (obj_ as any)[pointerLiteralSymbol];
+ },
+
+ clonePointer(obj_: CuaDriverLike): UniffiHandle {
+ const pointer = this.pointer(obj_);
+ return uniffiCaller.rustCall(
+ /*caller:*/ (callStatus) => nativeModule().uniffi_cua_driver_sdk_fn_clone_cuadriver(pointer, callStatus),
+ /*liftString:*/ FfiConverterString.lift
+ );
+ },
+
+ freePointer(pointer: UniffiHandle): void {
+ uniffiCaller.rustCall(
+ /*caller:*/ (callStatus) => nativeModule().uniffi_cua_driver_sdk_fn_free_cuadriver(pointer, callStatus),
+ /*liftString:*/ FfiConverterString.lift
+ );
+ },
+
+ isConcreteType(obj_: any): obj_ is CuaDriverLike {
+ return obj_[destructorGuardSymbol] && obj_[uniffiTypeNameSymbol] === "CuaDriver";
+ },
+}})();
+const FfiConverterTypeCuaDriver = new FfiConverterObject(uniffiTypeCuaDriverObjectFactory);
+
+// FfiConverter for Array<ImageContent>
+const FfiConverterSequenceTypeImageContent = new FfiConverterArray(FfiConverterTypeImageContent);
+
+// FfiConverter for string | undefined
+const FfiConverterOptionalString = new FfiConverterOptional(FfiConverterString);
+
+// FfiConverter for boolean | undefined
+const FfiConverterOptionalBoolean = new FfiConverterOptional(FfiConverterBool);
+
+
+/**
+ * This should be called before anything else.
+ *
+ * It is likely that this is being done for you by the library's `index.ts`.
+ *
+ * It checks versions of uniffi between when the Rust scaffolding was generated
+ * and when the bindings were generated.
+ *
+ * It also initializes the machinery to enable Rust to talk back to Javascript.
+ */
+function uniffiEnsureInitialized() {
+ // Get the bindings contract version from our ComponentInterface
+ const bindingsContractVersion = 30;
+ // Get the scaffolding contract version by calling the into the dylib
+ const scaffoldingContractVersion = nativeModule().ffi_cua_driver_sdk_uniffi_contract_version();
+ if (bindingsContractVersion !== scaffoldingContractVersion) {
+ throw new UniffiInternalError.ContractVersionMismatch(scaffoldingContractVersion, bindingsContractVersion);
+ }
+ if (nativeModule().uniffi_cua_driver_sdk_checksum_constructor_cuadriver_connect() !== 42154) {
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_cua_driver_sdk_checksum_constructor_cuadriver_connect");
+ }
+ if (nativeModule().uniffi_cua_driver_sdk_checksum_method_cuadriver_call_tool() !== 31445) {
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_cua_driver_sdk_checksum_method_cuadriver_call_tool");
+ }
+ if (nativeModule().uniffi_cua_driver_sdk_checksum_method_cuadriver_click() !== 34118) {
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_cua_driver_sdk_checksum_method_cuadriver_click");
+ }
+ if (nativeModule().uniffi_cua_driver_sdk_checksum_method_cuadriver_drag() !== 35252) {
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_cua_driver_sdk_checksum_method_cuadriver_drag");
+ }
+ if (nativeModule().uniffi_cua_driver_sdk_checksum_method_cuadriver_end_session() !== 33990) {
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_cua_driver_sdk_checksum_method_cuadriver_end_session");
+ }
+ if (nativeModule().uniffi_cua_driver_sdk_checksum_method_cuadriver_escalate_session() !== 37358) {
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_cua_driver_sdk_checksum_method_cuadriver_escalate_session");
+ }
+ if (nativeModule().uniffi_cua_driver_sdk_checksum_method_cuadriver_get_cursor_position() !== 54043) {
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_cua_driver_sdk_checksum_method_cuadriver_get_cursor_position");
+ }
+ if (nativeModule().uniffi_cua_driver_sdk_checksum_method_cuadriver_get_desktop_state() !== 32992) {
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_cua_driver_sdk_checksum_method_cuadriver_get_desktop_state");
+ }
+ if (nativeModule().uniffi_cua_driver_sdk_checksum_method_cuadriver_get_screen_size() !== 15250) {
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_cua_driver_sdk_checksum_method_cuadriver_get_screen_size");
+ }
+ if (nativeModule().uniffi_cua_driver_sdk_checksum_method_cuadriver_get_session_state() !== 51055) {
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_cua_driver_sdk_checksum_method_cuadriver_get_session_state");
+ }
+ if (nativeModule().uniffi_cua_driver_sdk_checksum_method_cuadriver_hotkey() !== 3135) {
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_cua_driver_sdk_checksum_method_cuadriver_hotkey");
+ }
+ if (nativeModule().uniffi_cua_driver_sdk_checksum_method_cuadriver_is_available() !== 42961) {
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_cua_driver_sdk_checksum_method_cuadriver_is_available");
+ }
+ if (nativeModule().uniffi_cua_driver_sdk_checksum_method_cuadriver_list_tools_json() !== 43987) {
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_cua_driver_sdk_checksum_method_cuadriver_list_tools_json");
+ }
+ if (nativeModule().uniffi_cua_driver_sdk_checksum_method_cuadriver_move_cursor() !== 11209) {
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_cua_driver_sdk_checksum_method_cuadriver_move_cursor");
+ }
+ if (nativeModule().uniffi_cua_driver_sdk_checksum_method_cuadriver_press_key() !== 17425) {
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_cua_driver_sdk_checksum_method_cuadriver_press_key");
+ }
+ if (nativeModule().uniffi_cua_driver_sdk_checksum_method_cuadriver_scroll() !== 21614) {
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_cua_driver_sdk_checksum_method_cuadriver_scroll");
+ }
+ if (nativeModule().uniffi_cua_driver_sdk_checksum_method_cuadriver_socket_path() !== 24461) {
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_cua_driver_sdk_checksum_method_cuadriver_socket_path");
+ }
+ if (nativeModule().uniffi_cua_driver_sdk_checksum_method_cuadriver_start_session() !== 53509) {
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_cua_driver_sdk_checksum_method_cuadriver_start_session");
+ }
+ if (nativeModule().uniffi_cua_driver_sdk_checksum_method_cuadriver_type_text() !== 19673) {
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_cua_driver_sdk_checksum_method_cuadriver_type_text");
+ }
+
+ }
+
+export default Object.freeze({
+ initialize: uniffiEnsureInitialized,
+ converters: {
+ FfiConverterTypeCuaDriver,
+ FfiConverterTypeDriverError,
+ FfiConverterTypeImageContent,
+ FfiConverterTypeToolResult,
+ }
+});
diff --git a/libs/cua-driver/typescript/src/native/index.ts b/libs/cua-driver/typescript/src/native/index.ts
new file mode 100644
index 0000000000..ec0453abca
--- /dev/null
+++ b/libs/cua-driver/typescript/src/native/index.ts
@@ -0,0 +1,21 @@
+// Generated by uniffi-bindgen-react-native — do not edit.
+export * from './cua_driver_contract.js';
+export * from './cua_driver_sdk.js';
+import * as cua_driver_contract from './cua_driver_contract.js';
+import * as cua_driver_sdk from './cua_driver_sdk.js';
+
+
+let initialized = false;
+if (!initialized) {
+ cua_driver_contract.default.initialize();
+ cua_driver_sdk.default.initialize();
+ initialized = true;
+}
+
+export async function uniffiInitAsync() { /* sync flavor: no-op */ }
+
+
+export default {
+ cua_driver_contract,
+ cua_driver_sdk,
+};
diff --git a/libs/cua-driver/typescript/test/native-daemon-fixture.mjs b/libs/cua-driver/typescript/test/native-daemon-fixture.mjs
new file mode 100644
index 0000000000..6d1cdb8960
--- /dev/null
+++ b/libs/cua-driver/typescript/test/native-daemon-fixture.mjs
@@ -0,0 +1,32 @@
+import net from "node:net"
+
+const socketPath = process.argv[2]
+if (!socketPath) throw new Error("missing socket path")
+
+const server = net.createServer((connection) => {
+ let buffer = ""
+ connection.setEncoding("utf8")
+ connection.on("data", (chunk) => {
+ buffer += chunk
+ const newline = buffer.indexOf("\n")
+ if (newline < 0) return
+ const request = JSON.parse(buffer.slice(0, newline))
+ process.send?.({ request })
+ connection.end(
+ `${JSON.stringify({
+ ok: true,
+ result: {
+ content: [
+ { type: "text", text: "node ffi" },
+ { type: "image", mimeType: "image/png", data: "cG5n" },
+ ],
+ structuredContent: { verified: true },
+ isError: false,
+ },
+ })}\n`,
+ )
+ server.close()
+ })
+})
+
+server.listen(socketPath, () => process.send?.({ ready: true }))
diff --git a/libs/cua-driver/typescript/test/native-loader.test.mjs b/libs/cua-driver/typescript/test/native-loader.test.mjs
new file mode 100644
index 0000000000..c97edfe712
--- /dev/null
+++ b/libs/cua-driver/typescript/test/native-loader.test.mjs
@@ -0,0 +1,100 @@
+import assert from "node:assert/strict"
+import { spawn } from "node:child_process"
+import { existsSync, mkdtempSync, rmSync } from "node:fs"
+import os from "node:os"
+import path from "node:path"
+import test from "node:test"
+import { fileURLToPath } from "node:url"
+
+const testDirectory = path.dirname(fileURLToPath(import.meta.url))
+const libraryName =
+ process.platform === "darwin"
+ ? "libcua_driver_sdk.dylib"
+ : process.platform === "win32"
+ ? "cua_driver_sdk.dll"
+ : "libcua_driver_sdk.so"
+const library = path.resolve(testDirectory, "../dist/native", libraryName)
+
+if (process.env.CUA_DRIVER_REQUIRE_UNIFFI === "1" && !existsSync(library)) {
+ throw new Error(`required staged UniFFI library is missing: ${library}`)
+}
+
+test(
+ "generated Node SDK bindings call the Rust daemon interface",
+ { skip: process.platform === "win32" || !existsSync(library), timeout: 10_000 },
+ async () => {
+ const directory = mkdtempSync(path.join(os.tmpdir(), "cua-driver-node-ffi-"))
+ const socketPath = path.join(directory, "driver.sock")
+ const fixture = spawn(
+ process.execPath,
+ [path.join(testDirectory, "native-daemon-fixture.mjs"), socketPath],
+ { stdio: ["ignore", "inherit", "inherit", "ipc"] },
+ )
+ const readyPromise = new Promise((resolve, reject) => {
+ fixture.on("error", reject)
+ fixture.on("message", (message) => {
+ if (message.ready) resolve(null)
+ })
+ })
+ const requestPromise = readyPromise.then(
+ () =>
+ new Promise((resolve, reject) => {
+ fixture.on("error", reject)
+ fixture.on("message", (message) => {
+ if (message.request) resolve(message.request)
+ })
+ }),
+ )
+
+ try {
+ await readyPromise
+ assert.equal(existsSync(socketPath), true)
+ const sdk = await import("@trycua/cua-driver")
+ const { CuaDriver, GetDesktopStateInput } = sdk
+ assert.equal("StdioMcpTransport" in sdk, false)
+ await assert.rejects(
+ import("@trycua/cua-driver/sdk"),
+ error => error?.code === "ERR_PACKAGE_PATH_NOT_EXPORTED",
+ )
+ await assert.rejects(
+ import("@trycua/cua-driver/native"),
+ error => error?.code === "ERR_PACKAGE_PATH_NOT_EXPORTED",
+ )
+ const driver = CuaDriver.connect(socketPath)
+ const expectedMethods = [
+ "startSession",
+ "escalateSession",
+ "getSessionState",
+ "endSession",
+ "getDesktopState",
+ "getScreenSize",
+ "getCursorPosition",
+ "moveCursor",
+ "click",
+ "drag",
+ "scroll",
+ "typeText",
+ "pressKey",
+ "hotkey",
+ ]
+ assert.equal(
+ expectedMethods.every((name) => typeof driver[name] === "function"),
+ true,
+ )
+ const result = driver.getDesktopState(
+ GetDesktopStateInput.new({ session: "node-run" }),
+ )
+ const request = await requestPromise
+ driver.uniffiDestroy()
+
+ assert.equal(result.text, "node ffi")
+ assert.equal(result.images[0].mimeType, "image/png")
+ assert.equal(result.verified, true)
+ assert.equal(request.name, "get_desktop_state")
+ assert.deepEqual(request.args, { session: "node-run" })
+ } finally {
+ fixture.kill()
+ rmSync(directory, { recursive: true, force: true })
+ }
+ },
+)
diff --git a/libs/cua-driver/typescript/tsconfig.json b/libs/cua-driver/typescript/tsconfig.json
new file mode 100644
index 0000000000..d33fa87ad7
--- /dev/null
+++ b/libs/cua-driver/typescript/tsconfig.json
@@ -0,0 +1,15 @@
+{
+ "compilerOptions": {
+ "target": "ES2022",
+ "module": "NodeNext",
+ "moduleResolution": "NodeNext",
+ "declaration": true,
+ "outDir": "dist",
+ "rootDir": "src",
+ "strict": true,
+ "noUncheckedIndexedAccess": true,
+ "exactOptionalPropertyTypes": true,
+ "skipLibCheck": true
+ },
+ "include": ["src/**/*.ts"]
+}
diff --git a/nix/cua-driver/tests/policy-rego.nix b/nix/cua-driver/tests/policy-rego.nix
index 7cf4288a83..f456b4ac07 100644
--- a/nix/cua-driver/tests/policy-rego.nix
+++ b/nix/cua-driver/tests/policy-rego.nix
@@ -60,7 +60,7 @@ let
request '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"screenshot","arguments":{}}}'
jq -e '.id == 2 and .error == null and .result != null' <<<"$response" >/dev/null
- request '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"shell_execute","arguments":{}}}'
+ request '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"type_text","arguments":{"text":"blocked"}}}'
jq -e '.id == 3 and .error == null and .result.isError == true and (.result.content[0].text | startswith("Permission denied:"))' <<<"$response" >/dev/null
request '{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"click","arguments":{"x":2000,"y":100}}}'
diff --git a/nix/cua-driver/tests/policy-yaml.nix b/nix/cua-driver/tests/policy-yaml.nix
index 65e9fe1120..ded572a110 100644
--- a/nix/cua-driver/tests/policy-yaml.nix
+++ b/nix/cua-driver/tests/policy-yaml.nix
@@ -19,7 +19,7 @@ let
y: { min: 0, max: 1080 }
deny:
tools:
- - shell_execute
+ - type_text
POLICY
socket=/tmp/cua-driver-policy-yaml.sock
@@ -54,7 +54,7 @@ let
request '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"screenshot","arguments":{}}}'
jq -e '.id == 2 and .error == null and .result != null' <<<"$response" >/dev/null
- request '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"shell_execute","arguments":{}}}'
+ request '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"type_text","arguments":{"text":"blocked"}}}'
jq -e '.id == 3 and .error == null and .result.isError == true and (.result.content[0].text | startswith("Permission denied:"))' <<<"$response" >/dev/null
request '{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"click","arguments":{"x":1921,"y":100}}}'
diff --git a/release-please-config.json b/release-please-config.json
index 53744d87fc..953d218f6c 100644
--- a/release-please-config.json
+++ b/release-please-config.json
@@ -32,6 +32,21 @@
"type": "generic",
"path": "python/src/cua_driver/__init__.py"
},
+ {
+ "type": "json",
+ "path": "typescript/package.json",
+ "jsonpath": "$.version"
+ },
+ {
+ "type": "json",
+ "path": "typescript/package-lock.json",
+ "jsonpath": "$.version"
+ },
+ {
+ "type": "json",
+ "path": "typescript/package-lock.json",
+ "jsonpath": "$.packages[''].version"
+ },
{
"type": "generic",
"path": "scripts/_install-rust.sh"