chaser-sdk
Advanced tools
+16
-1
| import { CdpClient, type CdpClientOptions } from './cdp.js'; | ||
| import type { AccountInfo, AccountMemberInfo, ApiKeyInfo, AuditEventInfo, AuditEventListQuery, BillingSummaryResponse, BrowserCdpTargetInfo, BrowserCdpVersionInfo, BulkDeleteWorkspacesResponse, BulkTerminateRequest, BulkTerminateResponse, CdpConnectOptions, CreateApiKeyResponse, CreateBillingCheckoutRequest, CreateBillingCheckoutResponse, CreateJobRequest, CreateServiceAccountKeyResponse, CreateSessionRequest, CreateWorkspaceRequest, CreateCustomerWebhookRequest, CreateCustomerWebhookResponse, CustomerWebhookDeliveryInfo, CustomerWebhookInfo, JobInfo, JobKindsInfo, ListJobsPage, SandboxExecRequest, SandboxExecResponse, SessionCommandInfo, SessionCommandKillRequest, SessionCommandKillResponse, SessionCommandStreamQuery, SessionCommandStdinRequest, SessionCommandStdinResponse, SessionExecRequest, SessionInfo, SessionSelfTestResponse, ServiceAccountInfo, ServiceAccountKeyInfo, SshKeyInfo, UpdateBillingAccountRequest, UploadFileRequest, UploadFileResponse, WaitForCommandOptions, WaitForSessionOptions, WorkspaceInfo, WorkspaceNameResponse, WorkspaceSnapshotInfo, WorkspaceTemplateResponse, BulkDeleteWorkspacesRequest } from './types.js'; | ||
| import type { AccountInfo, AccountMemberInfo, ApiKeyInfo, AuditEventInfo, AuditEventListQuery, BillingSummaryResponse, BrowserActionJobInput, BrowserCdpTargetInfo, BrowserCdpVersionInfo, BulkDeleteWorkspacesResponse, BulkDeleteWorkspacesRequest, BulkTerminateRequest, BulkTerminateResponse, CdpConnectOptions, CreateApiKeyResponse, CreateBillingCheckoutRequest, CreateBillingCheckoutResponse, CreateCustomerWebhookRequest, CreateCustomerWebhookResponse, CreateJobRequest, CreateServiceAccountKeyResponse, CreateSessionRequest, CreateWorkspaceRequest, CustomerWebhookDeliveryInfo, CustomerWebhookInfo, GithubRepositoriesResponse, GithubRunnerJobInput, ImportWorkspaceRequest, ImportWorkspaceResponse, JobInfo, JobCreateOptions, JobKindsInfo, ListSessionsResponse, ListJobsPage, BrowserScrapeJobInput, PipelineRunJobInput, SandboxExecRequest, SandboxExecResponse, SessionBulkTerminateJobInput, SessionCommandInfo, SessionCommandKillRequest, SessionCommandKillResponse, SessionCommandStreamQuery, SessionCommandStdinRequest, SessionCommandStdinResponse, SessionExecRequest, SessionInfo, SessionSelfTestResponse, SessionTerminateJobInput, ServiceAccountInfo, ServiceAccountKeyInfo, SshKeyInfo, UpdateBillingAccountRequest, UploadFileRequest, UploadFileResponse, WaitForJobOptions, WaitForCommandOptions, WaitForSessionOptions, WorkspaceBulkDeleteJobInput, WorkspaceDeleteJobInput, WorkspaceInfo, WorkspaceNameResponse, WorkspaceSnapshotInfo, WorkspaceTemplateResponse } from './types.js'; | ||
| type FetchLike = typeof fetch; | ||
@@ -65,2 +65,3 @@ interface RevokeApiKeyResponse { | ||
| list: () => Promise<SessionInfo[]>; | ||
| listPage: () => Promise<ListSessionsResponse>; | ||
| get: (sessionId: string) => Promise<SessionInfo>; | ||
@@ -99,2 +100,3 @@ selfTest: (sessionId: string) => Promise<SessionSelfTestResponse>; | ||
| create: (request: CreateWorkspaceRequest) => Promise<WorkspaceInfo>; | ||
| importFromGithub: (request: ImportWorkspaceRequest) => Promise<ImportWorkspaceResponse>; | ||
| rename: (workspace: string, name?: string | null) => Promise<WorkspaceNameResponse>; | ||
@@ -117,2 +119,5 @@ setTemplate: (workspace: string, template: boolean) => Promise<WorkspaceTemplateResponse>; | ||
| }; | ||
| readonly github: { | ||
| listRepositories: () => Promise<GithubRepositoriesResponse>; | ||
| }; | ||
| readonly browser: { | ||
@@ -161,2 +166,12 @@ version: (sessionId: string) => Promise<BrowserCdpVersionInfo>; | ||
| retry: (jobId: string) => Promise<JobInfo>; | ||
| waitForCompletion: (jobId: string, options?: WaitForJobOptions) => Promise<JobInfo>; | ||
| browserAction: (input: BrowserActionJobInput, options?: JobCreateOptions) => Promise<JobInfo>; | ||
| scrape: (input: BrowserScrapeJobInput, options?: JobCreateOptions) => Promise<JobInfo>; | ||
| exec: (input: SandboxExecRequest, options?: JobCreateOptions) => Promise<JobInfo>; | ||
| terminateSession: (input: SessionTerminateJobInput, options?: JobCreateOptions) => Promise<JobInfo>; | ||
| bulkTerminateSessions: (input: SessionBulkTerminateJobInput, options?: JobCreateOptions) => Promise<JobInfo>; | ||
| deleteWorkspace: (input: WorkspaceDeleteJobInput, options?: JobCreateOptions) => Promise<JobInfo>; | ||
| bulkDeleteWorkspaces: (input: WorkspaceBulkDeleteJobInput, options?: JobCreateOptions) => Promise<JobInfo>; | ||
| pipeline: (input: PipelineRunJobInput, options?: JobCreateOptions) => Promise<JobInfo>; | ||
| githubRunner: (input: GithubRunnerJobInput, options?: JobCreateOptions) => Promise<JobInfo>; | ||
| }; | ||
@@ -163,0 +178,0 @@ private buildUrl; |
+109
-1
@@ -8,2 +8,3 @@ import { CdpClient } from './cdp.js'; | ||
| const TERMINAL_SESSION_STATUSES = new Set(['terminated', 'failed']); | ||
| const TERMINAL_JOB_STATUSES = new Set(['completed', 'failed', 'canceled']); | ||
| const RUNNING_COMMAND_STATUSES = new Set(['running', 'queued', 'starting']); | ||
@@ -83,2 +84,14 @@ function trimTrailingSlash(value) { | ||
| } | ||
| function normalizeListSessionsResponse(response) { | ||
| if (Array.isArray(response)) { | ||
| return { | ||
| sessions: response, | ||
| total: response.length | ||
| }; | ||
| } | ||
| return response; | ||
| } | ||
| function asJsonValue(value) { | ||
| return value; | ||
| } | ||
| export class ChaserClient { | ||
@@ -209,4 +222,9 @@ baseUrl; | ||
| list: async () => { | ||
| return await this.requestJson('GET', '/v1/sessions'); | ||
| const response = await this.sessions.listPage(); | ||
| return response.sessions; | ||
| }, | ||
| listPage: async () => { | ||
| const response = await this.requestJson('GET', '/v1/sessions'); | ||
| return normalizeListSessionsResponse(response); | ||
| }, | ||
| get: async (sessionId) => { | ||
@@ -346,2 +364,7 @@ return await this.requestJson('GET', `/v1/sessions/${encodeSegment(sessionId)}`); | ||
| }, | ||
| importFromGithub: async (request) => { | ||
| return await this.requestJson('POST', '/v1/workspaces/import', { | ||
| body: request | ||
| }); | ||
| }, | ||
| rename: async (workspace, name) => { | ||
@@ -378,2 +401,7 @@ return await this.requestJson('PUT', `/v1/workspaces/${encodeSegment(workspace)}/name`, { body: { name: name ?? null } }); | ||
| }; | ||
| github = { | ||
| listRepositories: async () => { | ||
| return await this.requestJson('GET', '/v1/github/repositories'); | ||
| } | ||
| }; | ||
| browser = { | ||
@@ -482,2 +510,82 @@ version: async (sessionId) => { | ||
| return await this.requestJson('POST', `/v1/jobs/${encodeSegment(jobId)}/retry`); | ||
| }, | ||
| waitForCompletion: async (jobId, options = {}) => { | ||
| const timeoutMs = options.timeoutMs ?? DEFAULT_WAIT_TIMEOUT_MS; | ||
| const intervalMs = options.intervalMs ?? DEFAULT_WAIT_INTERVAL_MS; | ||
| const deadline = Date.now() + timeoutMs; | ||
| while (true) { | ||
| const job = await this.jobs.get(jobId); | ||
| const predicate = options.predicate ?? | ||
| ((candidate) => TERMINAL_JOB_STATUSES.has(candidate.status.toLowerCase())); | ||
| if (predicate(job)) { | ||
| return job; | ||
| } | ||
| if (Date.now() >= deadline) { | ||
| throw new ChaserTimeoutError(`Timed out waiting for job ${jobId} to finish`); | ||
| } | ||
| await sleep(intervalMs, options.signal); | ||
| } | ||
| }, | ||
| browserAction: async (input, options = {}) => { | ||
| return await this.jobs.create({ | ||
| kind: 'browser.action', | ||
| input: asJsonValue(input), | ||
| ...options | ||
| }); | ||
| }, | ||
| scrape: async (input, options = {}) => { | ||
| return await this.jobs.create({ | ||
| kind: 'browser.scrape', | ||
| input: asJsonValue(input), | ||
| ...options | ||
| }); | ||
| }, | ||
| exec: async (input, options = {}) => { | ||
| return await this.jobs.create({ | ||
| kind: 'sandbox.exec', | ||
| input: asJsonValue(input), | ||
| ...options | ||
| }); | ||
| }, | ||
| terminateSession: async (input, options = {}) => { | ||
| return await this.jobs.create({ | ||
| kind: 'session.terminate', | ||
| input: asJsonValue(input), | ||
| ...options | ||
| }); | ||
| }, | ||
| bulkTerminateSessions: async (input, options = {}) => { | ||
| return await this.jobs.create({ | ||
| kind: 'session.bulk_terminate', | ||
| input: asJsonValue(input), | ||
| ...options | ||
| }); | ||
| }, | ||
| deleteWorkspace: async (input, options = {}) => { | ||
| return await this.jobs.create({ | ||
| kind: 'workspace.delete', | ||
| input: asJsonValue(input), | ||
| ...options | ||
| }); | ||
| }, | ||
| bulkDeleteWorkspaces: async (input, options = {}) => { | ||
| return await this.jobs.create({ | ||
| kind: 'workspace.bulk_delete', | ||
| input: asJsonValue(input), | ||
| ...options | ||
| }); | ||
| }, | ||
| pipeline: async (input, options = {}) => { | ||
| return await this.jobs.create({ | ||
| kind: 'pipeline.run', | ||
| input: asJsonValue(input), | ||
| ...options | ||
| }); | ||
| }, | ||
| githubRunner: async (input, options = {}) => { | ||
| return await this.jobs.create({ | ||
| kind: 'github.runner', | ||
| input: asJsonValue(input), | ||
| ...options | ||
| }); | ||
| } | ||
@@ -484,0 +592,0 @@ }; |
+107
-13
@@ -15,14 +15,24 @@ export type SessionType = 'browser' | 'sandbox'; | ||
| control: string; | ||
| video?: string; | ||
| video?: string | null; | ||
| } | ||
| export interface SessionInfo { | ||
| id: string; | ||
| workspace_id?: string; | ||
| workspace_id?: string | null; | ||
| created_at: string; | ||
| status: SessionStatus; | ||
| session_type: SessionType | string; | ||
| active_connection_leases?: number; | ||
| active_connection_leases?: number | null; | ||
| endpoints: Endpoints; | ||
| persistence?: boolean; | ||
| persistence?: boolean | null; | ||
| } | ||
| export interface ListSessionsResponse { | ||
| sessions: SessionInfo[]; | ||
| total: number; | ||
| } | ||
| export interface SessionCreateRequestBase { | ||
| proxy?: string; | ||
| network?: NetworkConfig; | ||
| github_repo?: string | null; | ||
| env?: Record<string, string>; | ||
| } | ||
| export interface BrowserCdpVersionInfo { | ||
@@ -55,21 +65,15 @@ Browser?: string; | ||
| } | ||
| export interface PersistentSessionCreateRequest { | ||
| export interface PersistentSessionCreateRequest extends SessionCreateRequestBase { | ||
| workspace: string; | ||
| session_type?: SessionType; | ||
| proxy?: string; | ||
| network?: NetworkConfig; | ||
| ephemeral?: false; | ||
| } | ||
| export interface BrowserEphemeralSessionCreateRequest { | ||
| export interface BrowserEphemeralSessionCreateRequest extends SessionCreateRequestBase { | ||
| ephemeral: true; | ||
| session_type?: 'browser'; | ||
| proxy?: string; | ||
| network?: NetworkConfig; | ||
| } | ||
| export interface SandboxEphemeralSessionCreateRequest { | ||
| export interface SandboxEphemeralSessionCreateRequest extends SessionCreateRequestBase { | ||
| ephemeral: true; | ||
| session_type: 'sandbox'; | ||
| image?: string; | ||
| proxy?: string; | ||
| network?: NetworkConfig; | ||
| } | ||
@@ -227,2 +231,3 @@ export type CreateSessionRequest = PersistentSessionCreateRequest | BrowserEphemeralSessionCreateRequest | SandboxEphemeralSessionCreateRequest; | ||
| source_workspace_id?: string; | ||
| github_repo?: string; | ||
| assistant_home?: boolean; | ||
@@ -249,2 +254,30 @@ last_session_id?: string; | ||
| export type CreateWorkspaceRequest = FreshWorkspaceCreateRequest | CloneWorkspaceCreateRequest; | ||
| export interface GithubRepoInfo { | ||
| name: string; | ||
| installation_id: number; | ||
| account_login: string; | ||
| } | ||
| export interface GithubRepositoriesResponse { | ||
| repositories: GithubRepoInfo[]; | ||
| install_url?: string | null; | ||
| } | ||
| export interface ImportWorkspaceRequest { | ||
| repo: string; | ||
| name?: string | null; | ||
| } | ||
| export interface DevcontainerBootstrap { | ||
| path: string; | ||
| image?: string | null; | ||
| dockerfile?: string | null; | ||
| workspace_folder?: string | null; | ||
| post_create_command?: string | null; | ||
| forward_ports?: number[]; | ||
| } | ||
| export interface ImportWorkspaceResponse { | ||
| workspace: WorkspaceInfo; | ||
| github_repo: string; | ||
| private: boolean; | ||
| default_branch?: string | null; | ||
| devcontainer?: DevcontainerBootstrap | null; | ||
| } | ||
| export interface WorkspaceNameResponse { | ||
@@ -497,2 +530,57 @@ id: string; | ||
| } | ||
| export interface BrowserActionJobInput { | ||
| session_id: string; | ||
| steps: JsonValue[]; | ||
| timeout_ms?: number; | ||
| } | ||
| export interface BrowserScrapeJobInput { | ||
| session_id: string; | ||
| url: string; | ||
| selector?: string; | ||
| all?: boolean; | ||
| timeout_ms?: number; | ||
| } | ||
| export interface SessionTerminateJobInput { | ||
| session_id: string; | ||
| force?: boolean; | ||
| } | ||
| export interface SessionBulkTerminateJobInput { | ||
| ids?: string[]; | ||
| workspaces?: string[]; | ||
| all?: boolean; | ||
| session_type?: SessionType; | ||
| force?: boolean; | ||
| } | ||
| export interface WorkspaceDeleteJobInput { | ||
| workspace: string; | ||
| force?: boolean; | ||
| } | ||
| export interface WorkspaceBulkDeleteJobInput { | ||
| ids?: string[]; | ||
| all?: boolean; | ||
| force?: boolean; | ||
| } | ||
| export interface PipelineStepInput { | ||
| name?: string; | ||
| kind?: string; | ||
| input?: JsonValue; | ||
| command?: string; | ||
| timeout_ms?: number; | ||
| } | ||
| export interface PipelineRunJobInput { | ||
| workspace?: string; | ||
| steps: PipelineStepInput[]; | ||
| } | ||
| export interface GithubRunnerJobInput { | ||
| repo: string; | ||
| installation_id: number; | ||
| workflow_job_id: number; | ||
| run_id?: number; | ||
| labels: string[]; | ||
| timeout_ms?: number; | ||
| } | ||
| export interface JobCreateOptions { | ||
| run_at?: string; | ||
| idempotency_key?: string; | ||
| } | ||
| export interface JobKindSpecInfo { | ||
@@ -520,2 +608,8 @@ kind: string; | ||
| } | ||
| export interface WaitForJobOptions { | ||
| timeoutMs?: number; | ||
| intervalMs?: number; | ||
| signal?: AbortSignal; | ||
| predicate?: (job: JobInfo) => boolean; | ||
| } | ||
| export interface CdpConnectOptions { | ||
@@ -522,0 +616,0 @@ waitUntilReady?: boolean; |
+1
-1
| { | ||
| "name": "chaser-sdk", | ||
| "version": "0.1.3", | ||
| "version": "0.1.4", | ||
| "description": "Official TypeScript SDK for the Chaser", | ||
@@ -5,0 +5,0 @@ "type": "module", |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
63287
14.23%1657
15.15%