@sema-agent/core
Version:
Stateless, task-oriented AI agent core
24 lines (23 loc) • 1.23 kB
JavaScript
import { BaseSessionStorage, storageBuiltWithJudge } from "./storage-base.js";
import { uuidv7 } from "./uuid.js";
export class InMemorySessionStorage extends BaseSessionStorage {
constructor(options) {
super(options?.metadata ?? { id: uuidv7(), createdAt: new Date().toISOString() }, options?.entries ? [...options.entries] : [], undefined, options?.floorEntryId !== undefined || options?.holderIsCurrent !== undefined
? { ...(options.floorEntryId !== undefined ? { floorEntryId: options.floorEntryId } : {}), ...(options.holderIsCurrent !== undefined ? { holderIsCurrent: options.holderIsCurrent } : {}) }
: undefined);
}
async setLeafId(leafId, opts) {
this.assertExpectedLeaf(opts, "setLeafId");
this.recordEntry(this.createLeafEntry(leafId));
}
async appendEntry(entry, opts) {
this.assertExpectedLeaf(opts, "appendEntry");
this.recordEntry(entry);
}
getResidence() {
return Object.freeze(storageBuiltWithJudge(this) ? { durability: "process-local", fence: Object.freeze({ holder: "writes" }) } : { durability: "process-local" });
}
recordOwnerCell(metadata) {
this.adoptRecordedOwner(metadata);
}
}