Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { HyperAgentService } from "./services/agents/hyper-agent";
import { TeamService } from "./services/team";
import { ComputerActionService } from "./services/computer-action";
import { GeminiComputerUseService } from "./services/agents/gemini-computer-use";
import { TaskService } from "./services/agents/task";
import { WebService } from "./services/web";
import { SandboxesService } from "./services/sandboxes";
import { VolumesService } from "./services/volumes";
Expand Down Expand Up @@ -67,6 +68,7 @@ export class HyperbrowserClient {
cua: CuaService;
hyperAgent: HyperAgentService;
geminiComputerUse: GeminiComputerUseService;
task: TaskService;
};
public readonly team: TeamService;
public readonly computerAction: ComputerActionService;
Expand Down Expand Up @@ -102,6 +104,7 @@ export class HyperbrowserClient {
cua: new CuaService(apiKey, baseUrl, timeout),
hyperAgent: new HyperAgentService(apiKey, baseUrl, timeout),
geminiComputerUse: new GeminiComputerUseService(apiKey, baseUrl, timeout),
task: new TaskService(apiKey, baseUrl, timeout),
};
}
}
21 changes: 21 additions & 0 deletions src/services/agents/browser-use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,29 @@ import {
} from "../../types/agents/browser-use";
import { isZodSchema, sleep } from "../../utils";
import { BaseService } from "../base";
import { AgentTaskListParams, AgentTaskListResponse } from "../../types/agents/task";

