UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

102 lines (101 loc) • 9.47 kB
/** * Does a string START or END with white space — the very reading the name rule's last clause (`edge_whitespace` of {@link judgePrincipalName}) takes * and the clause the refusal sentence is made of, over the same set (ECMAScript's `\s`: the characters `String#trim` takes off). `starts` — its * first character is white space; `ends` — its last is (a string of white space only does both; the empty string neither). Only the EDGES are read: * white space inside a string is not asked, and nothing else of the name rule (visible content, length, characters, well-formedness) is. For a * reader whose input is wider than a principal name — a stored name an earlier release wrote, a filter target, a key that may carry a reserved * prefix — and that must still agree with the name rule on what an edge of white space is, instead of keeping a second definition of it. */ export declare function whiteSpaceAtEdgesOf(raw: string): { readonly starts: boolean; readonly ends: boolean; }; /** Does a string hold an unpaired surrogate — the name rule's `ill_formed` clause, asked alone? The one reading of it for every key a store * names a partition by (a scope, a session id, a rule bucket's owner): UTF-8 spells such a half as U+FFFD, so the key would name another * key's partition. U+FFFD itself is well-formed text and is not asked here. */ export declare function holdsUnpairedSurrogate(raw: string): boolean; /** The refusal sentence of a key {@link holdsUnpairedSurrogate} refuses: `what` names the parameter; the value itself is never repeated. */ export declare function unpairedSurrogateRefusal(what: string): string; /** The longest name any face keeps, in UTF-16 units (what `String#length` counts; an astral character is two): the principal's name rule * and the box's name spelling (a receipt id, a lease owner, a decision move's holder) read this one number. It only ever widens, and a * widening is announced one release before the release that makes it — a host sizes its columns by it and by {@link PRINCIPAL_NAME_MAX_BYTES}. */ export declare const PRINCIPAL_NAME_MAX_CHARS = 256; /** The most UTF-8 bytes a string the judge admits can take: a UTF-16 unit encodes as at most three bytes (U+0800–U+FFFF; a pair of * surrogates is two units and four bytes), so {@link PRINCIPAL_NAME_MAX_CHARS} units are at most three times as many bytes. Derived, never * restated; the width of a column that is measured in bytes. It moves only with {@link PRINCIPAL_NAME_MAX_CHARS}: only wider, announced * one release ahead. */ export declare const PRINCIPAL_NAME_MAX_BYTES: number; /** Why a value is not a principal name — one word per clause of the rule, in the order the judge asks them: `not_a_string` (the value is * not a string), `blank` (nothing is left once white space and the format characters are taken away — the empty string included), * `too_long` (more than {@link PRINCIPAL_NAME_MAX_CHARS} UTF-16 units), `refused_character` (a control character, a line or paragraph * separator, or a format character other than the two joiners), `ill_formed` (an unpaired surrogate), `edge_whitespace` (white space as * the first or the last character). The first clause a value fails is the word it gets. A clause joins the rule at the END of this list: * the clauses from `ill_formed` on are the ones an earlier release did not ask ({@link recordedPrincipalNameOf} reads past them), so each * is the word only of a string every older clause admits. */ export declare const PRINCIPAL_NAME_REFUSALS: readonly ["not_a_string", "blank", "too_long", "refused_character", "ill_formed", "edge_whitespace"]; export type PrincipalNameRefusal = (typeof PRINCIPAL_NAME_REFUSALS)[number]; /** The judge's answer: the name as written, or the word ({@link PrincipalNameRefusal}) and a clause for a refusal sentence (`fault`, for a * person to read: what kind of value or string it is). */ export type PrincipalNameVerdict = { readonly ok: true; readonly name: string; } | { readonly ok: false; readonly reason: PrincipalNameRefusal; readonly fault: string; }; /** THE judgment of a principal's name — every face that takes one, and every reading below, asks this. */ export declare function judgePrincipalName(raw: unknown): PrincipalNameVerdict; /** The name rule as one clause for a refusal sentence that restates it ("must be a principal name (…)"): said once, so a face that spells the * rule out never drifts from {@link judgePrincipalName}. */ export declare const PRINCIPAL_NAME_SPELLING = "a string with a visible character and no white space at either end, no control, line or paragraph separator character, no format character but a joiner, no unpaired surrogate, and at most 256 characters"; /** The stored-name reading as one clause for a refusal sentence (what {@link recordedPrincipalNameOf} admits), said once for every guard. */ export declare const RECORDED_PRINCIPAL_NAME_SPELLING = "a principal name (a string with a visible character and no white space at either end, no control, line or paragraph separator character, no format character but a joiner, no unpaired surrogate, and at most 256 characters), or one whose only faults are an unpaired surrogate or white space at an end (an earlier release wrote such names)"; /** * Does the string have VISIBLE content — something left once white space and every Unicode format character (the joiners, the zero-width * spaces, the bidirectional controls, the byte order mark) are taken away? The first clause of a name, read here once so that every face * that keeps a name as an opaque key (a mailbox's receipt id, lease owner and holder) and every face that needs the whole name rule * ({@link principalNameOf}) read "blank" the same way: a string of nothing but joiners is blank to both. */ export declare function hasVisibleContent(raw: string): boolean; /** The name, or `undefined` when the value is none ({@link judgePrincipalName}'s verdict, read as a value). */ export declare function principalNameOf(raw: unknown): string | undefined; /** * The name a STORED cell holds, or `undefined`: what a store reads back from a row, a marker or a record it wrote, and a name that only * points at an identity rows are already filed under — a re-key's or an adoption's source, a delete guard's owner (compared with the row's * owner cell by string equality in the engine, so it matches exactly the rows that hold that string). It is {@link judgePrincipalName}'s * verdict where a word from {@link NEWER_CLAUSES_FROM} on — `ill_formed`, `edge_whitespace`: clauses that joined the rule at its end, so * each is the word only of a string every older clause admits — still reads as the name: a release before the clause admitted that string * and wrote it, and reading the row as corrupt, or refusing its owner's delete, would lose it. Every older refusal refuses here as at a * door. Never the reading of a name a caller hands in to become an identity or act as one (a new row's owner, a move's target, the * principal a caller asks as — even one equal to a stored owner), nor of one a backend matches rows by (a UTF-8 backend would match the * U+FFFD spelling, a space-padding one `alice` for `alice `): that is {@link principalNameOf}. */ export declare function recordedPrincipalNameOf(raw: unknown): string | undefined; /** What a value offered as THE principal of a task or of a lookup is — read once, here, so no face decides it on its own. */ export type PrincipalReading = { readonly kind: "name"; readonly name: string; } | { readonly kind: "absent"; } | { readonly kind: "invalid"; readonly fault: string; }; /** * A principal offered to a face that tolerates having none: `name` (a principal name), `absent` (no principal — `undefined`, and the * empty string, which the task door and the bucket resolvers have always spelled the same), or `invalid` (it was PROVIDED and is not a name). Only absence reaches * the unauthenticated floor, or the declared local owner's bucket; an invalid value is a bad value, refused where a principal is taken * (never read as absence — a caller who appends one invisible character to a principal must not become the machine owner). */ export declare function readPrincipal(raw: unknown): PrincipalReading; /** A STORED identity member — a checkpoint row's principal or isolation scope, an inherited rule key's principal — as the principal it * names: {@link readPrincipal}, with a stored `null` (a SQL twin's empty column) absence too. The one reading of such a member: the row * verdict judges a checkpoint's by it, a resume reads the judged one by it, an inherited rule key is spelled by it. */ export declare function readStoredPrincipal(raw: unknown): PrincipalReading; /** The name a JUDGED stored identity member holds, `undefined` for its absence ({@link readStoredPrincipal}). The row verdict refuses * a row holding any other value before a resume reads one, so meeting one here is an engine defect: thrown, never read as absence. */ export declare function judgedStoredPrincipalOf(raw: unknown): string | undefined; /** Why a value is not a principal name, as a clause for a refusal sentence: the kind of string it is, or the type of the value * ({@link judgePrincipalName}'s `fault`; a value that is a name reads `a principal name`). */ export declare function principalNameFault(raw: unknown): string;