Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions hyperbrowser/client/managers/async_manager/agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .claude_computer_use import ClaudeComputerUseManager
from .hyper_agent import HyperAgentManager
from .gemini_computer_use import GeminiComputerUseManager
from .task import TaskManager


class Agents:
Expand All @@ -12,3 +13,4 @@ def __init__(self, client):
self.claude_computer_use = ClaudeComputerUseManager(client)
self.hyper_agent = HyperAgentManager(client)
self.gemini_computer_use = GeminiComputerUseManager(client)
self.task = TaskManager(client)
11 changes: 11 additions & 0 deletions hyperbrowser/client/managers/async_manager/agents/browser_use.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from .....models import (
POLLING_ATTEMPTS,
BasicResponse,
AgentTaskListParams,
AgentTaskListResponse,
BrowserUseTaskResponse,
BrowserUseTaskStatusResponse,
StartBrowserUseTaskParams,
Expand Down Expand Up @@ -51,6 +53,15 @@ async def stop(self, job_id: str) -> BasicResponse:
)
return BasicResponse(**response.data)

async def list(
self, params: AgentTaskListParams = AgentTaskListParams()
) -> AgentTaskListResponse:
response = await self._client.transport.get(
self._client._build_url("/task/browser-use"),
params=params.model_dump(exclude_none=True, by_alias=True),
)
return AgentTaskListResponse(**response.data)

async def start_and_wait(
self, params: StartBrowserUseTaskParams
) -> BrowserUseTaskResponse:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from .....models import (
POLLING_ATTEMPTS,
BasicResponse,
AgentTaskListParams,
AgentTaskListResponse,
ClaudeComputerUseTaskResponse,
ClaudeComputerUseTaskStatusResponse,
StartClaudeComputerUseTaskParams,
Expand Down Expand Up @@ -43,6 +45,15 @@ async def stop(self, job_id: str) -> BasicResponse:
)
return BasicResponse(**response.data)

async def list(
self, params: AgentTaskListParams = AgentTaskListParams()
) -> AgentTaskListResponse:
response = await self._client.transport.get(
self._client._build_url("/task/claude-computer-use"),
params=params.model_dump(exclude_none=True, by_alias=True),
)
return AgentTaskListResponse(**response.data)

async def start_and_wait(
self, params: StartClaudeComputerUseTaskParams
) -> ClaudeComputerUseTaskResponse:
Expand Down
11 changes: 11 additions & 0 deletions hyperbrowser/client/managers/async_manager/agents/cua.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from .....models import (
POLLING_ATTEMPTS,
BasicResponse,
AgentTaskListParams,
AgentTaskListResponse,
CuaTaskResponse,
CuaTaskStatusResponse,
StartCuaTaskParams,
Expand Down Expand Up @@ -41,6 +43,15 @@ async def stop(self, job_id: str) -> BasicResponse:
)
return BasicResponse(**response.data)

async def list(
self, params: AgentTaskListParams = AgentTaskListParams()
) -> AgentTaskListResponse:
response = await self._client.transport.get(
self._client._build_url("/task/cua"),
params=params.model_dump(exclude_none=True, by_alias=True),
)
return AgentTaskListResponse(**response.data)

async def start_and_wait(self, params: StartCuaTaskParams) -> CuaTaskResponse:
job_start_resp = await self.start(params)
job_id = job_start_resp.job_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from .....models import (
POLLING_ATTEMPTS,
BasicResponse,
AgentTaskListParams,
AgentTaskListResponse,
GeminiComputerUseTaskResponse,
GeminiComputerUseTaskStatusResponse,
StartGeminiComputerUseTaskParams,
Expand Down Expand Up @@ -43,6 +45,15 @@ async def stop(self, job_id: str) -> BasicResponse:
)
return BasicResponse(**response.data)

async def list(
self, params: AgentTaskListParams = AgentTaskListParams()
) -> AgentTaskListResponse:
response = await self._client.transport.get(
self._client._build_url("/task/gemini-computer-use"),
params=params.model_dump(exclude_none=True, by_alias=True),
)
return AgentTaskListResponse(**response.data)

