UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

33 lines (32 loc) • 3.06 kB
import type { SessionLogMark, SessionRowExpectation } from "../harness/types.js"; /** * Who holds a session row's two occupant cells, {@link SessionMetadata.incarnation} and {@link SessionMetadata.forkedFromIncarnation}: * - `"engine"` — the repo does: it mints the token in the write that creates a row, keeps it on every later write, and hands both cells * out on every read of the row (its sessions' metadata, its head, its listing). The default of every bundled repo. * - `"host"` — the host does, in a store of its own: the repo is a content repo. No write of it lays either cell down, no read of it * hands either out (a cell a row holds from an earlier engine-mode write is not read), and a conditional write is judged on the * owner and the log alone ({@link heldRowMatches}). The occupant every engine leg compares ({@link sameOccupant}) is then the * one the session store the host builds over the repo puts on the metadata its sessions answer and on its head read; a store * that hands this repo's rows out as they stand hands out rows naming no occupant, so `TtlSessionStore` refuses such a repo. * * One reading ({@link readSessionRepoRowCells}) and two laws: what a row holds ({@link heldRowCells}) and what a write may expect of it * ({@link heldRowMatches}). A repo reads its mode once and calls those two wherever a row is laid down, read back or judged. */ export type SessionRepoRowCells = "engine" | "host"; /** THE reading of a repo's {@link SessionRepoRowCells}: absent is `"engine"` (the cells are the repo's, as they always were); a value * outside the two words is refused `config.invalid_argument` naming `where`, never read as either. */ export declare function readSessionRepoRowCells(where: string, raw: unknown): SessionRepoRowCells; /** The row as a repo of `mode` holds it — what it writes and what it reads back: in `"engine"` mode the row as given; in `"host"` mode * the row without its two occupant cells, whatever the row was given or read with. */ export declare function heldRowCells<T extends { readonly incarnation?: unknown; readonly forkedFromIncarnation?: unknown; }>(mode: SessionRepoRowCells, row: T): Omit<T, "incarnation" | "forkedFromIncarnation">; /** {@link sessionRowMatches} as a repo of `mode` judges it. In `"host"` mode the row holds no occupant cell, so the owner and (when the log * binds) the log are what is judged, and an expectation that names an occupant token is refused (a `TypeError`): that question is the * host's, and this repo cannot answer it — read as a miss it would say the row was written since, read as a match it would say the * occupant was checked. An expectation that is not of the shape {@link SessionRowExpectation} is refused as `sessionRowMatches` refuses it. */ export declare function heldRowMatches(mode: SessionRepoRowCells, expect: SessionRowExpectation | undefined, row: { readonly owner?: string | null; readonly incarnation?: string | undefined; } | undefined, logNow: () => SessionLogMark): boolean;