Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.2.2"
".": "0.3.0"
}
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 26
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browser-use%2Fbrowser-use-9ff5409663c58ae9e3ecc9ac764956189e3a70600f5ba1b961bb1dedf0208271.yml
openapi_spec_hash: 9865acb75430d9b799502acbae860df0
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browser-use%2Fbrowser-use-d20f308ac3a63b1ea5749dac763fd846481c9723156a5653c1d03669e73d5b5e.yml
openapi_spec_hash: ccf5babfe92a776213a3e5097a7cd546
config_hash: 9d52be5177b2ede4cb0633c04f4cc4ef
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 0.3.0 (2025-08-15)

Full Changelog: [v0.2.2...v0.3.0](https://github.com/browser-use/browser-use-node/compare/v0.2.2...v0.3.0)

### Features

* Fix Stainless GitHub Action ([16f3e7f](https://github.com/browser-use/browser-use-node/commit/16f3e7f6a43c5f29c81543624ca56cfd72b8e0cf))

## 0.2.2 (2025-08-15)

Full Changelog: [v0.2.1...v0.2.2](https://github.com/browser-use/browser-use-node/compare/v0.2.1...v0.2.2)
Expand Down
3 changes: 2 additions & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ Types:
- <code><a href="./src/resources/tasks.ts">TaskStatus</a></code>
- <code><a href="./src/resources/tasks.ts">TaskStepView</a></code>
- <code><a href="./src/resources/tasks.ts">TaskView</a></code>
- <code><a href="./src/resources/tasks.ts">TaskCreateResponse</a></code>
- <code><a href="./src/resources/tasks.ts">TaskListResponse</a></code>
- <code><a href="./src/resources/tasks.ts">TaskGetLogsResponse</a></code>
- <code><a href="./src/resources/tasks.ts">TaskGetOutputFileResponse</a></code>
- <code><a href="./src/resources/tasks.ts">TaskGetUserUploadedFileResponse</a></code>

Methods:

- <code title="post /tasks">client.tasks.<a href="./src/resources/tasks.ts">create</a>({ ...params }) -> TaskView</code>
- <code title="post /tasks">client.tasks.<a href="./src/resources/tasks.ts">create</a>({ ...params }) -> TaskCreateResponse</code>
- <code title="get /tasks/{task_id}">client.tasks.<a href="./src/resources/tasks.ts">retrieve</a>(taskID) -> TaskView</code>
- <code title="patch /tasks/{task_id}">client.tasks.<a href="./src/resources/tasks.ts">update</a>(taskID, { ...params }) -> TaskView</code>
- <code title="get /tasks">client.tasks.<a href="./src/resources/tasks.ts">list</a>({ ...params }) -> TaskListResponse</code>
Expand Down
7 changes: 6 additions & 1 deletion examples/stream-zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ async function main() {
console.log('Creating task and starting stream...\n');

// Create a task and get the stream
const stream = browseruse.tasks.stream({
const task = await browseruse.tasks.create({
task: 'Extract top 10 Hacker News posts and return the title, url, and score',
structuredOutputJson: TaskOutput,
});

const stream = browseruse.tasks.stream({
taskId: task.id,
schema: TaskOutput,
});

for await (const msg of stream) {
// Regular
process.stdout.write(`${msg.data.status}`);
Expand Down
4 changes: 3 additions & 1 deletion examples/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ async function main() {
console.log('Creating task and starting stream...');

// Create a task and get the stream
const gen = browseruse.tasks.stream({
const task = await browseruse.tasks.create({
task: 'What is the weather in San Francisco?',
});

const gen = browseruse.tasks.stream(task.id);

for await (const msg of gen) {
console.log(msg);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "browser-use-sdk",
"version": "0.2.2",
"version": "0.3.0",
"description": "The official TypeScript library for the Browser Use API",
"author": "Browser Use <[email protected]>",
"types": "dist/index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
FileView,
LlmModel,
TaskCreateParams,
TaskCreateResponse,
TaskGetLogsResponse,
TaskGetOutputFileParams,
TaskGetOutputFileResponse,
Expand Down Expand Up @@ -782,6 +783,7 @@ export declare namespace BrowserUse {
type TaskStatus as TaskStatus,
type TaskStepView as TaskStepView,
type TaskView as TaskView,
type TaskCreateResponse as TaskCreateResponse,
type TaskListResponse as TaskListResponse,
type TaskGetLogsResponse as TaskGetLogsResponse,
type TaskGetOutputFileResponse as TaskGetOutputFileResponse,
Expand Down
1 change: 1 addition & 0 deletions src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export {
type TaskStatus,
type TaskStepView,
type TaskView,
type TaskCreateResponse,
type TaskListResponse,
type TaskGetLogsResponse,
type TaskGetOutputFileResponse,
Expand Down
159 changes: 74 additions & 85 deletions src/resources/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class Tasks extends APIResource {
*
* Returns:
*
* - The created task with its initial details
* - The created task ID together with the task's session ID
*
* Raises:
*
Expand All @@ -65,34 +65,71 @@ export class Tasks extends APIResource {
create<T extends ZodType>(
body: TaskCreateParamsWithSchema<T>,
options?: RequestOptions,
): APIPromise<TaskViewWithSchema<T>>;
create(body: TaskCreateParams, options?: RequestOptions): APIPromise<TaskView>;
): APIPromise<TaskCreateResponse>;
create(body: TaskCreateParams, options?: RequestOptions): APIPromise<TaskCreateResponse>;
create(
body: TaskCreateParams | TaskCreateParamsWithSchema<ZodType>,
options?: RequestOptions,
): APIPromise<unknown> {
if (body.structuredOutputJson == null || typeof body.structuredOutputJson === 'string') {
return this._client.post('/tasks', { body, ...options });
}

if (typeof body.structuredOutputJson === 'object') {
): APIPromise<TaskCreateResponse> {
if (body.structuredOutputJson != null && typeof body.structuredOutputJson === 'object') {
const schema = body.structuredOutputJson;

const _body: TaskCreateParams = {
...body,
structuredOutputJson: stringifyStructuredOutput(schema),
};

return this._client
.post('/tasks', { body: _body, ...options })
._thenUnwrap((rsp) => parseStructuredTaskOutput(rsp as TaskView, schema));
return this._client.post('/tasks', { body: _body, ...options });
}

return this._client.post('/tasks', { body, ...options });
}

/**
* Get detailed information about a specific AI agent task.
*
* Retrieves comprehensive information about a task, including its current status,
* progress, and detailed execution data. You can choose to get just the status
* (for quick polling) or full details including steps and file information.
*
* Use this endpoint to:
*
* - Monitor task progress in real-time
* - Review completed task results
* - Debug failed tasks by examining steps
* - Download output files and logs
*
* Args:
*
* - task_id: The unique identifier of the agent task
*
* Returns:
*
* - Complete task information
*
* Raises:
*
* - 404: If the user agent task doesn't exist
*/
retrieve<T extends ZodType>(
req: { taskId: string; schema: T },
options?: RequestOptions,
): APIPromise<TaskViewWithSchema<T>>;
retrieve(taskID: string, options?: RequestOptions): APIPromise<TaskView>;
retrieve(req: string | { taskId: string; schema: ZodType }, options?: RequestOptions): APIPromise<unknown> {
if (typeof req === 'string') {
return this._client.get(path`/tasks/${req}`, options);
}

const { taskId, schema } = req;

return this._client
.get(path`/tasks/${taskId}`, options)
._thenUnwrap((rsp) => parseStructuredTaskOutput(rsp as TaskView, schema));
}

private async *watch(
data: TaskCreateParams,
taskId: string,
config: { interval: number },
options?: RequestOptions,
): AsyncGenerator<{ event: 'status'; data: TaskView }> {
Expand All @@ -106,14 +143,7 @@ export class Tasks extends APIResource {

tick.current++;

let status: TaskView;

// NOTE: We take action on each tick.
if (state.current == null) {
status = await this.create(data, options);
} else {
status = await this.retrieve(state.current.taskId);
}
const status = await this.retrieve(taskId);

const [newState, event] = reducer(state.current, { kind: 'status', status });

Expand All @@ -132,89 +162,35 @@ export class Tasks extends APIResource {
}

stream<T extends ZodType>(
body: TaskCreateParamsWithSchema<T>,
body: {
taskId: string;
schema: T;
},
options?: RequestOptions,
): AsyncGenerator<{ event: 'status'; data: TaskViewWithSchema<T> }>;
stream(
body: TaskCreateParams,
options?: RequestOptions,
): AsyncGenerator<{ event: 'status'; data: TaskView }>;
stream(taskId: string, options?: RequestOptions): AsyncGenerator<{ event: 'status'; data: TaskView }>;
async *stream(
body: TaskCreateParams | TaskCreateParamsWithSchema<ZodType>,
body: string | { taskId: string; schema: ZodType },
options?: RequestOptions,
): AsyncGenerator<unknown> {
let req: TaskCreateParams;

if (
'structuredOutputJson' in body &&
body.structuredOutputJson != null &&
typeof body.structuredOutputJson === 'object'
) {
req = {
...body,
structuredOutputJson: stringifyStructuredOutput(body.structuredOutputJson),
};
} else {
req = body as TaskCreateParams;
}
const taskId = typeof body === 'object' ? body.taskId : body;

for await (const msg of this.watch(req, { interval: 500 }, options)) {
for await (const msg of this.watch(taskId, { interval: 500 }, options)) {
if (options?.signal?.aborted) {
break;
}

if (body.structuredOutputJson != null && typeof body.structuredOutputJson === 'object') {
const parsed = parseStructuredTaskOutput<ZodType>(msg.data, body.structuredOutputJson);
if (typeof body === 'object') {
const parsed = parseStructuredTaskOutput<ZodType>(msg.data, body.schema);
yield { event: 'status', data: parsed };
} else {
yield { event: 'status', data: msg.data };
}
}
}

/**
* Get detailed information about a specific AI agent task.
*
* Retrieves comprehensive information about a task, including its current status,
* progress, and detailed execution data. You can choose to get just the status
* (for quick polling) or full details including steps and file information.
*
* Use this endpoint to:
*
* - Monitor task progress in real-time
* - Review completed task results
* - Debug failed tasks by examining steps
* - Download output files and logs
*
* Args:
*
* - task_id: The unique identifier of the agent task
*
* Returns:
*
* - Complete task information
*
* Raises:
*
* - 404: If the user agent task doesn't exist
*/
retrieve<T extends ZodType>(
req: { taskId: string; schema: T },
options?: RequestOptions,
): APIPromise<TaskViewWithSchema<T>>;
retrieve(taskID: string, options?: RequestOptions): APIPromise<TaskView>;
retrieve(req: string | { taskId: string; schema: ZodType }, options?: RequestOptions): APIPromise<unknown> {
if (typeof req === 'string') {
return this._client.get(path`/tasks/${req}`, options);
}

const { taskId, schema } = req;

return this._client
.get(path`/tasks/${taskId}`, options)
._thenUnwrap((rsp) => parseStructuredTaskOutput(rsp as TaskView, schema));
}

/**
* Control the execution of an AI agent task.
*
Expand Down Expand Up @@ -561,6 +537,18 @@ export interface TaskView {
sessionLiveUrl?: string | null;
}

/**
* Response model for creating a task
*
* Attributes: task_id: An unique identifier for the created task session_id: The
* ID of the session this task belongs to
*/
export interface TaskCreateResponse {
id: string;

sessionId: string;
}

/**
* Response model for paginated task list requests
*
Expand Down Expand Up @@ -711,6 +699,7 @@ export declare namespace Tasks {
type TaskStatus as TaskStatus,
type TaskStepView as TaskStepView,
type TaskView as TaskView,
type TaskCreateResponse as TaskCreateResponse,
type TaskListResponse as TaskListResponse,
type TaskGetLogsResponse as TaskGetLogsResponse,
type TaskGetOutputFileResponse as TaskGetOutputFileResponse,
Expand Down
2 changes: 1 addition & 1 deletion src/resources/users/me/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Files extends APIResource {
}

/**
* Response model for presigned upload URL
* Response model for a presigned upload URL
*
* Attributes: url: The URL to upload the file to method: The HTTP method to use
* for the upload fields: The form fields to include in the upload request
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = '0.2.2'; // x-release-please-version
export const VERSION = '0.3.0'; // x-release-please-version