@typeonce/effect-machine 0.47.1 → 0.48.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 (334) hide show
  1. package/AGENTS.md +374 -22
  2. package/CLAUDE.md +374 -22
  3. package/README.md +56 -7
  4. package/ai-docs/src/10_modeling/01_create-a-machine.ts +3 -3
  5. package/ai-docs/src/10_modeling/index.md +64 -17
  6. package/ai-docs/src/20_root-api/index.md +2 -2
  7. package/ai-docs/src/35_cluster/index.md +213 -0
  8. package/ai-docs/src/37_new-host/index.md +90 -0
  9. package/dist/LocalMachine.d.ts +417 -0
  10. package/dist/LocalMachine.d.ts.map +1 -0
  11. package/dist/LocalMachine.js +193 -0
  12. package/dist/LocalMachine.js.map +1 -0
  13. package/dist/Machine.d.ts +1120 -812
  14. package/dist/Machine.d.ts.map +1 -1
  15. package/dist/Machine.js +195 -186
  16. package/dist/Machine.js.map +1 -1
  17. package/dist/index.d.ts +1 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +1 -0
  20. package/dist/index.js.map +1 -1
  21. package/dist/internal/machine/atom.d.ts +8 -10
  22. package/dist/internal/machine/atom.d.ts.map +1 -1
  23. package/dist/internal/machine/atom.js +7 -6
  24. package/dist/internal/machine/atom.js.map +1 -1
  25. package/dist/internal/machine/capability.d.ts +101 -0
  26. package/dist/internal/machine/capability.d.ts.map +1 -0
  27. package/dist/internal/machine/capability.js +70 -0
  28. package/dist/internal/machine/capability.js.map +1 -0
  29. package/dist/internal/machine/{invocationDefinition.d.ts → capturedInvocation.d.ts} +11 -11
  30. package/dist/internal/machine/capturedInvocation.d.ts.map +1 -0
  31. package/dist/internal/machine/{invocationDefinition.js → capturedInvocation.js} +2 -2
  32. package/dist/internal/machine/capturedInvocation.js.map +1 -0
  33. package/dist/internal/machine/child.d.ts +14 -0
  34. package/dist/internal/machine/child.d.ts.map +1 -0
  35. package/dist/internal/machine/child.js +19 -0
  36. package/dist/internal/machine/child.js.map +1 -0
  37. package/dist/internal/machine/childRegistry.d.ts +0 -2
  38. package/dist/internal/machine/childRegistry.d.ts.map +1 -1
  39. package/dist/internal/machine/childRegistry.js +2 -2
  40. package/dist/internal/machine/childRegistry.js.map +1 -1
  41. package/dist/internal/machine/cluster.d.ts +19 -4
  42. package/dist/internal/machine/cluster.d.ts.map +1 -1
  43. package/dist/internal/machine/cluster.js +263 -110
  44. package/dist/internal/machine/cluster.js.map +1 -1
  45. package/dist/internal/machine/clusterChild.d.ts +66 -0
  46. package/dist/internal/machine/clusterChild.d.ts.map +1 -0
  47. package/dist/internal/machine/clusterChild.js +105 -0
  48. package/dist/internal/machine/clusterChild.js.map +1 -0
  49. package/dist/internal/machine/clusterFailure.d.ts +14 -0
  50. package/dist/internal/machine/clusterFailure.d.ts.map +1 -0
  51. package/dist/internal/machine/clusterFailure.js +44 -0
  52. package/dist/internal/machine/clusterFailure.js.map +1 -0
  53. package/dist/internal/machine/clusterInstance.d.ts +194 -0
  54. package/dist/internal/machine/clusterInstance.d.ts.map +1 -0
  55. package/dist/internal/machine/clusterInstance.js +1076 -0
  56. package/dist/internal/machine/clusterInstance.js.map +1 -0
  57. package/dist/internal/machine/clusterKeepAlive.d.ts +47 -0
  58. package/dist/internal/machine/clusterKeepAlive.d.ts.map +1 -0
  59. package/dist/internal/machine/clusterKeepAlive.js +72 -0
  60. package/dist/internal/machine/clusterKeepAlive.js.map +1 -0
  61. package/dist/internal/machine/clusterProgress.d.ts +73 -0
  62. package/dist/internal/machine/clusterProgress.d.ts.map +1 -0
  63. package/dist/internal/machine/clusterProgress.js +116 -0
  64. package/dist/internal/machine/clusterProgress.js.map +1 -0
  65. package/dist/internal/machine/clusterProtocol.d.ts +37 -4
  66. package/dist/internal/machine/clusterProtocol.d.ts.map +1 -1
  67. package/dist/internal/machine/clusterProtocol.js +18 -4
  68. package/dist/internal/machine/clusterProtocol.js.map +1 -1
  69. package/dist/internal/machine/clusterProxy.d.ts +46 -0
  70. package/dist/internal/machine/clusterProxy.d.ts.map +1 -0
  71. package/dist/internal/machine/clusterProxy.js +150 -0
  72. package/dist/internal/machine/clusterProxy.js.map +1 -0
  73. package/dist/internal/machine/clusterRead.d.ts +61 -0
  74. package/dist/internal/machine/clusterRead.d.ts.map +1 -0
  75. package/dist/internal/machine/clusterRead.js +108 -0
  76. package/dist/internal/machine/clusterRead.js.map +1 -0
  77. package/dist/internal/machine/clusterSqlStorage.d.ts +16 -0
  78. package/dist/internal/machine/clusterSqlStorage.d.ts.map +1 -0
  79. package/dist/internal/machine/clusterSqlStorage.js +138 -0
  80. package/dist/internal/machine/clusterSqlStorage.js.map +1 -0
  81. package/dist/internal/machine/clusterStorageCheck.d.ts +19 -0
  82. package/dist/internal/machine/clusterStorageCheck.d.ts.map +1 -0
  83. package/dist/internal/machine/clusterStorageCheck.js +186 -0
  84. package/dist/internal/machine/clusterStorageCheck.js.map +1 -0
  85. package/dist/internal/machine/clusterTarget.d.ts +74 -0
  86. package/dist/internal/machine/clusterTarget.d.ts.map +1 -0
  87. package/dist/internal/machine/clusterTarget.js +81 -0
  88. package/dist/internal/machine/clusterTarget.js.map +1 -0
  89. package/dist/internal/machine/clusterTimer.d.ts +21 -0
  90. package/dist/internal/machine/clusterTimer.d.ts.map +1 -0
  91. package/dist/internal/machine/clusterTimer.js +50 -0
  92. package/dist/internal/machine/clusterTimer.js.map +1 -0
  93. package/dist/internal/machine/clusterWake.d.ts +61 -0
  94. package/dist/internal/machine/clusterWake.d.ts.map +1 -0
  95. package/dist/internal/machine/clusterWake.js +81 -0
  96. package/dist/internal/machine/clusterWake.js.map +1 -0
  97. package/dist/internal/machine/clusterWork.d.ts +130 -0
  98. package/dist/internal/machine/clusterWork.d.ts.map +1 -0
  99. package/dist/internal/machine/clusterWork.js +191 -0
  100. package/dist/internal/machine/clusterWork.js.map +1 -0
  101. package/dist/internal/machine/command.d.ts +4 -4
  102. package/dist/internal/machine/command.d.ts.map +1 -1
  103. package/dist/internal/machine/commandRuntime.d.ts +8 -6
  104. package/dist/internal/machine/commandRuntime.d.ts.map +1 -1
  105. package/dist/internal/machine/commandRuntime.js +1 -5
  106. package/dist/internal/machine/commandRuntime.js.map +1 -1
  107. package/dist/internal/machine/configuration.d.ts +0 -13
  108. package/dist/internal/machine/configuration.d.ts.map +1 -1
  109. package/dist/internal/machine/configuration.js +0 -151
  110. package/dist/internal/machine/configuration.js.map +1 -1
  111. package/dist/internal/machine/errors.d.ts +11 -2
  112. package/dist/internal/machine/errors.d.ts.map +1 -1
  113. package/dist/internal/machine/errors.js +11 -2
  114. package/dist/internal/machine/errors.js.map +1 -1
  115. package/dist/internal/machine/executionPlan.d.ts +45 -3
  116. package/dist/internal/machine/executionPlan.d.ts.map +1 -1
  117. package/dist/internal/machine/executionPlan.js +328 -191
  118. package/dist/internal/machine/executionPlan.js.map +1 -1
  119. package/dist/internal/machine/implementation.d.ts +6 -6
  120. package/dist/internal/machine/implementation.d.ts.map +1 -1
  121. package/dist/internal/machine/inspectionRuntime.d.ts +1 -1
  122. package/dist/internal/machine/inspectionRuntime.d.ts.map +1 -1
  123. package/dist/internal/machine/invocationChanges.d.ts +60 -0
  124. package/dist/internal/machine/invocationChanges.d.ts.map +1 -0
  125. package/dist/internal/machine/invocationChanges.js +54 -0
  126. package/dist/internal/machine/invocationChanges.js.map +1 -0
  127. package/dist/internal/machine/{activities.d.ts → invocationDefinitions.d.ts} +8 -8
  128. package/dist/internal/machine/invocationDefinitions.d.ts.map +1 -0
  129. package/dist/internal/machine/{activities.js → invocationDefinitions.js} +5 -5
  130. package/dist/internal/machine/invocationDefinitions.js.map +1 -0
  131. package/dist/internal/machine/invocationEvent.d.ts +16 -7
  132. package/dist/internal/machine/invocationEvent.d.ts.map +1 -1
  133. package/dist/internal/machine/invocationEvent.js +26 -12
  134. package/dist/internal/machine/invocationEvent.js.map +1 -1
  135. package/dist/internal/machine/invocationOutcome.d.ts +89 -0
  136. package/dist/internal/machine/invocationOutcome.d.ts.map +1 -0
  137. package/dist/internal/machine/invocationOutcome.js +76 -0
  138. package/dist/internal/machine/invocationOutcome.js.map +1 -0
  139. package/dist/internal/machine/invocationResolution.d.ts +137 -0
  140. package/dist/internal/machine/invocationResolution.d.ts.map +1 -0
  141. package/dist/internal/machine/invocationResolution.js +150 -0
  142. package/dist/internal/machine/invocationResolution.js.map +1 -0
  143. package/dist/internal/machine/logicScope.d.ts +24 -0
  144. package/dist/internal/machine/logicScope.d.ts.map +1 -0
  145. package/dist/internal/machine/logicScope.js +33 -0
  146. package/dist/internal/machine/logicScope.js.map +1 -0
  147. package/dist/internal/machine/machine.d.ts +17 -23
  148. package/dist/internal/machine/machine.d.ts.map +1 -1
  149. package/dist/internal/machine/machine.js +24 -40
  150. package/dist/internal/machine/machine.js.map +1 -1
  151. package/dist/internal/machine/observation.d.ts +3 -0
  152. package/dist/internal/machine/observation.d.ts.map +1 -1
  153. package/dist/internal/machine/observation.js +56 -2
  154. package/dist/internal/machine/observation.js.map +1 -1
  155. package/dist/internal/machine/plannedSnapshot.d.ts.map +1 -1
  156. package/dist/internal/machine/plannedSnapshot.js +11 -20
  157. package/dist/internal/machine/plannedSnapshot.js.map +1 -1
  158. package/dist/internal/machine/planner.d.ts +36 -23
  159. package/dist/internal/machine/planner.d.ts.map +1 -1
  160. package/dist/internal/machine/planner.js +15 -8
  161. package/dist/internal/machine/planner.js.map +1 -1
  162. package/dist/internal/machine/process.d.ts +17 -9
  163. package/dist/internal/machine/process.d.ts.map +1 -1
  164. package/dist/internal/machine/process.js +43 -503
  165. package/dist/internal/machine/process.js.map +1 -1
  166. package/dist/internal/machine/protocol.d.ts +1 -1
  167. package/dist/internal/machine/protocol.d.ts.map +1 -1
  168. package/dist/internal/machine/protocol.js +48 -10
  169. package/dist/internal/machine/protocol.js.map +1 -1
  170. package/dist/internal/machine/runtime.d.ts +20 -16
  171. package/dist/internal/machine/runtime.d.ts.map +1 -1
  172. package/dist/internal/machine/runtime.js +93 -88
  173. package/dist/internal/machine/runtime.js.map +1 -1
  174. package/dist/internal/machine/runtimeCompiled.d.ts.map +1 -1
  175. package/dist/internal/machine/runtimeCompiled.js +359 -120
  176. package/dist/internal/machine/runtimeCompiled.js.map +1 -1
  177. package/dist/internal/machine/runtimeProtocol.d.ts +151 -82
  178. package/dist/internal/machine/runtimeProtocol.d.ts.map +1 -1
  179. package/dist/internal/machine/runtimeProtocol.js +236 -219
  180. package/dist/internal/machine/runtimeProtocol.js.map +1 -1
  181. package/dist/internal/machine/stateDefinition.d.ts +0 -1
  182. package/dist/internal/machine/stateDefinition.d.ts.map +1 -1
  183. package/dist/internal/machine/stateDefinition.js +0 -1
  184. package/dist/internal/machine/stateDefinition.js.map +1 -1
  185. package/dist/internal/machine/step.d.ts +486 -0
  186. package/dist/internal/machine/step.d.ts.map +1 -0
  187. package/dist/internal/machine/step.js +957 -0
  188. package/dist/internal/machine/step.js.map +1 -0
  189. package/dist/internal/machine/stepHost.d.ts +33 -0
  190. package/dist/internal/machine/stepHost.d.ts.map +1 -0
  191. package/dist/internal/machine/stepHost.js +501 -0
  192. package/dist/internal/machine/stepHost.js.map +1 -0
  193. package/dist/internal/machine/symbols.d.ts +2 -11
  194. package/dist/internal/machine/symbols.d.ts.map +1 -1
  195. package/dist/internal/machine/symbols.js +2 -2
  196. package/dist/internal/machine/symbols.js.map +1 -1
  197. package/dist/internal/machine/transition.d.ts +7 -7
  198. package/dist/internal/machine/transition.d.ts.map +1 -1
  199. package/dist/internal/testing/machine/check.d.ts.map +1 -1
  200. package/dist/internal/testing/machine/check.js +217 -25
  201. package/dist/internal/testing/machine/check.js.map +1 -1
  202. package/dist/internal/testing/machine/exploration.d.ts +19 -2
  203. package/dist/internal/testing/machine/exploration.d.ts.map +1 -1
  204. package/dist/internal/testing/machine/exploration.js +14 -3
  205. package/dist/internal/testing/machine/exploration.js.map +1 -1
  206. package/dist/internal/testing/machine/format.js.map +1 -1
  207. package/dist/internal/testing/machine/probe.d.ts.map +1 -1
  208. package/dist/internal/testing/machine/probe.js +1 -1
  209. package/dist/internal/testing/machine/probe.js.map +1 -1
  210. package/dist/internal/testing/machine/runtime.d.ts +2 -2
  211. package/dist/internal/testing/machine/runtime.d.ts.map +1 -1
  212. package/dist/internal/testing/machine/runtime.js +10 -3
  213. package/dist/internal/testing/machine/runtime.js.map +1 -1
  214. package/dist/internal/testing/machine/trace.d.ts +38 -3
  215. package/dist/internal/testing/machine/trace.d.ts.map +1 -1
  216. package/dist/internal/testing/machine/trace.js +180 -33
  217. package/dist/internal/testing/machine/trace.js.map +1 -1
  218. package/dist/internal/testing/machine/transitionCoverage.d.ts +1 -1
  219. package/dist/internal/testing/machine/transitionCoverage.d.ts.map +1 -1
  220. package/dist/internal/testing/machine/verification.d.ts.map +1 -1
  221. package/dist/internal/testing/machine/verification.js +9 -1
  222. package/dist/internal/testing/machine/verification.js.map +1 -1
  223. package/dist/internal/testing/machine/work.d.ts +47 -0
  224. package/dist/internal/testing/machine/work.d.ts.map +1 -0
  225. package/dist/internal/testing/machine/work.js +74 -0
  226. package/dist/internal/testing/machine/work.js.map +1 -0
  227. package/dist/testing/MachineTest.d.ts +253 -37
  228. package/dist/testing/MachineTest.d.ts.map +1 -1
  229. package/dist/testing/MachineTest.js +81 -9
  230. package/dist/testing/MachineTest.js.map +1 -1
  231. package/dist/unstable/cluster/ClusterMachine.d.ts +1071 -41
  232. package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
  233. package/dist/unstable/cluster/ClusterMachine.js +441 -12
  234. package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
  235. package/dist/unstable/cluster/ClusterMachineProxy.d.ts +257 -0
  236. package/dist/unstable/cluster/ClusterMachineProxy.d.ts.map +1 -0
  237. package/dist/unstable/cluster/ClusterMachineProxy.js +73 -0
  238. package/dist/unstable/cluster/ClusterMachineProxy.js.map +1 -0
  239. package/dist/unstable/cluster/SqlMachineStorage.d.ts +125 -0
  240. package/dist/unstable/cluster/SqlMachineStorage.d.ts.map +1 -0
  241. package/dist/unstable/cluster/SqlMachineStorage.js +62 -0
  242. package/dist/unstable/cluster/SqlMachineStorage.js.map +1 -0
  243. package/dist/unstable/cluster/index.d.ts +13 -0
  244. package/dist/unstable/cluster/index.d.ts.map +1 -1
  245. package/dist/unstable/cluster/index.js +13 -0
  246. package/dist/unstable/cluster/index.js.map +1 -1
  247. package/dist/unstable/reactivity/AtomMachine.d.ts +21 -26
  248. package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
  249. package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
  250. package/package.json +5 -3
  251. package/src/LocalMachine.ts +611 -0
  252. package/src/Machine.ts +1379 -1334
  253. package/src/index.ts +1 -0
  254. package/src/internal/machine/atom.ts +20 -49
  255. package/src/internal/machine/capability.ts +123 -0
  256. package/src/internal/machine/{invocationDefinition.ts → capturedInvocation.ts} +13 -13
  257. package/src/internal/machine/child.ts +25 -0
  258. package/src/internal/machine/childRegistry.ts +1 -4
  259. package/src/internal/machine/cluster.ts +420 -205
  260. package/src/internal/machine/clusterChild.ts +117 -0
  261. package/src/internal/machine/clusterFailure.ts +53 -0
  262. package/src/internal/machine/clusterInstance.ts +1779 -0
  263. package/src/internal/machine/clusterKeepAlive.ts +93 -0
  264. package/src/internal/machine/clusterProgress.ts +159 -0
  265. package/src/internal/machine/clusterProtocol.ts +46 -4
  266. package/src/internal/machine/clusterProxy.ts +233 -0
  267. package/src/internal/machine/clusterRead.ts +207 -0
  268. package/src/internal/machine/clusterSqlStorage.ts +181 -0
  269. package/src/internal/machine/clusterStorageCheck.ts +274 -0
  270. package/src/internal/machine/clusterTarget.ts +154 -0
  271. package/src/internal/machine/clusterTimer.ts +58 -0
  272. package/src/internal/machine/clusterWake.ts +100 -0
  273. package/src/internal/machine/clusterWork.ts +269 -0
  274. package/src/internal/machine/command.ts +4 -4
  275. package/src/internal/machine/commandRuntime.ts +12 -24
  276. package/src/internal/machine/configuration.ts +0 -181
  277. package/src/internal/machine/errors.ts +11 -2
  278. package/src/internal/machine/executionPlan.ts +493 -263
  279. package/src/internal/machine/implementation.ts +6 -6
  280. package/src/internal/machine/inspectionRuntime.ts +1 -1
  281. package/src/internal/machine/invocationChanges.ts +89 -0
  282. package/src/internal/machine/{activities.ts → invocationDefinitions.ts} +10 -10
  283. package/src/internal/machine/invocationEvent.ts +35 -12
  284. package/src/internal/machine/invocationOutcome.ts +145 -0
  285. package/src/internal/machine/invocationResolution.ts +307 -0
  286. package/src/internal/machine/logicScope.ts +47 -0
  287. package/src/internal/machine/machine.ts +35 -100
  288. package/src/internal/machine/observation.ts +67 -2
  289. package/src/internal/machine/plannedSnapshot.ts +17 -20
  290. package/src/internal/machine/planner.ts +75 -99
  291. package/src/internal/machine/process.ts +78 -722
  292. package/src/internal/machine/protocol.ts +70 -26
  293. package/src/internal/machine/runtime.ts +198 -195
  294. package/src/internal/machine/runtimeCompiled.ts +496 -171
  295. package/src/internal/machine/runtimeProtocol.ts +416 -305
  296. package/src/internal/machine/stateDefinition.ts +0 -5
  297. package/src/internal/machine/step.ts +1518 -0
  298. package/src/internal/machine/stepHost.ts +634 -0
  299. package/src/internal/machine/symbols.ts +3 -14
  300. package/src/internal/machine/transition.ts +11 -11
  301. package/src/internal/testing/machine/check.ts +240 -36
  302. package/src/internal/testing/machine/exploration.ts +42 -3
  303. package/src/internal/testing/machine/format.ts +1 -1
  304. package/src/internal/testing/machine/probe.ts +2 -1
  305. package/src/internal/testing/machine/runtime.ts +15 -5
  306. package/src/internal/testing/machine/trace.ts +261 -41
  307. package/src/internal/testing/machine/transitionCoverage.ts +1 -1
  308. package/src/internal/testing/machine/verification.ts +11 -5
  309. package/src/internal/testing/machine/work.ts +101 -0
  310. package/src/testing/MachineTest.ts +268 -44
  311. package/src/unstable/cluster/ClusterMachine.ts +1183 -59
  312. package/src/unstable/cluster/ClusterMachineProxy.ts +372 -0
  313. package/src/unstable/cluster/SqlMachineStorage.ts +136 -0
  314. package/src/unstable/cluster/index.ts +15 -0
  315. package/src/unstable/reactivity/AtomMachine.ts +27 -88
  316. package/dist/internal/machine/activities.d.ts.map +0 -1
  317. package/dist/internal/machine/activities.js.map +0 -1
  318. package/dist/internal/machine/invocation.d.ts +0 -33
  319. package/dist/internal/machine/invocation.d.ts.map +0 -1
  320. package/dist/internal/machine/invocation.js +0 -220
  321. package/dist/internal/machine/invocation.js.map +0 -1
  322. package/dist/internal/machine/invocationDefinition.d.ts.map +0 -1
  323. package/dist/internal/machine/invocationDefinition.js.map +0 -1
  324. package/dist/internal/machine/requirements.d.ts +0 -4
  325. package/dist/internal/machine/requirements.d.ts.map +0 -1
  326. package/dist/internal/machine/requirements.js +0 -2
  327. package/dist/internal/machine/requirements.js.map +0 -1
  328. package/dist/internal/machine/runtimeGeneric.d.ts +0 -3
  329. package/dist/internal/machine/runtimeGeneric.d.ts.map +0 -1
  330. package/dist/internal/machine/runtimeGeneric.js +0 -465
  331. package/dist/internal/machine/runtimeGeneric.js.map +0 -1
  332. package/src/internal/machine/invocation.ts +0 -376
  333. package/src/internal/machine/requirements.ts +0 -11
  334. package/src/internal/machine/runtimeGeneric.ts +0 -797
