browser-use-sdk 3.0.3 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -171,6 +171,10 @@ var Sessions = class {
171
171
  deleteShare(sessionId) {
172
172
  return this.http.delete(`/sessions/${sessionId}/public-share`);
173
173
  }
174
+ /** Purge all session data (ZDR projects only). */
175
+ purge(sessionId) {
176
+ return this.http.post(`/sessions/${sessionId}/purge`);
177
+ }
174
178
  };
175
179
 
176
180
  // src/v2/resources/skills.ts
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/greg/Documents/browser-use/core/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,EAGhD,OAAA,CAAA,EAAgC;AAC9B,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAAiB,kBAAkB,CAAA;AAAA,EACtD;AACF,CAAA;AFMA;AACA;AGHO,IAAM,SAAA,EAAN,MAAe;AAAA,EACpB,WAAA,CAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,KAAA,EAAA,IAAA;AAAA,EAAmB;AAAA;AAAA,EAGhD,MAAA,CAAO,KAAA,EAA0B,CAAC,CAAA,EAAoC;AACpE,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,IAAA,CAA6B,WAAA,EAAa,IAAI,CAAA;AA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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;AV6RgD;AACA;ACpWvB;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;ADoUgD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/greg/Documents/browser-use/core/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}\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","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"]}
1
+ {"version":3,"sources":["/Users/greg/Documents/browser-use/core/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,EAGhD,OAAA,CAAA,EAAgC;AAC9B,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAAiB,kBAAkB,CAAA;AAAA,EACtD;AACF,CAAA;AFMA;AACA;AGHO,IAAM,SAAA,EAAN,MAAe;AAAA,EACpB,WAAA,CAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,KAAA,EAAA,IAAA;AAAA,EAAmB;AAAA;AAAA,EAGhD,MAAA,CAAO,KAAA,EAA0B,CAAC,CAAA,EAAoC;AACpE,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,IAAA,CAA6B,WAAA,EAAa,IAAI,CAAA;AAAA,EACjE;AAAA;AAAA,EAGA,IAAA,CAAK,MAAA,EAAiE;AACpE,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA;AAAA,MACf,WAAA;AAAA,MACA;AAAA,IACF,CAAA;AAAA,EACF;AAAA;AAAA,EAGA,GAAA,CAAI,SAAA,EAAgD;AAClD,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAAwB,CAAA,UAAA,EAAa,SAAS,CAAA,CAAA;AACjE,EAAA;AAAA;AAG0F,EAAA;AAChC,IAAA;AAC1D,EAAA;AAAA;AAGqD,EAAA;AACX,IAAA;AAC1C,EAAA;AACF;AHEgD;AACA;AI1C7B;AAC8B,EAAA;AAAlB,IAAA;AAAmB,EAAA;AAAA;AAGgD,EAAA;AAC7E,IAAA;AACa,MAAA;AAC5B,MAAA;AACF,IAAA;A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A;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/greg/Documents/browser-use/core/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}\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"]}
package/dist/index.d.cts CHANGED
@@ -118,6 +118,11 @@ interface components {
118
118
  * @default 0
119
119
  */
120
120
  browserCost: string;
121
+ /**
122
+ * Agent Session ID
123
+ * @description ID of the agent session that created this browser (None for standalone BaaS sessions)
124
+ */
125
+ agentSessionId?: string | null;
121
126
  };
122
127
  /**
123
128
  * BrowserSessionListResponse
@@ -225,6 +230,11 @@ interface components {
225
230
  * @default 0
226
231
  */
227
232
  browserCost: string;
233
+ /**
234
+ * Agent Session ID
235
+ * @description ID of the agent session that created this browser (None for standalone BaaS sessions)
236
+ */
237
+ agentSessionId?: string | null;
228
238
  };
229
239
  /**
230
240
  * CannotDeleteSkillWhileGeneratingError
@@ -2197,6 +2207,8 @@ declare class Sessions {
2197
2207
  createShare(sessionId: string): Promise<ShareView$1>;
2198
2208
  /** Remove public share for a session. */
2199
2209
  deleteShare(sessionId: string): Promise<void>;
2210
+ /** Purge all session data (ZDR projects only). */
2211
+ purge(sessionId: string): Promise<void>;
2200
2212
  }
2201
2213
 
2202
2214
  type CreateSkillRequest$1 = components["schemas"]["CreateSkillRequest"];
package/dist/index.d.ts CHANGED
@@ -118,6 +118,11 @@ interface components {
118
118
  * @default 0
119
119
  */
120
120
  browserCost: string;
121
+ /**
122
+ * Agent Session ID
123
+ * @description ID of the agent session that created this browser (None for standalone BaaS sessions)
124
+ */
125
+ agentSessionId?: string | null;
121
126
  };
122
127
  /**
123
128
  * BrowserSessionListResponse
@@ -225,6 +230,11 @@ interface components {
225
230
  * @default 0
226
231
  */
