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.

fix prettier issues

Sarina Liabaf590da1e0
diff --git a/.github/workflows/npm-publish-cli.yml b/.github/workflows/npm-publish-cli.yml
index 57d1ca7cc4..4bc2826b3d 100644
--- a/.github/workflows/npm-publish-cli.yml
+++ b/.github/workflows/npm-publish-cli.yml
@@ -4,9 +4,9 @@ on:
workflow_dispatch:
inputs:
version:
- description: 'Version to publish (default: from package.json)'
+ description: "Version to publish (default: from package.json)"
required: false
- default: ''
+ default: ""
jobs:
build-and-publish:
@@ -14,25 +14,25 @@ jobs:
id-token: write
contents: write
packages: write
-
+
strategy:
matrix:
include:
- target: bun-linux-x64
- ext: ''
+ ext: ""
binary_name: cua-linux-x64
- target: bun-darwin-x64
- ext: ''
+ ext: ""
binary_name: cua-darwin-x64
- target: bun-darwin-arm64
- ext: ''
+ ext: ""
binary_name: cua-darwin-arm64
- target: bun-windows-x64
- ext: '.exe'
+ ext: ".exe"
binary_name: cua-windows-x64
-
+
runs-on: ubuntu-latest
-
+
steps:
- name: Checkout code
uses: actions/checkout@v4
@@ -140,7 +140,7 @@ jobs:
```bash
# For Linux/macOS
curl -fsSL https://cua.ai/cli/install.sh | sh
-
+
# For Windows (PowerShell)
irm https://cua.ai/cli/install.ps1 | iex
```
@@ -149,7 +149,7 @@ jobs:
```bash
# Using bun
bun add -g @trycua/cli
-
+
# Or using npm
npm install -g @trycua/cli
```
@@ -209,4 +209,4 @@ jobs:
asset_name: cua-windows-x64.exe
asset_content_type: application/octet-stream
env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
\ No newline at end of file
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/libs/typescript/cua-cli/src/commands/vm.ts b/libs/typescript/cua-cli/src/commands/vm.ts
index 39ecb546aa..636b01bad2 100644
--- a/libs/typescript/cua-cli/src/commands/vm.ts
+++ b/libs/typescript/cua-cli/src/commands/vm.ts
@@ -11,11 +11,12 @@ export function registerVmCommands(y: Argv) {
.command(
['list', 'ls', 'ps'],
'List sandboxes',
- (y) => y.option('show-passwords', {
- type: 'boolean',
- default: false,
- describe: 'Show sandbox passwords in output'
- }),
+ (y) =>
+ y.option('show-passwords', {
+ type: 'boolean',
+ default: false,
+ describe: 'Show sandbox passwords in output',
+ }),
async (argv: Record<string, unknown>) => {
const token = await ensureApiKeyInteractive();
const res = await http('/v1/vms', { token });
@@ -34,284 +35,283 @@ export function registerVmCommands(y: Argv) {
)
.command(
'create',
- 'Create a new sandbox',
- (y) =>
- y
- .option('os', {
- type: 'string',
- choices: ['linux', 'windows', 'macos'],
- demandOption: true,
- describe: 'Operating system',
- })
- .option('configuration', {
- type: 'string',
- choices: ['small', 'medium', 'large'],
- demandOption: true,
- describe: 'Sandbox size configuration',
- })
- .option('region', {
- type: 'string',
- choices: [
- 'north-america',
- 'europe',
- 'asia-pacific',
- 'south-america',
- ],
- demandOption: true,
- describe: 'Sandbox region',
- }),
- async (argv: Record<string, unknown>) => {
- const token = await ensureApiKeyInteractive();
- const { os, configuration, region } = argv as {
- os: string;
- configuration: string;
- region: string;
- };
-
- const res = await http('/v1/vms', {
- token,
- method: 'POST',
- body: { os, configuration, region },
- });
+ 'Create a new sandbox',
+ (y) =>
+ y
+ .option('os', {
+ type: 'string',
+ choices: ['linux', 'windows', 'macos'],
+ demandOption: true,
+ describe: 'Operating system',
+ })
+ .option('configuration', {
+ type: 'string',
+ choices: ['small', 'medium', 'large'],
+ demandOption: true,
+ describe: 'Sandbox size configuration',
+ })
+ .option('region', {
+ type: 'string',
+ choices: [
+ 'north-america',
+ 'europe',
+ 'asia-pacific',
+ 'south-america',
+ ],
+ demandOption: true,
+ describe: 'Sandbox region',
+ }),
+ async (argv: Record<string, unknown>) => {
+ const token = await ensureApiKeyInteractive();
+ const { os, configuration, region } = argv as {
+ os: string;
+ configuration: string;
+ region: string;
+ };
- if (res.status === 401) {
- clearApiKey();
- console.error("Unauthorized. Try 'cua login' again.");
- process.exit(1);
- }
+ const res = await http('/v1/vms', {
+ token,
+ method: 'POST',
+ body: { os, configuration, region },
+ });
- if (res.status === 400) {
- console.error('Invalid request or unsupported configuration');
- process.exit(1);
- }
+ if (res.status === 401) {
+ clearApiKey();
+ console.error("Unauthorized. Try 'cua login' again.");
+ process.exit(1);
+ }
- if (res.status === 500) {
- console.error('Internal server error');
- process.exit(1);
- }
+ if (res.status === 400) {
+ console.error('Invalid request or unsupported configuration');
+ process.exit(1);
+ }
- if (res.status === 200) {
- // Sandbox ready immediately
- const data = (await res.json()) as {
- status: string;
- name: string;
- password: string;
- host: string;
- };
- console.log(`Sandbox created and ready: ${data.name}`);
- console.log(`Password: ${data.password}`);
- console.log(`Host: ${data.host}`);
- return;
- }
+ if (res.status === 500) {
+ console.error('Internal server error');
+ process.exit(1);
+ }
- if (res.status === 202) {
- // Sandbox provisioning started
- const data = (await res.json()) as {
- status: string;
- name: string;
- job_id: string;
- };
- console.log(`Sandbox provisioning started: ${data.name}`);
- console.log(`Job ID: ${data.job_id}`);
- console.log("Use 'cua list' to monitor provisioning progress");
- return;
- }
+ if (res.status === 200) {
+ // Sandbox ready immediately
+ const data = (await res.json()) as {
+ status: string;
+ name: string;
+ password: string;
+ host: string;
+ };
+ console.log(`Sandbox created and ready: ${data.name}`);
+ console.log(`Password: ${data.password}`);
+ console.log(`Host: ${data.host}`);
+ return;
+ }
- console.error(`Unexpected status: ${res.status}`);
- process.exit(1);
+ if (res.status === 202) {
+ // Sandbox provisioning started
+ const data = (await res.json()) as {
+ status: string;
+ name: string;
+ job_id: string;
+ };
+ console.log(`Sandbox provisioning started: ${data.name}`);
+ console.log(`Job ID: ${data.job_id}`);
+ console.log("Use 'cua list' to monitor provisioning progress");
+ return;
}
- )
+
+ console.error(`Unexpected status: ${res.status}`);
+ process.exit(1);
+ }
+ )
.command(
'delete <name>',
- 'Delete a sandbox',
- (y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
- async (argv: Record<string, unknown>) => {
- const token = await ensureApiKeyInteractive();
- const name = String((argv as any).name);
- const res = await http(`/v1/vms/${encodeURIComponent(name)}`, {
- token,
- method: 'DELETE',
- });
-
- if (res.status === 202) {
- const body = (await res.json().catch(() => ({}))) as {
- status?: string;
- };
- console.log(`Sandbox deletion initiated: ${body.status ?? 'deleting'}`);
- return;
- }
+ 'Delete a sandbox',
+ (y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
+ async (argv: Record<string, unknown>) => {
+ const token = await ensureApiKeyInteractive();
+ const name = String((argv as any).name);
+ const res = await http(`/v1/vms/${encodeURIComponent(name)}`, {
+ token,
+ method: 'DELETE',
+ });
- if (res.status === 404) {
- console.error('Sandbox not found or not owned by you');
- process.exit(1);
- }
+ if (res.status === 202) {
+ const body = (await res.json().catch(() => ({}))) as {
+ status?: string;
+ };
+ console.log(
+ `Sandbox deletion initiated: ${body.status ?? 'deleting'}`
+ );
+ return;
+ }
- if (res.status === 401) {
- clearApiKey();
- console.error("Unauthorized. Try 'cua login' again.");
- process.exit(1);
- }
+ if (res.status === 404) {
+ console.error('Sandbox not found or not owned by you');
+ process.exit(1);
+ }
- console.error(`Unexpected status: ${res.status}`);
+ if (res.status === 401) {
+ clearApiKey();
+ console.error("Unauthorized. Try 'cua login' again.");
process.exit(1);
}
- )
+
+ console.error(`Unexpected status: ${res.status}`);
+ process.exit(1);
+ }
+ )
.command(
'start <name>',
- 'Start a sandbox',
- (y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
- async (argv: Record<string, unknown>) => {
- const token = await ensureApiKeyInteractive();
- const name = String((argv as any).name);
- const res = await http(`/v1/vms/${encodeURIComponent(name)}/start`, {
- token,
- method: 'POST',
- });
- if (res.status === 204) {
- console.log('Start accepted');
- return;
- }
- if (res.status === 404) {
- console.error('Sandbox not found');
- process.exit(1);
- }
- if (res.status === 401) {
- clearApiKey();
- console.error("Unauthorized. Try 'cua login' again.");
- process.exit(1);
- }
- console.error(`Unexpected status: ${res.status}`);
+ 'Start a sandbox',
+ (y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
+ async (argv: Record<string, unknown>) => {
+ const token = await ensureApiKeyInteractive();
+ const name = String((argv as any).name);
+ const res = await http(`/v1/vms/${encodeURIComponent(name)}/start`, {
+ token,
+ method: 'POST',
+ });
+ if (res.status === 204) {
+ console.log('Start accepted');
+ return;
+ }
+ if (res.status === 404) {
+ console.error('Sandbox not found');
process.exit(1);
}
- )
+ if (res.status === 401) {
+ clearApiKey();
+ console.error("Unauthorized. Try 'cua login' again.");
+ process.exit(1);
+ }
+ console.error(`Unexpected status: ${res.status}`);
+ process.exit(1);
+ }
+ )
.command(
'stop <name>',
- 'Stop a sandbox',
- (y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
- async (argv: Record<string, unknown>) => {
- const token = await ensureApiKeyInteractive();
- const name = String((argv as any).name);
- const res = await http(`/v1/vms/${encodeURIComponent(name)}/stop`, {
- token,
- method: 'POST',
- });
- if (res.status === 202) {
- const body = (await res.json().catch(() => ({}))) as {
- status?: string;
- };
- console.log(body.status ?? 'stopping');
- return;
- }
- if (res.status === 404) {
- console.error('Sandbox not found');
- process.exit(1);
- }
- if (res.status === 401) {
- clearApiKey();
- console.error("Unauthorized. Try 'cua login' again.");
- process.exit(1);
- }
- console.error(`Unexpected status: ${res.status}`);
+ 'Stop a sandbox',
+ (y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
+ async (argv: Record<string, unknown>) => {
+ const token = await ensureApiKeyInteractive();
+ const name = String((argv as any).name);
+ const res = await http(`/v1/vms/${encodeURIComponent(name)}/stop`, {
+ token,
+ method: 'POST',
+ });
+ if (res.status === 202) {
+ const body = (await res.json().catch(() => ({}))) as {
+ status?: string;
+ };
+ console.log(body.status ?? 'stopping');
+ return;
+ }
+ if (res.status === 404) {
+ console.error('Sandbox not found');
process.exit(1);
}
- )
+ if (res.status === 401) {
+ clearApiKey();
+ console.error("Unauthorized. Try 'cua login' again.");
+ process.exit(1);
+ }
+ console.error(`Unexpected status: ${res.status}`);
+ process.exit(1);
+ }
+ )
.command(
'restart <name>',
- 'Restart a sandbox',
- (y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
- async (argv: Record<string, unknown>) => {
- const token = await ensureApiKeyInteractive();
- const name = String((argv as any).name);
- const res = await http(
- `/v1/vms/${encodeURIComponent(name)}/restart`,
- {
- token,
- method: 'POST',
- }
- );
- if (res.status === 202) {
- const body = (await res.json().catch(() => ({}))) as {
- status?: string;
- };
- console.log(body.status ?? 'restarting');
- return;
- }
- if (res.status === 404) {
- console.error('Sandbox not found');
- process.exit(1);
- }
- if (res.status === 401) {
- clearApiKey();
- console.error("Unauthorized. Try 'cua login' again.");
- process.exit(1);
- }
- console.error(`Unexpected status: ${res.status}`);
+ 'Restart a sandbox',
+ (y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
+ async (argv: Record<string, unknown>) => {
+ const token = await ensureApiKeyInteractive();
+ const name = String((argv as any).name);
+ const res = await http(`/v1/vms/${encodeURIComponent(name)}/restart`, {
+ token,
+ method: 'POST',
+ });
+ if (res.status === 202) {
+ const body = (await res.json().catch(() => ({}))) as {
+ status?: string;
+ };
+ console.log(body.status ?? 'restarting');
+ return;
+ }
+ if (res.status === 404) {
+ console.error('Sandbox not found');
+ process.exit(1);
+ }
+ if (res.status === 401) {
+ clearApiKey();
+ console.error("Unauthorized. Try 'cua login' again.");
process.exit(1);
}
- )
+ console.error(`Unexpected status: ${res.status}`);
+ process.exit(1);
+ }
+ )
.command(
'open <name>',
'Open NoVNC for a sandbox in your browser',
- (y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
- async (argv: Record<string, unknown>) => {
- const token = await ensureApiKeyInteractive();
- const name = String((argv as any).name);
- const listRes = await http('/v1/vms', { token });
- if (listRes.status === 401) {
- clearApiKey();
- console.error("Unauthorized. Try 'cua login' again.");
- process.exit(1);
- }
- if (!listRes.ok) {
- console.error(`Request failed: ${listRes.status}`);
- process.exit(1);
- }
- const vms = (await listRes.json()) as VmItem[];
- const vm = vms.find((v) => v.name === name);
- if (!vm) {
- console.error('Sandbox not found');
- process.exit(1);
- }
- const host =
- vm.host && vm.host.length
- ? vm.host
- : `${vm.name}.containers.cloud.trycua.com`;
- const url = `https://${host}/vnc.html?autoconnect=true&password=${encodeURIComponent(vm.password)}`;
- console.log(`Opening NoVNC: ${url}`);
- await openInBrowser(url);
+ (y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
+ async (argv: Record<string, unknown>) => {
+ const token = await ensureApiKeyInteractive();
+ const name = String((argv as any).name);
+ const listRes = await http('/v1/vms', { token });
+ if (listRes.status === 401) {
+ clearApiKey();
+ console.error("Unauthorized. Try 'cua login' again.");
+ process.exit(1);
}
- )
- // .command(
- // 'chat <name>',
- // 'Open CUA playground for a sandbox',
- // (y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
- // async (argv: Record<string, unknown>) => {
- // const token = await ensureApiKeyInteractive();
- // const name = String((argv as any).name);
- // const listRes = await http('/v1/vms', { token });
- // if (listRes.status === 401) {
- // clearApiKey();
- // console.error("Unauthorized. Try 'cua login' again.");
- // process.exit(1);
- // }
- // if (!listRes.ok) {
- // console.error(`Request failed: ${listRes.status}`);
- // process.exit(1);
- // }
- // const vms = (await listRes.json()) as VmItem[];
- // const vm = vms.find((v) => v.name === name);
- // if (!vm) {
- // console.error('Sandbox not found');
- // process.exit(1);
- // }
- // const host =
- // vm.host && vm.host.length
- // ? vm.host
- // : `${vm.name}.containers.cloud.trycua.com`;
- // const base = WEBSITE_URL.replace(/\/$/, '');
- // const url = `${base}/dashboard/playground?host=${encodeURIComponent(host)}&id=${encodeURIComponent(vm.name)}&name=${encodeURIComponent(vm.name)}&vnc_password=${encodeURIComponent(vm.password)}&fullscreen=true`;
- // console.log(`Opening Playground: ${url}`);
- // await openInBrowser(url);
- // }
- // );
+ if (!listRes.ok) {
+ console.error(`Request failed: ${listRes.status}`);
+ process.exit(1);
+ }
+ const vms = (await listRes.json()) as VmItem[];
+ const vm = vms.find((v) => v.name === name);
+ if (!vm) {
+ console.error('Sandbox not found');
+ process.exit(1);
+ }
+ const host =
+ vm.host && vm.host.length
+ ? vm.host
+ : `${vm.name}.containers.cloud.trycua.com`;
+ const url = `https://${host}/vnc.html?autoconnect=true&password=${encodeURIComponent(vm.password)}`;
+ console.log(`Opening NoVNC: ${url}`);
+ await openInBrowser(url);
+ }
+ );
+ // .command(
+ // 'chat <name>',
+ // 'Open CUA playground for a sandbox',
+ // (y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
+ // async (argv: Record<string, unknown>) => {
+ // const token = await ensureApiKeyInteractive();
+ // const name = String((argv as any).name);
+ // const listRes = await http('/v1/vms', { token });
+ // if (listRes.status === 401) {
+ // clearApiKey();
+ // console.error("Unauthorized. Try 'cua login' again.");
+ // process.exit(1);
+ // }
+ // if (!listRes.ok) {
+ // console.error(`Request failed: ${listRes.status}`);
+ // process.exit(1);
+ // }
+ // const vms = (await listRes.json()) as VmItem[];
+ // const vm = vms.find((v) => v.name === name);
+ // if (!vm) {
+ // console.error('Sandbox not found');
+ // process.exit(1);
+ // }
+ // const host =
+ // vm.host && vm.host.length
+ // ? vm.host
+ // : `${vm.name}.containers.cloud.trycua.com`;
+ // const base = WEBSITE_URL.replace(/\/$/, '');
+ // const url = `${base}/dashboard/playground?host=${encodeURIComponent(host)}&id=${encodeURIComponent(vm.name)}&name=${encodeURIComponent(vm.name)}&vnc_password=${encodeURIComponent(vm.password)}&fullscreen=true`;
+ // console.log(`Opening Playground: ${url}`);
+ // await openInBrowser(url);
+ // }
+ // );
}
diff --git a/libs/typescript/cua-cli/src/util.ts b/libs/typescript/cua-cli/src/util.ts
index 9992adc0cd..da259434ad 100644
--- a/libs/typescript/cua-cli/src/util.ts
+++ b/libs/typescript/cua-cli/src/util.ts
@@ -26,28 +26,29 @@ export type VmItem = {
};
export function printVmList(items: VmItem[], showPasswords: boolean = false) {
- const headers = showPasswords
+ const headers = showPasswords
? ['NAME', 'STATUS', 'PASSWORD', 'HOST']
: ['NAME', 'STATUS', 'HOST'];
-
+
const rows: string[][] = [
headers,
- ...items.map((v) => showPasswords
- ? [v.name, String(v.status), v.password, v.host || '']
- : [v.name, String(v.status), v.host || '']
+ ...items.map((v) =>
+ showPasswords
+ ? [v.name, String(v.status), v.password, v.host || '']
+ : [v.name, String(v.status), v.host || '']
),
];
-
+
const numCols = headers.length;
const widths: number[] = new Array(numCols).fill(0);
-
+
for (const r of rows)
for (let i = 0; i < numCols; i++)
widths[i] = Math.max(widths[i] ?? 0, (r[i] ?? '').length);
-
+
for (const r of rows)
console.log(r.map((c, i) => (c ?? '').padEnd(widths[i] ?? 0)).join(' '));
-
+
if (items.length === 0) console.log('No VMs found');
}