effect-machine 0.10.0 → 0.12.0

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 (81) hide show
  1. package/README.md +65 -62
  2. package/dist/actor.d.ts +35 -97
  3. package/dist/actor.js +69 -98
  4. package/dist/cluster/adapters/in-memory.d.ts +28 -0
  5. package/dist/cluster/adapters/in-memory.js +79 -0
  6. package/dist/cluster/entity-actor-ref.d.ts +56 -0
  7. package/dist/cluster/entity-actor-ref.js +33 -0
  8. package/dist/cluster/entity-machine.d.ts +31 -49
  9. package/dist/cluster/entity-machine.js +167 -52
  10. package/dist/cluster/index.d.ts +5 -2
  11. package/dist/cluster/index.js +4 -1
  12. package/dist/cluster/persistence.d.ts +49 -0
  13. package/dist/cluster/persistence.js +18 -0
  14. package/dist/cluster/to-entity.d.ts +9 -3
  15. package/dist/cluster/to-entity.js +16 -4
  16. package/dist/errors.d.ts +12 -1
  17. package/dist/errors.js +8 -1
  18. package/dist/index.d.ts +5 -8
  19. package/dist/index.js +1 -6
  20. package/dist/internal/brands.d.ts +14 -1
  21. package/dist/internal/runtime.d.ts +67 -0
  22. package/dist/internal/runtime.js +248 -0
  23. package/dist/internal/transition.d.ts +6 -1
  24. package/dist/internal/transition.js +16 -4
  25. package/dist/internal/utils.d.ts +42 -6
  26. package/dist/internal/utils.js +28 -6
  27. package/dist/machine.d.ts +55 -46
  28. package/dist/machine.js +74 -13
  29. package/dist/schema.d.ts +35 -34
  30. package/dist/schema.js +32 -3
  31. package/dist/testing.js +4 -2
  32. package/package.json +4 -4
  33. package/v3/dist/actor.d.ts +29 -96
  34. package/v3/dist/actor.js +52 -97
  35. package/v3/dist/cluster/adapters/in-memory.d.ts +15 -0
  36. package/v3/dist/cluster/adapters/in-memory.js +62 -0
  37. package/v3/dist/cluster/entity-actor-ref.d.ts +49 -0
  38. package/v3/dist/cluster/entity-actor-ref.js +19 -0
  39. package/v3/dist/cluster/entity-machine.d.ts +34 -49
  40. package/v3/dist/cluster/entity-machine.js +134 -50
  41. package/v3/dist/cluster/index.d.ts +5 -2
  42. package/v3/dist/cluster/index.js +4 -1
  43. package/v3/dist/cluster/persistence.d.ts +48 -0
  44. package/v3/dist/cluster/persistence.js +14 -0
  45. package/v3/dist/cluster/to-entity.d.ts +5 -2
  46. package/v3/dist/cluster/to-entity.js +12 -4
  47. package/v3/dist/errors.d.ts +16 -1
  48. package/v3/dist/errors.js +8 -1
  49. package/v3/dist/index.d.ts +5 -8
  50. package/v3/dist/index.js +1 -6
  51. package/v3/dist/internal/brands.d.ts +15 -1
  52. package/v3/dist/internal/runtime.d.ts +65 -0
  53. package/v3/dist/internal/runtime.js +236 -0
  54. package/v3/dist/internal/transition.d.ts +5 -0
  55. package/v3/dist/internal/transition.js +15 -3
  56. package/v3/dist/internal/utils.d.ts +42 -6
  57. package/v3/dist/internal/utils.js +28 -6
  58. package/v3/dist/machine.d.ts +48 -46
  59. package/v3/dist/machine.js +71 -13
  60. package/v3/dist/schema.d.ts +35 -34
  61. package/v3/dist/schema.js +29 -3
  62. package/dist/persistence/adapter.d.ts +0 -135
  63. package/dist/persistence/adapter.js +0 -25
  64. package/dist/persistence/adapters/in-memory.d.ts +0 -32
  65. package/dist/persistence/adapters/in-memory.js +0 -174
  66. package/dist/persistence/index.d.ts +0 -5
  67. package/dist/persistence/index.js +0 -5
  68. package/dist/persistence/persistent-actor.d.ts +0 -50
  69. package/dist/persistence/persistent-actor.js +0 -404
  70. package/dist/persistence/persistent-machine.d.ts +0 -105
  71. package/dist/persistence/persistent-machine.js +0 -22
  72. package/v3/dist/persistence/adapter.d.ts +0 -138
  73. package/v3/dist/persistence/adapter.js +0 -25
  74. package/v3/dist/persistence/adapters/in-memory.d.ts +0 -32
  75. package/v3/dist/persistence/adapters/in-memory.js +0 -174
  76. package/v3/dist/persistence/index.d.ts +0 -5
  77. package/v3/dist/persistence/index.js +0 -5
  78. package/v3/dist/persistence/persistent-actor.d.ts +0 -50
  79. package/v3/dist/persistence/persistent-actor.js +0 -404
  80. package/v3/dist/persistence/persistent-machine.d.ts +0 -105
  81. package/v3/dist/persistence/persistent-machine.js +0 -22
