import type { EmittedEvent, EventLogReader, MoxxyEvent, MoxxyEventOfType, MoxxyEventType, Principal, TurnId } from '@moxxy/sdk'; export type EventListener = (event: MoxxyEvent) => void | Promise; export declare class EventLog implements EventLogReader { private readonly events; private readonly listeners; private readonly clearListeners; private readonly now; private principal; /** * Lazy secondary indexes so `ofType`/`byTurn` are O(matches) instead of an * O(n) full-array `filter` per call (these back hot paths: token-accounting's * `ofType('provider_response')`, lazy-tool gating's * `ofType('tool_call_requested')`, and remote-session's per-turn * `byTurn(turnId)` priming). Built lazily on first query so a cold/seeded log * pays the one-time O(n) build only if anything ever queries it, then kept * O(1) per append/ingest. Reset to `null` (rebuild-on-next-query) by * `clear`/`rebase`, which mutate `events` wholesale. * * Each index holds the SAME event object references in their original * append order — so a query returns an array deep-equal to the old * `events.filter(...)` for every input. */ private byType; private byTurnId; /** * Seq of the FIRST event this log holds. 0 for an authoring log; a mirror * primed by a partial attach replay (runner protocol v6 `replay.start`) * rebases to the first replayed seq so `ingest`'s contiguity gate lines up * with the runner's stream instead of expecting history we never received. * `seq === base + index` for every held event. */ private base; constructor(seed?: ReadonlyArray, opts?: { now?: () => number; }); get length(): number; /** Seq of the first held event (see {@link rebase}). */ get baseSeq(): number; at(seq: number): MoxxyEvent | undefined; slice(from?: number, to?: number): ReadonlyArray; /** Build both secondary indexes from the current `events` array, preserving * append order. Bucket arrays hold the original event references. */ private buildIndexes; /** Append one event to the live indexes (no-op while they're cold). Called * after the event is pushed to `events`, so order is preserved. */ private indexEvent; ofType(type: T): ReadonlyArray>; byTurn(turnId: TurnId): ReadonlyArray; toJSON(): ReadonlyArray; /** * Identity stamped onto every appended event. Set by whoever owns the surface * (the CLI resolves the OS account; an authenticated channel resolves its * token's subject), never guessed here. */ setPrincipal(principal: Principal | undefined): void; /** The identity currently being attributed to, if any. */ getPrincipal(): Principal | undefined; append(partial: EmittedEvent): Promise; subscribe(fn: EventListener): () => void; /** * Append an already-materialized event, preserving its `id`/`seq`/`ts` * rather than minting new ones. This is how a thin client mirrors the * runner's log: the server is the sole authority for event identity, so the * mirror must keep the originals. De-dupes by `seq` (idempotent replay) and * fires listeners fire-and-forget - a mirror has no dispatcher to await. * * Not for normal authoring; use {@link append} for that. */ ingest(event: MoxxyEvent): void; /** * Start this (empty) log at `seq` instead of 0. A mirror primed by a * PARTIAL attach replay (`replay: 'none'` / `{ tail }`) calls this with the * runner's announced first seq so {@link ingest}'s contiguity gate accepts * the stream. Only valid while empty — rebasing held events would detach * their seqs from their indices. */ rebase(seq: number): void; /** * Drop every event from the log. Used by `/new` to start a fresh * session without rebuilding the entire Session object — the * registries, resolvers, and active provider stay; only the * conversation context vanishes. Per-event listeners are NOT * notified (there's no "event removed" event in the schema), but * {@link onClear} subscribers fire — that's how the persistence * sidecar truncates its JSONL (so `--resume` can't resurrect wiped * history) and how the runner broadcasts a reset to attached * mirrors, in lockstep with the wipe. * * Safe to call only when no turn is in flight — callers should abort * their AbortController and await any pending runTurn() first. */ clear(): void; /** * Subscribe to {@link clear}. Fires synchronously after the events array * empties, so a listener reading the log observes the post-wipe state. * Returns the unsubscribe callback. */ onClear(fn: () => void): () => void; asReader(): EventLogReader; } //# sourceMappingURL=log.d.ts.map