async def start_and_wait(
self, params: StartGeminiComputerUseTaskParams
) -> GeminiComputerUseTaskResponse:
Expand Down
11 changes: 11 additions & 0 deletions hyperbrowser/client/managers/async_manager/agents/hyper_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from .....models import (
POLLING_ATTEMPTS,
BasicResponse,
AgentTaskListParams,
AgentTaskListResponse,
HyperAgentTaskResponse,
HyperAgentTaskStatusResponse,
StartHyperAgentTaskParams,
Expand Down Expand Up @@ -43,6 +45,15 @@ async def stop(self, job_id: str) -> BasicResponse:
)
return BasicResponse(**response.data)

async def list(
self, params: AgentTaskListParams = AgentTaskListParams()
) -> AgentTaskListResponse:
response = await self._client.transport.get(
self._client._build_url("/task/hyper-agent"),
params=params.model_dump(exclude_none=True, by_alias=True),
)
return AgentTaskListResponse(**response.data)

async def start_and_wait(
self, params: StartHyperAgentTaskParams
) -> HyperAgentTaskResponse:
Expand Down
73 changes: 73 additions & 0 deletions hyperbrowser/client/managers/async_manager/agents/task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import asyncio

from hyperbrowser.exceptions import HyperbrowserError
from .....models import (
POLLING_ATTEMPTS,
BasicResponse,
AgentTaskListParams,
AgentTaskListResponse,
StartTaskParams,
StartTaskResponse,
TaskResponse,
TaskStatusResponse,
)


class TaskManager:
def __init__(self, client):
self._client = client

async def start(self, params: StartTaskParams) -> StartTaskResponse:
response = await self._client.transport.post(
self._client._build_url("/task"),
data=params.model_dump(exclude_none=True, by_alias=True),
)
return StartTaskResponse(**response.data)

async def get(self, job_id: str) -> TaskResponse:
response = await self._client.transport.get(
self._client._build_url(f"/task/{job_id}")
)
return TaskResponse(**response.data)

async def get_status(self, job_id: str) -> TaskStatusResponse:
response = await self._client.transport.get(
self._client._build_url(f"/task/{job_id}/status")
)
return TaskStatusResponse(**response.data)

async def stop(self, job_id: str) -> BasicResponse:
response = await self._client.transport.put(
self._client._build_url(f"/task/{job_id}/stop")
)
return BasicResponse(**response.data)

async def list(
self, params: AgentTaskListParams = AgentTaskListParams()
) -> AgentTaskListResponse:
response = await self._client.transport.get(
self._client._build_url("/task"),
params=params.model_dump(exclude_none=True, by_alias=True),
)
return AgentTaskListResponse(**response.data)

async def start_and_wait(self, params: StartTaskParams) -> TaskResponse:
job_start_resp = await self.start(params)
job_id = job_start_resp.job_id
if not job_id:
raise HyperbrowserError("Failed to start task job")

failures = 0
while True:
try:
job_response = await self.get_status(job_id)
if job_response.status in ("completed", "failed", "stopped"):
return await self.get(job_id)
failures = 0
except Exception as e:
failures += 1
if failures >= POLLING_ATTEMPTS:
raise HyperbrowserError(
f"Failed to poll task job {job_id} after {POLLING_ATTEMPTS} attempts: {e}"
)
await asyncio.sleep(2)
Comment thread
cursor[bot] marked this conversation as resolved.
18 changes: 18 additions & 0 deletions hyperbrowser/client/managers/async_manager/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
ProfileListParams,
ProfileListResponse,
ProfileResponse,
UpdateProfileParams,
BatchDeleteProfilesParams,
)
from hyperbrowser.models.session import BasicResponse

Expand Down Expand Up @@ -35,6 +37,22 @@ async def delete(self, id: str) -> BasicResponse:
)
return BasicResponse(**response.data)

