@sema-agent/core
Version:
Stateless, task-oriented AI agent core
38 lines (37 loc) • 2.2 kB
TypeScript
import { type LeafEntry, type SessionMetadata, type SessionStorage, type SessionTreeEntry, type SessionWriteOptions } from "../harness/types.js";
/** Return the effective branch leaf after applying a session tree entry. */
export declare function leafIdAfterEntry(entry: SessionTreeEntry): string | null;
export declare abstract class BaseSessionStorage<TMetadata extends SessionMetadata = SessionMetadata> implements SessionStorage<TMetadata> {
private readonly metadata;
private readonly entries;
private readonly byId;
private readonly labelsById;
private leafId;
private readonly floorId;
protected constructor(metadata: TMetadata, entries: SessionTreeEntry[], leafId?: string | null, opts?: {
floorEntryId?: string | null;
});
/** The bounded-window root this storage was woken with, or null for a full-tree load (F3). */
getFloorId(): string | null;
getMetadata(): Promise<TMetadata>;
getLeafId(): Promise<string | null>;
protected createLeafEntry(leafId: string | null): LeafEntry;
createEntryId(): Promise<string>;
/**
* Optimistic-lock check (F2). Throws `SessionError("conflict")` when `opts.expectedLeafId` is
* provided and does not match the current in-memory leaf. Concrete `appendEntry`/`setLeafId`
* implementations call this before persisting; durable backends should instead perform the same
* check atomically against shared state (a conditional write) so concurrent instances can't fork.
*/
protected assertExpectedLeaf(opts?: SessionWriteOptions): void;
protected recordEntry(entry: SessionTreeEntry): void;
getEntry(id: string): Promise<SessionTreeEntry | undefined>;
findEntries<TType extends SessionTreeEntry["type"]>(type: TType): Promise<Array<Extract<SessionTreeEntry, {
type: TType;
}>>>;
getLabel(id: string): Promise<string | undefined>;
getPathToRoot(leafId: string | null): Promise<SessionTreeEntry[]>;
getEntries(): Promise<SessionTreeEntry[]>;
abstract setLeafId(leafId: string | null, opts?: SessionWriteOptions): Promise<void>;
abstract appendEntry(entry: SessionTreeEntry, opts?: SessionWriteOptions): Promise<void>;
}