@@ -16,25 +16,22 @@ const browseruse = new BrowserUseClient({
16
16
// Basic ---------------------------------------------------------------------
17
17
18
18
async function basic ( ) {
19
- console . log ( "Basic: Creating task and starting stream ..." ) ;
19
+ console . log ( "Basic: Creating task and starting watch ..." ) ;
20
20
21
- // Create a task and get the stream
22
21
const task = await browseruse . tasks . createTask ( {
23
22
task : "What's the weather in SF and what's the temperature?" ,
24
23
agent : { llm : "gemini-2.5-flash" } ,
25
24
} ) ;
26
25
27
26
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 ) ;
31
28
32
29
if ( msg . data . status === "finished" ) {
33
- console . log ( `Basic : ${ msg . data . output } ` ) ;
30
+ console . log ( `OUTPUT : ${ msg . data . output } ` ) ;
34
31
}
35
32
}
36
33
37
- console . log ( "\nBasic: Stream completed" ) ;
34
+ console . log ( "Watch completed" ) ;
38
35
}
39
36
40
37
// Structured ----------------------------------------------------------------
@@ -51,40 +48,28 @@ const TaskOutput = z.object({
51
48
} ) ;
52
49
53
50
async function structured ( ) {
54
- console . log ( "Structured: Creating task and starting stream ...\n" ) ;
51
+ console . log ( "Structured: Creating task and starting watch ...\n" ) ;
55
52
56
- // Create a task and get the stream
57
53
const task = await browseruse . tasks . createTask ( {
58
54
task : "Extract top 10 Hacker News posts and return the title, url, and score" ,
59
55
schema : TaskOutput ,
60
56
agent : { llm : "gpt-4.1" } ,
61
57
} ) ;
62
58
63
59
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 ) ;
76
61
77
62
// Output
78
63
if ( msg . data . status === "finished" ) {
79
- process . stdout . write ( `\n\nOUTPUT :`) ;
64
+ console . log ( `OUTPUT :`) ;
80
65
81
66
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 } `) ;
83
68
}
84
69
}
85
70
}
86
71
87
- console . log ( "\nStructured: Stream completed" ) ;
72
+ console . log ( "\nStructured: Watch completed" ) ;
88
73
}
89
74
90
75
basic ( )
0 commit comments