/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ import type { EastType } from "@elaraai/east"; /** How long the footer says `Stopped · nothing changed` after Stop (§8): 2.5s. */ export declare const OPTIMISE_STOPPED_MS = 2500; /** What a builder counted of a result it landed as one step (R7, R8). */ export interface OptimiseCounts { readonly added: number; readonly changed: number; readonly removed: number; } /** * A result the builder would not land (#1553): why, in its words — the * banner's line — such as an answer changing a duty of a published week. */ export interface OptimiseRefused { readonly refused: string; } /** * What a run asks, and what the builder does with its answer. * * @typeParam Req - The request: the builder's `OptimiseRequest` * @typeParam Res - The result: its `OptimiseResult` */ export interface OptimiseArgs { /** The bound optimiser's name; `null` without one, and there is no eye. */ readonly name: string | null; /** What the function takes. */ readonly requestType: EastType; /** What it answers. */ readonly resultType: EastType; /** The scope in view, by its key — the period: a change stops a run out (O4). */ readonly scope: string; /** The builder's key: the run counter is kept under it (D5). */ readonly storageKey: string; /** * The result landed, for the run it was asked of: the builder diffs it * against the request by key and records one step (R7, R8), answering * what it counted; a refusal, recording nothing, for an answer it would * not take, naming why (#1553); `undefined` for an invalid response — a * key outside the scope, a row of another type — which is a failure (R10, * §12). */ readonly onLanded: (result: Res, request: Req, run: number) => OptimiseCounts | OptimiseRefused | undefined; } /** What a run came to (R10): its number, the period it was asked of, and what changed — or why not, `refused` the builder's words where it refused the answer (#1553). */ export type OptimiseRunOutcome = { readonly kind: "done"; readonly run: number; readonly period: string; readonly counts: OptimiseCounts; } | { readonly kind: "none"; readonly run: number; readonly period: string; } | { readonly kind: "fail"; readonly run: number; readonly period: string; readonly message: string; readonly refused?: string; }; /** * A run of the app's optimiser (see the module docs). * * @typeParam Req - The request */ export interface OptimiseRun { /** Whether the app bound an optimiser: the eye shows only then. */ readonly offered: boolean; /** Whether a call is out: the eye runs, the footer counts, the builder holds its lock (R2). */ readonly running: boolean; /** The seconds since the call left, from 1, while a call is out. */ readonly seconds: number; /** The latest run's number: the call out, or the last that landed or stopped; 0 before any. */ readonly run: number; /** * Starts a run (R1): one call with the request the builder makes for the * run's number, over the period named. Nothing while one is out, or with * no optimiser. * * @param request - The request for the run's number * @param period - The period's label — `W11` — which the outcome names */ start(request: (run: number) => Req, period: string): void; /** Stops the run out (R3): the call cancelled, a late response ignored, nothing recorded. */ stop(): void; /** Whether the footer says `Stopped · nothing changed`: for 2.5s after Stop. */ readonly stopped: boolean; /** What the last run came to; `undefined` until one lands, after `dismiss`, and from the next `start`. */ readonly outcome: OptimiseRunOutcome | undefined; /** Moves at each run that landed with nothing to change: the eye blinks once each time. */ readonly blinks: number; /** Clears the outcome: the banner dismissed. */ dismiss(): void; } /** * A run of the app's optimiser (see the module docs). * * @typeParam Req - The request * @typeParam Res - The result * @param args - The function, the scope, the builder's key, and what the builder does with a result * @returns The run */ export declare function useOptimise(args: OptimiseArgs): OptimiseRun; //# sourceMappingURL=use-optimise.d.ts.map