import type { MissCode } from "./contract.js"; import type { Fragment, PageSpan, Region } from "./fragments.js"; import type { Kind } from "./kinds.js"; import type { Limits } from "./limits.js"; /** What is known of a source for free: no render, no decode beyond a header. */ export type SourceFacts = { readonly kind: Kind; readonly bytes: number; readonly sha256: string; readonly mimeType?: string; /** Pixels of an image, upright; the frame size of a video. */ readonly width?: number; readonly height?: number; /** A document's pages, their sizes in points as displayed, and which carry a text layer (1-based). */ readonly pages?: number; readonly pageSizes?: readonly { readonly width: number; readonly height: number; }[]; readonly textPages?: readonly number[]; readonly durationS?: number; }; /** What the caller asked for: pages, a window, a region. `render` shows a document's pages as images even when they * carry text (a `read` with a question); a plan for the eyes always renders. */ export type Selector = { readonly pages?: PageSpan; readonly fromS?: number; readonly toS?: number; readonly region?: Region; readonly render?: boolean; }; /** `show`: what the lead is shown in a tool result. `ask`: what the eyes are asked about, in requests that fit the model. */ export type PlanMode = "show" | "ask"; /** A host's own caps on one plan for the eyes (`ask`): the pages, and the frames or clips, it may take. None by default. */ export type PlanCaps = { readonly pages?: number; readonly frames?: number; }; /** How a plan reduced its source to fit: not at all, shrunk, tiled, sampled, cut to a window, to text only, or refused. */ export type Reduction = "as_is" | "downscaled" | "tiled" | "sampled" | "windowed" | "text_only" | "refused"; /** What a plan did to fit, with the numbers a receipt and the model's first line carry. */ export type Fit = { readonly reduction: Reduction; readonly original?: { readonly width?: number; readonly height?: number; readonly pages?: number; readonly durationS?: number; readonly bytes?: number; }; readonly shown?: { readonly width?: number; readonly height?: number; readonly pages?: number; readonly frames?: number; readonly tiles?: number; readonly dpi?: number; readonly bytes?: number; }; /** Set when `reduction` is `refused`. */ readonly refusal?: { readonly code: MissCode; readonly detail: string; }; }; type Size = { readonly width: number; readonly height: number; }; type Rect = { readonly left: number; readonly top: number; readonly width: number; readonly height: number; }; /** One part to derive and send: which piece of the source it is and the target it is derived to. An empty fragment is * the whole source. `as_is` sends the source's own bytes (an image in a format the route does not take is converted * at the same size). A part whose fragment names a page is rendered from that page. */ export type PlannedPart = { readonly fragment: Fragment; readonly derive: "as_is" | "image" | "tile" | "page" | "frame" | "clip" | "text"; /** The part's own pixels: `crop`'s size, or `raster`'s when nothing is cut. */ readonly width?: number; readonly height?: number; readonly dpi?: number; readonly atS?: number; /** The whole image, page (at `dpi`) or frame scaled to this size, before `crop` is cut from it. A page renders only `crop`. */ readonly raster?: Size; /** The rectangle of `raster` this part is: a tile, a region, or a tile of a region. Absent: the whole raster. */ readonly crop?: Rect; /** Base64 bytes the derived part must fit in: its share of the result's budget (`show`) or of its request's (`ask`). */ readonly maxBytes?: number; }; /** The parts to derive, in order, and what the plan did to fit them. */ export type Plan = { readonly parts: readonly PlannedPart[]; readonly fit: Fit; }; /** A derived part, ready for a model. `data` is base64. `fragment` is the citation form of where it came from. */ export type Part = { readonly type: "text"; readonly text: string; readonly fragment?: string; } | { readonly type: "image"; readonly data: string; readonly mimeType: string; readonly width: number; readonly height: number; readonly fragment: string; } | { readonly type: "video"; readonly data: string; readonly mimeType: string; readonly fragment: string; }; /** A look's price before its first request, and its refusal when that is over the host's cap. */ export type LookEstimate = { readonly parts: number; readonly requests: number; readonly tokens: number; readonly usd: number | null; readonly refusal?: Fit["refusal"]; }; /** What a source's parts are, and how they fit `limits`, by its kind: shown to the lead (`show`) or asked of the eyes (`ask`). * A source no kind reads is a plan with no parts and `fit.reduction` `refused`. */ export declare function plan(facts: SourceFacts, selector: Selector, limits: Limits, mode: PlanMode, caps?: PlanCaps): Plan; /** The eyes requests of a plan made for `limits`, in order. */ export declare function lookRequests(planned: Plan, limits: Limits): PlannedPart[][]; /** Blocks already fitted, in order, one eyes request each: a request holds no more blocks than the least `most` of its * blocks allows, and no more than `maxChars` base64 characters. A block is never split: one over `maxChars` alone is a * request of its own. */ export declare function packRequests(blocks: readonly T[], chars: (block: T) => number, most: (block: T) => number, maxChars: number): T[][]; /** A look priced before its first request: parts times LOOK_TOKENS_PER_PART times the eyes' input price in dollars * per million tokens; over the host's `capUsd` it is refused with the estimate. No cap, or an unknown price, refuses * nothing. */ export declare function priceLook(planned: Plan, limits: Limits, inputUsdPerMTok: number | null | undefined, capUsd?: number): LookEstimate; export {};