@sema-agent/core
Version:
Stateless, task-oriented AI agent core
50 lines (49 loc) • 3.19 kB
TypeScript
/**
* The read-back judge of a stored rule-offer list: the {@link RuleOffer} array core mints beside an approval
* (`AskRequest.ruleOffers`, a parked row's `pendingAction.ruleOffers`). Core mints the shape, so its reading lives
* here; a backend or a surface that reads the list back calls {@link readRuleOffers} instead of keeping a schema of
* its own. Display caps (how many offers, members or detail rows a surface shows) stay with the surface.
*/
import { type RuleOffer } from "./permission-rule-model.js";
/**
* Why a stored rule-offer value, or one element of it, is not read:
* · `not_an_array` — the value itself (present, and not a list): no element is read;
* · `unknown_word` — a closed-set member holds a word this engine does not know: the offer `kind`, a batch member's
* `kind`, a `match`, a `cautions` word (a newer minter, or another writer);
* · `malformed` — not an object, a member missing or of the wrong type, a batch with no members, an uncovered count
* that is not a non-negative safe integer.
* The first defect in reading order names the element's problem.
*/
export declare const RULE_OFFER_SHAPE_PROBLEMS: readonly ["not_an_array", "unknown_word", "malformed"];
export type RuleOfferShapeProblem = (typeof RULE_OFFER_SHAPE_PROBLEMS)[number];
/** One element read. `index` is its position in the stored list — the selection key a card and its redemption keep. */
export interface RuleOfferRead {
readonly index: number;
/** A fresh object holding only the members the type declares (additive members the minter wrote are not copied). */
readonly offer: RuleOffer;
/** Present when the batch's `uncoveredDetail` seat was not one well-formed row per counted segment and was left out
* (the count is the truth source and an absent seat claims nothing); the caller owes that loss a disclosure. */
readonly uncoveredDetailDropped?: true;
}
/** One element not read, and why. The rest of the list is read regardless. */
export interface RuleOfferDropped {
readonly index: number;
readonly problem: Exclude<RuleOfferShapeProblem, "not_an_array">;
}
/** {@link readRuleOffers}' answer. */
export type RuleOffersReading = {
readonly offers: readonly RuleOfferRead[];
readonly dropped: readonly RuleOfferDropped[];
} | {
readonly problem: "not_an_array";
};
/**
* Read a stored rule-offer list. `undefined` (the member absent) reads as no offers; any other non-list is
* `not_an_array`. Each element is judged alone and keeps its original index: an element that is not an offer this
* engine reads is dropped WHOLE (a batch with one unreadable member is dropped, never shortened — a conjunction one
* member short would render "yes to N" as "yes to N−1") and its siblings stand. Every member is read once.
* The input domain is a decoded JSON value or a list core minted: a value carrying accessors or a Proxy is outside it,
* and such a value may be refused as malformed or may throw while it is read. A record is a plain one
* ({@link isPlainRecord}, the reading the risk-descriptor axes take too).
*/
export declare function readRuleOffers(raw: unknown): RuleOffersReading;