package/README.md CHANGED
@@ -208,7 +208,7 @@ machine
208
208
 
209
209
  ### Event Postpone
210
210
 
211
- `.postpone()` — gen_statem-style event postpone. When a matching event arrives in the given state, it is buffered. After the next state transition (tag change), buffered events drain in FIFO order:
211
+ `.postpone()` — gen_statem-style event postpone. When a matching event arrives in the given state, it is buffered. After the next state transition (tag change), buffered events drain in FIFO order, looping until stable:
212
212
 
213
213
  ```ts
214
214
  machine
@@ -257,6 +257,31 @@ const child = yield * parent.system.get("worker-1"); // Option<ActorRef>
257
257
 
258
258
  Every actor always has a system — `Machine.spawn` creates an implicit one if no `ActorSystem` is in context.
259
259
 
260
+ ### Persistence
261
+
262
+ Persistence is composed from primitives — no built-in adapter or framework:
263
+
264
+ ```ts
265
+ // Snapshot persistence — observe state changes, save externally
266
+ yield * actor.changes.pipe(Stream.runForEach((state) => saveSnapshot(actor.id, state)));
267
+
268
+ // Event journal — observe transitions
269
+ yield * actor.transitions.pipe(Stream.runForEach(({ event }) => appendEvent(actor.id, event)));
270
+
271
+ // Restore from snapshot
272
+ const savedState = yield * loadSnapshot(id);
273
+ const actor = yield * Machine.spawn(machine, { hydrate: savedState });
274
+
275
+ // Restore from event log
276
+ const events = yield * loadEvents(id);
277
+ const state = yield * Machine.replay(machine, events);
278
+ const actor = yield * Machine.spawn(machine, { hydrate: state });
279
+
280
+ // Restore from snapshot + tail events
281
+ const state = yield * Machine.replay(machine, tailEvents, { from: snapshot });
282
+ const actor = yield * Machine.spawn(machine, { hydrate: state });
283
+ ```
284
+
260
285
  ### System Observation
261
286
 
262
287
  React to actors joining and leaving the system:
@@ -296,21 +321,6 @@ expect(result.states.map((s) => s._tag)).toEqual(["Idle", "Loading", "Done"]);
296
321
  yield * assertPath(machine, events, ["Idle", "Loading", "Done"]);
297
322
  ```
298
323
 
299
- ## Documentation
300
-
301
- See the [primer](./primer/) for comprehensive documentation:
302
-
303
- | Topic | File | Description |
304
- | ----------- | ----------------------------------------- | ------------------------------ |
305
- | Overview | [index.md](./primer/index.md) | Navigation and quick reference |
306
- | Basics | [basics.md](./primer/basics.md) | Core concepts |
307
- | Handlers | [handlers.md](./primer/handlers.md) | Transitions, guards, reply |
308
- | Effects | [effects.md](./primer/effects.md) | spawn, background, timeouts |
309
- | Testing | [testing.md](./primer/testing.md) | simulate, harness, assertions |
310
- | Actors | [actors.md](./primer/actors.md) | ActorSystem, ActorRef |
311
- | Persistence | [persistence.md](./primer/persistence.md) | Snapshots, event sourcing |
312
- | Gotchas | [gotchas.md](./primer/gotchas.md) | Common mistakes |
313
-
314
324
  ## API Quick Reference