async def update(self, id: str, params: UpdateProfileParams) -> ProfileResponse:
response = await self._client.transport.put(
self._client._build_url(f"/profile/{id}"),
data=params.model_dump(exclude_none=True, by_alias=True),
)
return ProfileResponse(**response.data)

async def delete_many(self, params: BatchDeleteProfilesParams) -> BasicResponse:
response = await self._client.transport.client.request(
"DELETE",
self._client._build_url("/profiles"),
json=params.model_dump(exclude_none=True, by_alias=True),
)
handled = await self._client.transport._handle_response(response)
return BasicResponse(**handled.data)

async def list(
self, params: ProfileListParams = ProfileListParams()
) -> ProfileListResponse:
Expand Down
69 changes: 67 additions & 2 deletions hyperbrowser/client/managers/async_manager/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
SandboxImageListResponse,
SandboxListParams,
SandboxListResponse,
SandboxImageListParams,
SandboxRuntimeBrowserAuthResponse,
CreateFirecrackerImageBuildParams,
CompleteFirecrackerImageBuildParams,
CreateFirecrackerImageBuildResponse,
FirecrackerImageBuildResponse,
FirecrackerImageBuildListParams,
FirecrackerImageBuildListResponse,
SandboxMemorySnapshotParams,
SandboxMemorySnapshotResult,
SandboxRuntimeSession,
Expand Down Expand Up @@ -350,8 +358,15 @@ async def list(
)
return SandboxListResponse(**payload)

async def list_images(self) -> SandboxImageListResponse:
payload = await self._request("GET", "/images")
async def list_images(
self, params: SandboxImageListParams = SandboxImageListParams()
) -> SandboxImageListResponse:
query = params.model_dump(exclude_none=True, by_alias=True)
payload = await self._request(
"GET",
"/images",
params=query or None,
)
return SandboxImageListResponse(**payload)

async def list_snapshots(
Expand All @@ -366,6 +381,56 @@ async def list_snapshots(
)
return SandboxSnapshotListResponse(**payload)

async def get_runtime_browser_auth(
self, sandbox_id: str, allowed_origin: str
) -> SandboxRuntimeBrowserAuthResponse:
response = await self._client.transport.client.request(
"POST",
self._client._build_url(f"/sandbox/{sandbox_id}/runtime/browser-auth"),
headers={"Origin": allowed_origin},
)
payload = await self._client.transport._handle_response(response)
return SandboxRuntimeBrowserAuthResponse(**payload.data)

async def create_image_build(
self, params: CreateFirecrackerImageBuildParams
) -> CreateFirecrackerImageBuildResponse:
payload = await self._request(
"POST",
"/images/builds",
data=params.model_dump(exclude_none=True, by_alias=True),
)
return CreateFirecrackerImageBuildResponse(**payload)

async def list_image_builds(
self,
params: FirecrackerImageBuildListParams = FirecrackerImageBuildListParams(),
) -> FirecrackerImageBuildListResponse:
payload = await self._request(
"GET",
"/images/builds",
params=params.model_dump(exclude_none=True, by_alias=True),
)
return FirecrackerImageBuildListResponse(**payload)

async def get_image_build(self, build_id: str) -> FirecrackerImageBuildResponse:
payload = await self._request("GET", f"/images/builds/{build_id}")
return FirecrackerImageBuildResponse(**payload)

async def complete_image_build(
self, build_id: str, params: CompleteFirecrackerImageBuildParams
) -> FirecrackerImageBuildResponse:
payload = await self._request(
"POST",
f"/images/builds/{build_id}/complete",
data=params.model_dump(exclude_none=True, by_alias=True),
)
return FirecrackerImageBuildResponse(**payload)

async def cancel_image_build(self, build_id: str) -> FirecrackerImageBuildResponse:
payload = await self._request("POST", f"/images/builds/{build_id}/cancel")
return FirecrackerImageBuildResponse(**payload)

async def stop(self, sandbox_id: str) -> BasicResponse:
payload = await self._request("PUT", f"/sandbox/{sandbox_id}/stop")
return BasicResponse(**payload)
Expand Down
Loading