@@ -9,10 +9,11 @@ import * as Option from "effect/Option";
9
9
  import * as PubSub from "effect/PubSub";
10
10
  import * as Scope from "effect/Scope";
11
11
  import * as Stream from "effect/Stream";
12
+ import { ChildMachineRuntime, MachineRuntime } from "./capability.js";
13
+ import { isChildMachine } from "./child.js";
12
14
  import { isReservedChildId, matchesChild, offerChildObservation, registerChild, selectRegistryChild, takeChildObservations, unregisterChild } from "./childRegistry.js";
13
- import { ChildAlreadyExistsError, StoppedError } from "./errors.js";
15
+ import { ChildAlreadyExistsError, MachineSchemaDecodeError, StoppedError } from "./errors.js";
14
16
  import * as InspectionRuntime from "./inspectionRuntime.js";
15
- import { ChildMachineLogicTypeId } from "./symbols.js";
16
17
  /** @internal */
17
18
  export const activeSnapshotObserver = Symbol.for("effect/Machine/activeSnapshotObserver");
18
19
  /**
@@ -30,8 +31,87 @@ export const activeSnapshotObserver = Symbol.for("effect/Machine/activeSnapshotO
30
31
  export const snapshotObserver = Symbol.for("effect/Machine/snapshotObserver");
31
32
  /** @internal */
