Skip to content

Commit dd42408

Browse files
committed
cleanup
1 parent 5847acd commit dd42408

File tree

2 files changed

+17
-31
lines changed

2 files changed

+17
-31
lines changed

examples/stream.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const browseruse = new BrowserUseClient({
1818
async function basic() {
1919
console.log("Basic: Creating task and starting stream...");
2020

21-
// Create a task and get the stream
2221
const task = await browseruse.tasks.createTask({
2322
task: "What's the weather in SF and what's the temperature?",
2423
agent: { llm: "gemini-2.5-flash" },
@@ -29,9 +28,9 @@ async function basic() {
2928
}
3029

3130
const result = await task.complete();
32-
console.log(result);
3331

34-
console.log("\nBasic: Stream completed");
32+
console.log("Basic: Stream completed");
33+
console.log(result.output);
3534
}
3635

3736
// Structured ----------------------------------------------------------------
@@ -48,9 +47,8 @@ const TaskOutput = z.object({
4847
});
4948

5049
async function structured() {
51-
console.log("Structured: Creating task and starting stream...\n");
50+
console.log("Structured: Creating task and starting stream...");
5251

53-
// Create a task and get the stream
5452
const task = await browseruse.tasks.createTask({
5553
task: "Extract top 10 Hacker News posts and return the title, url, and score",
5654
schema: TaskOutput,
@@ -62,9 +60,12 @@ async function structured() {
6260
}
6361

6462
const result = await task.complete();
65-
console.log(result);
6663

67-
console.log("\nStructured: Stream completed");
64+
console.log("Structured: Stream completed");
65+
66+
for (const post of result.parsed!.posts) {
67+
console.log(` - ${post.title} (${post.score}) ${post.url}`);
68+
}
6869
}
6970

7071
basic()

examples/watch.ts

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,22 @@ const browseruse = new BrowserUseClient({
1616
// Basic ---------------------------------------------------------------------
1717

1818
async function basic() {
19-
console.log("Basic: Creating task and starting stream...");
19+
console.log("Basic: Creating task and starting watch...");
2020

21-
// Create a task and get the stream
2221
const task = await browseruse.tasks.createTask({
2322
task: "What's the weather in SF and what's the temperature?",
2423
agent: { llm: "gemini-2.5-flash" },
2524
});
2625

2726
for await (const msg of task.watch()) {
28-
console.log(
29-
`Basic: ${msg.data.status} ${msg.data.sessionId} ${msg.data.steps[msg.data.steps.length - 1]?.nextGoal}`,
30-
);
27+
console.log(msg);
3128

3229
if (msg.data.status === "finished") {
33-
console.log(`Basic: ${msg.data.output}`);
30+
console.log(`OUTPUT: ${msg.data.output}`);
3431
}
3532
}
3633

37-
console.log("\nBasic: Stream completed");
34+
console.log("Watch completed");
3835
}
3936

4037
// Structured ----------------------------------------------------------------
@@ -51,40 +48,28 @@ const TaskOutput = z.object({
5148
});
5249

5350
async function structured() {
54-
console.log("Structured: Creating task and starting stream...\n");
51+
console.log("Structured: Creating task and starting watch...\n");
5552

56-
// Create a task and get the stream
5753
const task = await browseruse.tasks.createTask({
5854
task: "Extract top 10 Hacker News posts and return the title, url, and score",
5955
schema: TaskOutput,
6056
agent: { llm: "gpt-4.1" },
6157
});
6258

6359
for await (const msg of task.watch()) {
64-
// Regular
65-
process.stdout.write(`Structured: ${msg.data.status}`);
66-
if (msg.data.sessionId) {
67-
process.stdout.write(` | Live URL: ${msg.data.sessionId}`);
68-
}
69-
70-
if (msg.data.steps.length > 0) {
71-
const latestStep = msg.data.steps[msg.data.steps.length - 1];
72-
process.stdout.write(` | ${latestStep!.nextGoal}`);
73-
}
74-
75-
process.stdout.write("\n");
60+
console.log(msg);
7661

7762
// Output
7863
if (msg.data.status === "finished") {
79-
process.stdout.write(`\n\nOUTPUT:`);
64+
console.log(`OUTPUT:`);
8065

8166
for (const post of msg.data.parsed!.posts) {
82-
process.stdout.write(`\n - ${post.title} (${post.score}) ${post.url}`);
67+
console.log(` - ${post.title} (${post.score}) ${post.url}`);
8368
}
8469
}
8570
}
8671

87-
console.log("\nStructured: Stream completed");
72+
console.log("\nStructured: Watch completed");
8873
}
8974

9075
basic()

0 commit comments

Comments
 (0)