import type { Kind } from "./kinds.js"; import type { MissEvent } from "./misses.js"; import type { Fit } from "./plan.js"; import type { CallContext, Usage } from "./host.js"; /** One look as the host files it: the call, its status, the facts a receipt header carries, and the answer or the miss as the body. */ export type LookRecord = { /** `look` for what was seen, `transcribe` for what was heard: the same shape, filed in the same document. */ readonly tool: "look" | "transcribe"; /** The call as the receipt header's `args:` line shows it. `native` is true when the lead saw the media itself. */ readonly args: { readonly path: string; readonly ask?: string; readonly page?: number; readonly pages?: string; readonly from_s?: number; readonly to_s?: number; readonly region?: string; readonly model: string; readonly native: boolean; readonly via?: string; }; readonly status: "ok" | "failed"; readonly facts: { /** The source's pixels (`x`) when its header says. */ readonly original?: string; /** The largest block shown or looked at (`x`), how many blocks, and the base64 characters of the largest. */ readonly shown?: string; readonly shown_blocks?: number; readonly shown_bytes?: number; readonly sha256: string; readonly kind: Kind; readonly fragment: string; readonly fit?: Fit; /** The look's memo key: SHA-256 of the source hash, selector, question, eyes model, contract version and plan. */ readonly key: string; readonly tokens_in?: number; readonly tokens_out?: number; /** Null when the price is not known, never 0; 0 when another service billed the look (see `via`). A failed look that * sent no request is 0 with no tokens; one answered with no text has that answer's price (and tokens, when it * has them); one whose request threw, and may have been billed, has none. */ readonly cost_usd?: number | null; readonly provider?: string; readonly derived?: readonly string[]; /** Set when the result's unit ids did not match its image blocks and every block was looked at on its own. */ readonly units_dropped?: string; /** Set when the answer was read back from the call's memo: an earlier attempt or an earlier call asked and paid for * it, and this one made no request. Its key's other records are that look's, not another payment. */ readonly kept?: true; /** When the model call this look made began, in epoch milliseconds. Absent for a look that made no request in this * call (a native look, one read back from a memo) and for one whose caller sent none. */ readonly startedAt?: number; /** The tool call the look ran under: the call's own `toolCallId` (`CallContext.toolCallId`), which a timeline names as * the parent of this look. Absent when the caller named none. */ readonly parentToolCallId?: string; }; /** The answer, "shown to the model natively", or the miss. */ readonly body: string; }; /** Where the host files a look's record. It has pi-browser's sink shape, so a host that files the browser's receipts files these the same way. */ export type EvidenceSink = { /** File `record` under the conversation's `label`. `path` is what the model is told to cite. Null when the host files nothing. */ file(label: string, record: LookRecord): Promise<{ readonly path: string; } | null>; }; /** One look that happened, for the host's rows and spend: a look the eyes made, and one the lead made natively (no * usage, `record.args.native` true). */ export type LookEvent = { readonly conversationId: string; /** `read` or `vision.see`, or the tool whose result held the image (`CallContext.tool`). */ readonly tool: string; readonly source: string; readonly ask?: string; readonly fragment: string; readonly model: string; readonly usage: Usage | null; /** Null when the price is not known; 0 when `billedBy` names another service. */ readonly costUsd: number | null; readonly billedBy?: string; /** When the model call began, in epoch milliseconds (`record.facts.startedAt`), and the tool call it ran under * (`record.facts.parentToolCallId`): a timeline draws the call as a bar under that tool call. Each is absent when the * record has none. */ readonly startedAt?: number; readonly parentToolCallId?: string; /** The host heard of this look in an earlier attempt of the call: do not charge it again. A look whose answer was read * back but whose host was never told (`record.facts.kept` alone) is charged once, here. A call cut after this hook * returns and before the guard keeps that it was told tells it again without `kept`: at least once. */ readonly kept?: true; /** Where the record was filed, or null when the sink filed nothing. */ readonly receipt: string | null; readonly record: LookRecord; }; /** Where a conversation's looks go: the host's sink under its label, and its hooks. */ export type Filing = { readonly conversationId: string; readonly label: string; readonly evidence: EvidenceSink; readonly onLook?: (look: LookEvent) => void | Promise; readonly onMiss?: (miss: MissEvent) => void | Promise; }; /** The memo key of a look: the same source, selector, question, eyes and plan under this contract give the same key. */ export declare function lookKey(input: { readonly sha256: string; readonly fragment: string; readonly ask?: string; readonly model: string; readonly plan?: unknown; }): string; /** The SHA-256 of the bytes a set of base64 blocks carries, in order: what a look at blocks with no source file saw. */ export declare const blocksSha256: (blocks: readonly { readonly data: string; }[]) => string; /** The record's facts as receipt header lines, in a fixed order, each a string or a number; absent facts are left out * and a price nobody knows is written `unknown`. `fit` is its reduction; its numbers are `original` and `shown`. */ export declare function receiptFacts(record: LookRecord): Record; /** Calls a host hook; a throw or a rejection is the host's and never fails the call. */ export declare function quietly(hook: ((value: T) => void | Promise) | undefined, value: T): Promise; /** File one look and tell the host: the receipt path, or null when the sink filed nothing or failed. */ export declare function fileLook(filing: Filing, tool: string, record: LookRecord, answer?: { readonly usage: Usage | null; readonly costUsd: number | null; readonly billedBy?: string; readonly kept?: true; }): Promise; /** `ask`'s answer kept as the call's memo `vision:look:` before anything reports it, and whether it was read back: * an earlier attempt of the call asked and paid, and this one asked nothing. */ export declare function keptAnswer(memo: CallContext["memo"], key: string, ask: () => Promise): Promise<{ readonly answer: T; readonly readBack: boolean; }>; /** A look filed and told through `file`, then kept as the call's memo `vision:told:` once the host's `onLook` has * returned; a call run again that finds it files and tells the look as told before (`file(filing, true)`). A hook that * throws leaves no memo, so a rerun tells the host again. */ export declare function fileTold(memo: CallContext["memo"], key: string, filing: Filing, file: (filing: Filing, told: boolean) => Promise): Promise;