315
325
 
316
326
  ### Building
@@ -330,58 +340,41 @@ See the [primer](./primer/) for comprehensive documentation:
330
340
  | `.final(State.X)` | Mark final state |
331
341
  | `.build({ slot: impl })` | Provide implementations, returns `BuiltMachine` (terminal) |
332
342
  | `.build()` | Finalize no-slot machine, returns `BuiltMachine` (terminal) |
333
- | `.persist(config)` | Enable persistence |
334
-
335
- ### State Constructors
336
-
337
- | Method | Purpose |
338
- | -------------------------------------- | ------------------------------ |
339
- | `State.X.derive(source)` | Pick target fields from source |
340
- | `State.X.derive(source, { field: v })` | Pick fields + apply overrides |
341
- | `State.$is("X")(value)` | Type guard |
342
- | `State.$match(value, { X: fn, ... })` | Pattern matching |
343
343
 
344
344
  ### Running
345
345
 
346
- | Method | Purpose |
347
- | ---------------------------- | ------------------------------------------------------------------------------------------------------- |
348
- | `Machine.spawn(machine)` | Single actor, no registry. Caller manages lifetime via `actor.stop`. Auto-cleans up if `Scope` present. |
349
- | `Machine.spawn(machine, id)` | Same as above with custom ID |
350
- | `system.spawn(id, machine)` | Registry, lookup by ID, bulk ops, persistence. Cleans up on system teardown. |
351
-
352
- ### Testing
353
-
354
- | Function | Description |
355
- | ------------------------------------------ | ---------------------------------------------------------------- |
356
- | `simulate(machine, events)` | Run events, get all states (accepts `Machine` or `BuiltMachine`) |
357
- | `createTestHarness(machine)` | Step-by-step testing (accepts `Machine` or `BuiltMachine`) |
358
- | `assertPath(machine, events, path)` | Assert exact path |
359
- | `assertReaches(machine, events, tag)` | Assert final state |
360
- | `assertNeverReaches(machine, events, tag)` | Assert state never visited |
346
+ | Method | Purpose |
347
+ | ---------------------------------------- | ------------------------------------------------------------------------------------------------------- |
348
+ | `Machine.spawn(machine)` | Single actor, no registry. Caller manages lifetime via `actor.stop`. Auto-cleans up if `Scope` present. |
349
+ | `Machine.spawn(machine, id)` | Same as above with custom ID |
350
+ | `Machine.spawn(machine, { hydrate: s })` | Restore from saved state re-runs spawn effects for that state |
351
+ | `Machine.replay(machine, events)` | Fold events through handlers to compute state (for event sourcing restore) |
352
+ | `system.spawn(id, machine)` | Registry, lookup by ID, bulk ops. Cleans up on system teardown. |
361
353
 
362
354
  ### Actor
363
355
 
