UNPKG

plato-sdk

Version:

JavaScript client for interacting with the Plato API

117 lines (116 loc) 4.44 kB
import { z } from 'zod'; export declare const PlatoTaskSchema: z.ZodObject<{ name: z.ZodString; prompt: z.ZodString; start_url: z.ZodString; }, "strip", z.ZodTypeAny, { name: string; prompt: string; start_url: string; }, { name: string; prompt: string; start_url: string; }>; export type PlatoTask = z.infer<typeof PlatoTaskSchema>; export interface WorkerReadyResponse { ready: boolean; worker_public_ip?: string; worker_ip?: string; worker_port?: number; health_status?: Record<string, any>; error?: string; } export declare class PlatoEnvironment { private client; id: string; alias: string | null; fast: boolean; private heartbeatInterval; private heartbeatIntervalMs; private runSessionId; constructor(client: Plato, id: string, alias?: string, fast?: boolean); getStatus(): Promise<any>; getCdpUrl(): Promise<string>; close(): Promise<any>; evaluate(): Promise<any>; /** * Resets the environment with a new task * @param task The task to run in the environment, or a simplified object with just name, prompt, and start_url * @param testCasePublicId The public ID of the test case * @param loadAuthenticated Whether to load authenticated browser state * @returns The response from the server */ reset(task?: PlatoTask | { name: string; prompt: string; start_url: string; }, testCasePublicId?: string, loadAuthenticated?: boolean): Promise<string | null>; getState(): Promise<any>; getLiveViewUrl(): Promise<string>; backup(): Promise<any>; /** * Starts the heartbeat interval to keep the environment alive * @private */ private startHeartbeat; /** * Stops the heartbeat interval * @private */ private stopHeartbeat; waitForReady(timeout?: number): Promise<void>; /** * Get the public URL for accessing this environment. * * @returns The public URL for this environment based on the deployment environment. * Uses alias if available, otherwise uses environment ID. * - Dev: https://{alias|env.id}.dev.sims.plato.so * - Staging: https://{alias|env.id}.staging.sims.plato.so * - Production: https://{alias|env.id}.sims.plato.so * - Local: http://localhost:8081/{alias|env.id} * @throws PlatoClientError If unable to determine the environment type. */ getPublicUrl(): string; } export declare class Plato { private apiKey; baseUrl: string; private http; constructor(apiKey: string, baseUrl?: string); /** * Create a new Plato environment for the given environment ID. * * @param envId The environment ID to create * @param openPageOnStart Whether to open the page on start * @param recordActions Whether to record actions * @param keepalive If true, jobs will not be killed due to heartbeat failures * @param alias Optional alias for the job group * @param fast Fast mode flag * @returns The created environment instance * @throws PlatoClientError If the API request fails */ makeEnvironment(envId: string, openPageOnStart?: boolean, recordActions?: boolean, keepalive?: boolean, alias?: string, fast?: boolean): Promise<PlatoEnvironment>; getJobStatus(jobId: string): Promise<any>; getCdpUrl(jobId: string): Promise<string>; closeEnvironment(jobId: string): Promise<any>; evaluate(sessionId: string): Promise<any>; /** * Resets an environment with a new task * @param jobId The ID of the job to reset * @param task The task to run in the environment, or a simplified object with just name, prompt, and start_url * @param testCasePublicId The public ID of the test case * @param loadAuthenticated Whether to load authenticated browser state * @returns The response from the server */ resetEnvironment(jobId: string, task?: PlatoTask | { name: string; prompt: string; start_url: string; }, testCasePublicId?: string, loadAuthenticated?: boolean): Promise<any>; getEnvironmentState(jobId: string): Promise<any>; getWorkerReady(jobId: string): Promise<WorkerReadyResponse>; getLiveViewUrl(jobId: string): Promise<string>; sendHeartbeat(jobId: string): Promise<any>; backupEnvironment(jobId: string): Promise<any>; }