227
232
  browserCost: string;
233
+ /**
234
+ * Agent Session ID
235
+ * @description ID of the agent session that created this browser (None for standalone BaaS sessions)
236
+ */
237
+ agentSessionId?: string | null;
228
238
  };
229
239
  /**
230
240
  * CannotDeleteSkillWhileGeneratingError
@@ -2197,6 +2207,8 @@ declare class Sessions {
2197
2207
  createShare(sessionId: string): Promise<ShareView$1>;
2198
2208
  /** Remove public share for a session. */
2199
2209
  deleteShare(sessionId: string): Promise<void>;
2210
+ /** Purge all session data (ZDR projects only). */
2211
+ purge(sessionId: string): Promise<void>;
2200
2212
  }
2201
2213
 
2202
2214
  type CreateSkillRequest$1 = components["schemas"]["CreateSkillRequest"];
package/dist/index.js CHANGED
@@ -171,6 +171,10 @@ var Sessions = class {
171
171
  deleteShare(sessionId) {
172
172
  return this.http.delete(`/sessions/${sessionId}/public-share`);
173
173
  }
174
+ /** Purge all session data (ZDR projects only). */
175
+ purge(sessionId) {
176
+ return this.http.post(`/sessions/${sessionId}/purge`);
177
+ }
174
178
  };
175
179
 
