import type { SessionContext } from "../session-types.js"; import { type DetectOptions } from "./dev-url.js"; import { type Device, type DeviceDriver, type DeviceTools } from "./devices.js"; import { type Spawner } from "./refresh.js"; import type { LivePreviewStatus } from "@kenkaiiii/gg-protocol"; export type { LivePreviewStatus }; export interface LivePreviewManagerDeps { /** Create (and register) a session in `cwd` that the app never shows as a window. */ createSession: (cwd: string) => Promise; closeSession: (id: string) => Promise; usage: (provider: "anthropic" | "moonshot") => Promise; /** The built overlay; null when this build doesn't have it. */ assetsDir: string | null; /** Finds servers the user started in the project, and checks what answers (servers.ts). */ scan?: DetectOptions["scan"]; probe?: DetectOptions["probe"]; log?: (message: string, fields?: Record) => void; /** A window's preview started or stopped (by the user or by the agent). */ onChange?: (windowId: string, status: LivePreviewStatus) => void; /** How long a tab's session outlives its last connection (a reload reconnects well within it). */ tabIdleMs?: number; /** Whether the dev server still accepts connections; a quick TCP connect by default. */ isUp?: (target: URL) => Promise; /** How long edits stay quiet before they count as one change. */ settleMs?: number; /** How long after a change to check the dev server still answers. */ downCheckMs?: number; /** Simulator and emulator tools (devices.ts by default). */ devices?: { detect: () => Promise; list: (tools: DeviceTools) => Promise; driver: (device: Device, tools: DeviceTools) => DeviceDriver; }; /** Runs rebuild and re-run commands (a shell by default). */ spawn?: Spawner; } /** Where the built overlay is, or null when it was never built. */ export declare function findLivePreviewAssets(candidates?: readonly string[]): string | null; /** A user-typed dev server address as a URL, or an error to show. */ export declare function parseDevUrl(raw: string): URL | { error: string; }; /** Whether something accepts connections at the dev server's address. */ export declare function tcpAnswers(target: URL, timeoutMs?: number): Promise; /** * The folders to serve, inside the project, in lookup order; or why not. * Paths may be relative to the project. */ export declare function resolveServeDirs(cwd: string, serve: readonly string[]): string[] | { error: string; }; /** * A phone, native or command-line app: show the simulator or emulator * (`device`), run `rebuild` after changes (native apps), or re-run `run` and * show its output (command-line apps). */ export interface AppMode { device?: boolean; rebuild?: string; run?: string; } export declare const COMMAND_MAX_CHARS = 2000; /** The app mode a start asks for, null for none, or why it can't be. */ export declare function appModeOf(opts: LivePreviewStartOptions): AppMode | null | { error: string; }; /** What's missing to show a phone app, said plainly; null when the tools are there. */ export declare function missingToolsNote(tools: DeviceTools, platform?: NodeJS.Platform): string | null; export interface LivePreviewStartOptions { url?: string; /** Serve these project folders directly instead of a dev server. */ serve?: string[]; /** Show the running iOS Simulator or Android emulator. */ device?: boolean; /** Rebuilds (and relaunches) a native app; run after each change. */ rebuild?: string; /** A command-line app: run now and after each change, its output shown. */ run?: string; /** * True from the window's own preview panel: no spare session is made (the * browser chat makes its sessions when a tab opens), and starts that follow * (the agent's) open nothing in the browser. False from the browser path. */ inApp?: boolean; } export interface LivePreviewManager { start: (window: SessionContext, opts?: LivePreviewStartOptions) => Promise; stop: (windowId: string) => Promise; status: (windowId: string) => LivePreviewStatus; /** The status, plus whether the dev server still answers while the preview runs. */ check: (windowId: string) => Promise; /** A session went away: stop the preview it owned or was. */ onSessionClosed: (id: string) => Promise; isPreviewSession: (id: string) => boolean; stopAll: () => Promise; } export declare function createLivePreviewManager(deps: LivePreviewManagerDeps): LivePreviewManager;