import http from "node:http";
/** A page error the page script saw: an uncaught error, or a hot-reload error overlay. */
export interface PageReport {
kind: "error" | "overlay";
message: string;
/** The page's path. */
page?: string;
}
export interface PreviewProxyOptions {
/** The dev server, e.g. http://localhost:5173/. Unused when `roots` is set. */
target: URL;
/** Tags added right after `
` of every HTML document. */
inject: string;
/** The page served when the dev server can't be reached. */
downPage: (target: URL) => string;
/** Serve these folders (looked up in order) instead of proxying a dev server. */
roots?: readonly string[];
onReport?: (report: PageReport) => void;
}
export interface HmrActivity {
/** Open websockets to the dev server (its hot-reload channel, usually). */
sockets: number;
/** When the dev server last sent bytes on any of them (epoch ms, 0 for never). */
lastBytesAt: number;
}
export interface PreviewProxy {
server: http.Server;
listen: (port: number) => Promise;
close: () => Promise;
/** Tell every open page to reload; returns how many were told. */
reload: () => number;
/** Pages listening on the reload channel. */
liveClients: () => number;
hmr: () => HmrActivity;
}
export declare const LIVE_PREFIX = "/__gg_live/";
export declare const REPORT_MAX_BYTES = 4096;
export declare const REPORT_MAX_CHARS = 300;
export declare const DOWN_HEADER = "x-gg-preview-down";
/** The proxy's own addresses: anything else is a DNS-rebinding attempt. */
export declare function allowedHosts(port: number): Set;
/** Redirects to the dev server's own address would leave the preview: send them back here. */
export declare function rewriteLocation(location: string, target: URL, proxyHost: string): string;
/** Remove `` tags from an HTML head. */
export declare function stripMetaCsp(html: string): string;
/**
* Where the page script goes in a buffered document start: after ``,
* else before ``, else after ``. Null for a fragment, which is
* left alone (htmx-style partials are HTML too).
*/
export declare function injectionPoint(text: string): number | null;
/** The page shown while the dev server is down. It still loads the overlay, so the user can ask GG to start it. */
export declare function defaultDownPage(target: URL, inject: string): string;
/**
* The file a URL path names inside the served folders, first match wins:
* the file itself, its `index.html`, or `.html`. Never leaves a root,
* and never serves dotfiles (`.env`) except under `.well-known`.
*/
export declare function resolveStatic(roots: readonly string[], urlPath: string): {
file: string;
} | {
redirect: string;
} | null;
/** Insert the page script into a whole HTML document (static mode). */
export declare function injectHtml(html: string, inject: string): string;
/** One line of untrusted page text, capped: it reaches the agent as information only. */
export declare function cleanReport(raw: unknown): PageReport | null;
export declare function createPreviewProxy(opts: PreviewProxyOptions): PreviewProxy;