browser-use-sdk 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/client.d.mts +2 -2
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +2 -2
  5. package/client.d.ts.map +1 -1
  6. package/client.js.map +1 -1
  7. package/client.mjs.map +1 -1
  8. package/internal/detect-platform.js +1 -1
  9. package/internal/detect-platform.js.map +1 -1
  10. package/internal/detect-platform.mjs +1 -1
  11. package/internal/detect-platform.mjs.map +1 -1
  12. package/lib/bin/auth.d.mts +10 -0
  13. package/lib/bin/auth.d.mts.map +1 -0
  14. package/lib/bin/auth.d.ts +10 -0
  15. package/lib/bin/auth.d.ts.map +1 -0
  16. package/lib/bin/auth.js +52 -0
  17. package/lib/bin/auth.js.map +1 -0
  18. package/lib/bin/auth.mjs +47 -0
  19. package/lib/bin/auth.mjs.map +1 -0
  20. package/lib/bin/cli.d.mts +3 -0
  21. package/lib/bin/cli.d.mts.map +1 -0
  22. package/lib/bin/cli.d.ts +3 -0
  23. package/lib/bin/cli.d.ts.map +1 -0
  24. package/lib/bin/cli.js +12 -0
  25. package/lib/bin/cli.js.map +1 -0
  26. package/lib/bin/cli.mjs +10 -0
  27. package/lib/bin/cli.mjs.map +1 -0
  28. package/lib/bin/commands/listen.d.mts +3 -0
  29. package/lib/bin/commands/listen.d.mts.map +1 -0
  30. package/lib/bin/commands/listen.d.ts +3 -0
  31. package/lib/bin/commands/listen.d.ts.map +1 -0
  32. package/lib/bin/commands/listen.js +120 -0
  33. package/lib/bin/commands/listen.js.map +1 -0
  34. package/lib/bin/commands/listen.mjs +117 -0
  35. package/lib/bin/commands/listen.mjs.map +1 -0
  36. package/lib/stream.d.mts.map +1 -1
  37. package/lib/stream.d.ts.map +1 -1
  38. package/lib/stream.js +6 -3
  39. package/lib/stream.js.map +1 -1
  40. package/lib/stream.mjs +6 -3
  41. package/lib/stream.mjs.map +1 -1
  42. package/lib/webhooks.d.mts +73 -0
  43. package/lib/webhooks.d.mts.map +1 -0
  44. package/lib/webhooks.d.ts +73 -0
  45. package/lib/webhooks.d.ts.map +1 -0
  46. package/lib/webhooks.js +84 -0
  47. package/lib/webhooks.js.map +1 -0
  48. package/lib/webhooks.mjs +78 -0
  49. package/lib/webhooks.mjs.map +1 -0
  50. package/package.json +9 -2
  51. package/resources/index.d.mts +1 -1
  52. package/resources/index.d.mts.map +1 -1
  53. package/resources/index.d.ts +1 -1
  54. package/resources/index.d.ts.map +1 -1
  55. package/resources/index.js.map +1 -1
  56. package/resources/index.mjs.map +1 -1
  57. package/resources/sessions/index.d.mts +1 -1
  58. package/resources/sessions/index.d.mts.map +1 -1
  59. package/resources/sessions/index.d.ts +1 -1
  60. package/resources/sessions/index.d.ts.map +1 -1
  61. package/resources/sessions/index.js.map +1 -1
  62. package/resources/sessions/index.mjs.map +1 -1
  63. package/resources/sessions/sessions.d.mts +2 -8
  64. package/resources/sessions/sessions.d.mts.map +1 -1
  65. package/resources/sessions/sessions.d.ts +2 -8
  66. package/resources/sessions/sessions.d.ts.map +1 -1
  67. package/resources/sessions/sessions.js +2 -2
  68. package/resources/sessions/sessions.js.map +1 -1
  69. package/resources/sessions/sessions.mjs +2 -2
  70. package/resources/sessions/sessions.mjs.map +1 -1
  71. package/resources/tasks.d.mts +57 -27
  72. package/resources/tasks.d.mts.map +1 -1
  73. package/resources/tasks.d.ts +57 -27
  74. package/resources/tasks.d.ts.map +1 -1
  75. package/src/client.ts +2 -2
  76. package/src/internal/detect-platform.ts +1 -1
  77. package/src/lib/bin/auth.ts +63 -0
  78. package/src/lib/bin/cli.ts +11 -0
  79. package/src/lib/bin/commands/listen.ts +158 -0
  80. package/src/lib/stream.ts +6 -3
  81. package/src/lib/webhooks.ts +118 -0
  82. package/src/resources/index.ts +0 -1
  83. package/src/resources/sessions/index.ts +0 -1
  84. package/src/resources/sessions/sessions.ts +2 -16
  85. package/src/resources/tasks.ts +66 -34
  86. package/src/version.ts +1 -1
  87. package/version.d.mts +1 -1
  88. package/version.d.ts +1 -1
  89. package/version.js +1 -1
  90. package/version.mjs +1 -1
