@hyperbrowser/sdk 0.36.0 → 0.38.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 +3 -1
- package/dist/client.js +3 -1
- package/dist/services/agents/cua.d.ts +30 -0
- package/dist/services/agents/cua.js +101 -0
- package/dist/types/agents/cua.d.ts +49 -0
- package/dist/types/agents/cua.js +2 -0
- package/dist/types/config.d.ts +1 -1
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { ProfilesService } from "./services/profiles";
|
|
|
6
6
|
import { ExtensionService } from "./services/extensions";
|
|
7
7
|
import { ExtractService } from "./services/extract";
|
|
8
8
|
import { BrowserUseService } from "./services/agents/browser-use";
|
|
9
|
+
import { CuaService } from "./services/agents/cua";
|
|
9
10
|
export declare class HyperbrowserError extends Error {
|
|
10
11
|
statusCode?: number | undefined;
|
|
11
12
|
constructor(message: string, statusCode?: number | undefined);
|
|
@@ -19,6 +20,7 @@ export declare class HyperbrowserClient {
|
|
|
19
20
|
readonly extensions: ExtensionService;
|
|
20
21
|
readonly agents: {
|
|
21
22
|
browserUse: BrowserUseService;
|
|
23
|
+
cua: CuaService;
|
|
22
24
|
};
|
|
23
|
-
constructor(config
|
|
25
|
+
constructor(config?: HyperbrowserConfig);
|
|
24
26
|
}
|
package/dist/client.js
CHANGED
|
@@ -8,6 +8,7 @@ const profiles_1 = require("./services/profiles");
|
|
|
8
8
|
const extensions_1 = require("./services/extensions");
|
|
9
9
|
const extract_1 = require("./services/extract");
|
|
10
10
|
const browser_use_1 = require("./services/agents/browser-use");
|
|
11
|
+
const cua_1 = require("./services/agents/cua");
|
|
11
12
|
class HyperbrowserError extends Error {
|
|
12
13
|
constructor(message, statusCode) {
|
|
13
14
|
super(`[Hyperbrowser]: ${message}`);
|
|
@@ -17,7 +18,7 @@ class HyperbrowserError extends Error {
|
|
|
17
18
|
}
|
|
18
19
|
exports.HyperbrowserError = HyperbrowserError;
|
|
19
20
|
class HyperbrowserClient {
|
|
20
|
-
constructor(config) {
|
|
21
|
+
constructor(config = {}) {
|
|
21
22
|
const apiKey = config.apiKey || process.env["HYPERBROWSER_API_KEY"];
|
|
22
23
|
const baseUrl = config.baseUrl || "https://app.hyperbrowser.ai";
|
|
23
24
|
const timeout = config.timeout || 30000;
|
|
@@ -32,6 +33,7 @@ class HyperbrowserClient {
|
|
|
32
33
|
this.extensions = new extensions_1.ExtensionService(apiKey, baseUrl, timeout);
|
|
33
34
|
this.agents = {
|
|
34
35
|
browserUse: new browser_use_1.BrowserUseService(apiKey, baseUrl, timeout),
|
|
36
|
+
cua: new cua_1.CuaService(apiKey, baseUrl, timeout),
|
|
35
37
|
};
|
|
36
38
|
}
|
|
37
39
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BasicResponse } from "../../types";
|
|
2
|
+
import { BaseService } from "../base";
|
|
3
|
+
import { CuaTaskResponse, CuaTaskStatusResponse, StartCuaTaskParams, StartCuaTaskResponse } from "../../types/agents/cua";
|
|
4
|
+
export declare class CuaService extends BaseService {
|
|
5
|
+
/**
|
|
6
|
+
* Start a new CUA task job
|
|
7
|
+
* @param params The parameters for the task job
|
|
8
|
+
*/
|
|
9
|
+
start(params: StartCuaTaskParams): Promise<StartCuaTaskResponse>;
|
|
10
|
+
/**
|
|
11
|
+
* Get the status of a CUA task job
|
|
12
|
+
* @param id The ID of the task job to get
|
|
13
|
+
*/
|
|
14
|
+
getStatus(id: string): Promise<CuaTaskStatusResponse>;
|
|
15
|
+
/**
|
|
16
|
+
* Get the result of a CUA task job
|
|
17
|
+
* @param id The ID of the task job to get
|
|
18
|
+
*/
|
|
19
|
+
get(id: string): Promise<CuaTaskResponse>;
|
|
20
|
+
/**
|
|
21
|
+
* Stop a CUA task job
|
|
22
|
+
* @param id The ID of the task job to stop
|
|
23
|
+
*/
|
|
24
|
+
stop(id: string): Promise<BasicResponse>;
|
|
25
|
+
/**
|
|
26
|
+
* Start a CUA task job and wait for it to complete
|
|
27
|
+
* @param params The parameters for the task job
|
|
28
|
+
*/
|
|
29
|
+
startAndWait(params: StartCuaTaskParams): Promise<CuaTaskResponse>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CuaService = 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 CuaService extends base_1.BaseService {
|
|
9
|
+
/**
|
|
10
|
+
* Start a new CUA task job
|
|
11
|
+
* @param params The parameters for the task job
|
|
12
|
+
*/
|
|
13
|
+
async start(params) {
|
|
14
|
+
try {
|
|
15
|
+
return await this.request("/task/cua", {
|
|
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 CUA task job", undefined);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get the status of a CUA 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/cua/${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 CUA task job ${id} status`, undefined);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get the result of a CUA 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/cua/${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 CUA task job ${id}`, undefined);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Stop a CUA 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/cua/${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 CUA task job ${id}`, undefined);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Start a CUA 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 CUA 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 CUA task job ${jobId} after ${constants_1.POLLING_ATTEMPTS} attempts: ${error}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
await (0, utils_1.sleep)(2000);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.CuaService = CuaService;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { CuaTaskStatus } from "../constants";
|
|
2
|
+
import { CreateSessionParams } from "../session";
|
|
3
|
+
export interface StartCuaTaskParams {
|
|
4
|
+
task: string;
|
|
5
|
+
sessionId?: string;
|
|
6
|
+
maxFailures?: number;
|
|
7
|
+
maxSteps?: number;
|
|
8
|
+
keepBrowserOpen?: boolean;
|
|
9
|
+
sessionOptions?: CreateSessionParams;
|
|
10
|
+
}
|
|
11
|
+
export interface StartCuaTaskResponse {
|
|
12
|
+
jobId: string;
|
|
13
|
+
liveUrl: string | null;
|
|
14
|
+
}
|
|
15
|
+
export interface CuaTaskStatusResponse {
|
|
16
|
+
status: CuaTaskStatus;
|
|
17
|
+
}
|
|
18
|
+
export interface CuaStepResponseError {
|
|
19
|
+
code: string;
|
|
20
|
+
message: string;
|
|
21
|
+
}
|
|
22
|
+
export interface CuaStepIncompleteDetails {
|
|
23
|
+
reason?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface CuaStepReasoning {
|
|
26
|
+
effort: string | null;
|
|
27
|
+
generate_summary?: string | null;
|
|
28
|
+
}
|
|
29
|
+
export interface CuaStepResponse {
|
|
30
|
+
created_at: number;
|
|
31
|
+
output_text: string;
|
|
32
|
+
error: CuaStepResponseError | null;
|
|
33
|
+
incomplete_details: CuaStepIncompleteDetails | null;
|
|
34
|
+
model: string;
|
|
35
|
+
output: Array<any>;
|
|
36
|
+
reasoning?: CuaStepReasoning | null;
|
|
37
|
+
status?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface CuaTaskData {
|
|
40
|
+
steps: CuaStepResponse[];
|
|
41
|
+
finalResult: string | null;
|
|
42
|
+
}
|
|
43
|
+
export interface CuaTaskResponse {
|
|
44
|
+
jobId: string;
|
|
45
|
+
status: CuaTaskStatus;
|
|
46
|
+
data?: CuaTaskData | null;
|
|
47
|
+
error?: string | null;
|
|
48
|
+
liveUrl: string | null;
|
|
49
|
+
}
|
package/dist/types/config.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ 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
5
|
export type BrowserUseTaskStatus = "pending" | "running" | "completed" | "failed" | "stopped";
|
|
6
|
+
export type CuaTaskStatus = "pending" | "running" | "completed" | "failed" | "stopped";
|
|
6
7
|
export type ScrapePageStatus = "completed" | "failed" | "pending" | "running";
|
|
7
8
|
export type CrawlPageStatus = "completed" | "failed";
|
|
8
9
|
export type ScrapeWaitUntil = "load" | "domcontentloaded" | "networkidle";
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { StartCrawlJobParams, StartCrawlJobResponse, CrawledPage, CrawlJobRespon
|
|
|
3
3
|
export { StartScrapeJobParams, StartScrapeJobResponse, ScrapeJobData, ScrapeJobResponse, ScrapeOptions, ScrapeJobStatusResponse, BatchScrapeJobStatusResponse, } from "./scrape";
|
|
4
4
|
export { StartExtractJobParams, StartExtractJobResponse, ExtractJobResponse, ExtractJobStatusResponse, } from "./extract";
|
|
5
5
|
export { StartBrowserUseTaskParams, StartBrowserUseTaskResponse, BrowserUseTaskStatusResponse, BrowserUseTaskResponse, BrowserUseTaskData, } from "./agents/browser-use";
|
|
6
|
+
export { StartCuaTaskParams, StartCuaTaskResponse, CuaTaskStatusResponse, CuaTaskResponse, CuaTaskData, CuaStepResponse, } from "./agents/cua";
|
|
6
7
|
export { BasicResponse, SessionStatus, Session, SessionDetail, SessionListParams, SessionListResponse, ScreenConfig, CreateSessionParams, } from "./session";
|
|
7
8
|
export { ProfileResponse, CreateProfileResponse, ProfileListParams, ProfileListResponse, } from "./profile";
|
|
8
9
|
export { CreateExtensionParams, CreateExtensionResponse, ListExtensionsResponse, } from "./extension";
|