@hyperbrowser/sdk 0.49.1 → 0.51.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.
@@ -1,4 +1,4 @@
1
- import { BasicResponse, CreateSessionParams, GetSessionDownloadsUrlResponse, GetSessionRecordingUrlResponse, GetSessionVideoRecordingUrlResponse, SessionDetail, SessionListParams, SessionListResponse, SessionRecording } from "../types/session";
1
+ import { BasicResponse, CreateSessionParams, GetActiveSessionsCountResponse, GetSessionDownloadsUrlResponse, GetSessionRecordingUrlResponse, GetSessionVideoRecordingUrlResponse, SessionDetail, SessionListParams, SessionListResponse, SessionRecording, UploadFileOptions, UploadFileResponse } from "../types/session";
2
2
  import { BaseService } from "./base";
3
3
  export declare class SessionsService extends BaseService {
4
4
  /**
@@ -41,4 +41,20 @@ export declare class SessionsService extends BaseService {
41
41
  * @param id The ID of the session to get the downloads URL from
42
42
  */
43
43
  getDownloadsURL(id: string): Promise<GetSessionDownloadsUrlResponse>;
44
+ /**
45
+ * Upload a file to the session
46
+ * @param id The ID of the session to upload the file to
47
+ * @param fileOptions Options for uploading a file
48
+ * @param fileOptions.fileInput File path string, ReadStream, or Buffer containing the file data
49
+ * @param fileOptions.fileName Optional name to use for the uploaded file. Required when fileInput is a Buffer
50
+ */
51
+ uploadFile(id: string, fileOptions: UploadFileOptions): Promise<UploadFileResponse>;
52
+ /**
53
+ * Helper method to check if input is a readable stream
54
+ */
55
+ private isReadableStream;
56
+ /**
57
+ * Get the number of active sessions
58
+ */
59
+ getActiveSessionsCount(): Promise<GetActiveSessionsCountResponse>;
44
60
  }
@@ -1,6 +1,35 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
2
28
  Object.defineProperty(exports, "__esModule", { value: true });
3
29
  exports.SessionsService = void 0;
30
+ const fs_1 = require("fs");
31
+ const path = __importStar(require("path"));
32
+ const form_data_1 = __importDefault(require("form-data"));
4
33
  const base_1 = require("./base");
5
34
  const client_1 = require("../client");
6
35
  class SessionsService extends base_1.BaseService {
@@ -133,5 +162,113 @@ class SessionsService extends base_1.BaseService {
133
162
  throw new client_1.HyperbrowserError(`Failed to get downloads url for session ${id}`, undefined);
134
163
  }
135
164
  }
