UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

38 lines (37 loc) • 2.63 kB
import { type MemoryPartitionIncidentSink, type SessionIdentityRead } from "./layout.js"; /** The seat's resolver shape ({@link createSessionIncarnationSeat}). */ export type SessionIncarnationResolver = (session: { sessionId: string; }) => string | undefined; /** * The resolver a Runner hands its engines, built from the ACQUIRED session's own row cells — the object * the run's transcript lives in, so the seat and the transcript never name two occupants (a second * lookup by id can answer a row that replaced it). `own` = that session's `incarnation`; a LINEAGE id * answers the occupant recorded with the lineage (`lineage`, e.g. the fork's `forkedFromIncarnation`), * never whoever holds that id now. Everything else, and an absent own token, is unknown (binds). */ export declare function sessionIncarnationResolver(sessionId: string, own: string | undefined, lineage: ReadonlyMap<string, string>): SessionIncarnationResolver; /** The current occupant's token, and the identity seat a per-session record read is made under. */ export interface SessionIncarnationSeat { incarnationOf(sessionId: string): string | undefined; identityRead(sessionId: string): SessionIdentityRead; } /** Build the seat over a resolver (absent ⇒ nothing stamped, nothing asked, every record binds * by id — the pre-incarnation answer). Both disclosures are DEDUPED on the axis their fact belongs to: the resolver * fault once per engine (a wiring fact), a separation once per session id (a fact about that id). */ export declare function createSessionIncarnationSeat(input: { resolve: SessionIncarnationResolver | undefined; onIncident: MemoryPartitionIncidentSink | undefined; }): SessionIncarnationSeat; /** Remember an in-process record under its session id, FIRST-WINS PER IDENTITY: this map is the * durable half's fallback exactly when the durable write failed, so keeping only the first * occupant's row would leave the next one unprotected on the one path it exists to cover. */ export declare function rememberForIdentity<T extends { incarnation?: string; }>(map: Map<string, T[]>, sessionId: string, record: T): void; /** The remembered record that BINDS `asking` ({@link sessionRecordBindsIncarnation}), if any. */ export declare function recalledForIdentity<T extends { incarnation?: string; }>(map: Map<string, T[]>, sessionId: string, asking: string | undefined): T | undefined; /** The first record remembered for `sessionId` by ANY occupant — for the id-blind faces. */ export declare function recalledForAnyIdentity<T>(map: Map<string, T[]>, sessionId: string): T | undefined;