/** * GenFrame -- generative UI frame scheduler. * * Fixed-step scheduler producing "UI frames" at configurable fps * from token buffer. Each frame classified as keyframe (I-frame), * delta (P-frame), or interpolated (B-frame). * * Integrates with FrameBudget for priority scheduling and receipt * chain for disconnect-resilient generative UI state. * * @module */ import type { ContentAddress } from './brands.js'; import type { TokenBuffer } from './token-buffer.js'; import type { UIQualityTier } from './ui-quality.js'; import { type Clock } from './clock.js'; /** * Classification of a {@link UIFrame} in the generative-UI pipeline, analogous to * I/P/B frames in video: `keyframe` replaces, `delta` patches, `interpolated` * keeps the DOM still and animates via CSS only. */ export type FrameType = 'keyframe' | 'delta' | 'interpolated'; /** How a {@link UIFrame} is applied to the DOM: full replace, patch, or CSS-only motion. */ export type MorphStrategy = 'replace' | 'patch' | 'css-only'; /** * A single frame emitted by the {@link GenFrame} scheduler — the unit of work * the DOM runtime consumes. Carries the drained tokens, its classification, * the quality tier that produced it, and a content-addressed receipt for * disconnect-resilient replay. */ export interface UIFrame { readonly type: FrameType; readonly tokens: readonly string[]; readonly qualityTier: UIQualityTier; readonly morphStrategy: MorphStrategy; readonly timestamp: number; readonly receiptId: ContentAddress; readonly bufferPosition: number; } /** * Recovery plan returned by {@link GenFrame.resolveGap} when a stream disconnects: * resume from a buffer position, replay cached frames, request a full restart, * or do nothing. */ export type GapStrategy = { readonly type: 'resume'; readonly bufferPosition: number; } | { readonly type: 'replay'; readonly frames: readonly UIFrame[]; } | { readonly type: 're-request'; readonly fromScratch: true; } | { readonly type: 'noop'; }; /** Transport-layer snapshot indicating whether the stream can resume from its last event. */ export interface ResumptionInfo { readonly canResume: boolean; readonly lastEventId?: string; } /** Accessor bundle that exposes the receipt chain to {@link GenFrame.resolveGap}. */ export interface ReceiptChainInfo { readonly hasFramesAfter: (receiptId: ContentAddress | null) => boolean; readonly getFramesAfter: (receiptId: ContentAddress | null) => readonly UIFrame[]; } declare function resolveGap(lastAckReceiptId: ContentAddress | null, currentStreamPosition: number, receiptChain: ReceiptChainInfo, resumptionState: ResumptionInfo): GapStrategy; interface GenFrameConfig { readonly fps?: number; readonly tokenBuffer: TokenBuffer.Shape; readonly getQualityTier: () => UIQualityTier; /** * Injected time source for the frame's `timestamp` metadata (NOT a content- * address input — ADR-0013 keeps the timestamp out of the receipt id, so the * frame's identity stays deterministic regardless). Defaults to * {@link systemClock}; a test passes a {@link fixedClock} for a stable stamp. */ readonly clock?: Clock; } interface GenFrameSchedulerShape { tick(): UIFrame | null; readonly frameCount: number; readonly lastFrame: UIFrame | null; markKeyframe(): void; reset(): void; } declare function _make(config: GenFrameConfig): GenFrameSchedulerShape; /** * Generative-UI frame scheduler namespace. * * Turns a bursty LLM token stream into evenly-paced frames the DOM runtime * can apply without stalling, and resolves disconnect gaps using the receipt * chain or transport resumption. */ export declare const GenFrame: { /** Create a new fixed-step scheduler bound to a {@link TokenBuffer} and quality-tier probe. */ make: typeof _make; /** Pick a recovery {@link GapStrategy} after a stream disconnect. */ resolveGap: typeof resolveGap; }; export declare namespace GenFrame { /** Structural shape of a scheduler instance returned by {@link GenFrame.make}. */ type Shape = GenFrameSchedulerShape; /** Configuration accepted by {@link GenFrame.make}. */ type Config = GenFrameConfig; /** Alias for {@link UIFrame}. */ type Frame = UIFrame; } export {}; //# sourceMappingURL=gen-frame.d.ts.map