364
- | Method | Description |
365
- | -------------------------------- | ------------------------------------------- |
366
- | `actor.send(event)` | Fire-and-forget (queue event) |
367
- | `actor.cast(event)` | Alias for send (OTP gen_server:cast) |
368
- | `actor.call(event)` | Request-reply, returns `ProcessEventResult` |
369
- | `actor.ask<R>(event)` | Typed domain reply from handler |
370
- | `actor.snapshot` | Get current state |
371
- | `actor.matches(tag)` | Check state tag |
372
- | `actor.can(event)` | Can handle event? |
373
- | `actor.changes` | Stream of changes |
374
- | `actor.waitFor(State.X)` | Wait for state (constructor or fn) |
375
- | `actor.awaitFinal` | Wait final state |
376
- | `actor.sendAndWait(ev, State.X)` | Send + wait for state |
377
- | `actor.subscribe(fn)` | Sync callback |
378
- | `actor.sync.send(event)` | Sync fire-and-forget (for UI) |
379
- | `actor.sync.stop()` | Sync stop |
380
- | `actor.sync.snapshot()` | Sync get state |
381
- | `actor.sync.matches(tag)` | Sync check state tag |
382
- | `actor.sync.can(event)` | Sync can handle event? |
383
- | `actor.system` | Access the actor's `ActorSystem` |
384
- | `actor.children` | Child actors (`ReadonlyMap`) |
356
+ | Method | Description |
357
+ | -------------------------------- | ----------------------------------------------- |
358
+ | `actor.send(event)` | Fire-and-forget (queue event) |
359
+ | `actor.cast(event)` | Alias for send (OTP gen_server:cast) |
360
+ | `actor.call(event)` | Request-reply, returns `ProcessEventResult` |
361
+ | `actor.ask<R>(event)` | Typed domain reply from handler |
362
+ | `actor.snapshot` | Get current state |
363
+ | `actor.matches(tag)` | Check state tag |
364
+ | `actor.can(event)` | Can handle event? |
365
+ | `actor.changes` | Stream of state changes |
366
+ | `actor.transitions` | Stream of `{ fromState, toState, event }` edges |
367
+ | `actor.waitFor(State.X)` | Wait for state (constructor or fn) |
368
+ | `actor.awaitFinal` | Wait final state |
369
+ | `actor.sendAndWait(ev, State.X)` | Send + wait for state |
370
+ | `actor.subscribe(fn)` | Sync callback |
371
+ | `actor.sync.send(event)` | Sync fire-and-forget (for UI) |
372
+ | `actor.sync.stop()` | Sync stop |
373
+ | `actor.sync.snapshot()` | Sync get state |
374
+ | `actor.sync.matches(tag)` | Sync check state tag |
375
+ | `actor.sync.can(event)` | Sync can handle event? |
376
+ | `actor.system` | Access the actor's `ActorSystem` |
377
+ | `actor.children` | Child actors (`ReadonlyMap`) |
385
378
 
386
379
  ### ActorSystem
387
380
 
@@ -394,6 +387,16 @@ See the [primer](./primer/) for comprehensive documentation:
394
387
  | `system.subscribe(fn)` | Sync callback for spawn/stop events |
395
388
  | `system.events` | Async `Stream<SystemEvent>` for spawn/stop |
396
389
 
390
+ ### Testing
391
+
392
+ | Function | Description |
393
+ | ------------------------------------------ | ---------------------------------------------------------------- |
394
+ | `simulate(machine, events)` | Run events, get all states (accepts `Machine` or `BuiltMachine`) |
395
+ | `createTestHarness(machine)` | Step-by-step testing (accepts `Machine` or `BuiltMachine`) |
396
+ | `assertPath(machine, events, path)` | Assert exact path |
397
+ | `assertReaches(machine, events, tag)` | Assert final state |
398
+ | `assertNeverReaches(machine, events, tag)` | Assert state never visited |
399
+
397
400
  ## License
398
401
 
399
402
  MIT
package/dist/actor.d.ts CHANGED
@@ -1,11 +1,9 @@
1
1
  import { EffectsDef, GuardsDef, MachineContext } from "./slot.js";
2
- import { PersistentMachine } from "./persistence/persistent-machine.js";
2
+ import { ExtractReply, ReplyTypeBrand } from "./internal/brands.js";
3
3
  import { ActorStoppedError, DuplicateActorError, NoReplyError } from "./errors.js";
4
4
  import { ProcessEventError, ProcessEventHooks, ProcessEventResult, processEventCore, resolveTransition, runSpawnEffects } from "./internal/transition.js";
5
- import { PersistentActorRef } from "./persistence/persistent-actor.js";
6
- import { ActorMetadata, PersistenceAdapterTag, PersistenceError, RestoreResult, VersionConflictError } from "./persistence/adapter.js";
7
5
  import { BuiltMachine, Machine, MachineRef } from "./machine.js";
8
- import { Deferred, Effect, Layer, Option, Queue, Ref, Scope, ServiceMap, Stream, SubscriptionRef } from "effect";
6
+ import { Deferred, Effect, Layer, Option, PubSub, Queue, Ref, Scope, ServiceMap, Stream, SubscriptionRef } from "effect";
9
7
  import * as effect_Tracer0 from "effect/Tracer";
10
8
 
11
9
  //#region src/actor.d.ts
