/** * Reading a provider profile out of a namespace's serialized settings schema. * * This is the part of Connect that keeps it provider-neutral. The naive way to * offer "set an API key" is to write `apiKeyEnv` into the profile, which is * what the field happens to be called in both adapters shipped today — and is * exactly the hard-coded provider knowledge this frontend must not hold. * * Harness already publishes the answer. A settings namespace registers a * schemastery schema, and a field that carries a credential REFERENCE is * declared `z.string().role('credential-ref')` — `llm-pi-ai`, `llm-deepseek`, * and `web-search-deepseek` all mark theirs that way. `ctx.settings.describe()` * hands back `schema.toJSON()`, so the role travels with the descriptor and an * adapter that calls its field something else is served without a code change. * * The serialized form is `{ uid, refs }`: every node lives in `refs` under its * own uid, and a nested node appears as that uid rather than inline, because * schemastery preserves shared and recursive references. So walking it means * resolving a number at each step, which is all {@link resolveNode} does. * * The rest of this module is the same walk applied to SHAPE, not just names: * a union's string constants (a protocol or modality vocabulary), a dict's * declared key schema (a reasoning-level vocabulary), a dict's element schema * (what one mapping value accepts), a number's `min`/`step`, and which * properties exist at all. A caller decides what a field is CALLED; everything * about what it accepts comes from here, and a shape this walk cannot classify * answers "unreadable" so the caller can fail closed rather than guess. * @module dshline/connect/schema */ /** A serialized schemastery node, as far as this walk needs to understand one. */ export interface SchemaNode { /** Node kind: `object`, `dict`, `array`, `union`, `intersect`, `string`, `const`, … */ type?: string; /** UI and validation metadata, including the renderer role. */ meta?: { role?: unknown; }; /** `object` properties, keyed by property name. */ dict?: Record; /** `dict` and `array` element schema. */ inner?: unknown; /** A `dict`'s key schema; a plain string when the schema does not constrain keys. */ sKey?: unknown; /** `union` and `intersect` members. */ list?: readonly unknown[]; /** The one value a `const` node accepts. */ value?: unknown; } /** The serialized envelope `schema.toJSON()` produces. */ export interface SchemaEnvelope { /** Uid of the root node. */ uid: number; /** Every node reachable from the root, keyed by uid. */ refs: Record; } /** The role a settings schema marks a credential-reference field with. */ export declare const CREDENTIAL_REF_ROLE = "credential-ref"; /** * Resolve one node reference against the envelope's table. * * The exported companion to the private walk step, for a caller that needs to * inspect a node's members directly — a `union` whose branches it must classify * itself, rather than one of the fixed shapes the other helpers recognize. * @param reference - a uid, or an inline node. * @param envelope - the table every uid is looked up in. * @returns the node, or undefined when the reference resolves to nothing. */ export declare function resolveSchemaNode(reference: unknown, envelope: SchemaEnvelope): SchemaNode | undefined; /** One profile's node, kept with the table its children resolve through. */ export interface LocatedProfile { /** The profile's own serialized node. */ readonly node: SchemaNode; /** The envelope every nested uid is looked up in. */ readonly envelope: SchemaEnvelope; } /** * The schema node one configurable provider's profile is described by. * @param schema - the namespace's serialized schema. * @param path - `LlmConfigurableProvider.settingsPath`; empty means the section root. * @returns the profile's node and its table, or undefined when the schema does * not describe that path. */ export declare function profileNode(schema: unknown, path: readonly string[]): LocatedProfile | undefined; /** * Property names in a profile that carry a credential reference. * * Plural because nothing stops a schema declaring two; the caller takes the * first and Connect says which one it used rather than guessing which of * several a person meant. An intersection is flattened, since that is how a * schema composes a shared field set with a specific one. * @param located - the profile {@link profileNode} found. * @returns the property names, in declaration order. */ export declare function credentialRefFields(located: LocatedProfile | undefined): string[]; /** * The schema node for one named field of a located profile. * * The one step {@link profileNode} does not take: a profile's node answers * what the WHOLE route looks like, and a caller reading one field — the * credential reference is the other case, but it is found by role rather than * by name — still needs to descend into it by the field's own name. * @param located - the profile {@link profileNode} found. * @param field - the property name to descend into. * @returns the field's node, or undefined when the schema does not describe it. */ export declare function fieldNode(located: LocatedProfile | undefined, field: string): SchemaNode | undefined; /** * String choices a `union`-of-`const` node offers, when it is shaped that way. * * This is how a protocol picker learns its choices without importing anything * about the adapter that published them: `z.union(['a', 'b'])` serializes as a * `union` node whose `list` members are each a `const` node carrying one * string, and that shape is generic schemastery vocabulary, not knowledge of * any one namespace. A field the owning schema did not build this way (a plain * `z.string()`, say) answers with an empty list, which is this walk's honest * way of saying the schema offers no fixed choice — the caller falls back to * free text rather than inventing one. * @param node - the field's own node, typically found via {@link profileNode} * plus one more {@link descend} step onto the field name. * @param envelope - the table every uid is looked up in. * @returns the offered strings, in schema order; empty when the node is not a * union of string consts. */ export declare function unionConstStrings(node: SchemaNode | undefined, envelope: SchemaEnvelope): string[]; /** * Every value a `union`-of-`const` node accepts, whatever type the constants are. * * The typed companion to {@link unionConstStrings}: a schema may union a * non-string constant with a structured branch — `llm-pi-ai`'s * `reasoningEfforts` unions `const(false)` with a dict — and a caller deciding * which BRANCHES exist needs those values without assuming strings. * @param node - the union node. * @param envelope - the table every uid is looked up in. * @returns the constant values, in schema order; empty when some member is not * a `const` node. */ export declare function unionConstValues(node: SchemaNode | undefined, envelope: SchemaEnvelope): unknown[]; /** * The fixed key vocabulary a `dict` node describes, when it declares one. * * `z.dict(value, keys)` serializes the key schema at `sKey`; when that schema * is a union of string consts the dict admits exactly those keys, which is how * a reasoning-level vocabulary travels from the owning adapter to this * frontend without either side hard-coding it. A dict of open keys (a plain * `z.dict(z.string())`, say) or one this walk cannot read answers with an * empty list, the honest "no fixed vocabulary here" a caller falls back from. * @param node - the field's own node, typically a `dict`. * @param envelope - the table every uid is looked up in. * @returns the key strings, in schema order; empty when none are declared. */ export declare function dictKeyStrings(node: SchemaNode | undefined, envelope: SchemaEnvelope): string[]; /** * The one node a `dict` or `array` describes all of its entries with. * * A dict segment and an array index are both answered by a single element * schema, so this is the step that turns "the `models` field" into "one model * entry" or "the `modelOverrides` dict" into "one override value." * @param node - the `dict` or `array` node. * @param envelope - the table every uid is looked up in. * @returns the element node, or undefined for any other node kind. */ export declare function innerNode(node: SchemaNode | undefined, envelope: SchemaEnvelope): SchemaNode | undefined; /** * The numeric constraints a `number` schema declares, when it is one. * * `z.number().step(1).min(1)` serializes its bounds into `meta`; reading them * lets a form state the same floor the owning schema enforces instead of * discovering it at a refused write. A `number` with no recorded bounds * answers an empty object, and any non-number node answers undefined so a * caller can tell "a number field with no bounds" from "not a number field." * @param node - the field's own node. * @returns the declared `min`/`step`, or undefined when the node is not a number. */ export declare function numberConstraints(node: SchemaNode | undefined): { min?: number; step?: number; } | undefined; /** * Whether a `union` node offers one exact constant. * * The companion to {@link unionConstValues} for a caller that only needs to * know a branch EXISTS — `llm-pi-ai`'s `reasoningEfforts` offering `false` is * what makes an explicit "this model does not reason" state expressible. * @param node - the union node. * @param envelope - the table every uid is looked up in. * @param value - the constant to look for, compared by `Object.is`. * @returns true when some member is a `const` carrying that value. */ export declare function unionHasConst(node: SchemaNode | undefined, envelope: SchemaEnvelope, value: unknown): boolean; /** Which primitive JSON kinds one schema leaf accepts. */ export interface LeafAcceptance { /** Whether the leaf accepts a string. */ readonly string: boolean; /** Whether the leaf accepts a number. */ readonly number: boolean; /** Whether the leaf accepts a boolean. */ readonly boolean: boolean; /** Whether the leaf accepts `null`. */ readonly null: boolean; } /** * Which primitive kinds a leaf schema accepts, when it is one. * * The value-side companion to {@link dictKeyStrings}: `llm-pi-ai`'s * `reasoningEfforts` maps each offered level to `union([z.string(), * z.const(null)])`, and a form that means to edit a leaf as text-or-nothing * must learn that from the schema rather than from the field's name. A union * of recognizable primitives merges their kinds; a structured member, an * intersection, an `any`, or a node this walk cannot classify answers * `undefined`, which is how a caller fails closed instead of guessing at a * shape it does not understand. An empty union accepts nothing and answers the * all-false record rather than `undefined`. * @param node - the leaf node itself, typically a `dict`'s `inner`. * @param envelope - the table every uid is looked up in. * @returns the accepted primitive kinds, or undefined when the shape is unrecognized. */ export declare function leafAcceptance(node: SchemaNode | undefined, envelope: SchemaEnvelope): LeafAcceptance | undefined; /** * Whether a node is a `dict` whose elements are plain strings. * * The companion shape check to {@link unionConstStrings}, and generic * schemastery vocabulary for the same reason: `z.dict(z.string())` serializes * as a `dict` node whose `inner` is a `string` node, and a caller that means to * edit a field as a map of text needs to know the schema still describes it * that way. A field the owning schema shapes some other way answers false, so * the caller can offer no editor rather than write a value the namespace would * refuse. * @param node - the field's own node, typically from {@link fieldNode}. * @param envelope - the table every uid is looked up in. * @returns true when the node is a dict whose element schema is a string. */ export declare function isStringDict(node: SchemaNode | undefined, envelope: SchemaEnvelope): boolean; /** * Read one path out of a resolved settings value. * * Separate from the schema walk because they answer different questions: the * schema says which field COULD name a credential, and the value says which * one currently does. * @param value - a namespace's resolved value, or a layer of it. * @param path - the path to read. * @returns the value at that path, or undefined when the path is absent. */ export declare function valueAt(value: unknown, path: readonly string[]): unknown; //# sourceMappingURL=schema.d.ts.map