import { BrowserContext, Page } from "playwright-core";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";

//#region packages/browser/src/types.d.ts
type BrowserMode = 'ui' | 'headless';
interface BrowserConfig {
  defaultMode: BrowserMode;
  browsersPath: string | null;
  userDataDirRoot: string | null;
  idleShutdownMinutes: number;
  allowInternalSchemes: boolean;
  allowLoopback?: boolean;
  evalTimeoutMs: number;
  evalMaxResultBytes: number;
  redactPasswordFieldsInScreenshots: boolean;
}
declare const DEFAULT_BROWSER_CONFIG: BrowserConfig;
interface PageInfo {
  pageId: string;
  url: string;
  title: string;
  label?: string;
  createdAt: Date;
}
interface SecurityCheckResult {
  allowed: boolean;
  reason?: string;
}
interface EvalValidationResult {
  valid: boolean;
  result?: string;
  truncated?: boolean;
  reason?: string;
}
//#endregion
//#region packages/browser/src/session.d.ts
declare class SessionRegistry {
  private pages;
  registerPage(page: Page, url: string, title: string, label?: string): string;
  getPageByLabel(label: string): Page;
  resolvePageId(pageIdOrLabel: string): string;
  getPage(pageId: string): Page;
  getPageInfo(pageId: string): PageInfo;
  setSnapshot(pageId: string, snapshot: string): void;
  getSnapshot(pageId: string): string | undefined;
  updatePageInfo(pageId: string, url: string, title: string): void;
  removePage(pageId: string): Promise<void>;
  listPages(): PageInfo[];
  closeAll(): Promise<void>;
  get size(): number;
}
//#endregion
//#region packages/browser/src/engine.d.ts
declare class BrowserEngine {
  private browser;
  private context;
  private idleTimer;
  private launchPromise;
  private currentMode;
  readonly session: SessionRegistry;
  private config;
  constructor(config?: Partial<BrowserConfig>);
  launch(mode?: BrowserMode, onProgress?: (msg: string) => void): Promise<void>;
  private doLaunch;
  private stopIdleTimer;
  resetIdleTimer(): void;
  close(): Promise<void>;
  getContext(): BrowserContext;
  getConfig(): BrowserConfig;
  isLaunched(): boolean;
}
declare function getEngine(config?: Partial<BrowserConfig>): BrowserEngine;
declare function closeEngine(): Promise<void>;
//#endregion
//#region packages/browser/src/install.d.ts
declare function getDefaultBrowsersPath(): string;
declare function resolveBrowsersPath(config: BrowserConfig): string;
declare function isBrowserInstalled(browsersPath: string): boolean;
declare function ensureBrowserInstalled(config: BrowserConfig, onProgress?: (msg: string) => void): Promise<string>;
//#endregion
//#region packages/browser/src/modes.d.ts
interface LaunchArgs {
  headless: boolean;
  args: string[];
}
declare function detectDisplayAvailable(): boolean;
declare function autoSelectMode(requested: BrowserMode): BrowserMode;
declare function getLaunchArgs(mode: BrowserMode): LaunchArgs;
//#endregion
//#region packages/browser/src/security.d.ts
declare function isUrlAllowed(url: string, config: BrowserConfig): SecurityCheckResult;
declare function isCookieAccessAllowed(confirm: boolean): SecurityCheckResult;
declare function validateEvalResult(result: unknown, maxBytes: number): EvalValidationResult;
declare function redactPasswordFields(html: string): string;
//#endregion
//#region packages/browser/src/tools/index.d.ts
declare function registerBrowserTools(server: McpServer, config: Record<string, unknown>): void;
//#endregion
export { BrowserConfig, BrowserEngine, BrowserMode, DEFAULT_BROWSER_CONFIG, EvalValidationResult, LaunchArgs, PageInfo, SecurityCheckResult, SessionRegistry, autoSelectMode, closeEngine, detectDisplayAvailable, ensureBrowserInstalled, getDefaultBrowsersPath, getEngine, getLaunchArgs, isBrowserInstalled, isCookieAccessAllowed, isUrlAllowed, redactPasswordFields, registerBrowserTools, resolveBrowsersPath, validateEvalResult };