@@ -250,18 +250,18 @@ export type LlmModel = 'gpt-4o' | 'gpt-4o-mini' | 'gpt-4.1' | 'gpt-4.1-mini' | '
250
250
  * View model for representing a task with its execution details
251
251
  *
252
252
  * Attributes: id: Unique identifier for the task session_id: ID of the session
253
- * this task belongs to session_live_url: Optional live URL of the session llm: The
254
- * LLM model used for this task task: The task prompt/instruction given to the
255
- * agent status: Current status of the task execution started_at: Naive UTC
256
- * timestamp when the task was started finished_at: Naive UTC timestamp when the
257
- * task completed (None if still running) metadata: Optional additional metadata
258
- * associated with the task set by the user is_scheduled: Whether this task was
259
- * created as a scheduled task steps: Optional list of execution steps done_output:
260
- * Final output/result of the task user_uploaded_files: Optional list of files
261
- * uploaded by user for this task output_files: Optional list of files generated as
262
- * output by this task browser_use_version: Version of browser-use used for this
263
- * task (older tasks may not have this set) is_success: Whether the task was
264
- * successful (self-reported by the agent)
253
+ * this task belongs to llm: The LLM model used for this task task: The task
254
+ * prompt/instruction given to the agent status: Current status of the task
255
+ * execution started_at: Naive UTC timestamp when the task was started finished_at:
256
+ * Naive UTC timestamp when the task completed (None if still running) metadata:
257
+ * Optional additional metadata associated with the task set by the user
258
+ * is_scheduled: Whether this task was created as a scheduled task steps: Optional
259
+ * list of execution steps done_output: Final output/result of the task
260
+ * user_uploaded_files: Optional list of files uploaded by user for this task
261
+ * output_files: Optional list of files generated as output by this task
262
+ * browser_use_version: Version of browser-use used for this task (older tasks may
263
+ * not have this set) is_success: Whether the task was successful (self-reported by
264
+ * the agent)
265
265
  */