32
33
  export const isSnapshotObservable = (value) => typeof value === "object" && value !== null && snapshotObserver in value;
34
+ /**
35
+ * Delivery for transition commands and internal work reports inside one
36
+ * runtime. A caller-awaited `send` or `sendTo` rejects an event that the
37
+ * schema of the machine refuses; a delivery has no waiting caller, so the
38
+ * receiving machine fails with that error when the event is planned.
39
+ *
40
+ * @internal
41
+ */
42
+ export const deliverEvent = Symbol.for("effect/Machine/deliverEvent");
33
43
  /** @internal */
34
- const sendParentOverride = Symbol.for("effect/Machine/sendParentOverride");
44
+ export const deliverFromProcess = Symbol.for("effect/Machine/deliverFromProcess");
45
+ /**
46
+ * The event of a delivery that the schema of the machine refused, or whose
47
+ * decoding threw. Planning it fails the machine with `error`.
48
+ *
49
+ * @internal
50
+ */
51
+ export class RefusedEvent {
52
+ error;
53
+ constructor(error) {
54
+ this.error = error;
55
+ }
56
+ }
57
+ /**
58
+ * What running work reports to the machine that owns it, as a message of the
59
+ * machine's mailbox, so its step takes the report in the machine's own turn:
60
+ * `Settle` ends the work with the `Exit` in `value`, `Element` delivers an
61
+ * element of a stream, and `Report` a snapshot of a child. It is never decoded.
62
+ * `sent` is the event that inspection reports for it.
63
+ *
64
+ * @internal
65
+ */
66
+ export class WorkMessage {
67
+ _tag;
68
+ work;
69
+ value;
70
+ sent;
71
+ constructor(_tag, work, value, sent) {
72
+ this._tag = _tag;
73
+ this.work = work;
74
+ this.value = value;
75
+ this.sent = sent;
76
+ }
77
+ }
78
+ /** The event that inspection reports for a message: what a report of work stands for, or the event. */
79
+ export const sentOf = (event) => event instanceof WorkMessage ? event.sent : event;
80
+ /**
81
+ * Decodes an event that a public `send` offers: a refused event is rejected
82
+ * with its `MachineSchemaDecodeError`, and any other throw is a defect of the
83
+ * machine, which fails when it plans the returned `RefusedEvent`.
84
+ *
85
+ * @internal
86
+ */
87
+ export const decodeSent = (decode, event) => {
88
+ if (decode === undefined)
89
+ return { _tag: "Decoded", event };
90
+ try {
91
+ return { _tag: "Decoded", event: decode(event) };
92
+ }
93
+ catch (error) {
94
+ return error instanceof MachineSchemaDecodeError
95
+ ? { _tag: "Rejected", error }
96
+ : { _tag: "Decoded", event: new RefusedEvent(error) };
97
+ }
98
+ };
99
+ /**
100
+ * Decodes an event that a delivery offers. A refused event becomes a
101
+ * `RefusedEvent`, so the machine fails when it plans it.
102
+ *
103
+ * @internal
104
+ */
105
+ export const decodeDelivered = (decode, event) => {
106
+ if (decode === undefined || event instanceof WorkMessage)
107
+ return event;
108
+ try {
109
+ return decode(event);
110
+ }
111
+ catch (error) {
112
+ return new RefusedEvent(error);
113
+ }
114
+ };
35
115
  /** @internal */
