-
Notifications
You must be signed in to change notification settings - Fork 1
Add SDK API parity methods #83
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
3
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
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { HyperbrowserError } from "../../client"; | ||
| import { AgentTaskListParams, AgentTaskListResponse } from "../../types/agents/task"; | ||
| import { BaseService } from "../base"; | ||
|
|
||
| export abstract class AgentTaskListService extends BaseService { | ||
| protected abstract readonly taskPath: string; | ||
| protected abstract readonly taskLabel: string; | ||
|
|
||
| async list(params: AgentTaskListParams = {}): Promise<AgentTaskListResponse> { | ||
| try { | ||
| return await this.request<AgentTaskListResponse>(`/task/${this.taskPath}`, undefined, { | ||
| task: params.task, | ||
| page: params.page, | ||
| limit: params.limit, | ||
| }); | ||
| } catch (error) { | ||
| if (error instanceof HyperbrowserError) { | ||
| throw error; | ||
| } | ||
| throw new HyperbrowserError(`Failed to list ${this.taskLabel} task jobs`, undefined); | ||
| } | ||
| } | ||
| } |
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,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); | ||
| } | ||
| } | ||
| } | ||
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.