import { type ActorRefLike, type InspectionEvent } from "xstate"; import { logger } from "../core"; // Mirrors @statelyai/inspect's ActorRefLikeWithData — the inspect // callback receives full Actor instances at runtime, but the type is // narrowed for @xstate/store compat. type ActorRefWithAncestry = ActorRefLike & { id?: string; _parent?: ActorRefWithAncestry; }; const actorPath = (ref: ActorRefWithAncestry): string => { const segments: string[] = []; let current: ActorRefWithAncestry | undefined = ref; while (current) { segments.unshift(current.id ?? current.sessionId); current = current._parent; } return segments.join(":"); }; /** @internal exported for testing */ export const inspect = (event: InspectionEvent): void => { const ref = event.actorRef as ActorRefWithAncestry; const log = logger.child(actorPath(ref)); switch (event.type) { case "@xstate.snapshot": { log.debug("snapshot", event.snapshot); break; } case "@xstate.event": log.debug("event", event.event); break; case "@xstate.action": log.debug("action", event.action); break; } };