176
180
  // src/v2/resources/skills.ts
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","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;AAAlB;AAAA,EAAmB;AAAA;AAAA,EAGhD,UAAgC;AAC9B,WAAO,KAAK,KAAK,IAAiB,kBAAkB;AAAA,EACtD;AACF;;;ACIO,IAAM,WAAN,MAAe;AAAA,EACpB,YAA6B,MAAkB;AAAlB;AAAA,EAAmB;AAAA;AAAA,EAGhD,OAAO,OAA0B,CAAC,GAAoC;AACpE,WAAO,KAAK,KAAK,KAA6B,aAAa,IAAI;AAAA,EACjE;AAAA;AAAA,EAGA,KAAK,QAAiE;AACpE,WAAO,KAAK,KAAK;AAAA,MACf;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA;AAAA,EAGA,IAAI,WAAgD;AAClD,WAAO,KAAK,KAAK,IAAwB,aAAa,SAAS,EAAE;AAAA,EACnE;AAAA;AAAA,EAGA,OAAO,WAAmB,MAAgE;AACxF,WAAO,KAAK,KAAK,MAA0B,aAAa,SAAS,IAAI,IAAI;AAAA,EAC3E;AAAA;AAAA,EAGA,KAAK,WAAgD;AACnD,WAAO,KAAK,OAAO,WAAW,EAAE,QAAQ,OAAO,CAAC;AAAA,EAClD;AACF;;;ACvCO,IAAM,QAAN,MAAY;AAAA,EACjB,YAA6B,MAAkB;AAAlB;AAAA,EAAmB;AAAA;AAAA,EAGhD,WAAW,WAAmB,MAAkE;AAC9F,WAAO,KAAK,KAAK;AAAA,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AuB;AACvD,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AACA,SAAK,OAAO,IAAI,WAAW;AAAA,MACzB;AAAA,MACA,SAAS,QAAQ,WAAW;AAAA,MAC5B,YAAY,QAAQ;AAAA,MACpB,SAAS,QAAQ;AAAA,IACnB,CAAC;AAED,SAAK,UAAU,IAAI,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":[]}
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;AAAlB;AAAA,EAAmB;AAAA;AAAA,EAGhD,UAAgC;AAC9B,WAAO,KAAK,KAAK,IAAiB,kBAAkB;AAAA,EACtD;AACF;;;ACIO,IAAM,WAAN,MAAe;AAAA,EACpB,YAA6B,MAAkB;AAAlB;AAAA,EAAmB;AAAA;AAAA,EAGhD,OAAO,OAA0B,CAAC,GAAoC;AACpE,WAAO,KAAK,KAAK,KAA6B,aAAa,IAAI;AAAA,EACjE;AAAA;AAAA,EAGA,KAAK,QAAiE;AACpE,WAAO,KAAK,KAAK;AAAA,MACf;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA;AAAA,EAGA,IAAI,WAAgD;AAClD,WAAO,KAAK,KAAK,IAAwB,aAAa,SAAS,EAAE;AAAA,EACnE;AAAA;AAAA,EAGA,OAAO,WAAmB,MAAgE;AACxF,WAAO,KAAK,KAAK,MAA0B,aAAa,SAAS,IAAI,IAAI;AAAA,EAC3E;AAAA;AAAA,EAGA,KAAK,WAAgD;AACnD,WAAO,KAAK,OAAO,WAAW,EAAE,QAAQ,OAAO,CAAC;AAAA,EAClD;AACF;;;ACvCO,IAAM,QAAN,MAAY;AAAA,EACjB,YAA6B,MAAkB;AAAlB;AAAA,EAAmB;AAAA;AAAA,EAGhD,WAAW,WAAmB,MAAkE;AAC9F,WAAO,KAAK,KAAK;AAAA,MACf,mBAAmB,SAAS;AAAA,MAC5B;AA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AC,GAAG;AAC3C,UAAM,SACJ,QAAQ,UAAU,QAAQ,IAAI,uBAAuB;AACvD,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AACA,SAAK,OAAO,IAAI,WAAW;AAAA,MACzB;AAAA,MACA,SAAS,QAAQ,WAAW;AAAA,MAC5B,YAAY,QAAQ;AAAA,MACpB,SAAS,QAAQ;AAAA,IACnB,CAAC;AAED,SAAK,UAAU,IAAI,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
@@ -11,7 +11,7 @@ var Sessions = class {
11
11
  constructor(http) {
12
12
  this.http = http;
13
13
  }
14
- /** Create a session and run a task. */
14
+ /** Create a session and optionally dispatch a task. */
15
15
  create(body) {
16
16
  return this.http.post("/sessions", body);
17
17
  }
@@ -23,9 +23,17 @@ var Sessions = class {
23
23
  get(sessionId) {
24
24
  return this.http.get(`/sessions/${sessionId}`);
25
25
  }
26
- /** Stop a session. */
27
- stop(sessionId) {
28
- return this.http.post(`/sessions/${sessionId}/stop`);
26
+ /** Stop a session or the running task. */
27
+ stop(sessionId, body) {
28
+ return this.http.post(`/sessions/${sessionId}/stop`, body);
29
+ }
30
+ /** Soft-delete a session. */
31
+ delete(sessionId) {
32
+ return this.http.delete(`/sessions/${sessionId}`);
33
+ }
34
+ /** Get presigned upload URLs for session files. */
35
+ uploadFiles(sessionId, body) {
36
+ return this.http.post(`/sessions/${sessionId}/files/upload`, body);
29
37
  }
30
38
  /** List files in a session's workspace. */
31
39
  files(sessionId, params) {
@@ -34,6 +42,63 @@ var Sessions = class {
34
42
  params
35
43
  );
36
44
  }
45
+ /** List messages for a session with cursor-based pagination. */
46
+ messages(sessionId, params) {
47
+ return this.http.get(
48
+ `/sessions/${sessionId}/messages`,
49
+ params
50
+ );
51
+ }
52
+ };
53
+
54
+ // src/v3/resources/workspaces.ts
55
+ var Workspaces = class {
56
+ constructor(http) {
57
+ this.http = http;
58
+ }
59
+ /** List workspaces for the authenticated project. */
60
+ list(params) {
61
+ return this.http.get("/workspaces", params);
62
+ }
63
+ /** Create a new workspace. */
64
+ create(body) {
65
+ return this.http.post("/workspaces", body);
66
+ }
67
+ /** Get workspace details. */
68
+ get(workspaceId) {
69
+ return this.http.get(`/workspaces/${workspaceId}`);
70
+ }
71
+ /** Update a workspace. */
72
+ update(workspaceId, body) {
73
+ return this.http.patch(`/workspaces/${workspaceId}`, body);
74
+ }
75
+ /** Delete a workspace and its data. */
76
+ delete(workspaceId) {
77
+ return this.http.delete(`/workspaces/${workspaceId}`);
78
+ }
79
+ /** List files in a workspace. */
80
+ files(workspaceId, params) {
81
+ return this.http.get(
82
+ `/workspaces/${workspaceId}/files`,
83
+ params
84
+ );
85
+ }
86
+ /** Get presigned upload URLs for workspace files. */
87
+ uploadFiles(workspaceId, body, query) {
88
+ return this.http.post(
89
+ `/workspaces/${workspaceId}/files/upload`,
90
+ body,
91
+ query
92
+ );
93
+ }
94
+ /** Delete a file from a workspace. */
95
+ deleteFile(workspaceId, path) {
96
+ return this.http.delete(`/workspaces/${workspaceId}/files`, { path });
97
+ }
98
+ /** Get storage usage for a workspace. */
99
+ size(workspaceId) {
100
+ return this.http.get(`/workspaces/${workspaceId}/size`);
101
+ }
37
102
  };
38
103
 
39
104
  // src/v3/helpers.ts
@@ -106,6 +171,7 @@ var DEFAULT_BASE_URL = "https://api.browser-use.com/api/v3";
106
171
  var BrowserUse = class {
107
172
 
108
173
 
174
+
109
175
  constructor(options = {}) {
110
176
  const apiKey = _nullishCoalesce(_nullishCoalesce(options.apiKey, () => ( process.env.BROWSER_USE_API_KEY)), () => ( ""));
111
177
  if (!apiKey) {
@@ -120,6 +186,7 @@ var BrowserUse = class {
120
186
  timeout: options.timeout
121
187
  });
122
188
  this.sessions = new Sessions(this.http);
189
+ this.workspaces = new Workspaces(this.http);
123
190
  }
124
191
  run(task, options) {
125
192
  const { schema, timeout, interval, ...rest } = _nullishCoalesce(options, () => ( {}));
@@ -136,5 +203,6 @@ var BrowserUse = class {
136
203
 
137
204
 
138
205
 
139
- exports.BrowserUse = BrowserUse; exports.BrowserUseError = _chunkRIRVOEIUcjs.BrowserUseError; exports.SessionRun = SessionRun; exports.Sessions = Sessions;
206
+
207
+ exports.BrowserUse = BrowserUse; exports.BrowserUseError = _chunkRIRVOEIUcjs.BrowserUseError; exports.SessionRun = SessionRun; exports.Sessions = Sessions; exports.Workspaces = Workspaces;
140
208
  //# sourceMappingURL=v3.cjs.map
package/dist/v3.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/greg/Documents/browser-use/core/sdk/browser-use-node/dist/v3.cjs","../src/v3/client.ts","../src/v3/resources/sessions.ts","../src/v3/helpers.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACLA,0BAAkB;ADOlB;AACA;AEcO,IAAM,SAAA,EAAN,M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F,IAAA;AAEU,IAAA;AACY,MAAA;AACtB,IAAA;AACF,EAAA;AAEyC,EAAA;AACZ,IAAA;AACD,IAAA;AACe,IAAA;AACZ,IAAA;AAC/B,EAAA;AACF;AHAgD;AACA;AC9FvB;AAYD;AACb,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;AAEqC,IAAA;AACxC,EAAA;AAiBgE,EAAA;AACnB,IAAA;AACd,IAAA;AACjB,IAAA;AAC+B,MAAA;AAC3C,IAAA;AACyC,IAAA;AACL,IAAA;AACtC,EAAA;AACF;ADiEgD;AACA;AACA;AACA;AACA;AACA","file":"/Users/greg/Documents/browser-use/core/sdk/browser-use-node/dist/v3.cjs","sourcesContent":[null,"import { z } from \"zod\";\nimport { HttpClient } from \"../core/http.js\";\nimport { Sessions } from \"./resources/sessions.js\";\nimport { SessionRun } from \"./helpers.js\";\nimport type { components } from \"../generated/v3/types.js\";\nimport type { RunOptions } from \"./helpers.js\";\n\ntype RunTaskRequest = components[\"schemas\"][\"RunTaskRequest\"];\n\nconst DEFAULT_BASE_URL = \"https://api.browser-use.com/api/v3\";\n\nexport interface BrowserUseOptions {\n apiKey?: string;\n baseUrl?: string;\n maxRetries?: number;\n timeout?: number;\n}\n\nexport type RunSessionOptions = Partial<Omit<RunTaskRequest, \"task\">> &\n RunOptions & { schema?: z.ZodType };\n\nexport class BrowserUse {\n readonly sessions: Sessions;\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.sessions = new Sessions(this.http);\n }\n\n /**\n * Create a session and run a task. `await` the result for a typed SessionResult.\n *\n * ```ts\n * // Simple — just get the output\n * const result = await client.run(\"Find the top HN post\");\n * console.log(result.output);\n *\n * // Structured output (Zod)\n * const result = await client.run(\"Find product info\", { schema: ProductSchema });\n * console.log(result.output.name); // fully typed\n * ```\n */\n run(task: string, options?: Omit<RunSessionOptions, \"schema\">): SessionRun<string>;\n run<T extends z.ZodType>(task: string, options: RunSessionOptions & { schema: T }): SessionRun<z.output<T>>;\n run(task: string, options?: RunSessionOptions): SessionRun<any> {\n const { schema, timeout, interval, ...rest } = options ?? {};\n const body = { task, ...rest } as RunTaskRequest;\n if (schema) {\n body.outputSchema = z.toJSONSchema(schema) as Record<string, unknown>;\n }\n const promise = this.sessions.create(body);\n return new SessionRun(promise, this.sessions, schema, { timeout, interval });\n }\n}\n","import type { HttpClient } from \"../../core/http.js\";\nimport type { components } from \"../../generated/v3/types.js\";\n\ntype RunTaskRequest = components[\"schemas\"][\"RunTaskRequest\"];\n/** Like RunTaskRequest but only `task` is required; fields with server defaults are optional. */\nexport type CreateSessionBody = Pick<RunTaskRequest, \"task\"> & Partial<Omit<RunTaskRequest, \"task\">>;\ntype SessionResponse = components[\"schemas\"][\"SessionResponse\"];\ntype SessionListResponse = components[\"schemas\"][\"SessionListResponse\"];\ntype FileListResponse = components[\"schemas\"][\"FileListResponse\"];\n\nexport interface SessionListParams {\n page?: number;\n page_size?: number;\n}\n\nexport interface SessionFilesParams {\n prefix?: string;\n limit?: number;\n cursor?: string | null;\n includeUrls?: boolean;\n}\n\nexport class Sessions {\n constructor(private readonly http: HttpClient) {}\n\n /** Create a session and run a task. */\n create(body: CreateSessionBody): Promise<SessionResponse> {\n return this.http.post<SessionResponse>(\"/sessions\", body);\n }\n\n /** List sessions for the authenticated project. */\n list(params?: SessionListParams): Promise<SessionListResponse> {\n return this.http.get<SessionListResponse>(\"/sessions\", params as Record<string, unknown>);\n }\n\n /** Get session details. */\n get(sessionId: string): Promise<SessionResponse> {\n return this.http.get<SessionResponse>(`/sessions/${sessionId}`);\n }\n\n /** Stop a session. */\n stop(sessionId: string): Promise<SessionResponse> {\n return this.http.post<SessionResponse>(`/sessions/${sessionId}/stop`);\n }\n\n /** List files in a session's workspace. */\n files(sessionId: string, params?: SessionFilesParams): Promise<FileListResponse> {\n return this.http.get<FileListResponse>(\n `/sessions/${sessionId}/files`,\n params as Record<string, unknown>,\n );\n }\n}\n","import type { z } from \"zod\";\nimport type { components } from \"../generated/v3/types.js\";\nimport type { Sessions } from \"./resources/sessions.js\";\n\ntype SessionResponse = components[\"schemas\"][\"SessionResponse\"];\n\nconst TERMINAL_STATUSES = new Set([\"idle\", \"stopped\", \"timed_out\", \"error\"]);\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/** Session result with typed output. All SessionResponse fields are directly accessible. */\nexport type SessionResult<T = string | null> = Omit<SessionResponse, \"output\"> & { output: T };\n\n/**\n * Dual-purpose session handle: `await` it for a typed SessionResult,\n * or access `.result` for the full SessionResult after resolution.\n */\nexport class SessionRun<T = string> implements PromiseLike<SessionResult<T>> {\n private readonly _createPromise: Promise<SessionResponse>;\n private readonly _sessions: Sessions;\n private readonly _schema?: z.ZodType<T>;\n private readonly _timeout: number;\n private readonly _interval: number;\n private _sessionId: string | null = null;\n private _result: SessionResult<T> | null = null;\n\n constructor(\n createPromise: Promise<SessionResponse>,\n sessions: Sessions,\n schema?: z.ZodType<T>,\n options?: RunOptions,\n ) {\n this._createPromise = createPromise;\n this._sessions = sessions;\n this._schema = schema;\n this._timeout = options?.timeout ?? 300_000;\n this._interval = options?.interval ?? 2_000;\n }\n\n /** The session ID, available after task creation resolves. */\n get sessionId(): string | null {\n return this._sessionId;\n }\n\n /** The full SessionResult, available after polling completes. */\n get result(): SessionResult<T> | null {\n return this._result;\n }\n\n /** Enable `await client.run(...)` — polls until terminal, returns SessionResult. */\n then<R1 = SessionResult<T>, R2 = never>(\n onFulfilled?:\n | ((value: SessionResult<T>) => R1 | PromiseLike<R1>)\n | null,\n onRejected?: ((reason: unknown) => R2 | PromiseLike<R2>) | null,\n ): Promise<R1 | R2> {\n return this._waitForOutput().then(onFulfilled, onRejected);\n }\n\n private async _ensureSessionId(): Promise<string> {\n if (this._sessionId) return this._sessionId;\n const created = await this._createPromise;\n this._sessionId = created.id;\n return this._sessionId;\n }\n\n /** Poll session until terminal, return SessionResult. */\n private async _waitForOutput(): Promise<SessionResult<T>> {\n const sessionId = await this._ensureSessionId();\n const deadline = Date.now() + this._timeout;\n\n while (Date.now() < deadline) {\n const session = await this._sessions.get(sessionId);\n if (TERMINAL_STATUSES.has(session.status)) {\n const { output, ...rest } = session;\n const parsed = this._parseOutput(output);\n this._result = { ...rest, output: parsed } as SessionResult<T>;\n return this._result;\n }\n const remaining = deadline - Date.now();\n if (remaining <= 0) break;\n await new Promise((r) =>\n setTimeout(r, Math.min(this._interval, remaining)),\n );\n }\n\n throw new Error(\n `Session ${sessionId} did not complete within ${this._timeout}ms`,\n );\n }\n\n private _parseOutput(output: unknown): T {\n if (output == null) return null as T;\n if (!this._schema) return output as unknown as T;\n const raw = typeof output === \"string\" ? JSON.parse(output) : output;\n return this._schema.parse(raw);\n }\n}\n"]}
1
+ {"version":3,"sources":["/Users/greg/Documents/browser-use/core/sdk/browser-use-node/dist/v3.cjs","../src/v3/client.ts","../src/v3/resources/sessions.ts","../src/v3/resources/workspaces.ts","../src/v3/helpers.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACLA,0BAAkB;ADOlB;AACA;AEyBO,IAAM,SAAA,EAAN,MAAe;AAAA,EACpB,WAAA,CAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,KAAA,EAAA,IAAA;AAAA,EAAmB;AAAA;AAAA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;AACF;AHwBgD;AACA;AIjGd;AAgB2C;AAC1D,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACmB,iBAAA;AACO,kBAAA;AAMzC,EAAA;AAEsB,IAAA;AACL,IAAA;AACF,IAAA;AACqB,IAAA;AACE,IAAA;AACxC,EAAA;AAAA;AAG+B,EAAA;AACjB,IAAA;AACd,EAAA;AAAA;AAGsC,EAAA;AACxB,IAAA;AACd,EAAA;AAAA;AAQoB,EAAA;AACgB,IAAA;AACpC,EAAA;AAEkD,EAAA;AACf,IAAA;AACN,IAAA;AACD,IAAA;AACd,IAAA;AACd,EAAA;AAAA;AAG0D,EAAA;AAC3B,IAAA;AACM,IAAA;AAEL,IAAA;AACa,MAAA;AACD,MAAA;AACV,QAAA;AACW,QAAA;AACL,QAAA;AACtB,QAAA;AACd,MAAA;AACsC,MAAA;AAClB,MAAA;AACV,MAAA;AACoB,QAAA;AAC9B,MAAA;AACF,IAAA;AAEU,IAAA;AACY,MAAA;AACtB,IAAA;AACF,EAAA;AAEyC,EAAA;AACZ,IAAA;AACD,IAAA;AACe,IAAA;AACZ,IAAA;AAC/B,EAAA;AACF;AJiEgD;AACA;AC9JvB;AAYD;AACb,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;AAEqC,IAAA;AACI,IAAA;AAC5C,EAAA;AAiBgE,EAAA;AACnB,IAAA;AACd,IAAA;AACjB,IAAA;AAC+B,MAAA;AAC3C,IAAA;AACyC,IAAA;AACL,IAAA;AACtC,EAAA;AACF;ADiIgD;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/greg/Documents/browser-use/core/sdk/browser-use-node/dist/v3.cjs","sourcesContent":[null,"import { z } from \"zod\";\nimport { HttpClient } from \"../core/http.js\";\nimport { Sessions } from \"./resources/sessions.js\";\nimport { Workspaces } from \"./resources/workspaces.js\";\nimport { SessionRun } from \"./helpers.js\";\nimport type { components } from \"../generated/v3/types.js\";\nimport type { RunOptions } from \"./helpers.js\";\n\ntype RunTaskRequest = components[\"schemas\"][\"RunTaskRequest\"];\n\nconst DEFAULT_BASE_URL = \"https://api.browser-use.com/api/v3\";\n\nexport interface BrowserUseOptions {\n apiKey?: string;\n baseUrl?: string;\n maxRetries?: number;\n timeout?: number;\n}\n\nexport type RunSessionOptions = Partial<Omit<RunTaskRequest, \"task\">> &\n RunOptions & { schema?: z.ZodType };\n\nexport class BrowserUse {\n readonly sessions: Sessions;\n readonly workspaces: Workspaces;\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.sessions = new Sessions(this.http);\n this.workspaces = new Workspaces(this.http);\n }\n\n /**\n * Create a session and run a task. `await` the result for a typed SessionResult.\n *\n * ```ts\n * // Simple — just get the output\n * const result = await client.run(\"Find the top HN post\");\n * console.log(result.output);\n *\n * // Structured output (Zod)\n * const result = await client.run(\"Find product info\", { schema: ProductSchema });\n * console.log(result.output.name); // fully typed\n * ```\n */\n run(task: string, options?: Omit<RunSessionOptions, \"schema\">): SessionRun<string>;\n run<T extends z.ZodType>(task: string, options: RunSessionOptions & { schema: T }): SessionRun<z.output<T>>;\n run(task: string, options?: RunSessionOptions): SessionRun<any> {\n const { schema, timeout, interval, ...rest } = options ?? {};\n const body = { task, ...rest } as RunTaskRequest;\n if (schema) {\n body.outputSchema = z.toJSONSchema(schema) as Record<string, unknown>;\n }\n const promise = this.sessions.create(body);\n return new SessionRun(promise, this.sessions, schema, { timeout, interval });\n }\n}\n","import type { HttpClient } from \"../../core/http.js\";\nimport type { components } from \"../../generated/v3/types.js\";\n\ntype RunTaskRequest = components[\"schemas\"][\"RunTaskRequest\"];\n/** All fields optional — omit `task` to create an idle session. */\nexport type CreateSessionBody = Partial<RunTaskRequest>;\ntype SessionResponse = components[\"schemas\"][\"SessionResponse\"];\ntype SessionListResponse = components[\"schemas\"][\"SessionListResponse\"];\ntype FileListResponse = components[\"schemas\"][\"FileListResponse\"];\ntype StopSessionRequest = components[\"schemas\"][\"StopSessionRequest\"];\ntype FileUploadRequest = components[\"schemas\"][\"FileUploadRequest\"];\ntype FileUploadResponse = components[\"schemas\"][\"FileUploadResponse\"];\ntype MessageListResponse = components[\"schemas\"][\"MessageListResponse\"];\n\nexport interface SessionListParams {\n page?: number;\n page_size?: number;\n}\n\nexport interface SessionFilesParams {\n prefix?: string;\n limit?: number;\n cursor?: string | null;\n includeUrls?: boolean;\n shallow?: boolean;\n}\n\nexport interface SessionMessagesParams {\n after?: string | null;\n before?: string | null;\n limit?: number;\n}\n\nexport class Sessions {\n constructor(private readonly http: HttpClient) {}\n\n /** Create a session and optionally dispatch a task. */\n create(body?: CreateSessionBody): Promise<SessionResponse> {\n return this.http.post<SessionResponse>(\"/sessions\", body);\n }\n\n /** List sessions for the authenticated project. */\n list(params?: SessionListParams): Promise<SessionListResponse> {\n return this.http.get<SessionListResponse>(\"/sessions\", params as Record<string, unknown>);\n }\n\n /** Get session details. */\n get(sessionId: string): Promise<SessionResponse> {\n return this.http.get<SessionResponse>(`/sessions/${sessionId}`);\n }\n\n /** Stop a session or the running task. */\n stop(sessionId: string, body?: StopSessionRequest): Promise<SessionResponse> {\n return this.http.post<SessionResponse>(`/sessions/${sessionId}/stop`, body);\n }\n\n /** Soft-delete a session. */\n delete(sessionId: string): Promise<void> {\n return this.http.delete<void>(`/sessions/${sessionId}`);\n }\n\n /** Get presigned upload URLs for session files. */\n uploadFiles(sessionId: string, body: FileUploadRequest): Promise<FileUploadResponse> {\n return this.http.post<FileUploadResponse>(`/sessions/${sessionId}/files/upload`, body);\n }\n\n /** List files in a session's workspace. */\n files(sessionId: string, params?: SessionFilesParams): Promise<FileListResponse> {\n return this.http.get<FileListResponse>(\n `/sessions/${sessionId}/files`,\n params as Record<string, unknown>,\n );\n }\n\n /** List messages for a session with cursor-based pagination. */\n messages(sessionId: string, params?: SessionMessagesParams): Promise<MessageListResponse> {\n return this.http.get<MessageListResponse>(\n `/sessions/${sessionId}/messages`,\n params as Record<string, unknown>,\n );\n }\n}\n","import type { HttpClient } from \"../../core/http.js\";\nimport type { components } from \"../../generated/v3/types.js\";\n\ntype WorkspaceView = components[\"schemas\"][\"WorkspaceView\"];\ntype WorkspaceListResponse = components[\"schemas\"][\"WorkspaceListResponse\"];\ntype WorkspaceCreateRequest = components[\"schemas\"][\"WorkspaceCreateRequest\"];\ntype WorkspaceUpdateRequest = components[\"schemas\"][\"WorkspaceUpdateRequest\"];\ntype FileListResponse = components[\"schemas\"][\"FileListResponse\"];\ntype FileUploadRequest = components[\"schemas\"][\"FileUploadRequest\"];\ntype FileUploadResponse = components[\"schemas\"][\"FileUploadResponse\"];\n\nexport interface WorkspaceListParams {\n pageSize?: number;\n pageNumber?: number;\n}\n\nexport interface WorkspaceFilesParams {\n prefix?: string;\n limit?: number;\n cursor?: string | null;\n includeUrls?: boolean;\n shallow?: boolean;\n}\n\nexport class Workspaces {\n constructor(private readonly http: HttpClient) {}\n\n /** List workspaces for the authenticated project. */\n list(params?: WorkspaceListParams): Promise<WorkspaceListResponse> {\n return this.http.get<WorkspaceListResponse>(\"/workspaces\", params as Record<string, unknown>);\n }\n\n /** Create a new workspace. */\n create(body?: WorkspaceCreateRequest): Promise<WorkspaceView> {\n return this.http.post<WorkspaceView>(\"/workspaces\", body);\n }\n\n /** Get workspace details. */\n get(workspaceId: string): Promise<WorkspaceView> {\n return this.http.get<WorkspaceView>(`/workspaces/${workspaceId}`);\n }\n\n /** Update a workspace. */\n update(workspaceId: string, body: WorkspaceUpdateRequest): Promise<WorkspaceView> {\n return this.http.patch<WorkspaceView>(`/workspaces/${workspaceId}`, body);\n }\n\n /** Delete a workspace and its data. */\n delete(workspaceId: string): Promise<void> {\n return this.http.delete<void>(`/workspaces/${workspaceId}`);\n }\n\n /** List files in a workspace. */\n files(workspaceId: string, params?: WorkspaceFilesParams): Promise<FileListResponse> {\n return this.http.get<FileListResponse>(\n `/workspaces/${workspaceId}/files`,\n params as Record<string, unknown>,\n );\n }\n\n /** Get presigned upload URLs for workspace files. */\n uploadFiles(workspaceId: string, body: FileUploadRequest, query?: { prefix?: string }): Promise<FileUploadResponse> {\n return this.http.post<FileUploadResponse>(\n `/workspaces/${workspaceId}/files/upload`,\n body,\n query as Record<string, unknown>,\n );\n }\n\n /** Delete a file from a workspace. */\n deleteFile(workspaceId: string, path: string): Promise<void> {\n return this.http.delete<void>(`/workspaces/${workspaceId}/files`, { path });\n }\n\n /** Get storage usage for a workspace. */\n size(workspaceId: string): Promise<unknown> {\n return this.http.get<unknown>(`/workspaces/${workspaceId}/size`);\n }\n}\n","import type { z } from \"zod\";\nimport type { components } from \"../generated/v3/types.js\";\nimport type { Sessions } from \"./resources/sessions.js\";\n\ntype SessionResponse = components[\"schemas\"][\"SessionResponse\"];\n\nconst TERMINAL_STATUSES = new Set([\"idle\", \"stopped\", \"timed_out\", \"error\"]);\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/** Session result with typed output. All SessionResponse fields are directly accessible. */\nexport type SessionResult<T = string | null> = Omit<SessionResponse, \"output\"> & { output: T };\n\n/**\n * Dual-purpose session handle: `await` it for a typed SessionResult,\n * or access `.result` for the full SessionResult after resolution.\n */\nexport class SessionRun<T = string> implements PromiseLike<SessionResult<T>> {\n private readonly _createPromise: Promise<SessionResponse>;\n private readonly _sessions: Sessions;\n private readonly _schema?: z.ZodType<T>;\n private readonly _timeout: number;\n private readonly _interval: number;\n private _sessionId: string | null = null;\n private _result: SessionResult<T> | null = null;\n\n constructor(\n createPromise: Promise<SessionResponse>,\n sessions: Sessions,\n schema?: z.ZodType<T>,\n options?: RunOptions,\n ) {\n this._createPromise = createPromise;\n this._sessions = sessions;\n this._schema = schema;\n this._timeout = options?.timeout ?? 300_000;\n this._interval = options?.interval ?? 2_000;\n }\n\n /** The session ID, available after task creation resolves. */\n get sessionId(): string | null {\n return this._sessionId;\n }\n\n /** The full SessionResult, available after polling completes. */\n get result(): SessionResult<T> | null {\n return this._result;\n }\n\n /** Enable `await client.run(...)` — polls until terminal, returns SessionResult. */\n then<R1 = SessionResult<T>, R2 = never>(\n onFulfilled?:\n | ((value: SessionResult<T>) => R1 | PromiseLike<R1>)\n | null,\n onRejected?: ((reason: unknown) => R2 | PromiseLike<R2>) | null,\n ): Promise<R1 | R2> {\n return this._waitForOutput().then(onFulfilled, onRejected);\n }\n\n private async _ensureSessionId(): Promise<string> {\n if (this._sessionId) return this._sessionId;\n const created = await this._createPromise;\n this._sessionId = created.id;\n return this._sessionId;\n }\n\n /** Poll session until terminal, return SessionResult. */\n private async _waitForOutput(): Promise<SessionResult<T>> {\n const sessionId = await this._ensureSessionId();\n const deadline = Date.now() + this._timeout;\n\n while (Date.now() < deadline) {\n const session = await this._sessions.get(sessionId);\n if (TERMINAL_STATUSES.has(session.status)) {\n const { output, ...rest } = session;\n const parsed = this._parseOutput(output);\n this._result = { ...rest, output: parsed } as SessionResult<T>;\n return this._result;\n }\n const remaining = deadline - Date.now();\n if (remaining <= 0) break;\n await new Promise((r) =>\n setTimeout(r, Math.min(this._interval, remaining)),\n );\n }\n\n throw new Error(\n `Session ${sessionId} did not complete within ${this._timeout}ms`,\n );\n }\n\n private _parseOutput(output: unknown): T {\n if (output == null) return null as T;\n if (!this._schema) return output as unknown as T;\n const raw = typeof output === \"string\" ? JSON.parse(output) : output;\n return this._schema.parse(raw);\n }\n}\n"]}