/** * A route's model list as a draft: pure edits, no Harness, no rendering. * * A pi-ai route serves one of two catalogs. An explicit `models` array is the * route's whole list, each entry carrying an `id` and possibly fields this pass * does not curate. A route with no such list inherits the installed catalog, * and then per-model edits go to `modelOverrides.` so the rest of that * catalog keeps serving untouched. {@link ModelStorage} is what tells the two * apart inside one draft type, and the write projection follows from it. * * An override draft records which curated fields the reader actually edited * ({@link ModelDraftEntry.changed}), because a whole-object rewrite would carry * the open-time copy of a field nobody opened back over a concurrent edit. The * `models` array keeps its whole-array write: array elements are not * independently path-addressable through this settings seam, and that write * already carries every uncurated field through. * * Every function here is a pure transform over `ModelDraftEntry[]`. The * terminal loop that turns keystrokes into calls on these lives in * `route-editor.ts`; nothing here pushes an overlay or calls a seam. * @module dshline/connect/model-editor */ import type { LlmDiscoveredModelRead } from './harness.ts'; import type { ModelCuratedField, ReasoningEffortsValue } from './pi-ai.ts'; /** Which profile field one draft's entries are written into. */ export type ModelStorage = 'models' | 'override'; /** One model row in a draft being edited. */ export interface ModelDraftEntry { readonly id: string; readonly name: string | undefined; readonly contextWindow: number | undefined; readonly maxTokens: number | undefined; /** Declared modalities, or undefined to inherit the installed catalog's / route default. */ readonly input: readonly string[] | undefined; /** The declared reasoning capability, or undefined to inherit. */ readonly reasoningEfforts: ReasoningEffortsValue | undefined; /** The entry's previous raw shape, so an unrendered field survives a write. */ readonly retained: Record | undefined; /** Whether this entry is part of the set that would be written. */ readonly included: boolean; /** Which profile field a write addresses. */ readonly storage: ModelStorage; /** * The curated fields this draft actually edited, and therefore the only * fields a `modelOverrides.` write may address. An untouched field stays * out of the set even though its value is displayed, which is what keeps a * second save after a revision race from reapplying a stale copy of a field * the reader never opened. */ readonly changed: ReadonlySet; } /** * Build a draft from a route's raw `models` array. * * The array is the route's explicit list, so every usable entry is included; * `undefined` and `[]` both mean the route inherits, and each yields an empty * draft. An entry without a usable id is skipped, since nothing downstream can * address it. * @param raw - the profile's stored entries, or undefined/empty when it inherits. * @returns one entry per usable raw item, all included, writing to `models`. */ export declare function entriesFromRaw(raw: readonly unknown[] | undefined): ModelDraftEntry[]; /** * Build a draft from a route's raw `modelOverrides` dict. * * Every stored override is included — it is a saved customization, and the * route menu must show it even when the installed catalog no longer describes * that id, because removing it is the repair. An empty key is skipped, since it * cannot address a model. * @param raw - the profile's raw `modelOverrides` dict. * @returns one entry per stored override, all included, writing to `modelOverrides`. */ export declare function entriesFromOverrides(raw: Record): ModelDraftEntry[]; /** * Fold discovery candidates into a draft, without touching an id already there. * * A candidate whose id the draft already knows is dropped rather than merged: * the draft's own fields — possibly hand-corrected — are the more trustworthy * source for that id, and an endpoint listing reports an id, at best a name, * two capacities, and (at the adopted generation) the modalities the installed * catalog records. A new id is added unchecked, so adopting it is still a * deliberate toggle rather than something this call did on the reader's behalf. * @param entries - the draft before the fetch. * @param candidates - what the endpoint reported. * @param storage - which field a later write addresses, matching the draft. * @returns the draft with unseen candidates appended, unincluded. */ export declare function addCandidates(entries: readonly ModelDraftEntry[], candidates: readonly LlmDiscoveredModelRead[], storage: ModelStorage): ModelDraftEntry[]; /** * Flip one entry's inclusion. * @param entries - the draft. * @param id - the entry to toggle. * @returns the draft with that entry's `included` flipped. */ export declare function toggleIncluded(entries: readonly ModelDraftEntry[], id: string): ModelDraftEntry[]; /** * Mark one curated field as edited, keeping every other field and the set's * previous members. * @param entry - the entry being edited. * @param field - the field the reader changed. * @returns the entry with the field recorded as changed. */ export declare function markChanged(entry: ModelDraftEntry, field: ModelCuratedField): ModelDraftEntry; /** Fields a hand-typed or hand-edited model row carries. */ export interface ModelFieldInput { readonly id: string; readonly name: string | undefined; readonly contextWindow: number | undefined; readonly maxTokens: number | undefined; readonly input: readonly string[] | undefined; readonly reasoningEfforts: ReasoningEffortsValue | undefined; } /** What adding or editing one entry produced. */ export type ModelEditResult = { readonly ok: true; readonly entries: ModelDraftEntry[]; } | { readonly ok: false; readonly reason: string; }; /** * Add a hand-typed model, refusing a duplicate id before it reaches settings. * @param entries - the draft. * @param fields - the typed fields. * @param storage - which field a later write addresses, matching the draft. * @returns the draft with the new entry appended and included, or the refusal. */ export declare function addManual(entries: readonly ModelDraftEntry[], fields: ModelFieldInput, storage: ModelStorage): ModelEditResult; /** * Replace one entry's curated fields, keeping its id, inclusion, and retained shape. * @param entries - the draft. * @param id - the entry being edited. * @param fields - the new curated values. * @param changed - the fields this edit actually touched. * @returns the draft with that entry updated. */ export declare function updateFields(entries: readonly ModelDraftEntry[], id: string, fields: Omit, changed?: readonly ModelCuratedField[]): ModelDraftEntry[]; /** * Drop one entry from the draft entirely. * @param entries - the draft. * @param id - the entry to remove. * @returns the draft without it. */ export declare function removeEntry(entries: readonly ModelDraftEntry[], id: string): ModelDraftEntry[]; /** The numeric bounds a serialized `number` field declared; absent means unconstrained. */ export interface NumericRules { readonly min?: number; readonly step?: number; } /** * Parse an optional numeric field against the constraints its own schema * declared. * * The rules come from the serialized `number` node, not from this function: a * blank answer means absent, a value must clear `min` when one is declared, and * a declared `step` (measured from `min`, or from zero when no floor exists) * must divide the value exactly. Nothing here assumes a positive integer — a * schema that allows zero, or a fractional step, is honored as written, and a * schema with no `step` accepts any finite number rather than inventing one. * @param raw - the typed text, or undefined when the field was not answered. * @param rules - the schema-declared bounds for this field. * @returns the parsed number, or the refusal reason. */ export declare function parseCapacity(raw: string | undefined, rules: NumericRules): { ok: true; value: number | undefined; } | { ok: false; reason: string; }; /** * The entries that would actually be written. * @param entries - the draft. * @returns the included entries, in draft order. */ export declare function includedEntries(entries: readonly ModelDraftEntry[]): readonly ModelDraftEntry[]; /** * The draft's included entries as JSON-compatible rows, unknown fields intact. * @param entries - the draft. * @returns one record per included entry, ready for a `set` op. */ export declare function toRawEntries(entries: readonly ModelDraftEntry[]): Record[]; /** * Whether two drafts would write the same models, order aside. * * Compared as written rows rather than as entry objects, so an entry whose * `retained` carries the same values two different ways (or not at all, * because a manual entry has none) still compares equal when the read is what * matters. Order does not matter to what a route serves, so a fetch that * re-adds entries in a different order is not reported as a change. * @param left - one draft. * @param right - the other draft. * @returns true when their written rows carry the same fields, regardless of order. */ export declare function sameModelSet(left: readonly ModelDraftEntry[], right: readonly ModelDraftEntry[]): boolean; /** * One override value as it would be written, unknown fields intact. * * Used only for an id's first appearance in a draft, where there is no stored * sibling to preserve; an existing override is written field by field. * @param entry - the draft entry. * @returns the `modelOverrides.` value. */ export declare function toRawOverride(entry: ModelDraftEntry): Record; /** * The draft's included overrides as id-keyed JSON-compatible values. * @param entries - the draft. * @returns the override dict, in draft order. */ export declare function toRawOverrides(entries: readonly ModelDraftEntry[]): Record>; /** * Whether two override drafts would write the same customizations. * * Compared as written values rather than as entry objects, for the same reason * {@link sameModelSet} compares rows: an edited field that lands on the value * already stored is not a change. Order is not compared because a dict has * none. Used by the menu to decide whether the draft differs at all, never to * build a write. * @param left - one draft. * @param right - the other draft. * @returns true when both write the same id set with the same fields. */ export declare function sameOverrideSet(left: readonly ModelDraftEntry[], right: readonly ModelDraftEntry[]): boolean; //# sourceMappingURL=model-editor.d.ts.map