/** * Reading provider configuration through Harness, and keeping nothing. * * One pass over four surfaces produces the whole browser: the configurable * directory says which routes exist, the model registry says which are live, * the settings document says how each is configured, and the credential seam * says whether the secret each names is present. Between passes this class * holds a rendered snapshot and nothing else — there is no provider list, no * credential cache, and no settings mirror to fall out of date. * * A pass is generation-stamped. Actions cause re-reads and `llm/adapters-updated` * causes more, so two can overlap; the older one's result is dropped rather than * being allowed to repaint a browser that has already moved on. * @module dshline/connect/catalog */ import type { Context } from '@deepseek-ai/cordis'; import type { ConnectCredentials, ConnectSeams, SettingsDescriptorRead } from './harness.ts'; import type { ConnectCredentialReading, ConnectReadiness, ConnectState } from './model.ts'; /** What the catalog needs from its owner. */ export interface ConnectCatalogSpec { /** The Harness seams to read, each optional except the model registry. */ readonly seams: ConnectSeams; /** Redraw after a pass lands. */ readonly invalidate: () => void; } /** Reads Harness's provider configuration into rows, on demand. */ export declare class ConnectCatalog { private readonly spec; private current; private generation; private disposed; /** * @param spec - the seams to read and the redraw to call. */ constructor(spec: ConnectCatalogSpec); /** The most recent complete reading, or what is standing in for one. */ state(): ConnectState; /** * Start a fresh pass over every surface. * * Never awaited by the caller: the browser is already on screen, and a read * that has not landed shows the previous reading rather than a blank frame. */ refresh(): void; /** * Read every surface once, adopt the result, and hand it back. * * {@link ConnectCatalog.refresh} exists because a browser already on screen * should not blank while a read lands; this exists because ONE caller needs * the reading itself before it may act. After a sign-in commits a credential * record, whether the matching route is dormant — and at which settings * revision — decides whether activation is offered at all, and offering it * from the pre-sign-in snapshot would mean writing an empty profile over a * route something else activated in the meantime. That write replaces a * profile wholesale, so a stale answer is not a cosmetic error. * * Generation-stamped like every other pass, so a reading this supersedes * cannot repaint over it, and a reading superseded BY one cannot either. The * value is still returned to its caller in that case: it is what this caller * asked Harness, and the caller is about to put a question to a human about * it rather than paint it. * @returns the reading this pass produced. */ reread(): Promise; /** Abandon in-flight passes; their results would repaint a closed browser. */ dispose(): void; /** * Adopt a pass's result when it is still the newest one. * @param generation - the pass's stamp. * @param next - what it read. */ private settle; /** * Read every surface once and join them. * @returns the complete reading. */ private gather; /** * Join one directory entry with the registry, its settings section, and its * credential. * @param entry - the configurable-provider directory entry. * @param active - route keys an adapter has registered. * @param descriptors - every namespace descriptor, keyed by namespace. * @param credentials - the credential seam, when one is mounted. * @returns the row. */ private providerRow; } /** * What one route's settings section says about its credential. * * The whole of Connect's credential reading for a single route, extracted so * the first-launch check reaches it without gathering the browser's entire * listing — that pass calls `listModels` for every active route to count * models, which is the one thing a startup check must not do. * * Reads the reference through the namespace's own schema role, never a field * name: `credential-ref` is the contract, and both shipped adapters calling it * `apiKeyEnv` is a coincidence this must not depend on. * @param descriptor - the owning namespace's descriptor, when it has one. * @param settingsPath - path from that section's root to the route's profile. * @param credentials - the credential seam, when one is mounted. * @returns the reading; never the secret itself. */ export declare function readRouteCredential(descriptor: SettingsDescriptorRead | undefined, settingsPath: readonly string[], credentials: ConnectCredentials | undefined): Promise; /** One route's readiness, and the reference the verdict was reached through. */ export interface ConnectRouteReadiness { /** Whether the route's credential is present, missing, or unestablished. */ readonly readiness: ConnectReadiness; /** The reference the route names, when it names one. */ readonly ref: string | undefined; } /** * Read the readiness of ONE route, and nothing else. * * Deliberately narrow: the directory and the registry are synchronous * in-memory reads, `settings.describe()` is in-memory too, and * `credentials.describe()` on the shipped local provider is a map lookup over * a snapshot loaded once at mount. No endpoint is contacted, and no other route * is examined. The catalog is not consulted here: its membership is advisory, * and exact model validity remains a Harness adapter responsibility. * * Total by construction. A provider nothing registered, a route the directory * does not declare configurable, and an absent settings or credential seam all * answer `unknown`, because none of them is evidence that a credential is * missing. * @param seams - the Harness seams. * @param provider - the route key to judge. * @returns its readiness and the reference behind it. */ export declare function readRouteReadiness(seams: ConnectSeams, provider: string): Promise; /** * A message for a failure, without leaking an object's shape into a row. * @param error - whatever was thrown. * @returns the sentence to show. */ export declare function messageOf(error: unknown): string; /** * Whether a rejected write lost a revision race. * * Recognized by the published `code` property, never by importing the error * class: this frontend consumes Harness through type-only imports, and a wire * layer that maps `SETTINGS_CONFLICT` to its own taxonomy is exactly the * caller this stable code exists for. Any other failure — including a refusal * carrying no code — answers false and is reported verbatim. * @param error - whatever a `settings.mutate` rejection carried. * @returns true when the namespace moved since the descriptor was read. */ export declare function isSettingsConflict(error: unknown): boolean; /** * Re-read whenever something Connect renders could have changed underneath it. * * Four feeds, because Connect joins four surfaces and each can move on its * own: `llm/adapters-updated` fires when a settings write activates or retires * a route, `settings/document-updated` fires on any namespace edit — the * official web Models page, a hand-edited patch, or another terminal — and * `credentials/reference-updated` / `credentials/record-updated` fire when a * key is stored, cleared, or a sign-in completes anywhere in the process. All * five are registered * unconditionally: a deployment mounting none of the optional seams simply * never fires them, which is what keeps this function correct without asking * which services are present. * * One microtask coalesces a burst into a single pass. A single settings write * commonly fires `settings/document-updated` alongside a credentials event, and * `setApiKey` writes settings and then a credential in the same action; * refreshing once after the burst settles is what a reader actually wants, * not a rendering read per event fighting the one the action's own call * already scheduled. * @param ctx - context carrying the model registry and the other seams' event * vocabulary, once anything in the process has imported their types. * @param catalog - the catalog to refresh. * @returns the disposer removing every subscription. */ export declare function watchAdapters(ctx: Context, catalog: ConnectCatalog): () => void; //# sourceMappingURL=catalog.d.ts.map