@@ -39,6 +37,15 @@ interface ActorRefSync<State extends {
39
37
  readonly matches: (tag: State["_tag"]) => boolean;
40
38
  readonly can: (event: Event) => boolean;
41
39
  }
40
+ /**
41
+ * Information about a successful transition.
42
+ * Emitted on the `transitions` stream after each accepted event.
43
+ */
44
+ interface TransitionInfo<State, Event> {
45
+ readonly fromState: State;
46
+ readonly toState: State;
47
+ readonly event: Event;
48
+ }
42
49
  interface ActorRef<State extends {
43
50
  readonly _tag: string;
44
51
  }, Event> {
@@ -53,11 +60,11 @@ interface ActorRef<State extends {
53
60
  */
54
61
  readonly call: (event: Event) => Effect.Effect<ProcessEventResult<State>>;
55
62
  /**
56
- * Typed request-reply. Event is processed through the queue; caller gets
57
- * the domain value returned by the handler's `reply` field.
63
+ * Typed request-reply. Accepts only events with a reply schema
64
+ * (defined via `Event.reply()`). Return type is inferred from the schema.
58
65
  * Fails with NoReplyError if the handler doesn't provide a reply.
59
66
  */
60
- readonly ask: <R>(event: Event) => Effect.Effect<R, NoReplyError | ActorStoppedError>;
67
+ readonly ask: <E extends Event & ReplyTypeBrand<unknown>>(event: E) => Effect.Effect<ExtractReply<E>, NoReplyError | ActorStoppedError>;
61
68
  /** Observable state. */
62
69
  readonly state: SubscriptionRef.SubscriptionRef<State>;
63
70
  /** Stop the actor gracefully. */
@@ -70,6 +77,14 @@ interface ActorRef<State extends {
70
77
  readonly can: (event: Event) => Effect.Effect<boolean>;
71
78
  /** Stream of state changes. */
72
79
  readonly changes: Stream.Stream<State>;
80
+ /**
81
+ * Stream of accepted transitions (edge stream).
82
+ *
83
+ * Emits `{ fromState, toState, event }` on every successful transition,
84
+ * including same-state reenters. PubSub-backed — late subscribers miss
85
+ * past edges. This is observational, not a durability guarantee.
86
+ */
87
+ readonly transitions: Stream.Stream<TransitionInfo<State, Event>>;
73
88
  /** Wait for a state matching predicate or variant (includes current snapshot). */
74
89
  readonly waitFor: {
75
90
  (predicate: (state: State) => boolean): Effect.Effect<State>;
@@ -123,54 +138,17 @@ interface ActorSystem {
123
138
  /**
124
139
  * Spawn a new actor with the given machine.
125
140
  *
126
- * For regular machines, returns ActorRef.
127
- * For persistent machines (created with Machine.persist), returns PersistentActorRef.
128
- *
129
- * All effect slots must be provided via `.build()` before spawning.
130
- *
131
141
  * @example
132
142
  * ```ts
133
- * // Regular machine (built)
134
143
  * const built = machine.build({ fetchData: ... })
135
144
  * const actor = yield* system.spawn("my-actor", built);
136
- *
137
- * // Persistent machine (auto-detected)
138
- * const persistentActor = yield* system.spawn("my-actor", persistentMachine);
139
- * persistentActor.persist; // available
140
- * persistentActor.version; // available
141
145
  * ```
142
146
  */
143
- readonly spawn: {
144
- <S extends {
145
- readonly _tag: string;
146
- }, E extends {
147
- readonly _tag: string;
148
- }, R>(id: string, machine: BuiltMachine<S, E, R>): Effect.Effect<ActorRef<S, E>, DuplicateActorError, R>;
149
- <S extends {
150
- readonly _tag: string;
151
- }, E extends {
152
- readonly _tag: string;
153
- }, R>(id: string, machine: PersistentMachine<S, E, R>): Effect.Effect<PersistentActorRef<S, E, R>, PersistenceError | VersionConflictError | DuplicateActorError, R | PersistenceAdapterTag>;
154
- };
155
- /**
156
- * Restore an actor from persistence.
157
- * Returns None if no persisted state exists for the given ID.
158
- *
159
- * @example
160
- * ```ts
161
- * const maybeActor = yield* system.restore("order-1", persistentMachine);
162
- * if (Option.isSome(maybeActor)) {
163
- * const actor = maybeActor.value;
164
- * const state = yield* actor.snapshot;
165
- * console.log(`Restored to state: ${state._tag}`);
166
- * }
167
- * ```
168
- */
169
- readonly restore: <S extends {
147
+ readonly spawn: <S extends {
170
148
  readonly _tag: string;
171
149
  }, E extends {
172
150
  readonly _tag: string;
173
- }, R>(id: string, machine: PersistentMachine<S, E, R>) => Effect.Effect<Option.Option<PersistentActorRef<S, E, R>>, PersistenceError | DuplicateActorError, R | PersistenceAdapterTag>;
151
+ }, R>(id: string, machine: BuiltMachine<S, E, R>) => Effect.Effect<ActorRef<S, E>, DuplicateActorError, R>;
174
152
  /**
175
153
  * Get an existing actor by ID
176
154
  */
@@ -194,53 +172,6 @@ interface ActorSystem {
194
172
  * Returns an unsubscribe function.
195
173
  */
196
174
  readonly subscribe: (fn: SystemEventListener) => () => void;
197
- /**
198
- * List all persisted actor metadata.
199
- * Returns empty array if adapter doesn't support registry.
200
- *
201
- * @example
202
- * ```ts
203
- * const actors = yield* system.listPersisted();
204
- * for (const meta of actors) {
205
- * console.log(`${meta.id}: ${meta.stateTag} (v${meta.version})`);
206
- * }
207
- * ```
208
- */
209
- readonly listPersisted: () => Effect.Effect<ReadonlyArray<ActorMetadata>, PersistenceError, PersistenceAdapterTag>;
210
- /**
211
- * Restore multiple actors by ID.
212
- * Returns both successfully restored actors and failures.
213
- *
214
- * @example
215
- * ```ts
216
- * const result = yield* system.restoreMany(["order-1", "order-2"], orderMachine);
217
- * console.log(`Restored: ${result.restored.length}, Failed: ${result.failed.length}`);
218
- * ```
219
- */
220
- readonly restoreMany: <S extends {
221
- readonly _tag: string;
222
- }, E extends {
223
- readonly _tag: string;
224
- }, R>(ids: ReadonlyArray<string>, machine: PersistentMachine<S, E, R>) => Effect.Effect<RestoreResult<S, E, R>, never, R | PersistenceAdapterTag>;
225
- /**
226
- * Restore all persisted actors for a machine type.
227
- * Uses adapter registry if available, otherwise returns empty result.
228
- *
229
- * @example
230
- * ```ts
231
- * const result = yield* system.restoreAll(orderMachine, {
232
- * filter: (meta) => meta.stateTag !== "Done"
233
- * });
234
- * console.log(`Restored ${result.restored.length} active orders`);
235
- * ```
236
- */
237
- readonly restoreAll: <S extends {
238
- readonly _tag: string;
239
- }, E extends {
240
- readonly _tag: string;
241
- }, R>(machine: PersistentMachine<S, E, R>, options?: {
242
- filter?: (meta: ActorMetadata) => boolean;
243
- }) => Effect.Effect<RestoreResult<S, E, R>, PersistenceError, R | PersistenceAdapterTag>;
244
175
  }
245
176
  /**
246
177
  * ActorSystem service tag
@@ -253,13 +184,13 @@ type Listeners<S> = Set<(state: S) => void>;
253
184
  */
254
185
  declare const notifyListeners: <S>(listeners: Listeners<S>, state: S) => void;
255
186
  /**
256
- * Build core ActorRef methods shared between regular and persistent actors.
187
+ * Build core ActorRef methods.
257
188
  */
258
189
  declare const buildActorRefCore: <S extends {
259
190
  readonly _tag: string;
260
191
  }, E extends {
261
192
  readonly _tag: string;
262
- }, R, GD extends GuardsDef, EFD extends EffectsDef>(id: string, machine: Machine<S, E, R, any, any, GD, EFD>, stateRef: SubscriptionRef.SubscriptionRef<S>, eventQueue: Queue.Queue<QueuedEvent<E>>, stoppedRef: Ref.Ref<boolean>, listeners: Listeners<S>, stop: Effect.Effect<void>, system: ActorSystem, childrenMap: ReadonlyMap<string, ActorRef<AnyState, unknown>>, pendingReplies: Set<Deferred.Deferred<unknown, unknown>>) => ActorRef<S, E>;
193
+ }, R, GD extends GuardsDef, EFD extends EffectsDef>(id: string, machine: Machine<S, E, R, any, any, GD, EFD>, stateRef: SubscriptionRef.SubscriptionRef<S>, eventQueue: Queue.Queue<QueuedEvent<E>>, stoppedRef: Ref.Ref<boolean>, listeners: Listeners<S>, stop: Effect.Effect<void>, system: ActorSystem, childrenMap: ReadonlyMap<string, ActorRef<AnyState, unknown>>, pendingReplies: Set<Deferred.Deferred<unknown, unknown>>, transitionsPubSub?: PubSub.PubSub<TransitionInfo<S, E>>) => ActorRef<S, E>;
263
194
  /**
264
195
  * Create and start an actor for a machine
265
196
  */
@@ -267,12 +198,19 @@ declare const createActor: <S extends {
267
198
  readonly _tag: string;
268
199
  }, E extends {
269
200
  readonly _tag: string;
270
- }, R, GD extends GuardsDef, EFD extends EffectsDef>(id: string, machine: Machine<S, E, R, Record<string, never>, Record<string, never>, GD, EFD>) => Effect.Effect<ActorRef<S, E>, never, Exclude<R, MachineContext<S, E, MachineRef<E>>> | Exclude<Exclude<R, MachineContext<S, E, MachineRef<E>>>, effect_Tracer0.ParentSpan> | Exclude<Exclude<R, MachineContext<S, E, MachineRef<E>>>, Scope.Scope> | Exclude<Exclude<Exclude<R, MachineContext<S, E, MachineRef<E>>>, Scope.Scope>, effect_Tracer0.ParentSpan>>;
201
+ }, R, GD extends GuardsDef, EFD extends EffectsDef>(id: string, machine: Machine<S, E, R, Record<string, never>, Record<string, never>, GD, EFD>, options?: {
202
+ initialState?: S;
203
+ } | undefined) => Effect.Effect<ActorRef<S, E>, never, Exclude<R, MachineContext<S, E, MachineRef<E>>> | Exclude<Exclude<R, MachineContext<S, E, MachineRef<E>>>, effect_Tracer0.ParentSpan> | Exclude<Exclude<R, MachineContext<S, E, MachineRef<E>>>, Scope.Scope> | Exclude<Exclude<Exclude<R, MachineContext<S, E, MachineRef<E>>>, Scope.Scope>, effect_Tracer0.ParentSpan>>;
271
204
  /** Fail all pending call/ask Deferreds with ActorStoppedError. Safe to call multiple times. */
272
205
  declare const settlePendingReplies: (pendingReplies: Set<Deferred.Deferred<unknown, unknown>>, actorId: string) => Effect.Effect<void, never, never>;
206
+ /**
207
+ * Create an ActorSystem instance. Must be run in a Scope.
208
+ * @internal — use Default layer for normal usage
209
+ */
210
+ declare const makeSystem: () => Effect.Effect<ActorSystem, never, Scope.Scope>;
273
211
  /**
274
212
  * Default ActorSystem layer
275
213
  */
276
214
  declare const Default: Layer.Layer<ActorSystem, never, never>;
277
215
  //#endregion
278
- export { ActorRef, ActorRefSync, ActorSystem, Default, Listeners, type ProcessEventError, type ProcessEventHooks, type ProcessEventResult, QueuedEvent, SystemEvent, SystemEventListener, buildActorRefCore, createActor, notifyListeners, processEventCore, resolveTransition, runSpawnEffects, settlePendingReplies };
216
+ export { ActorRef, ActorRefSync, ActorSystem, Default, Listeners, type ProcessEventError, type ProcessEventHooks, type ProcessEventResult, QueuedEvent, SystemEvent, SystemEventListener, TransitionInfo, buildActorRefCore, createActor, makeSystem, notifyListeners, processEventCore, resolveTransition, runSpawnEffects, settlePendingReplies };