UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

72 lines (71 loc) • 4.7 kB
/** * The selector: the one reading that picks, for a catalog message, the variant a run receives — and decides * whether an overlay's `when` applies to this run (every source class alike). Four dimensions, each with exactly one * writer, so no value ever needs a precedence order: * * - `traits` — derived from the run's two prompt-shape axes by {@link promptTraitsOf} (the prompt profile and the * fable-family model); catalog data reads traits, never the axes. * - `host` — `role` (which role base the run is assembled for; `TaskSpec.promptRole`, absent ⇒ `general`) and * `form` (`TaskSpec.promptForm`, which every engine-built child receives through the parent spec seat; absent ⇒ * `standard`). * - `facts` — the runtime facts prepare produces (one derived: `executionEnvironmentDeclared`). * - `binding` — the deployment's scenario name (`TaskSpec.promptBinding`, an open vocabulary; absent ⇒ none). * * A `when` is a conjunction: every listed trait present, every `noneOf` trait absent, every host key equal, every * fact equal, the binding inside its `anyOf` (or outside its `noneOf`). No disjunction across dimensions. */ import type { PromptManifestSelectors } from "../core/trace.js"; import { type CatalogMessage, type FactConjunction, type HostForm, type HostRole, type PromptFactName, type PromptTrait, type Variant, type VariantWhen } from "./catalog/schema.js"; import type { PromptRuntimeFacts } from "./types.js"; /** The run's selector values, resolved once per assembly. */ export interface PromptSelectors { readonly traits: ReadonlySet<PromptTrait>; readonly host: { readonly role: HostRole; readonly form: HostForm; }; readonly facts: Readonly<Record<PromptFactName, boolean>>; readonly binding?: string; } /** * The run's prompt traits, derived from the two prompt-shape axes the engine resolves today: the simple * profile is `lean_prompt`, a fable-family model is `fable_5_mitigations`. This is the only place those * axes become traits. */ export declare function promptTraitsOf(facts: Pick<PromptRuntimeFacts, "promptProfile" | "fableMitigations">): ReadonlySet<PromptTrait>; /** The predicate facts a condition may test; optional runtime facts read as false when absent. */ export declare function catalogFactsOf(facts: PromptRuntimeFacts): Readonly<Record<PromptFactName, boolean>>; /** * The host selector's two values as their one writer gave them: the task (`TaskSpec.promptRole` / * `TaskSpec.promptForm`; an engine-built child's spec carries its parent's form through the parent spec seat). * A value outside the closed set is refused by name (`config.prompt_selector_invalid`), never read as the default. */ export declare function resolveHost(task: { readonly promptRole?: unknown; readonly promptForm?: unknown; }): { readonly role?: HostRole; readonly form?: HostForm; }; /** The run's selectors — their one mint: traits and facts from the runtime facts, the host from its two writers' values, * the binding as the task's door validated it. */ export declare function selectorsOf(facts: PromptRuntimeFacts, host?: { readonly role?: HostRole; readonly form?: HostForm; }, binding?: string): PromptSelectors; /** The selectors' plain form (traits sorted): what the manifest shows, the identity's `binding` element digests and the * `prompt.compose` event carries — one record. */ export declare function selectorRecordOf(s: PromptSelectors): PromptManifestSelectors; export declare function factsHold(conj: FactConjunction | undefined, facts: Readonly<Record<PromptFactName, boolean>>): boolean; /** Whether a `when` holds under the run's selectors. */ export declare function whenHolds(when: VariantWhen | undefined, s: PromptSelectors): boolean; /** * A `when` in its normal form — the one spelling of what it asks: every list sorted and without repeats, a conjunct that * asks nothing (an empty `traits`, `host` or `facts`, an empty list) left out, and a condition left with no conjunct * (`{}`) is no condition at all (`undefined`). Two conditions that hold in the same runs by construction are equal as * values here, so the overlay door (`validateOverlay`) hands every reader — the artifact digest, the publish-side * conflict check — the same condition. Idempotent; it never changes which runs a condition holds for. */ export declare function canonicalWhen(when: VariantWhen | undefined): VariantWhen | undefined; /** The variant this run receives, or undefined when no variant's `when` holds (the message is absent). */ export declare function selectVariant(message: CatalogMessage, s: PromptSelectors): Variant | undefined;