/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ import { SortedMap, type EastType, type ValueTypeOf } from "@elaraai/east"; import { type PlanPayloadType } from "@elaraai/e3-ui/internal"; import { type Formatters } from "@elaraai/east-ui-components"; import type { OptimiseCounts } from "../shared/func/use-optimise.js"; import { type ScheduleCellsRead } from "../shared/schedule/cells.js"; import type { PlanEventEditing } from "./edit/events.js"; import { type PlanWireBlock } from "./model.js"; import type { PlanEventRange } from "./root/events.js"; import type { PlanElementOp, PlanGhost } from "./rows/element-optimise.js"; /** One event kind, as the Plan's payload carries it. */ type PlanEventKindValue = ValueTypeOf["events"][number]; /** One resource kind, as the Plan's payload carries it. */ type PlanResourceKindValue = ValueTypeOf["resources"][number]; /** A kind's rows by key, as the request and the result carry them. */ type Rows = SortedMap; /** The run's request: the window, the run's number, each event kind's rows by slot, and each resource kind's. */ export interface PlanOptimiseRequest { readonly from: Date; readonly to: Date; readonly run: bigint; readonly events: Readonly>; readonly resources: Readonly>; } /** The run's answer: each event kind's rows by slot, complete. */ export interface PlanOptimiseResult { readonly events: Readonly>; } /** * What the runs left on the Plan's events, until Apply (R17): each * element's operation, by the element's key, a later run's over an * earlier's; the ghosts of what stood on each row before a run, by the row's * key; and whether the latest run moved an event into or out of the backlog. */ export interface PlanOptimised { readonly ops: ReadonlyMap; readonly ghosts: ReadonlyMap; readonly backlogChanged: boolean; } /** * What a spec watches a run's request and its landing by (test use only), as * the canvas's render probe watches the canvas: each read of an event kind's * rows the request makes as a click builds it, and each read of a kind's * events its landing makes for what a changed event was before the run. */ export interface PlanOptimiseProbe { /** Called for each read of a kind's rows, with the kind's slot. */ readonly readRows?: (kind: string) => void; /** Called for each read of a kind's events as they stood before the run, as its result lands, with the kind's slot. */ readonly readEvents?: (kind: string) => void; } /** * Install (or clear) the probe a run's request and its landing are watched by. Test use only. * * @param probe - What watches it; `undefined` clears it */ export declare function setPlanOptimiseProbe(probe: PlanOptimiseProbe | undefined): void; /** * The request and result types over the Plan's kinds: what the bound * optimiser is called with, as the tag held it to. * * @param kinds - The event kinds * @param resources - The resource kinds * @returns The request and result East types */ export declare function planOptimiseTypes(kinds: readonly PlanEventKindValue[], resources: readonly PlanResourceKindValue[]): { request: EastType; result: EastType; }; /** The plan window in view, as the request carries it. */ export interface PlanOptimiseWindow { readonly from: Date; readonly to: Date; } /** Whether a run's request can carry the window whole now: `ready`, `reading` or `unread` ({@link planOptimiseReady}). */ export type PlanOptimiseReadiness = "ready" | "reading" | "unread"; /** * Whether a run's request can carry the window whole now (#1409, R24): every * kind's events in the window and its backlog, and each event's row held where * {@link planOptimiseRequest} reads it — called in a tracked read of a * component of its own ({@link PlanOptimiseReader}), which hears each land, so * the eye waits for them and the request a click makes finds them held. * * The request reads every event's row of a kind at once (`planRows`), from * the rows the canvas reads over its range — the plan window and the periods * laid out beyond it — and the backlog's beside them, drafts in place. So the * eye waits for those reads, read as the canvas reads them, and no row is read * by its key: whatever the number of events in the window, the eye asks e3 for * the windows alone. Read by its key, each row would be a key search and a * one-row page an event, for rows the canvas's windows hold already. Every * kind is read in one pass, so the kinds' windows are asked together. * * `reading` while one is on its way; `unread` for a window no request carries * whole: a kind past the cap of events over it (#1039), none of whose events * is read, or one read by its cells, never read over the window — a run would * place the backlog over events it was never shown. * * @param kinds - The event kinds * @param editing - The kinds' editing: each kind's drafts, which every read puts in place * @param window - The plan window in view * @param range - The range the canvas reads its event kinds' rows over (`eventReadRange`): the window, and the periods laid out beyond each edge — where the request reads each event's row * @param cells - The kinds' cells and counts, when the reader gives a kind cells * @returns Whether the request can be made: `ready`, `reading` or `unread` */ export declare function planOptimiseReady(kinds: readonly PlanEventKindValue[], editing: PlanEventEditing, window: PlanOptimiseWindow, range: PlanEventRange, cells: ScheduleCellsRead | undefined): PlanOptimiseReadiness; /** Props of {@link PlanOptimiseReader}. */ export interface PlanOptimiseReaderProps { /** The event kinds. */ kinds: readonly PlanEventKindValue[]; /** The kinds' editing: each kind's drafts, which every read puts in place. */ editing: PlanEventEditing; /** The plan window in view. */ window: PlanOptimiseWindow; /** The range the canvas reads its event kinds' rows over: where each event's row is held. */ range: PlanEventRange; /** The kinds' cells and counts, when the reader gives a kind cells. */ cells: ScheduleCellsRead | undefined; /** Where whether the request can be made goes: called only when that moves. */ onReady: (ready: PlanOptimiseReadiness) => void; } /** * Whether a run's request can carry the window whole (#1409, R24), read in a * component of its own (#1343): what {@link planOptimiseReady} reads lands in * as many settles as the searches it touches — every kind's rows over the * range the canvas reads, its events in the window, and its backlog — and each re-runs * this alone. It hands the canvas whether the request can be made only when * that moves, so the canvas renders as the eye's state changes, never at every * settle of what it reads. A read that fails is `unread`: no request carries a * window it could not read. * * @param props - What is read, over what, and where it goes * @returns Nothing: it reads */ export declare function PlanOptimiseReader({ kinds, editing, window, range, cells, onReady }: PlanOptimiseReaderProps): null; /** * The run's request (R1, R24, O3, O5): the window, the run's number, every * event kind's rows in the window and its backlog by key, as the session * holds them — base plus every unapplied draft, every row whatever the rail * shows — and every resource kind's rows, read whole. A kind's rows are read * once (`planRows`): its rows over the range the canvas reads and its * backlog's, drafts in place, which the eye waits for — none is read by its * key — indexed by key, and each event's row found there, so the click's cost * grows with the events plus the rows, never their product. A kind whose * window is still being read carries no rows: the eye is disabled until every * kind has read, and for a window no request carries whole ({@link planOptimiseReady}). * * @param kinds - The event kinds * @param resources - The resource kinds * @param editing - The kinds' editing: each kind's drafts, which every read puts in place * @param window - The plan window in view * @param range - The range the canvas reads its event kinds' rows over (`eventReadRange`): where each event's row is read * @param run - The run's number * @returns The request */ export declare function planOptimiseRequest(kinds: readonly PlanEventKindValue[], resources: readonly PlanResourceKindValue[], editing: PlanEventEditing, window: PlanOptimiseWindow, range: PlanEventRange, run: number): PlanOptimiseRequest; /** What a landing is made over. */ export interface PlanLanding { readonly kinds: readonly PlanEventKindValue[]; readonly resources: readonly PlanResourceKindValue[]; /** The kinds' editing: each kind's drafts, which its events before the run are read with, and where the step is recorded. */ readonly editing: PlanEventEditing; readonly request: PlanOptimiseRequest; readonly result: PlanOptimiseResult; /** The step's label — `Elara run #7`. */ readonly label: string; /** The run's number, formatted, for the provenance. */ readonly runText: string; /** The event kinds' rows as the canvas drew them before the run: where a ghost goes. */ readonly blocks: readonly PlanWireBlock[]; /** The app's formatters, for the provenance's words. */ readonly format: Formatters; /** What earlier runs left on the events, still the session's drafts. */ readonly before: PlanOptimised | undefined; } /** * The result landed (R7, R8, R10, R24, §12): diffed against the request by * key, kind by kind, its operations told by place, and recorded as one step * of the history, origin `optimise`. What each changed event was before the * run — its provenance's `Was …`, and whether the backlog moved — is found * among its kind's events as the request was built from them, read once a * kind that changed ({@link eventsBefore}), so a landing's work grows with the * changes plus the events, never their product. A result that answers no rows * for a kind the request asked is invalid, and nothing is recorded; one that * changes nothing records nothing and leaves what earlier runs left as it is * (R10); one that does lays its operations and ghosts over theirs. * * @param args - What the landing is made over * @returns What the run counted, and what the runs have left on the events — unchanged by a run that changed nothing; `undefined` for an invalid result, or one the session would not take */ export declare function landPlanOptimise(args: PlanLanding): { counts: OptimiseCounts; optimised: PlanOptimised | undefined; } | undefined; export {}; //# sourceMappingURL=optimise.d.ts.map