/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * Optimise in the Plan (#1409, #1419, east-workspace#1622; `Optimise Spec.md` * §5.1, §9.5, R24): the run's request — the plan window in view and the unit * its axis is zoomed to, the run's number and the rail's narrowing, and no row * — and its answer, a patch of each event kind's record by slot, landed on the * canvas's events as one edit: each key the patches touch, on the row the page * holds, kind by kind, recorded as one step (`ScheduleEditing.record`, origin * `optimise`), its operations told by place — backlog → placed is an add on * the canvas, placed → backlog a remove, a moved or re-assigned bar a change — * and what the landing draws kept until Apply: each element's operation and * provenance, and the ghosts of what stood on each row before. * * The request reads nothing the page read, so the eye waits on none of it * (rule 6): a kind read a cell at a time, and one past the cap of events over * the window, run as any other. An event the answer changes that the page does * not hold is read by its key before the answer lands (rule 8); one it changes * outside the window it was asked of refuses the answer whole (rule 11). * * @packageDocumentation */ import { type EastType, type ValueTypeOf, type option } from "@elaraai/east"; import { ScheduleOptimiseRequestType, type PlanPayloadType, type ScheduleOptimiseRecords } from "@elaraai/e3-ui/internal"; import { type Formatters } from "@elaraai/east-ui-components"; import { type OptimiseLanded } from "../shared/func/optimise-diff.js"; import type { OptimiseSlice } from "../shared/func/optimise-slice.js"; import type { OptimiseMissing, OptimiseRefused } from "../shared/func/use-optimise.js"; import type { PlanEventEditing } from "./edit/events.js"; import type { PlanRowValue } from "./model.js"; import type { PlanElementOp, PlanGhost } from "./rows/element-optimise.js"; import type { PlanResolution } from "./scale.js"; /** One event kind, as the Plan's payload carries it. */ type PlanEventKindValue = ValueTypeOf["events"][number]; /** The run's request: the window, the unit the axis is zoomed to, the run's number and the rail's narrowing. */ export type PlanOptimiseRequest = ValueTypeOf; /** The run's answer: each event kind's patch of its record, by slot. */ 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 the bound optimiser is called with, as the tag held it to, and each event kind's record type by slot. */ export interface PlanOptimiseTypes { readonly request: EastType; readonly result: EastType; /** Each event kind's record type, `Dict`, by slot: what its patch is read by. */ readonly records: ScheduleOptimiseRecords; } /** * 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 * @returns The request and result East types, and each kind's record type */ export declare function planOptimiseTypes(kinds: readonly PlanEventKindValue[]): PlanOptimiseTypes; /** The plan window in view, as the request carries it. */ export interface PlanOptimiseWindow { readonly from: Date; readonly to: Date; } /** * The run's request (R1, R24, O3; east-workspace#1622, rule 1): the plan * window in view and the unit its axis is zoomed to, the run's number and the * rail's narrowing. No row: the function reads the events it needs, the page's * unsaved edits laid over them. An axis zoomed to hours names a day, the * finest period a request names. * * @param window - The plan window in view * @param resolution - The unit the axis is zoomed to * @param slice - Each rail source's narrowing now * @param run - The run's number * @returns The request */ export declare function planOptimiseRequest(window: PlanOptimiseWindow, resolution: PlanResolution, slice: OptimiseSlice, run: number): PlanOptimiseRequest; /** What a landing is made over. */ export interface PlanLanding { readonly kinds: readonly PlanEventKindValue[]; /** Each kind's record type by slot. */ readonly types: PlanOptimiseTypes; /** The kinds' editing: how a kind reads a row, and where the step is recorded. */ readonly editing: PlanEventEditing; /** A row as the page holds it, read by its key where it holds none: what the answer lands on. */ readonly held: (kind: string, id: string) => option | undefined; readonly request: PlanOptimiseRequest; readonly result: PlanOptimiseResult; /** The step's label — `Elara run #7`. */ readonly label: string; /** The window's words, which a refusal names. */ readonly period: string; /** The run's number, formatted, for the provenance. */ readonly runText: string; /** The canvas's rows as it drew them before the run, the events joined into those they land on: where a ghost goes. */ readonly rows: readonly PlanRowValue[]; /** 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; east-workspace#1622, rules 7, 8, * 10, 11): each kind's patch landed key by key on the events the page holds, * 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 read from the row * the answer landed on, as its kind reads a row. An answer with no patch for a * kind, or one that does not fit the events the page holds, is invalid, and * nothing is recorded; one that changes an event outside the window it was * asked of — where the event stood, or where the answer puts it — is refused * whole, naming the event; one that touches an event the page does not hold * names it, to be read by its key (`landOptimiseEvents`, shared with the * Calendar); 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; * the events to read first; a refusal, naming the event; `undefined` for an invalid result, or one the session would not take */ export declare function landPlanOptimise(args: PlanLanding): OptimiseLanded | OptimiseMissing | OptimiseRefused | undefined; export {}; //# sourceMappingURL=optimise.d.ts.map