165
+ /**
166
+ * Upload a file to the session
167
+ * @param id The ID of the session to upload the file to
168
+ * @param fileOptions Options for uploading a file
169
+ * @param fileOptions.fileInput File path string, ReadStream, or Buffer containing the file data
170
+ * @param fileOptions.fileName Optional name to use for the uploaded file. Required when fileInput is a Buffer
171
+ */
172
+ async uploadFile(id, fileOptions) {
173
+ const { fileInput, fileName } = fileOptions;
174
+ try {
175
+ let fetchOptions;
176
+ if (typeof fileInput === "string") {
177
+ let stats;
178
+ try {
179
+ stats = await fs_1.promises.stat(fileInput);
180
+ }
181
+ catch (error) {
182
+ if (error.code === "ENOENT") {
183
+ throw new client_1.HyperbrowserError(`File not found: ${fileInput}`, undefined);
184
+ }
185
+ if (error.code === "EACCES") {
186
+ throw new client_1.HyperbrowserError(`Permission denied accessing file: ${fileInput}`, undefined);
187
+ }
188
+ throw new client_1.HyperbrowserError(`Failed to access file ${fileInput}: ${error.message}`, undefined);
189
+ }
190
+ if (!stats.isFile()) {
191
+ throw new client_1.HyperbrowserError(`Path is not a file: ${fileInput}`, undefined);
192
+ }
193
+ const formData = new form_data_1.default();
194
+ const fileStream = (0, fs_1.createReadStream)(fileInput);
195
+ const fileBaseName = fileName || path.basename(fileInput);
196
+ fileStream.on("error", (error) => {
197
+ throw new client_1.HyperbrowserError(`Failed to read file ${fileInput}: ${error.message}`, undefined);
198
+ });
199
+ formData.append("file", fileStream, {
200
+ filename: fileBaseName,
201
+ });
202
+ fetchOptions = {
203
+ method: "POST",
204
+ body: formData,
205
+ headers: formData.getHeaders(),
206
+ };
207
+ }
208
+ else if (this.isReadableStream(fileInput)) {
209
+ const formData = new form_data_1.default();
210
+ let tmpFileName = fileName || `file-${Date.now()}`;
211
+ if (fileInput.path && typeof fileInput.path === "string" && !fileName) {
212
+ tmpFileName = path.basename(fileInput.path);
213
+ }
214
+ formData.append("file", fileInput, {
215
+ filename: tmpFileName,
216
+ });
217
+ fetchOptions = {
218
+ method: "POST",
219
+ body: formData,
220
+ headers: formData.getHeaders(),
221
+ };
222
+ }
223
+ else if (Buffer.isBuffer(fileInput)) {
224
+ if (!fileName) {
225
+ throw new client_1.HyperbrowserError("fileName is required when uploading Buffer data", undefined);
226
+ }
227
+ const formData = new form_data_1.default();
228
+ formData.append("file", fileInput, {
229
+ filename: fileName,
230
+ });
231
+ fetchOptions = {
232
+ method: "POST",
233
+ body: formData,
234
+ headers: formData.getHeaders(),
235
+ };
236
+ }
237
+ else {
238
+ throw new client_1.HyperbrowserError("Unsupported file input type. Please provide a file path string, ReadStream, or Buffer.", undefined);
239
+ }
240
+ return await this.request(`/session/${id}/uploads`, fetchOptions);
241
+ }
242
+ catch (error) {
243
+ if (error instanceof client_1.HyperbrowserError) {
244
+ throw error;
245
+ }
246
+ throw new client_1.HyperbrowserError(`Failed to upload file for session ${id}: ${error}`, undefined);
247
+ }
248
+ }
249
+ /**
250
+ * Helper method to check if input is a readable stream
251
+ */
252
+ isReadableStream(obj) {
253
+ return (obj &&
254
+ typeof obj === "object" &&
255
+ typeof obj.read === "function" &&
256
+ typeof obj.on === "function" &&
257
+ obj.readable !== false);
258
+ }
259
+ /**
260
+ * Get the number of active sessions
261
+ */
262
+ async getActiveSessionsCount() {
263
+ try {
264
+ return await this.request("/sessions/active-count");
265
+ }
266
+ catch (error) {
267
+ if (error instanceof client_1.HyperbrowserError) {
268
+ throw error;
269
+ }
270
+ throw new client_1.HyperbrowserError("Failed to get active sessions count", undefined);
271
+ }
272
+ }
136
273
  }
137
274
  exports.SessionsService = SessionsService;
@@ -1,7 +1,8 @@
1
- import { ClaudeComputerUseTaskStatus } from "../constants";
1
+ import { ClaudeComputerUseLlm, ClaudeComputerUseTaskStatus } from "../constants";
2
2
  import { CreateSessionParams } from "../session";
