@zlink-systems/framework 0.10.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 (1121) hide show
  1. package/LICENSE +105 -0
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/contracts/Actors/ZLinkActor.d.ts +7 -0
  4. package/dist/contracts/Actors/ZLinkActor.js +2 -0
  5. package/dist/contracts/Actors/ZLinkActorClient.d.ts +15 -0
  6. package/dist/contracts/Actors/ZLinkActorClient.js +2 -0
  7. package/dist/contracts/Actors/ZLinkActorContext.d.ts +14 -0
  8. package/dist/contracts/Actors/ZLinkActorContext.js +2 -0
  9. package/dist/contracts/Actors/ZLinkActorFactory.d.ts +34 -0
  10. package/dist/contracts/Actors/ZLinkActorFactory.js +2 -0
  11. package/dist/contracts/Actors/ZLinkActorManager.d.ts +34 -0
  12. package/dist/contracts/Actors/ZLinkActorManager.js +2 -0
  13. package/dist/contracts/Actors/index.d.ts +5 -0
  14. package/dist/contracts/Actors/index.js +21 -0
  15. package/dist/contracts/Channels/Calls.d.ts +28 -0
  16. package/dist/contracts/Channels/Calls.js +2 -0
  17. package/dist/contracts/Channels/IZLinkChannelClient.d.ts +5 -0
  18. package/dist/contracts/Channels/IZLinkChannelClient.js +2 -0
  19. package/dist/contracts/Channels/IZLinkFanoutClient.d.ts +11 -0
  20. package/dist/contracts/Channels/IZLinkFanoutClient.js +2 -0
  21. package/dist/contracts/Channels/RouteCalls.d.ts +11 -0
  22. package/dist/contracts/Channels/RouteCalls.js +2 -0
  23. package/dist/contracts/Channels/index.d.ts +4 -0
  24. package/dist/contracts/Channels/index.js +20 -0
  25. package/dist/contracts/Codecs/IZLinkCodecRegistryBuilder.d.ts +14 -0
  26. package/dist/contracts/Codecs/IZLinkCodecRegistryBuilder.js +2 -0
  27. package/dist/contracts/Codecs/ZLinkMessageSerializer.d.ts +5 -0
  28. package/dist/contracts/Codecs/ZLinkMessageSerializer.js +2 -0
  29. package/dist/contracts/Codecs/index.d.ts +2 -0
  30. package/dist/contracts/Codecs/index.js +18 -0
  31. package/dist/contracts/Common/ActorRef.d.ts +7 -0
  32. package/dist/contracts/Common/ActorRef.js +2 -0
  33. package/dist/contracts/Common/CoreTypes.d.ts +6 -0
  34. package/dist/contracts/Common/CoreTypes.js +2 -0
  35. package/dist/contracts/Common/Message.d.ts +9 -0
  36. package/dist/contracts/Common/Message.js +2 -0
  37. package/dist/contracts/Common/ZLinkEncodedPayload.d.ts +12 -0
  38. package/dist/contracts/Common/ZLinkEncodedPayload.js +41 -0
  39. package/dist/contracts/Common/ZLinkMessage.d.ts +25 -0
  40. package/dist/contracts/Common/ZLinkMessage.js +127 -0
  41. package/dist/contracts/Common/ZLinkMessageMetadata.d.ts +10 -0
  42. package/dist/contracts/Common/ZLinkMessageMetadata.js +49 -0
  43. package/dist/contracts/Common/ZLinkProviderResolver.d.ts +5 -0
  44. package/dist/contracts/Common/ZLinkProviderResolver.js +2 -0
  45. package/dist/contracts/Common/encoded-payload-storage.d.ts +3 -0
  46. package/dist/contracts/Common/encoded-payload-storage.js +18 -0
  47. package/dist/contracts/Common/index.d.ts +5 -0
  48. package/dist/contracts/Common/index.js +24 -0
  49. package/dist/contracts/Configuration/Builders.d.ts +153 -0
  50. package/dist/contracts/Configuration/Builders.js +2 -0
  51. package/dist/contracts/Configuration/CodecContentType.d.ts +2 -0
  52. package/dist/contracts/Configuration/CodecContentType.js +68 -0
  53. package/dist/contracts/Configuration/CodecSerializerSelection.d.ts +9 -0
  54. package/dist/contracts/Configuration/CodecSerializerSelection.js +15 -0
  55. package/dist/contracts/Configuration/Configs.d.ts +23 -0
  56. package/dist/contracts/Configuration/Configs.js +2 -0
  57. package/dist/contracts/Configuration/ConfigurationException.d.ts +3 -0
  58. package/dist/contracts/Configuration/ConfigurationException.js +10 -0
  59. package/dist/contracts/Configuration/Connections.d.ts +5 -0
  60. package/dist/contracts/Configuration/Connections.js +2 -0
  61. package/dist/contracts/Configuration/DiagnosticsValidation.d.ts +3 -0
  62. package/dist/contracts/Configuration/DiagnosticsValidation.js +23 -0
  63. package/dist/contracts/Configuration/EndpointNotation.d.ts +77 -0
  64. package/dist/contracts/Configuration/EndpointNotation.js +218 -0
  65. package/dist/contracts/Configuration/InternalDefaults.d.ts +7 -0
  66. package/dist/contracts/Configuration/InternalDefaults.js +47 -0
  67. package/dist/contracts/Configuration/ObjectRoles.d.ts +38 -0
  68. package/dist/contracts/Configuration/ObjectRoles.js +13 -0
  69. package/dist/contracts/Configuration/Registration.d.ts +11 -0
  70. package/dist/contracts/Configuration/Registration.js +162 -0
  71. package/dist/contracts/Configuration/RegistrationBuilderPolicy.d.ts +14 -0
  72. package/dist/contracts/Configuration/RegistrationBuilderPolicy.js +61 -0
  73. package/dist/contracts/Configuration/RegistrationBuilders.d.ts +61 -0
  74. package/dist/contracts/Configuration/RegistrationBuilders.js +1181 -0
  75. package/dist/contracts/Configuration/RegistrationCodecRegistry.d.ts +19 -0
  76. package/dist/contracts/Configuration/RegistrationCodecRegistry.js +79 -0
  77. package/dist/contracts/Configuration/RegistrationNormalizers.d.ts +23 -0
  78. package/dist/contracts/Configuration/RegistrationNormalizers.js +319 -0
  79. package/dist/contracts/Configuration/RegistrationTypes.d.ts +414 -0
  80. package/dist/contracts/Configuration/RegistrationTypes.js +2 -0
  81. package/dist/contracts/Configuration/RegistrationValidators.d.ts +2 -0
  82. package/dist/contracts/Configuration/RegistrationValidators.js +461 -0
  83. package/dist/contracts/Configuration/RouteChannelInternalState.d.ts +10 -0
  84. package/dist/contracts/Configuration/RouteChannelInternalState.js +39 -0
  85. package/dist/contracts/Configuration/RuntimeEndpointConnections.d.ts +9 -0
  86. package/dist/contracts/Configuration/RuntimeEndpointConnections.js +80 -0
  87. package/dist/contracts/Configuration/SendTimeoutValidation.d.ts +2 -0
  88. package/dist/contracts/Configuration/SendTimeoutValidation.js +16 -0
  89. package/dist/contracts/Configuration/TimerRegistrationValidator.d.ts +2 -0
  90. package/dist/contracts/Configuration/TimerRegistrationValidator.js +24 -0
  91. package/dist/contracts/Configuration/index.d.ts +5 -0
  92. package/dist/contracts/Configuration/index.js +18 -0
  93. package/dist/contracts/Dispatch/ZLinkDispatchOptions.d.ts +181 -0
  94. package/dist/contracts/Dispatch/ZLinkDispatchOptions.js +89 -0
  95. package/dist/contracts/Dispatch/ZLinkFlowOrigin.d.ts +1 -0
  96. package/dist/contracts/Dispatch/ZLinkFlowOrigin.js +2 -0
  97. package/dist/contracts/Dispatch/index.d.ts +2 -0
  98. package/dist/contracts/Dispatch/index.js +18 -0
  99. package/dist/contracts/Errors/ZLinkFrameworkException.d.ts +20 -0
  100. package/dist/contracts/Errors/ZLinkFrameworkException.js +29 -0
  101. package/dist/contracts/Errors/index.d.ts +1 -0
  102. package/dist/contracts/Errors/index.js +6 -0
  103. package/dist/contracts/Eventing/Metrics.d.ts +29 -0
  104. package/dist/contracts/Eventing/Metrics.js +4 -0
  105. package/dist/contracts/Eventing/index.d.ts +1 -0
  106. package/dist/contracts/Eventing/index.js +17 -0
  107. package/dist/contracts/Handlers/Attributes.d.ts +24 -0
  108. package/dist/contracts/Handlers/Attributes.js +84 -0
  109. package/dist/contracts/Handlers/Contexts.d.ts +18 -0
  110. package/dist/contracts/Handlers/Contexts.js +2 -0
  111. package/dist/contracts/Handlers/IZLinkChannelHandlers.d.ts +43 -0
  112. package/dist/contracts/Handlers/IZLinkChannelHandlers.js +2 -0
  113. package/dist/contracts/Handlers/IZLinkHandlerFilter.d.ts +15 -0
  114. package/dist/contracts/Handlers/IZLinkHandlerFilter.js +11 -0
  115. package/dist/contracts/Handlers/JsonContract.d.ts +46 -0
  116. package/dist/contracts/Handlers/JsonContract.js +137 -0
  117. package/dist/contracts/Handlers/ZLinkHandlerFilterNext.d.ts +1 -0
  118. package/dist/contracts/Handlers/ZLinkHandlerFilterNext.js +2 -0
  119. package/dist/contracts/Handlers/index.d.ts +5 -0
  120. package/dist/contracts/Handlers/index.js +33 -0
  121. package/dist/contracts/Locations/ActorTransfer.d.ts +41 -0
  122. package/dist/contracts/Locations/ActorTransfer.js +2 -0
  123. package/dist/contracts/Locations/Authority.d.ts +296 -0
  124. package/dist/contracts/Locations/Authority.js +17 -0
  125. package/dist/contracts/Locations/Diagnostics.d.ts +42 -0
  126. package/dist/contracts/Locations/Diagnostics.js +12 -0
  127. package/dist/contracts/Locations/Keys.d.ts +86 -0
  128. package/dist/contracts/Locations/Keys.js +2 -0
  129. package/dist/contracts/Locations/Models.d.ts +7 -0
  130. package/dist/contracts/Locations/Models.js +23 -0
  131. package/dist/contracts/Locations/Options.d.ts +23 -0
  132. package/dist/contracts/Locations/Options.js +20 -0
  133. package/dist/contracts/Locations/Readiness.d.ts +5 -0
  134. package/dist/contracts/Locations/Readiness.js +2 -0
  135. package/dist/contracts/Locations/RelocationStore.d.ts +38 -0
  136. package/dist/contracts/Locations/RelocationStore.js +2 -0
  137. package/dist/contracts/Locations/Resolvers.d.ts +4 -0
  138. package/dist/contracts/Locations/Resolvers.js +2 -0
  139. package/dist/contracts/Locations/Rows.d.ts +152 -0
  140. package/dist/contracts/Locations/Rows.js +19 -0
  141. package/dist/contracts/Locations/RuntimeQuery.d.ts +25 -0
  142. package/dist/contracts/Locations/RuntimeQuery.js +2 -0
  143. package/dist/contracts/Locations/Stores.d.ts +88 -0
  144. package/dist/contracts/Locations/Stores.js +2 -0
  145. package/dist/contracts/Locations/Values.d.ts +27 -0
  146. package/dist/contracts/Locations/Values.js +36 -0
  147. package/dist/contracts/Locations/Watch.d.ts +14 -0
  148. package/dist/contracts/Locations/Watch.js +12 -0
  149. package/dist/contracts/Locations/Writes.d.ts +48 -0
  150. package/dist/contracts/Locations/Writes.js +15 -0
  151. package/dist/contracts/Locations/index.d.ts +12 -0
  152. package/dist/contracts/Locations/index.js +30 -0
  153. package/dist/contracts/RouteMesh/Contracts.d.ts +102 -0
  154. package/dist/contracts/RouteMesh/Contracts.js +39 -0
  155. package/dist/contracts/RouteMesh/RuntimeTopology.d.ts +165 -0
  156. package/dist/contracts/RouteMesh/RuntimeTopology.js +38 -0
  157. package/dist/contracts/RouteMesh/index.d.ts +2 -0
  158. package/dist/contracts/RouteMesh/index.js +18 -0
  159. package/dist/contracts/Spots/Builders.d.ts +10 -0
  160. package/dist/contracts/Spots/Builders.js +2 -0
  161. package/dist/contracts/Spots/Contracts.d.ts +110 -0
  162. package/dist/contracts/Spots/Contracts.js +9 -0
  163. package/dist/contracts/Spots/SpotKind.d.ts +8 -0
  164. package/dist/contracts/Spots/SpotKind.js +28 -0
  165. package/dist/contracts/Spots/ZLinkSpot.d.ts +62 -0
  166. package/dist/contracts/Spots/ZLinkSpot.js +15 -0
  167. package/dist/contracts/Spots/index.d.ts +3 -0
  168. package/dist/contracts/Spots/index.js +19 -0
  169. package/dist/contracts/Streams/BoundSessionContracts.d.ts +8 -0
  170. package/dist/contracts/Streams/BoundSessionContracts.js +2 -0
  171. package/dist/contracts/Streams/IZLinkSession.d.ts +44 -0
  172. package/dist/contracts/Streams/IZLinkSession.js +2 -0
  173. package/dist/contracts/Streams/IZLinkSessionActor.d.ts +15 -0
  174. package/dist/contracts/Streams/IZLinkSessionActor.js +2 -0
  175. package/dist/contracts/Streams/IZLinkSessionPacketHandler.d.ts +9 -0
  176. package/dist/contracts/Streams/IZLinkSessionPacketHandler.js +2 -0
  177. package/dist/contracts/Streams/IZLinkStream.d.ts +9 -0
  178. package/dist/contracts/Streams/IZLinkStream.js +2 -0
  179. package/dist/contracts/Streams/ZLinkMessageMetadata.d.ts +1 -0
  180. package/dist/contracts/Streams/ZLinkMessageMetadata.js +2 -0
  181. package/dist/contracts/Streams/ZLinkStreamCompression.d.ts +8 -0
  182. package/dist/contracts/Streams/ZLinkStreamCompression.js +2 -0
  183. package/dist/contracts/Streams/ZLinkStreamError.d.ts +8 -0
  184. package/dist/contracts/Streams/ZLinkStreamError.js +8 -0
  185. package/dist/contracts/Streams/index.d.ts +8 -0
  186. package/dist/contracts/Streams/index.js +24 -0
  187. package/dist/contracts/Timers/IZLinkTimer.d.ts +5 -0
  188. package/dist/contracts/Timers/IZLinkTimer.js +2 -0
  189. package/dist/contracts/Timers/ZLinkTimerOptions.d.ts +10 -0
  190. package/dist/contracts/Timers/ZLinkTimerOptions.js +9 -0
  191. package/dist/contracts/Timers/ZLinkTimerTick.d.ts +12 -0
  192. package/dist/contracts/Timers/ZLinkTimerTick.js +2 -0
  193. package/dist/contracts/Timers/index.d.ts +3 -0
  194. package/dist/contracts/Timers/index.js +19 -0
  195. package/dist/contracts/index.d.ts +25 -0
  196. package/dist/contracts/index.js +45 -0
  197. package/dist/index.d.ts +1 -0
  198. package/dist/index.js +17 -0
  199. package/dist/internal.d.ts +26 -0
  200. package/dist/internal.js +48 -0
  201. package/dist/location-store-integration.d.ts +5 -0
  202. package/dist/location-store-integration.js +31 -0
  203. package/dist/nest-integration.d.ts +49 -0
  204. package/dist/nest-integration.js +143 -0
  205. package/dist/runtime/abort.d.ts +13 -0
  206. package/dist/runtime/abort.js +71 -0
  207. package/dist/runtime/actors/actor-authority-payload-codec.d.ts +33 -0
  208. package/dist/runtime/actors/actor-authority-payload-codec.js +366 -0
  209. package/dist/runtime/actors/actor-authority-publication.d.ts +28 -0
  210. package/dist/runtime/actors/actor-authority-publication.js +207 -0
  211. package/dist/runtime/actors/actor-client.d.ts +36 -0
  212. package/dist/runtime/actors/actor-client.js +612 -0
  213. package/dist/runtime/actors/actor-context.d.ts +26 -0
  214. package/dist/runtime/actors/actor-context.js +433 -0
  215. package/dist/runtime/actors/actor-creation.d.ts +19 -0
  216. package/dist/runtime/actors/actor-creation.js +158 -0
  217. package/dist/runtime/actors/actor-execution-context.d.ts +6 -0
  218. package/dist/runtime/actors/actor-execution-context.js +27 -0
  219. package/dist/runtime/actors/actor-handoff.d.ts +191 -0
  220. package/dist/runtime/actors/actor-handoff.js +1252 -0
  221. package/dist/runtime/actors/actor-join-deferred-scope.d.ts +11 -0
  222. package/dist/runtime/actors/actor-join-deferred-scope.js +144 -0
  223. package/dist/runtime/actors/actor-join-relocation.d.ts +38 -0
  224. package/dist/runtime/actors/actor-join-relocation.js +2 -0
  225. package/dist/runtime/actors/actor-lifecycle-snapshot.d.ts +21 -0
  226. package/dist/runtime/actors/actor-lifecycle-snapshot.js +58 -0
  227. package/dist/runtime/actors/actor-local-native-join.d.ts +27 -0
  228. package/dist/runtime/actors/actor-local-native-join.js +409 -0
  229. package/dist/runtime/actors/actor-mailbox.d.ts +10 -0
  230. package/dist/runtime/actors/actor-mailbox.js +53 -0
  231. package/dist/runtime/actors/actor-message-follow-context.d.ts +46 -0
  232. package/dist/runtime/actors/actor-message-follow-context.js +257 -0
  233. package/dist/runtime/actors/actor-native-lookup.d.ts +4 -0
  234. package/dist/runtime/actors/actor-native-lookup.js +30 -0
  235. package/dist/runtime/actors/actor-packet-relay-wire.d.ts +73 -0
  236. package/dist/runtime/actors/actor-packet-relay-wire.js +144 -0
  237. package/dist/runtime/actors/actor-remote-joiner.d.ts +37 -0
  238. package/dist/runtime/actors/actor-remote-joiner.js +122 -0
  239. package/dist/runtime/actors/actor-remote-wire.d.ts +73 -0
  240. package/dist/runtime/actors/actor-remote-wire.js +84 -0
  241. package/dist/runtime/actors/actor-retry-delay.d.ts +5 -0
  242. package/dist/runtime/actors/actor-retry-delay.js +40 -0
  243. package/dist/runtime/actors/actor-routed-join-transport.d.ts +33 -0
  244. package/dist/runtime/actors/actor-routed-join-transport.js +2 -0
  245. package/dist/runtime/actors/actor-routed-json-request.d.ts +11 -0
  246. package/dist/runtime/actors/actor-routed-json-request.js +39 -0
  247. package/dist/runtime/actors/actor-runtime-contracts.d.ts +63 -0
  248. package/dist/runtime/actors/actor-runtime-contracts.js +2 -0
  249. package/dist/runtime/actors/actor-runtime-state.d.ts +152 -0
  250. package/dist/runtime/actors/actor-runtime-state.js +545 -0
  251. package/dist/runtime/actors/actor-source-transfer.d.ts +27 -0
  252. package/dist/runtime/actors/actor-source-transfer.js +2 -0
  253. package/dist/runtime/actors/actor-transfer-registry.d.ts +18 -0
  254. package/dist/runtime/actors/actor-transfer-registry.js +71 -0
  255. package/dist/runtime/actors/actor-transport-delivery-gate.d.ts +6 -0
  256. package/dist/runtime/actors/actor-transport-delivery-gate.js +4 -0
  257. package/dist/runtime/actors/bound-session-wire.d.ts +81 -0
  258. package/dist/runtime/actors/bound-session-wire.js +184 -0
  259. package/dist/runtime/actors/deferred-join-accepted-journal.d.ts +47 -0
  260. package/dist/runtime/actors/deferred-join-accepted-journal.js +962 -0
  261. package/dist/runtime/actors/index.d.ts +79 -0
  262. package/dist/runtime/actors/index.js +639 -0
  263. package/dist/runtime/actors/post-commit-actor-binder.d.ts +18 -0
  264. package/dist/runtime/actors/post-commit-actor-binder.js +68 -0
  265. package/dist/runtime/actors/post-commit-actor-location.d.ts +19 -0
  266. package/dist/runtime/actors/post-commit-actor-location.js +72 -0
  267. package/dist/runtime/actors/spot-actor-dispatch.d.ts +59 -0
  268. package/dist/runtime/actors/spot-actor-dispatch.js +179 -0
  269. package/dist/runtime/actors/transferred-actor-rollback.d.ts +16 -0
  270. package/dist/runtime/actors/transferred-actor-rollback.js +91 -0
  271. package/dist/runtime/admission.d.ts +20 -0
  272. package/dist/runtime/admission.js +166 -0
  273. package/dist/runtime/application-jobs/application-ingress-record-owner.d.ts +57 -0
  274. package/dist/runtime/application-jobs/application-ingress-record-owner.js +185 -0
  275. package/dist/runtime/application-jobs/application-job-queue-handler-start-gate.d.ts +8 -0
  276. package/dist/runtime/application-jobs/application-job-queue-handler-start-gate.js +8 -0
  277. package/dist/runtime/application-jobs/application-job-queue-scope.d.ts +17 -0
  278. package/dist/runtime/application-jobs/application-job-queue-scope.js +57 -0
  279. package/dist/runtime/application-jobs/contracts.d.ts +19 -0
  280. package/dist/runtime/application-jobs/contracts.js +2 -0
  281. package/dist/runtime/application-jobs/receive-flow-controller.d.ts +32 -0
  282. package/dist/runtime/application-jobs/receive-flow-controller.js +165 -0
  283. package/dist/runtime/backend/contracts/index.d.ts +487 -0
  284. package/dist/runtime/backend/contracts/index.js +29 -0
  285. package/dist/runtime/backend/index.d.ts +9 -0
  286. package/dist/runtime/backend/index.js +25 -0
  287. package/dist/runtime/backend/mesh-actor-session-node-adapter.d.ts +3 -0
  288. package/dist/runtime/backend/mesh-actor-session-node-adapter.js +51 -0
  289. package/dist/runtime/backend/mesh-completion-table.d.ts +34 -0
  290. package/dist/runtime/backend/mesh-completion-table.js +124 -0
  291. package/dist/runtime/backend/mesh-dispatch-pump.d.ts +48 -0
  292. package/dist/runtime/backend/mesh-dispatch-pump.js +322 -0
  293. package/dist/runtime/backend/mesh-record-dispatcher.d.ts +19 -0
  294. package/dist/runtime/backend/mesh-record-dispatcher.js +53 -0
  295. package/dist/runtime/backend/node/index.d.ts +4 -0
  296. package/dist/runtime/backend/node/index.js +22 -0
  297. package/dist/runtime/backend/node/node-backend-adapter-factory.d.ts +12 -0
  298. package/dist/runtime/backend/node/node-backend-adapter-factory.js +161 -0
  299. package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +52 -0
  300. package/dist/runtime/backend/node/node-backend-adapter-support.js +203 -0
  301. package/dist/runtime/backend/node/node-dealer-channel-client-transport.d.ts +13 -0
  302. package/dist/runtime/backend/node/node-dealer-channel-client-transport.js +52 -0
  303. package/dist/runtime/backend/node/node-mesh-backend-adapter.d.ts +11 -0
  304. package/dist/runtime/backend/node/node-mesh-backend-adapter.js +23 -0
  305. package/dist/runtime/backend/node/node-monitor-backend-adapter.d.ts +6 -0
  306. package/dist/runtime/backend/node/node-monitor-backend-adapter.js +38 -0
  307. package/dist/runtime/backend/node/node-raw-binding-port.d.ts +8 -0
  308. package/dist/runtime/backend/node/node-raw-binding-port.js +411 -0
  309. package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +266 -0
  310. package/dist/runtime/backend/node/node-raw-mesh-backend.js +1707 -0
  311. package/dist/runtime/backend/node/node-socket-backend-adapter.d.ts +9 -0
  312. package/dist/runtime/backend/node/node-socket-backend-adapter.js +286 -0
  313. package/dist/runtime/backend/node-backend-adapter.d.ts +9 -0
  314. package/dist/runtime/backend/node-backend-adapter.js +12 -0
  315. package/dist/runtime/backend/raw-binding-port.d.ts +58 -0
  316. package/dist/runtime/backend/raw-binding-port.js +2 -0
  317. package/dist/runtime/backend/runtime-message.d.ts +14 -0
  318. package/dist/runtime/backend/runtime-message.js +44 -0
  319. package/dist/runtime/backend/runtime-values.d.ts +78 -0
  320. package/dist/runtime/backend/runtime-values.js +66 -0
  321. package/dist/runtime/channels/channel-autoconnect.d.ts +14 -0
  322. package/dist/runtime/channels/channel-autoconnect.js +23 -0
  323. package/dist/runtime/channels/channel-clients.d.ts +50 -0
  324. package/dist/runtime/channels/channel-clients.js +329 -0
  325. package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +76 -0
  326. package/dist/runtime/channels/channel-dispatch-pipeline.js +237 -0
  327. package/dist/runtime/channels/channel-dispatch-services.d.ts +52 -0
  328. package/dist/runtime/channels/channel-dispatch-services.js +132 -0
  329. package/dist/runtime/channels/channel-dispatchers.d.ts +125 -0
  330. package/dist/runtime/channels/channel-dispatchers.js +575 -0
  331. package/dist/runtime/channels/channel-envelope-inspection.d.ts +25 -0
  332. package/dist/runtime/channels/channel-envelope-inspection.js +96 -0
  333. package/dist/runtime/channels/channel-envelope.d.ts +73 -0
  334. package/dist/runtime/channels/channel-envelope.js +546 -0
  335. package/dist/runtime/channels/channel-framework-packets.d.ts +2 -0
  336. package/dist/runtime/channels/channel-framework-packets.js +6 -0
  337. package/dist/runtime/channels/channel-multipart.d.ts +16 -0
  338. package/dist/runtime/channels/channel-multipart.js +31 -0
  339. package/dist/runtime/channels/channel-outbound-operations.d.ts +33 -0
  340. package/dist/runtime/channels/channel-outbound-operations.js +343 -0
  341. package/dist/runtime/channels/channel-receive-loops.d.ts +151 -0
  342. package/dist/runtime/channels/channel-receive-loops.js +728 -0
  343. package/dist/runtime/channels/channel-receive-task-tracker.d.ts +14 -0
  344. package/dist/runtime/channels/channel-receive-task-tracker.js +37 -0
  345. package/dist/runtime/channels/channel-runtime-lifecycle.d.ts +77 -0
  346. package/dist/runtime/channels/channel-runtime-lifecycle.js +630 -0
  347. package/dist/runtime/channels/channel-runtime-manager.d.ts +84 -0
  348. package/dist/runtime/channels/channel-runtime-manager.js +193 -0
  349. package/dist/runtime/channels/channel-socket-options.d.ts +18 -0
  350. package/dist/runtime/channels/channel-socket-options.js +119 -0
  351. package/dist/runtime/channels/channel-socket-registry.d.ts +157 -0
  352. package/dist/runtime/channels/channel-socket-registry.js +1428 -0
  353. package/dist/runtime/channels/channel-transports.d.ts +126 -0
  354. package/dist/runtime/channels/channel-transports.js +448 -0
  355. package/dist/runtime/channels/client-server-location-runtime.d.ts +41 -0
  356. package/dist/runtime/channels/client-server-location-runtime.js +465 -0
  357. package/dist/runtime/channels/client-server-service-wire.d.ts +48 -0
  358. package/dist/runtime/channels/client-server-service-wire.js +306 -0
  359. package/dist/runtime/channels/dispatch-error-reporter.d.ts +22 -0
  360. package/dist/runtime/channels/dispatch-error-reporter.js +133 -0
  361. package/dist/runtime/channels/fanout-location-runtime.d.ts +38 -0
  362. package/dist/runtime/channels/fanout-location-runtime.js +356 -0
  363. package/dist/runtime/channels/fanout-service-wire.d.ts +12 -0
  364. package/dist/runtime/channels/fanout-service-wire.js +29 -0
  365. package/dist/runtime/channels/handler-filter-scope.d.ts +8 -0
  366. package/dist/runtime/channels/handler-filter-scope.js +11 -0
  367. package/dist/runtime/channels/index.d.ts +9 -0
  368. package/dist/runtime/channels/index.js +30 -0
  369. package/dist/runtime/channels/local-spot-route-transport.d.ts +9 -0
  370. package/dist/runtime/channels/local-spot-route-transport.js +40 -0
  371. package/dist/runtime/channels/route-disconnected-error.d.ts +3 -0
  372. package/dist/runtime/channels/route-disconnected-error.js +10 -0
  373. package/dist/runtime/channels/route-member-snapshot.d.ts +10 -0
  374. package/dist/runtime/channels/route-member-snapshot.js +55 -0
  375. package/dist/runtime/channels/router-socket-spot-route-transport.d.ts +12 -0
  376. package/dist/runtime/channels/router-socket-spot-route-transport.js +43 -0
  377. package/dist/runtime/channels/source-spot-router.d.ts +10 -0
  378. package/dist/runtime/channels/source-spot-router.js +46 -0
  379. package/dist/runtime/channels/spot-direct-envelope.d.ts +5 -0
  380. package/dist/runtime/channels/spot-direct-envelope.js +29 -0
  381. package/dist/runtime/channels/spot-node-route-transport.d.ts +13 -0
  382. package/dist/runtime/channels/spot-node-route-transport.js +60 -0
  383. package/dist/runtime/channels/spot-route-bridge-transport.d.ts +14 -0
  384. package/dist/runtime/channels/spot-route-bridge-transport.js +58 -0
  385. package/dist/runtime/channels/spot-route-dispatch-strategy.d.ts +50 -0
  386. package/dist/runtime/channels/spot-route-dispatch-strategy.js +128 -0
  387. package/dist/runtime/channels/spot-route-target-resolver.d.ts +16 -0
  388. package/dist/runtime/channels/spot-route-target-resolver.js +92 -0
  389. package/dist/runtime/codecs/index.d.ts +14 -0
  390. package/dist/runtime/codecs/index.js +44 -0
  391. package/dist/runtime/configuration/index.d.ts +1 -0
  392. package/dist/runtime/configuration/index.js +17 -0
  393. package/dist/runtime/diagnostics/dispatch-error-port.d.ts +8 -0
  394. package/dist/runtime/diagnostics/dispatch-error-port.js +2 -0
  395. package/dist/runtime/diagnostics/flow-context.d.ts +21 -0
  396. package/dist/runtime/diagnostics/flow-context.js +68 -0
  397. package/dist/runtime/diagnostics/index.d.ts +82 -0
  398. package/dist/runtime/diagnostics/index.js +335 -0
  399. package/dist/runtime/diagnostics/internal-event-contracts.d.ts +139 -0
  400. package/dist/runtime/diagnostics/internal-event-contracts.js +68 -0
  401. package/dist/runtime/diagnostics/message-flow.d.ts +55 -0
  402. package/dist/runtime/diagnostics/message-flow.js +420 -0
  403. package/dist/runtime/diagnostics/runtime-metrics.d.ts +123 -0
  404. package/dist/runtime/diagnostics/runtime-metrics.js +454 -0
  405. package/dist/runtime/diagnostics/runtime-observation-queue.d.ts +58 -0
  406. package/dist/runtime/diagnostics/runtime-observation-queue.js +324 -0
  407. package/dist/runtime/diagnostics/topology-runtime-projections.d.ts +33 -0
  408. package/dist/runtime/diagnostics/topology-runtime-projections.js +255 -0
  409. package/dist/runtime/execution/index.d.ts +114 -0
  410. package/dist/runtime/execution/index.js +363 -0
  411. package/dist/runtime/execution/serial-execution-queue.d.ts +94 -0
  412. package/dist/runtime/execution/serial-execution-queue.js +411 -0
  413. package/dist/runtime/execution/serial-work-size.d.ts +4 -0
  414. package/dist/runtime/execution/serial-work-size.js +28 -0
  415. package/dist/runtime/execution/state-lane.d.ts +28 -0
  416. package/dist/runtime/execution/state-lane.js +105 -0
  417. package/dist/runtime/foundation/actor-join-recovery-codec.d.ts +72 -0
  418. package/dist/runtime/foundation/actor-join-recovery-codec.js +333 -0
  419. package/dist/runtime/foundation/event-loop-resources.d.ts +37 -0
  420. package/dist/runtime/foundation/event-loop-resources.js +163 -0
  421. package/dist/runtime/foundation/index.d.ts +18 -0
  422. package/dist/runtime/foundation/index.js +34 -0
  423. package/dist/runtime/foundation/message-follow-suppression-registry.d.ts +38 -0
  424. package/dist/runtime/foundation/message-follow-suppression-registry.js +89 -0
  425. package/dist/runtime/foundation/operation-identity.d.ts +12 -0
  426. package/dist/runtime/foundation/operation-identity.js +33 -0
  427. package/dist/runtime/foundation/operation-registry.d.ts +42 -0
  428. package/dist/runtime/foundation/operation-registry.js +146 -0
  429. package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +143 -0
  430. package/dist/runtime/foundation/raw-service-mesh-runtime.js +1349 -0
  431. package/dist/runtime/foundation/route-mesh-connection-policy.d.ts +3 -0
  432. package/dist/runtime/foundation/route-mesh-connection-policy.js +13 -0
  433. package/dist/runtime/foundation/runtime-state-projections.d.ts +13 -0
  434. package/dist/runtime/foundation/runtime-state-projections.js +44 -0
  435. package/dist/runtime/foundation/service-authority-payload-codec.d.ts +56 -0
  436. package/dist/runtime/foundation/service-authority-payload-codec.js +411 -0
  437. package/dist/runtime/foundation/service-discovery-registry.d.ts +42 -0
  438. package/dist/runtime/foundation/service-discovery-registry.js +175 -0
  439. package/dist/runtime/foundation/service-instance-activation-recovery-codec.d.ts +19 -0
  440. package/dist/runtime/foundation/service-instance-activation-recovery-codec.js +287 -0
  441. package/dist/runtime/foundation/service-liveness-registry.d.ts +28 -0
  442. package/dist/runtime/foundation/service-liveness-registry.js +109 -0
  443. package/dist/runtime/foundation/service-mailbox.d.ts +60 -0
  444. package/dist/runtime/foundation/service-mailbox.js +283 -0
  445. package/dist/runtime/foundation/service-maintenance-runtime.d.ts +45 -0
  446. package/dist/runtime/foundation/service-maintenance-runtime.js +198 -0
  447. package/dist/runtime/foundation/service-metadata-codec.d.ts +2 -0
  448. package/dist/runtime/foundation/service-metadata-codec.js +69 -0
  449. package/dist/runtime/foundation/service-relocation-aggregate-committer.d.ts +35 -0
  450. package/dist/runtime/foundation/service-relocation-aggregate-committer.js +139 -0
  451. package/dist/runtime/foundation/service-relocation-coordinator.d.ts +19 -0
  452. package/dist/runtime/foundation/service-relocation-coordinator.js +16 -0
  453. package/dist/runtime/foundation/service-relocation-object-owner.d.ts +71 -0
  454. package/dist/runtime/foundation/service-relocation-object-owner.js +242 -0
  455. package/dist/runtime/foundation/service-relocation-runtime.d.ts +143 -0
  456. package/dist/runtime/foundation/service-relocation-runtime.js +1080 -0
  457. package/dist/runtime/foundation/service-runtime-contracts.d.ts +332 -0
  458. package/dist/runtime/foundation/service-runtime-contracts.js +66 -0
  459. package/dist/runtime/foundation/service-session-binding-ingress-port.d.ts +23 -0
  460. package/dist/runtime/foundation/service-session-binding-ingress-port.js +11 -0
  461. package/dist/runtime/foundation/service-stateful-registry.d.ts +142 -0
  462. package/dist/runtime/foundation/service-stateful-registry.js +465 -0
  463. package/dist/runtime/foundation/service-stateful-runtime.d.ts +393 -0
  464. package/dist/runtime/foundation/service-stateful-runtime.js +3898 -0
  465. package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +597 -0
  466. package/dist/runtime/foundation/service-stateful-wire-codec.js +2006 -0
  467. package/dist/runtime/foundation/service-topology-registry.d.ts +68 -0
  468. package/dist/runtime/foundation/service-topology-registry.js +393 -0
  469. package/dist/runtime/foundation/service-weighted-selection.d.ts +14 -0
  470. package/dist/runtime/foundation/service-weighted-selection.js +128 -0
  471. package/dist/runtime/foundation/service-wire-binary-primitives.d.ts +10 -0
  472. package/dist/runtime/foundation/service-wire-binary-primitives.js +53 -0
  473. package/dist/runtime/foundation/service-wire-codec.d.ts +22 -0
  474. package/dist/runtime/foundation/service-wire-codec.js +67 -0
  475. package/dist/runtime/foundation/service-wire-constants.generated.d.ts +110 -0
  476. package/dist/runtime/foundation/service-wire-constants.generated.js +132 -0
  477. package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +102 -0
  478. package/dist/runtime/foundation/service-wire-m6a-codec.js +568 -0
  479. package/dist/runtime/framework-errors-internal.d.ts +95 -0
  480. package/dist/runtime/framework-errors-internal.js +301 -0
  481. package/dist/runtime/handlers/handler-instance-scope.d.ts +11 -0
  482. package/dist/runtime/handlers/handler-instance-scope.js +284 -0
  483. package/dist/runtime/handlers/index.d.ts +13 -0
  484. package/dist/runtime/handlers/index.js +57 -0
  485. package/dist/runtime/host/actor-packet-relay.d.ts +60 -0
  486. package/dist/runtime/host/actor-packet-relay.js +664 -0
  487. package/dist/runtime/host/actor-placement-coordinator.d.ts +32 -0
  488. package/dist/runtime/host/actor-placement-coordinator.js +386 -0
  489. package/dist/runtime/host/actor-runtime-options-factory.d.ts +65 -0
  490. package/dist/runtime/host/actor-runtime-options-factory.js +160 -0
  491. package/dist/runtime/host/actor-transfer-authority-runtime.d.ts +26 -0
  492. package/dist/runtime/host/actor-transfer-authority-runtime.js +138 -0
  493. package/dist/runtime/host/actor-transfer-runtime.d.ts +149 -0
  494. package/dist/runtime/host/actor-transfer-runtime.js +1245 -0
  495. package/dist/runtime/host/application-job-queue.d.ts +99 -0
  496. package/dist/runtime/host/application-job-queue.js +409 -0
  497. package/dist/runtime/host/bound-session-relay.d.ts +41 -0
  498. package/dist/runtime/host/bound-session-relay.js +52 -0
  499. package/dist/runtime/host/bounded-replay-map.d.ts +12 -0
  500. package/dist/runtime/host/bounded-replay-map.js +42 -0
  501. package/dist/runtime/host/channel-runtime-options-factory.d.ts +22 -0
  502. package/dist/runtime/host/channel-runtime-options-factory.js +76 -0
  503. package/dist/runtime/host/entry-actor-runtime.d.ts +30 -0
  504. package/dist/runtime/host/entry-actor-runtime.js +80 -0
  505. package/dist/runtime/host/host-capacity-status.d.ts +11 -0
  506. package/dist/runtime/host/host-capacity-status.js +85 -0
  507. package/dist/runtime/host/index.d.ts +188 -0
  508. package/dist/runtime/host/index.js +2552 -0
  509. package/dist/runtime/host/instance-activation-authority.d.ts +33 -0
  510. package/dist/runtime/host/instance-activation-authority.js +496 -0
  511. package/dist/runtime/host/location-runtime-owner.d.ts +48 -0
  512. package/dist/runtime/host/location-runtime-owner.js +227 -0
  513. package/dist/runtime/host/mesh-router-resolver.d.ts +16 -0
  514. package/dist/runtime/host/mesh-router-resolver.js +108 -0
  515. package/dist/runtime/host/relocation-direct-transfer.d.ts +81 -0
  516. package/dist/runtime/host/relocation-direct-transfer.js +240 -0
  517. package/dist/runtime/host/relocation-integrity-fault-gate.d.ts +6 -0
  518. package/dist/runtime/host/relocation-integrity-fault-gate.js +5 -0
  519. package/dist/runtime/host/relocation-state-adapter.d.ts +8 -0
  520. package/dist/runtime/host/relocation-state-adapter.js +13 -0
  521. package/dist/runtime/host/remote-actor-join-receiver.d.ts +47 -0
  522. package/dist/runtime/host/remote-actor-join-receiver.js +161 -0
  523. package/dist/runtime/host/remote-actor-packet-target-store.d.ts +29 -0
  524. package/dist/runtime/host/remote-actor-packet-target-store.js +185 -0
  525. package/dist/runtime/host/remote-bound-session-relay.d.ts +58 -0
  526. package/dist/runtime/host/remote-bound-session-relay.js +540 -0
  527. package/dist/runtime/host/route-mesh-runtime-options.d.ts +9 -0
  528. package/dist/runtime/host/route-mesh-runtime-options.js +41 -0
  529. package/dist/runtime/host/route-mesh-runtime.d.ts +76 -0
  530. package/dist/runtime/host/route-mesh-runtime.js +746 -0
  531. package/dist/runtime/host/runtime-shutdown.d.ts +33 -0
  532. package/dist/runtime/host/runtime-shutdown.js +68 -0
  533. package/dist/runtime/host/service-relocation-control.d.ts +7 -0
  534. package/dist/runtime/host/service-relocation-control.js +24 -0
  535. package/dist/runtime/host/service-relocation-host-runtime.d.ts +241 -0
  536. package/dist/runtime/host/service-relocation-host-runtime.js +4113 -0
  537. package/dist/runtime/host/spot-address-transport.d.ts +47 -0
  538. package/dist/runtime/host/spot-address-transport.js +601 -0
  539. package/dist/runtime/host/spot-node-runtime-options-factory.d.ts +38 -0
  540. package/dist/runtime/host/spot-node-runtime-options-factory.js +36 -0
  541. package/dist/runtime/host/spot-runtime-options-factory.d.ts +48 -0
  542. package/dist/runtime/host/spot-runtime-options-factory.js +169 -0
  543. package/dist/runtime/host/stateful-authority-route-runtime.d.ts +34 -0
  544. package/dist/runtime/host/stateful-authority-route-runtime.js +440 -0
  545. package/dist/runtime/host/user-spot-creation-coordinator.d.ts +69 -0
  546. package/dist/runtime/host/user-spot-creation-coordinator.js +759 -0
  547. package/dist/runtime/locations/actor-location-claims.d.ts +43 -0
  548. package/dist/runtime/locations/actor-location-claims.js +319 -0
  549. package/dist/runtime/locations/actor-session-route-claims.d.ts +10 -0
  550. package/dist/runtime/locations/actor-session-route-claims.js +51 -0
  551. package/dist/runtime/locations/aggregate-inventory-store.d.ts +18 -0
  552. package/dist/runtime/locations/aggregate-inventory-store.js +399 -0
  553. package/dist/runtime/locations/authority-key-codec.d.ts +6 -0
  554. package/dist/runtime/locations/authority-key-codec.js +78 -0
  555. package/dist/runtime/locations/auto-connect-loop.d.ts +37 -0
  556. package/dist/runtime/locations/auto-connect-loop.js +112 -0
  557. package/dist/runtime/locations/auto-connect-planner.d.ts +9 -0
  558. package/dist/runtime/locations/auto-connect-planner.js +137 -0
  559. package/dist/runtime/locations/auto-connect-reconciler.d.ts +57 -0
  560. package/dist/runtime/locations/auto-connect-reconciler.js +358 -0
  561. package/dist/runtime/locations/auto-connect-types.d.ts +42 -0
  562. package/dist/runtime/locations/auto-connect-types.js +2 -0
  563. package/dist/runtime/locations/auto-connect.d.ts +4 -0
  564. package/dist/runtime/locations/auto-connect.js +20 -0
  565. package/dist/runtime/locations/canonical-codec.d.ts +7 -0
  566. package/dist/runtime/locations/canonical-codec.js +48 -0
  567. package/dist/runtime/locations/domain-store-contract.d.ts +34 -0
  568. package/dist/runtime/locations/domain-store-contract.js +2 -0
  569. package/dist/runtime/locations/in-memory-authority-store.d.ts +51 -0
  570. package/dist/runtime/locations/in-memory-authority-store.js +895 -0
  571. package/dist/runtime/locations/in-memory-location-store.d.ts +78 -0
  572. package/dist/runtime/locations/in-memory-location-store.js +1008 -0
  573. package/dist/runtime/locations/in-memory-provider-location-store.d.ts +19 -0
  574. package/dist/runtime/locations/in-memory-provider-location-store.js +183 -0
  575. package/dist/runtime/locations/index.d.ts +11 -0
  576. package/dist/runtime/locations/index.js +27 -0
  577. package/dist/runtime/locations/internal-location-contracts.d.ts +7 -0
  578. package/dist/runtime/locations/internal-location-contracts.js +21 -0
  579. package/dist/runtime/locations/internal-store-contracts.d.ts +35 -0
  580. package/dist/runtime/locations/internal-store-contracts.js +2 -0
  581. package/dist/runtime/locations/key-codec.d.ts +13 -0
  582. package/dist/runtime/locations/key-codec.js +41 -0
  583. package/dist/runtime/locations/lease-tracker.d.ts +36 -0
  584. package/dist/runtime/locations/lease-tracker.js +155 -0
  585. package/dist/runtime/locations/lifecycle-runtime.d.ts +19 -0
  586. package/dist/runtime/locations/lifecycle-runtime.js +2 -0
  587. package/dist/runtime/locations/lifecycle.d.ts +40 -0
  588. package/dist/runtime/locations/lifecycle.js +120 -0
  589. package/dist/runtime/locations/location-store-repository.d.ts +72 -0
  590. package/dist/runtime/locations/location-store-repository.js +3198 -0
  591. package/dist/runtime/locations/relocation-blob.d.ts +7 -0
  592. package/dist/runtime/locations/relocation-blob.js +24 -0
  593. package/dist/runtime/locations/resolvers.d.ts +145 -0
  594. package/dist/runtime/locations/resolvers.js +693 -0
  595. package/dist/runtime/locations/runtime.d.ts +144 -0
  596. package/dist/runtime/locations/runtime.js +792 -0
  597. package/dist/runtime/locations/spot-location-claims.d.ts +36 -0
  598. package/dist/runtime/locations/spot-location-claims.js +305 -0
  599. package/dist/runtime/messaging/creation-payload-codec.d.ts +4 -0
  600. package/dist/runtime/messaging/creation-payload-codec.js +40 -0
  601. package/dist/runtime/messaging/framework-json-v1.d.ts +7 -0
  602. package/dist/runtime/messaging/framework-json-v1.js +296 -0
  603. package/dist/runtime/messaging/index.d.ts +1 -0
  604. package/dist/runtime/messaging/index.js +2 -0
  605. package/dist/runtime/messaging/packet-name.d.ts +4 -0
  606. package/dist/runtime/messaging/packet-name.js +79 -0
  607. package/dist/runtime/messaging/payload-codec.d.ts +25 -0
  608. package/dist/runtime/messaging/payload-codec.js +255 -0
  609. package/dist/runtime/messaging/submission-result.d.ts +15 -0
  610. package/dist/runtime/messaging/submission-result.js +37 -0
  611. package/dist/runtime/protocol/service_wire_pilot_codec.generated.d.ts +395 -0
  612. package/dist/runtime/protocol/service_wire_pilot_codec.generated.js +645 -0
  613. package/dist/runtime/routing-id.d.ts +8 -0
  614. package/dist/runtime/routing-id.js +112 -0
  615. package/dist/runtime/spots/formal-remote-actor-admission-registry.d.ts +124 -0
  616. package/dist/runtime/spots/formal-remote-actor-admission-registry.js +269 -0
  617. package/dist/runtime/spots/formal-remote-actor-transfer-registry.d.ts +33 -0
  618. package/dist/runtime/spots/formal-remote-actor-transfer-registry.js +94 -0
  619. package/dist/runtime/spots/index.d.ts +247 -0
  620. package/dist/runtime/spots/index.js +2090 -0
  621. package/dist/runtime/spots/spot-activation-registry.d.ts +47 -0
  622. package/dist/runtime/spots/spot-activation-registry.js +272 -0
  623. package/dist/runtime/spots/spot-activation-state.d.ts +104 -0
  624. package/dist/runtime/spots/spot-activation-state.js +288 -0
  625. package/dist/runtime/spots/spot-activation.d.ts +89 -0
  626. package/dist/runtime/spots/spot-activation.js +601 -0
  627. package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +20 -0
  628. package/dist/runtime/spots/spot-actor-admission-coordinator.js +194 -0
  629. package/dist/runtime/spots/spot-actor-join-dispatch.d.ts +83 -0
  630. package/dist/runtime/spots/spot-actor-join-dispatch.js +185 -0
  631. package/dist/runtime/spots/spot-actor-lifecycle-drain.d.ts +22 -0
  632. package/dist/runtime/spots/spot-actor-lifecycle-drain.js +51 -0
  633. package/dist/runtime/spots/spot-actor-membership.d.ts +39 -0
  634. package/dist/runtime/spots/spot-actor-membership.js +179 -0
  635. package/dist/runtime/spots/spot-actor-packet-dispatch.d.ts +91 -0
  636. package/dist/runtime/spots/spot-actor-packet-dispatch.js +315 -0
  637. package/dist/runtime/spots/spot-actor-packet-drain.d.ts +40 -0
  638. package/dist/runtime/spots/spot-actor-packet-drain.js +235 -0
  639. package/dist/runtime/spots/spot-actor-packet-relay-dispatch.d.ts +18 -0
  640. package/dist/runtime/spots/spot-actor-packet-relay-dispatch.js +110 -0
  641. package/dist/runtime/spots/spot-closing.d.ts +2 -0
  642. package/dist/runtime/spots/spot-closing.js +30 -0
  643. package/dist/runtime/spots/spot-context.d.ts +46 -0
  644. package/dist/runtime/spots/spot-context.js +113 -0
  645. package/dist/runtime/spots/spot-entry-activation.d.ts +107 -0
  646. package/dist/runtime/spots/spot-entry-activation.js +342 -0
  647. package/dist/runtime/spots/spot-handle.d.ts +28 -0
  648. package/dist/runtime/spots/spot-handle.js +38 -0
  649. package/dist/runtime/spots/spot-handler-registry.d.ts +52 -0
  650. package/dist/runtime/spots/spot-handler-registry.js +155 -0
  651. package/dist/runtime/spots/spot-lifecycle-metrics.d.ts +8 -0
  652. package/dist/runtime/spots/spot-lifecycle-metrics.js +16 -0
  653. package/dist/runtime/spots/spot-location-claim.d.ts +25 -0
  654. package/dist/runtime/spots/spot-location-claim.js +55 -0
  655. package/dist/runtime/spots/spot-manager-internal-contracts.d.ts +10 -0
  656. package/dist/runtime/spots/spot-manager-internal-contracts.js +2 -0
  657. package/dist/runtime/spots/spot-manager-public.d.ts +32 -0
  658. package/dist/runtime/spots/spot-manager-public.js +219 -0
  659. package/dist/runtime/spots/spot-native-actor-join-admission.d.ts +26 -0
  660. package/dist/runtime/spots/spot-native-actor-join-admission.js +105 -0
  661. package/dist/runtime/spots/spot-native-flags.d.ts +2 -0
  662. package/dist/runtime/spots/spot-native-flags.js +5 -0
  663. package/dist/runtime/spots/spot-node-autoconnect.d.ts +23 -0
  664. package/dist/runtime/spots/spot-node-autoconnect.js +246 -0
  665. package/dist/runtime/spots/spot-node-runtime-manager.d.ts +137 -0
  666. package/dist/runtime/spots/spot-node-runtime-manager.js +1111 -0
  667. package/dist/runtime/spots/spot-outbound.d.ts +78 -0
  668. package/dist/runtime/spots/spot-outbound.js +460 -0
  669. package/dist/runtime/spots/spot-provider.d.ts +4 -0
  670. package/dist/runtime/spots/spot-provider.js +28 -0
  671. package/dist/runtime/spots/spot-publisher-transport.d.ts +14 -0
  672. package/dist/runtime/spots/spot-publisher-transport.js +28 -0
  673. package/dist/runtime/spots/spot-remote-codec.d.ts +50 -0
  674. package/dist/runtime/spots/spot-remote-codec.js +190 -0
  675. package/dist/runtime/spots/spot-remote-route-codec.d.ts +47 -0
  676. package/dist/runtime/spots/spot-remote-route-codec.js +168 -0
  677. package/dist/runtime/spots/spot-route-packet-dispatch.d.ts +25 -0
  678. package/dist/runtime/spots/spot-route-packet-dispatch.js +238 -0
  679. package/dist/runtime/spots/spot-route-replies.d.ts +17 -0
  680. package/dist/runtime/spots/spot-route-replies.js +76 -0
  681. package/dist/runtime/spots/spot-route-reply-wire.d.ts +10 -0
  682. package/dist/runtime/spots/spot-route-reply-wire.js +6 -0
  683. package/dist/runtime/spots/spot-routed-actor-admission.d.ts +36 -0
  684. package/dist/runtime/spots/spot-routed-actor-admission.js +240 -0
  685. package/dist/runtime/spots/spot-routed-bound-session-dispatch.d.ts +19 -0
  686. package/dist/runtime/spots/spot-routed-bound-session-dispatch.js +46 -0
  687. package/dist/runtime/spots/spot-routed-frame-dispatch.d.ts +54 -0
  688. package/dist/runtime/spots/spot-routed-frame-dispatch.js +162 -0
  689. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.d.ts +43 -0
  690. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.js +152 -0
  691. package/dist/runtime/spots/spot-routing-internal.d.ts +28 -0
  692. package/dist/runtime/spots/spot-routing-internal.js +2 -0
  693. package/dist/runtime/spots/spot-runtime-ports.d.ts +64 -0
  694. package/dist/runtime/spots/spot-runtime-ports.js +2 -0
  695. package/dist/runtime/spots/spot-serial-executor.d.ts +38 -0
  696. package/dist/runtime/spots/spot-serial-executor.js +133 -0
  697. package/dist/runtime/spots/spot-serial-turn-executor.d.ts +54 -0
  698. package/dist/runtime/spots/spot-serial-turn-executor.js +219 -0
  699. package/dist/runtime/spots/spot-subscription-dispatch.d.ts +32 -0
  700. package/dist/runtime/spots/spot-subscription-dispatch.js +194 -0
  701. package/dist/runtime/spots/spot-timer.d.ts +110 -0
  702. package/dist/runtime/spots/spot-timer.js +419 -0
  703. package/dist/runtime/streams/actor-session-binding-registry.d.ts +193 -0
  704. package/dist/runtime/streams/actor-session-binding-registry.js +1127 -0
  705. package/dist/runtime/streams/actor-session-binding-runtime-owner.d.ts +20 -0
  706. package/dist/runtime/streams/actor-session-binding-runtime-owner.js +19 -0
  707. package/dist/runtime/streams/actor-session-lifecycle-coordinator.d.ts +4 -0
  708. package/dist/runtime/streams/actor-session-lifecycle-coordinator.js +24 -0
  709. package/dist/runtime/streams/bound-actor-relay-sender.d.ts +29 -0
  710. package/dist/runtime/streams/bound-actor-relay-sender.js +181 -0
  711. package/dist/runtime/streams/bound-session-response-target.d.ts +25 -0
  712. package/dist/runtime/streams/bound-session-response-target.js +54 -0
  713. package/dist/runtime/streams/bound-session-service.d.ts +48 -0
  714. package/dist/runtime/streams/bound-session-service.js +201 -0
  715. package/dist/runtime/streams/index.d.ts +152 -0
  716. package/dist/runtime/streams/index.js +338 -0
  717. package/dist/runtime/streams/managed-stream.d.ts +53 -0
  718. package/dist/runtime/streams/managed-stream.js +329 -0
  719. package/dist/runtime/streams/native-fallback-bound-session.d.ts +24 -0
  720. package/dist/runtime/streams/native-fallback-bound-session.js +201 -0
  721. package/dist/runtime/streams/protocol.d.ts +67 -0
  722. package/dist/runtime/streams/protocol.js +244 -0
  723. package/dist/runtime/streams/session-actor-coordinator.d.ts +56 -0
  724. package/dist/runtime/streams/session-actor-coordinator.js +371 -0
  725. package/dist/runtime/streams/session-calls.d.ts +59 -0
  726. package/dist/runtime/streams/session-calls.js +123 -0
  727. package/dist/runtime/streams/session-context.d.ts +108 -0
  728. package/dist/runtime/streams/session-context.js +377 -0
  729. package/dist/runtime/streams/session-local-actors.d.ts +10 -0
  730. package/dist/runtime/streams/session-local-actors.js +26 -0
  731. package/dist/runtime/streams/session-provider.d.ts +4 -0
  732. package/dist/runtime/streams/session-provider.js +30 -0
  733. package/dist/runtime/streams/session-requests.d.ts +25 -0
  734. package/dist/runtime/streams/session-requests.js +100 -0
  735. package/dist/runtime/streams/session-serial-executor.d.ts +12 -0
  736. package/dist/runtime/streams/session-serial-executor.js +58 -0
  737. package/dist/runtime/streams/stream-binding-runtime-ports.d.ts +62 -0
  738. package/dist/runtime/streams/stream-binding-runtime-ports.js +2 -0
  739. package/dist/runtime/streams/stream-frame-factory.d.ts +44 -0
  740. package/dist/runtime/streams/stream-frame-factory.js +149 -0
  741. package/dist/runtime/streams/stream-message-utils.d.ts +5 -0
  742. package/dist/runtime/streams/stream-message-utils.js +74 -0
  743. package/dist/runtime/streams/stream-session-runtime.d.ts +166 -0
  744. package/dist/runtime/streams/stream-session-runtime.js +1144 -0
  745. package/dist/runtime/workers/index.d.ts +38 -0
  746. package/dist/runtime/workers/index.js +474 -0
  747. package/package.json +19 -0
  748. package/src/contracts/Actors/ZLinkActor.ts +8 -0
  749. package/src/contracts/Actors/ZLinkActorClient.ts +18 -0
  750. package/src/contracts/Actors/ZLinkActorContext.ts +15 -0
  751. package/src/contracts/Actors/ZLinkActorFactory.ts +41 -0
  752. package/src/contracts/Actors/ZLinkActorManager.ts +31 -0
  753. package/src/contracts/Actors/index.ts +5 -0
  754. package/src/contracts/Channels/Calls.ts +33 -0
  755. package/src/contracts/Channels/IZLinkChannelClient.ts +6 -0
  756. package/src/contracts/Channels/IZLinkFanoutClient.ts +13 -0
  757. package/src/contracts/Channels/RouteCalls.ts +13 -0
  758. package/src/contracts/Channels/index.ts +4 -0
  759. package/src/contracts/Codecs/IZLinkCodecRegistryBuilder.ts +22 -0
  760. package/src/contracts/Codecs/ZLinkMessageSerializer.ts +6 -0
  761. package/src/contracts/Codecs/index.ts +2 -0
  762. package/src/contracts/Common/ActorRef.ts +8 -0
  763. package/src/contracts/Common/CoreTypes.ts +6 -0
  764. package/src/contracts/Common/Message.ts +9 -0
  765. package/src/contracts/Common/ZLinkEncodedPayload.ts +47 -0
  766. package/src/contracts/Common/ZLinkMessage.ts +135 -0
  767. package/src/contracts/Common/ZLinkMessageMetadata.ts +77 -0
  768. package/src/contracts/Common/ZLinkProviderResolver.ts +6 -0
  769. package/src/contracts/Common/encoded-payload-storage.ts +16 -0
  770. package/src/contracts/Common/index.ts +5 -0
  771. package/src/contracts/Configuration/Builders.ts +200 -0
  772. package/src/contracts/Configuration/CodecContentType.ts +68 -0
  773. package/src/contracts/Configuration/CodecSerializerSelection.ts +28 -0
  774. package/src/contracts/Configuration/Configs.ts +27 -0
  775. package/src/contracts/Configuration/ConfigurationException.ts +6 -0
  776. package/src/contracts/Configuration/Connections.ts +5 -0
  777. package/src/contracts/Configuration/DiagnosticsValidation.ts +25 -0
  778. package/src/contracts/Configuration/EndpointNotation.ts +232 -0
  779. package/src/contracts/Configuration/InternalDefaults.ts +13 -0
  780. package/src/contracts/Configuration/ObjectRoles.ts +47 -0
  781. package/src/contracts/Configuration/Registration.ts +191 -0
  782. package/src/contracts/Configuration/RegistrationBuilderPolicy.ts +76 -0
  783. package/src/contracts/Configuration/RegistrationBuilders.ts +1705 -0
  784. package/src/contracts/Configuration/RegistrationCodecRegistry.ts +118 -0
  785. package/src/contracts/Configuration/RegistrationNormalizers.ts +404 -0
  786. package/src/contracts/Configuration/RegistrationTypes.ts +499 -0
  787. package/src/contracts/Configuration/RegistrationValidators.ts +698 -0
  788. package/src/contracts/Configuration/RouteChannelInternalState.ts +50 -0
  789. package/src/contracts/Configuration/RuntimeEndpointConnections.ts +91 -0
  790. package/src/contracts/Configuration/SendTimeoutValidation.ts +15 -0
  791. package/src/contracts/Configuration/TimerRegistrationValidator.ts +37 -0
  792. package/src/contracts/Configuration/index.ts +35 -0
  793. package/src/contracts/Dispatch/ZLinkDispatchOptions.ts +222 -0
  794. package/src/contracts/Dispatch/ZLinkFlowOrigin.ts +1 -0
  795. package/src/contracts/Dispatch/index.ts +2 -0
  796. package/src/contracts/Errors/ZLinkFrameworkException.ts +27 -0
  797. package/src/contracts/Errors/index.ts +4 -0
  798. package/src/contracts/Eventing/Metrics.ts +27 -0
  799. package/src/contracts/Eventing/index.ts +1 -0
  800. package/src/contracts/Handlers/Attributes.ts +111 -0
  801. package/src/contracts/Handlers/Contexts.ts +21 -0
  802. package/src/contracts/Handlers/IZLinkChannelHandlers.ts +69 -0
  803. package/src/contracts/Handlers/IZLinkHandlerFilter.ts +22 -0
  804. package/src/contracts/Handlers/JsonContract.ts +172 -0
  805. package/src/contracts/Handlers/ZLinkHandlerFilterNext.ts +1 -0
  806. package/src/contracts/Handlers/index.ts +17 -0
  807. package/src/contracts/Locations/ActorTransfer.ts +84 -0
  808. package/src/contracts/Locations/Authority.ts +308 -0
  809. package/src/contracts/Locations/Diagnostics.ts +48 -0
  810. package/src/contracts/Locations/Keys.ts +93 -0
  811. package/src/contracts/Locations/Models.ts +7 -0
  812. package/src/contracts/Locations/Options.ts +42 -0
  813. package/src/contracts/Locations/Readiness.ts +11 -0
  814. package/src/contracts/Locations/RelocationStore.ts +51 -0
  815. package/src/contracts/Locations/Resolvers.ts +8 -0
  816. package/src/contracts/Locations/Rows.ts +164 -0
  817. package/src/contracts/Locations/RuntimeQuery.ts +56 -0
  818. package/src/contracts/Locations/Stores.ts +92 -0
  819. package/src/contracts/Locations/Values.ts +32 -0
  820. package/src/contracts/Locations/Watch.ts +16 -0
  821. package/src/contracts/Locations/Writes.ts +56 -0
  822. package/src/contracts/Locations/index.ts +48 -0
  823. package/src/contracts/RouteMesh/Contracts.ts +145 -0
  824. package/src/contracts/RouteMesh/RuntimeTopology.ts +201 -0
  825. package/src/contracts/RouteMesh/index.ts +2 -0
  826. package/src/contracts/Spots/Builders.ts +11 -0
  827. package/src/contracts/Spots/Contracts.ts +150 -0
  828. package/src/contracts/Spots/SpotKind.ts +24 -0
  829. package/src/contracts/Spots/ZLinkSpot.ts +88 -0
  830. package/src/contracts/Spots/index.ts +3 -0
  831. package/src/contracts/Streams/BoundSessionContracts.ts +9 -0
  832. package/src/contracts/Streams/IZLinkSession.ts +52 -0
  833. package/src/contracts/Streams/IZLinkSessionActor.ts +17 -0
  834. package/src/contracts/Streams/IZLinkSessionPacketHandler.ts +11 -0
  835. package/src/contracts/Streams/IZLinkStream.ts +10 -0
  836. package/src/contracts/Streams/ZLinkMessageMetadata.ts +1 -0
  837. package/src/contracts/Streams/ZLinkStreamCompression.ts +9 -0
  838. package/src/contracts/Streams/ZLinkStreamError.ts +9 -0
  839. package/src/contracts/Streams/index.ts +8 -0
  840. package/src/contracts/Timers/IZLinkTimer.ts +5 -0
  841. package/src/contracts/Timers/ZLinkTimerOptions.ts +11 -0
  842. package/src/contracts/Timers/ZLinkTimerTick.ts +12 -0
  843. package/src/contracts/Timers/index.ts +3 -0
  844. package/src/contracts/index.ts +71 -0
  845. package/src/index.ts +1 -0
  846. package/src/internal.ts +29 -0
  847. package/src/location-store-integration.ts +51 -0
  848. package/src/nest-integration.ts +251 -0
  849. package/src/runtime/abort.ts +70 -0
  850. package/src/runtime/actors/actor-authority-payload-codec.ts +454 -0
  851. package/src/runtime/actors/actor-authority-publication.ts +277 -0
  852. package/src/runtime/actors/actor-client.ts +1018 -0
  853. package/src/runtime/actors/actor-context.ts +583 -0
  854. package/src/runtime/actors/actor-creation.ts +254 -0
  855. package/src/runtime/actors/actor-execution-context.ts +38 -0
  856. package/src/runtime/actors/actor-handoff.ts +1911 -0
  857. package/src/runtime/actors/actor-join-deferred-scope.ts +183 -0
  858. package/src/runtime/actors/actor-join-relocation.ts +39 -0
  859. package/src/runtime/actors/actor-lifecycle-snapshot.ts +90 -0
  860. package/src/runtime/actors/actor-local-native-join.ts +725 -0
  861. package/src/runtime/actors/actor-mailbox.ts +92 -0
  862. package/src/runtime/actors/actor-message-follow-context.ts +347 -0
  863. package/src/runtime/actors/actor-native-lookup.ts +38 -0
  864. package/src/runtime/actors/actor-packet-relay-wire.ts +223 -0
  865. package/src/runtime/actors/actor-remote-joiner.ts +238 -0
  866. package/src/runtime/actors/actor-remote-wire.ts +169 -0
  867. package/src/runtime/actors/actor-retry-delay.ts +37 -0
  868. package/src/runtime/actors/actor-routed-join-transport.ts +58 -0
  869. package/src/runtime/actors/actor-routed-json-request.ts +44 -0
  870. package/src/runtime/actors/actor-runtime-contracts.ts +126 -0
  871. package/src/runtime/actors/actor-runtime-state.ts +805 -0
  872. package/src/runtime/actors/actor-source-transfer.ts +62 -0
  873. package/src/runtime/actors/actor-transfer-registry.ts +112 -0
  874. package/src/runtime/actors/actor-transport-delivery-gate.ts +17 -0
  875. package/src/runtime/actors/bound-session-wire.ts +257 -0
  876. package/src/runtime/actors/deferred-join-accepted-journal.ts +1319 -0
  877. package/src/runtime/actors/index.ts +972 -0
  878. package/src/runtime/actors/post-commit-actor-binder.ts +70 -0
  879. package/src/runtime/actors/post-commit-actor-location.ts +114 -0
  880. package/src/runtime/actors/spot-actor-dispatch.ts +362 -0
  881. package/src/runtime/actors/transferred-actor-rollback.ts +123 -0
  882. package/src/runtime/admission.ts +192 -0
  883. package/src/runtime/application-jobs/application-ingress-record-owner.ts +216 -0
  884. package/src/runtime/application-jobs/application-job-queue-handler-start-gate.ts +10 -0
  885. package/src/runtime/application-jobs/application-job-queue-scope.ts +64 -0
  886. package/src/runtime/application-jobs/contracts.ts +26 -0
  887. package/src/runtime/application-jobs/receive-flow-controller.ts +188 -0
  888. package/src/runtime/backend/contracts/index.ts +765 -0
  889. package/src/runtime/backend/index.ts +9 -0
  890. package/src/runtime/backend/mesh-actor-session-node-adapter.ts +73 -0
  891. package/src/runtime/backend/mesh-completion-table.ts +165 -0
  892. package/src/runtime/backend/mesh-dispatch-pump.ts +363 -0
  893. package/src/runtime/backend/mesh-record-dispatcher.ts +65 -0
  894. package/src/runtime/backend/node/index.ts +4 -0
  895. package/src/runtime/backend/node/node-backend-adapter-factory.ts +204 -0
  896. package/src/runtime/backend/node/node-backend-adapter-support.ts +257 -0
  897. package/src/runtime/backend/node/node-dealer-channel-client-transport.ts +133 -0
  898. package/src/runtime/backend/node/node-mesh-backend-adapter.ts +44 -0
  899. package/src/runtime/backend/node/node-monitor-backend-adapter.ts +39 -0
  900. package/src/runtime/backend/node/node-raw-binding-port.contract.ts +21 -0
  901. package/src/runtime/backend/node/node-raw-binding-port.ts +518 -0
  902. package/src/runtime/backend/node/node-raw-mesh-backend.ts +2669 -0
  903. package/src/runtime/backend/node/node-socket-backend-adapter.ts +372 -0
  904. package/src/runtime/backend/node-backend-adapter.ts +19 -0
  905. package/src/runtime/backend/raw-binding-port.ts +69 -0
  906. package/src/runtime/backend/runtime-message.ts +51 -0
  907. package/src/runtime/backend/runtime-values.ts +107 -0
  908. package/src/runtime/channels/channel-autoconnect.ts +46 -0
  909. package/src/runtime/channels/channel-clients.ts +527 -0
  910. package/src/runtime/channels/channel-dispatch-pipeline.ts +408 -0
  911. package/src/runtime/channels/channel-dispatch-services.ts +234 -0
  912. package/src/runtime/channels/channel-dispatchers.ts +790 -0
  913. package/src/runtime/channels/channel-envelope-inspection.ts +125 -0
  914. package/src/runtime/channels/channel-envelope.ts +743 -0
  915. package/src/runtime/channels/channel-framework-packets.ts +8 -0
  916. package/src/runtime/channels/channel-multipart.ts +61 -0
  917. package/src/runtime/channels/channel-outbound-operations.ts +584 -0
  918. package/src/runtime/channels/channel-receive-loops.ts +901 -0
  919. package/src/runtime/channels/channel-receive-task-tracker.ts +39 -0
  920. package/src/runtime/channels/channel-runtime-lifecycle.ts +969 -0
  921. package/src/runtime/channels/channel-runtime-manager.ts +444 -0
  922. package/src/runtime/channels/channel-socket-options.ts +153 -0
  923. package/src/runtime/channels/channel-socket-registry.ts +1837 -0
  924. package/src/runtime/channels/channel-transports.ts +1154 -0
  925. package/src/runtime/channels/client-server-location-runtime.ts +576 -0
  926. package/src/runtime/channels/client-server-service-wire.ts +390 -0
  927. package/src/runtime/channels/dispatch-error-reporter.ts +165 -0
  928. package/src/runtime/channels/fanout-location-runtime.ts +459 -0
  929. package/src/runtime/channels/fanout-service-wire.ts +43 -0
  930. package/src/runtime/channels/handler-filter-scope.ts +29 -0
  931. package/src/runtime/channels/index.ts +45 -0
  932. package/src/runtime/channels/local-spot-route-transport.ts +59 -0
  933. package/src/runtime/channels/route-disconnected-error.ts +6 -0
  934. package/src/runtime/channels/route-member-snapshot.ts +55 -0
  935. package/src/runtime/channels/router-socket-spot-route-transport.ts +77 -0
  936. package/src/runtime/channels/source-spot-router.ts +89 -0
  937. package/src/runtime/channels/spot-direct-envelope.ts +44 -0
  938. package/src/runtime/channels/spot-node-route-transport.ts +92 -0
  939. package/src/runtime/channels/spot-route-bridge-transport.ts +75 -0
  940. package/src/runtime/channels/spot-route-dispatch-strategy.ts +329 -0
  941. package/src/runtime/channels/spot-route-target-resolver.ts +101 -0
  942. package/src/runtime/codecs/index.ts +69 -0
  943. package/src/runtime/configuration/index.ts +1 -0
  944. package/src/runtime/diagnostics/dispatch-error-port.ts +8 -0
  945. package/src/runtime/diagnostics/flow-context.ts +84 -0
  946. package/src/runtime/diagnostics/index.ts +441 -0
  947. package/src/runtime/diagnostics/internal-event-contracts.ts +135 -0
  948. package/src/runtime/diagnostics/message-flow.ts +560 -0
  949. package/src/runtime/diagnostics/runtime-metrics.ts +601 -0
  950. package/src/runtime/diagnostics/runtime-observation-queue.ts +362 -0
  951. package/src/runtime/diagnostics/topology-runtime-projections.ts +298 -0
  952. package/src/runtime/execution/index.ts +466 -0
  953. package/src/runtime/execution/serial-execution-queue.ts +534 -0
  954. package/src/runtime/execution/serial-work-size.ts +31 -0
  955. package/src/runtime/execution/state-lane.ts +116 -0
  956. package/src/runtime/foundation/actor-join-recovery-codec.ts +465 -0
  957. package/src/runtime/foundation/event-loop-resources.ts +162 -0
  958. package/src/runtime/foundation/index.ts +18 -0
  959. package/src/runtime/foundation/message-follow-suppression-registry.ts +130 -0
  960. package/src/runtime/foundation/operation-identity.ts +49 -0
  961. package/src/runtime/foundation/operation-registry.ts +162 -0
  962. package/src/runtime/foundation/raw-service-mesh-runtime.ts +1771 -0
  963. package/src/runtime/foundation/route-mesh-connection-policy.ts +28 -0
  964. package/src/runtime/foundation/runtime-state-projections.ts +68 -0
  965. package/src/runtime/foundation/service-authority-payload-codec.ts +566 -0
  966. package/src/runtime/foundation/service-discovery-registry.ts +263 -0
  967. package/src/runtime/foundation/service-instance-activation-recovery-codec.ts +329 -0
  968. package/src/runtime/foundation/service-liveness-registry.ts +144 -0
  969. package/src/runtime/foundation/service-mailbox.ts +369 -0
  970. package/src/runtime/foundation/service-maintenance-runtime.ts +242 -0
  971. package/src/runtime/foundation/service-metadata-codec.ts +75 -0
  972. package/src/runtime/foundation/service-relocation-aggregate-committer.ts +218 -0
  973. package/src/runtime/foundation/service-relocation-coordinator.ts +37 -0
  974. package/src/runtime/foundation/service-relocation-object-owner.ts +428 -0
  975. package/src/runtime/foundation/service-relocation-runtime.ts +1407 -0
  976. package/src/runtime/foundation/service-runtime-contracts.ts +423 -0
  977. package/src/runtime/foundation/service-session-binding-ingress-port.ts +45 -0
  978. package/src/runtime/foundation/service-stateful-registry.ts +664 -0
  979. package/src/runtime/foundation/service-stateful-runtime.ts +5753 -0
  980. package/src/runtime/foundation/service-stateful-wire-codec.ts +3008 -0
  981. package/src/runtime/foundation/service-topology-registry.ts +599 -0
  982. package/src/runtime/foundation/service-weighted-selection.ts +166 -0
  983. package/src/runtime/foundation/service-wire-binary-primitives.ts +80 -0
  984. package/src/runtime/foundation/service-wire-codec.ts +91 -0
  985. package/src/runtime/foundation/service-wire-constants.generated.ts +131 -0
  986. package/src/runtime/foundation/service-wire-m6a-codec.ts +647 -0
  987. package/src/runtime/framework-errors-internal.ts +338 -0
  988. package/src/runtime/handlers/handler-instance-scope.ts +372 -0
  989. package/src/runtime/handlers/index.ts +93 -0
  990. package/src/runtime/host/actor-packet-relay.ts +1070 -0
  991. package/src/runtime/host/actor-placement-coordinator.ts +573 -0
  992. package/src/runtime/host/actor-runtime-options-factory.ts +282 -0
  993. package/src/runtime/host/actor-transfer-authority-runtime.ts +225 -0
  994. package/src/runtime/host/actor-transfer-runtime.ts +1958 -0
  995. package/src/runtime/host/application-job-queue.ts +518 -0
  996. package/src/runtime/host/bound-session-relay.ts +94 -0
  997. package/src/runtime/host/bounded-replay-map.ts +42 -0
  998. package/src/runtime/host/channel-runtime-options-factory.ts +104 -0
  999. package/src/runtime/host/entry-actor-runtime.ts +115 -0
  1000. package/src/runtime/host/host-capacity-status.ts +103 -0
  1001. package/src/runtime/host/index.ts +3492 -0
  1002. package/src/runtime/host/instance-activation-authority.ts +658 -0
  1003. package/src/runtime/host/location-runtime-owner.ts +313 -0
  1004. package/src/runtime/host/mesh-router-resolver.ts +114 -0
  1005. package/src/runtime/host/relocation-direct-transfer.ts +273 -0
  1006. package/src/runtime/host/relocation-integrity-fault-gate.ts +8 -0
  1007. package/src/runtime/host/relocation-state-adapter.ts +24 -0
  1008. package/src/runtime/host/remote-actor-join-receiver.ts +264 -0
  1009. package/src/runtime/host/remote-actor-packet-target-store.ts +244 -0
  1010. package/src/runtime/host/remote-bound-session-relay.ts +900 -0
  1011. package/src/runtime/host/route-mesh-runtime-options.ts +46 -0
  1012. package/src/runtime/host/route-mesh-runtime.ts +891 -0
  1013. package/src/runtime/host/runtime-shutdown.ts +101 -0
  1014. package/src/runtime/host/service-relocation-control.ts +28 -0
  1015. package/src/runtime/host/service-relocation-host-runtime.ts +5817 -0
  1016. package/src/runtime/host/spot-address-transport.ts +997 -0
  1017. package/src/runtime/host/spot-node-runtime-options-factory.ts +82 -0
  1018. package/src/runtime/host/spot-runtime-options-factory.ts +286 -0
  1019. package/src/runtime/host/stateful-authority-route-runtime.ts +662 -0
  1020. package/src/runtime/host/user-spot-creation-coordinator.ts +1176 -0
  1021. package/src/runtime/locations/actor-location-claims.ts +426 -0
  1022. package/src/runtime/locations/actor-session-route-claims.ts +64 -0
  1023. package/src/runtime/locations/aggregate-inventory-store.ts +581 -0
  1024. package/src/runtime/locations/authority-key-codec.ts +80 -0
  1025. package/src/runtime/locations/auto-connect-loop.ts +131 -0
  1026. package/src/runtime/locations/auto-connect-planner.ts +178 -0
  1027. package/src/runtime/locations/auto-connect-reconciler.ts +425 -0
  1028. package/src/runtime/locations/auto-connect-types.ts +62 -0
  1029. package/src/runtime/locations/auto-connect.ts +4 -0
  1030. package/src/runtime/locations/canonical-codec.ts +54 -0
  1031. package/src/runtime/locations/domain-store-contract.ts +149 -0
  1032. package/src/runtime/locations/in-memory-authority-store.ts +1172 -0
  1033. package/src/runtime/locations/in-memory-location-store.ts +1467 -0
  1034. package/src/runtime/locations/in-memory-provider-location-store.ts +213 -0
  1035. package/src/runtime/locations/index.ts +11 -0
  1036. package/src/runtime/locations/internal-location-contracts.ts +22 -0
  1037. package/src/runtime/locations/internal-store-contracts.ts +90 -0
  1038. package/src/runtime/locations/key-codec.ts +61 -0
  1039. package/src/runtime/locations/lease-tracker.ts +221 -0
  1040. package/src/runtime/locations/lifecycle-runtime.ts +44 -0
  1041. package/src/runtime/locations/lifecycle.ts +272 -0
  1042. package/src/runtime/locations/location-store-repository.ts +4211 -0
  1043. package/src/runtime/locations/relocation-blob.ts +36 -0
  1044. package/src/runtime/locations/resolvers.ts +1054 -0
  1045. package/src/runtime/locations/runtime.ts +1126 -0
  1046. package/src/runtime/locations/spot-location-claims.ts +435 -0
  1047. package/src/runtime/messaging/creation-payload-codec.ts +59 -0
  1048. package/src/runtime/messaging/framework-json-v1.ts +307 -0
  1049. package/src/runtime/messaging/index.ts +1 -0
  1050. package/src/runtime/messaging/packet-name.ts +94 -0
  1051. package/src/runtime/messaging/payload-codec.ts +418 -0
  1052. package/src/runtime/messaging/submission-result.ts +61 -0
  1053. package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +189 -0
  1054. package/src/runtime/routing-id.ts +125 -0
  1055. package/src/runtime/spots/formal-remote-actor-admission-registry.ts +418 -0
  1056. package/src/runtime/spots/formal-remote-actor-transfer-registry.ts +147 -0
  1057. package/src/runtime/spots/index.ts +3303 -0
  1058. package/src/runtime/spots/spot-activation-registry.ts +335 -0
  1059. package/src/runtime/spots/spot-activation-state.ts +414 -0
  1060. package/src/runtime/spots/spot-activation.ts +1027 -0
  1061. package/src/runtime/spots/spot-actor-admission-coordinator.ts +354 -0
  1062. package/src/runtime/spots/spot-actor-join-dispatch.ts +303 -0
  1063. package/src/runtime/spots/spot-actor-lifecycle-drain.ts +79 -0
  1064. package/src/runtime/spots/spot-actor-membership.ts +266 -0
  1065. package/src/runtime/spots/spot-actor-packet-dispatch.ts +593 -0
  1066. package/src/runtime/spots/spot-actor-packet-drain.ts +328 -0
  1067. package/src/runtime/spots/spot-actor-packet-relay-dispatch.ts +162 -0
  1068. package/src/runtime/spots/spot-closing.ts +34 -0
  1069. package/src/runtime/spots/spot-context.ts +259 -0
  1070. package/src/runtime/spots/spot-entry-activation.ts +551 -0
  1071. package/src/runtime/spots/spot-handle.ts +101 -0
  1072. package/src/runtime/spots/spot-handler-registry.ts +273 -0
  1073. package/src/runtime/spots/spot-lifecycle-metrics.ts +15 -0
  1074. package/src/runtime/spots/spot-location-claim.ts +86 -0
  1075. package/src/runtime/spots/spot-manager-internal-contracts.ts +11 -0
  1076. package/src/runtime/spots/spot-manager-public.ts +361 -0
  1077. package/src/runtime/spots/spot-native-actor-join-admission.ts +151 -0
  1078. package/src/runtime/spots/spot-native-flags.ts +4 -0
  1079. package/src/runtime/spots/spot-node-autoconnect.ts +325 -0
  1080. package/src/runtime/spots/spot-node-runtime-manager.ts +1573 -0
  1081. package/src/runtime/spots/spot-outbound.ts +761 -0
  1082. package/src/runtime/spots/spot-provider.ts +36 -0
  1083. package/src/runtime/spots/spot-publisher-transport.ts +69 -0
  1084. package/src/runtime/spots/spot-remote-codec.ts +308 -0
  1085. package/src/runtime/spots/spot-remote-route-codec.ts +284 -0
  1086. package/src/runtime/spots/spot-route-packet-dispatch.ts +359 -0
  1087. package/src/runtime/spots/spot-route-replies.ts +126 -0
  1088. package/src/runtime/spots/spot-route-reply-wire.ts +15 -0
  1089. package/src/runtime/spots/spot-routed-actor-admission.ts +351 -0
  1090. package/src/runtime/spots/spot-routed-bound-session-dispatch.ts +132 -0
  1091. package/src/runtime/spots/spot-routed-frame-dispatch.ts +250 -0
  1092. package/src/runtime/spots/spot-routed-spot-packet-dispatch.ts +254 -0
  1093. package/src/runtime/spots/spot-routing-internal.ts +33 -0
  1094. package/src/runtime/spots/spot-runtime-ports.ts +196 -0
  1095. package/src/runtime/spots/spot-serial-executor.ts +170 -0
  1096. package/src/runtime/spots/spot-serial-turn-executor.ts +319 -0
  1097. package/src/runtime/spots/spot-subscription-dispatch.ts +252 -0
  1098. package/src/runtime/spots/spot-timer.ts +609 -0
  1099. package/src/runtime/streams/actor-session-binding-registry.ts +1691 -0
  1100. package/src/runtime/streams/actor-session-binding-runtime-owner.ts +78 -0
  1101. package/src/runtime/streams/actor-session-lifecycle-coordinator.ts +20 -0
  1102. package/src/runtime/streams/bound-actor-relay-sender.ts +275 -0
  1103. package/src/runtime/streams/bound-session-response-target.ts +91 -0
  1104. package/src/runtime/streams/bound-session-service.ts +500 -0
  1105. package/src/runtime/streams/index.ts +706 -0
  1106. package/src/runtime/streams/managed-stream.ts +509 -0
  1107. package/src/runtime/streams/native-fallback-bound-session.ts +321 -0
  1108. package/src/runtime/streams/protocol.ts +291 -0
  1109. package/src/runtime/streams/session-actor-coordinator.ts +605 -0
  1110. package/src/runtime/streams/session-calls.ts +221 -0
  1111. package/src/runtime/streams/session-context.ts +609 -0
  1112. package/src/runtime/streams/session-local-actors.ts +30 -0
  1113. package/src/runtime/streams/session-provider.ts +50 -0
  1114. package/src/runtime/streams/session-requests.ts +109 -0
  1115. package/src/runtime/streams/session-serial-executor.ts +97 -0
  1116. package/src/runtime/streams/stream-binding-runtime-ports.ts +106 -0
  1117. package/src/runtime/streams/stream-frame-factory.ts +255 -0
  1118. package/src/runtime/streams/stream-message-utils.ts +89 -0
  1119. package/src/runtime/streams/stream-session-runtime.ts +1420 -0
  1120. package/src/runtime/workers/index.ts +580 -0
  1121. package/tsconfig.json +17 -0
