/** * What Harness says about provider configuration, as rows a terminal can draw. * * Every value here is a join of facts four Harness surfaces already publish. * Nothing is inferred from a provider's name, and nothing is remembered between * reads: Connect owns no provider registry, no credential cache, and no idea of * which providers "exist" beyond the directory the mounted adapters declare. * * The two row kinds are deliberately NOT merged. A configurable provider is a * route that configuration can activate; an authorization flow is a * conversation that obtains a credential. Harness publishes no correlation * between them — a flow's `CredentialKey` is scoped by its owning plugin's * registered name, which is not the directory entry's `settingsNs` by contract * — so joining them would be the frontend inventing a relationship, the same * mistake Work refuses when it keeps jobs and subagents apart. Both are listed, * each addressed by the identity Harness gave it. * * {@link ConnectSignInLink} is the one thing that narrows, and it narrows the * claim rather than the refusal. This module still derives no link — it holds * a field a presentation module may FILL, for the one adapter family that * documents the correspondence on both sides of it (see * {@link "./pi-ai.ts".piAiSignInRoute}). Every sign-in whose link nobody * established reads exactly as it did before the field existed, which is what * keeps "we do not know" the default rather than a special case. * @module dshline/connect/model */ import type { AuthorizationMethodRead, CredentialInfoRead, CredentialRecordInfoRead } from './harness.ts'; /** Where one configurable route stands with the model registry. */ export type ConnectRouteState = /** An adapter has registered the route; `/model` can already offer its models. */ 'active' /** Configuration describes a profile, but no adapter registered the route. */ | 'configured' /** Declared configurable, with nothing configured for it yet. */ | 'dormant'; /** What Connect knows about one route's credential, without ever holding one. */ export interface ConnectCredentialReading { /** * Profile property that carries a credential reference, taken from the * namespace's own schema role rather than from a field name this frontend * knows. Undefined when the schema declares none, which is what makes * "set an API key" unavailable rather than a guess. */ readonly field: string | undefined; /** The reference that property currently names, when the profile names one. */ readonly ref: string | undefined; /** What the credential seam says about that reference; never its value. */ readonly info: CredentialInfoRead | undefined; } /** One configurable provider route, joined across the surfaces that describe it. */ export interface ConnectProviderRow { /** Discriminant, so one list can carry both row kinds. */ readonly kind: 'provider'; /** Route key `GenerateOptions.provider` takes. */ readonly provider: string; /** Human-readable name the owning adapter chose. */ readonly displayName: string; /** Settings namespace whose section configures this route. */ readonly settingsNs: string; /** Path from that section's root to this route's profile. */ readonly settingsPath: readonly string[]; /** Whether the adapter knows this route only because configuration declared it. */ readonly declared: boolean | undefined; /** Configuration diagnostic retained by the adapter for repair. */ readonly error?: string; /** Where the route stands with the model registry. */ readonly state: ConnectRouteState; /** Models the route advertises, when it is active and could be listed. */ readonly models: number | undefined; /** The credential reading for this route. */ readonly credential: ConnectCredentialReading; /** Whether the user layer alone carries this profile, so removing it restores the base. */ readonly userOwned: boolean; /** The namespace revision this row was read at, for a conflict-checked write. */ readonly revision: number | undefined; } /** * The provider route one sign-in authenticates, when a presentation module for * a known configuration domain has established the correspondence. * * A plain data shape, and — like {@link ConnectNewRouteTarget} — not a claim * this module makes. Nothing here derives a link from a key's spelling: the * only producer is a presentation module that read one adapter family's own * documented identity (`pi-ai.ts`'s {@link "./pi-ai.ts".piAiSignInRoute}), and * a sign-in with no such producer keeps `route: undefined` and is presented * exactly as it was before this field existed. * * It exists because the alternative is worse than the refusal it relaxes. A * credential record and a settings profile are separate writes to separate * stores, so a successful sign-in leaves `/model` offering nothing until the * route is ALSO activated — and with the two rows asserting nothing about each * other, the only thing on screen after a successful login was a row that said * "signed in" beside a route that said "not active", with no stated relation * between them. Naming the relation where it is documented is what turns that * into an answerable question. */ export interface ConnectSignInLink { /** Route key the sign-in's credential authenticates. */ readonly provider: string; /** Where that route stands with the model registry, at the same reading. */ readonly state: ConnectRouteState; } /** One registered authorization flow, joined with the record it writes. */ export interface ConnectSignInRow { /** Discriminant, so one list can carry both row kinds. */ readonly kind: 'sign-in'; /** The `/` credential record this flow writes. */ readonly key: string; /** User-facing name of what is being authorized. */ readonly label: string; /** The methods this flow offers, most preferred first. */ readonly methods: readonly AuthorizationMethodRead[]; /** Whether an attempt for this key is running right now. */ readonly inFlight: boolean; /** What the credential seam says about the record; undefined when unreadable. */ readonly record: CredentialRecordInfoRead | undefined; /** * The route this sign-in authenticates, when a presentation module * established the link. Undefined is the ordinary case and asserts nothing. */ readonly route: ConnectSignInLink | undefined; } /** * The one entry point for declaring a route nothing lists yet. * * Shown once, at the foot of the provider section, only when a presentation * module for a known configuration domain — `llm-pi-ai`'s * {@link "./pi-ai.ts".piAiDeclarationTarget}, today — has confirmed it can * actually service a write there. Its label is generic on purpose — "custom * provider", never a namespace name — so this row stays something * `overlay.ts` can render without knowing which domain produced it; deciding * whether one CAN be produced is deliberately not this module's job. A * schema shaping a namespace's routes as a `dict` proves only that arbitrary * keys are structurally accepted, never that writing one declares a new LLM * route — that is a fact about one namespace's semantics, not about schema * shape in general, so it is asserted only inside the presentation module * that actually knows it. */ export interface ConnectCreateRow { /** Discriminant, so one list can carry all three row kinds. */ readonly kind: 'create'; /** What the row says: "Add custom provider". */ readonly label: string; /** Every address a new route could be declared at, in directory order. */ readonly targets: readonly ConnectNewRouteTarget[]; } /** Any of the three row kinds the browser lists. */ export type ConnectRow = ConnectProviderRow | ConnectSignInRow | ConnectCreateRow; /** * One address where a brand-new provider route can be declared. * * A plain data shape, not a claim: nothing in this module asserts that any * particular namespace can be written to this way, or derives one from schema * shape alone. A target is only ever produced by a presentation module that * has already confirmed, using knowledge specific to the one domain it * presents, that it can carry out the write end to end. */ export interface ConnectNewRouteTarget { /** The namespace a new route's profile would be written into. */ readonly settingsNs: string; /** Path from that namespace's section root to the dict holding every route. */ readonly parentPath: readonly string[]; /** The namespace revision this target was read at, for a conflict-checked write. */ readonly revision: number | undefined; } /** Which of the optional seams this deployment mounts. */ export interface ConnectCapabilities { /** Whether a settings provider is mounted, so profiles can be written. */ readonly settings: boolean; /** Whether a credential provider is mounted, so keys can be stored. */ readonly credentials: boolean; /** Whether the authorization seam is mounted, so sign-ins can run. */ readonly authorization: boolean; } /** What one gathering pass produced. */ export type ConnectState = /** The first read has not landed yet. */ { readonly kind: 'loading'; } /** Harness could not answer; the message is its own. */ | { readonly kind: 'failed'; readonly message: string; } /** A complete reading. */ | { readonly kind: 'ready'; readonly providers: readonly ConnectProviderRow[]; readonly signIns: readonly ConnectSignInRow[]; readonly capabilities: ConnectCapabilities; readonly newRouteTargets: readonly ConnectNewRouteTarget[]; }; /** Something Connect can ask Harness to do for one row. */ export type ConnectActionId = /** Run the row's authorization flow. */ 'sign-in' /** Delete the credential record a flow wrote. */ | 'sign-out' /** Store an API key behind this route's credential reference. */ | 'set-key' /** Forget the value behind that reference. */ | 'clear-key' /** Write a minimal profile so the adapter registers the route. */ | 'activate' /** Remove the user layer's profile for this route. */ | 'deactivate' /** * Open the curated editor for a route's endpoint, protocol, and model * catalog. Never offered by {@link rowActions} itself — no generic seam * publishes which profile fields are worth curating — but a presentation * module for one known configuration domain may add it for the rows that * domain owns. */ | 'edit-route'; /** One offered action, already worded for a picker. */ export interface ConnectAction { /** Which action this is. */ readonly id: ConnectActionId; /** The row label. */ readonly label: string; /** The second line, explaining what Harness will do. */ readonly description: string; } /** * How confidently a provider row's credential posture can be stated. * * Three states rather than two, because "we cannot tell" is a real answer here: * a deployment without a credential provider, or a route that authenticates * through its provider's own ambient discovery, is not misconfigured. Only a * reference the seam confirms is missing earns the negative mark — the same * rule the official Models page applies to its dots. Provider diagnostics are * displayed separately and do not change this credential readiness judgement. */ export type ConnectReadiness = 'ready' | 'missing' | 'unknown'; /** * Whether one row answers a typed query. * * Matched against what the row SHOWS, which is the whole contract of a filter: * a reader who cannot see why a row matched cannot trust the ones that did not. * @param row - the row. * @param query - raw query text. * @returns true when the row should stay visible. */ export declare function matchesRow(row: ConnectRow, query: string): boolean; /** * Apply a query to rows, preserving Harness's declaration order. * * Order is never re-ranked. The directory's order is the owning adapters' * registration order, and a frontend that re-sorted it would be inventing a * preference no adapter expressed. * @param rows - the rows. * @param query - raw query text. * @returns the matching rows, in their original order. */ export declare function filterRows(rows: readonly T[], query: string): readonly T[]; /** * How many rows the top-level Connect browser can select in one unfiltered reading. * * The one definition of the browser's row set, shared by its counter and by * Setup's decision to offer a handed-off `/connect`. It counts browser ROWS, * never available actions: a provider or sign-in row whose action picker has * nothing to offer is still a row the reader can move to and select, which is * why neither this function nor its callers is named for configuration or * remediation. * * The three arrays do not add up one-for-one. Every declarable target is * attached to the single synthetic "Add custom provider" row the browser * draws, so `newRouteTargets` contributes one whether it holds a single entry * or many; nothing may multiply the total by its length. * @param state - the current reading. * @returns the number of selectable rows; zero until a reading lands. */ export declare function connectSelectableCount(state: ConnectState): number; /** * Read the credential readiness for a provider row. * * A provider diagnostic remains separate from this credential judgement; a * `ready` result does not validate the selected model. * @param row - the provider row. * @returns the credential readiness mark. */ export declare function providerReadiness(row: ConnectProviderRow): ConnectReadiness; /** * The readiness judgement itself, over the route state and credential. * * Split out from {@link providerReadiness} so a caller holding those two facts * without a whole row — the first-launch check, which reads ONE route rather * than the browser's whole listing — reaches the same verdict through the same * code. A second implementation of route readiness is exactly the duplicated * authority this domain exists to avoid. * * The two `unknown` answers are the load-bearing ones, and neither is a * fallback. A route naming NO reference authenticates through its provider's * own discovery or a stored sign-in — an `llm-pi-ai` route activated by OAuth * has no `apiKeyEnv`, because that field carries no schema default — and a * reference the store could not answer for is unread, not unset. Both are * supported postures, so both stay unmarked rather than being called a fault. * @param state - where the route stands with the model registry. * @param credential - what was read about the reference it names. * @returns the readiness mark. */ export declare function readinessOf(state: ConnectRouteState, credential: ConnectCredentialReading): ConnectReadiness; /** * The right-hand column of a provider row: its state, then what qualifies it. * * Whole facts, joined with a separator the row's renderer may drop from the * left. Each is something a surface asked Harness rather than concluded. * @param row - the provider row. * @param capabilities - mounted seams, when the caller can determine whether activation is offered. * @returns the facts, most important first. */ export declare function providerFacts(row: ConnectProviderRow, capabilities?: ConnectCapabilities): string[]; /** * The indented facts under a selected provider row. * @param row - the provider row. * @returns one line's worth of facts, in decreasing usefulness. */ export declare function providerDetail(row: ConnectProviderRow): string[]; /** * The indented facts under a selected sign-in row. * @param row - the sign-in row. * @returns one line's worth of facts. */ export declare function signInDetail(row: ConnectSignInRow): string[]; /** * The right-hand column of a sign-in row. * @param row - the sign-in row. * @returns the facts, most important first. */ export declare function signInFacts(row: ConnectSignInRow): string[]; /** * The reference a route would store a typed key under, when its profile names * none yet. * * `_API_KEY` is the convention the official Models page derives, and * matching it is the point: a key stored from the terminal must be the same * reference the web UI would read, or the two surfaces would disagree about * whether the same provider is configured. * * A reference is a POSIX shell identifier, so a route id that cannot become one * — a leading digit survives every other check and then fails at the credential * seam with a raw regular expression — is refused here instead. * @param provider - the route key. * @returns the derived reference, or undefined when the id cannot name one. */ export declare function derivedCredentialRef(provider: string): string | undefined; /** * Whether a typed id could become a brand-new route at one declarable target. * * The grammar is the official Models page's own create-card rule, adopted * character for character rather than invented here: a route id is both a * settings dict key AND — through {@link derivedCredentialRef} — the stem of a * credential reference, which is a POSIX shell identifier and so cannot start * with a digit. A leading digit passes every other check a route id could face * and then fails at the credential seam with a raw regular expression the * reader cannot act on; refusing it here, where the field is still on screen, * is what that page's own card does. * @param id - the typed route id. * @param taken - route keys already declared at this target's namespace. * @returns why the id cannot be used, or undefined when it can. */ export declare function newRouteIdProblem(id: string, taken: ReadonlySet): string | undefined; /** * What Harness will let a reader do to one row, right now. * * Availability is derived from the seams and the row's own state, never from a * provider's identity: an action that is offered is one the owning surface has * already said it would accept, so a picker never lists a row that answers with * a refusal. * @param row - the selected row. * @param capabilities - which optional seams this deployment mounts. * @returns the offered actions, most useful first; empty when there are none. */ export declare function rowActions(row: ConnectRow, capabilities: ConnectCapabilities): ConnectAction[]; /** * Why a row offers nothing, when it offers nothing. * * A picker with no rows tells a reader only that they were ignored; naming the * missing capability tells them what their deployment would need. * @param row - the selected row. * @param capabilities - which optional seams this deployment mounts. * @returns the sentence to show instead of a picker. */ export declare function noActionsReason(row: ConnectRow, capabilities: ConnectCapabilities): string; //# sourceMappingURL=model.d.ts.map