UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

43 lines (42 loc) • 3.05 kB
import type { SessionStorage } from "../session.js"; import type { LegWrites } from "./contracts.js"; /** What a leg's write view holds the moment it closes ({@link LegWrites.close}). */ export type LegWritesAtClose = ReturnType<LegWrites["close"]>; export type { LegWrites }; export declare class SessionWriteLedger { #private; /** A leg's view. `report` receives the incidents (a refused write, a late settlement); a throwing sink is swallowed. */ openLeg(report: (err: Error, sessionId: string) => void): LegWrites; /** * The session's next hold starts here: resolves once `sessionId` has no write in flight, and throws `SessionError("conflict")` * — the leg about to start has written nothing — when one is still unsettled after `ms`. */ settleBeforeHold(sessionId: string, ms: number): Promise<void>; /** * Whether `sessionId` has a write in flight — a synchronous read. The session's next holder asks it before {@link settleBeforeHold} * and awaits only on `true`: a session with nothing in flight takes no suspension point at its hold. The two reads sit on one tick, * and nothing joins the set between the check and the hold's return — the previous holder's view is closed before its lock is * released, the lock serialises holders, and a holder that is no leg (the rewind verb) issues no write through a view. */ busy(sessionId: string): boolean; /** * Resolves `true` once `sessionId` has no write in flight, `false` when `ms` elapse first. The timer is not unref'd: the * caller awaits this in foreground control flow (the teardown-bounded discipline), and it is cleared on settle. */ drained(sessionId: string, ms: number): Promise<boolean>; } /** * THE stamp of a writer's grant holder on its session writes: the two write members are called with the holder added to their options * (`SessionWriteOptions.holder`), every other member is the storage's own. The options handed on are a plain object built here, the * caller's `expectedLeafId` read once into it — never the caller's object, so nothing the caller passed runs code between the store's * judgement and its write. Per writer and non-mutating (a Proxy). A run's leg and the out-of-run session verbs install it the same * way, only when they carry a holder; a leg an engine lane started carries none to stamp. */ export declare function stampHolder(storage: SessionStorage, holder: string): SessionStorage; /** * The acquired storage as a leg writes it: the two write members go through `leg.issue` (named by the entry type, `leaf` for a * leaf move, with the leaf the session is on once it lands — `leafIdAfterEntry` of the entry, the target of a leaf move — and the * entry's parent; a leaf move, appended or set, carries none), every other member is the storage's own. Per leg and non-mutating * (a Proxy), like the conflict watch above it. */ export declare function writesThroughLeg(storage: SessionStorage, leg: LegWrites, sessionId: string): SessionStorage;