@@ -0,0 +1,2090 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultZLinkSpotManager = exports.ZLinkPublicSpotManager = exports.ZLinkSpotNodeRuntimeManager = exports.createFrameworkEntrySpotId = exports.ZLinkEntrySpotActivation = exports.ZLinkRuntimeSpotPublisherTransport = exports.DefaultZLinkSpotHandlerRegistry = exports.DefaultZLinkSpotOutbound = exports.ZLinkSpotTimerRegistry = exports.ZLinkManagedTimer = exports.ZLinkSpotSerialExecutor = exports.ZLinkSpotSerialTurnExecutor = exports.ZLinkSpotActorAdmissionCoordinator = exports.ZLinkSpotRoutedBoundSessionDispatch = exports.sendToSpotHandle = exports.requestToSpotHandle = exports.resolveSpotHandle = exports.createSpotHandle = void 0;
4
+ var spot_handle_1 = require("./spot-handle");
5
+ Object.defineProperty(exports, "createSpotHandle", { enumerable: true, get: function () { return spot_handle_1.createSpotHandle; } });
6
+ Object.defineProperty(exports, "resolveSpotHandle", { enumerable: true, get: function () { return spot_handle_1.resolveSpotHandle; } });
7
+ var spot_outbound_1 = require("./spot-outbound");
8
+ Object.defineProperty(exports, "requestToSpotHandle", { enumerable: true, get: function () { return spot_outbound_1.requestToSpotHandle; } });
9
+ Object.defineProperty(exports, "sendToSpotHandle", { enumerable: true, get: function () { return spot_outbound_1.sendToSpotHandle; } });
10
+ var spot_routed_bound_session_dispatch_1 = require("./spot-routed-bound-session-dispatch");
11
+ Object.defineProperty(exports, "ZLinkSpotRoutedBoundSessionDispatch", { enumerable: true, get: function () { return spot_routed_bound_session_dispatch_1.ZLinkSpotRoutedBoundSessionDispatch; } });
12
+ var spot_actor_admission_coordinator_1 = require("./spot-actor-admission-coordinator");
13
+ Object.defineProperty(exports, "ZLinkSpotActorAdmissionCoordinator", { enumerable: true, get: function () { return spot_actor_admission_coordinator_1.ZLinkSpotActorAdmissionCoordinator; } });
14
+ const abort_1 = require("../abort");
15
+ const contracts_1 = require("../../contracts");
16
+ const ZLinkDispatchOptions_1 = require("../../contracts/Dispatch/ZLinkDispatchOptions");
17
+ const diagnostics_1 = require("../diagnostics");
18
+ const runtime_message_1 = require("../backend/runtime-message");
19
+ const runtime_values_1 = require("../backend/runtime-values");
20
+ const service_runtime_contracts_1 = require("../foundation/service-runtime-contracts");
21
+ const serial_work_size_1 = require("../execution/serial-work-size");
22
+ const configuration_1 = require("../configuration");
23
+ const framework_errors_internal_1 = require("../framework-errors-internal");
24
+ const workers_1 = require("../workers");
25
+ const payload_codec_1 = require("../messaging/payload-codec");
26
+ const channel_envelope_1 = require("../channels/channel-envelope");
27
+ const protocol_1 = require("../streams/protocol");
28
+ const actor_remote_wire_1 = require("../actors/actor-remote-wire");
29
+ const actor_handoff_1 = require("../actors/actor-handoff");
30
+ const spot_remote_codec_1 = require("./spot-remote-codec");
31
+ const routing_id_1 = require("../routing-id");
32
+ const service_wire_constants_generated_1 = require("../foundation/service-wire-constants.generated");
33
+ var spot_serial_turn_executor_1 = require("./spot-serial-turn-executor");
34
+ Object.defineProperty(exports, "ZLinkSpotSerialTurnExecutor", { enumerable: true, get: function () { return spot_serial_turn_executor_1.ZLinkSpotSerialTurnExecutor; } });
35
+ var spot_serial_executor_1 = require("./spot-serial-executor");
36
+ Object.defineProperty(exports, "ZLinkSpotSerialExecutor", { enumerable: true, get: function () { return spot_serial_executor_1.ZLinkSpotSerialExecutor; } });
37
+ var spot_timer_1 = require("./spot-timer");
38
+ Object.defineProperty(exports, "ZLinkManagedTimer", { enumerable: true, get: function () { return spot_timer_1.ZLinkManagedTimer; } });
39
+ Object.defineProperty(exports, "ZLinkSpotTimerRegistry", { enumerable: true, get: function () { return spot_timer_1.ZLinkSpotTimerRegistry; } });
40
+ var spot_outbound_2 = require("./spot-outbound");
41
+ Object.defineProperty(exports, "DefaultZLinkSpotOutbound", { enumerable: true, get: function () { return spot_outbound_2.DefaultZLinkSpotOutbound; } });
42
+ var spot_handler_registry_1 = require("./spot-handler-registry");
43
+ Object.defineProperty(exports, "DefaultZLinkSpotHandlerRegistry", { enumerable: true, get: function () { return spot_handler_registry_1.DefaultZLinkSpotHandlerRegistry; } });
44
+ var spot_publisher_transport_1 = require("./spot-publisher-transport");
45
+ Object.defineProperty(exports, "ZLinkRuntimeSpotPublisherTransport", { enumerable: true, get: function () { return spot_publisher_transport_1.ZLinkRuntimeSpotPublisherTransport; } });
46
+ const spot_activation_registry_1 = require("./spot-activation-registry");
47
+ const spot_activation_state_1 = require("./spot-activation-state");
48
+ const spot_activation_1 = require("./spot-activation");
49
+ const spot_actor_membership_1 = require("./spot-actor-membership");
50
+ const formal_remote_actor_transfer_registry_1 = require("./formal-remote-actor-transfer-registry");
51
+ const formal_remote_actor_admission_registry_1 = require("./formal-remote-actor-admission-registry");
52
+ const spot_location_claim_1 = require("./spot-location-claim");
53
+ const spot_routed_spot_packet_dispatch_1 = require("./spot-routed-spot-packet-dispatch");
54
+ var spot_entry_activation_1 = require("./spot-entry-activation");
55
+ Object.defineProperty(exports, "ZLinkEntrySpotActivation", { enumerable: true, get: function () { return spot_entry_activation_1.ZLinkEntrySpotActivation; } });
56
+ var spot_node_runtime_manager_1 = require("./spot-node-runtime-manager");
57
+ Object.defineProperty(exports, "createFrameworkEntrySpotId", { enumerable: true, get: function () { return spot_node_runtime_manager_1.createFrameworkEntrySpotId; } });
58
+ Object.defineProperty(exports, "ZLinkSpotNodeRuntimeManager", { enumerable: true, get: function () { return spot_node_runtime_manager_1.ZLinkSpotNodeRuntimeManager; } });
59
+ var spot_manager_public_1 = require("./spot-manager-public");
60
+ Object.defineProperty(exports, "ZLinkPublicSpotManager", { enumerable: true, get: function () { return spot_manager_public_1.ZLinkPublicSpotManager; } });
61
+ class DefaultZLinkSpotManager {
62
+ options;
63
+ factories;
64
+ activations;
65
+ workerRuntime;
66
+ locationClaim;
67
+ routedSpotPackets;
68
+ actorMembership;
69
+ activationLifecycle;
70
+ formalRemoteTransfers = new formal_remote_actor_transfer_registry_1.ZLinkFormalRemoteActorTransferRegistry();
71
+ formalRemoteActorAdmissions = new formal_remote_actor_admission_registry_1.ZLinkFormalRemoteActorAdmissionRegistry();
72
+ pendingInstanceMaterializations = new Map();
73
+ // Parallel index keyed by `${meshName}\0${spotId}` so per-activation
74
+ // callbacks (isInstanceMaterializing, sibling-generation lookups) resolve
75
+ // in O(1) instead of scanning every pending key.
76
+ pendingInstanceMaterializationsByPrefix = new Map();
77
+ instanceActivationGates = new Map();
78
+ pendingInstanceCloses = new Map();
79
+ pendingInstanceTerminals = new Map();
80
+ pendingInstanceTerminalGenerations = new Map();
81
+ deferredInstanceAuthorityReleases = new Map();
82
+ idleSweepTimer;
83
+ idleSweepRunning = false;
84
+ constructor(options, timerClock) {
85
+ this.options = options;
86
+ this.activations = new spot_activation_registry_1.ZLinkSpotActivationRegistry(options.metrics);
87
+ this.factories = new Set(options.spotFactories);
88
+ this.workerRuntime = options.workerRuntime ?? new workers_1.ZLinkWorkerRuntime();
89
+ this.locationClaim = new spot_location_claim_1.ZLinkSpotLocationClaim({
90
+ lifecycle: options.locationLifecycle,
91
+ nodeRid: options.nodeRid,
92
+ nodeRidProvider: options.nodeRidProvider,
93
+ nodeGenerationProvider: options.nodeGenerationProvider
94
+ });
95
+ this.routedSpotPackets = new spot_routed_spot_packet_dispatch_1.ZLinkRoutedSpotPacketDispatch({
96
+ resolveActivation: (spotId) => this.activations.resolveUnique(spotId),
97
+ claimApplicationWork: options.admission === undefined
98
+ ? undefined
99
+ : (meshName) => options.admission.claim(meshName, 'Spot route dispatch'),
100
+ providerResolver: options.providerResolver,
101
+ dispatchErrors: options.dispatchErrors
102
+ });
103
+ this.actorMembership = new spot_actor_membership_1.ZLinkSpotActorMembership({
104
+ resolveActivation: (spotId, meshName) => meshName === undefined
105
+ ? this.activations.resolveUnique(spotId)
106
+ : this.activations.resolve(meshName, spotId),
107
+ providerResolver: options.providerResolver,
108
+ messageSerializers: options.messageSerializers,
109
+ dispatchErrors: options.dispatchErrors,
110
+ entrySpotCallbacks: options.entrySpotCallbacks,
111
+ nodeRid: options.nodeRid,
112
+ nodeRidProvider: options.nodeRidProvider,
113
+ entryNodeRid: options.entryNodeRid,
114
+ entryNodeRidProvider: options.entryNodeRidProvider,
115
+ entrySpotIdProvider: options.entrySpotIdProvider,
116
+ spotRouteResolver: options.spotRouteResolver,
117
+ actorTransferRuntime: options.actorTransferRuntime
118
+ });
119
+ this.activationLifecycle = new spot_activation_1.ZLinkSpotActivationLifecycle({
120
+ timerClock,
121
+ spotTimerHandlers: options.spotTimerHandlers,
122
+ spotPacketHandlers: options.spotPacketHandlers,
123
+ spotSubscriptionHandlers: options.spotSubscriptionHandlers,
124
+ spotActorSendHandlers: options.spotActorSendHandlers,
125
+ spotActorRequestHandlers: options.spotActorRequestHandlers,
126
+ nodeRid: options.nodeRid,
127
+ nodeRidProvider: options.nodeRidProvider,
128
+ actorCountProvider: options.actorCountProvider,
129
+ userSpotExecutionMode: options.userSpotExecutionMode,
130
+ userSpotRelocationCoordinationMode: options.userSpotRelocationCoordinationMode,
131
+ channelClient: options.channelClient,
132
+ fanoutClient: options.fanoutClient,
133
+ spotPublisherClient: options.spotPublisherClient,
134
+ routedTransport: options.routedTransport,
135
+ addressTransport: options.addressTransport,
136
+ spotRouterChannelIdForMesh: options.spotRouterChannelIdForMesh,
137
+ providerResolver: options.providerResolver,
138
+ dispatchErrors: options.dispatchErrors,
139
+ runtimeEventPublisher: options.runtimeEventPublisher,
140
+ workerRuntime: this.workerRuntime,
141
+ messageSerializers: options.messageSerializers,
142
+ locationClaim: this.locationClaim,
143
+ createNativeSpot: options.createNativeSpot,
144
+ createReceived: options.createReceived,
145
+ createTopicMessage: options.createTopicMessage,
146
+ nativeSpotNodeProvider: options.nativeSpotNodeProvider,
147
+ actorResolver: options.actorResolver,
148
+ detachedTaskRunner: options.detachedTaskRunner,
149
+ actorTransferRuntime: options.actorTransferRuntime,
150
+ boundSessionRuntime: options.boundSessionRuntime,
151
+ actorHandoffRuntime: options.actorHandoffRuntime,
152
+ admission: options.admission,
153
+ statefulExecutionAllowed: options.statefulExecutionAllowed,
154
+ leaveActor: (spotId, actor, signal, meshName) => this.actorMembership.leaveActor(spotId, actor, signal, meshName),
155
+ closeSpot: (meshName, spotId, signal, reason) => this.closeWithReason(meshName, spotId, signal, reason),
156
+ registerActivation: (activation) => {
157
+ this.activations.register(activation);
158
+ this.scheduleIdleSweep();
159
+ },
160
+ // Spec 15 §4.2 relocation temporary queue: production ingress
161
+ // consults the same admission attempts registered on Accepted
162
+ // (`formalRemoteActorAdmissions.begin`, in dispatchMeshActorJoin)
163
+ // instead of dropping an arrival for an Actor that has not yet
164
+ // cut over locally.
165
+ routeToActorJoinPrewarm: (actorId, objectGeneration, arrival) => this.formalRemoteActorAdmissions.routeIngress(actorId, objectGeneration, arrival),
166
+ releaseLocation: (activation, meshName, spotId) => {
167
+ if (activation.domain.kind === 'user') {
168
+ return this.locationClaim.release(meshName, spotId);
169
+ }
170
+ const currentApplication = this.options.instanceSpotApplicationTargetProvider?.(meshName, spotId);
171
+ if (currentApplication !== undefined
172
+ && currentApplication.objectGeneration !== activation.domain.objectGeneration) {
173
+ // A superseded local application must not release the authority row
174
+ // that now belongs to the newer object generation.
175
+ return Promise.resolve();
176
+ }
177
+ const key = `${meshName}\0${String(spotId)}`;
178
+ const objectGeneration = activation.domain.objectGeneration;
179
+ if (this.pendingInstanceTerminals.has(key)) {
180
+ this.deferInstanceAuthorityRelease(key, objectGeneration);
181
+ return Promise.resolve();
182
+ }
183
+ this.removeDeferredInstanceAuthorityRelease(key, objectGeneration);
184
+ return this.releaseInstanceAuthority(meshName, spotId, objectGeneration);
185
+ },
186
+ metrics: options.metrics
187
+ });
188
+ this.scheduleIdleSweep();
189
+ }
190
+ entrySpotIdForMesh(meshName) {
191
+ return this.options.entrySpotIdProvider?.(meshName);
192
+ }
193
+ relocationActivations(meshName) {
194
+ return this.activations.activeActivations().filter(activation => activation.meshName === meshName
195
+ && this.activations.resolve(meshName, activation.spotId) === activation);
196
+ }
197
+ activeSpotCount(meshName) {
198
+ return this.activations.list(meshName).length;
199
+ }
200
+ instanceActivationConcurrency(meshName) {
201
+ const limit = this.options.activationConcurrencyLimitProvider?.(meshName) ?? 128;
202
+ return { active: this.instanceActivationGates.get(meshName)?.active ?? 0, limit };
203
+ }
204
+ resolveRelocationActivation(meshName, spotId) {
205
+ return this.activations.resolve(meshName, spotId);
206
+ }
207
+ async prepareRelocationSpot(meshName, objectKind, stableType, implementation, spotId, objectGeneration, authorityOwnerGeneration, signal) {
208
+ this.activations.stage(meshName, spotId);
209
+ try {
210
+ return await this.activationLifecycle.materializeRelocation(meshName, objectKind, stableType, implementation, spotId, objectGeneration, authorityOwnerGeneration, signal);
211
+ }
212
+ catch (error) {
213
+ this.activations.abandonStage(meshName, spotId);
214
+ throw error;
215
+ }
216
+ }
217
+ async publishRelocationSpot(activation, beforeAdmission) {
218
+ await activation.serial.execute(() => activation.spot.onInitialize?.());
219
+ await beforeAdmission?.();
220
+ this.activations.publish(activation.meshName, activation.spotId);
221
+ }
222
+ async abortRelocationSpot(activation) {
223
+ this.activations.detachRelocated(activation.meshName, activation.spotId);
224
+ await activation.timers.dispose();
225
+ await activation.nativeSpot?.dispose();
226
+ }
227
+ async completeRelocationSource(activation) {
228
+ this.activations.detachRelocated(activation.meshName, activation.spotId);
229
+ await activation.nativeSpot?.dispose();
230
+ }
231
+ async materializeInstance(meshName, instanceType, spotId, objectGeneration, signal) {
232
+ const existing = this.pendingInstanceMaterializations.get(instanceMaterializationKey(meshName, spotId, objectGeneration));
233
+ if (existing !== undefined) {
234
+ await (0, abort_1.awaitWithAbort)(existing, signal);
235
+ return;
236
+ }
237
+ const release = await this.acquireInstanceActivation(meshName, signal);
238
+ try {
239
+ await this.materializeInstanceCore(meshName, instanceType, spotId, objectGeneration, signal);
240
+ }
241
+ finally {
242
+ release();
243
+ }
244
+ }
245
+ async materializeInstanceCore(meshName, instanceType, spotId, objectGeneration, signal) {
246
+ const factory = this.requireInstanceFactory(meshName, instanceType);
247
+ const key = `${meshName}\0${String(spotId)}`;
248
+ const materializationKey = instanceMaterializationKey(meshName, spotId, objectGeneration);
249
+ const materializationPrefix = instanceMaterializationPrefix(meshName, spotId);
250
+ for (;;) {
251
+ // A close seals admission before cleanup removes the activation. An
252
+ // explicit Instance intent arriving at that boundary must wait for the
253
+ // old resources to be released before materializing the replacement.
254
+ // This is lifecycle convergence; it does not resubmit application work.
255
+ const pendingClose = this.pendingInstanceCloses.get(key);
256
+ if (pendingClose !== undefined) {
257
+ await (0, abort_1.awaitWithAbort)(pendingClose, signal);
258
+ continue;
259
+ }
260
+ const closing = this.activations.closingOperation(meshName, spotId);
261
+ if (closing !== undefined) {
262
+ await (0, abort_1.awaitWithAbort)(closing.ready, signal);
263
+ continue;
264
+ }
265
+ const current = this.activations.resolve(meshName, spotId);
266
+ if (current !== undefined) {
267
+ if (current.spotType !== factory) {
268
+ throw new configuration_1.ZLinkConfigurationException(`Instance Spot '${String(spotId)}' is assigned to another type.`);
269
+ }
270
+ if (current.objectGeneration === objectGeneration)
271
+ return;
272
+ if (current.objectGeneration === undefined
273
+ || current.objectGeneration > objectGeneration) {
274
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotGenerationStale, `Instance Spot '${String(spotId)}' has a newer application generation.`);
275
+ }
276
+ // A newer authority route may become visible while the previous
277
+ // application factory is still completing. Dispose that older
278
+ // activation before publishing the requested generation. The
279
+ // generation-aware release callback prevents this cleanup from
280
+ // releasing the newer authority row.
281
+ await this.discardInstance(meshName, spotId);
282
+ continue;
283
+ }
284
+ const lifecycleActivation = this.activations.activeActivations().find((activation) => activation.meshName === meshName && String(activation.spotId) === String(spotId));
285
+ if (lifecycleActivation?.isIdleEvicting === true) {
286
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotGenerationStale, `Instance Spot '${String(spotId)}' is entering idle eviction.`);
287
+ }
288
+ let pending = this.pendingInstanceMaterializations.get(materializationKey);
289
+ if (pending === undefined) {
290
+ const siblings = this.pendingInstanceMaterializationsByPrefix.get(materializationPrefix);
291
+ const otherPending = siblings === undefined
292
+ ? undefined
293
+ : siblings.values().next().value;
294
+ if (otherPending !== undefined) {
295
+ await (0, abort_1.awaitWithAbort)(otherPending, signal);
296
+ continue;
297
+ }
298
+ }
299
+ if (pending === undefined) {
300
+ const metric = this.options.metrics?.startInstanceSpotActivation(meshName, instanceType);
301
+ pending = this.activationLifecycle.materializeInstance(meshName, instanceType, factory, spotId, objectGeneration, signal).then(activation => {
302
+ metric?.complete('ready');
303
+ return activation;
304
+ }, error => {
305
+ metric?.complete(instanceActivationOutcome(error));
306
+ throw error;
307
+ });
308
+ this.pendingInstanceMaterializations.set(materializationKey, pending);
309
+ let siblings = this.pendingInstanceMaterializationsByPrefix.get(materializationPrefix);
310
+ if (siblings === undefined) {
311
+ siblings = new Map();
312
+ this.pendingInstanceMaterializationsByPrefix.set(materializationPrefix, siblings);
313
+ }
314
+ siblings.set(materializationKey, pending);
315
+ void pending.finally(() => {
316
+ if (this.pendingInstanceMaterializations.get(materializationKey) === pending) {
317
+ this.pendingInstanceMaterializations.delete(materializationKey);
318
+ }
319
+ const bucket = this.pendingInstanceMaterializationsByPrefix.get(materializationPrefix);
320
+ if (bucket !== undefined && bucket.get(materializationKey) === pending) {
321
+ bucket.delete(materializationKey);
322
+ if (bucket.size === 0) {
323
+ this.pendingInstanceMaterializationsByPrefix.delete(materializationPrefix);
324
+ }
325
+ }
326
+ }).catch(() => undefined);
327
+ }
328
+ await pending;
329
+ return;
330
+ }
331
+ }
332
+ async acquireInstanceActivation(meshName, signal) {
333
+ let gate = this.instanceActivationGates.get(meshName);
334
+ if (gate === undefined) {
335
+ gate = {
336
+ meshName,
337
+ limit: this.options.activationConcurrencyLimitProvider?.(meshName) ?? 128,
338
+ active: 0,
339
+ waiters: [],
340
+ waiterHead: 0
341
+ };
342
+ this.instanceActivationGates.set(meshName, gate);
343
+ }
344
+ if (signal?.aborted === true)
345
+ throw signal.reason;
346
+ if (gate.active < gate.limit) {
347
+ gate.active += 1;
348
+ this.options.onInstanceActivationConcurrencyChanged?.(meshName);
349
+ return () => this.releaseInstanceActivation(gate);
350
+ }
351
+ return new Promise((resolve, reject) => {
352
+ const waiter = { resolve, reject, signal, abort: undefined };
353
+ const slot = gate.waiters.length;
354
+ waiter.abort = () => {
355
+ if (gate.waiters[slot] === waiter)
356
+ gate.waiters[slot] = undefined;
357
+ reject(signal?.reason);
358
+ };
359
+ signal?.addEventListener('abort', waiter.abort, { once: true });
360
+ gate.waiters.push(waiter);
361
+ });
362
+ }
363
+ releaseInstanceActivation(gate) {
364
+ while (gate.waiterHead < gate.waiters.length) {
365
+ const waiter = gate.waiters[gate.waiterHead];
366
+ gate.waiters[gate.waiterHead] = undefined;
367
+ gate.waiterHead += 1;
368
+ if (gate.waiterHead >= gate.waiters.length) {
369
+ gate.waiters.length = 0;
370
+ gate.waiterHead = 0;
371
+ }
372
+ if (waiter === undefined)
373
+ continue;
374
+ if (waiter.abort !== undefined)
375
+ waiter.signal?.removeEventListener('abort', waiter.abort);
376
+ waiter.resolve(() => this.releaseInstanceActivation(gate));
377
+ return;
378
+ }
379
+ gate.waiters.length = 0;
380
+ gate.waiterHead = 0;
381
+ gate.active -= 1;
382
+ this.options.onInstanceActivationConcurrencyChanged?.(gate.meshName);
383
+ }
384
+ isInstanceMaterialized(meshName, instanceType, spotId) {
385
+ const activation = this.activations.resolve(meshName, spotId);
386
+ return activation !== undefined
387
+ && activation.spotType === this.requireInstanceFactory(meshName, instanceType);
388
+ }
389
+ isInstanceMaterializing(meshName, spotId) {
390
+ const prefix = instanceMaterializationPrefix(meshName, spotId);
391
+ return (this.pendingInstanceMaterializationsByPrefix.get(prefix)?.size ?? 0) > 0;
392
+ }
393
+ isInstanceClosing(meshName, spotId) {
394
+ const key = `${meshName}\0${String(spotId)}`;
395
+ return this.pendingInstanceCloses.has(key)
396
+ || this.activations.closingOperation(meshName, spotId) !== undefined;
397
+ }
398
+ async discardInstance(meshName, spotId) {
399
+ const activation = this.activations.resolve(meshName, spotId);
400
+ if (activation === undefined)
401
+ return;
402
+ activation.requestClose();
403
+ const operation = this.activations.startClose(meshName, spotId, (current) => this.activationLifecycle.discardInstance(current), () => true);
404
+ await operation?.ready;
405
+ }
406
+ isInstanceSpotIdleEvicting(meshName, spotId) {
407
+ const activation = this.activations.activeActivations().find((candidate) => candidate.meshName === meshName && String(candidate.spotId) === String(spotId));
408
+ return activation !== undefined
409
+ && activation.domain.kind === 'instance'
410
+ && activation.isIdleEvicting;
411
+ }
412
+ beginInstanceSpotIdleEviction(meshName, spotId) {
413
+ const activation = this.activations.activeActivations().find((candidate) => candidate.meshName === meshName && String(candidate.spotId) === String(spotId));
414
+ if (activation === undefined
415
+ || activation.domain.kind !== 'instance'
416
+ || !activation.isIdleFor(performance.now(), this.options.instanceSpotIdleTimeoutMs?.get(meshName) ?? 0)) {
417
+ return false;
418
+ }
419
+ return activation.beginIdleEviction();
420
+ }
421
+ async completeInstanceTerminal(meshName, spotId, objectGeneration) {
422
+ const key = `${meshName}\0${String(spotId)}`;
423
+ const pending = this.pendingInstanceTerminals.get(key);
424
+ if (pending === undefined)
425
+ return false;
426
+ this.removePendingInstanceTerminalGeneration(key, objectGeneration);
427
+ if (pending > 1) {
428
+ this.pendingInstanceTerminals.set(key, pending - 1);
429
+ return false;
430
+ }
431
+ this.pendingInstanceTerminals.delete(key);
432
+ this.pendingInstanceTerminalGenerations.delete(key);
433
+ const pendingClose = this.pendingInstanceCloses.get(key);
434
+ if (pendingClose !== undefined) {
435
+ this.deferInstanceAuthorityRelease(key, objectGeneration);
436
+ await pendingClose;
437
+ return true;
438
+ }
439
+ const deferredRelease = this.deferredInstanceAuthorityReleases.get(key)?.has(objectGeneration) === true;
440
+ if (!deferredRelease
441
+ && this.activations.closingOperation(meshName, spotId) === undefined) {
442
+ return false;
443
+ }
444
+ const currentApplication = this.options.instanceSpotApplicationTargetProvider?.(meshName, spotId);
445
+ if (currentApplication !== undefined
446
+ && currentApplication.objectGeneration !== objectGeneration) {
447
+ this.removeDeferredInstanceAuthorityRelease(key, objectGeneration);
448
+ return false;
449
+ }
450
+ this.removeDeferredInstanceAuthorityRelease(key, objectGeneration);
451
+ await this.releaseInstanceAuthority(meshName, spotId, objectGeneration);
452
+ return true;
453
+ }
454
+ beginInstanceTerminal(meshName, spotId, objectGeneration) {
455
+ const key = `${meshName}\0${String(spotId)}`;
456
+ this.pendingInstanceTerminals.set(key, (this.pendingInstanceTerminals.get(key) ?? 0) + 1);
457
+ const generations = this.pendingInstanceTerminalGenerations.get(key) ?? new Map();
458
+ const generationKey = objectGeneration.toString();
459
+ generations.set(generationKey, (generations.get(generationKey) ?? 0) + 1);
460
+ this.pendingInstanceTerminalGenerations.set(key, generations);
461
+ }
462
+ deferInstanceAuthorityRelease(key, objectGeneration) {
463
+ const generations = this.deferredInstanceAuthorityReleases.get(key) ?? new Set();
464
+ generations.add(objectGeneration);
465
+ this.deferredInstanceAuthorityReleases.set(key, generations);
466
+ }
467
+ removeDeferredInstanceAuthorityRelease(key, objectGeneration) {
468
+ const generations = this.deferredInstanceAuthorityReleases.get(key);
469
+ if (generations === undefined)
470
+ return;
471
+ generations.delete(objectGeneration);
472
+ if (generations.size === 0)
473
+ this.deferredInstanceAuthorityReleases.delete(key);
474
+ }
475
+ removePendingInstanceTerminalGeneration(key, objectGeneration) {
476
+ const generations = this.pendingInstanceTerminalGenerations.get(key);
477
+ if (generations === undefined)
478
+ return;
479
+ const generationKey = objectGeneration.toString();
480
+ const pending = generations.get(generationKey);
481
+ if (pending === undefined || pending <= 1)
482
+ generations.delete(generationKey);
483
+ else
484
+ generations.set(generationKey, pending - 1);
485
+ }
486
+ releaseInstanceAuthority(meshName, spotId, objectGeneration) {
487
+ return this.options.releaseInstanceAuthority?.(meshName, spotId, objectGeneration)
488
+ ?? Promise.resolve();
489
+ }
490
+ requireInstanceFactory(meshName, instanceType) {
491
+ const factory = this.options.instanceSpotFactories?.get(meshName)?.get(instanceType);
492
+ if (factory === undefined) {
493
+ throw new configuration_1.ZLinkConfigurationException(`Instance Spot factory '${instanceType}' is not registered on RouteMesh '${meshName}'.`);
494
+ }
495
+ return factory;
496
+ }
497
+ scheduleIdleSweep() {
498
+ if (this.idleSweepTimer !== undefined)
499
+ return;
500
+ if (!this.hasIdleSweepTarget())
501
+ return;
502
+ const delays = [...(this.options.instanceSpotIdleTimeoutMs?.values() ?? [])]
503
+ .filter((value) => value > 0);
504
+ if (delays.length === 0)
505
+ return;
506
+ const delay = Math.max(1, Math.min(...delays));
507
+ const timer = setTimeout(() => {
508
+ this.idleSweepTimer = undefined;
509
+ void this.runIdleSweep();
510
+ }, delay);
511
+ timer.unref();
512
+ this.idleSweepTimer = timer;
513
+ }
514
+ hasIdleSweepTarget() {
515
+ return this.activations.hasActiveActivations();
516
+ }
517
+ async runIdleSweep() {
518
+ if (this.idleSweepRunning)
519
+ return;
520
+ this.idleSweepRunning = true;
521
+ try {
522
+ const now = performance.now();
523
+ for (const activation of this.activations.nextActiveActivationBatch()) {
524
+ const timeoutMs = this.options.instanceSpotIdleTimeoutMs?.get(activation.meshName) ?? 0;
525
+ if (timeoutMs <= 0
526
+ || activation.domain.kind !== 'instance'
527
+ || !activation.isIdleFor(now, timeoutMs)
528
+ || !activation.beginIdleEviction()) {
529
+ continue;
530
+ }
531
+ let durableClosing;
532
+ try {
533
+ durableClosing = await (this.options.beginInstanceIdleClosingAuthority?.(activation.meshName, activation.spotId) ?? Promise.resolve({ restoreReady: async () => undefined }));
534
+ }
535
+ catch (error) {
536
+ activation.abortIdleEviction();
537
+ throw error;
538
+ }
539
+ if (durableClosing === undefined) {
540
+ activation.abortIdleEviction();
541
+ continue;
542
+ }
543
+ const close = this.closeWithReason(activation.meshName, activation.spotId, undefined, contracts_1.ZLinkSpotCloseReason.IdleEvicted);
544
+ const run = async () => {
545
+ try {
546
+ const closed = await close;
547
+ if (!closed) {
548
+ await durableClosing.restoreReady();
549
+ activation.abortIdleEviction();
550
+ }
551
+ }
552
+ catch (error) {
553
+ if (error instanceof spot_activation_state_1.ZLinkSpotCloseOccupiedError) {
554
+ await durableClosing.restoreReady();
555
+ }
556
+ activation.abortIdleEviction();
557
+ throw error;
558
+ }
559
+ };
560
+ this.options.detachedTaskRunner?.runDetached(`instance idle eviction ${String(activation.spotId)}`, run);
561
+ if (this.options.detachedTaskRunner === undefined) {
562
+ void run().catch(() => undefined);
563
+ }
564
+ }
565
+ }
566
+ finally {
567
+ this.idleSweepRunning = false;
568
+ this.scheduleIdleSweep();
569
+ }
570
+ }
571
+ async create(meshName, spotType, requestOrSignal, signal) {
572
+ requireMeshName(meshName);
573
+ const args = normalizeSpotCreateArgs(requestOrSignal, signal);
574
+ this.options.admission?.requireRequest('SPOT create', meshName);
575
+ const spotId = this.activations.allocateSpotId(meshName);
576
+ const ownedRequest = args.request === undefined
577
+ ? runtime_message_1.ZLinkBufferMessage.from(Buffer.alloc(0))
578
+ : (0, payload_codec_1.encodeFrameworkPayloadMessage)(args.request, this.options.messageSerializers);
579
+ try {
580
+ return await this.createActivation(meshName, spotType, spotId, ownedRequest, args.signal);
581
+ }
582
+ finally {
583
+ ownedRequest.close();
584
+ }
585
+ }
586
+ async getOrCreate(meshName, spotType, spotId, requestOrSignal, signal) {
587
+ return await this.getOrCreateWithAuthority(meshName, spotType, spotId, requestOrSignal, undefined, signal);
588
+ }
589
+ async getOrCreateWithAuthority(meshName, spotType, spotId, requestOrSignal, authority, signal) {
590
+ requireMeshName(meshName);
591
+ const args = normalizeSpotCreateArgs(requestOrSignal, signal);
592
+ (0, abort_1.throwIfAborted)(args.signal);
593
+ const operation = this.activations.getOrBegin(meshName, spotType, spotId, async () => {
594
+ this.options.admission?.requireRequest('SPOT create', meshName);
595
+ const ownedRequest = args.request === undefined
596
+ ? runtime_message_1.ZLinkBufferMessage.from(Buffer.alloc(0))
597
+ : (0, payload_codec_1.encodeFrameworkPayloadMessage)(args.request, this.options.messageSerializers);
598
+ try {
599
+ return await this.createActivation(meshName, spotType, spotId, ownedRequest, undefined, authority);
600
+ }
601
+ finally {
602
+ ownedRequest.close();
603
+ }
604
+ });
605
+ return await (0, abort_1.awaitWithAbort)(operation.ready, args.signal);
606
+ }
607
+ async find(meshName, spotId) {
608
+ requireMeshName(meshName);
609
+ return this.activations.has(meshName, spotId) ? { spotId } : null;
610
+ }
611
+ async list(meshName) {
612
+ requireMeshName(meshName);
613
+ return this.activations.list(meshName);
614
+ }
615
+ async drainForShutdown(meshName, signal, deadline) {
616
+ const results = await Promise.allSettled(this.activations.activeActivations()
617
+ .filter(activation => activation.meshName === meshName)
618
+ .map(activation => this.closeWithReason(meshName, activation.spotId, signal, contracts_1.ZLinkSpotCloseReason.HostShutdown, deadline)));
619
+ const errors = results
620
+ .filter((result) => result.status === 'rejected')
621
+ .map(result => result.reason);
622
+ if (errors.length === 1)
623
+ throw errors[0];
624
+ if (errors.length > 1)
625
+ throw new AggregateError(errors, 'Spot shutdown cleanup failed.');
626
+ }
627
+ async close(meshName, spotId, signal) {
628
+ return await this.closeWithReason(meshName, spotId, signal, contracts_1.ZLinkSpotCloseReason.ExplicitClose);
629
+ }
630
+ async closeWithReason(meshName, spotId, signal, reason = contracts_1.ZLinkSpotCloseReason.ExplicitClose, deadline) {
631
+ requireMeshName(meshName);
632
+ const key = `${meshName}\0${String(spotId)}`;
633
+ const closing = this.activations.closingOperation(meshName, spotId);
634
+ if (closing !== undefined) {
635
+ return await closing.ready;
636
+ }
637
+ const pendingClose = this.pendingInstanceCloses.get(key);
638
+ if (pendingClose !== undefined) {
639
+ const pendingActivation = this.activations.resolve(meshName, spotId);
640
+ if (pendingActivation?.serial.isCurrentTurn === true)
641
+ return true;
642
+ return await pendingClose;
643
+ }
644
+ const activation = this.activations.resolve(meshName, spotId);
645
+ if (activation === undefined) {
646
+ return false;
647
+ }
648
+ const currentTurn = activation.serial.isCurrentTurn;
649
+ const isInstance = activation.domain.kind === 'instance';
650
+ const beginClose = () => {
651
+ const seal = activation.sealExecution();
652
+ const operation = this.activations.startClose(meshName, spotId, (target) => this.activationLifecycle.closeAfterSeal(target, seal, signal, reason, deadline), (target) => this.activationLifecycle.resourcesReleased(target), reason);
653
+ if (operation === undefined) {
654
+ activation.abortExecutionSeal(seal);
655
+ }
656
+ return operation;
657
+ };
658
+ if (isInstance) {
659
+ const beginAuthorityClose = reason === contracts_1.ZLinkSpotCloseReason.ExplicitClose
660
+ ? this.options.beginInstanceClosingAuthority
661
+ : undefined;
662
+ // Register the close gate before waiting for the current application
663
+ // and activation-authority terminal completions. A close requested from
664
+ // a handler cannot publish Closing until that handler's durable inbox
665
+ // completion has removed the recovery fence.
666
+ const trackedClosePromise = (async () => {
667
+ const waitForApplication = this.options.instanceSpotApplicationQuiescenceProvider?.(meshName, spotId, signal);
668
+ if (waitForApplication !== undefined) {
669
+ await waitForApplication;
670
+ }
671
+ const closingAuthority = beginAuthorityClose === undefined
672
+ ? undefined
673
+ : await beginAuthorityClose(meshName, spotId);
674
+ if (beginAuthorityClose !== undefined && closingAuthority === undefined) {
675
+ return false;
676
+ }
677
+ const operation = beginClose();
678
+ if (operation === undefined) {
679
+ await closingAuthority?.restoreReady();
680
+ return false;
681
+ }
682
+ const closed = await operation.ready;
683
+ if (!closed)
684
+ await closingAuthority?.restoreReady();
685
+ return closed;
686
+ })().finally(() => {
687
+ if (this.pendingInstanceCloses.get(key) === trackedClosePromise) {
688
+ this.pendingInstanceCloses.delete(key);
689
+ }
690
+ });
691
+ this.pendingInstanceCloses.set(key, trackedClosePromise);
692
+ if (currentTurn) {
693
+ // The current turn must return before its terminal completion can
694
+ // release the activation recovery fence and allow the durable close
695
+ // CAS. The registered close gate prevents a second admission while
696
+ // that detached close finishes.
697
+ this.options.detachedTaskRunner?.runDetached(`instance spot close ${String(spotId)}`, async () => { await trackedClosePromise; });
698
+ if (this.options.detachedTaskRunner === undefined) {
699
+ void trackedClosePromise.catch(() => undefined);
700
+ }
701
+ return true;
702
+ }
703
+ return await trackedClosePromise;
704
+ }
705
+ const operation = beginClose();
706
+ if (operation === undefined) {
707
+ return false;
708
+ }
709
+ if (currentTurn) {
710
+ if (operation.started) {
711
+ this.options.detachedTaskRunner?.runDetached(`spot close ${String(spotId)}`, async () => { await operation.ready; });
712
+ if (this.options.detachedTaskRunner === undefined) {
713
+ void operation.ready.catch(() => undefined);
714
+ }
715
+ }
716
+ return true;
717
+ }
718
+ return await operation.ready;
719
+ }
720
+ async executeOnSpot(spotType, spotId, operation, signal) {
721
+ (0, abort_1.throwIfAborted)(signal);
722
+ const activation = this.activations.resolveUnique(spotId);
723
+ if (activation === undefined) {
724
+ throw new configuration_1.ZLinkConfigurationException(`Spot '${spotId}' is not active.`);
725
+ }
726
+ if (activation.spotType !== spotType) {
727
+ throw new configuration_1.ZLinkConfigurationException(`Spot '${spotId}' has a different spot type.`);
728
+ }
729
+ if (activation.serial.isCurrentTurn) {
730
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.InvalidOperation, `Spot '${String(spotId)}' cannot start a public operation from its current serial turn.`);
731
+ }
732
+ return activation.serial.execute(() => operation(activation.spot));
733
+ }
734
+ hasActiveSpot(spotId) {
735
+ return this.activations.resolveUnique(spotId) !== undefined;
736
+ }
737
+ canCloseUserSpot(meshName, spotId) {
738
+ return this.activations.canClose(meshName, spotId);
739
+ }
740
+ beginUserSpotPublication(meshName, spotId) {
741
+ this.activations.stage(meshName, spotId);
742
+ }
743
+ publishUserSpot(meshName, spotId) {
744
+ this.activations.publish(meshName, spotId);
745
+ }
746
+ abortUserSpotPublication(meshName, spotId) {
747
+ this.activations.abandonStage(meshName, spotId);
748
+ }
749
+ resolveLocalSpotRoute(spotId) {
750
+ const activation = this.activations.resolveUnique(spotId);
751
+ const generation = activation?.nativeSpot?.lifecycleGeneration;
752
+ if (activation === undefined || generation === undefined || generation <= 0n) {
753
+ return undefined;
754
+ }
755
+ const nodeRid = this.options.nodeRidProvider?.(activation.meshName) ?? this.options.nodeRid;
756
+ if (nodeRid === undefined) {
757
+ return undefined;
758
+ }
759
+ return {
760
+ routerChannelId: this.options.spotRouterChannelIdForMesh?.(activation.meshName) ?? activation.meshName,
761
+ targetNodeRid: nodeRid,
762
+ spotId: activation.spotId,
763
+ spotKind: contracts_1.ZLinkSpotKind.User,
764
+ targetSpotGeneration: generation
765
+ };
766
+ }
767
+ async admitActorJoin(spotId, actor, request, commit, signal, leaveSource, contentType = 'application/json') {
768
+ const meshName = this.activations.resolveUnique(spotId)?.meshName;
769
+ this.options.admission?.requireRequest('Actor join admission', meshName);
770
+ return await this.actorMembership.admitActorJoin(spotId, actor, request, commit, signal, leaveSource, contentType);
771
+ }
772
+ async leaveActor(spotId, actor, signal) {
773
+ const meshName = this.activations.resolveUnique(spotId)?.meshName;
774
+ await this.actorMembership.leaveActor(spotId, actor, signal, meshName);
775
+ }
776
+ async leaveActorInMesh(meshName, spotId, actor, signal) {
777
+ requireMeshName(meshName);
778
+ await this.actorMembership.leaveActor(spotId, actor, signal, meshName);
779
+ }
780
+ async notifyActorLeftAfterTransfer(spotId, actor, signal) {
781
+ await this.actorMembership.notifyActorLeftAfterTransfer(spotId, actor, signal);
782
+ }
783
+ async prepareActorLeaveForTransfer(spotId, actor, signal) {
784
+ await this.actorMembership.prepareActorLeaveForTransfer(spotId, actor, signal);
785
+ }
786
+ async commitActorLeaveAfterTransfer(spotId, actorId) {
787
+ await this.actorMembership.commitActorLeaveAfterTransfer(spotId, actorId);
788
+ }
789
+ async restoreActorAfterFailedTransfer(spotId, actor, signal) {
790
+ await this.actorMembership.restoreActorAfterFailedTransfer(spotId, actor, signal);
791
+ }
792
+ async beginActorTransfer(spotId, actorId) {
793
+ await this.actorMembership.beginActorTransfer(spotId, actorId);
794
+ }
795
+ async cancelActorTransfer(spotId, actorId) {
796
+ await this.actorMembership.cancelActorTransfer(spotId, actorId);
797
+ }
798
+ async notifyJoinedSpotActorDisconnected(spotId, actor, signal) {
799
+ return await this.actorMembership.notifyJoinedActorDisconnected(spotId, actor, signal);
800
+ }
801
+ dispatchRoutedActorPacket(spotId, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef) {
802
+ const activation = this.activations.resolveUnique(spotId);
803
+ if (activation === undefined) {
804
+ throw new configuration_1.ZLinkConfigurationException(`Spot '${spotId}' is not active.`);
805
+ }
806
+ return this.dispatchActorPacket(activation, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef);
807
+ }
808
+ /** @internal Replays a record already owned by the Actor handoff queue. */
809
+ dispatchRoutedActorPacketDirect(spotId, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef) {
810
+ const activation = this.activations.resolveUnique(spotId);
811
+ if (activation === undefined) {
812
+ throw new configuration_1.ZLinkConfigurationException(`Spot '${spotId}' is not active.`);
813
+ }
814
+ return this.activationLifecycle.dispatchActorPacketDirect(activation, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef);
815
+ }
816
+ /** @internal Atomically restores one durable packet prefix to an Actor FIFO. */
817
+ admitRoutedActorPacketPrefix(spotId, actorId, records) {
818
+ const activation = this.activations.resolveUnique(spotId);
819
+ if (activation === undefined) {
820
+ throw new configuration_1.ZLinkConfigurationException(`Spot '${spotId}' is not active.`);
821
+ }
822
+ return this.activationLifecycle.admitActorPacketPrefix(activation, actorId, records);
823
+ }
824
+ async dispatchRoutedSpotSend(spotId, packetName, message, context) {
825
+ await this.routedSpotPackets.send(spotId, packetName, message, context);
826
+ }
827
+ async dispatchRoutedSpotRequest(spotId, packetName, request, context) {
828
+ return await this.routedSpotPackets.request(spotId, packetName, request, context);
829
+ }
830
+ async dispatchMeshSpot(meshName, owner, record) {
831
+ const spotId = owner.spotId;
832
+ if (spotId === null) {
833
+ throw new configuration_1.ZLinkConfigurationException('MeshNode Spot record is missing the owner Spot RID.');
834
+ }
835
+ if (record.kind === service_runtime_contracts_1.ReceiveKind.SpotMulticast) {
836
+ const activation = this.activations.resolve(meshName, spotId);
837
+ if (activation?.actorDispatch === undefined) {
838
+ throw new configuration_1.ZLinkConfigurationException(`MeshNode Spot multicast target '${String(spotId)}' is not active.`);
839
+ }
840
+ if (record.topic === null || record.topic.length === 0) {
841
+ throw new configuration_1.ZLinkConfigurationException('MeshNode Spot multicast record is missing its topic.');
842
+ }
843
+ await activation.actorDispatch.dispatchSubscriptionRecord(record.topic, record.parts, record.sourceNodeRid);
844
+ return;
845
+ }
846
+ const envelope = (0, channel_envelope_1.decodeChannelEnvelope)(record.parts, undefined, this.options.dispatchErrors?.flow.flowCreationEnabled() ?? true);
847
+ const packetName = envelope.packetName;
848
+ const codecs = this.options.messageSerializers === undefined
849
+ ? undefined
850
+ : { serializers: this.options.messageSerializers };
851
+ const decodePayload = () => (0, channel_envelope_1.decodeChannelPayload)(envelope, codecs);
852
+ const context = {
853
+ channelName: envelope.header.channelName,
854
+ contentType: envelope.header.contentType,
855
+ workOptions: (0, serial_work_size_1.zlinkSerialWorkOptions)(envelope.payload.byteLength, record.applicationMetadata?.byteLength ?? (0, serial_work_size_1.zlinkMetadataByteLength)(envelope.header.metadata))
856
+ };
857
+ if (record.kind === service_runtime_contracts_1.ReceiveKind.SpotSend) {
858
+ await this.ensureInstanceApplicationActivation(meshName, spotId);
859
+ await this.routedSpotPackets.sendEncoded(spotId, packetName, decodePayload, context);
860
+ return;
861
+ }
862
+ if (record.kind !== service_runtime_contracts_1.ReceiveKind.SpotRequest) {
863
+ throw new configuration_1.ZLinkConfigurationException(`Unsupported MeshNode Spot record kind '${record.kind}'.`);
864
+ }
865
+ try {
866
+ await this.ensureInstanceApplicationActivation(meshName, spotId);
867
+ const response = await this.routedSpotPackets.requestEncoded(spotId, packetName, decodePayload, context);
868
+ requireMeshSpotReply(record.reply((0, channel_envelope_1.encodeChannelReplyParts)(envelope.header, response, codecs)));
869
+ }
870
+ catch (error) {
871
+ requireMeshSpotReply(record.reply((0, channel_envelope_1.encodeChannelErrorReplyParts)(envelope.header, error instanceof Error ? error.message : String(error))));
872
+ }
873
+ }
874
+ async ensureInstanceApplicationActivation(meshName, spotId) {
875
+ let target = this.options.instanceSpotApplicationTargetProvider?.(meshName, spotId);
876
+ if (target === undefined)
877
+ return;
878
+ for (;;) {
879
+ const current = this.activations.resolve(meshName, spotId);
880
+ if (current !== undefined
881
+ && current.objectGeneration === target.objectGeneration
882
+ && current.spotType === this.requireInstanceFactory(meshName, target.stableType))
883
+ return;
884
+ await this.materializeInstance(meshName, target.stableType, spotId, target.objectGeneration);
885
+ const latest = this.options.instanceSpotApplicationTargetProvider?.(meshName, spotId);
886
+ if (latest === undefined) {
887
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving, `Instance Spot target '${String(spotId)}' no longer has a Ready application target.`);
888
+ }
889
+ if (latest.objectGeneration === target.objectGeneration)
890
+ return;
891
+ target = latest;
892
+ }
893
+ }
894
+ async dispatchMeshInstance(meshName, owner, record) {
895
+ const spotId = owner.spotId;
896
+ if (spotId === null) {
897
+ throw new configuration_1.ZLinkConfigurationException('MeshNode Instance Spot record is missing the owner Spot RID.');
898
+ }
899
+ const envelope = (0, channel_envelope_1.decodeChannelEnvelope)(record.parts, undefined, this.options.dispatchErrors?.flow.flowCreationEnabled() ?? true);
900
+ const inboundFlow = (0, diagnostics_1.createInboundFlow)(envelope.header.flowId, envelope.header.flowOrigin, this.options.dispatchErrors?.flow.flowCreationEnabled() ?? true);
901
+ await (0, diagnostics_1.runWithFlow)(inboundFlow, async () => {
902
+ const request = record.operationKind === service_runtime_contracts_1.OperationKind.InstanceSpotRequest;
903
+ this.traceInstanceMessage(ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Received, meshName, spotId, record, envelope, 'activating');
904
+ try {
905
+ await this.ensureInstanceApplicationActivation(meshName, spotId);
906
+ const activation = this.activations.resolve(meshName, spotId);
907
+ if (activation === undefined || activation.domain.kind !== 'instance') {
908
+ throw new configuration_1.ZLinkConfigurationException(`MeshNode Instance Spot target '${String(spotId)}' is not active.`);
909
+ }
910
+ const target = this.options.instanceSpotApplicationTargetProvider?.(meshName, spotId);
911
+ if (target !== undefined
912
+ && activation.domain.objectGeneration !== target.objectGeneration) {
913
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotGenerationStale, `Instance Spot target '${String(spotId)}' application generation is stale.`);
914
+ }
915
+ const codecs = this.options.messageSerializers === undefined
916
+ ? undefined
917
+ : { serializers: this.options.messageSerializers };
918
+ const decodePayload = () => (0, channel_envelope_1.decodeChannelPayload)(envelope, codecs);
919
+ const context = {
920
+ channelName: envelope.header.channelName,
921
+ contentType: envelope.header.contentType,
922
+ awaitFirstHandlerTurn: record.kind === service_runtime_contracts_1.ReceiveKind.InstanceSpotActivation,
923
+ workOptions: (0, serial_work_size_1.zlinkSerialWorkOptions)(envelope.payload.byteLength, record.applicationMetadata?.byteLength ?? (0, serial_work_size_1.zlinkMetadataByteLength)(envelope.header.metadata))
924
+ };
925
+ this.traceInstanceMessage(ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Admitted, meshName, spotId, record, envelope, 'ready', target?.stableType);
926
+ if (!request) {
927
+ this.traceInstanceMessage(ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Dispatched, meshName, spotId, record, envelope, 'ready', target?.stableType);
928
+ await this.routedSpotPackets.sendEncoded(spotId, envelope.packetName, decodePayload, context);
929
+ this.traceInstanceMessage(ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Completed, meshName, spotId, record, envelope, 'ready', target?.stableType);
930
+ return;
931
+ }
932
+ this.traceInstanceMessage(ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Dispatched, meshName, spotId, record, envelope, 'ready', target?.stableType);
933
+ const response = await this.routedSpotPackets.requestEncoded(spotId, envelope.packetName, decodePayload, context);
934
+ requireMeshSpotReply(record.reply((0, channel_envelope_1.encodeChannelReplyParts)(envelope.header, response, codecs)));
935
+ this.traceInstanceMessage(ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Replied, meshName, spotId, record, envelope, 'ready', target?.stableType);
936
+ }
937
+ catch (error) {
938
+ const reason = instanceDispatchErrorReason(error);
939
+ if (!request) {
940
+ this.traceInstanceMessage(ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Dropped, meshName, spotId, record, envelope, 'closing', undefined, reason);
941
+ return;
942
+ }
943
+ this.options.dispatchErrors?.report({
944
+ surface: ZLinkDispatchOptions_1.ZLinkDispatchErrorSurface.InstanceSpot,
945
+ messageKind: ZLinkDispatchOptions_1.ZLinkDispatchMessageKind.Request,
946
+ packetName: envelope.packetName,
947
+ channelName: envelope.header.channelName,
948
+ meshName,
949
+ correlationId: envelope.header.correlationId ?? undefined,
950
+ sourceRid: record.sourceNodeRid === null ? undefined : String(record.sourceNodeRid),
951
+ spotId: String(spotId),
952
+ instanceSpotType: this.options.instanceSpotApplicationTargetProvider?.(meshName, spotId)?.stableType,
953
+ activationState: 'closing',
954
+ flowId: envelope.header.flowId,
955
+ flowOrigin: envelope.header.flowOrigin,
956
+ reason,
957
+ action: ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorAction.ReplyError,
958
+ error
959
+ });
960
+ requireMeshSpotReply(record.reply((0, channel_envelope_1.encodeChannelErrorReplyParts)(envelope.header, error instanceof Error ? error.message : String(error))));
961
+ }
962
+ });
963
+ }
964
+ traceInstanceMessage(outcome, meshName, spotId, record, envelope, activationState, instanceSpotType, errorReason) {
965
+ const flow = (0, diagnostics_1.flowIfEnabled)(this.options.dispatchErrors?.flow, outcome, undefined, envelope.header.flowId);
966
+ if (flow === undefined)
967
+ return;
968
+ flow.trace({
969
+ outcome,
970
+ surface: ZLinkDispatchOptions_1.ZLinkDispatchErrorSurface.InstanceSpot,
971
+ messageKind: record.operationKind === service_runtime_contracts_1.OperationKind.InstanceSpotRequest
972
+ ? ZLinkDispatchOptions_1.ZLinkDispatchMessageKind.Request
973
+ : ZLinkDispatchOptions_1.ZLinkDispatchMessageKind.Send,
974
+ packetName: envelope.packetName,
975
+ channelName: envelope.header.channelName,
976
+ meshName,
977
+ correlationId: envelope.header.correlationId ?? undefined,
978
+ sourceRid: record.sourceNodeRid === null ? undefined : String(record.sourceNodeRid),
979
+ spotId: String(spotId),
980
+ instanceSpotType,
981
+ activationState,
982
+ flowId: envelope.header.flowId,
983
+ flowOrigin: envelope.header.flowOrigin,
984
+ errorReason
985
+ });
986
+ }
987
+ async dispatchMeshActor(meshName, owner, record) {
988
+ const spotId = owner.spotId;
989
+ const entrySpotId = this.options.entryNodeRidProvider?.() ?? this.options.entryNodeRid;
990
+ const targetsEntrySpot = spotId === null
991
+ || (entrySpotId !== undefined && spotId === entrySpotId);
992
+ const actor = owner.actor;
993
+ if (actor === null) {
994
+ throw new configuration_1.ZLinkConfigurationException('MeshNode Actor record is missing its Actor owner.');
995
+ }
996
+ const request = record.kind === service_runtime_contracts_1.ReceiveKind.ActorRequest;
997
+ if (record.sourceBindingGeneration > 0n) {
998
+ this.options.actorBindingGenerationObserver?.(actor.actorId, record.sourceBindingGeneration);
999
+ }
1000
+ const resolvedOwner = this.options.actorDispatchOwnerResolver?.(actor.actorId);
1001
+ const resolvedActorRef = resolvedOwner?.actorRef ?? {
1002
+ actorId: actor.actorId,
1003
+ objectGeneration: actor.generation,
1004
+ meshName,
1005
+ nodeRid: String(actor.nodeRid)
1006
+ };
1007
+ const responseActorRef = record.sourceBindingGeneration > 0n
1008
+ ? {
1009
+ ...resolvedActorRef,
1010
+ bindingGeneration: record.sourceBindingGeneration
1011
+ }
1012
+ : resolvedActorRef;
1013
+ const ownerActorRef = responseActorRef;
1014
+ const requestTerminalState = { prepared: false, submitted: false };
1015
+ const requestTerminal = request
1016
+ ? Object.assign((response, preparedReply) => {
1017
+ const encoded = preparedReply === undefined
1018
+ ? this.encodeMeshActorReply(record.parts[0], protocol_1.ZLinkStreamMessageKind.Response, response)
1019
+ : preparedReply;
1020
+ requireMeshSpotReply(record.reply(encoded));
1021
+ requestTerminalState.submitted = true;
1022
+ }, {
1023
+ prepare: (response) => {
1024
+ const encoded = this.encodeMeshActorReply(record.parts[0], protocol_1.ZLinkStreamMessageKind.Response, response);
1025
+ requestTerminalState.prepared = true;
1026
+ return encoded;
1027
+ }
1028
+ })
1029
+ : undefined;
1030
+ try {
1031
+ if (this.formalRemoteTransfers.has(actor.actorId)) {
1032
+ throw new Error(`Actor '${actor.actorId}' target transfer reconciliation is not complete.`);
1033
+ }
1034
+ const response = targetsEntrySpot
1035
+ ? await this.options.dispatchEntryActorPacket?.(actor.actorId, record.parts, request, undefined, ownerActorRef, requestTerminal, record.messageFollowOrigin)
1036
+ : await this.dispatchMeshActorPacket(meshName, spotId, actor.actorId, record.parts, request, ownerActorRef, requestTerminal, record.messageFollowOrigin);
1037
+ if (targetsEntrySpot && this.options.dispatchEntryActorPacket === undefined) {
1038
+ throw new configuration_1.ZLinkConfigurationException('MeshNode Entry Spot Actor dispatch is not configured.');
1039
+ }
1040
+ if (request && !requestTerminalState.submitted) {
1041
+ requireMeshSpotReply(record.reply(this.encodeMeshActorReply(record.parts[0], protocol_1.ZLinkStreamMessageKind.Response, response)));
1042
+ }
1043
+ }
1044
+ catch (error) {
1045
+ if (!request) {
1046
+ throw error;
1047
+ }
1048
+ if (requestTerminalState.prepared || requestTerminalState.submitted) {
1049
+ throw error;
1050
+ }
1051
+ requireMeshSpotReply(record.reply(this.encodeMeshActorReply(record.parts[0], protocol_1.ZLinkStreamMessageKind.Error, {
1052
+ message: error instanceof Error ? error.message : String(error),
1053
+ kind: error instanceof contracts_1.ZLinkFrameworkException
1054
+ ? error.kind
1055
+ : contracts_1.ZLinkFrameworkErrorKind.InternalFailure
1056
+ })));
1057
+ }
1058
+ }
1059
+ async dispatchMeshActorJoin(meshName, owner, record) {
1060
+ const spotId = owner.spotId;
1061
+ const control = record.kindData;
1062
+ if (control?.kind !== 'actorControl') {
1063
+ throw new configuration_1.ZLinkConfigurationException('MeshNode Actor join record is missing lifecycle identity data.');
1064
+ }
1065
+ const actorId = control.currentActor?.actorId;
1066
+ if (spotId === null || actorId === undefined) {
1067
+ throw new configuration_1.ZLinkConfigurationException('MeshNode Actor join record is missing its Spot or Actor owner.');
1068
+ }
1069
+ const entrySpotId = this.options.entryNodeRidProvider?.() ?? this.options.entryNodeRid;
1070
+ let requestContentType = record.contentType ?? 'application/json';
1071
+ const targetsEntrySpot = entrySpotId !== undefined
1072
+ && String(spotId) === String(entrySpotId);
1073
+ const activation = this.activations.resolve(meshName, spotId);
1074
+ const transferRequest = record.parts.length === 0
1075
+ ? undefined
1076
+ : decodeFormalRemoteTransferRequest(record.parts[0]);
1077
+ const remoteJoinPhase = transferRequest?.phase;
1078
+ const isRemoteAdmission = remoteJoinPhase === actor_remote_wire_1.REMOTE_ACTOR_JOIN_ADMISSION;
1079
+ const isRemoteCommit = remoteJoinPhase === actor_remote_wire_1.REMOTE_ACTOR_JOIN_COMMIT;
1080
+ const isRemoteAbort = remoteJoinPhase === actor_remote_wire_1.REMOTE_ACTOR_JOIN_ABORT;
1081
+ let admissionRecord = transferRequest !== undefined
1082
+ ? this.formalRemoteActorAdmissions.get(transferRequest.transferId)
1083
+ : undefined;
1084
+ let canonicalAdmissionCreated = false;
1085
+ let pendingAdmission = isRemoteCommit ? admissionRecord : undefined;
1086
+ let commitAdmissionMissing = isRemoteCommit && admissionRecord === undefined;
1087
+ const applicationClaim = transferRequest === undefined
1088
+ ? this.options.admission?.claim(meshName, 'Actor join dispatch')
1089
+ : undefined;
1090
+ let canonicalActorType;
1091
+ if (control.canonicalActorJoin !== undefined) {
1092
+ const resolver = this.options.canonicalActorJoinResolver;
1093
+ if (resolver === undefined) {
1094
+ throw new configuration_1.ZLinkConfigurationException('Canonical Actor Join dispatch requires the Location Store admission resolver.');
1095
+ }
1096
+ const rawActorRef = control.previousActor ?? control.currentActor;
1097
+ const rawRequest = record.parts[0];
1098
+ if (rawActorRef === null) {
1099
+ throw new configuration_1.ZLinkConfigurationException(`Actor '${actorId}' canonical admission is missing its ActorRef or request.`);
1100
+ }
1101
+ const actorRef = toFrameworkRemoteAdmissionActorRef(rawActorRef, meshName);
1102
+ const provisional = this.formalRemoteActorAdmissions.beginProvisional({
1103
+ actorId,
1104
+ actorRef,
1105
+ spotId,
1106
+ targetSpotGeneration: control.currentSpotGeneration,
1107
+ expectedMembershipEpoch: control.currentMembershipEpoch,
1108
+ requestFingerprint: rawRequest.data().toString('base64'),
1109
+ transferId: control.canonicalActorJoin.handoffId,
1110
+ sourceActorNodeRid: control.canonicalActorJoin.actorNodeRid
1111
+ });
1112
+ admissionRecord = provisional.record;
1113
+ canonicalAdmissionCreated = provisional.created;
1114
+ try {
1115
+ canonicalActorType = (await resolver({ actorId, ...control.canonicalActorJoin })).actorType;
1116
+ }
1117
+ catch (error) {
1118
+ this.formalRemoteActorAdmissions.fail(control.canonicalActorJoin.handoffId, error);
1119
+ if (error instanceof contracts_1.ZLinkFrameworkException && record.replyFailure !== undefined) {
1120
+ const terminal = (0, framework_errors_internal_1.internalFrameworkWireReply)(error);
1121
+ requireMeshSpotReply(record.replyFailure(terminal.terminalResult, terminal.failureCode));
1122
+ return;
1123
+ }
1124
+ throw error;
1125
+ }
1126
+ }
1127
+ const resolvedActor = this.options.actorResolver?.(actorId);
1128
+ const lifecycleActor = targetsEntrySpot
1129
+ ? this.options.actorLifecycleResolver?.(actorId)
1130
+ : undefined;
1131
+ let actor = resolvedActor;
1132
+ if (actor === undefined && targetsEntrySpot) {
1133
+ // An actor returning from a User Spot can still be marked as moving
1134
+ // while the source-side relocation fence is being completed. Entry Spot
1135
+ // admission must resolve that lifecycle object so the accepted Core
1136
+ // reply can commit the return transaction.
1137
+ actor = lifecycleActor;
1138
+ }
1139
+ if (actor === undefined && admissionRecord?.actor !== undefined) {
1140
+ actor = admissionRecord.actor;
1141
+ }
1142
+ let callbackRequest = record.parts.length === 0
1143
+ ? undefined
1144
+ : record.parts[0];
1145
+ let ownedCallbackRequest;
1146
+ let materialized = false;
1147
+ let reply;
1148
+ let deferredJoinRoot;
1149
+ let preparedTransferState;
1150
+ let admissionOutcome;
1151
+ let accepted = false;
1152
+ let committedAdmissionReplay = isRemoteCommit
1153
+ && admissionRecord?.state === 'committed';
1154
+ let targetCommitPublished;
1155
+ const actorJoinIsCurrent = () => ((record.deadlineUnixMs === undefined || record.deadlineUnixMs > BigInt(Date.now()))
1156
+ && (record.isPending?.() ?? true));
1157
+ const abandonStaleAdmission = () => {
1158
+ if (isRemoteAdmission && transferRequest !== undefined) {
1159
+ this.formalRemoteActorAdmissions.abort(transferRequest.transferId);
1160
+ }
1161
+ };
1162
+ try {
1163
+ if (!isRemoteAbort && !actorJoinIsCurrent()) {
1164
+ abandonStaleAdmission();
1165
+ return;
1166
+ }
1167
+ if (isRemoteAbort) {
1168
+ if (transferRequest !== undefined) {
1169
+ this.formalRemoteActorAdmissions.abort(transferRequest.transferId);
1170
+ }
1171
+ requireMeshSpotReply(record.replyActorJoin(1, []));
1172
+ return;
1173
+ }
1174
+ if (transferRequest !== undefined) {
1175
+ ownedCallbackRequest = runtime_message_1.ZLinkBufferMessage.from(Buffer.from(transferRequest.request, 'base64'));
1176
+ callbackRequest = ownedCallbackRequest;
1177
+ }
1178
+ else if (callbackRequest !== undefined) {
1179
+ ownedCallbackRequest = runtime_message_1.ZLinkBufferMessage.from(callbackRequest.data());
1180
+ callbackRequest = ownedCallbackRequest;
1181
+ }
1182
+ if (control.canonicalActorJoin !== undefined) {
1183
+ if (callbackRequest === undefined) {
1184
+ throw new configuration_1.ZLinkConfigurationException(`Actor '${actorId}' canonical admission could not resolve its request.`);
1185
+ }
1186
+ const actorType = canonicalActorType;
1187
+ if (actorType === undefined) {
1188
+ throw new configuration_1.ZLinkConfigurationException(`Actor '${actorId}' canonical admission has no Store-resolved Actor type.`);
1189
+ }
1190
+ const actorRef = toFrameworkRemoteAdmissionActorRef(control.previousActor ?? control.currentActor, meshName);
1191
+ admissionRecord = this.formalRemoteActorAdmissions.finalizeProvisional(control.canonicalActorJoin.handoffId, {
1192
+ actorId,
1193
+ actorType,
1194
+ actorRef,
1195
+ spotId,
1196
+ targetSpotGeneration: control.currentSpotGeneration,
1197
+ expectedMembershipEpoch: control.currentMembershipEpoch,
1198
+ requestFingerprint: callbackRequest.data().toString('base64'),
1199
+ transferId: control.canonicalActorJoin.handoffId,
1200
+ sourceActorNodeRid: control.canonicalActorJoin.actorNodeRid
1201
+ });
1202
+ if (canonicalAdmissionCreated) {
1203
+ if (targetsEntrySpot) {
1204
+ admissionOutcome = {
1205
+ accepted: this.options.dispatchEntryActorJoin !== undefined,
1206
+ actorRef
1207
+ };
1208
+ }
1209
+ else if (activation === undefined) {
1210
+ admissionOutcome = { accepted: false, actorRef };
1211
+ }
1212
+ else {
1213
+ const response = await activation.serial.execute(async () => activation.spot.onActorJoin(actorRef.actorId, (0, payload_codec_1.wrapFrameworkPayloadMessage)(callbackRequest, this.options.messageSerializers, requestContentType)));
1214
+ let encodedReply;
1215
+ try {
1216
+ encodedReply = response.reply === undefined
1217
+ ? undefined
1218
+ : (0, payload_codec_1.encodeFrameworkPayloadMessage)(response.reply, this.options.messageSerializers);
1219
+ admissionOutcome = {
1220
+ accepted: response.accepted,
1221
+ actorRef,
1222
+ ...(encodedReply === undefined
1223
+ ? {}
1224
+ : {
1225
+ reply: Buffer.from(encodedReply.data()),
1226
+ replyContentType: (0, payload_codec_1.frameworkPayloadContentType)(encodedReply)
1227
+ })
1228
+ };
1229
+ }
1230
+ finally {
1231
+ encodedReply?.close();
1232
+ }
1233
+ }
1234
+ this.formalRemoteActorAdmissions.complete(control.canonicalActorJoin.handoffId, admissionOutcome);
1235
+ }
1236
+ admissionOutcome = admissionRecord.result ?? await admissionRecord.resultTask;
1237
+ if ('error' in admissionOutcome)
1238
+ throw admissionOutcome.error;
1239
+ accepted = admissionOutcome.accepted;
1240
+ reply = admissionOutcome.reply === undefined
1241
+ ? undefined
1242
+ : runtime_message_1.ZLinkBufferMessage.from(admissionOutcome.reply);
1243
+ }
1244
+ if (transferRequest !== undefined
1245
+ && !targetsEntrySpot
1246
+ && remoteJoinPhase === undefined) {
1247
+ // User Spot transfers must carry the private admission/commit phases.
1248
+ // A legacy one-phase request would otherwise read relocation state
1249
+ // before the target application has accepted the Actor.
1250
+ requireMeshSpotReply(record.replyActorJoin(1, []));
1251
+ return;
1252
+ }
1253
+ if (isRemoteAdmission && transferRequest !== undefined) {
1254
+ const rawActorRef = transferRequest.actorRef ?? control.currentActor ?? undefined;
1255
+ if (rawActorRef === undefined) {
1256
+ throw new configuration_1.ZLinkConfigurationException(`Actor '${actorId}' join record has no ActorRef.`);
1257
+ }
1258
+ const actorRef = toFrameworkRemoteAdmissionActorRef(rawActorRef, meshName);
1259
+ const admission = this.formalRemoteActorAdmissions.begin({
1260
+ actorId,
1261
+ actorType: transferRequest.actorType,
1262
+ actorRef,
1263
+ spotId,
1264
+ targetSpotGeneration: control.currentSpotGeneration,
1265
+ expectedMembershipEpoch: transferRequest.expectedMembershipEpoch,
1266
+ requestFingerprint: transferRequest.request,
1267
+ transferId: transferRequest.transferId,
1268
+ completionOperationId: transferRequest.completionOperationId,
1269
+ sourceSpotId: transferRequest.sourceSpotId
1270
+ });
1271
+ admissionRecord = admission.record;
1272
+ if (admission.created) {
1273
+ try {
1274
+ if (targetsEntrySpot) {
1275
+ if (this.options.dispatchEntryActorJoin !== undefined
1276
+ && transferRequest.completionOperationId !== undefined
1277
+ && this.options.actorTransferRuntime !== undefined) {
1278
+ deferredJoinRoot = await this.options.actorTransferRuntime
1279
+ .prepareDeferredJoinAccepted(actorId, transferRequest.completionOperationId, actorRef, Buffer.alloc(0));
1280
+ }
1281
+ admissionOutcome = {
1282
+ accepted: this.options.dispatchEntryActorJoin !== undefined,
1283
+ actorRef,
1284
+ ...(deferredJoinRoot === undefined ? {} : { deferredJoinRoot })
1285
+ };
1286
+ }
1287
+ else if (activation === undefined) {
1288
+ admissionOutcome = { accepted: false, actorRef };
1289
+ }
1290
+ else {
1291
+ if (!actorJoinIsCurrent()) {
1292
+ abandonStaleAdmission();
1293
+ return;
1294
+ }
1295
+ const response = await activation.serial.execute(async () => activation.spot.onActorJoin(actorRef.actorId, (0, payload_codec_1.wrapFrameworkPayloadMessage)(ownedCallbackRequest, this.options.messageSerializers, transferRequest.requestContentType)));
1296
+ let encodedReply;
1297
+ try {
1298
+ encodedReply = response.reply === undefined
1299
+ ? undefined
1300
+ : (0, payload_codec_1.encodeFrameworkPayloadMessage)(response.reply, this.options.messageSerializers);
1301
+ if (response.accepted
1302
+ && transferRequest.completionOperationId !== undefined
1303
+ && this.options.actorTransferRuntime !== undefined) {
1304
+ deferredJoinRoot = await this.options.actorTransferRuntime
1305
+ .prepareDeferredJoinAccepted(actorId, transferRequest.completionOperationId, actorRef, encodedReply?.data() ?? Buffer.alloc(0), encodedReply === undefined
1306
+ ? undefined
1307
+ : (0, payload_codec_1.frameworkPayloadContentType)(encodedReply));
1308
+ this.options.runtimeEventPublisher?.publish({
1309
+ sourceName: 'zlink.framework.actor-handoff',
1310
+ timestamp: new Date(),
1311
+ marker: 'deferred_completion_staged',
1312
+ actorId
1313
+ });
1314
+ }
1315
+ admissionOutcome = {
1316
+ accepted: response.accepted,
1317
+ actorRef,
1318
+ ...(deferredJoinRoot === undefined ? {} : { deferredJoinRoot }),
1319
+ ...(encodedReply === undefined
1320
+ ? {}
1321
+ : {
1322
+ reply: Buffer.from(encodedReply.data()),
1323
+ replyContentType: (0, payload_codec_1.frameworkPayloadContentType)(encodedReply)
1324
+ })
1325
+ };
1326
+ }
1327
+ finally {
1328
+ encodedReply?.close();
1329
+ }
1330
+ if (!actorJoinIsCurrent()) {
1331
+ abandonStaleAdmission();
1332
+ return;
1333
+ }
1334
+ }
1335
+ this.formalRemoteActorAdmissions.complete(transferRequest.transferId, admissionOutcome);
1336
+ }
1337
+ catch (error) {
1338
+ this.formalRemoteActorAdmissions.fail(transferRequest.transferId, error);
1339
+ throw error;
1340
+ }
1341
+ }
1342
+ admissionOutcome = await admissionRecord.resultTask;
1343
+ if ('error' in admissionOutcome) {
1344
+ throw admissionOutcome.error;
1345
+ }
1346
+ accepted = admissionOutcome.accepted;
1347
+ reply = admissionOutcome.reply === undefined
1348
+ ? undefined
1349
+ : runtime_message_1.ZLinkBufferMessage.from(admissionOutcome.reply);
1350
+ }
1351
+ if (isRemoteCommit && admissionRecord !== undefined) {
1352
+ admissionOutcome = await admissionRecord.resultTask;
1353
+ if ('error' in admissionOutcome) {
1354
+ throw admissionOutcome.error;
1355
+ }
1356
+ deferredJoinRoot = admissionOutcome.deferredJoinRoot;
1357
+ }
1358
+ if (actor === undefined
1359
+ && transferRequest !== undefined
1360
+ && this.options.actorTransferRuntime !== undefined
1361
+ && !isRemoteAdmission
1362
+ && !commitAdmissionMissing
1363
+ && admissionRecord?.state !== 'committed'
1364
+ && (targetsEntrySpot || activation !== undefined)) {
1365
+ // Relocation state travels inline with the join request. The store
1366
+ // reference handoff was removed with the direct-transfer contract
1367
+ // (spec 28 §2 — Relocation Store keeps no relocation state payloads).
1368
+ if (transferRequest.transferState === undefined) {
1369
+ throw new configuration_1.ZLinkConfigurationException(`Actor '${actorId}' transfer commit carries no inline relocation state.`);
1370
+ }
1371
+ preparedTransferState = runtime_message_1.ZLinkBufferMessage.from(Buffer.from(transferRequest.transferState, 'base64'));
1372
+ }
1373
+ if (isRemoteAdmission && targetsEntrySpot) {
1374
+ accepted = admissionOutcome !== undefined
1375
+ && !('error' in admissionOutcome)
1376
+ && admissionOutcome.accepted;
1377
+ }
1378
+ else if (isRemoteCommit && pendingAdmission !== undefined) {
1379
+ validateRemoteAdmissionCommit(pendingAdmission, transferRequest, actorId, control);
1380
+ accepted = pendingAdmission.state === 'admitted'
1381
+ || pendingAdmission.state === 'committed';
1382
+ }
1383
+ else if (commitAdmissionMissing) {
1384
+ accepted = false;
1385
+ }
1386
+ else if (targetsEntrySpot) {
1387
+ // Entry Spot return joins have no application admission callback. The
1388
+ // actor-manager transaction is committed after the Core reply below.
1389
+ // A formal transfer payload materializes the existing actor state at
1390
+ // the Entry owner before that transaction is committed.
1391
+ accepted = actor !== undefined
1392
+ || (transferRequest !== undefined && this.options.actorTransferRuntime !== undefined);
1393
+ }
1394
+ else if (!isRemoteAdmission
1395
+ && control.canonicalActorJoin === undefined
1396
+ &&
1397
+ activation !== undefined
1398
+ && callbackRequest !== undefined
1399
+ && (actor !== undefined || transferRequest !== undefined)) {
1400
+ if (!actorJoinIsCurrent())
1401
+ return;
1402
+ const request = callbackRequest;
1403
+ const rawActorRef = transferRequest?.actorRef ?? control.currentActor ?? undefined;
1404
+ if (rawActorRef === undefined) {
1405
+ throw new configuration_1.ZLinkConfigurationException(`Actor '${actorId}' join record has no ActorRef.`);
1406
+ }
1407
+ const actorRef = {
1408
+ actorId: rawActorRef.actorId,
1409
+ objectGeneration: 'objectGeneration' in rawActorRef
1410
+ ? rawActorRef.objectGeneration
1411
+ : rawActorRef.generation,
1412
+ meshName,
1413
+ nodeRid: rawActorRef.nodeRid
1414
+ };
1415
+ const response = await activation.serial.execute(async () => activation.spot.onActorJoin(actorRef.actorId, (0, payload_codec_1.wrapFrameworkPayloadMessage)(request, this.options.messageSerializers, transferRequest?.requestContentType ?? requestContentType)));
1416
+ if (!actorJoinIsCurrent())
1417
+ return;
1418
+ accepted = response.accepted;
1419
+ reply = response.reply === undefined
1420
+ ? undefined
1421
+ : (0, payload_codec_1.encodeFrameworkPayloadMessage)(response.reply, this.options.messageSerializers);
1422
+ if (accepted
1423
+ && transferRequest?.completionOperationId !== undefined
1424
+ && this.options.actorTransferRuntime !== undefined) {
1425
+ deferredJoinRoot = await this.options.actorTransferRuntime
1426
+ .prepareDeferredJoinAccepted(actorId, transferRequest.completionOperationId, actorRef, reply?.data() ?? Buffer.alloc(0), reply === undefined ? undefined : (0, payload_codec_1.frameworkPayloadContentType)(reply));
1427
+ this.options.runtimeEventPublisher?.publish({
1428
+ sourceName: 'zlink.framework.actor-handoff',
1429
+ timestamp: new Date(),
1430
+ marker: 'deferred_completion_staged',
1431
+ actorId
1432
+ });
1433
+ }
1434
+ }
1435
+ if (accepted
1436
+ && !isRemoteAdmission
1437
+ && actor === undefined
1438
+ && transferRequest !== undefined
1439
+ && this.options.actorTransferRuntime !== undefined) {
1440
+ if (!actorJoinIsCurrent())
1441
+ return;
1442
+ const transferState = preparedTransferState;
1443
+ preparedTransferState = undefined;
1444
+ if (transferState === undefined) {
1445
+ throw new Error('Remote actor transfer state was not prepared before admission.');
1446
+ }
1447
+ try {
1448
+ const result = await this.options.actorTransferRuntime.materializeRoutedActor(actorId, transferRequest.actorType, transferRequest.transferAdapterKey, transferState, transferRequest.actorEntryNodeRid, transferRequest.remoteBoundSessionTarget);
1449
+ actor = result.actor;
1450
+ materialized = true;
1451
+ await this.options.actorTransferRuntime.commitRoutedActorAuthority(actor, toFrameworkRemoteAdmissionActorRef(transferRequest.actorRef ?? control.currentActor, meshName), transferRequest.transferId, spotId, control.currentSpotGeneration, control.currentMembershipEpoch, record.deadlineUnixMs === undefined
1452
+ ? Date.now() + 5_000
1453
+ : Number(record.deadlineUnixMs), undefined);
1454
+ }
1455
+ finally {
1456
+ transferState.close();
1457
+ }
1458
+ if (!actorJoinIsCurrent()) {
1459
+ await this.options.actorTransferRuntime.rollbackRoutedActor(actor);
1460
+ materialized = false;
1461
+ return;
1462
+ }
1463
+ }
1464
+ if (accepted
1465
+ && transferRequest !== undefined
1466
+ && this.options.actorTransferRuntime !== undefined
1467
+ && !isRemoteAdmission) {
1468
+ // A lightweight Core actor-join notification can create the Actor
1469
+ // before the formal transfer request reaches this branch. Preserve
1470
+ // the full relocation fence in that race so a later Session bind
1471
+ // refresh cannot erase the seal or accepted journal.
1472
+ this.options.actorTransferRuntime.rememberRoutedActorTransferTarget(actorId, transferRequest.remoteBoundSessionTarget);
1473
+ }
1474
+ if (accepted
1475
+ && actor !== undefined
1476
+ && transferRequest !== undefined
1477
+ && !isRemoteAdmission
1478
+ && !committedAdmissionReplay) {
1479
+ this.formalRemoteTransfers.begin({
1480
+ actor,
1481
+ spotId,
1482
+ transferId: transferRequest.transferId,
1483
+ handoffBacklog: transferRequest.handoffBacklog,
1484
+ deferredJoinRoot
1485
+ });
1486
+ if (isRemoteCommit && admissionRecord !== undefined) {
1487
+ this.formalRemoteActorAdmissions.markCommitted(transferRequest.transferId, actor);
1488
+ }
1489
+ }
1490
+ const replyActorJoin = () => {
1491
+ if (!actorJoinIsCurrent())
1492
+ return false;
1493
+ const joinReplyResult = record.replyActorJoin(accepted ? 0 : 1, reply === undefined ? [] : [reply.data()], undefined, admissionOutcome === undefined || 'error' in admissionOutcome
1494
+ ? undefined
1495
+ : admissionOutcome.replyContentType);
1496
+ if (accepted && !isRemoteAdmission && joinReplyResult === runtime_values_1.SubmitResult.Ok) {
1497
+ // Core commits the target membership while it accepts this reply.
1498
+ // From this call onward a later callback/transport failure is
1499
+ // post-commit and must not roll the materialized Actor back.
1500
+ targetCommitPublished = true;
1501
+ }
1502
+ requireMeshSpotReply(joinReplyResult);
1503
+ return true;
1504
+ };
1505
+ if (control.canonicalActorJoin !== undefined) {
1506
+ replyActorJoin();
1507
+ return;
1508
+ }
1509
+ if (accepted && targetsEntrySpot && actor !== undefined) {
1510
+ const entryActor = actor;
1511
+ const pendingTransfer = transferRequest === undefined
1512
+ ? undefined
1513
+ : this.formalRemoteTransfers.get(actorId);
1514
+ if (committedAdmissionReplay) {
1515
+ if (!replyActorJoin())
1516
+ return;
1517
+ }
1518
+ else if (pendingTransfer === undefined) {
1519
+ if (!actorJoinIsCurrent())
1520
+ return;
1521
+ // The Core reply commits target membership. Entry lifecycle must
1522
+ // therefore run after that commit, as it does on the native path.
1523
+ if (!replyActorJoin())
1524
+ return;
1525
+ await this.options.dispatchEntryActorJoin?.(meshName, entryActor);
1526
+ }
1527
+ else {
1528
+ if (!replyActorJoin())
1529
+ return;
1530
+ const commitEntryTransfer = async () => {
1531
+ try {
1532
+ await this.options.dispatchEntryActorJoin?.(meshName, entryActor, []);
1533
+ }
1534
+ finally {
1535
+ this.formalRemoteTransfers.completeTargetLifecycle(entryActor.context.actorId, pendingTransfer.transferId);
1536
+ }
1537
+ const sourceLeaveSubmitted = await pendingTransfer.sourceLeaveSubmitted;
1538
+ if (!sourceLeaveSubmitted) {
1539
+ throw new Error(`Actor '${entryActor.context.actorId}' source authority commit failed before leave submission.`);
1540
+ }
1541
+ const handoffResults = await (0, actor_handoff_1.replayActorHandoffBacklog)(pendingTransfer.handoffBacklog, async (parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef) => {
1542
+ if (this.options.dispatchEntryActorPacket === undefined) {
1543
+ throw new Error('Entry Spot saved handoff replay requires its Actor packet runtime.');
1544
+ }
1545
+ return await this.options.dispatchEntryActorPacket(entryActor.context.actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef);
1546
+ }, index => this.options.runtimeEventPublisher?.publish({
1547
+ sourceName: 'zlink.framework.actor-handoff',
1548
+ timestamp: new Date(),
1549
+ marker: 'backlog_enqueued',
1550
+ actorId: entryActor.context.actorId,
1551
+ index
1552
+ }));
1553
+ const failedHandoff = handoffResults.find(result => !result.ok);
1554
+ if (failedHandoff !== undefined) {
1555
+ throw new Error(`Actor '${entryActor.context.actorId}' saved Entry handoff packet `
1556
+ + `${failedHandoff.index} failed: ${failedHandoff.error ?? 'unknown error'}.`);
1557
+ }
1558
+ this.formalRemoteTransfers.delete(entryActor.context.actorId);
1559
+ };
1560
+ this.options.detachedTaskRunner?.runDetached(`actor Entry Spot transfer ${entryActor.context.actorId}`, commitEntryTransfer);
1561
+ if (this.options.detachedTaskRunner === undefined) {
1562
+ void commitEntryTransfer().catch(() => undefined);
1563
+ }
1564
+ }
1565
+ }
1566
+ else {
1567
+ if (!replyActorJoin())
1568
+ return;
1569
+ }
1570
+ }
1571
+ catch (error) {
1572
+ if (control.canonicalActorJoin !== undefined) {
1573
+ this.formalRemoteActorAdmissions.fail(control.canonicalActorJoin.handoffId, error);
1574
+ }
1575
+ if (deferredJoinRoot !== undefined && targetCommitPublished !== true) {
1576
+ await this.options.actorTransferRuntime?.discardDeferredJoinAccepted(deferredJoinRoot);
1577
+ }
1578
+ if (targetCommitPublished !== true) {
1579
+ this.formalRemoteTransfers.delete(actorId);
1580
+ }
1581
+ if (materialized && targetCommitPublished !== true) {
1582
+ await this.options.actorTransferRuntime?.rollbackRoutedActor(actor);
1583
+ }
1584
+ throw error;
1585
+ }
1586
+ finally {
1587
+ preparedTransferState?.close();
1588
+ ownedCallbackRequest?.close();
1589
+ reply?.close();
1590
+ applicationClaim?.close();
1591
+ }
1592
+ }
1593
+ async dispatchMeshSpotControl(meshName, owner, record) {
1594
+ const spotId = owner.spotId;
1595
+ const control = record.kindData;
1596
+ if (control?.kind !== 'actorControl') {
1597
+ throw new configuration_1.ZLinkConfigurationException('MeshNode Spot control record is missing actor lifecycle data.');
1598
+ }
1599
+ const actorRef = control.lifecycleKind === service_runtime_contracts_1.ActorLifecycleKind.Left
1600
+ ? control.previousActor
1601
+ : control.currentActor;
1602
+ const actorId = actorRef?.actorId;
1603
+ const pendingTransfer = actorId === undefined
1604
+ ? undefined
1605
+ : this.formalRemoteTransfers.get(actorId);
1606
+ const sourceActivation = actorId === undefined || spotId === null
1607
+ ? undefined
1608
+ : this.activations.resolve(meshName, spotId);
1609
+ const sourceJoinedActor = actorId === undefined
1610
+ ? undefined
1611
+ : sourceActivation?.resolveJoinedActor(actorId);
1612
+ const actor = actorId === undefined
1613
+ ? undefined
1614
+ : pendingTransfer?.actor
1615
+ ?? sourceJoinedActor
1616
+ ?? this.options.actorLifecycleResolver?.(actorId)
1617
+ ?? this.options.actorResolver?.(actorId);
1618
+ const entrySpotId = this.options.entryNodeRidProvider?.() ?? this.options.entryNodeRid;
1619
+ if (actor === undefined) {
1620
+ return;
1621
+ }
1622
+ if (control.lifecycleKind === service_runtime_contracts_1.ActorLifecycleKind.Left
1623
+ && (spotId === null || (entrySpotId !== undefined && String(spotId) === String(entrySpotId)))) {
1624
+ const callback = async () => {
1625
+ await this.options.entrySpotCallbacks?.onLeaveActor(actor, undefined, actorRef, control.previousMembershipEpoch);
1626
+ };
1627
+ if (this.options.actorTransferRuntime === undefined) {
1628
+ await callback();
1629
+ }
1630
+ else {
1631
+ await this.options.actorTransferRuntime.notifyCoreSourceLeave(actor, callback);
1632
+ }
1633
+ return;
1634
+ }
1635
+ if (spotId === null) {
1636
+ return;
1637
+ }
1638
+ const activation = this.activations.resolve(meshName, spotId);
1639
+ if (activation === undefined) {
1640
+ return;
1641
+ }
1642
+ await activation.serial.execute(async () => {
1643
+ if (control.lifecycleKind === service_runtime_contracts_1.ActorLifecycleKind.Joined) {
1644
+ if (control.currentActor !== null) {
1645
+ this.options.actorTransferRuntime?.bindRoutedActorRef(actor, control.currentActor);
1646
+ }
1647
+ this.options.actorTransferRuntime?.commitRoutedActor(actor, spotId, activation.spot);
1648
+ const completeTargetLifecycle = async () => {
1649
+ await this.options.actorTransferRuntime?.claimRoutedActorLocation(actor, spotId, meshName, {
1650
+ spotGeneration: control.currentSpotGeneration,
1651
+ membershipEpoch: control.currentMembershipEpoch
1652
+ });
1653
+ // Make the Actor resolvable for lifecycle and saved-work dispatch,
1654
+ // while formalRemoteTransfers continues to fence new ingress until
1655
+ // the saved backlog has completed.
1656
+ activation.commitActorJoin(actor);
1657
+ await activation.spot.onJoinedActor(actor);
1658
+ };
1659
+ const completePublicJoin = async () => {
1660
+ const deferredJoinRoot = pendingTransfer?.deferredJoinRoot;
1661
+ if (deferredJoinRoot !== undefined) {
1662
+ const currentRef = this.options.actorTransferRuntime === undefined
1663
+ ? null
1664
+ : control.currentActor;
1665
+ if (currentRef === null) {
1666
+ throw new Error(`Actor '${actor.context.actorId}' has no target ref for deferred Join completion.`);
1667
+ }
1668
+ await this.options.actorTransferRuntime?.commitAndDeliverDeferredJoinAccepted(deferredJoinRoot, actor, currentRef, operation => activation.executeActor(actor.context.actorId, async () => await operation()));
1669
+ }
1670
+ };
1671
+ const completeTargetReady = async () => {
1672
+ if (pendingTransfer !== undefined) {
1673
+ const handoffResults = await (0, actor_handoff_1.replayActorHandoffBacklog)(pendingTransfer.handoffBacklog, (parts, returnResponse, remoteBoundSessionTarget, _fallbackActorRef) => this.dispatchActorPacket(activation, actor.context.actorId, parts, returnResponse, remoteBoundSessionTarget, undefined), (index) => this.options.runtimeEventPublisher?.publish({
1674
+ sourceName: 'zlink.framework.actor-handoff',
1675
+ timestamp: new Date(),
1676
+ marker: 'backlog_enqueued',
1677
+ actorId: actor.context.actorId,
1678
+ index
1679
+ }));
1680
+ const failedHandoff = handoffResults.find(result => !result.ok);
1681
+ if (failedHandoff !== undefined) {
1682
+ throw new Error(`Actor '${actor.context.actorId}' saved handoff packet `
1683
+ + `${failedHandoff.index} failed: ${failedHandoff.error ?? 'unknown error'}.`);
1684
+ }
1685
+ // Spec 15 §4.2 relocation temporary queue: arrivals parked at
1686
+ // this target directly (not relayed through the source's
1687
+ // ingress hold) migrate into the real Actor queue next, in the
1688
+ // order they parked — after the relayed backlog above, before
1689
+ // regular ingress opens.
1690
+ await this.migrateActorJoinPrewarm(activation, actor, pendingTransfer.transferId);
1691
+ // This registry owns target lifecycle and saved backlog
1692
+ // reconciliation only. Session route readiness is enforced by
1693
+ // the Session binding aggregate after this boundary.
1694
+ this.formalRemoteTransfers.delete(actor.context.actorId);
1695
+ }
1696
+ const updateBoundSessionRoute = async () => {
1697
+ await this.options.actorTransferRuntime?.publishRoutedActorOwnership(actor);
1698
+ await this.options.actorTransferRuntime?.openRoutedActorSession(actor);
1699
+ };
1700
+ // Session routing is an independent post-Ready branch. Callback
1701
+ // sends are retained by the Session owner seal until this converges.
1702
+ if (pendingTransfer !== undefined && this.options.detachedTaskRunner !== undefined) {
1703
+ this.options.detachedTaskRunner.runDetached(`actor transfer Session route ${actor.context.actorId}`, updateBoundSessionRoute);
1704
+ }
1705
+ else {
1706
+ await updateBoundSessionRoute();
1707
+ }
1708
+ };
1709
+ if (pendingTransfer !== undefined) {
1710
+ const resume = async () => {
1711
+ try {
1712
+ await activation.serial.post(completeTargetLifecycle);
1713
+ }
1714
+ finally {
1715
+ this.formalRemoteTransfers.completeTargetLifecycle(actor.context.actorId, pendingTransfer.transferId);
1716
+ }
1717
+ const sourceLeaveSubmitted = await pendingTransfer.sourceLeaveSubmitted;
1718
+ if (!sourceLeaveSubmitted) {
1719
+ throw new Error(`Actor '${actor.context.actorId}' source authority commit failed before leave submission.`);
1720
+ }
1721
+ await completePublicJoin();
1722
+ // Saved handlers enter the Spot owner on their own turns. Run
1723
+ // them only after the lifecycle turn above has been released.
1724
+ await completeTargetReady();
1725
+ };
1726
+ this.options.detachedTaskRunner?.runDetached(`actor transfer target commit ${actor.context.actorId}`, resume);
1727
+ if (this.options.detachedTaskRunner === undefined) {
1728
+ void resume().catch(() => undefined);
1729
+ }
1730
+ return;
1731
+ }
1732
+ await completeTargetLifecycle();
1733
+ await completePublicJoin();
1734
+ await completeTargetReady();
1735
+ return;
1736
+ }
1737
+ if (control.lifecycleKind === service_runtime_contracts_1.ActorLifecycleKind.Left) {
1738
+ if (this.options.actorTransferRuntime === undefined) {
1739
+ await activation.spot.onLeaveActor(actor);
1740
+ }
1741
+ else {
1742
+ // Spot.Context.leaveActor can run the source callback before the
1743
+ // native Entry join is submitted. In that path the membership is
1744
+ // already committed away, so a later Core LEFT control must not
1745
+ // execute the same callback twice.
1746
+ if (sourceJoinedActor === undefined && pendingTransfer === undefined) {
1747
+ return;
1748
+ }
1749
+ await this.options.actorTransferRuntime.notifyCoreSourceLeave(actor, () => activation.spot.onLeaveActor(actor));
1750
+ }
1751
+ activation.commitActorDeparture(actor.context.actorId);
1752
+ return;
1753
+ }
1754
+ if (control.lifecycleKind === service_runtime_contracts_1.ActorLifecycleKind.Disconnected) {
1755
+ await activation.spot.onDisconnectActor?.(actor);
1756
+ }
1757
+ });
1758
+ }
1759
+ async completeFormalSourceLeaveTerminal(actorId, transferId, succeeded) {
1760
+ return await this.formalRemoteTransfers.completeSourceLeaveTerminal(actorId, transferId, succeeded);
1761
+ }
1762
+ async finalizeActorJoinRelocation(meshName, relocationId, actor, actorRef, submitSourceLeave, signal) {
1763
+ (0, abort_1.throwIfAborted)(signal);
1764
+ const admission = this.formalRemoteActorAdmissions.get(relocationId);
1765
+ if (admission === undefined)
1766
+ return false;
1767
+ if (admission.admission.actorId !== actor.context.actorId) {
1768
+ throw new Error(`Actor Join relocation '${relocationId}' changed its admitted Actor.`);
1769
+ }
1770
+ const outcome = admission.result ?? await admission.resultTask;
1771
+ if ('error' in outcome)
1772
+ throw outcome.error;
1773
+ if (!outcome.accepted || admission.state !== 'admitted') {
1774
+ throw new Error(`Actor Join relocation '${relocationId}' has no accepted admission.`);
1775
+ }
1776
+ const entrySpotId = this.options.entryNodeRidProvider?.() ?? this.options.entryNodeRid;
1777
+ const targetsEntry = entrySpotId !== undefined
1778
+ && String(admission.admission.spotId) === String(entrySpotId);
1779
+ if (targetsEntry) {
1780
+ await this.options.dispatchEntryActorJoin?.(meshName, actor, []);
1781
+ }
1782
+ else {
1783
+ const activation = this.activations.resolve(meshName, admission.admission.spotId);
1784
+ if (activation === undefined) {
1785
+ throw new Error(`Actor Join relocation '${relocationId}' target Spot is not active.`);
1786
+ }
1787
+ await activation.serial.execute(() => activation.spot.onJoinedActor(actor));
1788
+ }
1789
+ await submitSourceLeave(admission.admission.actorRef.nodeRid);
1790
+ if (outcome.deferredJoinRoot !== undefined && this.options.actorTransferRuntime !== undefined) {
1791
+ const submitMailbox = targetsEntry
1792
+ ? (operation) => operation()
1793
+ : (operation) => {
1794
+ const activation = this.activations.resolve(meshName, admission.admission.spotId);
1795
+ if (activation === undefined) {
1796
+ throw new Error(`Actor Join relocation '${relocationId}' target mailbox is missing.`);
1797
+ }
1798
+ return activation.executeActor(actor.context.actorId, operation);
1799
+ };
1800
+ await this.options.actorTransferRuntime.commitAndDeliverDeferredJoinAccepted(outcome.deferredJoinRoot, actor, actorRef, submitMailbox, signal);
1801
+ }
1802
+ this.formalRemoteActorAdmissions.markCommitted(relocationId, actor);
1803
+ return true;
1804
+ }
1805
+ async restoreCanonicalActorJoinRecovery(recovery, signal, canonicalInventoryDigest) {
1806
+ (0, abort_1.throwIfAborted)(signal);
1807
+ const admission = this.formalRemoteActorAdmissions.get(recovery.request.handoffId);
1808
+ if (admission === undefined) {
1809
+ throw new Error(`Actor Join recovery '${recovery.request.handoffId}' has no canonical command-28 admission.`);
1810
+ }
1811
+ const outcome = admission.result ?? await admission.resultTask;
1812
+ if ('error' in outcome || !outcome.accepted || admission.state !== 'admitted') {
1813
+ throw new Error(`Actor Join recovery '${recovery.request.handoffId}' has no accepted admission.`);
1814
+ }
1815
+ const admitted = admission.admission;
1816
+ if (admitted.sourceActorNodeRid === undefined) {
1817
+ throw new Error(`Actor Join recovery '${recovery.request.handoffId}' lost its command-28 source route.`);
1818
+ }
1819
+ const admittedNodeBytes = Buffer.from((0, routing_id_1.encodeRoutingIdStorageHex)(admitted.sourceActorNodeRid), 'hex');
1820
+ if (admitted.actorId !== recovery.request.actorId
1821
+ || admitted.actorType !== recovery.request.actorType
1822
+ || admitted.requestFingerprint !== recovery.request.request.toString('base64')
1823
+ || String(admitted.spotId) !== recovery.targetSpotId
1824
+ || admitted.targetSpotGeneration !== recovery.targetSpotGeneration
1825
+ || admitted.actorRef.objectGeneration !== recovery.request.actorGeneration
1826
+ || !admittedNodeBytes.equals(recovery.request.sourceNodeRid)) {
1827
+ throw new Error(`Actor Join recovery '${recovery.request.handoffId}' changed its command-28 identity.`);
1828
+ }
1829
+ const admittedReply = outcome.reply ?? Buffer.alloc(0);
1830
+ if (!admittedReply.equals(recovery.reply)) {
1831
+ throw new Error(`Actor Join recovery '${recovery.request.handoffId}' changed its admission reply.`);
1832
+ }
1833
+ if (recovery.operationId === undefined) {
1834
+ if (recovery.replyContentType !== undefined || recovery.reply.byteLength !== 0) {
1835
+ throw new Error(`Actor Join recovery '${recovery.request.handoffId}' has a reply without an OperationId.`);
1836
+ }
1837
+ return;
1838
+ }
1839
+ const outerReplyContentType = admittedReply.byteLength === 0
1840
+ ? recovery.replyContentType
1841
+ : service_wire_constants_generated_1.SERVICE_FRAMEWORK_MULTIPART_CONTENT_TYPE;
1842
+ if (recovery.replyContentType !== outerReplyContentType) {
1843
+ throw new Error(`Actor Join recovery '${recovery.request.handoffId}' changed its reply content type.`);
1844
+ }
1845
+ // Command 28 carries a present reply in one outer framework-multipart
1846
+ // part. The accepted target admission still owns the inner typed content
1847
+ // type, which the durable completion must retain for application decode.
1848
+ const admittedContentType = admittedReply.byteLength === 0
1849
+ ? recovery.replyContentType
1850
+ : outcome.replyContentType;
1851
+ const transfer = this.options.actorTransferRuntime;
1852
+ if (transfer === undefined) {
1853
+ throw new Error('Canonical Actor Join recovery requires the Actor transfer runtime.');
1854
+ }
1855
+ const deferred = await transfer.prepareDeferredJoinAccepted(recovery.request.actorId, recovery.operationId, admitted.actorRef, recovery.reply, admittedContentType, signal, canonicalInventoryDigest);
1856
+ this.formalRemoteActorAdmissions.attachDeferredJoinRoot(recovery.request.handoffId, deferred);
1857
+ return deferred;
1858
+ }
1859
+ encodeMeshActorReply(requestHeaderPart, kind, payload) {
1860
+ // Spec 27 §4/§7: the decode gate strips the observation-only flow pair at
1861
+ // Off (and skips its validation); when tracing is on the reply preserves
1862
+ // the request's flow pair alongside its correlation.
1863
+ const requestHeader = (0, protocol_1.decodeStreamHeader)(requestHeaderPart.data(), this.options.dispatchErrors?.flow.flowCreationEnabled() ?? true);
1864
+ const encoded = (0, payload_codec_1.encodeFrameworkPayload)(payload, this.options.messageSerializers);
1865
+ try {
1866
+ // encodeStreamHeader returns a fresh, unaliased array; view it without
1867
+ // re-copying. The payload copy stays: encoded.message closes below.
1868
+ const replyHeader = (0, protocol_1.encodeStreamHeader)({
1869
+ kind,
1870
+ codec: (0, protocol_1.streamCodecForContentType)(encoded.contentType),
1871
+ flags: protocol_1.ZLinkStreamHeaderFlags.None,
1872
+ requestSeq: requestHeader.requestSeq,
1873
+ name: '',
1874
+ metadata: new Map(),
1875
+ correlationId: requestHeader.correlationId,
1876
+ flowId: requestHeader.flowId,
1877
+ flowOrigin: requestHeader.flowOrigin
1878
+ });
1879
+ return [
1880
+ Buffer.from(replyHeader.buffer, replyHeader.byteOffset, replyHeader.byteLength),
1881
+ Buffer.from(encoded.message.data())
1882
+ ];
1883
+ }
1884
+ finally {
1885
+ encoded.message.close();
1886
+ }
1887
+ }
1888
+ async createActivation(meshName, spotType, spotId, request, signal, authority) {
1889
+ this.requireRegisteredFactory(spotType);
1890
+ return await this.activationLifecycle.create(meshName, spotType, spotId, request, signal, authority);
1891
+ }
1892
+ requireRegisteredFactory(spotType) {
1893
+ if (!this.factories.has(spotType)) {
1894
+ throw new configuration_1.ZLinkConfigurationException('Spot type is not registered as a spot factory.');
1895
+ }
1896
+ }
1897
+ async dispatchActorPacket(activation, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef, requestTerminal, messageFollowOrigin) {
1898
+ return await this.activationLifecycle.dispatchActorPacket(activation, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef, requestTerminal, messageFollowOrigin);
1899
+ }
1900
+ /**
1901
+ * Spec 15 §4.2 relocation temporary queue: drains every arrival parked
1902
+ * for this exact Actor Join admission attempt since Accepted, in order,
1903
+ * dispatching each one for real now that the Actor has cut over locally.
1904
+ * {@link ZLinkFormalRemoteActorAdmissionRegistry#completeMigration}
1905
+ * synchronously snapshots the parked queue and flips the attempt to
1906
+ * `migrated` before this method dispatches anything, so a racing arrival
1907
+ * either lands in the snapshot or resolves the Actor directly through
1908
+ * ordinary ingress — never both, never neither.
1909
+ */
1910
+ async migrateActorJoinPrewarm(activation, actor, transferId) {
1911
+ const drained = this.formalRemoteActorAdmissions.completeMigration(transferId);
1912
+ for (const arrival of drained) {
1913
+ try {
1914
+ const response = await this.dispatchActorPacket(activation, actor.context.actorId, [
1915
+ runtime_message_1.ZLinkBufferMessage.from(arrival.header),
1916
+ runtime_message_1.ZLinkBufferMessage.from(arrival.payload)
1917
+ ], arrival.returnResponse, arrival.remoteBoundSessionTarget, arrival.fallbackActorRef, arrival.requestTerminal);
1918
+ arrival.resolve(response);
1919
+ }
1920
+ catch (error) {
1921
+ arrival.reject(error);
1922
+ }
1923
+ }
1924
+ }
1925
+ async dispatchMeshActorPacket(meshName, spotId, actorId, parts, returnResponse, fallbackActorRef, requestTerminal, messageFollowOrigin) {
1926
+ const activation = this.activations.resolve(meshName, spotId);
1927
+ if (activation === undefined) {
1928
+ throw new configuration_1.ZLinkConfigurationException(`Spot '${String(spotId)}' is not active in mesh '${meshName}'.`);
1929
+ }
1930
+ return await this.dispatchActorPacket(activation, actorId, parts, returnResponse, undefined, fallbackActorRef, requestTerminal, messageFollowOrigin);
1931
+ }
1932
+ }
1933
+ exports.DefaultZLinkSpotManager = DefaultZLinkSpotManager;
1934
+ function instanceDispatchErrorReason(error) {
1935
+ if (error instanceof contracts_1.ZLinkFrameworkException) {
1936
+ const kind = (0, framework_errors_internal_1.internalFrameworkErrorKind)(error);
1937
+ if (kind === framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotGenerationStale
1938
+ || kind === framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving
1939
+ || kind === framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotRouteNotFound
1940
+ || kind === framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.RequestTargetNotFound) {
1941
+ return ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorReason.StaleTarget;
1942
+ }
1943
+ }
1944
+ return ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorReason.HandlerException;
1945
+ }
1946
+ function decodeFormalRemoteTransferRequest(message) {
1947
+ return decodeFormalRemoteTransferRequestBytes(message.data());
1948
+ }
1949
+ function decodeFormalRemoteTransferRequestBytes(bytes) {
1950
+ let payload;
1951
+ try {
1952
+ payload = JSON.parse(Buffer.from(bytes).toString());
1953
+ }
1954
+ catch {
1955
+ return undefined;
1956
+ }
1957
+ if (payload.packetName !== actor_remote_wire_1.REMOTE_ACTOR_JOIN_PACKET
1958
+ || typeof payload.actorType !== 'string'
1959
+ || typeof payload.transferId !== 'string'
1960
+ || !(payload.phase === actor_remote_wire_1.REMOTE_ACTOR_JOIN_ADMISSION
1961
+ || payload.phase === actor_remote_wire_1.REMOTE_ACTOR_JOIN_ABORT
1962
+ || payload.phase === actor_remote_wire_1.REMOTE_ACTOR_JOIN_COMMIT
1963
+ || payload.phase === undefined)
1964
+ || !(payload.phase === actor_remote_wire_1.REMOTE_ACTOR_JOIN_ADMISSION
1965
+ || payload.phase === actor_remote_wire_1.REMOTE_ACTOR_JOIN_ABORT
1966
+ || (typeof payload.transferState === 'string'))
1967
+ || typeof payload.request !== 'string') {
1968
+ return undefined;
1969
+ }
1970
+ return {
1971
+ actorType: payload.actorType,
1972
+ actorId: typeof payload.actorId === 'string' ? payload.actorId : undefined,
1973
+ phase: payload.phase === actor_remote_wire_1.REMOTE_ACTOR_JOIN_ADMISSION
1974
+ || payload.phase === actor_remote_wire_1.REMOTE_ACTOR_JOIN_COMMIT
1975
+ || payload.phase === actor_remote_wire_1.REMOTE_ACTOR_JOIN_ABORT
1976
+ ? payload.phase
1977
+ : undefined,
1978
+ transferId: payload.transferId,
1979
+ transferAdapterKey: typeof payload.transferAdapterKey === 'string'
1980
+ ? payload.transferAdapterKey
1981
+ : undefined,
1982
+ transferState: typeof payload.transferState === 'string'
1983
+ ? payload.transferState
1984
+ : undefined,
1985
+ request: payload.request,
1986
+ requestContentType: typeof payload.requestContentType === 'string'
1987
+ ? payload.requestContentType
1988
+ : 'application/json',
1989
+ actorEntryNodeRid: typeof payload.actorEntryNodeRid === 'string'
1990
+ ? (0, routing_id_1.decodeRoutingId)(payload.actorEntryNodeRid, payload.actorEntryNodeRidHex)
1991
+ : undefined,
1992
+ sourceSpotId: typeof payload.sourceSpotId === 'string'
1993
+ ? payload.sourceSpotId
1994
+ : undefined,
1995
+ actorRef: decodeFormalRemoteActorRef(payload),
1996
+ remoteBoundSessionTarget: (0, spot_remote_codec_1.decodeRemoteBoundSessionTarget)(payload.boundSessionRouterChannelId, payload.boundSessionTargetNodeRid, payload.boundSessionTargetNodeRidHex, payload.boundSessionSpotId, payload.boundSessionNodeRid, payload.boundSessionNodeRidHex, payload.boundSessionRid, payload.boundSessionRidHex, payload.boundSessionBindingGeneration, payload.boundSessionPreviousAuthorityOwnerGeneration, payload.boundSessionPreviousOwnerLeaseGeneration, payload.boundSessionRelocationSealId, payload.boundSessionServiceWireRelocation),
1997
+ expectedMembershipEpoch: typeof payload.expectedMembershipEpoch === 'string'
1998
+ ? BigInt(payload.expectedMembershipEpoch)
1999
+ : 0n,
2000
+ handoffBacklog: (0, spot_remote_codec_1.decodeHandoffBacklog)(payload.handoffBacklog),
2001
+ completionOperationId: typeof payload.completionOperationHigh === 'string'
2002
+ && typeof payload.completionOperationLow === 'string'
2003
+ ? {
2004
+ high: BigInt(payload.completionOperationHigh),
2005
+ low: BigInt(payload.completionOperationLow)
2006
+ }
2007
+ : undefined
2008
+ };
2009
+ }
2010
+ function decodeFormalRemoteActorRef(payload) {
2011
+ const backend = (0, spot_remote_codec_1.decodeRemoteActorRef)(payload.actorNodeRid, payload.actorNodeRidHex, typeof payload.actorId === 'string' ? payload.actorId : '', payload.actorGeneration);
2012
+ if (backend === undefined || typeof payload.routerChannelId !== 'string') {
2013
+ return undefined;
2014
+ }
2015
+ return {
2016
+ actorId: backend.actorId,
2017
+ objectGeneration: backend.generation,
2018
+ meshName: payload.routerChannelId,
2019
+ nodeRid: backend.nodeRid
2020
+ };
2021
+ }
2022
+ function requireMeshSpotReply(result) {
2023
+ if (result !== runtime_values_1.SubmitResult.Ok) {
2024
+ throw new configuration_1.ZLinkConfigurationException(`MeshNode reply was not accepted (submit result ${result}).`);
2025
+ }
2026
+ }
2027
+ function toFrameworkRemoteAdmissionActorRef(rawActorRef, meshName) {
2028
+ const objectGeneration = rawActorRef.objectGeneration ?? rawActorRef.generation;
2029
+ if (objectGeneration === undefined) {
2030
+ throw new configuration_1.ZLinkConfigurationException(`Actor '${rawActorRef.actorId}' join record has no ObjectGeneration.`);
2031
+ }
2032
+ return {
2033
+ actorId: rawActorRef.actorId,
2034
+ objectGeneration,
2035
+ meshName,
2036
+ nodeRid: rawActorRef.nodeRid
2037
+ };
2038
+ }
2039
+ function validateRemoteAdmissionCommit(admission, request, actorId, control) {
2040
+ const expected = admission.admission;
2041
+ const actorRef = request.actorRef;
2042
+ if (expected.actorId !== actorId
2043
+ || expected.actorType !== request.actorType
2044
+ || expected.expectedMembershipEpoch !== request.expectedMembershipEpoch
2045
+ || expected.requestFingerprint !== request.request
2046
+ || expected.targetSpotGeneration !== (control.currentSpotGeneration ?? 0n)
2047
+ || actorRef === undefined
2048
+ || actorRef.actorId !== expected.actorRef.actorId
2049
+ || String(actorRef.nodeRid) !== String(expected.actorRef.nodeRid)
2050
+ || actorRef.objectGeneration !== expected.actorRef.objectGeneration) {
2051
+ throw new configuration_1.ZLinkConfigurationException(`Remote Actor '${actorId}' commit does not match its target admission.`);
2052
+ }
2053
+ }
2054
+ function normalizeSpotCreateArgs(requestOrSignal, signal) {
2055
+ if (isAbortSignal(requestOrSignal)) {
2056
+ return { request: undefined, signal: requestOrSignal };
2057
+ }
2058
+ return { request: requestOrSignal, signal };
2059
+ }
2060
+ function requireMeshName(meshName) {
2061
+ if (meshName.length === 0) {
2062
+ throw new configuration_1.ZLinkConfigurationException('Spot operations require a mesh name.');
2063
+ }
2064
+ }
2065
+ function instanceMaterializationPrefix(meshName, spotId) {
2066
+ return `${meshName}\0${String(spotId)}`;
2067
+ }
2068
+ function instanceMaterializationKey(meshName, spotId, objectGeneration) {
2069
+ return `${instanceMaterializationPrefix(meshName, spotId)}\0${objectGeneration}`;
2070
+ }
2071
+ function isAbortSignal(value) {
2072
+ return typeof value === 'object'
2073
+ && value !== null
2074
+ && typeof value.aborted === 'boolean'
2075
+ && typeof value.addEventListener === 'function';
2076
+ }
2077
+ function instanceActivationOutcome(error) {
2078
+ if ((0, abort_1.isAbortError)(error))
2079
+ return 'shutdown';
2080
+ if (error instanceof contracts_1.ZLinkFrameworkException) {
2081
+ if (error.kind === contracts_1.ZLinkFrameworkErrorKind.DeadlineExceeded)
2082
+ return 'timed_out';
2083
+ if (error.kind === contracts_1.ZLinkFrameworkErrorKind.AlreadyExists)
2084
+ return 'conflict';
2085
+ if (error.kind === contracts_1.ZLinkFrameworkErrorKind.InvalidOperation
2086
+ || error.kind === contracts_1.ZLinkFrameworkErrorKind.Unavailable)
2087
+ return 'fenced';
2088
+ }
2089
+ return 'failed';
2090
+ }