@hyperbrowser/sdk 0.81.2 → 0.82.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.ts CHANGED
@@ -12,6 +12,7 @@ import { HyperAgentService } from "./services/agents/hyper-agent";
12
12
  import { TeamService } from "./services/team";
13
13
  import { ComputerActionService } from "./services/computer-action";
14
14
  import { GeminiComputerUseService } from "./services/agents/gemini-computer-use";
15
+ import { WebService } from "./services/web";
15
16
  export declare class HyperbrowserError extends Error {
16
17
  statusCode?: number | undefined;
17
18
  constructor(message: string, statusCode?: number | undefined);
@@ -23,6 +24,7 @@ export declare class HyperbrowserClient {
23
24
  readonly extract: ExtractService;
24
25
  readonly profiles: ProfilesService;
25
26
  readonly extensions: ExtensionService;
27
+ readonly web: WebService;
26
28
  readonly agents: {
27
29
  browserUse: BrowserUseService;
28
30
  claudeComputerUse: ClaudeComputerUseService;
package/dist/client.js CHANGED
@@ -14,6 +14,7 @@ const hyper_agent_1 = require("./services/agents/hyper-agent");
14
14
  const team_1 = require("./services/team");
15
15
  const computer_action_1 = require("./services/computer-action");
16
16
  const gemini_computer_use_1 = require("./services/agents/gemini-computer-use");
17
+ const web_1 = require("./services/web");
17
18
  class HyperbrowserError extends Error {
18
19
  constructor(message, statusCode) {
19
20
  super(`[Hyperbrowser]: ${message}`);
@@ -36,6 +37,7 @@ class HyperbrowserClient {
36
37
  this.extract = new extract_1.ExtractService(apiKey, baseUrl, timeout);
37
38
  this.profiles = new profiles_1.ProfilesService(apiKey, baseUrl, timeout);
38
39
  this.extensions = new extensions_1.ExtensionService(apiKey, baseUrl, timeout);
40
+ this.web = new web_1.WebService(apiKey, baseUrl, timeout);
39
41
  this.team = new team_1.TeamService(apiKey, baseUrl, timeout);
40
42
  this.computerAction = new computer_action_1.ComputerActionService(apiKey, baseUrl, timeout);
41
43
  this.agents = {
@@ -0,0 +1,26 @@
1
+ import { BatchFetchJobResponse, BatchFetchJobStatusResponse, GetBatchFetchJobParams, StartBatchFetchJobParams, StartBatchFetchJobResponse } from "../../types/web/batch-fetch";
2
+ import { BaseService } from "../base";
3
+ export declare class BatchFetchService extends BaseService {
4
+ /**
5
+ * Start a new batch fetch job
6
+ * @param params The parameters for the batch fetch job
7
+ */
8
+ start(params: StartBatchFetchJobParams): Promise<StartBatchFetchJobResponse>;
9
+ /**
10
+ * Get the status of a batch fetch job
11
+ * @param id The ID of the batch fetch job to get
12
+ */
13
+ getStatus(id: string): Promise<BatchFetchJobStatusResponse>;
14
+ /**
15
+ * Get the details of a batch fetch job
16
+ * @param id The ID of the batch fetch job to get
17
+ * @param params Optional parameters to filter the batch fetch job
18
+ */
19
+ get(id: string, params?: GetBatchFetchJobParams): Promise<BatchFetchJobResponse>;
20
+ /**
21
+ * Start a batch fetch job and wait for it to complete
22
+ * @param params The parameters for the batch fetch job
23
+ * @param returnAllPages Whether to return all pages in the batch fetch job response
24
+ */
25
+ startAndWait(params: StartBatchFetchJobParams, returnAllPages?: boolean): Promise<BatchFetchJobResponse>;
26
+ }
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.BatchFetchService = void 0;
7
+ const zod_to_json_schema_1 = __importDefault(require("zod-to-json-schema"));
8
+ const zod_1 = require("zod");
9
+ const base_1 = require("../base");
10
+ const utils_1 = require("../../utils");
11
+ const client_1 = require("../../client");
12
+ const constants_1 = require("../../types/constants");
13
+ const utils_2 = require("../../utils");
14
+ class BatchFetchService extends base_1.BaseService {
15
+ /**
16
+ * Start a new batch fetch job
17
+ * @param params The parameters for the batch fetch job
18
+ */
19
+ async start(params) {
20
+ try {
21
+ if (params.outputs?.formats) {
22
+ for (const output of params.outputs.formats) {
23
+ if (typeof output === "object" && "type" in output && output.type === "json") {
24
+ const jsonOutput = output;
25
+ if (jsonOutput.schema) {
26
+ if ((0, utils_2.isZodSchema)(jsonOutput.schema)) {
27
+ try {
28
+ output.schema = (0, zod_1.toJSONSchema)(jsonOutput.schema);
29
+ }
30
+ catch {
31
+ output.schema = (0, zod_to_json_schema_1.default)(jsonOutput.schema);
32
+ }
33
+ }
34
+ }
35
+ }
36
+ }
37
+ }
38
+ return await this.request("/web/batch-fetch", {
39
+ method: "POST",
40
+ body: JSON.stringify(params),
41
+ });
42
+ }
43
+ catch (error) {
44
+ if (error instanceof client_1.HyperbrowserError) {
45
+ throw error;
46
+ }
47
+ throw new client_1.HyperbrowserError("Failed to start batch fetch job", undefined);
48
+ }
49
+ }
50
+ /**
51
+ * Get the status of a batch fetch job
52
+ * @param id The ID of the batch fetch job to get
53
+ */
54
+ async getStatus(id) {
55
+ try {
56
+ return await this.request(`/web/batch-fetch/${id}/status`);
57
+ }
58
+ catch (error) {
59
+ if (error instanceof client_1.HyperbrowserError) {
60
+ throw error;
61
+ }
62
+ throw new client_1.HyperbrowserError(`Failed to get batch fetch job ${id} status`, undefined);
63
+ }
64
+ }
65
+ /**
66
+ * Get the details of a batch fetch job
67
+ * @param id The ID of the batch fetch job to get
68
+ * @param params Optional parameters to filter the batch fetch job
69
+ */
70
+ async get(id, params) {
71
+ try {
72
+ return await this.request(`/web/batch-fetch/${id}`, undefined, {
73
+ page: params?.page,
74
+ batchSize: params?.batchSize,
75
+ });
76
+ }
77
+ catch (error) {
78
+ if (error instanceof client_1.HyperbrowserError) {
79
+ throw error;
80
+ }
81
+ throw new client_1.HyperbrowserError(`Failed to get batch fetch job ${id}`, undefined);
82
+ }
83
+ }
84
+ /**
85
+ * Start a batch fetch job and wait for it to complete
86
+ * @param params The parameters for the batch fetch job
87
+ * @param returnAllPages Whether to return all pages in the batch fetch job response
88
+ */
89
+ async startAndWait(params, returnAllPages = true) {
90
+ const job = await this.start(params);
91
+ const jobId = job.jobId;
92
+ if (!jobId) {
93
+ throw new client_1.HyperbrowserError("Failed to start batch fetch job, could not get job ID");
94
+ }
95
+ let failures = 0;
96
+ let jobStatus = "pending";
97
+ while (true) {
98
+ try {
99
+ const { status } = await this.getStatus(jobId);
100
+ if (status === "completed" || status === "failed") {
101
+ jobStatus = status;
102
+ break;
103
+ }
104
+ failures = 0;
105
+ }
106
+ catch (error) {
107
+ failures++;
108
+ if (failures >= constants_1.POLLING_ATTEMPTS) {
109
+ throw new client_1.HyperbrowserError(`Failed to poll batch fetch job ${jobId} after ${constants_1.POLLING_ATTEMPTS} attempts: ${error}`);
110
+ }
111
+ }
112
+ await (0, utils_1.sleep)(2000);
113
+ }
114
+ failures = 0;
115
+ if (!returnAllPages) {
116
+ while (true) {
117
+ try {
118
+ return await this.get(jobId);
119
+ }
120
+ catch (error) {
121
+ failures++;
122
+ if (failures >= constants_1.POLLING_ATTEMPTS) {
123
+ throw new client_1.HyperbrowserError(`Failed to get batch fetch job ${jobId} after ${constants_1.POLLING_ATTEMPTS} attempts: ${error}`);
124
+ }
125
+ }
126
+ await (0, utils_1.sleep)(500);
127
+ }
128
+ }
129
+ failures = 0;
130
+ const jobResponse = {
131
+ jobId,
132
+ status: jobStatus,
133
+ data: [],
134
+ currentPageBatch: 0,
135
+ totalPageBatches: 0,
136
+ totalPages: 0,
137
+ batchSize: 100,
138
+ };
139
+ let firstCheck = true;
140
+ while (firstCheck || jobResponse.currentPageBatch < jobResponse.totalPageBatches) {
141
+ try {
142
+ const tmpJobResponse = await this.get(jobId, {
143
+ page: jobResponse.currentPageBatch + 1,
144
+ batchSize: 100,
145
+ });
146
+ if (tmpJobResponse.data) {
147
+ jobResponse.data?.push(...tmpJobResponse.data);
148
+ }
149
+ if (tmpJobResponse.error) {
150
+ jobResponse.error = tmpJobResponse.error;
151
+ }
152
+ jobResponse.currentPageBatch = tmpJobResponse.currentPageBatch;
153
+ jobResponse.totalPages = tmpJobResponse.totalPages;
154
+ jobResponse.totalPageBatches = tmpJobResponse.totalPageBatches;
155
+ jobResponse.batchSize = tmpJobResponse.batchSize;
156
+ failures = 0;
157
+ firstCheck = false;
158
+ }
159
+ catch (error) {
160
+ failures++;
161
+ if (failures >= constants_1.POLLING_ATTEMPTS) {
162
+ throw new client_1.HyperbrowserError(`Failed to get batch page ${jobResponse.currentPageBatch + 1} for job ${jobId} after ${constants_1.POLLING_ATTEMPTS} attempts: ${error}`);
163
+ }
164
+ }
165
+ await (0, utils_1.sleep)(500);
166
+ }
167
+ return jobResponse;
168
+ }
169
+ }
170
+ exports.BatchFetchService = BatchFetchService;
@@ -0,0 +1,18 @@
1
+ import { BaseService } from "../base";
2
+ import { FetchParams, FetchResponse } from "../../types/web/fetch";
3
+ import { WebSearchParams, WebSearchResponse } from "../../types/web/search";
4
+ import { BatchFetchService } from "./batch-fetch";
5
+ export declare class WebService extends BaseService {
6
+ readonly batchFetch: BatchFetchService;
7
+ constructor(apiKey: string, baseUrl: string, timeout: number);
8
+ /**
9
+ * Fetch a URL and extract content
10
+ * @param params The parameters for the fetch request
11
+ */
12
+ fetch(params: FetchParams): Promise<FetchResponse>;
13
+ /**
14
+ * Search the web
15
+ * @param params The parameters for the search request
16
+ */
17
+ search(params: WebSearchParams): Promise<WebSearchResponse>;
18
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.WebService = void 0;
7
+ const zod_1 = require("zod");
8
+ const zod_to_json_schema_1 = __importDefault(require("zod-to-json-schema"));
9
+ const base_1 = require("../base");
10
+ const client_1 = require("../../client");
11
+ const utils_1 = require("../../utils");
12
+ const batch_fetch_1 = require("./batch-fetch");
13
+ class WebService extends base_1.BaseService {
14
+ constructor(apiKey, baseUrl, timeout) {
15
+ super(apiKey, baseUrl, timeout);
16
+ this.batchFetch = new batch_fetch_1.BatchFetchService(apiKey, baseUrl, timeout);
17
+ }
18
+ /**
19
+ * Fetch a URL and extract content
20
+ * @param params The parameters for the fetch request
21
+ */
22
+ async fetch(params) {
23
+ try {
24
+ // Handle JSON schema serialization if needed (similar to Python SDK)
25
+ if (params.outputs?.formats) {
26
+ for (const output of params.outputs.formats) {
27
+ if (typeof output === "object" && "type" in output && output.type === "json") {
28
+ const jsonOutput = output;
29
+ if (jsonOutput.schema) {
30
+ if ((0, utils_1.isZodSchema)(jsonOutput.schema)) {
31
+ try {
32
+ output.schema = (0, zod_1.toJSONSchema)(jsonOutput.schema);
33
+ }
34
+ catch {
35
+ output.schema = (0, zod_to_json_schema_1.default)(jsonOutput.schema);
36
+ }
37
+ }
38
+ }
39
+ }
40
+ }
41
+ }
42
+ return await this.request("/web/fetch", {
43
+ method: "POST",
44
+ body: JSON.stringify(params),
45
+ });
46
+ }
47
+ catch (error) {
48
+ if (error instanceof client_1.HyperbrowserError) {
49
+ throw error;
50
+ }
51
+ throw new client_1.HyperbrowserError("Failed to fetch URL", undefined);
52
+ }
53
+ }
54
+ /**
55
+ * Search the web
56
+ * @param params The parameters for the search request
57
+ */
58
+ async search(params) {
59
+ try {
60
+ return await this.request("/web/search", {
61
+ method: "POST",
62
+ body: JSON.stringify(params),
63
+ });
64
+ }
65
+ catch (error) {
66
+ if (error instanceof client_1.HyperbrowserError) {
67
+ throw error;
68
+ }
69
+ throw new client_1.HyperbrowserError("Failed to search web", undefined);
70
+ }
71
+ }
72
+ }
73
+ exports.WebService = WebService;
@@ -13,3 +13,7 @@ export { CreateExtensionParams, CreateExtensionResponse, ListExtensionsResponse,
13
13
  export { ExtractJobStatus, BrowserUseTaskStatus, BrowserUseLlm, ClaudeComputerUseLlm, GeminiComputerUseLlm, ScrapeScreenshotFormat, ScrapeJobStatus, CrawlJobStatus, Country, State, ISO639_1, OperatingSystem, Platform, ScrapeFormat, ScrapeWaitUntil, ScrapePageStatus, CrawlPageStatus, RecordingStatus, DownloadsStatus, HyperAgentLlm, HyperAgentTaskStatus, ClaudeComputerUseTaskStatus, CuaTaskStatus, GeminiComputerUseTaskStatus, SessionEventLogType, SessionRegion, BrowserUseVersion, HyperAgentVersion, } from "./constants";
14
14
  export { TeamCreditInfo } from "./team";
15
15
  export { ComputerAction, Coordinate, ClickActionParams, DragActionParams, PressKeysActionParams, MoveMouseActionParams, ScreenshotActionParams, ScrollActionParams, TypeTextActionParams, ComputerActionParams, ComputerActionResponse, ComputerActionMouseButton, ComputerActionResponseData, HoldKeyActionParams, MouseDownActionParams, MouseUpActionParams, GetClipboardTextActionParams, PutSelectionTextActionParams, ComputerActionResponseDataClipboardText, } from "./computer-action";
16
+ export { FetchParams, FetchResponse, FetchResponseData, FetchStatus } from "./web/fetch";
17
+ export { StartBatchFetchJobParams, GetBatchFetchJobParams, StartBatchFetchJobResponse, BatchFetchJobStatusResponse, BatchFetchJobResponse, BatchFetchJobStatus, } from "./web/batch-fetch";
18
+ export { WebSearchParams, WebSearchResponse, WebSearchResponseData, WebSearchResultItem, WebSearchFilters, WebSearchLocation, WebSearchFiletype, WebSearchStatus, } from "./web/search";
19
+ export { FetchStealthMode, FetchSanitizeMode, FetchWaitUntil, FetchScreenshotFormat, PageStatus, FetchOutputScreenshotOptions, FetchStorageStateOptions, FetchBrowserLocationOptions, PageData, FetchOutputMarkdown, FetchOutputHtml, FetchOutputLinks, FetchOutputScreenshot, FetchOutputJsonOptions, FetchOutputJson, FetchOutputFormat, FetchOutputOptions, FetchBrowserOptions, FetchNavigationOptions, FetchCacheOptions, } from "./web/common";
@@ -0,0 +1,30 @@
1
+ import { FetchBrowserOptions, FetchCacheOptions, FetchNavigationOptions, FetchOutputOptions, FetchStealthMode, PageData } from "./common";
2
+ export type BatchFetchJobStatus = "pending" | "running" | "completed" | "failed";
3
+ export interface StartBatchFetchJobParams {
4
+ urls: string[];
5
+ stealth?: FetchStealthMode;
6
+ outputs?: FetchOutputOptions;
7
+ browser?: FetchBrowserOptions;
8
+ navigation?: FetchNavigationOptions;
9
+ cache?: FetchCacheOptions;
10
+ }
11
+ export interface GetBatchFetchJobParams {
12
+ page?: number;
13
+ batchSize?: number;
14
+ }
15
+ export interface StartBatchFetchJobResponse {
16
+ jobId: string;
17
+ }
18
+ export interface BatchFetchJobStatusResponse {
19
+ status: BatchFetchJobStatus;
20
+ }
21
+ export interface BatchFetchJobResponse {
22
+ jobId: string;
23
+ status: BatchFetchJobStatus;
24
+ error?: string;
25
+ data?: PageData[];
26
+ totalPages: number;
27
+ totalPageBatches: number;
28
+ currentPageBatch: number;
29
+ batchSize: number;
30
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,74 @@
1
+ import { Country, State } from "../constants";
2
+ import { ScreenConfig } from "../session";
3
+ export type FetchStealthMode = "none" | "auto" | "ultra";
4
+ export type FetchSanitizeMode = "none" | "basic" | "advanced";
5
+ export type FetchWaitUntil = "load" | "domcontentloaded" | "networkidle";
6
+ export type FetchScreenshotFormat = "jpeg" | "png" | "webp";
7
+ export type PageStatus = "completed" | "failed" | "pending" | "running";
8
+ export interface FetchOutputScreenshotOptions {
9
+ fullPage?: boolean;
10
+ format?: FetchScreenshotFormat;
11
+ cropToContent?: boolean;
12
+ cropToContentMaxHeight?: number;
13
+ cropToContentMinHeight?: number;
14
+ }
15
+ export interface FetchStorageStateOptions {
16
+ localStorage?: Record<string, string>;
17
+ sessionStorage?: Record<string, string>;
18
+ }
19
+ export interface FetchBrowserLocationOptions {
20
+ country?: Country;
21
+ state?: State;
22
+ city?: string;
23
+ }
24
+ export interface PageData {
25
+ url: string;
26
+ status: PageStatus;
27
+ error?: string;
28
+ metadata?: Record<string, string | string[]>;
29
+ markdown?: string;
30
+ html?: string;
31
+ links?: string[];
32
+ screenshot?: string;
33
+ json?: Record<string, any>;
34
+ }
35
+ export interface FetchOutputMarkdown {
36
+ type: "markdown";
37
+ }
38
+ export interface FetchOutputHtml {
39
+ type: "html";
40
+ }
41
+ export interface FetchOutputLinks {
42
+ type: "links";
43
+ }
44
+ export interface FetchOutputScreenshot extends FetchOutputScreenshotOptions {
45
+ type: "screenshot";
46
+ }
47
+ export interface FetchOutputJsonOptions {
48
+ schema?: any;
49
+ }
50
+ export interface FetchOutputJson extends FetchOutputJsonOptions {
51
+ type: "json";
52
+ }
53
+ export type FetchOutputFormat = FetchOutputMarkdown | FetchOutputHtml | FetchOutputLinks | FetchOutputScreenshot | FetchOutputJson | "markdown" | "html" | "links" | "screenshot";
54
+ export interface FetchOutputOptions {
55
+ formats?: FetchOutputFormat[];
56
+ sanitize?: FetchSanitizeMode;
57
+ includeSelectors?: string[];
58
+ excludeSelectors?: string[];
59
+ storageState?: FetchStorageStateOptions;
60
+ }
61
+ export interface FetchBrowserOptions {
62
+ screen?: ScreenConfig;
63
+ profileId?: string;
64
+ solveCaptchas?: string;
65
+ location?: FetchBrowserLocationOptions;
66
+ }
67
+ export interface FetchNavigationOptions {
68
+ waitUntil?: FetchWaitUntil;
69
+ timeoutMs?: number;
70
+ waitFor?: number;
71
+ }
72
+ export interface FetchCacheOptions {
73
+ maxAgeSeconds?: number;
74
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,24 @@
1
+ import { FetchStealthMode, FetchOutputOptions, FetchBrowserOptions, FetchNavigationOptions, FetchCacheOptions } from "./common";
2
+ export type FetchStatus = "completed" | "failed" | "pending" | "running";
3
+ export interface FetchParams {
4
+ url: string;
5
+ stealth?: FetchStealthMode;
6
+ outputs?: FetchOutputOptions;
7
+ browser?: FetchBrowserOptions;
8
+ navigation?: FetchNavigationOptions;
9
+ cache?: FetchCacheOptions;
10
+ }
11
+ export interface FetchResponseData {
12
+ metadata?: Record<string, string | string[]>;
13
+ html?: string;
14
+ markdown?: string;
15
+ links?: string[];
16
+ screenshot?: string;
17
+ json?: Record<string, any>;
18
+ }
19
+ export interface FetchResponse {
20
+ jobId: string;
21
+ status: FetchStatus;
22
+ error?: string;
23
+ data?: FetchResponseData;
24
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,41 @@
1
+ import { Country, State } from "../constants";
2
+ export type WebSearchFiletype = "pdf" | "doc" | "docx" | "xls" | "xlsx" | "ppt" | "pptx" | "html";
3
+ export type WebSearchStatus = "completed" | "failed" | "pending" | "running";
4
+ export interface WebSearchFilters {
5
+ exactPhrase?: boolean;
6
+ semanticPhrase?: boolean;
7
+ excludeTerms?: string[];
8
+ boostTerms?: string[];
9
+ filetype?: WebSearchFiletype;
10
+ site?: string;
11
+ excludeSite?: string;
12
+ intitle?: string;
13
+ inurl?: string;
14
+ }
15
+ export interface WebSearchLocation {
16
+ country?: Country;
17
+ state?: State;
18
+ city?: string;
19
+ }
20
+ export interface WebSearchParams {
21
+ query: string;
22
+ page?: number;
23
+ maxAgeSeconds?: number;
24
+ location?: WebSearchLocation;
25
+ filters?: WebSearchFilters;
26
+ }
27
+ export interface WebSearchResultItem {
28
+ title: string;
29
+ url: string;
30
+ description: string;
31
+ }
32
+ export interface WebSearchResponseData {
33
+ query: string;
34
+ results: WebSearchResultItem[];
35
+ }
36
+ export interface WebSearchResponse {
37
+ jobId: string;
38
+ status: WebSearchStatus;
39
+ error?: string;
40
+ data?: WebSearchResponseData;
41
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperbrowser/sdk",
3
- "version": "0.81.2",
3
+ "version": "0.82.1",
4
4
  "description": "Node SDK for Hyperbrowser API",
5
5
  "author": "",
6
6
  "main": "dist/index.js",