36
116
  export const acknowledgedSend = Symbol.for("effect/Machine/acknowledgedSend");
37
117
  export const AcknowledgedMessageTypeId = Symbol("effect/Machine/AcknowledgedMessage");
@@ -60,9 +140,34 @@ export const stopAcknowledgedMessage = (message) => {
60
140
  }
61
141
  };
62
142
  export const isMachineTarget = (value) => typeof value === "object" && value !== null && "send" in value && typeof value.send === "function";
143
+ /** Sends to a target for a waiting caller: a refused event is rejected and the target keeps running. */
63
144
  export const sendMachineTarget = (target, event, source, causedBy) => "inspectionSubject" in target && "sendInspected" in target && typeof target.sendInspected === "function"
64
145
  ? target.sendInspected(event, source, causedBy)
65
146
  : target.send(event);
147
+ /** Delivers a transition command to a target without caller-side schema rejection. */
148
+ export const deliverMachineTarget = (target, event, source, causedBy) => deliverEvent in target
149
+ ? target[deliverEvent](event, source, causedBy)
150
+ : sendMachineTarget(target, event, source, causedBy);
151
+ /** Sends to an endpoint for a waiting caller. */
152
+ export const sendEndpoint = (endpoint, event, source, causedBy) => endpoint.sendInspected === undefined ? endpoint.send(event) : endpoint.sendInspected(event, source, causedBy);
153
+ /** Delivers an internal message or transition command to an endpoint of this runtime. */
154
+ export const deliverToEndpoint = (endpoint, event, source, causedBy) => endpoint[deliverEvent] !== undefined
155
+ ? endpoint[deliverEvent](event, source, causedBy)
156
+ : sendEndpoint(endpoint, event, source, causedBy);
157
+ /**
158
+ * Delivers a transition command to a child started by this runtime: a machine
159
+ * takes the delivery and fails when planning a refused event, and other logic
160
+ * decodes nothing.
161
+ */
162
+ const deliverToChild = (ref, event, source, causedBy) => ref[deliverEvent] === undefined
163
+ ? sendMachineTarget(ref, event, source, causedBy)
164
+ : ref[deliverEvent](event, source, causedBy);
165
+ /** Delivers a transition command from a running local process to a target or child. */
166
+ export const deliverFromScope = (scope, target, event) => scope.self[deliverFromProcess] !== undefined
167
+ ? scope.self[deliverFromProcess](target, event)
168
+ : isMachineTarget(target)
169
+ ? deliverMachineTarget(target, event, scope.self.inspectionSubject, undefined)
170
+ : scope.sendTo(target, event);
66
171
  export const executionIsChildless = (execution) => execution?._tag === "Childless" || execution?.childless === true;
