import { ActorRefLike, AnyEventObject, InspectionEvent, MachineContext, Observer, Snapshot, Subscribable } from "xstate"; //#region src/types.d.ts interface StatelyBaseInspectionEvent { rootId: string | undefined; sessionId: string; createdAt: string; id: string; _version: string; } type StatelySnapshotEvent = Pick & StatelyBaseInspectionEvent; type StatelyEventEvent = Pick & { sourceId: string | undefined; } & StatelyBaseInspectionEvent; type StatelyActorEvent = Pick & { name: string; snapshot: InspectedSnapshot; definition: string | undefined; parentId: string | undefined; } & StatelyBaseInspectionEvent; type StatelyInspectionEvent = StatelySnapshotEvent | StatelyEventEvent | StatelyActorEvent; interface Adapter { start?: () => void; stop?: () => void; send(event: StatelyInspectionEvent): void; } interface InspectedSnapshot { status?: Snapshot['status']; context?: any; value?: any; output?: any; } interface Inspector { adapter: TAdapter; /** * Sends a snapshot inspection event. This represents the state of the actor. */ snapshot(actor: ActorRefLikeWithData | string, snapshot: InspectedSnapshot, info?: { event?: AnyEventObject; }): void; /** * Sends an event inspection event. This represents the event that was sent to the actor. */ event(actor: ActorRefLikeWithData | string, event: AnyEventObject | string, info?: { source?: ActorRefLikeWithData | string; }): void; /** * Sends an actor registration inspection event. This represents the actor that was created. */ actor(actor: ActorRefLikeWithData | string, snapshot?: InspectedSnapshot, info?: { definition?: string; parentId?: string; rootId?: string; }): void; /** * Starts the inspector. */ start: () => void; /** * Stops the inspector. */ stop: () => void; /** * An inspection observer that can be passed into XState. * @example * ```js * import { createActor } from 'xstate'; * import { createInspector } from '@xstate/inspect'; * // ... * * const inspector = createInspector(...) * * const actor = createActor(someMachine, { * inspect: inspector.inspect * }) * ``` */ inspect: Observer; } type ActorRefLikeWithData = ActorRefLike & { _parent?: ActorRefLikeWithData; id?: string; }; //#endregion //#region src/createInspector.d.ts interface InspectorOptions { filter?: (event: StatelyInspectionEvent) => boolean; serialize?: (event: StatelyInspectionEvent) => StatelyInspectionEvent; /** * Whether to automatically start the inspector. * * @default true */ autoStart?: boolean; /** * The maximum number of deferred events to hold in memory until the inspector is active. * If the number of deferred events exceeds this number, the oldest events will be dropped. * * @default 200 */ maxDeferredEvents?: number; /** * Maximum depth for serialization. Prevents infinite recursion when serializing * HTML elements or deeply nested structures. Lower values provide better performance * but may truncate deeply nested data. * * @default 10 */ serializationDepthLimit?: number; /** * Sanitizes events sent to actors. Only the sanitized event will be sent to the inspector. */ sanitizeEvent?: (event: AnyEventObject) => AnyEventObject; /** * Sanitizes actor snapshot context. Only the sanitized context will be sent to the inspector. */ sanitizeContext?: (context: MachineContext) => MachineContext; } declare function createInspector(adapter: TAdapter, options?: InspectorOptions): Inspector; //#endregion //#region src/browser.d.ts interface BrowserReceiver extends Subscribable {} interface BrowserInspectorOptions extends InspectorOptions { url?: string; window?: Window; iframe?: HTMLIFrameElement | null; } interface OptionalBrowserInspectorOptions { send?: Adapter['send']; } /** * Creates a browser-based inspector that sends events to a remote inspector window. * The remote inspector opens an inspector window at the specified URL by default. */ declare function createBrowserInspector(options?: BrowserInspectorOptions & OptionalBrowserInspectorOptions): Inspector; interface BrowserReceiverOptions { window?: Window; /** * The number of events from the current event to replay */ replayCount?: number; } declare function createBrowserReceiver(options?: BrowserReceiverOptions): BrowserReceiver; declare class BrowserAdapter implements Adapter { options: Required & OptionalBrowserInspectorOptions; private status; private deferredEvents; targetWindow: Window | null; constructor(options: Required & OptionalBrowserInspectorOptions); start(): void; stop(): void; send(event: StatelyInspectionEvent): void; } //#endregion //#region src/createSkyInspector.d.ts declare function createSkyInspector(options?: { apiKey?: string; onerror?: (error: Error) => void; } & InspectorOptions): ReturnType; //#endregion //#region src/webSocket.d.ts interface WebSocketInspectorOptions extends InspectorOptions { url: string; } declare class WebSocketAdapter implements Adapter { private ws; private status; private deferredEvents; private options; private safeStringify; constructor(options?: WebSocketInspectorOptions); start(): void; stop(): void; send(inspectionEvent: StatelyInspectionEvent): void; } declare function createWebSocketInspector(options?: WebSocketInspectorOptions): Inspector; interface WebSocketReceiver extends Subscribable {} declare function createWebSocketReceiver(options?: { server: string; }): WebSocketReceiver; //#endregion export { type StatelyActorEvent, type StatelyEventEvent, type StatelyInspectionEvent, type StatelySnapshotEvent, createBrowserInspector, createBrowserReceiver, createInspector, createSkyInspector, createWebSocketInspector, createWebSocketReceiver };