-
Notifications
You must be signed in to change notification settings - Fork 2
Add SDK API parity methods #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shrisukhani
wants to merge
6
commits into
main
Choose a base branch
from
cursor/sdk-api-parity-b9e9
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e50f611
Add SDK API parity methods
cursoragent fa8ac44
Keep sandbox image helpers on manager
cursoragent f8b1c7e
Align task model types
cursoragent 9071cca
Add generic task list methods
cursoragent 83b11f9
fix(session): accept int status codes in SessionNetworkParams
cursoragent 222e3eb
Relax task list pagination fields
cursoragent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.