266
266
  export interface TaskItemView {
267
267
  id: string;
@@ -285,10 +285,6 @@ export interface TaskItemView {
285
285
  metadata?: {
286
286
  [key: string]: unknown;
287
287
  };
288
- outputFiles?: Array<FileView> | null;
289
- sessionLiveUrl?: string | null;
290
- steps?: Array<TaskStepView> | null;
291
- userUploadedFiles?: Array<FileView> | null;
292
288
  }
293
289
  /**
294
290
  * Enumeration of possible task execution states
@@ -321,11 +317,11 @@ export interface TaskStepView {
321
317
  * View model for representing a task with its execution details
322
318
  *
323
319
  * Attributes: id: Unique identifier for the task session_id: ID of the session
324
- * this task belongs to session_live_url: Optional live URL of the session llm: The
325
- * LLM model used for this task task: The task prompt/instruction given to the
326
- * agent status: Current status of the task execution started_at: Naive UTC
327
- * timestamp when the task was started finished_at: Naive UTC timestamp when the
328
- * task completed (None if still running) metadata: Optional additional metadata
320
+ * this task belongs to session: The session this task belongs to llm: The LLM
321
+ * model used for this task task: The task prompt/instruction given to the agent
322
+ * status: Current status of the task execution started_at: Naive UTC timestamp
323
+ * when the task was started finished_at: Naive UTC timestamp when the task
324
+ * completed (None if still running) metadata: Optional additional metadata
329
325
  * associated with the task set by the user is_scheduled: Whether this task was
330
326
  * created as a scheduled task steps: List of execution steps done_output: Final
331
327
  * output/result of the task user_uploaded_files: List of files uploaded by user
@@ -339,6 +335,15 @@ export interface TaskView {
339
335
  isScheduled: boolean;
340
336
  llm: LlmModel;
341
337
  outputFiles: Array<FileView>;
338
+ /**
339
+ * View model for representing a session that a task belongs to
340
+ *
341
+ * Attributes: id: Unique identifier for the session status: Current status of the
342
+ * session live_url: URL where the browser can be viewed live in real-time.
343
+ * started_at: Timestamp when the session was created and started. finished_at:
344
+ * Timestamp when the session was stopped (None if still active).
345
+ */
346
+ session: TaskView.Session;
342
347
  sessionId: string;
343
348
  startedAt: string;
344
349
  /**
@@ -359,7 +364,29 @@ export interface TaskView {
359
364
  metadata?: {
360
365
  [key: string]: unknown;
361
366
  };
362
- sessionLiveUrl?: string | null;
367
+ }
368
+ export declare namespace TaskView {
369
+ /**
370
+ * View model for representing a session that a task belongs to
371
+ *
372
+ * Attributes: id: Unique identifier for the session status: Current status of the
373
+ * session live_url: URL where the browser can be viewed live in real-time.
374
+ * started_at: Timestamp when the session was created and started. finished_at:
375
+ * Timestamp when the session was stopped (None if still active).
376
+ */
377
+ interface Session {
378
+ id: string;
379
+ startedAt: string;
380
+ /**
381
+ * Enumeration of possible (browser) session states
382
+ *
383
+ * Attributes: ACTIVE: Session is currently active and running (browser is running)
384
+ * STOPPED: Session has been stopped and is no longer active (browser is stopped)
385
+ */
386
+ status: 'active' | 'stopped';
387
+ finishedAt?: string | null;
388
+ liveUrl?: string | null;
389
+ }
363
390
  }
364
391
  /**
365
392
  * Response model for creating a task
@@ -393,18 +420,24 @@ export interface TaskGetLogsResponse {
393
420
  /**
394
421
  * Response model for output file requests
395
422
  *
396
- * Attributes: download_url: URL to download the output file
423
+ * Attributes: id: Unique identifier for the output file file_name: Name of the
424
+ * output file download_url: URL to download the output file
397
425
  */
398
426
  export interface TaskGetOutputFileResponse {
427
+ id: string;
399
428
  downloadUrl: string;
429
+ fileName: string;
400
430
  }
401
431
  /**
402
432
  * Response model for user uploaded file requests
403
433
  *
404
- * Attributes: download_url: URL to download the user uploaded file
434
+ * Attributes: id: Unique identifier for the user uploaded file file_name: Name of
435
+ * the user uploaded file download_url: URL to download the user uploaded file
405
436
  */
406
437
  export interface TaskGetUserUploadedFileResponse {
438
+ id: string;
407
439
  downloadUrl: string;
440
+ fileName: string;
408
441
  }
