xstate 6.0.0-alpha.44 → 6.0.0-alpha.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/{StateMachine-fcc48e11.cjs.js → StateMachine-756e1335.cjs.js} +3 -3
  2. package/dist/{StateMachine-b13b4b09.esm.js → StateMachine-9509c0bd.esm.js} +3 -3
  3. package/dist/{StateMachine-1ea29688.development.esm.js → StateMachine-a5ede014.development.esm.js} +3 -3
  4. package/dist/{StateMachine-16d7ee93.development.cjs.js → StateMachine-fa133051.development.cjs.js} +3 -3
  5. package/dist/{createActor-9538c7f8.cjs.js → createActor-0816a84b.cjs.js} +110 -23
  6. package/dist/{createActor-973c72ad.esm.js → createActor-9523f716.esm.js} +108 -24
  7. package/dist/{createActor-f9cc6590.development.esm.js → createActor-f5277b31.development.esm.js} +105 -24
  8. package/dist/{createActor-1a3a1d14.development.cjs.js → createActor-f6e6146f.development.cjs.js} +107 -23
  9. package/dist/declarations/src/createActor.d.ts +0 -1
  10. package/dist/declarations/src/createMachine.d.ts +3 -3
  11. package/dist/declarations/src/durable/index.d.ts +51 -16
  12. package/dist/declarations/src/inspectionAmbient.d.ts +1 -0
  13. package/dist/declarations/src/setup.d.ts +17 -3
  14. package/dist/declarations/src/system.d.ts +1 -1
  15. package/dist/declarations/src/types.d.ts +23 -13
  16. package/dist/declarations/src/types.v6.d.ts +14 -0
  17. package/dist/{effectDescriptor-7d6f945a.development.cjs.js → effectDescriptor-3a016bbe.cjs.js} +19 -1
  18. package/dist/{effectDescriptor-416ca00a.esm.js → effectDescriptor-87826c41.esm.js} +19 -1
  19. package/dist/{effectDescriptor-f8c9337f.cjs.js → effectDescriptor-8a5d62e0.development.cjs.js} +19 -1
  20. package/dist/{effectDescriptor-e6730c9a.development.esm.js → effectDescriptor-9a14147f.development.esm.js} +19 -1
  21. package/dist/{index-e0ba4813.development.cjs.js → index-1e1e1cba.development.cjs.js} +1 -1
  22. package/dist/{index-f284cc7b.development.esm.js → index-3907b7aa.development.esm.js} +1 -1
  23. package/dist/{index-ba7170ba.cjs.js → index-7b9c4f77.cjs.js} +1 -1
  24. package/dist/{index-b478f443.esm.js → index-c7431a16.esm.js} +1 -1
  25. package/dist/xstate-actors.cjs.js +2 -2
  26. package/dist/xstate-actors.development.cjs.js +2 -2
  27. package/dist/xstate-actors.development.esm.js +2 -2
  28. package/dist/xstate-actors.esm.js +2 -2
  29. package/dist/xstate-actors.umd.min.js +1 -1
  30. package/dist/xstate-actors.umd.min.js.map +1 -1
  31. package/dist/xstate-durable.cjs.js +80 -20
  32. package/dist/xstate-durable.development.cjs.js +80 -20
  33. package/dist/xstate-durable.development.esm.js +80 -20
  34. package/dist/xstate-durable.esm.js +80 -20
  35. package/dist/xstate-durable.umd.min.js +1 -1
  36. package/dist/xstate-durable.umd.min.js.map +1 -1
  37. package/dist/xstate-graph.cjs.js +3 -3
  38. package/dist/xstate-graph.development.cjs.js +3 -3
  39. package/dist/xstate-graph.development.esm.js +3 -3
  40. package/dist/xstate-graph.esm.js +3 -3
  41. package/dist/xstate-graph.umd.min.js +1 -1
  42. package/dist/xstate-graph.umd.min.js.map +1 -1
  43. package/dist/xstate-validation.cjs.js +1 -1
  44. package/dist/xstate-validation.development.cjs.js +1 -1
  45. package/dist/xstate-validation.development.esm.js +1 -1
  46. package/dist/xstate-validation.esm.js +1 -1
  47. package/dist/xstate.cjs.js +16 -4
  48. package/dist/xstate.development.cjs.js +16 -4
  49. package/dist/xstate.development.esm.js +18 -6
  50. package/dist/xstate.esm.js +18 -6
  51. package/dist/xstate.umd.min.js +1 -1
  52. package/dist/xstate.umd.min.js.map +1 -1
  53. package/package.json +1 -1
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var createActor = require('./createActor-9538c7f8.cjs.js');
4
- var dist_xstateActors = require('./index-ba7170ba.cjs.js');
3
+ var createActor = require('./createActor-0816a84b.cjs.js');
4
+ var dist_xstateActors = require('./index-7b9c4f77.cjs.js');
5
5
 
