|
7 | 7 | import type * as Cause from "effect/Cause" |
8 | 8 | import type * as Duration from "effect/Duration" |
9 | 9 | import type * as Effect from "effect/Effect" |
| 10 | +import type * as Exit from "effect/Exit" |
10 | 11 | import type * as Option from "effect/Option" |
11 | 12 | import type { Pipeable } from "effect/Pipeable" |
12 | 13 | import { hasProperty } from "effect/Predicate" |
@@ -1664,6 +1665,187 @@ export type RuntimeSnapshot<State, Error = never, Output = never> = |
1664 | 1665 | readonly state: State |
1665 | 1666 | } |
1666 | 1667 |
|
| 1668 | +/** |
| 1669 | + * Live, root-scoped records describing one prepared machine tree. |
| 1670 | + * |
| 1671 | + * Inspection records deliberately erase machine-specific values to `unknown`: |
| 1672 | + * one stream may contain unrelated root, child-machine, and `Logic` protocols. |
| 1673 | + * The record structure remains a closed discriminated union, while typed |
| 1674 | + * application observation continues through `changes` and `emissions`. |
| 1675 | + * |
| 1676 | + * @category models |
| 1677 | + * @since 0.13.0 |
| 1678 | + */ |
| 1679 | +export declare namespace Inspection { |
| 1680 | + /** Read-only identity of a local machine endpoint. */ |
| 1681 | + export interface Endpoint { |
| 1682 | + readonly id: string |
| 1683 | + readonly sessionId: string |
| 1684 | + } |
| 1685 | + |
| 1686 | + /** Read-only identity of a runtime represented in the inspection tree. */ |
| 1687 | + export interface Subject extends Endpoint { |
| 1688 | + readonly kind: "Machine" | "Logic" |
| 1689 | + } |
| 1690 | + |
| 1691 | + /** Causal origin of an inspected runtime. */ |
| 1692 | + export type Origin = |
| 1693 | + | { readonly _tag: "Root" } |
| 1694 | + | { |
| 1695 | + readonly _tag: "Invoke" |
| 1696 | + readonly ownerPath: string |
| 1697 | + readonly invokeId: string |
| 1698 | + } |
| 1699 | + | { |
| 1700 | + readonly _tag: "Spawn" |
| 1701 | + readonly address: string | undefined |
| 1702 | + } |
| 1703 | + |
| 1704 | + /** Causal owner of a send or emission. */ |
| 1705 | + export type Causation = |
| 1706 | + | { readonly _tag: "Initialization" } |
| 1707 | + | { readonly _tag: "Macrostep"; readonly macrostepId: number } |
| 1708 | + | { readonly _tag: "Activity"; readonly activitySessionId: string } |
| 1709 | + |
| 1710 | + /** Closed command projection safe for observation. */ |
| 1711 | + export type Command = |
| 1712 | + | { |
| 1713 | + readonly _tag: "SendTo" |
| 1714 | + readonly target: Endpoint | { readonly id: string } |
| 1715 | + readonly event: unknown |
| 1716 | + } |
| 1717 | + | { |
| 1718 | + readonly _tag: "Stop" |
| 1719 | + readonly target: Endpoint | { readonly id: string } |
| 1720 | + } |
| 1721 | + |
| 1722 | + /** One statechart microstep in a committed macrostep. */ |
| 1723 | + export interface Microstep { |
| 1724 | + readonly event: unknown |
| 1725 | + readonly transitions: ReadonlyArray<Machine.RetainedTransition> |
| 1726 | + readonly raisedEvents: ReadonlyArray<unknown> |
| 1727 | + readonly emittedEvents: ReadonlyArray<unknown> |
| 1728 | + readonly commands: ReadonlyArray<Command> |
| 1729 | + readonly exitPaths: ReadonlyArray<string> |
| 1730 | + readonly entryPaths: ReadonlyArray<string> |
| 1731 | + readonly changed: boolean |
| 1732 | + } |
| 1733 | + |
| 1734 | + /** Common ordering and identity fields for every record. */ |
| 1735 | + export interface Base { |
| 1736 | + /** Total publication order within this prepared root. */ |
| 1737 | + readonly sequence: number |
| 1738 | + /** Session id of the prepared root that owns this inspection stream. */ |
| 1739 | + readonly rootSessionId: string |
| 1740 | + /** Runtime instance described by this record. */ |
| 1741 | + readonly subject: Subject |
| 1742 | + } |
| 1743 | + |
| 1744 | + /** Announces allocation of a root or owned process identity. */ |
| 1745 | + export interface Created extends Base { |
| 1746 | + readonly _tag: "Created" |
| 1747 | + readonly parent: Subject | undefined |
| 1748 | + readonly origin: Origin |
| 1749 | + /** Compiled statechart definition; absent for generic `Logic`. */ |
| 1750 | + readonly definition: Machine.Any | undefined |
| 1751 | + } |
| 1752 | + |
| 1753 | + /** Announces successful initialization. */ |
| 1754 | + export interface Initialized extends Base { |
| 1755 | + readonly _tag: "Initialized" |
| 1756 | + readonly snapshot: RuntimeSnapshot<unknown, unknown, unknown> |
| 1757 | + readonly initialEntryPaths: ReadonlyArray<string> |
| 1758 | + readonly microsteps: ReadonlyArray<Microstep> |
| 1759 | + } |
| 1760 | + |
| 1761 | + /** Announces failure before an initial runtime snapshot exists. */ |
| 1762 | + export interface StartFailed extends Base { |
| 1763 | + readonly _tag: "StartFailed" |
| 1764 | + readonly cause: Cause.Cause<unknown> |
| 1765 | + } |
| 1766 | + |
| 1767 | + /** Announces acceptance of an event by a local mailbox. */ |
| 1768 | + export interface EventSent extends Base { |
| 1769 | + readonly _tag: "EventSent" |
| 1770 | + readonly deliveryId: number |
| 1771 | + readonly source: Subject | undefined |
| 1772 | + readonly target: Endpoint |
| 1773 | + readonly event: unknown |
| 1774 | + readonly causedBy: Causation | undefined |
| 1775 | + } |
| 1776 | + |
| 1777 | + /** Announces complete processing of one statechart mailbox event. */ |
| 1778 | + export interface EventProcessed extends Base { |
| 1779 | + readonly _tag: "EventProcessed" |
| 1780 | + readonly macrostepId: number |
| 1781 | + readonly deliveryId: number |
| 1782 | + readonly source: Subject | undefined |
| 1783 | + readonly event: unknown |
| 1784 | + readonly before: RuntimeSnapshot<unknown, unknown, unknown> |
| 1785 | + readonly after: RuntimeSnapshot<unknown, unknown, unknown> |
| 1786 | + readonly handled: boolean |
| 1787 | + readonly configurationChanged: boolean |
| 1788 | + readonly microsteps: ReadonlyArray<Microstep> |
| 1789 | + } |
| 1790 | + |
| 1791 | + /** Announces a direct state update made by generic `Logic`. */ |
| 1792 | + export interface StateChanged extends Base { |
| 1793 | + readonly _tag: "StateChanged" |
| 1794 | + readonly before: unknown |
| 1795 | + readonly after: unknown |
| 1796 | + readonly causedByDeliveryId: number | undefined |
| 1797 | + } |
| 1798 | + |
| 1799 | + /** Announces actual publication on a machine's domain emission stream. */ |
| 1800 | + export interface Emitted extends Base { |
| 1801 | + readonly _tag: "Emitted" |
| 1802 | + readonly emission: unknown |
| 1803 | + readonly causedBy: Causation | undefined |
| 1804 | + } |
| 1805 | + |
| 1806 | + /** Identity of one Effect or timer invocation run. */ |
| 1807 | + export interface Activity { |
| 1808 | + readonly id: string |
| 1809 | + readonly sessionId: string |
| 1810 | + readonly owner: Subject |
| 1811 | + readonly ownerPath: string |
| 1812 | + readonly kind: "Effect" | "Timer" |
| 1813 | + } |
| 1814 | + |
| 1815 | + /** Announces an Effect or timer invocation starting. */ |
| 1816 | + export interface ActivityStarted extends Base { |
| 1817 | + readonly _tag: "ActivityStarted" |
| 1818 | + readonly activity: Activity |
| 1819 | + } |
| 1820 | + |
| 1821 | + /** Announces an Effect or timer invocation outcome. */ |
| 1822 | + export interface ActivityStopped extends Base { |
| 1823 | + readonly _tag: "ActivityStopped" |
| 1824 | + readonly activity: Activity |
| 1825 | + /** Success or failure from the invoke; interruption means its owner stopped it. */ |
| 1826 | + readonly exit: Exit.Exit<unknown, unknown> |
| 1827 | + } |
| 1828 | + |
| 1829 | + /** Announces a terminal local runtime snapshot. */ |
| 1830 | + export interface Terminated extends Base { |
| 1831 | + readonly _tag: "Terminated" |
| 1832 | + readonly snapshot: RuntimeSnapshot<unknown, unknown, unknown> |
| 1833 | + } |
| 1834 | + |
| 1835 | + /** Complete live inspection protocol. */ |
| 1836 | + export type Event = |
| 1837 | + | Created |
| 1838 | + | Initialized |
| 1839 | + | StartFailed |
| 1840 | + | EventSent |
| 1841 | + | EventProcessed |
| 1842 | + | StateChanged |
| 1843 | + | Emitted |
| 1844 | + | ActivityStarted |
| 1845 | + | ActivityStopped |
| 1846 | + | Terminated |
| 1847 | +} |
| 1848 | + |
1667 | 1849 | /** |
1668 | 1850 | * Represents a classified terminal outcome derived from a runtime snapshot. |
1669 | 1851 | * |
@@ -1726,6 +1908,14 @@ export interface Prepared<out State, in Event, out Error, out Output, out Emitte |
1726 | 1908 | /** Streams ephemeral notifications published after subscription. */ |
1727 | 1909 | readonly emissions: Stream.Stream<Emitted> |
1728 | 1910 |
|
| 1911 | + /** |
| 1912 | + * Streams ordered operational records for this root and every locally owned |
| 1913 | + * descendant. The stream is hot, non-replayed, never fails, and completes |
| 1914 | + * after the prepared root terminates. Subscribe before evaluating `start` to |
| 1915 | + * observe initialization. |
| 1916 | + */ |
| 1917 | + readonly inspection: Stream.Stream<Inspection.Event> |
| 1918 | + |
1729 | 1919 | /** Initializes this machine once and returns its running reference. */ |
1730 | 1920 | readonly start: Effect.Effect<MachineRef<State, Event, Error, Output, Emitted>, StartError, StartRequirements> |
1731 | 1921 | } |
|
0 commit comments