Merge pull request #579 from sarinali/feat/new-usecase-connections-extraction

Post Event Contact Usecase
This commit is contained in:
Sarina Li
2025-11-16 18:55:09 -05:00
committed by GitHub
5 changed files with 1805 additions and 281 deletions

View File

@@ -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 }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -1,5 +1,5 @@
{
"title": "Cookbook",
"description": "Real-world examples of building with Cua",
"pages": ["form-filling"]
"pages": ["form-filling", "post-event-contact-export"]
}

File diff suppressed because it is too large Load Diff

View File

@@ -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;
};
'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 },
});
const res = await http('/v1/vms', {
token,
method: 'POST',
body: { os, configuration, region },
});
if (res.status === 401) {
clearApiKey();
console.error("Unauthorized. Try 'cua login' again.");
process.exit(1);
}
if (res.status === 400) {
console.error('Invalid request or unsupported configuration');
process.exit(1);
}
if (res.status === 500) {
console.error('Internal server error');
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 === 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}`);
if (res.status === 401) {
clearApiKey();
console.error("Unauthorized. Try 'cua login' again.");
process.exit(1);
}
)
if (res.status === 400) {
console.error('Invalid request or unsupported configuration');
process.exit(1);
}
if (res.status === 500) {
console.error('Internal server error');
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 === 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',
});
'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;
}
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 === 404) {
console.error('Sandbox not found or not owned by you');
process.exit(1);
}
if (res.status === 401) {
clearApiKey();
console.error("Unauthorized. Try 'cua login' again.");
process.exit(1);
}
console.error(`Unexpected status: ${res.status}`);
if (res.status === 404) {
console.error('Sandbox not found or not owned by you');
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(
'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);
// }
// );
}

View File

@@ -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');
}