/** * Error attribution — the bookkeeping games skip and then regret. * * The server reports UDP-side failures asynchronously as * `GenericErrorResponse { sequenceNumber, errorCode }`. Without a record of * what each sequence number was, apps can only log them. The session tracks * every outbound send made through the stores (kind, actor uuid, detail) in * a 256-slot table (sequence numbers are uint8), so each error is * **attributed** to the send that caused it and kept in a queryable ring * buffer. */ import type { SentPacketRecord, WorldSessionContext } from './session.js'; /** A server-reported send error, attributed to the send that caused it. */ export interface AttributedError { /** The server's `UdpErrorCode` (e.g. `'UNAUTHORIZED'`). */ errorCode: string; sequenceNumber: number; receivedAt: number; /** * The tracked outbound send with this sequence number, when the session * saw one (undefined for sends made outside the stores). */ send?: SentPacketRecord; } /** Options for {@link attachErrorStore}. */ export interface ErrorStoreConfig { /** Errors kept in the ring buffer. Defaults to 50. */ capacity?: number; /** Clock override for tests. Defaults to `Date.now`. */ now?: () => number; } /** * The SDK-managed **send-error log**: every `GenericErrorResponse` is * attributed to the tracked send with the same sequence number and recorded * (newest first). Query {@link recent}, subscribe with {@link onError}, or * look up the latest error for one actor with {@link lastFor}. * * Sequence numbers are uint8 correlation ids that wrap at 256, so * attribution is best-effort by design: a very old error after 256 newer * sends would attribute to the newer send with the reused number. */ export declare class ErrorStore { private readonly ring; private readonly sends; private readonly byActor; private readonly listeners; private readonly capacity; private readonly now; private totalCount; constructor(ctx: WorldSessionContext, config?: ErrorStoreConfig); /** The most recent errors, newest first (up to `n`, default all kept). */ recent(n?: number): AttributedError[]; /** The single most recent error, if any. */ get last(): AttributedError | undefined; /** Total errors seen (including ones evicted from the ring). */ get total(): number; /** The latest error attributed to sends by one actor uuid. */ lastFor(uuid: string): AttributedError | undefined; /** Subscribe to every attributed error. @returns off. */ onError(listener: (error: AttributedError) => void): () => void; /** Drop the recorded errors (send tracking continues). */ clear(): void; } /** * Attach an {@link ErrorStore} to a world session context. Prefer the * `errors` key of `createWorldSession`'s config. */ export declare function attachErrorStore(ctx: WorldSessionContext, config?: ErrorStoreConfig): ErrorStore; //# sourceMappingURL=errors.d.ts.map