@sema-agent/core
Version:
Stateless, task-oriented AI agent core
115 lines (114 loc) • 9.43 kB
TypeScript
/**
* What a USER row is — one vocabulary and one reading, behind `message_committed`'s `origin` / `inputId` / `noteKey` on a
* `role: "user"` frame AND behind the row itself as the session store keeps it: the row carries the fact, the frame says it.
*
* A `human_input` frame precedes the commit of the message it brings and cannot name that message's entry id, so a consumer
* used to join the two by stream order. That order is not a key: with a queued message leading the run and an interrupt before
* the first output, [queued message, objective] and [objective, interruption marker] are the same shape on the wire. And a
* reader of the store alone (a list's preview, a row's title) had no frame at all: a person's live steer, an interruption marker
* and an engine note were the same members on a stored row. So the row says what it is, and the commit frame reads the row.
*
* - `human_input` — the row IS a person's (or a relay's) input the `human_input` lifecycle arm accounts for; `inputId` is that
* arm's key. One row per key: an input that rode a merged message (below) has no row of its own.
* - `attachment` — a frame the engine minted for one of the input's declared attachments, trailing the input's message. It is part
* of the person's input, so it carries the same `inputId` as the objective's `human_input` frame (the key its own `attachment`
* record already holds); the origin tells the two rows apart — "the row of this input" is the `human_input` one. A frame whose
* record names an engine origin (a compaction's re-read, an instruction file) belongs to no declared input: it is a `queued_note`.
* - `interruption_marker` — the engine's own line that a person interrupted the run (turn-scoped or run-level). No `inputId`.
* - `queued_note` — every other engine-minted user-lane row: task notifications, boundary steers, the git frame, restated frames.
* No `inputId`. A task notification's row names its frame instead: `noteKey`, the durable key the frame was handed over under
* (`taskNotificationNoteOptions`, one set of options on every road the frame takes) — the row's `engineNoteKey`.
*
* THE RULE. The word is a member of the row (`UserMessage.origin`; a person's input row also `UserMessage.inputId`), written once,
* at the row's first commit point: the two mints that know more than the row's other facts say it as they mint — the harness for a
* person's input ({@link personInputRow}), the two interruption markers — and the leg's admission seat stamps every other user row
* ({@link stampUserRowOrigin}: its attachment record's, else `queued_note`) before the live context reads it again and before the
* store keeps it. The single reader is {@link userRowSourceOf}, for the commit frame and for a row read back from a store alike; the
* single judge of a value that claims to be a source is {@link judgeUserRowSource}. A row written before the member existed carries
* none and reads as no source — never as a word inferred from its other members (`provenance`, `engineMinted`, `engineNoteKey` say
* how derived views present a row, not who wrote it).
*
* WHERE A LEG BEGINS. A person's input row also says whether it is the first one its leg appended (`UserMessage.legFirstInput`): the
* row a leg's file-history boundary is keyed on when the leg records one, so "where did this leg begin" is read off the stored log,
* not re-derived from commit order. Written by the harness as its loop appends the row ({@link stampLegFirstInput}) — not at the
* mint, which a steer can reach before the objective it rides behind — and read by {@link legFirstInputOf} only.
*/
export declare const USER_ROW_ORIGINS: readonly ["human_input", "attachment", "interruption_marker", "queued_note"];
export type UserRowOrigin = (typeof USER_ROW_ORIGINS)[number];
/** Membership test for {@link UserRowOrigin}. */
export declare function isUserRowOrigin(v: unknown): v is UserRowOrigin;
/** What a user row states about itself, and what `message_committed` says of it: its origin, and the `human_input` key where the row
* belongs to one input (`human_input`: the input's own row; `attachment`: one of its attachment frames). */
export interface UserRowSource {
readonly origin: UserRowOrigin;
readonly inputId?: string;
/** Only beside `queued_note`, on a task notification's row: the frame's durable key (the row's `engineNoteKey`). */
readonly noteKey?: string;
}
/**
* Judge a claimed key: a non-empty string. The one reading of "a usable input key" on this path, shared by the harness mint
* (the key a person's row carries) and the commit frame's mint — a hollow key would join every unrelated row to one another.
*/
export declare function judgeInputId(inputId: unknown): string;
/** A key read off a stored record, when it is usable (a non-empty string); otherwise `undefined` — the row then states no key.
* For a value a persisted record hands over (a store that predates the key's rules is read as written, not re-validated). */
export declare function usableInputId(inputId: unknown): string | undefined;
/**
* Judge a claimed {@link UserRowSource}: `origin` a member of the closed set, `inputId` a non-empty string and only beside
* `human_input` or `attachment` (the other two origins are the engine's own rows, which belong to no input), `noteKey` a non-empty
* string and only beside `queued_note` (the one origin a handed-over frame's row reads as). Anything else is refused, never read as
* a neighbouring word — a source that is wrong here is a defect in the minting site, and a frame that quietly said something
* else would hand a consumer a false anchor.
*/
export declare function judgeUserRowSource(source: unknown): UserRowSource;
/** The members a person's input row is minted with: `origin: "human_input"` and, when the row is the one input a `human_input`
* frame accounts for, that frame's key (a resume's continuation merging parked steers carries none). A key that is given is
* judged ({@link judgeInputId}): a hollow one is refused at the mint. */
export declare function personInputRow(inputId?: unknown): {
readonly origin: "human_input";
readonly inputId?: string;
};
/**
* The admission seat's stamp: a user row that does not say what it is yet says it now — `attachment` when it carries the delivery
* record of an attachment a person declared (a record whose `origin` names the engine's own re-read or instruction file belongs to
* no declared input), else `queued_note`. A row that already carries an origin (a person's input, an interruption marker) keeps
* it; a row of another role is untouched. In place: the row is the object the live context and the store go on with.
*/
export declare function stampUserRowOrigin(row: {
role?: unknown;
origin?: unknown;
}): void;
/**
* The harness loop's stamp, as it appends a row: a person's input row that does not yet say whether it opened its leg says it now —
* `first` is whether the leg has appended no person-input row before this one. A row that already says (or one that is not a person's
* input row) is left as it is. Answers whether `row` is a person's input row, so the caller spends its leg's one first on it. In place:
* the row is the object the live context and the store go on with.
*/
export declare function stampLegFirstInput(row: {
role?: unknown;
origin?: unknown;
legFirstInput?: unknown;
}, first: boolean): boolean;
/**
* Whether a person's input row is the first one its leg appended (`UserMessage.legFirstInput`) — the one reading: the boundary seat
* begins on the row that answers `true`. `undefined` for a row that is not a person's input row and for one that states no boolean
* (written before the member existed): unknown, never read as `false`.
*/
export declare function legFirstInputOf(row: unknown): boolean | undefined;
/**
* Whether a stored row is a PERSON'S WORDS: a user row that carries no attachment record and whose source ({@link userRowSourceOf}) is
* `human_input` — or that has no `origin` member at all (written before the member existed: read as written, never as a word inferred
* from its other members). An engine row (`interruption_marker`, `queued_note`) and an attachment frame (part of a person's input, not its
* words) are not; nor is a row whose `origin` is a value this engine does not read (another engine's word, `null`): it claims a source,
* and a claim this engine cannot read is not taken as a person's. The one reading a rewind lands by: the target a rewind lands before.
* (Whether a person spoke AFTER a row a rewind's `lastSeenInput` names is another question — what the later rows state about themselves,
* {@link userRowSourceOf}: a row with no `origin` member is no evidence either way.)
*/
export declare function isPersonsWordsRow(row: unknown): boolean;
/**
* What a user row is, read off the row — the one reading, for the commit frame and for a row read back from a store. `undefined`
* for a row that states no origin (written before the member existed) and for a row of another role: absence is never read as a
* word. `human_input` names the row's own key, `attachment` its record's key, `queued_note` the frame key the row carries; a key
* that is not usable is no key.
*/
export declare function userRowSourceOf(row: unknown): UserRowSource | undefined;