6
6
  function createSpawner(actorScope, actors, spawnedChildren) {
7
7
  return (src, options) => {
8
- const referencedSrc = Object.entries(actors).find(([, logic]) => logic === src)?.[0];
8
+ const referencedSrc = createActor.resolveRegisteredActorSource(actors, src);
9
9
  // Generated ids come from the same transaction allocator as `enq.spawn`,
10
10
  // so context-factory allocations persist with the snapshot and never
11
11
  // collide with later spawns.
@@ -1,9 +1,9 @@
1
- import { Q as allocateChildId, R as assertChildIdFree, S as reserveChildId, T as STATE_DELIMITER, U as mapValues, t as toArray, V as createInvokeId, W as getDelayedTransitions, Y as getEventDescriptorKey, Z as getCandidates, _ as evaluateCandidate, $ as formatTransition, a0 as NULL_EVENT, a1 as toTransitionConfigArray, a2 as createInvokeTimeoutEventId, a3 as matchesActorSession, a4 as formatRouteTransitions, a5 as resolveStateValue, a6 as getAllStateNodes, x as getStateNodes, a7 as createMachineSnapshot, a8 as isInFinalState, a9 as createInertActorScope, aa as setInertActorScopeSnapshot, a as beginSpawnAllocation, ab as attachSnapshotActorRef, ac as macrostep, ad as isInertActorScope, ae as setSnapshotActorRef, af as cloneMachineSnapshot, ag as transitionNode, g as XSTATE_TIMER, m as matchesEventDescriptor, ah as getTransitionResult, ai as hasEffect, aj as createErrorPlatformEvent, ak as withActorSelf, r as resolveActionsWithContext, al as takeSpawnAllocationCounters, am as mergeActorIdCounters, K as createInitEvent, an as createSpawnEffect, ao as initialMicrostep, ap as toStatePath, aq as isStateId, ar as getStateNodeByPath, as as getPersistedSnapshot, at as createRemoteActorRef, au as resolveReferencedActor, av as createInvokeTimeoutEvent, aw as parseGeneratedActorId, ax as ACTOR_REF_TYPE, k as createActor } from './createActor-973c72ad.esm.js';
2
- import { g as assertValid } from './index-b478f443.esm.js';
1
+ import { Q as resolveRegisteredActorSource, R as allocateChildId, S as assertChildIdFree, T as reserveChildId, U as STATE_DELIMITER, V as mapValues, t as toArray, W as createInvokeId, Y as getDelayedTransitions, Z as getEventDescriptorKey, _ as getCandidates, $ as evaluateCandidate, a0 as formatTransition, a1 as NULL_EVENT, a2 as toTransitionConfigArray, a3 as createInvokeTimeoutEventId, a4 as matchesActorSession, a5 as formatRouteTransitions, a6 as resolveStateValue, a7 as getAllStateNodes, x as getStateNodes, a8 as createMachineSnapshot, a9 as isInFinalState, aa as createInertActorScope, ab as setInertActorScopeSnapshot, a as beginSpawnAllocation, ac as attachSnapshotActorRef, ad as macrostep, ae as isInertActorScope, af as setSnapshotActorRef, ag as cloneMachineSnapshot, ah as transitionNode, g as XSTATE_TIMER, m as matchesEventDescriptor, ai as getTransitionResult, aj as hasEffect, ak as createErrorPlatformEvent, al as withActorSelf, r as resolveActionsWithContext, am as takeSpawnAllocationCounters, an as mergeActorIdCounters, K as createInitEvent, ao as createSpawnEffect, ap as initialMicrostep, aq as toStatePath, ar as isStateId, as as getStateNodeByPath, at as getPersistedSnapshot, au as createRemoteActorRef, av as resolveReferencedActor, aw as createInvokeTimeoutEvent, ax as parseGeneratedActorId, ay as ACTOR_REF_TYPE, k as createActor } from './createActor-9523f716.esm.js';
2
+ import { g as assertValid } from './index-c7431a16.esm.js';
3
3
 
4
4
  function createSpawner(actorScope, actors, spawnedChildren) {
5
5
  return (src, options) => {
6
- const referencedSrc = Object.entries(actors).find(([, logic]) => logic === src)?.[0];
6
+ const referencedSrc = resolveRegisteredActorSource(actors, src);
7
7
  // Generated ids come from the same transaction allocator as `enq.spawn`,
8
8
  // so context-factory allocations persist with the snapshot and never
9
9
  // collide with later spawns.
@@ -1,9 +1,9 @@
1
- import { Q as allocateChildId, R as assertChildIdFree, S as reserveChildId, T as STATE_DELIMITER, U as mapValues, t as toArray, V as createInvokeId, W as getDelayedTransitions, Y as getEventDescriptorKey, Z as getCandidates, _ as evaluateCandidate, $ as formatTransition, a0 as NULL_EVENT, a1 as toTransitionConfigArray, a2 as createInvokeTimeoutEventId, a3 as matchesActorSession, a4 as formatRouteTransitions, a5 as resolveStateValue, a6 as getAllStateNodes, x as getStateNodes, a7 as createMachineSnapshot, a8 as isInFinalState, a9 as createInertActorScope, aa as setInertActorScopeSnapshot, a as beginSpawnAllocation, ab as attachSnapshotActorRef, ac as macrostep, ad as isInertActorScope, ae as setSnapshotActorRef, af as cloneMachineSnapshot, ag as transitionNode, g as XSTATE_TIMER, m as matchesEventDescriptor, ah as getTransitionResult, ai as hasEffect, aj as createErrorPlatformEvent, ak as withActorSelf, r as resolveActionsWithContext, al as takeSpawnAllocationCounters, am as mergeActorIdCounters, K as createInitEvent, an as createSpawnEffect, ao as initialMicrostep, ap as toStatePath, aq as isStateId, ar as getStateNodeByPath, as as getPersistedSnapshot, at as createRemoteActorRef, au as resolveReferencedActor, av as createInvokeTimeoutEvent, aw as parseGeneratedActorId, ax as ACTOR_REF_TYPE, k as createActor } from './createActor-f9cc6590.development.esm.js';
2
- import { g as assertValid } from './index-f284cc7b.development.esm.js';
1
+ import { Q as resolveRegisteredActorSource, R as allocateChildId, S as assertChildIdFree, T as reserveChildId, U as STATE_DELIMITER, V as mapValues, t as toArray, W as createInvokeId, Y as getDelayedTransitions, Z as getEventDescriptorKey, _ as getCandidates, $ as evaluateCandidate, a0 as formatTransition, a1 as NULL_EVENT, a2 as toTransitionConfigArray, a3 as createInvokeTimeoutEventId, a4 as matchesActorSession, a5 as formatRouteTransitions, a6 as resolveStateValue, a7 as getAllStateNodes, x as getStateNodes, a8 as createMachineSnapshot, a9 as isInFinalState, aa as createInertActorScope, ab as setInertActorScopeSnapshot, a as beginSpawnAllocation, ac as attachSnapshotActorRef, ad as macrostep, ae as isInertActorScope, af as setSnapshotActorRef, ag as cloneMachineSnapshot, ah as transitionNode, g as XSTATE_TIMER, m as matchesEventDescriptor, ai as getTransitionResult, aj as hasEffect, ak as createErrorPlatformEvent, al as withActorSelf, r as resolveActionsWithContext, am as takeSpawnAllocationCounters, an as mergeActorIdCounters, K as createInitEvent, ao as createSpawnEffect, ap as initialMicrostep, aq as toStatePath, ar as isStateId, as as getStateNodeByPath, at as getPersistedSnapshot, au as createRemoteActorRef, av as resolveReferencedActor, aw as createInvokeTimeoutEvent, ax as parseGeneratedActorId, ay as ACTOR_REF_TYPE, k as createActor } from './createActor-f5277b31.development.esm.js';
2
+ import { g as assertValid } from './index-3907b7aa.development.esm.js';
3
3
 
4
4
  function createSpawner(actorScope, actors, spawnedChildren) {
5
5
  return (src, options) => {
6
- const referencedSrc = Object.entries(actors).find(([, logic]) => logic === src)?.[0];
6
+ const referencedSrc = resolveRegisteredActorSource(actors, src);
7
7
  // Generated ids come from the same transaction allocator as `enq.spawn`,
8
8
  // so context-factory allocations persist with the snapshot and never
9
9
  // collide with later spawns.
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var createActor = require('./createActor-1a3a1d14.development.cjs.js');
4
- var dist_xstateActors = require('./index-e0ba4813.development.cjs.js');
3
+ var createActor = require('./createActor-f6e6146f.development.cjs.js');
4
+ var dist_xstateActors = require('./index-1e1e1cba.development.cjs.js');
5
5
 
6
6
  function createSpawner(actorScope, actors, spawnedChildren) {
7
7
  return (src, options) => {
8
- const referencedSrc = Object.entries(actors).find(([, logic]) => logic === src)?.[0];
8
+ const referencedSrc = createActor.resolveRegisteredActorSource(actors, src);
9
9
  // Generated ids come from the same transaction allocator as `enq.spawn`,
10
10
  // so context-factory allocations persist with the snapshot and never
11
11
  // collide with later spawns.
@@ -219,6 +219,27 @@ const builtInActions = {
219
219
  }
220
220
  };
221
221
 
222
+ const sourceKeyCaches = new WeakMap();
223
+
224
+ /** @internal */
225
+ function resolveRegisteredActorSource(actors, logic) {
226
+ let cache = sourceKeyCaches.get(actors);
227
+ if (!cache) {
228
+ cache = new Map();
229
+ for (const key of Object.keys(actors)) {
230
+ const registeredLogic = actors[key];
231
+ // Several source keys may intentionally share one implementation. The
232
+ // first key is its canonical persistence identity when spawning by the
233
+ // raw logic value, which cannot retain which alias was used to access it.
234
+ if (!cache.has(registeredLogic)) {
235
+ cache.set(registeredLogic, key);
236
+ }
237
+ }
238
+ sourceKeyCaches.set(actors, cache);
239
+ }
240
+ return cache.get(logic);
241
+ }
242
+
222
243
  const subscriptions = /* #__PURE__ */new WeakMap();
223
244
 
224
245
  /**
@@ -666,21 +687,31 @@ function beginSpawnAllocation(actorScope) {
666
687
  function getWorkingSnapshotOf(actorScope) {
667
688
  return actorScope.self._snapshot;
668
689
  }
669
- const srcKeyCaches = new WeakMap();
670
- function getRegisteredSrcKey(actorScope, logic) {
671
- const registeredActors = actorScope.self.logic?.sources?.actors;
672
- if (!registeredActors) {
673
- return undefined;
674
- }
675
- let cache = srcKeyCaches.get(registeredActors);
676
- if (!cache) {
677
- cache = new Map();
678
- for (const key of Object.keys(registeredActors)) {
679
- cache.set(registeredActors[key], key);
690
+ function getRegisteredActors(actorScope) {
691
+ return actorScope.self.logic?.sources?.actors;
692
+ }
693
+ function resolveTransitionSpawnSource(actorScope, source) {
694
+ const registeredActors = getRegisteredActors(actorScope);
695
+ if (typeof source === 'string') {
696
+ const logic = registeredActors?.[source];
697
+ if (!logic) {
698
+ throw new Error(`Actor source '${source}' is not provided`);
680
699
  }
681
- srcKeyCaches.set(registeredActors, cache);
700
+ return {
701
+ logic,
702
+ src: source
703
+ };
682
704
  }
683
- return cache.get(logic);
705
+ if (!registeredActors) {
706
+ return {
707
+ logic: source,
708
+ src: undefined
709
+ };
710
+ }
711
+ return {
712
+ logic: source,
713
+ src: resolveRegisteredActorSource(registeredActors, source)
714
+ };
684
715
  }
685
716
 
686
717
  /**
@@ -821,17 +852,17 @@ function createTransitionEnqueue(actorScope, actions, internalEvents, actorSubsc
821
852
  internalEvents.push(raisedEvent);
822
853
  }
823
854
  },
824
- spawn: (logic, options) => {
855
+ spawn: (source, options) => {
856
+ const {
857
+ logic,
858
+ src
859
+ } = resolveTransitionSpawnSource(actorScope, source);
825
860
  if (!createActors) {
826
861
  // TODO: replace this speculative placeholder with a typed inert actor ref.
827
862
  return {
828
- id: options?.id ?? options?.registryKey ?? logic.id
863
+ id: options?.id ?? options?.registryKey ?? src ?? logic.id
829
864
  };
830
865
  }
831
- // Recover the registered source key for setup-provided logic so the
832
- // spawned child persists (and gets a deterministic id prefix) by key
833
- // instead of by inline logic reference.
834
- const src = getRegisteredSrcKey(actorScope, logic);
835
866
  // Generated ids allocate from the parent snapshot's own counters
836
867
  // through the transition's allocation transaction; explicit
837
868
  // generated-shaped ids reserve their numbering the same way.
@@ -1266,6 +1297,45 @@ function parseDelayToMilliseconds(delay) {
1266
1297
  return parseDurationToMilliseconds(delay);
1267
1298
  }
1268
1299
 
1300
+ /**
1301
+ * The ambiently installed system inspector. Set for the duration of a durable
1302
+ * execution's transitions (`createDurable(..., { inspect })`), it makes the
1303
+ * pure-transition machinery observable: freshly constructed runtime systems
1304
+ * attach it, and snapshot systems created while it is set forward inspection
1305
+ * to their base system instead of stubbing it out.
1306
+ */
1307
+ let ambientInspector;
1308
+
1309
+ /** @internal */
1310
+ function hasAmbientInspector() {
1311
+ return ambientInspector !== undefined;
1312
+ }
1313
+
1314
+ /** @internal */
1315
+ function getAmbientInspector() {
1316
+ return ambientInspector;
1317
+ }
1318
+
1319
+ /**
1320
+ * Runs `fn` with systems it creates wired to `inspect` from construction, so
1321
+ * creation-time inspection events (the root actor's own registration, actors
1322
+ * spawned during the first transition) are observed too.
1323
+ *
1324
+ * @internal
1325
+ */
1326
+ function withSystemInspector(inspect, fn) {
1327
+ if (!inspect) {
1328
+ return fn();
1329
+ }
1330
+ const previous = ambientInspector;
1331
+ ambientInspector = inspect;
1332
+ try {
1333
+ return fn();
1334
+ } finally {
1335
+ ambientInspector = previous;
1336
+ }
1337
+ }
1338
+
1269
1339
  /** Snapshot-scoped actor identity and system view. @internal */
1270
1340
 
1271
1341
  const snapshotActorRefs = new WeakMap();
@@ -1328,6 +1398,7 @@ function getSnapshotChildren(snapshot) {
1328
1398
  * @internal
1329
1399
  */
1330
1400
  function createSnapshotSystem(baseSystem, children, baseState) {
1401
+ const forwardInspection = hasAmbientInspector();
1331
1402
  const registeredActors = copyRegisteredActors(baseSystem, baseState);
1332
1403
  const keyedActors = new Map(baseState?.keyedActors ?? getKeyedActors(baseSystem));
1333
1404
  const reverseKeyedActors = new WeakMap();
@@ -1366,10 +1437,13 @@ function createSnapshotSystem(baseSystem, children, baseState) {
1366
1437
  },
1367
1438
  get: registryKey => keyedActors.get(registryKey),
1368
1439
  getAll: () => Object.fromEntries(keyedActors),
1369
- // Pure transition resolution must not leak topology inspection events into
1370
- // a live runtime system.
1371
- _hasInspectionObservers: () => false,
1372
- _sendInspectionEvent: () => {}
1440
+ // Pure transition resolution must not leak topology inspection events
1441
+ // into a live runtime system — planning branches stay silent. The one
1442
+ // exception is a durable execution's own transitions (marked by the
1443
+ // ambient inspector at creation time): there the pure path IS the
1444
+ // execution, so inspection forwards to the base system's observers.
1445
+ _hasInspectionObservers: forwardInspection ? () => baseSystem._hasInspectionObservers?.() ?? false : () => false,
1446
+ _sendInspectionEvent: forwardInspection ? event => baseSystem._sendInspectionEvent(event) : () => {}
1373
1447
  });
1374
1448
  for (const [registryKey, actor] of keyedActors) {
1375
1449
  if (!actor) {
@@ -3656,6 +3730,9 @@ function getPersistedSnapshot(snapshot, options) {
3656
3730
  const embedChildren = options?.embedChildren !== false;
3657
3731
  for (const id in children) {
3658
3732
  const child = children[id];
3733
+ if (typeof child.src !== 'string' && (!options || !('__unsafeAllowInlineActors' in options))) {
3734
+ throw new Error('An inline child actor cannot be persisted.');
3735
+ }
3659
3736
  // Children are referenced by their logical address. Embedding the child
3660
3737
  // state is the co-locating runtime's whole-tree checkpoint capability;
3661
3738
  // remote handles never embed — their state lives with another runtime.
@@ -4372,6 +4449,10 @@ class RuntimeSystem {
4372
4449
  this._clock = options.clock;
4373
4450
  this._logger = options.logger;
4374
4451
  this.createActorRef = options.createActorRef;
4452
+ const ambientInspector = getAmbientInspector();
4453
+ if (ambientInspector) {
4454
+ this.inspect(ambientInspector);
4455
+ }
4375
4456
  this._snapshot = {
4376
4457
  _scheduledTimers: restoredSnapshot?.scheduler ?? emptyScheduledTimers,
4377
4458
  // System-level counters are process-local backstops; per-actor
@@ -5072,6 +5153,9 @@ class Actor {
5072
5153
  }
5073
5154
  this._inspectTransition(this._snapshot, event);
5074
5155
  }
5156
+
5157
+ /** @internal Emits the transition inspection event; used by the pure
5158
+ * `transition()` path for snapshots driven outside a live actor. */
5075
5159
  _inspectTransition(snapshot, event) {
5076
5160
  if (this.system._hasInspectionObservers?.() ?? true) {
5077
5161
  this.system._sendInspectionEvent({
@@ -5672,6 +5756,7 @@ exports.getSnapshotActorRef = getSnapshotActorRef;
5672
5756
  exports.getStateNodeByPath = getStateNodeByPath;
5673
5757
  exports.getStateNodes = getStateNodes;
5674
5758
  exports.getTransitionResult = getTransitionResult;
5759
+ exports.hasAmbientInspector = hasAmbientInspector;
5675
5760
  exports.hasEffect = hasEffect;
5676
5761
  exports.initialMicrostep = initialMicrostep;
5677
5762
  exports.isAtomicStateNode = isAtomicStateNode;
@@ -5696,6 +5781,7 @@ exports.pathToStateValue = pathToStateValue;
5696
5781
  exports.reserveChildId = reserveChildId;
5697
5782
  exports.resolveActionsWithContext = resolveActionsWithContext;
5698
5783
  exports.resolveReferencedActor = resolveReferencedActor;
5784
+ exports.resolveRegisteredActorSource = resolveRegisteredActorSource;
5699
5785
  exports.resolveStateValue = resolveStateValue;
5700
5786
  exports.runStep = runStep;
5701
5787
  exports.setInertActorScopeSnapshot = setInertActorScopeSnapshot;
@@ -5712,3 +5798,4 @@ exports.transitionNode = transitionNode;
5712
5798
  exports.withActorScope = withActorScope;
5713
5799
  exports.withActorSelf = withActorSelf;
5714
5800
  exports.withExecutionIdentity = withExecutionIdentity;
5801
+ exports.withSystemInspector = withSystemInspector;
@@ -217,6 +217,27 @@ const builtInActions = {
217
217
  }
218
218
  };
219
219
 
220
+ const sourceKeyCaches = new WeakMap();
221
+
222
+ /** @internal */
223
+ function resolveRegisteredActorSource(actors, logic) {
224
+ let cache = sourceKeyCaches.get(actors);
225
+ if (!cache) {
226
+ cache = new Map();
227
+ for (const key of Object.keys(actors)) {
228
+ const registeredLogic = actors[key];
229
+ // Several source keys may intentionally share one implementation. The
230
+ // first key is its canonical persistence identity when spawning by the
231
+ // raw logic value, which cannot retain which alias was used to access it.
232
+ if (!cache.has(registeredLogic)) {
233
+ cache.set(registeredLogic, key);
234
+ }
235
+ }
236
+ sourceKeyCaches.set(actors, cache);
237
+ }
238
+ return cache.get(logic);
239
+ }
240
+
220
241
  const subscriptions = /* #__PURE__ */new WeakMap();
221
242
 
222
243
  /**
@@ -664,21 +685,31 @@ function beginSpawnAllocation(actorScope) {
664
685
  function getWorkingSnapshotOf(actorScope) {
665
686
  return actorScope.self._snapshot;
666
687
  }
667
- const srcKeyCaches = new WeakMap();
668
- function getRegisteredSrcKey(actorScope, logic) {
669
- const registeredActors = actorScope.self.logic?.sources?.actors;
670
- if (!registeredActors) {
671
- return undefined;
672
- }
673
- let cache = srcKeyCaches.get(registeredActors);
674
- if (!cache) {
675
- cache = new Map();
676
- for (const key of Object.keys(registeredActors)) {
677
- cache.set(registeredActors[key], key);
688
+ function getRegisteredActors(actorScope) {
689
+ return actorScope.self.logic?.sources?.actors;
690
+ }
691
+ function resolveTransitionSpawnSource(actorScope, source) {
692
+ const registeredActors = getRegisteredActors(actorScope);
693
+ if (typeof source === 'string') {
694
+ const logic = registeredActors?.[source];
695
+ if (!logic) {
696
+ throw new Error(`Actor source '${source}' is not provided`);
678
697
  }
679
- srcKeyCaches.set(registeredActors, cache);
698
+ return {
699
+ logic,
700
+ src: source
701
+ };
680
702
  }
681
- return cache.get(logic);
703
+ if (!registeredActors) {
704
+ return {
705
+ logic: source,
706
+ src: undefined
707
+ };
708
+ }
709
+ return {
710
+ logic: source,
711
+ src: resolveRegisteredActorSource(registeredActors, source)
712
+ };
682
713
  }
683
714
 
684
715
  /**
@@ -819,17 +850,17 @@ function createTransitionEnqueue(actorScope, actions, internalEvents, actorSubsc
819
850
  internalEvents.push(raisedEvent);
820
851
  }
821
852
  },
822
- spawn: (logic, options) => {
853
+ spawn: (source, options) => {
854
+ const {
855
+ logic,
856
+ src
857
+ } = resolveTransitionSpawnSource(actorScope, source);
823
858
  if (!createActors) {
824
859
  // TODO: replace this speculative placeholder with a typed inert actor ref.
825
860
  return {
826
- id: options?.id ?? options?.registryKey ?? logic.id
861
+ id: options?.id ?? options?.registryKey ?? src ?? logic.id
827
862
  };
828
863
  }
829
- // Recover the registered source key for setup-provided logic so the
830
- // spawned child persists (and gets a deterministic id prefix) by key
831
- // instead of by inline logic reference.
832
- const src = getRegisteredSrcKey(actorScope, logic);
833
864
  // Generated ids allocate from the parent snapshot's own counters
834
865
  // through the transition's allocation transaction; explicit
835
866
  // generated-shaped ids reserve their numbering the same way.
@@ -1264,6 +1295,45 @@ function parseDelayToMilliseconds(delay) {
1264
1295
  return parseDurationToMilliseconds(delay);
1265
1296
  }
1266
1297
 
1298
+ /**
1299
+ * The ambiently installed system inspector. Set for the duration of a durable
1300
+ * execution's transitions (`createDurable(..., { inspect })`), it makes the
1301
+ * pure-transition machinery observable: freshly constructed runtime systems
1302
+ * attach it, and snapshot systems created while it is set forward inspection
1303
+ * to their base system instead of stubbing it out.
1304
+ */
1305
+ let ambientInspector;
1306
+
1307
+ /** @internal */
1308
+ function hasAmbientInspector() {
1309
+ return ambientInspector !== undefined;
1310
+ }
1311
+
1312
+ /** @internal */
1313
+ function getAmbientInspector() {
1314
+ return ambientInspector;
1315
+ }
1316
+
1317
+ /**
1318
+ * Runs `fn` with systems it creates wired to `inspect` from construction, so
1319
+ * creation-time inspection events (the root actor's own registration, actors
1320
+ * spawned during the first transition) are observed too.
1321
+ *
1322
+ * @internal
1323
+ */
1324
+ function withSystemInspector(inspect, fn) {
1325
+ if (!inspect) {
1326
+ return fn();
1327
+ }
1328
+ const previous = ambientInspector;
1329
+ ambientInspector = inspect;
1330
+ try {
1331
+ return fn();
1332
+ } finally {
1333
+ ambientInspector = previous;
1334
+ }
1335
+ }
1336
+
1267
1337
  /** Snapshot-scoped actor identity and system view. @internal */
1268
1338
 
1269
1339
  const snapshotActorRefs = new WeakMap();
@@ -1326,6 +1396,7 @@ function getSnapshotChildren(snapshot) {
1326
1396
  * @internal
1327
1397
  */
1328
1398
  function createSnapshotSystem(baseSystem, children, baseState) {
1399
+ const forwardInspection = hasAmbientInspector();
1329
1400
  const registeredActors = copyRegisteredActors(baseSystem, baseState);
1330
1401
  const keyedActors = new Map(baseState?.keyedActors ?? getKeyedActors(baseSystem));
1331
1402
  const reverseKeyedActors = new WeakMap();
@@ -1364,10 +1435,13 @@ function createSnapshotSystem(baseSystem, children, baseState) {
1364
1435
  },
1365
1436
  get: registryKey => keyedActors.get(registryKey),
1366
1437
  getAll: () => Object.fromEntries(keyedActors),
1367
- // Pure transition resolution must not leak topology inspection events into
1368
- // a live runtime system.
1369
- _hasInspectionObservers: () => false,
1370
- _sendInspectionEvent: () => {}
1438
+ // Pure transition resolution must not leak topology inspection events
1439
+ // into a live runtime system — planning branches stay silent. The one
1440
+ // exception is a durable execution's own transitions (marked by the
1441
+ // ambient inspector at creation time): there the pure path IS the
1442
+ // execution, so inspection forwards to the base system's observers.
1443
+ _hasInspectionObservers: forwardInspection ? () => baseSystem._hasInspectionObservers?.() ?? false : () => false,
1444
+ _sendInspectionEvent: forwardInspection ? event => baseSystem._sendInspectionEvent(event) : () => {}
1371
1445
  });
1372
1446
  for (const [registryKey, actor] of keyedActors) {
1373
1447
  if (!actor) {
@@ -3654,6 +3728,9 @@ function getPersistedSnapshot(snapshot, options) {
3654
3728
  const embedChildren = options?.embedChildren !== false;
3655
3729
  for (const id in children) {
3656
3730
  const child = children[id];
3731
+ if (typeof child.src !== 'string' && (!options || !('__unsafeAllowInlineActors' in options))) {
3732
+ throw new Error('An inline child actor cannot be persisted.');
3733
+ }
3657
3734
  // Children are referenced by their logical address. Embedding the child
3658
3735
  // state is the co-locating runtime's whole-tree checkpoint capability;
3659
3736
  // remote handles never embed — their state lives with another runtime.
@@ -4370,6 +4447,10 @@ class RuntimeSystem {
4370
4447
  this._clock = options.clock;
4371
4448
  this._logger = options.logger;
4372
4449
  this.createActorRef = options.createActorRef;
4450
+ const ambientInspector = getAmbientInspector();
4451
+ if (ambientInspector) {
4452
+ this.inspect(ambientInspector);
4453
+ }
4373
4454
  this._snapshot = {
4374
4455
  _scheduledTimers: restoredSnapshot?.scheduler ?? emptyScheduledTimers,
4375
4456
  // System-level counters are process-local backstops; per-actor
@@ -5070,6 +5151,9 @@ class Actor {
5070
5151
  }
5071
5152
  this._inspectTransition(this._snapshot, event);
5072
5153
  }
5154
+
5155
+ /** @internal Emits the transition inspection event; used by the pure
5156
+ * `transition()` path for snapshots driven outside a live actor. */
5073
5157
  _inspectTransition(snapshot, event) {
5074
5158
  if (this.system._hasInspectionObservers?.() ?? true) {
5075
5159
  this.system._sendInspectionEvent({
@@ -5612,4 +5696,4 @@ function createActor(logic, options) {
5612
5696
  return new Actor(logic, options);
5613
5697
  }
5614
5698
 
5615
- export { formatTransition as $, Actor as A, checkStateIn as B, pathToStateValue as C, toObserver as D, executeEffects as E, isBuiltInExecutableAction as F, deliverEvent as G, runStep as H, stopActor as I, terminateActor as J, createInitEvent as K, createCustomEffect as L, XSTATE_LOGIC_EFFECT_START as M, XSTATE_LOGIC_EFFECT_RESOLVE as N, XSTATE_LOGIC_EFFECT_REJECT as O, createEmitEffect as P, allocateChildId as Q, assertChildIdFree as R, reserveChildId as S, STATE_DELIMITER as T, mapValues as U, createInvokeId as V, getDelayedTransitions as W, XSTATE_INIT as X, getEventDescriptorKey as Y, getCandidates as Z, evaluateCandidate as _, beginSpawnAllocation as a, NULL_EVENT as a0, toTransitionConfigArray as a1, createInvokeTimeoutEventId as a2, matchesActorSession as a3, formatRouteTransitions as a4, resolveStateValue as a5, getAllStateNodes as a6, createMachineSnapshot as a7, isInFinalState as a8, createInertActorScope as a9, getActorIdPrefix as aA, getAllOwnEvents as aB, matchesEvent as aC, encodeAddressSegment as aD, getRootActorId as aE, RUNTIME_OPERATIONS as aF, withExecutionIdentity as aG, getSnapshotActorRef as aH, setInertActorScopeSnapshot as aa, attachSnapshotActorRef as ab, macrostep as ac, isInertActorScope as ad, setSnapshotActorRef as ae, cloneMachineSnapshot as af, transitionNode as ag, getTransitionResult as ah, hasEffect as ai, createErrorPlatformEvent as aj, withActorSelf as ak, takeSpawnAllocationCounters as al, mergeActorIdCounters as am, createSpawnEffect as an, initialMicrostep as ao, toStatePath as ap, isStateId as aq, getStateNodeByPath as ar, getPersistedSnapshot as as, createRemoteActorRef as at, resolveReferencedActor as au, createInvokeTimeoutEvent as av, parseGeneratedActorId as aw, ACTOR_REF_TYPE as ax, getProperAncestors as ay, isRemoteActorRef as az, builtInActions as b, createTransitionEnqueue as c, deriveDeferredStarts as d, XSTATE_STOP as e, finalizeTransitionResult as f, XSTATE_TIMER as g, createSendToEffect as h, isLazyActorScope as i, isAtomicStateNode as j, createActor as k, createListenerLogic as l, matchesEventDescriptor as m, createSubscriptionLogic as n, listenerLogic as o, parseDelayToMilliseconds as p, getInitialSnapshot as q, resolveActionsWithContext as r, subscriptionLogic as s, toArray as t, getNextSnapshot as u, isMachineSnapshot as v, withActorScope as w, getStateNodes as x, getAllOwnEventDescriptors as y, matchesState as z };
5699
+ export { evaluateCandidate as $, Actor as A, checkStateIn as B, pathToStateValue as C, toObserver as D, executeEffects as E, isBuiltInExecutableAction as F, deliverEvent as G, runStep as H, stopActor as I, terminateActor as J, createInitEvent as K, createCustomEffect as L, XSTATE_LOGIC_EFFECT_START as M, XSTATE_LOGIC_EFFECT_RESOLVE as N, XSTATE_LOGIC_EFFECT_REJECT as O, createEmitEffect as P, resolveRegisteredActorSource as Q, allocateChildId as R, assertChildIdFree as S, reserveChildId as T, STATE_DELIMITER as U, mapValues as V, createInvokeId as W, XSTATE_INIT as X, getDelayedTransitions as Y, getEventDescriptorKey as Z, getCandidates as _, beginSpawnAllocation as a, formatTransition as a0, NULL_EVENT as a1, toTransitionConfigArray as a2, createInvokeTimeoutEventId as a3, matchesActorSession as a4, formatRouteTransitions as a5, resolveStateValue as a6, getAllStateNodes as a7, createMachineSnapshot as a8, isInFinalState as a9, getProperAncestors as aA, isRemoteActorRef as aB, getActorIdPrefix as aC, getAllOwnEvents as aD, matchesEvent as aE, encodeAddressSegment as aF, getRootActorId as aG, RUNTIME_OPERATIONS as aH, withSystemInspector as aI, getSnapshotActorRef as aJ, withExecutionIdentity as aK, createInertActorScope as aa, setInertActorScopeSnapshot as ab, attachSnapshotActorRef as ac, macrostep as ad, isInertActorScope as ae, setSnapshotActorRef as af, cloneMachineSnapshot as ag, transitionNode as ah, getTransitionResult as ai, hasEffect as aj, createErrorPlatformEvent as ak, withActorSelf as al, takeSpawnAllocationCounters as am, mergeActorIdCounters as an, createSpawnEffect as ao, initialMicrostep as ap, toStatePath as aq, isStateId as ar, getStateNodeByPath as as, getPersistedSnapshot as at, createRemoteActorRef as au, resolveReferencedActor as av, createInvokeTimeoutEvent as aw, parseGeneratedActorId as ax, ACTOR_REF_TYPE as ay, hasAmbientInspector as az, builtInActions as b, createTransitionEnqueue as c, deriveDeferredStarts as d, XSTATE_STOP as e, finalizeTransitionResult as f, XSTATE_TIMER as g, createSendToEffect as h, isLazyActorScope as i, isAtomicStateNode as j, createActor as k, createListenerLogic as l, matchesEventDescriptor as m, createSubscriptionLogic as n, listenerLogic as o, parseDelayToMilliseconds as p, getInitialSnapshot as q, resolveActionsWithContext as r, subscriptionLogic as s, toArray as t, getNextSnapshot as u, isMachineSnapshot as v, withActorScope as w, getStateNodes as x, getAllOwnEventDescriptors as y, matchesState as z };