UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

70 lines (69 loc) • 6.55 kB
import type { Model } from "../internal/llm.js"; import type { CheckpointErrorReason } from "./checkpoint-store.js"; import { type ReceiptMode } from "./mods/kernel/receive.js"; /** The arms of the roles family's refusal (`detail.reason` of `config.unknown_role`): a word the catalog does not hold, a value that is no model * reference at all, a role word outside the vocabulary, a role whose whole fallback chain supplies no model. Each is a member of the checkpoint * refusal reasons (the resume screen carries it on). */ export type ModelBindingReason = Extract<CheckpointErrorReason, "unknown_model_ref" | "not_a_model_ref" | "unknown_role_word" | "no_model_for_role">; /** * The coded refusal of a model binding the engine cannot read — a role's seat, a tier's binding, the model a task names, a catalog entry, a * role word outside the vocabulary (`field` names the seat as the sentence does, `reason` the arm). The ONE place the code and its `detail` * are built: a value that is no model reference at all, a word the catalog does not hold and a role word nothing holds are the caller's own * configuration faults, refused by the roles family's code with the seat and the arm beside it — never as the raw read the lookup would have * been (a `TypeError` from a value that is not an object, an uncoded lookup error). The terminal states the same `{ field, reason }`. */ export declare function modelBindingRefusal(field: string, reason: ModelBindingReason, message: string): Error; /** Whether a value is a list — total: a revoked Proxy traps even `Array.isArray`, and a refusal's own reading must not throw in its place. */ export declare function isList(value: unknown): value is unknown[]; /** A word in a refusal sentence, bounded and quoted; any other kind of value by its kind (rendering it could itself throw). */ export declare function bindingShown(value: unknown): string; /** The model door's mode of the one receipt: the declaration mode, with `headers` read per use. */ export declare const MODEL_RECEIPT_MODE: ReceiptMode; /** The catalog entry a Model is: the entry a request's reading was made from ({@link requestModelOf}), else the Model itself — * what a reader that asks "is this the very entry X" compares (the reasoning stamp names it), never the request's own object. */ export declare function modelEntryOf(model: Model): Model; /** Whether `value` is a Model the door minted. */ export declare function isModelSnapshot(value: unknown): value is Model; /** * The object a Model snapshot was received from — the read a host keys its own tables by when it compares an engine answer with * the Model objects it built (the engine hands back its snapshots, never the caller's objects). A value the door did not mint is * its own origin. */ export declare function modelOriginOf(model: Model): Model; /** Whether two Models hold the same data member for member — the interning's own test: a `headers` read port compared by its identity * and the object it is read on (the copy calls the caller's getter on that object), never read. */ export declare function sameModelData(a: Model, b: Model): boolean; /** * A second snapshot of `snapshot`: the same members (a `headers` read port carried as the same port, never read here), the same * origin, minted by the door so it is received as itself — and an identity of its own. The catalog door takes one for an entry * whose words, in a later catalog generation, resolve to a chain other than the one its snapshot already carries. */ export declare function forkModelSnapshot(snapshot: Model): Model; /** * The entry as ONE request reads it — what the model lane hands a hop's route judgment and its Brain, so that what is judged is * what is sent. A member read per use (`headers`) is read at its first read in the request and kept: every later read in the * request (the request build, a retry of it) answers that one reading, a getter that threw throws the same error again, and a bag * it answers is read once into a frozen copy of its own enumerable entries (as a request build reads a bag). A snapshot with no * member read per use is itself. Minted by the door with the snapshot's origin ({@link modelOriginOf}; {@link sameModelData} * holds), and an identity of its own per request — {@link modelEntryOf} answers the entry it was read from. */ export declare function requestModelOf(snapshot: Model): Model; /** * Receive a Model at `seat` (the place the caller wrote it, as every refusal names it; `what` is how the sentence names the value — a * Model object written there, or the catalog entry a word resolved to): its frozen snapshot, or the coded refusal. A snapshot comes * back as itself. The refusals: a value that is not a plain record (a Proxy, a class instance, `Object.create(x)`, a list, a primitive) or * holds a member the receipt cannot copy (a getter that threw, a function, another prototype) — `config.unknown_role` / * `not_a_model_ref`; a retired member — `config.deps_retired_key` (its own sentence); a member outside the contract — `not_a_model_ref` * (the refusal says a newer engine may know it, and offers `Model.params` only for a provider's own parameter); an `id` that is not a non-empty string or an `api` that is not a string — * `not_a_model_ref`, naming the member; a `defaultThinking` that is present but not one of the seven tiers — `not_a_model_ref`, naming * the member; a `fallbacks` that is present but not a list of non-empty strings — `not_a_model_ref`, naming the member; a * `mediaItemLimit` that is present but not a whole number of at least 1 — `not_a_model_ref`, naming the member; a * `compat.thinkingFormat` that is present, not `null` and not a chat-completions dialect name — `not_a_model_ref`, naming the member. * * `fallbacks` is a CATALOG member: its words are resolved by the catalog door over the catalog it receives * (`model-fallbacks.ts`), so only the catalog door's own receipt (`catalogEntry`: a catalog entry, a tier's model object) takes a * Model carrying it. Received anywhere else (a task's model object, a role's model object, an entry of a catalog the door did not * receive) it is refused, `config.model_fallback_invalid`: a chain nothing resolved would be a declaration nothing walks. A snapshot * comes back as itself either way — one carrying `fallbacks` was minted by the catalog door. */ export declare function receiveModel(value: unknown, seat: string, what?: string, note?: string, catalogEntry?: boolean): Model;