/** * Curated presentation for one known configuration domain: `llm-pi-ai`. * * Every other module in this directory is generic — it reads what * `LlmConfigurableProvider`, a settings descriptor, or a credential reference * publishes, and holds no adapter's field names. That stays true for WHICH * routes exist, whether one is active, and where its credential lives (the * `credential-ref` schema role in {@link "./schema.ts"}). It stops being true * for a curated route editor: "endpoint", "protocol", and "model catalog" are * not roles any generic seam publishes, so presenting them at all means * knowing a specific namespace's field names. * * `llm-pi-ai` is that one namespace today — the adapter whose settings profile * can describe a provider route wholesale, per * `@deepseek-ai/dsh-llm-pi-ai`'s `PiAiProviderProfile`. This module names the * fields it curates (`displayName`, `baseURL`, `api`, `headers`, `models`, * `modelOverrides`, and each model's `name`/`contextWindow`/`maxTokens`/ * `input`/`reasoningEfforts`) as plain strings and reads/writes them through * the same generic `ctx.settings` path ops every other Connect action uses. It * does not import the pi-ai package at runtime, does not register providers, * does not parse model output, and does not perform network I/O — Harness still * does every one of those. What lives here is only the knowledge of which * fields, out of the many `PiAiProviderProfile` now has, are worth a terminal * form in this pass. * * `headers` earns its place for the same reason the route fields have it: it * decides what a route can REACH. A gateway that authenticates with anything * other than the one field carrying the `credential-ref` role — a tenant * header, a signed proxy token, a routing tag a corporate egress requires — is * otherwise unreachable from the terminal, and the route has to be finished by * hand in `settings.yaml`. The per-model capabilities earn theirs for the * complementary reason: they are what a deployment must be able to STATE, and * no listing states all of them. At the adopted generation discovery reports a * model's input modalities when the installed catalog knows them, but an * endpoint-interrogated route reports none and no listing reports a model's * reasoning-level wire spellings, so both fields stay editable. `compat`, * `retryPolicy`, and the operational budgets still stay out. * * Which of those fields exist, and every CHOICE or VOCABULARY one offers, comes * from the namespace's own serialized schema rather than a list written here — * see {@link routeModelSchema}. The field NAMES are the knowledge this module * is allowed to hold; their shapes are the owner's to publish. * * The protocol CHOICES this module offers are not hard-coded even though the * field name is: `protocolChoices` reads the `api` field's own schema node and * takes the strings out of a `union` of `const`s, which is exactly how * `dsh-llm-pi-ai` builds that field (`z.union(supportedProtocols())`). A future * protocol needs no dshline change; a schema that stops shaping the field this * way degrades to no offered choices rather than a stale list. * {@link headersCurated} is the same discipline for `headers`: the field is * offered only while the schema still shapes it as a dict of strings, so a * namespace that reshapes it gets no header editor instead of a write it would * refuse. * * {@link piAiDeclarationTarget} owns a second piece of Harness-specific * knowledge for the same reason: no generic seam publishes "this namespace * accepts a route key it has never seen," so deciding whether `+ Add custom * provider` can be serviced AT ALL has to live here too, gated on the same * namespace check plus the schema shapes the rest of this module already * depends on. `connect/model.ts` stays generic; it never claims that shape is * a declaration contract on its own. * * {@link piAiSignInRoute} is the third, and the one that reaches furthest: * which provider route a given sign-in actually authenticates. `model.ts` * refuses that join in general and is right to — Harness publishes no * contract that a flow's credential scope and a directory entry's namespace * must correspond. But `dsh-llm-pi-ai` publishes it for ITSELF, in prose, on * both sides: `recordKeyFor(providerId)` documents its parameter as "pi-ai's * own provider id, which is also the harness route key", and * `directoryEntries` puts that same id at `providers.` in this namespace. * Reading one adapter family's own documented identity is what this module is * for; asserting it of adapters in general is what `model.ts` refuses. * @module dshline/connect/pi-ai */ import type { LlmConfigurableProvider } from '@deepseek-ai/dsh-llm'; import type { SettingsDescriptorRead, SettingsPathOp } from './harness.ts'; import type { ConnectAction, ConnectCapabilities, ConnectNewRouteTarget, ConnectProviderRow } from './model.ts'; import type { LeafAcceptance } from './schema.ts'; /** The one namespace this module knows how to present curated fields for. */ export declare const PI_AI_NAMESPACE = "llm-pi-ai"; /** `PiAiProviderProfile` field names this pass curates; see the module note for why only these. */ export declare const DISPLAY_NAME_FIELD = "displayName"; export declare const BASE_URL_FIELD = "baseURL"; export declare const API_FIELD = "api"; export declare const HEADERS_FIELD = "headers"; export declare const MODELS_FIELD = "models"; export declare const MODEL_OVERRIDES_FIELD = "modelOverrides"; /** * `PiAiModelProfile` fields this pass curates, in either a `models` entry or a * `modelOverrides` value. The two sites share every field but the id's home, so * one set of names serves both. */ export declare const NAME_FIELD = "name"; export declare const CONTEXT_WINDOW_FIELD = "contextWindow"; export declare const MAX_TOKENS_FIELD = "maxTokens"; export declare const INPUT_FIELD = "input"; export declare const REASONING_EFFORTS_FIELD = "reasoningEfforts"; /** Whether a route row belongs to the one domain this module presents. */ export declare function isPiAiNamespace(settingsNs: string): boolean; /** * One model entry's `reasoningEfforts` exactly as `llm-pi-ai` accepts it: * `false` disables reasoning, and a dict maps each offered level to its wire * spelling (or `null` for "supported, send no wire value"). WHICH levels may * carry `null` is the namespace owner's semantic rule, not this module's — the * schema's leaf shape is the only thing read here. */ export type ReasoningEffortsValue = false | Record; /** One `PiAiModelProfile` entry, exactly as this pass curates it — never the whole shape. */ export interface CuratedModelFields { readonly id: string; readonly name: string | undefined; readonly contextWindow: number | undefined; readonly maxTokens: number | undefined; /** Declared modalities, or undefined to inherit. An empty list is read back as absent. */ readonly input: readonly string[] | undefined; /** The declared reasoning capability, or undefined to inherit the installed catalog's. */ readonly reasoningEfforts: ReasoningEffortsValue | undefined; } /** * One per-model field this pass curates, named by its profile key. * * The union is the write vocabulary: a `modelOverrides.` edit addresses * exactly one of these paths, so the type is what keeps an override edit from * becoming a whole-object rewrite that could carry a stale sibling back. */ export type ModelCuratedField = typeof NAME_FIELD | typeof CONTEXT_WINDOW_FIELD | typeof MAX_TOKENS_FIELD | typeof INPUT_FIELD | typeof REASONING_EFFORTS_FIELD; /** Every curated model field, in the order a form writes them. */ export declare const CURATED_MODEL_FIELDS: readonly ModelCuratedField[]; /** * One curated field's current value, read off a curated view. * * The single place the field-name union meets the value object, so a caller * diffing or writing fields never re-enumerates them. An absent value stays * `undefined`, which is the "inherit/unset" spelling a path op uses. * @param fields - the curated view of an entry or override. * @param field - the field to read. * @returns the field's JSON-compatible value, or undefined when unset. */ export declare function curatedFieldValue(fields: CuratedModelFields, field: ModelCuratedField): unknown; /** * The curated fields the row-editor form shows, out of whatever a raw model * entry actually carries. * * Every other property on the entry — `compat`, anything a future pi-ai * release adds — is read past here rather than discarded: {@link mergeModelEntry} * is what carries them forward. * @param raw - one element of the profile's `models` array, whatever shape it is. * @returns the curated view, or undefined when the entry has no usable `id`. */ export declare function curatedModelFields(raw: unknown): CuratedModelFields | undefined; /** * The curated view of one `modelOverrides.` value, whose id is the dict key. * * The same field reading as {@link curatedModelFields} without requiring an * `id` in the value — an override carrying one is refused by `llm-pi-ai`, so a * hand-edited profile's stray key is read past rather than trusted. A * non-object value still yields an id-only view rather than vanishing: a stored * override the adapter cannot serve must stay visible for repair. * @param id - the dict key. * @param raw - the override value, whatever shape it is. * @returns the curated view. */ export declare function curatedOverrideFields(id: string, raw: unknown): CuratedModelFields; /** * The profile's raw `models` array, exactly as stored. * * An absent key and `[]` are the same request in `llm-pi-ai`: the schema * materializes `[]` for the absent case, and an empty catalog could serve no * request anyway, so both mean "serve the installed catalog". A caller * therefore asks whether the array has entries, never whether the key exists. * A non-empty array is the profile's explicit replacement for that catalog. * @param profile - the profile value at a route's `settingsPath`. * @returns the raw entries, or undefined when the field is not an array. */ export declare function rawModels(profile: unknown): readonly unknown[] | undefined; /** * The profile's raw `modelOverrides` dict, exactly as stored. * * Only a catalog route with no explicit `models` list may carry one, and each * key is an installed model id whose entry this overrides field by field. A * non-object answers an empty dict, which is the same "no overrides" the * absence means. * @param profile - the profile value at a route's `settingsPath`. * @returns the raw overrides, keyed by model id. */ export declare function rawModelOverrides(profile: unknown): Record; /** * The profile's raw `headers` object, exactly as stored. * * Unlike `models`, absent and empty mean the same thing here: nothing inherits * a header set, so a route with no `headers` key and a route with `{}` both * send none. That is why the editor unsets the field rather than writing an * empty object — see {@link unsetHeadersOp}. * @param profile - the profile value at a route's `settingsPath`. * @returns the raw value, or undefined when the field is unset or not an object. */ export declare function rawHeaders(profile: unknown): unknown; /** One model entry's field availability and vocabularies, derived from the schema alone. */ export interface ModelEntrySchema { /** Whether the entry still declares a `name` string. */ readonly name: boolean; /** `contextWindow` bounds when it is still a constrained number; undefined otherwise. */ readonly contextWindow: { min?: number; step?: number; } | undefined; /** `maxTokens` bounds when it is still a constrained number; undefined otherwise. */ readonly maxTokens: { min?: number; step?: number; } | undefined; /** Schema-derived modality vocabulary; empty when the field is not offered. */ readonly input: readonly string[]; /** Schema-derived reasoning-level vocabulary; empty when the field is not offered. */ readonly reasoningLevels: readonly string[]; /** Whether the schema still offers `reasoningEfforts: false`. */ readonly reasoningCanDisable: boolean; /** * What one level's mapping VALUE accepts, derived from the dict's element * schema. `undefined` means the leaf is not a primitive (`union` of them) * this form can render, so the mapping editor fails closed rather than * guessing; an all-false record means the leaf accepts nothing. */ readonly reasoningWire: LeafAcceptance | undefined; } /** Which model-catalog shapes one route's schema still describes. */ export interface RouteModelSchema { /** Whether `models` is still an array of entry objects. */ readonly models: boolean; /** Whether `modelOverrides` is still a dict of entry objects. */ readonly overrides: boolean; /** The shared entry field set, when either site is still readable. */ readonly entry: ModelEntrySchema | undefined; } /** * The model-catalog shapes one route's schema describes right now. * * Every choice and vocabulary a model form needs is read from here rather than * written down in this module: a pi-ai release that adds a modality, a thinking * level, or a new entry field is presented without a dshline change, and a * schema that stops describing one disables that control instead of writing a * value the namespace would refuse. The field NAMES are the one thing this * module is allowed to know, for the same reason `protocolChoices` knows `api`. * @param schema - the `llm-pi-ai` namespace's serialized schema. * @param routePath - path to the route's profile. * @returns the readable shapes; all absent when the schema cannot be walked. */ export declare function routeModelSchema(schema: unknown, routePath: readonly string[]): RouteModelSchema; /** * Merge curated edits onto whatever a model entry already carried. * * The retained object is the source of unknown-field survival: spreading it * first and the curated fields second keeps `compat`, `headers`, and anything * else this pass does not render, while still letting a curated edit win. A * curated field cleared back to undefined is deleted rather than written as * `null` or literal `undefined` — `settings.mutate` accepts only JSON-compatible * data, and a stored `null` would read back as configured-to-nothing rather * than as inherited. * @param retained - the entry's previous raw shape, when one existed. * @param curated - the fields the editor changed. * @returns the entry to write, JSON-compatible. */ export declare function mergeModelEntry(retained: Record | undefined, curated: CuratedModelFields): Record; /** * Merge curated edits onto a `modelOverrides.` value. * * The id lives in the dict key, so a value carrying its own is refused by * `llm-pi-ai` — this strips one a hand-edited profile may have stored as well * as the `id` {@link mergeModelEntry} always stamps, so an override can never * carry a stray rename. * @param retained - the override's previous raw shape, when one existed. * @param curated - the fields the editor changed. * @returns the override value to write, JSON-compatible. */ export declare function mergeOverrideEntry(retained: Record | undefined, curated: CuratedModelFields): Record; /** * Wire protocols the `api` field's own schema currently offers. * @param schema - the `llm-pi-ai` namespace's serialized schema. * @param routePath - path to the route's profile (an existing route's * `settingsPath`, or a new route's `[...parentPath, id]` — a `dict` node * answers the same shape for a key it has never seen). * @returns the offered protocol strings, in schema order; empty when the * schema does not shape the field as a union of string consts. */ export declare function protocolChoices(schema: unknown, routePath: readonly string[]): string[]; /** * Whether this route's `headers` field is still shaped as a map of text. * * The same fail-closed reading {@link protocolChoices} makes, for the same * reason: the field NAME is knowledge this module is allowed to hold, but its * SHAPE is the schema's to publish, and a namespace that reshaped it — dropped * it, made its values structured — must produce no header editor rather than a * form whose write `settings.mutate` would refuse. A route whose schema this * walk cannot read at all answers false for the same reason. * @param schema - the `llm-pi-ai` namespace's serialized schema. * @param routePath - path to the route's profile (an existing route's * `settingsPath`, or a new route's `[...parentPath, id]`). * @returns true when the field can be curated as a dict of strings. */ export declare function headersCurated(schema: unknown, routePath: readonly string[]): boolean; /** One field-level change to a route's curated, non-model profile. */ export interface CuratedFieldChange { readonly field: string; /** The new value, or undefined to unset the field back to inherited/absent. */ readonly value: string | undefined; } /** * Path ops for a set of curated field changes against an EXISTING route. * * One op per changed field, each addressed under the route's own path — never * a wholesale replace, so a sibling field this pass does not render (`compat`, * `retryPolicy`, `thinkingBudgets`, …) is untouched by construction rather than * by care taken while building a bigger object. * @param routePath - the route's `settingsPath`. * @param changes - the fields that changed, already diffed against the read profile. * @returns the ops, in the order given. */ export declare function fieldOps(routePath: readonly string[], changes: readonly CuratedFieldChange[]): SettingsPathOp[]; /** * One op replacing a route's whole `models` array. * @param routePath - the route's `settingsPath`. * @param entries - the entries to write, already merged by {@link mergeModelEntry}. * @returns the op. */ export declare function setModelsOp(routePath: readonly string[], entries: readonly Record[]): SettingsPathOp; /** * One op replacing a route's whole `headers` map. * * Whole rather than per-header, unlike {@link fieldOps}: the editor renders * every pair the field holds, so there is no unrendered sibling to preserve * here — and a per-key write would need a matching `unset` for each removal, * which is more ops to say the same thing. * @param routePath - the route's `settingsPath`. * @param headers - the map to write; never empty, see {@link unsetHeadersOp}. * @returns the op. */ export declare function setHeadersOp(routePath: readonly string[], headers: Record): SettingsPathOp; /** * The op that removes a route's request headers entirely. * * `unset`, never `set` with `{}`, and for the opposite reason to * {@link unsetModelsOp}'s: an empty header map and an absent one are the same * route — nothing inherits headers — so writing `{}` would leave a key in * `settings.yaml` that says nothing the absent key did not already say. * @param routePath - the route's `settingsPath`. * @returns the op. */ export declare function unsetHeadersOp(routePath: readonly string[]): SettingsPathOp; /** * The op that resets a route's model catalog back to its owning adapter's. * * `unset`, never `set` with `[]`. The two are the same request to `llm-pi-ai` — * the schema materializes `[]` for the absent case, so both mean "serve the * installed catalog" — but only `unset` removes the key, leaving a * `settings.yaml` that says what it means instead of an empty array a reader * has to know is equivalent. * @param routePath - the route's `settingsPath`. * @returns the op. */ export declare function unsetModelsOp(routePath: readonly string[]): SettingsPathOp; /** * One op creating a whole `modelOverrides.` that did NOT exist at open. * * Deliberately not the general edit path. An override the route already * carried is edited field by field through {@link setOverrideFieldOp}, because * only the fields a reader actually touched may be written — a whole-object * `set` would carry the open-time copy of every field it never rendered back * over a concurrent edit. There is no sibling to preserve on the id's first * appearance, so one whole-value `set` is the honest spelling for it. * @param routePath - the route's `settingsPath`. * @param id - the installed model id, which is the dict key. * @param value - the override value, already merged by {@link mergeOverrideEntry}. * @returns the op. */ export declare function setNewOverrideOp(routePath: readonly string[], id: string, value: Record): SettingsPathOp; /** * One op addressing exactly one curated field of an existing override. * * The narrowest owned path the settings seam can express, so a conflict-time * second save reapplies only what the reader edited and leaves every other * field — curated or unknown — at whatever the current revision holds. An * undefined value unsets the key, which is how a field is returned to * inheritance rather than stored as `null`. * @param routePath - the route's `settingsPath`. * @param id - the installed model id. * @param field - the curated field to write. * @param value - the field's value, or undefined to unset it. * @returns the op. */ export declare function setOverrideFieldOp(routePath: readonly string[], id: string, field: ModelCuratedField, value: unknown): SettingsPathOp; /** * The op that removes one installed-catalog model's override. * * `unset` on the exact id, so removing the last override leaves an empty dict * the schema reads as "no overrides" — no whole-dict write that could drop a * sibling this pass never showed. * @param routePath - the route's `settingsPath`. * @param id - the installed model id. * @returns the op. */ export declare function unsetOverrideOp(routePath: readonly string[], id: string): SettingsPathOp; /** Every curated field a brand-new route's profile may set. */ export interface NewRouteProfile { readonly displayName: string | undefined; readonly baseURL: string; readonly api: string; /** Request headers the form collected; omitted from the write when empty. */ readonly headers: Record; readonly models: readonly CuratedModelFields[]; /** The schema-discovered credential-reference field, when the schema names one. */ readonly credentialField: string | undefined; readonly credentialRef: string | undefined; } /** * One `set` op declaring a brand-new route, whole. * * Unlike an edit, a new key has no prior value to preserve a sibling of, so * one op is the whole write — the same reason {@link activateRoute} in * `actions.ts` writes a single object for a route that does not exist yet. * @param routePath - `[...parentPath, id]` for the new route. * @param profile - the fields the create form collected. * @returns the op. */ export declare function createRouteOp(routePath: readonly string[], profile: NewRouteProfile): SettingsPathOp; /** * The one action `rowActions` cannot offer: opening the curated editor. * * `model.ts` stays generic on purpose, so "edit route" is not one of its * offers — no seam publishes which fields are worth curating for a route in * general. This is the one place that gap is closed, and only for the * domain this module presents: a row from any other namespace gets nothing * added, and falls back to whatever `rowActions` already offered. * @param row - the selected provider row. * @param capabilities - which optional seams this deployment mounts. * @returns zero or one action, to append to `rowActions`'s own offer. */ export declare function extraActions(row: ConnectProviderRow, capabilities: ConnectCapabilities): ConnectAction[]; /** * Where a brand-new `llm-pi-ai` route could be declared, when this module can * actually service the declaration end to end. * * Five things have to hold, and any one failing means the schema drifted from * what this presentation module knows how to read — the honest answer is to * offer nothing rather than a `+ Add custom provider` row that is guaranteed * to fail partway through the wizard, which is exactly the "never offer an * action known to fail" rule the rest of Connect already follows: * * 1. every existing `llm-pi-ai` directory entry agrees on where its dict of * routes sits — disagreement means there is no one address to assume for a * route that does not exist yet; * 2. the schema shapes that address as a `dict`, so an unseen key answers the * same shape as an existing one; * 3. the curated `baseURL` field is still reachable there; * 4. the curated `models` field is still reachable there too — * {@link "./route-editor.ts".runCreateRoute} always writes one, so a schema * that stopped describing it would accept the row and then fail the write; * 5. the `api` field is still a union of string consts this module can offer * as protocol choices — this is deliberately the same schema-shape check * {@link protocolChoices} makes, because a namespace this module cannot * offer a protocol for is one it cannot safely declare a route into either. * * A credential-reference field is deliberately NOT on this list. Its absence * is a supported state — a route with nowhere to store a key still has an * endpoint, a protocol, and a model list — so `runCreateRoute` reads it itself * and adjusts what it asks for, rather than this gate disabling creation * outright over a field only the API-key step needs. What it must never do is * accept a typed key it then has nowhere to put; see the note on * {@link "./route-editor.ts".runCreateRoute} for how that is kept from * happening. * * This is where the one Harness-specific fact this module knows — that * `llm-pi-ai` is a domain whose settings profile can describe a whole * provider route — is allowed to matter. A schema merely SHAPING a dict of * objects is not that fact by itself: a future adapter could publish * `providers: dict` while still only recognizing a fixed set * of keys, and nothing about that shape alone would say otherwise. Restricting * this check to entries already known to belong to `llm-pi-ai` is what keeps * the inference honest rather than reading "arbitrary keys are structurally * accepted" as "arbitrary keys declare a new LLM route." * @param directory - every configurable-provider entry Harness published. * @param descriptors - every namespace descriptor, keyed by namespace. * @returns the one target this module can service, or undefined. */ export declare function piAiDeclarationTarget(directory: readonly LlmConfigurableProvider[], descriptors: ReadonlyMap): ConnectNewRouteTarget | undefined; /** * The scope of the credential records this adapter family's authorization * flows write. * * Spelled as its own constant even though it is the same string as * {@link PI_AI_NAMESPACE}, because it is a different fact about a different * store. `RECORD_SCOPE` in `dsh-llm-pi-ai`'s `auth.ts` is documented as "the * plugin's registered name", and the plugin's `export const name` happens to * equal the settings namespace it installs. Two facts that agree today are * still two facts: folding them into one constant would quietly turn a * coincidence into an assumption, and the day upstream renames one the join * below should stop matching rather than address the wrong route. */ export declare const PI_AI_RECORD_SCOPE = "llm-pi-ai"; /** * The provider route one `llm-pi-ai` sign-in actually authenticates. * * `connect/model.ts` refuses to join the two row kinds in general, and stays * right to: a flow is addressed by a `CredentialKey` whose scope is its * owning plugin's registered name, a directory entry by `settingsNs` plus a * route key, and Harness publishes no contract that the two must correspond. * That refusal is about the GENERAL case. For the one domain this module * already presents, upstream states the correspondence outright: * `registerPiAiFlows` keys every flow it registers at * `recordKeyFor(providerId)` — `/` — where * `recordKeyFor`'s own parameter documentation calls `providerId` "pi-ai's own * provider id, WHICH IS ALSO THE HARNESS ROUTE KEY", and `directoryEntries` * publishes that same id as `provider` at `providers.` in this * namespace. * * So this is a reading of one adapter family's documented identity, not an * inference from shape — which is exactly the kind of knowledge this module * exists to hold and `model.ts` exists not to. It is also verified rather * than assumed: a key is only ever resolved against routes the directory * ACTUALLY published, so a scope that stopped naming this namespace, an id * outside it, or a namespace that started addressing its routes somewhere * other than `providers.` all answer undefined and leave the sign-in * standing alone, exactly as it does today. * @param key - the sign-in's `/` credential record address. * @param providers - every provider row the same reading produced. * @returns the route this sign-in authenticates, or undefined when nothing * published here can be said to correspond to it. */ export declare function piAiSignInRoute(key: string, providers: readonly ConnectProviderRow[]): ConnectProviderRow | undefined; //# sourceMappingURL=pi-ai.d.ts.map