browser-use-sdk 3.3.2 → 3.4.1

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.
package/dist/index.cjs DELETED
@@ -1,432 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
2
-
3
-
4
- var _chunkRIRVOEIUcjs = require('./chunk-RIRVOEIU.cjs');
5
-
6
- // src/v2/client.ts
7
- var _zod = require('zod');
8
-
9
- // src/v2/resources/billing.ts
10
- var Billing = class {
11
- constructor(http) {
12
- this.http = http;
13
- }
14
- /** Get authenticated account billing information including credit balance. */
15
- account() {
16
- return this.http.get("/billing/account");
17
- }
18
- };
19
-
20
- // src/v2/resources/browsers.ts
21
- var Browsers = class {
22
- constructor(http) {
23
- this.http = http;
24
- }
25
- /** Create a new browser session. */
26
- create(body = {}) {
27
- return this.http.post("/browsers", body);
28
- }
29
- /** List browser sessions with optional filtering. */
30
- list(params) {
31
- return this.http.get(
32
- "/browsers",
33
- params
34
- );
35
- }
36
- /** Get detailed browser session information. */
37
- get(sessionId) {
38
- return this.http.get(`/browsers/${sessionId}`);
39
- }
40
- /** Update a browser session (generic PATCH). */
41
- update(sessionId, body) {
42
- return this.http.patch(`/browsers/${sessionId}`, body);
43
- }
44
- /** Stop a browser session. */
45
- stop(sessionId) {
46
- return this.update(sessionId, { action: "stop" });
47
- }
48
- };
49
-
50
- // src/v2/resources/files.ts
51
- var Files = class {
52
- constructor(http) {
53
- this.http = http;
54
- }
55
- /** Generate a presigned URL for uploading files to an agent session. */
56
- sessionUrl(sessionId, body) {
57
- return this.http.post(
58
- `/files/sessions/${sessionId}/presigned-url`,
59
- body
60
- );
61
- }
62
- /** Generate a presigned URL for uploading files to a browser session. */
63
- browserUrl(sessionId, body) {
64
- return this.http.post(
65
- `/files/browsers/${sessionId}/presigned-url`,
66
- body
67
- );
68
- }
69
- /** Get secure download URL for a task output file. */
70
- taskOutput(taskId, fileId) {
71
- return this.http.get(
72
- `/files/tasks/${taskId}/output-files/${fileId}`
73
- );
74
- }
75
- };
76
-
77
- // src/v2/resources/marketplace.ts
78
- var Marketplace = class {
79
- constructor(http) {
80
- this.http = http;
81
- }
82
- /** List all public skills in the marketplace. */
83
- list(params) {
84
- return this.http.get(
85
- "/marketplace/skills",
86
- params
87
- );
88
- }
89
- /** Get details of a specific marketplace skill by slug. */
90
- get(skillSlug) {
91
- return this.http.get(`/marketplace/skills/${skillSlug}`);
92
- }
93
- /** Clone a public marketplace skill to your project. */
94
- clone(skillId) {
95
- return this.http.post(`/marketplace/skills/${skillId}/clone`);
96
- }
97
- /** Execute a marketplace skill. */
98
- execute(skillId, body) {
99
- return this.http.post(
100
- `/marketplace/skills/${skillId}/execute`,
101
- body
102
- );
103
- }
104
- };
105
-
106
- // src/v2/resources/profiles.ts
107
- var Profiles = class {
108
- constructor(http) {
109
- this.http = http;
110
- }
111
- /** Create a new browser profile. */
112
- create(body) {
113
- return this.http.post("/profiles", body);
114
- }
115
- /** List profiles with pagination. */
116
- list(params) {
117
- return this.http.get("/profiles", params);
118
- }
119
- /** Get profile details. */
120
- get(profileId) {
121
- return this.http.get(`/profiles/${profileId}`);
122
- }
123
- /** Update a browser profile. */
124
- update(profileId, body) {
125
- return this.http.patch(`/profiles/${profileId}`, body);
126
- }
127
- /** Delete a browser profile. */
128
- delete(profileId) {
129
- return this.http.delete(`/profiles/${profileId}`);
130
- }
131
- };
132
-
133
- // src/v2/resources/sessions.ts
134
- var Sessions = class {
135
- constructor(http) {
136
- this.http = http;
137
- }
138
- /** Create a new session. */
139
- create(body) {
140
- return this.http.post("/sessions", body);
141
- }
142
- /** List sessions with optional filtering. */
143
- list(params) {
144
- return this.http.get("/sessions", params);
145
- }
146
- /** Get detailed session information. */
147
- get(sessionId) {
148
- return this.http.get(`/sessions/${sessionId}`);
149
- }
150
- /** Update a session (generic PATCH). */
151
- update(sessionId, body) {
152
- return this.http.patch(`/sessions/${sessionId}`, body);
153
- }
154
- /** Stop a session and all its running tasks. */
155
- stop(sessionId) {
156
- return this.update(sessionId, { action: "stop" });
157
- }
158
- /** Delete a session with all its tasks. */
159
- delete(sessionId) {
160
- return this.http.delete(`/sessions/${sessionId}`);
161
- }
162
- /** Get public share information for a session. */
163
- getShare(sessionId) {
164
- return this.http.get(`/sessions/${sessionId}/public-share`);
165
- }
166
- /** Create or return existing public share for a session. */
167
- createShare(sessionId) {
168
- return this.http.post(`/sessions/${sessionId}/public-share`);
169
- }
170
- /** Remove public share for a session. */
171
- deleteShare(sessionId) {
172
- return this.http.delete(`/sessions/${sessionId}/public-share`);
173
- }
174
- /** Purge all session data (ZDR projects only). */
175
- purge(sessionId) {
176
- return this.http.post(`/sessions/${sessionId}/purge`);
177
- }
178
- };
179
-
180
- // src/v2/resources/skills.ts
181
- var Skills = class {
182
- constructor(http) {
183
- this.http = http;
184
- }
185
- /** Create a new skill via automated generation. */
186
- create(body) {
187
- return this.http.post("/skills", body);
188
- }
189
- /** List all skills owned by the project. */
190
- list(params) {
191
- return this.http.get("/skills", params);
192
- }
193
- /** Get details of a specific skill. */
194
- get(skillId) {
195
- return this.http.get(`/skills/${skillId}`);
196
- }
197
- /** Delete a skill. */
198
- delete(skillId) {
199
- return this.http.delete(`/skills/${skillId}`);
200
- }
201
- /** Update skill metadata. */
202
- update(skillId, body) {
203
- return this.http.patch(`/skills/${skillId}`, body);
204
- }
205
- /** Cancel the current in-progress generation for a skill. */
206
- cancel(skillId) {
207
- return this.http.post(`/skills/${skillId}/cancel`);
208
- }
209
- /** Execute a skill with the provided parameters. */
210
- execute(skillId, body) {
211
- return this.http.post(`/skills/${skillId}/execute`, body);
212
- }
213
- /** Refine a skill based on feedback. */
214
- refine(skillId, body) {
215
- return this.http.post(`/skills/${skillId}/refine`, body);
216
- }
217
- /** Rollback to the previous version. */
218
- rollback(skillId) {
219
- return this.http.post(`/skills/${skillId}/rollback`);
220
- }
221
- /** List executions for a specific skill. */
222
- executions(skillId, params) {
223
- return this.http.get(
224
- `/skills/${skillId}/executions`,
225
- params
226
- );
227
- }
228
- /** Get presigned URL for downloading skill execution output. */
229
- executionOutput(skillId, executionId) {
230
- return this.http.get(
231
- `/skills/${skillId}/executions/${executionId}/output`
232
- );
233
- }
234
- };
235
-
236
- // src/v2/helpers.ts
237
- var TERMINAL_STATUSES = /* @__PURE__ */ new Set(["finished", "stopped"]);
238
- var TaskRun = (_class = class {
239
-
240
-
241
-
242
-
243
-
244
- __init() {this._taskId = null}
245
- __init2() {this._result = null}
246
- constructor(createPromise, tasks, schema, options) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);
247
- this._createPromise = createPromise;
248
- this._tasks = tasks;
249
- this._schema = schema;
250
- this._timeout = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _ => _.timeout]), () => ( 3e5));
251
- this._interval = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _2 => _2.interval]), () => ( 2e3));
252
- }
253
- /** Task ID (available after creation resolves). */
254
- get taskId() {
255
- return this._taskId;
256
- }
257
- /** Full task result (available after awaiting or iterating to completion). */
258
- get result() {
259
- return this._result;
260
- }
261
- /** Enable `await client.run(...)` — polls status endpoint, returns TaskResult. */
262
- then(onFulfilled, onRejected) {
263
- return this._waitForOutput().then(onFulfilled, onRejected);
264
- }
265
- /** Enable `for await (const step of client.run(...))` — polls full task, yields new steps. */
266
- async *[Symbol.asyncIterator]() {
267
- const taskId = await this._ensureTaskId();
268
- let seen = 0;
269
- const deadline = Date.now() + this._timeout;
270
- while (Date.now() < deadline) {
271
- const task = await this._tasks.get(taskId);
272
- for (let i = seen; i < task.steps.length; i++) {
273
- yield task.steps[i];
274
- }
275
- seen = task.steps.length;
276
- if (TERMINAL_STATUSES.has(task.status)) {
277
- this._result = this._buildResult(task);
278
- return;
279
- }
280
- const remaining = deadline - Date.now();
281
- if (remaining <= 0) break;
282
- await new Promise((r) => setTimeout(r, Math.min(this._interval, remaining)));
283
- }
284
- throw new Error(`Task ${taskId} did not complete within ${this._timeout}ms`);
285
- }
286
- async _ensureTaskId() {
287
- if (this._taskId) return this._taskId;
288
- const created = await this._createPromise;
289
- this._taskId = created.id;
290
- return this._taskId;
291
- }
292
- /** Poll lightweight status endpoint until terminal, return TaskResult. */
293
- async _waitForOutput() {
294
- const taskId = await this._ensureTaskId();
295
- const deadline = Date.now() + this._timeout;
296
- while (Date.now() < deadline) {
297
- const status = await this._tasks.status(taskId);
298
- if (TERMINAL_STATUSES.has(status.status)) {
299
- const task = await this._tasks.get(taskId);
300
- this._result = this._buildResult(task);
301
- return this._result;
302
- }
303
- const remaining = deadline - Date.now();
304
- if (remaining <= 0) break;
305
- await new Promise((r) => setTimeout(r, Math.min(this._interval, remaining)));
306
- }
307
- throw new Error(`Task ${taskId} did not complete within ${this._timeout}ms`);
308
- }
309
- _buildResult(task) {
310
- const output = this._parseOutput(task.output);
311
- return { ...task, output };
312
- }
313
- _parseOutput(output) {
314
- if (output == null) return null;
315
- if (!this._schema) return output;
316
- return this._schema.parse(JSON.parse(output));
317
- }
318
- }, _class);
319
-
320
- // src/v2/resources/tasks.ts
321
- var Tasks = class {
322
- constructor(http) {
323
- this.http = http;
324
- }
325
- /** Create and start a new AI agent task. */
326
- create(body) {
327
- return this.http.post("/tasks", body);
328
- }
329
- /** List tasks with optional filtering. */
330
- list(params) {
331
- return this.http.get("/tasks", params);
332
- }
333
- /** Get detailed task information. */
334
- get(taskId) {
335
- return this.http.get(`/tasks/${taskId}`);
336
- }
337
- /** Update a task (generic PATCH). */
338
- update(taskId, body) {
339
- return this.http.patch(`/tasks/${taskId}`, body);
340
- }
341
- /** Stop a running task. */
342
- stop(taskId) {
343
- return this.update(taskId, { action: "stop" });
344
- }
345
- /** Stop a running task and its associated browser session. */
346
- stopTaskAndSession(taskId) {
347
- return this.update(taskId, { action: "stop_task_and_session" });
348
- }
349
- /** Get lightweight task status (optimized for polling). */
350
- status(taskId) {
351
- return this.http.get(`/tasks/${taskId}/status`);
352
- }
353
- /** Get secure download URL for task execution logs. */
354
- logs(taskId) {
355
- return this.http.get(`/tasks/${taskId}/logs`);
356
- }
357
- /** Poll until a task reaches a terminal status, then return the full TaskView. */
358
- async wait(taskId, opts) {
359
- const timeout = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _3 => _3.timeout]), () => ( 3e5));
360
- const interval = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _4 => _4.interval]), () => ( 2e3));
361
- const deadline = Date.now() + timeout;
362
- while (Date.now() < deadline) {
363
- const status = await this.status(taskId);
364
- if (TERMINAL_STATUSES.has(status.status)) {
365
- return this.get(taskId);
366
- }
367
- const remaining = deadline - Date.now();
368
- if (remaining <= 0) break;
369
- await new Promise((r) => setTimeout(r, Math.min(interval, remaining)));
370
- }
371
- throw new Error(`Task ${taskId} did not complete within ${timeout}ms`);
372
- }
373
- };
374
-
375
- // src/v2/client.ts
376
- var DEFAULT_BASE_URL = "https://api.browser-use.com/api/v2";
377
- var BrowserUse = class {
378
-
379
-
380
-
381
-
382
-
383
-
384
-
385
-
386
-
387
- constructor(options = {}) {
388
- const apiKey = _nullishCoalesce(_nullishCoalesce(options.apiKey, () => ( process.env.BROWSER_USE_API_KEY)), () => ( ""));
389
- if (!apiKey) {
390
- throw new Error(
391
- "No API key provided. Pass apiKey or set BROWSER_USE_API_KEY."
392
- );
393
- }
394
- this.http = new (0, _chunkRIRVOEIUcjs.HttpClient)({
395
- apiKey,
396
- baseUrl: _nullishCoalesce(options.baseUrl, () => ( DEFAULT_BASE_URL)),
397
- maxRetries: options.maxRetries,
398
- timeout: options.timeout
399
- });
400
- this.billing = new Billing(this.http);
401
- this.tasks = new Tasks(this.http);
402
- this.sessions = new Sessions(this.http);
403
- this.files = new Files(this.http);
404
- this.profiles = new Profiles(this.http);
405
- this.browsers = new Browsers(this.http);
406
- this.skills = new Skills(this.http);
407
- this.marketplace = new Marketplace(this.http);
408
- }
409
- run(task, options) {
410
- const { schema, timeout, interval, ...rest } = _nullishCoalesce(options, () => ( {}));
411
- const body = { task, ...rest };
412
- if (schema) {
413
- body.structuredOutput = JSON.stringify(_zod.z.toJSONSchema(schema));
414
- }
415
- const promise = this.tasks.create(body);
416
- return new TaskRun(promise, this.tasks, schema, { timeout, interval });
417
- }
418
- };
419
-
420
-
421
-
422
-
423
-
424
-
425
-
426
-
427
-
428
-
429
-
430
-
431
- exports.Billing = Billing; exports.BrowserUse = BrowserUse; exports.BrowserUseError = _chunkRIRVOEIUcjs.BrowserUseError; exports.Browsers = Browsers; exports.Files = Files; exports.Marketplace = Marketplace; exports.Profiles = Profiles; exports.Sessions = Sessions; exports.Skills = Skills; exports.TaskRun = TaskRun; exports.Tasks = Tasks;
432
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/sauravpanda/Github/LLMs/Browser-Use/sdk/browser-use-node/dist/index.cjs","../src/v2/client.ts","../src/v2/resources/billing.ts","../src/v2/resources/browsers.ts","../src/v2/resources/files.ts","../src/v2/resources/marketplace.ts","../src/v2/resources/profiles.ts","../src/v2/resources/sessions.ts","../src/v2/resources/skills.ts","../src/v2/helpers.ts","../src/v2/resources/tasks.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACLA,0BAAkB;ADOlB;AACA;AEHO,IAAM,QAAA,EAAN,MAAc;AAAA,EACnB,WAAA,CAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,KAAA,EAAA,IAAA;AAAA,EAAmB;AAAA;AAAA,EA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AAC9C,EAAA;AACF;AT2LgD;AACA;AUxS7B;AAC8B,EAAA;AAAlB,IAAA;AAAmB,EAAA;AAAA;AAGW,EAAA;AACA,IAAA;AAC3D,EAAA;AAAA;AAGyD,EAAA;AAC2B,IAAA;AACpF,EAAA;AAAA;AAGuC,EAAA;AACY,IAAA;AACnD,EAAA;AAAA;AAGmE,EAAA;AACZ,IAAA;AACvD,EAAA;AAAA;AAGwC,EAAA;AACM,IAAA;AAC9C,EAAA;AAAA;AAGsD,EAAA;AACf,IAAA;AACvC,EAAA;AAAA;AAGgD,EAAA;AACO,IAAA;AACvD,EAAA;AAAA;AAGmD,EAAA;AACgB,IAAA;AACnE,EAAA;AAAA;AAG8F,EAAA;AAC3D,IAAA;AACE,IAAA;AACL,IAAA;AAEA,IAAA;AACW,MAAA;AACG,MAAA;AAClB,QAAA;AACxB,MAAA;AACsC,MAAA;AAClB,MAAA;AACmB,MAAA;AACzC,IAAA;AAE8B,IAAA;AAChC,EAAA;AACF;AViSgD;AACA;ACxWvB;AAYD;AACb,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AAEQ,EAAA;AAE4B,EAAA;AAEf,IAAA;AACf,IAAA;AACD,MAAA;AACR,QAAA;AACF,MAAA;AACF,IAAA;AAC2B,IAAA;AACzB,MAAA;AAC4B,MAAA;AACR,MAAA;AACH,MAAA;AAClB,IAAA;AAEmC,IAAA;AACJ,IAAA;AACM,IAAA;AACN,IAAA;AACM,IAAA;AACA,IAAA;AACJ,IAAA;AACU,IAAA;AAC9C,EAAA;AAoB0D,EAAA;AACb,IAAA;AACE,IAAA;AACjC,IAAA;AAC+B,MAAA;AAC3C,IAAA;AACsC,IAAA;AACE,IAAA;AAC1C,EAAA;AACF;ADwUgD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/sauravpanda/Github/LLMs/Browser-Use/sdk/browser-use-node/dist/index.cjs","sourcesContent":[null,"import { z } from \"zod\";\nimport { HttpClient } from \"../core/http.js\";\nimport { Billing } from \"./resources/billing.js\";\nimport { Browsers } from \"./resources/browsers.js\";\nimport { Files } from \"./resources/files.js\";\nimport { Marketplace } from \"./resources/marketplace.js\";\nimport { Profiles } from \"./resources/profiles.js\";\nimport { Sessions } from \"./resources/sessions.js\";\nimport { Skills } from \"./resources/skills.js\";\nimport { Tasks } from \"./resources/tasks.js\";\nimport { TaskRun } from \"./helpers.js\";\nimport type { CreateTaskBody } from \"./resources/tasks.js\";\nimport type { RunOptions } from \"./helpers.js\";\n\nconst DEFAULT_BASE_URL = \"https://api.browser-use.com/api/v2\";\n\nexport interface BrowserUseOptions {\n apiKey?: string;\n baseUrl?: string;\n maxRetries?: number;\n timeout?: number;\n}\n\nexport type RunTaskOptions = Partial<Omit<CreateTaskBody, \"task\">> &\n RunOptions & { schema?: z.ZodType };\n\nexport class BrowserUse {\n readonly billing: Billing;\n readonly tasks: Tasks;\n readonly sessions: Sessions;\n readonly files: Files;\n readonly profiles: Profiles;\n readonly browsers: Browsers;\n readonly skills: Skills;\n readonly marketplace: Marketplace;\n\n private readonly http: HttpClient;\n\n constructor(options: BrowserUseOptions = {}) {\n const apiKey =\n options.apiKey ?? process.env.BROWSER_USE_API_KEY ?? \"\";\n if (!apiKey) {\n throw new Error(\n \"No API key provided. Pass apiKey or set BROWSER_USE_API_KEY.\",\n );\n }\n this.http = new HttpClient({\n apiKey,\n baseUrl: options.baseUrl ?? DEFAULT_BASE_URL,\n maxRetries: options.maxRetries,\n timeout: options.timeout,\n });\n\n this.billing = new Billing(this.http);\n this.tasks = new Tasks(this.http);\n this.sessions = new Sessions(this.http);\n this.files = new Files(this.http);\n this.profiles = new Profiles(this.http);\n this.browsers = new Browsers(this.http);\n this.skills = new Skills(this.http);\n this.marketplace = new Marketplace(this.http);\n }\n\n /**\n * Run an AI agent task.\n *\n * ```ts\n * // Simple — just get the output\n * const output = await client.run(\"Find the top HN post\");\n *\n * // Structured output (Zod)\n * const data = await client.run(\"Find product info\", { schema: ProductSchema });\n *\n * // Step-by-step progress\n * for await (const step of client.run(\"Go to google.com\")) {\n * console.log(`[${step.number}] ${step.nextGoal}`);\n * }\n * ```\n */\n run(task: string, options?: Omit<RunTaskOptions, \"schema\">): TaskRun<string>;\n run<T extends z.ZodType>(task: string, options: RunTaskOptions & { schema: T }): TaskRun<z.output<T>>;\n run(task: string, options?: RunTaskOptions): TaskRun<any> {\n const { schema, timeout, interval, ...rest } = options ?? {};\n const body: CreateTaskBody = { task, ...rest };\n if (schema) {\n body.structuredOutput = JSON.stringify(z.toJSONSchema(schema));\n }\n const promise = this.tasks.create(body);\n return new TaskRun(promise, this.tasks, schema, { timeout, interval });\n }\n}\n","import type { HttpClient } from \"../../core/http.js\";\nimport type { components } from \"../../generated/v2/types.js\";\n\ntype AccountView = components[\"schemas\"][\"AccountView\"];\n\nexport class Billing {\n constructor(private readonly http: HttpClient) {}\n\n /** Get authenticated account billing information including credit balance. */\n account(): Promise<AccountView> {\n return this.http.get<AccountView>(\"/billing/account\");\n }\n}\n","import type { HttpClient } from \"../../core/http.js\";\nimport type { components } from \"../../generated/v2/types.js\";\n\n/** All fields are optional (server applies defaults); body itself is required by the spec. */\nexport type CreateBrowserBody = Partial<components[\"schemas\"][\"CreateBrowserSessionRequest\"]>;\ntype BrowserSessionItemView = components[\"schemas\"][\"BrowserSessionItemView\"];\ntype BrowserSessionListResponse = components[\"schemas\"][\"BrowserSessionListResponse\"];\ntype BrowserSessionView = components[\"schemas\"][\"BrowserSessionView\"];\ntype UpdateBrowserSessionRequest = components[\"schemas\"][\"UpdateBrowserSessionRequest\"];\n\nexport interface BrowserListParams {\n pageSize?: number;\n pageNumber?: number;\n filterBy?: string;\n}\n\nexport class Browsers {\n constructor(private readonly http: HttpClient) {}\n\n /** Create a new browser session. */\n create(body: CreateBrowserBody = {}): Promise<BrowserSessionItemView> {\n return this.http.post<BrowserSessionItemView>(\"/browsers\", body);\n }\n\n /** List browser sessions with optional filtering. */\n list(params?: BrowserListParams): Promise<BrowserSessionListResponse> {\n return this.http.get<BrowserSessionListResponse>(\n \"/browsers\",\n params as Record<string, unknown>,\n );\n }\n\n /** Get detailed browser session information. */\n get(sessionId: string): Promise<BrowserSessionView> {\n return this.http.get<BrowserSessionView>(`/browsers/${sessionId}`);\n }\n\n /** Update a browser session (generic PATCH). */\n update(sessionId: string, body: UpdateBrowserSessionRequest): Promise<BrowserSessionView> {\n return this.http.patch<BrowserSessionView>(`/browsers/${sessionId}`, body);\n }\n\n /** Stop a browser session. */\n stop(sessionId: string): Promise<BrowserSessionView> {\n return this.update(sessionId, { action: \"stop\" });\n }\n}\n","import type { HttpClient } from \"../../core/http.js\";\nimport type { components } from \"../../generated/v2/types.js\";\n\ntype UploadFileRequest = components[\"schemas\"][\"UploadFileRequest\"];\ntype UploadFilePresignedUrlResponse = components[\"schemas\"][\"UploadFilePresignedUrlResponse\"];\ntype TaskOutputFileResponse = components[\"schemas\"][\"TaskOutputFileResponse\"];\n\nexport class Files {\n constructor(private readonly http: HttpClient) {}\n\n /** Generate a presigned URL for uploading files to an agent session. */\n sessionUrl(sessionId: string, body: UploadFileRequest): Promise<UploadFilePresignedUrlResponse> {\n return this.http.post<UploadFilePresignedUrlResponse>(\n `/files/sessions/${sessionId}/presigned-url`,\n body,\n );\n }\n\n /** Generate a presigned URL for uploading files to a browser session. */\n browserUrl(sessionId: string, body: UploadFileRequest): Promise<UploadFilePresignedUrlResponse> {\n return this.http.post<UploadFilePresignedUrlResponse>(\n `/files/browsers/${sessionId}/presigned-url`,\n body,\n );\n }\n\n /** Get secure download URL for a task output file. */\n taskOutput(taskId: string, fileId: string): Promise<TaskOutputFileResponse> {\n return this.http.get<TaskOutputFileResponse>(\n `/files/tasks/${taskId}/output-files/${fileId}`,\n );\n }\n}\n","import type { HttpClient } from \"../../core/http.js\";\nimport type { components } from \"../../generated/v2/types.js\";\n\ntype ExecuteSkillRequest = components[\"schemas\"][\"ExecuteSkillRequest\"];\ntype ExecuteSkillResponse = components[\"schemas\"][\"ExecuteSkillResponse\"];\ntype MarketplaceSkillListResponse = components[\"schemas\"][\"MarketplaceSkillListResponse\"];\ntype MarketplaceSkillResponse = components[\"schemas\"][\"MarketplaceSkillResponse\"];\ntype SkillResponse = components[\"schemas\"][\"SkillResponse\"];\n\nexport interface MarketplaceListParams {\n pageSize?: number;\n pageNumber?: number;\n query?: string;\n category?: string;\n fromDate?: string;\n toDate?: string;\n}\n\nexport class Marketplace {\n constructor(private readonly http: HttpClient) {}\n\n /** List all public skills in the marketplace. */\n list(params?: MarketplaceListParams): Promise<MarketplaceSkillListResponse> {\n return this.http.get<MarketplaceSkillListResponse>(\n \"/marketplace/skills\",\n params as Record<string, unknown>,\n );\n }\n\n /** Get details of a specific marketplace skill by slug. */\n get(skillSlug: string): Promise<MarketplaceSkillResponse> {\n return this.http.get<MarketplaceSkillResponse>(`/marketplace/skills/${skillSlug}`);\n }\n\n /** Clone a public marketplace skill to your project. */\n clone(skillId: string): Promise<SkillResponse> {\n return this.http.post<SkillResponse>(`/marketplace/skills/${skillId}/clone`);\n }\n\n /** Execute a marketplace skill. */\n execute(skillId: string, body: ExecuteSkillRequest): Promise<ExecuteSkillResponse> {\n return this.http.post<ExecuteSkillResponse>(\n `/marketplace/skills/${skillId}/execute`,\n body,\n );\n }\n}\n","import type { HttpClient } from \"../../core/http.js\";\nimport type { components } from \"../../generated/v2/types.js\";\n\ntype ProfileCreateRequest = components[\"schemas\"][\"ProfileCreateRequest\"];\ntype ProfileListResponse = components[\"schemas\"][\"ProfileListResponse\"];\ntype ProfileUpdateRequest = components[\"schemas\"][\"ProfileUpdateRequest\"];\ntype ProfileView = components[\"schemas\"][\"ProfileView\"];\n\nexport interface ProfileListParams {\n pageSize?: number;\n pageNumber?: number;\n query?: string;\n}\n\nexport class Profiles {\n constructor(private readonly http: HttpClient) {}\n\n /** Create a new browser profile. */\n create(body?: ProfileCreateRequest): Promise<ProfileView> {\n return this.http.post<ProfileView>(\"/profiles\", body);\n }\n\n /** List profiles with pagination. */\n list(params?: ProfileListParams): Promise<ProfileListResponse> {\n return this.http.get<ProfileListResponse>(\"/profiles\", params as Record<string, unknown>);\n }\n\n /** Get profile details. */\n get(profileId: string): Promise<ProfileView> {\n return this.http.get<ProfileView>(`/profiles/${profileId}`);\n }\n\n /** Update a browser profile. */\n update(profileId: string, body: ProfileUpdateRequest): Promise<ProfileView> {\n return this.http.patch<ProfileView>(`/profiles/${profileId}`, body);\n }\n\n /** Delete a browser profile. */\n delete(profileId: string): Promise<void> {\n return this.http.delete<void>(`/profiles/${profileId}`);\n }\n}\n","import type { HttpClient } from \"../../core/http.js\";\nimport type { components } from \"../../generated/v2/types.js\";\n\n/** User-facing body: all fields are optional (API has defaults). */\ntype CreateSessionBody = Partial<components[\"schemas\"][\"CreateSessionRequest\"]>;\ntype SessionItemView = components[\"schemas\"][\"SessionItemView\"];\ntype SessionListResponse = components[\"schemas\"][\"SessionListResponse\"];\ntype SessionView = components[\"schemas\"][\"SessionView\"];\ntype ShareView = components[\"schemas\"][\"ShareView\"];\ntype UpdateSessionRequest = components[\"schemas\"][\"UpdateSessionRequest\"];\n\nexport interface SessionListParams {\n pageSize?: number;\n pageNumber?: number;\n filterBy?: string;\n}\n\nexport class Sessions {\n constructor(private readonly http: HttpClient) {}\n\n /** Create a new session. */\n create(body?: CreateSessionBody): Promise<SessionItemView> {\n return this.http.post<SessionItemView>(\"/sessions\", body);\n }\n\n /** List sessions with optional filtering. */\n list(params?: SessionListParams): Promise<SessionListResponse> {\n return this.http.get<SessionListResponse>(\"/sessions\", params as Record<string, unknown>);\n }\n\n /** Get detailed session information. */\n get(sessionId: string): Promise<SessionView> {\n return this.http.get<SessionView>(`/sessions/${sessionId}`);\n }\n\n /** Update a session (generic PATCH). */\n update(sessionId: string, body: UpdateSessionRequest): Promise<SessionView> {\n return this.http.patch<SessionView>(`/sessions/${sessionId}`, body);\n }\n\n /** Stop a session and all its running tasks. */\n stop(sessionId: string): Promise<SessionView> {\n return this.update(sessionId, { action: \"stop\" });\n }\n\n /** Delete a session with all its tasks. */\n delete(sessionId: string): Promise<void> {\n return this.http.delete<void>(`/sessions/${sessionId}`);\n }\n\n /** Get public share information for a session. */\n getShare(sessionId: string): Promise<ShareView> {\n return this.http.get<ShareView>(`/sessions/${sessionId}/public-share`);\n }\n\n /** Create or return existing public share for a session. */\n createShare(sessionId: string): Promise<ShareView> {\n return this.http.post<ShareView>(`/sessions/${sessionId}/public-share`);\n }\n\n /** Remove public share for a session. */\n deleteShare(sessionId: string): Promise<void> {\n return this.http.delete<void>(`/sessions/${sessionId}/public-share`);\n }\n\n /** Purge all session data (ZDR projects only). */\n purge(sessionId: string): Promise<void> {\n return this.http.post<void>(`/sessions/${sessionId}/purge`);\n }\n}\n","import type { HttpClient } from \"../../core/http.js\";\nimport type { components } from \"../../generated/v2/types.js\";\n\ntype CreateSkillRequest = components[\"schemas\"][\"CreateSkillRequest\"];\ntype CreateSkillResponse = components[\"schemas\"][\"CreateSkillResponse\"];\ntype ExecuteSkillRequest = components[\"schemas\"][\"ExecuteSkillRequest\"];\ntype ExecuteSkillResponse = components[\"schemas\"][\"ExecuteSkillResponse\"];\ntype RefineSkillRequest = components[\"schemas\"][\"RefineSkillRequest\"];\ntype RefineSkillResponse = components[\"schemas\"][\"RefineSkillResponse\"];\ntype SkillExecutionListResponse = components[\"schemas\"][\"SkillExecutionListResponse\"];\ntype SkillExecutionOutputResponse = components[\"schemas\"][\"SkillExecutionOutputResponse\"];\ntype SkillListResponse = components[\"schemas\"][\"SkillListResponse\"];\ntype SkillResponse = components[\"schemas\"][\"SkillResponse\"];\ntype UpdateSkillRequest = components[\"schemas\"][\"UpdateSkillRequest\"];\n\nexport interface SkillListParams {\n pageSize?: number;\n pageNumber?: number;\n isPublic?: boolean;\n isEnabled?: boolean;\n category?: string;\n query?: string;\n fromDate?: string;\n toDate?: string;\n}\n\nexport interface SkillExecutionListParams {\n pageSize?: number;\n pageNumber?: number;\n}\n\nexport class Skills {\n constructor(private readonly http: HttpClient) {}\n\n /** Create a new skill via automated generation. */\n create(body: CreateSkillRequest): Promise<CreateSkillResponse> {\n return this.http.post<CreateSkillResponse>(\"/skills\", body);\n }\n\n /** List all skills owned by the project. */\n list(params?: SkillListParams): Promise<SkillListResponse> {\n return this.http.get<SkillListResponse>(\"/skills\", params as Record<string, unknown>);\n }\n\n /** Get details of a specific skill. */\n get(skillId: string): Promise<SkillResponse> {\n return this.http.get<SkillResponse>(`/skills/${skillId}`);\n }\n\n /** Delete a skill. */\n delete(skillId: string): Promise<void> {\n return this.http.delete<void>(`/skills/${skillId}`);\n }\n\n /** Update skill metadata. */\n update(skillId: string, body: UpdateSkillRequest): Promise<SkillResponse> {\n return this.http.patch<SkillResponse>(`/skills/${skillId}`, body);\n }\n\n /** Cancel the current in-progress generation for a skill. */\n cancel(skillId: string): Promise<SkillResponse> {\n return this.http.post<SkillResponse>(`/skills/${skillId}/cancel`);\n }\n\n /** Execute a skill with the provided parameters. */\n execute(skillId: string, body: ExecuteSkillRequest): Promise<ExecuteSkillResponse> {\n return this.http.post<ExecuteSkillResponse>(`/skills/${skillId}/execute`, body);\n }\n\n /** Refine a skill based on feedback. */\n refine(skillId: string, body: RefineSkillRequest): Promise<RefineSkillResponse> {\n return this.http.post<RefineSkillResponse>(`/skills/${skillId}/refine`, body);\n }\n\n /** Rollback to the previous version. */\n rollback(skillId: string): Promise<SkillResponse> {\n return this.http.post<SkillResponse>(`/skills/${skillId}/rollback`);\n }\n\n /** List executions for a specific skill. */\n executions(skillId: string, params?: SkillExecutionListParams): Promise<SkillExecutionListResponse> {\n return this.http.get<SkillExecutionListResponse>(\n `/skills/${skillId}/executions`,\n params as Record<string, unknown>,\n );\n }\n\n /** Get presigned URL for downloading skill execution output. */\n executionOutput(skillId: string, executionId: string): Promise<SkillExecutionOutputResponse> {\n return this.http.get<SkillExecutionOutputResponse>(\n `/skills/${skillId}/executions/${executionId}/output`,\n );\n }\n}\n","import type { z } from \"zod\";\nimport type { components } from \"../generated/v2/types.js\";\nimport type { Tasks } from \"./resources/tasks.js\";\n\ntype TaskCreatedResponse = components[\"schemas\"][\"TaskCreatedResponse\"];\ntype TaskStepView = components[\"schemas\"][\"TaskStepView\"];\ntype TaskView = components[\"schemas\"][\"TaskView\"];\n\nexport const TERMINAL_STATUSES = new Set([\"finished\", \"stopped\"]);\n\n/** Task result with typed output. All TaskView fields are directly accessible. */\nexport type TaskResult<T = string | null> = Omit<TaskView, \"output\"> & { output: T };\n\nexport interface RunOptions {\n /** Maximum time to wait in milliseconds. Default: 300_000 (5 min). */\n timeout?: number;\n /** Polling interval in milliseconds. Default: 2_000. */\n interval?: number;\n}\n\n/**\n * Lazy task handle returned by `client.run()`.\n *\n * - `await client.run(...)` polls the lightweight status endpoint, returns a `TaskResult`.\n * - `for await (const step of client.run(...))` polls the full task, yields new steps.\n */\nexport class TaskRun<T = string> implements PromiseLike<TaskResult<T>> {\n private readonly _createPromise: Promise<TaskCreatedResponse>;\n private readonly _tasks: Tasks;\n private readonly _schema?: z.ZodType<T>;\n private readonly _timeout: number;\n private readonly _interval: number;\n\n private _taskId: string | null = null;\n private _result: TaskResult<T> | null = null;\n\n constructor(\n createPromise: Promise<TaskCreatedResponse>,\n tasks: Tasks,\n schema?: z.ZodType<T>,\n options?: RunOptions,\n ) {\n this._createPromise = createPromise;\n this._tasks = tasks;\n this._schema = schema;\n this._timeout = options?.timeout ?? 300_000;\n this._interval = options?.interval ?? 2_000;\n }\n\n /** Task ID (available after creation resolves). */\n get taskId(): string | null {\n return this._taskId;\n }\n\n /** Full task result (available after awaiting or iterating to completion). */\n get result(): TaskResult<T> | null {\n return this._result;\n }\n\n /** Enable `await client.run(...)` — polls status endpoint, returns TaskResult. */\n then<R1 = TaskResult<T>, R2 = never>(\n onFulfilled?: ((value: TaskResult<T>) => R1 | PromiseLike<R1>) | null,\n onRejected?: ((reason: unknown) => R2 | PromiseLike<R2>) | null,\n ): Promise<R1 | R2> {\n return this._waitForOutput().then(onFulfilled, onRejected);\n }\n\n /** Enable `for await (const step of client.run(...))` — polls full task, yields new steps. */\n async *[Symbol.asyncIterator](): AsyncGenerator<TaskStepView> {\n const taskId = await this._ensureTaskId();\n let seen = 0;\n const deadline = Date.now() + this._timeout;\n\n while (Date.now() < deadline) {\n const task = await this._tasks.get(taskId);\n\n for (let i = seen; i < task.steps.length; i++) {\n yield task.steps[i];\n }\n seen = task.steps.length;\n\n if (TERMINAL_STATUSES.has(task.status)) {\n this._result = this._buildResult(task);\n return;\n }\n\n const remaining = deadline - Date.now();\n if (remaining <= 0) break;\n await new Promise((r) => setTimeout(r, Math.min(this._interval, remaining)));\n }\n\n throw new Error(`Task ${taskId} did not complete within ${this._timeout}ms`);\n }\n\n private async _ensureTaskId(): Promise<string> {\n if (this._taskId) return this._taskId;\n const created = await this._createPromise;\n this._taskId = created.id;\n return this._taskId;\n }\n\n /** Poll lightweight status endpoint until terminal, return TaskResult. */\n private async _waitForOutput(): Promise<TaskResult<T>> {\n const taskId = await this._ensureTaskId();\n const deadline = Date.now() + this._timeout;\n\n while (Date.now() < deadline) {\n const status = await this._tasks.status(taskId);\n if (TERMINAL_STATUSES.has(status.status)) {\n const task = await this._tasks.get(taskId);\n this._result = this._buildResult(task);\n return this._result;\n }\n const remaining = deadline - Date.now();\n if (remaining <= 0) break;\n await new Promise((r) => setTimeout(r, Math.min(this._interval, remaining)));\n }\n\n throw new Error(`Task ${taskId} did not complete within ${this._timeout}ms`);\n }\n\n private _buildResult(task: TaskView): TaskResult<T> {\n const output = this._parseOutput(task.output);\n return { ...task, output };\n }\n\n private _parseOutput(output: string | null | undefined): T {\n if (output == null) return null as T;\n if (!this._schema) return output as unknown as T;\n return this._schema.parse(JSON.parse(output));\n }\n}\n","import type { HttpClient } from \"../../core/http.js\";\nimport type { components } from \"../../generated/v2/types.js\";\nimport { TERMINAL_STATUSES } from \"../helpers.js\";\n\n/** User-facing body: only `task` is required; everything else has API defaults. */\nexport type CreateTaskBody = Pick<components[\"schemas\"][\"CreateTaskRequest\"], \"task\"> &\n Partial<Omit<components[\"schemas\"][\"CreateTaskRequest\"], \"task\">>;\ntype TaskCreatedResponse = components[\"schemas\"][\"TaskCreatedResponse\"];\ntype TaskListResponse = components[\"schemas\"][\"TaskListResponse\"];\ntype TaskLogFileResponse = components[\"schemas\"][\"TaskLogFileResponse\"];\ntype TaskStatusView = components[\"schemas\"][\"TaskStatusView\"];\ntype TaskView = components[\"schemas\"][\"TaskView\"];\ntype UpdateTaskRequest = components[\"schemas\"][\"UpdateTaskRequest\"];\n\nexport interface TaskListParams {\n pageSize?: number;\n pageNumber?: number;\n sessionId?: string;\n filterBy?: string;\n after?: string;\n before?: string;\n}\n\nexport class Tasks {\n constructor(private readonly http: HttpClient) {}\n\n /** Create and start a new AI agent task. */\n create(body: CreateTaskBody): Promise<TaskCreatedResponse> {\n return this.http.post<TaskCreatedResponse>(\"/tasks\", body);\n }\n\n /** List tasks with optional filtering. */\n list(params?: TaskListParams): Promise<TaskListResponse> {\n return this.http.get<TaskListResponse>(\"/tasks\", params as Record<string, unknown>);\n }\n\n /** Get detailed task information. */\n get(taskId: string): Promise<TaskView> {\n return this.http.get<TaskView>(`/tasks/${taskId}`);\n }\n\n /** Update a task (generic PATCH). */\n update(taskId: string, body: UpdateTaskRequest): Promise<TaskView> {\n return this.http.patch<TaskView>(`/tasks/${taskId}`, body);\n }\n\n /** Stop a running task. */\n stop(taskId: string): Promise<TaskView> {\n return this.update(taskId, { action: \"stop\" });\n }\n\n /** Stop a running task and its associated browser session. */\n stopTaskAndSession(taskId: string): Promise<TaskView> {\n return this.update(taskId, { action: \"stop_task_and_session\" });\n }\n\n /** Get lightweight task status (optimized for polling). */\n status(taskId: string): Promise<TaskStatusView> {\n return this.http.get<TaskStatusView>(`/tasks/${taskId}/status`);\n }\n\n /** Get secure download URL for task execution logs. */\n logs(taskId: string): Promise<TaskLogFileResponse> {\n return this.http.get<TaskLogFileResponse>(`/tasks/${taskId}/logs`);\n }\n\n /** Poll until a task reaches a terminal status, then return the full TaskView. */\n async wait(taskId: string, opts?: { timeout?: number; interval?: number }): Promise<TaskView> {\n const timeout = opts?.timeout ?? 300_000;\n const interval = opts?.interval ?? 2_000;\n const deadline = Date.now() + timeout;\n\n while (Date.now() < deadline) {\n const status = await this.status(taskId);\n if (TERMINAL_STATUSES.has(status.status)) {\n return this.get(taskId);\n }\n const remaining = deadline - Date.now();\n if (remaining <= 0) break;\n await new Promise((r) => setTimeout(r, Math.min(interval, remaining)));\n }\n\n throw new Error(`Task ${taskId} did not complete within ${timeout}ms`);\n }\n}\n"]}