Skip to content

Commit 7183cef

Browse files
feat(api): manual updates
1 parent 3df1a94 commit 7183cef

File tree

19 files changed

+620
-419
lines changed

19 files changed

+620
-419
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 21
1+
configured_endpoints: 26
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browser-use%2Fbrowser-use-9ff5409663c58ae9e3ecc9ac764956189e3a70600f5ba1b961bb1dedf0208271.yml
33
openapi_spec_hash: 9865acb75430d9b799502acbae860df0
4-
config_hash: 99e0e445bc20c5723030c315bab52940
4+
config_hash: 9d52be5177b2ede4cb0633c04f4cc4ef

README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ The full API of this library can be found in [api.md](api.md).
2222
```js
2323
import BrowserUse from 'browser-use-sdk';
2424

25-
const client = new BrowserUse();
25+
const client = new BrowserUse({
26+
apiKey: process.env['BROWSER_USE_API_KEY'], // This is the default and can be omitted
27+
});
2628

27-
const tasks = await client.tasks.list();
29+
const me = await client.users.me.retrieve();
2830

29-
console.log(tasks.items);
31+
console.log(me.additionalCreditsBalanceUsd);
3032
```
3133

3234
### Request & Response types
@@ -37,9 +39,11 @@ This library includes TypeScript definitions for all request params and response
3739
```ts
3840
import BrowserUse from 'browser-use-sdk';
3941

40-
const client = new BrowserUse();
42+
const client = new BrowserUse({
43+
apiKey: process.env['BROWSER_USE_API_KEY'], // This is the default and can be omitted
44+
});
4145

42-
const tasks: BrowserUse.TaskListResponse = await client.tasks.list();
46+
const me: BrowserUse.Users.MeRetrieveResponse = await client.users.me.retrieve();
4347
```
4448

4549
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
@@ -52,7 +56,7 @@ a subclass of `APIError` will be thrown:
5256

5357
<!-- prettier-ignore -->
5458
```ts
55-
const tasks = await client.tasks.list().catch(async (err) => {
59+
const me = await client.users.me.retrieve().catch(async (err) => {
5660
if (err instanceof BrowserUse.APIError) {
5761
console.log(err.status); // 400
5862
console.log(err.name); // BadRequestError
@@ -88,12 +92,11 @@ You can use the `maxRetries` option to configure or disable this:
8892
```js
8993
// Configure the default for all requests:
9094
const client = new BrowserUse({
91-
apiKey: 'My API Key',
9295
maxRetries: 0, // default is 2
9396
});
9497