67
172
  export const offerCompactMailbox = (mailbox, event) => {
68
173
  const items = mailbox.items ?? [];
@@ -137,91 +242,21 @@ export const closeProcessMailbox = (mailbox) => {
137
242
  receiver(Effect.interrupt);
138
243
  }
139
244
  };
140
- /**
141
- * Service required by operations that act on the machine executing them,
142
- * such as `sendTo`, `stopChild`, and `spawn`.
143
- *
144
- * **When to use**
145
- *
146
- * Name this requirement when annotating a reusable helper built from those
147
- * operations, or when exporting a value whose inferred type includes it.
148
- *
149
- * **Details**
150
- *
151
- * A running machine provides this service to the effects it executes, so it
152
- * never appears in the requirements of the machine itself. Only the type is
153
- * public: the service cannot be constructed or provided outside a running
154
- * machine.
155
- *
156
- * @category services
157
- * @since 0.47.0
158
- */
159
- export class MachineRuntime extends Context.Service()("effect/Machine/MachineRuntime") {
160
- }
161
- export const provideMachineRuntime = (effect, scope) => Effect.provideService(effect, MachineRuntime, scope);
162
- export const classifyOutcome = (snapshot) => {
163
- switch (snapshot.status) {
164
- case "active": {
165
- return undefined;
166
- }
167
- case "done": {
168
- return {
169
- _tag: "Done",
170
- output: snapshot.output,
171
- snapshot
172
- };
173
- }
174
- case "error": {
175
- const failure = snapshot.cause.reasons.find(Cause.isFailReason);
176
- if (failure !== undefined) {
177
- return {
178
- _tag: "Failure",
179
- error: failure.error,
180
- cause: snapshot.cause,
181
- snapshot
182
- };
183
- }
184
- const defect = snapshot.cause.reasons.find(Cause.isDieReason);
185
- if (defect !== undefined) {
186
- return {
187
- _tag: "Defect",
188
- defect: defect.defect,
189
- cause: snapshot.cause,
190
- snapshot
191
- };
192
- }
193
- const interrupted = snapshot.cause.reasons.find(Cause.isInterruptReason);
194
- if (interrupted !== undefined) {
195
- return {
196
- _tag: "Interrupted",
197
- cause: snapshot.cause,
198
- snapshot
199
- };
200
- }
201
- return {
202
- _tag: "Cause",
203
- cause: snapshot.cause,
204
- snapshot
205
- };
206
- }
207
- case "stopped": {
208
- return {
209
- _tag: "Stopped",
210
- snapshot
211
- };
212
- }
213
- }
214
- };
245
+ export const provideMachineRuntime = (effect, scope) =>
246
+ // One update of the context for both, as each process starts with them.
247
+ Effect.updateContext(effect, (context) => Context.add(Context.add(context, MachineRuntime, scope), ChildMachineRuntime, scope));
215
248
  export const notifyActiveSnapshot = (onSnapshot, snapshot) => Effect.suspend(() => onSnapshot(snapshot)).pipe(Effect.exit, Effect.asVoid);
