browser-use-sdk 3.3.0 → 3.3.2
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/README.md +12 -193
- package/dist/chunk-RIRVOEIU.cjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -9
- package/dist/index.d.ts +35 -9
- package/dist/index.js.map +1 -1
- package/dist/v3.cjs +248 -4
- package/dist/v3.cjs.map +1 -1
- package/dist/v3.d.cts +700 -5
- package/dist/v3.d.ts +700 -5
- package/dist/v3.js +246 -2
- package/dist/v3.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -291,9 +291,10 @@ interface components {
|
|
|
291
291
|
profileId?: string | null;
|
|
292
292
|
/**
|
|
293
293
|
* Proxy Country Code
|
|
294
|
-
* @description Country code for proxy location.
|
|
294
|
+
* @description Country code for proxy location. Defaults to US. Set to null to disable proxy.
|
|
295
|
+
* @default us
|
|
295
296
|
*/
|
|
296
|
-
proxyCountryCode
|
|
297
|
+
proxyCountryCode: components["schemas"]["ProxyCountryCode"] | null;
|
|
297
298
|
/**
|
|
298
299
|
* Timeout
|
|
299
300
|
* @description The timeout for the session in minutes. All users can use up to 240 minutes (4 hours). Pay As You Go users are charged $0.06/hour, subscribers get 50% off.
|
|
@@ -318,7 +319,7 @@ interface components {
|
|
|
318
319
|
allowResizing: boolean;
|
|
319
320
|
/**
|
|
320
321
|
* Custom Proxy
|
|
321
|
-
* @description Custom proxy settings to use for the session. If not provided, our proxies will be used. Custom proxies are only available
|
|
322
|
+
* @description Custom proxy settings to use for the session. If not provided, our proxies will be used. Custom proxies are only available on the Custom Enterprise plan.
|
|
322
323
|
*/
|
|
323
324
|
customProxy?: components["schemas"]["CustomProxy"] | null;
|
|
324
325
|
/**
|
|
@@ -340,9 +341,10 @@ interface components {
|
|
|
340
341
|
profileId?: string | null;
|
|
341
342
|
/**
|
|
342
343
|
* Proxy Country Code
|
|
343
|
-
* @description Country code for proxy location.
|
|
344
|
+
* @description Country code for proxy location. Defaults to US. Set to null to disable proxy.
|
|
345
|
+
* @default us
|
|
344
346
|
*/
|
|
345
|
-
proxyCountryCode
|
|
347
|
+
proxyCountryCode: components["schemas"]["ProxyCountryCode"] | null;
|
|
346
348
|
/**
|
|
347
349
|
* Start URL
|
|
348
350
|
* @description URL to navigate to when the session starts.
|
|
@@ -372,7 +374,7 @@ interface components {
|
|
|
372
374
|
keepAlive: boolean;
|
|
373
375
|
/**
|
|
374
376
|
* Custom Proxy
|
|
375
|
-
* @description Custom proxy settings to use for the session. If not provided, our proxies will be used. Custom proxies are only available
|
|
377
|
+
* @description Custom proxy settings to use for the session. If not provided, our proxies will be used. Custom proxies are only available on the Custom Enterprise plan.
|
|
376
378
|
*/
|
|
377
379
|
customProxy?: components["schemas"]["CustomProxy"] | null;
|
|
378
380
|
/**
|
|
@@ -887,6 +889,11 @@ interface components {
|
|
|
887
889
|
* @description Optional name for the profile
|
|
888
890
|
*/
|
|
889
891
|
name?: string | null;
|
|
892
|
+
/**
|
|
893
|
+
* User ID
|
|
894
|
+
* @description Your internal user identifier for this profile. Use this to associate a profile with a user in your system.
|
|
895
|
+
*/
|
|
896
|
+
userId?: string | null;
|
|
890
897
|
};
|
|
891
898
|
/**
|
|
892
899
|
* ProfileListResponse
|
|
@@ -935,12 +942,18 @@ interface components {
|
|
|
935
942
|
* @description Optional name for the profile
|
|
936
943
|
*/
|
|
937
944
|
name?: string | null;
|
|
945
|
+
/**
|
|
946
|
+
* User ID
|
|
947
|
+
* @description Your internal user identifier for this profile. Use this to associate a profile with a user in your system.
|
|
948
|
+
*/
|
|
949
|
+
userId?: string | null;
|
|
938
950
|
};
|
|
939
951
|
/**
|
|
940
952
|
* ProfileView
|
|
941
953
|
* @description View model for representing a profile. A profile lets you preserve the login state between sessions.
|
|
942
954
|
*
|
|
943
955
|
* We recommend that you create a separate profile for each user of your app.
|
|
956
|
+
* You can assign a user_id to each profile to easily identify which user the profile belongs to.
|
|
944
957
|
*/
|
|
945
958
|
ProfileView: {
|
|
946
959
|
/**
|
|
@@ -949,6 +962,11 @@ interface components {
|
|
|
949
962
|
* @description Unique identifier for the profile
|
|
950
963
|
*/
|
|
951
964
|
id: string;
|
|
965
|
+
/**
|
|
966
|
+
* User ID
|
|
967
|
+
* @description Your internal user identifier for this profile. Use this to associate a profile with a user in your system.
|
|
968
|
+
*/
|
|
969
|
+
userId?: string | null;
|
|
952
970
|
/**
|
|
953
971
|
* Name
|
|
954
972
|
* @description Optional name for the profile
|
|
@@ -1136,9 +1154,10 @@ interface components {
|
|
|
1136
1154
|
profileId?: string | null;
|
|
1137
1155
|
/**
|
|
1138
1156
|
* Proxy Country Code
|
|
1139
|
-
* @description Proxy country code for geo-targeted browsing.
|
|
1157
|
+
* @description Proxy country code for geo-targeted browsing. Defaults to US. Set to null to disable proxy.
|
|
1158
|
+
* @default us
|
|
1140
1159
|
*/
|
|
1141
|
-
proxyCountryCode
|
|
1160
|
+
proxyCountryCode: components["schemas"]["ProxyCountryCode"] | null;
|
|
1142
1161
|
/**
|
|
1143
1162
|
* Browser Screen Width
|
|
1144
1163
|
* @description Custom screen width in pixels for the browser.
|
|
@@ -1769,10 +1788,11 @@ interface components {
|
|
|
1769
1788
|
* CREATED: Task has been created but not yet started.
|
|
1770
1789
|
* STARTED: Task has been started and is currently running.
|
|
1771
1790
|
* FINISHED: Task has finished and the agent has completed the task.
|
|
1791
|
+
* FAILED: Task execution failed due to an error.
|
|
1772
1792
|
* STOPPED: Task execution has been manually stopped (cannot be resumed).
|
|
1773
1793
|
* @enum {string}
|
|
1774
1794
|
*/
|
|
1775
|
-
TaskStatus: "created" | "started" | "finished" | "stopped";
|
|
1795
|
+
TaskStatus: "created" | "started" | "finished" | "failed" | "stopped";
|
|
1776
1796
|
/**
|
|
1777
1797
|
* TaskStatusView
|
|
1778
1798
|
* @description Lightweight view optimized for polling. Use GET /tasks/{id}/status for efficient polling
|
|
@@ -1851,6 +1871,11 @@ interface components {
|
|
|
1851
1871
|
* @description List of stringified json actions performed by the agent in this step
|
|
1852
1872
|
*/
|
|
1853
1873
|
actions: string[];
|
|
1874
|
+
/**
|
|
1875
|
+
* Duration
|
|
1876
|
+
* @description Duration of the step in seconds. Calculated as the time elapsed from the previous step completion (or task start for the first step) to this step completion.
|
|
1877
|
+
*/
|
|
1878
|
+
duration?: number | null;
|
|
1854
1879
|
};
|
|
1855
1880
|
/**
|
|
1856
1881
|
* TaskUpdateAction
|
|
@@ -2196,6 +2221,7 @@ type ProfileView$1 = components["schemas"]["ProfileView"];
|
|
|
2196
2221
|
interface ProfileListParams {
|
|
2197
2222
|
pageSize?: number;
|
|
2198
2223
|
pageNumber?: number;
|
|
2224
|
+
query?: string;
|
|
2199
2225
|
}
|
|
2200
2226
|
declare class Profiles {
|
|
2201
2227
|
private readonly http;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../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"],"sourcesContent":["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}\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"],"mappings":";;;;;;AAAA,SAAS,SAAS;;;ACKX,IAAM,UAAN,MAAc;AAAA,EACnB,YAA6B,MAAkB;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SAAK,WAAW,IAAI,SAAS,KAAK,IAAI;AACtC,SAAK,QAAQ,IAAI,MAAM,KAAK,IAAI;AAChC,SAAK,WAAW,IAAI,SAAS,KAAK,IAAI;AACtC,SAAK,WAAW,IAAI,SAAS,KAAK,IAAI;AACtC,SAAK,SAAS,IAAI,OAAO,KAAK,IAAI;AAClC,SAAK,cAAc,IAAI,YAAY,KAAK,IAAI;AAAA,EAC9C;AAAA,EAoBA,IAAI,MAAc,SAAwC;AACxD,UAAM,EAAE,QAAQ,SAAS,UAAU,GAAG,KAAK,IAAI,WAAW,CAAC;AAC3D,UAAM,OAAuB,EAAE,MAAM,GAAG,KAAK;AAC7C,QAAI,QAAQ;AACV,WAAK,mBAAmB,KAAK,UAAU,EAAE,aAAa,MAAM,CAAC;AAAA,IAC/D;AACA,UAAM,UAAU,KAAK,MAAM,OAAO,IAAI;AACtC,WAAO,IAAI,QAAQ,SAAS,KAAK,OAAO,QAAQ,EAAE,SAAS,SAAS,CAAC;AAAA,EACvE;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../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"],"sourcesContent":["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"],"mappings":";;;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AAI,QAAQ,KAAK,IAAI;AACpC,SAAK,QAAQ,IAAI,MAAM,KAAK,IAAI;AAChC,SAAK,WAAW,IAAI,SAAS,KAAK,IAAI;AACtC,SAAK,QAAQ,IAAI,MAAM,KAAK,IAAI;AAChC,SAAK,WAAW,IAAI,SAAS,KAAK,IAAI;AACtC,SAAK,WAAW,IAAI,SAAS,KAAK,IAAI;AACtC,SAAK,SAAS,IAAI,OAAO,KAAK,IAAI;AAClC,SAAK,cAAc,IAAI,YAAY,KAAK,IAAI;AAAA,EAC9C;AAAA,EAoBA,IAAI,MAAc,SAAwC;AACxD,UAAM,EAAE,QAAQ,SAAS,UAAU,GAAG,KAAK,IAAI,WAAW,CAAC;AAC3D,UAAM,OAAuB,EAAE,MAAM,GAAG,KAAK;AAC7C,QAAI,QAAQ;AACV,WAAK,mBAAmB,KAAK,UAAU,EAAE,aAAa,MAAM,CAAC;AAAA,IAC/D;AACA,UAAM,UAAU,KAAK,MAAM,OAAO,IAAI;AACtC,WAAO,IAAI,QAAQ,SAAS,KAAK,OAAO,QAAQ,EAAE,SAAS,SAAS,CAAC;AAAA,EACvE;AACF;","names":[]}
|
package/dist/v3.cjs
CHANGED
|
@@ -6,6 +6,71 @@ var _chunkRIRVOEIUcjs = require('./chunk-RIRVOEIU.cjs');
|
|
|
6
6
|
// src/v3/client.ts
|
|
7
7
|
var _zod = require('zod');
|
|
8
8
|
|
|
9
|
+
// src/v3/resources/billing.ts
|
|
10
|
+
var Billing = class {
|
|
11
|
+
constructor(http) {
|
|
12
|
+
this.http = http;
|
|
13
|
+
}
|
|
14
|
+
/** Get account billing information. */
|
|
15
|
+
account() {
|
|
16
|
+
return this.http.get("/billing/account");
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// src/v3/resources/browsers.ts
|
|
21
|
+
var Browsers = class {
|
|
22
|
+
constructor(http) {
|
|
23
|
+
this.http = http;
|
|
24
|
+
}
|
|
25
|
+
/** Create a standalone browser session. */
|
|
26
|
+
create(body) {
|
|
27
|
+
return this.http.post("/browsers", body);
|
|
28
|
+
}
|
|
29
|
+
/** List browser sessions for the authenticated project. */
|
|
30
|
+
list(params) {
|
|
31
|
+
return this.http.get("/browsers", params);
|
|
32
|
+
}
|
|
33
|
+
/** Get browser session details. */
|
|
34
|
+
get(sessionId) {
|
|
35
|
+
return this.http.get(`/browsers/${sessionId}`);
|
|
36
|
+
}
|
|
37
|
+
/** Update a browser session (e.g. stop it). */
|
|
38
|
+
update(sessionId, body) {
|
|
39
|
+
return this.http.patch(`/browsers/${sessionId}`, body);
|
|
40
|
+
}
|
|
41
|
+
/** Stop a browser session. Convenience wrapper around update. */
|
|
42
|
+
stop(sessionId) {
|
|
43
|
+
return this.update(sessionId, { action: "stop" });
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/v3/resources/profiles.ts
|
|
48
|
+
var Profiles = class {
|
|
49
|
+
constructor(http) {
|
|
50
|
+
this.http = http;
|
|
51
|
+
}
|
|
52
|
+
/** Create a browser profile. */
|
|
53
|
+
create(body) {
|
|
54
|
+
return this.http.post("/profiles", body);
|
|
55
|
+
}
|
|
56
|
+
/** List profiles for the authenticated project. */
|
|
57
|
+
list(params) {
|
|
58
|
+
return this.http.get("/profiles", params);
|
|
59
|
+
}
|
|
60
|
+
/** Get profile details. */
|
|
61
|
+
get(profileId) {
|
|
62
|
+
return this.http.get(`/profiles/${profileId}`);
|
|
63
|
+
}
|
|
64
|
+
/** Update a profile. */
|
|
65
|
+
update(profileId, body) {
|
|
66
|
+
return this.http.patch(`/profiles/${profileId}`, body);
|
|
67
|
+
}
|
|
68
|
+
/** Delete a profile. */
|
|
69
|
+
delete(profileId) {
|
|
70
|
+
return this.http.delete(`/profiles/${profileId}`);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
9
74
|
// src/v3/resources/sessions.ts
|
|
10
75
|
var Sessions = class {
|
|
11
76
|
constructor(http) {
|
|
@@ -13,7 +78,7 @@ var Sessions = class {
|
|
|
13
78
|
}
|
|
14
79
|
/** Create a session and optionally dispatch a task. */
|
|
15
80
|
create(body) {
|
|
16
|
-
return this.http.post("/sessions", body);
|
|
81
|
+
return this.http.post("/sessions", _nullishCoalesce(body, () => ( {})));
|
|
17
82
|
}
|
|
18
83
|
/** List sessions for the authenticated project. */
|
|
19
84
|
list(params) {
|
|
@@ -49,9 +114,69 @@ var Sessions = class {
|
|
|
49
114
|
params
|
|
50
115
|
);
|
|
51
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Poll until recording URLs are available. Returns presigned MP4 URLs.
|
|
119
|
+
*
|
|
120
|
+
* Returns an empty array if no recording was produced (e.g. the agent
|
|
121
|
+
* answered without opening a browser, or recording was not enabled).
|
|
122
|
+
*/
|
|
123
|
+
async waitForRecording(sessionId, options) {
|
|
124
|
+
const timeout = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _ => _.timeout]), () => ( 15e3));
|
|
125
|
+
const interval = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _2 => _2.interval]), () => ( 2e3));
|
|
126
|
+
const deadline = Date.now() + timeout;
|
|
127
|
+
while (Date.now() < deadline) {
|
|
128
|
+
const session = await this.get(sessionId);
|
|
129
|
+
if (_optionalChain([session, 'access', _3 => _3.recordingUrls, 'optionalAccess', _4 => _4.length])) return session.recordingUrls;
|
|
130
|
+
const remaining = deadline - Date.now();
|
|
131
|
+
if (remaining <= 0) break;
|
|
132
|
+
await new Promise((r) => setTimeout(r, Math.min(interval, remaining)));
|
|
133
|
+
}
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
52
136
|
};
|
|
53
137
|
|
|
54
138
|
// src/v3/resources/workspaces.ts
|
|
139
|
+
var _fs = require('fs');
|
|
140
|
+
var _path = require('path');
|
|
141
|
+
function safeJoin(base, untrusted) {
|
|
142
|
+
const baseResolved = _path.resolve.call(void 0, base) + "/";
|
|
143
|
+
const resolved = _path.resolve.call(void 0, base, untrusted);
|
|
144
|
+
if (resolved !== _path.resolve.call(void 0, base) && !resolved.startsWith(baseResolved)) {
|
|
145
|
+
throw new Error(`Path traversal detected: ${untrusted}`);
|
|
146
|
+
}
|
|
147
|
+
return resolved;
|
|
148
|
+
}
|
|
149
|
+
var MIME_TYPES = {
|
|
150
|
+
".csv": "text/csv",
|
|
151
|
+
".json": "application/json",
|
|
152
|
+
".txt": "text/plain",
|
|
153
|
+
".md": "text/markdown",
|
|
154
|
+
".html": "text/html",
|
|
155
|
+
".xml": "application/xml",
|
|
156
|
+
".yaml": "application/yaml",
|
|
157
|
+
".yml": "application/yaml",
|
|
158
|
+
".pdf": "application/pdf",
|
|
159
|
+
".png": "image/png",
|
|
160
|
+
".jpg": "image/jpeg",
|
|
161
|
+
".jpeg": "image/jpeg",
|
|
162
|
+
".gif": "image/gif",
|
|
163
|
+
".webp": "image/webp",
|
|
164
|
+
".svg": "image/svg+xml",
|
|
165
|
+
".mp4": "video/mp4",
|
|
166
|
+
".mp3": "audio/mpeg",
|
|
167
|
+
".wav": "audio/wav",
|
|
168
|
+
".zip": "application/zip",
|
|
169
|
+
".gz": "application/gzip",
|
|
170
|
+
".tar": "application/x-tar",
|
|
171
|
+
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
172
|
+
".xls": "application/vnd.ms-excel",
|
|
173
|
+
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
174
|
+
".doc": "application/msword",
|
|
175
|
+
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
|
176
|
+
};
|
|
177
|
+
function guessContentType(path) {
|
|
178
|
+
return _nullishCoalesce(MIME_TYPES[_path.extname.call(void 0, path).toLowerCase()], () => ( "application/octet-stream"));
|
|
179
|
+
}
|
|
55
180
|
var Workspaces = class {
|
|
56
181
|
constructor(http) {
|
|
57
182
|
this.http = http;
|
|
@@ -99,6 +224,79 @@ var Workspaces = class {
|
|
|
99
224
|
size(workspaceId) {
|
|
100
225
|
return this.http.get(`/workspaces/${workspaceId}/size`);
|
|
101
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Upload local files to a workspace. Returns the list of remote paths.
|
|
229
|
+
*
|
|
230
|
+
* ```ts
|
|
231
|
+
* await client.workspaces.upload(wsId, "data.csv", "config.json");
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
async upload(workspaceId, ...paths) {
|
|
235
|
+
const items = paths.map((p) => ({
|
|
236
|
+
name: _path.basename.call(void 0, p),
|
|
237
|
+
contentType: guessContentType(p),
|
|
238
|
+
size: _fs.statSync.call(void 0, p).size
|
|
239
|
+
}));
|
|
240
|
+
const resp = await this.uploadFiles(workspaceId, { files: items });
|
|
241
|
+
for (let i = 0; i < paths.length; i++) {
|
|
242
|
+
const body = _fs.readFileSync.call(void 0, paths[i]);
|
|
243
|
+
const res = await fetch(resp.files[i].uploadUrl, {
|
|
244
|
+
method: "PUT",
|
|
245
|
+
headers: { "Content-Type": items[i].contentType },
|
|
246
|
+
body
|
|
247
|
+
});
|
|
248
|
+
if (!res.ok) throw new Error(`Upload failed: ${res.status} ${res.statusText}`);
|
|
249
|
+
}
|
|
250
|
+
return resp.files.map((f) => f.path);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Download a single file from a workspace. Returns the local path.
|
|
254
|
+
*
|
|
255
|
+
* ```ts
|
|
256
|
+
* const local = await client.workspaces.download(wsId, "uploads/data.csv", { to: "./data.csv" });
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
async download(workspaceId, path, options) {
|
|
260
|
+
const fileList = await this.files(workspaceId, { prefix: path, includeUrls: true });
|
|
261
|
+
const match = _optionalChain([fileList, 'access', _5 => _5.files, 'optionalAccess', _6 => _6.find, 'call', _7 => _7((f) => f.path === path)]);
|
|
262
|
+
if (!match) throw new Error(`File not found in workspace: ${path}`);
|
|
263
|
+
const dest = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _8 => _8.to]), () => ( _path.basename.call(void 0, match.path)));
|
|
264
|
+
_fs.mkdirSync.call(void 0, _path.dirname.call(void 0, dest), { recursive: true });
|
|
265
|
+
const resp = await fetch(match.url);
|
|
266
|
+
if (!resp.ok) throw new Error(`Download failed: ${resp.status}`);
|
|
267
|
+
_fs.writeFileSync.call(void 0, dest, Buffer.from(await resp.arrayBuffer()));
|
|
268
|
+
return dest;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Download all files from a workspace. Returns list of local paths.
|
|
272
|
+
*
|
|
273
|
+
* ```ts
|
|
274
|
+
* const paths = await client.workspaces.downloadAll(wsId, { to: "./output" });
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
async downloadAll(workspaceId, options) {
|
|
278
|
+
const destDir = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _9 => _9.to]), () => ( "."));
|
|
279
|
+
_fs.mkdirSync.call(void 0, destDir, { recursive: true });
|
|
280
|
+
const results = [];
|
|
281
|
+
let cursor;
|
|
282
|
+
do {
|
|
283
|
+
const fileList = await this.files(workspaceId, {
|
|
284
|
+
prefix: _optionalChain([options, 'optionalAccess', _10 => _10.prefix]),
|
|
285
|
+
includeUrls: true,
|
|
286
|
+
cursor
|
|
287
|
+
});
|
|
288
|
+
for (const f of _nullishCoalesce(fileList.files, () => ( []))) {
|
|
289
|
+
const local = safeJoin(destDir, f.path);
|
|
290
|
+
_fs.mkdirSync.call(void 0, _path.dirname.call(void 0, local), { recursive: true });
|
|
291
|
+
const resp = await fetch(f.url);
|
|
292
|
+
if (!resp.ok) throw new Error(`Download failed for ${f.path}: ${resp.status}`);
|
|
293
|
+
_fs.writeFileSync.call(void 0, local, Buffer.from(await resp.arrayBuffer()));
|
|
294
|
+
results.push(local);
|
|
295
|
+
}
|
|
296
|
+
cursor = fileList.hasMore ? _nullishCoalesce(fileList.nextCursor, () => ( void 0)) : void 0;
|
|
297
|
+
} while (cursor);
|
|
298
|
+
return results;
|
|
299
|
+
}
|
|
102
300
|
};
|
|
103
301
|
|
|
104
302
|
// src/v3/helpers.ts
|
|
@@ -115,8 +313,8 @@ var SessionRun = (_class = class {
|
|
|
115
313
|
this._createPromise = createPromise;
|
|
116
314
|
this._sessions = sessions;
|
|
117
315
|
this._schema = schema;
|
|
118
|
-
this._timeout = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
119
|
-
this._interval = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
316
|
+
this._timeout = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _11 => _11.timeout]), () => ( 144e5));
|
|
317
|
+
this._interval = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _12 => _12.interval]), () => ( 2e3));
|
|
120
318
|
}
|
|
121
319
|
/** The session ID, available after task creation resolves. */
|
|
122
320
|
get sessionId() {
|
|
@@ -158,6 +356,40 @@ var SessionRun = (_class = class {
|
|
|
158
356
|
`Session ${sessionId} did not complete within ${this._timeout}ms`
|
|
159
357
|
);
|
|
160
358
|
}
|
|
359
|
+
/**
|
|
360
|
+
* Enable `for await (const msg of client.run(...))` — yields messages as they appear.
|
|
361
|
+
* After iteration, `.result` contains the final SessionResult.
|
|
362
|
+
*/
|
|
363
|
+
async *[Symbol.asyncIterator]() {
|
|
364
|
+
const sessionId = await this._ensureSessionId();
|
|
365
|
+
let cursor;
|
|
366
|
+
const deadline = Date.now() + this._timeout;
|
|
367
|
+
while (Date.now() < deadline) {
|
|
368
|
+
const resp = await this._sessions.messages(sessionId, { after: cursor, limit: 100 });
|
|
369
|
+
for (const msg of resp.messages) {
|
|
370
|
+
yield msg;
|
|
371
|
+
cursor = msg.id;
|
|
372
|
+
}
|
|
373
|
+
const session = await this._sessions.get(sessionId);
|
|
374
|
+
if (TERMINAL_STATUSES.has(session.status)) {
|
|
375
|
+
while (true) {
|
|
376
|
+
const page = await this._sessions.messages(sessionId, { after: cursor, limit: 100 });
|
|
377
|
+
if (!page.messages.length) break;
|
|
378
|
+
for (const msg of page.messages) {
|
|
379
|
+
yield msg;
|
|
380
|
+
cursor = msg.id;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
const { output, ...rest } = session;
|
|
384
|
+
this._result = { ...rest, output: this._parseOutput(output) };
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
const remaining = deadline - Date.now();
|
|
388
|
+
if (remaining <= 0) break;
|
|
389
|
+
await new Promise((r) => setTimeout(r, Math.min(this._interval, remaining)));
|
|
390
|
+
}
|
|
391
|
+
throw new Error(`Session ${sessionId} did not complete within ${this._timeout}ms`);
|
|
392
|
+
}
|
|
161
393
|
_parseOutput(output) {
|
|
162
394
|
if (output == null) return null;
|
|
163
395
|
if (!this._schema) return output;
|
|
@@ -172,6 +404,9 @@ var BrowserUse = class {
|
|
|
172
404
|
|
|
173
405
|
|
|
174
406
|
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
175
410
|
constructor(options = {}) {
|
|
176
411
|
const apiKey = _nullishCoalesce(_nullishCoalesce(options.apiKey, () => ( process.env.BROWSER_USE_API_KEY)), () => ( ""));
|
|
177
412
|
if (!apiKey) {
|
|
@@ -185,6 +420,9 @@ var BrowserUse = class {
|
|
|
185
420
|
maxRetries: options.maxRetries,
|
|
186
421
|
timeout: options.timeout
|
|
187
422
|
});
|
|
423
|
+
this.billing = new Billing(this.http);
|
|
424
|
+
this.browsers = new Browsers(this.http);
|
|
425
|
+
this.profiles = new Profiles(this.http);
|
|
188
426
|
this.sessions = new Sessions(this.http);
|
|
189
427
|
this.workspaces = new Workspaces(this.http);
|
|
190
428
|
}
|
|
@@ -194,6 +432,9 @@ var BrowserUse = class {
|
|
|
194
432
|
if (schema) {
|
|
195
433
|
body.outputSchema = _zod.z.toJSONSchema(schema);
|
|
196
434
|
}
|
|
435
|
+
if (body.sessionId && body.keepAlive === void 0) {
|
|
436
|
+
body.keepAlive = true;
|
|
437
|
+
}
|
|
197
438
|
const promise = this.sessions.create(body);
|
|
198
439
|
return new SessionRun(promise, this.sessions, schema, { timeout, interval });
|
|
199
440
|
}
|
|
@@ -204,5 +445,8 @@ var BrowserUse = class {
|
|
|
204
445
|
|
|
205
446
|
|
|
206
447
|
|
|
207
|
-
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
exports.Billing = Billing; exports.BrowserUse = BrowserUse; exports.BrowserUseError = _chunkRIRVOEIUcjs.BrowserUseError; exports.Browsers = Browsers; exports.Profiles = Profiles; exports.SessionRun = SessionRun; exports.Sessions = Sessions; exports.Workspaces = Workspaces;
|
|
208
452
|
//# sourceMappingURL=v3.cjs.map
|