import type { BunFile } from "bun"; import type { ElementHandle, Page } from "puppeteer-core"; declare module "puppeteer-core" { interface Frame { /** The frame's isolated world, where a page's replaced globals never reach (`@internal` upstream). */ isolatedRealm(): Realm; } } /** What a browser's own pick reports for a file. */ export interface UploadFileInfo { name: string; /** Bare MIME type, empty when the extension names none. */ type: string; lastModified: number; } /** A file to hand a page, its contents base64-encoded. */ export interface FilePayload extends UploadFileInfo { data: string; } /** A file to upload, opened for reading in slices. */ export interface UploadSource { path: string; file: BunFile; size: number; /** A folder, which only a browser reading its path can expand (for a `webkitdirectory` input). */ directory: boolean; /** * The file's identity and last change (inode, size, mtime, ctime). A rewrite that keeps size and mtime (a coarse * clock, a build step restoring timestamps) still moves ctime, and a replace by rename changes the inode. */ revision: string; info: UploadFileInfo; } /** * How a browser gets uploaded files: `paths` of staged copies it reads itself, or `contents` omp reads and streams in, * for a browser that may not open omp's files (a relay without file-URL access, a Chrome on another machine). */ export type UploadRoute = "paths" | "contents"; /** Open a file for upload; rejects when it cannot be read. */ export declare function openUploadSource(absolute: string): Promise; /** Open every file of one upload, in order. */ export declare function openUploadSources(absolutePaths: string[], signal?: AbortSignal): Promise; /** Reject folders for a browser that only takes file contents: only a browser reading a path expands a folder. */ export declare function refuseFolders(sources: UploadSource[]): void; /** Read whole files into payloads for one call into the page. */ export declare function readFilePayloads(absolutePaths: string[], signal?: AbortSignal): Promise; /** * Set a file input's files to `paths` through `DOM.setFileInputFiles`; the browser reads them itself. Raw CDP rather than * `ElementHandle.uploadFile`, which an actionable handle routes back through the upload helpers. */ export declare function setFileInputPaths(input: ElementHandle, paths: string[]): Promise; /** A detached file input's page side; this package type-checks without the DOM lib. */ interface PagePicker { type: string; multiple: boolean; readonly files: ArrayLike<{ text(): Promise; }> | null; } /** Create a detached ``. Runs in the page, in the isolated world. */ export declare function createFilePicker(): PagePicker; /** A picker's files, as an array. Runs in the page. */ export declare function pickedFiles(picker: PagePicker): unknown[]; /** The staging folder path for a new tab; it is created on the tab's first upload. */ export declare function newUploadStagingDir(): string; /** Remove a tab's staging folder, once the page that may read its copies is gone. */ export declare function removeUploadStaging(directory: string): Promise; /** * Remove staging folders a day after their last upload once no open tab of this process owns them and the omp * process that made them is this one or gone. Another running omp sweeps its own. */ export declare function sweepUploadStaging(live: ReadonlySet, now?: number): Promise; /** * One tab worker's uploads: the route a one-time check picked for its browser connection, and the tab's staging * folder, which outlives the worker (a recycle or a relay release starts a new one on the same page) and is removed by * the supervisor, since Chrome reads a picked file lazily. */ export declare class UploadStaging { #private; constructor(directory: string); /** * The route for this connection: the browser gets a token file's path through `DOM.setFileInputFiles` on a detached * input and must read it back. A read of the token means paths and `Not allowed` means contents, both kept for the * connection. Anything else (a late or failed read, a navigation, a busy page) decides nothing: this upload gets * contents, which any browser takes, and the next one checks again. */ route(page: Page, signal?: AbortSignal): Promise; /** * Copy files or folders into the staging directory, keeping names and mtimes, and return the copies' paths. Links * are followed: a copy that pointed back at the original would send the browser to it again. */ stage(sources: UploadSource[], signal?: AbortSignal): Promise; } export {};