import type { MrtLogEntry, TailMrtLogsResult } from '@salesforce/b2c-tooling-sdk/operations/mrt'; import type { ToolExecutionContext } from '../adapter.js'; /** Maximum number of buffered entries before oldest are evicted. */ export declare const DEFAULT_BUFFER_CAP = 5000; /** * Maximum cumulative bytes buffered before oldest entries are evicted. * Guards against a small number of pathologically large entries (e.g. multi-MB * stack traces) blowing past the count cap's intended memory bound. */ export declare const DEFAULT_BUFFER_BYTES_CAP: number; export interface PollWaiter { resolve: () => void; timer: ReturnType; } export interface MrtLogWatchEntry { watchId: string; /** MRT project slug being tailed. */ project: string; /** MRT environment slug being tailed. */ environment: string; /** MRT API origin URL (used for the logs WebSocket host). */ origin?: string; buffer: MrtLogEntry[]; /** Running byte size of `buffer` (raw + message), used for the byte cap. */ bufferBytes: number; errors: Array<{ message: string; at: string; }>; totalEntriesSeen: number; droppedEntries: number; bufferCap: number; bufferBytesCap: number; stop: () => void; done: Promise; pollWaiters: PollWaiter[]; createdAt: number; lastActivityAt: number; /** * True once the underlying WebSocket has closed — either via stop() or * because the server closed/failed the connection on its own. A stopped * watch keeps its buffered entries until drained or idle-reaped. */ stopped: boolean; } export interface RegisterMrtWatchOptions { project: string; environment: string; origin?: string; tailResult: TailMrtLogsResult; bufferCap?: number; bufferBytesCap?: number; } /** * Stable dedup key for an MRT log watch. A developer may tail several * (project, environment, origin) tuples concurrently — unlike the SFCC log * watch which keys on hostname — so all three components form the key. A space * separator is safe since project/environment slugs are URL-safe (no spaces). */ export declare function mrtWatchKey(project: string, environment: string, origin?: string): string; /** * In-memory registry of background MRT log-tail streams. * * Mirrors `LogWatchRegistry` (SFCC instance logs) but adapted for the MRT * logging WebSocket: there are no log files, prefixes, or rotations — just a * single live stream per (project, environment, origin). The stream can also * close on its own (idle timeout, auth expiry, server restart), which is * recorded as `stopped: true` plus a buffered error so a poll can surface it. */ export declare class MrtLogWatchRegistry { private cleanupTimer; private readonly watches; constructor(); /** * Append a log entry to a watch buffer. Evicts oldest if over cap. * Resolves any pending poll waiters. */ appendEntry(watchId: string, entry: MrtLogEntry): void; appendError(watchId: string, err: Error): void; destroyAll(): Promise; destroyWatch(watchId: string): Promise; /** * Drain buffered entries (up to maxEntries) and any error events from the * watch. Removes drained items from the underlying buffers. */ drain(watchId: string, maxEntries: number): { entries: MrtLogEntry[]; errors: Array<{ message: string; at: string; }>; truncated: boolean; }; findByKey(project: string, environment: string, origin?: string): MrtLogWatchEntry | undefined; getWatch(watchId: string): MrtLogWatchEntry | undefined; getWatchOrThrow(watchId: string): MrtLogWatchEntry; listWatches(): MrtLogWatchEntry[]; /** * Mark a watch's stream as closed (the WebSocket ended on its own or via * stop). Keeps the entry so buffered entries can still be drained and the * `stopped` flag is observable on the next poll; idle cleanup removes it * later. Resolves any blocked pollers so they return promptly. */ markStreamClosed(watchId: string): void; registerWatch(opts: RegisterMrtWatchOptions): MrtLogWatchEntry; /** * Wait until at least one entry is buffered (or an error event arrives, or * the stream stops), or until timeout elapses. Returns immediately if there * is already activity to report. */ waitForActivity(watchId: string, timeoutMs: number): Promise; private cleanupIdleWatches; private flushWaiters; } export declare function getMrtLogWatchRegistry(context: ToolExecutionContext): MrtLogWatchRegistry;