import { BrowserUse } from "browser-use-sdk/v3";
import * as readline from "readline";
const client = new BrowserUse();
// 1. Create a persistent session
const session = await client.sessions.create({ keepAlive: true });
console.log(`Live view: ${session.liveUrl}`);
// 2. Agent does the first part
const searchResult = await client.run(
"Go to Google Flights and search for flights from NYC to London",
{ sessionId: session.id },
);
console.log(searchResult.output);
// 3. Human opens liveUrl and picks a flight
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
await new Promise((resolve) =>
rl.question("Press Enter after you've selected a flight in the live view...", resolve),
);
rl.close();
// 4. Agent continues where the human left off
const result = await client.run(
"Get the details of the selected flight — airline, price, departure and arrival times",
{ sessionId: session.id },
);
console.log(result.output);
// Clean up
await client.sessions.stop(session.id);