3
3
  export interface StartClaudeComputerUseTaskParams {
4
4
  task: string;
5
+ llm?: ClaudeComputerUseLlm;
5
6
  sessionId?: string;
6
7
  maxFailures?: number;
7
8
  maxSteps?: number;
@@ -13,7 +13,8 @@ export type ScrapeScreenshotFormat = "jpeg" | "png" | "webp";
13
13
  export type RecordingStatus = "not_enabled" | "pending" | "in_progress" | "completed" | "failed";
14
14
  export type DownloadsStatus = "not_enabled" | "pending" | "in_progress" | "completed" | "failed";
15
15
  export declare const POLLING_ATTEMPTS = 5;
16
- export type BrowserUseLlm = "gpt-4o" | "gpt-4o-mini" | "claude-3-7-sonnet-20250219" | "claude-3-5-sonnet-20241022" | "claude-3-5-haiku-20241022" | "gemini-2.0-flash";
16
+ export type BrowserUseLlm = "gpt-4o" | "gpt-4o-mini" | "gpt-4.1" | "gpt-4.1-mini" | "claude-sonnet-4-20250514" | "claude-3-7-sonnet-20250219" | "claude-3-5-sonnet-20241022" | "claude-3-5-haiku-20241022" | "gemini-2.0-flash";
17
+ export type ClaudeComputerUseLlm = "claude-3-7-sonnet-20250219" | "claude-sonnet-4-20250514";
17
18
  export type HyperAgentLlm = "gpt-4o" | "gpt-4o-mini" | "gpt-4.1" | "gpt-4.1-mini" | "gpt-4.1-nano";
18
19
  export type Country = "AD" | "AE" | "AF" | "AL" | "AM" | "AO" | "AR" | "AT" | "AU" | "AW" | "AZ" | "BA" | "BD" | "BE" | "BG" | "BH" | "BJ" | "BO" | "BR" | "BS" | "BT" | "BY" | "BZ" | "CA" | "CF" | "CH" | "CI" | "CL" | "CM" | "CN" | "CO" | "CR" | "CU" | "CY" | "CZ" | "DE" | "DJ" | "DK" | "DM" | "EC" | "EE" | "EG" | "ES" | "ET" | "EU" | "FI" | "FJ" | "FR" | "GB" | "GE" | "GH" | "GM" | "GR" | "HK" | "HN" | "HR" | "HT" | "HU" | "ID" | "IE" | "IL" | "IN" | "IQ" | "IR" | "IS" | "IT" | "JM" | "JO" | "JP" | "KE" | "KH" | "KR" | "KW" | "KZ" | "LB" | "LI" | "LR" | "LT" | "LU" | "LV" | "MA" | "MC" | "MD" | "ME" | "MG" | "MK" | "ML" | "MM" | "MN" | "MR" | "MT" | "MU" | "MV" | "MX" | "MY" | "MZ" | "NG" | "NL" | "NO" | "NZ" | "OM" | "PA" | "PE" | "PH" | "PK" | "PL" | "PR" | "PT" | "PY" | "QA" | "RANDOM_COUNTRY" | "RO" | "RS" | "RU" | "SA" | "SC" | "SD" | "SE" | "SG" | "SI" | "SK" | "SN" | "SS" | "TD" | "TG" | "TH" | "TM" | "TN" | "TR" | "TT" | "TW" | "UA" | "UG" | "US" | "UY" | "UZ" | "VE" | "VG" | "VN" | "YE" | "ZA" | "ZM" | "ZW" | "ad" | "ae" | "af" | "al" | "am" | "ao" | "ar" | "at" | "au" | "aw" | "az" | "ba" | "bd" | "be" | "bg" | "bh" | "bj" | "bo" | "br" | "bs" | "bt" | "by" | "bz" | "ca" | "cf" | "ch" | "ci" | "cl" | "cm" | "cn" | "co" | "cr" | "cu" | "cy" | "cz" | "de" | "dj" | "dk" | "dm" | "ec" | "ee" | "eg" | "es" | "et" | "eu" | "fi" | "fj" | "fr" | "gb" | "ge" | "gh" | "gm" | "gr" | "hk" | "hn" | "hr" | "ht" | "hu" | "id" | "ie" | "il" | "in" | "iq" | "ir" | "is" | "it" | "jm" | "jo" | "jp" | "ke" | "kh" | "kr" | "kw" | "kz" | "lb" | "li" | "lr" | "lt" | "lu" | "lv" | "ma" | "mc" | "md" | "me" | "mg" | "mk" | "ml" | "mm" | "mn" | "mr" | "mt" | "mu" | "mv" | "mx" | "my" | "mz" | "ng" | "nl" | "no" | "nz" | "om" | "pa" | "pe" | "ph" | "pk" | "pl" | "pr" | "pt" | "py" | "qa" | "ro" | "rs" | "ru" | "sa" | "sc" | "sd" | "se" | "sg" | "si" | "sk" | "sn" | "ss" | "td" | "tg" | "th" | "tm" | "tn" | "tr" | "tt" | "tw" | "ua" | "ug" | "us" | "uy" | "uz" | "ve" | "vg" | "vn" | "ye" | "za" | "zm" | "zw";
19
20
  export type OperatingSystem = "windows" | "android" | "macos" | "linux" | "ios";
@@ -6,7 +6,7 @@ export { StartBrowserUseTaskParams, StartBrowserUseTaskResponse, BrowserUseTaskS
6
6
  export { StartClaudeComputerUseTaskParams, StartClaudeComputerUseTaskResponse, ClaudeComputerUseTaskStatusResponse, ClaudeComputerUseTaskResponse, ClaudeComputerUseTaskData, ClaudeComputerUseStepResponse, } from "./agents/claude-computer-use";
7
7
  export { StartCuaTaskParams, StartCuaTaskResponse, CuaTaskStatusResponse, CuaTaskResponse, CuaTaskData, CuaStepResponse, } from "./agents/cua";
8
8
  export { StartHyperAgentTaskParams, StartHyperAgentTaskResponse, HyperAgentTaskStatusResponse, HyperAgentTaskResponse, HyperAgentTaskData, HyperAgentStep, HyperAgentOutput, HyperAgentActionOutput, } from "./agents/hyper-agent";
9
- export { BasicResponse, SessionStatus, Session, SessionDetail, SessionListParams, SessionListResponse, ScreenConfig, CreateSessionParams, GetSessionDownloadsUrlResponse, GetSessionVideoRecordingUrlResponse, GetSessionRecordingUrlResponse, ImageCaptchaParam, } from "./session";
9
+ export { BasicResponse, SessionStatus, Session, SessionDetail, SessionListParams, SessionListResponse, ScreenConfig, CreateSessionParams, GetSessionDownloadsUrlResponse, GetSessionVideoRecordingUrlResponse, GetSessionRecordingUrlResponse, ImageCaptchaParam, UploadFileResponse, UploadFileOptions, GetActiveSessionsCountResponse, } from "./session";
10
10
  export { CreateProfileParams, ProfileResponse, CreateProfileResponse, ProfileListParams, ProfileListResponse, } from "./profile";
11
11
  export { CreateExtensionParams, CreateExtensionResponse, ListExtensionsResponse, } from "./extension";
12
- export { ExtractJobStatus, BrowserUseTaskStatus, BrowserUseLlm, ScrapeScreenshotFormat, ScrapeJobStatus, CrawlJobStatus, Country, State, ISO639_1, OperatingSystem, Platform, ScrapeFormat, ScrapeWaitUntil, ScrapePageStatus, CrawlPageStatus, RecordingStatus, DownloadsStatus, HyperAgentLlm, HyperAgentTaskStatus, ClaudeComputerUseTaskStatus, CuaTaskStatus, } from "./constants";
12
+ export { ExtractJobStatus, BrowserUseTaskStatus, BrowserUseLlm, ClaudeComputerUseLlm, ScrapeScreenshotFormat, ScrapeJobStatus, CrawlJobStatus, Country, State, ISO639_1, OperatingSystem, Platform, ScrapeFormat, ScrapeWaitUntil, ScrapePageStatus, CrawlPageStatus, RecordingStatus, DownloadsStatus, HyperAgentLlm, HyperAgentTaskStatus, ClaudeComputerUseTaskStatus, CuaTaskStatus, } from "./constants";
@@ -1,3 +1,4 @@
1
+ import fs from "fs";
1
2
  import { Country, DownloadsStatus, ISO639_1, OperatingSystem, Platform, RecordingStatus, State } from "./constants";
2
3
  export type SessionStatus = "active" | "closed" | "error";
3
4
  export interface BasicResponse {
@@ -92,3 +93,13 @@ export interface GetSessionDownloadsUrlResponse {
92
93
  downloadsUrl?: string | null;
93
94
  error?: string | null;
94
95
  }
96
+ export interface UploadFileResponse {
97
+ message: string;
98
+ }
99
+ export interface UploadFileOptions {
100
+ fileInput: string | fs.ReadStream | Buffer;
101
+ fileName?: string;
102
+ }
103
+ export interface GetActiveSessionsCountResponse {
104
+ activeSessionsCount: number;
105
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperbrowser/sdk",
3
- "version": "0.49.1",
3
+ "version": "0.51.0",
4
4
  "description": "Node SDK for Hyperbrowser API",
5
5
  "author": "",
6
6
  "main": "dist/index.js",