export class BrowserUseService extends BaseService {

/**
* List task jobs
* @param params Optional filters and pagination
*/
async list(params: AgentTaskListParams = {}): Promise<AgentTaskListResponse> {
try {
return await this.request<AgentTaskListResponse>("/task/browser-use", undefined, {
task: params.task,
page: params.page,
limit: params.limit,
});
} catch (error) {
if (error instanceof HyperbrowserError) {
throw error;
}
throw new HyperbrowserError("Failed to list browser-use task jobs", undefined);
}
}
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated

/**
* Start a new browser-use task job
* @param params The parameters for the task job
Expand Down
21 changes: 21 additions & 0 deletions src/services/agents/claude-computer-use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BasicResponse } from "../../types";
import { POLLING_ATTEMPTS } from "../../types/constants";
import { sleep } from "../../utils";
import { BaseService } from "../base";
import { AgentTaskListParams, AgentTaskListResponse } from "../../types/agents/task";
import {
ClaudeComputerUseTaskResponse,
ClaudeComputerUseTaskStatusResponse,
Expand All @@ -11,6 +12,26 @@ import {
} from "../../types/agents/claude-computer-use";

export class ClaudeComputerUseService extends BaseService {

/**
* List task jobs
* @param params Optional filters and pagination
*/
async list(params: AgentTaskListParams = {}): Promise<AgentTaskListResponse> {
try {
return await this.request<AgentTaskListResponse>("/task/claude-computer-use", undefined, {
task: params.task,
page: params.page,
limit: params.limit,
});
} catch (error) {
if (error instanceof HyperbrowserError) {
throw error;
}
throw new HyperbrowserError("Failed to list claude-computer-use task jobs", undefined);
}
}

/**
* Start a new Claude Computer Use task job
* @param params The parameters for the task job
Expand Down
21 changes: 21 additions & 0 deletions src/services/agents/cua.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BasicResponse } from "../../types";
import { POLLING_ATTEMPTS } from "../../types/constants";
import { sleep } from "../../utils";
import { BaseService } from "../base";
import { AgentTaskListParams, AgentTaskListResponse } from "../../types/agents/task";
import {
CuaTaskResponse,
CuaTaskStatusResponse,
Expand All @@ -11,6 +12,26 @@ import {
} from "../../types/agents/cua";

export class CuaService extends BaseService {

/**
* List task jobs
* @param params Optional filters and pagination
*/
async list(params: AgentTaskListParams = {}): Promise<AgentTaskListResponse> {
try {
return await this.request<AgentTaskListResponse>("/task/cua", undefined, {
task: params.task,
page: params.page,
limit: params.limit,
});
} catch (error) {
if (error instanceof HyperbrowserError) {
throw error;
}
throw new HyperbrowserError("Failed to list cua task jobs", undefined);
}
}

/**
* Start a new CUA task job
* @param params The parameters for the task job
Expand Down
21 changes: 21 additions & 0 deletions src/services/agents/gemini-computer-use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BasicResponse } from "../../types";
import { POLLING_ATTEMPTS } from "../../types/constants";
import { sleep } from "../../utils";
import { BaseService } from "../base";
import { AgentTaskListParams, AgentTaskListResponse } from "../../types/agents/task";
import {
GeminiComputerUseTaskResponse,
GeminiComputerUseTaskStatusResponse,
Expand All @@ -11,6 +12,26 @@ import {
} from "../../types/agents/gemini-computer-use";

export class GeminiComputerUseService extends BaseService {

/**
* List task jobs
* @param params Optional filters and pagination
*/
async list(params: AgentTaskListParams = {}): Promise<AgentTaskListResponse> {
try {
return await this.request<AgentTaskListResponse>("/task/gemini-computer-use", undefined, {
task: params.task,
page: params.page,
limit: params.limit,
});
} catch (error) {
if (error instanceof HyperbrowserError) {
throw error;
}
throw new HyperbrowserError("Failed to list gemini-computer-use task jobs", undefined);
}
}

/**
* Start a new Gemini Computer Use task job
* @param params The parameters for the task job
Expand Down
21 changes: 21 additions & 0 deletions src/services/agents/hyper-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BasicResponse } from "../../types";
import { POLLING_ATTEMPTS } from "../../types/constants";
import { sleep } from "../../utils";
import { BaseService } from "../base";
import { AgentTaskListParams, AgentTaskListResponse } from "../../types/agents/task";
import {
HyperAgentTaskResponse,
HyperAgentTaskStatusResponse,
Expand All @@ -11,6 +12,26 @@ import {
} from "../../types/agents/hyper-agent";

export class HyperAgentService extends BaseService {

/**
* List task jobs
* @param params Optional filters and pagination
*/
async list(params: AgentTaskListParams = {}): Promise<AgentTaskListResponse> {
try {
return await this.request<AgentTaskListResponse>("/task/hyper-agent", undefined, {
task: params.task,
page: params.page,
limit: params.limit,
});
} catch (error) {
if (error instanceof HyperbrowserError) {
throw error;
}
throw new HyperbrowserError("Failed to list hyper-agent task jobs", undefined);
}
}

/**
* Start a new HyperAgent task job
* @param params The parameters for the task job
Expand Down
87 changes: 87 additions & 0 deletions src/services/agents/task.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { HyperbrowserError } from "../../client";
import { BasicResponse } from "../../types";
import { POLLING_ATTEMPTS } from "../../types/constants";
import {
StartTaskParams,
StartTaskResponse,
TaskResponse,
TaskStatusResponse,
} from "../../types/agents/task";
import { sleep } from "../../utils";
import { BaseService } from "../base";

export class TaskService extends BaseService {
async start(params: StartTaskParams): Promise<StartTaskResponse> {
try {
return await this.request<StartTaskResponse>("/task", {
method: "POST",
body: JSON.stringify(params),
});
} catch (error) {
if (error instanceof HyperbrowserError) {
throw error;
}
throw new HyperbrowserError("Failed to start task job", undefined);
}
}

async getStatus(id: string): Promise<TaskStatusResponse> {
try {
return await this.request<TaskStatusResponse>(`/task/${id}/status`);
} catch (error) {
if (error instanceof HyperbrowserError) {
throw error;
}
throw new HyperbrowserError(`Failed to get task job ${id} status`, undefined);
}
}

async get(id: string): Promise<TaskResponse> {
try {
return await this.request<TaskResponse>(`/task/${id}`);
} catch (error) {
if (error instanceof HyperbrowserError) {
throw error;
}
throw new HyperbrowserError(`Failed to get task job ${id}`, undefined);
}
}

async stop(id: string): Promise<BasicResponse> {
try {
return await this.request<BasicResponse>(`/task/${id}/stop`, { method: "PUT" });
} catch (error) {
if (error instanceof HyperbrowserError) {
throw error;
}
throw new HyperbrowserError(`Failed to stop task job ${id}`, undefined);
}
}

async startAndWait(params: StartTaskParams): Promise<TaskResponse> {
const jobStartResp = await this.start(params);
const jobId = jobStartResp.jobId;
if (!jobId) {
throw new HyperbrowserError("Failed to start task job");
}

let failures = 0;
while (true) {
try {
const jobResponse = await this.getStatus(jobId);
if (["completed", "failed", "stopped"].includes(jobResponse.status)) {
return await this.get(jobId);
}
failures = 0;
} catch (error) {
failures++;
if (failures >= POLLING_ATTEMPTS) {
throw new HyperbrowserError(
`Failed to poll task job ${jobId} after ${POLLING_ATTEMPTS} attempts: ${error}`
);
}
}
await sleep(2000);
}
Comment thread
cursor[bot] marked this conversation as resolved.
}
}
40 changes: 40 additions & 0 deletions src/services/profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
CreateProfileParams,
ProfileResponse,
CreateProfileResponse,
UpdateProfileParams,
BatchDeleteProfilesParams,
ProfileListParams,
ProfileListResponse,
} from "../types/profile";
Expand Down Expand Up @@ -60,6 +62,44 @@ export class ProfilesService extends BaseService {
}
}


/**
* Update an existing profile
* @param id The ID of the profile to update
* @param params Profile fields to update
*/
async update(id: string, params: UpdateProfileParams): Promise<ProfileResponse> {
try {
return await this.request<ProfileResponse>(`/profile/${id}`, {
method: "PUT",
body: JSON.stringify(params),
});
} catch (error) {
if (error instanceof HyperbrowserError) {
throw error;
}
throw new HyperbrowserError(`Failed to update profile ${id}`, undefined);
}
}

/**
* Delete multiple profiles
* @param params Profile IDs to delete
*/
async deleteMany(params: BatchDeleteProfilesParams): Promise<BasicResponse> {
try {
return await this.request<BasicResponse>("/profiles", {
method: "DELETE",
body: JSON.stringify(params),
});
} catch (error) {
if (error instanceof HyperbrowserError) {
throw error;
}
throw new HyperbrowserError("Failed to delete profiles", undefined);
}
}

/**
* List all profiles with optional pagination
* @param params Optional parameters to filter the profiles
Expand Down
Loading