/** * Capability discovery — runtime detection of which WIP domains the * connected WebKit build actually supports. * * Motivated by iOS WKWebView (tested on iOS 26.5.0) hanging on `CSS.*` * (TIMEOUT, not -32601 NOT_FOUND). The WIP protocol declares CSS as always * available, but iOS WebKit runtime does not respond to CSS domain calls. * spec: docs/spec.md §"Capability discovery architecture". * * Strategy: * 1. Try `Schema.getDomains` first — canonical Apple WIP discovery method. * 2. If that fails (-32601), probe a curated CSS sentinel (CSS.enable with * a short timeout) — TIMEOUT means the fork omitted the domain even if * it would respond -32601 to other calls. * * The probe runs async after page attach so tool calls are not blocked. Tool * handlers may consult `PageSession.capability()` to fail-fast with a * structured `WipError` instead of waiting for a 15s timeout. */ import type { WipSession } from './wip-client/ws-session.js'; export type WipErrorCode = 'DOMAIN_UNAVAILABLE' | 'METHOD_NOT_FOUND' | 'INVALID_PARAMS' | 'TIMEOUT' | 'TRANSPORT_ERROR' | 'INTERNAL'; export declare class WipError extends Error { readonly code: WipErrorCode; readonly domain?: string; readonly rawCode?: number; readonly fallback?: string; constructor(code: WipErrorCode, message: string, opts?: { domain?: string; rawCode?: number; fallback?: string; }); toStructured(): Record; } /** * Map a raw WIP error response (or thrown Error) to a WipError with code. * `code === -32601` → METHOD_NOT_FOUND (or DOMAIN_UNAVAILABLE if message * contains "domain was not found"). `-32602` → INVALID_PARAMS. Plain timeout * messages from `WipSession.send` → TIMEOUT. */ export declare function classifyWipError(err: unknown, method: string): WipError; export interface CapabilitySnapshot { /** ISO timestamp of probe completion. */ probedAt: string; /** ms it took to complete all probes. */ probeDurationMs: number; /** Domains reported by Schema.getDomains, lowercased to set membership. undefined if Schema unavailable. */ supportedDomains?: Set; /** True iff Schema.getDomains succeeded. False if probe fell back to sentinels. */ schemaProbeSucceeded: boolean; /** Curated sentinel results: domain → 'ok' | 'timeout' | 'not-found' | 'invalid-params'. */ sentinels: Record; /** Free-form notes (e.g. "CSS.enable hung after 3s — iOS WKWebView runtime no-op on CSS domain"). */ notes: string[]; } export declare function probeCapabilities(session: WipSession): Promise; /** * Convenience: throw a structured WipError if the snapshot tells us the * required domain is unavailable. No-op if `supportedDomains` is undefined * (Schema probe failed → assume optimistic). */ export declare function assertDomainAvailable(snap: CapabilitySnapshot | undefined, domain: string): void;