import { BrowserConfig, BrowserTaskInput, BrowserTaskResult, BrowserTaskWithPromise, BrowserTaskInputWithSchema, BrowserTaskWithPromiseAndSchema, RecordingWithMethods, ErrorsResponse, WebpOptions, WebpResponse } from './types.js'; import { ProfilesClient } from './profiles/core.js'; import { MorphAPIClient } from '../../core/client.js'; import { APIResource } from '../../core/resource.js'; import '../utils/resilience.js'; import './profiles/types.js'; /** * Core implementation for browser automation tasks */ /** * BrowserClient class for easier usage with instance configuration * * @deprecated Prefer the unified `MorphClient` (`new MorphClient({ apiKey }).browser`). * Standalone clients remain only for backwards compatibility and may be removed in a future * major version — do not use them in new code. */ declare class BrowserClient extends APIResource { private config; /** * Profile management - create and manage browser profiles for storing login state. */ profiles: ProfilesClient; constructor(clientOrConfig?: MorphAPIClient | BrowserConfig); /** * Execute a browser automation task */ execute(input: BrowserTaskInput): Promise; createTask(input: BrowserTaskInput): Promise; createTask(input: BrowserTaskInputWithSchema): Promise>; /** * Execute task with recording and wait for video to be ready */ executeWithRecording(input: BrowserTaskInput & { recordVideo: true; }): Promise; /** * Get recording status and URLs */ getRecording(recordingId: string): Promise; /** * Wait for recording to complete with automatic polling */ waitForRecording(recordingId: string, options?: { timeout?: number; pollInterval?: number; }): Promise; /** * Get errors from recording with screenshots */ getErrors(recordingId: string): Promise; /** * Get animated WebP preview of recording */ getWebp(recordingId: string, options?: WebpOptions): Promise; /** * Check if browser worker service is healthy */ checkHealth(): Promise<{ ok: boolean; google_configured: boolean; database_configured: boolean; s3_configured: boolean; error?: string; }>; } /** * Execute a natural language browser automation task * * Returns the full task result including rich agent history data (urls, errors, * action_history, judgement, etc.). When using this as an agent tool, use the * formatResult() functions from the SDK adapters to return a concise summary. * * @param input - Task parameters * @param config - Optional configuration (apiKey, apiUrl to override default) * @returns Task result with success status, findings, and comprehensive execution history * * @example * ```typescript * const result = await executeBrowserTask( * { * task: "Test checkout flow for buying a pineapple", * url: "https://3000-abc.e2b.dev", * maxSteps: 20, * repoId: "my-project", * commitId: "uuid-here" * }, * { * apiKey: process.env.MORPH_API_KEY, * // apiUrl: 'http://localhost:8001' // Override for local testing * } * ); * * if (result.success) { * console.log('Task completed:', result.result); * console.log('URLs visited:', result.urls); * console.log('Actions taken:', result.actionNames); * console.log('Has errors:', result.hasErrors); * console.log('Replay:', result.replayUrl); * } * ``` */ declare function executeBrowserTask(input: BrowserTaskInput, config?: BrowserConfig): Promise; /** * Get recording status and video URL * * @param recordingId - Recording UUID from BrowserTaskResult * @param config - Configuration with apiKey * @returns Recording with convenience methods (.getWebp(), .getErrors()) * * @example * ```typescript * const recording = await getRecording('uuid-here', { apiKey: 'key' }); * * // Get animated WebP * const { webpUrl } = await recording.getWebp({ width: 780 }); * * // Get errors with screenshots * const { errors } = await recording.getErrors(); * ``` */ declare function getRecording(recordingId: string, config?: BrowserConfig): Promise; /** * Wait for recording to complete with automatic polling * * @param recordingId - Recording UUID * @param config - Configuration with apiKey * @param options - Polling options * @returns Recording status when completed or errored * * @example * ```typescript * const result = await executeBrowserTask({ task: '...', recordVideo: true }, config); * if (result.recordingId) { * const recording = await waitForRecording(result.recordingId, config, { * timeout: 60000, // 1 minute * pollInterval: 2000 // Check every 2 seconds * }); * console.log('Video URL:', recording.videoUrl); * } * ``` */ declare function waitForRecording(recordingId: string, config?: BrowserConfig, options?: { timeout?: number; pollInterval?: number; }): Promise; /** * Execute task with recording and wait for video to be ready * * @param input - Task parameters with recordVideo=true * @param config - Configuration with apiKey * @returns Task result with ready video URL * * @example * ```typescript * const result = await executeWithRecording( * { * task: "Test checkout flow", * url: "https://example.com", * recordVideo: true, * repoId: "my-project" * }, * { apiKey: process.env.MORPH_API_KEY } * ); * * console.log('Task result:', result.result); * console.log('Video URL:', result.recording?.videoUrl); * ``` */ declare function executeWithRecording(input: BrowserTaskInput & { recordVideo: true; }, config?: BrowserConfig): Promise; /** * Get errors from recording with screenshots * * Screenshots are captured in real-time (500ms after error occurs) during the browser session. * * @param recordingId - Recording UUID from BrowserTaskResult * @param config - Configuration with apiKey * @returns Errors with real-time screenshots * * @example * ```typescript * const { errors, totalErrors } = await getErrors('uuid-here', { apiKey: 'key' }); * * console.log(`Found ${totalErrors} errors`); * * errors.forEach(err => { * console.log(`[${err.type}] ${err.message}`); * if (err.url) console.log(` URL: ${err.url}`); * if (err.screenshotUrl) console.log(` Screenshot: ${err.screenshotUrl}`); * * // Download screenshot * if (err.screenshotUrl) { * const response = await fetch(err.screenshotUrl); * const screenshot = await response.arrayBuffer(); * // Save or process screenshot * } * }); * ``` */ declare function getErrors(recordingId: string, config?: BrowserConfig): Promise; /** * Get animated WebP preview of recording * * Converts the native video recording to an animated WebP. Results are cached in S3. * * @param recordingId - Recording UUID from BrowserTaskResult * @param config - Configuration with apiKey * @param options - WebP generation options * @returns WebP URL and metadata * * @example * ```typescript * const webp = await getWebp('uuid-here', { apiKey: 'key' }, { * width: 780, * fps: 10, * quality: 65, * maxDuration: 15 * }); * console.log('WebP URL:', webp.webpUrl); * console.log('From cache:', webp.cached); * ``` */ declare function getWebp(recordingId: string, config?: BrowserConfig, options?: WebpOptions): Promise; /** * Check if browser worker service is healthy * * @param config - Optional configuration * @returns Health status */ declare function checkHealth(config?: BrowserConfig): Promise<{ ok: boolean; google_configured: boolean; database_configured: boolean; s3_configured: boolean; error?: string; }>; export { BrowserClient, checkHealth, executeBrowserTask, executeWithRecording, getErrors, getRecording, getWebp, waitForRecording };