9598
// Or, configure per-request:
96-
await client.tasks.list({
99+
await client.users.me.retrieve({
97100
maxRetries: 5,
98101
});
99102
```
@@ -106,12 +109,11 @@ Requests time out after 1 minute by default. You can configure this with a `time
106109
```ts
107110
// Configure the default for all requests:
108111
const client = new BrowserUse({
109-
apiKey: 'My API Key',
110112
timeout: 20 * 1000, // 20 seconds (default is 1 minute)
111113
});
112114

113115
// Override per-request:
114-
await client.tasks.list({
116+
await client.users.me.retrieve({
115117
timeout: 5 * 1000,
116118
});
117119
```
@@ -134,13 +136,13 @@ Unlike `.asResponse()` this method consumes the body, returning once it is parse
134136
```ts
135137
const client = new BrowserUse();
136138

137-
const response = await client.tasks.list().asResponse();
139+
const response = await client.users.me.retrieve().asResponse();
138140
console.log(response.headers.get('X-My-Header'));
139141
console.log(response.statusText); // access the underlying Response object
140142

141-
const { data: tasks, response: raw } = await client.tasks.list().withResponse();
143+
const { data: me, response: raw } = await client.users.me.retrieve().withResponse();
142144
console.log(raw.headers.get('X-My-Header'));
143-
console.log(tasks.items);
145+
console.log(me.additionalCreditsBalanceUsd);
144146
```
145147

146148
### Logging
@@ -220,7 +222,7 @@ parameter. This library doesn't validate at runtime that the request matches the
220222
send will be sent as-is.
221223

222224
```ts
223-
client.tasks.list({
225+
client.users.me.retrieve({
224226
// ...
225227
// @ts-expect-error baz is not yet public
226228
baz: 'undocumented option',

api.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,49 @@
1+
# Users
2+
3+
## Me
4+
5+
Types:
6+
7+
- <code><a href="./src/resources/users/me/me.ts">MeRetrieveResponse</a></code>
8+
9+
Methods:
10+
11+
- <code title="get /users/me">client.users.me.<a href="./src/resources/users/me/me.ts">retrieve</a>() -> MeRetrieveResponse</code>
12+
13+
### Files
14+
15+
Types:
16+
17+
- <code><a href="./src/resources/users/me/files.ts">FileCreatePresignedURLResponse</a></code>
18+
19+
Methods:
20+
21+
- <code title="post /users/me/files/presigned-url">client.users.me.files.<a href="./src/resources/users/me/files.ts">createPresignedURL</a>({ ...params }) -> FileCreatePresignedURLResponse</code>
22+
123
# Tasks
224

325
Types:
426

27+
- <code><a href="./src/resources/tasks.ts">FileView</a></code>
528
- <code><a href="./src/resources/tasks.ts">LlmModel</a></code>
29+
- <code><a href="./src/resources/tasks.ts">TaskItemView</a></code>
630
- <code><a href="./src/resources/tasks.ts">TaskStatus</a></code>
31+
- <code><a href="./src/resources/tasks.ts">TaskStepView</a></code>
732
- <code><a href="./src/resources/tasks.ts">TaskView</a></code>
833
- <code><a href="./src/resources/tasks.ts">TaskListResponse</a></code>
9-
- <code><a href="./src/resources/tasks.ts">TaskRetrieveLogsResponse</a></code>
34+
- <code><a href="./src/resources/tasks.ts">TaskGetLogsResponse</a></code>
35+
- <code><a href="./src/resources/tasks.ts">TaskGetOutputFileResponse</a></code>
36+
- <code><a href="./src/resources/tasks.ts">TaskGetUserUploadedFileResponse</a></code>
1037

1138
Methods:
1239

1340
- <code title="post /tasks">client.tasks.<a href="./src/resources/tasks.ts">create</a>({ ...params }) -> TaskView</code>
1441
- <code title="get /tasks/{task_id}">client.tasks.<a href="./src/resources/tasks.ts">retrieve</a>(taskID) -> TaskView</code>
1542
- <code title="patch /tasks/{task_id}">client.tasks.<a href="./src/resources/tasks.ts">update</a>(taskID, { ...params }) -> TaskView</code>
1643
- <code title="get /tasks">client.tasks.<a href="./src/resources/tasks.ts">list</a>({ ...params }) -> TaskListResponse</code>
17-
- <code title="get /tasks/{task_id}/logs">client.tasks.<a href="./src/resources/tasks.ts">retrieveLogs</a>(taskID) -> TaskRetrieveLogsResponse</code>
44+
- <code title="get /tasks/{task_id}/logs">client.tasks.<a href="./src/resources/tasks.ts">getLogs</a>(taskID) -> TaskGetLogsResponse</code>
45+
- <code title="get /tasks/{task_id}/output-files/{file_id}">client.tasks.<a href="./src/resources/tasks.ts">getOutputFile</a>(fileID, { ...params }) -> TaskGetOutputFileResponse</code>
46+
- <code title="get /tasks/{task_id}/user-uploaded-files/{file_id}">client.tasks.<a href="./src/resources/tasks.ts">getUserUploadedFile</a>(fileID, { ...params }) -> TaskGetUserUploadedFileResponse</code>
1847

1948
# Sessions
2049

@@ -29,6 +58,7 @@ Methods:
2958
- <code title="get /sessions/{session_id}">client.sessions.<a href="./src/resources/sessions/sessions.ts">retrieve</a>(sessionID, { ...params }) -> SessionView</code>
3059
- <code title="patch /sessions/{session_id}">client.sessions.<a href="./src/resources/sessions/sessions.ts">update</a>(sessionID, { ...params }) -> SessionView</code>
3160
- <code title="get /sessions">client.sessions.<a href="./src/resources/sessions/sessions.ts">list</a>({ ...params }) -> SessionListResponse</code>
61+
- <code title="delete /sessions/{session_id}">client.sessions.<a href="./src/resources/sessions/sessions.ts">delete</a>(sessionID) -> void</code>
3262

3363
## PublicShare
3464

src/client.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,19 @@ import {
3434
ProxyCountryCode,
3535
} from './resources/browser-profiles';
3636
import {
37+
FileView,
3738
LlmModel,
3839
TaskCreateParams,
40+
TaskGetLogsResponse,
41+
TaskGetOutputFileParams,
42+
TaskGetOutputFileResponse,
43+
TaskGetUserUploadedFileParams,
44+
TaskGetUserUploadedFileResponse,
45+
TaskItemView,
3946
TaskListParams,
4047
TaskListResponse,
41-
TaskRetrieveLogsResponse,
4248
TaskStatus,
49+
TaskStepView,
4350
TaskUpdateParams,
4451
TaskView,
4552
Tasks,
@@ -53,6 +60,7 @@ import {
5360
SessionView,
5461
Sessions,
5562
} from './resources/sessions/sessions';
63+
import { Users } from './resources/users/users';
5664
import { type Fetch } from './internal/builtin-types';
5765
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
5866
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
@@ -242,6 +250,10 @@ export class BrowserUse {
242250
return;
243251
}
244252

253+
protected async authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
254+
return buildHeaders([{ 'X-Browser-Use-API-Key': this.apiKey }]);
255+
}
256+
245257
/**
246258
* Basic re-implementation of `qs.stringify` for primitive types.
247259
*/
@@ -679,6 +691,7 @@ export class BrowserUse {
679691
...(options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {}),
680692
...getPlatformHeaders(),
681693
},
694+
await this.authHeaders(options),
682695
this._options.defaultHeaders,
683696
bodyHeaders,
684697
options.headers,
@@ -745,28 +758,39 @@ export class BrowserUse {
745758

746759
static toFile = Uploads.toFile;
747760

761+
users: API.Users = new API.Users(this);
748762
tasks: API.Tasks = new API.Tasks(this);
749763
sessions: API.Sessions = new API.Sessions(this);
750764
browserProfiles: API.BrowserProfiles = new API.BrowserProfiles(this);
751765
agentProfiles: API.AgentProfiles = new API.AgentProfiles(this);
752766
}
767+
BrowserUse.Users = Users;
753768
BrowserUse.Tasks = Tasks;
754769
BrowserUse.Sessions = Sessions;
755770
BrowserUse.BrowserProfiles = BrowserProfiles;
756771
BrowserUse.AgentProfiles = AgentProfiles;
757772
export declare namespace BrowserUse {
758773
export type RequestOptions = Opts.RequestOptions;
759774

775+
export { Users as Users };
776+
760777
export {
761778
Tasks as Tasks,
779+
type FileView as FileView,
762780
type LlmModel as LlmModel,
781+
type TaskItemView as TaskItemView,
763782
type TaskStatus as TaskStatus,
783+
type TaskStepView as TaskStepView,
764784
type TaskView as TaskView,
765785
type TaskListResponse as TaskListResponse,
766-
type TaskRetrieveLogsResponse as TaskRetrieveLogsResponse,
786+
type TaskGetLogsResponse as TaskGetLogsResponse,
787+
type TaskGetOutputFileResponse as TaskGetOutputFileResponse,
788+
type TaskGetUserUploadedFileResponse as TaskGetUserUploadedFileResponse,
767789
type TaskCreateParams as TaskCreateParams,
768790
type TaskUpdateParams as TaskUpdateParams,
769791
type TaskListParams as TaskListParams,
792+
type TaskGetOutputFileParams as TaskGetOutputFileParams,
793+
type TaskGetUserUploadedFileParams as TaskGetUserUploadedFileParams,
770794
};
771795

772796
export {

src/internal/utils/log.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export const formatRequestDetails = (details: {
106106
([name, value]) => [
107107
name,
108108
(
109+
name.toLowerCase() === 'x-browser-use-api-key' ||
109110
name.toLowerCase() === 'authorization' ||
110111
name.toLowerCase() === 'cookie' ||
111112
name.toLowerCase() === 'set-cookie'

src/resources/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,20 @@ export {
2828
} from './sessions/sessions';
2929
export {
3030
Tasks,
31+
type FileView,
3132
type LlmModel,
33+
type TaskItemView,
3234
type TaskStatus,
35+
type TaskStepView,
3336
type TaskView,
3437
type TaskListResponse,
35-
type TaskRetrieveLogsResponse,
38+
type TaskGetLogsResponse,
39+
type TaskGetOutputFileResponse,
40+
type TaskGetUserUploadedFileResponse,
3641
type TaskCreateParams,
3742
type TaskUpdateParams,
3843
type TaskListParams,
44+
type TaskGetOutputFileParams,
45+
type TaskGetUserUploadedFileParams,
3946
} from './tasks';
47+
export { Users } from './users/users';

0 commit comments

Comments
 (0)