216
- export const watch = (ref) => ref.changes.pipe(Stream.filter((snapshot) => snapshot.status !== "active"), Stream.map((snapshot) => classifyOutcome(snapshot)), Stream.take(1));
217
- export const makeProcessRuntime = (start, startCompiledSync) => {
249
+ export const makeProcessRuntime = (start, startCompiledSync, makeChildLogic) => {
218
250
  // Strategy hooks belong to the shared prototype. Each root owns only its
219
251
  // session counter and optional inspection runtime, independent of other roots.
220
252
  class Runtime {
221
- nextSessionId;
222
- constructor() {
223
- let sessionIdCounter = 0;
224
- this.nextSessionId = Effect.sync(() => `machine:${sessionIdCounter++}`);
253
+ sessionIdCounter = 0;
254
+ _nextSessionId = undefined;
255
+ nextSessionIdSync() {
256
+ return `machine:${this.sessionIdCounter++}`;
257
+ }
258
+ get nextSessionId() {
259
+ return this._nextSessionId ??= Effect.sync(() => this.nextSessionIdSync());
225
260
  }
226
261
  get start() {
227
262
  return start;
@@ -229,6 +264,9 @@ export const makeProcessRuntime = (start, startCompiledSync) => {
229
264
  get startCompiledSync() {
230
265
  return startCompiledSync;
231
266
  }
267
+ get makeChildLogic() {
268
+ return makeChildLogic;
269
+ }
232
270
  }
233
271
  return Effect.sync(() => new Runtime());
234
272
  };
@@ -242,14 +280,15 @@ export const messageCausation = (message, initializing) => initializing
242
280
  : message !== undefined && isAcknowledgedMessage(message) && message.inspection !== undefined
243
281
  ? { _tag: "Macrostep", macrostepId: message.inspection.macrostepId }
244
282
  : undefined;
245
- export const makeInspectedMessage = (inspection, subject, event, source, causedBy, deferred) => {
283
+ export const makeInspectedMessage = (inspection, subject, event, source, causedBy, deferred, sent = event) => {
246
284
  const deliveryId = inspection.nextDeliveryId();
247
285
  const macrostepId = inspection.nextMacrostepId();
286
+ // Inspection reports the event as it was sent, before decoding.
248
287
  const inspected = {
249
288
  deliveryId,
250
289
  macrostepId,
251
290
  source,
252
- event,
291
+ event: sent,
253
292
  causedBy,
254
293
  complete: (delivery) => {
255
294
  const microsteps = InspectionRuntime.microsteps(delivery.plan);
@@ -259,7 +298,7 @@ export const makeInspectedMessage = (inspection, subject, event, source, causedB
259
298
  macrostepId,
260
299
  deliveryId,
261
300
  source,
262
- event,
301
+ event: sent,
263
302
  before: { status: "active", state: delivery.before },
264
303
  after: { status: "active", state: delivery.after },
265
304
  handled: microsteps.some((microstep) => microstep.transitions.length > 0),
@@ -289,6 +328,57 @@ export const publishInspectedSent = (inspection, subject, message) => {
289
328
  causedBy: delivery.causedBy
290
329
  });
291
330
  };
331
+ /**
332
+ * Parent endpoint exposed to an owned invocation. Prototype getters and methods
333
+ * keep each running child free of per-child parent endpoint closures.
334
+ */
335
+ class OwnedChildParent {
336
+ owner;
337
+ childId;
338
+ token;
339
+ ownerKey;
340
+ startedChild = undefined;
341
+ constructor(owner, childId, token, ownerKey) {
342
+ this.owner = owner;
343
+ this.childId = childId;
344
+ this.token = token;
345
+ this.ownerKey = ownerKey;
346
+ }
347
+ get id() {
348
+ return this.owner.self.id;
349
+ }
350
+ get sessionId() {
351
+ return this.owner.self.sessionId;
352
+ }
353
+ get inspectionSubject() {
354
+ return this.owner.self.inspectionSubject;
355
+ }
356
+ get stop() {
357
+ return this.owner.self.stop;
358
+ }
359
+ isCurrent() {
360
+ const entry = this.owner.registry.children.get(this.childId);
361
+ return entry?.token === this.token && entry.ownerKey === this.ownerKey && entry.ownerActive === true;
362
+ }
363
+ unregister() {
364
+ unregisterChild(this.owner.registry, this.childId, this.token);
365
+ }
366
+ send(event) {
367
+ return this.isCurrent() ? this.owner.self.send(event) : Effect.void;
368
+ }
369
+ sendInspected(event, source, causedBy) {
370
+ return this.isCurrent() ? sendEndpoint(this.owner.self, event, source, causedBy) : Effect.void;
371
+ }
372
+ [deliverEvent](event, source, causedBy) {
373
+ return this.isCurrent() ? deliverToEndpoint(this.owner.self, event, source, causedBy) : Effect.void;
374
+ }
375
+ get [acknowledgedSend]() {
376
+ const send = this.owner.sendAcknowledged;
377
+ if (send === undefined)
378
+ return undefined;
379
+ return (event) => this.isCurrent() ? send(event) : Effect.interrupt;
380
+ }
381
+ }
292
382
  class OwnedChildRuntimeImpl {
293
383
  registry;
294
384
  self;
@@ -296,13 +386,6 @@ class OwnedChildRuntimeImpl {
296
386
  services;
297
387
  sendAcknowledged;
298
388
  scopedServices;
299
- // The current generation of each active invoking state path. Most
300
- // configurations have one such path, held inline; further paths use the map.
301
- // Entries are removed when their state exits, so neither outgrows the active
302
- // configuration.
303
- generationPath;
304
- generation;
305
- generations;
306
389
  constructor(registry, self, runtime, services, sendAcknowledged) {
307
390
  this.registry = registry;
308
391
  this.self = self;
@@ -321,161 +404,90 @@ class OwnedChildRuntimeImpl {
321
404
  entry.ownerActive = false;
322
405
  return entry._tag === "Started" ? entry.ref.stop : Effect.void;
323
406
  }
324
- spawn(makeLogic, options) {
407
+ spawn(source, options) {
325
408
  const token = Symbol();
326
- let startedChild;
327
- const isCurrent = () => {
328
- const entry = this.registry.children.get(options.id);
329
- return entry?.token === token && entry.ownerKey === options.key && entry.ownerActive === true;
330
- };
409
+ const id = options.id;
410
+ const key = options.key;
411
+ const onOutcome = options.onOutcome;
412
+ const onSnapshot = options.onSnapshot;
413
+ const parent = new OwnedChildParent(this, id, token, key);
331
414
  return Effect.suspend(() => {
332
415
  if (this.registry.closed)
333
416
  return Effect.interrupt;
334
- if (this.has(options.key) || this.registry.children.has(options.id)) {
417
+ if (this.registry.children.size > 0 && (this.has(key) || this.registry.children.has(id))) {
335
418
  return Effect.fail(new ChildAlreadyExistsError({ id: options.duplicateId }));
336
419
  }
337
- const logic = makeLogic();
420
+ const logic = typeof source === "function"
421
+ ? source()
422
+ : this.runtime.makeChildLogic(source.child.machine, source.input?.());
423
+ const descriptor = typeof source === "function" ? undefined : source.child;
338
424
  const scope = this.registry.scope ??= Scope.makeUnsafe("parallel");
339
- this.registry.children.set(options.id, {
425
+ this.registry.children.set(id, {
340
426
  _tag: "Starting",
341
427
  token,
342
- ownerKey: options.key,
343
- ownerPath: options.path,
428
+ ownerKey: key,
344
429
  ownerActive: true
345
430
  });
346
- const parent = {
347
- ...this.self,
348
- send: (event) => options.sendParent(isCurrent, event),
349
- sendInspected: (event, source, causedBy) => isCurrent() ? sendMachineTarget(this.self, event, source, causedBy) : Effect.void,
350
- ...(this.sendAcknowledged === undefined
351
- ? undefined
352
- : {
353
- [acknowledgedSend]: (event) => isCurrent()
354
- ? this.sendAcknowledged(event)
355
- : Effect.interrupt
356
- })
357
- };
431
+ const isCurrent = () => parent.isCurrent();
358
432
  const startOptions = {
359
433
  detached: true,
360
- id: options.id,
361
- sendParent: (event) => options.sendParent(isCurrent, event),
362
- onOutcome: (outcome) => options.onOutcome(isCurrent, outcome, startedChild?.sessionId),
363
- ...(options.onSnapshot === undefined
434
+ id,
435
+ onOutcome: (outcome) => onOutcome(isCurrent, outcome, parent.startedChild?.sessionId),
436
+ ...(onSnapshot === undefined
364
437
  ? undefined
365
- : { onSnapshot: (snapshot) => options.onSnapshot(isCurrent, snapshot) }),
438
+ : { onSnapshot: (snapshot) => onSnapshot(isCurrent, snapshot) }),
366
439
  onReadySync: (child) => {
367
- startedChild = child;
368
- return registerChild(this.registry, options.id, token, child, options.descriptor);
440
+ parent.startedChild = child;
441
+ startOptions.onReadySync = undefined;
442
+ return registerChild(this.registry, id, token, child, descriptor);
369
443
  },
370
- onStopSync: () => unregisterChild(this.registry, options.id, token),
444
+ onStopSync: () => parent.unregister(),
371
445
  skipStoppedOutcome: true,
372
446
  parent,
373
447
  runtime: this.runtime,
374
- origin: { _tag: "Invoke", ownerPath: options.path, invokeId: options.duplicateId },
375
- ...(options.activityKind === undefined || this.runtime.inspection === undefined ||
376
- this.self.inspectionSubject === undefined
448
+ ...(this.runtime.inspection === undefined
377
449
  ? undefined
378
450
  : {
379
- activity: {
380
- id: options.duplicateId,
381
- owner: this.self.inspectionSubject,
382
- ownerPath: options.path,
383
- kind: options.activityKind
384
- }
451
+ origin: { _tag: "Invoke", ownerPath: options.path, invokeId: options.duplicateId },
452
+ ...(options.programKind === undefined || this.self.inspectionSubject === undefined
453
+ ? undefined
454
+ : {
455
+ programInvocation: {
456
+ id: options.duplicateId,
457
+ owner: this.self.inspectionSubject,
458
+ ownerPath: options.path,
459
+ kind: options.programKind
460
+ }
461
+ })
385
462
  })
386
463
  };
387
464
  const execution = logic.execution;
388
- const synchronous = this.services !== undefined && options.onSnapshot === undefined &&
465
+ const synchronous = this.services !== undefined && onSnapshot === undefined &&
389
466
  execution?._tag === "Compiled" && execution.childless && execution.drain._tag === "Owned" &&
390
467
  execution.initialSync !== undefined;
391
468
  const start = synchronous
392
- ? Effect.flatMap(this.runtime.nextSessionId, (sessionId) => this.runtime.startCompiledSync(logic, startOptions, this.scopedServices ??= Context.add(this.services, Scope.Scope, scope), sessionId))
469
+ ? this.runtime.startCompiledSync(logic, startOptions, this.scopedServices ??= Context.add(this.services, Scope.Scope, scope), this.runtime.nextSessionIdSync())
393
470
  : this.runtime.start(logic, startOptions);
394
471
  const guarded = start.pipe(Effect.onExit((exit) => {
395
472
  if (Exit.isSuccess(exit))
396
473
  return Effect.void;
397
- unregisterChild(this.registry, options.id, token);
398
- return startedChild === undefined ? Effect.void : startedChild.stop;
474
+ parent.unregister();
475
+ return parent.startedChild === undefined ? Effect.void : parent.startedChild.stop;
399
476
  }));
400
477
  return (synchronous ? guarded : Scope.provide(guarded, scope)).pipe(Effect.asVoid);
401
478
  });
402
479
  }
403
- beginGeneration(path) {
404
- this.retireGeneration(path);
405
- const generation = { current: true };
406
- if (this.generationPath === undefined) {
407
- this.generationPath = path;
408
- this.generation = generation;
409
- }
410
- else {
411
- ;
412
- (this.generations ??= new Map()).set(path, generation);
413
- }
414
- return generation;
415
- }
416
- retireGeneration(path) {
417
- const inline = this.generation;
418
- if (inline !== undefined && this.generationPath === path) {
419
- inline.current = false;
420
- this.generationPath = undefined;
421
- this.generation = undefined;
422
- return;
423
- }
424
- const generations = this.generations;
425
- const generation = generations?.get(path);
426
- if (generations !== undefined && generation !== undefined) {
427
- generation.current = false;
428
- generations.delete(path);
429
- }
430
- }
431
- stopAll() {
480
+ stopKey(key) {
432
481
  return Effect.suspend(() => {
433
- if (this.generation !== undefined) {
434
- this.generation.current = false;
435
- this.generationPath = undefined;
436
- this.generation = undefined;
437
- }
438
- const generations = this.generations;
439
- if (generations !== undefined && generations.size > 0) {
440
- for (const generation of generations.values())
441
- generation.current = false;
442
- generations.clear();
443
- }
444
- const effects = [];
445
482
  for (const entry of this.registry.children.values()) {
446
- if (entry.ownerActive)
447
- effects.push(this.stopEntry(entry));
483
+ if (entry.ownerActive && entry.ownerKey === key)
484
+ return this.stopEntry(entry);
448
485
  }
449
- return effects.length === 0
450
- ? Effect.void
451
- : effects.length === 1
452
- ? effects[0]
453
- : Effect.all(effects, { concurrency: "unbounded", discard: true });
486
+ return Effect.void;
454
487
  });
455
488
  }
456
- stopPaths(paths) {
457
- if (paths.length === 0)
458
- return undefined;
459
- if (this.generation !== undefined || (this.generations !== undefined && this.generations.size > 0)) {
460
- for (const path of paths)
461
- this.retireGeneration(path);
462
- }
463
- const pathSet = new Set(paths);
464
- const effects = [];
465
- for (const entry of this.registry.children.values()) {
466
- if (entry.ownerActive && entry.ownerPath !== undefined && pathSet.has(entry.ownerPath)) {
467
- effects.push(this.stopEntry(entry));
468
- }
469
- }
470
- return effects.length === 0
471
- ? undefined
472
- : effects.length === 1
473
- ? effects[0]
474
- : Effect.all(effects, { concurrency: "unbounded", discard: true });
475
- }
476
489
  }
477
490
  const noChildChanges = Stream.succeed(Option.none()).pipe(Stream.concat(Stream.never));
478
- export const noParentSend = (_event) => Effect.void;
479
491
  export const noInspectInitial = (_paths, _microsteps) => { };
480
492
  export const noCausation = () => undefined;
481
493
  export const EmissionsClosed = Symbol("effect/Machine/EmissionsClosed");
@@ -515,13 +527,11 @@ export const childlessRuntime = {
515
527
  get: () => Effect.succeed(Option.none()),
516
528
  changes: () => noChildChanges,
517
529
  sendTo: () => Effect.void,
530
+ deliverTo: () => Effect.void,
518
531
  stop: () => Effect.void,
519
532
  owned: {
520
533
  spawn: () => Effect.die(new Error("Childless machine logic cannot spawn an owned process")),
521
- // Unreachable for childless logic; `spawn` reports the defect as a failure.
522
- beginGeneration: () => ({ current: true }),
523
- stopAll: () => Effect.void,
524
- stopPaths: () => undefined
534
+ stopKey: () => Effect.void
525
535
  }
526
536
  };
527
537
  export const makeChildRuntimeSync = (self, runtime, services, sendAcknowledged) => {
@@ -622,6 +632,18 @@ export const makeChildRuntimeSync = (self, runtime, services, sendAcknowledged)
622
632
  : Effect.void;
623
633
  });
624
634
  };
635
+ const deliverTo = (child, event, source, causedBy) => {
636
+ const id = typeof child === "string" ? child : child.id;
637
+ return Effect.suspend(() => {
638
+ if (registry.closed) {
639
+ return Effect.void;
640
+ }
641
+ const entry = registry.children.get(id);
642
+ return entry !== undefined && matchesChild(entry, child)
643
+ ? deliverToChild(entry.ref, event, source, causedBy)
644
+ : Effect.void;
645
+ });
646
+ };
625
647
  const stop = (child) => {
626
648
  const id = typeof child === "string" ? child : child.id;
627
649
  return Effect.suspend(() => {
@@ -635,13 +657,10 @@ export const makeChildRuntimeSync = (self, runtime, services, sendAcknowledged)
635
657
  });
636
658
  };
637
659
  function spawn(logicOrChild, options) {
638
- const descriptor = typeof logicOrChild === "object" && logicOrChild !== null &&
639
- ChildMachineLogicTypeId in logicOrChild
640
- ? logicOrChild
641
- : undefined;
660
+ const descriptor = isChildMachine(logicOrChild) ? logicOrChild : undefined;
642
661
  const logic = descriptor === undefined
643
662
  ? logicOrChild
644
- : descriptor[ChildMachineLogicTypeId](options?.input);
663
+ : runtime.makeChildLogic(descriptor.machine, options?.input);
645
664
  const spawnOptions = descriptor === undefined
646
665
  ? options
647
666
  : { id: descriptor.id, descriptor };
@@ -664,9 +683,6 @@ export const makeChildRuntimeSync = (self, runtime, services, sendAcknowledged)
664
683
  ...(spawnOptions?.[activeSnapshotObserver] === undefined
665
684
  ? undefined
666
685
  : { onSnapshot: spawnOptions[activeSnapshotObserver] }),
667
- ...(spawnOptions?.[sendParentOverride] === undefined
668
- ? undefined
669
- : { sendParent: spawnOptions[sendParentOverride] }),
670
686
  onReady: (child, requestChildStop) => Effect.sync(() => {
671
687
  startedChild = child;
672
688
  }).pipe(Effect.andThen(register(key, token, child, spawnOptions?.descriptor)), Effect.flatMap((registered) => registered ? Effect.void : requestChildStop)),
@@ -685,6 +701,7 @@ export const makeChildRuntimeSync = (self, runtime, services, sendAcknowledged)
685
701
  get,
686
702
  changes,
687
703
  sendTo,
704
+ deliverTo,
688
705
  stop,
689
706
  owned: new OwnedChildRuntimeImpl(registry, self, runtime, services, sendAcknowledged)
690
707
  };