/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * Optimise in the Allocation (#1409, #1420, east-workspace#1622; `Optimise * Spec.md` §5.1, §9.5, R26): the run's request — the day in view, the run's * number and the rail's narrowing, and no row: the function reads the bins, * the arrivals and the resources itself, the board's unsaved edits laid over * them — and its answer, a patch of the bins' record, landed on the bins the * page holds as one edit: each key the patch touches, recorded as one step * (`ScheduleEditing.record`, origin `optimise`), and what the landing draws * kept until Apply — each bin's operation and its provenance, the ghosts of * the bins a run moved or removed where they stood, which lanes the latest * run changed, whether an arrival left the Arrivals tab or came back to it, * and the links the runs added or changed with the kilns they land on, which * the Timeline draws outlined in the Elara tone and glows for the highlight. * While a run is out the commands are locked (R2): every gesture refused, * the day's drafts kept. A bin the answer changes that the page does not hold * is read by its key first (rule 8); one it changes outside the day it was * asked of — where the bin stood, or where the answer puts it — or any change * of a day that takes no edit, as the day stands as the answer lands, refuses * the answer whole (rule 11). * * @packageDocumentation */ import { DictType, type EastType, type ValueTypeOf, type option } from "@elaraai/east"; import { AllocationOptimiseRequestType } from "@elaraai/e3-ui/internal"; 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 { AllocationCommands } from "./actions.js"; import type { AllocationEditing } from "./editing.js"; import type { AllocationMessages } from "./messages.js"; import { type AllocationDomain, type AllocationValue, type Bin, type Context, type Day } from "./model.js"; /** The run's request: the day, the run's number and the rail's narrowing. */ export type AllocationOptimiseRequest = ValueTypeOf; /** The run's answer: the patch of the bins' record. */ export interface AllocationOptimiseResult { readonly bins: unknown; } /** One operation a run left on a bin, until Apply (R17): what it did, the run that made it, and what its hover says. */ export interface AllocationBinOp { readonly op: "add" | "chg"; /** The run's number, formatted. */ readonly run: string; /** `Added by Elara · run #7`, or `Was B-1 06:15 on K-203 · Elara run #7`. */ readonly provenance: string; } /** Where a bin stood before a run removed it (`del`) or moved it (`from`): its ghost, for the highlight (R15). */ export interface AllocationGhost { readonly id: string; readonly op: "del" | "from"; readonly run: string; /** The lane slot it stood in. */ readonly lane: string; readonly at: Date; /** Its code — `LD-2231`, or `Reserved`. */ readonly label: string; /** Where it stood, in words: `B-1 06:15 on K-203`. */ readonly where: string; /** `Removed by Elara · run #7`, or `Moved by Elara · run #7`. */ readonly title: string; } /** * What the runs left on the Allocation's bins, until Apply (R17): each bin's * operation, a later run's over an earlier's on the same bin; the ghosts of * the bins the runs moved or removed, where they stood; the lanes the latest * run changed; and whether it booked an arrival or returned one. */ export interface AllocationOptimised { readonly ops: ReadonlyMap; readonly ghosts: readonly AllocationGhost[]; /** The lanes whose bins the latest run added, moved or removed: their heads' figures flash. */ readonly lanes: ReadonlySet; /** Whether the latest run booked an arrival or returned one to Arrivals: the Arrivals tab's count flashes. */ readonly arrivalsChanged: boolean; /** * The links the runs added or changed, by bin — each kiln whose part is new or differs from before the run, an * earlier run's kept while the bin still has it — while still the runs' drafts: the Timeline draws them for the * highlight, outlined in the Elara tone, never filled, so a result's many links stay readable. */ readonly links: ReadonlyMap>; /** Their kilns: each one's load takes the landing and the highlight with the cards. */ readonly resources: ReadonlySet; } /** What the bound optimiser is called with, as the tag held it to, and the bins' record type. */ export interface AllocationOptimiseTypes { readonly request: EastType; readonly result: EastType; /** The bins' record type, `Dict`: what the answer's patch is read by. */ readonly record: DictType; } /** * The request and result types over the app's bin row type: what the bound * optimiser is called with, as the tag held it to. * * @param rowType - The bin kind's row type * @returns The request and result East types, and the bins' record type */ export declare function allocationOptimiseTypes(rowType: EastType): AllocationOptimiseTypes; /** * The run's request (R1, R26, O3; east-workspace#1622, rule 1): the day in * view, the run's number and the rail's narrowing. No row: the function reads * the bins, the arrivals and the resources itself, the board's unsaved edits * laid over them. * * @param day - The plan day * @param slice - Each rail source's narrowing now * @param run - The run's number * @returns The request */ export declare function allocationOptimiseRequest(day: Date, slice: OptimiseSlice, run: number): AllocationOptimiseRequest; /** * Where a bin stands, as its provenance and its ghost say it: `B-1 06:15 on * K-203`, `B-2 10:35 · not linked`. * * @param value - The payload: the lanes' labels * @param context - Every resource, by key * @param bin - The bin * @returns The words */ export declare function allocationPlaceWords(value: AllocationValue, context: Context, bin: Bin): string; /** What a landing is made over. */ export interface AllocationLanding { readonly value: AllocationValue; readonly domain: AllocationDomain; /** The bins' record type. */ readonly types: AllocationOptimiseTypes; /** The editing the step is recorded in. */ readonly editing: AllocationEditing; /** 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: AllocationOptimiseRequest; readonly result: AllocationOptimiseResult; /** The step's label — `Elara run #7`. */ readonly label: string; /** The run's number, formatted, for the provenance. */ readonly runText: string; /** The day's words, which a refusal names. */ readonly period: string; /** The day as drafted before the run: where a ghost goes, and what the provenance says a bin was. */ readonly plan: Day; readonly context: Context; /** What earlier runs left on the bins, still the session's drafts. */ readonly before: AllocationOptimised | undefined; /** Whether the day takes edits as the answer lands: the status of the period holding it, stored and drafted, one that does. */ readonly open: boolean; /** The period the board publishes — the day, or its week (#1550): what a refusal over one that takes no edit names. */ readonly unit: "day" | "week"; /** The board's words: a refusal's. */ readonly m: Pick; } /** * The result landed (R7, R8, R10, §12; east-workspace#1622, rules 7, 8, 10, * 11): the answer's patch landed key by key on the bins the page holds, and * recorded as one step of the history, origin `optimise`. A bin the * result adds is an add — booked, its arrival leaves the Arrivals tab; one it * changes is a change, with a ghost at its old lane slot when it moved; one * it drops is a remove, its ghost where it stood, its arrival back in * Arrivals (§9.5). A result that changes nothing records nothing and leaves * what earlier runs left as it is (R10); one that does lays its operations, * its ghosts and its links over theirs. One that changes a bin outside the * day it was asked of — where the bin stood, or where the answer puts it — is * refused whole, naming the bin, and so is one that changes anything of a day * that takes no edit, as a gesture there is (`open`); one that touches a bin * the page does not hold names it, to be read by its key. * * @param args - What the landing is made over * @returns What the run counted, and what the runs have left on the bins — unchanged by a run that changed nothing; * the bins to read first; a refusal, naming the bin; `undefined` for an answer that does not fit the bins the page * holds, or one the session would not take */ export declare function landAllocationOptimise(args: AllocationLanding): OptimiseLanded | OptimiseMissing | OptimiseRefused | undefined; /** * The commands while a run is out (R2): the day takes no gesture — every * command refused, Publish off — the session the views read kept, so they * keep drawing their drafts while nothing is written. * * @param commands - The commands * @returns The commands, locked */ export declare function lockAllocationCommands(commands: AllocationCommands): AllocationCommands; //# sourceMappingURL=optimise.d.ts.map