@hyperbrowser/sdk 0.29.0 → 0.31.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/client.d.ts +2 -0
- package/dist/client.js +2 -0
- package/dist/services/task.d.ts +30 -0
- package/dist/services/task.js +101 -0
- package/dist/types/constants.d.ts +3 -0
- package/dist/types/extract.d.ts +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/session.d.ts +3 -1
- package/dist/types/task.d.ts +30 -0
- package/dist/types/task.js +2 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { CrawlService } from "./services/crawl";
|
|
|
5
5
|
import { ProfilesService } from "./services/profiles";
|
|
6
6
|
import { ExtensionService } from "./services/extensions";
|
|
7
7
|
import { ExtractService } from "./services/extract";
|
|
8
|
+
import { TaskService } from "./services/task";
|
|
8
9
|
export declare class HyperbrowserError extends Error {
|
|
9
10
|
statusCode?: number | undefined;
|
|
10
11
|
constructor(message: string, statusCode?: number | undefined);
|
|
@@ -16,5 +17,6 @@ export declare class HyperbrowserClient {
|
|
|
16
17
|
readonly extract: ExtractService;
|
|
17
18
|
readonly profiles: ProfilesService;
|
|
18
19
|
readonly extensions: ExtensionService;
|
|
20
|
+
readonly tasks: TaskService;
|
|
19
21
|
constructor(config: HyperbrowserConfig);
|
|
20
22
|
}
|
package/dist/client.js
CHANGED
|
@@ -7,6 +7,7 @@ const crawl_1 = require("./services/crawl");
|
|
|
7
7
|
const profiles_1 = require("./services/profiles");
|
|
8
8
|
const extensions_1 = require("./services/extensions");
|
|
9
9
|
const extract_1 = require("./services/extract");
|
|
10
|
+
const task_1 = require("./services/task");
|
|
10
11
|
class HyperbrowserError extends Error {
|
|
11
12
|
constructor(message, statusCode) {
|
|
12
13
|
super(`[Hyperbrowser]: ${message}`);
|
|
@@ -29,6 +30,7 @@ class HyperbrowserClient {
|
|
|
29
30
|
this.extract = new extract_1.ExtractService(apiKey, baseUrl, timeout);
|
|
30
31
|
this.profiles = new profiles_1.ProfilesService(apiKey, baseUrl, timeout);
|
|
31
32
|
this.extensions = new extensions_1.ExtensionService(apiKey, baseUrl, timeout);
|
|
33
|
+
this.tasks = new task_1.TaskService(apiKey, baseUrl, timeout);
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
exports.HyperbrowserClient = HyperbrowserClient;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BasicResponse } from "../types";
|
|
2
|
+
import { StartTaskJobParams, StartTaskJobResponse, TaskJobResponse, TaskJobStatusResponse } from "../types/task";
|
|
3
|
+
import { BaseService } from "./base";
|
|
4
|
+
export declare class TaskService extends BaseService {
|
|
5
|
+
/**
|
|
6
|
+
* Start a new task job
|
|
7
|
+
* @param params The parameters for the task job
|
|
8
|
+
*/
|
|
9
|
+
start(params: StartTaskJobParams): Promise<StartTaskJobResponse>;
|
|
10
|
+
/**
|
|
11
|
+
* Get the status of a task job
|
|
12
|
+
* @param id The ID of the task job to get
|
|
13
|
+
*/
|
|
14
|
+
getStatus(id: string): Promise<TaskJobStatusResponse>;
|
|
15
|
+
/**
|
|
16
|
+
* Get the result of a task job
|
|
17
|
+
* @param id The ID of the task job to get
|
|
18
|
+
*/
|
|
19
|
+
get(id: string): Promise<TaskJobResponse>;
|
|
20
|
+
/**
|
|
21
|
+
* Stop a task job
|
|
22
|
+
* @param id The ID of the task job to stop
|
|
23
|
+
*/
|
|
24
|
+
stop(id: string): Promise<BasicResponse>;
|
|
25
|
+
/**
|
|
26
|
+
* Start a task job and wait for it to complete
|
|
27
|
+
* @param params The parameters for the task job
|
|
28
|
+
*/
|
|
29
|
+
startAndWait(params: StartTaskJobParams): Promise<TaskJobResponse>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TaskService = void 0;
|
|
4
|
+
const client_1 = require("../client");
|
|
5
|
+
const constants_1 = require("../types/constants");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const base_1 = require("./base");
|
|
8
|
+
class TaskService extends base_1.BaseService {
|
|
9
|
+
/**
|
|
10
|
+
* Start a new task job
|
|
11
|
+
* @param params The parameters for the task job
|
|
12
|
+
*/
|
|
13
|
+
async start(params) {
|
|
14
|
+
try {
|
|
15
|
+
return await this.request("/task", {
|
|
16
|
+
method: "POST",
|
|
17
|
+
body: JSON.stringify(params),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (error instanceof client_1.HyperbrowserError) {
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
throw new client_1.HyperbrowserError("Failed to start task job", undefined);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get the status of a task job
|
|
29
|
+
* @param id The ID of the task job to get
|
|
30
|
+
*/
|
|
31
|
+
async getStatus(id) {
|
|
32
|
+
try {
|
|
33
|
+
return await this.request(`/task/${id}/status`);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error instanceof client_1.HyperbrowserError) {
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
throw new client_1.HyperbrowserError(`Failed to get task job ${id} status`, undefined);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get the result of a task job
|
|
44
|
+
* @param id The ID of the task job to get
|
|
45
|
+
*/
|
|
46
|
+
async get(id) {
|
|
47
|
+
try {
|
|
48
|
+
return await this.request(`/task/${id}`);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (error instanceof client_1.HyperbrowserError) {
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
throw new client_1.HyperbrowserError(`Failed to get task job ${id}`, undefined);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Stop a task job
|
|
59
|
+
* @param id The ID of the task job to stop
|
|
60
|
+
*/
|
|
61
|
+
async stop(id) {
|
|
62
|
+
try {
|
|
63
|
+
return await this.request(`/task/${id}/stop`, { method: "PUT" });
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (error instanceof client_1.HyperbrowserError) {
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
throw new client_1.HyperbrowserError(`Failed to stop task job ${id}`, undefined);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Start a task job and wait for it to complete
|
|
74
|
+
* @param params The parameters for the task job
|
|
75
|
+
*/
|
|
76
|
+
async startAndWait(params) {
|
|
77
|
+
const job = await this.start(params);
|
|
78
|
+
const jobId = job.jobId;
|
|
79
|
+
if (!jobId) {
|
|
80
|
+
throw new client_1.HyperbrowserError("Failed to start task job, could not get job ID");
|
|
81
|
+
}
|
|
82
|
+
let failures = 0;
|
|
83
|
+
while (true) {
|
|
84
|
+
try {
|
|
85
|
+
const { status } = await this.getStatus(jobId);
|
|
86
|
+
if (status === "completed" || status === "failed" || status === "stopped") {
|
|
87
|
+
return await this.get(jobId);
|
|
88
|
+
}
|
|
89
|
+
failures = 0;
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
failures++;
|
|
93
|
+
if (failures >= constants_1.POLLING_ATTEMPTS) {
|
|
94
|
+
throw new client_1.HyperbrowserError(`Failed to poll task job ${jobId} after ${constants_1.POLLING_ATTEMPTS} attempts: ${error}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
await (0, utils_1.sleep)(2000);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.TaskService = TaskService;
|
|
@@ -2,12 +2,15 @@ export type ScrapeFormat = "markdown" | "html" | "links" | "screenshot";
|
|
|
2
2
|
export type ScrapeJobStatus = "pending" | "running" | "completed" | "failed";
|
|
3
3
|
export type ExtractJobStatus = "pending" | "running" | "completed" | "failed";
|
|
4
4
|
export type CrawlJobStatus = "pending" | "running" | "completed" | "failed";
|
|
5
|
+
export type TaskJobStatus = "pending" | "running" | "completed" | "failed" | "stopped";
|
|
5
6
|
export type ScrapePageStatus = "completed" | "failed" | "pending" | "running";
|
|
6
7
|
export type CrawlPageStatus = "completed" | "failed";
|
|
7
8
|
export type ScrapeWaitUntil = "load" | "domcontentloaded" | "networkidle";
|
|
8
9
|
export type ScrapeScreenshotFormat = "jpeg" | "png" | "webp";
|
|
9
10
|
export declare const POLLING_ATTEMPTS = 5;
|
|
11
|
+
export type Llm = "gpt-4o" | "gpt-4o-mini" | "claude-3-7-sonnet-20250219" | "claude-3-5-haiku-20241022" | "gemini-2.0-flash" | "gemini-2.0-flash-thinking" | "gemini-2.0-pro";
|
|
10
12
|
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";
|
|
11
13
|
export type OperatingSystem = "windows" | "android" | "macos" | "linux" | "ios";
|
|
12
14
|
export type Platform = "chrome" | "firefox" | "safari" | "edge";
|
|
13
15
|
export type ISO639_1 = "aa" | "ab" | "ae" | "af" | "ak" | "am" | "an" | "ar" | "as" | "av" | "ay" | "az" | "ba" | "be" | "bg" | "bh" | "bi" | "bm" | "bn" | "bo" | "br" | "bs" | "ca" | "ce" | "ch" | "co" | "cr" | "cs" | "cu" | "cv" | "cy" | "da" | "de" | "dv" | "dz" | "ee" | "el" | "en" | "eo" | "es" | "et" | "eu" | "fa" | "ff" | "fi" | "fj" | "fo" | "fr" | "fy" | "ga" | "gd" | "gl" | "gn" | "gu" | "gv" | "ha" | "he" | "hi" | "ho" | "hr" | "ht" | "hu" | "hy" | "hz" | "ia" | "id" | "ie" | "ig" | "ii" | "ik" | "io" | "is" | "it" | "iu" | "ja" | "jv" | "ka" | "kg" | "ki" | "kj" | "kk" | "kl" | "km" | "kn" | "ko" | "kr" | "ks" | "ku" | "kv" | "kw" | "ky" | "la" | "lb" | "lg" | "li" | "ln" | "lo" | "lt" | "lu" | "lv" | "mg" | "mh" | "mi" | "mk" | "ml" | "mn" | "mo" | "mr" | "ms" | "mt" | "my" | "na" | "nb" | "nd" | "ne" | "ng" | "nl" | "nn" | "no" | "nr" | "nv" | "ny" | "oc" | "oj" | "om" | "or" | "os" | "pa" | "pi" | "pl" | "ps" | "pt" | "qu" | "rm" | "rn" | "ro" | "ru" | "rw" | "sa" | "sc" | "sd" | "se" | "sg" | "si" | "sk" | "sl" | "sm" | "sn" | "so" | "sq" | "sr" | "ss" | "st" | "su" | "sv" | "sw" | "ta" | "te" | "tg" | "th" | "ti" | "tk" | "tl" | "tn" | "to" | "tr" | "ts" | "tt" | "tw" | "ty" | "ug" | "uk" | "ur" | "uz" | "ve" | "vi" | "vo" | "wa" | "wo" | "xh" | "yi" | "yo" | "za" | "zh" | "zu";
|
|
16
|
+
export type State = "AL" | "AK" | "AZ" | "AR" | "CA" | "CO" | "CT" | "DE" | "FL" | "GA" | "HI" | "ID" | "IL" | "IN" | "IA" | "KS" | "KY" | "LA" | "ME" | "MD" | "MA" | "MI" | "MN" | "MS" | "MO" | "MT" | "NE" | "NV" | "NH" | "NJ" | "NM" | "NY" | "NC" | "ND" | "OH" | "OK" | "OR" | "PA" | "RI" | "SC" | "SD" | "TN" | "TX" | "UT" | "VT" | "VA" | "WA" | "WV" | "WI" | "WY" | "al" | "ak" | "az" | "ar" | "ca" | "co" | "ct" | "de" | "fl" | "ga" | "hi" | "id" | "il" | "in" | "ia" | "ks" | "ky" | "la" | "me" | "md" | "ma" | "mi" | "mn" | "ms" | "mo" | "mt" | "ne" | "nv" | "nh" | "nj" | "nm" | "ny" | "nc" | "nd" | "oh" | "ok" | "or" | "pa" | "ri" | "sc" | "sd" | "tn" | "tx" | "ut" | "vt" | "va" | "wa" | "wv" | "wi" | "wy";
|
package/dist/types/extract.d.ts
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export { StartScrapeJobParams, StartScrapeJobResponse, ScrapeJobData, ScrapeJobR
|
|
|
4
4
|
export { BasicResponse, SessionStatus, Session, SessionDetail, SessionListParams, SessionListResponse, ScreenConfig, CreateSessionParams, } from "./session";
|
|
5
5
|
export { ProfileResponse, CreateProfileResponse, ProfileListParams, ProfileListResponse, } from "./profile";
|
|
6
6
|
export { CreateExtensionParams, CreateExtensionResponse, ListExtensionsResponse, } from "./extension";
|
|
7
|
-
export { ScrapeJobStatus, CrawlJobStatus, Country, ISO639_1, OperatingSystem, Platform, ScrapeFormat, ScrapeWaitUntil, ScrapePageStatus, CrawlPageStatus, } from "./constants";
|
|
7
|
+
export { ScrapeJobStatus, CrawlJobStatus, Country, State, ISO639_1, OperatingSystem, Platform, ScrapeFormat, ScrapeWaitUntil, ScrapePageStatus, CrawlPageStatus, } from "./constants";
|
package/dist/types/session.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Country, ISO639_1, OperatingSystem, Platform } from "./constants";
|
|
1
|
+
import { Country, ISO639_1, OperatingSystem, Platform, State } from "./constants";
|
|
2
2
|
export type SessionStatus = "active" | "closed" | "error";
|
|
3
3
|
export interface BasicResponse {
|
|
4
4
|
success: boolean;
|
|
@@ -44,6 +44,8 @@ export interface CreateSessionParams {
|
|
|
44
44
|
proxyServerPassword?: string;
|
|
45
45
|
proxyServerUsername?: string;
|
|
46
46
|
proxyCountry?: Country;
|
|
47
|
+
proxyState?: State;
|
|
48
|
+
proxyCity?: string;
|
|
47
49
|
operatingSystems?: OperatingSystem[];
|
|
48
50
|
device?: ("desktop" | "mobile")[];
|
|
49
51
|
platform?: Platform[];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Llm, TaskJobStatus } from "./constants";
|
|
2
|
+
import { CreateSessionParams } from "./session";
|
|
3
|
+
export interface StartTaskJobParams {
|
|
4
|
+
task: string;
|
|
5
|
+
llm?: Llm;
|
|
6
|
+
sessionId?: string;
|
|
7
|
+
validateOutput?: boolean;
|
|
8
|
+
useVision?: boolean;
|
|
9
|
+
useVisionForPlanner?: boolean;
|
|
10
|
+
maxActionsPerStep?: number;
|
|
11
|
+
maxInputTokens?: number;
|
|
12
|
+
plannerLlm?: Llm;
|
|
13
|
+
pageExtractionLlm?: Llm;
|
|
14
|
+
plannerInterval?: number;
|
|
15
|
+
maxSteps?: number;
|
|
16
|
+
keepBrowserOpen?: boolean;
|
|
17
|
+
sessionOptions?: CreateSessionParams;
|
|
18
|
+
}
|
|
19
|
+
export interface StartTaskJobResponse {
|
|
20
|
+
jobId: string;
|
|
21
|
+
}
|
|
22
|
+
export interface TaskJobStatusResponse {
|
|
23
|
+
status: TaskJobStatus;
|
|
24
|
+
}
|
|
25
|
+
export interface TaskJobResponse {
|
|
26
|
+
jobId: string;
|
|
27
|
+
status: TaskJobStatus;
|
|
28
|
+
data?: object | null;
|
|
29
|
+
error?: string | null;
|
|
30
|
+
}
|