import type { BrowserContext } from 'playwright'; import { type FittedRow, type PreviewAddOn } from '../vehicle/previewAddon'; import { type SeatReport } from '../vehicle/previewSeats'; export type Json = Record; export interface PreviewGlb { file: string; sha256: string; bytes: number; } export interface PreviewCandidate { /** The vehicle package exactly as the author wrote it (audio rows backed by a local WAV get a served URL). */ pkg: Json; glb: PreviewGlb; /** * Local WAVs the package plays, by sha256. An unpublished package authors its audio rows as `{ name, file }`; the * engine refuses a row without url/checksum/bytes and then never spawns the car, so each row is given a * content-addressed URL on PREVIEW_AUDIO_ORIGIN and the browser is served the bytes from disk. */ audio?: PreviewGlb[]; /** * Unpublished add-ons to fit to the car (`helix vehicle preview --addon`): the session's `composition` is rebuilt to carry them, * and each one's GLB is served from disk. */ addOns?: PreviewAddOn[]; /** * Fit the add-ons to the PUBLISHED car the session names, leaving its package and model alone (`--item`): `pkg` and `glb` are * placeholders and are never read. */ keepCar?: boolean; /** `seat_*` node names of the candidate GLB (its physical seats), for the seat bridge. */ seatNodes?: string[]; } /** Host of the content URLs local audio rows are given; every request to it is fulfilled from disk, never sent. */ export declare const PREVIEW_AUDIO_ORIGIN = "https://candidate-audio.preview.invalid"; /** Content-addressed URL of the candidate GLB on the proxy's own CDN origin. */ export declare function candidateModelUrl(cdnOrigin: string, sha256: string): string; export declare function sha256Hex(bytes: Uint8Array): string; /** sha256 of the package's canonical JSON bytes: the identity checksum the backend pins and the engine reads. */ export declare function packageChecksum(pkg: Json): string; /** * The package as the runtime receives it for a published car: `mesh` pinned to the universal item (what `item publish` * does to a v2 package), and the web rendition pointed at the candidate GLB, so the engine fetches those bytes and * verifies them against the checksum it is given. A package with no `mesh.visual.renditions` is left without one: the * runtime then draws the session's `modelUrl`, which is rewritten to the candidate as well. */ export declare function servedPackage(pkg: Json, o: { proxyItemId: string; modelUrl: string; glb: PreviewGlb; }): Json; export interface SessionRewriteReport { rewritten: boolean; /** The proxy's model URLs that were replaced (so the harness can prove none of them was fetched afterwards). */ proxyModelUrls: string[]; /** The proxy's package checksum that was replaced. */ proxyChecksum: string | null; candidateChecksum: string | null; candidateModelUrl: string | null; stringsReplaced: number; /** The add-ons the rebuilt composition fits, with the slot each took (when `--addon` was given). */ addOns?: FittedRow[]; compositionDigest?: string; recipeDigest?: string; /** The candidate's seat vocabulary against the stand-in's, and the translation table the boarding bridge uses (candidate car only). */ seats?: SeatReport; } /** * Rewrite a Try Now session response so the runtime spawns the candidate. Mutates and returns `json`. A response that is * not a vehicle trial (no `spawnedItem.vehiclePackage`) is left untouched and reported as `rewritten: false`. */ export declare function rewriteTrialSession(json: unknown, cand: PreviewCandidate, proxyItemId: string): SessionRewriteReport; export interface PreviewRouteSink { /** How many times the browser fetched a candidate audio sample from disk. */ audioServed?: number; /** One entry per rewritten session response. */ sessions: SessionRewriteReport[]; /** Session responses for the proxy that could not be rewritten (with why). */ sessionMisses: string[]; /** How many times the browser fetched the candidate GLB from disk. */ glbServed: number; /** Every proxy model URL the browser fetched anyway (must stay empty: it would mean the proxy's car was drawn). */ proxyModelFetched: string[]; /** How many times the browser fetched each fitted add-on's GLB from disk, by the add-on's synthetic item id. */ addOnGlbServed: Record; } export declare function newPreviewSink(): PreviewRouteSink; /** * Install the two routes on a browser context. The session POST of the proxy item is fetched, rewritten, and fulfilled; * the candidate GLB's content URL is fulfilled from disk. Call BEFORE the page navigates. */ export declare function installVehiclePreviewRoutes(ctx: BrowserContext, cand: PreviewCandidate, proxyItemId: string, sink: PreviewRouteSink): Promise; /** Record fetches of the proxy's own model: a hit means the proxy car, not the candidate, was drawn. */ export declare function watchProxyModelFetches(ctx: BrowserContext, sink: PreviewRouteSink): void; /** * The room reserves a Try Now car's entity from the PROXY's package, and the engine refuses to draw a build whose digest * differs from the room's (`if (authorityBuild !== void 0 && authorityBuild !== requestedBuild) return;`), leaving the * car "still resolving" forever. A candidate necessarily differs, so the preview lifts that one gate in the runtime bundle * it serves to its own browser. Returns the patched source and whether the gate was found. */ export declare function liftAuthorityGate(source: string): { body: string; lifted: boolean; };