409
442
  export interface TaskCreateParams {
410
443
  task: string;
@@ -475,9 +508,6 @@ export interface TaskListParams {
475
508
  * UNSUCCESSFUL: All unsuccessful tasks
476
509
  */
477
510
  filterBy?: 'started' | 'paused' | 'stopped' | 'finished' | 'successful' | 'unsuccessful' | null;
478
- includeOutputFiles?: boolean;
479
- includeSteps?: boolean;
480
- includeUserUploadedFiles?: boolean;
481
511
  pageNumber?: number;
482
512
  pageSize?: number;
483
513
  sessionId?: string | null;
@@ -1 +1 @@
1
- {"version":3,"file":"tasks.d.ts","sourceRoot":"","sources":["../src/resources/tasks.ts"],"names":[],"mappings":"OAEO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK;OAE3B,EAAE,UAAU,EAAE;OACd,EAAE,W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;IACtC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,6BAA6B;IAC5C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,CAAC,OAAO,WAAW,KAAK,CAAC;IAC7B,OAAO,EACL,KAAK,QAAQ,IAAI,QAAQ,EACzB,KAAK,QAAQ,IAAI,QAAQ,EACzB,KAAK,YAAY,IAAI,YAAY,EACjC,KAAK,UAAU,IAAI,UAAU,EAC7B,KAAK,YAAY,IAAI,YAAY,EACjC,KAAK,QAAQ,IAAI,QAAQ,EACzB,KAAK,kBAAkB,IAAI,kBAAkB,EAC7C,KAAK,gBAAgB,IAAI,gBAAgB,EACzC,KAAK,mBAAmB,IAAI,mBAAmB,EAC/C,KAAK,yBAAyB,IAAI,yBAAyB,EAC3D,KAAK,+BAA+B,IAAI,+BAA+B,EACvE,KAAK,gBAAgB,IAAI,gBAAgB,EACzC,KAAK,gBAAgB,IAAI,gBAAgB,EACzC,KAAK,cAAc,IAAI,cAAc,EACrC,KAAK,uBAAuB,IAAI,uBAAuB,EACvD,KAAK,6BAA6B,IAAI,6BAA6B,GACpE,CAAC;CACH"}
package/src/client.ts CHANGED
@@ -55,7 +55,6 @@ import {
55
55
  import {
56
56
  SessionListParams,
57
57
  SessionListResponse,
58
- SessionRetrieveParams,
59
58
  SessionStatus,
60
59
  SessionUpdateParams,
61
60
  SessionView,
@@ -765,11 +764,13 @@ export class BrowserUse {
765
764
  browserProfiles: API.BrowserProfiles = new API.BrowserProfiles(this);
766
765
  agentProfiles: API.AgentProfiles = new API.AgentProfiles(this);
767
766
  }
767
+
768
768
  BrowserUse.Users = Users;
769
769
  BrowserUse.Tasks = Tasks;
770
770
  BrowserUse.Sessions = Sessions;
771
771
  BrowserUse.BrowserProfiles = BrowserProfiles;
772
772
  BrowserUse.AgentProfiles = AgentProfiles;
773
+
773
774
  export declare namespace BrowserUse {
774
775
  export type RequestOptions = Opts.RequestOptions;
775
776
 
@@ -800,7 +801,6 @@ export declare namespace BrowserUse {
800
801
  type SessionStatus as SessionStatus,
801
802
  type SessionView as SessionView,
802
803
  type SessionListResponse as SessionListResponse,
803
- type SessionRetrieveParams as SessionRetrieveParams,
804
804
  type SessionUpdateParams as SessionUpdateParams,
805
805
  type SessionListParams as SessionListParams,
806
806
  };
@@ -67,7 +67,7 @@ const getPlatformProperties = (): PlatformProperties => {
67
67
  'X-Stainless-Arch': normalizeArch(Deno.build.arch),
68
68
  'X-Stainless-Runtime': 'deno',
69
69
  'X-Stainless-Runtime-Version':
70
- typeof Deno.version === 'string' ? Deno.version : Deno.version?.deno ?? 'unknown',
70
+ typeof Deno.version === 'string' ? Deno.version : (Deno.version?.deno ?? 'unknown'),
71
71
  };
72
72
  }
73
73
  if (typeof EdgeRuntime !== 'undefined') {
@@ -0,0 +1,63 @@
1
+ import * as dotenv from '@dotenvx/dotenvx';
2
+
3
+ import { BrowserUse } from '../../';
4
+
5
+ const API_KEY_ENV_VAR_KEY = 'BROWSER_USE_API_KEY';
6
+
7
+ /**
8
+ * Creates a new BrowserUse client with the API key from the environment variable.
9
+ */
10
+ export function createBrowserUseClient() {
11
+ let apiKey: string | null = null;
12
+
13
+ if (process.env[API_KEY_ENV_VAR_KEY]) {
14
+ apiKey = process.env[API_KEY_ENV_VAR_KEY];
15
+ }
16
+
17
+ if (apiKey == null) {
18
+ const env = dotenv.config({ path: '.env' });
19
+
20
+ const envApiKey = env.parsed?.[API_KEY_ENV_VAR_KEY];
21
+
22
+ if (envApiKey) {
23
+ apiKey = envApiKey;
24
+ }
25
+ }
26
+
27
+ if (apiKey == null) {
28
+ console.error(`Missing ${API_KEY_ENV_VAR_KEY} environment variable!`);
29
+ process.exit(1);
30
+ }
31
+
32
+ return new BrowserUse({ apiKey });
33
+ }
34
+
35
+ const SECRET_ENV_VAR_KEY = 'SECRET_KEY';
36
+
37
+ /**
38
+ * Loads the Browser Use webhook secret from the environment variable.
39
+ */
40
+ export function getBrowserUseWebhookSecret() {
41
+ let secret: string | null = null;
42
+
43
+ if (process.env[SECRET_ENV_VAR_KEY]) {
44
+ secret = process.env[SECRET_ENV_VAR_KEY];
45
+ }
46
+
47
+ if (secret == null) {
48
+ const env = dotenv.config({ path: '.env' });
49
+
50
+ const envSecret = env.parsed?.[SECRET_ENV_VAR_KEY];
51
+
52
+ if (envSecret) {
53
+ secret = envSecret;
54
+ }
55
+ }
56
+
57
+ if (secret == null) {
58
+ console.error(`Missing ${SECRET_ENV_VAR_KEY} environment variable!`);
59
+ process.exit(1);
60
+ }
61
+
62
+ return secret;
63
+ }
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env -S npm run tsn -T
2
+
3
+ import { program } from 'commander';
4
+ import { listen } from './commands/listen';
5
+
6
+ program
7
+ .name('browser-use')
8
+ .description('CLI to some JavaScript string utilities')
9
+ .version('0.8.0')
10
+ .addCommand(listen)
11
+ .parse(process.argv);
@@ -0,0 +1,158 @@
1
+ import { Command } from 'commander';
2
+
3
+ import { BrowserUse } from '../../../';
4
+ import { createWebhookSignature, Webhook } from '../../webhooks';
5
+ import { createBrowserUseClient, getBrowserUseWebhookSecret } from '../auth';
6
+
7
+ // NOTE: We perform task list refresh to get all running tasks and then
8
+ const tickRef: {
9
+ timeout: NodeJS.Timeout | null;
10
+ abort: AbortController | null;
11
+ } = { timeout: null, abort: null };
12
+
13
+ export const listen = new Command('listen')
14
+ .description(`Open a local webhook to receive Cloud API updates from the CLI on your local machine.`)
15
+ .option('-d, --dev <endpoint>', 'The endpoint to forward updates to.')
16
+ .action(async (options) => {
17
+ // Auth
18
+
19
+ const client = createBrowserUseClient();
20
+ const secret = getBrowserUseWebhookSecret();
21
+
22
+ // Proxy
23
+
24
+ const { dev: localTargetEndpoint } = options;
25
+
26
+ if (typeof localTargetEndpoint !== 'string') {
27
+ // NOTE: This should never happen because the command is validated by commander.
28
+ throw new Error(
29
+ 'Something unexpected happened. Please report this issue. https://github.com/browser-use/browser-use-node/issues',
30
+ );
31
+ }
32
+
33
+ const localTargetURL = new URL(localTargetEndpoint);
34
+
35
+ //
36
+
37
+ const queue: { current: Webhook[] } = { current: [] };
38
+ const runs: Map<string, BrowserUse.TaskStatus> = new Map();
39
+
40
+ tickRef.timeout = setInterval(async () => {
41
+ // NOTE: On next tick, we abort the current abort controller.
42
+ if (tickRef.abort != null) {
43
+ tickRef.abort.abort();
44
+ }
45
+
46
+ const controller = new AbortController();
47
+
48
+ tickRef.abort = controller;
49
+
50
+ console.log(`[polling] ${new Date().toISOString()} `.padEnd(100, '='));
51
+
52
+ const tasks: BrowserUse.Tasks.TaskItemView[] = await client.tasks
53
+ .list(
54
+ { pageSize: 10 },
55
+ {
56
+ signal: tickRef.abort.signal,
57
+ },
58
+ )
59
+ .then((res) => res.items)
60
+ .catch((_) => []);
61
+
62
+ for (const task of tasks) {
63
+ const currentTaskStatus = runs.get(task.id);
64
+
65
+ const timestamp = task.finishedAt ? task.finishedAt : task.startedAt;
66
+
67
+ if (currentTaskStatus == null) {
68
+ // NOTE: The task is new and the CLI hasn't yet captured it in the current run.
69
+ queue.current.push({
70
+ type: 'agent.task.status_update',
71
+ timestamp,
72
+ payload: {
73
+ session_id: task.sessionId,
74
+ task_id: task.id,
75
+ status: task.status,
76
+ metadata: task.metadata,
77
+ },
78
+ });
79
+
80
+ runs.set(task.id, task.status);
81
+
82
+ continue;
83
+ } else {
84
+ // NOTE: CLI has registered the task in the registry and we need to compare.
85
+ if (task.status !== currentTaskStatus) {
86
+ queue.current.push({
87
+ type: 'agent.task.status_update',
88
+ timestamp,
89
+ payload: {
90
+ session_id: task.sessionId,
91
+ task_id: task.id,
92
+ status: task.status,
93
+ metadata: task.metadata,
94
+ },
95
+ });
96
+
97
+ runs.set(task.id, task.status);
98
+
99
+ continue;
100
+ }
101
+ }
102
+ }
103
+
104
+ if (queue.current.length === 0) {
105
+ return;
106
+ }
107
+
108
+ const promises = queue.current.map(async (update) => {
109
+ const body = JSON.stringify(update);
110
+
111
+ const signature = createWebhookSignature({
112
+ payload: update.payload,
113
+ timestamp: update.timestamp,
114
+ secret,
115
+ });
116
+
117
+ try {
118
+ const res = await fetch(localTargetURL, {
119
+ method: 'POST',
120
+ body,
121
+ headers: {
122
+ 'Content-Type': 'application/json',
123
+ // https://docs.browser-use.com/cloud/webhooks#implementing-webhook-verification
124
+ 'X-Browser-Use-Timestamp': update.timestamp,
125
+ 'X-Browser-Use-Signature': signature,
126
+ },
127
+
128
+ signal: controller.signal,
129
+ });
130
+
131
+ console.log(`[update] ${update.timestamp} ${update.type} ${res.status}`);
132
+
133
+ return { delivery: 'fulfilled', update, status: res.status };
134
+ } catch (err) {
135
+ console.log(`[update] ${update.timestamp} ${update.type} failed`);
136
+
137
+ return { delivery: 'rejected', update, error: err };
138
+ }
139
+ });
140
+
141
+ const delivery = await Promise.all(promises);
142
+
143
+ // NOTE: We preserve the rejected updates so we can retry them.
144
+ queue.current = delivery.filter((d) => d.delivery === 'rejected').map((d) => d.update);
145
+ }, 1_000);
146
+
147
+ console.log(`Listening in dev mode at: ${localTargetEndpoint}`);
148
+ });
149
+
150
+ process.on('SIGINT', () => {
151
+ if (tickRef.abort != null) {
152
+ tickRef.abort.abort();
153
+ }
154
+
155
+ if (tickRef.timeout) {
156
+ clearInterval(tickRef.timeout);
157
+ }
158
+ });
package/src/lib/stream.ts CHANGED
@@ -23,7 +23,7 @@ export function reducer(state: BrowserState, action: BrowserAction): [BrowserSta
23
23
  // INIT
24
24
 
25
25
  if (state == null) {
26
- const liveUrl = action.status.sessionLiveUrl ?? null;
26
+ const liveUrl = action.status.session.liveUrl ?? null;
27
27
  const doneOutput = action.status.doneOutput ?? null;
28
28
 
29
29
  const state: BrowserState = {
@@ -39,7 +39,7 @@ export function reducer(state: BrowserState, action: BrowserAction): [BrowserSta
39
39
 
40
40
  // UPDATE
41
41
 
42
- const liveUrl = action.status.sessionLiveUrl ?? state.liveUrl;
42
+ const liveUrl = action.status.session.liveUrl ?? state.liveUrl;
43
43
  const doneOutput = action.status.doneOutput ?? state.doneOutput;
44
44
 
45
45
  const steps: TaskStepView[] = [...state.steps];
@@ -68,7 +68,10 @@ export function reducer(state: BrowserState, action: BrowserAction): [BrowserSta
68
68
  const update: ReducerEvent = {
69
69
  ...action.status,
70
70
  steps: newState.steps,
71
- sessionLiveUrl: newState.liveUrl,
71
+ session: {
72
+ ...action.status.session,
73
+ liveUrl: newState.liveUrl,
74
+ },
72
75
  doneOutput: newState.doneOutput,
73
76
  };
74
77
 
@@ -0,0 +1,118 @@
1
+ import { createHmac } from 'crypto';
2
+ import { z } from 'zod';
3
+ import stringify from 'fast-json-stable-stringify';
4
+
5
+ // https://docs.browser-use.com/cloud/webhooks
6
+
7
+ //
8
+
9
+ export const zWebhookTimestamp = z.iso.datetime({ offset: true, local: true });
10
+
11
+ // test
12
+
13
+ export const zWebhookTestPayload = z.object({
14
+ test: z.literal('ok'),
15
+ });
16
+
17
+ export type WebhookTestPayload = z.infer<typeof zWebhookTestPayload>;
18
+
19
+ export const zWebhookTest = z.object({
20
+ type: z.literal('test'),
21
+ timestamp: z.iso.datetime({ offset: true }),
22
+ payload: zWebhookTestPayload,
23
+ });
24
+
25
+ // agent.task.status_update
26
+
27
+ export const zWebhookAgentTaskStatusUpdatePayloadMetadata = z.record(z.string(), z.unknown()).optional();
28
+
29
+ export const zWebhookAgentTaskStatusUpdatePayloadStatus = z.literal([
30
+ 'initializing',
31
+ 'started',
32
+ 'paused',
33
+ 'stopped',
34
+ 'finished',
35
+ ]);
36
+
37
+ export const zWebhookAgentTaskStatusUpdatePayload = z.object({
38
+ session_id: z.string(),
39
+ task_id: z.string(),
40
+ status: zWebhookAgentTaskStatusUpdatePayloadStatus,
41
+ metadata: zWebhookAgentTaskStatusUpdatePayloadMetadata,
42
+ });
43
+
44
+ export type WebhookAgentTaskStatusUpdatePayload = z.infer<typeof zWebhookAgentTaskStatusUpdatePayload>;
45
+
46
+ export const zWebhookAgentTaskStatusUpdate = z.object({
47
+ type: z.literal('agent.task.status_update'),
48
+ timestamp: zWebhookTimestamp,
49
+ payload: zWebhookAgentTaskStatusUpdatePayload,
50
+ });
51
+
52
+ //
53
+
54
+ export const zWebhookSchema = z.discriminatedUnion('type', [
55
+ //
56
+ zWebhookTest,
57
+ zWebhookAgentTaskStatusUpdate,
58
+ ]);
59
+
60
+ export type Webhook = z.infer<typeof zWebhookSchema>;
61
+
62
+ // Signature
63
+
64
+ /**
65
+ * Utility function that validates the received Webhook event/
66
+ */
67
+ export async function verifyWebhookEventSignature(
68
+ evt: {
69
+ evt: string;
70
+ signature: string;
71
+ timestamp: string;
72
+ },
73
+ cfg: { secret: string },
74
+ ): Promise<{ ok: true; event: Webhook } | { ok: false }> {
75
+ try {
76
+ const event = await zWebhookSchema.safeParseAsync(JSON.parse(evt.evt));
77
+
78
+ if (event.success === false) {
79
+ return { ok: false };
80
+ }
81
+
82
+ const signature = createWebhookSignature({
83
+ payload: event.data.payload,
84
+ timestamp: evt.timestamp,
85
+ secret: cfg.secret,
86
+ });
87
+
88
+ // Compare signatures using timing-safe comparison
89
+ if (evt.signature !== signature) {
90
+ return { ok: false };
91
+ }
92
+
93
+ return { ok: true, event: event.data };
94
+ } catch (err) {
95
+ console.error(err);
96
+ return { ok: false };
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Creates a webhook signature for the given payload, timestamp, and secret.
102
+ */
103
+ export function createWebhookSignature({
104
+ payload,
105
+ timestamp,
106
+ secret,
107
+ }: {
108
+ payload: unknown;
109
+ timestamp: string;
110
+ secret: string;
111
+ }): string {
112
+ const dump = stringify(payload);
113
+ const message = `${timestamp}.${dump}`;
114
+
115
+ const hmac = createHmac('sha256', secret);
116
+ hmac.update(message);
117
+ return hmac.digest('hex');
118
+ }
@@ -22,7 +22,6 @@ export {
22
22
  type SessionStatus,
23
23
  type SessionView,
24
24
  type SessionListResponse,
25
- type SessionRetrieveParams,
26
25
  type SessionUpdateParams,
27
26
  type SessionListParams,
28
27
  } from './sessions/sessions';
@@ -6,7 +6,6 @@ export {
6
6
  type SessionStatus,
7
7
  type SessionView,
8
8
  type SessionListResponse,
9
- type SessionRetrieveParams,
10
9
  type SessionUpdateParams,
11
10
  type SessionListParams,
12
11
  } from './sessions';
@@ -34,12 +34,8 @@ export class Sessions extends APIResource {
34
34
  *
35
35
  * - 404: If the user agent session doesn't exist
36
36
  */
37
- retrieve(
38
- sessionID: string,
39
- query: SessionRetrieveParams | null | undefined = {},
40
- options?: RequestOptions,
41
- ): APIPromise<SessionView> {
42
- return this._client.get(path`/sessions/${sessionID}`, { query, ...options });
37
+ retrieve(sessionID: string, options?: RequestOptions): APIPromise<SessionView> {
38
+ return this._client.get(path`/sessions/${sessionID}`, options);
43
39
  }
44
40
 
45
41
  /**
@@ -185,7 +181,6 @@ export namespace SessionListResponse {
185
181
  * session (active/stopped). live_url: URL where the browser can be viewed live in
186
182
  * real-time. started_at: Timestamp when the session was created and started.
187
183
  * finished_at: Timestamp when the session was stopped (None if still active).
188
- * tasks: Optional list of tasks associated with this session.
189
184
  */
190
185
  export interface Item {
191
186
  id: string;
@@ -203,15 +198,9 @@ export namespace SessionListResponse {
203
198
  finishedAt?: string | null;
204
199
 
205
200
  liveUrl?: string | null;
206
-
207
- tasks?: Array<TasksAPI.TaskItemView> | null;
208
201
  }
209
202
  }
210
203
 
211
- export interface SessionRetrieveParams {
212
- includeTasks?: boolean;
213
- }
214
-
215
204
  export interface SessionUpdateParams {
216
205
  /**
217
206
  * Available actions that can be performed on a session
@@ -231,8 +220,6 @@ export interface SessionListParams {
231
220
  */
232
221
  filterBy?: SessionStatus | null;
233
222
 
234
- includeTasks?: boolean;
235
-
236
223
  pageNumber?: number;
237
224
 
238
225
  pageSize?: number;
@@ -245,7 +232,6 @@ export declare namespace Sessions {
245
232
  type SessionStatus as SessionStatus,
246
233
  type SessionView as SessionView,
247
234
  type SessionListResponse as SessionListResponse,
248
- type SessionRetrieveParams as SessionRetrieveParams,
249
235
  type SessionUpdateParams as SessionUpdateParams,
250
236
  type SessionListParams as SessionListParams,
251
237
  };