/** * 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"; import type { SourcesChrome } from "../schedule/visibility.js"; import { type OptimiseSlice } from "./optimise-slice.js"; import { type FuncCallBinding, type FuncCallDraft } from "./use-func-call.js"; import type { OptimiseSessions } from "./use-optimise.js"; /** * The page's scope a builder's fit asks in ({@link fitScope}, rule 1), the same object while each source's scope holds: * the builder's questions are asked in it by identity, so a choice on the rail — never sent to a fit — asks nothing * again, and a new scope asks anew. * * @param chrome - The builder's rail, as its payload carries it; `undefined` for a builder with no rail * @returns Each source's scope, by the source's name */ export declare function useFitScope(chrome: SourcesChrome | undefined): OptimiseSlice; /** * What a builder's fit asks, and how. * * @typeParam Q - A question * @typeParam P - The plan a question is asked of: the builder's drafts as it reads them, or a plan it derives from them * @typeParam C - The context it is asked in * @typeParam R - An answer */ export interface FitQuestions { /** The app's function's name; `null` with none, and nothing is asked. */ name: string | null; /** What the function lists in `drafts` and reads, as its binding names them: one that lists none is called with its request alone. */ binding: FuncCallBinding; /** The builder's sessions over the records it edits: an ask takes its drafts from them as they stand. */ sessions: OptimiseSessions; /** What the function takes. */ requestType: EastType; /** What it answers. */ resultType: EastType; /** A question's key: its East text. */ key: (question: Q) => string; /** The key of the question an answer answers, from what it echoes. */ answers: (result: R) => string; /** The function's argument for a question, in a context: the question and the page's scope, and no row (rule 1). */ request: (question: Q, context: C) => unknown; /** * A plan the builder derives from its drafts, as one more draft laid after its sessions' (rule 10): the change from * the drafts to it, of a record the function lists in `drafts`. * * @param of - The derived plan * @param base - The drafts it was derived from * @returns The draft; `undefined` where the function lists no record the change is of — it reads none of it, and * is asked of the drafts — or the two hold the same rows */ further?: (of: P, base: P) => FuncCallDraft | undefined; /** * Whether a question's own subject is complete (rule 8): one whose edit has a field still missing is in no draft, * so the question is not asked until it is complete, and shows no verdict meanwhile. Every question's is, unless given. */ complete?: (question: Q) => boolean; } /** * A builder's fit (see the module docs). * * @typeParam Q - A question * @typeParam P - A plan * @typeParam R - An answer */ export interface FitAnswers { /** The answer to a question about the plan as it stands, or about one derived from it, once it has landed (F1). */ answer: (question: Q, of?: P) => R | undefined; /** * Asks a question of the plan as it stands, or of one derived from it: answered from what is kept, else sent once nothing is in * flight. A new plan or context is a new `ask`, so an effect that asks, listing it, asks again then (F1). */ ask: (question: Q, of?: P) => void; /** * Why a question about a derived plan has no answer, and none is coming: its record refused the plan's change as e3 * laid it (rule 10), in the record's words. That question alone has failed — the board's fit has not, and the drafts * as they stand are still asked about — until the plan or the context moves on, when it is asked anew; `undefined` * for any other question. */ refused: (question: Q, of?: P) => string | undefined; /** Whether a question asked of the plan as it stands is unanswered (F2). */ pending: boolean; /** Why the last call failed, or why the sessions' edits could not be asked about (F3; rules 9 and 12). */ error: string | undefined; /** Asks the failed question again (F3). */ retry: () => void; } /** * A builder's fit (see the module docs). * * @typeParam Q - A question * @typeParam P - The plan a question is asked of, kept by identity: a new plan, new answers * @typeParam C - The context it is asked in, kept by identity: a new context, new answers. It holds what the page * reads and its sessions' drafts, so the drafts an ask takes from the sessions are made once for each * @typeParam R - An answer * @param questions - The function and what it lists, the builder's sessions, and how a question is keyed, answered and asked * @param plan - The builder's drafts as they stand * @param context - What every question is asked in * @returns The fit */ export declare function useFit(questions: FitQuestions, plan: P, context: C): FitAnswers; //# sourceMappingURL=use-fit.d.ts.map