@sema-agent/core
Version:
Stateless, task-oriented AI agent core
61 lines (60 loc) • 5.14 kB
TypeScript
import { type Session, type SessionCreateOptions, type SessionForkOptions, type SessionHead, type SessionMetadata, type SessionPlacementRecord, type SessionRepo, type SessionRow, type SessionRowExpectation, type SessionRowRead, type SessionTreeEntry } from "../harness/types.js";
import { type SessionRepoRowCells } from "./row-cells.js";
import { type HolderJudge, type StoreHolderFence } from "../../core/checkpoint-generation.js";
/** {@link InMemorySessionRepo}'s options. */
export interface InMemorySessionRepoOptions {
readonly rowCells?: SessionRepoRowCells;
/** The deployment's grant judge ({@link HolderJudge}): every storage this repo hands out judges the holder of each append and leaf
* move that carries one by it, first; with it the repo declares `fence = { holder: "writes" }`. */
readonly holderIsCurrent?: HolderJudge;
}
export declare class InMemorySessionRepo implements SessionRepo<SessionMetadata, SessionCreateOptions> {
private rows;
/** Each row's last touch (epoch ms). */
private touched;
/** Who holds the rows' occupant cells ({@link SessionRepoRowCells}): `"engine"` (absent) — this repo; `"host"` — the host's store. */
readonly rowCells: SessionRepoRowCells;
/** The holder declaration: present (`{ holder: "writes" }`) only on a repo given a judge. */
readonly fence?: StoreHolderFence;
private readonly holderIsCurrent;
constructor(options?: InMemorySessionRepoOptions);
create(options?: SessionCreateOptions): Promise<Session>;
open(metadata: SessionMetadata): Promise<Session>;
/** The row's head off the one row that IS it: every cell comes from that row, so a delete and re-create of the id while this reads
* cannot mix two generations. */
headOf(sessionId: string): Promise<SessionHead | undefined>;
/** {@link SessionRepo.placementOf}: the row's placement cell, off its metadata alone (its log is never read). A subclass that keeps its rows
* somewhere other than `this.rows` overrides this with `headOf` / `readRow` — an answer read from the wrong place says "unplaced" for a placed
* row, and the owner's delete then removes the placement row. */
placementOf(sessionId: string): Promise<SessionPlacementRecord | undefined>;
/** The row in one synchronous read: its metadata, its head and a copy of its log, from the one row that is it. */
readRow(sessionId: string): Promise<SessionRowRead | undefined>;
/** Every row, with its last {@link touch} as its activity time where it has one. This repo hands its sessions' storages out and never
* sees their writes (an entry's own `timestamp` is the writer's data, not the time of the write), so a row never touched carries none
* and a reader takes its `createdAt`. */
list(): Promise<SessionRow[]>;
/** Record activity on the row now (a missing row: nothing to record). The time lives and dies with the row: `delete` drops it. */
touch(sessionId: string): Promise<void>;
/** Remove the row; with `expect`, only the row the expectation names, judged and removed in one synchronous step. */
delete(metadata: SessionMetadata, expect?: SessionRowExpectation): Promise<void>;
fork(sourceMetadata: SessionMetadata, options: SessionForkOptions & SessionCreateOptions): Promise<Session>;
/** 2c session-sync: the FULL log for export — {@link readRow}'s log (InMemory holds everything, no F3 floor: the full oldest-first log
* with `id`/`parentId` verbatim). A missing row is `not_found`. */
exportEntries(sessionId: string): Promise<SessionTreeEntry[]>;
/** 2c session-sync: import a verbatim log into `sessionId`. The single invariant gate runs first
* ({@link validateEntriesForImport}, fail-closed); then, in one synchronous step, the row standing now is judged — the expectation
* (`options.expect`, {@link sessionRowMatches}) and the write law (`importRowCells`: a new row records `owner`, an existing row keeps its
* metadata whole and must already be `owner`'s) — and the log replaced; the head answered is the new row's.
* design/171: the operator's trusted-import flag is forwarded to the gate that persists — see
* SessionRepo.importEntries. */
importEntries(sessionId: string, owner: string | undefined, entries: SessionTreeEntry[], options?: {
preserveActorAssertions?: boolean;
expect?: SessionRowExpectation;
}): Promise<SessionHead>;
/** {@link SessionRepo.recordOwner}: the row judged and its owner recorded in one synchronous step, on the storage every handle of the row
* holds — the row object is not replaced, so a session handed out before the write keeps writing to the row and reads the recorded owner. */
recordOwner(sessionId: string, owner: string, expect: SessionRowExpectation): Promise<SessionHead | undefined>;
/** Lay a row down under its id: one storage, one session over it, and the metadata as this repo holds it ({@link heldRowCells}),
* frozen — every write that lays a row down comes through here, so no row holds a cell its mode does not. */
private lay;
}